Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp799655pxb; Fri, 22 Apr 2022 11:23:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzkolgM7u5KmAgnfdmX5oS745QVsDBeSLO4CO/vzYPSLwqhvVp/knb0JOZPEmdXuQURHbzC X-Received: by 2002:a17:903:11c7:b0:154:b936:d1d4 with SMTP id q7-20020a17090311c700b00154b936d1d4mr5632392plh.78.1650651820176; Fri, 22 Apr 2022 11:23:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650651820; cv=none; d=google.com; s=arc-20160816; b=gUNxWfnzZkTz5zju0xVFblWHZGLWjXfJNag2DDwfpWcakDrnntbfokRPCir6myPk2N lrug/m9+Kci+SLfTr5ilA/FuT9HRvE9t5X6DRvuLil1s0ze8YiCtplBHLktXUQ2uklCA 9m1KNgXa24pmIULTfeDE8YX6jGpeQ00yqbyOb8IL/0uFyxH3wHd4cxXOoeYM6GEpg3jA BB6QorkHy+ogL9RmofkU9rHpTz8gw9Fk+7hN90L5pViuSxPNomgTi+VuF/N3a5kUPUUk qk/4kzXeN5Ce7Nre2MtxCJJEyoxviMBHxCbwUq11jo7ohNyDh4ziTjlOjn2/7OfkZGl4 0V1A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=9RJixS4WeRJM0mGb+47v6hlLi3zfcIYx/lFEH2QI33c=; b=cwXLsMMMC7j7ekb3uU4Kr5Q2WOOqPbmqsjN/eaG3j8Sr+QGgr6/QYLR5TmEu81JSvO 4FM5fIz87eu1lJkP0IeuqWWpBoK3tHKqvQ9hyCmHOVeKUnFdxXGR0wlK2vjioYtX/7cv 0YJqj1DSSex6/kPRQa2wrN7kp92xlDimQaDA19sAzdmHz7n0XHtp8p5YYbiimAATVDKB 1Am5OwuOKy3neB6Q1FJKm92RL2D8OadGZcqb3i5UASgUlwnaHJ9UDR7GfGkL5+8Rl6gP +ysnrtywHlG7Af01GzhRQAIyXnWskCL84gTZvWULrkjOAgUbihc+c74WrDUIs4CB0sUT wukg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=LQK4L9nq; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id 33-20020a630e61000000b0039cb8fe4bddsi8466313pgo.259.2022.04.22.11.23.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Apr 2022 11:23:40 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=LQK4L9nq; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 55593103DC3; Fri, 22 Apr 2022 10:53:39 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1448020AbiDVNcR (ORCPT + 99 others); Fri, 22 Apr 2022 09:32:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33292 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1447993AbiDVNcF (ORCPT ); Fri, 22 Apr 2022 09:32:05 -0400 Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 30382583BD; Fri, 22 Apr 2022 06:29:11 -0700 (PDT) Received: from pps.filterd (m0098396.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 23MBiYYQ028312; Fri, 22 Apr 2022 13:29:06 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : mime-version; s=pp1; bh=9RJixS4WeRJM0mGb+47v6hlLi3zfcIYx/lFEH2QI33c=; b=LQK4L9nqxBCNrkjJXoKarB1mFqKz8zGlMUH+fgKWlteI9gfWSvv6M07uaTl6ts6udq/W CUh4WYt6787UFnMQCzR+b/kcVe+oYcEU4caDATa9NBUVbYMU46BznVtolWJOOOTrFryZ nn7+8FW4mO38R9AoYcHxT2g0f/SxslfU27bj3iAGkpSKTaoN2KYKaTMMgIXDjwuOSKzF uRlMXSEae/LCHAT1R4oUUTx94fYborRU66+QztP6KdM5KC/Hogs+HjMxfD1tcIJbILlf z/3tkkkPBs2pIDYgO9nFaioXfBNC+e2HHfHJBgxfcF70BSFxXZzd/QJuLUYJNCeRYTuy Og== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 3fjff4cpcg-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 22 Apr 2022 13:29:05 +0000 Received: from m0098396.ppops.net (m0098396.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.43/8.16.0.43) with SMTP id 23MD0q00024469; Fri, 22 Apr 2022 13:29:05 GMT Received: from ppma03fra.de.ibm.com (6b.4a.5195.ip4.static.sl-reverse.com [149.81.74.107]) by mx0a-001b2d01.pphosted.com with ESMTP id 3fjff4cpbw-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 22 Apr 2022 13:29:04 +0000 Received: from pps.filterd (ppma03fra.de.ibm.com [127.0.0.1]) by ppma03fra.de.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 23MDJM9p011085; Fri, 22 Apr 2022 13:29:02 GMT Received: from b06avi18878370.portsmouth.uk.ibm.com (b06avi18878370.portsmouth.uk.ibm.com [9.149.26.194]) by ppma03fra.de.ibm.com with ESMTP id 3ffne97g9s-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 22 Apr 2022 13:29:02 +0000 Received: from d06av24.portsmouth.uk.ibm.com (d06av24.portsmouth.uk.ibm.com [9.149.105.60]) by b06avi18878370.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 23MDTB1h55837132 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 22 Apr 2022 13:29:11 GMT Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 5C2654203F; Fri, 22 Apr 2022 13:28:59 +0000 (GMT) Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 15DC042042; Fri, 22 Apr 2022 13:28:59 +0000 (GMT) Received: from tuxmaker.boeblingen.de.ibm.com (unknown [9.152.85.9]) by d06av24.portsmouth.uk.ibm.com (Postfix) with ESMTP; Fri, 22 Apr 2022 13:28:59 +0000 (GMT) From: Niklas Schnelle To: Bjorn Helgaas , Jan Kiszka , Matthew Rosato , Pierre Morel Cc: linux-kernel@vger.kernel.org, virtualization@lists.linux-foundation.org, linux-s390@vger.kernel.org, linux-pci@vger.kernel.org Subject: [PATCH v4 2/4] PCI: Move jailhouse's isolated function handling to pci_scan_slot() Date: Fri, 22 Apr 2022 15:28:56 +0200 Message-Id: <20220422132858.1213022-3-schnelle@linux.ibm.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220422132858.1213022-1-schnelle@linux.ibm.com> References: <20220422132858.1213022-1-schnelle@linux.ibm.com> X-TM-AS-GCONF: 00 X-Proofpoint-GUID: p2W33-X5_R8Fb5CTEgxtN1SQoDrwbEpH X-Proofpoint-ORIG-GUID: fydxqy7U7KgU1xA-vjVb6FI3l_X-5X1C Content-Transfer-Encoding: 8bit X-Proofpoint-UnRewURL: 0 URL was un-rewritten MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.858,Hydra:6.0.486,FMLib:17.11.64.514 definitions=2022-04-22_03,2022-04-22_01,2022-02-23_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 mlxlogscore=999 adultscore=0 clxscore=1015 lowpriorityscore=0 malwarescore=0 bulkscore=0 phishscore=0 suspectscore=0 priorityscore=1501 mlxscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2204220058 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The special case of the jailhouse hypervisor passing through individual PCI functions handles scanning for PCI functions even if function 0 does not exist. Currently this is done with an extra loop duplicating the one in pci_scan_slot(). By incorporating the check for jailhouse_paravirt() into pci_scan_slot() we can instead do this as part of the normal slot scan. Note that with the assignment of dev->multifunction gated by fn > 0 we set dev->multifunction unconditionally for all functions if function 0 is missing just as in the existing jailhouse loop. The only functional change is that we now call pcie_aspm_init_link_state() for these functions but this already happened if function 0 was passed through and should not be a problem. Cc: Jan Kiszka Link: https://lore.kernel.org/linux-pci/20220408224514.GA353445@bhelgaas/ Suggested-by: Bjorn Helgaas Signed-off-by: Niklas Schnelle --- drivers/pci/probe.c | 30 ++++++++++-------------------- 1 file changed, 10 insertions(+), 20 deletions(-) diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c index 2000e9858f12..ce4e41a7d358 100644 --- a/drivers/pci/probe.c +++ b/drivers/pci/probe.c @@ -2659,8 +2659,13 @@ int pci_scan_slot(struct pci_bus *bus, int devfn) if (fn > 0) dev->multifunction = 1; } else if (fn == 0) { - /* function 0 is required */ - break; + /* + * function 0 is required unless we are running on + * a hypervisor which passes through individual PCI + * functions. + */ + if (!jailhouse_paravirt()) + break; } fn = next_fn(bus, dev, fn); } while (fn >= 0); @@ -2859,29 +2864,14 @@ 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, fn, cmax, max = start; + unsigned int devfn, 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 < 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; - } - } - } + for (devfn = 0; devfn < 256; devfn += 8) + pci_scan_slot(bus, devfn); /* Reserve buses for SR-IOV capability */ used_buses = pci_iov_bus_range(bus); -- 2.32.0