Michael S. Tsirkin
2014-Dec-02 11:44 UTC
[PATCH RFC 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.
Signed-off-by: Michael S. Tsirkin <mst at redhat.com>
---
include/uapi/linux/virtio_balloon.h | 5 +++--
drivers/virtio/virtio_balloon.c | 4 ++--
2 files changed, 5 insertions(+), 4 deletions(-)
diff --git a/include/uapi/linux/virtio_balloon.h
b/include/uapi/linux/virtio_balloon.h
index 5e26f61..5bee71c 100644
--- a/include/uapi/linux/virtio_balloon.h
+++ b/include/uapi/linux/virtio_balloon.h
@@ -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 */
diff --git a/drivers/virtio/virtio_balloon.c b/drivers/virtio/virtio_balloon.c
index 4497def..721e32f 100644
--- a/drivers/virtio/virtio_balloon.c
+++ b/drivers/virtio/virtio_balloon.c
@@ -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)
--
MST
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.
Signed-off-by: Michael S. Tsirkin <mst at redhat.com>
---
include/linux/virtio.h | 2 --
drivers/virtio/virtio.c | 4 ----
drivers/virtio/virtio_balloon.c | 1 -
3 files changed, 7 deletions(-)
diff --git a/include/linux/virtio.h b/include/linux/virtio.h
index 2bbf626..f70411e 100644
--- a/include/linux/virtio.h
+++ b/include/linux/virtio.h
@@ -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);
diff --git a/drivers/virtio/virtio.c b/drivers/virtio/virtio.c
index fa6b75d..2e836d8 100644
--- a/drivers/virtio/virtio.c
+++ b/drivers/virtio/virtio.c
@@ -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
diff --git a/drivers/virtio/virtio_balloon.c b/drivers/virtio/virtio_balloon.c
index 721e32f..fed3709 100644
--- a/drivers/virtio/virtio_balloon.c
+++ b/drivers/virtio/virtio_balloon.c
@@ -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,
--
MST
Cornelia Huck
2014-Dec-02 18:39 UTC
[PATCH RFC 1/2] virtio_balloon: convert to virtio 1.0 endian-ness
On Tue, 2 Dec 2014 13:44:06 +0200 "Michael S. Tsirkin" <mst at redhat.com> 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?> > Signed-off-by: Michael S. Tsirkin <mst at redhat.com> > --- > include/uapi/linux/virtio_balloon.h | 5 +++-- > drivers/virtio/virtio_balloon.c | 4 ++-- > 2 files changed, 5 insertions(+), 4 deletions(-) >> struct virtio_balloon_stat { > - __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?
Michael S. Tsirkin
2014-Dec-03 14:02 UTC
[PATCH RFC 1/2] virtio_balloon: convert to virtio 1.0 endian-ness
On Tue, Dec 02, 2014 at 07:39:30PM +0100, Cornelia Huck wrote:> On Tue, 2 Dec 2014 13:44:06 +0200 > "Michael S. Tsirkin" <mst at redhat.com> 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.> 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.> > > > Signed-off-by: Michael S. Tsirkin <mst at redhat.com> > > --- > > include/uapi/linux/virtio_balloon.h | 5 +++-- > > drivers/virtio/virtio_balloon.c | 4 ++-- > > 2 files changed, 5 insertions(+), 4 deletions(-) > > > > > struct virtio_balloon_stat { > > - __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?
Maybe Matching Threads
- [PATCH RFC 1/2] virtio_balloon: convert to virtio 1.0 endian-ness
- [PATCH v3 0/6] virtio 1.0 enhancements
- [PATCH v3 0/6] virtio 1.0 enhancements
- [PATCH RFC 1/2] virtio_balloon: convert to virtio 1.0 endian-ness
- [PATCH RFC 1/2] virtio_balloon: convert to virtio 1.0 endian-ness