Skip to content

Commit 49f8b45

Browse files
committed
xen: switch gnttab_end_foreign_access() to take a struct page pointer
Instead of a virtual kernel address use a pointer of the associated struct page as second parameter of gnttab_end_foreign_access(). Most users have that pointer available already and are creating the virtual address from it, risking problems in case the memory is located in highmem. gnttab_end_foreign_access() itself won't need to get the struct page from the address again. Suggested-by: Jan Beulich <[email protected]> Signed-off-by: Juergen Gross <[email protected]> Reviewed-by: Jan Beulich <[email protected]> Signed-off-by: Juergen Gross <[email protected]>
1 parent 5b33539 commit 49f8b45

File tree

11 files changed

+28
-32
lines changed

11 files changed

+28
-32
lines changed

drivers/block/xen-blkfront.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1221,7 +1221,7 @@ static void blkif_free_ring(struct blkfront_ring_info *rinfo)
12211221
list_del(&persistent_gnt->node);
12221222
if (persistent_gnt->gref != INVALID_GRANT_REF) {
12231223
gnttab_end_foreign_access(persistent_gnt->gref,
1224-
0UL);
1224+
NULL);
12251225
rinfo->persistent_gnts_c--;
12261226
}
12271227
if (info->feature_persistent)
@@ -1244,7 +1244,7 @@ static void blkif_free_ring(struct blkfront_ring_info *rinfo)
12441244
rinfo->shadow[i].req.u.rw.nr_segments;
12451245
for (j = 0; j < segs; j++) {
12461246
persistent_gnt = rinfo->shadow[i].grants_used[j];
1247-
gnttab_end_foreign_access(persistent_gnt->gref, 0UL);
1247+
gnttab_end_foreign_access(persistent_gnt->gref, NULL);
12481248
if (info->feature_persistent)
12491249
__free_page(persistent_gnt->page);
12501250
kfree(persistent_gnt);
@@ -1259,7 +1259,7 @@ static void blkif_free_ring(struct blkfront_ring_info *rinfo)
12591259

12601260
for (j = 0; j < INDIRECT_GREFS(segs); j++) {
12611261
persistent_gnt = rinfo->shadow[i].indirect_grants[j];
1262-
gnttab_end_foreign_access(persistent_gnt->gref, 0UL);
1262+
gnttab_end_foreign_access(persistent_gnt->gref, NULL);
12631263
__free_page(persistent_gnt->page);
12641264
kfree(persistent_gnt);
12651265
}

drivers/input/misc/xen-kbdfront.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,7 @@ static int xenkbd_connect_backend(struct xenbus_device *dev,
481481
error_evtchan:
482482
xenbus_free_evtchn(dev, evtchn);
483483
error_grant:
484-
gnttab_end_foreign_access(info->gref, 0UL);
484+
gnttab_end_foreign_access(info->gref, NULL);
485485
info->gref = -1;
486486
return ret;
487487
}
@@ -492,7 +492,7 @@ static void xenkbd_disconnect_backend(struct xenkbd_info *info)
492492
unbind_from_irqhandler(info->irq, info);
493493
info->irq = -1;
494494
if (info->gref >= 0)
495-
gnttab_end_foreign_access(info->gref, 0UL);
495+
gnttab_end_foreign_access(info->gref, NULL);
496496
info->gref = -1;
497497
}
498498

drivers/net/xen-netfront.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1386,7 +1386,7 @@ static void xennet_release_tx_bufs(struct netfront_queue *queue)
13861386
queue->tx_skbs[i] = NULL;
13871387
get_page(queue->grant_tx_page[i]);
13881388
gnttab_end_foreign_access(queue->grant_tx_ref[i],
1389-
(unsigned long)page_address(queue->grant_tx_page[i]));
1389+
queue->grant_tx_page[i]);
13901390
queue->grant_tx_page[i] = NULL;
13911391
queue->grant_tx_ref[i] = INVALID_GRANT_REF;
13921392
add_id_to_list(&queue->tx_skb_freelist, queue->tx_link, i);
@@ -1418,8 +1418,7 @@ static void xennet_release_rx_bufs(struct netfront_queue *queue)
14181418
* foreign access is ended (which may be deferred).
14191419
*/
14201420
get_page(page);
1421-
gnttab_end_foreign_access(ref,
1422-
(unsigned long)page_address(page));
1421+
gnttab_end_foreign_access(ref, page);
14231422
queue->grant_rx_ref[id] = INVALID_GRANT_REF;
14241423

14251424
kfree_skb(skb);
@@ -1760,7 +1759,7 @@ static void xennet_end_access(int ref, void *page)
17601759
{
17611760
/* This frees the page as a side-effect */
17621761
if (ref != INVALID_GRANT_REF)
1763-
gnttab_end_foreign_access(ref, (unsigned long)page);
1762+
gnttab_end_foreign_access(ref, virt_to_page(page));
17641763
}
17651764

17661765
static void xennet_disconnect_backend(struct netfront_info *info)

drivers/xen/gntalloc.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,6 @@ static int add_grefs(struct ioctl_gntalloc_alloc_gref *op,
175175

176176
static void __del_gref(struct gntalloc_gref *gref)
177177
{
178-
unsigned long addr;
179-
180178
if (gref->notify.flags & UNMAP_NOTIFY_CLEAR_BYTE) {
181179
uint8_t *tmp = kmap_local_page(gref->page);
182180
tmp[gref->notify.pgoff] = 0;
@@ -190,10 +188,9 @@ static void __del_gref(struct gntalloc_gref *gref)
190188
gref->notify.flags = 0;
191189

192190
if (gref->gref_id) {
193-
if (gref->page) {
194-
addr = (unsigned long)page_to_virt(gref->page);
195-
gnttab_end_foreign_access(gref->gref_id, addr);
196-
} else
191+
if (gref->page)
192+
gnttab_end_foreign_access(gref->gref_id, gref->page);
193+
else
197194
gnttab_free_grant_reference(gref->gref_id);
198195
}
199196

drivers/xen/gntdev-dmabuf.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,7 @@ static void dmabuf_imp_end_foreign_access(u32 *refs, int count)
524524

525525
for (i = 0; i < count; i++)
526526
if (refs[i] != INVALID_GRANT_REF)
527-
gnttab_end_foreign_access(refs[i], 0UL);
527+
gnttab_end_foreign_access(refs[i], NULL);
528528
}
529529

530530
static void dmabuf_imp_free_storage(struct gntdev_dmabuf *gntdev_dmabuf)

drivers/xen/grant-table.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -430,13 +430,13 @@ int gnttab_try_end_foreign_access(grant_ref_t ref)
430430
}
431431
EXPORT_SYMBOL_GPL(gnttab_try_end_foreign_access);
432432

433-
void gnttab_end_foreign_access(grant_ref_t ref, unsigned long page)
433+
void gnttab_end_foreign_access(grant_ref_t ref, struct page *page)
434434
{
435435
if (gnttab_try_end_foreign_access(ref)) {
436-
if (page != 0)
437-
put_page(virt_to_page(page));
436+
if (page)
437+
put_page(page);
438438
} else
439-
gnttab_add_deferred(ref, page ? virt_to_page(page) : NULL);
439+
gnttab_add_deferred(ref, page);
440440
}
441441
EXPORT_SYMBOL_GPL(gnttab_end_foreign_access);
442442

drivers/xen/pvcalls-front.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -238,8 +238,8 @@ static void pvcalls_front_free_map(struct pvcalls_bedata *bedata,
238238
spin_unlock(&bedata->socket_lock);
239239

240240
for (i = 0; i < (1 << PVCALLS_RING_ORDER); i++)
241-
gnttab_end_foreign_access(map->active.ring->ref[i], 0);
242-
gnttab_end_foreign_access(map->active.ref, 0);
241+
gnttab_end_foreign_access(map->active.ring->ref[i], NULL);
242+
gnttab_end_foreign_access(map->active.ref, NULL);
243243
free_page((unsigned long)map->active.ring);
244244

245245
kfree(map);
@@ -1117,7 +1117,7 @@ static int pvcalls_front_remove(struct xenbus_device *dev)
11171117
}
11181118
}
11191119
if (bedata->ref != -1)
1120-
gnttab_end_foreign_access(bedata->ref, 0);
1120+
gnttab_end_foreign_access(bedata->ref, NULL);
11211121
kfree(bedata->ring.sring);
11221122
kfree(bedata);
11231123
xenbus_switch_state(dev, XenbusStateClosed);

drivers/xen/xen-front-pgdir-shbuf.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ void xen_front_pgdir_shbuf_free(struct xen_front_pgdir_shbuf *buf)
135135

136136
for (i = 0; i < buf->num_grefs; i++)
137137
if (buf->grefs[i] != INVALID_GRANT_REF)
138-
gnttab_end_foreign_access(buf->grefs[i], 0UL);
138+
gnttab_end_foreign_access(buf->grefs[i], NULL);
139139
}
140140
kfree(buf->grefs);
141141
kfree(buf->directory);

drivers/xen/xenbus/xenbus_client.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ void xenbus_teardown_ring(void **vaddr, unsigned int nr_pages,
439439

440440
for (i = 0; i < nr_pages; i++) {
441441
if (grefs[i] != INVALID_GRANT_REF) {
442-
gnttab_end_foreign_access(grefs[i], 0);
442+
gnttab_end_foreign_access(grefs[i], NULL);
443443
grefs[i] = INVALID_GRANT_REF;
444444
}
445445
}

include/xen/grant_table.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,18 +101,18 @@ int gnttab_end_foreign_access_ref(grant_ref_t ref);
101101
* Eventually end access through the given grant reference, and once that
102102
* access has been ended, free the given page too. Access will be ended
103103
* immediately iff the grant entry is not in use, otherwise it will happen
104-
* some time later. page may be 0, in which case no freeing will occur.
104+
* some time later. page may be NULL, in which case no freeing will occur.
105105
* Note that the granted page might still be accessed (read or write) by the
106106
* other side after gnttab_end_foreign_access() returns, so even if page was
107-
* specified as 0 it is not allowed to just reuse the page for other
107+
* specified as NULL it is not allowed to just reuse the page for other
108108
* purposes immediately. gnttab_end_foreign_access() will take an additional
109109
* reference to the granted page in this case, which is dropped only after
110110
* the grant is no longer in use.
111111
* This requires that multi page allocations for areas subject to
112112
* gnttab_end_foreign_access() are done via alloc_pages_exact() (and freeing
113113
* via free_pages_exact()) in order to avoid high order pages.
114114
*/
115-
void gnttab_end_foreign_access(grant_ref_t ref, unsigned long page);
115+
void gnttab_end_foreign_access(grant_ref_t ref, struct page *page);
116116

117117
/*
118118
* End access through the given grant reference, iff the grant entry is

0 commit comments

Comments
 (0)