Commit bce21a2b authored by Jan Beulich's avatar Jan Beulich Committed by Boris Ostrovsky

Xen/gnttab: introduce common INVALID_GRANT_{HANDLE,REF}

It's not helpful if every driver has to cook its own. Generalize
xenbus'es INVALID_GRANT_HANDLE and pcifront's INVALID_GRANT_REF (which
shouldn't have expanded to zero to begin with). Use the constants in
p2m.c and gntdev.c right away, and update field types where necessary so
they would match with the constants' types (albeit without touching
struct ioctl_gntdev_grant_ref's ref field, as that's part of the public
interface of the kernel and would require introducing a dependency on
Xen's grant_table.h public header).
Signed-off-by: default avatarJan Beulich <jbeulich@suse.com>
Reviewed-by: default avatarJuergen Gross <jgross@suse.com>
Link: https://lore.kernel.org/r/db7c38a5-0d75-d5d1-19de-e5fe9f0b9c48@suse.comSigned-off-by: default avatarBoris Ostrovsky <boris.ostrovsky@oracle.com>
parent 36caa3fe
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include <xen/xen.h> #include <xen/xen.h>
#include <xen/interface/memory.h> #include <xen/interface/memory.h>
#include <xen/grant_table.h>
#include <xen/page.h> #include <xen/page.h>
#include <xen/swiotlb-xen.h> #include <xen/swiotlb-xen.h>
...@@ -109,7 +110,7 @@ int set_foreign_p2m_mapping(struct gnttab_map_grant_ref *map_ops, ...@@ -109,7 +110,7 @@ int set_foreign_p2m_mapping(struct gnttab_map_grant_ref *map_ops,
map_ops[i].status = GNTST_general_error; map_ops[i].status = GNTST_general_error;
unmap.host_addr = map_ops[i].host_addr, unmap.host_addr = map_ops[i].host_addr,
unmap.handle = map_ops[i].handle; unmap.handle = map_ops[i].handle;
map_ops[i].handle = ~0; map_ops[i].handle = INVALID_GRANT_HANDLE;
if (map_ops[i].flags & GNTMAP_device_map) if (map_ops[i].flags & GNTMAP_device_map)
unmap.dev_bus_addr = map_ops[i].dev_bus_addr; unmap.dev_bus_addr = map_ops[i].dev_bus_addr;
else else
......
...@@ -741,7 +741,7 @@ int set_foreign_p2m_mapping(struct gnttab_map_grant_ref *map_ops, ...@@ -741,7 +741,7 @@ int set_foreign_p2m_mapping(struct gnttab_map_grant_ref *map_ops,
map_ops[i].status = GNTST_general_error; map_ops[i].status = GNTST_general_error;
unmap[0].host_addr = map_ops[i].host_addr, unmap[0].host_addr = map_ops[i].host_addr,
unmap[0].handle = map_ops[i].handle; unmap[0].handle = map_ops[i].handle;
map_ops[i].handle = ~0; map_ops[i].handle = INVALID_GRANT_HANDLE;
if (map_ops[i].flags & GNTMAP_device_map) if (map_ops[i].flags & GNTMAP_device_map)
unmap[0].dev_bus_addr = map_ops[i].dev_bus_addr; unmap[0].dev_bus_addr = map_ops[i].dev_bus_addr;
else else
...@@ -751,7 +751,7 @@ int set_foreign_p2m_mapping(struct gnttab_map_grant_ref *map_ops, ...@@ -751,7 +751,7 @@ int set_foreign_p2m_mapping(struct gnttab_map_grant_ref *map_ops,
kmap_ops[i].status = GNTST_general_error; kmap_ops[i].status = GNTST_general_error;
unmap[1].host_addr = kmap_ops[i].host_addr, unmap[1].host_addr = kmap_ops[i].host_addr,
unmap[1].handle = kmap_ops[i].handle; unmap[1].handle = kmap_ops[i].handle;
kmap_ops[i].handle = ~0; kmap_ops[i].handle = INVALID_GRANT_HANDLE;
if (kmap_ops[i].flags & GNTMAP_device_map) if (kmap_ops[i].flags & GNTMAP_device_map)
unmap[1].dev_bus_addr = kmap_ops[i].dev_bus_addr; unmap[1].dev_bus_addr = kmap_ops[i].dev_bus_addr;
else else
......
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
#include <xen/platform_pci.h> #include <xen/platform_pci.h>
#include <asm/xen/swiotlb-xen.h> #include <asm/xen/swiotlb-xen.h>
#define INVALID_GRANT_REF (0)
#define INVALID_EVTCHN (-1) #define INVALID_EVTCHN (-1)
struct pci_bus_entry { struct pci_bus_entry {
...@@ -42,7 +42,7 @@ struct pcifront_device { ...@@ -42,7 +42,7 @@ struct pcifront_device {
struct list_head root_buses; struct list_head root_buses;
int evtchn; int evtchn;
int gnt_ref; grant_ref_t gnt_ref;
int irq; int irq;
......
...@@ -186,11 +186,11 @@ struct gntdev_grant_map *gntdev_alloc_map(struct gntdev_priv *priv, int count, ...@@ -186,11 +186,11 @@ struct gntdev_grant_map *gntdev_alloc_map(struct gntdev_priv *priv, int count,
goto err; goto err;
for (i = 0; i < count; i++) { for (i = 0; i < count; i++) {
add->map_ops[i].handle = -1; add->map_ops[i].handle = INVALID_GRANT_HANDLE;
add->unmap_ops[i].handle = -1; add->unmap_ops[i].handle = INVALID_GRANT_HANDLE;
if (use_ptemod) { if (use_ptemod) {
add->kmap_ops[i].handle = -1; add->kmap_ops[i].handle = INVALID_GRANT_HANDLE;
add->kunmap_ops[i].handle = -1; add->kunmap_ops[i].handle = INVALID_GRANT_HANDLE;
} }
} }
...@@ -279,7 +279,7 @@ static int find_grant_ptes(pte_t *pte, unsigned long addr, void *data) ...@@ -279,7 +279,7 @@ static int find_grant_ptes(pte_t *pte, unsigned long addr, void *data)
map->grants[pgnr].ref, map->grants[pgnr].ref,
map->grants[pgnr].domid); map->grants[pgnr].domid);
gnttab_set_unmap_op(&map->unmap_ops[pgnr], pte_maddr, flags, gnttab_set_unmap_op(&map->unmap_ops[pgnr], pte_maddr, flags,
-1 /* handle */); INVALID_GRANT_HANDLE);
return 0; return 0;
} }
...@@ -297,7 +297,7 @@ int gntdev_map_grant_pages(struct gntdev_grant_map *map) ...@@ -297,7 +297,7 @@ int gntdev_map_grant_pages(struct gntdev_grant_map *map)
if (!use_ptemod) { if (!use_ptemod) {
/* Note: it could already be mapped */ /* Note: it could already be mapped */
if (map->map_ops[0].handle != -1) if (map->map_ops[0].handle != INVALID_GRANT_HANDLE)
return 0; return 0;
for (i = 0; i < map->count; i++) { for (i = 0; i < map->count; i++) {
unsigned long addr = (unsigned long) unsigned long addr = (unsigned long)
...@@ -306,7 +306,7 @@ int gntdev_map_grant_pages(struct gntdev_grant_map *map) ...@@ -306,7 +306,7 @@ int gntdev_map_grant_pages(struct gntdev_grant_map *map)
map->grants[i].ref, map->grants[i].ref,
map->grants[i].domid); map->grants[i].domid);
gnttab_set_unmap_op(&map->unmap_ops[i], addr, gnttab_set_unmap_op(&map->unmap_ops[i], addr,
map->flags, -1 /* handle */); map->flags, INVALID_GRANT_HANDLE);
} }
} else { } else {
/* /*
...@@ -332,7 +332,7 @@ int gntdev_map_grant_pages(struct gntdev_grant_map *map) ...@@ -332,7 +332,7 @@ int gntdev_map_grant_pages(struct gntdev_grant_map *map)
map->grants[i].ref, map->grants[i].ref,
map->grants[i].domid); map->grants[i].domid);
gnttab_set_unmap_op(&map->kunmap_ops[i], address, gnttab_set_unmap_op(&map->kunmap_ops[i], address,
flags, -1); flags, INVALID_GRANT_HANDLE);
} }
} }
...@@ -390,7 +390,7 @@ static int __unmap_grant_pages(struct gntdev_grant_map *map, int offset, ...@@ -390,7 +390,7 @@ static int __unmap_grant_pages(struct gntdev_grant_map *map, int offset,
pr_debug("unmap handle=%d st=%d\n", pr_debug("unmap handle=%d st=%d\n",
map->unmap_ops[offset+i].handle, map->unmap_ops[offset+i].handle,
map->unmap_ops[offset+i].status); map->unmap_ops[offset+i].status);
map->unmap_ops[offset+i].handle = -1; map->unmap_ops[offset+i].handle = INVALID_GRANT_HANDLE;
} }
return err; return err;
} }
...@@ -406,13 +406,15 @@ static int unmap_grant_pages(struct gntdev_grant_map *map, int offset, ...@@ -406,13 +406,15 @@ static int unmap_grant_pages(struct gntdev_grant_map *map, int offset,
* already unmapped some of the grants. Only unmap valid ranges. * already unmapped some of the grants. Only unmap valid ranges.
*/ */
while (pages && !err) { while (pages && !err) {
while (pages && map->unmap_ops[offset].handle == -1) { while (pages &&
map->unmap_ops[offset].handle == INVALID_GRANT_HANDLE) {
offset++; offset++;
pages--; pages--;
} }
range = 0; range = 0;
while (range < pages) { while (range < pages) {
if (map->unmap_ops[offset+range].handle == -1) if (map->unmap_ops[offset + range].handle ==
INVALID_GRANT_HANDLE)
break; break;
range++; range++;
} }
......
...@@ -50,6 +50,13 @@ ...@@ -50,6 +50,13 @@
#include <linux/page-flags.h> #include <linux/page-flags.h>
#include <linux/kernel.h> #include <linux/kernel.h>
/*
* Technically there's no reliably invalid grant reference or grant handle,
* so pick the value that is the most unlikely one to be observed valid.
*/
#define INVALID_GRANT_REF ((grant_ref_t)-1)
#define INVALID_GRANT_HANDLE ((grant_handle_t)-1)
#define GNTTAB_RESERVED_XENSTORE 1 #define GNTTAB_RESERVED_XENSTORE 1
/* NR_GRANT_FRAMES must be less than or equal to that configured in Xen */ /* NR_GRANT_FRAMES must be less than or equal to that configured in Xen */
......
...@@ -51,7 +51,6 @@ ...@@ -51,7 +51,6 @@
#define XENBUS_MAX_RING_GRANT_ORDER 4 #define XENBUS_MAX_RING_GRANT_ORDER 4
#define XENBUS_MAX_RING_GRANTS (1U << XENBUS_MAX_RING_GRANT_ORDER) #define XENBUS_MAX_RING_GRANTS (1U << XENBUS_MAX_RING_GRANT_ORDER)
#define INVALID_GRANT_HANDLE (~0U)
/* Register callback to watch this node. */ /* Register callback to watch this node. */
struct xenbus_watch struct xenbus_watch
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment