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 34928C38A2D for ; Wed, 26 Oct 2022 19:49:10 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.430776.682840 (Exim 4.92) (envelope-from ) id 1onmOY-0006wJ-5X; Wed, 26 Oct 2022 19:48:58 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 430776.682840; Wed, 26 Oct 2022 19:48:58 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1onmOY-0006wC-2m; Wed, 26 Oct 2022 19:48:58 +0000 Received: by outflank-mailman (input) for mailman id 430776; Wed, 26 Oct 2022 19:48:57 +0000 Received: from mail.xenproject.org ([104.130.215.37]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1onmOX-0006w4-6Z for xen-devel@lists.xenproject.org; Wed, 26 Oct 2022 19:48:57 +0000 Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1onmOV-000294-L6; Wed, 26 Oct 2022 19:48:55 +0000 Received: from home.octic.net ([81.187.162.82] helo=[10.0.1.102]) by xenbits.xenproject.org with esmtpsa (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1onmOV-0001st-FJ; Wed, 26 Oct 2022 19:48:55 +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" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org; s=20200302mail; h=Content-Transfer-Encoding:Content-Type:In-Reply-To:Subject: From:References:Cc:To:MIME-Version:Date:Message-ID; bh=EfraIYUHNiit4dxFrnJ/h0saWNF3hEuMzVJIWeO/o5c=; b=5iJhi2tKYvPv0wZx+BOPII813p u3D5dysuyo5T4rC/cm5TtQAqaIdTSbs37pkO170n30kjo6K4Y1Ve08TsLVTEW7jj43cByXoQR+rZg 9qlz1AhYV2wF9Xrjby9h8Z/QpkcuSoPZACRRGrImlJ5AQL3gdMVZp34hkQ4zEo18cuV0=; Message-ID: <60b9cc07-c0ec-756b-802b-5fc96f253dbf@xen.org> Date: Wed, 26 Oct 2022 20:48:52 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.3.3 To: Rahul Singh Cc: Xen developer discussion , Stefano Stabellini , Bertrand Marquis , Michal Orzel , Oleksandr Tyshchenko , Oleksandr Andrushchenko , Volodymyr Babchuk , Jan Beulich , =?UTF-8?Q?Roger_Pau_Monn=c3=a9?= , Andrew Cooper , Juergen Gross References: <75b7665f-66aa-2e11-35a0-edf20a9c0139@xen.org> <99E954B0-50F5-4D7B-A7D2-50D1B7B3657C@arm.com> From: Julien Grall Subject: Re: Proposal for virtual IOMMU binding b/w vIOMMU and passthrough devices In-Reply-To: <99E954B0-50F5-4D7B-A7D2-50D1B7B3657C@arm.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit On 26/10/2022 15:33, Rahul Singh wrote: > Hi Julien, Hi Rahul, >> On 26 Oct 2022, at 2:36 pm, Julien Grall wrote: >> >> >> >> On 26/10/2022 14:17, Rahul Singh wrote: >>> Hi All, >> >> Hi Rahul, >> >>> At Arm, we started to implement the POC to support 2 levels of page tables/nested translation in SMMUv3. >>> To support nested translation for guest OS Xen needs to expose the virtual IOMMU. If we passthrough the >>> device to the guest that is behind an IOMMU and virtual IOMMU is enabled for the guest there is a need to >>> add IOMMU binding for the device in the passthrough node as per [1]. This email is to get an agreement on >>> how to add the IOMMU binding for guest OS. >>> Before I will explain how to add the IOMMU binding let me give a brief overview of how we will add support for virtual >>> IOMMU on Arm. In order to implement virtual IOMMU Xen need SMMUv3 Nested translation support. SMMUv3 hardware >>> supports two stages of translation. Each stage of translation can be independently enabled. An incoming address is logically >>> translated from VA to IPA in stage 1, then the IPA is input to stage 2 which translates the IPA to the output PA. Stage 1 is >>> intended to be used by a software entity( Guest OS) to provide isolation or translation to buffers within the entity, for example, >>> DMA isolation within an OS. Stage 2 is intended to be available in systems supporting the Virtualization Extensions and is >>> intended to virtualize device DMA to guest VM address spaces. When both stage 1 and stage 2 are enabled, the translation >>> configuration is called nesting. >>> Stage 1 translation support is required to provide isolation between different devices within the guest OS. XEN already supports >>> Stage 2 translation but there is no support for Stage 1 translation for guests. We will add support for guests to configure >>> the Stage 1 transition via virtual IOMMU. XEN will emulate the SMMU hardware and exposes the virtual SMMU to the guest. >>> Guest can use the native SMMU driver to configure the stage 1 translation. When the guest configures the SMMU for Stage 1, >>> XEN will trap the access and configure the hardware accordingly. >>> Now back to the question of how we can add the IOMMU binding between the virtual IOMMU and the master devices so that >>> guests can configure the IOMMU correctly. The solution that I am suggesting is as below: >>> For dom0, while handling the DT node(handle_node()) Xen will replace the phandle in the "iommus" property with the virtual >>> IOMMU node phandle. >> Below, you said that each IOMMUs may have a different ID space. So shouldn't we expose one vIOMMU per pIOMMU? If not, how do you expect the user to specify the mapping? > > Yes you are right we need to create one vIOMMU per pIOMMU for dom0. This also helps in the ACPI case > where we don’t need to modify the tables to delete the pIOMMU entries and create one vIOMMU. > In this case, no need to replace the phandle as Xen create the vIOMMU with the same pIOMMU > phandle and same base address. > > For domU guests one vIOMMU per guest will be created. IIRC, the SMMUv3 is using a ring like the GICv3 ITS. I think we need to be open here because this may end up to be tricky to security support it (we have N guest ring that can write to M host ring). > >> >>> For domU guests, when passthrough the device to the guest as per [2], add the below property in the partial device tree >>> node that is required to describe the generic device tree binding for IOMMUs and their master(s) >>> "iommus = < &magic_phandle 0xvMasterID> >>> • magic_phandle will be the phandle ( vIOMMU phandle in xl) that will be documented so that the user can set that in partial DT node (0xfdea). >> >> Does this mean only one IOMMU will be supported in the guest? > > Yes. > >> >>> • vMasterID will be the virtual master ID that the user will provide. >>> The partial device tree will look like this: >>> /dts-v1/; >>> / { >>> /* #*cells are here to keep DTC happy */ >>> #address-cells = <2>; >>> #size-cells = <2>; >>> aliases { >>> net = &mac0; >>> }; >>> passthrough { >>> compatible = "simple-bus"; >>> ranges; >>> #address-cells = <2>; >>> #size-cells = <2>; >>> mac0: ethernet@10000000 { >>> compatible = "calxeda,hb-xgmac"; >>> reg = <0 0x10000000 0 0x1000>; >>> interrupts = <0 80 4 0 81 4 0 82 4>; >>> iommus = <0xfdea 0x01>; >>> }; >>> }; >>> }; >>> In xl.cfg we need to define a new option to inform Xen about vMasterId to pMasterId mapping and to which IOMMU device this >>> the master device is connected so that Xen can configure the right IOMMU. This is required if the system has devices that have >>> the same master ID but behind a different IOMMU. >> >> In xl.cfg, we already pass the device-tree node path to passthrough. So Xen should already have all the information about the IOMMU and Master-ID. So it doesn't seem necessary for Device-Tree. >> >> For ACPI, I would have expected the information to be found in the IOREQ. >> >> So can you add more context why this is necessary for everyone? > > We have information for IOMMU and Master-ID but we don’t have information for linking vMaster-ID to pMaster-ID. I am confused. Below, you are making the virtual master ID optional. So shouldn't this be mandatory if you really need the mapping with the virtual ID? > The device tree node will be used to assign the device to the guest and configure the Stage-2 translation. Guest will use the > vMaster-ID to configure the vIOMMU during boot. Xen needs information to link vMaster-ID to pMaster-ID to configure > the corresponding pIOMMU. As I mention we need vMaster-ID in case a system could have 2 identical Master-ID but > each one connected to a different SMMU and assigned to the guest. I am afraid I still don't understand why this is a requirement. Libxl could have enough knowledge (which will be necessarry for the PCI case) to know the IOMMU and pMasterID associated with a device. So libxl could allocate the vMasterID, tell Xen the corresponding mapping and update the device-tree. IOW, it doesn't seem to be necessary to involve the user in the process here. > >> >>> iommu_devid_map = [ “PMASTER_ID[@VMASTER_ID],IOMMU_BASE_ADDRESS” , “PMASTER_ID[@VMASTER_ID],IOMMU_BASE_ADDRESS”] >>> • PMASTER_ID is the physical master ID of the device from the physical DT. >>> • VMASTER_ID is the virtual master Id that the user will configure in the partial device tree. >>> • IOMMU_BASE_ADDRESS is the base address of the physical IOMMU device to which this device is connected. >> >> Below you give an example for Platform device. How would that fit in the context of PCI passthrough? > > In PCI passthrough case, xl will create the "iommu-map" property in vpci host bridge node with phandle to vIOMMU node. > vSMMUv3 node will be created in xl. This means that libxl will need to know the associated pMasterID to a PCI device. So, I don't understand why you can't do the same for platform devices. > >> >>> Example: Let's say the user wants to assign the below physical device in DT to the guest. >>> iommu@4f000000 { >>> compatible = "arm,smmu-v3"; >>> interrupts = <0x00 0xe4 0xf04>; >>> interrupt-parent = <0x01>; >>> #iommu-cells = <0x01>; >>> interrupt-names = "combined"; >>> reg = <0x00 0x4f000000 0x00 0x40000>; >>> phandle = <0xfdeb>; >>> name = "iommu"; >>> }; >> >> So I guess this node will be written by Xen. How will you the case where there are extra property to added (e.g. dma-coherent)? > > In this example this is physical IOMMU node. vIOMMU node wil be created by xl during guest creation. Ok. I think it would be better to use very different phandle in your example so it doesn't look like a mistake. Cheers, -- Julien Grall