From: Bibo Mao <maobibo@loongson.cn>
To: Huacai Chen <chenhuacai@kernel.org>
Cc: Sean Christopherson <seanjc@google.com>,
Paolo Bonzini <pbonzini@redhat.com>,
WANG Xuerui <kernel@xen0n.name>, Arnd Bergmann <arnd@arndb.de>,
Xi Ruoyao <xry111@xry111.site>,
kvm@vger.kernel.org, loongarch@lists.linux.dev,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH 4/6] LoongArch: KVM: implement vmid updating logic
Date: Mon, 3 Aug 2026 09:23:53 +0800 [thread overview]
Message-ID: <b4689c17-e900-468b-eb08-6fb199c14a63@loongson.cn> (raw)
In-Reply-To: <CAAhV-H5uF_hzKGZZbXzj5t6TFPefDVn09F0VM-AuNiDjoJZzCQ@mail.gmail.com>
On 2026/8/2 下午10:13, Huacai Chen wrote:
> Hi, BIbo,
>
> On Mon, Jul 27, 2026 at 3:30 PM Bibo Mao <maobibo@loongson.cn> wrote:
>>
>> For every physical CPU, there is one vmid calculation method. For
>> vCPUs on the same VM, vmid is the same. However for vCPUs on
>> different VM, vmid is different. When vCPU is scheduled on the
>> physical CPU, it checked vmid of this VM and the global cached
>> vmid, and judge whether it is valid or not.
> I think Patch#2/3/4 can be folded into one.
will merge patch 2/3/4 together.
Regards
Bibo Mao
>
>
> Huacai
>
>>
>> Signed-off-by: Bibo Mao <maobibo@loongson.cn>
>> ---
>> arch/loongarch/include/asm/kvm_host.h | 2 ++
>> arch/loongarch/kvm/main.c | 42 ++++++++++++++++++++++++++-
>> 2 files changed, 43 insertions(+), 1 deletion(-)
>>
>> diff --git a/arch/loongarch/include/asm/kvm_host.h b/arch/loongarch/include/asm/kvm_host.h
>> index e93307cbe740..a01623c42c7a 100644
>> --- a/arch/loongarch/include/asm/kvm_host.h
>> +++ b/arch/loongarch/include/asm/kvm_host.h
>> @@ -79,6 +79,7 @@ struct kvm_arch_memory_slot {
>> #define HOST_MAX_PMNUM 16
>> struct kvm_context {
>> unsigned long vpid_cache;
>> + unsigned long vmid_cache;
>> struct kvm_vcpu *last_vcpu;
>> /* Host PMU CSR */
>> u64 perf_ctrl[HOST_MAX_PMNUM];
>> @@ -132,6 +133,7 @@ struct kvm_arch {
>> unsigned long kvm_features;
>>
>> s64 time_offset;
>> + unsigned long vmid[NR_CPUS];
>> struct kvm_context __percpu *vmcs;
>> struct loongarch_ipi *ipi;
>> struct loongarch_dmsintc *dmsintc;
>> diff --git a/arch/loongarch/kvm/main.c b/arch/loongarch/kvm/main.c
>> index 3df46e02594f..7b3661da8958 100644
>> --- a/arch/loongarch/kvm/main.c
>> +++ b/arch/loongarch/kvm/main.c
>> @@ -281,9 +281,33 @@ static void kvm_check_vcpuid(struct kvm_vcpu *vcpu)
>> }
>> }
>>
>> -static void kvm_check_vmid(struct kvm_vcpu *vcpu)
>> +static void kvm_update_vmid(struct kvm_vcpu *vcpu, int cpu)
>> {
>> unsigned long vmid;
>> + struct kvm_context *context;
>> +
>> + context = per_cpu_ptr(vcpu->kvm->arch.vmcs, cpu);
>> + vmid = context->vmid_cache + 1;
>> + if (!(vmid & vpid_mask)) {
>> + /* finish round of vmid loop */
>> + if (unlikely(!vmid))
>> + vmid = vpid_mask + 1;
>> +
>> + ++vmid; /* vmid 0 reserved for root */
>> +
>> + /* start new vmid cycle */
>> + kvm_flush_tlb_all_stage2();
>> + }
>> +
>> + context->vmid_cache = vmid;
>> + vcpu->kvm->arch.vmid[cpu] = vmid;
>> +}
>> +
>> +static void kvm_check_vmid(struct kvm_vcpu *vcpu)
>> +{
>> + int cpu;
>> + unsigned long ver, old, vmid;
>> + struct kvm_context *context;
>>
>> /* On some machines like 3A5000, vmid needs the same with vpid */
>> if (!cpu_has_guestid) {
>> @@ -295,6 +319,21 @@ static void kvm_check_vmid(struct kvm_vcpu *vcpu)
>>
>> return;
>> }
>> +
>> + cpu = smp_processor_id();
>> + context = per_cpu_ptr(vcpu->kvm->arch.vmcs, cpu);
>> +
>> + /*
>> + * Check if our vmid is of an older version
>> + */
>> + ver = vcpu->kvm->arch.vmid[cpu] & ~vpid_mask;
>> + old = context->vmid_cache & ~vpid_mask;
>> + if (ver != old) {
>> + kvm_update_vmid(vcpu, cpu);
>> + kvm_clear_request(KVM_REQ_TLB_FLUSH_GPA, vcpu);
>> + }
>> +
>> + vcpu->arch.vmid = vcpu->kvm->arch.vmid[cpu] & vpid_mask;
>> }
>>
>> void kvm_check_vpid(struct kvm_vcpu *vcpu)
>> @@ -400,6 +439,7 @@ static int kvm_loongarch_env_init(void)
>> for_each_possible_cpu(cpu) {
>> context = per_cpu_ptr(vmcs, cpu);
>> context->vpid_cache = vpid_mask + 1;
>> + context->vmid_cache = vpid_mask + 1;
>> context->last_vcpu = NULL;
>> }
>>
>> --
>> 2.39.3
>>
next prev parent reply other threads:[~2026-08-03 1:24 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-27 7:21 [PATCH 0/6] LoongArch: KVM: Add separate vmid support Bibo Mao
2026-07-27 7:21 ` [PATCH 1/6] LoongArch: KVM: Add vmid support for stage2 MMU Bibo Mao
2026-08-02 14:11 ` Huacai Chen
2026-08-03 1:20 ` Bibo Mao
2026-08-04 14:14 ` Huacai Chen
2026-08-05 1:21 ` Bibo Mao
2026-08-05 1:27 ` Bibo Mao
2026-08-05 2:19 ` Bibo Mao
2026-07-27 7:21 ` [PATCH 2/6] LoongArch: KVM: Add separate vCPU and VM id update function Bibo Mao
2026-08-02 14:12 ` Huacai Chen
2026-08-03 1:22 ` Bibo Mao
2026-07-27 7:21 ` [PATCH 3/6] LoongArch: KVM: Add separate vmid feature support Bibo Mao
2026-07-27 7:21 ` [PATCH 4/6] LoongArch: KVM: implement vmid updating logic Bibo Mao
2026-08-02 14:13 ` Huacai Chen
2026-08-03 1:23 ` Bibo Mao [this message]
2026-07-27 7:21 ` [PATCH 5/6] LoongArch: KVM: Add remote tlb flushing support Bibo Mao
2026-07-27 7:21 ` [PATCH 6/6] LoongArch: KVM: Enable separate vmid feature Bibo Mao
2026-08-02 14:14 ` Huacai Chen
2026-08-03 1:26 ` Bibo Mao
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=b4689c17-e900-468b-eb08-6fb199c14a63@loongson.cn \
--to=maobibo@loongson.cn \
--cc=arnd@arndb.de \
--cc=chenhuacai@kernel.org \
--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=seanjc@google.com \
--cc=xry111@xry111.site \
/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®