From patchwork Tue Feb 15 10:15:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Oliver Neukum X-Patchwork-Id: 542995 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 1E829C433EF for ; Tue, 15 Feb 2022 10:16:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235962AbiBOKQL (ORCPT ); Tue, 15 Feb 2022 05:16:11 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:48080 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230217AbiBOKQK (ORCPT ); Tue, 15 Feb 2022 05:16:10 -0500 Received: from de-smtp-delivery-102.mimecast.com (de-smtp-delivery-102.mimecast.com [194.104.109.102]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 639E910E54B for ; Tue, 15 Feb 2022 02:16:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=mimecast20200619; t=1644920158; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type; bh=k5bmSa09/wWkKaEuzd3vLcfD6NRfSloD+hYmHtpCbeU=; b=IYj1FA+EwtIEz6/DC7aZFdGcnklFAuApIfkjmU2CZYIbI7bhxfxIIXNtc6ujVPcG14Uz9Y WtHOyRks0H9KrKLheAj5ci1c+v/UrgX2kKn5/HLFsgAOZUSXsYtQEWc2blm+I7tDBIpZJA /exMh1UhQ7lTn7QV4yNAX2mVnDpYowo= Received: from EUR03-AM5-obe.outbound.protection.outlook.com (mail-am5eur03lp2056.outbound.protection.outlook.com [104.47.8.56]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id de-mta-33-SdUi0ttTOf6qdt6ba4VfJw-1; Tue, 15 Feb 2022 11:15:57 +0100 X-MC-Unique: SdUi0ttTOf6qdt6ba4VfJw-1 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Hd+1MfoGOaJFLDKiQoOHjpiuBOTOTyqawD8gHza2AnMLHkFzwx3IyU4AnxtqMDpgnribZHukfIW9kwmV0ARSvJIc+bdryWai4LyWvJRR6nVInXegfWlTvlXeKMf8doZQbAex/6ml3OvFj0SuKYgSqNifQuKkMoUCZLnVeHkA67+kY1keil/21YkvsOr3sGdADZHR0dZn/YAutrr9Pc4lLze8STmpd2JdSnkd7dhqMAlJVWZ3KTlEJuWV+iALYL8v/DL5DjiFMnCds//QDtf0Dk6bv+I7LooaAMRSB0/tWZpEiQfirPhC/chu5Hn4xA6BKKZU308D5Ce8kfaBLEE96g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=k5bmSa09/wWkKaEuzd3vLcfD6NRfSloD+hYmHtpCbeU=; b=UyGi+dADzhf4XuR5cXBUnIDzSHuCLX1pYku7DDTZ6kmrGpa4A9ZqtlpUxYzs1php3k7K1FqrOefQA+qiqbIyJpISX+QFXQT1WBpfP+mD9rmkZkFtBVIRDj7RTu7gsXBACDsFaZRvRUUW/Sxn43vqc6ATMpe6ihScnguA2b9qPfMZvC1YRHk7M5RjR5WQe7tP1GThxwo5ieNDBMLPnUEhxDKP+jHxwtit08WIHNE7+IaSSPujg5XdrjDfZMpvX+zcc3MnXHrG/ITRe0iwwfEs7CLopGAjz0wp/DFjixiy6Obg/y9Lo3Cs9lJtm5+T1C74i5sTK6LpOq2Mui7n4UtP8w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com; Received: from DB7PR04MB5050.eurprd04.prod.outlook.com (2603:10a6:10:22::23) by AM0PR04MB5492.eurprd04.prod.outlook.com (2603:10a6:208:11c::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4975.18; Tue, 15 Feb 2022 10:15:54 +0000 Received: from DB7PR04MB5050.eurprd04.prod.outlook.com ([fe80::98e0:cb7:30fd:254f]) by DB7PR04MB5050.eurprd04.prod.outlook.com ([fe80::98e0:cb7:30fd:254f%5]) with mapi id 15.20.4975.018; Tue, 15 Feb 2022 10:15:54 +0000 Message-ID: Date: Tue, 15 Feb 2022 11:15:52 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.5.0 Content-Language: en-US To: Guoqing Zhang Cc: USB list From: Oliver Neukum Subject: possible race condition with PM entering test mode X-ClientProxiedBy: AM6P195CA0031.EURP195.PROD.OUTLOOK.COM (2603:10a6:209:81::44) To DB7PR04MB5050.eurprd04.prod.outlook.com (2603:10a6:10:22::23) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 8fc0726c-2b8f-4f21-5b6c-08d9f06c264d X-MS-TrafficTypeDiagnostic: AM0PR04MB5492:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:2150; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 2ChlTsv+CteyusI9gyTBPGrvOrx0U+PCGMtF28WJfT669AOPf4hiRqQKlyJMdorwmuW4yu5nuExZRv3OcRRGittnbA+tHtk3BCNyZIhNd1zsM0RTslvItlhSechcH9v1lCbGTmncs+4CUrfaCfjzLai4gAO1+IpyjU4XjgBx2HYJwdq6MdLVqAd+ASYZGwFwD9QUBEynSFuBqkQcYONo/JFbwMfiN7ojKWkNXEF2iqKoo3zDmC6aG8YT+Pgj7e8BPvwrMVOpXZ/nYwePYXyMn0R7wTTbrg8XdpI/TyBZhc9u26wykhVopavd913I/55k1fSd0Vng/xTybq6doBDQ4ZtndEGQNR0zI9ADwWryT0bbUU9bxDgSidI4TDTrMQFmq0R6J37rnnJGdI7zhiHtIk06AMYWwymKxjCrNsxxKOB5E+APghlSfeXfpzzA5AhwmuxGplJuugOPcf2EmQIWhBTPRbT2PD4CxIwocC4tf5P/74aSgfHrzYQhGqGrkFlH8J5OZ1P+gP4gB2Eu5EoZ1BNDbPrBcBGHPBfjHIkcRbnU+G8Rj0jRAfyx5I98j7FPSWXZpKdlzPcl4GRTOg6hYCFPtURSXHPor1YCjh2I6qdhwEKQkScjdFHaNS/9PXz7Hd1jjEhd4/qS32xvT5DJKLZaSiKx0KhwlStkYOyvhyp3TwW/+OXRTjcCa+q/jRARTJKcEmGtt+1VhHB8lihdIeDcQHOBIw+Nyy5Y+MvsXI4= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DB7PR04MB5050.eurprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230001)(366004)(508600001)(6506007)(6512007)(66946007)(8936002)(8676002)(66476007)(66556008)(2616005)(31686004)(186003)(6916009)(4326008)(6486002)(316002)(36756003)(38100700002)(31696002)(86362001)(2906002)(33964004)(564344004)(235185007)(5660300002)(43740500002)(45980500001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?N3rq8A3K/f3Frj08cSLzBPWqxrl6?= =?utf-8?q?5lJulw0IB6qIBRjdujN6Wde8JxNw8QdF/uTb+cJN2BpOVXhJIqotY2ub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ICBM99MkVZLKFqI3EH?= =?utf-8?q?dyBzqmJjsV6jhs2/Th/ny1S+8UCpRkq/+D1ZwWx+ifdYiaXQEm9i3L0WKlclmR1Wn?= =?utf-8?q?LasUFXVStyljwrROR8YiENETX69Eo4xkEci/dIZqCzJ1Br49GhKbsnl5QnQ/IzioX?= =?utf-8?q?6YBs6JYOUUCYOa66L5rzkmArc7QPbteROCSz/M31pknBVcE5lz/wxiZf7I0k5LqH8?= =?utf-8?q?LU3d90XorPhLD/vPiqdWo1M8ubOdjoV82LOeBtACBC3/Hierc5bsKWs4RDhu9LvYS?= =?utf-8?q?Io/IaBTVguSY2ZvfhAObgJdigUDnvVumAtsVUbCliXrexro8LpB2DD7MMi6NaN2Qy?= =?utf-8?q?dcdk0sbEYslpeVtZZvK/Ok3dKjy8LYa/CgNV7B210JV6uQRTGy7fa5B1Tb5+FVVus?= =?utf-8?q?YTjWVizVX9QdH+q70kL/wG1Vq9/rXdURJFFwtcLdpe1ka6302TbmfRa+1OuouXuNi?= =?utf-8?q?hpetlC+fQro+OUfgVV5C76KQo18hpw2xczk9B5ZFRRhdbOiGATIlwWq8//hvYbK5Q?= =?utf-8?q?jOy0kIH/86jfd4XtxlMjjKy/28vpijIBEfFfoKSznkefep0u2htcWPsPkP4ndCcqF?= =?utf-8?q?2sQrZ2vIjALPI75CSu3WisiSxfc/mXxH3jXR4bD55DjpHGUzl4rxznWsghYRZ6adk?= =?utf-8?q?b9fHFAvlQ4qvC28syj9E6UHUDpSHchXJpLU3UlL1fMv2H3p3SLRE54=3D?= X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8fc0726c-2b8f-4f21-5b6c-08d9f06c264d X-MS-Exchange-CrossTenant-AuthSource: DB7PR04MB5050.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Feb 2022 10:15:54.0467 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: f7a17af6-1c5c-4a36-aa8b-f5be247aa4ba X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: yb5H6zB8FYKqYN+3Xic+5O+vlBJpkmdYygATD7DB1C1q31+6IgF6+6kjqK58MCh0Om9XjOeKiTvs6AdmEQbciw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR04MB5492 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Hi, it looks to me like you need to disable runtime PM earlier if you wish for an undisturbed entry into test mode. Does the attached patch look good to you?     Regards         Oliver >From da128eb84c1ca8195a9a28a0e7157c80075d1685 Mon Sep 17 00:00:00 2001 From: Oliver Neukum Date: Tue, 15 Feb 2022 11:09:22 +0100 Subject: [PATCH] XHCI: race conditions entering test mode If you do not want runtime PM to mess with your HC during test mode, you need to disable it before entering the transition, even if that makes error handling uglier. Signed-off-by: Oliver Neukum --- drivers/usb/host/xhci-hub.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/drivers/usb/host/xhci-hub.c b/drivers/usb/host/xhci-hub.c index df3522dab31b..4bfc71b0ae43 100644 --- a/drivers/usb/host/xhci-hub.c +++ b/drivers/usb/host/xhci-hub.c @@ -709,6 +709,8 @@ static int xhci_enter_test_mode(struct xhci_hcd *xhci, { int i, retval; + /* Disable runtime PM for test mode */ + pm_runtime_forbid(xhci_to_hcd(xhci)->self.controller); /* Disable all Device Slots */ xhci_dbg(xhci, "Disable all slots\n"); spin_unlock_irqrestore(&xhci->lock, *flags); @@ -735,15 +737,17 @@ static int xhci_enter_test_mode(struct xhci_hcd *xhci, xhci_dbg(xhci, "Stop controller\n"); retval = xhci_halt(xhci); if (retval) - return retval; - /* Disable runtime PM for test mode */ - pm_runtime_forbid(xhci_to_hcd(xhci)->self.controller); + goto err_out; /* Set PORTPMSC.PTC field to enter selected test mode */ /* Port is selected by wIndex. port_id = wIndex + 1 */ xhci_dbg(xhci, "Enter Test Mode: %d, Port_id=%d\n", test_mode, wIndex + 1); xhci_port_set_test_mode(xhci, test_mode, wIndex); return retval; +err_out: + /* reset will not work if the HC has not halted */ + pm_runtime_allow(xhci_to_hcd(xhci)->self.controller); + return retval; } static int xhci_exit_test_mode(struct xhci_hcd *xhci) @@ -760,9 +764,10 @@ static int xhci_exit_test_mode(struct xhci_hcd *xhci) if (retval) return retval; } - pm_runtime_allow(xhci_to_hcd(xhci)->self.controller); + retval = xhci_reset(xhci); xhci->test_mode = 0; - return xhci_reset(xhci); + pm_runtime_allow(xhci_to_hcd(xhci)->self.controller); + return retval; } void xhci_set_link_state(struct xhci_hcd *xhci, struct xhci_port *port, -- 2.34.1