Received: by 10.223.185.116 with SMTP id b49csp4745994wrg; Tue, 6 Mar 2018 23:41:48 -0800 (PST) X-Google-Smtp-Source: AG47ELuMXXt2Mq14QjuBITO1tGx20FcebB9ghz13rDtzwyfP7Fg+K1ca+69Uols8R+UQJBvldTF7 X-Received: by 2002:a17:902:a60d:: with SMTP id u13-v6mr19252522plq.165.1520408508767; Tue, 06 Mar 2018 23:41:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520408508; cv=none; d=google.com; s=arc-20160816; b=JD6m/FE4jCN37Hm0s9X67R0a81+OHkNgRO5USyVtUSln2XjLumF/UyV/VrUdam5ZoU gTREdbeeR/drMDX0uJMEWiP4KGDwBh560+CgM+fhvZO+49Cju1PYE+Uto1JhMAj3yekG d6+FM5/3p5lszCwPYPBg7CXbta3hjNkQiERxvgrV1NrQrr84gbD+Jj6fD6oFC2JoGW5t nsOWjc5zQf/7FOtkRWVs3wM7Jcs3pvcQpkwc2GwSO9m1ccC8cLA4DURcR6uudiTZbxg4 ZbuWqkIWZrREVyKxk5u/BsIjGFk2qk2FRur7GScgtTQODpJCOJm/EtbP3byrArOBpUVW 9Bgg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=FFrXXGmDKsCbC141dbClQJJfZqJoML9ZhQOxQ8iIzx4=; b=XfeBrRAOteSeFuWXJQl0djwhvhhlq5Nh5OcAycdE4dCcMKpIF+WqhIrv57UUaA77P4 SnuGgnIhyUrm6gCsWivzjtCNfveC8QPUmHTiOavLjiozjUlX+R67eTuDAGEzgmwQhOek zJYSKpDGNjpBN/mCTy2NwXnJrZa8h9PcJ85LWbzsbBdERzDyMx9kNtA6XAJY6CP7O+kN orutFh1hwX2YY970c2rkyO32ietjMgVt52xwNB/VCSqdEOFOdxntmy8sbYczjBHtKAec +i9YkzkjYERLUSB54JcU9+u0HtSpALlhwI7ahFZJhjszxOgHd8rfzHzYYvXuoW7MY5Ja Qj7A== 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 g5si10376854pgo.211.2018.03.06.23.41.34; Tue, 06 Mar 2018 23:41:48 -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 S1751177AbeCGHjj (ORCPT + 99 others); Wed, 7 Mar 2018 02:39:39 -0500 Received: from goliath.siemens.de ([192.35.17.28]:50277 "EHLO goliath.siemens.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751110AbeCGHjg (ORCPT ); Wed, 7 Mar 2018 02:39:36 -0500 Received: from mail3.siemens.de (mail3.siemens.de [139.25.208.14]) by goliath.siemens.de (8.15.2/8.15.2) with ESMTPS id w277dLXd032113 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 7 Mar 2018 08:39:21 +0100 Received: from md1f2u6c.ww002.siemens.net ([167.87.11.133]) by mail3.siemens.de (8.15.2/8.15.2) with ESMTP id w277dIAi004697; Wed, 7 Mar 2018 08:39:21 +0100 From: Jan Kiszka To: Thomas Gleixner , Ingo Molnar , "H . Peter Anvin" , Bjorn Helgaas Cc: x86@kernel.org, Linux Kernel Mailing List , jailhouse-dev@googlegroups.com, linux-pci@vger.kernel.org, virtualization@lists.linux-foundation.org, Andy Shevchenko , Benedikt Spranger Subject: [PATCH v5 2/7] PCI: Scan all functions when running over Jailhouse Date: Wed, 7 Mar 2018 08:39:13 +0100 Message-Id: <06e279b2a3e06cf6689ab3975f8ab592bba02362.1520408357.git.jan.kiszka@siemens.com> X-Mailer: git-send-email 2.13.6 In-Reply-To: References: In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jan Kiszka 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. Derived from original patch by Benedikt Spranger. CC: Benedikt Spranger Signed-off-by: Jan Kiszka Acked-by: Bjorn Helgaas Reviewed-by: Andy Shevchenko --- 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); -- 2.13.6