From patchwork Wed Mar 6 18:42:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alison Schofield X-Patchwork-Id: 13584539 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.12]) (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 179BB137C4A for ; Wed, 6 Mar 2024 18:42:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.12 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709750552; cv=none; b=bcncPZuiyC2cXCGLN43+2qtx0h5d7fRzIjt3R6yWaqgbCkoa6exFpy6s2LdpWRARa6O9ZtBdgORkD4XFSMa7cBOa56dvHypxxaoAXbz9w6wvM0XVCj+7qXHycLdfrTT1xm8/XRW/D2emk+N/bTHrdGKQqN3ZCexRhMdtbXJV9rE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709750552; c=relaxed/simple; bh=w2PzexwB2loTJZ+xDVTgYJmA2I7IIdSALPdEyuLuCjI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=iQiJBwNdtH6qFOmPxqhgEIEur/PVN6Hgya69gGjW2mKhxwU3YcG3TZSonH7rrI+1LThPlseusqKevhLkz1tGx5327AI7ygygoFkUWR4Gm9TQBAMgkpStHLNDbAdWbMEpSwtyEDYMuoyzHpTp9ONIt3aE1lmNVWeus30/jdkOExQ= 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=YqanpK9E; arc=none smtp.client-ip=198.175.65.12 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="YqanpK9E" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1709750551; x=1741286551; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=w2PzexwB2loTJZ+xDVTgYJmA2I7IIdSALPdEyuLuCjI=; b=YqanpK9EhyrT+ini45ItBNtUS6mrAFHB7CToarqbN8m/hH7mPWUazuX7 noG3KhHf8L+p30NKI0C16phJbRqpv+xcvNRUK48FrTYXq/KipMIv8gO5z JILHUdRQ7hq3zWqZAtXJLVakz8c2neZNzvqcplvYA0nR605ZObX4ZZ5z4 cr4Y24x9xuL5vJ01NBaBNH7Wz+zgb4qIbNZ3Uz9d89dtbTffPG/oK4xV6 IdKx8c4vKAriJHQFE+k0HYBAPnz3hhXnDDHg0yMV/smOPxG5N/SWLypli psT47Tx4YFmhSowx6QXb/UJXvJ+nTSaIJfgmMY0v6wkmL+gy71lztWPlv Q==; X-IronPort-AV: E=McAfee;i="6600,9927,11005"; a="15819821" X-IronPort-AV: E=Sophos;i="6.06,209,1705392000"; d="scan'208";a="15819821" Received: from orviesa009.jf.intel.com ([10.64.159.149]) by orvoesa104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Mar 2024 10:42:30 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.06,209,1705392000"; d="scan'208";a="9925962" Received: from aschofie-mobl2.amr.corp.intel.com (HELO localhost) ([10.251.9.155]) by orviesa009-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Mar 2024 10:42:30 -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 v10 1/7] libcxl: add interfaces for GET_POISON_LIST mailbox commands Date: Wed, 6 Mar 2024 10:42:20 -0800 Message-Id: X-Mailer: git-send-email 2.40.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: nvdimm@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Alison Schofield CXL devices maintain a list of locations that are poisoned or result in poison if the addresses are accessed by the host. Per the spec (CXL 3.1 8.2.9.9.4.1), the device returns the Poison List as a set of Media Error Records that include the source of the error, the starting device physical address and length. Trigger the retrieval of the poison list by writing to the memory device sysfs attribute: trigger_poison_list. The CXL driver only offers triggering per memdev, so the trigger by region interface offered here is a convenience API that triggers a poison list retrieval for each memdev contributing to a region. int cxl_memdev_trigger_poison_list(struct cxl_memdev *memdev); int cxl_region_trigger_poison_list(struct cxl_region *region); The resulting poison records are logged as kernel trace events named 'cxl_poison'. Signed-off-by: Alison Schofield Reviewed-by: Dave Jiang Reviewed-by: Dan Williams --- cxl/lib/libcxl.c | 47 ++++++++++++++++++++++++++++++++++++++++++++++ cxl/lib/libcxl.sym | 2 ++ cxl/libcxl.h | 2 ++ 3 files changed, 51 insertions(+) diff --git a/cxl/lib/libcxl.c b/cxl/lib/libcxl.c index ff27cdf7c44a..73db8f15c704 100644 --- a/cxl/lib/libcxl.c +++ b/cxl/lib/libcxl.c @@ -1761,6 +1761,53 @@ CXL_EXPORT int cxl_memdev_disable_invalidate(struct cxl_memdev *memdev) return 0; } +CXL_EXPORT int cxl_memdev_trigger_poison_list(struct cxl_memdev *memdev) +{ + struct cxl_ctx *ctx = cxl_memdev_get_ctx(memdev); + char *path = memdev->dev_buf; + int len = memdev->buf_len, rc; + + if (snprintf(path, len, "%s/trigger_poison_list", + memdev->dev_path) >= len) { + err(ctx, "%s: buffer too small\n", + cxl_memdev_get_devname(memdev)); + return -ENXIO; + } + rc = sysfs_write_attr(ctx, path, "1\n"); + if (rc < 0) { + fprintf(stderr, + "%s: Failed write sysfs attr trigger_poison_list\n", + cxl_memdev_get_devname(memdev)); + return rc; + } + return 0; +} + +CXL_EXPORT int cxl_region_trigger_poison_list(struct cxl_region *region) +{ + struct cxl_memdev_mapping *mapping; + int rc; + + cxl_mapping_foreach(region, mapping) { + struct cxl_decoder *decoder; + struct cxl_memdev *memdev; + + decoder = cxl_mapping_get_decoder(mapping); + if (!decoder) + continue; + + memdev = cxl_decoder_get_memdev(decoder); + if (!memdev) + continue; + + rc = cxl_memdev_trigger_poison_list(memdev); + if (rc) + return rc; + } + + return 0; +} + CXL_EXPORT int cxl_memdev_enable(struct cxl_memdev *memdev) { struct cxl_ctx *ctx = cxl_memdev_get_ctx(memdev); diff --git a/cxl/lib/libcxl.sym b/cxl/lib/libcxl.sym index de2cd84b2960..3f709c60db3d 100644 --- a/cxl/lib/libcxl.sym +++ b/cxl/lib/libcxl.sym @@ -280,4 +280,6 @@ global: cxl_memdev_get_pmem_qos_class; cxl_memdev_get_ram_qos_class; cxl_region_qos_class_mismatch; + cxl_memdev_trigger_poison_list; + cxl_region_trigger_poison_list; } LIBCXL_6; diff --git a/cxl/libcxl.h b/cxl/libcxl.h index a6af3fb04693..29165043ca3f 100644 --- a/cxl/libcxl.h +++ b/cxl/libcxl.h @@ -467,6 +467,8 @@ enum cxl_setpartition_mode { int cxl_cmd_partition_set_mode(struct cxl_cmd *cmd, enum cxl_setpartition_mode mode); +int cxl_memdev_trigger_poison_list(struct cxl_memdev *memdev); +int cxl_region_trigger_poison_list(struct cxl_region *region); int cxl_cmd_alert_config_set_life_used_prog_warn_threshold(struct cxl_cmd *cmd, int threshold); From patchwork Wed Mar 6 18:42:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alison Schofield X-Patchwork-Id: 13584541 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.12]) (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 9FB0C13E7C5 for ; Wed, 6 Mar 2024 18:42:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.12 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709750554; cv=none; b=SewwdMqc88w/c/ssY3t9uTSeJXkyaWqg+mMkcvHKtA4l3mrOQwjZfPXLPStRvXGuiCEDhftW/0Eazxf0n2v7VNQo5A1LgoPsY+8i/7tFWPqGF8za0257YtulmtrGplMJitZCgcDq3SGC7Z/mOMaN6nrsEKUv2HOBzM2wnrbgDfE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709750554; c=relaxed/simple; bh=hbtZxXnoVzB3QnmV5PLXG8Us1o2ekbGwln4vc2//uhw=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=qOVZUt93ShxFi21Foxp3j+1ler+NNxjaBph4pJq9fedgJDzSSciNG/CCrXYkkAQfSpzdROJgg+hBE6zVkeXxpsxyvHsq4YeBlu2z+rKwLVrF4zZIBoG4DN8G/zJGbccTotJWPRdCu0ZAEwKeTpelhH1pLJ9YIHgsrTug4k73Fzc= 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=DXqU/L1N; arc=none smtp.client-ip=198.175.65.12 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="DXqU/L1N" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1709750551; x=1741286551; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=hbtZxXnoVzB3QnmV5PLXG8Us1o2ekbGwln4vc2//uhw=; b=DXqU/L1NPQdkpIL24maNA9g/4v/CLnakKtumAsJ8Gw0UgSOYc/kLl2I4 caI/1XIVRXzn4kAxlkvFKKBPiNbbCfah13VhQFtmUURewmpMEfzqb2PrO 92PZSf+XB4euCTmRRUWmu1rsXo4bJ+1ShCO7hIWzOt7crjHKgcE3PwXg5 Vjx7/5uDYNS3sPvRGkYgacmba9MfQhYgfUvsZLrDqJ9c4dm6jQof+r1yk aYkFgV+LCTA0p0/OyjhHn8qMwAQlA3vikXwgusdHVOSDrrSdfqXfh2C6t AhXgxLvVdu1QPSRqK5Ni5mnk79mo8a0IfnOk493rd3d+Svcppvmi1xuD4 Q==; X-IronPort-AV: E=McAfee;i="6600,9927,11005"; a="15819823" X-IronPort-AV: E=Sophos;i="6.06,209,1705392000"; d="scan'208";a="15819823" Received: from orviesa009.jf.intel.com ([10.64.159.149]) by orvoesa104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Mar 2024 10:42:31 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.06,209,1705392000"; d="scan'208";a="9925966" Received: from aschofie-mobl2.amr.corp.intel.com (HELO localhost) ([10.251.9.155]) by orviesa009-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Mar 2024 10:42:31 -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 v10 2/7] cxl: add an optional pid check to event parsing Date: Wed, 6 Mar 2024 10:42:21 -0800 Message-Id: X-Mailer: git-send-email 2.40.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: nvdimm@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Alison Schofield 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 Reviewed-by: Dan Williams --- cxl/event_trace.c | 5 +++++ cxl/event_trace.h | 1 + 2 files changed, 6 insertions(+) diff --git a/cxl/event_trace.c b/cxl/event_trace.c index 1b5aa09de8b2..93a95f9729fd 100644 --- a/cxl/event_trace.c +++ b/cxl/event_trace.c @@ -214,6 +214,11 @@ static int cxl_event_parse(struct tep_event *event, struct tep_record *record, return 0; } + if (event_ctx->event_pid) { + if (event_ctx->event_pid != tep_data_pid(event->tep, record)) + return 0; + } + if (event_ctx->parse_event) return event_ctx->parse_event(event, record, &event_ctx->jlist_head); diff --git a/cxl/event_trace.h b/cxl/event_trace.h index ec6267202c8b..7f7773b2201f 100644 --- a/cxl/event_trace.h +++ b/cxl/event_trace.h @@ -15,6 +15,7 @@ struct event_ctx { const char *system; struct list_head jlist_head; const char *event_name; /* optional */ + int event_pid; /* optional */ int (*parse_event)(struct tep_event *event, struct tep_record *record, struct list_head *jlist_head); /* optional */ }; From patchwork Wed Mar 6 18:42:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alison Schofield X-Patchwork-Id: 13584540 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.12]) (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 9940E13E7CA for ; Wed, 6 Mar 2024 18:42:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.12 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709750554; cv=none; b=farnWeUaz1tWLe7lgdMYu3ZbM3b2BWwk/yN5JvIF4l96HKJbcsm9LVriazWsDDJB6AjERg8VneuU37efTGgp6KmniDkMvAawPCEdZQlPKX0fiYzPxd/H8EvOOFgfGFmU9WzyJHevcEMOE99Va92kHe8O9M8edy/k/faZbKFXQwM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709750554; c=relaxed/simple; bh=vAtrXMzOPQbVk0ENBhOuNC+XRIcLDIDYr/JHq12NW44=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=R9ByKvbV02oGz7FVe6IpKV1+sL6ZTbqoPKU9gZdr3clcSnEKVxZccxx8NJDDWDon42JQfMhexQ1F11/2XIgkvslkwwZqcBBZ/u0cHMhfjOCE3f1Be0mRDybJOUbtnwULlJ2dM5D9Az/rwbkawq3XK2UJ7Nn1xfszCmbh/7ooHi0= 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=J4Jyusff; arc=none smtp.client-ip=198.175.65.12 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="J4Jyusff" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1709750552; x=1741286552; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=vAtrXMzOPQbVk0ENBhOuNC+XRIcLDIDYr/JHq12NW44=; b=J4Jyusff/VW7ZKxyqo2vSHS2SiJMh/DoKAEeH3sBNLnuNvhRSwMgGctX avaqLppuXFgUELsu7L1UNWiXR5W8BBxXkdWmxrQcfB1WlbnZYOR2UYPyT DV+lXIT+bCcX75XYsN57gG5JQ9CdD0TLSqRs4ZGqjS4motAx8wQpALTCJ 7B4OxsGYoFmR5lQyHsQJz/oV2wuThmGKmXaqk8ear/+Xo4mzFy6JL/DeK lDXwBFbiTzmJO47gmGV0UDOOvTRqHfCUerfZbDDegvVAMmA0VJ0a3R5rd hFK9Urvv2J6JqBLd2b4rj8YNSmZyr3Kupji8DT8ykl0sYbfAfLq5v/eDM g==; X-IronPort-AV: E=McAfee;i="6600,9927,11005"; a="15819826" X-IronPort-AV: E=Sophos;i="6.06,209,1705392000"; d="scan'208";a="15819826" Received: from orviesa009.jf.intel.com ([10.64.159.149]) by orvoesa104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Mar 2024 10:42:31 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.06,209,1705392000"; d="scan'208";a="9925969" Received: from aschofie-mobl2.amr.corp.intel.com (HELO localhost) ([10.251.9.155]) by orviesa009-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Mar 2024 10:42:31 -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 v10 3/7] cxl/event_trace: add a private context for private parsers Date: Wed, 6 Mar 2024 10:42:22 -0800 Message-Id: <6e975df49a62cdb544791633fdd1a998a0b60164.1709748564.git.alison.schofield@intel.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: nvdimm@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Alison Schofield CXL event tracing provides helpers to iterate through a trace buffer and extract events of interest. It offers two parsing options: a default parser that adds every field of an event to a json object, and a private parsing option where the caller can parse each event as it wishes. Although the private parser can do some conditional parsing based on field values, it has no method to receive additional information needed to make parsing decisions in the callback. 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 93a95f9729fd..bdad0c19dbd4 100644 --- a/cxl/event_trace.c +++ b/cxl/event_trace.c @@ -221,7 +221,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 Wed Mar 6 18:42:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alison Schofield X-Patchwork-Id: 13584542 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.12]) (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 D91A713E7C0 for ; Wed, 6 Mar 2024 18:42:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.12 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709750554; cv=none; b=InL4HhsFOfu/nmf/QSQRI2N3qwjoPzaEGNxNgnmV5hfcVKaLiTsrA6LyPVQo6IsDJhRVPeTDJWqzyd313HKzUjpgv4VTUH+OPZ2eTj2/uEQrVvLsD4LflTbf8qEu5QqPIELVtfNxxwELmYUZKHVzWMNmyWTxtppseJrbYFegSKw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709750554; c=relaxed/simple; bh=p8rV7ixS6CdG+oryCs0HOp9CyxgH1ZyvlwmJtf0Zf24=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=LqgUlhfNUqw+MMbHK8npi+DnzxQh3Dw5dvw5Giaj+W4bM5hK0LjGer9TAoIQTOgC4fgXLBIrONycPwx7kPmcWLvSZJeEeFZ4I46mmtXNGJ2TPX2zXqRBLgJ53PSShQA4S8RQRpQXFO4vHTk6GWwGKRefyBJ+OgQTeZ3yzrfmn58= 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=e1y8CpV8; arc=none smtp.client-ip=198.175.65.12 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="e1y8CpV8" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1709750553; x=1741286553; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=p8rV7ixS6CdG+oryCs0HOp9CyxgH1ZyvlwmJtf0Zf24=; b=e1y8CpV8RVZjUShJ27lkpYrphQID0txrq1UsO/AQSaXooYOThnJz3PHc YEKms3i1RoKHdRTkGK/kWnohReHoXY1lAkOwE1pMRMB0/BnM/fVsx+TzB 396sVKIsaDV1EmvbFvMtgeeMv1CibownjdlrwZ+NCaowRH+rNiO2aW3jk K0Kzgu8YUsjTi+4t7tYjAj4Bw1kJEsN68d3nZbVD5JUeHpQ9TijE8H9gY Ocewx4LHXSc87r5ghJDeyZy6n1KTfAQqED8Vlez1CcVFGniSCEl/MlWbJ CrSTDKlfbqvqiKGkVmc/FdmaFozmhUDTou9jpLEOn9kvEuhnMPXU03JcQ A==; X-IronPort-AV: E=McAfee;i="6600,9927,11005"; a="15819828" X-IronPort-AV: E=Sophos;i="6.06,209,1705392000"; d="scan'208";a="15819828" Received: from orviesa009.jf.intel.com ([10.64.159.149]) by orvoesa104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Mar 2024 10:42:32 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.06,209,1705392000"; d="scan'208";a="9925973" Received: from aschofie-mobl2.amr.corp.intel.com (HELO localhost) ([10.251.9.155]) by orviesa009-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Mar 2024 10:42:32 -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 v10 4/7] cxl/event_trace: add helpers to retrieve tep fields by type Date: Wed, 6 Mar 2024 10:42:23 -0800 Message-Id: <3d264f1fe4c92a90eabf9cd3365a2dc69caacc4e.1709748564.git.alison.schofield@intel.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: nvdimm@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Alison Schofield Add helpers to extract the value of an event record field given the field name. This is useful when the user knows the name and format of the field and simply needs to get it. Since this is in preparation for adding a cxl_poison private parser for 'cxl list --media-errors' support, add those specific required types: u8, u32, u64, char* Signed-off-by: Alison Schofield Reviewed-by: Dave Jiang --- cxl/event_trace.c | 75 +++++++++++++++++++++++++++++++++++++++++++++++ cxl/event_trace.h | 10 ++++++- 2 files changed, 84 insertions(+), 1 deletion(-) diff --git a/cxl/event_trace.c b/cxl/event_trace.c index bdad0c19dbd4..6cc9444f3204 100644 --- a/cxl/event_trace.c +++ b/cxl/event_trace.c @@ -15,6 +15,81 @@ #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; +} + +u64 cxl_get_field_u64(struct tep_event *event, struct tep_record *record, + const char *name) +{ + struct tep_format_field *f; + unsigned char *val; + int len; + + f = __find_field(event, name); + if (!f) + return ULLONG_MAX; + + val = tep_get_field_raw(NULL, event, f->name, record, &len, 0); + if (!val) + return ULLONG_MAX; + + return *(u64 *)val; +} + +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); +} + +u32 cxl_get_field_u32(struct tep_event *event, struct tep_record *record, + const char *name) +{ + char *val; + + val = cxl_get_field_string(event, record, name); + if (!val) + return UINT_MAX; + + return *(u32 *)val; +} + +u8 cxl_get_field_u8(struct tep_event *event, struct tep_record *record, + const char *name) +{ + char *val; + + val = cxl_get_field_string(event, record, name); + if (!val) + return UCHAR_MAX; + + return *(u8 *)val; +} + static struct json_object *num_to_json(void *num, int elem_size, unsigned long flags) { bool sign = flags & TEP_FIELD_IS_SIGNED; diff --git a/cxl/event_trace.h b/cxl/event_trace.h index ec61962abbc6..bbdea3b896e0 100644 --- a/cxl/event_trace.h +++ b/cxl/event_trace.h @@ -5,6 +5,7 @@ #include #include +#include struct jlist_node { struct json_object *jobj; @@ -25,5 +26,12 @@ 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); +u8 cxl_get_field_u8(struct tep_event *event, struct tep_record *record, + const char *name); +u32 cxl_get_field_u32(struct tep_event *event, struct tep_record *record, + const char *name); +u64 cxl_get_field_u64(struct tep_event *event, struct tep_record *record, + const char *name); #endif From patchwork Wed Mar 6 18:42:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alison Schofield X-Patchwork-Id: 13584543 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.12]) (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 42AEB13E7DB for ; Wed, 6 Mar 2024 18:42:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.12 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709750556; cv=none; b=N2yuNuOlT272Qr1VfO6nTyeCTw1giCyzde0EPCoUb3/PRztl7iKht6CPTov8mmiVf6zz/zONAFNNDgrp7rmZLkNlQld0dO+R/N+1n+vPXjj83XRT0L5f1jV645jb3a5cEW3dKH7rhiLhZG4rg+yWWayjIwol+JGjhaVLcY5AnTY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709750556; c=relaxed/simple; bh=iWHnk1neQZIKAqWfpW+1RZrwfjWKjuOzgV4aWEXbwE8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=DEdmtE8P6+0flZQe+RmSS4CEOUnucBm0gCQoBA2CB6R+Kg/od9CoOPQM2dTMkztO/eX2OGJ1iMMYS4bbXKw4RlfTxJj/ZKQFiIHnZ5zu9lCKpcdoSrJR8jftTTdkInK9kzF4KOFYkml036PNd2V/bnDb7W0WIIbXIvGLSP9Xeas= 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=ChCjS2y2; arc=none smtp.client-ip=198.175.65.12 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="ChCjS2y2" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1709750554; x=1741286554; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=iWHnk1neQZIKAqWfpW+1RZrwfjWKjuOzgV4aWEXbwE8=; b=ChCjS2y25Aywb+oN/icJNWvpYsB03EcH1YSb+j0EiSWwaMJ2X8iZIvBe 5k/xojA5Yi1YAyTdQqKQg9XriCzOrjZC804vcKE3lyS/wfZt4OdShzKQ1 rgCQA4IMR+fEJrR2PnpcRqqwuisKDZ6hPvdhKtH8O178ttASeiudMCKHn bEKjttPnCSVgxpmZn9erttrTQx/NacF0n+oN+4uOEIP7GKf6z67ZjAdLx qNPV/Spo+iNG+aVSG67EbFR64gLdCex9gIC2CfcrYA1+EiZyTfupTrrm+ PHng7p341/0ckgkXHfscHa+vjgHd1A8M6tV/ARPaXgwMc7Nr84nTZxe89 Q==; X-IronPort-AV: E=McAfee;i="6600,9927,11005"; a="15819830" X-IronPort-AV: E=Sophos;i="6.06,209,1705392000"; d="scan'208";a="15819830" Received: from orviesa009.jf.intel.com ([10.64.159.149]) by orvoesa104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Mar 2024 10:42:32 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.06,209,1705392000"; d="scan'208";a="9925978" Received: from aschofie-mobl2.amr.corp.intel.com (HELO localhost) ([10.251.9.155]) by orviesa009-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Mar 2024 10:42:33 -0800 From: alison.schofield@intel.com To: Vishal Verma Cc: Alison Schofield , nvdimm@lists.linux.dev, linux-cxl@vger.kernel.org Subject: [ndctl PATCH v10 5/7] cxl/list: collect and parse media_error records Date: Wed, 6 Mar 2024 10:42:24 -0800 Message-Id: <9e3916d77162b4cbf6ee2636f13454f239f979c7.1709748564.git.alison.schofield@intel.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: nvdimm@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Alison Schofield Media_error records are logged as events in the kernel tracing subsystem. To prepare the media_error records for cxl list, enable tracing, trigger the poison list read, and parse the generated cxl_poison events into a json representation. Use the event_trace private parsing option to customize the json representation based on cxl-list calling options and event field settings. Signed-off-by: Alison Schofield --- cxl/json.c | 257 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 257 insertions(+) diff --git a/cxl/json.c b/cxl/json.c index fbe41c78e82a..435747de384d 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,247 @@ err_jobj: return NULL; } +/* CXL Spec 3.1 Table 8-140 Media Error Record */ +#define CXL_POISON_SOURCE_MAX 7 +static const char *poison_source[] = { "Unknown", "External", "Internal", + "Injected", "Reserved", "Reserved", + "Reserved", "Vendor" }; + +/* CXL Spec 3.1 Table 8-139 Get Poison List Output Payload */ +#define CXL_POISON_FLAG_MORE BIT(0) +#define CXL_POISON_FLAG_OVERFLOW BIT(1) +#define CXL_POISON_FLAG_SCANNING BIT(2) + +struct poison_ctx { + struct json_object *jpoison; + struct cxl_region *region; + struct cxl_memdev *memdev; + unsigned long flags; +}; + +static struct cxl_memdev *find_memdev(struct cxl_region *region, + const char *memdev_name) +{ + struct cxl_memdev_mapping *mapping; + struct cxl_decoder *decoder; + struct cxl_memdev *memdev; + + cxl_mapping_foreach(region, mapping) + { + decoder = cxl_mapping_get_decoder(mapping); + if (!decoder) + continue; + + memdev = cxl_decoder_get_memdev(decoder); + if (strcmp(memdev_name, cxl_memdev_get_devname(memdev)) == 0) + break; + + memdev = NULL; + } + return memdev; +} + +static const char *find_decoder_name(struct poison_ctx *ctx, + const char *memdev_name, u64 addr) +{ + struct cxl_memdev *memdev = ctx->memdev; + const char *decoder_name = NULL; + struct cxl_endpoint *endpoint; + struct cxl_decoder *decoder; + struct cxl_port *port; + u64 start, end; + + if (!memdev) + memdev = find_memdev(ctx->region, memdev_name); + + 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) { + decoder_name = cxl_decoder_get_devname(decoder); + break; + } + } + return decoder_name; +} + +static 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; + const char *decoder_name = NULL; + const char *region_name = NULL; + const char *memdev_name = NULL; + char flag_str[32] = { '\0' }; + bool overflow = false; + u8 source, pflags; + u64 addr, ts; + u32 length; + char *str; + + jp = json_object_new_object(); + if (!jp) + return -ENOMEM; + + /* Skip records not in this region when listing by region */ + if (p_ctx->region) + region_name = cxl_region_get_devname(p_ctx->region); + if (region_name) + str = cxl_get_field_string(event, record, "region"); + + if ((region_name) && (strcmp(region_name, str) != 0)) { + json_object_put(jp); + return 0; + } + + /* Include endpoint decoder name with hpa, when present */ + addr = cxl_get_field_u64(event, record, "hpa"); + if (addr != ULLONG_MAX) { + memdev_name = cxl_get_field_string(event, record, "memdev"); + decoder_name = find_decoder_name(p_ctx, memdev_name, addr); + } + if (decoder_name) { + jobj = json_object_new_string(decoder_name); + if (jobj) + json_object_object_add(jp, "decoder", jobj); + + jobj = util_json_object_hex(addr, flags); + if (jobj) + json_object_object_add(jp, "hpa", jobj); + } + + addr = cxl_get_field_u64(event, record, "dpa"); + jobj = util_json_object_hex(addr, flags); + if (jobj) + json_object_object_add(jp, "dpa", jobj); + + length = cxl_get_field_u32(event, record, "dpa_length"); + jobj = util_json_object_size(length, flags); + if (jobj) + json_object_object_add(jp, "length", jobj); + + source = cxl_get_field_u8(event, record, "source"); + if (source <= CXL_POISON_SOURCE_MAX) + jobj = json_object_new_string(poison_source[source]); + else + jobj = json_object_new_string("Reserved"); + + if (jobj) + json_object_object_add(jp, "source", jobj); + + pflags = cxl_get_field_u8(event, record, "flags"); + if (pflags && pflags < UCHAR_MAX) { + if (pflags & CXL_POISON_FLAG_MORE) + strcat(flag_str, "More,"); + if (pflags & CXL_POISON_FLAG_SCANNING) + strcat(flag_str, "Scanning,"); + if (pflags & CXL_POISON_FLAG_OVERFLOW) { + strcat(flag_str, "Overflow,"); + overflow = true; + } + jobj = json_object_new_string(flag_str); + if (jobj) + json_object_object_add(jp, "flags", jobj); + } + + if (overflow) { + ts = cxl_get_field_u64(event, record, "overflow_ts"); + jobj = util_json_object_hex(ts, flags); + if (jobj) + json_object_object_add(jp, "overflow_t", jobj); + } + json_object_array_add(jpoison, jp); + + return 0; +} + +static struct json_object * +util_cxl_poison_events_to_json(struct tracefs_instance *inst, + struct poison_ctx *p_ctx) +{ + struct event_ctx ectx = { + .event_name = "cxl_poison", + .event_pid = getpid(), + .system = "cxl", + .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); + goto put_jobj; + } + if (json_object_array_length(p_ctx->jpoison) == 0) + goto put_jobj; + + return p_ctx->jpoison; + +put_jobj: + json_object_put(p_ctx->jpoison); + return NULL; +} + +static struct json_object * +util_cxl_poison_list_to_json(struct cxl_region *region, + struct cxl_memdev *memdev, + unsigned long flags) +{ + struct json_object *jpoison = NULL; + struct poison_ctx p_ctx; + struct tracefs_instance *inst; + int rc; + + inst = tracefs_instance_create("cxl list"); + if (!inst) { + fprintf(stderr, "tracefs_instance_create() failed\n"); + return NULL; + } + + rc = cxl_event_tracing_enable(inst, "cxl", "cxl_poison"); + if (rc < 0) { + fprintf(stderr, "Failed to enable trace: %d\n", rc); + goto err_free; + } + + if (region) + rc = cxl_region_trigger_poison_list(region); + else + rc = cxl_memdev_trigger_poison_list(memdev); + if (rc) + goto err_free; + + rc = cxl_event_tracing_disable(inst); + if (rc < 0) { + fprintf(stderr, "Failed to disable trace: %d\n", rc); + goto err_free; + } + + p_ctx = (struct poison_ctx) { + .region = region, + .memdev = memdev, + .flags = flags, + }; + jpoison = util_cxl_poison_events_to_json(inst, &p_ctx); + +err_free: + tracefs_instance_free(inst); + return jpoison; +} + struct json_object *util_cxl_memdev_to_json(struct cxl_memdev *memdev, unsigned long flags) { @@ -664,6 +909,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 +1263,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 Wed Mar 6 18:42:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alison Schofield X-Patchwork-Id: 13584544 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.12]) (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 8D29B13E7EA for ; Wed, 6 Mar 2024 18:42:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.12 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709750556; cv=none; b=Wjrkoal1VZl8wC9hjvpqtsUH+LesbTlG3a+at6P1x3XkjJyH4E8ng6QQ8xSIgUOHG1sQc+QpLgg1NyH6yl9pt66AEhmCZulyLVSVueotN1FL++ogtpnqGeAiUBMeE4/3ILSnKzvekE9fe3bfdW4BM8n1eds902FUZyArYTtnMag= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709750556; c=relaxed/simple; bh=sFSwfMOSaRKAAtONH9OZkJqK2kxBdAF3OaadvPZiR4o=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=N8mBpjUYepuqfUMFsrYzZEN88XFh8c0/vgrLtnoqOCEdlPeqQe/21/inAnfUMcD5Ass2gGBqQXi68j7cAEazhUrWMpf/5yZk6RmAPkMeGoSmOkv9GcriDTvEknDuqaK7hV6R603pyeg9JQxMS3EIoIMGVH7OiWsqpM9ZYutrFJ4= 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=ZxHAPWd6; arc=none smtp.client-ip=198.175.65.12 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="ZxHAPWd6" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1709750554; x=1741286554; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=sFSwfMOSaRKAAtONH9OZkJqK2kxBdAF3OaadvPZiR4o=; b=ZxHAPWd6GgXmhpLqTZM6xxS42rIyG9M+1PiUcGvA7Wv2mUklYhhnjlQt 94D5uZ/uuDcpMpPKBr7k6hf4KbzTB3UPBhXaH4HNIhzLennwUao21m0N1 yNmDEAD+8fT25dILvWJagwd4eLYy1Bkvm8AcMlIeWb2DMuVwhl76Iiyc7 Ob5Ur2UPaCHbSucmGwdDD+iXU1cPoQzWGMqkNMlP1GK3d7nwiH7JfwbbO cRGkwCgMI8eqy1RwIAhYyiEswuczsPl5fKTxECJQP9yWKaSIGCrzJ7UdO jyLi8+0c038NtH6kucG3VXljPdyksR8tTNz+PxbeqXN18UUpv7amzC2TP A==; X-IronPort-AV: E=McAfee;i="6600,9927,11005"; a="15819832" X-IronPort-AV: E=Sophos;i="6.06,209,1705392000"; d="scan'208";a="15819832" Received: from orviesa009.jf.intel.com ([10.64.159.149]) by orvoesa104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Mar 2024 10:42:33 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.06,209,1705392000"; d="scan'208";a="9925983" Received: from aschofie-mobl2.amr.corp.intel.com (HELO localhost) ([10.251.9.155]) by orviesa009-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Mar 2024 10:42:33 -0800 From: alison.schofield@intel.com To: Vishal Verma Cc: Alison Schofield , nvdimm@lists.linux.dev, linux-cxl@vger.kernel.org Subject: [ndctl PATCH v10 6/7] cxl/list: add --media-errors option to cxl list Date: Wed, 6 Mar 2024 10:42:25 -0800 Message-Id: <2047e536ed7a1d1a46c048053dfe22fc798ca35e.1709748564.git.alison.schofield@intel.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: nvdimm@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Alison Schofield 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: Dan Williams --- 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 Wed Mar 6 18:42:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alison Schofield X-Patchwork-Id: 13584545 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.12]) (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 B186313E7EF for ; Wed, 6 Mar 2024 18:42:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.12 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709750556; cv=none; b=Dl0nn90du8uU2DOmJhq/byZjyxcTugk8FI03lD010XlnKxEHrSgWL6C2dC530cA983OdwKu6U3YpCyJNhTNB0X7/BywR68yytS1I+/pSTkepg41Xgb7PcCPRIrhe96UkIGc/h3+q7a+QCBKWnuOsnEMg94UlFDI90YUjPghOiSI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709750556; c=relaxed/simple; bh=uta8tJ21GeBnYbAOfl0Q5MYKJMDYAWPc7SljrGN3qg0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=lB6kEcLOkk7jNrRE75ZcWvquQGnz3pDe1xOehOh7jqWzY4nSruvAIgaDzcgasm5mzTdGE1gO2vmWLUKF1qwsl1hTUtOXGg2gTcvjHqoZigFViiIWIRemxxk6RXBp7DBPOmRlI6IL1mEufHeNLbIVrXhqyviI3IZpRT2MhCNLOsY= 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=FHWbB2ve; arc=none smtp.client-ip=198.175.65.12 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="FHWbB2ve" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1709750554; x=1741286554; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=uta8tJ21GeBnYbAOfl0Q5MYKJMDYAWPc7SljrGN3qg0=; b=FHWbB2veCbuLAB5kWNdXA5z2SPlFMbeF0OJd7z92RoLAJu1GupqOo6nj tZ92XKBlTIdyDgsLV24m+FYSWzUyDW9msYePfn9FECY0UV655qZpKvcNa XvJVGuaHt9sMNqqZG0WL9IMPW0YovvIYHOKQ1jw8tUvYhn/iLWCCq6cCX aVPVV6hbwLPxLN8dLalPa2M0w5AM0ja71aOXxQV4cNjlj4I8w+v6G+/q+ fIDesyF45wVKLNWTcvHAkaWqPLQ8ZEDm2PYFfuYXWmQU3/rEsg5vAHJVr 6TrmmW5YV6fsxNfMMaHqGRNMoM1ZgaPXtD/iM7RcPtQG8sWjCu2HV7CG2 Q==; X-IronPort-AV: E=McAfee;i="6600,9927,11005"; a="15819838" X-IronPort-AV: E=Sophos;i="6.06,209,1705392000"; d="scan'208";a="15819838" Received: from orviesa009.jf.intel.com ([10.64.159.149]) by orvoesa104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Mar 2024 10:42:34 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.06,209,1705392000"; d="scan'208";a="9925988" Received: from aschofie-mobl2.amr.corp.intel.com (HELO localhost) ([10.251.9.155]) by orviesa009-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Mar 2024 10:42:34 -0800 From: alison.schofield@intel.com To: Vishal Verma Cc: Alison Schofield , nvdimm@lists.linux.dev, linux-cxl@vger.kernel.org Subject: [ndctl PATCH v10 7/7] cxl/test: add cxl-poison.sh unit test Date: Wed, 6 Mar 2024 10:42:26 -0800 Message-Id: <170103ffb14d7ac4d87fce8ef9e6b433b2ac166d.1709748564.git.alison.schofield@intel.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: nvdimm@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Alison Schofield Exercise cxl list, libcxl, and driver pieces of the get poison list pathway. Inject and clear poison using debugfs and use cxl-cli to read the poison list by memdev and by region. Signed-off-by: Alison Schofield --- test/cxl-poison.sh | 137 +++++++++++++++++++++++++++++++++++++++++++++ test/meson.build | 2 + 2 files changed, 139 insertions(+) create mode 100644 test/cxl-poison.sh diff --git a/test/cxl-poison.sh b/test/cxl-poison.sh new file mode 100644 index 000000000000..af2e9dcd1a11 --- /dev/null +++ b/test/cxl-poison.sh @@ -0,0 +1,137 @@ +#!/bin/bash +# SPDX-License-Identifier: GPL-2.0 +# Copyright (C) 2023 Intel Corporation. All rights reserved. + +. "$(dirname "$0")"/common + +rc=77 + +set -ex + +trap 'err $LINENO' ERR + +check_prereq "jq" + +modprobe -r cxl_test +modprobe cxl_test + +rc=1 + +# THEORY OF OPERATION: Exercise cxl-cli and cxl driver ability to +# inject, clear, and get the poison list. Do it by memdev and by region. + +find_memdev() +{ + readarray -t capable_mems < <("$CXL" list -b "$CXL_TEST_BUS" -M | + jq -r ".[] | select(.pmem_size != null) | + select(.ram_size != null) | .memdev") + + if [ ${#capable_mems[@]} == 0 ]; then + echo "no memdevs found for test" + err "$LINENO" + fi + + memdev=${capable_mems[0]} +} + +create_x2_region() +{ + # Find an x2 decoder + decoder="$($CXL list -b "$CXL_TEST_BUS" -D -d root | jq -r ".[] | + select(.pmem_capable == true) | + select(.nr_targets == 2) | + .decoder")" + + # Find a memdev for each host-bridge interleave position + port_dev0="$($CXL list -T -d "$decoder" | jq -r ".[] | + .targets | .[] | select(.position == 0) | .target")" + port_dev1="$($CXL list -T -d "$decoder" | jq -r ".[] | + .targets | .[] | select(.position == 1) | .target")" + mem0="$($CXL list -M -p "$port_dev0" | jq -r ".[0].memdev")" + mem1="$($CXL list -M -p "$port_dev1" | jq -r ".[0].memdev")" + + region="$($CXL create-region -d "$decoder" -m "$mem0" "$mem1" | + jq -r ".region")" + if [[ ! $region ]]; then + echo "create-region failed for $decoder" + err "$LINENO" + fi + echo "$region" +} + +# When cxl-cli support for inject and clear arrives, replace +# the writes to /sys/kernel/debug with the new cxl commands. + +inject_poison_sysfs() +{ + memdev="$1" + addr="$2" + + echo "$addr" > /sys/kernel/debug/cxl/"$memdev"/inject_poison +} + +clear_poison_sysfs() +{ + memdev="$1" + addr="$2" + + echo "$addr" > /sys/kernel/debug/cxl/"$memdev"/clear_poison +} + +validate_poison_found() +{ + list_by="$1" + nr_expect="$2" + + poison_list="$($CXL list "$list_by" --media-errors | + jq -r '.[].media_errors')" + if [[ ! $poison_list ]]; then + nr_found=0 + else + nr_found=$(jq "length" <<< "$poison_list") + fi + if [ "$nr_found" -ne "$nr_expect" ]; then + echo "$nr_expect poison records expected, $nr_found found" + err "$LINENO" + fi +} + +test_poison_by_memdev() +{ + find_memdev + inject_poison_sysfs "$memdev" "0x40000000" + inject_poison_sysfs "$memdev" "0x40001000" + inject_poison_sysfs "$memdev" "0x600" + inject_poison_sysfs "$memdev" "0x0" + validate_poison_found "-m $memdev" 4 + + clear_poison_sysfs "$memdev" "0x40000000" + clear_poison_sysfs "$memdev" "0x40001000" + clear_poison_sysfs "$memdev" "0x600" + clear_poison_sysfs "$memdev" "0x0" + validate_poison_found "-m $memdev" 0 +} + +test_poison_by_region() +{ + create_x2_region + inject_poison_sysfs "$mem0" "0x40000000" + inject_poison_sysfs "$mem1" "0x40000000" + validate_poison_found "-r $region" 2 + + clear_poison_sysfs "$mem0" "0x40000000" + clear_poison_sysfs "$mem1" "0x40000000" + validate_poison_found "-r $region" 0 +} + +# Turn tracing on. Note that 'cxl list --poison' does toggle the tracing. +# Turning it on here allows the test user to also view inject and clear +# trace events. +echo 1 > /sys/kernel/tracing/events/cxl/cxl_poison/enable + +test_poison_by_memdev +test_poison_by_region + +check_dmesg "$LINENO" + +modprobe -r cxl-test diff --git a/test/meson.build b/test/meson.build index a965a79fd6cb..d871e28e17ce 100644 --- a/test/meson.build +++ b/test/meson.build @@ -160,6 +160,7 @@ cxl_events = find_program('cxl-events.sh') cxl_sanitize = find_program('cxl-sanitize.sh') cxl_destroy_region = find_program('cxl-destroy-region.sh') cxl_qos_class = find_program('cxl-qos-class.sh') +cxl_poison = find_program('cxl-poison.sh') tests = [ [ 'libndctl', libndctl, 'ndctl' ], @@ -192,6 +193,7 @@ tests = [ [ 'cxl-sanitize.sh', cxl_sanitize, 'cxl' ], [ 'cxl-destroy-region.sh', cxl_destroy_region, 'cxl' ], [ 'cxl-qos-class.sh', cxl_qos_class, 'cxl' ], + [ 'cxl-poison.sh', cxl_poison, 'cxl' ], ] if get_option('destructive').enabled()