From nobody Sat Oct 4 22:35:29 2025 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AEE3D258CDF for ; Tue, 12 Aug 2025 12:50:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755003054; cv=none; b=Yb0IeqDLFNMkaCFbpSYcwuWZYEGsNimg+ELpBw4rmiPPGkB/ilDz2UgkYnCc+7+LPewSg6sEoYUDvk5CE8qUD2kD+0NYw67bXHnzm7M11v5i58PbWykY766rmMjqISG23JaMexaPvid1egEsvpH2ji89YG5HyJfc7Gon9v2XxFM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755003054; c=relaxed/simple; bh=bnmrtZpr6JNf7FB8rzp2u6XrM3bDUnV0svmYGEKWX8c=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-type; b=fZ2CXkTYxoTni/e0J8pVdvludI4pp7nHjVMZqfAjmXqj8I0Ma5FTI4YZPDKVdV81lCXUZOEog16nxZQEbYapj1Wkmr89Z8W4dAoWyBH86paCKWNLBq3S8TFQb5HZn7HlZhs75U1AHIUh3Cz/YShcCBrffo2RTNvqa/LzK1JDdiE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=WgbGkryD; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="WgbGkryD" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1755003051; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=jd0CGLClfWsUYGgm7aK9F7vU1kBgjVrUFDs4V0d+D1M=; b=WgbGkryDlB2olDTpvjbe/nt1Khgf2kfqqy+m5KDHJcPgjHwUzo1vLnnoB1f2YtylCiEwG4 fCCkgqG6hK8RkpxB2hrl1KzqIDK2pVmoTjs4M5UHbn5JuqX8W0pe4Kz04S0uI8m+Ns9Sll NZYdQDmhixhVGUHhRTCuDm0O2j1W9Lw= Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-655-aJnDQK3BP9GHbyaEUfDmJQ-1; Tue, 12 Aug 2025 08:50:46 -0400 X-MC-Unique: aJnDQK3BP9GHbyaEUfDmJQ-1 X-Mimecast-MFC-AGG-ID: aJnDQK3BP9GHbyaEUfDmJQ_1755003044 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 90BF2180047F; Tue, 12 Aug 2025 12:50:44 +0000 (UTC) Received: from MiWiFi-R3L-srv.redhat.com (unknown [10.72.112.156]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 140FC300145D; Tue, 12 Aug 2025 12:50:37 +0000 (UTC) From: Baoquan He To: linux-mm@kvack.org Cc: ryabinin.a.a@gmail.com, glider@google.com, andreyknvl@gmail.com, dvyukov@google.com, vincenzo.frascino@arm.com, akpm@linux-foundation.org, kasan-dev@googlegroups.com, linux-kernel@vger.kernel.org, kexec@lists.infradead.org, sj@kernel.org, lorenzo.stoakes@oracle.com, elver@google.com, snovitoll@gmail.com, Baoquan He Subject: [PATCH v2 07/12] arch/powerpc: don't initialize kasan if it's disabled Date: Tue, 12 Aug 2025 20:49:36 +0800 Message-ID: <20250812124941.69508-8-bhe@redhat.com> In-Reply-To: <20250812124941.69508-1-bhe@redhat.com> References: <20250812124941.69508-1-bhe@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 Content-Type: text/plain; charset="utf-8" This includes 32bit, book3s/64 and book3e/64. And also add code to enable kasan_flag_enabled, this is for later usage. Signed-off-by: Baoquan He --- arch/powerpc/mm/kasan/init_32.c | 8 +++++++- arch/powerpc/mm/kasan/init_book3e_64.c | 6 ++++++ arch/powerpc/mm/kasan/init_book3s_64.c | 6 ++++++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/arch/powerpc/mm/kasan/init_32.c b/arch/powerpc/mm/kasan/init_3= 2.c index 03666d790a53..b0c465f3fbf5 100644 --- a/arch/powerpc/mm/kasan/init_32.c +++ b/arch/powerpc/mm/kasan/init_32.c @@ -141,6 +141,9 @@ void __init kasan_init(void) u64 i; int ret; =20 + if (kasan_arg_disabled) + return; + for_each_mem_range(i, &base, &end) { phys_addr_t top =3D min(end, total_lowmem); =20 @@ -163,6 +166,9 @@ void __init kasan_init(void) =20 clear_page(kasan_early_shadow_page); =20 + /* KASAN is now initialized, enable it. */ + static_branch_enable(&kasan_flag_enabled); + /* At this point kasan is fully initialized. Enable error messages */ init_task.kasan_depth =3D 0; pr_info("KASAN init done\n"); @@ -170,7 +176,7 @@ void __init kasan_init(void) =20 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(); } =20 diff --git a/arch/powerpc/mm/kasan/init_book3e_64.c b/arch/powerpc/mm/kasan= /init_book3e_64.c index 60c78aac0f63..1e1c10467a2b 100644 --- a/arch/powerpc/mm/kasan/init_book3e_64.c +++ b/arch/powerpc/mm/kasan/init_book3e_64.c @@ -111,6 +111,9 @@ void __init kasan_init(void) u64 i; pte_t zero_pte =3D pfn_pte(virt_to_pfn(kasan_early_shadow_page), PAGE_KER= NEL_RO); =20 + if (kasan_arg_disabled) + return; + for_each_mem_range(i, &start, &end) kasan_init_phys_region(phys_to_virt(start), phys_to_virt(end)); =20 @@ -125,6 +128,9 @@ void __init kasan_init(void) =20 memset(kasan_early_shadow_page, 0, PAGE_SIZE); =20 + /* KASAN is now initialized, enable it. */ + static_branch_enable(&kasan_flag_enabled); + /* Enable error messages */ init_task.kasan_depth =3D 0; pr_info("KASAN init done\n"); diff --git a/arch/powerpc/mm/kasan/init_book3s_64.c b/arch/powerpc/mm/kasan= /init_book3s_64.c index 7d959544c077..9c5cf2354c8b 100644 --- a/arch/powerpc/mm/kasan/init_book3s_64.c +++ b/arch/powerpc/mm/kasan/init_book3s_64.c @@ -56,6 +56,9 @@ void __init kasan_init(void) u64 i; pte_t zero_pte =3D pfn_pte(virt_to_pfn(kasan_early_shadow_page), PAGE_KER= NEL); =20 + if (kasan_arg_disabled) + return; + if (!early_radix_enabled()) { pr_warn("KASAN not enabled as it requires radix!"); return; @@ -94,6 +97,9 @@ void __init kasan_init(void) =20 static_branch_inc(&powerpc_kasan_enabled_key); =20 + /* KASAN is now initialized, enable it. */ + static_branch_enable(&kasan_flag_enabled); + /* Enable error messages */ init_task.kasan_depth =3D 0; pr_info("KASAN init done\n"); --=20 2.41.0