Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp4021979pxb; Mon, 27 Sep 2021 07:47:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzn2+UQZHt/0EmbuolbaCrd70SlreHCHNryb1Ry/0Xg9FlVXRuU5M9IcTBvDPQGZFrlGRPb X-Received: by 2002:a17:90a:312:: with SMTP id 18mr20485691pje.178.1632754076878; Mon, 27 Sep 2021 07:47:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632754076; cv=none; d=google.com; s=arc-20160816; b=kkGlxx0v707mBpk33564pwUBhovfQPouy77z9VnZBG5COV2AQutF55LlrcuAnajA/Q r1re2S/CKA1rB1GYR4dNQtVB+t0RTTVMnFMjUc5O8xSPuqHZmWyPb6CeYRlKpjfZb+o3 Kf7iUtDkVDvAJw2/Hd36PEn13fL6fAciHBnJXHeF/qxkTPkdiyqoq+FJO6wkbbJMzDF8 mJd6Fc9ZbBTfDh4y2QS6VGsqBFGytF8DOueKwi0NfoYiz+H3dtsbhwS2I02JlT4ksGAx 8KbPKFeInJScGaBpmR9icG+b/IUxycNYUhNRX6kIktGQWVmbwL4YPK5wgWGqIFkzJEK0 3UDQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent:references:in-reply-to :subject:cc:to:from:message-id:date; bh=VUkT19S0s8hPNtsFxrha4ITCKNYnDmCnvPspgNJLohM=; b=zE/PRrdxQ3orqKgGiYuXb0LqXdQJ3ou43yc6d4umCaSy4TwDlkZiNMyWPZ6xfWVqqu Lz/U7bDoTFCCPaVnfTv3ipj+O04bkyl58MMXsNfdojpgzREAKa0hsLL89Qc7mHsqFgdB MhBY5fWCDQ/gr6Yqs51zH0D/QhTJ8kd+N4rneC65pm7lzkosks7TPVz+7i49kNLIKRel Uu0G0JMdSxmi4H5bRHBHC0vml4OQoaJdVODItkEMVreKBTNfGpsbQUu6TbEsd7ExiNS8 h41GK9xOAwWjod0RBCtMzeTyFAMu7qM81J6KQdA9zJ9h9V8ZCTC1uhSj2X7yMa2Y4vWm qt/g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m4si25080513pjg.26.2021.09.27.07.47.43; Mon, 27 Sep 2021 07:47:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234864AbhI0Oq4 (ORCPT + 99 others); Mon, 27 Sep 2021 10:46:56 -0400 Received: from mail.kernel.org ([198.145.29.99]:46094 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234799AbhI0Oq4 (ORCPT ); Mon, 27 Sep 2021 10:46:56 -0400 Received: from disco-boy.misterjones.org (disco-boy.misterjones.org [51.254.78.96]) (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 8580060FC2; Mon, 27 Sep 2021 14:45:18 +0000 (UTC) Received: from sofa.misterjones.org ([185.219.108.64] helo=why.misterjones.org) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1mUrsZ-00DGOU-2N; Mon, 27 Sep 2021 15:45:16 +0100 Date: Mon, 27 Sep 2021 15:45:14 +0100 Message-ID: <87r1dat6v9.wl-maz@kernel.org> From: Marc Zyngier To: Kishon Vijay Abraham I Cc: Thomas Gleixner , Bjorn Helgaas , , , Lorenzo Pieralisi , Subject: Re: [PATCH 1/3] PCI: Add support in pci_walk_bus() to invoke callback matching RID In-Reply-To: <4c6d6b57-d868-eccb-7cfb-66008af530bb@ti.com> References: <20210920064133.14115-1-kishon@ti.com> <20210920064133.14115-2-kishon@ti.com> <8735pzwrq0.wl-maz@kernel.org> <49b2ba0c-c69d-266c-5db6-549fab031ffd@ti.com> <87mto7unw1.wl-maz@kernel.org> <4c6d6b57-d868-eccb-7cfb-66008af530bb@ti.com> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM-LB/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL-LB/10.8 EasyPG/1.0.0 Emacs/27.1 (x86_64-pc-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: text/plain; charset=US-ASCII X-SA-Exim-Connect-IP: 185.219.108.64 X-SA-Exim-Rcpt-To: kishon@ti.com, tglx@linutronix.de, bhelgaas@google.com, linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, lorenzo.pieralisi@arm.com, lokeshvutla@ti.com X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 22 Sep 2021 02:26:09 +0100, Kishon Vijay Abraham I wrote: > > >>>> -void pci_walk_bus(struct pci_bus *top, int (*cb)(struct pci_dev *, void *), > >>>> - void *userdata) > >>>> +void __pci_walk_bus(struct pci_bus *top, int (*cb)(struct pci_dev *, void *), > >>>> + void *userdata, u32 rid, u32 mask) > >>>> { > >>>> struct pci_dev *dev; > >>>> struct pci_bus *bus; > >>>> @@ -399,13 +401,16 @@ void pci_walk_bus(struct pci_bus *top, int (*cb)(struct pci_dev *, void *), > >>>> } else > >>>> next = dev->bus_list.next; > >>>> > >>>> + if (mask != 0xffff && ((pci_dev_id(dev) & mask) != rid)) > >>> > >>> Why the check for the mask? I also wonder whether the mask should apply > >>> to the rid as well: > >> > >> If the mask is set for all 16bits, then there is not going to be two PCIe > >> devices which gets the same ITS device ID right? So no need for calculating > >> total number of vectors? > > > > Are we really arguing about the cost of a compare+branch vs some > > readability? Or is there an actual correctness issue here? > > It is for correctness. So existing pci_walk_bus() doesn't invoke cb based on > rid. So when we convert to __pci_walk_bus(), existing callers of pci_walk_bus() > might not invoke cb for some devices without the check. > > > >>> > >>> if ((pci_dev_id(dev) & mask) != (rid & mask)) > > > > Because I think the above expression is a lot more readable (and > > likely more correct) than what you are suggesting. > > That would result in existing pci_walk_bus() behave differently from what was > before this patch no? > > I'm having something like this below > +#define pci_walk_bus(top, cb, userdata) \ > + __pci_walk_bus((top), (cb), (userdata), 0x0, 0xffff) > > So if we add only "if ((pci_dev_id(dev) & mask) != (rid & mask))", > the callback will not be invoked for any devices (other than one > with rid = 0) But that *is* the bug, isn't it? If you want to parse all the devices, a mask of 0 is what you need. The mask defines the bits that you want to match against the RID you passed as a parameter. If you don't want to check any bit, don't pass any! Thanks, M. -- Without deviation from the norm, progress is not possible.