From: Tianrui Zhao <zhaotianrui@loongson.cn>
To: Huacai Chen <chenhuacai@kernel.org>
Cc: Paolo Bonzini <pbonzini@redhat.com>,
WANG Xuerui <kernel@xen0n.name>,
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>,
maobibo@loongson.cn, Xi Ruoyao <xry111@xry111.site>
Subject: Re: [PATCH v7 16/30] LoongArch: KVM: Implement update VM id function
Date: Wed, 19 Apr 2023 16:53:38 +0800 [thread overview]
Message-ID: <d2dbcf54-4015-81ec-6b96-47cdcc22cd13@loongson.cn> (raw)
In-Reply-To: <CAAhV-H4pyBi=0ckNDLErz6G_b5G7ti2wVDXF3a7xv-MiJtF_tA@mail.gmail.com>
在 2023年04月19日 10:01, Huacai Chen 写道:
> Hi, Tianrui,
>
> On Mon, Apr 17, 2023 at 5:47 PM Tianrui Zhao <zhaotianrui@loongson.cn> wrote:
>> Implement kvm check vmid and update vmid, the vmid should be checked before
>> vcpu enter guest.
>>
>> Signed-off-by: Tianrui Zhao <zhaotianrui@loongson.cn>
>> ---
>> arch/loongarch/kvm/vmid.c | 65 +++++++++++++++++++++++++++++++++++++++
>> 1 file changed, 65 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 000000000000..7d9688c24184
>> --- /dev/null
>> +++ b/arch/loongarch/kvm/vmid.c
>> @@ -0,0 +1,65 @@
>> +// SPDX-License-Identifier: GPL-2.0
>> +/*
>> + * Copyright (C) 2020-2023 Loongson Technology Corporation Limited
>> + */
>> +
>> +#include <linux/kvm_host.h>
>> +#include <asm/kvm_host.h>
> linux/kvm_host.h already include asm/kvm_host.h
>
> Huacai
Thanks, I will remove the asm/kvm_host.h.
Thanks
Tianrui Zhao
>> +#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, int cpu)
>> +{
>> + struct kvm_context *context;
>> + bool migrated;
>> + unsigned long ver, old, vpid;
>> +
>> + /*
>> + * 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->arch.last_exec_cpu != cpu);
>> + vcpu->arch.last_exec_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);
>> + }
>> +
>> + /* Restore GSTAT(0x50).vpid */
>> + vpid = (vcpu->arch.vpid & vpid_mask)
>> + << CSR_GSTAT_GID_SHIFT;
>> + change_csr_gstat(vpid_mask << CSR_GSTAT_GID_SHIFT, vpid);
>> +}
>> --
>> 2.31.1
>>
next prev parent reply other threads:[~2023-04-19 8:53 UTC|newest]
Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-04-17 9:46 [PATCH v7 00/30] Add KVM LoongArch support Tianrui Zhao
2023-04-17 9:46 ` [PATCH v7 01/30] LoongArch: KVM: Add kvm related header files Tianrui Zhao
2023-04-19 9:28 ` WANG Xuerui
2023-04-20 2:36 ` Tianrui Zhao
2023-04-20 3:32 ` Tianrui Zhao
2023-04-17 9:46 ` [PATCH v7 02/30] LoongArch: KVM: Implement kvm module related interface Tianrui Zhao
2023-04-17 9:46 ` [PATCH v7 03/30] LoongArch: KVM: Implement kvm hardware enable, disable interface Tianrui Zhao
2023-04-17 9:46 ` [PATCH v7 04/30] LoongArch: KVM: Implement VM related functions Tianrui Zhao
2023-04-17 9:46 ` [PATCH v7 05/30] LoongArch: KVM: Add vcpu related header files Tianrui Zhao
2023-04-17 9:46 ` [PATCH v7 06/30] LoongArch: KVM: Implement vcpu create and destroy interface Tianrui Zhao
2023-04-17 9:46 ` [PATCH v7 07/30] LoongArch: KVM: Implement vcpu run interface Tianrui Zhao
2023-04-17 9:46 ` [PATCH v7 08/30] LoongArch: KVM: Implement vcpu handle exit interface Tianrui Zhao
2023-04-17 9:46 ` [PATCH v7 09/30] LoongArch: KVM: Implement vcpu get, vcpu set registers Tianrui Zhao
2023-04-17 9:46 ` [PATCH v7 10/30] LoongArch: KVM: Implement vcpu ENABLE_CAP ioctl interface Tianrui Zhao
2023-04-17 9:46 ` [PATCH v7 11/30] LoongArch: KVM: Implement fpu related operations for vcpu Tianrui Zhao
2023-04-17 9:46 ` [PATCH v7 12/30] LoongArch: KVM: Implement vcpu interrupt operations Tianrui Zhao
2023-04-17 9:46 ` [PATCH v7 13/30] LoongArch: KVM: Implement misc vcpu related interfaces Tianrui Zhao
2023-04-17 9:46 ` [PATCH v7 14/30] LoongArch: KVM: Implement vcpu load and vcpu put operations Tianrui Zhao
2023-04-17 9:46 ` [PATCH v7 15/30] LoongArch: KVM: Implement vcpu status description Tianrui Zhao
2023-04-17 9:46 ` [PATCH v7 16/30] LoongArch: KVM: Implement update VM id function Tianrui Zhao
2023-04-19 2:01 ` Huacai Chen
2023-04-19 8:53 ` Tianrui Zhao [this message]
2023-04-17 9:46 ` [PATCH v7 17/30] LoongArch: KVM: Implement virtual machine tlb operations Tianrui Zhao
2023-04-19 2:02 ` Huacai Chen
2023-04-19 8:59 ` Tianrui Zhao
2023-04-17 9:46 ` [PATCH v7 18/30] LoongArch: KVM: Implement vcpu timer operations Tianrui Zhao
2023-04-17 9:46 ` [PATCH v7 19/30] LoongArch: KVM: Implement kvm mmu operations Tianrui Zhao
2023-04-17 9:46 ` [PATCH v7 20/30] LoongArch: KVM: Implement handle csr excption Tianrui Zhao
2023-04-17 9:46 ` [PATCH v7 21/30] LoongArch: KVM: Implement handle iocsr exception Tianrui Zhao
2023-04-17 9:46 ` [PATCH v7 22/30] LoongArch: KVM: Implement handle idle exception Tianrui Zhao
2023-04-17 9:46 ` [PATCH v7 23/30] LoongArch: KVM: Implement handle gspr exception Tianrui Zhao
2023-04-17 9:46 ` [PATCH v7 24/30] LoongArch: KVM: Implement handle mmio exception Tianrui Zhao
2023-04-17 9:46 ` [PATCH v7 25/30] LoongArch: KVM: Implement handle fpu exception Tianrui Zhao
2023-04-17 9:46 ` [PATCH v7 26/30] LoongArch: KVM: Implement kvm exception vector Tianrui Zhao
2023-04-17 9:46 ` [PATCH v7 27/30] LoongArch: KVM: Implement vcpu world switch Tianrui Zhao
2023-04-17 9:46 ` [PATCH v7 28/30] LoongArch: KVM: Implement probe virtualization when loongarch cpu init Tianrui Zhao
2023-04-18 9:19 ` [PATCH v7 00/30] Add KVM LoongArch support Tianrui Zhao
2023-04-17 9:59 Tianrui Zhao
2023-04-17 9:59 ` [PATCH v7 16/30] LoongArch: KVM: Implement update VM id function Tianrui Zhao
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=d2dbcf54-4015-81ec-6b96-47cdcc22cd13@loongson.cn \
--to=zhaotianrui@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=maobibo@loongson.cn \
--cc=oliver.upton@linux.dev \
--cc=pbonzini@redhat.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®