Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp2227114pxb; Fri, 25 Mar 2022 13:26:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw4+qgWZg08JCflPjNvjQzYXLQyPAgXjuu9mh3VA3zEQHnWyI9e2VVuDIfpqSysmDPWUYOU X-Received: by 2002:a63:7804:0:b0:398:1338:86a with SMTP id t4-20020a637804000000b003981338086amr1000198pgc.575.1648239970149; Fri, 25 Mar 2022 13:26:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648239970; cv=none; d=google.com; s=arc-20160816; b=K/sUMiDn7jJpuTX/WtB14P3YKbz4ekk9LiZPTsb4jQWCfeJBrjUg3mWQdHGRPJn/0V 7riBnzd1wGBWK45eHT5BZ1S8AjdVMCcLwriFxCFLIigHTxJet9rYQMw08Q7vpR01upP5 I4VIuOodipIe6diOH7+cvGoQg551J+lMgwzihVMD57d2pKVQQJv96w1doEzJTHqwqNaX rCKhgR7OD2qXjGeA0086yuCyG77lMEAILBkOuHai1sBRjMRZwZxJyW3mKsffdodgz8pw 0aSDbGSERiYhCR43sBrgamizZMmRX78zG6GqugaC+vx7JPv3D4rZ//qbU+gPBi0K8EIf Z0sA== 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=DL5k5oIA8HQG+iTwhSK5kvrVDZLOEXkRyqzhxoBFpAU=; b=Ew6TeBthgJliIqL3Lj7la98ZZnYV2laHLQ0Cjl5lFmxlOE2gFIc+8wHDTB2adS8dca G4pzz1ySjHLHBxhDVHZxlybYFjfngm+/5RaSqCTpR/NJIeq5UXIQYKyg48rj1/Khh6W6 NqpAYWM3V5/A/feq8g/jZl/WrlsYEnY78Kx3Aa2xq2Qbbh74L5cLXYw8BZyhcdKce53E V7nJOrVUtazLp4+/ASsIPEis9uN3azseCZGH4RlPBw18fSo7g8pSDkqUQ+viXd1NR0AI NvhVEq6NPcOQ9C8r2YxH81sWBWySX/QdbmDmR69OM7EpBPtqmgOm9fdoq7UiiWQ0q/66 LsnQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id j18-20020a170902da9200b00153b2d1656asi3617569plx.370.2022.03.25.13.26.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Mar 2022 13:26:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 5C5B32D25AF; Fri, 25 Mar 2022 12:43:06 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231299AbiCYTn5 (ORCPT + 70 others); Fri, 25 Mar 2022 15:43:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36180 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232225AbiCYTnc (ORCPT ); Fri, 25 Mar 2022 15:43:32 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 06B34160FDF; Fri, 25 Mar 2022 12:14:27 -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 A898413D5; Fri, 25 Mar 2022 12:14:26 -0700 (PDT) Received: from [10.57.41.19] (unknown [10.57.41.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 1A5C93F73D; Fri, 25 Mar 2022 12:14:23 -0700 (PDT) Message-ID: Date: Fri, 25 Mar 2022 19:14:20 +0000 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; rv:91.0) Gecko/20100101 Thunderbird/91.7.0 Subject: Re: [REGRESSION] Recent swiotlb DMA_FROM_DEVICE fixes break ath9k-based AP Content-Language: en-GB To: Linus Torvalds , Maxime Bizon Cc: =?UTF-8?Q?Toke_H=c3=b8iland-J=c3=b8rgensen?= , Christoph Hellwig , Oleksandr Natalenko , Halil Pasic , Marek Szyprowski , Kalle Valo , "David S. Miller" , Jakub Kicinski , Paolo Abeni , Olha Cherevyk , iommu , linux-wireless , Netdev , Linux Kernel Mailing List , Greg Kroah-Hartman , stable References: <1812355.tdWV9SEqCh@natalenko.name> <20220324055732.GB12078@lst.de> <4386660.LvFx2qVVIh@natalenko.name> <81ffc753-72aa-6327-b87b-3f11915f2549@arm.com> <878rsza0ih.fsf@toke.dk> <4be26f5d8725cdb016c6fdd9d05cfeb69cdd9e09.camel@freebox.fr> <20220324163132.GB26098@lst.de> <871qyr9t4e.fsf@toke.dk> <31434708dcad126a8334c99ee056dcce93e507f1.camel@freebox.fr> From: Robin Murphy In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,NICE_REPLY_A, RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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-wireless@vger.kernel.org On 2022-03-25 18:30, Linus Torvalds wrote: > On Fri, Mar 25, 2022 at 3:25 AM Maxime Bizon wrote: >> >> In the non-cache-coherent scenario, and assuming dma_map() did an >> initial cache invalidation, you can write this: > > .. but the problem is that the dma mapping code is supposed to just > work, and the driver isn't supposed to know or care whether dma is > coherent or not, or using bounce buffers or not. > > And currently it doesn't work. > > Because what that ath9k driver does is "natural", but it's wrong for > the bounce buffer case. > > And I think the problem is squarely on the dma-mapping side for two reasons: > > (a) this used to work, now it doesn't, and it's unclear how many > other drivers are affected > > (b) the dma-mapping naming and calling conventions are horrible and > actively misleading > > That (a) is a big deal. The reason the ath9k issue was found quickly > is very likely *NOT* because ath9k is the only thing affected. No, > it's because ath9k is relatively common. > > Just grep for dma_sync_single_for_device() and ask yourself: how many > of those other drivers have you ever even HEARD of, much less be able > to test? > > And that's just one "dma_sync" function. Admittedly it's likely one of > the more common ones, but still.. > > Now, (b) is why I think driver nufgt get this so wrong - or, in this > case, possibly the dma-mapping code itself. > > The naming - and even the documentation(!!!) - implies that what ath9k > does IS THE RIGHT THING TO DO. > > The documentation clearly states: > > "Before giving the memory to the device, dma_sync_single_for_device() needs > to be called, and before reading memory written by the device, > dma_sync_single_for_cpu(), just like for streaming DMA mappings that are > reused" Except that's documentation for the non-coherent allocation API, rather than the streaming API in question here. I'll refrain from commenting on having at least 3 DMA APIs, with the same set of sync functions serving two of them, and just stand back a safe distance... Anyway, the appropriate part of that document is probably: "You must do this: - Before reading values that have been written by DMA from the device (use the DMA_FROM_DEVICE direction)" I'm not saying it constitutes *good* documentation, but I would note how it says "have been written", and not "are currently being written". Similarly from the HOWTO: "If you need to use the same streaming DMA region multiple times and touch the data in between the DMA transfers, the buffer needs to be synced properly..." Note "between the DMA transfers", and not "during the DMA transfers". The fundamental assumption of the streaming API is that only one thing is ever accessing the mapping at any given time, which is what the whole notion of ownership is about. Thanks, Robin.