🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #26524

Re: [PATCH 2/3] dma-debug: skip irrelevant buckets for partial syncs

#26524
From: Robin Murphy
Date: Thu, 03 Dec 2026 17:38
131 lines
13001 bytes
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 <juanlu@fastmail.com>
> ---
>   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);
>   
>   	/*
> 
Technical Details
Message-ID: <41001cf2-6304-45ff-977f-ac1b66ecf559@arm.com>
Path: mbox-mo1.pugleaf.net!news-fra.pugleaf.net!feed-eu-txt.newsdeef.eu!feed-eu-ch.newsdeef.eu!srl.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-376787-linux-kernel-netdev=dewy.ru
References: <20261110-zcrx-dma-debug-registration-v1-0-48743ea61631@fastmail.com> <20261110-zcrx-dma-debug-registration-v1-2-48743ea61631@fastmail.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-fra.pugleaf.net!feed-eu-txt.newsdeef.eu!feed-eu-ch.newsdeef.eu!srl.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-376787-linux-kernel-netdev=dewy.ru
From: robin.murphy@arm.com (Robin Murphy)
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH 2/3] dma-debug: skip irrelevant buckets for partial syncs
Date: Thu, 3 Dec 2026 17:38:58 +0000
Organization: Usenet Network
Message-ID: <41001cf2-6304-45ff-977f-ac1b66ecf559@arm.com>
References: <20261110-zcrx-dma-debug-registration-v1-0-48743ea61631@fastmail.com>
 <20261110-zcrx-dma-debug-registration-v1-2-48743ea61631@fastmail.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Info: usenet.network;
	logging-data="2555971"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:yFWiZQzymMwi2UutgLmlfkvSIBQ= sha256:pMD3x9f6R+/y0hKRars6HjW1GNcXKforjKQK1FugJSs=
	sha1:duKXz4R+fF1NZCoCKFlI5FMyGVc= sha256:9cqveLxAryvW7hwRa8ozW6+KB1PrMSbf7g4WF055ZDc=
Content-Language: en-GB
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
	by mail.dewy.ru (Postfix) with ESMTP id 6D42A1179ED; Thu,  3 Dec 2026 20:39:53 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -2.999
X-Spam-Status: No, score=-2.999 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIM_INVALID=0.1, DKIM_SIGNED=0.1,
	HEADER_FROM_DIFFERENT_DOMAINS=0.001, MAILING_LIST_MULTI=-1,
	RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001]
	autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=neutral
	reason="invalid (public key: DNS error: query timed out)"
	header.d=arm.com
X-Received: from mail.dewy.ru ([127.0.0.1])
	by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id UHbtbRuN18zy;
	Thu,  3 Dec 2026 20:39:41 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-376787-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=none (p=none dis=none) header.from=arm.com
X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
	by mail.dewy.ru (Postfix) with ESMTPS id 878201179E9; Thu,  3 Dec 2026 20:39:23 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by sea.lore.kernel.org (Postfix) with ESMTP id 2511A27665; Thu,  3 Dec 2026 17:39:22 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
	t=1796319562;
	b=e1gKIdX1VA6Es7RM611qJKfVUKaAVLHjXC6Es5XkQ5X1/Xs5h2kup135gg8Nnxa8PWap
	 +r5kx2oOummWrt09qjFd0UUZhyAlgFyyujC2gtNoNNfvOlwOI4c46ajTTa8TClmXmPqjn
	 ULtDjASDv4BjcgZQaPuW+E24hmLqHefS6567g2IO34CskXLZFHxHO/MWKRKmQxZ/lwKm1
	 mjWbeEB2LPZ+7bZ+BMxQToS4RLktoq5CVtvRmb0RJYoju+uhmyGMkdre1nkT4tInjNgUf
	 OccwbluTBrxYKqm0pcUNk+YoglPFvj6M9oMaqIxxn7Pp/t/c0oJp1FDDg7+zNE8Pf3g==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796319562;
	h=X-Original-To:Received:DMARC-Filter:Received:Received:DKIM-Signature:
	 Message-ID:Date:X-Mailing-List:List-Id:List-Post:List-Help:
	 List-Subscribe:List-Unsubscribe:List-Owner:Precedence:MIME-Version:
	 User-Agent:Subject:To:Cc:References:From:Content-Language:In-Reply-To:
	 Content-Type:Content-Transfer-Encoding;
	bh=/33f2Rl5k1qrNqmq0Tb+jopzMIQSy9NV1hSeHIKFdDc=;
	b=JDD2xGJjhegsBE8x1kGxUFyv2bS2IKHD/jcZ8NVoGAselBlDOVkzbYnab6ySrDvl2tSQ
	 d+gMRT5R5ayC0UkZZwuGgjr62hbZ8FMN/Ev7mn1WX+MhRsZMMMy030IE6ORBOKwacorcn
	 h/TSMs4nHg3++rIScV77L5F3doYenaQLlqkHTpO0ReQWBusTzoy9lWouXGfnWzud+5pss
	 1PZecxErRgj/Xa1qZe7iRaDCvwDQadb4PIvPs+5i8bYtWpuGVTgqAXT7L9JHex1FMFQrH
	 WYcvkjYfleMAYl0ediF9DGxV3HhnhVkjTcL4EBZriWau27K5PHaWJmuX09vSXan5vKw==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=arm.com header.i=@arm.com header.a=rsa-sha256 header.s=foss header.b=bYJuUrUn;
	dmarc=pass header.from=arm.com;
	spf=pass smtp.mailfrom=arm.com;
	arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
	by smtp.subspace.kernel.org (Postfix) with ESMTP id F0B95606A333;
	Thu,  3 Dec 2026 17:39:21 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.a=rsa-sha256 header.s=foss header.b=bYJuUrUn
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=217.140.110.172
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1796319551;
	b=sV4+TEqTJZq/QDkCpdkPjS9cNrhtLcl8pO+9k+Q+2WjB3/gyhZYZmbo5S9Pi8Teq4sAv
	 wqD9BHSwezPiAOvjs3wkXMTtKQv5KWleP4TIV7P11JAwQxegbC7yHcv5eH7CQrSBj6aQQ
	 8B6sguGWvy1P7DY66uOsiWjFBOmmy8XukzgVa3EEMhw0kvPUK3ZR3MpdcPQHSdH+UGH1J
	 Z8G8zr5w1IWkHwo3do7PcxviWdjyhYwvP0kKWMonLKosdD0gnKphpacrEH2F5ml8ecwL1
	 yaltyOfeJUnmCm51S3AmsLFRGj/CnLXzEx/1+audmVImF74e3yDC2uet55l2tBztaiA==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796319551;
	h=DMARC-Filter:Received:Received:DKIM-Signature:Message-ID:Date:
	 MIME-Version:User-Agent:Subject:To:Cc:References:From:
	 Content-Language:In-Reply-To:Content-Type:Content-Transfer-Encoding;
	bh=/33f2Rl5k1qrNqmq0Tb+jopzMIQSy9NV1hSeHIKFdDc=;
	b=kp6QAb2qMtb+0Wkq3jB6YL4dDXVxgt2v+lebc4FPm4jhXzH66YAzOslRU1QT1cfd16b9
	 ovUcVkBJJMKlXOSxPfYr91ErXWGKL1/HtWrw2byn5iezU+kcoZU8gNavKvKZ7z00yXOnd
	 1zmWcoFng8l+WFX68fWD20QOw+HMzetyNYCZA2qeMhLAbviaiuaR6W5VL3I2ESJvR6ZdC
	 gvFvrLdkLoPy2zVt1etQZDvmHtlZ0uqQfp64Kk0FujfTd0zAkMqhKTBgFET43b63Fcqz/
	 trXP3J5itBwMDlAiYpCzgs9eLCyxwS8ECrIahm7r5Ni1c5Csv/V9rNRIdaHbE4fRm4w==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dmarc=pass header.from=arm.com;
	spf=pass smtp.mailfrom=arm.com;
	dkim=pass header.d=arm.com header.i=@arm.com header.a=rsa-sha256 header.s=foss header.b=bYJuUrUn;
	arc=none smtp.remote-ip=217.140.110.172
X-Received: from foss.arm.com (foss.arm.com [217.140.110.172])
	by smtp.subspace.kernel.org (Postfix) with ESMTP id 995DC606A32C;
	Thu,  3 Dec 2026 17:39:10 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 995DC606A32C
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com
X-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 28BAF1477;
	Thu,  3 Dec 2026 09:39:07 -0800 (PST)
X-Received: from [10.57.93.206] (unknown [10.57.93.206])
	by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 520F23F7D8;
	Thu,  3 Dec 2026 09:39:02 -0800 (PST)
X-DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=arm.com; s=foss;
	t=1796319549; bh=TESBB4vt1NiCTOaONaw1wnvDg5MI8qPEUsPgIG6qubQ=;
	h=Date:Subject:To:Cc:References:From:In-Reply-To:From;
	b=bYJuUrUnTCDROtMyMmqKrrmPt8FOquGcUr0AxLnyT3iCP5OfYMk/Rjng0fT9ANr9V
	 6QcfGwpZeZEmFaIDpfuC/JvD3iS+lZHsjWmNA1nCK7DFsxG9xVl/1K4zPoG8WhKoBb
	 WnKyYuPz1chM24ebzC0iQ7yk6FI8caMww8nOWQhg=
X-Mailing-List: netdev@vger.kernel.org
X-List-Post: <mailto:netdev@vger.kernel.org>
X-List-Help: <mailto:netdev+help@vger.kernel.org>
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:netdev+owner@vger.kernel.org>
X-Precedence: list
X-User-Agent: Mozilla Thunderbird
X-Cc: netdev@vger.kernel.org, linux-kselftest@vger.kernel.org,
 linux-kernel@vger.kernel.org, iommu@lists.linux.dev
X-In-Reply-To: <20261110-zcrx-dma-debug-registration-v1-2-48743ea61631@fastmail.com>