* [PATCH v2 0/4] Consolidate IO memcpy functions
@ 2024-09-09 13:31 Julian Vetter
2024-09-09 13:31 ` [PATCH v2 1/4] Consolidate __memcpy_{to,from}io and __memset_io into a single lib Julian Vetter
` (4 more replies)
0 siblings, 5 replies; 9+ messages in thread
From: Julian Vetter @ 2024-09-09 13:31 UTC (permalink / raw)
To: Arnd Bergmann, Catalin Marinas, Will Deacon, Guo Ren, Huacai Chen,
WANG Xuerui, Andrew Morton
Cc: linux-arm-kernel, linux-kernel, linux-csky, loongarch,
Yann Sionneau, Julian Vetter
Thank you for your feedback Arnd. In regards to the filename, etc. I
went with the first route and created a new file called io_copy.c.
Although, I'm not sure if it's a good idea to create yet another file
that serves a limited purpose. But I'm a bit afraid to add the
functions to iomap_copy.c because there is no common consus in the
architecture code about memcpy_{from,to}io. Some specify it with
_memcpy_xx, some directly with memcpy_xx, and another bunch uses
__memcpy_xx. So, if we want to merge it with iomap_copy.c, I would need
to export the __memcpy_xx symbols for all architectures that don't want
to use the "generic" memcpy_xx functions for now or rename their given
implementation to __memcpy_xx, right? But if you think it's better to
merge the two, I will have another look and modify the code for all
remaining architectures as well.
Signed-off-by: Julian Vetter <jvetter@kalrayinc.com>
---
Changes for v2:
- Renamed io.c -> io_copy.c
- Updated flag to 'GENERIC_IO_COPY'
- Replaced pointer dereferences by 'put_unaligned()'/'get_unaligned()'
- Replaced '#ifdef CONFIG_64BIT' by 'if(IS_ENABLED(CONFIG_64BIT))'
- Removed '__raw_{read,write}_native' and replaced by
'if(IS_ENABLED(CONFIG_64BIT))' -> '__raw_write{l,q}'
---
Julian Vetter (4):
Consolidate __memcpy_{to,from}io and __memset_io into a single lib
Use generic io memcpy functions on the arm64 architecture
Use generic io memcpy functions on the csky architecture
Use generic io memcpy functions on the loongarch architecture
arch/arm64/Kconfig | 1 +
arch/arm64/kernel/io.c | 87 ---------------------------
arch/csky/Kconfig | 1 +
arch/csky/kernel/Makefile | 2 +-
arch/csky/kernel/io.c | 91 ----------------------------
arch/loongarch/Kconfig | 1 +
arch/loongarch/kernel/Makefile | 2 +-
arch/loongarch/kernel/io.c | 94 -----------------------------
lib/Kconfig | 3 +
lib/Makefile | 1 +
lib/io_copy.c | 107 +++++++++++++++++++++++++++++++++
11 files changed, 116 insertions(+), 274 deletions(-)
delete mode 100644 arch/csky/kernel/io.c
delete mode 100644 arch/loongarch/kernel/io.c
create mode 100644 lib/io_copy.c
--
2.34.1
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH v2 1/4] Consolidate __memcpy_{to,from}io and __memset_io into a single lib
2024-09-09 13:31 [PATCH v2 0/4] Consolidate IO memcpy functions Julian Vetter
@ 2024-09-09 13:31 ` Julian Vetter
2024-09-09 13:31 ` [PATCH v2 2/4] Use generic io memcpy functions on the arm64 architecture Julian Vetter
` (3 subsequent siblings)
4 siblings, 0 replies; 9+ messages in thread
From: Julian Vetter @ 2024-09-09 13:31 UTC (permalink / raw)
To: Arnd Bergmann, Catalin Marinas, Will Deacon, Guo Ren, Huacai Chen,
WANG Xuerui, Andrew Morton
Cc: linux-arm-kernel, linux-kernel, linux-csky, loongarch,
Yann Sionneau, Julian Vetter
Various architectures have almost the same implementations for
__memcpy_{to,from}io and __memset_io functions. So, consolidate them and
introduce a CONFIG_GENERIC_IO_COPY flag to build the given
lib/io_copy.c.
Reviewed-by: Yann Sionneau <ysionneau@kalrayinc.com>
Signed-off-by: Julian Vetter <jvetter@kalrayinc.com>
---
lib/Kconfig | 3 ++
lib/Makefile | 1 +
lib/io_copy.c | 107 ++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 111 insertions(+)
create mode 100644 lib/io_copy.c
diff --git a/lib/Kconfig b/lib/Kconfig
index b38849af6f13..741550bc3856 100644
--- a/lib/Kconfig
+++ b/lib/Kconfig
@@ -70,6 +70,9 @@ source "lib/math/Kconfig"
config NO_GENERIC_PCI_IOPORT_MAP
bool
+config GENERIC_IO_COPY
+ bool
+
config GENERIC_IOMAP
bool
select GENERIC_PCI_IOMAP
diff --git a/lib/Makefile b/lib/Makefile
index 322bb127b4dc..4f56ad5f9ed6 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -130,6 +130,7 @@ CFLAGS_debug_info.o += $(call cc-option, -femit-struct-debug-detailed=any)
obj-y += math/ crypto/
+obj-$(CONFIG_GENERIC_IO_COPY) += io_copy.o
obj-$(CONFIG_GENERIC_IOMAP) += iomap.o
obj-$(CONFIG_HAS_IOMEM) += iomap_copy.o devres.o
obj-$(CONFIG_CHECK_SIGNATURE) += check_signature.o
diff --git a/lib/io_copy.c b/lib/io_copy.c
new file mode 100644
index 000000000000..bfdb84e87607
--- /dev/null
+++ b/lib/io_copy.c
@@ -0,0 +1,107 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * derived from arch/arm/kernel/io.c
+ *
+ * Copyright (C) 2024 Kalray Inc.
+ * Author(s): Julian Vetter
+ */
+
+#include <asm/unaligned.h>
+
+#include <linux/export.h>
+#include <linux/types.h>
+#include <linux/io.h>
+
+#define NATIVE_STORE_SIZE (BITS_PER_LONG/8)
+
+void __memcpy_fromio(void *to, const volatile void __iomem *from, size_t count)
+{
+ while (count && !IS_ALIGNED((unsigned long)from, NATIVE_STORE_SIZE)) {
+ *(u8 *)to = __raw_readb(from);
+ from++;
+ to++;
+ count--;
+ }
+
+ while (count >= NATIVE_STORE_SIZE) {
+ if (IS_ENABLED(CONFIG_64BIT))
+ put_unaligned(__raw_readq(from), (uintptr_t *)to);
+ else
+ put_unaligned(__raw_readl(from), (uintptr_t *)to);
+
+ from += NATIVE_STORE_SIZE;
+ to += NATIVE_STORE_SIZE;
+ count -= NATIVE_STORE_SIZE;
+ }
+
+ while (count) {
+ *(u8 *)to = __raw_readb(from);
+ from++;
+ to++;
+ count--;
+ }
+}
+EXPORT_SYMBOL(__memcpy_fromio);
+
+void __memcpy_toio(volatile void __iomem *to, const void *from, size_t count)
+{
+ while (count && !IS_ALIGNED((unsigned long)to, NATIVE_STORE_SIZE)) {
+ __raw_writeb(*(u8 *)from, to);
+ from++;
+ to++;
+ count--;
+ }
+
+ while (count >= NATIVE_STORE_SIZE) {
+ if (IS_ENABLED(CONFIG_64BIT))
+ __raw_writeq(get_unaligned((uintptr_t *)from), to);
+ else
+ __raw_writel(get_unaligned((uintptr_t *)from), to);
+
+ from += NATIVE_STORE_SIZE;
+ to += NATIVE_STORE_SIZE;
+ count -= NATIVE_STORE_SIZE;
+ }
+
+ while (count) {
+ __raw_writeb(*(u8 *)from, to);
+ from++;
+ to++;
+ count--;
+ }
+}
+EXPORT_SYMBOL(__memcpy_toio);
+
+void __memset_io(volatile void __iomem *dst, int c, size_t count)
+{
+ uintptr_t qc = (u8)c;
+
+ qc |= qc << 8;
+ qc |= qc << 16;
+
+ if (IS_ENABLED(CONFIG_64BIT))
+ qc |= qc << 32;
+
+ while (count && !IS_ALIGNED((unsigned long)dst, NATIVE_STORE_SIZE)) {
+ __raw_writeb(c, dst);
+ dst++;
+ count--;
+ }
+
+ while (count >= NATIVE_STORE_SIZE) {
+ if (IS_ENABLED(CONFIG_64BIT))
+ __raw_writeq(qc, dst);
+ else
+ __raw_writel(qc, dst);
+
+ dst += NATIVE_STORE_SIZE;
+ count -= NATIVE_STORE_SIZE;
+ }
+
+ while (count) {
+ __raw_writeb(c, dst);
+ dst++;
+ count--;
+ }
+}
+EXPORT_SYMBOL(__memset_io);
--
2.34.1
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH v2 2/4] Use generic io memcpy functions on the arm64 architecture
2024-09-09 13:31 [PATCH v2 0/4] Consolidate IO memcpy functions Julian Vetter
2024-09-09 13:31 ` [PATCH v2 1/4] Consolidate __memcpy_{to,from}io and __memset_io into a single lib Julian Vetter
@ 2024-09-09 13:31 ` Julian Vetter
2024-09-09 13:31 ` [PATCH v2 3/4] Use generic io memcpy functions on the csky architecture Julian Vetter
` (2 subsequent siblings)
4 siblings, 0 replies; 9+ messages in thread
From: Julian Vetter @ 2024-09-09 13:31 UTC (permalink / raw)
To: Arnd Bergmann, Catalin Marinas, Will Deacon, Guo Ren, Huacai Chen,
WANG Xuerui, Andrew Morton
Cc: linux-arm-kernel, linux-kernel, linux-csky, loongarch,
Yann Sionneau, Julian Vetter
Use the generic __memcpy_{from,to}io and __memset_io functions on the
arm64 processor architecture.
Reviewed-by: Yann Sionneau <ysionneau@kalrayinc.com>
Signed-off-by: Julian Vetter <jvetter@kalrayinc.com>
---
arch/arm64/Kconfig | 1 +
arch/arm64/kernel/io.c | 87 ------------------------------------------
2 files changed, 1 insertion(+), 87 deletions(-)
diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig
index a2f8ff354ca6..cfb1c729c9a1 100644
--- a/arch/arm64/Kconfig
+++ b/arch/arm64/Kconfig
@@ -140,6 +140,7 @@ config ARM64
select GENERIC_CPU_VULNERABILITIES
select GENERIC_EARLY_IOREMAP
select GENERIC_IDLE_POLL_SETUP
+ select GENERIC_IO_COPY
select GENERIC_IOREMAP
select GENERIC_IRQ_IPI
select GENERIC_IRQ_PROBE
diff --git a/arch/arm64/kernel/io.c b/arch/arm64/kernel/io.c
index ef48089fbfe1..fe86ada23c7d 100644
--- a/arch/arm64/kernel/io.c
+++ b/arch/arm64/kernel/io.c
@@ -9,34 +9,6 @@
#include <linux/types.h>
#include <linux/io.h>
-/*
- * Copy data from IO memory space to "real" memory space.
- */
-void __memcpy_fromio(void *to, const volatile void __iomem *from, size_t count)
-{
- while (count && !IS_ALIGNED((unsigned long)from, 8)) {
- *(u8 *)to = __raw_readb(from);
- from++;
- to++;
- count--;
- }
-
- while (count >= 8) {
- *(u64 *)to = __raw_readq(from);
- from += 8;
- to += 8;
- count -= 8;
- }
-
- while (count) {
- *(u8 *)to = __raw_readb(from);
- from++;
- to++;
- count--;
- }
-}
-EXPORT_SYMBOL(__memcpy_fromio);
-
/*
* This generates a memcpy that works on a from/to address which is aligned to
* bits. Count is in terms of the number of bits sized quantities to copy. It
@@ -78,62 +50,3 @@ void __iowrite32_copy_full(void __iomem *to, const void *from, size_t count)
dgh();
}
EXPORT_SYMBOL(__iowrite32_copy_full);
-
-/*
- * Copy data from "real" memory space to IO memory space.
- */
-void __memcpy_toio(volatile void __iomem *to, const void *from, size_t count)
-{
- while (count && !IS_ALIGNED((unsigned long)to, 8)) {
- __raw_writeb(*(u8 *)from, to);
- from++;
- to++;
- count--;
- }
-
- while (count >= 8) {
- __raw_writeq(*(u64 *)from, to);
- from += 8;
- to += 8;
- count -= 8;
- }
-
- while (count) {
- __raw_writeb(*(u8 *)from, to);
- from++;
- to++;
- count--;
- }
-}
-EXPORT_SYMBOL(__memcpy_toio);
-
-/*
- * "memset" on IO memory space.
- */
-void __memset_io(volatile void __iomem *dst, int c, size_t count)
-{
- u64 qc = (u8)c;
-
- qc |= qc << 8;
- qc |= qc << 16;
- qc |= qc << 32;
-
- while (count && !IS_ALIGNED((unsigned long)dst, 8)) {
- __raw_writeb(c, dst);
- dst++;
- count--;
- }
-
- while (count >= 8) {
- __raw_writeq(qc, dst);
- dst += 8;
- count -= 8;
- }
-
- while (count) {
- __raw_writeb(c, dst);
- dst++;
- count--;
- }
-}
-EXPORT_SYMBOL(__memset_io);
--
2.34.1
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH v2 3/4] Use generic io memcpy functions on the csky architecture
2024-09-09 13:31 [PATCH v2 0/4] Consolidate IO memcpy functions Julian Vetter
2024-09-09 13:31 ` [PATCH v2 1/4] Consolidate __memcpy_{to,from}io and __memset_io into a single lib Julian Vetter
2024-09-09 13:31 ` [PATCH v2 2/4] Use generic io memcpy functions on the arm64 architecture Julian Vetter
@ 2024-09-09 13:31 ` Julian Vetter
2024-09-10 7:27 ` kernel test robot
2024-09-09 13:31 ` [PATCH v2 4/4] Use generic io memcpy functions on the loongarch architecture Julian Vetter
2024-09-10 16:07 ` [PATCH v2 0/4] Consolidate IO memcpy functions Arnd Bergmann
4 siblings, 1 reply; 9+ messages in thread
From: Julian Vetter @ 2024-09-09 13:31 UTC (permalink / raw)
To: Arnd Bergmann, Catalin Marinas, Will Deacon, Guo Ren, Huacai Chen,
WANG Xuerui, Andrew Morton
Cc: linux-arm-kernel, linux-kernel, linux-csky, loongarch,
Yann Sionneau, Julian Vetter
Use the generic __memcpy_{from,to}io and __memset_io functions on the
csky processor architecture.
Reviewed-by: Yann Sionneau <ysionneau@kalrayinc.com>
Signed-off-by: Julian Vetter <jvetter@kalrayinc.com>
---
arch/csky/Kconfig | 1 +
arch/csky/kernel/Makefile | 2 +-
arch/csky/kernel/io.c | 91 ---------------------------------------
3 files changed, 2 insertions(+), 92 deletions(-)
delete mode 100644 arch/csky/kernel/io.c
diff --git a/arch/csky/Kconfig b/arch/csky/Kconfig
index 5479707eb5d1..59d4051b2a83 100644
--- a/arch/csky/Kconfig
+++ b/arch/csky/Kconfig
@@ -48,6 +48,7 @@ config CSKY
select DMA_DIRECT_REMAP
select IRQ_DOMAIN
select DW_APB_TIMER_OF
+ select GENERIC_IO_COPY
select GENERIC_IOREMAP
select GENERIC_LIB_ASHLDI3
select GENERIC_LIB_ASHRDI3
diff --git a/arch/csky/kernel/Makefile b/arch/csky/kernel/Makefile
index 8a868316b912..de1c3472e8f0 100644
--- a/arch/csky/kernel/Makefile
+++ b/arch/csky/kernel/Makefile
@@ -2,7 +2,7 @@
extra-y := vmlinux.lds
obj-y += head.o entry.o atomic.o signal.o traps.o irq.o time.o vdso.o vdso/
-obj-y += power.o syscall.o syscall_table.o setup.o io.o
+obj-y += power.o syscall.o syscall_table.o setup.o
obj-y += process.o cpu-probe.o ptrace.o stacktrace.o
obj-y += probes/
diff --git a/arch/csky/kernel/io.c b/arch/csky/kernel/io.c
deleted file mode 100644
index 5883f13fa2b1..000000000000
--- a/arch/csky/kernel/io.c
+++ /dev/null
@@ -1,91 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0
-
-#include <linux/export.h>
-#include <linux/types.h>
-#include <linux/io.h>
-
-/*
- * Copy data from IO memory space to "real" memory space.
- */
-void __memcpy_fromio(void *to, const volatile void __iomem *from, size_t count)
-{
- while (count && !IS_ALIGNED((unsigned long)from, 4)) {
- *(u8 *)to = __raw_readb(from);
- from++;
- to++;
- count--;
- }
-
- while (count >= 4) {
- *(u32 *)to = __raw_readl(from);
- from += 4;
- to += 4;
- count -= 4;
- }
-
- while (count) {
- *(u8 *)to = __raw_readb(from);
- from++;
- to++;
- count--;
- }
-}
-EXPORT_SYMBOL(__memcpy_fromio);
-
-/*
- * Copy data from "real" memory space to IO memory space.
- */
-void __memcpy_toio(volatile void __iomem *to, const void *from, size_t count)
-{
- while (count && !IS_ALIGNED((unsigned long)to, 4)) {
- __raw_writeb(*(u8 *)from, to);
- from++;
- to++;
- count--;
- }
-
- while (count >= 4) {
- __raw_writel(*(u32 *)from, to);
- from += 4;
- to += 4;
- count -= 4;
- }
-
- while (count) {
- __raw_writeb(*(u8 *)from, to);
- from++;
- to++;
- count--;
- }
-}
-EXPORT_SYMBOL(__memcpy_toio);
-
-/*
- * "memset" on IO memory space.
- */
-void __memset_io(volatile void __iomem *dst, int c, size_t count)
-{
- u32 qc = (u8)c;
-
- qc |= qc << 8;
- qc |= qc << 16;
-
- while (count && !IS_ALIGNED((unsigned long)dst, 4)) {
- __raw_writeb(c, dst);
- dst++;
- count--;
- }
-
- while (count >= 4) {
- __raw_writel(qc, dst);
- dst += 4;
- count -= 4;
- }
-
- while (count) {
- __raw_writeb(c, dst);
- dst++;
- count--;
- }
-}
-EXPORT_SYMBOL(__memset_io);
--
2.34.1
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH v2 4/4] Use generic io memcpy functions on the loongarch architecture
2024-09-09 13:31 [PATCH v2 0/4] Consolidate IO memcpy functions Julian Vetter
` (2 preceding siblings ...)
2024-09-09 13:31 ` [PATCH v2 3/4] Use generic io memcpy functions on the csky architecture Julian Vetter
@ 2024-09-09 13:31 ` Julian Vetter
2024-09-10 16:07 ` [PATCH v2 0/4] Consolidate IO memcpy functions Arnd Bergmann
4 siblings, 0 replies; 9+ messages in thread
From: Julian Vetter @ 2024-09-09 13:31 UTC (permalink / raw)
To: Arnd Bergmann, Catalin Marinas, Will Deacon, Guo Ren, Huacai Chen,
WANG Xuerui, Andrew Morton
Cc: linux-arm-kernel, linux-kernel, linux-csky, loongarch,
Yann Sionneau, Julian Vetter
Use the generic __memcpy_{from,to}io and __memset_io functions on the
loongarch processor architecture.
Reviewed-by: Yann Sionneau <ysionneau@kalrayinc.com>
Signed-off-by: Julian Vetter <jvetter@kalrayinc.com>
---
arch/loongarch/Kconfig | 1 +
arch/loongarch/kernel/Makefile | 2 +-
arch/loongarch/kernel/io.c | 94 ----------------------------------
3 files changed, 2 insertions(+), 95 deletions(-)
delete mode 100644 arch/loongarch/kernel/io.c
diff --git a/arch/loongarch/Kconfig b/arch/loongarch/Kconfig
index 70f169210b52..bc97b09efd16 100644
--- a/arch/loongarch/Kconfig
+++ b/arch/loongarch/Kconfig
@@ -84,6 +84,7 @@ config LOONGARCH
select GENERIC_CPU_DEVICES
select GENERIC_ENTRY
select GENERIC_GETTIMEOFDAY
+ select GENERIC_IO_COPY
select GENERIC_IOREMAP if !ARCH_IOREMAP
select GENERIC_IRQ_MULTI_HANDLER
select GENERIC_IRQ_PROBE
diff --git a/arch/loongarch/kernel/Makefile b/arch/loongarch/kernel/Makefile
index c9bfeda89e40..9497968ee158 100644
--- a/arch/loongarch/kernel/Makefile
+++ b/arch/loongarch/kernel/Makefile
@@ -8,7 +8,7 @@ OBJECT_FILES_NON_STANDARD_head.o := y
extra-y := vmlinux.lds
obj-y += head.o cpu-probe.o cacheinfo.o env.o setup.o entry.o genex.o \
- traps.o irq.o idle.o process.o dma.o mem.o io.o reset.o switch.o \
+ traps.o irq.o idle.o process.o dma.o mem.o reset.o switch.o \
elf.o syscall.o signal.o time.o topology.o inst.o ptrace.o vdso.o \
alternative.o unwind.o
diff --git a/arch/loongarch/kernel/io.c b/arch/loongarch/kernel/io.c
deleted file mode 100644
index cb85bda5a6ad..000000000000
--- a/arch/loongarch/kernel/io.c
+++ /dev/null
@@ -1,94 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0
-/*
- * Copyright (C) 2020-2022 Loongson Technology Corporation Limited
- */
-#include <linux/export.h>
-#include <linux/types.h>
-#include <linux/io.h>
-
-/*
- * Copy data from IO memory space to "real" memory space.
- */
-void __memcpy_fromio(void *to, const volatile void __iomem *from, size_t count)
-{
- while (count && !IS_ALIGNED((unsigned long)from, 8)) {
- *(u8 *)to = __raw_readb(from);
- from++;
- to++;
- count--;
- }
-
- while (count >= 8) {
- *(u64 *)to = __raw_readq(from);
- from += 8;
- to += 8;
- count -= 8;
- }
-
- while (count) {
- *(u8 *)to = __raw_readb(from);
- from++;
- to++;
- count--;
- }
-}
-EXPORT_SYMBOL(__memcpy_fromio);
-
-/*
- * Copy data from "real" memory space to IO memory space.
- */
-void __memcpy_toio(volatile void __iomem *to, const void *from, size_t count)
-{
- while (count && !IS_ALIGNED((unsigned long)to, 8)) {
- __raw_writeb(*(u8 *)from, to);
- from++;
- to++;
- count--;
- }
-
- while (count >= 8) {
- __raw_writeq(*(u64 *)from, to);
- from += 8;
- to += 8;
- count -= 8;
- }
-
- while (count) {
- __raw_writeb(*(u8 *)from, to);
- from++;
- to++;
- count--;
- }
-}
-EXPORT_SYMBOL(__memcpy_toio);
-
-/*
- * "memset" on IO memory space.
- */
-void __memset_io(volatile void __iomem *dst, int c, size_t count)
-{
- u64 qc = (u8)c;
-
- qc |= qc << 8;
- qc |= qc << 16;
- qc |= qc << 32;
-
- while (count && !IS_ALIGNED((unsigned long)dst, 8)) {
- __raw_writeb(c, dst);
- dst++;
- count--;
- }
-
- while (count >= 8) {
- __raw_writeq(qc, dst);
- dst += 8;
- count -= 8;
- }
-
- while (count) {
- __raw_writeb(c, dst);
- dst++;
- count--;
- }
-}
-EXPORT_SYMBOL(__memset_io);
--
2.34.1
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH v2 3/4] Use generic io memcpy functions on the csky architecture
2024-09-09 13:31 ` [PATCH v2 3/4] Use generic io memcpy functions on the csky architecture Julian Vetter
@ 2024-09-10 7:27 ` kernel test robot
2024-09-10 9:15 ` Arnd Bergmann
0 siblings, 1 reply; 9+ messages in thread
From: kernel test robot @ 2024-09-10 7:27 UTC (permalink / raw)
To: Julian Vetter, Arnd Bergmann, Catalin Marinas, Will Deacon,
Guo Ren, Huacai Chen, WANG Xuerui, Andrew Morton
Cc: oe-kbuild-all, Linux Memory Management List, linux-arm-kernel,
linux-kernel, linux-csky, loongarch, Yann Sionneau, Julian Vetter
Hi Julian,
kernel test robot noticed the following build errors:
[auto build test ERROR on akpm-mm/mm-nonmm-unstable]
[also build test ERROR on arm64/for-next/core soc/for-next linus/master v6.11-rc7 next-20240909]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Julian-Vetter/Consolidate-__memcpy_-to-from-io-and-__memset_io-into-a-single-lib/20240909-213659
base: https://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm.git mm-nonmm-unstable
patch link: https://lore.kernel.org/r/20240909133159.2024688-4-jvetter%40kalrayinc.com
patch subject: [PATCH v2 3/4] Use generic io memcpy functions on the csky architecture
config: csky-allnoconfig (https://download.01.org/0day-ci/archive/20240910/202409101549.CyV0mJ2S-lkp@intel.com/config)
compiler: csky-linux-gcc (GCC) 14.1.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240910/202409101549.CyV0mJ2S-lkp@intel.com/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202409101549.CyV0mJ2S-lkp@intel.com/
All error/warnings (new ones prefixed by >>):
In file included from ./arch/csky/include/generated/asm/unaligned.h:1,
from lib/io_copy.c:9:
lib/io_copy.c: In function '__memcpy_fromio':
>> lib/io_copy.c:28:39: error: implicit declaration of function '__raw_readq'; did you mean '__raw_readl'? [-Wimplicit-function-declaration]
28 | put_unaligned(__raw_readq(from), (uintptr_t *)to);
| ^~~~~~~~~~~
include/asm-generic/unaligned.h:19:22: note: in definition of macro '__put_unaligned_t'
19 | __pptr->x = (val); \
| ^~~
lib/io_copy.c:28:25: note: in expansion of macro 'put_unaligned'
28 | put_unaligned(__raw_readq(from), (uintptr_t *)to);
| ^~~~~~~~~~~~~
lib/io_copy.c: In function '__memcpy_toio':
>> lib/io_copy.c:57:25: error: implicit declaration of function '__raw_writeq'; did you mean '__raw_writel'? [-Wimplicit-function-declaration]
57 | __raw_writeq(get_unaligned((uintptr_t *)from), to);
| ^~~~~~~~~~~~
| __raw_writel
lib/io_copy.c: In function '__memset_io':
>> lib/io_copy.c:83:26: warning: left shift count >= width of type [-Wshift-count-overflow]
83 | qc |= qc << 32;
| ^~
vim +28 lib/io_copy.c
6a9bfa83709a84e Julian Vetter 2024-09-09 16
6a9bfa83709a84e Julian Vetter 2024-09-09 17 void __memcpy_fromio(void *to, const volatile void __iomem *from, size_t count)
6a9bfa83709a84e Julian Vetter 2024-09-09 18 {
6a9bfa83709a84e Julian Vetter 2024-09-09 19 while (count && !IS_ALIGNED((unsigned long)from, NATIVE_STORE_SIZE)) {
6a9bfa83709a84e Julian Vetter 2024-09-09 20 *(u8 *)to = __raw_readb(from);
6a9bfa83709a84e Julian Vetter 2024-09-09 21 from++;
6a9bfa83709a84e Julian Vetter 2024-09-09 22 to++;
6a9bfa83709a84e Julian Vetter 2024-09-09 23 count--;
6a9bfa83709a84e Julian Vetter 2024-09-09 24 }
6a9bfa83709a84e Julian Vetter 2024-09-09 25
6a9bfa83709a84e Julian Vetter 2024-09-09 26 while (count >= NATIVE_STORE_SIZE) {
6a9bfa83709a84e Julian Vetter 2024-09-09 27 if (IS_ENABLED(CONFIG_64BIT))
6a9bfa83709a84e Julian Vetter 2024-09-09 @28 put_unaligned(__raw_readq(from), (uintptr_t *)to);
6a9bfa83709a84e Julian Vetter 2024-09-09 29 else
6a9bfa83709a84e Julian Vetter 2024-09-09 30 put_unaligned(__raw_readl(from), (uintptr_t *)to);
6a9bfa83709a84e Julian Vetter 2024-09-09 31
6a9bfa83709a84e Julian Vetter 2024-09-09 32 from += NATIVE_STORE_SIZE;
6a9bfa83709a84e Julian Vetter 2024-09-09 33 to += NATIVE_STORE_SIZE;
6a9bfa83709a84e Julian Vetter 2024-09-09 34 count -= NATIVE_STORE_SIZE;
6a9bfa83709a84e Julian Vetter 2024-09-09 35 }
6a9bfa83709a84e Julian Vetter 2024-09-09 36
6a9bfa83709a84e Julian Vetter 2024-09-09 37 while (count) {
6a9bfa83709a84e Julian Vetter 2024-09-09 38 *(u8 *)to = __raw_readb(from);
6a9bfa83709a84e Julian Vetter 2024-09-09 39 from++;
6a9bfa83709a84e Julian Vetter 2024-09-09 40 to++;
6a9bfa83709a84e Julian Vetter 2024-09-09 41 count--;
6a9bfa83709a84e Julian Vetter 2024-09-09 42 }
6a9bfa83709a84e Julian Vetter 2024-09-09 43 }
6a9bfa83709a84e Julian Vetter 2024-09-09 44 EXPORT_SYMBOL(__memcpy_fromio);
6a9bfa83709a84e Julian Vetter 2024-09-09 45
6a9bfa83709a84e Julian Vetter 2024-09-09 46 void __memcpy_toio(volatile void __iomem *to, const void *from, size_t count)
6a9bfa83709a84e Julian Vetter 2024-09-09 47 {
6a9bfa83709a84e Julian Vetter 2024-09-09 48 while (count && !IS_ALIGNED((unsigned long)to, NATIVE_STORE_SIZE)) {
6a9bfa83709a84e Julian Vetter 2024-09-09 49 __raw_writeb(*(u8 *)from, to);
6a9bfa83709a84e Julian Vetter 2024-09-09 50 from++;
6a9bfa83709a84e Julian Vetter 2024-09-09 51 to++;
6a9bfa83709a84e Julian Vetter 2024-09-09 52 count--;
6a9bfa83709a84e Julian Vetter 2024-09-09 53 }
6a9bfa83709a84e Julian Vetter 2024-09-09 54
6a9bfa83709a84e Julian Vetter 2024-09-09 55 while (count >= NATIVE_STORE_SIZE) {
6a9bfa83709a84e Julian Vetter 2024-09-09 56 if (IS_ENABLED(CONFIG_64BIT))
6a9bfa83709a84e Julian Vetter 2024-09-09 @57 __raw_writeq(get_unaligned((uintptr_t *)from), to);
6a9bfa83709a84e Julian Vetter 2024-09-09 58 else
6a9bfa83709a84e Julian Vetter 2024-09-09 59 __raw_writel(get_unaligned((uintptr_t *)from), to);
6a9bfa83709a84e Julian Vetter 2024-09-09 60
6a9bfa83709a84e Julian Vetter 2024-09-09 61 from += NATIVE_STORE_SIZE;
6a9bfa83709a84e Julian Vetter 2024-09-09 62 to += NATIVE_STORE_SIZE;
6a9bfa83709a84e Julian Vetter 2024-09-09 63 count -= NATIVE_STORE_SIZE;
6a9bfa83709a84e Julian Vetter 2024-09-09 64 }
6a9bfa83709a84e Julian Vetter 2024-09-09 65
6a9bfa83709a84e Julian Vetter 2024-09-09 66 while (count) {
6a9bfa83709a84e Julian Vetter 2024-09-09 67 __raw_writeb(*(u8 *)from, to);
6a9bfa83709a84e Julian Vetter 2024-09-09 68 from++;
6a9bfa83709a84e Julian Vetter 2024-09-09 69 to++;
6a9bfa83709a84e Julian Vetter 2024-09-09 70 count--;
6a9bfa83709a84e Julian Vetter 2024-09-09 71 }
6a9bfa83709a84e Julian Vetter 2024-09-09 72 }
6a9bfa83709a84e Julian Vetter 2024-09-09 73 EXPORT_SYMBOL(__memcpy_toio);
6a9bfa83709a84e Julian Vetter 2024-09-09 74
6a9bfa83709a84e Julian Vetter 2024-09-09 75 void __memset_io(volatile void __iomem *dst, int c, size_t count)
6a9bfa83709a84e Julian Vetter 2024-09-09 76 {
6a9bfa83709a84e Julian Vetter 2024-09-09 77 uintptr_t qc = (u8)c;
6a9bfa83709a84e Julian Vetter 2024-09-09 78
6a9bfa83709a84e Julian Vetter 2024-09-09 79 qc |= qc << 8;
6a9bfa83709a84e Julian Vetter 2024-09-09 80 qc |= qc << 16;
6a9bfa83709a84e Julian Vetter 2024-09-09 81
6a9bfa83709a84e Julian Vetter 2024-09-09 82 if (IS_ENABLED(CONFIG_64BIT))
6a9bfa83709a84e Julian Vetter 2024-09-09 @83 qc |= qc << 32;
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v2 3/4] Use generic io memcpy functions on the csky architecture
2024-09-10 7:27 ` kernel test robot
@ 2024-09-10 9:15 ` Arnd Bergmann
2024-09-18 2:26 ` Guo Ren
0 siblings, 1 reply; 9+ messages in thread
From: Arnd Bergmann @ 2024-09-10 9:15 UTC (permalink / raw)
To: kernel test robot, Julian Vetter, Catalin Marinas, Will Deacon,
guoren, Huacai Chen, WANG Xuerui, Andrew Morton
Cc: oe-kbuild-all, Linux Memory Management List, linux-arm-kernel,
linux-kernel, linux-csky@vger.kernel.org, loongarch,
Yann Sionneau
On Tue, Sep 10, 2024, at 07:27, kernel test robot wrote:
> 6a9bfa83709a84e Julian Vetter 2024-09-09 55 while (count >=
> NATIVE_STORE_SIZE) {
> 6a9bfa83709a84e Julian Vetter 2024-09-09 56 if
> (IS_ENABLED(CONFIG_64BIT))
> 6a9bfa83709a84e Julian Vetter 2024-09-09 @57
> __raw_writeq(get_unaligned((uintptr_t *)from), to);
> 6a9bfa83709a84e Julian Vetter 2024-09-09 58 else
Right, this one actually has to be a preprocessor conditional
because __raw_writeq is not defined.
Arnd
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v2 0/4] Consolidate IO memcpy functions
2024-09-09 13:31 [PATCH v2 0/4] Consolidate IO memcpy functions Julian Vetter
` (3 preceding siblings ...)
2024-09-09 13:31 ` [PATCH v2 4/4] Use generic io memcpy functions on the loongarch architecture Julian Vetter
@ 2024-09-10 16:07 ` Arnd Bergmann
4 siblings, 0 replies; 9+ messages in thread
From: Arnd Bergmann @ 2024-09-10 16:07 UTC (permalink / raw)
To: Julian Vetter, Catalin Marinas, Will Deacon, guoren, Huacai Chen,
WANG Xuerui, Andrew Morton
Cc: linux-arm-kernel, linux-kernel, linux-csky@vger.kernel.org,
loongarch, Yann Sionneau
On Mon, Sep 9, 2024, at 13:31, Julian Vetter wrote:
> Thank you for your feedback Arnd. In regards to the filename, etc. I
> went with the first route and created a new file called io_copy.c.
> Although, I'm not sure if it's a good idea to create yet another file
> that serves a limited purpose. But I'm a bit afraid to add the
> functions to iomap_copy.c because there is no common consus in the
> architecture code about memcpy_{from,to}io. Some specify it with
> _memcpy_xx, some directly with memcpy_xx, and another bunch uses
> __memcpy_xx.
Just for clarification: the idea in that file is to have a
generic implementation and use that on all architectures that
do not define their own, hence the "#define __iowrite32_copy
__iowrite32_copy" for the three that do. The exact same method
would clearly work for memcpy_fromio().
At the moment, there are 13 architectures that define a custom
memcpy_fromio/memcpy_toio/memset_io, and nine that rely on the
fallback using memcpy()/memset() in include/asm-generic/io.h.
What we could do here is to first change the fallback
implementation in asm-generic/io.h to your new generic
version and then remove the three extra copies.
> So, if we want to merge it with iomap_copy.c, I would need
> to export the __memcpy_xx symbols for all architectures that don't want
> to use the "generic" memcpy_xx functions for now or rename their given
> implementation to __memcpy_xx, right? But if you think it's better to
> merge the two, I will have another look and modify the code for all
> remaining architectures as well.
No, this would not be necessary: the architectures that
already have a custom memcpy_fromio() etc can just keep
using the same one. Cleaning those up is something we
can do later, in which case most of them would probably
converge on the generic version.
Arnd
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v2 3/4] Use generic io memcpy functions on the csky architecture
2024-09-10 9:15 ` Arnd Bergmann
@ 2024-09-18 2:26 ` Guo Ren
0 siblings, 0 replies; 9+ messages in thread
From: Guo Ren @ 2024-09-18 2:26 UTC (permalink / raw)
To: Arnd Bergmann
Cc: kernel test robot, Julian Vetter, Catalin Marinas, Will Deacon,
Huacai Chen, WANG Xuerui, Andrew Morton, oe-kbuild-all,
Linux Memory Management List, linux-arm-kernel, linux-kernel,
linux-csky@vger.kernel.org, loongarch, Yann Sionneau
On Tue, Sep 10, 2024 at 5:16 PM Arnd Bergmann <arnd@arndb.de> wrote:
>
> On Tue, Sep 10, 2024, at 07:27, kernel test robot wrote:
>
> > 6a9bfa83709a84e Julian Vetter 2024-09-09 55 while (count >=
> > NATIVE_STORE_SIZE) {
> > 6a9bfa83709a84e Julian Vetter 2024-09-09 56 if
> > (IS_ENABLED(CONFIG_64BIT))
> > 6a9bfa83709a84e Julian Vetter 2024-09-09 @57
> > __raw_writeq(get_unaligned((uintptr_t *)from), to);
> > 6a9bfa83709a84e Julian Vetter 2024-09-09 58 else
>
> Right, this one actually has to be a preprocessor conditional
> because __raw_writeq is not defined.
All 32-bit ISAs didn't support __raw_writeq.
e.g.: include/asm-generic/io.h
#ifdef CONFIG_64BIT
#ifndef __raw_writeq
#define __raw_writeq __raw_writeq
static inline void __raw_writeq(u64 value, volatile void __iomem *addr)
{
*(volatile u64 __force *)addr = value;
}
#endif
#endif /* CONFIG_64BIT */
e.g.: arch/riscv/include/asm/mmio.h
#ifdef CONFIG_64BIT
#define __raw_writeq __raw_writeq
static inline void __raw_writeq(u64 val, volatile void __iomem *addr)
{
asm volatile("sd %0, 0(%1)" : : "r" (val), "r" (addr));
}
#endif
>
> Arnd
--
Best Regards
Guo Ren
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2024-09-18 2:28 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-09-09 13:31 [PATCH v2 0/4] Consolidate IO memcpy functions Julian Vetter
2024-09-09 13:31 ` [PATCH v2 1/4] Consolidate __memcpy_{to,from}io and __memset_io into a single lib Julian Vetter
2024-09-09 13:31 ` [PATCH v2 2/4] Use generic io memcpy functions on the arm64 architecture Julian Vetter
2024-09-09 13:31 ` [PATCH v2 3/4] Use generic io memcpy functions on the csky architecture Julian Vetter
2024-09-10 7:27 ` kernel test robot
2024-09-10 9:15 ` Arnd Bergmann
2024-09-18 2:26 ` Guo Ren
2024-09-09 13:31 ` [PATCH v2 4/4] Use generic io memcpy functions on the loongarch architecture Julian Vetter
2024-09-10 16:07 ` [PATCH v2 0/4] Consolidate IO memcpy functions Arnd Bergmann
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).