Re: [PATCH v12 04/31] LoongArch: KVM: Implement VM related functions

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Reviewed-by: Bibo, Mao <maobibo@xxxxxxxxxxx>

在 2023/5/30 09:51, Tianrui Zhao 写道:
> Implement LoongArch VM operations: Init and destroy vm interface,
> allocating memory page to save the vm pgd when init vm. Implement
> vm check extension, such as getting vcpu number info, memory slots
> info, and fpu info. And implement vm status description.
> 
> Signed-off-by: Tianrui Zhao <zhaotianrui@xxxxxxxxxxx>
> ---
>  arch/loongarch/kvm/vm.c | 78 +++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 78 insertions(+)
>  create mode 100644 arch/loongarch/kvm/vm.c
> 
> diff --git a/arch/loongarch/kvm/vm.c b/arch/loongarch/kvm/vm.c
> new file mode 100644
> index 000000000000..43688a04ab78
> --- /dev/null
> +++ b/arch/loongarch/kvm/vm.c
> @@ -0,0 +1,78 @@
> +// SPDX-License-Identifier: GPL-2.0
> +/*
> + * Copyright (C) 2020-2023 Loongson Technology Corporation Limited
> + */
> +
> +#include <linux/kvm_host.h>
> +
> +#define KVM_LOONGARCH_VERSION 1
> +
> +const struct _kvm_stats_desc kvm_vm_stats_desc[] = {
> +	KVM_GENERIC_VM_STATS(),
> +};
> +
> +const struct kvm_stats_header kvm_vm_stats_header = {
> +	.name_size = KVM_STATS_NAME_SIZE,
> +	.num_desc = ARRAY_SIZE(kvm_vm_stats_desc),
> +	.id_offset =  sizeof(struct kvm_stats_header),
> +	.desc_offset = sizeof(struct kvm_stats_header) + KVM_STATS_NAME_SIZE,
> +	.data_offset = sizeof(struct kvm_stats_header) + KVM_STATS_NAME_SIZE +
> +					sizeof(kvm_vm_stats_desc),
> +};
> +
> +int kvm_arch_init_vm(struct kvm *kvm, unsigned long type)
> +{
> +	/* Allocate page table to map GPA -> RPA */
> +	kvm->arch.gpa_mm.pgd = kvm_pgd_alloc();
> +	if (!kvm->arch.gpa_mm.pgd)
> +		return -ENOMEM;
> +
> +	kvm_init_vmcs(kvm);
> +	kvm->arch.gpa_size = BIT(cpu_vabits - 1);
> +	return 0;
> +}
> +
> +void kvm_arch_destroy_vm(struct kvm *kvm)
> +{
> +	kvm_destroy_vcpus(kvm);
> +	_kvm_destroy_mm(kvm);
> +}
> +
> +int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext)
> +{
> +	int r;
> +
> +	switch (ext) {
> +	case KVM_CAP_ONE_REG:
> +	case KVM_CAP_ENABLE_CAP:
> +	case KVM_CAP_READONLY_MEM:
> +	case KVM_CAP_SYNC_MMU:
> +	case KVM_CAP_IMMEDIATE_EXIT:
> +	case KVM_CAP_IOEVENTFD:
> +	case KVM_CAP_MP_STATE:
> +		r = 1;
> +		break;
> +	case KVM_CAP_NR_VCPUS:
> +		r = num_online_cpus();
> +		break;
> +	case KVM_CAP_MAX_VCPUS:
> +		r = KVM_MAX_VCPUS;
> +		break;
> +	case KVM_CAP_MAX_VCPU_ID:
> +		r = KVM_MAX_VCPU_IDS;
> +		break;
> +	case KVM_CAP_NR_MEMSLOTS:
> +		r = KVM_USER_MEM_SLOTS;
> +		break;
> +	default:
> +		r = 0;
> +		break;
> +	}
> +
> +	return r;
> +}
> +
> +int kvm_arch_vm_ioctl(struct file *filp, unsigned int ioctl, unsigned long arg)
> +{
> +	return -ENOIOCTLCMD;
> +}




[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux