Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp940668pxb; Thu, 15 Apr 2021 09:57:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxcUHed8RWSJvsbcvtflDg9oPAyKRbmy6SOn0Z2rOmXxD/k7XCItKk3Zk9yRmbcXE44KkGq X-Received: by 2002:a62:1706:0:b029:244:86e9:9e7 with SMTP id 6-20020a6217060000b029024486e909e7mr4008628pfx.65.1618505864076; Thu, 15 Apr 2021 09:57:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618505864; cv=none; d=google.com; s=arc-20160816; b=p+Wk+8D+7Cicw1ps4ImgPwL4MqDq2pC4W8tMasuGicqW41ceNO+DcCkjLShM/GVx/c 2JkkRalzCBpatT4cSGNtEqCH3CkFXCxNz4dnOTFF/hnmxF+AsDIbaMmGZdEaRzu97PkJ 55ZAyQ7dG3+5gBU0cg+OGscLymMkIGy/IUtYDxq+2aiHIjtHNtH3ygK7qIsPZMbCla0W 7crztyaMczR5KqvVy9/J0w31sQRWT+V0MakVNArl5ni+YYeWb0eOJOrW0ohJLnkZEqQa KVPktpYvFY0T2qy5r1nV24Pia3K6mkzZpzUUKKrZj9216ypj1qqaNOkZ3NI28DEgC2Ur eS/Q== 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=ssLL2NClrrsFyaLaoAWuOz/cf3x+Tj+t14k/W0AGB/E=; b=Jq/kbZaCBJBcIeTbVGXMMi1J0UXpDtuizhHuxJuw0vNelqE0FjJPkN1Xket4kkx4jm 5jE1hTX9SY6E0MLPPAyyKN/HIOq2faBxNyhhmyTQlYhPSjwjrlaXqmrtQRYAuLmg7UE+ q90nlwr8BH4QWo8kU7l0FfITW5uUiUDuickBOC9n0DSCnmylGzhh/MMbpEP3eOYZKEZc +1P0t/c+Gz9gz/E3Cdrcbl3LIS03UFybU++T8xEPspVZ/lSzRe40CnrTk5XxiPLmQ1Hu R2euW5JmnJqYODVSnYToj8+71WoC5/EqJcbux5xZl3kZxosAIiRTBTmr7mfePrTw1YtA lLDg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@alien8.de header.s=dkim header.b=CyzjZzEE; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-crypto-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 f4si3673849pgs.59.2021.04.15.09.57.21; Thu, 15 Apr 2021 09:57:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-crypto-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=CyzjZzEE; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-crypto-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 S233609AbhDOQ5m (ORCPT + 99 others); Thu, 15 Apr 2021 12:57:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43016 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231549AbhDOQ5l (ORCPT ); Thu, 15 Apr 2021 12:57: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 8D4D1C061574; Thu, 15 Apr 2021 09:57:18 -0700 (PDT) Received: from zn.tnic (p200300ec2f0ace002a6aea191a6cda8f.dip0.t-ipconnect.de [IPv6:2003:ec:2f0a:ce00:2a6a:ea19:1a6c:da8f]) (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 BA2F71EC0518; Thu, 15 Apr 2021 18:57:14 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=alien8.de; s=dkim; t=1618505834; 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=ssLL2NClrrsFyaLaoAWuOz/cf3x+Tj+t14k/W0AGB/E=; b=CyzjZzEEj58xGorNZdZE7IJ+pq0wpH73fEnomHbUsDszk83CPnmjec9iesU+6ALC1QxQEI 0nBBMm6VOdq8wrGVkXCk1/5tt2MVe41ayn4ISnYaw10tgtXOnFsbG7Q+vgKMOMwf60Jpoi aK2D67UjFNRopXf6gP/O+Cpsgw1VqII= Date: Thu, 15 Apr 2021 18:57:11 +0200 From: Borislav Petkov To: Brijesh Singh Cc: linux-kernel@vger.kernel.org, x86@kernel.org, kvm@vger.kernel.org, linux-crypto@vger.kernel.org, ak@linux.intel.com, herbert@gondor.apana.org.au, 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 Part2 PATCH 02/30] x86/sev-snp: add RMP entry lookup helpers Message-ID: <20210415165711.GD6318@zn.tnic> References: <20210324170436.31843-1-brijesh.singh@amd.com> <20210324170436.31843-3-brijesh.singh@amd.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20210324170436.31843-3-brijesh.singh@amd.com> Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org On Wed, Mar 24, 2021 at 12:04:08PM -0500, Brijesh Singh wrote: > The lookup_page_in_rmptable() can be used by the host to read the RMP > entry for a given page. The RMP entry format is documented in PPR > section 2.1.5.2. I see Table 15-36. Fields of an RMP Entry in the APM. Which PPR do you mean? Also, you know where to put those documents, right? > +/* RMP table entry format (PPR section 2.1.5.2) */ > +struct __packed rmpentry { > + union { > + struct { > + uint64_t assigned:1; > + uint64_t pagesize:1; > + uint64_t immutable:1; > + uint64_t rsvd1:9; > + uint64_t gpa:39; > + uint64_t asid:10; > + uint64_t vmsa:1; > + uint64_t validated:1; > + uint64_t rsvd2:1; > + } info; > + uint64_t low; > + }; > + uint64_t high; > +}; > + > +typedef struct rmpentry rmpentry_t; Eww, a typedef. Why? struct rmpentry is just fine. > diff --git a/arch/x86/mm/mem_encrypt.c b/arch/x86/mm/mem_encrypt.c > index 39461b9cb34e..06394b6d56b2 100644 > --- a/arch/x86/mm/mem_encrypt.c > +++ b/arch/x86/mm/mem_encrypt.c > @@ -34,6 +34,8 @@ > > #include "mm_internal.h" > <--- Needs a comment here to explain the magic 0x4000 and the magic shift by 8. > +#define rmptable_page_offset(x) (0x4000 + (((unsigned long) x) >> 8)) > + > /* > * Since SME related variables are set early in the boot process they must > * reside in the .data section so as not to be zeroed out when the .bss > @@ -612,3 +614,33 @@ static int __init mem_encrypt_snp_init(void) > * SEV-SNP must be enabled across all CPUs, so make the initialization as a late initcall. > */ > late_initcall(mem_encrypt_snp_init); > + > +rmpentry_t *lookup_page_in_rmptable(struct page *page, int *level) snp_lookup_page_in_rmptable() > +{ > + unsigned long phys = page_to_pfn(page) << PAGE_SHIFT; > + rmpentry_t *entry, *large_entry; > + unsigned long vaddr; > + > + if (!static_branch_unlikely(&snp_enable_key)) > + return NULL; > + > + vaddr = rmptable_start + rmptable_page_offset(phys); > + if (WARN_ON(vaddr > rmptable_end)) Do you really want to spew a warn on splat for each wrong vaddr? What for? > + return NULL; > + > + entry = (rmpentry_t *)vaddr; > + > + /* > + * Check if this page is covered by the large RMP entry. This is needed to get > + * the page level used in the RMP entry. > + * No need for a new line in the comment and no need for the "e.g." thing either. Also, s/the large RMP entry/a large RMP entry/g. > + * e.g. if the page is covered by the large RMP entry then page size is set in the > + * base RMP entry. > + */ > + vaddr = rmptable_start + rmptable_page_offset(phys & PMD_MASK); > + large_entry = (rmpentry_t *)vaddr; > + *level = rmpentry_pagesize(large_entry); > + > + return entry; > +} > +EXPORT_SYMBOL_GPL(lookup_page_in_rmptable); Exported for kvm? -- Regards/Gruss, Boris. https://people.kernel.org/tglx/notes-about-netiquette