Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp3307512imm; Fri, 25 May 2018 03:31:07 -0700 (PDT) X-Google-Smtp-Source: AB8JxZrlwtAAEqQiSHQKLrdOh2H7aoSCotmSJjgIDB2jTb1sDBRsuvCbjR3MJqDPoN6clEsWEU2v X-Received: by 2002:a62:1549:: with SMTP id 70-v6mr1960700pfv.91.1527244267433; Fri, 25 May 2018 03:31:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527244267; cv=none; d=google.com; s=arc-20160816; b=M3kH2jwnZoika6gUVSy45cWQgW7cesdqLHTvZifnSOm5Wr3S1eey0iJPNPeCIVloUC jNBRQKYZXMVmo57KduskvKn88/8yVapLES+OKPECXHti3HkcQlQmDWobBbqs/SC6s2kJ TkIcF7z6h2JoY3nbDcz+LL58KVkFVkQn5V/5jF1ob0Ktv7Q3CSe2qeOfGAhb46qB6vvy Ebib5sWsLI3A1j/Qoy8gxnwsShUfA0dJmNICdJztPZHDaGPfAGaciutOm26YtGTeToEq qTrILq+L0XdpXRcbzH/4WPQ7XZN0zSIFf7kLqyowwyCSaUC1Jn7a564Kl8Y9HO/3cwVS vjJw== 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=Xk1V/Si5AHPei8GSu90ldeRqL3Apd+vaPWHpIrMkk78=; b=d1TLzmpnYmBORqHy0HCoLYXYp5MDestXWepJD66XloC6SCDO92nFamPLMQFxWZRu1H fuuUuDchuIv5fBDUw5vcU+BGTvxbGqr2BtwlioDT2rf7JjLN1GqcgHCLq+w2YrRbdMyQ h2m7TpO0ZW90wa0LiIF+JaYSL3ePhyyDWGzxtZhzZck8igS2mAUMUQNMfqHz8JloQSEH UAK5+E9nUG5NC3L9MrzannAdQd9T+MGoPuHeuAKodcGKGi9xN1SchlhIVOSxpnGJXhzP ommtTcJm+1qvOnhzPLnPgD+wZg9hnd5Gt4evqrhUYvK71v17T3UO4wGEQTP61mzsdDHs g6Vw== 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 o9-v6si23979517pfk.276.2018.05.25.03.30.51; Fri, 25 May 2018 03:31:07 -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 S965695AbeEYK3r (ORCPT + 99 others); Fri, 25 May 2018 06:29:47 -0400 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:58888 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965137AbeEYK3q (ORCPT ); Fri, 25 May 2018 06:29:46 -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 1183380D; Fri, 25 May 2018 03:29:46 -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 B098D3F578; Fri, 25 May 2018 03:29:43 -0700 (PDT) Date: Fri, 25 May 2018 11:29:40 +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: <20180525102940.GD6507@e107981-ln.cambridge.arm.com> References: <20180524124101.GB20732@e107981-ln.cambridge.arm.com> 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 Thu, May 24, 2018 at 11:55:35PM +0000, Dexuan Cui wrote: > > From: Lorenzo Pieralisi > > Sent: Thursday, May 24, 2018 05:41 > > 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. > > > > > > --- 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; > > > > This is pretty racy, isn't it ? Also, I reckon you should consider the > > timeout return value as an error condition unless I am completely > > missing the point of what you are doing. > > > > Lorenzo > > Actually, this is not racy: we only exit the loop when > 1) the channel is rescinded > or > 2) the channel is not rescinded, and the event is completed. > > wait_for_completion_timeout() returns 0 if timed out: in this case, > we keep spinning in the loop every 0.1 second, testing the 2 conditions. Yes sorry, you are right, the exit condition is correct, I am waiting for maintainers ACK to merge it, I need it as soon as possible if you want this to make it for v4.18. Thanks, Lorenzo > If the chanel is not rescinded, here we should wait for the event > forever, as the host is supposed to respond to us quickly, and the > event will be completed accordingly. This is what the current code > does. But, in case the channel is rescinded, we need to exit the loop > immediately with an error return value: this is the only change > made by the patch. > > Ideally, we should not use this ugly "polling" method, and the > rescind-handler, i.e. vmbus_onoffer_rescind(), should notify > wait_for_response(), but as I mentioned, there is no good way > to get notified from vmbus_onoffer_rescind(), so I'm proposing > this "polling" method: it's simple and it can work correctly, > and this is not a hot path. > > Thanks, > -- Dexuan