xen/xenbus: Support multiple grants ring with 64KB page
Subsystems (3)
cover xen/xenbus: Support multiple grants ring with 64KB page
Hi all,
The support of multiple grants ring was left aside for 64KB page. This series aims to fix it.
It's based on xentip/for-linus-4.4.
Sincelerely yours,
Julien Grall (3):
xen/xenbus: Rename *RING_PAGE* to *RING_GRANT* xen/grant-table: Add an helper to iterate over a specific number of
grants
xenbus: Support multiple grants ring with 64KB
drivers/block/xen-blkback/blkback.c | 8 +-- drivers/block/xen-blkback/xenbus.c | 2 +- drivers/block/xen-blkfront.c | 10 +-- drivers/xen/grant-table.c | 22 +++++++ drivers/xen/xenbus/xenbus_client.c | 121 +++++++++++++++++++++++++----------- include/xen/grant_table.h | 6 ++ include/xen/xenbus.h | 4 +- 7 files changed, 124 insertions(+), 49 deletions(-)
Signature · 1 line
2.1.4
PATCH 1/3 xen/xenbus: Rename *RING_PAGE* to *RING_GRANT*
Linux may use a different page size than the size of grant. So make clear that the order is actually in number of grant.
---
Cc: Konrad Rzeszutek Wilk <[email protected]>
Cc: "Roger Pau Monné" <[email protected]>
Cc: Boris Ostrovsky <[email protected]>
Cc: David Vrabel <[email protected]>
Cc: Stefano Stabellini <[email protected]>
--- drivers/block/xen-blkback/blkback.c | 8 ++++---- drivers/block/xen-blkback/xenbus.c | 2 +- drivers/block/xen-blkfront.c | 10 +++++----- drivers/xen/xenbus/xenbus_client.c | 34 +++++++++++++++++----------------- include/xen/xenbus.h | 4 ++-- 5 files changed, 29 insertions(+), 29 deletions(-)
drivers/block/xen-blkback/blkback.c +4 -4
@@ -87,7 +87,7 @@ MODULE_PARM_DESC(max_persistent_grants,* Maximum order of pages to be used for the shared ring between front and * backend, 4KB page granularity is used. */ -unsigned int xen_blkif_max_ring_order =XENBUS_MAX_RING_PAGE_ORDER ; +unsigned int xen_blkif_max_ring_order =XENBUS_MAX_RING_GRANT_ORDER ;module_param_named (max_ring_page_order, xen_blkif_max_ring_order, int,S_IRUGO );MODULE_PARM_DESC (max_ring_page_order,"Maximum order of pages to be used for the shared ring" );/*
@@ -1446,10 +1446,10 @@ static int __init xen_blkif_init(void)if (!xen_domain ())return -ENODEV ; -if (xen_blkif_max_ring_order >XENBUS_MAX_RING_PAGE_ORDER ) { +if (xen_blkif_max_ring_order >XENBUS_MAX_RING_GRANT_ORDER ) {pr_info ("Invalid max_ring_order (%d), will use default max: %d.\n" , - xen_blkif_max_ring_order,XENBUS_MAX_RING_PAGE_ORDER ); - xen_blkif_max_ring_order =XENBUS_MAX_RING_PAGE_ORDER ; + xen_blkif_max_ring_order,XENBUS_MAX_RING_GRANT_ORDER ); + xen_blkif_max_ring_order =XENBUS_MAX_RING_GRANT_ORDER ; } rc =xen_blkif_interface_init ();
drivers/block/xen-blkback/xenbus.c +1 -1
@@ -827,7 +827,7 @@ again:static int connect_ring (struct backend_info *be) {struct xenbus_device *dev = be->dev; -unsigned int ring_ref[XENBUS_MAX_RING_PAGES ]; +unsigned int ring_ref[XENBUS_MAX_RING_GRANTS ];unsigned int evtchn, nr_grefs, ring_page_order;unsigned int pers_grants;char protocol[64 ] ="" ;
drivers/block/xen-blkfront.c +5 -5
@@ -111,7 +111,7 @@ MODULE_PARM_DESC(max_ring_page_order, "Maximum order of pages to be used for the __CONST_RING_SIZE(blkif, XEN_PAGE_SIZE * (info)->nr_ring_pages)#define BLK_MAX_RING_SIZE \ - __CONST_RING_SIZE(blkif, XEN_PAGE_SIZE * XENBUS_MAX_RING_PAGES) + __CONST_RING_SIZE(blkif, XEN_PAGE_SIZE * XENBUS_MAX_RING_GRANTS)/* * ring-ref%i i=(-1UL) would take 11 characters + 'ring-ref' is 8, so 19
@@ -133,7 +133,7 @@ struct blkfront_infoint vdevice;blkif_vdev_t handle;enum blkif_state connected; -int ring_ref[XENBUS_MAX_RING_PAGES ]; +int ring_ref[XENBUS_MAX_RING_GRANTS ];unsigned int nr_ring_pages;struct blkif_front_ring ring;unsigned int evtchn, irq;
@@ -1412,7 +1412,7 @@ static int setup_blkring(struct xenbus_device *dev,struct blkif_sring *sring;int err, i;unsigned long ring_size = info->nr_ring_pages *XEN_PAGE_SIZE ; -grant_ref_t gref[XENBUS_MAX_RING_PAGES ]; +grant_ref_t gref[XENBUS_MAX_RING_GRANTS ];for (i =0 ; i < info->nr_ring_pages; i++) info->ring_ref[i] =GRANT_INVALID_REF ;
@@ -2283,9 +2283,9 @@ static int __init xlblk_init(void)if (!xen_domain ())return -ENODEV ; -if (xen_blkif_max_ring_order >XENBUS_MAX_RING_PAGE_ORDER ) { +if (xen_blkif_max_ring_order >XENBUS_MAX_RING_GRANT_ORDER ) {pr_info ("Invalid max_ring_order (%d), will use default max: %d.\n" , - xen_blkif_max_ring_order,XENBUS_MAX_RING_PAGE_ORDER ); + xen_blkif_max_ring_order,XENBUS_MAX_RING_GRANT_ORDER ); xen_blkif_max_ring_order =0 ; }
drivers/xen/xenbus/xenbus_client.c +17 -17
@@ -56,11 +56,11 @@ struct xenbus_map_node {struct vm_struct *area; } pv;struct { -struct page *pages[XENBUS_MAX_RING_PAGES ]; +struct page *pages[XENBUS_MAX_RING_GRANTS ];void *addr; } hvm; }; -grant_handle_t handles[XENBUS_MAX_RING_PAGES ]; +grant_handle_t handles[XENBUS_MAX_RING_GRANTS ];unsigned int nr_handles; };
@@ -479,12 +479,12 @@ static int __xenbus_map_ring(struct xenbus_device *dev,unsigned int flags, bool *leaked) { - struct gnttab_map_grant_ref map[XENBUS_MAX_RING_PAGES]; -struct gnttab_unmap_grant_ref unmap[XENBUS_MAX_RING_PAGES ]; + struct gnttab_map_grant_ref map[XENBUS_MAX_RING_GRANTS]; +struct gnttab_unmap_grant_ref unmap[XENBUS_MAX_RING_GRANTS ];int i, j;int err = GNTST_okay; -if (nr_grefs >XENBUS_MAX_RING_PAGES ) +if (nr_grefs >XENBUS_MAX_RING_GRANTS )return -EINVAL ;for (i =0 ; i < nr_grefs; i++) {
@@ -540,15 +540,15 @@ static int xenbus_map_ring_valloc_pv(struct xenbus_device *dev, {struct xenbus_map_node *node;struct vm_struct *area; -pte_t *ptes[XENBUS_MAX_RING_PAGES ]; -phys_addr_t phys_addrs[XENBUS_MAX_RING_PAGES ]; +pte_t *ptes[XENBUS_MAX_RING_GRANTS ]; +phys_addr_t phys_addrs[XENBUS_MAX_RING_GRANTS ];int err = GNTST_okay;int i;bool leaked; *vaddr =NULL ; -if (nr_grefs >XENBUS_MAX_RING_PAGES ) +if (nr_grefs >XENBUS_MAX_RING_GRANTS )return -EINVAL ; node =kzalloc (sizeof (*node),GFP_KERNEL );
@@ -602,10 +602,10 @@ static int xenbus_map_ring_valloc_hvm(struct xenbus_device *dev,void *addr;bool leaked = false;/* Why do we need two arrays? See comment of __xenbus_map_ring */ -phys_addr_t phys_addrs[XENBUS_MAX_RING_PAGES ]; -unsigned long addrs[XENBUS_MAX_RING_PAGES ]; +phys_addr_t phys_addrs[XENBUS_MAX_RING_GRANTS ]; +unsigned long addrs[XENBUS_MAX_RING_GRANTS ]; -if (nr_grefs >XENBUS_MAX_RING_PAGES ) +if (nr_grefs >XENBUS_MAX_RING_GRANTS )return -EINVAL ; *vaddr =NULL ;
@@ -686,10 +686,10 @@ int xenbus_map_ring(struct xenbus_device *dev, grant_ref_t *gnt_refs, unsigned int nr_grefs, grant_handle_t *handles, unsigned long *vaddrs, bool *leaked) { - phys_addr_t phys_addrs[XENBUS_MAX_RING_PAGES]; + phys_addr_t phys_addrs[XENBUS_MAX_RING_GRANTS];int i; -if (nr_grefs >XENBUS_MAX_RING_PAGES ) +if (nr_grefs >XENBUS_MAX_RING_GRANTS )return -EINVAL ;for (i =0 ; i < nr_grefs; i++)
@@ -722,7 +722,7 @@ EXPORT_SYMBOL_GPL(xenbus_unmap_ring_vfree);static int xenbus_unmap_ring_vfree_pv (struct xenbus_device *dev,void *vaddr) {struct xenbus_map_node *node; -struct gnttab_unmap_grant_ref unmap[XENBUS_MAX_RING_PAGES ]; +struct gnttab_unmap_grant_ref unmap[XENBUS_MAX_RING_GRANTS ];unsigned int level;int i;bool leaked = false;
@@ -787,7 +787,7 @@ static int xenbus_unmap_ring_vfree_hvm(struct xenbus_device *dev, void *vaddr)int rv;struct xenbus_map_node *node;void *addr; -unsigned long addrs[XENBUS_MAX_RING_PAGES ]; +unsigned long addrs[XENBUS_MAX_RING_GRANTS ];int i;spin_lock (&xenbus_valloc_lock);
@@ -840,11 +840,11 @@ int xenbus_unmap_ring(struct xenbus_device *dev, grant_handle_t *handles, unsigned int nr_handles, unsigned long *vaddrs) { - struct gnttab_unmap_grant_ref unmap[XENBUS_MAX_RING_PAGES]; + struct gnttab_unmap_grant_ref unmap[XENBUS_MAX_RING_GRANTS];int i;int err; -if (nr_handles >XENBUS_MAX_RING_PAGES ) +if (nr_handles >XENBUS_MAX_RING_GRANTS )return -EINVAL ;for (i =0 ; i < nr_handles; i++)
include/xen/xenbus.h +2 -2
@@ -46,8 +46,8 @@#include <xen/interface/io/xenbus.h> #include <xen/interface/io/xs_wire.h> -#define XENBUS_MAX_RING_PAGE_ORDER 4 -#define XENBUS_MAX_RING_PAGES (1U << XENBUS_MAX_RING_PAGE_ORDER) +#define XENBUS_MAX_RING_GRANT_ORDER 4 +#define XENBUS_MAX_RING_GRANTS (1U << XENBUS_MAX_RING_GRANT_ORDER)#define INVALID_GRANT_HANDLE (~0U)/* Register callback to watch this node. */
Signature · 7 lines
2.1.4 _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel
PATCH 1/3 xen/xenbus: Rename *RING_PAGE* to *RING_GRANT*
In reply to Julien GrallLinux may use a different page size than the size of grant. So make clear that the order is actually in number of grant.
---
Cc: Konrad Rzeszutek Wilk <[email protected]>
Cc: "Roger Pau Monné" <[email protected]>
Cc: Boris Ostrovsky <[email protected]>
Cc: David Vrabel <[email protected]>
Cc: Stefano Stabellini <[email protected]>
--- drivers/block/xen-blkback/blkback.c | 8 ++++---- drivers/block/xen-blkback/xenbus.c | 2 +- drivers/block/xen-blkfront.c | 10 +++++----- drivers/xen/xenbus/xenbus_client.c | 34 +++++++++++++++++----------------- include/xen/xenbus.h | 4 ++-- 5 files changed, 29 insertions(+), 29 deletions(-)
drivers/block/xen-blkback/blkback.c +4 -4
@@ -87,7 +87,7 @@ MODULE_PARM_DESC(max_persistent_grants,* Maximum order of pages to be used for the shared ring between front and * backend, 4KB page granularity is used. */ -unsigned int xen_blkif_max_ring_order =XENBUS_MAX_RING_PAGE_ORDER ; +unsigned int xen_blkif_max_ring_order =XENBUS_MAX_RING_GRANT_ORDER ;module_param_named (max_ring_page_order, xen_blkif_max_ring_order, int,S_IRUGO );MODULE_PARM_DESC (max_ring_page_order,"Maximum order of pages to be used for the shared ring" );/*
@@ -1446,10 +1446,10 @@ static int __init xen_blkif_init(void)if (!xen_domain ())return -ENODEV ; -if (xen_blkif_max_ring_order >XENBUS_MAX_RING_PAGE_ORDER ) { +if (xen_blkif_max_ring_order >XENBUS_MAX_RING_GRANT_ORDER ) {pr_info ("Invalid max_ring_order (%d), will use default max: %d.\n" , - xen_blkif_max_ring_order,XENBUS_MAX_RING_PAGE_ORDER ); - xen_blkif_max_ring_order =XENBUS_MAX_RING_PAGE_ORDER ; + xen_blkif_max_ring_order,XENBUS_MAX_RING_GRANT_ORDER ); + xen_blkif_max_ring_order =XENBUS_MAX_RING_GRANT_ORDER ; } rc =xen_blkif_interface_init ();
drivers/block/xen-blkback/xenbus.c +1 -1
@@ -827,7 +827,7 @@ again:static int connect_ring (struct backend_info *be) {struct xenbus_device *dev = be->dev; -unsigned int ring_ref[XENBUS_MAX_RING_PAGES ]; +unsigned int ring_ref[XENBUS_MAX_RING_GRANTS ];unsigned int evtchn, nr_grefs, ring_page_order;unsigned int pers_grants;char protocol[64 ] ="" ;
drivers/block/xen-blkfront.c +5 -5
@@ -111,7 +111,7 @@ MODULE_PARM_DESC(max_ring_page_order, "Maximum order of pages to be used for the __CONST_RING_SIZE(blkif, XEN_PAGE_SIZE * (info)->nr_ring_pages)#define BLK_MAX_RING_SIZE \ - __CONST_RING_SIZE(blkif, XEN_PAGE_SIZE * XENBUS_MAX_RING_PAGES) + __CONST_RING_SIZE(blkif, XEN_PAGE_SIZE * XENBUS_MAX_RING_GRANTS)/* * ring-ref%i i=(-1UL) would take 11 characters + 'ring-ref' is 8, so 19
@@ -133,7 +133,7 @@ struct blkfront_infoint vdevice;blkif_vdev_t handle;enum blkif_state connected; -int ring_ref[XENBUS_MAX_RING_PAGES ]; +int ring_ref[XENBUS_MAX_RING_GRANTS ];unsigned int nr_ring_pages;struct blkif_front_ring ring;unsigned int evtchn, irq;
@@ -1412,7 +1412,7 @@ static int setup_blkring(struct xenbus_device *dev,struct blkif_sring *sring;int err, i;unsigned long ring_size = info->nr_ring_pages *XEN_PAGE_SIZE ; -grant_ref_t gref[XENBUS_MAX_RING_PAGES ]; +grant_ref_t gref[XENBUS_MAX_RING_GRANTS ];for (i =0 ; i < info->nr_ring_pages; i++) info->ring_ref[i] =GRANT_INVALID_REF ;
@@ -2283,9 +2283,9 @@ static int __init xlblk_init(void)if (!xen_domain ())return -ENODEV ; -if (xen_blkif_max_ring_order >XENBUS_MAX_RING_PAGE_ORDER ) { +if (xen_blkif_max_ring_order >XENBUS_MAX_RING_GRANT_ORDER ) {pr_info ("Invalid max_ring_order (%d), will use default max: %d.\n" , - xen_blkif_max_ring_order,XENBUS_MAX_RING_PAGE_ORDER ); + xen_blkif_max_ring_order,XENBUS_MAX_RING_GRANT_ORDER ); xen_blkif_max_ring_order =0 ; }
drivers/xen/xenbus/xenbus_client.c +17 -17
@@ -56,11 +56,11 @@ struct xenbus_map_node {struct vm_struct *area; } pv;struct { -struct page *pages[XENBUS_MAX_RING_PAGES ]; +struct page *pages[XENBUS_MAX_RING_GRANTS ];void *addr; } hvm; }; -grant_handle_t handles[XENBUS_MAX_RING_PAGES ]; +grant_handle_t handles[XENBUS_MAX_RING_GRANTS ];unsigned int nr_handles; };
@@ -479,12 +479,12 @@ static int __xenbus_map_ring(struct xenbus_device *dev,unsigned int flags, bool *leaked) { - struct gnttab_map_grant_ref map[XENBUS_MAX_RING_PAGES]; -struct gnttab_unmap_grant_ref unmap[XENBUS_MAX_RING_PAGES ]; + struct gnttab_map_grant_ref map[XENBUS_MAX_RING_GRANTS]; +struct gnttab_unmap_grant_ref unmap[XENBUS_MAX_RING_GRANTS ];int i, j;int err = GNTST_okay; -if (nr_grefs >XENBUS_MAX_RING_PAGES ) +if (nr_grefs >XENBUS_MAX_RING_GRANTS )return -EINVAL ;for (i =0 ; i < nr_grefs; i++) {
@@ -540,15 +540,15 @@ static int xenbus_map_ring_valloc_pv(struct xenbus_device *dev, {struct xenbus_map_node *node;struct vm_struct *area; -pte_t *ptes[XENBUS_MAX_RING_PAGES ]; -phys_addr_t phys_addrs[XENBUS_MAX_RING_PAGES ]; +pte_t *ptes[XENBUS_MAX_RING_GRANTS ]; +phys_addr_t phys_addrs[XENBUS_MAX_RING_GRANTS ];int err = GNTST_okay;int i;bool leaked; *vaddr =NULL ; -if (nr_grefs >XENBUS_MAX_RING_PAGES ) +if (nr_grefs >XENBUS_MAX_RING_GRANTS )return -EINVAL ; node =kzalloc (sizeof (*node),GFP_KERNEL );
@@ -602,10 +602,10 @@ static int xenbus_map_ring_valloc_hvm(struct xenbus_device *dev,void *addr;bool leaked = false;/* Why do we need two arrays? See comment of __xenbus_map_ring */ -phys_addr_t phys_addrs[XENBUS_MAX_RING_PAGES ]; -unsigned long addrs[XENBUS_MAX_RING_PAGES ]; +phys_addr_t phys_addrs[XENBUS_MAX_RING_GRANTS ]; +unsigned long addrs[XENBUS_MAX_RING_GRANTS ]; -if (nr_grefs >XENBUS_MAX_RING_PAGES ) +if (nr_grefs >XENBUS_MAX_RING_GRANTS )return -EINVAL ; *vaddr =NULL ;
@@ -686,10 +686,10 @@ int xenbus_map_ring(struct xenbus_device *dev, grant_ref_t *gnt_refs, unsigned int nr_grefs, grant_handle_t *handles, unsigned long *vaddrs, bool *leaked) { - phys_addr_t phys_addrs[XENBUS_MAX_RING_PAGES]; + phys_addr_t phys_addrs[XENBUS_MAX_RING_GRANTS];int i; -if (nr_grefs >XENBUS_MAX_RING_PAGES ) +if (nr_grefs >XENBUS_MAX_RING_GRANTS )return -EINVAL ;for (i =0 ; i < nr_grefs; i++)
@@ -722,7 +722,7 @@ EXPORT_SYMBOL_GPL(xenbus_unmap_ring_vfree);static int xenbus_unmap_ring_vfree_pv (struct xenbus_device *dev,void *vaddr) {struct xenbus_map_node *node; -struct gnttab_unmap_grant_ref unmap[XENBUS_MAX_RING_PAGES ]; +struct gnttab_unmap_grant_ref unmap[XENBUS_MAX_RING_GRANTS ];unsigned int level;int i;bool leaked = false;
@@ -787,7 +787,7 @@ static int xenbus_unmap_ring_vfree_hvm(struct xenbus_device *dev, void *vaddr)int rv;struct xenbus_map_node *node;void *addr; -unsigned long addrs[XENBUS_MAX_RING_PAGES ]; +unsigned long addrs[XENBUS_MAX_RING_GRANTS ];int i;spin_lock (&xenbus_valloc_lock);
@@ -840,11 +840,11 @@ int xenbus_unmap_ring(struct xenbus_device *dev, grant_handle_t *handles, unsigned int nr_handles, unsigned long *vaddrs) { - struct gnttab_unmap_grant_ref unmap[XENBUS_MAX_RING_PAGES]; + struct gnttab_unmap_grant_ref unmap[XENBUS_MAX_RING_GRANTS];int i;int err; -if (nr_handles >XENBUS_MAX_RING_PAGES ) +if (nr_handles >XENBUS_MAX_RING_GRANTS )return -EINVAL ;for (i =0 ; i < nr_handles; i++)
include/xen/xenbus.h +2 -2
@@ -46,8 +46,8 @@#include <xen/interface/io/xenbus.h> #include <xen/interface/io/xs_wire.h> -#define XENBUS_MAX_RING_PAGE_ORDER 4 -#define XENBUS_MAX_RING_PAGES (1U << XENBUS_MAX_RING_PAGE_ORDER) +#define XENBUS_MAX_RING_GRANT_ORDER 4 +#define XENBUS_MAX_RING_GRANTS (1U << XENBUS_MAX_RING_GRANT_ORDER)#define INVALID_GRANT_HANDLE (~0U)/* Register callback to watch this node. */
Signature · 1 line
2.1.4
PATCH 2/3 xen/grant-table: Add an helper to iterate over a specific number of grants
In reply to Julien GrallWith the 64KB page granularity support on ARM64, a Linux page may be split accross multiple grant.
Currently we have the helper gnttab_foreach_grant_in_grant to break a Linux page based on an offset and a len, but it doesn't fit when we only have a number of grants in hand.
Introduce a new helper which take an array of Linux page and a number of grant and will figure out the address of each grant.
---
Cc: Konrad Rzeszutek Wilk <[email protected]>
Cc: Boris Ostrovsky <[email protected]>
Cc: David Vrabel <[email protected]>
Cc: Stefano Stabellini <[email protected]>
--- drivers/xen/grant-table.c | 22 ++++++++++++++++++++++ include/xen/grant_table.h | 6 ++++++ 2 files changed, 28 insertions(+)
drivers/xen/grant-table.c +22 -0
@@ -802,6 +802,28 @@ void gnttab_foreach_grant_in_range(struct page *page, }EXPORT_SYMBOL_GPL (gnttab_foreach_grant_in_range); +void gnttab_foreach_grant (struct page **pages, +unsigned int nr_grefs, +xen_grant_fn_t fn, +void *data) +{ +unsigned int goffset =0 ; +unsigned long xen_pfn =0 ; +unsigned int i; + +for (i =0 ; i < nr_grefs; i++) { +if ((i %XEN_PFN_PER_PAGE ) ==0 ) { + xen_pfn =page_to_xen_pfn (pages[i /XEN_PFN_PER_PAGE ]); + goffset =0 ; + } + +fn (pfn_to_gfn (xen_pfn), goffset,XEN_PAGE_SIZE , data); + + goffset +=XEN_PAGE_SIZE ; + xen_pfn++; + } +} +int gnttab_map_refs (struct gnttab_map_grant_ref *map_ops,struct gnttab_map_grant_ref *kmap_ops,struct page **pages,unsigned int count)
include/xen/grant_table.h +6 -0
@@ -264,6 +264,12 @@ static inline void gnttab_for_one_grant(struct page *page, unsigned int offset,gnttab_foreach_grant_in_range (page, offset, len, fn, data); } +/* Get @nr_grefs grants from an array of page and call fn for each grant */ +void gnttab_foreach_grant (struct page **pages, +unsigned int nr_grefs, +xen_grant_fn_t fn, +void *data); +/* Get the number of grant in a specified region * * start: Offset from the beginning of the first page
Signature · 1 line
2.1.4
PATCH 2/3 xen/grant-table: Add an helper to iterate over a specific number of grants
In reply to Julien GrallWith the 64KB page granularity support on ARM64, a Linux page may be split accross multiple grant.
Currently we have the helper gnttab_foreach_grant_in_grant to break a Linux page based on an offset and a len, but it doesn't fit when we only have a number of grants in hand.
Introduce a new helper which take an array of Linux page and a number of grant and will figure out the address of each grant.
---
Cc: Konrad Rzeszutek Wilk <[email protected]>
Cc: Boris Ostrovsky <[email protected]>
Cc: David Vrabel <[email protected]>
Cc: Stefano Stabellini <[email protected]>
--- drivers/xen/grant-table.c | 22 ++++++++++++++++++++++ include/xen/grant_table.h | 6 ++++++ 2 files changed, 28 insertions(+)
drivers/xen/grant-table.c +22 -0
@@ -802,6 +802,28 @@ void gnttab_foreach_grant_in_range(struct page *page, }EXPORT_SYMBOL_GPL (gnttab_foreach_grant_in_range); +void gnttab_foreach_grant (struct page **pages, +unsigned int nr_grefs, +xen_grant_fn_t fn, +void *data) +{ +unsigned int goffset =0 ; +unsigned long xen_pfn =0 ; +unsigned int i; + +for (i =0 ; i < nr_grefs; i++) { +if ((i %XEN_PFN_PER_PAGE ) ==0 ) { + xen_pfn =page_to_xen_pfn (pages[i /XEN_PFN_PER_PAGE ]); + goffset =0 ; + } + +fn (pfn_to_gfn (xen_pfn), goffset,XEN_PAGE_SIZE , data); + + goffset +=XEN_PAGE_SIZE ; + xen_pfn++; + } +} +int gnttab_map_refs (struct gnttab_map_grant_ref *map_ops,struct gnttab_map_grant_ref *kmap_ops,struct page **pages,unsigned int count)
include/xen/grant_table.h +6 -0
@@ -264,6 +264,12 @@ static inline void gnttab_for_one_grant(struct page *page, unsigned int offset,gnttab_foreach_grant_in_range (page, offset, len, fn, data); } +/* Get @nr_grefs grants from an array of page and call fn for each grant */ +void gnttab_foreach_grant (struct page **pages, +unsigned int nr_grefs, +xen_grant_fn_t fn, +void *data); +/* Get the number of grant in a specified region * * start: Offset from the beginning of the first page
Signature · 1 line
2.1.4
PATCH 3/3 xenbus: Support multiple grants ring with 64KB
In reply to Julien GrallThe PV ring may use multiple grants and expect them to be mapped contiguously in the virtual memory.
Although, the current code is relying on a Linux page will be mapped to a single grant. On build where Linux is using a different page size than the grant (i.e other than 4KB), the grant will always be mapped on the first 4KB of each Linux page which make the final ring not contiguous in the memory.
This can be fixed by mapping multiple grant in a same Linux page.
---
Cc: Konrad Rzeszutek Wilk <[email protected]>
Cc: Boris Ostrovsky <[email protected]>
Cc: David Vrabel <[email protected]>
Cc: Stefano Stabellini <[email protected]>
--- drivers/xen/xenbus/xenbus_client.c | 97 ++++++++++++++++++++++++++++---------- 1 file changed, 72 insertions(+), 25 deletions(-)
drivers/xen/xenbus/xenbus_client.c +72 -25
@@ -49,6 +49,10 @@#include "xenbus_probe.h" +#define XENBUS_PAGES (_grants) (DIV_ROUND_UP(_grants, XEN_PFN_PER_PAGE)) + +#define XENBUS_MAX_RING_PAGES (XENBUS_PAGES(XENBUS_MAX_RING_GRANTS)) +struct xenbus_map_node {struct list_head next;union {
@@ -56,7 +60,8 @@ struct xenbus_map_node {struct vm_struct *area; } pv;struct { -struct page *pages[XENBUS_MAX_RING_GRANTS ]; +struct page *pages[XENBUS_MAX_RING_PAGES ]; +unsigned long addrs[XENBUS_MAX_RING_GRANTS ];void *addr; } hvm; };
@@ -591,19 +596,42 @@ failed:return err; } +struct map_ring_valloc_hvm +{ +unsigned int idx; + +/* Why do we need two arrays? See comment of __xenbus_map_ring */ +phys_addr_t phys_addrs[XENBUS_MAX_RING_GRANTS ]; +unsigned long addrs[XENBUS_MAX_RING_GRANTS ]; +}; + +static void xenbus_map_ring_setup_grant_hvm (unsigned long gfn, +unsigned int goffset, +unsigned int len, +void *data) +{ +struct map_ring_valloc_hvm *info = data; +unsigned long vaddr = (unsigned long )gfn_to_virt (gfn); + + info->phys_addrs[info->idx] = vaddr; + info->addrs[info->idx] = vaddr; + + info->idx++; +} +static int xenbus_map_ring_valloc_hvm (struct xenbus_device *dev,grant_ref_t *gnt_ref,unsigned int nr_grefs,void **vaddr) {struct xenbus_map_node *node; -int i;int err;void *addr;bool leaked = false; -/* Why do we need two arrays? See comment of __xenbus_map_ring */ -phys_addr_t phys_addrs[XENBUS_MAX_RING_GRANTS ]; -unsigned long addrs[XENBUS_MAX_RING_GRANTS ]; +struct map_ring_valloc_hvm info = { + .idx =0 , + }; +unsigned int nr_pages =XENBUS_PAGES (nr_grefs);if (nr_grefs >XENBUS_MAX_RING_GRANTS )return -EINVAL ;
@@ -614,24 +642,22 @@ static int xenbus_map_ring_valloc_hvm(struct xenbus_device *dev,if (!node)return -ENOMEM ; - err =alloc_xenballooned_pages (nr_grefs, node->hvm.pages); + err =alloc_xenballooned_pages (nr_pages, node->hvm.pages);if (err) goto out_err; -for (i =0 ; i < nr_grefs; i++) { -unsigned long pfn =page_to_pfn (node->hvm.pages[i]); - phys_addrs[i] = (unsigned long )pfn_to_kaddr (pfn); - addrs[i] = (unsigned long )pfn_to_kaddr (pfn); - } +gnttab_foreach_grant (node->hvm.pages, nr_grefs, + xenbus_map_ring_setup_grant_hvm, + &info); err =__xenbus_map_ring (dev, gnt_ref, nr_grefs, node->handles, - phys_addrs, GNTMAP_host_map, &leaked); + info.phys_addrs, GNTMAP_host_map, &leaked); node->nr_handles = nr_grefs;if (err) goto out_free_ballooned_pages; - addr =vmap (node->hvm.pages, nr_grefs,VM_MAP |VM_IOREMAP , + addr =vmap (node->hvm.pages, nr_pages,VM_MAP |VM_IOREMAP ,PAGE_KERNEL );if (!addr) { err = -ENOMEM ;
@@ -649,14 +675,13 @@ static int xenbus_map_ring_valloc_hvm(struct xenbus_device *dev, out_xenbus_unmap_ring:if (!leaked) -xenbus_unmap_ring (dev, node->handles, node->nr_handles, - addrs); +xenbus_unmap_ring (dev, node->handles, nr_grefs, info.addrs);else pr_alert ("leaking %p size %u page(s)" , - addr, nr_grefs); + addr, nr_pages); out_free_ballooned_pages:if (!leaked) -free_xenballooned_pages (nr_grefs, node->hvm.pages); +free_xenballooned_pages (nr_pages, node->hvm.pages); out_err:kfree (node);return err;
@@ -782,13 +807,33 @@ static int xenbus_unmap_ring_vfree_pv(struct xenbus_device *dev, void *vaddr)return err; } +struct unmap_ring_vfree_hvm +{ +unsigned int idx; +unsigned long addrs[XENBUS_MAX_RING_GRANTS ]; +}; + +static void xenbus_unmap_ring_setup_grant_hvm (unsigned long gfn, +unsigned int goffset, +unsigned int len, +void *data) +{ +struct unmap_ring_vfree_hvm *info = data; + + info->addrs[info->idx] = (unsigned long )gfn_to_virt (gfn); + + info->idx++; +} +static int xenbus_unmap_ring_vfree_hvm (struct xenbus_device *dev,void *vaddr) {int rv;struct xenbus_map_node *node;void *addr; -unsigned long addrs[XENBUS_MAX_RING_GRANTS ]; -int i; +struct unmap_ring_vfree_hvm info = { + .idx =0 , + }; +unsigned int nr_pages;spin_lock (&xenbus_valloc_lock);list_for_each_entry (node, &xenbus_valloc_pages, next) {
@@ -808,18 +853,20 @@ static int xenbus_unmap_ring_vfree_hvm(struct xenbus_device *dev, void *vaddr)return GNTST_bad_virt_addr; } -for (i =0 ; i < node->nr_handles; i++) - addrs[i] = (unsigned long )pfn_to_kaddr (page_to_pfn (node->hvm.pages[i])); + nr_pages =XENBUS_PAGES (node->nr_handles); + +gnttab_foreach_grant (node->hvm.pages, node->nr_handles, + xenbus_unmap_ring_setup_grant_hvm, + &info); rv =xenbus_unmap_ring (dev, node->handles, node->nr_handles, - addrs); + info.addrs);if (!rv) {vunmap (vaddr); -free_xenballooned_pages (node->nr_handles, node->hvm.pages); +free_xenballooned_pages (nr_pages, node->hvm.pages); }else -WARN (1 ,"Leaking %p, size %u page(s)\n" , vaddr, - node->nr_handles); +WARN (1 ,"Leaking %p, size %u page(s)\n" , vaddr, nr_pages);kfree (node);return rv;
Signature · 1 line
2.1.4
PATCH 3/3 xenbus: Support multiple grants ring with 64KB
In reply to Julien GrallThe PV ring may use multiple grants and expect them to be mapped contiguously in the virtual memory.
Although, the current code is relying on a Linux page will be mapped to a single grant. On build where Linux is using a different page size than the grant (i.e other than 4KB), the grant will always be mapped on the first 4KB of each Linux page which make the final ring not contiguous in the memory.
This can be fixed by mapping multiple grant in a same Linux page.
---
Cc: Konrad Rzeszutek Wilk <[email protected]>
Cc: Boris Ostrovsky <[email protected]>
Cc: David Vrabel <[email protected]>
Cc: Stefano Stabellini <[email protected]>
--- drivers/xen/xenbus/xenbus_client.c | 97 ++++++++++++++++++++++++++++---------- 1 file changed, 72 insertions(+), 25 deletions(-)
drivers/xen/xenbus/xenbus_client.c +72 -25
@@ -49,6 +49,10 @@#include "xenbus_probe.h" +#define XENBUS_PAGES (_grants) (DIV_ROUND_UP(_grants, XEN_PFN_PER_PAGE)) + +#define XENBUS_MAX_RING_PAGES (XENBUS_PAGES(XENBUS_MAX_RING_GRANTS)) +struct xenbus_map_node {struct list_head next;union {
@@ -56,7 +60,8 @@ struct xenbus_map_node {struct vm_struct *area; } pv;struct { -struct page *pages[XENBUS_MAX_RING_GRANTS ]; +struct page *pages[XENBUS_MAX_RING_PAGES ]; +unsigned long addrs[XENBUS_MAX_RING_GRANTS ];void *addr; } hvm; };
@@ -591,19 +596,42 @@ failed:return err; } +struct map_ring_valloc_hvm +{ +unsigned int idx; + +/* Why do we need two arrays? See comment of __xenbus_map_ring */ +phys_addr_t phys_addrs[XENBUS_MAX_RING_GRANTS ]; +unsigned long addrs[XENBUS_MAX_RING_GRANTS ]; +}; + +static void xenbus_map_ring_setup_grant_hvm (unsigned long gfn, +unsigned int goffset, +unsigned int len, +void *data) +{ +struct map_ring_valloc_hvm *info = data; +unsigned long vaddr = (unsigned long )gfn_to_virt (gfn); + + info->phys_addrs[info->idx] = vaddr; + info->addrs[info->idx] = vaddr; + + info->idx++; +} +static int xenbus_map_ring_valloc_hvm (struct xenbus_device *dev,grant_ref_t *gnt_ref,unsigned int nr_grefs,void **vaddr) {struct xenbus_map_node *node; -int i;int err;void *addr;bool leaked = false; -/* Why do we need two arrays? See comment of __xenbus_map_ring */ -phys_addr_t phys_addrs[XENBUS_MAX_RING_GRANTS ]; -unsigned long addrs[XENBUS_MAX_RING_GRANTS ]; +struct map_ring_valloc_hvm info = { + .idx =0 , + }; +unsigned int nr_pages =XENBUS_PAGES (nr_grefs);if (nr_grefs >XENBUS_MAX_RING_GRANTS )return -EINVAL ;
@@ -614,24 +642,22 @@ static int xenbus_map_ring_valloc_hvm(struct xenbus_device *dev,if (!node)return -ENOMEM ; - err =alloc_xenballooned_pages (nr_grefs, node->hvm.pages); + err =alloc_xenballooned_pages (nr_pages, node->hvm.pages);if (err) goto out_err; -for (i =0 ; i < nr_grefs; i++) { -unsigned long pfn =page_to_pfn (node->hvm.pages[i]); - phys_addrs[i] = (unsigned long )pfn_to_kaddr (pfn); - addrs[i] = (unsigned long )pfn_to_kaddr (pfn); - } +gnttab_foreach_grant (node->hvm.pages, nr_grefs, + xenbus_map_ring_setup_grant_hvm, + &info); err =__xenbus_map_ring (dev, gnt_ref, nr_grefs, node->handles, - phys_addrs, GNTMAP_host_map, &leaked); + info.phys_addrs, GNTMAP_host_map, &leaked); node->nr_handles = nr_grefs;if (err) goto out_free_ballooned_pages; - addr =vmap (node->hvm.pages, nr_grefs,VM_MAP |VM_IOREMAP , + addr =vmap (node->hvm.pages, nr_pages,VM_MAP |VM_IOREMAP ,PAGE_KERNEL );if (!addr) { err = -ENOMEM ;
@@ -649,14 +675,13 @@ static int xenbus_map_ring_valloc_hvm(struct xenbus_device *dev, out_xenbus_unmap_ring:if (!leaked) -xenbus_unmap_ring (dev, node->handles, node->nr_handles, - addrs); +xenbus_unmap_ring (dev, node->handles, nr_grefs, info.addrs);else pr_alert ("leaking %p size %u page(s)" , - addr, nr_grefs); + addr, nr_pages); out_free_ballooned_pages:if (!leaked) -free_xenballooned_pages (nr_grefs, node->hvm.pages); +free_xenballooned_pages (nr_pages, node->hvm.pages); out_err:kfree (node);return err;
@@ -782,13 +807,33 @@ static int xenbus_unmap_ring_vfree_pv(struct xenbus_device *dev, void *vaddr)return err; } +struct unmap_ring_vfree_hvm +{ +unsigned int idx; +unsigned long addrs[XENBUS_MAX_RING_GRANTS ]; +}; + +static void xenbus_unmap_ring_setup_grant_hvm (unsigned long gfn, +unsigned int goffset, +unsigned int len, +void *data) +{ +struct unmap_ring_vfree_hvm *info = data; + + info->addrs[info->idx] = (unsigned long )gfn_to_virt (gfn); + + info->idx++; +} +static int xenbus_unmap_ring_vfree_hvm (struct xenbus_device *dev,void *vaddr) {int rv;struct xenbus_map_node *node;void *addr; -unsigned long addrs[XENBUS_MAX_RING_GRANTS ]; -int i; +struct unmap_ring_vfree_hvm info = { + .idx =0 , + }; +unsigned int nr_pages;spin_lock (&xenbus_valloc_lock);list_for_each_entry (node, &xenbus_valloc_pages, next) {
@@ -808,18 +853,20 @@ static int xenbus_unmap_ring_vfree_hvm(struct xenbus_device *dev, void *vaddr)return GNTST_bad_virt_addr; } -for (i =0 ; i < node->nr_handles; i++) - addrs[i] = (unsigned long )pfn_to_kaddr (page_to_pfn (node->hvm.pages[i])); + nr_pages =XENBUS_PAGES (node->nr_handles); + +gnttab_foreach_grant (node->hvm.pages, node->nr_handles, + xenbus_unmap_ring_setup_grant_hvm, + &info); rv =xenbus_unmap_ring (dev, node->handles, node->nr_handles, - addrs); + info.addrs);if (!rv) {vunmap (vaddr); -free_xenballooned_pages (node->nr_handles, node->hvm.pages); +free_xenballooned_pages (nr_pages, node->hvm.pages); }else -WARN (1 ,"Leaking %p, size %u page(s)\n" , vaddr, - node->nr_handles); +WARN (1 ,"Leaking %p, size %u page(s)\n" , vaddr, nr_pages);kfree (node);return rv;
Signature · 1 line
2.1.4
David Vrabel
AppliedQuoted 4 lines · Julien Grall
Hi all,
The support of multiple grants ring was left aside for 64KB page. This series aims to fix it.
Applied to for-linus-4.4, thanks.
David
David Vrabel
AppliedQuoted 4 lines · Julien Grall
Hi all,
The support of multiple grants ring was left aside for 64KB page. This series aims to fix it.
Applied to for-linus-4.4, thanks.
David