Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3543029pxb; Mon, 24 Jan 2022 11:50:30 -0800 (PST) X-Google-Smtp-Source: ABdhPJz9e1Ol/sliWv2ndDGVkjfkMydxLk1kHv9rFams5wMIm7CH63y545X3bh/sbT96mNA2dVu2 X-Received: by 2002:a17:902:76c8:b0:14a:4a48:cac0 with SMTP id j8-20020a17090276c800b0014a4a48cac0mr16151741plt.90.1643053830534; Mon, 24 Jan 2022 11:50:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643053830; cv=none; d=google.com; s=arc-20160816; b=sfAgNBxTqMqb4KOVmWvtZqS45wnBJX5xevF0ChIqQLc+NqzDJ9Q7N1RebjgI+La0FQ /rsGsc4dhvraBv58Gn9p0XgRxF7CW4H/I8wLvq2sniJPIJ9NhkSDxEt4bzTz9BS1oOZp wrn5DfTfKYIM6o1jhNpYQi5cboOccNBgpFENOfDUqkmwn7KZGUeb2JmooDQspq3YftKb xc57UxxAV2uH9d1M9gTY/SaHXgEIzjqnYva9AKusMHEguIB8dHZWJaHk22ImlMOBMaAr xstwmJ0fLhECsuzwS4V49/YEWiOOYqvWsPbEKYW6AlS83J8FCuqSEPTa7AQvgUv8NpO3 Ls8A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=ypDUrRwpvHxVi9/0pzLPCyjGz64l2U6vLcrEu5OiSo8=; b=qYGDfeG60D+AB0Qdy9bUUx2JeZcxenJ9oJ/oQoT1Ty0pM2oxDQeFdh3AGAbw3HoBHI ttGOrnnHANjUo+GOU5cl73FMe46uwlbyejNZUeGMuQA5e1sUQc7R9MmecfSZozLu7Hkr W5cor34sgsjURpRyW09jLIy9bjBiY+ZktUw6p5/q6NfW1+4zxdmQWEL/168Fd8J7h7KF yryDbrUoj9/j2csRkQDeoOmd/WjsQNDUOfsvBv5wDc2xbjlLiYn1EQ+BNBhE/EHxLEPr fcr1l/Yjr2IU1ZFn2s4lBAR6OIQxB97oDdMuSwyBNzgqqNe/ZbfZfvGxnDUCRwli3Qgm +78g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=h5KNT+HE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id x25si14265823pga.541.2022.01.24.11.50.18; Mon, 24 Jan 2022 11:50:30 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=h5KNT+HE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244959AbiAXSHz (ORCPT + 99 others); Mon, 24 Jan 2022 13:07:55 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32820 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244955AbiAXSHb (ORCPT ); Mon, 24 Jan 2022 13:07:31 -0500 Received: from out0.migadu.com (out0.migadu.com [IPv6:2001:41d0:2:267::]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0A014C061748 for ; Mon, 24 Jan 2022 10:07:30 -0800 (PST) X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1643047649; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ypDUrRwpvHxVi9/0pzLPCyjGz64l2U6vLcrEu5OiSo8=; b=h5KNT+HE1tKNl8ee9QGd2J7zWqwuSghQOwH0ssGabPUeG/2X6n0oVJ+eGPg0ZJJjeEX/Ja qkxlKfLQ+WQdvG4iYDLBizd0WFXWkjtg+5zwMDHoCl1l2+84TzWpdZeElA/8OFOjnTKSe0 Pl06koOQs2H3JvLAj2nhgTZi1e3hAow= From: andrey.konovalov@linux.dev To: Andrew Morton Cc: Andrey Konovalov , Marco Elver , Alexander Potapenko , Dmitry Vyukov , Andrey Ryabinin , kasan-dev@googlegroups.com, linux-mm@kvack.org, Vincenzo Frascino , Catalin Marinas , Will Deacon , Mark Rutland , linux-arm-kernel@lists.infradead.org, Peter Collingbourne , Evgenii Stepanov , linux-kernel@vger.kernel.org, Andrey Konovalov Subject: [PATCH v6 34/39] kasan: clean up feature flags for HW_TAGS mode Date: Mon, 24 Jan 2022 19:05:08 +0100 Message-Id: <76ebb340265be57a218564a497e1f52ff36a3879.1643047180.git.andreyknvl@google.com> In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT X-Migadu-Auth-User: linux.dev Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Andrey Konovalov - Untie kasan_init_hw_tags() code from the default values of kasan_arg_mode and kasan_arg_stacktrace. - Move static_branch_enable(&kasan_flag_enabled) to the end of kasan_init_hw_tags_cpu(). - Remove excessive comments in kasan_arg_mode switch. - Add new comments. Signed-off-by: Andrey Konovalov --- Changes v4->v5: - Add this patch. --- mm/kasan/hw_tags.c | 38 +++++++++++++++++++++----------------- mm/kasan/kasan.h | 2 +- 2 files changed, 22 insertions(+), 18 deletions(-) diff --git a/mm/kasan/hw_tags.c b/mm/kasan/hw_tags.c index 6509809dd5d8..6a3146d1ccc5 100644 --- a/mm/kasan/hw_tags.c +++ b/mm/kasan/hw_tags.c @@ -42,16 +42,22 @@ static enum kasan_arg kasan_arg __ro_after_init; static enum kasan_arg_mode kasan_arg_mode __ro_after_init; static enum kasan_arg_stacktrace kasan_arg_stacktrace __initdata; -/* Whether KASAN is enabled at all. */ +/* + * Whether KASAN is enabled at all. + * The value remains false until KASAN is initialized by kasan_init_hw_tags(). + */ DEFINE_STATIC_KEY_FALSE(kasan_flag_enabled); EXPORT_SYMBOL(kasan_flag_enabled); -/* Whether the selected mode is synchronous/asynchronous/asymmetric.*/ +/* + * Whether the selected mode is synchronous, asynchronous, or asymmetric. + * Defaults to KASAN_MODE_SYNC. + */ enum kasan_mode kasan_mode __ro_after_init; EXPORT_SYMBOL_GPL(kasan_mode); /* Whether to collect alloc/free stack traces. */ -DEFINE_STATIC_KEY_FALSE(kasan_flag_stacktrace); +DEFINE_STATIC_KEY_TRUE(kasan_flag_stacktrace); /* kasan=off/on */ static int __init early_kasan_flag(char *arg) @@ -127,7 +133,11 @@ void kasan_init_hw_tags_cpu(void) * as this function is only called for MTE-capable hardware. */ - /* If KASAN is disabled via command line, don't initialize it. */ + /* + * If KASAN is disabled via command line, don't initialize it. + * When this function is called, kasan_flag_enabled is not yet + * set by kasan_init_hw_tags(). Thus, check kasan_arg instead. + */ if (kasan_arg == KASAN_ARG_OFF) return; @@ -154,42 +164,36 @@ void __init kasan_init_hw_tags(void) if (kasan_arg == KASAN_ARG_OFF) return; - /* Enable KASAN. */ - static_branch_enable(&kasan_flag_enabled); - switch (kasan_arg_mode) { case KASAN_ARG_MODE_DEFAULT: - /* - * Default to sync mode. - */ - fallthrough; + /* Default is specified by kasan_mode definition. */ + break; case KASAN_ARG_MODE_SYNC: - /* Sync mode enabled. */ kasan_mode = KASAN_MODE_SYNC; break; case KASAN_ARG_MODE_ASYNC: - /* Async mode enabled. */ kasan_mode = KASAN_MODE_ASYNC; break; case KASAN_ARG_MODE_ASYMM: - /* Asymm mode enabled. */ kasan_mode = KASAN_MODE_ASYMM; break; } switch (kasan_arg_stacktrace) { case KASAN_ARG_STACKTRACE_DEFAULT: - /* Default to enabling stack trace collection. */ - static_branch_enable(&kasan_flag_stacktrace); + /* Default is specified by kasan_flag_stacktrace definition. */ break; case KASAN_ARG_STACKTRACE_OFF: - /* Do nothing, kasan_flag_stacktrace keeps its default value. */ + static_branch_disable(&kasan_flag_stacktrace); break; case KASAN_ARG_STACKTRACE_ON: static_branch_enable(&kasan_flag_stacktrace); break; } + /* KASAN is now initialized, enable it. */ + static_branch_enable(&kasan_flag_enabled); + pr_info("KernelAddressSanitizer initialized (hw-tags, mode=%s, stacktrace=%s)\n", kasan_mode_info(), kasan_stack_collection_enabled() ? "on" : "off"); diff --git a/mm/kasan/kasan.h b/mm/kasan/kasan.h index 020f3e57a03f..efda13a9ce6a 100644 --- a/mm/kasan/kasan.h +++ b/mm/kasan/kasan.h @@ -12,7 +12,7 @@ #include #include "../slab.h" -DECLARE_STATIC_KEY_FALSE(kasan_flag_stacktrace); +DECLARE_STATIC_KEY_TRUE(kasan_flag_stacktrace); enum kasan_mode { KASAN_MODE_SYNC, -- 2.25.1