mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: maobibo <maobibo@loongson.cn>
To: WANG Xuerui <kernel@xen0n.name>,
	Paolo Bonzini <pbonzini@redhat.com>,
	Huacai Chen <chenhuacai@kernel.org>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	loongarch@lists.linux.dev, linux-kernel@vger.kernel.org,
	kvm@vger.kernel.org, Jens Axboe <axboe@kernel.dk>,
	Mark Brown <broonie@kernel.org>,
	Alex Deucher <alexander.deucher@amd.com>,
	Oliver Upton <oliver.upton@linux.dev>,
	Xi Ruoyao <xry111@xry111.site>,
	Tianrui Zhao <zhaotianrui@loongson.cn>
Subject: Re: [PATCH v10 00/30] Add KVM LoongArch support
Date: Tue, 23 May 2023 19:57:20 +0800	[thread overview]
Message-ID: <94b7f3d6-e2e1-be0a-cd39-dd1b1f1f607e@loongson.cn> (raw)
In-Reply-To: <29a9c6b4-96b8-3fb5-9b7a-2f9dba97e06f@xen0n.name>



在 2023/5/23 18:27, WANG Xuerui 写道:
> 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.)
a0 is ok for me.

riscv has better method than both parse_r helper and using tmp register
as follows, maybe we can use the similiar method. 

        .macro insn_r, opcode, func3, func7, rd, rs1, rs2
        .4byte  ((\opcode << INSN_R_OPCODE_SHIFT) |             \
                 (\func3 << INSN_R_FUNC3_SHIFT) |               \
                 (\func7 << INSN_R_FUNC7_SHIFT) |               \
                 (.L__gpr_num_\rd << INSN_R_RD_SHIFT) |         \
                 (.L__gpr_num_\rs1 << INSN_R_RS1_SHIFT) |       \
                 (.L__gpr_num_\rs2 << INSN_R_RS2_SHIFT))
        .endm

#define HINVAL_VVMA(vaddr, asid)                                \
        INSN_R(OPCODE_SYSTEM, FUNC3(0), FUNC7(19),              \
               __RD(0), RS1(vaddr), RS2(asid))

asm volatile(HINVAL_VVMA(%0, %1)
                        : : "r" (pos), "r" (asid) : "memory");

Regards
Bibo, Mao
> 
>>
>>          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;
>> }
> 


      reply	other threads:[~2023-05-23 11:57 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-15  2:14 Tianrui Zhao
2023-05-15  2:14 ` [PATCH v10 01/30] LoongArch: KVM: Add kvm related header files Tianrui Zhao
2023-05-15  2:14 ` [PATCH v10 02/30] LoongArch: KVM: Implement kvm module related interface Tianrui Zhao
2023-05-15  2:14 ` [PATCH v10 03/30] LoongArch: KVM: Implement kvm hardware enable, disable interface Tianrui Zhao
2023-05-15  2:14 ` [PATCH v10 04/30] LoongArch: KVM: Implement VM related functions Tianrui Zhao
2023-05-15  2:14 ` [PATCH v10 05/30] LoongArch: KVM: Add vcpu related header files Tianrui Zhao
2023-05-15  2:14 ` [PATCH v10 06/30] LoongArch: KVM: Implement vcpu create and destroy interface Tianrui Zhao
2023-05-15  2:14 ` [PATCH v10 07/30] LoongArch: KVM: Implement vcpu run interface Tianrui Zhao
2023-05-15  2:15 ` [PATCH v10 08/30] LoongArch: KVM: Implement vcpu handle exit interface Tianrui Zhao
2023-05-15  2:15 ` [PATCH v10 09/30] LoongArch: KVM: Implement vcpu get, vcpu set registers Tianrui Zhao
2023-05-15  2:15 ` [PATCH v10 10/30] LoongArch: KVM: Implement vcpu ENABLE_CAP ioctl interface Tianrui Zhao
2023-05-15  2:15 ` [PATCH v10 11/30] LoongArch: KVM: Implement fpu related operations for vcpu Tianrui Zhao
2023-05-15  2:15 ` [PATCH v10 12/30] LoongArch: KVM: Implement vcpu interrupt operations Tianrui Zhao
2023-05-15  2:15 ` [PATCH v10 13/30] LoongArch: KVM: Implement misc vcpu related interfaces Tianrui Zhao
2023-05-15  2:15 ` [PATCH v10 14/30] LoongArch: KVM: Implement vcpu load and vcpu put operations Tianrui Zhao
2023-05-15  2:15 ` [PATCH v10 15/30] LoongArch: KVM: Implement vcpu status description Tianrui Zhao
2023-05-15  2:15 ` [PATCH v10 16/30] LoongArch: KVM: Implement update VM id function Tianrui Zhao
2023-05-15  2:15 ` [PATCH v10 17/30] LoongArch: KVM: Implement virtual machine tlb operations Tianrui Zhao
2023-05-15  2:15 ` [PATCH v10 18/30] LoongArch: KVM: Implement vcpu timer operations Tianrui Zhao
2023-05-15  2:15 ` [PATCH v10 19/30] LoongArch: KVM: Implement kvm mmu operations Tianrui Zhao
2023-05-15  2:15 ` [PATCH v10 20/30] LoongArch: KVM: Implement handle csr excption Tianrui Zhao
2023-05-15  2:15 ` [PATCH v10 21/30] LoongArch: KVM: Implement handle iocsr exception Tianrui Zhao
2023-05-15  2:15 ` [PATCH v10 22/30] LoongArch: KVM: Implement handle idle exception Tianrui Zhao
2023-05-15  2:15 ` [PATCH v10 23/30] LoongArch: KVM: Implement handle gspr exception Tianrui Zhao
2023-05-15  2:15 ` [PATCH v10 24/30] LoongArch: KVM: Implement handle mmio exception Tianrui Zhao
2023-05-15  2:15 ` [PATCH v10 25/30] LoongArch: KVM: Implement handle fpu exception Tianrui Zhao
2023-05-15  2:15 ` [PATCH v10 26/30] LoongArch: KVM: Implement kvm exception vector Tianrui Zhao
2023-05-15  2:15 ` [PATCH v10 27/30] LoongArch: KVM: Implement vcpu world switch Tianrui Zhao
2023-05-15  2:15 ` [PATCH v10 28/30] LoongArch: KVM: Implement probe virtualization when LoongArch cpu init Tianrui Zhao
2023-05-15  2:15 ` [PATCH v10 29/30] LoongArch: KVM: Enable kvm config and add the makefile Tianrui Zhao
2023-05-15  2:15 ` [PATCH v10 30/30] LoongArch: KVM: Supplement kvm document about LoongArch-specific part Tianrui Zhao
2023-05-18  2:56 ` [PATCH v10 00/30] Add KVM LoongArch support maobibo
2023-05-21 10:22   ` WANG Xuerui
2023-05-21 11:17     ` Xi Ruoyao
2023-05-22  1:39     ` maobibo
2023-05-22  2:37       ` WANG Xuerui
2023-05-22  6:17         ` Xi Ruoyao
2023-05-23  2:54         ` maobibo
2023-05-23 10:27           ` WANG Xuerui
2023-05-23 11:57             ` maobibo [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=94b7f3d6-e2e1-be0a-cd39-dd1b1f1f607e@loongson.cn \
    --to=maobibo@loongson.cn \
    --cc=alexander.deucher@amd.com \
    --cc=axboe@kernel.dk \
    --cc=broonie@kernel.org \
    --cc=chenhuacai@kernel.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=kernel@xen0n.name \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=loongarch@lists.linux.dev \
    --cc=oliver.upton@linux.dev \
    --cc=pbonzini@redhat.com \
    --cc=xry111@xry111.site \
    --cc=zhaotianrui@loongson.cn \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®