Message ID | 20231016115028.996656-3-michael.roth@amd.com (mailing list archive) |
---|---|
State | New |
Headers | show
Return-Path: <owner-linux-mm@kvack.org> X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 39B5FCDB465 for <linux-mm@archiver.kernel.org>; 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 <linux-mm@kvack.org>; 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 <linux-mm@kvack.org>; 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 <linux-mm@kvack.org>; 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 <michael.roth@amd.com> To: <kvm@vger.kernel.org> CC: <linux-coco@lists.linux.dev>, <linux-mm@kvack.org>, <linux-crypto@vger.kernel.org>, <x86@kernel.org>, <linux-kernel@vger.kernel.org>, <linux-fsdevel@vger.kernel.org>, <pbonzini@redhat.com>, <seanjc@google.com>, <isaku.yamahata@intel.com>, <ackerleytng@google.com>, <vbabka@suse.cz>, <ashish.kalra@amd.com>, <nikunj.dadhania@amd.com>, <jroedel@suse.de>, <pankaj.gupta@amd.com> 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 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: 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: <linux-mm.kvack.org> |
Series |
KVM: gmem hooks/changes needed for x86 (other archs?)
|
expand
|
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);
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 <seanjc@google.com> Signed-off-by: Michael Roth <michael.roth@amd.com> --- virt/kvm/guest_memfd.c | 1 + 1 file changed, 1 insertion(+)