RISC-V: Avoid corrupting the upper 32-bit of phys_addr_t in ioremap
authorVincent Chen <vincentc@andestech.com>
Tue, 2 Oct 2018 08:52:31 +0000 (16:52 +0800)
committerPalmer Dabbelt <palmer@sifive.com>
Tue, 23 Oct 2018 00:02:56 +0000 (17:02 -0700)
For 32bit, the upper 32-bit of phys_addr_t will be flushed to zero
after AND with PAGE_MASK because the data type of PAGE_MASK is
unsigned long. To fix this problem, the page alignment is done by
subtracting the page offset instead of AND with PAGE_MASK.

Signed-off-by: Vincent Chen <vincentc@andestech.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Palmer Dabbelt <palmer@sifive.com>
arch/riscv/mm/ioremap.c

index 70ef2724cdf61e5b2001f0ec6243b7f5e9c6bfaa..bd2f2db557cc54f182794284bb0d9d317cb2b36a 100644 (file)
@@ -42,7 +42,7 @@ static void __iomem *__ioremap_caller(phys_addr_t addr, size_t size,
 
        /* Page-align mappings */
        offset = addr & (~PAGE_MASK);
-       addr &= PAGE_MASK;
+       addr -= offset;
        size = PAGE_ALIGN(size + offset);
 
        area = get_vm_area_caller(size, VM_IOREMAP, caller);