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 10:54:23 +0800	[thread overview]
Message-ID: <1218d3f9-4955-7176-afbd-a0dfa0bd7565@loongson.cn> (raw)
In-Reply-To: <90b2fc60-af26-4ba6-f775-7db2514a62f4@xen0n.name>



在 2023/5/22 10:37, WANG Xuerui 写道:
> On 2023/5/22 09:39, maobibo wrote:
>>
>>
>> 在 2023/5/21 18:22, WANG Xuerui 写道:
>>> On 2023/5/18 10:56, maobibo wrote:
>>>> <snip>
>>> (BTW, how do people usually deal with pre-release hardware wit documentation not out yet? I suppose similar situations like this should turn up fairly often.)
>> Manual is actually one issue, however it does not prevent the review
>> process. There are some drivers for *fruit* devices, I can not find
>> the hw manual also.  With the manual, it helps to review and points
>> out the further and detailed issues.
> 
> There's a *slight* difference: the certain vendor you've mentioned is historically uncooperative in providing the documentation, so outside contributors had to reverse-engineer and document the HW themselves; but in Loongson's case, you *are* the vendor, so you are probably in a position that can make everyone's life easier by at least pushing for the docs release...
> 
>>>
>>> Aside from this, there's another point: use of undocumented instructions in raw form with ".word". This currently doesn't work in LLVM/Clang <snip>
>> As for one new architecture, it is normal to use .word or .insn, instruction
>> will update for the first few years and also compiler may be not supported
>> timely. The other arch has the same phenomenon if you grep "\.insn", also
>> llvm on LoongArch supports ".word" directives.
>>
>> After three or five years, we will remove these ".insn" macro when hw and
>> compiler is matured.
> 
> Sorry for the confusion at my side; `.word` certainly works, what doesn't work currently seems to be the `parse_r` helper. I know because I've tried in the last week with latest LLVM/Clang snapshot. And you can't write ergonomic inline asm with proper register allocator awareness without the helper; the LoongArch assembler isn't capable of assembling in a certain encoding format. With RISC-V `.insn` you can do things like `.insn r 0xNN, 0, 0, a0, a1, a2`, but you cannot simply e.g. express gcsrxchg with `.insn DJK 0x05000000, a0, a1, a2` because no such instruction format convention has been standardized. (The notation demonstrated here is taken from [1].)

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"
		/*
		 * 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");

        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;
} 

Regards
Bibo, Mao
> 
> In any case, it seems best to at least wait for the documentation release a little bit, or you should state clearly that this is not going to happen soon, so people can properly manage their expectation and prioritize. (For example, if I know docs and/or assembler support for the virtualization extension won't come soon, then I'd work on supporting the .word idiom before other things. Otherwise there are more important things than that.)
> 
> [1]: https://github.com/loongson/LoongArch-Documentation/pull/56
> 


  parent reply	other threads:[~2023-05-23  2:54 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 [this message]
2023-05-23 10:27           ` WANG Xuerui
2023-05-23 11:57             ` maobibo

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=1218d3f9-4955-7176-afbd-a0dfa0bd7565@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®