Linux-Media Archive mirror
 help / color / mirror / Atom feed
From: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
To: Hans Verkuil <hverkuil@xs4all.nl>
Cc: Linux Media Mailing List <linux-media@vger.kernel.org>
Subject: Re: [PATCH for v6.10] media: v4l2-ctrls: drop unnecessary locking that caused potential deadlock
Date: Fri, 10 May 2024 03:08:51 +0300	[thread overview]
Message-ID: <20240510000851.GB30247@pendragon.ideasonboard.com> (raw)
In-Reply-To: <20240510000223.GA30247@pendragon.ideasonboard.com>

Another comment. The subject line states v6.10, but this is a v6.9
regression. How about reverting the offending commit for v6.9, and
working on a better implementation for v6.11 ?

On Fri, May 10, 2024 at 03:02:25AM +0300, Laurent Pinchart wrote:
> Hi Hans,
> 
> Thank you for the patch.
> 
> On Wed, May 08, 2024 at 11:11:01AM +0200, Hans Verkuil wrote:
> > When logging the control values through VIDIOC_LOG_STATUS you could
> > get into a potential deadlock situation in the vivid driver:
> > 
> > [Wed May  8 10:02:06 2024]  Possible unsafe locking scenario:
> > 
> > [Wed May  8 10:02:06 2024]        CPU0                    CPU1
> > [Wed May  8 10:02:06 2024]        ----                    ----
> > [Wed May  8 10:02:06 2024]   lock(vivid_ctrls:1620:(hdl_vid_cap)->_lock);
> > [Wed May  8 10:02:06 2024]                                lock(vivid_ctrls:1608:(hdl_user_vid)->_lock);
> > [Wed May  8 10:02:06 2024]                                lock(vivid_ctrls:1620:(hdl_vid_cap)->_lock);
> > [Wed May  8 10:02:06 2024]   lock(vivid_ctrls:1608:(hdl_user_vid)->_lock);
> 
> This looks scary. How was this triggered, can you provide the full
> lockdep report ? I'm worried there could be other scenarios where the
> locks could be taken in different orders.
> 
> > That's because both the main control handler was locked and the
> > inner control handler containing the control that you want to log.
> > 
> > In this particular case there is no need to lock the inner control
> > handler since it is guaranteed that that handler won't delete controls
> > unexpectedly.
> 
> All the v4l2_ctrl_type_ops operations currently rely on the control
> handler being locked when they're called. I don't like the idea of
> lifting that requirement without an audit of the implementations. We
> should then clearly document that the log operation can be called
> without the lock held.
> 
> > 
> > Fixes: 9801b5b28c692 ("media: v4l2-ctrls: show all owned controls in log_status")
> > Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
> > ---
> >  drivers/media/v4l2-core/v4l2-ctrls-core.c | 4 ----
> >  1 file changed, 4 deletions(-)
> > 
> > diff --git a/drivers/media/v4l2-core/v4l2-ctrls-core.c b/drivers/media/v4l2-core/v4l2-ctrls-core.c
> > index c59dd691f79f6..4e6748bd419cf 100644
> > --- a/drivers/media/v4l2-core/v4l2-ctrls-core.c
> > +++ b/drivers/media/v4l2-core/v4l2-ctrls-core.c
> > @@ -2518,11 +2518,7 @@ static void log_ctrl(const struct v4l2_ctrl_handler *hdl,
> 
> You can also drop the hdl argument to this function, which was
> introduced by the commit referenced by Fixes:.
> 
> > 
> >  	pr_info("%s%s%s: ", prefix, colon, ctrl->name);
> > 
> > -	if (ctrl->handler != hdl)
> > -		v4l2_ctrl_lock(ctrl);
> >  	ctrl->type_ops->log(ctrl);
> > -	if (ctrl->handler != hdl)
> > -		v4l2_ctrl_unlock(ctrl);
> > 
> >  	if (ctrl->flags & (V4L2_CTRL_FLAG_INACTIVE |
> >  			   V4L2_CTRL_FLAG_GRABBED |

-- 
Regards,

Laurent Pinchart

      reply	other threads:[~2024-05-10  0:09 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-08  9:11 [PATCH for v6.10] media: v4l2-ctrls: drop unnecessary locking that caused potential deadlock Hans Verkuil
2024-05-10  0:02 ` Laurent Pinchart
2024-05-10  0:08   ` Laurent Pinchart [this message]

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=20240510000851.GB30247@pendragon.ideasonboard.com \
    --to=laurent.pinchart@ideasonboard.com \
    --cc=hverkuil@xs4all.nl \
    --cc=linux-media@vger.kernel.org \
    /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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).