Commit 7c0e37ce authored by Zhiqiang Ni's avatar Zhiqiang Ni Committed by ni-zhiqiang111
Browse files

KVM:arm64:Add a kvm parameter to control guest wfi trapping

virt inclusion
category: performance
bugzilla: https://gitee.com/openeuler/kernel/issues/IAQV1W



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

Currently, on GICv4+ system if a vCPU is only runnable process
on a pCPU and we are using direct injection of interrupts, the
guest WFI trapping will be turn off. So in host view, the vcpu
process's CPU util is almost 100%, which may confuse someone.
Let's add a kvm parameter to control guest wfi trapping.

Signed-off-by: default avatarZhiqiang Ni <nizhiqiang1@huawei.com>
parent ea308216
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -119,6 +119,9 @@ static inline void vcpu_clear_wfx_traps(struct kvm_vcpu *vcpu)
		vcpu->arch.hcr_el2 &= ~HCR_TWI;
	else
		vcpu->arch.hcr_el2 |= HCR_TWI;

	if (force_wfi_trap)
		vcpu->arch.hcr_el2 |= HCR_TWI;
}

static inline void vcpu_set_wfx_traps(struct kvm_vcpu *vcpu)
+2 −0
Original line number Diff line number Diff line
@@ -54,6 +54,7 @@
#define KVM_REQ_SUSPEND		KVM_ARCH_REQ(6)
#define KVM_REQ_RESYNC_PMU_EL0	KVM_ARCH_REQ(7)
#define KVM_REQ_RELOAD_TLBI_DVMBM	KVM_ARCH_REQ(8)
#define KVM_REQ_RELOAD_WFI_TRAPS       KVM_ARCH_REQ(9)

#define KVM_DIRTY_LOG_MANUAL_CAPS   (KVM_DIRTY_LOG_MANUAL_PROTECT_ENABLE | \
				     KVM_DIRTY_LOG_INITIALLY_SET)
@@ -1284,6 +1285,7 @@ extern unsigned int twedel;
void kvm_arm_vcpu_power_off(struct kvm_vcpu *vcpu);
bool kvm_arm_vcpu_stopped(struct kvm_vcpu *vcpu);

extern bool force_wfi_trap;
extern bool kvm_ncsnp_support;
extern bool kvm_dvmbm_support;

+49 −0
Original line number Diff line number Diff line
@@ -83,6 +83,48 @@ unsigned int twedel;
module_param(twedel, uint, 0644);
#endif

static int vcpu_req_reload_wfi_traps(const char *val, const struct kernel_param *kp);

static const struct kernel_param_ops force_wfi_trap_ops = {
	.set = vcpu_req_reload_wfi_traps,
	.get = param_get_bool,
};

bool force_wfi_trap;
module_param_cb(force_wfi_trap, &force_wfi_trap_ops, &force_wfi_trap, 0644);

static int vcpu_req_reload_wfi_traps(const char *val, const struct kernel_param *kp)
{
	struct kvm *kvm;
	bool oldvalue;
	int err;

	oldvalue = force_wfi_trap;
	err = param_set_bool(val, kp);
	if (err)
		return err;

	if (oldvalue == force_wfi_trap)
		return err;

	/*
	 * If set the force_wfi_trap from 1 to 0, no need to kick vcpus here.
	 * The HCR_TWI flag will be cleared in kvm_arch_vcpu_load().
	 */
	if (force_wfi_trap == 0)
		return 0;

	/*
	 * We need to kick vcpus out of guest mode here to reload
	 * wfx trapping config when re-enter guest mode.
	 */
	mutex_lock(&kvm_lock);
	list_for_each_entry(kvm, &vm_list, vm_list)
		kvm_make_all_cpus_request(kvm, KVM_REQ_RELOAD_WFI_TRAPS);
	mutex_unlock(&kvm_lock);
	return err;
}

int kvm_arch_vcpu_should_kick(struct kvm_vcpu *vcpu)
{
	return kvm_vcpu_exiting_guest_mode(vcpu) == IN_GUEST_MODE;
@@ -956,6 +998,13 @@ static int check_vcpu_requests(struct kvm_vcpu *vcpu)

		if (kvm_check_request(KVM_REQ_RELOAD_TLBI_DVMBM, vcpu))
			kvm_hisi_reload_lsudvmbm(vcpu->kvm);

		if (kvm_check_request(KVM_REQ_RELOAD_WFI_TRAPS, vcpu)) {
			if (single_task_running())
				vcpu_clear_wfx_traps(vcpu);
			else
				vcpu_set_wfx_traps(vcpu);
		}
	}

	return 1;