Received: by 2002:a05:6a10:83d0:0:0:0:0 with SMTP id o16csp121712pxh; Thu, 7 Apr 2022 16:01:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwEbOPquiP0D3e6hSy9e8rJru3uB/4rmfzm4580RIuyKy1gGAaMcuzUu/YAi+iLzuuTTZkF X-Received: by 2002:a05:6808:1992:b0:2da:7ea7:7ef8 with SMTP id bj18-20020a056808199200b002da7ea77ef8mr6746776oib.49.1649372475118; Thu, 07 Apr 2022 16:01:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649372475; cv=none; d=google.com; s=arc-20160816; b=G7QR7xmPCMWc2J97li5RUnys97ICDyRRBGw36J4ad2ZLAEL45xh9nksl9xLOpIEVDk f40Ki/+hHZ7mygHnbK7JLDEHghUu8Ad8gstVoCgI04leCu5rLbXDB4cwp+ZtR8O65H14 NdmkUHEM3PlyU9PyyzTIL6jtIJsWsDl9o7/KiJY9VvPpBHZhZcuKJTGLweJ7S3QHfq+U brQAqY/qahzNqlaJaV+ztGW8Wfphs+m+DX4kZ2pHD+NHGaiwUjY+U5rhF56lbYao1zbC GjzjJEsAzfSvenD4kq92l4UW7XvTOjFS7YFlb/a4/LtjwatJe+uPuwzYsQgW3gqV/5TZ lXpQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :message-id:subject:cc:to:from:date:dkim-signature; bh=v2DaBYMHEgmnI8uPJOG51tPtMBXaMuKPAQx6ruFJqZY=; b=rdbRf3jQ7PidmgWas5N6uagJnGZU+6cfPpXQHd7gvqG8XF24dwcdEbXy3Coj1KGEtw lOOvCtfkYsOw0t8pfOg3myNdEcbxuESBCsHzkqmzIYTBx0Sp+Yi1oKvR9WKCZ2zbWTQQ eHiFjCfV31ROI5Kv6SkkUJJ/A9HYpQw6WIzkdGK6ZIaB+VWeda9rJ5sDgrkRsDquDqGt hDkPhyvHDA3BZlzJpU1rRJ15l2IPqeCM0mrccGZcMStfFGkB2j5XVbCznWnxJ8Hc6yie h9r/NFpOA7RZjN7w6vmp57AZhb5VB18nRmTVFKczFccnNaU0nMJMIBOsXOu750hic64k DhCw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=sp2hT5KY; 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=kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id j133-20020aca3c8b000000b002f934d24bcbsi11309605oia.186.2022.04.07.16.01.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Apr 2022 16:01:15 -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=@kernel.org header.s=k20201202 header.b=sp2hT5KY; 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=kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id A7E95106629; Thu, 7 Apr 2022 15:32:33 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232094AbiDGWe1 (ORCPT + 99 others); Thu, 7 Apr 2022 18:34:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52666 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231794AbiDGWeZ (ORCPT ); Thu, 7 Apr 2022 18:34:25 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 298B113E88; Thu, 7 Apr 2022 15:32:20 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id E2130B829A7; Thu, 7 Apr 2022 22:32:18 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 87E89C385A4; Thu, 7 Apr 2022 22:32:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1649370737; bh=dLO/D3nL1f64UtF+spus0K/GKQhrE9Nu7Ou/L3Uy3Og=; h=Date:From:To:Cc:Subject:In-Reply-To:From; b=sp2hT5KYp7bW4QdGUrzkGf9SF8LKBQzemdv3dG17BeeB22Gnh5mcP+N63zIS3e7RZ oKgpzP1R1M1qhREYzqttHyuQcwC2FtahaqOThIckfBvDTHAFTfyyNl/B4f39VhB6OM A0yvh36KkV/qDROrWFB47X7jUWwnmP7TkrZQE32vuDZM2uwUdNssAzC0TkY1q255nH hmSRnLcZ2mB/g2WKn8s1ewap2863WH47CmFEbJDbULXIfBOnTRSQCNQE0x3Gs4uO23 PiaUcM5MhJ3H+3K/7GIsw+2A56lL9DUkjTiTu7+DG6txE5ROn2Tq69Ih5IlJzlv00o /AUuItqOwm6zQ== Date: Thu, 7 Apr 2022 17:32:15 -0500 From: Bjorn Helgaas To: Shlomo Pongratz Cc: linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, andrew.maier@eideticom.com, logang@deltatee.com, bhelgaas@google.com, jgg@nvidia.com, Shlomo Pongratz Subject: Re: [PATCH V6 1/1] Intel Sky Lake-E host root ports check. Message-ID: <20220407223215.GA265412@bhelgaas> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220403102008.7122-2-shlomop@pliops.com> X-Spam-Status: No, score=-2.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 On Sun, Apr 03, 2022 at 01:20:08PM +0300, Shlomo Pongratz wrote: > In commit 7b94b53db34f ("PCI/P2PDMA: Add Intel Sky Lake-E Root Ports B, C, > D to the whitelist") > Andrew Maier added the Sky Lake-E additional devices > 2031, 2032 and 2033 root ports to the already existing 2030 device. > > The Intel devices 2030, 2031, 2032 and 2033 which are root ports A, B, C > and D, respectively and if all exist they will occupy slots 0 till 3 in > that order. > > The original code handled only the case where the devices in the whitelist > are host bridges and assumed that they will be found on slot 0. > > Since this assumption doesn't hold for root ports, add a test to cover this > case. > > Signed-off-by: Shlomo Pongratz > --- > drivers/pci/p2pdma.c | 25 ++++++++++++++++++------- > 1 file changed, 18 insertions(+), 7 deletions(-) > > diff --git a/drivers/pci/p2pdma.c b/drivers/pci/p2pdma.c > index 30b1df3c9d2f..c281bf5b304a 100644 > --- a/drivers/pci/p2pdma.c > +++ b/drivers/pci/p2pdma.c > @@ -327,15 +327,19 @@ static const struct pci_p2pdma_whitelist_entry { > > /* > * This lookup function tries to find the PCI device corresponding to a given > - * host bridge. > + * host bridge or a root port. > * > * It assumes the host bridge device is the first PCI device in the > - * bus->devices list and that the devfn is 00.0. These assumptions should hold > - * for all the devices in the whitelist above. > + * bus->devices list and that the devfn is 00.0. The first assumption should > + * hold for all the devices in the whitelist above, however the second > + * assumption doesn't always hold for root ports. > + * For example for Intel Skylake devices 2030, 2031, 2032 and 2033, > + * which are root ports (A, B, C and D respectively). > + * So the function checks explicitly that the device is a root port. > * > - * This function is equivalent to pci_get_slot(host->bus, 0), however it does > - * not take the pci_bus_sem lock seeing __host_bridge_whitelist() must not > - * sleep. > + * This function is equivalent to pci_get_slot(host->bus, 0) (except for > + * the root port test), however it does not take the pci_bus_sem lock seeing > + * __host_bridge_whitelist() must not sleep. > * > * For this to be safe, the caller should hold a reference to a device on the > * bridge, which should ensure the host_bridge device will not be freed > @@ -350,7 +354,14 @@ static struct pci_dev *pci_host_bridge_dev(struct pci_host_bridge *host) > > if (!root) > return NULL; > - if (root->devfn != PCI_DEVFN(0, 0)) > + > + /* Verify that the device is a host bridge or a root port > + * It is assumed that host bridges have a 0 devfn, (common practice) > + * but some of the entries in the whitelist are root ports that can > + * have any devfn > + */ > + if (root->devfn != PCI_DEVFN(0, 0) && > + pci_pcie_type(root) != PCI_EXP_TYPE_ROOT_PORT) > return NULL; > > return root; The negative logic here makes this hard to read. The previous code was the same as: if (root->devfn == PCI_DEVFN(0, 0)) return root; return NULL; I think this patch would be easier to read if you made it: if (root->devfn == PCI_DEVFN(0, 0)) return root; if (pci_pcie_type(root) == PCI_EXP_TYPE_ROOT_PORT) return root; return NULL; IIUC, this patch tweaks it so we take the first device on the bus and if it is either 00.0 or a Root Port, we search pci_p2pdma_whitelist[] for it.