From patchwork Wed Jun 15 00:10:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alison Schofield X-Patchwork-Id: 12881716 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 09A86C433EF for ; Wed, 15 Jun 2022 00:10:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231699AbiFOAK6 (ORCPT ); Tue, 14 Jun 2022 20:10:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55972 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235492AbiFOAKw (ORCPT ); Tue, 14 Jun 2022 20:10:52 -0400 Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4632C31356; Tue, 14 Jun 2022 17:10:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1655251851; x=1686787851; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Nu1sRFuhuPRHQby7CWmOe+Fl1IDvKYrgdKkIDvgU/T8=; b=E3FBejEgmc5S/58yxsJqgesXqZwfXyEAkCdYppz8ef7xeg4C5IZDfzx7 I2XOyJ57XLJTUuKWzfGq050BMgy1spfbqwWYgLYKBw4XT87eoT+rl1TZR 6xpUyOu5eQfQCLVBS1tVxwFYDEBbVzSWSZeyVdhYcKd1F14ZNTaTsQp1H H6kgevPfYEc0p+zbdS9LlsIRSL+Lo1bIvhdWd9BtWb9uxRtfxmpVZk/QS G3SuC6IBPks1qC0ojGcYJ1ebPkXp4seHiyGKtD59+NidmBMZ4FCKTivTJ dwlSwB/0AyuU3EqqtYK6H55y6UaZxGzLQc3yhzRzB67kmmh37a0YpZANV Q==; X-IronPort-AV: E=McAfee;i="6400,9594,10378"; a="278825448" X-IronPort-AV: E=Sophos;i="5.91,300,1647327600"; d="scan'208";a="278825448" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Jun 2022 17:10:51 -0700 X-IronPort-AV: E=Sophos;i="5.91,300,1647327600"; d="scan'208";a="640662873" Received: from alison-desk.jf.intel.com (HELO localhost) ([10.54.74.41]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Jun 2022 17:10:49 -0700 From: alison.schofield@intel.com To: Dan Williams , Ira Weiny , Vishal Verma , Ben Widawsky , Steven Rostedt , Ingo Molnar Cc: Alison Schofield , linux-cxl@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/3] trace, cxl: Introduce a TRACE_EVENT for CXL Poison Records Date: Tue, 14 Jun 2022 17:10:26 -0700 Message-Id: <32a761fe7046680a4d50762fc43988def24a4bcd.1655250669.git.alison.schofield@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-cxl@vger.kernel.org From: Alison Schofield Add a trace event for CXL Poison List Media Error Records that includes the starting DPA of the poison, the length, and the the source of the poison. This trace event will be used by the CXL_MEM driver to log the Media Errors returned by the GET_POISON_LIST Mailbox command. Signed-off-by: Alison Schofield Reviewed-by: Steven Rostedt (VMware) Reviewed-by: Davidlohr Bueso Reviewed-by: Jonathan Cameron --- include/trace/events/cxl.h | 60 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 include/trace/events/cxl.h diff --git a/include/trace/events/cxl.h b/include/trace/events/cxl.h new file mode 100644 index 000000000000..17e707c3817e --- /dev/null +++ b/include/trace/events/cxl.h @@ -0,0 +1,60 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#undef TRACE_SYSTEM +#define TRACE_SYSTEM cxl + +#if !defined(_CXL_TRACE_H) || defined(TRACE_HEADER_MULTI_READ) +#define _CXL_TRACE_H + +#include + +TRACE_DEFINE_ENUM(CXL_POISON_SOURCE_UNKNOWN); +TRACE_DEFINE_ENUM(CXL_POISON_SOURCE_INTERNAL); +TRACE_DEFINE_ENUM(CXL_POISON_SOURCE_EXTERNAL); +TRACE_DEFINE_ENUM(CXL_POISON_SOURCE_INJECTED); +TRACE_DEFINE_ENUM(CXL_POISON_SOURCE_VENDOR); +TRACE_DEFINE_ENUM(CXL_POISON_SOURCE_INVALID); + +#define show_poison_source(source) \ + __print_symbolic(source, \ + {CXL_POISON_SOURCE_UNKNOWN, "UNKNOWN"}, \ + {CXL_POISON_SOURCE_EXTERNAL, "EXTERNAL"}, \ + {CXL_POISON_SOURCE_INTERNAL, "INTERNAL"}, \ + {CXL_POISON_SOURCE_INJECTED, "INJECTED"}, \ + {CXL_POISON_SOURCE_VENDOR, "VENDOR"}, \ + {CXL_POISON_SOURCE_INVALID, "INVALID"}) + +TRACE_EVENT(cxl_poison_list, + + TP_PROTO(struct device *dev, + int source, + unsigned long start, + unsigned int length), + + TP_ARGS(dev, source, start, length), + + TP_STRUCT__entry( + __string(name, dev_name(dev)) + __field(int, source) + __field(u64, start) + __field(u32, length) + ), + + TP_fast_assign( + __assign_str(name, dev_name(dev)); + __entry->source = source; + __entry->start = start; + __entry->length = length; + ), + + TP_printk("dev %s source %s start %llu length %u", + __get_str(name), + show_poison_source(__entry->source), + __entry->start, + __entry->length) +); +#endif /* _CXL_TRACE_H */ + +/* This part must be outside protection */ +#undef TRACE_INCLUDE_FILE +#define TRACE_INCLUDE_FILE cxl +#include From patchwork Wed Jun 15 00:10:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alison Schofield X-Patchwork-Id: 12881718 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 8D0ECCCA47A for ; Wed, 15 Jun 2022 00:10:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234507AbiFOAK7 (ORCPT ); Tue, 14 Jun 2022 20:10:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56140 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236024AbiFOAKx (ORCPT ); Tue, 14 Jun 2022 20:10:53 -0400 Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5D3392CDD9; Tue, 14 Jun 2022 17:10:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1655251852; x=1686787852; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Rgzx0VAJN0GDKGJ7XNvOIp3dKw4QY0igqjHzJxj6vHE=; b=YrNSU0F1Cd3cgM0gMzdMHStjMPvHa4KyfCzmg6bvAM3lkgnbrEAKEMHA O0cUpP3r3YWqmCW7vc+gTM0m/5XFLnukMuduMsboxiuch8Ro+afFQxNFP RNBxO8f4ysxlNrhh86IGUVTvzjhDE9ujkhWrJL9opaFCUOY08S/a08AZf mhXncsXNvwRt6u3NOodSdkpY4MjEyUZFSlwMK9lV0IivQQmxuardSyMuf 7uMzJJ8JtHAcXa5pnAQKujY0NmaP9GXx2mkt/Jz08CDvHPD9hkP/8xALj 0eHoHRBCmwF38bwazgSEi668vRTSuXw4cpZK9hLV7ZX55gwkR6mgTjQx5 Q==; X-IronPort-AV: E=McAfee;i="6400,9594,10378"; a="278825453" X-IronPort-AV: E=Sophos;i="5.91,300,1647327600"; d="scan'208";a="278825453" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Jun 2022 17:10:52 -0700 X-IronPort-AV: E=Sophos;i="5.91,300,1647327600"; d="scan'208";a="640662892" Received: from alison-desk.jf.intel.com (HELO localhost) ([10.54.74.41]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Jun 2022 17:10:51 -0700 From: alison.schofield@intel.com To: Dan Williams , Ira Weiny , Vishal Verma , Ben Widawsky , Steven Rostedt , Ingo Molnar Cc: Alison Schofield , linux-cxl@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/3] cxl/mbox: Add GET_POISON_LIST mailbox command support Date: Tue, 14 Jun 2022 17:10:27 -0700 Message-Id: <382a9c35ef43e89db85670637d88371f9197b7a2.1655250669.git.alison.schofield@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-cxl@vger.kernel.org From: Alison Schofield CXL devices that support persistent memory maintain a list of locations that are poisoned or result in poison if the addresses are accessed by the host. Per the spec (CXL 2.0 8.2.8.5.4.1), the device returns this Poison list as a set of Media Error Records that include the source of the error, the starting device physical address and length. The length is the number of adjacent DPAs in the record and is in units of 64 bytes. Retrieve the list and log each Media Error Record as a trace event of type cxl_poison_list. Signed-off-by: Alison Schofield --- drivers/cxl/cxlmem.h | 43 +++++++++++++++++++++++ drivers/cxl/core/mbox.c | 75 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 118 insertions(+) diff --git a/drivers/cxl/cxlmem.h b/drivers/cxl/cxlmem.h index 60d10ee1e7fc..29cf0459b44a 100644 --- a/drivers/cxl/cxlmem.h +++ b/drivers/cxl/cxlmem.h @@ -174,6 +174,7 @@ struct cxl_endpoint_dvsec_info { * (CXL 2.0 8.2.8.4.3 Mailbox Capabilities Register) * @lsa_size: Size of Label Storage Area * (CXL 2.0 8.2.9.5.1.1 Identify Memory Device) + * @poison_max_mer: maximum Media Error Records tracked in Poison List * @mbox_mutex: Mutex to synchronize mailbox access. * @firmware_version: Firmware version for the memory device. * @enabled_cmds: Hardware commands found enabled in CEL. @@ -204,6 +205,7 @@ struct cxl_dev_state { size_t payload_size; size_t lsa_size; + u32 poison_max; struct mutex mbox_mutex; /* Protects device mailbox and firmware */ char firmware_version[0x10]; DECLARE_BITMAP(enabled_cmds, CXL_MEM_COMMAND_ID_MAX); @@ -317,6 +319,46 @@ struct cxl_mbox_set_partition_info { #define CXL_SET_PARTITION_IMMEDIATE_FLAG BIT(0) +struct cxl_mbox_poison_payload_in { + __le64 offset; + __le64 length; +} __packed; + +struct cxl_mbox_poison_payload_out { + u8 flags; + u8 rsvd1; + __le64 overflow_timestamp; + __le16 count; + u8 rsvd2[0x14]; + struct cxl_poison_record { + __le64 address; + __le32 length; + __le32 rsvd; + } __packed record[]; +} __packed; + +/* CXL 8.2.9.5.4.1 Get Poison List: payload out flags: */ +#define CXL_POISON_FLAG_MORE BIT(0) +#define CXL_POISON_FLAG_OVERFLOW BIT(1) +#define CXL_POISON_FLAG_SCANNING BIT(2) + +/* CXL 8.2.9.5.4.1 Get Poison List: Error is encoded in record.address[2:0] */ +#define CXL_POISON_SOURCE_MASK GENMASK(2, 0) +#define CXL_POISON_SOURCE_UNKNOWN 0 +#define CXL_POISON_SOURCE_EXTERNAL 1 +#define CXL_POISON_SOURCE_INTERNAL 2 +#define CXL_POISON_SOURCE_INJECTED 3 +#define CXL_POISON_SOURCE_VENDOR 7 + +/* Software define */ +#define CXL_POISON_SOURCE_INVALID 99 +#define CXL_POISON_SOURCE_VALID(x) \ + (((x) == CXL_POISON_SOURCE_UNKNOWN) || \ + ((x) == CXL_POISON_SOURCE_EXTERNAL) || \ + ((x) == CXL_POISON_SOURCE_INTERNAL) || \ + ((x) == CXL_POISON_SOURCE_INJECTED) || \ + ((x) == CXL_POISON_SOURCE_VENDOR)) + /** * struct cxl_mem_command - Driver representation of a memory device command * @info: Command information as it exists for the UAPI @@ -351,6 +393,7 @@ int cxl_mem_create_range_info(struct cxl_dev_state *cxlds); struct cxl_dev_state *cxl_dev_state_create(struct device *dev); void set_exclusive_cxl_commands(struct cxl_dev_state *cxlds, unsigned long *cmds); void clear_exclusive_cxl_commands(struct cxl_dev_state *cxlds, unsigned long *cmds); +int cxl_mem_get_poison_list(struct device *dev); #ifdef CONFIG_CXL_SUSPEND void cxl_mem_active_inc(void); void cxl_mem_active_dec(void); diff --git a/drivers/cxl/core/mbox.c b/drivers/cxl/core/mbox.c index 54f434733b56..c10c7020ebc2 100644 --- a/drivers/cxl/core/mbox.c +++ b/drivers/cxl/core/mbox.c @@ -9,6 +9,9 @@ #include "core.h" +#define CREATE_TRACE_POINTS +#include + static bool cxl_raw_allow_all; /** @@ -755,6 +758,7 @@ int cxl_dev_state_identify(struct cxl_dev_state *cxlds) { /* See CXL 2.0 Table 175 Identify Memory Device Output Payload */ struct cxl_mbox_identify id; + __le32 val = 0; int rc; rc = cxl_mbox_send_cmd(cxlds, CXL_MBOX_OP_IDENTIFY, NULL, 0, &id, @@ -783,6 +787,9 @@ int cxl_dev_state_identify(struct cxl_dev_state *cxlds) cxlds->lsa_size = le32_to_cpu(id.lsa_size); memcpy(cxlds->firmware_version, id.fw_revision, sizeof(id.fw_revision)); + memcpy(&val, id.poison_list_max_mer, 3); + cxlds->poison_max = le32_to_cpu(val); + return 0; } EXPORT_SYMBOL_NS_GPL(cxl_dev_state_identify, CXL); @@ -826,6 +833,74 @@ int cxl_mem_create_range_info(struct cxl_dev_state *cxlds) } EXPORT_SYMBOL_NS_GPL(cxl_mem_create_range_info, CXL); +int cxl_mem_get_poison_list(struct device *dev) +{ + struct cxl_memdev *cxlmd = to_cxl_memdev(dev); + struct cxl_dev_state *cxlds = cxlmd->cxlds; + struct cxl_mbox_poison_payload_out *po; + struct cxl_mbox_poison_payload_in pi; + int nr_records = 0; + int rc, i; + + if (range_len(&cxlds->pmem_range)) { + pi.offset = cpu_to_le64(cxlds->pmem_range.start); + pi.length = cpu_to_le64(range_len(&cxlds->pmem_range)); + } else { + return -ENXIO; + } + + po = kvmalloc(cxlds->payload_size, GFP_KERNEL); + if (!po) + return -ENOMEM; + + do { + rc = cxl_mbox_send_cmd(cxlds, CXL_MBOX_OP_GET_POISON, &pi, + sizeof(pi), po, cxlds->payload_size); + if (rc) + goto out; + + if (po->flags & CXL_POISON_FLAG_OVERFLOW) { + time64_t o_time = le64_to_cpu(po->overflow_timestamp); + + dev_err(dev, "Poison list overflow at %ptTs UTC\n", + &o_time); + rc = -ENXIO; + goto out; + } + + if (po->flags & CXL_POISON_FLAG_SCANNING) { + dev_err(dev, "Scan Media in Progress\n"); + rc = -EBUSY; + goto out; + } + + for (i = 0; i < le16_to_cpu(po->count); i++) { + u64 addr = le64_to_cpu(po->record[i].address); + u32 len = le32_to_cpu(po->record[i].length); + int source = FIELD_GET(CXL_POISON_SOURCE_MASK, addr); + + if (!CXL_POISON_SOURCE_VALID(source)) { + dev_dbg(dev, "Invalid poison source %d", + source); + source = CXL_POISON_SOURCE_INVALID; + } + + trace_cxl_poison_list(dev, source, addr, len); + } + + /* Protect against an uncleared _FLAG_MORE */ + nr_records = nr_records + le16_to_cpu(po->count); + if (nr_records >= cxlds->poison_max) + goto out; + + } while (po->flags & CXL_POISON_FLAG_MORE); + +out: + kvfree(po); + return rc; +} +EXPORT_SYMBOL_NS_GPL(cxl_mem_get_poison_list, CXL); + struct cxl_dev_state *cxl_dev_state_create(struct device *dev) { struct cxl_dev_state *cxlds; From patchwork Wed Jun 15 00:10:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alison Schofield X-Patchwork-Id: 12881717 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 0A690CCA47C for ; Wed, 15 Jun 2022 00:11:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229520AbiFOAK7 (ORCPT ); Tue, 14 Jun 2022 20:10:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56250 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231530AbiFOAKz (ORCPT ); Tue, 14 Jun 2022 20:10:55 -0400 Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2065736176; Tue, 14 Jun 2022 17:10:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1655251854; x=1686787854; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=rmwqOoory/BhG+mzzDYl/irO2wGnfPfD8xSW1RR8boc=; b=WfuUk4EhdSwZLQ7jdTQiG9I/IPtcn81sX09oqnTKKYgH5jkMWEICy4y+ xxLT3wEp6s4zwYWTolnviBRJx2y0PNDJmvQ9y2LqlwaRDKQKwoDaw+PyX O5bNDkpGJ1+CqZvfMTEWnn57Re3CCy8dse+yPA2pkKCParg3KWp999MAh GV3l2eAa2ty3wVZKFa53iuN/GAic+A5z/T5onO3mS112Py96/uauoD/EC v7HO412OvWP3Cw5G48pSLlWnDfNOD2Ix2j7wVecrL/RNhTlCViVub7FPF MQPW7qC4lKzDm8bSc+9tfiUPSyzoRWsqJf2BNRhQnpMs+IhkgYqD4Js92 A==; X-IronPort-AV: E=McAfee;i="6400,9594,10378"; a="278825457" X-IronPort-AV: E=Sophos;i="5.91,300,1647327600"; d="scan'208";a="278825457" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Jun 2022 17:10:54 -0700 X-IronPort-AV: E=Sophos;i="5.91,300,1647327600"; d="scan'208";a="640662914" Received: from alison-desk.jf.intel.com (HELO localhost) ([10.54.74.41]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Jun 2022 17:10:53 -0700 From: alison.schofield@intel.com To: Dan Williams , Ira Weiny , Vishal Verma , Ben Widawsky , Steven Rostedt , Ingo Molnar Cc: Alison Schofield , linux-cxl@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 3/3] cxl/core: Add sysfs attribute get_poison for list retrieval Date: Tue, 14 Jun 2022 17:10:28 -0700 Message-Id: <57644934bb7af8e1c692735f53c2c415a1ba16d1.1655250669.git.alison.schofield@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-cxl@vger.kernel.org From: Alison Schofield The sysfs attribute, get_poison, allows user space to request the retrieval of a CXL devices poison list for its persistent memory. From Documentation/ABI/.../sysfs-bus-cxl (WO) When a '1' is written to this attribute the memdev driver retrieves the poison list from the device. The list includes addresses that are poisoned or would result in poison if accessed, and the source of the poison. This attribute is only visible for devices supporting the capability. The retrieved errors are logged as kernel trace events with the label: cxl_poison_list. Signed-off-by: Alison Schofield Reviewed-by: Ira Weiny --- Documentation/ABI/testing/sysfs-bus-cxl | 13 ++++++++++ drivers/cxl/core/memdev.c | 32 +++++++++++++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/Documentation/ABI/testing/sysfs-bus-cxl b/Documentation/ABI/testing/sysfs-bus-cxl index 7c2b846521f3..9d0c3988fdd2 100644 --- a/Documentation/ABI/testing/sysfs-bus-cxl +++ b/Documentation/ABI/testing/sysfs-bus-cxl @@ -163,3 +163,16 @@ Description: memory (type-3). The 'target_type' attribute indicates the current setting which may dynamically change based on what memory regions are activated in this decode hierarchy. + +What: /sys/bus/cxl/devices/memX/get_poison +Date: June, 2022 +KernelVersion: v5.20 +Contact: linux-cxl@vger.kernel.org +Description: + (WO) When a '1' is written to this attribute the memdev + driver retrieves the poison list from the device. The list + includes addresses that are poisoned or would result in + poison if accessed, and the source of the poison. This + attribute is only visible for devices supporting the + capability. The retrieved errors are logged as kernel + trace events with the label: cxl_poison_list. diff --git a/drivers/cxl/core/memdev.c b/drivers/cxl/core/memdev.c index f7cdcd33504a..5ef9ffaa934a 100644 --- a/drivers/cxl/core/memdev.c +++ b/drivers/cxl/core/memdev.c @@ -106,12 +106,34 @@ static ssize_t numa_node_show(struct device *dev, struct device_attribute *attr, } static DEVICE_ATTR_RO(numa_node); +static ssize_t get_poison_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t len) + +{ + int rc; + + if (!sysfs_streq(buf, "1")) { + dev_err(dev, "%s: unknown value: %s\n", attr->attr.name, buf); + return -EINVAL; + } + + rc = cxl_mem_get_poison_list(dev); + if (rc) { + dev_err(dev, "Failed to retrieve poison list %d\n", rc); + return rc; + } + return len; +} +static DEVICE_ATTR_WO(get_poison); + static struct attribute *cxl_memdev_attributes[] = { &dev_attr_serial.attr, &dev_attr_firmware_version.attr, &dev_attr_payload_max.attr, &dev_attr_label_storage_size.attr, &dev_attr_numa_node.attr, + &dev_attr_get_poison.attr, NULL, }; @@ -130,6 +152,16 @@ static umode_t cxl_memdev_visible(struct kobject *kobj, struct attribute *a, { if (!IS_ENABLED(CONFIG_NUMA) && a == &dev_attr_numa_node.attr) return 0; + + if (a == &dev_attr_get_poison.attr) { + struct device *dev = container_of(kobj, struct device, kobj); + struct cxl_memdev *cxlmd = to_cxl_memdev(dev); + struct cxl_dev_state *cxlds = cxlmd->cxlds; + + if (!test_bit(CXL_MEM_COMMAND_ID_GET_POISON, + cxlds->enabled_cmds)) + return 0; + } return a->mode; }