From patchwork Wed Feb 24 18:56:36 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jake Oshins X-Patchwork-Id: 587584 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 0D34B140779 for ; Thu, 25 Feb 2016 05:57:11 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=sendgrid.me header.i=@sendgrid.me header.b=KUlPQA7b; dkim-atps=neutral Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755306AbcBXS5J (ORCPT ); Wed, 24 Feb 2016 13:57:09 -0500 Received: from o1.f.az.sendgrid.net ([208.117.55.132]:37361 "EHLO o1.f.az.sendgrid.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750901AbcBXS5I (ORCPT ); Wed, 24 Feb 2016 13:57:08 -0500 DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sendgrid.me; h=from:to:cc:subject; s=smtpapi; bh=4W7rHYujzabBUAQl4RC9FcFxZqc=; b=KUlPQA7b3NjimF2JyRMvMHisNMrR61lrbZs/bjzpkTNMpgPR7IIKWXvjPdumNX 15rlEWRTNRHkZbltBmRpaJ/YfvEXljWaiEjHqEBlmTsRrjdlAI2N1KumCtVVufro ElX4g6dY5jZMUw0FdAcZ7rMRnba0ZlDuBnr9CE+x1H5L4= Received: by filter0170p1las1.sendgrid.net with SMTP id filter0170p1las1.23881.56CDFD0177 2016-02-24 18:57:05.796682921 +0000 UTC Received: from jakeoshinsu2.jakeoshinsu2.d1.internal.cloudapp.net (unknown [104.210.40.47]) by ismtpd0013p1las1.sendgrid.net (SG) with ESMTP id jEfqiwTvRbi2OdPfG42-MA Wed, 24 Feb 2016 18:57:05.558 +0000 (UTC) From: jakeo@microsoft.com To: bhelgaas@google.com, linux-pci@vger.kernel.org, gregkh@linuxfoundation.org, kys@microsoft.com, linux-kernel@vger.kernel.org, devel@linuxdriverproject.org, olaf@aepfle.de, apw@canonical.com, vkuznets@redhat.com, tglx@linutronix.de, haiyangz@microsoft.com, marc.zyngier@arm.com, haddenh@microsoft.com Cc: Jake Oshins Subject: [PATCH] PCI: Remove usage of pci_domain_nr when the PCI bus doesn't yet exist Date: Wed, 24 Feb 2016 18:56:36 +0000 Message-Id: <1456340196-13717-1-git-send-email-jakeo@microsoft.com> X-Mailer: git-send-email 1.9.1 X-SendGrid-Contentd-ID: {"test_id":"1456340226"} X-SG-EID: lfnueJVzSjg1mfuVqqukVH7tZvRy9mfCIcBnfbfzaMPHFkS3jNHhkgccBLJqd5E0xBdwMMx22sNlj6 2mPs7tCWlVJ2cd+6tE61RIx3htyZl7ZFm404Nut/0s43ebPwdLvLwzBWNnq5Pro6s8ekGPD1LZpFtk senjcl4EVEw8b4p5DIKX9UP/CNWMxqVeNSC3MhoFuEqaDOOlet19IOavZQ== Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org From: Jake Oshins This patch fixes a race condition in this driver. Using the function pci_domain_nr() only works if the PCI bus has already been fully created. This patch just deletes one call site, as it was in debug prints which aren't strictly necessary. Another call site is changed to look for the data in the same structure that is passed in when creating the PCI bus in the first place. Signed-off-by: Jake Oshins --- drivers/pci/host/pci-hyperv.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/drivers/pci/host/pci-hyperv.c b/drivers/pci/host/pci-hyperv.c index 9391dee..ed651ba 100644 --- a/drivers/pci/host/pci-hyperv.c +++ b/drivers/pci/host/pci-hyperv.c @@ -1265,11 +1265,6 @@ static struct hv_pci_dev *new_pcichild_device(struct hv_pcibus_device *hbus, if (!hpdev) return NULL; - dev_info(&hbus->hdev->device, - "New child device (%p) [%04x:%04x] at %04x:00:00.%02x\n", - hpdev, desc->v_id, desc->d_id, pci_domain_nr(hbus->pci_bus), - desc->win_slot.bits.func); - hpdev->hbus = hbus; memset(&pkt, 0, sizeof(pkt)); @@ -1558,9 +1553,15 @@ static void hv_eject_device_work(struct work_struct *work) return; } + /* + * Ejection can come before or after the PCI bus has been set up, so + * attempt to find it and tear down the bus state, if it exists. This + * must be done without constructs like pci_domain_nr(hbus->pci_bus) + * because hbus->pci_bus may not exist yet. + */ wslot = wslot_to_devfn(hpdev->desc.win_slot.slot); - pdev = pci_get_domain_bus_and_slot(pci_domain_nr(hpdev->hbus->pci_bus), - 0, wslot); + pdev = pci_get_domain_bus_and_slot(hpdev->hbus->sysdata.domain, 0, + wslot); if (pdev) { pci_stop_and_remove_bus_device(pdev); pci_dev_put(pdev);