Received: by 10.223.185.116 with SMTP id b49csp7255680wrg; Thu, 1 Mar 2018 02:29:47 -0800 (PST) X-Google-Smtp-Source: AG47ELueTj7ieh/+YBiWtaZ8FzQItqrxgPEec88ZKCxnWGMls+OUpP7AqiWlOX/7IO1F8LpYvO6X X-Received: by 2002:a17:902:768b:: with SMTP id m11-v6mr1469833pll.185.1519900187860; Thu, 01 Mar 2018 02:29:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519900187; cv=none; d=google.com; s=arc-20160816; b=IesGvQ7R3iVozLjPHhY/zBP8k/XODdl8P+c9ceqzmTSL7V6DlMXysSx4DERx7gfZZf QnPrYEuhCr2HBreZEvJEfeHj5GcPTaxgUmF4a/BGt40/sQroKN+BJJx+wlXc5Za0zQSM hrBU9USBOKfZbPOV5e+okyZxlwNe093fRZZc8K6zbrfhJZ+SaFnrci8y5HzGSrhrtZbD UiKJJ4xXeJpKliJL5F4JOC2QlDXU2PnoLb1pMFCzvf88V5A4DMTt6gHlCvFSxdwYhJ4z MUhTg27W4WhvJFDE4s5yBwVyb6xNQoe5tTS2CdKdN1CFkyVgPpMXPtaOEF4FoiIaom10 dMhA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature :arc-authentication-results; bh=fghRh7Kqug7prOVBGQPDNriXQvSXJv+dCtlCmLwvQic=; b=Leiyte6XeYUi+GOPvxUPVR6Gn9DQUMH8rhWqH48cbKnaNAFEBMk0xoL4KBGU7zT25b 4sWdp3D92KRtrR5E5xqrNOKsmviC8rjGsMEO+Zk42yoqtg2xCShVFwPtRFtekBvdqL5e Jhp3GgPICdeogjEuN67BBSuA2xTqM1ixE5Qr9KgSAqQW9JES4KSzyaA2l2sfwBcnhA2v PGMgymWgoTfuBIx3bIfzxH2klr9x2wnVaieSbvyu5y/+GsJX9pIFiw09G8oyTbvnamCP dqtKB6xeFLnSEdM5M1fRoDpeeIlev4UjkPF+rYevZuw2KcVVMS1Ha7sMHIAkBTu69bWl VFPQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=bTNtPOr8; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h10si512511pgf.326.2018.03.01.02.29.33; Thu, 01 Mar 2018 02:29:47 -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; dkim=pass header.i=@gmail.com header.s=20161025 header.b=bTNtPOr8; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S966850AbeCAK2y (ORCPT + 99 others); Thu, 1 Mar 2018 05:28:54 -0500 Received: from mail-qt0-f193.google.com ([209.85.216.193]:35206 "EHLO mail-qt0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S966528AbeCAK2r (ORCPT ); Thu, 1 Mar 2018 05:28:47 -0500 Received: by mail-qt0-f193.google.com with SMTP id z14so6864014qti.2; Thu, 01 Mar 2018 02:28:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=fghRh7Kqug7prOVBGQPDNriXQvSXJv+dCtlCmLwvQic=; b=bTNtPOr8O+DuFJexNAXw/6OVpndplFl0itV5OeuHpN7vtCSWJWS4mDpV/+f9VDpdXL bkiPxtNMYv/rZg2FBrbuHm0x8LYsip3p4ShzKmcjc5h2hoaoOwmYCxMBd6M3umzLLv8g 8132t7d98xhOAyirQHQHlXa5Ij3wHBaSOBMCyDhnFwZARAIP55ToKpNA8uODk4yUs133 sPff8ShBQbYoz9zJEUOo8gKMr3NQ8Wi9Et+XCErrdaOm9GirxhGlUf167JOt+9Y7cQJf y/uBL4w+0zOGqNbQdOqORdZzNE7B4qcGDDwE/Lyow74ILovYKBo2+N7dGuOwSWoR6HZJ +Lzw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=fghRh7Kqug7prOVBGQPDNriXQvSXJv+dCtlCmLwvQic=; b=TZM99Pii9Z3ngjMC8ooykfhYsnm0Sg0jNbdm2JGschL1YsyOcXkNBcHRNMozBvf+bv 2lgs8Xp46yH/HnC4RGG0+mNkmWjNDT2rjsNyaTfpFvrt4i75KNAlQzkiM1Mgxcuht89e 1GdqI/N4iioJFyG1Qvj3uh3vJ/FjuP850H9ZZs3fM8yXMLS492X/d5XDMktWIZXsMANr W+yeATKC+jHk6m+w/vWzUD0UmlYXKdd/R6A5ow4Of2ND5QxyfFwA+9iSH9n+I5iMb/R3 BfFH7FiTBQdWD58ZN8y2gkS89gu6x5LU9GeukCdOk9RfSPfffQFwQYtqz4PMWuqlSC9a tAqw== X-Gm-Message-State: AElRT7G9ecPNEIx75GQ80oc7CCPHJGL/q5TneIP//T8oSMoGQ0xllh2f 9RshN2U5HdgwgstoEFQ+DdP+lWFgDW4SNcwNgFA= X-Received: by 10.237.48.229 with SMTP id 92mr2075787qtf.39.1519900126693; Thu, 01 Mar 2018 02:28:46 -0800 (PST) MIME-Version: 1.0 Received: by 10.12.195.80 with HTTP; Thu, 1 Mar 2018 02:28:45 -0800 (PST) In-Reply-To: <2b4c650d27e59c81903fa4c2526bf18a2cf2d243.1519882849.git.jan.kiszka@siemens.com> References: <2b4c650d27e59c81903fa4c2526bf18a2cf2d243.1519882849.git.jan.kiszka@siemens.com> From: Andy Shevchenko Date: Thu, 1 Mar 2018 12:28:45 +0200 Message-ID: Subject: Re: [PATCH v3 2/6] PCI: Scan all functions when running over Jailhouse To: Jan Kiszka Cc: Thomas Gleixner , Ingo Molnar , "H . Peter Anvin" , Bjorn Helgaas , x86@kernel.org, Linux Kernel Mailing List , jailhouse-dev@googlegroups.com, linux-pci@vger.kernel.org, virtualization@lists.linux-foundation.org, Benedikt Spranger Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Mar 1, 2018 at 7:40 AM, Jan Kiszka wrote: > 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. > FWIW, Reviewed-by: Andy Shevchenko One nit below. > CC: Benedikt Spranger > Signed-off-by: Jan Kiszka > Acked-by: Bjorn Helgaas > --- > 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..da22d6d216f8 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 < 0x100; devfn += 8) { Since you touch this line perhaps make sense to unify with above, i.e. 0x100 -> 256 ? > + 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 > -- With Best Regards, Andy Shevchenko