Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp1325115imm; Wed, 23 May 2018 14:12:54 -0700 (PDT) X-Google-Smtp-Source: AB8JxZrnbvAmLnqD4uGR157diflba3HWiQzgqBgCQxvNRzfOfo9dXRgFJLO4B07pUeD06vmMtDfG X-Received: by 2002:a62:5b02:: with SMTP id p2-v6mr4354409pfb.96.1527109974088; Wed, 23 May 2018 14:12:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527109974; cv=none; d=google.com; s=arc-20160816; b=eXzq6SNWyRtWzz821oc5NR1kcrPv1ZJ2oihdy79tvaCFuujLOS//nu2UFx18NxMfHu DyTd7HzY813VbY5LD3otnAA434voL8ARo6u8tXYF/rAbflOnUWHtc7RMatP/Lx3mSFRU byIVl99RuB7U+fT/fqZA4jTpa7POhtEeKRr6Su2CwydQ/9TI4Ks8BLhozTW/GIoPPZwD L8S1a1N6PqIftUAbuNkCfrMXcqiRO3HtjG+MeUx/ILrCBPN/iukhheWdNEfjfds8OTTV JPzLS89k6qXrxjNRFHT+W2WBMO/nSoBB6u0SsmpklU60O/zRwYjCO71dJ2zhVjeBERnr gTRw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:content-transfer-encoding :spamdiagnosticmetadata:spamdiagnosticoutput:msip_labels :content-language:accept-language:message-id:date:thread-index :thread-topic:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=ucrpL2EXxLFSaw3+c005hst2WK1q11M5h4esuImUg68=; b=P/sIyWbkIK4bQCvGG7Lvbr5ajZdaL75sdRyYQ4xKTT/ouioilm/K86H/b4Ba0AVLKD e0klfQF4MS+J+G0UnIPhaR18l4xL1Bc1LVHGFtfLoedCJLbV4OnqOpb8PO6KK32smSOA Q3y8fxLumfdocdlAHm9DGeg3iOaoUmBv2mqB7HW96nIwI7n4+ed45jnbio53tw3cQ1dR BHnuNLiZos2uiA6T4bZr9KDcPZ2qp3EfxkpUfO1c4xpgvx2KX0ndDYWNKJr4LE/FXpMD 8ekgYXdvwNlhXcvYCWpmXtw4hQh2PF+mAblNePgdLtcBFBt3HRxjUiKx3vX2sH1FROgJ c3+Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=E7LeCU3N; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id bd4-v6si195446plb.338.2018.05.23.14.12.38; Wed, 23 May 2018 14:12:54 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=E7LeCU3N; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934696AbeEWVMX (ORCPT + 99 others); Wed, 23 May 2018 17:12:23 -0400 Received: from mail-pu1apc01on0093.outbound.protection.outlook.com ([104.47.126.93]:54144 "EHLO APC01-PU1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S934230AbeEWVMT (ORCPT ); Wed, 23 May 2018 17:12:19 -0400 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=ucrpL2EXxLFSaw3+c005hst2WK1q11M5h4esuImUg68=; b=E7LeCU3NcGlRLOiPfMrFr8eDpUN2A04+sAlDSyf9NpYTfM/aDl8Q1B5Et48T5gTGC4yYQzSRqrf9W5eZC6aUqFfORrMubn7dx+b5WDsGf7IZL1v41+CZMKv8o4epURAxRol31Dh+IurWaH943kvLQ/mRrDRqC9++IBS35Ya/GaY= Received: from KL1P15301MB0006.APCP153.PROD.OUTLOOK.COM (10.170.167.17) by KL1P15301MB0021.APCP153.PROD.OUTLOOK.COM (10.170.167.146) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.820.2; Wed, 23 May 2018 21:12:02 +0000 Received: from KL1P15301MB0006.APCP153.PROD.OUTLOOK.COM ([10.170.167.17]) by KL1P15301MB0006.APCP153.PROD.OUTLOOK.COM ([10.170.167.17]) with mapi id 15.20.0820.001; Wed, 23 May 2018 21:12:02 +0000 From: Dexuan Cui To: 'Lorenzo Pieralisi' , 'Bjorn Helgaas' , "'linux-pci@vger.kernel.org'" , KY Srinivasan , Stephen Hemminger , "'olaf@aepfle.de'" , "'apw@canonical.com'" , "'jasowang@redhat.com'" CC: "'linux-kernel@vger.kernel.org'" , "'driverdev-devel@linuxdriverproject.org'" , Haiyang Zhang , "'vkuznets@redhat.com'" , "'marcelo.cerri@canonical.com'" Subject: [PATCH] PCI: hv: Do not wait forever on a device that has disappeared Thread-Topic: [PATCH] PCI: hv: Do not wait forever on a device that has disappeared Thread-Index: AdPy2mt/5cq5najeS4qpn1DMFXGqNw== Date: Wed, 23 May 2018 21:12:01 +0000 Message-ID: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: msip_labels: MSIP_Label_f42aa342-8706-4288-bd11-ebb85995028c_Enabled=True; MSIP_Label_f42aa342-8706-4288-bd11-ebb85995028c_SiteId=72f988bf-86f1-41af-91ab-2d7cd011db47; MSIP_Label_f42aa342-8706-4288-bd11-ebb85995028c_Owner=decui@microsoft.com; MSIP_Label_f42aa342-8706-4288-bd11-ebb85995028c_SetDate=2018-05-23T21:11:58.7383302Z; MSIP_Label_f42aa342-8706-4288-bd11-ebb85995028c_Name=General; MSIP_Label_f42aa342-8706-4288-bd11-ebb85995028c_Application=Microsoft Azure Information Protection; MSIP_Label_f42aa342-8706-4288-bd11-ebb85995028c_Extended_MSFT_Method=Automatic; Sensitivity=General authentication-results: spf=none (sender IP is ) smtp.mailfrom=decui@microsoft.com; x-originating-ip: [2001:4898:80e8:8:b100:aa00:9dfd:2063] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1;KL1P15301MB0021;7:dnd8TaN8iPGdnlCzhqg3FiiGK+maepdMVLSdnlynP0vmVp3nOMGbJm3XtiCdJ576SfNIt63q2+Grg+Ku37Pujyfrlu7H6ByE91HD8uD4pO9Cm5LnxN1aHLfd7moUBVPlRNMgF3wyPHkeevV/wu7pb4iOzwCZDe9czExYBttL24AcjpUMKmvzVKUjhioEDy8lk5qr5+Ffy+DXORANsPihcajlHKvJCdHa/AciTRWxeeTDhYe8IvSQbsAILCtBcJfE;20:AY3uiIpMm9dzAL3/M9furAtqs+fDLtAfXr2/fnsf85D3f4oBeij4hKdI2ZZPotwOHdxtvE+t7R+uDRPJlO8+Sw3Nio+9LbEGw7mm4imLJkM8U/ZN8zsYEgsquzdXiOVZYGEnNvQXZWCqo33W3sHGN+UOCHsU3WuOqu9MjpYtnTg= x-ms-exchange-antispam-srfa-diagnostics: SOS; x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020095)(4652020)(5600026)(48565401081)(4534165)(4627221)(201703031133081)(201702281549075)(2017052603328)(7193020);SRVR:KL1P15301MB0021; x-ms-traffictypediagnostic: KL1P15301MB0021: x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(28532068793085)(244540007438412)(89211679590171); x-ms-exchange-senderadcheck: 1 x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(8211001083)(6040522)(2401047)(5005006)(8121501046)(3002001)(3231254)(944501410)(52105095)(93006095)(93001095)(10201501046)(6055026)(149027)(150027)(6041310)(20161123562045)(20161123558120)(20161123560045)(20161123564045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(6072148)(201708071742011)(7699016);SRVR:KL1P15301MB0021;BCL:0;PCL:0;RULEID:;SRVR:KL1P15301MB0021; x-forefront-prvs: 06818431B9 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(979002)(376002)(396003)(39380400002)(366004)(39860400002)(346002)(189003)(199004)(7696005)(86612001)(305945005)(2900100001)(102836004)(1511001)(6506007)(59450400001)(99286004)(186003)(4326008)(25786009)(77096007)(1857600001)(97736004)(486006)(476003)(46003)(10290500003)(86362001)(74316002)(53936002)(7736002)(68736007)(8676002)(6436002)(8936002)(14454004)(8990500004)(6116002)(105586002)(10090500001)(106356001)(3660700001)(81166006)(5660300001)(81156014)(316002)(2906002)(22452003)(9686003)(3280700002)(110136005)(54906003)(478600001)(55016002)(7416002)(33656002)(491001)(969003)(989001)(999001)(1009001)(1019001);DIR:OUT;SFP:1102;SCL:1;SRVR:KL1P15301MB0021;H:KL1P15301MB0006.APCP153.PROD.OUTLOOK.COM;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;MX:1;A:1; received-spf: None (protection.outlook.com: microsoft.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: vNnyFo4LwHCRzQVh0xjWaWuJs2/RIetSEQ8ohCzGSCKvWgSxh08vzEhjc1qQUtcoRW2Nqj1zFcho+XGowT5JZjHmNTFn5A2tP9LiikJqQ7DX5m0ewIlKR/a/saa97+ZryF1UkCYRaOtxSlDq/xoL37mTNTjRutRo21hsrALBDiVxCBrhv3arGhUuIHuOYGj4 spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-MS-Office365-Filtering-Correlation-Id: 4d1f28d9-5139-4dcd-0c9d-08d5c0f1d446 X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4d1f28d9-5139-4dcd-0c9d-08d5c0f1d446 X-MS-Exchange-CrossTenant-originalarrivaltime: 23 May 2018 21:12:01.8750 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-Transport-CrossTenantHeadersStamped: KL1P15301MB0021 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Before the guest finishes the device initialization, the device can be removed anytime by the host, and after that the host won't respond to the guest's request, so the guest should be prepared to handle this case. Signed-off-by: Dexuan Cui Cc: Stephen Hemminger Cc: K. Y. Srinivasan --- drivers/pci/host/pci-hyperv.c | 46 ++++++++++++++++++++++++++++++++-------= ---- 1 file changed, 34 insertions(+), 12 deletions(-) diff --git a/drivers/pci/host/pci-hyperv.c b/drivers/pci/host/pci-hyperv.c index ad6a64d..248765f 100644 --- a/drivers/pci/host/pci-hyperv.c +++ b/drivers/pci/host/pci-hyperv.c @@ -556,6 +556,26 @@ static void put_pcichild(struct hv_pci_dev *hv_pcidev, static void get_hvpcibus(struct hv_pcibus_device *hv_pcibus); static void put_hvpcibus(struct hv_pcibus_device *hv_pcibus); =20 +/* + * There is no good way to get notified from vmbus_onoffer_rescind(), + * so let's use polling here, since this is not a hot path. + */ +static int wait_for_response(struct hv_device *hdev, + struct completion *comp) +{ + while (true) { + if (hdev->channel->rescind) { + dev_warn_once(&hdev->device, "The device is gone.\n"); + return -ENODEV; + } + + if (wait_for_completion_timeout(comp, HZ / 10)) + break; + } + + return 0; +} + /** * devfn_to_wslot() - Convert from Linux PCI slot to Windows * @devfn: The Linux representation of PCI slot @@ -1569,7 +1589,8 @@ static struct hv_pci_dev *new_pcichild_device(struct = hv_pcibus_device *hbus, if (ret) goto error; =20 - wait_for_completion(&comp_pkt.host_event); + if (wait_for_response(hbus->hdev, &comp_pkt.host_event)) + goto error; =20 hpdev->desc =3D *desc; refcount_set(&hpdev->refs, 1); @@ -2070,15 +2091,16 @@ static int hv_pci_protocol_negotiation(struct hv_de= vice *hdev) sizeof(struct pci_version_request), (unsigned long)pkt, VM_PKT_DATA_INBAND, VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED); + if (!ret) + ret =3D wait_for_response(hdev, &comp_pkt.host_event); + if (ret) { dev_err(&hdev->device, - "PCI Pass-through VSP failed sending version reqquest: %#x", + "PCI Pass-through VSP failed to request version: %d", ret); goto exit; } =20 - wait_for_completion(&comp_pkt.host_event); - if (comp_pkt.completion_status >=3D 0) { pci_protocol_version =3D pci_protocol_versions[i]; dev_info(&hdev->device, @@ -2287,11 +2309,12 @@ static int hv_pci_enter_d0(struct hv_device *hdev) ret =3D vmbus_sendpacket(hdev->channel, d0_entry, sizeof(*d0_entry), (unsigned long)pkt, VM_PKT_DATA_INBAND, VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED); + if (!ret) + ret =3D wait_for_response(hdev, &comp_pkt.host_event); + if (ret) goto exit; =20 - wait_for_completion(&comp_pkt.host_event); - if (comp_pkt.completion_status < 0) { dev_err(&hdev->device, "PCI Pass-through VSP failed D0 Entry with status %x\n", @@ -2331,11 +2354,10 @@ static int hv_pci_query_relations(struct hv_device = *hdev) =20 ret =3D vmbus_sendpacket(hdev->channel, &message, sizeof(message), 0, VM_PKT_DATA_INBAND, 0); - if (ret) - return ret; + if (!ret) + ret =3D wait_for_response(hdev, &comp); =20 - wait_for_completion(&comp); - return 0; + return ret; } =20 /** @@ -2405,11 +2427,11 @@ static int hv_send_resources_allocated(struct hv_de= vice *hdev) size_res, (unsigned long)pkt, VM_PKT_DATA_INBAND, VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED); + if (!ret) + ret =3D wait_for_response(hdev, &comp_pkt.host_event); if (ret) break; =20 - wait_for_completion(&comp_pkt.host_event); - if (comp_pkt.completion_status < 0) { ret =3D -EPROTO; dev_err(&hdev->device, --=20 2.7.4