[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <29a9c6b4-96b8-3fb5-9b7a-2f9dba97e06f@xen0n.name>
Date: Tue, 23 May 2023 18:27:19 +0800
From: WANG Xuerui <kernel@...0n.name>
To: maobibo <maobibo@...ngson.cn>, Paolo Bonzini <pbonzini@...hat.com>,
Huacai Chen <chenhuacai@...nel.org>
Cc: Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
loongarch@...ts.linux.dev, linux-kernel@...r.kernel.org,
kvm@...r.kernel.org, Jens Axboe <axboe@...nel.dk>,
Mark Brown <broonie@...nel.org>,
Alex Deucher <alexander.deucher@....com>,
Oliver Upton <oliver.upton@...ux.dev>,
Xi Ruoyao <xry111@...111.site>,
Tianrui Zhao <zhaotianrui@...ngson.cn>
Subject: Re: [PATCH v10 00/30] Add KVM LoongArch support
On 2023/5/23 10:54, maobibo wrote:
>
> [snip]
>
> I hate parse_r helper also, it is hard to understand, the kernel about
> LoongArch has the same issue. How about using a fixed register like this?
>
> /* GCSR */
> static __always_inline u64 gcsr_read(u32 reg)
> {
> u64 val = 0;
>
> BUILD_BUG_ON(!__builtin_constant_p(reg));
> /* Instructions will be available in binutils later */
> asm volatile (
> "parse_r __reg, %[val]\n\t"
Isn't this still parse_r-ing things? ;-)
> /*
> * read val from guest csr register %[reg]
> * gcsrrd %[val], %[reg]
> */
> ".word 0x5 << 24 | %[reg] << 10 | 0 << 5 | __reg\n\t"
> : [val] "+r" (val)
> : [reg] "i" (reg)
> : "memory");
>
> return val;
> }
>
> /* GCSR */
> static __always_inline u64 gcsr_read(u32 reg)
> {
> register unsigned long val asm("t0");
I got what you're trying to accomplish here. At which point you may just
refer to how glibc implements its inline syscall templates and hardcode
both the input and output arguments, then simply hard-code the whole
instruction word. If others don't have opinions about doing things this
way, I wouldn't either.
(CSR operations are not expected to become performance-sensitive in any
case, so you may freely choose registers here, and t0 for output seems
okay. I'd recommend stuffing "reg" to a temporary value bound to a0 though.)
>
> BUILD_BUG_ON(!__builtin_constant_p(reg));
> /* Instructions will be available in binutils later */
> asm volatile (
> "parse_r __reg, %[val]\n\t"
> /*
> * read val from guest csr register %[reg]
> * gcsrrd %[val], %[reg]
> */
> ".word 0x5 << 24 | %[reg] << 10 | 0 << 5 | 12 \n\t"
> : : [reg] "i" (reg)
> : "memory", "t0");
>
> return val;
> }
--
WANG "xen0n" Xuerui
Linux/LoongArch mailing list: https://lore.kernel.org/loongarch/
Powered by blists - more mailing lists