From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C708AC433EF for ; Thu, 21 Oct 2021 11:35:56 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 283E060EFE for ; Thu, 21 Oct 2021 11:35:56 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 283E060EFE Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=nongnu.org Received: from localhost ([::1]:44318 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mdWMV-000648-A7 for qemu-devel@archiver.kernel.org; Thu, 21 Oct 2021 07:35:55 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46916) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mdWKs-0004bA-KT for qemu-devel@nongnu.org; Thu, 21 Oct 2021 07:34:16 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:27994) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mdWKq-0005zS-Eb for qemu-devel@nongnu.org; Thu, 21 Oct 2021 07:34:13 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1634816051; h=from:from:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=kldq/+LkGWYAfDieXzBYvHh2N/UigpZAVC4bKn5V1us=; b=g8zQ46XZJMx7heH7tG4igkW3ztWoxA5XCnojwgP2K/I+BqhHunr8qQSUI/bmfHvvXfuHS1 Pk7r5K4jX1jbKnahdfISQspJTczu5HGKrs5K+bSeHNYZRNEncjYXfBBneDaANdtYvQNz2s 9OUKKKtOxBXlutKmHTlraFdhMCzZswY= Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-249-oBMkNhNGMPKFiH_H98m3PA-1; Thu, 21 Oct 2021 07:34:10 -0400 X-MC-Unique: oBMkNhNGMPKFiH_H98m3PA-1 Received: by mail-wr1-f71.google.com with SMTP id c4-20020a5d6cc4000000b00160edc8bb28so83035wrc.9 for ; Thu, 21 Oct 2021 04:34:10 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:reply-to:subject:to:cc:references:from :message-id:date:user-agent:mime-version:in-reply-to :content-transfer-encoding:content-language; bh=kldq/+LkGWYAfDieXzBYvHh2N/UigpZAVC4bKn5V1us=; b=CDCfdqBBasM5/mv7Kl5H2Temf9NnlewWprop9xBjx0COmtf/bi2Rm/W3sxSFYlNRC5 Lf/sJqLoJAKGupbayesVbiKKa1j//XM3o94AyL5rgsOgKX9mPsLzLuYrstexlgrAt2br kAtandF0UrE0PNIOhngEGNZw2WOP6tDi/HG8TTdGpI275map3WNzJ2sTIln1/C/RHL9M OFkIrhzSLzwzM+PMafXZgvdjoLO3DttgGapM0Z1BT0/hN8N4A47xCsiAld2EkBilKkKB g3LXAWjRiv3Un2TKfMfAfpLwwLxdzTjvlPTXcufSB3XqMnfLqKaE5x1u8ID6SduWxitN Z1gw== X-Gm-Message-State: AOAM530uN2Ew4sOUrLQ1GFGT/wc1tuNUzD35nTldYOWgxotz+s2hIGWF GXj7BmLYV7/7/iDdZX8K7Hfs0okWEIMt3c2bhoIJmjJOQ9vHrRY7pGI3sSmc77uFTNHAniQSXWQ NovxggaCmqUi5I/M= X-Received: by 2002:a05:6000:15c6:: with SMTP id y6mr6644504wry.210.1634816049358; Thu, 21 Oct 2021 04:34:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx9/94PnRqZbktvh9NrTdpCz8r4hgI7StyALy+426HzeFLcVI0BrVkE78EEA8rNd4ISXcNq4w== X-Received: by 2002:a05:6000:15c6:: with SMTP id y6mr6644471wry.210.1634816049084; Thu, 21 Oct 2021 04:34:09 -0700 (PDT) Received: from ?IPv6:2a01:e0a:59e:9d80:527b:9dff:feef:3874? ([2a01:e0a:59e:9d80:527b:9dff:feef:3874]) by smtp.gmail.com with ESMTPSA id n12sm5622234wri.22.2021.10.21.04.34.07 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 21 Oct 2021 04:34:08 -0700 (PDT) Subject: Re: [PATCH 3/8] pci: Use pci_for_each_device_under_bus*() To: Peter Xu , qemu-devel@nongnu.org References: <20211021104259.57754-1-peterx@redhat.com> <20211021104259.57754-4-peterx@redhat.com> From: Eric Auger Message-ID: Date: Thu, 21 Oct 2021 13:34:07 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.10.1 MIME-Version: 1.0 In-Reply-To: <20211021104259.57754-4-peterx@redhat.com> Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=eric.auger@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Content-Language: en-US Received-SPF: pass client-ip=216.205.24.124; envelope-from=eric.auger@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -56 X-Spam_score: -5.7 X-Spam_bar: ----- X-Spam_report: (-5.7 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, NICE_REPLY_A=-2.867, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: eric.auger@redhat.com Cc: Peter Maydell , "Daniel P . Berrange" , Eduardo Habkost , "Michael S . Tsirkin" , Jason Wang , David Hildenbrand , Markus Armbruster , Shannon Zhao , Alex Williamson , Paolo Bonzini , Igor Mammedov , David Gibson Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Hi Peter, On 10/21/21 12:42 PM, Peter Xu wrote: > Replace all the call sites of existing pci_for_each_device*() where the bus > number is calculated from a PCIBus* already. It should avoid the lookup of the > PCIBus again. > > Signed-off-by: Peter Xu > --- > hw/i386/acpi-build.c | 5 ++--- > hw/pci/pcie.c | 4 +--- > hw/ppc/spapr_pci.c | 12 +++++------- > hw/ppc/spapr_pci_nvlink2.c | 7 +++---- > hw/ppc/spapr_pci_vfio.c | 4 ++-- > hw/s390x/s390-pci-bus.c | 5 ++--- > hw/xen/xen_pt.c | 4 ++-- > 7 files changed, 17 insertions(+), 24 deletions(-) > > diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c > index 81418b7911..a76b17ed92 100644 > --- a/hw/i386/acpi-build.c > +++ b/hw/i386/acpi-build.c > @@ -2132,8 +2132,7 @@ dmar_host_bridges(Object *obj, void *opaque) > PCIBus *bus = PCI_HOST_BRIDGE(obj)->bus; > > if (bus && !pci_bus_bypass_iommu(bus)) { > - pci_for_each_device(bus, pci_bus_num(bus), insert_scope, > - scope_blob); > + pci_for_each_device_under_bus(bus, insert_scope, scope_blob); > } > } > > @@ -2339,7 +2338,7 @@ ivrs_host_bridges(Object *obj, void *opaque) > PCIBus *bus = PCI_HOST_BRIDGE(obj)->bus; > > if (bus && !pci_bus_bypass_iommu(bus)) { > - pci_for_each_device(bus, pci_bus_num(bus), insert_ivhd, ivhd_blob); > + pci_for_each_device_under_bus(bus, insert_ivhd, ivhd_blob); > } > } > > diff --git a/hw/pci/pcie.c b/hw/pci/pcie.c > index 6e95d82903..914a9bf3d1 100644 > --- a/hw/pci/pcie.c > +++ b/hw/pci/pcie.c > @@ -694,9 +694,7 @@ void pcie_cap_slot_write_config(PCIDevice *dev, > (!(old_slt_ctl & PCI_EXP_SLTCTL_PCC) || > (old_slt_ctl & PCI_EXP_SLTCTL_PIC_OFF) != PCI_EXP_SLTCTL_PIC_OFF)) { > PCIBus *sec_bus = pci_bridge_get_sec_bus(PCI_BRIDGE(dev)); > - pci_for_each_device(sec_bus, pci_bus_num(sec_bus), > - pcie_unplug_device, NULL); > - > + pci_for_each_device_under_bus(sec_bus, pcie_unplug_device, NULL); > pci_word_test_and_clear_mask(exp_cap + PCI_EXP_SLTSTA, > PCI_EXP_SLTSTA_PDS); > if (dev->cap_present & QEMU_PCIE_LNKSTA_DLLLA || > diff --git a/hw/ppc/spapr_pci.c b/hw/ppc/spapr_pci.c > index 7430bd6314..5bfd4aa9e5 100644 > --- a/hw/ppc/spapr_pci.c > +++ b/hw/ppc/spapr_pci.c > @@ -1317,8 +1317,7 @@ static int spapr_dt_pci_bus(SpaprPhbState *sphb, PCIBus *bus, > RESOURCE_CELLS_SIZE)); > > assert(bus); > - pci_for_each_device_reverse(bus, pci_bus_num(bus), > - spapr_dt_pci_device_cb, &cbinfo); > + pci_for_each_device_under_bus_reverse(bus, spapr_dt_pci_device_cb, &cbinfo); > if (cbinfo.err) { > return cbinfo.err; > } > @@ -2306,8 +2305,8 @@ static void spapr_phb_pci_enumerate_bridge(PCIBus *bus, PCIDevice *pdev, > return; > } > > - pci_for_each_device(sec_bus, pci_bus_num(sec_bus), > - spapr_phb_pci_enumerate_bridge, bus_no); > + pci_for_each_device_under_bus(sec_bus, spapr_phb_pci_enumerate_bridge, > + bus_no); > pci_default_write_config(pdev, PCI_SUBORDINATE_BUS, *bus_no, 1); > } > > @@ -2316,9 +2315,8 @@ static void spapr_phb_pci_enumerate(SpaprPhbState *phb) > PCIBus *bus = PCI_HOST_BRIDGE(phb)->bus; > unsigned int bus_no = 0; > > - pci_for_each_device(bus, pci_bus_num(bus), > - spapr_phb_pci_enumerate_bridge, > - &bus_no); > + pci_for_each_device_under_bus(bus, spapr_phb_pci_enumerate_bridge, > + &bus_no); > > } > > diff --git a/hw/ppc/spapr_pci_nvlink2.c b/hw/ppc/spapr_pci_nvlink2.c > index 8ef9b40a18..7fb0cf4d04 100644 > --- a/hw/ppc/spapr_pci_nvlink2.c > +++ b/hw/ppc/spapr_pci_nvlink2.c > @@ -164,8 +164,7 @@ static void spapr_phb_pci_collect_nvgpu(PCIBus *bus, PCIDevice *pdev, > return; > } > > - pci_for_each_device(sec_bus, pci_bus_num(sec_bus), > - spapr_phb_pci_collect_nvgpu, opaque); > + pci_for_each_device_under_bus(sec_bus, spapr_phb_pci_collect_nvgpu, opaque); > } > > void spapr_phb_nvgpu_setup(SpaprPhbState *sphb, Error **errp) > @@ -183,8 +182,8 @@ void spapr_phb_nvgpu_setup(SpaprPhbState *sphb, Error **errp) > sphb->nvgpus->nv2_atsd_current = sphb->nv2_atsd_win_addr; > > bus = PCI_HOST_BRIDGE(sphb)->bus; > - pci_for_each_device(bus, pci_bus_num(bus), > - spapr_phb_pci_collect_nvgpu, sphb->nvgpus); > + pci_for_each_device_under_bus(bus, spapr_phb_pci_collect_nvgpu, > + sphb->nvgpus); > > if (sphb->nvgpus->err) { > error_propagate(errp, sphb->nvgpus->err); > diff --git a/hw/ppc/spapr_pci_vfio.c b/hw/ppc/spapr_pci_vfio.c > index f3b37df8ea..2a76b4e0b5 100644 > --- a/hw/ppc/spapr_pci_vfio.c > +++ b/hw/ppc/spapr_pci_vfio.c > @@ -164,8 +164,8 @@ static void spapr_phb_vfio_eeh_clear_dev_msix(PCIBus *bus, > > static void spapr_phb_vfio_eeh_clear_bus_msix(PCIBus *bus, void *opaque) > { > - pci_for_each_device(bus, pci_bus_num(bus), > - spapr_phb_vfio_eeh_clear_dev_msix, NULL); > + pci_for_each_device_under_bus(bus, spapr_phb_vfio_eeh_clear_dev_msix, > + NULL); > } > > static void spapr_phb_vfio_eeh_pre_reset(SpaprPhbState *sphb) > diff --git a/hw/s390x/s390-pci-bus.c b/hw/s390x/s390-pci-bus.c > index 6fafffb029..1b51a72838 100644 > --- a/hw/s390x/s390-pci-bus.c > +++ b/hw/s390x/s390-pci-bus.c > @@ -1163,8 +1163,7 @@ static void s390_pci_enumerate_bridge(PCIBus *bus, PCIDevice *pdev, > } > > /* Assign numbers to all child bridges. The last is the highest number. */ > - pci_for_each_device(sec_bus, pci_bus_num(sec_bus), > - s390_pci_enumerate_bridge, s); > + pci_for_each_device_under_bus(sec_bus, s390_pci_enumerate_bridge, s); > pci_default_write_config(pdev, PCI_SUBORDINATE_BUS, s->bus_no, 1); > } > > @@ -1193,7 +1192,7 @@ static void s390_pcihost_reset(DeviceState *dev) > * on every system reset, we also have to reassign numbers. > */ > s->bus_no = 0; > - pci_for_each_device(bus, pci_bus_num(bus), s390_pci_enumerate_bridge, s); > + pci_for_each_device_under_bus(bus, s390_pci_enumerate_bridge, s); > } > > static void s390_pcihost_class_init(ObjectClass *klass, void *data) > diff --git a/hw/xen/xen_pt.c b/hw/xen/xen_pt.c > index ca0a98187e..027190fa44 100644 > --- a/hw/xen/xen_pt.c > +++ b/hw/xen/xen_pt.c > @@ -615,8 +615,8 @@ static void xen_pt_region_update(XenPCIPassthroughState *s, > } > > args.type = d->io_regions[bar].type; > - pci_for_each_device(pci_get_bus(d), pci_dev_bus_num(d), > - xen_pt_check_bar_overlap, &args); > + pci_for_each_device_under_bus(pci_get_bus(d), > + xen_pt_check_bar_overlap, &args); > if (args.rc) { > XEN_PT_WARN(d, "Region: %d (addr: 0x%"FMT_PCIBUS > ", len: 0x%"FMT_PCIBUS") is overlapped.\n", Maybe squash with the previous one? Besides Reviewed-by: Eric Auger Eric