Received: by 2002:a05:7412:b10a:b0:f3:1519:9f41 with SMTP id az10csp1212743rdb; Fri, 1 Dec 2023 09:43:12 -0800 (PST) X-Google-Smtp-Source: AGHT+IEvK6yqCnX9hZb69lW07nysS6va2r/CAjtyK9wdK/AJ2u7Kmp7IZiwXxDKhd370bI4nDaZb X-Received: by 2002:a05:6a00:1f0a:b0:6cb:63cb:83c0 with SMTP id be10-20020a056a001f0a00b006cb63cb83c0mr29488371pfb.29.1701452591902; Fri, 01 Dec 2023 09:43:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701452591; cv=none; d=google.com; s=arc-20160816; b=UZZSH+soH4hdhRWlxk01vxYQnQ3BlIug59cWzUVtZB/TMd6h7LvF+lqFDTtc061Cly i7pQRijv/y/DLX7ihj39M0oDW3TsjV4DZocLStpEK7jOBO4wHakF6xijanhGW7208pY+ MKU5GBoxoox2opqp90PEGu+Xdc0j9Px5SpmepBtz6zkJCZ7H03lhxNfHEOAxX1T1/4Gs bsokIkjbnaeNnGrsVNbSM1s+qEzMt+77WWnoajphGm1stXVsg2h+ISkh0x5UMfoEtnBP /Mswzr0fZxVE7OD7MEEBHPbDSnhIxuUarc8NENAoRRYjczApdZuoJNDQt/Jcbhvy06Wi /tLg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=mUsFiFXiiTANP6STejVyd4TiqCvcP0QmZV7JOVzPSg8=; fh=kK4Rqd/T60gqLIdlxBCXSD6DYcfiy0fC44J500kRcZU=; b=0Ry35RZiZDrIeEkk+UsW4nfVJjj+xpOVreuEHqrVRXBAF3JUSnpLA4H9ELeiR+sB4J n9v1zXSYDGu3i8wawx4soo/uCD7mLROAQWIzKh0eudubi2MWBmLci7Y0OXd/jKzSHOSS LiDaCzdRXatb76L0ixaA1eB5KYlnSMBtJDaD3Kw3KJg0hXqX0qm99O5m1/QtSptbBDUy Mtn8hlBhWW/W7OjTxVBuaqCo91IGfFQufUfajpsJNE9zfxm2h1LgXe+4uZop5XYYPRbS tvH8xEMHJmMFCQpKQJFof2H5y4ELRKjJhnd61WwwvSBKJ13WtQGmzxjzGGnyPmnix0eS 18Lg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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 snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id k190-20020a6384c7000000b005c25a1d3916si3723964pgd.651.2023.12.01.09.43.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Dec 2023 09:43:11 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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 snail.vger.email (Postfix) with ESMTP id 0908B812AD17; Fri, 1 Dec 2023 09:43:02 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229905AbjLARmw (ORCPT + 99 others); Fri, 1 Dec 2023 12:42:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38590 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229534AbjLARmv (ORCPT ); Fri, 1 Dec 2023 12:42:51 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1AAB8C4 for ; Fri, 1 Dec 2023 09:42:58 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E2E47C433C7; Fri, 1 Dec 2023 17:42:54 +0000 (UTC) Date: Fri, 1 Dec 2023 17:42:52 +0000 From: Catalin Marinas To: Alan Stern Cc: Ferry Toth , Ferry Toth , Christoph Hellwig , Hamza Mahfooz , Dan Williams , Marek Szyprowski , Andrew , Andy Shevchenko , Thorsten Leemhuis , iommu@lists.linux.dev, Kernel development list , USB mailing list , Robin Murphy , Will Deacon Subject: Re: Bug in add_dma_entry()'s debugging code Message-ID: References: <736e584f-7d5f-41aa-a382-2f4881ba747f@rowland.harvard.edu> <20231127160759.GA1668@lst.de> <637d6dff-de56-4815-a15a-1afccde073f0@rowland.harvard.edu> <20231128133702.GA9917@lst.de> <76e8def2-ff45-47d3-91ab-96876ea84079@gmail.com> <5425cf42-0f49-41b5-b26d-1e099d5bdcc2@elsinga.info> <5093ce37-047e-4aa8-a9e8-2978da9d734a@rowland.harvard.edu> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <5093ce37-047e-4aa8-a9e8-2978da9d734a@rowland.harvard.edu> X-Spam-Status: No, score=-4.0 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_MED,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 X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Fri, 01 Dec 2023 09:43:02 -0800 (PST) Replying to both here. On Fri, Dec 01, 2023 at 11:21:40AM -0500, Alan Stern wrote: > On Fri, Dec 01, 2023 at 01:17:43PM +0100, Ferry Toth wrote: > > > A non-cache coherent platform would either have the kmalloc() > > > allocations aligned or it would bounce those small, unaligned buffers. > > > > It would? Or it always has? It depends on the configuration. arm64 does the bounce as it opted in to CONFIG_DMA_BOUNCE_UNALIGNED_KMALLOC. > > > So it doesn't seem right to issue a warning on x86 where kmalloc() > > > minimum alignment is 8 and not getting the warning on a non-coherent > > > platform which forces the kmalloc() alignment. > > > > If *all*non-coherent platforms implement either correct alignment or bounce > > buffer, and on (coherent) x86 we get an WARN, then it is a false alarm > > right? > > > > That is exactly my question (because I have no idea which platforms have > > non-coherent caches). > > Don't forget, not all DMA buffers are allocated by kmalloc(). A buffer > allocated by some other means might not be aligned properly and might > share a cache line with another buffer. > > Or you might have a single data structure that was allocated by > kmalloc() and then create separate DMA mappings for two members of that > structure. If the two members are in the same cache line, that would be > an error. Indeed, so to be sure we don't trip over other false alarms, we'd also need to force ARCH_DMA_MINALIGN to be at least a cache-line size. That's used in some structures to force a static alignment of various members that take DMA transfers. After that, anything reported might actually be a potential issue, not a false alarm. However, I wonder whether we'd actually hide some genuine problems. Let's say x86 gets some DMA corruption when it tries to DMA 8 bytes into two adjacent buffers because of some DMA buffer overflow, nothing to do with cache lines. You enable the DMA API debugging to see if it reports anything and it suddenly starts working because of the forced minimum alignment. -- Catalin