From: George Dunlap <george.dunlap@cloud.com>
To: Andrew Cooper <andrew.cooper3@citrix.com>
Cc: Xen-devel <xen-devel@lists.xenproject.org>,
"Jan Beulich" <JBeulich@suse.com>,
"Roger Pau Monné" <roger.pau@citrix.com>,
"Stefano Stabellini" <sstabellini@kernel.org>,
"Xenia Ragiadakou" <xenia.ragiadakou@amd.com>,
"Sergiy Kibrik" <Sergiy_Kibrik@epam.com>,
"Andrei Semenov" <andrei.semenov@vates.fr>,
"Vaishali Thakkar" <vaishali.thakkar@vates.tech>
Subject: Re: [PATCH 2/5] x86/cpu-policy: Add SVM features already used by Xen
Date: Wed, 1 May 2024 11:51:19 +0100 [thread overview]
Message-ID: <CA+zSX=aVb2znDf5XZ+04_vTD2aRPF8t4XoO9ZicYeU0_A2hsMQ@mail.gmail.com> (raw)
In-Reply-To: <c5efd98f-da49-414c-8427-8e4b2311f9bc@citrix.com>
On Wed, May 1, 2024 at 11:39 AM Andrew Cooper <andrew.cooper3@citrix.com> wrote:
>
> On 01/05/2024 11:00 am, George Dunlap wrote:
> > On Mon, Apr 29, 2024 at 4:16 PM Andrew Cooper <andrew.cooper3@citrix.com> wrote:
> >> These will replace svm_feature_flags and the SVM_FEATURE_* constants over the
> >> next few changes. Take the opportunity to rationalise some names.
> >>
> >> Drop the opencoded "inherit from host" logic in calculate_hvm_max_policy() and
> >> use 'h'/'!' annotations. The logic needs to operate on fs, not the policy
> >> object, given its position within the function.
> >>
> >> Drop some trailing whitespace introduced when this block of code was last
> >> moved.
> >>
> >> Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
> >> ---
> >> CC: Jan Beulich <JBeulich@suse.com>
> >> CC: Roger Pau Monné <roger.pau@citrix.com>
> >> CC: Stefano Stabellini <sstabellini@kernel.org>
> >> CC: Xenia Ragiadakou <xenia.ragiadakou@amd.com>
> >> CC: Sergiy Kibrik <Sergiy_Kibrik@epam.com>
> >> CC: George Dunlap <george.dunlap@citrix.com>
> >> CC: Andrei Semenov <andrei.semenov@vates.fr>
> >> CC: Vaishali Thakkar <vaishali.thakkar@vates.tech>
> >> ---
> >> tools/misc/xen-cpuid.c | 11 +++++++++++
> >> xen/arch/x86/cpu-policy.c | 17 +++++------------
> >> xen/include/public/arch-x86/cpufeatureset.h | 14 ++++++++++++++
> >> xen/tools/gen-cpuid.py | 3 +++
> >> 4 files changed, 33 insertions(+), 12 deletions(-)
> >>
> >> diff --git a/tools/misc/xen-cpuid.c b/tools/misc/xen-cpuid.c
> >> index ab09410a05d6..0d01b0e797f1 100644
> >> --- a/tools/misc/xen-cpuid.c
> >> +++ b/tools/misc/xen-cpuid.c
> >> @@ -266,6 +266,17 @@ static const char *const str_m10Ah[32] =
> >>
> >> static const char *const str_eAd[32] =
> >> {
> >> + [ 0] = "npt", [ 1] = "v-lbr",
> >> + [ 2] = "svm-lock", [ 3] = "nrips",
> >> + [ 4] = "v-tsc-rate", [ 5] = "vmcb-cleanbits",
> >> + [ 6] = "flush-by-asid", [ 7] = "decode-assist",
> >> +
> >> + [10] = "pause-filter",
> >> + [12] = "pause-thresh",
> >> + /* 14 */ [15] = "v-loadsave",
> >> + [16] = "v-gif",
> >> + /* 18 */ [19] = "npt-sss",
> >> + [20] = "v-spec-ctrl",
> >> };
> >>
> >> static const char *const str_e1Fa[32] =
> >> diff --git a/xen/arch/x86/cpu-policy.c b/xen/arch/x86/cpu-policy.c
> >> index 4b6d96276399..da4401047e89 100644
> >> --- a/xen/arch/x86/cpu-policy.c
> >> +++ b/xen/arch/x86/cpu-policy.c
> >> @@ -9,7 +9,6 @@
> >> #include <asm/amd.h>
> >> #include <asm/cpu-policy.h>
> >> #include <asm/hvm/nestedhvm.h>
> >> -#include <asm/hvm/svm/svm.h>
> >> #include <asm/intel-family.h>
> >> #include <asm/msr-index.h>
> >> #include <asm/paging.h>
> >> @@ -748,22 +747,16 @@ static void __init calculate_hvm_max_policy(void)
> >> if ( !cpu_has_vmx )
> >> __clear_bit(X86_FEATURE_PKS, fs);
> >>
> >> - /*
> >> + /*
> >> * Make adjustments to possible (nested) virtualization features exposed
> >> * to the guest
> >> */
> >> - if ( p->extd.svm )
> >> + if ( test_bit(X86_FEATURE_SVM, fs) )
> >> {
> >> - /* Clamp to implemented features which require hardware support. */
> >> - p->extd.raw[0xa].d &= ((1u << SVM_FEATURE_NPT) |
> >> - (1u << SVM_FEATURE_LBRV) |
> >> - (1u << SVM_FEATURE_NRIPS) |
> >> - (1u << SVM_FEATURE_PAUSEFILTER) |
> >> - (1u << SVM_FEATURE_DECODEASSISTS));
> >> - /* Enable features which are always emulated. */
> >> - p->extd.raw[0xa].d |= (1u << SVM_FEATURE_VMCBCLEAN);
> >> + /* Xen always emulates cleanbits. */
> >> + __set_bit(X86_FEATURE_VMCB_CLEANBITS, fs);
> >> }
> > What about this line, at the end of recalculate_cpuid_policy()?
> >
> > if ( !p->extd.svm )
> > p->extd.raw[0xa] = EMPTY_LEAF;
> >
> > Is there a reason to continue to operate directly on the policy here,
> > or would it be better to do this up in the featureset section?
>
> That's still needed.
>
> Otherwise in a !SVM VM you still see svm_rev and nr_asids in a leaf that
> should be all zeroes.
...Uh, yes of course we still need to clear the non-existent CPUID
bits. I was asking if we should change *how* we should clear them.
In the hunk I responded to, when enabling VMCBCLEAN, we switch from
setting bits in the policy, to setting bits in the featureset. I was
asking whether it would make sense to do something like
if !test_bit(X86_FEATURE_SVM, fs)
fs[FEATURESET_eAd] = 0;
before the x86_cpu_featureset_to_policy() instead.
-George
next prev parent reply other threads:[~2024-05-01 10:51 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-29 15:16 [PATCH 0/5] x86: AMD CPUID handling improvements Andrew Cooper
2024-04-29 15:16 ` [PATCH 1/5] x86/cpu-policy: Infrastructure for the AMD SVM and SEV leaves Andrew Cooper
2024-04-30 12:45 ` Jan Beulich
2024-04-30 13:25 ` Andrew Cooper
2024-04-30 13:33 ` Jan Beulich
2024-05-01 9:16 ` George Dunlap
2024-04-29 15:16 ` [PATCH 2/5] x86/cpu-policy: Add SVM features already used by Xen Andrew Cooper
2024-04-29 15:24 ` Andrew Cooper
2024-04-30 13:02 ` Jan Beulich
2024-05-01 10:00 ` George Dunlap
2024-05-01 10:39 ` Andrew Cooper
2024-05-01 10:51 ` George Dunlap [this message]
2024-04-29 15:16 ` [PATCH 3/5] x86/spec-ctrl: Remove open-coded check of SVM_FEATURE_SPEC_CTRL Andrew Cooper
2024-04-30 13:13 ` Jan Beulich
2024-04-29 15:16 ` [PATCH 4/5] x86/svm: Switch SVM features over normal cpu_has_* Andrew Cooper
2024-04-30 5:51 ` Vaishali Thakkar
2024-04-30 13:25 ` Jan Beulich
2024-04-29 15:16 ` [PATCH 5/5] x86/cpu-policy: Introduce some SEV features Andrew Cooper
2024-04-30 6:15 ` Vaishali Thakkar
2024-04-30 13:54 ` Jan Beulich
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='CA+zSX=aVb2znDf5XZ+04_vTD2aRPF8t4XoO9ZicYeU0_A2hsMQ@mail.gmail.com' \
--to=george.dunlap@cloud.com \
--cc=JBeulich@suse.com \
--cc=Sergiy_Kibrik@epam.com \
--cc=andrei.semenov@vates.fr \
--cc=andrew.cooper3@citrix.com \
--cc=roger.pau@citrix.com \
--cc=sstabellini@kernel.org \
--cc=vaishali.thakkar@vates.tech \
--cc=xen-devel@lists.xenproject.org \
--cc=xenia.ragiadakou@amd.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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).