Received: from out-177.mta1.migadu.com (out-177.mta1.migadu.com [95.215.58.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D95FB40DFAA for ; Tue, 10 Mar 2026 22:31:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.177 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773181917; cv=none; b=TPHE5DGh+oYA2OFPB1jgKaRT8mJNvpaDpmCLRuDtQSIgSVfbTsNs/wvyYJJd3lGtsitrT7QvxdDdFRlj7qGVhAHbVmMXA9ytk/NAlgjOjwdilpAs2Y3uNKuyENADZSJRibrvruaRdHhecFVc2kK4/yj0S5jN/pxTVWf2I0jCKIE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773181917; c=relaxed/simple; bh=nCg+f0Ir6nq1atsLP/nsyl/0EfHnr5HJe3XImmUMm80=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=cRF9/JSMieR2bx/DasIeKQxqo6bzqslyTfLjgYwQWRVe6cG1bT1STvlJWu7yseAs9vHRxAgrw5620yxIv4GGjwWRsgap/ZNKO65tRLiPRZLJWYc4UOKqXgxRN5keubd3n5mBXNX/8nKf0LrMLojEaqlLk6TgjsRTA+Ll9OkoaBo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=W/u9QQWk; arc=none smtp.client-ip=95.215.58.177 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="W/u9QQWk" Message-ID: DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1773181914; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=IyLfIQxPvnSedK9kxLfC8cNGtJC+e8gFg6CxxaAUpKs=; b=W/u9QQWkiMKY212DJYhc4mNg95s2YFRJMWY248WGOxV5eT8hiydA67VOwtWWXS6SRd7ifA Qb69xG+51/ypT/XwRZZ5DhNmRcmSJpxekklG4xL/Ox5BdSpM/7NJxQomilqBKYqApWBH6Q 0vGTnvi3pM9k//z79cRqH0v0oad9mJo= Date: Tue, 10 Mar 2026 18:31:46 -0400 Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Subject: Re: [BUG] uvc_status_stop hangs if called from async_ctrl.work To: Ricardo Ribalda Cc: Laurent Pinchart , Hans de Goede , linux-media@vger.kernel.org, linux-usb@vger.kernel.org References: <6733bdfb-3e88-479f-8956-ab09c04c433e@linux.dev> Content-Language: en-US X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Sean Anderson In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Migadu-Flow: FLOW_OUT On 3/10/26 18:08, Ricardo Ribalda wrote: > Hi Sean > > On Tue, 10 Mar 2026 at 22:23, Sean Anderson wrote: >> >> On 3/10/26 16:56, Ricardo Ribalda wrote: >> > Hi Sean >> > >> > Thanks for the report. >> > >> > I have not been able to repro with qv4l2 on my computer :(. >> > >> > Could you try if this patch works for you? Not saying that it is >> > beautiful patch, or the way to do it.... but it will let me know if I >> > am looking in the right place. >> > >> > >> > diff --git a/drivers/media/usb/uvc/uvc_status.c >> > b/drivers/media/usb/uvc/uvc_status.c >> > index 231cfee8e7c2..cca2aed162c3 100644 >> > --- a/drivers/media/usb/uvc/uvc_status.c >> > +++ b/drivers/media/usb/uvc/uvc_status.c >> > @@ -340,7 +340,9 @@ static void uvc_status_stop(struct uvc_device *dev) >> > * Cancel any pending asynchronous work. If any status event was queued, >> > * process it synchronously. >> > */ >> > - if (cancel_work_sync(&w->work)) >> > + if (&w->work == current_work()) >> > + cancel_work(&w->work); >> > + else if (cancel_work_sync(&w->work)) >> > uvc_ctrl_status_event(w->chain, w->ctrl, w->data); >> > >> > /* Kill the urb. */ >> > @@ -352,7 +354,7 @@ static void uvc_status_stop(struct uvc_device *dev) >> > * cancelled before returning or it could then race with a future >> > * uvc_status_start() call. >> > */ >> > - if (cancel_work_sync(&w->work)) >> > + if (&w->work != current_work() && cancel_work_sync(&w->work)) >> > uvc_ctrl_status_event(w->chain, w->ctrl, w->data); >> > >> > /* >> >> I don't think this works since the urb will be rescheduled as flush_status >> is set to false again. However, the following patch works for me: > > It does not work, in the sense that the urb is re submited... but if > would have confirmed the rootcause of the lockdep. But you have > already proven that with your patch, which I think is correct :). > Thanks for that > > Can you resend it as a proper patch? > > You probably want to add: > Fixes: a32d9c41bdb8 ("media: uvcvideo: Make power management granular") Done. > I will try to review with extra care and a big cup of tea tomorrow morning. > > Thanks! > >> >> diff --git a/drivers/media/usb/uvc/uvc_status.c b/drivers/media/usb/uvc/uvc_status.c >> index 231cfee8e7c2c..2a23606c7f4c6 100644 >> --- a/drivers/media/usb/uvc/uvc_status.c >> +++ b/drivers/media/usb/uvc/uvc_status.c >> @@ -316,6 +316,14 @@ static int uvc_status_start(struct uvc_device *dev, gfp_t flags) >> if (!dev->int_urb) >> return 0; >> >> + /* >> + * If the work called uvc_status_stop it may still be running. Wait for >> + * it to finish before we submit the urb. >> + */ >> + cancel_work_sync(&dev->async_ctrl.work); >> + >> + /* Clear the flush status if we were previously stopped */ >> + smp_store_release(&dev->flush_status, false); >> return usb_submit_urb(dev->int_urb, flags); >> } >> >> @@ -336,6 +344,14 @@ static void uvc_status_stop(struct uvc_device *dev) >> */ >> smp_store_release(&dev->flush_status, true); >> >> + /* >> + * We will deadlock if we are currently in the work function. >> + * Fortunately, we know that the URB is already dead and that no >> + * further work can be queued, so there's nothing left for us to do. >> + */ >> + if (current_work() == &w->work) >> + return; >> + >> /* >> * Cancel any pending asynchronous work. If any status event was queued, >> * process it synchronously. >> @@ -354,15 +370,6 @@ static void uvc_status_stop(struct uvc_device *dev) >> */ >> if (cancel_work_sync(&w->work)) >> uvc_ctrl_status_event(w->chain, w->ctrl, w->data); >> - >> - /* >> - * From this point, there are no events on the queue and the status URB >> - * is dead. No events will be queued until uvc_status_start() is called. >> - * The barrier is needed to make sure that flush_status is visible to >> - * uvc_ctrl_status_event_work() when uvc_status_start() will be called >> - * again. >> - */ >> - smp_store_release(&dev->flush_status, false); >> } >> >> int uvc_status_resume(struct uvc_device *dev) >> -- >> >> The first cancel_work_sync also seems superfluous to me, since we have to cancel >> again anyway. > > It has been a while since we did this, but I believe that since we did > not use locks, the only way to guarantee the event queue was flushed > and the URB was killed was to have the double cancel_work() in that > order. Oh, I see because we could have something like CPU A CPU B ================================= ======================= uvc_ctrl_status_event_work smp_load_acqure(flush_status) uvc_status_stop() smp_store_release() usb_kill_urb() cancel_work_sync() usb_submit_urb() --Sean