Received: by 10.223.185.116 with SMTP id b49csp2389415wrg; Thu, 22 Feb 2018 12:59:07 -0800 (PST) X-Google-Smtp-Source: AH8x227oALDRWb7Kn/x9pSEJ7Y8AhZlH+kh00SWZWFktV50u/tN23jhTaniRqBTDiqQqQYHavsuW X-Received: by 2002:a17:902:7b98:: with SMTP id w24-v6mr7790023pll.328.1519333147620; Thu, 22 Feb 2018 12:59:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519333147; cv=none; d=google.com; s=arc-20160816; b=m6Rt4AZ6ULl5SlbgdTYRAT90OEZw+OLCFw/0s4llSGuWfZoxd8giJKoTTCRaHaoHG1 XMOu3a5FpGwIBf4G3buFCSkwq6n/P4vZWmTn3k8yUpNq+XBvX5fkV/Jzl897/Km0iVRB V87RwuQzNka5RVgwEL81qXM9YC59Rwszbz9EtECh2J0xS96Te/eGyYBkI/itdX+kA/tQ wI/oRkOdIsSbJp5L7ovZWrntdA4kMCkf5bt7aQPpHlqUjFfB3X/xVJquiUYBsc0ufxU5 teLp0jni9pelZpjf2fMVos2E1koHiccYybVujXuTiLW3kRSE3nlK+tpk33mB3XGyc1qZ +Nfg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dmarc-filter:arc-authentication-results; bh=0ftySfsqvPHGpfYcvQ4B8T5aRTtuOxBhUEfVQCE1uuA=; b=zUgJvzlhqxViTn0G6XmXd5C0E1sWz3t+6OhFCelzb3Qjwf74Xy6UhINMrzswwdzSPl ml0j+pD4xPkBDw64n824h6GvgIGwWTFXfSLZZ+XW3Z1F3aA2HYYq4/1zNx1J7C1gGQzx 1WlX2VLzS0GK49Jdjd1SvMdbRUXKAA0ue95fq9SYOiny7nreghFhQM9Ig3LJJwvYe7e8 2FsJPyUbaL8eVOid3IVXWdVe3Z4FoUkC2LhU6zR6KfUlPng0hTFRIDKmeGXn4o/2Hpo+ +Cy5OWEIu/wb5u6wrSKlNayfhyERZvz5P7RP8OyljX47tyvYgEFP2r3EurzAYZAtHW0P /idw== 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 g23si204644pfg.341.2018.02.22.12.58.52; Thu, 22 Feb 2018 12:59:07 -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 S1751376AbeBVU56 (ORCPT + 99 others); Thu, 22 Feb 2018 15:57:58 -0500 Received: from mail.kernel.org ([198.145.29.99]:33240 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751119AbeBVU5z (ORCPT ); Thu, 22 Feb 2018 15:57:55 -0500 Received: from localhost (unknown [69.55.156.246]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 8EEFD21784; Thu, 22 Feb 2018 20:57:54 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8EEFD21784 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=helgaas@kernel.org Date: Thu, 22 Feb 2018 14:57:53 -0600 From: Bjorn Helgaas 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 Subject: Re: [PATCH 2/6] pci: Scan all functions when probing while running over Jailhouse Message-ID: <20180222205753.GE16519@bhelgaas-glaptop.roam.corp.google.com> References: <66bfcfc6dc1832baa3fbd8e4879764d36aa9c1e7.1516601570.git.jan.kiszka@siemens.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <66bfcfc6dc1832baa3fbd8e4879764d36aa9c1e7.1516601570.git.jan.kiszka@siemens.com> User-Agent: Mutt/1.9.2 (2017-12-15) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jan 22, 2018 at 07:12:46AM +0100, Jan Kiszka wrote: > From: Jan Kiszka > > PCI and PCIBIOS probing only scans devices at function number 0/8/16/... > Subdevices (e.g. multiqueue) have function numbers which are not a > multiple of 8. Suggested text: 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. > The simple hypervisor Jailhouse passes subdevices directly w/o providing > a virtual PCI topology like KVM. As a consequence a PCI passthrough from > Jailhouse to a guest will not be detected by Linux. > > Based on patch by Benedikt Spranger, adding Jailhouse probing to avoid > changing the behavior in the absence of the hypervisor. > > CC: Benedikt Spranger > Signed-off-by: Jan Kiszka With subject change to: PCI: Scan all functions when running over Jailhouse Acked-by: Bjorn Helgaas > --- > arch/x86/pci/legacy.c | 4 +++- > drivers/pci/probe.c | 4 +++- > 2 files changed, 6 insertions(+), 2 deletions(-) > > diff --git a/arch/x86/pci/legacy.c b/arch/x86/pci/legacy.c > index 1cb01abcb1be..a7b0476b4f44 100644 > --- a/arch/x86/pci/legacy.c > +++ b/arch/x86/pci/legacy.c > @@ -5,6 +5,7 @@ > #include > #include > #include > +#include > > /* > * Discover remaining PCI buses in case there are peer host bridges. > @@ -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 14e0ea1ff38b..60ad14c8245f 100644 > --- a/drivers/pci/probe.c > +++ b/drivers/pci/probe.c > @@ -17,6 +17,7 @@ > #include > #include > #include > +#include > #include "pci.h" > > #define CARDBUS_LATENCY_TIMER 176 /* secondary latency timer */ > @@ -2454,6 +2455,7 @@ static unsigned int pci_scan_child_bus_extend(struct pci_bus *bus, > unsigned int available_buses) > { > unsigned int used_buses, normal_bridges = 0, hotplug_bridges = 0; > + unsigned int stride = jailhouse_paravirt() ? 1 : 8; > unsigned int start = bus->busn_res.start; > unsigned int devfn, cmax, max = start; > struct pci_dev *dev; > @@ -2461,7 +2463,7 @@ static unsigned int pci_scan_child_bus_extend(struct pci_bus *bus, > dev_dbg(&bus->dev, "scanning bus\n"); > > /* Go find them, Rover! */ > - for (devfn = 0; devfn < 0x100; devfn += 8) > + for (devfn = 0; devfn < 0x100; devfn += stride) > pci_scan_slot(bus, devfn); > > /* Reserve buses for SR-IOV capability. */ > -- > 2.13.6 >