Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp1398796pxb; Thu, 24 Mar 2022 19:47:56 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyNUbZZDy+5p8NvhfDt39n8vfYI2O+YfLyCA0wdOD7AD5bvUNGAMtbZUVnxQK9JaRk8NT8H X-Received: by 2002:a17:906:4cce:b0:6d6:e571:fcf6 with SMTP id q14-20020a1709064cce00b006d6e571fcf6mr9151154ejt.293.1648176476551; Thu, 24 Mar 2022 19:47:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648176476; cv=none; d=google.com; s=arc-20160816; b=0in5lAXb/thWyutQyKM8jTR+SubQOPuBES6qzcVZ+mtyPhtjGeepdRjos8SUCKP6LR 65MDFwydnvcn7L5XusYBqLMNaJfZmoarfzhx0cCOMs5QO0cwTxIEU3WtKXvqmI19210B kCYwrAVYLUqEEwo2SKGbqdDKyYy+YsvM5sCrsUPWmRbK9yF9Y3R+tWvbVrY/l1QP53eO cJHbWgVXC2YuSZshPtz6jWefKntEsy2Nm0AwwcAvN/Q9yt3Q6BgQfoZ1wwJaEoo4I/k0 DURi+YGruXnJSDO6XSo/2EYiZtYo/pHChTVmIE2XWkwtjTcHpDni5xw/1p9uwvOl9BPr +ivA== 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=yxClJmY6DK4HXAsGZ4xMpvbXEYkBnHZP6Cgnodk0pdc=; b=O6KxszpGYxSQAzkFZKwUWmwXanq+jGsNDJrvZx6ZUixuBmiS0AppRya2t4Km7JtmpV tlAcqlXPGxt5Zt+ihegLlxjEXVknIm67LsaIMKBF1sCbcBeqg2y/KNKf7GDZTdvwSV0X QKI8nABZOhi9g/wnR8qyCyc7vt+/CvbPkupA5fa3wVYtpR9GQKEwKQjoQvjfHuv/hbxM 9ZgFxoSByVC02pHU5Bc5sgvHrcXaTzM06xZrWDAc7QhzZCwY5pYO9H4uoxBtWOdWW3di KVnA7hbbzX1To32z97snpD/ry+MP/c20edMchL8aru06sdT9U77DhDf9pVMM+yEiBrGM swlA== 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:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g4-20020aa7c844000000b00418c2b5bec9si1454181edt.427.2022.03.24.19.47.34; Thu, 24 Mar 2022 19:47:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-wireless-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-wireless-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-wireless-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 S1349640AbiCXLGt (ORCPT + 70 others); Thu, 24 Mar 2022 07:06:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35800 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242588AbiCXLGs (ORCPT ); Thu, 24 Mar 2022 07:06:48 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 2B0615BD0E; Thu, 24 Mar 2022 04:05: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 D3FD11515; Thu, 24 Mar 2022 04:05:16 -0700 (PDT) Received: from [10.57.43.230] (unknown [10.57.43.230]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 7E8DC3F73D; Thu, 24 Mar 2022 04:05:13 -0700 (PDT) Message-ID: <81ffc753-72aa-6327-b87b-3f11915f2549@arm.com> Date: Thu, 24 Mar 2022 11:05:08 +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: Oleksandr Natalenko , Christoph Hellwig Cc: Linus Torvalds , Halil Pasic , Marek Szyprowski , =?UTF-8?Q?Toke_H=c3=b8iland-J=c3=b8rgensen?= , 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> From: Robin Murphy In-Reply-To: <4386660.LvFx2qVVIh@natalenko.name> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00,NICE_REPLY_A, RCVD_IN_DNSWL_HI,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-wireless@vger.kernel.org On 2022-03-24 10:25, Oleksandr Natalenko wrote: > Hello. > > On čtvrtek 24. března 2022 6:57:32 CET Christoph Hellwig wrote: >> On Wed, Mar 23, 2022 at 08:54:08PM +0000, Robin Murphy wrote: >>> I'll admit I still never quite grasped the reason for also adding the >>> override to swiotlb_sync_single_for_device() in aa6f8dcbab47, but I think >>> by that point we were increasingly tired and confused and starting to >>> second-guess ourselves (well, I was, at least). I don't think it's wrong >>> per se, but as I said I do think it can bite anyone who's been doing >>> dma_sync_*() wrong but getting away with it until now. If ddbd89deb7d3 >>> alone turns out to work OK then I'd be inclined to try a partial revert of >>> just that one hunk. >> >> Agreed. Let's try that first. >> >> Oleksandr, can you try the patch below: >> >> >> diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c >> index 6db1c475ec827..6c350555e5a1c 100644 >> --- a/kernel/dma/swiotlb.c >> +++ b/kernel/dma/swiotlb.c >> @@ -701,13 +701,10 @@ void swiotlb_tbl_unmap_single(struct device *dev, phys_addr_t tlb_addr, >> void swiotlb_sync_single_for_device(struct device *dev, phys_addr_t tlb_addr, >> size_t size, enum dma_data_direction dir) >> { >> - /* >> - * Unconditional bounce is necessary to avoid corruption on >> - * sync_*_for_cpu or dma_ummap_* when the device didn't overwrite >> - * the whole lengt of the bounce buffer. >> - */ >> - swiotlb_bounce(dev, tlb_addr, size, DMA_TO_DEVICE); >> - BUG_ON(!valid_dma_direction(dir)); >> + if (dir == DMA_TO_DEVICE || dir == DMA_BIDIRECTIONAL) >> + swiotlb_bounce(dev, tlb_addr, size, DMA_TO_DEVICE); >> + else >> + BUG_ON(dir != DMA_FROM_DEVICE); >> } >> >> void swiotlb_sync_single_for_cpu(struct device *dev, phys_addr_t tlb_addr, >> > > With this patch the AP works for me. Cool, thanks for confirming. So I think ath9k probably is doing something dodgy with dma_sync_*(), but if Linus prefers to make the above change rather than wait for that to get figured out, I believe that should be fine. The crucial part of the "rework" patch is that we'll unconditionally initialise the SWIOTLB bounce slot as it's allocated in swiotlb_tbl_map_single(), regardless of DMA_ATTR_SKIP_CPU_SYNC. As long as that happens, we're safe in terms of leaking data from previous mappings, and any possibility for incorrect sync usage to lose newly-written DMA data is at least no worse than it always has been. The most confusion was around how the proposed DMA_ATTR_OVERWRITE attribute would need to interact with DMA_ATTR_SKIP_CPU_SYNC to remain safe but still have any useful advantage, so unless and until anyone wants to revisit that, this should remain comparatively simple to reason about. Cheers, Robin.