From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796227820; b=wFhN+K4TcNyeUsOSe/lqTnbtU/R+SUhIDpfJjqxsN8OV5D6STVR5Rn6NkQnep8P90DCG DghEmmW+JK+U68OZeDRDhNPxtq33a9klxc5pHBl0cF+OUIyzQF4EdGwEjyD+m/EbhRLGr qpr/CDagg0xyRA074uc6tjQHpp/a2RiTOx4x2Os1W6Qu89nKlDSmGbkWSUiN7CpAA/+4I 6PKRsEB3a0QvSICf1spTO32EQs1RIaLrXdLv0qsKh4in59awjMFK4W272UExw3bJQOoPJ 4wBHqjoWtjfyFtL+Gi06R/Pj/JjfmcMuu0O3B6lE9l97btNVTnfjftCN+N/bO88BixQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796227820; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=dQaYBdvbLF+UR9doGyB0zRfG8UZ0n5mfGpvQbm6/Mpo=; b=VdWg3XQ5y2x5P9M+Yb2Hj9rJrbQmxneXd3oUqLruJr23CU/dbtlXnOIPkZKu5i+Ys1n8 u1Fr/PyZ3A8X3s5qR0657+E/n1ykBpGqtQ9IAQRL+IzbPoJ9gIEF5OC5u/vsAOeUF0JWe UVWroWftzCCDWJr00x9UcFBzBS6p+EgrIJTBvwqE0NyyIr6YVSmCf3h6XYr0Bh4+rl5rP OfgGY/yabKo1RU4B+YGS1mZMUOk1P7UwkRJk0cS6lBvvdIN3M7GO52RhwtELdoAiByOIH 9+Fviuzy2B5ypjAEC6xkSB68hhsrosrP2Eyw53IyLRSYzWjLNPBDVo7fOjk+DzdMV9g== 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=b6RMlbw0; arc=none smtp.remote-ip=100.103.45.18 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 5FDD9606A31A for ; Wed, 2 Dec 2026 16:10:20 +0000 (UTC) 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=b6RMlbw0 Received: by smtp.kernel.org (Postfix) with ESMTPSA id DA7DB1F000C1; Wed, 2 Dec 2026 16:10:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796227820; bh=dQaYBdvbLF+UR9doGyB0zRfG8UZ0n5mfGpvQbm6/Mpo=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=b6RMlbw0Uhc7CVYV/08U2oELmSCHdXD9vqRLLzE0ebhbfeAgQVzJA/WytS4i6TLqZ /fE5CgWefC8uOwgutKjU35cfru3I2BjJTnv3N1sPKU1lgV6iCxYS0WB3iRuRiuomzX cyEJBGfyTOwUs6YpsYYX7iuTyQh1ME4apUE+ua4GYRCiisCzJDNRQYMkeFIybuHJZb p5G2u28N8fnmvq65h1itkOYe7E1wvrhwWZsGE/Eris3FzKdeoESatnxJ7n1/OucQY1 ++vgQUxqcrltB9eYJPBSBTVHkQ3r3OkXT2ftTg/3i6zm3jaQkC5d7ze2EpKRMhtLZW Au0TdeWvqeCTA== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v2 08/10] cxl/mbox: Allow userspace background commands Reply-To: sashiko-reviews@lists.linux.dev To: "Davidlohr Bueso" Cc: linux-cxl@vger.kernel.org In-Reply-To: <20261202154404.4016305-9-dave@stgolabs.net> References: <20261202154404.4016305-1-dave@stgolabs.net> <20261202154404.4016305-9-dave@stgolabs.net> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Wed, 02 Dec 2026 16:10:19 +0000 X-Mailing-List: linux-cxl@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Thank you for your contribution! Sashiko AI review found 3 potential issues to consider: - [Medium] cxl/pci: unlocked read of mds->bg.user in cxl_pci_mbox_irq() - [Medium] cxl/pci: stale cxl_mbox_bgpoll_work() acts on newly started bg command - [Low] cxl/pci: unreachable default branch in __cxl_pci_mbox_send_cmd() -- commit 8459d3a327df488babc367e3665eac99ff3c874f Author: Davidlohr Bueso cxl/mbox: Allow userspace background commands This commit enables abortable userspace background mailbox commands, tracks them asynchronously via the background polling worker, and allows incoming background commands to abort an active userspace background command. > diff --git a/drivers/cxl/pci.c b/drivers/cxl/pci.c > index ef4853296e860..1cacc9e90a311 100644 > --- a/drivers/cxl/pci.c > +++ b/drivers/cxl/pci.c > @@ -134,7 +134,7 @@ static irqreturn_t cxl_pci_mbox_irq(int irq, void *id) > =20 > reg =3D readq(cxlds->regs.mbox + CXLDEV_MBOX_BG_CMD_STATUS_OFFSET); > opcode =3D FIELD_GET(CXLDEV_MBOX_BG_CMD_COMMAND_OPCODE_MASK, reg); > - if (opcode =3D=3D CXL_MBOX_OP_SANITIZE) { > + if (opcode =3D=3D CXL_MBOX_OP_SANITIZE || mds->bg.user) { > mutex_lock(&cxl_mbox->mbox_mutex); > if (mds->bg.opcode) > mod_delayed_work(system_percpu_wq, [Severity: Medium] Can reading mds->bg.user outside cxl_mbox->mbox_mutex in cxl_pci_mbox_irq() race with __cxl_pci_mbox_send_cmd() and cxl_mbox_bg_end()? __cxl_pci_mbox_send_cmd() only sets mds->bg.user after ringing and waiting for the command doorbell under mbox_mutex: CPU0 CPU1 (threaded IRQ) __cxl_pci_mbox_send_cmd() mutex_lock(&cxl_mbox->mbox_mutex) writel(... | DOORBELL, ...) cxl_pci_mbox_wait_for_doorbell() cxl_pci_mbox_irq() if (... || mds->bg.user) <-- false rcuwait_wake_up(&cxl_mbox->mbox_wai= t) mds->bg.opcode =3D mbox_cmd->opcode mds->bg.user =3D mbox_cmd->user schedule_delayed_work(..., 1 * HZ) mutex_unlock(&cxl_mbox->mbox_mutex) When a fast userspace background command completes before mds->bg.user is stored, the IRQ handler takes the else branch and fails to expedite mds->bg.poll_dwork. Conversely, if cxl_pci_mbox_irq() reads mds->bg.user =3D=3D true for a fini= shed or aborted command and blocks on mbox_mutex while a new command is submitted, it will either kick poll_dwork immediately against a newly started userspace background command (bumping its poll backoff from 1s to 11s) or exit without calling rcuwait_wake_up(&cxl_mbox->mbox_wait) if a synchronous kernel background command started and completed in the meantime. > @@ -159,16 +180,10 @@ static void cxl_mbox_bgpoll_work(struct work_struct= *work) > struct cxl_mailbox *cxl_mbox =3D &cxlds->cxl_mbox; > =20 > mutex_lock(&cxl_mbox->mbox_mutex); > - if (cxl_mbox_background_done(cxlds)) { > - mds->bg.poll_tmo_secs =3D 0; > - if (mds->bg.opcode =3D=3D CXL_MBOX_OP_SANITIZE && > - mds->security.sanitize_node) > - sysfs_notify_dirent(mds->security.sanitize_node); > - > - dev_dbg(cxlds->dev, > - "Mailbox background operation (0x%04x) ended\n", > - mds->bg.opcode); > - mds->bg.opcode =3D 0; > + if (!mds->bg.opcode) { > + /* cxl_try_to_cancel_background() got here first */ > + } else if (cxl_mbox_background_done(cxlds)) { > + cxl_mbox_bg_end(mds); > } else { > int timeout =3D min(15 * 60, mds->bg.poll_tmo_secs + 10); > =20 [Severity: Medium] Can an in-flight cxl_mbox_bgpoll_work() blocked on mbox_mutex act on a newly started background command instead of noticing the cancellation? In cxl_pci_mbox_send(), cxl_try_to_cancel_background() and __cxl_pci_mbox_send_cmd() run under the same mbox_mutex acquisition: CPU0 CPU1 (kworker) cxl_pci_mbox_send() mutex_lock(&cxl_mbox->mbox_mutex) cxl_mbox_bgpoll_work() mutex_lock(&cxl_mbox->mbox_mutex) cxl_try_to_cancel_background() cancel_delayed_work(&mds->bg.poll_dwork) cxl_mbox_bg_end() mds->bg.opcode =3D 0 __cxl_pci_mbox_send_cmd() mds->bg.poll_tmo_secs =3D 1 mds->bg.opcode =3D mbox_cmd->opcode schedule_delayed_work(..., 1 * HZ) mutex_unlock(&cxl_mbox->mbox_mutex) if (!mds->bg.opcode) <-- false Because mds->bg.opcode is overwritten before mbox_mutex is released, the stale worker sees the new command's opcode. If the new command is still running, the stale worker immediately increases mds->bg.poll_tmo_secs from 1s to 11s; if the new command has already finished, it calls cxl_mbox_bg_end() and clears mds->bg.opcode to 0 while the 1s delayed work scheduled by __cxl_pci_mbox_send_cmd() remains pending. > @@ -261,13 +276,26 @@ static int __cxl_pci_mbox_send_cmd(struct cxl_mailb= ox *cxl_mbox, > } > =20 > /* > - * With sanitize polling, hardware might be done and the poller still > - * not be in sync. Ensure no new command comes in until so. Keep the > - * hardware semantics and only allow device health status. > + * With async bg polling, hardware might be done and the poller still > + * not be in sync. At the very least, prevent any incoming bg-capable > + * commands during this window. > */ > - if (mds->bg.opcode =3D=3D CXL_MBOX_OP_SANITIZE) { > + switch (mds->bg.opcode) { > + case 0: > + /* no async background operation to stay in sync with */ > + break; > + case CXL_MBOX_OP_SANITIZE: > + /* > + * Ensure no new command comes in until so. Keep the > + * hardware semantics and only allow device health status. > + */ > if (mbox_cmd->opcode !=3D CXL_MBOX_OP_GET_HEALTH_INFO) > return -EBUSY; > + break; > + default: > + if (cxl_is_background_cmd(mds, mbox_cmd->opcode)) > + return -EBUSY; > + break; > } [Severity: Low] Is the default branch in this switch reachable? __cxl_pci_mbox_send_cmd() is only called from cxl_try_to_cancel_background() (with CXL_MBOX_OP_REQUEST_ABORT_BG_OP, where cxl_is_background_cmd() is false) and from cxl_pci_mbox_send(). In cxl_pci_mbox_send(), any command where cxl_is_background_cmd() is true first calls cxl_try_to_cancel_background() under mbox_mutex, which either fails and returns -EBUSY before calling __cxl_pci_mbox_send_cmd(), or succeeds and clears mds->bg.opcode to 0 via cxl_mbox_bg_end(). --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261202154404.4016= 305-1-dave@stgolabs.net?part=3D8