Received: by 2002:a05:7412:419a:b0:f3:1519:9f41 with SMTP id i26csp3177406rdh; Mon, 27 Nov 2023 08:02:30 -0800 (PST) X-Google-Smtp-Source: AGHT+IHVxCgnb6SvpV0R76ZlcXUmBVNzQmUv3iER+grRRKTI3X0VdRH7EmXHFfW1kxzsitBNH9sC X-Received: by 2002:a05:6870:5ba3:b0:1fa:3c4b:edc0 with SMTP id em35-20020a0568705ba300b001fa3c4bedc0mr6403475oab.59.1701100950245; Mon, 27 Nov 2023 08:02:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701100950; cv=none; d=google.com; s=arc-20160816; b=AOHCVHCBJjdMolSsNm6mP08VWWhjipoHUxqfGBaXs2QcPVp5uhBEgRrvfepr62Xpsu 4lyAfMkLP6WU2xmw1CndxfprzKeSbrFf4JTjuYPD0V4T521c0Gmrj8CAkMvo10StJQKg 2LJX1ajmMiwsJgeVf10nTj832FxOVz7YdUH+wUI+VSuZnMjHFYiYRjZvMFLues7c4PF4 iMJpbgFo/ovBgmZGEIlE4LsRRMU3INJIbSAXmm7BTYmp9xKqbIn6AxuSiXxxpJJbMZfY eDfIZC5vGXgMuWT544vQiH2Slp/sJaNi1LC99dXg5SOfXP8WQnsRqusHpKfhe/ftGAbp vCAg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-disposition:mime-version:message-id :subject:cc:to:from:date; bh=NtE2T1SbimXIniJiwIcZwZJJdAr+8+6AHeKUoWyMEJE=; fh=J2sBCiZ9hmOa9KoVluL5JAy179bvkAN8iXOf5C3mBJU=; b=ffu3PBrCcXvEHha0EbCeobVEaRZ/k62Q0Af+ts5/Qk/UsRRLsVREmcXakvthIon7Q0 rK+qL3iSikMbS9JkatQ8Yt5MKDByT5TBh5LVt6CX6l/b5WoqMZITBF76of+eeomHW9zy Pxuy6GIFuU+Gb/P1GbruYQhzyShtagXXGqnTCgNOrHgerwC+9giZ7b8UNbWDSVuenYJf Yxoq5F3wUSD40aBVvorDICr8qiG/krfrNvWtI3IBISK0FslWFtpGRSCycFVV6dFyWX9+ kAyypyw8ZoY0QRNeBLxUiNaidQ1XBn1uaK0bN3MknKeA2mK6mFSwD3+H6HCx7ApQTV/2 7/4w== 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=harvard.edu Return-Path: Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id f26-20020a056830205a00b006d8187c3518si1815098otp.90.2023.11.27.08.02.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Nov 2023 08:02:30 -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=harvard.edu Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 4FDA580A1862; Mon, 27 Nov 2023 08:02:27 -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 S234277AbjK0QCR (ORCPT + 99 others); Mon, 27 Nov 2023 11:02:17 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37744 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234282AbjK0QCQ (ORCPT ); Mon, 27 Nov 2023 11:02:16 -0500 Received: from netrider.rowland.org (netrider.rowland.org [192.131.102.5]) by lindbergh.monkeyblade.net (Postfix) with SMTP id AC37B1B5 for ; Mon, 27 Nov 2023 08:02:21 -0800 (PST) Received: (qmail 126610 invoked by uid 1000); 27 Nov 2023 11:02:20 -0500 Date: Mon, 27 Nov 2023 11:02:20 -0500 From: Alan Stern To: Hamza Mahfooz , Dan Williams , Christoph Hellwig Cc: Marek Szyprowski , Andrew , Ferry Toth , Andy Shevchenko , Thorsten Leemhuis , iommu@lists.linux.dev, Kernel development list , USB mailing list Subject: Bug in add_dma_entry()'s debugging code Message-ID: <736e584f-7d5f-41aa-a382-2f4881ba747f@rowland.harvard.edu> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_BLOCKED,SPF_HELO_PASS, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no 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]); Mon, 27 Nov 2023 08:02:27 -0800 (PST) Among other things, add_dma_entry() in kernel/dma/debug.c prints an error message when it sees two overlapping FROM_DEVICE DMA mappings. The actual overlap detection is performed by a separate routine, active_cacheline_insert(). But the criterion this routine uses is wrong. All it looks for is mappings that start on the same cache line. However on architectures that have cache-coherent DMA (such as x86), touching the same cache line does not mean that two DMA mappings will interfere with each other. To truly overlap, they would have to touch the same _bytes_. The routine does not check for this, and consequently we get error messages about overlapping mappings when in fact there is no overlap. This bug has been reported in https://bugzilla.kernel.org/show_bug.cgi?id=215740 How should this be fixed? Since the check done in add_dma_entry() is completely invalid for x86 and similar architectures, should it simply be removed for them? Or should the check be enhanced to look for byte-granularity overlap? Alan Stern PS: As a separate issue, active_cacheline_insert() fails to detect overlap in situations where a mapping occupies more than one cache line. For example, if mapping A uses lines N and N+1 and mapping B uses line N+1, no overlap will be detected because the radix-tree keys for A and B will be different (N vs. N+1).