2020-10-26 16:14:54

by 刘邵华BTD

[permalink] [raw]
Subject: [PATCH v3] riscv: fix pfn_to_virt err in do_page_fault().

From: Liu Shaohua <[email protected]>

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

Reviewed-by: Palmer Dabbelt <[email protected]>
Reviewed-by: Anup Patel <[email protected]>
Signed-off-by: liush <[email protected]>
---
arch/riscv/mm/fault.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/arch/riscv/mm/fault.c b/arch/riscv/mm/fault.c
index 1359e21..3c8b9e4 100644
--- a/arch/riscv/mm/fault.c
+++ b/arch/riscv/mm/fault.c
@@ -86,6 +86,7 @@ static inline void vmalloc_fault(struct pt_regs *regs, int code, unsigned long a
pmd_t *pmd, *pmd_k;
pte_t *pte_k;
int index;
+ unsigned long pfn;

/* User mode accesses just cause a SIGSEGV */
if (user_mode(regs))
@@ -100,7 +101,8 @@ static inline void vmalloc_fault(struct pt_regs *regs, int code, unsigned long a
* of a task switch.
*/
index = pgd_index(addr);
- pgd = (pgd_t *)pfn_to_virt(csr_read(CSR_SATP)) + index;
+ pfn = csr_read(CSR_SATP) & SATP_PPN;
+ pgd = (pgd_t *)pfn_to_virt(pfn) + index;
pgd_k = init_mm.pgd + index;

if (!pgd_present(*pgd_k)) {
--
2.7.4


2020-10-26 16:15:46

by Pekka Enberg

[permalink] [raw]
Subject: Re: [PATCH v3] riscv: fix pfn_to_virt err in do_page_fault().

On Mon, Oct 26, 2020 at 08:26:54PM +0800, liush wrote:
> From: Liu Shaohua <[email protected]>
>
> The argument to pfn_to_virt() should be pfn not the value of CSR_SATP.
>
> Reviewed-by: Palmer Dabbelt <[email protected]>
> Reviewed-by: Anup Patel <[email protected]>
> Signed-off-by: liush <[email protected]>

Reviewed-by: Pekka Enberg <[email protected]>

> ---
> arch/riscv/mm/fault.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/arch/riscv/mm/fault.c b/arch/riscv/mm/fault.c
> index 1359e21..3c8b9e4 100644
> --- a/arch/riscv/mm/fault.c
> +++ b/arch/riscv/mm/fault.c
> @@ -86,6 +86,7 @@ static inline void vmalloc_fault(struct pt_regs *regs, int code, unsigned long a
> pmd_t *pmd, *pmd_k;
> pte_t *pte_k;
> int index;
> + unsigned long pfn;
>
> /* User mode accesses just cause a SIGSEGV */
> if (user_mode(regs))
> @@ -100,7 +101,8 @@ static inline void vmalloc_fault(struct pt_regs *regs, int code, unsigned long a
> * of a task switch.
> */
> index = pgd_index(addr);
> - pgd = (pgd_t *)pfn_to_virt(csr_read(CSR_SATP)) + index;
> + pfn = csr_read(CSR_SATP) & SATP_PPN;
> + pgd = (pgd_t *)pfn_to_virt(pfn) + index;
> pgd_k = init_mm.pgd + index;
>
> if (!pgd_present(*pgd_k)) {
> --
> 2.7.4
>

2020-11-06 05:20:08

by Palmer Dabbelt

[permalink] [raw]
Subject: Re: [PATCH v3] riscv: fix pfn_to_virt err in do_page_fault().

On Mon, 26 Oct 2020 05:26:54 PDT (-0700), [email protected] wrote:
> From: Liu Shaohua <[email protected]>
>
> The argument to pfn_to_virt() should be pfn not the value of CSR_SATP.
>
> Reviewed-by: Palmer Dabbelt <[email protected]>
> Reviewed-by: Anup Patel <[email protected]>
> Signed-off-by: liush <[email protected]>
> ---
> arch/riscv/mm/fault.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/arch/riscv/mm/fault.c b/arch/riscv/mm/fault.c
> index 1359e21..3c8b9e4 100644
> --- a/arch/riscv/mm/fault.c
> +++ b/arch/riscv/mm/fault.c
> @@ -86,6 +86,7 @@ static inline void vmalloc_fault(struct pt_regs *regs, int code, unsigned long a
> pmd_t *pmd, *pmd_k;
> pte_t *pte_k;
> int index;
> + unsigned long pfn;
>
> /* User mode accesses just cause a SIGSEGV */
> if (user_mode(regs))
> @@ -100,7 +101,8 @@ static inline void vmalloc_fault(struct pt_regs *regs, int code, unsigned long a
> * of a task switch.
> */
> index = pgd_index(addr);
> - pgd = (pgd_t *)pfn_to_virt(csr_read(CSR_SATP)) + index;
> + pfn = csr_read(CSR_SATP) & SATP_PPN;
> + pgd = (pgd_t *)pfn_to_virt(pfn) + index;
> pgd_k = init_mm.pgd + index;
>
> if (!pgd_present(*pgd_k)) {

This is on fixes, thanks!