From patchwork Thu Jan 7 16:01:44 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 12004381 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-26.6 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7B05EC433E6 for ; Thu, 7 Jan 2021 16:02:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4DBB423428 for ; Thu, 7 Jan 2021 16:02:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728285AbhAGQCe (ORCPT ); Thu, 7 Jan 2021 11:02:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42546 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725965AbhAGQCd (ORCPT ); Thu, 7 Jan 2021 11:02:33 -0500 Received: from mail-wr1-x44a.google.com (mail-wr1-x44a.google.com [IPv6:2a00:1450:4864:20::44a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2DE3FC0612F4 for ; Thu, 7 Jan 2021 08:01:53 -0800 (PST) Received: by mail-wr1-x44a.google.com with SMTP id o17so2825246wra.8 for ; Thu, 07 Jan 2021 08:01:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:message-id:mime-version:subject:from:to:cc; bh=cIq2VE7GHy/A2isTfDsjFX2FggL4BJiiCnO6T+jBwiM=; b=V2dITOA4ZjQIh2CP/4hdMBOhHdPmn6LvL5o1BQmeXUJWYStzYxOyeukrKxJFrwD7I5 PWWjqrFvsPibnGIuA9XfKs2wn2Bu5zrka5JWFF1njoWkmqfZvWZCTubMCUYP9JHYTLF/ t31kkKtUmhSwZ9ARkQpjC+ec2pnVBix1wPsb2jB3nQlL6iZV907N98AY7YG0CKM/brIh q8TqXjUY1FiHrtCGpOZ4wKJrYZASTlk+Z4KsvxXqk1BWaMf4pXW2y/hzx0nmGWS618uW i+qeKOQdDicunc596/MeRoR2lOh5f09ia0+QO6tcP4xmLfAK6m4FnshJxxJA1cGOEKoC bEnQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:message-id:mime-version:subject:from :to:cc; bh=cIq2VE7GHy/A2isTfDsjFX2FggL4BJiiCnO6T+jBwiM=; b=igqU61GDUWHSXXyYqIx96SLC6z3+CraEYHMVnA/7iQzjxztAqHnfg2cMb1TuWCp1oN +lQxbhP1xawf5Uvc+VClcsWztQgxGyi8kfhMKPbLtHJutjaxWE/J/N/cji9MkdwbNlCm LCRpDC+WpO2k+rJV9uw28WvJoAIE72KAapapbdw225J7RgQIq1REoFcutIqMT/JlxfpI lGhT8PsNPJpjcSJTexKpVbd6KHi07pgBeqFc1QvyfavM2rNSvJGp98pPyIvMeyw9Kizm SVrB0XlbpBiuLl1PAcG6dz7S8MIxW33PzSi1O1N9FLMirTD8bbZktXuUmLr8hh74hfIC tpmw== X-Gm-Message-State: AOAM532Kl/1dtEKdf+oysMAjGdXdPUVCebm1V49HovG93zgcttiSB7ys LZUzrW4f888t7uAg/H1kUhyHS02ZeMHKGlI/ X-Google-Smtp-Source: ABdhPJwA5EIT8h4WB2E34cwYPYToSiJcQ93GEB2pMHddQLY8+1saxvnZdXIrKJ6e9sf9dluJGXMEXRjObypGj0Hz Sender: "andreyknvl via sendgmr" X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:a1c:2c89:: with SMTP id s131mr1458471wms.0.1610035310903; Thu, 07 Jan 2021 08:01:50 -0800 (PST) Date: Thu, 7 Jan 2021 17:01:44 +0100 Message-Id: <04978189d40307e979be61c458f4944b61134198.1610035117.git.andreyknvl@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.29.2.729.g45daf8777d-goog Subject: [PATCH v2] kcov, usb: hide in_serving_softirq checks in __usb_hcd_giveback_urb From: Andrey Konovalov To: Greg Kroah-Hartman Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, kasan-dev@googlegroups.com, Dmitry Vyukov , Alexander Potapenko , Marco Elver , Andrey Konovalov Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Done opencode in_serving_softirq() checks in __usb_hcd_giveback_urb() to avoid cluttering the code, hide them in kcov helpers instead. Fixes: aee9ddb1d371 ("kcov, usb: only collect coverage from __usb_hcd_giveback_urb in softirq") Signed-off-by: Andrey Konovalov --- Changes v1->v2: - Fix a typo in the commit description and in a comment in the patch. --- drivers/usb/core/hcd.c | 8 +++----- include/linux/kcov.h | 21 +++++++++++++++++++++ 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c index 60886a7464c3..ad5a0f405a75 100644 --- a/drivers/usb/core/hcd.c +++ b/drivers/usb/core/hcd.c @@ -1649,14 +1649,12 @@ static void __usb_hcd_giveback_urb(struct urb *urb) urb->status = status; /* * This function can be called in task context inside another remote - * coverage collection section, but KCOV doesn't support that kind of + * 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); + kcov_remote_start_usb_softirq((u64)urb->dev->bus->busnum); urb->complete(urb); - if (in_serving_softirq()) - kcov_remote_stop(); + kcov_remote_stop_softirq(); usb_anchor_resume_wakeups(anchor); atomic_dec(&urb->use_count); diff --git a/include/linux/kcov.h b/include/linux/kcov.h index a10e84707d82..18306ef8ad5a 100644 --- a/include/linux/kcov.h +++ b/include/linux/kcov.h @@ -52,6 +52,25 @@ static inline void kcov_remote_start_usb(u64 id) kcov_remote_start(kcov_remote_handle(KCOV_SUBSYSTEM_USB, id)); } +/* + * The softirq flavor of kcov_remote_*() functions is introduced as a temporary + * workaround for kcov's lack of nested remote coverage sections support in + * task context. Adding suport for nested sections is tracked in: + * https://bugzilla.kernel.org/show_bug.cgi?id=210337 + */ + +static inline void kcov_remote_start_usb_softirq(u64 id) +{ + if (in_serving_softirq()) + kcov_remote_start_usb(id); +} + +static inline void kcov_remote_stop_softirq(void) +{ + if (in_serving_softirq()) + kcov_remote_stop(); +} + #else static inline void kcov_task_init(struct task_struct *t) {} @@ -66,6 +85,8 @@ static inline u64 kcov_common_handle(void) } static inline void kcov_remote_start_common(u64 id) {} static inline void kcov_remote_start_usb(u64 id) {} +static inline void kcov_remote_start_usb_softirq(u64 id) {} +static inline void kcov_remote_stop_softirq(void) {} #endif /* CONFIG_KCOV */ #endif /* _LINUX_KCOV_H */