Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=23.83.222.52 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796226289; b=phKXgfiLJhO3vn6xAVnbBVQdtDFWfKSkNdF0gVsF+CJPto7p0VzYqvR0JkjnKp4i26v0 o3t4e/fgdcPRgmynxS6XsCeRaRWlhiJ0DfI9PGuuxlSMbvIHeStMPILbwsQJ+rHnUKcxJ dtRURmD5E2fJxLZw3fx1NyeWHQrVMcJqMkcz5tSlTDlNguJ7aohxDMtCRmD7erGCzcFTT se93FiCX/QCssp54bNOTzqOivv77e+0F84pP1rG5AV6r/G+rZDH7EvE5Zuh39oFVex8GM sk8fS5/9kjDoZMWTkG1dP9SA89i9Hz/1FF4GvQID2f3htN9ZI/fj7SK1E5/CIypqIwg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796226289; h=DMARC-Filter:X-Sender-Id:Received:Received:X-Sender-Id:X-MC-Relay: X-MailChannels-SenderId:X-MailChannels-Auth-Id:X-Glossy-Callous: X-MC-Loop-Signature:X-MC-Ingress-Time:Received:Received: DKIM-Signature:From:To:Cc:Subject:Date:Message-Id:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; bh=4kFUN1GbIfivtKMwunNmVc0NSYFHzfqepVA1zoYE9zY=; b=JWZdb9cwcO/LxiBteQPjiP9N0oFHwI3c+umfIEZQTQ96PIfGa8GJUNCTCyo32eJ/rsZd pvePsxtJzx/t45o8gdViLcG5/USH8O5Gx4V4SfXs/WTw4kMfkKU1dEY4p72yN/dQ8Kex/ tvCtxm4EfhO8+f6wZyT/oIiKsvLVHzP/TxODwgHWVGMa+jbdB28SkeKJU6qfot5F+hoHl jqe/BgOV+pTL/ZB9mxkGehVyprygyNbtc7cCt6hquywn2/DPFYFw3cHw1plAp3xh5gttl FV9CF1rda61hfGxIekBOUAvdtKsHnEK5R8xg5VmBFfhkSPPrhAW+wb4s88iXGFOoZWQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none header.from=stgolabs.net; spf=fail smtp.mailfrom=stgolabs.net; dkim=pass header.d=stgolabs.net header.i=@stgolabs.net header.a=rsa-sha256 header.s=dreamhost header.b=U6qa8DEL; arc=none smtp.remote-ip=23.83.222.52 Received: from duck.ash.relay.mailchannels.net (duck.ash.relay.mailchannels.net [23.83.222.52]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 07C6D606A325 for ; Wed, 2 Dec 2026 15:44:47 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 07C6D606A325 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=stgolabs.net Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=stgolabs.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=stgolabs.net header.i=@stgolabs.net header.a=rsa-sha256 header.s=dreamhost header.b=U6qa8DEL X-Sender-Id: dreamhost|x-authsender|dave@stgolabs.net Received: from relay.mailchannels.net (localhost [127.0.0.1]) by relay.mailchannels.net (Postfix) with ESMTP id E4E23380DF0; Wed, 02 Dec 2026 15:44:40 +0000 (UTC) Received: from pdx1-sub0-mail-a229.dreamhost.com (trex-green-6.trex.outbound.svc.cluster.local [100.96.15.253]) (Authenticated sender: dreamhost) by relay.mailchannels.net (Postfix) with ESMTPA id 80DBB382728; Wed, 02 Dec 2026 15:44:36 +0000 (UTC) X-Sender-Id: dreamhost|x-authsender|dave@stgolabs.net X-MC-Relay: Neutral X-MailChannels-SenderId: dreamhost|x-authsender|dave@stgolabs.net X-MailChannels-Auth-Id: dreamhost X-Glossy-Callous: 456269c7503ddeb8_1796226280881_3417666006 X-MC-Loop-Signature: 1796226280881:126102227 X-MC-Ingress-Time: 1796226280881 Received: from pdx1-sub0-mail-a229.dreamhost.com (pop.dreamhost.com [64.90.62.162]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384) by 100.96.15.253 (trex/8.0.2); Wed, 02 Dec 2026 15:44:40 +0000 Received: from offworld.tailf5af7a.ts.net (unknown [76.167.199.67]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: dave@stgolabs.net) by pdx1-sub0-mail-a229.dreamhost.com (Postfix) with ESMTPSA id 4jfhrz5jQBzV6; Wed, 2 Dec 2026 07:44:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=stgolabs.net; s=dreamhost; t=1796226276; bh=4kFUN1GbIfivtKMwunNmVc0NSYFHzfqepVA1zoYE9zY=; h=From:To:Cc:Subject:Date:Content-Transfer-Encoding; b=U6qa8DELVowZucPBxNj03G+M2+D21VY3+bk7cfI7lJ906OYASJlXH2kQO/nJayHup rNxq8KF/il2iLfnFT8n/YKk4ZbZ2IlKQk/iMdqkIx7q8+0dg8/C0IWj22Rh+jjPAyG AfBbnYrSjviYeD1uOyWqetnHOvRfAyNwtDOO5hCXcT3ueBJ/liejm6HoD6fZzj86wI BAbP1j4Y3T7+Cd/rJGViwtczB7kvDnJIkeCDx67DJVNHOfuS7fbikFbFugVdlnOVek 45q1mO4xOtsNHczwwxhqvZARsfJsFWvrQR2jLNrlYFudjFL/Hkhwqfl/guVmlDd0+a AYzTFklXzFbDw== From: Davidlohr Bueso To: dave.jiang@intel.com Cc: jic23@kernel.org, alison.schofield@intel.com, ming.li@zohomail.com, icheng@nvidia.com, benjamin.cheatham@amd.com, unsung0317@gmail.com, linux-cxl@vger.kernel.org, dave@stgolabs.net Subject: [PATCH v2 04/10] cxl/mbox: Decouple async background handling from security Date: Wed, 2 Dec 2026 07:43:58 -0800 Message-Id: <20261202154404.4016305-5-dave@stgolabs.net> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20261202154404.4016305-1-dave@stgolabs.net> References: <20261202154404.4016305-1-dave@stgolabs.net> X-Mailing-List: linux-cxl@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit The asynchronous handling of a background command, the state that says one is running and the work that polls for its completion, lives in the security state and is hardwired to Sanitize. Move it to the background state and track the running operation by its opcode, such that other commands can make use of it. Now that the interrupt handler kicks the poller based on the tracked operation instead of the sanitize sysfs node, the sanitize notifier teardown no longer keeps the poller from being rescheduled. Cancel it with a devm action of its own that runs after the interrupt is gone. Sanitize remains the only command handled asynchronously. Signed-off-by: Davidlohr Bueso --- drivers/cxl/core/hdm.c | 2 +- drivers/cxl/core/memdev.c | 7 ++-- drivers/cxl/cxlmem.h | 12 +++---- drivers/cxl/pci.c | 64 +++++++++++++++++++++++------------- tools/testing/cxl/test/mem.c | 10 +++--- 5 files changed, 57 insertions(+), 38 deletions(-) diff --git a/drivers/cxl/core/hdm.c b/drivers/cxl/core/hdm.c index 6329eb3b9214..04576c08f22f 100644 --- a/drivers/cxl/core/hdm.c +++ b/drivers/cxl/core/hdm.c @@ -879,7 +879,7 @@ static int cxl_decoder_commit(struct cxl_decoder *cxld) struct cxl_memdev_state *mds = to_cxl_memdev_state(cxlmd->cxlds); - if (mds && mds->security.sanitize_active) { + if (mds && mds->bg.opcode == CXL_MBOX_OP_SANITIZE) { dev_dbg(&cxlmd->dev, "attempted to commit %s during sanitize\n", dev_name(&cxld->dev)); diff --git a/drivers/cxl/core/memdev.c b/drivers/cxl/core/memdev.c index 787988e92965..002f56322b47 100644 --- a/drivers/cxl/core/memdev.c +++ b/drivers/cxl/core/memdev.c @@ -133,7 +133,7 @@ static ssize_t security_state_show(struct device *dev, /* sync with latest submission state */ mutex_lock(&cxl_mbox->mbox_mutex); - if (mds->security.sanitize_active) + if (mds->bg.opcode == CXL_MBOX_OP_SANITIZE) rc = sysfs_emit(buf, "sanitize\n"); mutex_unlock(&cxl_mbox->mbox_mutex); if (rc) @@ -1301,15 +1301,14 @@ static void sanitize_teardown_notifier(void *data) struct kernfs_node *state; /* - * Prevent new irq triggered invocations of the workqueue and - * flush inflight invocations. + * Stop the poller from notifying and flush inflight invocations. */ mutex_lock(&cxl_mbox->mbox_mutex); state = mds->security.sanitize_node; mds->security.sanitize_node = NULL; mutex_unlock(&cxl_mbox->mbox_mutex); - cancel_delayed_work_sync(&mds->security.poll_dwork); + cancel_delayed_work_sync(&mds->bg.poll_dwork); sysfs_put(state); } diff --git a/drivers/cxl/cxlmem.h b/drivers/cxl/cxlmem.h index 8b0df394d231..e1d028d9af1b 100644 --- a/drivers/cxl/cxlmem.h +++ b/drivers/cxl/cxlmem.h @@ -406,17 +406,11 @@ struct cxl_fw_state { * * @state: state of last security operation * @enabled_cmds: All security commands enabled in the CEL - * @poll_tmo_secs: polling timeout - * @sanitize_active: sanitize completion pending - * @poll_dwork: polling work item * @sanitize_node: sanitation sysfs file to notify */ struct cxl_security_state { unsigned long state; DECLARE_BITMAP(enabled_cmds, CXL_SEC_ENABLED_MAX); - int poll_tmo_secs; - bool sanitize_active; - struct delayed_work poll_dwork; struct kernfs_node *sanitize_node; }; @@ -424,9 +418,15 @@ struct cxl_security_state { * struct cxl_background_state - Driver background operation state info * * @enabled_cmds: All background commands enabled in the CEL + * @poll_dwork: polling background work item + * @poll_tmo_secs: polling timeout + * @opcode: async running background command */ struct cxl_background_state { DECLARE_BITMAP(enabled_cmds, CXL_BG_ENABLED_MAX); + struct delayed_work poll_dwork; + int poll_tmo_secs; + int opcode; }; #define CXL_MAX_DC_PARTITIONS 8 diff --git a/drivers/cxl/pci.c b/drivers/cxl/pci.c index fd3db405a6d5..1bc28ad17200 100644 --- a/drivers/cxl/pci.c +++ b/drivers/cxl/pci.c @@ -136,8 +136,9 @@ static irqreturn_t cxl_pci_mbox_irq(int irq, void *id) opcode = FIELD_GET(CXLDEV_MBOX_BG_CMD_COMMAND_OPCODE_MASK, reg); if (opcode == CXL_MBOX_OP_SANITIZE) { mutex_lock(&cxl_mbox->mbox_mutex); - if (mds->security.sanitize_node) - mod_delayed_work(system_percpu_wq, &mds->security.poll_dwork, 0); + if (mds->bg.opcode) + mod_delayed_work(system_percpu_wq, + &mds->bg.poll_dwork, 0); mutex_unlock(&cxl_mbox->mbox_mutex); } else { /* short-circuit the wait in __cxl_pci_mbox_send_cmd() */ @@ -150,26 +151,29 @@ static irqreturn_t cxl_pci_mbox_irq(int irq, void *id) /* * Sanitization operation polling mode. */ -static void cxl_mbox_sanitize_work(struct work_struct *work) +static void cxl_mbox_bgpoll_work(struct work_struct *work) { struct cxl_memdev_state *mds = - container_of(work, typeof(*mds), security.poll_dwork.work); + container_of(work, typeof(*mds), bg.poll_dwork.work); struct cxl_dev_state *cxlds = &mds->cxlds; struct cxl_mailbox *cxl_mbox = &cxlds->cxl_mbox; mutex_lock(&cxl_mbox->mbox_mutex); if (cxl_mbox_background_complete(cxlds)) { - mds->security.poll_tmo_secs = 0; - if (mds->security.sanitize_node) + mds->bg.poll_tmo_secs = 0; + if (mds->bg.opcode == CXL_MBOX_OP_SANITIZE && + mds->security.sanitize_node) sysfs_notify_dirent(mds->security.sanitize_node); - mds->security.sanitize_active = false; - dev_dbg(cxlds->dev, "Sanitization operation ended\n"); + dev_dbg(cxlds->dev, + "Mailbox background operation (0x%04x) ended\n", + mds->bg.opcode); + mds->bg.opcode = 0; } else { - int timeout = min(15 * 60, mds->security.poll_tmo_secs + 10); + int timeout = min(15 * 60, mds->bg.poll_tmo_secs + 10); - mds->security.poll_tmo_secs = timeout; - schedule_delayed_work(&mds->security.poll_dwork, timeout * HZ); + mds->bg.poll_tmo_secs = timeout; + schedule_delayed_work(&mds->bg.poll_dwork, timeout * HZ); } mutex_unlock(&cxl_mbox->mbox_mutex); } @@ -242,7 +246,7 @@ static int __cxl_pci_mbox_send_cmd(struct cxl_mailbox *cxl_mbox, * not be in sync. Ensure no new command comes in until so. Keep the * hardware semantics and only allow device health status. */ - if (mds->security.poll_tmo_secs > 0) { + if (mds->bg.opcode == CXL_MBOX_OP_SANITIZE) { if (mbox_cmd->opcode != CXL_MBOX_OP_GET_HEALTH_INFO) return -EBUSY; } @@ -298,28 +302,27 @@ static int __cxl_pci_mbox_send_cmd(struct cxl_mailbox *cxl_mbox, u64 bg_status_reg; int i, timeout; + dev_dbg(dev, "Mailbox background operation (0x%04x) started\n", + mbox_cmd->opcode); + /* * Sanitization is a special case which monopolizes the device * and cannot be timesliced. Handle asynchronously instead, * and allow userspace to poll(2) for completion. */ if (mbox_cmd->opcode == CXL_MBOX_OP_SANITIZE) { - if (mds->security.sanitize_active) + if (mds->bg.opcode) return -EBUSY; /* give first timeout a second */ timeout = 1; - mds->security.poll_tmo_secs = timeout; - mds->security.sanitize_active = true; - schedule_delayed_work(&mds->security.poll_dwork, + mds->bg.poll_tmo_secs = timeout; + mds->bg.opcode = mbox_cmd->opcode; + schedule_delayed_work(&mds->bg.poll_dwork, timeout * HZ); - dev_dbg(dev, "Sanitization operation started\n"); goto success; } - dev_dbg(dev, "Mailbox background operation (0x%04x) started\n", - mbox_cmd->opcode); - timeout = mbox_cmd->poll_interval_ms; for (i = 0; i < mbox_cmd->poll_count; i++) { if (rcuwait_wait_event_timeout(&cxl_mbox->mbox_wait, @@ -389,6 +392,13 @@ static int cxl_pci_mbox_send(struct cxl_mailbox *cxl_mbox, return rc; } +static void cxl_pci_bg_teardown(void *data) +{ + struct cxl_memdev_state *mds = data; + + cancel_delayed_work_sync(&mds->bg.poll_dwork); +} + static int cxl_pci_setup_mailbox(struct cxl_memdev_state *mds, bool irq_avail) { struct cxl_dev_state *cxlds = &mds->cxlds; @@ -396,7 +406,7 @@ static int cxl_pci_setup_mailbox(struct cxl_memdev_state *mds, bool irq_avail) const int cap = readl(cxlds->regs.mbox + CXLDEV_MBOX_CAPS_OFFSET); struct device *dev = cxlds->dev; unsigned long timeout; - int irq, msgnum; + int irq, msgnum, rc; u64 md_status; u32 ctrl; @@ -445,7 +455,17 @@ static int cxl_pci_setup_mailbox(struct cxl_memdev_state *mds, bool irq_avail) dev_dbg(dev, "Mailbox payload sized %zu", cxl_mbox->payload_size); - INIT_DELAYED_WORK(&mds->security.poll_dwork, cxl_mbox_sanitize_work); + INIT_DELAYED_WORK(&mds->bg.poll_dwork, cxl_mbox_bgpoll_work); + + /* + * The interrupt handler kicks the poller for as long as an + * operation is tracked, whatever the sanitize notifier is up to. + * Registered ahead of the interrupt, so that by the time the + * poller is cancelled nothing can kick it. + */ + rc = devm_add_action_or_reset(dev, cxl_pci_bg_teardown, mds); + if (rc) + return rc; /* background command interrupts are optional */ if (!(cap & CXLDEV_MBOX_CAP_BG_CMD_IRQ) || !irq_avail) diff --git a/tools/testing/cxl/test/mem.c b/tools/testing/cxl/test/mem.c index c740372bdaaa..6d01fe9c9453 100644 --- a/tools/testing/cxl/test/mem.c +++ b/tools/testing/cxl/test/mem.c @@ -665,13 +665,13 @@ static int mock_partition_info(struct cxl_mbox_cmd *cmd) void cxl_mockmem_sanitize_work(struct work_struct *work) { struct cxl_memdev_state *mds = - container_of(work, typeof(*mds), security.poll_dwork.work); + container_of(work, typeof(*mds), bg.poll_dwork.work); struct cxl_mailbox *cxl_mbox = &mds->cxlds.cxl_mbox; mutex_lock(&cxl_mbox->mbox_mutex); if (mds->security.sanitize_node) sysfs_notify_dirent(mds->security.sanitize_node); - mds->security.sanitize_active = false; + mds->bg.opcode = 0; mutex_unlock(&cxl_mbox->mbox_mutex); dev_dbg(mds->cxlds.dev, "sanitize complete\n"); @@ -700,9 +700,9 @@ static int mock_sanitize(struct cxl_mockmem_data *mdata, } mutex_lock(&cxl_mbox->mbox_mutex); - if (schedule_delayed_work(&mds->security.poll_dwork, + if (schedule_delayed_work(&mds->bg.poll_dwork, msecs_to_jiffies(mdata->sanitize_timeout))) { - mds->security.sanitize_active = true; + mds->bg.opcode = CXL_MBOX_OP_SANITIZE; dev_dbg(mds->cxlds.dev, "sanitize issued\n"); } else rc = -EBUSY; @@ -1766,7 +1766,7 @@ static int cxl_mock_mem_probe(struct platform_device *pdev) cxl_mbox->mbox_send = cxl_mock_mbox_send; cxl_mbox->payload_size = SZ_4K; mds->event.buf = (struct cxl_get_event_payload *) mdata->event_buf; - INIT_DELAYED_WORK(&mds->security.poll_dwork, cxl_mockmem_sanitize_work); + INIT_DELAYED_WORK(&mds->bg.poll_dwork, cxl_mockmem_sanitize_work); if (is_rcd(pdev)) cxlds->rcd = true; -- 2.39.5