Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp4618614iog; Wed, 22 Jun 2022 02:25:22 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uEsMm2K1wRkBKjQa2ZgdiOXMOxqLx9YWejbTlOxJfb/KjOl6LKpYKtAbxUSxyHnyf8HTVC X-Received: by 2002:a05:6402:34ca:b0:435:7402:7faa with SMTP id w10-20020a05640234ca00b0043574027faamr2971890edc.274.1655889921837; Wed, 22 Jun 2022 02:25:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655889921; cv=none; d=google.com; s=arc-20160816; b=jf/hLZMqEJaVp5b/4FqsH5N8gLJBsdsDKsfJtMobii1SvdXCkp8N68ALFDDGg5otU7 oHB95Z1RH9T2N1vioLp7VCWOrbt8hTsnSpAAOMDn4GncbBSRz9AVbX4WXHKCpnVduHHp sGJkdqEREaF0rHre9iq2+Barz+iTfpob6WGwSUW9gw29t6yfZ4fnXKeu8D6EU65sF13C uDCivqpMULD1tiOywaWaWO++L6Ztnb1Kp5hVIflvP0COunzSNT4KYAvhne4I/rFSGByW szCF04vRN+hNAOuFja87AIPAVzdB7rIFzMO6b4x5lj6yCa0KPgvpxB6WyK/uTNDDwICG B/XA== 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:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id; bh=/ZV7BgT8F5W+rdciPDzh8GvFnvMgYWWfJe+UPhI63LU=; b=xiyrUYQMtNbYOU6EbSNFWDKQlAc++fLmBZxSf8rc1OJ5vDkUfzgbqj2auTFNVNAVMB yZ15IhicT1he7FIGHF5chsoQpl4IlJRC2AwfJtXowsBMBg4KM4WPBGVXVmLzy7DFHgEO tZ1AHFLTr3dhl9G9+Ex5O+8cyAE1UmZ19bNAgZtGGEYRWKftgPM7GKsgpEvY0lnOSnkI GHot1/+gFncyB71xhRZdbnkxfXIESnI5V5NsQoj7+jkUzVROEoIyevQRrRCKa7FVyYCG prAxA/U+lrBOeTPIIjGb4AgN9n8INRfWuE39zLPrGJl4vh9t+qMwRU/uqUU3ZlsVUH0W AxMg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id r21-20020aa7cfd5000000b0043572b5ef82si11076709edy.546.2022.06.22.02.24.56; Wed, 22 Jun 2022 02:25:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235341AbiFVJPJ (ORCPT + 99 others); Wed, 22 Jun 2022 05:15:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44512 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1352467AbiFVJOx (ORCPT ); Wed, 22 Jun 2022 05:14:53 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 0A0DF101F2; Wed, 22 Jun 2022 02:14:17 -0700 (PDT) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id C031813D5; Wed, 22 Jun 2022 02:14:16 -0700 (PDT) Received: from [10.57.85.1] (unknown [10.57.85.1]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 48B373F66F; Wed, 22 Jun 2022 02:14:12 -0700 (PDT) Message-ID: <47a0abcc-b3d6-a9a3-8d3a-5689bbf8767a@arm.com> Date: Wed, 22 Jun 2022 10:14:08 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; rv:91.0) Gecko/20100101 Thunderbird/91.10.0 Subject: Re: [RFC 2/3] iommu/samsung: Introduce Exynos sysmmu-v8 driver Content-Language: en-GB To: Sam Protsenko , Marek Szyprowski Cc: Krzysztof Kozlowski , Joerg Roedel , Will Deacon , Sumit Semwal , Rob Herring , Catalin Marinas , Cho KyongHo , Hyesoo Yu , Janghyuck Kim , Jinkyu Yang , Alex , Carlos Llamas , Daniel Mentz , Erick Reyes , "J . Avila" , Jonglin Lee , Mark Salyzyn , Thierry Strudel , Will McVicker , Shawn Guo , Bjorn Andersson , linux-samsung-soc@vger.kernel.org, iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org References: <20220120201958.2649-1-semen.protsenko@linaro.org> <20220120201958.2649-3-semen.protsenko@linaro.org> <54b76143-dff3-8a19-7ab9-57fb80d59743@samsung.com> From: Robin Murphy In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00,NICE_REPLY_A, RCVD_IN_DNSWL_HI,SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2022-06-21 20:57, Sam Protsenko wrote: > Hi Marek, > > On Fri, 21 Jan 2022 at 14:31, Marek Szyprowski wrote: > > [snip] > >> >> Well, for starting point the existing exynos-iommu driver is really >> enough. I've played a bit with newer Exyos SoCs some time ago. If I >> remember right, if you limit the iommu functionality to the essential >> things like mapping pages to IO-virtual space, the hardware differences >> between SYSMMU v5 (already supported by the exynos-iommu driver) and v7 >> are just a matter of changing a one register during the initialization >> and different bits the page fault reason decoding. You must of course >> rely on the DMA-mapping framework and its implementation based on >> mainline DMA-IOMMU helpers. All the code for custom iommu group(s) >> handling or extended fault management are not needed for the initial >> version. >> > > Thanks for the advice! Just implemented some testing driver, which > uses "Emulated Translation" registers available on SysMMU v7. That's > one way to verify the IOMMU driver with no actual users of it. It > works fine with vendor SysMMU driver I ported to mainline earlier, and > now I'm trying to use it with exynos-sysmmu driver (existing > upstream). If you're curious -- I can share the testing driver > somewhere on GitHub. > > I believe the register you mentioned is PT_BASE one, so I used > REG_V7_FLPT_BASE_VM = 0x800C instead of REG_V5_PT_BASE_PFN. But I > didn't manage to get that far, unfortunately, as > exynos_iommu_domain_alloc() function fails in my case, with BUG_ON() > at this line: > > /* For mapping page table entries we rely on dma == phys */ > BUG_ON(handle != virt_to_phys(domain->pgtable)); > > One possible explanation for this BUG is that "dma-ranges" property is > not provided in DTS (which seems to be the case right now for all > users of "samsung,exynos-sysmmu" driver). Because of that the SWIOTLB > is used for dma_map_single() call (in exynos_iommu_domain_alloc() > function), which in turn leads to that BUG. At least that's what > happens in my case. The call chain looks like this: > > exynos_iommu_domain_alloc() > v > dma_map_single() > v > dma_map_single_attrs() > v > dma_map_page_attrs() > v > dma_direct_map_page() // dma_capable() == false > v > swiotlb_map() > v > swiotlb_tbl_map_single() > > And the last call of course always returns the address different than > the address for allocated pgtable. E.g. in my case I see this: > > handle = 0x00000000fbfff000 > virt_to_phys(domain->pgtable) = 0x0000000880d0c000 > > Do you know what might be the reason for that? I just wonder how the > SysMMU driver work for all existing Exynos platforms right now. I feel > I might be missing something, like some DMA option should be enabled > so that SWIOTLB is not used, or something like that. Please let me > know if you have any idea on possible cause. The vendor's SysMMU > driver is kinda different in that regard, as it doesn't use > dma_map_single(), so I don't see such issue there. If this SysMMU version is capable of addressing more than 32 bits, then exynos_iommu_probe_device() should set its DMA masks appropriately. (as a side note since I looked, the use of PAGE_SIZE/PAGE_SHIFT in the driver looks wrong, since I can't imagine that the hardware knows whether Linux is using 4KB, 16KB or 64KB and adjusts itself accordingly...) Robin.