Skip to contentSkip to conversation

virtio_balloon: convert to virtio 1.0 endian-ness

RFC PATCH In review Michael S. Tsirkin 2 participants 6 messages Dec 2, 2014 – Dec 3, 2014

Subsystems (3)
lore
Share & tools
lore

Michael S. Tsirkin

author maintainer
#0 lore raw

RFC PATCH 1/2 virtio_balloon: convert to virtio 1.0 endian-ness

balloon device is not part of virtio 1.0 spec. Still, it's easy enough to make it handle endian-ness exactly as other virtio 1.0 devices: what we gain from this, is that there's no need to special-case it in virtio core.

---
 include/uapi/linux/virtio_balloon.h | 5 +++--
 drivers/virtio/virtio_balloon.c     | 4 ++--
 2 files changed, 5 insertions(+), 4 deletions(-)
include/uapi/linux/virtio_balloon.h +3 -2
index 5e26f61..5bee71c 100644
@@ -27,6 +27,7 @@
  * SUCH DAMAGE. */
 #include <linux/virtio_ids.h>
 #include <linux/virtio_config.h>
+#include <linux/virtio_types.h>
 
 /* The feature bitmap for virtio balloon */
 #define VIRTIO_BALLOON_F_MUST_TELL_HOST	0 /* Tell before reclaiming pages */
@@ -52,8 +53,8 @@ struct virtio_balloon_config
 #define VIRTIO_BALLOON_S_NR       6
 
 struct virtio_balloon_stat {
-	__u16 tag;
-	__u64 val;
+	__virtio16 tag;
+	__virtio64 val;
 } __attribute__((packed));
 
 #endif /* _LINUX_VIRTIO_BALLOON_H */
drivers/virtio/virtio_balloon.c +2 -2
index 4497def..721e32f 100644
@@ -201,8 +201,8 @@ static inline void update_stat(struct virtio_balloon *vb, int idx,
 			       u16 tag, u64 val)
 {
 	BUG_ON(idx >= VIRTIO_BALLOON_S_NR);
-	vb->stats[idx].tag = tag;
-	vb->stats[idx].val = val;
+	vb->stats[idx].tag = cpu_to_virtio16(vb->vdev, tag);
+	vb->stats[idx].val = cpu_to_virtio64(vb->vdev, val);
 }
 
 #define pages_to_bytes(x) ((u64)(x) << PAGE_SHIFT)
Signature · 1 line
MST
author maintainer
#1 lore raw

RFC PATCH 2/2 virtio_balloon: drop legacy_only

balloon is the only driver using legacy_only ATM.
It turns out, it's easier to just make balloon support virtio 1.0 endian-ness and drop the flag from core.

---
 include/linux/virtio.h          | 2 --
 drivers/virtio/virtio.c         | 4 ----
 drivers/virtio/virtio_balloon.c | 1 -
 3 files changed, 7 deletions(-)
include/linux/virtio.h +0 -2
index 2bbf626..f70411e 100644
@@ -132,7 +132,6 @@ int virtio_device_restore(struct virtio_device *dev);
  * @feature_table_size: number of entries in the feature table array.
  * @feature_table_legacy: same as feature_table but when working in legacy mode.
  * @feature_table_size_legacy: number of entries in feature table legacy array.
- * @legacy_only: driver does not support virtio 1.0.
  * @probe: the function to call when a device is found.  Returns 0 or -errno.
  * @remove: the function to call when a device is removed.
  * @config_changed: optional function to call when the device configuration
@@ -145,7 +144,6 @@ struct virtio_driver {
 	unsigned int feature_table_size;
 	const unsigned int *feature_table_legacy;
 	unsigned int feature_table_size_legacy;
-	bool legacy_only;
 	int (*probe)(struct virtio_device *dev);
 	void (*scan)(struct virtio_device *dev);
 	void (*remove)(struct virtio_device *dev);
drivers/virtio/virtio.c +0 -4
index fa6b75d..2e836d8 100644
@@ -197,10 +197,6 @@ static int virtio_dev_probe(struct device *_d)
 		driver_features_legacy = driver_features;
 	}
 
-	/* Detect legacy-only drivers and disable VIRTIO_F_VERSION_1. */
-	if (drv->legacy_only)
-		device_features &= ~(1ULL << VIRTIO_F_VERSION_1);
-
 	if (device_features & (1ULL << VIRTIO_F_VERSION_1))
 		dev->features = driver_features & device_features;
 	else
drivers/virtio/virtio_balloon.c +0 -1
index 721e32f..fed3709 100644
@@ -518,7 +518,6 @@ static unsigned int features[] = {
 };
 
 static struct virtio_driver virtio_balloon_driver = {
-	.legacy_only = true,
 	.feature_table = features,
 	.feature_table_size = ARRAY_SIZE(features),
 	.driver.name =	KBUILD_MODNAME,
Signature · 1 line
MST
#2 lore raw
In reply to Michael S. Tsirkin
Quoted 4 lines · On Tue, 2 Dec 2014 13:44:06 +0200 "Michael S. Tsirkin"…

balloon device is not part of virtio 1.0 spec. Still, it's easy enough to make it handle endian-ness exactly as other virtio 1.0 devices: what we gain from this, is that there's no need to special-case it in virtio core.

Well, the balloon is weird in a number of ways, including its always little-endian config space.

But I'm not quite sure the spec covers this?

Quoted 9 lines
---
 include/uapi/linux/virtio_balloon.h | 5 +++--
 drivers/virtio/virtio_balloon.c     | 4 ++--
 2 files changed, 5 insertions(+), 4 deletions(-)

struct virtio_balloon_stat {

include/uapi/linux/virtio_balloon.h struct virtio_balloon_config · line 58

Quoted 5 lines
include/uapi/linux/virtio_balloon.h +2 -2
-	__u16 tag;
-	__u64 val;
+	__virtio16 tag;
+	__virtio64 val;
 } __attribute__((packed));

Would the respective fields in the spec need updating? While it is actually talking about legacy requirements, the fields are not specified as __virtio{16,64}.

Also, is changing the stat fields enough? I've not looked into balloon operation, but does the payload need some endianess conversion as well?

author maintainer
#3 lore raw
Quoted 10 lines · Cornelia Huck
Quoted 4 lines · On Tue, 2 Dec 2014 13:44:06 +0200 "Michael S. Tsirkin" <[email protected]> wrote:

balloon device is not part of virtio 1.0 spec. Still, it's easy enough to make it handle endian-ness exactly as other virtio 1.0 devices: what we gain from this, is that there's no need to special-case it in virtio core.

Well, the balloon is weird in a number of ways, including its always little-endian config space.

Hmm yes, I forgot about that.

Quoted 1 line

But I'm not quite sure the spec covers this?

The spec does not cover balloon. It merely includes a reference section about legacy balloon device. What to do when that device sets VERSION_1 is really up to us.

Patchset v8 simply makes balloon tell core it's legacy_only. This is I guess fine as far as it goes.
I was still looking for the best way that involves minimal noise in core. This looked like the best way: change 4 lines, and drop all special casing in core, but given the config space endian-ness mess, I'm not sure anymore.
I guess we'll just stick to what v8 does for now.

Quoted 21 lines
Quoted 9 lines
---
 include/uapi/linux/virtio_balloon.h | 5 +++--
 drivers/virtio/virtio_balloon.c     | 4 ++--
 2 files changed, 5 insertions(+), 4 deletions(-)

struct virtio_balloon_stat {

include/uapi/linux/virtio_balloon.h struct virtio_balloon_config · line 58

Quoted 5 lines
include/uapi/linux/virtio_balloon.h +2 -2
-	__u16 tag;
-	__u64 val;
+	__virtio16 tag;
+	__virtio64 val;
 } __attribute__((packed));

Would the respective fields in the spec need updating? While it is actually talking about legacy requirements, the fields are not specified as __virtio{16,64}.

Also, is changing the stat fields enough? I've not looked into balloon operation, but does the payload need some endianess conversion as well?

#4 lore raw
Quoted 20 lines · On Wed, 3 Dec 2014 16:02:28 +0200 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 10 lines · Cornelia Huck
Quoted 4 lines · On Tue, 2 Dec 2014 13:44:06 +0200 "Michael S. Tsirkin" <[email protected]> wrote:

balloon device is not part of virtio 1.0 spec. Still, it's easy enough to make it handle endian-ness exactly as other virtio 1.0 devices: what we gain from this, is that there's no need to special-case it in virtio core.

Well, the balloon is weird in a number of ways, including its always little-endian config space.

Hmm yes, I forgot about that.

Quoted 1 line

But I'm not quite sure the spec covers this?

The spec does not cover balloon. It merely includes a reference section about legacy balloon device. What to do when that device sets VERSION_1 is really up to us.

Quoted 7 lines

Patchset v8 simply makes balloon tell core it's legacy_only. This is I guess fine as far as it goes.
I was still looking for the best way that involves minimal noise in core. This looked like the best way: change 4 lines, and drop all special casing in core, but given the config space endian-ness mess, I'm not sure anymore.
I guess we'll just stick to what v8 does for now.

I don't think the legacy_only approach is so bad, let's keep it for now.

#5 lore raw
In reply to Michael S. Tsirkin
Quoted 4 lines · On Tue, 2 Dec 2014 13:44:06 +0200 "Michael S. Tsirkin" <[email protected]> wrote:

balloon device is not part of virtio 1.0 spec. Still, it's easy enough to make it handle endian-ness exactly as other virtio 1.0 devices: what we gain from this, is that there's no need to special-case it in virtio core.

Well, the balloon is weird in a number of ways, including its always little-endian config space.

But I'm not quite sure the spec covers this?

Quoted 9 lines
---
 include/uapi/linux/virtio_balloon.h | 5 +++--
 drivers/virtio/virtio_balloon.c     | 4 ++--
 2 files changed, 5 insertions(+), 4 deletions(-)

struct virtio_balloon_stat {

include/uapi/linux/virtio_balloon.h struct virtio_balloon_config · line 58

Quoted 5 lines
include/uapi/linux/virtio_balloon.h +2 -2
-	__u16 tag;
-	__u64 val;
+	__virtio16 tag;
+	__virtio64 val;
 } __attribute__((packed));

Would the respective fields in the spec need updating? While it is actually talking about legacy requirements, the fields are not specified as __virtio{16,64}.

Also, is changing the stat fields enough? I've not looked into balloon operation, but does the payload need some endianess conversion as well?