Received: by 2002:a05:7412:b10a:b0:f3:1519:9f41 with SMTP id az10csp950224rdb; Fri, 1 Dec 2023 03:09:13 -0800 (PST) X-Google-Smtp-Source: AGHT+IE1dViiYLYS+RTxnrpxE5ROHLOuU155NGLOyaXHP74vLQ6/ySXuPDXusB/NMJz1ywNFBIM4 X-Received: by 2002:a17:90a:1910:b0:280:cc47:b60d with SMTP id 16-20020a17090a191000b00280cc47b60dmr25511440pjg.14.1701428952946; Fri, 01 Dec 2023 03:09:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701428952; cv=none; d=google.com; s=arc-20160816; b=z9StwZc8ZFKTSqdRKWFwijhKDqF9NMRwN28ZZaIT95vpVaNkrhuW9O0wNQk98l+nYv V9w6c3tzluM7e2yfh4FPMzd9DCzrT0J/on7UwBfKWbZUc6LjF/Qsb4NgW6rd6nyiD738 klVMC1NVYX74CBUk1J7WPohEY57x1RMOz0fAeqqwH9OIcDiQOKPZjg64TZwMmSHA4sN/ Tr43P/JxJCVe+bQK0bT07gUIgVVNDHoTEdXJcMLUkp5dBqtkeLMTzpiB+ArtZV4cqaIP SGbaS14By3rCLOZ6fnKFwCnJS0PUtvX8LkD/Q0uvC/MYo1h7Uy/iCrIgpdJlRALHEsEB Lfqw== 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=SkABw60gW6s2v7BekWU8MVlfmpeYCsPsdgVAHjnHA0M=; fh=f34tcXXr1hC9TCMNCN8/NpIFeDU2MOW7hhlZZwNEmvM=; b=kiSEt2qN8xGmdL7PTca4omQLQyRjdKoYsaE6cic4gRnZsh+KW1Nc+dTfDAmlWA1Awu m10k+2Do/Gnwbs++0gmQHM94TaI5Ac0b3Z3jIg8s9kzjz08BlG+W+oiRkyJI5+4gcUTQ UJfF2FryfFKPZZwxfsmxR9mdpbeySFavXrHnBN6xPGeqiBRwna7/i2xTy5ZvMXDnUyTJ L+92B+O6iiWNyPq/CVSRZvcuVEkmmFSIwiC2WA3EX6nemSU9sTqQg9ofBVkuHnDY0twO eCR/Tr93010qIRj1ggqFsNtr6VboAHeWUbIaOxxuCgZK6l9aZ2GY0W7qr2gBPPFVdG1n hsOQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 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 morse.vger.email (morse.vger.email. [23.128.96.31]) by mx.google.com with ESMTPS id x13-20020a17090abc8d00b00280feff8f0fsi5241243pjr.127.2023.12.01.03.09.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Dec 2023 03:09:12 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) client-ip=23.128.96.31; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 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 morse.vger.email (Postfix) with ESMTP id 9ED3783328DD; Fri, 1 Dec 2023 03:09:06 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1378473AbjLALIo (ORCPT + 99 others); Fri, 1 Dec 2023 06:08:44 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50770 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1378464AbjLALIn (ORCPT ); Fri, 1 Dec 2023 06:08:43 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9499D1B2 for ; Fri, 1 Dec 2023 03:08:49 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6BBCAC433C7; Fri, 1 Dec 2023 11:08:46 +0000 (UTC) Date: Fri, 1 Dec 2023 11:08:43 +0000 From: Catalin Marinas To: Ferry Toth Cc: Alan Stern , Christoph Hellwig , Hamza Mahfooz , Dan Williams , Marek Szyprowski , Andrew , Ferry Toth , 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> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <76e8def2-ff45-47d3-91ab-96876ea84079@gmail.com> 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 morse.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 (morse.vger.email [0.0.0.0]); Fri, 01 Dec 2023 03:09:06 -0800 (PST) On Thu, Nov 30, 2023 at 09:08:23PM +0100, Ferry Toth wrote: > Op 28-11-2023 om 18:44 schreef Catalin Marinas: > > Or just force the kmalloc() min align to cache_line_size(), something > > like: > > > > diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h > > index 4a658de44ee9..3ece20367636 100644 > > --- a/include/linux/dma-mapping.h > > +++ b/include/linux/dma-mapping.h > > @@ -543,6 +543,8 @@ static inline int dma_get_cache_alignment(void) > > #ifdef ARCH_HAS_DMA_MINALIGN > > return ARCH_DMA_MINALIGN; > > #endif > > + if (IS_ENABLED(CONFIG_DMA_API_DEBUG)) > > + return cache_line_size(); > > return 1; > > } > > #endif > > diff --git a/mm/slab_common.c b/mm/slab_common.c > > index 8d431193c273..d0b21d6e9328 100644 > > --- a/mm/slab_common.c > > +++ b/mm/slab_common.c > > @@ -879,7 +879,7 @@ static unsigned int __kmalloc_minalign(void) > > unsigned int minalign = dma_get_cache_alignment(); > > if (IS_ENABLED(CONFIG_DMA_BOUNCE_UNALIGNED_KMALLOC) && > > - is_swiotlb_allocated()) > > + is_swiotlb_allocated() && !IS_ENABLED(CONFIG_DMA_API_DEBUG)) > > minalign = ARCH_KMALLOC_MINALIGN; > > return max(minalign, arch_slab_minalign()); > > With above suggestion "force the kmalloc() min align to cache_line_size()" + > Alan's debug code: > > root@yuna:~# journalctl -k | grep hub > kernel: usbcore: registered new interface driver hub > kernel: hub 1-0:1.0: USB hub found > kernel: usb usb1: hub buffer at 71c7180, status at 71c71c0 > kernel: hub 1-0:1.0: 1 port detected > kernel: hub 2-0:1.0: USB hub found > kernel: usb usb2: hub buffer at 71c79c0, status at 71c7a00 > kernel: hub 2-0:1.0: 1 port detected > kernel: hub 1-1:1.0: USB hub found > kernel: usb 1-1: hub buffer at 65b36c0, status at 6639340 > kernel: hub 1-1:1.0: 7 ports detected > > and the stack trace indeed goes away. > > IOW also the 2 root hub kmalloc() are now also aligned to the cache line > size, even though these never triggered the stack trace. Strange: hub status > is aligned far away from hub buffer, kmalloc mysteries. They are 64 bytes apart in most cases other than the last one which I guess the status had to go to a different slab page. > This still did not land for me: are we detecting a false alarm here as the 2 > DMA operations can never happen on the same cache line on non-cache-coherent > platforms? If so, shouldn't we fix up the dma debug code to not detect a > false alarm? Instead of changing the alignment? It's a false alarm indeed on this hardware since the DMA is cache-coherent. I think Christoph mentioned earlier in this thread that he'd like the DMA API debug to report potential problems even if the hardware it is running on is safe. > Or, is this a bonafide warning (for non-cache-coherent platforms)? Then we > should not silence it by force aligning it, but issue a WARN (on a cache > coherent platform) that is more useful (i.e. here we have not an overlap but > a shared cache line). On a non-cache coherent platform something stronger > than a WARN might be appropriate? A non-cache coherent platform would either have the kmalloc() allocations aligned or it would bounce those small, unaligned buffers. 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 we consider the kmalloc() aspect already covered by bouncing or force alignment, the DMA API debug code can still detect other cache line sharing situations. -- Catalin