From patchwork Sun Oct 1 22:31:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alison Schofield X-Patchwork-Id: 13405488 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 DA89AE78499 for ; Sun, 1 Oct 2023 22:31:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234245AbjJAWbq (ORCPT ); Sun, 1 Oct 2023 18:31:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49014 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234055AbjJAWbp (ORCPT ); Sun, 1 Oct 2023 18:31:45 -0400 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.126]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EEF74CE for ; Sun, 1 Oct 2023 15:31:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1696199499; x=1727735499; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=HeCMJQEot2esdShY0EXFtWrMW2AeAXtVWZdLs5/EsNU=; b=PXVRYV//2zYv3voODdwZ9eNwnozaPpt+IjwTb8w77pY2J2psTIl1IATY Ndz3IDV8y0sz/IEIr71BlUZt67eW97TdlR3YOudzY5NuGf8EQVlAYN4fr 3FvMG5TuyqdNhpLB17aw5uMJWtvGMl4FYdoph/kNcN09ibTq7OhiWPpWw i3kcYch3nPtZm+wCfoXDXgeT7SuT4knhMRm+OojB6etCbU3UJRgQN1LW0 gxQ1e4wc6YnPtaY38wy0gN5kmFZNuPzzpWoqGStqTt0c024mwhtECqTaN PLWh/OATX1TTiIrz787Q2rQhq45L41I2y5H3DT1K/AZ5bay+emrom8lJd Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10850"; a="367618310" X-IronPort-AV: E=Sophos;i="6.03,193,1694761200"; d="scan'208";a="367618310" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Oct 2023 15:31:38 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10850"; a="779781949" X-IronPort-AV: E=Sophos;i="6.03,193,1694761200"; d="scan'208";a="779781949" Received: from aschofie-mobl2.amr.corp.intel.com (HELO localhost) ([10.251.20.198]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Oct 2023 15:31:38 -0700 From: alison.schofield@intel.com To: Vishal Verma Cc: Alison Schofield , nvdimm@lists.linux.dev, linux-cxl@vger.kernel.org Subject: [ndctl PATCH v2 1/5] libcxl: add interfaces for GET_POISON_LIST mailbox commands Date: Sun, 1 Oct 2023 15:31:31 -0700 Message-Id: X-Mailer: git-send-email 2.40.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 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 the Poison List as a set of Media Error Records that include the source of the error, the starting device physical address and length. Trigger the retrieval of the poison list by writing to the memory device sysfs attribute: trigger_poison_list. The CXL driver only offers triggering per memdev, so the trigger by region interface offered here is a convenience API that triggers a poison list retrieval for each memdev contributing to a region. int cxl_memdev_trigger_poison_list(struct cxl_memdev *memdev); int cxl_region_trigger_poison_list(struct cxl_region *region); The resulting poison records are logged as kernel trace events named 'cxl_poison'. Signed-off-by: Alison Schofield --- cxl/lib/libcxl.c | 47 ++++++++++++++++++++++++++++++++++++++++++++++ cxl/lib/libcxl.sym | 6 ++++++ cxl/libcxl.h | 2 ++ 3 files changed, 55 insertions(+) diff --git a/cxl/lib/libcxl.c b/cxl/lib/libcxl.c index af4ca44eae19..2f6e64ea2ae7 100644 --- a/cxl/lib/libcxl.c +++ b/cxl/lib/libcxl.c @@ -1647,6 +1647,53 @@ CXL_EXPORT int cxl_memdev_disable_invalidate(struct cxl_memdev *memdev) return 0; } +CXL_EXPORT int cxl_memdev_trigger_poison_list(struct cxl_memdev *memdev) +{ + 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/trigger_poison_list", memdev->dev_path) >= + len) { + err(ctx, "%s: buffer too small\n", + cxl_memdev_get_devname(memdev)); + return -ENXIO; + } + rc = sysfs_write_attr(ctx, path, "1\n"); + if (rc < 0) { + fprintf(stderr, + "%s: Failed write sysfs attr trigger_poison_list\n", + cxl_memdev_get_devname(memdev)); + return rc; + } + return 0; +} + +CXL_EXPORT int cxl_region_trigger_poison_list(struct cxl_region *region) +{ + struct cxl_memdev_mapping *mapping; + int rc; + + cxl_mapping_foreach(region, mapping) { + struct cxl_decoder *decoder; + struct cxl_memdev *memdev; + + decoder = cxl_mapping_get_decoder(mapping); + if (!decoder) + continue; + + memdev = cxl_decoder_get_memdev(decoder); + if (!memdev) + continue; + + rc = cxl_memdev_trigger_poison_list(memdev); + if (rc) + return rc; + } + + return 0; +} + CXL_EXPORT int cxl_memdev_enable(struct cxl_memdev *memdev) { struct cxl_ctx *ctx = cxl_memdev_get_ctx(memdev); diff --git a/cxl/lib/libcxl.sym b/cxl/lib/libcxl.sym index 8fa1cca3d0d7..277b7e21d6a6 100644 --- a/cxl/lib/libcxl.sym +++ b/cxl/lib/libcxl.sym @@ -264,3 +264,9 @@ global: cxl_memdev_update_fw; cxl_memdev_cancel_fw_update; } LIBCXL_5; + +LIBCXL_7 { +global: + cxl_memdev_trigger_poison_list; + cxl_region_trigger_poison_list; +} LIBCXL_6; diff --git a/cxl/libcxl.h b/cxl/libcxl.h index 0f4f4b2648fb..ecdffe36df2c 100644 --- a/cxl/libcxl.h +++ b/cxl/libcxl.h @@ -460,6 +460,8 @@ enum cxl_setpartition_mode { int cxl_cmd_partition_set_mode(struct cxl_cmd *cmd, enum cxl_setpartition_mode mode); +int cxl_memdev_trigger_poison_list(struct cxl_memdev *memdev); +int cxl_region_trigger_poison_list(struct cxl_region *region); #ifdef __cplusplus } /* extern "C" */ From patchwork Sun Oct 1 22:31:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alison Schofield X-Patchwork-Id: 13405489 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 054C3E7849B for ; Sun, 1 Oct 2023 22:31:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234055AbjJAWbq (ORCPT ); Sun, 1 Oct 2023 18:31:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49030 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229557AbjJAWbp (ORCPT ); Sun, 1 Oct 2023 18:31:45 -0400 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.126]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 336E8D3 for ; Sun, 1 Oct 2023 15:31:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1696199500; x=1727735500; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=qw6ErE+N/Zs5mIaQY8NIOuKAGUcYqneo1GoEkWUjLLw=; b=mg91a4mll6xhrKkCgTehH8ZFCuW4UIoq4AmRZpzK9y3MBhIWsBh/0Pvc BQrPr/9xnfzBU2Td+z4+Kcyz81b4MhlqhC1Fd5po6Vs/YzkG2Q70eAU8U REJuXXS3iQSeSXpHXY+AZBimvW8Y5woC/iAEmtSd7W6EAz+EJI+JHdnv7 eEBBE6EMXwH+4o8188BBCrkgjRhaQOER/TVl7oqWGQnCkIZzaTDDxYXs6 Jh2+OoQgFTw1hftRNME7SlVreLrAkUFgUV3N0h9wa80TtLnRhSciou89x qY2GyWtV94ibcnh/Ivyre+zsKzEiDJTsNnVltf9NB2XJ5GkBv5nvmPzNs w==; X-IronPort-AV: E=McAfee;i="6600,9927,10850"; a="367618316" X-IronPort-AV: E=Sophos;i="6.03,193,1694761200"; d="scan'208";a="367618316" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Oct 2023 15:31:39 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10850"; a="779781956" X-IronPort-AV: E=Sophos;i="6.03,193,1694761200"; d="scan'208";a="779781956" Received: from aschofie-mobl2.amr.corp.intel.com (HELO localhost) ([10.251.20.198]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Oct 2023 15:31:39 -0700 From: alison.schofield@intel.com To: Vishal Verma Cc: Alison Schofield , nvdimm@lists.linux.dev, linux-cxl@vger.kernel.org, Jonathan Cameron Subject: [ndctl PATCH v2 2/5] cxl: add an optional pid check to event parsing Date: Sun, 1 Oct 2023 15:31:32 -0700 Message-Id: X-Mailer: git-send-email 2.40.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-cxl@vger.kernel.org From: Alison Schofield When parsing CXL events, callers may only be interested in events that originate from the current process. Introduce an optional argument to the event trace context: event_pid. When event_pid is present, only include events with a matching pid in the returned JSON list. It is not a failure to see other, non matching results. Simply skip those. The initial use case for this is device poison listings where only the poison error records requested by this process are wanted. Signed-off-by: Alison Schofield Reviewed-by: Jonathan Cameron --- cxl/event_trace.c | 5 +++++ cxl/event_trace.h | 1 + 2 files changed, 6 insertions(+) diff --git a/cxl/event_trace.c b/cxl/event_trace.c index db8cc85f0b6f..269060898118 100644 --- a/cxl/event_trace.c +++ b/cxl/event_trace.c @@ -208,6 +208,11 @@ static int cxl_event_parse(struct tep_event *event, struct tep_record *record, return 0; } + if (event_ctx->event_pid) { + if (event_ctx->event_pid != tep_data_pid(event->tep, record)) + return 0; + } + if (event_ctx->parse_event) return event_ctx->parse_event(event, record, &event_ctx->jlist_head); diff --git a/cxl/event_trace.h b/cxl/event_trace.h index ec6267202c8b..7f7773b2201f 100644 --- a/cxl/event_trace.h +++ b/cxl/event_trace.h @@ -15,6 +15,7 @@ struct event_ctx { const char *system; struct list_head jlist_head; const char *event_name; /* optional */ + int event_pid; /* optional */ int (*parse_event)(struct tep_event *event, struct tep_record *record, struct list_head *jlist_head); /* optional */ }; From patchwork Sun Oct 1 22:31:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alison Schofield X-Patchwork-Id: 13405491 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 B5515E7849D for ; Sun, 1 Oct 2023 22:31:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234377AbjJAWbs (ORCPT ); Sun, 1 Oct 2023 18:31:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49044 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234325AbjJAWbq (ORCPT ); Sun, 1 Oct 2023 18:31:46 -0400 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.126]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1EBECC9 for ; Sun, 1 Oct 2023 15:31:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1696199501; x=1727735501; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ss2qGh5tc1nEVr3jP5K92uooA1Rp/4DXxMWMqYFg+wU=; b=LAItyVWBmKz6n2+OLndWi/VrIOfuyJHcUAuCLxtZn4JywsANvUTIgNTz k8i/V4tXKcFFnKGIB8n6RT4HoKZrJYC+XYLGyMeynS32ZN6+/vlisttQp +E4xMi2CRV9nj5J5HC/DjKt6NOj+y7vuKOkr9hfJmssnTeyWYSUffhOTI 9gkwlapRBlp3QQDYH7vY5qpV8rOg2s34SdlAi9Ccf+3+PBANuHxbxo04r 1HEGhJrHtyZLCNJQp5cZogaoe3U1mfTsJy9PIs6FehC+5Ua96YdQ/obj6 uBrvmU/9IIcn+gJTtrr8extNiCk/2SIAMNdjsyxn52TFSiP29Vqjf3Z+k Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10850"; a="367618320" X-IronPort-AV: E=Sophos;i="6.03,193,1694761200"; d="scan'208";a="367618320" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Oct 2023 15:31:40 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10850"; a="779781963" X-IronPort-AV: E=Sophos;i="6.03,193,1694761200"; d="scan'208";a="779781963" Received: from aschofie-mobl2.amr.corp.intel.com (HELO localhost) ([10.251.20.198]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Oct 2023 15:31:39 -0700 From: alison.schofield@intel.com To: Vishal Verma Cc: Alison Schofield , nvdimm@lists.linux.dev, linux-cxl@vger.kernel.org Subject: [ndctl PATCH v2 3/5] cxl/list: collect and parse the poison list records Date: Sun, 1 Oct 2023 15:31:33 -0700 Message-Id: <80f60f513ced74bc5eed7d0082faf74783fa41d7.1696196382.git.alison.schofield@intel.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-cxl@vger.kernel.org From: Alison Schofield Poison list records are logged as events in the kernel tracing subsystem. To prepare the poison list for cxl list, enable tracing, trigger the poison list read, and parse the generated cxl_poison events into a json representation. Signed-off-by: Alison Schofield --- cxl/json.c | 208 ++++++++++++++++++++++++++++++++++++++++++++++++++++ util/json.h | 1 + 2 files changed, 209 insertions(+) diff --git a/cxl/json.c b/cxl/json.c index 7678d02020b6..36db73de4f8f 100644 --- a/cxl/json.c +++ b/cxl/json.c @@ -2,15 +2,19 @@ // Copyright (C) 2015-2021 Intel Corporation. All rights reserved. #include #include +#include #include #include #include #include #include +#include +#include #include "filter.h" #include "json.h" #include "../daxctl/json.h" +#include "event_trace.h" #define CXL_FW_VERSION_STR_LEN 16 #define CXL_FW_MAX_SLOTS 4 @@ -571,6 +575,190 @@ err_jobj: return NULL; } +/* CXL 8.2.9.5.4.1 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 + +/* 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) + +static struct json_object * +util_cxl_poison_events_to_json(struct tracefs_instance *inst, bool is_region, + unsigned long flags) +{ + struct json_object *jerrors, *jmedia, *jobj = NULL; + struct jlist_node *jnode, *next; + struct event_ctx ectx = { + .event_name = "cxl_poison", + .event_pid = getpid(), + .system = "cxl", + }; + int rc, count = 0; + + list_head_init(&ectx.jlist_head); + rc = cxl_parse_events(inst, &ectx); + if (rc < 0) { + fprintf(stderr, "Failed to parse events: %d\n", rc); + return NULL; + } + /* Add nr_poison_records:0 to json */ + if (list_empty(&ectx.jlist_head)) + goto out; + + jerrors = json_object_new_array(); + if (!jerrors) + return NULL; + + list_for_each_safe(&ectx.jlist_head, jnode, next, list) { + struct json_object *jval = NULL; + struct json_object *jp = NULL; + int source, pflags; + u64 addr, len; + + jp = json_object_new_object(); + if (!jp) + return NULL; + + if (is_region) { + /* Add the memdev name in a by region list */ + if (json_object_object_get_ex(jnode->jobj, "memdev", + &jval)) + json_object_object_add(jp, "memdev", jval); + } + + /* + * When listing is by memdev, region names and valid HPAs + * will appear if the poison address is part of a region. + * Pick up those valid region names and HPAs but ignore the + * empties and invalids. + */ + + /* Only add non NULL region names */ + if (json_object_object_get_ex(jnode->jobj, "region", &jval)) { + if (strlen(json_object_get_string(jval)) != 0) + json_object_object_add(jp, "region", jval); + } + /* Only display valid HPAs */ + if (json_object_object_get_ex(jnode->jobj, "hpa", &jval)) { + addr = json_object_get_uint64(jval); + if (addr != ULLONG_MAX) { + jobj = util_json_object_hex(addr, flags); + json_object_object_add(jp, "hpa", jobj); + } + } + if (json_object_object_get_ex(jnode->jobj, "dpa", &jval)) { + addr = json_object_get_int64(jval); + jobj = util_json_object_hex(addr, flags); + json_object_object_add(jp, "dpa", jobj); + } + if (json_object_object_get_ex(jnode->jobj, "dpa_length", &jval)) { + len = json_object_get_int64(jval); + jobj = util_json_object_size(len, flags); + json_object_object_add(jp, "dpa_length", jobj); + } + if (json_object_object_get_ex(jnode->jobj, "source", &jval)) { + source = json_object_get_int(jval); + if (source == CXL_POISON_SOURCE_UNKNOWN) + jobj = json_object_new_string("Unknown"); + else if (source == CXL_POISON_SOURCE_EXTERNAL) + jobj = json_object_new_string("External"); + else if (source == CXL_POISON_SOURCE_INTERNAL) + jobj = json_object_new_string("Internal"); + else if (source == CXL_POISON_SOURCE_INJECTED) + jobj = json_object_new_string("Injected"); + else if (source == CXL_POISON_SOURCE_VENDOR) + jobj = json_object_new_string("Vendor"); + else + jobj = json_object_new_string("Reserved"); + json_object_object_add(jp, "source", jobj); + } + if (json_object_object_get_ex(jnode->jobj, "flags", &jval)) { + char flag_str[32] = { '\0' }; + + pflags = json_object_get_int(jval); + if (pflags & CXL_POISON_FLAG_MORE) + strcat(flag_str, "More,"); + if (pflags & CXL_POISON_FLAG_OVERFLOW) + strcat(flag_str, "Overflow,"); + if (pflags & CXL_POISON_FLAG_SCANNING) + strcat(flag_str, "Scanning,"); + jobj = json_object_new_string(flag_str); + if (jobj) + json_object_object_add(jp, "flags", jobj); + } + if (json_object_object_get_ex(jnode->jobj, "overflow_t", &jval)) + json_object_object_add(jp, "overflow_time", jval); + + json_object_array_add(jerrors, jp); + count++; + } /* list_for_each_safe */ + +out: + jmedia = json_object_new_object(); + if (!jmedia) + return NULL; + + /* Always include the count. If count is zero, no records follow. */ + jobj = json_object_new_int(count); + if (jobj) + json_object_object_add(jmedia, "nr_poison_records", jobj); + if (count) + json_object_object_add(jmedia, "poison_records", jerrors); + + return jmedia; +} + +struct cxl_poison_ctx { + void *dev; + bool is_region; +}; + +static struct json_object * +util_cxl_poison_list_to_json(struct cxl_poison_ctx *pctx, + unsigned long flags) +{ + struct json_object *jmedia = NULL; + struct tracefs_instance *inst; + int rc; + + inst = tracefs_instance_create("cxl list"); + if (!inst) { + fprintf(stderr, "tracefs_instance_create() failed\n"); + return NULL; + } + + rc = cxl_event_tracing_enable(inst, "cxl", "cxl_poison"); + if (rc < 0) { + fprintf(stderr, "Failed to enable trace: %d\n", rc); + goto err_free; + } + + if (pctx->is_region) + rc = cxl_region_trigger_poison_list(pctx->dev); + else + rc = cxl_memdev_trigger_poison_list(pctx->dev); + if (rc) { + fprintf(stderr, "Failed write of sysfs attribute: %d\n", rc); + goto err_free; + } + + rc = cxl_event_tracing_disable(inst); + if (rc < 0) { + fprintf(stderr, "Failed to disable trace: %d\n", rc); + goto err_free; + } + + jmedia = util_cxl_poison_events_to_json(inst, pctx->is_region, flags); +err_free: + tracefs_instance_free(inst); + return jmedia; +} + struct json_object *util_cxl_memdev_to_json(struct cxl_memdev *memdev, unsigned long flags) { @@ -649,6 +837,16 @@ struct json_object *util_cxl_memdev_to_json(struct cxl_memdev *memdev, json_object_object_add(jdev, "firmware", jobj); } + if (flags & UTIL_JSON_POISON_LIST) { + struct cxl_poison_ctx pctx = { + .dev = memdev, + .is_region = false, + }; + jobj = util_cxl_poison_list_to_json(&pctx, flags); + if (jobj) + json_object_object_add(jdev, "poison", jobj); + } + json_object_set_userdata(jdev, memdev, NULL); return jdev; } @@ -987,6 +1185,16 @@ struct json_object *util_cxl_region_to_json(struct cxl_region *region, json_object_object_add(jregion, "state", jobj); } + if (flags & UTIL_JSON_POISON_LIST) { + struct cxl_poison_ctx pectx = { + .dev = region, + .is_region = true, + }; + jobj = util_cxl_poison_list_to_json(&pectx, flags); + if (jobj) + json_object_object_add(jregion, "poison", jobj); + } + util_cxl_mappings_append_json(jregion, region, flags); if (flags & UTIL_JSON_DAX) { diff --git a/util/json.h b/util/json.h index ea370df4d1b7..3ae4074a95c3 100644 --- a/util/json.h +++ b/util/json.h @@ -21,6 +21,7 @@ enum util_json_flags { UTIL_JSON_TARGETS = (1 << 11), UTIL_JSON_PARTITION = (1 << 12), UTIL_JSON_ALERT_CONFIG = (1 << 13), + UTIL_JSON_POISON_LIST = (1 << 14), }; void util_display_json_array(FILE *f_out, struct json_object *jarray, From patchwork Sun Oct 1 22:31:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alison Schofield X-Patchwork-Id: 13405490 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 7830EE7849C for ; Sun, 1 Oct 2023 22:31:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229557AbjJAWbr (ORCPT ); Sun, 1 Oct 2023 18:31:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49058 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234377AbjJAWbq (ORCPT ); Sun, 1 Oct 2023 18:31:46 -0400 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.126]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E905BD8 for ; Sun, 1 Oct 2023 15:31:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1696199503; x=1727735503; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=qCuYnXUKB6u9g+0ltmmaStCmBZs+B1gL2MkePG6yECg=; b=hev3l1UdyLppTz6DkKqQh8mqbfV5NAxAmU5iYuyQGbX72c2FcdVp9BPo aDjyI2BreBg9JxlUJR7RfUsfRCiLj9HCCPmOf+ftUOa2jIApi1XOZ6gKE y2gAOGbTXOqqMjAQsv2IOQQv3sfy4PpZZaOmOZsouPtZ1mVyIU4f81SwU ybhknAi68BO0leMZDzmmrGsunw8a0AB4RUr89vsv/7ResvlyQdbnsBOZD AtKrWAuso6YAcZdw5qxloCvJnDAadu2Jfz940IEhN1BIZ2ATV20PD4Xja Rv434PicgFN6uldQP9sPnwDYlLAydjwYHTbJGZBoVLbXFfKUR/SdhkYm5 A==; X-IronPort-AV: E=McAfee;i="6600,9927,10850"; a="367618322" X-IronPort-AV: E=Sophos;i="6.03,193,1694761200"; d="scan'208";a="367618322" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Oct 2023 15:31:40 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10850"; a="779781971" X-IronPort-AV: E=Sophos;i="6.03,193,1694761200"; d="scan'208";a="779781971" Received: from aschofie-mobl2.amr.corp.intel.com (HELO localhost) ([10.251.20.198]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Oct 2023 15:31:40 -0700 From: alison.schofield@intel.com To: Vishal Verma Cc: Alison Schofield , nvdimm@lists.linux.dev, linux-cxl@vger.kernel.org Subject: [ndctl PATCH v2 4/5] cxl/list: add --poison option to cxl list Date: Sun, 1 Oct 2023 15:31:34 -0700 Message-Id: X-Mailer: git-send-email 2.40.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 --poison option to 'cxl list' retrieves poison lists from memory devices supporting the capability and displays the returned poison records in the cxl list json. This option can apply to memdevs or regions. Example usage in the Documentation/cxl/cxl-list.txt update. Signed-off-by: Alison Schofield --- Documentation/cxl/cxl-list.txt | 64 ++++++++++++++++++++++++++++++++++ cxl/filter.h | 3 ++ cxl/list.c | 2 ++ 3 files changed, 69 insertions(+) diff --git a/Documentation/cxl/cxl-list.txt b/Documentation/cxl/cxl-list.txt index 838de4086678..2a4a8fe2efaa 100644 --- a/Documentation/cxl/cxl-list.txt +++ b/Documentation/cxl/cxl-list.txt @@ -415,6 +415,70 @@ OPTIONS --region:: Specify CXL region device name(s), or device id(s), to filter the listing. +-L:: +--poison:: + Include poison information. The poison list is retrieved from the + device(s) and poison records are added to the listing. Apply this + option to memdevs and regions where devices support the poison + list capability. + +---- +# cxl list -m mem11 --poison +[ + { + "memdev":"mem11", + "pmem_size":268435456, + "ram_size":0, + "serial":0, + "host":"0000:37:00.0", + "poison":{ + "nr_poison_records":1, + "poison_records":[ + { + "dpa":0, + "dpa_length":64, + "source":"Internal", + "flags":"", + "overflow_time":0 + } + ] + } + } +] +# cxl list -r region5 --poison +[ + { + "region":"region5", + "resource":1035623989248, + "size":2147483648, + "interleave_ways":2, + "interleave_granularity":4096, + "decode_state":"commit", + "poison":{ + "nr_poison_records":2, + "poison_records":[ + { + "memdev":"mem2", + "dpa":0, + "dpa_length":64, + "source":"Internal", + "flags":"", + "overflow_time":0 + }, + { + "memdev":"mem5", + "dpa":0, + "length":512, + "source":"Vendor", + "flags":"", + "overflow_time":0 + } + ] + } + } +] +---- + -v:: --verbose:: Increase verbosity of the output. This can be specified diff --git a/cxl/filter.h b/cxl/filter.h index 3f65990f835a..f38470e39543 100644 --- a/cxl/filter.h +++ b/cxl/filter.h @@ -30,6 +30,7 @@ struct cxl_filter_params { bool fw; bool alert_config; bool dax; + bool poison; int verbose; struct log_ctx ctx; }; @@ -88,6 +89,8 @@ static inline unsigned long cxl_filter_to_flags(struct cxl_filter_params *param) flags |= UTIL_JSON_ALERT_CONFIG; if (param->dax) flags |= UTIL_JSON_DAX | UTIL_JSON_DAX_DEVS; + if (param->poison) + flags |= UTIL_JSON_POISON_LIST; return flags; } diff --git a/cxl/list.c b/cxl/list.c index 93ba51ef895c..13fef8569340 100644 --- a/cxl/list.c +++ b/cxl/list.c @@ -57,6 +57,8 @@ static const struct option options[] = { "include memory device firmware information"), OPT_BOOLEAN('A', "alert-config", ¶m.alert_config, "include alert configuration information"), + OPT_BOOLEAN('L', "poison", ¶m.poison, + "include poison information "), OPT_INCR('v', "verbose", ¶m.verbose, "increase output detail"), #ifdef ENABLE_DEBUG OPT_BOOLEAN(0, "debug", &debug, "debug list walk"), From patchwork Sun Oct 1 22:31:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alison Schofield X-Patchwork-Id: 13405492 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 1B24CE7849E for ; Sun, 1 Oct 2023 22:31:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234289AbjJAWbr (ORCPT ); Sun, 1 Oct 2023 18:31:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49074 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234381AbjJAWbq (ORCPT ); Sun, 1 Oct 2023 18:31:46 -0400 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.126]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E90E5D9 for ; Sun, 1 Oct 2023 15:31:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1696199503; x=1727735503; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=akNBQPskrM8djdz7UCrD/NyGZShfvvdEJHx6llS4OvU=; b=fQE+thGmM4hhj6dQmxLZ5cxa+s2ZX1l7xblNydEaU/ZTyUijOzSeDSMy TKRoHGWt8DYHUcUx5LFhUCFNp6X4Fwn67om630fllOeAIHJjSFDOduDEA vnMXwRkoeiUIYzGz43w3qaWJ890p12NBXgy1WYwV3cAjC7D4uFKfF8A5k jsPx0nZaJpof4YtxZt8zO+pT6hBPCqzZszMfVxcxyVQvvjjZjBJ8pgy9x D9eEe4IpEg1UDafNL2uGzeUJbOxW/kFQDCJS8aUEX+tnN6LlkzYIH+B/s w5hRtRN+k73GSnbv7uowQE6ufTK3GGFnvIuD28rInNodX/sJ0641+/KRI g==; X-IronPort-AV: E=McAfee;i="6600,9927,10850"; a="367618324" X-IronPort-AV: E=Sophos;i="6.03,193,1694761200"; d="scan'208";a="367618324" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Oct 2023 15:31:41 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10850"; a="779781976" X-IronPort-AV: E=Sophos;i="6.03,193,1694761200"; d="scan'208";a="779781976" Received: from aschofie-mobl2.amr.corp.intel.com (HELO localhost) ([10.251.20.198]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Oct 2023 15:31:40 -0700 From: alison.schofield@intel.com To: Vishal Verma Cc: Alison Schofield , nvdimm@lists.linux.dev, linux-cxl@vger.kernel.org Subject: [ndctl PATCH v2 5/5] cxl/test: add cxl-poison.sh unit test Date: Sun, 1 Oct 2023 15:31:35 -0700 Message-Id: <51fdd212d139d203506cc2ee18abb362e5859e3e.1696196382.git.alison.schofield@intel.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-cxl@vger.kernel.org From: Alison Schofield Exercise cxl list, libcxl, and driver pieces of the get poison list pathway. Inject and clear poison using debugfs and use cxl-cli to read the poison list by memdev and by region. Signed-off-by: Alison Schofield --- test/cxl-poison.sh | 103 +++++++++++++++++++++++++++++++++++++++++++++ test/meson.build | 2 + 2 files changed, 105 insertions(+) create mode 100644 test/cxl-poison.sh diff --git a/test/cxl-poison.sh b/test/cxl-poison.sh new file mode 100644 index 000000000000..3c424532da7b --- /dev/null +++ b/test/cxl-poison.sh @@ -0,0 +1,103 @@ +#!/bin/bash +# SPDX-License-Identifier: GPL-2.0 +# Copyright (C) 2022 Intel Corporation. All rights reserved. + +. $(dirname $0)/common + +rc=77 + +set -ex + +trap 'err $LINENO' ERR + +check_prereq "jq" + +modprobe -r cxl_test +modprobe cxl_test +cxl list + +# THEORY OF OPERATION: Exercise cxl-cli and cxl driver ability to +# inject, clear, and get the poison list. Do it by memdev and by region. +# Based on current cxl-test topology. + +create_region() +{ + region=$($CXL create-region -d $decoder -m $memdevs | jq -r ".region") + + if [[ ! $region ]]; then + echo "create-region failed for $decoder" + err "$LINENO" + fi +} + +setup_x2_region() +{ + # Find an x2 decoder + decoder=$($CXL list -b cxl_test -D -d root | jq -r ".[] | + select(.pmem_capable == true) | + select(.nr_targets == 2) | + .decoder") + + # Find a memdev for each host-bridge interleave position + port_dev0=$($CXL list -T -d $decoder | jq -r ".[] | + .targets | .[] | select(.position == 0) | .target") + port_dev1=$($CXL list -T -d $decoder | jq -r ".[] | + .targets | .[] | select(.position == 1) | .target") + mem0=$($CXL list -M -p $port_dev0 | jq -r ".[0].memdev") + mem1=$($CXL list -M -p $port_dev1 | jq -r ".[0].memdev") + memdevs="$mem0 $mem1" +} + +find_media_errors() +{ + nr=$(echo $json | jq -r ".nr_poison_records") + if [[ $nr -ne $NR_ERRS ]]; then + echo "$mem: $NR_ERRS poison records expected, $nr found" + err "$LINENO" + fi +} + +# Turn Tracing ON +# Note that 'cxl list --poison' does toggle the tracing, so +# turning it on here is to enable the test user to view inject +# and clear trace events, if they wish. +echo 1 > /sys/kernel/tracing/events/cxl/cxl_poison/enable + +# Using DEBUGFS: +# When cxl-cli support for inject and clear arrives, replace +# the writes to /sys/kernel/debug with the new cxl commands +# that wrap them. + +# Poison by memdev: inject, list, clear, list. +# Inject 2 into pmem and 2 into ram partition. +echo 0x40000000 > /sys/kernel/debug/cxl/mem1/inject_poison +echo 0x40001000 > /sys/kernel/debug/cxl/mem1/inject_poison +echo 0x0 > /sys/kernel/debug/cxl/mem1/inject_poison +echo 0x600 > /sys/kernel/debug/cxl/mem1/inject_poison +NR_ERRS=4 +json=$("$CXL" list -m mem1 --poison | jq -r '.[].poison') +find_media_errors +echo 0x40000000 > /sys/kernel/debug/cxl/mem1/clear_poison +echo 0x40001000 > /sys/kernel/debug/cxl/mem1/clear_poison +echo 0x0 > /sys/kernel/debug/cxl/mem1/clear_poison +echo 0x600 > /sys/kernel/debug/cxl/mem1/clear_poison +NR_ERRS=0 +json=$("$CXL" list -m mem1 --poison | jq -r '.[].poison') +find_media_errors + +# Poison by region: inject, list, clear, list. +setup_x2_region +create_region +echo 0x40000000 > /sys/kernel/debug/cxl/"$mem0"/inject_poison +echo 0x40000000 > /sys/kernel/debug/cxl/"$mem1"/inject_poison +NR_ERRS=2 +json=$("$CXL" list -r "$region" --poison | jq -r '.[].poison') +find_media_errors +echo 0x40000000 > /sys/kernel/debug/cxl/"$mem0"/clear_poison +echo 0x40000000 > /sys/kernel/debug/cxl/"$mem1"/clear_poison +NR_ERRS=0 +json=$("$CXL" list -r "$region" --poison | jq -r '.[].poison') +find_media_errors + +check_dmesg "$LINENO" +modprobe -r cxl-test diff --git a/test/meson.build b/test/meson.build index 224adaf41fcc..2706fa5d633c 100644 --- a/test/meson.build +++ b/test/meson.build @@ -157,6 +157,7 @@ cxl_create_region = find_program('cxl-create-region.sh') cxl_xor_region = find_program('cxl-xor-region.sh') cxl_update_firmware = find_program('cxl-update-firmware.sh') cxl_events = find_program('cxl-events.sh') +cxl_poison = find_program('cxl-poison.sh') tests = [ [ 'libndctl', libndctl, 'ndctl' ], @@ -186,6 +187,7 @@ tests = [ [ 'cxl-create-region.sh', cxl_create_region, 'cxl' ], [ 'cxl-xor-region.sh', cxl_xor_region, 'cxl' ], [ 'cxl-events.sh', cxl_events, 'cxl' ], + [ 'cxl-poison.sh', cxl_poison, 'cxl' ], ] if get_option('destructive').enabled()