From: Wei Huang <wei.huang2@amd.com>
To: <dmaengine@vger.kernel.org>
Cc: <vkoul@kernel.org>, <Frank.Li@kernel.org>, <shuah@kernel.org>,
<nathan.lynch@amd.com>, <wei.huang2@amd.com>,
<mario.limonciello@amd.com>, <Stephen.Bates@amd.com>,
<tycho@kernel.org>, <suravee.suthikulpanit@amd.com>,
<rientjes@google.com>, <John.Kariuki@amd.com>, <jic23@kernel.org>,
<weixugc@google.com>, <bhelgaas@google.com>,
<Shyam.Iyer@dell.com>, <linux-kernel@vger.kernel.org>,
<linux-kselftest@vger.kernel.org>, <linux-pci@vger.kernel.org>
Subject: [PATCH v1 13/44] dmaengine: sdxi: kill user contexts on fatal errors
Date: Thu, 19 Nov 2026 14:22:49 -0600 [thread overview]
Message-ID: <20261119202321.1734355-14-wei.huang2@amd.com> (raw)
In-Reply-To: <20261119202321.1734355-1-wei.huang2@amd.com>
Use context references from current xarray to translate error-log
stop reactions into fatal userspace context cleanup. Kernel and
administrative contexts remain under their existing owners.
Co-developed-by: Nathan Lynch <nathan.lynch@amd.com>
Signed-off-by: Nathan Lynch <nathan.lynch@amd.com>
Signed-off-by: Wei Huang <wei.huang2@amd.com>
---
drivers/dma/sdxi/context.c | 21 +++++++++++
drivers/dma/sdxi/context.h | 1 +
drivers/dma/sdxi/device.c | 5 +++
drivers/dma/sdxi/error.c | 71 ++++++++++++++++++++++++++++++++++++--
drivers/dma/sdxi/sdxi.h | 1 +
5 files changed, 96 insertions(+), 3 deletions(-)
diff --git a/drivers/dma/sdxi/context.c b/drivers/dma/sdxi/context.c
index f5e31f9f9131..2c3b6f5df4b5 100644
--- a/drivers/dma/sdxi/context.c
+++ b/drivers/dma/sdxi/context.c
@@ -1119,6 +1119,27 @@ void sdxi_cxt_kill(struct sdxi_cxt *cxt)
wake_up_poll(&cxt->poll_wq, EPOLLERR);
}
+void sdxi_cxt_kill_stopped(struct sdxi_cxt *cxt)
+{
+ bool newly_fatal;
+
+ if (!cxt)
+ return;
+
+ mutex_lock(&cxt->cleanup_lock);
+ newly_fatal = !cxt->fatal;
+ cxt->fatal = true;
+ cxt->started = false;
+ cxt->quiesced = true;
+ cxt->quiesce_cst_flags = 0;
+ if (sdxi_cxt_is_user(cxt))
+ sdxi_cxt_queue_cleanup_locked(cxt, 0);
+ mutex_unlock(&cxt->cleanup_lock);
+
+ if (newly_fatal)
+ wake_up_poll(&cxt->poll_wq, EPOLLERR);
+}
+
void sdxi_cxt_release_user_handle(struct sdxi_cxt *cxt)
{
if (!cxt)
diff --git a/drivers/dma/sdxi/context.h b/drivers/dma/sdxi/context.h
index b4a416509243..bbe83e54b827 100644
--- a/drivers/dma/sdxi/context.h
+++ b/drivers/dma/sdxi/context.h
@@ -108,6 +108,7 @@ int sdxi_cxt_quiesce(struct sdxi_cxt *cxt, unsigned int timeout_ms,
bool sdxi_cxt_is_user(const struct sdxi_cxt *cxt);
bool sdxi_cxt_is_fatal(const struct sdxi_cxt *cxt);
void sdxi_cxt_kill(struct sdxi_cxt *cxt);
+void sdxi_cxt_kill_stopped(struct sdxi_cxt *cxt);
void sdxi_cxt_release_user_handle(struct sdxi_cxt *cxt);
int sdxi_cxt_notify_mm_release(struct sdxi_cxt *cxt);
void sdxi_cxt_vma_open(struct sdxi_cxt *cxt);
diff --git a/drivers/dma/sdxi/device.c b/drivers/dma/sdxi/device.c
index e760c8a2603a..1587795c0a16 100644
--- a/drivers/dma/sdxi/device.c
+++ b/drivers/dma/sdxi/device.c
@@ -96,6 +96,11 @@ static enum sdxi_fn_gsv sdxi_dev_gsv(const struct sdxi_dev *sdxi)
return gsv;
}
+bool sdxi_dev_in_error(const struct sdxi_dev *sdxi)
+{
+ return sdxi_dev_gsv(sdxi) == SDXI_GSV_ERROR;
+}
+
static const unsigned long gsv_poll_interval_us = USEC_PER_MSEC * 100;
static const unsigned long gsv_transition_timeout_us = USEC_PER_SEC * 1;
diff --git a/drivers/dma/sdxi/error.c b/drivers/dma/sdxi/error.c
index 561e88d81f41..4d8607b3bbec 100644
--- a/drivers/dma/sdxi/error.c
+++ b/drivers/dma/sdxi/error.c
@@ -14,6 +14,7 @@
#include <linux/sizes.h>
#include <linux/string.h>
+#include "context.h"
#include "error.h"
#include "hw.h"
#include "mmio.h"
@@ -61,6 +62,11 @@ enum {
SDXI_PACKING_QUIRKS = QUIRK_LITTLE_ENDIAN | QUIRK_LSW32_IS_FIRST,
};
+enum sdxi_errlog_reaction {
+ SDXI_ERRLOG_REACTION_CXT_STOP = 1,
+ SDXI_ERRLOG_REACTION_FN_STOP = 2,
+};
+
static const char *const sdxi_err_steps[] = {
[1] = "internal",
[2] = "context L2",
@@ -124,6 +130,44 @@ static void sdxi_errlog_report(struct sdxi_dev *sdxi, u64 read_index,
dev_err(sdxi->dev, " buffer=%u\n", entry->buf);
}
+static bool sdxi_errlog_handle_reaction(struct sdxi_dev *sdxi,
+ const struct sdxi_errlog_entry *entry)
+{
+ struct sdxi_cxt *cxt;
+
+ if (entry->reaction == SDXI_ERRLOG_REACTION_FN_STOP)
+ return true;
+ if (entry->reaction != SDXI_ERRLOG_REACTION_CXT_STOP ||
+ !entry->cv || !entry->cxt_num)
+ return false;
+
+ cxt = sdxi_cxt_get_by_id(sdxi, entry->cxt_num);
+ if (!cxt)
+ return false;
+
+ if (sdxi_cxt_is_user(cxt))
+ sdxi_cxt_kill_stopped(cxt);
+ sdxi_cxt_put(cxt);
+ return false;
+}
+
+static void sdxi_error_handle_function(struct sdxi_dev *sdxi)
+{
+ struct sdxi_cxt *cxt;
+ u32 cxt_id;
+
+ dev_err(sdxi->dev, "function stopped after hardware error\n");
+ sdxi_dev_fail(sdxi);
+
+ for (cxt_id = 1; cxt_id <= sdxi->max_cxtid; cxt_id++) {
+ cxt = sdxi_cxt_get_by_id(sdxi, cxt_id);
+ if (!cxt)
+ continue;
+ sdxi_cxt_kill_stopped(cxt);
+ sdxi_cxt_put(cxt);
+ }
+}
+
static irqreturn_t sdxi_error_irq_thread(int irq, void *data)
{
struct sdxi_dev *sdxi = data;
@@ -134,10 +178,16 @@ static irqreturn_t sdxi_error_irq_thread(int irq, void *data)
u64 read_index;
u64 status;
u64 count;
+ bool function_stopped;
status = sdxi_read64(sdxi, SDXI_MMIO_ERR_STS);
- if (!(status & ack_mask))
- return IRQ_NONE;
+ function_stopped = sdxi_dev_in_error(sdxi);
+ if (!(status & ack_mask)) {
+ if (!function_stopped)
+ return IRQ_NONE;
+ sdxi_error_handle_function(sdxi);
+ return IRQ_HANDLED;
+ }
if (status & SDXI_MMIO_ERR_STS_ERR_BIT)
dev_err(sdxi->dev, "hardware could not write the error log\n");
@@ -145,6 +195,8 @@ static irqreturn_t sdxi_error_irq_thread(int irq, void *data)
dev_err(sdxi->dev, "error log overflowed\n");
if (!(status & SDXI_MMIO_ERR_STS_STS_BIT)) {
sdxi_write64(sdxi, SDXI_MMIO_ERR_STS, status & ack_mask);
+ if (function_stopped)
+ sdxi_error_handle_function(sdxi);
return IRQ_HANDLED;
}
@@ -170,12 +222,17 @@ static irqreturn_t sdxi_error_irq_thread(int irq, void *data)
size_t index = read_index % SDXI_ERRLOG_ENTRIES;
memcpy(&raw, &sdxi->err_log[index], sizeof(raw));
- if (sdxi_errlog_decode(sdxi, &raw, &entry))
+ if (sdxi_errlog_decode(sdxi, &raw, &entry)) {
sdxi_errlog_report(sdxi, read_index, &entry);
+ function_stopped |=
+ sdxi_errlog_handle_reaction(sdxi, &entry);
+ }
read_index++;
}
sdxi_write64(sdxi, SDXI_MMIO_ERR_RD, read_index);
+ if (function_stopped)
+ sdxi_error_handle_function(sdxi);
return IRQ_HANDLED;
}
@@ -214,6 +271,10 @@ int sdxi_error_init(struct sdxi_dev *sdxi)
FIELD_MODIFY(SDXI_MMIO_ERR_CTL_EN, ®, 1);
sdxi_write64(sdxi, SDXI_MMIO_ERR_CTL, reg);
+ reg = sdxi_read64(sdxi, SDXI_MMIO_CTL0);
+ FIELD_MODIFY(SDXI_MMIO_CTL0_FN_ERR_INTR_EN, ®, 1);
+ sdxi_write64(sdxi, SDXI_MMIO_CTL0, reg);
+
size_order = ilog2(SDXI_ERRLOG_SIZE) - ilog2(SZ_4K);
reg = FIELD_PREP(SDXI_MMIO_ERR_CFG_PTR,
sdxi->err_log_dma >> ilog2(SZ_4K)) |
@@ -237,6 +298,10 @@ void sdxi_error_exit(struct sdxi_dev *sdxi)
FIELD_MODIFY(SDXI_MMIO_ERR_CTL_EN, ®, 0);
sdxi_write64(sdxi, SDXI_MMIO_ERR_CTL, reg);
+ reg = sdxi_read64(sdxi, SDXI_MMIO_CTL0);
+ FIELD_MODIFY(SDXI_MMIO_CTL0_FN_ERR_INTR_EN, ®, 0);
+ sdxi_write64(sdxi, SDXI_MMIO_CTL0, reg);
+
if (sdxi->error_irq >= 0)
devm_free_irq(sdxi->dev, sdxi->error_irq, sdxi);
diff --git a/drivers/dma/sdxi/sdxi.h b/drivers/dma/sdxi/sdxi.h
index c000542b5ce9..fa34aaa36c16 100644
--- a/drivers/dma/sdxi/sdxi.h
+++ b/drivers/dma/sdxi/sdxi.h
@@ -160,6 +160,7 @@ static inline int sdxi_vector_to_irq(struct sdxi_dev *sdxi, unsigned int nr)
int sdxi_register(struct device *dev, const struct sdxi_bus_ops *ops);
void sdxi_unregister(struct device *dev);
+bool sdxi_dev_in_error(const struct sdxi_dev *sdxi);
void sdxi_dev_force_quiesce(struct sdxi_dev *sdxi);
void sdxi_dev_fail(struct sdxi_dev *sdxi);
--
2.56.1
next prev parent reply other threads:[~2026-11-19 20:26 UTC|newest]
Thread overview: 45+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-19 20:22 [PATCH v1 00/44] dmaengine: sdxi: add userspace control and management support Wei Huang
2026-11-19 20:22 ` [PATCH v1 01/44] dmaengine: sdxi: cache hardware version for feature gating Wei Huang
2026-11-19 20:22 ` [PATCH v1 02/44] dmaengine: sdxi: define key and error MMIO registers Wei Huang
2026-11-19 20:22 ` [PATCH v1 03/44] dmaengine: sdxi: define SDXI hardware layouts Wei Huang
2026-11-19 20:22 ` [PATCH v1 04/44] dmaengine: sdxi: encode admin descriptors Wei Huang
2026-11-19 20:22 ` [PATCH v1 05/44] dmaengine: sdxi: support timeout-aware completion waits Wei Huang
2026-11-19 20:22 ` [PATCH v1 06/44] dmaengine: sdxi: support the full context table hierarchy Wei Huang
2026-11-19 20:22 ` [PATCH v1 07/44] dmaengine: sdxi: implement synchronous admin operations Wei Huang
2026-11-19 20:22 ` [PATCH v1 08/44] dmaengine: sdxi: add core RKey table management Wei Huang
2026-11-19 20:22 ` [PATCH v1 09/44] dmaengine: sdxi: handle hardware error logs Wei Huang
2026-11-19 20:22 ` [PATCH v1 10/44] dmaengine: sdxi: separate context and submission resources Wei Huang
2026-11-19 20:22 ` [PATCH v1 11/44] dmaengine: sdxi: support userspace context lifetimes Wei Huang
2026-11-19 20:22 ` [PATCH v1 12/44] dmaengine: sdxi: route context interrupts to eventfd Wei Huang
2026-11-19 20:22 ` Wei Huang [this message]
2026-11-19 20:22 ` [PATCH v1 14/44] dmaengine: sdxi: define the ioctl UAPI surface Wei Huang
2026-11-19 20:22 ` [PATCH v1 15/44] dmaengine: sdxi: add internal ioctl definitions Wei Huang
2026-11-19 20:22 ` [PATCH v1 16/44] dmaengine: sdxi: register core character devices Wei Huang
2026-11-19 20:22 ` [PATCH v1 17/44] dmaengine: sdxi: implement fixed-size ioctl dispatch Wei Huang
2026-11-19 20:22 ` [PATCH v1 18/44] dmaengine: sdxi: implement userspace context file operations Wei Huang
2026-11-19 20:22 ` [PATCH v1 19/44] dmaengine: sdxi: validate and copy key ioctl payloads Wei Huang
2026-11-19 20:22 ` [PATCH v1 20/44] dmaengine: sdxi: implement RKey management ioctls Wei Huang
2026-11-19 20:22 ` [PATCH v1 21/44] dmaengine: sdxi: implement AKey " Wei Huang
2026-11-19 20:22 ` [PATCH v1 22/44] dmaengine: sdxi: expose operation-group discovery Wei Huang
2026-11-19 20:22 ` [PATCH v1 23/44] dmaengine: sdxi: implement typed vendor admin transport Wei Huang
2026-11-19 20:23 ` [PATCH v1 24/44] dmaengine: sdxi: expose character device attributes Wei Huang
2026-11-19 20:23 ` [PATCH v1 25/44] dmaengine: sdxi: add PF and VF device naming Wei Huang
2026-11-19 20:23 ` [PATCH v1 26/44] dmaengine: sdxi: add SDXI trace events Wei Huang
2026-11-19 20:23 ` [PATCH v1 27/44] dmaengine: sdxi: support suspend and resume Wei Huang
2026-11-19 20:23 ` [PATCH v1 28/44] dmaengine: sdxi: amd: define QoS request formats Wei Huang
2026-11-19 20:23 ` [PATCH v1 29/44] dmaengine: sdxi: amd: add QoS validation scaffolding Wei Huang
2026-11-19 20:23 ` [PATCH v1 30/44] dmaengine: sdxi: amd: build QoS admin descriptors Wei Huang
2026-11-19 20:23 ` [PATCH v1 31/44] dmaengine: sdxi: amd: prevalidate QoS operations Wei Huang
2026-11-19 20:23 ` [PATCH v1 32/44] dmaengine: sdxi: amd: execute QoS vendor operations Wei Huang
2026-11-19 20:23 ` [PATCH v1 33/44] dmaengine: sdxi: amd: register QoS vendor handler Wei Huang
2026-11-19 20:23 ` [PATCH v1 34/44] dmaengine: sdxi: amd: test QoS validation with KUnit Wei Huang
2026-11-19 20:23 ` [PATCH v1 35/44] selftests: sdxi: add build scaffold Wei Huang
2026-11-19 20:23 ` [PATCH v1 36/44] selftests: sdxi: add shared descriptor and context helpers Wei Huang
2026-11-19 20:23 ` [PATCH v1 37/44] selftests: sdxi: test context creation Wei Huang
2026-11-19 20:23 ` [PATCH v1 38/44] selftests: sdxi: test NOP descriptor submission Wei Huang
2026-11-19 20:23 ` [PATCH v1 39/44] selftests: sdxi: test copy submission and ring wrap Wei Huang
2026-11-19 20:23 ` [PATCH v1 40/44] selftests: sdxi: exercise dataplane error paths Wei Huang
2026-11-19 20:23 ` [PATCH v1 41/44] selftests: sdxi: test device ioctls Wei Huang
2026-11-19 20:23 ` [PATCH v1 42/44] selftests: sdxi: test vendor admin ioctls Wei Huang
2026-11-19 20:23 ` [PATCH v1 43/44] selftests: sdxi: test RKey ioctls Wei Huang
2026-11-19 20:23 ` [PATCH v1 44/44] MAINTAINERS: cover SDXI UAPI, vendor files, and selftests Wei Huang
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=20261119202321.1734355-14-wei.huang2@amd.com \
--to=wei.huang2@amd.com \
--cc=Frank.Li@kernel.org \
--cc=John.Kariuki@amd.com \
--cc=Shyam.Iyer@dell.com \
--cc=Stephen.Bates@amd.com \
--cc=bhelgaas@google.com \
--cc=dmaengine@vger.kernel.org \
--cc=jic23@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=mario.limonciello@amd.com \
--cc=nathan.lynch@amd.com \
--cc=rientjes@google.com \
--cc=shuah@kernel.org \
--cc=suravee.suthikulpanit@amd.com \
--cc=tycho@kernel.org \
--cc=vkoul@kernel.org \
--cc=weixugc@google.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®