Re: [PATCH] x86/coco, x86/sev: Use cpu_feature_enabled() to detect SEV guest flavor

From: Borislav Petkov
Date: Tue Jan 02 2024 - 07:30:48 EST


On Tue, Jan 02, 2024 at 03:22:33PM +0300, Kirill A. Shutemov wrote:
> On Tue, Dec 05, 2023 at 09:33:37PM +0100, Borislav Petkov wrote:
> > On Tue, Dec 05, 2023 at 07:52:41PM +0100, Borislav Petkov wrote:
> > > So yes, we will fix your issue, no worries. I'm figuring out the
> > > details as we speak.
> >
> > So you can do for the short term:
> >
> > ---
> > diff --git a/arch/x86/kernel/kvm.c b/arch/x86/kernel/kvm.c
> > index c461c1a4b6af..f8999f6d1b00 100644
> > --- a/arch/x86/kernel/kvm.c
> > +++ b/arch/x86/kernel/kvm.c
> > @@ -434,7 +434,7 @@ static void __init sev_map_percpu_data(void)
> > {
> > int cpu;
> >
> > - if (!cc_platform_has(CC_ATTR_GUEST_MEM_ENCRYPT))
> > + if (cc_vendor != CC_VENDOR_AMD || !cc_platform_has(CC_ATTR_GUEST_MEM_ENCRYPT))
> > return;
> >
> > for_each_possible_cpu(cpu) {
> > ---
> >
> > until we've sorted out the bigger picture.
>
> So, there seems no movement on the issue.
>
> Borislav, could you share your view on the bigger picture. I can try to
> implement it.

cc_platform_has() gets used in arch-agnostic code.

x86 code can use cc_platform_has() or X86_FEATURE as TDX already does.
In the AMD case, cc_platform_has() makes more sense because we need
sev_status which is much earlier there than X86_FEATURE.

So the only thing to "implement" is to check vendor in
sev_map_percpu_data() as mentioned above.

Thx.

--
Regards/Gruss,
Boris.

https://people.kernel.org/tglx/notes-about-netiquette