From patchwork Wed May 17 03:23:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Junhyeok Im X-Patchwork-Id: 13244126 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 A8E93C77B7A for ; Wed, 17 May 2023 03:24:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231656AbjEQDYB (ORCPT ); Tue, 16 May 2023 23:24:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54084 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231565AbjEQDYA (ORCPT ); Tue, 16 May 2023 23:24:00 -0400 Received: from mailout3.samsung.com (mailout3.samsung.com [203.254.224.33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6FDBC1FCD for ; Tue, 16 May 2023 20:23:58 -0700 (PDT) Received: from epcas2p3.samsung.com (unknown [182.195.41.55]) by mailout3.samsung.com (KnoxPortal) with ESMTP id 20230517032356epoutp03447bafb9f15f22c8e9aaf6366439e9bf~f0FIos0Au1321113211epoutp03c for ; Wed, 17 May 2023 03:23:56 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout3.samsung.com 20230517032356epoutp03447bafb9f15f22c8e9aaf6366439e9bf~f0FIos0Au1321113211epoutp03c DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1684293836; bh=8Zzb02ZjSAu/dJG89FoPovJc75d06VRpaBJeAo0Fgd0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FKNX5vQ9RO64TdpqvqizXAXAYkRLwiEBMkRqy3MKwl5QVXeahqgPBuDXRroHF1A7E SBKzMJzZAl0jeBZ6INW2UkG+dSCPZYDWmEEbEKlKa79UXE24tIBzaSOhUtKw5mlgID 2ft+xhW0K201wL87D0UiALKzioRpWBbXJc98ifIs= Received: from epsnrtp3.localdomain (unknown [182.195.42.164]) by epcas2p3.samsung.com (KnoxPortal) with ESMTP id 20230517032355epcas2p37cf22a7ab0ffcf5bf614e099d4c1e95c~f0FHU2Gsq0983209832epcas2p33; Wed, 17 May 2023 03:23:55 +0000 (GMT) Received: from epsmges2p1.samsung.com (unknown [182.195.36.98]) by epsnrtp3.localdomain (Postfix) with ESMTP id 4QLdk271hSz4x9Pt; Wed, 17 May 2023 03:23:54 +0000 (GMT) Received: from epcas2p2.samsung.com ( [182.195.41.54]) by epsmges2p1.samsung.com (Symantec Messaging Gateway) with SMTP id AA.9A.03265.AC844646; Wed, 17 May 2023 12:23:54 +0900 (KST) Received: from epsmtrp2.samsung.com (unknown [182.195.40.14]) by epcas2p4.samsung.com (KnoxPortal) with ESMTPA id 20230517032354epcas2p402be25cecb758d5a3d8e477fa5efac99~f0FGgebGw1792117921epcas2p43; Wed, 17 May 2023 03:23:54 +0000 (GMT) Received: from epsmgms1p1new.samsung.com (unknown [182.195.42.41]) by epsmtrp2.samsung.com (KnoxPortal) with ESMTP id 20230517032354epsmtrp22064cdc194bf17fe88b0f7fadd7ef9f0~f0FGf322w0097500975epsmtrp2X; Wed, 17 May 2023 03:23:54 +0000 (GMT) X-AuditID: b6c32a45-6d1fd70000020cc1-1e-646448ca3384 Received: from epsmtip2.samsung.com ( [182.195.34.31]) by epsmgms1p1new.samsung.com (Symantec Messaging Gateway) with SMTP id 31.16.27706.AC844646; Wed, 17 May 2023 12:23:54 +0900 (KST) Received: from dell-ArcherCity.dsn.sec.samsung.com (unknown [10.229.83.212]) by epsmtip2.samsung.com (KnoxPortal) with ESMTPA id 20230517032354epsmtip2ad7f986ba790d098606c34a57681b3a9~f0FGSLFf81034810348epsmtip2Q; Wed, 17 May 2023 03:23:54 +0000 (GMT) From: Junhyeok Im To: linux-cxl@vger.kernel.org Cc: vishal.l.verma@intel.com, dan.j.williams@intel.com, bwidawsk@kernel.org, alison.schofield@intel.com, ira.weiny@intel.com, ks0204.kim@samsung.com, Junhyeok Im Subject: [ndctl PATCH v2 1/2] libcxl: Add memdev inject & clear poison support Date: Wed, 17 May 2023 12:23:10 +0900 Message-Id: <20230517032311.19923-2-junhyeok.im@samsung.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230517032311.19923-1-junhyeok.im@samsung.com> MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFupmk+LIzCtJLcpLzFFi42LZdljTTPeUR0qKwdpn5hZ3H19gs2ievJjR YvrUC4wW+58+Z7FYfHQGs8XRPRwW52edYrG4NeEYkwOHx+I9L5k8Nq3qZPPo27KK0ePzJrkA lqhsm4zUxJTUIoXUvOT8lMy8dFsl7+B453hTMwNDXUNLC3MlhbzE3FRbJRefAF23zBygK5QU yhJzSoFCAYnFxUr6djZF+aUlqQoZ+cUltkqpBSk5BeYFesWJucWleel6eaklVoYGBkamQIUJ 2RnHJzSxF8xXqzi98xdbA+Np+S5GTg4JAROJ43u7mLsYuTiEBHYwSvS8+cAG4XxilNj79hQL hPONUeL/l5NMMC1LZ81lgkjsZZRYf/E2VFUjk0TDqr8sIFVsAtoSf/unM4LYIgKyEs3rHoB1 MAvsZ5RYsXMLG0hCWCBA4v7ZM0BFHBwsAqoSh/55goR5BWwk5p28yQixTV5i/8GzzCA2p4Ct xNHdrWwQNYISJ2c+AdvFDFTTvHU22BMSAj/ZJRZO2sUM0ewiseLHHDYIW1ji1fEt7BC2lMTn d3uh4vkSUw9OhIqXSLSdOQBlG0u8u/mcFeQ2ZgFNifW79EFMCQFliSO3oNbySXQc/ssOEeaV 6GgTgmhUldiy4QXUEGmJoxM3sUDYHhKrV75ihwTVBEaJe0/fsUxgVJiF5JtZSL6ZhbB4ASPz Kkax1ILi3PTUYqMCQ3gMJ+fnbmIEp0ot1x2Mk99+0DvEyMTBeIhRgoNZS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X/D vG2tht75W2q1XU5hSerxJW+3iy/oZcxoCl0ZuqZ0ieo6B2t9lQoW5iMbV6eciN1vPU1pzqej R743MjyWDDZ4zLBkpuDyV2+vSBmG3mfv2fxro9Vlc7Ybn+xrzWPqvi5aEv3dfovEmavc6zpn /ojUtMw0uBvs8zXlatT71svtzK/WTg6aPL0irf+nardAyAxBdtu0Z7es2Y/zLjj0eHMGY1zw TM/nR+f1G9bcUtqoLH8vqH3n0TkrN1ekrmVR/D/RwkrUmycyQsCY4TbP5rZnKQnba7/1mtv/ ncZybPN/NTaJBOcYXrF355PXhW3M6PpqLSAg7XwvyGZT/L8ZZSJJnIXB4pVHH+8tVWIpzkg0 1GIuKk4EAHwPRyruAgAA X-CMS-MailID: 20230517032354epcas2p402be25cecb758d5a3d8e477fa5efac99 X-Msg-Generator: CA X-Sendblock-Type: AUTO_CONFIDENTIAL CMS-TYPE: 102P DLP-Filter: Pass X-CFilter-Loop: Reflected X-CMS-RootMailID: 20230517032354epcas2p402be25cecb758d5a3d8e477fa5efac99 References: <20230517032311.19923-1-junhyeok.im@samsung.com> Precedence: bulk List-ID: X-Mailing-List: linux-cxl@vger.kernel.org Add abilities to inject and clear poison to memdev based on the debugfs (/sys/kernel/debug/cxl/memX/{inject_/clear_}poison) interfaces that target kernel v6.4[1]. These interfaces trigger inject/clear poison function by writing DPA to the memory device debugfs attributes. In order to write the DPA in the debugfs attribute, 'sysfs_write_attr' macro is used which already defined. Signed-off-by: Junhyeok Im [1] https://lore.kernel.org/linux-cxl/cover.1681874357.git.alison.schofield@intel.com/ --- Documentation/cxl/lib/libcxl.txt | 5 +++ cxl/lib/libcxl.c | 53 ++++++++++++++++++++++++++++++++ cxl/lib/libcxl.sym | 6 ++++ cxl/libcxl.h | 2 ++ 4 files changed, 66 insertions(+) diff --git a/Documentation/cxl/lib/libcxl.txt b/Documentation/cxl/lib/libcxl.txt index 31bc855..24a2535 100644 --- a/Documentation/cxl/lib/libcxl.txt +++ b/Documentation/cxl/lib/libcxl.txt @@ -132,6 +132,8 @@ int cxl_memdev_read_label(struct cxl_memdev *memdev, void *buf, size_t length, size_t offset); int cxl_memdev_write_label(struct cxl_memdev *memdev, void *buf, size_t length, size_t offset); +int cxl_memdev_inject_poison(struct cxl_memdev *memdev, const char *address); +int cxl_memdev_clear_poison(struct cxl_memdev *memdev, const char *address); struct cxl_cmd *cxl_cmd_new_get_partition(struct cxl_memdev *memdev); struct cxl_cmd *cxl_cmd_new_set_partition(struct cxl_memdev *memdev, unsigned long long volatile_size); @@ -172,6 +174,9 @@ cxl_memdev{read,write,zero}_label() are helpers for marshaling multiple label access commands over an arbitrary extent of the device's label area. +cxl_memdev_{inject,clear}_poison() support injecting/clearing poison +into/from a physical address on a specified CXL memory device. + cxl_cmd_partition_set_mode() supports selecting NEXTBOOT or IMMEDIATE mode. When CXL_SETPART_IMMEDIATE mode is set, it is the caller’s responsibility to avoid immediate changes to partitioning when the diff --git a/cxl/lib/libcxl.c b/cxl/lib/libcxl.c index 769cd8a..b2d0642 100644 --- a/cxl/lib/libcxl.c +++ b/cxl/lib/libcxl.c @@ -1458,6 +1458,59 @@ CXL_EXPORT int cxl_memdev_enable(struct cxl_memdev *memdev) return 0; } +#define PATH_DEBUG_FS "/sys/kernel/debug/cxl" +CXL_EXPORT int cxl_memdev_inject_poison(struct cxl_memdev *memdev, + const char *address) +{ + struct cxl_ctx *ctx = cxl_memdev_get_ctx(memdev); + char *path = memdev->dev_buf; + int len = memdev->buf_len, rc; + + if (snprintf(path, len, "%s/%s/inject_poison", PATH_DEBUG_FS, + cxl_memdev_get_devname(memdev)) >= len) { + err(ctx, "%s: buffer too small\n", + cxl_memdev_get_devname(memdev)); + return -ENXIO; + } + rc = sysfs_write_attr(ctx, path, address); + if (rc < 0) { + err(ctx, "%s: failed to inject poison\n", + cxl_memdev_get_devname(memdev)); + return rc; + } + + dbg(ctx, "%s: poison injected at %s\n", cxl_memdev_get_devname(memdev), + address); + + return 0; +} + +CXL_EXPORT int cxl_memdev_clear_poison(struct cxl_memdev *memdev, + const char *address) +{ + struct cxl_ctx *ctx = cxl_memdev_get_ctx(memdev); + char *path = memdev->dev_buf; + int len = memdev->buf_len, rc; + + if (snprintf(path, len, "%s/%s/clear_poison", PATH_DEBUG_FS, + cxl_memdev_get_devname(memdev)) >= len) { + err(ctx, "%s: buffer too small\n", + cxl_memdev_get_devname(memdev)); + return -ENXIO; + } + rc = sysfs_write_attr(ctx, path, address); + if (rc < 0) { + err(ctx, "%s: failed to clear poison\n", + cxl_memdev_get_devname(memdev)); + return rc; + } + + dbg(ctx, "%s: poison cleared at %s\n", cxl_memdev_get_devname(memdev), + address); + + return 0; +} + static struct cxl_endpoint * cxl_port_recurse_endpoint(struct cxl_port *parent_port, struct cxl_memdev *memdev) diff --git a/cxl/lib/libcxl.sym b/cxl/lib/libcxl.sym index c6545c7..0f312a5 100644 --- a/cxl/lib/libcxl.sym +++ b/cxl/lib/libcxl.sym @@ -250,3 +250,9 @@ global: cxl_region_get_daxctl_region; cxl_port_get_parent_dport; } LIBCXL_4; + +LIBCXL_6 { +global: + cxl_memdev_inject_poison; + cxl_memdev_clear_poison; +} LIBCXL_5; diff --git a/cxl/libcxl.h b/cxl/libcxl.h index 0218d73..e3b2524 100644 --- a/cxl/libcxl.h +++ b/cxl/libcxl.h @@ -68,6 +68,8 @@ int cxl_memdev_read_label(struct cxl_memdev *memdev, void *buf, size_t length, size_t offset); int cxl_memdev_write_label(struct cxl_memdev *memdev, void *buf, size_t length, size_t offset); +int cxl_memdev_inject_poison(struct cxl_memdev *memdev, const char *address); +int cxl_memdev_clear_poison(struct cxl_memdev *memdev, const char *address); #define cxl_memdev_foreach(ctx, memdev) \ for (memdev = cxl_memdev_get_first(ctx); \ From patchwork Wed May 17 03:23:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Junhyeok Im X-Patchwork-Id: 13244127 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 6383BC77B7D for ; Wed, 17 May 2023 03:24:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231485AbjEQDYL (ORCPT ); Tue, 16 May 2023 23:24:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54150 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231683AbjEQDYJ (ORCPT ); Tue, 16 May 2023 23:24:09 -0400 Received: from mailout2.samsung.com (mailout2.samsung.com [203.254.224.25]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 432911FFB for ; Tue, 16 May 2023 20:24:07 -0700 (PDT) Received: from epcas2p3.samsung.com (unknown [182.195.41.55]) by mailout2.samsung.com (KnoxPortal) with ESMTP id 20230517032404epoutp02d4b32807da93f62b1b3fda3569ca34a1~f0FPynacw1878518785epoutp02N for ; Wed, 17 May 2023 03:24:04 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.samsung.com 20230517032404epoutp02d4b32807da93f62b1b3fda3569ca34a1~f0FPynacw1878518785epoutp02N DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1684293844; bh=Q4LyMhdnIFcxDHL0z0+MFUfEZnso5D9xr3asQfzYsso=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Zlbs9Or1SNp7CS0TSwvxkT7Jys8lpYMqMM6emEU7Hb+k2P9pgFTuoJmJqETIy/Hrv Sgd8Zmvpo/gAewFu2FSkxlR71vDu10GprzfPAqSUzAdvONqS9mAJiPttJPC32SoHKi n199OofaC03s9eeH5zoCcRCycuircZ3ZHDocqDfY= Received: from epsnrtp2.localdomain (unknown [182.195.42.163]) by epcas2p1.samsung.com (KnoxPortal) with ESMTP id 20230517032404epcas2p1c3d394a24e127c5d2f60631b6fdc8301~f0FPbj0SN0857808578epcas2p1R; Wed, 17 May 2023 03:24:04 +0000 (GMT) Received: from epsmges2p2.samsung.com (unknown [182.195.36.68]) by epsnrtp2.localdomain (Postfix) with ESMTP id 4QLdkC5CpRz4x9Py; Wed, 17 May 2023 03:24:03 +0000 (GMT) Received: from epcas2p2.samsung.com ( [182.195.41.54]) by epsmges2p2.samsung.com (Symantec Messaging Gateway) with SMTP id 1B.A2.17293.3D844646; Wed, 17 May 2023 12:24:03 +0900 (KST) Received: from epsmtrp2.samsung.com (unknown [182.195.40.14]) by epcas2p4.samsung.com (KnoxPortal) with ESMTPA id 20230517032403epcas2p48fbabf7aec3334b4892c87265b1a7705~f0FOogDhX3043130431epcas2p4f; Wed, 17 May 2023 03:24:03 +0000 (GMT) Received: from epsmgms1p2.samsung.com (unknown [182.195.42.42]) by epsmtrp2.samsung.com (KnoxPortal) with ESMTP id 20230517032403epsmtrp2965fb1a5131c536cab6a4cf64cf3dd76~f0FOn21uv0097500975epsmtrp2g; Wed, 17 May 2023 03:24:03 +0000 (GMT) X-AuditID: b6c32a46-b23fd7000001438d-62-646448d372db Received: from epsmtip2.samsung.com ( [182.195.34.31]) by epsmgms1p2.samsung.com (Symantec Messaging Gateway) with SMTP id 25.84.28392.3D844646; Wed, 17 May 2023 12:24:03 +0900 (KST) Received: from dell-ArcherCity.dsn.sec.samsung.com (unknown [10.229.83.212]) by epsmtip2.samsung.com (KnoxPortal) with ESMTPA id 20230517032403epsmtip276c3b07ab06b101e1cdca0b9a894d7ff~f0FOXo6uu0909809098epsmtip2r; Wed, 17 May 2023 03:24:03 +0000 (GMT) From: Junhyeok Im To: linux-cxl@vger.kernel.org Cc: vishal.l.verma@intel.com, dan.j.williams@intel.com, bwidawsk@kernel.org, alison.schofield@intel.com, ira.weiny@intel.com, ks0204.kim@samsung.com, Junhyeok Im Subject: [ndctl PATCH v2 2/2] cxl: add inject-poison & clear-poison commands to cxl tool Date: Wed, 17 May 2023 12:23:11 +0900 Message-Id: <20230517032311.19923-3-junhyeok.im@samsung.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230517032311.19923-1-junhyeok.im@samsung.com> MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFupkk+LIzCtJLcpLzFFi42LZdljTTPeyR0qKwckp6hZ3H19gs2ievJjR YvrUC4wW+58+Z7FYfHQGs8XRPRwW52edYrG4NeEYkwOHx+I9L5k8Nq3qZPPo27KK0ePzJrkA lqhsm4zUxJTUIoXUvOT8lMy8dFsl7+B453hTMwNDXUNLC3MlhbzE3FRbJRefAF23zBygK5QU yhJzSoFCAYnFxUr6djZF+aUlqQoZ+cUltkqpBSk5BeYFesWJucWleel6eaklVoYGBkamQIUJ 2Rl3X4YXHPepOHdxKVsD40GbLkYODgkBE4lpe0y6GLk4hAR2MEqsubuUCcL5xCjx5voOZgjn M6PEk5Ymxi5GTrCOc69WQlXtYpTo/bmPFcJpZJKYf+IiE0gVm4C2xN/+6WAdIgKyEs3rHoB1 MAvsZ5RYsXMLG0hCWCBKYv3mCcwgh7AIqEo87VQCCfMK2Ejs3D6dDWKbvMT+g2eZQWxOAVuJ o7tb2SBqBCVOznzCAmIzA9U0b50NdqqEwEt2id8XWlghml0kpi3YCXW2sMSr41vYIWwpic/v 9kItyJeYenAiVLxEou3MASjbWOLdzeesILcxC2hKrN+lDwkvZYkjt6DW8kl0HP7LDhHmleho E4JoVJXYsuEF1BBpiaMTN7FA2B4Sd380QgN0AqPEtd8L2CcwKsxC8s0sJN/MQli8gJF5FaNY akFxbnpqsVGBETx+k/NzNzGC06SW2w7GKW8/6B1iZOJgPMQowcGsJMIb2JecIsSbklhZlVqU H19UmpNafIjRFBjUE5mlRJPzgYk6ryTe0MTSwMTMzNDcyNTAXEmcV9r2ZLKQQHpiSWp2ampB ahFMHxMHp1QDk/vqfev7XJWn93Zr3GH5Fns16XUZ8ykLrcs8s98zV5Tu3W2aHX5qcXXDwkdr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PV5keTJo6f4QtZkJP49Xlc7csZUl0r3sy45wq2PFc/c/rZ4eZl/f leSSKqcRo7HawyB+9mPnAweDXie9jYyJNpXS4su91RIQE+Lr8y1p8SvuC2u0rO8oab3q0Jr4 ZVPCVfeJfzq7TDwTqrbpqe7ecZxz/q3tM2tY+N+sF9yy45ESS3FGoqEWc1FxIgAdGd0v2AIA AA== X-CMS-MailID: 20230517032403epcas2p48fbabf7aec3334b4892c87265b1a7705 X-Msg-Generator: CA X-Sendblock-Type: AUTO_CONFIDENTIAL CMS-TYPE: 102P DLP-Filter: Pass X-CFilter-Loop: Reflected X-CMS-RootMailID: 20230517032403epcas2p48fbabf7aec3334b4892c87265b1a7705 References: <20230517032311.19923-1-junhyeok.im@samsung.com> Precedence: bulk List-ID: X-Mailing-List: linux-cxl@vger.kernel.org Add new commands to cli tool, to inject and clear poison into dpa(-a) on the memory device(memdev), and add man page documentation for the commands (inject-poison, clear-poison). Since the validity verification of the dpa would be done in 'cxl_validate_poison_dpa' of CXL driver, no additional logic is added in this patch. Also since it is expected no use case of injecting / clearing poison into the same address for multiple devices, this command targets only one memdev, like 'write-labels' command. usage: cxl {inject,clear}-poison -a [] -v, --verbose turn on debug -S, --serial use serial numbers to id memdevs -a, --address DPA to inject or clear poison Link to corresponding kernel patch: - inject poison: https://lore.kernel.org/linux-cxl/241c64115e6bd2effed9c7a20b08b3908dd7be8f.1681874357.git.alison.schofield@intel.com/ - clear poison: https://lore.kernel.org/linux-cxl/8682c30ec24bd9c45af5feccb04b02be51e58c0a.1681874357.git.alison.schofield@intel.com/ Signed-off-by: Junhyeok Im --- Documentation/cxl/cxl-clear-poison.txt | 41 ++++++++++++ Documentation/cxl/cxl-inject-poison.txt | 42 ++++++++++++ Documentation/cxl/meson.build | 2 + cxl/builtin.h | 2 + cxl/cxl.c | 2 + cxl/memdev.c | 85 ++++++++++++++++++++++++- 6 files changed, 171 insertions(+), 3 deletions(-) create mode 100644 Documentation/cxl/cxl-clear-poison.txt create mode 100644 Documentation/cxl/cxl-inject-poison.txt diff --git a/Documentation/cxl/cxl-clear-poison.txt b/Documentation/cxl/cxl-clear-poison.txt new file mode 100644 index 0000000..eabad00 --- /dev/null +++ b/Documentation/cxl/cxl-clear-poison.txt @@ -0,0 +1,41 @@ +// SPDX-License-Identifier: GPL-2.0 + +cxl-clear-poison(1) +==================== + +NAME +---- +cxl-clear-poison - send clear poison command to specified CXL memdev + targeting given DPA. + +SYNOPSIS +-------- +[verse] +'cxl clear-poison -a []' + +DESCRIPTION +----------- +Clear poison from the of the , and remove the address from the +device's Poison List. Note that it is not an error to clear poison from an +address that does not have poison set. + +OPTIONS +------- +:: + A 'memX' device name, or a memdev id number. Restrict the operation to + the specified memdev. + +-a:: +--address=:: + Physical address of a CXL memdev to inject poison into. + +-S:: +--serial=:: + Specify CXL memory device serial number(s) to filter the listing + +include::verbose-option.txt[] + + +SEE ALSO +-------- +CXL-3.0 8.2.9.8.4.3 diff --git a/Documentation/cxl/cxl-inject-poison.txt b/Documentation/cxl/cxl-inject-poison.txt new file mode 100644 index 0000000..5a0fac2 --- /dev/null +++ b/Documentation/cxl/cxl-inject-poison.txt @@ -0,0 +1,42 @@ +// SPDX-License-Identifier: GPL-2.0 + +cxl-inject-poison(1) +==================== + +NAME +---- +cxl-inject-poison - send inject poison command to specified CXL memdev + targeting given DPA. + +SYNOPSIS +-------- +[verse] +'cxl inject-poison -a []' + +DESCRIPTION +----------- +Add the to the poison list and the error source shall be set +to an injected error. In addition, the device shall add an appropriate poison +creation event to its internal Informational Event Log, update the Event Status +register, and if configured, interrupt the host. + +OPTIONS +------- +:: + A 'memX' device name, or a memdev id number. Restrict the operation to + the specified memdev. + +-a:: +--address=:: + Physical address of a CXL memdev to inject poison into. + +-S:: +--serial=:: + Specify CXL memory device serial number(s) to filter the listing + +include::verbose-option.txt[] + + +SEE ALSO +-------- +CXL-3.0 8.2.9.8.4.2 diff --git a/Documentation/cxl/meson.build b/Documentation/cxl/meson.build index a6d77ab..c0067ab 100644 --- a/Documentation/cxl/meson.build +++ b/Documentation/cxl/meson.build @@ -46,6 +46,8 @@ cxl_manpages = [ 'cxl-enable-region.txt', 'cxl-destroy-region.txt', 'cxl-monitor.txt', + 'cxl-inject-poison.txt', + 'cxl-clear-poison.txt', ] foreach man : cxl_manpages diff --git a/cxl/builtin.h b/cxl/builtin.h index 9baa43b..60b081c 100644 --- a/cxl/builtin.h +++ b/cxl/builtin.h @@ -22,6 +22,8 @@ int cmd_create_region(int argc, const char **argv, struct cxl_ctx *ctx); int cmd_enable_region(int argc, const char **argv, struct cxl_ctx *ctx); int cmd_disable_region(int argc, const char **argv, struct cxl_ctx *ctx); int cmd_destroy_region(int argc, const char **argv, struct cxl_ctx *ctx); +int cmd_inject_poison(int argc, const char **argv, struct cxl_ctx *ctx); +int cmd_clear_poison(int argc, const char **argv, struct cxl_ctx *ctx); #ifdef ENABLE_LIBTRACEFS int cmd_monitor(int argc, const char **argv, struct cxl_ctx *ctx); #else diff --git a/cxl/cxl.c b/cxl/cxl.c index 3be7026..359e619 100644 --- a/cxl/cxl.c +++ b/cxl/cxl.c @@ -77,6 +77,8 @@ static struct cmd_struct commands[] = { { "disable-region", .c_fn = cmd_disable_region }, { "destroy-region", .c_fn = cmd_destroy_region }, { "monitor", .c_fn = cmd_monitor }, + { "inject-poison", .c_fn = cmd_inject_poison }, + { "clear-poison", .c_fn = cmd_clear_poison }, }; int main(int argc, const char **argv) diff --git a/cxl/memdev.c b/cxl/memdev.c index 0b3ad02..d1fed3c 100644 --- a/cxl/memdev.c +++ b/cxl/memdev.c @@ -34,6 +34,7 @@ static struct parameters { const char *type; const char *size; const char *decoder_filter; + const char *poison_address; } param; static struct log_ctx ml; @@ -85,6 +86,10 @@ OPT_STRING('t', "type", ¶m.type, "type", \ OPT_BOOLEAN('f', "force", ¶m.force, \ "Attempt 'expected to fail' operations") +#define POISON_OPTIONS() \ +OPT_STRING('a', "address", ¶m.poison_address, "dpa", \ + "DPA to inject or clear poison") + static const struct option read_options[] = { BASE_OPTIONS(), LABEL_OPTIONS(), @@ -135,6 +140,12 @@ static const struct option free_dpa_options[] = { OPT_END(), }; +static const struct option poison_options[] = { + BASE_OPTIONS(), + POISON_OPTIONS(), + OPT_END(), +}; + enum reserve_dpa_mode { DPA_ALLOC, DPA_FREE, @@ -351,6 +362,42 @@ static int action_free_dpa(struct cxl_memdev *memdev, return __reserve_dpa(memdev, DPA_FREE, actx); } +static int action_inject_poison(struct cxl_memdev *memdev, + struct action_context *actx) +{ + int rc; + + if (!param.poison_address) { + log_err(&ml, "%s: set dpa to inject poison.\n", + cxl_memdev_get_devname(memdev)); + return -EINVAL; + } + rc = cxl_memdev_inject_poison(memdev, param.poison_address); + if (rc < 0) { + log_err(&ml, "%s: inject poison failed: %s\n", + cxl_memdev_get_devname(memdev), strerror(-rc)); + } + return rc; +} + +static int action_clear_poison(struct cxl_memdev *memdev, + struct action_context *actx) +{ + int rc; + + if (!param.poison_address) { + log_err(&ml, "%s: set dpa to clear poison.\n", + cxl_memdev_get_devname(memdev)); + return -EINVAL; + } + rc = cxl_memdev_clear_poison(memdev, param.poison_address); + if (rc < 0) { + log_err(&ml, "%s: clear poison failed: %s\n", + cxl_memdev_get_devname(memdev), strerror(-rc)); + } + return rc; +} + static int action_disable(struct cxl_memdev *memdev, struct action_context *actx) { if (!cxl_memdev_is_enabled(memdev)) @@ -755,7 +802,9 @@ static int memdev_action(int argc, const char **argv, struct cxl_ctx *ctx, continue; found = true; - if (action == action_write) { + if ((action == action_write) || + (action == action_inject_poison) || + (action == action_clear_poison)) { single = memdev; rc = 0; } else @@ -771,9 +820,17 @@ static int memdev_action(int argc, const char **argv, struct cxl_ctx *ctx, } rc = err; - if (action == action_write) { + if ((action == action_write) || (action == action_inject_poison) || + (action == action_clear_poison)) { if (count > 1) { - error("write-labels only supports writing a single memdev\n"); + if (action == action_write) { + error("write-labels only supports writing " + "a single memdev\n"); + } else { + error("poison command only supports injecting " + "or clearing poison into a single " + "memdev\n"); + } usage_with_options(u, options); return -EINVAL; } else if (single) { @@ -893,3 +950,25 @@ int cmd_free_dpa(int argc, const char **argv, struct cxl_ctx *ctx) return count >= 0 ? 0 : EXIT_FAILURE; } + +int cmd_inject_poison(int argc, const char **argv, struct cxl_ctx *ctx) +{ + int count = memdev_action( + argc, argv, ctx, action_inject_poison, poison_options, + "cxl inject-poison -a []"); + log_info(&ml, "inject-poison %d mem%s\n", count >= 0 ? count : 0, + count > 1 ? "s" : ""); + + return count >= 0 ? 0 : EXIT_FAILURE; +} + +int cmd_clear_poison(int argc, const char **argv, struct cxl_ctx *ctx) +{ + int count = memdev_action( + argc, argv, ctx, action_clear_poison, poison_options, + "cxl clear-poison -a []"); + log_info(&ml, "clear-poison %d mem%s\n", count >= 0 ? count : 0, + count > 1 ? "s" : ""); + + return count >= 0 ? 0 : EXIT_FAILURE; +}