From patchwork Thu Feb 8 01:01:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alison Schofield X-Patchwork-Id: 13549202 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.8]) (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 471A21E4B0 for ; Thu, 8 Feb 2024 01:02:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.8 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707354122; cv=none; b=FhIQs5yMxQ+/Qb1kvVPwLiWX+ubw0IOvSAyMkz9DUWBdoXfDwjNs7iT868KAZje4GH5RBmd5vI3hpKX93ewpvMpX7TZLgWSCEkZOUgh7vvGc+0gHJN0lgO28hQihB6Depvmz3ti0pTUXi2X1ww6mEoyxV7KJvFfD6JJJWiS/evI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707354122; c=relaxed/simple; bh=IaRSgCE//M4Me1zHdPxEMAf8QU8K37PGAgtiMACBBwU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=pHXyEWMqwCfcH9/JNwIXy7sB2LUPdgx/ZusuRvoMcqP9I5YI257MY/sFecw+YZmrHQcc7EEy2cTP/WP7yTNf68BuI3yXVMeKiWWA1Z2YROPefe6mul55TIVq/AnM+64POBesdpUoy7tSYKG1wqxIJ48tQfEP7uCm5jr3tLYZ7Pg= 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=c4XSJTQa; arc=none smtp.client-ip=192.198.163.8 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="c4XSJTQa" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1707354120; x=1738890120; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=IaRSgCE//M4Me1zHdPxEMAf8QU8K37PGAgtiMACBBwU=; b=c4XSJTQak94AobyMv9f6X90ipYNw0xVC+8ycUR9pBb2nz5rNo6B/80bP 9H9rMdTcJRl95eWfXxfvzrMwG3OzRrsV1FaB+b9sJQ0hrQQ5E+gl0+j5h 9qyLvDnRn0N+9Q1StpSoKXuVB203yhR/++zLYPIEiV5MtOvvjhw1+N82F JJld0I2lb8zPisvLmcmwFyMg+xO4ADXlKe3heWLXaXTeKjcPIW2gwK716 +y4Hl+WFdyJTZYxQE7JiESOpd85jvQcAdF4xYDhpRYP5rNLhGA8e5d6h1 4clnlRLVy7Xj1x6uyQOLzfJ8wTupsE9MoYlp2MX/iO5xJTZgxwr274hbd Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10977"; a="18629889" X-IronPort-AV: E=Sophos;i="6.05,252,1701158400"; d="scan'208";a="18629889" Received: from orviesa010.jf.intel.com ([10.64.159.150]) by fmvoesa102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Feb 2024 17:01:49 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.05,252,1701158400"; d="scan'208";a="1529248" Received: from aschofie-mobl2.amr.corp.intel.com (HELO localhost) ([10.209.105.224]) by orviesa010-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Feb 2024 17:01:49 -0800 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 v7 1/7] libcxl: add interfaces for GET_POISON_LIST mailbox commands Date: Wed, 7 Feb 2024 17:01:40 -0800 Message-Id: <076dcb2fe7e2fa0eb300c57c1b95753421599ad9.1707351560.git.alison.schofield@intel.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-cxl@vger.kernel.org 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 | 6 ++++++ cxl/libcxl.h | 2 ++ 3 files changed, 55 insertions(+) diff --git a/cxl/lib/libcxl.c b/cxl/lib/libcxl.c index af4ca44eae19..cc95c2d7c94a 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 Thu Feb 8 01:01:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alison Schofield X-Patchwork-Id: 13549203 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.8]) (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 061E014007 for ; Thu, 8 Feb 2024 01:02:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.8 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707354127; cv=none; b=T4Hi71l5lqcmcD6/uXQ4/hubFYsW3+RVmVSZIfvAlvF6xhNhgXr011/DZUp1P+mvXab2KKBNZjGMFUhEsQXUOYLVoGex839n6KjRUOwg3eJP92hhzdyplNNMiqIbtaGKsm4cXaPoZs/ztfIYTzBH3ReEpp6hHKcipEn29oSn1L0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707354127; c=relaxed/simple; bh=sg75Nzd0Nfpa+tECk4dpxR+hOqypAdcjo1sTuoZWf9Q=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=KEYLfB+gbABahjh29mrs2GuZVX/WDSBP21xuxdVwlw7dZl4EbxXbqcPpazTBmr3MoI+NnetriNKwb931gNCoxm7QTlJPu6BltbB28+jlPwGHDk4roe3rrxyEpyRgkKl3DnykawDg+bOKwEGpLKoz+/iKrC6Wu/quomq+GbGzS2U= 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=lQIFcOQk; arc=none smtp.client-ip=192.198.163.8 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="lQIFcOQk" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1707354126; x=1738890126; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=sg75Nzd0Nfpa+tECk4dpxR+hOqypAdcjo1sTuoZWf9Q=; b=lQIFcOQkSEP5Leg5max5H27bqdtLUfcIwu9ffhRpWTZi4Z0r1s3WuE7e 75BLzJOeIBXRBUiLVi9ucXqQOuTpqNhADUR1kBVyvp6jFqF9DolQlWfZQ JML2CnTfwyHx2uBo3o7ETA6kUCPCj0J702Kckv7KtPQ0T0NJRTSzdBbQQ 5HNs2fTehgFbcF0z7Vs9b8BI1H7zZfBcDRMMLA5ztkIPx6TijMJWGY9sh EH4lJXxiIG5qUI5bv03wAMMtNfS69EUMO39Ccvo2C4x/cSkiFyB3SXI5p 74NNml0y97CDt0kJ3y4x/j1izRxIlBggxg31HsTYm/cHJhgOWQTxlZQiF A==; X-IronPort-AV: E=McAfee;i="6600,9927,10977"; a="18629895" X-IronPort-AV: E=Sophos;i="6.05,252,1701158400"; d="scan'208";a="18629895" Received: from orviesa010.jf.intel.com ([10.64.159.150]) by fmvoesa102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Feb 2024 17:01:49 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.05,252,1701158400"; d="scan'208";a="1529258" Received: from aschofie-mobl2.amr.corp.intel.com (HELO localhost) ([10.209.105.224]) by orviesa010-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Feb 2024 17:01:50 -0800 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 v7 2/7] cxl: add an optional pid check to event parsing Date: Wed, 7 Feb 2024 17:01:41 -0800 Message-Id: X-Mailer: git-send-email 2.40.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-cxl@vger.kernel.org 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 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 Thu Feb 8 01:01:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alison Schofield X-Patchwork-Id: 13549204 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.8]) (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 061B0134AA for ; Thu, 8 Feb 2024 01:02:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.8 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707354127; cv=none; b=WahnLWtNuF802FJqZoODqIItyThfscK6IZP7J6x5m1GQ5LAxZnzGBTG8XFSKEk/6fe+K9dB/1O1LgV7BElLBVyowSn67tZ4zzVC13RsE9thm1JOqJDeP23Cu5zPoXEWwssZZXQMFmMLKe3gNPDVUvr2d+G1ebMEhDwIRt+IgV0M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707354127; c=relaxed/simple; bh=5l/LDaPWUJnWpUgs2BmMwHt9+H1G0u+Aq/EbL9KxNUQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=QyqO7LwoolNiIuOsaaSrXRYbk4eaM42FGnxJ03PtBXYTfCCveWd9PAdICX2VIIn1VQKsKKus6+kbhLuWJJb0VkKtpvEyf7vS2JxyLxvsahlvrqmN0qmf82DeVsnMgVDs/t+tF7V/dMYR8Iv0IqqRDxtexwJWRILp1P4vaibD9wo= 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=FWJPxlCj; arc=none smtp.client-ip=192.198.163.8 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="FWJPxlCj" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1707354126; x=1738890126; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=5l/LDaPWUJnWpUgs2BmMwHt9+H1G0u+Aq/EbL9KxNUQ=; b=FWJPxlCjdsHL817yPFZgZK4pDKAGzgJTvF89E6oToruFAIObucQqDaZA w0JzeZLcSnvcdBgg0hsVcVPNwLhqSnDtGkmdvuqgxp0P/fk2JE3Empv58 3NbTxom3nkMdL4dOcQQTYqo2i7bVrZkBEU9ZY7+faunNzKVl5ziE1DHNg oO4g5Uc0larwWHBhCBqrHD5jW39EqUfTbAe8y2NuDLsq/nl1f8kNH7uSL bHexKu5Oz3nq4oJlAwI3zHGmKnRMtvAQ9+C86i9cDVHIm9tgGokZbqWQb wzDHtO+nfLc+hJHEU+/jD84nr4c7GHHzD0bbyu4V11es4kst0ljD7+vJq g==; X-IronPort-AV: E=McAfee;i="6600,9927,10977"; a="18629905" X-IronPort-AV: E=Sophos;i="6.05,252,1701158400"; d="scan'208";a="18629905" Received: from orviesa010.jf.intel.com ([10.64.159.150]) by fmvoesa102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Feb 2024 17:01:50 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.05,252,1701158400"; d="scan'208";a="1529271" Received: from aschofie-mobl2.amr.corp.intel.com (HELO localhost) ([10.209.105.224]) by orviesa010-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Feb 2024 17:01:50 -0800 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 v7 3/7] cxl/event_trace: add a private context for private parsers Date: Wed, 7 Feb 2024 17:01:42 -0800 Message-Id: <3085229a8b979dfb6686baacfd606b7c96150862.1707351560.git.alison.schofield@intel.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-cxl@vger.kernel.org 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. Add a private_ctx field to the existing 'struct event_context'. Replace the jlist_head parameter, used in the default parser, with the private_ctx. This is in preparation for adding a private parser requiring additional context for cxl_poison events. Signed-off-by: Alison Schofield Reviewed-by: Dave Jiang --- cxl/event_trace.c | 2 +- cxl/event_trace.h | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/cxl/event_trace.c b/cxl/event_trace.c index 269060898118..fbf7a77235ff 100644 --- a/cxl/event_trace.c +++ b/cxl/event_trace.c @@ -215,7 +215,7 @@ 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); + event_ctx->private_ctx); return cxl_event_to_json(event, record, &event_ctx->jlist_head); } diff --git a/cxl/event_trace.h b/cxl/event_trace.h index 7f7773b2201f..ec61962abbc6 100644 --- a/cxl/event_trace.h +++ b/cxl/event_trace.h @@ -16,8 +16,9 @@ struct event_ctx { struct list_head jlist_head; const char *event_name; /* optional */ int event_pid; /* optional */ + void *private_ctx; /* required with parse_event() */ int (*parse_event)(struct tep_event *event, struct tep_record *record, - struct list_head *jlist_head); /* optional */ + void *private_ctx);/* optional */ }; int cxl_parse_events(struct tracefs_instance *inst, struct event_ctx *ectx); From patchwork Thu Feb 8 01:01:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alison Schofield X-Patchwork-Id: 13549206 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.8]) (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 D176414AB2 for ; Thu, 8 Feb 2024 01:02:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.8 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707354129; cv=none; b=WLw34OlapI0gTE0CA0SBmtFNjfri9KCX9iuVkmgiS0A1zj/ok1eYEooaHE4EwGsKOyV4PHMNHU0ZTC9HG2kU7xNv6HQ5Zbv/s7Lo93rVNE2uM4y0M/qY1B3S5CkHXH5vydqEb5hfPRoopfgkHlljkkR/v7uGEVqMBiff69w5ZAU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707354129; c=relaxed/simple; bh=03nNMcoFPn8wAKY2CXwt0qaGCgnWQ87C8p+I43b3mBA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=rMD30xPeF72Y4HARdMeuf4qfXMyozBPr9eLPWIo5bRMs8/CkaVTmuPNF7JOR89M5DyZoPvh1t+F9D7LXdRiMpyC0Ruh0shJemmtH/KItwXfay4HSS3QLhqOKaekB4Ma5WItXd8uI55/gqBs35gfYYhcuP99UIiGQMoW6xf9i4QI= 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=lMcZpYYc; arc=none smtp.client-ip=192.198.163.8 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="lMcZpYYc" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1707354128; x=1738890128; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=03nNMcoFPn8wAKY2CXwt0qaGCgnWQ87C8p+I43b3mBA=; b=lMcZpYYcada3gpEyhKS18+GvvgOuQbnsrdfnzHbc8bG+mXrfC6XWKO2X urgda27Cl1/C3UEC+BlUsVRSiMoCqhzjk0XyAw8ToZLXlZO/a6MpN0JJS TCWnqbJOP74E4IJ+NO6umUpRH+TdcSiKieXOseZyqtyG9g7rCynofwCsX hA0uWVi3G+AUZEF7PIBcl9vPaLDqSPgphwkjLOKRgqr5jB0fKlCn913K1 aDvhA00xGP2Aha2x9umS7pr2yhiQxl9xCTermRccmuOdexstpJSf8duBw ADeKYSCzYiF5VXRMhBl8m6X/l4Fa+vJpVhPKrG+/xmfmBA6ZPuSM6ym9r Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10977"; a="18629911" X-IronPort-AV: E=Sophos;i="6.05,252,1701158400"; d="scan'208";a="18629911" Received: from orviesa010.jf.intel.com ([10.64.159.150]) by fmvoesa102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Feb 2024 17:01:50 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.05,252,1701158400"; d="scan'208";a="1529281" Received: from aschofie-mobl2.amr.corp.intel.com (HELO localhost) ([10.209.105.224]) by orviesa010-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Feb 2024 17:01:51 -0800 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 v7 4/7] cxl/event_trace: add helpers get_field_[string|data]() Date: Wed, 7 Feb 2024 17:01:43 -0800 Message-Id: <56096cb08363c5743793211b77e52645efdcb1a9.1707351560.git.alison.schofield@intel.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-cxl@vger.kernel.org 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. Add signed and unsigned char* versions to support string and u64 data fields. This is in preparation for adding a private parser of cxl_poison events. Signed-off-by: Alison Schofield Reviewed-by: Dave Jiang --- cxl/event_trace.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ cxl/event_trace.h | 5 ++++- 2 files changed, 50 insertions(+), 1 deletion(-) diff --git a/cxl/event_trace.c b/cxl/event_trace.c index fbf7a77235ff..8d04d8d34194 100644 --- a/cxl/event_trace.c +++ b/cxl/event_trace.c @@ -15,6 +15,52 @@ #define _GNU_SOURCE #include +static struct tep_format_field *__find_field(struct tep_event *event, + const char *name) +{ + struct tep_format_field **fields; + + fields = tep_event_fields(event); + if (!fields) + return NULL; + + for (int i = 0; fields[i]; i++) { + struct tep_format_field *f = fields[i]; + + if (strcmp(f->name, name) != 0) + continue; + + return f; + } + return NULL; +} + +unsigned char *cxl_get_field_data(struct tep_event *event, + struct tep_record *record, const char *name) +{ + struct tep_format_field *f; + int len; + + f = __find_field(event, name); + if (!f) + return NULL; + + return tep_get_field_raw(NULL, event, f->name, record, &len, 0); +} + +char *cxl_get_field_string(struct tep_event *event, struct tep_record *record, + const char *name) +{ + struct tep_format_field *f; + int len; + + f = __find_field(event, name); + if (!f) + return NULL; + + return tep_get_field_raw(NULL, event, f->name, record, &len, 0); +} + 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 ec61962abbc6..6252f583097a 100644 --- a/cxl/event_trace.h +++ b/cxl/event_trace.h @@ -25,5 +25,8 @@ 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); - +char *cxl_get_field_string(struct tep_event *event, struct tep_record *record, + const char *name); +unsigned char *cxl_get_field_data(struct tep_event *event, + struct tep_record *record, const char *name); #endif From patchwork Thu Feb 8 01:01:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alison Schofield X-Patchwork-Id: 13549205 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.8]) (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 8070114267 for ; Thu, 8 Feb 2024 01:02:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.8 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707354129; cv=none; b=a0qlTXo4ZTM7CCexqXuBJN5wZa0Gvq1IVpPCW5MpY4mq2zkKCNLf+G+kPCPmbEOyvD66G6JkxEmARWj46L8Uh6kfSCd/iad11Fz6YLueBVos200UhFnOSizSE2C8WEJ6Rpkx0ovY/Pv6St/ivdrX+TNaaneFowYpj8XzkNrX7aY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707354129; c=relaxed/simple; bh=VdubHMm3GEeu4WHd1uFeduYB15mjoJTfOkC85fyY0Uk=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=uwNzXFhy0ePs6KUHRjnRvIc9A471dzTSz6B6kFlOnuPflUML+nwVzHf1JiPG/DLd99ZyFv0JP8LPQZtt+jd6X7EGmjjVGjTRuxMmdFyWrSpR1GrkfCx1DuiuK20Gdqo371a4FWQM8aVUqCxMYeuiQS4nx+Gqo7Hk6ga4L6dMA4E= 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=RNFK1Ca6; arc=none smtp.client-ip=192.198.163.8 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="RNFK1Ca6" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1707354126; x=1738890126; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=VdubHMm3GEeu4WHd1uFeduYB15mjoJTfOkC85fyY0Uk=; b=RNFK1Ca62aTQVuqQluKPWRTIrf7i/oz2l0ZfHYXvTDTYoiGUW+6BAlZj 78W0WUPsji0l/Q8mJNLEeB1ZggRe6/iEgJaTguk4M6vLr+YoJRhUYJYqq R5a2WUvwyNEWISivskMmnyp72w8wZXZu/OWkXfyV9vf2rQPoV2V0B/x9b u1Q+FYy3WdUoiBXx/cQJHAryBs7cuQ5D/tIydkKjh+jdLI0ahv8oDHfu3 sJXXJ5O77yllaFbmp8uHRQ0hKgZ8qVrtincMFLdbwPFFRfLu+ZpBqY3Hp rJwGtjEd7hwgFxG+Z4qIL3bJbbAvwLiITx2WT+lUhvCkesScDAHeDiTUI A==; X-IronPort-AV: E=McAfee;i="6600,9927,10977"; a="18629919" X-IronPort-AV: E=Sophos;i="6.05,252,1701158400"; d="scan'208";a="18629919" Received: from orviesa010.jf.intel.com ([10.64.159.150]) by fmvoesa102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Feb 2024 17:01:51 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.05,252,1701158400"; d="scan'208";a="1529290" Received: from aschofie-mobl2.amr.corp.intel.com (HELO localhost) ([10.209.105.224]) by orviesa010-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Feb 2024 17:01:51 -0800 From: alison.schofield@intel.com To: Vishal Verma Cc: Alison Schofield , nvdimm@lists.linux.dev, linux-cxl@vger.kernel.org Subject: [ndctl PATCH v7 5/7] cxl/list: collect and parse media_error records Date: Wed, 7 Feb 2024 17:01:44 -0800 Message-Id: <566a2acff6a3f32a1d6af9d81fb0da8808e5b4ff.1707351560.git.alison.schofield@intel.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-cxl@vger.kernel.org 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 --- cxl/json.c | 261 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 261 insertions(+) diff --git a/cxl/json.c b/cxl/json.c index 7678d02020b6..bc104dd877a9 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,251 @@ err_jobj: return NULL; } +/* CXL Spec 3.1 Table 8-140 Media Error Record */ +#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 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) + +struct poison_ctx { + struct json_object *jpoison; + struct cxl_region *region; + struct cxl_memdev *memdev; + unsigned long flags; +}; + +static const char * +find_decoder_name(struct poison_ctx *ctx, const char *name, u64 addr) +{ + struct cxl_memdev *memdev = ctx->memdev; + struct cxl_memdev_mapping *mapping; + struct cxl_endpoint *endpoint; + struct cxl_decoder *decoder; + struct cxl_port *port; + u64 start, end; + + if (memdev) + goto find_decoder; + + cxl_mapping_foreach(ctx->region, mapping) { + decoder = cxl_mapping_get_decoder(mapping); + if (!decoder) + continue; + + memdev = cxl_decoder_get_memdev(decoder); + if (strcmp(name, cxl_memdev_get_devname(memdev)) == 0) + break; + + memdev = NULL; + } + +find_decoder: + if (!memdev) + return NULL; + + endpoint = cxl_memdev_get_endpoint(memdev); + port = cxl_endpoint_get_port(endpoint); + + cxl_decoder_foreach(port, decoder) { + start = cxl_decoder_get_resource(decoder); + end = start + cxl_decoder_get_size(decoder) - 1; + if (start <= addr && addr <= end) + return cxl_decoder_get_devname(decoder); + } + + return NULL; +} + +int poison_event_to_json(struct tep_event *event, struct tep_record *record, + void *ctx) +{ + struct poison_ctx *p_ctx = (struct poison_ctx *)ctx; + struct json_object *jobj, *jp, *jpoison = p_ctx->jpoison; + unsigned long flags = p_ctx->flags; + bool overflow = false; + unsigned char *data; + const char *name; + int pflags; + char *str; + + jp = json_object_new_object(); + if (!jp) + return -ENOMEM; + + /* Skip records not in this region when listing by region */ + name = p_ctx->region ? cxl_region_get_devname(p_ctx->region) : NULL; + if (name) + str = cxl_get_field_string(event, record, "region"); + + if ((name) && (strcmp(name, str) != 0)) { + json_object_put(jp); + return 0; + } + + /* Include endpoint decoder name with hpa, when present */ + name = cxl_get_field_string(event, record, "memdev"); + data = cxl_get_field_data(event, record, "hpa"); + if (*(uint64_t *)data != ULLONG_MAX) + name = find_decoder_name(p_ctx, name, *(uint64_t *)data); + else + name = NULL; + + if (name) { + jobj = json_object_new_string(name); + if (jobj) + json_object_object_add(jp, "decoder", jobj); + + jobj = util_json_object_hex(*(uint64_t *)data, flags); + if (jobj) + json_object_object_add(jp, "hpa", jobj); + } + + data = cxl_get_field_data(event, record, "dpa"); + jobj = util_json_object_hex(*(uint64_t *)data, flags); + if (jobj) + json_object_object_add(jp, "dpa", jobj); + + data = cxl_get_field_data(event, record, "dpa_length"); + jobj = util_json_object_size(*(uint32_t *)data, flags); + if (jobj) + json_object_object_add(jp, "length", jobj); + + str = cxl_get_field_string(event, record, "source"); + switch (*(uint8_t *)str) { + case CXL_POISON_SOURCE_UNKNOWN: + jobj = json_object_new_string("Unknown"); + break; + case CXL_POISON_SOURCE_EXTERNAL: + jobj = json_object_new_string("External"); + break; + case CXL_POISON_SOURCE_INTERNAL: + jobj = json_object_new_string("Internal"); + break; + case CXL_POISON_SOURCE_INJECTED: + jobj = json_object_new_string("Injected"); + break; + case CXL_POISON_SOURCE_VENDOR: + jobj = json_object_new_string("Vendor"); + break; + default: + jobj = json_object_new_string("Reserved"); + } + if (jobj) + json_object_object_add(jp, "source", jobj); + + str = cxl_get_field_string(event, record, "flags"); + pflags = *(uint8_t *)str; + if (pflags) { + char flag_str[32] = { '\0' }; + + 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) { + data = cxl_get_field_data(event, record, "overflow_ts"); + jobj = util_json_object_hex(*(uint64_t *)data, 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", + .private_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); + json_object_put(p_ctx->jpoison); + return NULL; + } + + if (json_object_array_length(p_ctx->jpoison) == 0) { + json_object_put(p_ctx->jpoison); + return NULL; + } + + return p_ctx->jpoison; +} + +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) { @@ -649,6 +898,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; } @@ -987,6 +1242,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 Feb 8 01:01:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alison Schofield X-Patchwork-Id: 13549207 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.8]) (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 12003168BE for ; Thu, 8 Feb 2024 01:02:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.8 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707354130; cv=none; b=ugscEca88TADKyiNSWrGd1NqpPv/Wmjq7m0sBhEai98U1Fx+MPrhnliSQv2Zfip1f5ZSMNYJQxUjDpxN+PI/JoFGEqcro0U2BAp+hTK0HmzQhw+mQ026IiQTnpoKmCnFPtvLPMejcGVHyNVbEl8ploKtbaG+EVGLp6yS1Lof9cQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707354130; c=relaxed/simple; bh=sFSwfMOSaRKAAtONH9OZkJqK2kxBdAF3OaadvPZiR4o=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=s/lzGZ6yeZvTSqIV0e3/H7nU4pehUsSKMBBTmlqHpGH19YqGfs8IwF1qnec9AG9fCE7vBQPPVfXsMnKDrbYkBhhixU7kHXPol43HsEoTBRHrfXwnPjablvGswaaGtCZH3aDps0AM5Xzw/XfNhFtRK4eqGDGRPtbr/FNj8Nx8uk8= 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=Yhw0JRqT; arc=none smtp.client-ip=192.198.163.8 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="Yhw0JRqT" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1707354128; x=1738890128; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=sFSwfMOSaRKAAtONH9OZkJqK2kxBdAF3OaadvPZiR4o=; b=Yhw0JRqTk9fMYK3VWUFujQt+IlNp/T5tNIK1GHPs4RNWSP0qtLYgxXdT 9RwlMfLYzckk/VyCNt/zMyc2cQZWzjpqNe57BgOvW5MD2BNcdr1vacl80 5PXJ+91LoGvQFuIVMMXw9+/Rch7Tgc7PEuhkJ/mDsevs3H9RCMams2KtU c/Mo6Rxtmgn1th4pRRcoLcItdkF0jSmIHwLll2XMUqoYVKGr+W8uNNL35 uwzJZnCSqexmShNYBOOG5O0/53Tsz0JASMVsCko6pfbaZFbzYAhN4WKm3 fR1fpM9QRPcWy2XgkHal7bBViW6owzXkXJQjA0KRX1JVgwyYinj6cUXXx A==; X-IronPort-AV: E=McAfee;i="6600,9927,10977"; a="18629926" X-IronPort-AV: E=Sophos;i="6.05,252,1701158400"; d="scan'208";a="18629926" Received: from orviesa010.jf.intel.com ([10.64.159.150]) by fmvoesa102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Feb 2024 17:01:51 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.05,252,1701158400"; d="scan'208";a="1529297" Received: from aschofie-mobl2.amr.corp.intel.com (HELO localhost) ([10.209.105.224]) by orviesa010-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Feb 2024 17:01:52 -0800 From: alison.schofield@intel.com To: Vishal Verma Cc: Alison Schofield , nvdimm@lists.linux.dev, linux-cxl@vger.kernel.org Subject: [ndctl PATCH v7 6/7] cxl/list: add --media-errors option to cxl list Date: Wed, 7 Feb 2024 17:01:45 -0800 Message-Id: <6f03d2d26d17beb33d28c7471a4fbfc1ec8a8e21.1707351560.git.alison.schofield@intel.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-cxl@vger.kernel.org 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 | 79 +++++++++++++++++++++++++++++++++- cxl/filter.h | 3 ++ cxl/list.c | 3 ++ 3 files changed, 84 insertions(+), 1 deletion(-) diff --git a/Documentation/cxl/cxl-list.txt b/Documentation/cxl/cxl-list.txt index 838de4086678..5c20614ef579 100644 --- a/Documentation/cxl/cxl-list.txt +++ b/Documentation/cxl/cxl-list.txt @@ -415,6 +415,83 @@ 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. + + "decoder" and "hpa" are included when the media-error is in a mapped + address. + + "source" will be one of: External, Internal, Injected, Vendor Specific, + or Unknown, as defined in CXL Specification v3.1 Table 8-140. + +---- +# cxl list -m mem1 --media-errors +[ + { + "memdev":"mem1", + "pmem_size":1073741824, + "ram_size":1073741824, + "serial":1, + "numa_node":1, + "host":"cxl_mem.1", + "media_errors":[ + { + "dpa":0, + "length":64, + "source":"Internal" + }, + { + "decoder":"decoder10.0", + "hpa":1035355557888, + "dpa":1073741824, + "length":64, + "source":"External" + }, + { + "decoder":"decoder10.0", + "hpa":1035355566080, + "dpa":1073745920, + "length":64, + "source":"Injected" + } + ] + } +] + +# cxl list -r region5 --media-errors +[ + { + "region":"region5", + "resource":1035355553792, + "size":2147483648, + "type":"pmem", + "interleave_ways":2, + "interleave_granularity":4096, + "decode_state":"commit", + "media_errors":[ + { + "decoder":"decoder10.0", + "hpa":1035355557888, + "dpa":1073741824, + "length":64, + "source":"External" + }, + { + "decoder":"decoder8.1", + "hpa":1035355553792, + "dpa":1073741824, + "length":64, + "source":"Internal" + } + ] + } +] +---- + -v:: --verbose:: Increase verbosity of the output. This can be specified @@ -431,7 +508,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 Feb 8 01:01:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alison Schofield X-Patchwork-Id: 13549208 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.8]) (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 7092A1401B for ; Thu, 8 Feb 2024 01:02:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.8 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707354131; cv=none; b=b+rzy1CzaLTbBexuqSetRWzUzhJlhHZzjdrfA+EzJ2Cxj/azNR4VXjUmsV5SUb+Vvm2iDIhesjw8LQOzID6/7Ve2H8qn46iDbieh0EcWESgpgZHZXI9lnl4BMfeG62ZnvuctwlADx+eZGPORK/4qLcYdmb6tfPMyjzlc5F8xqJU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707354131; c=relaxed/simple; bh=M3V70XCNX5QG1HzOUk5i+Odv0ldGHNGFIMGClOlU/No=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=LgZsk0AHubirVZDDDAi8vY3EsxKyFh4Io49lgDvf5g4WKSGBQbqxgmhKe2Cclraa6t/yHkmnrFZagls+pw57h9DXmZOzxeJfhP3fD11ct2Yp3XOW60qR83BpZFFe+oIoyQTYizLPkSd4p5vwaTdOjoxVfgQdFsUGyiuKZbuq99E= 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=fw3plA7E; arc=none smtp.client-ip=192.198.163.8 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="fw3plA7E" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1707354129; x=1738890129; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=M3V70XCNX5QG1HzOUk5i+Odv0ldGHNGFIMGClOlU/No=; b=fw3plA7EPeJ2TtBXjCFc3sKrRbmPqkXpsNun42ZS0W+7Az3dK8G9nwmN 8uRgV6votL4w2m6O+uBeKanh4CtVOdb5A49ZZQeLOVpJghZoyRPm6XVkb 9NRTwtIgB4TaH+nfyaJr9Bsd3eXaInO62KGf6hKOOW1ObtBQoHPYgEJa0 pAEsH2qjTSRLeAtqiupfeMsUQF6/BVS+f04oA0ByK2LHYcJcLSDIzty95 waczQG0ZW2I89cXbf6j6Kkf6CpE6pQg5IAXVd4+58B2Uw9znFdzW5v1Nn M88IA3BXY5NLoab861JShf4ecfiXyAY2ddL0qJkuTTr5gDDtcvhzGT120 A==; X-IronPort-AV: E=McAfee;i="6600,9927,10977"; a="18629934" X-IronPort-AV: E=Sophos;i="6.05,252,1701158400"; d="scan'208";a="18629934" Received: from orviesa010.jf.intel.com ([10.64.159.150]) by fmvoesa102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Feb 2024 17:01:52 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.05,252,1701158400"; d="scan'208";a="1529305" Received: from aschofie-mobl2.amr.corp.intel.com (HELO localhost) ([10.209.105.224]) by orviesa010-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Feb 2024 17:01:52 -0800 From: alison.schofield@intel.com To: Vishal Verma Cc: Alison Schofield , nvdimm@lists.linux.dev, linux-cxl@vger.kernel.org Subject: [ndctl PATCH v7 7/7] cxl/test: add cxl-poison.sh unit test Date: Wed, 7 Feb 2024 17:01:46 -0800 Message-Id: <855025e88e0c261ae36dd6bd70443ebd9e7e5e6f.1707351560.git.alison.schofield@intel.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-cxl@vger.kernel.org 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..6fceb0f2c360 --- /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 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()