From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 466E21C3D for ; Fri, 3 Feb 2023 10:16:09 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8B884C433D2; Fri, 3 Feb 2023 10:16:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1675419369; bh=nRmQ2yB8snjffGeonwL2aUNm/OyahtMdnKhusCjEK6o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=shESBfRd2XVFgLMTD26vTGE3ksfJf+lZFsU38p1KGh9/pnNf8d7zE1HNURzAwu8fV vL6NfhwUIo+YsS5El64lg+zyKLE3CtSSivVy3Cp4zQOVrsREFHTff9a9RWqIfOeo67 CUzFB67UVM4BLyqv/e228i2uKi6S4bDo+MgXukmY= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Tiezhu Yang , Marco Elver , Andrey Ryabinin , Baoquan He , Jonathan Corbet , Xuefeng Li , Andrew Morton , Linus Torvalds , Eric Biggers Subject: [PATCH 4.14 46/62] panic: unset panic_on_warn inside panic() Date: Fri, 3 Feb 2023 11:12:42 +0100 Message-Id: <20230203101014.916293954@linuxfoundation.org> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230203101012.959398849@linuxfoundation.org> References: <20230203101012.959398849@linuxfoundation.org> User-Agent: quilt/0.67 Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From: Tiezhu Yang commit 1a2383e8b84c0451fd9b1eec3b9aab16f30b597c upstream. In the current code, the following three places need to unset panic_on_warn before calling panic() to avoid recursive panics: kernel/kcsan/report.c: print_report() kernel/sched/core.c: __schedule_bug() mm/kfence/report.c: kfence_report_error() In order to avoid copy-pasting "panic_on_warn = 0" all over the places, it is better to move it inside panic() and then remove it from the other places. Link: https://lkml.kernel.org/r/1644324666-15947-4-git-send-email-yangtiezhu@loongson.cn Signed-off-by: Tiezhu Yang Reviewed-by: Marco Elver Cc: Andrey Ryabinin Cc: Baoquan He Cc: Jonathan Corbet Cc: Xuefeng Li Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Eric Biggers Signed-off-by: Greg Kroah-Hartman --- kernel/panic.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) --- a/kernel/panic.c +++ b/kernel/panic.c @@ -139,6 +139,16 @@ void panic(const char *fmt, ...) int old_cpu, this_cpu; bool _crash_kexec_post_notifiers = crash_kexec_post_notifiers; + if (panic_on_warn) { + /* + * This thread may hit another WARN() in the panic path. + * Resetting this prevents additional WARN() from panicking the + * system on this thread. Other threads are blocked by the + * panic_mutex in panic(). + */ + panic_on_warn = 0; + } + /* * Disable local interrupts. This will prevent panic_smp_self_stop * from deadlocking the first cpu that invokes the panic, since @@ -536,16 +546,8 @@ void __warn(const char *file, int line, if (args) vprintk(args->fmt, args->args); - if (panic_on_warn) { - /* - * This thread may hit another WARN() in the panic path. - * Resetting this prevents additional WARN() from panicking the - * system on this thread. Other threads are blocked by the - * panic_mutex in panic(). - */ - panic_on_warn = 0; + if (panic_on_warn) panic("panic_on_warn set ...\n"); - } print_modules();