Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp5010507rwb; Wed, 17 Aug 2022 09:28:40 -0700 (PDT) X-Google-Smtp-Source: AA6agR5jgSV+ReQfIt+0XI1apc1iV04qwN8LZfouQDkCvMAUZIiGUHEpKj/NXYkqrDJtlMYux85Q X-Received: by 2002:a17:907:d07:b0:72e:ec79:ad0f with SMTP id gn7-20020a1709070d0700b0072eec79ad0fmr17565856ejc.296.1660753720401; Wed, 17 Aug 2022 09:28:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660753720; cv=none; d=google.com; s=arc-20160816; b=Ru3iNTTo5juK6R/bgRgtLJR9AGgD6xNjBw0mvVGWygn6YpUPBTpcYT8ariu8zhHSf3 VH1Ab4g7Mpsnw3vfdqq2CbsNUqvlS0mB+NlicvBxBavIZ8iVB1TmVt2fjFOd+mwSFXpl uddJXp9J8LACw8Zrv9whMF0dYLSW+wxizYNbNzJ7kO+p2tCqSXl6GdTPDXWLih6UfRx6 ApU5HxZDugfufpnnS/yq9NwK2FWegN5Xs0hhE7tb5AVlxwYuS6RPSTg0OAXFujW30unr D4Hx1ClkO0ga1+qHGvPnjbO3DT/Rm7N8sknwN1MoDkM3wTX098D0dTbczqDQmzfDNWRF 0D4Q== 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=wxHwgaQYszXgOk2yCZLgI7etmYPcha6b1/7gPCoB2pw=; b=eSfkL6ZYZptTHTjNPtvNQcUbI6/m0gQLcjXDTf0u2xem1zclewoPwXl0qm7X+Ehgfa QOw54LHAyNXIQf+lOYTBPKyhczGRaZUSzLFVcKMV3T1IGQKb6CWcMrzTN0MUyEtojMnj HByP4uZKNCEiVj/0Gg+HFIpeoOM2fF25fBWl9GeXP2CpcPq6FjUFhVBp6dwqheAguMsr gfycvJ2ixOA3lRGLuw/9EehCkpHgUh8eDovsiyxiF9FvFCy92dPriU1Lr3ZxdtMz4FMp C/bwm4TWazrGVOUXn5rcm2aZ8GzLB/GFgIqOd08m0C8b5Smdp+K5dVPXz/fxYqNpXTQp +Nmw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@alien8.de header.s=dkim header.b="Ada/DEb5"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n19-20020aa7d053000000b00445f3dd3861si527558edo.313.2022.08.17.09.28.14; Wed, 17 Aug 2022 09:28:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@alien8.de header.s=dkim header.b="Ada/DEb5"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S240912AbiHQQJY (ORCPT + 99 others); Wed, 17 Aug 2022 12:09:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55144 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240906AbiHQQIl (ORCPT ); Wed, 17 Aug 2022 12:08:41 -0400 Received: from mail.skyhub.de (mail.skyhub.de [IPv6:2a01:4f8:190:11c2::b:1457]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F24B49F76C for ; Wed, 17 Aug 2022 09:08:29 -0700 (PDT) Received: from zn.tnic (p200300ea971b98b0329c23fffea6a903.dip0.t-ipconnect.de [IPv6:2003:ea:971b:98b0:329c:23ff:fea6:a903]) (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 2A7BA1EC01B7; Wed, 17 Aug 2022 18:08:24 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=alien8.de; s=dkim; t=1660752504; 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=wxHwgaQYszXgOk2yCZLgI7etmYPcha6b1/7gPCoB2pw=; b=Ada/DEb5Q69qYOz7e8f5v9+SMfGYiMY8eTop2+PP/7r+hT/IwelYV9pqJHG0/g1ZJ6dF28 b0tvQp2IR/8hyNpaU2UKt+wD1tmkdD/xv1MJmhVeVaUJTt6p1BwX0u10xNqWNofygOilf7 DO7V153szMP0h5FRK7HJQV0eG8yRc9k= Date: Wed, 17 Aug 2022 18:08:19 +0200 From: Borislav Petkov To: Tom Lendacky Cc: linux-kernel@vger.kernel.org, x86@kernel.org, Thomas Gleixner , Ingo Molnar , Dave Hansen , "Kirill A. Shutemov" , "H. Peter Anvin" , Michael Roth , Joerg Roedel , Andy Lutomirski , Peter Zijlstra Subject: Re: [PATCH v3 1/2] x86/sev: Put PSC struct on the stack in prep for unaccepted memory support Message-ID: References: <20220614120231.48165-1-kirill.shutemov@linux.intel.com> <9017076fe1050b8a38d5ee8447b827a5c41c4e72.1660579062.git.thomas.lendacky@amd.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <9017076fe1050b8a38d5ee8447b827a5c41c4e72.1660579062.git.thomas.lendacky@amd.com> X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Aug 15, 2022 at 10:57:42AM -0500, Tom Lendacky wrote: > diff --git a/arch/x86/kernel/sev.c b/arch/x86/kernel/sev.c > index c05f0124c410..40268ce97aad 100644 > --- a/arch/x86/kernel/sev.c > +++ b/arch/x86/kernel/sev.c > @@ -66,6 +66,17 @@ static struct ghcb boot_ghcb_page __bss_decrypted __aligned(PAGE_SIZE); > */ > static struct ghcb *boot_ghcb __section(".data"); > > +/* > + * A flag used by set_pages_state() that indicates when the per-CPU GHCB has > + * been created and registered and thus can be used instead of using the MSR > + * protocol. The set_pages_state() function eventually invokes vmgexit_psc(), > + * which only works with a per-CPU GHCB. > + * > + * For APs, the per-CPU GHCB is created before they are started and registered > + * upon startup, so this flag can be used globally for the BSP and APs. > + */ Ok, better, thanks! > +static bool ghcb_percpu_ready __section(".data"); However, it reads really weird if you have "percpu" in the name of a variable which is not per CPU... Let's just call it "ghcbs_initialized" and be done with it. And I still hate the whole thing ofc. Do this ontop (and I knew we had a flags thing already): (And yes, __read_mostly is in the .data section too). --- diff --git a/arch/x86/kernel/sev.c b/arch/x86/kernel/sev.c index 40268ce97aad..5b3afbf26349 100644 --- a/arch/x86/kernel/sev.c +++ b/arch/x86/kernel/sev.c @@ -66,17 +66,6 @@ static struct ghcb boot_ghcb_page __bss_decrypted __aligned(PAGE_SIZE); */ static struct ghcb *boot_ghcb __section(".data"); -/* - * A flag used by set_pages_state() that indicates when the per-CPU GHCB has - * been created and registered and thus can be used instead of using the MSR - * protocol. The set_pages_state() function eventually invokes vmgexit_psc(), - * which only works with a per-CPU GHCB. - * - * For APs, the per-CPU GHCB is created before they are started and registered - * upon startup, so this flag can be used globally for the BSP and APs. - */ -static bool ghcb_percpu_ready __section(".data"); - /* Bitmap of SEV features supported by the hypervisor */ static u64 sev_hv_features __ro_after_init; @@ -128,7 +117,18 @@ static DEFINE_PER_CPU(struct sev_es_save_area *, sev_vmsa); struct sev_config { __u64 debug : 1, - __reserved : 63; + + /* + * A flag used by set_pages_state() that indicates when the per-CPU GHCB has + * been created and registered and thus can be used instead of using the MSR + * protocol. The set_pages_state() function eventually invokes vmgexit_psc(), + * which only works with a per-CPU GHCB. + * + * For APs, the per-CPU GHCB is created before they are started and registered + * upon startup, so this flag can be used globally for the BSP and APs. + */ + ghcbs_initialized : 1, + __reserved : 62; }; static struct sev_config sev_cfg __read_mostly; @@ -762,7 +762,7 @@ static int vmgexit_psc(struct snp_psc_desc *desc) unsigned long flags; struct ghcb *ghcb; - WARN_ON_ONCE(!ghcb_percpu_ready); + WARN_ON_ONCE(!sev_cfg.ghcbs_initialized); /* * __sev_get_ghcb() needs to run with IRQs disabled because it is using @@ -887,7 +887,7 @@ static void set_pages_state(unsigned long vaddr, unsigned int npages, int op) * Use the MSR protocol when the per-CPU GHCBs are not yet registered, * since vmgexit_psc() uses the per-CPU GHCB. */ - if (!ghcb_percpu_ready) + if (!sev_cfg.ghcbs_initialized) return early_set_pages_state(__pa(vaddr), npages, op); vaddr = vaddr & PAGE_MASK; @@ -1268,7 +1268,7 @@ void setup_ghcb(void) if (cc_platform_has(CC_ATTR_GUEST_SEV_SNP)) snp_register_per_cpu_ghcb(); - ghcb_percpu_ready = true; + sev_cfg.ghcbs_initialized = true; return; } -- Regards/Gruss, Boris. https://people.kernel.org/tglx/notes-about-netiquette