Received: by 2002:a05:7412:b130:b0:e2:908c:2ebd with SMTP id az48csp256818rdb; Thu, 16 Nov 2023 19:19:31 -0800 (PST) X-Google-Smtp-Source: AGHT+IH4UwfP/uMVj9HiG1OYThcqQBoF7czjYSbm8IZqEuseyTJZkpH6sJIU7B5JMkfhu3s8FDmH X-Received: by 2002:a17:90b:3886:b0:27d:3ecb:3cbb with SMTP id mu6-20020a17090b388600b0027d3ecb3cbbmr16454667pjb.37.1700191171204; Thu, 16 Nov 2023 19:19:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700191171; cv=none; d=google.com; s=arc-20160816; b=JH1UJ75khvuhk7UNseWrEra1BJalVfVM+d1Fu/wwCS4t5yhpwHy06p8iUSpOffCttl 9pobnZjEv7cO5+ZcZABxQfUCoZWeg+Um0v0oeg2KIe8OuDjOcarFZwraHN91MY7ytWhj EbvpUWmrbd4+JEfUEH7Tksz6634Mtmka79wVQWMxIIUX1dmHBln1tHBKZvt4Zc8istH6 ArnMb4N+jQOpee4sZBlyoNQ+t0WNqlttp7xJe5wiHo0c+IIsMQ305DrhweIf7UUJZYwZ 3BHqo813evnAKWplX0J0Q2GDeZQ8U4YPiadiFEjvx8aLhdjZnZTqK4UmkqYdUoo2HIi6 fHDg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:references :cc:to:from:content-language:subject:user-agent:mime-version:date :message-id:dkim-signature; bh=bO5ted+P1A5SGXs96O4z/73BO8Z3ap47fgrFTtk6ec0=; fh=BtvY8BYEYcTuGo5h9IuE+6yds2096eDdhpvWi8nDEJY=; b=MwGN3yG116AvQvdHtBWjrgkj+spb2dEf9SQGU70kpqMETewOhrMpnizREOqbRMDEGB hflmGUKcLBGqmq5VxTt8xFuVvyeCBqnldR7/2Wa4WcyW/UVxPTCPmn7yUSoKno4G9KSq TQtSk3AClsCHswrQssIYmE5zKnjxH7caa0kaaXg//ONBC52bhFGmxmbrsjYYNHw3cwtp 4X0CU9Bpl4q0EXBaCCCAd32h1RyVc+xdkERK6Pwks4kxIoy+clK7k8FjqkCdq2OQfKJZ kWlHnZlhazW/eqp62ADqIBhr4IBf4Gthl2O8uK+vodnGiqOe7pWiJXS05nl9IPGU5Dxj sSvA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@netscape.net header.s=a2048 header.b=p7PoNBbb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=netscape.net Return-Path: Received: from groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id b8-20020a17090aa58800b0026822221502si919647pjq.163.2023.11.16.19.19.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Nov 2023 19:19:31 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; dkim=pass header.i=@netscape.net header.s=a2048 header.b=p7PoNBbb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=netscape.net Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id E836482665B2; Thu, 16 Nov 2023 19:19:27 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345651AbjKQDSc (ORCPT + 99 others); Thu, 16 Nov 2023 22:18:32 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58798 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229437AbjKQDSb (ORCPT ); Thu, 16 Nov 2023 22:18:31 -0500 Received: from sonic301-20.consmr.mail.gq1.yahoo.com (sonic301-20.consmr.mail.gq1.yahoo.com [98.137.64.146]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ECDBAB9 for ; Thu, 16 Nov 2023 19:18:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=netscape.net; s=a2048; t=1700191107; bh=bO5ted+P1A5SGXs96O4z/73BO8Z3ap47fgrFTtk6ec0=; h=Date:Subject:From:To:Cc:References:In-Reply-To:From:Subject:Reply-To; b=p7PoNBbbpxMlpHgmJtjMlBR1ErmscOnmpwr/7UwZ4JnTv4ZCtoCF4f9ULpqSqsAjtTW7k7l33yB4792Af1PXGxwQ/uh3caCCf9zWLw9BJGN9Cmx3xdtVvS2HO40UHvdFhFMOqzARJvUJMkBihEtGNFPwgchxI+7nrAlHO5lDHKsFxqUS8HJZxNq/uruusywRD9hgrVsXCUnKSRK08YVkGY8XWpeNwMzg/JYnW7lVifc14I+sVWeA6hETngdIuc4Ee4stuSS5eEsdN+x02o9gEFzT2kXdkDHOeB5jcLWEOMTh8tWzhLzr8+g8p7K2aY87dDR63CNrTUldyAfit7vkZA== X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1700191107; bh=FS3Ium9Ve7xz7p3mB3DqxcJ6Cse7/KC59ZGsgR4a/Si=; h=X-Sonic-MF:Date:Subject:From:To:From:Subject; b=JJGC2O4POKRNdrTd/RZst9d5SbYmI/XQXhF1+bG+ZReqMkgykDkpOY99+LuGzQ6gZrt1Ct7jq5syKPu5Tzpx/aEv2F3l41WcRMiEbE6+ibzXhgPpQwgg79BdMiAqV39jeiPIr3h8POP/66iQi3iqy49nfQdQrLuLSm5SxY/9YlYOT+fQwTbJKRVMhGZkIiM1LZM+vrdhdDt2EfD/NmnwYC8M82Fb960PT/udi74m0vn3DYiwYdCA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v38jrThXzpoZwAf3Mm1EZLTX.uiwxfjIgq4CeeU LA2zuW8rHYJ0dtInRxAaQX4iLKqhihZeMlEQDwa3LqbjVtvrz0jfoCoNLw4COytbD2xKV5w91JDj 6.S8P2wmOnrlbEpp8J3LwSPHWuie7wt5eBWWRH1AC1ygWggXrw_PQa3BVY_RBnyLekH68z6_pWOz .RDqKB_hrbB_Y7i9FCiF.eU.1IAEA49YEscW8X_QDxfcWZxR0by0OBQQT4BB66g0thmTpxxFdzA8 .5wMF.tzi X-Sonic-MF: X-Sonic-ID: 681c8a96-fdee-4e51-ac62-0881e8c8f908 Received: from sonic.gate.mail.ne1.yahoo.com by sonic301.consmr.mail.gq1.yahoo.com with HTTP; Fri, 17 Nov 2023 03:18:27 +0000 Received: by hermes--production-ne1-56df75844-2xz9h (Yahoo Inc. Hermes SMTP Server) with ESMTPA ID 2d6715d33867073cd4a75dc60ca8514f; Fri, 17 Nov 2023 03:18:24 +0000 (UTC) Message-ID: Date: Thu, 16 Nov 2023 22:18:22 -0500 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] arm/mm: add option to prefer IOMMU ops for DMA on Xen Content-Language: en-US From: Chuck Zmudzinski To: Stefano Stabellini , Robin Murphy Cc: Chuck Zmudzinski , linux-arm-kernel@lists.infradead.org, Russell King , Juergen Gross , 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 References: <20231111184538.2371-1-brchuckz.ref@aol.com> <20231111184538.2371-1-brchuckz@aol.com> In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Mailer: WebService/1.1.21896 mail.backend.jedi.jws.acl:role.jedi.acl.token.atz.jws.hermes.aol X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Thu, 16 Nov 2023 19:19:28 -0800 (PST) On 11/15/2023 12:56 PM, Chuck Zmudzinski wrote: > On 11/14/2023 5:20 PM, Stefano Stabellini wrote: >> On Tue, 14 Nov 2023, Robin Murphy wrote: >>> On 11/11/2023 6:45 pm, Chuck Zmudzinski wrote: >>> > 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 >>> >>> FWIW I don't think this really needs a config option - if Xen *has* made an >>> IOMMU available, then there isn't really much reason not to use it, and if for >>> some reason someone really didn't want to then they could simply disable the >>> IOMMU driver anyway. >> >> The fact that the Exynos IOMMU is exposed to Linux is a mistake. Xen >> doesn't recognize the Exynos IOMMU (it is not one of the IOMMUs Xen has >> a driver for) so it assigns the IOMMU to Dom0. It doesn't happen on >> purpose, it happens by accident. Certain things are going to break, >> specifically I am fairly certain PV drivers are going to break. >> >> If Xen recognized the Exynos IOMMU as an IOMMU it would probably hide it >> from Dom0. (Today Xen doesn't have a list of IOMMUs Xen recognizes but >> doesn't have a driver for.) >> >> I think it is OK for Chuck and others to play around with this >> configuration but I wouldn't add a new kconfig option to Linux to >> support it. >> >> If we do want a kconfig option, I would add a kconfig option or Linux >> command line option to enable/disable swiotlb-xen. Basically a way to >> force-enable or force-disable xen_swiotlb_detect(). That could be >> generally useful for debugging and would also solve the problem here as >> it could be used to force-disable swiotlb-xen. I would imagine that the >> end result is the same: the default ops (iommu_ops) are used. Actually, if the swiotlb-xen DMA ops are disabled, arm/mm/dma-mapping.c does not set DMA ops for any of the devices except for the two devices that the Exyos DRM driver uses: the Exyno fimd and the Exynos mixer, and only for those two devices do iommu_ops get set. The same thing happens on bare metal. Only those same two devices have iommu_ops set, and all the other devices do not have any DMA ops set at all on the bare metal, at least not by arm/mm/dma-mapping.c. I will work on implementing the option to disable swiotlb-xen on the command line which makes it possible to do testing and debugging and also enables fixing the problem with the Exynos mixer by setting a command line option instead of recompiling the kernel with a new config option. > > I will try this. It isn't exactly what I have tested until now because > in all my tests so far all the DMA capable devices on the Chromebook use > swioltlb-xen except for the two devices that need to use the Exynos IOMMU > to fix the error with the Exynos mixer. > >> >> >> >>> > + if (dev->dma_ops == &iommu_ops) { >>> > + dev->archdata.dma_ops_setup = true; >>> >>> The existing assignment is effectively unconditional by this point anyway, so >>> could probably just be moved earlier to save duplicating it (or perhaps just >>> make the xen_setup_dma_ops() call conditional instead to save the early return >>> as well). >>> >>> However, are the IOMMU DMA ops really compatible with Xen? The comments about >>> hypercalls and foreign memory in xen_arch_need_swiotlb() leave me concerned >>> that assuming non-coherent DMA to any old Dom0 page is OK might not actually >>> work in general :/ >> >> Xen has (not yet upstreaming) support for nested IOMMU (Xen uses the >> IOMMU while also it exposes a virtual IOMMU to guests.) In those cases >> the iommu_ops should be compatible with Xen. >> >> swiotlb-xen is useful in cases where there is no IOMMU on the platform >> (or the IOMMU doesn't cover all DMA-capable devices) and Dom0 is 1:1 >> mapped. See include/xen/arm/swiotlb-xen.h:xen_swiotlb_detect. If Dom0 is >> not 1:1 mapped swiotlb-xen doesn't work. If an IOMMU is present and >> covers all DMA-capable devices, then swiotlb-xen is superfluous. > > It seems that swiotlb-xen works on this Chromebook since all but two > of the DMA capable devices use it when configured with the Kconfig option > added here and it seems to work fine so I presume Dom0 is 1:1 mapped as > expected. It is possible that on this device, the IOMMU is only covering > the two devices that need to use the Exynos IOMMU in the tests I have done. > There are many other DMA capable devices that use swiotlb-xen DMA ops > on Xen, but I have not checked what DMA ops the other devices use when > Linux runs on the Chromebook on bare metal without Xen. > > So I plan to do some tests and see what DMA ops the other devices use if > swiotlb-xen is disabled and also what DMA ops the other devices use when > Linux runs on the Chromebook on bare metal without Xen. If these tests > show the problem can be fixed by disabling swiotlb-xen with a Kconfig or > command line option, I will propose v2 to implement that as a solution. > >> This last case is the interesting case for virtual IOMMU and Linux usage of >> iommu_ops.