From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 85FF4C433FE for ; Wed, 29 Sep 2021 18:38:39 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 225C26134F for ; Wed, 29 Sep 2021 18:38:39 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 225C26134F Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=alien8.de Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 98BF194004F; Wed, 29 Sep 2021 14:38:38 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9142B94003A; Wed, 29 Sep 2021 14:38:38 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 78D2894004F; Wed, 29 Sep 2021 14:38:38 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0169.hostedemail.com [216.40.44.169]) by kanga.kvack.org (Postfix) with ESMTP id 66A0A94003A for ; Wed, 29 Sep 2021 14:38:38 -0400 (EDT) Received: from smtpin09.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 1B84639499 for ; Wed, 29 Sep 2021 18:38:38 +0000 (UTC) X-FDA: 78641471916.09.BE0A596 Received: from mail.skyhub.de (mail.skyhub.de [5.9.137.197]) by imf02.hostedemail.com (Postfix) with ESMTP id C25E37001704 for ; Wed, 29 Sep 2021 18:38:36 +0000 (UTC) Received: from zn.tnic (p200300ec2f0bd10085b5178de8b08a0e.dip0.t-ipconnect.de [IPv6:2003:ec:2f0b:d100:85b5:178d:e8b0:8a0e]) (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 2F3AD1EC0136; Wed, 29 Sep 2021 20:38:35 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=alien8.de; s=dkim; t=1632940715; 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=Bo+gAEaB3c3ilgMX8OgreD8PMGNiwY4UFgAUH1GnA0M=; b=BX2CAl3ohCbYKJL64okCa2H8GmBJcotMMGimHp4e44UXgDWZIafY5Ao8UiKadDFMQALdAS gIdU97e8g1oAMrREVviFDVlwyhtq/V1wr/uhEtNyNGYdP92oJjJPdwINQnMqgBCa8WEObR NziEBHyhnhpkYJ/9PGQskFQSTwbjg00= Date: Wed, 29 Sep 2021 20:38:31 +0200 From: Borislav Petkov To: Brijesh Singh Cc: x86@kernel.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, linux-coco@lists.linux.dev, linux-mm@kvack.org, linux-crypto@vger.kernel.org, Thomas Gleixner , Ingo Molnar , Joerg Roedel , Tom Lendacky , "H. Peter Anvin" , Ard Biesheuvel , Paolo Bonzini , Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , 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 , tony.luck@intel.com, marcorr@google.com, sathyanarayanan.kuppuswamy@linux.intel.com Subject: Re: [PATCH Part2 v5 09/45] x86/fault: Add support to dump RMP entry on fault Message-ID: References: <20210820155918.7518-1-brijesh.singh@amd.com> <20210820155918.7518-10-brijesh.singh@amd.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20210820155918.7518-10-brijesh.singh@amd.com> X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: C25E37001704 X-Stat-Signature: mwkxr41uoiopfhjc7jqd6rdqn4k9s8r9 Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=alien8.de header.s=dkim header.b=BX2CAl3o; dmarc=pass (policy=none) header.from=alien8.de; spf=pass (imf02.hostedemail.com: domain of bp@alien8.de designates 5.9.137.197 as permitted sender) smtp.mailfrom=bp@alien8.de X-HE-Tag: 1632940716-166205 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Fri, Aug 20, 2021 at 10:58:42AM -0500, Brijesh Singh wrote: > When SEV-SNP is enabled globally, a write from the host goes through the > RMP check. If the hardware encounters the check failure, then it raises > the #PF (with RMP set). Dump the RMP entry at the faulting pfn to help > the debug. > > Signed-off-by: Brijesh Singh > --- > arch/x86/include/asm/sev.h | 7 +++++++ > arch/x86/kernel/sev.c | 43 ++++++++++++++++++++++++++++++++++++++ > arch/x86/mm/fault.c | 17 +++++++++++---- > include/linux/sev.h | 2 ++ > 4 files changed, 65 insertions(+), 4 deletions(-) > > diff --git a/arch/x86/include/asm/sev.h b/arch/x86/include/asm/sev.h > index 92ced9626e95..569294f687e6 100644 > --- a/arch/x86/include/asm/sev.h > +++ b/arch/x86/include/asm/sev.h > @@ -106,6 +106,11 @@ struct __packed rmpentry { > > #define rmpentry_assigned(x) ((x)->info.assigned) > #define rmpentry_pagesize(x) ((x)->info.pagesize) > +#define rmpentry_vmsa(x) ((x)->info.vmsa) > +#define rmpentry_asid(x) ((x)->info.asid) > +#define rmpentry_validated(x) ((x)->info.validated) > +#define rmpentry_gpa(x) ((unsigned long)(x)->info.gpa) > +#define rmpentry_immutable(x) ((x)->info.immutable) If some of those accessors are going to be used only in dump_rmpentry(), then you don't really need them. > > #define RMPADJUST_VMSA_PAGE_BIT BIT(16) > > @@ -165,6 +170,7 @@ void __init snp_prep_memory(unsigned long paddr, unsigned int sz, enum psc_op op > void snp_set_memory_shared(unsigned long vaddr, unsigned int npages); > void snp_set_memory_private(unsigned long vaddr, unsigned int npages); > void snp_set_wakeup_secondary_cpu(void); > +void dump_rmpentry(u64 pfn); > #ifdef __BOOT_COMPRESSED > bool sev_snp_enabled(void); > #else > @@ -188,6 +194,7 @@ static inline void snp_set_memory_shared(unsigned long vaddr, unsigned int npage > static inline void snp_set_memory_private(unsigned long vaddr, unsigned int npages) { } > static inline void snp_set_wakeup_secondary_cpu(void) { } > static inline void sev_snp_cpuid_init(struct boot_params *bp) { } > +static inline void dump_rmpentry(u64 pfn) {} > #ifdef __BOOT_COMPRESSED > static inline bool sev_snp_enabled { return false; } > #else > diff --git a/arch/x86/kernel/sev.c b/arch/x86/kernel/sev.c > index bad41deb8335..8b3e83e50468 100644 > --- a/arch/x86/kernel/sev.c > +++ b/arch/x86/kernel/sev.c > @@ -2404,6 +2404,49 @@ static struct rmpentry *__snp_lookup_rmpentry(u64 pfn, int *level) > return entry; > } > > +void dump_rmpentry(u64 pfn) snp_dump_rmpentry() > +{ > + unsigned long pfn_end; > + struct rmpentry *e; > + int level; > + > + e = __snp_lookup_rmpentry(pfn, &level); > + if (!e) { > + pr_alert("failed to read RMP entry pfn 0x%llx\n", pfn); > + return; > + } > + > + if (rmpentry_assigned(e)) { > + pr_alert("RMPEntry paddr 0x%llx [assigned=%d immutable=%d pagesize=%d gpa=0x%lx" > + " asid=%d vmsa=%d validated=%d]\n", pfn << PAGE_SHIFT, WARNING: quoted string split across lines #174: FILE: arch/x86/kernel/sev.c:2421: + pr_alert("RMPEntry paddr 0x%llx [assigned=%d immutable=%d pagesize=%d gpa=0x%lx" + " asid=%d vmsa=%d validated=%d]\n", pfn << PAGE_SHIFT, > + rmpentry_assigned(e), rmpentry_immutable(e), rmpentry_pagesize(e), > + rmpentry_gpa(e), rmpentry_asid(e), rmpentry_vmsa(e), > + rmpentry_validated(e)); > + return; > + } > + > + /* > + * If the RMP entry at the faulting pfn was not assigned, then we do not > + * know what caused the RMP violation. To get some useful debug information, > + * let iterate through the entire 2MB region, and dump the RMP entries if > + * one of the bit in the RMP entry is set. > + */ > + pfn = pfn & ~(PTRS_PER_PMD - 1); > + pfn_end = pfn + PTRS_PER_PMD; > + > + while (pfn < pfn_end) { > + e = __snp_lookup_rmpentry(pfn, &level); > + if (!e) > + return; return? You mean "continue;" ? > + > + if (e->low || e->high) > + pr_alert("RMPEntry paddr 0x%llx: [high=0x%016llx low=0x%016llx]\n", > + pfn << PAGE_SHIFT, e->high, e->low); > + pfn++; > + } > +} > +EXPORT_SYMBOL_GPL(dump_rmpentry); Why is that exported? Some module will be calling it too? > + > /* > * Return 1 if the RMP entry is assigned, 0 if it exists but is not assigned, > * and -errno if there is no corresponding RMP entry. > diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c > index f2d543b92f43..9cd33169dfb5 100644 > --- a/arch/x86/mm/fault.c > +++ b/arch/x86/mm/fault.c > @@ -33,6 +33,7 @@ > #include /* VMALLOC_START, ... */ > #include /* kvm_handle_async_pf */ > #include /* fixup_vdso_exception() */ > +#include /* dump_rmpentry() */ > > #define CREATE_TRACE_POINTS > #include > @@ -289,7 +290,7 @@ static bool low_pfn(unsigned long pfn) > return pfn < max_low_pfn; > } > > -static void dump_pagetable(unsigned long address) > +static void dump_pagetable(unsigned long address, bool show_rmpentry) I think passing in error_code and testing X86_PF_RMP inside should make this a bit more palatable than simply "grafting" SNP-specific functionality to generic paths. Thx. -- Regards/Gruss, Boris. https://people.kernel.org/tglx/notes-about-netiquette