From patchwork Mon Feb 20 18:38:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Roth X-Patchwork-Id: 13146858 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id B6947C6379F for ; Mon, 20 Feb 2023 18:45:03 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1657D6B0072; Mon, 20 Feb 2023 13:45:03 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 115E36B0073; Mon, 20 Feb 2023 13:45:03 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EF8486B0074; Mon, 20 Feb 2023 13:45:02 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id E0C9F6B0072 for ; Mon, 20 Feb 2023 13:45:02 -0500 (EST) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 8E28C1607D8 for ; Mon, 20 Feb 2023 18:45:02 +0000 (UTC) X-FDA: 80488547244.02.4145A29 Received: from NAM02-SN1-obe.outbound.protection.outlook.com (mail-sn1nam02on2058.outbound.protection.outlook.com [40.107.96.58]) by imf06.hostedemail.com (Postfix) with ESMTP id 8B75D180012 for ; Mon, 20 Feb 2023 18:44:59 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=UkpYSvrn; spf=pass (imf06.hostedemail.com: domain of Michael.Roth@amd.com designates 40.107.96.58 as permitted sender) smtp.mailfrom=Michael.Roth@amd.com; arc=pass ("microsoft.com:s=arcselector9901:i=1"); dmarc=pass (policy=quarantine) header.from=amd.com ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1676918699; h=from:from:sender: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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=F2kvs1P/l4ZozOxsEC0d23b+JIIcSAMRctM1la8Mn4o=; b=syhFeDaZFDQ+GG6gaQKgnLWv3LG/R3KkxxGUTlf4oHgWs8oj6wcDn5bT6wJjdjEr6UhsUy H02DIN+o5gDGypNmpOaU1picW7KF99BSQMLsx3LSv99geWjou3yXP/qmZ9S87Xs7Uxkb9T joxFAPLFWMzKwZz09AHY5/vT07slnMk= ARC-Authentication-Results: i=2; imf06.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=UkpYSvrn; spf=pass (imf06.hostedemail.com: domain of Michael.Roth@amd.com designates 40.107.96.58 as permitted sender) smtp.mailfrom=Michael.Roth@amd.com; arc=pass ("microsoft.com:s=arcselector9901:i=1"); dmarc=pass (policy=quarantine) header.from=amd.com ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1676918699; a=rsa-sha256; cv=pass; b=Ye7o0Vb4KTGRt/X02d9fDYTintnYnD3J6IZ5N2Gex/d3lBTMINoqMfTsN2SxNRqXFGvujp nUWNOG6rJ9LwRU+M+D0eAWOcAITkhY7p53Vfrvff+Ht0z7yGevZA9Pk9VqLjymi5JqvM5u eRR7ysWzVX4EYYJaoRAmO2FznCcfZyw= ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=YbVjny7Alf9EebGhN9aVJxLbPByfm8J6u+JfSKOVDSSVidiIgfRPcEtrRQlOb3SqKBhgM81OlZ8xmdAh5DQ5G4yz20d8B3TtvJhxkTDrrPmmXvjWVplIANeRcDNHkSBQ60uwvEjSUd1Qfidp3KddBpMMi1oCb21tvX3DdF4w34OUxtLRcSaHEHNK7dAiSXmtsoWlhQBWoix88tCANzPAYKBfzJ7Py3VdLz0lHFMI7JBQZpHCi7Z/A/6vtAoTuSfcrkymSqhTRsVVbhNtsOxIiseDIzD8Z0J5H7Z9kdOojkks/KYOe76bnvYtJsAa5WB3JWc8OkhB4CtJxczxwfmrnA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=F2kvs1P/l4ZozOxsEC0d23b+JIIcSAMRctM1la8Mn4o=; b=IxGZ5YT2jwwxB6OvNDv6aNoytVhqjEpAukNGcF7Oj/wcRea1w1X4n5Kpeae+3g8C5RSlXQpWonoyEG8NkNeJhd/1rACLbgXpbi7yczHfRKJusd2/CH0yApOYem7/PwMpBACFHeNFkV69bXgztJ6CXdTSpF/Zu+oRV6LQ6XSONeEs0rw2pHkehoqMxfbYakgo8eRXrvKmKTrZrjTswiGTlum2A0ok1SI4Px7NqRXc+wAvlayfgHJrQUF4mKjTYaYFGmCEDJpKnJMWPDuZ71BYc/4SHkbfLsdrvP3y8RQ3YxTZQulPrH/O67K/TAVM6j4ukeq2WrWGhZF/fdi/asTuCQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=F2kvs1P/l4ZozOxsEC0d23b+JIIcSAMRctM1la8Mn4o=; b=UkpYSvrnwaSykb28m6Gtf6DYlINfGtBgD0VVYyKWZq4zJt5TIlpXaYZSPQm2+lqYs14ZzHnMaKJkf9P86uJZvzFURRxeKpAzNLacMGsX2QlKAonTlsurxzRfKeFSCLuwfUTro8PIsvzcmHMN/Zlwjmie927Ms0bsOPnLPbnz/rI= Received: from DM6PR07CA0062.namprd07.prod.outlook.com (2603:10b6:5:74::39) by CY8PR12MB7754.namprd12.prod.outlook.com (2603:10b6:930:86::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6111.13; Mon, 20 Feb 2023 18:44:57 +0000 Received: from DM6NAM11FT090.eop-nam11.prod.protection.outlook.com (2603:10b6:5:74:cafe::cb) by DM6PR07CA0062.outlook.office365.com (2603:10b6:5:74::39) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6111.20 via Frontend Transport; Mon, 20 Feb 2023 18:44:57 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by DM6NAM11FT090.mail.protection.outlook.com (10.13.172.184) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6111.20 via Frontend Transport; Mon, 20 Feb 2023 18:44:56 +0000 Received: from localhost (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Mon, 20 Feb 2023 12:44:55 -0600 From: Michael Roth To: CC: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Brijesh Singh Subject: [PATCH RFC v8 13/56] x86/fault: Add helper for dumping RMP entries Date: Mon, 20 Feb 2023 12:38:04 -0600 Message-ID: <20230220183847.59159-14-michael.roth@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230220183847.59159-1-michael.roth@amd.com> References: <20230220183847.59159-1-michael.roth@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6NAM11FT090:EE_|CY8PR12MB7754:EE_ X-MS-Office365-Filtering-Correlation-Id: 26894fc4-1c33-4779-bf79-08db1372903a X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: k5MHBK56RFlQC5aKaQjyU5GLAIjushZvHab6ynl6l11i3+wRrEl2YX02kTaow3mM3+Lsd06bQyQVAok4+l1mp3vk1KWnLmvFOebF0IgKl8vQb9zGTG/MXrq6+MHQoObiLfc3m16tju6Uaih9xKzs6s22s0O0MBErbQETRzCUsm7OwJkPzrLaBMhaFnzGURjUt2diAoazru6g+U3NITYG9xpI8WU3yoDZhoi6otijm+u4QNBc1ypnBFzaqUgEpdg2/kn2Dug6iLiYhJbzyH/YghFy6AzIpIrslIZpGiUiEnpSTWwVvS9NdMIvV7Oksxhr9GbPt4vT793MY52qXcSEMYzb+9CTqxZRbUT9RAbAqMPWC4GxD7U04/PTWHvitr/IQTxIoGxeFctkFlyVve20UUGZS3w3rGFgXky8Boo+LnWpuPDUQVPAxJzu+ZDFUjp7qr3fGaOSahlDr/lhPjBDiGGve9L+ADITEspKfa0p3JP1Fx82BbColqjKSLz/yNyQmX5uXiT4t6qXWvDFkDJxOJqjWEFk23qzqRgy02nIbkK1sAuWh0gRTl7rO3Zw4fSZEHLom5TbsLpB+pJLdh1BiLznMr75RfewTvkHy5AJIipWnbsZ/OOsS+X0D1FHSdH/ad5s8OTzHGN0Cy9x7goApcuLG4zKnvAaJsRG3QY2opbeJd9x+r5KvJtZKK5vI2/DXoQ7z0Sn0WZBXhkhDzQ727g1M8FalQ+qKWMUrVxC6ZM= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230025)(4636009)(346002)(39860400002)(136003)(376002)(396003)(451199018)(36840700001)(46966006)(40470700004)(40460700003)(1076003)(40480700001)(83380400001)(47076005)(82740400003)(426003)(36860700001)(86362001)(81166007)(82310400005)(356005)(6666004)(16526019)(336012)(478600001)(36756003)(186003)(2616005)(26005)(5660300002)(7416002)(4326008)(70206006)(54906003)(70586007)(41300700001)(8936002)(6916009)(8676002)(2906002)(316002)(44832011)(7406005)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Feb 2023 18:44:56.9088 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 26894fc4-1c33-4779-bf79-08db1372903a X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: DM6NAM11FT090.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY8PR12MB7754 X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 8B75D180012 X-Stat-Signature: g74mgpunfchxacishbb1txniwei8xj4b X-HE-Tag: 1676918699-656586 X-HE-Meta: U2FsdGVkX1/Z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SZ7PIq/V1nIg5kTzMfXFyuyerAeB1wgY8H+kEIgMr7IcR2bXLMpfmNCW1NUr4qiLfrumT2DLadjgYCNi0dkk6b58WTldkQrR3CzQGi1abgJpKcXmoXmb/89Y1CbVqRoqHZ1Qh8XRLdZj7K9TzeOWBOG4lANBdAkDhr40GXeOTjuHhTtL0CfNqjT5fEPst+pjBvXtUvzCIfCFP5NHliXyNNN2gCsIC/Kw5XnBpoiz82if/HHw8= 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: This information will be useful for debugging things like page faults due to RMP access violations and RMPUPDATE failures. Signed-off-by: Brijesh Singh Signed-off-by: Ashish Kalra [mdr: move helper to standalone patch] Signed-off-by: Michael Roth --- arch/x86/include/asm/sev.h | 2 ++ arch/x86/kernel/sev.c | 48 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+) diff --git a/arch/x86/include/asm/sev.h b/arch/x86/include/asm/sev.h index 8d3ce2ad27da..edbb7fa488af 100644 --- a/arch/x86/include/asm/sev.h +++ b/arch/x86/include/asm/sev.h @@ -198,6 +198,7 @@ bool snp_init(struct boot_params *bp); void __init __noreturn snp_abort(void); int snp_issue_guest_request(u64 exit_code, struct snp_req_data *input, unsigned long *fw_err); int snp_lookup_rmpentry(u64 pfn, int *level); +void sev_dump_rmpentry(u64 pfn); #else static inline void sev_es_ist_enter(struct pt_regs *regs) { } static inline void sev_es_ist_exit(void) { } @@ -223,6 +224,7 @@ static inline int snp_issue_guest_request(u64 exit_code, struct snp_req_data *in return -ENOTTY; } static inline int snp_lookup_rmpentry(u64 pfn, int *level) { return 0; } +static inline void sev_dump_rmpentry(u64 pfn) {} #endif #endif diff --git a/arch/x86/kernel/sev.c b/arch/x86/kernel/sev.c index a063c1b98034..a01741c4a1b8 100644 --- a/arch/x86/kernel/sev.c +++ b/arch/x86/kernel/sev.c @@ -2504,6 +2504,54 @@ static struct rmpentry *__snp_lookup_rmpentry(u64 pfn, int *level) return entry; } +void sev_dump_rmpentry(u64 pfn) +{ + unsigned long pfn_end; + struct rmpentry *e; + int level; + + e = __snp_lookup_rmpentry(pfn, &level); + if (IS_ERR(e)) { + pr_info("Failed to read RMP entry for PFN 0x%llx\n", pfn); + return; + } + + if (rmpentry_assigned(e)) { + pr_info("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), e->info.immutable, + rmpentry_pagesize(e), (unsigned long)e->info.gpa, e->info.asid, + e->info.vmsa, e->info.validated); + + /* Dump all the non-zero entries if debug enabled */ + if (!sev_cfg.debug) + return; + } + + /* + * If the RMP entry at the faulting pfn was not assigned, then not sure + * what caused the RMP violation. To get some useful debug information, + * 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 (IS_ERR(e)) { + pr_info("Failed to read RMP entry for PFN 0x%llx\n", pfn); + pfn++; + continue; + } + + if (e->low || e->high) + pr_info("RMPEntry paddr 0x%llx: [high=0x%016llx low=0x%016llx]\n", + pfn << PAGE_SHIFT, e->high, e->low); + pfn++; + } +} +EXPORT_SYMBOL_GPL(sev_dump_rmpentry); + /* * 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.