Commit 2e584981 authored by Bibo Mao's avatar Bibo Mao Committed by Xianglai Li
Browse files

LoongArch: KVM: Enable paravirt feature control from VMM

mainline inclusion
from mainline-v6.12-rc1
commit cdc118f802410525cca872e0861a14d76d12c574
category: feature
bugzilla: https://gitee.com/openeuler/kernel/issues/IAZJDO


CVE: NA

--------------------------------

Export kernel paravirt features to user space, so that VMM can control
each single paravirt feature. By default paravirt features will be the
same with kvm supported features if VMM does not set it.

Also a new feature KVM_FEATURE_VIRT_EXTIOI is added which can be set
from user space. This feature indicates that the virt EIOINTC can route
interrupts to 256 vCPUs, rather than 4 vCPUs like with real HW.

Signed-off-by: default avatarBibo Mao <maobibo@loongson.cn>
Signed-off-by: default avatarHuacai Chen <chenhuacai@loongson.cn>
Signed-off-by: default avatarXianglai Li <lixianglai@loongson.cn>
parent 031d5914
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -141,6 +141,8 @@ struct kvm_arch {
	unsigned int  root_level;
	spinlock_t    phyid_map_lock;
	struct kvm_phyid_map  *phyid_map;
	/* Enabled PV features */
	unsigned long pv_features;

	s64 time_offset;
	struct kvm_context __percpu *vmcs;
@@ -175,6 +177,11 @@ enum emulation_result {
#define KVM_LARCH_SWCSR_LATEST	(0x1 << 5)
#define KVM_LARCH_HWCSR_USABLE	(0x1 << 6)

#define LOONGARCH_PV_FEAT_UPDATED	BIT_ULL(63)
#define LOONGARCH_PV_FEAT_MASK		(BIT(KVM_FEATURE_IPI) |		\
					 BIT(KVM_FEATURE_STEAL_TIME) |	\
					 BIT(KVM_FEATURE_VIRT_EXTIOI))

struct kvm_vcpu_arch {
	/*
	 * Switch pointer-to-function type to unsigned long
+2 −0
Original line number Diff line number Diff line
@@ -2,6 +2,8 @@
#ifndef _ASM_LOONGARCH_KVM_PARA_H
#define _ASM_LOONGARCH_KVM_PARA_H

#include <uapi/asm/kvm_para.h>

/*
 * Hypercall code field
 */
+5 −0
Original line number Diff line number Diff line
@@ -130,4 +130,9 @@ static inline bool kvm_pvtime_supported(void)
	return !!sched_info_on();
}

static inline bool kvm_guest_has_pv_feature(struct kvm_vcpu *vcpu, unsigned int feature)
{
	return vcpu->kvm->arch.pv_features & BIT(feature);
}

#endif /* __ASM_LOONGARCH_KVM_VCPU_H__ */
+1 −8
Original line number Diff line number Diff line
@@ -161,15 +161,8 @@

/*
 * cpucfg index area: 0x40000000 -- 0x400000ff
 * SW emulation for KVM hypervirsor
 * SW emulation for KVM hypervirsor, see arch/loongarch/include/uapi/asm/kvm_para.h
 */
#define CPUCFG_KVM_BASE			0x40000000UL
#define CPUCFG_KVM_SIZE			0x100
#define CPUCFG_KVM_SIG			CPUCFG_KVM_BASE
#define  KVM_SIGNATURE			"KVM\0"
#define CPUCFG_KVM_FEATURE		(CPUCFG_KVM_BASE + 4)
#define  KVM_FEATURE_PV_IPI		BIT(1)
#define  KVM_FEATURE_STEAL_TIME		BIT(2)

#ifndef __ASSEMBLY__

+9 −7
Original line number Diff line number Diff line
@@ -102,6 +102,8 @@ struct kvm_fpu {
#define  KVM_LOONGARCH_VM_FEAT_ARMBT		3
#define  KVM_LOONGARCH_VM_FEAT_MIPSBT		4
#define  KVM_LOONGARCH_VM_FEAT_PMU		5
#define  KVM_LOONGARCH_VM_FEAT_PV_IPI		6
#define  KVM_LOONGARCH_VM_FEAT_PV_STEALTIME	7

/* Device Control API on vcpu fd */
#define KVM_LOONGARCH_VCPU_CPUCFG	0
Loading