From patchwork Wed Nov 20 07:16:55 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dexuan Cui X-Patchwork-Id: 1197937 X-Patchwork-Delegate: lorenzo.pieralisi@arm.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; 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.b="fixvOOjY"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 47HvCs4w79z9sPc for ; Wed, 20 Nov 2019 18:17:45 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727869AbfKTHRV (ORCPT ); Wed, 20 Nov 2019 02:17:21 -0500 Received: from mail-eopbgr720133.outbound.protection.outlook.com ([40.107.72.133]:51631 "EHLO NAM05-CO1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727175AbfKTHRU (ORCPT ); Wed, 20 Nov 2019 02:17:20 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=FljHz+jx7IYOjrcJzrsyXUHsK53gOwq4iIRU8yi8iqhpI0+R0jTPVsPUFAhGZLhWjEIQM6ds4yr0nyJFndNPSd+LjASe+UupzIgX8wVuX2A22KERka4gYtk8NzPTtpcN1IoWDQjsoTmYwo4YZSpkDZd4/RbyqoPrfXk/wimMhce42oJ6g+K88ar0FF/CM6wCNHsOHdw6kQZggTChynn84zj+C5tenWr/Fqh4wyNA0cob1QuoTrQCRNdiyDNECvQ+NC0s2uomWcfOBFla61E4liD0MlGwPj0idIthoq82vsVPpxtceZv3Gr9IcDC2LYKoKG7kYjNMp/UzHI4dDOzp4Q== 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=n9IMnM1ZPlUAuAQe0sfSNqTZkAVsThpCLoezmc5eCMI=; b=LqfQ4XF4JFaKGg2zP73MT3xrKsxMVTXikqnNqdgMiUZ2atL4NjhTDm2aHCXuD2niB2m66iA9zM8JgvFutUMzLouQNecPhtfCKydujHjf0XolfCk0oE8xI0gWaw9GQ+2HWgDXqQgfL+se/J/WKd/BtfG2/EhtpJI/3PmZr6+PAJ4HFBGiTz/zGT9LXb5BtWa5Ljf/Ac4HXW4sqzbsDERH2o4LiMOfBIb/x2jSLM0jAz9dc3DS8kE8Ho+kjMchUFMQenozV9Yrwrgu4oYxdH7rm0Gt+sYYkmRC3QMISRFMLqF2nY4oRUUJi41GxEdQxifxjkLpRqVyp0qNBEs28nHOew== 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=n9IMnM1ZPlUAuAQe0sfSNqTZkAVsThpCLoezmc5eCMI=; b=fixvOOjYu1CrA2HShnGzkiW4YyziIlY+5oITlxRRIa512cYZjMNO9D9utsVzxlisDQw6+kPVzc6Iw5PBfywrlO0MVDh4RX3GCs7WiyK4hUy1mD1GyeiXlxTjx65jCrNiYforwPT+WySyQ1l6YsdnX+k7htBqln6LrRQeDcpC660= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=decui@microsoft.com; Received: from BN8PR21MB1137.namprd21.prod.outlook.com (20.179.72.96) by BN8PR21MB1251.namprd21.prod.outlook.com (20.179.74.28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2495.3; Wed, 20 Nov 2019 07:17:17 +0000 Received: from BN8PR21MB1137.namprd21.prod.outlook.com ([fe80::c596:ecf5:7a6:734d]) by BN8PR21MB1137.namprd21.prod.outlook.com ([fe80::c596:ecf5:7a6:734d%2]) with mapi id 15.20.2495.006; Wed, 20 Nov 2019 07:17:17 +0000 From: Dexuan Cui To: kys@microsoft.com, haiyangz@microsoft.com, sthemmin@microsoft.com, 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, mikelley@microsoft.com, Alexander.Levin@microsoft.com Cc: Dexuan Cui Subject: [PATCH v2 1/4] PCI: hv: Reorganize the code in preparation of hibernation Date: Tue, 19 Nov 2019 23:16:55 -0800 Message-Id: <1574234218-49195-2-git-send-email-decui@microsoft.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1574234218-49195-1-git-send-email-decui@microsoft.com> References: <1574234218-49195-1-git-send-email-decui@microsoft.com> Reply-To: decui@microsoft.com X-ClientProxiedBy: MWHPR2001CA0022.namprd20.prod.outlook.com (2603:10b6:301:15::32) To BN8PR21MB1137.namprd21.prod.outlook.com (2603:10b6:408:71::32) MIME-Version: 1.0 Received: from linuxonhyperv3.guj3yctzbm1etfxqx2vob5hsef.xx.internal.cloudapp.net (13.77.154.182) by MWHPR2001CA0022.namprd20.prod.outlook.com (2603:10b6:301:15::32) with Microsoft SMTP Server (version=TLS1_2, cipher=) via Frontend Transport; Wed, 20 Nov 2019 07:17:15 +0000 X-Mailer: git-send-email 1.8.3.1 X-Originating-IP: [13.77.154.182] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 9edbb00b-4c5c-4c30-f389-08d76d89ac8e X-MS-TrafficTypeDiagnostic: BN8PR21MB1251:|BN8PR21MB1251: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:3826; X-Forefront-PRVS: 02272225C5 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(376002)(346002)(396003)(136003)(39860400002)(366004)(199004)(189003)(10090500001)(36756003)(8936002)(50226002)(81166006)(81156014)(8676002)(14444005)(6436002)(6486002)(1511001)(86362001)(7736002)(2906002)(5660300002)(478600001)(10290500003)(4720700003)(6636002)(3846002)(6116002)(25786009)(3450700001)(66946007)(66556008)(66476007)(305945005)(316002)(386003)(6666004)(4326008)(6506007)(22452003)(26005)(16586007)(186003)(16526019)(107886003)(76176011)(51416003)(52116002)(66066001)(48376002)(47776003)(50466002)(446003)(11346002)(43066004)(956004)(2616005)(476003)(486006)(6512007)(921003)(1121003); DIR:OUT; SFP:1102; SCL:1; SRVR:BN8PR21MB1251; H:BN8PR21MB1137.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: BCL:0; X-Microsoft-Antispam-Message-Info: h+TOfimj/W705YRii+naDzdZDKyx9GbCSrI407O4rwirYaGLwU8nFxd327/zXLBkEWNqxaj8tSUxyjKsjeCiltnBqyt2eKoAMoD6NhBIxZUKtzHNM5/Cp4wM18jm+09MtZzPYAaDi8eqPXzjEl3hbk0q7PhFXrC9RcOsYxLBtHvunbftALo8oVI64v5hsib5jnKYhgU4NAHInajzF+5IoicU0rk5MCeVZkRrJA8ZR1lmDF7WYNzLEInDOBhzOIElmZLKKYhykbOW3vpgnE2NRQLSK7G4FDzkdum7yOvg1UZh3LYNe6aQaGoJbQYtlWZuAcGF6+3yoykXfMSsBpadcZeXNSA3JTQxrcs0apAg561+XcaVl6dzT9UZ4M5AkEcBgY1sQATmv3KKfc/Tkg8bDcLab7I4jN3gdq9H8SBYxRXamMd66TXo53ArcUIsiCCn X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: 9edbb00b-4c5c-4c30-f389-08d76d89ac8e X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Nov 2019 07:17:17.2333 (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: OpiukM9nJ+CtOvLojAxotg0zPjHBYdgFxO5v6FEdh9uo18W/xOkxOJjwJj0MULY7lFZKcUniZZXNWCDYs6tScw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN8PR21MB1251 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 Reviewed-by: Michael Kelley --- No change in v2. 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 f1f300218fab..65f18f840ce9 100644 --- a/drivers/pci/controller/pci-hyperv.c +++ b/drivers/pci/controller/pci-hyperv.c @@ -2379,7 +2379,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; @@ -2403,8 +2405,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, @@ -2420,7 +2422,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); @@ -2930,7 +2932,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; @@ -3011,7 +3014,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 { @@ -3027,16 +3030,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); @@ -3049,8 +3056,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; } /** @@ -3062,6 +3074,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) { @@ -3074,7 +3087,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); @@ -3091,7 +3104,7 @@ static int hv_pci_remove(struct hv_device *hdev) hv_put_dom_num(hbus->sysdata.domain); free_page((unsigned long)hbus); - return 0; + return ret; } static const struct hv_vmbus_device_id hv_pci_id_table[] = { From patchwork Wed Nov 20 07:16:56 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dexuan Cui X-Patchwork-Id: 1197936 X-Patchwork-Delegate: lorenzo.pieralisi@arm.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; 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.b="JvIjHJks"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 47HvCg59zKz9sPv for ; Wed, 20 Nov 2019 18:17:35 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727887AbfKTHRX (ORCPT ); Wed, 20 Nov 2019 02:17:23 -0500 Received: from mail-eopbgr720133.outbound.protection.outlook.com ([40.107.72.133]:51631 "EHLO NAM05-CO1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727670AbfKTHRW (ORCPT ); Wed, 20 Nov 2019 02:17:22 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=bBl+K/S4vYmfsBdQ/tyymdFRPNlmFznfiGHTtKWvAXHM5JoDkUwQ286u/qWSCoWeNi1zCz1HaUZXU0p7AwufuakSwyGjjB/ejtoo3ihFWWoT1hzz/RGwxWqTlTMThTqC75o0+uejbwznSE4fCtMR6zJeX96OMnV2PWGFQLhXewT1T7xXoaISMAIT98ypRs9EcT1dROebRUmF2/juH63VfShqhLLhggH4qDZf5njZHbn6g/Fh+01WRpu3jMKhMSQHHMrgFlk9C0hL6fGaFGpY9Pugdd9pAJo4VtFd7c2pO8oGnhcx2lP4Ed9ytam+LK9nkXRLGx9dlqUph8RyD4rUdA== 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=QecmJbecI4m5UIXgnD35Z33oc/QS05Ga5gawtJStTZc=; b=fO3SdOTwgei6FtSwWemEoIoL4/PR1oIx9hWtKNiGg2FKjcODjTarQjPrOnSPeVaAnyBtF4tvKew+CqkswZRKZmIBKQtnmSjBRF8Na4jQUr/QTSXnPUx/k05u8S4Bc4HJTTEO0cb6zlr0pEfAKPHSwUmwyaAbuSGp0yo0Sl2jcmPMWXCL2/QzCHn4KDOUkRo9eLz2i3wX7uFKTQmUzjvhDYf6HH7PgNKK2WhyLSRKUnVCWMNJXqUPJUsvQ3GlRPsd3cIRPVe39vMNtwpT3FiPEQE3Igeq7PeOSY8wMuzlAiID72XtG7UXNyl9EAzMG7d/HajUd7xD0fsq+KCOdtpHFg== 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=QecmJbecI4m5UIXgnD35Z33oc/QS05Ga5gawtJStTZc=; b=JvIjHJkslOnrJRlfHz9HePG1Mb5OFzrnLqq/CKh89QtVwL7WvfDwofwZlXdPQiTsCdvPpgE/QaOIvmnYs7tyaEf3Fj2keHSEP/8mQvhXrK8XG/TmqQrcTlXuFXKJp3XLPmA8nhykc8BiZtWxJDGE1NOcVK4VJwikBLMc/Fv5q94= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=decui@microsoft.com; Received: from BN8PR21MB1137.namprd21.prod.outlook.com (20.179.72.96) by BN8PR21MB1251.namprd21.prod.outlook.com (20.179.74.28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2495.3; Wed, 20 Nov 2019 07:17:18 +0000 Received: from BN8PR21MB1137.namprd21.prod.outlook.com ([fe80::c596:ecf5:7a6:734d]) by BN8PR21MB1137.namprd21.prod.outlook.com ([fe80::c596:ecf5:7a6:734d%2]) with mapi id 15.20.2495.006; Wed, 20 Nov 2019 07:17:18 +0000 From: Dexuan Cui To: kys@microsoft.com, haiyangz@microsoft.com, sthemmin@microsoft.com, 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, mikelley@microsoft.com, Alexander.Levin@microsoft.com Cc: Dexuan Cui Subject: [PATCH v2 2/4] PCI: hv: Add the support of hibernation Date: Tue, 19 Nov 2019 23:16:56 -0800 Message-Id: <1574234218-49195-3-git-send-email-decui@microsoft.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1574234218-49195-1-git-send-email-decui@microsoft.com> References: <1574234218-49195-1-git-send-email-decui@microsoft.com> Reply-To: decui@microsoft.com X-ClientProxiedBy: MWHPR2001CA0022.namprd20.prod.outlook.com (2603:10b6:301:15::32) To BN8PR21MB1137.namprd21.prod.outlook.com (2603:10b6:408:71::32) MIME-Version: 1.0 Received: from linuxonhyperv3.guj3yctzbm1etfxqx2vob5hsef.xx.internal.cloudapp.net (13.77.154.182) by MWHPR2001CA0022.namprd20.prod.outlook.com (2603:10b6:301:15::32) with Microsoft SMTP Server (version=TLS1_2, cipher=) via Frontend Transport; Wed, 20 Nov 2019 07:17:17 +0000 X-Mailer: git-send-email 1.8.3.1 X-Originating-IP: [13.77.154.182] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 17d8c894-c9fe-4c03-e6d8-08d76d89ad6b X-MS-TrafficTypeDiagnostic: BN8PR21MB1251:|BN8PR21MB1251: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:8882; X-Forefront-PRVS: 02272225C5 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(376002)(346002)(396003)(136003)(39860400002)(366004)(199004)(189003)(10090500001)(36756003)(8936002)(50226002)(81166006)(81156014)(8676002)(14444005)(6436002)(6486002)(1511001)(86362001)(7736002)(2906002)(5660300002)(478600001)(10290500003)(4720700003)(6636002)(3846002)(6116002)(25786009)(3450700001)(66946007)(66556008)(66476007)(305945005)(316002)(386003)(6666004)(4326008)(6506007)(22452003)(26005)(16586007)(186003)(16526019)(107886003)(76176011)(51416003)(52116002)(66066001)(48376002)(47776003)(50466002)(446003)(11346002)(43066004)(956004)(2616005)(476003)(486006)(6512007)(921003)(1121003); DIR:OUT; SFP:1102; SCL:1; SRVR:BN8PR21MB1251; H:BN8PR21MB1137.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: BCL:0; X-Microsoft-Antispam-Message-Info: WuOMyEb/BeQlcapCJR1LSb1XpUtNER3T/sgd61CZdZC+Y7PACrn5y9OQvaBMH3rw4eNg6CWZfiRS5xLNSQVxWGZ+IxfijaBdeO0pvmW1TM3YSgM6iMr8YgB38mYHxlgYhIZkhdlOu0Mj4KJnmwVpr8AlEdkHTe21mdcqVNE4jwskW8W702J01b3VMFBFbaKcqckmZ2L64hWM8HV4bGnVxKnB5zbuDEOaVrzclm/eNtS4KJ9Vh+a4mXvCDI5ZnULXRBdjrsd96OUCe7XRgE8O9m74R2qcsH7uiDtvV1sOfWQwidIBhjTQBSfIkI2pTrMHuC7G9Wnu2DTfBbbfA3XdS4AIrmwDaycK7RrhA4TvwZTsAzCdGbGCoZTB4CgsACZvWwRUdfnwH5QrQpYz0+eGzerP6ct6t47ki4gxq9k8pVqXJz2UMj3FPToRtqyroiP9 X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: 17d8c894-c9fe-4c03-e6d8-08d76d89ad6b X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Nov 2019 07:17:18.6823 (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: dUlEFDMdPsiwm8UQogxw0zoLrs1Tgcwf0f5Q2UcPcxsc1u2SmKjPqome6Fm+XTKhAKXG5S1s7TEf2P1FFM/AgQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN8PR21MB1251 Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org Implement the suspend/resume callbacks. We must make sure there is no pending work items before we call vmbus_close(). Signed-off-by: Dexuan Cui --- Changes in v2: this patch is a simple merge of 2 previous smaller patches, accordign to the suggestion of Lorenzo Pieralisi . drivers/pci/controller/pci-hyperv.c | 107 +++++++++++++++++++++++++++- 1 file changed, 105 insertions(+), 2 deletions(-) diff --git a/drivers/pci/controller/pci-hyperv.c b/drivers/pci/controller/pci-hyperv.c index 65f18f840ce9..e71eb6e0bfdd 100644 --- a/drivers/pci/controller/pci-hyperv.c +++ b/drivers/pci/controller/pci-hyperv.c @@ -455,6 +455,7 @@ enum hv_pcibus_state { hv_pcibus_init = 0, hv_pcibus_probed, hv_pcibus_installed, + hv_pcibus_removing, hv_pcibus_removed, hv_pcibus_maximum }; @@ -1681,6 +1682,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) { @@ -2107,6 +2125,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; @@ -2223,11 +2247,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); } /** @@ -3107,6 +3139,75 @@ 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); + enum hv_pcibus_state old_state; + int ret; + + 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); + 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 */ @@ -3121,6 +3222,8 @@ static struct hv_driver hv_pci_drv = { .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 Nov 20 07:16:57 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dexuan Cui X-Patchwork-Id: 1197934 X-Patchwork-Delegate: lorenzo.pieralisi@arm.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; 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.b="a4DbWPHb"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 47HvCW5x0kz9sPc for ; Wed, 20 Nov 2019 18:17:27 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727903AbfKTHRZ (ORCPT ); Wed, 20 Nov 2019 02:17:25 -0500 Received: from mail-eopbgr720133.outbound.protection.outlook.com ([40.107.72.133]:51631 "EHLO NAM05-CO1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727175AbfKTHRZ (ORCPT ); Wed, 20 Nov 2019 02:17:25 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Khb9Gno50KEp7+JVEMyrdif5SYPdWDoZPTXXaqC0TCcMfWb4zmYWctD3dVI5XEtb0JJX1y4f41jtz2s8o4eaIBo92WabuvYLV2y3ogrE0MjuzBmS2nGFaJPIjlLMpvHRXTR63z65lMzBhDcKvHL0gZEM3csKChBeJSUgg589yFxhachBPjyFdexPDnuSpH1+ejDxfTSN76t4JrVMksNssVg44JeDsf6aqzA83gwg9SYHWw1DAIlMrKw/lV74p82mhJN4RAV1YoGnJeLHQkhMUgMRGgEqKfB2aLVowVuX8AQmX6C1xsglko5YjxlnWGR+N8ocm04ov7EO7iAn5LwWRw== 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=cL1RFQTRnF5ayLm4bMmyJ37tBq6H+wHVCPEN/ID/wcI=; b=FTqfpDkhsR/YWltWMSuy8WCtPDQvF0Zdch+oQtGEKgT8kgTsQkLoceIM+KBQGPzyUmaJk1z1yx13KDcpfdbjykzITPpRnUiSKrBNV9M5G8v1aGT9wbFOCubDMzQknH6W55IOeO3csRdsV7oE8arktQo9ZP8zOiS49zDsO/1ZZvdBixujDID9vuVMv2+CKLtZxvrRNMkLNgpCwC7YDlolNXSc5zX6xKl3mIMfarV9tLaEb33BSWG/MneIXzWJaCRG5hWWBd6j78g44+hTqV66zjxZ2aX40CWn2VbF2EhDee9z3cxOYtGQOFBrxVNZuOAuCeUc4AgzvAL7aec4vv6Ajg== 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=cL1RFQTRnF5ayLm4bMmyJ37tBq6H+wHVCPEN/ID/wcI=; b=a4DbWPHbFteg77noxHkLtKneoIbPw2VT6nyyM9XyzGSvS+kKdtCJCYHpz0tSzzTK6KFLj6kaAg6z9NAg6F4XN1u2pDVzhW8GwT5GKVU6VD3Oy7fCCGGDkIhHw9y8HvxhdzoIi+BYEdqY3DFfcle1s+w4kn0/iABizVjr8VtotL0= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=decui@microsoft.com; Received: from BN8PR21MB1137.namprd21.prod.outlook.com (20.179.72.96) by BN8PR21MB1251.namprd21.prod.outlook.com (20.179.74.28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2495.3; Wed, 20 Nov 2019 07:17:20 +0000 Received: from BN8PR21MB1137.namprd21.prod.outlook.com ([fe80::c596:ecf5:7a6:734d]) by BN8PR21MB1137.namprd21.prod.outlook.com ([fe80::c596:ecf5:7a6:734d%2]) with mapi id 15.20.2495.006; Wed, 20 Nov 2019 07:17:20 +0000 From: Dexuan Cui To: kys@microsoft.com, haiyangz@microsoft.com, sthemmin@microsoft.com, 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, mikelley@microsoft.com, Alexander.Levin@microsoft.com Cc: Dexuan Cui Subject: [PATCH v2 3/4] PCI: hv: Change pci_protocol_version to per-hbus Date: Tue, 19 Nov 2019 23:16:57 -0800 Message-Id: <1574234218-49195-4-git-send-email-decui@microsoft.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1574234218-49195-1-git-send-email-decui@microsoft.com> References: <1574234218-49195-1-git-send-email-decui@microsoft.com> Reply-To: decui@microsoft.com X-ClientProxiedBy: MWHPR2001CA0022.namprd20.prod.outlook.com (2603:10b6:301:15::32) To BN8PR21MB1137.namprd21.prod.outlook.com (2603:10b6:408:71::32) MIME-Version: 1.0 Received: from linuxonhyperv3.guj3yctzbm1etfxqx2vob5hsef.xx.internal.cloudapp.net (13.77.154.182) by MWHPR2001CA0022.namprd20.prod.outlook.com (2603:10b6:301:15::32) with Microsoft SMTP Server (version=TLS1_2, cipher=) via Frontend Transport; Wed, 20 Nov 2019 07:17:18 +0000 X-Mailer: git-send-email 1.8.3.1 X-Originating-IP: [13.77.154.182] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: f33a61fd-a3d4-42d9-12e3-08d76d89ae4a X-MS-TrafficTypeDiagnostic: BN8PR21MB1251:|BN8PR21MB1251: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:8273; X-Forefront-PRVS: 02272225C5 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(376002)(346002)(396003)(136003)(39860400002)(366004)(199004)(189003)(54534003)(10090500001)(36756003)(8936002)(50226002)(81166006)(81156014)(8676002)(14444005)(6436002)(6486002)(1511001)(86362001)(7736002)(2906002)(5660300002)(478600001)(10290500003)(4720700003)(6636002)(3846002)(6116002)(25786009)(3450700001)(66946007)(66556008)(66476007)(305945005)(316002)(386003)(6666004)(4326008)(6506007)(22452003)(26005)(16586007)(186003)(16526019)(107886003)(76176011)(51416003)(52116002)(66066001)(48376002)(47776003)(50466002)(446003)(11346002)(43066004)(956004)(2616005)(476003)(486006)(6512007)(921003)(1121003); DIR:OUT; SFP:1102; SCL:1; SRVR:BN8PR21MB1251; H:BN8PR21MB1137.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: BCL:0; X-Microsoft-Antispam-Message-Info: nBXouDfOGn7ho25OxX4R9rHR82YM1/irY1BP+kJ7qTv3BAmtxqAqes3ZlFN1W7sRiUd+roUr+hSdBWsCzYbkCRXQybqu3pRDIIzuCWrM5JPS9NoOydNHcBaPRgKQwlJ1+clyWv55AUJTlD9VObCN07+XYMMzL/PVXZZVHjw2j0Dt54AI0NupWZD9OvMXCOHQRZZ/QuPJcdsblo51zioQOixVlq132/FfKRtP/uJjEDbNVfa0ua1huhG4kYvFsseYbH8NPuhjt44mI+SyzXTb3zevPtAi0TcUToYgqTIt3e2zw4MR9YOv2fGB053qZ1+d388XW4H4Gj06OIZ4yJBSVsR4aVjRSyacQ4LOp02TZIka0axChO0Q5AQ3R5wrDwVP6Ij3c9HYfnOWx7NAvSvAQx3KHYn44bFSEsJuPpCYObw/dWflly+zdARdSDUCNA4L X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: f33a61fd-a3d4-42d9-12e3-08d76d89ae4a X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Nov 2019 07:17:20.1373 (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: bb9iKIMChth9X7o06dg/4VCWeuu+0B++NN5QxhCXwmnqjwUYV9GNxAeWqLrPou+PeBBkc7+HEnhNtdhXYPDFvA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN8PR21MB1251 Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org A VM can have multiple Hyper-V hbus. It's incorrect to set the global variable 'pci_protocol_version' when *every* hbus is initialized in hv_pci_protocol_negotiation(). This is not an issue in practice since every hbus should have the same value of hbus->protocol_version, but we should make the variable per-hbus, so in case we have busses with different protocol_versions, the driver can still work correctly. Signed-off-by: Dexuan Cui Reviewed-by: Michael Kelley --- changes in v2: Improved the changelog by making it clear that this patch fixes a potential bug if we have busses with different protocol_versions. 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 e71eb6e0bfdd..d7e05d436b5e 100644 --- a/drivers/pci/controller/pci-hyperv.c +++ b/drivers/pci/controller/pci-hyperv.c @@ -76,11 +76,6 @@ static enum pci_protocol_version_t pci_protocol_versions[] = { 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) @@ -462,6 +457,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; @@ -1225,7 +1222,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 @@ -1395,7 +1392,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, @@ -2415,6 +2412,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; @@ -2454,10 +2452,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; } @@ -2741,7 +2739,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); @@ -2760,7 +2758,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 = @@ -3182,7 +3180,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; From patchwork Wed Nov 20 07:16:58 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dexuan Cui X-Patchwork-Id: 1197935 X-Patchwork-Delegate: lorenzo.pieralisi@arm.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; 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.b="JtWbtlEv"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 47HvCc0KKjz9sPv for ; Wed, 20 Nov 2019 18:17:31 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727918AbfKTHRa (ORCPT ); Wed, 20 Nov 2019 02:17:30 -0500 Received: from mail-eopbgr720133.outbound.protection.outlook.com ([40.107.72.133]:51631 "EHLO NAM05-CO1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727670AbfKTHR0 (ORCPT ); Wed, 20 Nov 2019 02:17:26 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=GmDVQiFH8lBmcq9rVdmSRlglTrGgI3IQf7rfK9RArJjXRhBgCp53lspqH1SlcQGTsPI7cScS/Vy5+j/cIKufzw0xzG/N0Xrto0j4nwn81P55ydiHGkkT5wrURyqcmdydHi+SCpZdW4OZn0geR26gUm7ZlwHy5bl0OgvyjUUaxSI7GkWxd6AKfP3Q+ssshFETBCr+Q14R5Pt4qpm8GeoVAcrYKCWm5Ri3+1IwJq1EiucMixcc4ciQnVKjBF7K7RNT2Of1iHuSbwRDBDicMqTSBQxNRY/2b5ea6W4dayyxsNGew8GXHanz8BEdDFpOu/maP68G+zaLl8/FJkUzt1Z25g== 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=a11YkNayM24x6XpnzvUOyD0iIziEh/6Kr4UhFQAGMaQ=; b=OuNyvJpqJSMunhTp4Z+xwCNCQ7LtqsH+z+AsDF9tZOPfe9nntBESPAaP9wShXbkEJayOZkQr2Ce98kJ8tFh85VT1Pig/Qs/7G0nPHkLJ7hVyPWAV7ALteIMdGrr0RpiVLyvbS8cvCR2E5wpDpjIRcojK5+lO+yLHlV2UT9d6AUgl6zETwmfLt7QmtX64WZxdqilhICx40UAGBJpMJPpyTWSDSXEWLa+LNNVn99rDtwrcANGmJtOcG5z6dYPbFaRphy6ljJQLGFAsEIW/2SUL7v1Of4+k/vAsl4Y2GORjV9W0DYWTWpzFupzdZRyKqsiVzgfZ8Ncc5TOOP6uNlywkVQ== 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=a11YkNayM24x6XpnzvUOyD0iIziEh/6Kr4UhFQAGMaQ=; b=JtWbtlEv0H4XIj7YzrXNxlcRdZ4Uc0R4TCPN8SgVRA0AR9N39mODWd5JZ6TT6GhD69P/RmPoEFPd+7lSz2/6VDgzhRqTxsb6iewsGAzz+bFy5dPGyfMe1Wo8URUyo81GyaBXMNumkw/yaJRuqH0XrujXMDeEEiYkL7pH2UxUte4= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=decui@microsoft.com; Received: from BN8PR21MB1137.namprd21.prod.outlook.com (20.179.72.96) by BN8PR21MB1251.namprd21.prod.outlook.com (20.179.74.28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2495.3; Wed, 20 Nov 2019 07:17:21 +0000 Received: from BN8PR21MB1137.namprd21.prod.outlook.com ([fe80::c596:ecf5:7a6:734d]) by BN8PR21MB1137.namprd21.prod.outlook.com ([fe80::c596:ecf5:7a6:734d%2]) with mapi id 15.20.2495.006; Wed, 20 Nov 2019 07:17:21 +0000 From: Dexuan Cui To: kys@microsoft.com, haiyangz@microsoft.com, sthemmin@microsoft.com, 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, mikelley@microsoft.com, Alexander.Levin@microsoft.com Cc: Dexuan Cui Subject: [PATCH v2 4/4] PCI: hv: kmemleak: Track the page allocations for struct hv_pcibus_device Date: Tue, 19 Nov 2019 23:16:58 -0800 Message-Id: <1574234218-49195-5-git-send-email-decui@microsoft.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1574234218-49195-1-git-send-email-decui@microsoft.com> References: <1574234218-49195-1-git-send-email-decui@microsoft.com> Reply-To: decui@microsoft.com X-ClientProxiedBy: MWHPR2001CA0022.namprd20.prod.outlook.com (2603:10b6:301:15::32) To BN8PR21MB1137.namprd21.prod.outlook.com (2603:10b6:408:71::32) MIME-Version: 1.0 Received: from linuxonhyperv3.guj3yctzbm1etfxqx2vob5hsef.xx.internal.cloudapp.net (13.77.154.182) by MWHPR2001CA0022.namprd20.prod.outlook.com (2603:10b6:301:15::32) with Microsoft SMTP Server (version=TLS1_2, cipher=) via Frontend Transport; Wed, 20 Nov 2019 07:17:20 +0000 X-Mailer: git-send-email 1.8.3.1 X-Originating-IP: [13.77.154.182] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: b0164f2a-1ed1-4430-5a85-08d76d89af2e X-MS-TrafficTypeDiagnostic: BN8PR21MB1251:|BN8PR21MB1251: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:9508; X-Forefront-PRVS: 02272225C5 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(376002)(346002)(396003)(136003)(39860400002)(366004)(199004)(189003)(10090500001)(36756003)(8936002)(50226002)(81166006)(81156014)(8676002)(14444005)(6436002)(6486002)(1511001)(86362001)(7736002)(2906002)(5660300002)(478600001)(10290500003)(4720700003)(6636002)(3846002)(6116002)(25786009)(3450700001)(66946007)(66556008)(66476007)(305945005)(316002)(386003)(6666004)(4326008)(6506007)(22452003)(26005)(16586007)(186003)(16526019)(107886003)(76176011)(51416003)(52116002)(66066001)(48376002)(47776003)(50466002)(446003)(11346002)(43066004)(956004)(2616005)(476003)(486006)(6512007)(921003)(1121003); DIR:OUT; SFP:1102; SCL:1; SRVR:BN8PR21MB1251; H:BN8PR21MB1137.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: BCL:0; X-Microsoft-Antispam-Message-Info: 1FZnyVBcMO4HC6UtvXGX3yDrXung2km9PPa+K9QeXtv2gpU5GbjMHWk8SSPx31nDdyuC6UyQLnWKheDh3eNk2Ev8qjg1NtuX68/ArjszxwXx2wLlpVJs9qK54Gq2fVZLcUmezq6yzlCVbQO8bgvQHDn/ckoMvHrA7OrJZD6wvH23uIB0IeGfqaG4iPwdihWu721J0JQiz9f5XXD59xSQ1oMclVWEL8eWkKLWyJ7kYOtNR2mZO2mMjHEKjAc4H7Ji8cYUAYNqW+DOQW5fQPjSxx2ssy6FRgLQBm/vEkvjLQVzoXJn/xmOYpDHPntnlSCeUenM36S2vpSQ6OSt19xBC30DiEBxFEIOa8i8plHdL9YYob7/4WbDppEpiw9QQs8OZTB91eqXbkAXRqlwd2soUwZS+O6bZ4gt2TfiXCIGPsD5drRENP41Uk2Xz1W6PhDT X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: b0164f2a-1ed1-4430-5a85-08d76d89af2e X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Nov 2019 07:17:21.6174 (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: 0hWydk/5vj+nKRMdpzMgrCu3E0xDLrMUz5Sr62lB0m1WnEEjoVt4zTwBTUWgbId0HT+NBqW6MNldcw6Quv6Qwg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN8PR21MB1251 Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org The page allocated for struct hv_pcibus_device contains pointers to other slab allocations in new_pcichild_device(). Since kmemleak does not track and scan page allocations, the slab objects will be reported as leaks (false positives). Use the kmemleak APIs to allow tracking of such pages. Reported-by: Lili Deng Signed-off-by: Dexuan Cui --- This is actually v1. I use "v2" in the Subject just to be consistent with the other patches in the patchset. Without the patch, we can see the below warning in dmesg, if kmemleak is enabled: kmemleak: 1 new suspected memory leaks (see /sys/kernel/debug/kmemleak) and "cat /sys/kernel/debug/kmemleak" shows: unreferenced object 0xffff9217d1f2bec0 (size 192): comm "kworker/u256:7", pid 100821, jiffies 4501481057 (age 61409.997s) hex dump (first 32 bytes): a8 60 b1 63 17 92 ff ff a8 60 b1 63 17 92 ff ff .`.c.....`.c.... 02 00 00 00 00 00 00 00 80 92 cd 61 17 92 ff ff ...........a.... backtrace: [<0000000006f7ae93>] pci_devices_present_work+0x326/0x5e0 [pci_hyperv] [<00000000278eb88a>] process_one_work+0x15f/0x360 [<00000000c59501e6>] worker_thread+0x49/0x3c0 [<000000000a0a7a94>] kthread+0xf8/0x130 [<000000007075c2e7>] ret_from_fork+0x35/0x40 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 d7e05d436b5e..cc73f49c9e03 100644 --- a/drivers/pci/controller/pci-hyperv.c +++ b/drivers/pci/controller/pci-hyperv.c @@ -46,6 +46,7 @@ #include #include #include +#include #include #include #include @@ -2907,6 +2908,16 @@ static int hv_pci_probe(struct hv_device *hdev, hbus = (struct hv_pcibus_device *)get_zeroed_page(GFP_KERNEL); if (!hbus) return -ENOMEM; + + /* + * kmemleak doesn't track page allocations as they are not commonly + * used for kernel data structures, but here hbus->children indeed + * contains pointers to hv_pci_dev structs, which are dynamically + * created in new_pcichild_device(). Allow kmemleak to scan the page + * so we don't get a false warning of memory leak. + */ + kmemleak_alloc(hbus, PAGE_SIZE, 1, GFP_KERNEL); + hbus->state = hv_pcibus_init; /* @@ -3133,6 +3144,8 @@ static int hv_pci_remove(struct hv_device *hdev) hv_put_dom_num(hbus->sysdata.domain); + /* Remove kmemleak object previously allocated in hv_pci_probe() */ + kmemleak_free(hbus); free_page((unsigned long)hbus); return ret; }