Received: by 2002:a05:7412:2a8c:b0:e2:908c:2ebd with SMTP id u12csp3362496rdh; Thu, 28 Sep 2023 09:25:41 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEFUknFfktaJKw+leHJ7m1HPgDvm+/IVqp2bzXleaqRBJ8o2CoUjZcxeznuJahSHJ0MaIBR X-Received: by 2002:a05:6e02:b27:b0:349:296c:9b8a with SMTP id e7-20020a056e020b2700b00349296c9b8amr1938912ilu.2.1695918341578; Thu, 28 Sep 2023 09:25:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695918341; cv=none; d=google.com; s=arc-20160816; b=gam9M3f9izBj9QyMzHhBc9Sjnm2GFUAzst6wzsiikXnzpS4AocLseMJPD4gvyaM96N zy0AAj1rsOHAspc+GoQiAuUk+Z2LtxeAdLw1G72fwcGWH6gpi9+xzEdM4frTTyK+ATXV m1LlK8Y8ioU5FJNAMPd0C0PVdoYprO1QvEcc9j0cDipghepx4VhoIy2hmtZPkiTPkl0g hkc6QvzgQmetQ/1moQulPquuCiYXh42VlNeNao8V+oa0S3p6CQ/+vT8+Tydrj2B2EBjd uSJBPTDTzjATmfGYyunRFb7xVRMTo0h/y5rWiusRzXB+z3tYlDy4p9Vg4agorL2oBpJI YEEg== 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=Qf1UZe9D/6NTelVdT6dOPMq33HHUbKReTij6L4fVL3E=; fh=7Iw7ITv30oaLEO++lKZBC6rDkYdinPX3TUwgfBdsSSM=; b=mXoHOyDLpuFbZh26d34CETBTeWfOkHWAEskYjxNxDqZaGkcPdEJTr4Kio6WZvwwJDP Mc6fhDHNlltYI+1rQu5txbt5HzMb/Kd1up2ZQZa3XzPEk1oPCMuB6VPspuOO8lJhj6/5 yR9IVvAUDvWtfmDo3Yd09TCksT0u2Of709hu1LlA+MWNE7/PEWZU9BhbFHThSojXMfYK F9rKN1gPDdP6B/heEjIYeHta7nB2Kckkg4r7FC9IYbx25xRIA3Y39G1Mu9I9Whd5R8Yt F+YUBXHFJpgT/QwY1xdFsnBCOSHqk43u22WSuxoqwcd6VZv7sSgfKeQdne4s2uAoLCsQ ogVw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 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 howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id s20-20020a632c14000000b005694f4b9e85si19470371pgs.229.2023.09.28.09.25.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Sep 2023 09:25:41 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id 95271807C874; Thu, 28 Sep 2023 08:33:29 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231924AbjI1PdV (ORCPT + 99 others); Thu, 28 Sep 2023 11:33:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45620 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231940AbjI1PdT (ORCPT ); Thu, 28 Sep 2023 11:33:19 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id EA136C0 for ; Thu, 28 Sep 2023 08:33: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 E9B351FB; Thu, 28 Sep 2023 08:33:55 -0700 (PDT) Received: from [10.1.196.40] (e121345-lin.cambridge.arm.com [10.1.196.40]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 3792D3F59C; Thu, 28 Sep 2023 08:33:15 -0700 (PDT) Message-ID: Date: Thu, 28 Sep 2023 16:33:08 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux aarch64; rv:102.0) Gecko/20100101 Thunderbird/102.15.1 Subject: Re: [PATCH v1 1/1] ARM: Select DMA_DIRECT_REMAP to fix restricted DMA Content-Language: en-GB To: Arnd Bergmann , Jim Quinlan Cc: Linus Walleij , Christoph Hellwig , bcm-kernel-feedback-list@broadcom.com, jim2101024@gmail.com, Russell King , Geert Uytterhoeven , Russell King , Andrew Morton , Jonathan Corbet , Thomas Gleixner , Sebastian Reichel , Mike Rapoport , Eric DeVolder , Nathan Chancellor , "Kirill A. Shutemov" , Christophe Leroy , "moderated list:ARM PORT" , open list , Claire Chang References: <20230926175208.9298-1-james.quinlan@broadcom.com> <20230926175208.9298-2-james.quinlan@broadcom.com> <1f08bd12-0ac4-43ea-b058-7836521eec12@app.fastmail.com> From: Robin Murphy In-Reply-To: <1f08bd12-0ac4-43ea-b058-7836521eec12@app.fastmail.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-5.7 required=5.0 tests=BAYES_00,NICE_REPLY_A, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_NONE 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 X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Thu, 28 Sep 2023 08:33:30 -0700 (PDT) On 28/09/2023 4:16 pm, Arnd Bergmann wrote: > On Thu, Sep 28, 2023, at 10:00, Jim Quinlan wrote: >> On Thu, Sep 28, 2023 at 9:32 AM Arnd Bergmann wrote: >>> >>> On Thu, Sep 28, 2023, at 08:07, Jim Quinlan wrote: >>>> On Wed, Sep 27, 2023 at 7:10 PM Linus Walleij wrote: >>>>> >>>>> Clearly if you want to do this, surely the ARM-specific >>>>> arch/arm/mm/dma-mapping.c and arch/arm/mm/dma-mapping-nommu.c >>>>> needs to be removed at the same time? >>>> >>>> >>>> Yes, this is the reason I used "RFC" as the fix looked too easy to be viable :-) >>>> I debugged it enough to see that the host driver's >>>> writes to the dma_alloc_coherent() region were not appearing in >>>> memory, and that >>>> led me to DMA_DIRECT_REMAP. >>> >>> Usually when you see a mismatch between the data observed by the >>> device and the CPU, the problem is an incorrect "dma-coherent" >>> property in the DT: either the device is coherent and accesses >>> the cache but the CPU tries to bypass it because the property >>> is missing, or there is an extraneous property and the CPU >>> goes the through the cache but the devices bypasses it. >> >> I just searched, there are no "dt-coherent" properties in our device tree. >> Also, even if we did have them, wouldn't things also fail when not using >> restricted DMA? > > Correct, it should be independent of restricted DMA, but it might > work by chance that way even if it's still wrong. If your DT > is marked as non-coherent (note: the property to look for > is "dma-coherent", not "dt-coherent"), can you check the > datasheet of the SoC to if that is actually correct? > > If the chip is designed to support high-speed devices on > PCIe, it's likely that the PCIe root complex is either coherent > with the caches, or can (and should) be configured that way > for performance reasons. > >>> It could also be a driver bug if the device mixes up the >>> address spaces, e.g. passing virt_to_phys(pointer) rather >>> than the DMA address returned by dma_alloc_coherent(). >> >> This is an Intel 7260 part using the iwlwifi driver, I doubt it has >> errors of that kind. > > It's unlikely but not impossible, as the driver has some > unusual constructs, using a lot of coherent mappings that > might otherwise be streaming mappings, and relying on > dma_sync_single_for_device(..., DMA_BIDIRECTIONAL) for other > data, but without the corresponding dma_sync_single_for_cpu(). > If all the testing happens on x86, this might easily lead > to a bug that only shows up on non-coherent systems but > is never seen during testing. Probably the significant thing about restricted DMA is that it forces all streaming DMA to be bounce-buffered. That should expose busted synchronisation even more decisively than a lack of coherency. If there's no IOMMU, then testing the driver in the absence of restricted DMA but with "swiotlb=force" should confirm or disprove that. Robin. > If the problem is not the "dma-coherent" property, can you > double-check if using a different PCIe device works, or narrow > down which specific buffer you saw get corrupted? > > Arnd > > _______________________________________________ > linux-arm-kernel mailing list > linux-arm-kernel@lists.infradead.org > http://lists.infradead.org/mailman/listinfo/linux-arm-kernel