From: "Arnd Bergmann" <arnd@kernel.org>
To: "Daniel Palmer" <daniel@thingy.jp>,
"Michael S. Tsirkin" <mst@redhat.com>,
"Jason Wang" <jasowang@redhat.com>,
"Xuan Zhuo" <xuanzhuo@linux.alibaba.com>,
"Eugenio Pérez" <eperezma@redhat.com>
Cc: virtualization@lists.linux.dev, linux-kernel@vger.kernel.org,
linux-m68k@lists.linux-m68k.org
Subject: Re: [PATCH 2/2] virtio-mmio: Use raw io accessors to avoid arch issues
Date: Sat, 14 Mar 2026 08:42:34 +0100 [thread overview]
Message-ID: <32d021cc-0179-45de-b832-f122698211fb@app.fastmail.com> (raw)
In-Reply-To: <20260314030612.1949420-3-daniel@thingy.jp>
On Sat, Mar 14, 2026, at 04:06, Daniel Palmer wrote:
> virtio-mmio registers are always little endian even on machines
> where peripheral registers are normally big endian.
>
> At least on nommu, non-coldfire, m68k (see: arch/m68k/include/asm/io_no.h)
> readl() and friends are defined to the raw versions. So the value from
> the bus is returned as is.
>
> Since virtio-mmio is a bit special and will always be little endian
> even if that is different to the machine's convention use the raw
> accessors and do the endian swap, where needed, in house.
>
> There are some places in the code where the little endian values are
> actually wanted and we currently swap those back again. If we don't
> swap them in the first place maybe that saves some unneeded swapping?
>
> Signed-off-by: Daniel Palmer <daniel@thingy.jp>
I don't think this is safe to do in portable code
> -
> +/*
> + * The virtio registers are always little endian, even on machines
> + * where everything else is big endian. readl()/write() could use the
> + * value from the bus as-is or endian swap it from little endian.
> + * To avoid confusion use the raw accessors and do the swap here.
> + */
> +#define virtio_mmio_readl(addr) le32_to_cpu(__raw_readl(addr))
> +#define virtio_mmio_writel(value, addr) __raw_writel(cpu_to_le32(value), addr)
The __raw accessors are not well-defined across architectures and
don't technically guarantee anything about the access beyond being
usable as part of a memory access to byte data behind a bridge.
In particular using these for MMIO registers (real or emulated)
misses the bits about
- atomicity of the access
- emulating them from virtualization host
- actual endianess
- ordering against memory or MMIO accesses
I think a better approach would be to change the dragonball
specific device drivers to just use iowrite32_be/ioread32_be
instead of writel/readl, and make the behavior consistent
with the rest of Linux (including io_mm.h and coldfire),
using the generic definition:
diff --git a/arch/m68k/include/asm/io_no.h b/arch/m68k/include/asm/io_no.h
index 516371d5587a..c39db8798ef2 100644
--- a/arch/m68k/include/asm/io_no.h
+++ b/arch/m68k/include/asm/io_no.h
@@ -96,15 +96,6 @@ static inline void writel(u32 value, volatile void __iomem *addr)
__raw_writel(swab32(value), addr);
}
-#else
-
-#define readb __raw_readb
-#define readw __raw_readw
-#define readl __raw_readl
-#define writeb __raw_writeb
-#define writew __raw_writew
-#define writel __raw_writel
-
#endif /* IOMEMBASE */
#if defined(CONFIG_PCI)
Can you try if this works?
Arnd
next prev parent reply other threads:[~2026-03-14 7:42 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-14 3:06 [PATCH 0/2] Allow virtio-mmio to work on m68k nommu 68000 Daniel Palmer
2026-03-14 3:06 ` [PATCH 1/2] virtio-mmio: Replace sizeof x with sizeof(x) Daniel Palmer
2026-03-14 3:06 ` [PATCH 2/2] virtio-mmio: Use raw io accessors to avoid arch issues Daniel Palmer
2026-03-14 7:42 ` Arnd Bergmann [this message]
2026-03-14 8:32 ` Daniel Palmer
2026-03-14 15:06 ` Arnd Bergmann
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=32d021cc-0179-45de-b832-f122698211fb@app.fastmail.com \
--to=arnd@kernel.org \
--cc=daniel@thingy.jp \
--cc=eperezma@redhat.com \
--cc=jasowang@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-m68k@lists.linux-m68k.org \
--cc=mst@redhat.com \
--cc=virtualization@lists.linux.dev \
--cc=xuanzhuo@linux.alibaba.com \
/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
all inboxes | Powered by JetHome®