Received: by 2002:a05:6500:1b45:b0:1f5:f2ab:c469 with SMTP id cz5csp20948lqb; Tue, 16 Apr 2024 07:46:57 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCW/e41+ekOEQ+rf40svz8eM/kpIpOLApNjHlwGLLMu521y88kNJcitPkENOEXzB/dHdL/Z2cgmgz4G8jBHGAccyKeix02loIP8puAp5kw== X-Google-Smtp-Source: AGHT+IHmoOe/HtKt2fSXV8RbwEHE1m37BusoYeLfoBGTz7c+5BKWZZY1O+p0u1T6llet9CNhZHdK X-Received: by 2002:a50:99dd:0:b0:570:5215:d29c with SMTP id n29-20020a5099dd000000b005705215d29cmr85987edb.4.1713278817736; Tue, 16 Apr 2024 07:46:57 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713278817; cv=pass; d=google.com; s=arc-20160816; b=ghtfzdTyGdiisOEGHCDZA0QJEZB3vTvJ9ZYMSgKmjpsjMBkrfLy6Sg5p4yDG6rl3j0 85I6Yc/QGV4aK79SoHGBofqojxgtso1DvLcwWMBBmzYyWzkMpj3xmwQPsp037rO7doKh +XFt8L6fii4OunDIPsbrydtI2G1EnS7Ki4LiF1CUDVNR7kcCHoa3fKNCHMOlK23oi/Bl fy2Bhzvrlgl6C5XxT3ZNrD5dDo+lA0OTcFSSJB3tmMzuHORcSenLRLTJNAs4Y4BgoUg8 R1nwaIvvFiK+ZV3Wxmeer76nTw6nX7O/jpkTnbiy00ThcXKj98BvAWq56cGQqndeEVuc uGgQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date; bh=+yPYU6VtqUUwZdBJncGbdp1M3cuF6OkGtg2uT1OuHs0=; fh=AGFBHHpYN5mv0+SnhFXAMmpvv/XoqVIL2B5IsBP1bYU=; b=onjKEcDIohenPx9JqVKzAm/L/r/crykVZN05xj6tNHWNExaChVJBYTEQME+T+nRRlx 39CuR3wn16KJGU5+3s1rjenLaYxMCjRMaLeJrejKVHinLv025UAQXR8E3plWPy2RsrUh 0QorL9Jsvs5/jgJpbet1PyJY4Rif2FbuVvTHMe2cLEwy2O2gqos2cr0SZuYQyJIhgmfv Yh5d272s/wT3KgOM+u05n3tdBBwi8zztJdT1P3awNFVt6vPr8k4mbfvliUD34ESK/U4y bte1eQIRqMVEKzKn0yg6qHxIv54RICyutH3AnBCr8+97mki/VZnv/ZyyCUgOBj0gU5CS atPw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=alien8.de dmarc=pass fromdomain=alien8.de); spf=pass (google.com: domain of linux-kernel+bounces-147051-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-147051-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alien8.de Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id w28-20020a50d79c000000b0056bd1c4942dsi5753395edi.377.2024.04.16.07.46.57 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Apr 2024 07:46:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-147051-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=alien8.de dmarc=pass fromdomain=alien8.de); spf=pass (google.com: domain of linux-kernel+bounces-147051-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-147051-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alien8.de Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id DCDFA1F23036 for ; Tue, 16 Apr 2024 14:46:30 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 24DB212FF91; Tue, 16 Apr 2024 14:46:13 +0000 (UTC) Received: from mail.alien8.de (mail.alien8.de [65.109.113.108]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8C91112F37F; Tue, 16 Apr 2024 14:46:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=65.109.113.108 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713278772; cv=none; b=KtboLXpcW26qxlkzzt0XBwiEA4aSJvP8j2gDe5XgRaqIjcf4KvhctXH22yH17OzJbXwk3vAMP0N8O9g/Z/1kKZ+MvPJQQCwmaPzTlqkjbMrxZNJUuawGVMua29w1qOcaxNkXKo+Wr7f+hpkWxPY7cx9KEHNM/VJDqVIwL8HV9AY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713278772; c=relaxed/simple; bh=d81gaNfPfukpzkiqCd/WpjLfADwgO0JBtLOlCm82Qr4=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=VBCgxTAlAEz6DA0TCBzM7KuykF4qMu14g55lA5YoFF3d/tqr8+gITsCMfWX+hc8SXn6lPkJOtNRuS6NojnJMWPbYrQ64OZHUAJwSxKzwTX5I1QrUVT2cSLMZipKEf7a3l9EN2ASxFIRzFCe+nWxgRiqDs7bVczogTTOSm52JFjo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=alien8.de; spf=pass smtp.mailfrom=alien8.de; arc=none smtp.client-ip=65.109.113.108 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=alien8.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=alien8.de Received: from localhost (localhost.localdomain [127.0.0.1]) by mail.alien8.de (SuperMail on ZX Spectrum 128k) with ESMTP id E527A40E0177; Tue, 16 Apr 2024 14:46:07 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at mail.alien8.de Received: from mail.alien8.de ([127.0.0.1]) by localhost (mail.alien8.de [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id L-M63d3ZGt_4; Tue, 16 Apr 2024 14:46:00 +0000 (UTC) Received: from zn.tnic (pd953020b.dip0.t-ipconnect.de [217.83.2.11]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature ECDSA (P-256) server-digest SHA256) (No client certificate requested) by mail.alien8.de (SuperMail on ZX Spectrum 128k) with ESMTPSA id D4C9040E00B2; Tue, 16 Apr 2024 14:45:48 +0000 (UTC) Date: Tue, 16 Apr 2024 16:45:42 +0200 From: Borislav Petkov To: Nikunj A Dadhania Cc: linux-kernel@vger.kernel.org, thomas.lendacky@amd.com, x86@kernel.org, kvm@vger.kernel.org, mingo@redhat.com, tglx@linutronix.de, dave.hansen@linux.intel.com, pgonda@google.com, seanjc@google.com, pbonzini@redhat.com Subject: Re: [PATCH v8 05/16] x86/sev: Cache the secrets page address Message-ID: <20240416144542.GFZh6PFjPNT9Zt3iUl@fat_crate.local> References: <20240215113128.275608-1-nikunj@amd.com> <20240215113128.275608-6-nikunj@amd.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20240215113128.275608-6-nikunj@amd.com> On Thu, Feb 15, 2024 at 05:01:17PM +0530, Nikunj A Dadhania wrote: > +/* Secrets page physical address from the CC blob */ > +static u64 secrets_pa __ro_after_init; Since you're going to use this during runtime (are you?), why don't you put in here the result of: ioremap_encrypted(secrets_pa, PAGE_SIZE); so that you can have it ready and not even have to ioremap each time? And then you iounmap on driver teardown. > +static void __init set_secrets_pa(const struct cc_blob_sev_info *cc_info) > +{ > + if (cc_info && cc_info->secrets_phys && cc_info->secrets_len == PAGE_SIZE) > + secrets_pa = cc_info->secrets_phys; > +} Why is this a separate function if it is called only once and it is a trivial function at that? Also, can the driver continue without secrets page? If not, then you need to unwind. > bool __init snp_init(struct boot_params *bp) > { > struct cc_blob_sev_info *cc_info; > @@ -2099,6 +2079,8 @@ bool __init snp_init(struct boot_params *bp) > if (!cc_info) > return false; > > + set_secrets_pa(cc_info); > + > setup_cpuid_table(cc_info); > > /* > @@ -2246,16 +2228,16 @@ static struct platform_device sev_guest_device = { > static int __init snp_init_platform_device(void) > { > struct sev_guest_platform_data data; > - u64 gpa; > > if (!cc_platform_has(CC_ATTR_GUEST_SEV_SNP)) > return -ENODEV; > > - gpa = get_secrets_page(); > - if (!gpa) > + if (!secrets_pa) { > + pr_err("SNP secrets page not found\n"); > return -ENODEV; > + } Yeah, no, you need to error out in snp_init() and not drag it around to snp_init_platform_device(). Thx. -- Regards/Gruss, Boris. https://people.kernel.org/tglx/notes-about-netiquette