Skip to contentSkip to conversation

virtio_balloon: fix up endian-ness for free cmd id

PATCH In review Michael S. Tsirkin 4 participants 4 messages Jul 27, 2020 – Jul 29, 2020

Subsystems (3)
lore
Share & tools
lore

Michael S. Tsirkin

author maintainer
#0 lore raw

PATCH 1/1 virtio_balloon: fix up endian-ness for free cmd id

free cmd id is read using virtio endian, spec says all fields in balloon are LE. Fix it up.

Fixes 86a559787e6f ("virtio-balloon: VIRTIO_BALLOON_F_FREE_PAGE_HINT")
---
 drivers/virtio/virtio_balloon.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/virtio/virtio_balloon.c +5 -1
index 774deb65a9bb..798ec304fe3e 100644
@@ -578,10 +578,14 @@ static int init_vqs(struct virtio_balloon *vb)
 static u32 virtio_balloon_cmd_id_received(struct virtio_balloon *vb)
 {
 	if (test_and_clear_bit(VIRTIO_BALLOON_CONFIG_READ_CMD_ID,
-			       &vb->config_read_bitmap))
+			       &vb->config_read_bitmap)) {
 		virtio_cread(vb->vdev, struct virtio_balloon_config,
 			     free_page_hint_cmd_id,
 			     &vb->cmd_id_received_cache);
+		/* Legacy balloon config space is LE, unlike all other devices. */
+		if (!virtio_has_feature(vb->vdev, VIRTIO_F_VERSION_1))
+			vb->cmd_id_received_cache = le32_to_cpu((__force __le32)vb->cmd_id_received_cache);
+	}
 
 	return vb->cmd_id_received_cache;
 }
Signature · 1 line
MST
Acked-by on v1 1/1
#1 lore raw
Quoted 21 lines · Michael S. Tsirkin

free cmd id is read using virtio endian, spec says all fields in balloon are LE. Fix it up.

Fixes 86a559787e6f ("virtio-balloon: VIRTIO_BALLOON_F_FREE_PAGE_HINT")
---
 drivers/virtio/virtio_balloon.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/virtio/virtio_balloon.c +1 -1
index 774deb65a9bb..798ec304fe3e 100644
@@ -578,10 +578,14 @@ static int init_vqs(struct virtio_balloon *vb)
 static u32 virtio_balloon_cmd_id_received(struct virtio_balloon *vb)
 {
 	if (test_and_clear_bit(VIRTIO_BALLOON_CONFIG_READ_CMD_ID,
-			       &vb->config_read_bitmap))
+			       &vb->config_read_bitmap)) {

drivers/virtio/virtio_balloon.c static int init_vqs(struct virtio_balloon *vb) · line 591

Quoted 10 lines
drivers/virtio/virtio_balloon.c +4 -0
 		virtio_cread(vb->vdev, struct virtio_balloon_config,
 			     free_page_hint_cmd_id,
 			     &vb->cmd_id_received_cache);
+		/* Legacy balloon config space is LE, unlike all other devices. */
+		if (!virtio_has_feature(vb->vdev, VIRTIO_F_VERSION_1))
+			vb->cmd_id_received_cache = le32_to_cpu((__force __le32)vb->cmd_id_received_cache);
+	}
 
 	return vb->cmd_id_received_cache;
 }
Signature · 3 lines
Thanks,

David / dhildenb
Reviewed-by on v1 1/1
#2 lore raw
In reply to Michael S. Tsirkin
Quoted 16 lines · Michael S. Tsirkin

free cmd id is read using virtio endian, spec says all fields in balloon are LE. Fix it up.

Fixes 86a559787e6f ("virtio-balloon: VIRTIO_BALLOON_F_FREE_PAGE_HINT")
---
  drivers/virtio/virtio_balloon.c | 6 +++++-
  1 file changed, 5 insertions(+), 1 deletion(-)
drivers/virtio/virtio_balloon.c +0 -0
index 774deb65a9bb..798ec304fe3e 100644
@@ -578,10 +578,14 @@ static int init_vqs(struct virtio_balloon *vb)
  static u32 virtio_balloon_cmd_id_received(struct virtio_balloon *vb)

drivers/virtio/virtio_balloon.c static int init_vqs(struct virtio_balloon *vb) · line 587

Quoted 10 lines
drivers/virtio/virtio_balloon.c +4 -1
  {
  	if (test_and_clear_bit(VIRTIO_BALLOON_CONFIG_READ_CMD_ID,
-			       &vb->config_read_bitmap))
+			       &vb->config_read_bitmap)) {
  		virtio_cread(vb->vdev, struct virtio_balloon_config,
  			     free_page_hint_cmd_id,
  			     &vb->cmd_id_received_cache);
+		/* Legacy balloon config space is LE, unlike all other devices. */
+		if (!virtio_has_feature(vb->vdev, VIRTIO_F_VERSION_1))
+			vb->cmd_id_received_cache = le32_to_cpu((__force __le32)vb->cmd_id_received_cache);

Seems it exceeds 80 character length.

Best,
Wei

Acked-by on v1 1/1
#3 lore raw
In reply to Michael S. Tsirkin
Quoted 20 lines · Michael S. Tsirkin

free cmd id is read using virtio endian, spec says all fields in balloon are LE. Fix it up.

Fixes 86a559787e6f ("virtio-balloon: VIRTIO_BALLOON_F_FREE_PAGE_HINT")
---
  drivers/virtio/virtio_balloon.c | 6 +++++-
  1 file changed, 5 insertions(+), 1 deletion(-)
drivers/virtio/virtio_balloon.c +1 -1
index 774deb65a9bb..798ec304fe3e 100644
@@ -578,10 +578,14 @@ static int init_vqs(struct virtio_balloon *vb)
  static u32 virtio_balloon_cmd_id_received(struct virtio_balloon *vb)
  {
  	if (test_and_clear_bit(VIRTIO_BALLOON_CONFIG_READ_CMD_ID,
-			       &vb->config_read_bitmap))
+			       &vb->config_read_bitmap)) {

drivers/virtio/virtio_balloon.c static int init_vqs(struct virtio_balloon *vb) · line 591

Quoted 10 lines
drivers/virtio/virtio_balloon.c +4 -0
  		virtio_cread(vb->vdev, struct virtio_balloon_config,
  			     free_page_hint_cmd_id,
  			     &vb->cmd_id_received_cache);
+		/* Legacy balloon config space is LE, unlike all other devices. */
+		if (!virtio_has_feature(vb->vdev, VIRTIO_F_VERSION_1))
+			vb->cmd_id_received_cache = le32_to_cpu((__force __le32)vb->cmd_id_received_cache);
+	}
 
  	return vb->cmd_id_received_cache;
  }