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 72C41C433FE for ; Fri, 11 Feb 2022 11:23:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347593AbiBKLXm (ORCPT ); Fri, 11 Feb 2022 06:23:42 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:44718 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229584AbiBKLXk (ORCPT ); Fri, 11 Feb 2022 06:23:40 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 06950E76 for ; Fri, 11 Feb 2022 03:23:39 -0800 (PST) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1644578617; 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: in-reply-to:in-reply-to:references:references; bh=cJouc3QVVJgp9Loq33XddcMozbLzg+YfW/kufsdqZI0=; b=mytSf6U43JAcwtPAgFiKRtJnZWHudGff1Aew3V7cNfL4s41Y83whscxKdQD52MhQrfA9BK LSvzUxjAKVVLTAEZu6GwjDqbvWxCDFDrpBYqJrsTW3YgKgyYyRoD9gxzcOieCnVl9Lv4Dh E3ZnRyOZDKrcY9yo/IeusvP880JQw6X8NYoDo1XZgi85e+7SZRQgp/UlIRkEzPOtItnGHQ CpGbDsy7N6ojhVL8BOGwbLkf2aq30GV72TwKyMdoQGdqMIfqbdv61kKvzGs0lexcxJRRQZ k/md7dqufPmn56s334JrJQ/Yzz4Eh7JpGw/DI/eS2lIV6GtAyU+BB1UwseBThw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1644578617; 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: in-reply-to:in-reply-to:references:references; bh=cJouc3QVVJgp9Loq33XddcMozbLzg+YfW/kufsdqZI0=; b=s0dfgbJw22swlYUJdQo//bR6+cWJhp5EifVkE4igyRY/69hJx7ZKF0t0IUCmkASf9T7ve5 kV/3tnLpgZy/c3DA== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , linux-kernel@vger.kernel.org, Sebastian Andrzej Siewior Subject: [PATCH v3] printk: use atomic updates for klogd work In-Reply-To: <87leyhd4wc.fsf@jogness.linutronix.de> References: <20220203112915.1350753-1-john.ogness@linutronix.de> <87bkzj3t77.fsf@jogness.linutronix.de> <87leyhd4wc.fsf@jogness.linutronix.de> Date: Fri, 11 Feb 2022 12:29:37 +0106 Message-ID: <87iltld4ue.fsf@jogness.linutronix.de> MIME-Version: 1.0 Content-Type: text/plain Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- Changes: v3: also fix __this_cpu_xchg() usage v2: fix commit message 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 82abfaf3c2aa..c7280b40de6c 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -3228,7 +3228,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 */ @@ -3262,7 +3262,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.30.2