From nobody Sat Nov 30 12:49:04 2024 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 716D518A6C5; Mon, 9 Sep 2024 17:27:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725902878; cv=none; b=ELcpa8JxuuBwtLc8DuoA+Z/iMYjup52D6EezK5eZ9dl1g1Jubzmc3mzVRuekBU2YOZRaVqMAqygA3Sk6U0GJDgMJ4hK0leq1zzxEtywRYpc1vtmPolHJ96qk1z5RzYNylgCJZMN/r3ET9+oZDGPi3Dx6nEcQQwPCxSnn/EZyVWY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725902878; c=relaxed/simple; bh=/Ae1vTCFvBQ2+HBVkNd9q212iMR9nHEurZYfam1ZUwE=; h=Date:From:To:Subject:Cc:In-Reply-To:References:MIME-Version: Message-ID:Content-Type; b=MP0o3aWbPBquQCIj7qHULJ+LcB0O3FKpEi5FmBRkoY5eLXKpVTMaFiJIU2qcE1j7xDY+C0lMMUBkDPrArfanWs9qlfLh65MOHa7F92+sUB/djuW5je4yRMVplLjzZiarmA+QNXXDNl2jx7c+UHEw0N3zmx6TPSHzDMeKAdoDAJo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=EyupiiUL; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=xZdl3NJS; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="EyupiiUL"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="xZdl3NJS" Date: Mon, 09 Sep 2024 17:27:52 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1725902873; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=34cWTU0Cw0v+DorO8Gayw2ArJA5MPIR1Mlb9qWiJWfE=; b=EyupiiULIaSazyrbpq0gt9nD11rgmeBbENwfhRsZ7iS6J316HdxIhmcn4Ml7msYn0so2AJ Lq+LTviARse++O9xp3iE/jQoqs9ImbOyfGqqmdD67y112MJ8bhAZj753ElS71dGtdEE5a7 J3qEUv6yiP6fuHte1BL/ik+UKSwIAgNRaIks29kRu5oKliDg/Nq1gnlsJLLuG/6YpoJHWZ BtCrxXQpyU2zOMS/ARG/vK5dKKRF9Y8oE1Zb4sbxrFCOjcI0ly4dTVgmS3ugzVdtSW6Uhf N1VVYhaRnxzObGP3PZDaCjkd3zDtdbgLS8ye1SKevi7+9CfAahpOOo+q2AQUew== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1725902873; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=34cWTU0Cw0v+DorO8Gayw2ArJA5MPIR1Mlb9qWiJWfE=; b=xZdl3NJSAHQA0EYN0fXqCEErHHTb+nBHqWx//0LhjwdeFtGrHHmDIGoL93jCHaigGTxHR6 BpZ/LpgoNvKFAgBQ== From: "tip-bot2 for John Ogness" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: sched/rt] printk: nbcon: Use nbcon consoles in console_flush_all() Cc: John Ogness , Petr Mladek , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20240820063001.36405-23-john.ogness@linutronix.de> References: <20240820063001.36405-23-john.ogness@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-ID: <172590287265.2215.17133384482553386626.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Precedence: bulk Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable The following commit has been merged into the sched/rt branch of tip: Commit-ID: c158834b223fbfab3a14855ac203b8d9cddbbefd Gitweb: https://git.kernel.org/tip/c158834b223fbfab3a14855ac203b8d9c= ddbbefd Author: John Ogness AuthorDate: Tue, 20 Aug 2024 08:35:48 +02:06 Committer: Petr Mladek CommitterDate: Wed, 21 Aug 2024 14:56:24 +02:00 printk: nbcon: Use nbcon consoles in console_flush_all() Allow nbcon consoles to print messages in the legacy printk() caller context (printing via unlock) by integrating them into console_flush_all(). The write_atomic() callback is used for printing. Provide nbcon_legacy_emit_next_record(), which acts as the nbcon variant of console_emit_next_record(). Call this variant within console_flush_all() for nbcon consoles. Since nbcon consoles use their own @nbcon_seq variable to track the next record to print, this also must be appropriately handled in console_flush_all(). Note that the legacy printing logic uses @handover to detect handovers for printing all consoles. For nbcon consoles, handovers/takeovers occur on a per-console basis and thus do not cause the console_flush_all() loop to abort. Signed-off-by: John Ogness Reviewed-by: Petr Mladek Link: https://lore.kernel.org/r/20240820063001.36405-23-john.ogness@linutro= nix.de Signed-off-by: Petr Mladek --- kernel/printk/internal.h | 6 +++- kernel/printk/nbcon.c | 87 +++++++++++++++++++++++++++++++++++++++- kernel/printk/printk.c | 17 +++++--- 3 files changed, 105 insertions(+), 5 deletions(-) diff --git a/kernel/printk/internal.h b/kernel/printk/internal.h index 0dc9b92..44468f3 100644 --- a/kernel/printk/internal.h +++ b/kernel/printk/internal.h @@ -78,6 +78,8 @@ void defer_console_output(void); =20 u16 printk_parse_prefix(const char *text, int *level, enum printk_info_flags *flags); +void console_lock_spinning_enable(void); +int console_lock_spinning_disable_and_check(int cookie); =20 u64 nbcon_seq_read(struct console *con); void nbcon_seq_force(struct console *con, u64 seq); @@ -85,6 +87,8 @@ bool nbcon_alloc(struct console *con); void nbcon_free(struct console *con); enum nbcon_prio nbcon_get_default_prio(void); void nbcon_atomic_flush_pending(void); +bool nbcon_legacy_emit_next_record(struct console *con, bool *handover, + int cookie); =20 /* * Check if the given console is currently capable and allowed to print @@ -140,6 +144,8 @@ static inline bool nbcon_alloc(struct console *con) { r= eturn false; } static inline void nbcon_free(struct console *con) { } static inline enum nbcon_prio nbcon_get_default_prio(void) { return NBCON_= PRIO_NONE; } static inline void nbcon_atomic_flush_pending(void) { } +static inline bool nbcon_legacy_emit_next_record(struct console *con, bool= *handover, + int cookie) { return false; } =20 static inline bool console_is_usable(struct console *con, short flags) { r= eturn false; } =20 diff --git a/kernel/printk/nbcon.c b/kernel/printk/nbcon.c index 3982d68..d09c084 100644 --- a/kernel/printk/nbcon.c +++ b/kernel/printk/nbcon.c @@ -992,6 +992,93 @@ enum nbcon_prio nbcon_get_default_prio(void) } =20 /* + * nbcon_atomic_emit_one - Print one record for an nbcon console using the + * write_atomic() callback + * @wctxt: An initialized write context struct to use for this context + * + * Return: True, when a record has been printed and there are still + * pending records. The caller might want to continue flushing. + * + * False, when there is no pending record, or when the console + * context cannot be acquired, or the ownership has been lost. + * The caller should give up. Either the job is done, cannot be + * done, or will be handled by the owning context. + * + * This is an internal helper to handle the locking of the console before + * calling nbcon_emit_next_record(). + */ +static bool nbcon_atomic_emit_one(struct nbcon_write_context *wctxt) +{ + struct nbcon_context *ctxt =3D &ACCESS_PRIVATE(wctxt, ctxt); + + if (!nbcon_context_try_acquire(ctxt)) + return false; + + /* + * nbcon_emit_next_record() returns false when the console was + * handed over or taken over. In both cases the context is no + * longer valid. + * + * The higher priority printing context takes over responsibility + * to print the pending records. + */ + if (!nbcon_emit_next_record(wctxt)) + return false; + + nbcon_context_release(ctxt); + + return ctxt->backlog; +} + +/** + * nbcon_legacy_emit_next_record - Print one record for an nbcon console + * in legacy contexts + * @con: The console to print on + * @handover: Will be set to true if a printk waiter has taken over the + * console_lock, in which case the caller is no longer holding + * both the console_lock and the SRCU read lock. Otherwise it + * is set to false. + * @cookie: The cookie from the SRCU read lock. + * + * Context: Any context except NMI. + * Return: True, when a record has been printed and there are still + * pending records. The caller might want to continue flushing. + * + * False, when there is no pending record, or when the console + * context cannot be acquired, or the ownership has been lost. + * The caller should give up. Either the job is done, cannot be + * done, or will be handled by the owning context. + * + * This function is meant to be called by console_flush_all() to print rec= ords + * on nbcon consoles from legacy context (printing via console unlocking). + * Essentially it is the nbcon version of console_emit_next_record(). + */ +bool nbcon_legacy_emit_next_record(struct console *con, bool *handover, + int cookie) +{ + struct nbcon_write_context wctxt =3D { }; + struct nbcon_context *ctxt =3D &ACCESS_PRIVATE(&wctxt, ctxt); + unsigned long flags; + bool progress; + + /* Use the same procedure as console_emit_next_record(). */ + printk_safe_enter_irqsave(flags); + console_lock_spinning_enable(); + stop_critical_timings(); + + ctxt->console =3D con; + ctxt->prio =3D nbcon_get_default_prio(); + + progress =3D nbcon_atomic_emit_one(&wctxt); + + start_critical_timings(); + *handover =3D console_lock_spinning_disable_and_check(cookie); + printk_safe_exit_irqrestore(flags); + + return progress; +} + +/** * __nbcon_atomic_flush_pending_con - Flush specified nbcon console using = its * write_atomic() callback * @con: The nbcon console to flush diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index b8634a1..f08bf5e 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -1860,7 +1860,7 @@ static bool console_waiter; * there may be a waiter spinning (like a spinlock). Also it must be * ready to hand over the lock at the end of the section. */ -static void console_lock_spinning_enable(void) +void console_lock_spinning_enable(void) { /* * Do not use spinning in panic(). The panic CPU wants to keep the lock. @@ -1899,7 +1899,7 @@ lockdep: * * Return: 1 if the lock rights were passed, 0 otherwise. */ -static int console_lock_spinning_disable_and_check(int cookie) +int console_lock_spinning_disable_and_check(int cookie) { int waiter; =20 @@ -3021,13 +3021,20 @@ static bool console_flush_all(bool do_cond_resched,= u64 *next_seq, bool *handove cookie =3D console_srcu_read_lock(); for_each_console_srcu(con) { short flags =3D console_srcu_read_flags(con); + u64 printk_seq; bool progress; =20 if (!console_is_usable(con, flags)) continue; any_usable =3D true; =20 - progress =3D console_emit_next_record(con, handover, cookie); + if (flags & CON_NBCON) { + progress =3D nbcon_legacy_emit_next_record(con, handover, cookie); + printk_seq =3D nbcon_seq_read(con); + } else { + progress =3D console_emit_next_record(con, handover, cookie); + printk_seq =3D con->seq; + } =20 /* * If a handover has occurred, the SRCU read lock @@ -3037,8 +3044,8 @@ static bool console_flush_all(bool do_cond_resched, u= 64 *next_seq, bool *handove return false; =20 /* Track the next of the highest seq flushed. */ - if (con->seq > *next_seq) - *next_seq =3D con->seq; + if (printk_seq > *next_seq) + *next_seq =3D printk_seq; =20 if (!progress) continue;