All of lore.kernel.org
 help / color / mirror / Atom feed
From: Conor Dooley <conor@kernel.org>
To: panqinglin2020@iscas.ac.cn
Cc: atishp@atishpatra.org, alex@ghiti.fr,
	linux-riscv@lists.infradead.org, palmer@dabbelt.com
Subject: Re: [PATCH v1 1/1] riscv: mm: add missing memcpy in kasan_init
Date: Sun, 9 Oct 2022 12:30:09 +0100	[thread overview]
Message-ID: <Y0KwwUNpfC+JOhQR@spud> (raw)
In-Reply-To: <20221009083050.3814850-1-panqinglin2020@iscas.ac.cn>

On Sun, Oct 09, 2022 at 04:30:50PM +0800, panqinglin2020@iscas.ac.cn wrote:
> From: Qinglin Pan <panqinglin2020@iscas.ac.cn>
> 
> Hi Atish,
> 
> It seems that the panic is due to the missing memcpy during kasan_init.
> Could you please check whether this patch is helpful?

If this does solve the problem it would be:
Fixes: 8fbdccd2b173 ("riscv: mm: Support kasan for sv57")
right?

Thanks,
Conor.

> 
> When doing kasan_populate, the new allocated base_pud/base_p4d should
> contain kasan_early_shadow_{pud, p4d}'s content. Add the missing memcpy
> to avoid page fault when read/write kasan shadow region.
> 
> Tested on:
>  - qemu with sv57 and CONFIG_KASAN on.
>  - qemu with sv48 and CONFIG_KASAN on.
> 
> Signed-off-by: Qinglin Pan <panqinglin2020@iscas.ac.cn>
> ---
>  arch/riscv/mm/kasan_init.c | 7 ++++++-
>  1 file changed, 6 insertions(+), 1 deletion(-)
> 
> diff --git a/arch/riscv/mm/kasan_init.c b/arch/riscv/mm/kasan_init.c
> index a22e418dbd82..e1226709490f 100644
> --- a/arch/riscv/mm/kasan_init.c
> +++ b/arch/riscv/mm/kasan_init.c
> @@ -113,6 +113,8 @@ static void __init kasan_populate_pud(pgd_t *pgd,
>  		base_pud = pt_ops.get_pud_virt(pfn_to_phys(_pgd_pfn(*pgd)));
>  	} else if (pgd_none(*pgd)) {
>  		base_pud = memblock_alloc(PTRS_PER_PUD * sizeof(pud_t), PAGE_SIZE);
> +		memcpy(base_pud, (void *)kasan_early_shadow_pud,
> +			sizeof(pud_t) * PTRS_PER_PUD);
>  	} else {
>  		base_pud = (pud_t *)pgd_page_vaddr(*pgd);
>  		if (base_pud == lm_alias(kasan_early_shadow_pud)) {
> @@ -173,8 +175,11 @@ static void __init kasan_populate_p4d(pgd_t *pgd,
>  		base_p4d = pt_ops.get_p4d_virt(pfn_to_phys(_pgd_pfn(*pgd)));
>  	} else {
>  		base_p4d = (p4d_t *)pgd_page_vaddr(*pgd);
> -		if (base_p4d == lm_alias(kasan_early_shadow_p4d))
> +		if (base_p4d == lm_alias(kasan_early_shadow_p4d)) {
>  			base_p4d = memblock_alloc(PTRS_PER_PUD * sizeof(p4d_t), PAGE_SIZE);
> +			memcpy(base_p4d, (void *)kasan_early_shadow_p4d,
> +				sizeof(p4d_t) * PTRS_PER_P4D);
> +		}
>  	}
>  
>  	p4dp = base_p4d + p4d_index(vaddr);
> -- 
> 2.35.1
> 
> 
> _______________________________________________
> linux-riscv mailing list
> linux-riscv@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-riscv

_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

  reply	other threads:[~2022-10-09 11:30 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-09  0:10 KASAN/pcpu_alloc related panics on v6.0 Atish Patra
2022-10-09  8:30 ` [PATCH v1 1/1] riscv: mm: add missing memcpy in kasan_init panqinglin2020
2022-10-09 11:30   ` Conor Dooley [this message]
2022-10-09 13:25     ` Qinglin Pan
2022-10-09 13:32       ` Conor Dooley
2022-10-10  6:49   ` Atish Patra
2022-10-14 16:34     ` Palmer Dabbelt
2022-10-27 22:45   ` Palmer Dabbelt
2022-10-09 13:23 ` [PATCH v1 1/1] Fixes: 8fbdccd2b173 ("riscv: mm: Support kasan for sv57") panqinglin2020

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Y0KwwUNpfC+JOhQR@spud \
    --to=conor@kernel.org \
    --cc=alex@ghiti.fr \
    --cc=atishp@atishpatra.org \
    --cc=linux-riscv@lists.infradead.org \
    --cc=palmer@dabbelt.com \
    --cc=panqinglin2020@iscas.ac.cn \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.