Linux USB
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: memoriaru@foxmail.com
Cc: linux-usb@vger.kernel.org
Subject: Re: [PATCH usb v2] usb: typec: tcpm: align SOP' Soft Reset handling with SOP
Date: Fri, 20 Nov 2026 18:43:07 +0000	[thread overview]
Message-ID: <sashiko-outbox-225863@kernel.org> (raw)
In-Reply-To: <tencent_3C8B79F98D619AA20768761A53496A7D6E05@qq.com>

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [High] usb: typec: tcpm: SOP' MessageID desync and broken SOP' reset
  in SOFT_RESET
- [Low] usb: typec: tcpm: malformed Fixes SHA, reply chatter, and wrong
  claim in log
--

commit dccd2b15acd9fd37db996886a0767a44d39c3adf
Author: Zhang Hewei <memoriaru@foxmail.com>

> usb: typec: tcpm: align SOP' Soft Reset handling with SOP
>
> Resending as plain text -- the previous two copies went out in HTML
> format and were rejected by the vger list infrastructure. Please use
> this one and disregard the duplicates.
>
> Hi Heikki,
>
> Apologies -- you are right, and thanks for catching it. The patch
> doesn't apply because I generated the diff from inside
> drivers/usb/typec/tcpm/ and shipped it with the short paths (a/tcpm.c
> instead of a/drivers/usb/typec/tcpm/tcpm.c), so git apply fails at the
> root of the tree. I had not verified it with `git apply --check` from
> the top before sending. Lesson taken.
>
> The base itself was the real tree: the index blob bb90211 in the v2
> diff is the master tcpm.c blob, and the two hunks apply cleanly and
> build with the corrected paths. I've verified v3 end to end on a fresh
> master tree: git apply --check passes at the root (forward and
> reverse), and with CONFIG_TYPEC_TCPM=y the patched tcpm.c compiles
> clean (tcpm.o, zero warnings).
>
> The rebased v3 below is content-identical to v2 (same index blob
> bb90211 -- the base was the real tree, only the paths were wrong):
>
> From: Zhang Hewei <memoriaru@foxmail.com>
> Subject: [PATCH usb v3] usb: typec: tcpm: align SOP' Soft Reset handling with SOP
>
> The PD message duplicate-check and the SOFT_RESET state handling treat
> the SOP and SOP' channels differently:
>
> - tcpm_pd_rx_handler() exempts PD_CTRL_SOFT_RESET from the MessageID
>   duplicate check on the SOP path (USB PD spec 6.6.1.2 note: a
>   Soft_Reset message always carries MessageID zero, so the duplicate
>   check must not drop it), but the SOP' branch of the same switch has
>   no such exemption. A cable that sends a second Soft Reset over SOP'
>   (MessageID zero again) has that message silently dropped by the
>   stale rx_msgid_prime comparison, and the cable-side re-negotiation
>   stalls.
>
> - run_state_machine()'s SOFT_RESET case resets message_id/rx_msgid but
>   not message_id_prime/rx_msgid_prime, while the initiator path
>   (SOFT_RESET_SEND, SOP_PRIME branch) resets both counter pairs. After
>   a responder-side soft reset the prime counters stay stale.
>
> Reset the prime counters together with the SOP counters and exempt
> Soft Reset from the SOP' duplicate check, aligning the SOP' handling
> with the SOP path.
>
> Found by code inspection; a software TCPC stub was built for the
> responder path.
>
> Fixes: 6bd181ba60 ("usb: typec: tcpm: add control message support to sop'")
> Cc: stable@vger.kernel.org
> Signed-off-by: Zhang Hewei <memoriaru@foxmail.com>

[Severity: Low]
The mailing-list reply notes and embedded From:/Subject: headers at the top
belong below the "---" separator rather than in the commit changelog.

The Fixes tag also uses a 10-character SHA instead of at least 12
characters:

  Fixes: 6bd181ba60e1 ("usb: typec: tcpm: add control message support to sop'")

Also, is the description of SOFT_RESET_SEND accurate?  In
run_state_machine(), SOFT_RESET_SEND branches on port->tx_sop_type ==
TCPC_TX_SOP_PRIME and resets only message_id_prime/rx_msgid_prime for SOP'
or only message_id/rx_msgid for SOP, not both counter pairs.

> diff --git a/drivers/usb/typec/tcpm/tcpm.c b/drivers/usb/typec/tcpm/tcpm.c
> index bf7fd632d815e..0aa38f1e36bdb 100644
> --- a/drivers/usb/typec/tcpm/tcpm.c
> +++ b/drivers/usb/typec/tcpm.c
> @@ -4206,7 +4206,8 @@ static void tcpm_pd_rx_handler(struct kthread_work *work)
>  		 */
>  		switch (rx_sop_type) {
>  		case TCPC_TX_SOP_PRIME:
> -			if (msgid == port->rx_msgid_prime)
> +			if (msgid == port->rx_msgid_prime &&
> +			    type != PD_CTRL_SOFT_RESET)
>  				goto done;
>  			port->rx_msgid_prime = msgid;
>  			break;
> @@ -6199,6 +6200,8 @@ static void run_state_machine(struct tcpm_port *port)
>  	case SOFT_RESET:
>  		port->message_id = 0;
>  		port->rx_msgid = -1;
> +		port->message_id_prime = 0;
> +		port->rx_msgid_prime = -1;
>  		/* remove existing capabilities */
>  		tcpm_partner_source_caps_reset(port);
>  		tcpm_pd_send_control(port, PD_CTRL_ACCEPT, TCPC_TX_SOP);

[Severity: High]
Does unconditionally resetting port->message_id_prime and
port->rx_msgid_prime in SOFT_RESET desynchronize SOP' MessageID counters
with the cable plug during an SOP Soft Reset, while also mishandling an
incoming SOP' Soft Reset as an SOP reset?

SOP and SOP' maintain independent MessageID counters per USB PD 3.0
sections 6.3.13 and 6.7.1.  When the port partner sends an SOP
PD_CTRL_SOFT_RESET, the cable plug does not process SOP packets and keeps
its existing SOP' MessageID state.  If the port already sent one SOP' VDM
(such as CMD_DISCOVER_IDENT with MessageID 0, advancing
port->message_id_prime to 1 and leaving the cable plug's stored MessageID
at 0), resetting port->message_id_prime to 0 here causes the next SOP'
message to be sent with MessageID 0 again and dropped by the cable plug as
a duplicate.

Conversely, when PD_CTRL_SOFT_RESET arrives on TCPC_TX_SOP_PRIME,
tcpm_pd_ctrl_request() ignores rx_sop_type and enters SOFT_RESET:

drivers/usb/typec/tcpm/tcpm.c:tcpm_pd_ctrl_request() {
    ...
	case PD_CTRL_SOFT_RESET:
		port->ams = SOFT_RESET_AMS;
		tcpm_set_state(port, SOFT_RESET, 0);
		break;
    ...
}

SOFT_RESET then resets the SOP counters, clears partner source capabilities
and port->explicit_contract, sends PD_CTRL_ACCEPT on TCPC_TX_SOP instead of
TCPC_TX_SOP_PRIME, and restarts SOP power negotiation rather than
acknowledging the cable plug on SOP' and returning to ready_state(port).

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/tencent_3C8B79F98D619AA20768761A53496A7D6E05@qq.com?part=1

  reply	other threads:[~2026-11-20 18:43 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-13 22:20 [PATCH usb] usb: typec: tcpm: align SOP' Soft Reset handling with SOP memoriaru
2026-11-17 11:27 ` Heikki Krogerus
2026-11-17 11:36   ` [PATCH usb v2] " memoriaru
2026-11-20 13:16     ` Heikki Krogerus
2026-11-20 18:34       ` memoriaru
2026-11-20 18:43         ` sashiko-bot [this message]
2026-11-20 19:25       ` memoriaru
     [not found]       ` <1795204200.cover.tcpm-v4@foxmail.com>
2026-11-20 19:25         ` [PATCH usb v4] usb: typec: tcpm: exempt Soft Reset from the SOP' MessageID duplicate check memoriaru

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-225863@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=memoriaru@foxmail.com \
    --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