From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796452957; b=Wd75IsQ7i558xzP0V/FaDzNGmG6fy4s+FwNZrgNrPDtX048fWyXi9NYvB1+wAb5OSvYb 9Hk63GCnxuHJrgcAGm4LylQpij5IT9ExQ2M39IXbhlIbdL/1nhRc2hg19Q/JW1rrNDPfA upPAjZJ5dpSEc57eFWA0uLXUII193VM4tawa5m2K7YdLWhZyhszfXnBcN/OL2a8iJx75q 1h7f1VpD6uNUsAUGbJcezV7aGPugRKaoACQimY8gdSFteg4wAe2WJ0iNVWt9YleUnbs8T +GENpIi8kMNsakhFFPrw8fSgT67/lw0Elf0am3eZgsV/vCUHcvITakx3GiY/7Xk6vZg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796452957; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=W7Gpb+lqa/RTGhNXvI7dVYeznpJ1FZ7sg8JzfUzG2tk=; b=UrcceLxGoaZ2eY5Xq1BblB/hXkxAv0yG3oR49MQTt6eg180SmjtbJfGTDZLrXB30FThH z5AIJYe9NGbrdnQtgP+04oxomh2uQX+INMgOFtg/vkJN7m/kdL6lxZ9zgM/4zKjKW6uSK xNJfvZxBvg0WK6+ttv86CCDtpnu3/VJwGZdWTwb0YTGWbsVTQ3e4kLZBiUYBG561nFx6N OurtFWZ8yuCl1VGZY0obdkmpRAuTqM7Oi6gIAdeA4Kud6p3ZQPUtqLo8flu4Z0OqYTIdZ BqqpqDILlsIkbHF8LynP+fP1rNJtMFka4td8/MC48+PTs65G4RnKGCd3189GexP0iDw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=HyqDH43z; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A9EF3606A32F; Sat, 5 Dec 2026 06:42:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=HyqDH43z Received: by smtp.kernel.org (Postfix) with ESMTPSA id 27BA31F0092B; Sat, 5 Dec 2026 06:42:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796452957; bh=W7Gpb+lqa/RTGhNXvI7dVYeznpJ1FZ7sg8JzfUzG2tk=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=HyqDH43zuHZXqLUPjcC734zoGygeiT09o1Khg1lkKuiM+0s46sXOnZ1StXvjV2+MO Jp2a7KAdvEUSTSoAO0hg8TV70qqt+Ity4BFcaa+YnSGdtCwagGCVcHggE7YrlzF/E9 /T8YiBazdtMAqZZ3NL4n7aT39mbWNfzSpJbLVvzKR1DoWMKNlS8FbrCP2B3qpdrYzJ yT1KZbdCG3f0ZGB3Qjoc/FG9fIyUZoiz/JzAlxzp2Copx90Ud8EBLHbJMlm8S1DJln NfTnHqfSyRskp/r1O0ojPw+Iki3Fgo98Xy6Shub6OaB0cK9PruJ8Ig2TnCd2fGBEJo m0hVm0fzVTxUw== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH usb-next v2] usb: gadget: pxa27x_udc: fix locking in req_done() on PREEMPT_RT Reply-To: sashiko-reviews@lists.linux.dev To: "Xinsheng Zhu" , linux-usb@vger.kernel.org Cc: linux-rt-devel@lists.linux.dev, linux-kernel@vger.kernel.org In-Reply-To: <20261205063000.75015-1-xinsheng.zhu.ny@gmail.com> References: <20261205063000.75015-1-xinsheng.zhu.ny@gmail.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Sat, 05 Dec 2026 06:42:36 +0000 X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Thank you for your contribution! Sashiko AI review found 2 potential issues to consider: - [Low] usb: gadget: pxa27x_udc: unused pflags pointer kept as bool in req_done() - [Low] usb: gadget: pxa27x_udc: commit message omits pxa_ep_dequeue() lock change -- commit 5f58fa50b677bda0e909e4f97a6e3ac181b4d2f2 Author: Xinsheng Zhu > usb: gadget: pxa27x_udc: fix locking in req_done() on PREEMPT_RT > > req_done() explicitly disables local interrupts around > usb_gadget_giveback_request(). The completion callback may acquire > spinlocks, which become sleeping locks on PREEMPT_RT and cannot be > acquired with interrupts disabled. > > Use spin_unlock() and spin_lock() around the giveback, following > the locking pattern introduced in commit 8d63c83d8eb9 > ("USB: gadget: dummy-hcd: Fix locking bug in RT-enabled kernels") > and commit 09bf21bf5249 ("usbip: Fix locking bug in RT-enabled kernels"). > This keeps interrupts disabled during the giveback on non-RT kernels > without explicitly disabling them on PREEMPT_RT. > > When pflags is NULL, acquire ep->lock before ep_del_request() to > protect the request removal and status update. Release the lock > and restore the interrupt state before returning. > > Fixes: 5e23e90f3388 ("USB: pxa27x_udc: Fix deadlocks on request queueing") > Signed-off-by: Xinsheng Zhu [Severity: Low] Should the commit message also describe the locking change in pxa_ep_dequeue()? The diff keeps ep->lock held across the request lookup and the call to req_done(), closing a race where an interrupt could complete and free the request between lookup and removal. That change is currently only noted under Changes in v2 below the tearline, which git am strips. > diff --git a/drivers/usb/gadget/udc/pxa27x_udc.c b/drivers/usb/gadget/udc= /pxa27x_udc.c > index 9fd079cb65c6b..2c4e46533999b 100644 > --- a/drivers/usb/gadget/udc/pxa27x_udc.c > +++ b/drivers/usb/gadget/udc/pxa27x_udc.c > @@ -650,17 +650,23 @@ static void ep_del_request(struct pxa_ep *ep, struc= t pxa27x_request *req) > * @ep: pxa physical endpoint > * @req: pxa request > * @status: usb request status sent to gadget API > - * @pflags: flags of previous spinlock_irq_save() or NULL if no lock held > + * @pflags: non-NULL if the caller holds ep->lock with spin_lock_irqsave= (), > + * NULL otherwise > * > - * Context: ep->lock held if flags not NULL, else ep->lock released > + * Context: ep->lock held if @pflags is non-NULL, otherwise unlocked. > * > - * Retire a pxa27x usb request. Endpoint must be locked. > + * Retire a pxa27x usb request. Acquire the endpoint lock if needed > + * and temporarily release it around the completion callback. > + * Return with the original lock state restored. > */ > static void req_done(struct pxa_ep *ep, struct pxa27x_request *req, int = status, > unsigned long *pflags) > { > unsigned long flags; > =20 > + if (!pflags) > + spin_lock_irqsave(&ep->lock, flags); > + > ep_del_request(ep, req); > if (likely(req->req.status =3D=3D -EINPROGRESS)) > req->req.status =3D status; > @@ -672,20 +678,20 @@ static void req_done(struct pxa_ep *ep, struct pxa2= 7x_request *req, int status, > &req->req, status, > req->req.actual, req->req.length); > =20 > - if (pflags) > - spin_unlock_irqrestore(&ep->lock, *pflags); > - local_irq_save(flags); > + spin_unlock(&ep->lock); > usb_gadget_giveback_request(&req->udc_usb_ep->usb_ep, &req->req); > - local_irq_restore(flags); > - if (pflags) > - spin_lock_irqsave(&ep->lock, *pflags); > + spin_lock(&ep->lock); > + > + if (!pflags) > + spin_unlock_irqrestore(&ep->lock, flags); > } [Severity: Low] Can pflags be replaced now that req_done() never dereferences it? After switching to spin_unlock() and spin_lock() around the giveback, pflags is only used as a boolean in req_done() and its wrappers, forcing locked callers to pass &flags as a dummy sentinel. The conditional locking also triggers lock-context imbalance warnings in static analyzers. In addition, ep0_end_out_req() and ep0_end_in_req() still take pflags even though every call site passes NULL. Splitting req_done() into a locked helper and an unlocked wrapper (and dropping the parameter from those two helpers) would make the locking contract explicit. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261205063000.7501= 5-1-xinsheng.zhu.ny@gmail.com?part=3D1