From patchwork Sat Nov 11 18:45:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chuck Zmudzinski X-Patchwork-Id: 13453160 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 C26E8C4332F for ; Sat, 11 Nov 2023 18:46:24 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.631045.984174 (Exim 4.92) (envelope-from ) id 1r1szT-0006tA-KK; Sat, 11 Nov 2023 18:45:55 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 631045.984174; Sat, 11 Nov 2023 18:45:55 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1r1szT-0006t3-Gz; Sat, 11 Nov 2023 18:45:55 +0000 Received: by outflank-mailman (input) for mailman id 631045; Sat, 11 Nov 2023 18:45:53 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1r1szR-0006sx-FS for xen-devel@lists.xenproject.org; Sat, 11 Nov 2023 18:45:53 +0000 Received: from sonic317-20.consmr.mail.gq1.yahoo.com (sonic317-20.consmr.mail.gq1.yahoo.com [98.137.66.146]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 8837639f-80c2-11ee-98da-6d05b1d4d9a1; Sat, 11 Nov 2023 19:45:51 +0100 (CET) Received: from sonic.gate.mail.ne1.yahoo.com by sonic317.consmr.mail.gq1.yahoo.com with HTTP; Sat, 11 Nov 2023 18:45:48 +0000 Received: by hermes--production-bf1-5b945b6d47-pndd9 (Yahoo Inc. Hermes SMTP Server) with ESMTPA ID 58e07c2fd10b16fd7664a3575d70a740; Sat, 11 Nov 2023 18:45:45 +0000 (UTC) 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: 8837639f-80c2-11ee-98da-6d05b1d4d9a1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aol.com; s=a2048; t=1699728348; bh=7k+/Lp++yHj7+j0d0F+FragJXYDYTH7zSig2Tf7HDZQ=; h=From:To:Cc:Subject:Date:References:From:Subject:Reply-To; b=M76eNIVymkrSFhyBSXDSVqVhrOgDqh437O2gD0gyloA80XAkjoxphoxvrhVMTX7wrPIoGJh4oSUJDg5qsUVfHo2Iys65qkBT+HWUqaMFTMynK5V+l4W9FooWfYWX9/Y41+QxWS8zFBrxtMSiswCkHHUPPl1tAQmck62m3phes554K4yc2o21zgW2YqDFQw1TYV5TpmwLuonymVPQMSCdklleoM/RgV3Gv16YdnTjuNI0mK8uts2U4VD6TFfAztT90caPw2P3dN4ax9UGWQ3reKdFdmXtW1eaeEPdfzFH7AheNV3KgRAI+GHEHHzAknprXKyQgGeEcjzfuHe93uaZhg== X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1699728348; bh=R6NSUDEeVyyIX4F6J8syYWD5DeWO2XGw6dBgcM4fiyI=; h=X-Sonic-MF:From:To:Subject:Date:From:Subject; b=WBqXTjQxEvBbAn9nPeDbikM2at+eOyiiRthIQ1Iytgn5qs5BrdrX5KCxyGAdPupyKjfgc1TTLeEDim7/ilvl8YDNGyxc31pGagmO82oE6aYvCyDcoBE/iwStFonqERUib2xakhoU4l8KwTx5NiwtjJaDGDUNSA9U+8gCs6JQnSmc23iQ8YPekHRTWc2m2sNUWeLa4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q.2gWRuyVGrdvM0KB.TWhqra8PDmLZ1DKNdDCKPzDV1WK11OOht4cx.N.7avG Y6sJLBo38VkUXSGidNjbuV8HoUsVpm3Mp12RAQsMPJXLzIXOy8d1VZjF0jLkEuoTPz0XsLRTcPhY fk48XNKDyFeV4pPg3OJRSDuyHXB9Rg2u1cVxlMF1IYc69otOQ1fP14Cif0NuQKVZ2a4HzVZ6V3WS hn5mvVK7_A.7CTp9gS5rGmqGp7BQ0DRqEGFVtPrfdPlY3cDz7_vArURyJMmRVEEeYPJo3hoT3EN7 x6ihTJ2tu X-Sonic-MF: X-Sonic-ID: 935860db-45fa-466f-a70d-9a74ba36a6db From: Chuck Zmudzinski To: linux-arm-kernel@lists.infradead.org Cc: Russell King , Juergen Gross , Stefano Stabellini , Oleksandr Tyshchenko , linux-kernel@vger.kernel.org, xen-devel@lists.xenproject.org, Marek Szyprowski , Andrew Morton , Mathieu Poirier , Greg Kroah-Hartman , "Matthew Wilcox (Oracle)" , Linus Walleij , Jason Gunthorpe , Arnd Bergmann , Julien Grall , Mario Marietto , Bertrand Marquis Subject: [PATCH] arm/mm: add option to prefer IOMMU ops for DMA on Xen Date: Sat, 11 Nov 2023 13:45:37 -0500 Message-ID: <20231111184538.2371-1-brchuckz@aol.com> X-Mailer: git-send-email 2.42.0 MIME-Version: 1.0 References: <20231111184538.2371-1-brchuckz.ref@aol.com> Enabling the new option, ARM_DMA_USE_IOMMU_XEN, fixes this error when attaching the Exynos mixer in Linux dom0 on Xen on the Chromebook Snow (and probably on other devices that use the Exynos mixer): [drm] Exynos DRM: using 14400000.fimd device for DMA mapping operations exynos-drm exynos-drm: bound 14400000.fimd (ops 0xc0d96354) exynos-mixer 14450000.mixer: [drm:exynos_drm_register_dma] *ERROR* Device 14450000.mixer lacks support for IOMMU exynos-drm exynos-drm: failed to bind 14450000.mixer (ops 0xc0d97554): -22 exynos-drm exynos-drm: adev bind failed: -22 exynos-dp: probe of 145b0000.dp-controller failed with error -22 Linux normally uses xen_swiotlb_dma_ops for DMA for all devices when xen_swiotlb is detected even when Xen exposes an IOMMU to Linux. Enabling the new config option allows devices such as the Exynos mixer to use the IOMMU instead of xen_swiotlb_dma_ops for DMA and this fixes the error. The new config option is not set by default because it is likely some devices that use IOMMU for DMA on Xen will cause DMA errors and memory corruption when Xen PV block and network drivers are in use on the system. Link: https://lore.kernel.org/xen-devel/acfab1c5-eed1-4930-8c70-8681e256c820@netscape.net/ Signed-off-by: Chuck Zmudzinski --- The reported error with the Exynos mixer is not fixed by default by adding a second patch to select the new option in the Kconfig definition for the Exynos mixer if EXYNOS_IOMMU and SWIOTLB_XEN are enabled because it is not certain setting the config option is suitable for all cases. So it is necessary to explicitly select the new config option during the config stage of the Linux kernel build to fix the reported error or similar errors that have the same cause of lack of support for IOMMU on Xen. This is necessary to avoid any regressions that might be caused by enabling the new option by default for the Exynos mixer. arch/arm/mm/dma-mapping.c | 6 ++++++ drivers/xen/Kconfig | 16 ++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/arch/arm/mm/dma-mapping.c b/arch/arm/mm/dma-mapping.c index 5409225b4abc..ca04fdf01be3 100644 --- a/arch/arm/mm/dma-mapping.c +++ b/arch/arm/mm/dma-mapping.c @@ -1779,6 +1779,12 @@ void arch_setup_dma_ops(struct device *dev, u64 dma_base, u64 size, if (iommu) arm_setup_iommu_dma_ops(dev, dma_base, size, iommu, coherent); +#ifdef CONFIG_ARM_DMA_USE_IOMMU_XEN + if (dev->dma_ops == &iommu_ops) { + dev->archdata.dma_ops_setup = true; + return; + } +#endif xen_setup_dma_ops(dev); dev->archdata.dma_ops_setup = true; } diff --git a/drivers/xen/Kconfig b/drivers/xen/Kconfig index d5989871dd5d..44e1334b6acd 100644 --- a/drivers/xen/Kconfig +++ b/drivers/xen/Kconfig @@ -181,6 +181,22 @@ config SWIOTLB_XEN select DMA_OPS select SWIOTLB +config ARM_DMA_USE_IOMMU_XEN + bool "Prefer IOMMU DMA ops on Xen" + depends on SWIOTLB_XEN + depends on ARM_DMA_USE_IOMMU + help + Normally on Xen, the IOMMU is used by Xen and not exposed to + Linux. Some Arm systems such as Exynos have an IOMMU that + Xen does not use so the IOMMU is exposed to Linux in those + cases. This option enables Linux to use the IOMMU instead of + using the Xen swiotlb_dma_ops for DMA on Xen. + + Say N here unless support for one or more devices that use + IOMMU ops instead of Xen swiotlb ops for DMA is needed and the + devices that use the IOMMU do not cause any problems on the + Xen system in use. + config XEN_PCI_STUB bool