Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp5076981pxb; Mon, 15 Feb 2021 08:55:06 -0800 (PST) X-Google-Smtp-Source: ABdhPJx79x53g3RyL29GaECmmpC0P8lRiC9CcWy6LCQVOZBHO0Kj6iSbQJL1EsBDFfBX0mRTbMQ3 X-Received: by 2002:a05:6402:d:: with SMTP id d13mr16822621edu.274.1613408106788; Mon, 15 Feb 2021 08:55:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1613408106; cv=none; d=google.com; s=arc-20160816; b=rxbNnMyRf0THkElVdfyWW372g6DojTNRkXssHZ3PiOJaO+tPxnHDKP5AVJ6NVMw48Z XhMJchcIMb4Y4Nc1sxFP/BTX8DiEsZnbaGpGpp8zDPM4FzLQNfnpDPE1VGLIcNxzkXwA bmVxwG2S8W5jJoTxywKwolBO1aHS7KwrZR9rIqJFngAgSFigzDxJ1AHfMP53ltHpl29i Xw74wln8IJLlPLUYMzu7dPpMAh8kkOriON7+bJu+WObPNnfluvBmCiDqd3/oV6KEfmOn CrK3/OUYR+t3Zeu7cUxrDSFOhg688TJ7WtFBHxjGzzldrtTQx57pjNGI8BB4YvdxLS+j dMDw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=4Ue3Ghiz9wwcBD3TKvNWDOBrSDZV3AKeWPu6ZYhj3b8=; b=CZblXKK0yyBvzaFonqouvTD/s+A4F7XKqGbdJFORGnLjCWG2PPcvSTQYYDQpPVqxDV NQD3anDGKTzpZp99Ws6/NtOEKHB7dpR4H/CAYEW31F3sAIKSh4zl2hlmxOQZQ3WYRJBW XkO7uoV8T5l+tRDjxp1D1tUqRad9XzheefJ5y3biVAjXn5b3OjKKfLsvzPjyb3UmU8ZZ jw24AK9PSVbZYFyUceMgxtsJnl1gk8+I3MH5q9Ggz5O9vjGkgHXTf2hjGsGVk6/+pyx/ axxUhFcwsox+0T/91j9BYconeGpEiVbcuzCkbE4ggMixEt3tjeP/52azwoyKRvuQv/q9 X7pw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=IwH+nKfO; 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=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y25si12959258ejb.546.2021.02.15.08.54.43; Mon, 15 Feb 2021 08:55:06 -0800 (PST) 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=@linuxfoundation.org header.s=korg header.b=IwH+nKfO; 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=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231839AbhBOQwp (ORCPT + 99 others); Mon, 15 Feb 2021 11:52:45 -0500 Received: from mail.kernel.org ([198.145.29.99]:50184 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231342AbhBOPmC (ORCPT ); Mon, 15 Feb 2021 10:42:02 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 1EC7F64EB2; Mon, 15 Feb 2021 15:35:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1613403302; bh=IwpvTOBV/qBSb/D4GNBQPatO473ds64g9Ir3Kza9X0Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IwH+nKfOnDg3tLNklLKCzHRM8ytYacWEgig+5Gf9D7ji/0OdeSADkI18nbP73SSvs GKU1GMjZGTf7NQrqnxYy+vwK5BdgH8tPk4fIXiIAJ18dbMX/xazc6CsOFol3wVNtFT ZgUAFNcMy8vBe9AE/izmOfg/7cs/By6KOqnIddxE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Dmitry Vyukov , Marco Elver , Andrey Konovalov Subject: [PATCH 5.10 104/104] kcov, usb: only collect coverage from __usb_hcd_giveback_urb in softirq Date: Mon, 15 Feb 2021 16:27:57 +0100 Message-Id: <20210215152722.828789915@linuxfoundation.org> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210215152719.459796636@linuxfoundation.org> References: <20210215152719.459796636@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Andrey Konovalov commit aee9ddb1d3718d3ba05b50c51622d7792ae749c9 upstream. 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. Reviewed-by: Dmitry Vyukov Acked-by: Marco Elver Signed-off-by: Andrey Konovalov Link: https://lore.kernel.org/r/f3a7a153f0719cb53ec385b16e912798bd3e4cf9.1602856358.git.andreyknvl@google.com Signed-off-by: Greg Kroah-Hartman --- drivers/usb/core/hcd.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) --- a/drivers/usb/core/hcd.c +++ b/drivers/usb/core/hcd.c @@ -1646,9 +1646,16 @@ static void __usb_hcd_giveback_urb(struc /* 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(); usb_anchor_resume_wakeups(anchor); atomic_dec(&urb->use_count);