x86: PAT bug fix for attribute type check after reserve_memtype
authorVenki Pallipadi <venkatesh.pallipadi@intel.com>
Mon, 24 Mar 2008 21:39:55 +0000 (14:39 -0700)
committerIngo Molnar <mingo@elte.hu>
Thu, 17 Apr 2008 15:41:20 +0000 (17:41 +0200)
Bug fixes for reserve_memtype() call in __ioremap and pci_mmap_page_range().
If reserve_memtype returns non-zero, then it is an error and subsequent free is
not required. Requested and returned prot value check should be done when
reserve_memtype returns success.

Signed-off-by: Venkatesh Pallipadi <venkatesh.pallipadi@intel.com>
Signed-off-by: Suresh Siddha <suresh.b.siddha@intel.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
arch/x86/mm/ioremap.c
arch/x86/pci/i386.c

index 6cd3418afe712a77a77ed5345e91d1e52832be01..3f7f05e2c434d3f8469f8d7c00b6a87f28488ea8 100644 (file)
@@ -124,6 +124,7 @@ static void __iomem *__ioremap(resource_size_t phys_addr, unsigned long size,
        struct vm_struct *area;
        unsigned long new_prot_val;
        pgprot_t prot;
+       int retval;
 
        /* Don't allow wraparound or zero size */
        last_addr = phys_addr + size - 1;
@@ -163,8 +164,14 @@ static void __iomem *__ioremap(resource_size_t phys_addr, unsigned long size,
        phys_addr &= PAGE_MASK;
        size = PAGE_ALIGN(last_addr+1) - phys_addr;
 
-       if (reserve_memtype(phys_addr, phys_addr + size,
-                           prot_val, &new_prot_val)) {
+       retval = reserve_memtype(phys_addr, phys_addr + size,
+                                               prot_val, &new_prot_val);
+       if (retval) {
+               printk("reserve_memtype returned %d\n", retval);
+               return NULL;
+       }
+
+       if (prot_val != new_prot_val) {
                /*
                 * Do not fallback to certain memory types with certain
                 * requested type:
index 4ebf52f6b1fdd4b0b8e5f5d16ef232ecf5f9ac25..2ead72363077a1853970328b988a4637f3f8ca73 100644 (file)
@@ -328,6 +328,7 @@ int pci_mmap_page_range(struct pci_dev *dev, struct vm_area_struct *vma,
        unsigned long len = vma->vm_end - vma->vm_start;
        unsigned long flags;
        unsigned long new_flags;
+       int retval;
 
        /* I/O space cannot be accessed via normal processor loads and
         * stores on this platform.
@@ -344,7 +345,11 @@ int pci_mmap_page_range(struct pci_dev *dev, struct vm_area_struct *vma,
        vma->vm_page_prot = __pgprot(prot);
 
        flags = pgprot_val(vma->vm_page_prot) & _PAGE_CACHE_MASK;
-       if (reserve_memtype(addr, addr + len, flags, &new_flags)) {
+       retval = reserve_memtype(addr, addr + len, flags, &new_flags);
+       if (retval)
+               return retval;
+
+       if (flags != new_flags) {
                /*
                 * Do not fallback to certain memory types with certain
                 * requested type: