From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S967516AbeE2VVE (ORCPT ); Tue, 29 May 2018 17:21:04 -0400 Received: from mail-qk0-f193.google.com ([209.85.220.193]:45802 "EHLO mail-qk0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S966946AbeE2VU7 (ORCPT ); Tue, 29 May 2018 17:20:59 -0400 X-Google-Smtp-Source: ADUXVKIye5USyjX8GB/e7J3t1EEGKURZxSg2F14zcWzbILFLy4g8SN7vVn9D84y+AclPyygiBIBv6DPEG+X3sYf6p6o= MIME-Version: 1.0 In-Reply-To: References: From: Andy Shevchenko Date: Wed, 30 May 2018 00:20:57 +0300 Message-ID: Subject: Re: [PATCH] PCI: hv: Do not wait forever on a device that has disappeared To: Dexuan Cui Cc: Lorenzo Pieralisi , 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" Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, May 24, 2018 at 12:12 AM, 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. > + 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; > + } Infinite loops are usually a red flags. What's wrong with simple: do { ... } while (wait_...(...) == 0); ? > + if (!ret) > + ret = wait_for_response(hdev, &comp); Better to use well established patterns, i.e. if (ret) return ret; > + if (!ret) > + ret = wait_for_response(hdev, &comp_pkt.host_event); Here it looks okay on the first glance, but better to think about it again and refactor. -- With Best Regards, Andy Shevchenko