From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-186.mta0.migadu.com (out-186.mta0.migadu.com [91.218.175.186]) (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 029913CAE66 for ; Tue, 10 Mar 2026 21:23:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.186 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773177834; cv=none; b=OHqNFafD5Xxk4fgfw9G3qUeoWOzwryvEC5xiW2/pirr8SQxZ2NewhokaiY6bbf2a0p03sL8zJDlK6rAWPs8QJX4HEWpNJqfPBL2Gcm9J0Z6z6k4zQX9GnhFE+LMHux3HgYRdcadnBxQqybeZi3qfSzwXb4fSwjca23rKCmjDg4Q= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773177834; c=relaxed/simple; bh=5x2B0VItY076mEw7SlJpcOMHnQIayXVrqVWyRDo5ea0=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=WX+J3XXqDyw3wP8TJJ0gFv9L34XaQviT8dViVhCASYyCFsY8LEoelerBT+NmKDvGW2rJys/mqPMCu7PxhAlr2tTig+UYAyC3xkrkAD0Pr8hZTMtQDZcjip6jhKiydahtZo0YnLZvjSA9+S6A5pEgykcCxnkpe3YYDoMtDGlJCT8= 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=HkHQPBTR; arc=none smtp.client-ip=91.218.175.186 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="HkHQPBTR" Message-ID: DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1773177816; 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=q8QUrrZbtBaw96JE4uwm78SaKmRtGD4luJCTiJ68oMc=; b=HkHQPBTRzF2lqrzJYkkUuOtuR4JhCckytHaKF8FjTv22skiI34h6A2p4k5ENsXvg1u6fLL CJv8jt0xQjBW8NeNHRk7mnzPaSAfRBWaJyc9lnjwNth3eoxZmsER76vybdsyfvuMAeZVH6 7RPdiOJ95CJpLXBRY61eWO9bMiJ3Gm8= Date: Tue, 10 Mar 2026 17:23:32 -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 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: 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. --Sean