From: Sean Christopherson <seanjc@google.com>
To: Xin Li <xin@zytor.com>
Cc: linux-kernel@vger.kernel.org, kvm@vger.kernel.org,
pbonzini@redhat.com, tglx@linutronix.de, mingo@redhat.com,
bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org,
hpa@zytor.com, weijiang.yang@intel.com
Subject: Re: [PATCH 1/1] KVM: VMX: Cleanup VMX basic information defines and usages
Date: Thu, 19 Oct 2023 09:15:14 -0700 [thread overview]
Message-ID: <ZTFWEte375FF-5RA@google.com> (raw)
In-Reply-To: <20bb3005-bf6c-4fe1-bf0d-6d37e0ce1a77@zytor.com>
On Thu, Oct 19, 2023, Xin Li wrote:
> On 10/18/2023 2:08 PM, Sean Christopherson wrote:
>
> > > Add IA32_VMX_BASIC MSR bitfield shift macros and use them to define VMX
> > > basic information bitfields.
> >
> > Why? Unless something actually uses the shift independently, just define the
> > BIT_ULL(...) straightaway.
>
> Well, reading "BIT_ULL(49) | BIT_ULL(54) | BIT_ULL(55) |" is hard.
I wasn't suggesting that, I was suggesting:
#define VMX_BASIC_INOUT BIT_ULL(54)
instead of
#define VMX_BASIC_INOUT BIT_ULL(VMX_BASIC_INOUT_SHIFT)
Defining a shift adds a pointless layer of indirection (if the shift isn't used
directly). It's especially problematic when there are a series of definitions.
E.g. if I want to know which bit a flag corresponds to, this:
#define VMX_BASIC_32BIT_PHYS_ADDR_ONLY BIT_ULL(48)
#define VMX_BASIC_DUAL_MONITOR_TREATMENT BIT_ULL(49)
#define VMX_BASIC_MEM_TYPE(x) (((x) & GENMASK_ULL(53, 50)) >> 50)
#define VMX_BASIC_INOUT BIT_ULL(54)
#define VMX_BASIC_TRUE_CTLS BIT_ULL(55)
is much easier for me to process than this
#define VMX_BASIC_32BIT_PHYS_ADDR_ONLY_SHIFT 48
#define VMX_BASIC_32BIT_PHYS_ADDR_ONLY BIT_ULL(VMX_BASIC_32BIT_PHYS_ADDR_ONLY_SHIFT)
#define VMX_BASIC_DUAL_MONITOR_TREATMENT_SHIFT 49
#define VMX_BASIC_DUAL_MONITOR_TREATMENT BIT_ULL(VMX_BASIC_DUAL_MONITOR_TREATMENT_SHIFT)
#define VMX_BASIC_MEM_TYPE_SHIFT 50
#define VMX_BASIC_INOUT_SHIFT 54
#define VMX_BASIC_INOUT BIT_ULL(VMX_BASIC_INOUT_SHIFT)
#define VMX_BASIC_TRUE_CTLS_SHIFT 55
#define VMX_BASIC_TRUE_CTLS BIT_ULL(VMX_BASIC_TRUE_CTLS_SHIFT)
and the former also tends to work better for IDEs that support peeking at macro
definitions.
> > > ---
> > > arch/x86/include/asm/msr-index.h | 31 ++++++++++++++++++++------
> > > arch/x86/kvm/vmx/nested.c | 10 +++------
> > > arch/x86/kvm/vmx/vmx.c | 2 +-
> > > tools/arch/x86/include/asm/msr-index.h | 31 ++++++++++++++++++++------
> >
> > Please drop the tools/ update, copying kernel headers into tools is a perf tools
> > thing that I want no part of.
> >
> > https://lore.kernel.org/all/Y8bZ%2FJ98V5i3wG%2Fv@google.com
>
> why can't we simply remove tools/arch/x86/include/asm/msr-index.h?
That's a question for the tools/perf folks, though I believe the answer is partly
that the perf tooling relies on *exactly* matching kernel-internal structures, and
so tools/perf doesn't want to rely on installed headers.
> > > +#define VMX_BASIC_RESERVED_BITS \
> > > + (VMX_BASIC_ALWAYS_0 | \
> > > + VMX_BASIC_RESERVED_RANGE_1 | \
> > > + VMX_BASIC_RESERVED_RANGE_2)
> >
> > I don't see any value in defining VMX_BASIC_RESERVED_RANGE_1 and
> > VMX_BASIC_RESERVED_RANGE_2 separately. Or VMX_BASIC_ALWAYS_0 for the matter.
> > And I don't think these macros need to go in msr-index.h, e.g. just define them
> > above vmx_restore_vmx_basic() as that's likely going to be the only user, ever.
>
> hmm, I'm overusing macros, better do:
> #define VMX_BASIC_RESERVED_BITS \
> (BIT_ULL(31) | GENMASK_ULL(47, 45) | GENMASK_ULL(63, 56))
Please define from high=>low, x86 is little-endian. I.e.
(GENMASK_ULL(63, 56) | GENMASK_ULL(47, 45) | BIT_ULL(31))
> Probably should also move VMX MSR field defs from msr-index.h to
> a vmx header file.
Why bother putting them in a header? As above, it's extremely unlikely anything
besides vmx_restore_vmx_basic() will ever care about exactly which bits are
reserved.
prev parent reply other threads:[~2023-10-19 16:15 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-27 23:08 [PATCH 1/1] KVM: VMX: Cleanup VMX basic information defines and usages Xin Li (Intel)
2023-10-18 21:08 ` Sean Christopherson
2023-10-19 8:26 ` Xin Li
2023-10-19 16:15 ` Sean Christopherson [this message]
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=ZTFWEte375FF-5RA@google.com \
--to=seanjc@google.com \
--cc=bp@alien8.de \
--cc=dave.hansen@linux.intel.com \
--cc=hpa@zytor.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=pbonzini@redhat.com \
--cc=tglx@linutronix.de \
--cc=weijiang.yang@intel.com \
--cc=x86@kernel.org \
--cc=xin@zytor.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