[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <669b2a0fb4f028f3903bd4468f819f3e7f9758cb.camel@redhat.com>
Date: Wed, 24 Jul 2024 13:55:02 -0400
From: Maxim Levitsky <mlevitsk@...hat.com>
To: Sean Christopherson <seanjc@...gle.com>
Cc: Paolo Bonzini <pbonzini@...hat.com>, Vitaly Kuznetsov
<vkuznets@...hat.com>, kvm@...r.kernel.org, linux-kernel@...r.kernel.org,
Hou Wenlong <houwenlong.hwl@...group.com>, Kechen Lu <kechenl@...dia.com>,
Oliver Upton <oliver.upton@...ux.dev>, Binbin Wu
<binbin.wu@...ux.intel.com>, Yang Weijiang <weijiang.yang@...el.com>,
Robert Hoo <robert.hoo.linux@...il.com>
Subject: Re: [PATCH v2 25/49] KVM: x86: Harden CPU capabilities processing
against out-of-scope features
On Tue, 2024-07-09 at 11:11 -0700, Sean Christopherson wrote:
> On Thu, Jul 04, 2024, Maxim Levitsky wrote:
> > On Fri, 2024-05-17 at 10:39 -0700, Sean Christopherson wrote:
> > > +/*
> > > + * For kernel-defined leafs, mask the boot CPU's pre-populated value. For KVM-
> > > + * defined leafs, explicitly set the leaf, as KVM is the one and only authority.
> > > + */
> > > +#define kvm_cpu_cap_init(leaf, mask) \
> > > +do { \
> > > + const struct cpuid_reg cpuid = x86_feature_cpuid(leaf * 32); \
> > > + const u32 __maybe_unused kvm_cpu_cap_init_in_progress = leaf; \
> >
> > Why not to #define the kvm_cpu_cap_init_in_progress as well instead of a variable?
>
> Macros can't #define new macros. A macro could be used, but it would require the
> caller to #define and #undef the macro, e.g.
Oh, I somehow forgot about this, of course this is how C processor works.
> #define kvm_cpu_cap_init_in_progress CPUID_1_ECX
> kvm_cpu_cap_init(CPUID_1_ECX, ...)
> #undef kvm_cpu_cap_init_in_progress
>
Yes, this is much uglier.
> but, stating the obvious, that's ugly and is less robust than automatically
> "defining" the in-progress leaf in kvm_cpu_cap_init().
>
Best regards,
Maxim Levitsky
Powered by blists - more mailing lists