All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Yongxin Yang" <yangyongxin@kylinos.cn>
Cc: linux-cxl@vger.kernel.org
Subject: Re: [PATCH v9] cxl/core: Create EINJ debugfs files when EINJ is initialized
Date: Thu, 03 Dec 2026 07:16:59 +0000	[thread overview]
Message-ID: <sashiko-outbox-247273@kernel.org> (raw)
In-Reply-To: <20261203065904.1554483-1-yangyongxin@kylinos.cn>

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] cxl/core: missing root host lock in
  cxl_einj_debugfs_create_dport_dirs()
- [Low] ACPI: APEI: EINJ: undocumented constraints on
  einj_cxl_register_ready_cb()
--

commit 63612c001bb6f8f3cf3912f918dc83156766933d
Author: Yongxin Yang <yangyongxin@kylinos.cn>

cxl/core: Create EINJ debugfs files when EINJ is initialized

This commit defers CXL EINJ debugfs file creation to a callback invoked
once EINJ is initialized, and walks cxl_bus_type to create any dport
debugfs directories that were skipped before EINJ came up.

Link: https://lore.kernel.org/all/20261104061256.1449275-1-yangyongxin@kylinos.cn/

> diff --git a/drivers/acpi/apei/einj-cxl.c b/drivers/acpi/apei/einj-cxl.c
> index e70a416ec9256..93003fe4527e6 100644
> --- a/drivers/acpi/apei/einj-cxl.c
> +++ b/drivers/acpi/apei/einj-cxl.c
[ ... ]
> +static void (*einj_cxl_ready_cb)(void);
> +
> +/**
> + * einj_cxl_register_ready_cb - run a callback once EINJ is initialized
> + * @cb: callback to invoke, or NULL to cancel a pending registration
> + *
> + * cxl_core cannot tell at init time whether EINJ will come up.  If EINJ is
> + * already initialized, @cb runs immediately.
> + */
> +void einj_cxl_register_ready_cb(void (*cb)(void))
> +{
> +	if (cb && einj_cxl_is_initialized()) {
> +		cb();
> +		return;
> +	}
> +
> +	einj_cxl_ready_cb = cb;
> +}
> +EXPORT_SYMBOL_NS_GPL(einj_cxl_register_ready_cb, "CXL");

[Severity: Low]
Should the kernel-doc for einj_cxl_register_ready_cb() document its
single-registrant and serialization constraints?

Because it is exported and updates an unlocked global pointer without
checking whether one is already registered, a second caller would silently
overwrite the existing callback, and callers rely on initcall and module
dependency ordering to avoid racing with einj_cxl_notify_ready().

[ ... ]

> diff --git a/drivers/cxl/core/port.c b/drivers/cxl/core/port.c
> index 625e4aa427db0..4f6137651ca4c 100644
> --- a/drivers/cxl/core/port.c
> +++ b/drivers/cxl/core/port.c
[ ... ]
> +static int cxl_einj_debugfs_create_dport_dirs(struct device *dev, void *data)
> +{
> +	struct cxl_dport *dport;
> +	struct cxl_port *port;
> +	unsigned long index;
> +
> +	if (!is_cxl_port(dev))
> +		return 0;
> +
> +	port = to_cxl_port(dev);
> +
> +	guard(device)(dev);
> +	xa_for_each(&port->dports, index, dport)
> +		cxl_debugfs_create_dport_dir(dport);
> +
> +	return 0;
> +}

[Severity: Medium]
Can iterating port->dports under only device_lock(&port->dev) race with
root-port dport teardown and cause a use-after-free on struct cxl_dport?

For a CXL root port, dport_to_host() hosts cxl_dport_remove() and
free_dport() on port->uport_dev rather than &port->dev, and
__devm_cxl_add_dport() drops &port->dev right after add_dport().  With
driver_async_probe, cxl_acpi_probe() can run alongside einj_init():

CPU0 (cxl_acpi_probe)             CPU1 (einj_init)
device_lock(port->uport_dev)
__devm_cxl_add_dport()
  cond_cxl_root_lock(port)
  add_dport(port, dport)
  cond_cxl_root_unlock(port)
                                  cxl_einj_debugfs_create_dport_dirs()
                                    guard(device)(&port->dev)
                                    xa_for_each(&port->dports, ..., dport)
                                      cxl_debugfs_create_dport_dir(dport)
probe fails -> devres unwind
  cxl_dport_remove(dport)
  free_dport(dport) -> kfree()
                                        debugfs_create_file(..., dport, ...)
                                          <-- use-after-free

This dereferences a freed dport and can leave einj_inject pointing to freed
memory.  Because __devm_cxl_add_dport() also creates the debugfs directory
without &port->dev held, both threads can race past debugfs_lookup() and
collide creating the same directory for a CXL 1.1 RCH dport.

Acquiring guard(device)(port_to_host(port)) before guard(device)(dev), as
find_or_add_dport() does, would serialize against root-port dport setup,
debugfs creation, and devres teardown.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261203065904.1554483-1-yangyongxin@kylinos.cn?part=1

      reply	other threads:[~2026-12-03  7:17 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-03  6:59 [PATCH v9] cxl/core: Create EINJ debugfs files when EINJ is initialized Yongxin Yang
2026-12-03  7:16 ` sashiko-bot [this message]

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-247273@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=linux-cxl@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=yangyongxin@kylinos.cn \
    /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.