From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1C615C433EF for ; Wed, 30 Mar 2022 12:07:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347511AbiC3MG7 (ORCPT ); Wed, 30 Mar 2022 08:06:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55072 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345928AbiC3LzN (ORCPT ); Wed, 30 Mar 2022 07:55:13 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C3760140DF; Wed, 30 Mar 2022 04:52:51 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 6E035B81C29; Wed, 30 Mar 2022 11:52:50 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2368DC36AE5; Wed, 30 Mar 2022 11:52:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1648641169; bh=NypiL6lci9l5j/OmMuO5F34lp2YDjPb0RKdmurJjOlU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mvj3Ho24l+Vt+AF76FWmMgYvYkeI/Zrvi5q1DGvCIXVzKSU54iSBLynuIF/pluNfW LhbfiJVwKVmg0tO7Rgo+cT3Yrpn1N4oNfpiW21lzKzmjYCcwkhhgyOwXQN1a1IYnwR IztfKSPEdQFM7oYz7IyBoY+MTW1lx8A/YQDyFw8fushjeQpXL+lhJSpsmFvPXZ+hgE HLcCcYeIM/o5JAb4jaTSPN5CZQtd/WG6slCMQqSRCK5IXL+X0PLfzXGbrTQ8TThUmd ZtoyCaBJPTysklARAULS6tHDJWymO3QsfxZf8umYZpzJk5KS3vGCeDEN/btTkicn4j pdI+VitqBKVqw== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: John Ogness , Sebastian Andrzej Siewior , Petr Mladek , Sasha Levin , senozhatsky@chromium.org, stephen.s.brennan@oracle.com, linux@roeck-us.net Subject: [PATCH AUTOSEL 5.4 15/25] printk: use atomic updates for klogd work Date: Wed, 30 Mar 2022 07:52:15 -0400 Message-Id: <20220330115225.1672278-15-sashal@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220330115225.1672278-1-sashal@kernel.org> References: <20220330115225.1672278-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: John Ogness [ Upstream commit 2ba3673d70178bf07fb75ff25c54bc478add4021 ] The per-cpu @printk_pending variable can be updated from sleepable contexts, such as: get_random_bytes() warn_unseeded_randomness() printk_deferred() defer_console_output() and can be updated from interrupt contexts, such as: handle_irq_event_percpu() __irq_wake_thread() wake_up_process() try_to_wake_up() select_task_rq() select_fallback_rq() printk_deferred() defer_console_output() and can be updated from NMI contexts, such as: vprintk() if (in_nmi()) defer_console_output() Therefore the atomic variant of the updating functions must be used. Replace __this_cpu_xchg() with this_cpu_xchg(). Replace __this_cpu_or() with this_cpu_or(). Reported-by: Sebastian Andrzej Siewior Signed-off-by: John Ogness Signed-off-by: Petr Mladek Link: https://lore.kernel.org/r/87iltld4ue.fsf@jogness.linutronix.de Signed-off-by: Sasha Levin --- kernel/printk/printk.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index 0989920e8cef..6a67d753485e 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -2990,7 +2990,7 @@ static DEFINE_PER_CPU(int, printk_pending); static void wake_up_klogd_work_func(struct irq_work *irq_work) { - int pending = __this_cpu_xchg(printk_pending, 0); + int pending = this_cpu_xchg(printk_pending, 0); if (pending & PRINTK_PENDING_OUTPUT) { /* If trylock fails, someone else is doing the printing */ @@ -3026,7 +3026,7 @@ void defer_console_output(void) return; preempt_disable(); - __this_cpu_or(printk_pending, PRINTK_PENDING_OUTPUT); + this_cpu_or(printk_pending, PRINTK_PENDING_OUTPUT); irq_work_queue(this_cpu_ptr(&wake_up_klogd_work)); preempt_enable(); } -- 2.34.1