Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp234734pxf; Thu, 8 Apr 2021 01:39:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzvE3RCsV2QQtuCqB/sjQYbLmLSFa2RFrXPITRqbDo+RkdB3PdY6jrlW0s2c0ywJM4LJ1K0 X-Received: by 2002:aa7:d88b:: with SMTP id u11mr9877965edq.254.1617871197087; Thu, 08 Apr 2021 01:39:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617871197; cv=none; d=google.com; s=arc-20160816; b=DwYWILa+/klt+dGvez/pB4KawSxLZAqBK1wRT+XeLNjfVIfhU/V3bW6toKk0/uPCmB Z8TQuOVBfY5Iox3S8dUpt4u1b+DsUUqWeP6ojg7iKyY3jyyAXsHeXRb/3QJs6XTiPj6o r6meZ1qIQphYqIw3dNmyqZVGUSN54LNBIfbUZsUWA6opAc1NkIODYakVqrSTUIBocwOx 3CQ6JKIq0jwc3KU6wGibw0+IQAz3xQGy5OnP4dTtykfXHitbGGtFWn03ENWNO3hGITlm rN5XnNf4I0BDjNc1JTXiPy6fhdqNBcERhRJnl54Hpj97NCpDjylTk3JVZR7m3hia5SQ+ /4Vw== 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=Kxh8yxt419FOMUzcjS1sp7cQfN4dfxrZXCO9G9/LPLs=; b=oSPAiQnbpc7FhyHOAKh4FdVs1b3ol8esXhlZrWmGh7s4f/8vuTHFZZ9QxWtvIMflDa EQKDqu4+R9IWChBhCK5S+Bj/4AcSrB2KO0328Xcj3BcqQUWIp/va9Rb/0BOIsGDEQB0b y7XKg87RzMCi0mxS8A+eT/TWTZXAXOZUpZ9VYxIYlz9f2lds2D7CamGvfkqCMT0GZHII d+9Bd3CPETHnPSS1yJteQ9Uh5lccdz4daAbErf6B9R+S2y4GJoqJx3uIJ2uATvt9VqRC Hbv6WfJXH76u4//LXCp3MYB10KWo6yWgkGspAmChdAtvA90itrz5M6HZpQ+j4eIDX3Co pNOw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@alien8.de header.s=dkim header.b=o0qqxJ1J; 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 u19si13987744edi.94.2021.04.08.01.39.34; Thu, 08 Apr 2021 01:39:57 -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=o0qqxJ1J; 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 S230213AbhDHIic (ORCPT + 99 others); Thu, 8 Apr 2021 04:38:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59238 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229539AbhDHIib (ORCPT ); Thu, 8 Apr 2021 04:38:31 -0400 Received: from mail.skyhub.de (mail.skyhub.de [IPv6:2a01:4f8:190:11c2::b:1457]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6A871C061760; Thu, 8 Apr 2021 01:38:20 -0700 (PDT) Received: from zn.tnic (p200300ec2f095000c11580856fe05acf.dip0.t-ipconnect.de [IPv6:2003:ec:2f09:5000:c115:8085:6fe0:5acf]) (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 E1B411EC03CE; Thu, 8 Apr 2021 10:38:14 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=alien8.de; s=dkim; t=1617871095; 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=Kxh8yxt419FOMUzcjS1sp7cQfN4dfxrZXCO9G9/LPLs=; b=o0qqxJ1JzVVmPhtCc06e0Zs3ccsPt4yTLpjUArkfRalbVy1cLaYahJ87Afn48n8rubLeph 6DXjUkomsf0u3V3kHLdcQPFJx0eaPFcwq0rTRMh0IUByxsQ8zg+VUpyhVF+TsCtZ1OH1sw qc4lR7F8T9uFhD1ppYMAOhnAsZM81+w= Date: Thu, 8 Apr 2021 10:38:14 +0200 From: Borislav Petkov To: Brijesh Singh Cc: linux-kernel@vger.kernel.org, x86@kernel.org, kvm@vger.kernel.org, ak@linux.intel.com, Thomas Gleixner , Ingo Molnar , Joerg Roedel , "H. Peter Anvin" , Tony Luck , Dave Hansen , "Peter Zijlstra (Intel)" , Paolo Bonzini , Tom Lendacky , David Rientjes , Sean Christopherson Subject: Re: [RFC Part1 PATCH 08/13] x86/sev-es: register GHCB memory when SEV-SNP is active Message-ID: <20210408083814.GB10192@zn.tnic> References: <20210324164424.28124-1-brijesh.singh@amd.com> <20210324164424.28124-9-brijesh.singh@amd.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20210324164424.28124-9-brijesh.singh@amd.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Mar 24, 2021 at 11:44:19AM -0500, Brijesh Singh wrote: > @@ -88,6 +89,13 @@ struct sev_es_runtime_data { > * is currently unsupported in SEV-ES guests. > */ > unsigned long dr7; > + > + /* > + * SEV-SNP requires that the GHCB must be registered before using it. > + * The flag below will indicate whether the GHCB is registered, if its > + * not registered then sev_es_get_ghcb() will perform the registration. > + */ > + bool ghcb_registered; snp_ghcb_registered because it is SNP-specific. > }; > > struct ghcb_state { > @@ -196,6 +204,12 @@ static __always_inline struct ghcb *sev_es_get_ghcb(struct ghcb_state *state) > data->ghcb_active = true; > } > > + /* SEV-SNP guest requires that GHCB must be registered before using it. */ > + if (sev_snp_active() && !data->ghcb_registered) { > + sev_snp_register_ghcb(__pa(ghcb)); > + data->ghcb_registered = true; This needs to be set to true in the function itself, in the success case. > +static inline u64 sev_es_rd_ghcb_msr(void) > +{ > + return __rdmsr(MSR_AMD64_SEV_ES_GHCB); > +} > + > +static inline void sev_es_wr_ghcb_msr(u64 val) > +{ > + u32 low, high; > + > + low = (u32)(val); > + high = (u32)(val >> 32); > + > + native_wrmsr(MSR_AMD64_SEV_ES_GHCB, low, high); > +} Those copies will go away once you create the common sev.c > + > +/* Provides sev_es_terminate() */ > +#include "sev-common-shared.c" > + > +void sev_snp_register_ghcb(unsigned long paddr) > +{ > + u64 pfn = paddr >> PAGE_SHIFT; > + u64 old, val; > + > + /* save the old GHCB MSR */ > + old = sev_es_rd_ghcb_msr(); > + > + /* Issue VMGEXIT */ > + sev_es_wr_ghcb_msr(GHCB_REGISTER_GPA_REQ_VAL(pfn)); > + VMGEXIT(); > + > + val = sev_es_rd_ghcb_msr(); > + > + /* If the response GPA is not ours then abort the guest */ > + if ((GHCB_SEV_GHCB_RESP_CODE(val) != GHCB_REGISTER_GPA_RESP) || > + (GHCB_REGISTER_GPA_RESP_VAL(val) != pfn)) > + sev_es_terminate(GHCB_SEV_ES_REASON_GENERAL_REQUEST); > + > + /* Restore the GHCB MSR value */ > + sev_es_wr_ghcb_msr(old); > +} This is an almost identical copy of the version in compressed/. Move to the shared file? Thx. -- Regards/Gruss, Boris. https://people.kernel.org/tglx/notes-about-netiquette