From patchwork Sat Jul 6 06:24:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alison Schofield X-Patchwork-Id: 13725676 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.18]) (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 42FEF18EA8 for ; Sat, 6 Jul 2024 06:25:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720247103; cv=none; b=Ka3DgSG9rimhbP8pT/jzNUD+uxLVP0Ee9EVxfhBIqywQr+EmgOpGpDG25UGmNWd48La+qzivL9QcU3iYAxHZyMUVcEFN+PzE6a47168lWm/q2okTOGHN5KLQK1/EAUWSvoYLsKG3VpW6Ek6efYyefNJQkBJtzlg7AIjfmKp+Fuc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720247103; c=relaxed/simple; bh=rpaGUWaLvO4l8WKxDOXBPIRDuftOU8PVos6GfauBuQA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=KRCPI624Q+HyZr/IaqiZoOdpfovQUEnA13VlK9PjSHuAhs2HBfg/AjGU+kiojkBuY6FQFSqVysVJNkUkxVjFV665sRN4McRfZ/VzbA5cjwvSpiYAB0dueC+UsLvdU3+7sptE66bx4F11ylYKDJv6hHhnaXVsqCEFILbo6orSv/Q= 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=Pb0EJRfF; arc=none smtp.client-ip=192.198.163.18 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="Pb0EJRfF" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1720247101; x=1751783101; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=rpaGUWaLvO4l8WKxDOXBPIRDuftOU8PVos6GfauBuQA=; b=Pb0EJRfFUQBY6jxFoWX1kC5ANITg8aB7rySAj2lRUDxG8r6/dsixFjk8 ur/3zlatX8ISD5uon6t0z5b4YJsfBqlCcImBGSWTC2bHq6YDNnlSHtBWq 8D2Es/ZnTKz+E2/J44gNzva1Y8cIioiYMzmnTwZKmMUgFdib2UOowfUVg KYVWK9ZpC5W6FDk54NzCn/WiQdG6bqk4j8DeUPkSajx/zGlVnK2YPMU+g HUYR2ZlaeYFIAA234wxwveYFZ40gqQg6Oob9+bH2SH3KXPMtwISoQP21z UXfLfJvHOSxD6Q1jZQbVZjUf7VG6T6+jsW/sHxW2Q5/hIZerhKjDIso81 w==; X-CSE-ConnectionGUID: 7X+G59fQTS2NwNfLZbMCCw== X-CSE-MsgGUID: URQbl9jXRJavX4Xt57sZYQ== X-IronPort-AV: E=McAfee;i="6700,10204,11123"; a="17166928" X-IronPort-AV: E=Sophos;i="6.09,187,1716274800"; d="scan'208";a="17166928" Received: from fmviesa001.fm.intel.com ([10.60.135.141]) by fmvoesa112.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Jul 2024 23:24:59 -0700 X-CSE-ConnectionGUID: 1R2VyW2WTKO91mVvG3xZVw== X-CSE-MsgGUID: TUxLEhG5RDyzB7C7A8leGQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.09,187,1716274800"; d="scan'208";a="78172487" Received: from aschofie-mobl2.amr.corp.intel.com (HELO localhost) ([10.209.72.84]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Jul 2024 23:24:59 -0700 From: alison.schofield@intel.com To: nvdimm@lists.linux.dev, linux-cxl@vger.kernel.org Cc: Alison Schofield Subject: [ndctl PATCH v13 1/8] util/trace: move trace helpers from ndctl/cxl/ to ndctl/util/ Date: Fri, 5 Jul 2024 23:24:47 -0700 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 A set of helpers used to parse kernel trace events were introduced in ndctl/cxl/ in support of the CXL monitor command. The work these helpers perform may be useful beyond CXL. Move them to the ndctl/util/ where other generic helpers reside. Replace cxl-ish naming with generic names and update the single user, cxl/monitor.c, to match. This move is in preparation for extending the helpers in support of cxl_poison trace events. Signed-off-by: Alison Schofield Reviewed-by: Dave Jiang --- cxl/meson.build | 2 +- cxl/monitor.c | 11 +++++------ {cxl => util}/event_trace.c | 21 ++++++++++----------- {cxl => util}/event_trace.h | 12 ++++++------ 4 files changed, 22 insertions(+), 24 deletions(-) rename {cxl => util}/event_trace.c (88%) rename {cxl => util}/event_trace.h (61%) diff --git a/cxl/meson.build b/cxl/meson.build index 61b4d8762b42..e4d1683ce8c6 100644 --- a/cxl/meson.build +++ b/cxl/meson.build @@ -27,7 +27,7 @@ deps = [ if get_option('libtracefs').enabled() cxl_src += [ - 'event_trace.c', + '../util/event_trace.c', 'monitor.c', ] deps += [ diff --git a/cxl/monitor.c b/cxl/monitor.c index a85452a4dc82..2066f984668d 100644 --- a/cxl/monitor.c +++ b/cxl/monitor.c @@ -28,8 +28,7 @@ #define ENABLE_DEBUG #endif #include - -#include "event_trace.h" +#include static const char *cxl_system = "cxl"; const char *default_log = "/var/log/cxl-monitor.log"; @@ -87,9 +86,9 @@ static int monitor_event(struct cxl_ctx *ctx) goto epoll_ctl_err; } - rc = cxl_event_tracing_enable(inst, cxl_system, NULL); + rc = trace_event_enable(inst, cxl_system, NULL); if (rc < 0) { - err(&monitor, "cxl_trace_event_enable() failed: %d\n", rc); + err(&monitor, "trace_event_enable() failed: %d\n", rc); goto event_en_err; } @@ -112,7 +111,7 @@ static int monitor_event(struct cxl_ctx *ctx) } list_head_init(&ectx.jlist_head); - rc = cxl_parse_events(inst, &ectx); + rc = trace_event_parse(inst, &ectx); if (rc < 0) goto parse_err; @@ -129,7 +128,7 @@ static int monitor_event(struct cxl_ctx *ctx) } parse_err: - if (cxl_event_tracing_disable(inst) < 0) + if (trace_event_disable(inst) < 0) err(&monitor, "failed to disable tracing\n"); event_en_err: epoll_ctl_err: diff --git a/cxl/event_trace.c b/util/event_trace.c similarity index 88% rename from cxl/event_trace.c rename to util/event_trace.c index 1b5aa09de8b2..16013412bc06 100644 --- a/cxl/event_trace.c +++ b/util/event_trace.c @@ -59,8 +59,8 @@ static struct json_object *num_to_json(void *num, int elem_size, unsigned long f return json_object_new_int64(val); } -static int cxl_event_to_json(struct tep_event *event, struct tep_record *record, - struct list_head *jlist_head) +static int event_to_json(struct tep_event *event, struct tep_record *record, + struct list_head *jlist_head) { struct json_object *jevent, *jobj, *jarray; struct tep_format_field **fields; @@ -200,8 +200,8 @@ err_jnode: return rc; } -static int cxl_event_parse(struct tep_event *event, struct tep_record *record, - int cpu, void *ctx) +static int event_parse(struct tep_event *event, struct tep_record *record, + int cpu, void *ctx) { struct event_ctx *event_ctx = (struct event_ctx *)ctx; @@ -218,10 +218,10 @@ static int cxl_event_parse(struct tep_event *event, struct tep_record *record, return event_ctx->parse_event(event, record, &event_ctx->jlist_head); - return cxl_event_to_json(event, record, &event_ctx->jlist_head); + return event_to_json(event, record, &event_ctx->jlist_head); } -int cxl_parse_events(struct tracefs_instance *inst, struct event_ctx *ectx) +int trace_event_parse(struct tracefs_instance *inst, struct event_ctx *ectx) { struct tep_handle *tep; int rc; @@ -230,14 +230,13 @@ int cxl_parse_events(struct tracefs_instance *inst, struct event_ctx *ectx) if (!tep) return -ENOMEM; - rc = tracefs_iterate_raw_events(tep, inst, NULL, 0, cxl_event_parse, - ectx); + rc = tracefs_iterate_raw_events(tep, inst, NULL, 0, event_parse, ectx); tep_free(tep); return rc; } -int cxl_event_tracing_enable(struct tracefs_instance *inst, const char *system, - const char *event) +int trace_event_enable(struct tracefs_instance *inst, const char *system, + const char *event) { int rc; @@ -252,7 +251,7 @@ int cxl_event_tracing_enable(struct tracefs_instance *inst, const char *system, return 0; } -int cxl_event_tracing_disable(struct tracefs_instance *inst) +int trace_event_disable(struct tracefs_instance *inst) { return tracefs_trace_off(inst); } diff --git a/cxl/event_trace.h b/util/event_trace.h similarity index 61% rename from cxl/event_trace.h rename to util/event_trace.h index ec6267202c8b..37c39aded871 100644 --- a/cxl/event_trace.h +++ b/util/event_trace.h @@ -1,7 +1,7 @@ /* SPDX-License-Identifier: GPL-2.0 */ /* Copyright (C) 2022 Intel Corporation. All rights reserved. */ -#ifndef __CXL_EVENT_TRACE_H__ -#define __CXL_EVENT_TRACE_H__ +#ifndef __UTIL_EVENT_TRACE_H__ +#define __UTIL_EVENT_TRACE_H__ #include #include @@ -19,9 +19,9 @@ struct event_ctx { struct list_head *jlist_head); /* optional */ }; -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); +int trace_event_parse(struct tracefs_instance *inst, struct event_ctx *ectx); +int trace_event_enable(struct tracefs_instance *inst, const char *system, + const char *event); +int trace_event_disable(struct tracefs_instance *inst); #endif From patchwork Sat Jul 6 06:24:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alison Schofield X-Patchwork-Id: 13725677 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.18]) (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 0AB011BC43 for ; Sat, 6 Jul 2024 06:25:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720247103; cv=none; b=qyeyqha5Jgm255+e4zNaXPYw7hb8SgJA3dJeAPlXWmaGLQ0gGgjsJUGFMSc2T9g07XyQ7mfWFrb9rWDefTDvWBrHxvqZEanq/r7xq9cxGnrhgf0DEd3esgqHRY0ziLTrfyUJjTzw71ehbtdSs0GaYPjWVTObIKDlJAar3lqgrCs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720247103; c=relaxed/simple; bh=roIYcf7YeNI5tK4KPiAUUtFVUrvSOClHX7/lSK37xJk=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=lMVCov2WJtEzfwhFYXGZZc/SQ62oE6LAjCAI8VEFGbZcWRGGzu/sgPu5NRjNCVk627OmyYxBcvPQ6JWPel4uaHIC4iUTObL3F4m4xEtE1rig0YNvdDi5oQnclXRiQlIPjkeWOLg0kDofpnKUk9uPZGjKGUvnpgww0bzm7AM2oNA= 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=mJEGCWIt; arc=none smtp.client-ip=192.198.163.18 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="mJEGCWIt" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1720247102; x=1751783102; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=roIYcf7YeNI5tK4KPiAUUtFVUrvSOClHX7/lSK37xJk=; b=mJEGCWItRzSLQIuRb/mFuOT6jE68lxnzYXuMrunEwYt5zLQQDjECGl5M EgwpHJ/kgHEOq5QHt55gV3/PHZmNJD1uB6JJRr3s1+kXropH9MK7yVm/r KCGQgC0cUNaVVVgae8JWE5axabAc/shsbjBz4Xk71DiHHuiH4qaHD49hN bf55B+xJQyf1ZP83XGRbFYC5rbl7crP2CTcpf1yg52Az8byM0fVUn5/M+ Ku90bBbgSzmNsNnEPpIqIA7ym+HXynSsy0tQkGoEAca7WT7IsRJ6lpTF9 KPEA3P6+sbJsHD8eqT/Fz8EBVITKSbKBPdNAG2d9kdeRxIbsNAEWg+sKL g==; X-CSE-ConnectionGUID: OE6HQZkeQJ+uTvGGL06tXA== X-CSE-MsgGUID: b0AmoVrFTGq1tg7LGjYbyA== X-IronPort-AV: E=McAfee;i="6700,10204,11123"; a="17166930" X-IronPort-AV: E=Sophos;i="6.09,187,1716274800"; d="scan'208";a="17166930" Received: from fmviesa001.fm.intel.com ([10.60.135.141]) by fmvoesa112.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Jul 2024 23:25:00 -0700 X-CSE-ConnectionGUID: ejVAxJL7SA+XVqDpLTXl1g== X-CSE-MsgGUID: UzfHbPpSSAKbdMVYva4KTg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.09,187,1716274800"; d="scan'208";a="78172492" Received: from aschofie-mobl2.amr.corp.intel.com (HELO localhost) ([10.209.72.84]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Jul 2024 23:25:00 -0700 From: alison.schofield@intel.com To: nvdimm@lists.linux.dev, linux-cxl@vger.kernel.org Cc: Alison Schofield , Jonathan Cameron , Dave Jiang Subject: [ndctl PATCH v13 2/8] util/trace: add an optional pid check to event parsing Date: Fri, 5 Jul 2024 23:24:48 -0700 Message-Id: <78e904ed934820f217f96d19603acf64e322184a.1720241079.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 When parsing 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 CXL 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 --- util/event_trace.c | 5 +++++ util/event_trace.h | 1 + 2 files changed, 6 insertions(+) diff --git a/util/event_trace.c b/util/event_trace.c index 16013412bc06..57318e2adace 100644 --- a/util/event_trace.c +++ b/util/event_trace.c @@ -214,6 +214,11 @@ static int 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/util/event_trace.h b/util/event_trace.h index 37c39aded871..6586e1dc254d 100644 --- a/util/event_trace.h +++ b/util/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 Sat Jul 6 06:24:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alison Schofield X-Patchwork-Id: 13725678 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.18]) (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 78968BE71 for ; Sat, 6 Jul 2024 06:25:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720247104; cv=none; b=MgcFCUPle6dhi1UQGBfUsEhMoc0BeoQcXq+9b5USvgJKkJgysQpcl8jB8c2mRtwYzdYBvTWxZmkgsm7l23/3Rtg7lGbP/hWIbgp+lOBtnBwi/jkYQ88YqT8gDNqhoMzwjVXNyn/P9RmYHxyS/yBlIEp7mKDwhD0pgyG+9WurRw8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720247104; c=relaxed/simple; bh=XISgranDwa4ij9bgE4Mun2LrZs7N9ulXb55CaoAbkp0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=skiFpUK4gsaTR5rGyJLMumsLH9IE+j94gFso4jrFZAqly91F20sxSuIQI7CVmyR39vh1buQd5f261hwpKeAUwWWFO2Q4vEbSOUnqrs5lsOuE9CnAwNKFHX3usYeIXhsHLfUR5Oh4lxc5vwHndXW3i6zA/X7tcwOwZU0yW+Va0WI= 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=hN8zjDp0; arc=none smtp.client-ip=192.198.163.18 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="hN8zjDp0" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1720247102; x=1751783102; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=XISgranDwa4ij9bgE4Mun2LrZs7N9ulXb55CaoAbkp0=; b=hN8zjDp0OHUZybW2vfBl+WJeM02bR/bNUcMnL4BNwtbznabX3k5EoMFc gDJlHrOb48SuYF7i2XxP4WTiX9J5Sttj+vLY5FJD5v8IE5c6fuedShplS rqCXJTnVTLoRom9TXI0RU34HCIZ6wisDmm1OrLL0B692Ud0gkKl4xgsDy 83JM7c/1wiKg54QsCH0RLVQsgUwo4pKa63iy85Agdv4fHEse58uoWLCN2 TYOI9SmEm2eW57NZdWbETqnUcuEnHvVM+06ViStDwshqXMhtFf33sq16/ noqtKu80EQJhblj+TLm3q/bsbNK8LuB/5y/RRo0RI43usT1b6Yp8pc/h8 g==; X-CSE-ConnectionGUID: qvPeC5hjRNOu2g1nzV275w== X-CSE-MsgGUID: hK+pJ5JUSNax/+PuQgIK6Q== X-IronPort-AV: E=McAfee;i="6700,10204,11123"; a="17166934" X-IronPort-AV: E=Sophos;i="6.09,187,1716274800"; d="scan'208";a="17166934" Received: from fmviesa001.fm.intel.com ([10.60.135.141]) by fmvoesa112.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Jul 2024 23:25:01 -0700 X-CSE-ConnectionGUID: LVFKvypHSx+cbynVDLkLPA== X-CSE-MsgGUID: qWjtLJoXS1W6PUua51yYhg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.09,187,1716274800"; d="scan'208";a="78172503" Received: from aschofie-mobl2.amr.corp.intel.com (HELO localhost) ([10.209.72.84]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Jul 2024 23:25:01 -0700 From: alison.schofield@intel.com To: nvdimm@lists.linux.dev, linux-cxl@vger.kernel.org Cc: Alison Schofield Subject: [ndctl PATCH v13 3/8] util/trace: pass an event_ctx to its own parse_event method Date: Fri, 5 Jul 2024 23:24:49 -0700 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 Tidy-up the calling convention used in trace event parsing by passing the entire event_ctx to its parse_event method. This makes it explicit that a parse_event operates on an event_ctx object and it allows the parse_event function to access any members of the event_ctx structure. This is in preparation for adding a private parser requiring more context for cxl_poison events. Signed-off-by: Alison Schofield Reviewed-by: Dave Jiang --- util/event_trace.c | 9 ++++----- util/event_trace.h | 2 +- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/util/event_trace.c b/util/event_trace.c index 57318e2adace..1f5c180a030b 100644 --- a/util/event_trace.c +++ b/util/event_trace.c @@ -60,7 +60,7 @@ static struct json_object *num_to_json(void *num, int elem_size, unsigned long f } static int 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 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 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 event_to_json(event, record, &event_ctx->jlist_head); + return event_to_json(event, record, event_ctx); } int trace_event_parse(struct tracefs_instance *inst, struct event_ctx *ectx) diff --git a/util/event_trace.h b/util/event_trace.h index 6586e1dc254d..9c53eba7533f 100644 --- a/util/event_trace.h +++ b/util/event_trace.h @@ -17,7 +17,7 @@ struct event_ctx { 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 */ + struct event_ctx *ctx); }; int trace_event_parse(struct tracefs_instance *inst, struct event_ctx *ectx); From patchwork Sat Jul 6 06:24:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alison Schofield X-Patchwork-Id: 13725679 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.18]) (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 79ABF1C68C for ; Sat, 6 Jul 2024 06:25:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720247105; cv=none; b=N+G+ooJYSOm07UQbyYgTL1L8Q/sDRf8S+9ZZUWcOEM0a3kcdo1ayL3xc0oL7Sn5XthqmMKfmvZ45f8GY/0VKv0ckV2Soututfn6oWzbFGC/YWV1XHL/CMoY5piax0n/RZe76/+flrxMZ7p70s9TPoI/llfaprWMgdAZzrJQEWd8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720247105; c=relaxed/simple; bh=hvKg/t3CyFdt16dcyKFhlzMVaWxFkrYEOsQBvf3o8zc=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=GCPX+H87nWT0MEmpBBbkIrmseHzJFVL/Pwg60cIISoMPlRZrYbp0wbi2MUayFWJeWI0jXyZRN/xsesBSzKXr1UPz+E8ozTiuyEOSl3N9UN6jZ/CoO9a4GbgLmRECLzzLzA6rpM5GTZtA6PdXbhyJ00mQ3vp4GLNICe13iGgSfAk= 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=c4OnQmWw; arc=none smtp.client-ip=192.198.163.18 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="c4OnQmWw" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1720247103; x=1751783103; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=hvKg/t3CyFdt16dcyKFhlzMVaWxFkrYEOsQBvf3o8zc=; b=c4OnQmWwRUF47TySgYivOfLz2DyocQaT4nC5IMa77zCHEKu/7iY+G+xR OXxkH8IB6iNgi8bvdMO9/y/XUxHI9tDXQWf9YHK8diH601W5bIeAHFv9C 9h6BqZSPFiun9a4Psel5dJ7M+aiZnqpt9Rew8AC6qUorjARmq9GIvZbN6 2g1XF+pL1JNi2F4FJkN5OO5R4YEFos2YWlP6mIXA+WXjZ2zxDhQ2UuTP1 InUHbDzStManKAkfrbgXDfllkTMgHoRpQ4W142b2zNB24Adm1rpo5cDpp NDUr34ct9j+HOVl21anqZD0Lgj0QbtIPVxPAbLF5SqYSpXc0PTOe2usVL w==; X-CSE-ConnectionGUID: AB6GQSyHQAiYqjM8oDzb5A== X-CSE-MsgGUID: 8XQAgQZ2Sv6ndQnvQ0MsdQ== X-IronPort-AV: E=McAfee;i="6700,10204,11123"; a="17166938" X-IronPort-AV: E=Sophos;i="6.09,187,1716274800"; d="scan'208";a="17166938" Received: from fmviesa001.fm.intel.com ([10.60.135.141]) by fmvoesa112.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Jul 2024 23:25:02 -0700 X-CSE-ConnectionGUID: WzvvE/ijQqudln6JSfnsZA== X-CSE-MsgGUID: FPz/UGr/Rsa4ES7I/41QmQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.09,187,1716274800"; d="scan'208";a="78172519" Received: from aschofie-mobl2.amr.corp.intel.com (HELO localhost) ([10.209.72.84]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Jul 2024 23:25:02 -0700 From: alison.schofield@intel.com To: nvdimm@lists.linux.dev, linux-cxl@vger.kernel.org Cc: Alison Schofield , Dave Jiang , Fan Ni Subject: [ndctl PATCH v13 4/8] util/trace: add helpers to retrieve tep fields by type Date: Fri, 5 Jul 2024 23:24:50 -0700 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 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 --- util/event_trace.c | 37 +++++++++++++++++++++++++++++++++++++ util/event_trace.h | 8 +++++++- 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/util/event_trace.c b/util/event_trace.c index 1f5c180a030b..bde3a76adfbf 100644 --- a/util/event_trace.c +++ b/util/event_trace.c @@ -15,6 +15,43 @@ #define _GNU_SOURCE #include +u64 trace_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 trace_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 trace_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/util/event_trace.h b/util/event_trace.h index 9c53eba7533f..4d498577a00f 100644 --- a/util/event_trace.h +++ b/util/event_trace.h @@ -5,6 +5,7 @@ #include #include +#include struct jlist_node { struct json_object *jobj; @@ -24,5 +25,10 @@ int trace_event_parse(struct tracefs_instance *inst, struct event_ctx *ectx); int trace_event_enable(struct tracefs_instance *inst, const char *system, const char *event); int trace_event_disable(struct tracefs_instance *inst); - +u8 trace_get_field_u8(struct tep_event *event, struct tep_record *record, + const char *name); +u32 trace_get_field_u32(struct tep_event *event, struct tep_record *record, + const char *name); +u64 trace_get_field_u64(struct tep_event *event, struct tep_record *record, + const char *name); #endif From patchwork Sat Jul 6 06:24:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alison Schofield X-Patchwork-Id: 13725680 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.18]) (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 C848E1C693 for ; Sat, 6 Jul 2024 06:25:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720247105; cv=none; b=gdHaCYTUDWewdjEQ6mLbt0PyE/D2Xg664UTUhPYRHT7KStoTQfmWhmAxdahJhi4sVkH5d2KY6QoUlVndWvGrso7ba4zYmbEJ0p16gS7PxbO1U5nXz4DDEolnY2+T+QEHFniZRDThaoj2z2GyrSl5oAxkJoKvc0HdXz9m0e+YNwE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720247105; c=relaxed/simple; bh=EZaQR/vMZ15Damf1T/EUQAfXuo5XKQ90Ahtx/U2XHeM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=sfEPiNAA4Kwz2MlDURFP1mUuQWfrsbpwVi4kh4UI9gpQt+7uE+SwXljDYz0ho97wb2cCtgad7OFpWRGy/Iw1niThpZrTLx5Ise/UI/HpvkbwtaABhOMqRn/VWyDzDkfVi2RiYJD+syqmEKSpZxjxEWuQLhszRoDyQcy7Kn+J49M= 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=OVwQJ8v9; arc=none smtp.client-ip=192.198.163.18 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="OVwQJ8v9" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1720247104; x=1751783104; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=EZaQR/vMZ15Damf1T/EUQAfXuo5XKQ90Ahtx/U2XHeM=; b=OVwQJ8v98UbVxjPPJixHUGGPwYOydSx8BP5bpv+BXt4EytWxXGkkhq0V Z+jJUjCG60Y5HsysS9n7QQYu7g1FnUL3FkPaMzpdkARnG2Sw5c5eGzc4Q BRCr4b5jyCNBvkafXzP0hVfGNLofOfUohH1HXfYx0B6B2SaCESM50xDjN X7UrCI/YxtbbvNWuypDwfAVBoDgDjE3uqDgKfWNU+BeTNSsytiRnqQQ3I FcuKu3KXWBgaTLOjywQzxEV5UVo5WuWanxuFMqaBtr/YEsIUERDU5YKhY UYpjnyXL74wxvBVidAWd0PgPGgB6FpA0BLOcK83+tXgPlk7dsvdqtNIyZ g==; X-CSE-ConnectionGUID: 7mqqlIg3QLuKeiHH92NgsQ== X-CSE-MsgGUID: DGPvkBd7QLuSZZuYnEr7vw== X-IronPort-AV: E=McAfee;i="6700,10204,11123"; a="17166941" X-IronPort-AV: E=Sophos;i="6.09,187,1716274800"; d="scan'208";a="17166941" Received: from fmviesa001.fm.intel.com ([10.60.135.141]) by fmvoesa112.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Jul 2024 23:25:03 -0700 X-CSE-ConnectionGUID: P3j073hQTq27TCdeoq4uOA== X-CSE-MsgGUID: RSZMr83wSw6RR9DmF44aIQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.09,187,1716274800"; d="scan'208";a="78172525" Received: from aschofie-mobl2.amr.corp.intel.com (HELO localhost) ([10.209.72.84]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Jul 2024 23:25:03 -0700 From: alison.schofield@intel.com To: nvdimm@lists.linux.dev, linux-cxl@vger.kernel.org Cc: Alison Schofield , Dave Jiang Subject: [ndctl PATCH v13 5/8] libcxl: add interfaces for GET_POISON_LIST mailbox commands Date: Fri, 5 Jul 2024 23:24:51 -0700 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 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 | 53 ++++++++++++++++++++++++++++++++++++++++++++++ cxl/lib/libcxl.sym | 6 ++++++ cxl/libcxl.h | 2 ++ 3 files changed, 61 insertions(+) diff --git a/cxl/lib/libcxl.c b/cxl/lib/libcxl.c index 91eedd1c4688..63aa4ef3acdc 100644 --- a/cxl/lib/libcxl.c +++ b/cxl/lib/libcxl.c @@ -1762,6 +1762,59 @@ 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; + } + + if (access(path, F_OK) != 0) { + err(ctx, "%s: trigger_poison_list unsupported by device\n", + cxl_memdev_get_devname(memdev)); + return -ENXIO; + } + + rc = sysfs_write_attr(ctx, path, "1\n"); + if (rc < 0) { + err(ctx, "%s: Failed 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 304d7fa735d4..0c155a40ad47 100644 --- a/cxl/lib/libcxl.sym +++ b/cxl/lib/libcxl.sym @@ -282,3 +282,9 @@ global: cxl_region_qos_class_mismatch; cxl_port_decoders_committed; } LIBCXL_6; + +LIBECXL_8 { +global: + cxl_memdev_trigger_poison_list; + cxl_region_trigger_poison_list; +} LIBCXL_7; diff --git a/cxl/libcxl.h b/cxl/libcxl.h index fc6dd0085440..0a5fd0e13cc2 100644 --- a/cxl/libcxl.h +++ b/cxl/libcxl.h @@ -468,6 +468,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 Sat Jul 6 06:24:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alison Schofield X-Patchwork-Id: 13725681 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.18]) (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 8638E1C698 for ; Sat, 6 Jul 2024 06:25:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720247106; cv=none; b=QeQ5ljud7jgEhuuy/uuec0uATbL90kvo5XZ1jTh3YitmbfQ2cZqSvb3uMUa2EZDxeVQvAE5vLWp7Wau48SnyM+EmA6oIi3gXWWzflnORhqAkXVbgcg/BLwIIOLD21t3cxRM1py6/ucgchMwbPjCG3HUa1il5tkjUZ13EJ+cfayY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720247106; c=relaxed/simple; bh=9NkY04vIeo8REjJNp3DXCgty5Jgk79GRgxLcCDlD5ig=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=PNg9c6JqyHUIESapcnENv44caB59mSI84xh/vFOF1dJ+hPVWL+1etgSWFp/2WDEo7ojlSlTEtCWGlVLIcW7j5ga0HJs2pGDWHvMxlBL/bF1qsLMywFaetYa2zPNbyCpAtf6GpHSANTAeY0UExIktpDuPmLaLF6bj8nRcJt0i6po= 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=jgRxJHcB; arc=none smtp.client-ip=192.198.163.18 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="jgRxJHcB" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1720247104; x=1751783104; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=9NkY04vIeo8REjJNp3DXCgty5Jgk79GRgxLcCDlD5ig=; b=jgRxJHcBM4FGXobNOdT2iqMyF3l1sfEeG++QvmMHgQJzSqLbfQmLDoJb FfPskBNsPH0wqgnTyT9efjcCQC7lIqUOEG3JWuBbVbENGnt6iBvF233un XvJ4q8Ejvd/hvoldSdvAqajbiDjKE0yXOTsY6YbX74Cql1WfoJ2Bp3IjU Okd0NrOjoU5eDY+coJmh91ybNZN6dXo2CB7xPSZE7YbwycZOz8Yo8ku/w WDtofhjOvs81Sjeyob0TbWjLeOc++lW8x7c1ay8OiQmcswQaLVZqzt0xy UU4qMEetTEGSOKzkv03yYqMAeEo96IYb0hgue66m5xor90vCluD8UODL6 g==; X-CSE-ConnectionGUID: AsjG6e/5S6O1jNu0PsFMGA== X-CSE-MsgGUID: bqdkbt2JSoCiZnDvD+3eIw== X-IronPort-AV: E=McAfee;i="6700,10204,11123"; a="17166943" X-IronPort-AV: E=Sophos;i="6.09,187,1716274800"; d="scan'208";a="17166943" Received: from fmviesa001.fm.intel.com ([10.60.135.141]) by fmvoesa112.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Jul 2024 23:25:04 -0700 X-CSE-ConnectionGUID: eZPlzY2OR3qeshXoIX6GWw== X-CSE-MsgGUID: h21McgaWQZGAjzowJCck5A== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.09,187,1716274800"; d="scan'208";a="78172547" Received: from aschofie-mobl2.amr.corp.intel.com (HELO localhost) ([10.209.72.84]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Jul 2024 23:25:04 -0700 From: alison.schofield@intel.com To: nvdimm@lists.linux.dev, linux-cxl@vger.kernel.org Cc: Alison Schofield , Dave Jiang Subject: [ndctl PATCH v13 6/8] cxl/list: collect and parse media_error records Date: Fri, 5 Jul 2024 23:24:52 -0700 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 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 Reviewed-by: Xingtao Yao --- cxl/json.c | 195 +++++++++++++++++++++++++++++++++++++++++++++ util/event_trace.h | 8 ++ 2 files changed, 203 insertions(+) diff --git a/cxl/json.c b/cxl/json.c index 0c27abaea0bd..004aadda3396 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 "../util/event_trace.h" #define CXL_FW_VERSION_STR_LEN 16 #define CXL_FW_MAX_SLOTS 4 @@ -571,6 +575,185 @@ err_jobj: return NULL; } +/* CXL Spec 3.1 Table 8-140 Media Error Record */ +#define CXL_POISON_SOURCE_MAX 7 +static const char * const 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 cxl_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 = e_ctx->json_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 = trace_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 = trace_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 = trace_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 = trace_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 = trace_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 = trace_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 cxl_poison_ctx *p_ctx, + unsigned long flags) +{ + struct event_ctx ectx = { + .event_name = "cxl_poison", + .event_pid = getpid(), + .system = "cxl", + .poison_ctx = p_ctx, + .json_flags = flags, + .parse_event = poison_event_to_json, + }; + int rc; + + p_ctx->jpoison = json_object_new_array(); + if (!p_ctx->jpoison) + return NULL; + + rc = trace_event_parse(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 cxl_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 = trace_event_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 = trace_event_disable(inst); + if (rc < 0) { + fprintf(stderr, "Failed to disable trace: %d\n", rc); + goto err_free; + } + + p_ctx = (struct cxl_poison_ctx){ + .region = region, + .memdev = memdev, + }; + jpoison = util_cxl_poison_events_to_json(inst, &p_ctx, flags); + +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 +847,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 +1201,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) { diff --git a/util/event_trace.h b/util/event_trace.h index 4d498577a00f..a87407ff8296 100644 --- a/util/event_trace.h +++ b/util/event_trace.h @@ -12,11 +12,19 @@ struct jlist_node { struct list_node list; }; +struct cxl_poison_ctx { + struct json_object *jpoison; + struct cxl_region *region; + struct cxl_memdev *memdev; +}; + struct event_ctx { const char *system; struct list_head jlist_head; const char *event_name; /* optional */ int event_pid; /* optional */ + struct cxl_poison_ctx *poison_ctx; /* optional */ + unsigned long json_flags; int (*parse_event)(struct tep_event *event, struct tep_record *record, struct event_ctx *ctx); }; From patchwork Sat Jul 6 06:24:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alison Schofield X-Patchwork-Id: 13725682 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.18]) (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 64C201C6B7 for ; Sat, 6 Jul 2024 06:25:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720247107; cv=none; b=KNxMB5LrS2k4r92cEz1wfSiFSe9QdreM6jigL0DP7OgknfkcXLlfG9nf+jZk4z5wbU3uG4FjFgNRyriu3zYxTXBTv4YrazOGEgOjiMOkqVg5s/Q4zX54qd4Au7+Z7dFnNr2uIDCff3KDYlWif1WGmvLITUP6bCfgLl0jO2nG4p4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720247107; c=relaxed/simple; bh=hjPo4ROZPv9HYfnmt1Ek/EoJqcd1JCplv4L11Gc+/8o=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=orBOSDwacd4lgztMUcyvWhW6xGQkk3+rKkBIcfWlAiXiNkjkp6cAfVQRE9IYv4BMAaSl1Up2sgVPZkr3DrpXmfYtwyLnFSjSSOKibDtHuH711a6HTYr/VNpg5AOqGN0zy1ygMHKKJPDIyfTN83P8/tCjey01ehaKZEBTXTL0OoM= 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=cIgewi6z; arc=none smtp.client-ip=192.198.163.18 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="cIgewi6z" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1720247105; x=1751783105; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=hjPo4ROZPv9HYfnmt1Ek/EoJqcd1JCplv4L11Gc+/8o=; b=cIgewi6zoahyPsesqcbiWd6d52dAyJQwtWE0v7ottRU6tX1ni8e6Pku5 W/VRLyRthOtHV05UIG9y2lVf040RGGYZgZUxDhzdsryTu/3PNk6VFMIyq WpFxaxttLWj9IWOep8UIoYANULtqvOIzCxw5Q8iJZ1AXpP/VBNLo+i+Hb aYuartifTXaBI8ky2+TPxAJccrpiMuVou8qiGT0+fHRmxDSQl8SpE6sjh TjYNlgRMXTOaoLwi0GZ4rIqPl5oYnjLb1Sc8FHkAFcqP6NTOP+mttf1yw KsCzyWoHP1k6Wd8NQjCd9y8Q1KOJDoJk1j84fVca/FyGxhs6gzl5Jn9pZ Q==; X-CSE-ConnectionGUID: bjSVEGR4QBq408CrIM31IQ== X-CSE-MsgGUID: K4yrVC9YR6iq6bwBNk4iqQ== X-IronPort-AV: E=McAfee;i="6700,10204,11123"; a="17166946" X-IronPort-AV: E=Sophos;i="6.09,187,1716274800"; d="scan'208";a="17166946" Received: from fmviesa001.fm.intel.com ([10.60.135.141]) by fmvoesa112.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Jul 2024 23:25:05 -0700 X-CSE-ConnectionGUID: Q8kyhXqZSHepOrQ9gL2cZg== X-CSE-MsgGUID: e8kzR7tUSxONS4NFbanR4Q== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.09,187,1716274800"; d="scan'208";a="78172557" Received: from aschofie-mobl2.amr.corp.intel.com (HELO localhost) ([10.209.72.84]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Jul 2024 23:25:05 -0700 From: alison.schofield@intel.com To: nvdimm@lists.linux.dev, linux-cxl@vger.kernel.org Cc: Alison Schofield , Dave Jiang Subject: [ndctl PATCH v13 7/8] cxl/list: add --media-errors option to cxl list Date: Fri, 5 Jul 2024 23:24:53 -0700 Message-Id: <76eb7636d1aab2fecd60d18617828d004adb58d9.1720241079.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 Tested-by: Xingtao Yao --- Documentation/cxl/cxl-list.txt | 56 +++++++++++++++++++++++++++++++++- cxl/filter.h | 3 ++ cxl/list.c | 3 ++ 3 files changed, 61 insertions(+), 1 deletion(-) diff --git a/Documentation/cxl/cxl-list.txt b/Documentation/cxl/cxl-list.txt index 838de4086678..8f52ef0cf687 100644 --- a/Documentation/cxl/cxl-list.txt +++ b/Documentation/cxl/cxl-list.txt @@ -415,6 +415,60 @@ 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" + } + ] +} + +# 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" + } + ] +} +---- + -v:: --verbose:: Increase verbosity of the output. This can be specified @@ -431,7 +485,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 Sat Jul 6 06:24:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alison Schofield X-Patchwork-Id: 13725683 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.18]) (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 3C67E1CA96 for ; Sat, 6 Jul 2024 06:25:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720247110; cv=none; b=AqzwiARNIu99lQRDx4STGw/5lzonAl4VhzKeSas77BIhSZ1Bszfx5PsSrQhlJb+emJgvwxL8nOXgisL0LCGPohUAGJdNrZCQKYU3p+RvcLePDOYDB2+HllSMo796YxaOkGydSkzTgP0Bz2ZWFyiNH58ug5Gv6VdT93kvIsmCJI4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720247110; c=relaxed/simple; bh=RkvUXVi/Dt6O4GzRluGcJSTqPWOyEmy7NvPT0BP6324=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=KYWQNF+buYtTQFVFnOgtwatE259IPqZxXXJKVxntncIvzTt7CC6KLKk4Z1FxgDOnMphK9sVpl3/uEVJc8ToazZLQj20LgU1nKSSfYMOMZdCSaOjFEwb/K2YTAGAwg8/FYYMzdUIT/Mrb3EHJGfBRQZzoIPgqA24b3kF3D2HWow8= 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=TwGKTQC0; arc=none smtp.client-ip=192.198.163.18 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="TwGKTQC0" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1720247106; x=1751783106; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=RkvUXVi/Dt6O4GzRluGcJSTqPWOyEmy7NvPT0BP6324=; b=TwGKTQC0iuk6xPqsYLHp883zUwyCq/jn29yjU8oEqbASzrMSp0L1SHBE YAgC+zLgdIUUINfW9C+tS9ErjkY+DSbh0MOw4FBZ9OX31fEYuYmPEu+5X RkZxsxp7Ib0CMwauQsIegQLID8SWqtaTxNwQtPvFpo9z8WTysm1IsuyOY d3c9n5MOOL4+5J+fV0oq6tLwXWNRGQ63geQxUhdYs4z2I5n/HrkGzDL3J Szd3HnB0LQE3dZzuStOOBujDorbqfktdtD7pVlZZA8Qgb33R79AGTSaqQ fu0sHou4XAPyYU97JdXU0Z2OQD4jTisfreAXJFnckAU8+fk305mMvltoh A==; X-CSE-ConnectionGUID: LipIqNl6TACpygJ/HOGkbw== X-CSE-MsgGUID: gkPXMGJ+QPeVfuKHE9v1CQ== X-IronPort-AV: E=McAfee;i="6700,10204,11123"; a="17166949" X-IronPort-AV: E=Sophos;i="6.09,187,1716274800"; d="scan'208";a="17166949" Received: from fmviesa001.fm.intel.com ([10.60.135.141]) by fmvoesa112.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Jul 2024 23:25:06 -0700 X-CSE-ConnectionGUID: ksjkjPKdQsOvLn+RVuv2wg== X-CSE-MsgGUID: bv4BEl1vTXCxuzgG3wAyIg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.09,187,1716274800"; d="scan'208";a="78172561" Received: from aschofie-mobl2.amr.corp.intel.com (HELO localhost) ([10.209.72.84]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Jul 2024 23:25:05 -0700 From: alison.schofield@intel.com To: nvdimm@lists.linux.dev, linux-cxl@vger.kernel.org Cc: Alison Schofield , Dave Jiang Subject: [ndctl PATCH v13 8/8] cxl/test: add cxl-poison.sh unit test Date: Fri, 5 Jul 2024 23:24:54 -0700 Message-Id: <4212bf9d89e31a17f0092b84da473de2abf554a2.1720241079.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 Tested-by: Xingtao Yao --- 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..2caf092db460 --- /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 --media-errors' toggles 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()