Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp1269950pxb; Fri, 21 Jan 2022 13:57:37 -0800 (PST) X-Google-Smtp-Source: ABdhPJymuGKp1bGShKXWXYG6lKIKdXPm02S+UTvJ2diIvpZqcLrC1enszPOMfvJFXrGILHaCU7VR X-Received: by 2002:a17:90b:3841:: with SMTP id nl1mr2633627pjb.60.1642802257061; Fri, 21 Jan 2022 13:57:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1642802257; cv=none; d=google.com; s=arc-20160816; b=jC+/S0Qxkwm2rc0MjLPt0JjqYQcl9TgR3k4tsTnMjEoolR724I4ifBLm2QS1c9iUnD Pbsz2Ihfxj3OmygKUKcH67AHDeb+wife9yNivpxpq1B8F6wYGvUOqAZvPJuGEYClKJne qhBl7l6rb2cc1LpZhpsamyWoOA0hJTtud8epM0yNZoT6DZ9eTiQNvdgCMWkNvs7LJCtk IC+McHJidXaCYB8irdmiT70+2ZmwWQ2ZU3g1KB8SsywN4F5cxDNT5b42c9DEawC34awU ygFP8U2rjadoVKNejGyIl1gVLvselsAhs4sn3K+nsg1Eg/0P/2I2tZ7oI2DaSs2BR1zG FaVA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=XO6AT+gIfZtH9EDaR1V0c6Fkovljr0vEcHMLtYZNXi0=; b=klNSdYFfRpekiPNBlUYgjCCGWLraRaSpt7TaPwEMNCBlb5dRW6qv3InGTGx2YOU9IW VDjWrsMilJh+l2B9dZ2ElYTIu80kXG0dE3cbUhII090LwJY/lzXKvKvMPkZfbUPEAvRC PhJ8uXj5tx90bhRJdL5x6B18z99IW+y04Dx6I9mmBHwfH5xwdI6Iw4AlcoWn1M9v2eZk e411YR0lkk6tGoKOCXJGvS6cKB2zVfI605WFj6xjv8wKJgjwQjqubEtwZSX73nUiVvKD GCAIE0n+OExrF/7kmPCQHoWv0SvZptJOWhqdVnOGu2+OxLldk8s0c0kBsBm802hepJIq qGoQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@alien8.de header.s=dkim header.b=ZvS9JkdJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=alien8.de Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id j3si6887913pll.394.2022.01.21.13.57.25; Fri, 21 Jan 2022 13:57:37 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@alien8.de header.s=dkim header.b=ZvS9JkdJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=alien8.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241341AbiATMSg (ORCPT + 99 others); Thu, 20 Jan 2022 07:18:36 -0500 Received: from mail.skyhub.de ([5.9.137.197]:44738 "EHLO mail.skyhub.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237697AbiATMSe (ORCPT ); Thu, 20 Jan 2022 07:18:34 -0500 Received: from zn.tnic (dslb-088-067-202-008.088.067.pools.vodafone-ip.de [88.67.202.8]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.skyhub.de (SuperMail on ZX Spectrum 128k) with ESMTPSA id A0B6F1EC01B5; Thu, 20 Jan 2022 13:18:28 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=alien8.de; s=dkim; t=1642681108; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:in-reply-to:in-reply-to: references:references; bh=XO6AT+gIfZtH9EDaR1V0c6Fkovljr0vEcHMLtYZNXi0=; b=ZvS9JkdJCYllJDFBD0tsEGn3u9iKtDu9RRyiFn28RlB9ttb3/cSuVBse0GV9xDiAmJXru1 G7WhLPYYU8EKqnivp/dBPCdF6YYQ7q3y6G8vJIsVo2jZaCOyhOigOuYlQCmxRcEn/trNns hHEBxqnny4SO9CJxR0abXyH3IFJubqs= Date: Thu, 20 Jan 2022 13:18:22 +0100 From: Borislav Petkov To: Brijesh Singh Cc: x86@kernel.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, linux-efi@vger.kernel.org, platform-driver-x86@vger.kernel.org, linux-coco@lists.linux.dev, linux-mm@kvack.org, Thomas Gleixner , Ingo Molnar , Joerg Roedel , Tom Lendacky , "H. Peter Anvin" , Ard Biesheuvel , Paolo Bonzini , Sean Christopherson , Vitaly Kuznetsov , Jim Mattson , Andy Lutomirski , Dave Hansen , Sergio Lopez , Peter Gonda , Peter Zijlstra , Srinivas Pandruvada , David Rientjes , Dov Murik , Tobin Feldman-Fitzthum , Michael Roth , Vlastimil Babka , "Kirill A . Shutemov" , Andi Kleen , "Dr . David Alan Gilbert" , tony.luck@intel.com, marcorr@google.com, sathyanarayanan.kuppuswamy@linux.intel.com Subject: Re: [PATCH v8 32/40] x86/compressed: use firmware-validated CPUID for SEV-SNP guests Message-ID: References: <20211210154332.11526-1-brijesh.singh@amd.com> <20211210154332.11526-33-brijesh.singh@amd.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20211210154332.11526-33-brijesh.singh@amd.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Dec 10, 2021 at 09:43:24AM -0600, Brijesh Singh wrote: > Subject: Re: [PATCH v8 32/40] x86/compressed: use firmware-validated CPUID for SEV-SNP guests ^ leafs or so. > From: Michael Roth > > SEV-SNP guests will be provided the location of special 'secrets' > 'CPUID' pages via the Confidential Computing blob. This blob is > provided to the boot kernel either through an EFI config table entry, > or via a setup_data structure as defined by the Linux Boot Protocol. > > Locate the Confidential Computing from these sources and, if found, > use the provided CPUID page/table address to create a copy that the > boot kernel will use when servicing cpuid instructions via a #VC CPUID > handler. > > Signed-off-by: Michael Roth > Signed-off-by: Brijesh Singh > --- > arch/x86/boot/compressed/sev.c | 13 ++++++++++ > arch/x86/include/asm/sev.h | 1 + > arch/x86/kernel/sev-shared.c | 43 ++++++++++++++++++++++++++++++++++ > 3 files changed, 57 insertions(+) > > diff --git a/arch/x86/boot/compressed/sev.c b/arch/x86/boot/compressed/sev.c > index 93e125da12cf..29dfb34b5907 100644 > --- a/arch/x86/boot/compressed/sev.c > +++ b/arch/x86/boot/compressed/sev.c > @@ -415,6 +415,19 @@ bool snp_init(struct boot_params *bp) > if (!cc_info) > return false; > > + /* > + * If SEV-SNP-specific Confidential Computing blob is present, then ^ a > + * firmware/bootloader have indicated SEV-SNP support. Verifying this > + * involves CPUID checks which will be more reliable if the SEV-SNP > + * CPUID table is used. See comments for snp_cpuid_info_create() for s/for/over/ ? > + * more details. > + */ > + snp_cpuid_info_create(cc_info); > + > + /* SEV-SNP CPUID table should be set up now. */ > + if (!snp_cpuid_active()) > + sev_es_terminate(1, GHCB_TERM_CPUID); Right, that is not needed now. > * Pass run-time kernel a pointer to CC info via boot_params so EFI > * config table doesn't need to be searched again during early startup > diff --git a/arch/x86/include/asm/sev.h b/arch/x86/include/asm/sev.h > index cd189c20bcc4..4fa7ca20d7c9 100644 > --- a/arch/x86/include/asm/sev.h > +++ b/arch/x86/include/asm/sev.h > @@ -157,6 +157,7 @@ bool snp_init(struct boot_params *bp); > * sev-shared.c via #include and these declarations can be dropped. > */ > struct cc_blob_sev_info *snp_find_cc_blob_setup_data(struct boot_params *bp); > +void snp_cpuid_info_create(const struct cc_blob_sev_info *cc_info); > #else > static inline void sev_es_ist_enter(struct pt_regs *regs) { } > static inline void sev_es_ist_exit(void) { } > diff --git a/arch/x86/kernel/sev-shared.c b/arch/x86/kernel/sev-shared.c > index bd58a4ce29c8..5cb8f87df4b3 100644 > --- a/arch/x86/kernel/sev-shared.c > +++ b/arch/x86/kernel/sev-shared.c > @@ -403,6 +403,23 @@ snp_cpuid_find_validated_func(u32 func, u32 subfunc, u32 *eax, u32 *ebx, > return false; > } > > +static void __init snp_cpuid_set_ranges(void) > +{ > + const struct snp_cpuid_info *cpuid_info = snp_cpuid_info_get_ptr(); > + int i; > + > + for (i = 0; i < cpuid_info->count; i++) { > + const struct snp_cpuid_fn *fn = &cpuid_info->fn[i]; > + > + if (fn->eax_in == 0x0) > + cpuid_std_range_max = fn->eax; > + else if (fn->eax_in == 0x40000000) > + cpuid_hyp_range_max = fn->eax; > + else if (fn->eax_in == 0x80000000) > + cpuid_ext_range_max = fn->eax; > + } > +} Kinda arbitrary to have a separate function which has a single caller. You can just as well move the loop into snp_cpuid_info_create() and put a comment above it: /* Set CPUID ranges. */ for (i = 0; i < cpuid_info->count; i++) { ... Also, snp_cpuid_info_create() should be called snp_setup_cpuid_table() which is what this thing does. Thx. -- Regards/Gruss, Boris. https://people.kernel.org/tglx/notes-about-netiquette