From patchwork Wed Sep 11 23:38:19 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dexuan Cui X-Patchwork-Id: 11141959 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A288517E6 for ; Wed, 11 Sep 2019 23:38:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 776FE208E4 for ; Wed, 11 Sep 2019 23:38:38 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=microsoft.com header.i=@microsoft.com header.b="ZUPgw+pA" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729275AbfIKXiX (ORCPT ); Wed, 11 Sep 2019 19:38:23 -0400 Received: from mail-eopbgr690132.outbound.protection.outlook.com ([40.107.69.132]:35718 "EHLO NAM04-CO1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727659AbfIKXiX (ORCPT ); Wed, 11 Sep 2019 19:38:23 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=MEzCjtxWldot3KedsGRWpZCtt4JfUvWqfDm9JATtpu9+GVokpdqzQKv8kXDk0DNl4xPiRpm67RncvvpJwOmPm35h45OdFWF5kDrDubRd1///e9KavFVJIPh1uTBpCIk7x1PsBgWHUWKm6cGrW9wCCL41zQexQ4e/Gzy/h4DRtpiYfQeCZ7uHkXk2o+YrcVnPK64xbyUEUGz4KkgdIBHqotVycx+ZHHZCxf8ocYyuT0rOwH5yCPL7lpPFv5qOuyIDA5brHwyXWT//64plaMB8o74b5ZiaEupGLr1gh42lu+B36Mw8ujW5l1O3O+VJ4NB+WrvaeOeGz8KNX9ALd8Yoqg== 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=9DlLZwW6isbPdVbDQ4/oJebPTV6kdXee37ZfWpTsV9w=; b=GzqQBZWxN2c4y5701rJZaozHm/wUANcfOCXWN18m98nOVkqmnWMLWjg7upkwdjBAbXi56FGTYSkt5bHhGxpOc6puyYr2WAe0KPnPcwzYZW3UeMUT7FHTufPvJBUDthWQDsip7KX/3YdSCmOWA2js2L6amcuRNmeO5S3dk0309K83gWSbG+f2YRzE8+5FMIJaRI51GLvc8tzPiAGmKpMuqxizDTiVusexRnrYlEQSidgxJ1mAStAXOuiZsc/zFzR7K5yjwO8sRdaM+C7Z+gB6RbQiqevs7cb7Y44UYcaU9nt5Km5KnkXjBkDFhwzbUDBD8soOhVPbVfuviaiUS+7baA== 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=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=9DlLZwW6isbPdVbDQ4/oJebPTV6kdXee37ZfWpTsV9w=; b=ZUPgw+pAaLlHvQJgqdk0rt1yqXuTEHuBCOubP/EapG6jhgHkQgWXbHHvbAdKqzF2/nUJ6EBAl7lRFg8j/aA79aLl3ml4y3ycFJi53s3/KD8Us0eMtZ0UQuZFoTeuGyTQJArr2IyLAwU/nsubTjwfylebUvWvqT78VeQXCJf4DDw= Received: from SN6PR2101MB0942.namprd21.prod.outlook.com (52.132.114.19) by SN6PR2101MB1087.namprd21.prod.outlook.com (52.132.115.24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2284.7; Wed, 11 Sep 2019 23:38:19 +0000 Received: from SN6PR2101MB0942.namprd21.prod.outlook.com ([fe80::dd56:aa4f:204f:86a4]) by SN6PR2101MB0942.namprd21.prod.outlook.com ([fe80::dd56:aa4f:204f:86a4%3]) with mapi id 15.20.2263.005; Wed, 11 Sep 2019 23:38:19 +0000 From: Dexuan Cui To: KY Srinivasan , Haiyang Zhang , Stephen Hemminger , "sashal@kernel.org" , "lorenzo.pieralisi@arm.com" , "bhelgaas@google.com" , "linux-hyperv@vger.kernel.org" , "linux-pci@vger.kernel.org" , "linux-kernel@vger.kernel.org" , Michael Kelley CC: Dexuan Cui Subject: [PATCH 1/4] PCI: hv: Reorganize the code in preparation of hibernation Thread-Topic: [PATCH 1/4] PCI: hv: Reorganize the code in preparation of hibernation Thread-Index: AQHVaPn9aDMSJjZvRECnLTtcPvbeMw== Date: Wed, 11 Sep 2019 23:38:19 +0000 Message-ID: <1568245086-70601-2-git-send-email-decui@microsoft.com> References: <1568245086-70601-1-git-send-email-decui@microsoft.com> In-Reply-To: <1568245086-70601-1-git-send-email-decui@microsoft.com> Reply-To: Dexuan Cui Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: MWHPR19CA0072.namprd19.prod.outlook.com (2603:10b6:300:94::34) To SN6PR2101MB0942.namprd21.prod.outlook.com (2603:10b6:805:4::19) authentication-results: spf=none (sender IP is ) smtp.mailfrom=decui@microsoft.com; x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: git-send-email 1.8.3.1 x-originating-ip: [13.77.154.182] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 25d46f05-0466-4555-fbad-08d737111fae x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0;PCL:0;RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600166)(711020)(4605104)(1401327)(4618075)(2017052603328)(7193020);SRVR:SN6PR2101MB1087; x-ms-traffictypediagnostic: SN6PR2101MB1087:|SN6PR2101MB1087: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:4941; x-forefront-prvs: 0157DEB61B x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(4636009)(376002)(136003)(346002)(39860400002)(396003)(366004)(199004)(189003)(10290500003)(11346002)(2201001)(2501003)(256004)(7736002)(6436002)(305945005)(2906002)(14454004)(3846002)(2616005)(81156014)(81166006)(8936002)(50226002)(66066001)(26005)(8676002)(5660300002)(110136005)(6116002)(316002)(6512007)(66556008)(186003)(66946007)(86362001)(446003)(66446008)(6486002)(64756008)(66476007)(22452003)(71200400001)(476003)(71190400001)(107886003)(43066004)(25786009)(478600001)(14444005)(102836004)(6636002)(99286004)(1511001)(36756003)(4326008)(486006)(76176011)(53936002)(52116002)(3450700001)(6506007)(386003)(4720700003)(10090500001)(921003)(1121003);DIR:OUT;SFP:1102;SCL:1;SRVR:SN6PR2101MB1087;H:SN6PR2101MB0942.namprd21.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;A:1;MX:1; received-spf: None (protection.outlook.com: microsoft.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: 9VkZEHZKjS9yme7oudYBU9tNos9D7wPPeNDgYnCpSkNetxYqRP3txARQog8IBQzJj/hbrt8rOHpXhMZ2hEdAV5Fpcjtj/+HBb7NMF59KYrHg+eUVI24g0wMrqV98/qJaS2+HZ/VaK0V5A+cQZT+gJx7BqVZV3TVvzZMeeFFsj4TRm9tKS2YYvpHxoKfFKcsZbFtSImefARdVAf45EjoQsnfaof3Ze9nzImu+jUTfd49OIj8/vPQBrJiTgCTNiXus+ZanXsrPS3DY/C5I5kSqaWWHjoPx/B9gVoGuZDh7a/5JKHWK503LavIWwLI2NDEeL95tNXNtQYP3eGVtYR2aRHKd+WPfqTZRXoTjYXDO6UtKPkc0Mn8wFv6vReOskYu3VpHAh8zrl2rpXRyKyd0BFhHodw/m3DiQdAPsa674Dyk= MIME-Version: 1.0 X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: 25d46f05-0466-4555-fbad-08d737111fae X-MS-Exchange-CrossTenant-originalarrivaltime: 11 Sep 2019 23:38:19.2201 (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: KC0Dk1XhguFdXL5oRVO2QIEqdppNojxZzJBep7LRyxluxQsy4lTlZh2X3VJfd+xtkxRjIVU0VEKd1IeGe55TGQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN6PR2101MB1087 Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org There is no functional change. This is just preparatory to a later patch which adds the hibernation support for the pci-hyperv driver. Signed-off-by: Dexuan Cui --- drivers/pci/controller/pci-hyperv.c | 43 ++++++++++++++++++++++++------------- 1 file changed, 28 insertions(+), 15 deletions(-) diff --git a/drivers/pci/controller/pci-hyperv.c b/drivers/pci/controller/pci-hyperv.c index 40b6254..03fa039 100644 --- a/drivers/pci/controller/pci-hyperv.c +++ b/drivers/pci/controller/pci-hyperv.c @@ -2080,7 +2080,9 @@ static void hv_pci_onchannelcallback(void *context) * failing if the host doesn't support the necessary protocol * level. */ -static int hv_pci_protocol_negotiation(struct hv_device *hdev) +static int hv_pci_protocol_negotiation(struct hv_device *hdev, + enum pci_protocol_version_t version[], + int num_version) { struct pci_version_request *version_req; struct hv_pci_compl comp_pkt; @@ -2104,8 +2106,8 @@ static int hv_pci_protocol_negotiation(struct hv_device *hdev) version_req = (struct pci_version_request *)&pkt->message; version_req->message_type.type = PCI_QUERY_PROTOCOL_VERSION; - for (i = 0; i < ARRAY_SIZE(pci_protocol_versions); i++) { - version_req->protocol_version = pci_protocol_versions[i]; + for (i = 0; i < num_version; i++) { + version_req->protocol_version = version[i]; ret = vmbus_sendpacket(hdev->channel, version_req, sizeof(struct pci_version_request), (unsigned long)pkt, VM_PKT_DATA_INBAND, @@ -2121,7 +2123,7 @@ static int hv_pci_protocol_negotiation(struct hv_device *hdev) } if (comp_pkt.completion_status >= 0) { - pci_protocol_version = pci_protocol_versions[i]; + pci_protocol_version = version[i]; dev_info(&hdev->device, "PCI VMBus probing: Using version %#x\n", pci_protocol_version); @@ -2572,7 +2574,8 @@ static int hv_pci_probe(struct hv_device *hdev, hv_set_drvdata(hdev, hbus); - ret = hv_pci_protocol_negotiation(hdev); + ret = hv_pci_protocol_negotiation(hdev, pci_protocol_versions, + ARRAY_SIZE(pci_protocol_versions)); if (ret) goto close; @@ -2644,7 +2647,7 @@ static int hv_pci_probe(struct hv_device *hdev, return ret; } -static void hv_pci_bus_exit(struct hv_device *hdev) +static int hv_pci_bus_exit(struct hv_device *hdev, bool hibernating) { struct hv_pcibus_device *hbus = hv_get_drvdata(hdev); struct { @@ -2660,16 +2663,20 @@ static void hv_pci_bus_exit(struct hv_device *hdev) * access the per-channel ringbuffer any longer. */ if (hdev->channel->rescind) - return; + return 0; - /* Delete any children which might still exist. */ - memset(&relations, 0, sizeof(relations)); - hv_pci_devices_present(hbus, &relations); + if (!hibernating) { + /* Delete any children which might still exist. */ + memset(&relations, 0, sizeof(relations)); + hv_pci_devices_present(hbus, &relations); + } ret = hv_send_resources_released(hdev); - if (ret) + if (ret) { dev_err(&hdev->device, "Couldn't send resources released packet(s)\n"); + return ret; + } memset(&pkt.teardown_packet, 0, sizeof(pkt.teardown_packet)); init_completion(&comp_pkt.host_event); @@ -2682,8 +2689,13 @@ static void hv_pci_bus_exit(struct hv_device *hdev) (unsigned long)&pkt.teardown_packet, VM_PKT_DATA_INBAND, VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED); - if (!ret) - wait_for_completion_timeout(&comp_pkt.host_event, 10 * HZ); + if (ret) + return ret; + + if (wait_for_completion_timeout(&comp_pkt.host_event, 10 * HZ) == 0) + return -ETIMEDOUT; + + return 0; } /** @@ -2695,6 +2707,7 @@ static void hv_pci_bus_exit(struct hv_device *hdev) static int hv_pci_remove(struct hv_device *hdev) { struct hv_pcibus_device *hbus; + int ret; hbus = hv_get_drvdata(hdev); if (hbus->state == hv_pcibus_installed) { @@ -2707,7 +2720,7 @@ static int hv_pci_remove(struct hv_device *hdev) hbus->state = hv_pcibus_removed; } - hv_pci_bus_exit(hdev); + ret = hv_pci_bus_exit(hdev, false); vmbus_close(hdev->channel); @@ -2721,7 +2734,7 @@ static int hv_pci_remove(struct hv_device *hdev) wait_for_completion(&hbus->remove_event); destroy_workqueue(hbus->wq); free_page((unsigned long)hbus); - return 0; + return ret; } static const struct hv_vmbus_device_id hv_pci_id_table[] = { From patchwork Wed Sep 11 23:38:20 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dexuan Cui X-Patchwork-Id: 11141957 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3F0701599 for ; Wed, 11 Sep 2019 23:38:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 12E0420863 for ; Wed, 11 Sep 2019 23:38:38 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=microsoft.com header.i=@microsoft.com header.b="PaJVMpsS" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729081AbfIKXi0 (ORCPT ); Wed, 11 Sep 2019 19:38:26 -0400 Received: from mail-eopbgr690132.outbound.protection.outlook.com ([40.107.69.132]:35718 "EHLO NAM04-CO1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726525AbfIKXiZ (ORCPT ); Wed, 11 Sep 2019 19:38:25 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=KTGaRGIoroQHCrMM+im3dHbi3JXEulZqO4kTICvgeZBvnwcMBRn+hSrCfRD8CbrS+I7NXlANfQzYuMcpxbsSU0qV5++wotWQXRtngp30Zhz7mMA4QfEsNYw33zFj9IEnBAjDQoeSQs9XrGYXv0nh7c19jOskqbctGFJyENH39SN8sjyHKCHT/bKY5cisPHEiiPrwWNvb0sZnxUx5tsWtwxOyIgQHHiamX/enAunVJZ+wHMX1Ev+HPtSjxnPvzzwOkQZuDVGlFcJtaySN/tA3LoA2bTGzzrQI8B064FrdF3BxddvPDbgtnc3DmnoGpkiylcjNgf3qlAV1YKgLsZgAZQ== 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=G9Vln3Esilvf0BzlbdluiKamT5+ViS25EX8eBAg/Jss=; b=j6AQ95JwRuRHaFwrTqeQ/xQiLXcnr7fLlqVxiZVCSVjXNiJL7oSE2x2VkE/F2YR/As8bCkpC4fNfRCf0Q/8yzL070UI6GhBf4SPE0P7ktNh0oPZEPYfpwxZEFU1kx6za5nw4pHMtOachtVSfWqxlzau70H03J8W4Zs+swcsZHXKrSoUhdqawVs3VOWrhxfYUtrREZpcKeRzg06pAJq+ss/9IY7g+0l+tWNstt6vgM7e96TmELJO77w41tjfdcHxaEYyenlqrRScYWmrlN1Qtc9vXnuaW6IvcwYw1pv1xC62YRT0m4sXNdyTUJEXq3o27CX2n7GfFyXuyRRwFSG2lWg== 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=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=G9Vln3Esilvf0BzlbdluiKamT5+ViS25EX8eBAg/Jss=; b=PaJVMpsSDg8C/IjCkoKFkySSDX7bURW9EdlUzh78FYNRzj+nzOIt7lJX2Ml0CdZijfxTsbzN6BwoUWDFNCpyOWrCIXXpl8RSN6e7yO2Hr6hcZx0lkoFbdruquYSjbl243wb9NaynBfQM0ddXLkeNsfdKdyRtghtOP38wfTk1xB8= Received: from SN6PR2101MB0942.namprd21.prod.outlook.com (52.132.114.19) by SN6PR2101MB1087.namprd21.prod.outlook.com (52.132.115.24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2284.7; Wed, 11 Sep 2019 23:38:20 +0000 Received: from SN6PR2101MB0942.namprd21.prod.outlook.com ([fe80::dd56:aa4f:204f:86a4]) by SN6PR2101MB0942.namprd21.prod.outlook.com ([fe80::dd56:aa4f:204f:86a4%3]) with mapi id 15.20.2263.005; Wed, 11 Sep 2019 23:38:20 +0000 From: Dexuan Cui To: KY Srinivasan , Haiyang Zhang , Stephen Hemminger , "sashal@kernel.org" , "lorenzo.pieralisi@arm.com" , "bhelgaas@google.com" , "linux-hyperv@vger.kernel.org" , "linux-pci@vger.kernel.org" , "linux-kernel@vger.kernel.org" , Michael Kelley CC: Dexuan Cui Subject: [PATCH 2/4] PCI: hv: Add the support of hibernation Thread-Topic: [PATCH 2/4] PCI: hv: Add the support of hibernation Thread-Index: AQHVaPn+DI+GUCWMB0+XXf/yIGJHbQ== Date: Wed, 11 Sep 2019 23:38:20 +0000 Message-ID: <1568245086-70601-3-git-send-email-decui@microsoft.com> References: <1568245086-70601-1-git-send-email-decui@microsoft.com> In-Reply-To: <1568245086-70601-1-git-send-email-decui@microsoft.com> Reply-To: Dexuan Cui Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: MWHPR19CA0072.namprd19.prod.outlook.com (2603:10b6:300:94::34) To SN6PR2101MB0942.namprd21.prod.outlook.com (2603:10b6:805:4::19) authentication-results: spf=none (sender IP is ) smtp.mailfrom=decui@microsoft.com; x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: git-send-email 1.8.3.1 x-originating-ip: [13.77.154.182] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: ee158937-7278-4e47-c733-08d7371120d3 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0;PCL:0;RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600166)(711020)(4605104)(1401327)(4618075)(2017052603328)(7193020);SRVR:SN6PR2101MB1087; x-ms-traffictypediagnostic: SN6PR2101MB1087:|SN6PR2101MB1087: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:8882; x-forefront-prvs: 0157DEB61B x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(4636009)(376002)(136003)(346002)(39860400002)(396003)(366004)(199004)(189003)(10290500003)(11346002)(2201001)(2501003)(256004)(7736002)(6436002)(305945005)(2906002)(14454004)(3846002)(2616005)(81156014)(81166006)(8936002)(50226002)(66066001)(26005)(8676002)(5660300002)(110136005)(6116002)(316002)(6512007)(66556008)(186003)(66946007)(86362001)(446003)(66446008)(6486002)(64756008)(66476007)(22452003)(71200400001)(476003)(71190400001)(107886003)(43066004)(25786009)(478600001)(14444005)(102836004)(6636002)(99286004)(1511001)(36756003)(4326008)(486006)(76176011)(53936002)(52116002)(3450700001)(6506007)(386003)(4720700003)(10090500001)(21314003)(921003)(1121003);DIR:OUT;SFP:1102;SCL:1;SRVR:SN6PR2101MB1087;H:SN6PR2101MB0942.namprd21.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;A:1;MX:1; received-spf: None (protection.outlook.com: microsoft.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: QuTtAVzF4IzsT9/AML/9Lgu1js1fc0vB8AXvkE2Njs58mpGv4etirziCZcS2KoZcu6OZ/SILCE+dfow5ELS2j2EK2ldyT9oUTjAlE0Ga5+EXs0lNazTzXewx7UVb8mVFvx3sdCI0N059AhnftO9wg/k+Fzi3XTj1bdhnClMAJyxCXNkLIKP7erRhFnx1IIBNpkdq+O+DEHaUIBLXLQ2kVHGdNHv6kqPJboFcULqPaoaWaYaXBozpI0Z/9VD170h6HmHeQcsjCc4CrvnOtz33UGSpBK0hi5hrMVshdafCl27pDMziQ9pQ+uRWV6Yi7rtLDYgLP1g4ywa4Eedexcp0pRazYbGZqeyVcsoL3Y4SG6UKPT83tSH5GYqjEpK5gfkMhEQhrW3Jp2DuDz4EUB/XJUHsF0Pueb6kI6wbS8ev0Aw= MIME-Version: 1.0 X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: ee158937-7278-4e47-c733-08d7371120d3 X-MS-Exchange-CrossTenant-originalarrivaltime: 11 Sep 2019 23:38:20.3484 (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: 664EO/hRa6rCP40JGdUz1jgo5g+NZopQlDIlSOyvssUmRuue1ePPNip4gMnP1RJXJLB7qW0mg9/2c7qmFREUsw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN6PR2101MB1087 Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org Implement the suspend/resume callbacks for hibernation. hv_pci_suspend() needs to prevent any new work from being queued: a later patch will address this issue. Signed-off-by: Dexuan Cui --- drivers/pci/controller/pci-hyperv.c | 76 +++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) diff --git a/drivers/pci/controller/pci-hyperv.c b/drivers/pci/controller/pci-hyperv.c index 03fa039..3b77a3a 100644 --- a/drivers/pci/controller/pci-hyperv.c +++ b/drivers/pci/controller/pci-hyperv.c @@ -1398,6 +1398,23 @@ static void prepopulate_bars(struct hv_pcibus_device *hbus) spin_lock_irqsave(&hbus->device_list_lock, flags); + /* + * Clear the memory enable bit, in case it's already set. This occurs + * in the suspend path of hibernation, where the device is suspended, + * resumed and suspended again: see hibernation_snapshot() and + * hibernation_platform_enter(). + * + * If the memory enable bit is already set, Hyper-V sliently ignores + * the below BAR updates, and the related PCI device driver can not + * work, because reading from the device register(s) always returns + * 0xFFFFFFFF. + */ + list_for_each_entry(hpdev, &hbus->children, list_entry) { + _hv_pcifront_read_config(hpdev, PCI_COMMAND, 2, &command); + command &= ~PCI_COMMAND_MEMORY; + _hv_pcifront_write_config(hpdev, PCI_COMMAND, 2, command); + } + /* Pick addresses for the BARs. */ do { list_for_each_entry(hpdev, &hbus->children, list_entry) { @@ -2737,6 +2754,63 @@ static int hv_pci_remove(struct hv_device *hdev) return ret; } +static int hv_pci_suspend(struct hv_device *hdev) +{ + struct hv_pcibus_device *hbus = hv_get_drvdata(hdev); + int ret; + + /* XXX: Need to prevent any new work from being queued. */ + flush_workqueue(hbus->wq); + + ret = hv_pci_bus_exit(hdev, true); + if (ret) + return ret; + + vmbus_close(hdev->channel); + + return 0; +} + +static int hv_pci_resume(struct hv_device *hdev) +{ + struct hv_pcibus_device *hbus = hv_get_drvdata(hdev); + enum pci_protocol_version_t version[1]; + int ret; + + hbus->state = hv_pcibus_init; + + ret = vmbus_open(hdev->channel, pci_ring_size, pci_ring_size, NULL, 0, + hv_pci_onchannelcallback, hbus); + if (ret) + return ret; + + /* Only use the version that was in use before hibernation. */ + version[0] = pci_protocol_version; + ret = hv_pci_protocol_negotiation(hdev, version, 1); + if (ret) + goto out; + + ret = hv_pci_query_relations(hdev); + if (ret) + goto out; + + ret = hv_pci_enter_d0(hdev); + if (ret) + goto out; + + ret = hv_send_resources_allocated(hdev); + if (ret) + goto out; + + prepopulate_bars(hbus); + + hbus->state = hv_pcibus_installed; + return 0; +out: + vmbus_close(hdev->channel); + return ret; +} + static const struct hv_vmbus_device_id hv_pci_id_table[] = { /* PCI Pass-through Class ID */ /* 44C4F61D-4444-4400-9D52-802E27EDE19F */ @@ -2751,6 +2825,8 @@ static int hv_pci_remove(struct hv_device *hdev) .id_table = hv_pci_id_table, .probe = hv_pci_probe, .remove = hv_pci_remove, + .suspend = hv_pci_suspend, + .resume = hv_pci_resume, }; static void __exit exit_hv_pci_drv(void) From patchwork Wed Sep 11 23:38:21 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dexuan Cui X-Patchwork-Id: 11141953 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id F361A1599 for ; Wed, 11 Sep 2019 23:38:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C631420863 for ; Wed, 11 Sep 2019 23:38:31 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=microsoft.com header.i=@microsoft.com header.b="YpA5Db8J" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728956AbfIKXi1 (ORCPT ); Wed, 11 Sep 2019 19:38:27 -0400 Received: from mail-eopbgr690132.outbound.protection.outlook.com ([40.107.69.132]:35718 "EHLO NAM04-CO1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727659AbfIKXi1 (ORCPT ); Wed, 11 Sep 2019 19:38:27 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=XX/ULtzYVh72pt9xJmNZOx52cvA8TIvOIb1xej5Ht7R3DTUqNzpS9JtKv/Loj/Y5I3XhXwnpIw3EAv0PZ64TBI9NjfL0etxqhDyGTM+UtIVCwOOTwo1B7lYVexNMW7xNJaZi6t95Kv4aBS0NcrGgLULED+Z6AQ2XwYrTnJqx1b0h7FgBT12fcWRfcPkdew1v7ob3f443Uck+8pjJSRglwHQ13/yHO2TuHfmpPNH0DVtaJFNSthDivBi1VcXfXkghH2NDhSKkUVfLTbY/JYmuDe8V5E81ReD38nfeZ68MoW258g2GrGvo3B2E2ImJNdLuJl3E33Z+F4u3+XDdyQFHHA== 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=wUwVSOOzmPB8yKg//uWeoY+txIH+PriwlUrZ5oaqjZA=; b=k+fvA0DgKWIbLP9+eckJ0Gj1NTN6SU6CcV6usGAPOT55NX8wZSYFBqQQrNJ/aWnmv8kLqckPrd1sbnkemXU9pcDlYiu150SUp7xNcJPovGUCkyIWeFAdqj4L53fGDZrnTa0GRxolEpdnbuzhd4wi3j+jlFLuaU98l3h4hKvVChIeieqZ2ATWbDlQ+bqObbk3WRJz3ehSeOw8aRU+4ExZ/IlAXBU9rPwdpMM0+J9WOobVIHASVwlhS+yMOqm3UXinqcYIdAd9z1l1spz1ae0p36Ws6n4BSi6HvTPE2z/qBGZgIsARlWMAKlkQjm89XknBGNNvb1WbqyNvB/mcJm2Aig== 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=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=wUwVSOOzmPB8yKg//uWeoY+txIH+PriwlUrZ5oaqjZA=; b=YpA5Db8JZfKeB/1Az/ie0Ecde+dy4MfiOwrIpRI0ipajqLiXta9NQ9bfFMNqLdDa30N8DRBGUMvgH58sNCGXs/4KjaWDRLTR8OJdIZ2KGsn/eijjEX6YZUFj1K3H9vFMe6dRD7pNqSFZhLNUXQ8+82h7FQclTJMwGUPdBdv9PUk= Received: from SN6PR2101MB0942.namprd21.prod.outlook.com (52.132.114.19) by SN6PR2101MB1087.namprd21.prod.outlook.com (52.132.115.24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2284.7; Wed, 11 Sep 2019 23:38:22 +0000 Received: from SN6PR2101MB0942.namprd21.prod.outlook.com ([fe80::dd56:aa4f:204f:86a4]) by SN6PR2101MB0942.namprd21.prod.outlook.com ([fe80::dd56:aa4f:204f:86a4%3]) with mapi id 15.20.2263.005; Wed, 11 Sep 2019 23:38:22 +0000 From: Dexuan Cui To: KY Srinivasan , Haiyang Zhang , Stephen Hemminger , "sashal@kernel.org" , "lorenzo.pieralisi@arm.com" , "bhelgaas@google.com" , "linux-hyperv@vger.kernel.org" , "linux-pci@vger.kernel.org" , "linux-kernel@vger.kernel.org" , Michael Kelley CC: Dexuan Cui Subject: [PATCH 3/4] PCI: hv: Do not queue new work items on hibernation Thread-Topic: [PATCH 3/4] PCI: hv: Do not queue new work items on hibernation Thread-Index: AQHVaPn/cNR9IJtpNE6TYmXuPOiYYQ== Date: Wed, 11 Sep 2019 23:38:21 +0000 Message-ID: <1568245086-70601-4-git-send-email-decui@microsoft.com> References: <1568245086-70601-1-git-send-email-decui@microsoft.com> In-Reply-To: <1568245086-70601-1-git-send-email-decui@microsoft.com> Reply-To: Dexuan Cui Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: MWHPR19CA0072.namprd19.prod.outlook.com (2603:10b6:300:94::34) To SN6PR2101MB0942.namprd21.prod.outlook.com (2603:10b6:805:4::19) authentication-results: spf=none (sender IP is ) smtp.mailfrom=decui@microsoft.com; x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: git-send-email 1.8.3.1 x-originating-ip: [13.77.154.182] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: cd5d5c12-31ae-4993-51f2-08d737112181 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0;PCL:0;RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600166)(711020)(4605104)(1401327)(4618075)(2017052603328)(7193020);SRVR:SN6PR2101MB1087; x-ms-traffictypediagnostic: SN6PR2101MB1087:|SN6PR2101MB1087: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:2043; x-forefront-prvs: 0157DEB61B x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(4636009)(376002)(136003)(346002)(39860400002)(396003)(366004)(199004)(189003)(10290500003)(11346002)(2201001)(2501003)(256004)(7736002)(6436002)(305945005)(2906002)(14454004)(3846002)(2616005)(81156014)(81166006)(8936002)(50226002)(66066001)(26005)(8676002)(5660300002)(110136005)(6116002)(316002)(6512007)(66556008)(186003)(66946007)(86362001)(446003)(66446008)(6486002)(64756008)(66476007)(22452003)(71200400001)(476003)(71190400001)(107886003)(43066004)(25786009)(478600001)(14444005)(102836004)(6636002)(99286004)(1511001)(36756003)(4326008)(486006)(76176011)(53936002)(52116002)(3450700001)(6506007)(386003)(4720700003)(10090500001)(21314003)(921003)(1121003);DIR:OUT;SFP:1102;SCL:1;SRVR:SN6PR2101MB1087;H:SN6PR2101MB0942.namprd21.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;A:1;MX:1; received-spf: None (protection.outlook.com: microsoft.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: QBXfQXg4zjNvIilfHYTnCyBEftJhpenT+zazlYDQ40yq03UzBImzHs7Xuulri69DsQCmynzITeHD77yoAd7fa3cMq2U9LYIJHfYxvTaq3/0FADhKx4AKtFYGEHxFaOtLyWsnanDAr5Q1cJz1iSWDnihRl+J7nwleFVik+5ByDP5/a9xAjQRmSJj1SWbSm94JI8vd1+5qDfZevd6crsZF5UYJ+NdXJ6Jmm7iPQPxWDF6HrwkbDnVsYmZnaXX7KidhZ+TNLcGEEJZsRPONzMAIYVrOaSZqM8U38xhYFgVMnYujoscipfpzNW/FWXMiaSmSICkkmZeQ3VpD8XHCWYPqLtfabmjbnJmRShJvtxOD980kMcs+JK6h+WEqfWl8WX025YrbYZlbA3UODd5uTWq3+PGF3TYA3ZprALJkSbJHdHo= MIME-Version: 1.0 X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: cd5d5c12-31ae-4993-51f2-08d737112181 X-MS-Exchange-CrossTenant-originalarrivaltime: 11 Sep 2019 23:38:21.9075 (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: u/6Wts2uDJRFdziV2cCVrDMvQ3CLOvijdWUYeuUexpgIq4O/C7QC3V9E7FcYnGsfYeJ7hTkeTY7ocL72VA6ITg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN6PR2101MB1087 Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org We must make sure there is no pending work items before we call vmbus_close(). Signed-off-by: Dexuan Cui --- drivers/pci/controller/pci-hyperv.c | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/drivers/pci/controller/pci-hyperv.c b/drivers/pci/controller/pci-hyperv.c index 3b77a3a..2655df2 100644 --- a/drivers/pci/controller/pci-hyperv.c +++ b/drivers/pci/controller/pci-hyperv.c @@ -422,6 +422,7 @@ enum hv_pcibus_state { hv_pcibus_init = 0, hv_pcibus_probed, hv_pcibus_installed, + hv_pcibus_removing, hv_pcibus_removed, hv_pcibus_maximum }; @@ -1841,6 +1842,12 @@ static void hv_pci_devices_present(struct hv_pcibus_device *hbus, unsigned long flags; bool pending_dr; + if (hbus->state == hv_pcibus_removing) { + dev_info(&hbus->hdev->device, + "PCI VMBus BUS_RELATIONS: ignored\n"); + return; + } + dr_wrk = kzalloc(sizeof(*dr_wrk), GFP_NOWAIT); if (!dr_wrk) return; @@ -1957,11 +1964,19 @@ static void hv_eject_device_work(struct work_struct *work) */ static void hv_pci_eject_device(struct hv_pci_dev *hpdev) { + struct hv_pcibus_device *hbus = hpdev->hbus; + struct hv_device *hdev = hbus->hdev; + + if (hbus->state == hv_pcibus_removing) { + dev_info(&hdev->device, "PCI VMBus EJECT: ignored\n"); + return; + } + hpdev->state = hv_pcichild_ejecting; get_pcichild(hpdev); INIT_WORK(&hpdev->wrk, hv_eject_device_work); - get_hvpcibus(hpdev->hbus); - queue_work(hpdev->hbus->wq, &hpdev->wrk); + get_hvpcibus(hbus); + queue_work(hbus->wq, &hpdev->wrk); } /** @@ -2757,9 +2772,21 @@ static int hv_pci_remove(struct hv_device *hdev) static int hv_pci_suspend(struct hv_device *hdev) { struct hv_pcibus_device *hbus = hv_get_drvdata(hdev); + enum hv_pcibus_state old_state; int ret; - /* XXX: Need to prevent any new work from being queued. */ + tasklet_disable(&hdev->channel->callback_event); + + /* Change the hbus state to prevent new work items. */ + old_state = hbus->state; + if (hbus->state == hv_pcibus_installed) + hbus->state = hv_pcibus_removing; + + tasklet_enable(&hdev->channel->callback_event); + + if (old_state != hv_pcibus_installed) + return -EINVAL; + flush_workqueue(hbus->wq); ret = hv_pci_bus_exit(hdev, true); From patchwork Wed Sep 11 23:38:23 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dexuan Cui X-Patchwork-Id: 11141955 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 60064112B for ; Wed, 11 Sep 2019 23:38:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 29CAD20863 for ; Wed, 11 Sep 2019 23:38:35 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=microsoft.com header.i=@microsoft.com header.b="JP4xD+yP" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729384AbfIKXib (ORCPT ); Wed, 11 Sep 2019 19:38:31 -0400 Received: from mail-eopbgr690132.outbound.protection.outlook.com ([40.107.69.132]:35718 "EHLO NAM04-CO1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1729345AbfIKXia (ORCPT ); Wed, 11 Sep 2019 19:38:30 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=mHyuRCDV/MHXjio60hoc/4EROQdrXXfkYr3Zl00fQ2uLZwZZckcpl/+11Sag1bI+eKlZtJhg4P3JCB12aMJlx1RmL8ZGtRwhql1ornKOHTW0m7NUMpHsTVEkhuOGcNU2x/XkZcbWXMm5LyR0C7usJsqsiEVowAXzYYwiM1dupffzBDsopM+l0vSqAvLFm0pNPsMmKVjARuwwkyPEg+/KHKGUBno4m4VltpOZPZtqaKG2GE0rV5sOWFK6amoUCddiMyrs8XZLGdcDPmZhHjxwsTgbpAz3ERVl0iNQEr0HSI0Mei9I8jSf38TuuzExuqtKSIgMzRRD+PasXL/f/26vKg== 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=VwvGZPYQQ+QmtJQSstOMKl1M2qPluYhNpTF//MX3ZAI=; b=CO3nkfXHaEkmrYKS08UgpJYhfGoaxyivAuPrFNdD61X+pM6pI4eK7Ic+1aneo2ukIUZy/k8njmgOenQMJz4tjMEw+mH7EpVgBhDq7L0B42xrdiAsFG7bU87C0vgoDCsh0Zkl986j7g7EHgbH/5jQpWcPV0PN9SrB+zNwrZY97JWGqo9DUKE/u4xPz+49AghXdqS2yHqTA2KrtAVcvZpH7zlNsk8UQMQs/6XvIM6pDxRweT8Rh+QSPkg+BtXohiQ5gCZX12RckZI1f1QQY6LXe+GPUaejZ1KQB5m2tMZWPG92sxETMXbIMfp7ibKffyXFQmvNiuyyKdZXcvt8gMn/0w== 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=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=VwvGZPYQQ+QmtJQSstOMKl1M2qPluYhNpTF//MX3ZAI=; b=JP4xD+yPq0T0R8XR0ilgWl5rYix1a5s9HHNcZpMiegf93/cviFCRLhnnWyLqf1lZcQC1LBqJlTlZaVWXHliPj5OehIDOTK891WDcU2V8GVuEbziPdgEEcLcUoXjqGMxD1lYcAKzSf0ffAOQB123n46z3+laOAd2M6FMzetjTcss= Received: from SN6PR2101MB0942.namprd21.prod.outlook.com (52.132.114.19) by SN6PR2101MB1087.namprd21.prod.outlook.com (52.132.115.24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2284.7; Wed, 11 Sep 2019 23:38:23 +0000 Received: from SN6PR2101MB0942.namprd21.prod.outlook.com ([fe80::dd56:aa4f:204f:86a4]) by SN6PR2101MB0942.namprd21.prod.outlook.com ([fe80::dd56:aa4f:204f:86a4%3]) with mapi id 15.20.2263.005; Wed, 11 Sep 2019 23:38:23 +0000 From: Dexuan Cui To: KY Srinivasan , Haiyang Zhang , Stephen Hemminger , "sashal@kernel.org" , "lorenzo.pieralisi@arm.com" , "bhelgaas@google.com" , "linux-hyperv@vger.kernel.org" , "linux-pci@vger.kernel.org" , "linux-kernel@vger.kernel.org" , Michael Kelley CC: Dexuan Cui Subject: [PATCH 4/4] PCI: hv: Change pci_protocol_version to per-hbus Thread-Topic: [PATCH 4/4] PCI: hv: Change pci_protocol_version to per-hbus Thread-Index: AQHVaPoAFdEKC5iwakqGSO4n9CfPoQ== Date: Wed, 11 Sep 2019 23:38:23 +0000 Message-ID: <1568245086-70601-5-git-send-email-decui@microsoft.com> References: <1568245086-70601-1-git-send-email-decui@microsoft.com> In-Reply-To: <1568245086-70601-1-git-send-email-decui@microsoft.com> Reply-To: Dexuan Cui Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: MWHPR19CA0072.namprd19.prod.outlook.com (2603:10b6:300:94::34) To SN6PR2101MB0942.namprd21.prod.outlook.com (2603:10b6:805:4::19) authentication-results: spf=none (sender IP is ) smtp.mailfrom=decui@microsoft.com; x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: git-send-email 1.8.3.1 x-originating-ip: [13.77.154.182] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 641a4b42-a458-4149-49b3-08d73711229b x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0;PCL:0;RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600166)(711020)(4605104)(1401327)(4618075)(2017052603328)(7193020);SRVR:SN6PR2101MB1087; x-ms-traffictypediagnostic: SN6PR2101MB1087:|SN6PR2101MB1087: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:4714; x-forefront-prvs: 0157DEB61B x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(4636009)(376002)(136003)(346002)(39860400002)(396003)(366004)(199004)(189003)(10290500003)(11346002)(2201001)(2501003)(256004)(7736002)(6436002)(305945005)(2906002)(14454004)(3846002)(2616005)(81156014)(81166006)(8936002)(50226002)(66066001)(26005)(8676002)(5660300002)(110136005)(6116002)(316002)(6512007)(66556008)(186003)(66946007)(86362001)(446003)(66446008)(6486002)(64756008)(66476007)(22452003)(71200400001)(476003)(71190400001)(107886003)(43066004)(25786009)(478600001)(14444005)(102836004)(6636002)(99286004)(1511001)(36756003)(4326008)(486006)(76176011)(53936002)(52116002)(3450700001)(6506007)(386003)(4720700003)(10090500001)(921003)(1121003);DIR:OUT;SFP:1102;SCL:1;SRVR:SN6PR2101MB1087;H:SN6PR2101MB0942.namprd21.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;A:1;MX:1; received-spf: None (protection.outlook.com: microsoft.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: 1fxsbW9tHbAaMqi9QoRcz9jN++hBndQxKAC379aU9Jsv3wDqqnBmy/436IRhpJYgMQE9Z5PpwyL7CX+VkoO6RltNvsw6I6MjjiOI7XzNNz/KyLasfDjr6Eb54z40qej/QuKTI9oHxCQqVebma0VpqY/4yZyVHpB58LKYjDhSzKAr9LnRg1RPqVsvtg/OBSM12tltO9xVYcRq+TPnVLEtwtOTd7GrAeLtIn2LFrbYtw0JW8rUIQt12hbbPdJNK5uKXq7JDpyop5QmkW4bIuy7y+boGSxeC4vF8A6g8EIM4QsIbBwte6XXCe15pQKlbOc5ugIpb8BqWuZkq93fhdkt0pVsAn3GkhjrwnNA7D+TOo2gz2f6KqMcsArxxgAzPmWLlUbrC3MKNHplK8Q+mMOUcx+hr9w76/qJmfdyzW7BYqM= MIME-Version: 1.0 X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: 641a4b42-a458-4149-49b3-08d73711229b X-MS-Exchange-CrossTenant-originalarrivaltime: 11 Sep 2019 23:38:23.3376 (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: GbAnGWRftTKDca6wOOC0joVMLEU9fHHAs/gRbhEH8SpFt1fOsOQyJ/40lu7JvaYLIfWboujut2BtsXnX6/nz3Q== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN6PR2101MB1087 Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org A VM can have multiple hbus. It looks incorrect for the second hbus's hv_pci_protocol_negotiation() to set the global variable 'pci_protocol_version' (which was set by the first hbus), even if the same value is written. Signed-off-by: Dexuan Cui --- drivers/pci/controller/pci-hyperv.c | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/drivers/pci/controller/pci-hyperv.c b/drivers/pci/controller/pci-hyperv.c index 2655df2..55730c5 100644 --- a/drivers/pci/controller/pci-hyperv.c +++ b/drivers/pci/controller/pci-hyperv.c @@ -76,11 +76,6 @@ enum pci_protocol_version_t { PCI_PROTOCOL_VERSION_1_1, }; -/* - * Protocol version negotiated by hv_pci_protocol_negotiation(). - */ -static enum pci_protocol_version_t pci_protocol_version; - #define PCI_CONFIG_MMIO_LENGTH 0x2000 #define CFG_PAGE_OFFSET 0x1000 #define CFG_PAGE_SIZE (PCI_CONFIG_MMIO_LENGTH - CFG_PAGE_OFFSET) @@ -429,6 +424,8 @@ enum hv_pcibus_state { struct hv_pcibus_device { struct pci_sysdata sysdata; + /* Protocol version negotiated with the host */ + enum pci_protocol_version_t protocol_version; enum hv_pcibus_state state; refcount_t remove_lock; struct hv_device *hdev; @@ -942,7 +939,7 @@ static void hv_irq_unmask(struct irq_data *data) * negative effect (yet?). */ - if (pci_protocol_version >= PCI_PROTOCOL_VERSION_1_2) { + if (hbus->protocol_version >= PCI_PROTOCOL_VERSION_1_2) { /* * PCI_PROTOCOL_VERSION_1_2 supports the VP_SET version of the * HVCALL_RETARGET_INTERRUPT hypercall, which also coincides @@ -1112,7 +1109,7 @@ static void hv_compose_msi_msg(struct irq_data *data, struct msi_msg *msg) ctxt.pci_pkt.completion_func = hv_pci_compose_compl; ctxt.pci_pkt.compl_ctxt = ∁ - switch (pci_protocol_version) { + switch (hbus->protocol_version) { case PCI_PROTOCOL_VERSION_1_1: size = hv_compose_msi_req_v1(&ctxt.int_pkts.v1, dest, @@ -2116,6 +2113,7 @@ static int hv_pci_protocol_negotiation(struct hv_device *hdev, enum pci_protocol_version_t version[], int num_version) { + struct hv_pcibus_device *hbus = hv_get_drvdata(hdev); struct pci_version_request *version_req; struct hv_pci_compl comp_pkt; struct pci_packet *pkt; @@ -2155,10 +2153,10 @@ static int hv_pci_protocol_negotiation(struct hv_device *hdev, } if (comp_pkt.completion_status >= 0) { - pci_protocol_version = version[i]; + hbus->protocol_version = version[i]; dev_info(&hdev->device, "PCI VMBus probing: Using version %#x\n", - pci_protocol_version); + hbus->protocol_version); goto exit; } @@ -2442,7 +2440,7 @@ static int hv_send_resources_allocated(struct hv_device *hdev) u32 wslot; int ret; - size_res = (pci_protocol_version < PCI_PROTOCOL_VERSION_1_2) + size_res = (hbus->protocol_version < PCI_PROTOCOL_VERSION_1_2) ? sizeof(*res_assigned) : sizeof(*res_assigned2); pkt = kmalloc(sizeof(*pkt) + size_res, GFP_KERNEL); @@ -2461,7 +2459,7 @@ static int hv_send_resources_allocated(struct hv_device *hdev) pkt->completion_func = hv_pci_generic_compl; pkt->compl_ctxt = &comp_pkt; - if (pci_protocol_version < PCI_PROTOCOL_VERSION_1_2) { + if (hbus->protocol_version < PCI_PROTOCOL_VERSION_1_2) { res_assigned = (struct pci_resources_assigned *)&pkt->message; res_assigned->message_type.type = @@ -2812,7 +2810,7 @@ static int hv_pci_resume(struct hv_device *hdev) return ret; /* Only use the version that was in use before hibernation. */ - version[0] = pci_protocol_version; + version[0] = hbus->protocol_version; ret = hv_pci_protocol_negotiation(hdev, version, 1); if (ret) goto out;