Message ID | 20240706-virt-to-phys-v1-1-7a4dc11f542c@berkeley.edu (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | [kvm-unit-tests] riscv: Fix virt_to_phys() | expand |
On Sat, Jul 06, 2024 at 04:09:44PM GMT, Cade Richard wrote: > Needs a commit message stating it's currently broken for anything other than addresses on page boundaries and that this is the fix. > > --- 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") > Signed-off-by: Cade Richard <cade.richard@berkeley.edu> > --- > lib/riscv/mmu.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/lib/riscv/mmu.c b/lib/riscv/mmu.c > index bd006881..c4770552 100644 > --- a/lib/riscv/mmu.c > +++ b/lib/riscv/mmu.c > @@ -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. > } > > void *phys_to_virt(unsigned long address) > Thanks, drew
On Mon, Jul 15, 2024 at 03:57:12PM GMT, Andrew Jones wrote: > On Sat, Jul 06, 2024 at 04:09:44PM GMT, Cade Richard wrote: > > > > Needs a commit message stating it's currently broken for anything > other than addresses on page boundaries and that this is the fix. > > > > > --- > > 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") > > > Signed-off-by: Cade Richard <cade.richard@berkeley.edu> > > --- > > lib/riscv/mmu.c | 2 +- > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > diff --git a/lib/riscv/mmu.c b/lib/riscv/mmu.c > > index bd006881..c4770552 100644 > > --- a/lib/riscv/mmu.c > > +++ b/lib/riscv/mmu.c > > @@ -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. > > > } > > > > 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
diff --git a/lib/riscv/mmu.c b/lib/riscv/mmu.c index bd006881..c4770552 100644 --- a/lib/riscv/mmu.c +++ b/lib/riscv/mmu.c @@ -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)
--- Signed-off-by: Cade Richard <cade.richard@berkeley.edu> --- lib/riscv/mmu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- base-commit: a68956b3fb6f5f308822b20ce0ff8e02db1f7375 change-id: 20240706-virt-to-phys-2a27a924ef2a Best regards,