Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp2139224iof; Tue, 7 Jun 2022 21:04:01 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzpp/CfL6864NNyY54ZCIP7AaPPTSfDY+uZbopwtqGo6VZ9E3xb5CQorrG2XE7RlqdFKC+5 X-Received: by 2002:a63:f046:0:b0:3fd:a876:10c9 with SMTP id s6-20020a63f046000000b003fda87610c9mr13651624pgj.237.1654661041757; Tue, 07 Jun 2022 21:04:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654661041; cv=none; d=google.com; s=arc-20160816; b=CEu5BZGh3fr3uP1c9CBt7+4uz7hrMB2BYiOdOVqdQUl0MFyNSlU2AVhPCUcPr71/e8 lXMX/5SCSN2+Ns9aTVXkDaUiGQfIlSrlxul3RTyv6+LiXi1GM3/02g5DAxXJnI7PJJoj Cc4oIpaniEEDlhG5bYBEBhBXYpgjgVc0pUfLyH+xLTxfYUPRYclf0IbdbuwXDOA+5daj +tpM+cW2VKA1UDZbY/llqwAr24BhNYQUtBzAzRhsI1YQeGRY3t9J7+Z/OgeV1n6z9v4R Mgz/Fh3kNJdYOpEPVdYheZwHKzv7bXGIdZNcSoienL2BTQm0jNtt+uSS6HHdnDDIJKZJ e4LQ== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=EZtUzZC2R9s4dR6Q/0nakhVUiC3FxCNF7czdBoLHKI4=; b=H5BLssRTaTndH35hxYyWjqMmkwE4SUVn2pYf0jXIh4eP5Ct9vThHW/KW/H67D7OA6k 6Fn69ClU+7FYAeUACFlgQcAydJbPhdVcHd11LVu/BTbKWg3+6NeS8Pwfi+dGHIcCRKhJ tUOevjyMVUXXOcLlCmZzzv/WpoJGEt4MVK6WQTujChxIJt1LX+7o0JORFrZ+wRNsVU5l A8Udnp9JA7qAk7ooV7lo4PwO9LwsC/CDzGj6MuvKS+8oJ+QXdw26YLudPwO1xFxXvS0P bbJ3G8uhpEv2N6kkDaUBNz/CW9jVg74vsAXU9PRCy/T7lG0mOUlvMJ9MGMA4QSB5UcJx n9XA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=kNJGTark; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id m19-20020a63ed53000000b003f605851c65si26331562pgk.303.2022.06.07.21.04.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jun 2022 21:04:01 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=kNJGTark; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 9D30720B7D6; Tue, 7 Jun 2022 20:29:43 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1381627AbiFGWhU (ORCPT + 99 others); Tue, 7 Jun 2022 18:37:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38842 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1378743AbiFGVX4 (ORCPT ); Tue, 7 Jun 2022 17:23:56 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1E6AB227CCA; Tue, 7 Jun 2022 12:00:59 -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 C6BC6B8239D; Tue, 7 Jun 2022 19:00:57 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 29D60C385A2; Tue, 7 Jun 2022 19:00:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1654628456; bh=gPNm/Stsz87WXeMK4jr5IewBkETfcfvKl7Nyf7dX7PI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kNJGTarkdP2oskPrBZbA5eI6ZepXboOyzjsaDUjGGXT6WghVho6tl1AJu68R6K+BT /rDZZ/SHLyvp1dpaLREmBJvrkyqGk5RsSDhlU+imXTsHBsJzKZ9v9xmZoLySOcJN57 3ZlP1TaEto3/AzWqn2O1ol2Izh4FFPLjuspENBqw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, John Ogness , Petr Mladek , Sasha Levin Subject: [PATCH 5.18 337/879] printk: wake waiters for safe and NMI contexts Date: Tue, 7 Jun 2022 18:57:35 +0200 Message-Id: <20220607165012.638902023@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220607165002.659942637@linuxfoundation.org> References: <20220607165002.659942637@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-3.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 5341b93dea8c39d7612f7a227015d4b1d5cf30db ] When printk() is called from safe or NMI contexts, it will directly store the record (vprintk_store()) and then defer the console output. However, defer_console_output() only causes console printing and does not wake any waiters of new records. Wake waiters from defer_console_output() so that they also are aware of the new records from safe and NMI contexts. Fixes: 03fc7f9c99c1 ("printk/nmi: Prevent deadlock when accessing the main log buffer in NMI") Signed-off-by: John Ogness Reviewed-by: Petr Mladek Signed-off-by: Petr Mladek Link: https://lore.kernel.org/r/20220421212250.565456-6-john.ogness@linutronix.de Signed-off-by: Sasha Levin --- kernel/printk/printk.c | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index ed6f20992915..1ead794fc2f4 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -754,7 +754,7 @@ static ssize_t devkmsg_read(struct file *file, char __user *buf, * prepare_to_wait_event() pairs with the full memory barrier * within wq_has_sleeper(). * - * This pairs with wake_up_klogd:A. + * This pairs with __wake_up_klogd:A. */ ret = wait_event_interruptible(log_wait, prb_read_valid(prb, @@ -1532,7 +1532,7 @@ static int syslog_print(char __user *buf, int size) * prepare_to_wait_event() pairs with the full memory barrier * within wq_has_sleeper(). * - * This pairs with wake_up_klogd:A. + * This pairs with __wake_up_klogd:A. */ len = wait_event_interruptible(log_wait, prb_read_valid(prb, seq, NULL)); /* LMM(syslog_print:A) */ @@ -3332,7 +3332,7 @@ static void wake_up_klogd_work_func(struct irq_work *irq_work) static DEFINE_PER_CPU(struct irq_work, wake_up_klogd_work) = IRQ_WORK_INIT_LAZY(wake_up_klogd_work_func); -void wake_up_klogd(void) +static void __wake_up_klogd(int val) { if (!printk_percpu_data_ready()) return; @@ -3349,22 +3349,26 @@ void wake_up_klogd(void) * * This pairs with devkmsg_read:A and syslog_print:A. */ - if (wq_has_sleeper(&log_wait)) { /* LMM(wake_up_klogd:A) */ - this_cpu_or(printk_pending, PRINTK_PENDING_WAKEUP); + if (wq_has_sleeper(&log_wait) || /* LMM(__wake_up_klogd:A) */ + (val & PRINTK_PENDING_OUTPUT)) { + this_cpu_or(printk_pending, val); irq_work_queue(this_cpu_ptr(&wake_up_klogd_work)); } preempt_enable(); } -void defer_console_output(void) +void wake_up_klogd(void) { - if (!printk_percpu_data_ready()) - return; + __wake_up_klogd(PRINTK_PENDING_WAKEUP); +} - preempt_disable(); - this_cpu_or(printk_pending, PRINTK_PENDING_OUTPUT); - irq_work_queue(this_cpu_ptr(&wake_up_klogd_work)); - preempt_enable(); +void defer_console_output(void) +{ + /* + * New messages may have been added directly to the ringbuffer + * using vprintk_store(), so wake any waiters as well. + */ + __wake_up_klogd(PRINTK_PENDING_WAKEUP | PRINTK_PENDING_OUTPUT); } void printk_trigger_flush(void) -- 2.35.1