From: Marc Zyngier <marc.zyngier@arm.com>
To: linux-kernel@vger.kernel.org, virtualization@lists.linux-foundation.org
Cc: Rusty Russell <rusty@rustcorp.com.au>,
"Michael S. Tsirkin" <mst@redhat.com>,
Pawel Moll <pawel.moll@arm.com>
Subject: [RFC PATCH] virt_mmio: fix signature checking for BE guests
Date: Wed, 13 Feb 2013 14:25:38 +0000 [thread overview]
Message-ID: <1360765538-18097-1-git-send-email-marc.zyngier@arm.com> (raw)
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
next reply other threads:[~2013-02-13 14:26 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-02-13 14:25 Marc Zyngier [this message]
2013-02-13 15:08 ` [RFC PATCH] virt_mmio: fix signature checking for BE guests 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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1360765538-18097-1-git-send-email-marc.zyngier@arm.com \
--to=marc.zyngier@arm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mst@redhat.com \
--cc=pawel.moll@arm.com \
--cc=rusty@rustcorp.com.au \
--cc=virtualization@lists.linux-foundation.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).