All of lore.kernel.org
 help / color / mirror / Atom feed
From: Kenji Kaneshige <kaneshige.kenji@jp.fujitsu.com>
To: Yinghai Lu <yinghai@kernel.org>
Cc: "Eric W. Biederman" <ebiederm@xmission.com>,
	Jesse Barnes <jbarnes@virtuousgeek.org>,
	Alex Chiang <achiang@hp.com>,
	Bjorn Helgaas <bjorn.helgaas@hp.com>, Ingo Molnar <mingo@elte.hu>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"linux-pci@vger.kernel.org" <linux-pci@vger.kernel.org>,
	Ivan Kokshaysky <ink@jurassic.park.msu.ru>
Subject: Re: [PATCH 2/2] pci: only release that resource index is less than 3 -v5
Date: Thu, 29 Oct 2009 15:34:09 +0900	[thread overview]
Message-ID: <4AE93761.6000503@jp.fujitsu.com> (raw)
In-Reply-To: <4AE89992.3010801@kernel.org>

Yinghai Lu wrote:
> after
> 
> | commit 308cf8e13f42f476dfd6552aeff58fdc0788e566
> |
> |    PCI: get larger bridge ranges when space is available
> 
> found one of resource of peer root bus (0x00) get released from root
> resource. later one hotplug device can not get big range anymore.
> other peer root buses is ok.
> 
> it turns out it is from transparent path.
> 
> those resources will be used for pci bridge BAR updated.
> so need to limit it to 3.
> 
> v2: Jesse doesn't like it is in find_free_bus_resource...
>     try to move out of pci_bus_size_bridges loop.
> need to apply after:
> 	[PATCH] pci: pciehp update the slot bridge res to get big range for pcie devices - v4
> v3: add pci_setup_bridge calling after pci_bridge_release_not_used_res.
>     only clear release those res for x86.
> v4: Bjorn want to release use dev instead of bus.
> v5: Kenji pointed out it will have problem with several level bridge.
>     so let only handle leaf bridge.
> 
> Signed-off-by: Yinghai Lu <yinghai@kernel.org>
> 
> ---
>  arch/x86/pci/i386.c              |    6 ++
>  drivers/pci/hotplug/pciehp_pci.c |    2 
>  drivers/pci/setup-bus.c          |   81 ++++++++++++++++++++++++++++++++++++++-
>  include/linux/pci.h              |    2 
>  4 files changed, 90 insertions(+), 1 deletion(-)
> 
> Index: linux-2.6/drivers/pci/setup-bus.c
> ===================================================================
> --- linux-2.6.orig/drivers/pci/setup-bus.c
> +++ linux-2.6/drivers/pci/setup-bus.c
> @@ -319,6 +319,42 @@ static void pci_bridge_check_ranges(stru
>  	}
>  }
>  
> +void pci_bridge_release_not_used_res(struct pci_bus *bus)
> +{
> +	int idx;
> +	bool changed = false;
> +	struct pci_dev *dev;
> +	struct resource *r;
> +	unsigned long type_mask = IORESOURCE_IO | IORESOURCE_MEM |
> +				  IORESOURCE_PREFETCH;
> +
> +	/* for pci bridges res only */
> +	dev = bus->self;
> +	for (idx = PCI_BRIDGE_RESOURCES; idx < PCI_BRIDGE_RESOURCES + 3;
> +	    idx++) {

If this function is only for normal PCI bridge, we need additional
check at the head of this function.

	if ((dev->class >> 8) == PCI_CLASS_BRIDGE_CARDBUS)
		return;

if not, 3 should be 4 instead. And we can do as follows

        for (i = PCI_BRIDGE_RESOURCE; i <= PCI_BRIDGE_RESOURCE_END; i++) {

> +		r = &dev->resource[idx];
> +		if (r->flags & type_mask) {

How about
		if (!(r->flags & type_mask))
			continue;

> +			if (!r->parent)
> +				continue;
> +			/*
> +			 * if there is no child under that, we should release
> +			 * and use it.
> +			 */

I think this comment should be updated because whether "we should
release and use it" is decided by the caller of this function.

> +			if (!r->child && !release_resource(r)) {
> +				dev_info(&dev->dev,
> +					 "resource %d %pRt released\n",
> +					 idx, r);
> +				r->flags = 0;
> +				changed = true;
> +			}

How about
		if (r->child)
			continue;

		if (!release_resource(r)) {
			...
		}

> +		}
> +	}
> +
> +	if (changed)
> +		pci_setup_bridge(bus);

The pci_setup_bridge() is called even if some resources are used
by children. For example, mem resource is used by children, but
prefetchable mem resource is not used by children. In this case,
I think mem resource is released and pci_setup_bridge() is called
while prefetcable mem resource is being used. I'm worrying that it
might cause something wrong.

> +}
> +EXPORT_SYMBOL(pci_bridge_release_not_used_res);
> +
>  /* Helper function for sizing routines: find first available
>     bus resource of a given type. Note: we intentionally skip
>     the bus resources which have already been assigned (that is,
> @@ -576,6 +612,48 @@ void __ref pci_bus_size_bridges(struct p
>  }
>  EXPORT_SYMBOL(pci_bus_size_bridges);
>  
> +
> +/* only release those resources that is on leaf bridge */
> +void __ref pci_bus_release_bridges_not_used_res(struct pci_bus *bus)
> +{
> +	struct pci_dev *dev;
> +	bool is_leaf_bridge = true;
> +
> +	list_for_each_entry(dev, &bus->devices, bus_list) {
> +		struct pci_bus *b = dev->subordinate;
> +		if (!b)
> +			continue;
> +
> +		switch (dev->class >> 8) {
> +		case PCI_CLASS_BRIDGE_CARDBUS:
> +			is_leaf_bridge = false;
> +			break;
> +
> +		case PCI_CLASS_BRIDGE_PCI:
> +		default:
> +			is_leaf_bridge = false;
> +			pci_bus_release_bridges_not_used_res(b);
> +			break;
> +		}
> +	}
> +
> +	/* The root bus? */
> +	if (!bus->self)
> +		return;
> +
> +	switch (bus->self->class >> 8) {
> +	case PCI_CLASS_BRIDGE_CARDBUS:
> +		break;
> +
> +	case PCI_CLASS_BRIDGE_PCI:
> +	default:
> +		if (is_leaf_bridge)
> +			pci_bridge_release_not_used_res(bus);
> +		break;
> +	}
> +}

How about like below. This might need to be called with "pci_bus_sem" held.

void __ref pci_bus_release_bridges_not_used_res(struct pci_bus *bus)
{
        struct pci_bus *b;

        /* If the bus is cardbus, do nothing */
        if (bus->self && (bus->self->class >> 8) == PCI_CLASS_BRIDGE_CARDBUS)
                return;

        /* We only release the resources under the leaf bridge */
        if (list_empty(&bus->children)) {
                if (!pci_is_root_bus(bus))
                        pci_bridge_release_not_used_res(bus);
                return;
        }

        /* Scan child buses if the bus is not leaf */
        list_for_each_entry(b, &bus->children, node)
		pci_bus_release_bridges_not_used_res(b);
}

> +EXPORT_SYMBOL(pci_bus_release_bridges_not_used_res);
> +
>  void __ref pci_bridge_assign_resources(const struct pci_dev *bridge)
>  {
>  	struct pci_bus *b;
> @@ -644,7 +722,8 @@ static void pci_bus_dump_res(struct pci_
>  
>          for (i = 0; i < PCI_BUS_NUM_RESOURCES; i++) {
>                  struct resource *res = bus->resource[i];
> -                if (!res || !res->end)
> +
> +		if (!res || !res->end || !res->flags)
>                          continue;
>  
>  		dev_printk(KERN_DEBUG, &bus->dev, "resource %d %pRt\n", i, res);
> Index: linux-2.6/drivers/pci/hotplug/pciehp_pci.c
> ===================================================================
> --- linux-2.6.orig/drivers/pci/hotplug/pciehp_pci.c
> +++ linux-2.6/drivers/pci/hotplug/pciehp_pci.c
> @@ -98,6 +98,7 @@ int pciehp_configure_device(struct slot
>  		pci_dev_put(dev);
>  	}
>  
> +	pci_bridge_release_not_used_res(parent);

I guess this is for the slots that are empty at the boot time on non x86
systems. And it only works at the first hot-add. Correct? How about doing
this at the pciehp's slot initialization.


>  	pci_bus_size_bridges(parent);
>  	pci_clear_master(bridge);
>  	pci_bridge_assign_resources(bridge);
> @@ -171,6 +172,7 @@ int pciehp_unconfigure_device(struct slo
>  		}
>  		pci_dev_put(temp);
>  	}
> +	pci_bridge_release_not_used_res(parent);

How about call pci_bus_release_bridges_not_used_res() instead and
make pci_bridge_release_not_used_res() static function.

>  
>  	return rc;
>  }
> Index: linux-2.6/include/linux/pci.h
> ===================================================================
> --- linux-2.6.orig/include/linux/pci.h
> +++ linux-2.6/include/linux/pci.h
> @@ -759,6 +759,8 @@ int pci_vpd_truncate(struct pci_dev *dev
>  void pci_bridge_assign_resources(const struct pci_dev *bridge);
>  void pci_bus_assign_resources(const struct pci_bus *bus);
>  void pci_bus_size_bridges(struct pci_bus *bus);
> +void pci_bus_release_bridges_not_used_res(struct pci_bus *bus);
> +void pci_bridge_release_not_used_res(struct pci_bus *bus);
>  int pci_claim_resource(struct pci_dev *, int);
>  void pci_assign_unassigned_resources(void);
>  void pdev_enable_device(struct pci_dev *);
> Index: linux-2.6/arch/x86/pci/i386.c
> ===================================================================
> --- linux-2.6.orig/arch/x86/pci/i386.c
> +++ linux-2.6/arch/x86/pci/i386.c
> @@ -194,6 +194,7 @@ static void __init pcibios_allocate_reso
>  static int __init pcibios_assign_resources(void)
>  {
>  	struct pci_dev *dev = NULL;
> +	struct pci_bus *bus;
>  	struct resource *r;
>  
>  	if (!(pci_probe & PCI_ASSIGN_ROMS)) {
> @@ -213,6 +214,11 @@ static int __init pcibios_assign_resourc
>  		}
>  	}
>  
> +	/* Try to release bridge resources, that there is not child under it */
> +	list_for_each_entry(bus, &pci_root_buses, node) {
> +		pci_bus_release_bridges_not_used_res(bus);
> +	}
> +

If this is only for PCIe hotplug, I don't think we need it here (as
you're doing for non x86 platforms). If not, I think you should do
it in the another patch.

Thanks,
Kenji Kaneshige



  reply	other threads:[~2009-10-29  6:34 UTC|newest]

Thread overview: 129+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-10-21  7:19 [PATCH] pci: pciehp update the slot bridge res to get big range for pcie devices Yinghai Lu
2009-10-21 18:57 ` Alex Chiang
2009-10-22  0:29   ` [PATCH] pci: pciehp update the slot bridge res to get big range for pcie devices - v2 Yinghai Lu
2009-10-26  4:54 ` [PATCH] pci: pciehp update the slot bridge res to get big range for pcie devices Kenji Kaneshige
2009-10-26  5:49   ` Yinghai Lu
2009-10-26  7:48     ` Kenji Kaneshige
2009-10-26  8:25       ` Yinghai Lu
2009-10-26 10:27         ` Kenji Kaneshige
2009-10-26 17:59           ` Yinghai Lu
2009-10-26 18:52             ` Yinghai Lu
2009-10-28  8:31               ` Kenji Kaneshige
2009-10-28 17:44                 ` Yinghai Lu
2009-10-28 17:52                   ` Bjorn Helgaas
2009-10-28 18:37                     ` Yinghai Lu
2009-10-28 19:00                   ` Eric W. Biederman
2009-10-28 19:12                     ` Yinghai Lu
2009-10-28 19:36                       ` Eric W. Biederman
2009-10-28 19:50                         ` Yinghai Lu
2009-10-28 21:30                           ` Eric W. Biederman
2009-10-28 21:39                             ` Yinghai Lu
2009-10-28 22:25                               ` Yinghai Lu
2009-10-28 22:26                                 ` Yinghai Lu
2009-10-29  8:16                                 ` Eric W. Biederman
2009-10-29  9:03                                   ` Yinghai Lu
2009-10-29 15:43                                     ` Eric W. Biederman
2009-10-29 17:00                                       ` Yinghai Lu
2009-10-29 19:48                                         ` Eric W. Biederman
2009-10-29 19:55                                           ` Yinghai Lu
2009-10-30  8:36                                           ` [PATCH 1/2] pci: release that leaf bridge' resource that is not big -v8 Yinghai Lu
2009-10-30  8:37                                             ` [PATCH 2/2] pci: pciehp update the slot bridge res to get big range for pcie devices - v8 Yinghai Lu
2009-11-10  8:00                                             ` [PATCH 1/2] pci: release that leaf bridge' resource that is not big -v8 Kenji Kaneshige
2009-10-29 13:21                                   ` [PATCH] pci: pciehp update the slot bridge res to get big range for pcie devices Bjorn Helgaas
2009-10-29 15:13                                     ` Eric W. Biederman
2009-10-29 15:43                                       ` Bjorn Helgaas
2009-10-29 19:28                                         ` Eric W. Biederman
2009-10-29 19:36                                           ` Bjorn Helgaas
     [not found]                     ` <4AE89933.8030809@kernel.org>
2009-10-28 19:20                       ` [PATCH 2/2] pci: only release that resource index is less than 3 -v5 Yinghai Lu
2009-10-29  6:34                         ` Kenji Kaneshige [this message]
2009-10-29  9:03                           ` Yinghai Lu
2009-10-28 19:21                     ` [PATCH 1/2] pci: pciehp update the slot bridge res to get big range for pcie devices - v4 Yinghai Lu
2009-10-29  8:28                       ` Kenji Kaneshige
2009-10-29  8:30                         ` Yinghai Lu
2009-10-29  8:55                           ` Kenji Kaneshige
2009-10-29  8:57                             ` Yinghai Lu
2009-10-29  9:52                             ` [PATCH 1/2] pci: release that leaf bridge' resource index is not used -v6 Yinghai Lu
2009-10-29 16:31                               ` Jesse Barnes
2009-10-29 17:10                                 ` Yinghai Lu
2009-10-29 17:51                                   ` Jesse Barnes
     [not found]                             ` <4AE9657F.7010302@kernel.org>
2009-10-29  9:52                               ` [PATCH 2/2] pci: pciehp update the slot bridge res to get big range for pcie devices - v5 Yinghai Lu
2009-11-04 17:30                                 ` Jesse Barnes
2009-11-04 18:52                                   ` Yinghai Lu
2009-11-05  1:40                                     ` [PATCH 1/2] pci: release that leaf bridge' resource that is not big -v9 Yinghai Lu
2009-11-05  1:40                                       ` [PATCH 2/2] pci: pciehp update the slot bridge res to get big range for pcie devices - v9 Yinghai Lu
2009-11-05 20:47                                         ` Alex Chiang
2009-11-05 21:06                                           ` Yinghai Lu
2009-11-07  5:41                                         ` [PATCH 2/2] pci: pciehp update the slot bridge res to get big range for pcie devices - v10 Yinghai Lu
2009-11-07  5:43                                         ` Yinghai Lu
2009-11-10  8:07                                           ` Kenji Kaneshige
2009-11-10  9:48                                             ` Yinghai Lu
2009-11-13  6:08                                               ` Kenji Kaneshige
2009-11-13  6:26                                                 ` Yinghai Lu
2009-11-13  8:33                                                   ` Kenji Kaneshige
2009-11-14  8:50                                                     ` [PATCH 1/2] pci: release that leaf bridge' resource that is not big -v11 Yinghai Lu
2009-11-24  1:08                                                       ` Kenji Kaneshige
2009-11-24  1:14                                                         ` Yinghai Lu
     [not found]                                                           ` <4B0B3C13.9030502@jp.fujit! su.com>
2009-11-24  1:51                                                           ` Kenji Kaneshige
2009-11-24  2:32                                                             ` Yinghai Lu
2009-11-24 23:18                                                             ` Yinghai Lu
2009-11-25 11:24                                                               ` Kenji Kaneshige
2009-11-25 11:25                                                                 ` [PATCH 1/2] pciehp: remove redundancy in bridge resource allocation Kenji Kaneshige
2009-11-25 17:37                                                                   ` Yinghai Lu
2009-11-25 11:27                                                                 ` [PATCH 2/2] pciehp: add support for bridge resource reallocation Kenji Kaneshige
2009-11-25 17:44                                                                 ` [PATCH 1/2] pci: release that leaf bridge' resource that is not big -v11 Yinghai Lu
2009-11-26  6:43                                                                   ` Kenji Kaneshige
2009-11-26  7:30                                                                     ` Yinghai
2009-11-27  7:12                                                                       ` Kenji Kaneshige
2009-11-27  7:52                                                                         ` Yinghai Lu
2009-11-27  8:26                                                                           ` Kenji Kaneshige
2009-11-27 23:13                                                                             ` Yinghai Lu
2009-11-25 19:58                                                                 ` [PATCH 0/9] pci: update pci bridge resource to get more big range for devices under it - v12 Yinghai Lu
     [not found]                                                                 ` <4B0D88A4.5050904@kerne! l.org>
     [not found]                                                                   ` <4B0D88A4.5050904@kernel.org>
2009-11-25 19:59                                                                     ` [PATCH 1/9] pci: separate pci_setup_bridge to small functions Yinghai Lu
2009-11-25 19:59                                                                     ` [PATCH 2/9] pci: add pci_bridge_release_unused_res and pci_bus_release_unused_bridge_res Yinghai Lu
2009-11-25 19:59                                                                     ` [PATCH 3/9] pci: don't dump it when bus resource flags is not set Yinghai Lu
2009-11-25 19:59                                                                     ` [PATCH 4/9] pci: add failed_list to record failed one for pci_bus_assign_resources Yinghai Lu
2009-11-25 19:59                                                                     ` [PATCH 5/9] pci: update leaf bridge res to get more big range in pci assign unssign Yinghai Lu
2009-11-25 19:59                                                                     ` [PATCH 6/9] pci: don't shrink bridge resources Yinghai Lu
2009-11-25 19:59                                                                     ` [PATCH 7/9] pci: introduce pci_assign_unassigned_bridge_resources Yinghai Lu
2009-11-25 19:59                                                                     ` [PATCH 8/9] pci: pciehp clean flow in pciehp_configure_device Yinghai Lu
2009-11-25 19:59                                                                     ` [PATCH 9/9] pci: pciehp second try to get big range for pcie devices Yinghai Lu
2009-11-28  7:34                                                                 ` [PATCH 0/9] pci: update pci bridge resource to get more big range for devices under it - v13 Yinghai Lu
2009-11-28  8:15                                                                   ` Yinghai Lu
2009-11-30  7:10                                                                   ` Kenji Kaneshige
2009-11-30  7:14                                                                     ` Yinghai Lu
2009-11-30  7:26                                                                       ` Kenji Kaneshige
2009-11-30  7:43                                                                         ` Yinghai Lu
2009-11-30  8:19                                                                         ` Yinghai Lu
2009-11-30  8:44                                                                           ` Kenji Kaneshige
2009-12-16 20:54                                                                   ` Jesse Barnes
2009-12-16 21:11                                                                     ` Alex Chiang
2009-12-16 22:21                                                                       ` Yinghai Lu
2009-12-16 22:27                                                                       ` Yinghai Lu
2009-12-16 22:44                                                                         ` Alex Chiang
     [not found]                                                                 ` <4B10D084.8070608@kerne! l.org>
     [not found]                                                                   ` <4B10D084.8070608@kernel.org>
2009-11-28  7:34                                                                     ` [PATCH 1/9] pci: separate pci_setup_bridge to small functions Yinghai Lu
2009-12-16 20:41                                                                       ` Jesse Barnes
2009-12-17 11:03                                                                         ` Rolf Eike Beer
2009-11-28  7:35                                                                     ` [PATCH 2/9] pci: add pci_bridge_release_unused_res and pci_bus_release_unused_bridge_res Yinghai Lu
2009-12-16 20:49                                                                       ` Jesse Barnes
2009-12-16 22:19                                                                         ` Yinghai Lu
2009-11-28  7:35                                                                     ` [PATCH 3/9] pci: don't dump it when bus resource flags is not used Yinghai Lu
2009-12-16 20:50                                                                       ` Jesse Barnes
2009-12-16 22:20                                                                         ` Yinghai Lu
2009-11-28  7:35                                                                     ` [PATCH 4/9] pci: add failed_list to record failed one for pci_bus_assign_resources -v2 Yinghai Lu
2009-11-28  7:35                                                                     ` [PATCH 5/9] pci: update leaf bridge res to get more big range in pci assign unssign -v2 Yinghai Lu
2009-11-30 21:55                                                                       ` [PATCH 5/9] pci: update leaf bridge res to get more big range in pci assign unssign -v3 Yinghai Lu
2009-11-28  7:36                                                                     ` [PATCH 6/9] pci: don't shrink bridge resources Yinghai Lu
2009-11-28  7:36                                                                     ` [PATCH 7/9] pci: introduce pci_assign_unassigned_bridge_resources -v2 Yinghai Lu
2009-11-28  7:36                                                                     ` [PATCH 8/9] pci: pciehp clean flow in pciehp_configure_device Yinghai Lu
2009-11-28  7:36                                                                     ` [PATCH 9/9] pci: pciehp second try to get big range for pcie devices -v2 Yinghai Lu
2009-12-01  1:19                                                                       ` [PATCH 1/2] pci: pci_bridge_release_res Yinghai Lu
2009-12-07 21:42                                                                         ` Patrick Keller
2009-12-07 21:57                                                                           ` Yinghai Lu
2009-12-01  1:21                                                                       ` [PATCH 2/2] pciehp: add support for bridge resource reallocation -v2 Yinghai Lu
2009-11-14  8:51                                                     ` [PATCH 2/2] pci: pciehp update the slot bridge res to get big range for pcie devices - v11 Yinghai Lu
2009-10-26  8:27       ` [PATCH] pci: pciehp update the slot bridge res to get big range for pcie devices - v3 Yinghai Lu
2009-10-27  8:09         ` [PATCH 1/4] pci: pciehp update the slot bridge res to get big range for pcie devices - v4 Yinghai Lu
     [not found]         ` <4AE6A9CA.4060106@kernel.org>
2009-10-27  8:09           ` [PATCH 2/4] pci: revert "get larger bridge ranges when space is available" Yinghai Lu
2009-10-27  8:10           ` [PATCH 3/4] pci: only release that resource index is less than 3 -v3 Yinghai Lu
2009-10-27  8:10           ` [PATCH 4/4] pci: remove min_size for hotplug bridge Yinghai Lu
2009-10-27  9:20             ` Eric W. Biederman

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4AE93761.6000503@jp.fujitsu.com \
    --to=kaneshige.kenji@jp.fujitsu.com \
    --cc=achiang@hp.com \
    --cc=bjorn.helgaas@hp.com \
    --cc=ebiederm@xmission.com \
    --cc=ink@jurassic.park.msu.ru \
    --cc=jbarnes@virtuousgeek.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=yinghai@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.