Skip to content

Commit b723cae

Browse files
Christoph Hellwigtorvalds
authored andcommitted
xen/xenbus: use apply_to_page_range directly in xenbus_map_ring_pv
Replacing alloc_vm_area with get_vm_area_caller + apply_page_range allows to fill put the phys_addr values directly instead of doing another loop over all addresses. Signed-off-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Reviewed-by: Boris Ostrovsky <boris.ostrovsky@oracle.com> Cc: Chris Wilson <chris@chris-wilson.co.uk> Cc: Jani Nikula <jani.nikula@linux.intel.com> Cc: Joonas Lahtinen <joonas.lahtinen@linux.intel.com> Cc: Juergen Gross <jgross@suse.com> Cc: Matthew Auld <matthew.auld@intel.com> Cc: "Matthew Wilcox (Oracle)" <willy@infradead.org> Cc: Minchan Kim <minchan@kernel.org> Cc: Nitin Gupta <ngupta@vflare.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Rodrigo Vivi <rodrigo.vivi@intel.com> Cc: Stefano Stabellini <sstabellini@kernel.org> Cc: Tvrtko Ursulin <tvrtko.ursulin@intel.com> Cc: Uladzislau Rezki (Sony) <urezki@gmail.com> Link: https://lkml.kernel.org/r/20201002122204.1534411-10-hch@lst.de Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 534a668 commit b723cae

1 file changed

Lines changed: 16 additions & 14 deletions

File tree

drivers/xen/xenbus/xenbus_client.c

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -73,16 +73,13 @@ struct map_ring_valloc {
7373
struct xenbus_map_node *node;
7474

7575
/* Why do we need two arrays? See comment of __xenbus_map_ring */
76-
union {
77-
unsigned long addrs[XENBUS_MAX_RING_GRANTS];
78-
pte_t *ptes[XENBUS_MAX_RING_GRANTS];
79-
};
76+
unsigned long addrs[XENBUS_MAX_RING_GRANTS];
8077
phys_addr_t phys_addrs[XENBUS_MAX_RING_GRANTS];
8178

8279
struct gnttab_map_grant_ref map[XENBUS_MAX_RING_GRANTS];
8380
struct gnttab_unmap_grant_ref unmap[XENBUS_MAX_RING_GRANTS];
8481

85-
unsigned int idx; /* HVM only. */
82+
unsigned int idx;
8683
};
8784

8885
static DEFINE_SPINLOCK(xenbus_valloc_lock);
@@ -686,6 +683,14 @@ int xenbus_unmap_ring_vfree(struct xenbus_device *dev, void *vaddr)
686683
EXPORT_SYMBOL_GPL(xenbus_unmap_ring_vfree);
687684

688685
#ifdef CONFIG_XEN_PV
686+
static int map_ring_apply(pte_t *pte, unsigned long addr, void *data)
687+
{
688+
struct map_ring_valloc *info = data;
689+
690+
info->phys_addrs[info->idx++] = arbitrary_virt_to_machine(pte).maddr;
691+
return 0;
692+
}
693+
689694
static int xenbus_map_ring_pv(struct xenbus_device *dev,
690695
struct map_ring_valloc *info,
691696
grant_ref_t *gnt_refs,
@@ -694,18 +699,15 @@ static int xenbus_map_ring_pv(struct xenbus_device *dev,
694699
{
695700
struct xenbus_map_node *node = info->node;
696701
struct vm_struct *area;
697-
int err = GNTST_okay;
698-
int i;
699-
bool leaked;
702+
bool leaked = false;
703+
int err = -ENOMEM;
700704

701-
area = alloc_vm_area(XEN_PAGE_SIZE * nr_grefs, info->ptes);
705+
area = get_vm_area(XEN_PAGE_SIZE * nr_grefs, VM_IOREMAP);
702706
if (!area)
703707
return -ENOMEM;
704-
705-
for (i = 0; i < nr_grefs; i++)
706-
info->phys_addrs[i] =
707-
arbitrary_virt_to_machine(info->ptes[i]).maddr;
708-
708+
if (apply_to_page_range(&init_mm, (unsigned long)area->addr,
709+
XEN_PAGE_SIZE * nr_grefs, map_ring_apply, info))
710+
goto failed;
709711
err = __xenbus_map_ring(dev, gnt_refs, nr_grefs, node->handles,
710712
info, GNTMAP_host_map | GNTMAP_contains_pte,
711713
&leaked);

0 commit comments

Comments
 (0)