riscv: Fix virt_to_phys()
Subsystems (3)
PATCH 1/1 riscv: Fix virt_to_phys()
---
--- lib/riscv/mmu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
lib/riscv/mmu.c +1 -1
@@ -194,7 +194,7 @@ unsigned long virt_to_phys(volatile void *address) paddr =virt_to_pte_phys (pgtable, (void *)address);assert (sizeof (long ) ==8 || !(paddr >>32 )); -return (unsigned long )paddr; +return (unsigned long )paddr | ((unsigned long ) address &0x00000FFF ); }void *phys_to_virt (unsigned long address)
---
base-commit: a68956b3fb6f5f308822b20ce0ff8e02db1f7375
change-id: 20240706-virt-to-phys-2a27a924ef2a
Best regards,
Signature · 1 line
Cade Richard <[email protected]>
Quoted 1 line · Cade Richard
Needs a commit message stating it's currently broken for anything other than addresses on page boundaries and that this is the fix.
Quoted 2 lines
---
These dashes shouldn't be here. With them, git will strip the s-o-b on commit.
Please also add
Quoted 10 lines
Signed-off-by Cade Richard <[email protected]>--- lib/riscv/mmu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)lib/riscv/mmu.c +0
-0
lib/riscv/mmu.c unsigned long virt_to_phys(volatile void *address) · line 197
Quoted 5 lines
lib/riscv/mmu.c +1
-1@@ -194,7 +194,7 @@ unsigned long virt_to_phys(volatile void *address) paddr =virt_to_pte_phys (pgtable, (void *)address);assert (sizeof (long ) ==8 || !(paddr >>32 )); -return (unsigned long )paddr; +return (unsigned long )paddr | ((unsigned long ) address &0x00000FFF );
Let's add
#define offset_in_page(p) ((unsigned long)(p) & ~PAGE_MASK)
to lib/asm-generic/page.h and use it here.
lib/riscv/mmu.c unsigned long virt_to_phys(volatile void *address) · line 200
Quoted 4 lines
lib/riscv/mmu.c +0
-0}void *phys_to_virt (unsigned long address)
Thanks,
drew
Quoted 38 lines · Andrew Jones
Quoted 1 line · Cade Richard
Needs a commit message stating it's currently broken for anything other than addresses on page boundaries and that this is the fix.
Quoted 2 lines
---
These dashes shouldn't be here. With them, git will strip the s-o-b on commit.
Please also add
Fixes 23100d972705 ("riscv: Enable vmalloc")Quoted 10 lines
Signed-off-by Cade Richard <[email protected]>--- lib/riscv/mmu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)lib/riscv/mmu.c +0
-0lib/riscv/mmu.c unsigned long virt_to_phys(volatile void *address) · line 197
Quoted 5 lines
lib/riscv/mmu.c +1
-1@@ -194,7 +194,7 @@ unsigned long virt_to_phys(volatile void *address) paddr =virt_to_pte_phys (pgtable, (void *)address);assert (sizeof (long ) ==8 || !(paddr >>32 )); -return (unsigned long )paddr; +return (unsigned long )paddr | ((unsigned long ) address &0x00000FFF );Let's add
#define offset_in_page(p) ((unsigned long)(p) & ~PAGE_MASK)to
lib/asm-generic/page.hand use it here.
Quoted 8 lines
lib/riscv/mmu.c unsigned long virt_to_phys(volatile void *address) · line 200
Quoted 4 lines
lib/riscv/mmu.c +0
-0}void *phys_to_virt (unsigned long address)Thanks,
drew
Since this is a fix that I'd like to get in sooner than later, I've made my suggested changes myself and merged it.
Thanks,
drew