Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp3110707ybi; Thu, 18 Jul 2019 21:13:50 -0700 (PDT) X-Google-Smtp-Source: APXvYqxKCUQPM2l9arZ+Ao/PGa2/uU0KBmO8E8aWgVXXrunMGQyfosO6zXWRQSX3sjM9d1oQx7xK X-Received: by 2002:a17:902:f216:: with SMTP id gn22mr53155898plb.118.1563509630472; Thu, 18 Jul 2019 21:13:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563509630; cv=none; d=google.com; s=arc-20160816; b=KMJBNelTP9tRMKNtfS7DDJ3W5KVk6TsUkgPorJfpEQyPKGSKvfHtaB6oEQWo/Z4kna ektXC+owCYRMUznO6gSRzjydJAzqW5dSe1bB/v0rf/86wnO096A5SEnx+KZaUk2PqUp4 O6FKvPRwYBBRTHGOiN0YD/oILqjNC3k8SmPEwQpUJXptsVafp6m4VRF5fPjsZu9JDUVX M8EJ+Ae/FoCmw81jAFkH9fxoXF9rCU0POtPVMcRywt7LRWqDJil6aFjBFScFES6NsbB/ QATIp4cIa0TLnXOahfcKGAcS73NTQx2g0r121fSid1w2ItJD9lxEYa85BNLcCxxokV2Q vrhA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=EmLsZv0/XFJ6g2EnboG4tr4Xc2sUne2CcPwkr/+elXE=; b=ixFxhLeL8hZxYn9bDWSEAmD9SUvnGZRoofaMzsG8CS9lpD+9ujJC0xxackgAUt7yfc dUvR3HAbq5paOAVXOelpi90EQ1rod9Q5gqyWj5vHawcvXFplNMrEhQ+LrcPPLqfAO+Ma pQe1Ipf90MTYL1gh3kg8oLDofC1rd32T7iHtV4s8sCI1yMVJ5t5ter48Nd1rpV5FVZMN lPpmThisywdhBCicnFhHA7+U3eaovmOcu/1tavrcTfLx6BvTYLuUqAPaoEETn5ZCpkSA xo5lZwWt54qOVtpilO93aYSquIXbDXfgJhaO/gUHXHHCg9fUM17LQ86vwywe8bDd8lBE xbig== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=IK5y7uGN; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d7si90823plr.18.2019.07.18.21.13.35; Thu, 18 Jul 2019 21:13:50 -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=@kernel.org header.s=default header.b=IK5y7uGN; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732882AbfGSEL0 (ORCPT + 99 others); Fri, 19 Jul 2019 00:11:26 -0400 Received: from mail.kernel.org ([198.145.29.99]:46292 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730254AbfGSELW (ORCPT ); Fri, 19 Jul 2019 00:11:22 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 3991121873; Fri, 19 Jul 2019 04:11:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1563509481; bh=lTpd3BwJntjvisbyb/KkUvM8RQIScLiS5UOe+xKdDrg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IK5y7uGNwssdy/6IMIpU1xh/iUIngh849+YaD94uVrjPS8aMcKCIWlgO8lykg+VF2 1g3zSWOa9apHjCxADf7uNsxdLBP/7c+KIdv5uN1mbIAM+iKa+37cedi8d1bLGsJfsw 5pStqknUABx0rz8M3SJoYXLKJ1WMV80HckPej+yo= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Alex Williamson , Bjorn Helgaas , Sasha Levin , linux-pci@vger.kernel.org Subject: [PATCH AUTOSEL 4.14 07/60] PCI: Return error if cannot probe VF Date: Fri, 19 Jul 2019 00:10:16 -0400 Message-Id: <20190719041109.18262-7-sashal@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190719041109.18262-1-sashal@kernel.org> References: <20190719041109.18262-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Alex Williamson [ Upstream commit 76002d8b48c4b08c9bd414517dd295e132ad910b ] Commit 0e7df22401a3 ("PCI: Add sysfs sriov_drivers_autoprobe to control VF driver binding") allows the user to specify that drivers for VFs of a PF should not be probed, but it actually causes pci_device_probe() to return success back to the driver core in this case. Therefore by all sysfs appearances the device is bound to a driver, the driver link from the device exists as does the device link back from the driver, yet the driver's probe function is never called on the device. We also fail to do any sort of cleanup when we're prohibited from probing the device, the IRQ setup remains in place and we even hold a device reference. Instead, abort with errno before any setup or references are taken when pci_device_can_probe() prevents us from trying to probe the device. Link: https://lore.kernel.org/lkml/155672991496.20698.4279330795743262888.stgit@gimli.home Fixes: 0e7df22401a3 ("PCI: Add sysfs sriov_drivers_autoprobe to control VF driver binding") Signed-off-by: Alex Williamson Signed-off-by: Bjorn Helgaas Signed-off-by: Sasha Levin --- drivers/pci/pci-driver.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/drivers/pci/pci-driver.c b/drivers/pci/pci-driver.c index ea69b4dbab66..e5a8bf2c9b37 100644 --- a/drivers/pci/pci-driver.c +++ b/drivers/pci/pci-driver.c @@ -415,6 +415,9 @@ static int pci_device_probe(struct device *dev) struct pci_dev *pci_dev = to_pci_dev(dev); struct pci_driver *drv = to_pci_driver(dev->driver); + if (!pci_device_can_probe(pci_dev)) + return -ENODEV; + pci_assign_irq(pci_dev); error = pcibios_alloc_irq(pci_dev); @@ -422,12 +425,10 @@ static int pci_device_probe(struct device *dev) return error; pci_dev_get(pci_dev); - if (pci_device_can_probe(pci_dev)) { - error = __pci_device_probe(drv, pci_dev); - if (error) { - pcibios_free_irq(pci_dev); - pci_dev_put(pci_dev); - } + error = __pci_device_probe(drv, pci_dev); + if (error) { + pcibios_free_irq(pci_dev); + pci_dev_put(pci_dev); } return error; -- 2.20.1