Received: by 2002:a05:6a10:2785:0:0:0:0 with SMTP id ia5csp2271343pxb; Mon, 11 Jan 2021 05:42:22 -0800 (PST) X-Google-Smtp-Source: ABdhPJxjG3u43Y9VkFORTAVrvkKQFnFt1Xbc0fA+iwLMQrimxv/+OgffibhXu7zIjr8jEUWPKvmc X-Received: by 2002:a50:f40e:: with SMTP id r14mr13679968edm.5.1610372542379; Mon, 11 Jan 2021 05:42:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610372542; cv=none; d=google.com; s=arc-20160816; b=C7C6sXhf+irF+AALxnGy/86oYixwHaLHHyd5u2FeCDcspoWhp0+E6nImdzgFCMaqDQ Hnn20e58dxoIDqXCpLyN9SxhCCIcfPYRlcIKbQBH261y+/xdB9MKy7PB+ZZDwtf65Uwm UjLNtfBjOaWaFBcg4/4cP5AvXQ4Zd610YzW/1Nln37lkvcqkosXxCrLMQxR6QR7ws80h eZwWHKOyHcrWyIoQUY7zTtjlamh5+aW55HojmmMSbAr7mgtoHfr7QJi6ayzVtRBXO8ZY kcGbRWU8X5JJ5YZZHK57vuav1Xk9RCFD/07ps0aFFwwtF5Uxa5GIB2j4xNyV5YgtCxBw oB+g== 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=/277Rw76m7NNoBTErZ0Y3YOlOVHdiZXck+QpNe1WaUU=; b=MQ8mhKEwGbZ3mWpxT/8QuAHaCpipWyG/Zuk41G5DkALr0mLix8yQa2MongytumvAcn 4d6UT8dpXOE1Whubd+CfF80bZXDQ97cPmPet3iYQhjB8uRoV+/Lx5MUHO5oWofs8hl4k ezhGH4PIqNwSSiJHDZY1vh51XZpb/ECrRmlWD1gfVJkvh2OD8gU9BBkCBbZmU0nbYA+X /5q+Szuhsq7Is6f3z8LZyWwdPak7E642eCK0bsgKR8ypRIQ3sCNTUtAhJ6+Ykgbpnb0c RDOF+bZsOr81z5+631Q6XrUv3JoCClSyo2JAe4IO3yFVPuaV49uOeOi5MxP4vsWjnf+D pHAQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="K/n+oEgu"; 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 o11si6868700edq.506.2021.01.11.05.41.57; Mon, 11 Jan 2021 05:42:22 -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="K/n+oEgu"; 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 S1731706AbhAKNNO (ORCPT + 99 others); Mon, 11 Jan 2021 08:13:14 -0500 Received: from mail.kernel.org ([198.145.29.99]:58982 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730984AbhAKNMX (ORCPT ); Mon, 11 Jan 2021 08:12:23 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 2348622515; Mon, 11 Jan 2021 13:12:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1610370727; bh=jo4RtVvdmWtVgWNCwYhEMwcWPnuklUH9D2hsuT5/PuI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=K/n+oEgu06uXdXoZlemolyHjUTLP3OQoV0gXQsRrAyMKQQTgAbo/eVwnm1JeRCki4 16QRS29f0Mrt9UIpPZnwqHrW+1Y3iPAvxGgdFe5D1TRYcm0bfNxFRQ+D6Ne9DRcIy4 QXQQY3nZtZKaZsxPkC8FIXd9PT2zRy4k1raTEqr4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Peter Chen , Sriharsha Allenki Subject: [PATCH 5.4 72/92] usb: gadget: Fix spinlock lockup on usb_function_deactivate Date: Mon, 11 Jan 2021 14:02:16 +0100 Message-Id: <20210111130042.620240833@linuxfoundation.org> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210111130039.165470698@linuxfoundation.org> References: <20210111130039.165470698@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: Sriharsha Allenki commit 5cc35c224a80aa5a5a539510ef049faf0d6ed181 upstream. There is a spinlock lockup as part of composite_disconnect when it tries to acquire cdev->lock as part of usb_gadget_deactivate. This is because the usb_gadget_deactivate is called from usb_function_deactivate with the same spinlock held. This would result in the below call stack and leads to stall. rcu: INFO: rcu_preempt detected stalls on CPUs/tasks: rcu: 3-...0: (1 GPs behind) idle=162/1/0x4000000000000000 softirq=10819/10819 fqs=2356 (detected by 2, t=5252 jiffies, g=20129, q=3770) Task dump for CPU 3: task:uvc-gadget_wlhe state:R running task stack: 0 pid: 674 ppid: 636 flags:0x00000202 Call trace: __switch_to+0xc0/0x170 _raw_spin_lock_irqsave+0x84/0xb0 composite_disconnect+0x28/0x78 configfs_composite_disconnect+0x68/0x70 usb_gadget_disconnect+0x10c/0x128 usb_gadget_deactivate+0xd4/0x108 usb_function_deactivate+0x6c/0x80 uvc_function_disconnect+0x20/0x58 uvc_v4l2_release+0x30/0x88 v4l2_release+0xbc/0xf0 __fput+0x7c/0x230 ____fput+0x14/0x20 task_work_run+0x88/0x140 do_notify_resume+0x240/0x6f0 work_pending+0x8/0x200 Fix this by doing an unlock on cdev->lock before the usb_gadget_deactivate call from usb_function_deactivate. The same lockup can happen in the usb_gadget_activate path. Fix that path as well. Reported-by: Peter Chen Link: https://lore.kernel.org/linux-usb/20201102094936.GA29581@b29397-desktop/ Tested-by: Peter Chen Signed-off-by: Sriharsha Allenki Cc: stable Link: https://lore.kernel.org/r/20201202130220.24926-1-sallenki@codeaurora.org Signed-off-by: Greg Kroah-Hartman --- drivers/usb/gadget/composite.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) --- a/drivers/usb/gadget/composite.c +++ b/drivers/usb/gadget/composite.c @@ -392,8 +392,11 @@ int usb_function_deactivate(struct usb_f spin_lock_irqsave(&cdev->lock, flags); - if (cdev->deactivations == 0) + if (cdev->deactivations == 0) { + spin_unlock_irqrestore(&cdev->lock, flags); status = usb_gadget_deactivate(cdev->gadget); + spin_lock_irqsave(&cdev->lock, flags); + } if (status == 0) cdev->deactivations++; @@ -424,8 +427,11 @@ int usb_function_activate(struct usb_fun status = -EINVAL; else { cdev->deactivations--; - if (cdev->deactivations == 0) + if (cdev->deactivations == 0) { + spin_unlock_irqrestore(&cdev->lock, flags); status = usb_gadget_activate(cdev->gadget); + spin_lock_irqsave(&cdev->lock, flags); + } } spin_unlock_irqrestore(&cdev->lock, flags);