Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp3063407pxb; Mon, 18 Oct 2021 07:32:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzNPq9hCfSXkUkfzS5uFLXqf9D7MW5ZDC2O7VwpX7xOp6NnwaeYyUvL7fAsQYPLEZ8m+Owr X-Received: by 2002:a17:906:4793:: with SMTP id cw19mr28606843ejc.200.1634567551333; Mon, 18 Oct 2021 07:32:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634567551; cv=none; d=google.com; s=arc-20160816; b=WcRsSn/EEMNr95u6er3D8FPujjHbrSKhNg0pShiJQrQ943qAD698pYghkBswmlPzCe BPfDS6pWOcdF33vH/YdWiBvpzmK5Idpia8Ttt/DKaZ1InNi2yrUYq4QbnabSzv5fpQoS iR236UVfVu9GHlHEokiSSnpiybY4Y7bqg7vIODj1XmgQoVqm+KAbHLBDaUdshCl7wXW3 M7TXPe06SqCtp177DOIYbkZwFnZ5WDp/1PmmMvFdBfbDLyD2AE+CRjJWk2EFWajLNuVt aZQ4efpF7pPDYjsb2VVq8wj2e64GE2hC2qKjHdNH/V5QuIwsTyahMQwsK38m0mf6uHnx BSsg== 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=c9xEu9dyx4wrnGD++qak7Rf0JfD9ujFQ9E5yOZB19Q0=; b=0L5TVbV6RQvLTAhBAa2Efgnj1J5m0v58jIfeNmdW47jN5gtHVFImec8zab7ou0JEGR ro29cJXKNo3N509r2maUVpBrugdgEnQvL7MaOi/VF0g0bLzxnyFhRMJ3T3DZtlRsBWFy XJxcdpDQcZ5dz20EXzskc0ABwG+NowUhjjC+C8SrOlCLu5l2EafOfmDB2cL0eMVWGjRs mDvDJVOZYwKuGbrIfm8P8oLOVQSYHdL3RRFbmSmIkaewtZHsJnyEhZxLmTQQ43hL7RiH lhNBRxUcIRiIkKzLEiq4ntjrgVy+daJErksN11n+VzLOMNshwozb1hnl27Z2sSCwhaeo Mu+g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@alien8.de header.s=dkim header.b=aKWwYTlr; 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 s22si18416658edq.81.2021.10.18.07.32.07; Mon, 18 Oct 2021 07:32:31 -0700 (PDT) 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=aKWwYTlr; 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 S232277AbhJRObz (ORCPT + 99 others); Mon, 18 Oct 2021 10:31:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48364 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232260AbhJRObj (ORCPT ); Mon, 18 Oct 2021 10:31:39 -0400 Received: from mail.skyhub.de (mail.skyhub.de [IPv6:2a01:4f8:190:11c2::b:1457]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8CFADC06176D; Mon, 18 Oct 2021 07:29:09 -0700 (PDT) Received: from zn.tnic (p200300ec2f085700a5f06031787ecc0a.dip0.t-ipconnect.de [IPv6:2003:ec:2f08:5700:a5f0:6031:787e:cc0a]) (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 D2FC91EC04C2; Mon, 18 Oct 2021 16:29:07 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=alien8.de; s=dkim; t=1634567347; 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=c9xEu9dyx4wrnGD++qak7Rf0JfD9ujFQ9E5yOZB19Q0=; b=aKWwYTlr9cCQu7ia5dZP/kuxrxzN93CyPBgOxttie/QBj3Td/GyHk64AiEAbXaIbAsIGqx BgGTrkPaemD3IjwBuWI2GydbibFzG2kuXi6yqjHnJLtsSpqF8n17AX6r45/y+wPNjuoNcV Bkj7MRJet38z0l3P6cMLUbOfmJ1xF50= Date: Mon, 18 Oct 2021 16:29:07 +0200 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 v6 08/42] x86/sev-es: initialize sev_status/features within #VC handler Message-ID: References: <20211008180453.462291-1-brijesh.singh@amd.com> <20211008180453.462291-9-brijesh.singh@amd.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20211008180453.462291-9-brijesh.singh@amd.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Oct 08, 2021 at 01:04:19PM -0500, Brijesh Singh wrote: > From: Michael Roth > > Generally access to MSR_AMD64_SEV is only safe if the 0x8000001F CPUID > leaf indicates SEV support. With SEV-SNP, CPUID responses from the > hypervisor are not considered trustworthy, particularly for 0x8000001F. > SEV-SNP provides a firmware-validated CPUID table to use as an > alternative, but prior to checking MSR_AMD64_SEV there are no > guarantees that this is even an SEV-SNP guest. > > Rather than relying on these CPUID values early on, allow SEV-ES and > SEV-SNP guests to instead use a cpuid instruction to trigger a #VC and > have it cache MSR_AMD64_SEV in sev_status, since it is known to be safe > to access MSR_AMD64_SEV if a #VC has triggered. > > Signed-off-by: Michael Roth > Signed-off-by: Brijesh Singh > --- > arch/x86/kernel/sev-shared.c | 14 ++++++++++++++ > 1 file changed, 14 insertions(+) > > diff --git a/arch/x86/kernel/sev-shared.c b/arch/x86/kernel/sev-shared.c > index 8ee27d07c1cd..2796c524d174 100644 > --- a/arch/x86/kernel/sev-shared.c > +++ b/arch/x86/kernel/sev-shared.c > @@ -191,6 +191,20 @@ void __init do_vc_no_ghcb(struct pt_regs *regs, unsigned long exit_code) > if (exit_code != SVM_EXIT_CPUID) > goto fail; > > + /* > + * A #VC implies that either SEV-ES or SEV-SNP are enabled, so the SEV > + * MSR is also available. Go ahead and initialize sev_status here to > + * allow SEV features to be checked without relying solely on the SEV > + * cpuid bit to indicate whether it is safe to do so. > + */ > + if (!sev_status) { > + unsigned long lo, hi; > + > + asm volatile("rdmsr" : "=a" (lo), "=d" (hi) > + : "c" (MSR_AMD64_SEV)); > + sev_status = (hi << 32) | lo; > + } > + > sev_es_wr_ghcb_msr(GHCB_CPUID_REQ(fn, GHCB_CPUID_REQ_EAX)); > VMGEXIT(); > val = sev_es_rd_ghcb_msr(); > -- Ok, you guys are killing me. ;-\ How is bolting some pretty much unrelated code into the early #VC handler not a hack? Do you not see it? So sme_enable() is reading MSR_AMD64_SEV and setting up everything there, including sev_status. If a SNP guest does not trust CPUID, why can't you attempt to read that MSR there, even if CPUID has lied to the guest? And not just slap it somewhere just because it works? -- Regards/Gruss, Boris. https://people.kernel.org/tglx/notes-about-netiquette