From patchwork Fri Nov 11 03:12:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alison Schofield X-Patchwork-Id: 13039526 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 87F81C4332F for ; Fri, 11 Nov 2022 03:12:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232231AbiKKDMx (ORCPT ); Thu, 10 Nov 2022 22:12:53 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50200 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232094AbiKKDMw (ORCPT ); Thu, 10 Nov 2022 22:12:52 -0500 Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6ECAF2EF42; Thu, 10 Nov 2022 19:12:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1668136371; x=1699672371; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=dpT2xSej3sVQoszQCqz3VXjYp4+bosvOJvtGCWIi7qY=; b=gwwPesXrClALuyZh3u3Q6dmPf/XscyQRKq4YVA7rHLZuXs4MTczA2BNg ILKmKjUWWwynFVsSW8EB85mr8xWUR2yhIp8XJ0EhuNEMWUk24S9JL2EAw I4hR77D8b/YTCj+lrhxLq5k4vLYfVZBN9/+8NKoAHc+TmlCzPZmvkGJo6 3qZlH/xYeQWw8/PTc3BdixtlBDCLiWpc6XQ5sX1CPGkXBBfIgTFk/ZPYb u+7oxqh2EEz7TbxXh/lhv6PFnN3WYkLiU8/vbETdPvXht+Kwykbm+XUYl 07TYw3owEUwp1T9nAv/1Y0zA77mAY8vxTLyOt+F9kwZiwmlGs6GD02hyr g==; X-IronPort-AV: E=McAfee;i="6500,9779,10527"; a="310224398" X-IronPort-AV: E=Sophos;i="5.96,155,1665471600"; d="scan'208";a="310224398" Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Nov 2022 19:12:51 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10527"; a="812296052" X-IronPort-AV: E=Sophos;i="5.96,155,1665471600"; d="scan'208";a="812296052" Received: from aschofie-mobl2.amr.corp.intel.com (HELO localhost) ([10.209.161.45]) by orsmga005-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Nov 2022 19:12:50 -0800 From: alison.schofield@intel.com To: Dan Williams , Ira Weiny , Vishal Verma , Dave Jiang , Ben Widawsky , Steven Rostedt , Ingo Molnar Cc: Alison Schofield , linux-cxl@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 1/6] trace, cxl: Introduce a TRACE_EVENT for CXL poison records Date: Thu, 10 Nov 2022 19:12:39 -0800 Message-Id: <5746274c905f57f117987c8268c9f6dc9bd33337.1668115235.git.alison.schofield@intel.com> X-Mailer: git-send-email 2.37.3 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 may support the retrieval of a device poison list. Introduce a trace event that the CXL subsystem can use to log the poison error records. Signed-off-by: Alison Schofield Reviewed-by: Jonathan Cameron --- drivers/cxl/cxlmem.h | 14 +++++++ include/trace/events/cxl.h | 80 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 94 insertions(+) create mode 100644 include/trace/events/cxl.h diff --git a/drivers/cxl/cxlmem.h b/drivers/cxl/cxlmem.h index 88e3a8e54b6a..669868cc1553 100644 --- a/drivers/cxl/cxlmem.h +++ b/drivers/cxl/cxlmem.h @@ -347,6 +347,20 @@ struct cxl_mbox_set_partition_info { #define CXL_SET_PARTITION_IMMEDIATE_FLAG BIT(0) +/* Get Poison List CXL 3.0 Spec 8.2.9.8.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) + +/* Get Poison List: Poison Source */ +#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 + /** * struct cxl_mem_command - Driver representation of a memory device command * @info: Command information as it exists for the UAPI diff --git a/include/trace/events/cxl.h b/include/trace/events/cxl.h new file mode 100644 index 000000000000..03428125573f --- /dev/null +++ b/include/trace/events/cxl.h @@ -0,0 +1,80 @@ +/* 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 +#include + +#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" }) + +#define show_poison_source(source) \ + (((source > CXL_POISON_SOURCE_INJECTED) && \ + (source != CXL_POISON_SOURCE_VENDOR)) ? "Reserved" \ + : __show_poison_source(source)) + +#define show_poison_flags(flags) \ + __print_flags(flags, "|", \ + { CXL_POISON_FLAG_MORE, "More" }, \ + { CXL_POISON_FLAG_OVERFLOW, "Overflow" }, \ + { CXL_POISON_FLAG_SCANNING, "Scanning" }) + +TRACE_EVENT(cxl_poison, + + TP_PROTO(const char *memdev, const char *pcidev, const char *region, + const uuid_t *uuid, u64 dpa, u32 length, u8 source, + u8 flags, u64 overflow_t), + + TP_ARGS(memdev, pcidev, region, uuid, dpa, length, source, + flags, overflow_t), + + TP_STRUCT__entry( + __string(memdev, memdev) + __string(pcidev, pcidev) + __string(region, region ? region : "") + __array(char, uuid, 16) + __field(u64, dpa) + __field(u32, length) + __field(u8, source) + __field(u8, flags) + __field(u64, overflow_t) + ), + + TP_fast_assign( + __assign_str(memdev, memdev); + __assign_str(pcidev, pcidev); + __assign_str(region, region ? region : ""); + if (uuid) + memcpy(__entry->uuid, uuid, 16); + __entry->dpa = dpa; + __entry->length = length; + __entry->source = source; + __entry->flags = flags; + __entry->overflow_t = overflow_t; + ), + + TP_printk("memdev=%s pcidev=%s region=%s region_uuid=%pU dpa=0x%llx length=0x%x source=%s flags=%s overflow_time=%llu", + __get_str(memdev), + __get_str(pcidev), + __get_str(region), + __entry->uuid, + __entry->dpa, + __entry->length, + show_poison_source(__entry->source), + show_poison_flags(__entry->flags), + __entry->overflow_t) +); +#endif /* _CXL_TRACE_H */ + +/* This part must be outside protection */ +#undef TRACE_INCLUDE_FILE +#define TRACE_INCLUDE_FILE cxl +#include From patchwork Fri Nov 11 03:12:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alison Schofield X-Patchwork-Id: 13039527 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 23701C4332F for ; Fri, 11 Nov 2022 03:13:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232426AbiKKDMz (ORCPT ); Thu, 10 Nov 2022 22:12:55 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50220 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232335AbiKKDMy (ORCPT ); Thu, 10 Nov 2022 22:12:54 -0500 Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4C4382EF42; Thu, 10 Nov 2022 19:12:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1668136373; x=1699672373; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=bOUKwtAc44fVEJb7Wp1v8fcxde+NjnUeKTqw0XJ/NhE=; b=E91T1odnuhzb0VGz10mPVFEfi6kcE77X76saFnr5fpy2oR3J+4MN7a5x hHdQksXlJo17bmFsKeYHY7vOken8PWFtRZRclVPr6vUEwMkf+KMfY3G4s kohV/7H860ijPP0shU2+IhKALSTTxSPJOJxHrKBnwQSeq+tXT4zIJghdv 6b8QlHF4dOt/JsYWKPuXlAxtlQsoKBiNmfujB40erptfg+VXaLTB4kcn1 HpHnDpsQS5Vx47OTNew7574gvdXcbAfSh5aoihWv+oVSQg6RK7DnLXPf+ QagJgpRjcbL2HRPvGeChsg1puKdLx8HWb0HEvFSTEX5mn4cesqBaFyIQt w==; X-IronPort-AV: E=McAfee;i="6500,9779,10527"; a="310224404" X-IronPort-AV: E=Sophos;i="5.96,155,1665471600"; d="scan'208";a="310224404" Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Nov 2022 19:12:52 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10527"; a="812296069" X-IronPort-AV: E=Sophos;i="5.96,155,1665471600"; d="scan'208";a="812296069" Received: from aschofie-mobl2.amr.corp.intel.com (HELO localhost) ([10.209.161.45]) by orsmga005-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Nov 2022 19:12:51 -0800 From: alison.schofield@intel.com To: Dan Williams , Ira Weiny , Vishal Verma , Dave Jiang , Ben Widawsky , Steven Rostedt , Ingo Molnar Cc: Alison Schofield , linux-cxl@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 2/6] cxl/mbox: Add GET_POISON_LIST mailbox command Date: Thu, 10 Nov 2022 19:12:40 -0800 Message-Id: <46c7c7339224744fce424b196da3e5566effec17.1668115235.git.alison.schofield@intel.com> X-Mailer: git-send-email 2.37.3 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 maintain a list of locations that are poisoned or result in poison if the addresses are accessed by the host. Per the spec (CXL 3.0 8.2.9.8.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'. When the poison list is requested by region, include the region name and uuid in the trace event. Signed-off-by: Alison Schofield --- drivers/cxl/core/mbox.c | 81 +++++++++++++++++++++++++++++++++++++++++ drivers/cxl/cxlmem.h | 37 +++++++++++++++++++ 2 files changed, 118 insertions(+) diff --git a/drivers/cxl/core/mbox.c b/drivers/cxl/core/mbox.c index 0c90f13870a4..88f034e97812 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; /** @@ -752,6 +755,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, @@ -771,6 +775,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 = min_t(u32, le32_to_cpu(val), CXL_POISON_LIST_MAX); + return 0; } EXPORT_SYMBOL_NS_GPL(cxl_dev_state_identify, CXL); @@ -835,6 +842,79 @@ int cxl_mem_create_range_info(struct cxl_dev_state *cxlds) } EXPORT_SYMBOL_NS_GPL(cxl_mem_create_range_info, CXL); +static void cxl_trace_poison(struct cxl_mbox_poison_payload_out *po, + struct cxl_region *cxlr, + const char *memdev_name, + const char *pcidev_name) +{ + const char *region_name = cxlr ? dev_name(&cxlr->dev) : NULL; + struct cxl_region_params *p = cxlr ? &cxlr->params : NULL; + uuid_t *uuid = p ? &p->uuid : NULL; + u64 addr, dpa, overflow_t = 0; + u8 source; + u32 len; + + if (po->flags & CXL_POISON_FLAG_OVERFLOW) + overflow_t = le64_to_cpu(po->overflow_timestamp); + + for (int i = 0; i < le16_to_cpu(po->count); i++) { + len = le32_to_cpu(po->record[i].length) * CXL_POISON_LEN_MULT; + addr = le64_to_cpu(po->record[i].address); + source = addr & CXL_POISON_SOURCE_MASK; + dpa = addr & CXL_POISON_START_MASK; + + trace_cxl_poison(memdev_name, pcidev_name, region_name, uuid, + dpa, len, source, po->flags, overflow_t); + } +} + +int cxl_mem_get_poison(struct cxl_memdev *cxlmd, u64 offset, u64 len, + struct cxl_region *cxlr) +{ + struct cxl_dev_state *cxlds = cxlmd->cxlds; + const char *memdev_name = dev_name(&cxlmd->dev); + const char *pcidev_name = dev_name(cxlds->dev); + struct cxl_mbox_poison_payload_out *po; + struct cxl_mbox_poison_payload_in pi; + int nr_records = 0; + int rc; + + po = kvmalloc(cxlds->payload_size, GFP_KERNEL); + if (!po) + return -ENOMEM; + + pi.offset = cpu_to_le64(offset); + pi.length = cpu_to_le64(len); + + rc = mutex_lock_interruptible(&cxlds->poison_list_mutex); + if (rc) + goto out; + + do { + rc = cxl_mbox_send_cmd(cxlds, CXL_MBOX_OP_GET_POISON, &pi, + sizeof(pi), po, cxlds->payload_size); + if (rc) + break; + + if (trace_cxl_poison_enabled()) + cxl_trace_poison(po, cxlr, memdev_name, pcidev_name); + + /* Protect against an uncleared _FLAG_MORE */ + nr_records = nr_records + le16_to_cpu(po->count); + if (nr_records >= cxlds->poison_max) { + dev_dbg(&cxlmd->dev, "Max Error Records reached: %d\n", + nr_records); + break; + } + } while (po->flags & CXL_POISON_FLAG_MORE); + + mutex_unlock(&cxlds->poison_list_mutex); +out: + kvfree(po); + return rc; +} +EXPORT_SYMBOL_NS_GPL(cxl_mem_get_poison, CXL); + struct cxl_dev_state *cxl_dev_state_create(struct device *dev) { struct cxl_dev_state *cxlds; @@ -846,6 +926,7 @@ struct cxl_dev_state *cxl_dev_state_create(struct device *dev) } mutex_init(&cxlds->mbox_mutex); + mutex_init(&cxlds->poison_list_mutex); cxlds->dev = dev; return cxlds; diff --git a/drivers/cxl/cxlmem.h b/drivers/cxl/cxlmem.h index 669868cc1553..49d891347e39 100644 --- a/drivers/cxl/cxlmem.h +++ b/drivers/cxl/cxlmem.h @@ -192,6 +192,8 @@ 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: maximum media error records held in device cache + * @poison_list_mutex: Mutex to synchronize poison list retrieval * @mbox_mutex: Mutex to synchronize mailbox access. * @firmware_version: Firmware version for the memory device. * @enabled_cmds: Hardware commands found enabled in CEL. @@ -224,6 +226,8 @@ struct cxl_dev_state { size_t payload_size; size_t lsa_size; + u32 poison_max; + struct mutex poison_list_mutex; /* Protect reads of poison list */ struct mutex mbox_mutex; /* Protects device mailbox and firmware */ char firmware_version[0x10]; DECLARE_BITMAP(enabled_cmds, CXL_MEM_COMMAND_ID_MAX); @@ -349,6 +353,37 @@ struct cxl_mbox_set_partition_info { /* Get Poison List CXL 3.0 Spec 8.2.9.8.4.1 */ +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; + +/* + * Get Poison List address field encodes the starting + * address of poison, and the source of the poison. + */ +#define CXL_POISON_START_MASK GENMASK_ULL(63, 6) +#define CXL_POISON_SOURCE_MASK GENMASK(2, 0) + +/* Get Poison List record length is in units of 64 bytes */ +#define CXL_POISON_LEN_MULT 64 + +/* Kernel defined maximum for a list of poison errors */ +#define CXL_POISON_LIST_MAX 1024 + /* Get Poison List: Payload out flags */ #define CXL_POISON_FLAG_MORE BIT(0) #define CXL_POISON_FLAG_OVERFLOW BIT(1) @@ -395,6 +430,8 @@ 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(struct cxl_memdev *cxlmd, u64 offset, u64 len, + struct cxl_region *cxlr); #ifdef CONFIG_CXL_SUSPEND void cxl_mem_active_inc(void); void cxl_mem_active_dec(void); From patchwork Fri Nov 11 03:12:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alison Schofield X-Patchwork-Id: 13039528 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 04A94C433FE for ; Fri, 11 Nov 2022 03:13:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232431AbiKKDM5 (ORCPT ); Thu, 10 Nov 2022 22:12:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50250 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232476AbiKKDMz (ORCPT ); Thu, 10 Nov 2022 22:12:55 -0500 Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EDED05B5AC; Thu, 10 Nov 2022 19:12:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1668136374; x=1699672374; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=VsDB9dzd0mEr75cQiAY7peAbT1Qp+7elj42fOh/7AAo=; b=CXohdT7Bp1D0gxxie1HJ5GTlDiS1KHIObiEM6VNDOq6BbB+o2LwpYQn3 r4oxhfv+ZihSdO7BnjpIll94sTegw4VD1Of/TudnjgkjxsnBjzvEwkZZu seHoX1oVbHDnZX3CEQrOrSIs0/NkHEtMia5wf9J5imuzOcJH93li2gqf6 3hToYwXOyn0uPoezSNCMHAABVMhjOmpVJ104/45+78XLxuD0QmjVgkaxf Fmc4rVy16POO3iWefrexaply2w9Nv9TZ3U7rDMajHSBuJaqtvEUXIgU/B wLR8W1QZ/3G4Xy7K9GE3iyv4ZMF/QR81FsIFrPCob/4pwLqJD2LQXN32e Q==; X-IronPort-AV: E=McAfee;i="6500,9779,10527"; a="310224411" X-IronPort-AV: E=Sophos;i="5.96,155,1665471600"; d="scan'208";a="310224411" Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Nov 2022 19:12:54 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10527"; a="812296085" X-IronPort-AV: E=Sophos;i="5.96,155,1665471600"; d="scan'208";a="812296085" Received: from aschofie-mobl2.amr.corp.intel.com (HELO localhost) ([10.209.161.45]) by orsmga005-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Nov 2022 19:12:53 -0800 From: alison.schofield@intel.com To: Dan Williams , Ira Weiny , Vishal Verma , Dave Jiang , Ben Widawsky , Steven Rostedt , Ingo Molnar Cc: Alison Schofield , linux-cxl@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 3/6] cxl/memdev: Add trigger_poison_list sysfs attribute Date: Thu, 10 Nov 2022 19:12:41 -0800 Message-Id: <5055dd47526d900f85f43bb0d85f4ccd4c9502b6.1668115235.git.alison.schofield@intel.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-cxl@vger.kernel.org From: Alison Schofield When a boolean 'true' 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'. Signed-off-by: Alison Schofield --- Documentation/ABI/testing/sysfs-bus-cxl | 14 +++++++++ drivers/cxl/core/memdev.c | 41 +++++++++++++++++++++++++ 2 files changed, 55 insertions(+) diff --git a/Documentation/ABI/testing/sysfs-bus-cxl b/Documentation/ABI/testing/sysfs-bus-cxl index 8494ef27e8d2..1c5f4a853ba2 100644 --- a/Documentation/ABI/testing/sysfs-bus-cxl +++ b/Documentation/ABI/testing/sysfs-bus-cxl @@ -388,3 +388,17 @@ Description: 1), and checks that the hardware accepts the commit request. Reading this value indicates whether the region is committed or not. + + +What: /sys/bus/cxl/devices/memX/trigger_poison_list +Date: November, 2022 +KernelVersion: v6.2 +Contact: linux-cxl@vger.kernel.org +Description: + (WO) When a boolean 'true' 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'. diff --git a/drivers/cxl/core/memdev.c b/drivers/cxl/core/memdev.c index 20ce488a7754..06d265db5127 100644 --- a/drivers/cxl/core/memdev.c +++ b/drivers/cxl/core/memdev.c @@ -106,12 +106,45 @@ static ssize_t numa_node_show(struct device *dev, struct device_attribute *attr, } static DEVICE_ATTR_RO(numa_node); +static ssize_t trigger_poison_list_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t len) +{ + struct cxl_memdev *cxlmd = to_cxl_memdev(dev); + struct cxl_dev_state *cxlds = cxlmd->cxlds; + u64 offset, length; + bool tmp; + int rc; + + if (kstrtobool(buf, &tmp)) + return -EINVAL; + + /* Per CXL Spec, separate the pmem and ram poison list reads */ + if (resource_size(&cxlds->pmem_res)) { + offset = cxlds->pmem_res.start; + length = resource_size(&cxlds->pmem_res); + rc = cxl_mem_get_poison(cxlmd, offset, length, NULL); + if (rc) + return rc; + } + if (resource_size(&cxlds->ram_res)) { + offset = cxlds->ram_res.start; + length = resource_size(&cxlds->ram_res); + rc = cxl_mem_get_poison(cxlmd, offset, length, NULL); + if (rc) + return rc; + } + return len; +} +static DEVICE_ATTR_WO(trigger_poison_list); + 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_trigger_poison_list.attr, NULL, }; @@ -130,6 +163,14 @@ 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_trigger_poison_list.attr) { + struct device *dev = kobj_to_dev(kobj); + + if (!test_bit(CXL_MEM_COMMAND_ID_GET_POISON, + to_cxl_memdev(dev)->cxlds->enabled_cmds)) + return 0; + } return a->mode; } From patchwork Fri Nov 11 03:12:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alison Schofield X-Patchwork-Id: 13039529 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 18A2DC433FE for ; Fri, 11 Nov 2022 03:13:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232607AbiKKDNB (ORCPT ); Thu, 10 Nov 2022 22:13:01 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50272 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231483AbiKKDM5 (ORCPT ); Thu, 10 Nov 2022 22:12:57 -0500 Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AA3A72EF42; Thu, 10 Nov 2022 19:12:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1668136376; x=1699672376; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=D2Rd/Pgneu6uQpvUYP+09V/ctmxkFwMNJvxyOCowpy0=; b=Pdq3mywfMNQPVHBqLsIsLvShiWWCTPHHmYmRrhMuaw8bFtLm7+LlPE8O S5V7sGrhuVHCsr3AvAkAqA0YUsJghmyoBqzuTo4/FlQturgwgVDl8kZZg sWZht16t+KbRAovtv3OD8AvAvyNZ8SGXKAezmaGYTgvqmddW2eJqiPrt3 iVljrVXt9JjKc4JQVGqsv0DupTxzZXrwObmMOVpOq9fPm/Uvh6p0w23Z6 MldhNMZqo9L9GLOeOymuHklwkp1UhRPO0AZJyPBmVal4WR67Dep1R4Qm6 LlLXQwoAvD9kwZVyo10n68BUtzHk6dCla/se8dg9uxaoufNbcHLdtmnlP w==; X-IronPort-AV: E=McAfee;i="6500,9779,10527"; a="310224414" X-IronPort-AV: E=Sophos;i="5.96,155,1665471600"; d="scan'208";a="310224414" Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Nov 2022 19:12:56 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10527"; a="812296090" X-IronPort-AV: E=Sophos;i="5.96,155,1665471600"; d="scan'208";a="812296090" Received: from aschofie-mobl2.amr.corp.intel.com (HELO localhost) ([10.209.161.45]) by orsmga005-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Nov 2022 19:12:55 -0800 From: alison.schofield@intel.com To: Dan Williams , Ira Weiny , Vishal Verma , Dave Jiang , Ben Widawsky , Steven Rostedt , Ingo Molnar Cc: Alison Schofield , linux-cxl@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 4/6] cxl/region: Add trigger_poison_list sysfs attribute Date: Thu, 10 Nov 2022 19:12:42 -0800 Message-Id: X-Mailer: git-send-email 2.37.3 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-cxl@vger.kernel.org From: Alison Schofield When a boolean 'true' is written to this attribute the region driver retrieves the poison list for the capacity each device contributes to this region. The list includes addresses that are poisoned, or would result in poison if accessed, and the source of the poison. The retrieved errors are logged as kernel trace events with the label 'cxl_poison'. Devices not supporting the poison list capability are ignored. Signed-off-by: Alison Schofield Reviewed-by: Jonathan Cameron --- Documentation/ABI/testing/sysfs-bus-cxl | 14 +++++++++++ drivers/cxl/core/region.c | 33 +++++++++++++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/Documentation/ABI/testing/sysfs-bus-cxl b/Documentation/ABI/testing/sysfs-bus-cxl index 1c5f4a853ba2..54fad3bdcb2b 100644 --- a/Documentation/ABI/testing/sysfs-bus-cxl +++ b/Documentation/ABI/testing/sysfs-bus-cxl @@ -402,3 +402,17 @@ Description: attribute is only visible for devices supporting the capability. The retrieved errors are logged as kernel trace events with the label 'cxl_poison'. + + +What: /sys/bus/cxl/devices/regionZ/trigger_poison_list +Date: November, 2022 +KernelVersion: v6.2 +Contact: linux-cxl@vger.kernel.org +Description: + (WO) When a boolean 'true' is written to this attribute the + region driver retrieves the poison list for the capacity + each device contributes to this region. The list includes + addresses that are poisoned, or would result in poison if + accessed, and the source of the poison. The retrieved + errors are logged as kernel trace events with the label + 'cxl_poison'. diff --git a/drivers/cxl/core/region.c b/drivers/cxl/core/region.c index f9ae5ad284ff..68821238491e 100644 --- a/drivers/cxl/core/region.c +++ b/drivers/cxl/core/region.c @@ -72,6 +72,38 @@ static int is_dup(struct device *match, void *data) return 0; } +static ssize_t trigger_poison_list_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t len) +{ + struct cxl_region *cxlr = to_cxl_region(dev); + struct cxl_region_params *p = &cxlr->params; + struct cxl_endpoint_decoder *cxled; + struct cxl_memdev *cxlmd; + u64 offset, length; + int rc, i; + bool tmp; + + if (kstrtobool(buf, &tmp)) + return -EINVAL; + + for (i = 0; i < p->nr_targets; i++) { + cxled = p->targets[i]; + cxlmd = cxled_to_memdev(cxled); + if (!test_bit(CXL_MEM_COMMAND_ID_GET_POISON, + cxlmd->cxlds->enabled_cmds)) + continue; + + offset = cxl_dpa_resource_start(cxled); + length = cxl_dpa_size(cxled); + rc = cxl_mem_get_poison(cxlmd, offset, length, cxlr); + if (rc) + return rc; + } + return len; +} +static DEVICE_ATTR_WO(trigger_poison_list); + static ssize_t uuid_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t len) { @@ -570,6 +602,7 @@ static struct attribute *cxl_region_attrs[] = { &dev_attr_interleave_granularity.attr, &dev_attr_resource.attr, &dev_attr_size.attr, + &dev_attr_trigger_poison_list.attr, NULL, }; From patchwork Fri Nov 11 03:12:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alison Schofield X-Patchwork-Id: 13039530 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 4BA9CC4321E for ; Fri, 11 Nov 2022 03:13:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232684AbiKKDND (ORCPT ); Thu, 10 Nov 2022 22:13:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50300 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232507AbiKKDM7 (ORCPT ); Thu, 10 Nov 2022 22:12:59 -0500 Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8468A5CD12; Thu, 10 Nov 2022 19:12:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1668136378; x=1699672378; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=JdyavRtcyKYFKOnnExa3qY1SoXZOphSrTHOAQ8KDAJw=; b=MApE+J/RoaEae/iGA01GOeL8nmN+cv22SONSdf4UWytH0xCw1oR8AdAD 96S7Ey6bFaPh6G3Wh9PtpNeD1yejXRHUeYzIfViXO9e2VekSMn7/mstaq ChB7+RNMV2DUBCoo8uY0pr29MhkThHUp1SZ95osPtBnm26GHqxmRyKuiP Xn+zA2fuAtiEe2QL+TZWvnAVBS1EFXwcv3uk6VOjOJv11fHVfAlZFbLKX ZApGaRcJBtBvQoW81DUl/6sA27AxFNGdscP1GHKlUc4kQYh5L5MbUn2mp Eqv/9osZyRXGauBRlpmCYKt1fd+EB3rbMxr3HElNXdM6InzTv+4jQNsGC w==; X-IronPort-AV: E=McAfee;i="6500,9779,10527"; a="310224418" X-IronPort-AV: E=Sophos;i="5.96,155,1665471600"; d="scan'208";a="310224418" Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Nov 2022 19:12:58 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10527"; a="812296101" X-IronPort-AV: E=Sophos;i="5.96,155,1665471600"; d="scan'208";a="812296101" Received: from aschofie-mobl2.amr.corp.intel.com (HELO localhost) ([10.209.161.45]) by orsmga005-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Nov 2022 19:12:57 -0800 From: alison.schofield@intel.com To: Dan Williams , Ira Weiny , Vishal Verma , Dave Jiang , Ben Widawsky , Steven Rostedt , Ingo Molnar Cc: Alison Schofield , linux-cxl@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 5/6] tools/testing/cxl: Mock the max err records field of Identify cmd Date: Thu, 10 Nov 2022 19:12:43 -0800 Message-Id: <14b883bd220ff388cc3a287cf104d83d53a2f520.1668115235.git.alison.schofield@intel.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-cxl@vger.kernel.org From: Alison Schofield The CXL mbox command Identify reports the maximum media error records that a device will report. Mock it here for testing the GET POISON LIST mbox command. Signed-off-by: Alison Schofield --- tools/testing/cxl/test/mem.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tools/testing/cxl/test/mem.c b/tools/testing/cxl/test/mem.c index aa2df3a15051..f0704d090073 100644 --- a/tools/testing/cxl/test/mem.c +++ b/tools/testing/cxl/test/mem.c @@ -111,6 +111,10 @@ static int mock_id(struct cxl_dev_state *cxlds, struct cxl_mbox_cmd *cmd) cpu_to_le64(DEV_SIZE / CXL_CAPACITY_MULTIPLIER), }; + __le32 val = cpu_to_le32(SZ_64); + + memcpy(id.poison_list_max_mer, &val, 3); + if (cmd->size_out < sizeof(id)) return -EINVAL; From patchwork Fri Nov 11 03:12:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alison Schofield X-Patchwork-Id: 13039531 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 CBC61C4332F for ; Fri, 11 Nov 2022 03:13:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231802AbiKKDNG (ORCPT ); Thu, 10 Nov 2022 22:13:06 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50432 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232667AbiKKDND (ORCPT ); Thu, 10 Nov 2022 22:13:03 -0500 Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7FC2F5CD29; Thu, 10 Nov 2022 19:13:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1668136380; x=1699672380; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Y00FqPXd0tXMVfbMPOYOFfjRtaD0786m2Qc/OlOfGUE=; b=IUdDeEcWfeS9KM33cf7hVpD8Az0gL3y3vfxU+Fdsb/MJyFviz3FLIoc4 cWZKLYlVg8Y0FM88FSzBw9vZAVE1vsPIGhFu5Lr8Ce0mc4VA/dARTEOjX WYefm52/CWHIPPhsaAsDFZ9l7kwJRJMOXfGXMe39WhE2bMzeajtRigpWQ dQBhP8LU2lxYyhh6e0CCegh+SAXh/mP+c4cJZDZqpErXu6m39qnd+j44k FHg5ubgQA7PTMhD0ADaP+pb8upN0lgv3SsyTK9iqyTV5UZcZyj4rSOnoc ycT1a7EUUmvJ5Uy/MHebiwf4Wj78WVpPIW/W7rGrpBna/tEIa26F9MlzU g==; X-IronPort-AV: E=McAfee;i="6500,9779,10527"; a="310224419" X-IronPort-AV: E=Sophos;i="5.96,155,1665471600"; d="scan'208";a="310224419" Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Nov 2022 19:13:00 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10527"; a="812296108" X-IronPort-AV: E=Sophos;i="5.96,155,1665471600"; d="scan'208";a="812296108" Received: from aschofie-mobl2.amr.corp.intel.com (HELO localhost) ([10.209.161.45]) by orsmga005-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Nov 2022 19:12:59 -0800 From: alison.schofield@intel.com To: Dan Williams , Ira Weiny , Vishal Verma , Dave Jiang , Ben Widawsky , Steven Rostedt , Ingo Molnar Cc: Alison Schofield , linux-cxl@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 6/6] tools/testing/cxl: Mock the Get Poison List mbox command Date: Thu, 10 Nov 2022 19:12:44 -0800 Message-Id: <7accc4b25613bd04ded1c48fa317dcf08803575f.1668115235.git.alison.schofield@intel.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-cxl@vger.kernel.org From: Alison Schofield Return fake poison error records when the get poison list mbox command is issued. This supports testing the kernel tracing and cxl list capabilities for media errors. Signed-off-by: Alison Schofield Reviewed-by: Jonathan Cameron --- tools/testing/cxl/test/mem.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/tools/testing/cxl/test/mem.c b/tools/testing/cxl/test/mem.c index f0704d090073..f729e055605d 100644 --- a/tools/testing/cxl/test/mem.c +++ b/tools/testing/cxl/test/mem.c @@ -38,6 +38,10 @@ static struct cxl_cel_entry mock_cel[] = { .opcode = cpu_to_le16(CXL_MBOX_OP_GET_HEALTH_INFO), .effect = cpu_to_le16(0), }, + { + .opcode = cpu_to_le16(CXL_MBOX_OP_GET_POISON), + .effect = cpu_to_le16(0), + }, }; /* See CXL 2.0 Table 181 Get Health Info Output Payload */ @@ -207,6 +211,30 @@ static int mock_health_info(struct cxl_dev_state *cxlds, return 0; } +static int mock_get_poison(struct cxl_dev_state *cxlds, struct cxl_mbox_cmd *cmd) +{ + struct { + struct cxl_mbox_poison_payload_out poison_out; + struct cxl_poison_record record; + } mock_poison_list = { + .poison_out = { + .count = cpu_to_le16(1), + }, + .record = { + /* .address encodes DPA and poison source bits */ + .address = cpu_to_le64(CXL_POISON_SOURCE_INTERNAL), + .length = cpu_to_le32(1), + }, + }; + + if (cmd->size_out < sizeof(mock_poison_list)) + return -EINVAL; + + memcpy(cmd->payload_out, &mock_poison_list, sizeof(mock_poison_list)); + cmd->size_out = sizeof(mock_poison_list); + return 0; +} + static int cxl_mock_mbox_send(struct cxl_dev_state *cxlds, struct cxl_mbox_cmd *cmd) { struct device *dev = cxlds->dev; @@ -234,6 +262,9 @@ static int cxl_mock_mbox_send(struct cxl_dev_state *cxlds, struct cxl_mbox_cmd * case CXL_MBOX_OP_GET_HEALTH_INFO: rc = mock_health_info(cxlds, cmd); break; + case CXL_MBOX_OP_GET_POISON: + rc = mock_get_poison(cxlds, cmd); + break; default: break; }