Re: [PATCH] kcov, usb, vhost: specify contexts for remote coverage sections

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, Oct 7, 2020 at 10:07 PM Alan Stern <stern@xxxxxxxxxxxxxxxxxxx> wrote:
>
> On Wed, Oct 07, 2020 at 09:54:57PM +0200, Andrey Konovalov wrote:
> > On Wed, Oct 7, 2020 at 9:29 PM Alan Stern <stern@xxxxxxxxxxxxxxxxxxx> wrote:
> > >
> > > On Wed, Oct 07, 2020 at 07:30:51PM +0200, Andrey Konovalov wrote:
> > > > Currently there's a KCOV remote coverage collection section in
> > > > __usb_hcd_giveback_urb(). Initially that section was added based on the
> > > > assumption that usb_hcd_giveback_urb() can only be called in interrupt
> > > > context as indicated by a comment before it.
> > > >
> > > > As it turns out, it's actually valid to call usb_hcd_giveback_urb() in task
> > > > context, provided that the caller turned off the interrupts; USB/IP actually
> > > > does that. This can lead to a nested KCOV remote coverage collection
> > > > sections both trying to collect coverage in task context. This isn't
> > > > supported by KCOV, and leads to a WARNING.
> > > >
> > > > The approach this patch takes is to annotate every call of kcov_remote_*()
> > > > callbacks with the context those callbacks are supposed to be executed in.
> > > > If the current context doesn't match the mask provided to a callback,
> > > > that callback is ignored. KCOV currently only supports collecting remote
> > > > coverage in two contexts: task and softirq.
> > > >
> > > > As the result, the coverage from USB/IP related usb_hcd_giveback_urb() calls
> > > > won't be collected, but the WARNING is fixed.
> > > >
> > > > A potential future improvement would be to support nested remote coverage
> > > > collection sections, but this patch doesn't address that.
> > > >
> > > > Signed-off-by: Andrey Konovalov <andreyknvl@xxxxxxxxxx>
> > > > ---
> > >
> > > > --- a/drivers/usb/core/hcd.c
> > > > +++ b/drivers/usb/core/hcd.c
> > > > @@ -1646,9 +1646,9 @@ static void __usb_hcd_giveback_urb(struct urb *urb)
> > > >
> > > >       /* pass ownership to the completion handler */
> > > >       urb->status = status;
> > > > -     kcov_remote_start_usb((u64)urb->dev->bus->busnum);
> > > > +     kcov_remote_start_usb((u64)urb->dev->bus->busnum, KCOV_CONTEXT_SOFTIRQ);
> > > >       urb->complete(urb);
> > > > -     kcov_remote_stop();
> > > > +     kcov_remote_stop(KCOV_CONTEXT_SOFTIRQ);
> > >
> > > This isn't right.  __usb_hcd_giveback_urb() can execute in pretty much
> > > any context; its constraint is that interrupts must be disabled.
> >
> > You're right, but here we constraint kcov to only collect coverage in
> > case __usb_hcd_giveback_urb() is  executed in softirq context. This is
> > what happens when we're fuzzing USB with the dummy driver, which is
> > the case we currently take care of. Whenever someone has a desire to
> > collect coverage in other contexts, it will need to be implemented
> > separately.
>
> Oh, sorry.  I thought the constraint meant that it would be an error
> if kcov observed __usb_hcd_giveback_urb() executing in anything other
> than softirq context.

Ah, no, it will just be ignored. But I'll clarify this in v2, thank you!



[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux