From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=217.140.110.172 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== 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== 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 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) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 995DC606A32C Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com 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 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) 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) 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= Message-ID: <41001cf2-6304-45ff-977f-ac1b66ecf559@arm.com> Date: Thu, 3 Dec 2026 17:38:58 +0000 X-Mailing-List: netdev@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 2/3] dma-debug: skip irrelevant buckets for partial syncs To: Juanlu Herrero , Andrew Lunn , "David S. Miller" , Jakub Kicinski , Paolo Abeni , Shuah Khan , Marek Szyprowski , Eric Dumazet Cc: netdev@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, iommu@lists.linux.dev References: <20261110-zcrx-dma-debug-registration-v1-0-48743ea61631@fastmail.com> <20261110-zcrx-dma-debug-registration-v1-2-48743ea61631@fastmail.com> From: Robin Murphy Content-Language: en-GB In-Reply-To: <20261110-zcrx-dma-debug-registration-v1-2-48743ea61631@fastmail.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit 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); > > /* >