From: sashiko-bot@kernel.org
To: "Badal Nilawar" <badal.nilawar@intel.com>,
intel-xe@lists.freedesktop.org
Subject: Re: [PATCH 4/5] drm/xe/i2c: Expose AMC alert reason through sysfs
Date: Fri, 27 Nov 2026 06:30:55 +0000 [thread overview]
Message-ID: <sashiko-outbox-236738@kernel.org> (raw)
In-Reply-To: <20261127061333.1019047-11-badal.nilawar@intel.com>
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] drm/xe/amc: sysfs attribute name mismatch with ABI
documentation
- [Low] drm/xe/amc: missing memory barriers between alert_reason and
alert_seen
It also noticed 1 related pre-existing issue this patch does not
introduce:
- [Critical] drm/xe: use-after-free in xe_amc_handle_alert() [1]
--
commit b8f40abebebf63a2b3f28d9c10f02b5465a7edf7
Author: Badal Nilawar <badal.nilawar@intel.com>
drm/xe/i2c: Expose AMC alert reason through sysfs
This commit exposes the most recent AMC alert reason through a read-only
device sysfs attribute and documents the new ABI.
> diff --git a/Documentation/ABI/testing/sysfs-driver-intel-xe-amc b/Documentation/ABI/testing/sysfs-driver-intel-xe-amc
> new file mode 100644
> index 0000000000000..8c2731cfa91c9
> --- /dev/null
> +++ b/Documentation/ABI/testing/sysfs-driver-intel-xe-amc
> @@ -0,0 +1,24 @@
> +What: /sys/bus/pci/drivers/xe/.../xe_amc_alert_reason
[ ... ]
> diff --git a/drivers/gpu/drm/xe/xe_amc.c b/drivers/gpu/drm/xe/xe_amc.c
> index b0e9250fa9719..a619346a3451b 100644
> --- a/drivers/gpu/drm/xe/xe_amc.c
> +++ b/drivers/gpu/drm/xe/xe_amc.c
[ ... ]
> @@ -107,6 +110,50 @@ static const struct amc_request amc_get_alert_reason = {
> },
> };
>
> +/**
> + * DOC: AMC Alert Reason
> + *
> + * Expose the most recent AMC alert reason through device sysfs.
> + *
> + * See Documentation/ABI/testing/sysfs-driver-intel-xe-amc for the ABI
> + * specification.
> + */
> +
> +static enum xe_amc_alert amc_alert_reason(struct xe_amc *amc)
> +{
> + return READ_ONCE(amc->alert_reason);
> +}
> +
> +static ssize_t amc_alert_reason_show(struct device *dev,
> + struct device_attribute *attr, char *buf)
> +{
> + struct xe_device *xe = pdev_to_xe_device(to_pci_dev(dev));
> + struct xe_amc *amc = xe->i2c->amc;
> + enum xe_amc_alert alert_reason;
> +
> + if (!READ_ONCE(amc->alert_seen))
> + return sysfs_emit(buf, "none\n");
> +
> + alert_reason = amc_alert_reason(amc);
> +
> + return sysfs_emit(buf, "%s\n", amc_alert[alert_reason]);
> +}
> +static DEVICE_ATTR_RO(amc_alert_reason);
[Severity: Medium]
Should the sysfs attribute name match the ABI documentation?
DEVICE_ATTR_RO(amc_alert_reason) creates "amc_alert_reason", whereas
Documentation/ABI/testing/sysfs-driver-intel-xe-amc documents
"xe_amc_alert_reason", so userspace tools looking up the documented path
will fail with -ENOENT.
[ ... ]
> @@ -156,11 +203,15 @@ static void xe_amc_work(struct work_struct *work)
> }
>
> alert_reason = response.value;
> - dev_dbg(&client->dev, "Alert reason: %d\n", alert_reason);
> + dev_dbg(&client->dev, "Alert reason: %u\n", (unsigned int)alert_reason);
>
> out_reassert_interrupt:
> xe_mmio_rmw32(amc->i2c->mmio, I2C_CONFIG_CMD, PCI_COMMAND_INTX_DISABLE, 0);
>
> + WRITE_ONCE(amc->alert_reason, alert_reason < ARRAY_SIZE(amc_alert) ?
> + alert_reason : AMC_ALERT_UNKNOWN);
> + WRITE_ONCE(amc->alert_seen, true);
[Severity: Low]
Can amc_alert_reason_show() observe amc->alert_seen as true before the
store to amc->alert_reason becomes visible on weakly-ordered architectures?
READ_ONCE() and WRITE_ONCE() do not enforce CPU memory ordering across
distinct variables, so a concurrent sysfs read racing with the first alert
can transiently read the initial zero value (AMC_ALERT_UNKNOWN) and report
"unknown" instead of "none" or the actual reason. Pairing
smp_store_release(&amc->alert_seen, true) with
smp_load_acquire(&amc->alert_seen) would order the accesses.
[ ... ]
> @@ -202,13 +255,21 @@ int xe_amc_init(struct xe_i2c *i2c)
> i2c->amc = amc;
> amc->i2c = i2c;
>
> - return 0;
> + ret = amc_create_alert_sysfs(i2c);
> + if (ret) {
> + kfree(i2c->amc);
> + i2c->amc = NULL;
> + }
> +
> + return ret;
> }
>
> void xe_amc_exit(struct xe_i2c *i2c)
> {
> if (i2c->amc) {
> + amc_remove_alert_sysfs(i2c);
> cancel_work_sync(&i2c->amc->work);
> kfree(i2c->amc);
> + i2c->amc = NULL;
> }
> }
[Severity: Critical]
This problem wasn't introduced by this patch, but can xe_amc_exit() race
with an in-flight SMBus alert interrupt and cause a use-after-free in
xe_amc_handle_alert() [1]?
In xe_i2c_remove(), xe_i2c_irq_reset() disables hardware interrupts and
immediately calls xe_amc_exit() without waiting for in-flight interrupt
handlers to finish:
drivers/gpu/drm/xe/xe_i2c.c:xe_i2c_handle_smbus_alert() {
...
if (stat & DW_IC_SMBUS_INTR_ALERT && i2c->amc)
xe_amc_handle_alert(i2c);
}
CPU0 CPU1
xe_i2c_remove()
xe_i2c_irq_reset()
xe_i2c_handle_smbus_alert()
if (... && i2c->amc)
xe_amc_exit()
cancel_work_sync(&i2c->amc->work)
kfree(i2c->amc)
i2c->amc = NULL
xe_amc_handle_alert()
queue_work(..., &i2c->amc->work)
<-- use-after-free
Queuing the freed work_struct corrupts the workqueue lists and crashes the
kernel. Synchronizing the IRQ after xe_i2c_irq_reset() before running
xe_amc_exit() would prevent the handler from racing with teardown.
[1] https://sashiko.dev/#/bug/linux-e2bb2e7e-d158-4981-a226-338921893668
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261127061333.1019047-7-badal.nilawar@intel.com?part=4
next prev parent reply other threads:[~2026-11-27 6:31 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-27 6:13 [PATCH 0/5] Process AMC alert Badal Nilawar
2026-11-27 6:13 ` [PATCH 1/5] drm/xe: Request cold-reset recovery on AMC thermal trip alert Badal Nilawar
2026-11-27 6:13 ` [PATCH 2/5] drm/xe: Request cold-reset recovery on AMC OOB request alert Badal Nilawar
2026-11-27 6:13 ` [PATCH 3/5] drm/xe: Request cold-reset recovery on AMC CATERR alert Badal Nilawar
2026-11-27 6:13 ` [PATCH 4/5] drm/xe/i2c: Expose AMC alert reason through sysfs Badal Nilawar
2026-11-27 6:30 ` sashiko-bot [this message]
2026-11-27 6:13 ` [PATCH 5/5] drm/xe: Request vendor recovery for AMC firmware download alert Badal Nilawar
2026-11-27 6:23 ` sashiko-bot
2026-11-27 6:58 ` ✗ CI.checkpatch: warning for Process AMC alert Patchwork
2026-11-27 7:00 ` ✓ CI.KUnit: success " 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=sashiko-outbox-236738@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=badal.nilawar@intel.com \
--cc=intel-xe@lists.freedesktop.org \
--cc=sashiko-reviews@lists.linux.dev \
/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