Skip to contentSkip to conversation

riscv: fix pfn_to_virt err in do_page_fault().

PATCH Superseded liush 4 participants 5 messages Sep 17, 2020 – Sep 28, 2020 RISC-V

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

liush

author
#0 lore raw

PATCH 1/1 riscv: fix pfn_to_virt err in do_page_fault().

The argument to pfn_to_virt() should be pfn not the value of CSR_SATP.

---
 arch/riscv/mm/fault.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/riscv/mm/fault.c +1 -1
index 716d64e..9b4e088 100644
@@ -212,7 +212,7 @@ asmlinkage void do_page_fault(struct pt_regs *regs)
 		 * of a task switch.
 		 */
 		index = pgd_index(addr);
-		pgd = (pgd_t *)pfn_to_virt(csr_read(CSR_SATP)) + index;
+		pgd = (pgd_t *)pfn_to_virt(csr_read(CSR_SATP) & SATP_PPN) + index;
 		pgd_k = init_mm.pgd + index;
 
 		if (!pgd_present(*pgd_k))
Signature · 1 line
2.7.4
Reviewed-by on v1 1/1
#1 lore raw
Quoted 22 lines · liush

The argument to pfn_to_virt() should be pfn not the value of CSR_SATP.

---
 arch/riscv/mm/fault.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/riscv/mm/fault.c +1 -2
index 716d64e..9b4e088 100644
@@ -212,7 +212,7 @@ asmlinkage void do_page_fault(struct pt_regs *regs)
                 * of a task switch.
                 */
                index = pgd_index(addr);
-               pgd = (pgd_t *)pfn_to_virt(csr_read(CSR_SATP)) + index;
+               pgd = (pgd_t *)pfn_to_virt(csr_read(CSR_SATP) & SATP_PPN) + index;
                pgd_k = init_mm.pgd + index;
 
                if (!pgd_present(*pgd_k))
--
Quoted 2 lines

2.7.4

Looks good to me.

Regards,
Anup

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

#2 lore raw
In reply to liush
Quoted 12 lines · liush

The argument to pfn_to_virt() should be pfn not the value of CSR_SATP.

---
 arch/riscv/mm/fault.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/riscv/mm/fault.c +0 -0
index 716d64e..9b4e088 100644

arch/riscv/mm/fault.c asmlinkage void do_page_fault(struct pt_regs *regs) · line 215

Quoted 5 lines
arch/riscv/mm/fault.c +1 -1
@@ -212,7 +212,7 @@ asmlinkage void do_page_fault(struct pt_regs *regs)
 		 * of a task switch.
 		 */
 		index = pgd_index(addr);
-		pgd = (pgd_t *)pfn_to_virt(csr_read(CSR_SATP)) + index;
+		pgd = (pgd_t *)pfn_to_virt(csr_read(CSR_SATP) & SATP_PPN) + index;

This adds a crazy long line. One nice way to clean this up would be to add a local pfn variable, as it would also make the code more readable.

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

#3 lore raw

Hi Christoph,

Quoted 8 lines · liush
Quoted 7 lines

The argument to pfn_to_virt() should be pfn not the value of CSR_SATP.

---
 arch/riscv/mm/fault.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 13 lines

arch/riscv/mm/fault.c asmlinkage void do_page_fault(struct pt_regs *regs) · line 215

Quoted 10 lines
arch/riscv/mm/fault.c +1 -1
index 716d64e..9b4e088 100644
@@ -212,7 +212,7 @@ asmlinkage void do_page_fault(struct pt_regs *regs)
    * of a task switch.
    */
   index = pgd_index(addr);
-  pgd = (pgd_t *)pfn_to_virt(csr_read(CSR_SATP)) + index;
+  pgd = (pgd_t *)pfn_to_virt(csr_read(CSR_SATP) & SATP_PPN) + index;

This adds a crazy long line. One nice way to clean this up would be to add a local pfn variable, as it would also make the code more readable.

Thanks, i'll modify it in next revision

#4 lore raw
Quoted 23 lines · 刘邵华BTD

Hi Christoph,

Quoted 8 lines · liush
Quoted 7 lines

The argument to pfn_to_virt() should be pfn not the value of CSR_SATP.

---
 arch/riscv/mm/fault.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 13 lines

arch/riscv/mm/fault.c asmlinkage void do_page_fault(struct pt_regs *regs) · line 215

Quoted 10 lines
arch/riscv/mm/fault.c +1 -1
index 716d64e..9b4e088 100644
@@ -212,7 +212,7 @@ asmlinkage void do_page_fault(struct pt_regs *regs)
    * of a task switch.
    */
   index = pgd_index(addr);
-  pgd = (pgd_t *)pfn_to_virt(csr_read(CSR_SATP)) + index;
+  pgd = (pgd_t *)pfn_to_virt(csr_read(CSR_SATP) & SATP_PPN) + index;

This adds a crazy long line. One nice way to clean this up would be to add a local pfn variable, as it would also make the code more readable.

Quoted 1 line

Thanks, i'll modify it in next revision

Signature · 1 line
<http://www.allwinnertech.com> Allwinnertech Technology