All of lore.kernel.org
 help / color / mirror / Atom feed
From: Nadav Amit <namit@vmware.com>
To: pbonzini@redhat.com
Cc: kvm@vger.kernel.org, sean.j.christopherson@intel.com,
	Nadav Amit <namit@vmware.com>
Subject: [kvm-unit-tests PATCH] x86: vmx: Fix the check whether CMCI is supported
Date: Wed,  9 Oct 2019 04:27:54 -0700	[thread overview]
Message-ID: <20191009112754.36805-1-namit@vmware.com> (raw)

The logic of figuring out whether CMCI is supported is broken, causing
the CMCI accessing tests to fail on Skylake bare-metal.

Determine whether CMCI is supported according to the maximum entries in
the LVT as encoded in the APIC version register.

Suggested-by: Sean Christopherson <sean.j.christopherson@intel.com>
Signed-off-by: Nadav Amit <namit@vmware.com>
---
 lib/x86/apic.h  |  7 +++++++
 x86/vmx_tests.c | 10 +---------
 2 files changed, 8 insertions(+), 9 deletions(-)

diff --git a/lib/x86/apic.h b/lib/x86/apic.h
index b5bf208..a7eff63 100644
--- a/lib/x86/apic.h
+++ b/lib/x86/apic.h
@@ -70,6 +70,11 @@ static inline u32 x2apic_msr(u32 reg)
 	return APIC_BASE_MSR + (reg >> 4);
 }
 
+static inline bool apic_lvt_entry_supported(int idx)
+{
+	return GET_APIC_MAXLVT(apic_read(APIC_LVR)) >= idx;
+}
+
 static inline bool x2apic_reg_reserved(u32 reg)
 {
 	switch (reg) {
@@ -83,6 +88,8 @@ static inline bool x2apic_reg_reserved(u32 reg)
 	case 0x3a0 ... 0x3d0:
 	case 0x3f0:
 		return true;
+	case APIC_CMCI:
+		return !apic_lvt_entry_supported(6);
 	default:
 		return false;
 	}
diff --git a/x86/vmx_tests.c b/x86/vmx_tests.c
index f4b348b..0c710cd 100644
--- a/x86/vmx_tests.c
+++ b/x86/vmx_tests.c
@@ -5863,11 +5863,6 @@ static u64 virt_x2apic_mode_nibble1(u64 val)
 	return val & 0xf0;
 }
 
-static bool is_cmci_enabled(void)
-{
-	return rdmsr(MSR_IA32_MCG_CAP) & BIT_ULL(10);
-}
-
 static void virt_x2apic_mode_rd_expectation(
 	u32 reg, bool virt_x2apic_mode_on, bool disable_x2apic,
 	bool apic_register_virtualization, bool virtual_interrupt_delivery,
@@ -5877,9 +5872,6 @@ static void virt_x2apic_mode_rd_expectation(
 		!x2apic_reg_reserved(reg) &&
 		reg != APIC_EOI;
 
-	if (reg == APIC_CMCI && !is_cmci_enabled())
-		readable = false;
-
 	expectation->rd_exit_reason = VMX_VMCALL;
 	expectation->virt_fn = virt_x2apic_mode_identity;
 	if (virt_x2apic_mode_on && apic_register_virtualization) {
@@ -5943,7 +5935,7 @@ static bool get_x2apic_wr_val(u32 reg, u64 *val)
 		*val = apic_read(reg);
 		break;
 	case APIC_CMCI:
-		if (!is_cmci_enabled())
+		if (!apic_lvt_entry_supported(6))
 			return false;
 		*val = apic_read(reg);
 		break;
-- 
2.17.1


             reply	other threads:[~2019-10-09 18:49 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-09 11:27 Nadav Amit [this message]
2019-11-23  0:24 ` [kvm-unit-tests PATCH] x86: vmx: Fix the check whether CMCI is supported Nadav Amit
2019-11-23 10:27 ` Paolo Bonzini

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=20191009112754.36805-1-namit@vmware.com \
    --to=namit@vmware.com \
    --cc=kvm@vger.kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=sean.j.christopherson@intel.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.