From: "Christian A. Ehrhardt" <lk@c--e.de>
To: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
Cc: linux-kernel@vger.kernel.org,
"Heikki Krogerus" <heikki.krogerus@linux.intel.com>,
"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
"Prashant Malani" <pmalani@chromium.org>,
"Jameson Thies" <jthies@google.com>,
"Abhishek Pandit-Subedi" <abhishekpandit@chromium.org>,
"Neil Armstrong" <neil.armstrong@linaro.org>,
"Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>,
"Samuel Čavoj" <samuel@cavoj.net>,
linux-usb@vger.kernel.org, "Kenneth Crudup" <kenny@panix.com>
Subject: Re: [PATCH 2/5] usb: typec: ucsi: Check for notifications after init
Date: Mon, 1 Apr 2024 22:11:08 +0200 [thread overview]
Message-ID: <ZgsU3HsfDJzjPCWA@cae.in-ulm.de> (raw)
In-Reply-To: <ZgbqdBd1OiWgDN-_@eriador.lumag.spb.ru>
Hi,
On Fri, Mar 29, 2024 at 06:21:08PM +0200, Dmitry Baryshkov wrote:
> On Wed, Mar 20, 2024 at 08:39:23AM +0100, Christian A. Ehrhardt wrote:
> > The completion notification for the final SET_NOTIFICATION_ENABLE
> > command during initialization can include a connector change
> > notification. However, at the time this completion notification is
> > processed, the ucsi struct is not ready to handle this notification.
> > As a result the notification is ignored and the controller
> > never sends an interrupt again.
> >
> > Re-check CCI for a pending connector state change after
> > initialization is complete. Adjust the corresponding debug
> > message accordingly.
> >
> > Fixes: 71a1fa0df2a3 ("usb: typec: ucsi: Store the notification mask")
> > Cc: stable@vger.kernel.org
> > Signed-off-by: Christian A. Ehrhardt <lk@c--e.de>
> > ---
> > drivers/usb/typec/ucsi/ucsi.c | 10 +++++++++-
> > 1 file changed, 9 insertions(+), 1 deletion(-)
> >
> > diff --git a/drivers/usb/typec/ucsi/ucsi.c b/drivers/usb/typec/ucsi/ucsi.c
> > index 8a6645ffd938..dceeed207569 100644
> > --- a/drivers/usb/typec/ucsi/ucsi.c
> > +++ b/drivers/usb/typec/ucsi/ucsi.c
> > @@ -1237,7 +1237,7 @@ void ucsi_connector_change(struct ucsi *ucsi, u8 num)
> > struct ucsi_connector *con = &ucsi->connector[num - 1];
> >
> > if (!(ucsi->ntfy & UCSI_ENABLE_NTFY_CONNECTOR_CHANGE)) {
> > - dev_dbg(ucsi->dev, "Bogus connector change event\n");
> > + dev_dbg(ucsi->dev, "Early connector change event\n");
> > return;
> > }
> >
> > @@ -1636,6 +1636,7 @@ static int ucsi_init(struct ucsi *ucsi)
> > {
> > struct ucsi_connector *con, *connector;
> > u64 command, ntfy;
> > + u32 cci;
> > int ret;
> > int i;
> >
> > @@ -1688,6 +1689,13 @@ static int ucsi_init(struct ucsi *ucsi)
> >
> > ucsi->connector = connector;
> > ucsi->ntfy = ntfy;
> > +
> > + ret = ucsi->ops->read(ucsi, UCSI_CCI, &cci, sizeof(cci));
> > + if (ret)
> > + return ret;
> > + if (UCSI_CCI_CONNECTOR(READ_ONCE(cci)))
> > + ucsi_connector_change(ucsi, cci);
> > +
>
> I think this leaves place for the race. With this patchset + "Ack
> connector change early" in place Neil triggered the following backtrace
> on sm8550 HDK while testing my UCSI-qcom-fixes patchset:
Sorry, but this seems to be a brown paper bag change.
- The READ_ONCE is bogus and a remnant of a prevoius verion of the
change.
- Calling ->read should probably be done with the PPM lock held.
- The argument to ucsi_connector_change() must be
UCSI_CCI_CONNECTOR(cci) instead of the plain cci.
I'll send a fix.
> What happens:
[ ... ]
>
> [ 10.595807] ------------[ cut here ]------------
> [ 10.595808] WARNING: CPU: 6 PID: 101 at kernel/workqueue.c:2384 __queue_work+0x374/0x474
>
> [skipped the register dump]
>
> [ 10.595953] __queue_work+0x374/0x474
> [ 10.595956] queue_work_on+0x68/0x84
> [ 10.595959] ucsi_connector_change+0x54/0x88 [typec_ucsi]
> [ 10.595963] ucsi_init_work+0x834/0x85c [typec_ucsi]
> [ 10.595968] process_one_work+0x148/0x29c
> [ 10.595971] worker_thread+0x2fc/0x40c
> [ 10.595974] kthread+0x110/0x114
> [ 10.595978] ret_from_fork+0x10/0x20
> [ 10.595985] ---[ end trace 0000000000000000 ]---
>
> Warning, because the work is already scheduled.
No, the reason is the wrong connector number. Scheduling a work that
is already scheduled is fine.
Best regards
Christian
next prev parent reply other threads:[~2024-04-01 20:11 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-20 7:39 [PATCH 0/5] Fix various races in UCSI Christian A. Ehrhardt
2024-03-20 7:39 ` [PATCH 1/5] usb: typec: ucsi: Clear EVENT_PENDING under PPM lock Christian A. Ehrhardt
2024-03-22 9:53 ` Heikki Krogerus
2024-03-20 7:39 ` [PATCH 2/5] usb: typec: ucsi: Check for notifications after init Christian A. Ehrhardt
2024-03-22 9:54 ` Heikki Krogerus
2024-03-29 16:21 ` Dmitry Baryshkov
2024-04-01 20:11 ` Christian A. Ehrhardt [this message]
2024-03-20 7:39 ` [PATCH 3/5] usb: typec: ucsi: Ack unsupported commands Christian A. Ehrhardt
2024-03-22 10:04 ` Heikki Krogerus
2024-03-20 7:39 ` [PATCH 4/5] usb: typec: ucsi_acpi: Refactor and fix DELL quirk Christian A. Ehrhardt
2024-03-22 10:00 ` Heikki Krogerus
2024-03-20 7:39 ` [PATCH 5/5] usb: typec: ucsi: Clear UCSI_CCI_RESET_COMPLETE before reset Christian A. Ehrhardt
2024-03-22 10:06 ` Heikki Krogerus
2024-12-15 18:34 ` Sasha Levin
2024-12-16 21:47 ` Christian A. Ehrhardt
2024-12-17 4:24 ` Gopal, Saranya
2024-12-18 13:58 ` Gopal, Saranya
2025-01-19 13:23 ` Fedor Pchelkin
2025-01-22 21:11 ` Christian A. Ehrhardt
2025-01-28 13:58 ` Fedor Pchelkin
2025-01-28 14:04 ` Fedor Pchelkin
2024-03-20 10:53 ` [PATCH 0/5] Fix various races in UCSI Kenneth Crudup
2024-03-22 10:57 ` Neil Armstrong
2024-03-22 10:02 ` 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=ZgsU3HsfDJzjPCWA@cae.in-ulm.de \
--to=lk@c--e.de \
--cc=abhishekpandit@chromium.org \
--cc=dmitry.baryshkov@linaro.org \
--cc=gregkh@linuxfoundation.org \
--cc=heikki.krogerus@linux.intel.com \
--cc=jthies@google.com \
--cc=kenny@panix.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=neil.armstrong@linaro.org \
--cc=pmalani@chromium.org \
--cc=samuel@cavoj.net \
--cc=u.kleine-koenig@pengutronix.de \
/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