public inbox for linux-media@vger.kernel.org
 help / color / mirror / Atom feed
From: Mauro Carvalho Chehab <mchehab@infradead.org>
To: Brandon Philips <bphilips@suse.de>
Cc: v4l <video4linux-list@redhat.com>
Subject: Re: [PATCH 6 of 9] videobuf-vmalloc.c: Fix hack of postponing mmap on remap failure
Date: Tue, 8 Apr 2008 18:37:40 -0300	[thread overview]
Message-ID: <20080408183740.143c3dee@gaivota> (raw)
In-Reply-To: <20080408204514.GA6844@plankton.public.utexas.edu>

On Tue, 8 Apr 2008 13:45:14 -0700
Brandon Philips <bphilips@suse.de> wrote:

> > Sorry, but I think I missed your point.
> 
> Wow, that got jumbled.  What I meant to say was:
> 
> This patch allocates the vmalloc area when mmap() is called.  6/9
> allocates vmalloc during reqbuf.

Ah, ok. I don't see any technical issue of postponing vmalloc to be done on
iolock (but see bellow). The code will just become a little bit more complex.
On the other hand, I don't see any advantage, since vmalloc_user() doesn't
really alloc memory, AFAIK.

> I read the spec in such a way that once reqbuf is made the application
> can qbuf immediately without mmap'ing.  I may be mistaken though.

If you don't call REQBUF, vb->memory and baddr will be 0, as if you were doing a read().
The end result is that QBUF won't work. The same behaviour will also occur with your patch.

I've already tested this, by accident. No OOPS. it just returns -EINVAL.

> > > > +	case V4L2_MEMORY_USERPTR:
> > > > +	{
> > > 
> > > Why are you adding braces here?
> > > 
> > > > +		int pages = PAGE_ALIGN(vb->size);
> > 
> > To declare pages var on above code. without braces, a warning is generated.
> 
> I think that declarations should just go at the top of the function to
> avoid that.

Ok, I'll change it on a next patch.

> > Probably, in this case, we may have some troubles, due to vfree() if we get an
> > interrupt between:
> > 	vfree(mem->vmalloc)
> > 		and
> > 	mem->vmalloc=NULL.
> > 
> > A fix could be to disable IRQ during that interval of time, and/or protecting
> > with a spinlock.
> 
> Yes, protecting with a spinlock is required to release these buffers.
> 
> > I can't see any other issues. Btw, the same kind of code is also used on
> > videobuf-dma-sg, cafe-ccic, and several other USB drivers.
> 
> cafe-ccic does not free it's vmalloc area in the vm_close method.

True. The lock is needed. 

I'm not quite sure on how to properly protect videobuf-vmalloc and
videobuf-dma-sg against this kind of threat. Any suggestions? 

A lock for vmalloc would be easy, but the worse case seems to be dma, since a
transfer may be in course, while unmap is happening. I couldn't find any place
where this is handled on videobuf-dma-sg. I think that some drivers try to
handle it, by calling videobuf_dma_sync(). Yet, this seems to be a feature that
should be inside videobuf, not externally handled.

> 
> > > Really, I think the allocation should happen in REQBUF as I did.
> > 
> > By looking on your code, it didn't work previously, due to a bug on this line:
> > 
> > 	retval=remap_vmalloc_range(vma, mem->vmalloc,0);
> 
> What is wrong with this?

Before my patch, mem->vmalloc were equal to NULL.

That's why this were failing with em28xx: it needs FIRST to alloc something,
THEN remap it. 

If we move vmalloc to iolock, we'll need to move also remap_vmalloc_range to there. 

Moving remap_vmalloc_range() to iolock will also work properly, but it doesn't
seem to be right to use mmap() callback just to store some things to be handled
inside iolock. That's the reason why I've opted to move just the vmalloc to
__videobuf_mmap_mapper().

What were happening before my and your patches is that the above line (remap)
were always failing for real devices. So, there was another
remap_vmalloc_range() inside iolock. The last one were the one who were really
working for tm6000 and em28xx.

I dunno why, but, for vivi, it seems that the first vmalloc were actually
working.

> > Also, all userspace clients already do something like this, on buffer_prepare:
> > 
> >         if (VIDEOBUF_NEEDS_INIT == buf->vb.state) {
> >                 rc = videobuf_iolock(vq, &buf->vb, NULL);
> >                 if (rc < 0)
> >                         goto fail;
> >         }
> 
> Huh?  How do userspace apps use videobuf_iolock?!
 
I was meaning to say "videobuf clients".

What I tried to say is that you've added a similar code to this inside patch
6/9. It would be interesting if we could remove the above code from videobuf
clients to be handled internally, and simplifying the logic inside the drivers,
but this seems to be complicated, since buffer should be filled inside
buffer_prepare.

Cheers,
Mauro

--
video4linux-list mailing list
Unsubscribe mailto:video4linux-list-request@redhat.com?subject=unsubscribe
https://www.redhat.com/mailman/listinfo/video4linux-list

  parent reply	other threads:[~2008-04-08 21:38 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-03-28 10:18 [PATCH 0 of 9] videobuf fixes Brandon Philips
2008-03-28 10:18 ` [PATCH 1 of 9] soc_camera: Introduce a spinlock for use with videobuf Brandon Philips
2008-03-28 20:53   ` Guennadi Liakhovetski
2008-03-29  3:59     ` Brandon Philips
2008-04-04 13:46       ` [PATCH] soc-camera: use a spinlock for videobuffer queue Guennadi Liakhovetski
2008-04-04 20:17         ` Brandon Philips
2008-03-28 10:18 ` [PATCH 2 of 9] videobuf: Require spinlocks for all videobuf users Brandon Philips
2008-03-28 10:18 ` [PATCH 3 of 9] videobuf: Wakeup queues after changing the state to ERROR Brandon Philips
2008-03-28 10:18 ` [PATCH 4 of 9] videobuf: Simplify videobuf_waiton logic and possibly avoid missed wakeup Brandon Philips
2008-03-28 10:18 ` [PATCH 5 of 9] videobuf-vmalloc.c: Remove buf_release from videobuf_vm_close Brandon Philips
2008-03-28 10:18 ` [PATCH 6 of 9] videobuf-vmalloc.c: Fix hack of postponing mmap on remap failure Brandon Philips
     [not found]   ` <20080405131236.7c083554@gaivota>
     [not found]     ` <20080406080011.GA3596@plankton.ifup.org>
     [not found]       ` <20080407183226.703217fc@gaivota>
     [not found]         ` <20080408152238.GA8438@plankton.public.utexas.edu>
2008-04-08 18:40           ` Mauro Carvalho Chehab
     [not found]             ` <c8b4dbe10804081306xb1e8f91q64d1e6d18d3d2531@mail.gmail.com>
2008-04-08 20:50               ` Mauro Carvalho Chehab
     [not found]                 ` <c8b4dbe10804090626l6b2b10d9p1c22e02dfe2850fe@mail.gmail.com>
2008-04-09 20:42                   ` Mauro Carvalho Chehab
     [not found]             ` <20080408204514.GA6844@plankton.public.utexas.edu>
2008-04-08 21:37               ` Mauro Carvalho Chehab [this message]
     [not found]                 ` <20080415021558.GA22068@plankton.ifup.org>
2008-04-15 14:10                   ` Mauro Carvalho Chehab
2008-03-28 10:18 ` [PATCH 7 of 9] vivi: Simplify the vivi driver and avoid deadlocks Brandon Philips
2008-03-28 18:34   ` Mauro Carvalho Chehab
2008-03-29  5:35     ` Brandon Philips
2008-03-31 19:35       ` Mauro Carvalho Chehab
2008-03-28 10:18 ` [PATCH 8 of 9] videobuf: Avoid deadlock with QBUF and bring up to spec for empty queue Brandon Philips
2008-03-28 10:18 ` [PATCH 9 of 9] videobuf-dma-sg.c: Avoid NULL dereference and add comment about backwards compatibility Brandon Philips
2008-03-28 19:09 ` [PATCH 0 of 9] videobuf fixes Mauro Carvalho Chehab
2008-03-29  5:25   ` Brandon Philips
2008-03-29 22:49     ` Vanessa Ezekowitz
2008-03-31 18:35     ` Mauro Carvalho Chehab
2008-03-31 19:26       ` Brandon Philips
2008-03-31 21:31         ` Mauro Carvalho Chehab
2008-04-01  3:11           ` Brandon Philips
2008-04-01 20:49             ` Mauro Carvalho Chehab
2008-04-02 18:54               ` Brandon Philips
2008-04-02 20:06                 ` Mauro Carvalho Chehab
2008-04-02 18:56               ` Brandon Philips

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=20080408183740.143c3dee@gaivota \
    --to=mchehab@infradead.org \
    --cc=bphilips@suse.de \
    --cc=video4linux-list@redhat.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