arch/loongarch/include/asm/loongarch.h | 31 +++++++++++--------------- 1 file changed, 13 insertions(+), 18 deletions(-)
larchintrin.h is a system header of compiler, include it in the
kernel header may lead to the fatal error "'larchintrin.h' file
not found".
There are two related cases so far:
(1) When compiling samples/bpf, it has been fixed in the latest
kernel [1].
(2) When running bcc script, it has been fixed in the latest
bcc [2] [3], like this:
$ /usr/share/bcc/tools/filetop
In file included from <built-in>:4:
In file included from /virtual/include/bcc/helpers.h:54:
In file included from arch/loongarch/include/asm/page.h:7:
In file included from arch/loongarch/include/asm/addrspace.h:9:
arch/loongarch/include/asm/loongarch.h:11:10: fatal error: 'larchintrin.h' file not found
11 | #include <larchintrin.h>
| ^~~~~~~~~~~~~~~
1 error generated.
Maybe there are same errors for the other unknown projects, it is
annoyance to add the include path each time. In order to avoid such
errors once and for all, do not include larchintrin.h, just use the
builtin functions directly.
[1] https://git.kernel.org/torvalds/c/548762f05d19
[2] https://github.com/iovisor/bcc/commit/8aa9f7072d53
[3] https://github.com/iovisor/bcc/commit/af8258c21004
Cc: stable@vger.kernel.org # 6.6+
Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
---
arch/loongarch/include/asm/loongarch.h | 31 +++++++++++---------------
1 file changed, 13 insertions(+), 18 deletions(-)
diff --git a/arch/loongarch/include/asm/loongarch.h b/arch/loongarch/include/asm/loongarch.h
index 52651aa0e583..b33e4c9cb903 100644
--- a/arch/loongarch/include/asm/loongarch.h
+++ b/arch/loongarch/include/asm/loongarch.h
@@ -9,14 +9,6 @@
#include <linux/linkage.h>
#include <linux/types.h>
-#ifndef __ASSEMBLY__
-#include <larchintrin.h>
-
-/* CPUCFG */
-#define read_cpucfg(reg) __cpucfg(reg)
-
-#endif /* !__ASSEMBLY__ */
-
#ifdef __ASSEMBLY__
/* LoongArch Registers */
@@ -173,19 +165,22 @@
#ifndef __ASSEMBLY__
+/* CPUCFG */
+#define read_cpucfg(reg) __builtin_loongarch_cpucfg(reg)
+
/* CSR */
-#define csr_read32(reg) __csrrd_w(reg)
-#define csr_read64(reg) __csrrd_d(reg)
-#define csr_write32(val, reg) __csrwr_w(val, reg)
-#define csr_write64(val, reg) __csrwr_d(val, reg)
-#define csr_xchg32(val, mask, reg) __csrxchg_w(val, mask, reg)
-#define csr_xchg64(val, mask, reg) __csrxchg_d(val, mask, reg)
+#define csr_read32(reg) __builtin_loongarch_csrrd_w(reg)
+#define csr_read64(reg) __builtin_loongarch_csrrd_d(reg)
+#define csr_write32(val, reg) __builtin_loongarch_csrwr_w(val, reg)
+#define csr_write64(val, reg) __builtin_loongarch_csrwr_d(val, reg)
+#define csr_xchg32(val, mask, reg) __builtin_loongarch_csrxchg_w(val, mask, reg)
+#define csr_xchg64(val, mask, reg) __builtin_loongarch_csrxchg_d(val, mask, reg)
/* IOCSR */
-#define iocsr_read32(reg) __iocsrrd_w(reg)
-#define iocsr_read64(reg) __iocsrrd_d(reg)
-#define iocsr_write32(val, reg) __iocsrwr_w(val, reg)
-#define iocsr_write64(val, reg) __iocsrwr_d(val, reg)
+#define iocsr_read32(reg) __builtin_loongarch_iocsrrd_w(reg)
+#define iocsr_read64(reg) __builtin_loongarch_iocsrrd_d(reg)
+#define iocsr_write32(val, reg) __builtin_loongarch_iocsrwr_w(val, reg)
+#define iocsr_write64(val, reg) __builtin_loongarch_iocsrwr_d(val, reg)
#endif /* !__ASSEMBLY__ */
--
2.42.0
On Tue, 2025-05-20 at 14:49 +0800, Tiezhu Yang wrote: > larchintrin.h is a system header of compiler, include it in the > kernel header may lead to the fatal error "'larchintrin.h' file > not found". > > There are two related cases so far: > > (1) When compiling samples/bpf, it has been fixed in the latest > kernel [1]. > > (2) When running bcc script, it has been fixed in the latest > bcc [2] [3], like this: > > $ /usr/share/bcc/tools/filetop > In file included from <built-in>:4: > In file included from /virtual/include/bcc/helpers.h:54: > In file included from arch/loongarch/include/asm/page.h:7: > In file included from arch/loongarch/include/asm/addrspace.h:9: > arch/loongarch/include/asm/loongarch.h:11:10: fatal error: 'larchintrin.h' file not found > 11 | #include <larchintrin.h> > | ^~~~~~~~~~~~~~~ > 1 error generated. > > Maybe there are same errors for the other unknown projects, it is > annoyance to add the include path each time. In order to avoid such > errors once and for all, do not include larchintrin.h, just use the > builtin functions directly. Sorry, but in GCC those builtin functions are not documented and may subject to change in the future. Only the larchintrin.h interface is documented. Thus if you don't want to rely on GCC for those operations, you may need to write inline asm... -- Xi Ruoyao <xry111@xry111.site> School of Aerospace Science and Technology, Xidian University
On 2025/5/21 下午1:41, Xi Ruoyao wrote: > On Tue, 2025-05-20 at 14:49 +0800, Tiezhu Yang wrote: >> larchintrin.h is a system header of compiler, include it in the >> kernel header may lead to the fatal error "'larchintrin.h' file >> not found". >> >> There are two related cases so far: >> >> (1) When compiling samples/bpf, it has been fixed in the latest >> kernel [1]. >> >> (2) When running bcc script, it has been fixed in the latest >> bcc [2] [3], like this: >> >> $ /usr/share/bcc/tools/filetop >> In file included from <built-in>:4: >> In file included from /virtual/include/bcc/helpers.h:54: >> In file included from arch/loongarch/include/asm/page.h:7: >> In file included from arch/loongarch/include/asm/addrspace.h:9: >> arch/loongarch/include/asm/loongarch.h:11:10: fatal error: 'larchintrin.h' file not found >> 11 | #include <larchintrin.h> >> | ^~~~~~~~~~~~~~~ >> 1 error generated. >> >> Maybe there are same errors for the other unknown projects, it is >> annoyance to add the include path each time. In order to avoid such >> errors once and for all, do not include larchintrin.h, just use the >> builtin functions directly. > > Sorry, but in GCC those builtin functions are not documented and may > subject to change in the future. Only the larchintrin.h interface is > documented. AFAICT, the LoongArch Base Built-in Functions are listed in the GCC documentation [1], they will not be changed easily and frequently in my opinion. __builtin_loongarch_cpucfg() __builtin_loongarch_csrrd_w() __builtin_loongarch_csrrd_d() __builtin_loongarch_csrwr_w() __builtin_loongarch_csrwr_d() __builtin_loongarch_csrxchg_w() __builtin_loongarch_csrxchg_d() __builtin_loongarch_iocsrrd_w() __builtin_loongarch_iocsrrd_d() __builtin_loongarch_iocsrwr_w() __builtin_loongarch_iocsrwr_d() > Thus if you don't want to rely on GCC for those operations, you may need > to write inline asm... so these builtin functions can be used directly and safely. [1] https://gcc.gnu.org/onlinedocs/gcc/LoongArch-Base-Built-in-Functions.html Thanks, Tiezhu
On Tue, 2025-05-27 at 11:17 +0800, Tiezhu Yang wrote: > On 2025/5/21 下午1:41, Xi Ruoyao wrote: > > On Tue, 2025-05-20 at 14:49 +0800, Tiezhu Yang wrote: > > > larchintrin.h is a system header of compiler, include it in the > > > kernel header may lead to the fatal error "'larchintrin.h' file > > > not found". > > > > > > There are two related cases so far: > > > > > > (1) When compiling samples/bpf, it has been fixed in the latest > > > kernel [1]. > > > > > > (2) When running bcc script, it has been fixed in the latest > > > bcc [2] [3], like this: > > > > > > $ /usr/share/bcc/tools/filetop > > > In file included from <built-in>:4: > > > In file included from /virtual/include/bcc/helpers.h:54: > > > In file included from arch/loongarch/include/asm/page.h:7: > > > In file included from arch/loongarch/include/asm/addrspace.h:9: > > > arch/loongarch/include/asm/loongarch.h:11:10: fatal error: > > > 'larchintrin.h' file not found > > > 11 | #include <larchintrin.h> > > > | ^~~~~~~~~~~~~~~ > > > 1 error generated. > > > > > > Maybe there are same errors for the other unknown projects, it is > > > annoyance to add the include path each time. In order to avoid > > > such > > > errors once and for all, do not include larchintrin.h, just use > > > the > > > builtin functions directly. > > > > Sorry, but in GCC those builtin functions are not documented and may > > subject to change in the future. Only the larchintrin.h interface > > is > > documented. > > AFAICT, the LoongArch Base Built-in Functions are listed in the GCC > documentation [1], they will not be changed easily and frequently in > my opinion. > > __builtin_loongarch_cpucfg() > __builtin_loongarch_csrrd_w() > __builtin_loongarch_csrrd_d() > __builtin_loongarch_csrwr_w() > __builtin_loongarch_csrwr_d() > __builtin_loongarch_csrxchg_w() > __builtin_loongarch_csrxchg_d() > __builtin_loongarch_iocsrrd_w() > __builtin_loongarch_iocsrrd_d() > __builtin_loongarch_iocsrwr_w() > __builtin_loongarch_iocsrwr_d() > > > Thus if you don't want to rely on GCC for those operations, you may > > need > > to write inline asm... > > so these builtin functions can be used directly and safely. Oops, I mistakenly believed they were like __builtin_lsx_* which are not documented. So yes they can be used directly. -- Xi Ruoyao <xry111@xry111.site> School of Aerospace Science and Technology, Xidian University
On Tue, May 27, 2025 at 11:47 AM Xi Ruoyao <xry111@xry111.site> wrote: > > On Tue, 2025-05-27 at 11:17 +0800, Tiezhu Yang wrote: > > On 2025/5/21 下午1:41, Xi Ruoyao wrote: > > > On Tue, 2025-05-20 at 14:49 +0800, Tiezhu Yang wrote: > > > > larchintrin.h is a system header of compiler, include it in the > > > > kernel header may lead to the fatal error "'larchintrin.h' file > > > > not found". > > > > > > > > There are two related cases so far: > > > > > > > > (1) When compiling samples/bpf, it has been fixed in the latest > > > > kernel [1]. > > > > > > > > (2) When running bcc script, it has been fixed in the latest > > > > bcc [2] [3], like this: > > > > > > > > $ /usr/share/bcc/tools/filetop > > > > In file included from <built-in>:4: > > > > In file included from /virtual/include/bcc/helpers.h:54: > > > > In file included from arch/loongarch/include/asm/page.h:7: > > > > In file included from arch/loongarch/include/asm/addrspace.h:9: > > > > arch/loongarch/include/asm/loongarch.h:11:10: fatal error: > > > > 'larchintrin.h' file not found > > > > 11 | #include <larchintrin.h> > > > > | ^~~~~~~~~~~~~~~ > > > > 1 error generated. > > > > > > > > Maybe there are same errors for the other unknown projects, it is > > > > annoyance to add the include path each time. In order to avoid > > > > such > > > > errors once and for all, do not include larchintrin.h, just use > > > > the > > > > builtin functions directly. > > > > > > Sorry, but in GCC those builtin functions are not documented and may > > > subject to change in the future. Only the larchintrin.h interface > > > is > > > documented. > > > > AFAICT, the LoongArch Base Built-in Functions are listed in the GCC > > documentation [1], they will not be changed easily and frequently in > > my opinion. > > > > __builtin_loongarch_cpucfg() > > __builtin_loongarch_csrrd_w() > > __builtin_loongarch_csrrd_d() > > __builtin_loongarch_csrwr_w() > > __builtin_loongarch_csrwr_d() > > __builtin_loongarch_csrxchg_w() > > __builtin_loongarch_csrxchg_d() > > __builtin_loongarch_iocsrrd_w() > > __builtin_loongarch_iocsrrd_d() > > __builtin_loongarch_iocsrwr_w() > > __builtin_loongarch_iocsrwr_d() > > > > > Thus if you don't want to rely on GCC for those operations, you may > > > need > > > to write inline asm... > > > > so these builtin functions can be used directly and safely. > > Oops, I mistakenly believed they were like __builtin_lsx_* which are not > documented. > > So yes they can be used directly. I don't think so. 1. csr & iocsr can be only used in kernel mode, if the kernel doesn't use the convenient short names, then the short names are totally useless. 2. We get larchintrin.h included by "KBUILD_CFLAGS += -isystem $(shell $(CC) -print-file-name=include)", and this manner is also used by other architectures. 3. I don't think there will be many projects that need to be modified. Huacai > > -- > Xi Ruoyao <xry111@xry111.site> > School of Aerospace Science and Technology, Xidian University
On Tue, May 20, 2025 at 2:49 PM Tiezhu Yang <yangtiezhu@loongson.cn> wrote: > > larchintrin.h is a system header of compiler, include it in the > kernel header may lead to the fatal error "'larchintrin.h' file > not found". > > There are two related cases so far: > > (1) When compiling samples/bpf, it has been fixed in the latest > kernel [1]. > > (2) When running bcc script, it has been fixed in the latest > bcc [2] [3], like this: > > $ /usr/share/bcc/tools/filetop > In file included from <built-in>:4: > In file included from /virtual/include/bcc/helpers.h:54: > In file included from arch/loongarch/include/asm/page.h:7: > In file included from arch/loongarch/include/asm/addrspace.h:9: > arch/loongarch/include/asm/loongarch.h:11:10: fatal error: 'larchintrin.h' file not found > 11 | #include <larchintrin.h> > | ^~~~~~~~~~~~~~~ > 1 error generated. > > Maybe there are same errors for the other unknown projects, it is > annoyance to add the include path each time. In order to avoid such > errors once and for all, do not include larchintrin.h, just use the > builtin functions directly. > Acked-by: Hengqi Chen <hengqi.chen@gmail.com> > [1] https://git.kernel.org/torvalds/c/548762f05d19 > [2] https://github.com/iovisor/bcc/commit/8aa9f7072d53 > [3] https://github.com/iovisor/bcc/commit/af8258c21004 > > Cc: stable@vger.kernel.org # 6.6+ > Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn> > --- > arch/loongarch/include/asm/loongarch.h | 31 +++++++++++--------------- > 1 file changed, 13 insertions(+), 18 deletions(-) > > diff --git a/arch/loongarch/include/asm/loongarch.h b/arch/loongarch/include/asm/loongarch.h > index 52651aa0e583..b33e4c9cb903 100644 > --- a/arch/loongarch/include/asm/loongarch.h > +++ b/arch/loongarch/include/asm/loongarch.h > @@ -9,14 +9,6 @@ > #include <linux/linkage.h> > #include <linux/types.h> > > -#ifndef __ASSEMBLY__ > -#include <larchintrin.h> > - > -/* CPUCFG */ > -#define read_cpucfg(reg) __cpucfg(reg) > - > -#endif /* !__ASSEMBLY__ */ > - > #ifdef __ASSEMBLY__ > > /* LoongArch Registers */ > @@ -173,19 +165,22 @@ > > #ifndef __ASSEMBLY__ > > +/* CPUCFG */ > +#define read_cpucfg(reg) __builtin_loongarch_cpucfg(reg) > + > /* CSR */ > -#define csr_read32(reg) __csrrd_w(reg) > -#define csr_read64(reg) __csrrd_d(reg) > -#define csr_write32(val, reg) __csrwr_w(val, reg) > -#define csr_write64(val, reg) __csrwr_d(val, reg) > -#define csr_xchg32(val, mask, reg) __csrxchg_w(val, mask, reg) > -#define csr_xchg64(val, mask, reg) __csrxchg_d(val, mask, reg) > +#define csr_read32(reg) __builtin_loongarch_csrrd_w(reg) > +#define csr_read64(reg) __builtin_loongarch_csrrd_d(reg) > +#define csr_write32(val, reg) __builtin_loongarch_csrwr_w(val, reg) > +#define csr_write64(val, reg) __builtin_loongarch_csrwr_d(val, reg) > +#define csr_xchg32(val, mask, reg) __builtin_loongarch_csrxchg_w(val, mask, reg) > +#define csr_xchg64(val, mask, reg) __builtin_loongarch_csrxchg_d(val, mask, reg) > > /* IOCSR */ > -#define iocsr_read32(reg) __iocsrrd_w(reg) > -#define iocsr_read64(reg) __iocsrrd_d(reg) > -#define iocsr_write32(val, reg) __iocsrwr_w(val, reg) > -#define iocsr_write64(val, reg) __iocsrwr_d(val, reg) > +#define iocsr_read32(reg) __builtin_loongarch_iocsrrd_w(reg) > +#define iocsr_read64(reg) __builtin_loongarch_iocsrrd_d(reg) > +#define iocsr_write32(val, reg) __builtin_loongarch_iocsrwr_w(val, reg) > +#define iocsr_write64(val, reg) __builtin_loongarch_iocsrwr_d(val, reg) > > #endif /* !__ASSEMBLY__ */ > > -- > 2.42.0 > >
© 2016 - 2025 Red Hat, Inc.