🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #12564

Re: [PATCH rdma-next 15/23] RDMA/core: Set the CQ comp_handler after its poll context is set up

#12564
From: netdev-bot+sashiko
Date: Sat, 07 Nov 2026 20:24
152 lines
13944 bytes
Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.

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

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 relies on program order alone to publish the poll
  context before the handler, and that ordering does not hold for…
- [Medium] __ib_alloc_cq() (drivers/infiniband/core/cq.c) still stores
  cq->comp_handler after dev->ops.create_cq() has returned (create_cq at…

--

RDMA/core: Set the CQ comp_handler after its poll context is set up

This commit reorders __ib_alloc_cq(). The irq_poll or work context and
comp_wq are now initialized before cq->comp_handler is stored, and the CQ
is armed only after the handler is set. The goal is that a completion
event raised right after ops.create_cq() returns no longer finds an
uninitialized poll context.

> diff --git a/drivers/infiniband/core/cq.c b/drivers/infiniband/core/cq.c
> index 12304c9a9403e..42e4d272f5ade 100644
> --- a/drivers/infiniband/core/cq.c
> +++ b/drivers/infiniband/core/cq.c

[ ... ]

> @@ -269,6 +267,15 @@ struct ib_cq *__ib_alloc_cq(struct ib_device *dev, void *private, int nr_cqe,
>  		goto out_destroy_cq;
>  	}
>  
> +	/*
> +	 * The CQ is reachable from the completion interrupt once created. Set
> +	 * the handler only after the poll context it schedules is set up, and
> +	 * arm the CQ only after that.
> +	 */
> +	cq->comp_handler = comp_handler;

[Severity: Medium]
This store still runs after dev->ops.create_cq() has returned. By then, can
the driver's EQ dispatch already reach the CQ while comp_handler is still
NULL from rdma_zalloc_drv_obj()?

The driver publishes the CQN during create_cq. For example,
mlx5_core_create_cq()->mlx5_eq_add_cq() inserts it into the radix tree,
efa stores it in dev->cqs_xa, and mthca adds it to cq_table.

Several drivers then call the handler without a NULL check. For example,
in drivers/infiniband/hw/mlx4/cq.c:

static void mlx4_ib_cq_comp(struct mlx4_cq *cq)
{
	struct ib_cq *ibcq = &to_mibcq(cq)->ibcq;
	ibcq->comp_handler(ibcq, ibcq->cq_context);
}

efa_process_comp_eqe() and mthca_cq_completion() do the same, and so does
mlx5_ib_cq_comp() at this commit.

So an early event from a non-conforming device would now be a NULL
function pointer call in irq or tasklet context, instead of scheduling an
uninitialized irq_poll or work. The patch also moves the store later than
before, past rdma_dim_init() (which can do a GFP_KERNEL allocation) and the
whole poll context switch, so the window gets a bit longer.

The commit message says:

    A conforming device raises no event for a new,
    empty CQ, but nothing in the core relies on that.

Doesn't the core now rely on every driver NULL-checking comp_handler?

The later commit "RDMA/mlx5: Ignore completion events for a CQ without a
handler" adds that check to mlx5_ib_cq_comp(), which closes the window for
mlx5. mlx4, efa and mthca still call the handler unconditionally at the end
of the series.

__ib_create_cq() in verbs.c, and the uverbs paths, set the handler before
calling into the driver:

	cq->device = device;
	cq->comp_handler = comp_handler;
	...
	ret = device->ops.create_cq(cq, cq_attr, NULL);

Could __ib_alloc_cq() do the same? That would mean running irq_poll_init(),
INIT_WORK(), the comp_wq store and the comp_handler store before
ops.create_cq(), and keeping only ib_req_notify_cq() for afterwards. The
driver's own publication of the CQ would then provide the ordering.

[Severity: High]
Is program order enough to make the poll context visible before the
handler? The irq_poll_init() stores (memset, INIT_LIST_HEAD, weight, poll),
INIT_WORK() and the cq->comp_wq store are all plain stores. This
comp_handler store is plain too, with no smp_store_release() or smp_wmb().

The reader side has no acquire ordering either:

mlx5 EQ irq
  mlx5_cq_tasklet_cb()
    mlx5_ib_cq_comp()
      ibcq->comp_handler()          <- plain load, indirect call
        ib_cq_completion_softirq()
          irq_poll_sched(&cq->iop)
      or
        ib_cq_completion_workqueue()
          queue_work(cq->comp_wq, &cq->work)

An event that arrives before the CQ is armed gets no ordering from the
doorbell write in ib_req_notify_cq().

On weakly ordered CPUs such as arm64 and POWER, can another CPU see the new
comp_handler before the iop, work or comp_wq stores? In the workqueue
cases, the compiler is also free to reorder the adjacent plain stores to
comp_wq and comp_handler.

If that happens, three things could go wrong:

- The reader schedules an iop whose memset and INIT_LIST_HEAD land after
  its own test_and_set_bit() and list_add_tail(). That corrupts the per-cpu
  irq_poll list.
- irq_poll_softirq() calls a stale NULL iop->poll.
- queue_work() is called with a NULL workqueue.

These are the failures the commit message describes.

Adversarial mode is enabled through cc_platform_has(CC_ATTR_GUEST_MEM_ENCRYPT).
That is true for arm64 realm/pKVM guests and pseries secure guests. The mlx5
UMR CQ allocated in mlx5r_umr_resource_init() with IB_POLL_SOFTIRQ goes
through this path. The plain NULL check that the later commit adds to
mlx5_ib_cq_comp() does not provide acquire ordering.

Would this need smp_store_release() on comp_handler, paired with an acquire
load in the drivers? The other option is to do all of this setup before
ops.create_cq(). Then the driver's publication, such as radix_tree_insert()
under table->lock in mlx5_eq_add_cq(), would order the stores for readers
that look up the CQ.

> +	if (cq->poll_ctx != IB_POLL_DIRECT)
> +		ib_req_notify_cq(cq, IB_CQ_NEXT_COMP);

[ ... ]

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261103163949.1554-1-yishaih%40nvidia.com
Technical Details
Message-ID: <179408309884.994134.17628521837326789530@kernel.org>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-358510-linux-kernel-netdev=dewy.ru
References: <20261103163949.1554-16-yishaih@nvidia.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-358510-linux-kernel-netdev=dewy.ru
From: netdev-bot+sashiko@kernel.org
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH rdma-next 15/23] RDMA/core: Set the CQ comp_handler after
 its poll context is set up
Date: Sat, 07 Nov 2026 20:24:58 +0000
Organization: Usenet Network
Message-ID: <179408309884.994134.17628521837326789530@kernel.org>
References: <20261103163949.1554-16-yishaih@nvidia.com>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="4186030"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:qSar7quYUNG8/xo5Ksq12wkTsrY= sha256:6pMQfDaZyRsUwwhg9HHIz2GWtabRQqiGga6kjHgR0mk=
	sha1:DBLSBp70lKpCeReOYLsI1N7lPRw= sha256:TVKZq1TGWoT+T0Z/6xGXKtFKJiayBTDcmv8LsldBJj0=
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 9AB3511349A; Sat,  7 Nov 2026 23:26:15 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.501
X-Spam-Status: No, score=-3.501 tagged_above=-9999 required=6.31
	tests=[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]
	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 Z6WGmlYKxVP1;
	Sat,  7 Nov 2026 23:26:12 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.232.135.74; helo=sto.lore.kernel.org; envelope-from=netdev+bounces-358510-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 sto.lore.kernel.org (sto.lore.kernel.org [172.232.135.74])
	by mail.dewy.ru (Postfix) with ESMTPS id 0DE2E1132E6; Sat,  7 Nov 2026 23:26:03 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by sto.lore.kernel.org (Postfix) with ESMTP id 756D6625A87; Sat,  7 Nov 2026 20:25:18 +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=1794083106;
	b=tJnNvVanMePWXGZEkA6IyK9m2g4ljNRYZXCouyvvCRfA2R8vqh9+Ucdnwx0el7ndDfzX
	 paZ80kvpXVWNbQ492aKEa+mfpc9+OrZ6bbs5qfhzRfjl7d9zWYaztXyh8rlWHfvFc1vUX
	 n03cW2ZhcAV/OPd3AMZlRVfVMO3pvsmeYc0kFP0AnB5236WAEP6w8PJnrtbJdQ3WHorch
	 ztA2R6pXiUFiKSimlrd6o5DZurnSGiL+D4ur335F1r7AbLnetAJ3dBVJ38OvU89jONwj2
	 DKbwTsVpFkiSifOQc50a9Mu+g3CALIp9tO/vST0OujzEpD3yOHhnlP5d7F/p8oIYSFg==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1794083106;
	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=+sYQxBcP7NU+0E9pOU+OKA6LcFbrC8mLyMrCGr9ieqk=;
	b=EOUrpnAD/rvjRGwOdP0+2aSpYWrF9QqNvYZwYbk+yq96wO54agWAgxpv9h2rz+7JlJQh
	 EZ8flZupgO0444pFhtgscYit0lSalHa3DIECHvI3dJB1MkXpzVyjRFKn7hrZjjqAHnyRE
	 hMQvteJSlfdeoz+kiIa9ZWxUWTlT1KYRj+45HO7Z7+6n+74Yzgkwq54J9sGIpEJxRi+S6
	 Uc8MmAFfS/XDl9a8pY0Z1MB8sqjTUX/dc2W68wfFMAihI1KruX05qy1n+fjFWNZmSDsJA
	 tusOKHg+NY293MmBEdVntJlXoQlfKid9NROwxqfG03bdbCyQSxyDkkVLnoAHV13O5ig==
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=VFX03h8o;
	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 42772606EE82;
	Sat,  7 Nov 2026 20:25:06 +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=VFX03h8o
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=1794083100;
	b=p6n8+mt1EBjgtSWrURk2yRrfK6t7Ivr+h3qEY8Zpw6B/lTk82wJygQiZxhPs2ZFoIIOe
	 RBNNHpQQE0rHIRuhk/5+xfjd1vpTcOyPeoeBlIiW+mrDT+yk2WwkLCY8uKJBi+JwEXkwG
	 i1miea97NuWov8ScYtgiOwGrhB6lDNnTiGSa3jPRJjeCei8jP2wWhXBTJN/lqq+1v8Nvg
	 bv7FQeVND0xYE7S/a24bOYshqQKPrEHLNqp3eMLsTAQyN/D3Ddg50H2zaCdRKzpzzujH7
	 0MoVmLeE/94JvqaWooZNGv4Ilnf9VrfJZWG9+RLgLTnNme+HP5rWifRNDDJTLIb0tNg==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1794083100;
	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=+sYQxBcP7NU+0E9pOU+OKA6LcFbrC8mLyMrCGr9ieqk=;
	b=RvhyWyfjKqOkSiKupO/KQHVWUpSjhXJDGPfWrbx+M+TITyAQAyoB4hYt/J7wKyg8XJPn
	 i/2iGm5TM++Hpht4MvIY8F+BYllOI9ulrRD+DezrRiB/kXANMd41gw9Gis4qdb2DnjHNj
	 CiU3DcRboHxR1oxLInUW1HahRCQvq+toL34s/OByyQQavPHA6w/9MZw2TBbT955oHP40R
	 EpU7c3t5ItgoZdQTM3NVLXoRn1Hk6bDAnSYU9K3ZvZOFks18jgN7fSu9Q7Xr6h5mmJw0B
	 lmNF0ymeK62aWKY/5hfVrDqGMdWUhNSOU+TEp0aXmZu36tk/+/eaFX8GQFfzd1F3ggQ==
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=VFX03h8o;
	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 204A9606A33D;
	Sat,  7 Nov 2026 20:25:00 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3FD1D1F008A2;
	Sat,  7 Nov 2026 20:24:59 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1794083100;
	bh=+sYQxBcP7NU+0E9pOU+OKA6LcFbrC8mLyMrCGr9ieqk=;
	h=Subject:From:To:Cc:Date:In-Reply-To:References;
	b=VFX03h8o7bT+5Mveui5Muo6i4nlLdvi+b83+WVobPLnPR+kJYbbC4MXI9ZQUK9yhq
	 WZs3p/Dx/GzDAI2vpfd06EgENTfZ4SIDEzyMsgFMSrHI9S+6oRBjVO2Mkn2B2AX+wY
	 wukSNALw7qOyDqmCpIc/4I9/Fjg2qYopod8RTjzhStaZmk91QHW+Wu0+FzLwiOB8jZ
	 8RvmLsK5vSVbeFWXPuJ0DHUcjuT4N8RpYJUEQ94uoYiSViupcmvFuC7R/8/rCL/XcK
	 KXYaJOWKFhTrxf7ttm6xh4H4wwrlC9GBO0GH95QBFjnZZd57jNTo9XzMdyCBVwPUeu
	 fTcgOx/F9+ewA==
X-Cc: jgg@ziepe.ca, leon@kernel.org, linux-rdma@vger.kernel.org,
 netdev@vger.kernel.org, saeedm@nvidia.com, tariqt@nvidia.com,
 mbloch@nvidia.com, kuba@kernel.org, pabeni@redhat.com, edumazet@kernel.org,
 davem@davemloft.net, andrew+netdev@lunn.ch, dtatulea@nvidia.com,
 moshe@nvidia.com, maorg@nvidia.com
X-In-Reply-To: <20261103163949.1554-16-yishaih@nvidia.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