linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: maobibo <maobibo@loongson.cn>
To: WANG Xuerui <kernel@xen0n.name>,
	Jiaxun Yang <jiaxun.yang@flygoat.com>,
	Huacai Chen <chenhuacai@kernel.org>
Cc: Tianrui Zhao <zhaotianrui@loongson.cn>,
	Juergen Gross <jgross@suse.com>,
	Paolo Bonzini <pbonzini@redhat.com>,
	loongarch@lists.linux.dev, linux-kernel@vger.kernel.org,
	virtualization@lists.linux.dev, kvm@vger.kernel.org
Subject: Re: [PATCH v5 3/6] LoongArch: KVM: Add cpucfg area for kvm hypervisor
Date: Tue, 27 Feb 2024 18:12:15 +0800	[thread overview]
Message-ID: <62cc24fd-025a-53c6-1c8e-2d20de54d297@loongson.cn> (raw)
In-Reply-To: <327808dd-ac34-4c61-9992-38642acc9419@xen0n.name>



On 2024/2/27 下午5:10, WANG Xuerui wrote:
> On 2/27/24 11:14, maobibo wrote:
>>
>>
>> On 2024/2/27 上午4:02, Jiaxun Yang wrote:
>>>
>>>
>>> 在2024年2月26日二月 上午8:04,maobibo写道:
>>>> On 2024/2/26 下午2:12, Huacai Chen wrote:
>>>>> On Mon, Feb 26, 2024 at 10:04 AM maobibo <maobibo@loongson.cn> wrote:
>>>>>>
>>>>>>
>>>>>>
>>>>>> On 2024/2/24 下午5:13, Huacai Chen wrote:
>>>>>>> Hi, Bibo,
>>>>>>>
>>>>>>> On Thu, Feb 22, 2024 at 11:28 AM Bibo Mao <maobibo@loongson.cn> 
>>>>>>> wrote:
>>>>>>>>
>>>>>>>> Instruction cpucfg can be used to get processor features. And there
>>>>>>>> is trap exception when it is executed in VM mode, and also it is
>>>>>>>> to provide cpu features to VM. On real hardware cpucfg area 0 - 20
>>>>>>>> is used.  Here one specified area 0x40000000 -- 0x400000ff is used
>>>>>>>> for KVM hypervisor to privide PV features, and the area can be 
>>>>>>>> extended
>>>>>>>> for other hypervisors in future. This area will never be used for
>>>>>>>> real HW, it is only used by software.
>>>>>>> After reading and thinking, I find that the hypercall method 
>>>>>>> which is
>>>>>>> used in our productive kernel is better than this cpucfg method.
>>>>>>> Because hypercall is more simple and straightforward, plus we don't
>>>>>>> worry about conflicting with the real hardware.
>>>>>> No, I do not think so. cpucfg is simper than hypercall, hypercall can
>>>>>> be in effect when system runs in guest mode. In some scenario like 
>>>>>> TCG
>>>>>> mode, hypercall is illegal intruction, however cpucfg can work.
>>>>> Nearly all architectures use hypercall except x86 for its historical
>>>> Only x86 support multiple hypervisors and there is multiple hypervisor
>>>> in x86 only. It is an advantage, not historical reason.
>>>
>>> I do believe that all those stuff should not be exposed to guest user 
>>> space
>>> for security reasons.
>> Can you add PLV checking when cpucfg 0x40000000-0x400000FF is 
>> emulated? if it is user mode return value is zero and it is kernel 
>> mode emulated value will be returned. It can avoid information leaking.
> 
> I've suggested this approach in another reply [1], but I've rechecked 
> the manual, and it turns out this behavior is not permitted by the 
> current wording. See LoongArch Reference Manual v1.10, Volume 1, Section 
> 2.2.10.5 "CPUCFG":
> 
>  > CPUCFG 访问未定义的配置字将读回全 0 值。
>  >
>  > Reads of undefined CPUCFG configuration words shall return all-zeroes.
> 
> This sentence mentions no distinction based on privilege modes, so it 
> can only mean the behavior applies universally regardless of privilege 
> modes.
> 
> I think if you want to make CPUCFG behavior PLV-dependent, you may have 
> to ask the LoongArch spec editors, internally or in public, for a new 
> spec revision.
No, CPUCFG behavior between CPUCFG0-CPUCFG21 is unchanged, only that it 
can be defined by software since CPUCFG 0x400000000 is used by software. >
> (There are already multiple third-party LoongArch implementers as of 
> late 2023, so any ISA-level change like this would best be coordinated, 
> to minimize surprises.)
With document Vol 4-23
https://www.intel.com/content/dam/develop/external/us/en/documents/335592-sdm-vol-4.pdf

There is one line "MSR address range between 40000000H - 400000FFH is 
marked as a specially reserved range. All existing and
future processors will not implement any features using any MSR in this 
range."

It only says that it is reserved, it does not say detailed software 
behavior. Software behavior is defined in hypervisor such as:
https://github.com/MicrosoftDocs/Virtualization-Documentation/blob/main/tlfs/Requirements%20for%20Implementing%20the%20Microsoft%20Hypervisor%20Interface.pdf
https://kb.vmware.com/s/article/1009458

If hypercall method is used, there should be ABI also like aarch64:
https://documentation-service.arm.com/static/6013e5faeee5236980d08619

Regards
Bibo Mao

> 
> [1]: 
> https://lore.kernel.org/loongarch/d8994f0f-d789-46d2-bc4d-f9b37fb396ff@xen0n.name/ 
> 
> 


  reply	other threads:[~2024-02-27 10:12 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-22  3:27 [PATCH v5 0/6] LoongArch: Add pv ipi support on LoongArch VM Bibo Mao
2024-02-22  3:27 ` [PATCH v5 1/6] LoongArch/smp: Refine some ipi functions on LoongArch platform Bibo Mao
2024-02-22  3:27 ` [PATCH v5 2/6] LoongArch: KVM: Add hypercall instruction emulation support Bibo Mao
2024-02-22  3:28 ` [PATCH v5 3/6] LoongArch: KVM: Add cpucfg area for kvm hypervisor Bibo Mao
2024-02-24  9:13   ` Huacai Chen
2024-02-26  2:04     ` maobibo
2024-02-26  5:25       ` WANG Xuerui
2024-02-26  8:00         ` maobibo
2024-02-26  8:07           ` WANG Xuerui
2024-02-26  6:12       ` Huacai Chen
2024-02-26  8:04         ` maobibo
2024-02-26 20:02           ` Jiaxun Yang
2024-02-27  3:14             ` maobibo
2024-02-27  5:23               ` Jiaxun Yang
2024-02-27  7:09                 ` maobibo
2024-02-27  9:05                   ` Xi Ruoyao
2024-02-27  9:52                     ` maobibo
2024-02-27  9:10               ` WANG Xuerui
2024-02-27 10:12                 ` maobibo [this message]
2024-02-27 10:19                   ` WANG Xuerui
2024-02-27 14:57                     ` Huacai Chen
2024-03-02  2:57                     ` maobibo
2024-02-26  2:07     ` maobibo
2024-02-22  3:28 ` [PATCH v5 4/6] LoongArch: Add paravirt interface for guest kernel Bibo Mao
2024-02-24  9:15   ` Huacai Chen
2024-02-26  2:27     ` maobibo
2024-02-22  3:28 ` [PATCH v5 5/6] LoongArch: KVM: Add vcpu search support from physical cpuid Bibo Mao
2024-02-22  3:28 ` [PATCH v5 6/6] LoongArch: Add pv ipi support on LoongArch system Bibo Mao
2024-02-24  9:19   ` Huacai Chen
2024-02-26  2:30     ` 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=62cc24fd-025a-53c6-1c8e-2d20de54d297@loongson.cn \
    --to=maobibo@loongson.cn \
    --cc=chenhuacai@kernel.org \
    --cc=jgross@suse.com \
    --cc=jiaxun.yang@flygoat.com \
    --cc=kernel@xen0n.name \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=loongarch@lists.linux.dev \
    --cc=pbonzini@redhat.com \
    --cc=virtualization@lists.linux.dev \
    --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;
as well as URLs for NNTP newsgroup(s).