[PATCH v3 6/7] asm-generic: percpu: Add assembly guard

Tiwei Bie posted 7 patches 2 weeks, 4 days ago
[PATCH v3 6/7] asm-generic: percpu: Add assembly guard
Posted by Tiwei Bie 2 weeks, 4 days ago
From: Tiwei Bie <tiwei.btw@antgroup.com>

Currently, asm/percpu.h is directly or indirectly included by
some assembly files on x86. Some of them (e.g., checksum_32.S)
are also used on um. But x86 and um provide different versions
of asm/percpu.h -- um uses asm-generic/percpu.h directly.

When SMP is enabled, asm-generic/percpu.h will introduce C code
that cannot be assembled. Since asm-generic/percpu.h currently
is not designed for use in assembly, and these assembly files
do not actually need asm/percpu.h on um, let's add the assembly
guard in asm-generic/percpu.h to fix this issue.

Cc: Arnd Bergmann <arnd@arndb.de>
Cc: linux-arch@vger.kernel.org
Signed-off-by: Tiwei Bie <tiwei.btw@antgroup.com>
---
 include/asm-generic/percpu.h | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/include/asm-generic/percpu.h b/include/asm-generic/percpu.h
index 02aeca21479a..6628670bcb90 100644
--- a/include/asm-generic/percpu.h
+++ b/include/asm-generic/percpu.h
@@ -2,6 +2,8 @@
 #ifndef _ASM_GENERIC_PERCPU_H_
 #define _ASM_GENERIC_PERCPU_H_
 
+#ifndef __ASSEMBLER__
+
 #include <linux/compiler.h>
 #include <linux/threads.h>
 #include <linux/percpu-defs.h>
@@ -557,4 +559,5 @@ do {									\
 	this_cpu_generic_cmpxchg(pcp, oval, nval)
 #endif
 
+#endif /* __ASSEMBLER__ */
 #endif /* _ASM_GENERIC_PERCPU_H_ */
-- 
2.34.1
Re: [PATCH v3 6/7] asm-generic: percpu: Add assembly guard
Posted by Arnd Bergmann 2 weeks, 3 days ago
On Sun, Sep 14, 2025, at 17:56, Tiwei Bie wrote:
> From: Tiwei Bie <tiwei.btw@antgroup.com>
>
> Currently, asm/percpu.h is directly or indirectly included by
> some assembly files on x86. Some of them (e.g., checksum_32.S)
> are also used on um. But x86 and um provide different versions
> of asm/percpu.h -- um uses asm-generic/percpu.h directly.
>
> When SMP is enabled, asm-generic/percpu.h will introduce C code
> that cannot be assembled. Since asm-generic/percpu.h currently
> is not designed for use in assembly, and these assembly files
> do not actually need asm/percpu.h on um, let's add the assembly
> guard in asm-generic/percpu.h to fix this issue.
>
> Cc: Arnd Bergmann <arnd@arndb.de>
> Cc: linux-arch@vger.kernel.org
> Signed-off-by: Tiwei Bie <tiwei.btw@antgroup.com>

Have you tried if you can remove the percpu.h dependency from
the files that currently include it? In many cases it should
be enough to use percpu-defs.h.

If that doesn't work, I have no objections to this patch either.

Acked-by: Arnd Bergmann <arnd@arndb.de>
Re: [PATCH v3 6/7] asm-generic: percpu: Add assembly guard
Posted by Tiwei Bie 2 weeks, 3 days ago
On Mon, 15 Sep 2025 09:40:35 +0200, Arnd Bergmann wrote:
> On Sun, Sep 14, 2025, at 17:56, Tiwei Bie wrote:
> > From: Tiwei Bie <tiwei.btw@antgroup.com>
> >
> > Currently, asm/percpu.h is directly or indirectly included by
> > some assembly files on x86. Some of them (e.g., checksum_32.S)
> > are also used on um. But x86 and um provide different versions
> > of asm/percpu.h -- um uses asm-generic/percpu.h directly.
> >
> > When SMP is enabled, asm-generic/percpu.h will introduce C code
> > that cannot be assembled. Since asm-generic/percpu.h currently
> > is not designed for use in assembly, and these assembly files
> > do not actually need asm/percpu.h on um, let's add the assembly
> > guard in asm-generic/percpu.h to fix this issue.
> >
> > Cc: Arnd Bergmann <arnd@arndb.de>
> > Cc: linux-arch@vger.kernel.org
> > Signed-off-by: Tiwei Bie <tiwei.btw@antgroup.com>
> 
> Have you tried if you can remove the percpu.h dependency from
> the files that currently include it? In many cases it should
> be enough to use percpu-defs.h.

It doesn't seem to work. The indirect inclusion of asm/percpu.h
comes from asm/nospec-branch.h, which expands DECLARE_PER_CPU()
and thus requires asm/percpu.h.

> 
> If that doesn't work, I have no objections to this patch either.
> 
> Acked-by: Arnd Bergmann <arnd@arndb.de>

Thanks! :)

Regards,
Tiwei