diff mbox series

[v7,09/10] um: Add dummy implementation for IO memcpy/memset

Message ID 20240930132321.2785718-10-jvetter@kalrayinc.com (mailing list archive)
State New, archived
Headers show
Series Consolidate IO memcpy functions | expand

Commit Message

Julian Vetter Sept. 30, 2024, 1:23 p.m. UTC
The um arch is the only architecture that sets the config 'NO_IOMEM',
yet drivers that use IO memory can be selected. In order to make these
drivers happy we add a dummy implementation for memcpy_{from,to}io and
memset_io functions.

Reviewed-by: Yann Sionneau <ysionneau@kalrayinc.com>
Signed-off-by: Julian Vetter <jvetter@kalrayinc.com>
---
Changes for v7:
- New patch
---
 arch/um/include/asm/io.h | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

Comments

Johannes Berg Oct. 1, 2024, 12:53 p.m. UTC | #1
On Mon, 2024-09-30 at 15:23 +0200, Julian Vetter wrote:
> The um arch is the only architecture that sets the config 'NO_IOMEM',
> yet drivers that use IO memory can be selected. In order to make these
> drivers happy we add a dummy implementation for memcpy_{from,to}io and
> memset_io functions.

Maybe I'm just not understanding this series, but how does this work
with lib/logic_iomem.c?

You're adding these inlines unconditionally, so if this included
logic_io.h, you should get symbol conflicts?

Also not sure these functions should/need to do anything at all, there's
no IO memory on ARCH=um in case of not having logic_io.h. Maybe even
BUG_ON() or something? It can't be reachable (under correct drivers)
since ioremap() always returns NULL (without logic_iomem).

I think Arnd also said that other architectures might want to use
logic_iomem, though I don't see any now.

johannes
Julian Vetter Oct. 7, 2024, 7:49 a.m. UTC | #2
On 10/1/24 14:53, Johannes Berg wrote:
> On Mon, 2024-09-30 at 15:23 +0200, Julian Vetter wrote:
>> The um arch is the only architecture that sets the config 'NO_IOMEM',
>> yet drivers that use IO memory can be selected. In order to make these
>> drivers happy we add a dummy implementation for memcpy_{from,to}io and
>> memset_io functions.
> 
> Maybe I'm just not understanding this series, but how does this work
> with lib/logic_iomem.c?
> 
No, I think you're understanding the series correctly. It doesn't work. 
I will revert this.

> You're adding these inlines unconditionally, so if this included
> logic_io.h, you should get symbol conflicts?
> 
> Also not sure these functions should/need to do anything at all, there's
> no IO memory on ARCH=um in case of not having logic_io.h. Maybe even
> BUG_ON() or something? It can't be reachable (under correct drivers)
> since ioremap() always returns NULL (without logic_iomem).
> 
Thanks. You're right. I added this patch because there was a build robot 
on some mailinglist building a random config with 'ARCH=um' and with 
some MTD drivers that actually use memcpy_fromio or memcpy_toio. These 
drivers are not guarded by a 'depends on HAS_IOMEM'. I thought I could 
simply fix it by adding stub functions to the um arch. Because I saw 
there are A LOT of drivers that use IO functions without being guarded 
by 'depends on HAS_IOMEM'. Not sure though, how to handle this case.

> I think Arnd also said that other architectures might want to use
> logic_iomem, though I don't see any now.
> 
> johannes
> 
> 
> 
>
Johannes Berg Oct. 7, 2024, 8:06 a.m. UTC | #3
On Mon, 2024-10-07 at 09:49 +0200, Julian Vetter wrote:
> 
> > > The um arch is the only architecture that sets the config 'NO_IOMEM',

(you did note this, for the comment below)

> No, I think you're understanding the series correctly. It doesn't work. 
> I will revert this.

OK.

> > You're adding these inlines unconditionally, so if this included
> > logic_io.h, you should get symbol conflicts?
> > 
> > Also not sure these functions should/need to do anything at all, there's
> > no IO memory on ARCH=um in case of not having logic_io.h. Maybe even
> > BUG_ON() or something? It can't be reachable (under correct drivers)
> > since ioremap() always returns NULL (without logic_iomem).

> Thanks. You're right. I added this patch because there was a build robot 
> on some mailinglist building a random config with 'ARCH=um' and with 
> some MTD drivers that actually use memcpy_fromio or memcpy_toio. These 
> drivers are not guarded by a 'depends on HAS_IOMEM'. I thought I could 
> simply fix it by adding stub functions to the um arch. Because I saw 
> there are A LOT of drivers that use IO functions without being guarded 
> by 'depends on HAS_IOMEM'. Not sure though, how to handle this case.

Right, well, as you noted above ARCH=um is the only architecture that
has NO_IOMEM, so I suppose drivers are just broken. But e.g.
kernel/iomem.c is also only ever built if you have HAS_IOMEM, so devm_*
functions related to this are not available.

So I don't know. On the one hand, it feels correct to have NO_IOMEM and
HAS_IOMEM, on the other hand that's a bit of a fight against windmills?


What happens now though? Seems it should _already_ not build with
ARCH=um and memcpy_*io() being used? No, I guess it picked up the asm-
generic version?

Hm. I'm almost thinking we should let such drivers not build, and then
see that they add appropriate HAS_IOMEM dependencies, but ... windmills?

johannes
diff mbox series

Patch

diff --git a/arch/um/include/asm/io.h b/arch/um/include/asm/io.h
index 9ea42cc746d9..f02f40609798 100644
--- a/arch/um/include/asm/io.h
+++ b/arch/um/include/asm/io.h
@@ -21,6 +21,23 @@  static inline void iounmap(void __iomem *addr)
 }
 #endif /* iounmap */
 
+static inline void memset_io(volatile void __iomem *dst, int c, size_t count)
+{
+	memset((void *)dst, c, count);
+}
+
+static inline void memcpy_toio(volatile void __iomem *to, const void *from,
+			       size_t count)
+{
+	memcpy((void *)to, from, count);
+}
+
+static inline void memcpy_fromio(void *to, const volatile void __iomem *from,
+				 size_t count)
+{
+	memcpy(to, (void *)from, count);
+}
+
 #include <asm-generic/io.h>
 
 #endif