mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Alan Stern <stern@rowland.harvard.edu>
To: Andrey Konovalov <andreyknvl@google.com>
Cc: Dmitry Vyukov <dvyukov@google.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	USB list <linux-usb@vger.kernel.org>,
	LKML <linux-kernel@vger.kernel.org>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Shuah Khan <shuah@kernel.org>,
	Alexander Potapenko <glider@google.com>,
	Marco Elver <elver@google.com>,
	Aleksandr Nogikh <nogikh@google.com>,
	Nazime Hande Harputluoglu <handeharputlu@google.com>
Subject: Re: [PATCH] kcov, usb, vhost: specify contexts for remote coverage sections
Date: Wed, 7 Oct 2020 16:07:55 -0400	[thread overview]
Message-ID: <20201007200755.GD468921@rowland.harvard.edu> (raw)
In-Reply-To: <CAAeHK+yV=mmrgyor=AeYq6SpLaqvpieHP51iTMrjNHLBhKDzyQ@mail.gmail.com>

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@rowland.harvard.edu> 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@google.com>
> > > ---
> >
> > > --- 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.

Alan Stern

  reply	other threads:[~2020-10-07 20:07 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-07 17:30 Andrey Konovalov
2020-10-07 17:41 ` Andrey Konovalov
2020-10-07 19:29 ` Alan Stern
2020-10-07 19:54   ` Andrey Konovalov
2020-10-07 20:07     ` Alan Stern [this message]
2020-10-07 20:29       ` Andrey Konovalov

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=20201007200755.GD468921@rowland.harvard.edu \
    --to=stern@rowland.harvard.edu \
    --cc=akpm@linux-foundation.org \
    --cc=andreyknvl@google.com \
    --cc=dvyukov@google.com \
    --cc=elver@google.com \
    --cc=glider@google.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=handeharputlu@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=nogikh@google.com \
    --cc=shuah@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

all inboxes | Powered by JetHome®