From patchwork Thu Mar 14 04:05:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alison Schofield X-Patchwork-Id: 13592070 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.10]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6912E5398 for ; Thu, 14 Mar 2024 04:05:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.10 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710389130; cv=none; b=u+aHgDI7wAZ60Q4Cyd6TAJWCiPTFYz0NRKOH0JTXI/lDHtjSQp+YTgBcxBtk6rRv7aSAeaJ56jSjWNBhmWazu5B67MjzmDzI9qQuqIFex5w/9dtqAThvSgXe3uMN8WHVtj+/bWiNilQnQjeI2zccRQlGNWCKvRYARIgZQbAxu4Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710389130; c=relaxed/simple; bh=w2PzexwB2loTJZ+xDVTgYJmA2I7IIdSALPdEyuLuCjI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=iMnhGRv8XxD2gD9CYaFUY6iciEs0lQQuJT6V9MpUe0a+CizfMZOdi1MjQ7U+CEbFgVGQgUwz0iH5uNKjpKODwiaXmeJAq/y2PT4qhk2aQbpnHexG4AhVN5Cx5S3aTfrNTjb1YmHtMI9swTBZzlxS4xJcr33hTA9d69N/7Q/3jR4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=RrDV0LiZ; arc=none smtp.client-ip=198.175.65.10 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="RrDV0LiZ" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1710389129; x=1741925129; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=w2PzexwB2loTJZ+xDVTgYJmA2I7IIdSALPdEyuLuCjI=; b=RrDV0LiZUfFpfYff8BtahEr1S7KboEvCUZMnT5sOto6BtBFpNVJ59VXG vVYAj0vCoj88CV7wz1wcGgVCfdeAt++J2RVgPXQfiiu3Qr+reA3bSIXWl yy75haB+WdPpTld/jE66YBCDohbDJjnAhINHmnL9Ye5YhaQfXDGu+sjfb nR+sWZ8dcXRzVfCs+SjjS90bZtiqBnTtuBhrkm0P2CuU0bihGqONjyJRC PrU6uVpo3FFU4K77brDLjDFuw21e29wexzHwXQxh0Tt+316UpYFjQ6XaT Lp3N0TalUWeg0chSdWTGqfiQ3DhmM1/mvGthPXoG0wkvF0aFVhIL94W3x A==; X-IronPort-AV: E=McAfee;i="6600,9927,11012"; a="22648793" X-IronPort-AV: E=Sophos;i="6.07,124,1708416000"; d="scan'208";a="22648793" Received: from fmviesa010.fm.intel.com ([10.60.135.150]) by orvoesa102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Mar 2024 21:05:28 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.07,124,1708416000"; d="scan'208";a="12080671" Received: from aschofie-mobl2.amr.corp.intel.com (HELO localhost) ([10.209.86.131]) by fmviesa010-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Mar 2024 21:05:26 -0700 From: alison.schofield@intel.com To: Vishal Verma Cc: Alison Schofield , nvdimm@lists.linux.dev, linux-cxl@vger.kernel.org, Dave Jiang Subject: [ndctl PATCH v11 1/7] libcxl: add interfaces for GET_POISON_LIST mailbox commands Date: Wed, 13 Mar 2024 21:05:17 -0700 Message-Id: X-Mailer: git-send-email 2.40.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: nvdimm@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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.1 8.2.9.9.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 Reviewed-by: Dave Jiang --- cxl/lib/libcxl.c | 47 ++++++++++++++++++++++++++++++++++++++++++++++ cxl/lib/libcxl.sym | 2 ++ cxl/libcxl.h | 2 ++ 3 files changed, 51 insertions(+) diff --git a/cxl/lib/libcxl.c b/cxl/lib/libcxl.c index ff27cdf7c44a..73db8f15c704 100644 --- a/cxl/lib/libcxl.c +++ b/cxl/lib/libcxl.c @@ -1761,6 +1761,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 de2cd84b2960..3f709c60db3d 100644 --- a/cxl/lib/libcxl.sym +++ b/cxl/lib/libcxl.sym @@ -280,4 +280,6 @@ global: cxl_memdev_get_pmem_qos_class; cxl_memdev_get_ram_qos_class; cxl_region_qos_class_mismatch; + cxl_memdev_trigger_poison_list; + cxl_region_trigger_poison_list; } LIBCXL_6; diff --git a/cxl/libcxl.h b/cxl/libcxl.h index a6af3fb04693..29165043ca3f 100644 --- a/cxl/libcxl.h +++ b/cxl/libcxl.h @@ -467,6 +467,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); int cxl_cmd_alert_config_set_life_used_prog_warn_threshold(struct cxl_cmd *cmd, int threshold); From patchwork Thu Mar 14 04:05:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alison Schofield X-Patchwork-Id: 13592071 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.10]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7E76C53BE for ; Thu, 14 Mar 2024 04:05:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.10 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710389131; cv=none; b=Mn3qdzZ/nJW6986TJ5gwzW/OGmLRHdDVk1L2UdZuZHuYOBmPHSyCt2Ym1bQ7h4uVXPALTrBGvfhgwK2YrW5Wa1Ba7uKK6FfK8ctdS/E8epQ1pz4vgE0nhkULogUtt/tm0o/uoP1nsLnNWrVca+Ys6oOped6l95I91Pcthx+E7Xc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710389131; c=relaxed/simple; bh=hbtZxXnoVzB3QnmV5PLXG8Us1o2ekbGwln4vc2//uhw=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=KYlhbEtdl50hrE1TmRyvsk8xo+OQ5M4Yf0WV2vWkYBY+43Ve825XhpC7hDNnQyoXYVwDq1eOnzN/aEjJo+b18XKaoySuhLTEiYRemkAl2JYh8fF9NfIgWk0YKum+tF9cZqUmOtutptUYjsZcCamXeVkSFpARrlDzeSYCRHAkkdA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=MaHLy9a5; arc=none smtp.client-ip=198.175.65.10 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="MaHLy9a5" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1710389130; x=1741925130; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=hbtZxXnoVzB3QnmV5PLXG8Us1o2ekbGwln4vc2//uhw=; b=MaHLy9a5bb6FFSDRWlesHYYmqmrxk0tKKkHQJdQMJ2XhEw1HUsM1W+ND 4T+Za+j/qKUY9uurVTt/pnIz4WhIzLWnT95fkhf6VCrDm63lBZ7dzG9cs pA3sO9AbywE3HqVlQvLKW2DxnME8di3zgsyyU9Xtlg+UJa2uh6lHW+gVH IsAp98l0wKdQ7sF02e+P8hcF0bfG7n4G/M5olYY0Sw9ERj/xRaSGJ2XEa dEYlZ/GDmUWUEdyw8FiZtVj17cTuI7oyYGJJ6Kd6Tjk7WdwhE6luEpQh8 cRPtivitmWpq1vzbUffz6h0XUV11c2ar5K104D4IXUJwVPCtj4mE64dC/ A==; X-IronPort-AV: E=McAfee;i="6600,9927,11012"; a="22648798" X-IronPort-AV: E=Sophos;i="6.07,124,1708416000"; d="scan'208";a="22648798" Received: from fmviesa010.fm.intel.com ([10.60.135.150]) by orvoesa102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Mar 2024 21:05:29 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.07,124,1708416000"; d="scan'208";a="12080677" Received: from aschofie-mobl2.amr.corp.intel.com (HELO localhost) ([10.209.86.131]) by fmviesa010-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Mar 2024 21:05:28 -0700 From: alison.schofield@intel.com To: Vishal Verma Cc: Alison Schofield , nvdimm@lists.linux.dev, linux-cxl@vger.kernel.org, Jonathan Cameron , Dave Jiang Subject: [ndctl PATCH v11 2/7] cxl/event_trace: add an optional pid check to event parsing Date: Wed, 13 Mar 2024 21:05:18 -0700 Message-Id: <5cefea50b4f62e60d642b4a627ca6943755758fc.1710386468.git.alison.schofield@intel.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: nvdimm@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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, simply skip the parsing of events without a matching pid. It is not a failure to see other, non matching events. The initial use case for this is device poison listings where only the media-error records requested by this process are wanted. Signed-off-by: Alison Schofield Reviewed-by: Jonathan Cameron Reviewed-by: Dave Jiang --- 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 1b5aa09de8b2..93a95f9729fd 100644 --- a/cxl/event_trace.c +++ b/cxl/event_trace.c @@ -214,6 +214,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 Thu Mar 14 04:05:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alison Schofield X-Patchwork-Id: 13592072 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.10]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0E1EF5CBD for ; Thu, 14 Mar 2024 04:05:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.10 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710389131; cv=none; b=u7EEmrB2bEPsa0KaWydM1n3eqUhrkk6dLYWEnnBbUMGnZuc7kv73A2IpclSA2/BxenfgC3n3ErgTepSnbyqlrSkS9tem9YWrVXHbya48O4/Zjo4+n0wOsCJJe5rDZ3V8OmOw2r8zUu2I3kbyk/szuvMu8dqATnz9pQSAS9hGkMA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710389131; c=relaxed/simple; bh=/X1stBiStEV3wCln7xoNBfmLXVoVlaflFQiGvyIJEJw=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=exBb3WYb1ErtPp5H69rUGOpfn25GTIJ8CZPCanJXMQ8NGe+uUdjfiemeNsal/OUZrF9i6lsoZ6NDQ6xAHeMN1zw2PBSBThadvLBYocYNffW9RiSmipBsgl1EColIzpaKS9+FRC87hBRUj5WHOz09io/dL7ebW6bshaBeD2HlOHA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=PKpZZJNC; arc=none smtp.client-ip=198.175.65.10 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="PKpZZJNC" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1710389130; x=1741925130; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=/X1stBiStEV3wCln7xoNBfmLXVoVlaflFQiGvyIJEJw=; b=PKpZZJNCMf1CQq2hKXkLj8iB871bYosrFBeDjTz0HByRszAuDDzW2lJ4 FTsFsYmq1odBh3fybm6pQjW6kZ9jmqD3wQdVMFTT/p17M1jvjvsgBE3ic dNgHemudMo483B2eTCO3fGss4Nrv+zeFrh1yQfYAmUehX4/2mxXoNL6Gp 9gyRi7Li+NdRjQuTX71tjsJ6o/3zjVbrVL/bzT76aB8pp5WaxPDvfHLPf lPqLLI314BZZypYGGFKNbnITN/eBDY/xiVYu22h5/1+sOoTnYGIa1kP4z jEMbzJqkUdSHz1jEWWYA0ypwTjZ64zghQ6SiBabnOJO2I403QJiPFfEqD w==; X-IronPort-AV: E=McAfee;i="6600,9927,11012"; a="22648801" X-IronPort-AV: E=Sophos;i="6.07,124,1708416000"; d="scan'208";a="22648801" Received: from fmviesa010.fm.intel.com ([10.60.135.150]) by orvoesa102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Mar 2024 21:05:30 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.07,124,1708416000"; d="scan'208";a="12080683" Received: from aschofie-mobl2.amr.corp.intel.com (HELO localhost) ([10.209.86.131]) by fmviesa010-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Mar 2024 21:05:29 -0700 From: alison.schofield@intel.com To: Vishal Verma Cc: Alison Schofield , nvdimm@lists.linux.dev, linux-cxl@vger.kernel.org, Dave Jiang Subject: [ndctl PATCH v11 3/7] cxl/event_trace: support poison context in event parsing Date: Wed, 13 Mar 2024 21:05:19 -0700 Message-Id: <3ebea9e20c9d95095acec7469dd5d12216dcc444.1710386468.git.alison.schofield@intel.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: nvdimm@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Alison Schofield CXL event tracing provides helpers to iterate through a trace buffer and extract events of interest. It offers two parsing options: a default parser that adds every field of an event to a json object, and a private parsing option where the caller can parse each event as it wishes. Although the private parser can do some conditional parsing based on field values, it has no method to receive additional information needed to make parsing decisions in the callback. Provide additional information required by cxl_poison events by adding a pointer to the poison_ctx directly the struct event_context. Tidy-up the calling convention by passing the entire event_ctx to it's own parse_event method rather than growing the param list. This is in preparation for adding a private parser requiring the additional context for cxl_poison events. Signed-off-by: Alison Schofield Reviewed-by: Dave Jiang --- cxl/event_trace.c | 9 ++++----- cxl/event_trace.h | 10 +++++++++- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/cxl/event_trace.c b/cxl/event_trace.c index 93a95f9729fd..640abdab67bf 100644 --- a/cxl/event_trace.c +++ b/cxl/event_trace.c @@ -60,7 +60,7 @@ static struct json_object *num_to_json(void *num, int elem_size, unsigned long f } static int cxl_event_to_json(struct tep_event *event, struct tep_record *record, - struct list_head *jlist_head) + struct event_ctx *ctx) { struct json_object *jevent, *jobj, *jarray; struct tep_format_field **fields; @@ -190,7 +190,7 @@ static int cxl_event_to_json(struct tep_event *event, struct tep_record *record, } } - list_add_tail(jlist_head, &jnode->list); + list_add_tail(&ctx->jlist_head, &jnode->list); return 0; err_jevent: @@ -220,10 +220,9 @@ static int cxl_event_parse(struct tep_event *event, struct tep_record *record, } if (event_ctx->parse_event) - return event_ctx->parse_event(event, record, - &event_ctx->jlist_head); + return event_ctx->parse_event(event, record, event_ctx); - return cxl_event_to_json(event, record, &event_ctx->jlist_head); + return cxl_event_to_json(event, record, event_ctx); } int cxl_parse_events(struct tracefs_instance *inst, struct event_ctx *ectx) diff --git a/cxl/event_trace.h b/cxl/event_trace.h index 7f7773b2201f..b77cafb410c4 100644 --- a/cxl/event_trace.h +++ b/cxl/event_trace.h @@ -11,13 +11,21 @@ struct jlist_node { struct list_node list; }; +struct poison_ctx { + struct json_object *jpoison; + struct cxl_region *region; + struct cxl_memdev *memdev; + unsigned long flags; +}; + struct event_ctx { const char *system; struct list_head jlist_head; const char *event_name; /* optional */ int event_pid; /* optional */ + struct poison_ctx *poison_ctx; /* optional */ int (*parse_event)(struct tep_event *event, struct tep_record *record, - struct list_head *jlist_head); /* optional */ + struct event_ctx *ctx); }; int cxl_parse_events(struct tracefs_instance *inst, struct event_ctx *ectx); From patchwork Thu Mar 14 04:05:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alison Schofield X-Patchwork-Id: 13592073 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.10]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D776B79EE for ; Thu, 14 Mar 2024 04:05:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.10 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710389132; cv=none; b=Lsm60AE91UKJO7litUUHDgyW8ZKXLYv48Z9zXGiXVv3dWUSeBq+xSAyrP3yrpn80AcR0/uKarcy2ZnM0MW15dkky5T239dXCnEkKWy8I937BYAkNH3dyadS7i8WW7gROrGYmZFal1w0PdhkLGwSGQXwxMqM+gFfKbOd/iaKVFFM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710389132; c=relaxed/simple; bh=f2uYpAZcM9h1Gz2rTb32ZN2hNmqJWyiUEWYb6QUeISY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=BbVYB/x7hOYKG1Rb2pzUYbsLFJmV/iv2WCIF86iUvKML1jbYCMaFFEyyxcemCcBL19H7paOIOzlKSQNJi/g2sua3RD4yoBf34fC0ed+MBhMxOyniOrEa60CQjAoMpSaTKTy+2VFgWpp+b3j07ZVOOLPLEM6GutRuqrBtua3vHQQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=lANihWFn; arc=none smtp.client-ip=198.175.65.10 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="lANihWFn" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1710389131; x=1741925131; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=f2uYpAZcM9h1Gz2rTb32ZN2hNmqJWyiUEWYb6QUeISY=; b=lANihWFn/MPnWH1VpdROMiFe313s0ZTVvP3acbQUpFdApbWJoISJ/Qhe csR84hF9qzoPf5tnoPJOKTCrPLA4Gj9LkPpuh+vPi4lPLBAJLH7RCw2W2 ct3KmNhw94jDYdJm1PnamRrFbLYvcZj0xYAyEeyX+ZYxJLV/115r4733c XYiBiYLEsrKTdwNyh7WpzC3T2ZO6IkrBLBqyhQA+tus3ZkgVtdwTA+bQo K71VjJ9JzQphwe0lBWSygvAl5UuS8DUD6i+6hawHnS4b/0aVXQHRyHjq3 6NY+fJTsbXaYc7f/LzP0P0GbW4BP9eF8sVRG+YHchIPyUWUGMkDigUtLR A==; X-IronPort-AV: E=McAfee;i="6600,9927,11012"; a="22648803" X-IronPort-AV: E=Sophos;i="6.07,124,1708416000"; d="scan'208";a="22648803" Received: from fmviesa010.fm.intel.com ([10.60.135.150]) by orvoesa102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Mar 2024 21:05:31 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.07,124,1708416000"; d="scan'208";a="12080689" Received: from aschofie-mobl2.amr.corp.intel.com (HELO localhost) ([10.209.86.131]) by fmviesa010-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Mar 2024 21:05:30 -0700 From: alison.schofield@intel.com To: Vishal Verma Cc: Alison Schofield , nvdimm@lists.linux.dev, linux-cxl@vger.kernel.org Subject: [ndctl PATCH v11 4/7] cxl/event_trace: add helpers to retrieve tep fields by type Date: Wed, 13 Mar 2024 21:05:20 -0700 Message-Id: <0dbf9557aaf5e8047440cb74f7df84ae404c11ba.1710386468.git.alison.schofield@intel.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: nvdimm@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Alison Schofield Add helpers to extract the value of an event record field given the field name. This is useful when the user knows the name and format of the field and simply needs to get it. The helpers also return the 'type'_MAX of the type when the field is Since this is in preparation for adding a cxl_poison private parser for 'cxl list --media-errors' support those specific required types: u8, u32, u64. Signed-off-by: Alison Schofield Reviewed-by: Dave Jiang Reviewed-by: Fan Ni --- cxl/event_trace.c | 37 +++++++++++++++++++++++++++++++++++++ cxl/event_trace.h | 8 +++++++- 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/cxl/event_trace.c b/cxl/event_trace.c index 640abdab67bf..324edb982888 100644 --- a/cxl/event_trace.c +++ b/cxl/event_trace.c @@ -15,6 +15,43 @@ #define _GNU_SOURCE #include +u64 cxl_get_field_u64(struct tep_event *event, struct tep_record *record, + const char *name) +{ + unsigned long long val; + + if (tep_get_field_val(NULL, event, name, record, &val, 0)) + return ULLONG_MAX; + + return val; +} + +u32 cxl_get_field_u32(struct tep_event *event, struct tep_record *record, + const char *name) +{ + char *val; + int len; + + val = tep_get_field_raw(NULL, event, name, record, &len, 0); + if (!val) + return UINT_MAX; + + return *(u32 *)val; +} + +u8 cxl_get_field_u8(struct tep_event *event, struct tep_record *record, + const char *name) +{ + char *val; + int len; + + val = tep_get_field_raw(NULL, event, name, record, &len, 0); + if (!val) + return UCHAR_MAX; + + return *(u8 *)val; +} + static struct json_object *num_to_json(void *num, int elem_size, unsigned long flags) { bool sign = flags & TEP_FIELD_IS_SIGNED; diff --git a/cxl/event_trace.h b/cxl/event_trace.h index b77cafb410c4..7b30c3922aef 100644 --- a/cxl/event_trace.h +++ b/cxl/event_trace.h @@ -5,6 +5,7 @@ #include #include +#include struct jlist_node { struct json_object *jobj; @@ -32,5 +33,10 @@ int cxl_parse_events(struct tracefs_instance *inst, struct event_ctx *ectx); int cxl_event_tracing_enable(struct tracefs_instance *inst, const char *system, const char *event); int cxl_event_tracing_disable(struct tracefs_instance *inst); - +u8 cxl_get_field_u8(struct tep_event *event, struct tep_record *record, + const char *name); +u32 cxl_get_field_u32(struct tep_event *event, struct tep_record *record, + const char *name); +u64 cxl_get_field_u64(struct tep_event *event, struct tep_record *record, + const char *name); #endif From patchwork Thu Mar 14 04:05:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alison Schofield X-Patchwork-Id: 13592075 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.10]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B42DC8BF8 for ; Thu, 14 Mar 2024 04:05:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.10 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710389135; cv=none; b=TRx0E8oU0mF6FsB3aVzjL10zt//0beI/fIDhO/oq9wbvFZHUrQSIYAS2W12y+i6b65SaYUZwHJF01txz1sBgh0bVJRaiunbXs9ZUfnkDzmiqL8Jf4T1jxCaZCAv2jwg/jG8WaK4yIJBsX23aiRE4gcmwepxbMVXCm8zsblmMWLI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710389135; c=relaxed/simple; bh=EmtUglyaKsNLMLpS4ME1KW7w3APTbjkZOU4AFJkGcNw=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=f6vy2hcca8mjgyz0Wz+ZWhMykOD+dHOHBhW/Yth725dqRnui1LKtrmHt/9r7OmT/4Nnoh1312iEJ3w7l6aFDNUpwMOZr5ARlu5NoTiRfFIsYSSlVY3BvX00isWdNf4OmwN4pyaQmlM2HgrJ2bkva//Ctd+PVBYpbGeqyDaXP8Sg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=N6cRb6yU; arc=none smtp.client-ip=198.175.65.10 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="N6cRb6yU" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1710389132; x=1741925132; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=EmtUglyaKsNLMLpS4ME1KW7w3APTbjkZOU4AFJkGcNw=; b=N6cRb6yUsVegHwo+TDsLzVndCPU4VCU5YQuJD8Dpz9KEiWCKHGktaew5 xlnWijBp2DF/zNtLaLbLkMvYbjFTtXkUj17ZDm2l/5yQKEpkHLSXxNjAc tB6C7NYDGkqdhEJdenJC/wM/KmmQ5rArhEM8WEPVBnrcHosrbeZKcaoul Dk7IElnpfHMQ00ehBwHL9iZWKaYCyDCNCgy/y4AqJ9fl7eUcGQZCYFMBN uHRYAI3JBcjZkiVyoz3ZzHhNC7CmfCdMH9/yZgIsprazaHfPAyh5do8s7 vguwQjStF7tEC35zN0dxEHdkE5IHhC8VL1JAUMGEBNmFM2PoKDyQQDDI3 g==; X-IronPort-AV: E=McAfee;i="6600,9927,11012"; a="22648805" X-IronPort-AV: E=Sophos;i="6.07,124,1708416000"; d="scan'208";a="22648805" Received: from fmviesa010.fm.intel.com ([10.60.135.150]) by orvoesa102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Mar 2024 21:05:32 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.07,124,1708416000"; d="scan'208";a="12080695" Received: from aschofie-mobl2.amr.corp.intel.com (HELO localhost) ([10.209.86.131]) by fmviesa010-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Mar 2024 21:05:31 -0700 From: alison.schofield@intel.com To: Vishal Verma Cc: Alison Schofield , nvdimm@lists.linux.dev, linux-cxl@vger.kernel.org Subject: [ndctl PATCH v11 5/7] cxl/list: collect and parse media_error records Date: Wed, 13 Mar 2024 21:05:21 -0700 Message-Id: <20c83daf14ac45542e9b6ed4cddfaf659e0ce7b0.1710386468.git.alison.schofield@intel.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: nvdimm@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Alison Schofield Media_error records are logged as events in the kernel tracing subsystem. To prepare the media_error records for cxl list, enable tracing, trigger the poison list read, and parse the generated cxl_poison events into a json representation. Use the event_trace private parsing option to customize the json representation based on cxl-list calling options and event field settings. Signed-off-by: Alison Schofield Reviewed-by: Dave Jiang --- cxl/json.c | 194 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 194 insertions(+) diff --git a/cxl/json.c b/cxl/json.c index fbe41c78e82a..974e98f13cec 100644 --- a/cxl/json.c +++ b/cxl/json.c @@ -1,16 +1,20 @@ // SPDX-License-Identifier: GPL-2.0 // 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,184 @@ err_jobj: return NULL; } +/* CXL Spec 3.1 Table 8-140 Media Error Record */ +#define CXL_POISON_SOURCE_MAX 7 +static const char *poison_source[] = { "Unknown", "External", "Internal", + "Injected", "Reserved", "Reserved", + "Reserved", "Vendor" }; + +/* CXL Spec 3.1 Table 8-139 Get Poison List Output Payload */ +#define CXL_POISON_FLAG_MORE BIT(0) +#define CXL_POISON_FLAG_OVERFLOW BIT(1) +#define CXL_POISON_FLAG_SCANNING BIT(2) + +static int poison_event_to_json(struct tep_event *event, + struct tep_record *record, + struct event_ctx *e_ctx) +{ + struct poison_ctx *p_ctx = e_ctx->poison_ctx; + struct json_object *jp, *jobj, *jpoison = p_ctx->jpoison; + struct cxl_memdev *memdev = p_ctx->memdev; + struct cxl_region *region = p_ctx->region; + unsigned long flags = p_ctx->flags; + const char *region_name = NULL; + char flag_str[32] = { '\0' }; + bool overflow = false; + u8 source, pflags; + u64 offset, ts; + u32 length; + char *str; + int len; + + jp = json_object_new_object(); + if (!jp) + return -ENOMEM; + + /* Skip records not in this region when listing by region */ + if (region) + region_name = cxl_region_get_devname(region); + if (region_name) + str = tep_get_field_raw(NULL, event, "region", record, &len, 0); + if ((region_name) && (strcmp(region_name, str) != 0)) { + json_object_put(jp); + return 0; + } + /* Include offset,length by region (hpa) or by memdev (dpa) */ + if (region) { + offset = cxl_get_field_u64(event, record, "hpa"); + if (offset != ULLONG_MAX) { + offset = offset - cxl_region_get_resource(region); + jobj = util_json_object_hex(offset, flags); + if (jobj) + json_object_object_add(jp, "offset", jobj); + } + } else if (memdev) { + offset = cxl_get_field_u64(event, record, "dpa"); + if (offset != ULLONG_MAX) { + jobj = util_json_object_hex(offset, flags); + if (jobj) + json_object_object_add(jp, "offset", jobj); + } + } + length = cxl_get_field_u32(event, record, "dpa_length"); + jobj = util_json_object_size(length, flags); + if (jobj) + json_object_object_add(jp, "length", jobj); + + /* Always include the poison source */ + source = cxl_get_field_u8(event, record, "source"); + if (source <= CXL_POISON_SOURCE_MAX) + jobj = json_object_new_string(poison_source[source]); + else + jobj = json_object_new_string("Reserved"); + if (jobj) + json_object_object_add(jp, "source", jobj); + + /* Include flags and overflow time if present */ + pflags = cxl_get_field_u8(event, record, "flags"); + if (pflags && pflags < UCHAR_MAX) { + if (pflags & CXL_POISON_FLAG_MORE) + strcat(flag_str, "More,"); + if (pflags & CXL_POISON_FLAG_SCANNING) + strcat(flag_str, "Scanning,"); + if (pflags & CXL_POISON_FLAG_OVERFLOW) { + strcat(flag_str, "Overflow,"); + overflow = true; + } + jobj = json_object_new_string(flag_str); + if (jobj) + json_object_object_add(jp, "flags", jobj); + } + if (overflow) { + ts = cxl_get_field_u64(event, record, "overflow_ts"); + jobj = util_json_object_hex(ts, flags); + if (jobj) + json_object_object_add(jp, "overflow_t", jobj); + } + json_object_array_add(jpoison, jp); + + return 0; +} + +static struct json_object * +util_cxl_poison_events_to_json(struct tracefs_instance *inst, + struct poison_ctx *p_ctx) +{ + struct event_ctx ectx = { + .event_name = "cxl_poison", + .event_pid = getpid(), + .system = "cxl", + .poison_ctx = p_ctx, + .parse_event = poison_event_to_json, + }; + int rc = 0; + + p_ctx->jpoison = json_object_new_array(); + if (!p_ctx->jpoison) + return NULL; + + rc = cxl_parse_events(inst, &ectx); + if (rc < 0) { + fprintf(stderr, "Failed to parse events: %d\n", rc); + goto put_jobj; + } + if (json_object_array_length(p_ctx->jpoison) == 0) + goto put_jobj; + + return p_ctx->jpoison; + +put_jobj: + json_object_put(p_ctx->jpoison); + return NULL; +} + +static struct json_object * +util_cxl_poison_list_to_json(struct cxl_region *region, + struct cxl_memdev *memdev, + unsigned long flags) +{ + struct json_object *jpoison = NULL; + struct poison_ctx p_ctx; + 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 (region) + rc = cxl_region_trigger_poison_list(region); + else + rc = cxl_memdev_trigger_poison_list(memdev); + if (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; + } + + p_ctx = (struct poison_ctx) { + .region = region, + .memdev = memdev, + .flags = flags, + }; + jpoison = util_cxl_poison_events_to_json(inst, &p_ctx); + +err_free: + tracefs_instance_free(inst); + return jpoison; +} + struct json_object *util_cxl_memdev_to_json(struct cxl_memdev *memdev, unsigned long flags) { @@ -664,6 +846,12 @@ struct json_object *util_cxl_memdev_to_json(struct cxl_memdev *memdev, json_object_object_add(jdev, "firmware", jobj); } + if (flags & UTIL_JSON_MEDIA_ERRORS) { + jobj = util_cxl_poison_list_to_json(NULL, memdev, flags); + if (jobj) + json_object_object_add(jdev, "media_errors", jobj); + } + json_object_set_userdata(jdev, memdev, NULL); return jdev; } @@ -1012,6 +1200,12 @@ struct json_object *util_cxl_region_to_json(struct cxl_region *region, json_object_object_add(jregion, "state", jobj); } + if (flags & UTIL_JSON_MEDIA_ERRORS) { + jobj = util_cxl_poison_list_to_json(region, NULL, flags); + if (jobj) + json_object_object_add(jregion, "media_errors", jobj); + } + util_cxl_mappings_append_json(jregion, region, flags); if (flags & UTIL_JSON_DAX) { From patchwork Thu Mar 14 04:05:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alison Schofield X-Patchwork-Id: 13592076 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.10]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8194F8F5B for ; Thu, 14 Mar 2024 04:05:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.10 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710389135; cv=none; b=gUd9DJu5Ujnm+5j9fWS3+B42t2AEBAwmOosLeyoppLU25oSj5X3/EkTIbVlYCNOuuTJSGB9NM69d0rdwmDO1CbLgWW7ayqnvnqIE3ahgWTLLfj6ya6PfW9+yhQdlapOHrmGos/2iS8rwsyGheFB2xWiPc8NviKn0H29I4l5vz48= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710389135; c=relaxed/simple; bh=Fh5lla700vONaOH1/VHbSAKzU7acUdog7JH10qr3u9I=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=oHiMK3UROQDO4VIlY3cKqCsVNA8ESwYVUrSlkDzUpzoBkEkecRsKCCIwntxjX5KUwjtPTVazHvRX73qWtYFVre+kzw9bLFPy6Ffz407ofqCTy0Bxy70TkWBdPtVRaHyZzaIMjZgUnof+EscNUvUPSWZCA4f/g/pJJjpWeibHx/k= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=HG/wX+/i; arc=none smtp.client-ip=198.175.65.10 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="HG/wX+/i" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1710389133; x=1741925133; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Fh5lla700vONaOH1/VHbSAKzU7acUdog7JH10qr3u9I=; b=HG/wX+/iZoO6p2eizX17uVTK4AA6WHHHHxdtKe4NFqlQ4h3g+1ysdJj/ S1IZMqGFGbh21j99Q/CgA6Ff8vZQvBdBsxLLeLHZUGs1PfmsNb38GmzCN 2NTt2RHmNI2YwrwyklsWJBnePhkiaWpjMVqsp5WC/AImVMBkaDQLFiEcn A2HuLvu7ruWcnYjLLMLT1d5PIYbdVf3EVrzNP1ddJmLo8o0SWA5ndJCJe b3tn2nkz5fHrl+v6vpZQ62KU/ImlAh1f7AVoijDJR8D0d4BQVH0KeKcah +zpo20EEKZu1uiUv/fwj05xEd5d9Zz8Gwk8W+wvnRb6C84ImnV1mPo5qx w==; X-IronPort-AV: E=McAfee;i="6600,9927,11012"; a="22648810" X-IronPort-AV: E=Sophos;i="6.07,124,1708416000"; d="scan'208";a="22648810" Received: from fmviesa010.fm.intel.com ([10.60.135.150]) by orvoesa102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Mar 2024 21:05:33 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.07,124,1708416000"; d="scan'208";a="12080700" Received: from aschofie-mobl2.amr.corp.intel.com (HELO localhost) ([10.209.86.131]) by fmviesa010-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Mar 2024 21:05:32 -0700 From: alison.schofield@intel.com To: Vishal Verma Cc: Alison Schofield , nvdimm@lists.linux.dev, linux-cxl@vger.kernel.org Subject: [ndctl PATCH v11 6/7] cxl/list: add --media-errors option to cxl list Date: Wed, 13 Mar 2024 21:05:22 -0700 Message-Id: X-Mailer: git-send-email 2.40.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: nvdimm@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Alison Schofield The --media-errors option to 'cxl list' retrieves poison lists from memory devices supporting the capability and displays the returned media_error records in the cxl list json. This option can apply to memdevs or regions. Include media-errors in the -vvv verbose option. Example usage in the Documentation/cxl/cxl-list.txt update. Signed-off-by: Alison Schofield Reviewed-by: Dave Jiang --- Documentation/cxl/cxl-list.txt | 62 +++++++++++++++++++++++++++++++++- cxl/filter.h | 3 ++ cxl/list.c | 3 ++ 3 files changed, 67 insertions(+), 1 deletion(-) diff --git a/Documentation/cxl/cxl-list.txt b/Documentation/cxl/cxl-list.txt index 838de4086678..6d3ef92c29e8 100644 --- a/Documentation/cxl/cxl-list.txt +++ b/Documentation/cxl/cxl-list.txt @@ -415,6 +415,66 @@ OPTIONS --region:: Specify CXL region device name(s), or device id(s), to filter the listing. +-L:: +--media-errors:: + Include media-error information. The poison list is retrieved from the + device(s) and media_error records are added to the listing. Apply this + option to memdevs and regions where devices support the poison list + capability. "offset:" is relative to the region resource when listing + by region and is the absolute device DPA when listing by memdev. + "source:" is one of: External, Internal, Injected, Vendor Specific, + or Unknown, as defined in CXL Specification v3.1 Table 8-140. + +---- +# cxl list -m mem9 --media-errors -u +{ + "memdev":"mem9", + "pmem_size":"1024.00 MiB (1073.74 MB)", + "pmem_qos_class":42, + "ram_size":"1024.00 MiB (1073.74 MB)", + "ram_qos_class":42, + "serial":"0x5", + "numa_node":1, + "host":"cxl_mem.5", + "media_errors":[ + { + "offset":"0x40000000", + "length":64, + "source":"Injected" + } + ] +} +---- +In the above example, region mappings can be found using: +"cxl list -p mem9 --decoders" +---- +# cxl list -r region5 --media-errors -u +{ + "region":"region5", + "resource":"0xf110000000", + "size":"2.00 GiB (2.15 GB)", + "type":"pmem", + "interleave_ways":2, + "interleave_granularity":4096, + "decode_state":"commit", + "media_errors":[ + { + "offset":"0x1000", + "length":64, + "source":"Injected" + }, + { + "offset":"0x2000", + "length":64, + "source":"Injected" + } + ] +} +---- +In the above example, memdev mappings can be found using: +"cxl list -r region5 --targets" and "cxl list -d " + + -v:: --verbose:: Increase verbosity of the output. This can be specified @@ -431,7 +491,7 @@ OPTIONS devices with --idle. - *-vvv* Everything *-vv* provides, plus enable - --health and --partition. + --health, --partition, --media-errors. --debug:: If the cxl tool was built with debug enabled, turn on debug diff --git a/cxl/filter.h b/cxl/filter.h index 3f65990f835a..956a46e0c7a9 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 media_errors; 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->media_errors) + flags |= UTIL_JSON_MEDIA_ERRORS; return flags; } diff --git a/cxl/list.c b/cxl/list.c index 93ba51ef895c..0b25d78248d5 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', "media-errors", ¶m.media_errors, + "include media-error information "), OPT_INCR('v', "verbose", ¶m.verbose, "increase output detail"), #ifdef ENABLE_DEBUG OPT_BOOLEAN(0, "debug", &debug, "debug list walk"), @@ -121,6 +123,7 @@ int cmd_list(int argc, const char **argv, struct cxl_ctx *ctx) param.fw = true; param.alert_config = true; param.dax = true; + param.media_errors = true; /* fallthrough */ case 2: param.idle = true; From patchwork Thu Mar 14 04:05:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alison Schofield X-Patchwork-Id: 13592074 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.10]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7B46F8F70 for ; Thu, 14 Mar 2024 04:05:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.10 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710389135; cv=none; b=o6hzu67q18/Cse+nv+Dy/EGa1f9ghfKYA8pJaB80B9fbVB94/IxwOi7h8i97Na68KjelBBGZJCvJ9k1px/alOBhSoNFyq7nNpVctRVLYxbBbGZIb54i0bZJYnoUMlb/FcW5pMMAJb0xVXbSO6Y/46szMP13wpudZKT5L2PzEG5Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710389135; c=relaxed/simple; bh=uta8tJ21GeBnYbAOfl0Q5MYKJMDYAWPc7SljrGN3qg0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=PX4CMcaXhrycqc2moZpZAC2qzDCJgPiXNL1Q5veQLM3rLgMS9YJ6qOXwtV1PwdRNLNF5ONzC/E6iAdpBKuEVL5nCksCkqDzi46BlX+LQBl9DSuuN8SIsjdwfZTOdI3oH4u+vHHAG4MxBu0eMJ6RB4f2calw1FXnhZbH+3euaXWc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=kPkQ6vAk; arc=none smtp.client-ip=198.175.65.10 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="kPkQ6vAk" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1710389134; x=1741925134; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=uta8tJ21GeBnYbAOfl0Q5MYKJMDYAWPc7SljrGN3qg0=; b=kPkQ6vAkcAHXar2wgT1w2hPMwnrzBAC19TtxZUXIBgDwpzTgYYxB/9Di u8hMT1ltt/uILrw8nY4y5draMBADicM964f0K7na4T3qvPz6+WG3xC3kq H72DMgGFENWHjX7k8z3OJ+0ysRlJupS+c+8ax1Xq1gvO5R7lg/z2XexUH r9KE2FA5bZQR6wv3DttGXyPa94iQQf+l1bxgQ43fKiSWmPwcurvmaIR97 +szKd7NBkV9nDbYxTmxT9XXZzAdH7+o8HOmPKAA+ENC50MQs898mfmuOY mq9pdL53/6dKjyfX5hmTdKsGDBteavbFtiU0u/0HA7HljAhOAhPW66Zrh g==; X-IronPort-AV: E=McAfee;i="6600,9927,11012"; a="22648812" X-IronPort-AV: E=Sophos;i="6.07,124,1708416000"; d="scan'208";a="22648812" Received: from fmviesa010.fm.intel.com ([10.60.135.150]) by orvoesa102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Mar 2024 21:05:34 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.07,124,1708416000"; d="scan'208";a="12080707" Received: from aschofie-mobl2.amr.corp.intel.com (HELO localhost) ([10.209.86.131]) by fmviesa010-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Mar 2024 21:05:32 -0700 From: alison.schofield@intel.com To: Vishal Verma Cc: Alison Schofield , nvdimm@lists.linux.dev, linux-cxl@vger.kernel.org Subject: [ndctl PATCH v11 7/7] cxl/test: add cxl-poison.sh unit test Date: Wed, 13 Mar 2024 21:05:23 -0700 Message-Id: <24c1f2ec413f92e8e6e8817b3d4d55f5bb142849.1710386468.git.alison.schofield@intel.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: nvdimm@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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 Reviewed-by: Dave Jiang --- test/cxl-poison.sh | 137 +++++++++++++++++++++++++++++++++++++++++++++ test/meson.build | 2 + 2 files changed, 139 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..af2e9dcd1a11 --- /dev/null +++ b/test/cxl-poison.sh @@ -0,0 +1,137 @@ +#!/bin/bash +# SPDX-License-Identifier: GPL-2.0 +# Copyright (C) 2023 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 + +rc=1 + +# 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. + +find_memdev() +{ + readarray -t capable_mems < <("$CXL" list -b "$CXL_TEST_BUS" -M | + jq -r ".[] | select(.pmem_size != null) | + select(.ram_size != null) | .memdev") + + if [ ${#capable_mems[@]} == 0 ]; then + echo "no memdevs found for test" + err "$LINENO" + fi + + memdev=${capable_mems[0]} +} + +create_x2_region() +{ + # Find an x2 decoder + decoder="$($CXL list -b "$CXL_TEST_BUS" -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")" + + region="$($CXL create-region -d "$decoder" -m "$mem0" "$mem1" | + jq -r ".region")" + if [[ ! $region ]]; then + echo "create-region failed for $decoder" + err "$LINENO" + fi + echo "$region" +} + +# When cxl-cli support for inject and clear arrives, replace +# the writes to /sys/kernel/debug with the new cxl commands. + +inject_poison_sysfs() +{ + memdev="$1" + addr="$2" + + echo "$addr" > /sys/kernel/debug/cxl/"$memdev"/inject_poison +} + +clear_poison_sysfs() +{ + memdev="$1" + addr="$2" + + echo "$addr" > /sys/kernel/debug/cxl/"$memdev"/clear_poison +} + +validate_poison_found() +{ + list_by="$1" + nr_expect="$2" + + poison_list="$($CXL list "$list_by" --media-errors | + jq -r '.[].media_errors')" + if [[ ! $poison_list ]]; then + nr_found=0 + else + nr_found=$(jq "length" <<< "$poison_list") + fi + if [ "$nr_found" -ne "$nr_expect" ]; then + echo "$nr_expect poison records expected, $nr_found found" + err "$LINENO" + fi +} + +test_poison_by_memdev() +{ + find_memdev + inject_poison_sysfs "$memdev" "0x40000000" + inject_poison_sysfs "$memdev" "0x40001000" + inject_poison_sysfs "$memdev" "0x600" + inject_poison_sysfs "$memdev" "0x0" + validate_poison_found "-m $memdev" 4 + + clear_poison_sysfs "$memdev" "0x40000000" + clear_poison_sysfs "$memdev" "0x40001000" + clear_poison_sysfs "$memdev" "0x600" + clear_poison_sysfs "$memdev" "0x0" + validate_poison_found "-m $memdev" 0 +} + +test_poison_by_region() +{ + create_x2_region + inject_poison_sysfs "$mem0" "0x40000000" + inject_poison_sysfs "$mem1" "0x40000000" + validate_poison_found "-r $region" 2 + + clear_poison_sysfs "$mem0" "0x40000000" + clear_poison_sysfs "$mem1" "0x40000000" + validate_poison_found "-r $region" 0 +} + +# Turn tracing on. Note that 'cxl list --poison' does toggle the tracing. +# Turning it on here allows the test user to also view inject and clear +# trace events. +echo 1 > /sys/kernel/tracing/events/cxl/cxl_poison/enable + +test_poison_by_memdev +test_poison_by_region + +check_dmesg "$LINENO" + +modprobe -r cxl-test diff --git a/test/meson.build b/test/meson.build index a965a79fd6cb..d871e28e17ce 100644 --- a/test/meson.build +++ b/test/meson.build @@ -160,6 +160,7 @@ cxl_events = find_program('cxl-events.sh') cxl_sanitize = find_program('cxl-sanitize.sh') cxl_destroy_region = find_program('cxl-destroy-region.sh') cxl_qos_class = find_program('cxl-qos-class.sh') +cxl_poison = find_program('cxl-poison.sh') tests = [ [ 'libndctl', libndctl, 'ndctl' ], @@ -192,6 +193,7 @@ tests = [ [ 'cxl-sanitize.sh', cxl_sanitize, 'cxl' ], [ 'cxl-destroy-region.sh', cxl_destroy_region, 'cxl' ], [ 'cxl-qos-class.sh', cxl_qos_class, 'cxl' ], + [ 'cxl-poison.sh', cxl_poison, 'cxl' ], ] if get_option('destructive').enabled()