All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Purkait, Soham" <soham.purkait@intel.com>
To: Ravi Kishore Koppuravuri <ravi.kishore.koppuravuri@intel.com>,
	<igt-dev@lists.freedesktop.org>
Cc: Riana Tauro <riana.tauro@intel.com>,
	Gupta Anshuman <anshuman.gupta@intel.com>,
	Jadav Raag <raag.jadav@intel.com>,
	Nilawar Badal <badal.nilawar@intel.com>,
	Koujalagi Mallesh <mallesh.koujalagi@intel.com>,
	Harish Chegondi <harish.chegondi@intel.com>
Subject: Re: [PATCH v4 04/10] lib/igt_drm_netlink: add get_error_counter support
Date: Thu, 10 Sep 2026 17:35:47 +0530	[thread overview]
Message-ID: <1ed559f2-2dbd-4048-aa5b-d4b6e2493e91@intel.com> (raw)
In-Reply-To: <20260903073335.339540-5-ravi.kishore.koppuravuri@intel.com>

Hi Ravi,

On 03-09-2026 13:03, Ravi Kishore Koppuravuri wrote:
> Add netlink request/response handling for DRM_RAS_CMD_GET_ERROR_COUNTER.
>
> Cc: Purkait Soham <soham.purkait@intel.com>
> Cc: Riana Tauro <riana.tauro@intel.com>
> Cc: Gupta Anshuman <anshuman.gupta@intel.com>
> Cc: Jadav Raag <raag.jadav@intel.com>
> Cc: Nilawar Badal <badal.nilawar@intel.com>
> Cc: Koujalagi Mallesh <mallesh.koujalagi@intel.com>
> Cc: Harish Chegondi <harish.chegondi@intel.com>
> Signed-off-by: Ravi Kishore Koppuravuri <ravi.kishore.koppuravuri@intel.com>
> ---
> v2:Handled ACK/FINISH/ERR nl responses using separate callbacks
>     Added a check whether error_value updated by valid callback or not
>     Added a check whether response required for the command or not
> v4:Added support to poll for incoming netlink messages with 10 seconds timeout
>     Renamed the library functions with prefix "igt_drm_netlink_*" and
>     other cosmetic changes (Nikula Jani & Kamil)
> ---
>   lib/igt_drm_netlink.c | 268 +++++++++++++++++++++++++++++++++++++++++-
>   lib/igt_drm_netlink.h |   9 ++
>   2 files changed, 275 insertions(+), 2 deletions(-)
>
> diff --git a/lib/igt_drm_netlink.c b/lib/igt_drm_netlink.c
> index 709c01987..b18e3eeb6 100644
> --- a/lib/igt_drm_netlink.c
> +++ b/lib/igt_drm_netlink.c
> @@ -3,6 +3,8 @@
>    * Copyright © 2026 Intel Corporation
>    */
>   
> +#include <errno.h>
> +#include <poll.h>
>   #include <stdint.h>
>   
>   #include <netlink/genl/ctrl.h>
> @@ -11,6 +13,229 @@
>   #include "igt_core.h"
>   #include "igt_drm_netlink.h"
>   
> +#define DRM_RAS_NETLINK_REPLY_TIMEOUT_MS 10000
> +
> +static int ras_command_cb(struct nl_msg *msg, void *arg)
> +{
> +	struct app_context *ctx = arg;
> +	struct nlmsghdr *nlh;
> +	struct genlmsghdr *gnlh;
> +	int ret;
> +
> +	nlh = nlmsg_hdr(msg);
> +	gnlh = nlmsg_data(nlh);
> +
> +	switch (gnlh->cmd) {
> +	case DRM_RAS_CMD_GET_ERROR_COUNTER: {
> +		struct nlattr *attrs[DRM_RAS_A_ERROR_COUNTER_ATTRS_MAX + 1];
> +
> +		ret = genlmsg_parse(nlh, 0, attrs,
> +				    DRM_RAS_A_ERROR_COUNTER_ATTRS_MAX, NULL);
> +		if (ret < 0)
> +			return NL_SKIP;
> +
> +		if (!attrs[DRM_RAS_A_ERROR_COUNTER_ATTRS_ERROR_VALUE])
> +			return NL_SKIP;
> +
> +		ctx->error_value = nla_get_u32(attrs[DRM_RAS_A_ERROR_COUNTER_ATTRS_ERROR_VALUE]);
> +		break;
> +	}
> +	default:
> +		return NL_SKIP;
> +	}
> +
> +	ctx->reply_received = true;
> +	if (ctx->ack_received)
> +		ctx->cmd_done = true;
> +
> +	return NL_OK;
> +}
> +
> +static int ras_error_cb(struct sockaddr_nl *nla, struct nlmsgerr *err, void *arg)
> +{
> +	struct app_context *ctx = arg;
> +
> +	ctx->last_nl_error = err->error;
> +	ctx->cmd_done = true;
> +
> +	return NL_STOP;
> +}
> +
> +static int ras_ack_cb(struct nl_msg *msg, void *arg)
> +{
> +	struct app_context *ctx = arg;
> +
> +	ctx->ack_received = true;
> +	if (!ctx->response_required || ctx->reply_received)
> +		ctx->cmd_done = true;
> +
> +	return NL_STOP;
> +}
> +
> +static int ras_finish_cb(struct nl_msg *msg, void *arg)
> +{
> +	struct app_context *ctx = arg;
> +
> +	ctx->cmd_done = true;
> +
> +	return NL_STOP;
> +}
> +
> +static int register_callbacks(struct nl_cb *cb, struct app_context *ctx)
> +{
> +	int ret;
> +
> +	ret = nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM, ras_command_cb, ctx);
> +	if (ret < 0)
> +		return ret;
> +
> +	ret = nl_cb_set(cb, NL_CB_ACK, NL_CB_CUSTOM, ras_ack_cb, ctx);
> +	if (ret < 0)
> +		return ret;
> +
> +	ret = nl_cb_set(cb, NL_CB_FINISH, NL_CB_CUSTOM, ras_finish_cb, ctx);
> +	if (ret < 0)
> +		return ret;
> +
> +	ret = nl_cb_err(cb, NL_CB_CUSTOM, ras_error_cb, ctx);
> +	if (ret < 0)
> +		return ret;
> +
> +	return 0;
> +}
> +
> +static int send_and_recv_nl_msg(struct app_context *ctx,
> +				struct nl_cb *cb,
> +				struct nl_msg *msg)
> +{
> +	struct pollfd pfd = {
> +		.fd = nl_socket_get_fd(ctx->sock),
> +		.events = POLLIN,
> +	};
> +	int ret;
> +
> +	ret = nl_send_auto(ctx->sock, msg);
> +	nlmsg_free(msg);
> +	if (ret < 0) {
> +		nl_cb_put(cb);
> +		return ret;
> +	}
> +
> +	/* NL Reply and ACK arrive as separate responses */
> +	while (!ctx->cmd_done) {
> +		do {
> +			/* poll for incoming netlink messages with 10 seconds timeout */
> +			ret = poll(&pfd, 1, DRM_RAS_NETLINK_REPLY_TIMEOUT_MS);
> +		} while (ret < 0 && errno == EINTR);
> +
> +		if (ret == 0) {
> +			ret = -ETIMEDOUT;
> +			break;
> +		}
> +
> +		if (ret < 0) {
> +			ret = -errno;
> +			break;
> +		}
> +
> +		if (!(pfd.revents & POLLIN)) {
> +			ret = -EIO;
> +			break;
> +		}
> +
> +		ret = nl_recvmsgs(ctx->sock, cb);
> +		if (ret < 0)
> +			break;
> +	}
> +	nl_cb_put(cb);
> +
> +	return ret < 0 ? ret : 0;
> +}
> +
> +static int send_command(struct app_context *ctx, uint8_t cmd)
> +{
> +	struct nl_cb *cb;
> +	struct nl_msg *msg;
> +	void *msg_head;
> +	int ret;
> +
> +	msg = nlmsg_alloc();
> +	if (!msg)
> +		return -ENOMEM;
> +
> +	ctx->last_nl_error = 0;
> +	ctx->cmd_done = false;
> +	ctx->reply_received = false;
> +	ctx->ack_received = false;
> +	ctx->response_required = false;
> +
> +	msg_head = genlmsg_put(msg,
> +			       NL_AUTO_PORT,
> +			       NL_AUTO_SEQ,
> +			       ctx->family_id,
> +			       0,
> +			       NLM_F_REQUEST | NLM_F_ACK,
> +			       cmd,
> +			       DRM_RAS_FAMILY_VERSION);
> +	if (!msg_head) {
> +		nlmsg_free(msg);
> +		return -ENOMEM;
> +	}
> +
> +	switch (cmd) {
> +	case DRM_RAS_CMD_GET_ERROR_COUNTER:
> +		ctx->response_required = true;
> +		ret = nla_put_u32(msg,
> +				  DRM_RAS_A_ERROR_COUNTER_ATTRS_NODE_ID,
> +				  ctx->node_id);
> +		if (ret < 0) {
> +			nlmsg_free(msg);
> +			return ret;
> +		}
> +
> +		ret = nla_put_u32(msg,
> +				  DRM_RAS_A_ERROR_COUNTER_ATTRS_ERROR_ID,
> +				  ctx->error_id);
> +		if (ret < 0) {
> +			nlmsg_free(msg);
> +			return ret;
> +		}
> +		break;
> +	default:
> +		nlmsg_free(msg);
> +		return -EOPNOTSUPP;
> +	}
> +
> +	cb = nl_cb_alloc(NL_CB_DEFAULT);
> +	if (!cb) {
> +		nlmsg_free(msg);
> +		return -ENOMEM;
> +	}
> +
> +	ret = register_callbacks(cb, ctx);
> +	if (ret < 0) {
> +		nl_cb_put(cb);
> +		nlmsg_free(msg);
> +		return ret;
> +	}
> +
> +	return send_and_recv_nl_msg(ctx, cb, msg);
> +}
> +
> +static void reset_drm_ras_netlink_context(struct app_context *ctx)
> +{
> +	ctx->sock = NULL;
> +	ctx->node_id = UINT32_MAX;
> +	ctx->error_id = UINT32_MAX;
> +	ctx->error_value = 0;
> +	ctx->last_nl_error = 0;
> +	ctx->cmd_done = false;
> +	ctx->reply_received = false;
> +	ctx->ack_received = false;
> +	ctx->response_required = false;
> +	ctx->family_id = -1;
> +}
> +
>   void igt_drm_netlink_cleanup(struct app_context *ctx)
>   {
>   	if (!ctx || !ctx->sock)
> @@ -18,14 +243,19 @@ void igt_drm_netlink_cleanup(struct app_context *ctx)
>   
>   	nl_close(ctx->sock);
>   	nl_socket_free(ctx->sock);
> -	ctx->sock = NULL;
> -	ctx->family_id = -1;
> +
> +	reset_drm_ras_netlink_context(ctx);
>   
>   	igt_debug("Cleaned up netlink socket.\n");
>   }
>   
>   int igt_drm_netlink_init(struct app_context *ctx)
>   {
> +	if (!ctx)
> +		return -EINVAL;
> +
> +	reset_drm_ras_netlink_context(ctx);
> +
>   	ctx->sock = nl_socket_alloc();
>   	if (!ctx->sock)
>   		return -1;
> @@ -52,3 +282,37 @@ int igt_drm_netlink_init(struct app_context *ctx)
>   		  DRM_RAS_FAMILY_NAME, ctx->family_id);
>   	return 0;
>   }
> +
> +int igt_drm_netlink_get_error_counter(struct app_context *ctx)

Aren't the return codes here mixing -errno and libnl -NLE_* values, 
which overlap numerically and mean different things?

Thanks,
Soham
> +{
> +	int ret;
> +
> +	if (!ctx || !ctx->sock || ctx->family_id < 0)
> +		return -EINVAL;
> +
> +	if (ctx->node_id == UINT32_MAX ||
> +	    ctx->error_id == UINT32_MAX ||
> +	    ctx->error_id == 0) {
> +		igt_warn("Invalid node_id (%u) or error_id (%u) provided. "
> +			 "node_id should be >= 0 and error_id should be >= 1.\n",
> +			 ctx->node_id, ctx->error_id);
> +		return -EINVAL;
> +	}
> +
> +	ctx->error_value = UINT32_MAX;
> +
> +	ret = send_command(ctx, DRM_RAS_CMD_GET_ERROR_COUNTER);
> +	if (ret < 0)
> +		return ret;
> +
> +	if (ctx->error_value == UINT32_MAX) {
> +		igt_warn("No valid error counter reply: node_id=%u error_id=%u kernel_error=%d\n",
> +			 ctx->node_id, ctx->error_id, ctx->last_nl_error);
> +		return ctx->last_nl_error ? ctx->last_nl_error : -ENODATA;
> +	}
> +
> +	igt_debug("Retrieved error counter: node_id=%u error_id=%u value=%u\n",
> +		  ctx->node_id, ctx->error_id, ctx->error_value);
> +
> +	return 0;
> +}
> diff --git a/lib/igt_drm_netlink.h b/lib/igt_drm_netlink.h
> index 0e563e55f..5db7f4ab5 100644
> --- a/lib/igt_drm_netlink.h
> +++ b/lib/igt_drm_netlink.h
> @@ -10,11 +10,20 @@
>   
>   struct app_context {
>   	struct nl_sock *sock;
> +	uint32_t node_id;
> +	uint32_t error_id;
> +	uint32_t error_value;
> +	int last_nl_error;
> +	bool cmd_done;
> +	bool reply_received;
> +	bool ack_received;
> +	bool response_required;
>   	int family_id;
>   };
>   
>   void igt_drm_netlink_cleanup(struct app_context *ctx);
>   int igt_drm_netlink_init(struct app_context *ctx);
> +int igt_drm_netlink_get_error_counter(struct app_context *ctx);
>   
>   #endif /* IGT_DRM_NETLINK_H */
>   

  reply	other threads:[~2026-09-10 12:07 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-03  7:33 [PATCH v4 00/10] Xe3P GPU Error Injection Test Suite with DRM RAS Netlink Support Ravi Kishore Koppuravuri
2026-09-03  7:33 ` [PATCH v4 01/10] drm-uapi/drm_ras: Sync with kernel b2207d4c4e84 Ravi Kishore Koppuravuri
2026-09-10 11:12   ` Raag Jadav
2026-09-11  4:19     ` Koppuravuri, Ravi Kishore
2026-09-03  7:33 ` [PATCH v4 02/10] lib/meson: Add libnl dependencies for DRM RAS support Ravi Kishore Koppuravuri
2026-09-10  8:45   ` Purkait, Soham
2026-09-03  7:33 ` [PATCH v4 03/10] lib/igt_drm_netlink: Introduce DRM RAS Netlink interface library Ravi Kishore Koppuravuri
2026-09-10  6:17   ` Purkait, Soham
2026-09-03  7:33 ` [PATCH v4 04/10] lib/igt_drm_netlink: add get_error_counter support Ravi Kishore Koppuravuri
2026-09-10 12:05   ` Purkait, Soham [this message]
2026-09-03  7:33 ` [PATCH v4 05/10] lib/igt_drm_netlink: add get_error_threshold command support Ravi Kishore Koppuravuri
2026-09-03  7:33 ` [PATCH v4 06/10] lib/igt_drm_netlink: add set_error_threshold " Ravi Kishore Koppuravuri
2026-09-11 11:48   ` Purkait, Soham
2026-09-03  7:33 ` [PATCH v4 07/10] tests/intel/xe_err_injection: Add GT UC Unicast GAM Walker Command Parity Error Injection Ravi Kishore Koppuravuri
2026-09-03 16:45   ` Purkait, Soham
2026-09-11 15:03   ` Kamil Konieczny
2026-09-03  7:33 ` [PATCH v4 08/10] lib/igt_drm_netlink: add event notify subscription and event wait support Ravi Kishore Koppuravuri
2026-09-03  7:33 ` [PATCH v4 09/10] tests/intel/xe_err_injection: Add tests for L2 bank Corr err threshold scenarios Ravi Kishore Koppuravuri
2026-09-11  8:14   ` Purkait, Soham
2026-09-03  7:33 ` [PATCH v4 10/10] tests/intel/xe_err_injection: add CRI GPU requirement check Ravi Kishore Koppuravuri
2026-09-10  6:19   ` Purkait, Soham
2026-09-03 20:21 ` ✓ Xe.CI.BAT: success for Xe3P GPU Error Injection Test Suite with DRM RAS Netlink Support (rev7) Patchwork
2026-09-03 20:56 ` ✓ i915.CI.BAT: " Patchwork
2026-09-04  8:50 ` ✓ Xe.CI.FULL: " Patchwork
2026-09-04 10:51 ` ✗ i915.CI.Full: failure " Patchwork

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1ed559f2-2dbd-4048-aa5b-d4b6e2493e91@intel.com \
    --to=soham.purkait@intel.com \
    --cc=anshuman.gupta@intel.com \
    --cc=badal.nilawar@intel.com \
    --cc=harish.chegondi@intel.com \
    --cc=igt-dev@lists.freedesktop.org \
    --cc=mallesh.koujalagi@intel.com \
    --cc=raag.jadav@intel.com \
    --cc=ravi.kishore.koppuravuri@intel.com \
    --cc=riana.tauro@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.