From patchwork Sun Feb 11 17:47:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ankit Agrawal X-Patchwork-Id: 13552533 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 B2CE8C4829B for ; Sun, 11 Feb 2024 17:47:38 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 292136B0074; Sun, 11 Feb 2024 12:47:38 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 21A126B0075; Sun, 11 Feb 2024 12:47:38 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 046786B0078; Sun, 11 Feb 2024 12:47:37 -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 E08516B0074 for ; Sun, 11 Feb 2024 12:47:37 -0500 (EST) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 7167180655 for ; Sun, 11 Feb 2024 17:47:37 +0000 (UTC) X-FDA: 81780255354.21.592C70A Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2041.outbound.protection.outlook.com [40.107.236.41]) by imf28.hostedemail.com (Postfix) with ESMTP id 7C8B4C000C for ; Sun, 11 Feb 2024 17:47:34 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=Nvidia.com header.s=selector2 header.b=PJqTo1GC; dmarc=pass (policy=reject) header.from=nvidia.com; arc=pass ("microsoft.com:s=arcselector9901:i=1"); spf=pass (imf28.hostedemail.com: domain of ankita@nvidia.com designates 40.107.236.41 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=1707673654; 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=8reAq1+JeHA8Bw3vavJBNBftpGtUmI2ty9heYFxxluA=; b=wqJFT41zGTlEZ4pkJQbaV0LfYSAL6+fhme03P6ENoiUQJ/aGTpA19tbzPDkHP5FHSQfYPz P0M8tPp9fVITaHSqDMUvu7HZmQcvHzxvx1OX/wFOjDNxlDiKLY46ukl+EP9yIKv01jQMtL ETNOc17fn3pdyly7IEFJbehOUzEgEig= ARC-Authentication-Results: i=2; imf28.hostedemail.com; dkim=pass header.d=Nvidia.com header.s=selector2 header.b=PJqTo1GC; dmarc=pass (policy=reject) header.from=nvidia.com; arc=pass ("microsoft.com:s=arcselector9901:i=1"); spf=pass (imf28.hostedemail.com: domain of ankita@nvidia.com designates 40.107.236.41 as permitted sender) smtp.mailfrom=ankita@nvidia.com ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1707673654; a=rsa-sha256; cv=pass; b=YusVQ98izyP/n51gEY6Fr2QFkY2XoyuK/NRlrad74H0WVwZZukncT5TB1cfopDAMcnsPll wV7/wKUP8JtkimrYTQS95oREY9idKU4lhrs9BtpZz57h9yRW2BrjqeNMmxLCGyexpgDSn9 rYfUChJ5Qea/0t0Hi/9eheCorMOewKw= ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=D1OXMuF8BkMUg5PxoNpQtEwa+gZ/Ed27GjLp2lz55xay9NBRXFfG23GDPKp+qcWkYhzwSKZNlwpwaNP0SHgAT3lbdhS+kmmqzsU3f8gb3n/kU2gsilEfns+RMuEEGryxNFIV1IclGbiqpcYCgHq4ih84y51p2Grx/9W541T7tT6ww8apptzbj/rZYqKCCw2dH+mCKOTFks9GorwQ+0UFxPNl8PjSnEgwT0lF85ZaZvRL51G4WBvS4ZI416UkIBLwV1UvJ063D+SZbs5g+1Yi0ftt2DTQOL4xubDnlmNsFuCra96H2Ezg6IH6BlwT90reX2ylQ3e5i9xaj2tjUjWGgQ== 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=8reAq1+JeHA8Bw3vavJBNBftpGtUmI2ty9heYFxxluA=; b=TcuU7snBVquqUBiTdvWw1WagIcqVQ87IXKMGddrenI6ksytAy7KjkdPMak6aSlm5nP2Pk7EZ6wGjKvIZQWNEHvDAob5O3Ej9KcDc53qdHT1LdvKxk9RvuMrezZ4BokF1tLfLu/10vvrfM33a/zzto7lTAVjywIYB4VrlfbMjKyv3vct6bi7QhVhQUOMiOJLm6+CNXmnRkeBLtZo8B3hzPJq6k0/nkSqjugAD/9o3+a8OUj7FUvfXWGX3JeTSN1AW3z4gWigj1g25Vw3zUUiSmRdya6s0nIImj9Ai4uOdGokwk3jK5vyGTFwmaO5azvSmwPkHrNnjQRfbPXgqVoBIdQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.118.233) 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=8reAq1+JeHA8Bw3vavJBNBftpGtUmI2ty9heYFxxluA=; b=PJqTo1GC7rq8wnb+k8DNmIoi1K8AJvIHnqByf9v7oDYmzLSwnKqx9fO4IKADeumxNTj6jOw2M4iprgG4Xx37s7wZfwOHE0NAzuWthtDoYmBEFlvuG6rwlTCSysFSpUefgfqEqLLFW74bAC0J1k+LwD4AFLUNtZj8bhNGcGvM9Wy4gULYMEokacQ/TpFT762GqKMx2GMDN//ZarYVKMfpC+JH5YoMdswe5t9NVz4MPWXECAWf3PRpJ41RN+RFwmD+q/lrzP/0BVrm9gnEfYYc/JeNlfHhXsGviCVQHF8K4v0ZM3HGT7l+kAIcXp7MJttQApPK/GQ/0K3BUqavPy4elw== Received: from DM6PR03CA0037.namprd03.prod.outlook.com (2603:10b6:5:100::14) by IA0PR12MB7626.namprd12.prod.outlook.com (2603:10b6:208:438::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7270.17; Sun, 11 Feb 2024 17:47:31 +0000 Received: from DS3PEPF000099D6.namprd04.prod.outlook.com (2603:10b6:5:100:cafe::65) by DM6PR03CA0037.outlook.office365.com (2603:10b6:5:100::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7270.38 via Frontend Transport; Sun, 11 Feb 2024 17:47:31 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.118.233) 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.118.233 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.118.233; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.118.233) by DS3PEPF000099D6.mail.protection.outlook.com (10.167.17.7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7249.19 via Frontend Transport; Sun, 11 Feb 2024 17:47:31 +0000 Received: from drhqmail201.nvidia.com (10.126.190.180) by mail.nvidia.com (10.127.129.6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.41; Sun, 11 Feb 2024 09:47:29 -0800 Received: from drhqmail203.nvidia.com (10.126.190.182) by drhqmail201.nvidia.com (10.126.190.180) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1258.12; Sun, 11 Feb 2024 09:47:29 -0800 Received: from sgarnayak-dt.nvidia.com (10.127.8.9) by mail.nvidia.com (10.126.190.182) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1258.12 via Frontend Transport; Sun, 11 Feb 2024 09:47:18 -0800 From: To: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , CC: , , , , , , , , , , , , , , Subject: [PATCH v7 1/4] kvm: arm64: introduce new flag for non-cacheable IO memory Date: Sun, 11 Feb 2024 23:17:02 +0530 Message-ID: <20240211174705.31992-2-ankita@nvidia.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240211174705.31992-1-ankita@nvidia.com> References: <20240211174705.31992-1-ankita@nvidia.com> MIME-Version: 1.0 X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS3PEPF000099D6:EE_|IA0PR12MB7626:EE_ X-MS-Office365-Filtering-Correlation-Id: 0beddbec-28df-4e17-feea-08dc2b29857b X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: xgljVu+PnyWV78w40OoG/UkZqtf0xWHqpZ7AalVVNbMzufrBNhT6/GF3eqzYWeluGzOTWfN0kEVl9ALoSvUDPlQr2jn8tnuY48jw9WPOp+11TZoymLbnttVCCLohRbrcAJ4olxOFoJNmV4GxOIxv1aaxPRI1YPK9+GEoV240jNMrxdAyRVh83Atv/5g0D3wu8t3YvmWWFR7UEXDKuA+RkTSk1k4r2jn3ztzYojBUGv5zqjPiwR7WfK/E9RzFFGv0yGOU6BHcqSYf0a1R5WtgmsOme0vxucbkvJHdn6WKfrEQhJaewrUG0KcnMAlY8Qsl4/l5DD5R9z3ZrnfUBhVUmdAK36sz0+W4qKUJKsanMeCf1jQPeh0dVlIvCrhcERwXIMw4L1UqfY0fR40jdVz+DS94U2hfUN8XXkQ7idZUSOpxdGJrOjbXWb7lqjmy6jAAnFx2PUFm8qfbwI3jdbYwLiCg0q92ZyQTOseweFWzyVXgTX79/smDEhtmRWwvGszjIyXQYMraFLIXbJnh73oSTqJyFgpjDRUD1JSm2Ee0Ny/jRIq6Q/frjqsFJItH0YdrsMsjBQg9lZOLcECNKou6o7RGAa4pFbIegh7zDk3CB+rCxeMy8idxvTkb5Q9R7KgOq2s1yOxSHXRnRn+XGMwKng== X-Forefront-Antispam-Report: CIP:216.228.118.233;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc7edge2.nvidia.com;CAT:NONE;SFS:(13230031)(4636009)(396003)(346002)(136003)(376002)(39860400002)(230922051799003)(451199024)(186009)(82310400011)(1800799012)(64100799003)(36840700001)(46966006)(40470700004)(83380400001)(41300700001)(26005)(478600001)(1076003)(2906002)(6666004)(70206006)(7696005)(7406005)(426003)(316002)(7416002)(110136005)(54906003)(7636003)(19627235002)(2616005)(8676002)(70586007)(356005)(82740400003)(5660300002)(921011)(86362001)(336012)(4326008)(8936002)(36756003)(2876002);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Feb 2024 17:47:31.1667 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 0beddbec-28df-4e17-feea-08dc2b29857b X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.118.233];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: DS3PEPF000099D6.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA0PR12MB7626 X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 7C8B4C000C X-Stat-Signature: zynstyacnof9rmqrhjetxpwo9m83oq7y X-Rspam-User: X-HE-Tag: 1707673654-604119 X-HE-Meta: U2FsdGVkX18xuTYfLu37S+L6dRIaGgiHf1Mp8ZDS4xZRUUZKVfIe3K0QSY3sCatZQRTpfMge/iETlPrQ+OOR2/BuDgPos60pFMIPSOwEOGenAtIAHeh2vvOdqsBhwVbhn5O0YMLO3oiXBHCqelq0elOiBa9A0xXOnA4YwXNasAfucTY5Mph8vmogk/YV05+1L1NqUdrPjMrlW++/58fFdv1zerByxlFi/SbjeRIheOzU6jEcxFjd+RHab9ui15S2K3qzaEdX4/8hf0dtyOQ0CZBV5an1/fO+QQY82cePnGJlOxufCdTif9J9K3ruYhd6B+8HD+g5LOLTMzbMn7uRi41foMHYNX4a3CALEP78uOzlHj3Yh4JYN/oZUdusyHg3SDRuSC4zYslktr2JZ6nN30Xgv7VkXN81jwFZnDMxYHyAZazm8sh0LxIwhVOm/sHyxZ4UwCqIe9iQJTNkHE/cW3MX5Hw1vvcE0gPO108BzYWUq/vWFdmHLuti2gfSURxD8jve5MP3pqLqWsOub6UZX85wmI8lJ0xgRiFwxddf3sUzqRKvyfiUNhGLiw47HEiYOaDJ9Kd+naPeNT1+FeO6xsSt0RciGfXf+/b05PyW+N7AuSqyk7MoCg3E7+aUJyMAhlZ6Ft75HIs2MqapjUs2DGKvXPdY3WXjRw9JS41XYYLgFA7mwCWJYOPb3B/aCeEUGoIJ7PioRvU2haP9sUM+2GXcqKLlcDDIydYeazuH0v9BvxokG1tJzmZi0ZUJ/M59H+G9sm6qxfBpM7u6rt805ZXQS8XGCocP0mL5HwgdvAVV1xG1WequKy7HnXmQPTu2as3hjzlqSKtUi2dAhUjp+QxIJGygvZOAv1/4uR3KQmBdHBZTgQS2aOGovT1hETrANwXTBwOCCDhdVygXtlMjtL+drYaL8+pqPsjMi5JyZXMDSnUFFdp/lsfsclmqUC6O9PYwwroOs97L3SCFX/k 5+/22Nme 0d1dMy5xAGt44lMaDx08lSlrpfXbg/hxNLMH6nFv9EiLq12Nphgt1n3itKMnE8oxTcNc2Ac+Lk1eCNT6FiUVf8M6MP/iI30oAyEoB/dHD5SSoxA5sSboJT1cfolf4t2F0QuH853QBd6bmX6kfOHn4bgx5MRk4RjT8PJ3CKKpX6yvQiYLHIJkQzw9/LtiMaR1BBvAArzRJGRsChBKQ5/8Rz08+ofPSNObr4XmKwtuRlvNZY7iyhbn3BfGTihQ9ZOWZgecqUn/SGM/0q5uUUD3NICEnHumJC9/55poM 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 Currently, KVM for ARM64 maps at stage 2 memory that is considered device (i.e. it is not RAM) with DEVICE_nGnRE memory attributes; this setting overrides (as per the ARM architecture [1]) any device MMIO mapping present at stage 1, resulting in a set-up whereby a guest operating system cannot determine device MMIO mapping memory attributes on its own but it is always overridden by the KVM stage 2 default. This set-up does not allow guest operating systems to select device memory attributes independently from KVM stage-2 mappings (refer to [1], "Combining stage 1 and stage 2 memory type attributes"), which turns out to be an issue in that guest operating systems (e.g. Linux) may request to map devices MMIO regions with memory attributes that guarantee better performance (e.g. gathering attribute - that for some devices can generate larger PCIe memory writes TLPs) and specific operations (e.g. unaligned transactions) such as the NormalNC memory type. The default device stage 2 mapping was chosen in KVM for ARM64 since it was considered safer (i.e. it would not allow guests to trigger uncontained failures ultimately crashing the machine) but this turned out to be asynchronous (SError) defeating the purpose. Failures containability is a property of the platform and is independent from the memory type used for MMIO device memory mappings. Actually, DEVICE_nGnRE memory type is even more problematic than Normal-NC memory type in terms of faults containability in that e.g. aborts triggered on DEVICE_nGnRE loads cannot be made, architecturally, synchronous (i.e. that would imply that the processor should issue at most 1 load transaction at a time - it cannot pipeline them - otherwise the synchronous abort semantics would break the no-speculation attribute attached to DEVICE_XXX memory). This means that regardless of the combined stage1+stage2 mappings a platform is safe if and only if device transactions cannot trigger uncontained failures and that in turn relies on platform capabilities and the device type being assigned (i.e. PCIe AER/DPC error containment and RAS architecture[3]); therefore the default KVM device stage 2 memory attributes play no role in making device assignment safer for a given platform (if the platform design adheres to design guidelines outlined in [3]) and therefore can be relaxed. For all these reasons, relax the KVM stage 2 device memory attributes from DEVICE_nGnRE to Normal-NC. The NormalNC was chosen over a different Normal memory type default at stage-2 (e.g. Normal Write-through) to avoid cache allocation/snooping. Relaxing S2 KVM device MMIO mappings to Normal-NC is not expected to trigger any issue on guest device reclaim use cases either (i.e. device MMIO unmap followed by a device reset) at least for PCIe devices, in that in PCIe a device reset is architected and carried out through PCI config space transactions that are naturally ordered with respect to MMIO transactions according to the PCI ordering rules. Having Normal-NC S2 default puts guests in control (thanks to stage1+stage2 combined memory attributes rules [1]) of device MMIO regions memory mappings, according to the rules described in [1] and summarized here ([(S1) - stage1], [(S2) - stage 2]): S1 | S2 | Result NORMAL-WB | NORMAL-NC | NORMAL-NC NORMAL-WT | NORMAL-NC | NORMAL-NC NORMAL-NC | NORMAL-NC | NORMAL-NC DEVICE | NORMAL-NC | DEVICE It is worth noting that currently, to map devices MMIO space to user space in a device pass-through use case the VFIO framework applies memory attributes derived from pgprot_noncached() settings applied to VMAs, which result in device-nGnRnE memory attributes for the stage-1 VMM mappings. This means that a userspace mapping for device MMIO space carried out with the current VFIO framework and a guest OS mapping for the same MMIO space may result in a mismatched alias as described in [2]. Defaulting KVM device stage-2 mappings to Normal-NC attributes does not change anything in this respect, in that the mismatched aliases would only affect (refer to [2] for a detailed explanation) ordering between the userspace and GuestOS mappings resulting stream of transactions (i.e. it does not cause loss of property for either stream of transactions on its own), which is harmless given that the userspace and GuestOS access to the device is carried out through independent transactions streams. A Normal-NC flag is not present today. So add a new kvm_pgtable_prot (KVM_PGTABLE_PROT_NORMAL_NC) flag for it, along with its corresponding PTE value 0x5 (0b101) determined from [1]. Lastly, adapt the stage2 PTE property setter function (stage2_set_prot_attr) to handle the NormalNC attribute. [1] section D8.5.5 - DDI0487J_a_a-profile_architecture_reference_manual.pdf [2] section B2.8 - DDI0487J_a_a-profile_architecture_reference_manual.pdf [3] sections 1.7.7.3/1.8.5.2/appendix C - DEN0029H_SBSA_7.1.pdf Suggested-by: Jason Gunthorpe Acked-by: Catalin Marinas Signed-off-by: Ankit Agrawal --- arch/arm64/include/asm/kvm_pgtable.h | 2 ++ arch/arm64/include/asm/memory.h | 2 ++ arch/arm64/kvm/hyp/pgtable.c | 24 +++++++++++++++++++----- 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/arch/arm64/include/asm/kvm_pgtable.h b/arch/arm64/include/asm/kvm_pgtable.h index cfdf40f734b1..19278dfe7978 100644 --- a/arch/arm64/include/asm/kvm_pgtable.h +++ b/arch/arm64/include/asm/kvm_pgtable.h @@ -197,6 +197,7 @@ enum kvm_pgtable_stage2_flags { * @KVM_PGTABLE_PROT_W: Write permission. * @KVM_PGTABLE_PROT_R: Read permission. * @KVM_PGTABLE_PROT_DEVICE: Device attributes. + * @KVM_PGTABLE_PROT_NORMAL_NC: Normal noncacheable attributes. * @KVM_PGTABLE_PROT_SW0: Software bit 0. * @KVM_PGTABLE_PROT_SW1: Software bit 1. * @KVM_PGTABLE_PROT_SW2: Software bit 2. @@ -208,6 +209,7 @@ enum kvm_pgtable_prot { KVM_PGTABLE_PROT_R = BIT(2), KVM_PGTABLE_PROT_DEVICE = BIT(3), + KVM_PGTABLE_PROT_NORMAL_NC = BIT(4), KVM_PGTABLE_PROT_SW0 = BIT(55), KVM_PGTABLE_PROT_SW1 = BIT(56), diff --git a/arch/arm64/include/asm/memory.h b/arch/arm64/include/asm/memory.h index d82305ab420f..449ca2ff1df6 100644 --- a/arch/arm64/include/asm/memory.h +++ b/arch/arm64/include/asm/memory.h @@ -173,6 +173,7 @@ * Memory types for Stage-2 translation */ #define MT_S2_NORMAL 0xf +#define MT_S2_NORMAL_NC 0x5 #define MT_S2_DEVICE_nGnRE 0x1 /* @@ -180,6 +181,7 @@ * Stage-2 enforces Normal-WB and Device-nGnRE */ #define MT_S2_FWB_NORMAL 6 +#define MT_S2_FWB_NORMAL_NC 5 #define MT_S2_FWB_DEVICE_nGnRE 1 #ifdef CONFIG_ARM64_4K_PAGES diff --git a/arch/arm64/kvm/hyp/pgtable.c b/arch/arm64/kvm/hyp/pgtable.c index c651df904fe3..e2982a8922c3 100644 --- a/arch/arm64/kvm/hyp/pgtable.c +++ b/arch/arm64/kvm/hyp/pgtable.c @@ -717,15 +717,29 @@ void kvm_tlb_flush_vmid_range(struct kvm_s2_mmu *mmu, static int stage2_set_prot_attr(struct kvm_pgtable *pgt, enum kvm_pgtable_prot prot, kvm_pte_t *ptep) { - bool device = prot & KVM_PGTABLE_PROT_DEVICE; - kvm_pte_t attr = device ? KVM_S2_MEMATTR(pgt, DEVICE_nGnRE) : - KVM_S2_MEMATTR(pgt, NORMAL); + kvm_pte_t attr; u32 sh = KVM_PTE_LEAF_ATTR_LO_S2_SH_IS; + switch (prot & (KVM_PGTABLE_PROT_DEVICE | + KVM_PGTABLE_PROT_NORMAL_NC)) { + case KVM_PGTABLE_PROT_DEVICE | KVM_PGTABLE_PROT_NORMAL_NC: + return -EINVAL; + case KVM_PGTABLE_PROT_DEVICE: + if (prot & KVM_PGTABLE_PROT_X) + return -EINVAL; + attr = KVM_S2_MEMATTR(pgt, DEVICE_nGnRE); + break; + case KVM_PGTABLE_PROT_NORMAL_NC: + if (prot & KVM_PGTABLE_PROT_X) + return -EINVAL; + attr = KVM_S2_MEMATTR(pgt, NORMAL_NC); + break; + default: + attr = KVM_S2_MEMATTR(pgt, NORMAL); + } + if (!(prot & KVM_PGTABLE_PROT_X)) attr |= KVM_PTE_LEAF_ATTR_HI_S2_XN; - else if (device) - return -EINVAL; if (prot & KVM_PGTABLE_PROT_R) attr |= KVM_PTE_LEAF_ATTR_LO_S2_S2AP_R; From patchwork Sun Feb 11 17:47:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ankit Agrawal X-Patchwork-Id: 13552534 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 DCA8BC4829A for ; Sun, 11 Feb 2024 17:47:49 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 725FA6B0078; Sun, 11 Feb 2024 12:47:49 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 6AE446B007B; Sun, 11 Feb 2024 12:47:49 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 54FFC6B007D; Sun, 11 Feb 2024 12:47:49 -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 42A856B0078 for ; Sun, 11 Feb 2024 12:47:49 -0500 (EST) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 12AE5C0579 for ; Sun, 11 Feb 2024 17:47:49 +0000 (UTC) X-FDA: 81780255858.27.E61082C Received: from NAM02-DM3-obe.outbound.protection.outlook.com (mail-dm3nam02on2040.outbound.protection.outlook.com [40.107.95.40]) by imf21.hostedemail.com (Postfix) with ESMTP id 3DE071C0004 for ; Sun, 11 Feb 2024 17:47:46 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=Nvidia.com header.s=selector2 header.b=maM81IZg; spf=pass (imf21.hostedemail.com: domain of ankita@nvidia.com designates 40.107.95.40 as permitted sender) smtp.mailfrom=ankita@nvidia.com; dmarc=pass (policy=reject) header.from=nvidia.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=1707673666; 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=k5zGtt47H9t3q8PQmD/JIeN4xCzA2TDjhLc/bv9gbc0=; b=oNAjrpAWgYDPU1DOjD54wwiD1KegNoUYJJMllou8tXTQIMlgtTpY8LCexIBySxc4vbrb/V 3qPdlZRZEID0BZSAvCSe6RohcjNoib3vT5P68BSthwUAyMND1sfNLiWbx1h+n+QcP2SsIG UKaIQKuogpeGHWs4m9VYKc5sMusmvJk= ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1707673666; a=rsa-sha256; cv=pass; b=mkiZB3MaxwWZJGFFbWYSaOIxhNVIwNkDaTPCx9HyXNeNSDup4VTbX6Xl+llb8m/m6GC1VB qGnH1LsB6n6Mbafqn0V11eP/51vC9Src7MyEZojCqwrm5XkU0fpyaxEE6Z2UhRF75z1i8J GRHb5M9vBzXPELROWy4mCHB6SLu7uQM= ARC-Authentication-Results: i=2; imf21.hostedemail.com; dkim=pass header.d=Nvidia.com header.s=selector2 header.b=maM81IZg; spf=pass (imf21.hostedemail.com: domain of ankita@nvidia.com designates 40.107.95.40 as permitted sender) smtp.mailfrom=ankita@nvidia.com; dmarc=pass (policy=reject) header.from=nvidia.com; arc=pass ("microsoft.com:s=arcselector9901:i=1") ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=b14R01CnK/mOWDiIO/92bQZROhx4hCOWYfz15x5x6zOBIuXWwWsh9/ha2I2NtKhsK+29JNFKVYgYsNptcttFkM54FFJpwr/ExeLEjxi/HAZDsJRgfogZ1CMLmsTjO4BZr8rak638oUG3cKjuFjQpggUvr5p+0pmVeKncv9opVhYfkI95KVee8bXeQ17ZFedn9U4bu9QEkhDm7BhP8m3vYm37ZtnGARbbXDF40CEWwo8/PWzsCUOgeeCTysnz7wyJK8DXvzldNvvqnNax5yd57sSUyiXxw9itHH1xl9QwoB5pXp5ckavgHlXkVwLwGurwZa2QjHbE/pKhiAY+b1SwTA== 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=k5zGtt47H9t3q8PQmD/JIeN4xCzA2TDjhLc/bv9gbc0=; b=oeQUJoV6s3BXmk6/i+5qub+shlf9IptHeXlwSZwN0olqvrvnK1GwUZxSJ8K1+x3+V8/hHFUtu96AYoAhuGH8Fflk6NbstRF2z8eoy18v16UJ7QfNfigN0t1khOBhMtE5IbyhgIrL3zxzLvT8qFs2kRvHHxz+kw/U3rs1ghvH+Esm7TnUo0b7WqPX06g7sdUD2v+OwWsTex0CQVn5PYfZXWJszGMTgcIcxGtGVN49cBkRFf8VDIOLHh+TQ2YHROGTHboMIcGX6qb3tfdZL5lso+RZXxL2tZFVfBBqmr0Akf5FdNm/2eBNWTi/3ivyRPWHKnZ8Z96zi5V+lJF8PodcAA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.118.233) 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=k5zGtt47H9t3q8PQmD/JIeN4xCzA2TDjhLc/bv9gbc0=; b=maM81IZgir/IjiP0aa+kMAn+vlKuOWZGU/dLRKffzIBbuOKXezJNsqG7Wh58l04hQxwvFN+dd1IFFV7cjYnL1hGjWQudwuvMG/lGUkMYXQBkDTMS4BmYPotMPDukKqLM2n8Tfwa6Eo5yOhVLO+xnHWxq12FGhAJMPwdSeixzGE9ZqmK6SHw0B9pbb120fvVvOQoe0QPGkihmKuUKSGby51z9MjCYnriX8kHXRcBkc1hDUe11uvwGhUTQi+U8/Ew8eDNuYTN6SjGq7iVnpkgGMqOy11r005DMtRnvVWwCjyIewwIhDFoRpEhOuWz8P+1E48egJgMeAY0VTDzZLslx2w== Received: from DM6PR03CA0065.namprd03.prod.outlook.com (2603:10b6:5:100::42) by CH2PR12MB4261.namprd12.prod.outlook.com (2603:10b6:610:a9::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7292.14; Sun, 11 Feb 2024 17:47:42 +0000 Received: from DS3PEPF000099D6.namprd04.prod.outlook.com (2603:10b6:5:100:cafe::2a) by DM6PR03CA0065.outlook.office365.com (2603:10b6:5:100::42) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7270.37 via Frontend Transport; Sun, 11 Feb 2024 17:47:42 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.118.233) 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.118.233 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.118.233; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.118.233) by DS3PEPF000099D6.mail.protection.outlook.com (10.167.17.7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7249.19 via Frontend Transport; Sun, 11 Feb 2024 17:47:42 +0000 Received: from drhqmail201.nvidia.com (10.126.190.180) by mail.nvidia.com (10.127.129.6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.41; Sun, 11 Feb 2024 09:47:41 -0800 Received: from drhqmail203.nvidia.com (10.126.190.182) by drhqmail201.nvidia.com (10.126.190.180) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1258.12; Sun, 11 Feb 2024 09:47:40 -0800 Received: from sgarnayak-dt.nvidia.com (10.127.8.9) by mail.nvidia.com (10.126.190.182) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1258.12 via Frontend Transport; Sun, 11 Feb 2024 09:47:29 -0800 From: To: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , CC: , , , , , , , , , , , , , , Subject: [PATCH v7 2/4] mm: introduce new flag to indicate wc safe Date: Sun, 11 Feb 2024 23:17:03 +0530 Message-ID: <20240211174705.31992-3-ankita@nvidia.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240211174705.31992-1-ankita@nvidia.com> References: <20240211174705.31992-1-ankita@nvidia.com> MIME-Version: 1.0 X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS3PEPF000099D6:EE_|CH2PR12MB4261:EE_ X-MS-Office365-Filtering-Correlation-Id: 2b659551-c621-4322-9836-08dc2b298c4f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: awzC5TE0LSxMn4qr+GzBDMDcxV52pxIfhT9/r7CzH40NJzFNp3Xf+m3uM+NuV71HKTlT5++9Aqbb8oLB/0xoYvRSFaAD4ZQ1NIrynDE7/HlMkUD0PKdhNAyuolPDFaLtCWurwQe91+BcxK2ldQkQZEVsygvqQ7DL5ArrNbfSVOEV/DQx/ollSsmICx4gIYFP8V3BXFN82xBWkeW9aj2fbNz7M7O17y3lGCl4P81LlgT9z49LNcMWv6h2TWs6xNb8L1GPsXfcX2NsgB0kD7pUCSLQSOF8f0nik0lsEiQhhVbd6InvymtBdtknAzHfD4Bw2RqZRo7xt3bKhQr7bieGnJDC2B30weZoCSZ6PQ7/ay9+HY8SGajbqgfkYUcVZfayjMgmV9E3768WsNevG/URFDqTOqsz6jDFk8mxmTLbAggtiwp50bxnkUSHB47tu4GAyKS1+lI4XGYId08K6YwpOWswK7hRbbRE1dklUkOpe4ZXlcPt9mVgKIscFJcdKMb3SKd8iqDtrMZdbEnk7bEG5D7qhmlCLWdC1GM95OQgT3dZcVXyHn8DFnz6aaiM69DoLrXwpDeHEunZC2tZ0t0+vZj/F0EbeQMJ7u8eeQfNmxB8TZl+UjtdzlTlRXtE+V60PdRtO+URoslOsLJjiLwDeA== X-Forefront-Antispam-Report: CIP:216.228.118.233;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc7edge2.nvidia.com;CAT:NONE;SFS:(13230031)(4636009)(346002)(136003)(396003)(376002)(39860400002)(230922051799003)(186009)(82310400011)(451199024)(1800799012)(64100799003)(40470700004)(36840700001)(46966006)(316002)(2876002)(2906002)(5660300002)(82740400003)(7406005)(7416002)(8936002)(921011)(356005)(1076003)(83380400001)(7636003)(36756003)(110136005)(6666004)(70586007)(4326008)(70206006)(54906003)(41300700001)(8676002)(478600001)(26005)(426003)(2616005)(336012)(86362001)(7696005);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Feb 2024 17:47:42.6197 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 2b659551-c621-4322-9836-08dc2b298c4f X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.118.233];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: DS3PEPF000099D6.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH2PR12MB4261 X-Rspamd-Queue-Id: 3DE071C0004 X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: chw33dty1odyrhwxg9w6b5f65bxg8p3i X-HE-Tag: 1707673666-571695 X-HE-Meta: U2FsdGVkX19OOKO5e7IPQpwkj5MIYxwpCQlWqsWMy3+4h066YtwZRbTXIKv8BHg8Kc0Upu2m+7hhRsLCZtbzNhdCToCZ+hsZRfp3M8hR/7IBl6Ah5rqOd4ypV0iUa9nO/GpqBIN7s4im7roCK/rdHd/vAElevq00DqdL+WwD+06F2+b9a1AvoNO/20ASjLJJs1SHIGmXPI2ai1OnCRxwgb0gxl3A0SN4F5fLLnJe4TRpZEpWHjfq6KtUt04Ci17TKLIbELQuKhBDtcpg5Pr6nHUzx21tJuAtEgP/RlK87ppMPeIgza+0OhLeJT4Prjsok7FHGZLBafNxR9I876cb/4DKM+Kma3dC+KvPIZFzDikTEx3ep9qH2bhvkGUpApTYE+aOW/OkQ+kDwtNcBdYvf79JxC8N3zsYrlHU92lHHeAtbHoUgjPND0kGgKKmhoYwiCn+BpFpJPmS9PKEMoPjKq3bdzNSoYYPGafQ9S4Gog+u0nKBhPvlKan9qExp23qr8DyQC/2rAMrBsb3VaNxDyDgAsoEQKSCKNp4UPAnCOzxhu7IfjjeivaM7uw+0Ze+AKa8p541ortZdlCA3JGSDO7Gj41fkfU+c/6tihLMubfwF0TMjV5N2Oy0VCgWSjdbG9nKX+AiioqHIHk2rKnhionst5p6fszXiOxLSeqztTTOOzObROrw8Tm447uK9uAOHu24V4j4liLQsJbViMZNSBSiAQXkXuEIW+1H+Tv1UmCo3tGPR3oSNYdPwKuAH5cBmgNnauAoNJbwLNq6dPy1ynb9tsGKmJcv5Xo8NUUTcvVx91CcdRf2XRTivCuq7WPsqkcwwkrsnJnO6DnCvTdHQgCH64tbBl33ZcMDjS+UNNwxnP1aSPKYrMLWqRNdsBb15Q2BjJga/zPh8adAxjIAYJTQawuVra9zsQLpwTntyx13qMG7Rd4kQJG3giSGqSZuHDsgKoVBswIzxouULzHy 1RGTX5Vn n0JD96+1zrKCwilQwXzgShogmDpnyxqB+2C/PJNFQNAQ6oLfhPHJnUVPNNZ4Ei5/TQ6s4MTABIanWobpVcXqUjR+xYa4FGY9T7pBuWLokWo79mtP1nvOimd4zByE1rCnZHpMwTwFJyKn/fxQeGOdFvCfowMcgnqkh6rJRedgeg5Fwnd7DD6nUdk5RvCivCEzr/EozHCo1kxF3sYytMC5mIqrPsPSaP/nipTD8IRRSERjclrwdNprbpI6Z1S/Ra2pcPlc89plJRes6tUx+xs3MOqsL8A== 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 Generalizing S2 setting from DEVICE_nGnRE to NormalNc for non PCI devices may be problematic. E.g. GICv2 vCPU interface, which is effectively a shared peripheral, can allow a guest to affect another guest's interrupt distribution. The issue may be solved by limiting the relaxation to mappings that have a user VMA. Still there is insufficient information and uncertainity in the behavior of non PCI drivers. Add a new flag VM_ALLOW_ANY_UNCACHED to indicate KVM that the device is WC capable and these S2 changes can be extended to it. KVM can use this flag to activate the code. Suggested-by: Catalin Marinas Reviewed-by: Jason Gunthorpe Signed-off-by: Ankit Agrawal Acked-by: David Hildenbrand --- 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) From patchwork Sun Feb 11 17:47:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ankit Agrawal X-Patchwork-Id: 13552535 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 78827C4829B for ; Sun, 11 Feb 2024 17:48:01 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D3FFC6B007D; Sun, 11 Feb 2024 12:48:00 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id CC8DB6B007E; Sun, 11 Feb 2024 12:48:00 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B1D276B0080; Sun, 11 Feb 2024 12:48:00 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 9F0C96B007D for ; Sun, 11 Feb 2024 12:48:00 -0500 (EST) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 4647B1608A1 for ; Sun, 11 Feb 2024 17:48:00 +0000 (UTC) X-FDA: 81780256320.12.DEF7DE8 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2070.outbound.protection.outlook.com [40.107.237.70]) by imf23.hostedemail.com (Postfix) with ESMTP id 69683140002 for ; Sun, 11 Feb 2024 17:47:57 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=Nvidia.com header.s=selector2 header.b=EtCuoswo; dmarc=pass (policy=reject) header.from=nvidia.com; arc=pass ("microsoft.com:s=arcselector9901:i=1"); spf=pass (imf23.hostedemail.com: domain of ankita@nvidia.com designates 40.107.237.70 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=1707673677; 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=GEUPBUp/mRSrwoBY6hHPxBFvFm1Cd4dE+qw16gP2bsw=; b=bCwZqsMFTZL+AZwawVoR1yFDeFofTHbMoGXVrkpuOkoEsBM/YL4TV5JgQzDNQjJc0psm5K RNKL2tXApp2jtzTb+rPNYruQC5S1rvgR+PuUweQ/yO/mN4c0PPa8qHs+WGwdrcgyrmBrR5 HfZ1nssn/9prSdgBv8xOzv1Me8T/Aqg= ARC-Authentication-Results: i=2; imf23.hostedemail.com; dkim=pass header.d=Nvidia.com header.s=selector2 header.b=EtCuoswo; dmarc=pass (policy=reject) header.from=nvidia.com; arc=pass ("microsoft.com:s=arcselector9901:i=1"); spf=pass (imf23.hostedemail.com: domain of ankita@nvidia.com designates 40.107.237.70 as permitted sender) smtp.mailfrom=ankita@nvidia.com ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1707673677; a=rsa-sha256; cv=pass; b=dzGWHnSYV4LqSgD3XajGGVK9OaTbfy5bi9m7IOOMquzJMosYGIS4z1yx/qAWO+xXFtQVhk Z43gwGSOTJGfMJCeq6/XRIlQJnvQaip+JMJhfXCuv8T6xWs09jl91T/Y/VGrN1VMnPb7Ct m5T9MFsKvicc5cQ3XKms+EmrvnmFdAI= ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=nEzsiuYFjSP8N4G5X5fjz1Ur1/N3qfKNECA9J6NbAjHkvXT866wLPKgq2H8q78RRTPgX6YpoEbQ2Smdt3x8AutDP0rkzJ9HdCehhSxozXhxdF9cAtWdk0eBdp6zzFaGrfI5pP8QiyYWmve6llN4raPYPFNMB+kf2hm4LzyBFGIC0+FQ4V4Ixw3kc1oi816xn1FN0bYw2gbYK3GmIH2OzXnQSAKBSpKob/en3wADXGrKxRDzydshvN1JSN8nU6r8xUMPTumzQ1bjo+aqfV+74367fOOwinLIytojx7Z2AqK9/EgJitvjN1HQ5OkUUonr7zPC5OSXM7GxxYet3rEeMhg== 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=GEUPBUp/mRSrwoBY6hHPxBFvFm1Cd4dE+qw16gP2bsw=; b=eiqQKPjOsGjX/jhWgG+ETYhHlcmVZdb2UEWHxnKF/UIHhrE3DwV95hYtUyI5qA0Gg4QlqxSMkaR49PYlS3S94obsy0OkvZh5dj60U0Z45FzDdfuNmDQCbtBMhIaJWecCdevVYn1lHQhQLyTEJC3nWKTX/6tFOaa1DtoIoz1vbDaeEtXdFaqnw1cZNuSHs9m6YNK100jsIjpRPrzRRtz2awdmhqTXMpphgoL2gcA2WM7lMrJHtG9NXauE4JKj5pOqgN4qjS8JOy9upckSBzJabbE72jyOjwHK19fvNLsTJUM1KbDIsh6Im3+BIcZLDZC8J9jXrFMifgn1XbUQTgEyJw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.118.233) 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=GEUPBUp/mRSrwoBY6hHPxBFvFm1Cd4dE+qw16gP2bsw=; b=EtCuoswotMWpcrle1XP1yr9Eku3RnAE5vjr5yOJiRtAATzvKfW5tJ7FTL2sCnsys6TxFrMmATmyEbs8T6ai7UauzENkDL6T2kE7jhaMY4uokHu/KS8/+kXq4LuU5WifJxa3hkqrKlnNDtkkOd4F3hX/46rXJp/8luql+6/t8vLxvn48kHE/vxBDBPaN+iH2JnOZObgfZSuM3gv1t+bzfAWWS4rUuaTVplWQWa3xTtgeyygtuabbmoNAZRop9h8Vfmue1+4RY91XcS1+ZpH0cW7C7eUT+CxP3DdNFlytLzJwI7Hql68XsWubSjHMGMI+5jk0U4wGu5xPGSCprPiYv5A== Received: from DM6PR03CA0054.namprd03.prod.outlook.com (2603:10b6:5:100::31) by SN7PR12MB7225.namprd12.prod.outlook.com (2603:10b6:806:2a8::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7270.14; Sun, 11 Feb 2024 17:47:53 +0000 Received: from DS3PEPF000099D6.namprd04.prod.outlook.com (2603:10b6:5:100:cafe::81) by DM6PR03CA0054.outlook.office365.com (2603:10b6:5:100::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7270.35 via Frontend Transport; Sun, 11 Feb 2024 17:47:53 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.118.233) 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.118.233 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.118.233; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.118.233) by DS3PEPF000099D6.mail.protection.outlook.com (10.167.17.7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7249.19 via Frontend Transport; Sun, 11 Feb 2024 17:47:53 +0000 Received: from drhqmail203.nvidia.com (10.126.190.182) by mail.nvidia.com (10.127.129.6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.41; Sun, 11 Feb 2024 09:47:53 -0800 Received: from drhqmail203.nvidia.com (10.126.190.182) by drhqmail203.nvidia.com (10.126.190.182) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1258.12; Sun, 11 Feb 2024 09:47:52 -0800 Received: from sgarnayak-dt.nvidia.com (10.127.8.9) by mail.nvidia.com (10.126.190.182) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1258.12 via Frontend Transport; Sun, 11 Feb 2024 09:47:41 -0800 From: To: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , CC: , , , , , , , , , , , , , , Subject: [PATCH v7 3/4] kvm: arm64: set io memory s2 pte as normalnc for vfio pci device Date: Sun, 11 Feb 2024 23:17:04 +0530 Message-ID: <20240211174705.31992-4-ankita@nvidia.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240211174705.31992-1-ankita@nvidia.com> References: <20240211174705.31992-1-ankita@nvidia.com> MIME-Version: 1.0 X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS3PEPF000099D6:EE_|SN7PR12MB7225:EE_ X-MS-Office365-Filtering-Correlation-Id: 9328e4e7-c2b8-4281-f93b-08dc2b2992e9 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: AhSeR5BaxNzG0QKrNhr7kPTxSNWm9QP170YFV72q5ODiA4Y1hSL7BppZPD7U14QobLia8LrifmyWzg4OzDLz5p2XhefJqXX5rhz7HZq3TUh+h32imnfEgh3agJAPc8qcXl/UfRms7q/jR8EYl6cBjCdjxk3wfKDi7/cdU3ocw0To/6hlZXYs7mK8fMmqzv/kcJso1BGTxaF/DEoDv+MwxxGSsCbYyxkxsD3w8Alz/OLrcxwhuF0bVAlVmI0iQpQ+lUx58AMJ7JBlA5dk2V4Sr0Lo3LePXECONE0nj9/ZAhEu9XBsrRGcupE60UKh8g1g/i5FkmkypVW/J90tvUhvvZccZjewmCbgwRbKnjebqy3U3fwQLmWO+R6z0pKeHw/hVNptqHbuMEA6K8s9FviUZ5Kt9i7JdJlKAHsICvkXXcNwrbn0gcrQ+LRHOEkWp+2MpjNXVwAzg33sk4nD2pxL6UNSVOO1z2xKsBvoMRV8VmwDbB44uZAse1Red/dRlAKi7pKsNBJuO1IteA+9AsXunLMOOLcP8A9OdDpqv6cTtL8k7BR+jELYQur/x+LMqsureYsk2yGkM9HgjItcuPpJJJas02+YpHdMxzVqstdTDZ4R3b+paz2MqfNSdiqZEmoPw5btCR0Px5o6avPd6wAG+w== X-Forefront-Antispam-Report: CIP:216.228.118.233;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc7edge2.nvidia.com;CAT:NONE;SFS:(13230031)(4636009)(376002)(396003)(136003)(39860400002)(346002)(230922051799003)(451199024)(82310400011)(186009)(64100799003)(1800799012)(40470700004)(36840700001)(46966006)(36756003)(921011)(478600001)(5660300002)(7636003)(7416002)(41300700001)(70206006)(8676002)(7696005)(1076003)(426003)(26005)(54906003)(2616005)(83380400001)(356005)(2876002)(336012)(2906002)(4326008)(110136005)(6666004)(86362001)(7406005)(70586007)(316002)(8936002)(82740400003);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Feb 2024 17:47:53.7134 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 9328e4e7-c2b8-4281-f93b-08dc2b2992e9 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.118.233];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: DS3PEPF000099D6.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN7PR12MB7225 X-Rspam-User: X-Stat-Signature: 6br1an7zh1m5gtmf6wu5mxcwmycsxaa8 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 69683140002 X-HE-Tag: 1707673677-700155 X-HE-Meta: U2FsdGVkX1/SKYoC65sYuaJY+ejwB6W7pZDsHanesdKAQvg40eX+Uzb/jixp+8jfkUYW0OTbRt5ykCJ1UIEWRK2vDTacpLPTB61pJbBoCd4zvhQAVADINzU/j4cZnskgZrCu6rlkG6JSYrKWYzFt09R7C56xLphwTBegihsnE6iPY4pQflPepL+Rt22GCvf0lkdHqBFMyZgMp3eau8o384EROGo+Y88KHUH/+DkU5UHHBOniFN2f8dwzxrifWydHSghYUDP4gXgLUOnEr2yGZsnJEEpF1/+iSd4hOGXlIhPhwfpmFpVlbOIlwq8fEQ+YRgwbo91JBFx26lT1F+r/0+bYIbie1h/lXNVslhaawVta3xYVNEPRQgR2TxNWXQGl5qUnW6C0EZZ7jwWr1BQ5Li5gp92au2J6z9elnzI05R9Tbob5CFNSwSPru+L1NMiTPMvtp7H2xz8qIJFm4TYLfbCM7zYY46/wCFz+oZM4udx64usyf7BSsQq1DeWRsDg8ySw8enaHgeV8wijQWREO51gDsWSSw6IQ2BeMgvHoHGffe5W2c4Zd6Q83vdlielJJi8G1b95Yzwcfz/9yrhK2djImUBwNqhCTiKO61BpUYwI8twS6isBLUbf5PuBzIICjAJpvVVw4CvX+cwZOxtNkWeFu0N2STdwVcBacbXtjqcB6tRtIFmKoPQ8QVncr/RQvsGDz7pBoL4wPlCf37YtJv8Po3VeG/0Yk+gx65+NUXGMkkripWxps9NFE3pfU1ayUAfGOWqtxzHfZE3Qb6zS3yjy+ChBZ3Q9WIfVmSezasFxDsEMkELJhkAvWhonMllKkMo1VaKhETW00DanyEcfrn223Ij3NsOKlZYRBC/WnmUcVz06Ptq53A9CMmwgybey1Bj3LUWQuJDmsbEMz1azF31B5KGhBWZJ6/DJ8RERML2YMBjy9eJ9lwCZQlRmJaR/uGMAATtLqDtKCmeVpGE+ gCV0j0En j4GjCOSnyT+9J9rrs9/lJIKPBenyOWsTgoa2SZtIimQbZD2hdAlSlTGjcFPXIQkCPihXpJ6972WAelIJKfNlSvWTsV2pFCm42tavG5P7L6Q4G6lGk0R02Rr4QfL1pUXBDuGo9eAKV4hf38TrWHPMs1ka/TAf5wrkVkFpPB0nyJ/ncx5O6cWd+WZRJZOTpOxLqb6LB/jCYRcQ80UQewQ/DYH2ddPm7eKwegfMF5htBCjLp0uFWUysKbSRpIUntMymwOCjMbiKYtegYuL2pg0l0okqLjg== 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 To provide VM with the ability to get device IO memory with NormalNC property, map device MMIO in KVM for ARM64 at stage2 as NormalNC. Having NormalNC S2 default puts guests in control (based on [1], "Combining stage 1 and stage 2 memory type attributes") of device MMIO regions memory mappings. The rules are summarized below: ([(S1) - stage1], [(S2) - stage 2]) S1 | S2 | Result NORMAL-WB | NORMAL-NC | NORMAL-NC NORMAL-WT | NORMAL-NC | NORMAL-NC NORMAL-NC | NORMAL-NC | NORMAL-NC DEVICE | NORMAL-NC | DEVICE Still this cannot be generalized to non PCI devices such as GICv2. There is insufficient information and uncertainity in the behavior of non PCI driver. A driver must indicate support using the new flag VM_ALLOW_ANY_UNCACHED. Adapt KVM to make use of the flag VM_ALLOW_ANY_UNCACHED as indicator to activate the S2 setting to NormalNc. [1] section D8.5.5 of DDI0487J_a_a-profile_architecture_reference_manual.pdf Suggested-by: Catalin Marinas Acked-by: Jason Gunthorpe Reviewed-by: Catalin Marinas Signed-off-by: Ankit Agrawal --- arch/arm64/kvm/mmu.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c index d14504821b79..1742fdccb432 100644 --- a/arch/arm64/kvm/mmu.c +++ b/arch/arm64/kvm/mmu.c @@ -1381,7 +1381,7 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa, int ret = 0; bool write_fault, writable, force_pte = false; bool exec_fault, mte_allowed; - bool device = false; + bool device = false, vfio_allow_any_uc = false; unsigned long mmu_seq; struct kvm *kvm = vcpu->kvm; struct kvm_mmu_memory_cache *memcache = &vcpu->arch.mmu_page_cache; @@ -1472,6 +1472,8 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa, gfn = fault_ipa >> PAGE_SHIFT; mte_allowed = kvm_vma_mte_allowed(vma); + vfio_allow_any_uc = vma->vm_flags & VM_ALLOW_ANY_UNCACHED; + /* Don't use the VMA after the unlock -- it may have vanished */ vma = NULL; @@ -1557,10 +1559,14 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa, if (exec_fault) prot |= KVM_PGTABLE_PROT_X; - if (device) - prot |= KVM_PGTABLE_PROT_DEVICE; - else if (cpus_have_final_cap(ARM64_HAS_CACHE_DIC)) + if (device) { + if (vfio_allow_any_uc) + prot |= KVM_PGTABLE_PROT_NORMAL_NC; + else + prot |= KVM_PGTABLE_PROT_DEVICE; + } else if (cpus_have_final_cap(ARM64_HAS_CACHE_DIC)) { prot |= KVM_PGTABLE_PROT_X; + } /* * Under the premise of getting a FSC_PERM fault, we just need to relax From patchwork Sun Feb 11 17:47:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ankit Agrawal X-Patchwork-Id: 13552536 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 89F70C4829A for ; Sun, 11 Feb 2024 17:48:15 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 245106B0080; Sun, 11 Feb 2024 12:48:15 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 1CDBA6B0081; Sun, 11 Feb 2024 12:48:15 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 046866B0082; Sun, 11 Feb 2024 12:48:14 -0500 (EST) 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 E42FF6B0080 for ; Sun, 11 Feb 2024 12:48:14 -0500 (EST) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 7899B120511 for ; Sun, 11 Feb 2024 17:48:14 +0000 (UTC) X-FDA: 81780256908.18.BDFE667 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2058.outbound.protection.outlook.com [40.107.93.58]) by imf11.hostedemail.com (Postfix) with ESMTP id 604094000F for ; Sun, 11 Feb 2024 17:48:11 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=Nvidia.com header.s=selector2 header.b=CQbruZeQ; spf=pass (imf11.hostedemail.com: domain of ankita@nvidia.com designates 40.107.93.58 as permitted sender) smtp.mailfrom=ankita@nvidia.com; dmarc=pass (policy=reject) header.from=nvidia.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=1707673691; 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=wh4MZCC2T9D1grz8V/GzArHYhJ98qxcO/FoJgoYQOSY=; b=v8ccmgZq0yT5KUfRwV1bOKjEQjfubwcVNmpy0dbPBAO8liGZFoJmoYFADB0a7wjlC3R4r5 CsWKOHZnTQzymHXhOWd4qDJYM3cf6jZrdEU8VvPzOrL99wZWtab2/rQAtzseylQx4EyQgW 0hXrxvYpyGOR6DCmSGvIjaa6edADQew= ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1707673691; a=rsa-sha256; cv=pass; b=1xrjwDoU7wRa1bxWSb/xDos5Lbn3pLcFkuY3Yy31kbyM3d7RdD2Y34kvOlszpBAR2IpPTG 4uX8HdQt4MF2jLhQP12osq/L0e9wIrSOqYH6i5sHDELoSJZ4bvTviQxIGss8ohpZrz/sy8 J94MIiq8tMLoljcFCCyC9qC67CXcBSw= ARC-Authentication-Results: i=2; imf11.hostedemail.com; dkim=pass header.d=Nvidia.com header.s=selector2 header.b=CQbruZeQ; spf=pass (imf11.hostedemail.com: domain of ankita@nvidia.com designates 40.107.93.58 as permitted sender) smtp.mailfrom=ankita@nvidia.com; dmarc=pass (policy=reject) header.from=nvidia.com; arc=pass ("microsoft.com:s=arcselector9901:i=1") ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=EYRphY9UwgFTedg7L2G7QVasqDihPQvqPRVUskY1s5nWREut41+RGOdHb+PvriW5wwp0g4Me5S4FjBuNxpZGA43ZzkZynazkSQ83Lcl6i9uu5UtB0/VPXuRjTaS9+T2zqfqL45B5fW4y/PwlN2rIqeLMSwJ4sVRfdtjAsHqh7gNkHPfOsEUTkDWwteuZZ3ylk1kcO8hHN6hA1sFh97NtG9w3/CsiJgbEMEE7MV+SfS1bGynDJW4HgLvTSBQzd7dFHI4R5kvb+hsRXu/3bPjO6pu9eeqlaYJQIsXRofJe7os81BhpP37d7zLWYHKDjehedNYk9DBv7qzfgLIAxoLJeg== 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=wh4MZCC2T9D1grz8V/GzArHYhJ98qxcO/FoJgoYQOSY=; b=WBlq66OfMJRlCFiTMnw6Y1yXwNvVHsZCnb/HplOeZn60X6uKdppg5Nb8dXjhTSZL7s5WOWpbRKImzJEI1x9gLEYZAmABWDDfB5L/03aUvrpokBLTkOywU7xh8lqYnZYWuDIbM0sScEKjluBr35NcoRE+7LWDXNUV4jbSafRZIxn02hS9uunT8KEniqGuTDJg9xi1yGYgvYj2BduTZfLecSCNJJZ+sJW+FQxQF8jqymgCQ12kLL+igilNil3VU8hQQTnCqcGUr0l+BifaTFf0uUNzZNxF1DtouiVcdvgzjHt58XIfH+7M7Ymvl8NLQw4dJKSoRhtKaQXt5boS6KhkiQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.118.233) 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=wh4MZCC2T9D1grz8V/GzArHYhJ98qxcO/FoJgoYQOSY=; b=CQbruZeQXqtaHiq2B62VBbuJgjMLgk2Uy56v3ziIDkkIdqUMRtzV9+rJCFwUlE1zpMX3+c5lpBim39cMS0BLIAqAR1IzOw2oZh2Qvvxd/QQqp8UScwDQhnjT0KfOghV6YHa4qdQvsKuGXv9PYnw2ts7cXw01L79GE8dD7BY9Tt9PJJM3GMGYKVtIVvtDvAC/mcLWzkTl5NxVXUsLkeKZvkjAqXMGgonQFvldEnicnQ6DSnyowJQ5G+k20B3tiyYOZMnZJPGJfc+IRutFitJl7KKqIgZoOIAp/bUHcglqMC9Gee1aUa1OLjp07LWev6LWQu+Vln9T2A3ZeQUsXXahUA== Received: from DS7PR03CA0056.namprd03.prod.outlook.com (2603:10b6:5:3b5::31) by MW6PR12MB7087.namprd12.prod.outlook.com (2603:10b6:303:238::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7292.23; Sun, 11 Feb 2024 17:48:08 +0000 Received: from DS3PEPF000099D3.namprd04.prod.outlook.com (2603:10b6:5:3b5:cafe::d9) by DS7PR03CA0056.outlook.office365.com (2603:10b6:5:3b5::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7270.35 via Frontend Transport; Sun, 11 Feb 2024 17:48:08 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.118.233) 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.118.233 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.118.233; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.118.233) by DS3PEPF000099D3.mail.protection.outlook.com (10.167.17.4) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7249.19 via Frontend Transport; Sun, 11 Feb 2024 17:48:08 +0000 Received: from drhqmail203.nvidia.com (10.126.190.182) by mail.nvidia.com (10.127.129.6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.41; Sun, 11 Feb 2024 09:48:04 -0800 Received: from drhqmail203.nvidia.com (10.126.190.182) by drhqmail203.nvidia.com (10.126.190.182) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1258.12; Sun, 11 Feb 2024 09:48:03 -0800 Received: from sgarnayak-dt.nvidia.com (10.127.8.9) by mail.nvidia.com (10.126.190.182) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1258.12 via Frontend Transport; Sun, 11 Feb 2024 09:47:53 -0800 From: To: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , CC: , , , , , , , , , , , , , , Subject: [PATCH v7 4/4] vfio: convey kvm that the vfio-pci device is wc safe Date: Sun, 11 Feb 2024 23:17:05 +0530 Message-ID: <20240211174705.31992-5-ankita@nvidia.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240211174705.31992-1-ankita@nvidia.com> References: <20240211174705.31992-1-ankita@nvidia.com> MIME-Version: 1.0 X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS3PEPF000099D3:EE_|MW6PR12MB7087:EE_ X-MS-Office365-Filtering-Correlation-Id: 2d7fcd35-0deb-4edd-9f6a-08dc2b299b7f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 6sTQt6Nmm7FkBbUtT2MaOXv9VsAcZ/rB9MlRAC2Ld+MijCgoE6SP6t7XLtTIdSYsSkKWO2TFCzzOlITjfkO4L/IOnXrILncFq5BVDvYq3CVZQ/ptiKVZHvv9b1j6GBnJivwPGmA8RbkY+QTGYIznCpf9J+pOXNpyteiVWNOkHZ7UGZBSj+Hspg+vEJ3GLStd9zk4j8Mir8C0CMfZqxvcVjzBAyvUiL5EC83N3MrJN745Wh3LQaoN2IBirde92a3SVmFfF+iJVJ16j3RKwZUBMEoQ3ULitjpQ01WgBOpJmm9fewPZYz6iMO5/GlKBo8wpPO0qvvWvQV/YgxELRcejlCn7JJfyPiX4jzSrFIkV47p65hGeL+XubX0akTMMofs/ifsjUOVhpC7OAIQedG3x4VhK6QohFT1/4UbTScf9QmzIhKnT2c6Lvrz2cTu5/IPiIKLggRTkc7IgmkICg1RuvkTerKajNkJur1RYxIK40rZtbWf7iVXep3fpPfyHojJ5n9xxihavTyu10IIlPZWenXIUegziQfJ2D+yn4sX1hgOqCB2tsLUoccc4RrygijRZ7dTWHwBQ5rdpSiJ9k0gGSj4/sY6yb3n4oZsQJuSFIt1cO3mQ15ZIuPPcNeeo2tWJUhEP2xJqD2dSBXs08Z6tRA== X-Forefront-Antispam-Report: CIP:216.228.118.233;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc7edge2.nvidia.com;CAT:NONE;SFS:(13230031)(4636009)(376002)(346002)(136003)(396003)(39860400002)(230922051799003)(64100799003)(451199024)(82310400011)(186009)(1800799012)(40470700004)(36840700001)(46966006)(2906002)(2876002)(426003)(41300700001)(2616005)(336012)(1076003)(478600001)(26005)(7416002)(4326008)(7406005)(5660300002)(54906003)(8936002)(70586007)(8676002)(70206006)(83380400001)(36756003)(921011)(110136005)(86362001)(7696005)(6666004)(316002)(7636003)(356005)(82740400003);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Feb 2024 17:48:08.1003 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 2d7fcd35-0deb-4edd-9f6a-08dc2b299b7f X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.118.233];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: DS3PEPF000099D3.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW6PR12MB7087 X-Rspamd-Queue-Id: 604094000F X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: aayi1tumj66jzbew143kir6qaspzkeq4 X-HE-Tag: 1707673691-460063 X-HE-Meta: U2FsdGVkX19AzpMKBOFF3D0ZgQBxUVC28Fk5zAdh5BAXCfWqjKhzMnpDxAvMi7cHoo+0YNf7T4x4mRgRfYeSK/s9UbNamH80vYTY+MFG+NRR6UCdb9SFVK3PFzSrnaQd2f5BLI8q17rVz6oEOhdVHTpvG/fwQYgTNc5ELur2F2IXnuV5ap93px11CEaLz/4S1WItXOfViKQcxI0HLoeEVPOnHm7ljv4Kc+yRcuP7zQJ1Tj4aPW5hjYBTi4CMR3/vmfTjBA/qgcMtJYogIRHXezSuUoW27TkgfRr1cyJyilZREkFxtRrdQ0Neah2V8ztE+RvRvsSJ7PODXfib5UbUkOILNTDy3Ip11V4jCSbOoQat19K33sIPYU2V9AU2CPDDhTpkXCAu/4DprXbNdbDT8KJNM7xrobbeZWmGQgP2b73hYEooN9U1rWVfR8iHb/RLYri+dWQts3sPzuhr+zckY6t8wkkV1Tq/wZk12PC6185Swv1PtTc+Ussh0ODcXfgSwnuF2PSt96ATUnJdv686BHJd/+lFOest43X7Dqe8I98/kzi2HvZReSUYjho3vGDGMdxJn6MFjYhXdgZHoImkQQitqUY2guRxGlx3P/lJhCekHCgq5k2wXDjZpyoLCQSznWl3sqpXetcU3EeV9YYhHZ656/+AiIQRdKOxGo7fiVQcpU3NVO3G81K9bsMZAdc+yM4cUxEFoZ71UYbX8fGk1hq+VqUX0Xd16fVi/TBrv7QPuxtuqIy/D/lS1yQpF6L8HxgFECtXx54m2yzZdxEvKNKf/J9w/51mFSHDJ7X7zpuSEx/nyK0y04dcwqJgyGVb/qZ1YGWl9fkesxoYRaGTe5jV17TFwnhqG6+T87BSdEJbaGbHDDVpEhzJ8EzjJe0+xcEHn0Bi4gLrXdK1qDO5RXc/kCGEzJUFH4Aqtnojf5bt1kxa6BhlLmKorhYNAPh2S1ZwmnwOkFMVp/J13xg QydgGy7p mnb0cceUkZ2X6Cg8KymUwmKaYf+eccZ5czkmLzcqvhu3/C8Ao5YFQM52NTfpdgED77OYh0Mborah5+sUfFyoClPWm2BJ6UsLqpdni27ZUj/22zXxGQhRMnvvtHZicQ0awA9Jogh5ouPD4T9Fxzsd3DQ+dD784Fdy+ZfNldvKArgx5IHAbirocsQ2iRosdnrWPod+L1OLFIr08GUooFNL6RJCtNnV/9IzM2zqXAHgTpZDvETnW7NwhTAl/eyjEeT4OOlGUH0qu7GDEDabcTZQGDfL63g== 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 code to map the MMIO in S2 as NormalNC is enabled when conveyed that the device is WC safe using a new flag VM_ALLOW_ANY_UNCACHED. Make vfio-pci set the VM_ALLOW_ANY_UNCACHED flag. This could be extended to other devices in the future once that is deemed safe. Suggested-by: Catalin Marinas Acked-by: Jason Gunthorpe Acked-by: Catalin Marinas Signed-off-by: Ankit Agrawal Reviewed-by: David Hildenbrand --- drivers/vfio/pci/vfio_pci_core.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/drivers/vfio/pci/vfio_pci_core.c b/drivers/vfio/pci/vfio_pci_core.c index 1cbc990d42e0..eba2146202f9 100644 --- a/drivers/vfio/pci/vfio_pci_core.c +++ b/drivers/vfio/pci/vfio_pci_core.c @@ -1862,8 +1862,12 @@ int vfio_pci_core_mmap(struct vfio_device *core_vdev, struct vm_area_struct *vma /* * See remap_pfn_range(), called from vfio_pci_fault() but we can't * change vm_flags within the fault handler. Set them now. + * + * Set an additional flag VM_ALLOW_ANY_UNCACHED to convey kvm that + * the device is wc safe. */ - vm_flags_set(vma, VM_IO | VM_PFNMAP | VM_DONTEXPAND | VM_DONTDUMP); + vm_flags_set(vma, VM_ALLOW_ANY_UNCACHED | VM_IO | VM_PFNMAP | + VM_DONTEXPAND | VM_DONTDUMP); vma->vm_ops = &vfio_pci_mmap_ops; return 0;