Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp1430216pxu; Fri, 16 Oct 2020 11:44:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxTbr1xrp70WSlDc+ZCsffmbIclW+P1ShTUk/lSHRr5n6ttUCYLo2L0PvPhU9JN4AyT4+9R X-Received: by 2002:a05:6402:100e:: with SMTP id c14mr5389260edu.365.1602873861195; Fri, 16 Oct 2020 11:44:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1602873861; cv=none; d=google.com; s=arc-20160816; b=bu5UHwLC7lsYQsMjZTeKkvaSBRC//uQHET29d8lOXHQP9PU5w3JiOkR1lrbyphAhC5 NNLszH89fLp/30vYZhys5f8dAxJ3h8APwFs+lElM5kWU5c0oqK6unsfsblHebfnMAm7K /gy/7bbYuWnw5a1PGNKmGHg1GosZYny3lFW4mkxehO9kZD7AApq37/lZaWvJaecaG/sy Eebr4xz77XMzViHljcId4bLwBU9VIotns//yTamF7jNmQazVUgx/FXWglcRJ9A8l4g2D XUQRx4+KYTMfKPaJe+Ys6bu4ZZMB+X0IPZTI8JaHEzUnbyrNUxAq2jtWMjYULo3YzIPD 0oBw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=5B2JHx1oEsLnYhPJ0E0oLsxJSDwxjG1w2DFx5zPQCSM=; b=QTWXKrUzYjkegD+Wll723f7jsmtwd4RVDvX8r9h2L+s+H+2A8/RguGre+WjYU1PXsC cbHbiVpnh+cTELfvF3DPBoZjdaiPnSVwQacvQszjEQiB22/VSIoCyfFRt75frS1mcYPq mytkY/nreo0i6B9EHc3M2linzij5kC5x8VV8gCnrT+GRxKr7uVUg2GQXp/46hA8675Mg GDbAEYsofnVjuFXE4ptZCxgzCxEbE1F+C2Bdzl2NsP4Uq27SI9SyhOfKLAJB4Sfnqy7m 9bE6XORvOtXuFyR4cxQPI4O08truRhMfej1ZNhF+XVhn6i8EN7ur+gZ5u5axF8OOM48F ALpg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b="Oe/2QOCS"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w21si2341947ejj.377.2020.10.16.11.43.59; Fri, 16 Oct 2020 11:44:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b="Oe/2QOCS"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2408881AbgJPOdf (ORCPT + 99 others); Fri, 16 Oct 2020 10:33:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55002 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2408882AbgJPOdd (ORCPT ); Fri, 16 Oct 2020 10:33:33 -0400 Received: from mail-qk1-x741.google.com (mail-qk1-x741.google.com [IPv6:2607:f8b0:4864:20::741]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8EA07C0613D3 for ; Fri, 16 Oct 2020 07:33:32 -0700 (PDT) Received: by mail-qk1-x741.google.com with SMTP id y198so2102839qka.0 for ; Fri, 16 Oct 2020 07:33:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=5B2JHx1oEsLnYhPJ0E0oLsxJSDwxjG1w2DFx5zPQCSM=; b=Oe/2QOCSG/SDi0QQrY46fSiCcCIK2j3PJumDTv536yxaxYM4LY2q5W62Nzl8BTk/xG C5LteZVDRMdC+rJH0F64uebkLipY9PuIOWof+ZEwMDCWzY90R1r52WR2MOMyFuEAxo7x a2pcBC+vxs2HImfAC3aYVyYEvYeN9LUWhPiN482y/5zeOkitXcziNyPS5iwbLHR8s81J jnFo4d8ht2QN99WibP6Vilm16N0AI4qoDvZJjG5PjRMiyx3Lf1rQb3Ji3fb4USS40qqI wDzTdQyEK3fuRpMf/QmVX9rWWlBgYvrLhBNbBcehMkmxKrbC9UqzyJJCD+K65zkFl0pM tqPQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=5B2JHx1oEsLnYhPJ0E0oLsxJSDwxjG1w2DFx5zPQCSM=; b=G6lDo//TbPOUIn2nrAa7JWgk+u4yokiMPTFxGJzHPWrMpfH6hluwgBUizCuZb32lIG i1Gt2GyT3jf6rYnsiN0SlvtysLaDXdIGUQwU2I23JPNyCq53mjtdsIWPdCi0O8NIp+Oi 5X4B0dIwPwFyjkf2AcCoDGuXXDF5p70B/ogeVe1AbaKtImsLmhucwlxn5Whu0GTMvJp8 vnv+r/maZqSpR+skEJEcb4zQgZxaNVmUrkMwMGFI+QJbE+4fZBVg39Gaijms6B8exKDC Zkxuf8x3RNvEHk7OOztYsltZ07vycHK73BokAG2mesJ2KuYkSSDOqxdZcajz8Z8EwJwy zqFA== X-Gm-Message-State: AOAM533nFwdyZDJ1SNJ9qz0mclc9S2F3onxh7blDeo1KHye7OdQejhr3 DUWnZnuGiBxk/IdMzz+0uEsddPeuTPmbE3ZDk30SfA== X-Received: by 2002:a05:620a:1188:: with SMTP id b8mr1888251qkk.265.1602858811326; Fri, 16 Oct 2020 07:33:31 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Dmitry Vyukov Date: Fri, 16 Oct 2020 16:33:19 +0200 Message-ID: Subject: Re: [PATCH v4] kcov, usb: only collect coverage from __usb_hcd_giveback_urb in softirq To: Andrey Konovalov Cc: Greg Kroah-Hartman , USB list , LKML , Andrew Morton , Alan Stern , Shuah Khan , Alexander Potapenko , Marco Elver , Aleksandr Nogikh , Nazime Hande Harputluoglu Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Oct 16, 2020 at 3:57 PM 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. This is what happens when > syzkaller is fuzzing the USB stack via the dummy_hcd driver. > > 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 does > exactly 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. > > Change __usb_hcd_giveback_urb() to only call kcov_remote_*() callbacks > when it's being executed in a 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 > Acked-by: Marco Elver > --- > > Changes v3->v4: > - Don't make any kcov changes, do a softirq context check in usb code > instead. > > --- > drivers/usb/core/hcd.c | 11 +++++++++-- > 1 file changed, 9 insertions(+), 2 deletions(-) > > diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c > index a33b849e8beb..2f6a39e09dc6 100644 > --- a/drivers/usb/core/hcd.c > +++ b/drivers/usb/core/hcd.c > @@ -1646,9 +1646,16 @@ 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); > + /* > + * This function can be called in task context inside another remote > + * coverage collection section, but KCOV doesn't support that kind of > + * recursion yet. Only collect coverage in softirq context for now. > + */ > + if (in_serving_softirq()) > + kcov_remote_start_usb((u64)urb->dev->bus->busnum); > urb->complete(urb); > - kcov_remote_stop(); > + if (in_serving_softirq()) > + kcov_remote_stop(); Reviewed-by: Dmitry Vyukov Looks simpler :) > usb_anchor_resume_wakeups(anchor); > atomic_dec(&urb->use_count); > -- > 2.29.0.rc1.297.gfa9743e501-goog >