From patchwork Fri Mar 29 21:24:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Roth X-Patchwork-Id: 13611107 Received: from NAM02-DM3-obe.outbound.protection.outlook.com (mail-dm3nam02on2069.outbound.protection.outlook.com [40.107.95.69]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CF1AF13792C for ; Fri, 29 Mar 2024 21:29:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.95.69 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711747756; cv=fail; b=nXch+0VAZUf8LTNBJR7M8CxHmW9ulhfR8fgdH+cvihsUgy8JRUyQq4fIGdJQ8uPwNyaktk4OKJPhKPVRIc75vY+CATAU1cuyItUfDXpLE94XWq2kpBW0jWlcBySuy6KopBeC+nG/pv6X73d3ctfTekVzSZ4L7vNFyULsoA8mhRo= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711747756; c=relaxed/simple; bh=5s4kK/WP9ZqeYVhiSqxoJ57SFYiFP7JevhkyTaq6wRk=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=T7BO1T3BO38asbpLYLqjqj0jeHM/BLyQ3dbtF7b8eIuqHErLbpv57HfkMUp8rZJcDiK0aaxSp8e23VzBvEBQn7HrUGL3B7k4XXmELwEMcvW4+duUARpe2O4FTWMcJIzp3eSAFkvU1CUIn7QBufBlWhuQh0QiM1LR5kDyBe4LKL8= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=2AxYTXet; arc=fail smtp.client-ip=40.107.95.69 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="2AxYTXet" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=FzFk5wGTClgL1Hsoxgk+gRVGgXrTLnTk4J3YtRzeH7uc8jNP5hjhuAik2fH78W+2A9OE0MvJqeiDJxMOSPpJiKOPUIjw2L5mHnCoa1r4nhyKnCUREJs4v8Os2xFOhhPKzy8jkeZNa1bAxs4JefCH/vGCTL7MPCBrdmmFZ25OUe0pyy7qvYeLtbO/WQhZRoAOgvo3KWQcnbmpfyT4hHcZE9cPszLb0zBj5XNxDKoG+r2C1sRsTPWyj6eUvL8vPgovGRdrf77nEaF328DmZFpG93CY/tmLE44vz0uSG6BDATikiTiokz2L7BC99/H+towz3rLcAlHsuA68+iWKSKZkVQ== 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=biAfkB++kZWlpmZvTkqedIFy/Mxtmn0mW1+CED4pjEM=; b=b7qfre/S7SOzVo/q85OBvkSc3Z27f3wsPsjSsJqxyyub9HScSkBzmSsrZBOgp8JXFu4VYa7hcR3fO7qJqkOWLFNh+VX3ORTbamGOKWSJ673EZueJRjYJNVoXxyypVEZB+t7OPx4rWzwlMZlxhuO0Cpsy/m/kYgB5NK18N8nfUbQ+f1yAL46BFQGVGLGfxnJS5BO2/Uyl/QDCTTqxc1B924fYQtDEuz8kEZNsaC/qMlM0Y6yh8BuYLy33KpMvBhRUBIFCXz56zFh3gMDj9h3uPayYY+lOFTzamxYHnDth/SF8pjYJTKfTWTtiFj1RS8Rd5hxmqk9fAQ2dhpklHyRwqQ== 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 (0) 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=biAfkB++kZWlpmZvTkqedIFy/Mxtmn0mW1+CED4pjEM=; b=2AxYTXetQ2rCsVx/j7Cf4m12osbVgY9XeUi6XY3HF176i5NVLMf1HMa17l5NDa9UmlNT5WAngnVA35jCLnnfztYSKKjj3axfxSi0InEgXbzHu8kNXn2iM4lpPrYulHqQPjXUke69sSW4JAh0ueyS3SYN12CJRlS3OmQyb4cPT4A= Received: from SJ0PR03CA0020.namprd03.prod.outlook.com (2603:10b6:a03:33a::25) by PH7PR12MB9074.namprd12.prod.outlook.com (2603:10b6:510:2f4::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7409.33; Fri, 29 Mar 2024 21:29:12 +0000 Received: from SJ5PEPF000001CB.namprd05.prod.outlook.com (2603:10b6:a03:33a:cafe::94) by SJ0PR03CA0020.outlook.office365.com (2603:10b6:a03:33a::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7409.40 via Frontend Transport; Fri, 29 Mar 2024 21:29:12 +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 SJ5PEPF000001CB.mail.protection.outlook.com (10.167.242.40) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7409.10 via Frontend Transport; Fri, 29 Mar 2024 21:29:12 +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.35; Fri, 29 Mar 2024 16:29:11 -0500 From: Michael Roth To: CC: , Paolo Bonzini , Sean Christopherson , Isaku Yamahata , Xu Yilun , Binbin Wu , Xiaoyao Li Subject: [PATCH gmem 1/6] KVM: guest_memfd: Fix stub for kvm_gmem_get_uninit_pfn() Date: Fri, 29 Mar 2024 16:24:39 -0500 Message-ID: <20240329212444.395559-2-michael.roth@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240329212444.395559-1-michael.roth@amd.com> References: <20240329212444.395559-1-michael.roth@amd.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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: SJ5PEPF000001CB:EE_|PH7PR12MB9074:EE_ X-MS-Office365-Filtering-Correlation-Id: 6faefce5-2934-40f6-fab2-08dc50374721 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: aucdNKPI2+QfE6zc/gdeUopuMm8nDykSkS3U7QocOC997HqVzQENeA4OUaENpZ6cbrHzqLAFayu0qE2gdXADnsrAcCPH3mkTnxRtBCX4MoYrN17IkPIg5R/bOd6IyuWI+wL+HQr2UeRlM6/kv+CrRAN/rT4+Rj4dCCy6BgOqC+dzieug/jKVHdNbgbR/DHq00s2PpM2RNHkqjH7pahmW/EPBSpnkLkkcFmOCQgDTzEVe+dqbKjiD+z9g1kZBtFDwMWJxw9f8iRZ4e0cGBy1oXSguE1PorQ2/lBBtSD/ara3mY6WjeuiT59v5QwFAU6Q6+IeSVY4eSuzVfdxhNCYVBArtlUUOmdKSlN9XS0zeeZic8Tw8GctMqsGCgoVAAQw/7HNq8tln255ylP7PujXuUZ5CTWA0tG68C2z01y8okR4RFkx5Vpy21niauJUcG0zd7Z0yvK6tbuaBdffzQSqCHmoH7+0QxBIoheGiGsHCdEo62UhUOQkSi39J2MLN2qYzSlZz2dEXQeLkSR6Ln4DzxdtuZe2fcvLUmlsFmiTXQ5Pd+wgTbvBEEwXOyFn+Mu8Uoy5iv3kQ9nRq9PrOajQ9QXVnxkmEwfu9Vrpv1GSwCixuYpYa96yfq8zu+IOfkpKOwh1DgDqR3ucsTKSLa+Q4OttrgxTvoTi6Bu7VBxgPrywn5xwMxM67sOlbWF10jj6M6JZNIftcSD2n5zZ6QuAs8n8HO82kPq88WsKxDP5bXjKAYDCalVybC+XPvwsusKzP 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)(376005)(1800799015)(82310400014)(36860700004);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Mar 2024 21:29:12.5350 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 6faefce5-2934-40f6-fab2-08dc50374721 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: SJ5PEPF000001CB.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB9074 The stub needs to return an integer in order to avoid breakage when CONFIG_KVM_PRIVATE_MEM is not set. Add it. Signed-off-by: Michael Roth --- include/linux/kvm_host.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h index 73638779974a..2f5074eff958 100644 --- a/include/linux/kvm_host.h +++ b/include/linux/kvm_host.h @@ -2459,7 +2459,9 @@ static inline int kvm_gmem_get_uninit_pfn(struct kvm *kvm, static inline int kvm_gmem_undo_get_pfn(struct kvm *kvm, struct kvm_memory_slot *slot, gfn_t gfn, int order) -{} +{ + return -EIO; +} #endif /* CONFIG_KVM_PRIVATE_MEM */ #ifdef CONFIG_HAVE_KVM_GMEM_PREPARE From patchwork Fri Mar 29 21:24:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Roth X-Patchwork-Id: 13611108 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2040.outbound.protection.outlook.com [40.107.236.40]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 825E413C67C for ; Fri, 29 Mar 2024 21:29:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.236.40 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711747778; cv=fail; b=Alo1KKBPLZIipZ8hq2y5l/BbiGSLGzbscAhy4Ub4SPP4x63Ib7+eBXWXtuIw6PgFOzbU0Z+nTiaM+sG4BF7dYo5aHusPI902RFNreHOgfO/ZPJMG7YBuspeeUy93VsnLnMY+r0sPWKK60d9h+U+LY61/6RNbFF6Z0N/7+8+xzIc= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711747778; c=relaxed/simple; bh=CxAlODFYLBjvWGlVzw37m63fgN7tkd/jnzmXELBKHRY=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=a4PY0Q4CVblFH40mwACPA7zPMetxTLuDVESrq9SXG0A/pTu60gcXnHwRtG+nC3wEpKm1dRKp3ZlS8p+Gne6COY/ogSGwjmwFHL3qIiHopPSqhwhzJ2hc6sP6XHIgfm8NG4Eg3x4at3Rgi4wKX8GO7tcy7sgQ8Y6oAxNI4d3ikYA= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=VwnkJXNQ; arc=fail smtp.client-ip=40.107.236.40 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="VwnkJXNQ" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=fv1HRFaKXQ0wYvkRoDlqRpzgKeyWCJjwv8kA/m5+mxVQyyjBgoGc32aO9uGs6Z0RrJA64yS0qhn8ba1Fl66fDksYv8YtUUxt/Nm6AbbUNhj/y/WWNXGAkzDcAuCsLPbHHqOlAFzGF8jOcGeCN/yO+ptNCKRkLPK2EjpuOWUzvCGR3wo9EaL2f6CsD1Ym3Wgl7Su6s7bORb9Y9hal/5G+R2bxwt5+0k6nxxtz+xE3Kd9odQAkB2UiCYLAgZKUkTd2YevaP19QIt4n/9i0rIl+84YTsG74OOhJkF8RIDM8sNj3Qmn+jK8fjQ7mD7SRWJnW7nQL168/Qhq/LhFk6i0BrA== 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=9VOrNraY1ABO0bZ1hE/eIRvCR1N1pJSdRPyDLzh6Ego=; b=douoa4ReEseT69N+nZ+7yoFzw0R6pXTmmT2B+Q28/npo5+NagCSO7YSKcmFBtbd9vRu1O8iw88q0o3/6+64Pldg3uC+/gfKhXKxCpAhSV47e1gbE+MflcUMLNsUrH/9wjww2W+6rekIFNhZslMm7JI6ADClrcs8vcqQwLuupKWaweSIWHjcxKn9Tx+iMtbuRmwoi4GcR8RotHp+L8pD6ybnb8PD17+4lfJbOWOqGGZXwk0/dhxBWvsQs+P8QjUKr2nxNvT9s+E6iyq9nnhk4JSAscjfRotYv+YDmShkwo8+/qwrCkLAO4YA7mveb/XXzja+/Uaypqw02ibyfSI+7OA== 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 (0) 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=9VOrNraY1ABO0bZ1hE/eIRvCR1N1pJSdRPyDLzh6Ego=; b=VwnkJXNQq7b9L7qNU7JwMZS4ex1N1XoEad+GvZJpmBr2/gGybVCVm4hL3aH72UpETctKxbJeBzrUou8Kwo9g8sXxc4z6KMKzTxbjc4TEtAUKnRH81CQgnpU/wIJY8WzTP/SC8vNt11DBojhmgBSIwcjq6CHrR7yCssraWwLUJLQ= Received: from SJ0PR05CA0116.namprd05.prod.outlook.com (2603:10b6:a03:334::31) by SN7PR12MB7451.namprd12.prod.outlook.com (2603:10b6:806:29b::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7409.32; Fri, 29 Mar 2024 21:29:34 +0000 Received: from SJ5PEPF000001CF.namprd05.prod.outlook.com (2603:10b6:a03:334:cafe::c7) by SJ0PR05CA0116.outlook.office365.com (2603:10b6:a03:334::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7409.12 via Frontend Transport; Fri, 29 Mar 2024 21:29:33 +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 SJ5PEPF000001CF.mail.protection.outlook.com (10.167.242.43) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7409.10 via Frontend Transport; Fri, 29 Mar 2024 21:29:33 +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.35; Fri, 29 Mar 2024 16:29:32 -0500 From: Michael Roth To: CC: , Paolo Bonzini , Sean Christopherson , Isaku Yamahata , Xu Yilun , Binbin Wu , Xiaoyao Li , Isaku Yamahata Subject: [PATCH gmem 2/6] KVM: guest_memfd: Only call kvm_arch_gmem_prepare hook if necessary Date: Fri, 29 Mar 2024 16:24:40 -0500 Message-ID: <20240329212444.395559-3-michael.roth@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240329212444.395559-1-michael.roth@amd.com> References: <20240329212444.395559-1-michael.roth@amd.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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: SJ5PEPF000001CF:EE_|SN7PR12MB7451:EE_ X-MS-Office365-Filtering-Correlation-Id: ed637ffd-c29d-4f5b-8f5c-08dc503753a2 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: S+BejoOMDew66mmDDM7MwmrXga1bMMypUjDl/17doZ14Ba511OpQldeQUFn/GGeY0gxFNAVVyT4Axmp8RXLO34CvCBrfateRfiC6cPsde0mvw+9U/PZjcILf3ms1n4uf3AQt9TuOjumrxdTZiivxJvrQmUG/g6C4qK/XofWXKfUdDrIMkzzjb1tCpswjOKbReSNB3Z0V9tNeX/yvfLPFTgFbwqcjc3/Dn6xWLCuID8wSOld9rticRnJ4UFlvNEPWYYyRYrO2y8YLyXUXdjdJJehbGSXEYJR1NoBefeDmRAIKdzWZOZlBqKRhp5KEuEj33DwNQGxtc0M+bDo1HeHPMfa4eJDyYnxMsgXdgOYuAVc2gjogWx84Iarm5tTEI2Eow8MMMC4QHC6u0mDb5h9JykVv3GJixPkPjDXqJJ+ZCUy8IxQzN42p1lIvVLAXZC85XW42QWyP6QpnDXj0LkTD2W1UWrRKaeAHlKw96l5vm296LbuRjztX4RD4uSnopuLwk1azhvEPOWt15EiiA/SYmxpTADJnvO1186Lbsis10NiSwFvNe2pOJzUkAstQKJ3/Bdn0ESxCeSRJp+NmJ7cO7mg5Jstehno6ya7Zn0u4htcrJti36tVZ0bJfChTBeusDttUjQ9NO3sjbeQxc0DP6vz0DjL3mRoM5dSbhyCcKFs50wwKziVMsx0x9UM1S18eufqoLnrYlf/+vIFktymyGsA== 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)(376005)(36860700004)(1800799015)(82310400014);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Mar 2024 21:29:33.5103 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: ed637ffd-c29d-4f5b-8f5c-08dc503753a2 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: SJ5PEPF000001CF.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN7PR12MB7451 It has been reported that the internal workings of kvm_gmem_prepare_folio() incurs noticeable overhead for large guests even for platforms where kvm_arch_gmem_prepare() is a no-op. Provide a new kvm_arch_gmem_prepare_needed() hook so that architectures that set CONFIG_HAVE_KVM_GMEM_PREPARE can still opt-out of issuing the kvm_arch_gmem_prepare() callback if the particular KVM instance doesn't require any sort of special preparation of its gmem pages prior to use. Link: https://lore.kernel.org/lkml/20240228202906.GB10568@ls.amr.corp.intel.com/ Suggested-by: Isaku Yamahata Signed-off-by: Michael Roth --- include/linux/kvm_host.h | 1 + virt/kvm/guest_memfd.c | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h index 2f5074eff958..5b8308b5e4af 100644 --- a/include/linux/kvm_host.h +++ b/include/linux/kvm_host.h @@ -2466,6 +2466,7 @@ static inline int kvm_gmem_undo_get_pfn(struct kvm *kvm, #ifdef CONFIG_HAVE_KVM_GMEM_PREPARE int kvm_arch_gmem_prepare(struct kvm *kvm, gfn_t gfn, kvm_pfn_t pfn, int max_order); +bool kvm_arch_gmem_prepare_needed(struct kvm *kvm); #endif #ifdef CONFIG_HAVE_KVM_GMEM_INVALIDATE diff --git a/virt/kvm/guest_memfd.c b/virt/kvm/guest_memfd.c index 74e19170af8a..4ce0056d1149 100644 --- a/virt/kvm/guest_memfd.c +++ b/virt/kvm/guest_memfd.c @@ -13,6 +13,13 @@ struct kvm_gmem { struct list_head entry; }; +#ifdef CONFIG_HAVE_KVM_GMEM_PREPARE +bool __weak kvm_arch_gmem_prepare_needed(struct kvm *kvm) +{ + return false; +} +#endif + static int kvm_gmem_prepare_folio(struct inode *inode, pgoff_t index, struct folio *folio) { #ifdef CONFIG_HAVE_KVM_GMEM_PREPARE @@ -27,6 +34,9 @@ static int kvm_gmem_prepare_folio(struct inode *inode, pgoff_t index, struct fol gfn_t gfn; int rc; + if (!kvm_arch_gmem_prepare_needed(kvm)) + continue; + slot = xa_load(&gmem->bindings, index); if (!slot) continue; From patchwork Fri Mar 29 21:24:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Roth X-Patchwork-Id: 13611109 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2046.outbound.protection.outlook.com [40.107.243.46]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 42FAB13C3D3 for ; Fri, 29 Mar 2024 21:29:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.243.46 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711747798; cv=fail; b=sUq4TDWAeVqR4bmNMBSA8tozQ25gva53JChyDj2NLG2LdaB5nK8wGqbZXZqekg+cDpaVHlSjaBxNqLXtMX7LUa/re4g4eKZ+WoP+cLw1yaRzxFaW7Xn7h5ZvrUbqVta3zxMova3hmPCnWQmWUGnGCy0lkvObuc6CHNDgT7IyaJc= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711747798; c=relaxed/simple; bh=pxJWsUH0LYl+HBVjpNCC1IBh/lredb2muB4U900OwK0=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=a9yAf1fnLjdStkK58n3DpnV+J3lMUekMaWQ6fYE2hsgISJBvHTBmWM8bDE4vl5UWRb912mudM0jEl4I9QQFkub8eC7xkIgOmo5yLotyMau+9xVvazXvljP2BGPivLfsgm9yasP2Q4BA3aK2yQIVgy3xVqX6adPIWekKOabUHTTI= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=YaejfdVx; arc=fail smtp.client-ip=40.107.243.46 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="YaejfdVx" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ZqmCYWU4/RlXJ8RYU2eaV2JyNbSLqQhLSUSNcqPzXvhmKgLKaTaYsONsp8sQOd3S0m852q/oj7/09WVD/VIshPed7taEZ1hDweJcCpSN8dqPTIgl2BRrApL6Fp46FC2lpjiPrXfnXoxioxPWADxOtwTOUogr/5Ldzti3KpXxIbMV4ahK02j+2NqHViVwsGy6rzns/QucCiPtf/hJ3mO86s6nEssItXKebmMIRKubHNp4EQgavoc9sHYne/M8/e9zgMY9P5BZOLY7mCFR4vgsScQe+FtKXlke3tZbxMwrgcdJoQmFROvKSAsrW5ojVuZM6MNp5WaNM/r/vRGllApCiA== 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=ugJ9I0m9t7jZi5D7ZCKz+s5HBr61uhs2MgrhZhxvsMk=; b=oAqdDUm9R/2tRsNmyGbPpPT6N5JaaQNY/RAFc/8UJNCJ3trlX4NvP7JEAQ5d5dnXitaqsNtE77DAA5LTrqQMLmOKPPOaToz9q5pcgdoV09eV0eP6xug0Mqztnx4GGjujVuHISpOdIRwsMoKc2QJYG3B6LzRuzl1i8KP0xMEsedMRUVMDQj+/4kfM4tnnkFr4tB0tannJHlgbw26fMuHJDMv9v+r3As4R3ffDaHLS0i1EePHwSQ4/flxUBAJSSuMexXNbDPKwbhgw4LJL1nMLudICRmlmjE7+0CrPCJKHShZ3uhiFIJVrxhxzDAd/jP1kESwUicM9vxCsaTOhaddH1w== 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 (0) 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=ugJ9I0m9t7jZi5D7ZCKz+s5HBr61uhs2MgrhZhxvsMk=; b=YaejfdVxDpCZKRZKcPstCocOnPuWu13gJvC9R6CP1LpjZd4FygrTYjPdIn893XSzVD3FRq79AOJcfhVisLWzco7OR8PrSpylfLJkzU6ozXjHbf2VL4nRSx2Icrw4IEiKtS/jRoBBj5pUfT7hsHBESPjaihbLNMr4paeVwAUQEWI= Received: from SJ0PR05CA0028.namprd05.prod.outlook.com (2603:10b6:a03:33b::33) by CH2PR12MB4117.namprd12.prod.outlook.com (2603:10b6:610:ae::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7409.40; Fri, 29 Mar 2024 21:29:55 +0000 Received: from SJ5PEPF000001C8.namprd05.prod.outlook.com (2603:10b6:a03:33b:cafe::1c) by SJ0PR05CA0028.outlook.office365.com (2603:10b6:a03:33b::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7452.16 via Frontend Transport; Fri, 29 Mar 2024 21:29:54 +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 SJ5PEPF000001C8.mail.protection.outlook.com (10.167.242.36) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7409.10 via Frontend Transport; Fri, 29 Mar 2024 21:29:54 +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.35; Fri, 29 Mar 2024 16:29:53 -0500 From: Michael Roth To: CC: , Paolo Bonzini , Sean Christopherson , Isaku Yamahata , Xu Yilun , Binbin Wu , Xiaoyao Li Subject: [PATCH gmem 3/6] KVM: x86: Pass private/shared fault indicator to gmem_validate_fault Date: Fri, 29 Mar 2024 16:24:41 -0500 Message-ID: <20240329212444.395559-4-michael.roth@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240329212444.395559-1-michael.roth@amd.com> References: <20240329212444.395559-1-michael.roth@amd.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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: SJ5PEPF000001C8:EE_|CH2PR12MB4117:EE_ X-MS-Office365-Filtering-Correlation-Id: 1856f6a1-b056-423f-dcb4-08dc50376021 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: te47BAQwhc1soyCg0Hoh00aBleZuLAv9dbZGyFvPjcnnsH/rTLjWom5OPMxCyIpXReEl9MTr7dc76qpMsuIZBvRqEDM+xoYjGphZ09BCRg/iqtaXOJIRqTvI/LXCHUvPnQU8B6oPeSOIBu1dNpcgi9nrI/J3Q3lR14HnvavpKnUqTfwvA6seajAYzzbXqOf0GahOI5ik4QGXN7asIJV9yOjHfZpN80rFshgrzp6ooqOimc9NFutfUdzjmfSyQw17DotcMI++6rbmpNSqRiafDcsfo4KL7zaPjR5AAJhnyiSrJkDUsBhz7I+Ptq2Awhn1jUKUUQyBWoPE/8Cmy3ungIRVKc4wjjlJlmBvRV9HIJ2TXcVpZQ0wFl2gtIlQ8NLCA4equ37Ct4RQkUvktOl+msZ7hBONw5y/iRO3ZJQUDWZbUQSQQgWp27nWw9s9Wh0bCstFxLfx2FVIY5M6y7WpVrimJ+jsLvkzTGGEdONp5TnQKAby3n3CyKQIEqrdJzFBoLVaU44/dBXDtbvGWBmksfaCQ/B/EcSxggmlM3n3VTlIQhOp9jqVpuq4obFz8gifQLPQF0s5OXANY0pFKNeKmJdd55YDWfFNDOCdSTAWotlZ8hHs+WKU8QAlU5lEd0a6UYPkoNqsCxS8y8goXixMOftD8jDOhxyc4L3EW7eYEqZTf3H9GyEzbV7eZ6TcOpmwC8Ecd2nJotHKcepFExamZw== 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)(36860700004)(82310400014)(376005)(1800799015);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Mar 2024 21:29:54.4773 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 1856f6a1-b056-423f-dcb4-08dc50376021 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: SJ5PEPF000001C8.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH2PR12MB4117 TDX has use for a similar interface, but in that case it needs an indication of whether or not the fault was private. Go ahead and plumb that information through. Link: https://lore.kernel.org/lkml/35bc4582-8a03-413b-be0e-4cc419715772@linux.intel.com/ Signed-off-by: Michael Roth --- arch/x86/include/asm/kvm_host.h | 3 ++- arch/x86/kvm/mmu/mmu.c | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h index 16fff18ef2e5..90dc0ae9311a 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -1815,7 +1815,8 @@ struct kvm_x86_ops { void *(*alloc_apic_backing_page)(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); - int (*gmem_validate_fault)(struct kvm *kvm, kvm_pfn_t pfn, gfn_t gfn, u8 *max_level); + int (*gmem_validate_fault)(struct kvm *kvm, kvm_pfn_t pfn, gfn_t gfn, bool is_private, + u8 *max_level); }; struct kvm_x86_nested_ops { diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c index 8d7ee18fe524..0049d49aa913 100644 --- a/arch/x86/kvm/mmu/mmu.c +++ b/arch/x86/kvm/mmu/mmu.c @@ -4340,7 +4340,8 @@ static int kvm_faultin_pfn_private(struct kvm_vcpu *vcpu, fault->map_writable = !(fault->slot->flags & KVM_MEM_READONLY); r = static_call(kvm_x86_gmem_validate_fault)(vcpu->kvm, fault->pfn, - fault->gfn, &fault->max_level); + fault->gfn, fault->is_private, + &fault->max_level); if (r) { kvm_release_pfn_clean(fault->pfn); return r; From patchwork Fri Mar 29 21:24:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Roth X-Patchwork-Id: 13611110 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2088.outbound.protection.outlook.com [40.107.243.88]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0BC3613B2B8 for ; Fri, 29 Mar 2024 21:30:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.243.88 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711747820; cv=fail; b=uJHie/BDHTojfwVCUvfbzBZaXj6EO8K+1nLVOEC0S5Se+ck0QvaNHvxyXcRbAixPi8qrK1yDTGDwg5jLj1NCfURqENvWcjbo4F7j6koF+nTOv1ZYrPJ+PeqtNkaDQFL7cOzmhOx4DFs27eU97gmRDM8uSRYy0UcZGhn402+54jI= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711747820; c=relaxed/simple; bh=gK8DGPzYq88zeYTnm4BLo5RO69l2leggmduUCcWn5ks=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=RQWjE+eotfUOGt43oJgofy75GlXWxXo4J1FqN4K4HBg1GVxJtNvaSO7omwxgfXDq/HFTk+/1EtSZOra5Rc4lfOAC4AxoGKrsnBZx4Si5E2JYOOxcImtu9Ynik1MHcYbk62ewTZIkdIdFLppaMRQ8DTnTZscmVZaGFfQWJtNRAak= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=I0OxUuk5; arc=fail smtp.client-ip=40.107.243.88 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="I0OxUuk5" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=GIzLPiWYYXRS6jZu1/DLGPxxm8GyY8tgfpRT07QYLlG2lcG1NLZ1qPCecdbUWLcNobuoizOzf0s0fzuHrj4DwuXOYZE2Jv3SdMGVOv6DFD0XEeP0Uiv9Zl1zUT+MqYHmot9Vk3Hs49j3b+IFNrjkbC49CzyqhF1K/o3l+OuQRrgFvkD5fb9oUAUDi68hSGbdeDxTVJIbamsY8m2K0WNkFgTWeIYubs+gGWh/j1OLnTHlmi4um1pObKUpn8Df9re/y2rv8tnpsZRJ8o6tsnPXa/HgmMpvA47KXBSxxAbtlNy+Klejmo5Lp3Qh9faipVdabv4ufWOieCIu94tCMX83Zg== 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=/lCLdHSXtJkYud82fzvTsYFf0+WNYAHh8Ljl4KMQ/Uk=; b=U6cfLNBe5CnuZH+mpB7z/mf4+cMdcAI3MPEG8HX815I4ZXcaHGXLUh4wQKl7acZ9s8/fO/CymAJ5jkJpOH9/5jdJiDw3X5QsTtA3j3LOBOSjBLhKfyxVaB/YbFDb6X4x+aGGhQMVd00tE2G0XU063+g3mer/+TGgxq7rU65o8w4qFAZmHi/7RlhCzcd+ya9QlnRP9jDdRFxdhWRPlYQJea87XRiWmyA7kEOVBkhXNdNQ9iUE+pPk0NuVzSgRBDLkMVwNhEFcX0PM086xFfKdPhoRs3Fz6a7CTxwmxgIvYeGKWbNXAaBgyxE/EaD0H5ZCXaWaICt7ITzI3c6NLyGtMw== 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 (0) 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=/lCLdHSXtJkYud82fzvTsYFf0+WNYAHh8Ljl4KMQ/Uk=; b=I0OxUuk5bx/pL8E8s0m5wNtPqy8K9sfE73Y/Ocr4sxKzEzGq6+Ech6XZ7pyuaiu7aOYceuuARqi5FU/3vXUPLATfUYKEXH6kdqX0iRIPmHHSPFowfkxxsyXpSYI2CxhO9BYl74QieJlTiN+iB1/XvaV0jRQbNyPEydOR5Jbqam8= Received: from SJ0PR05CA0003.namprd05.prod.outlook.com (2603:10b6:a03:33b::8) by SA3PR12MB8802.namprd12.prod.outlook.com (2603:10b6:806:314::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7409.40; Fri, 29 Mar 2024 21:30:15 +0000 Received: from SJ5PEPF000001C8.namprd05.prod.outlook.com (2603:10b6:a03:33b:cafe::4) by SJ0PR05CA0003.outlook.office365.com (2603:10b6:a03:33b::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7452.16 via Frontend Transport; Fri, 29 Mar 2024 21:30:15 +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 SJ5PEPF000001C8.mail.protection.outlook.com (10.167.242.36) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7409.10 via Frontend Transport; Fri, 29 Mar 2024 21:30:15 +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.35; Fri, 29 Mar 2024 16:30:14 -0500 From: Michael Roth To: CC: , Paolo Bonzini , Sean Christopherson , Isaku Yamahata , Xu Yilun , Binbin Wu , Xiaoyao Li , Matthew Wilcox Subject: [PATCH gmem 4/6] mm: Introduce AS_INACCESSIBLE for encrypted/confidential memory Date: Fri, 29 Mar 2024 16:24:42 -0500 Message-ID: <20240329212444.395559-5-michael.roth@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240329212444.395559-1-michael.roth@amd.com> References: <20240329212444.395559-1-michael.roth@amd.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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: SJ5PEPF000001C8:EE_|SA3PR12MB8802:EE_ X-MS-Office365-Filtering-Correlation-Id: efbb0557-2739-4477-af96-08dc50376c9c X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: v1zGjQ2zkewG9+btQMndrwTMoEiqcqx4husXYADoETD0zdrS3sHPUPBOhZuuBSk26eEsLFPs6wng57p4gnD8s+bwfVScYMWUDNVWOPwmYQ32YRMeBahwRPcD6wo9dbvmVjmqcm5MKSjLiT3NensqbhtTwS2vyPNGBH3PupZBkK8LZdpVoacuCoH589AsDWAuQcVITlpZ5i/B5vlh/iGoTDMmuaG3iKMQfbNGhGDryjZXaLEqX1KTAHnzvT+d7rfeR1OF8F3bHJXWyCE4hDDtezopcf/eu94mkA9LfmmEz8qtf71e9ig+dc8nohXBJ91ASsLAQZrOenSSN+t2Su5UFDK9vdUTNSB9EM/A/O3RyyazHSl3etkPIW5Ge6ooy/GdbIF3toSgFdnuxNKVYHeFRb+DLhWpNdPxhcnLM0I8rEbWbaMjon9paYZqIBG30ezU6hIY5EuLulypQOYGzFPvldm/qLPLwNl3duTXlY/vwFkVaE6Dmbzs93brGA9B9ZZNmgaq67Lta98r9GtD3AjjMOXi0fiLGCzqousXqgS7fz0q6H5VpIoIMcslxz03GHikd3BFqPGYwDbVijynMKYGw2rJ2hBd/MAz/ECnVb7ZDhxiXgxkxj+SA+LkihVPQwbaUAxrhAEsvtX6/uRAtaV769g+vwF8D0EWHDz12VTdmz1s9pwVHoHQkMp9FbFsPGaR/D1UFVUgSX1vhBGbymfSGg== 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)(36860700004)(376005)(82310400014)(1800799015);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Mar 2024 21:30:15.3992 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: efbb0557-2739-4477-af96-08dc50376c9c 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: SJ5PEPF000001C8.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA3PR12MB8802 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 Acked-by: Vlastimil Babka --- 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 e8ac0b32f84d..a7c3f43d1d22 100644 --- a/include/linux/pagemap.h +++ b/include/linux/pagemap.h @@ -207,6 +207,7 @@ enum mapping_flags { AS_STABLE_WRITES, /* must wait for writeback before modifying folio contents */ AS_UNMOVABLE, /* The mapping cannot be moved, ever */ + AS_INACCESSIBLE, /* Do not attempt direct R/W access to the mapping */ }; /** diff --git a/mm/truncate.c b/mm/truncate.c index 725b150e47ac..c501338c7ebd 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 Fri Mar 29 21:24:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Roth X-Patchwork-Id: 13611111 Received: from NAM04-DM6-obe.outbound.protection.outlook.com (mail-dm6nam04on2073.outbound.protection.outlook.com [40.107.102.73]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 09D0413792C for ; Fri, 29 Mar 2024 21:30:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.102.73 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711747844; cv=fail; b=YIkjwuNUzzOeRWU1I3zn+uRiXo0UOTNW5Wv4i24y52AR+VJKjh4MCVxYj6ri3mI43ovXaCz7cRcka/61NHzDOsCJiOjRiZ/9RF7xdmi0TxK8RshospfmyhZTbBsD0ZSlfLxtngr8fsw3kUTOaIvHq4QWwfhjqCx/TAZkdw1kAbo= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711747844; c=relaxed/simple; bh=XK+D24Mus0Fd07JBujOKIkrDHXMbMMVpD3gupVHk9as=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=XRG1K8LvSKHuPy+pIIjc7uu1l51w0tZp0D7tC4z4too2NPcVKD5pi/+Yh+RbWu3dVUiqiKM7xZWrcnTUVovojDGKCLPAo2Z1HRrnEmUi+79ygyNmmUedP/SItwmhYCVHe8OrZnAfvRT7gNgrejGS/+Jm/zWC362ZD4NkopOvuKo= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=49eW2WWB; arc=fail smtp.client-ip=40.107.102.73 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="49eW2WWB" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=GT1g8yvH1XiIyMv3WZzJr0f9OR4m2qNQEHYbpJNU2yS7QR0WxcABB+vft30MgudoqtusO2GADtOaEeK3/EDoaS0HmeKEVElxkdxnL1rT3vLf/6c/pO58VwLbtRhXgu44DCWEMjLzLbICMvKX4aa3LUFtKPEQoICO0Lu6wTz7sHy9aqttyb8HX0DwxcdKHeMURTPFDV26zRDJ7X1Y+MaTnrX+t+HeP+mCT95eGTVFix+i003o3SqYUP1ZrJWely38NM56W949SMYjn4Dg2ybjM/tOPyUhyOKmBmKYh8OQMPXxP8gAMs7/KEav6ltTzvqYmU7fZfH9iYFbZVWpK7hWLg== 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=SDJ9GNkgsvqUYnrui+dCPye3Ifpx9eOhVld2KHe7Kfg=; b=OhPSblThE+RenDPgf1HcXqsiDoZSm+4u9ni3LITnCRIyrK4j9MfHlIZfFaHF0tVdIrjncJVI3XnZGVWAENmEVPI/BkL0GpEusP95ea/+RiJ1U2t6eZW5PkRSMpnIXYOxfAtmUw49NdnZtX3vOy0gAAf2cRCOiKeO4zwRoBkk0aXeILbTJ5jLGZy8nvNF+UnEijqC1nOmhGGXLDRRFqsM9GgmoM4MFvf2rU2QYsx5dWNUMKPYx+roJtCW/iiOXh2BzLy+jWHUORKxx4mYlKPQlmknIhzwFWtpvllfOhgXd98MZ70NJk1+hovCcV/E5+jvONqwj2M+f/qqtl8OevvyFw== 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 (0) 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=SDJ9GNkgsvqUYnrui+dCPye3Ifpx9eOhVld2KHe7Kfg=; b=49eW2WWBX2d+bcp8GLInaCtH2PP/79KfcBPSjFAWhqUhYnziwuMReilySXJMi63SrZFe/e3aXvaX9W0/wMndJMXOSaRpkPfFdNfyRyL9yVH6ZcUKFNY4Pe++bH8Cki5fvp6jz6I4K1wgi5CVblObyjMCMqafjR4CYTdaaDWa/b4= Received: from BY3PR03CA0001.namprd03.prod.outlook.com (2603:10b6:a03:39a::6) by CH3PR12MB8329.namprd12.prod.outlook.com (2603:10b6:610:12e::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7409.40; Fri, 29 Mar 2024 21:30:40 +0000 Received: from SJ5PEPF000001C9.namprd05.prod.outlook.com (2603:10b6:a03:39a:cafe::6c) by BY3PR03CA0001.outlook.office365.com (2603:10b6:a03:39a::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7409.41 via Frontend Transport; Fri, 29 Mar 2024 21:30:36 +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 SJ5PEPF000001C9.mail.protection.outlook.com (10.167.242.37) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7409.10 via Frontend Transport; Fri, 29 Mar 2024 21:30:36 +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.35; Fri, 29 Mar 2024 16:30:35 -0500 From: Michael Roth To: CC: , Paolo Bonzini , Sean Christopherson , Isaku Yamahata , Xu Yilun , Binbin Wu , Xiaoyao Li Subject: [PATCH gmem 5/6] KVM: guest_memfd: Use AS_INACCESSIBLE when creating guest_memfd inode Date: Fri, 29 Mar 2024 16:24:43 -0500 Message-ID: <20240329212444.395559-6-michael.roth@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240329212444.395559-1-michael.roth@amd.com> References: <20240329212444.395559-1-michael.roth@amd.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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: SJ5PEPF000001C9:EE_|CH3PR12MB8329:EE_ X-MS-Office365-Filtering-Correlation-Id: b0fa828f-dd22-4374-38d9-08dc5037791f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 1Ah85ZJzdT1MmfwJUT1oLJ/mt5e06IV2F58zgUgMHG23CNVKp3VkSiuqNB6UfYaF4BEAE/r8jioyKjBpqnoQzYmBtQrMmSG4/60Bjb5x6+SUby31c2/TwWanex8taFGN/2hx0b+u9o6/Z6mlmd5EhXbtvU7EoQrhw46NTANnUDA4wdsIIBjruwWGLWuZmR0cLtW1bcrpKCoGhjjr6bPj2Z9SAzjn+FIa+VgaZdF6G0TO0sVRsE9kcOMFCHG0T476tXu5Ev5FSyiyaN/QY3k9Z2l918fdSepmREEqsIboP3BtrVtfsFxU9YRwaU8rWioBaa/teG5K6RmyT9CcfUzHOEMaRuqFpN64a05/ooAmXGZus86jbBNsN1Cr84GJpDcNQHsICgd19QcVgiZFrJo8+0aAm6HREvEJ06TtfeKRhuKpTxT77gE90sBhdCQ9Pau8V1D0SQodZnvsyOrQyLADSoxuooCwaj7Ras5kidhixfpqV/+F0dNuP5Zg0e5pN4HoM7L9/uRMEak1PYe0tXP2eINgP211TCnxK3KcNToC5NHJ9eJ8D8V+71y3LulvnmokXllkot8aSygikf1WG+tLJxrE42SSYM7Fbyo93G4oucvCL47Gr9zv4aNDUnw/x84yF555AIUjV4ZIZFGvz+JPtFm5s0Z3Tz/xK5uYrfIZA0i7ecFHzwamf5/g9M6Nss7HOIuhxn16Q4dydFvmDltcPw== 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)(36860700004)(376005)(82310400014)(1800799015);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Mar 2024 21:30:36.4030 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: b0fa828f-dd22-4374-38d9-08dc5037791f 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: SJ5PEPF000001C9.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH3PR12MB8329 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 Acked-by: Vlastimil Babka --- 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 4ce0056d1149..3668a5f1d82b 100644 --- a/virt/kvm/guest_memfd.c +++ b/virt/kvm/guest_memfd.c @@ -428,6 +428,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 Fri Mar 29 21:24:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Roth X-Patchwork-Id: 13611112 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2077.outbound.protection.outlook.com [40.107.244.77]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DD1AC1369BC for ; Fri, 29 Mar 2024 21:31:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.244.77 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711747865; cv=fail; b=kXtvAK/ArmxuRAOG6B9TmP9Z6WpB/7vXbm0VQHO5+RxJSnkVOTkcxG5RQs9LGbzvwrjGxqdwc/IBIs0WuFbTRGf7JocI3PONBTK6ER0ZJxT4aD3WGaxQtorlFNvU8pD3Q+QA29pClV2BLWq68fEkPF0m/iCdATVu6Eutdhv/mZk= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711747865; c=relaxed/simple; bh=lNtCR0A1c6b5FZaYMd40gScah5uy1hgosrD7l+hIo0w=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=QTARjv6C+KbwcHNtblzNvvhs/lp0Z020LNX+putszDwVxIHeh1T+yNbyr5KTliqx5AK5XCwEnxlP7VyWULVSbalf8cotggsYWEeUeyucq3otrCY/VOcEBldiXL4nXX1hQ/87dZSAl6CwPTrrlPvUxj6t+Llx12X26gJafWVomqo= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=f1jbCNR+; arc=fail smtp.client-ip=40.107.244.77 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="f1jbCNR+" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=RqUaU/h8ZP5PBw9z0lxOh+Zw/4m9pVFhy/Y5qv2mzLt6192RVUDvGeZaDPjYcwvCfmpboT5Dnr7LTHZ1jYHWTczCkMHIywrPxhTcOmzmvaa9lq7xiybui62Dumt+GL2anngWDj/Q42QmWe01/z6iSFF1Pk5C4uJb6uMWZI3Xv3N2Fo0Qw1s8H3rZCqbSBKDXETZnCQgXaq9TuGWDgVkrB5YNK4UPBigpalathiDzSpER6/qSvBEZMNbxa7Qgf8QZw4DS6Z5XXa0NcMzKVWf5Wn57d5mNBs6WO7Lux2VL8Vg3ok/K4bC952HRQQSObWoVlEAjtkKclQQut+3o14ch1Q== 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=hFtBDS2no1Ul0Q4qQCB1DyAo8Aqu1dKOcg07pwJhEVM=; b=hjSPiattuXzlYaXHt9Xq56ft8sjLFX6I4V6UD3KBrUe5rFFacwjj5IlpmD13mzHnbaTil9bWb5WbCb9GmH2ZQx5fzJhACztw7d4MR/dUVadR9PZTLrJkPM7eV9pbvslCCKXznedNVD0MdZF5piGpZgmnApBZw32WFlwFBbJosFC6eq5pcxczf53sRrmGFGhEP3pZ5YACtyw+BYXcHN0LMr/lx8jiXu1DwnuEvh4/Geh8ZcC5r4rpWUlGY0xfyKuKol0/Bb60xNj3YMOB+GBmvX3kvfIRYMMI0gsMmDUJ+/W7htDaBzdiR+9lLBsIxiMcP+ds5essGq2F/G0sKLn7tw== 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 (0) 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=hFtBDS2no1Ul0Q4qQCB1DyAo8Aqu1dKOcg07pwJhEVM=; b=f1jbCNR+EJ0MSfQ1UDy3v2RHCVUbl9ATQEPs3k9dBXXhqzHbbo/BMR+neA4cSvowVvf/ui3l+/w2Qplb75FS4nu82IEO7xUCjzslz2uI3e8NUrN05v23sJMiFVeyLvpiWKpyusQydRZA9Urw9q/a9CFpaDpvRagYpyhFaw5DgPk= Received: from SJ0PR05CA0180.namprd05.prod.outlook.com (2603:10b6:a03:339::35) by PH7PR12MB7212.namprd12.prod.outlook.com (2603:10b6:510:207::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7409.40; Fri, 29 Mar 2024 21:30:59 +0000 Received: from SJ5PEPF000001CA.namprd05.prod.outlook.com (2603:10b6:a03:339:cafe::37) by SJ0PR05CA0180.outlook.office365.com (2603:10b6:a03:339::35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7409.41 via Frontend Transport; Fri, 29 Mar 2024 21:30:59 +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 SJ5PEPF000001CA.mail.protection.outlook.com (10.167.242.39) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7409.10 via Frontend Transport; Fri, 29 Mar 2024 21:30:59 +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.35; Fri, 29 Mar 2024 16:30:56 -0500 From: Michael Roth To: CC: , Paolo Bonzini , Sean Christopherson , Isaku Yamahata , Xu Yilun , Binbin Wu , Xiaoyao Li Subject: [PATCH gmem 6/6] KVM: guest_memfd: Add interface for populating gmem pages with user data Date: Fri, 29 Mar 2024 16:24:44 -0500 Message-ID: <20240329212444.395559-7-michael.roth@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240329212444.395559-1-michael.roth@amd.com> References: <20240329212444.395559-1-michael.roth@amd.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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: SJ5PEPF000001CA:EE_|PH7PR12MB7212:EE_ X-MS-Office365-Filtering-Correlation-Id: d078135d-9400-4a37-0907-08dc503786af X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: a/6IEK7LA25fwn30gqlHpbIvyUmYKkiv9J1GdoqDoiQXKkHiQQsZRLKgCmjjACgb0oZz+57k6Ad0Z+1ipT43fhGP+hDBsZGfhZLC4YAlLwYtHLX3xzqeDcj/YFJqikvBSPhB1jDs/G+SE5UMroyMGqwRJ48IaEbQ3z1ftRUu2vql0mg423htKJWCx1kXYJlx3AGw/JEGUow1xTWcu2/xtc+ZadajqHaMNfqDJDSeSQ79PouC3uy7qrR9aTjgRttTK0CHs5OauDgxFfUpA3qRU71e1qRpalMpxS9ewrsguGomi64Xzxo1ieKv75DLvYFmwxGR2iIqis9Ugt6q86RG92o1vJLIC9gloS9Adm5KBzIoA2ENKBTtMVf1/m+t5fbXvO9xF/iRojfn5qIOP/XJdUq0jWBvhuzl6dGkWf6N0tcqBs1XLoSQO70hO9QG+27QqiTGIqvdK9YDhW40Q1q/A65uv6ERjFtuqghYEl/l4fKoTPJ0US9ntqejkffrx4oZS3/mAi1HyH70nQ1eISbRQr2QdF+Tnr4fJADN6fo8IU5R3d+bDTAX/kGuZzIJZ7Zt4bl8Vm2LXfEg/TyQ7XIURHNFcHFHBXNvUm/SuaNWnezx6KCNKH/Ga9EQH9Kp114t4MAj/GjJadENNsDhJLw/AoJD41FFVuK/j9NgpPYfQ36dlax5E+VHu/wnjt7PJpcA2cW4LE6VC0E5JtItoxZAbDSEg0IGpu4ORC9Jhv9aqDqQox84pVziZkgaLhAykdjA 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)(376005)(36860700004)(82310400014)(1800799015);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Mar 2024 21:30:59.1559 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: d078135d-9400-4a37-0907-08dc503786af 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: SJ5PEPF000001CA.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB7212 During guest run-time, kvm_arch_gmem_prepare() is issued as needed to prepare newly-allocated gmem pages prior to mapping them into the guest. In the case of SEV-SNP, this mainly involves setting the pages to private in the RMP table. However, for the GPA ranges comprising the initial guest payload, which are encrypted/measured prior to starting the guest, the gmem pages need to be accessed prior to setting them to private in the RMP table so they can be initialized with the userspace-provided data. Additionally, an SNP firmware call is needed afterward to encrypt them in-place and measure the contents into the guest's launch digest. While it is possible to bypass the kvm_arch_gmem_prepare() hooks so that this handling can be done in an open-coded/vendor-specific manner, this may expose more gmem-internal state/dependencies to external callers than necessary. Try to avoid this by implementing an interface that tries to handle as much of the common functionality inside gmem as possible, while also making it generic enough to potentially be usable/extensible for use-cases beyond just SEV-SNP. Suggested-by: Sean Christopherson Signed-off-by: Michael Roth --- include/linux/kvm_host.h | 40 ++++++++++++++++++++++++++++++++++++++++ virt/kvm/guest_memfd.c | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 80 insertions(+) diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h index 5b8308b5e4af..8a75787090f3 100644 --- a/include/linux/kvm_host.h +++ b/include/linux/kvm_host.h @@ -2473,4 +2473,44 @@ bool kvm_arch_gmem_prepare_needed(struct kvm *kvm); void kvm_arch_gmem_invalidate(kvm_pfn_t start, kvm_pfn_t end); #endif +/** + * kvm_gmem_populate_args - kvm_gmem_populate() argument structure + * + * @gfn: starting GFN to be populated + * @src: userspace-provided buffer containing data to copy into GFN range + * @npages: number of pages to copy from userspace-buffer + * @do_memcpy: whether to do a direct memcpy of the data prior to issuing + * the post-populate callback + * @post_populate: callback to issue for each gmem page that backs the GPA + * range (which will be filled with corresponding contents from + * @src if @do_memcpy was set) + * @opaque: opaque data to pass to @post_populate callback + */ +struct kvm_gmem_populate_args { + gfn_t gfn; + void __user *src; + int npages; + bool do_memcpy; + int (*post_populate)(struct kvm *kvm, struct kvm_memory_slot *slot, + gfn_t gfn, kvm_pfn_t pfn, void __user *src, int order, + void *opaque); + void *opaque; +}; + +/** + * kvm_gmem_populate() - Populate/prepare a GPA range with guest data + * + * @kvm: KVM instance + * @slot: slot containing the GPA range being prepared + * @args: argument structure + * + * This is primarily intended for cases where a gmem-backed GPA range needs + * to be initialized with userspace-provided data prior to being mapped into + * the guest as a private page. This should be called with the slots->lock + * held so that caller-enforced invariants regarding the expected memory + * attributes of the GPA range do not race with KVM_SET_MEMORY_ATTRIBUTES. + */ +int kvm_gmem_populate(struct kvm *kvm, struct kvm_memory_slot *slot, + struct kvm_gmem_populate_args *args); + #endif diff --git a/virt/kvm/guest_memfd.c b/virt/kvm/guest_memfd.c index 3668a5f1d82b..3e3c4b7fff3b 100644 --- a/virt/kvm/guest_memfd.c +++ b/virt/kvm/guest_memfd.c @@ -643,3 +643,43 @@ int kvm_gmem_undo_get_pfn(struct kvm *kvm, struct kvm_memory_slot *slot, return r; } EXPORT_SYMBOL_GPL(kvm_gmem_undo_get_pfn); + +int kvm_gmem_populate(struct kvm *kvm, struct kvm_memory_slot *slot, + struct kvm_gmem_populate_args *args) +{ + int ret, max_order, i; + + for (i = 0; i < args->npages; i += (1 << max_order)) { + void __user *src = args->src + i * PAGE_SIZE; + gfn_t gfn = args->gfn + i; + kvm_pfn_t pfn; + + ret = __kvm_gmem_get_pfn(kvm, slot, gfn, &pfn, &max_order, false); + if (ret) + break; + + if (!IS_ALIGNED(gfn, (1 << max_order)) || + (args->npages - i) < (1 << max_order)) + max_order = 0; + + if (args->do_memcpy && args->src) { + ret = copy_from_user(pfn_to_kaddr(pfn), src, (1 << max_order) * PAGE_SIZE); + if (ret) + goto e_release; + } + + if (args->post_populate) { + ret = args->post_populate(kvm, slot, gfn, pfn, src, max_order, + args->opaque); + if (ret) + goto e_release; + } +e_release: + put_page(pfn_to_page(pfn)); + if (ret) + break; + } + + return ret; +} +EXPORT_SYMBOL_GPL(kvm_gmem_populate);