Skip to contentSkip to conversation

make protocol specific usage of shared sring explicit

PATCH In review Ian Campbell 3 participants 8 messages Jul 1, 2010 – Jul 5, 2010 Xen hypervisor interface

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 make protocol specific usage of shared sring explicit

I don't think protocol specific data't really belongs in this header but since it is already there and we seem to be stuck with it lets at least make the users explicit lest people get caught out by future new fields moving the pad field around.

This is the Xen portion of this change. The kernel portion will be sent separately. There is no dependency between the two.

Cc Jeremy Fitzhardinge <[email protected]>
Cc Daniel Stodden <[email protected]>
Cc Dongxiao Xu <[email protected]>
tools/blktap2/drivers/tapdisk-vbd.c +1 -1
diff -r aecf092da748 -r 9fb06660a061 tools/blktap2/drivers/tapdisk-vbd.c
@@ -1684,7 +1684,7 @@
 	if (!vbd->ring.sring)
 		return -EINVAL;
 
-	switch (vbd->ring.sring->pad[0]) {
+	switch (vbd->ring.sring->private.tapif_user.msg) {
 	case 0:
 		return 0;
 
xen/include/public/io/ring.h +10 -2
diff -r aecf092da748 -r 9fb06660a061 xen/include/public/io/ring.h
@@ -103,8 +103,16 @@
 struct __name##_sring {                                                 \
     RING_IDX req_prod, req_event;                                       \
     RING_IDX rsp_prod, rsp_event;                                       \
-    uint8_t  netfront_smartpoll_active;                                 \
-    uint8_t  pad[47];                                                   \
+    union {                                                             \
+        struct {                                                        \
+            uint8_t smartpoll_active;                                   \
+        } netif;                                                        \
+        struct {                                                        \
+            uint8_t msg;                                                \
+        } tapif_user;                                                   \
+        uint8_t pvt_pad[4];                                             \
+    } private;                                                          \
+    uint8_t pad[44];                                                    \
     union __name##_sring_entry ring[1]; /* variable-length */           \
 };                                                                      \
                                                                         \
#1 lore raw

PATCH 1/1 make protocol specific usage of shared sring explicit

I don't think protocol specific data't really belongs in this header but since it is already there and we seem to be stuck with it lets at least make the users explicit lest people get caught out by future new fields moving the pad field around.

This is the kernel portion of this change. The Xen portion was sent separately. There is no dependency between the two.

I was unable to find the netfront portion of the smartpoll code in the merge branches. Looks like it is in the xen/netfront branch but not merged anywhere.

Cc Jeremy Fitzhardinge <[email protected]>
Cc Daniel Stodden <[email protected]>
Cc Dongxiao Xu <[email protected]>
---
 drivers/xen/blktap/ring.c       |    4 ++--
 drivers/xen/blktap/sysfs.c      |    3 ++-
 drivers/xen/netback/netback.c   |   13 ++++++-------
 include/xen/interface/io/ring.h |   12 ++++++++++--
 4 files changed, 20 insertions(+), 12 deletions(-)
drivers/xen/blktap/ring.c +2 -2
index b49c478..d7d0c79 100644
@@ -335,7 +335,7 @@ blktap_ring_set_message(struct blktap *tap, int msg)
 	struct blktap_ring *ring = &tap->ring;
 
 	if (ring->ring.sring)
-		ring->ring.sring->pad[0] = msg;
+		ring->ring.sring->private.tapif_user.msg = msg;
 }
 
 static int
@@ -400,7 +400,7 @@ static unsigned int blktap_ring_poll(struct file *filp, poll_table *wait)
 	up_read(&current->mm->mmap_sem);
 
 	if (work ||
-	    ring->ring.sring->pad[0])
+	    ring->ring.sring->private.tapif_user.msg)
 		return POLLIN | POLLRDNORM;
 
 	return 0;
drivers/xen/blktap/sysfs.c +2 -1
index 49f5e67..53f3b95 100644
@@ -97,6 +97,7 @@ blktap_sysfs_remove_device(struct device *dev,
 			   const char *buf, size_t size)
 {
 	struct blktap *tap = (struct blktap *)dev_get_drvdata(dev);
+	struct blktap_ring *ring = &tap->ring;
 
 	if (!tap->ring.dev)
 		return size;
@@ -105,7 +106,7 @@ blktap_sysfs_remove_device(struct device *dev,
 		return -EBUSY;
 
 	BTDBG("sending tapdisk close message\n");
-	tap->ring.ring.sring->pad[0] = BLKTAP2_RING_MESSAGE_CLOSE;
+	ring->sring->private.tapif_user.msg = BLKTAP2_RING_MESSAGE_CLOSE;
 	blktap_ring_kick_user(tap);
 	wait_event_interruptible(tap->wq,
 				 !test_bit(BLKTAP_CONTROL, &tap->dev_inuse));
drivers/xen/netback/netback.c +6 -7
index 9a7ada2..29b60c8 100644
@@ -729,11 +729,10 @@ static void net_rx_action(unsigned long data)
 		 * netfront_smartpoll_active indicates whether
 		 * netfront timer is active.
 		 */
-		if ((netif->smart_poll == 1)) {
-			if (!(netif->rx.sring->netfront_smartpoll_active)) {
-				notify_remote_via_irq(irq);
-				netif->rx.sring->netfront_smartpoll_active = 1;
-			}
+		if ((netif->smart_poll == 1) &&
+		    !(netif->rx.sring->private.netif.smartpoll_active)) {
+			notify_remote_via_irq(irq);
+			netif->rx.sring->private.netif.smartpoll_active = 1;
 		}
 
 		netif_put(netif);
@@ -1612,9 +1611,9 @@ static void make_tx_response(struct xen_netif *netif,
 	 * is active.
 	 */
 	if ((netif->smart_poll == 1)) {
-		if (!(netif->rx.sring->netfront_smartpoll_active)) {
+		if (!(netif->rx.sring->private.netif.smartpoll_active)) {
 			notify_remote_via_irq(netif->irq);
-			netif->rx.sring->netfront_smartpoll_active = 1;
+			netif->rx.sring->private.netif.smartpoll_active = 1;
 		}
 	} else if (notify)
 		notify_remote_via_irq(netif->irq);
include/xen/interface/io/ring.h +10 -2
index 865dcf0..7b301fa 100644
@@ -73,8 +73,16 @@ union __name##_sring_entry {						\
 struct __name##_sring {							\
     RING_IDX req_prod, req_event;					\
     RING_IDX rsp_prod, rsp_event;					\
-    uint8_t  netfront_smartpoll_active;					\
-    uint8_t  pad[47];							\
+    union {								\
+        struct {							\
+            uint8_t smartpoll_active;					\
+        } netif;							\
+        struct {							\
+            uint8_t msg;						\
+        } tapif_user;							\
+        uint8_t pvt_pad[4];						\
+    } private;								\
+    uint8_t pad[44];							\
     union __name##_sring_entry ring[1]; /* variable-length */		\
 };									\
 									\
Signature · 1 line
1.5.6.5
#2 lore raw
Quoted 4 lines · Ian Campbell

I don't think protocol specific data't really belongs in this header but since it is already there and we seem to be stuck with it lets at least make the users explicit lest people get caught out by future new fields moving the pad field around.

The blktap use of the pad field was/is used as a back channel of sorts to communicate device shutdown from the toolstack to the userspace tapdisk process via a sysfs write which set the flag in pad[0] which the tapdisk userspace picked up. This has now been replaced by a unix domain socket control interface (tap-ctl) allowing communication directly between the toolstack and the tapdisk process (a much cleaner and preferable interface).

However the interface between userspace and kernel was inadvertently changed when the netfront smartpoll feature was added to netback due to the new field in the shared ring which caused the the poll[0] field to move up by one in the structure.

On the kernel side smartpoll change was apparently merged into xen/master in October 2009 and on the hypervisor side the it is present in Xen 4.0. So it seems that we have combinations in the wild of kernel blktap and tapdisk userspace both independently using one of two possible offsets of pad[0].

Perhaps this interface would be better deprecated and removed sooner rather than later? Is the tap-ctl baked enough to consider for Xen 4.0.1?

Ian.

#3 lore raw

PATCH 1/1 make shared ring pad field less enticing for users by adding a __ prefix

In reply to Ian Campbell
Cc Jeremy Fitzhardinge <[email protected]>
Cc Daniel Stodden <[email protected]>
Cc Dongxiao Xu <[email protected]>
---
 include/xen/interface/io/ring.h |    5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)
include/xen/interface/io/ring.h +3 -2
index 7b301fa..fae3296 100644
@@ -82,7 +82,7 @@ struct __name##_sring {							\
         } tapif_user;							\
         uint8_t pvt_pad[4];						\
     } private;								\
-    uint8_t pad[44];							\
+    uint8_t __pad[44];							\
     union __name##_sring_entry ring[1]; /* variable-length */		\
 };									\
 									\
@@ -121,7 +121,8 @@ struct __name##_back_ring {						\
 #define SHARED_RING_INIT(_s) do {					\
     (_s)->req_prod  = (_s)->rsp_prod  = 0;				\
     (_s)->req_event = (_s)->rsp_event = 1;				\
-    memset((_s)->pad, 0, sizeof((_s)->pad));				\
+    memset((_s)->private.pvt_pad, 0, sizeof((_s)->private.pvt_pad));	\
+    memset((_s)->__pad, 0, sizeof((_s)->__pad));			\
 } while(0)
 
 #define FRONT_RING_INIT(_r, _s, __size) do {				\
Signature · 1 line
1.5.6.5
#4 lore raw
In reply to Ian Campbell

Could we get the relevant bits (the netback part apparently needs to be dropped) of this change also into the 2.6.18 tree please, so that issues won't arise the next time the public headers get sync-ed over as a whole?

Thanks, Jan

Quoted 8 lines
Quoted 1 line
Quoted 1 line · Ian Campbell

I don't think protocol specific data't really belongs in this header but since it is already there and we seem to be stuck with it lets at least make the users explicit lest people get caught out by future new fields moving the pad field around.

This is the kernel portion of this change. The Xen portion was sent separately. There is no dependency between the two.

As a side note: This isn't really true, as the patch moves the field blktap uses, and hence tools and kernel ought to be changed at the same time.

Quoted 114 lines

I was unable to find the netfront portion of the smartpoll code in the merge branches. Looks like it is in the xen/netfront branch but not merged anywhere.

Cc Jeremy Fitzhardinge <[email protected]>
Cc Daniel Stodden <[email protected]>
Cc Dongxiao Xu <[email protected]>
---
 drivers/xen/blktap/ring.c       |    4 ++--
 drivers/xen/blktap/sysfs.c      |    3 ++-
 drivers/xen/netback/netback.c   |   13 ++++++-------
 include/xen/interface/io/ring.h |   12 ++++++++++--
 4 files changed, 20 insertions(+), 12 deletions(-)
drivers/xen/blktap/ring.c +2 -2
index b49c478..d7d0c79 100644
@@ -335,7 +335,7 @@ blktap_ring_set_message(struct blktap *tap, int msg)
 	struct blktap_ring *ring = &tap->ring;
 
 	if (ring->ring.sring)
-		ring->ring.sring->pad[0] = msg;
+		ring->ring.sring->private.tapif_user.msg = msg;
 }
 
 static int
@@ -400,7 +400,7 @@ static unsigned int blktap_ring_poll(struct file *filp, 
 poll_table *wait)
 	up_read(&current->mm->mmap_sem);
 
 	if (work ||
-	    ring->ring.sring->pad[0])
+	    ring->ring.sring->private.tapif_user.msg)
 		return POLLIN | POLLRDNORM;
 
drivers/xen/blktap/ring.c +0 -0
 	return 0;
drivers/xen/blktap/sysfs.c +2 -1
index 49f5e67..53f3b95 100644
@@ -97,6 +97,7 @@ blktap_sysfs_remove_device(struct device *dev,
 			   const char *buf, size_t size)
 {
 	struct blktap *tap = (struct blktap *)dev_get_drvdata(dev);
+	struct blktap_ring *ring = &tap->ring;
 
 	if (!tap->ring.dev)
 		return size;
@@ -105,7 +106,7 @@ blktap_sysfs_remove_device(struct device *dev,
 		return -EBUSY;
 
 	BTDBG("sending tapdisk close message\n");
-	tap->ring.ring.sring->pad[0] = BLKTAP2_RING_MESSAGE_CLOSE;
+	ring->sring->private.tapif_user.msg = BLKTAP2_RING_MESSAGE_CLOSE;
 	blktap_ring_kick_user(tap);
 	wait_event_interruptible(tap->wq,
 				 !test_bit(BLKTAP_CONTROL, &tap->dev_inuse));
drivers/xen/netback/netback.c +6 -7
index 9a7ada2..29b60c8 100644
@@ -729,11 +729,10 @@ static void net_rx_action(unsigned long data)
 		 * netfront_smartpoll_active indicates whether
 		 * netfront timer is active.
 		 */
-		if ((netif->smart_poll == 1)) {
-			if (!(netif->rx.sring->netfront_smartpoll_active)) {
-				notify_remote_via_irq(irq);
-				netif->rx.sring->netfront_smartpoll_active = 1;
-			}
+		if ((netif->smart_poll == 1) &&
+		    !(netif->rx.sring->private.netif.smartpoll_active)) {
+			notify_remote_via_irq(irq);
+			netif->rx.sring->private.netif.smartpoll_active = 1;
 		}
 
 		netif_put(netif);
@@ -1612,9 +1611,9 @@ static void make_tx_response(struct xen_netif *netif,
 	 * is active.
 	 */
 	if ((netif->smart_poll == 1)) {
-		if (!(netif->rx.sring->netfront_smartpoll_active)) {
+		if (!(netif->rx.sring->private.netif.smartpoll_active)) {
 			notify_remote_via_irq(netif->irq);
-			netif->rx.sring->netfront_smartpoll_active = 1;
+			netif->rx.sring->private.netif.smartpoll_active = 1;
 		}
 	} else if (notify)
 		notify_remote_via_irq(netif->irq);
include/xen/interface/io/ring.h +10 -2
index 865dcf0..7b301fa 100644
@@ -73,8 +73,16 @@ union __name##_sring_entry {						\
 struct __name##_sring {							\
     RING_IDX req_prod, req_event;					\
     RING_IDX rsp_prod, rsp_event;					\
-    uint8_t  netfront_smartpoll_active;					\
-    uint8_t  pad[47];							\
+    union {								\
+        struct {							\
+            uint8_t smartpoll_active;					\
+        } netif;							\
+        struct {							\
+            uint8_t msg;						\
+        } tapif_user;							\
+        uint8_t pvt_pad[4];						\
+    } private;								\
+    uint8_t pad[44];							\
     union __name##_sring_entry ring[1]; /* variable-length */		\
 };									\
 									\
#5 lore raw
In reply to Ian Campbell
Quoted 9 lines
Quoted 1 line
Quoted 1 line · Ian Campbell
xen/include/public/io/ring.h +0 -2
@@ -103,8 +103,16 @@
 struct __name##_sring {                                                 \
     RING_IDX req_prod, req_event;                                       \
     RING_IDX rsp_prod, rsp_event;                                       \
-    uint8_t  netfront_smartpoll_active;                                 \
-    uint8_t  pad[47];                                                   \

xen/include/public/io/ring.h line 115

Quoted 10 lines
xen/include/public/io/ring.h +10 -0
+    union {                                                             \
+        struct {                                                        \
+            uint8_t smartpoll_active;                                   \
+        } netif;                                                        \
+        struct {                                                        \
+            uint8_t msg;                                                \
+        } tapif_user;                                                   \
+        uint8_t pvt_pad[4];                                             \
+    } private;                                                          \
+    uint8_t pad[44];                                                    \

Since this is source incompatible for consumers anyway, wouldn't it be better to rename the new pad[] to e.g. _pad[], so that builds of unchanged consumers fail instead of producing runtime incompatible code?

Jan

#6 lore raw
Quoted 16 lines · Jan Beulich
Quoted 16 lines
Quoted 1 line
Quoted 1 line · Ian Campbell
xen/include/public/io/ring.h +7 -2
@@ -103,8 +103,16 @@
 struct __name##_sring {                                                 \
     RING_IDX req_prod, req_event;                                       \
     RING_IDX rsp_prod, rsp_event;                                       \
-    uint8_t  netfront_smartpoll_active;                                 \
-    uint8_t  pad[47];                                                   \
+    union {                                                             \
+        struct {                                                        \
+            uint8_t smartpoll_active;                                   \
+        } netif;                                                        \
+        struct {                                                        \
+            uint8_t msg;                                                \
+        } tapif_user;                                                   \
Quoted 8 lines

xen/include/public/io/ring.h line 115

Quoted 3 lines
xen/include/public/io/ring.h +3 -0
+        uint8_t pvt_pad[4];                                             \
+    } private;                                                          \
+    uint8_t pad[44];                                                    \

Since this is source incompatible for consumers anyway, wouldn't it be better to rename the new pad[] to e.g. _pad[], so that builds of unchanged consumers fail instead of producing runtime incompatible code?

Yes, that's a good idea. I'll follow up with a patch to use __pad (I think the single _ namespace is reserved for libc or some such)

Ian.

#7 lore raw

PATCH 1/1 make shared ring pad field less enticing for users by adding a __ prefix

In reply to Ian Campbell
Cc Jeremy Fitzhardinge <[email protected]>
Cc Daniel Stodden <[email protected]>
Cc Dongxiao Xu <[email protected]>
xen/include/public/io/ring.h +3 -2
diff -r 0918ea363872 -r 15ff04882377 xen/include/public/io/ring.h
@@ -112,7 +112,7 @@
         } tapif_user;                                                   \
         uint8_t pvt_pad[4];                                             \
     } private;                                                          \
-    uint8_t pad[44];                                                    \
+    uint8_t __pad[44];                                                  \
     union __name##_sring_entry ring[1]; /* variable-length */           \
 };                                                                      \
                                                                         \
@@ -156,7 +156,8 @@
 #define SHARED_RING_INIT(_s) do {                                       \
     (_s)->req_prod  = (_s)->rsp_prod  = 0;                              \
     (_s)->req_event = (_s)->rsp_event = 1;                              \
-    (void)memset((_s)->pad, 0, sizeof((_s)->pad));                      \
+    (void)memset((_s)->private.pvt_pad, 0, sizeof((_s)->private.pvt_pad)); \
+    (void)memset((_s)->__pad, 0, sizeof((_s)->__pad));                  \
 } while(0)
 
 #define FRONT_RING_INIT(_r, _s, __size) do {                            \