🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #14609

Re: [PATCH v3] libcxgb: use raw_cpu_ptr() in ppm_get_cpu_entries()

#14609
From: netdev-bot+sashiko
Date: Wed, 11 Nov 2026 16:08
128 lines
12530 bytes
Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.

Critical: 0 · High: 1 · Medium: 0 · Low: 1

If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).

- [High] The patch changes how ppm_get_cpu_entries() encodes the global
  ppod index but leaves the release path decoding it the old way.
- [Low] The commit fixes a user-visible PREEMPT_RT bug in
  ppm_get_cpu_entries()…

--

libcxgb: use raw_cpu_ptr() in ppm_get_cpu_entries()

The commit removes the get_cpu()/put_cpu() pair around spin_lock_bh() in
ppm_get_cpu_entries(), so the code no longer takes a sleeping lock with
preemption disabled on PREEMPT_RT. It reads the pool with raw_cpu_ptr().
It also builds the global ppod index from a new pool->base, set in
ppm_alloc_cpu_pool(), instead of cpu * pool_index_max.

> diff --git a/drivers/net/ethernet/chelsio/libcxgb/libcxgb_ppm.c b/drivers/net/ethernet/chelsio/libcxgb/libcxgb_ppm.c
> index 2e3973a32d9d1..7fb6c8a41e98f 100644
> --- a/drivers/net/ethernet/chelsio/libcxgb/libcxgb_ppm.c
> +++ b/drivers/net/ethernet/chelsio/libcxgb/libcxgb_ppm.c
> @@ -119,16 +119,13 @@ static int ppm_get_cpu_entries(struct cxgbi_ppm *ppm, unsigned int count,
>  			       unsigned long caller_data)
>  {
>  	struct cxgbi_ppm_pool *pool;
> -	unsigned int cpu;
>  	int i;
>  
>  	if (!ppm->pool)
>  		return -EINVAL;
>  
> -	cpu = get_cpu();
> -	pool = per_cpu_ptr(ppm->pool, cpu);
> +	pool = raw_cpu_ptr(ppm->pool);
>  	spin_lock_bh(&pool->lock);
> -	put_cpu();

[Severity: Low]
This isn't a bug, but should the patch have a Fixes: tag? The sequence
get_cpu(); per_cpu_ptr(); spin_lock_bh(); put_cpu(); dates back to the
original page pod manager, before the file moved to libcxgb:

Fixes: 47da7e62b391 ("cxgb4: add iSCSI DDP page pod manager")

>  
>  	i = ppm_find_unused_entries(pool->bmap, ppm->pool_index_max,
>  				    pool->next, count, 0);
> @@ -145,10 +142,10 @@ static int ppm_get_cpu_entries(struct cxgbi_ppm *ppm, unsigned int count,
>  	spin_unlock_bh(&pool->lock);
>  
>  	pr_debug("%s: cpu %u, idx %d + %d (%d), next %u.\n",
> -		 __func__, cpu, i, count, i + cpu * ppm->pool_index_max,
> -		pool->next);
> +		 __func__, pool->base / ppm->pool_index_max, i, count,
> +		i + pool->base, pool->next);
>  
> -	i += cpu * ppm->pool_index_max;
> +	i += pool->base;
>  	ppm_mark_entries(ppm, i, count, caller_data);
>  
>  	return i;
> @@ -375,6 +372,7 @@ ppm_alloc_cpu_pool(unsigned int *total, unsigned int *pcpu_ppmax)
>  
>  		memset(ppool, 0, alloc_sz);
>  		spin_lock_init(&ppool->lock);
> +		ppool->base = count;
>  		count += ppmax;
>  	}

[Severity: High]
Does the new encoding still match the release path?

ppm_alloc_cpu_pool() walks the pools with for_each_possible_cpu(), so
pool->base is the CPU's position in cpu_possible_mask times ppmax. It is
not cpu * ppmax. ppm_get_cpu_entries() now returns i + pool->base.

ppm_unmark_entries() is unchanged and still treats that value as a CPU
id:

drivers/net/ethernet/chelsio/libcxgb/libcxgb_ppm.c:ppm_unmark_entries() {
    ...
		cpu = i / ppm->pool_index_max;
		i %= ppm->pool_index_max;

		pool = per_cpu_ptr(ppm->pool, cpu);
		spin_lock_bh(&pool->lock);
		bitmap_clear(pool->bmap, i, count);
    ...
}

If cpu_possible_mask has no holes, position and CPU id are the same.
If it has holes, they differ.

With possible = {0,2,3}, CPU 3 is at position 2. So
cxgbi_ppm_ppod_release()->ppm_unmark_entries() clears CPU 3's entries in
CPU 2's pool:

- CPU 3's bits are never freed.
- CPU 2 can hand out an index that is still in use, so two live DDP tags
  could share one hardware page pod.

With possible = {0,2}, CPU 2's entries decode to cpu 1, which is not a
possible CPU. per_cpu_ptr(ppm->pool, 1) then points at a slot that was
never memset() or spin_lock_init()'d. The code takes a lock in it and
clears bits in it.

The new pr_debug() above also prints this position as "cpu".

The v1 changelog says "ppm_unmark_entries() derives the owning pool from
the index itself". After this patch, the index it decodes no longer
matches how ppm_get_cpu_entries() builds it.

Should ppm_unmark_entries() be updated as well? For example, it could
find the possible CPU whose [base, base + pool_index_max) range holds
the index, or the owning CPU could be recorded.

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261109180748.33682-1-haoranwangsec%40gmail.com
Technical Details
Message-ID: <179441329408.2199510.4180666422903927699@kernel.org>
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-361165-linux-kernel-netdev=dewy.ru
References: <20261109180748.33682-1-haoranwangsec@gmail.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-361165-linux-kernel-netdev=dewy.ru
From: netdev-bot+sashiko@kernel.org
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH v3] libcxgb: use raw_cpu_ptr() in ppm_get_cpu_entries()
Date: Wed, 11 Nov 2026 16:08:14 +0000
Organization: Usenet Network
Message-ID: <179441329408.2199510.4180666422903927699@kernel.org>
References: <20261109180748.33682-1-haoranwangsec@gmail.com>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="891100"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:7cT4P0prlF6zby20uYHIe7d8JYs= sha256:GQaJ0iJvCdzvKbZOTi6NMwn6xaM1ZmKFI3VoqquA4ak=
	sha1:pSyBLjIY8NUToSG+HrtIt+2WibM= sha256:6eO5MBdLQynFy0WL1dYTzJIZ+oD4ig4rcnQew0yJx7E=
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 5E9D8113F4B; Wed, 11 Nov 2026 19:15:10 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.4
X-Spam-Status: No, score=-3.4 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1,
	DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1,
	MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001,
	SPF_PASS=-0.001, URIBL_BLOCKED=0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
	header.d=kernel.org
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 OWZRz6trIm6W;
	Wed, 11 Nov 2026 19:15:01 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-361165-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org
X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
	by mail.dewy.ru (Postfix) with ESMTPS id 78AE6113F38; Wed, 11 Nov 2026 19:14:52 +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 04C9C161571; Wed, 11 Nov 2026 16:08:19 +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=1794413296;
	b=w0o4IX64uEIchrNR1FHdUtY7kL6RdVmAv0faeYTl2J4Os2p0yGnRafuytuSSk6kAoXB7
	 j9WaHlOo+pG7ckLYk2Pa4LNP/eWvtUXWfWyrlN49y29lHW8OTMA5eEIemZ+nfz8CouuQa
	 /iB1jyA2sh5Y3zXV3fxbxJcnO9eM39kXFQI9yQQuzFxoA4PooQOizPnAWKYKDZ10X9+cq
	 topeYJFIfVIIgi/hWKxJ3HteCw3FopLwa3mhlLr0fNCPvE43KT7eOZ61Y8zGMWz4hO1DC
	 +rCVtp3zuXSqITK9y0aDnwoaqSJYedLlMBO+0R/TrB7chwsBM5OLAdLdU5RlBpP3fAQ==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1794413296;
	h=X-Original-To:Received:Received:DKIM-Signature:Subject:From:To:Cc:
	 Date:Message-ID:In-Reply-To:References:X-sashiko-severity:
	 Content-Type:Content-Transfer-Encoding:X-Mailing-List:List-Id:
	 List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner:
	 Precedence:MIME-Version;
	bh=bqR+F5Cu2cpA5OZAVf1AXWWlYtWd7xJLjOh702/W4M8=;
	b=m4O5vJro154p1AH7cjbm6pkzgb9L+DzEDgbPw3w5PsNoaCSyxhKf9+wp3pUSwEMV3IPE
	 c8Vgep/+SOeQwYLU5rUDzTmHeY0yXRCwuFi+kD7iwtoihBRVnvf1Z6bJ+84F/7oMN0pQZ
	 3lLKfqM05G7R7q1PzgYhP7tVBT0NC86XXxBmhlFXnlBNlUIjka51OvUZ7Tnu99GlfAuOu
	 KrVNpv6Ei1NESsrVC1/cIe5J/pdBe0/FvZF/Hq3of+otIVpWiwP0+IvY4PxACnGnYl/ix
	 vAzR4q970ZjvPC1QDI1/R0wXDmCDZ2bAUCeMAI/PLv1hRZhJJIvwxXeFlOteqH3FN3g==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=dWx0jylW;
	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 573C6606A33E;
	Wed, 11 Nov 2026 16:08:16 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=dWx0jylW
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1794413295;
	b=fJxcTJpR0S9/j94aVA4pnDLtkojYQWzyKKU5e09ZFXxoif0imepKi2DffcI8Ovn71ykG
	 UiPjY7+zy0w7yuddfyriGo/TnXRMmNU3D0NBGVzbCgKAr/ulqTsFGWuduYBQmkuIVKmlZ
	 6bAFoda6RFnjMGD3xP3+htEi2zCrnRHgZ6U8utoR7Wl8dZJl35fxint7XBscvIbMbpe7c
	 kdEc+5JwJx5O5eSfO9LG790yfpa1iPW2Kx8tWNzZANts9nbtogR4wYLaslAdMTYJlRjPI
	 KUUG+/UjSIKdTg7AN2ykFIbSf7uAEUB6LQJ4CdpmuCJwovIpLPnBmEuiYAUFG56hN+g==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1794413295;
	h=Received:DKIM-Signature:Subject:From:To:Cc:Date:Message-ID:
	 In-Reply-To:References:X-sashiko-severity:Content-Type:
	 Content-Transfer-Encoding:MIME-Version;
	bh=bqR+F5Cu2cpA5OZAVf1AXWWlYtWd7xJLjOh702/W4M8=;
	b=UeFE9AorQfjnX+DL1ooMFh7ToLtQWaHQrJcyIPzNgjoioTUkBBoR8hGPtG246Tkgebvz
	 VkAgN49Y4tbCwUTFLIy6q8HxqEMt6u0kHZBr93+hYiVJhKM7IY2H4lyAADW87hSGYJ8tz
	 2ukrNE5z0qaajtaxYXtrZTGz+TqkO6c81i1HFK4SN/rg7tJqwlE6epsHoE0E8Pjst366Y
	 NDcMITmKUf3YxjVp0re/kR42NznivloXnk6eBW2M3oHvi4PtwrMm9GtOk0qqTpD6Gn/WR
	 kLzSddQeen8ntai4gJgiPOnrLBMmbszlmrRVFNSglsm6YjYbziiLdjTubzHRuK92MPA==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=dWx0jylW;
	arc=none smtp.remote-ip=100.103.45.18
X-Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature ECDSA (prime256v1))
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id 75310606A321;
	Wed, 11 Nov 2026 16:08:15 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8B0A31F00A07;
	Wed, 11 Nov 2026 16:08:14 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1794413295;
	bh=bqR+F5Cu2cpA5OZAVf1AXWWlYtWd7xJLjOh702/W4M8=;
	h=Subject:From:To:Cc:Date:In-Reply-To:References;
	b=dWx0jylWZSrsY/6pvcQw2KjLLIT/sFqNulj9Q3oSOlS3VkE/LN1p+2124qDB3+kc+
	 yF/9BugE86YznVa4A4huWrcyNqnO1cMlL9D4cK4XV7fQwSuzSa4p4jBB5gVNbR9wc7
	 Y0gRq4FyPWrEHdQ+6UvOPXrCAuVONfAsZ2ntNLJvprLe8tYim50xzqmPbC6EHs+uVV
	 dd2gtaMcyoeJeof8Vj3xPZ7a8ooiFXd4EIAJAngv+WjgQF0IHp0TVfu1tiqeydcCSL
	 lNlQd/ys5aaUVulcNG7Z+MvLP+jqlvEmLm8K7ynrs60UxzQq6xw/XsjvyLbaiRNJA9
	 OCReJ69uGWJzg==
X-Cc: bigeasy@linutronix.de, netdev@vger.kernel.org,
 linux-kernel@vger.kernel.org, linux-rt-devel@lists.linux.dev,
 andrew+netdev@lunn.ch, davem@davemloft.net, edumazet@kernel.org,
 kuba@kernel.org, pabeni@redhat.com, rostedt@goodmis.org
X-In-Reply-To: <20261109180748.33682-1-haoranwangsec@gmail.com>
X-sashiko-severity: High
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