From patchwork Mon Jan 17 12:32:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergiy Kibrik X-Patchwork-Id: 12715403 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 9E7F6C433F5 for ; Mon, 17 Jan 2022 12:43:45 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.258170.444315 (Exim 4.92) (envelope-from ) id 1n9RM2-0007Ty-RQ; Mon, 17 Jan 2022 12:43:22 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 258170.444315; Mon, 17 Jan 2022 12:43:22 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1n9RM2-0007Tr-OI; Mon, 17 Jan 2022 12:43:22 +0000 Received: by outflank-mailman (input) for mailman id 258170; Mon, 17 Jan 2022 12:43:21 +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 1n9RM1-0007E9-DS for xen-devel@lists.xenproject.org; Mon, 17 Jan 2022 12:43:21 +0000 Received: from pb-smtp1.pobox.com (pb-smtp1.pobox.com [64.147.108.70]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 0c0175df-7793-11ec-a115-11989b9578b4; Mon, 17 Jan 2022 13:43:19 +0100 (CET) Received: from pb-smtp1.pobox.com (unknown [127.0.0.1]) by pb-smtp1.pobox.com (Postfix) with ESMTP id 59F8F10CFB2; Mon, 17 Jan 2022 07:43:18 -0500 (EST) (envelope-from sakib@darkstar.site) Received: from pb-smtp1.nyi.icgroup.com (unknown [127.0.0.1]) by pb-smtp1.pobox.com (Postfix) with ESMTP id 429ED10CFB1; Mon, 17 Jan 2022 07:43:18 -0500 (EST) (envelope-from sakib@darkstar.site) Received: from localhost (unknown [95.67.114.216]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by pb-smtp1.pobox.com (Postfix) with ESMTPSA id 9854610CFB0; Mon, 17 Jan 2022 07:43:17 -0500 (EST) (envelope-from sakib@darkstar.site) 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: 0c0175df-7793-11ec-a115-11989b9578b4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed; d=pobox.com; h=from:to:cc :subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; s=sasl; bh=f0AlLUfRzkYVt5wQ5V5E+WuOQ hXu94EtTB2kwhRzmaM=; b=T55NzSTbB62XGFKxxkGi17J85nvNT+iAsS9+dZwuC zTbwZbZNpz6/RbBmFlZrkm7Uuitb53faAb+3dROo+i9vPKskRk5bGL3zODzRs3Fz bZuRc1JD89WyVT01F3OIBUO1NJG9OSvtxoul8HGRP8cdSGC4LjqOFnwWyZ3/gHGE 5E= From: Sergiy Kibrik To: xen-devel@lists.xenproject.org Cc: Sergiy Kibrik , Stefano Stabellini , Julien Grall , Oleksandr Tyshchenko , devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH v3 1/2] dt-bindings: arm: xen: document Xen iommu device Date: Mon, 17 Jan 2022 12:32:50 +0000 Message-Id: <20220117123251.140867-2-Sergiy_Kibrik@epam.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220117123251.140867-1-Sergiy_Kibrik@epam.com> References: <20220117123251.140867-1-Sergiy_Kibrik@epam.com> MIME-Version: 1.0 X-Pobox-Relay-ID: 0B6155C2-7793-11EC-864F-5E84C8D8090B-90055647!pb-smtp1.pobox.com In IOMMU-capable system hypervisor usually takes over IOMMU control. Generally guest domains don't need to care about IOMMU management and take any extra actions. Yet in some cases a knowledge about which device is protected may be useful for privileged domain. In compliance with iommu bindings this can be achieved with device-level iommus property specified with dummy Xen iommu device. Signed-off-by: Sergiy Kibrik --- Documentation/devicetree/bindings/arm/xen.txt | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/Documentation/devicetree/bindings/arm/xen.txt b/Documentation/devicetree/bindings/arm/xen.txt index db5c56db30ec..98efa95c0d1b 100644 --- a/Documentation/devicetree/bindings/arm/xen.txt +++ b/Documentation/devicetree/bindings/arm/xen.txt @@ -58,3 +58,29 @@ Documentation/arm/uefi.rst, which are provided by the regular UEFI stub. However they differ because they are provided by the Xen hypervisor, together with a set of UEFI runtime services implemented via hypercalls, see http://xenbits.xen.org/docs/unstable/hypercall/x86_64/include,public,platform.h.html. + +* XEN IOMMU device + +In compliance with iommu bindings Xen virtual IOMMU device node represents +hypervisor-managed IOMMU [1]. Platform devices specified as IOMMU masters of +this xen-iommu device are protected by hypervisor-managed platform IOMMU. + +Required properties: + +- compatible: Should be "xen,iommu-el2-v1" +- #iommu-cells: must be 0 + +Example: + +xen-iommu { + compatible = "xen,iommu-el2-v1"; + #iommu-cells = <0>; +}; + +video@fe001000 { + ... + /* this platform device is IOMMU-protected by hypervisor */ + iommus = <&xen-iommu 0x0>; +}; + +[1] Documentation/devicetree/bindings/iommu/iommu.txt From patchwork Mon Jan 17 12:32:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergiy Kibrik X-Patchwork-Id: 12715404 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 0A603C4332F for ; Mon, 17 Jan 2022 12:43:46 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.258171.444326 (Exim 4.92) (envelope-from ) id 1n9RM4-0007kW-8J; Mon, 17 Jan 2022 12:43:24 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 258171.444326; Mon, 17 Jan 2022 12:43:24 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1n9RM4-0007kO-4j; Mon, 17 Jan 2022 12:43:24 +0000 Received: by outflank-mailman (input) for mailman id 258171; Mon, 17 Jan 2022 12:43:22 +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 1n9RM2-0007E9-57 for xen-devel@lists.xenproject.org; Mon, 17 Jan 2022 12:43:22 +0000 Received: from pb-smtp1.pobox.com (pb-smtp1.pobox.com [64.147.108.70]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 0d18e35f-7793-11ec-a115-11989b9578b4; Mon, 17 Jan 2022 13:43:21 +0100 (CET) Received: from pb-smtp1.pobox.com (unknown [127.0.0.1]) by pb-smtp1.pobox.com (Postfix) with ESMTP id 24B6710CFB5; Mon, 17 Jan 2022 07:43:20 -0500 (EST) (envelope-from sakib@darkstar.site) Received: from pb-smtp1.nyi.icgroup.com (unknown [127.0.0.1]) by pb-smtp1.pobox.com (Postfix) with ESMTP id 1DA1210CFB4; Mon, 17 Jan 2022 07:43:20 -0500 (EST) (envelope-from sakib@darkstar.site) Received: from localhost (unknown [95.67.114.216]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by pb-smtp1.pobox.com (Postfix) with ESMTPSA id 8609810CFB3; Mon, 17 Jan 2022 07:43:19 -0500 (EST) (envelope-from sakib@darkstar.site) 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: 0d18e35f-7793-11ec-a115-11989b9578b4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed; d=pobox.com; h=from:to:cc :subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; s=sasl; bh=1Y9jeSy+H7oeySABufDfja5st 9AviOj1ziyeeSJthVY=; b=VWyMejs5a88+TkTlBowB84FC9rpPD/V5BTX3fnLdx qqqCrHy/SmTMi9aUkUQkmSbcH5wSklQswbRrkq0umtxv6b4ixYShUzHXOYeY82CS CJmiseBGMr34WtpO5oTYs3qFiKO0HSeF+1ZzBtdAi/5QXfm5XZB3OwzuBeFFyW5x Bc= From: Sergiy Kibrik To: xen-devel@lists.xenproject.org Cc: Sergiy Kibrik , Stefano Stabellini , Julien Grall , Oleksandr Tyshchenko , devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH v3 2/2] arm/xen: don't use xen DMA ops when the device is protected by an IOMMU Date: Mon, 17 Jan 2022 12:32:51 +0000 Message-Id: <20220117123251.140867-3-Sergiy_Kibrik@epam.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220117123251.140867-1-Sergiy_Kibrik@epam.com> References: <20220117123251.140867-1-Sergiy_Kibrik@epam.com> MIME-Version: 1.0 X-Pobox-Relay-ID: 0C8633E6-7793-11EC-8825-5E84C8D8090B-90055647!pb-smtp1.pobox.com Only Xen is able to know if a device can safely avoid to use xen-swiotlb. However since Xen links FDT nodes of protected devices to special dummy xen-iommu node we can use that information to decide whether xen-swiotlb is needed. Signed-off-by: Sergiy Kibrik --- Changelog: v3: rebased over master & documented DT binding https://lists.xenproject.org/archives/html/xen-devel/2021-12/msg01755.html v2: re-use common iommu dt bindings to let guests know which devices are protected: https://lists.xenproject.org/archives/html/xen-devel/2021-10/msg00073.html arch/arm/mm/dma-mapping.c | 2 +- arch/arm/xen/enlighten.c | 9 +++++++++ arch/arm64/mm/dma-mapping.c | 2 +- include/xen/swiotlb-xen.h | 1 + 4 files changed, 12 insertions(+), 2 deletions(-) diff --git a/arch/arm/mm/dma-mapping.c b/arch/arm/mm/dma-mapping.c index 4b61541853ea..73495f0b0a4d 100644 --- a/arch/arm/mm/dma-mapping.c +++ b/arch/arm/mm/dma-mapping.c @@ -2286,7 +2286,7 @@ void arch_setup_dma_ops(struct device *dev, u64 dma_base, u64 size, set_dma_ops(dev, dma_ops); #ifdef CONFIG_XEN - if (xen_initial_domain()) + if (xen_initial_domain() && !xen_is_protected_device(dev)) dev->dma_ops = &xen_swiotlb_dma_ops; #endif dev->archdata.dma_ops_setup = true; diff --git a/arch/arm/xen/enlighten.c b/arch/arm/xen/enlighten.c index 7619fbffcea2..0c2f0b77c8b9 100644 --- a/arch/arm/xen/enlighten.c +++ b/arch/arm/xen/enlighten.c @@ -63,6 +63,15 @@ static __read_mostly unsigned int xen_events_irq; uint32_t xen_start_flags; EXPORT_SYMBOL(xen_start_flags); +bool xen_is_protected_device(struct device *dev) +{ + struct fwnode_handle *fwnode = + fwnode_find_reference(dev_fwnode(dev), "iommus", 0) ; + if (IS_ERR(fwnode)) + return false; + return of_device_is_compatible(to_of_node(fwnode), "xen,iommu-el2-v1"); +} + int xen_unmap_domain_gfn_range(struct vm_area_struct *vma, int nr, struct page **pages) { diff --git a/arch/arm64/mm/dma-mapping.c b/arch/arm64/mm/dma-mapping.c index 6719f9efea09..2f2b5921bf68 100644 --- a/arch/arm64/mm/dma-mapping.c +++ b/arch/arm64/mm/dma-mapping.c @@ -53,7 +53,7 @@ void arch_setup_dma_ops(struct device *dev, u64 dma_base, u64 size, iommu_setup_dma_ops(dev, dma_base, dma_base + size - 1); #ifdef CONFIG_XEN - if (xen_swiotlb_detect()) + if (xen_swiotlb_detect() && !xen_is_protected_device(dev)) dev->dma_ops = &xen_swiotlb_dma_ops; #endif } diff --git a/include/xen/swiotlb-xen.h b/include/xen/swiotlb-xen.h index b3e647f86e3e..f3d805f2246f 100644 --- a/include/xen/swiotlb-xen.h +++ b/include/xen/swiotlb-xen.h @@ -9,6 +9,7 @@ void xen_dma_sync_for_cpu(struct device *dev, dma_addr_t handle, size_t size, enum dma_data_direction dir); void xen_dma_sync_for_device(struct device *dev, dma_addr_t handle, size_t size, enum dma_data_direction dir); +bool xen_is_protected_device(struct device *dev); int xen_swiotlb_init(void); void __init xen_swiotlb_init_early(void);