From patchwork Mon Oct 16 11:50:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Roth X-Patchwork-Id: 13423110 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 B05B6C41513 for ; Mon, 16 Oct 2023 11:52:13 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4F45A8D0065; Mon, 16 Oct 2023 07:52:13 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4A59B8D0001; Mon, 16 Oct 2023 07:52:13 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 36BA28D0065; Mon, 16 Oct 2023 07:52:13 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 263188D0001 for ; Mon, 16 Oct 2023 07:52:13 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id E8972120741 for ; Mon, 16 Oct 2023 11:52:12 +0000 (UTC) X-FDA: 81351161304.16.89BD3E2 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2081.outbound.protection.outlook.com [40.107.223.81]) by imf22.hostedemail.com (Postfix) with ESMTP id 0B98BC0020 for ; Mon, 16 Oct 2023 11:52:09 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=ZvnukhVo; dmarc=pass (policy=quarantine) header.from=amd.com; arc=pass ("microsoft.com:s=arcselector9901:i=1"); spf=pass (imf22.hostedemail.com: domain of Michael.Roth@amd.com designates 40.107.223.81 as permitted sender) smtp.mailfrom=Michael.Roth@amd.com ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1697457130; 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=QpTF5ISBAxLP+TjLWKpFyWZ7IGLMCLFMl9FnoZfCrV4=; b=gImIdy6f2BeijE+1/+5pU+GhPCZihLbTkeHjiNCMSmo5aBSusf7/3P2j6O6wLEE38BduNR 3f24evSfVdDFwrRAwDi+vmPsDkv74mb0X1IkSqe4NNG3s3vSJYP/NDDtGrU+c2potCHwIB lo5xhdcivR8JzZISOrVkZ14u+BhtY74= ARC-Authentication-Results: i=2; imf22.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=ZvnukhVo; dmarc=pass (policy=quarantine) header.from=amd.com; arc=pass ("microsoft.com:s=arcselector9901:i=1"); spf=pass (imf22.hostedemail.com: domain of Michael.Roth@amd.com designates 40.107.223.81 as permitted sender) smtp.mailfrom=Michael.Roth@amd.com ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1697457130; a=rsa-sha256; cv=pass; b=MRm9RRwU4wttVt1BFj774LIEP4xFe+7fzKohPToJ3k4vzWYnkZWOY8DtC34/D9J6BHOY2K M5F0R2BYXwuDm3/44EK02VfbAkjQCtDjhu9yYvDSe2qdrG3Bchr91JvwkBvS82w1A0q+9e 9LCL34ivc4nwwzEBuAjCdYPT9vSOhFc= ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=YngqZPT8GeGWhC8F111ic+vicnsCbRcXDHN8xiOS3bYLDK03MuIdce2aKGBiU1qoko/lI2eM3xz8wGCnrMUbkwc3GA6gBiGHjK/bRH15IXRvWzOYXel8LLHWWw2qloX6B5TpDdOjfUtrubY6KzLbSZ4d6egaQ7IGObP6KzmbR9Sf4STqujSMmTREaLsodsMQWMMELpqXy5a+dkEHEpuV9YOYx0IXW+4rSycgpEq2hVO4SgWIVGIVYOxhqGr6nedzf1nLPmQmNdUsRQUUsq2v5F6XHnaIYCmOtl2ihny2nL+Ds5UUYRFArJHVbDF3i1TgNTzVEvBazquXwhrdSQPWiQ== 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=QpTF5ISBAxLP+TjLWKpFyWZ7IGLMCLFMl9FnoZfCrV4=; b=Jp7mVb7QwTVTzRtjOBm4slB4fRunH9ePkAR8oHRzDxJjOK485WzST1Jz7Fzpg8htXsv31rcofe7zTYptuv+F/YOwLB5joW2N/8eDrDLI0W3pWYx4Y1XvGzX9+/LGmQaK0tK/uFGXn6t5kZ7SdDoH4n80WARxoTTsscEk1G6fNJsnGXvRTglhkDLvJ7duPJ+jJvGVAJIZ+AApQh6ji/OEDwwpbVADX+bYZhO2rt4SkvVtPKpdZ+BYcF9a8WsYbcoks4KlmDFn1rcBkDqDZD+nuidTH2zAfeJKknY3xX1YnyXsyeE1noAPL0cvUriAX1Qp6kEnUaA0ssP3aRxI/zrb3g== 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=QpTF5ISBAxLP+TjLWKpFyWZ7IGLMCLFMl9FnoZfCrV4=; b=ZvnukhVoC6kQBZP/6sKTwAC64oGLCg1fxOYLfA/kLZqxwL8WC4qssqyzI8bmhFQLJatwjvQM2+Pi9WQyFlEXyp1e2PO5l+zFAUQKvR/OXmj2Td1uXT3HoS83GHnEAp+DgwKHdi8WVsgprxSOZJJUfAYBkhwC4DLhzFCkPXr+5FI= Received: from CH0PR03CA0364.namprd03.prod.outlook.com (2603:10b6:610:119::15) by DS0PR12MB9276.namprd12.prod.outlook.com (2603:10b6:8:1a0::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6886.36; Mon, 16 Oct 2023 11:52:04 +0000 Received: from SA2PEPF000015CC.namprd03.prod.outlook.com (2603:10b6:610:119:cafe::20) by CH0PR03CA0364.outlook.office365.com (2603:10b6:610:119::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6886.35 via Frontend Transport; Mon, 16 Oct 2023 11:52:04 +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 SA2PEPF000015CC.mail.protection.outlook.com (10.167.241.202) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6838.22 via Frontend Transport; Mon, 16 Oct 2023 11:52:03 +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.27; Mon, 16 Oct 2023 06:52:03 -0500 From: Michael Roth To: CC: , , , , , , , , , , , , , , , "Matthew Wilcox" Subject: [PATCH RFC gmem v1 1/8] mm: Introduce AS_INACCESSIBLE for encrypted/confidential memory Date: Mon, 16 Oct 2023 06:50:21 -0500 Message-ID: <20231016115028.996656-2-michael.roth@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231016115028.996656-1-michael.roth@amd.com> References: <20231016115028.996656-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: SA2PEPF000015CC:EE_|DS0PR12MB9276:EE_ X-MS-Office365-Filtering-Correlation-Id: 44632831-91fc-43cb-e3ce-08dbce3e5098 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: OsebtnEQYofdoRWjybAht+iGibpV+J3ZDQduagw/JDnjLyY2agfF3DZhK7AYcilBH5C6V+PgjsMg6s3QbDEofKPdbUqhyaKssZWRaWhZjBOE9msFhmAuB0RBXImKjRadWnkwGiLstWa8QcdyF5bTO+lSImttp00dEMe8P8DPg47EvC96d2zvMOpViG42V7TNlFaFTW1aafcrGHDfINC3g2NrqxW23AbTYx25dp1ZaPhBwmXtI+KVHqM8+gyRmCxAIzqjLT0DFVRuhNI6RW9Xi5TOhlEc23x1aq3n0RCHwGLdnSQTxac0XrieLWdwtYVmx3HU1G0SH+4VGAJk/7N+JfboK/E56dVF43Prhzgkh4gjO93xfUV1bY84LM4/ftHQ+z314M/slUrYeNS3WPNns18ml0aCQzgxsisgMp6QSkD5zF0hV9HUG/pw+dlrK2OfU439fqmFLnL//bR5HT1cA+pgj33Vbbupp0eTxAfzFuee9XislTtUykev3NGYTMJ9cGbzEyWKgD8PPzUGQvArWQlpXGINdUpsRL8ugYKuFxvjR53ESMLpEnZduaWnGBm97y/MwI1x8qBmqH5nklEdvfrK2Y5awwaT/Ia60Y/vYUvd2fw9Lwi1gGIROsgCv6uYiMalgpTgcEtaLx9JOrzOFGqUQFfRr8+hEoQZUdiDkvV3HfnKJSFPoibHXsEC0sD5U8MMBQpdTQUiKwgE39wWFFZeuipTH2YqnTbxre7hkt+pEFlEaP/gaxOBAk6ScHep 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:(13230031)(4636009)(39860400002)(346002)(396003)(376002)(136003)(230922051799003)(64100799003)(82310400011)(1800799009)(186009)(451199024)(36840700001)(46966006)(40470700004)(966005)(478600001)(6666004)(82740400003)(356005)(81166007)(36756003)(86362001)(40460700003)(16526019)(1076003)(2616005)(426003)(26005)(336012)(83380400001)(316002)(6916009)(54906003)(70586007)(70206006)(41300700001)(5660300002)(8936002)(8676002)(4326008)(2906002)(7416002)(47076005)(40480700001)(36860700001)(44832011)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Oct 2023 11:52:03.7923 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 44632831-91fc-43cb-e3ce-08dbce3e5098 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: SA2PEPF000015CC.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR12MB9276 X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 0B98BC0020 X-Stat-Signature: 1fngoqjsqkhj1mqeuyq4w5ss7tm7dx4t X-Rspam-User: X-HE-Tag: 1697457129-369751 X-HE-Meta: U2FsdGVkX1/URJVWHXi3EpIbB8+YmAkcsksxlRe9psidoYPutlVvo1gIl6jBo1HlAvOWQIsSFVZDT/MKtfxDV0h3r4TveO3cShNgcg9odoxXZgTKmN8YIoSaPycD21foo132yM/l5k0Kav/sQuVrAxTgKtuDod4XRjBrSrQn7zDEgeR52ajSmnNrMwD9L/GVNqMYnJHpPaSdG6Cbsi8h3W0qWidZHWT2CRABCFd3NAdDZb5+njCSDFC88GCH4e9r98q4VGlA7vkZ4aVNFGvQgo59sc5FrdwXBU38zL5XZ0isVTZ6BV6A0b5k96k47Qa+6AdwZRIE7MKMNuxcU3/mdPkZZcinP1yUh7raHArT2uydLFvMhHZd3Wio8+1SbuaVjWH6cCuujnW/RbpQ0SWZPlP/H/dBCnz5iuFVnGt7juDJYUCQMdaa52Nvtn5HY2toY4F8fetLvExrT9nbFAQDDVODjRwfLWojb9VXxmfumph12G8MDQDrKpiyfQ5jLxBRgdGjzzMeMLHpn6ROzca+v9OfyVLvrkkcssZQ5vdhWPcwJfw0MpALofD54qLaJBOnFv31pImJvic67BUBwFfbYYZNyWXSPZ9AHm8HdFrIYlNpGaVdIW49U11C6u4pP3OgJSMevyvHeT4uRXPSYBLmGacq6KP5lQtyvCIgqkPmnXvB69kPFUBpMs1dss62RwokiLUiSTV+v29dt6RdUIFMFcAicJnzf+u0nD9iEJLAD+enQGixxKqgVoYiTHFMIblXvFu9EnJvSSz87b/lnI6JSlUcQWyjRwVYUN8fX1WF2QxCgDsjjCCBIG6Jg6pbpKV9EQDllFmpuV8Ie0XR6EYwGDyk3cnW8HE7rxpKbEQmfVGwxU6R6FC7VP8PbE2eA1GnwZMZtDNsBrurC6qvMsbZDZ4kQE/aXqvuZaLPdkmIeMRqc9fa3h7Ig+JTrvKo19HmsdznjL6Wsozlhooe0oc swYdEpGH Qo1SmN1+hPuP1uZNsuMJd9veEy+THF0dF2h1VuJhlLsPtXcL96pGTDtlqd6HlHbLZUz2S9bkRR0ZxiQJZYUM7HRXsQWrYB2C82/WEP2JnkQ1s8JEAqQxdA5KzlA711KWAQgx7YDS8T6q681rpo8izLL0oFhgMn/gx0q4tICC90QcTz4QG1KmA6wjs4h9bgqBXLHxBPXLtTSy/5aY5V7TsZyKD+a44LRyX/DjnuFxtmWC+0MKARVT74zjrZ7olPgzDRIPaxMMRDaPTaLaOFrdtXKT3PgKo5rtJhRErOIQnmx50CxddK6XEUr7rGooUTv158cXNHvAN3m7Sn/2oBFxO/ivRKxGt7eXh25DH8xiJf8R8UQVRuu97Hmfg5uonmqBBLQKO/EsG9yWwe0tO+1ICs0jXoIXudNdot7BTRUJAH7kexGcDdAnsjcYDC1A0d1DIHm6VyYXd0IauW9O0Anjsctwn2ISFnAy5iLxrWAgJEAKoei0V5Gc9Xm2UtrCFs+ePFBAIYhvcuAS5ugY= 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: filemap users like guest_memfd may use page cache pages to allocate/manage memory that is only intended to be accessed by guests via hardware protections like encryption. Writes to memory of this sort in common paths like truncation may cause unexpected behavior such writing garbage instead of zeros when attempting to zero pages, or worse, triggering hardware protections that are considered fatal as far as the kernel is concerned. Introduce a new address_space flag, AS_INACCESSIBLE, and use this initially to prevent zero'ing of pages during truncation, with the understanding that it is up to the owner of the mapping to handle this specially if needed. Link: https://lore.kernel.org/lkml/ZR9LYhpxTaTk6PJX@google.com/ Cc: Matthew Wilcox Suggested-by: Sean Christopherson Signed-off-by: Michael Roth --- include/linux/pagemap.h | 1 + mm/truncate.c | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h index 82c9bf506b79..9e79cf48f67a 100644 --- a/include/linux/pagemap.h +++ b/include/linux/pagemap.h @@ -205,6 +205,7 @@ enum mapping_flags { AS_LARGE_FOLIO_SUPPORT = 6, AS_RELEASE_ALWAYS = 7, /* Call ->release_folio(), even if no private data */ AS_UNMOVABLE = 8, /* The mapping cannot be moved, ever */ + AS_INACCESSIBLE = 9, /* Do not attempt direct R/W access to the mapping */ }; /** diff --git a/mm/truncate.c b/mm/truncate.c index 8e3aa9e8618e..0d80bcc250af 100644 --- a/mm/truncate.c +++ b/mm/truncate.c @@ -233,7 +233,8 @@ bool truncate_inode_partial_folio(struct folio *folio, loff_t start, loff_t end) * doing a complex calculation here, and then doing the zeroing * anyway if the page split fails. */ - folio_zero_range(folio, offset, length); + if (!(folio->mapping->flags & AS_INACCESSIBLE)) + folio_zero_range(folio, offset, length); if (folio_has_private(folio)) folio_invalidate(folio, offset, length); From patchwork Mon Oct 16 11:50:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Roth X-Patchwork-Id: 13423111 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 39B5FCDB465 for ; Mon, 16 Oct 2023 11:52:33 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9D5E48D0066; Mon, 16 Oct 2023 07:52:32 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 986588D0001; Mon, 16 Oct 2023 07:52:32 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 84D908D0066; Mon, 16 Oct 2023 07:52:32 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 71D998D0001 for ; Mon, 16 Oct 2023 07:52:32 -0400 (EDT) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 4E1A9A088B for ; Mon, 16 Oct 2023 11:52:32 +0000 (UTC) X-FDA: 81351162144.26.4825CE1 Received: from NAM02-DM3-obe.outbound.protection.outlook.com (mail-dm3nam02on2087.outbound.protection.outlook.com [40.107.95.87]) by imf19.hostedemail.com (Postfix) with ESMTP id 6EBE21A0003 for ; Mon, 16 Oct 2023 11:52:29 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=QyYLeFe5; spf=pass (imf19.hostedemail.com: domain of Michael.Roth@amd.com designates 40.107.95.87 as permitted sender) smtp.mailfrom=Michael.Roth@amd.com; dmarc=pass (policy=quarantine) header.from=amd.com; arc=pass ("microsoft.com:s=arcselector9901:i=1") ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1697457149; 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=k9F4dMH6wTBPjd0LQYAclw+pyXgphEr5kdLSN2lHbR4=; b=kCRYF/zQgX2aUjLGFVfVoUR7lW/NamEsA5Z5JtnQyVwNVsOx5J6zOVFIfD2/AkDatfweP9 s3hZIJlRKIlWqg3nLaUF5M3OWvQbt6ZPRSIM1pAPpnsQ9+J8dhH/+d/VaTy+nr5ehHPYYC MBoaXjV+vCB//ZxZvDdNNuZ27Ri/xlE= ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1697457149; a=rsa-sha256; cv=pass; b=HdYUpMxxj5Bf2SKLJ5cGwD1GqL7peN69jXfTiIkZOz96Ww7i+L7k51FchViX+Qy1Ql7do7 7V/ypnqIEmVIcLeAG3AKMVPc2tVTy9Db0fZ5HaGrWJ60R15j3maIIsSpz9EDi9GxeGEer0 UtOlIJD9WSFs40fkp91CbWEW9bQKfK0= ARC-Authentication-Results: i=2; imf19.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=QyYLeFe5; spf=pass (imf19.hostedemail.com: domain of Michael.Roth@amd.com designates 40.107.95.87 as permitted sender) smtp.mailfrom=Michael.Roth@amd.com; dmarc=pass (policy=quarantine) header.from=amd.com; arc=pass ("microsoft.com:s=arcselector9901:i=1") ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ZqMl//xKByAMUfcftWj5ijZuA8tG81tcR0aYqJzySZPs24fk0mw+2kIZiOswgnjSnj8eFvxqn+jpp0OC4JXxSbfa/rkVdRn98WE/wIXJzkS5X5i2gB8ByZ/gfcoKtTJK5ZsF0Jero8936U0lY7GnJRMc3FkBHM3+v523PuHTQItYkSdQzB3x6HXWz5C595pM9nDopC3ifykFYLp2mR8JghTt4xvy4YCIuPBjZqVgxhBWbo5EY9OcvDV0+IF9QY/8zCSgqkVSXIRNK5BBJXKKY4eN4FVqkcsWOEf8KcWqbsarAcORq/+YMzjIyGw4u+JyrnhNU+Ds9UlnGu6Pxga3Ag== 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=k9F4dMH6wTBPjd0LQYAclw+pyXgphEr5kdLSN2lHbR4=; b=CR9vgVtOlY/IuaF3ws2/RHrBPxh7/UU2WPcKbgqb2ZVz3/hk5oJFlRmOLlnzC97tolV4jMXl6DBxEGS934C8GZFKdVNrKvQp0Jx4zAJfhxj1nV3I6tkimH4xJmfDgyXtIRQBnX6iloC+3LDNEQeY1JHf1vRDe000OBpIIT4mDp9vNXEDYDkfPMFCqDefIbPDON8T9lVCeX5S+G0wKcXnk3PEvRKnxft7dlnWGrLruNRAlfmyUD/Za6WFwFkgCh0qNTjVbqV+2/FOnjn4J15+pv0X3ANdNWGP25F/7LBgolQ6OWrxxMUyXZSRtS3OPkgSqi5yJQ+T8RQIQtzUMpfXkw== 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=k9F4dMH6wTBPjd0LQYAclw+pyXgphEr5kdLSN2lHbR4=; b=QyYLeFe5cToOPhzUBURBpyqocN3BXbLUa2iqtGiepPsd5PLVesWJFivq9X0AsHK7YXLzZ7aD3NUFzAvqmPjur/C5YRWqf61f4mUSPaVSFNy/tHC24mkIoVEH53pWeeguSbuMvvX3Dm0letQwaioWIrHzf7gunaO9IsZz5KhHcmc= Received: from SN6PR04CA0100.namprd04.prod.outlook.com (2603:10b6:805:f2::41) by CH3PR12MB9395.namprd12.prod.outlook.com (2603:10b6:610:1ce::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6886.35; Mon, 16 Oct 2023 11:52:25 +0000 Received: from SA2PEPF000015C8.namprd03.prod.outlook.com (2603:10b6:805:f2:cafe::86) by SN6PR04CA0100.outlook.office365.com (2603:10b6:805:f2::41) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6886.35 via Frontend Transport; Mon, 16 Oct 2023 11:52:24 +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 SA2PEPF000015C8.mail.protection.outlook.com (10.167.241.198) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6838.22 via Frontend Transport; Mon, 16 Oct 2023 11:52:24 +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.27; Mon, 16 Oct 2023 06:52:24 -0500 From: Michael Roth To: CC: , , , , , , , , , , , , , , Subject: [PATCH RFC gmem v1 2/8] KVM: Use AS_INACCESSIBLE when creating guest_memfd inode Date: Mon, 16 Oct 2023 06:50:22 -0500 Message-ID: <20231016115028.996656-3-michael.roth@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231016115028.996656-1-michael.roth@amd.com> References: <20231016115028.996656-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: SA2PEPF000015C8:EE_|CH3PR12MB9395:EE_ X-MS-Office365-Filtering-Correlation-Id: ab6f675d-ba53-4dbe-7d4b-08dbce3e5d04 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Uoav+3Enfcy5yEECewIFnLCUzdeDnNqgY21IFHnAaXjtD9TQoipvpYi1F4Mk3NdLivfOqHUZ5m6ETCKVSd61VMsDPkocOK1oj28wIqs2vqC/XHzxyKYbB/aRrEhI2gjcp198swPDqhoKK5h0hjONdG1BRiV4+rrE+O6UDGNoQ9tvXxnEOlBzOGkezlBRgoKX8GiMTsGV4iTEX6/jS8nmPCZnXPfQiSAydRV26VeJ2j5pqtInGfFuQqHySH8jzjuAflzgr3sKTL6FyIwAGW65sQls2UJRAuTUBaVcq1OcxfW3h9p8dFLqyvxW1K/vnkK6GyOdW4oXuyPQU4ZE9OYc4H7Tn7LnzKOJTni2ZhSWaCtSrPvT4n64wxB0jGORQKZ2Mx1/9H9NI+BONb96F40YsXUvqo/eXjLiEkvYbAyRSJPKe+QnGQvMwOGAQa8bV6gDNSdQyGQDcjhep8ymrz0AFdLxSV8XX89TSoIAiuS7T8ylO91GhTu8shAYSrhzzmiDDWTPuj+q2ThjbVdtIoCNQv0yvNjT9XfYS/tF+044Mln2gaQWvD+Ves2UinLVFMgrkU3hwB9bp8AbCvkLKzNuI0Af4SPwuYNZlyWmfm4wY0IfdypASU22FRFPGHU56aKDwqodP4fIiD6l7htNFtgJaK0ZPEnmoCf3UPrEBHvpZnglMC4dwvtgAsfz4ZOPqS/K6GCCV3jsG7ZilysUJpXGIYwWmAqv4NP/jwMd9dG6UR8pgSzrkQUYfeA0WTBWMeIawx5qWlTj70IZUwfNEBliZw== 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:(13230031)(4636009)(396003)(346002)(136003)(39860400002)(376002)(230922051799003)(82310400011)(451199024)(1800799009)(186009)(64100799003)(36840700001)(46966006)(40470700004)(40480700001)(5660300002)(44832011)(40460700003)(2906002)(1076003)(26005)(36756003)(2616005)(426003)(336012)(83380400001)(16526019)(82740400003)(356005)(81166007)(86362001)(36860700001)(47076005)(7416002)(966005)(41300700001)(316002)(6916009)(54906003)(70586007)(70206006)(8676002)(4326008)(8936002)(478600001)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Oct 2023 11:52:24.6301 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: ab6f675d-ba53-4dbe-7d4b-08dbce3e5d04 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: SA2PEPF000015C8.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH3PR12MB9395 X-Rspamd-Queue-Id: 6EBE21A0003 X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: qwer7db9aun4fqgje7u6bykgic7nywok X-HE-Tag: 1697457149-215261 X-HE-Meta: U2FsdGVkX1/MAIasQXjfSINgey7dauAQM/oCojlfxvbrc8XXyzICoNEzPlrFie1rdVZ8qf3ZYw862FwP9m5KebwhDLUpxNuEodz18H7fl4uxMdWspJXXeV9Nrt/6Q3Bl8Gs6xHdzSfqNv5R1U18qlmhIvEUy0hWXEJ9DPFlHRrvWh5p9WC6C2Y4TgM+jqqqgrDztONOByjuE87/XfDMc02gML6Fd3hY1ghV5P8AHlovnvMg7R3KJ1um+4mcNpfKe8jXvHQS5GLrZuvGPb0OdWU5EATzbJVhmApiyOk6GZ1JGJHUyxQLYpsInN0VduxpYEhAHW/r0R78rGh+lxFcB5isvSaDhUFDYK9JBIO663vaIO4ZP9nAhqOsYQiUXVUHPCSeB3yhdAjvpHBfsVfmIf0DEdlD23c8D+L3RRtinPRN/4fzIxHk3hPtSUHH6CqaZpRLTF2dvGq1+7M6cg4zGQ2kdBZqiE41B0h4c0i1jAQXaNpw+VHpffaOwF2aTUW903tR0RelBEjf7W9+HvcR7UZCehMu7q8A+OaDRcCy//pwjrNvr4/RUGnNyPTeeflUG+hrZyLkVFOwjAGqYdhkmG56Erhdo0I7ZqusHiT43xq+GLaXLU1M/mIO0SvS1c1Mils1qA/jTBt2lk5qRE8YKX/1xwdrC0SHnfAuRryaTH6v01FgfOGhtqYCM7KzUWf+XoJieciRu+GEmjFqDy9JD/nkzMhyA5Jy4btujFqFNTO/yGPztv7D0RbLbwiIwtJ1L8tv15jY9Sd3YAvBKAB69mybw2vdvL5xzHuCbKcbLYmguiiWY4ChbtGk3UpYOHumP/xgoH+acnSE5o2yzYhV0tQN0VRJjqV47ZL3P4isDkye+X0QteOSW9/K/Y7m6iO8gBMUvZPD0DfTrez2VrGDMWmt3hoK9D0keFDBoyMBIb0++c3EoxvTgTQ76Q39t3EMGPD9xzGI5y26DQ6m0sbG cIU3F5f1 0EWtEb7a01aKgYDJhdGDFknRfuJ810/9VFF8oY1lAHEJEZkcyD15W6MOhNWIbCgGaPUgXlxyDwK+XU8HD4M1/WciFiI7iNByWr6zwxxzcNnHJplAHnSKDcpU5aB8AdDdIacK6leKvHP8EuXXT4dZOdsRte5nOslDf9Fmo1WMnJnMavwUWMJyQrPipIW7iBpvWwF6I3MKMi/nJGL8gxxFjOGziNq0L83rOL2ZcSrgLpyFRFa4uy+HBTzDTS+cDl6hFaDP/GO5oCUJMwW1wY66N6rccCQFzK/duFH2YUaJDM+2N5KNRTmDx/a7HZPpVa7cScMcsDWZk4bw3BheT+zGOWmtKxU/441GcHAM80kdRlfaWgzboABHx2Y9GmiTyrAGz4GKxyugQfbf7vk9BTuNLszXIwqdBvfKSnwbUIxApWOcsNoqnYraMdQhumO/et5rUb9tf9tbQEGoOFfBTC2EAnH6T0Q== 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: truncate_inode_pages_range() may attempt to zero pages before truncating them, and this will occur before arch-specific invalidations can be triggered via .invalidate_folio/.free_folio hooks via kvm_gmem_aops. For AMD SEV-SNP this would result in an RMP #PF being generated by the hardware, which is currently treated as fatal (and even if specifically allowed for, would not result in anything other than garbage being written to guest pages due to encryption). On Intel TDX this would also result in undesirable behavior. Set the AS_INACCESSIBLE flag to prevent the MM from attempting unexpected accesses of this sort during operations like truncation. This may also in some cases yield a decent performance improvement for guest_memfd userspace implementations that hole-punch ranges immediately after private->shared conversions via KVM_SET_MEMORY_ATTRIBUTES, since the current implementation of truncate_inode_pages_range() always ends up zero'ing an entire 4K range if it is backing by a 2M folio. Link: https://lore.kernel.org/lkml/ZR9LYhpxTaTk6PJX@google.com/ Suggested-by: Sean Christopherson Signed-off-by: Michael Roth --- virt/kvm/guest_memfd.c | 1 + 1 file changed, 1 insertion(+) diff --git a/virt/kvm/guest_memfd.c b/virt/kvm/guest_memfd.c index 9ffce54555ae..f6f1b17a319c 100644 --- a/virt/kvm/guest_memfd.c +++ b/virt/kvm/guest_memfd.c @@ -398,6 +398,7 @@ static int __kvm_gmem_create(struct kvm *kvm, loff_t size, u64 flags) inode->i_private = (void *)(unsigned long)flags; inode->i_op = &kvm_gmem_iops; inode->i_mapping->a_ops = &kvm_gmem_aops; + inode->i_mapping->flags |= AS_INACCESSIBLE; inode->i_mode |= S_IFREG; inode->i_size = size; mapping_set_gfp_mask(inode->i_mapping, GFP_HIGHUSER); From patchwork Mon Oct 16 11:50:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Roth X-Patchwork-Id: 13423112 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 0EB19CDB465 for ; Mon, 16 Oct 2023 11:52:52 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A24838D0067; Mon, 16 Oct 2023 07:52:51 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9FAD68D0001; Mon, 16 Oct 2023 07:52:51 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 89DC48D0067; Mon, 16 Oct 2023 07:52:51 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 776788D0001 for ; Mon, 16 Oct 2023 07:52:51 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 53F2B1A0928 for ; Mon, 16 Oct 2023 11:52:51 +0000 (UTC) X-FDA: 81351162942.06.3F1BBE6 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2075.outbound.protection.outlook.com [40.107.92.75]) by imf27.hostedemail.com (Postfix) with ESMTP id 40CDD4000A for ; Mon, 16 Oct 2023 11:52:48 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=3k1PRWuD; dmarc=pass (policy=quarantine) header.from=amd.com; arc=pass ("microsoft.com:s=arcselector9901:i=1"); spf=pass (imf27.hostedemail.com: domain of Michael.Roth@amd.com designates 40.107.92.75 as permitted sender) smtp.mailfrom=Michael.Roth@amd.com ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1697457168; 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=myaxqRX3xLPJ3eviVJraa3ck6aG2KJ+tPZVXN0+ejzE=; b=8WWlp6L9HE8hZ7FeETrKZDPJF4S2aam6IPSgc9gQSFIqByQqlDD8WhTmEeNM3qDMQ9JjIJ 0IUmnysbmfyaFS1J/uYUmwyhggFmNOK7au5NS83umIeLBTM6ZSQycsQ7xjRUvlrz3n+xDW S7hqjLUE6IhaISkmlbzj0mntUHjV3L8= ARC-Authentication-Results: i=2; imf27.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=3k1PRWuD; dmarc=pass (policy=quarantine) header.from=amd.com; arc=pass ("microsoft.com:s=arcselector9901:i=1"); spf=pass (imf27.hostedemail.com: domain of Michael.Roth@amd.com designates 40.107.92.75 as permitted sender) smtp.mailfrom=Michael.Roth@amd.com ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1697457168; a=rsa-sha256; cv=pass; b=WWgcEsQ8t8YUygWGapsxndNLYequ9tQCNEFa7MySB6UxIRIbAUzY3qQzEtnPsD8IZlYC1i T3ShCKc/g8SROEjP7wIajQyi9BgiX2gjlBO+WgPcpHiPYwUCwQQAuhrQRjn6g5G0DIvzhZ GpOlfAFmNqHlS9pnhAsV6r8TCzZfdEo= ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=OdWqE1thXxGFfRkxhXJ28a4XP0cf9YYiXIusSkZQU80Ad2UGtKIJwMG+yKdQxqHQ9Q72X7kS9A4aoB0pCARQI8UndZW2f8ncInAmT4HI9DTpGXn1PBy0PW9DLSTMYt74kLWwP1ugPCmmmbq1XKfTezlW58hXLXlk5V1lvtzjEvR/cNgvNBx11y0y9A5SehCX7MYmKwfmK6WCEqrA84mtcPuj6bZX9b9Td5qj9cGuwOyJwdRL4KqR9PQYgtWCX3gmVPGE85aaPx4Ful7NwJIzDYond5XHlIk8zVrI9VCJwujiKSbO1bB3w1rI15LICaB2K7DFiGyCsDm04XrCOsrdgQ== 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=myaxqRX3xLPJ3eviVJraa3ck6aG2KJ+tPZVXN0+ejzE=; b=c3rqVGXrzBaazmwbnIyCKV0PFjg7Jc8TuW1ACP50TfTqtU2JIv4sKLDHZ9AxeocrHqgWFxcKPy4yodYYLHFyT/Iu8X9ddCsIJkEXbyaRnygMyqUzGwtdoOMI6OvrepBFZA4zTL5C4s8vDcfIFX3gBeuDjY7JxxwHsQmu38IbrPFiiwPlIwAEbYQILUOHw6ylboh+6K+zpSQltdJH7P4/JGm7nm7f60MFGAuLF6sfi4cK+5AukxRE3SxJ2428cwzwOyJd+DN31wckVxuHF8DIDEaQtqqU6q0fxjS+6hO6e55/1TFr002Azeyrs0LpI3cf57ZqUYFnTXpQFcIhXux2AQ== 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=myaxqRX3xLPJ3eviVJraa3ck6aG2KJ+tPZVXN0+ejzE=; b=3k1PRWuDUDkKPMFa/BhgH5GiUYoElydg2VQIrN0vPWW9Q5Rka4fHj8O/KIMt7kWO5EEFh+RHTqXXBknQH8e8ssF2r6unRpEL4YlwjDchRDo6eeYoWCITco0aH34QVit/STgdPtZ1fHd/Anav0cmkwLyxWhgHtVl99yp5zyOFBn8= Received: from SA0PR11CA0140.namprd11.prod.outlook.com (2603:10b6:806:131::25) by CYYPR12MB9013.namprd12.prod.outlook.com (2603:10b6:930:c2::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6863.45; Mon, 16 Oct 2023 11:52:45 +0000 Received: from SA2PEPF000015CA.namprd03.prod.outlook.com (2603:10b6:806:131:cafe::34) by SA0PR11CA0140.outlook.office365.com (2603:10b6:806:131::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6886.35 via Frontend Transport; Mon, 16 Oct 2023 11:52:45 +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 SA2PEPF000015CA.mail.protection.outlook.com (10.167.241.200) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6838.22 via Frontend Transport; Mon, 16 Oct 2023 11:52:45 +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.27; Mon, 16 Oct 2023 06:52:44 -0500 From: Michael Roth To: CC: , , , , , , , , , , , , , , Subject: [PATCH RFC gmem v1 3/8] KVM: x86: Add gmem hook for initializing memory Date: Mon, 16 Oct 2023 06:50:23 -0500 Message-ID: <20231016115028.996656-4-michael.roth@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231016115028.996656-1-michael.roth@amd.com> References: <20231016115028.996656-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: SA2PEPF000015CA:EE_|CYYPR12MB9013:EE_ X-MS-Office365-Filtering-Correlation-Id: a9010232-301f-44db-cfff-08dbce3e696f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 2RFk8QZpR5yLnAalGBWGJE/kqNFJNqTnlKfS+FsLvRr820WRw/VCQ0AYvsOzlF7Tc6odA9wlHhaLrLgG+0EEgGgqbFHwEQNubWiTv7V/efgoQnC5QOfW5PMXql8c65SL2TA2tvHQWm7U9qWCGWLG+6qNdQ+3FcZ8C5EwbY6WNrsLFN8f03yHhcMjmEGYNwFm0tRda9vrfmIvUcegK5RTbJXEDZl2Gka/J4vPMRc43WFwTsLwOi+lhFAGJvVLIMx3FcxAly7Umf+DUJvw0P0r5dsfmdDhKp4IhXENEMdtsxipVEI9uxmMPsBwWEUjd/gQ+EhJEcJmFBZhjKaQkMSrrQKk96/lssvNDfSVXyiccwG1eaTaKw4Iqx62l6rAj73Ct1/dmoRShDSQ5JcEj4q+HNxqRmVgcC8MIy79oXVy0hVxvjUuw8Ib7jV+qTWXuszpQbqpKdiX9JawFwo98LdhOb7llB/lsBcHLoqZnBfkZLDFVdZVSXIFqLw8u0P95O6xm2fAHJUL7XE+LLyevhmuffTCFeI5KDsVLVuL48c6IN3KgcBffTfoJRBZ8QcwA9v3noSuM+wC6yLr1bV+HSwXbYVNaoIyff68tRHEjLF2biveAlODBE+xGt8QZ4uz+4sXrIsip9pOL1oloz6PiOD3D8ybxk5wshUbaAT8WQfRCmDmu/YabQvhhN+IyW5ZWJWrwNAVE8670XQpQvwEAk2NMOvWv8gSKyVmYOmCCjOrveqTIvc9YeuSA/+9lGjBhn7SJY6LFs63ADcGKdH9phU93g== 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:(13230031)(4636009)(396003)(39860400002)(346002)(136003)(376002)(230922051799003)(82310400011)(1800799009)(186009)(64100799003)(451199024)(40470700004)(36840700001)(46966006)(36756003)(40480700001)(86362001)(40460700003)(41300700001)(316002)(6916009)(54906003)(70206006)(70586007)(81166007)(82740400003)(336012)(356005)(16526019)(966005)(426003)(47076005)(36860700001)(83380400001)(2906002)(1076003)(6666004)(26005)(2616005)(8676002)(4326008)(478600001)(5660300002)(7416002)(44832011)(8936002)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Oct 2023 11:52:45.4661 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: a9010232-301f-44db-cfff-08dbce3e696f 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: SA2PEPF000015CA.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CYYPR12MB9013 X-Rspam-User: X-Stat-Signature: kkrdgdedcmkkgwky7pyod8rkzo9o5sqn X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 40CDD4000A X-HE-Tag: 1697457168-119446 X-HE-Meta: U2FsdGVkX1/iAF+z36wVMZEVbkdjvC/upgYFH8YQ5RQ+1FVAKB1XG128QWdwg/pq/mljz+KT+C7+ghI8Bd+B75Cenjx3Wqdy5GhEfVgmEeJxshIMAidPVwUe/C74ij5macreIj3t21Rm13eEGV4YjfL47kH7BzzdbdV2Mdwt+Y+26/XAuVGM7GB0lZduFz4j7UQiDAN/VK8b0ZpVJ1rCAi3GfP+GuPMi77Cl0dQGwDaP6dP87bCuM+VSLfrj8ZOhpBUtPM0zSH6Wvsjgufi0v5d0imb7jU08lOTgny9fN6zcj/fK+A1bYm4yHLG3PUE/MiouWGj8FLg0Rj+j0+BZqieSBQxW+g136Vn+heAva+G2apPQW8SE6e2/RVe39PTd8mKkg0M0AmhzkgQ5CAg2jkxu/I+e9F/RJuzhEVb2jEcAM0XTiioqkv13xj0smUPOTx+LFwmeOry+DXOhcOgVgOgfwNra7ELV8uKp3L7YmN2+OYjGxQEDXH1d3TZbzvooItmhnyUwb7OWYhEW/VtjkWoeqq+M98vrWC5oBcXgWy4G2JdFyqlBSHSWRXUZWkCgyULrn1YOvZaw2qB/aUjmDSXkeb9kVCq5cbEeZ18CoCHajMHabXuVR9n9a/1vESbgE7c6JkhvF03rX97AuYtcXcn+hhs6i2DXQlAOOSGtYpch/3mibG4I1PhJDg/aCABbkBRSHXSQ5xYsr1Q0twIb/K0TL/4EDNZ3W8tITywPuoMRqDqgfw7eZ2LGONfj5RTOHkyVN5TpIaPuM7SE1OBU37gPpZl5du26tX8lbLF55kkUBLWAAvo+MtWs02608hsDITYwl7vNFa4eHkDvbIKkx6/y63AV2omrscf3s4JtnXZxMjKsi1/psElDxBG3xqWdbn8jaArdapFu0YLQk4wuXF4XGXRj4llljgYzhTBRDwrPV+7UIs3xz0hhUIWQdUEUQnEEmdO7XO/exQD7Dtn 6a17g0KQ sTbKlgnqGgkqtcazq3GfOwZo2K2tETWFgsMOVyFa5J6Kde+fGxsNmL9HFE0JVAn0Db1Y74ZREx5H0b7cjxCoA4lKGM8xTFn1MUtW5JcRyAqy9u7vPnS/tkQoo+FA+PJhpX7S0Q7g5eGp4RTkxj9wtnKzAXr+1cAeg6h/uWnu4kJ3ckcJeiTDxg1oNkpwm3bAkuKRR0DlOGlHun5OxbZ5CNs1J1T9DlRqk2xWuSdYR5G+4D0KJ10vdyZEX3IRc0NPnhuBceFm1loN2qE7S4a4wVnQBwCYHmTilVWAFP70FkqnoRafujzWXo3HjSs/OtmMF8HSqcrulZVaRvWloXLngQOn+oze6dk4KllRglUKuyI429ffsC9yWVKMGbkLK0ysxdEsdQwAeiRmoz0++CfRHkfq89yysSeZJlUw/ 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: guest_memfd pages are generally expected to be in some arch-defined initial state prior to using them for guest memory. For SEV-SNP this initial state is 'private', or 'guest-owned', and requires additional operations to move these pages into a 'private' state by updating the corresponding entries the RMP table. Allow for an arch-defined hook to handle updates of this sort, and go ahead and implement one for x86 so KVM implementations like AMD SVM can register a kvm_x86_ops callback to handle these updates for SEV-SNP guests. The preparation callback is always called when allocating/grabbing folios via gmem, and it is up to the architecture to keep track of whether or not the pages are already in the expected state (e.g. the RMP table in the case of SEV-SNP). In some cases, it is necessary to defer the preparation of the pages to handle things like in-place encryption of initial guest memory payloads before marking these pages as 'private'/'guest-owned', so also add a helper that performs the same function as kvm_gmem_get_pfn(), but allows for the preparation callback to be bypassed to allow for pages to be accessed beforehand. Link: https://lore.kernel.org/lkml/ZLqVdvsF11Ddo7Dq@google.com/ Signed-off-by: Michael Roth --- arch/x86/include/asm/kvm-x86-ops.h | 1 + arch/x86/include/asm/kvm_host.h | 2 ++ arch/x86/kvm/x86.c | 6 ++++ include/linux/kvm_host.h | 14 ++++++++ virt/kvm/Kconfig | 4 +++ virt/kvm/guest_memfd.c | 56 +++++++++++++++++++++++++++--- 6 files changed, 78 insertions(+), 5 deletions(-) diff --git a/arch/x86/include/asm/kvm-x86-ops.h b/arch/x86/include/asm/kvm-x86-ops.h index e3054e3e46d5..0c113f42d5c7 100644 --- a/arch/x86/include/asm/kvm-x86-ops.h +++ b/arch/x86/include/asm/kvm-x86-ops.h @@ -134,6 +134,7 @@ KVM_X86_OP(msr_filter_changed) KVM_X86_OP(complete_emulated_msr) KVM_X86_OP(vcpu_deliver_sipi_vector) KVM_X86_OP_OPTIONAL_RET0(vcpu_get_apicv_inhibit_reasons); +KVM_X86_OP_OPTIONAL_RET0(gmem_prepare) #undef KVM_X86_OP #undef KVM_X86_OP_OPTIONAL diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h index 95018cc653f5..66fc89d1858f 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -1752,6 +1752,8 @@ struct kvm_x86_ops { * Returns vCPU specific APICv inhibit reasons */ unsigned long (*vcpu_get_apicv_inhibit_reasons)(struct kvm_vcpu *vcpu); + + int (*gmem_prepare)(struct kvm *kvm, kvm_pfn_t pfn, gfn_t gfn, int max_order); }; struct kvm_x86_nested_ops { diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 767236b4d771..33a4cc33d86d 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -13301,6 +13301,12 @@ bool kvm_arch_no_poll(struct kvm_vcpu *vcpu) } EXPORT_SYMBOL_GPL(kvm_arch_no_poll); +#ifdef CONFIG_HAVE_KVM_GMEM_PREPARE +int kvm_arch_gmem_prepare(struct kvm *kvm, gfn_t gfn, kvm_pfn_t pfn, int max_order) +{ + return static_call(kvm_x86_gmem_prepare)(kvm, pfn, gfn, max_order); +} +#endif int kvm_spec_ctrl_test_value(u64 value) { diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h index 8c5c017ab4e9..c7f82c2f1bcf 100644 --- a/include/linux/kvm_host.h +++ b/include/linux/kvm_host.h @@ -2403,9 +2403,19 @@ static inline bool kvm_mem_is_private(struct kvm *kvm, gfn_t gfn) #endif /* CONFIG_KVM_GENERIC_MEMORY_ATTRIBUTES */ #ifdef CONFIG_KVM_PRIVATE_MEM +int __kvm_gmem_get_pfn(struct kvm *kvm, struct kvm_memory_slot *slot, + gfn_t gfn, kvm_pfn_t *pfn, int *max_order, bool prep); int kvm_gmem_get_pfn(struct kvm *kvm, struct kvm_memory_slot *slot, gfn_t gfn, kvm_pfn_t *pfn, int *max_order); #else +static inline int __kvm_gmem_get_pfn(struct kvm *kvm, + struct kvm_memory_slot *slot, gfn_t gfn, + kvm_pfn_t *pfn, int *max_order) +{ + KVM_BUG_ON(1, kvm); + return -EIO; +} + static inline int kvm_gmem_get_pfn(struct kvm *kvm, struct kvm_memory_slot *slot, gfn_t gfn, kvm_pfn_t *pfn, int *max_order) @@ -2415,4 +2425,8 @@ static inline int kvm_gmem_get_pfn(struct kvm *kvm, } #endif /* CONFIG_KVM_PRIVATE_MEM */ +#ifdef CONFIG_HAVE_KVM_GMEM_PREPARE +int kvm_arch_gmem_prepare(struct kvm *kvm, gfn_t gfn, kvm_pfn_t pfn, int max_order); +#endif + #endif diff --git a/virt/kvm/Kconfig b/virt/kvm/Kconfig index 2c964586aa14..992cf6ed86ef 100644 --- a/virt/kvm/Kconfig +++ b/virt/kvm/Kconfig @@ -109,3 +109,7 @@ config KVM_GENERIC_PRIVATE_MEM select KVM_GENERIC_MEMORY_ATTRIBUTES select KVM_PRIVATE_MEM bool + +config HAVE_KVM_GMEM_PREPARE + bool + depends on KVM_PRIVATE_MEM diff --git a/virt/kvm/guest_memfd.c b/virt/kvm/guest_memfd.c index f6f1b17a319c..72ff8b7b31d5 100644 --- a/virt/kvm/guest_memfd.c +++ b/virt/kvm/guest_memfd.c @@ -44,7 +44,40 @@ static struct folio *kvm_gmem_get_huge_folio(struct inode *inode, pgoff_t index) #endif } -static struct folio *kvm_gmem_get_folio(struct inode *inode, pgoff_t index) +static int kvm_gmem_prepare_folio(struct inode *inode, pgoff_t index, struct folio *folio) +{ +#ifdef CONFIG_HAVE_KVM_GMEM_PREPARE + struct list_head *gmem_list = &inode->i_mapping->private_list; + struct kvm_gmem *gmem; + + list_for_each_entry(gmem, gmem_list, entry) { + struct kvm_memory_slot *slot; + struct kvm *kvm = gmem->kvm; + struct page *page; + kvm_pfn_t pfn; + gfn_t gfn; + int rc; + + slot = xa_load(&gmem->bindings, index); + if (!slot) + continue; + + page = folio_file_page(folio, index); + pfn = page_to_pfn(page); + gfn = slot->base_gfn + index - slot->gmem.pgoff; + rc = kvm_arch_gmem_prepare(kvm, gfn, pfn, compound_order(compound_head(page))); + if (rc) { + pr_warn_ratelimited("gmem: Failed to prepare folio for index %lx, error %d.\n", + index, rc); + return rc; + } + } + +#endif + return 0; +} + +static struct folio *kvm_gmem_get_folio(struct inode *inode, pgoff_t index, bool prep) { struct folio *folio; @@ -74,6 +107,12 @@ static struct folio *kvm_gmem_get_folio(struct inode *inode, pgoff_t index) folio_mark_uptodate(folio); } + if (prep && kvm_gmem_prepare_folio(inode, index, folio)) { + folio_unlock(folio); + folio_put(folio); + return NULL; + } + /* * Ignore accessed, referenced, and dirty flags. The memory is * unevictable and there is no storage to write back to. @@ -178,7 +217,7 @@ static long kvm_gmem_allocate(struct inode *inode, loff_t offset, loff_t len) break; } - folio = kvm_gmem_get_folio(inode, index); + folio = kvm_gmem_get_folio(inode, index, true); if (!folio) { r = -ENOMEM; break; @@ -537,8 +576,8 @@ void kvm_gmem_unbind(struct kvm_memory_slot *slot) fput(file); } -int kvm_gmem_get_pfn(struct kvm *kvm, struct kvm_memory_slot *slot, - gfn_t gfn, kvm_pfn_t *pfn, int *max_order) +int __kvm_gmem_get_pfn(struct kvm *kvm, struct kvm_memory_slot *slot, + gfn_t gfn, kvm_pfn_t *pfn, int *max_order, bool prep) { pgoff_t index, huge_index; struct kvm_gmem *gmem; @@ -559,7 +598,7 @@ int kvm_gmem_get_pfn(struct kvm *kvm, struct kvm_memory_slot *slot, goto out_fput; } - folio = kvm_gmem_get_folio(file_inode(file), index); + folio = kvm_gmem_get_folio(file_inode(file), index, prep); if (!folio) { r = -ENOMEM; goto out_fput; @@ -600,4 +639,11 @@ int kvm_gmem_get_pfn(struct kvm *kvm, struct kvm_memory_slot *slot, return r; } +EXPORT_SYMBOL_GPL(__kvm_gmem_get_pfn); + +int kvm_gmem_get_pfn(struct kvm *kvm, struct kvm_memory_slot *slot, + gfn_t gfn, kvm_pfn_t *pfn, int *max_order) +{ + return __kvm_gmem_get_pfn(kvm, slot, gfn, pfn, max_order, true); +} EXPORT_SYMBOL_GPL(kvm_gmem_get_pfn); From patchwork Mon Oct 16 11:50:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Roth X-Patchwork-Id: 13423113 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 BD3BFC41513 for ; Mon, 16 Oct 2023 11:53:12 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 590088D0068; Mon, 16 Oct 2023 07:53:12 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 540E58D0001; Mon, 16 Oct 2023 07:53:12 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 408818D0068; Mon, 16 Oct 2023 07:53:12 -0400 (EDT) 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 30E138D0001 for ; Mon, 16 Oct 2023 07:53:12 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id EF9A4C0BD7 for ; Mon, 16 Oct 2023 11:53:11 +0000 (UTC) X-FDA: 81351163782.28.FA6659C Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2069.outbound.protection.outlook.com [40.107.223.69]) by imf13.hostedemail.com (Postfix) with ESMTP id 074C020009 for ; Mon, 16 Oct 2023 11:53:08 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b="33/tX8f5"; dmarc=pass (policy=quarantine) header.from=amd.com; spf=pass (imf13.hostedemail.com: domain of Michael.Roth@amd.com designates 40.107.223.69 as permitted sender) smtp.mailfrom=Michael.Roth@amd.com; arc=pass ("microsoft.com:s=arcselector9901:i=1") ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1697457189; 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=sHeU96y7Mcw+wZiGNEIwGSVFMnPqa/uZ2RPQzjKaLYY=; b=E4dmN8uoIpgG4ZYC5V1Cyw3XU9ITzA34/BwIq0cFxjR5aUo+mgrRYPZ67Klp8S754Atx/R DRVBu58OSVs2zb9fN0c4bBcwZpMYvx3QgbDdVAAYZlKpVe6dLhZbItQHcSU1DjyWSazeOs S1tMfyQB34Xeyy5S69x0ib5rje3zLgU= ARC-Authentication-Results: i=2; imf13.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b="33/tX8f5"; dmarc=pass (policy=quarantine) header.from=amd.com; spf=pass (imf13.hostedemail.com: domain of Michael.Roth@amd.com designates 40.107.223.69 as permitted sender) smtp.mailfrom=Michael.Roth@amd.com; arc=pass ("microsoft.com:s=arcselector9901:i=1") ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1697457189; a=rsa-sha256; cv=pass; b=MlpTizly/BOjPALVjopsIBzjxUll1VSEgBxpjNuQq5/5fQW51R0TjyGq2I2xbrOSqQt3CH Sqyr44UO2RVTH4AzbZSDjgwUAKYhyC8DsQbgJLSxHwj5J3KhXed2NU1Fw3cLmE2BKiORDc kk2Zpj9N7gcN73wyttR5zx6V6MZrJXA= ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=DWzLXIgqbWTF1RnfxItauirZXCkYwCGCUq/Xhyn3UTITNYrKZyfDPpnLz5OkG9mlQdF03lucmrUJKMDnbuKBiiLjN8IgQ5Tc0GLpZetjFeW+x4wnQrpWpCzIbp/2/V8op/DFi2qiyvNdooJC+vZO1+jThk6pSzucn6NtKqouJCQ9C+35Z5lBPxHUk2q2P6dZSFQ0XZr2nARdCSEhBgU/aNhsUXeaFl16Vs2zk6cMGTmHneXnYFiWBWf+Y1gsAe16iumr881CXVBu15P0A+zAgBL7vsIqdqQPhp5+71WQEpUUEltcgrvMjt6xkODpXwyQcyMZ2Q5o40iQ5U4g9btPqA== 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=sHeU96y7Mcw+wZiGNEIwGSVFMnPqa/uZ2RPQzjKaLYY=; b=ZhUQU4LVy7DH5PmP+pMASLUzE20Piq02KcmxmoUdfNtklc7Ku6GBh4B/1WieOf352gU8LrRtB08MfjL8180q0lClzjlpOsPejqjvNRO1qT/BFFPM8KZ4BRFovJb7OSo/8t6fq93n5JBoZJuISh+iHMEj6CcoIowT7/oLQUC27ZmEWeN7aIoAc2Ud6lEUf5/kAt0AemwlPcGJkmQx6TuqsPx9MypY0Qy8wpgnvWA9Mz5y59sA+jzPcfxS6a852pq/jsV0wKn1y5nrQJcmyzZhNERXnLcZJmsbZ8eIDb5tm1FWE2AVVBEVzN9zpjsWGg9RKqllvogU1QuC0fEAJ1mdEg== 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=sHeU96y7Mcw+wZiGNEIwGSVFMnPqa/uZ2RPQzjKaLYY=; b=33/tX8f5087Ab3OA7QNTH0Z4m46LYNH3TlyJ9QMx9NDGCSICTakSeHCG5UB/91OFYFKB4Te8b3Rt1DzNLuP5FRCUg/kuwgAZPVR6pfoReMbDXVhe22TkBVv5hU7yXmw9vOJcg/Ty+PbIPtlYSnONgOHEmdBQuJ64vdGGyaxkTk4= Received: from SN6PR04CA0075.namprd04.prod.outlook.com (2603:10b6:805:f2::16) by DM4PR12MB8569.namprd12.prod.outlook.com (2603:10b6:8:18a::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6886.35; Mon, 16 Oct 2023 11:53:06 +0000 Received: from SA2PEPF000015C8.namprd03.prod.outlook.com (2603:10b6:805:f2:cafe::da) by SN6PR04CA0075.outlook.office365.com (2603:10b6:805:f2::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6886.35 via Frontend Transport; Mon, 16 Oct 2023 11:53:06 +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 SA2PEPF000015C8.mail.protection.outlook.com (10.167.241.198) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6838.22 via Frontend Transport; Mon, 16 Oct 2023 11:53:06 +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.27; Mon, 16 Oct 2023 06:53:05 -0500 From: Michael Roth To: CC: , , , , , , , , , , , , , , Subject: [PATCH RFC gmem v1 4/8] KVM: x86: Add gmem hook for invalidating memory Date: Mon, 16 Oct 2023 06:50:24 -0500 Message-ID: <20231016115028.996656-5-michael.roth@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231016115028.996656-1-michael.roth@amd.com> References: <20231016115028.996656-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: SA2PEPF000015C8:EE_|DM4PR12MB8569:EE_ X-MS-Office365-Filtering-Correlation-Id: 9170734a-5cf0-4296-24f4-08dbce3e75db X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 7PtZ3Hu+5EP0OsApGAx3qKT/gSk/u5UTyE7maHyZdGjE7TAd/vlCUWXmsj2WbSDpCosDlCC/qwYw6k/OIWUr5ZAcO8XeNrduZ0jI/S6L2uZgooTd+JHeDwQh7PTiDOqwiouIk/soP67Xuj9Gk1uCX8OC+aNi+niP1Ms5G0ImU3j4tNvYS1GEovHpRtGOFKgDPTJxMX1Vxh8qjRWK16EFnJxYzyhNFa1F9IXKDEINrCr0LSHV9IS9ETdfBT5vyRxerNI/s4Q34Rq+tGsb4vD/vY7z2gbHzeqr/zfizwJRSS2W1/hhRTqXaqHfQPTw5pFLSDNL2oyjmqJeIGVkqidY65xKEJbX9pFOYOL7F9DDeK8pb/oIn2KGbhU7aKOjgK5laahoM8GsH50hEbqwDnJhzZM8qHj98Y1CQd96yMh9DzPuaomiJIUTy+2uJ9uz6YSZ8v3/0WhErxhykDPHv+NHmpxjrfxdREsntg8ccWI+JxFzIVEmCGRbmrJ1uYxSw+4Q/u2/q4ezoc81UtAf8ZF60DNfQ4xphqcqjgIyBfAiKtmwmc+kqpAIWkTm2HrOaMxwTCoYXyeW+MvyFKBVpcB18pCxqL0h2m0LqmsRELWJJCFzZq7AwliNejjLerWbz0GwkCbgO+RiW85J4YEp0TuHwF4MDLdtOVlDzHIzlcUXre1mNndlzu+tZtidUHyoYk7xwC7520DvxbooENPGd4Whuo4s21sKP2z0WCm8aZXIgmQiLVbWTmJpwNXTujWafsJSOmXvscjE++q+WKDwWtigAg== 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:(13230031)(4636009)(39860400002)(136003)(346002)(376002)(396003)(230922051799003)(186009)(1800799009)(82310400011)(64100799003)(451199024)(40470700004)(46966006)(36840700001)(70206006)(478600001)(70586007)(54906003)(6666004)(6916009)(1076003)(26005)(16526019)(336012)(426003)(316002)(2616005)(8936002)(7416002)(4326008)(8676002)(2906002)(5660300002)(36756003)(44832011)(81166007)(86362001)(47076005)(36860700001)(83380400001)(82740400003)(356005)(41300700001)(40460700003)(40480700001)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Oct 2023 11:53:06.3022 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 9170734a-5cf0-4296-24f4-08dbce3e75db 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: SA2PEPF000015C8.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB8569 X-Rspamd-Queue-Id: 074C020009 X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: 8ubu6pquj4dmjic6r1ong1qs53wjpzzx X-HE-Tag: 1697457188-22083 X-HE-Meta: U2FsdGVkX1/zklqvLSXm3nqFRbPZ2WbmsZYWVUGW8HalEsVGBE2HFdBHgAA8ypl8G/qt9wo5JLwXJ1LZxFIZIX37Dhwe1C6Myv4SQnxSq0YF1R2wgZ1VBPTZ8OZh5ZOAM895r/DtDnoo/KO5d5GEx7WBDEQQdmp4jB/rnXUjj+iPD1baDIReNINqjPqvUR0kbEX87HzmHUMYEu3PKIWQRSD9C24bBt8G/bVrcwtQG5MW0eN/RpS/0ixWm00CT1NyWco0tqZbZz7GNPtSHRXC/BXK41G8FqiglWwoaMvQXegy/V09sDLWws/rsHopD1Wm+b0hjqNV6cuujigyGA1Y6a0plnJ+9OYNtkCLM6bECc5GQWLt7aBokC1ESN3C1EABvAMqherw8Z8yWaKPsu5sx0UDFhx67DTCLmOe/GDERYT2TlMia/iihdnOiVKb75mN7R768N1F0FtGPMgKU2k6TiSaYld1SLDWRp9v0WgcPltAYQFc6Q5b5EGfJExfY26j3n8cegPNY9pcHQoE4F3soGjB6lS+4KeuFvLhEMmjvK3E4IoRnWx7tE0+DSSxaPvSBOk4DD845KQa1sLF/nT0t6xap8P0Vjo/RancsJYeCLGQ94ejSV5KXOWrhLxUaUA/OywVM23SmibD1oISwZh+lsVOuVHK01oblOupQ2xuLFGI+Z9v2WtZ9/gi8xgeF86sU6IB6hYPJBY/9nUn5XkVg0ZJc/sNda5Z01ohKZ/FHPho3Xf+865cNfUR5vGJ+5M5Q4zcKLNJ2ykxPHX9IKdnocKHXbV9Fua0fC2Pi2vJtiREAtrYeclR7hfK4DBA00RjY/2QtovqNyha5z/MDnHQmaTgMJA6MFIVx+dv8nFUTT2pxY1ei86gQy3SbUrzuebecg5gQ+7YwqXLgYmghoa0BeFd29XS934EAADW1j1918TF5nbjRvE6+zGqJY0A477XIt01APi1mnDMAEchHrz +c7B1Vjr TOTTIzgIsWgx1A8R2kJYRfLvBZI609hoWDMQtKiXtrmIATLs8yj5q/9MfMqZBpHIpXZ6HOupVAQ/1dPcDH5YizXsu0s7bV5S+EYpg5rTyQzzCIEuxbSMnUw8DLSZMxDjuaDL//ENVVSd1/e2wlLOmI4s7JbV1ofOSYQliJ151wLC8qtBVa0uPHnQ2R9g9yVj/JPYHFWn863j+NxJPNpQ453AK3X2daYkuHCfABEG64yZOfBeS92fx1J26YeuPyqHIK9/5OuBXbrdUyxHwQLCsLoKmaHVG5fDIH4KriWSgOEASPo5wZ/kxUqQigIZXDwUEz1AWJaXMRBD4WV4= 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: In some cases, like with SEV-SNP, guest memory needs to be updated in a platform-specific manner before it can be safely freed back to the host. Wire up arch-defined hooks to the .free_folio kvm_gmem_aops callback to allow for special handling of this sort when freeing memory in response to FALLOC_FL_PUNCH_HOLE operations and when releasing the inode, and go ahead and define an arch-specific hook for x86 since it will be needed for handling memory used for SEV-SNP guests. Signed-off-by: Michael Roth --- arch/x86/include/asm/kvm-x86-ops.h | 1 + arch/x86/include/asm/kvm_host.h | 1 + arch/x86/kvm/x86.c | 7 +++++++ include/linux/kvm_host.h | 4 ++++ virt/kvm/Kconfig | 4 ++++ virt/kvm/guest_memfd.c | 14 ++++++++++++++ 6 files changed, 31 insertions(+) diff --git a/arch/x86/include/asm/kvm-x86-ops.h b/arch/x86/include/asm/kvm-x86-ops.h index 0c113f42d5c7..f1505a5fa781 100644 --- a/arch/x86/include/asm/kvm-x86-ops.h +++ b/arch/x86/include/asm/kvm-x86-ops.h @@ -135,6 +135,7 @@ KVM_X86_OP(complete_emulated_msr) KVM_X86_OP(vcpu_deliver_sipi_vector) KVM_X86_OP_OPTIONAL_RET0(vcpu_get_apicv_inhibit_reasons); KVM_X86_OP_OPTIONAL_RET0(gmem_prepare) +KVM_X86_OP_OPTIONAL(gmem_invalidate) #undef KVM_X86_OP #undef KVM_X86_OP_OPTIONAL diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h index 66fc89d1858f..dbec74783f48 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -1754,6 +1754,7 @@ struct kvm_x86_ops { unsigned long (*vcpu_get_apicv_inhibit_reasons)(struct kvm_vcpu *vcpu); int (*gmem_prepare)(struct kvm *kvm, kvm_pfn_t pfn, gfn_t gfn, int max_order); + void (*gmem_invalidate)(kvm_pfn_t start, kvm_pfn_t end); }; struct kvm_x86_nested_ops { diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 33a4cc33d86d..0e95c3a95e59 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -13308,6 +13308,13 @@ int kvm_arch_gmem_prepare(struct kvm *kvm, gfn_t gfn, kvm_pfn_t pfn, int max_ord } #endif +#ifdef CONFIG_HAVE_KVM_GMEM_INVALIDATE +void kvm_arch_gmem_invalidate(kvm_pfn_t start, kvm_pfn_t end) +{ + static_call_cond(kvm_x86_gmem_invalidate)(start, end); +} +#endif + int kvm_spec_ctrl_test_value(u64 value) { /* diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h index c7f82c2f1bcf..840a5be5962a 100644 --- a/include/linux/kvm_host.h +++ b/include/linux/kvm_host.h @@ -2429,4 +2429,8 @@ static inline int kvm_gmem_get_pfn(struct kvm *kvm, int kvm_arch_gmem_prepare(struct kvm *kvm, gfn_t gfn, kvm_pfn_t pfn, int max_order); #endif +#ifdef CONFIG_HAVE_KVM_GMEM_INVALIDATE +void kvm_arch_gmem_invalidate(kvm_pfn_t start, kvm_pfn_t end); +#endif + #endif diff --git a/virt/kvm/Kconfig b/virt/kvm/Kconfig index 992cf6ed86ef..7fd1362a7ebe 100644 --- a/virt/kvm/Kconfig +++ b/virt/kvm/Kconfig @@ -113,3 +113,7 @@ config KVM_GENERIC_PRIVATE_MEM config HAVE_KVM_GMEM_PREPARE bool depends on KVM_PRIVATE_MEM + +config HAVE_KVM_GMEM_INVALIDATE + bool + depends on KVM_PRIVATE_MEM diff --git a/virt/kvm/guest_memfd.c b/virt/kvm/guest_memfd.c index 72ff8b7b31d5..b4c4df259fb8 100644 --- a/virt/kvm/guest_memfd.c +++ b/virt/kvm/guest_memfd.c @@ -369,12 +369,26 @@ static int kvm_gmem_error_page(struct address_space *mapping, struct page *page) return MF_DELAYED; } +#ifdef CONFIG_HAVE_KVM_GMEM_INVALIDATE +static void kvm_gmem_free_folio(struct folio *folio) +{ + struct page *page = folio_page(folio, 0); + kvm_pfn_t pfn = page_to_pfn(page); + int order = folio_order(folio); + + kvm_arch_gmem_invalidate(pfn, pfn + (1ul << order)); +} +#endif + static const struct address_space_operations kvm_gmem_aops = { .dirty_folio = noop_dirty_folio, #ifdef CONFIG_MIGRATION .migrate_folio = kvm_gmem_migrate_folio, #endif .error_remove_page = kvm_gmem_error_page, +#ifdef CONFIG_HAVE_KVM_GMEM_INVALIDATE + .free_folio = kvm_gmem_free_folio, +#endif }; static int kvm_gmem_getattr(struct mnt_idmap *idmap, const struct path *path, From patchwork Mon Oct 16 11:50:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Roth X-Patchwork-Id: 13423114 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 EA302CDB465 for ; Mon, 16 Oct 2023 11:53:33 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8C5818D0069; Mon, 16 Oct 2023 07:53:33 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 876528D0001; Mon, 16 Oct 2023 07:53:33 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 716748D0069; Mon, 16 Oct 2023 07:53:33 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 5FE358D0001 for ; Mon, 16 Oct 2023 07:53:33 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 39511B5D98 for ; Mon, 16 Oct 2023 11:53:33 +0000 (UTC) X-FDA: 81351164706.23.87CB30E Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2084.outbound.protection.outlook.com [40.107.93.84]) by imf02.hostedemail.com (Postfix) with ESMTP id 329BB8000D for ; Mon, 16 Oct 2023 11:53:29 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=XKZggh8i; arc=pass ("microsoft.com:s=arcselector9901:i=1"); spf=pass (imf02.hostedemail.com: domain of Michael.Roth@amd.com designates 40.107.93.84 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=1697457210; 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=JzhdxTCjEnyDbbG4eHyU9AZ0euSgP8vBuvxuU2bmxv0=; b=Q7u74eaZFIzdiiCgAm+YnYYDJ/Y3/HTcSFPgvhwCg49IExhWqifGBPvUdNoTcXcPxlUiJ4 sXWyf64alXeBm1i4Wiylu25jpWt5ggk8IJICGBj9f1b3wtrNMEYX59+KSesaUUZ3zG+jr2 TWX0k4rE4QWJLRfQwnVpsDyu5QOxNMM= ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1697457210; a=rsa-sha256; cv=pass; b=J+509QGYdG7rNX2mbRj2IdqT/FL32MRb6Bzs2WtnFLJmd+7LVby30ecfvRzAOqdk/SJYj1 OiGu8r16O5jRi5dR0JnCD36QOnKigJSrfPFhrNOthevC30eCx0RD88VCPJ3wJjSHcjqbiP /QcTTUVxpTqaqZX/bDDrRcQcS70OYlw= ARC-Authentication-Results: i=2; imf02.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=XKZggh8i; arc=pass ("microsoft.com:s=arcselector9901:i=1"); spf=pass (imf02.hostedemail.com: domain of Michael.Roth@amd.com designates 40.107.93.84 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=QKcT4tFDRQScsBCCSu3M9htvRGFOR1ZoGUSICWu7qRH8XHG8w4iGt9ZqIj2XIBzzb9KVL8LyArWTKjNn3FaS0C2DItLBhzJ5L217N/1LQvWt6UVu3A5yNdGiP3TjWNbdMaEHZE75eREM8xNFNEodW3u7ZyvxRyZ5hNitwZ4KTOtk1xyv0FgToyzcP5ylEIMXgS1GSQhJiUatocFiUSQbM++OQN3jBTCg/7/6CLqg4zPoUJ3vHd90eJnVCiaYpt6lClZa2/QPuWQwOFkqF393+h88pFK2jQJBa+Wm/UFkaSNZu48JjE5g85Bff9jEyjMiK54H9tXvA6IJMn4gkpnniw== 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=JzhdxTCjEnyDbbG4eHyU9AZ0euSgP8vBuvxuU2bmxv0=; b=eu6tn2cYgTpf0wDzVPOletOKcPq1+aCpVKTU9HonRLC2Ce7UnFSZRqJu/PwTxvMXzrazCNOKx4NfzBSlQM9X7be5Vm9l7qG/bA5e2xguYD/ud+8qvWHGkvfb4rPATqG1gPoA+5k8xh25Yl0Suy89opcEN/vvqNLpoK2pG3S0COaw+t3zqUNlJc/SPELP+4xFT0myIcyDcHwEKrKzRRQG6m7nOwIzy0otTN1yC9/Fr0QfWLl3rPcyMHP1whDyJhqR1TyNearSYTFFF3V6skXRC3LIa9xOyWZ6JNSrPA37KJzFaXBrSk+gDCKoL7wdPZAA1d4CABt5vEtzBPoTu75gfg== 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=JzhdxTCjEnyDbbG4eHyU9AZ0euSgP8vBuvxuU2bmxv0=; b=XKZggh8iOk8JCtS+r6p2GGTNPrBXuWE9eNVhDrBT8sEBek77z+CzQG0Pl497uwc2vPMD3x07/CUxjBJYUKkynC0bYoKDBD2OopUxZgeN4YfCC40HAZY+6wwTALZYy1PYf17hjtIaG0Or7saoy95e9h97RheSMuYmA+GxGp3XUHM= Received: from SN6PR04CA0087.namprd04.prod.outlook.com (2603:10b6:805:f2::28) by LV8PR12MB9231.namprd12.prod.outlook.com (2603:10b6:408:192::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6863.38; Mon, 16 Oct 2023 11:53:27 +0000 Received: from SA2PEPF000015C8.namprd03.prod.outlook.com (2603:10b6:805:f2:cafe::39) by SN6PR04CA0087.outlook.office365.com (2603:10b6:805:f2::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6886.35 via Frontend Transport; Mon, 16 Oct 2023 11:53:27 +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 SA2PEPF000015C8.mail.protection.outlook.com (10.167.241.198) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6838.22 via Frontend Transport; Mon, 16 Oct 2023 11:53:27 +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.27; Mon, 16 Oct 2023 06:53:26 -0500 From: Michael Roth To: CC: , , , , , , , , , , , , , , Subject: [PATCH RFC gmem v1 5/8] KVM: x86/mmu: Pass around full 64-bit error code for KVM page faults Date: Mon, 16 Oct 2023 06:50:25 -0500 Message-ID: <20231016115028.996656-6-michael.roth@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231016115028.996656-1-michael.roth@amd.com> References: <20231016115028.996656-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: SA2PEPF000015C8:EE_|LV8PR12MB9231:EE_ X-MS-Office365-Filtering-Correlation-Id: f70f5930-8080-4575-a9bd-08dbce3e8247 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: LzzfvIWKwKJzqW7s1FdBhzKnjnlKLWYlMlFiLM/+dzgvxcAHTPPFhEH776oyfqdjBUi3NFdNF95vZ+Yifaf6kJmQa9Ihtg9mXNPyuOkE2wZsYiFVm3l3J6OyMyHs7fwz0UiT6UQ43JwNc08AI5nnjCEfKqkmhGFIOgj616R8Cp377NYo4Gr6gEqAPAvdAlgOEKLSl37XT20EWsq7P1nhK/+0ijir5L1aIUfvwKoXbfl2vwH/GffSLlCgIr/b6LJ6D93rpfdDWwRrx1Aiqiy08GVXjV/3nthw5kaNYri9M1hN24ccOaPU/5HfROISQgzlCSDImFeeJSxBx0fOQ/Kb4FxA0oRj822ZoMdakktUeQcORpH+gDwpLkx1PW+ZL41UXzu/71CvzLCa2CshsotCXEDEBSS1BtrWkawrKlj3Y3fJ/2na0JQqKRoeeSDmACOfzyq6qTZ32W1RHmWpYeEXOUdfzHWfAAHbgSBY2Q31b4nzWBFoVKckfBShmS07wDffBMhE1lmzlStbw49PtKUr4fACpSvPq/HnY3lnbZxgg1X+rHTJTjplgQOMmpMaYQu8IYmO+8S5Zy/q7MxhI+wT09CuEv4Txw3ayQ2ncZHYIUFcphEADkhjLPzYlM3kxptIbXPoMuBAYaPdpH9kZiSFVLjIglD4GuaGRTTiI2D4whrTWPPGLUbeL66c7RT9m2gw9swzJlXDmuS2ij/mfO1xaaz6mtf9CsQDbHgxNDJ4pmhkgaVz3ZcI3igKWd7Wdb9M 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:(13230031)(4636009)(136003)(396003)(346002)(39860400002)(376002)(230922051799003)(186009)(451199024)(82310400011)(1800799009)(64100799003)(36840700001)(40470700004)(46966006)(36756003)(86362001)(2906002)(1076003)(40480700001)(44832011)(41300700001)(478600001)(5660300002)(2616005)(40460700003)(70586007)(7416002)(6916009)(70206006)(8676002)(966005)(316002)(336012)(356005)(426003)(4326008)(16526019)(26005)(54906003)(8936002)(81166007)(82740400003)(36860700001)(47076005)(83380400001)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Oct 2023 11:53:27.1460 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: f70f5930-8080-4575-a9bd-08dbce3e8247 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: SA2PEPF000015C8.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: LV8PR12MB9231 X-Stat-Signature: nk66c7b5p8jigaj5yu593eo3qnes337t X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 329BB8000D X-Rspam-User: X-HE-Tag: 1697457209-208221 X-HE-Meta: U2FsdGVkX1+QoFGrziS3JKBwgc84T0sYosVcdcxckJrxM12SeU3HnZvluv5nBdmQ3rkcWDjRLZlIJUf7Y7u9hsOrjG5gCHwRQDTq/gXxbpn3zndIwyhTaF8gwTeent5G+tKKvPjlEhqQzD4+z26nNTgDlIzPuWGXUBPgR62lfTwQXbYm/9rECjKGn8CsrK9oZHQ04McVKFFtlbVx2Oojy3HakHi3VXoDnjuAouv0qt/Yte24IsMXP6vp68pJh5a3VkmOoPD6GrlDTjKfdameWxvXdIf6R9EmMDziDfeJuGz3SLnUGRNE/R2E3FXBIXPWsoGaumbsdPXugliSoLeQmLJ9Dn3fOYWFWdodonVqCs3BG0pein+lwuGfmkSnQ7cjh3/2ErnwwLIWlzt53moZHxzjesplFWFZZQ767ZX3+jpwCw3H01PhAygASiyu0e8mGdwyV+tRU+7ym593xsomDk7cg13Lh59JxnWbwnWWUPuJo7MDkzSHsutQzDUInd1ntmdABl5pJfyEU8wq5akUba7AVL7blCYyLZj3joTWua4uzTLMFyMFAVcWSkiwAEKwjm6cU0Qrp7VuWPflGEsxBb2+qdNE5QUKrrtdi/hY5vBAT9ErRjo4iGGqP+Afw4gOCoVBb5sZ9E4wP+RB49C3QXsrfaS1czMoK0J+prHsatrSqilTENX9bnKzXPwpWnGZiDLeSijO7lwKQXhYYAmJ9vsJ50w/Xb0bA3bYLibQhUQ86Ic8BZQll28PZ4d4w3LV8v1AYP1i0z7irGf1c8q9DbbW7sJsn9mJU136MzaP0zR7ghGdoehl8A0+V5KtQy8InUPIkwtTLt+KT6uNA1I/Q87EjNQNWg4mpyGRgUa1ewuH7PPuvCHvG+kMpthRj1QyQusAg1b7FqUs0tz7RxgZks453Z3y/NGUiNJY0zLR6cyHNwZekgHxNf6KEgrKKLlPBNCj+3iR5Wv+3Ek9KWz f58/Burz 0FQImIMg1BrfUxNYE/sJ7rcqCDD9f4USmWhGqVDxULVqWUAkpAEFj5bUbr2yPzI7x39klBxAbV91Ib+ju0ALTFRq54ILymr303Fn74D1lYc6k9SMwviNWXhvl1bnSxuXjo6pfTQFx0jPiYKlrnuD7kI2z6JdY29etzODzGPR/v0GQzQr0q32vbz1KAoUOmN7pQrKORzDEWy+K0KQNT2Wnh7CQMvVuEiuRBIxVv/BqSDBBgqU7MMtNlKBW1ObOxMmP1K328YwkesKL7yVQYZFShELNKBg7b2f/i7JZGjJIwkIVIBloVB01aIa2kPxWR7xC2e/pjBOMuwsKeWkynDhQBmD3cHIo2vePi2V4/npN46Kr3FrqLP0NTzc6walzW2HWm5EHd2g+GascY7zHRh46TsXJ5la06yp7fS6B 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: In some cases the full 64-bit error code for the KVM page fault will be needed to determine things like whether or not a fault was for a private or shared guest page, so update related code to accept the full 64-bit value so it can be plumbed all the way through to where it is needed. The accessors of fault->error_code are changed as follows: - FNAME(page_fault): change to explicitly use lower_32_bits() since that is no longer done in kvm_mmu_page_fault() - kvm_mmu_page_fault(): explicit mask with PFERR_RSVD_MASK, PFERR_NESTED_GUEST_PAGE - mmutrace: changed u32 -> u64 Signed-off-by: Isaku Yamahata Link: https://lore.kernel.org/kvm/20230612042559.375660-1-michael.roth@amd.com/T/#mbd0b20c9a2cf50319d5d2a27b63f73c772112076 [mdr: drop references/changes to code not in current gmem tree, update commit message] Signed-off-by: Michael Roth --- arch/x86/kvm/mmu/mmu.c | 3 +-- arch/x86/kvm/mmu/mmu_internal.h | 4 ++-- arch/x86/kvm/mmu/mmutrace.h | 2 +- arch/x86/kvm/mmu/paging_tmpl.h | 2 +- 4 files changed, 5 insertions(+), 6 deletions(-) diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c index bcb812a7f563..686f88c263a9 100644 --- a/arch/x86/kvm/mmu/mmu.c +++ b/arch/x86/kvm/mmu/mmu.c @@ -5802,8 +5802,7 @@ int noinline kvm_mmu_page_fault(struct kvm_vcpu *vcpu, gpa_t cr2_or_gpa, u64 err } if (r == RET_PF_INVALID) { - r = kvm_mmu_do_page_fault(vcpu, cr2_or_gpa, - lower_32_bits(error_code), false, + r = kvm_mmu_do_page_fault(vcpu, cr2_or_gpa, error_code, false, &emulation_type); if (KVM_BUG_ON(r == RET_PF_INVALID, vcpu->kvm)) return -EIO; diff --git a/arch/x86/kvm/mmu/mmu_internal.h b/arch/x86/kvm/mmu/mmu_internal.h index 71ba4f833dc1..759c8b718201 100644 --- a/arch/x86/kvm/mmu/mmu_internal.h +++ b/arch/x86/kvm/mmu/mmu_internal.h @@ -190,7 +190,7 @@ static inline bool is_nx_huge_page_enabled(struct kvm *kvm) struct kvm_page_fault { /* arguments to kvm_mmu_do_page_fault. */ const gpa_t addr; - const u32 error_code; + const u64 error_code; const bool prefetch; /* Derived from error_code. */ @@ -280,7 +280,7 @@ enum { }; static inline int kvm_mmu_do_page_fault(struct kvm_vcpu *vcpu, gpa_t cr2_or_gpa, - u32 err, bool prefetch, int *emulation_type) + u64 err, bool prefetch, int *emulation_type) { struct kvm_page_fault fault = { .addr = cr2_or_gpa, diff --git a/arch/x86/kvm/mmu/mmutrace.h b/arch/x86/kvm/mmu/mmutrace.h index ae86820cef69..195d98bc8de8 100644 --- a/arch/x86/kvm/mmu/mmutrace.h +++ b/arch/x86/kvm/mmu/mmutrace.h @@ -260,7 +260,7 @@ TRACE_EVENT( TP_STRUCT__entry( __field(int, vcpu_id) __field(gpa_t, cr2_or_gpa) - __field(u32, error_code) + __field(u64, error_code) __field(u64 *, sptep) __field(u64, old_spte) __field(u64, new_spte) diff --git a/arch/x86/kvm/mmu/paging_tmpl.h b/arch/x86/kvm/mmu/paging_tmpl.h index c85255073f67..2f60f68f5f2d 100644 --- a/arch/x86/kvm/mmu/paging_tmpl.h +++ b/arch/x86/kvm/mmu/paging_tmpl.h @@ -787,7 +787,7 @@ static int FNAME(page_fault)(struct kvm_vcpu *vcpu, struct kvm_page_fault *fault * The bit needs to be cleared before walking guest page tables. */ r = FNAME(walk_addr)(&walker, vcpu, fault->addr, - fault->error_code & ~PFERR_RSVD_MASK); + lower_32_bits(fault->error_code) & ~PFERR_RSVD_MASK); /* * The page is not mapped by the guest. Let the guest handle it. From patchwork Mon Oct 16 11:50:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Roth X-Patchwork-Id: 13423115 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 73281CDB465 for ; Mon, 16 Oct 2023 11:53:54 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 14B4D8D006A; Mon, 16 Oct 2023 07:53:54 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0FBCA8D0001; Mon, 16 Oct 2023 07:53:54 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EDF258D006A; Mon, 16 Oct 2023 07:53:53 -0400 (EDT) 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 DD5868D0001 for ; Mon, 16 Oct 2023 07:53:53 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 6DD1F1A0943 for ; Mon, 16 Oct 2023 11:53:53 +0000 (UTC) X-FDA: 81351165546.22.AA4D7AE Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2080.outbound.protection.outlook.com [40.107.93.80]) by imf13.hostedemail.com (Postfix) with ESMTP id 6B6B02001D for ; Mon, 16 Oct 2023 11:53:50 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=0eQBvdbE; dmarc=pass (policy=quarantine) header.from=amd.com; arc=pass ("microsoft.com:s=arcselector9901:i=1"); spf=pass (imf13.hostedemail.com: domain of Michael.Roth@amd.com designates 40.107.93.80 as permitted sender) smtp.mailfrom=Michael.Roth@amd.com ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1697457230; 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=/OHgKUYFAZCONnATUVnBIwfZqzs8EaYMPwtwwWj6zPA=; b=jsJ69pNWskkADYh+5rrrxRzoT4jivhfYJ2r2P/tMgz9wdYkk1GUm+F9Ll68c0Z1REEX4/s w3ZW4ojyzY0rAsbmd0u+L5XZyO+4mcCUzFRQdW62MG4IMYMhaZ209k4HAuIo5wOfXpcH+Z csDslGi7WMfmGUSd+Iq+cYojFMBF0m4= ARC-Authentication-Results: i=2; imf13.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=0eQBvdbE; dmarc=pass (policy=quarantine) header.from=amd.com; arc=pass ("microsoft.com:s=arcselector9901:i=1"); spf=pass (imf13.hostedemail.com: domain of Michael.Roth@amd.com designates 40.107.93.80 as permitted sender) smtp.mailfrom=Michael.Roth@amd.com ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1697457230; a=rsa-sha256; cv=pass; b=gUtY/RJEzQnwtiErrDUAWy1PHdIkDu/IaMTZ6yTG7Ga6FJYb7qUGrbv96gNufw38xpp7Zr KofWdF71mu+QQVFjKP+eIJneKDtojDICmRbL9G/R+OoEPmtaMax1XrIymvec5YRMsdTg9T 3YHyKznxbfqPfK7jjJWfslfIGVkFdKk= ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=n5CN1ZxpI+MrfKf75ATvqxNc3pBVZKPqEV0k47JRlguNoeL0f4HhR9Qk/Dr1xvC9EitCSfdv7psb4h0OXgLPLFGvL5pBA6mgn/YGbKs1okPDor2CoxVw0IV6YWrgWiaZ+T8lzeouH6pyvpBOo5XMjALLp7aNAh3HkU9xUkLwTBNMK7FjAz/kH09F8zUyGXWPCoDu3zgJYP/tJw3M7AES+eGrOYVgwogV8xCkFhuYn6JQlHLizpvQYldF+n/KWxMIwFJ3eyasd2NiGYVM/6L4yJQ4QCCMwbTh3nrxK9hADJCQCmYxT6NrCnVSefuIhZLlUW/fW4XjBKWE2NHadP4L+A== 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=/OHgKUYFAZCONnATUVnBIwfZqzs8EaYMPwtwwWj6zPA=; b=Nv9XKqQrEI8C0pYLOaLvJMDsJA2dJulq/iZ9a8stITQykhTtWkJATUvA28UXno1EAwdhuGQ7z8LSUwJ2eU46SuBIguU1yglfRYQE2reh7dVj/dmzMfaukzM6QWDPoKT8gN9A9cf01teLd2i5ZxaYPNK+xTuLNqty5KftxktsG4LyUtMpEVpHm6bMp03bk5UfQoo4oHi6D+sGaTcta8pHSfmCy8/D/wHaGLHL1pTLt5UWEcby+maA4IKP8t9/6/R9z0GxZ2MCYznjzbqpXPWRhbBt1sCi4lttCRcbdiUaeTXTKsH2QMjAiOdrprETByHBk3kpIQQfHgeEuTh5i6bVOQ== 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=/OHgKUYFAZCONnATUVnBIwfZqzs8EaYMPwtwwWj6zPA=; b=0eQBvdbEtgJNh4G0P1QDKsH9akDx+vqB2rT0NUSb0Tw71a0yNWIPJdHkK8xUlwCMJLtIzLseJKvxelamt1MTc+YMVYcOmcLQFKjz8tswpHHRSOBqJ5S6hDHsuYFtbQLK/cVibkGzmLz5cE/bPbGSZdexjn4PeBu89Uh3Ufm3Hg4= Received: from SN6PR04CA0095.namprd04.prod.outlook.com (2603:10b6:805:f2::36) by CY8PR12MB7660.namprd12.prod.outlook.com (2603:10b6:930:84::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6886.34; Mon, 16 Oct 2023 11:53:48 +0000 Received: from SA2PEPF000015C8.namprd03.prod.outlook.com (2603:10b6:805:f2:cafe::da) by SN6PR04CA0095.outlook.office365.com (2603:10b6:805:f2::36) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6886.35 via Frontend Transport; Mon, 16 Oct 2023 11:53:48 +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 SA2PEPF000015C8.mail.protection.outlook.com (10.167.241.198) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6838.22 via Frontend Transport; Mon, 16 Oct 2023 11:53:48 +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.27; Mon, 16 Oct 2023 06:53:47 -0500 From: Michael Roth To: CC: , , , , , , , , , , , , , , Subject: [PATCH RFC gmem v1 6/8] KVM: x86: Add KVM_X86_SNP_VM vm_type Date: Mon, 16 Oct 2023 06:50:26 -0500 Message-ID: <20231016115028.996656-7-michael.roth@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231016115028.996656-1-michael.roth@amd.com> References: <20231016115028.996656-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: SA2PEPF000015C8:EE_|CY8PR12MB7660:EE_ X-MS-Office365-Filtering-Correlation-Id: 3db7f415-47f2-4d5c-f397-08dbce3e8eb8 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: j+OqCqSbLp/+f5t5QRtCPHeQtMatZSancDPNeZu1R3eqdDR5vxNvR3hEGhgmLTU2hJviSfx7RiLAm/klSI3W2aoEZCrI3dSgjV/koKuepCwa6YLRRjYsU2T16+Qgu+3WzLLP9wVxlZZBQDc6pLxCO4dQ+Hu+YH1j+ofKnrdokizvx3Y40OnRqXmXh6/6/UW36GRWYXY9M0LMoKCDZZE8gEzunw+LBQa2dCWZWGlaIeY6YRwhF+7IMIHaZiMzJVciDB6Hz+kZYZhiDjFJJiUjZi0YYMvFiWtS+py/8MdtSt3spGHcpUHm8EBUc8gzbf1SrIt6cYpMwrEPrrcvuuJTTTmj2a9lMSa/4XtAsrXpmOaJH44i3Deps4E092OTOwc7wrf8i8H8eo78my3/nmSYqYi3BwimCysaVsBzOMya4B9ulogS5I+xrSKDW4DUhXk2SvUNq6ykbq3UOjoPztFyHG0gcmcs+JiXDYGxuPSPCMXpIZmd2g0QYfxb7aoG8qOikVQuRMo5gex2rbqSUis5uTkfgnmvrBoofubOclWE3VdnezIrGmFig0O65edHe7Gvs9vRkwpD1H5P5UFzQSPH/p3ob03CxkakC+OAWmU0LzmTchsXKijIJOrF99iejpHIaOjhjZiS8x3+pYQGWJrtu0I8r6c8agLYi6yNAoA//j6fcMDoCJtTVwy4WNPibvHCF5a8/bFIC5KBMzn7eUcW3QkbDJjEugmTT2T/g6+eYHYsui+Z7ZFklB8ihVFe96gpFuXW1gSx/u4d1P+Ilcw3Fw== 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:(13230031)(4636009)(396003)(136003)(39860400002)(346002)(376002)(230922051799003)(64100799003)(451199024)(1800799009)(186009)(82310400011)(36840700001)(40470700004)(46966006)(40480700001)(40460700003)(6666004)(478600001)(36860700001)(47076005)(86362001)(36756003)(81166007)(356005)(82740400003)(2906002)(7416002)(83380400001)(16526019)(426003)(336012)(26005)(2616005)(1076003)(70586007)(5660300002)(41300700001)(6916009)(54906003)(8936002)(4326008)(8676002)(316002)(44832011)(70206006)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Oct 2023 11:53:48.0055 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 3db7f415-47f2-4d5c-f397-08dbce3e8eb8 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: SA2PEPF000015C8.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY8PR12MB7660 X-Rspam-User: X-Stat-Signature: b16j9i1uhzeucxrforznowd8sxf6931b X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 6B6B02001D X-HE-Tag: 1697457230-479078 X-HE-Meta: U2FsdGVkX1/fDAXCjiO9gdOTBjKhWBk4e0qhIdKKzkKSubfho5gow3s4UUR/R8F1LlV7LCSN5Aq/HPDIx9k/jshrH0i9uqH/sDBLLv42aacX7PRH3v5S7EANg5/ZRtPU9lxbptyrG5C26zyxH2hMTzzVZKrNm7EMmpMdZcOe++RHmU/+keFJidV21nDAPbUfjweNECksh3FZl1/pGNKMdJVvAL3+XPtzfNXgOpy4vQ6/CAU54LQRFBv6pjhqmG726uc9D8Py+ZpC0Z2PG3Ijo2xuTWCRy+aZxSeG8iaV9Yqx7dNi6EpWba9tkQ2p8Am1Hqsn0Au6wDPUxKAw+7+m1LdWZKL0cpeIjAtkCtMTyFhp4ceHuwSkkLVRm+nuKBnSmXj3Dmv2attaaBRHxLDpeaSoOAaDwJ0KcfcRsBV5+Rkd63HKFVqCP5hGHuVeJ4gX0VtRZYDo4Dek6faLhwfKnzwN1llmnxSdf2cT4I8Xtn3yGnFYVnYmNJywP8NaWmNXa7H7qITl2sH1jv2z95wkjnp2HnXntw1kQcLo5afHk9S86Uv3/KF3YwvthRjVpGdnToaDPjpsWeKTA5+a4GUutshfiEs6jeT2yQnNKJFGcDHWqcCvxfuXrrf1m0/TJ0UQGwZJCHp6JXPLw2f605JkW70rKv3HKG3CcFXi22P7Hu8gqcwjN1iYAlizMz7nSDIqWnEI2/5R5tz6maX6QnHv4vpyTGXnmxcnNMr/qfdGw1WCw3Z+udvIl1tMbJvqvEtv1lVHlR6ABcv3ui3PQ9X46S/OzES9EVJKXdxQPP5ZZAXRsf19J5iJCDFXyfHFpViurtLkDn1doERoqszceDn75m5x4VyRuK7m/MaN7oX6KWb+Oylv0RTNeCMZrau2oXgz+VBg3EwWpuWyndz4GhKlTk+c3UmPodebfKuGxLQahVyFa0mJKiV+xkdql16oZdkpj1ttFSHHxCvNsmpD8Oo uEIYkB54 bvhuqdhL4k3GmXSfBFy9+LiwOYjh7U1u68vXQuVsfhwcSvZ+azFgjevYpP79uagN701cQSHACl87Z+LPd1AmkFDayV77LCkv9EVOoAif+DFjyKmmQvYMlgG2SC+SN9j9ID5jUNmhkGHivqTUiNL+n6DxOCfr0iXrj6EsZkYqo/FzqK8Ev9uZkb8lcgUDKtXYjYm+K0SGqw/9/kwF0vt254UFwySQYiPGj3zfsq+N9bmaKNsi+i+/LuKVtCSHswiW9c/XnKgawMWASY3/0kuE/QQZtp29d1kTHemGGJdiD13Z7BXg2PukLxj9WNKYQ9HxK8hVIfCyj/n6ZAfsXkYNplBW2/f1ZjK+HcvctWZZshi3EbhVQdenmmn7Hg+qwLfIOlvnW 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: In some cases, such as detecting whether a page fault should be handled as a private fault or not, KVM will need to handle things differently versus the existing KVM_X86_PROTECTED_VM type. Add a new KVM_X86_SNP_VM to allow for this, along with a helper to query the vm_type. Signed-off-by: Michael Roth --- arch/x86/include/asm/kvm_host.h | 2 ++ arch/x86/include/uapi/asm/kvm.h | 1 + arch/x86/kvm/x86.c | 8 +++++++- 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h index dbec74783f48..cdc235277a6f 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -2089,6 +2089,8 @@ void kvm_configure_mmu(bool enable_tdp, int tdp_forced_root_level, #define kvm_arch_has_private_mem(kvm) false #endif +bool kvm_is_vm_type(struct kvm *kvm, unsigned long type); + static inline u16 kvm_read_ldt(void) { u16 ldt; diff --git a/arch/x86/include/uapi/asm/kvm.h b/arch/x86/include/uapi/asm/kvm.h index a448d0964fc0..57e4ba484aa2 100644 --- a/arch/x86/include/uapi/asm/kvm.h +++ b/arch/x86/include/uapi/asm/kvm.h @@ -564,5 +564,6 @@ struct kvm_pmu_event_filter { #define KVM_X86_DEFAULT_VM 0 #define KVM_X86_SW_PROTECTED_VM 1 +#define KVM_X86_SNP_VM 3 #endif /* _ASM_X86_KVM_H */ diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 0e95c3a95e59..12f9e99c7ad0 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -4444,10 +4444,16 @@ static int kvm_ioctl_get_supported_hv_cpuid(struct kvm_vcpu *vcpu, static bool kvm_is_vm_type_supported(unsigned long type) { return type == KVM_X86_DEFAULT_VM || - (type == KVM_X86_SW_PROTECTED_VM && + ((type == KVM_X86_SW_PROTECTED_VM || + type == KVM_X86_SNP_VM) && IS_ENABLED(CONFIG_KVM_SW_PROTECTED_VM) && tdp_enabled); } +bool kvm_is_vm_type(struct kvm *kvm, unsigned long type) +{ + return kvm->arch.vm_type == type; +} + int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext) { int r = 0; From patchwork Mon Oct 16 11:50:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Roth X-Patchwork-Id: 13423116 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 5584ECDB465 for ; Mon, 16 Oct 2023 11:54:23 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E43788D006B; Mon, 16 Oct 2023 07:54:22 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id DF3D48D0001; Mon, 16 Oct 2023 07:54:22 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C94FF8D006B; Mon, 16 Oct 2023 07:54:22 -0400 (EDT) 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 B9B598D0001 for ; Mon, 16 Oct 2023 07:54:22 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 91E99408F8 for ; Mon, 16 Oct 2023 11:54:22 +0000 (UTC) X-FDA: 81351166764.09.74BB178 Received: from NAM02-SN1-obe.outbound.protection.outlook.com (mail-sn1nam02on2071.outbound.protection.outlook.com [40.107.96.71]) by imf26.hostedemail.com (Postfix) with ESMTP id 96F28140007 for ; Mon, 16 Oct 2023 11:54:19 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=LiJ5cNlh; spf=pass (imf26.hostedemail.com: domain of Michael.Roth@amd.com designates 40.107.96.71 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=1697457259; a=rsa-sha256; cv=pass; b=n5zKt5Fw8KgpjcINfaHm96xLmyY45WDcie2CSg0cU2tXD2/PqpUrNn1IBFVpBsgdAB4XoT 3WUj58qBaPjb0HpQoXSc5NgXGmvvafq9rLJfSV0R8OVUQhI2Aj7KqepqoLFsm4WAyZNdbD 7wCpqn8VZNSahRadwHQqv1/zc4jJnOY= ARC-Authentication-Results: i=2; imf26.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=LiJ5cNlh; spf=pass (imf26.hostedemail.com: domain of Michael.Roth@amd.com designates 40.107.96.71 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=1697457259; 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=fqORnrIgc6WOHMaUpeIdBg/NVRKwm737btzZB/8O3pI=; b=32Gx+nWxXSBiuaATnLybKuKCEEi/aCsJENUQ2sNT/+OChdXbHy6CGtDLd9Tesx+wdF8sAQ IFmJInzz4qN+juSsVRu4DzBZo2ww3wETeweyThZ66KHjMfyeIgj+HAU1KTOHoE5A4Abrsf t473pBCNM3JeqDDr+M429h/WYuvR8PU= ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=iKcwyWaH2V5slCwu1GGmFquJCgC00MlxtwTDBxQMht8d4HTSepokAevx8dXXZyILw+er28ORyufFvlQ35Rc4sqm9O7Wz7stwZJ/hwcI2OBoQLDhTYgJCtZffTiA4erizcR+JrQ2Zh6t17K6eV+M9fXK3W6Ut5DsZvRxEALjYYKUn9O19PMg50k9MRooRVcWcJsGJsS7DCLTq+zh87JWo1+gtXdEss2wrXMR2ODD3F+cwbAVQv3wYsyz+zBqx6+DGeZc8jmBQwbI9zezLDqaN63iVi7+cbOPExQCRzMWBzZ/XLPV7srpQ67L2sRXXu4oCToobnULaM7gKM7rXr8vowA== 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=fqORnrIgc6WOHMaUpeIdBg/NVRKwm737btzZB/8O3pI=; b=Qd2cuUozEyoDfVwHvXHG5bpvrqS0d0XIy36wD4LQzU+OGXpY7m4F7rY6Qg4uFewUprjBW5ERMriEkWAs27R1/MyxYCx+TBI0QcPubgsBwHG12eZ/KaMCnDFxFe3LnrygSgpMlFu0M/ZkZSLFLMEzaehsOt+UFybh5qLWFIdif3o48rsOaQiHgOt3guk3ZgYVVu/ynTg0Fu937lD7B2VcT8y212UiqwJheDlXUzkywYvnz4DlikykpbflgqVlet8A8fdfwvZ6JFvyHXP3X5sz5Y1p9mdLdHXveWD8Sld19SHRaCWP2JrUcal6lAVnrJUkMmtFdrbUTUhs3Szx2CuBMg== 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=fqORnrIgc6WOHMaUpeIdBg/NVRKwm737btzZB/8O3pI=; b=LiJ5cNlh3+is/cI08/167mFwE2E6ZSVvjgeq1bNTT+IY3IhgJx9eMLj4oGPR0IcrXHjCpqZI6lM1bQ4XFs2IzN9yk0Rnj8eWm0PDZXWHjQuMAjPMI6FOAIEWH9RJ+nX5dG/ZKNK0lcCj5puT3mQaKwbNFrJFvzlBa5zHT2v0DuI= Received: from PA7P264CA0067.FRAP264.PROD.OUTLOOK.COM (2603:10a6:102:2de::12) by CY5PR12MB6408.namprd12.prod.outlook.com (2603:10b6:930:3b::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6886.36; Mon, 16 Oct 2023 11:54:12 +0000 Received: from SA2PEPF000015C9.namprd03.prod.outlook.com (2603:10a6:102:2de:cafe::39) by PA7P264CA0067.outlook.office365.com (2603:10a6:102:2de::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6886.35 via Frontend Transport; Mon, 16 Oct 2023 11:54:10 +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 SA2PEPF000015C9.mail.protection.outlook.com (10.167.241.199) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6838.22 via Frontend Transport; Mon, 16 Oct 2023 11:54:09 +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.27; Mon, 16 Oct 2023 06:54:08 -0500 From: Michael Roth To: CC: , , , , , , , , , , , , , , , "Brijesh Singh" Subject: [PATCH RFC gmem v1 7/8] KVM: x86: Define RMP page fault error bits for #NPF Date: Mon, 16 Oct 2023 06:50:27 -0500 Message-ID: <20231016115028.996656-8-michael.roth@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231016115028.996656-1-michael.roth@amd.com> References: <20231016115028.996656-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: SA2PEPF000015C9:EE_|CY5PR12MB6408:EE_ X-MS-Office365-Filtering-Correlation-Id: f5e6cf73-ee29-40e9-93b8-08dbce3e9bcc X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: iQcCogIWGLFkVA9HrVhZpShcHnKlbXPqqnBqggNIn7hSjOjxLLrcr88J4XQNSiTMzcLPkD2FUx0dxTpV1/24OlVLhDlKiNQoA/XbDbSlaJ8/6Bi+MdKg/tSnchyTZC/5DwKyc9CNKP+DTp9MsN7jWVi7kuSnQub+rsrkKQsM3Lr7r9Sl5jgRTupzXOOy+K+Qu5cBWxn1idvaShNIk7OCbD7jfyKC+LKit5PMQUkxcUglJn9cVKVtBKTxBPh+w5V9VVrCBHn9ADCArALvZ/TP/+kGriHoHq00WAXK5AJM7f2SfBXW1J63XyYL3CvxfNBYi07buc61RHLjGsw1fxuCcuixoaEQGPiHPa2fqjLDt/OfPWxan+DbcFoX+/YOylnx3+ZUKGQt7vmBz5gD86hJXzdqgMSwNMK+nBu7ZuWFPHPKVW8eOMfG8CGEwcuPIkYqoVdRMCWOzgmy1ffR9qA0hbannD2lvkdoBqnqPpPozQFRRY7HownAshd1GCcE+JQnejJ0is1kAK+2W5abotqEFNa30YfoFqAOZlDLX/zYOfGYrFuNKBASuhG6mBKG95fV3WF6UUE3Oaiak1CSWrLBXFeOG1o6nMKBQC7OJ4S3A3wolMhQHaAgIgi/wo5xox6nkND1cBoUZfoUsc4uxfRJb3AHsxxLsr4zXtyXqLCRUJmARdkGctRhwSTXewMoT/xCI8JKUrTl32TyiSkmgrHXSVGB/DbEvsFOTddlBtB51gaD2JpSAxJY8MXUScFoylX1pvk+0HO+/gnFgMc9YnxORw== 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:(13230031)(4636009)(346002)(136003)(396003)(39860400002)(376002)(230922051799003)(1800799009)(451199024)(64100799003)(186009)(82310400011)(40470700004)(36840700001)(46966006)(47076005)(40460700003)(36860700001)(6916009)(54906003)(316002)(70206006)(478600001)(70586007)(5660300002)(8936002)(8676002)(4326008)(6666004)(2616005)(7416002)(86362001)(41300700001)(44832011)(2906002)(40480700001)(26005)(82740400003)(16526019)(81166007)(1076003)(426003)(336012)(83380400001)(356005)(36756003)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Oct 2023 11:54:09.9758 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: f5e6cf73-ee29-40e9-93b8-08dbce3e9bcc 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: SA2PEPF000015C9.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY5PR12MB6408 X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 96F28140007 X-Stat-Signature: aqjmzxidfrs7w5a6a4t46oftbuhoow54 X-Rspam-User: X-HE-Tag: 1697457259-183061 X-HE-Meta: U2FsdGVkX1+arKMbsWlvt03j3RWytWB6S0tfcUll7XGNHBSr6yxqavWLHg6gbY2j94ewXndU4xb3PfnrY9MpnS5rzD+sIrbWYCEAUJ5jjJRav2niugfykSVjQZ+5jMENQHTycNZ7lUdgA50OAchrj5+5K1+CHwc9U35l5svYfPV/NRe9NoSdnWY1aP63saUD8wMQgo3oHVIBRYDIn4mtEpLxFfbTZXTV1MvoqH/PJ9E6+RdRCGv3+/jM3OVbc6dmYkfTu77ykhOpBNXZ3TGzuuN2PcHCdQNohw9ZfKantTBMuHeCbh5wJul46Z9qJXWZLcIydcseXVbzfBtIBwa/x5fcCvvRxRPKDAbPRkei+NRmRWZj8v/NQ4q01ftyaZrwGqrijM7rv3s2M4bY1+K2VIsDfqmeVXE5mGiDOh3IKlcruO/aRUy2HX8JnYc0dGWUKWAsNo1I/nRrq67AsNY0j+28f4h+FysyVjYktysKEGKQLMsf9nxy+Odw5e4hu98BWmjv4ZMuB6SjnZ9QMQjYTubjO0AXx1QcyBRyRW7cvGqjT6ejjkKGeh3kV9vQQChE4ObYR8V7X6RfOYRCUa+AYqSnlP+3uEO8bKrcpqwc7vdsuEbSTsJ4rfKzzxEQ/dzMbl+8o3WaKfX3gF31i1RUeAjbMvFiUk5D1Cyyq30lTcDD6KSGjMBb8NOvLEBbZTelDyedIzJyuGcXYmW2vTh9azmAmRRjuqyjoUmCBriN3DjNjySylM/ZRlWZMZWRQ5ioWkkysFTY+KpBqzp8V5HMn6mTw1uNIXJzB4RXPvN+aR+XdzE//lkDBN8chAOHbVIz7wDGx0Gy/L/gqAfEVQXRQZK7BOi/cTx0PuRT5bRClM2nIFUc3QyittYKXSr0ShRW6ro7G8dUIngPanihe/c06Jk4GFrNzaHjUGC2G83IzKJjQqCgTMVbJ0NhqhmRMUDEDkA8ipiThiMUTQcVUKI cAb+O5DC anf7iwxPl5U7t/Xp9l1EODFfifhLhdpoFtuXRnzzjhnKz3V/3Gwq0XGxKYj4mPHcMOvTOyeHXHwvczucvuLzI05j2fel7MKY3/UCz7RLuE9F3Ag+7MFi7wuNX79xe+3Zzts8D8TewEAsKPIR3zVrq/sPB2ZyyRYZrktFjbeY15o5aZdsSVG9SEFEEnvPrjyBXwFwjGLptof63A/igvjTMI4cj4RjSmAvEy6alfjkr+WZdKAgk2+0ybw2qJvwoLXwyhKElDaRi70ERI1NDL5RwGRbmexsk2lUNWruHyZqhKHNz3rJdYrAnups5rUgvsBM2Nu5sz1STpJaUrHYAX/KHOFytSSmA3il2Olix/RS3RNhQ1FxgWQbOWrVv9g== 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 When SEV-SNP is enabled globally, the hardware places restrictions on all memory accesses based on the RMP entry, whether the hypervisor or a VM, performs the accesses. When hardware encounters an RMP access violation during a guest access, it will cause a #VMEXIT(NPF) with a number of additional bits set to indicate the reasons for the #NPF. Define those here. See APM2 section 16.36.10 for more details. Signed-off-by: Brijesh Singh Signed-off-by: Ashish Kalra [mdr: add some additional details to commit message] Signed-off-by: Michael Roth --- arch/x86/include/asm/kvm_host.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h index cdc235277a6f..fa401cb1a552 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -253,9 +253,13 @@ enum x86_intercept_stage; #define PFERR_FETCH_BIT 4 #define PFERR_PK_BIT 5 #define PFERR_SGX_BIT 15 +#define PFERR_GUEST_RMP_BIT 31 #define PFERR_GUEST_FINAL_BIT 32 #define PFERR_GUEST_PAGE_BIT 33 #define PFERR_IMPLICIT_ACCESS_BIT 48 +#define PFERR_GUEST_ENC_BIT 34 +#define PFERR_GUEST_SIZEM_BIT 35 +#define PFERR_GUEST_VMPL_BIT 36 #define PFERR_PRESENT_MASK BIT(PFERR_PRESENT_BIT) #define PFERR_WRITE_MASK BIT(PFERR_WRITE_BIT) @@ -267,6 +271,10 @@ enum x86_intercept_stage; #define PFERR_GUEST_FINAL_MASK BIT_ULL(PFERR_GUEST_FINAL_BIT) #define PFERR_GUEST_PAGE_MASK BIT_ULL(PFERR_GUEST_PAGE_BIT) #define PFERR_IMPLICIT_ACCESS BIT_ULL(PFERR_IMPLICIT_ACCESS_BIT) +#define PFERR_GUEST_RMP_MASK BIT_ULL(PFERR_GUEST_RMP_BIT) +#define PFERR_GUEST_ENC_MASK BIT_ULL(PFERR_GUEST_ENC_BIT) +#define PFERR_GUEST_SIZEM_MASK BIT_ULL(PFERR_GUEST_SIZEM_BIT) +#define PFERR_GUEST_VMPL_MASK BIT_ULL(PFERR_GUEST_VMPL_BIT) #define PFERR_NESTED_GUEST_PAGE (PFERR_GUEST_PAGE_MASK | \ PFERR_WRITE_MASK | \ From patchwork Mon Oct 16 11:50:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Roth X-Patchwork-Id: 13423117 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 3CA36CDB465 for ; Mon, 16 Oct 2023 11:54:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D0AF08D006C; Mon, 16 Oct 2023 07:54:36 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id CBB668D0001; Mon, 16 Oct 2023 07:54:36 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B5C868D006C; Mon, 16 Oct 2023 07:54:36 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id A3CBD8D0001 for ; Mon, 16 Oct 2023 07:54:36 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 73113B5318 for ; Mon, 16 Oct 2023 11:54:36 +0000 (UTC) X-FDA: 81351167352.22.0B2898B Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2048.outbound.protection.outlook.com [40.107.220.48]) by imf05.hostedemail.com (Postfix) with ESMTP id 67744100017 for ; Mon, 16 Oct 2023 11:54:33 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=r5PwcGX1; spf=pass (imf05.hostedemail.com: domain of Michael.Roth@amd.com designates 40.107.220.48 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=1697457273; a=rsa-sha256; cv=pass; b=QJeeJKuLZ0x3EeSpc+lfBjVUkGmN+kc0lVcgYy5GDpj3YXOHJ1LXFwyIRd3vZ0Buxn1Gq/ UExG6oPPXrzgFE0WFgjfUTobWi7PRw6LzdssRr13Zs+KK8hGZJgHveEB8EtYznbc+rdHQm DbC3e3GFtMuz+sn8xNLq54xaX6N1NeM= ARC-Authentication-Results: i=2; imf05.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=r5PwcGX1; spf=pass (imf05.hostedemail.com: domain of Michael.Roth@amd.com designates 40.107.220.48 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=1697457273; 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=wOIYpK8d1FFoOQs5uPVJt/jFrFTrz07zgHXT4XBNINI=; b=TLLyYjXeOOjr8U6GA7wDmStVrlyps7kKXKvZvZZ+7myz5fXAHe+mdSWGi6EQuGSylwnyac ZUzPylg7hLVaLldbSepwgBLRH7WPyCms+50dDarXM7vLxSJgT82k53M9gamXNt9LHJ30G0 NUo2sMlaYRjriR9vwH8bVfGTFve9kSU= ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=FP9Chzl/yRdI9zuUQJ//a4dB0zYcOGRvvERAf2wcUuBLp8ZVsro7+hL5ZXsKcKcjFUf4aaLl7IM6zyby9XcotMysMz+R64n20rP6s//O2IG1B8inSR5T4VaEInP0TIVlfDN1WS1IN5Uxw3KF/YAUWqyRZ985T6gRFKhR2BkAGrgpv60OJMkzgca8Cv6ctFf2xP+/TWWKzXPBk/EeYGmr5cdavTW95LofTilcccbMPKN0FpaiKuu3a6mGvSM/4K1Jd6N2rBqJiXHFc+3LALtxc5HiyejVIOe1Rj8PK9ghxK8B9iBEDNB2XaItvP3ldANPDgyQdGObC1oVW+uiga3XjA== 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=wOIYpK8d1FFoOQs5uPVJt/jFrFTrz07zgHXT4XBNINI=; b=XkLV4zfwUBF7UEh64mUHR/QMUeX4GQnXLoq8EVR7+ouYDdOOjz52gk7EoL8YV/iWO3xmu24jHQUTAP0AUkxq4BpP2MXs4keme+L771y/fqWeKaeA9HEfXZp2N492rNVXuYRVvxCpQLLKzjJ8S1TEV36E31KIQP/14B3AGr1sZ/maRbgVIXTci1KOmrmzHMvVftBInKrg6uBkRqo1khvaYf0GjvIaBg/RuJAKPNBmXtoxYVzah5haicJ3EbYzGRiCbIHOUSpURg+V8UEAzq0EraMXwXZ/E+KKGgfMbiWdd3Hiz9hBz/3RP1c1u5bjAFP6KsQtf+M6qzRUmnaqphMoQQ== 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=wOIYpK8d1FFoOQs5uPVJt/jFrFTrz07zgHXT4XBNINI=; b=r5PwcGX1EVKZpGIyXCHQMWiXYzser3qVm12min/RKOZD9FkcVKUi+25gZYidt5AnEShsD0m//7pzOnc0BrFrHK6UgeryV4P/hyKwOlcTu8ELXy/Woi9jufMRzIPC9pK0bQRlhtRx3IrHMX11yZyhI53wPaltCYSHtd+mueYcX+k= Received: from SN6PR16CA0071.namprd16.prod.outlook.com (2603:10b6:805:ca::48) by MN0PR12MB6080.namprd12.prod.outlook.com (2603:10b6:208:3c8::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6886.36; Mon, 16 Oct 2023 11:54:30 +0000 Received: from SA2PEPF000015CC.namprd03.prod.outlook.com (2603:10b6:805:ca:cafe::f5) by SN6PR16CA0071.outlook.office365.com (2603:10b6:805:ca::48) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6886.35 via Frontend Transport; Mon, 16 Oct 2023 11:54:29 +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 SA2PEPF000015CC.mail.protection.outlook.com (10.167.241.202) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6838.22 via Frontend Transport; Mon, 16 Oct 2023 11:54:29 +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.27; Mon, 16 Oct 2023 06:54:29 -0500 From: Michael Roth To: CC: , , , , , , , , , , , , , , Subject: [PATCH RFC gmem v1 8/8] KVM: x86: Determine shared/private faults based on vm_type Date: Mon, 16 Oct 2023 06:50:28 -0500 Message-ID: <20231016115028.996656-9-michael.roth@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231016115028.996656-1-michael.roth@amd.com> References: <20231016115028.996656-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: SA2PEPF000015CC:EE_|MN0PR12MB6080:EE_ X-MS-Office365-Filtering-Correlation-Id: bbbb7028-0f7f-4744-3ab0-08dbce3ea789 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 2iUKxxYLuJaF5gNLwGPK/WMGRJpQo0FX/u6b+T+jXyhqU5vvsoQcKipvx8Jux41n2ZQN1fkOZ9ipdKraOTh+29UsoePk/mPlzeJxg6Do0UY11pOghNnVyBQhl/T/W8HFS5zhkjxwLYuUZdhVEUkos8i44+YWnzihvm0pkakrZeF7iclZS5N/Xwydw2rEUvlY7h4F5XzNArRTQeTBcRifFl7SiG4jm6GI3kxrIbjUrVde9ZrTx3UPU8Sgj2PeJQcIOpIsyfFI5sZ4JPHEMZbPNGIR+Zsn0aDtImqK2IGxiHi3TUdp92MR2z9Kiu8rAX0CS7kwBhhSHgwY2mmisLHnfhu5EYyvueHhA2Nt0Hde2oWw0AOPIgdClA2eNe7jzi3EaSsfhcIGu1I/h9gMMZ6zVozMMVbI/iT/b3C0vXne8wzp2+eqfTQktFRSnIfKaNaBNDyh1AKpxqNCu6N+PEakWyrM7B9KY0KX3ybMYJZ7HzVc/kslhppH1+ebeHbw254UUuV2efO9TaVJpof2c5IEB+36bdmsgDhrrdFYNEStjy/BHn80jWpzu0eVu5Gm/oabJ9XvKA92ws74E4Y8nF6tJd70EhlLY33PELgxWQKSWhWHPBcD0B69zNIre2hRpc9J72O8xysUwkB/FbpHKk9GxWoxbsa6dzSP4mk+uwrnLdBNLE6NWQim0cBqp8MMFF3j3nbLnHT43vSOBqLZ9IjQv8UBdAqMospUta/Ui6llkZnmZ2m/YcS1nW/xpSJwOWk+Ao7JtVX8A9S9LvnNkTbRkg== 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:(13230031)(4636009)(39860400002)(396003)(376002)(136003)(346002)(230922051799003)(186009)(1800799009)(82310400011)(451199024)(64100799003)(46966006)(36840700001)(40470700004)(478600001)(70586007)(70206006)(54906003)(6916009)(1076003)(26005)(16526019)(336012)(426003)(2616005)(316002)(4326008)(8936002)(8676002)(7416002)(2906002)(5660300002)(36756003)(44832011)(41300700001)(81166007)(86362001)(47076005)(36860700001)(83380400001)(356005)(82740400003)(66899024)(40460700003)(40480700001)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Oct 2023 11:54:29.6514 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: bbbb7028-0f7f-4744-3ab0-08dbce3ea789 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: SA2PEPF000015CC.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN0PR12MB6080 X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 67744100017 X-Stat-Signature: 6uckwdzd3ofeafwb6h5jsqxto9js3t1t X-Rspam-User: X-HE-Tag: 1697457273-128481 X-HE-Meta: U2FsdGVkX19U1OblALnlJzQrOcEDLcM9DRn8zQrDEGSbrKicyU2bf7nw43WZGHDp3RP+wYgzfNRa4khRZu68j4GHhLMyFBTxJuYmgRrXDTa0XBjRrK/9NvpTIE7WDKu7CfNOTZO+JIU0QLh2k5d9akhpRL7FpMeaj/eKNwTttRGB7gyVqtNjGQOOD/Lrji3rhjbvmijmWYQNM8Q38CwFjoC7HfZF3P1y3TxXnSfVfSAwY+9dDZlxIw8rA4jJ9RXJFLyz9JqKiPr3RoXE2cZlkgFInYLcp8XZB6JZsXhaYJDkHEkPQrNhXm+z84urxQKlFGYcga6NPcXiqHAQzJzWhqkwmeZmOM+SS8h7i9HjUloUAEEOigNKw1ubYtGuJzETy0ko8Lo3UlO/LIEwfEzy7gzI12+eNCN8Hv9omyJe24NJ2tCndZk0ySBPLOSgmOZdgGvGnBWIHgffWaOMdas+j2aRu1k6ZD+XIYgUHCRpGT9RNO+unL7GRGh9j1lt6oaLQl5jQK1PN95mzELTte/ViWktJoHBUW5pLI1+wrOJQ0si7u8+fMRM4zA5RA2h7yOep2A1k4Dgn+dnVHBaSycnUMdpX+roQRzgKxESAm7C4h6qcY/F+C3NmzZTK2fcJY+C0Y2ILVUT3F6tcx6qaM+EyZ5/COMa18pSjRHzrId9CX1ctTIvpq8qsRWKZs3F7aLgwHuFimG43ytHUCa+EPxGM89kTmBlDimnXqqtZE9IFLPWBnyouNIJULSW4Dza88S091N6/9LWkn9m5xe89ozlOFas4JDMawPzmtLeatN2jz8tyhVpGQbI+ktuyiQlYboKzzIFq0sF4ulYG4sXZxf07oZ6Q36afNmnUhgRBTtEaen9VLghUVIHWH1PDyeDtbYDbu9sQp5NTh576IYSi2KlnUfU1KgZ+6CfhjpEWsfxaPzwXdaXRD+LR3XBiEOlbRLs0HMGKwksw+lcjIPTPKu GOExboUY AJun16H65n2ZZmQuk38oXzrpSHnVubujGIBusYsZmgIAOgLvPWGJm+IM6lU+ZaAaKfukYviEY9DgVCBND6y9nrMHBNC13hyEVeP1t7ly4m5ObyNMujTaB9EjqoPS/x2PbgYWKOzXoYBttszYEzZPzO3jDlyN9heZtraT1Mcpyy1wdDk8Baco3RSvNJVR//niZ56HOc0i6/K6B1DSAYSXMnHbSNMHH46PkHrhesrLO8DRNgf0aquROHTav7qPcXwU/8y5Z8AW+0+tnkR47jhx0TDm3AoTzuZStRXtJnmw6fEqSYVcAjMxfK0tKMkNS0FXWcNUKnhHWf34lMPgXlTkNrRTcsrc+bH7KAwphdeqvzHOX+MuOl52ImkqApEi3ir3liVBS 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: For KVM_X86_SNP_VM, only the PFERR_GUEST_ENC_MASK flag is needed to determine with an #NPF is due to a private/shared access by the guest. Implement that handling here. Also add handling needed to deal with SNP guests which in some cases will make MMIO accesses with the encryption bit. Signed-off-by: Michael Roth --- arch/x86/kvm/mmu/mmu.c | 12 ++++++++++-- arch/x86/kvm/mmu/mmu_internal.h | 20 +++++++++++++++++++- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c index 686f88c263a9..10c323e2faa4 100644 --- a/arch/x86/kvm/mmu/mmu.c +++ b/arch/x86/kvm/mmu/mmu.c @@ -4327,6 +4327,7 @@ static int kvm_faultin_pfn_private(struct kvm_vcpu *vcpu, static int __kvm_faultin_pfn(struct kvm_vcpu *vcpu, struct kvm_page_fault *fault) { struct kvm_memory_slot *slot = fault->slot; + bool private_fault = fault->is_private; bool async; /* @@ -4356,12 +4357,19 @@ static int __kvm_faultin_pfn(struct kvm_vcpu *vcpu, struct kvm_page_fault *fault return RET_PF_EMULATE; } - if (fault->is_private != kvm_mem_is_private(vcpu->kvm, fault->gfn)) { + /* + * In some cases SNP guests will make MMIO accesses with the encryption + * bit set. Handle these via the normal MMIO fault path. + */ + if (!slot && private_fault && kvm_is_vm_type(vcpu->kvm, KVM_X86_SNP_VM)) + private_fault = false; + + if (private_fault != kvm_mem_is_private(vcpu->kvm, fault->gfn)) { kvm_mmu_prepare_memory_fault_exit(vcpu, fault); return -EFAULT; } - if (fault->is_private) + if (private_fault) return kvm_faultin_pfn_private(vcpu, fault); async = false; diff --git a/arch/x86/kvm/mmu/mmu_internal.h b/arch/x86/kvm/mmu/mmu_internal.h index 759c8b718201..e5b973051ad9 100644 --- a/arch/x86/kvm/mmu/mmu_internal.h +++ b/arch/x86/kvm/mmu/mmu_internal.h @@ -251,6 +251,24 @@ struct kvm_page_fault { int kvm_tdp_page_fault(struct kvm_vcpu *vcpu, struct kvm_page_fault *fault); +static bool kvm_mmu_fault_is_private(struct kvm *kvm, gpa_t gpa, u64 err) +{ + bool private_fault = false; + + if (kvm_is_vm_type(kvm, KVM_X86_SNP_VM)) { + private_fault = !!(err & PFERR_GUEST_ENC_MASK); + } else if (kvm_is_vm_type(kvm, KVM_X86_SW_PROTECTED_VM)) { + /* + * This handling is for gmem self-tests and guests that treat + * userspace as the authority on whether a fault should be + * private or not. + */ + private_fault = kvm_mem_is_private(kvm, gpa >> PAGE_SHIFT); + } + + return private_fault; +} + /* * Return values of handle_mmio_page_fault(), mmu.page_fault(), fast_page_fault(), * and of course kvm_mmu_do_page_fault(). @@ -298,7 +316,7 @@ static inline int kvm_mmu_do_page_fault(struct kvm_vcpu *vcpu, gpa_t cr2_or_gpa, .max_level = KVM_MAX_HUGEPAGE_LEVEL, .req_level = PG_LEVEL_4K, .goal_level = PG_LEVEL_4K, - .is_private = kvm_mem_is_private(vcpu->kvm, cr2_or_gpa >> PAGE_SHIFT), + .is_private = kvm_mmu_fault_is_private(vcpu->kvm, cr2_or_gpa, err), }; int r;