Message ID | 20221214194056.161492-19-michael.roth@amd.com (mailing list archive) |
---|---|
State | New |
Headers | show
Return-Path: <owner-linux-mm@kvack.org> 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 AEFFCC4332F for <linux-mm@archiver.kernel.org>; Wed, 14 Dec 2022 19:50:20 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4BB608E0007; Wed, 14 Dec 2022 14:50:20 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 46B148E0002; Wed, 14 Dec 2022 14:50:20 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2E4778E0007; Wed, 14 Dec 2022 14:50:20 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 1E52D8E0002 for <linux-mm@kvack.org>; Wed, 14 Dec 2022 14:50:20 -0500 (EST) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id D096F1C67E6 for <linux-mm@kvack.org>; Wed, 14 Dec 2022 19:50:19 +0000 (UTC) X-FDA: 80241953358.12.1B6D39E Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2041.outbound.protection.outlook.com [40.107.236.41]) by imf04.hostedemail.com (Postfix) with ESMTP id 08EE74000C for <linux-mm@kvack.org>; Wed, 14 Dec 2022 19:50:16 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=Jw+D4WFv; spf=pass (imf04.hostedemail.com: domain of Michael.Roth@amd.com designates 40.107.236.41 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=1671047417; 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=xr9WbvJ0VYPoXlLW+mpQJnYb1YLVqrmHGPL/cfLSrWI=; b=wcJlZ3xnCUswp7ntXXHulgtZsvKzSDDzDiYSmDTwGPtD+ief2xHWvl2AfbDJnkq6zR0ZDJ 3MrFt52zZ1n7Wbmwi1OMbR75ZKEQPnmvDtcjuRtvJpGXmqWPUdq1eFsoajnxJz7wNyVWOc bhDe1rdllvGZnLXpFa0DXGdcoKUcBcA= ARC-Authentication-Results: i=2; imf04.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=Jw+D4WFv; spf=pass (imf04.hostedemail.com: domain of Michael.Roth@amd.com designates 40.107.236.41 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=1671047417; a=rsa-sha256; cv=pass; b=41VMjx64QXcezwM9+eRtBp+FDQut162v1kxu2bvmk1iKq2mS0gYuC+LzM3f/cKH868aYrn HlISpgXb+fUjKetMex53/m6OhObxNkU3OY6Gua1hHXo06iAi3V3WEOpo/4oY3HAasIWrh+ iDb4RCpjFv2GCKbnP/XMmcITpTlATY0= ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=YdB1eR9TpCnHdFMks1CqIbzwKpBbSNN2pvdJbkOWQi74ZJxSFo+urEzBJUf+/4KdG/bdYO6D+Pc3pEPgaW3eH2YOFldVUqObQnkdGRRwtkt+hG97dEO/4oMYHUZC1VQ6V+rts1oqjupWjpBURF6peecw7ggIoeiaZxwAyH3E5HS0S7hXcHj6ac3TSnPFVweS9PsxVk81P++xwBzvuw3PWPvo+7GNOTqy8uWSV1q2ZRznjLxkO0nRFVTYbZH0iDBoErr94zV1PwfNGWl5ZWxHV49ylsTZfNWH99J6ad0b6XQEVZgzQAGI8tJ/W0Chj5DGh1mLri2mqkGvBq9kCQjCXQ== 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=xr9WbvJ0VYPoXlLW+mpQJnYb1YLVqrmHGPL/cfLSrWI=; b=JvvUiGuWyRCV/d6m/zLVPdSP2MoRgYoWFhCXWbDuGu/KCE/2coh2q2a4EieAarP5yFX9hrJ2an8PEVQfLDIHyjEFdBj/VfsktZzAEvTPGDD7puYVWgAN+1BI3O1YN03bSHPOT9DSWXvM7qEit6wlEBSF7YXItLrMsuaXwq1Cb+ZH/LlYaKgdZg+lvcesYbu1l+6K95X0Vrnyjbp4N8RCmPnBahbh1vxHl+NrbLb1PxJBwF73/7DxbDCbyFFkA5V+SkmuAi3STbj0dMGaVqsQewnKIkptCvMcQY2rf6tpNYyozkg18Eht/pfHDiAAkq+X/GoSj9RJisBoZbkhhO+V8w== 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=xr9WbvJ0VYPoXlLW+mpQJnYb1YLVqrmHGPL/cfLSrWI=; b=Jw+D4WFv9XAcV3ddRB16D1lc1TmfOuFIkyjAXIjGegAZrEigZhEdv18Q1TiiRG0z8lIjuGtt4saxUfx7cU27AcwUtu+71ma2BMEYa77OzwNWfEqeCcwpoDlj60DCpqTxVudyJ+4M5O/I4ymWby/FIdbS/V4Az6NvsCLAgYotckc= Received: from CY5P221CA0022.NAMP221.PROD.OUTLOOK.COM (2603:10b6:930:b::23) by CO6PR12MB5475.namprd12.prod.outlook.com (2603:10b6:5:354::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5924.11; Wed, 14 Dec 2022 19:50:14 +0000 Received: from CY4PEPF0000C978.namprd02.prod.outlook.com (2603:10b6:930:b:cafe::79) by CY5P221CA0022.outlook.office365.com (2603:10b6:930:b::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5924.11 via Frontend Transport; Wed, 14 Dec 2022 19:50:14 +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 CY4PEPF0000C978.mail.protection.outlook.com (10.167.241.139) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5924.10 via Frontend Transport; Wed, 14 Dec 2022 19:50:14 +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; Wed, 14 Dec 2022 13:50:13 -0600 From: Michael Roth <michael.roth@amd.com> To: <kvm@vger.kernel.org> CC: <linux-coco@lists.linux.dev>, <linux-mm@kvack.org>, <linux-crypto@vger.kernel.org>, <x86@kernel.org>, <linux-kernel@vger.kernel.org>, <tglx@linutronix.de>, <mingo@redhat.com>, <jroedel@suse.de>, <thomas.lendacky@amd.com>, <hpa@zytor.com>, <ardb@kernel.org>, <pbonzini@redhat.com>, <seanjc@google.com>, <vkuznets@redhat.com>, <wanpengli@tencent.com>, <jmattson@google.com>, <luto@kernel.org>, <dave.hansen@linux.intel.com>, <slp@redhat.com>, <pgonda@google.com>, <peterz@infradead.org>, <srinivas.pandruvada@linux.intel.com>, <rientjes@google.com>, <dovmurik@linux.ibm.com>, <tobin@ibm.com>, <bp@alien8.de>, <vbabka@suse.cz>, <kirill@shutemov.name>, <ak@linux.intel.com>, <tony.luck@intel.com>, <marcorr@google.com>, <sathyanarayanan.kuppuswamy@linux.intel.com>, <alpergun@google.com>, <dgilbert@redhat.com>, <jarkko@kernel.org>, <ashish.kalra@amd.com>, <harald@profian.com>, Brijesh Singh <brijesh.singh@amd.com> Subject: [PATCH RFC v7 18/64] x86/sev: Invalidate pages from the direct map when adding them to the RMP table Date: Wed, 14 Dec 2022 13:40:10 -0600 Message-ID: <20221214194056.161492-19-michael.roth@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221214194056.161492-1-michael.roth@amd.com> References: <20221214194056.161492-1-michael.roth@amd.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain 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: CY4PEPF0000C978:EE_|CO6PR12MB5475:EE_ X-MS-Office365-Filtering-Correlation-Id: 3d79f132-52b7-4d84-b876-08dade0c6b04 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: CINFwuHUrf+qXKJFcBtDD1EA7g1DtHRzzXorcqC7/ltyMhn3JjCaJqWXuX4dMCaIPLWeJmtAITv/C26Tft1pokla+mfexCY5IZyiEf1An20JTmpjRwWvwRjCKfhd+ydA35YePOU03kzU9LltPrGDGzjrW3GXPDbC6UbVUjoo45yiO3z93GC4sVpMWqbkyRBvCNctv95D0jp0x8LUNe+qlJ0CV5ee2lk/cvdlTpbzfplm0isRsePWIGLavjJP/qJOBB12sEhiKvFYCJGeDpvwhO8eVdkOEiyxYKULT3+BCK5YmeFrDHSKk8N3cq0VwOL9YSKww6SVz4KtCqoqusLEb0ikEqKgYON1HXq5o2Xae0aJKdhFkX+6eUUxPrmaPp05D3QHyxIcN0l6mFtfb+j5nCtBXTPhqVT5XxHoDwvL4fAH+kwEJgZaQXpKe+5aMP3lO84F32ydsR59hu7UsTeYpuvNPyPYD62l6GUVTx852Z05Cpf4dkd1uF4WxHYfIz5IjXx7y2i4QK+D/eSQoggjb0EGhSoswffYFRB11nZfmY6wQ9Lx24y8mXUGUNrzod7dFgmBICXxxUgMuFdGFSwsUaxzkZXjmVLeX0AlBBKrV1MpamOICjoiMa2hVLZau3xaQXn7P9m5wog+QvPsYfHrkAiv4n9y6qMQjSVuy1K8rTtTYz2ESik1sIZg5LEuy6avL9iK9kQyFkcCBRh95ZnQVTiLWTYOGx4bm0eBGtZ3Gqs= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:CA;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230022)(4636009)(39860400002)(136003)(396003)(346002)(376002)(451199015)(46966006)(40470700004)(36840700001)(36756003)(2906002)(7416002)(7406005)(40480700001)(36860700001)(40460700003)(5660300002)(336012)(8936002)(44832011)(86362001)(1076003)(2616005)(81166007)(356005)(426003)(47076005)(82740400003)(83380400001)(6916009)(54906003)(186003)(316002)(16526019)(82310400005)(4326008)(41300700001)(26005)(8676002)(478600001)(70206006)(70586007)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Dec 2022 19:50:14.1855 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 3d79f132-52b7-4d84-b876-08dade0c6b04 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: CY4PEPF0000C978.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO6PR12MB5475 X-Rspamd-Queue-Id: 08EE74000C X-Stat-Signature: rhiod76gm6sxqrsetnzukgi4zu6n76yd X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1671047416-11817 X-HE-Meta: U2FsdGVkX19N7o3nP/Acl7eI4JmH3B7hjwvLqoirWqHZvxSUXjC3h3VeptW0Y74xnldDFFbRhb8mY9+0OrTkvqcIYxfDXSEe6BIhnKN+098otAQtKXR6DdXHdd4iXNPiBwIrY6q32ubute+SqUJ4G1K3qtLD+TA+xZTGQ0W6DanwhRIfo4tTv2paWCedJrNPItnlENUGEUbi/sKQsUv1b9kKx68k4DEzzj2u1ssOkzZfKyDM+GAc1uilts1vXvvq3gdZCdVg4R+Zy71rJ1ylXVvdiPg+dnj2pOXbqtIOFf7FQU8SoT3/Uvwr/+cB3SsfaBi3qhUhulyGu2zaqGFyPds8N7RpEYzEy6C3UmeoYsXpvBDuGWSwLDQP/FkWt+LTySx8+3UqahqUbr5GwmY7H0OZUrZLwtheiIH/qOdtcq/72rSgsFD/UehH+K3BSSTyRab2vweD8JRxeNocghVTbw6LVouXGp2P+IcxQNjkqwSjhM8utFJLRwcEbxp8NFpD36dA2rWB+anIvg1fIYx3dElXyL/xvoqSyz1FrBfVxN5AwmWch0MloPVFwD/KneCT6aHsvgJQtgu7k2PLUqKINMyII+3aKHHwyzhp986wIXbnJk5OrSSsxlrhuzCSkdZ8Khga3n3IJhukm55E1JdWjhGH2e7nInVyR1rjbFhkS3SSrL1ei7WWsXBrjaUa1n1Q5/otFciaWhlBaNcTKAVTJNVhHnBYUQngP1rhrPPwKrktu63ox8VM11eU2JSlfC1Pwwe2e8ttLm1e4tiqFYpAY8gyrasgWDhMVhLFdCSd4oksJdN3xzO9rYmJBYJxHY8nsXm/xoLadeUC+SKCHj8q3L0llC7G43vDaAlF4rMJF4iO2xtKf7WPmZ8Si8xcDi7rZh5Yhjvv6bPV2S+VSZdFpt2L38RX7spZOi0ILOnaQwS0p7W/jujX0xdS6m4ffCWH6WM+Cuy43H5qDeFPGgD rmniGVZE 3+NgT 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: <linux-mm.kvack.org> |
Series |
Add AMD Secure Nested Paging (SEV-SNP) Hypervisor Support
|
expand
|
diff --git a/arch/x86/kernel/sev.c b/arch/x86/kernel/sev.c index 67035d34adad..e2b38c3551be 100644 --- a/arch/x86/kernel/sev.c +++ b/arch/x86/kernel/sev.c @@ -2549,15 +2549,40 @@ int psmash(u64 pfn) } EXPORT_SYMBOL_GPL(psmash); +static int restore_direct_map(u64 pfn, int npages) +{ + return set_memory_p((unsigned long)pfn_to_kaddr(pfn), npages); +} + +static int invalidate_direct_map(unsigned long pfn, int npages) +{ + return set_memory_np((unsigned long)pfn_to_kaddr(pfn), npages); +} + static int rmpupdate(u64 pfn, struct rmp_state *val) { unsigned long paddr = pfn << PAGE_SHIFT; + int ret, level, npages; int retries = 0; - int ret; if (!cpu_feature_enabled(X86_FEATURE_SEV_SNP)) return -ENXIO; + level = RMP_TO_X86_PG_LEVEL(val->pagesize); + npages = page_level_size(level) / PAGE_SIZE; + + /* + * If page is getting assigned in the RMP table then unmap it from the + * direct map. + */ + if (val->assigned) { + if (invalidate_direct_map(pfn, npages)) { + pr_err("Failed to unmap %d pages at pfn 0x%llx from the direct_map\n", + npages, pfn); + return -EFAULT; + } + } + retry: /* Binutils version 2.36 supports the RMPUPDATE mnemonic. */ asm volatile(".byte 0xF2, 0x0F, 0x01, 0xFE" @@ -2578,6 +2603,17 @@ static int rmpupdate(u64 pfn, struct rmp_state *val) pr_err("RMPUPDATE for pfn %llx succeeded after %d retries\n", pfn, retries); } + /* + * Restore the direct map after the page is removed from the RMP table. + */ + if (!ret && !val->assigned) { + if (restore_direct_map(pfn, npages)) { + pr_err("Failed to map %d pages at pfn 0x%llx into the direct_map\n", + npages, pfn); + return -EFAULT; + } + } + return ret; }