Re: [PATCH 02/11] PCI: Try to allocate mem64 above 4G at first

Yinghai Lu
2012-05-25T18:39:28Z

[-- Attachment #1: Type: text/plain, Size: 841 bytes --]

On Fri, May 25, 2012 at 10:53 AM, Yinghai Lu <yinghai@kernel.org> wrote:
>> I don't really like the dependency on PCIBIOS_MAX_MEM_32 + 1ULL
>> overflowing to zero -- that means the reader has to know what the
>> value of PCIBIOS_MAX_MEM_32 is, and things would break in non-obvious
>> ways if we changed it.
>>

please check if attached one is more clear.

make max and bottom is only related to _MEM and not default one.

- if (!(res->flags & IORESOURCE_MEM_64))
- max = PCIBIOS_MAX_MEM_32;
+ if (res->flags & IORESOURCE_MEM) {
+ if (!(res->flags & IORESOURCE_MEM_64))
+ max = PCIBIOS_MAX_MEM_32;
+ else if (PCIBIOS_MAX_MEM_32 != -1)
+ bottom = (resource_size_t)(1ULL<<32);
+ }

will still not affect to other arches.

Thanks

Yinghai

[-- Attachment #2: allocate_high_at_first.patch --]
[-- Type: application/octet-stream, Size: 1948 bytes --]

Subject: [PATCH] PCI: Try to allocate mem64 above 4G at first

and will fall back to below 4g if it can not find any above 4g.

only x86 have PCIBIOS_MAX_MEM_32 set to 0xffffffff.
it will only affect x86_64 and 32bit with resource_size_t 64bit support.
only that case bottom is set to 4g for first try.

x86 32bit without X86_PAE support will have bottom set to 0, becuase
resource_size_t is 32bit.

Also for 32bit with resource_size_t 64bit kernel on machine with pae support
we are safe because iomem_resource is limited to 32bit according to
x86_phys_bits.

-v2: update bottom assigning to make it clear for non-pae support machine.

Signed-off-by: Yinghai Lu <yinghai@kernel.org>

---
drivers/pci/bus.c | 20 ++++++++++++++++----
1 file changed, 16 insertions(+), 4 deletions(-)

Index: linux-2.6/drivers/pci/bus.c
===================================================================
--- linux-2.6.orig/drivers/pci/bus.c
+++ linux-2.6/drivers/pci/bus.c
@@ -122,13 +122,19 @@ pci_bus_alloc_resource(struct pci_bus *b
int i, ret = -ENOMEM;
struct resource *r;
resource_size_t max = -1;
+ resource_size_t bottom = 0;

type_mask |= IORESOURCE_IO | IORESOURCE_MEM;

/* don't allocate too high if the pref mem doesn't support 64bit*/
- if (!(res->flags & IORESOURCE_MEM_64))
- max = PCIBIOS_MAX_MEM_32;
+ if (res->flags & IORESOURCE_MEM) {
+ if (!(res->flags & IORESOURCE_MEM_64))
+ max = PCIBIOS_MAX_MEM_32;
+ else if (PCIBIOS_MAX_MEM_32 != -1)
+ bottom = (resource_size_t)(1ULL<<32);
+ }

+again:
pci_bus_for_each_resource(bus, r, i) {
if (!r)
continue;
@@ -145,12 +151,18 @@ pci_bus_alloc_resource(struct pci_bus *b

/* Ok, try it out.. */
ret = allocate_resource(r, res, size,
- r->start ? : min,
+ max(bottom, r->start ? : min),
max, align,
alignf, alignf_data);
if (ret == 0)
- break;
+ return 0;
+ }
+
+ if (bottom != 0) {
+ bottom = 0;
+ goto again;
}
+
return ret;
}