Received: by 10.223.185.116 with SMTP id b49csp5830937wrg; Tue, 27 Feb 2018 22:36:16 -0800 (PST) X-Google-Smtp-Source: AH8x227st9qLEnsRqdeaA0YxmyE2yW9iRKs7pKqm/7g7lK9wFNe4U+ersX0r3VActeAwtHAjPwro X-Received: by 2002:a17:902:5269:: with SMTP id z96-v6mr16925524plh.385.1519799776648; Tue, 27 Feb 2018 22:36:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519799776; cv=none; d=google.com; s=arc-20160816; b=d4H3fpKB5xjj9g5mv077PYcw+WUtzPHa8i1pXPyd29APeDj4vt4CwfqhXxyYahj1// BK7blUGGvoe7QoJNTVWe8MRBGuHs/UAhHScgMhIElZPGbTwUWv2vZdRt24OB4HE706lH 5uwuG/et96UpS/7llq/aRdmDzYY9azeU9Wwg2HAzQbPQDANoCLiM1Gon4dSDGQlVLx/F SKYmz33VnFTkhFL+J6QO0OAC+Lf0cDmJUr3PHLvnKb/Txd6Da9IVodXwufnXXlFCCw3M 5I4BQbt+9KRfRPPO+J+sG6awjnMjzzFPnQGNtz8uEgq9zLXyb5GjCDuYJll99EFHuj3C T4Gw== 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=Kwy93ampuD6hmqFo/u5IU7q4sRpAjAn7G4VbHVV40FE=; b=PfGlCEkBikTrbhWlAciNLWaRh4fDEeY6QyJXv8SAxtPoWYS2HJYHtp0c2I4KILjgyP 5LdMmlj1vQtjTg0kqMqWpTheYoHvBWb1lcw/89tZgRPW22uMRgdBsgWDHI6HTWQEPnTf 6lceG4VQEWcOtt3vtsZX4TRYCjYjPiVu4A4tH/4YakGacYKw4gfZL5jWMpVYiOcdvDNv 8AN8tI95VtWSJSPPOc2a9cDfk90eckAVCQLzP6ysgouKsfPXXcL8NjnLqjmvNcTO6niQ idGGAHKTVwCN1Iqb+D41m8IDyi+CNo88aji77h/JqHSGgB+tfkCEFyhLejpewRDG//MV PTQw== 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 f5-v6si791460plj.201.2018.02.27.22.36.02; Tue, 27 Feb 2018 22:36:16 -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 S1752120AbeB1GfX (ORCPT + 99 others); Wed, 28 Feb 2018 01:35:23 -0500 Received: from david.siemens.de ([192.35.17.14]:45985 "EHLO david.siemens.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751721AbeB1GfN (ORCPT ); Wed, 28 Feb 2018 01:35:13 -0500 Received: from mail3.siemens.de (mail3.siemens.de [139.25.208.14]) by david.siemens.de (8.15.2/8.15.2) with ESMTPS id w1S6YuUZ013920 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 28 Feb 2018 07:34:56 +0100 Received: from md1f2u6c.ww002.siemens.net ([167.87.77.211]) by mail3.siemens.de (8.15.2/8.15.2) with ESMTP id w1S6Yqu4013249; Wed, 28 Feb 2018 07:34:55 +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, Benedikt Spranger Subject: [PATCH v2 2/6] PCI: Scan all functions when running over Jailhouse Date: Wed, 28 Feb 2018 07:34:47 +0100 Message-Id: <021d3dde4276c9bf4325f7bdc37e3c47069e48fc.1519799691.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. 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 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..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..ce728251ae36 100644 --- a/drivers/pci/probe.c +++ b/drivers/pci/probe.c @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include "pci.h" @@ -2517,6 +2518,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; @@ -2524,7 +2526,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