From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7F30BC433EF for ; Fri, 25 Mar 2022 09:24:59 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id ECDFC6B0071; Fri, 25 Mar 2022 05:24:58 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E56D96B0073; Fri, 25 Mar 2022 05:24:58 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CAA176B0074; Fri, 25 Mar 2022 05:24:58 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0208.hostedemail.com [216.40.44.208]) by kanga.kvack.org (Postfix) with ESMTP id B4C386B0071 for ; Fri, 25 Mar 2022 05:24:58 -0400 (EDT) Received: from smtpin27.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 6D5FC9EB29 for ; Fri, 25 Mar 2022 09:24:58 +0000 (UTC) X-FDA: 79282374276.27.77832D7 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by imf24.hostedemail.com (Postfix) with ESMTP id BE590180017 for ; Fri, 25 Mar 2022 09:24:57 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 250B01F745; Fri, 25 Mar 2022 09:24:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1648200296; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=dvN7myr0MDfmtMFkdZ1k/72coAzlBsKoPtLN6KtQ1CQ=; b=v7ByO0o1ZIbFE5mwJyFIHpW2wINXiMWRB8n9NTThT5QJklwm6VB3tMgmaRuw+BNeQ0mIaN Jra5pct2F+ssPqGHTFKPmuvlUlbIXuuHfP7ZhD13c++eR5WgQH6r+oHxYAsW3qQmYfS9EK fRwHZZabz/9vqllHvpg8l/abeRokoCA= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1648200296; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=dvN7myr0MDfmtMFkdZ1k/72coAzlBsKoPtLN6KtQ1CQ=; b=QRumQzO+afwTgRwYz9SpOF+rQLK40HkIs3BRJSzs/Q2UZ3AYLDcTAHwYgb+zNjJPFOPBGT mt53x2Wzp/5juLAQ== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 12EAE132E9; Fri, 25 Mar 2022 09:24:56 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id TmabBGiKPWIRfwAAMHmgww (envelope-from ); Fri, 25 Mar 2022 09:24:56 +0000 Date: Fri, 25 Mar 2022 10:24:50 +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 , Borislav Petkov , Michael Roth , Vlastimil Babka , "Kirill A . Shutemov" , Andi Kleen , "Dr . David Alan Gilbert" , brijesh.ksingh@gmail.com, tony.luck@intel.com, marcorr@google.com, sathyanarayanan.kuppuswamy@linux.intel.com Subject: Re: [PATCH v12 40/46] x86/sev: add sev=debug cmdline option to dump SNP CPUID table Message-ID: References: <20220307213356.2797205-1-brijesh.singh@amd.com> <20220307213356.2797205-41-brijesh.singh@amd.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20220307213356.2797205-41-brijesh.singh@amd.com> X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: BE590180017 X-Rspam-User: Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=v7ByO0o1; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=QRumQzO+; dmarc=pass (policy=none) header.from=suse.de; spf=pass (imf24.hostedemail.com: domain of bp@suse.de designates 195.135.220.29 as permitted sender) smtp.mailfrom=bp@suse.de X-Stat-Signature: tge15tt4koqwjn3ntawynjbzcw8y6ub7 X-HE-Tag: 1648200297-399632 Content-Transfer-Encoding: quoted-printable X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Mon, Mar 07, 2022 at 03:33:50PM -0600, Brijesh Singh wrote: > From: Michael Roth >=20 > For debugging purposes it is very useful to have a way to see the full > contents of the SNP CPUID table provided to a guest. Add an sev=3Ddebug > kernel command-line option to do so. >=20 > Also introduce some infrastructure so that additional options can be > specified via sev=3Doption1[,option2] over time in a consistent manner. >=20 > Suggested-by: Borislav Petkov > Signed-off-by: Michael Roth > --- > .../admin-guide/kernel-parameters.txt | 2 + > Documentation/x86/x86_64/boot-options.rst | 14 +++++ > arch/x86/kernel/sev.c | 58 +++++++++++++++++++ > 3 files changed, 74 insertions(+) I simplified the string parsing: --- From: Michael Roth Date: Mon, 7 Mar 2022 15:33:50 -0600 Subject: [PATCH] x86/sev: Add a sev=3D cmdline option For debugging purposes it is very useful to have a way to see the full contents of the SNP CPUID table provided to a guest. Add an sev=3Ddebug kernel command-line option to do so. Also introduce some infrastructure so that additional options can be specified via sev=3Doption1[,option2] over time in a consistent manner. [ bp: Massage, simplify string parsing. ] Suggested-by: Borislav Petkov Signed-off-by: Michael Roth Signed-off-by: Borislav Petkov Link: https://lore.kernel.org/r/20220307213356.2797205-41-brijesh.singh@a= md.com --- .../admin-guide/kernel-parameters.txt | 2 + Documentation/x86/x86_64/boot-options.rst | 14 ++++++ arch/x86/kernel/sev.c | 44 +++++++++++++++++++ 3 files changed, 60 insertions(+) diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentat= ion/admin-guide/kernel-parameters.txt index 7123524a86b8..5f7fa7c141dc 100644 --- a/Documentation/admin-guide/kernel-parameters.txt +++ b/Documentation/admin-guide/kernel-parameters.txt @@ -5229,6 +5229,8 @@ =20 serialnumber [BUGS=3DX86-32] =20 + sev=3Doption[,option...] [X86-64] See Documentation/x86/x86_64/boot-opt= ions.rst + shapers=3D [NET] Maximal number of shapers. =20 diff --git a/Documentation/x86/x86_64/boot-options.rst b/Documentation/x8= 6/x86_64/boot-options.rst index ccb7e86bf8d9..eaecb5d89167 100644 --- a/Documentation/x86/x86_64/boot-options.rst +++ b/Documentation/x86/x86_64/boot-options.rst @@ -317,3 +317,17 @@ Miscellaneous Do not use GB pages for kernel direct mappings. gbpages Use GB pages for kernel direct mappings. + + +AMD SEV (Secure Encrypted Virtualization) +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D +Options relating to AMD SEV, specified via the following format: + +:: + + sev=3Doption1[,option2] + +The available options are: + + debug + Enable debug messages. diff --git a/arch/x86/kernel/sev.c b/arch/x86/kernel/sev.c index c8733725d8bf..70ecc6e2f251 100644 --- a/arch/x86/kernel/sev.c +++ b/arch/x86/kernel/sev.c @@ -112,6 +112,13 @@ DEFINE_STATIC_KEY_FALSE(sev_es_enable_key); =20 static DEFINE_PER_CPU(struct sev_es_save_area *, sev_vmsa); =20 +struct sev_config { + __u64 debug : 1, + __reserved : 63; +}; + +static struct sev_config sev_cfg __read_mostly; + static __always_inline bool on_vc_stack(struct pt_regs *regs) { unsigned long sp =3D regs->sp; @@ -2042,6 +2049,23 @@ void __init snp_abort(void) sev_es_terminate(SEV_TERM_SET_GEN, GHCB_SNP_UNSUPPORTED); } =20 +static void dump_cpuid_table(void) +{ + const struct snp_cpuid_table *cpuid_table =3D snp_cpuid_get_table(); + int i =3D 0; + + pr_info("count=3D%d reserved=3D0x%x reserved2=3D0x%llx\n", + cpuid_table->count, cpuid_table->__reserved1, cpuid_table->__reserved2= ); + + for (i =3D 0; i < SNP_CPUID_COUNT_MAX; i++) { + const struct snp_cpuid_fn *fn =3D &cpuid_table->fn[i]; + + pr_info("index=3D%3d fn=3D0x%08x subfn=3D0x%08x: eax=3D0x%08x ebx=3D0x= %08x ecx=3D0x%08x edx=3D0x%08x xcr0_in=3D0x%016llx xss_in=3D0x%016llx res= erved=3D0x%016llx\n", + i, fn->eax_in, fn->ecx_in, fn->eax, fn->ebx, fn->ecx, + fn->edx, fn->xcr0_in, fn->xss_in, fn->__reserved); + } +} + /* * It is useful from an auditing/testing perspective to provide an easy = way * for the guest owner to know that the CPUID table has been initialized= as @@ -2059,6 +2083,26 @@ static int __init report_cpuid_table(void) pr_info("Using SNP CPUID table, %d entries present.\n", cpuid_table->count); =20 + if (sev_cfg.debug) + dump_cpuid_table(); + return 0; } arch_initcall(report_cpuid_table); + +static int __init init_sev_config(char *str) +{ + char *s; + + while ((s =3D strsep(&str, ","))) { + if (!strcmp(s, "debug")) { + sev_cfg.debug =3D true; + continue; + } + + pr_info("SEV command-line option '%s' was not recognized\n", s); + } + + return 1; +} +__setup("sev=3D", init_sev_config); --=20 2.35.1 --=20 Regards/Gruss, Boris. SUSE Software Solutions Germany GmbH, GF: Ivo Totev, HRB 36809, AG N=C3=BC= rnberg