lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250520064936.32291-1-yangtiezhu@loongson.cn>
Date: Tue, 20 May 2025 14:49:36 +0800
From: Tiezhu Yang <yangtiezhu@...ngson.cn>
To: Huacai Chen <chenhuacai@...nel.org>
Cc: loongarch@...ts.linux.dev,
	linux-kernel@...r.kernel.org
Subject: [RFC PATCH] LoongArch: Do not include larchintrin.h

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@...r.kernel.org # 6.6+
Signed-off-by: Tiezhu Yang <yangtiezhu@...ngson.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


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ