Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp1605926pxb; Fri, 25 Mar 2022 01:54:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwUyC3sRC1iww0RqL/1Pd7rD2coGONg6rvKH6RLw8Ypg/Uexj3T6gu/Ulp80hSjWKd65mGt X-Received: by 2002:a17:90a:528b:b0:1bc:c5f9:82a with SMTP id w11-20020a17090a528b00b001bcc5f9082amr23504799pjh.210.1648198488151; Fri, 25 Mar 2022 01:54:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648198488; cv=none; d=google.com; s=arc-20160816; b=JSW/rsRxNFNqwvGrKHggc4D4I1FoxQZptsYnq29/gaMH40IvToBs8HO95GIlcRARt0 jzMOQaCC6HGk7ZL303pruv+RLkV8Ns8JjKSgf8L1qbunRYY4oANyWwXm5FZaqTRKBxfv 5sLxo7w24f6nlV8GY83UruLrTD+ZoNyOnX/b+mrHHDT2bsOqSwwAa0lZ6xyhumTIiYhT SEogZRkuxF4QxmUlzE6RmvJXqRq+2n0MsUmOLbFTYQJbB3MxNaR5YmzT1Oxgkl34M0rU w7RDuaH4bLEepnWI7J+qP6Mpm6nIhsDoAk4mokH4Tpak4NisXw3Kmdx1JSSyNQFov+rZ kA4g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:references :in-reply-to:subject:cc:to:dkim-signature:from; bh=3T9ji2+vMZ6yU+DLqMeLjbdAgarI9h6R8m+Qzkn6wwY=; b=0c6sIZNsBdKDhysRsEWbUOos7wbT6RP17EC/I3FeWEf/ZwKHfbe0U8jkqQYCkIwwqC nKuRh+gF5Of3pZwdSTbdp5JNALcuqhdc2uIvhtONf/Ro1PpOmB/4DwHJvfehrSBLf8h0 3UThbZCefe/ZmzPVQcKlBtqKACPgExaiNzK5YK4IUTOT9z2FMFWX8aeO+/s42SwzF9Af mA28n5rpkP5bYApxIh+PtCu1W822krKpIIMBgcjPxc1wRvV0C7UM1PmVF87npvjPCEC8 G8NWcVs3o3RhXnDE8VEzNXEedNzfgqbEyjHQrEkwED/OmO5muN7//ZE7KGadTkQAGE5X tl3A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@toke.dk header.s=20161023 header.b=bhFRZWBs; 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=pass (p=REJECT sp=REJECT dis=NONE) header.from=toke.dk Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l8-20020a17090270c800b00153b2d1665asi1648678plt.610.2022.03.25.01.54.34; Fri, 25 Mar 2022 01:54:47 -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; dkim=pass header.i=@toke.dk header.s=20161023 header.b=bhFRZWBs; 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=pass (p=REJECT sp=REJECT dis=NONE) header.from=toke.dk Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1352112AbiCXRJG (ORCPT + 99 others); Thu, 24 Mar 2022 13:09:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48580 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242253AbiCXRJF (ORCPT ); Thu, 24 Mar 2022 13:09:05 -0400 Received: from mail.toke.dk (mail.toke.dk [45.145.95.4]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C1DCDB18A8; Thu, 24 Mar 2022 10:07:32 -0700 (PDT) From: Toke =?utf-8?Q?H=C3=B8iland-J=C3=B8rgensen?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=toke.dk; s=20161023; t=1648141651; bh=fBBTep0fsFEy1SpGBxltwkhke+QjxK1XAYERNO2rihY=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=bhFRZWBsXOArjlqHIuob1rAQIRclaUsGXtG0oYMnqwucW0eBkVtBa836EE26AgPkP rDYnYVabCLw7xPJJZklieM6hKIXr4OOKDCxYIma89OF2kmdzdPfixk6LsMRH7/XpIt XoLz6iqw/Nel9vizNBhxFPAcqltsDSYj+nLrKAqu4dwFqA81LfGt1aBWoedpWXOH6J TNW9npCRFGqtmCp7jaAYTq7v1fDBmeIPIe6qntS+LTFQtOEYN7gPB7m6SWe7SuXTIy 3+tCgwzG5AXbPni5j6XNyuq6vjIpvATiyCHA5Fg0gRLyJzJnOq1dioEQtcZ4hmYBua d42HhFVa3yW5w== To: Robin Murphy , Christoph Hellwig , Maxime Bizon Cc: Oleksandr Natalenko , Linus Torvalds , 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 Subject: Re: [REGRESSION] Recent swiotlb DMA_FROM_DEVICE fixes break ath9k-based AP In-Reply-To: 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> Date: Thu, 24 Mar 2022 18:07:29 +0100 X-Clacks-Overhead: GNU Terry Pratchett Message-ID: <871qyr9t4e.fsf@toke.dk> MIME-Version: 1.0 Content-Type: text/plain X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, 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 Robin Murphy writes: > On 2022-03-24 16:31, Christoph Hellwig wrote: >> On Thu, Mar 24, 2022 at 05:29:12PM +0100, Maxime Bizon wrote: >>>> I'm looking into this; but in the interest of a speedy resolution of >>>> the regression I would be in favour of merging that partial revert >>>> and reinstating it if/when we identify (and fix) any bugs in ath9k :) >>> >>> This looks fishy: >>> >>> ath9k/recv.c >>> >>> /* We will now give hardware our shiny new allocated skb */ >>> new_buf_addr = dma_map_single(sc->dev, requeue_skb->data, >>> common->rx_bufsize, dma_type); >>> if (unlikely(dma_mapping_error(sc->dev, new_buf_addr))) { >>> dev_kfree_skb_any(requeue_skb); >>> goto requeue_drop_frag; >>> } >>> >>> /* Unmap the frame */ >>> dma_unmap_single(sc->dev, bf->bf_buf_addr, >>> common->rx_bufsize, dma_type); >>> >>> bf->bf_mpdu = requeue_skb; >>> bf->bf_buf_addr = new_buf_addr; >> >> Creating a new mapping for the same buffer before unmapping the >> previous one does looks rather bogus. But it does not fit the >> pattern where revering the sync_single changes make the driver >> work again. > > OK, you made me look :) > > Now that it's obvious what to look for, I can only conclude that during > the stanza in ath_edma_get_buffers(), the device is still writing to the > buffer while ownership has been transferred to the CPU, and whatever got > written while ath9k_hw_process_rxdesc_edma() was running then gets wiped > out by the subsequent sync_for_device, which currently resets the > SWIOTLB slot to the state that sync_for_cpu copied out. By the letter of > the DMA API that's not allowed, but on the other hand I'm not sure if we > even have a good idiom for "I can't tell if the device has finished with > this buffer or not unless I look at it" :/ Right, but is that sync_for_device call really needed? AFAICT, that ath9k_hw_process_rxdesc_edma() invocation doesn't actually modify any of the data when it returns EINPROGRESS, so could we just skip it? Like the patch below? Or am I misunderstanding the semantics here? -Toke diff --git a/drivers/net/wireless/ath/ath9k/recv.c b/drivers/net/wireless/ath/ath9k/recv.c index 0c0624a3b40d..19244d4c0ada 100644 --- a/drivers/net/wireless/ath/ath9k/recv.c +++ b/drivers/net/wireless/ath/ath9k/recv.c @@ -647,12 +647,8 @@ static bool ath_edma_get_buffers(struct ath_softc *sc, common->rx_bufsize, DMA_FROM_DEVICE); ret = ath9k_hw_process_rxdesc_edma(ah, rs, skb->data); - if (ret == -EINPROGRESS) { - /*let device gain the buffer again*/ - dma_sync_single_for_device(sc->dev, bf->bf_buf_addr, - common->rx_bufsize, DMA_FROM_DEVICE); + if (ret == -EINPROGRESS) return false; - } __skb_unlink(skb, &rx_edma->rx_fifo); if (ret == -EINVAL) {