Skip to contentSkip to conversation

9p/xen: Use array for data rings

PATCH In review Rosen Penev 2 participants 2 messages Sep 13 9P file system

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 9p/xen: Use 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.

Assisted-by Codex:GPT-5.5

---
v2: switch to normal array.

 net/9p/trans_xen.c | 66 ++++++++++++++++++++--------------------------
 1 file changed, 29 insertions(+), 37 deletions(-)
net/9p/trans_xen.c +29 -37
index f9fb2db7a066..1e87a55e6042 100644
@@ -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[XEN_9PFS_NUM_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);
@@ -450,11 +447,6 @@ static int xen_9pfs_front_init(struct xenbus_device *dev)
 	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.55.0
#1 lore raw

Rosen Penev wrote on Sun, Sep 13, 2026 at 12:27:40PM -0700:

Quoted 10 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.5

---
v2: switch to normal array.

Thanks, looks good to me, picked up.

net/9p/trans_xen.c static void xen_9pfs_front_free(struct xen_9pfs_front_priv *priv) · line 293

Quoted 4 lines
net/9p/trans_xen.c +2 -2
-				for (j = 0; j < (1 << ring->intf->ring_order);
-				     j++) {
+			for (j = 0; j < (1 << ring->intf->ring_order);
+			     j++) {

^ now fits in a single line within 80 chars so I've rewrapped it

Signature · 1 line
Dominique