Received: by 2002:a05:7412:419a:b0:f3:1519:9f41 with SMTP id i26csp3975143rdh; Tue, 28 Nov 2023 08:31:49 -0800 (PST) X-Google-Smtp-Source: AGHT+IE5R5Oa8BMeKBZpA2VF2K+x7naDLIO5HFXQGKnfY4rPrLRFr89bvC07AXVHX9+WBQI7A5ja X-Received: by 2002:a05:6808:18a4:b0:3b8:5ea4:5bc7 with SMTP id bi36-20020a05680818a400b003b85ea45bc7mr14610150oib.39.1701189109362; Tue, 28 Nov 2023 08:31:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701189109; cv=none; d=google.com; s=arc-20160816; b=g73cKwFM6UdjxEjadUq1CO50r5Bx0WHdK4ezqzdoY9HakMlZ8/dd7Nm+MWsneSXEto oSjOIQ4CRmRvDVrO0W2B3so3Xdgt4aSRzr3+1uZKIEMgfa4wFHX2UMu90mnTAT4vaIiC Orx0B17ytFJIrow4uuWX0LJjoLUMNM4DkwICD2P+UlsIrLG/p04CBm1IgdVt8azOH+2h 2LWoIkHYonk1JMGSixtOYu/LBlmbqMyAbkeueaua952eZ84wOcWUz4hP+WRmYR6SWLIe msED/9qKK0gAkXwEBdxFDDq8UAZOAE7RHUesJX8wwMELye7a/+zL54heXsTkiD82ZiZq qGSw== 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=pcQ6g/7V9mViXg1v+cNvtRolZ1DLJmLmz6Fd1Kavr1o=; fh=jsO7llzxgwW/xnJRXngoT8xs0hHc3VOR29vgA3eQnt8=; b=OUeOZHBoveF+Rg5wTY3UJvIlJm/JZw8D1bDtBmxOE03f6ZaX3XiE7E4cW+JY5ZRicm 95Y1ZJx4ZKD8AbJvdH99I9w0Grb3ZkCJAvOebJdzsSgvZGoclSQkP4KGOILoUl2I+PIh FXZlyWnv2wpbNC6dt0a5RkRMcxY42W4ELN8aJi+iAZw5vLXidFg167tYuo0u1teJxC/p sEw4Vj1MBlMBzW+b7veaFO/F8n91ZnVJOpkFGKhVcxn7DtUBt0spojSPjwtC8/ASCz2s uewM3GLaTJl3rNMgY2F70k1Gq76ETtRw3pGLTOb2vZyK62c77MJ6Oe72VQzmEO0sFw0x qvIw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 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 fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id cn22-20020a056808351600b003b8931dd1d3si29856oib.122.2023.11.28.08.31.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Nov 2023 08:31:49 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 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 fry.vger.email (Postfix) with ESMTP id B924E80A0571; Tue, 28 Nov 2023 08:31:46 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344350AbjK1QbW (ORCPT + 99 others); Tue, 28 Nov 2023 11:31:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39880 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344331AbjK1QbT (ORCPT ); Tue, 28 Nov 2023 11:31:19 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 7E37DAB; Tue, 28 Nov 2023 08:31:25 -0800 (PST) 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 70A2DC15; Tue, 28 Nov 2023 08:32:12 -0800 (PST) Received: from [10.1.196.40] (e121345-lin.cambridge.arm.com [10.1.196.40]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 5732C3F6C4; Tue, 28 Nov 2023 08:31:22 -0800 (PST) Message-ID: Date: Tue, 28 Nov 2023 16:31:20 +0000 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Bug in add_dma_entry()'s debugging code Content-Language: en-GB To: Alan Stern , Christoph Hellwig Cc: Hamza Mahfooz , Dan Williams , Marek Szyprowski , Andrew , Ferry Toth , Andy Shevchenko , Thorsten Leemhuis , iommu@lists.linux.dev, Kernel development list , USB mailing list , Catalin Marinas , Will Deacon 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> From: Robin Murphy In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email 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 (fry.vger.email [0.0.0.0]); Tue, 28 Nov 2023 08:31:46 -0800 (PST) On 28/11/2023 3:18 pm, Alan Stern wrote: > On Tue, Nov 28, 2023 at 02:37:02PM +0100, Christoph Hellwig wrote: >> I'd actually go one step back: >> >> 1) for not cache coherent DMA you can't do overlapping operations inside >> a cache line > > Rephrasing slightly: You mustn't perform multiple non-cache-coherent DMA > operations that touch the same cache line concurrently. (The word > "overlapping" is a a little ambiguous in this context.) > > (Right now dma-debug considers only DMA-IN operations. In theory this > restriction should apply even when some of the concurrent operations are > DMA-OUT, provided that at least one of them is DMA-IN. Minor point...) > >> 2) dma-debug is intended to find DMA API misuses, even if they don't >> have bad effects on your particular system >> 3) the fact that the kmalloc implementation returns differently aligned >> memory depending on the platform breaks how dma-debug works currently > > Exactly. That's essentially what Bugzilla #215740 is about. > >> The logical confcusion from that would be that IFF dma-debug is enabled on >> any platform we need to set ARCH_DMA_MINALIGN to the cache line size. > > (IF, not IFF.) And tell distributions that CONFIG_DMA_API_DEBUG is not > meant for production systems but rather for kernel testing, right? Yikes, I'd hope that distros are heeding the warning that the Kconfig calls out already. It's perhaps somewhat understated, as I'd describe the performance impact to large modern systems with high-bandwidth I/O as somewhere between "severe" and "crippling". >> BUT: we're actually reduzing our dependency on ARCH_DMA_MINALIGN by >> moving to bounce buffering unaligned memory for non-coherent >> architectures, > > What's the reason for this? To allow the minimum allocation size to be > smaller than the cache line size? Does the savings in memory make up > for the extra overhead of bounce buffering? Yes, on systems where non-coherent streaming DMA is expected to be rare, or at least not performance-critical, not having to allocate 128 bytes every time we want just 8 or so soon adds up. > Or is this just to allow people to be more careless about how they > allocate their DMA buffers (which doesn't seem to make sense)? > >> which makes this even more complicated. Right now I >> don't have a good idea how to actually deal with having the cachline >> sanity checks with that, but I'm Ccing some of the usual suspects if >> they have a better idea. > > I get the impression that you would really like to have two different > versions of kmalloc() and friends: one for buffers that will be used in > DMA (and hence require cache-line alignment) and one for buffers that > won't be. That approach was mooted, but still has potentially-fiddly corner cases like when the DMA buffer is a member of a larger struct, so we settled on the bounce-buffering solution as the most robust compromise. Thanks, Robin.