Re: [PATCH v5 09/15] arch/powerpc: don't initialize kasan if it's disabled

Sourabh Jain
2026-03-17T02:40:10Z

On 12/03/26 16:53, Christophe Leroy (CS GROUP) wrote:
>
>
> Le 12/03/2026 à 12:12, Sourabh Jain a écrit :
>>
>>
>> On 25/02/26 13:44, Baoquan He wrote:
>>> Here, kasan is disabled if specified 'kasan=off' in kernel cmdline.
>>>
>>> This includes 32bit, book3s/64 and book3e/64.
>>>
>>> Signed-off-by: Baoquan He <bhe@redhat.com>
>>> Cc: linuxppc-dev@lists.ozlabs.org
>>> ---
>>>   arch/powerpc/mm/kasan/init_32.c        | 6 +++++-
>>>   arch/powerpc/mm/kasan/init_book3e_64.c | 4 ++++
>>>   arch/powerpc/mm/kasan/init_book3s_64.c | 4 ++++
>>>   3 files changed, 13 insertions(+), 1 deletion(-)
>>>
>>> diff --git a/arch/powerpc/mm/kasan/init_32.c
>>> b/arch/powerpc/mm/kasan/ init_32.c
>>> index 1d083597464f..0ea2a636c992 100644
>>> --- a/arch/powerpc/mm/kasan/init_32.c
>>> +++ b/arch/powerpc/mm/kasan/init_32.c
>>> @@ -141,6 +141,10 @@ void __init kasan_init(void)
>>>       u64 i;
>>>       int ret;
>>> +    /* If KASAN is disabled via command line, don't initialize it. */
>>> +    if (kasan_arg_disabled)
>>> +        return;
>>> +
>>>       for_each_mem_range(i, &base, &end) {
>>>           phys_addr_t top = min(end, total_lowmem);
>>> @@ -170,7 +174,7 @@ void __init kasan_init(void)
>>>   void __init kasan_late_init(void)
>>>   {
>>> -    if (IS_ENABLED(CONFIG_KASAN_VMALLOC))
>>> +    if (IS_ENABLED(CONFIG_KASAN_VMALLOC) && kasan_enabled())
>>>           kasan_unmap_early_shadow_vmalloc();
>>>   }
>>> diff --git a/arch/powerpc/mm/kasan/init_book3e_64.c
>>> b/arch/powerpc/mm/ kasan/init_book3e_64.c
>>> index 0d3a73d6d4b0..fbe4c9a7e460 100644
>>> --- a/arch/powerpc/mm/kasan/init_book3e_64.c
>>> +++ b/arch/powerpc/mm/kasan/init_book3e_64.c
>>> @@ -111,6 +111,10 @@ void __init kasan_init(void)
>>>       u64 i;
>>>       pte_t zero_pte = pfn_pte(virt_to_pfn(kasan_early_shadow_page),
>>> PAGE_KERNEL_RO);
>>> +    /* If KASAN is disabled via command line, don't initialize it. */
>>> +    if (kasan_arg_disabled)
>>> +        return;
>>> +
>>>       for_each_mem_range(i, &start, &end)
>>>           kasan_init_phys_region(phys_to_virt(start),
>>> phys_to_virt(end));
>>> diff --git a/arch/powerpc/mm/kasan/init_book3s_64.c
>>> b/arch/powerpc/mm/ kasan/init_book3s_64.c
>>> index dcafa641804c..f7906f9ef9be 100644
>>> --- a/arch/powerpc/mm/kasan/init_book3s_64.c
>>> +++ b/arch/powerpc/mm/kasan/init_book3s_64.c
>>> @@ -54,6 +54,10 @@ void __init kasan_init(void)
>>>       u64 i;
>>>       pte_t zero_pte = pfn_pte(virt_to_pfn(kasan_early_shadow_page),
>>> PAGE_KERNEL);
>>> +    /* If KASAN is disabled via command line, don't initialize it. */
>>> +    if (kasan_arg_disabled)
>>> +        return;
>>> +
>>>       if (!early_radix_enabled()) {
>>>           pr_warn("KASAN not enabled as it requires radix!");
>>>           return;
>>
>> Should we log in the kernel log buffer that KASAN is disabled?
>>
>> Right now, I don't see the kernel advertising the same.
>
> When KASAN is enabled it is advertised with:
>
>     pr_info("KernelAddressSanitizer initialized (generic)\n");
>
> Isn't the absence of that message enough to understand KASAN is not
> there ?

Yes this should work. Thanks.

- Sourabh Jain

>
>>
>> $ dmesg | grep -i kasan
>> [    0.000000] Kernel command line: BOOT_IMAGE=(ieee1275//vdevice/v-
>> scsi@30000070/disk@8100000000000000,msdos2)/vmlinuz-7.0.0-rc3+
>> crashkernel=2G kasan=off
>>
>> Tested this series on powerpc Pseries platform.
>> So feel free to add:
>> Tested-by: Sourabh Jain <sourabhjain@linux.ibm.com>
>>
>> - Sourabh Jain
>>
>