9p/xen: Use flexible array for data rings
PATCH 1/1 9p/xen: Use flexible array for data rings
Store the fixed set of Xen 9p data rings in the frontend private allocation instead of allocating a separate rings array.
This keeps the data ring storage tied to the frontend lifetime and simplifies the allocation and cleanup paths.
--- net/9p/trans_xen.c | 68 ++++++++++++++++++++-------------------------- 1 file changed, 30 insertions(+), 38 deletions(-)
net/9p/trans_xen.c +30 -38
@@ -55,7 +55,7 @@ struct xen_9pfs_front_priv {char *tag;struct p9_client *client; -struct xen_9pfs_dataring *rings; +struct xen_9pfs_dataring rings[]; };static LIST_HEAD (xen_9pfs_devs);
@@ -277,41 +277,38 @@ static void xen_9pfs_front_free(struct xen_9pfs_front_priv *priv) {int i, j; -if (priv->rings) { -for (i =0 ; i <XEN_9PFS_NUM_RINGS ; i++) { -struct xen_9pfs_dataring *ring = &priv->rings[i]; +for (i =0 ; i <XEN_9PFS_NUM_RINGS ; i++) { +struct xen_9pfs_dataring *ring = &priv->rings[i]; -cancel_work_sync (&ring->work); +cancel_work_sync (&ring->work); -if (!ring->intf) -break ; -if (ring->irq >=0 ) { -unbind_from_irqhandler (ring->irq, ring); - ring->irq =-1 ; - } -if (ring->data.in) { -for (j =0 ; j < (1 << ring->intf->ring_order); - j++) { -grant_ref_t ref; - - ref = ring->intf->ref[j]; -gnttab_end_foreign_access (ref,NULL ); - ring->intf->ref[j] =INVALID_GRANT_REF ; - } -free_pages_exact (ring->data.in, -1UL << (ring->intf->ring_order + -XEN_PAGE_SHIFT )); - ring->data.in =NULL ; - ring->data.out =NULL ; - } -if (ring->ref !=INVALID_GRANT_REF ) { -gnttab_end_foreign_access (ring->ref,NULL ); - ring->ref =INVALID_GRANT_REF ; +if (!ring->intf) +break ; +if (ring->irq >=0 ) { +unbind_from_irqhandler (ring->irq, ring); + ring->irq =-1 ; + } +if (ring->data.in) { +for (j =0 ; j < (1 << ring->intf->ring_order); + j++) { +grant_ref_t ref; + + ref = ring->intf->ref[j]; +gnttab_end_foreign_access (ref,NULL ); + ring->intf->ref[j] =INVALID_GRANT_REF ; } -free_page ((unsigned long )ring->intf); - ring->intf =NULL ; +free_pages_exact (ring->data.in, +1UL << (ring->intf->ring_order + +XEN_PAGE_SHIFT )); + ring->data.in =NULL ; + ring->data.out =NULL ; } -kfree (priv->rings); +if (ring->ref !=INVALID_GRANT_REF ) { +gnttab_end_foreign_access (ring->ref,NULL ); + ring->ref =INVALID_GRANT_REF ; + } +free_page ((unsigned long )ring->intf); + ring->intf =NULL ; }kfree (priv->tag);kfree (priv);
@@ -446,15 +443,10 @@ static int xen_9pfs_front_init(struct xenbus_device *dev)if (p9_xen_trans.maxsize >XEN_FLEX_RING_SIZE (max_ring_order)) p9_xen_trans.maxsize =XEN_FLEX_RING_SIZE (max_ring_order) /2 ; - priv =kzalloc_obj (*priv); + priv =kzalloc_flex (*priv, rings,XEN_9PFS_NUM_RINGS );if (!priv)return -ENOMEM ; priv->dev = dev; - priv->rings =kzalloc_objs (*priv->rings,XEN_9PFS_NUM_RINGS ); -if (!priv->rings) { -kfree (priv); -return -ENOMEM ; - }for (i =0 ; i <XEN_9PFS_NUM_RINGS ; i++) { priv->rings[i].priv = priv;
Signature · 1 line
2.54.0
Quoted 17 lines · Rosen Penev
Store the fixed set of Xen 9p data rings in the frontend private allocation instead of allocating a separate rings array.
This keeps the data ring storage tied to the frontend lifetime and simplifies the allocation and cleanup paths.
Assisted-by Codex:GPT-5.5Signed-off-by Rosen Penev <[email protected]>--- net/9p/trans_xen.c | 68 ++++++++++++++++++++-------------------------- 1 file changed, 30 insertions(+), 38 deletions(-)net/9p/trans_xen.c +0
-0
net/9p/trans_xen.c struct xen_9pfs_front_priv { · line 58
Quoted 5 lines
net/9p/trans_xen.c +1
-1@@ -55,7 +55,7 @@ struct xen_9pfs_front_priv {char *tag;struct p9_client *client; -struct xen_9pfs_dataring *rings; +struct xen_9pfs_dataring rings[];
Any reason not to use rings[XEN_9PFS_NUM_RINGS] instead of a flex array?
The number of rings is a compile time constant, after all!
Juergen
Quoted 22 lines · Jürgen Groß
Quoted 20 lines · Rosen Penev
Store the fixed set of Xen 9p data rings in the frontend private allocation instead of allocating a separate rings array.
This keeps the data ring storage tied to the frontend lifetime and simplifies the allocation and cleanup paths.
Assisted-by Codex:GPT-5.5Signed-off-by Rosen Penev <[email protected]>--- net/9p/trans_xen.c | 68 ++++++++++++++++++++-------------------------- 1 file changed, 30 insertions(+), 38 deletions(-)net/9p/trans_xen.c +0
-0@@ -55,7 +55,7 @@ struct xen_9pfs_front_priv {char *tag;struct p9_client *client;
Quoted 6 lines
net/9p/trans_xen.c struct xen_9pfs_front_priv { · line 58
Quoted 2 lines
net/9p/trans_xen.c +1
-1-struct xen_9pfs_dataring *rings; +struct xen_9pfs_dataring rings[];Any reason not to use rings[XEN_9PFS_NUM_RINGS] instead of a flex array?
The number of rings is a compile time constant, after all!
flexibility really. I don't know if this will ever change.
Quoted 3 lines
Juergen
Quoted 23 lines · Rosen Penev
Quoted 22 lines · Jürgen Groß
Quoted 20 lines · Rosen Penev
Store the fixed set of Xen 9p data rings in the frontend private allocation instead of allocating a separate rings array.
This keeps the data ring storage tied to the frontend lifetime and simplifies the allocation and cleanup paths.
Assisted-by Codex:GPT-5.5Signed-off-by Rosen Penev <[email protected]>--- net/9p/trans_xen.c | 68 ++++++++++++++++++++-------------------------- 1 file changed, 30 insertions(+), 38 deletions(-)net/9p/trans_xen.c +0
-0@@ -55,7 +55,7 @@ struct xen_9pfs_front_priv {char *tag;struct p9_client *client;
Quoted 7 lines
Quoted 6 lines
net/9p/trans_xen.c struct xen_9pfs_front_priv { · line 58
Quoted 2 lines
net/9p/trans_xen.c +1
-1-struct xen_9pfs_dataring *rings; +struct xen_9pfs_dataring rings[];Any reason not to use rings[XEN_9PFS_NUM_RINGS] instead of a flex array?
The number of rings is a compile time constant, after all!
flexibility really. I don't know if this will ever change.
If it ever changes we can still switch to a flex array.
Juergen
Dominique Martinet
maintainerJürgen Groß wrote on Wed, May 27, 2026 at 07:39:07AM +0200:
Quoted 13 lines · Rosen Penev
Quoted 12 lines
Store the fixed set of Xen 9p data rings in the frontend private allocation instead of allocating a separate rings array.
This keeps the data ring storage tied to the frontend lifetime and simplifies the allocation and cleanup paths.
Assisted-by Codex:GPT-5.5Signed-off-by Rosen Penev <[email protected]>--- net/9p/trans_xen.c | 68 ++++++++++++++++++++-------------------------- 1 file changed, 30 insertions(+), 38 deletions(-)
Quoted 11 lines
net/9p/trans_xen.c struct xen_9pfs_front_priv { · line 57
Quoted 9 lines
net/9p/trans_xen.c +1
-1@@ -55,7 +55,7 @@ struct xen_9pfs_front_priv {char *tag;struct p9_client *client; -struct xen_9pfs_dataring *rings; +struct xen_9pfs_dataring rings[];Any reason not to use rings[XEN_9PFS_NUM_RINGS] instead of a flex array?
Rosen, do you intend to resend with this fixed number?
Given that's just a two line diff from your patch (just changing the type and keeping kzalloc_obj instead of kzalloc_flex) I can do it myself but I also don't have any direct merit from it, so if I don't hear back I'll forget about this
(unless Jürgen says he actually read the whole diff and it's worth taking for simplification, I don't have time...)
Thanks,
Signature · 1 line
Dominique Martinet | Asmadeus
Quoted 27 lines · Dominique Martinet
Jürgen Groß wrote on Wed, May 27, 2026 at 07:39:07AM +0200:
Quoted 13 lines · Rosen Penev
Quoted 12 lines
Store the fixed set of Xen 9p data rings in the frontend private allocation instead of allocating a separate rings array.
This keeps the data ring storage tied to the frontend lifetime and simplifies the allocation and cleanup paths.
Assisted-by Codex:GPT-5.5Signed-off-by Rosen Penev <[email protected]>--- net/9p/trans_xen.c | 68 ++++++++++++++++++++-------------------------- 1 file changed, 30 insertions(+), 38 deletions(-)Quoted 11 lines
net/9p/trans_xen.c struct xen_9pfs_front_priv { · line 57
Quoted 9 lines
net/9p/trans_xen.c +1
-1@@ -55,7 +55,7 @@ struct xen_9pfs_front_priv {char *tag;struct p9_client *client; -struct xen_9pfs_dataring *rings; +struct xen_9pfs_dataring rings[];Any reason not to use rings[XEN_9PFS_NUM_RINGS] instead of a flex array?
Quoted 1 line
Rosen, do you intend to resend with this fixed number?
Sent
Quoted 11 lines
Given that's just a two line diff from your patch (just changing the type and keeping
kzalloc_objinstead ofkzalloc_flex) I can do it myself but I also don't have any direct merit from it, so if I don't hear back I'll forget about this
(unless Jürgen says he actually read the whole diff and it's worth taking for simplification, I don't have time...)Thanks,
--
Dominique Martinet | Asmadeus