Re: [PATCH v6 29/30] LoongArch: KVM: Enable kvm config and add the makefile

From: Tianrui Zhao
Date: Thu Apr 13 2023 - 07:52:57 EST




在 2023年04月13日 16:33, Xi Ruoyao 写道:
On Thu, 2023-04-13 at 15:32 +0800, kernel test robot wrote:

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

f2ac457a61389b Huacai Chen 2022-05-31 238
2c87b678639d25 Tianrui Zhao 2023-04-12 239 /* GCSR */
2c87b678639d25 Tianrui Zhao 2023-04-12 240 static inline u64 gcsr_read(u32 reg)
Try __always_inline instead of inline because this "function" will
definitely break up if it's not inlined.

And I guess we should have something like:

extern u64 __compiletime_error("gcsr_read parameter is not a constant")
__gcsr_read_non_const(void);

static __always_inline u64 gcsr_read(u32 reg)
{
u64 val = 0;

if (!__builtin_constant_p(reg))
return __gcsr_read_non_const();

asm volatile (
... ...

Or perhaps we should just rewrite gcsr_read to a macro.

2c87b678639d25 Tianrui Zhao 2023-04-12 241 {
2c87b678639d25 Tianrui Zhao 2023-04-12 242 u64 val = 0;
2c87b678639d25 Tianrui Zhao 2023-04-12 243 /* Instructions will be available in binutils later */
2c87b678639d25 Tianrui Zhao 2023-04-12 @244 asm volatile (
2c87b678639d25 Tianrui Zhao 2023-04-12 245 "parse_r __reg, %[val]\n\t"
2c87b678639d25 Tianrui Zhao 2023-04-12 246 /*
2c87b678639d25 Tianrui Zhao 2023-04-12 247 * read val from guest csr register %[reg]
2c87b678639d25 Tianrui Zhao 2023-04-12 248 * gcsrrd %[val], %[reg]
2c87b678639d25 Tianrui Zhao 2023-04-12 249 */
2c87b678639d25 Tianrui Zhao 2023-04-12 250 ".word 0x5 << 24 | %[reg] << 10 | 0 << 5 | __reg\n\t"
2c87b678639d25 Tianrui Zhao 2023-04-12 251 : [val] "+r" (val)
2c87b678639d25 Tianrui Zhao 2023-04-12 252 : [reg] "i" (reg)
2c87b678639d25 Tianrui Zhao 2023-04-12 253 : "memory");
2c87b678639d25 Tianrui Zhao 2023-04-12 254
2c87b678639d25 Tianrui Zhao 2023-04-12 255 return val;
2c87b678639d25 Tianrui Zhao 2023-04-12 256 }
2c87b678639d25 Tianrui Zhao 2023-04-12 257

Thanks, it really should use __always_inline there, and I will reconsider to fix this function mistakes about compiling.

Thanks
Tianrui Zhao