From patchwork Tue Feb 20 07:29:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ankit Agrawal X-Patchwork-Id: 13563528 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 767F1C48BC3 for ; Tue, 20 Feb 2024 07:30:31 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0E59C6B008C; Tue, 20 Feb 2024 02:30:31 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 096CD6B0092; Tue, 20 Feb 2024 02:30:31 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E79826B0093; Tue, 20 Feb 2024 02:30:30 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id D8BFC6B008C for ; Tue, 20 Feb 2024 02:30:30 -0500 (EST) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id AD88AC05B7 for ; Tue, 20 Feb 2024 07:30:30 +0000 (UTC) X-FDA: 81811359420.22.3B1191A Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2060.outbound.protection.outlook.com [40.107.94.60]) by imf22.hostedemail.com (Postfix) with ESMTP id AED5AC0007 for ; Tue, 20 Feb 2024 07:30:27 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=Nvidia.com header.s=selector2 header.b=K2r6bmJ6; dmarc=pass (policy=reject) header.from=nvidia.com; arc=pass ("microsoft.com:s=arcselector9901:i=1"); spf=pass (imf22.hostedemail.com: domain of ankita@nvidia.com designates 40.107.94.60 as permitted sender) smtp.mailfrom=ankita@nvidia.com ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1708414227; 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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=5HNtKkDPIq2Wa2PmpJenFBQzXvyzTh38KvX3ICNw+5U=; b=0xoyvrI89GbZgiAxgu88PdgXfd0siKB8YP8/BL2++atw9FnBrMdEkiSP7Z1H0EsGpfLeLK ILqCsnKm8tZHREIA/bu00p4UMvIn1QMfLMCjomLTCUPdfzYI01TXW+ob8lh+Dp2Ho53Zyx GnAX1yRmYZxD2LeWwC2rsdNQ7/j4sKs= ARC-Authentication-Results: i=2; imf22.hostedemail.com; dkim=pass header.d=Nvidia.com header.s=selector2 header.b=K2r6bmJ6; dmarc=pass (policy=reject) header.from=nvidia.com; arc=pass ("microsoft.com:s=arcselector9901:i=1"); spf=pass (imf22.hostedemail.com: domain of ankita@nvidia.com designates 40.107.94.60 as permitted sender) smtp.mailfrom=ankita@nvidia.com ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1708414227; a=rsa-sha256; cv=pass; b=PyEcucqtEF9WhbxQo7qV7e1h1wBrMAkjWL1uLZmyvGDXuhuxgKvJd22eWu3g30tYiG6cUO 40UZRctsSKoHjHA3QbLaN9H2vMondM4kk47a4B2P0KVIi4icsp2oWR4PCk2eNDZbOe0K38 2O3UJdBC1GiyLmRElWL6lyqRhGndIHE= ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=DdwWsruWQUaRyntM3PSubqCMNkV2OHywqxa/hgPBZDF5E1AyerPvJyevXzUIPb9nmeNQI0GwBaDsanwl3AYuz4OTbFS8B5i+j0NngtVmkK6NnD3awUPsx8SR5Z3If3H6DtTrtviW0aTps2hhB7+eIUm6cpH7CfGLvJaYanrDG1KHi2KfiYUBc65ciPzKSU0trutMTXnnnpwUYl1s6bWsMX7AIZbtVcfuXTJZshy95ihDw6BIaiaE9sVf/e/qL7pHoooNb7bX0mHXGS8b/5ijPbfKacCkuHs03SKqlkJGGitfm0okHPM+POc6+l+XR0hxmD/kX0QKKj7QBQ65XTtaKQ== 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=5HNtKkDPIq2Wa2PmpJenFBQzXvyzTh38KvX3ICNw+5U=; b=Ud91zoghkI6PfPQDILa95GjRRf386rPb6+xamcElDPq7Vo/oYfbFJNpVf/zBv9Jb0ccD8ulzvKLfDbrmlccraX/MbMZ8ceS6vAAPT/YJ0XiPTDwauIqYQtKSdjKIOlmRQqt/PGfWjZUGPIP2eEsqb4E3iTsN2xst7Giur0gxUhDSZoM7Vw4MjsSscw+PtuR7THvzSaIUSOZDLpAsd5XJFUNLI3wIy1sVweiBHZWGab+MMVdTWsjdLG6P4oIF7f2IhrveA+fwGLn3+7SIZJOL7mwsSEcZy1rlPnIzSfe+2oUqoKnC+WsJ1GEyJjNX/FKQzJG9K2F8bxdZe+28KPJScQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.160) smtp.rcpttodomain=kernel.org smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=5HNtKkDPIq2Wa2PmpJenFBQzXvyzTh38KvX3ICNw+5U=; b=K2r6bmJ6LloCVaYjqstLQFO2hLH7vK+PqWVlIvVUbEzbV664RUWA6ysiCptxa8go8mD25MN82hrU+0E7JjuWA1zAuAjhyRzeaoy69j3LMSMIqwzLjgjXFbkbF3AbIMbIAJRmHX2BkUPhPD++TfzWGE5JhqovQW16Cef/Cuj1c/GOlCtvy6+E46rqC2ItxbfyWASO8M8OwqlwL7tqKlHLfKZdcfByYmgR/lrlkg8SL2Xk/mK70792Fcxbx0544Kd3orNJO0Ha8VdeHtDkNL5Y4OK/as0NPjapZNUbb9OiRS1Lgy82r0Gavsugw1U+4kdoPINZ60vI3PT1lSwywvUZKg== Received: from DM6PR04CA0017.namprd04.prod.outlook.com (2603:10b6:5:334::22) by DM4PR12MB7501.namprd12.prod.outlook.com (2603:10b6:8:113::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7316.19; Tue, 20 Feb 2024 07:30:22 +0000 Received: from DS1PEPF00017096.namprd05.prod.outlook.com (2603:10b6:5:334:cafe::a4) by DM6PR04CA0017.outlook.office365.com (2603:10b6:5:334::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7292.39 via Frontend Transport; Tue, 20 Feb 2024 07:30:22 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.160) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.117.160 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.160; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.160) by DS1PEPF00017096.mail.protection.outlook.com (10.167.18.100) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7292.25 via Frontend Transport; Tue, 20 Feb 2024 07:30:22 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by mail.nvidia.com (10.129.200.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.41; Mon, 19 Feb 2024 23:30:10 -0800 Received: from rnnvmail202.nvidia.com (10.129.68.7) by rnnvmail201.nvidia.com (10.129.68.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1258.12; Mon, 19 Feb 2024 23:30:09 -0800 Received: from sgarnayak-dt.nvidia.com (10.127.8.9) by mail.nvidia.com (10.129.68.7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1258.12 via Frontend Transport; Mon, 19 Feb 2024 23:29:56 -0800 From: To: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , CC: , , , , , , , , , , , , , , Subject: [PATCH v8 2/4] mm: introduce new flag to indicate wc safe Date: Tue, 20 Feb 2024 12:59:24 +0530 Message-ID: <20240220072926.6466-3-ankita@nvidia.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240220072926.6466-1-ankita@nvidia.com> References: <20240220072926.6466-1-ankita@nvidia.com> MIME-Version: 1.0 X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS1PEPF00017096:EE_|DM4PR12MB7501:EE_ X-MS-Office365-Filtering-Correlation-Id: 9baeac31-ee65-4a6f-3e6f-08dc31e5cc6d X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: OjL1k5WQRcdh4vjhjQUUxo5cuWa1ZDmV55Tq5D+dou1QEShSv6LFhmfkPBvlzWv4/AHbwbRyH+JN/A4B/2nGMTsZBaHFlmaN5+/82PIawBYcSOLHBb2w7Z/5MStxWEi6MquQuTrUtUClyWEK/TNnMSYMI3poKqh8FJSbeBT5MMYF8/UmtSJxQsUxUngPXfiAlp5rrkdtvcFbaLUAQmKKgWvbKK0RpPQhK5iPQrVBrZoYtZRTza868S7ZuJsofxJmPfzc0mhQaW8ncc251pG362D7oS5tG/uJch1QSO7Mz0lsUNgyzm6xWwlUr6qKgLWVwLZ3rS37fSDiF220i6RRWOwHijFku3B3Az/PshJa2OmCld41T8yD1fxVG2j6MNRxUtKoJhXCGLwwE2r0B7HteMQI1xaf37K9clRYRHnJTSC9cj4S87tE4+XAJgOypzp8XkzrE7UafR1m8U9wf6gNVzOo5MecFksP9hP7CfJ6KVVXWiIaxbiKDabCmIeVkeSm+DvYZ6wVVBYbFAIpoWoPMshVOcZKFitAfEtC7lEE/xUfxvORxwrmQF23rZkfiBjvcJriskPO19Ed6vtn4SB0r5Ab0xZUxWWzVQXaReJgqC3nLcRudF6wk1wm5TYYVzJmgyflfA6h6xUHl7SR5M/J9l3wy1lx+cqjYIpVfhQbAL8= X-Forefront-Antispam-Report: CIP:216.228.117.160;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge1.nvidia.com;CAT:NONE;SFS:(13230031)(36860700004)(46966006)(40470700004)(921011);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Feb 2024 07:30:22.4876 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 9baeac31-ee65-4a6f-3e6f-08dc31e5cc6d X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.117.160];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: DS1PEPF00017096.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12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xHyUgIslIAKh+iaf89/an31ca lTk0AGiV JLjt/mEHqov9MQOOhDgmH7xhB2RA8DhQNKJbZMKHnbXmr6AqEnYnqxohe7KlrX5Zh6LVOROiz8ZlDxT9Htl+B9dTPIjJPMF4+FjO67VqDADgxUbIFMrsWr8JTI9kGgkm2fcxdIhbcAGFQdON2U125fDu/KCd5ITOIG03QYBWzVkM1zL38pco3jDlhe17PnYAzpFD/PLh/tv9qDbSbbDKBOLfVR14RoR53+kIjVsEIrzQsSCDa3MFCrYEytjvI4P64cedDHkeA4WmsXbLgPVfvJ9iNvfrKkMWp683IP9Zx3Do4DKuIMPGy92XmUg== 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: List-Subscribe: List-Unsubscribe: From: Ankit Agrawal The VM_ALLOW_ANY_UNCACHED flag is implemented for ARM64, allowing KVM stage 2 device mapping attributes to use NormalNC rather than DEVICE_nGnRE, which allows guest mappings supporting combining attributes (WC). ARM does not architecturally guarantee this is safe, and indeed some MMIO regions like the GICv2 VCPU interface can trigger uncontained faults if NormalNC is used. Even worse we expect there are platforms where even DEVICE_nGnRE can allow uncontained faults in corner cases. Unfortunately existing ARM IP requires platform integration to take responsibility to prevent this. To safely use VFIO in KVM the platform must guarantee full safety in the guest where no action taken against a MMIO mapping can trigger an uncontained failure. We belive that most VFIO PCI platforms support this for both mapping types, at least in common flows, based on some expectations of how PCI IP is integrated. This can be enabled more broadly, for instance into vfio-platform drivers, but only after the platform vendor completes auditing for safety. The VMA flag VM_ALLOW_ANY_UNCACHED was found to be the simplest and cleanest way to communicate the information from VFIO to KVM that mapping the region in S2 as NormalNC is safe. KVM consumes it to activate the code that does the S2 mapping as NormalNC. Suggested-by: Catalin Marinas Reviewed-by: Jason Gunthorpe Acked-by: David Hildenbrand Signed-off-by: Ankit Agrawal --- include/linux/mm.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/include/linux/mm.h b/include/linux/mm.h index f5a97dec5169..59576e56c58b 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -391,6 +391,20 @@ extern unsigned int kobjsize(const void *objp); # define VM_UFFD_MINOR VM_NONE #endif /* CONFIG_HAVE_ARCH_USERFAULTFD_MINOR */ +/* + * This flag is used to connect VFIO to arch specific KVM code. It + * indicates that the memory under this VMA is safe for use with any + * non-cachable memory type inside KVM. Some VFIO devices, on some + * platforms, are thought to be unsafe and can cause machine crashes + * if KVM does not lock down the memory type. + */ +#ifdef CONFIG_64BIT +#define VM_ALLOW_ANY_UNCACHED_BIT 39 +#define VM_ALLOW_ANY_UNCACHED BIT(VM_ALLOW_ANY_UNCACHED_BIT) +#else +#define VM_ALLOW_ANY_UNCACHED VM_NONE +#endif + /* Bits set in the VMA until the stack is in its final location */ #define VM_STACK_INCOMPLETE_SETUP (VM_RAND_READ | VM_SEQ_READ | VM_STACK_EARLY)