diff mbox series

riscv: Pass virtual addresses to kasan_mem_to_shadow

Message ID 20210222080734.31631-1-alex@ghiti.fr (mailing list archive)
State New, archived
Headers show
Series riscv: Pass virtual addresses to kasan_mem_to_shadow | expand

Commit Message

Alexandre Ghiti Feb. 22, 2021, 8:07 a.m. UTC
kasan_mem_to_shadow translates virtual addresses to kasan shadow
addresses whereas for_each_mem_range returns physical addresses: it is
then required to use __va on those addresses before passing them to
kasan_mem_to_shadow.

Fixes: b10d6bca8720 ("arch, drivers: replace for_each_membock() with for_each_mem_range()")
Signed-off-by: Alexandre Ghiti <alex@ghiti.fr>
---
 arch/riscv/mm/kasan_init.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Palmer Dabbelt Feb. 23, 2021, 2:58 a.m. UTC | #1
On Mon, 22 Feb 2021 00:07:34 PST (-0800), alex@ghiti.fr wrote:
> kasan_mem_to_shadow translates virtual addresses to kasan shadow
> addresses whereas for_each_mem_range returns physical addresses: it is
> then required to use __va on those addresses before passing them to
> kasan_mem_to_shadow.
>
> Fixes: b10d6bca8720 ("arch, drivers: replace for_each_membock() with for_each_mem_range()")
> Signed-off-by: Alexandre Ghiti <alex@ghiti.fr>
> ---
>  arch/riscv/mm/kasan_init.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/arch/riscv/mm/kasan_init.c b/arch/riscv/mm/kasan_init.c
> index 4b9149f963d3..6d3b88f2c566 100644
> --- a/arch/riscv/mm/kasan_init.c
> +++ b/arch/riscv/mm/kasan_init.c
> @@ -148,8 +148,8 @@ void __init kasan_init(void)
>  			(void *)kasan_mem_to_shadow((void *)VMALLOC_END));
>
>  	for_each_mem_range(i, &_start, &_end) {
> -		void *start = (void *)_start;
> -		void *end = (void *)_end;
> +		void *start = (void *)__va(_start);
> +		void *end = (void *)__va(_end);
>
>  		if (start >= end)
>  			break;

Thanks, but unless I'm missing something this is already in Linus' tree as
c25a053e1577 ("riscv: Fix KASAN memory mapping.").
Alexandre Ghiti Feb. 23, 2021, 5:41 a.m. UTC | #2
Hi Palmer,

Le 2/22/21 à 9:58 PM, Palmer Dabbelt a écrit :
> On Mon, 22 Feb 2021 00:07:34 PST (-0800), alex@ghiti.fr wrote:
>> kasan_mem_to_shadow translates virtual addresses to kasan shadow
>> addresses whereas for_each_mem_range returns physical addresses: it is
>> then required to use __va on those addresses before passing them to
>> kasan_mem_to_shadow.
>>
>> Fixes: b10d6bca8720 ("arch, drivers: replace for_each_membock() with 
>> for_each_mem_range()")
>> Signed-off-by: Alexandre Ghiti <alex@ghiti.fr>
>> ---
>>  arch/riscv/mm/kasan_init.c | 4 ++--
>>  1 file changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/arch/riscv/mm/kasan_init.c b/arch/riscv/mm/kasan_init.c
>> index 4b9149f963d3..6d3b88f2c566 100644
>> --- a/arch/riscv/mm/kasan_init.c
>> +++ b/arch/riscv/mm/kasan_init.c
>> @@ -148,8 +148,8 @@ void __init kasan_init(void)
>>              (void *)kasan_mem_to_shadow((void *)VMALLOC_END));
>>
>>      for_each_mem_range(i, &_start, &_end) {
>> -        void *start = (void *)_start;
>> -        void *end = (void *)_end;
>> +        void *start = (void *)__va(_start);
>> +        void *end = (void *)__va(_end);
>>
>>          if (start >= end)
>>              break;
> 
> Thanks, but unless I'm missing something this is already in Linus' tree as
> c25a053e1577 ("riscv: Fix KASAN memory mapping.").

You're right, I missed this one: but for some reasons, this patch does 
not appear in for-next.

Thanks,

Alex

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

Patch

diff --git a/arch/riscv/mm/kasan_init.c b/arch/riscv/mm/kasan_init.c
index 4b9149f963d3..6d3b88f2c566 100644
--- a/arch/riscv/mm/kasan_init.c
+++ b/arch/riscv/mm/kasan_init.c
@@ -148,8 +148,8 @@  void __init kasan_init(void)
 			(void *)kasan_mem_to_shadow((void *)VMALLOC_END));
 
 	for_each_mem_range(i, &_start, &_end) {
-		void *start = (void *)_start;
-		void *end = (void *)_end;
+		void *start = (void *)__va(_start);
+		void *end = (void *)__va(_end);
 
 		if (start >= end)
 			break;