From patchwork Tue Mar 28 04:51:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dexuan Cui X-Patchwork-Id: 13190462 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 3CB29C761A6 for ; Tue, 28 Mar 2023 04:53:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230431AbjC1ExQ (ORCPT ); Tue, 28 Mar 2023 00:53:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59476 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230138AbjC1ExO (ORCPT ); Tue, 28 Mar 2023 00:53:14 -0400 Received: from DM6FTOPR00CU001.outbound.protection.outlook.com (mail-cusazon11020027.outbound.protection.outlook.com [52.101.61.27]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9D4FF270F; Mon, 27 Mar 2023 21:53:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=mOUqCaJylJEWODm+hJdAy7Dw6RNtJX/ST/YVMDxgqquWOM9uPqXKUyzv+4RIjRVSlafRa4lZgZEMyh3TGlJwk2dIGU0pg3UuJY5ZHpIZVOLFrHA03OD+OMGDn3gUtT+q5RX7HXfMYFtMULT3LeaUjcy+sSPcwYer68DlZ0LuT+6ld0pBha7AePYSx6/h4dYxO6aZrxY8jYWdS2YNslXbSOs5M4SnJklK9dxlNr/5k5G/0fZnHfoFMZxH42WLwc35tVOi+Xh4scdlPENYs8WlOfZrplwS657RiNTKHzgowMWUnYchvQKZgznnMnSUBgQ5sKvgu+lapklcxYYwqAtvlQ== 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=F1Tzxuc4aIWXApIxi/7jlVJrOCy5V7jrasIaKfenavk=; b=JIw0J7HHjKYEAV30MruAgMyOwU7LaXgPGZSGtkua8f54D32tGEltTBDs9QpVlq0ZdPDbI6k9OvnlfIMieyV8bmc7i2OM+4YnzhQM8iEjMP4dQnYAAFzJuzvyl9M76R44ijsas4JbrSSZGnF7x6hVytJ/SQmZM4bX7WXOJXll6ZaBLbzjB40BeAAvprvZYsZcaNjgxUa2iHN5C2UUNaQyzMe3jHN0F2vv0knrEpzrHs/9J91B3xsdu4OZgG8lssu5o4rKLzz4ME3L9D/YlrGeZs+xtYoezhvXXuv+vieihqTGNJVSAVMMaHQZNQ6RU0M6jOe8OszphhXHi/L0El9O4g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=microsoft.com; dmarc=pass action=none header.from=microsoft.com; dkim=pass header.d=microsoft.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=F1Tzxuc4aIWXApIxi/7jlVJrOCy5V7jrasIaKfenavk=; b=WJIwVyS1m1m70PAhZbPnjvKiA5Cof8S/Cra7e6n710GBTimRsovxxXIMxXYHs6uun+pQJJUxuQkGUsV2RcMN+3QsRPrxdx+edH/dTyEZF7vwZX2tluEIFO4161COzoBxZMXdVdmoG29mp5GHZvIHso+iolluJUoExwOGbxuPhuw= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=microsoft.com; Received: from BL0PR2101MB1092.namprd21.prod.outlook.com (2603:10b6:207:30::23) by IA1PR21MB3402.namprd21.prod.outlook.com (2603:10b6:208:3e1::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6277.6; Tue, 28 Mar 2023 04:53:06 +0000 Received: from BL0PR2101MB1092.namprd21.prod.outlook.com ([fe80::97b2:25ca:c44:9b7]) by BL0PR2101MB1092.namprd21.prod.outlook.com ([fe80::97b2:25ca:c44:9b7%6]) with mapi id 15.20.6277.005; Tue, 28 Mar 2023 04:53:06 +0000 From: Dexuan Cui To: bhelgaas@google.com, davem@davemloft.net, decui@microsoft.com, edumazet@google.com, haiyangz@microsoft.com, jakeo@microsoft.com, kuba@kernel.org, kw@linux.com, kys@microsoft.com, leon@kernel.org, linux-pci@vger.kernel.org, lpieralisi@kernel.org, mikelley@microsoft.com, pabeni@redhat.com, robh@kernel.org, saeedm@nvidia.com, wei.liu@kernel.org, longli@microsoft.com, boqun.feng@gmail.com Cc: linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org, linux-rdma@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH 1/6] PCI: hv: fix a race condition bug in hv_pci_query_relations() Date: Mon, 27 Mar 2023 21:51:17 -0700 Message-Id: <20230328045122.25850-2-decui@microsoft.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230328045122.25850-1-decui@microsoft.com> References: <20230328045122.25850-1-decui@microsoft.com> X-ClientProxiedBy: MW4PR03CA0013.namprd03.prod.outlook.com (2603:10b6:303:8f::18) To BL0PR2101MB1092.namprd21.prod.outlook.com (2603:10b6:207:30::23) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL0PR2101MB1092:EE_|IA1PR21MB3402:EE_ X-MS-Office365-Filtering-Correlation-Id: 585f1308-72af-4103-5705-08db2f48522a X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 7s8m2mgO3EX639PEEmyYkogPz/Rp25q9yitkm7kK2AN6l8FRx+Hrc+4aeWM9DZxvAEKIeSDWud+oFoNiuog54PgZwxEVgAMYNewcKuSbHNZ97v5rHMDZwYJY5WihL0zQsDMNDyhpWDwf/FvQyCcqPAPmXaahrtmPW3Z1DVOIzlY+OmTfu26BINQlaetAuzURq83Tgfh101Cs/ihXTHlo06hNkzH7f8WVKJAMQQ533Y3aMsJSoADTNe7NshbZmVwQzEuUrcgmt/XoJr1GtK5It94xpqp2FPkkNMqxCUkFU/KkQ1zEYIXUYldey8flJNgecjN6jlT+AzPf73rHHaJBD3lmIKdVb8vr3KAYa19tHp58mdRnoH7c0sU48d+Q91PP2zrbHgPBTjBZULYQkSkVL9nR93OfUmsgSXTTzLQiVwEGZYQsEap1utVhjhVOpcZAdJMm3r6pUtEyBlWqtcXAp7NN3xFXRU43PLC+cwLXyniuUk3KIDvoTHtsAa722LcGvYOzzlFJGsSH6m79qNWAmEE0yfe8cKZl6Vd5Jr/Cbj89Ze8KIq+rD3Z/feAGnoRglmncSLNu/1/Uf9L4U9iG/MQKk3TtzTojTyG1aF5XmtrTOiuBDh7zJ8zCgBly4qFVsYe2IGkLE+FDxxhViYIOkw== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BL0PR2101MB1092.namprd21.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(4636009)(346002)(376002)(366004)(396003)(39860400002)(136003)(451199021)(478600001)(83380400001)(10290500003)(2906002)(1076003)(38100700002)(52116002)(7416002)(6486002)(6506007)(6512007)(921005)(2616005)(5660300002)(8936002)(6666004)(316002)(86362001)(82960400001)(82950400001)(186003)(41300700001)(66556008)(66476007)(4326008)(66946007)(8676002)(36756003);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: g/fRPvJtjdfYS2Xn+TyPOY686J5X9PCNGI4uFvBf13f1YoO+uLvQ4RJzzX+TxMo/qTnDRSl+0S3ylBhJulVkO58wilCR8vb5CgfB40HbAOWDh4n7QRF2oVZGTbwKD5lqApeWPz0o4/aErIBOyzruvSTZX6+H/4ual95RK/5ONwJl8xcF7d4cpdg2aUB+ASoRIFLebLFVvOkioo7ZpPojYNsHhsFJhRwC03AvTGCWteX5Sf6E5NY87QP+I6264rH6Princ5yz2kvtqCul711ekVmaen+q+0S8okR4xkko7sB3fwUbmTQPOGMDeWXqXL1EWhi5VRGiOZ6PJRpzgmWfYmNf6MwIM1hk5P+XswmLdPXn98bEeIpClfHc6RILcnBTHQlltkYvA9aVYVEIJ1Pd9Re2tzMHe3zMoNt3G1M34EyFW3Z9/2uQ1Z/mImnlCc4qbiss0wYNRZuN4Dxa/88UyEyIwyxvdhcQgrvidMXg57PtHsH+8gIvQafT79Eyugc+OIEUbvp7QtGa7gBDI1isVZB5Jb3BWsRqdLVOWJ4d2eql5Ol2v5MJHcF+Sz1A1wKC/WezINYcayzXKURR//Rhft9l95t12O2NY5aWSC4m29iI+p9bEBsTHaGaeIFpeEfG7XpQmEEwQaybtYnyhFeLuUlj6UGxMri3X4JQqybpCKQM7z+3bob5GncRYRW7/0mj5Vrc/q0Wx8s67jI5NFkGV67lQFx41q9g1b1vRmakfLd8uDDf+80j/pHSu9RinG0TemM5Sv8xYNyZakCbr/ucxzfpEMSpIoYfgr2UJ8UTA5vsAG7iAeAZsnxNgRapwrtgr29PrWA1ky+plq15DJldNytWs9An8CLtwii9ngsFU4QML7MBXeBRS7cm6zKFVtFvAUCV3j/VtxOtguZKopMcntxNI2krOjWqGQB4LG0mS0M3gNnqVEMMIrLONSUHAbaTwqU13oc+B+Ssgt929P8kuEB1PAcFcDeXr8xlOadSd6mm2RPkidUI39muQlJnTWtZp7722TBiW8Y+RIUxiAfaVA55Q5lppqrXgAJCl/kOwzV0wdupfzNFD4nYJAeyqO7zK1WqV1zhaqOs/muC3TEYKEzAURq4xlTydgTZvY4KlIObOhgh9Yle23l41IdcnyC+hFG0AplGRmHs92gacqcKRZkAoDQcjD5GwsM/K6Cl184EV31yGEx7zMQEU4fwp35ugsWBcWDdnK7cD4zM6w9r2YRd1QlEZYL0Nri9ZOq89F81GQQdDTjOCqO12FuzOk41Svk/iJ7dbqDopbvWJDxYgpvuTFMJtfQrovM72+fJ5/qef5Yf1zy6TSECKtER/dyda9augjRTK/qkz6WKMyI+hyn9UVtoiDyzS3YCgjgvv/kBprjVBQq8ojfy+2/PEV8c36UjxwkhP9yh2IIAr69If4ZpvE+9NS2IKrRTJp0ImoXntwcC8SVOk7AA/aOGDNi3tsEzMVZZLD4A/YZOKEaB7Ha+reimRFgu/nG4ZMehUVDtjEmcBGrDpKA8fXOFs5YQ7otSILEH8MUj+jJ/5R1Y+s6+hElll3YAdBQyohLiz3P7IBt1qo0AK3iSi97Xu42YwsxSTOojV4IKWQSpg2a+aIZu1llrpx1Kun2hHe0Ixbm3E0GiXNS1/mw586PWZuKf X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: 585f1308-72af-4103-5705-08db2f48522a X-MS-Exchange-CrossTenant-AuthSource: BL0PR2101MB1092.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Mar 2023 04:53:06.8983 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: oUs+6AcBoliJdzof1wY4WBkMSoPpHm5kdQ2KrjyfnDIEHU5GpqZYHoG5td42eVOuMEyxniq+SVt0syu+K3vx6A== X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR21MB3402 Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org Fix the longstanding race between hv_pci_query_relations() and survey_child_resources() by flushing the workqueue before we exit from hv_pci_query_relations(). Fixes: 4daace0d8ce8 ("PCI: hv: Add paravirtual PCI front-end for Microsoft Hyper-V VMs") Signed-off-by: Dexuan Cui --- drivers/pci/controller/pci-hyperv.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) With the below debug code: @@ -2103,6 +2103,8 @@ static void survey_child_resources(struct hv_pcibus_device *hbus) } spin_unlock_irqrestore(&hbus->device_list_lock, flags); + ssleep(15); + printk("%s: completing %px\n", __func__, event); complete(event); } @@ -3305,8 +3307,12 @@ static int hv_pci_query_relations(struct hv_device *hdev) ret = vmbus_sendpacket(hdev->channel, &message, sizeof(message), 0, VM_PKT_DATA_INBAND, 0); - if (!ret) + if (!ret) { + ssleep(10); // unassign the PCI device on the host during the 10s ret = wait_for_response(hdev, &comp); + printk("%s: comp=%px is becoming invalid! ret=%d\n", + __func__, &comp, ret); + } return ret; } @@ -3635,6 +3641,8 @@ static int hv_pci_probe(struct hv_device *hdev, retry: ret = hv_pci_query_relations(hdev); + printk("hv_pci_query_relations() exited\n"); + if (ret) goto free_irq_domain; I'm able to repro the below hang issue: [ 74.544744] hv_pci b92a0085-468b-407a-a88a-d33fac8edc75: PCI VMBus probing: Using version 0x10004 [ 76.886944] hv_netvsc 818fe754-b912-4445-af51-1f584812e3c9 eth0: VF slot 1 removed [ 84.788266] hv_pci b92a0085-468b-407a-a88a-d33fac8edc75: The device is gone. [ 84.792586] hv_pci_query_relations: comp=ffffa7504012fb58 is becoming invalid! ret=-19 [ 84.797505] hv_pci_query_relations() exited [ 89.652268] survey_child_resources: completing ffffa7504012fb58 [ 150.392242] rcu: INFO: rcu_preempt detected stalls on CPUs/tasks: [ 150.398447] rcu: 15-...0: (2 ticks this GP) idle=867c/1/0x4000000000000000 softirq=947/947 fqs=5234 [ 150.405851] rcu: (detected by 14, t=15004 jiffies, g=2553, q=4833 ncpus=16) [ 150.410870] Sending NMI from CPU 14 to CPUs 15: [ 150.414836] NMI backtrace for cpu 15 [ 150.414840] CPU: 15 PID: 10 Comm: kworker/u32:0 Tainted: G W E 6.3.0-rc3-decui-dirty #34 ... [ 150.414849] Workqueue: hv_pci_468b pci_devices_present_work [pci_hyperv] [ 150.414866] RIP: 0010:__pv_queued_spin_lock_slowpath+0x10f/0x3c0 ... [ 150.414905] Call Trace: [ 150.414907] [ 150.414911] _raw_spin_lock_irqsave+0x40/0x50 [ 150.414917] complete+0x1d/0x60 [ 150.414924] pci_devices_present_work+0x5dd/0x680 [pci_hyperv] [ 150.414946] process_one_work+0x21f/0x430 [ 150.414952] worker_thread+0x4a/0x3c0 With this patch, the hang issue goes away: [ 186.143612] hv_pci b92a0085-468b-407a-a88a-d33fac8edc75: The device is gone. [ 186.148034] hv_pci_query_relations: comp=ffffa7cfd0aa3b50 is becoming invalid! ret=-19 [ 191.263611] survey_child_resources: completing ffffa7cfd0aa3b50 [ 191.267732] hv_pci_query_relations() exited diff --git a/drivers/pci/controller/pci-hyperv.c b/drivers/pci/controller/pci-hyperv.c index f33370b75628..b82c7cde19e6 100644 --- a/drivers/pci/controller/pci-hyperv.c +++ b/drivers/pci/controller/pci-hyperv.c @@ -3308,6 +3308,19 @@ static int hv_pci_query_relations(struct hv_device *hdev) if (!ret) ret = wait_for_response(hdev, &comp); + /* + * In the case of fast device addition/removal, it's possible that + * vmbus_sendpacket() or wait_for_response() returns -ENODEV but we + * already got a PCI_BUS_RELATIONS* message from the host and the + * channel callback already scheduled a work to hbus->wq, which can be + * running survey_child_resources() -> complete(&hbus->survey_event), + * even after hv_pci_query_relations() exits and the stack variable + * 'comp' is no longer valid. This can cause a strange hang issue + * or sometimes a page fault. Flush hbus->wq before we exit from + * hv_pci_query_relations() to avoid the issues. + */ + flush_workqueue(hbus->wq); + return ret; } From patchwork Tue Mar 28 04:51:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dexuan Cui X-Patchwork-Id: 13190465 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 D0941C77B62 for ; Tue, 28 Mar 2023 04:53:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230468AbjC1ExZ (ORCPT ); Tue, 28 Mar 2023 00:53:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59530 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230269AbjC1ExP (ORCPT ); Tue, 28 Mar 2023 00:53:15 -0400 Received: from DM6FTOPR00CU001.outbound.protection.outlook.com (mail-cusazon11020027.outbound.protection.outlook.com [52.101.61.27]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E1A8F211F; Mon, 27 Mar 2023 21:53:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=CRdlk7vL2GqwyYg0UqsB6OSy3DfzCcZP7vcJUH5xtr0grTt7Y2n/lPLD/+6SLfcbXJ4pn30KXE3MCc102YKztcffZ3Ptx3iUgrjbn5pGY5tq5E0F048lVho6qTVVPpG8O//e7HZS1Dwx0badxSg8dc9EsaPnNme0IkPx9lEx6RtCFY3G+0YeODwczejc6On3b9mZYEsvXR23d9MYXjNz9Q8BCyHt1iBvoizrbvBzzdguuBr+/FO5/voloGVyFrYu0vP4GRGE3sBPBI1WkfHveiwGqMW7LF5jgpzmZn6zjycubJYsNXY7oozB5AghGL9WYdEThs14ATSHVl4nR65RLw== 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=KOudYeSTU9X8aDDWViWGpouAGH7mV9k9HxlIre+s3M8=; b=lPq/Us4lsGRTwUosqY8+T07KC2e/dQMTP07PBgf7tU6Za/00vmKO7GBducofuUvAQTdVSSX/cuoxEHm/DnIRa+YZUrFV9eKAiJPoAMM1U5PdJsWYwcQ5VycTAn7VSQOWk5VKT/UnbXVazsA38JmA7K8R/nkT0M67XK0fEVgBOQ5OG0fk4W9msdJz1nJx8q44If8Roq2ZQMEmMHfcj5xjJVtgykZerfQQoNMpB0tZdBesS6YXI0T7XRaXRG1Dep7aifEw2GSSc6wv6YtlDWTkdq8Ycm9BxIdCAW7YD3KDH4pbljqHp6LHle7lqV1ay45lUrVIRgyF/snGVDGY8uaSlw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=microsoft.com; dmarc=pass action=none header.from=microsoft.com; dkim=pass header.d=microsoft.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=KOudYeSTU9X8aDDWViWGpouAGH7mV9k9HxlIre+s3M8=; b=iKgRQvciWYPwtC6cjMTaIznLo5lZei79MWxPQ9ye1qwncVguqouk+gny7b2B4yzYVT9uxUFCBvVszvjYBy7oiIptY9URde9v6jLnYCafxbWjkP2hWjPnpnHKYj1DVRtgsRv7LAA4yQL4fwtLswEyA66XQ/T20JtAb6sDXnEgUrE= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=microsoft.com; Received: from BL0PR2101MB1092.namprd21.prod.outlook.com (2603:10b6:207:30::23) by IA1PR21MB3402.namprd21.prod.outlook.com (2603:10b6:208:3e1::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6277.6; Tue, 28 Mar 2023 04:53:09 +0000 Received: from BL0PR2101MB1092.namprd21.prod.outlook.com ([fe80::97b2:25ca:c44:9b7]) by BL0PR2101MB1092.namprd21.prod.outlook.com ([fe80::97b2:25ca:c44:9b7%6]) with mapi id 15.20.6277.005; Tue, 28 Mar 2023 04:53:08 +0000 From: Dexuan Cui To: bhelgaas@google.com, davem@davemloft.net, decui@microsoft.com, edumazet@google.com, haiyangz@microsoft.com, jakeo@microsoft.com, kuba@kernel.org, kw@linux.com, kys@microsoft.com, leon@kernel.org, linux-pci@vger.kernel.org, lpieralisi@kernel.org, mikelley@microsoft.com, pabeni@redhat.com, robh@kernel.org, saeedm@nvidia.com, wei.liu@kernel.org, longli@microsoft.com, boqun.feng@gmail.com Cc: linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org, linux-rdma@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH 2/6] PCI: hv: Fix a race condition in hv_irq_unmask() that can cause panic Date: Mon, 27 Mar 2023 21:51:18 -0700 Message-Id: <20230328045122.25850-3-decui@microsoft.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230328045122.25850-1-decui@microsoft.com> References: <20230328045122.25850-1-decui@microsoft.com> X-ClientProxiedBy: MW4PR03CA0013.namprd03.prod.outlook.com (2603:10b6:303:8f::18) To BL0PR2101MB1092.namprd21.prod.outlook.com (2603:10b6:207:30::23) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL0PR2101MB1092:EE_|IA1PR21MB3402:EE_ X-MS-Office365-Filtering-Correlation-Id: b948b4d7-4c48-43bc-ddba-08db2f48537c X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: +uuPSCWKWZvZBs6o5y31xkxg9obPMtuSfgRzDmWchpDRy3xPGwpJRx+Am99/xX/s22+6+/hsXHkMIQwXmMS0XqedJcLXxGRDHNffEDyeTZZjY5ruNFbj92vu5QKbJC8iKV3KB+Ed6D3WTPQVNipY4sUkiR9a2ZMYMU8UcQttRajeXg0B0nRzmP7zdcPN2aoVqZgTU9RhOfxP/5ukSJvyuu51TIGxiJYHVEYizYcTd5dOAXQ+ArfpyV+ePCwMwQx0EtGm8UWRuoEyYNLPMcC3K2V41Rq/nThAgI1TC2/M88vHd+XvY/GcAFMv4URhwDXcHyI7Q5AqhJkqzWGivlYwIjU6w9llnZ/g08RkkCfgHiFfKWxOLePBQkHKXnK94IrKbJCTRZRFp4DiY4tjGQc/cWdCjHZv0U9TaheE51oIbojixDyeyNkLaBPdoeyzb5ZoppFouy2ecevae4LxzB2zMwcFZX6Fq1ckM+nl380EoGUiworuzY0g8h1DXL3FaXLekOTDJw/m1WdWAOGZYAE1L13D+3WIK25EdxrPrnLifc1ZwP4liEFpvnLcubxuFqmBFKZUFobKJEmyj4uFDua8OxOVz91tzk0NrB3ExsQH7rRaqIbKGI0Po8mxyi8y8+AYVln9zYriBJYVZzwdPJhHHw== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BL0PR2101MB1092.namprd21.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(4636009)(346002)(376002)(366004)(396003)(39860400002)(136003)(451199021)(478600001)(83380400001)(10290500003)(2906002)(1076003)(38100700002)(66899021)(52116002)(7416002)(6486002)(6506007)(6512007)(921005)(2616005)(5660300002)(8936002)(6666004)(316002)(86362001)(82960400001)(82950400001)(186003)(41300700001)(66556008)(66476007)(4326008)(66946007)(8676002)(36756003);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: N2lOZCDTEWfOfv/VwV60CQETWH9qbGgVFb0cipBELH6+tNKALnFn3ggfOFGdnB761ovuJgxwiotU5sBUXDBcaunLbiNW3Q2XOCJTsHkiFueK+J803dytV4qR+Ooi4f62H6/lh70wpVdJm9TjDqEy/6aNeMzcWnh9KE2gDGL7LwX15CMyJ87II1P22VHM9p3g0xVB57ER7wzHRZ4c6/W0TmKQU/lVtqMV1Tt2VEj63s9cuitU1yIxVkpOT4tV2YEcPE5LDHQ8zBRsOtBeb7JAl9noKtRCmgKe4GY9DA7A8WlTm9ZWiY19Pv5pdObIOwsGMrFymYhS5W8RhlN65wlvPW/3efe076aE+fkpIju8So9A+uoe5oJh5HwRBvJA+YyN87AX4pK7rM3lL2e2e94NLFg9oEN4jlQoxzFuGuoREd6TIUHMlmITlzCUjxADkeIy4XpX7r0yvnL7oAhkWkIABxKhd5S8ozOaJoBxMWMu7Vf64FeDrrHDBUS2+mFi8z2zdvFjs6+hO/BjvEJiP8tjCjxfTfuBgWgxwGq3oANTRsi5mMn8EkEuSN8a77CSM1KhaYNlJe0fMptKGwUkCQXV2WGKqtLsfn0GC7IgJlmRT1n9LbvfphEPqDm37vANxYof8oJvqlhHCX/snKXNyt9pgM1JPom0hru3neZ5Adpr5zjG6RYbSK6mzYjAe0YeHw9futaLf8Pe/ElUF5xMiiCYvSXGvPm3CTH1KGUcSOnImXMYt72FngBLP27CF8yWoWuUHAPaHrF4TrBZxZFGU8Bzd1NfMgfEF6xp72rRSelMCB9gs0dgT2xrGUKp0CXE+HXE7AirJkMRNe+EhJhTFz+PJzJ9lsu9YhNMnTHGdc0/DSrR8ehv+AxI2qclZuovFFZTiQ13DYvhIFb85DxLYTqhwYVjtYcZWbveM4klSucpReVZDN+xd/tbjea4dyClHtEnrEDxIVJISDzimXkRxK5LsGEUs0wHl7qgQg6KI9SFJGVeRtnNc2CFgqNMR/1JMeLxuxUS1WWoHjxPLKiVrQcGRYUITZcH/cDw+5y11lbd3Kr4mtN/smVesm+6Asi2bjLkKYvaYXwVMCQTrz/dq30YQuziccef4IQ6qqkrVmnw+9fl0UASC+Al0KhrDX5DDWgXrToPO3ft77VRabz7GOt+bvpF1TRDjZMZWxin177p/I4VMQ0ISp2JsvnBeNvX3xCN73aJjRw3hdlGAgS5Z0byYFwKesLijkadFFj7lMM2rjh0Um/4W+ucTHDpC6sZRC46+chqJe2rLTPMHWcalCsHr1iZh335bPZaPBe73Lxn48MrnmKHeciFtbNvrgJzvYde8xTAPid/vXLqxLA7n1WzAYZHPPj/JHXioAG4KOqBDcn2TDYuDpLy8jokl3WdkSNMPZ2Gdmp3r8IDoQxMnz4au6Nqm1S1t4vWJfmkunXMQ6ZJzrq0/lsExwHoo4F1vEFRH+rdhYvca2Wl6PpVwGSNp54Ud7M8jqWSkgZ6g6RJqGfEzwyOOHuwiroCh8GBi7R+mlWrrJbNpruuJjyKSZviv20g82OC8TOFOogF6fUEkU7npOz60xJfrvR3vjT+P8c0Gwz7BDK+PG8pVriuO8aBt3DYV+Kr9Vfp9rqHnAGZVrzkKFztLOxc9TCZEYiVo7iD X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: b948b4d7-4c48-43bc-ddba-08db2f48537c X-MS-Exchange-CrossTenant-AuthSource: BL0PR2101MB1092.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Mar 2023 04:53:08.9043 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: l3uu3Tk0EUxPtVBHfFFxfZRTtZ4Jm0/BqKlQjBmRdfMpVJIGvkSYCcSG6khdy1ACU9XjMRCSS3oxwjKZpmRJqg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR21MB3402 Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org When the host tries to remove a PCI device, the host first sends a PCI_EJECT message to the guest, and the guest is supposed to gracefully remove the PCI device and send a PCI_EJECTION_COMPLETE message to the host; the host then sends a VMBus message CHANNELMSG_RESCIND_CHANNELOFFER to the guest (when the guest receives this message, the device is already unassigned from the guest) and the guest can do some final cleanup work; if the guest fails to respond to the PCI_EJECT message within one minute, the host sends the VMBus message CHANNELMSG_RESCIND_CHANNELOFFER and removes the PCI device forcibly. In the case of fast device addition/removal, it's possible that the PCI device driver is still configuring MSI-X interrupts when the guest receives the PCI_EJECT message; the channel callback calls hv_pci_eject_device(), which sets hpdev->state to hv_pcichild_ejecting, and schedules a work hv_eject_device_work(); if the PCI device driver is calling pci_alloc_irq_vectors() -> ... -> hv_compose_msi_msg(), we can break the while loop in hv_compose_msi_msg() due to the updated hpdev->state, and leave data->chip_data with its default value of NULL; later, when the PCI device driver calls request_irq() -> ... -> hv_irq_unmask(), the guest crashes in hv_arch_irq_unmask() due to data->chip_data being NULL. Fix the issue by not testing hpdev->state in the while loop: when the guest receives PCI_EJECT, the device is still assigned to the guest, and the guest has one minute to finish the device removal gracefully. We don't really need to (and we should not) test hpdev->state in the loop. Fixes: de0aa7b2f97d ("PCI: hv: Fix 2 hang issues in hv_compose_msi_msg()") Signed-off-by: Dexuan Cui --- drivers/pci/controller/pci-hyperv.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) With the below debug code: @@ -643,6 +643,9 @@ static void hv_arch_irq_unmask(struct irq_data *data) pbus = pdev->bus; hbus = container_of(pbus->sysdata, struct hv_pcibus_device, sysdata); int_desc = data->chip_data; + if (!int_desc) + dev_warn(&hbus->hdev->device, "%s() can not unmask irq %u\n", + __func__, data->irq); spin_lock_irqsave(&hbus->retarget_msi_interrupt_lock, flags); @@ -1865,6 +1868,11 @@ static void hv_compose_msi_msg(struct irq_data *data, struct msi_msg *msg) goto free_int_desc; } + printk("%s: line %d: irq=%u\n", __func__, __LINE__, data->irq); + { + static bool delayed; //remove the device within the 10s. + if (!delayed) { delayed = true; mdelay(10000); } + } ret = vmbus_sendpacket_getid(hpdev->hbus->hdev->channel, &ctxt.int_pkts, size, (unsigned long)&ctxt.pci_pkt, &trans_id, VM_PKT_DATA_INBAND, I'm able to repro the below panic: [ 23.258674] hv_pci b92a0085-468b-407a-a88a-d33fac8edc75: PCI VMBus probing: Using version 0x10004 [ 23.271313] hv_pci b92a0085-468b-407a-a88a-d33fac8edc75: PCI host bridge to bus 468b:00 [ 23.274554] pci_bus 468b:00: root bus resource [mem 0xfe0000000-0xfe00fffff window] [ 23.277733] pci_bus 468b:00: No busn resource found for root bus, will use [bus 00-ff] [ 23.283845] pci 468b:00:02.0: [15b3:1016] type 00 class 0x020000 [ 23.289796] pci 468b:00:02.0: reg 0x10: [mem 0xfe0000000-0xfe00fffff 64bit pref] [ 23.296463] pci 468b:00:02.0: enabling Extended Tags ... [ 23.331300] pci_bus 468b:00: busn_res: [bus 00-ff] end is updated to 00 [ 23.334130] pci 468b:00:02.0: BAR 0: assigned [mem 0xfe0000000-0xfe00fffff 64bit pref] [ 23.507985] mlx5_core 468b:00:02.0: no default pinctrl state [ 23.510834] mlx5_core 468b:00:02.0: enabling device (0000 -> 0002) [ 23.516843] mlx5_core 468b:00:02.0: firmware version: 14.25.8102 [ 23.745069] hv_compose_msi_msg: line 1871: irq=24 [ 33.685554] hv_pci b92a0085-468b-407a-a88a-d33fac8edc75: the device is being ejected [ 33.690855] hv_compose_msi_msg: line 1871: irq=25 [ 33.694797] hv_compose_msi_msg: line 1871: irq=26 [ 33.698884] hv_compose_msi_msg: line 1871: irq=27 [ 33.702910] hv_compose_msi_msg: line 1871: irq=28 [ 33.705726] hv_compose_msi_msg: line 1871: irq=29 [ 33.709644] hv_compose_msi_msg: line 1871: irq=29 [ 33.712182] hv_pci b92a0085-468b-407a-a88a-d33fac8edc75: hv_arch_irq_unmask() can not unmask irq 29 [ 33.716625] BUG: kernel NULL pointer dereference, address: 0000000000000008 ... [ 33.737426] Workqueue: events work_for_cpu_fn [ 33.739562] RIP: 0010:hv_irq_unmask+0xc2/0x400 [pci_hyperv] ... [ 33.778511] Call Trace: [ 33.779533] [ 33.780428] unmask_irq.part.0+0x23/0x40 [ 33.781994] irq_enable+0x60/0x70 [ 33.783336] __irq_startup+0x5b/0x80 [ 33.784772] irq_startup+0x75/0x140 [ 33.786175] __setup_irq+0x3ae/0x840 [ 33.787586] request_threaded_irq+0x112/0x180 [ 33.789298] mlx5_irq_alloc+0x111/0x310 [mlx5_core] [ 33.791464] irq_pool_request_vector+0x72/0x80 [mlx5_core] [ 33.794449] mlx5_ctrl_irq_request+0xc9/0x160 [mlx5_core] [ 33.797454] mlx5_eq_table_create+0x9e/0xb30 [mlx5_core] [ 33.802127] mlx5_load+0x54/0x3b0 [mlx5_core] [ 33.804157] mlx5_init_one+0x1e6/0x550 [mlx5_core] [ 33.806347] probe_one+0x2e5/0x460 [mlx5_core] [ 33.808664] local_pci_probe+0x4b/0xb0 [ 33.810377] work_for_cpu_fn+0x1a/0x30 [ 33.812275] process_one_work+0x21f/0x430 [ 33.814700] worker_thread+0x1fa/0x3c0 diff --git a/drivers/pci/controller/pci-hyperv.c b/drivers/pci/controller/pci-hyperv.c index b82c7cde19e6..1b11cf739193 100644 --- a/drivers/pci/controller/pci-hyperv.c +++ b/drivers/pci/controller/pci-hyperv.c @@ -643,6 +643,11 @@ static void hv_arch_irq_unmask(struct irq_data *data) pbus = pdev->bus; hbus = container_of(pbus->sysdata, struct hv_pcibus_device, sysdata); int_desc = data->chip_data; + if (!int_desc) { + dev_warn(&hbus->hdev->device, "%s() can not unmask irq %u\n", + __func__, data->irq); + return; + } spin_lock_irqsave(&hbus->retarget_msi_interrupt_lock, flags); @@ -1911,12 +1916,6 @@ static void hv_compose_msi_msg(struct irq_data *data, struct msi_msg *msg) hv_pci_onchannelcallback(hbus); spin_unlock_irqrestore(&channel->sched_lock, flags); - if (hpdev->state == hv_pcichild_ejecting) { - dev_err_once(&hbus->hdev->device, - "the device is being ejected\n"); - goto enable_tasklet; - } - udelay(100); } From patchwork Tue Mar 28 04:51:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dexuan Cui X-Patchwork-Id: 13190463 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 5A48FC77B6D for ; Tue, 28 Mar 2023 04:53:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231477AbjC1ExT (ORCPT ); Tue, 28 Mar 2023 00:53:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59566 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230142AbjC1ExP (ORCPT ); Tue, 28 Mar 2023 00:53:15 -0400 Received: from DM6FTOPR00CU001.outbound.protection.outlook.com (mail-cusazon11020023.outbound.protection.outlook.com [52.101.61.23]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7F6402139; Mon, 27 Mar 2023 21:53:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ZRw2kVrKCF5ZhzxCApq8B0aL8VNeUvazaxsAjXf84BsU/IKgdjuvxTVyrNik22KMXCbmEsOldR34A7dV1u4xuJmJrp+gIfv3gZuxQHgOXSAeLTmKFuGIHPVEtKaVOl6NClBxBnej3K1IpUuGudy5ym4IX/aom9xSd9QTBoQJOHeIN5Xpoqfjp1cR237rU053wfRn7a1HjivaKZ3TA+rB9ZrL07E+0UBPJLkBrEi9sl4oK5Ce4ReU21MKShIl184OO+Il5T1cH+FC5y6Zo7se50IqCeFDA6GMe9R7bp41k8JpdeXrB8rHpxN/JD28bnhHKPKFUmcDDWz0KrxQoUhnFw== 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=Q+LurV+FUeNXwWGPJozwHjAJOkAQZ573EunRNVw6njA=; b=Le6UQgHoHn70VHqMmNKWhupk0eJRC0EIyZ6xsNV4XG7MNnrOmKTmfTAnBy+JhJ9nY3ZmcdvqGVA/jOHQ9cfD0UAOyZzKj0TscQ8EsgonxSO/qei9Ut4gjpMoRJFGo86epyDO4ol3p6UAvMiLzMEh/sZHRDiRsTdT4cAb39d4ZLI7ofNi/AMGB2xlkqFwWCmQbCWcugfB13pT6hcYWNEKc40IBTtgDe3KP/5nsCqrL21GsiNS6uEQFzvX1b1GeHDgPU5H/zWFm1r25svhKNvnXbt/lmbMykRTrlMSAEMAwWVifZWB5bHUGywLmDvnXX8hFD3dtFjd06MGeMG2kSxi5g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=microsoft.com; dmarc=pass action=none header.from=microsoft.com; dkim=pass header.d=microsoft.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Q+LurV+FUeNXwWGPJozwHjAJOkAQZ573EunRNVw6njA=; b=WnTjfKRocJDftxYA1NzqoWJPEvszCmrTVejm4IYWAYkcS/A/96fqnnEAqHUZwrsbfYoGsPfA9ocSdKmKXPmhaKOw+UkJYLUEY6xlGO5QSEzZ4fKEHgVwYNtXYNMg1CejUxBcr2ATFagrDDe1JPSPcZqIC1R93Gjz67rKzm7DrQc= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=microsoft.com; Received: from BL0PR2101MB1092.namprd21.prod.outlook.com (2603:10b6:207:30::23) by IA1PR21MB3402.namprd21.prod.outlook.com (2603:10b6:208:3e1::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6277.6; Tue, 28 Mar 2023 04:53:11 +0000 Received: from BL0PR2101MB1092.namprd21.prod.outlook.com ([fe80::97b2:25ca:c44:9b7]) by BL0PR2101MB1092.namprd21.prod.outlook.com ([fe80::97b2:25ca:c44:9b7%6]) with mapi id 15.20.6277.005; Tue, 28 Mar 2023 04:53:10 +0000 From: Dexuan Cui To: bhelgaas@google.com, davem@davemloft.net, decui@microsoft.com, edumazet@google.com, haiyangz@microsoft.com, jakeo@microsoft.com, kuba@kernel.org, kw@linux.com, kys@microsoft.com, leon@kernel.org, linux-pci@vger.kernel.org, lpieralisi@kernel.org, mikelley@microsoft.com, pabeni@redhat.com, robh@kernel.org, saeedm@nvidia.com, wei.liu@kernel.org, longli@microsoft.com, boqun.feng@gmail.com Cc: linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org, linux-rdma@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH 3/6] PCI: hv: Remove the useless hv_pcichild_state from struct hv_pci_dev Date: Mon, 27 Mar 2023 21:51:19 -0700 Message-Id: <20230328045122.25850-4-decui@microsoft.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230328045122.25850-1-decui@microsoft.com> References: <20230328045122.25850-1-decui@microsoft.com> X-ClientProxiedBy: MW4PR03CA0013.namprd03.prod.outlook.com (2603:10b6:303:8f::18) To BL0PR2101MB1092.namprd21.prod.outlook.com (2603:10b6:207:30::23) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL0PR2101MB1092:EE_|IA1PR21MB3402:EE_ X-MS-Office365-Filtering-Correlation-Id: 8d7484dd-7374-4c01-0434-08db2f4854ae X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: +Gl9NRIUB/xsCvP9JKv1n19t+c7ixhP/rDrkuBJysmHdGgzCGpJCqN1VaojIfPRoUGF3McjIDUbBNOOseqaK3OlqAqmkhBDEZs7wqRk2+TvWicFr2cVPZZS+hizwJ+llho9AwHAEHE/chZ7vyLKyxZy/+SBY2rqjy4VMKq1l82SiNWwdVNtxdupz6FiDnkIXodZIxTQr/Afd9NNFtw5pz5DlbiLd6V2h/ghVb3E4byUT4LlDKJBPX7Ba0ovkWYPktf/XBCf5rDpyGVZhVkhFhPlaB/qaFzx9K+SPrniDbmbMU3BnbqJk7AogS2+KOMWPDtBB7e2wJbPg7qRiTRFf7ExtgbGIKTQcjfjhR6q7uDCvourMAZE3Jzrfu2je5enJfUd0aIyVzcavGV+rEQh679pJtHKkkJLATARslci9TI9X929nh9+2jzfV2M8ekAB/eTyOg+/eMeGBohKu6AEZbvlb0lb2+6V5OGohgGrmpiLzfJQ2lgCF61YDk6DMnWPo4Gc4yfLA6h/azFlOvrpwJJy1N0/ZpQeTKQ7JXdlnV8YbBLG9XCG5wD69ClRfKcvn+viO8MJNiwAheKoFW12y/e7inGpdMGJ8TxXjxwjh6mWuoLDlwHaova8fjddJAgnjLir3UyPHb0UGLMKTXoCFGw== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BL0PR2101MB1092.namprd21.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(4636009)(346002)(376002)(366004)(396003)(39860400002)(136003)(451199021)(478600001)(83380400001)(10290500003)(2906002)(1076003)(38100700002)(52116002)(7416002)(6486002)(6506007)(6512007)(921005)(2616005)(5660300002)(8936002)(316002)(86362001)(82960400001)(82950400001)(186003)(41300700001)(66556008)(66476007)(4326008)(66946007)(8676002)(36756003);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: sTzcW86ITtseHJKJxTVpbjfDN02dd+TrxAVZ5hV3mZU01pr5Ex2RibKL63S323N/JHTnksiuYFMX+VAAz6QYKQNhqawCpZeG9JUc1MTgo1o6cLqmQYzaFQ09tzP2rgkEkmQkFXmSmO5RiGxgvcfdQ9PRv+uTwE7U3Ntd41JtYo5qWMewcQFaoFiQJ6XgU1WZAIpt78blRys2RxIBG69J/4AmbMM90t31qXWJUnSxy2WXMgn+R/DKcihIXT1/NP4g4//QJPJAx7iLsJOTucYD83Y4phRc1avtiOa0GiVyKbL99PUAmscMHXAp21qhbLB3wAQilhKaAlIyNl32BLHif+PMXEDPu/HLPP1Rcc+OsmyX/sT+YjgBQ3sKUL2wGCSI76wBnGMfNVivLyPOziF30yY4bXr1CnDqY0XUmHQsmeI1EhbJSBunP1CL7NMJwQloXNCdMPJ3sP8xfJN9aYTlyLBSawf6SBuBlX8a+7bGeAf54JNdZGxMxbJPAIaBWA1mbpt2COcoPNSXOERN63Nu7410sJrPw+ABHyFxld6HHB1TOn1Q6AVpqIyHhGEm7k/jJjVWuIA0+8N3oe5LtA0FoQnWoAzMPQYQjXz1pKnZg9l1HwHbbjZb8TVPCVnSrBJkhFrS4qafkQiTnOSOCKVwzZnNSeBRKmC03ewpskb9ktck/yXe/0g61e6NBmRaVMYlPPaOIQUllgYzz2zGcxs4TnVGYEJIWgZiPS6THjfDnbd70DTTw9zY+Ko0WWzBugVNM6PpJv2atOq/VGHdb1VK+rAuO1IP0C6XwW5IGL0JGE+SyRPIX6WxGuW7zi9fJzIxbdEmXzpaey1waJtdk605G3lbBIvYbwXKUwhdrU+AM+jJ/jaZVyLRlk6TDCkc4wN3w5QmUHeBYyAIyjuBWwtSzLMHvmx1iGiG1fKtq1+oBHW9aa6PPVRQvD4suIMQh8VNE/yz5v8bZd1Boiu+FAIkty9lasn4rtobdi3EIn0cnrAG0RUoa0cdNc4zsks/JxflX9E4366tp8AZzRiXrcWU0XsAYT5qezPV4uQAc7+VEx1cQplQ6XZ+AJHe+zsKnNlK9Y2KSWpEJYFnYxCZ0vt5ViTRW5qhpZzfVnsDdVkK1z5eoRr+Ros/vuxl/WaRZLbHolF0uOzV+egyQnetMF91j67egEXjg4FaSC/3iH1xVVbRnc+HWWLExFtlfDpsrl0KmJwzR+lIcPZAUN7aCQ5wry9qqMwbU0k3vnbJRokgd6q0P7+kIqUG91wMqqyD3lxP+mY4Nfc0pKF4voxhNr8xa3yv2nJhDGWUTqyjFC8n3CKIZg5phcmzgR9DaFoOmr9bT8KwZ9O5wDoqQwo42eB/nqzc5noiROTnzSKg0mfkbuag/Cfmb8vBIxxYrCbk6VzJirdxwM0xxZSKQyIopbSIcvwaWebNFur9sGUqEKFWedqiA4PfurGdPEKkjc80i8GC/eKm6hRBxr0q+WCBgb9dt4V2Us6FXbI93RqQM51FQP10zTLG8euS6HgxZFDIFefSbevDqy5QFeW/xbtvVdg3+mI5iTU3rXz708fZtVVxNcKK9c4nam1C+m14uzrQR4yH2KVu4oBhNalplvjziAduVweLvUiRRtzv8G1ynYb5A/XGrMIqkG+t3R6T8YLZbeBx X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8d7484dd-7374-4c01-0434-08db2f4854ae X-MS-Exchange-CrossTenant-AuthSource: BL0PR2101MB1092.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Mar 2023 04:53:10.8951 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: wv8TId7ue8jIBdHYyYbsrnCwGqk9fxx7y0WC6eURJWi2QoMGPMHHC/KsJZpR9SToHrlEK0ho75Af2E+9PLb/Gw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR21MB3402 Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org The hpdev->state is never really useful. The only use in hv_pci_eject_device() and hv_eject_device_work() is not really necessary. Signed-off-by: Dexuan Cui --- drivers/pci/controller/pci-hyperv.c | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/drivers/pci/controller/pci-hyperv.c b/drivers/pci/controller/pci-hyperv.c index 1b11cf739193..46df6d093d68 100644 --- a/drivers/pci/controller/pci-hyperv.c +++ b/drivers/pci/controller/pci-hyperv.c @@ -553,19 +553,10 @@ struct hv_dr_state { struct hv_pcidev_description func[]; }; -enum hv_pcichild_state { - hv_pcichild_init = 0, - hv_pcichild_requirements, - hv_pcichild_resourced, - hv_pcichild_ejecting, - hv_pcichild_maximum -}; - struct hv_pci_dev { /* List protected by pci_rescan_remove_lock */ struct list_head list_entry; refcount_t refs; - enum hv_pcichild_state state; struct pci_slot *pci_slot; struct hv_pcidev_description desc; bool reported_missing; @@ -2750,8 +2741,6 @@ static void hv_eject_device_work(struct work_struct *work) hpdev = container_of(work, struct hv_pci_dev, wrk); hbus = hpdev->hbus; - WARN_ON(hpdev->state != hv_pcichild_ejecting); - /* * Ejection can come before or after the PCI bus has been set up, so * attempt to find it and tear down the bus state, if it exists. This @@ -2808,7 +2797,6 @@ static void hv_pci_eject_device(struct hv_pci_dev *hpdev) return; } - hpdev->state = hv_pcichild_ejecting; get_pcichild(hpdev); INIT_WORK(&hpdev->wrk, hv_eject_device_work); queue_work(hbus->wq, &hpdev->wrk); From patchwork Tue Mar 28 04:51:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dexuan Cui X-Patchwork-Id: 13190464 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 83FE7C761A6 for ; Tue, 28 Mar 2023 04:53:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229975AbjC1ExX (ORCPT ); Tue, 28 Mar 2023 00:53:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59552 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231279AbjC1ExS (ORCPT ); Tue, 28 Mar 2023 00:53:18 -0400 Received: from DM6FTOPR00CU001.outbound.protection.outlook.com (mail-cusazon11020018.outbound.protection.outlook.com [52.101.61.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6724A26A6; Mon, 27 Mar 2023 21:53:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=WKAeYNZUF6dp/2zJWLCtXnuaCPUnuv+TvFDoEBW3wV6dsBjR0iupethHynkqP7K9FCSt7zua9pRzWKHCMVMxkBpmFfZrxCu6Drs2wf4ex4rQsVlHrVbyOD2Gm7pfgzZAIa+XyoF5Ts4nVOpvcGgjbJZi00WzV91yhojaodbW8I8HV01Qb6YB2zOQp/y4lYuMjgiDDBQ4v3Iue48IDSl0LaoZsrBXmpTLHaBu+z/n7vFMaSTMU93NcZZHjGh7SffA8vlPBQcg0am35pXB0zWgVZh1GH7wzYhUUUsjrqv63USf55kRsWeEB+51VFI7P2mGSfJcqf16BItpFVPAzB5aUA== 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=r602AhK3lP3IJo/nC+/46SPMWQHOXhGqOgHGO5+GLUQ=; b=LkCP9rTinfyhxCUH66zGkLPZkEbnjWWoN2Pgm0Utwmt8fmaPNhuOLrPaHnHsIuPO2lnT0H9YjWSKOwcOCxnq5Wx2szQc9nSV+sQ93ini/lc2hcFPTo7mTdRizdZ/cN+bWIOqA6/24aCKSmUc8Sa+vRmVQDaUkhUY3b6E/0ZyL20HavpUKO59CACuInR42NEZh0Xl1KiIyeVT84H4TNxS7FPyoZPyHYE/jhO05iGO7wGxuyuNKKc9AJH/iMGXENl8b9sHP06G6W72Ob4LF7yeXbEUmPMZWuPma0yz0WgGxyY/eX8aR8vyYBMHvDXu73tss1SQFBGkwiM5sInDL7Z5vQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=microsoft.com; dmarc=pass action=none header.from=microsoft.com; dkim=pass header.d=microsoft.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=r602AhK3lP3IJo/nC+/46SPMWQHOXhGqOgHGO5+GLUQ=; b=bG7amG6HXu2oxdowyZbvT7qOLk1mJz5ryaCwwF38jdJHpc6CDSckwX7TbPNOy2PMAWLudZy2nsrCeKLP/J/x+OLbeTXXcW9vBAPDhUHXa3Hd1UHXjuQ/nQEQeXAcE/pYQNm0S4TToYK4/edUU1kJ3bCkVST9TMpe5wm2q6EOzuw= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=microsoft.com; Received: from BL0PR2101MB1092.namprd21.prod.outlook.com (2603:10b6:207:30::23) by IA1PR21MB3402.namprd21.prod.outlook.com (2603:10b6:208:3e1::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6277.6; Tue, 28 Mar 2023 04:53:12 +0000 Received: from BL0PR2101MB1092.namprd21.prod.outlook.com ([fe80::97b2:25ca:c44:9b7]) by BL0PR2101MB1092.namprd21.prod.outlook.com ([fe80::97b2:25ca:c44:9b7%6]) with mapi id 15.20.6277.005; Tue, 28 Mar 2023 04:53:12 +0000 From: Dexuan Cui To: bhelgaas@google.com, davem@davemloft.net, decui@microsoft.com, edumazet@google.com, haiyangz@microsoft.com, jakeo@microsoft.com, kuba@kernel.org, kw@linux.com, kys@microsoft.com, leon@kernel.org, linux-pci@vger.kernel.org, lpieralisi@kernel.org, mikelley@microsoft.com, pabeni@redhat.com, robh@kernel.org, saeedm@nvidia.com, wei.liu@kernel.org, longli@microsoft.com, boqun.feng@gmail.com Cc: linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org, linux-rdma@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH 4/6] Revert "PCI: hv: Fix a timing issue which causes kdump to fail occasionally" Date: Mon, 27 Mar 2023 21:51:20 -0700 Message-Id: <20230328045122.25850-5-decui@microsoft.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230328045122.25850-1-decui@microsoft.com> References: <20230328045122.25850-1-decui@microsoft.com> X-ClientProxiedBy: MW4PR03CA0013.namprd03.prod.outlook.com (2603:10b6:303:8f::18) To BL0PR2101MB1092.namprd21.prod.outlook.com (2603:10b6:207:30::23) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL0PR2101MB1092:EE_|IA1PR21MB3402:EE_ X-MS-Office365-Filtering-Correlation-Id: 502a4588-6066-4f16-6614-08db2f4855da X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: W4ptgAIaeK7c+hL0WFjcPj1ic5OtXe1xgYixxzw9Qrct49TR0d+oo6OUjZQPVlEfjee08ql6tfzXsFoWmkKHnTsTrPyQuO3iMrULoBi55y47pf9IzrX2grxtySlX0Kg/vatq8uq90GdQx/Y3YdsWTA4yF6ymmq2rm+hRcfco4N76LVJHiKq68BK7pC4ivoL5Jk/bo6PHoayCkQJ9VB/FELAWwZtNJQn7vx8/PRq8jZGhDSj5xKIpMngf27ohIUKgoQ745X5bEcB8fRaMGW01E1ynEpDCRu36EU7m71TQM9hUjm+y2VHJWELRkSX1d4E93aE9C7soy8QbbmvGKqH/wU0LDu7qYesTdffwvxUSYFR6PgA9kFYCWqi+KJscvq5hladLv8/YUMhiXUtuFtjLz7SjT82cPcjEqR4GRsBumMV8tjbjkFgYB6qBW+JHk0+3NADxajic6LZOWOOJWARjmDjp0nxpnIZ/6jpbCBtwHfVD3fBrJdoo0mDKFxNIHPujy3Bmdmwh2/x4QZOuytq4PCQpgzONMX0bPgpDsllmdA/mucL5FIx/OClh1SPH0aDrQtDVq89HxI0T+3yZC6bCeCsWmdV5n1nrk6myf8cFzfTGQSdbnL0TiASo6NDW0iv24ZaB1qMI3aO6Dsm73t6ozg== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BL0PR2101MB1092.namprd21.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(4636009)(346002)(376002)(366004)(396003)(39860400002)(136003)(451199021)(478600001)(83380400001)(10290500003)(2906002)(1076003)(38100700002)(52116002)(7416002)(6486002)(6506007)(6512007)(921005)(2616005)(5660300002)(8936002)(6666004)(316002)(86362001)(82960400001)(82950400001)(186003)(41300700001)(66556008)(66476007)(4326008)(66946007)(8676002)(36756003);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: VsKuDBijtF6cjuWgoO8+pVjZKh+BG8JvZri3aoPrG/W3wj2iJGrFUUKIVTg/BZJhOipl4n/TU78y9PgiwGTwpYgowZnUG/SpfMFBvE3e2L4Ky2AClWfuScS6Wt5GPQ7ldcGmLwvW9D4seNnJdQh54FIhJ1+iYHg+qK3Qiu3/hzfnI9p1PxTnqq9wszxk9c4Z/R3JGmep20YBlu2c55pwfB+0KR97IeinImcacZqhRtIM9QGlc3oINQJ6pSywvUvlhvoqEFJUM+b8A+l7O82UCRkiup4OQrMOjSSIlH2SUH8giSc4HtwZ1z3RKR7kJD83eatD8npfxdcY+3BIeZuDrGGRyKUbQ0m6G6QQ6WVInsRHW27Cl3DTCqhqschJRMJGKQZ9jMdFPAauo5XRdJ9XSxzoWyFKZfM77x3JuQnujUGyqbHiLaaIn8shTa+wcMIvo3aQJZhdJ+/Fdly2XpoJo+ps5hUXUHrMbSLhyh8DsyH2byc2avzPh746EjBcTPIzGEyYALP2H6lQK+hT60oULbATH6pkrodvVku+OKsLxzLziTUWUk8eNQFk847elCbvAfxFvD1m+BSdaetxF070Ng8SDx8berMN17fDo0CIGUQaXaA/1LZkbqVBNkP++PCm1EPXmxR7xeyHE3smLIkZHB9v2U1ZUwTQmTH26zuzi/13Qvl3BWDaQ90rRPCuG7Kz3uYXKdppTY6JxXLdDPvUl2ED2YWsMk1lXvUCjvmcZYnHTHWZOIGFgyOreR6odHSUnnhJ72doZRynb2Cdac4DqRLaH1J12msJ6kqG5rimu07sG0o3Iv98GnnmxAlGilV4Q7cw01rW7CMVJn9lbHmJauBEqLnUYtvil8ghNrBit6wziPrRd4TDq3bzyPIaDfBBUE9U//sEaLM7rX2fHML1cevImioKmL1tlB3N0Ws3l2vPIFJOO24X0kaaK2C0dDNRHIBLFktB2wtQYm1vY9GDdKsOXkYSJUqogwFJnUztza9E91Wv6IVqs4WlB56wQNM0E0jUIhvCAVsmUpvj7+uf2iHlULa2wumK/KEJoXUy6hQmuym8nTdi+sd0if+XW0eFExi9RxqL3koztnu6xEdK8LcFB72FVVFaq49Pa4f445PSQOHXmFhe6o43iICnG8z7wm1EosGkOck+Nsmn9C04W67NqyXcOmtJO7x7411eogBYzEVgOxzKmTlZ9d3q549d2Aw0nWQL8lTF3cN27KYVHkkP8kS4ksXn3SoBl9vII0BlhIW2MRORXoWs6s5QFTZ6hp6Xsu1T0EIFI94wqzc6D5nC/51ZtSL2ceZjx280hQS35XN6Li/L8cHQuukmDMrLPZYcEUnpwvnHiRyqQSVgoZ4MHiV4CZ54yBbhQG9whFvGIWlZK7bDYwTHx0K/VobU3Mp3NK6biPZjdzHCNIyCRofKVRaUJmNpnWRgIeFjhQehmQ3YK8JGVIfT6DbxgTYkEy+ybliCEKdWdJDITCa6H0FrNP+iyKt4Awcg8IeSflmOChdlPAnYKwsKfOTO1JtGIFYPd6d2a+DORKPO1mnmhFb5tGnmSak47OcfpNBHpKsXpSwsK/IufKggrtDMFYbzHynR5QlsjJpT8eY+pHs9JNZ2HrOPsPVDegfDbynJuUjOYgP4SCi89n5/+cXZbv5g X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: 502a4588-6066-4f16-6614-08db2f4855da X-MS-Exchange-CrossTenant-AuthSource: BL0PR2101MB1092.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Mar 2023 04:53:12.9156 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: g750lvB1vGR18k9QyUBSKuScqMq+9VQk4O3A/AtvV5ZgEIxivlOI6SBvaLf7znY5COsDEkwCxBhXQnMEtCtK2g== X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR21MB3402 Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org This reverts commit d6af2ed29c7c1c311b96dac989dcb991e90ee195. The statement "the hv_pci_bus_exit() call releases structures of all its child devices" in commit d6af2ed29c7c is not true: in the path hv_pci_probe() -> hv_pci_enter_d0() -> hv_pci_bus_exit(hdev, true): the parameter "keep_devs" is true, so hv_pci_bus_exit() does *not* release the child "struct hv_pci_dev *hpdev" that is created earlier in pci_devices_present_work() -> new_pcichild_device(). The commit d6af2ed29c7c was originally made in July 2020 for RHEL 7.7, where the old version of hv_pci_bus_exit() was used; when the commit was rebased and merged into the upstream, people didn't notice that it's not really necessary. The commit itself doesn't cause any issue, but it makes hv_pci_probe() more complicated. Revert it to facilitate some upcoming changes to hv_pci_probe(). Signed-off-by: Dexuan Cui Acked-by: Wei Hu --- drivers/pci/controller/pci-hyperv.c | 71 ++++++++++++++--------------- 1 file changed, 34 insertions(+), 37 deletions(-) diff --git a/drivers/pci/controller/pci-hyperv.c b/drivers/pci/controller/pci-hyperv.c index 46df6d093d68..48feab095a14 100644 --- a/drivers/pci/controller/pci-hyperv.c +++ b/drivers/pci/controller/pci-hyperv.c @@ -3225,8 +3225,10 @@ static int hv_pci_enter_d0(struct hv_device *hdev) struct pci_bus_d0_entry *d0_entry; struct hv_pci_compl comp_pkt; struct pci_packet *pkt; + bool retry = true; int ret; +enter_d0_retry: /* * Tell the host that the bus is ready to use, and moved into the * powered-on state. This includes telling the host which region @@ -3253,6 +3255,38 @@ static int hv_pci_enter_d0(struct hv_device *hdev) if (ret) goto exit; + /* + * In certain case (Kdump) the pci device of interest was + * not cleanly shut down and resource is still held on host + * side, the host could return invalid device status. + * We need to explicitly request host to release the resource + * and try to enter D0 again. + */ + if (comp_pkt.completion_status < 0 && retry) { + retry = false; + + dev_err(&hdev->device, "Retrying D0 Entry\n"); + + /* + * Hv_pci_bus_exit() calls hv_send_resource_released() + * to free up resources of its child devices. + * In the kdump kernel we need to set the + * wslot_res_allocated to 255 so it scans all child + * devices to release resources allocated in the + * normal kernel before panic happened. + */ + hbus->wslot_res_allocated = 255; + + ret = hv_pci_bus_exit(hdev, true); + + if (ret == 0) { + kfree(pkt); + goto enter_d0_retry; + } + dev_err(&hdev->device, + "Retrying D0 failed with ret %d\n", ret); + } + if (comp_pkt.completion_status < 0) { dev_err(&hdev->device, "PCI Pass-through VSP failed D0 Entry with status %x\n", @@ -3493,7 +3527,6 @@ static int hv_pci_probe(struct hv_device *hdev, struct hv_pcibus_device *hbus; u16 dom_req, dom; char *name; - bool enter_d0_retry = true; int ret; /* @@ -3633,47 +3666,11 @@ static int hv_pci_probe(struct hv_device *hdev, if (ret) goto free_fwnode; -retry: ret = hv_pci_query_relations(hdev); if (ret) goto free_irq_domain; ret = hv_pci_enter_d0(hdev); - /* - * In certain case (Kdump) the pci device of interest was - * not cleanly shut down and resource is still held on host - * side, the host could return invalid device status. - * We need to explicitly request host to release the resource - * and try to enter D0 again. - * Since the hv_pci_bus_exit() call releases structures - * of all its child devices, we need to start the retry from - * hv_pci_query_relations() call, requesting host to send - * the synchronous child device relations message before this - * information is needed in hv_send_resources_allocated() - * call later. - */ - if (ret == -EPROTO && enter_d0_retry) { - enter_d0_retry = false; - - dev_err(&hdev->device, "Retrying D0 Entry\n"); - - /* - * Hv_pci_bus_exit() calls hv_send_resources_released() - * to free up resources of its child devices. - * In the kdump kernel we need to set the - * wslot_res_allocated to 255 so it scans all child - * devices to release resources allocated in the - * normal kernel before panic happened. - */ - hbus->wslot_res_allocated = 255; - ret = hv_pci_bus_exit(hdev, true); - - if (ret == 0) - goto retry; - - dev_err(&hdev->device, - "Retrying D0 failed with ret %d\n", ret); - } if (ret) goto free_irq_domain; From patchwork Tue Mar 28 04:51:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dexuan Cui X-Patchwork-Id: 13190479 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 7E5F3C76195 for ; Tue, 28 Mar 2023 04:53:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232183AbjC1Ex5 (ORCPT ); Tue, 28 Mar 2023 00:53:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60504 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231978AbjC1Exk (ORCPT ); Tue, 28 Mar 2023 00:53:40 -0400 Received: from DM6FTOPR00CU001.outbound.protection.outlook.com (mail-cusazon11020018.outbound.protection.outlook.com [52.101.61.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 70DA52709; Mon, 27 Mar 2023 21:53:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=gjDe7V4S1KT3fU9ZcgJghU0Cl3RcJJgX/sHRN/gFXjOykk/YYWI4fxQ0153rKWju0RO+4bKpjtoQDKdNvOW3ezhIgUCJx7TQa4xgfzeTPbs3L8D3wiNbwhiVf+H29ro3F+/4czAiZhiLaz7UYUfikNbhdED0fdcJnazkkx0UGfA5cF0yVUpnPrBMygLs8SbW2DTjRSGfOmeicEajHQ9kdDQ32kap5pceA6b0W8iyi12DdrBxcAE3dXr0rWXlPuXjG8fXNWTYsHQwmE202cboBvoS5wHF2esIYXiDmpw3umlSkWYlzyLQ/ixE8RnoFud8koTMrdrQGRXiLJ9sp9pjvQ== 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=mIdejf2Qm7gwgjEEPWxewX41SsfdLZbzID/iX5ohE4w=; b=B2vuF0G2Eh/rSc4Nj9aFBH12sQLYOl/UJ3z21KpG7EepSMoYWwihKCYSRmfgNwtPpe3z6ndamBGChbdQv/vMJ74KFx4WCbbRVDU5zj8ma1I4IS9n2PgPVaLKCoXOZHkBc/4Ca++vBvFg/X4BrWg3qzwx+Hr7R7KZorJcVvt2MAGzIMCcYk5LF+Lfyn4pxk1BFLnV2L8/e5T+AUkEK1aOKNr7sMxc4vVh0GK1CUtB3oCnEWCVh+xFrjvhgCnBTuw0+HZHkQUVhx+CaCfA+F8v4nvHTEdeZo9OjhcGpaqIq2wQEUrID3BD5T1qi8yQZlsUSw4roDai0mV/cL3VFqM7nw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=microsoft.com; dmarc=pass action=none header.from=microsoft.com; dkim=pass header.d=microsoft.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=mIdejf2Qm7gwgjEEPWxewX41SsfdLZbzID/iX5ohE4w=; b=RCwJJ0f7arhF5MKhj5c0NnmWJXxqdfOemKQGK+ujRX7kqbGE+bBckQc9sgjaRJ+QXAGtLnOTAJabbblPgz7H1VQhidc8kM926n3MdPpJIm8URmrQdXPSGJ/24a0lIEituZGwmiomfG5C/2l4x5Wd/ikz/dPm2MNnk1AZtxFoXTw= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=microsoft.com; Received: from BL0PR2101MB1092.namprd21.prod.outlook.com (2603:10b6:207:30::23) by IA1PR21MB3402.namprd21.prod.outlook.com (2603:10b6:208:3e1::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6277.6; Tue, 28 Mar 2023 04:53:15 +0000 Received: from BL0PR2101MB1092.namprd21.prod.outlook.com ([fe80::97b2:25ca:c44:9b7]) by BL0PR2101MB1092.namprd21.prod.outlook.com ([fe80::97b2:25ca:c44:9b7%6]) with mapi id 15.20.6277.005; Tue, 28 Mar 2023 04:53:15 +0000 From: Dexuan Cui To: bhelgaas@google.com, davem@davemloft.net, decui@microsoft.com, edumazet@google.com, haiyangz@microsoft.com, jakeo@microsoft.com, kuba@kernel.org, kw@linux.com, kys@microsoft.com, leon@kernel.org, linux-pci@vger.kernel.org, lpieralisi@kernel.org, mikelley@microsoft.com, pabeni@redhat.com, robh@kernel.org, saeedm@nvidia.com, wei.liu@kernel.org, longli@microsoft.com, boqun.feng@gmail.com Cc: linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org, linux-rdma@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH 5/6] PCI: hv: Add a per-bus mutex state_lock Date: Mon, 27 Mar 2023 21:51:21 -0700 Message-Id: <20230328045122.25850-6-decui@microsoft.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230328045122.25850-1-decui@microsoft.com> References: <20230328045122.25850-1-decui@microsoft.com> X-ClientProxiedBy: MW4PR03CA0013.namprd03.prod.outlook.com (2603:10b6:303:8f::18) To BL0PR2101MB1092.namprd21.prod.outlook.com (2603:10b6:207:30::23) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL0PR2101MB1092:EE_|IA1PR21MB3402:EE_ X-MS-Office365-Filtering-Correlation-Id: 53069f02-9084-43d5-eede-08db2f48570d X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: G9cea6A7CAyau3DXpBEA2Q3twjNYTcV+yKN1PwlvEGP4O/jImp2rKSMW38sdZTtAp9Q7UXaQT3BA98Y296FfJ0gKBcJn4lezFrOcc+s3qxMuApkVzJTtKVCd5GNmDfiH+hb3Q/fZacLLTJAY66PZA9y8i6riNsy9ulqRgvc8rRX1cYLNCqvQ30RM+RpvwsG28zHSkbg/e5ff9x4/vgUJ14/MdEZAqubo1zJNibQzmJkucO8+cH53NytcV58rU8snsa6Pg/Hj7SCXtBcleO5znEZXAtQUxntJkK7mWlSa7HNTZUY0lXuIBaz3YfW2aF+xonoXumx4JpYJzIQV2/hScEF+p7BpxGYu7w3DgMNikZfU7GGlclif/71KutdzSH8MHvH9GEYuBZN7m8eIfn3CteEv+vTfS4RusEsIk5IEepSeSC2Xuft0V2ZyoIYy80oE+Z8hXXh2Fa0kXRjOwNR6I0FBezz+NA1tqnfZgcAyNwUR+LL7wCg9AcqtuYi/HzTMUWhmu031iFPMXDcWMh/eL2DGzpckThkB1XkKRik86z94ICVXse3kNtiJHKXdf8GBEN5O60qwhdiRNEJnO/FwLCEnS+F1ZfktlJ2d7Dw6QCmTnPq9QW+DP6HE32vMLAtyQB19FMsvsicUG8bUZrYV8w== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BL0PR2101MB1092.namprd21.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(4636009)(346002)(376002)(366004)(396003)(39860400002)(136003)(451199021)(478600001)(83380400001)(10290500003)(2906002)(1076003)(38100700002)(52116002)(7416002)(6486002)(30864003)(6506007)(6512007)(921005)(2616005)(5660300002)(8936002)(6666004)(316002)(86362001)(82960400001)(82950400001)(186003)(41300700001)(66556008)(66476007)(4326008)(66946007)(8676002)(36756003);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: UNDYynaym+7HRVyg4nRH4FtFXrS/1F5ijno4QYnE+banZ8nrUIoz2P8a4HjoQIzPpFxI+DWBhVoyfWJQJlvLoewdwjpwI18HooTW3fWMaBr5qSksF56lbGSumDNnwrxvts7dRDt4mLBKhpm2t4Zfh1eCetYf7HbzWtrNG1X4AKMjjZqlh9Y7bDcD6oswzSYpufcv8cJ/6z18RIzKQ23pIY4TbA+Zaqs04dS/2rxSAvYDrg2AU8jv9LQOzZBPnoGkTssqNIe6SFq89427YAYuHPQMVEpkOXDX+r3yhYy4EHZOHe2FWbMLrBwhNJVLVLPSWqQE6fK6PBYptiWEVeHzlfPU0W8tl9bDwvNtL83LqLLazAIDO2cUEMaFISVWfUKCFGXYTLA5nJshVUNzcXZc8zQpxhBZCmKwIkxIw4p80rMUtYBLHY4xnUqyaVu6dvMmOpEohVefC9cJH6SPo/gk5oGFJ/hbmc2sOwbWy8L2/XBIRaulIAJ00RF68tcuhbogI4mKau0RnT5ERqhE9gsgPTXtpA26tYMDj0AoH0mdO58I3ffu0F6s6rAE5PEBdkz1rGf1Vn62GroH8AZ3hXanT4HA0fcC7WzGQ7L63psxKFc1+U0y6RCJeFQbLaOB/UTw5V/IFZsmLqwasKGLW1OjAn6BsGwh3X74S0zUvjY0aJZwJaghQqF0Z3spNBPT4jgFuGSVT/kJV0j5IpvAKzYvKUablCB3W/uZVTlepBU+J+/dMDT8ZXDFCBWCnM/mLexABceYP9PLkVZo6DVtKIBfotdXbm/KNsZN4PVmtL6t7Z1pUX/WJgSdGlSOmn5DDwXLjUyPxQ9qtDeoNEyKkOU+0uN5nQVKcLEJllczQWGmuHHS9tRxUDfHUH5pWUVUIL2SDM5iBUJ3L3IXf4uJP1wgm0pmBfulIZlvvUcyyEeafW/wYpQFxwDxsa2w8Sg6RlY60aPbmAg58fx+ajERMM0INtXWt1fwH12pO3GGlMXlAGpO3jLPh7RUnxP1NJTvy/m+kycZQ2+sxgjwj555VD6yel2RXjViyHtoK2fUPbCHlbSAUUHk2CQapFYIAnRU7gKb2T6HG74yZnFWGk+j8QFvIKJw1hhUDwrnwWKlHxwffRkGZ7hsqgWVqPA/0WAgUV00PgzLhYoVXj6B2W1P9PksnGR+4RWSnfcJ8ZYdluKyoc838P9dzIiEljTaG4jVbzWUSU2paKH0Z2CQBbKi/BStDfp8cOIO/40H08EuvSO3aIGGvtAtAcxuAnd9yhjKjuwAuEcEO4amR2xX6VDjLbRaCmPmf+PEnGLq7eeBqJ4OxW4ytSj6l3N/s2m+cBD9Pf0HggfrP8slRLlO6yBzbCAG8jYMIEFOO+HxNYeUxENuOfPvUmsEYS5H4u02XOLdKlNpVRISORx9RVd6/DbbLkWs42mCCJ1c9KEKUTC75c9lw0CfEA2JhRfRudT7mXn3GA8BZZZ+b0nd27wenkOCCSVsyJMsWvQkl8NZVEUDPxX2qqFc8Fre2vBk8UIw9/IzpdnxJkijSul5ucwTbOaPCfHmkbFq0SrGabr31d38yCAHYNIbo4Bs511AO0c23112JPLdzEdY04PxEdZDgjaTQksEqgeDD3EDnGgnd++XYlSN29a4BQHyKHtbRZtPMfOubWGu X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: 53069f02-9084-43d5-eede-08db2f48570d X-MS-Exchange-CrossTenant-AuthSource: BL0PR2101MB1092.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Mar 2023 04:53:14.9349 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: bIIp6fxrzNYF+mOUIwQvUt3ObqM4wEGM19nXx9q+VTOH6nNb/BoMFHH8L0lxeK33s8ep72zB9Rd16YP4HIEEbA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR21MB3402 Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org In the case of fast device addition/removal, it's possible that hv_eject_device_work() can start to run before create_root_hv_pci_bus() starts to run; as a result, the pci_get_domain_bus_and_slot() in hv_eject_device_work() can return a 'pdev' of NULL, and hv_eject_device_work() can remove the 'hpdev', and immediately send a message PCI_EJECTION_COMPLETE to the host, and the host immediately unassigns the PCI device from the guest; meanwhile, create_root_hv_pci_bus() and the PCI device driver can be probing the dead PCI device and reporting timeout errors. Fix the issue by adding a per-bus mutex 'state_lock' and grabbing the mutex before powering on the PCI bus in hv_pci_enter_d0(): when hv_eject_device_work() starts to run, it's able to find the 'pdev' and call pci_stop_and_remove_bus_device(pdev): if the PCI device driver has loaded, the PCI device driver's probe() function is already called in create_root_hv_pci_bus() -> pci_bus_add_devices(), and now hv_eject_device_work() -> pci_stop_and_remove_bus_device() is able to call the PCI device driver's remove() function and remove the device reliably; if the PCI device driver hasn't loaded yet, the function call hv_eject_device_work() -> pci_stop_and_remove_bus_device() is able to remove the PCI device reliably and the PCI device driver's probe() function won't be called; if the PCI device driver's probe() is already running (e.g., systemd-udev is loading the PCI device driver), it must be holding the per-device lock, and after the probe() finishes and releases the lock, hv_eject_device_work() -> pci_stop_and_remove_bus_device() is able to proceed to remove the device reliably. Fixes: 4daace0d8ce8 ("PCI: hv: Add paravirtual PCI front-end for Microsoft Hyper-V VMs") Signed-off-by: Dexuan Cui --- drivers/pci/controller/pci-hyperv.c | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) With the below debug code: Changes to /drivers/net/ethernet/mellanox/mlx5/core/main.c @@ -1727,6 +1727,8 @@ static int probe_one(struct pci_dev *pdev, const struct pci_device_id *id) struct devlink *devlink; int err; + printk("%s: line %d: sleep 20s: \n", __func__, __LINE__); ssleep(20); + printk("%s: line %d: sleep 20s: done\n", __func__, __LINE__); devlink = mlx5_devlink_alloc(&pdev->dev); if (!devlink) { dev_err(&pdev->dev, "devlink alloc failed\n"); Changes to drivers/pci/controller/pci-hyperv.c @@ -2749,6 +2749,7 @@ static void hv_eject_device_work(struct work_struct *work) */ wslot = wslot_to_devfn(hpdev->desc.win_slot.slot); pdev = pci_get_domain_bus_and_slot(hbus->bridge->domain_nr, 0, wslot); + printk("%s: 1: line %d: pdev=%px\n", __func__, __LINE__, pdev); if (pdev) { pci_lock_rescan_remove(); pci_stop_and_remove_bus_device(pdev); @@ -2756,9 +2757,12 @@ static void hv_eject_device_work(struct work_struct *work) pci_unlock_rescan_remove(); } + printk("%s: 2: line %d: pdev=%px: sleeping 10s\n", __func__, __LINE__, pdev); ssleep(10); + printk("%s: 3: line %d: pdev=%px: sleeping 10s: done: removing hpdev\n", __func__, __LINE__, pdev); spin_lock_irqsave(&hbus->device_list_lock, flags); list_del(&hpdev->list_entry); spin_unlock_irqrestore(&hbus->device_list_lock, flags); + printk("%s: 4: line %d: pdev=%px: hpdev is removed!!!\n", __func__, __LINE__, pdev); if (hpdev->pci_slot) pci_destroy_slot(hpdev->pci_slot); @@ -2770,6 +2774,7 @@ static void hv_eject_device_work(struct work_struct *work) vmbus_sendpacket(hbus->hdev->channel, ejct_pkt, sizeof(*ejct_pkt), 0, VM_PKT_DATA_INBAND, 0); + printk("%s: 5: line %d: pdev=%px: sent PCI_EJECTION_COMPLETE\n", __func__, __LINE__, pdev); /* For the get_pcichild() in hv_pci_eject_device() */ put_pcichild(hpdev); @@ -3686,7 +3691,10 @@ static int hv_pci_probe(struct hv_device *hdev, hbus->state = hv_pcibus_probed; + printk("%s: line %d: create_root_hv_pci_bus=%d: sleeping 10s\n", __func__, __LINE__, ret); ssleep(10); + printk("%s: line %d: create_root_hv_pci_bus=%d: sleeping 10s: done\n", __func__, __LINE__, ret); ret = create_root_hv_pci_bus(hbus); + printk("%s: line %d: create_root_hv_pci_bus=%d\n", __func__, __LINE__, ret); if (ret) goto free_windows; I'm able to repro the below timeout errors (remove the PCI VF NIC within 10 seconds after it's assigned) [ 31.445306] hv_pci b92a0085-468b-407a-a88a-d33fac8edc75: PCI VMBus probing: Using version 0x10004 [ 31.452133] hv_pci_probe: line 3694: create_root_hv_pci_bus=0: sleeping 10s [ 34.345256] hv_eject_device_work: 1: line 2752: pdev=0000000000000000 [ 34.350175] hv_eject_device_work: 2: line 2760: pdev=0000000000000000: sleeping 10s [ 41.650330] hv_pci_probe: line 3695: create_root_hv_pci_bus=0: sleeping 10s: done [ 41.668443] hv_pci b92a0085-468b-407a-a88a-d33fac8edc75: PCI host bridge to bus 468b:00 [ 41.674201] pci_bus 468b:00: root bus resource [mem 0xfe0000000-0xfe00fffff window] [ 41.680284] pci_bus 468b:00: No busn resource found for root bus, will use [bus 00-ff] [ 41.688901] pci 468b:00:02.0: [15b3:1016] type 00 class 0x020000 [ 41.695554] pci 468b:00:02.0: reg 0x10: [mem 0xfe0000000-0xfe00fffff 64bit pref] [ 41.704304] pci 468b:00:02.0: enabling Extended Tags ... [ 41.745847] hv_pci_probe: line 3697: create_root_hv_pci_bus=0 [ 41.938950] mlx5_core 468b:00:02.0: no default pinctrl state [ 41.941462] probe_one: line 1730: sleep 20s: [ 44.466334] hv_eject_device_work: 3: line 2761: pdev=0000000000000000: sleeping 10s: done: removing hpdev [ 44.472691] hv_eject_device_work: 4: line 2765: pdev=0000000000000000: hpdev is removed!!! [ 44.478007] hv_eject_device_work: 5: line 2777: pdev=0000000000000000: sent PCI_EJECTION_COMPLETE [ 44.480213] hv_netvsc 818fe754-b912-4445-af51-1f584812e3c9 eth0: VF slot 1 removed [ 63.154376] probe_one: line 1731: sleep 20s: done [ 63.161610] mlx5_core 468b:00:02.0: firmware version: 65535.65535.65535 [ 83.174538] mlx5_core 468b:00:02.0: wait_fw_init:199:(pid 17): Waiting for FW initialization, timeout abort in 100s (0xffffffff) [ 103.190543] mlx5_core 468b:00:02.0: wait_fw_init:199:(pid 17): Waiting for FW initialization, timeout abort in 79s (0xffffffff) [ 123.202507] mlx5_core 468b:00:02.0: wait_fw_init:199:(pid 17): Waiting for FW initialization, timeout abort in 59s (0xffffffff) [ 143.214547] mlx5_core 468b:00:02.0: wait_fw_init:199:(pid 17): Waiting for FW initialization, timeout abort in 39s (0xffffffff) [ 163.222594] mlx5_core 468b:00:02.0: wait_fw_init:199:(pid 17): Waiting for FW initialization, timeout abort in 19s (0xffffffff) [ 183.178629] mlx5_core 468b:00:02.0: mlx5_function_setup:1130:(pid 17): Firmware over 120000 MS in pre-initializing state, aborting [ 183.186289] mlx5_core 468b:00:02.0: probe_one:1764:(pid 17): mlx5_init_one failed with error code -16 [ 183.192623] mlx5_core: probe of 468b:00:02.0 failed with error -16 [ 183.202701] pci_bus 468b:00: busn_res: [bus 00] is released With the fix, I'm no longer seeing the timeout errors: [ 31.144066] hv_pci b92a0085-468b-407a-a88a-d33fac8edc75: PCI VMBus probing: Using version 0x10004 [ 31.149207] hv_pci_probe: line 3708: create_root_hv_pci_bus=0: sleeping 10s [ 41.378274] hv_pci_probe: line 3709: create_root_hv_pci_bus=0: sleeping 10s: done [ 41.397577] hv_pci b92a0085-468b-407a-a88a-d33fac8edc75: PCI host bridge to bus 468b:00 [ 41.402799] pci_bus 468b:00: root bus resource [mem 0xfe0000000-0xfe00fffff window] ... [ 41.415586] pci 468b:00:02.0: [15b3:1016] type 00 class 0x020000 [ 41.423132] pci 468b:00:02.0: reg 0x10: [mem 0xfe0000000-0xfe00fffff 64bit pref] ... [ 41.471366] hv_pci_probe: line 3711: create_root_hv_pci_bus=0 [ 41.484371] hv_eject_device_work: 1: line 2761: pdev=ffff90f4c4858000 [ 41.491644] hv_eject_device_work: 2: line 2769: pdev=ffff90f4c4858000: sleeping 10s [ 51.618268] hv_eject_device_work: 3: line 2770: pdev=ffff90f4c4858000: sleeping 10s: done: removing hpdev [ 51.625094] hv_eject_device_work: 4: line 2774: pdev=ffff90f4c4858000: hpdev is removed!!! [ 51.630234] hv_eject_device_work: 5: line 2786: pdev=ffff90f4c4858000: sent PCI_EJECTION_COMPLETE [ 51.632148] hv_netvsc 818fe754-b912-4445-af51-1f584812e3c9 eth0: VF slot 1 removed [ 51.647014] pci_bus 468b:00: busn_res: [bus 00] is released Now the mlx5_core driver is loaded; I try fast device addition/removal again and I'm still not seeing the timeout errors: [ 495.622678] hv_pci b92a0085-468b-407a-a88a-d33fac8edc75: PCI VMBus probing: Using version 0x10004 [ 495.627791] hv_pci_probe: line 3708: create_root_hv_pci_bus=0: sleeping 10s [ 505.762550] hv_pci_probe: line 3709: create_root_hv_pci_bus=0: sleeping 10s: done [ 505.779496] hv_pci b92a0085-468b-407a-a88a-d33fac8edc75: PCI host bridge to bus 468b:00 [ 505.784872] pci_bus 468b:00: root bus resource [mem 0xfe0000000-0xfe00fffff window] ... [ 505.798323] pci 468b:00:02.0: [15b3:1016] type 00 class 0x020000 ... [ 505.868908] probe_one: line 1730: sleep 20s: [ 525.986578] probe_one: line 1731: sleep 20s: done [ 525.990717] mlx5_core 468b:00:02.0: enabling device (0000 -> 0002) [ 525.998339] mlx5_core 468b:00:02.0: firmware version: 14.25.8102 ... [ 526.381211] hv_netvsc 818fe754-b912-4445-af51-1f584812e3c9 eth0: VF registering: eth1 [ 526.385432] mlx5_core 468b:00:02.0 eth1: joined to eth0 [ 526.389076] mlx5_core 468b:00:02.0 eth1: Disabling LRO, not supported in legacy RQ [ 526.397276] mlx5_core 468b:00:02.0 eth1: Disabling LRO, not supported in legacy RQ [ 526.400330] mlx5_core 468b:00:02.0: MLX5E: StrdRq(0) RqSz(1024) StrdSz(256) RxCqeCmprss(0 basic) ... [ 526.430803] hv_pci_probe: line 3711: create_root_hv_pci_bus=0 [ 526.443633] hv_eject_device_work: 1: line 2761: pdev=ffff90f4e369b000 [ 526.454819] hv_netvsc 818fe754-b912-4445-af51-1f584812e3c9 eth0: VF unregistering: enP18059s1 [ 526.457828] mlx5_core 468b:00:02.0 enP18059s1 (unregistering): Disabling LRO, not supported in legacy RQ [ 527.680118] mlx5_core 468b:00:02.0: devm_attr_group_remove: removing group 00000000074d6d6b [ 527.692794] hv_eject_device_work: 2: line 2769: pdev=ffff90f4e369b000: sleeping 10s [ 537.762575] hv_eject_device_work: 3: line 2770: pdev=ffff90f4e369b000: sleeping 10s: done: removing hpdev [ 537.768831] hv_eject_device_work: 4: line 2774: pdev=ffff90f4e369b000: hpdev is removed!!! [ 537.774313] hv_eject_device_work: 5: line 2786: pdev=ffff90f4e369b000: sent PCI_EJECTION_COMPLETE [ 537.777737] hv_netvsc 818fe754-b912-4445-af51-1f584812e3c9 eth0: VF slot 1 removed [ 537.794038] pci_bus 468b:00: busn_res: [bus 00] is released diff --git a/drivers/pci/controller/pci-hyperv.c b/drivers/pci/controller/pci-hyperv.c index 48feab095a14..2c0b86b20408 100644 --- a/drivers/pci/controller/pci-hyperv.c +++ b/drivers/pci/controller/pci-hyperv.c @@ -489,7 +489,10 @@ struct hv_pcibus_device { struct fwnode_handle *fwnode; /* Protocol version negotiated with the host */ enum pci_protocol_version_t protocol_version; + + struct mutex state_lock; enum hv_pcibus_state state; + struct hv_device *hdev; resource_size_t low_mmio_space; resource_size_t high_mmio_space; @@ -2512,6 +2515,8 @@ static void pci_devices_present_work(struct work_struct *work) if (!dr) return; + mutex_lock(&hbus->state_lock); + /* First, mark all existing children as reported missing. */ spin_lock_irqsave(&hbus->device_list_lock, flags); list_for_each_entry(hpdev, &hbus->children, list_entry) { @@ -2593,6 +2598,8 @@ static void pci_devices_present_work(struct work_struct *work) break; } + mutex_unlock(&hbus->state_lock); + kfree(dr); } @@ -2741,6 +2748,8 @@ static void hv_eject_device_work(struct work_struct *work) hpdev = container_of(work, struct hv_pci_dev, wrk); hbus = hpdev->hbus; + mutex_lock(&hbus->state_lock); + /* * Ejection can come before or after the PCI bus has been set up, so * attempt to find it and tear down the bus state, if it exists. This @@ -2777,6 +2786,8 @@ static void hv_eject_device_work(struct work_struct *work) put_pcichild(hpdev); put_pcichild(hpdev); /* hpdev has been freed. Do not use it any more. */ + + mutex_unlock(&hbus->state_lock); } /** @@ -3562,6 +3573,7 @@ static int hv_pci_probe(struct hv_device *hdev, return -ENOMEM; hbus->bridge = bridge; + mutex_init(&hbus->state_lock); hbus->state = hv_pcibus_init; hbus->wslot_res_allocated = -1; @@ -3670,9 +3682,11 @@ static int hv_pci_probe(struct hv_device *hdev, if (ret) goto free_irq_domain; + mutex_lock(&hbus->state_lock); + ret = hv_pci_enter_d0(hdev); if (ret) - goto free_irq_domain; + goto release_state_lock; ret = hv_pci_allocate_bridge_windows(hbus); if (ret) @@ -3690,12 +3704,15 @@ static int hv_pci_probe(struct hv_device *hdev, if (ret) goto free_windows; + mutex_unlock(&hbus->state_lock); return 0; free_windows: hv_pci_free_bridge_windows(hbus); exit_d0: (void) hv_pci_bus_exit(hdev, true); +release_state_lock: + mutex_unlock(&hbus->state_lock); free_irq_domain: irq_domain_remove(hbus->irq_domain); free_fwnode: @@ -3945,20 +3962,26 @@ static int hv_pci_resume(struct hv_device *hdev) if (ret) goto out; + mutex_lock(&hbus->state_lock); + ret = hv_pci_enter_d0(hdev); if (ret) goto out; ret = hv_send_resources_allocated(hdev); if (ret) - goto out; + goto release_state_lock; prepopulate_bars(hbus); hv_pci_restore_msi_state(hbus); hbus->state = hv_pcibus_installed; + mutex_unlock(&hbus->state_lock); return 0; + +release_state_lock: + mutex_unlock(&hbus->state_lock); out: vmbus_close(hdev->channel); return ret; From patchwork Tue Mar 28 04:51:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dexuan Cui X-Patchwork-Id: 13190480 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 10EA0C76196 for ; Tue, 28 Mar 2023 04:54:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231970AbjC1EyT (ORCPT ); Tue, 28 Mar 2023 00:54:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60874 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232287AbjC1EyB (ORCPT ); Tue, 28 Mar 2023 00:54:01 -0400 Received: from DM6FTOPR00CU001.outbound.protection.outlook.com (mail-cusazon11020018.outbound.protection.outlook.com [52.101.61.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 84139359B; Mon, 27 Mar 2023 21:53:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=mSOg86jc0Hp9KYB4v/qdQss0utKoHWV2FpjI3d6rF9BGyBLU15oxoMPs1DPM0FtETYjtBAkpn3i1meJBfKA3E0UQEZVEAMDnA9OLCo5StsH3cZtydMlqfCYwhOdqQ+BEY+3cTzUDul+Q7W5LX5saE2oQt+D94jK+/WdZ9PVN/WkLcmvFNumCTJZfqC+vDmxEYSZRD5en4LIRsp4L0ssKkJ0E+g9vYNmMVaZ/jvMPNAf3beCAsbuxDvYj3L/Cxm/JtaVMRr06A188BBdWXTcG9eFoo0wvGEg7yZwKXmMG6XVMXS6A/XSpsoE9582lKQ5uEXzsm0DYduLdHNiqLoKgSQ== 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=ZXf8oCsuD4692IF7aE7rV9LfnreLFzYWT+HaqSiheDY=; b=Rbd68lbuiAUD+jxO3RzOhBFfW3pfoKmySJNVzyNNyLgmqIdnoFqNkx3I/BSZWYF5Dyb69/i47i5wMg+G2sz4Rd5LxsKxURO1eBGZ9X2i2iG0eVjCqYVuVJIhRReIIc4gv8L548Z6pmgBQQBpbpdGeVaMrht642M9cenxkAF6gpxoLXAfqUqKIxr8zmL9RS7+exH3X1fno4a7sSqJdjS9YAKGHtM5VhMs2x0y2Pt43+WIJw09NGGO1HnPXQjaePfO4BBN4n55djlO2DVyh7knvs2jAyvPXMSEVmEKAlncRnrCAMVVcxenxuX/1Np1RdJKrcmoKddHPXoHGQs2p2DdfQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=microsoft.com; dmarc=pass action=none header.from=microsoft.com; dkim=pass header.d=microsoft.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=ZXf8oCsuD4692IF7aE7rV9LfnreLFzYWT+HaqSiheDY=; b=ibVMLhbb89Z7cxPoT5Mw60Sc5GuhxH1lBvusouw6g12aiSa6Aop548Zimx6ES7Rn6z1JyHqVvCWffsNx6XfOD3sx/X3ETGklloNFJ5tI2alr1fFXOkbhx6nt+cvGN0idLMtPuvpkG8KcxHWMd8DiT0FBXKVjzML4a2yme0Zl7rU= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=microsoft.com; Received: from BL0PR2101MB1092.namprd21.prod.outlook.com (2603:10b6:207:30::23) by IA1PR21MB3402.namprd21.prod.outlook.com (2603:10b6:208:3e1::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6277.6; Tue, 28 Mar 2023 04:53:17 +0000 Received: from BL0PR2101MB1092.namprd21.prod.outlook.com ([fe80::97b2:25ca:c44:9b7]) by BL0PR2101MB1092.namprd21.prod.outlook.com ([fe80::97b2:25ca:c44:9b7%6]) with mapi id 15.20.6277.005; Tue, 28 Mar 2023 04:53:16 +0000 From: Dexuan Cui To: bhelgaas@google.com, davem@davemloft.net, decui@microsoft.com, edumazet@google.com, haiyangz@microsoft.com, jakeo@microsoft.com, kuba@kernel.org, kw@linux.com, kys@microsoft.com, leon@kernel.org, linux-pci@vger.kernel.org, lpieralisi@kernel.org, mikelley@microsoft.com, pabeni@redhat.com, robh@kernel.org, saeedm@nvidia.com, wei.liu@kernel.org, longli@microsoft.com, boqun.feng@gmail.com Cc: linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org, linux-rdma@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH 6/6] PCI: hv: Use async probing to reduce boot time Date: Mon, 27 Mar 2023 21:51:22 -0700 Message-Id: <20230328045122.25850-7-decui@microsoft.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230328045122.25850-1-decui@microsoft.com> References: <20230328045122.25850-1-decui@microsoft.com> X-ClientProxiedBy: MW4PR03CA0013.namprd03.prod.outlook.com (2603:10b6:303:8f::18) To BL0PR2101MB1092.namprd21.prod.outlook.com (2603:10b6:207:30::23) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL0PR2101MB1092:EE_|IA1PR21MB3402:EE_ X-MS-Office365-Filtering-Correlation-Id: bc1fdca0-8564-407e-156c-08db2f48583f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: vYisbpc0bDwYSxSA6V3obTuoYZJIZYZ17F3cFNhWmN49uxepQvO0h9jR5KtujTVrvu3mEWJ1DJiLtRZ9YmCHAeZnWCX7ViC6pJgki2jNV57eDBSnST1mGAfWR8rtg7S9ToOB0OFFq5Wl5cfz6ToRVPFXWqK4wD1E4cC21Y/ZXdeuppaQUwWjDwVYA2/80fDAa7VLl1nVP3JFyoseFAaP7GxtsySRjvzOY81ZmUrpykHUY/8eSuK7YGwyEHeMn5DLi3kxzrB+4nBzvcKZIZELX36ER+ZIkP7xP95XwBXMZXOmJ9vx2me6SxGRbigNXlciAMTvARsS/wDw5oVtF+8v2BVOPsDVW/knRaf4LZkG8Yb4nYVcPacHalvztmtUPZAQY/jtHqtVdPVY7zw+3wxXYqUq5Sqi6p2pMkcVaWsqnNjRdV5HoP3F1O14fIZI+zCqOdl6z83quqIbZ80oSa+xjF6cVYSlLPvowaq+51r96DcC3/SN1rrjxxwxRuEmTGJUupLkKv2Pc7dV7+wNK1GyCAO67bPla/OYt5tVp6ySwpcfSL1RLillC5Rl7bFqq8DkLjlKsC+wNaY/fHQEXFzPrmlL0ljyT9rfgHaR/3R0brX+DpU3abWr/Bg6dPylUfMda3YInsAYts2DFSPO6fs3hw== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BL0PR2101MB1092.namprd21.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(4636009)(346002)(376002)(366004)(396003)(39860400002)(136003)(451199021)(478600001)(83380400001)(10290500003)(2906002)(1076003)(38100700002)(52116002)(7416002)(6486002)(6506007)(6512007)(921005)(2616005)(5660300002)(8936002)(6666004)(316002)(86362001)(82960400001)(82950400001)(186003)(41300700001)(66556008)(66476007)(4326008)(66946007)(8676002)(36756003);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 1ZbUgDbTABzt3+Z8t5SwESveP2pXTa2B7bIU3x8K2P5zn1vMWoJChRdxsIbdtID9YYLwCzYt59+4h2OX16eFttRJkYFhIeno3gzb9mCYEZ6h22KBLb36sNwhUs2dV6aNmVzN7AWj2JU+mKrdsDntKZZ/KpHktBg5SiSke55Ocbz/Y5IKKUkqVVrpJOG4fZI3varuxDAbrwZQXm+/j563hQiR3Ew5DhJcr8mkzBEbklpgmyv+GMzx4XDbck5lQgxUuxzriqqtjMGXCPpzW/XQv6WnijXm36yhx0H8hRQjZJcD2QqwaAtmaWQ56cF+SVcAOzFupGv2xn4HHOWjc24FksBApS/A8X0cIAZHVZlvHHAxBNYM84x8gQl+O++aB1EEyYUI8DMp5497XOaggopunxugDBCE6gUKYLo32i5fRe3YayTQHifwCyt/qvzaLieu6euUudrtN76H5p8wuNLTALgIAomGMlKAVmzTLdKDAIcdy8/gWvlg6cJl35ujvFIMRybuQmbBOXjXYmEOSjW9DmI4hdKpIl8AvgGVIREgze4X6MCGtjDo4OxuRNeENt1JkFG4o1srefXHxGzu/k+JhBxzgu/HImN7GqCU/ln/uyQze4UKXdxvpEio9JZm426v/+PCwGm4YJHQyyzG+h/nwNHC2n7XWSnoiJ9/Y3PRablhxGPo8ABqyhKsi8HMt6Pz5UrPdTl+8Gm6EwEB38oMC3gCBR8ChhoUEZ92XjrE2MSHQ/oBQOvxLEekncst8bsDluS1jXzQFikqIBi0PjC6zDCtOh+YE/0oqjNLcTB0yMpANG7XRSYa/ku1CQ+x9d6mupFsUHGuHxbH175jaY/8kIxIV8V6eS/h1vn7M4+O+G+UIPtjd9JrpFq9ieLAe0B0VfzOu6yfApIBC2H+Wj1KPh1FRyWsDOmspCAe1GvZNQBWGInWeyc98XpwaIKQOyMFXdIf5QhvgSdApp0X/YOxW0RIomCAhypxxT82E4yMw2QGAZdUqD5uk93ByOLt+TCym0ZFSzaU4UXZHq+Rh8dUiHmf3+C7zmjEryaIN97/Xw69ZwWqhNtjPAlFZxhRnLNqatn2mKz9lDHYuewEb9PA9JqdBAZFrYEubohYQLVll0J2GzBQPDvQNVaf7DFzGN63fO6CeMELClD9bJG6vwlWU3JpmVyKCeTr8czv8geqQguuVqeGSROerupmP1bNTTHk60PNGrUdfDsXBNHh1v/rLdYhNTB9fuw6Vq24XEtotJTuUlMoDrjVfrcbnoGeFoZy1wyPYNjy4teH5RLLgNAQweGih4Ahwn4XI4XkLv3kZAKMK77xA92Njk6qG495Ds2pu3gXiv+NAbYcVT8U8Nt8t2bfTsMjwsFdRWbX1VNIkCPiJa+H4xlJE2EEL/gDAOGrj8YcB6lyQz8FRyY7tY43+RD0kvcNOlqx9xHpd4gE3AWHLuFW7JTeYATSSWcYXWsqBV5jRVb9Tr/DeaThhRkM7Amv5qgXRGZrhwuQJqih4s0Dz5QiZ8RAYqT+cQLOGa93kCa+OFqCVFJSAn0NfyMk3IvJa1fQJGCLqtAyClEkdRbrplXX7IN8WCp5ykISxCkGEovT7X+rNzMyBJ8F5TTwTYwEIhyD7xH+eTAZn0J7eu5wT3AHPDnxtMFBWk8yfiRM X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: bc1fdca0-8564-407e-156c-08db2f48583f X-MS-Exchange-CrossTenant-AuthSource: BL0PR2101MB1092.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Mar 2023 04:53:16.8783 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 2zPvkLu+Qnetj1B4AXe4Ub1pBDFvZqDsmESES7EyKF7lFLhzGcnoXQYXRj+f0WIxgJf6hY7W6md3COMLKD+lBQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR21MB3402 Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org Commit 414428c5da1c ("PCI: hv: Lock PCI bus on device eject") added the pci_lock_rescan_remove() and pci_unlock_rescan_remove() to address the race between create_root_hv_pci_bus() and hv_eject_device_work(), but it doesn't really work well. Now with hbus->state_lock and other fixes, the race is resolved, so remove pci_{lock,unlock}_rescan_remove(). Also enable async probing to reduce boot time. Signed-off-by: Dexuan Cui --- drivers/pci/controller/pci-hyperv.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/drivers/pci/controller/pci-hyperv.c b/drivers/pci/controller/pci-hyperv.c index 2c0b86b20408..08ab389e27cc 100644 --- a/drivers/pci/controller/pci-hyperv.c +++ b/drivers/pci/controller/pci-hyperv.c @@ -2312,12 +2312,16 @@ static int create_root_hv_pci_bus(struct hv_pcibus_device *hbus) if (error) return error; - pci_lock_rescan_remove(); + /* + * pci_lock_rescan_remove() and pci_unlock_rescan_remove() are + * unnecessary here, because we hold the hbus->state_lock, meaning + * hv_eject_device_work() and pci_devices_present_work() can't race + * with create_root_hv_pci_bus(). + */ hv_pci_assign_numa_node(hbus); pci_bus_assign_resources(bridge->bus); hv_pci_assign_slots(hbus); pci_bus_add_devices(bridge->bus); - pci_unlock_rescan_remove(); hbus->state = hv_pcibus_installed; return 0; } @@ -4003,6 +4007,9 @@ static struct hv_driver hv_pci_drv = { .remove = hv_pci_remove, .suspend = hv_pci_suspend, .resume = hv_pci_resume, + .driver = { + .probe_type = PROBE_PREFER_ASYNCHRONOUS, + }, }; static void __exit exit_hv_pci_drv(void)