From patchwork Thu May 7 05:02:11 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Hu X-Patchwork-Id: 1284896 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-pci-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=reject dis=none) header.from=microsoft.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=microsoft.com header.i=@microsoft.com header.a=rsa-sha256 header.s=selector2 header.b=FODBNIR6; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 49HhDB50ddz9sSW for ; Thu, 7 May 2020 15:02:50 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725802AbgEGFCp (ORCPT ); Thu, 7 May 2020 01:02:45 -0400 Received: from mail-eopbgr760131.outbound.protection.outlook.com ([40.107.76.131]:19651 "EHLO NAM02-CY1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725763AbgEGFCp (ORCPT ); Thu, 7 May 2020 01:02:45 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=i/TPkzE5sVmhjoc0Md0NpRggwQpccx2x27hAAW3PBJiMIWBw8Fm6GX/TpxYfySRR4BtrZt44SerTI9LiCRth+zDnXXJVDsGmOrItI+cmqiffoQ2ibouXH+FMTHFzGrIXONalrO3lBBgqg6Hd7/cY5BtNbATWDsZ4syjMv7xlL52eoD9YvewJkMHcwEbFrWR19JpH/Pg6k4Pc14hWl4L+Jz10aEHr5pGwvYICk9sftedRMfxll+RxEHPlLNLBcK810ZTWx5Y3npaVVxeXnxef/jkDCqnxZzxPS7A/F8mpyaSMklX5edP8KIZ+BDepk6K4h6wOcPuO05ta+VuEsm0iiA== 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-SenderADCheck; bh=xQaNSgKHCD+G1afG00asYiqCpzBjZS7h3kfEg6+aj74=; b=hZP9URLHuSVSg8p5tz89RGpqFMrLZ+ZGIHQ5GlA/W1iIjax/8zEfuvLwKhM66Cl8w1aGOlXeDbL0vjSsIBUzjeEqhloO399rPc08ePkz+JpGEkqKe/Zy4Q5kjlMHC0zqIOJqdaURJzcGXyckSVUvGc3FBhuOhVTtoj2rWXo2V5AnDDvCUyyHO95kvZKR/B8oqaNg3U9TpPE/ebsVanhLp8JlZIIdTUQtKiUGk2ElkKEtfcWwF4ZDGedPp19BtsIrpfnl51rXGqZ4vGYoVYkDwN9C9me9NYn2xxLpHlPULD6YVzfK6UCMF+634ZVgDtfrEjxQirJU+sRIsGZTzP8czg== 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=xQaNSgKHCD+G1afG00asYiqCpzBjZS7h3kfEg6+aj74=; b=FODBNIR63sTJ/4KRea+mxCSoeuTgBOo5w8YwAOEad/zNr9n8XkKJIZdR+btmOph2L8mlEFYTFzEqIeJ/94pgzLr4FX6bpijeglS0uQQY2LSLzZHmT2MisPTIsbFgrfKUBVPj5DjH1zlCtAYk8WGNcbmuF7/ZL5VK+9hMjhHB/jg= Authentication-Results: microsoft.com; dkim=none (message not signed) header.d=none;microsoft.com; dmarc=none action=none header.from=microsoft.com; Received: from SN6PR2101MB1021.namprd21.prod.outlook.com (2603:10b6:805:8::12) by SN4PR2101MB1584.namprd21.prod.outlook.com (2603:10b6:803:43::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3000.3; Thu, 7 May 2020 05:02:39 +0000 Received: from SN6PR2101MB1021.namprd21.prod.outlook.com ([fe80::a9e6:4244:f67e:c55]) by SN6PR2101MB1021.namprd21.prod.outlook.com ([fe80::a9e6:4244:f67e:c55%6]) with mapi id 15.20.3000.004; Thu, 7 May 2020 05:02:39 +0000 From: Wei Hu To: kys@microsoft.com, haiyangz@microsoft.com, sthemmin@microsoft.com, wei.liu@kernel.org, lorenzo.pieralisi@arm.com, robh@kernel.org, bhelgaas@google.com, linux-hyperv@vger.kernel.org, linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, decui@microsoft.com, mikelley@microsoft.com Cc: Wei Hu Subject: [PATCH v3 1/2] PCI: hv: Fix the PCI HyperV probe failure path to release resource properly Date: Thu, 7 May 2020 13:02:11 +0800 Message-Id: <20200507050211.10923-1-weh@microsoft.com> X-Mailer: git-send-email 2.20.1 Reply-To: weh@microsoft.com X-ClientProxiedBy: SG2PR0601CA0019.apcprd06.prod.outlook.com (2603:1096:3::29) To SN6PR2101MB1021.namprd21.prod.outlook.com (2603:10b6:805:8::12) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from weh-g1-u1904d-testwin10.corp.microsoft.com (167.220.255.113) by SG2PR0601CA0019.apcprd06.prod.outlook.com (2603:1096:3::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2979.27 via Frontend Transport; Thu, 7 May 2020 05:02:35 +0000 X-Mailer: git-send-email 2.20.1 X-Originating-IP: [167.220.255.113] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 94021301-1cd5-4b28-5809-08d7f243dd7c X-MS-TrafficTypeDiagnostic: SN4PR2101MB1584: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:2733; X-Forefront-PRVS: 03965EFC76 X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 3zaUdJaQysS0I/FYUdgUW4nOK5dX8kKl7cQCqHG5sHPIv61GOpD6Nrjs773MjAX2dFb2FKeILF4JlSlcPk4Hy+KacAWlhsFBlNnmC8vbNQRi5BQwkfqZXtxSNUJ8YYWWUsVPy4kRigEzWkaGAxWN5I7yvFATi8SJGRwdZu4Hk7bOil7R9R5ODvQ9OmoB3xSBXNk3HuzW8Y9So4z23h58rbeBWxhjdPt0/Mbv+o6cKdWSv9f6fqzykdISrcIUigoODcgQTn6E8tKFiqCaGQOyy6Rcuw2UJSz2bscS5lcow7igkrA4PQPXZs9WyBn3Js+o/YvEsgndWWI1a8hyRX8D5swBjseL2b81VYvE4bfmJmY384UKHn4DkNcTIgOdc2KzTaJxS79qL8dhXzY06gpPWCcuVrhGogvyTYFvIsLFr6rGsLul3ivJ1vFO3xZo+HZgNfgRnXQB9J7xhaC5ljT+6yByQIuyzY0Hm/l5XRViEVp3SWItqSTNFhkS7rP73blnIaHkxog2FmzpcthtOYK4Bum6WUFuijNUjcY57ofV0sE= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SN6PR2101MB1021.namprd21.prod.outlook.com;PTR:;CAT:NONE;SFTY:;SFS:(4636009)(39860400002)(396003)(366004)(346002)(376002)(136003)(33430700001)(82950400001)(5660300002)(2616005)(956004)(478600001)(10290500003)(316002)(1076003)(83300400001)(83280400001)(83320400001)(83310400001)(83290400001)(66946007)(3450700001)(82960400001)(4326008)(6636002)(107886003)(26005)(7696005)(52116002)(36756003)(33440700001)(86362001)(6666004)(66476007)(8676002)(186003)(6486002)(66556008)(2906002)(16526019)(8936002)(921003);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData: Mz9foqbUM4dLf9gSrycvn4IqOzeDA31cBZtKO24gmsJvGFhpTpw9DJuvJ2iTuhlzD/DyZU+BpQUF9LBlr0eRBgnMRB7pTsh8aum3EW5CQmOTiq1wwPxqTpHB8rZBYz/qlYGQH+tBVFXKRFVxrkN0iZgRnksfkVhOrDWTwZrLmsc8t5zaWN4IVxq3WPQP796w5/FgUXAiyj9Zz0Y6HjL8EaLU+NFZ9c8cmaN39glrRl1OIBBWsVEKEolnYUxQPlqIyQWdiSFKPCA74RrI5mcw4mWaflpdP0O6QSLIbf0BmYvAAsaXkAZofHgD45cxDQvCgSuJO0TopMA+nb9P3wf3vxIyqQ+TLuxMTVyAvVFPSbSQYSE/xs6UVz4cdCaRM7+wBth2yQv0cn+zLflj3wXYdHjRJcKv8RNFIW3a7Rxf/Wh4+nrMl16aNVCXRvMKrvxB1r3+Kerl+22m39smvDVYoAuOn7RBdrE2WVb+rybuXYJqWYeHQe4cYhdNYyyvuwj/DBx5Dy8kQ3Zsy6QciyyhKzgCc/gzRAplBM86nrUMEAHRbfks9qIJnqbdDC8HW+noHH1v0kFjgIsm5lzSiQZ1tz1ES2Y39Y+g2LzyOaYHx4VAWOUtVp0APF2oaR/ifWjmySnhXDSPuhHwAd4jsSugaAhzGEtpJRXaKZIVjIYNa7czRz2WDL16hwTo5X6R22fGm1MtO0LozennlGnsPLfmfqyKTRVyHwEyLD0GDSo7MS1H08oEoZQ0RX1oBTZ+4E6h93mBRGPy/VziCZeazjS16yzeSSXUNAPyO1a8i9TU+ozpDC4m49WSYDJvQdX4Yiy9 X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: 94021301-1cd5-4b28-5809-08d7f243dd7c X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 May 2020 05:02:39.2107 (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: TDgMtfyxT+p2imBUfX3SDYayNCkR0d3wofFgkhFpD/Y85r/W/gu5DXmEeYgub+vX8A2FcfGyuzsbxZFjoBki+w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN4PR2101MB1584 Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org In some error cases in hv_pci_probe(), allocated resources are not freed. Fix this by adding a field to keep track of the high water mark for slots that have resources allocated to them. In case of an error, this high water mark is used to know which slots have resources that must be released. Since slots are numbered starting with zero, a value of -1 indicates no slots have been allocated resources. There may be unused slots in the range between slot 0 and the high water mark slot, but these slots are already ignored by the existing code in the allocate and release loops with the call to get_pcichild_wslot(). Signed-off-by: Wei Hu Reviewed-by: Michael Kelley --- v3: Add detailed explanation of this patch in commit log per Lorenzo Pieralisi's suggestions. drivers/pci/controller/pci-hyperv.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/drivers/pci/controller/pci-hyperv.c b/drivers/pci/controller/pci-hyperv.c index e15022ff63e3..e6fac0187722 100644 --- a/drivers/pci/controller/pci-hyperv.c +++ b/drivers/pci/controller/pci-hyperv.c @@ -480,6 +480,9 @@ struct hv_pcibus_device { struct workqueue_struct *wq; + /* Highest slot of child device with resources allocated */ + int wslot_res_allocated; + /* hypercall arg, must not cross page boundary */ struct hv_retarget_device_interrupt retarget_msi_interrupt_params; @@ -2847,7 +2850,7 @@ static int hv_send_resources_allocated(struct hv_device *hdev) struct hv_pci_dev *hpdev; struct pci_packet *pkt; size_t size_res; - u32 wslot; + int wslot; int ret; size_res = (hbus->protocol_version < PCI_PROTOCOL_VERSION_1_2) @@ -2900,6 +2903,8 @@ static int hv_send_resources_allocated(struct hv_device *hdev) comp_pkt.completion_status); break; } + + hbus->wslot_res_allocated = wslot; } kfree(pkt); @@ -2918,10 +2923,10 @@ static int hv_send_resources_released(struct hv_device *hdev) struct hv_pcibus_device *hbus = hv_get_drvdata(hdev); struct pci_child_message pkt; struct hv_pci_dev *hpdev; - u32 wslot; + int wslot; int ret; - for (wslot = 0; wslot < 256; wslot++) { + for (wslot = hbus->wslot_res_allocated; wslot >= 0; wslot--) { hpdev = get_pcichild_wslot(hbus, wslot); if (!hpdev) continue; @@ -2936,8 +2941,12 @@ static int hv_send_resources_released(struct hv_device *hdev) VM_PKT_DATA_INBAND, 0); if (ret) return ret; + + hbus->wslot_res_allocated = wslot - 1; } + hbus->wslot_res_allocated = -1; + return 0; } @@ -3037,6 +3046,7 @@ static int hv_pci_probe(struct hv_device *hdev, if (!hbus) return -ENOMEM; hbus->state = hv_pcibus_init; + hbus->wslot_res_allocated = -1; /* * The PCI bus "domain" is what is called "segment" in ACPI and other @@ -3136,7 +3146,7 @@ static int hv_pci_probe(struct hv_device *hdev, ret = hv_pci_allocate_bridge_windows(hbus); if (ret) - goto free_irq_domain; + goto exit_d0; ret = hv_send_resources_allocated(hdev); if (ret) @@ -3154,6 +3164,8 @@ static int hv_pci_probe(struct hv_device *hdev, free_windows: hv_pci_free_bridge_windows(hbus); +exit_d0: + (void) hv_pci_bus_exit(hdev, true); free_irq_domain: irq_domain_remove(hbus->irq_domain); free_fwnode: From patchwork Thu May 7 05:03:00 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Hu X-Patchwork-Id: 1284897 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-pci-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=reject dis=none) header.from=microsoft.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=microsoft.com header.i=@microsoft.com header.a=rsa-sha256 header.s=selector2 header.b=iJA+AxpG; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 49HhF13MC7z9sSW for ; Thu, 7 May 2020 15:03:33 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725783AbgEGFDb (ORCPT ); Thu, 7 May 2020 01:03:31 -0400 Received: from mail-eopbgr760092.outbound.protection.outlook.com ([40.107.76.92]:22353 "EHLO NAM02-CY1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725763AbgEGFDb (ORCPT ); Thu, 7 May 2020 01:03:31 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Go0GHRPJjjODy7rYDaELbrn596ysCoRRXlzKbKQdWq8aFvelc+d0a+LkDadAGn9+JA0+DX3WZXt7rI8dYK+Dl1WSNXuUXV4YEXDykIYW/ZikreKb6/ZTuHtemfMf2lXsSv7L76k9k9QB3DVv9dqw4uE14GgjhQhMg4lE4+uXBzkxliRWNcsPLM0c5oj2Om4SewTmLhMrIgKeUNID3DdilxrVCtsF5XUroCU7WBYy26fpRJsmwULst4Uh5I5psG0UExIf2JqNNkwEFH4Wtdm/mJtxggA0ucfsvrcmHzwqcpYlg8yQu6hZUomAr2V0C2uv0wCLiQkmhU/+XwAm4vZHtA== 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-SenderADCheck; bh=kKFVlzUIW4xVhlfs4E5qk5bCEg1g3RRToHvxtByxeKU=; b=a+L70UaxBVsxSVo+WiZEY8l2uU1BDy4aaGF8RYBIj3iOil5SG98l17AeC1rnK1mBjvcGK6hsN7ayIyCVAsK5tfbTeOZsNQFfElH2hnA3M5kCL1TXjYWQJniGTZcs/98mLWo37vpD5Oz+LSa7aQcBnT+rl/Y/qE7kYzoeVt49CYjffXueiv+KdYBbZpVsrPm/3zBcpulEX6KCWBjRw8qfGoF3D4m3/v1HefPMRpeKTcdpYT+gmnrqsxy9Yrdv3yQBphIR5j98fXmEbwKPPRzSnubc7+aX6Nh0+OEyWcW37nnqN7K+GaltVJEkHY7DmRKpb6GuDh5Gd65xBHeAY0JxrQ== 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=kKFVlzUIW4xVhlfs4E5qk5bCEg1g3RRToHvxtByxeKU=; b=iJA+AxpGiWTrPf8xdEGI1onAX9VIKwNWA+yC7zxbCed3OEktKmz3RnEV3xYfXB/ynt5ARTx63SUI87d4RboxAQW+74fLEfIrjKwlP1IVGTU+dX/GkloDMa1x2g/YcenFasd1dIpz9rAdnTcbSAzh0G6X9fw1HoUyC+GHqiIGJ5w= Authentication-Results: microsoft.com; dkim=none (message not signed) header.d=none;microsoft.com; dmarc=none action=none header.from=microsoft.com; Received: from SN6PR2101MB1021.namprd21.prod.outlook.com (2603:10b6:805:8::12) by SN4PR2101MB1584.namprd21.prod.outlook.com (2603:10b6:803:43::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3000.3; Thu, 7 May 2020 05:03:28 +0000 Received: from SN6PR2101MB1021.namprd21.prod.outlook.com ([fe80::a9e6:4244:f67e:c55]) by SN6PR2101MB1021.namprd21.prod.outlook.com ([fe80::a9e6:4244:f67e:c55%6]) with mapi id 15.20.3000.004; Thu, 7 May 2020 05:03:28 +0000 From: Wei Hu To: kys@microsoft.com, haiyangz@microsoft.com, sthemmin@microsoft.com, wei.liu@kernel.org, lorenzo.pieralisi@arm.com, robh@kernel.org, bhelgaas@google.com, linux-hyperv@vger.kernel.org, linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, decui@microsoft.com, mikelley@microsoft.com Cc: Wei Hu Subject: [PATCH v3 2/2] PCI: hv: Retry PCI bus D0 entry when the first attempt failed with invalid device state Date: Thu, 7 May 2020 13:03:00 +0800 Message-Id: <20200507050300.10974-1-weh@microsoft.com> X-Mailer: git-send-email 2.20.1 Reply-To: weh@microsoft.com X-ClientProxiedBy: SG2PR02CA0046.apcprd02.prod.outlook.com (2603:1096:3:18::34) To SN6PR2101MB1021.namprd21.prod.outlook.com (2603:10b6:805:8::12) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from weh-g1-u1904d-testwin10.corp.microsoft.com (167.220.255.113) by SG2PR02CA0046.apcprd02.prod.outlook.com (2603:1096:3:18::34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2979.28 via Frontend Transport; Thu, 7 May 2020 05:03:24 +0000 X-Mailer: git-send-email 2.20.1 X-Originating-IP: [167.220.255.113] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 41a8155d-8c26-43c0-7e78-08d7f243fac2 X-MS-TrafficTypeDiagnostic: SN4PR2101MB1584: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:9508; X-Forefront-PRVS: 03965EFC76 X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: rTFzUuomV3TsTRGTJ9WUhbgKRKfwAG2sx6p/mrJmRUeAQtoFA5PZn4LRNAOh/yuDU1Av0brp/EjFSFv3oY+RH8lvxrrhfxeq8O2Mieis7Vj04osxUBxxzw/geQeb3GC619jNqBATQvuurBP0utgrQNTTM8cm/G3nmgLcdjGC7QTmf10uPu5zMAz0uxV6bR1aqqA4/e2JelEi8LyL/WlbiEf3g47gIQ1C87jMAQDMDKyVVaLBDs9vbFLZISV5viauBk6TP9I9sSLvTSQ1W5Tj6ySyBllq1bBLJwYHFZ5eRLEDOCcA7DiaCWdYt9XO+j3PBclnUGbJaOAi6rplgZ5++t8j5IclZNCyiBaWB5Tv8tHJyWwvDxLFCtST6fOVYifBXKWH/QUeuZO8w05pTaApeZbJTWkfL5GxXoDBFs7jd7BAy09rgJ/j/5IRSHA5HNycNSCiKukd372k98n95wjTscZSgvYSSCGq4aliJwS1fVZHT4Bn8kh0h8OfWEY5xqzMA+gTw6nFc1r9VcpgKWdUsaDV8RCfax8OcaP2NESTZaI= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SN6PR2101MB1021.namprd21.prod.outlook.com;PTR:;CAT:NONE;SFTY:;SFS:(4636009)(39860400002)(396003)(366004)(346002)(376002)(136003)(33430700001)(82950400001)(5660300002)(2616005)(956004)(478600001)(10290500003)(316002)(1076003)(83300400001)(83280400001)(83320400001)(83310400001)(83290400001)(66946007)(3450700001)(82960400001)(4326008)(6636002)(107886003)(26005)(7696005)(52116002)(36756003)(33440700001)(86362001)(6666004)(66476007)(8676002)(186003)(6486002)(66556008)(2906002)(16526019)(8936002)(921003);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData: cBANEynu1zzzef11M3ERjNFrxelnlcXxkHOHex38IiKK4+sHsofeo631xowm9BCjVCARC+HrJd8MPZB94m3pUaoPg6Q+CaxlMcGktMd3X1L/2bzVsQdrEZf6WSs5WXwRZRN/u+75cX+CPRlGxFLf/aeWdUGwNRimB2Yk49LJaZINu6ehkgHFWZxBTZTrKo9ejTCwyHBaS4vAq+HY5RFJo7kXFXc9KaH8svzefDI4Rp4rYfbCh9YMsl7m0dsggL9eTEjr5NsiJmQ0Z8bWbdZFTgHq7+e3/zbtZHOesN4t0Dj92fSGe5gvvyUeugHBBzs6P5LLLmG+5onEQXiYgNsXQzYM9FmqxdJ3/mc9768WNpmo6rIHdwbMbOX5Y+IWerN8iGyjFr4NXnpjIEKHy9Et4ScjmrGQql8uIAvClhB7s77QS7dVF07ICXrkfcdXPTkXr50w7IiLpb6dduZPuHHj++M85fuGTc5ekJUPJydtvitcS+EcyjB/w0nZFiKt+gC9l9nF0Xa1M7G54CZV+WkkSBfH/cZVz6whjtBvNvHn7yeNHGkcfLQu0CLBayVJviKi1KS4GIUozRYUkC/FmLCFmKdgONhplt7lt1/9MR+z+qmusC7dU0+Oq6rXcwKFKWbzvloxL03pANMuCIUWRqkEyigFT+PD201+BYSwN38PRqwouVssj3QIPuYhD+TB5RERegRT120Eeb2JpcEU6QmT85wZlxa0HqdWq5iGl4ASeyo5vG5xUO0IFPk1bh6OPYTqCxmjjdo+72ApuZxykUqwzJC6zIwBeUPa4yvdkrVlpV6w50bHBwWj875M4wFos4wp X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: 41a8155d-8c26-43c0-7e78-08d7f243fac2 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 May 2020 05:03:28.3283 (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: vKOTRcy6upIjrPsp8xmzhmAJtZIFY61HslCGcWSZLr45ChorV6FlW11xorYUq9RDyQnfOsxHYOsbQgdsuNRB7Q== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN4PR2101MB1584 Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org In the case of kdump, the PCI device was not cleanly shut down before the kdump kernel starts. This causes the initial attempt of entering D0 state in the kdump kernel to fail with invalid device state returned from Hyper-V host. When this happens, explicitly call PCI bus exit and retry to enter the D0 state. Signed-off-by: Wei Hu Reviewed-by: Michael Kelley --- v2: Incorporate review comments from Michael Kelley, Dexuan Cui and Bjorn Helgaas drivers/pci/controller/pci-hyperv.c | 40 +++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/drivers/pci/controller/pci-hyperv.c b/drivers/pci/controller/pci-hyperv.c index e6fac0187722..92092a47d3af 100644 --- a/drivers/pci/controller/pci-hyperv.c +++ b/drivers/pci/controller/pci-hyperv.c @@ -2739,6 +2739,8 @@ static void hv_free_config_window(struct hv_pcibus_device *hbus) vmbus_free_mmio(hbus->mem_config->start, PCI_CONFIG_MMIO_LENGTH); } +static int hv_pci_bus_exit(struct hv_device *hdev, bool keep_devs); + /** * hv_pci_enter_d0() - Bring the "bus" into the D0 power state * @hdev: VMBus's tracking struct for this root PCI bus @@ -2751,8 +2753,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 @@ -2779,6 +2783,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", @@ -3185,7 +3221,7 @@ static int hv_pci_probe(struct hv_device *hdev, return ret; } -static int hv_pci_bus_exit(struct hv_device *hdev, bool hibernating) +static int hv_pci_bus_exit(struct hv_device *hdev, bool keep_devs) { struct hv_pcibus_device *hbus = hv_get_drvdata(hdev); struct { @@ -3203,7 +3239,7 @@ static int hv_pci_bus_exit(struct hv_device *hdev, bool hibernating) if (hdev->channel->rescind) return 0; - if (!hibernating) { + if (!keep_devs) { /* Delete any children which might still exist. */ dr = kzalloc(sizeof(*dr), GFP_KERNEL); if (dr && hv_pci_start_relations_work(hbus, dr))