From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 93739C04FE0 for ; Mon, 24 Jul 2023 01:44:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232439AbjGXBoq (ORCPT ); Sun, 23 Jul 2023 21:44:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47874 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232358AbjGXBnA (ORCPT ); Sun, 23 Jul 2023 21:43:00 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4E3591FC2; Sun, 23 Jul 2023 18:37:35 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id EFBE560FBE; Mon, 24 Jul 2023 01:33:31 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5C39AC433C8; Mon, 24 Jul 2023 01:33:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1690162411; bh=21tWWeeuHMEWNHK8DfQK8F+75gGlM4Y+yiAz9pIZINc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jQXtDM8WDFmKWxBY1n0hyDmnFAdgoBbyihVdhfzNKiOq0YkYIY6dYjFQt5Ejk2o/y Y74PPlbNAA2SDurBsyGpnFGOKUGE535ah/QUwWCOaUTSpKlSBhqQ+I3sU2D6rJXKPV 77fUFY+V6OYaqGenSht54ewFhUY6zqg28GSN/+4x0ljfpeG/Qalz4ayOoCqLd4B9+6 0LVVD2gHyJEJLAgZlQ22twVVC3p39VV9fjrdJ1sYnOPjX7do1Nd1F08AcL5euBaeg5 KeXJuLA6bZHcEVzI+hw6MCpTWlTRWhpV8fwoh1QFaH5SEpgJpa3XvDiFId7mfHSdSj 5JIS3bdvQUvww== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Prashanth K , Greg Kroah-Hartman , Sasha Levin , balbi@kernel.org, linux-usb@vger.kernel.org Subject: [PATCH AUTOSEL 5.15 03/24] usb: gadget: u_serial: Avoid spinlock recursion in __gs_console_push Date: Sun, 23 Jul 2023 21:33:04 -0400 Message-Id: <20230724013325.2332084-3-sashal@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230724013325.2332084-1-sashal@kernel.org> References: <20230724013325.2332084-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore X-stable-base: Linux 5.15.121 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Prashanth K [ Upstream commit e5990469943c711cb00bfde6338d2add6c6d0bfe ] When serial console over USB is enabled, gs_console_connect queues gs_console_work, where it acquires the spinlock and queues the usb request, and this request goes to gadget layer. Now consider a situation where gadget layer prints something to dmesg, this will eventually call gs_console_write() which requires cons->lock. And this causes spinlock recursion. Avoid this by excluding usb_ep_queue from the spinlock. spin_lock_irqsave //needs cons->lock gs_console_write . . _printk __warn_printk dev_warn/pr_err . . [USB Gadget Layer] . . usb_ep_queue gs_console_work __gs_console_push // acquires cons->lock process_one_work Signed-off-by: Prashanth K Link: https://lore.kernel.org/r/1683638872-6885-1-git-send-email-quic_prashk@quicinc.com Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sasha Levin --- drivers/usb/gadget/function/u_serial.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/usb/gadget/function/u_serial.c b/drivers/usb/gadget/function/u_serial.c index 116d2e15e9b22..23d97a774cc6b 100644 --- a/drivers/usb/gadget/function/u_serial.c +++ b/drivers/usb/gadget/function/u_serial.c @@ -915,8 +915,11 @@ static void __gs_console_push(struct gs_console *cons) } req->length = size; + + spin_unlock_irq(&cons->lock); if (usb_ep_queue(ep, req, GFP_ATOMIC)) req->length = 0; + spin_lock_irq(&cons->lock); } static void gs_console_work(struct work_struct *work) -- 2.39.2