Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp3044830imm; Fri, 10 Aug 2018 02:50:01 -0700 (PDT) X-Google-Smtp-Source: AA+uWPx3XpwlUpk4Sgq9EvDBIymAdkg+1s2Ix3qdCV79rp3AkFts2eHtVyoulFoe4XQCbCoPlttT X-Received: by 2002:a63:cd4c:: with SMTP id a12-v6mr5799690pgj.15.1533894601600; Fri, 10 Aug 2018 02:50:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533894601; cv=none; d=google.com; s=arc-20160816; b=dIuqpSLrLXrT3Pak8KluzmL//gqVqdGcTQnRRAU/T2Y1LE15hqVNGz64QQdno4fx9j lRtQ2hYw8xtNKyA7dSUVVvxx9+hR1qWHUyQ0Fqg6m25uV6zydsHTJppKCb9nqpvFtoqR HNntO1R9s96v4La6uNio36TxU1dlf08zONNs2suw7WhISK6op2i8K72KmjhvHW10gxRA MGuLzFERIn0M4iTJJUW5s+JhtXzs5nk1fGZLXTuPTecE7IyQSLZE7/C5eIg0QuK3+08a nDUGOV2vwf+zptty4LfGOJpjhr2rkTzGw/HV5Ct0lFjIrcQBsu9C74lSk5TVlo5/I6q8 SGSg== 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:arc-authentication-results; bh=E6y1a2P6a0z4IPscB/CftoQIZpI4CDoMrdFGqTDm/dc=; b=gx4gppb3FxBj6t51aycSXpLAGH2c2Qc225HvFW5KuDPqWo34vbpJn6TVMVU1wQAYxO YwWQHQbr3ZIN6MWkM9VPEeAzO+52DDo6VSSjhpFQfmAHeeiH0Z9A4mregmISxIFNl19d yHP3MdgllN7jZTMB5/uagBFShR7kMLg66nhOeMqLtAM8QKth297Oo9hcvWq62yicWlAY eqoxMqRoLZOAht07urjW90WifYTCIDlQXRgvPL8OoRj2TE7R6KgZ3LCVVLeo51KJyiQd mmii8yaLPdqp7Zsfjei136gV3CqgFVbS9ctFanDX2HyzLOpYjZGXzNOQoz0WuylKhqSa f9yw== 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 144-v6si10372329pge.406.2018.08.10.02.49.47; Fri, 10 Aug 2018 02:50:01 -0700 (PDT) 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 S1727555AbeHJMKx (ORCPT + 99 others); Fri, 10 Aug 2018 08:10:53 -0400 Received: from nikam.ms.mff.cuni.cz ([195.113.20.16]:56048 "EHLO nikam.ms.mff.cuni.cz" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727117AbeHJMKx (ORCPT ); Fri, 10 Aug 2018 08:10:53 -0400 Received: by nikam.ms.mff.cuni.cz (Postfix, from userid 2587) id A5B69543585; Fri, 10 Aug 2018 11:35:01 +0200 (CEST) Date: Fri, 10 Aug 2018 11:35:01 +0200 From: Martin Mares To: Matthew Wilcox Cc: Logan Gunthorpe , linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, linux-doc@vger.kernel.org, Stephen Bates , Christoph Hellwig , Bjorn Helgaas , Jonathan Corbet , Ingo Molnar , Thomas Gleixner , "Paul E. McKenney" , Marc Zyngier , Kai-Heng Feng , Frederic Weisbecker , Dan Williams , =?utf-8?B?SsOpcsO0bWU=?= Glisse , Benjamin Herrenschmidt , Alex Williamson , Christian =?utf-8?B?S8O2bmln?= Subject: Re: lspci: Display path to device Message-ID: References: <20180717170204.30470-1-logang@deltatee.com> <20180717203900.GA1771@bombadil.infradead.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180717203900.GA1771@bombadil.infradead.org> User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hello! > I don't like telling the user to grovel around lspci -t by hand. It's > not many lines of code to add a new -P option to lspci to show the path > to each device instead of bus:dev.fn I like the feature, but I have a couple of minor objections to the implementation: > -static char options[] = "nvbxs:d:ti:mgp:qkMDQ" GENERIC_OPTIONS ; > +static char options[] = "nvbxs:d:tPi:mgp:qkMDQ" GENERIC_OPTIONS ; Please update the help_msg, too. > +static void > +show_slot_path(struct pci_dev *p) > +{ > + struct pci_dev *d = NULL; > + > + if (opt_path && p->bus) > + { > + for (d = p->access->devices; d; d = d->next) { > + if (d->hdrtype == -1) > + d->hdrtype = pci_read_byte(d, PCI_HEADER_TYPE) & 0x7f; Please do not modify the hdrtype field, it is private to libpci. Instead, always read the PCI_HEADER_TYPE register. It will be fast since lspci caches configuration space accesses. > + if (d->hdrtype != PCI_HEADER_TYPE_BRIDGE && > + d->hdrtype != PCI_HEADER_TYPE_CARDBUS) > + continue; > + if (pci_read_byte(d, PCI_SECONDARY_BUS) > p->bus) > + continue; > + if (pci_read_byte(d, PCI_SUBORDINATE_BUS) < p->bus) > + continue; Beware, cardbus bridges use different registers for secondary and subordinate bus. ... the more I think about it, the more I am convinced that we want to re-use the bus topology builder from ls-tree.c. I will give it a try, stay tuned. Martin