Received: by 10.223.185.116 with SMTP id b49csp6201399wrg; Thu, 8 Mar 2018 03:37:27 -0800 (PST) X-Google-Smtp-Source: AG47ELvDpvOfertEzoVxvGY6Pzf88ug1QSHj+GMrh3aIdGZmvbJEB+/wkhxfEY5TkMy6/+aaCIra X-Received: by 2002:a17:902:7486:: with SMTP id h6-v6mr23560866pll.216.1520509047455; Thu, 08 Mar 2018 03:37:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520509047; cv=none; d=google.com; s=arc-20160816; b=OZeddeHW8IpDyVcVQ6JQO+owXZH08nNdc20b8YKfdED0+kX/BIfBddBUlz5xy6YpS0 12majfuEBsp6X9Ar/FQyEjMo2kRmYQ2OJLG6QfEcou119QrZxgy16zd+nJVnpzp5rMKr nZwqtgElOtMifRF1oh3DEz1TL4ZAwnV3HkLQSzEQqt6KVum5kKdSmCkd5P/QcedQYw5L EjZIPf8o2gT9+4FrQ5nD/imuAcdC+7AV+fmgl2ktQdTG2NFwhIflmhC11HTi1EE3W6Wf g+yLmOeoW/u96ogt/VJTB3fVswo1Vb84C3njbXOchw8V/KB/o4ZnPkdi7Dppcs+y4Gg5 w9qw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-disposition :content-transfer-encoding:mime-version:robot-unsubscribe:robot-id :git-commit-id:subject:to:references:in-reply-to:reply-to:cc :message-id:from:date:arc-authentication-results; bh=0bhypOPfVfsCTnZ6LAjYwmZxaq14QVBx1r+n+q2i7dQ=; b=zBTuYznvDRKhCFVvxCg5sOVPe8bM+eDNdby0X+ldAU2Uy7+mJ5tv1WtOOBUkeAQABB /EgHGm8MHgVBVOT29s1hyNfOPb7uz0YD1qK8JVp+HoOsWln80Jmxl3TwNBgirky+dUeY WCZSLzj858fLXpLCfvuJNareo1wkn4xGzBeF+0FuYBtJtljAOGsxDFaqpZpLNCC49QmU hJEuaJzA9Ii+6PYmeCBRAN9tnJtIHY8RXUR8FotWWtU0RArS8LN8inR45QOKeCvfG0+v ajGTPfjJBZlhOsdLY6UPSo8MnfH3+yK4blFm/fR4YgM9DgMQy919Xmyowb085gym9V50 MXmw== 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 m9si12815854pgp.542.2018.03.08.03.37.12; Thu, 08 Mar 2018 03:37:27 -0800 (PST) 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 S965656AbeCHLem (ORCPT + 99 others); Thu, 8 Mar 2018 06:34:42 -0500 Received: from terminus.zytor.com ([198.137.202.136]:45289 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934653AbeCHLek (ORCPT ); Thu, 8 Mar 2018 06:34:40 -0500 Received: from terminus.zytor.com (localhost [127.0.0.1]) by terminus.zytor.com (8.15.2/8.15.2) with ESMTP id w28BYQOx029932; Thu, 8 Mar 2018 03:34:26 -0800 Received: (from tipbot@localhost) by terminus.zytor.com (8.15.2/8.15.2/Submit) id w28BYQUg029925; Thu, 8 Mar 2018 03:34:26 -0800 Date: Thu, 8 Mar 2018 03:34:26 -0800 X-Authentication-Warning: terminus.zytor.com: tipbot set sender to tipbot@zytor.com using -f From: tip-bot for Jan Kiszka Message-ID: Cc: linux-kernel@vger.kernel.org, andy.shevchenko@gmail.com, tglx@linutronix.de, hpa@zytor.com, b.spranger@linutronix.de, jan.kiszka@siemens.com, bhelgaas@google.com, mingo@kernel.org Reply-To: andy.shevchenko@gmail.com, linux-kernel@vger.kernel.org, bhelgaas@google.com, mingo@kernel.org, jan.kiszka@siemens.com, b.spranger@linutronix.de, tglx@linutronix.de, hpa@zytor.com In-Reply-To: <06e279b2a3e06cf6689ab3975f8ab592bba02362.1520408357.git.jan.kiszka@siemens.com> References: <06e279b2a3e06cf6689ab3975f8ab592bba02362.1520408357.git.jan.kiszka@siemens.com> To: linux-tip-commits@vger.kernel.org Subject: [tip:x86/platform] PCI: Scan all functions when running over Jailhouse Git-Commit-ID: 690f4304104f37e473bd5e43fc5247f5cd35b225 X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline X-Spam-Status: No, score=-0.8 required=5.0 tests=ALL_TRUSTED,BAYES_00, FREEMAIL_FORGED_REPLYTO autolearn=no autolearn_force=no version=3.4.1 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on terminus.zytor.com Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: 690f4304104f37e473bd5e43fc5247f5cd35b225 Gitweb: https://git.kernel.org/tip/690f4304104f37e473bd5e43fc5247f5cd35b225 Author: Jan Kiszka AuthorDate: Wed, 7 Mar 2018 08:39:13 +0100 Committer: Thomas Gleixner CommitDate: Thu, 8 Mar 2018 12:30:37 +0100 PCI: Scan all functions when running over Jailhouse Per PCIe r4.0, sec 7.5.1.1.9, multi-function devices are required to have a function 0. Therefore, Linux scans for devices at function 0 (devfn 0/8/16/...) and only scans for other functions if function 0 has its Multi-Function Device bit set or ARI or SR-IOV indicate there are more functions. The Jailhouse hypervisor may pass individual functions of a multi-function device to a guest without passing function 0, which means a Linux guest won't find them. Change Linux PCI probing so it scans all function numbers when running as a guest over Jailhouse. This is technically prohibited by the spec, so it is possible that PCI devices without the Multi-Function Device bit set may have unexpected behavior in response to this probe. Originally-by: Benedikt Spranger Signed-off-by: Jan Kiszka Signed-off-by: Thomas Gleixner Reviewed-by: Andy Shevchenko Acked-by: Bjorn Helgaas Cc: jailhouse-dev@googlegroups.com Cc: Benedikt Spranger Cc: linux-pci@vger.kernel.org Cc: virtualization@lists.linux-foundation.org Link: https://lkml.kernel.org/r/06e279b2a3e06cf6689ab3975f8ab592bba02362.1520408357.git.jan.kiszka@siemens.com --- arch/x86/pci/legacy.c | 4 +++- drivers/pci/probe.c | 22 +++++++++++++++++++--- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/arch/x86/pci/legacy.c b/arch/x86/pci/legacy.c index 1cb01abcb1be..dfbe6ac38830 100644 --- a/arch/x86/pci/legacy.c +++ b/arch/x86/pci/legacy.c @@ -4,6 +4,7 @@ #include #include #include +#include #include /* @@ -34,13 +35,14 @@ int __init pci_legacy_init(void) void pcibios_scan_specific_bus(int busn) { + int stride = jailhouse_paravirt() ? 1 : 8; int devfn; u32 l; if (pci_find_bus(0, busn)) return; - for (devfn = 0; devfn < 256; devfn += 8) { + for (devfn = 0; devfn < 256; devfn += stride) { if (!raw_pci_read(0, busn, devfn, PCI_VENDOR_ID, 2, &l) && l != 0x0000 && l != 0xffff) { DBG("Found device at %02x:%02x [%04x]\n", busn, devfn, l); diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c index ef5377438a1e..3c365dc996e7 100644 --- a/drivers/pci/probe.c +++ b/drivers/pci/probe.c @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include "pci.h" @@ -2518,14 +2519,29 @@ static unsigned int pci_scan_child_bus_extend(struct pci_bus *bus, { unsigned int used_buses, normal_bridges = 0, hotplug_bridges = 0; unsigned int start = bus->busn_res.start; - unsigned int devfn, cmax, max = start; + unsigned int devfn, fn, cmax, max = start; struct pci_dev *dev; + int nr_devs; dev_dbg(&bus->dev, "scanning bus\n"); /* Go find them, Rover! */ - for (devfn = 0; devfn < 0x100; devfn += 8) - pci_scan_slot(bus, devfn); + for (devfn = 0; devfn < 256; devfn += 8) { + nr_devs = pci_scan_slot(bus, devfn); + + /* + * The Jailhouse hypervisor may pass individual functions of a + * multi-function device to a guest without passing function 0. + * Look for them as well. + */ + if (jailhouse_paravirt() && nr_devs == 0) { + for (fn = 1; fn < 8; fn++) { + dev = pci_scan_single_device(bus, devfn + fn); + if (dev) + dev->multifunction = 1; + } + } + } /* Reserve buses for SR-IOV capability */ used_buses = pci_iov_bus_range(bus);