Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp1901288pxb; Wed, 30 Mar 2022 12:13:23 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw8QI67nMwFOTcnUaFQMSYeXOJZhEoGnHN/+PT2ud5pAZu0kyXmVbTtpbEkQjXqm4HrKJvZ X-Received: by 2002:a17:906:7943:b0:6df:e5b3:6553 with SMTP id l3-20020a170906794300b006dfe5b36553mr1188290ejo.398.1648667602587; Wed, 30 Mar 2022 12:13:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648667602; cv=none; d=google.com; s=arc-20160816; b=PiTgp7AWWq9Ldw7CdEIl+X6xuwjTzkei+tmsKVxVCVjUKC0Zei61auINUqnfxu0bZj bwr7LyDpsH5ZJJnlCPy5tU9Fuz/YaZJtXEGgkoCIVl63QICsqmKiXEoUIVRShPP3om4a HESnUcFI56aSU2DKleOa6Vjx0vvvPZM22GDBbOc40k6JIqYXi1MSUda5S4t2SqTg+Yfj QjDFCV9qthVgVz1E2Bw8P+c2sfMf3hmMsjYiZtQHEZmZePhEsokZdCfIPpva24vmptrk aHNt0So1Re6I2KWsbF9N85MTrc0EKtVAGzWg+9PTPORkOCTfunCrs8/9+DxL7yj0396Q Z4tw== 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=+d/PreTyeXsZfr1oCll8Hb1BaPKfeJGQ40jGDJyJJbo=; b=OqVatPHMq5X9U+qPSD7YWG6Y3rqZpf3QUr0W5V/rg5vafblnwsDdRz8MMT8h33iJ3k YBkBOdFO39eyOx7IZ055NesnWIXz7X/GUmppdtOfEEszfhgZXYUGsAvn+43uGrlWNMFd wqFt2mqFUhdWGsf+MV2nesULWvBS9k3Qq9K+oIoZscPnK0wFiAsLTyC551IjfzARu448 h0Ew/1jwErwC1KcgOg+YgZxpdMC0GiAbj2uvRO6flV3IwzQbNl7HUco+HSScsiJYsfi/ muybQ2F1qOSsfhGILgkfLwNfKv28evfzrTn0cNhsFgE+/s7saly8JMYrxAdSpj7tmPn3 T5UA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ln0YwYjW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k5-20020aa7c045000000b004198e82318dsi21376655edo.79.2022.03.30.12.12.56; Wed, 30 Mar 2022 12:13:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ln0YwYjW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242069AbiC3MAX (ORCPT + 99 others); Wed, 30 Mar 2022 08:00:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59274 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344690AbiC3LxZ (ORCPT ); Wed, 30 Mar 2022 07:53:25 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 523B526C57B; Wed, 30 Mar 2022 04:49:28 -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 D0D74B81C24; Wed, 30 Mar 2022 11:49:27 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6DAE4C340EE; Wed, 30 Mar 2022 11:49:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1648640966; bh=E55ebv/N5h1JzNgoTODDqTjBKt/rPNRqhyYYRctfcz8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ln0YwYjWKUf1in6YJ3rbMPSe9vaH/RE5Hl2RXGA5q31SVtWZWhcx3dWAweBtRePQt GBR+WobE9Rv6XZ5qYHqDlXsx+9Y4rhvo8ElA64tpZB0UB+4K8Cx06f5WtyDyJPsXzF n6n87uXb4w9rOmpLheIb2huzLR+OfUa0Fc7FgE6ePD4VVP9koxl/pKW1m3M8+j5bEn K4PABlIXfHFnN0CTIZOQpq0+iJ8JT+CJavlLqyFiBid5uWj/rCbjQgLZz+vxLQq2Vu /Z/qI7VSW7/60SG3O+fs4cjKmy+UN2ubJDT9oO6FGp7AQJ3RtfO9kuo8SHEfScWLFS S+PBtuOpdQmEw== 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, linux@roeck-us.net, stephen.s.brennan@oracle.com, gregkh@linuxfoundation.org Subject: [PATCH AUTOSEL 5.16 35/59] printk: use atomic updates for klogd work Date: Wed, 30 Mar 2022 07:48:07 -0400 Message-Id: <20220330114831.1670235-35-sashal@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220330114831.1670235-1-sashal@kernel.org> References: <20220330114831.1670235-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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 92eb7785e6e7..9aa27702363c 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -3257,7 +3257,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 */ @@ -3291,7 +3291,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