From patchwork Thu Jul 11 14:04:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Teddy Astie X-Patchwork-Id: 13730756 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 lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 93D24C3DA41 for ; Thu, 11 Jul 2024 14:04:31 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.757523.1166508 (Exim 4.92) (envelope-from ) id 1sRuPB-0008Bg-2f; Thu, 11 Jul 2024 14:04:17 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 757523.1166508; Thu, 11 Jul 2024 14:04:17 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1sRuPB-0008BZ-0B; Thu, 11 Jul 2024 14:04:17 +0000 Received: by outflank-mailman (input) for mailman id 757523; Thu, 11 Jul 2024 14:04:15 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1sRuP9-0008BT-Iv for xen-devel@lists.xenproject.org; Thu, 11 Jul 2024 14:04:15 +0000 Received: from mail186-27.suw21.mandrillapp.com (mail186-27.suw21.mandrillapp.com [198.2.186.27]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 731bc81b-3f8e-11ef-8776-851b0ebba9a2; Thu, 11 Jul 2024 16:04:12 +0200 (CEST) Received: from pmta10.mandrill.prod.suw01.rsglab.com (localhost [127.0.0.1]) by mail186-27.suw21.mandrillapp.com (Mailchimp) with ESMTP id 4WKc0W41Q6z6CQ2dP for ; Thu, 11 Jul 2024 14:04:11 +0000 (GMT) Received: from [37.26.189.201] by mandrillapp.com id 71c57759c31047c8a919f94a61e8dac0; Thu, 11 Jul 2024 14:04:11 +0000 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 731bc81b-3f8e-11ef-8776-851b0ebba9a2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mandrillapp.com; s=mte1; t=1720706651; x=1720967151; bh=OO478PqU3r70xVXwjD0fZgEZDEQGLcHFOLvp5rg+Dm0=; h=From:Subject:To:Cc:Message-Id:Feedback-ID:Date:MIME-Version: Content-Type:Content-Transfer-Encoding:CC:Date:Subject:From; b=fYhZNTSOp5K1RGb5atPs2IsPtbZk2lU9jXxAiWPqq9AvEfKiZpNWk4hTXiR6d09sA Q20EIJQoFuvfmRvERwE9A9Z7+Dk+8+Tt/It9mOoC8ore86oNGebEWtSlwUEC+Y/Oxh DB6byYlTlhq/NDeYR8kALobyTB9fPvX04ccZs6XhDeemGEkb9DzNYu1g8dAZq9qGeT mBVj63p3atk2yjZgDeKRK3Sj59UgKsz8O6cEv8W0GTPh8tln88oNHjMehSa+Qyj5hq AwIaNWSLD1jkwMCX29eHAcPHiColazgm+wJr8Is3LFVV+YxJzQN11ZMJZ1GOqVIkTq Vhlhm8jwNU0Yw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vates.tech; s=mte1; t=1720706651; x=1720967151; i=teddy.astie@vates.tech; bh=OO478PqU3r70xVXwjD0fZgEZDEQGLcHFOLvp5rg+Dm0=; h=From:Subject:To:Cc:Message-Id:Feedback-ID:Date:MIME-Version: Content-Type:Content-Transfer-Encoding:CC:Date:Subject:From; b=NSQCPvyXeQdd3OmpeWfH6xTDqyES7g4ExQtfKeeDYOOC/FDG4IzYv4j3L5rX8iPZ5 Y4UyDzAYFGxgthgMyLwVo2ZZ3hqOFF0aB31jFRv5znWGThQL8fVHwUYlFbgrvr66S+ gsgD20R+3fDW17a3ldV2nLl/vvMmqdFpQmPdqeKroKKr0ARIIiJva/1gyekHvRxjd7 AbzLCrRdjrB42FRTZ6++fDlwVLNUgUnA66xmDPBcY0X4UIwEcwOiFCyGfouwP33i53 xjeONqBR6H6aOMdfCch27EWli2lCWYBAIKSDZKZb6G5tqN9ugev+xLU4NU3rvb0V+A xphoEXH5q41Vg== From: Teddy Astie Subject: =?utf-8?q?=5BRFC_XEN_PATCH_v3_0/5=5D_IOMMU_subsystem_redesign_and_P?= =?utf-8?q?V-IOMMU_interface?= X-Mailer: git-send-email 2.45.2 X-Bm-Disclaimer: Yes X-Bm-Milter-Handled: 4ffbd6c1-ee69-4e1b-aabd-f977039bd3e2 X-Bm-Transport-Timestamp: 1720706648754 To: xen-devel@lists.xenproject.org Cc: Teddy Astie , Andrew Cooper , Jan Beulich , Julien Grall , Stefano Stabellini , =?utf-8?q?Roger_Pau_Monn=C3=A9?= , Lukasz Hawrylko , "Daniel P. Smith" , =?utf-8?q?Mateusz_M=C3=B3?= =?utf-8?q?wka?= , =?utf-8?q?Marek_Marczykowski-G?= =?utf-8?q?=C3=B3recki?= Message-Id: X-Native-Encoded: 1 X-Report-Abuse: =?utf-8?q?Please_forward_a_copy_of_this_message=2C_including?= =?utf-8?q?_all_headers=2C_to_abuse=40mandrill=2Ecom=2E_You_can_also_report_?= =?utf-8?q?abuse_here=3A_https=3A//mandrillapp=2Ecom/contact/abuse=3Fid=3D30?= =?utf-8?q?504962=2E71c57759c31047c8a919f94a61e8dac0?= X-Mandrill-User: md_30504962 Feedback-ID: 30504962:30504962.20240711:md Date: Thu, 11 Jul 2024 14:04:11 +0000 MIME-Version: 1.0 This work has been presented at Xen Summit 2024 during the IOMMU paravirtualization and Xen IOMMU subsystem rework design session. Operating systems may want to have access to a IOMMU in order to do DMA protection or implement certain features (e.g VFIO on Linux). VFIO support is mandatory for framework such as SPDK, which can be useful to implement an alternative storage backend for virtual machines [1]. In this patch series, we introduce in Xen the ability to manage several contexts per domain and provide a new hypercall interface to allow guests to manage IOMMU contexts. The VT-d driver is updated to support these new features. [1] Using SPDK with the Xen hypervisor - FOSDEM 2023 --- Changed in v2 : * fixed Xen crash when dumping IOMMU contexts (using X debug key) with DomUs without IOMMU * s/dettach/detach/ * removed some unused includes * fix dangling devices in contexts with detach Changed in v3 : * lock entirely map/unmap in hypercall * prevent IOMMU operations on dying contexts (fix race condition) * iommu_check_context+iommu_get_context -> iommu_get_context and check for NULL Teddy Astie (5): docs/designs: Add a design document for PV-IOMMU docs/designs: Add a design document for IOMMU subsystem redesign IOMMU: Introduce redesigned IOMMU subsystem VT-d: Port IOMMU driver to new subsystem xen/public: Introduce PV-IOMMU hypercall interface --- docs/designs/iommu-contexts.md | 398 +++++++ docs/designs/pv-iommu.md | 105 ++ xen/arch/x86/domain.c | 2 +- xen/arch/x86/include/asm/arena.h | 54 + xen/arch/x86/include/asm/iommu.h | 44 +- xen/arch/x86/include/asm/pci.h | 17 - xen/arch/x86/mm/p2m-ept.c | 2 +- xen/arch/x86/pv/dom0_build.c | 4 +- xen/arch/x86/tboot.c | 4 +- xen/common/Makefile | 1 + xen/common/memory.c | 4 +- xen/common/pv-iommu.c | 328 ++++++ xen/drivers/passthrough/Kconfig | 14 + xen/drivers/passthrough/Makefile | 3 + xen/drivers/passthrough/context.c | 649 +++++++++++ xen/drivers/passthrough/iommu.c | 337 ++---- xen/drivers/passthrough/pci.c | 49 +- xen/drivers/passthrough/quarantine.c | 49 + xen/drivers/passthrough/vtd/Makefile | 2 +- xen/drivers/passthrough/vtd/extern.h | 14 +- xen/drivers/passthrough/vtd/iommu.c | 1557 +++++++++++--------------- xen/drivers/passthrough/vtd/quirks.c | 21 +- xen/drivers/passthrough/x86/Makefile | 1 + xen/drivers/passthrough/x86/arena.c | 157 +++ xen/drivers/passthrough/x86/iommu.c | 104 +- xen/include/hypercall-defs.c | 6 + xen/include/public/pv-iommu.h | 114 ++ xen/include/public/xen.h | 1 + xen/include/xen/iommu.h | 120 +- xen/include/xen/pci.h | 3 + 30 files changed, 2855 insertions(+), 1309 deletions(-) create mode 100644 docs/designs/iommu-contexts.md create mode 100644 docs/designs/pv-iommu.md create mode 100644 xen/arch/x86/include/asm/arena.h create mode 100644 xen/common/pv-iommu.c create mode 100644 xen/drivers/passthrough/context.c create mode 100644 xen/drivers/passthrough/quarantine.c create mode 100644 xen/drivers/passthrough/x86/arena.c create mode 100644 xen/include/public/pv-iommu.h