Linux USB
 help / color / mirror / Atom feed
From: Thinh Nguyen <Thinh.Nguyen@synopsys.com>
To: Konrad Dybcio <konradybcio@kernel.org>
Cc: Thinh Nguyen <Thinh.Nguyen@synopsys.com>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Jiazi Liu <jiazi.liu1984@gmail.com>,
	Wesley Cheng <quic_wcheng@quicinc.com>,
	Felipe Balbi <balbi@kernel.org>,
	"linux-usb@vger.kernel.org" <linux-usb@vger.kernel.org>,
	Konrad Dybcio <konrad.dybcio@oss.qualcomm.com>
Subject: Re: [PATCH v2 1/4] usb: dwc3: gadget: serialize connection bitfield writes
Date: Fri, 4 Dec 2026 20:43:13 +0000	[thread overview]
Message-ID: <axMYY_wcDy-kNSJB@vbox> (raw)
In-Reply-To: <20261126-topic-usb_dwc3_fixups-v2-1-c0cc2b75c518@oss.qualcomm.com>

On Thu, Nov 26, 2026, Konrad Dybcio wrote:
> From: Konrad Dybcio <konrad.dybcio@oss.qualcomm.com>
> 
> softconnect and pullups_connected are bitfields that share their storage
> with dwc->connected, which is written under dwc->lock from IRQ context.
> Unprotected writes to these bitfields can race with the IRQ's updates to
> the shared storage.

dwc->pending_events shares the same storage and is written without
dwc->lock from hard IRQ in dwc3_check_event_buf(), so locking alone is
not enough.

> 
> Take dwc->lock around the softconnect assignment in dwc3_gadget_pullup()
> and the pullups_connected assignments in dwc3_gadget_run_stop().
> 

Can we just change them to bool instead? This avoids adding the extra
locking.

diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h
index 294d2736cd28..e9d1727be23c 100644
--- a/drivers/usb/dwc3/core.h
+++ b/drivers/usb/dwc3/core.h
@@ -1394,8 +1394,8 @@ struct dwc3 {
 
 	const char		*hsphy_interface;
 
-	unsigned		connected:1;
-	unsigned		softconnect:1;
+	bool			connected;
+	bool			softconnect;
 	unsigned		delayed_status:1;
 	unsigned		ep0_bounced:1;
 	unsigned		ep0_expect_in:1;
@@ -1403,9 +1403,9 @@ struct dwc3 {
 	unsigned		has_lpm_erratum:1;
 	unsigned		is_utmi_l1_suspend:1;
 	unsigned		is_fpga:1;
-	unsigned		pending_events:1;
+	bool			pending_events;
 	unsigned		do_fifo_resize:1;
-	unsigned		pullups_connected:1;
+	bool			pullups_connected;
 	unsigned		setup_packet_pending:1;
 	unsigned		three_stage_setup:1;
 	unsigned		dis_start_transfer_quirk:1;

Thanks,
Thinh

  reply	other threads:[~2026-12-04 20:43 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-26 13:01 [PATCH v2 0/4] DWC3 concurrency fixes Konrad Dybcio
2026-11-26 13:01 ` [PATCH v2 1/4] usb: dwc3: gadget: serialize connection bitfield writes Konrad Dybcio
2026-12-04 20:43   ` Thinh Nguyen [this message]
2026-11-26 13:01 ` [PATCH v2 2/4] usb: dwc3: gadget: clear softconnect on stop and failed pullup Konrad Dybcio
2026-11-26 13:22   ` sashiko-bot
2026-11-26 13:01 ` [PATCH v2 3/4] usb: dwc3: gadget: serialize resume against error recovery Konrad Dybcio
2026-11-26 13:22   ` sashiko-bot
2026-11-26 13:01 ` [PATCH v2 4/4] usb: dwc3: gadget: cancel err_recovery_work after usb_del_gadget Konrad Dybcio
2026-11-26 13:15   ` sashiko-bot
2026-11-26 13:22 ` [PATCH v2 0/4] DWC3 concurrency fixes 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=axMYY_wcDy-kNSJB@vbox \
    --to=thinh.nguyen@synopsys.com \
    --cc=balbi@kernel.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=jiazi.liu1984@gmail.com \
    --cc=konrad.dybcio@oss.qualcomm.com \
    --cc=konradybcio@kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=quic_wcheng@quicinc.com \
    /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