From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=103.168.172.154 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796341446; b=4vlAMp/mpl8DZYDvS1meg71a5W+XYtkzJiMP5Y4cjdhz1cbH3RJMz0bcDkGUycYo1Yz3 v4L5boWuQpwkEzQ4hF333ynzWsEmahwoUBt7ax1EpYafPyDMWxEEpeGIv/6DLAC94k6t+ qDuKlfzBeQ6CI6Ea6pq4mPVTcZ/p00uoEzM0BLZr0upXGtdwVvzf+Ib8hES7jHYzPwBbF n9SHx8QGdrPUqZFLw5Yg88zk2bKAPIYwu4hIIIQy1UOn8Ye4wjVWqkQH7yFwcsHKvDEFv /GDa7rvfLlkab3MFaOPVKxTrtb353vyPdpprz3EkVf9L2mapwxOEZb0pLKH4FS0t4kQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796341446; h=DMARC-Filter:Received:Received:DKIM-Signature:DKIM-Signature: X-DKIM2-Info:DKIM2-Signature:X-DKIM2-Info:Message-Instance: X-ME-Sender:X-ME-Received:X-ME-Proxy-Cause:X-ME-Proxy:Feedback-ID: Received:Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; bh=Z5i4g+ILTU+LweznsUBbu+VY3MJBcwZmf5LWDxw8p4U=; b=M1i3vyBWx3LwI5TqWekgL2WYnNYELfkEAEfxv7l1KiL+0Dj3XcalcKXYUWxFSH/IBCny o1mrK0buV19CMoIifdl6xT303ZB8GGz3S5Qs4uvK66DnOnLsgBkrWJ/tV+9HfupiNb7gN 4n+v/gZJc0xALKJxI8SmoX/ayROUYF7FGQyBxeu1D8JKQigoxE2UJZ9dEqkK1bym+nGm1 QuFq6a0821wqnhXxvK4nkiGIVpF0le2MaQReC2vv4lCs8yKglpiVm8Em3pWIVxjTvAjeX lt7V9SZtwYW5LePz11jdVqGEzvpEkOW2dAzM6mOJW1XDzI1EfvcPGS3hqfhqcLkPkyA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=fastmail.com; spf=pass smtp.mailfrom=fastmail.com; dkim=pass header.d=fastmail.com header.i=@fastmail.com header.a=rsa-sha256 header.s=fm3 header.b=iyZkhrno; dkim=pass header.d=messagingengine.com header.i=@messagingengine.com header.a=rsa-sha256 header.s=fm3 header.b=ZtdwenvF; arc=none smtp.remote-ip=103.168.172.154 Received: from fhigh-a3-smtp.messagingengine.com (fhigh-a3-smtp.messagingengine.com [103.168.172.154]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 36AF6606A322 for ; Thu, 3 Dec 2026 23:44:05 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 36AF6606A322 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=fastmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=fastmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=fastmail.com header.i=@fastmail.com header.a=rsa-sha256 header.s=fm3 header.b=iyZkhrno; dkim=pass (2048-bit key, unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.a=rsa-sha256 header.s=fm3 header.b=ZtdwenvF Received: from phl-compute-05.internal (phl-compute-05.internal [10.202.2.45]) by mailfhigh.phl.internal (Postfix) with ESMTP id 5D497140017B for ; Thu, 3 Dec 2026 18:44:04 -0500 (EST) Received: from phl-frontend-03 ([10.202.2.162]) by phl-compute-05.internal (MEProxy); Thu, 03 Dec 2026 18:44:04 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fastmail.com; h= cc:cc:content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1796341444; x=1796427844; bh=Z5i4g+ILTU +LweznsUBbu+VY3MJBcwZmf5LWDxw8p4U=; b=iyZkhrnoa+ymMasdvp5llkuTXf GPiEnT2ENreClZWGd+5lXCpg+wEilvFsMoUm2gEpJdj41WBtWBuiHL4+vN27Ro7r 2KWU3YJcjiQ1Cw0MoQSpW1iy3XEwObeyHFbENqgi80uYF4HSvXxDizVWfNEOAEHq 8/1DHRjDO/XYVf3j9YYOnj8eFNWalFsUYMcOiT4vFb1pGctgYtSPFi39V+w21WAD ycKlkhpTpkQLUt4fFVRl0PogWVD9dyiuL+lFw+7e/1zJSpHQ27rHvdhGr2vHgSfw 9/MV6LXT5nNffAVKvEnneEQcBoxKRXxIlFMTyt3H+Sc65NUU+36PcI5ILxVA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm3; t= 1796341444; x=1796427844; bh=Z5i4g+ILTU+LweznsUBbu+VY3MJBcwZmf5L WDxw8p4U=; b=ZtdwenvFwOU4ZBqI5ZzR7NzvVVolJSSUXy8EweGXQ71SYwTYdAi +hIyw8ae6KG77wr9LAMseM+1xsn+TE824eJD2adTmNgP6BOdueT3IobQ+B+Ixj/b KDosWlTsSrfzMQXfTJHW0cMcsQuyoxlWjhcilFB/G98cUO6Nxt7YUvzFK0Vxh2MM 45BBWMkm7Omu/Ceut1ZGo3oy41vvQZQa1FhBkQGNFOuEF/GUbskkKopItM4OqD98 PcHTwzXCrzBvQpH2KYZs+kIP5k/Z6PZO559CkVAvsldUqq4GGhoyS7FefeA41c6o Ql/H2BjzdTuBdbQpBOx13IVBSqjucwtG+mw== X-DKIM2-Info: draft=ietf-dkim-dkim2-spec-09; repo=github.com/dkim2wg/interop; date=2026-11-03; sw=lmtpprox; action=sign d=fastmail.com a=rsa-sha256; DKIM2-Signature: i=1; m=1; t=1796341444; d=fastmail.com; mf=PGp1YW5sdUBmYXN0bWFpbC5jb20+; rt=PGxpbnV4LWtzZWxmdGVzdEB2Z2VyLmtlcm5lbC5vcmc+; s=fm3:rsa-sha256:P5zmOSFRSmgpXGr7UZ0561gvPbLGrOhIzrbR8AeYhCgzEH/ pgLENieJ6IleU90m9EkT9beGVbCzwfzhjSaKz6ea0oCelqc495zWuWWfEWlymDJD Z7ZR63f91VXqUDI8hzdOkfLIiGYJQU96EoSzO4zf4STWhikt4o4gzUa5sxcSXDmF xBdlYAoHmli0xDE0bQ1ubAg8BrYNjngz1MM3YfjACSANe72ylNaESGQ4adog/tbK WlRACx0whHlM8EIrz6g9Cy5d1gcjgoB/spV1FpyQ8eBT1EAp7DTDHbT5mS/v5pqS GzdlbURWpm4mmaIovIyq1OuU25hMIkvCKbCvOJQ==; X-DKIM2-Info: draft=ietf-dkim-dkim2-spec-09; repo=github.com/dkim2wg/interop; date=2026-11-03; sw=lmtpprox; action=mi-m=1; hc=12; hn=cc,content-disposition,content-type,date,feedback-id,from, in-reply-to,message-id,mime-version,references,subject,to; Message-Instance: m=1; h=sha256:W358eN5kEL+On1uqf18gmLVITKgSnXCIB3MPBm6hqYI=:o6OeLmwBKvovNKOVUQFXp/yKVFv9PDBb+IDP6/CFl7o=; X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: dmFkZTE00PczsCnFyn8FJfTIqoZTdjIWK3L5C0xxT7hDDrCUCnBxzTPFIh6S1y2HX/9JJe v8uivLJLnT8Gwq5xuX0bjrhYieIygY/3h1aZBmwAoYX0ES7ZST3HSRM6k/85cC/TpRqs4S +twK5r1k40szou1VlWPrIrKXuo0Ov+Lqji3talmDL8ECBJVMWch+qR/bp4PYIVQWNtrVt9 kbSAG1IZhS4MFtfhuecuczCWqBmIRxAFB7faZ0riO6CG2HHX9THUwYdJANVkWmS5ZWzZH3 7jr/n07euvvZfcc9r+j9eGHouXlspNLHSyYa6gxd/MslkWU42L4DCLAHEcSqhEzHNIfzhE Yeu/42Kqf5XO+RNYzWb2Id3La/YUOX6vSPhSvBn73+Wt8JlL4PYxycOXz8sjnPjfvoVook y+SRtEL4tgkBZhqImW8adMZkYeqwHC5spiPPIa+pG0OS8aLnj/qQcfyuiLHxDW2H4eN4oi N4ra6SWMfedGvIN2RFHzFCKtn1L51Hp76uAwTQ8kJ9URWrS89C7VEuHrBkKJ0DNUcpRUbw unwViEQ3XBp+4uIYv8203NOmrxuv2tHOi6bLHeFBjuzzs2EJTHIgRx+8syQL+B5/Eca9sh Y13yLQetV4GrhwGIFVftGL/PDPxGKgFoTxkjcW6ftVLDF/jc6Elbmgc3Zzwg X-ME-Proxy: Feedback-ID: i80b64ba7:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 3 Dec 2026 18:44:03 -0500 (EST) Date: Thu, 3 Dec 2026 15:44:02 -0800 From: Juanlu Herrero To: Robin Murphy Cc: Andrew Lunn , "David S. Miller" , Jakub Kicinski , Paolo Abeni , Shuah Khan , Marek Szyprowski , Eric Dumazet , netdev@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, iommu@lists.linux.dev Subject: Re: [PATCH 2/3] dma-debug: skip irrelevant buckets for partial syncs Message-ID: References: <20261110-zcrx-dma-debug-registration-v1-0-48743ea61631@fastmail.com> <20261110-zcrx-dma-debug-registration-v1-2-48743ea61631@fastmail.com> <41001cf2-6304-45ff-977f-ac1b66ecf559@arm.com> X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <41001cf2-6304-45ff-977f-ac1b66ecf559@arm.com> On Thu, Dec 03, 2026 at 05:38:58PM +0000, Robin Murphy wrote: > On 2026-11-10 9:36 pm, Juanlu Herrero wrote: > > Partial syncs may start after a mapping's first hash bucket. Finding the > > mapping then requires locking earlier buckets. > > > > Keep a conservative size bound per bucket and skip those that cannot > > span the sync range. Raise the bound on insertion and reset it when the > > bucket empties. Stale larger bounds only add searches, so removal needs > > no list rescan to update the bound. > > > > This relies on ordered map publication before sync and unmapping after > > sync. The bucket lock carries earlier bound updates through later > > insertions even when the bound is unchanged. > > Doesn't this then run the risk of then mis-reporting a sync/unmap with a > larger-than-mapped size? The whole point of dma-debug is to catch bad API > usage, so obviously it cannot rely on callers being correct. It is an > explicit choice for developers who want to check correctness and accept the > massive performance impact of doing so, so any reduction of > robustness/coverage for the sake of making the inherently slow thing a > little less slow seems like a wrong move, and rather missing the point. > > Thanks, > Robin. > > Signed-off-by: Juanlu Herrero > > --- > > kernel/dma/debug.c | 49 +++++++++++++++++++++++++++++++++++++++---------- > > 1 file changed, 39 insertions(+), 10 deletions(-) > > > > diff --git a/kernel/dma/debug.c b/kernel/dma/debug.c > > index 4cb5f86a7228a..8dad45d0a4360 100644 > > --- a/kernel/dma/debug.c > > +++ b/kernel/dma/debug.c > > @@ -90,6 +90,8 @@ typedef bool (*match_fn)(struct dma_debug_entry *, struct dma_debug_entry *); > > struct hash_bucket { > > struct list_head list; > > spinlock_t lock; > > + /* Upper bound on live mapping sizes; reset when the bucket empties. */ > > + unsigned long max_entry_size; > > }; > > /* Hash list to save the allocated dma addresses */ > > @@ -354,27 +356,49 @@ static struct dma_debug_entry *bucket_find_contain(struct hash_bucket **bucket, > > struct dma_debug_entry *ref, > > unsigned long *flags) > > { > > - > > struct dma_debug_entry *entry, index = *ref; > > + u64 min_offset = (index.dev_addr & ((1ULL << HASH_FN_SHIFT) - 1)) + 1; > > int limit = min(HASH_SIZE, (index.dev_addr >> HASH_FN_SHIFT) + 1); > > - for (int i = 0; i < limit; i++) { > > + entry = __hash_bucket_find(*bucket, ref, containing_match); > > + if (entry) > > + return entry; > > + put_hash_bucket(*bucket, *flags); > > + > > + for (int i = 1; i < limit; i++) { > > + unsigned long max_entry_size; > > + > > + index.dev_addr -= (1 << HASH_FN_SHIFT); > > + *bucket = &dma_entry_hash[hash_fn(&index)]; > > + /* > > + * Writers serialize updates with the bucket lock. For any entry > > + * that can validly match this sync, publishing the mapping is > > + * ordered before the sync, including a cross-CPU handoff, and > > + * unmapping is ordered after it. The bound only grows while the > > + * bucket is nonempty, so it cannot become smaller than a live > > + * entry. Removing an unrelated mapping may leave a larger bound, > > + * which only causes an unnecessary search. > > + */ > > + max_entry_size = READ_ONCE((*bucket)->max_entry_size); > > + /* The mapping must span the distance back to this bucket. */ > > + if (max_entry_size < ref->size || > > + max_entry_size - ref->size < min_offset) > > + goto next; > > + > > + *bucket = get_hash_bucket(&index, flags); > > entry = __hash_bucket_find(*bucket, ref, containing_match); > > if (entry) > > return entry; > > - /* > > - * Nothing found, go back a hash bucket > > - */ > > put_hash_bucket(*bucket, *flags); > > - index.dev_addr -= (1 << HASH_FN_SHIFT); > > - *bucket = get_hash_bucket(&index, flags); > > +next: > > + min_offset += 1ULL << HASH_FN_SHIFT; > > } > > + *bucket = get_hash_bucket(ref, flags); > > return NULL; > > } > > - > > /* > > * Add an entry to a hash bucket > > */ > > @@ -382,14 +406,19 @@ static void hash_bucket_add(struct hash_bucket *bucket, > > struct dma_debug_entry *entry) > > { > > list_add_tail(&entry->list, &bucket->list); > > + if (entry->size > bucket->max_entry_size) > > + WRITE_ONCE(bucket->max_entry_size, entry->size); > > } > > /* > > * Remove entry from a hash bucket list > > */ > > -static void hash_bucket_del(struct dma_debug_entry *entry) > > +static void hash_bucket_del(struct hash_bucket *bucket, > > + struct dma_debug_entry *entry) > > { > > list_del(&entry->list); > > + if (list_empty(&bucket->list)) > > + WRITE_ONCE(bucket->max_entry_size, 0); > > } > > /* > > @@ -1100,7 +1129,7 @@ static void check_unmap(struct dma_debug_entry *ref) > > } > > #undef DMA_ATTR_UNMAP_VALID > > - hash_bucket_del(entry); > > + hash_bucket_del(bucket, entry); > > put_hash_bucket(bucket, flags); > > /* > > > Hi Robin, thanks for raising those concerns. I checked the oversized-request behavior and unmap still uses the same exact-address lookup and map/unmap size comparison. For oversized syncs, containing_match() already rejects the mapping and error reported is still "memory it has not allocated." With LLM assistance, I A/B tested the patch and all instances reported the same error count while only in 1 case (when the requested sync's address + size overflows) reports a different error ("outside allocated range" vs "memory it has not allocated"). I can add in v2, kunit tests covering oversized sync/unmap! Do you consider the diagnostic change a regression that needs addressing? -- Juanlu Herrero