Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp951940pxb; Thu, 24 Mar 2022 09:52:17 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzKNWGLq81v/JuiLUeQUHbZ1csSKYhUvjuh2W6nDr/cTVCl2N6uzOpf2ogOBtIWF32aP8TG X-Received: by 2002:a63:4e0d:0:b0:381:4606:ec9e with SMTP id c13-20020a634e0d000000b003814606ec9emr4708569pgb.345.1648140737301; Thu, 24 Mar 2022 09:52:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648140737; cv=none; d=google.com; s=arc-20160816; b=vSfFJtuoJlVj57x0/9seNMz3he/T9OHAZv4g7i3xG8BOK+lSAXnmpaaVCN7do0CwuA zg2At/+ypgFQdh+MEKUt10sfixb1IXWvPvbpgenzP6yBZfhuuz5E35qF1JsmMyE3z1tN dcxiXgwU8llTbS/c17pBh3l8N5nruTZUj5kHWIQZ5aVfHAOKSAe5S3hxiWg3aEcJ+4en D+EJ4SWiR7DIRBw2HHyW5zB9aho0S7Y+Y099GtTTTQtkd5yjW0UAR9DdKbfVZsR/8w6D SNXRxf9q0pchBeDiqUxSEzs+SRjHdmS2ePgVeZ28tQRvMZUzXxt2TEBN3FTUf5Sf1AVw dOBw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=6bPyXmkfxZTo8oTy/H3BRIFrA7EJ12kwiCpy8KRE9ts=; b=bbCCCJod5XCTeYwPH6h+BDi9bB8WoUDzWAgRNihvbYIC51nHY86ajQ2CoS68CT6h2l JtwZeG1jHoBkeTcLIANmtl24yqUM7UcqyFD7nSQmTpJwqhVTQCTDPO1TsF6ybQ9SZuCw SsGFTcEYMlLnC4KvhAJblkDua+OMoqX6dy1C4k5188XrktXUmGxM+bVJCpFBUwd5BDbH an2W1uwsW0cCcD4JwdhLteTQK6JkrzeAiay51F3D9gnVq5Gf7Ph0DYON4k2MXhe2Xwmu Pp2dKaKTbKTpIkh06JKFBAWV1jhx/2VV/GxfQ9oCSftR7CZtm98gWmbQrOvDP65LyDt2 DxcA== 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id bm10-20020a656e8a000000b003816043ef25si23701934pgb.282.2022.03.24.09.51.59; Thu, 24 Mar 2022 09:52:17 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347506AbiCXF7N (ORCPT + 99 others); Thu, 24 Mar 2022 01:59:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41378 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346218AbiCXF7J (ORCPT ); Thu, 24 Mar 2022 01:59:09 -0400 Received: from verein.lst.de (verein.lst.de [213.95.11.211]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 20B0F9398F; Wed, 23 Mar 2022 22:57:37 -0700 (PDT) Received: by verein.lst.de (Postfix, from userid 2407) id 320C868B05; Thu, 24 Mar 2022 06:57:33 +0100 (CET) Date: Thu, 24 Mar 2022 06:57:32 +0100 From: Christoph Hellwig To: Robin Murphy Cc: Linus Torvalds , Oleksandr Natalenko , Halil Pasic , Christoph Hellwig , Marek Szyprowski , Toke =?iso-8859-1?Q?H=F8iland-J=F8rgensen?= , 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 Message-ID: <20220324055732.GB12078@lst.de> References: <1812355.tdWV9SEqCh@natalenko.name> <27b5a287-7a33-9a8b-ad6d-04746735fb0c@arm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.17 (2007-11-01) X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,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 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,