From patchwork Tue Apr 4 02:05:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dexuan Cui X-Patchwork-Id: 13199041 X-Patchwork-Delegate: kuba@kernel.org 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 9816DC77B6E for ; Tue, 4 Apr 2023 02:07:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233186AbjDDCHL (ORCPT ); Mon, 3 Apr 2023 22:07:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47482 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232109AbjDDCHG (ORCPT ); Mon, 3 Apr 2023 22:07:06 -0400 Received: from DM6FTOPR00CU001.outbound.protection.outlook.com (mail-cusazon11020022.outbound.protection.outlook.com [52.101.61.22]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 446F32111; Mon, 3 Apr 2023 19:07:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=c3NZHMZEp7t5OhzpxvPpZET6JHrAy7bSXf/93QjniOb3nyfox2N75GJjjESvduW1vhtnU0rz3xZUBbjk4qYnI++07H5aBjpIg931u0iKbyFhjKH59c4HP8qJCBBQcgKYI8eqcoK1E+NtQBazu6Xu5H/0AcmVkUYlmglEYsSu8Sf9KlAl8uOepmKWu6jldF8Y/ozmdSFWQhlTCnoAteDtWRE+EmOflAbZgWV9DA3LMrIbdkHw6QPeGnjr+QSRhIYmvzF2C4rBPhmopGAX9gT7J5SI+eGUDDIbpcrEKzq8tsETqWIwlgmQP5quPyGCVVi7URw0TjreUmGjRnX815zstQ== 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=EyQyMDLnlJ2DfFZyn8dC+7aaFeGEHemgz2YuKNO70Fo=; b=J40qJrzakYsVW9TzXrK5lsCkPmPwO1F1uJmwuNX7vJ0fGLvWut4dU/e1Gf/vkj2NiP284/yvSSPuLJ3R8MxS7ozF/EBHmi9nYM4P/C0fSwtPQzkKvbBI0mr2TfLkewY9T6A/WhFgM/MhgZ92rZj/7wpuxBTYsyPW573Lyp1wAmUhe7tdYdK/77Okasa+QCAcGtiZR757KKCWo3STOCnZt0S23uaNu4L2GR7ldIRuTLsPUu9yXheLZR4rXBkxLyfq0z15NuVtJ79XchpGY/Jm9RH1/urrvARkl57j+g7LuFEB+rlpGQMYz1e38nrLDizes4y5hHgYNpTwhuo/uZOVnw== 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=EyQyMDLnlJ2DfFZyn8dC+7aaFeGEHemgz2YuKNO70Fo=; b=F/dGRE+/zVbooYfmyfDIztblEdC4h7LBr6x+EDnTJmljmq8J61mqpvmoclgqTGQ/0Q2Qty3e5I59GfrBu0G0M9GOa9cR6vgxAm9URkGM3xMKT+XFqmoIMkIS2UUneNvD72vGzC3yodEtmRikUjvcCZkWLOctK2KuQblrU7I5Hks= 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 PH8PR21MB3959.namprd21.prod.outlook.com (2603:10b6:510:23b::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6298.11; Tue, 4 Apr 2023 02:07:01 +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.6298.010; Tue, 4 Apr 2023 02:07:01 +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, ssengar@microsoft.com, helgaas@kernel.org Cc: linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org, linux-rdma@vger.kernel.org, netdev@vger.kernel.org, stable@vger.kernel.org Subject: [PATCH v2 1/6] PCI: hv: Fix a race condition bug in hv_pci_query_relations() Date: Mon, 3 Apr 2023 19:05:40 -0700 Message-Id: <20230404020545.32359-2-decui@microsoft.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230404020545.32359-1-decui@microsoft.com> References: <20230404020545.32359-1-decui@microsoft.com> X-ClientProxiedBy: MW4P221CA0019.NAMP221.PROD.OUTLOOK.COM (2603:10b6:303:8b::24) 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_|PH8PR21MB3959:EE_ X-MS-Office365-Filtering-Correlation-Id: 6f54c075-23aa-4760-e78c-08db34b14715 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 1LCrQ6z2VCxfGCI6jthm/RR6zqWTqTZwlRf/HoJWLDPOQ2PBlWnKNfbZjCuitM/vDCl4tAHHGN9DGcdVVek8PQhMhN+l1Yv/LnIXCc6UfRAjcNcCoMWC7pIU4P0xielRn72S/lxoKWek3EYkQAy8rw7nLjwdZ7a93/oSoY2rC5VzVoFvakfCKdKY+WYpNpRrclZ2aMpKR7/kwj4vfyYPnLbRz64/Ax862VqEVCXjTwD0FT+Rn/7lzMnc1yCW2NBn6M1WR8BVa4pQdM14WZojiTCYSn8jeY+DWBKARxidwGznU+yLV8nxn0UQ/pZsDI4ewWFIeXHGsnKLy+g4PqWveQhbE6uyaQGJd3a34WDv6mksP5J8PIBJu/eBpkrwDx+ZVPRfxHiL4rv9I5YIlGu+RyRcXMVk+odBOHV3DkhtbWQVc37neJD0OA3gzV7OFI/bBmt9/VPZH9+YkNQv77vyDZCa9BkaU3tV6RLzy+qUMktGHLDnd5tLWhjtXP4FpZhKZYsN5/PRNEjMrVaIwkFlkmjERjUVZlGF6ARN9VgDGAepjgvuupIte96HNiyw+vJTaxkQGVc6a9Mh65ZqZvQGvnpn7/yZDfmf01Kw8wNaanTSa4PMtwY9AtmK2IkwI00janymxu0on2TbUUR1G3qfHg== 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)(136003)(39860400002)(451199021)(6486002)(5660300002)(82950400001)(82960400001)(36756003)(478600001)(921005)(10290500003)(38100700002)(66946007)(66556008)(66476007)(8676002)(4326008)(86362001)(41300700001)(786003)(316002)(52116002)(8936002)(2616005)(186003)(6512007)(6506007)(1076003)(2906002)(6666004)(7416002)(83380400001);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-Chun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P04f233luE40n9c7uyACeqWl/r0pfG1fRt3oQaBo0wHdnCe2OmAA8XWpK/PsJ7sZ41LpzYOsdH5XcRKLqPMaxH8OldAqQERf2mWtPJdi5dy2kxB2I+DxBh1U3RYzRE+VOo1Ta58zWk+CrtHa8CRZCL8KuatKzmI2PtWm8bwRe5kXviG/HAmk8vJKZk1WfnBe8H6NbQh8lRciRfh01hNSwRrumT6COV3TeC4JxWcalWzhReV22NIPl87bICQpi6qcIteR25F4Nd+RVo9VpQU97PPrz/nDzgVVgO+J9e3Sphb1kuktFOdQB0SF8+0zbnC24OK6sg0nx+lxOrKVS8IwHINna85/6vAc2C9iim25UrnPHK7CvAzaaMm8/y+Vz7snQUIzrv7gdXpiLFt2sKXEV4ZM2HTnEfHzxAAauIWy3jxnTzDVGXVKGk0EqkjFSrwt8+gRd1kVbyTTtIbLeDnbIiNyoBvVVsYgw7bC3jR8SQ8YTusOoyjcAPEeXVTJoP1BoLBAIr+bXxW44KVLIqtUAH5X1XxYxC03Pmh840dj2EUMP8ww4bHpyqyNx+fQNQsEWtowMcS1SploRdqbCyZit5doXu4vpEpIWt72YuFPhXSB5dCBAoNthOT X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6f54c075-23aa-4760-e78c-08db34b14715 X-MS-Exchange-CrossTenant-AuthSource: BL0PR2101MB1092.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Apr 2023 02:07:01.1369 (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: M3BdP+6W+198buQ8Cx6YBDjGkz2r8/KrPzhyiEn9UyhNccP1FHfEIS5/Dqgax3DffdQFB3fN5M7DaSeNgvz0rA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH8PR21MB3959 Precedence: bulk List-ID: X-Mailing-List: netdev@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 Cc: stable@vger.kernel.org Reviewed-by: Michael Kelley --- v2: Removed the "debug code". No change to the patch body. Added Cc:stable drivers/pci/controller/pci-hyperv.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/drivers/pci/controller/pci-hyperv.c b/drivers/pci/controller/pci-hyperv.c index f33370b756283..b82c7cde19e66 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 Apr 4 02:05:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dexuan Cui X-Patchwork-Id: 13199042 X-Patchwork-Delegate: kuba@kernel.org 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 9F45CC77B6C for ; Tue, 4 Apr 2023 02:07:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233244AbjDDCHS (ORCPT ); Mon, 3 Apr 2023 22:07:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47552 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232973AbjDDCHI (ORCPT ); Mon, 3 Apr 2023 22:07:08 -0400 Received: from DM6FTOPR00CU001.outbound.protection.outlook.com (mail-cusazon11020022.outbound.protection.outlook.com [52.101.61.22]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BE3332695; Mon, 3 Apr 2023 19:07:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=IivObe+W11y54caRAFEVUO0vzIrSqVgkfSJj55FUUcXNSw03CBpbf5GKcjib+Zw8ZPy8u3JzHdxqHt7HLVdD+sGgorSBCM8lRwQMi3aM/14gKYzL7Lfot3TtlP6QRtbCKTJN6owkBfzrSXM4ExCUFDTyY/cvv0DEpAujcX7FHLDwpKEUyFn1C8H0QMHJozBVeTJ/f1g4ESAcLmYSIXFr2Opq90HzLuA026bcQkoBTv4RPhSdM4NbzAee27jMO7Cef2KeS1C13mRL6H0P7+AS/dhdIaELIvJp+19qjsUxmZpNR4FatrrGuM3LldPQZiWFD0A1wL9i4XNWhkYMD1o/uw== 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=rQw8s0e+ITqhk/HKjdZspANCHM8y/8k8XqmHREtfe/o=; b=DcOV/zx1kXnMj7Rh1BTYVvymLD/ZwG8N6+u04kC3GzhpoET8FmK8cXafvgwu1l69thWCQrS2/TzOdz3IkGJgqdtnFm2Zubp6tIDpcuAwMIuDcppUBtXNVPQzOUyku8fQXtSoooKGtOR4FJknCEQ95BorGJsNIWFJtgz1twrZfgpJjEYvBADmf21Eo5PHUt7PTVjmM/24Ak6/r/PuHK2uIm3aG+gYUCIyFRwSgDylFX6jMZw0gZpNU/oQYzCCtksv2vSclb4Z47pYpvl9FfAaVcyGb+aT5ZyXMalNiCVBx6C2E+MbUVz5M9l3OyYi72WWtMgSb+ELn/DG8Lmx3JFbEw== 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=rQw8s0e+ITqhk/HKjdZspANCHM8y/8k8XqmHREtfe/o=; b=fCIUP/Kfzun0/Bd3wMal06CDDsU626RetHGC6ZDsdVGmHPeb+lgcZBmU/VChutd07tavFR6eyiRKAefATEC0OAKTkz5nv1oBrsyo8QcCwO1svLtkHLS1DRciBGFm8DukLZiu7T0dQeykbRAlaNhLb/1qZtQgxbxrk3Vvj8v4Zag= 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 PH8PR21MB3959.namprd21.prod.outlook.com (2603:10b6:510:23b::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6298.11; Tue, 4 Apr 2023 02:07:03 +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.6298.010; Tue, 4 Apr 2023 02:07:03 +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, ssengar@microsoft.com, helgaas@kernel.org Cc: linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org, linux-rdma@vger.kernel.org, netdev@vger.kernel.org, stable@vger.kernel.org Subject: [PATCH v2 2/6] PCI: hv: Fix a race condition in hv_irq_unmask() that can cause panic Date: Mon, 3 Apr 2023 19:05:41 -0700 Message-Id: <20230404020545.32359-3-decui@microsoft.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230404020545.32359-1-decui@microsoft.com> References: <20230404020545.32359-1-decui@microsoft.com> X-ClientProxiedBy: MW4P221CA0019.NAMP221.PROD.OUTLOOK.COM (2603:10b6:303:8b::24) 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_|PH8PR21MB3959:EE_ X-MS-Office365-Filtering-Correlation-Id: 12a42dfb-5b01-4a97-47c4-08db34b14861 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: qdP/HG0zihdWgIFDHdPFK6dSCOQQLvs86fwQPwd9IzCC/c1llsv7O2tBsOMLaaFN/ZkK6AG4Yw9axo4AKWsOCHkGWmlwYOGBRBXrgMj47kj6Zgi00jW6bOnZIHHIbnm/oWorMzxml+LppFUKSapoWfyH1aWcKlZ/wT9oS60FWhjG1GkI5l7mrJzhbgP+Eh4Ibtpau34wIIEaUJaKMf8MaCtM/1MpcVROK9zRVC8+/GIbCrrfLmDlu/Yi/jcDILSbnw0ukblNn68b2P8vPmvc9mmOTFhwBJB+vvZii4r2Z30o/LVQpxklKEQHJk6tQW5ajn7j159R7Vj/LSF3yuD+7CUl5eFN20SWoHpitetEsxN4V5DO4KkZ/YKaKyv9KyoEZyd7jpJ0xkQ0ni+ahiQReEZa6hBzqFY3l43sEkh/637MDH7ji8yYU0+poNXK1bVAQ3Pw6RyadzqrniiZeBMgIroyhuiRKJvF4z6qo/dlvEQyl/hAnLsG6NubhxF+2pzqzp8ctmlhUOMw915OjEBve9MtdRMKED4T1FwzIeY/qMXJxJot6eS8aPWAm38vapmCNb3dS0Eq0Ze6elY8DH66YipOAQIwry6Jl9lRzs1zUAhrUW/uRldovwS2/hEmsRPcBpBBcfJYCnFWswogM6lgMg== 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)(136003)(39860400002)(451199021)(6486002)(5660300002)(82950400001)(82960400001)(36756003)(478600001)(921005)(10290500003)(38100700002)(66946007)(66556008)(66476007)(8676002)(4326008)(86362001)(41300700001)(786003)(316002)(52116002)(8936002)(2616005)(186003)(6512007)(6506007)(1076003)(2906002)(6666004)(66899021)(7416002)(83380400001);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: tOyVx/hLPywgs5I+1yYZ8W3eU8E1B0Pylq4Q57rR9DWu5IB8/iiVPQdmXQ9B4PWOEScfOajdgBPwfyaVHWQzTGZYbCjwcJxZfShOaLFE9gwuVgU9N/Jw+UqcDhZXJl+4W8UJKDo7hPDPFP7gHu4Sf925dU8HXMX81A9/7rVfZSyRK3PRWcPa7biJEzoJoFU+f07p+Pz/s/XrW/5+mqJvXJtAH/4ytOQK86nTOwYZctt6A1ZLHM1YOQNvTOAqHc33d/eDGkWzTm9UJf0zf66g6omPH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Y8qdQMbXqyukQNmQeIc5T5z+y6Kh6wvjBqXmVBHr3RFEtrxiHq60pMslsgyyYKPIzrfHw4o4XbNznT9L3ooFHdpkx9kBLqTPu/p+KeZ/c/rzhpMn1goemjk1VGro1dBQ7HsTM+7XOevzAIpBxZP4AxsA/5s7OFZD4A7ZupoMb9XYiGW0BNF94OoSbFoG/c68iUOSm/tQ7dAd6bb8eaPSsx+S9cjv8XHo1eZvcZ96CEA+ds3kTUQhaMulV5CIwUEj3VizH1tQjgcImCRr6Pjr1jF9EQQvLTJ001Yv2GnpGz0jV1M7h3N4Ugzm5Md9aYzsxz X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: 12a42dfb-5b01-4a97-47c4-08db34b14861 X-MS-Exchange-CrossTenant-AuthSource: BL0PR2101MB1092.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Apr 2023 02:07:03.3284 (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: rQpojLHSL7Nb/TCsmZL7NC2xD4NEpOl6mmGznyKEO7+MmLC7m5WYNmoH5EEwTRK37dgrwNODfPpIzxLUdusvAA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH8PR21MB3959 Precedence: bulk List-ID: X-Mailing-List: netdev@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 Cc: stable@vger.kernel.org Reviewed-by: Michael Kelley --- v2: Removed the "debug code". No change to the patch body. Added Cc:stable drivers/pci/controller/pci-hyperv.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/drivers/pci/controller/pci-hyperv.c b/drivers/pci/controller/pci-hyperv.c index b82c7cde19e66..1b11cf7391933 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 Apr 4 02:05:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dexuan Cui X-Patchwork-Id: 13199043 X-Patchwork-Delegate: kuba@kernel.org 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 EF20FC77B70 for ; Tue, 4 Apr 2023 02:07:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233160AbjDDCHU (ORCPT ); Mon, 3 Apr 2023 22:07:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47590 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232997AbjDDCHI (ORCPT ); Mon, 3 Apr 2023 22:07:08 -0400 Received: from DM6FTOPR00CU001.outbound.protection.outlook.com (mail-cusazon11020022.outbound.protection.outlook.com [52.101.61.22]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BFEA5271C; Mon, 3 Apr 2023 19:07:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ehL7GItWkaPJbysyfJJkbAB3KU9X+W65ZO8nq3puNFdg/onOwU8c7vDF9h1J899WrTOPgc7sINB+OWq9ZM2i+TRq/UkjZW0vySsFjRdW1Wy0fv2QD+Xyp3F6xtEVgct5m6avlTjKVVOihRRrz3iqg1poD3zS8CtmKhBkbyoOFPfdVemHmX48dgKlw/Y6tQQ3yOtYxmzVo9DGBnZu8GhNbgwiViZ9WybeQLizitsuHTc4ncXeOM2tqL8IVSMGJOGauLq/U6wffNVZ2ypn8/JQaOY7OtbOPGr6IxD1k4xSEKsUV7PwYf8QZVISuPNhnrgLEO1H0MqMfklrlYb1kc3e3g== 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=kxLe1FYK7bQI/ndH3Bdw5dGK2hjINKnHd0St/4JWr5k=; b=k6EjZykxJC1nUf1QdpJIetI+SHj/1OFV7jdYOtJq1g2UZqreWFyWHilKF9ls2Qql7KGhVKR4d20Lz6o9IDFEN+/UKZwobwyB/OY5334+F5BvgRR1siMIw8MgbBOyIQd4rYNqXmLoz8Xhm/WGMi6Lyqa1xRA3losFtQEybcTBKsztZe38eqSp6Renm6Aakjcws/f0CEsNkK/5Ps4iC1J7HiiQ9bQ0+5kCQMBDArs14e7LNqrc94FKgFHgzUXsjLrAFRWtOUm06a5XJrN7XkO5QuJPddyotIZ3ufjObHD6wGoyWH2MBZ8qA3IS/1exBkhjnc3IAYvEfV0szjvSf8Co+w== 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=kxLe1FYK7bQI/ndH3Bdw5dGK2hjINKnHd0St/4JWr5k=; b=IXgLLigmL4wVecNoDO/mZ5ziTOc5M5af4HvVzBOrnvI7up3O67nsYLQoc5bYhmZcDoum9QieEHE6VhLZNvglKbPiufyxjGnhm4CHB6NL4ZNVO7rJGFGKlIiSna+tR9NUs7/7BEjWVfLXqehQSB0i/b4soPkUudVjLoX0RwjIDms= 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 PH8PR21MB3959.namprd21.prod.outlook.com (2603:10b6:510:23b::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6298.11; Tue, 4 Apr 2023 02:07:05 +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.6298.010; Tue, 4 Apr 2023 02:07:05 +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, ssengar@microsoft.com, helgaas@kernel.org Cc: linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org, linux-rdma@vger.kernel.org, netdev@vger.kernel.org, stable@vger.kernel.org Subject: [PATCH v2 3/6] PCI: hv: Remove the useless hv_pcichild_state from struct hv_pci_dev Date: Mon, 3 Apr 2023 19:05:42 -0700 Message-Id: <20230404020545.32359-4-decui@microsoft.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230404020545.32359-1-decui@microsoft.com> References: <20230404020545.32359-1-decui@microsoft.com> X-ClientProxiedBy: MW4P221CA0019.NAMP221.PROD.OUTLOOK.COM (2603:10b6:303:8b::24) 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_|PH8PR21MB3959:EE_ X-MS-Office365-Filtering-Correlation-Id: f5dbe20d-7f32-47dd-459b-08db34b149aa X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: rCamEumvZaf+JElnqRQHUuYumGB+YCwBdt2zLq+pLpfN+6K2Sr/wo6PieA8Qe59WRt5+VplzfgSq4Krbe3wdAVdD1QfnXd2b4NyBE8MLaRd6Mq1zI8uD1aM+ccQDC40XYcI7xeoJiIPtjie4B9BQcHrteuxSpfElA4OJ4Kqpuc5Q2vazlraFmFe3Rv9siZYvadWn5ITAmkrFsh4wgZJWlWyJ15In+ieFK8CJkLJOjPgYw7lt8SCe/zS67VOQ2eaai7wbasbKHSPa+4LpNbc/znMoscZB/7v6l5jSp7g/9EQIrG8869XQrd9LYVAc6HROsCMRAhGjLiSuSWX5n7DGqLd2EexPTbxCTMnesceEYHW8heDVw3E+D/rXoebPg8DTmtZ8nRTjqXJ3YNlSr0w+vwHLpfyWQYTVGUlmdTuUr1gnWNDpNzNrsTD6JmRIAnwSosSQaQwUO74ASHXZJMtHgLNv9BZ07qFADq6/7o5Qyew5vG0N3wIDAYRKsGUtCBZhBkg8G17aENq7D8f51cYsxaUuTp5PP4zr3fpLbyNh47zAkyIbxrkNsVt007L00z/O3syZgiQOrK8Ixve8enpFNVuljRUEbIcQExvJCxSJz2G2V3WBcBmu/VXQufMPOU5ySLa8FqvXH8Psrs9cJoEMXw== 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)(136003)(39860400002)(451199021)(6486002)(5660300002)(82950400001)(82960400001)(36756003)(478600001)(921005)(10290500003)(38100700002)(66946007)(66556008)(66476007)(8676002)(4326008)(86362001)(41300700001)(786003)(316002)(52116002)(8936002)(2616005)(186003)(6512007)(6506007)(1076003)(2906002)(6666004)(7416002)(83380400001);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-M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AeemKzkfSAFUDMODOihlX6+Ae2RYf282Ir181JBbhMdvsVj/q/wqr3AoRo+8TBCFASWqMdJ0mo/L+POzPN1kOghjHJcQ5l9KTUlMB9hpQVGqcY/2J1+euprPxxquAm7VOXZRJH28HRdKqFQ6mvqEUTl3RKKSL759fLc8gZBvdDm7cjh4xqcZf8HpMxCoU8zT5HFsSlG4wVx3vF9H1uyOm/1NTHy1efLeK5FlsT+gKF1s+bTaPhsNqDalTgqAArfanustGKR7VlVoHJpxCWLWB2gc6ZyUhTknbKn1IHZEflz01yWgo+pS9Ry0Gy0HZv4/SLVO7p338kmxxWhFwiFAe9XspHmOgrlrFp+s1YCpxnBHd1TReiKS2ioYdCE2mUWe01/hCsFr8iTjNNdmQ1EYfQif8Za9+blrjNTGZklgSPbN8giacoxCwRe9uAkrlQe20NwomeJ0ZkYn+youWWk3scWofaMTExGIDHLYpLdbnPi8Dm42vx9rKVrKt7s8zOvFolkUYODHgxchmquiznthnjcPJaZEsGsWQVO5p/ZeyHd8V6JYIl60IBzoVVZ5GH20ASTfvlmS/N9UwB038F9beaL7Ndy1voWJd8n1YQyh2FvwDQpu7c3Q X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: f5dbe20d-7f32-47dd-459b-08db34b149aa X-MS-Exchange-CrossTenant-AuthSource: BL0PR2101MB1092.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Apr 2023 02:07:05.4694 (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: LCXT/on0pqJSoGmFSUBX7w7GLZkA9Re8C8BzYAjCikqnekq52grCM52CkZoWerXUdTt5NjM3lDnKqney4+EJvg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH8PR21MB3959 Precedence: bulk List-ID: X-Mailing-List: netdev@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 Cc: stable@vger.kernel.org Reviewed-by: Michael Kelley --- drivers/pci/controller/pci-hyperv.c | 12 ------------ 1 file changed, 12 deletions(-) v2: No change to the patch body. Added Cc:stable diff --git a/drivers/pci/controller/pci-hyperv.c b/drivers/pci/controller/pci-hyperv.c index 1b11cf7391933..46df6d093d683 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 Apr 4 02:05:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dexuan Cui X-Patchwork-Id: 13199044 X-Patchwork-Delegate: kuba@kernel.org 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 88BE7C77B60 for ; Tue, 4 Apr 2023 02:07:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233345AbjDDCHn (ORCPT ); Mon, 3 Apr 2023 22:07:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47552 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229684AbjDDCHh (ORCPT ); Mon, 3 Apr 2023 22:07:37 -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 32D4D2704; Mon, 3 Apr 2023 19:07:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Kk77QAgqKzL3752Lms9ySxf3RJ9I57v8+11x5LbeSo0beLUOsVPqjsm/rMf0/jBq9tj6X81LCX1Pljcag2jyjX5XC/sGxCAw4g8JjoPIpDl3+DStDghmsNvbewYth3Zux9sZrpHFKTuShQME+nBMMBN0GQmN8cqHpCZHTM3E93V115Vk6/+2/XMoBZVT8Vs+Ku3s175t9nWwwFPNK9ZEsWmPkM8UpLzz5BBITTc4eJfI6cBtXVqeIVZ+AFnXZWkA2rOYNh1BE3uTbBm06zz0dA0qN9QgtyF76SkNw5xDeH/twtPH3fOq3Vrq2zjO4Dyb3fIjzJ2J/UJOGYabj/t0qA== 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=jneeNI1CuHXTmt+Z+OGxvygWjqmXlgkHAmbx3PaIIgU=; b=M0oBTx9mxuT78PcNoivi+9jUvjj0DwDqDT0k8cSSFSGpXf/DDynT56niIZ1r0ArjztNaa6QqhtT8jr5V+4gXrXIQ9pOcIiso2Pym5e2PA9poXZT7aDA5uwY41QmWY7aeyXW5ubigRemxWbdodFHduOFXsiI+gM+mcfIiXdUv37ShzfD2/rz1mvKDaTJeNzdV9TipojoM7D+/E4aroJwbiZXUTPGW1P4xFXIO/ACD1aMANuzdGXf2mYl4b/p7JB/pHcJXF8dofztMSOh76jsWPEAPE67Z9zZSps4lhc8MrGGBhwOlGHpRrkkZdZqudkRFp96NZlj4WWDnF9JaOHhiFg== 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=jneeNI1CuHXTmt+Z+OGxvygWjqmXlgkHAmbx3PaIIgU=; b=ZWzAVhaZiacNEfR3ufyYJPM+Gl7b3Lj3lIS0xMSDvu1zgzSnT9pKj7opwCNgeVysWwiiByrNJGjBIVyljWpu6WBdd6/qq7mxcL38q5NERX2/G3nSKYzL/NNS6ixEY+oEKiCknStRxVB4/cKXvp28T7151/pf3YFEnlgorn5AQ94= 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 PH8PR21MB3959.namprd21.prod.outlook.com (2603:10b6:510:23b::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6298.11; Tue, 4 Apr 2023 02:07:07 +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.6298.010; Tue, 4 Apr 2023 02:07:07 +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, ssengar@microsoft.com, helgaas@kernel.org Cc: linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org, linux-rdma@vger.kernel.org, netdev@vger.kernel.org, stable@vger.kernel.org Subject: [PATCH v2 4/6] Revert "PCI: hv: Fix a timing issue which causes kdump to fail occasionally" Date: Mon, 3 Apr 2023 19:05:43 -0700 Message-Id: <20230404020545.32359-5-decui@microsoft.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230404020545.32359-1-decui@microsoft.com> References: <20230404020545.32359-1-decui@microsoft.com> X-ClientProxiedBy: MW4P221CA0019.NAMP221.PROD.OUTLOOK.COM (2603:10b6:303:8b::24) 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_|PH8PR21MB3959:EE_ X-MS-Office365-Filtering-Correlation-Id: a78004c2-47a6-451e-4394-08db34b14af3 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: sPKPKQL+wDd1lWJhRAEmynII/RsmTO6NMi8zGd5vDtP+Sq+QnsGEPzMl4xxXKsmLfM/d5V7kcwgOTSE48YYS7TVqbwQjfNG6JSHMHerHVVOuONeDXpMQ2v/FZpF4N0nzJ5qYTLOSgs2C7xh+GCrX7XiCHwzFJtKULzeLEZll5DlFddveHycfvrT9r0NsQ9BGNdf4QH9lSu31a8AsjDKlNersCI5wH6e2u/5KJy7yI4akzhS8NW+/pjvZ8kapLrKtuUg6FWN/B4K8tdjvfYzCUmFwkNi4Ab2iBa5cZrhXII44l6ykVi6UUTDCqtr9ip2p8btVO30j2P8iSKV+6EQvvHtr9DxeqzAKcRvcQgX6S8V/8aGVz6ixkM9Oxbew0sHFqqWMSkPSPnWIf+nGvSYOB6Qfar1lhTgqsqTbPqhWzJdu9S69+XKj6OLKOYx9aX6zilj6RdaYRjqMbcnhYI+zyqroqA1aWcabn0qyWHInr1EJtFmoGuPbvGNZ49sRhXX/YfIHt/fYbqxeUq97WwU+nV/hp2FuVaFYG9vgJMNGIOIDEwNPaYTeTVFfqa7E1blgpsTPJMF4Wp6PDktwJUeTx7PYfTlRf74WeThMCCNXNR62sOrjC/wjO452JhP4YPuZaTnTppie7BaRNhvA2fH77g== 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)(136003)(39860400002)(451199021)(6486002)(5660300002)(82950400001)(82960400001)(36756003)(478600001)(921005)(10290500003)(38100700002)(66946007)(66556008)(66476007)(8676002)(4326008)(86362001)(41300700001)(786003)(316002)(52116002)(8936002)(2616005)(186003)(6512007)(6506007)(1076003)(2906002)(6666004)(7416002)(83380400001);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: uVwV9qHZbefMLp9nQHc44uDCDEeiVDQiWOlWqXL3yB+jy+c967BvPv5GkUfh7uoDGKPAoIHJp8mZye9Dn9WieRRl9atb3OF3C8NX5Fr3vPuv/+K36bIwT3eUo4ZHGfxdXjqtP7sJgAjkQOv7Uk/2b5+qqm3j2wcj7ZL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EpP8esUkg6WnMdzU+uD7kKERLA8kQhijq5BN0Wqy/OEYBg9wO1peiuv6nt043bFyQ/9CGPqSgGzTjcl98r3+mGmuHl1DscHNt5JF+CYRh08n+POB5ysf8rwJiG6zHQzMuPqdfG71sOp2o0On0H/AQBXPuAcG9kI6LBF1yXnLqjMdQqzzmqQDwzBeu8TkR/uhmBbwKFFs+PRJcC3q4k39Hgo2zTzsY2RgjBlmXDylTZ0euyenidXEgI3WYnV9kXD5LBqruRvZbnrjg2J7+WGn+K323ITbg8+NUInfOJmT+P7iDi1ggRKHY3jbIqThr3xObB2F9Ma+Bz23Uml1cst5D/+Zn2RQSS0X52owO4loSr2f7mjACczdIRUx3TBjQFof9RNRgth3rnGR2zUC84DPcpsCr1U2y2zJ7 X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: a78004c2-47a6-451e-4394-08db34b14af3 X-MS-Exchange-CrossTenant-AuthSource: BL0PR2101MB1092.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Apr 2023 02:07:07.6618 (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: s1fitSC23aGFjp5NrD7UPko9E9q1oz4hvrsJxVgZU0NgriRBll84fJ5PRbLQVsmMnRwVSmg8rUGRPjT8mMoRWw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH8PR21MB3959 Precedence: bulk List-ID: X-Mailing-List: netdev@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 Cc: stable@vger.kernel.org Reviewed-by: Michael Kelley --- v2: No change to the patch body. Added Wei Hu's Acked-by. Added Cc:stable 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 46df6d093d683..48feab095a144 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 Apr 4 02:05:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dexuan Cui X-Patchwork-Id: 13199046 X-Patchwork-Delegate: kuba@kernel.org 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 A87D9C7618D for ; Tue, 4 Apr 2023 02:08:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233558AbjDDCIW (ORCPT ); Mon, 3 Apr 2023 22:08:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48936 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232597AbjDDCHk (ORCPT ); Mon, 3 Apr 2023 22:07: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 296A53580; Mon, 3 Apr 2023 19:07:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=bZylccHie1l16rKWASFoQJs54YhVR07E0FY4/ZEo1K7gRu6D9GmCEun3yiaqpbqEtN3yUifYTUrZlfvnRNtO5bt+My0WdYuOR7XL39RYiz2FsXDn3x7SoRQbxyrg+BtrTPp3TIoJaGF2iCfraXbiXRyeuu64E5s5qosDbXM06mIQUA55m+F3wPasE+25OcT6VOLNnZ8XktUYU3n7xxR1D3UCtwqKW9Ypr/nn1ce9DKCtV04bZRCpxh1+SajhqaFN6fWPfJEkI+a08PtteXmPkTBustq4U8Td3ViGQ2Y38jjrSgh6NwYRby90XOm+8r6LWb3W/zAktc9La8qVS1uSrQ== 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=RPFm4OWnOyuxncPe3RjVHu8Y/2NhJOX+IXISsBP0JZo=; b=T315nGxZ2SvzzqdL7Zp7+Qn4Cc1UGCl5d2fM9fjj0CrbIxHSZAMlNJLd+H+FzNCih/My25lajhDp4+ts0EWgexcHJns7KB+mmW15K8eyVm9VstTRoZFY3LrFisqVcI/TrTWjch3yeykwJ8rtu6mIGdst0qEYbHU9RYSv6iZFbvdkI+M/nvvf9BD9EIyzM099Sca45w1DK6DbRcbYENlICyAxfa4nIYvUMds6Av4lzz0meVpLgCYixDAO9/7jZD/7uxAIqN58CaErDqJq0+tfMrJDp2trIg1KB1UumRRnasAtBb9ty5fO7enrB/a2jklnSSy4zf5oZbqwMP7p0gU5OQ== 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=RPFm4OWnOyuxncPe3RjVHu8Y/2NhJOX+IXISsBP0JZo=; b=fd2lYieVaMrUcqjC5M/jRFxjuztq0Pob0GERmmXX1Cx+X4mRCBdmKOZZbIYe3yulmb+x3HVfq4SJ4CURgy0dWXf9nCTm0OsQ942EGX9k9feohsNoLHklQH+z/P+pdOnFftdfey3WnZwbsYpQOL/31+T9ndQJbWhzkjF60drVhPY= 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 PH8PR21MB3959.namprd21.prod.outlook.com (2603:10b6:510:23b::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6298.11; Tue, 4 Apr 2023 02:07:10 +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.6298.010; Tue, 4 Apr 2023 02:07: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, ssengar@microsoft.com, helgaas@kernel.org Cc: linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org, linux-rdma@vger.kernel.org, netdev@vger.kernel.org, stable@vger.kernel.org Subject: [PATCH v2 5/6] PCI: hv: Add a per-bus mutex state_lock Date: Mon, 3 Apr 2023 19:05:44 -0700 Message-Id: <20230404020545.32359-6-decui@microsoft.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230404020545.32359-1-decui@microsoft.com> References: <20230404020545.32359-1-decui@microsoft.com> X-ClientProxiedBy: MW4P221CA0019.NAMP221.PROD.OUTLOOK.COM (2603:10b6:303:8b::24) 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_|PH8PR21MB3959:EE_ X-MS-Office365-Filtering-Correlation-Id: 988a30ab-bb88-4622-686b-08db34b14c43 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: lmFfaHDExSx6zk/oaST89v1JASYQJj17KBQtUt5T3b7Ch+sNYg85Ek6E/JpX7KAukN3w2vSqOr+Qcmcb5RheEJjWKY31i/OBy58Rly4dZJub4olSAOOR1Ypto5YX384HjzlzexSABx6fskb9ebmm6avtXO0LdG6oDOdIXE7FoVpwyc2+Zk5GAIPDdnIyghl/aIo/CiugGX/ys6kIIfEU2h4BpOQelJ85LC6FBJYHHjZ6gDv1nEml91CAcMIRgPxu2imdi5Q+rPEBZjxT+95JFrh9Ntl0kNpt1MCNPhTemOzSQHpLYKxtwWr1V9Bd0Ba98AogxKWhyS9biLi9IGm2i/bLe553zTwpvoHbcAE/tV9WmGFmYrni5HGVMBMbhR+eQixaog8uvXJeKqQ4HLsvW922AvfPcSFcSglE7e7GsebmaVlD/b4oG7sKgm0LzJWjqas7V5hwuXzFpeB8JH0QY0VRuwUKu8S716VEahBZ19vgu8mC1fu4YzpJN6X7Xqkb42iex48jTcOfCcP6ulxI1TJPMBw0+HqXHZz3jpZ4Fy04NxiLphvAEt+JUzY6LbakUMFCl9u/Efd371dSPNbrbp0oQR0/3Mz/JjNp8dmfVGy3b+hn4u+eVCS4BiBLajNWeei0BF5Tm1C4PN7QLJ4mEA== 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)(136003)(39860400002)(451199021)(6486002)(5660300002)(82950400001)(82960400001)(36756003)(478600001)(921005)(10290500003)(38100700002)(66946007)(66556008)(66476007)(8676002)(4326008)(86362001)(41300700001)(786003)(316002)(52116002)(8936002)(2616005)(186003)(6512007)(6506007)(1076003)(2906002)(6666004)(7416002)(83380400001);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: b3mMO8l2sNpkh7XZzt3+/R2bB1AhOj7s4l0yg/KEUFS2Hl1/0O6wq8/4aTQHA9UvtCc4U8dPR1lH4MiUfzlpgkZRyMi4Gg65wTECO48TITJbLiLgsirtw+3UFr6PdJsBlSuQQHj3enjZ2lYUXb+K8OyrVf0nvdfmm0Uyk+ZFMX4TuGsN9gLrfeMmeFuhfHOJG1iPfk1pMu0/iQ29edGfl0ngFtWze3tm3c8UPTsF8Z+lx/4J8+bE6gdQJx2v3AILkwXxCwm6nhgruR4x4FPgA1mNGx5jtW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VHvBNA6BtAFzIUj+06/k5itpoatni/FmqREiwx8r0f86UDz+TdQgrStKNOptK/DRdaglhse02K7lsu5sMrzIvCCMpwK1krflgK3XfP7aWc8MksGrvRHl2t2QqzNOIetCImztRYDrVexypBEa18g4hvcGw4XTOIycm05zCK8rcAvbv0LuQXK6tSp6S9b9Mxu0YF9XJLFVORWtgiTNRIO8AgWWL29omtpM3qXrlQl3pBvBQbsuBtHk4p4pQ19h0Aw6ORLl1Mej2mMNqqhE0g4eHDw3/ONF1aF1nUv4PwvarIMFPU X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: 988a30ab-bb88-4622-686b-08db34b14c43 X-MS-Exchange-CrossTenant-AuthSource: BL0PR2101MB1092.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Apr 2023 02:07:09.8287 (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: lgA/eBAasg7gzrpkzc+2Nszh27l4U1m4qKtZWnZgZgdRHvkkDZDXd0UoSJ+HTJhUHWLzurqycKcrL2Tean43HA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH8PR21MB3959 Precedence: bulk List-ID: X-Mailing-List: netdev@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 Cc: stable@vger.kernel.org Reviewed-by: Michael Kelley --- v2: Removed the "debug code". Fixed the "goto out" in hv_pci_resume() [Michael Kelley] Added Cc:stable drivers/pci/controller/pci-hyperv.c | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/drivers/pci/controller/pci-hyperv.c b/drivers/pci/controller/pci-hyperv.c index 48feab095a144..3ae2f99dea8c2 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; + goto release_state_lock; 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 Apr 4 02:05:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dexuan Cui X-Patchwork-Id: 13199045 X-Patchwork-Delegate: kuba@kernel.org 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 30FE2C77B71 for ; Tue, 4 Apr 2023 02:08:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230108AbjDDCIX (ORCPT ); Mon, 3 Apr 2023 22:08:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48814 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233362AbjDDCH7 (ORCPT ); Mon, 3 Apr 2023 22:07:59 -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 EE9832697; Mon, 3 Apr 2023 19:07:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=e3vOtvneztIcQNqSo5ywRnqvMCGGMI8vQDyfUMc63QsFNEfs24u6NE+ehBl5Pq5Z9foKN3duKebWogOMhokSec+eqtpjfvf7CWGeZugLvQNdyI1GjfjpD8TzfUETKmuYC6I1Y2DlAoUh/1uneIqmdF1exNgA0WmMt4Q1kuyAHSrGkyhWCPb+lI0DA3fsxqqz4TwQnt2lXNJtz1oVSz/OY+Fu0+0xKKgNDGWQSyZcqqcrOzCyeUL7U4w5KFQrPoibgqFU194ORcMog0pkv9glZRoitevXhWHAgYweDcvtO2Eg+b1ILm1fK/WyKlPVY3YeSqWBGk5qYPKeAOJ3ewMfbQ== 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=wDCPVlpBub9q/x5lZqg7h70+lhnavfvxkowfL2WMUR8=; b=MjMO2RyN2D1lah5oHivG3hFUvSM03ufLuqKubpA+PFMhECuJvhpnWs0rkvXzFevJNknUJZgQJMnqWfD26OgNQQPW9anKiOXmiRaeXPQ6ht2mRYwjfVJZeLw+5yRATDs2XUTCzSM1znxiOuQ4Thk2rC/P0lFeZx0SlrVf74kXSJlGFIuyu0PZVRjs3Er+gnQICmoy59My4ScNGROnVIBc8qShsNxSdj8GBCvG9YRCvySaZsS7dNSOQRE78NIat7GPX4Zz11KYyFfPxLjNHERPwm08ZwfBb2S2aBzg+FFib1GYjt0PuA4NXPWSdksGfK+ucLtOM2T1wf/98fXVjP9gRA== 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=wDCPVlpBub9q/x5lZqg7h70+lhnavfvxkowfL2WMUR8=; b=PBWjRFjFJIZXPg2iG2LNqf2FjXzHjXbEC1k+OUJCpETNs/HCVPraxYTN3qz3l0eHt0Pye+Il3YSXdRyp7oijVx1ZNVZnY3p2KH8ns4aozV3x4t/Nd4AiFtI2W7lyIkgndMdkTJMGNsWanYG6eilePe5qD6fq8Yd22Tfnfmxy5KM= 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 PH8PR21MB3959.namprd21.prod.outlook.com (2603:10b6:510:23b::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6298.11; Tue, 4 Apr 2023 02:07: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.6298.010; Tue, 4 Apr 2023 02:07: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, ssengar@microsoft.com, helgaas@kernel.org Cc: linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org, linux-rdma@vger.kernel.org, netdev@vger.kernel.org, stable@vger.kernel.org Subject: [PATCH v2 6/6] PCI: hv: Use async probing to reduce boot time Date: Mon, 3 Apr 2023 19:05:45 -0700 Message-Id: <20230404020545.32359-7-decui@microsoft.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230404020545.32359-1-decui@microsoft.com> References: <20230404020545.32359-1-decui@microsoft.com> X-ClientProxiedBy: MW4P221CA0019.NAMP221.PROD.OUTLOOK.COM (2603:10b6:303:8b::24) 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_|PH8PR21MB3959:EE_ X-MS-Office365-Filtering-Correlation-Id: 7c926473-d701-4552-c891-08db34b14d8e X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: vc4FiXZaK0usUYP9gESRaVpcpf/Nmf/fF4lpfzeizYeyGJeJmm6oFHefiu4w/7ilMfHqA2bnfN4PD4f+9XYAypcDmKHbuLTWPLkO7y4MwpnVU5fouc1lkYwf7OLy4GW9yCdWBnIMwCrDP0qa8dXcSoIgPuw4dBeBCmwi14s7mqAeK2pxrbbD2QVsFI5s0UGAbrKKMu9raS8l9fzMVUieICvyn8k0AxA6nDcEh3dgR/j7rqlU/9AxMUMMEMFTBghO8P8cPp4TVl05xmU5O4zP8p5DnTp0NoU0N6sGMjxu556WQvPR+J0N6oEPJuBbR9ffacBS8NvJDuwpkRMPTW16IrkhNGf4+lQcRC4eErQtKMOASQP/ldKpMa5smxVnDdNn+aBzjQSII+kC3olNSpPZOeqPtTZ/lIkWjn/V0dy9eBNfJLDvOecm3sHIT7prICbno6O5Troqe+96bABxu5jYoh3paaaVJB874aDaVirxGC0I0j1ySQW2hgHC4peoBfsHtyatOP2iuVpcPVfNPVdmWN2+2rgH7KqHoz9Axuvhr24v4WFy4gra6Hnt1JAuLdVyelkLTnPzCxiRzrEfpZnksB93isAExmoDTLpxzQotBpUDreBynXf0Of7kfrBBjQi0Jdw2I0l04lZyjivoX865MQ== 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)(136003)(39860400002)(451199021)(6486002)(5660300002)(82950400001)(82960400001)(36756003)(478600001)(921005)(10290500003)(38100700002)(66946007)(66556008)(66476007)(8676002)(4326008)(86362001)(41300700001)(786003)(316002)(52116002)(8936002)(2616005)(186003)(6512007)(6506007)(1076003)(2906002)(6666004)(7416002)(83380400001);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: rVbyagShOq2tM/r7e5VeQBmI70EJ8mVhcMBy2quxg2J5NSG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FDyMqZeqXPIObCVV/vMKPFMi0oNRu1bOoDaFkdFt+6gjbJTeKnB3oY8wyCx1SvH/GXEmNLhLemwFXDC2EH1PsT+tK1BFJ0ghVRAvlH1dLMZdlOoYqSrYgto2PDQjyYWCLO3JUzD7s3XpE7u7ZeAnN5K90YLTpN3UJLTYbYU/grGBFVgwYI/ne9w+Ag8dFZMcjI5+jfp06RMtseAy/dgZPaYi7M3pkbjiFptjkZ7Sw3u+nkuHDpgja47h4j+eWslV0UZimv86gtukouNCWtOpyhERpT4EeRaKN+Hk4KFikv09/fKVc2R2oteG9zZKQiij+DOwICdexAhirhrYjpw1fOgsKmiUuSOr9g2OWDKymCgp8AnauMjJYLK1drrv3Zg/6zCa2mrkvGVqSjxjC7y4pm2DPDCq9c5q1cJ+997i2IlMUCdXMW/nXHJHdOdTEP29LbZISPCkzo1IHqEZRG0brOf5dMR+LpAJRimk7YeDDpbtdAO2emU1UZFhC+OGJ1kA8EYnqqC0THv3V+2ydL3MMKors X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: 7c926473-d701-4552-c891-08db34b14d8e X-MS-Exchange-CrossTenant-AuthSource: BL0PR2101MB1092.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Apr 2023 02:07:12.0059 (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: jIX0nLvWYBH+lIMTI2vAE4+kZiiDYmjBIVbKzCJ8k/UU+OzF7CQS+LmNrsB8+BIR+ZI2WPnJXciD03yuKOBxhA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH8PR21MB3959 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Commit 414428c5da1c ("PCI: hv: Lock PCI bus on device eject") added pci_lock_rescan_remove() and pci_unlock_rescan_remove() in create_root_hv_pci_bus() and in hv_eject_device_work() to address the race between create_root_hv_pci_bus() and hv_eject_device_work(), but it turns that grubing the pci_rescan_remove_lock mutex is not enough: refer to the earlier fix "PCI: hv: Add a per-bus mutex state_lock". Now with hbus->state_lock and other fixes, the race is resolved, so remove pci_{lock,unlock}_rescan_remove() in create_root_hv_pci_bus(): this removes the serialization in hv_pci_probe() and hence allows async-probing (PROBE_PREFER_ASYNCHRONOUS) to work. Add the async-probing flag to hv_pci_drv. pci_{lock,unlock}_rescan_remove() in hv_eject_device_work() and in hv_pci_remove() are still kept: according to the comment before drivers/pci/probe.c: static DEFINE_MUTEX(pci_rescan_remove_lock), "PCI device removal routines should always be executed under this mutex". Signed-off-by: Dexuan Cui Cc: stable@vger.kernel.org Reviewed-by: Michael Kelley Reviewed-by: Long Li --- v2: No change to the patch body. Improved the commit message [Michael Kelley] Added Cc:stable 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 3ae2f99dea8c2..2ea2b1b8a4c9a 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)