From patchwork Thu Mar 2 19:56:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 63552 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp44204wrd; Thu, 2 Mar 2023 12:03:38 -0800 (PST) X-Google-Smtp-Source: AK7set/YviHcuiFrtiMj835NBuK+n06LbOS6IjvljWR67OWpok238uz2ZJo5Uaon6miGiEelScH/ X-Received: by 2002:a17:90a:4b:b0:237:9f75:6937 with SMTP id 11-20020a17090a004b00b002379f756937mr13050280pjb.28.1677787417771; Thu, 02 Mar 2023 12:03:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1677787417; cv=none; d=google.com; s=arc-20160816; b=TVDjnh/DCVFCmAi0LOeWSAfpA84GtymdqvdlfBwgk4AFNIMWnTSMhgjkuCK6bhQ7a9 GDF8+InbCmz6P3It7tKQZEyYc7IWIFVeSqVxH0/S7uuNDUwLr7vHSGjj9LulRC7LNiAD S3onk8gI9RAcLH0th5JVnXM5CZhtvMmPcYOlqS4DBLwYMKaONEQZeboaJlHsOKQOzb3H udBFvY8pf1vSQUYYRYltpghSFcgXKtBRdF2NuSynUGhQXhisqQTRRouDsmedLxyqOMt7 D7RWiMqsLRktHkuecpdrna0mt76ZTmH1A6psP5pDd7CdsZZjVpcbEsi3t1bB0fYQNv2S MJJw== 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:dkim-signature :dkim-signature:from; bh=pInHvcVDhlPvPce/Y/2kDlCM4xbrektXByOcawRj+0U=; b=091XzEHZ4drLFtZfP/8UCY3xUKqhyQMbk7PA+w8Ev0sts+EIJqWkoTZgGShr8nbEbX pjN524gBffsDlZkefy2x9ROqeACLLkT8fnQ5TC4ShrAwsW30+l1NdzJt9OXe+p+msWBN gOGp4x0xhWSN8ey0jB67vD6zHTU3iJP1EHqtrYECSs87JvNlaNxXSUCp0Em8XV+icJsl R93K8eTJB0B4JWoAwtWHwT7GQGPCpUlZtktPjbGlKW8UTzE+p1FbRTKStJ9eLhl87KeM zmKxQwpU4PiZH6lGjmqn8Wz8K/XZbhZVey6CYnKzifkFcqpf/++odSqAG2NYzeznRzkR ZRFw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=h1FbnCMG; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=maOqQIw3; 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=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x15-20020a17090a46cf00b00234b4a5cbb8si3113391pjg.33.2023.03.02.12.03.24; Thu, 02 Mar 2023 12:03:37 -0800 (PST) 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=@linutronix.de header.s=2020 header.b=h1FbnCMG; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=maOqQIw3; 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=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230078AbjCBT6l (ORCPT + 99 others); Thu, 2 Mar 2023 14:58:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55038 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230029AbjCBT5w (ORCPT ); Thu, 2 Mar 2023 14:57:52 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4A78E48E3C for ; Thu, 2 Mar 2023 11:57:51 -0800 (PST) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1677787068; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=pInHvcVDhlPvPce/Y/2kDlCM4xbrektXByOcawRj+0U=; b=h1FbnCMGHQDvQR5n7qJZizMYJFjX9il2feilw35+EzPvA/b1gvi3IxQZhoGDSqoMBfkAFC bcdmRZrczX/5lWhxyohoBiY5o8FEch1kiZht4hLoVSOFdv51lFEsyzcxkb4slBKtDyDtKR X3W8eSvKqfAFUcdpW/Labe6N7r83IPxdily+bPw7jLdYCgn6JXNaDRYyUxbS16gpd3kuPz OwrGiI/0vV/syNp/sQlbeWl9OU0RFDODOIPAKst6+L09Ctc5iOFCVPPcLtFeyCUIiMvXUA 5UF6fxZILwMDXChTqqDICPzKk7wpwpcG3b8QHTDYzo3cO9lf/VPHRYot9H5QwA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1677787068; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=pInHvcVDhlPvPce/Y/2kDlCM4xbrektXByOcawRj+0U=; b=maOqQIw3FYXH1/cDnM8pH2rfYr5sExWFW5Ascwc4DyQUHDC3ZKkIMwpmoF5qNS7tzvuH3d 7/dLoL+9MjTNiYCA== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org Subject: [PATCH printk v1 18/18] printk: Perform atomic flush in console_flush_on_panic() Date: Thu, 2 Mar 2023 21:02:18 +0106 Message-Id: <20230302195618.156940-19-john.ogness@linutronix.de> In-Reply-To: <20230302195618.156940-1-john.ogness@linutronix.de> References: <20230302195618.156940-1-john.ogness@linutronix.de> MIME-Version: 1.0 X-Spam-Status: No, score=-3.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,INVALID_DATE_TZ_ABSURD, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_PASS 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1759287619210121846?= X-GMAIL-MSGID: =?utf-8?q?1759287619210121846?= Typically the panic() function will take care of atomic flushing the non-BKL consoles on panic. However, there are several users of console_flush_on_panic() outside of panic(). Also perform atomic flushing in console_flush_on_panic(). A new function cons_force_seq() is implemented to support the mode=CONSOLE_REPLAY_ALL feature. Signed-off-by: John Ogness --- kernel/printk/internal.h | 2 ++ kernel/printk/printk.c | 28 ++++++++++++++++++++++------ kernel/printk/printk_nobkl.c | 24 ++++++++++++++++++++++++ 3 files changed, 48 insertions(+), 6 deletions(-) diff --git a/kernel/printk/internal.h b/kernel/printk/internal.h index a417e3992b7a..f147ca386afa 100644 --- a/kernel/printk/internal.h +++ b/kernel/printk/internal.h @@ -79,6 +79,7 @@ bool cons_nobkl_init(struct console *con); bool cons_alloc_percpu_data(struct console *con); void cons_kthread_create(struct console *con); void cons_wake_threads(void); +void cons_force_seq(struct console *con, u64 seq); /* * Check if the given console is currently capable and allowed to print @@ -148,6 +149,7 @@ static inline void cons_kthread_create(struct console *con) { } static inline bool printk_percpu_data_ready(void) { return false; } static inline bool cons_nobkl_init(struct console *con) { return true; } static inline void cons_nobkl_cleanup(struct console *con) { } +static inline void cons_force_seq(struct console *con, u64 seq) { } #endif /* CONFIG_PRINTK */ diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index 015c240f9f04..9a8ba8b3dca5 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -3160,6 +3160,28 @@ void console_unblank(void) */ void console_flush_on_panic(enum con_flush_mode mode) { + struct console *c; + short flags; + int cookie; + u64 seq; + + seq = prb_first_valid_seq(prb); + + /* + * Safely flush the atomic consoles before trying to flush any + * BKL/legacy consoles. + */ + if (mode == CONSOLE_REPLAY_ALL) { + cookie = console_srcu_read_lock(); + for_each_console_srcu(c) { + flags = console_srcu_read_flags(c); + if (flags & CON_NO_BKL) + cons_force_seq(c, seq); + } + console_srcu_read_unlock(cookie); + } + cons_atomic_flush(NULL, true); + if (!have_bkl_console) return; @@ -3174,12 +3196,6 @@ void console_flush_on_panic(enum con_flush_mode mode) console_may_schedule = 0; if (mode == CONSOLE_REPLAY_ALL) { - struct console *c; - int cookie; - u64 seq; - - seq = prb_first_valid_seq(prb); - cookie = console_srcu_read_lock(); for_each_console_srcu(c) { /* diff --git a/kernel/printk/printk_nobkl.c b/kernel/printk/printk_nobkl.c index 53989c8f1dbc..ac2ba785500e 100644 --- a/kernel/printk/printk_nobkl.c +++ b/kernel/printk/printk_nobkl.c @@ -233,6 +233,30 @@ static void cons_seq_init(struct console *con) #endif } +/** + * cons_force_seq - Force a specified sequence number for a console + * @con: Console to work on + * @seq: Sequence number to force + * + * This function is only intended to be used in emergency situations. In + * particular: console_flush_on_panic(CONSOLE_REPLAY_ALL) + */ +void cons_force_seq(struct console *con, u64 seq) +{ +#ifdef CONFIG_64BIT + struct cons_state old; + struct cons_state new; + + do { + cons_state_read(con, CON_STATE_CUR, &old); + copy_bit_state(new, old); + new.seq = seq; + } while (!cons_state_try_cmpxchg(con, CON_STATE_CUR, &old, &new)); +#else + atomic_set(&ACCESS_PRIVATE(con, atomic_seq), seq); +#endif +} + static inline u64 cons_expand_seq(u64 seq) { u64 rbseq;