From patchwork Wed Feb 7 20:46:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ankit Agrawal X-Patchwork-Id: 13549064 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 091AAC4828D for ; Wed, 7 Feb 2024 20:47:28 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6AD516B0088; Wed, 7 Feb 2024 15:47:28 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 635F46B0089; Wed, 7 Feb 2024 15:47:28 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4B0026B008A; Wed, 7 Feb 2024 15:47:28 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 347196B0088 for ; Wed, 7 Feb 2024 15:47:28 -0500 (EST) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id F3B7A140683 for ; Wed, 7 Feb 2024 20:47:27 +0000 (UTC) X-FDA: 81766193334.27.41F79E5 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2079.outbound.protection.outlook.com [40.107.223.79]) by imf07.hostedemail.com (Postfix) with ESMTP id 314BA40019 for ; Wed, 7 Feb 2024 20:47:23 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=Nvidia.com header.s=selector2 header.b=aRSqJxyS; dmarc=pass (policy=reject) header.from=nvidia.com; spf=pass (imf07.hostedemail.com: domain of ankita@nvidia.com designates 40.107.223.79 as permitted sender) smtp.mailfrom=ankita@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=1707338844; 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: references:dkim-signature; bh=aot13UJCsTPx4X4X08wsEuhasploJqO5xwf6HdKOBfk=; b=NZZqcvIpNHnH3O/17SimyiVou0IHZROqK+X1jLpeDuhyYb+TLeSXYB+R7yy7eqUTpHGhkW L8w4woHMFTVH9aG6BzHwntSGjg88ji+5cjGESAHlt1g4YfuNF1bCuWHhS+1MNEwJdjUUCo YQfpCAIjYB+TN9XQ6gdXWmXO/u39+4c= ARC-Authentication-Results: i=2; imf07.hostedemail.com; dkim=pass header.d=Nvidia.com header.s=selector2 header.b=aRSqJxyS; dmarc=pass (policy=reject) header.from=nvidia.com; spf=pass (imf07.hostedemail.com: domain of ankita@nvidia.com designates 40.107.223.79 as permitted sender) smtp.mailfrom=ankita@nvidia.com; arc=pass ("microsoft.com:s=arcselector9901:i=1") ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1707338844; a=rsa-sha256; cv=pass; b=qSU5LZtGYgiUGieMGO4B4GGh6F861CpJyh1dCmuXZh+s41af61ZpIOrIFsmEVPhVGpc4he rybdjLNvSo+G2/74iBNsWWeNnzTyBuX9KLRxEKVgr7Va9s+q96lY433xz0OeTb9792Yaen MvZ+J+/sXfQ7CL7BmVOnUJ4Z7kj6ChI= ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=fDcvrD8mF/rATSgyi3sKYZPV5FFq6+4BZlSWrslaaqLJ22FLFRX3mdx5XrTALGAujMlr/2ArIPTBUgO3qyR0Q8k/p4gku/ydl3Wb9VaJN/Mt3R083F6gAUzv8ApVXeQo5LmznzgF3hB+tvnS5ENpywKJaLMcqe5zgcQK7XazdBQC6Fo/QMwrec3hUmayeHtEQZMkIDKIh7XKiAVHU8t4M8VLcPTFdHpFIEnzFSTGvB2k0+s4oD3tlB7aY9YOUedv9zXACtS00hhrA6Dy+iZxi8sk7qo5/8E+TgMPjT98jOPWcl2o2Q1RgoV0YvzoKNVxXiiTUoPkYJBzxFNmsPaHxQ== 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=aot13UJCsTPx4X4X08wsEuhasploJqO5xwf6HdKOBfk=; b=NLRX/CsBLhv1OrEP9VV1JvWgaJHhg5BslC+CqPVDElwZi5iHpGkiq310GNqHTYONl5KS6mqlHbYSH629YZq3st/w/hufqjLMsmpMJMeWxOiPvrGkL+E6HtNTwa1WlunQw1yNAmy9kApVwjtEdvvTS1dIOtC5D+mQr3TESl4vcjCzEg8hRr4SYQYqqhL2G+25CWQm3JIZKDDW8Zp1q1DbsLHrLOFwqG+shN01Nq8TTyHTvvKRvZObopwQB97qhvsWo37SMcoypoLMR64sl6SzNRFYVMH6lVkGHiFLO2I5RskyP7coHhkRGxbR1P12hT+n9lv7jSz3Yiz/sX5ErZKUNw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.160) smtp.rcpttodomain=kvack.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=aot13UJCsTPx4X4X08wsEuhasploJqO5xwf6HdKOBfk=; b=aRSqJxySmxtGp8MK1jgy2fqhrH8WskastSH+2t1RkGHV5SETMM+vk3u4FmeAfOAoDQLegeobWTQ4M/zSb2+nftwkNHo37oJxkjEVwO4ifInmz0IRZE27oJUYAlh/7l3xvCB2EvCIMOU3GZBCU+B2Q1C0Tq1PQMEimH+6ikTYNzp6CGF4ejcUjFXmkMMnQD8uO4WVzT8ahs9K828ymtpHABlPYXR1smH6Nx4ykqcQGBWmgEFtzRTpII4kmLfaDy2N7Liu0vFiFhZQQt6CF/aAa9BOjQKWlR2AZZmt4+adyMMnAZXzkBljM3AHyBdR2mwVPkQkqYJNh81FhLAzX78O5g== Received: from BL0PR0102CA0019.prod.exchangelabs.com (2603:10b6:207:18::32) by SA1PR12MB8947.namprd12.prod.outlook.com (2603:10b6:806:386::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7270.14; Wed, 7 Feb 2024 20:47:21 +0000 Received: from BL02EPF0001A102.namprd05.prod.outlook.com (2603:10b6:207:18:cafe::c5) by BL0PR0102CA0019.outlook.office365.com (2603:10b6:207:18::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7249.38 via Frontend Transport; Wed, 7 Feb 2024 20:47:21 +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 BL02EPF0001A102.mail.protection.outlook.com (10.167.241.134) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7202.16 via Frontend Transport; Wed, 7 Feb 2024 20:47:20 +0000 Received: from rnnvmail204.nvidia.com (10.129.68.6) 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; Wed, 7 Feb 2024 12:47:05 -0800 Received: from rnnvmail202.nvidia.com (10.129.68.7) by rnnvmail204.nvidia.com (10.129.68.6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.41; Wed, 7 Feb 2024 12:47:04 -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; Wed, 7 Feb 2024 12:46:54 -0800 From: To: , , , , , , , , , , , , , , , , , , , , , , , , , , CC: , , , , , , , , , , , , , , Subject: [PATCH v6 0/4] kvm: arm64: allow the VM to select DEVICE_* and NORMAL_NC for IO memory Date: Thu, 8 Feb 2024 02:16:48 +0530 Message-ID: <20240207204652.22954-1-ankita@nvidia.com> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL02EPF0001A102:EE_|SA1PR12MB8947:EE_ X-MS-Office365-Filtering-Correlation-Id: 5f4ab940-2ce6-40bb-5e3d-08dc281dfb11 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: DOqwwwQ1me5hWBnAJ/rUxVUHjcbSuYTUDA7BhdXLbov5zy/WlK6rth6GppDEX7whLzY22majp3O43uDcz8ArWaOnhLiC4GxoN1WAvm7dTA2znYzGGwCI3SAAoD5fUfye0SY6IqsVMm0hctuQpqWTITR2TJnijwg5uz6pLtOZ2vhc2CkJ5TWVdfLdkP4KF1Zxq6fOwbngAyl6ZpItINxVtvWdmXwTpphX15lue7KDG6cqHjo1eGtZoSpKIVDlwTLAJ2/rqscYx1VBMW6QM51JelKXUG2YnyuWqptkXlqwuQfXuZP9ME4I8weIJ6d/9BDrUOVyLvi5Dc5YZQ11XpVYQfmgG3LMEU8hKa00YYjGdX+8RTJ2UyZ16n2E3OcOc3oOj+tM5u3DH/1Y2ykb5ACUmaLeTeA8pSj/ltj8gA1KwSmvUEZOBfe/MeT3XzKL2S3M42gPMGZIs7AyTGKWeg91H++KwxzRRLJwpzestPYcBXYbaMJYrdZcxfghJmy3ibaWoWdbRSURHbAXL7ftxhXztLx+CGJ89+0dKUTJvjJW2NdXjEhePNAWEJoYXOW2rh54lgDkH9cutRsWcTQ5e/1wo2QPZxFOFACwPOupzVHsGkcXdUUiakZQAbetIu62NsqI2TY/9kMMaFGIsduA1tka1BvYVvlavO/obFNQQZzBM/rKRL58bdzs+mNM6g+DgwKG 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)(4636009)(396003)(376002)(136003)(39860400002)(346002)(230922051799003)(230273577357003)(186009)(82310400011)(64100799003)(451199024)(1800799012)(46966006)(40470700004)(36840700001)(70206006)(7636003)(5660300002)(82740400003)(2876002)(54906003)(356005)(7416002)(110136005)(41300700001)(2906002)(8676002)(8936002)(4326008)(336012)(426003)(26005)(70586007)(1076003)(316002)(83380400001)(2616005)(36756003)(966005)(86362001)(7696005)(478600001)(921011)(6666004);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Feb 2024 20:47:20.9274 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 5f4ab940-2ce6-40bb-5e3d-08dc281dfb11 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: BL02EPF0001A102.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA1PR12MB8947 X-Rspamd-Queue-Id: 314BA40019 X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: r7w7i7naf1h3j8814t6ibso4x56jqf43 X-HE-Tag: 1707338843-41525 X-HE-Meta: U2FsdGVkX18hhUuftMVKbLP6er9WZHwwRJ8SvcK50DvPOEjtedIX+irrm/+Mf/5Ww4Yndbcavw72anCrKEjKM2vv2AcBx1cZ2rTwx/z7gOD748V7H/AWJDt7OzlHNLytyizlRmsfMpPemFJjoBdOM63d0KmSYxFMsu+3By080pcPCniRsJ4588AGufUvVAHPxJ7uS4RHGwHdFsNNfh59Z2jdvI2JNt2We7o4rn+yZcz7rEzW1Yb3Kly/D8Ghw65S5vhfl9Z6NRsaqd8wTNgu86AXiv51X7qnANUskWCTwXmMYfgrhJsfFFZyjnbpyMyCPpQiqoS5t31wO10n4O2n7+PZnQp13yBZidS9RipcLTKcmQtv6Fv1BxQrqMknQwyqYxeeSIWh41cuSkt0rysi130pWzDA5Ero64ugUyjFoMmZyrcPaY6OYueKi2G+45rDoAd9VD1MQaoFHWNEkCMYSy+DPlsEgjLvUan5gtLueCLOajpaM5elxpr0C5xRAXRW+BBr1t8klZ5FVsilRmRDc100qgPOPmd1tNJTXBssT1jV6PKvKzmge659NweM+uWZ2wCwBsjfvQvm0K4x6a6qAK0D6j6VCit85lM+6+NfAtFMUWuA0KIeGW6toOxECfOTa28cDiLsWLTGl/4t2bKlB3odBldtu9u5nUNHJETu1at5QMbLffpnI/aCIPzvyknjtcZzV53fdpacKErARu82tyejsqCtuGWyam9gGGSYs61zEf57eP5OfYT3jG9+bntEsAxSirI1nlKaBRlfiBtFjojmRRW3sgk0v0/4fbM7J2tYwM8ge8eyDeMKysV2Z55Cb5AV5vLIAUnQ2TFpVkREC2oIySU3TWHaFGe78YdTw+Q+G4ceU5iCOkva9I9ABXmqU69ruViXKk8EOtzyPap6unyRW9aLUjgd1qgAY3RJsCzDJO6DbfQAlSLqs/yk1y1VfptIXtPye3tdPfOWuGi KcRjO5bX yADN9THbc2qZRECOwWtCAoztXQE90kH5tWT08BQ+Y8xhD8zhio6Pzf73HmyLMttWKWWwtbR40Ki+1GO7Nkr+cKyzeHI0wd96FQX0qHIlBk5dXJ+8xrJxhwO80tyHhORvmO6tSZyF6+ufC5th67XUnUdNUWD32RPj5K58mvYPXWsZXUa6oGnxzgHE6aWf0k/+34PJLC96kdebeipOtVYOoxnkHcMs1eClaBDdPtsldiXoubhXojrJBiCK+LH7xiCnvwsrknq1xpU0h7LK6xfEzQve/c8ZmR+wBDByPQsHc+ilQl78QRtHRfjJAdIEiBQXlgHjxj4O5praecWmO+XtEVxZBWMzGRR9SvEIR8LxBTGsldloccWK9f0YYImm0vbfKOJAFAS3mtMVJ7ck= 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 with DEVICE_nGnRE memory attributes; this setting overrides (per 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. For these reasons, relax the KVM stage 2 device memory attributes from DEVICE_nGnRE to Normal-NC. Generalizing to other devices may be problematic, however. E.g. GICv2 VCPU interface, which is effectively a shared peripheral, can allow a guest to affect another guest's interrupt distribution. Hence limit the change to VFIO PCI as caution. This is achieved by making the VFIO PCI core module set a flag that is tested by KVM to activate the code. This could be extended to other devices in the future once that is deemed safe. [1] section D8.5 - DDI0487J_a_a-profile_architecture_reference_manual.pdf Applied over v6.8-rc2. History ======= v5 -> v6 - Rebased to v6.8-rc2 v4 -> v5 - Moved the cover letter description text to patch 1/4. - Cleaned up stage2_set_prot_attr() based on Marc Zyngier suggestions. - Moved the mm header file changes to a separate patch. - Rebased to v6.7-rc3. v3 -> v4 - Moved the vfio-pci change to use the VM_VFIO_ALLOW_WC into separate patch. - Added check to warn on the case NORMAL_NC and DEVICE are set simultaneously. - Fixed miscellaneous nitpicks suggested in v3. v2 -> v3 - Added a new patch (and converted to patch series) suggested by Catalin Marinas to ensure the code changes are restricted to VFIO PCI devices. - Introduced VM_VFIO_ALLOW_WC flag for VFIO PCI to communicate with VMM. - Reverted GIC mapping to DEVICE. v1 -> v2 - Updated commit log to the one posted by Lorenzo Pieralisi (Thanks!) - Added new flag to represent the NORMAL_NC setting. Updated stage2_set_prot_attr() to handle new flag. v5 Link: https://lore.kernel.org/all/20231221154002.32622-1-ankita@nvidia.com/ Signed-off-by: Ankit Agrawal Suggested-by: Jason Gunthorpe Acked-by: Catalin Marinas Ankit Agrawal (4): kvm: arm64: introduce new flag for non-cacheable IO memory mm: introduce new flag to indicate wc safe kvm: arm64: set io memory s2 pte as normalnc for vfio pci device vfio: convey kvm that the vfio-pci device is wc safe arch/arm64/include/asm/kvm_pgtable.h | 2 ++ arch/arm64/include/asm/memory.h | 2 ++ arch/arm64/kvm/hyp/pgtable.c | 23 ++++++++++++++++++----- arch/arm64/kvm/mmu.c | 18 ++++++++++++++---- drivers/vfio/pci/vfio_pci_core.c | 3 ++- include/linux/mm.h | 14 ++++++++++++++ 6 files changed, 52 insertions(+), 10 deletions(-)