From: Sean Christopherson <seanjc@google.com>
To: Sean Christopherson <seanjc@google.com>,
Paolo Bonzini <pbonzini@redhat.com>
Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org,
Wenyao Hai <haiwenyao@uniontech.com>,
Ke Guo <guoke@uniontech.com>
Subject: [PATCH 3/5] KVM: x86: Use MTRR macros to define possible MTRR MSR ranges
Date: Wed, 3 May 2023 11:28:50 -0700 [thread overview]
Message-ID: <20230503182852.3431281-4-seanjc@google.com> (raw)
In-Reply-To: <20230503182852.3431281-1-seanjc@google.com>
Use the MTRR macros to identify the ranges of possible MTRR MSRs instead
of bounding the ranges with a mismash of open coded values and unrelated
MSR indices. Carving out the gap for the machine check MSRs in particular
is confusing, as it's easy to incorrectly think the case statement handles
MCE MSRs instead of skipping them.
Drop the range-based funneling of MSRs between the end of the MCE MSRs
and MTRR_DEF_TYPE, i.e. 0x2A0-0x2FF, and instead handle MTTR_DEF_TYPE as
the one-off case that it is.
Extract PAT (0x277) as well in anticipation of dropping PAT "handling"
from the MTRR code.
Keep the range-based handling for the variable+fixed MTRRs even though
capturing unknown MSRs 0x214-0x24F is arguably "wrong". There is a gap in
the fixed MTRRs, 0x260-0x267, i.e. the MTRR code needs to filter out
unknown MSRs anyways, and using a single range generates marginally better
code for the big switch statement.
Signed-off-by: Sean Christopherson <seanjc@google.com>
---
arch/x86/kvm/mtrr.c | 2 +-
arch/x86/kvm/x86.c | 10 ++++++----
2 files changed, 7 insertions(+), 5 deletions(-)
diff --git a/arch/x86/kvm/mtrr.c b/arch/x86/kvm/mtrr.c
index 9fac1ec03463..d2c428f4ae42 100644
--- a/arch/x86/kvm/mtrr.c
+++ b/arch/x86/kvm/mtrr.c
@@ -28,7 +28,7 @@
static bool msr_mtrr_valid(unsigned msr)
{
switch (msr) {
- case 0x200 ... 0x200 + 2 * KVM_NR_VAR_MTRR - 1:
+ case MTRRphysBase_MSR(0) ... MTRRphysMask_MSR(KVM_NR_VAR_MTRR - 1):
case MSR_MTRRfix64K_00000:
case MSR_MTRRfix16K_80000:
case MSR_MTRRfix16K_A0000:
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index e7f78fe79b32..8b356c9d8a81 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -3700,8 +3700,9 @@ int kvm_set_msr_common(struct kvm_vcpu *vcpu, struct msr_data *msr_info)
return 1;
}
break;
- case 0x200 ... MSR_IA32_MC0_CTL2 - 1:
- case MSR_IA32_MCx_CTL2(KVM_MAX_MCE_BANKS) ... 0x2ff:
+ case MSR_IA32_CR_PAT:
+ case MTRRphysBase_MSR(0) ... MSR_MTRRfix4K_F8000:
+ case MSR_MTRRdefType:
return kvm_mtrr_set_msr(vcpu, msr, data);
case MSR_IA32_APICBASE:
return kvm_set_apic_base(vcpu, msr_info);
@@ -4108,9 +4109,10 @@ int kvm_get_msr_common(struct kvm_vcpu *vcpu, struct msr_data *msr_info)
msr_info->data = kvm_scale_tsc(rdtsc(), ratio) + offset;
break;
}
+ case MSR_IA32_CR_PAT:
case MSR_MTRRcap:
- case 0x200 ... MSR_IA32_MC0_CTL2 - 1:
- case MSR_IA32_MCx_CTL2(KVM_MAX_MCE_BANKS) ... 0x2ff:
+ case MTRRphysBase_MSR(0) ... MSR_MTRRfix4K_F8000:
+ case MSR_MTRRdefType:
return kvm_mtrr_get_msr(vcpu, msr_info->index, &msr_info->data);
case 0xcd: /* fsb frequency */
msr_info->data = 3;
--
2.40.1.495.gc816e09b53d-goog
next prev parent reply other threads:[~2023-05-03 18:29 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-05-03 18:28 [PATCH 0/5] KVM: x86: Clean up MSR PAT handling Sean Christopherson
2023-05-03 18:28 ` [PATCH 1/5] KVM: VMX: Open code writing vCPU's PAT in VMX's MSR handler Sean Christopherson
2023-05-03 23:00 ` Huang, Kai
2023-05-03 23:25 ` Sean Christopherson
2023-05-03 23:41 ` Huang, Kai
2023-05-04 17:23 ` Sean Christopherson
2023-05-03 18:28 ` [PATCH 2/5] KVM: SVM: Use kvm_pat_valid() directly instead of kvm_mtrr_valid() Sean Christopherson
2023-05-03 23:04 ` Huang, Kai
2023-05-04 15:34 ` Sean Christopherson
2023-05-05 11:20 ` Huang, Kai
2023-05-11 23:03 ` Sean Christopherson
2023-05-03 18:28 ` Sean Christopherson [this message]
2023-05-03 23:23 ` [PATCH 3/5] KVM: x86: Use MTRR macros to define possible MTRR MSR ranges Huang, Kai
2023-05-03 23:36 ` Sean Christopherson
2023-05-03 23:49 ` Huang, Kai
2023-05-04 9:02 ` Yan Zhao
2023-05-04 15:36 ` Sean Christopherson
2023-05-03 18:28 ` [PATCH 4/5] KVM: x86: WARN if writes to PAT MSR are handled by common KVM code Sean Christopherson
2023-05-03 23:26 ` Huang, Kai
2023-05-03 23:38 ` Sean Christopherson
2023-05-03 18:28 ` [PATCH 5/5] KVM: x86: Move PAT MSR handling out of mtrr.c Sean Christopherson
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=20230503182852.3431281-4-seanjc@google.com \
--to=seanjc@google.com \
--cc=guoke@uniontech.com \
--cc=haiwenyao@uniontech.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=pbonzini@redhat.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®