linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFC PATCH] virt_mmio: fix signature checking for BE guests
@ 2013-02-13 14:25 Marc Zyngier
  2013-02-13 15:08 ` Pawel Moll
  0 siblings, 1 reply; 19+ messages in thread
From: Marc Zyngier @ 2013-02-13 14:25 UTC (permalink / raw)
  To: linux-kernel, virtualization
  Cc: Rusty Russell, Michael S. Tsirkin, Pawel Moll

Using readl() to read the magic value and then memcmp() to check it
fails on BE, as bytes will be the other way around (by virtue of
the registers to follow the endianess of the guest).

Fix it by encoding the magic as an integer instead of a string.

Cc: Rusty Russell <rusty@rustcorp.com.au>
Cc: Michael S. Tsirkin <mst@redhat.com>
Cc: Pawel Moll <pawel.moll@arm.com>
Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
---
So I'm not completely sure this is the right fix, and I can imagine
other ways to cure the problem:
- Reading the MAGIC register byte by byte. Is that allowed? The spec
  only says it is 32bit wide.
- Using __raw_readl() instead. Is that a generic enough API?

 drivers/virtio/virtio_mmio.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/virtio/virtio_mmio.c b/drivers/virtio/virtio_mmio.c
index 31f966f..3811e94 100644
--- a/drivers/virtio/virtio_mmio.c
+++ b/drivers/virtio/virtio_mmio.c
@@ -470,7 +470,7 @@ static int virtio_mmio_probe(struct platform_device *pdev)
 
 	/* Check magic value */
 	magic = readl(vm_dev->base + VIRTIO_MMIO_MAGIC_VALUE);
-	if (memcmp(&magic, "virt", 4) != 0) {
+	if (magic != ('v' | 'i' << 8 | 'r' << 16 | 't' << 24)) {
 		dev_warn(&pdev->dev, "Wrong magic value 0x%08lx!\n", magic);
 		return -ENODEV;
 	}
-- 
1.8.1.2



^ permalink raw reply related	[flat|nested] 19+ messages in thread

end of thread, other threads:[~2013-03-07  7:04 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-02-13 14:25 [RFC PATCH] virt_mmio: fix signature checking for BE guests Marc Zyngier
2013-02-13 15:08 ` Pawel Moll
2013-02-13 15:28   ` Marc Zyngier
2013-02-13 15:46     ` Pawel Moll
2013-02-13 16:40       ` Marc Zyngier
2013-02-13 16:53     ` Michael S. Tsirkin
2013-02-13 17:04       ` Marc Zyngier
2013-02-14  0:22       ` Rusty Russell
2013-02-14 10:54         ` [PATCH] virtio-spec: Define virtio-mmio registers as LE Pawel Moll
2013-02-15  3:57           ` Rusty Russell
2013-03-01 10:41           ` Marc Zyngier
2013-03-01 10:50             ` Pawel Moll
2013-03-01 11:21               ` Marc Zyngier
2013-03-01 12:37                 ` Pawel Moll
2013-03-01 13:16                   ` Marc Zyngier
2013-03-05  0:11                   ` Rusty Russell
2013-03-06 15:10                     ` Pawel Moll
2013-03-07  6:36                       ` Rusty Russell
2013-02-15  0:07     ` [RFC PATCH] virt_mmio: fix signature checking for BE guests Benjamin Herrenschmidt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).