From: Sean Christopherson <seanjc@google.com>
To: Paolo Bonzini <pbonzini@redhat.com>
Cc: Vitaly Kuznetsov <vkuznets@redhat.com>,
Wanpeng Li <wanpengli@tencent.com>,
Jim Mattson <jmattson@google.com>, Joerg Roedel <joro@8bytes.org>,
kvm@vger.kernel.org, linux-kernel@vger.kernel.org,
Chenyi Qiang <chenyi.qiang@intel.com>,
Lei Wang <lei4.wang@intel.com>
Subject: Re: [PATCH 1/2] KVM: VMX: Sanitize VM-Entry/VM-Exit control pairs at kvm_intel load time
Date: Thu, 26 May 2022 21:35:02 +0000 [thread overview]
Message-ID: <Yo/yhiVl++FTSa3S@google.com> (raw)
In-Reply-To: <8baca98e-63d6-f7dd-067b-05f8e0dc381f@redhat.com>
On Thu, May 26, 2022, Paolo Bonzini wrote:
> On 5/25/22 23:04, Sean Christopherson wrote:
> > +#define VMCS_ENTRY_EXIT_PAIR(name, entry_action, exit_action) \
> > + { VM_ENTRY_##entry_action##_##name, VM_EXIT_##exit_action##_##name }
> > +
> > static __init int setup_vmcs_config(struct vmcs_config *vmcs_conf,
> > struct vmx_capability *vmx_cap)
> > {
> > @@ -2473,6 +2476,24 @@ static __init int setup_vmcs_config(struct vmcs_config *vmcs_conf,
> > u64 _cpu_based_3rd_exec_control = 0;
> > u32 _vmexit_control = 0;
> > u32 _vmentry_control = 0;
> > + int i;
> > +
> > + /*
> > + * LOAD/SAVE_DEBUG_CONTROLS are absent because both are mandatory.
> > + * SAVE_IA32_PAT and SAVE_IA32_EFER are absent because KVM always
> > + * intercepts writes to PAT and EFER, i.e. never enables those controls.
> > + */
> > + struct {
> > + u32 entry_control;
> > + u32 exit_control;
> > + } vmcs_entry_exit_pairs[] = {
> > + VMCS_ENTRY_EXIT_PAIR(IA32_PERF_GLOBAL_CTRL, LOAD, LOAD),
> > + VMCS_ENTRY_EXIT_PAIR(IA32_PAT, LOAD, LOAD),
> > + VMCS_ENTRY_EXIT_PAIR(IA32_EFER, LOAD, LOAD),
> > + VMCS_ENTRY_EXIT_PAIR(BNDCFGS, LOAD, CLEAR),
> > + VMCS_ENTRY_EXIT_PAIR(IA32_RTIT_CTL, LOAD, CLEAR),
> > + VMCS_ENTRY_EXIT_PAIR(IA32_LBR_CTL, LOAD, CLEAR),
>
> No macros please, it's just as clear to expand them especially since the
> #define is far from the struct definition.
It's not for clarity, it's to prevent plopping an EXIT control into the ENTRY
slot and vice versa. I have a hell of a time trying to visually differentiate
those, and a buggy pair isn't guaranteed to be detected at runtime, e.g. if both
are swapped, all bets are off, and if one is duplicated, odds the warn may or may
not show up unless hardware actually supports at least one of the controls, if not
both.
With this, swapping LOAD and LOAD is obviously a nop, and swapping LOAD and CLEAR
will generate a compiler error.
FWIW, I did originally have the array declared as static __initdata immediately
after the #define. I moved away from that because __initdata doesn't play nice
with const, but then of course I forgot to add back the "const". /facepalm
next prev parent reply other threads:[~2022-05-26 21:35 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-05-25 21:04 [PATCH 0/2] KVM: VMX: Sanitize VM-Entry/VM-Exit pairs during setup Sean Christopherson
2022-05-25 21:04 ` [PATCH 1/2] KVM: VMX: Sanitize VM-Entry/VM-Exit control pairs at kvm_intel load time Sean Christopherson
2022-05-25 23:27 ` Yuan Yao
2022-05-26 0:42 ` Sean Christopherson
2022-05-26 1:04 ` Yuan Yao
2022-05-26 10:39 ` Paolo Bonzini
2022-05-26 21:35 ` Sean Christopherson [this message]
2022-05-27 9:44 ` Paolo Bonzini
2022-05-25 21:04 ` [PATCH 2/2] KVM: VMX: Add knob to allow rejecting kvm_intel on inconsistent VMCS config Sean Christopherson
2022-05-25 21:17 ` Jim Mattson
2022-05-26 0:45 ` Sean Christopherson
2022-05-26 1:00 ` Jim Mattson
2022-05-26 10:39 ` 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=Yo/yhiVl++FTSa3S@google.com \
--to=seanjc@google.com \
--cc=chenyi.qiang@intel.com \
--cc=jmattson@google.com \
--cc=joro@8bytes.org \
--cc=kvm@vger.kernel.org \
--cc=lei4.wang@intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=pbonzini@redhat.com \
--cc=vkuznets@redhat.com \
--cc=wanpengli@tencent.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