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: 153354 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp3402010vqb; Mon, 16 Oct 2023 04:52:51 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFXvTsHdQxBjtV84+rcgai55P0I9nmc6hgHsZOmvMkdG6G+7jrcm7Tqz4WC0Oxu/g+YMUyq X-Received: by 2002:a05:6a00:3ab:b0:68f:c309:9736 with SMTP id y43-20020a056a0003ab00b0068fc3099736mr36285445pfs.3.1697457171020; Mon, 16 Oct 2023 04:52:51 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697457171; cv=pass; d=google.com; s=arc-20160816; b=SMfgGP6mST1Mtl46dj6RM+SdHDh2/5Gcjw2rdX/9Mm9dObUXHUY47oTVdfSnprNupn z3Bad1LXYpGJasjlWUryhdEUCN6q6KkxdDhd20HwDHyhfnRa156ptHRJvFFP88kgvsD8 AUxOb8EWPGapGacq7jZ5hNwfLpLBmvqRsFrbs3AXqr4dpI39cUa7DlfQMyY5HsoZ1UKf 3MTGuFTdRQCeWLBW/zNlbqxT/5PsEDNAvWwHjyIqPLi/QBAOpZDYkAPmOjYN3mnHKDBG ONZ0eUoDmUc3PBWOGducXHOckVxBYSv/eBgbUVc7Fem7gNw3TgNFQAwmLH16ceaKg7H4 rl8A== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=k9F4dMH6wTBPjd0LQYAclw+pyXgphEr5kdLSN2lHbR4=; fh=O/33OfWh3tgBRvVucuqbtMFeS8FpVuifQ5WdKFtCmeQ=; b=ODkkdRpsZSpUwhdNyf6WXMzGGvQEQvHI/+/XJnSHVQPRHqRdDrSe2ftY8V4pre32Ez 9eZ8s91K+2guWlzrJmAr8SEL82ZdWfiNvmFMal6LxKbCGf/W0uqmiXGjUYbVjxL3tCs4 y/kh0dBdSs+Qutya+fGrWsvGdjI2q8xC9WEyJKvd7vdrXIHkLXRyQEyEWryyiwHtA+lz R8CQEf331mAlZZy7TJXPW90gsbhZkHkRZiBYGkGLg/vi44ekYGpINA9zcfotLRSnw6Zu InaVaL+EvUNQa22BiZioINS2nGK4KWvFcINdzEtyrzHtvBPfgTdqFuIbTzGUimtQaJMf uh/g== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=QyYLeFe5; arc=pass (i=1 spf=pass spfdomain=amd.com dmarc=pass fromdomain=amd.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amd.com Received: from fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id s33-20020a056a0017a100b006b5c34a0c8csi6704249pfg.251.2023.10.16.04.52.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Oct 2023 04:52:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=QyYLeFe5; arc=pass (i=1 spf=pass spfdomain=amd.com dmarc=pass fromdomain=amd.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amd.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id BA4EA8027488; Mon, 16 Oct 2023 04:52:48 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232090AbjJPLwf (ORCPT + 18 others); Mon, 16 Oct 2023 07:52:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44814 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232905AbjJPLwc (ORCPT ); Mon, 16 Oct 2023 07:52:32 -0400 Received: from NAM02-DM3-obe.outbound.protection.outlook.com (mail-dm3nam02on2074.outbound.protection.outlook.com [40.107.95.74]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5CF8FF3; Mon, 16 Oct 2023 04:52:29 -0700 (PDT) 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-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (fry.vger.email [0.0.0.0]); Mon, 16 Oct 2023 04:52:48 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1779912850951018275 X-GMAIL-MSGID: 1779912850951018275 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);