2022-08-31 07:12:46

by Yupeng Li

[permalink] [raw]
Subject: [PATCH 1/1] LoongArch: Fixed loongarch kernel csr_xxx implicit declaration.

Loongarch CSR register operation related interface, use the
interface defined __builtin_loongarch_xxx instead.
Build kernel error messages like:

CALL scripts/atomic/check-atomics.sh
CC arch/loongarch/kernel/asm-offsets.s
In file included from ./arch/loongarch/include/asm/cpu-info.h:11,
from ./arch/loongarch/include/asm/processor.h:13,
from ./arch/loongarch/include/asm/thread_info.h:15,
from ./include/linux/thread_info.h:60,
from ./include/asm-generic/current.h:5,
from ./arch/loongarch/include/generated/asm/current.h:1,
from ./include/linux/sched.h:12,
from arch/loongarch/kernel/asm-offsets.c:8:
./arch/loongarch/include/asm/loongarch.h: In function 'csr_read32':
./arch/loongarch/include/asm/loongarch.h:232:9: error: implicit declaration of function '__csrrd_w'; did you mean '__iocsrrd_w'? [-Werror=implicit-function-declaration]
return __csrrd_w(reg);
^~~~~~~~~
__iocsrrd_w
./arch/loongarch/include/asm/loongarch.h: In function 'csr_read64':
./arch/loongarch/include/asm/loongarch.h:237:9: error: implicit declaration of function '__csrrd_d'; did you mean '__iocsrrd_d'? [-Werror=implicit-function-declaration]
return __csrrd_d(reg);
^~~~~~~~~
__iocsrrd_d
./arch/loongarch/include/asm/loongarch.h: In function 'csr_write32':
./arch/loongarch/include/asm/loongarch.h:242:2: error: implicit declaration of function '__csrwr_w'; did you mean '__iocsrwr_w'? [-Werror=implicit-function-declaration]
__csrwr_w(val, reg);
^~~~~~~~~
__iocsrwr_w
./arch/loongarch/include/asm/loongarch.h: In function 'csr_write64':
./arch/loongarch/include/asm/loongarch.h:247:2: error: implicit declaration of function '__csrwr_d'; did you mean '__iocsrwr_d'? [-Werror=implicit-function-declaration]
__csrwr_d(val, reg);
^~~~~~~~~
__iocsrwr_d
./arch/loongarch/include/asm/loongarch.h: In function 'csr_xchg32':
./arch/loongarch/include/asm/loongarch.h:252:9: error: implicit declaration of function '__csrxchg_w'; did you mean '__cmpxchg'? [-Werror=implicit-function-declaration]
return __csrxchg_w(val, mask, reg);
^~~~~~~~~~~
__cmpxchg
./arch/loongarch/include/asm/loongarch.h: In function 'csr_xchg64':
./arch/loongarch/include/asm/loongarch.h:257:9: error: implicit declaration of function '__csrxchg_d'; did you mean '__cmpxchg'? [-Werror=implicit-function-declaration]
return __csrxchg_d(val, mask, reg);
^~~~~~~~~~~
__cmpxchg
cc1: all warnings being treated as errors
make[1]: *** [scripts/Makefile.build:117:arch/loongarch/kernel/asm-offsets.s] 错误 1
make: *** [Makefile:1205:prepare0] 错误 2

Signed-off-by: Yupeng Li <[email protected]>
Signed-off-by: Caicai <[email protected]>
---
arch/loongarch/include/asm/loongarch.h | 23 +++++++++++------------
1 file changed, 11 insertions(+), 12 deletions(-)

diff --git a/arch/loongarch/include/asm/loongarch.h b/arch/loongarch/include/asm/loongarch.h
index 3ba4f7e87cd2..576ec266d9fc 100644
--- a/arch/loongarch/include/asm/loongarch.h
+++ b/arch/loongarch/include/asm/loongarch.h
@@ -10,7 +10,6 @@
#include <linux/types.h>

#ifndef __ASSEMBLY__
-#include <larchintrin.h>

/*
* parse_r var, r - Helper assembler macro for parsing register names.
@@ -58,7 +57,7 @@ __asm__(".macro parse_r var r\n\t"
/* CPUCFG */
static inline u32 read_cpucfg(u32 reg)
{
- return __cpucfg(reg);
+ return __builtin_loongarch_cpucfg(reg);
}

#endif /* !__ASSEMBLY__ */
@@ -229,53 +228,53 @@ static inline u32 read_cpucfg(u32 reg)
/* CSR */
static __always_inline u32 csr_read32(u32 reg)
{
- return __csrrd_w(reg);
+ return __builtin_loongarch_csrrd(reg);
}

static __always_inline u64 csr_read64(u32 reg)
{
- return __csrrd_d(reg);
+ return __builtin_loongarch_csrrd(reg);
}

static __always_inline void csr_write32(u32 val, u32 reg)
{
- __csrwr_w(val, reg);
+ __builtin_loongarch_csrwr(val, reg);
}

static __always_inline void csr_write64(u64 val, u32 reg)
{
- __csrwr_d(val, reg);
+ __builtin_loongarch_csrwr(val, reg);
}

static __always_inline u32 csr_xchg32(u32 val, u32 mask, u32 reg)
{
- return __csrxchg_w(val, mask, reg);
+ return __builtin_loongarch_csrxchg(val, mask, reg);
}

static __always_inline u64 csr_xchg64(u64 val, u64 mask, u32 reg)
{
- return __csrxchg_d(val, mask, reg);
+ return __builtin_loongarch_csrxchg(val, mask, reg);
}

/* IOCSR */
static __always_inline u32 iocsr_read32(u32 reg)
{
- return __iocsrrd_w(reg);
+ return __builtin_loongarch_iocsrrd_w(reg);
}

static __always_inline u64 iocsr_read64(u32 reg)
{
- return __iocsrrd_d(reg);
+ return __builtin_loongarch_iocsrrd_d(reg);
}

static __always_inline void iocsr_write32(u32 val, u32 reg)
{
- __iocsrwr_w(val, reg);
+ __builtin_loongarch_iocsrwr_w(val, reg);
}

static __always_inline void iocsr_write64(u64 val, u32 reg)
{
- __iocsrwr_d(val, reg);
+ __builtin_loongarch_iocsrwr_d(val, reg);
}

#endif /* !__ASSEMBLY__ */
--
2.34.1


2022-08-31 07:14:01

by Xi Ruoyao

[permalink] [raw]
Subject: Re: [PATCH 1/1] LoongArch: Fixed loongarch kernel csr_xxx implicit declaration.

On Wed, 2022-08-31 at 14:14 +0800, Yupeng Li wrote:
> Loongarch CSR register operation related interface, use the
> interface defined  __builtin_loongarch_xxx instead.
> Build kernel error messages like:

It's likely because you are using a draft version of LoongArch GCC port.
Wrapper functions like __csrrd_w has been there in larchintrin.h since
the first day GCC port was merged upstream
(https://gcc.gnu.org/r12-7881).

A quick search shows IA64 and PowerPC also use GCC ia64intrin.h and
spu_intrinsics.h, so the use of these wrappers are not forbidden in
kernel source.

Unless there is some new good reason for the change,

Nacked-by: Xi Ruoyao <[email protected]>

>
>   CALL    scripts/atomic/check-atomics.sh
>   CC      arch/loongarch/kernel/asm-offsets.s
> In file included from ./arch/loongarch/include/asm/cpu-info.h:11,
>                  from ./arch/loongarch/include/asm/processor.h:13,
>                  from ./arch/loongarch/include/asm/thread_info.h:15,
>                  from ./include/linux/thread_info.h:60,
>                  from ./include/asm-generic/current.h:5,
>                  from
> ./arch/loongarch/include/generated/asm/current.h:1,
>                  from ./include/linux/sched.h:12,
>                  from arch/loongarch/kernel/asm-offsets.c:8:
> ./arch/loongarch/include/asm/loongarch.h: In function 'csr_read32':
> ./arch/loongarch/include/asm/loongarch.h:232:9: error: implicit
> declaration of function '__csrrd_w'; did you mean '__iocsrrd_w'? [-
> Werror=implicit-function-declaration]
>   return __csrrd_w(reg);
>          ^~~~~~~~~
>          __iocsrrd_w

--
Xi Ruoyao <[email protected]>
School of Aerospace Science and Technology, Xidian University

2022-08-31 11:51:32

by Xi Ruoyao

[permalink] [raw]
Subject: Re: [PATCH 1/1] LoongArch: Fixed loongarch kernel csr_xxx implicit declaration.

On Wed, 2022-08-31 at 15:54 +0800, 李宇鹏 wrote:
>
> thank you for your reply。
> I used the latest gcc tool on the official website of loongson,gcc-
> 8.3.0.
> http://www.loongnix.cn/zh/toolchain/GNU/

Vanilla kernel cannot work with Loongnix:

1. In Loongnix, GRUB loads pass the essential information to the kernel
following "Loongson Firmware-Kernel Interface Specification". Vanilla
kernel does not support it and will never support it.
2. In Loongnix, the syscall numbers are different and the layout of some
data structures used in kernel UAPI is different. Any Loongnix
application invoking a syscall will likely blow up immediately on a
vanilla kernel.

These two problems are very difficult. There is some plan to insert
compatibility layers to work around them, but not even one line of code
has been written AFAIK.

So if you want to build a kernel for Loongnix, don't use the vanilla
kernel. If you just want to build a vanilla kernel with a pre-built
cross toolchain, use the toolchain from
https://kernel.org/pub/tools/crosstool/.
--
Xi Ruoyao <[email protected]>
School of Aerospace Science and Technology, Xidian University

2022-08-31 15:41:46

by kernel test robot

[permalink] [raw]
Subject: Re: [PATCH 1/1] LoongArch: Fixed loongarch kernel csr_xxx implicit declaration.

Hi Yupeng,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on linus/master]
[also build test ERROR on v6.0-rc3 next-20220831]
[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/Yupeng-Li/LoongArch-Fixed-loongarch-kernel-csr_xxx-implicit-declaration/20220831-141510
base: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git dcf8e5633e2e69ad60b730ab5905608b756a032f
config: loongarch-randconfig-r031-20220830
compiler: loongarch64-linux-gcc (GCC) 12.1.0
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# https://github.com/intel-lab-lkp/linux/commit/48fc76b573f0f7284876a1df20eb70642b09920e
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review Yupeng-Li/LoongArch-Fixed-loongarch-kernel-csr_xxx-implicit-declaration/20220831-141510
git checkout 48fc76b573f0f7284876a1df20eb70642b09920e
# save the config file
mkdir build_dir && cp config build_dir/.config
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross W=1 O=build_dir ARCH=loongarch prepare

If you fix the issue, kindly add following tag where applicable
Reported-by: kernel test robot <[email protected]>

All errors (new ones prefixed by >>):

In file included from arch/loongarch/include/asm/cpu-info.h:11,
from arch/loongarch/include/asm/processor.h:13,
from arch/loongarch/include/asm/thread_info.h:15,
from include/linux/thread_info.h:60,
from include/asm-generic/current.h:5,
from ./arch/loongarch/include/generated/asm/current.h:1,
from include/linux/sched.h:12,
from arch/loongarch/kernel/asm-offsets.c:8:
arch/loongarch/include/asm/loongarch.h: In function 'csr_read32':
>> arch/loongarch/include/asm/loongarch.h:231:16: error: implicit declaration of function '__builtin_loongarch_csrrd'; did you mean '__builtin_loongarch_csrrd_w'? [-Werror=implicit-function-declaration]
231 | return __builtin_loongarch_csrrd(reg);
| ^~~~~~~~~~~~~~~~~~~~~~~~~
| __builtin_loongarch_csrrd_w
arch/loongarch/include/asm/loongarch.h: In function 'csr_write32':
>> arch/loongarch/include/asm/loongarch.h:241:9: error: implicit declaration of function '__builtin_loongarch_csrwr'; did you mean '__builtin_loongarch_csrwr_w'? [-Werror=implicit-function-declaration]
241 | __builtin_loongarch_csrwr(val, reg);
| ^~~~~~~~~~~~~~~~~~~~~~~~~
| __builtin_loongarch_csrwr_w
arch/loongarch/include/asm/loongarch.h: In function 'csr_xchg32':
>> arch/loongarch/include/asm/loongarch.h:251:16: error: implicit declaration of function '__builtin_loongarch_csrxchg'; did you mean '__builtin_loongarch_csrxchg_w'? [-Werror=implicit-function-declaration]
251 | return __builtin_loongarch_csrxchg(val, mask, reg);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~
| __builtin_loongarch_csrxchg_w
arch/loongarch/kernel/asm-offsets.c: At top level:
arch/loongarch/kernel/asm-offsets.c:16:6: warning: no previous prototype for 'output_ptreg_defines' [-Wmissing-prototypes]
16 | void output_ptreg_defines(void)
| ^~~~~~~~~~~~~~~~~~~~
arch/loongarch/kernel/asm-offsets.c:63:6: warning: no previous prototype for 'output_task_defines' [-Wmissing-prototypes]
63 | void output_task_defines(void)
| ^~~~~~~~~~~~~~~~~~~
arch/loongarch/kernel/asm-offsets.c:75:6: warning: no previous prototype for 'output_thread_info_defines' [-Wmissing-prototypes]
75 | void output_thread_info_defines(void)
| ^~~~~~~~~~~~~~~~~~~~~~~~~~
arch/loongarch/kernel/asm-offsets.c:91:6: warning: no previous prototype for 'output_thread_defines' [-Wmissing-prototypes]
91 | void output_thread_defines(void)
| ^~~~~~~~~~~~~~~~~~~~~
arch/loongarch/kernel/asm-offsets.c:134:6: warning: no previous prototype for 'output_thread_fpu_defines' [-Wmissing-prototypes]
134 | void output_thread_fpu_defines(void)
| ^~~~~~~~~~~~~~~~~~~~~~~~~
arch/loongarch/kernel/asm-offsets.c:174:6: warning: no previous prototype for 'output_mm_defines' [-Wmissing-prototypes]
174 | void output_mm_defines(void)
| ^~~~~~~~~~~~~~~~~
arch/loongarch/kernel/asm-offsets.c:206:6: warning: no previous prototype for 'output_sc_defines' [-Wmissing-prototypes]
206 | void output_sc_defines(void)
| ^~~~~~~~~~~~~~~~~
arch/loongarch/kernel/asm-offsets.c:214:6: warning: no previous prototype for 'output_signal_defines' [-Wmissing-prototypes]
214 | void output_signal_defines(void)
| ^~~~~~~~~~~~~~~~~~~~~
arch/loongarch/kernel/asm-offsets.c:252:6: warning: no previous prototype for 'output_smpboot_defines' [-Wmissing-prototypes]
252 | void output_smpboot_defines(void)
| ^~~~~~~~~~~~~~~~~~~~~~
cc1: some warnings being treated as errors
make[2]: *** [scripts/Makefile.build:117: arch/loongarch/kernel/asm-offsets.s] Error 1
make[2]: Target '__build' not remade because of errors.
make[1]: *** [Makefile:1205: prepare0] Error 2
make[1]: Target 'prepare' not remade because of errors.
make: *** [Makefile:222: __sub-make] Error 2
make: Target 'prepare' not remade because of errors.


vim +231 arch/loongarch/include/asm/loongarch.h

227
228 /* CSR */
229 static __always_inline u32 csr_read32(u32 reg)
230 {
> 231 return __builtin_loongarch_csrrd(reg);
232 }
233
234 static __always_inline u64 csr_read64(u32 reg)
235 {
236 return __builtin_loongarch_csrrd(reg);
237 }
238
239 static __always_inline void csr_write32(u32 val, u32 reg)
240 {
> 241 __builtin_loongarch_csrwr(val, reg);
242 }
243
244 static __always_inline void csr_write64(u64 val, u32 reg)
245 {
246 __builtin_loongarch_csrwr(val, reg);
247 }
248
249 static __always_inline u32 csr_xchg32(u32 val, u32 mask, u32 reg)
250 {
> 251 return __builtin_loongarch_csrxchg(val, mask, reg);
252 }
253

--
0-DAY CI Kernel Test Service
https://01.org/lkp


Attachments:
(No filename) (6.55 kB)
config (174.69 kB)
Download all attachments