Message ID | 1683638872-6885-1-git-send-email-quic_prashk@quicinc.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp2889987vqo; Tue, 9 May 2023 06:37:33 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5cCcdgDUWJOL7Xla8OHsAJtW2o4MYxFsBqiol7ozlREnJHwsdOTkxnEFMOSwVP3KCDOhAx X-Received: by 2002:a05:6a00:23c3:b0:637:f1ae:d3e with SMTP id g3-20020a056a0023c300b00637f1ae0d3emr19156501pfc.25.1683639453514; Tue, 09 May 2023 06:37:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683639453; cv=none; d=google.com; s=arc-20160816; b=tdRNPiN2G6zP1Dn7yWH0dFZbuOI+IJEroql0by/1U51CG684hDFFhZ7BlDBZZMe2Tv uo7SPrGKzjmH6nXcYXFwir4os5sZHWrqa259I1OzlsLB9ct+x9k8ipMkrT8JOR108jyc dK62BoKnXJ4hl5U1CLN4P6cozvnZfiSvDgWDcuRq4juRAZSurcv6qKrju+Tyqvuy6lj8 BxhomzA6p0zXePQzGtVO/nbhmE8lTisHNfReZA61zZTUr/pJjC+MLFNvTCGUldMzBh6/ iCJvZgijYDkDMU+b/y2TtSvYEPa9T/6WckvaOO7KmRD6h7hhSsFK9FzzLsmH3HFSqStK YE6A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:subject:cc:to:from :dkim-signature; bh=l3r2XEZB1U/YwJZFuK+8z/idqnRnierbtnQr7GRErDg=; b=ANEQFbXN/reC0Ux8uvv5eu65//iK0bgMYkiLwnJKchNyxtS4PQNdJtREx40pHg0Pq4 EO90LV5ekQ6EadbfrYGL/WhJ7O4MsiuO1egNGKuDhTDXwrbB72tQtCQgRTJpP3Vliu4F I/+sj6sk0MM/6itrEHTIBVklD/IdOb0NGR1DU6mgjE8TTh4XbMbwSmE1Em6yAaFRFFYf NI4s7v5lcsyYr/Fy7+fHR2txB01+08pa55Iusfe9oUtyvXN34CcC3LHZVAVI22+W8NVx hOcIsfxeWq0bkNkVzfp+ENLsSxyUO+LGZRG75cFSAh78qvHz38IfDW61v2UL+jIQpHLF syAA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=Onoekuqe; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g15-20020aa79dcf000000b0063d24857c5bsi2502854pfq.43.2023.05.09.06.36.59; Tue, 09 May 2023 06:37:33 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=Onoekuqe; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235482AbjEIN2M (ORCPT <rfc822;baris.duru.linux@gmail.com> + 99 others); Tue, 9 May 2023 09:28:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52422 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235481AbjEIN2G (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Tue, 9 May 2023 09:28:06 -0400 Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D7D232D7E; Tue, 9 May 2023 06:28:05 -0700 (PDT) Received: from pps.filterd (m0279863.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 34996Rkp001145; Tue, 9 May 2023 13:28:01 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h=from : to : cc : subject : date : message-id : mime-version : content-type; s=qcppdkim1; bh=l3r2XEZB1U/YwJZFuK+8z/idqnRnierbtnQr7GRErDg=; b=Onoekuqe4JGOVQo/sRbM4cmkOtWNX+PXQXEY0i7hx6bd1rnAIMMK5aG6XeF+lcQn510F AWzR0EtoKQIIYei6ScTVz8jjBd1txDS3xux9phSI8idToEVrPLMX+HwphXBDrxfwKRx6 4J5p7StRblJ/t7uQjAsYL7iBoRrMOym+CdSC1vfPwvUZoxI1rl3zY9id96zC2KPVDYS5 UEdSaxPYQjVVEA2ncbzva+I6KzSwKt9Ng10lbIn9kImHGK9wBLmSsOIH9Hs1Y6/4QuEU uFxSjyJfT7uIZyxOxlAHJOASHMW4Ynyp1EhRCrB6B9BVIjrLwdWOAqXBRv/TplkhPaYZ 4w== Received: from nalasppmta03.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3qf77h9upa-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 09 May 2023 13:28:00 +0000 Received: from nalasex01a.na.qualcomm.com (nalasex01a.na.qualcomm.com [10.47.209.196]) by NALASPPMTA03.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 349DS0if008934 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 9 May 2023 13:28:00 GMT Received: from hu-prashk-hyd.qualcomm.com (10.80.80.8) by nalasex01a.na.qualcomm.com (10.47.209.196) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.42; Tue, 9 May 2023 06:27:57 -0700 From: Prashanth K <quic_prashk@quicinc.com> To: Greg Kroah-Hartman <gregkh@linuxfoundation.org> CC: Xiu Jianfeng <xiujianfeng@huawei.com>, Christophe JAILLET <christophe.jaillet@wanadoo.fr>, <linux-usb@vger.kernel.org>, <linux-kernel@vger.kernel.org>, Prashanth K <quic_prashk@quicinc.com> Subject: [PATCH] usb: gadget: u_serial: Avoid spinlock recursion in __gs_console_push Date: Tue, 9 May 2023 18:57:52 +0530 Message-ID: <1683638872-6885-1-git-send-email-quic_prashk@quicinc.com> X-Mailer: git-send-email 2.7.4 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.80.80.8] X-ClientProxiedBy: nasanex01b.na.qualcomm.com (10.46.141.250) To nalasex01a.na.qualcomm.com (10.47.209.196) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-GUID: zDJLKpz_KNb4EZp4VVX3sBGHgtmYs-JI X-Proofpoint-ORIG-GUID: zDJLKpz_KNb4EZp4VVX3sBGHgtmYs-JI X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.942,Hydra:6.0.573,FMLib:17.11.170.22 definitions=2023-05-09_08,2023-05-05_01,2023-02-09_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 mlxscore=0 bulkscore=0 impostorscore=0 lowpriorityscore=0 malwarescore=0 priorityscore=1501 suspectscore=0 phishscore=0 mlxlogscore=648 adultscore=0 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2304280000 definitions=main-2305090110 X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1765423923468163012?= X-GMAIL-MSGID: =?utf-8?q?1765423923468163012?= |
Series |
usb: gadget: u_serial: Avoid spinlock recursion in __gs_console_push
|
|
Commit Message
Prashanth K
May 9, 2023, 1:27 p.m. UTC
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 <quic_prashk@quicinc.com>
---
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 a0ca47f..1bc96ff 100644 --- a/drivers/usb/gadget/function/u_serial.c +++ b/drivers/usb/gadget/function/u_serial.c @@ -916,8 +916,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)