Skip to contentSkip to conversation

virtio-balloon: Document byte ordering of poison_val

PATCH Applied Alexander Duyck 3 participants 3 messages Jul 13, 2020 – Jul 20, 2020

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 virtio-balloon: Document byte ordering of poison_val

From: Alexander Duyck <[email protected]>

The poison_val field in the virtio_balloon_config is treated as a little-endian field by the host. Since we are currently only having to deal with a single byte poison value this isn't a problem, however if the value should ever expand it would cause byte ordering issues. Document that in the code so that we know that if the value should ever expand we need to byte swap the value on big-endian architectures.

---
 drivers/virtio/virtio_balloon.c |    5 +++++
 1 file changed, 5 insertions(+)
drivers/virtio/virtio_balloon.c +5 -0
index 1f157d2f4952..d0fd8f8dc6ed 100644
@@ -974,6 +974,11 @@ static int virtballoon_probe(struct virtio_device *vdev)
 		/*
 		 * Let the hypervisor know that we are expecting a
 		 * specific value to be written back in balloon pages.
+		 *
+		 * If the PAGE_POISON value was larger than a byte we would
+		 * need to byte swap poison_val here to guarantee it is
+		 * little-endian. However for now it is a single byte so we
+		 * can pass it as-is.
 		 */
 		if (!want_init_on_free())
 			memset(&poison_val, PAGE_POISON, sizeof(poison_val));
maintainer Applied
#1 lore raw
Quoted 10 lines · Alexander Duyck

From: Alexander Duyck <[email protected]>

The poison_val field in the virtio_balloon_config is treated as a little-endian field by the host. Since we are currently only having to deal with a single byte poison value this isn't a problem, however if the value should ever expand it would cause byte ordering issues. Document that in the code so that we know that if the value should ever expand we need to byte swap the value on big-endian architectures.

Queued, thanks!

Quoted 10 lines
---
 drivers/virtio/virtio_balloon.c |    5 +++++
 1 file changed, 5 insertions(+)
drivers/virtio/virtio_balloon.c +0 -0
index 1f157d2f4952..d0fd8f8dc6ed 100644
@@ -974,6 +974,11 @@ static int virtballoon_probe(struct virtio_device *vdev)
 		/*

drivers/virtio/virtio_balloon.c static int virtballoon_probe(struct virtio_device *vdev) · line 984

Quoted 10 lines
drivers/virtio/virtio_balloon.c +5 -0
 		 * Let the hypervisor know that we are expecting a
 		 * specific value to be written back in balloon pages.
+		 *
+		 * If the PAGE_POISON value was larger than a byte we would
+		 * need to byte swap poison_val here to guarantee it is
+		 * little-endian. However for now it is a single byte so we
+		 * can pass it as-is.
 		 */
 		if (!want_init_on_free())
 			memset(&poison_val, PAGE_POISON, sizeof(poison_val));

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]

Acked-by on v1 1/1
#2 lore raw
In reply to Alexander Duyck
Quoted 19 lines · Alexander Duyck

From: Alexander Duyck <[email protected]>

The poison_val field in the virtio_balloon_config is treated as a little-endian field by the host. Since we are currently only having to deal with a single byte poison value this isn't a problem, however if the value should ever expand it would cause byte ordering issues. Document that in the code so that we know that if the value should ever expand we need to byte swap the value on big-endian architectures.

---
 drivers/virtio/virtio_balloon.c |    5 +++++
 1 file changed, 5 insertions(+)
drivers/virtio/virtio_balloon.c +0 -0
index 1f157d2f4952..d0fd8f8dc6ed 100644

drivers/virtio/virtio_balloon.c static int virtballoon_probe(struct virtio_device *vdev) · line 981

Quoted 8 lines
drivers/virtio/virtio_balloon.c +5 -0
@@ -974,6 +974,11 @@ static int virtballoon_probe(struct virtio_device *vdev)
 		/*
 		 * Let the hypervisor know that we are expecting a
 		 * specific value to be written back in balloon pages.
+		 *
+		 * If the PAGE_POISON value was larger than a byte we would
+		 * need to byte swap poison_val here to guarantee it is
+		 * little-endian. However for now it is a single byte so we
+		 * can pass it as-is.

Yeah, why not (although it's pretty fundamental that 1-byte values don't need any swapping).

Signature · 8 lines
Thanks,

David / dhildenb


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]