From patchwork Fri Sep 22 10:48:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Prashanth K X-Patchwork-Id: 143427 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp5561636vqi; Fri, 22 Sep 2023 06:11:57 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFEZkmAwK68YMlEDya/UkGhytSjWmZVppV7Whca5R1GOK0A2yZLRy2+3Ty/iXP/Z7I6U9ss X-Received: by 2002:aca:6742:0:b0:3a8:4d1f:9da5 with SMTP id b2-20020aca6742000000b003a84d1f9da5mr7752042oiy.31.1695388316718; Fri, 22 Sep 2023 06:11:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695388316; cv=none; d=google.com; s=arc-20160816; b=wryco+YA3UZISGsMmhVIwngyOD/o8ZIodd8l2u3vdZQl25ZFVbtnatjxgVHouYn3vY eqJ3fUkhIJRfTMtbTIarK/5GFFDkFSNCT4PfpCL9LVmH6MkMmUQgMR9RxomOHhActUoc k44KN1ljtmgp7hrr1xm1wMcYemXfPsJWS6Sy+rfZ4E6LI1tyZNPgQDqi1ncPL2o9Tnge gmXRCdpmmDu/5vi6B7VONeE+7z17S3mpkK6uEBs4OLuZw/mrW34ro2gzAiYhW4uzAOtD W2yZWjYso93MxMV9YJt87qbkAZBbHTy1lcRfTvYxgWAWHZNfK9+E4kiMQJ9r7XcVcdXz FuqA== 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=hpO/ZP6cwcezFYAfpFZFentrmwNE3+cuCJGJa6/4z90=; fh=vkHFfyOAVJrq3LpAz8/s5Jdoy7CE19x/KC2e9gz1wNU=; b=w/ImTjQa6r+D2h+USydUr4vuaZL/1cHretPb1+lk8IRhvge1VaJ718EoqyIgjoJp6X jRh+8rAAn71ygb/wextsV9n8aWkhkbmB9QQ+o6RvTTUdfCmEfk7aYP8pTMZ0Z/B64rn1 kUdRQaadzPjHQ6wPMcheC2ayI61XDYJ4xH0s+BpbLVMzG8X5ZuMQzrbtSWWpH/8t7n8/ EpfuLCLKY+qanEUEdcnw2WJidDcFIm7mZuYB+WF88cZTeiajcdu9ruk54Co7y6Ju1arn DHLxRl7RgK6wFoRuVAQiDA+Ihr/xqzchJTJ6yyHjN6V69q+4Qdj66GRyetLIRpuQBVhp Thpw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=NOEqFXk4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 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 lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id n24-20020a056a000d5800b0069109ee0b59si3569931pfv.231.2023.09.22.06.11.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Sep 2023 06:11:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=NOEqFXk4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 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 (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id C96BF829EA26; Fri, 22 Sep 2023 03:49:55 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233446AbjIVKtc (ORCPT + 30 others); Fri, 22 Sep 2023 06:49:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51136 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229810AbjIVKta (ORCPT ); Fri, 22 Sep 2023 06:49:30 -0400 Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7F25C99; Fri, 22 Sep 2023 03:49:24 -0700 (PDT) Received: from pps.filterd (m0279873.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 38M79Du1020281; Fri, 22 Sep 2023 10:49:12 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=hpO/ZP6cwcezFYAfpFZFentrmwNE3+cuCJGJa6/4z90=; b=NOEqFXk4ttcd+iqZgyufhpRAyp2pzHxx3cztxChA44mzuyLsDXRj1xgq6F2oSNawmU7g JiMqXY0Vds2RpghxVSITtPohKqE6sy/jlyjkKlkxOayXK4npWLzW9Unx5ZT11C6bxu74 rDknlUyVlyBO5R6sKzAM9NiijuTEcxGDnzAV+bE5fQH7sK5jKUfHnsuwzn48X9QHrb75 LWmk1z2ew42WUxGcwpoUdeP36uzTEXxNHpLrzmYdASZlBwD6SByY5sRNw++ETKu+qy8p l2UOefhpJLDlm76TGlxONxB7p2kLW8DNnZopmUj2XGfQDrXmdXw23r1XS6M2VTDF+Z6E ag== Received: from nalasppmta01.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3t8u6rsm7n-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 22 Sep 2023 10:49:12 +0000 Received: from nalasex01a.na.qualcomm.com (nalasex01a.na.qualcomm.com [10.47.209.196]) by NALASPPMTA01.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 38MAnBSi012721 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 22 Sep 2023 10:49:11 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.1118.36; Fri, 22 Sep 2023 03:49:07 -0700 From: Prashanth K To: CC: Greg Kroah-Hartman , Hongyu Xie , Mathias Nyman , , Hongyu Xie , Mathias Nyman , "# 5 . 15" , Prashanth K Subject: [PATCH RESEND] xhci: Keep interrupt disabled in initialization until host is running. Date: Fri, 22 Sep 2023 16:18:44 +0530 Message-ID: <1695379724-28628-1-git-send-email-quic_prashk@quicinc.com> X-Mailer: git-send-email 2.7.4 MIME-Version: 1.0 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: Ph53r2qVzdc-EYX6FSdrGQHCYTJrw-cC X-Proofpoint-ORIG-GUID: Ph53r2qVzdc-EYX6FSdrGQHCYTJrw-cC X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-09-22_08,2023-09-21_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 lowpriorityscore=0 adultscore=0 mlxlogscore=686 impostorscore=0 malwarescore=0 mlxscore=0 spamscore=0 bulkscore=0 phishscore=0 suspectscore=0 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2309220091 X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Fri, 22 Sep 2023 03:49:55 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777743499836713623 X-GMAIL-MSGID: 1777743499836713623 From: Hongyu Xie [ Upstream commit 808925075fb750804a60ff0710614466c396db4 ] irq is disabled in xhci_quiesce(called by xhci_halt, with bit:2 cleared in USBCMD register), but xhci_run(called by usb_add_hcd) re-enable it. It's possible that you will receive thousands of interrupt requests after initialization for 2.0 roothub. And you will get a lot of warning like, "xHCI dying, ignoring interrupt. Shouldn't IRQs be disabled?". This amount of interrupt requests will cause the entire system to freeze. This problem was first found on a device with ASM2142 host controller on it. [tidy up old code while moving it, reword header -Mathias] Cc: stable@kernel.org Signed-off-by: Hongyu Xie Signed-off-by: Mathias Nyman Link: https://lore.kernel.org/r/20220623111945.1557702-2-mathias.nyman@linux.intel.com Signed-off-by: Greg Kroah-Hartman Cc: # 5.15 Signed-off-by: Prashanth K --- drivers/usb/host/xhci.c | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c index 541fe4d..7ee747e 100644 --- a/drivers/usb/host/xhci.c +++ b/drivers/usb/host/xhci.c @@ -607,8 +607,27 @@ static int xhci_init(struct usb_hcd *hcd) static int xhci_run_finished(struct xhci_hcd *xhci) { + unsigned long flags; + u32 temp; + + /* + * Enable interrupts before starting the host (xhci 4.2 and 5.5.2). + * Protect the short window before host is running with a lock + */ + spin_lock_irqsave(&xhci->lock, flags); + + xhci_dbg_trace(xhci, trace_xhci_dbg_init, "Enable interrupts"); + temp = readl(&xhci->op_regs->command); + temp |= (CMD_EIE); + writel(temp, &xhci->op_regs->command); + + xhci_dbg_trace(xhci, trace_xhci_dbg_init, "Enable primary interrupter"); + temp = readl(&xhci->ir_set->irq_pending); + writel(ER_IRQ_ENABLE(temp), &xhci->ir_set->irq_pending); + if (xhci_start(xhci)) { xhci_halt(xhci); + spin_unlock_irqrestore(&xhci->lock, flags); return -ENODEV; } xhci->shared_hcd->state = HC_STATE_RUNNING; @@ -619,6 +638,8 @@ static int xhci_run_finished(struct xhci_hcd *xhci) xhci_dbg_trace(xhci, trace_xhci_dbg_init, "Finished xhci_run for USB3 roothub"); + + spin_unlock_irqrestore(&xhci->lock, flags); return 0; } @@ -667,19 +688,6 @@ int xhci_run(struct usb_hcd *hcd) temp |= (xhci->imod_interval / 250) & ER_IRQ_INTERVAL_MASK; writel(temp, &xhci->ir_set->irq_control); - /* Set the HCD state before we enable the irqs */ - temp = readl(&xhci->op_regs->command); - temp |= (CMD_EIE); - xhci_dbg_trace(xhci, trace_xhci_dbg_init, - "// Enable interrupts, cmd = 0x%x.", temp); - writel(temp, &xhci->op_regs->command); - - temp = readl(&xhci->ir_set->irq_pending); - xhci_dbg_trace(xhci, trace_xhci_dbg_init, - "// Enabling event ring interrupter %p by writing 0x%x to irq_pending", - xhci->ir_set, (unsigned int) ER_IRQ_ENABLE(temp)); - writel(ER_IRQ_ENABLE(temp), &xhci->ir_set->irq_pending); - if (xhci->quirks & XHCI_NEC_HOST) { struct xhci_command *command;