From patchwork Fri Sep 22 13:05:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeongtae Park X-Patchwork-Id: 13395779 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1B4EEE6FE22 for ; Fri, 22 Sep 2023 13:03:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229947AbjIVNDO (ORCPT ); Fri, 22 Sep 2023 09:03:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42854 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231894AbjIVNDN (ORCPT ); Fri, 22 Sep 2023 09:03:13 -0400 Received: from mailout2.samsung.com (mailout2.samsung.com [203.254.224.25]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 72210C6 for ; Fri, 22 Sep 2023 06:03:06 -0700 (PDT) Received: from epcas2p1.samsung.com (unknown [182.195.41.53]) by mailout2.samsung.com (KnoxPortal) with ESMTP id 20230922130304epoutp023892c1dc20d614957b5e8b6b268ed181~HOjUkyiMK3063930639epoutp02L for ; Fri, 22 Sep 2023 13:03:04 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.samsung.com 20230922130304epoutp023892c1dc20d614957b5e8b6b268ed181~HOjUkyiMK3063930639epoutp02L DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1695387784; bh=Q0W4WImgD5N0ejljQDCcQVqwjZekZLjePm+XCw/tJDQ=; h=From:To:Cc:Subject:Date:References:From; b=iXSE2OrII1thMxmOBvouIXoeb9u4H2xkRde+iZ+3edu1jIOjMOq6dkLUvNZUKo+Re 41eGOAdjdaowookogfjBWUaet+jGHDlXpFa7QeaWROvsNK4GoX9zJdTJfuqv0ZvgCa rdabAxT5D7zPr/Nq/SHW8NocGhHlnwNs+16/DILw= Received: from epsnrtp3.localdomain (unknown [182.195.42.164]) by epcas2p4.samsung.com (KnoxPortal) with ESMTP id 20230922130303epcas2p48d4bc5c04fe295271024a35709fbf7ac~HOjTqImAy0828508285epcas2p4o; Fri, 22 Sep 2023 13:03:03 +0000 (GMT) Received: from epsmges2p1.samsung.com (unknown [182.195.36.100]) by epsnrtp3.localdomain (Postfix) with ESMTP id 4RsXWC0zclz4x9Pp; Fri, 22 Sep 2023 13:03:03 +0000 (GMT) Received: from epcas2p4.samsung.com ( [182.195.41.56]) by epsmges2p1.samsung.com (Symantec Messaging Gateway) with SMTP id 18.65.09693.6809D056; Fri, 22 Sep 2023 22:03:02 +0900 (KST) Received: from epsmtrp1.samsung.com (unknown [182.195.40.13]) by epcas2p3.samsung.com (KnoxPortal) with ESMTPA id 20230922130302epcas2p3911ef4d46327ed8bb2ae990f933e9ad3~HOjSkbMTK0781807818epcas2p3F; Fri, 22 Sep 2023 13:03:02 +0000 (GMT) Received: from epsmgmcp1.samsung.com (unknown [182.195.42.82]) by epsmtrp1.samsung.com (KnoxPortal) with ESMTP id 20230922130302epsmtrp11f94801fa7282e2f724211c08c1171e6~HOjSjb3RI3196931969epsmtrp1v; Fri, 22 Sep 2023 13:03:02 +0000 (GMT) X-AuditID: b6c32a45-abbfd700000025dd-46-650d90863694 Received: from epsmtip1.samsung.com ( [182.195.34.30]) by epsmgmcp1.samsung.com (Symantec Messaging Gateway) with SMTP id 98.9A.18916.6809D056; Fri, 22 Sep 2023 22:03:02 +0900 (KST) Received: from jtpark-7920.dsn.sec.samsung.com (unknown [10.229.83.56]) by epsmtip1.samsung.com (KnoxPortal) with ESMTPA id 20230922130302epsmtip17e95514d9e215c751826df58df7e5d0f~HOjSR2C8b2258922589epsmtip18; Fri, 22 Sep 2023 13:03:02 +0000 (GMT) From: Jeongtae Park To: linux-cxl@vger.kernel.org Cc: Dan Williams , Alison Schofield , Vishal Verma , Ben Widawsky , Jonathan Cameron , Dave Jiang , Davidlohr Bueso , Fan Ni , Kyungsan Kim , Wonjae Lee , Hojin Nam , Junhyeok Im , Jehoon Park , Jeongtae Park , Jeongtae Park Subject: [RFC PATCH 1/3] cxl: Modify background cmd handling for the others Date: Fri, 22 Sep 2023 22:05:48 +0900 Message-Id: <20230922130548.3476202-1-jtp.park@samsung.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrKJsWRmVeSWpSXmKPExsWy7bCmhW7bBN5Ug2/LrCzuPr7AZtE8eTGj xfSpFxgtTtxsZLNYfXMNo0XT6rusFh/e/GOxOPC6gd3izNmXrBarFl5jsziy9iqTxeKjM5gt ju7hsDg/6xSLxa0Jx5gsNt5/x+Yg4LFz1l12j5Yjb1k9Fu95yeSxaVUnm0ffllWMHlNn13t8 3iQXwB6VbZORmpiSWqSQmpecn5KZl26r5B0c7xxvamZgqGtoaWGupJCXmJtqq+TiE6DrlpkD dLuSQlliTilQKCCxuFhJ386mKL+0JFUhI7+4xFYptSAlp8C8QK84Mbe4NC9dLy+1xMrQwMDI FKgwITvj3vbbLAWXvSsm77zL2sA42a6LkZNDQsBE4sWDvexdjFwcQgI7GCUa2x4wQjifGCV6 l99gBakCcz4fUIXpuPa9H6poJ6PEs9VXmCCcP4wSt65uZgSpYhPQkpg+swGsW0RAVqJ53QOw ImaBqywSk05dZAJJCAt4S2xo3gHWwCKgKvHmRjtYA6+AtcT/np2MEOvkJfYfPMsMEReUODnz CQuIzQwUb946mxlkqITATA6Jv8f3QzW4SDz//JcdwhaWeHV8C5QtJfGyv40doqGZUeL18yss EE4Lo8S62zugqowl3t18DnQGB9AKTYn1u/RBTAkBZYkjt6AW80l0HAaZDxLmlehoE4JoVJKY t3QeM4QtIXFp7hYo20NiX2sbI0i5kECsxNZbuhMY5Wch+WYWkm9mIaxdwMi8ilEstaA4N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g7GQ4wSHMxKIrzJn7hShXhTEiurUovy44tKc1KLDzFKc7AoifMq53SmCAmk J5akZqemFqQWwWSZODilGpj0xWIWtwlo+zXPEY2dJl6e/sfkm/jpU2zbPuprBlwLnfFg/tHL tYwveR1chBrv7L1mfOrN4+ISizd3tvyY0un78uhS+9k3726cmXb27oP/cXt5fy+supadu84s 8ffOa0urrx47crUi78DWfb9kd9Xecua56P1ogs2tGNdN5yekMR5sEp3M/t/j9spN+7cFq7Ge sk2LX/Cr9YTpSp1l1xI+8n/LMN7pXNS01HRBoP2apUeXPOrYdvGPcHnL1ru+M651yl27sVek xHuiTe2iZTdUVwfxLSjUl37IxXxYWj5fkGdFYTi/XHjvUqOGyvPzeKbyV+25xPBo0YoFUbMY ogSDV5QLNS7I0N9u6my28/ezF0osxRmJhlrMRcWJAA+6jcT0AgAA X-CMS-MailID: 20230922130302epcas2p3911ef4d46327ed8bb2ae990f933e9ad3 X-Msg-Generator: CA X-Sendblock-Type: AUTO_CONFIDENTIAL CMS-TYPE: 102P DLP-Filter: Pass X-CFilter-Loop: Reflected X-CMS-RootMailID: 20230922130302epcas2p3911ef4d46327ed8bb2ae990f933e9ad3 References: Precedence: bulk List-ID: X-Mailing-List: linux-cxl@vger.kernel.org This patch modifies sanitize command handling to support background-capable commands asynchronously also. Much of the implementation follows the approach of the sanitize command implementation, with the addition of 'bgmode' to cxl_mbox_cmd explicitly could choose how each command is handled. However, even if you want asynchronous processing via irq, it will fallback to poll based if the device doesn't support it. Added a new cxl_bgcmd_state by moving the necessary data structures from cxl_security_state. Signed-off-by: Jeongtae Park Signed-off-by: Hojin Nam --- drivers/cxl/core/memdev.c | 8 ++--- drivers/cxl/cxlmem.h | 33 +++++++++++++++++--- drivers/cxl/pci.c | 65 +++++++++++++++++++-------------------- 3 files changed, 64 insertions(+), 42 deletions(-) diff --git a/drivers/cxl/core/memdev.c b/drivers/cxl/core/memdev.c index f99e7ec3cc40..8d1692231767 100644 --- a/drivers/cxl/core/memdev.c +++ b/drivers/cxl/core/memdev.c @@ -537,13 +537,13 @@ void clear_exclusive_cxl_commands(struct cxl_memdev_state *mds, } EXPORT_SYMBOL_NS_GPL(clear_exclusive_cxl_commands, CXL); -static void cxl_memdev_security_shutdown(struct device *dev) +static void cxl_memdev_bgcmd_shutdown(struct device *dev) { struct cxl_memdev *cxlmd = to_cxl_memdev(dev); struct cxl_memdev_state *mds = to_cxl_memdev_state(cxlmd->cxlds); - if (mds->security.poll) - cancel_delayed_work_sync(&mds->security.poll_dwork); + if (mds->bgcmd.poll) + cancel_delayed_work_sync(&mds->bgcmd.poll_dwork); } static void cxl_memdev_shutdown(struct device *dev) @@ -551,7 +551,7 @@ static void cxl_memdev_shutdown(struct device *dev) struct cxl_memdev *cxlmd = to_cxl_memdev(dev); down_write(&cxl_memdev_rwsem); - cxl_memdev_security_shutdown(dev); + cxl_memdev_bgcmd_shutdown(dev); cxlmd->cxlds = NULL; up_write(&cxl_memdev_rwsem); } diff --git a/drivers/cxl/cxlmem.h b/drivers/cxl/cxlmem.h index 79e99c873ca2..879903a8c822 100644 --- a/drivers/cxl/cxlmem.h +++ b/drivers/cxl/cxlmem.h @@ -100,6 +100,13 @@ static inline struct cxl_ep *cxl_ep_load(struct cxl_port *port, return xa_load(&port->endpoints, (unsigned long)&cxlmd->dev); } +enum cxl_bg_cmd_mode { +#define CXL_BG_CMD_ASYNC BIT_MASK(0) + CXL_BG_CMD_SYNC = 0x00, + CXL_BG_CMD_ASYNC_POLL = 0x01, + CXL_BG_CMD_ASYNC_INT = 0x03 +}; + /** * struct cxl_mbox_cmd - A command to be submitted to hardware. * @opcode: (input) The command set and command submitted to hardware. @@ -113,6 +120,8 @@ static inline struct cxl_ep *cxl_ep_load(struct cxl_port *port, * variable sized output commands, it tells the exact number of bytes * written. * @min_out: (input) internal command output payload size validation + * @bg_mode: (input) The processing mode of a background command. It will be + * valid only when the background command started successfully. * @poll_count: (input) Number of timeouts to attempt. * @poll_interval_ms: (input) Time between mailbox background command polling * interval timeouts. @@ -131,6 +140,7 @@ struct cxl_mbox_cmd { size_t size_in; size_t size_out; size_t min_out; + int bg_mode; int poll_count; int poll_interval_ms; u16 return_code; @@ -346,17 +356,31 @@ struct cxl_fw_state { * struct cxl_security_state - Device security state * * @state: state of last security operation - * @poll: polling for sanitization is enabled, device has no mbox irq support - * @poll_tmo_secs: polling timeout - * @poll_dwork: polling work item * @sanitize_node: sanitation sysfs file to notify */ struct cxl_security_state { unsigned long state; + struct kernfs_node *sanitize_node; +}; + +/** + * struct cxl_bgcmd_state - Device background command state + * + * @poll: polling for background command completion, device has no mbox + * irq support + * @poll_tmo_secs: polling timeout + * @poll_dwork: polling work item + * @opcode: The background command submitted to hardware + * @mode: The background command submitted to hardware + * @complete_node: background command completion file to notify + */ +struct cxl_bgcmd_state { bool poll; int poll_tmo_secs; struct delayed_work poll_dwork; - struct kernfs_node *sanitize_node; + u16 opcode; + int mode; + struct kernfs_node *complete_node; }; /* @@ -460,6 +484,7 @@ struct cxl_memdev_state { struct cxl_poison_state poison; struct cxl_security_state security; struct cxl_fw_state fw; + struct cxl_bgcmd_state bgcmd; struct rcuwait mbox_wait; int (*mbox_send)(struct cxl_memdev_state *mds, diff --git a/drivers/cxl/pci.c b/drivers/cxl/pci.c index 1cb1494c28fe..570fca24ab12 100644 --- a/drivers/cxl/pci.c +++ b/drivers/cxl/pci.c @@ -116,8 +116,6 @@ static bool cxl_mbox_background_complete(struct cxl_dev_state *cxlds) static irqreturn_t cxl_pci_mbox_irq(int irq, void *id) { - u64 reg; - u16 opcode; struct cxl_dev_id *dev_id = id; struct cxl_dev_state *cxlds = dev_id->cxlds; struct cxl_memdev_state *mds = to_cxl_memdev_state(cxlds); @@ -125,13 +123,12 @@ static irqreturn_t cxl_pci_mbox_irq(int irq, void *id) if (!cxl_mbox_background_complete(cxlds)) return IRQ_NONE; - reg = readq(cxlds->regs.mbox + CXLDEV_MBOX_BG_CMD_STATUS_OFFSET); - opcode = FIELD_GET(CXLDEV_MBOX_BG_CMD_COMMAND_OPCODE_MASK, reg); - if (opcode == CXL_MBOX_OP_SANITIZE) { - if (mds->security.sanitize_node) - sysfs_notify_dirent(mds->security.sanitize_node); + if (mds->bgcmd.mode & CXL_BG_CMD_ASYNC) { + if (mds->bgcmd.complete_node) + sysfs_notify_dirent(mds->bgcmd.complete_node); - dev_dbg(cxlds->dev, "Sanitization operation ended\n"); + dev_dbg(cxlds->dev, "Mailbox background operation (0x%04x) ended\n", + mds->bgcmd.opcode); } else { /* short-circuit the wait in __cxl_pci_mbox_send_cmd() */ rcuwait_wake_up(&mds->mbox_wait); @@ -141,28 +138,29 @@ static irqreturn_t cxl_pci_mbox_irq(int irq, void *id) } /* - * Sanitization operation polling mode. + * Background operation polling mode. */ -static void cxl_mbox_sanitize_work(struct work_struct *work) +static void cxl_mbox_bg_work(struct work_struct *work) { struct cxl_memdev_state *mds = - container_of(work, typeof(*mds), security.poll_dwork.work); + container_of(work, typeof(*mds), bgcmd.poll_dwork.work); struct cxl_dev_state *cxlds = &mds->cxlds; mutex_lock(&mds->mbox_mutex); if (cxl_mbox_background_complete(cxlds)) { - mds->security.poll_tmo_secs = 0; + mds->bgcmd.poll_tmo_secs = 0; put_device(cxlds->dev); - if (mds->security.sanitize_node) - sysfs_notify_dirent(mds->security.sanitize_node); + if (mds->bgcmd.complete_node) + sysfs_notify_dirent(mds->bgcmd.complete_node); - dev_dbg(cxlds->dev, "Sanitization operation ended\n"); + dev_dbg(cxlds->dev, "Mailbox background operation (0x%04x) ended\n", + mds->bgcmd.opcode); } else { - int timeout = mds->security.poll_tmo_secs + 10; + int timeout = mds->bgcmd.poll_tmo_secs + 10; - mds->security.poll_tmo_secs = min(15 * 60, timeout); - queue_delayed_work(system_wq, &mds->security.poll_dwork, + mds->bgcmd.poll_tmo_secs = min(15 * 60, timeout); + queue_delayed_work(system_wq, &mds->bgcmd.poll_dwork, timeout * HZ); } mutex_unlock(&mds->mbox_mutex); @@ -234,7 +232,8 @@ static int __cxl_pci_mbox_send_cmd(struct cxl_memdev_state *mds, * 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->bgcmd.poll_tmo_secs > 0 && + mds->bgcmd.opcode == CXL_MBOX_OP_SANITIZE) { if (mbox_cmd->opcode != CXL_MBOX_OP_GET_HEALTH_INFO) return -EBUSY; } @@ -289,31 +288,29 @@ static int __cxl_pci_mbox_send_cmd(struct cxl_memdev_state *mds, u64 bg_status_reg; int i, timeout; - /* - * 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.poll) { + dev_dbg(dev, "Mailbox background operation (0x%04x) started\n", + mbox_cmd->opcode); + + mds->bgcmd.opcode = mbox_cmd->opcode; + mds->bgcmd.mode = mbox_cmd->bg_mode; + + if (mbox_cmd->bg_mode & CXL_BG_CMD_ASYNC) { + if (mbox_cmd->bg_mode == CXL_BG_CMD_ASYNC_POLL || + mds->bgcmd.poll) { /* hold the device throughout */ get_device(cxlds->dev); /* give first timeout a second */ timeout = 1; - mds->security.poll_tmo_secs = timeout; + mds->bgcmd.poll_tmo_secs = timeout; queue_delayed_work(system_wq, - &mds->security.poll_dwork, + &mds->bgcmd.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(&mds->mbox_wait, @@ -460,8 +457,8 @@ static int cxl_pci_setup_mailbox(struct cxl_memdev_state *mds) } mbox_poll: - mds->security.poll = true; - INIT_DELAYED_WORK(&mds->security.poll_dwork, cxl_mbox_sanitize_work); + mds->bgcmd.poll = true; + INIT_DELAYED_WORK(&mds->bgcmd.poll_dwork, cxl_mbox_bg_work); dev_dbg(cxlds->dev, "Mailbox interrupts are unsupported"); return 0; From patchwork Fri Sep 22 13:05:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeongtae Park X-Patchwork-Id: 13395780 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1AC65E6FE22 for ; Fri, 22 Sep 2023 13:03:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232618AbjIVNDY (ORCPT ); Fri, 22 Sep 2023 09:03:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49424 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231894AbjIVNDX (ORCPT ); Fri, 22 Sep 2023 09:03:23 -0400 Received: from mailout1.samsung.com (mailout1.samsung.com [203.254.224.24]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4935B180 for ; Fri, 22 Sep 2023 06:03:17 -0700 (PDT) Received: from epcas2p1.samsung.com (unknown [182.195.41.53]) by mailout1.samsung.com (KnoxPortal) with ESMTP id 20230922130314epoutp018b1fe8e6e4ce9691298dda7f00b14f3b~HOjd3GIon1688716887epoutp01M for ; Fri, 22 Sep 2023 13:03:14 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.samsung.com 20230922130314epoutp018b1fe8e6e4ce9691298dda7f00b14f3b~HOjd3GIon1688716887epoutp01M DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1695387794; bh=sXnICAZzbwBeu6cGhlbscfT82TuFcSoq+DcuINfYYu0=; h=From:To:Cc:Subject:Date:References:From; b=tZyK7oSfuSWCzys6eC4lnTZUp0oSL2uNW24YyRi5FcPtyFy1ch09gzhwvhQPPIW4F HJmdHefMIrUwKxdVo1PUBf8bwxv5CEc1rDCwW0I4bcB5p0garwgutFcd60UjuGkoXP s+OdNlWYx9aCI8gE1xhaMW6yIQDWUUTDhGb+J6ME= Received: from epsnrtp4.localdomain (unknown [182.195.42.165]) by epcas2p3.samsung.com (KnoxPortal) with ESMTP id 20230922130314epcas2p396869699df5e497b7e72533c004c6496~HOjdSFy5Y0783307833epcas2p3R; Fri, 22 Sep 2023 13:03:14 +0000 (GMT) Received: from epsmges2p1.samsung.com (unknown [182.195.36.89]) by epsnrtp4.localdomain (Postfix) with ESMTP id 4RsXWP1qrvz4x9Pq; Fri, 22 Sep 2023 13:03:13 +0000 (GMT) Received: from epcas2p1.samsung.com ( [182.195.41.53]) by epsmges2p1.samsung.com (Symantec Messaging Gateway) with SMTP id 8D.65.09693.1909D056; Fri, 22 Sep 2023 22:03:13 +0900 (KST) Received: from epsmtrp2.samsung.com (unknown [182.195.40.14]) by epcas2p1.samsung.com (KnoxPortal) with ESMTPA id 20230922130311epcas2p1ef59a510027060360e98e5c6a31a1198~HOjbVuvbK0857408574epcas2p1R; Fri, 22 Sep 2023 13:03:11 +0000 (GMT) Received: from epsmgms1p2new.samsung.com (unknown [182.195.42.42]) by epsmtrp2.samsung.com (KnoxPortal) with ESMTP id 20230922130311epsmtrp2e867fedf727deb829afed1210a1a3a26~HOjbU1P2o1524315243epsmtrp2F; Fri, 22 Sep 2023 13:03:11 +0000 (GMT) X-AuditID: b6c32a45-abbfd700000025dd-60-650d909126f8 Received: from epsmtip1.samsung.com ( [182.195.34.30]) by epsmgms1p2new.samsung.com (Symantec Messaging Gateway) with SMTP id 42.69.08788.F809D056; Fri, 22 Sep 2023 22:03:11 +0900 (KST) Received: from jtpark-7920.dsn.sec.samsung.com (unknown [10.229.83.56]) by epsmtip1.samsung.com (KnoxPortal) with ESMTPA id 20230922130311epsmtip1826dd7f3ea786c28e58dcfaf6c106c49~HOjbCrQnY2258922589epsmtip19; Fri, 22 Sep 2023 13:03:11 +0000 (GMT) From: Jeongtae Park To: linux-cxl@vger.kernel.org Cc: Dan Williams , Alison Schofield , Vishal Verma , Ben Widawsky , Jonathan Cameron , Dave Jiang , Davidlohr Bueso , Fan Ni , Kyungsan Kim , Wonjae Lee , Hojin Nam , Junhyeok Im , Jehoon Park , Jeongtae Park , Jeongtae Park Subject: [RFC PATCH 2/3] cxl/mbox: Update sanitize opcode support Date: Fri, 22 Sep 2023 22:05:57 +0900 Message-Id: <20230922130557.3476469-1-jtp.park@samsung.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA01TfUwTZxzO2yvXg6zLrTr2hmQUb5ubJIWWAT1UNjaFNGGLEJh/OBie7QmE cr20xShxoaw40UXGR7BYAmMgcRStrgNXGSKUVoaDDVyBAKEqQ/wa2AhsEx1b28PN/57f83ue 38f7gSGiTjQMy2f0tJah1AQawr/YvyVOUlUppKWt3QJy5rcRlDTWtADSVDsCyB8nS1GyffIs ID9rnwkivb+v8cneBwYBOTR8L4i0fD2Oks5zYzyyxVWHkK5ujPzFfI1PTlVe5ZHf3lhEk3DF JfOMQFHmXAhStHTf4ylslmOooqLDAhS19SWKJVt4mmBPwfY8mlLR2giaUWpU+UxuIpGakbMj Jy5eKpPIEkg5EcFQhXQisfODNElKvto3OxFxgFIX+ag0Sqcjot/ZrtUU6emIPI1On0jQrErN ytkoHVWoK2Jyoxhav1UmlcbE+YR7C/JsQ0dR1iQ4uLpSDgzgz6DjIBiDeCxcmS314RBMhNsB nK9wIVzwCEDLie9QLvgDwH9MD8EzS89Ao4BLXAbw6PzAuv8pgH1DTahfheKR0HTKEGiyEX8V Gq03eX4Rgo/xYfW1UZ4/sQF/D7rHVn0iDOPjb8Dyp5v8tBDfBi88buJx3cTwSt8wwvEvwcFT c3w/Rny8sbM+MCvEGzDonpgI1IH4Trjqiea8G+D9gQ4Bh8Pg0uJllNMbAXxwx83ngjIArdP2 ddXbcHHyTqAQgm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xglUwuKc9Nziw0LjPJSy/WKE3OLS/PS9ZLzczcx giNCS2sH455VH/QOMTJxMB5ilOBgVhLhTf7ElSrEm5JYWZValB9fVJqTWnyIUZqDRUmc99vr 3hQhgfTEktTs1NSC1CKYLBMHp1QDU5vt5dKHbQ3Na93eZLuG5yRufnbX5M3m1acXG647NuFa yRKDnl2dotcWGfqVFQg83r6accKUrz0mdY1TP1fxPHbaGXDkxANWhYCi+7/Ewx8FSOhP9DJr XZ9bs1426axvyjONXf8Dj03Pdubo53jL91vZqffWVeXZd9gvaW1RLrewclwq3KrXvvYhj7Tx lSzFlTMer31SYzB/2ZvvRU9um/POWP4xY593V7vWsa69HkkPr4rqzpdqYfJ8pneu2ND/yvVY 7c3/mdhaQrRtLpzqzL9k8OJZQkdickmneg/H6aYD9tsfWR1xipC5+PdJqXZm/B/1r0LzH7rq ySst3iSZL5xvlypnMD/+T+pDjp3KSizFGYmGWsxFxYkAmgoas/cCAAA= X-CMS-MailID: 20230922130311epcas2p1ef59a510027060360e98e5c6a31a1198 X-Msg-Generator: CA X-Sendblock-Type: AUTO_CONFIDENTIAL CMS-TYPE: 102P DLP-Filter: Pass X-CFilter-Loop: Reflected X-CMS-RootMailID: 20230922130311epcas2p1ef59a510027060360e98e5c6a31a1198 References: Precedence: bulk List-ID: X-Mailing-List: linux-cxl@vger.kernel.org This patch adds bgmode to the existing sanitize command. By adding it, the sanitize operation will work the same as before. Signed-off-by: Jeongtae Park Signed-off-by: Hojin Nam --- drivers/cxl/core/mbox.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/cxl/core/mbox.c b/drivers/cxl/core/mbox.c index d6d067fbee97..2a7c12950a1e 100644 --- a/drivers/cxl/core/mbox.c +++ b/drivers/cxl/core/mbox.c @@ -1106,7 +1106,10 @@ int cxl_mem_sanitize(struct cxl_memdev_state *mds, u16 cmd) .payload_out = &out, .size_out = sizeof(out), }; - struct cxl_mbox_cmd mbox_cmd = { .opcode = cmd }; + struct cxl_mbox_cmd mbox_cmd = { + .opcode = cmd, + .bg_mode = CXL_BG_CMD_ASYNC_INT, + }; struct cxl_dev_state *cxlds = &mds->cxlds; if (cmd != CXL_MBOX_OP_SANITIZE && cmd != CXL_MBOX_OP_SECURE_ERASE) From patchwork Fri Sep 22 13:06:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeongtae Park X-Patchwork-Id: 13395781 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3492EE6FE22 for ; Fri, 22 Sep 2023 13:03:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232760AbjIVNDc (ORCPT ); Fri, 22 Sep 2023 09:03:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60180 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231894AbjIVNDc (ORCPT ); Fri, 22 Sep 2023 09:03:32 -0400 Received: from mailout4.samsung.com (mailout4.samsung.com [203.254.224.34]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C2A4BCE for ; Fri, 22 Sep 2023 06:03:25 -0700 (PDT) Received: from epcas2p3.samsung.com (unknown [182.195.41.55]) by mailout4.samsung.com (KnoxPortal) with ESMTP id 20230922130323epoutp045a3d4a1235cb9ae13a852c286b923761~HOjmbzPMl1726017260epoutp04q for ; Fri, 22 Sep 2023 13:03:23 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout4.samsung.com 20230922130323epoutp045a3d4a1235cb9ae13a852c286b923761~HOjmbzPMl1726017260epoutp04q DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1695387803; bh=EL5l6JcR8uz02ZxFBoH5zh+xdym7MBRL+lVUs5ih56U=; h=From:To:Cc:Subject:Date:References:From; b=AmkYpTMgo9XNFyjqbpYy6ie1qVZwI/Ya8eboU3T1InLNRNfFz3P1TEAMHha8eu3GQ WEsp5sSC7OL3LuuKAN/S+NKImuicY2n7rr/eUoyX6k4YDaobEh1SPphi5mCMaLHP8u zlzxOuyZPk46DY+SmkecTPQ7zJUEJxIk1UByJwRU= Received: from epsnrtp1.localdomain (unknown [182.195.42.162]) by epcas2p4.samsung.com (KnoxPortal) with ESMTP id 20230922130322epcas2p4c8967cdd4d899eff396b672b7333d615~HOjlRSHf10828508285epcas2p4O; Fri, 22 Sep 2023 13:03:22 +0000 (GMT) Received: from epsmges2p3.samsung.com (unknown [182.195.36.101]) by epsnrtp1.localdomain (Postfix) with ESMTP id 4RsXWZ0991z4x9Pr; Fri, 22 Sep 2023 13:03:22 +0000 (GMT) Received: from epcas2p3.samsung.com ( [182.195.41.55]) by epsmges2p3.samsung.com (Symantec Messaging Gateway) with SMTP id C4.5E.09660.9909D056; Fri, 22 Sep 2023 22:03:21 +0900 (KST) Received: from epsmtrp1.samsung.com (unknown [182.195.40.13]) by epcas2p1.samsung.com (KnoxPortal) with ESMTPA id 20230922130321epcas2p1e3041a8a284e8aa3a3b203ca3380d1db~HOjj7o6Zz0857408574epcas2p1e; Fri, 22 Sep 2023 13:03:21 +0000 (GMT) Received: from epsmgms1p1new.samsung.com (unknown [182.195.42.41]) by epsmtrp1.samsung.com (KnoxPortal) with ESMTP id 20230922130321epsmtrp12ab3a154baca50fac543402f21abcc6a~HOjj6vgNI3218332183epsmtrp1N; Fri, 22 Sep 2023 13:03:21 +0000 (GMT) X-AuditID: b6c32a47-d5dfa700000025bc-19-650d90994bdf Received: from epsmtip1.samsung.com ( [182.195.34.30]) by epsmgms1p1new.samsung.com (Symantec Messaging Gateway) with SMTP id AC.49.08742.8909D056; Fri, 22 Sep 2023 22:03:21 +0900 (KST) Received: from jtpark-7920.dsn.sec.samsung.com (unknown [10.229.83.56]) by epsmtip1.samsung.com (KnoxPortal) with ESMTPA id 20230922130320epsmtip166f855430e449cdd68995e44b1c28f38~HOjjpyw5f2684526845epsmtip1d; Fri, 22 Sep 2023 13:03:20 +0000 (GMT) From: Jeongtae Park To: linux-cxl@vger.kernel.org Cc: Dan Williams , Alison Schofield , Vishal Verma , Ben Widawsky , Jonathan Cameron , Dave Jiang , Davidlohr Bueso , Fan Ni , Kyungsan Kim , Wonjae Lee , Hojin Nam , Junhyeok Im , Jehoon Park , Jeongtae Park , Jeongtae Park Subject: [RFC PATCH 3/3] cxl/memdev: Add background command sysfs file Date: Fri, 22 Sep 2023 22:06:07 +0900 Message-Id: <20230922130607.3476828-1-jtp.park@samsung.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrKJsWRmVeSWpSXmKPExsWy7bCmue7MCbypBm+umlncfXyBzaJ58mJG i+lTLzBanLjZyGax+uYaRoum1XdZLT68+cdiceB1A7vFmbMvWS1WLbzGZnFk7VUmi8VHZzBb HN3DYXF+1ikWi1sTjjFZbLz/js1BwGPnrLvsHi1H3rJ6LN7zkslj06pONo++LasYPabOrvf4 vEkugD0q2yYjNTEltUghNS85PyUzL91WyTs43jne1MzAUNfQ0sJcSSEvMTfVVsnFJ0DXLTMH 6HYlhbLEnFKgUEBicbGSvp1NUX5pSapCRn5xia1SakFKToF5gV5xYm5xaV66Xl5qiZWhgYGR KVBhQnbGu13TmAvmqFT0919haWDcJ9fFyMkhIWAice3xXZYuRi4OIYEdjBIr/pyCcj4xSrRu ncsI4XxjlGjZe50VpuX9tpvMEIm9jBILdkxiBEkICfxhlJh4zA7EZhPQkpg+swGsQURAVqJ5 3QMmkAZmgassEpNOXWQCSQgLuEn8mvWPDcRmEVCVaL52CyzOK2At8bBpNQvENnmJ/QfPMkPE BSVOznwCFmcGijdvnQ12hYTATA6Jk5POA13BAeS4SCxs5oPoFZZ4dXwLO4QtJfGyv40d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SjRfuwU2lVfAWuJh02oWiA3yEvsPnmWGiAtKnJz5 BCzODBRv3jqbeQIj3ywkqVlIUgsYmVYxSqYWFOem5xYbFhjmpZbrFSfmFpfmpesl5+duYgTH hJbmDsbtqz7oHWJk4mA8xCjBwawkwpv8iStViDclsbIqtSg/vqg0J7X4EKM0B4uSOK/4i94U IYH0xJLU7NTUgtQimCwTB6dUA9OCiipP3cLXF3PKV9kdX2HBsnbfhp+5V7RjLW+kC3ZZXjU1 jvf+e8OvzHMHL+PZfn+RoldJLg12VqtSZfccWTJjlVTLhAP9D+7f/ty9QfzLEYvdCz5s83VS 4uL/NknW+vKCb5pBV0OF5x3Y1iJ8uT/1crdXnf2x1NVfdhxuCfxzhEHuT3MNL8tzoYCw14e/ lRiZmar/lJlWf/dH/Tb28iu2zwLc3kasP/rkv+Wqm1bFfzXDTZ/OSO+cotahJH/7lIZrsYO9 rSDn7bPcK2Tn90R1dFtlmoR+5Sz5pihuf9s52DbDyCj0fK9Gf/jFfbfY1CKMU8OW7klivbF8 QevOs3vmTTqheKH0cvfCHZkKukosxRmJhlrMRcWJACj1UTz4AgAA X-CMS-MailID: 20230922130321epcas2p1e3041a8a284e8aa3a3b203ca3380d1db X-Msg-Generator: CA X-Sendblock-Type: AUTO_CONFIDENTIAL CMS-TYPE: 102P DLP-Filter: Pass X-CFilter-Loop: Reflected X-CMS-RootMailID: 20230922130321epcas2p1e3041a8a284e8aa3a3b203ca3380d1db References: Precedence: bulk List-ID: X-Mailing-List: linux-cxl@vger.kernel.org Add a read-only sysfs file to notify the background command state of a device: /sys/bus/cxl/devices/memX/bgcmd/complete Signed-off-by: Jeongtae Park Signed-off-by: Hojin Nam --- Documentation/ABI/testing/sysfs-bus-cxl | 10 ++++ drivers/cxl/core/memdev.c | 63 +++++++++++++++++++++++++ 2 files changed, 73 insertions(+) diff --git a/Documentation/ABI/testing/sysfs-bus-cxl b/Documentation/ABI/testing/sysfs-bus-cxl index 6350dd82b9a9..e9773f20deac 100644 --- a/Documentation/ABI/testing/sysfs-bus-cxl +++ b/Documentation/ABI/testing/sysfs-bus-cxl @@ -477,3 +477,13 @@ Description: attribute is only visible for devices supporting the capability. The retrieved errors are logged as kernel events when cxl_poison event tracing is enabled. + +What: /sys/bus/cxl/devices/memX/bgcmd/complete +Date: September, 2023 +KernelVersion: v6.6 +Contact: linux-cxl@vger.kernel.org +Description: + (RO) This file can be used to read the processing status of + background commands. When a background command starts successfully, + it represents the progress as a percentage, and when it finishes, + userspace can read the opcode of a completed background operations. diff --git a/drivers/cxl/core/memdev.c b/drivers/cxl/core/memdev.c index 8d1692231767..ba23ef6b6278 100644 --- a/drivers/cxl/core/memdev.c +++ b/drivers/cxl/core/memdev.c @@ -201,6 +201,24 @@ static ssize_t security_erase_store(struct device *dev, static struct device_attribute dev_attr_security_erase = __ATTR(erase, 0200, NULL, security_erase_store); +static ssize_t bgcmd_complete_show(struct device *dev, + struct device_attribute *attr, + char *buf) +{ + struct cxl_memdev *cxlmd = to_cxl_memdev(dev); + struct cxl_dev_state *cxlds = cxlmd->cxlds; + u64 reg = readq(cxlds->regs.mbox + CXLDEV_MBOX_BG_CMD_STATUS_OFFSET); + u32 pct = FIELD_GET(CXLDEV_MBOX_BG_CMD_COMMAND_PCT_MASK, reg); + u16 cmd = FIELD_GET(CXLDEV_MBOX_BG_CMD_COMMAND_OPCODE_MASK, reg); + + if (pct == 100) + return sysfs_emit(buf, "0x%04x\n", cmd); + else + return sysfs_emit(buf, "%3u\n", pct); +} +static struct device_attribute dev_attr_bgcmd_complete = + __ATTR(complete, 0444, bgcmd_complete_show, NULL); + static int cxl_get_poison_by_memdev(struct cxl_memdev *cxlmd) { struct cxl_dev_state *cxlds = cxlmd->cxlds; @@ -454,6 +472,11 @@ static struct attribute *cxl_memdev_security_attributes[] = { NULL, }; +static struct attribute *cxl_memdev_bgcmd_attributes[] = { + &dev_attr_bgcmd_complete.attr, + NULL, +}; + static umode_t cxl_memdev_visible(struct kobject *kobj, struct attribute *a, int n) { @@ -482,11 +505,17 @@ static struct attribute_group cxl_memdev_security_attribute_group = { .attrs = cxl_memdev_security_attributes, }; +static struct attribute_group cxl_memdev_bgcmd_attribute_group = { + .name = "bgcmd", + .attrs = cxl_memdev_bgcmd_attributes, +}; + static const struct attribute_group *cxl_memdev_attribute_groups[] = { &cxl_memdev_attribute_group, &cxl_memdev_ram_attribute_group, &cxl_memdev_pmem_attribute_group, &cxl_memdev_security_attribute_group, + &cxl_memdev_bgcmd_attribute_group, NULL, }; @@ -1012,6 +1041,36 @@ static int cxl_memdev_security_init(struct cxl_memdev *cxlmd) return devm_add_action_or_reset(cxlds->dev, put_sanitize, mds); } +static void put_bgcmd(void *data) +{ + struct cxl_memdev_state *mds = data; + + sysfs_put(mds->bgcmd.complete_node); +} + +static int cxl_memdev_bgcmd_init(struct cxl_memdev *cxlmd) +{ + struct cxl_dev_state *cxlds = cxlmd->cxlds; + struct cxl_memdev_state *mds = to_cxl_memdev_state(cxlds); + struct device *dev = &cxlmd->dev; + struct kernfs_node *bg; + + bg = sysfs_get_dirent(dev->kobj.sd, "bgcmd"); + if (!bg) { + dev_err(dev, "sysfs_get_dirent 'bgcmd' failed\n"); + return -ENODEV; + } + + mds->bgcmd.complete_node = sysfs_get_dirent(bg, "complete"); + sysfs_put(bg); + if (!mds->bgcmd.complete_node) { + dev_err(dev, "sysfs_get_dirent 'complete' failed\n"); + return -ENODEV; + } + + return devm_add_action_or_reset(cxlds->dev, put_bgcmd, mds); +} + struct cxl_memdev *devm_cxl_add_memdev(struct cxl_dev_state *cxlds) { struct cxl_memdev *cxlmd; @@ -1044,6 +1103,10 @@ struct cxl_memdev *devm_cxl_add_memdev(struct cxl_dev_state *cxlds) if (rc) goto err; + rc = cxl_memdev_bgcmd_init(cxlmd); + if (rc) + goto err; + rc = devm_add_action_or_reset(cxlds->dev, cxl_memdev_unregister, cxlmd); if (rc) return ERR_PTR(rc);