i386 pci: Handle mmaping 64bit bars.
PATCH 1/1 i386 pci: Handle mmaping 64bit bars.
While reading through pci_mmap_page_range I realized that if don't properly handle 64bit bars in the 32bit kernel.
Without the added cast the shift will be done in 32bit despite being assigned to a 64bit variable and if we are mmaping an address above 4G things will do the wrong thing.
--- arch/x86/pci/i386.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
arch/x86/pci/i386.c +1 -1
@@ -283,7 +283,7 @@ int pci_mmap_page_range(struct pci_dev *dev, struct vm_area_struct *vma, enum pci_mmap_state mmap_state, int write_combine) {unsigned long prot; -u64 addr = vma->vm_pgoff <<PAGE_SHIFT ; +u64 addr = ((u64 )vma->vm_pgoff) <<PAGE_SHIFT ;unsigned long len = vma->vm_end - vma->vm_start;unsigned long flags;unsigned long new_flags;
Signature · 1 line
1.6.0.6
H. Peter Anvin
reviewerQuoted 6 lines · Eric W. Biederman
While reading through
pci_mmap_page_rangeI realized that if don't properly handle 64bit bars in the 32bit kernel.Without the added cast the shift will be done in 32bit despite being assigned to a 64bit variable and if we are mmaping an address above 4G things will do the wrong thing.
Hm... this really should be resource_size_t, no?
arch/x86/pci/i386.c int pci_mmap_page_range(struct pci_dev *dev, struct vm_area_struct *vma, · line 286
Quoted 2 lines
arch/x86/pci/i386.c +1
-1-u64 addr = vma->vm_pgoff <<PAGE_SHIFT ; +u64 addr = ((u64 )vma->vm_pgoff) <<PAGE_SHIFT ;
-hpa
Signature · 2 lines
H. Peter Anvin, Intel Open Source Technology Center I work for Intel. I don't speak on their behalf.
Quoted 4 lines · H. Peter Anvin
Quoted 3 lines · Eric W. Biederman
While reading through
pci_mmap_page_rangeI realized that if don't properly handle 64bit bars in the 32bit kernel.
Quoted 8 lines
Quoted 3 lines
Without the added cast the shift will be done in 32bit despite being assigned to a 64bit variable and if we are mmaping an address above 4G things will do the wrong thing.
Hm... this really should be
resource_size_t, no?arch/x86/pci/i386.c int pci_mmap_page_range(struct pci_dev *dev, struct vm_area_struct *vma, · line 286
Quoted 2 lines
arch/x86/pci/i386.c +1
-1-u64 addr = vma->vm_pgoff <<PAGE_SHIFT ; +u64 addr = ((u64 )vma->vm_pgoff) <<PAGE_SHIFT ;
It is a parameter to the reserve_memtype and free_memtype functions, which take a u64 so the type looks ok.
If I was going to quibble I would argue that those functions should take a pfn instead of a u64...
Eric