mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "bibo, mao" <maobibo@loongson.cn>
To: Tianrui Zhao <zhaotianrui@loongson.cn>,
	linux-kernel@vger.kernel.org, kvm@vger.kernel.org
Cc: Paolo Bonzini <pbonzini@redhat.com>,
	Huacai Chen <chenhuacai@kernel.org>,
	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 v12 06/31] LoongArch: KVM: Implement vcpu create and destroy interface
Date: Mon, 5 Jun 2023 20:44:39 +0800	[thread overview]
Message-ID: <4d4d7453-356d-9eec-c183-e8211a40e5e9@loongson.cn> (raw)
In-Reply-To: <20230530015223.147755-7-zhaotianrui@loongson.cn>

Reviewed-by: Bibo, Mao <maobibo@loongson.cn>

在 2023/5/30 09:51, Tianrui Zhao 写道:
> Implement vcpu create and destroy interface, saving some info
> into vcpu arch structure such as vcpu exception entrance, vcpu
> enter guest pointer, etc. Init vcpu timer and set address
> translation mode when vcpu create.
> 
> Signed-off-by: Tianrui Zhao <zhaotianrui@loongson.cn>
> ---
>  arch/loongarch/kvm/vcpu.c | 88 +++++++++++++++++++++++++++++++++++++++
>  1 file changed, 88 insertions(+)
>  create mode 100644 arch/loongarch/kvm/vcpu.c
> 
> diff --git a/arch/loongarch/kvm/vcpu.c b/arch/loongarch/kvm/vcpu.c
> new file mode 100644
> index 000000000000..24b5b00266a1
> --- /dev/null
> +++ b/arch/loongarch/kvm/vcpu.c
> @@ -0,0 +1,88 @@
> +// SPDX-License-Identifier: GPL-2.0
> +/*
> + * Copyright (C) 2020-2023 Loongson Technology Corporation Limited
> + */
> +
> +#include <linux/kvm_host.h>
> +#include <asm/fpu.h>
> +#include <asm/loongarch.h>
> +#include <asm/setup.h>
> +#include <asm/time.h>
> +
> +#define CREATE_TRACE_POINTS
> +#include "trace.h"
> +
> +int kvm_arch_vcpu_precreate(struct kvm *kvm, unsigned int id)
> +{
> +	return 0;
> +}
> +
> +int kvm_arch_vcpu_create(struct kvm_vcpu *vcpu)
> +{
> +	unsigned long timer_hz;
> +	struct loongarch_csrs *csr;
> +
> +	vcpu->arch.vpid = 0;
> +
> +	hrtimer_init(&vcpu->arch.swtimer, CLOCK_MONOTONIC, HRTIMER_MODE_ABS_PINNED);
> +	vcpu->arch.swtimer.function = kvm_swtimer_wakeup;
> +	vcpu->kvm->arch.online_vcpus = vcpu->vcpu_id + 1;
> +
> +	vcpu->arch.guest_eentry = (unsigned long)kvm_loongarch_ops->guest_eentry;
> +	vcpu->arch.handle_exit = _kvm_handle_exit;
> +	vcpu->arch.csr = kzalloc(sizeof(struct loongarch_csrs), GFP_KERNEL);
> +	if (!vcpu->arch.csr)
> +		return -ENOMEM;
> +
> +	/*
> +	 * kvm all exceptions share one exception entry, and host <-> guest switch
> +	 * also switch excfg.VS field, keep host excfg.VS info here
> +	 */
> +	vcpu->arch.host_ecfg = (read_csr_ecfg() & CSR_ECFG_VS);
> +
> +	/* Init */
> +	vcpu->arch.last_sched_cpu = -1;
> +	vcpu->arch.last_exec_cpu = -1;
> +
> +	/*
> +	 * Initialize guest register state to valid architectural reset state.
> +	 */
> +	timer_hz = calc_const_freq();
> +	kvm_init_timer(vcpu, timer_hz);
> +
> +	/* Set Initialize mode for GUEST */
> +	csr = vcpu->arch.csr;
> +	kvm_write_sw_gcsr(csr, LOONGARCH_CSR_CRMD, CSR_CRMD_DA);
> +
> +	/* Set cpuid */
> +	kvm_write_sw_gcsr(csr, LOONGARCH_CSR_TMID, vcpu->vcpu_id);
> +
> +	/* start with no pending virtual guest interrupts */
> +	csr->csrs[LOONGARCH_CSR_GINTC] = 0;
> +
> +	return 0;
> +}
> +
> +void kvm_arch_vcpu_postcreate(struct kvm_vcpu *vcpu)
> +{
> +}
> +
> +void kvm_arch_vcpu_destroy(struct kvm_vcpu *vcpu)
> +{
> +	int cpu;
> +	struct kvm_context *context;
> +
> +	hrtimer_cancel(&vcpu->arch.swtimer);
> +	kvm_mmu_free_memory_cache(&vcpu->arch.mmu_page_cache);
> +	kfree(vcpu->arch.csr);
> +
> +	/*
> +	 * If the vCPU is freed and reused as another vCPU, we don't want the
> +	 * matching pointer wrongly hanging around in last_vcpu.
> +	 */
> +	for_each_possible_cpu(cpu) {
> +		context = per_cpu_ptr(vcpu->kvm->arch.vmcs, cpu);
> +		if (context->last_vcpu == vcpu)
> +			context->last_vcpu = NULL;
> +	}
> +}


  reply	other threads:[~2023-06-05 12:44 UTC|newest]

Thread overview: 73+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-30  1:51 [PATCH v12 00/31] Add KVM LoongArch support Tianrui Zhao
2023-05-30  1:51 ` [PATCH v12 01/31] LoongArch: KVM: Add kvm related header files Tianrui Zhao
2023-06-05  5:00   ` Huacai Chen
2023-06-05 10:18     ` Paolo Bonzini
2023-06-05 12:22   ` bibo, mao
2023-06-06  6:30   ` Youling Tang
2023-06-06 10:00     ` Tianrui Zhao
2023-05-30  1:51 ` [PATCH v12 02/31] LoongArch: KVM: Implement kvm module related interface Tianrui Zhao
2023-06-05 12:27   ` bibo, mao
2023-05-30  1:51 ` [PATCH v12 03/31] LoongArch: KVM: Implement kvm hardware enable, disable interface Tianrui Zhao
2023-05-30  1:51 ` [PATCH v12 04/31] LoongArch: KVM: Implement VM related functions Tianrui Zhao
2023-06-05 12:31   ` bibo, mao
2023-05-30  1:51 ` [PATCH v12 05/31] LoongArch: KVM: Add vcpu related header files Tianrui Zhao
2023-06-05 12:42   ` bibo, mao
2023-06-06  2:00     ` Tianrui Zhao
2023-05-30  1:51 ` [PATCH v12 06/31] LoongArch: KVM: Implement vcpu create and destroy interface Tianrui Zhao
2023-06-05 12:44   ` bibo, mao [this message]
2023-05-30  1:51 ` [PATCH v12 07/31] LoongArch: KVM: Implement vcpu run interface Tianrui Zhao
2023-06-05 12:53   ` bibo, mao
2023-06-06  2:02     ` Tianrui Zhao
2023-05-30  1:52 ` [PATCH v12 08/31] LoongArch: KVM: Implement vcpu handle exit interface Tianrui Zhao
2023-06-05 13:03   ` bibo, mao
2023-06-06  2:13     ` Tianrui Zhao
2023-05-30  1:52 ` [PATCH v12 09/31] LoongArch: KVM: Implement vcpu get, vcpu set registers Tianrui Zhao
2023-06-05 13:04   ` bibo, mao
2023-06-06  6:41   ` Youling Tang
2023-06-06  9:12     ` Tianrui Zhao
2023-05-30  1:52 ` [PATCH v12 10/31] LoongArch: KVM: Implement vcpu ENABLE_CAP ioctl interface Tianrui Zhao
2023-06-05 13:12   ` bibo, mao
2023-06-06  3:20     ` Tianrui Zhao
2023-05-30  1:52 ` [PATCH v12 11/31] LoongArch: KVM: Implement fpu related operations for vcpu Tianrui Zhao
2023-06-05 13:13   ` bibo, mao
2023-05-30  1:52 ` [PATCH v12 12/31] LoongArch: KVM: Implement vcpu interrupt operations Tianrui Zhao
2023-06-05 13:13   ` bibo, mao
2023-06-06  6:49   ` Youling Tang
2023-06-06  9:13     ` Tianrui Zhao
2023-05-30  1:52 ` [PATCH v12 13/31] LoongArch: KVM: Implement misc vcpu related interfaces Tianrui Zhao
2023-05-30  1:52 ` [PATCH v12 14/31] LoongArch: KVM: Implement vcpu load and vcpu put operations Tianrui Zhao
2023-05-30  1:52 ` [PATCH v12 15/31] LoongArch: KVM: Implement vcpu status description Tianrui Zhao
2023-06-05 13:04   ` bibo, mao
2023-05-30  1:52 ` [PATCH v12 16/31] LoongArch: KVM: Implement update VM id function Tianrui Zhao
2023-06-06  1:13   ` bibo, mao
2023-05-30  1:52 ` [PATCH v12 17/31] LoongArch: KVM: Implement virtual machine tlb operations Tianrui Zhao
2023-06-06  1:20   ` bibo, mao
2023-05-30  1:52 ` [PATCH v12 18/31] LoongArch: KVM: Implement vcpu timer operations Tianrui Zhao
2023-05-30  1:52 ` [PATCH v12 19/31] LoongArch: KVM: Implement kvm mmu operations Tianrui Zhao
2023-06-06  1:28   ` bibo, mao
2023-06-06  2:51     ` Tianrui Zhao
2023-05-30  1:52 ` [PATCH v12 20/31] LoongArch: KVM: Implement handle csr excption Tianrui Zhao
2023-06-06  1:35   ` bibo, mao
2023-06-06  2:59     ` Tianrui Zhao
2023-05-30  1:52 ` [PATCH v12 21/31] LoongArch: KVM: Implement handle iocsr exception Tianrui Zhao
2023-06-06  1:36   ` bibo, mao
2023-05-30  1:52 ` [PATCH v12 22/31] LoongArch: KVM: Implement handle idle exception Tianrui Zhao
2023-06-06  1:36   ` bibo, mao
2023-05-30  1:52 ` [PATCH v12 23/31] LoongArch: KVM: Implement handle gspr exception Tianrui Zhao
2023-06-06  1:38   ` bibo, mao
2023-05-30  1:52 ` [PATCH v12 24/31] LoongArch: KVM: Implement handle mmio exception Tianrui Zhao
2023-06-06  1:41   ` bibo, mao
2023-05-30  1:52 ` [PATCH v12 25/31] LoongArch: KVM: Implement handle fpu exception Tianrui Zhao
2023-06-06  1:42   ` bibo, mao
2023-05-30  1:52 ` [PATCH v12 26/31] LoongArch: KVM: Implement kvm exception vector Tianrui Zhao
2023-06-06  1:43   ` bibo, mao
2023-06-06  7:00   ` Youling Tang
2023-06-06  9:16     ` Tianrui Zhao
2023-06-08 11:44     ` 赵天瑞
2023-05-30  1:52 ` [PATCH v12 27/31] LoongArch: KVM: Implement vcpu world switch Tianrui Zhao
2023-06-06  2:27   ` bibo, mao
2023-05-30  1:52 ` [PATCH v12 28/31] LoongArch: KVM: Implement probe virtualization when LoongArch cpu init Tianrui Zhao
2023-05-30  1:52 ` [PATCH v12 29/31] LoongArch: KVM: Enable kvm config and add the makefile Tianrui Zhao
2023-06-06  2:37   ` bibo, mao
2023-05-30  1:52 ` [PATCH v12 30/31] LoongArch: KVM: Supplement kvm document about LoongArch-specific part Tianrui Zhao
2023-05-30  1:52 ` [PATCH v12 31/31] LoongArch: KVM: Add maintainers for LoongArch KVM 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=4d4d7453-356d-9eec-c183-e8211a40e5e9@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®