From: sashiko-bot@kernel.org
To: "Jie Gan" <jie.gan@oss.qualcomm.com>
Cc: devicetree@vger.kernel.org, robh@kernel.org, conor+dt@kernel.org
Subject: Re: [PATCH RFC 2/6] soc: qcom: add QDCP firmware provider
Date: Thu, 19 Nov 2026 09:18:07 +0000 [thread overview]
Message-ID: <sashiko-outbox-222809@kernel.org> (raw)
In-Reply-To: <20261119-introduce-qcom-qecp-feature-v1-2-b1a730d2c57a@oss.qualcomm.com>
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [High] soc: qcom: qdcp_send_resp() callers pass struct size as QMI
wire length
- [Medium] soc: qcom: devm_qdcp_get() races with provider unbind after
unlock
--
commit 0767c9931547d43da1782dd32902fb9f2ad363f7
Author: Jie Gan <jie.gan@oss.qualcomm.com>
soc: qcom: add QDCP firmware provider
This commit adds a QMI service provider driver for the Qualcomm Debug
Control Protocol (QDCP) so consumer drivers can enable, disable, and
query QECP firmware-owned debug and trace blocks.
> diff --git a/drivers/soc/qcom/qcom_qdcp.c b/drivers/soc/qcom/qcom_qdcp.c
> new file mode 100644
> index 0000000000000..295138b298819
> --- /dev/null
> +++ b/drivers/soc/qcom/qcom_qdcp.c
> @@ -0,0 +1,985 @@
[ ... ]
> +static int qdcp_send_resp(struct qdcp_data *qdcp, unsigned int msg_id,
> + const struct qmi_elem_info *req_ei, const void *req,
> + size_t req_len, const struct qmi_elem_info *resp_ei,
> + void *resp, size_t resp_len)
> +{
[ ... ]
> + ret = qmi_send_request(&qdcp->qmi, &sq, &txn, msg_id, req_len, req_ei,
> + req);
> + if (ret < 0) {
> + qmi_txn_cancel(&txn);
> + return ret;
> + }
> +
> + ret = qmi_txn_wait(&txn, msecs_to_jiffies(QDCP_TIMEOUT_MS));
> + if (ret < 0)
> + return ret;
> +
> + return qdcp_check_resp(qdcp, qmi_resp);
> +}
> +
> +static int qdcp_send(struct qdcp_data *qdcp, unsigned int msg_id,
> + const struct qmi_elem_info *req_ei, const void *req,
> + size_t req_len, struct qdcp_resp_v01 *resp)
> +{
> + return qdcp_send_resp(qdcp, msg_id, req_ei, req, req_len, qdcp_resp_ei,
> + resp, sizeof(*resp));
> +}
> +
> +static int qdcp_set_state(struct qdcp_data *qdcp, unsigned int msg_id,
> + u64 id, bool enable)
> +{
> + struct qdcp_state_req_v01 req = {
> + .id = id,
> + .state = enable,
> + };
> + struct qdcp_resp_v01 resp;
> +
> + return qdcp_send(qdcp, msg_id, qdcp_state_req_ei, &req, sizeof(req),
> + &resp);
> +}
[Severity: High]
Does passing sizeof(req) as req_len cause qmi_send_request() to fail with
-ETOOSMALL across all QDCP requests?
qmi_send_request() passes req_len to qmi_encode_message() as the maximum
encoded wire payload length, and each top-level TLV adds a 3-byte TLV
header (1-byte type + 2-byte length) to the field payload. For example,
struct qdcp_state_req_v01 is 16 bytes, whereas qdcp_state_req_ei encodes
two top-level TLVs totaling (3 + 8) + (3 + 4) = 18 bytes. Because
qdcp_set_state(), qdcp_stm_source_enable(), qdcp_tmc_set_param(),
qdcp_tmc_get_param(), and qdcp_tmc_assign_buffer() all pass sizeof(req),
every exported QDCP operation fails in qmi_encode() with -ETOOSMALL.
> +struct qdcp_devres {
> + struct qdcp_data *qdcp;
> +};
> +
> +static void qdcp_release_provider(void *data)
> +{
> + struct qdcp_devres *devres = data;
> +
> + put_device(devres->qdcp->dev);
> + kref_put(&devres->qdcp->ref, qdcp_release);
> +}
> +
> +struct qdcp_data *devm_qdcp_get(struct device *dev, const char *phandle_name)
> +{
> + struct qdcp_devres *devres;
> + struct device_link *link;
> + struct qdcp_data *qdcp;
> + struct device_node *np;
> + int ret;
> +
> + if (!dev->of_node)
> + return ERR_PTR(-ENOENT);
> +
> + np = of_parse_phandle(dev->of_node, phandle_name, 0);
> + if (!np)
> + return ERR_PTR(-ENOENT);
> +
> + mutex_lock(&qdcp_providers_lock);
> + list_for_each_entry(qdcp, &qdcp_providers, node) {
> + if (qdcp->of_node != np || qdcp->dying)
> + continue;
> +
> + if (!kref_get_unless_zero(&qdcp->ref))
> + continue;
> +
> + get_device(qdcp->dev);
> + mutex_unlock(&qdcp_providers_lock);
> + of_node_put(np);
> +
> + /*
> + * A managed link with DL_FLAG_AUTOREMOVE_CONSUMER (i.e. no
> + * DL_FLAG_STATELESS) is required so that the driver core's
> + * device_links_busy()/device_links_unbind_consumers()
> + * machinery forces this consumer to unbind before
> + * qdcp_remove() can proceed on the supplier, and so the link
> + * itself is dropped automatically by the core when this
> + * consumer unbinds or fails to probe. A stateless link
> + * carries neither guarantee: qdcp_remove() could release the
> + * QMI handle while a consumer still has outstanding or
> + * in-flight QDCP RPCs, and device_link_del() refuses to drop
> + * a non-stateless link while the consumer is still
> + * registered, which is always the case from inside a devm
> + * release callback.
> + */
> + link = device_link_add(dev, qdcp->dev,
> + DL_FLAG_AUTOREMOVE_CONSUMER);
> + if (!link) {
> + put_device(qdcp->dev);
> + kref_put(&qdcp->ref, qdcp_release);
> + return ERR_PTR(-EINVAL);
> + }
> +
> + /*
> + * The core still creates a link to a supplier that is already
> + * unbinding, and will not unbind this consumer for it. Defer
> + * rather than bind to a provider that is going away.
> + */
> + if (READ_ONCE(link->status) == DL_STATE_SUPPLIER_UNBIND) {
> + put_device(qdcp->dev);
> + kref_put(&qdcp->ref, qdcp_release);
> + return ERR_PTR(-EPROBE_DEFER);
> + }
[Severity: Medium]
Can devm_qdcp_get() still race with provider unbind after dropping
qdcp_providers_lock?
CPU0 CPU1
devm_qdcp_get()
mutex_lock(&qdcp_providers_lock)
/* finds qdcp, !qdcp->dying */
mutex_unlock(&qdcp_providers_lock)
__device_release_driver(qdcp->dev)
qdcp_remove()
qdcp->dying = true
qmi_handle_release(&qdcp->qmi)
device_links_driver_cleanup()
supplier->links.status =
DL_DEV_NO_DRIVER
device_link_add(dev, qdcp->dev,
DL_FLAG_AUTOREMOVE_CONSUMER)
/* link->status = DL_STATE_DORMANT */
if (link->status ==
DL_STATE_SUPPLIER_UNBIND)
/* false, returns dead qdcp */
...
device_links_driver_bound()
WARN_ON(link->status !=
DL_STATE_CONSUMER_PROBE) <-- warning & bound to dead provider
If the supplier finishes unbinding in the window between dropping
qdcp_providers_lock and calling device_link_add(), supplier->links.status
is already DL_DEV_NO_DRIVER, so device_link_init_status() initializes
link->status to DL_STATE_DORMANT rather than DL_STATE_SUPPLIER_UNBIND.
devm_qdcp_get() then succeeds on a provider whose QMI handle was released
and triggers WARN_ON(link->status != DL_STATE_CONSUMER_PROBE) in
device_links_driver_bound().
Even when device_link_add() runs while the supplier is still in
DL_DEV_UNBINDING (setting link->status to DL_STATE_SUPPLIER_UNBIND), the
new DL_FLAG_AUTOREMOVE_CONSUMER link stays on supplier->links.consumers
until the consumer's probe failure path runs device_links_no_driver(), so
device_links_driver_cleanup() on the supplier can win the race and hit
WARN_ON(device_link_test(link, DL_FLAG_AUTOREMOVE_CONSUMER)).
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261119-introduce-qcom-qecp-feature-v1-0-b1a730d2c57a@oss.qualcomm.com?part=2
next prev parent reply other threads:[~2026-11-19 9:18 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-19 9:01 [PATCH RFC 0/6] Coresight: Introduce Qualcomm QDCP support for QECP-owned trace blocks Jie Gan
2026-11-19 9:01 ` [PATCH RFC 1/6] dt-bindings: soc: qcom: add QDCP provider Jie Gan
2026-11-19 9:12 ` sashiko-bot
2026-11-19 14:00 ` Krzysztof Kozlowski
2026-11-19 9:01 ` [PATCH RFC 2/6] soc: qcom: add QDCP firmware provider Jie Gan
2026-11-19 9:18 ` sashiko-bot [this message]
2026-11-19 9:01 ` [PATCH RFC 3/6] dt-bindings: arm: qcom: add QDCP STM source Jie Gan
2026-11-19 14:02 ` Krzysztof Kozlowski
2026-11-19 9:01 ` [PATCH RFC 4/6] coresight: " Jie Gan
2026-11-19 9:28 ` sashiko-bot
2026-11-19 9:01 ` [PATCH RFC 5/6] dt-bindings: arm: qcom: add QDCP TMC ETR sink Jie Gan
2026-11-19 9:01 ` [PATCH RFC 6/6] coresight: tmc: add QDCP ETR sysfs support Jie Gan
2026-11-19 9:25 ` sashiko-bot
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-222809@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=jie.gan@oss.qualcomm.com \
--cc=robh@kernel.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 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.