From patchwork Mon Jun 12 04:25:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Roth X-Patchwork-Id: 13275451 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 8D2D4C7EE23 for ; Mon, 12 Jun 2023 04:27:35 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E46416B0072; Mon, 12 Jun 2023 00:27:34 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id DF61E8E0005; Mon, 12 Jun 2023 00:27:34 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CA1928E0003; Mon, 12 Jun 2023 00:27:34 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id BBF616B0072 for ; Mon, 12 Jun 2023 00:27:34 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 8A088120232 for ; Mon, 12 Jun 2023 04:27:34 +0000 (UTC) X-FDA: 80892812028.21.CABD127 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2071.outbound.protection.outlook.com [40.107.93.71]) by imf28.hostedemail.com (Postfix) with ESMTP id 88E32C000A for ; Mon, 12 Jun 2023 04:27:31 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=s48ASt0B; arc=pass ("microsoft.com:s=arcselector9901:i=1"); spf=pass (imf28.hostedemail.com: domain of Michael.Roth@amd.com designates 40.107.93.71 as permitted sender) smtp.mailfrom=Michael.Roth@amd.com; 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=1686544051; 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=aRmnZV9+q0iWnxivqpSKbZUlVCI+wjQITiyoM9Ekv08=; b=n0R8D29UC0doJnr+tNQTw4BDwNoH/16mL+b5f6UlUX6IeeSsFKZzMsbaj/ibFCsv7FoC78 oLleUrOhd42ep2edf3Zzl7iPSkQE9VB8Qtz7CLTyIeCbgB3fXdzQhvq17qoAStfuhc3af7 Irg5cYgA9NXh6xd8yR5nJtjhxx1EdCs= ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1686544051; a=rsa-sha256; cv=pass; b=s9IRr/gAdIf8qyAPziZg5ARP6LnGNsRbGTzPmJNkvVK3sq6vVmX94Z/wUmFIa30go2+vg9 Jm/HR/uNZPE5FxUIe0UlzO3sUZEJyEJ3REGy4to++NMrJYsZVMFlup8vxdKCHFXjH175t8 OYS8f7RkVt50j8ljKAYyBFVKAna48h8= ARC-Authentication-Results: i=2; imf28.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=s48ASt0B; arc=pass ("microsoft.com:s=arcselector9901:i=1"); spf=pass (imf28.hostedemail.com: domain of Michael.Roth@amd.com designates 40.107.93.71 as permitted sender) smtp.mailfrom=Michael.Roth@amd.com; dmarc=pass (policy=quarantine) header.from=amd.com ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=kVl++eSid4DAaBvxslCd3GmMmzrocTZ9rdLXfv/gpRqdyFisH9GVw3JZXXIV/G+lOSNk2OS34zp7TkWQPgykPQOzRFr0k9OcRwJ1eUqIdxbJAsyIJf6AYX7Hha6NV2HXBm1BXSwADJzHDIvYVlfUtT4wC37NliAz+xm3GV1GIIMBuC/e6tSR7rmq0WSmrrPCakFzuTD2tDd7ewMDEC/NoDm6RxkqJb5WhqWKiQ7sgbgGHwP+igb/XI0hSQLRn/0/679AcJWebHeYz9lhB4pg1iw45XBF92+WCl4qohWqEtyt6ohMLHCqOW1Errz/kxNLwcj1jwaD9iuJo44XgRROfw== 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=aRmnZV9+q0iWnxivqpSKbZUlVCI+wjQITiyoM9Ekv08=; b=h/fHsJsQ7re9v4WUgZZs0GkMMv4KlRrW0H0vrSgb7fxhajkZ9Up0rHFCvt1o86Ds5r8lyH0NdarRExZgOAGDGfwwmM40daKajeVo8tJXnu47u47RVag7m6G8mp31iuXO7kS8R8kz4yXLZFh0wCRK9MD1h8Zpd52l7xoxfB9cCCYyJqIYPL0tHv9B1dMXfKWI7vPPt0VsRfLPIBZIZ0DiE0LXgWEg2Dt055BsgdMeGdhdZRAQW1hSVkyt7I93SpQb6hMb7kmWDDEQFA/KG5zF/3QBWuOIQggJ4zqF5bX86UqLl9YHALi8nDTekr1BRkIy6ypubrmyeWyEhdpvmFTpHw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=temperror (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=amd.com; dmarc=temperror 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=aRmnZV9+q0iWnxivqpSKbZUlVCI+wjQITiyoM9Ekv08=; b=s48ASt0BZuLSJb9nucZ5nCuw/r7v7eUM5VGKcwEgMETM0TdMYhp3Da/iSy7jB7aIrqiw8GVRf5ueVKz37BO8w17h9P1E17ikLCnIUx/k9DL7vpT8nRjelC9sAczTLNmBrdn6nynKEBocT2Sy61OKwR+IbaWxoDjfavU5ykZOTNc= Received: from CY5PR15CA0136.namprd15.prod.outlook.com (2603:10b6:930:68::24) by PH0PR12MB7840.namprd12.prod.outlook.com (2603:10b6:510:28a::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6477.29; Mon, 12 Jun 2023 04:27:28 +0000 Received: from CY4PEPF0000E9D2.namprd03.prod.outlook.com (2603:10b6:930:68:cafe::26) by CY5PR15CA0136.outlook.office365.com (2603:10b6:930:68::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6477.34 via Frontend Transport; Mon, 12 Jun 2023 04:27:28 +0000 X-MS-Exchange-Authentication-Results: spf=temperror (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=temperror action=none header.from=amd.com; Received-SPF: TempError (protection.outlook.com: error in processing during lookup of amd.com: DNS Timeout) Received: from SATLEXMB04.amd.com (165.204.84.17) by CY4PEPF0000E9D2.mail.protection.outlook.com (10.167.241.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6500.21 via Frontend Transport; Mon, 12 Jun 2023 04:27:26 +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.2507.23; Sun, 11 Jun 2023 23:27:25 -0500 From: Michael Roth To: CC: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Brijesh Singh Subject: [PATCH RFC v9 10/51] x86/fault: Add helper for dumping RMP entries Date: Sun, 11 Jun 2023 23:25:18 -0500 Message-ID: <20230612042559.375660-11-michael.roth@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230612042559.375660-1-michael.roth@amd.com> References: <20230612042559.375660-1-michael.roth@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY4PEPF0000E9D2:EE_|PH0PR12MB7840:EE_ X-MS-Office365-Filtering-Correlation-Id: 2ed0c52a-060f-4081-22ae-08db6afd53b4 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: sCNboHJeVkb0hpgOeku8Xu7OKeC7TXZ2u1xhdTH7MQ2Y00/p7IcfXeDW/9Fgqr97oUI7x0XkoSGBfot4rJqw2VDQJRb21k4JtpizXwjWM5Mt1YGRXWvTxu6mpso/vTZQdkV7NpHB2IxrWmMieNGKKJ5vNMHbl8gTJfkrERd/tk/ezhWrU2ftgQIWGHHsYPZffmV/LnpUaPnncl1RF7jB3lcVlZ1e0nwkMQ1+ugCWc8JYEtVPLTfiQGISTfzWFFgbm4+Nn6WW9L9YF3yO5x0Hg4Ub7U1iksX56sIpA3lWM2mo3WQ9gljsJM0qgkx2DlPlIcpqNMXn2fAJbAVSxgslTldv4AFjDuHAc7idptaqkpHt5IrnEoQdXYt+iwIcmIyooqCflCgv8m2rbc5TAusCQQ0OO+rax6xUhCJBdiX+YMaCnFjcr5oUGxJ67bwrzg8L4QV/WtuJBQhLqxRgSVC2TLUPq0JuAEC8sovxMSQJglQH57Bh645fEAUaqsCDy85w3XbNwfmN/LfwDXxBv5axiny5KcRONq26ioxPUpfvV9hVtQXsf5u1MTHRS4/zDFhqGDk/qoLJCa/spJKY4yMqYCtmzZzrj+XoBWBj6IoAG/ox7VMlfBVml5B58sj6wbaw0fnI9gPAvtT4J1x6Gb00BGwV2StmCL6Uvohg55w8+YVIK0DfcD10PmH27Em0M+pMGycx3eoEKYibHsy+Q5E8GPkUkO/jG9xpzvwtYrfG4+/pRmWxuucF/n3P5NdJnJv7NK79LS/zNPw6li967hbyYw== 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:(13230028)(4636009)(396003)(39860400002)(346002)(136003)(376002)(451199021)(46966006)(36840700001)(40470700004)(40460700003)(6666004)(47076005)(36756003)(63350400001)(426003)(336012)(83380400001)(63370400001)(2616005)(86362001)(82310400005)(82740400003)(81166007)(1076003)(26005)(356005)(40480700001)(36860700001)(186003)(16526019)(2906002)(5660300002)(54906003)(44832011)(8676002)(7406005)(7416002)(8936002)(316002)(41300700001)(6916009)(4326008)(70206006)(70586007)(478600001)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Jun 2023 04:27:26.5235 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 2ed0c52a-060f-4081-22ae-08db6afd53b4 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: CY4PEPF0000E9D2.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR12MB7840 X-Stat-Signature: qgjcqnmcpy4mzch7ejgzx5fpkgqfuc5k X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 88E32C000A X-Rspam-User: X-HE-Tag: 1686544051-992566 X-HE-Me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Gv121m0oIBQdtVqMG1yyAifUrW2+88sWJ424G3Opxrg7ck0nXihw30wzRApH/PjjIInvQ0cJ+MtabGzMW4Fotvy3Pw0RKmXJ8s9wDxl9XeepM/Wctt5ZMeCbelxY/QT5J4uDINtB+Aj6A7gKZXpcC6JvVEkDBZz1KioTRlQVFLePlFyZEpiM2sFmeakP2TlBKn3K8NF5fARvNwPbu+fqko0VxtFN+emlx/cfI/Q== 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: From: Brijesh Singh 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/coco/sev/host.c | 43 +++++++++++++++++++++++++++++++++ arch/x86/include/asm/sev-host.h | 2 ++ 2 files changed, 45 insertions(+) diff --git a/arch/x86/coco/sev/host.c b/arch/x86/coco/sev/host.c index 0cc5a6d11b25..d766b3bc6647 100644 --- a/arch/x86/coco/sev/host.c +++ b/arch/x86/coco/sev/host.c @@ -295,3 +295,46 @@ int snp_lookup_rmpentry(u64 pfn, bool *assigned, int *level) return 0; } EXPORT_SYMBOL_GPL(snp_lookup_rmpentry); + +void sev_dump_rmpentry(u64 pfn) +{ + unsigned long pfn_end; + struct rmpentry e; + int level, ret; + + ret = __snp_lookup_rmpentry(pfn, &e, &level); + if (ret) { + pr_info("Failed to read RMP entry for PFN 0x%llx, error %d\n", pfn, ret); + return; + } + + if (rmpentry_assigned(&e)) { + pr_info("RMPEntry paddr 0x%llx: [high=0x%016llx low=0x%016llx]\n", + pfn << PAGE_SHIFT, e.high, e.low); + 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) { + ret = __snp_lookup_rmpentry(pfn, &e, &level); + if (ret) { + 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); diff --git a/arch/x86/include/asm/sev-host.h b/arch/x86/include/asm/sev-host.h index 30d47e20081d..85cfe577155c 100644 --- a/arch/x86/include/asm/sev-host.h +++ b/arch/x86/include/asm/sev-host.h @@ -15,8 +15,10 @@ #ifdef CONFIG_KVM_AMD_SEV int snp_lookup_rmpentry(u64 pfn, bool *assigned, int *level); +void sev_dump_rmpentry(u64 pfn); #else static inline int snp_lookup_rmpentry(u64 pfn, bool *assigned, int *level) { return 0; } +static inline void sev_dump_rmpentry(u64 pfn) {} #endif #endif