Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp3506525imm; Fri, 25 May 2018 06:56:57 -0700 (PDT) X-Google-Smtp-Source: AB8JxZri3LnKPoLEYp0lAKW8QXTpKYRLXNviLB7uLkQ6Q/kwpXJ9N1vtk3Ke/6t9M5blGvkIpBIh X-Received: by 2002:a65:6557:: with SMTP id a23-v6mr2078763pgw.319.1527256616999; Fri, 25 May 2018 06:56:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527256616; cv=none; d=google.com; s=arc-20160816; b=ikwy3zdw8mBbis+RTRJOpqLtbLOzCn23MQ6zffUWp5NBTc6dmvzhF1d+QmaX3nPpWn fiAULi22VvP6r0cZyJ4JR+5gk1HD6y0+nwjsBNa9T53mf4v93qGE+RR61HmS2kKPztEz iRrF0cFBHZgYtFA5t42Z4sPg+qfEqqGxSw/L/DjdnwKtIgyUTEFu7gb5HKLPXZEFmfpy jj1F+D0XVXWsDo+eN4wW6Qgd+1ZNXtJEVlaj0jiZ3p1mGggeeNxEnS3dZsAsH4GHtYNv s+WCnHZhmpElIiqVwrnyzK7wBxCT1M4J/6uLMiNlKMhZ+tXA98VhvBr7sDp8nL2XYLoQ nULw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:arc-authentication-results; bh=07P8YlI0KVFHkaXWeg4tym98HxBdUK+3xJs0I5j+H0k=; b=EQFolC0fg6o0CecbKH/B6sepGkPzLYqB03hMvdyP6MbEn8cH7HDG93QHVhS74psU33 U8mpdrLiuKeZ2ii33QZfnXPSnFCXow+/wIgiaubUphtAJTU7mW2JvyrAJhd5+p6/7lF/ i947OsKo5g9JTczB+d+ILLVrQHpWUuzgbegvzH72E8oK16expNC+B9vqbRvgs3JLOaI1 Kvae7DBwWsfWrtyxP+wNI+2xL/dK29+wbimmT63PNz0TN5CP48jA+hb+39elnrNNzYec 9VEcRnrJhUb3Machq7AxWRXIIjPp7tvDbnbm7sRuyKtlZDhLWSypI4PzwaK6CpCkj7LQ PU9A== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b9-v6si23943371pfn.100.2018.05.25.06.56.40; Fri, 25 May 2018 06:56:56 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S935837AbeEYN4c (ORCPT + 99 others); Fri, 25 May 2018 09:56:32 -0400 Received: from foss.arm.com ([217.140.101.70]:34024 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934496AbeEYN4b (ORCPT ); Fri, 25 May 2018 09:56:31 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id D10F080D; Fri, 25 May 2018 06:56:30 -0700 (PDT) Received: from e107981-ln.cambridge.arm.com (e107981-ln.cambridge.arm.com [10.1.207.54]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 860633F557; Fri, 25 May 2018 06:56:28 -0700 (PDT) Date: Fri, 25 May 2018 14:56:23 +0100 From: Lorenzo Pieralisi To: Dexuan Cui Cc: 'Bjorn Helgaas' , "'linux-pci@vger.kernel.org'" , KY Srinivasan , Stephen Hemminger , "'olaf@aepfle.de'" , "'apw@canonical.com'" , "'jasowang@redhat.com'" , "'linux-kernel@vger.kernel.org'" , "'driverdev-devel@linuxdriverproject.org'" , Haiyang Zhang , "'vkuznets@redhat.com'" , "'marcelo.cerri@canonical.com'" Subject: Re: [PATCH] PCI: hv: Do not wait forever on a device that has disappeared Message-ID: <20180525135623.GA10871@e107981-ln.cambridge.arm.com> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, May 23, 2018 at 09:12:01PM +0000, Dexuan Cui wrote: > > 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(-) Applied with a minor tweak to the commit log to pci/hv for v4.18. Thanks, Lorenzo > 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); > > +/* > + * 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; > > - wait_for_completion(&comp_pkt.host_event); > + if (wait_for_response(hbus->hdev, &comp_pkt.host_event)) > + goto error; > > hpdev->desc = *desc; > refcount_set(&hpdev->refs, 1); > @@ -2070,15 +2091,16 @@ static int hv_pci_protocol_negotiation(struct hv_device *hdev) > sizeof(struct pci_version_request), > (unsigned long)pkt, VM_PKT_DATA_INBAND, > VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED); > + if (!ret) > + ret = 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; > } > > - wait_for_completion(&comp_pkt.host_event); > - > if (comp_pkt.completion_status >= 0) { > pci_protocol_version = pci_protocol_versions[i]; > dev_info(&hdev->device, > @@ -2287,11 +2309,12 @@ static int hv_pci_enter_d0(struct hv_device *hdev) > ret = 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 = wait_for_response(hdev, &comp_pkt.host_event); > + > if (ret) > goto exit; > > - 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) > > ret = vmbus_sendpacket(hdev->channel, &message, sizeof(message), > 0, VM_PKT_DATA_INBAND, 0); > - if (ret) > - return ret; > + if (!ret) > + ret = wait_for_response(hdev, &comp); > > - wait_for_completion(&comp); > - return 0; > + return ret; > } > > /** > @@ -2405,11 +2427,11 @@ static int hv_send_resources_allocated(struct hv_device *hdev) > size_res, (unsigned long)pkt, > VM_PKT_DATA_INBAND, > VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED); > + if (!ret) > + ret = wait_for_response(hdev, &comp_pkt.host_event); > if (ret) > break; > > - wait_for_completion(&comp_pkt.host_event); > - > if (comp_pkt.completion_status < 0) { > ret = -EPROTO; > dev_err(&hdev->device, > -- > 2.7.4 >