From nobody Fri Nov 29 16:48:22 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1633341286; cv=none; d=zohomail.com; s=zohoarc; b=R8azOq6YfKkuaPSWP32HoSDmbj+oJTWdBSzyBQx9DMUGrEgp3JiFLSPACAEMm4W8qvUIFbg++oX4VZKq/wq0MVMC4w+2SI6OQI3yVdNpJhU2xqotfY29nyB5hOUC+0m4SCkZr37WH/bQXjy9d6oNkpcL8YEE9J+91Rc2Vxpv8TE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1633341286; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=pKeIejZMmAWUKSzpNfYJ7ftj0OuVVZzScF0RA9xJMh8=; b=RYBoXXR3F6OVFqH/+d+FEFQZUy7uS9uxl9wu6+SkHrMJxiBB7tFnx2zs+VoQ365NB9cKNyDwdWF0mco5jcSOsKogTrW40c6WK40YFR2Q95OB4CHqp5w4YukhD9DBagOmDyfmuwrm3sLFZ4WXeI9mREhXsun2RShXMHig+bb0Gh8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1633341286308531.2273468185635; Mon, 4 Oct 2021 02:54:46 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.201256.355697 (Exim 4.92) (envelope-from ) id 1mXKfu-00042K-C3; Mon, 04 Oct 2021 09:54:22 +0000 Received: by outflank-mailman (output) from mailman id 201256.355697; Mon, 04 Oct 2021 09:54: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 1mXKfu-00042D-8o; Mon, 04 Oct 2021 09:54:22 +0000 Received: by outflank-mailman (input) for mailman id 201256; Mon, 04 Oct 2021 09:54:21 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mXKft-0003kC-Bi for xen-devel@lists.xenproject.org; Mon, 04 Oct 2021 09:54:21 +0000 Received: from mail-lf1-x131.google.com (unknown [2a00:1450:4864:20::131]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 89649863-3125-4d7c-a32c-023248b3999f; Mon, 04 Oct 2021 09:54:16 +0000 (UTC) Received: by mail-lf1-x131.google.com with SMTP id b20so69477941lfv.3 for ; Mon, 04 Oct 2021 02:54:16 -0700 (PDT) Received: from localhost ([178.151.124.169]) by smtp.gmail.com with ESMTPSA id d26sm252462lfi.154.2021.10.04.02.54.14 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 04 Oct 2021 02:54:15 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version 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: 89649863-3125-4d7c-a32c-023248b3999f DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=pKeIejZMmAWUKSzpNfYJ7ftj0OuVVZzScF0RA9xJMh8=; b=IwNzQ2/zRS6NytwyXdzbEIDWmskxGJk/uioBO4rV+JHcIAiTW+yc300kIMSmWFflvD BaGaqMAIGZkc3PkDOd2A7LRBLWQp/jXIhuTK/sJKU67zPgVG5wakyrWfTiZR3R0NGATh QGQvOTXCr9mz4mZvBOSYxLWbWsumJlXqQPHdoDSYPCs9EjE+XHm2dRxMfFlsxf4i6NJ0 9bEozKqLe6lvqANCD1qVPo2h+r3/8hv48cphH41yAF8rxYTAD3EeU6cou6xHZVNWtHnr 5mdXklpXrM86ALocZ5SFCWUkKzrc/fLiLGwwNQz1TYa8SMy44qbGI8odaApBRqykrdcr zJ0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=pKeIejZMmAWUKSzpNfYJ7ftj0OuVVZzScF0RA9xJMh8=; b=kqYLSgyvmD3w0OLzUU0PEfHbxhHIXIgJGXFjm+CTSH//imhQsNjri6sxjXzCDgh+iW V/Spb9WkbMT5fTMyOEgH5b96sSgpqx55Z0I82w7R+kFMv4IsLrkQ9d7O3SGe4crLM75Z 8jSEKaozKvcXKZ5TIOy7GHtM0TuUu8fULKKDibja9YGl/6h/IYUsOtPdzU08MVKnhijx Evxxz1v79i3FDzgeHkLrKJzQBDyNOLXZJMoHwikLD32Z14AI88ep/nAKrNUG4lC26Q7d zF2p0mHXVbwdUZKneY9b2Yh6yXA7HXxi7VBe7T9KhBoyrRVIzvObNp1mR4Elk/+rs0UG 5GLw== X-Gm-Message-State: AOAM531m46a6bWEwhpMD1nOfyDcgg7h6CSGK1hBGst7sRZYFyLKi2MPZ X84C0UTQ8iWuqjiGEkaqiWD0AYfjIqpTkwO2 X-Google-Smtp-Source: ABdhPJyeztrkU+uxCkN1Q5o9nLEW+laMiQoaZtMd9zaApCallzLBMawwyhb4zEQIneNj/grWipTyvQ== X-Received: by 2002:ac2:4e0a:: with SMTP id e10mr150199lfr.225.1633341255568; Mon, 04 Oct 2021 02:54:15 -0700 (PDT) From: Roman Skakun X-Google-Original-From: Roman Skakun To: Stefano Stabellini , Julien Grall , xen-devel@lists.xenproject.org Cc: Roman Skakun , Roman Skakun , Volodymyr Babchuk , Andrii Anisov Subject: [RFC 1/1] xen/arm: set iommu property for IOMMU-protected devices Date: Mon, 4 Oct 2021 12:54:02 +0300 Message-Id: <5b101e4e85668bbb18da83044520b0350344f408.1633106362.git.roman_skakun@epam.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1633341288736100001 Content-Type: text/plain; charset="utf-8" From: Roman Skakun Xen is not exposing any IOMMU properties to Dom0. So Dom0 assumes that all it's devices are not protected by IOMMU. To make Dom0 aware of IOMMU-protected devices, we need to mark them somehow. With this approach Dom0 Linux kernel will be able to selectively disable swiotlb-xen fops for them which will remove unnecessary buffer bounces. This patch adds mechanism to describe IOMMU-protected devices by adding `xen,behind-iommu` property to relevant device nodes in Dom0 device tree. Signed-off-by: Roman Skakun --- xen/arch/arm/domain_build.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c index 69fff7fc29..99e2c42b6c 100644 --- a/xen/arch/arm/domain_build.c +++ b/xen/arch/arm/domain_build.c @@ -580,6 +580,13 @@ static int __init write_properties(struct domain *d, s= truct kernel_info *kinfo, return res; } =20 + if ( iommu_node && is_iommu_enabled(d) && dt_device_is_protected(node)= ) + { + res =3D fdt_property(kinfo->fdt, "xen,behind-iommu", NULL, 0); + if ( res ) + return res; + } + /* * Override the property "status" to disable the device when it's * marked for passthrough. --=20 2.27.0 From nobody Fri Nov 29 16:48:22 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1633341290; cv=none; d=zohomail.com; s=zohoarc; b=ElZv5XNIZV1r4VXXBn0b9OSoIqcuP+0A+Z8bRVf6JgkFRvcVpM1d/m0OkqFyDVTyxTb9sYwaBD6cz35veFK1rEQ9Fz/f4Hal0kQ1vDXvpbJ7wzwjeBNOjPPoIrDw+hjR+peVzdG5ZTurviKNmJWLT9hM5dRQ0VbkJyl51bR4MoY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1633341290; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=dvnwbtKXuUTovX39gB85uB/X6CcafQCm1x1qqRSoYLU=; b=R4VMMZCX2feolfcWiLqUJmEttAlBdO9KzKxOufCtQOmCYSiH4hQGW+TgLrW3AZfjMtlTv3F5Be5i8QEyFCsj2pS7FHK/hJ/7B6UmjO9ydwYv7iEwHXzW1h6tml9gvlljXQexbB2jn8mWYtMID0hauqVj1wGHTfTeKgVT8hP8l5w= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1633341290166990.1061476044573; Mon, 4 Oct 2021 02:54:50 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.201257.355708 (Exim 4.92) (envelope-from ) id 1mXKfz-0004Mb-Le; Mon, 04 Oct 2021 09:54:27 +0000 Received: by outflank-mailman (output) from mailman id 201257.355708; Mon, 04 Oct 2021 09:54:27 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mXKfz-0004MU-Gq; Mon, 04 Oct 2021 09:54:27 +0000 Received: by outflank-mailman (input) for mailman id 201257; Mon, 04 Oct 2021 09:54:26 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mXKfy-0003kC-Br for xen-devel@lists.xenproject.org; Mon, 04 Oct 2021 09:54:26 +0000 Received: from mail-lf1-x133.google.com (unknown [2a00:1450:4864:20::133]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 7cfb36a7-985a-4f7a-8746-bb783082fc2f; Mon, 04 Oct 2021 09:54:18 +0000 (UTC) Received: by mail-lf1-x133.google.com with SMTP id i4so69637767lfv.4 for ; Mon, 04 Oct 2021 02:54:17 -0700 (PDT) Received: from localhost ([178.151.124.169]) by smtp.gmail.com with ESMTPSA id w14sm1612368ljw.73.2021.10.04.02.54.16 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 04 Oct 2021 02:54:16 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version 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: 7cfb36a7-985a-4f7a-8746-bb783082fc2f DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=dvnwbtKXuUTovX39gB85uB/X6CcafQCm1x1qqRSoYLU=; b=YNmeI4BJ3NA50ZgVWUtmG53Yz9NzRqEsySE7NtRQV0dVt15bwba1LF7cnFL3leFtCf pBEheknC/K/zeSTz3nPcdD830yk8aH0N4ClnDpWJh8AZSzlj0hDbgiCz2+Q2WrRSSYRH VJP+uNx6H8U36Rvv15TKmBEulFJBQlHAqa8qZOba1sC1XPebeTCdnl041eT0jGop3wol iissrEgIuk8pDlrT1Nnt5f7YPjeQoUu3zS4muj4nBlYYohyYcsHpf3KCAztRqh3OsGqg EUMmofKcocqfEFa03Jd2cInRnoDTxY5Ofq/F62slQloVVaPpRL72OuIMol9aZVrGXD7Z WMXw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=dvnwbtKXuUTovX39gB85uB/X6CcafQCm1x1qqRSoYLU=; b=nJ50rz7cER+32P5FywPKwms5LGlPw+5P5S3fUJ/6gxDBy6N436nkKntwgOM7da0y+U rxLGMGh/+B0nwGQLMvcpSlXx1DDFbe8QTPDoont26BGcTwYigs4Pci+2rcytyYqmkjye NuOkErsCn537CjArvzPh0Bx5j2ir87HIzlMQvex4m3p3ReWCEV4TweXi0lf3SU/oOuhI n8S9TYSv53eY5wtVzqYp4k9dLNy2Tc6eWuuENfeiikwPafUvZ3/JAd5px7l+k60xV2uI 99oaqTj2uMob+XGH8/23o5a1VFT/QyfRhPfYcwdAN9w5i9ZEQcLixhfcgTUd0s/0Cxg2 1AAw== X-Gm-Message-State: AOAM531pzWy7rdBumeF9G5EK1By+/oAErWko7rvEkKYEGJDr+Zn145MN Dn3YA2QCIpMuNZqgjP+XSds= X-Google-Smtp-Source: ABdhPJzyJGasKtm3y+zLqxQVYpV5fmsIGojp/kBAB//FqkuWucfSlK8Vxl8hFgwI2mPCd49zyc8X8g== X-Received: by 2002:a2e:504a:: with SMTP id v10mr14456170ljd.9.1633341257004; Mon, 04 Oct 2021 02:54:17 -0700 (PDT) From: Roman Skakun X-Google-Original-From: Roman Skakun To: Stefano Stabellini , Julien Grall , xen-devel@lists.xenproject.org Cc: Roman Skakun , Roman Skakun , Volodymyr Babchuk , Andrii Anisov , Roman Skakun Subject: [RFC PATCH] dma-mapping: don't set swiotlb-xen fops for IOMMU-protected devices Date: Mon, 4 Oct 2021 12:54:03 +0300 Message-Id: <20211004095415.100756-1-Roman_Skakun@epam.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1633341292157100005 Content-Type: text/plain; charset="utf-8" Prior to this patch swiotlb-xen fops are set for all devices when we are booting as as Dom0 or direct-mapped DomU. Since Xen now marks devices which are IOMMU-protected by adding additional property to the relevant device, we can check for this property and don't set swiotlb-xen fops for any IOMMU-protected device. Signed-off-by: Roman Skakun --- arch/arm/mm/dma-mapping.c | 2 +- arch/arm/xen/enlighten.c | 4 ++++ arch/arm64/mm/dma-mapping.c | 2 +- include/xen/xen.h | 2 ++ 4 files changed, 8 insertions(+), 2 deletions(-) diff --git a/arch/arm/mm/dma-mapping.c b/arch/arm/mm/dma-mapping.c index c4b8df2ad328..c3e5841d871e 100644 --- a/arch/arm/mm/dma-mapping.c +++ b/arch/arm/mm/dma-mapping.c @@ -2280,7 +2280,7 @@ void arch_setup_dma_ops(struct device *dev, u64 dma_b= ase, u64 size, set_dma_ops(dev, dma_ops); =20 #ifdef CONFIG_XEN - if (xen_initial_domain()) + if (xen_initial_domain() && !xen_is_device_protected(dev)) dev->dma_ops =3D &xen_swiotlb_dma_ops; #endif dev->archdata.dma_ops_setup =3D true; diff --git a/arch/arm/xen/enlighten.c b/arch/arm/xen/enlighten.c index 49f566ad9acb..6ddef3233095 100644 --- a/arch/arm/xen/enlighten.c +++ b/arch/arm/xen/enlighten.c @@ -425,6 +425,10 @@ static int __init xen_pm_init(void) } late_initcall(xen_pm_init); =20 +bool xen_is_device_protected(void *obj) { + struct device *dev =3D obj; + return of_property_read_bool(dev->of_node, "xen,behind-iommu"); +} =20 /* empty stubs */ void xen_arch_pre_suspend(void) { } diff --git a/arch/arm64/mm/dma-mapping.c b/arch/arm64/mm/dma-mapping.c index 93e87b287556..0af5f7a63124 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, size); =20 #ifdef CONFIG_XEN - if (xen_initial_domain()) + if (xen_initial_domain() && !xen_is_device_protected(dev)) dev->dma_ops =3D &xen_swiotlb_dma_ops; #endif } diff --git a/include/xen/xen.h b/include/xen/xen.h index 43efba045acc..3725d69de6f9 100644 --- a/include/xen/xen.h +++ b/include/xen/xen.h @@ -61,4 +61,6 @@ void xen_free_unpopulated_pages(unsigned int nr_pages, st= ruct page **pages); #include #endif =20 +bool xen_is_device_protected(void *obj); + #endif /* _XEN_XEN_H */ --=20 2.27.0