From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: ejo@pengutronix.de, Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH 3/5] mtd: cfi-flash: use I/O accessors for reads/writes of MMIO regions
Date: Wed, 9 Oct 2024 08:05:09 +0200 [thread overview]
Message-ID: <20241009060511.4121157-4-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20241009060511.4121157-1-a.fatoum@pengutronix.de>
The memcpy() routine can use post-indexed memory access instructions
on ARM that would trigger data aborts under KVM.
To fix this, use memcpy_fromio/memcpy_toio or the (read|write)[bwlq]
family of functions, as these are safe to call on MMIO addresses.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
drivers/mtd/nor/cfi_flash.c | 2 +-
drivers/mtd/nor/cfi_flash.h | 15 ++++++++++++---
2 files changed, 13 insertions(+), 4 deletions(-)
diff --git a/drivers/mtd/nor/cfi_flash.c b/drivers/mtd/nor/cfi_flash.c
index 2cb3d5538fbd..ea2373a01827 100644
--- a/drivers/mtd/nor/cfi_flash.c
+++ b/drivers/mtd/nor/cfi_flash.c
@@ -892,7 +892,7 @@ static int cfi_mtd_read(struct mtd_info *mtd, loff_t from, size_t len,
{
struct flash_info *info = container_of(mtd, struct flash_info, mtd);
- memcpy(buf, info->base + from, len);
+ memcpy_fromio(buf, info->base + from, len);
*retlen = len;
return 0;
diff --git a/drivers/mtd/nor/cfi_flash.h b/drivers/mtd/nor/cfi_flash.h
index 5d3053f97156..a80a979f8c0f 100644
--- a/drivers/mtd/nor/cfi_flash.h
+++ b/drivers/mtd/nor/cfi_flash.h
@@ -260,7 +260,11 @@ static inline void flash_write32(u32 value, void *addr)
static inline void flash_write64(u64 value, void *addr)
{
- memcpy((void *)addr, &value, 8);
+#if BITS_PER_LONG >= 64
+ __raw_writeq(value, addr);
+#else
+ memcpy_toio(addr, &value, 8);
+#endif
}
static inline u8 flash_read8(void *addr)
@@ -280,8 +284,13 @@ static inline u32 flash_read32(void *addr)
static inline u64 flash_read64(void *addr)
{
- /* No architectures currently implement readq() */
- return *(volatile u64 *)addr;
+ u64 value;
+#if BITS_PER_LONG >= 64
+ value = __raw_readq(addr);
+#else
+ memcpy_fromio(&value, addr, 8);
+#endif
+ return value;
}
/*
--
2.39.5
next prev parent reply other threads:[~2024-10-09 6:11 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-09 6:05 [PATCH 0/5] ARM64: make barebox compatible with KVM Ahmad Fatoum
2024-10-09 6:05 ` [PATCH 1/5] ARM64: io: implement I/O accessors in assembly Ahmad Fatoum
2024-10-09 6:05 ` [PATCH 2/5] ARM64: board-dt-2nd: grow stack down from start of binary Ahmad Fatoum
2024-10-09 6:05 ` Ahmad Fatoum [this message]
2024-10-09 6:05 ` [PATCH 4/5] ARM64: mmu: flush cacheable regions prior to remapping Ahmad Fatoum
2024-10-09 6:05 ` [PATCH 5/5] virtio: don't use DMA API unless required Ahmad Fatoum
2024-10-14 12:48 ` Sascha Hauer
2024-10-14 13:05 ` Ahmad Fatoum
2024-10-14 13:06 ` [PATCH] fixup! " Ahmad Fatoum
2024-10-15 6:54 ` [PATCH 0/5] ARM64: make barebox compatible with KVM Sascha Hauer
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=20241009060511.4121157-4-a.fatoum@pengutronix.de \
--to=a.fatoum@pengutronix.de \
--cc=barebox@lists.infradead.org \
--cc=ejo@pengutronix.de \
/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