From: Heikki Krogerus <heikki.krogerus@linux.intel.com>
To: RD Babiera <rdbabiera@google.com>
Cc: linux@roeck-us.net, gregkh@linuxfoundation.org,
hdegoede@redhat.com, badhri@google.com,
linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org,
stable@vger.kernel.org
Subject: Re: [PATCH v1] usb: typec: tcpm: enforce ready state when queueing alt mode vdm
Date: Thu, 25 Apr 2024 12:49:17 +0300 [thread overview]
Message-ID: <ZionHYcUvvc865z4@kuha.fi.intel.com> (raw)
In-Reply-To: <20240423202356.3372314-2-rdbabiera@google.com>
On Tue, Apr 23, 2024 at 08:23:57PM +0000, RD Babiera wrote:
> Before sending Enter Mode for an Alt Mode, there is a gap between Discover
> Modes and the Alt Mode driver queueing the Enter Mode VDM for the port
> partner to send a message to the port.
>
> If this message results in unregistering Alt Modes such as in a DR_SWAP,
> then the following deadlock can occur with respect to the DisplayPort Alt
> Mode driver:
> 1. The DR_SWAP state holds port->lock. Unregistering the Alt Mode driver
> results in a cancel_work_sync() that waits for the current dp_altmode_work
> to finish.
> 2. dp_altmode_work makes a call to tcpm_altmode_enter. The deadlock occurs
> because tcpm_queue_vdm_unlock attempts to hold port->lock.
>
> Before attempting to grab the lock, ensure that the port is in a state
> vdm_run_state_machine can run in. Alt Mode unregistration will not occur
> in these states.
I'm probable missing something, but wouldn't it be safer to check
port->state after grabbing the lock?
> Fixes: 03eafcfb60c0 ("usb: typec: tcpm: Add tcpm_queue_vdm_unlocked() helper")
> Cc: stable@vger.kernel.org
> Signed-off-by: RD Babiera <rdbabiera@google.com>
> ---
> drivers/usb/typec/tcpm/tcpm.c | 4 ++++
> 1 file changed, 4 insertions(+)
>
> diff --git a/drivers/usb/typec/tcpm/tcpm.c b/drivers/usb/typec/tcpm/tcpm.c
> index c26fb70c3ec6..6fa1601ac259 100644
> --- a/drivers/usb/typec/tcpm/tcpm.c
> +++ b/drivers/usb/typec/tcpm/tcpm.c
> @@ -1564,6 +1564,10 @@ static void tcpm_queue_vdm(struct tcpm_port *port, const u32 header,
> static void tcpm_queue_vdm_unlocked(struct tcpm_port *port, const u32 header,
> const u32 *data, int cnt, enum tcpm_transmit_type tx_sop_type)
> {
> + if (port->state != SRC_READY && port->state != SNK_READY &&
> + port->state != SRC_VDM_IDENTITY_REQUEST)
> + return;
> +
> mutex_lock(&port->lock);
> tcpm_queue_vdm(port, header, data, cnt, TCPC_TX_SOP);
> mutex_unlock(&port->lock);
>
> base-commit: 684e9f5f97eb4b7831298ffad140d5c1d426ff27
> --
> 2.44.0.769.g3c40516874-goog
--
heikki
next prev parent reply other threads:[~2024-04-25 9:49 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-23 20:23 [PATCH v1] usb: typec: tcpm: enforce ready state when queueing alt mode vdm RD Babiera
2024-04-25 9:49 ` Heikki Krogerus [this message]
2024-04-25 17:37 ` RD Babiera
2024-04-29 8:18 ` Heikki Krogerus
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=ZionHYcUvvc865z4@kuha.fi.intel.com \
--to=heikki.krogerus@linux.intel.com \
--cc=badhri@google.com \
--cc=gregkh@linuxfoundation.org \
--cc=hdegoede@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=linux@roeck-us.net \
--cc=rdbabiera@google.com \
--cc=stable@vger.kernel.org \
/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