Received: by 2002:a05:7412:419a:b0:f3:1519:9f41 with SMTP id i26csp3183972rdh; Mon, 27 Nov 2023 08:08:32 -0800 (PST) X-Google-Smtp-Source: AGHT+IGeLLHKVR+epTc7r8H/Ob+B8dRg0fryOIS8su0esf4TjauMOwKOhJ0f/sSkBe8witXERypO X-Received: by 2002:a05:6a21:9981:b0:18b:37a2:c4db with SMTP id ve1-20020a056a21998100b0018b37a2c4dbmr19737023pzb.10.1701101311585; Mon, 27 Nov 2023 08:08:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701101311; cv=none; d=google.com; s=arc-20160816; b=KP3oFCXRBZP111LmKViaNtll4i8zuGmJISbwCUGmkd5NyfxsjnV1mgPubHhrvTYkI9 Wn3b3rQcrlC4P7frGUPfZr5iS0E1r+NXJ9wMshy6ZEd9CZKkxKcdOCERkGZYtp02KdwQ e9+vzNrgK3bvoGD2w6IKojy/LGQNjpfOQcRwUe+voEJ0Ard1pKmxFg4zteTZxByMw1Pk N9onXSdcmdSDc0n4jSNYzD322y9UbdB5oeGC7s+te6FiIeevGM/sHNF3DPbLpFO1Vy7A KiU7sfV5ixG8GljG2HkW3r5JoRX3G5JJoGcFQU8xUwcARJ3nlmc6aayoJVr3+bwisIVG 4+CA== 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=MpMfOzcoSI8lZXtlQuBRTRdSh85yuAd1qulcLIaNixU=; fh=i/DHXoe93n632nSpnGFRM5l8E8+zB5vfno/UO9yIFuQ=; b=gU5qlJutWgTCmgWal6+D9MrGO/QHF2hSZ1SPrpO43j29SMRgAgUQBbhMnodq9Xuti5 bjDxTKpwdp7Kc9mqosnoSwFR3Yovh17Q8ve03J9qwo+FZpFc50YU9lyoEU3z0P8jvjMH /BZxHrhYKH0338B1Dg+xnCL3QQOBHEKqwv1l9hOBleN8bfy3Oa5EdRGWuy8wLbrzlvR3 yq/1txJvMyTE8c+5OK3KfcVdDU51HB+kLnTMbgXF+eTlj+6eqYQwKiOMKBlvnOegbRbK HfuNCkRxoPaFP9HAwZxKowLimb/OptqQuMoLD/i8hsQWil2uCpwF4EedyiNa27BTleRK /s0g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from pete.vger.email (pete.vger.email. [23.128.96.36]) by mx.google.com with ESMTPS id a4-20020a634d04000000b005c1cc53612dsi9947209pgb.500.2023.11.27.08.08.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Nov 2023 08:08:31 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) client-ip=23.128.96.36; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id A310D814555A; Mon, 27 Nov 2023 08:08:27 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234327AbjK0QIC (ORCPT + 99 others); Mon, 27 Nov 2023 11:08:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35300 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234297AbjK0QH7 (ORCPT ); Mon, 27 Nov 2023 11:07:59 -0500 Received: from verein.lst.de (verein.lst.de [213.95.11.211]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6639E19A; Mon, 27 Nov 2023 08:08:05 -0800 (PST) Received: by verein.lst.de (Postfix, from userid 2407) id 797F568B05; Mon, 27 Nov 2023 17:08:00 +0100 (CET) Date: Mon, 27 Nov 2023 17:07:59 +0100 From: Christoph Hellwig To: Alan Stern Cc: Hamza Mahfooz , Dan Williams , Christoph Hellwig , Marek Szyprowski , Andrew , Ferry Toth , Andy Shevchenko , Thorsten Leemhuis , iommu@lists.linux.dev, Kernel development list , USB mailing list Subject: Re: Bug in add_dma_entry()'s debugging code Message-ID: <20231127160759.GA1668@lst.de> References: <736e584f-7d5f-41aa-a382-2f4881ba747f@rowland.harvard.edu> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <736e584f-7d5f-41aa-a382-2f4881ba747f@rowland.harvard.edu> User-Agent: Mutt/1.5.17 (2007-11-01) 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 pete.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 (pete.vger.email [0.0.0.0]); Mon, 27 Nov 2023 08:08:28 -0800 (PST) On Mon, Nov 27, 2023 at 11:02:20AM -0500, Alan Stern wrote: > 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_. But that is a special case that does not matter. Linux drivers need to be written in a portable way, and that means we have to care about platforms that are not DMA coherent. > 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? The patch is every but "completely invalid". It points out that you violate the Linux DMA API requirements. This might not have an effect on the particular plaform you are currently running on, but it is still wrong. Note that there have been various mumblings about using nosnoop dma on x86, in which case you'll have the issue there as well. > 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). Fixes welcome.