Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 6092d3d3 authored by Joerg Roedel's avatar Joerg Roedel Committed by Paolo Bonzini
Browse files

kvm: svm: Only propagate next_rip when guest supports it



Currently we always write the next_rip of the shadow vmcb to
the guests vmcb when we emulate a vmexit. This could confuse
the guest when its cpuid indicated no support for the
next_rip feature.

Fix this by only propagating next_rip if the guest actually
supports it.

Cc: Bandan Das <bsd@redhat.com>
Cc: Dirk Mueller <dmueller@suse.com>
Tested-By: default avatarDirk Mueller <dmueller@suse.com>
Signed-off-by: default avatarJoerg Roedel <jroedel@suse.de>
Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
parent 951f9fd7
Loading
Loading
Loading
Loading
+21 −0
Original line number Diff line number Diff line
@@ -149,4 +149,25 @@ static inline bool guest_cpuid_has_rdtscp(struct kvm_vcpu *vcpu)
	best = kvm_find_cpuid_entry(vcpu, 0x80000001, 0);
	return best && (best->edx & bit(X86_FEATURE_RDTSCP));
}

/*
 * NRIPS is provided through cpuidfn 0x8000000a.edx bit 3
 */
#define BIT_NRIPS	3

static inline bool guest_cpuid_has_nrips(struct kvm_vcpu *vcpu)
{
	struct kvm_cpuid_entry2 *best;

	best = kvm_find_cpuid_entry(vcpu, 0x8000000a, 0);

	/*
	 * NRIPS is a scattered cpuid feature, so we can't use
	 * X86_FEATURE_NRIPS here (X86_FEATURE_NRIPS would be bit
	 * position 8, not 3).
	 */
	return best && (best->edx & bit(BIT_NRIPS));
}
#undef BIT_NRIPS

#endif
+10 −1
Original line number Diff line number Diff line
@@ -159,6 +159,9 @@ struct vcpu_svm {
	u32 apf_reason;

	u64  tsc_ratio;

	/* cached guest cpuid flags for faster access */
	bool nrips_enabled	: 1;
};

static DEFINE_PER_CPU(u64, current_tsc_ratio);
@@ -2365,6 +2368,8 @@ static int nested_svm_vmexit(struct vcpu_svm *svm)
	nested_vmcb->control.exit_info_2       = vmcb->control.exit_info_2;
	nested_vmcb->control.exit_int_info     = vmcb->control.exit_int_info;
	nested_vmcb->control.exit_int_info_err = vmcb->control.exit_int_info_err;

	if (svm->nrips_enabled)
		nested_vmcb->control.next_rip  = vmcb->control.next_rip;

	/*
@@ -4085,6 +4090,10 @@ static u64 svm_get_mt_mask(struct kvm_vcpu *vcpu, gfn_t gfn, bool is_mmio)

static void svm_cpuid_update(struct kvm_vcpu *vcpu)
{
	struct vcpu_svm *svm = to_svm(vcpu);

	/* Update nrips enabled cache */
	svm->nrips_enabled = !!guest_cpuid_has_nrips(&svm->vcpu);
}

static void svm_set_supported_cpuid(u32 func, struct kvm_cpuid_entry2 *entry)