From patchwork Thu Apr 20 02:40:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dexuan Cui X-Patchwork-Id: 13217756 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 55C5DC77B7E for ; Thu, 20 Apr 2023 02:41:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233411AbjDTCl1 (ORCPT ); Wed, 19 Apr 2023 22:41:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40554 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229687AbjDTClR (ORCPT ); Wed, 19 Apr 2023 22:41:17 -0400 Received: from BN6PR00CU002.outbound.protection.outlook.com (mail-eastus2azon11021022.outbound.protection.outlook.com [52.101.57.22]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 319F319C; Wed, 19 Apr 2023 19:41:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=L2daLkX4jTduVqc1IwwYyh34QzFtZMCxLnSmHOMAzJCovYD79VU4kzcBjXiFusbxVnHpVO9EySNMQhEgP2/5Y4oTp7HWsvfOsdLP0YTLyJVD7halIVHv5JR86I6WUlL/sxKJLpm852aJ5V+0wlHyqi7mPEHkgCoRoc0K0Xf44qRokst/dSIG95kNkbbA5R5V0fUHWWO6oAyykHAFedp6tESD1Oulo8nabxROD4PioAiPQ7L0p2YgJbuUhyLr0eeAS/6Cr904WMmtPGOrf2/zz8QFi/x6kZZc0smN3O23tq5f0uPaej3pQmFYD7oVB6DsjLj6myfXcUdraLRh15EVgQ== 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=S43hd72g4XCuT214Mh2BPkeNAGS1uZ+7A5vBPK/+6qM=; b=dfkk6u/PJPsT7LmDi/ApycGWdvWKlM+yNTy1lfjdDvliCmyWR2XBZy7P3jFQYmdBJ+n2euLmZ0tk4PgepncdF6wT+PKBO1zgumo+J7ac/kkBSa9RebdaESofnEb49JZYIO2+0NqdR1ZCNjfxTsS2wrU4aTn8GdOSkJWuHsi7KxVcnfer2lbPuNfHS8TN8QTyAZIubslVyEeGBKaEJKH/f4JA6RcsXUEuHHxUtxFD4wBkcmGZxxFyAd7bJGYiqEZRXo0ESgTX1vxVPVmH4/HKhIBpT3hStip/KMgizop1TWZ9fUNZgjD1LzQ5eUqiwaoHuG8eaf6fLJzz1HDCz05H/A== 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=S43hd72g4XCuT214Mh2BPkeNAGS1uZ+7A5vBPK/+6qM=; b=jScYm3+Ssf94O83Z71ASzmHn1vrcQk8ufvi9mPUs9G4iS4NV6N9hYYErij8OG+jJSFRoZeXhTcWqVqniOONU/PlgzfD040AVxXOUsKUr+YSRhVvcS3oMilBNSl7dJnwYdddV0MRzaMgjVlbv11Uw9Mtch9x/bQwy+xhzugT4DdA= 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 SJ1PR21MB3411.namprd21.prod.outlook.com (2603:10b6:a03:451::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6340.7; Thu, 20 Apr 2023 02:41:13 +0000 Received: from BL0PR2101MB1092.namprd21.prod.outlook.com ([fe80::932e:24fe:fc1b:5d30]) by BL0PR2101MB1092.namprd21.prod.outlook.com ([fe80::932e:24fe:fc1b:5d30%5]) with mapi id 15.20.6340.009; Thu, 20 Apr 2023 02:41:13 +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, josete@microsoft.com, stable@vger.kernel.org Subject: [PATCH v3 1/6] PCI: hv: Fix a race condition bug in hv_pci_query_relations() Date: Wed, 19 Apr 2023 19:40:32 -0700 Message-Id: <20230420024037.5921-2-decui@microsoft.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230420024037.5921-1-decui@microsoft.com> References: <20230420024037.5921-1-decui@microsoft.com> X-ClientProxiedBy: MW4P221CA0023.NAMP221.PROD.OUTLOOK.COM (2603:10b6:303:8b::28) 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_|SJ1PR21MB3411:EE_ X-MS-Office365-Filtering-Correlation-Id: dafc2c46-7017-48eb-2c97-08db4148b4ee X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: +0hcMB2HLsP11j2ZcWyQDF3Ry0p0B7LTajJ0D1afPGKl52/0TSncNRUMv8/0adCIhoYPQqPe5F+HiBCtEBD5bvW2TG2wwQej8GMH6CtmmXqzjKd2hKGMAg8MusbiXKtioRyr3flGVfCr9eWjWTCJPyDQum0VOhPgH28qyzPPUw7fRebA5AeKWKSzKPZMFLBHObTSmmSk+grxnfHW5cqaQTxH4QifPLGAsioivTslHeOgaJqPxSBBTUSQSRHQQIjkZUsXiBnhj2dC4nW+UZVtElD3U1PveHiAxk1l+oqLBz623d6zyUhml/x8mvNzSQqI7hYrEqWvj8jj0EH6tJ87SqA6gOkZEJOs5CPOMPAuzZCfm2yqK+JDMM3RVWsBcAlqc82SvhLvZaDx3+3Qfr8vkXoCVYth1G/6++cJ+6/P2U8FmResv3QC8h27PjVZv9eEEM3s5GEO0WXkzmJRUSidoeeDWWD5U4qGPofKNoGNQxtHZfJpQcicTdr4MLZlcBHuvAKzcowPbsFTT/Hl5jbbUcSEKMiE6ZaAlCGFz3kDLDNFna/k81/Y7RswGxPfqn8uxGOX5u6KKVlIkVEcLGrM7MFtk6BKDmMLGXf3/S1GdvAkQIIbA+WVwxc4WNEOq8n57gDrso5nK+Eb3Df8hV49LA== 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)(376002)(366004)(39860400002)(346002)(396003)(136003)(451199021)(2616005)(83380400001)(36756003)(186003)(6486002)(6512007)(1076003)(6506007)(6666004)(52116002)(66946007)(66556008)(10290500003)(66476007)(478600001)(4326008)(316002)(41300700001)(82950400001)(82960400001)(921005)(786003)(8676002)(8936002)(38100700002)(5660300002)(7416002)(86362001)(2906002);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-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t/BtxSzP2zZ/8p/1NCxjvTFsIOayh//IX31ycugdXhnQSLOB4IFQ1kOD2TubhEsBQtp6S81Wgh+VSDKtiHp6JqTWuwB0yZTaOAOum0246I4oEkjJDNzOF9bYBv7SvXF8afCj+4ef6oZz27TLM1Jx33lYhMc9e6IGYw3HFWiQXvBRlT5oYbsEGdh/zi8o42h7Crm0qkk0Jpr29pcKycct7HhZSnaaSQz+9Z2SfEnIJv/cN2oGVerXS3DH9zx/dn1GlvhNeesvciU7amX5apodvksCX0GElxtvlTNvpc/Za8sGIT0I7+hGRjLAFx6Aqecx7F3FGdbgSdDn39bgTRD8Tyha31GMCs+b7hSuvd/+ddjNKzC+2ti1QyxwR7w2XYLKzEL33N9e68dn1+4DPy5UCEdWQnKGV8LwCcXNGyRkZyn/ffr1G4yS52qZ7PFqKnweb2hm32HRkMyPBUtmSiH4Brf0j04ILrgUhwt9oopt1lbeaYm9JYuRtMxDcEaeYIBUCWwrMs0w8m1xh8ixEH4xNCMIAsZFj/R8nFwiZDrtRwox/KWr4j2Y1SnR5nradL6/O4ZUp/GR++W/Z65J+e5MoWk8ZBC0YB X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: dafc2c46-7017-48eb-2c97-08db4148b4ee X-MS-Exchange-CrossTenant-AuthSource: BL0PR2101MB1092.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Apr 2023 02:41:13.3714 (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: zEOO7tZbhVX6C6y5rbq0qRjFUAJ6KMBEyI9LNMGeZwz0A0QFeA6MnXScX5FEugzuF+l6460CxqIVs/+gVJfZxA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ1PR21MB3411 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 Reviewed-by: Michael Kelley Cc: stable@vger.kernel.org Acked-by: Lorenzo Pieralisi --- v2: Removed the "debug code". No change to the patch body. Added Cc:stable v3: Added Michael's Reviewed-by. 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 Thu Apr 20 02:40:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dexuan Cui X-Patchwork-Id: 13217757 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 ADB66C7EE21 for ; Thu, 20 Apr 2023 02:41:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232659AbjDTCl3 (ORCPT ); Wed, 19 Apr 2023 22:41:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40630 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232635AbjDTClU (ORCPT ); Wed, 19 Apr 2023 22:41:20 -0400 Received: from BN6PR00CU002.outbound.protection.outlook.com (mail-eastus2azon11021022.outbound.protection.outlook.com [52.101.57.22]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3DE0B4EC3; Wed, 19 Apr 2023 19:41:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=BUbcBBXLRNeEPVdzKSBSCFkNfUpnVk0ElvPvR33vQ4IjSX/R+AjOL2SLSEIx54nIqzeHTFBXwm4dQ9MmA82Pi96nhmXQpvLxHbP1RV2lQ2UGdHNhEwASv7lYGPJrvx74Fl8RxEFVLzv5eC/IjhhxStjmPVtKV9FTmTkh1hoa+lJSzZ83uvD8rojBh6GXiLsl4pwwW+v5RtmSFA6nLcrVYvXpHGHO55RTRV+MMnBNO0kUu6dD6SLsr+w+xG9gVVVtMmo+Goby7EEn70s+0RFGrgdQ+9vdiLeft0H5qk49n+cXzGWDI/0SXnO5xKEl6Ie7WxhdBVRnEzK1cgw9Umz+Ng== 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=2qOPAMkZr4rtwbzpMhwxs/4UwiZWmjvSHb4CdQwyqS4=; b=Bs1ienACzmoC2iMN6Td3bJPaVdG8uLYMIyEmEN9Px2Rg+3CXz5p7T3vws+T2ZUpctNuP22Vkze3Q/WkkZNh+SGEmnmcloJQy+1+iHvyATlbl9KcPKFZ9Aoc/7MVGlbwoyadFq8btFvx234bVOC/7jzqYpZgOu6qzfJ7qvtZQ8D0+pY3tFGtQpLPEhOQgY6bK5H+9XhuVGmlspfNBAXi9CmcIRZoAZrK2JJJefzswUr5pruhKLkwcYkQb3Zx2i8mreTdkYeWPaLxyNLKmVn8p5VRDVRg1FYGFuyLo3btp/LH2FJ+5MtuzbC33r8MeLnwg+EGULbRiSdT9g2RjQN9rpw== 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=2qOPAMkZr4rtwbzpMhwxs/4UwiZWmjvSHb4CdQwyqS4=; b=YCp7H84zJYOSe+J+80R2hVaJMuB0XGL2ohnnPz59CT887Ij3ugTKgdJqsRGcFmt8vLTAzXWu2yPDxo7Ccp9h7d4K1xYYzG6pmCqI4CqBgGWWoX4UaKQGz1LZlO9OAGZNmv4n57HqQCgYig34Fh1tz6dkrBXs/zrtKGhES1dn+1E= 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 SJ1PR21MB3411.namprd21.prod.outlook.com (2603:10b6:a03:451::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6340.7; Thu, 20 Apr 2023 02:41:15 +0000 Received: from BL0PR2101MB1092.namprd21.prod.outlook.com ([fe80::932e:24fe:fc1b:5d30]) by BL0PR2101MB1092.namprd21.prod.outlook.com ([fe80::932e:24fe:fc1b:5d30%5]) with mapi id 15.20.6340.009; Thu, 20 Apr 2023 02:41: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, 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, josete@microsoft.com, stable@vger.kernel.org Subject: [PATCH v3 2/6] PCI: hv: Fix a race condition in hv_irq_unmask() that can cause panic Date: Wed, 19 Apr 2023 19:40:33 -0700 Message-Id: <20230420024037.5921-3-decui@microsoft.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230420024037.5921-1-decui@microsoft.com> References: <20230420024037.5921-1-decui@microsoft.com> X-ClientProxiedBy: MW4P221CA0023.NAMP221.PROD.OUTLOOK.COM (2603:10b6:303:8b::28) 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_|SJ1PR21MB3411:EE_ X-MS-Office365-Filtering-Correlation-Id: 71268da5-6bac-45dc-9f31-08db4148b64c X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 43AG5Ny/u0MFFsrA1XyCJrvbol9uB6YB5da7vVzZ7+/EeDgoOruyoFDOhLS8BK19IdoQpUyF2T6zJPYdAYiFL9r1qXKCKDZplUrwy/R79TW2cfWE3oSKrV6v+LQENEIwbETvv5K0FO9vQfHqvWncCZk7zh6QwloRCnCBXAPgIvpHMjXfpmAYgDdK0/bj0PWif8HVGpyuDeaNam971tFK8fAN96fYS74mFk7n2evsGfuKt1T7AqJnf6mbAgDrYG4hLUqB741n4u0R7oGvYnDFqerdLJWCFKj9I0ecZqKY9b9tWQDVFIbQOPtEPXRdgSx9S+0r6OQpuonlU8S0LCUGQ59AgZ8CVRJqHN4Cblr/U1J265wtYytAhX8tPOdKJsLtvCqHvirMsaWQbE6Q2cGxCA9FQDn2gJCV4WO2Fes7pU9hTnZfGuTQjTf2OR4PsKLhvP7qhV+QpgxLSa0L79rVZhKVg6v8t72N6JIsA6rcu1a14MibO106v3ponTmGEQowo/xKGp4XiqyES37PYPN+GRF9UuSqBIPaSUZTjSOq2PZSeu3/PPP0hsW3+UuCAymJWCqEfuX6hXrd06bLMmCa2SDdAbSTMOpomdyHWIc6FpC+MXFgI2gVhoOBAxLU+L+4BI4rLHlShef2BnTNKWGUyA== 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)(376002)(366004)(39860400002)(346002)(396003)(136003)(451199021)(2616005)(83380400001)(36756003)(186003)(6486002)(6512007)(1076003)(6506007)(6666004)(52116002)(66946007)(66556008)(10290500003)(66476007)(478600001)(4326008)(316002)(41300700001)(82950400001)(82960400001)(921005)(786003)(8676002)(8936002)(38100700002)(5660300002)(66899021)(7416002)(86362001)(2906002);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: lBt1pE3KS2VxTaHw6c201QQnmwupheTd9rqzb2x8XtyC90SVMq+AdwjA38v0SPyA7mVSZ5tuUAcvZVDqvqnofN7rObWk/ZoYDee9Ly4EP3lQgUkqOMwGbd50K/QGD2GWObmvdDXlPzoteASvgDAlVIQou/9Ax/naI/kAti9P9eeMvr3T9RIxYhiB5G2t4AOFW0YBusRhHHUC4DSUk1hoLoN81n+0Gl3VBGD0e3JV7WJFBSq4BQ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uNPjzQt7bUGOObShUFwI7lDNMW3ArSJHJk3LSC/PY3rTEB7mX8ubStHAl+yBXqSge0wAnuQZTsNhOGqwrEj0p/A5XApA1ZxNWVa29c75ko+EZJL+Bfz11xlYXOHAC0X5/HEqs1BrQkfYDsUs8st2upzNoQleA05gS4HFErckNwj37Tuwe+a9xx45+ioT3LYHcbEApUzN/INnpUbO9oFzZriTReXiM2pX/LxK24LIsrL1bCUReM19iGkaTj8Nkc/xV1RJ25VIDm42sDTVwmrZxCgEcZvl5Yf9oo4ZgwuP9Kqgj3Y5VVhlQFQESxguq1q6vUsy X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: 71268da5-6bac-45dc-9f31-08db4148b64c X-MS-Exchange-CrossTenant-AuthSource: BL0PR2101MB1092.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Apr 2023 02:41:15.6669 (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: TGWNROkJbnTnvhIBSWLgt5JRkvhGsMv+p/wf5EVUTTBCunDB6zneh2hm9PfFpkP7Qywn+r5x+f/1tb6oOPlcPw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ1PR21MB3411 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 Reviewed-by: Michael Kelley Cc: stable@vger.kernel.org --- v2: Removed the "debug code". No change to the patch body. Added Cc:stable v3: Added Michael's Reviewed-by. 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 Thu Apr 20 02:40:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dexuan Cui X-Patchwork-Id: 13217758 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 06BF5C6FD18 for ; Thu, 20 Apr 2023 02:41:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233605AbjDTClh (ORCPT ); Wed, 19 Apr 2023 22:41:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40864 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233337AbjDTCl0 (ORCPT ); Wed, 19 Apr 2023 22:41:26 -0400 Received: from BN6PR00CU002.outbound.protection.outlook.com (mail-eastus2azon11021022.outbound.protection.outlook.com [52.101.57.22]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 53D20F9; Wed, 19 Apr 2023 19:41:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=UHiHC33NZ8SCDytbIc2iOt1SPbdXOVV/raxFFfCGxFmaEG08MNV9T56BaQFpcIsMJIFfQkWy3gpHFGfagb4B+nMOROzT8EiENJ2+jxbuISi52F2elc4xrYBZLhQad2OIy/Ap0008JkFpy89v63x5Xv/p6KesdCw8hducj3RRbVbceohRlOG0Q2ZL2lWV8lbdSyVKDWVLUPOY0mNNWyjD1XgBtuJOySDJqjME8zQ5wHWIC3kLUL+UZo9gACI71Avke+lAeZg3A/gm8M4IL2a2SRNJ5J8FOIzCwULXzU/UjRF/Yw+Mk8F9NA7W3Shp80nzkysm8vF4vuHvtMBgRmRHjQ== 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=YOtyolTiZvROuvCdIoKLhmvPeieVpPdw+Netk63t3oY=; b=m3Ey96bCfnb7AuauFZYG9pBnKwrFXNik8lxBlY9t6oJdpY6W3iDhSMaQA7cMOZEPdJsuJ33VV6h3lPkdFy/+b3ObEzpU88Tb/FLosulftsjEjJeN5DxK9UesRsBai99z5/mehnbg5UFT0TZucWf6ywPtkNTlL7hKJEQLIqNNosQcmgGSsb9Qz82t3qYjpUufNyq5/ti7MinkB42xq18u82xt4u55gaOt5aRcXtXcnrz5aqV2xo1ySXVoZ1Yyr7TcVGdzz1Yx2ePAM8WHp2LTCLRKs4fz7vMnxn7blfUjBrleBSyxdFh5HVkuqBWsZL+szA8M7MLvLYqyN5MFzga4MQ== 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=YOtyolTiZvROuvCdIoKLhmvPeieVpPdw+Netk63t3oY=; b=I3KjXOVh/IvRg+D2UOAtaFT9zMoW1l6IM9mnDmNUMyTn/nEe81YVaOCldz7/g8uzeYbk1n1Crg0P29cU4/+99ZgNAN3Adl0dqmNbtVCHnxxXbyc5NNS1aJv7yic2XEP6zfyvA86sbUMqKYZ/dWjj2tcl5jXDmHQ5+/qHX8tvkF8= 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 SJ1PR21MB3411.namprd21.prod.outlook.com (2603:10b6:a03:451::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6340.7; Thu, 20 Apr 2023 02:41:18 +0000 Received: from BL0PR2101MB1092.namprd21.prod.outlook.com ([fe80::932e:24fe:fc1b:5d30]) by BL0PR2101MB1092.namprd21.prod.outlook.com ([fe80::932e:24fe:fc1b:5d30%5]) with mapi id 15.20.6340.009; Thu, 20 Apr 2023 02:41:18 +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, josete@microsoft.com, stable@vger.kernel.org Subject: [PATCH v3 3/6] PCI: hv: Remove the useless hv_pcichild_state from struct hv_pci_dev Date: Wed, 19 Apr 2023 19:40:34 -0700 Message-Id: <20230420024037.5921-4-decui@microsoft.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230420024037.5921-1-decui@microsoft.com> References: <20230420024037.5921-1-decui@microsoft.com> X-ClientProxiedBy: MW4P221CA0023.NAMP221.PROD.OUTLOOK.COM (2603:10b6:303:8b::28) 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_|SJ1PR21MB3411:EE_ X-MS-Office365-Filtering-Correlation-Id: 91b09d1b-1ac5-463e-11dd-08db4148b7ab X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Eyr6mY8JQYRf5mx1rADNVbeoyggPjkDBhx5s9qTNkgiCjODNTCrgwEJA8fXt9jew8A5whM+zH2wrZhaVl0KtI0/smoq57msT2I5A/odx7vRsLOwKkDGAz/oGyXCMBRtu4vhsgsMP0qbl8W6+CZ0hAQO1bK0HQmnv7IngcjS5LzqP3aHCr0zLg/XZMiUBxSvuw27Ykycq9Pm46S41V05ajEXt9X1CH6D5RHC8lj3KcxvNjaOjeDhkbTGR+Use7lORdoRQ+a65Fao/ZLLkNGobfnBf6WFIhhWn6e9vG+ikPL6ZFNkDGXTok1CDmcxYd3t/FAxILpd3TKnsVLPXmlzNuk/r5y5yUp6CuT450ewMqvDjf74mMubvVqzmbUjOpFxD/cidvsayaYG6SsYbum+TKwBB5gOYAf1WDXtSVrYYQeddkHIIv3IrA3AWWcgWOWnuOtiDY3GcTqDIunkKReJNZlwTR/+Ew2P3bWgf0WI2oa3o6oLT+pbA9tAbjHU6yQzpLfwozX0fj816lSIYpMp7QsuHcEClki1jW4Osvr30Bg5GU8wW0pQxtxPHPKJ0GtA46vvOFM/XhsI9qKFMA2mHso/eqjGil7R0BQF+4AcB90JYi/X1GxEgikBPdj2kr//giP+KjdiDgRmmFr3UNzq3+w== 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)(376002)(366004)(39860400002)(346002)(396003)(136003)(451199021)(2616005)(83380400001)(36756003)(186003)(6486002)(6512007)(1076003)(6506007)(6666004)(52116002)(66946007)(66556008)(10290500003)(66476007)(478600001)(4326008)(316002)(41300700001)(82950400001)(82960400001)(921005)(786003)(8676002)(8936002)(38100700002)(5660300002)(7416002)(86362001)(2906002);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-M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1LEHGNDNqWhKTy/013tCD/sJ/m2WMYnVgHwVPu856bI3/KBAC8m3m7SODUFnbElWCe94MsgnuADHLwBzcbyQ7OBJniOc2AikqKkM67K198+nRiN/j27A3ViQMEnsAwb8bYXA5baB0GjH3fMabIHrkXkEXuy03avl4HjzNgQG3EIUcADSqLkEVcMdRogYoLcuisOioViLSJiLQN+GejvNXw9vBvn1qTZplHzcOuqx5PYPswm/xhYYU64uR96xhCX8PMMN/0QILMkY947UfLKfKWIOak3XTrVdAxOVsFLjYpoya/LuWa47VOv3tOS0Bwef/imVKLGbrVbBkJamw+sAyVlyvF1nDRoHmVB6hIfBWrbbX7YOP/VY+aZRXCGb5M1JthRobIxUypjNIsgmMhzd2RPXdo/TsV+MHUNrom4VHWVxAACV3ce7nqoH5iVMIjZTh7QxqrWVsuChNn9TN/wJb5pqvDEFhlXChcyv+pvxnRLxxTZXGA0+15O4iIxCxTlGQQLKRJiV/bRsUula+/uyGxWz5xzUgnmN1F+0aRv8RMft0FVK9gX2w7d40DM+5w95aLh9HbvD1hRSIOSQlBgJK41A1+cMNEm8mC8BuwnRGidB X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: 91b09d1b-1ac5-463e-11dd-08db4148b7ab X-MS-Exchange-CrossTenant-AuthSource: BL0PR2101MB1092.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Apr 2023 02:41:17.9618 (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: SaNPadS+rcD5r+A7+LD3xJFeF5ThoGGWoNv7TE2tebY4WjJWqjNlZ4c5ybitKeFpgIar4L/wtAg7DvMiginEhQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ1PR21MB3411 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 Reviewed-by: Michael Kelley Cc: stable@vger.kernel.org Acked-by: Lorenzo Pieralisi --- v2: No change to the patch body. Added Cc:stable v3: Added Michael's Reviewed-by. 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 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 Thu Apr 20 02:40:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dexuan Cui X-Patchwork-Id: 13217759 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 46B53C77B75 for ; Thu, 20 Apr 2023 02:41:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233658AbjDTClq (ORCPT ); Wed, 19 Apr 2023 22:41:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40908 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233507AbjDTCl2 (ORCPT ); Wed, 19 Apr 2023 22:41:28 -0400 Received: from BN6PR00CU002.outbound.protection.outlook.com (mail-eastus2azon11021015.outbound.protection.outlook.com [52.101.57.15]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2DEF81AB; Wed, 19 Apr 2023 19:41:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=dsZc7gw1AHgIWAzLEbQkxObgkWzgUSRJQMrZ2hMbcChSxC0wHAjXQgbvcJMqEdUUAW40pP5SQ93JnS0fpjpG0tnismK4Lt5xwMUxsHG9SRe6wOu9F4krp6RfcSTuV/9Wen905K6j7z1FQwP02f2rJ7lGGxLLcezjLEU+Zk4I6F3KQD/L5mwP9MgZmikJKohpR2CRSs7fBqnXpLROb5K6zWbv0efBbSeA955CcjSzNZQq2oPPkubZhn9+tSy3D7qqHKvlvx9I5Bh+OCiefs27R1/foPZG3hsnaHAmDpORvLgTcmhLIjj4JL8m1odcD3+dcQOhxxFUfWUNd0efRZRfHg== 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=3prjjBiDMNJjNVQK4bImxHlXF9B4TpfNKM7lAedvycY=; b=d57+zW/Hj/LPYi4w8LvbBj9w0xSbf8bV8pZ+26t0UGJcJO9ftSIUZs6kNQpZjYMDxkwq6x/bzSmeuXSYFqOAxYJByLVXXOokzyw96udcicxGbmSdBgz3wLk+pK5lRQ2cgiKQQ9FmJaVZwteQaXInmbXqZCCsDuLdg3kA056IVBmGI7crv0/cVnF/zVpZTK3h6cp5jXxSxH9bMrv+ZjfCirSnTEv+Cj4VBcOGuewaJ2F+Xhxf1a1j5/ePPuzfUKpIXsSoSA2lns7IY7Z11Mj95NWpkHvMA/CDSLa81uvc23siAeGdfXSKpkRnSAlFxvT1X7uibiOi9e9fX+1Jmv5vvw== 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=3prjjBiDMNJjNVQK4bImxHlXF9B4TpfNKM7lAedvycY=; b=BCXlCBWiPedKFtPNeKs3iNmRt9NraVZpOeNS1wAEZqpSGpp3wpfMbdcED4rhhJvO5rswJNoE6dkRGixYRWhKbTgpTdxng2j1xBvPnXiIsTEwWJid8nHAyG7dBw6qqoWAaNqtXJZz5nMINDPRGF2vvytwXQ3+CoSXtDk4Q8pBH6A= 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 SJ1PR21MB3411.namprd21.prod.outlook.com (2603:10b6:a03:451::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6340.7; Thu, 20 Apr 2023 02:41:20 +0000 Received: from BL0PR2101MB1092.namprd21.prod.outlook.com ([fe80::932e:24fe:fc1b:5d30]) by BL0PR2101MB1092.namprd21.prod.outlook.com ([fe80::932e:24fe:fc1b:5d30%5]) with mapi id 15.20.6340.009; Thu, 20 Apr 2023 02:41:20 +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, josete@microsoft.com, stable@vger.kernel.org Subject: [PATCH v3 4/6] Revert "PCI: hv: Fix a timing issue which causes kdump to fail occasionally" Date: Wed, 19 Apr 2023 19:40:35 -0700 Message-Id: <20230420024037.5921-5-decui@microsoft.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230420024037.5921-1-decui@microsoft.com> References: <20230420024037.5921-1-decui@microsoft.com> X-ClientProxiedBy: MW4P221CA0023.NAMP221.PROD.OUTLOOK.COM (2603:10b6:303:8b::28) 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_|SJ1PR21MB3411:EE_ X-MS-Office365-Filtering-Correlation-Id: 4e5dc93c-57fc-4f73-847c-08db4148b909 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: jq0ghVO0abZWhGzT1O4GiqfE6Wbvw1Jr2I9DDqKdJbYlD1MLRvF60Jnztwn8+TNUgV5i8b7G1YMuYmhlsIy4paY7TDMAawaBdLQjDUivL1cs2DoZHppADS3Y2rh7LwvYDOc2DP4roGhPwZpf+6WUq1rSTSC+dZdvUHRzQTPuZ5CvRtzYj+XIbizVJkPZOBl3WtsKphyH+hRE1uZdGyDvtmby4P7XBWKk1YCZSbe4VgBBqNOz1hSz8C7TM/v0EJoAL3GPiNX8d3x+/ZzcahZwwwmXEsYj2DMancJTaV3LqzEG1bojHTV6iA3YWmFcnaNlG8QcPT01Twy64vQoDjDdJAbS4vU6YJ/310up5zgFqCxreao0leM1J+vY+3utqKdxAScVoSxSQ3Xr8plVYTllHq+hpxv1tVdPwacnTG4xGEZ132NkITfU62zP8wfMxg00kcbuisqJdJuMHGu0tnbkEFtXZkqc1OMWammlALZ9ZJxnTrFyf7Rjxxlhd2CgZVUidsK3Fev9NoLHch6jJeG+Jwimky4GPWkUef7SgX27o4g+0dUsFdOb3A3o+M4DGWRwwM7FUN+PZ5nt3Vh6C26L1kU7iqCgwrSSXImSrQvqnrQZRi3ta+/953+inbKfcxfpaiSn2fzbK025qjZRgPa+GA== 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)(376002)(366004)(39860400002)(346002)(396003)(136003)(451199021)(2616005)(83380400001)(36756003)(186003)(6486002)(6512007)(1076003)(6506007)(6666004)(52116002)(66946007)(66556008)(10290500003)(66476007)(478600001)(4326008)(316002)(41300700001)(82950400001)(82960400001)(921005)(786003)(8676002)(8936002)(38100700002)(5660300002)(7416002)(86362001)(2906002);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: +ek2q8OfZ+O0tMV41bWwWhzW71JlZsa+3geawA5sqpqSeqw8pqAbS7ZOq0vwxqeSAhPAP7oe+EiZWx5NZhP394n6GYBq8LkDDYTn3WPy+TU9z2j1mYABXtXFKh+PzbDuFyl6qkXrPTKjxozrKbKpU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cghQIDJzvZDN7rCqlrBlrCauOZ05TqQf/uIcCJKn9LTf9kIjJO1J2KJDsLFlScSavx3fMdiMt5oOeRQDu3mUFrzuvBuIAS3upaMJld0id9AG6cH7NfhZdCITG9Eb5THxtxgH/48tWGoqcn39FkmhsU5cL7xRCQRtc1KC6Q4AYug9NOp3v/aWof0QAyNkJTW9iQ40VT0/YkSjpsefiKUXrl8n/3f9eDO5wXHRs7dqPV/FT2FuiADxiVp7Bl+usMUQaPpTFU1F+hRoLsX9ifh9oF2IfATC7/y1QnayW5WWYulpw4HxwWKxwuROHcnuuTevPpt7AToksfW+GyT3ryEIysOx0r0/KsXnRVchhKP27WxF9GpSG4vjHnZpBrbg5xCVG72QRJKM9wMmyHO2XQAlpn5022iOWokz67x5fjd/bVlN5PQewt X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4e5dc93c-57fc-4f73-847c-08db4148b909 X-MS-Exchange-CrossTenant-AuthSource: BL0PR2101MB1092.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Apr 2023 02:41:20.2521 (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: kXlWjZIjS8O9VIO7fLtuMLmUA5pUOos3rga+sC7WoO+dgZoofdBfEoN0CfA+VdsTQf45JTUHN0eav4vDUpt73A== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ1PR21MB3411 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 Reviewed-by: Michael Kelley Acked-by: Wei Hu Cc: stable@vger.kernel.org --- v2: No change to the patch body. Added Wei Hu's Acked-by. Added Cc:stable v3: Added Michael's Reviewed-by. 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 Thu Apr 20 02:40:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dexuan Cui X-Patchwork-Id: 13217760 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 180D3C77B7F for ; Thu, 20 Apr 2023 02:42:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233742AbjDTCmG (ORCPT ); Wed, 19 Apr 2023 22:42:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41184 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233384AbjDTCld (ORCPT ); Wed, 19 Apr 2023 22:41:33 -0400 Received: from BN6PR00CU002.outbound.protection.outlook.com (mail-eastus2azon11021015.outbound.protection.outlook.com [52.101.57.15]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 87E9DF2; Wed, 19 Apr 2023 19:41:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ckBzDoXDETXXMoBKglLjULIGhFmSnzRM6lgS+Ju+okqGxKmZq7BYZKA62Y05AMmS48+ekazSmAr15/Xpucstk1cmiYgpLggM/T+OiOBcZMQ55Y5A1PNdAa4utJyDXYB73GjEsKDFWhzpYOF0lq/o5u2gl5z2vQ1ORcnV9Bg1jM5UoAJIMKuq8MBF8dvyrJ8qWlTLVlHVI4FibeRJaeQTQCUSVjkk6D9kzGsTtVt98bwxPouX5kWCWxkeG69B7VTpMXv+BJSTKRV0wrXZg6AuFyTubYwZsTUY4sSEpK2weQ7C8+ndTFbowBFNvcG8uofizTtNrhMxM4B4REHCMV6jxg== 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=MPrGWX8hfKz4SMbhlNl5Ey3zRmEQqqIy5YShwVJTCAk=; b=hmJSGunmKVeftBZY7r+hhg3GwohbOWr04243r4iNm68kbB1k6kGBvzV+P1SwjSWjVg4USRT4rU5j1icGxaxDPXSj6KhpYlPekxMHhUqxlzIXFVruIPwMPjab/+kgjg7qaaNIkbIYKHLxwhZrOt7ZTaUoGM3kpR8c9Qr3u6Bby9pGbnEFVcagML7/vOg43eJdqhJXFqb3mtNm9EdWfQj9dDaiOiZ9LOAqhrBqSg3L9Revj3rzMFZut6WZjGwlsrB9pxlMWSmQysmaOyv1ecs/CYyTnJ9cNolL8lspmMHmqIFMy7gl84ejOu+hkTubZhwLjVnF9uodA7o4bpRp1HiDdQ== 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=MPrGWX8hfKz4SMbhlNl5Ey3zRmEQqqIy5YShwVJTCAk=; b=KwnGayZHSxkd9VsCxW6HcVcJbKH3pNNW+2+nzPrfhTjnQ1FmAO8PzTmQl3+eitYEKUF/3781wNZ0c11san+3fnd6SF7SXk6BNR6eSH0hiSoq3aqbdz/BQuQyHm79QhAwGu4BRPgKP7VAEWkkbvp1zAC7P9zVZYz0UPE2nQnHopg= 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 SJ1PR21MB3411.namprd21.prod.outlook.com (2603:10b6:a03:451::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6340.7; Thu, 20 Apr 2023 02:41:22 +0000 Received: from BL0PR2101MB1092.namprd21.prod.outlook.com ([fe80::932e:24fe:fc1b:5d30]) by BL0PR2101MB1092.namprd21.prod.outlook.com ([fe80::932e:24fe:fc1b:5d30%5]) with mapi id 15.20.6340.009; Thu, 20 Apr 2023 02:41:22 +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, josete@microsoft.com, stable@vger.kernel.org Subject: [PATCH v3 5/6] PCI: hv: Add a per-bus mutex state_lock Date: Wed, 19 Apr 2023 19:40:36 -0700 Message-Id: <20230420024037.5921-6-decui@microsoft.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230420024037.5921-1-decui@microsoft.com> References: <20230420024037.5921-1-decui@microsoft.com> X-ClientProxiedBy: MW4P221CA0023.NAMP221.PROD.OUTLOOK.COM (2603:10b6:303:8b::28) 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_|SJ1PR21MB3411:EE_ X-MS-Office365-Filtering-Correlation-Id: 7f688bc2-30d8-4e33-8055-08db4148ba71 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: qzqDAnwa4IeEpcur8vOHPH+2bGepNYekO0wDF1YBAnKtJTnva4PDY6ciPnUHb0hKYFi17tWJEuQQGXj4kzNpyeIGILgwcB2C4kT9oaAuvozZ/f2ZDw1ELav5E/Rgw4mafpb4GK/aGTvxItMdptZZnr2p1kJOfDXnYDZP3h55+CbBDMEiC7jwxFuIkAKHNnmJR9z8QqJazXMhet7+YNkPRxxSVf1rnWEm/RegmvwKbX3VZwAt6wyr7e1ZIrcfZe+2aSI00n+j+croq2GNmCwLoK4IcOeIXmVR4rrY5wnNZSdmjyzmA/t11Zius5Vjv8YrKLRQW4/slxyOHLPqnglKjV4NvsJGi6FrtRro90VRPzbtti+004y1ccPNv95lzn8u/D/U3Dk/cqtkLO9hlo9wcMPVZxyNC2X7RNZm8ePSv47BADvG8ikJtibOGu/SqbqM/nuy36H1mZ/ez3stHN6sN6qF2zFCFLRb94BJSjnXVAYMQWiI0Fq9XLmE6eXmvltd8N8fWtV3iFM92AasyfyUNgQW2hYYAVtOWZWAlMZsR2wgsiELP0w5XdU/mCYoV06wX0W9welwH8SRY6DcL3c1UQJtRhhZ++VWAoNsv+ynYhQd79dGnJoboFgZGvYNPxYmLWa4uVuY/mu7hsvonZylZw== 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)(376002)(366004)(39860400002)(346002)(396003)(136003)(451199021)(2616005)(83380400001)(36756003)(186003)(6486002)(6512007)(1076003)(6506007)(6666004)(52116002)(66946007)(66556008)(10290500003)(66476007)(478600001)(4326008)(316002)(41300700001)(82950400001)(82960400001)(921005)(786003)(8676002)(8936002)(38100700002)(5660300002)(7416002)(86362001)(2906002);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: iRT1vzRRNGUvZPfmkl8JlQxzEwEYitgStTFzHXAQhWxG9nq0gw7LHIsg6uLQ0bj0PYUmKd8t8RHnFlZ4RnlUU2NHzkoJRO92U7mmb02vIT9yIqdn6zOjO3eiZANH3QVM3AkkudN/u6PqYUqpNAEKH2D5Wd6zWGoE7C6kSlLxFuKgYPW3OeOsVp3pDAzQQ0EkpeyI6bZLk1OqGURVlANVtqHrTe5fCRLL6Q0gvobqJOarUHa+Y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eWQL4kUCTfNnxQ5ZSI8XEpnrTyIKAScIJDKlwDA5Uex4EtDWp6Qz59k0VIJd1DkNqoUsS+bwP34FJZzAilH4j5BtQJKxNfDhGFZDA+jVdcH6M9HjpxmxPgCek/Gnys1IywUZXVeRybCxZZZ0iBGBXtzRdk79mtEokDRS5pA5txdwllWHONSYX31D/sQ9RZraCUdGeX9oucyHtbD0cbJBBmBmZVnJ879Qz3JJl9R+Y6OZlfsYwMJmQqZx0Bgvx2th7t4BQvxJN77xsP7jZ3B9ACCleFPt/s92cDSCENWGRmTqY8HqrRnZNbcX1RKOKuSVtI70CDLbIN9wR9ELiS+lc/6Y8cNCgZqyqAZOi2ME X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: 7f688bc2-30d8-4e33-8055-08db4148ba71 X-MS-Exchange-CrossTenant-AuthSource: BL0PR2101MB1092.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Apr 2023 02:41:22.6300 (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: 2MKZy7yplie3QwkYdBy3LSJ1ALN5r0U6A0MYGeR/wH3bg6PZNEKO1z8yCW76TMrz4/hFai+fwmolc80iUax2nQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ1PR21MB3411 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 Reviewed-by: Michael Kelley Cc: stable@vger.kernel.org Acked-by: Lorenzo Pieralisi --- v2: Removed the "debug code". Fixed the "goto out" in hv_pci_resume() [Michael Kelley] Added Cc:stable v3: Added Michael's Reviewed-by. 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 Thu Apr 20 02:40:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dexuan Cui X-Patchwork-Id: 13217761 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 8BBF0C77B7C for ; Thu, 20 Apr 2023 02:42:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233813AbjDTCmn (ORCPT ); Wed, 19 Apr 2023 22:42:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41846 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233733AbjDTCmG (ORCPT ); Wed, 19 Apr 2023 22:42:06 -0400 Received: from BN6PR00CU002.outbound.protection.outlook.com (mail-eastus2azon11021015.outbound.protection.outlook.com [52.101.57.15]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2FACB7287; Wed, 19 Apr 2023 19:41:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=QkQLkawleUzKWLOOviEKp+uxsNUxnT63zMmNdcyS9JMQJAN0AE9hokJqb8FbJyUzAJ4bk0KPUj4UPM70q0mBCRcCy8GoSm7v9/6qEtdsHydsfNb6Mypc0aCNuuz4H5oDxGAvIwMVlhmEq1oVfuLnSwreluHEO5lVqkHJW6YeUz/ShjFM3aWz91uPlGM3iFaALqQAA63F+g9Wv+tZ6p8jXnB+2mf0X0uHKceebeWVYeVntlI6/dCA/OWb5BxbfT7YZkCULn6ehMr1qejX0F7ckrlrYtmd0c7RC5CfnDiB34ph02wj7EW64wceWXlAtbYGQeqVGNk81xjGaRyW25jsOg== 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=4iyhmWuJbQEfT/SmVjDTEIzOqUYQjNjzxVBbj5zIUhE=; b=Mchm+jpd6lUmHC3+qlc3qz/5LSm5K2XDaf6XF5o8GNiQnPsq3Lseo3x1D1HJLnpIkeKOMqYXtjwVdPj42eiVuy3z3U8h4xalKtVlTzfWypoyiuoJ89h8JOmHwT+SJ+Q0THucXcH7hNlLFrUTM+x2PSP2UMOaix7BRAt4iDMyd9Ou7meBlSHmYl9D3qhQJNBXWo/aq9VG+ACzt+0J+i/hnhb4SCv0NUoDuO3rRy2OhvmqJWegaF8f7t0TnfQibN3rhnIVOk14AnoJE3zju0RVH4iaAZm2fkKyDYwD4Lcf48mHa/+gxyUgWTV0F+R2RwrLY6TWH3LWjmYmvPqJX4Fzdw== 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=4iyhmWuJbQEfT/SmVjDTEIzOqUYQjNjzxVBbj5zIUhE=; b=gs1Z2d1sJehkNsdRg6CIkD76FkNuzQV5bOhiruhhskmIM2d6EfSQ2068r4e9RWHHmJlBFE/4TdwF90mwhAeS9GD1qNP3DatNoh/0RAW05wfHIBSH+Pvd2fPQyZ6IXYhAWwP5+9DQNEwgc2b85fUu2Asch4xf3gGYZQkG8oFAEmA= 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 SJ1PR21MB3411.namprd21.prod.outlook.com (2603:10b6:a03:451::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6340.7; Thu, 20 Apr 2023 02:41:25 +0000 Received: from BL0PR2101MB1092.namprd21.prod.outlook.com ([fe80::932e:24fe:fc1b:5d30]) by BL0PR2101MB1092.namprd21.prod.outlook.com ([fe80::932e:24fe:fc1b:5d30%5]) with mapi id 15.20.6340.009; Thu, 20 Apr 2023 02:41:25 +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, josete@microsoft.com, stable@vger.kernel.org Subject: [PATCH v3 6/6] PCI: hv: Use async probing to reduce boot time Date: Wed, 19 Apr 2023 19:40:37 -0700 Message-Id: <20230420024037.5921-7-decui@microsoft.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230420024037.5921-1-decui@microsoft.com> References: <20230420024037.5921-1-decui@microsoft.com> X-ClientProxiedBy: MW4P221CA0023.NAMP221.PROD.OUTLOOK.COM (2603:10b6:303:8b::28) 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_|SJ1PR21MB3411:EE_ X-MS-Office365-Filtering-Correlation-Id: e38939b3-9173-4145-55d0-08db4148bbd2 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: r9TTXWr4eYaMlnhgzRkMRrsifacAAQf1hhTz1Ri137+rwCyYmGjAZEB9c0Rl1F+gLPFbP6eKh9Za9eAm5GwVG+Ox51skQiiyu1x69nySTdqTHfLAMYuuAS/XRvLdyvlZQ99jKko1hC3Sr8dMh55HM+cFghI33YyBGSu8UW07WUxNuoFabB07JqZN8U6XTruAV7xdvdnz30McGJmm7VI8a0yVjd/TqhEkQEi9E1RmcvCYeBmGUGAMN4+2jJqpCdLNzV59lpmb+huBAljLGeUY6BwQDNBjHTCmprAV9EYF1d0Y3pxtjrqDKHhbUGIsLvE/zz3Vj/kr969jT5Km4hb4E8as+C+PlwHIjAW60EUDtUOx33DB1iop/5XxcuvkNEFzoF3nPN7NZwsqElXr6MbT+3jgz5pfxI3vpGABCsAmpGj0yejpw1f+625A3fzMq97Hsr4C8MDHHRiU0VaOlWvKQwE1HqBGujeHNu3K409flDfKzOuIpqK0YYKmsZXg1189SQHhm0mHzhrNtQx2//JAj5SALEkba4CgcdqU32XHGNLesMA/ilDU1WrHFfNINoqR4RUeuVnmjyY/ocgwoItn0ySyn9wdl03UJfXU5zCKz/OcvrbLhtD4bv92Sv0ZJlsCd9PeHH52VohrJLGYPZX02g== 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)(376002)(366004)(39860400002)(346002)(396003)(136003)(451199021)(2616005)(83380400001)(36756003)(186003)(6486002)(6512007)(1076003)(6506007)(6666004)(52116002)(66946007)(66556008)(10290500003)(66476007)(478600001)(4326008)(316002)(41300700001)(82950400001)(82960400001)(921005)(786003)(8676002)(8936002)(38100700002)(5660300002)(7416002)(86362001)(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GkOk4pQEvoUmy87d3DXVoRpHI9NTTBjjZi+Qxza9yvD70gysbXRTb1BtT0Zj/iwd/i/QlclArOFjgMdxmC+R+Ce1F/R5M1rLu0URPFrdSOGQ0mc1E+V7Zq8Rm7swk2oGhc7Pj5YTbc4t4Jvi2k6ibtGjGhRHmXCzPjZKHKyPeeZbxR3oyLXb/g2clSfjdrO6YdN/gdU0jB0DOkpqRRsTTbvU5gGd7T1ufuU23URndZybbGnYrMwB4y0avrmqpvdRhlSs6ccTudw3eUMcdBQ9Uzqg6JJSRiXfb97gsUtZY98416bKmaeFED4a+cK+vvmJMjt8oZJMn+yzccauBWUp5lZw5/9cUEaor94GuTkBqTColt7cFL0chkulgeuGaGMZkMXRAZEZI5kYxeuDp9peIxyAI3gYDsK/XOhk7pjFQFItJ2nPi2PquIUabsE//iQb4AOFA/lmrbcp7x73Jg74ZD5RV/9ETlMq2GWuw5bhfLwbnHM4zKD87exUUaGiElYUi+7nszbzGsW1XtWK+yTACu5xxaPNDHO9iIf+rYCMyt5udrkqL9CCC/FVyB/Ud8zWJJqSqmbltYYi1tTun7eqH3NdC0z1WkID2bjUthz8BMCsj3s5GsFwmrctidkaS6CHkYq7kqhYsnwWA5KoUlYWJCEfW15Z X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: e38939b3-9173-4145-55d0-08db4148bbd2 X-MS-Exchange-CrossTenant-AuthSource: BL0PR2101MB1092.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Apr 2023 02:41:24.9337 (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: qlEoNcgCZ9WCdmTjtfN3ZPrNu8HkAvlk2S61c5S1mrcUaJSFb6i1t0GMmZSSHUalKmq/fVw5m+QXz6SK7Db+eA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ1PR21MB3411 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 grabing 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 Reviewed-by: Michael Kelley Reviewed-by: Long Li Cc: stable@vger.kernel.org --- v2: No change to the patch body. Improved the commit message [Michael Kelley] Added Cc:stable v3: Added Michael's and Long Li's Reviewed-by. Fixed a typo in the commit message: grubing -> grabing [Thanks, Michael!] 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)