All the mail mirrored from lore.kernel.org
 help / color / mirror / Atom feed
From: bibo mao <maobibo@loongson.cn>
To: Huacai Chen <chenhuacai@kernel.org>,
	Tianrui Zhao <zhaotianrui@loongson.cn>
Cc: linux-kernel@vger.kernel.org, kvm@vger.kernel.org,
	Paolo Bonzini <pbonzini@redhat.com>,
	WANG Xuerui <kernel@xen0n.name>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	loongarch@lists.linux.dev, 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>
Subject: Re: [PATCH v20 16/30] LoongArch: KVM: Implement update VM id function
Date: Mon, 11 Sep 2023 18:23:50 +0800	[thread overview]
Message-ID: <7379be58-30a5-1f0f-2e13-ca51b7cff096@loongson.cn> (raw)
In-Reply-To: <CAAhV-H497R=B3KaO8Z5ig2Nwst10dm63eiPnDpfNbFCxG4uVKg@mail.gmail.com>



在 2023/9/11 18:00, Huacai Chen 写道:
> Hi, Tianrui,
> 
> On Thu, Aug 31, 2023 at 4:30 PM Tianrui Zhao <zhaotianrui@loongson.cn> wrote:
>>
>> Implement kvm check vmid and update vmid, the vmid should be checked before
>> vcpu enter guest.
>>
>> Reviewed-by: Bibo Mao <maobibo@loongson.cn>
>> Signed-off-by: Tianrui Zhao <zhaotianrui@loongson.cn>
>> ---
>>  arch/loongarch/kvm/vmid.c | 66 +++++++++++++++++++++++++++++++++++++++
>>  1 file changed, 66 insertions(+)
>>  create mode 100644 arch/loongarch/kvm/vmid.c
>>
>> diff --git a/arch/loongarch/kvm/vmid.c b/arch/loongarch/kvm/vmid.c
>> new file mode 100644
>> index 0000000000..fc25ddc3b7
>> --- /dev/null
>> +++ b/arch/loongarch/kvm/vmid.c
>> @@ -0,0 +1,66 @@
>> +// SPDX-License-Identifier: GPL-2.0
>> +/*
>> + * Copyright (C) 2020-2023 Loongson Technology Corporation Limited
>> + */
>> +
>> +#include <linux/kvm_host.h>
>> +#include "trace.h"
>> +
>> +static void _kvm_update_vpid(struct kvm_vcpu *vcpu, int cpu)
>> +{
>> +       struct kvm_context *context;
>> +       unsigned long vpid;
>> +
>> +       context = per_cpu_ptr(vcpu->kvm->arch.vmcs, cpu);
>> +       vpid = context->vpid_cache + 1;
>> +       if (!(vpid & vpid_mask)) {
>> +               /* finish round of 64 bit loop */
>> +               if (unlikely(!vpid))
>> +                       vpid = vpid_mask + 1;
>> +
>> +               /* vpid 0 reserved for root */
>> +               ++vpid;
>> +
>> +               /* start new vpid cycle */
>> +               kvm_flush_tlb_all();
>> +       }
>> +
>> +       context->vpid_cache = vpid;
>> +       vcpu->arch.vpid = vpid;
>> +}
>> +
>> +void _kvm_check_vmid(struct kvm_vcpu *vcpu)
>> +{
>> +       struct kvm_context *context;
>> +       bool migrated;
>> +       unsigned long ver, old, vpid;
>> +       int cpu;
>> +
>> +       cpu = smp_processor_id();
>> +       /*
>> +        * Are we entering guest context on a different CPU to last time?
>> +        * If so, the vCPU's guest TLB state on this CPU may be stale.
>> +        */
>> +       context = per_cpu_ptr(vcpu->kvm->arch.vmcs, cpu);
>> +       migrated = (vcpu->cpu != cpu);
>> +
>> +       /*
>> +        * Check if our vpid is of an older version
>> +        *
>> +        * We also discard the stored vpid if we've executed on
>> +        * another CPU, as the guest mappings may have changed without
>> +        * hypervisor knowledge.
>> +        */
>> +       ver = vcpu->arch.vpid & ~vpid_mask;
>> +       old = context->vpid_cache  & ~vpid_mask;
>> +       if (migrated || (ver != old)) {
>> +               _kvm_update_vpid(vcpu, cpu);
>> +               trace_kvm_vpid_change(vcpu, vcpu->arch.vpid);
>> +               vcpu->cpu = cpu;
>> +       }
>> +
>> +       /* Restore GSTAT(0x50).vpid */
>> +       vpid = (vcpu->arch.vpid & vpid_mask)
>> +               << CSR_GSTAT_GID_SHIFT;
>> +       change_csr_gstat(vpid_mask << CSR_GSTAT_GID_SHIFT, vpid);
>> +}
> I believe that vpid and vmid are both GID in the gstat register, so
> please unify their names. And I think vpid is better than vmid.

For processor 3A5000 vpid is the same with vmid, with next generation processor
like 3A6000, it is seperated. vpid is for vcpu specific and represents
translation from gva to gpa; vmid is the whole vm and represents translation
from gpa to hpa, all vcpus shares the same vmid, so that tlb indexed with vpid
will be still in effective when flushing shadow tlbs indexed with vmid.

Only that VM patch for 3A6000 is not submitted now, generation method for
vpid and vmid will be much different. It is prepared for future processor
update :)

Regards
Bibo Mao

> 
> Moreover, no need to create a vmid.c file, just putting them in main.c is OK.
> 
> Huacai
> 
>> --
>> 2.27.0
>>


  reply	other threads:[~2023-09-11 22:24 UTC|newest]

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

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=7379be58-30a5-1f0f-2e13-ca51b7cff096@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.