From patchwork Sun Feb 18 18:57:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 202866 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp915067dyc; Sun, 18 Feb 2024 11:06:39 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCU0BaUtnN4j4NqA/NU+wdEr4DhhdNfPU8ZV+0BWtGFYidrFg8607gGGzPEXbp5CLbZkDapUQbAoMrhmUWCeg5xSnZl2wQ== X-Google-Smtp-Source: AGHT+IEdqeokhX8UWskuQctZKHadO5X9Tq3rjA6p+2doTwTUTErep9jby3JrOBFXCVRrxpPLiIAz X-Received: by 2002:a05:6a20:9c8d:b0:1a0:77ef:f203 with SMTP id mj13-20020a056a209c8d00b001a077eff203mr11599853pzb.6.1708283198965; Sun, 18 Feb 2024 11:06:38 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708283198; cv=pass; d=google.com; s=arc-20160816; b=BS8svL794jZn03FRr/YsQiIXgh7jCHC4QCGdliCYTb6fTbOBUzGpVEnc8I8VpB0S6m WEdktk0WJuKG0+yA3ChXNAC6KlQm3ydOZyqdGY2wtnkeB1CuVML4uwm5yfbm55Scl/Z9 5k/vlblVmnQOsI+PNpvhuDuSNf7po/nwB3HrSFKXspQH3m1bYbxKHm/Bk9304W4RTBJe bWx7n6QeSujQKNuUGn25/5D/KREtf1n9G25zuDKM0VynP621mDNepnLIw8cQ+6983ewR ldNxCpCRZInmeKloq7GN3t7urHm+kKo4zsTbLiehLnDX6ykQyTSzoCxnWkejj7UxUaWb Tj3Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:dkim-signature:dkim-signature:from; bh=T7h0W3N0f4G0pvkySvFkTqS4E2wnXwr34/jX5hTg2E0=; fh=0Pli4VVduKxZ0fQxWVZuNJh9suMHfKGP1KTFuBeggoo=; b=BsCxMGJWVWuX6zWH38CVrqbci5QxpQEOO+GTB2vOv64Cu73R7e6rmUDiumUcpkNWkj sndSJWU0QGuHvNwpv0vu4WLJVEJITvtNKE8NE0VCYgn9RJa0AFznVv3E8bYkOBwF/Mfo g9Q0PP/BfPq6bVSbnWwT26edpprUxyn1lfUABog131qF9yMtVHks70AARo9Cz9GdwbgF lFNtGPmqVywqAiuZxIzQGfbBZbDzL0eibOFU+N/TpkQuxnFLGZMRY8K0J5pXi4gByFAt rkdgnodC5wAYZTcs6d4jPqjDObqDLTVenySpNCP2Wg4GWOvdpL4gifamOwFFXJeeQ3/B CllA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=QbZvSBMy; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-70533-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-70533-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id e22-20020a656896000000b005cf0309e41bsi3145402pgt.823.2024.02.18.11.06.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 18 Feb 2024 11:06:38 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-70533-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=QbZvSBMy; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-70533-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-70533-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id C05432814F3 for ; Sun, 18 Feb 2024 19:06:38 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DE640745EC; Sun, 18 Feb 2024 19:04:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="QbZvSBMy"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="1z8+tEXm" 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 A85546F09B; Sun, 18 Feb 2024 19:04:33 +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=1708283075; cv=none; b=ooRR9dVBI0UcwFBp8zIu06DK9/rxerYmFct6AmLUn7jyUakUNgdr7qkCGAvXruL52KFwN0DLJG75dCyunSMNqYOJzTSBNqKvGhzGUUXdA7F2rp/ykjNJx0BPf4un+CWt7y2QXCMAzy1+rWO+AuXWLo6+XmjBqUQ76GvKySzyQog= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708283075; c=relaxed/simple; bh=HasGcnsQPSL+51DxJXDfrG8HXukFZjehWiaU2ph0T/w=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=ORgepS+1ySG5mjfXLwPqsP4+P20CTb+DUSFCApEEpIugvnCrltawIBltJR9w9rmcSdgoT2eDZ23cHFunsSosgy4j9FArazqM0fW3uvyMKRFLVtFi9BtHeKzV2AyH0+cRspq6POEtt55K1Ioed6UMqRKiPOa5DGnTGFVpd+Cs+gY= 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=QbZvSBMy; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=1z8+tEXm; 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 From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1708282668; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=T7h0W3N0f4G0pvkySvFkTqS4E2wnXwr34/jX5hTg2E0=; b=QbZvSBMyDM4LOXmsINAW3w29lQi6+iV6oQkdlkV+GEv4sBYFoXHoVGk4LYf57RGYMZm3Lw Agq6rijvE5UuJlE5kduRrbGQHWNTHZ7CR9JG8p8iIUoQuYgOuogv5b5S2koYAlFnLykNpP BIcvF321vrpUKDgkTI0JnGQe2D69ltp0PKCjHlY/Mio9lGQw5UMcCHy29ZOajsOxjue1cB X4umV+QaQqzODLrSyJc0ZAuZGJSYcA6uKzldZvSMX5nPRvUH8cawUaTYPzzZo2d2OuzuIW R+dkjjwKUNILaScRlyDCvBK91fi0MuotaUffV7vgIsZR6lqLkcsmWhCZvm9PCg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1708282668; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=T7h0W3N0f4G0pvkySvFkTqS4E2wnXwr34/jX5hTg2E0=; b=1z8+tEXmXQ18FV+rBWbYgc0kRFK8G2HiNfmJFiIet43GfimLO57gHMXL7MJAJy1NTAVxVb 5IVL+++Q0XAAiiDA== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org, Greg Kroah-Hartman , Jiri Slaby , linux-serial@vger.kernel.org, =?utf-8?q?Ilpo_J=C3=A4rvinen?= Subject: [PATCH printk v2 01/26] serial: core: Provide port lock wrappers Date: Sun, 18 Feb 2024 20:03:01 +0106 Message-Id: <20240218185726.1994771-2-john.ogness@linutronix.de> In-Reply-To: <20240218185726.1994771-1-john.ogness@linutronix.de> References: <20240218185726.1994771-1-john.ogness@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791264763290487308 X-GMAIL-MSGID: 1791264763290487308 From: Thomas Gleixner mainline commit: b0af4bcb49464c221ad5f95d40f2b1b252ceedcc When a serial port is used for kernel console output, then all modifications to the UART registers which are done from other contexts, e.g. getty, termios, are interference points for the kernel console. So far this has been ignored and the printk output is based on the principle of hope. The rework of the console infrastructure which aims to support threaded and atomic consoles, requires to mark sections which modify the UART registers as unsafe. This allows the atomic write function to make informed decisions and eventually to restore operational state. It also allows to prevent the regular UART code from modifying UART registers while printk output is in progress. All modifications of UART registers are guarded by the UART port lock, which provides an obvious synchronization point with the console infrastructure. Provide wrapper functions for spin_[un]lock*(port->lock) invocations so that the console mechanics can be applied later on at a single place and does not require to copy the same logic all over the drivers. Signed-off-by: Thomas Gleixner Reviewed-by: Ilpo Järvinen Signed-off-by: John Ogness Link: https://lore.kernel.org/r/20230914183831.587273-2-john.ogness@linutronix.de Signed-off-by: Greg Kroah-Hartman --- include/linux/serial_core.h | 79 +++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) diff --git a/include/linux/serial_core.h b/include/linux/serial_core.h index bb6f073bc159..f1d5c0d1568c 100644 --- a/include/linux/serial_core.h +++ b/include/linux/serial_core.h @@ -588,6 +588,85 @@ struct uart_port { void *private_data; /* generic platform data pointer */ }; +/** + * uart_port_lock - Lock the UART port + * @up: Pointer to UART port structure + */ +static inline void uart_port_lock(struct uart_port *up) +{ + spin_lock(&up->lock); +} + +/** + * uart_port_lock_irq - Lock the UART port and disable interrupts + * @up: Pointer to UART port structure + */ +static inline void uart_port_lock_irq(struct uart_port *up) +{ + spin_lock_irq(&up->lock); +} + +/** + * uart_port_lock_irqsave - Lock the UART port, save and disable interrupts + * @up: Pointer to UART port structure + * @flags: Pointer to interrupt flags storage + */ +static inline void uart_port_lock_irqsave(struct uart_port *up, unsigned long *flags) +{ + spin_lock_irqsave(&up->lock, *flags); +} + +/** + * uart_port_trylock - Try to lock the UART port + * @up: Pointer to UART port structure + * + * Returns: True if lock was acquired, false otherwise + */ +static inline bool uart_port_trylock(struct uart_port *up) +{ + return spin_trylock(&up->lock); +} + +/** + * uart_port_trylock_irqsave - Try to lock the UART port, save and disable interrupts + * @up: Pointer to UART port structure + * @flags: Pointer to interrupt flags storage + * + * Returns: True if lock was acquired, false otherwise + */ +static inline bool uart_port_trylock_irqsave(struct uart_port *up, unsigned long *flags) +{ + return spin_trylock_irqsave(&up->lock, *flags); +} + +/** + * uart_port_unlock - Unlock the UART port + * @up: Pointer to UART port structure + */ +static inline void uart_port_unlock(struct uart_port *up) +{ + spin_unlock(&up->lock); +} + +/** + * uart_port_unlock_irq - Unlock the UART port and re-enable interrupts + * @up: Pointer to UART port structure + */ +static inline void uart_port_unlock_irq(struct uart_port *up) +{ + spin_unlock_irq(&up->lock); +} + +/** + * uart_port_lock_irqrestore - Unlock the UART port, restore interrupts + * @up: Pointer to UART port structure + * @flags: The saved interrupt flags for restore + */ +static inline void uart_port_unlock_irqrestore(struct uart_port *up, unsigned long flags) +{ + spin_unlock_irqrestore(&up->lock, flags); +} + static inline int serial_port_in(struct uart_port *up, int offset) { return up->serial_in(up, offset); From patchwork Sun Feb 18 18:57:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 202864 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp915049dyc; Sun, 18 Feb 2024 11:06:36 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXdy1C+gX49NMSM6S11hUT0wpFx+ovhTxDJmrX3v+aDwmAhx6Wyd8fs9ECsEv6c7NPkDlPWHEs5OUvhE2/Bx48NL/9l3Q== X-Google-Smtp-Source: AGHT+IGJ3F6Rn/RCEL4PDAQO8kAc80Su4EOlJP1zERyuf3P1Tp+CbiaTfmKmoFDPbwoCB3nNl8Q1 X-Received: by 2002:a05:6a20:9c8b:b0:199:e4ab:691c with SMTP id mj11-20020a056a209c8b00b00199e4ab691cmr13984051pzb.8.1708283196503; Sun, 18 Feb 2024 11:06:36 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708283196; cv=pass; d=google.com; s=arc-20160816; b=VmVbjqQE7qnxCSmhptIWlPGtDDmvivBM0uubEQHsS12ipAcc9C8/OefBmFsq+dZCxj ulZ7sLEqltsNWcfB2Dw4CcK8QZ2LPfN0Z/px95z6hi9qeZ6HmoRkrpEdnQpGLBcVX33D qImoq4rUkJxISQPIr5AyfULNLfx/wpb1i4Qsrfb6Tw9oyuwJIBWPVkm0gHxOWruCgDBv 0xd2LrkTTk57Dkq9IB0/CHBmg8SB3sQZG5Iw3zA4Fo337cQwKVUST+xFmzX3cRv19puN fbLRbOUPCZIBDP9S8lupVyPwXMvFItVNflaEnXowakoW2OTBl1sw/2TIfEVSK2wenKRb nPcw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:dkim-signature:dkim-signature:from; bh=7K5mFiabL7N74FJZwx3sG2fqkTYhk/mX6rh+7t2HHdE=; fh=0Pli4VVduKxZ0fQxWVZuNJh9suMHfKGP1KTFuBeggoo=; b=aVKVXK3Z92S0Fnd4ZuIB6lC1iMkm7cTZLNGr1skmMDbI1W3hi1WDaYrcIb0myWv07z RYfoKWk7/chYVbgh6csPWck9Fod7iP0Jxp4hAS0y9xD9KdphIs5vXW6Va14o3inpVZNR TzE5ZIOdne9zVXAebwGdqtqttJPufCgKZ7PDYwjX6Hy7Uf+XB9QV8ERHC9NL2Y30YspB WTD5ddunjU2SUoz5ddCbTWYjkTCP6khCtVZwUoCC40rv14/R+egmQIRo4cXlNb2Q9W9Y 4Zpv+rNG9K2n0Sj7UJCNYFjXLbynTZRljYom+Wx2/kBSZjDXnxjyyCMKKAbF0O6HezCE 4NSw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b="GM/VNnAa"; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-70531-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-70531-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id e12-20020a65688c000000b0057d7cff25besi3142405pgt.829.2024.02.18.11.06.36 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 18 Feb 2024 11:06:36 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-70531-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b="GM/VNnAa"; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-70531-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-70531-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 5F861B20A5F for ; Sun, 18 Feb 2024 19:06:35 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9B7EC745E0; Sun, 18 Feb 2024 19:04:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="GM/VNnAa"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="j01hjXjY" 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 A862D71B35; Sun, 18 Feb 2024 19:04:33 +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=1708283075; cv=none; b=LzSIsjVjU01EgH+UhpArRIBW+cwraqci/+/xd+3977Ou4bISM/mjZSym3Igv7GurW37Svg9t5GCsr8Q9eOmEW0u+f1HvZblMAxtJiHOA7AVqUOq9gYhXNWnP3mkauYViQpZlbQvyrFh1y4BP9zTdgDcGzjTQ23U4c2ne/1AlUIA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708283075; c=relaxed/simple; bh=MO6Y8tj0NIiymjFHpZwGZycpK1m0Vc+X7D6vRJLm6OQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=HrEYbWttJArkFXIjF+xMLBpbPbfDh/5zC83kX4/AaxPiAyfZCfYDJZoaTZKSn960hiak/SKfzRTNF6nXvzezIDcwxPeaKpYv3UBWl39HByt0fI57OCCuHe+YWHgoU5I7W3oZZ2KZNtood2uRjhGOxySf4M7xlA4jwFqevOQabEU= 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=GM/VNnAa; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=j01hjXjY; 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 From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1708282668; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=7K5mFiabL7N74FJZwx3sG2fqkTYhk/mX6rh+7t2HHdE=; b=GM/VNnAaXsfrk931JW7tOsC8rSnrcoVqetLvg7dHTNoaA0biAHVOo0QDOQZHWoeseZkkwM mRFZ9mcxot4t+TcgT/BPvpiknWQs1OH99Fhd8aPFXFwDfpRwYOpkc7KYUHJfcOa5N4nPDe pwPSogdC84OLic8N43gLNsWNSSyLgBEKssAc9aR2Ts/+DmFWiYxqhtAHK6nP47dn9C2iUv xiRwnf80gRKlr8q8/oWpv3LOCgWxj8qd1UJmWMqWjLMZ0Rb1zHUS2ogv/C4SVqphfIdATV Sd2b+8wJRFJh+jdsehIsvBCLThyeZsFXpZQFuJqj+fdo8czdgU31ep9pzrk0Cg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1708282668; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=7K5mFiabL7N74FJZwx3sG2fqkTYhk/mX6rh+7t2HHdE=; b=j01hjXjY0lEpNjUkrWN71FG4yDfhUXPiKRay1EPW8PknNnIXHNnQV9wJESzRbUmBKK7NOA lIzvZldl2ebOclBw== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org, Greg Kroah-Hartman , Jiri Slaby , linux-serial@vger.kernel.org, =?utf-8?q?Ilpo_J=C3=A4rvinen?= Subject: [PATCH printk v2 02/26] serial: core: Use lock wrappers Date: Sun, 18 Feb 2024 20:03:02 +0106 Message-Id: <20240218185726.1994771-3-john.ogness@linutronix.de> In-Reply-To: <20240218185726.1994771-1-john.ogness@linutronix.de> References: <20240218185726.1994771-1-john.ogness@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791264760980681410 X-GMAIL-MSGID: 1791264760980681410 From: Thomas Gleixner mainline commit: c5cbdb76e8e33ce90fec2946e8eee7d71d68e57a When a serial port is used for kernel console output, then all modifications to the UART registers which are done from other contexts, e.g. getty, termios, are interference points for the kernel console. So far this has been ignored and the printk output is based on the principle of hope. The rework of the console infrastructure which aims to support threaded and atomic consoles, requires to mark sections which modify the UART registers as unsafe. This allows the atomic write function to make informed decisions and eventually to restore operational state. It also allows to prevent the regular UART code from modifying UART registers while printk output is in progress. All modifications of UART registers are guarded by the UART port lock, which provides an obvious synchronization point with the console infrastructure. To avoid adding this functionality to all UART drivers, wrap the spin_[un]lock*() invocations for uart_port::lock into helper functions which just contain the spin_[un]lock*() invocations for now. In a subsequent step these helpers will gain the console synchronization mechanisms. Converted with coccinelle. No functional change. Signed-off-by: Thomas Gleixner Reviewed-by: Ilpo Järvinen Signed-off-by: John Ogness Link: https://lore.kernel.org/r/20230914183831.587273-3-john.ogness@linutronix.de Signed-off-by: Greg Kroah-Hartman --- include/linux/serial_core.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/include/linux/serial_core.h b/include/linux/serial_core.h index f1d5c0d1568c..3091c62ec37b 100644 --- a/include/linux/serial_core.h +++ b/include/linux/serial_core.h @@ -1035,14 +1035,14 @@ static inline void uart_unlock_and_check_sysrq(struct uart_port *port) u8 sysrq_ch; if (!port->has_sysrq) { - spin_unlock(&port->lock); + uart_port_unlock(port); return; } sysrq_ch = port->sysrq_ch; port->sysrq_ch = 0; - spin_unlock(&port->lock); + uart_port_unlock(port); if (sysrq_ch) handle_sysrq(sysrq_ch); @@ -1054,14 +1054,14 @@ static inline void uart_unlock_and_check_sysrq_irqrestore(struct uart_port *port u8 sysrq_ch; if (!port->has_sysrq) { - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); return; } sysrq_ch = port->sysrq_ch; port->sysrq_ch = 0; - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); if (sysrq_ch) handle_sysrq(sysrq_ch); @@ -1077,12 +1077,12 @@ static inline int uart_prepare_sysrq_char(struct uart_port *port, u8 ch) } static inline void uart_unlock_and_check_sysrq(struct uart_port *port) { - spin_unlock(&port->lock); + uart_port_unlock(port); } static inline void uart_unlock_and_check_sysrq_irqrestore(struct uart_port *port, unsigned long flags) { - spin_unlock_irqrestore(&port->lock, flags); + uart_port_unlock_irqrestore(port, flags); } #endif /* CONFIG_MAGIC_SYSRQ_SERIAL */ From patchwork Sun Feb 18 18:57:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 202865 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp915058dyc; Sun, 18 Feb 2024 11:06:37 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXbMxGEPs9plTyyVfQ4AqxHYDHRC0uJKJ6AjAOFk0XdRYqRW0k/VQlLsqP5BcWMWG6+k+/3BNtrEusbmWeCGVIkXDCdAA== X-Google-Smtp-Source: AGHT+IFl7nDWurxPYon6xJ55BBQwXBUqpPW4qrVLaeVkNHja3ZZRIYSpHpLpgIK2t2ZZ6fQe+pD3 X-Received: by 2002:a05:6808:13cb:b0:3c1:5599:2461 with SMTP id d11-20020a05680813cb00b003c155992461mr2593332oiw.20.1708283197616; Sun, 18 Feb 2024 11:06:37 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708283197; cv=pass; d=google.com; s=arc-20160816; b=bisFXSqEwqiZp5m4TAlqvtywjwafU6mEPd0yApT1RIdttjqqf0/11YcKi7USdE078q XLkJ20MktX4wQiHcsM4RHRKzzkehwvdWBC890WeOFyDQy7akK9I9m4oRI5hGdBZNpCB0 YWgnvhlqmm/RGYQ1a6uMANcfj+vebBqE09vfna7o01JFvCWE06r1MKd+djoAKnS0bghU lyblLdbueT2rtQIjhUaP+ZdKLxr/OreXFmzFPTzTdoGlc/fZx5NrYQLB+rzKlIuJkzOl cIJ9TL8hh1GS498L8BmYdLAwimzxxxS5E/TL4IrxdN5LiePd7UfsMnRn/cqP49nlj/vO 9OQA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:dkim-signature:dkim-signature:from; bh=hl9qbklGnpInKmYvJoa6ZS5PHIy9GOhc0q9FzMa8X2Y=; fh=j6+PD5G2JP7q2Jw773ELurh1wgwslp/mFvwvZ0cuvt0=; b=khw6B7ySixLH6jvoxfoT4dig7rrheUYX+3w5aliWWn183L0lWLfHgl2IxuDOkSmJoo 5Njovm9AMY83cjF0AkXleF6jwhMlOnpoVzQvi394BO2QV/w4H3jx1knXssnHJ0XUidZy 9NXBhWli4uIorQ12HSGZ6tleML5HrjwZ5Ui8hlZnyWDR4AFM1AJ3NrdVFL8x0KWJ1aMn y4/zSxKTpErj34wVd1LMol2o4TDylWu3Y54OGyp14bhwCBGh7gBY1Qa9rxZANaCrUXK2 70zHuIstQhaGygw9nSGtsnlE1HyjLXaOvOdAY0ChL8ED7Gi4qGZkItt5P0JWOLiXv/ZW RacA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=hzsRMOH6; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-70534-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-70534-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id q2-20020a05622a030200b0042aadd56214si5050834qtw.92.2024.02.18.11.06.37 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 18 Feb 2024 11:06:37 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-70534-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=hzsRMOH6; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-70534-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-70534-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 6473A1C2103E for ; Sun, 18 Feb 2024 19:06:37 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C8174745E8; Sun, 18 Feb 2024 19:04:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="hzsRMOH6"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="aTmN1BPg" 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 A858E6F507; Sun, 18 Feb 2024 19:04:33 +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=1708283076; cv=none; b=ppMCEYoH98Tb/WHdKsxaa4ATXJb0XjB+OyuMqdyp01u+EigJTtTOqBhAwEjL6uzYiEjF1WlrZYNTBhxWpNZ5EGzzlnMWD2jNpVJ8nyJx0GOIyNW5nnsCMmbtbEKsE9/geATzpf6+2wSNxZSPih7acV6s16pX2MPPuYEuQ3pf2NA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708283076; c=relaxed/simple; bh=keGeNhzs3xp+qeYPU8cNtdBOt0vcNU3zMqIHr/8gsdk=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=EFNV6inn4TM1o/YYlwAMDMLLhVF2EkQrfd+AWDTiwa7gtIAmMmdnWSaLw7Q4xCTWwO9UsFyLpi4bxBvzQf/PoOSzVxx3sk5wKBsMcSU0QS7htnQuZrI494X/DQh822IoFnt/yNw5zfACaqaYEMypVsiza16W3HiGGCtKZPf7r0U= 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=hzsRMOH6; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=aTmN1BPg; 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 From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1708282669; 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=hl9qbklGnpInKmYvJoa6ZS5PHIy9GOhc0q9FzMa8X2Y=; b=hzsRMOH6xeWxc2o2bRi5V62jaRTvfs7zJ+P0LqBDGw2zp7XE/6L+IQGhAIrtviSmkoco4x 9eIgWPX+MYzeEF+BWttPOsMQfQp637cS3Ljr33qbYM0REFlEz+3GqCfKqDIX0XLYBkbH/K l9JX/WpwrANdf0ctJgkvSnfllg0p3BLmu4mhA7pmccbd/V+FqKDyzsgiq1/Ln/fU3EJuwI EO/SzKzaikWR4aiaskFaHBKwzNUgqzm3topJgtTZTG60Axn1vfYluAEdZA5b5ZMkUQnjcI 8tWHpYiq2ITkc4fiGkjXfwa2ndDHUnwfFQKhqfNEU5OYIfM8xQ9K9p3GtVKisQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1708282669; 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=hl9qbklGnpInKmYvJoa6ZS5PHIy9GOhc0q9FzMa8X2Y=; b=aTmN1BPgkJfjz5ghzY+8zNVy8iT7ckSrrKhBMJR8BN+z8EP3Hh0PLeU0D6cc7pLTCRm959 PY5rzrq5hPOljlDw== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org, Randy Dunlap , Greg Kroah-Hartman , Jiri Slaby , =?utf-8?q?Ilpo_J=C3=A4rvinen?= , linux-serial@vger.kernel.org Subject: [PATCH printk v2 03/26] serial: core: fix kernel-doc for uart_port_unlock_irqrestore() Date: Sun, 18 Feb 2024 20:03:03 +0106 Message-Id: <20240218185726.1994771-4-john.ogness@linutronix.de> In-Reply-To: <20240218185726.1994771-1-john.ogness@linutronix.de> References: <20240218185726.1994771-1-john.ogness@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791264762146182449 X-GMAIL-MSGID: 1791264762146182449 From: Randy Dunlap mainline commit: 29bff582b74ed0bdb7e6986482ad9e6799ea4d2f Fix the function name to avoid a kernel-doc warning: include/linux/serial_core.h:666: warning: expecting prototype for uart_port_lock_irqrestore(). Prototype was for uart_port_unlock_irqrestore() instead Fixes: b0af4bcb4946 ("serial: core: Provide port lock wrappers") Signed-off-by: Randy Dunlap Cc: Thomas Gleixner Cc: John Ogness Cc: linux-serial@vger.kernel.org Cc: Greg Kroah-Hartman Cc: Jiri Slaby Reviewed-by: John Ogness Link: https://lore.kernel.org/r/20230927044128.4748-1-rdunlap@infradead.org Signed-off-by: Greg Kroah-Hartman --- include/linux/serial_core.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/linux/serial_core.h b/include/linux/serial_core.h index 3091c62ec37b..89f7b6c63598 100644 --- a/include/linux/serial_core.h +++ b/include/linux/serial_core.h @@ -658,7 +658,7 @@ static inline void uart_port_unlock_irq(struct uart_port *up) } /** - * uart_port_lock_irqrestore - Unlock the UART port, restore interrupts + * uart_port_unlock_irqrestore - Unlock the UART port, restore interrupts * @up: Pointer to UART port structure * @flags: The saved interrupt flags for restore */ From patchwork Sun Feb 18 18:57:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 202863 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp914976dyc; Sun, 18 Feb 2024 11:06:24 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXpMjI1pRDJpnanWW++eH7kwTgaagmnvpQoB8x9efC6wH8XlVIxrDsQVSPzmIxTqEGZN/P1l6GzFf9TOqTsCOeXlu2Dnw== X-Google-Smtp-Source: AGHT+IHA2owfrhL3T1Zl/hle787LTpzitfbf7xJL1XAbDePaZIUGQOZdJsQdbieeaACXbA5xb3dM X-Received: by 2002:a17:90b:164e:b0:299:6b93:9d94 with SMTP id il14-20020a17090b164e00b002996b939d94mr1147125pjb.25.1708283184005; Sun, 18 Feb 2024 11:06:24 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708283183; cv=pass; d=google.com; s=arc-20160816; b=RgsJiKlGFdBaZGq3YaSrVgcokooJ19JCX16rnvvAqmaA63SqqrVnWJyKMERacuqXVf YUwENd92itxY8003lsmcstQZTz/DJxKAOnjD3PlmUSxl1h6wVE3rO0Jwcs9OVlUAOGpH aTeBys6zvCaQcRgyGR9J0G6AE3lOisAHTZcxXxAY97ghKYqVyeR8Iuk+Qzjmmkwx3pdi 72sDBRLGzDB/Zmyukxrej/IxZ3UGFlBwWyR3DZxo5vbg3DVcwL0zhL59TuVnm5MJRhVY ww+LebSSvygk8qaY9BHFNYaYe94JlUPfg102zocITn69sERFjshFqb7AVE0/RmvhyLHI eAwA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:dkim-signature:dkim-signature:from; bh=xxlb5lhcjt/hac5FRx4FUo+WOPkTmWiB9/oYCJlGF7c=; fh=pKnPKUsir0uEGSsor+4Zc2vgbu+g+ayvUgsdzkuXaoA=; b=GVjd2v12c+5NKW5W3TMXrUOMBTi2/+n/33ljjdVUn9bhGeaZdg7KuWQnGuVJ0/q2Mm iUrdAeb13cmaXvfcUN5yZbPDJkH/djvxOI1OXJdopFIa7uzAxTaxU1XuU/WxUa3U7D0W Fw+r3OeBAJNMQ7AHRYGFti2EN0huvabQeWUkXK4OYSRCKslL24V7rpI574JdAFrvmLiM siaK/3BaJOxQMtPh8P3A/cNIolGDkdDHk7TP5FlTuRdSs0dNQVZXQck82ZTt5vMGgyAQ JfPSkRNWxpMXo6e00dAGfnd7OITZTZj94VjaUk25jb/PZzXIY1GiiLRY5ALJCIGKcWeD VZEA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=V1z5I0ZK; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-70530-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-70530-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id cm18-20020a17090afa1200b0029898dc0b1bsi3306961pjb.116.2024.02.18.11.06.23 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 18 Feb 2024 11:06:23 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-70530-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=V1z5I0ZK; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-70530-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-70530-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id CC68C280DC5 for ; Sun, 18 Feb 2024 19:06:23 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 09464745C6; Sun, 18 Feb 2024 19:04:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="V1z5I0ZK"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="JU0rh4zw" 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 A866E71B36 for ; Sun, 18 Feb 2024 19:04:33 +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=1708283075; cv=none; b=ez9el1Zg1YONAVWSACvMwBGg0BR6uWH9bffocgEsOKNZsLPNAseXWHIhwguGSvYVazN0y0PhbZLlO1R0mPtzrr1myMtMncEuAqEBT0L/H4+Z+ti8UwkZ2VjI6ENbL0Bgw4CXZZs/8MhPNeRIrVis7iJIHGWR9vkwUd88vNDK+Mk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708283075; c=relaxed/simple; bh=UgNQzP2/u6tlCo+4rRFkvhUnGTuONwvzfEkavv5ocsw=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=E2zdrv6mPAhcnDrTi8Ivm3sDgEER3FU0Tmep2FTPWpe6dC1wflNHyb+3Ufvl3L+FtL7H2LC+VNEzQ7gbKzISN9wtn45ifF+VVh295jovXXfpLPD4qJ0+Avm1kwpnIrNp2tx5pKAXILW5ybMvn7Q/vPEbZVIETavwZEQW8WlMJHs= 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=V1z5I0ZK; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=JU0rh4zw; 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 From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1708282669; 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=xxlb5lhcjt/hac5FRx4FUo+WOPkTmWiB9/oYCJlGF7c=; b=V1z5I0ZKF4iHILJ11grW3yUcMsf6dzsgE9WmHuFW6u/mxsPMHOJ0NSsnRbXIC6b8V1T0Z9 wqPspAxBrbJs7PJxTaKHgLbrdQPevNQ5dnXs6vXoyD+hrTN3n1gh+X8inITIaEMq3XNX8l dKXlX7bVC2Ea2M7PeM2Satzn9re/EfxAmImJYno6Owt6YqVpL7yIsWeXlWfziccFOTF7EL 89bInQanbWKAzq0TvEvvLMh0Swdds4mpPwEcCIbCABldoG8S0gVmv9Lm/41vzLqA3jr5bT agzhWDfYaOcXGngoaxe8lTI2CS81GGXp1TVsB+vrx2AI7tD3/tARoptktJJG7Q== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1708282669; 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=xxlb5lhcjt/hac5FRx4FUo+WOPkTmWiB9/oYCJlGF7c=; b=JU0rh4zwDuGsnP1WFQPCdy7oRZb7xMVV+ZfKxvMADbaw7dYlMWIc2fH5D4SMeMceDUvmUD nvvtMP+k9d9OBDDw== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org Subject: [PATCH printk v2 04/26] printk: Consider nbcon boot consoles on seq init Date: Sun, 18 Feb 2024 20:03:04 +0106 Message-Id: <20240218185726.1994771-5-john.ogness@linutronix.de> In-Reply-To: <20240218185726.1994771-1-john.ogness@linutronix.de> References: <20240218185726.1994771-1-john.ogness@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791264747956254033 X-GMAIL-MSGID: 1791264747956254033 If a non-boot console is registering and boot consoles exist, the consoles are flushed before being unregistered. This allows the non-boot console to continue where the boot console left off. If for whatever reason flushing fails, the lowest seq found from any of the enabled boot consoles is used. Until now con->seq was checked. However, if it is an nbcon boot console, the function nbcon_seq_read() must be used to read seq because con->seq is always 0. Check if it is an nbcon boot console and if so call nbcon_seq_read() to read seq. Signed-off-by: John Ogness --- kernel/printk/printk.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index 1685a71f3f71..696a9d76c09c 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -3391,11 +3391,20 @@ static void console_init_seq(struct console *newcon, bool bootcon_registered) newcon->seq = prb_next_seq(prb); for_each_console(con) { - if ((con->flags & CON_BOOT) && - (con->flags & CON_ENABLED) && - con->seq < newcon->seq) { - newcon->seq = con->seq; + u64 seq; + + if (!((con->flags & CON_BOOT) && + (con->flags & CON_ENABLED))) { + continue; } + + if (con->flags & CON_NBCON) + seq = nbcon_seq_read(con); + else + seq = con->seq; + + if (seq < newcon->seq) + newcon->seq = seq; } } From patchwork Sun Feb 18 18:57:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 202835 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp911307dyc; Sun, 18 Feb 2024 10:58:41 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUu+u0zvqWsLXW5hBwrveN5XKaaD27zrjqVheZwSnQIHX6RAdEgHg63YCSAkrVebFCV3+Wb4VF0SqPKRcxQkW3Tv2NJCw== X-Google-Smtp-Source: AGHT+IELr0eiKyAq9juymSCt9Fb8Bn9Agl+3nutbzO9Ir4nwflpxByjQ2lGXFRu1LiqhuSvCRO8+ X-Received: by 2002:a05:6871:3285:b0:21e:dfa2:d8b6 with SMTP id mp5-20020a056871328500b0021edfa2d8b6mr395752oac.8.1708282721023; Sun, 18 Feb 2024 10:58:41 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708282720; cv=pass; d=google.com; s=arc-20160816; b=ZaRPl+BQMiUY3fn/C+rSPT/2qmkXvAJWEzQEIkv5AZqFUDEV4IjXgLm5kF8UJWDvnj 0IsF088IDtHr7utDriReJQnOZZvvBT0fSWK0NZggTLRlKkGnO3f3OKcbDPhTr3v5uP8V Y/Nw5r0i3bYGgAcm/0EwqFYeSfPW7aRylgA3Z8HPE0SGbopzKdvwmZNml7RKlgYuVBmQ yna9R1/vy+K6/ysfipGfwbsgXnzW1dwgqrgA3V10WHN7ewdRpQK1oI+2upKzQEN+Wcgd Kw6AH43lrt43OLtCREaWSVqecrsvXmRD002GuJ2mg72Zr65u2JS8CQZG6T+jXnS1DMRB CV4Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:dkim-signature:dkim-signature:from; bh=4Un0rwRwZZ3a2XT9jb+evA7D9ZWLwutkDIt2olFNBSM=; fh=PnRqlo+gSrEyXQylTbIbu2gslrfZ8YMEl0YokxZ3dP8=; b=FrMKVOVlB6JfWO4BE/7tgMR4FusWRf1J/vn7wAxAlV5G++2D0lb74B04tnT40fl54Y 9OKdfswi4R9g4wJOowZO8FKo8Ht2nwm9PcZsM36LbHFPk9IazFwyePycsp1PgDWo2ZKU sgySbpn23NpGRvJTK7H3tIXIGvlfamiD+94dE08jY79s8ZlVHcGi4G2o1O0az6YpLqox P51tu0XQvbrjamgtMIWQyOdyPFAlZF3KMSh4kiTsu1UjQeV5KiytdSYG0ZgnGqRA05Sp Sya8x4indMbBD6L0r3HjEUipetUxvtvWVXkIaHyEOSSOWPYH9QtIAc3n6Uc2EgP8wofJ DTVQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=qrnb2FPQ; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-70500-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-70500-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id c27-20020a63725b000000b005dc42fd2ea5si3155742pgn.889.2024.02.18.10.58.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 18 Feb 2024 10:58:40 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-70500-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=qrnb2FPQ; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-70500-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-70500-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id CD37E2819F6 for ; Sun, 18 Feb 2024 18:58:40 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B5FB271B54; Sun, 18 Feb 2024 18:57:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="qrnb2FPQ"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="TZBO/V1B" 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 376B725772 for ; Sun, 18 Feb 2024 18:57:52 +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=1708282673; cv=none; b=o7HLDI/U5H2AhiZmJpMmM6RDRqPoQIjW169gqqxSuXF2nhbU4X5Leh8SB+bYMCKHfjJGIPzRgo7VCb8VGPx3jGEpdTGHOhcZoj9va+cpbhLXRzoOcTMwGOwCnwShL8iq2IuIxol9erraH5sLYGivT9/5WjZElnz42sc+L91duKI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708282673; c=relaxed/simple; bh=szxbYO6I4lhZ0tittilU4W8LlO/EcPP5ZLOScG+pyp4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=f81GMo2NjMSd90QLGQq86KEuLjh2hfMjI5uVaYyQr+YjEG3OxrKmTlVl3X8LnYBtFgj66OYakSNfRYA2Sq/aaQWBjk6nTIWgGN8V0Yx3/iPZCv2OuAvhM9gMWbW0eWNFkD8dWXhmIZd2yBQm+DSnE18WEsTt1gpaDLC7zdwETxI= 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=qrnb2FPQ; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=TZBO/V1B; 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 From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1708282669; 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=4Un0rwRwZZ3a2XT9jb+evA7D9ZWLwutkDIt2olFNBSM=; b=qrnb2FPQWgUIoPQJwgH3E7DufsQ8IsmtrQQqmcYm22LHa2RlOcWRaeSgLnTFRkhmI+mqtI LRtd+VTf3IGtSg31pnViD3VR4oQLjkg/aygbOYwww0ug90EJiO7B0J2tW815u+ZjEbJ2L7 aXR2jDLA0+TBCYwEQzB2/sxQTpYFEI8RPyW5XDMBYMHWL1pAxkd9SBV82uAdo7iMHesD38 WRuCisj15Tlbb3l3AEKayPiqVcSXandv/cN4vbqodVlGzOWCbAH+ssr8l8CDm7k3kZuMNt CVTx2lQTuI+sOT63pugYF4DZCMWzYNhlyYfNKl9HVk47k8XSDkbqVUxCyXX39w== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1708282669; 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=4Un0rwRwZZ3a2XT9jb+evA7D9ZWLwutkDIt2olFNBSM=; b=TZBO/V1Bg1bIdmb66zgE0251XZPPIH3YGi9O+tOmQDQ3pr7l4tHkAdFsCwv7sEQgcEqLRv 77OR8OHaSoy8eBCg== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org, "Paul E. McKenney" , Miguel Ojeda , kernel test robot Subject: [PATCH printk v2 05/26] printk: Add notation to console_srcu locking Date: Sun, 18 Feb 2024 20:03:05 +0106 Message-Id: <20240218185726.1994771-6-john.ogness@linutronix.de> In-Reply-To: <20240218185726.1994771-1-john.ogness@linutronix.de> References: <20240218185726.1994771-1-john.ogness@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791264262634230424 X-GMAIL-MSGID: 1791264262634230424 kernel/printk/printk.c:284:5: sparse: sparse: context imbalance in 'console_srcu_read_lock' - wrong count at exit include/linux/srcu.h:301:9: sparse: sparse: context imbalance in 'console_srcu_read_unlock' - unexpected unlock Reported-by: kernel test robot Fixes: 6c4afa79147e ("printk: Prepare for SRCU console list protection") Signed-off-by: John Ogness Reviewed-by: Petr Mladek --- kernel/printk/printk.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index 696a9d76c09c..b75ca383683d 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -282,6 +282,7 @@ EXPORT_SYMBOL(console_list_unlock); * Return: A cookie to pass to console_srcu_read_unlock(). */ int console_srcu_read_lock(void) + __acquires(&console_srcu) { return srcu_read_lock_nmisafe(&console_srcu); } @@ -295,6 +296,7 @@ EXPORT_SYMBOL(console_srcu_read_lock); * Counterpart to console_srcu_read_lock() */ void console_srcu_read_unlock(int cookie) + __releases(&console_srcu) { srcu_read_unlock_nmisafe(&console_srcu, cookie); } From patchwork Sun Feb 18 18:57:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 202836 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp911314dyc; Sun, 18 Feb 2024 10:58:42 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUOhCH7hQ+9eR/H+1VWD1tUcIIRdbNNQfkKuJ+8M9iwdlG0OmXZR3eAwB/aKfGl8ULSjYBwCuGn9+/J8KzfKVWWrXjEJA== X-Google-Smtp-Source: AGHT+IFnjA5J4uwOroMcaXPT1Wf5pSQhVNkjLSP8Z1pXyEhWNAaAk5gFT/zmV4ihHMfFk2MG4GjE X-Received: by 2002:a05:6a00:2da0:b0:6dd:da40:948d with SMTP id fb32-20020a056a002da000b006ddda40948dmr10837933pfb.25.1708282722060; Sun, 18 Feb 2024 10:58:42 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708282722; cv=pass; d=google.com; s=arc-20160816; b=EP3Gl9hENYH6XQfuN/MqfeAKQVkIFnRy3Jtk3toW9Bydd8/mYe6qI8tCr3Mwne6th9 dlp2mGdbnOUm3z/jfXl98kVfTjydfp3duzREPDrAf+ccPsLRo3lB4U7CuWpDvI5a5Jq6 ZNvO2lA3lLQnNAb0KC2vVmU/jOGDYN5QmLwFXPvPK5Uwe8yB6HhWEFO/DH+qqb1uAfx1 tAXQAxolmp6Q/Ji7hSEiRXSfDKe6w7UCAlO7UWzCFJrI58JRJNBd5bJwlIHlJQitG7sb pjsIWMdFj+df5EDtteYJJfZJvTXg+jyM5kbCAtFhI1++Dhz1o1aSPbtYigVDn1edObEH ZJtA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:dkim-signature:dkim-signature:from; bh=Kjns8XLkW3UOjxVLP1Xg+LLtdkqweLRjHg511yq2AQM=; fh=pKnPKUsir0uEGSsor+4Zc2vgbu+g+ayvUgsdzkuXaoA=; b=sbH61/zIuqyadHniBHJwOvnosLfYgTcCv5bNNcDldi/ooUHB0Vfqbow+4Spogrypt7 Zjt+qIefc33dZnpVPez3F5x3YwrsKRd7NKB4ie+G2Ox/zmfRWHmlgGHqzZugtOvjXKdx DUX1Fu3k52FeNLfgdHjbzDtS+7oGQ2BRUFHZ5Es8w5ukQi3TOEyIWiduGpSgdvTvQcws kC4w7yThcvkcZ+zERJsIjRvwmoV+FHmQRlaeFxyzfV+qmVZFY0ty18z4Pv7JCq9YcKOt Ji27YqqofDipQxMB5KfFZ45+zkXdaOrkGn9VfEVWMh2tEmpJNdCQrE4g+f3k0FJmN2Bx sKSQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=snqAalWA; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-70499-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-70499-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id by8-20020a056a00400800b006e302dd06aasi2599925pfb.66.2024.02.18.10.58.41 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 18 Feb 2024 10:58:42 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-70499-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=snqAalWA; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-70499-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-70499-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id DD70E281819 for ; Sun, 18 Feb 2024 18:58:41 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id BBDB971B55; Sun, 18 Feb 2024 18:57:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="snqAalWA"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="ZmyFWTbF" 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 376F76F094 for ; Sun, 18 Feb 2024 18:57:52 +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=1708282673; cv=none; b=Uv8s91tBnvaOp/R2oG0A0MJpYp7Jehn0wwBJfSmSDngELDRkCJ0KIgwiF2pZH77QEin566yf7pMj3zsLBFnzIK1YW+3VN4gO0pG/HeuPmDqVj0VwDL4cQxarPHjZXiumWSFnffxeDeXqfkEvBR+CULeSbwvSHLKjw5M4oU/wlH0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708282673; c=relaxed/simple; bh=xRjhM41YiCV0XIFxys+lC68vQSHxZf7wjECrZPYdxII=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Mj0bkQ6pLnjysOZ3uzyjxPZAFa03D9aicEziRr9PWz4W7jTD6dFAWCa/49QmzwDRMHLr5+9JcCcsgNIh4IvrkZ19rN0ANhC/wD9v18xmyEvFQ4inHmvCwgJrm1k34E2y3KKIPC4BTSWVYpMJifewp3iyR6qtk/1zvs3PdHVtC6A= 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=snqAalWA; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=ZmyFWTbF; 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 From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1708282670; 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=Kjns8XLkW3UOjxVLP1Xg+LLtdkqweLRjHg511yq2AQM=; b=snqAalWATXYn0aUg65LZvGca4wwwf8i8uVStRHQLraQha7BTOjAHnpHAmXikabBL39RLiE MRmXDgvvG2+RBg0rtq5N4Y099iHJtZtZRA2IM7CyqsvJkv1hL2xszoPrUIuRQu2i7iPNm5 4Ct4gXVxeZ//4jnJt56fzxkAOIuycjU+ZRQseZzN1btEl27/9yjG37VTWInD4oLeSwQB14 42u4kchPISfE4m5ic24bedmSDw3pVg7g13BwY2g5C762aTwkRl/Awgk1+pErAzruPbDe6c eU+3HuZVI71hY0OhWp23G8N/FtzzDJANTPF4+myOwLmf1PAuNXlNo146FHyCKg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1708282670; 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=Kjns8XLkW3UOjxVLP1Xg+LLtdkqweLRjHg511yq2AQM=; b=ZmyFWTbFlEMBKl9FVuqkxwy1anMpcoUdWmv8BI2orJRjCsQxNuo7BoQOG21L6KMv1rWiVC 1NYdc0VXdvcu3ICg== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org Subject: [PATCH printk v2 06/26] printk: nbcon: Ensure ownership release on failed emit Date: Sun, 18 Feb 2024 20:03:06 +0106 Message-Id: <20240218185726.1994771-7-john.ogness@linutronix.de> In-Reply-To: <20240218185726.1994771-1-john.ogness@linutronix.de> References: <20240218185726.1994771-1-john.ogness@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791264263728502817 X-GMAIL-MSGID: 1791264263728502817 Until now it was assumed that ownership has been lost when the write_atomic() callback fails. And nbcon_emit_next_record() directly returned false. However, if nbcon_emit_next_record() returns false, the context must no longer have ownership. The semantics for the callbacks could be specified such that if they return false, they must have released ownership. But in practice those semantics seem odd since the ownership was acquired outside of the callback. Ensure ownership has been released before reporting failure by explicitly attempting a release. If the current context is not the owner, the release has no effect. Signed-off-by: John Ogness --- kernel/printk/nbcon.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/kernel/printk/nbcon.c b/kernel/printk/nbcon.c index c8093bcc01fe..8ecd76aa22e6 100644 --- a/kernel/printk/nbcon.c +++ b/kernel/printk/nbcon.c @@ -852,7 +852,7 @@ static bool nbcon_emit_next_record(struct nbcon_write_context *wctxt) unsigned long con_dropped; struct nbcon_state cur; unsigned long dropped; - bool done; + bool done = false; /* * The printk buffers are filled within an unsafe section. This @@ -891,17 +891,18 @@ static bool nbcon_emit_next_record(struct nbcon_write_context *wctxt) nbcon_state_read(con, &cur); wctxt->unsafe_takeover = cur.unsafe_takeover; - if (con->write_atomic) { + if (con->write_atomic) done = con->write_atomic(con, wctxt); - } else { - nbcon_context_release(ctxt); - WARN_ON_ONCE(1); - done = false; - } - /* If not done, the emit was aborted. */ - if (!done) + if (!done) { + /* + * The emit was aborted, probably due to a loss of ownership. + * Ensure ownership was lost or released before reporting the + * loss. + */ + nbcon_context_release(ctxt); return false; + } /* * Since any dropped message was successfully output, reset the From patchwork Sun Feb 18 18:57:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 202837 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp911345dyc; Sun, 18 Feb 2024 10:58:47 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWdWRJJxy4feVjvJRgmV/kjQTDswG+1aK6c6GKeyL4XeUrxczYSwPuqZHZHTufuEqDfXDSgaARfRqwRnLvcsyhsjmuCxQ== X-Google-Smtp-Source: AGHT+IF9vEzoojz6+XN2h3iAdNccanvEqzq+exSK5yBxwsMm2c63Q6k6ued8NWbRZTsVys657q20 X-Received: by 2002:a05:6808:3c9a:b0:3c1:53cb:7293 with SMTP id gs26-20020a0568083c9a00b003c153cb7293mr4617446oib.34.1708282727652; Sun, 18 Feb 2024 10:58:47 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708282727; cv=pass; d=google.com; s=arc-20160816; b=vd2FyxJ/QcaagC/WpBoTbj1WmIlyIwc6n3rIEYpvhBG1WOTFAemz2SsDfZn93F6KEE X+PcwoDto12c9HhApWBVPLXal2qucLTqkevxN41nkopOMwfeY1xZkK8Kq8OjMw1datdJ 9wWoH45U8gmW0c0hc+Y7yQPbYp5AkCE1n/UQ+ZOsImZn8B6lHMeXpAaNEQZ9rFiQuYmc ezlI1BnIK5GGuvl72pVluYFKfeB6Y4r1ZmxComrA1exSj26PxRbXn1vD9ZE868/AxLd/ /GQ5IblS2ILg+saZbqCMN4eWeUFPP+GwxcxdPogSGAehSseeSkVtL9aP7l6hlfVUeLRj FN+A== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:dkim-signature:dkim-signature:from; bh=rhiYAxJ52E/enQP4Ayf/MIif8Xm2i96p2VSKi7x6/pk=; fh=PbMLUItzKPZoRBvHUI9C5cxQAQuKFUSvllEZTNwnglo=; b=FAiIjIpWMlKJ0qlPSbsFXKAd9CKJ1h+aqXNPrwuQjn96Y+0dfTLHon79hXSVUcsTtx +w6xAaqRJyZ1twxWeGdJn4OqTT8/5zgwR8mqmHuT6yWIv8CxUyPQ5cJ+Kn0SvygSjnIJ y2PNBdIbm5uHvp8fgkPk1zdDEEqJGHPNAAMfG8iV1QOujkG6qBO10KlMLBpw16VjJPE5 jlsiWNZr4UzD7cpD3UlLwJNddISf0oZpOPNnFayjrM0w3wAzYLMARl8yX3vHtZCYx8hf tLaIlpgxftCZ5mmC82oM1cusRu58XLg2VYgoWt7a1H8pvBk2+qj4tYkoNw0YfWtJ/HTI 4bog==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b="Z/8tYXT2"; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-70501-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-70501-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id m9-20020ac86889000000b0042c2147b5d1si4422414qtq.474.2024.02.18.10.58.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 18 Feb 2024 10:58:47 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-70501-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b="Z/8tYXT2"; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-70501-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-70501-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 70E921C20971 for ; Sun, 18 Feb 2024 18:58:47 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 26F3371B49; Sun, 18 Feb 2024 18:57:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="Z/8tYXT2"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="i9pMn/EB" 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 867256F09A for ; Sun, 18 Feb 2024 18:57:52 +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=1708282674; cv=none; b=i17QdP1VY/RTZXJDka9/mDBWz5zavUzQZZ+rs1x6oSy/3UnayIQLh8RkVriMG6LfYg2SeWVeDAts1/qiT+eyS+mRSHqCBTesZ0OOYx2EQ1gLj+pkQImwHhSr5aDnJX3XkJ9KrbDPqYO82m926+lkZMDsNYAp/fJbfJPF9iF5gSs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708282674; c=relaxed/simple; bh=QUm3HonFr4bI9kdM8sLrYXTcDYUW2kypDJWENyu683c=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=WjCMBKPat0XMtGHi0sO76J4FnPHFGwYZ3L7KbJRzLJYMKyeN1PI+eE86YXrSaMlVEVcr0Ovcjj7uxugMK8AvnsjaJCGtXCdJ4K/pscVYgPp9gAzz4KawjsgGTXxJ5ZsAKRPL08YiMbxFaQFW0X5VCqZHCfsIuybl0ofOv4Uex8c= 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=Z/8tYXT2; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=i9pMn/EB; 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 From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1708282670; 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=rhiYAxJ52E/enQP4Ayf/MIif8Xm2i96p2VSKi7x6/pk=; b=Z/8tYXT2WSDAy/oWuJCJWbFDqgYvMv1StysN1afFGWiaizrs1Sey8dbHymursqMg64AOxu 8y3QmJDsjKSQsXAg9Xq7OL35hf0l20OSbsFDRS1bpet71gqBMKUzO23Nft/f2TZkFaCQQJ 1VTKQ4aEuBfNEMI3CmjUMOzSEDx7WFjsaU8jEf4gxH+EKyJcEPpDplzpU3P9MHt2cm5/jO gg4482yTJPtLbcRrLt+gJOCyqWS3gjRtuBMfK1Jr6J3j2lS2//JhLt19l/q3Onn9y6fIzD 6uinp4xNsIoaOBEk34ufZOFS/TEUy33xfgohPM1mPd+IXv8IWmDIPngc13shyg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1708282670; 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=rhiYAxJ52E/enQP4Ayf/MIif8Xm2i96p2VSKi7x6/pk=; b=i9pMn/EB1LeNHwwoyZzphndAhEQPz7vVuj1gMJibIlEhslNTv+R6kLlQ5h+5I24cS/nFdG v5uWCEVLIW/zfIBw== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org, Sebastian Andrzej Siewior Subject: [PATCH printk v2 07/26] printk: Check printk_deferred_enter()/_exit() usage Date: Sun, 18 Feb 2024 20:03:07 +0106 Message-Id: <20240218185726.1994771-8-john.ogness@linutronix.de> In-Reply-To: <20240218185726.1994771-1-john.ogness@linutronix.de> References: <20240218185726.1994771-1-john.ogness@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791264269209352856 X-GMAIL-MSGID: 1791264269209352856 From: Sebastian Andrzej Siewior Add validation that printk_deferred_enter()/_exit() are called in non-migration contexts. Signed-off-by: Sebastian Andrzej Siewior Signed-off-by: John Ogness Reviewed-by: Petr Mladek --- include/linux/printk.h | 7 +++++-- kernel/printk/printk_safe.c | 12 ++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/include/linux/printk.h b/include/linux/printk.h index 955e31860095..8d5c5588eec9 100644 --- a/include/linux/printk.h +++ b/include/linux/printk.h @@ -159,13 +159,16 @@ __printf(1, 2) __cold int _printk_deferred(const char *fmt, ...); extern void __printk_safe_enter(void); extern void __printk_safe_exit(void); +extern void __printk_deferred_enter(void); +extern void __printk_deferred_exit(void); + /* * The printk_deferred_enter/exit macros are available only as a hack for * some code paths that need to defer all printk console printing. Interrupts * must be disabled for the deferred duration. */ -#define printk_deferred_enter __printk_safe_enter -#define printk_deferred_exit __printk_safe_exit +#define printk_deferred_enter() __printk_deferred_enter() +#define printk_deferred_exit() __printk_deferred_exit() /* * Please don't use printk_ratelimit(), because it shares ratelimiting state diff --git a/kernel/printk/printk_safe.c b/kernel/printk/printk_safe.c index 6d10927a07d8..8d9408d653de 100644 --- a/kernel/printk/printk_safe.c +++ b/kernel/printk/printk_safe.c @@ -26,6 +26,18 @@ void __printk_safe_exit(void) this_cpu_dec(printk_context); } +void __printk_deferred_enter(void) +{ + cant_migrate(); + this_cpu_inc(printk_context); +} + +void __printk_deferred_exit(void) +{ + cant_migrate(); + this_cpu_dec(printk_context); +} + asmlinkage int vprintk(const char *fmt, va_list args) { #ifdef CONFIG_KGDB_KDB From patchwork Sun Feb 18 18:57:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 202839 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp911532dyc; Sun, 18 Feb 2024 10:59:31 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWw5QXgQBLTmzwxRLCyBtGs1ZPJhlpZbAhgG16jSVcQXVQp9aq2oFxsVElmefn7lEYh2WN7vFXA2ag7nqB50rJmufAj5g== X-Google-Smtp-Source: AGHT+IEQrJ6fnZPfdCXPAQ/lXXYT/ycAUt7rpNdYSUGvvJExIkTlXU3cCL4hEOv35/13ZAFg8ne1 X-Received: by 2002:a0c:e44f:0:b0:68f:3a58:af94 with SMTP id d15-20020a0ce44f000000b0068f3a58af94mr6074235qvm.9.1708282771321; Sun, 18 Feb 2024 10:59:31 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708282771; cv=pass; d=google.com; s=arc-20160816; b=ijLWKacqqMt3/RAOTyBCrn8eNYAq7WYzeahJe6quoHLYODHr7tco+r+cAcZjbyz3/i FofzWW1G93Y2usA2X/iAQja4ffuxa88D3OylX4QHMtJ5Rbw4lkEsYurhAYFt09g9wwul cGm+nLgEGfFVOYYKfkEiBCaIZtzSqxKUq0Q/COu/Vk8Lyjv6+p5yAactUDeEmTVVOwMK +eL31899uTkjkE4muClvX37Ewz73a3U84JBlL2da1akweCaHhwOizrNWm6gKcBSOC8EV 42LcImwHrHp0n4SKTvQ4ynYCrplAeM4th1tu9R+qFfFDV9WcbB11Uie7tOtIDwOsCsaQ sjWA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:dkim-signature:dkim-signature:from; bh=xrTMG/IO2xEuBdqD5OxQ1/ULXhRtRhpYhyRMl+KnF7w=; fh=X5XpYSLMojJVLknYdZ6Tl2/0pJFf0A70sJpMIndXqH0=; b=P9DqFyi7IzvI+2ghAFSsKVhtSE4WiyPzv70S2W5h/wwB3ny5IpRcgITiKueV55nef0 QcLXXNSEoTnOWPcuLGqa0XMljcQ3VAmbgd3LSjEKLZHgU3mAHFTUuu47fi36O418X9or /QkUXg336GRgiEKpZgCc7Un+LGjSxnzK/BZ9dIko8jPBp3/qFleYzTw4RNdGT1e+noY2 IZIrS5eSX9qHkFuJ6pccWZwoR5NfCD5BQz3BsIzw8JbzpUcyNk5/RSLD2k0D5MX7kuCe kNHwIag2n2PwtOTToFmhZAz+YbJ3KWBQrE9i1jhAoJJIqQC5o9j0dpPBL6LWhk3bLsLs Fb2g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=OxRI2d34; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-70503-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-70503-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id kj25-20020a056214529900b0068caf39560dsi4497550qvb.429.2024.02.18.10.59.31 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 18 Feb 2024 10:59:31 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-70503-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=OxRI2d34; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-70503-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-70503-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 131EE1C20CA5 for ; Sun, 18 Feb 2024 18:59:31 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id EEFAC745D0; Sun, 18 Feb 2024 18:57:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="OxRI2d34"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="Rsnkb8W7" 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 BEFAD6F09B; Sun, 18 Feb 2024 18:57:52 +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=1708282674; cv=none; b=AhgcbfS4eg6HlKfcNVIRC6xeRye+lEQZXd646F84cvdUimRUvJvStzmRq0oUyMvDp6MlbubOxn7fdaNlgguVjUjMQYBp7uk+gI2lSHAXc9tLzSa44G+hA5VZAX2upyIqDVWJBiHO+T7d/7zEQpI6ORJPY/zTNmmSqtEnGUGCvBA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708282674; c=relaxed/simple; bh=Uh1a7N6liYSzDazmzjchFNl1uPkqsuEMN7I6bWMM5lg=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=F8VK+cZaI17xAQQkQ98GiMYBrhgiKM39ALgkY1ZNze7Dlyr2qCWltIHKtAYy8v1sad4izTkuDFauF7DQPvwUD2bV35QWVSQVKFuheOVyozVa0R4Ay1EulMEGreVrdJerJZDb1rZn6v1Ho3bDzvBEeovBI7AxVc8jiz9Ja2EuFEw= 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=OxRI2d34; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=Rsnkb8W7; 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 From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1708282671; 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=xrTMG/IO2xEuBdqD5OxQ1/ULXhRtRhpYhyRMl+KnF7w=; b=OxRI2d34d6eZ84FJ7ek1LsuerkJcVIohMxOCIEONANmxjad1y70ujK/AQkOy/143chnRYk axXq9ozPgZaRTxPS2OU7FU/O2GmA4dQqaDAYVnThA0KVqDRntfohKh/LtQmkD6y6C6/PpO w5Mo7Fvy6+2N6uBZjtL8dfWxrur03oO6Riby83YgQu9pWCnLN3iuAnBMI0QZ8lP6gIHFqN wI3gEXimzNOiRYIOXA7IuqqFHlIQPWrFitlcfb249CDX8ATU6Ne+IliEJ+ba6VDCwX+OcB 8aTaUpAxr18hbUGOGraqr3e+Caqa7suhJtJvrivhatX1a6gL7hZM8e7x1aOLqg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1708282671; 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=xrTMG/IO2xEuBdqD5OxQ1/ULXhRtRhpYhyRMl+KnF7w=; b=Rsnkb8W7+dOJGMPJ0e2uA0Qw+jE3lvQlvn7hjAPcJzTKGdemWwBwLWErNiRpjvS9iouHHa VyIr8Gp7jlbNNSAg== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org, Greg Kroah-Hartman , Jiri Slaby , =?utf-8?q?Ilpo_J=C3=A4rvinen?= , Andy Shevchenko , Tony Lindgren , Geert Uytterhoeven , Justin Chen , Jiaqing Zhao , linux-serial@vger.kernel.org Subject: [PATCH printk v2 08/26] printk: nbcon: Implement processing in port->lock wrapper Date: Sun, 18 Feb 2024 20:03:08 +0106 Message-Id: <20240218185726.1994771-9-john.ogness@linutronix.de> In-Reply-To: <20240218185726.1994771-1-john.ogness@linutronix.de> References: <20240218185726.1994771-1-john.ogness@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791264315047632402 X-GMAIL-MSGID: 1791264315047632402 Currently the port->lock wrappers uart_port_lock(), uart_port_unlock() (and their variants) only lock/unlock the spin_lock. If the port is an nbcon console, the wrappers must also acquire/release the console and mark the region as unsafe. This allows general port->lock synchronization to be synchronized with the nbcon console ownership. Add a flag to struct uart_port to track nbcon console ownership. Signed-off-by: John Ogness --- drivers/tty/serial/8250/8250_port.c | 1 + include/linux/printk.h | 13 +++++ include/linux/serial_core.h | 19 ++++++- kernel/printk/nbcon.c | 77 +++++++++++++++++++++++++++++ 4 files changed, 108 insertions(+), 2 deletions(-) diff --git a/drivers/tty/serial/8250/8250_port.c b/drivers/tty/serial/8250/8250_port.c index 141627370aab..16e2705b4867 100644 --- a/drivers/tty/serial/8250/8250_port.c +++ b/drivers/tty/serial/8250/8250_port.c @@ -3284,6 +3284,7 @@ void serial8250_init_port(struct uart_8250_port *up) struct uart_port *port = &up->port; spin_lock_init(&port->lock); + port->nbcon_locked_port = false; port->ctrl_id = 0; port->pm = NULL; port->ops = &serial8250_pops; diff --git a/include/linux/printk.h b/include/linux/printk.h index 8d5c5588eec9..ef57a4d93ae2 100644 --- a/include/linux/printk.h +++ b/include/linux/printk.h @@ -9,6 +9,8 @@ #include #include +struct uart_port; + extern const char linux_banner[]; extern const char linux_proc_banner[]; @@ -195,6 +197,8 @@ void show_regs_print_info(const char *log_lvl); extern asmlinkage void dump_stack_lvl(const char *log_lvl) __cold; extern asmlinkage void dump_stack(void) __cold; void printk_trigger_flush(void); +extern void uart_nbcon_acquire(struct uart_port *up); +extern void uart_nbcon_release(struct uart_port *up); #else static inline __printf(1, 0) int vprintk(const char *s, va_list args) @@ -274,6 +278,15 @@ static inline void dump_stack(void) static inline void printk_trigger_flush(void) { } + +static inline void uart_nbcon_acquire(struct uart_port *up) +{ +} + +static inline void uart_nbcon_release(struct uart_port *up) +{ +} + #endif bool this_cpu_in_panic(void); diff --git a/include/linux/serial_core.h b/include/linux/serial_core.h index 89f7b6c63598..d4b93d721715 100644 --- a/include/linux/serial_core.h +++ b/include/linux/serial_core.h @@ -488,6 +488,7 @@ struct uart_port { struct uart_icount icount; /* statistics */ struct console *cons; /* struct console, if any */ + bool nbcon_locked_port; /* True, if the port is locked by nbcon */ /* flags must be updated while holding port mutex */ upf_t flags; @@ -595,6 +596,7 @@ struct uart_port { static inline void uart_port_lock(struct uart_port *up) { spin_lock(&up->lock); + uart_nbcon_acquire(up); } /** @@ -604,6 +606,7 @@ static inline void uart_port_lock(struct uart_port *up) static inline void uart_port_lock_irq(struct uart_port *up) { spin_lock_irq(&up->lock); + uart_nbcon_acquire(up); } /** @@ -614,6 +617,7 @@ static inline void uart_port_lock_irq(struct uart_port *up) static inline void uart_port_lock_irqsave(struct uart_port *up, unsigned long *flags) { spin_lock_irqsave(&up->lock, *flags); + uart_nbcon_acquire(up); } /** @@ -624,7 +628,11 @@ static inline void uart_port_lock_irqsave(struct uart_port *up, unsigned long *f */ static inline bool uart_port_trylock(struct uart_port *up) { - return spin_trylock(&up->lock); + if (!spin_trylock(&up->lock)) + return false; + + uart_nbcon_acquire(up); + return true; } /** @@ -636,7 +644,11 @@ static inline bool uart_port_trylock(struct uart_port *up) */ static inline bool uart_port_trylock_irqsave(struct uart_port *up, unsigned long *flags) { - return spin_trylock_irqsave(&up->lock, *flags); + if (!spin_trylock_irqsave(&up->lock, *flags)) + return false; + + uart_nbcon_acquire(up); + return true; } /** @@ -645,6 +657,7 @@ static inline bool uart_port_trylock_irqsave(struct uart_port *up, unsigned long */ static inline void uart_port_unlock(struct uart_port *up) { + uart_nbcon_release(up); spin_unlock(&up->lock); } @@ -654,6 +667,7 @@ static inline void uart_port_unlock(struct uart_port *up) */ static inline void uart_port_unlock_irq(struct uart_port *up) { + uart_nbcon_release(up); spin_unlock_irq(&up->lock); } @@ -664,6 +678,7 @@ static inline void uart_port_unlock_irq(struct uart_port *up) */ static inline void uart_port_unlock_irqrestore(struct uart_port *up, unsigned long flags) { + uart_nbcon_release(up); spin_unlock_irqrestore(&up->lock, flags); } diff --git a/kernel/printk/nbcon.c b/kernel/printk/nbcon.c index 8ecd76aa22e6..02e8fdc1ea43 100644 --- a/kernel/printk/nbcon.c +++ b/kernel/printk/nbcon.c @@ -6,6 +6,7 @@ #include #include #include +#include #include "internal.h" /* * Printk console printing implementation for consoles which does not depend @@ -995,3 +996,79 @@ void nbcon_free(struct console *con) con->pbufs = NULL; } + +static inline bool uart_is_nbcon(struct uart_port *up) +{ + int cookie; + bool ret; + + if (!uart_console(up)) + return false; + + cookie = console_srcu_read_lock(); + ret = (console_srcu_read_flags(up->cons) & CON_NBCON); + console_srcu_read_unlock(cookie); + return ret; +} + +/** + * uart_nbcon_acquire - The second half of the port locking wrapper + * @up: The uart port whose @lock was locked + * + * The uart_port_lock() wrappers will first lock the spin_lock @up->lock. + * Then this function is called to implement nbcon-specific processing. + * + * If @up is an nbcon console, this console will be acquired and marked as + * unsafe. Otherwise this function does nothing. + */ +void uart_nbcon_acquire(struct uart_port *up) +{ + struct console *con = up->cons; + struct nbcon_context ctxt; + + if (!uart_is_nbcon(up)) + return; + + WARN_ON_ONCE(up->nbcon_locked_port); + + do { + do { + memset(&ctxt, 0, sizeof(ctxt)); + ctxt.console = con; + ctxt.prio = NBCON_PRIO_NORMAL; + } while (!nbcon_context_try_acquire(&ctxt)); + + } while (!nbcon_context_enter_unsafe(&ctxt)); + + up->nbcon_locked_port = true; +} +EXPORT_SYMBOL_GPL(uart_nbcon_acquire); + +/** + * uart_nbcon_release - The first half of the port unlocking wrapper + * @up: The uart port whose @lock is about to be unlocked + * + * The uart_port_unlock() wrappers will first call this function to implement + * nbcon-specific processing. Then afterwards the uart_port_unlock() wrappers + * will unlock the spin_lock @up->lock. + * + * If @up is an nbcon console, the console will be marked as safe and + * released. Otherwise this function does nothing. + */ +void uart_nbcon_release(struct uart_port *up) +{ + struct console *con = up->cons; + struct nbcon_context ctxt = { + .console = con, + .prio = NBCON_PRIO_NORMAL, + }; + + if (!up->nbcon_locked_port) + return; + + if (nbcon_context_exit_unsafe(&ctxt)) + nbcon_context_release(&ctxt); + + up->nbcon_locked_port = false; +} +EXPORT_SYMBOL_GPL(uart_nbcon_release); From patchwork Sun Feb 18 18:57:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 202838 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp911411dyc; Sun, 18 Feb 2024 10:59:03 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXgMnhP6b+seZKcjhnPtDslRE15AXg32Vhr3TI3fak/MiqB+0PL1OBu4yj/PenGNdXfy7+qKFq3987uGmPKuGmXgTcs9w== X-Google-Smtp-Source: AGHT+IFnxZzMDC5p/gle1B47lcj0jCCIV1M5C2xjOw3YToDiA+aNCa8RYjuQzEDCdr5OxnqdfCgB X-Received: by 2002:a05:6a00:9287:b0:6e2:f54a:5ee4 with SMTP id jw7-20020a056a00928700b006e2f54a5ee4mr4612898pfb.13.1708282743720; Sun, 18 Feb 2024 10:59:03 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708282743; cv=pass; d=google.com; s=arc-20160816; b=IGbhF4wF9un4+wwRZXtRSXlRRuRlYBL0LXO0Q80BW3qZcEbWg8qmWT1aTv0btfulkk RzBtKjoAb4AAsG+MetRlEI/wQwcYpdRpMLbIdH7R34ng/W+HTYZwsym2tQ9kUtzF+urw ECx/MnlA3w0BeCJTyi8aC0YpHtL5CYpgwRX4iuv63Jw6uRuWhl+spZ6mtMqJRbEE1hSK B7KDvZVuJ5rG4/uVSKKHj2ptpqiZKVaXuIBgOKhnMk0fMh/PoOV+TGLHi/HhxHH2usTI gkJnbIMdRZgtwQ2P7wGoSKSyO70t8K5PW4IvW64tP4mgQCenRK49QDwkllKd0i1DIHbu bDCg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:dkim-signature:dkim-signature:from; bh=3I1dHuUwYQfwJlbzcngwYe/b4Lctrl7m0BYdiHEdADM=; fh=/NZX815RJy/ecOe1WbZ023sSZUJKZnpaeIZwQG5Ym7U=; b=oGGFANVl9+EDjn09XgsAAkJBhcgucj1FPDCIHj/798TyOlxSEt2qNXrYHrbwBBn7mG Cq54ZHj0mQmc5kVqxUiW+VKGotgAG2pVTLpAbL+J5Yt4fhe3HQNiANN5vEw0XaTxfV/8 zUEZbyxFLRoGkPfRdMhcMe/lWt/TvVkgLcjKuvk12Zipc9T1mJr602BE54W3Cm6xq4cf 0RntJ7NDNUyeDCs6bpjqQGaFjXIIITWVl9PR8TnUT8K2JA+RdeuVLZMVww1I0/9DCsh3 I13LKI1DFn4bgDOT8vQ0VwwjOjh46l/8vdmP9Mh2f92n2RhW3i/SC4uMk2mAdF3uP+yi wwuQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=bUvH6ld6; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-70502-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-70502-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id fh26-20020a056a00391a00b006e0945e03fasi3265087pfb.162.2024.02.18.10.59.03 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 18 Feb 2024 10:59:03 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-70502-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=bUvH6ld6; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-70502-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-70502-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 44363B2116D for ; Sun, 18 Feb 2024 18:58:59 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A3C567317B; Sun, 18 Feb 2024 18:57:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="bUvH6ld6"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="mv3bI0iZ" 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 DA5766F09C for ; Sun, 18 Feb 2024 18:57:52 +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=1708282674; cv=none; b=MrjfjejcyY12hoSJfICLYJEu1AXyJNGesjG6UCW+xUJTpm4HhSJGEThYqIyUoSlARYtlLqtH4hPldujSqoouE1T9/0M1kkrlxl/+3CzMZQnlDXqKnckVU59I3TFdA3qMiQ31rOSTd+aIQf7PXqW+atlv6YMo70MXs83plAhaxu8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708282674; c=relaxed/simple; bh=vTgd2itv2WvqWfA2iHd5zEucMOb4GN4MKZQhbctg1CE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=m+GfE/DmQ815XkHAIHAxqPE524y93tsrHQJ8lD8lnjKSwa7+5b6UtBpNCxafjwJf7sjMnOiaT7SE+ZpaWohlM/oK0BR9BSF9dMiOGndbtvLuk2ERdTFnbfks17SOp3hCYAcnk562lnwKIF/c3p6llGoXjy7dDiZ4VFk6KO405sE= 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=bUvH6ld6; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=mv3bI0iZ; 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 From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1708282671; 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=3I1dHuUwYQfwJlbzcngwYe/b4Lctrl7m0BYdiHEdADM=; b=bUvH6ld6ZR2Lx7Xmdigmcn4lgfr2aDNvw4v/80RT0CXEAcaNRMKHc5jHO6u4d7wjSu/kLh xfbiIRlZLFennUA4anuz4ogw5nxq3uoQNdSr4AS9EpdIyuAyE6bm6xHKI8lP6pZSj0asaV jce8Tfn5LLyr7LDy4vYkcEfHQjv+rYzyi82pYP5oOd880wpNfwKafO0sh/KGE7/4hDp/CQ hAUPlz1qdkP9mi6CtrcL5wxhCsaz97b9WRlh33kGjePhNUgcYigxSKYU/xMeunxgaSt3Xo s3kOkTkSe7ie8C3PBR2rawdtpVOBYFIa9jCMKt4A3p5z5prM65E5vTdN5ubQkQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1708282671; 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=3I1dHuUwYQfwJlbzcngwYe/b4Lctrl7m0BYdiHEdADM=; b=mv3bI0iZRBTmcWWJ3oT7jB7zGmwIkGzso/mTLeCK3sGCyUsHPvlz6U4660FUqUbnlE82tO 7rxsKqaEcP+w6OCw== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org, Greg Kroah-Hartman Subject: [PATCH printk v2 09/26] printk: nbcon: Add detailed doc for write_atomic() Date: Sun, 18 Feb 2024 20:03:09 +0106 Message-Id: <20240218185726.1994771-10-john.ogness@linutronix.de> In-Reply-To: <20240218185726.1994771-1-john.ogness@linutronix.de> References: <20240218185726.1994771-1-john.ogness@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791264286321497503 X-GMAIL-MSGID: 1791264286321497503 The write_atomic() callback has special requirements and is allowed to use special helper functions. Provide detailed documentation of the callback so that a developer has a chance of implementing it correctly. Signed-off-by: John Ogness Reviewed-by: Petr Mladek --- include/linux/console.h | 34 ++++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/include/linux/console.h b/include/linux/console.h index e4fc6f7c1496..5c55faa013e8 100644 --- a/include/linux/console.h +++ b/include/linux/console.h @@ -278,7 +278,7 @@ struct nbcon_write_context { /** * struct console - The console descriptor structure * @name: The name of the console driver - * @write: Write callback to output messages (Optional) + * @write: Legacy write callback to output messages (Optional) * @read: Read callback for console input (Optional) * @device: The underlying TTY device driver (Optional) * @unblank: Callback to unblank the console (Optional) @@ -295,7 +295,6 @@ struct nbcon_write_context { * @data: Driver private data * @node: hlist node for the console list * - * @write_atomic: Write callback for atomic context * @nbcon_state: State for nbcon consoles * @nbcon_seq: Sequence number of the next record for nbcon to print * @pbufs: Pointer to nbcon private buffer @@ -320,8 +319,35 @@ struct console { struct hlist_node node; /* nbcon console specific members */ - bool (*write_atomic)(struct console *con, - struct nbcon_write_context *wctxt); + + /** + * @write_atomic: + * + * NBCON callback to write out text in any context. (Optional) + * + * This callback is called with the console already acquired. The + * callback can use nbcon_can_proceed() at any time to verify that + * it is still the owner of the console. In the case that it has + * lost ownership, it is no longer allowed to go forward. In this + * case it must back out immediately and carefully. The buffer + * content is also no longer trusted since it no longer belongs to + * the context. + * + * If the callback needs to perform actions where ownership is not + * allowed to be taken over, nbcon_enter_unsafe() and + * nbcon_exit_unsafe() can be used to mark such sections. These + * functions are also points of possible ownership transfer. If + * either function returns false, ownership has been lost. + * + * This callback can be called from any context (including NMI). + * Therefore it must avoid usage of any locking and instead rely + * on the console ownership for synchronization. + * + * Returns true if all text was successfully written out and + * ownership was never lost, otherwise false. + */ + bool (*write_atomic)(struct console *con, struct nbcon_write_context *wctxt); + atomic_t __private nbcon_state; atomic_long_t __private nbcon_seq; struct printk_buffers *pbufs; From patchwork Sun Feb 18 18:57:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 202840 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp911854dyc; Sun, 18 Feb 2024 11:00:19 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXWmzo8BIzaLIs+oSeswasJHMNXyvYVZN99s+wOz+n3P9/QU0OJk7i0US5o8PqULbSuzo6ERjJmamZS908Vmo/FI2ufOQ== X-Google-Smtp-Source: AGHT+IGvEseITMho1fJp4XXojWaQ/lMioF0/1USSnbPEifQxlkqUJtrFSSSqIrVI17gQbIJkOt6Z X-Received: by 2002:a17:906:abd8:b0:a3e:1205:a02d with SMTP id kq24-20020a170906abd800b00a3e1205a02dmr4223743ejb.17.1708282819093; Sun, 18 Feb 2024 11:00:19 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708282819; cv=pass; d=google.com; s=arc-20160816; b=C4bMYDvxQqQnK1SSbseIRwFsF9qySzc9w0acoEoA2HmqAYs1B5r1fKQxzK7PhWSWsx W2MDPwD18kwdfCJcLxUykhIuX5eszgwy1VhrkeuYwHEQsxdAa4609yd6B5ZuIswofSPf Y3O8BZrnBS94Ayje3Pypeo/rZHC2M7mwqQ1/uEcMRhBZ5G6QZ58Yka1mCYNORr+GjWpC Xod2Oq6cl+aZF+14uTBnyrEYF6/AXw/IYQA0ljDiN/k2WU9m1bz2yE7gIzTRhED+cFOY EFodHr2MpFpTjiGHGEx3JaGUdv6pKCHYFgf7rcxmdMyJldnPmRY9pNrF7OMZS8qYKnid TdKA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:dkim-signature:dkim-signature:from; bh=Do8ewsprPzBc28AvFoSgrf1uIwAex3sQdWFNrubJEIE=; fh=/NZX815RJy/ecOe1WbZ023sSZUJKZnpaeIZwQG5Ym7U=; b=GyYLafgiRKTYHOZUlGmQgT8TlmvaTOloeew1BRVDqFaBdPdmBcI4ayLlOa8gQzlaU2 irvb9NIkWWZpkZ4Okrd8/vA953Fn4AjuyloYb+ybHBTXKdgRDr2Ul8n7lalwzD9EqCmX qXxI3IqgFzJz8DGt6GdEvVIRRitCr7a+sFL6zku2y6gPnvShOZO20N3KRfV32Ihn3aV/ Z17qww54TswYAXEEwtJlizdvz0qWYvbGnuBe2Onl8zzUo77W0AMTNBEVgYNE0f+9z+LB M9HUMs7Y7+ONUtrWM9ZiRowSyzHtVO3j5LJCdiich9YM0mEW1ZvlK7/4apH9SFMBVLpC N22w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b="n0WIo/21"; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-70505-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-70505-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id jo25-20020a170906f6d900b00a3e874ba560si372823ejb.30.2024.02.18.11.00.18 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 18 Feb 2024 11:00:19 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-70505-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b="n0WIo/21"; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-70505-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-70505-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id B16811F230F4 for ; Sun, 18 Feb 2024 19:00:18 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 837BF76021; Sun, 18 Feb 2024 18:58:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="n0WIo/21"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="rxjV0DyE" 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 7A6726F09D for ; Sun, 18 Feb 2024 18:57:53 +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=1708282674; cv=none; b=qnyZrIxiFk1Ee5SAEc7/U1gR30f41FRWHrB/Kxi6H6ogBk6GeBW/o++N1ofFENYuKZuXJigqzd5a8gFrbZqpBvE8Hz+aBcAfi0DJkopO0QUsyYg6fOfDOFXN/yLLfGaMrbrVqgrn8WOYNp0Tqa78K5k/+beZmkxr5qGjk/ST9nU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708282674; c=relaxed/simple; bh=dox9/szQb+26iWG6sdrMGBj/6N8EK08NBiaQoryJAZY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=osFYRAlJotSEBhvSR6sqKyFBv9FFvxL+CwHA1hAuV9zXpcGOjvyYn8oZ/479QXias97SZW+48reOMEo9PVaD573Emr7jFtwzEQZIpTmevAdsOTU5PBCFJkLLwEWbqHLDXiSM2m4WjaM7t163Nqe6w5+x92hMjHCEDe2mOgq1udw= 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=n0WIo/21; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=rxjV0DyE; 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 From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1708282671; 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=Do8ewsprPzBc28AvFoSgrf1uIwAex3sQdWFNrubJEIE=; b=n0WIo/21+og62Xcdgg4mHDaJ9aa+CTHp0s7sApg1zCrn4OCuWxR6QQMEbiCHvbb+dFMm1L V9FnWhjtHIeb1jcwhgPgzjnfISI4Du2Fid4OhSb5q5yRNHbxovscbdrlDAnyqtr5Ot/Dvz NoOrEmSD94iNw1Ij7asEVkJqyzuQoUkXKFubKBHBbASydUM5avhQSJ/lEmOZB48MPTkOww 2fXOOOFQZuvDbsRED3yBvNqNo/77k7k+urNy+DhwMGutAIrdyj5z5wGiJ6uO7NrSrGnbmr hneukamflRKxXUyGNhrOISFNO4NJCHCVL46pWq55uSLBGxplRjEP6lnVlLUs1g== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1708282671; 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=Do8ewsprPzBc28AvFoSgrf1uIwAex3sQdWFNrubJEIE=; b=rxjV0DyEVlmUerI569cgyyqOJTLFr3BJW/IldEcccb31Wr3M+HzMoQYeQ7O44tY+agL9J3 gl8yKmTbAJdauQDA== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org, Greg Kroah-Hartman Subject: [PATCH printk v2 10/26] printk: nbcon: Fix kerneldoc for enums Date: Sun, 18 Feb 2024 20:03:10 +0106 Message-Id: <20240218185726.1994771-11-john.ogness@linutronix.de> In-Reply-To: <20240218185726.1994771-1-john.ogness@linutronix.de> References: <20240218185726.1994771-1-john.ogness@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791264365433635151 X-GMAIL-MSGID: 1791264365433635151 Kerneldoc requires enums to be specified as such. Otherwise it is interpreted as function documentation. Signed-off-by: John Ogness Reviewed-by: Randy Dunlap Reviewed-by: Petr Mladek --- include/linux/console.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/linux/console.h b/include/linux/console.h index 5c55faa013e8..d8922282efa1 100644 --- a/include/linux/console.h +++ b/include/linux/console.h @@ -130,7 +130,7 @@ static inline int con_debug_leave(void) */ /** - * cons_flags - General console flags + * enum cons_flags - General console flags * @CON_PRINTBUFFER: Used by newly registered consoles to avoid duplicate * output of messages that were already shown by boot * consoles or read by userspace via syslog() syscall. @@ -211,7 +211,7 @@ struct nbcon_state { static_assert(sizeof(struct nbcon_state) <= sizeof(int)); /** - * nbcon_prio - console owner priority for nbcon consoles + * enum nbcon_prio - console owner priority for nbcon consoles * @NBCON_PRIO_NONE: Unused * @NBCON_PRIO_NORMAL: Normal (non-emergency) usage * @NBCON_PRIO_EMERGENCY: Emergency output (WARN/OOPS...) From patchwork Sun Feb 18 18:57:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 202843 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp912035dyc; Sun, 18 Feb 2024 11:00:39 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWkY5eiQuX2xhVnHWk0TF1o7vTaDpXUQCT+HGGx9Q18LQBKkpO0F689y6pwLqesgmIrZ1uodBsLFx+085fyVN0muaG4Sg== X-Google-Smtp-Source: AGHT+IECctD7aJMlHjzzWqkRaQCsz72zRCVADQc52TlW95UZ9uQMyVEwF8g9IirdbhVBWKWPUHds X-Received: by 2002:a17:902:f78e:b0:1db:92e1:2e50 with SMTP id q14-20020a170902f78e00b001db92e12e50mr12331907pln.43.1708282839053; Sun, 18 Feb 2024 11:00:39 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708282839; cv=pass; d=google.com; s=arc-20160816; b=yx1CPZgZt16xGmbhWYdoDFwdMwULQgPnlS+SKeqikkKzb+GRt2+JK6ccruJMKzT01b J7A8lyg7LQ9ynwXgrnT/3rqFJ9/D8IB769ANP7+2JhqYXOfaJ8Yc1HKk9vFJi64L3SPo 9VgHT3N9Nk3nS7diVRcxJdo+1G2PmCk0XI492IWuAfOp1FpF+Fa7hyoj3Z0riSQ7h3L3 0iJsWebtJr2mY99z8M0pFzGs8EmgU6NeMVb0Wx/Q8CefB3PsJLPob3CdzS7ShW52I1gJ hXCR10UEn4UEe2w4ScjE3GXzgRQa7t+zG0NJRYA7JQeLOXjXOkXLbNGGhx8TFEnW14Rk /E1g== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:dkim-signature:dkim-signature:from; bh=n24MWmzqzOOOOZwEfqW/0eRQt3f3jgwSF64cWTce6J0=; fh=pKnPKUsir0uEGSsor+4Zc2vgbu+g+ayvUgsdzkuXaoA=; b=syLYlQN4lq5LirjzHcwG/+PznjIIpDmGos8qlEyG/NizvPEB7+RuvtF3RPMajhVSLf Y/nlIu+XirwI+h74b22Z77fso+uN57qhx8atPTb5UL+9LjI/J2C7qvBYi1XBtcvIC2K/ HMApUrhM3cWcHM7fyFVntYLcC6GFDyziSiL0hz38CIBUsrs4Yv1x7BjQdsafUZGMX0zM nhPg+9T1Gy9SoxMJBdBjob+DfbQUSMXVyGNOOUbNEsfNjKqBPyh607Tbg1qFYThhbtLW BibbqscVRaENHF6N2g5qEAEtXHL3bSNYwQT39mB+e8AJWq2Ngt0lPAHDWibbOaVQcwCd vcaQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=QMSBU7jD; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=Y+6u7iXO; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-70507-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-70507-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id iz14-20020a170902ef8e00b001d9fcd34721si3215933plb.119.2024.02.18.11.00.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 18 Feb 2024 11:00:39 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-70507-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=QMSBU7jD; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=Y+6u7iXO; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-70507-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-70507-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 74567B20F59 for ; Sun, 18 Feb 2024 19:00:31 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DB99276037; Sun, 18 Feb 2024 18:58:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="QMSBU7jD"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="Y+6u7iXO" 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 B37606F09F for ; Sun, 18 Feb 2024 18:57:53 +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=1708282675; cv=none; b=dcVoXcTLsiI0pCnIrd1jBsohAEkEfIfI4+L5IZ9PdOpQ+v+XHY2FQbmWdm2PJVPHzzOdfFNBpaFDo85UFWEWQEUJ271725C638SbUrLART7jGaP1syYn58bTBdMgBvbuz/tQjlzs2pitC14QJ4avMMCIJQ+uXo6QKWmk5j2ITmU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708282675; c=relaxed/simple; bh=Gn+uo9q8su4/qFeCC4JeId6lrhn6gSNTkrfRmi156Nw=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=ZTySrhhER/jtyP0qo2schzyNrPGMWwf59Lftqb7SJ1vv61+KKTqNemRmGjzXAi8TFjs1lg0f7r9Wx2Fv8WF7ecpil3m4NIYg7QvDxCY5rKMlNqM8vmOGJ8kERzo7UTXVbMpl8j88TLGZ/72Pkqk05b2BB9GM7OBjdsQSVbbhuBg= 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=QMSBU7jD; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=Y+6u7iXO; 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 From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1708282672; 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=n24MWmzqzOOOOZwEfqW/0eRQt3f3jgwSF64cWTce6J0=; b=QMSBU7jD94Yh/o3DcWTZjh0a8JGG9Yx9WNZg5k4O77UQ4qID8e+4cRj1MXJ3SVvOAmVn2/ h2OKdZDfsKW916dakuJrYuN8Y3JU/PeeaGWdkRV/DNOoyrO1GZcHFOFGjRRPpxmAQtqwG+ Ewg+eeiAXtrsH5wjUJmkovot03PxpfwzMmJaE+Dq99ru3fkcTZgAtlnTbcXrnlgdR2iZ/T JwSdJL8smlJrWZc4SL7jk+c8UTfaTaswB08nQdr5MjdYXm7qxU1ooTR9SchSIR+StZT7xx Pw9TdcOnef41ejCiw9jH+vbIcdc7QkmT6p6JpXFPkBRSFwzjl8EF9vT9UrVZwQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1708282672; 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=n24MWmzqzOOOOZwEfqW/0eRQt3f3jgwSF64cWTce6J0=; b=Y+6u7iXOgtAwwO99mk362rIMqX3U2eCm3OiQleJuLdrhHEE5dahThYSucQl6FvoXuqDPcY 9Y+H+7HsP4PVEvBQ== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org Subject: [PATCH printk v2 11/26] printk: Make console_is_usable() available to nbcon Date: Sun, 18 Feb 2024 20:03:11 +0106 Message-Id: <20240218185726.1994771-12-john.ogness@linutronix.de> In-Reply-To: <20240218185726.1994771-1-john.ogness@linutronix.de> References: <20240218185726.1994771-1-john.ogness@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791264385908043494 X-GMAIL-MSGID: 1791264385908043494 Move console_is_usable() as-is into internal.h so that it can be used by nbcon printing functions as well. Signed-off-by: John Ogness Reviewed-by: Petr Mladek --- kernel/printk/internal.h | 32 ++++++++++++++++++++++++++++++++ kernel/printk/printk.c | 30 ------------------------------ 2 files changed, 32 insertions(+), 30 deletions(-) diff --git a/kernel/printk/internal.h b/kernel/printk/internal.h index 6c2afee5ef62..6e8c1b02adae 100644 --- a/kernel/printk/internal.h +++ b/kernel/printk/internal.h @@ -78,6 +78,36 @@ bool nbcon_alloc(struct console *con); void nbcon_init(struct console *con); void nbcon_free(struct console *con); +/* + * Check if the given console is currently capable and allowed to print + * records. + * + * Requires the console_srcu_read_lock. + */ +static inline bool console_is_usable(struct console *con) +{ + short flags = console_srcu_read_flags(con); + + if (!(flags & CON_ENABLED)) + return false; + + if ((flags & CON_SUSPENDED)) + return false; + + if (!con->write) + return false; + + /* + * Console drivers may assume that per-cpu resources have been + * allocated. So unless they're explicitly marked as being able to + * cope (CON_ANYTIME) don't call them until this CPU is officially up. + */ + if (!cpu_online(raw_smp_processor_id()) && !(flags & CON_ANYTIME)) + return false; + + return true; +} + #else #define PRINTK_PREFIX_MAX 0 @@ -99,6 +129,8 @@ static inline bool nbcon_alloc(struct console *con) { return false; } static inline void nbcon_init(struct console *con) { } static inline void nbcon_free(struct console *con) { } +static inline bool console_is_usable(struct console *con) { return false; } + #endif /* CONFIG_PRINTK */ extern struct printk_buffers printk_shared_pbufs; diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index b75ca383683d..ecb50590815c 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -2694,36 +2694,6 @@ int is_console_locked(void) } EXPORT_SYMBOL(is_console_locked); -/* - * Check if the given console is currently capable and allowed to print - * records. - * - * Requires the console_srcu_read_lock. - */ -static inline bool console_is_usable(struct console *con) -{ - short flags = console_srcu_read_flags(con); - - if (!(flags & CON_ENABLED)) - return false; - - if ((flags & CON_SUSPENDED)) - return false; - - if (!con->write) - return false; - - /* - * Console drivers may assume that per-cpu resources have been - * allocated. So unless they're explicitly marked as being able to - * cope (CON_ANYTIME) don't call them until this CPU is officially up. - */ - if (!cpu_online(raw_smp_processor_id()) && !(flags & CON_ANYTIME)) - return false; - - return true; -} - static void __console_unlock(void) { console_locked = 0; From patchwork Sun Feb 18 18:57:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 202841 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp911910dyc; Sun, 18 Feb 2024 11:00:24 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCX6onwOZ1hPD5S1lAKmzbV1gvyc0/Uy7Kyyro3H+T38DUNsv8vwKxX1VUw3RGL2htnUIAL+bPJ53D3W71JB0xuRtSpifQ== X-Google-Smtp-Source: AGHT+IHj8xBRf/le6eHiyl3AOkg6rqacQ3/RPhsSzw/HpFfl71WSj/l6Nw57WB9b/qRVUKJqbURk X-Received: by 2002:a05:6e02:330e:b0:365:2390:9313 with SMTP id bm14-20020a056e02330e00b0036523909313mr4539450ilb.12.1708282824275; Sun, 18 Feb 2024 11:00:24 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708282824; cv=pass; d=google.com; s=arc-20160816; b=OeQQ82pmNNJQU9lTbAGHMqBCiwsh7HKXglcOF8StH9GBcIPhsCObAz3RPxDfHLWg7V I+hdfl/TaKTEnzcfveJNRkSRY7Y8fqElVrBU9CPfNFTmPraxkTKoaj0mUtxz8mdR8brb jcOJ9ioEbhIA1ptf6dTLV6aDER9eJjeQ1e8IXTJL+QVx515Xw7ypilEfL7a8iVsidPWa jqkcDwHz/+2UlIhGi4WspHw56Z1ZOCbE3iri4wrDMq7nBIwZYTq6v5khIWJszrEgx7pG K29Hd5hDUk7Q68jnXVUmt8Uf7Tmgq+fwID9kKwpkdzj7tdk7qRqWIQxcrJp8IGWXngDC fkQw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:dkim-signature:dkim-signature:from; bh=IUwIeSGZ+StqqGIqBIJs0cGENFsoVWre3Jl13joVS94=; fh=pKnPKUsir0uEGSsor+4Zc2vgbu+g+ayvUgsdzkuXaoA=; b=fX4TLlPpxjgET1AMGo1Ae7GlYdA2aktvOG58mgn3qAUkDSmOKFuEJUbkuE42sivsU0 r4djE9KSD4HFSrKFSCnrLniZaD2w8VT/kGdmvr+O2CYAHiEfNPo1UZRxW+rUbs5D84Z7 QXI3LcJ0ovlbdkha3y86C6a4QLQue2K9J5PottRKH2fgxyn96ZGURN3xbyArvqCfMcZv SgzMg90Z4VOxz6BlllIvk+jQjg5oyvahBpMCGl3Qlnv2JIBIFGdBV4iRHozHoKwuV+Q/ Q/fHI5q9VCdwYz7KKMC/Kf3C2z48wnJ2nuLlaMD0FUH6rH6SqFq9uI6wHkSLxVjtVRa4 tFKg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=t7xu7hfV; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-70504-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-70504-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id x7-20020a656aa7000000b005e0b2413677si2531233pgu.552.2024.02.18.11.00.24 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 18 Feb 2024 11:00:24 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-70504-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=t7xu7hfV; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-70504-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-70504-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 15F4D281C9C for ; Sun, 18 Feb 2024 19:00:24 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id AF9047602A; Sun, 18 Feb 2024 18:58:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="t7xu7hfV"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="3WC1PWFT" 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 0C7A36F504 for ; Sun, 18 Feb 2024 18:57:53 +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=1708282675; cv=none; b=JkReHT7NbwNe9sFEkl7DtcbCCTNfb6qHFXp0bRrNkwqFICsiKv3MRosZqXdcNM/OdpKgUuV7z1SDNb3hHLcVZzSZfVtTbU9sEy+MSPw8Hc2OqjB2jFpJap5Rz9fgCOEDfaLKl5AUwEMRs12H/AEJNvpzVY7Ny6YJZbdsYSa9tnY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708282675; c=relaxed/simple; bh=VBHx4Cus2cJidu47KwQl5FHQQheHgkCUVrX8zpd9KsM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=pGHncS6O3FLed5WbdgXksC1Ic56ZcbNeWllbMiA67J1I3HGDN+LuFX+j1RuNScjIT4oDQ8MBgrmIU/3uoZ1WpZ6S/0STxcz2nutDb3shyX6lCTp+J6FR5ZZbupCJVKvRFfI+uLT7Z6O8MyE4eJiEY2lwbkhRimXBgnqHDBE584E= 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=t7xu7hfV; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=3WC1PWFT; 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 From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1708282672; 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=IUwIeSGZ+StqqGIqBIJs0cGENFsoVWre3Jl13joVS94=; b=t7xu7hfVQXpd79WP0b9+W4yS7IsMad5j3VNVWCe5WHFy2pwwlog2q66avUuTa7EurOMbPd UWvIjARCFpJvv5Jp42GoE7ne8PBdxxT6p2fsZH1ic8ur0e0ZMylY00a6CkpP8bXiwZLNb8 nihLJssxgJ6M8Vb+GyNTdG256q3I0QUsN+q3IT2ZSALYVDLd8S376vkjiitDNaogQ0Eu7O R1hQAsoBHDBDNkzF7CxwHn1Wwul0N52Iz616hQhcLL4m+AFia5+Q8ReUR95m9sQ+EEQG5j KOn9mXZuS9LqHBWEnxMeYNSdAXBAZYW55ZW+7xob6AfnzKAIQDt2WaQQF/DyXw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1708282672; 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=IUwIeSGZ+StqqGIqBIJs0cGENFsoVWre3Jl13joVS94=; b=3WC1PWFTwRsETdj+pq340CnfZVlD62OQIrZCKwUyr53+TZcJsH3jvnZzhsPN/IiZFOHmHU 7MQyIjPv75805ICw== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org Subject: [PATCH printk v2 12/26] printk: Let console_is_usable() handle nbcon Date: Sun, 18 Feb 2024 20:03:12 +0106 Message-Id: <20240218185726.1994771-13-john.ogness@linutronix.de> In-Reply-To: <20240218185726.1994771-1-john.ogness@linutronix.de> References: <20240218185726.1994771-1-john.ogness@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791264371190657931 X-GMAIL-MSGID: 1791264371190657931 The nbcon consoles use a different printing callback. For nbcon consoles, check for the write_atomic() callback instead of write(). Signed-off-by: John Ogness Reviewed-by: Petr Mladek --- kernel/printk/internal.h | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/kernel/printk/internal.h b/kernel/printk/internal.h index 6e8c1b02adae..69c8861be92c 100644 --- a/kernel/printk/internal.h +++ b/kernel/printk/internal.h @@ -80,6 +80,8 @@ void nbcon_free(struct console *con); /* * Check if the given console is currently capable and allowed to print + * records. Note that this function does not consider the current context, + * which can also play a role in deciding if @con can be used to print * records. * * Requires the console_srcu_read_lock. @@ -94,8 +96,13 @@ static inline bool console_is_usable(struct console *con) if ((flags & CON_SUSPENDED)) return false; - if (!con->write) - return false; + if (flags & CON_NBCON) { + if (!con->write_atomic) + return false; + } else { + if (!con->write) + return false; + } /* * Console drivers may assume that per-cpu resources have been From patchwork Sun Feb 18 18:57:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 202842 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp912017dyc; Sun, 18 Feb 2024 11:00:37 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCW3XbSoDBBH1rnCeEqyecCX9uuYfqXTkyEjVg6ZUBN8ZiK4SPtTsY9I31+nRumoQiQIjUYv4fiyfZp5cADTIzV/3atxSg== X-Google-Smtp-Source: AGHT+IEj6gLjH/glgsx/FUV9e6SBIR51KkJqniCjp2D+mlakJ7hiUfK7SYVBhRqsncZJ13y9HWZc X-Received: by 2002:a05:6808:1156:b0:3c0:3f3f:16e9 with SMTP id u22-20020a056808115600b003c03f3f16e9mr13935260oiu.12.1708282837551; Sun, 18 Feb 2024 11:00:37 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708282837; cv=pass; d=google.com; s=arc-20160816; b=WPHZwTCfWUY5RdhSEWPVe5h8bst3WBNcFX0+THhlp/08Rb5hyOVk60bLDjidbdHWUV Ua4WxQsI+F2JKTgBDdhvGtT9SQiifB4JEJJkvqwKiGkBKzaMO2AEc5gjBvNdcVrCMN3v NzqB+BPQQLlt4pyG8lhwU/kCot5hDxPqsa/ZvQpp/Bci9UoEC1XdUpXOEf9b5EHSM1+g 8QLpJqH6ORyGHgcHv8zug7OQg4UnTo+CazvzOCPYMBtlk0g3iVJA9wuKfPJB00vffBS+ w/E8ifCWbCvXgYs9cD6jNFp3+TK9+3J0drKxOCA1XgK38ucynnM35OiWGVZ/b4jHls/u XaCg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:dkim-signature:dkim-signature:from; bh=0GibUZTFTeq8Azv+JjrVAmh6V7HAl4otIfefb2UG9wk=; fh=pKnPKUsir0uEGSsor+4Zc2vgbu+g+ayvUgsdzkuXaoA=; b=LMgqngEb85GK7ah3vfgEUiiAgIuL4LRqMyzTJfVQg7GsFxymZMsCp2Xnl1oAi0Zr3m G5apJoq67lUZVXECOKQ/yyUPKvvI/GM3LUM+CVIFxsJrLLnWGj+PuLk0MfoL46qjOnWH 6jWki4+jVzZw3Iu1LR0O1RA8atVMnLWD+6qR8JzO0HaBfwJAmJkLnCbZODZrTlgoSzK7 Atd+UhRvYMKgybXomTqNbwx6ycK82uSEYWYf+yX8l86QxFzyfPn9Uqby5u+QRfWE/zA+ 60FkNzWWSCWlRHKlhdbMgezo/npIlGUQGf4OyP/eORSsPu+SGEdd52l75xd/Q9M8NtFw QL7g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=UiMlLlop; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-70506-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-70506-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id z187-20020a6333c4000000b005dc49a8c93fsi3189089pgz.764.2024.02.18.11.00.37 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 18 Feb 2024 11:00:37 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-70506-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=UiMlLlop; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-70506-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-70506-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 787D8B20F40 for ; Sun, 18 Feb 2024 19:00:30 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D3DF276034; Sun, 18 Feb 2024 18:58:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="UiMlLlop"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="gFUUiIHd" 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 470346F50C for ; Sun, 18 Feb 2024 18:57:54 +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=1708282675; cv=none; b=bTVB4U3gorWFZCM9rTR+7W7fWi/qCziwgEkGLSi5AYqKgs11rFivksI/tcxHDsuGn+xaxthhEnW7F75HSPdKv4zM5IoA6WRYLTTT4nXF+v1NwlEbIQQ0VKSBJ0wg99CWAqiTARwQC86kuhRZYoHGfHQdnJPdzNDUyyk9KCuxyBk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708282675; c=relaxed/simple; bh=KWSkXCKQeNrr5eZStT4LqIX1rH8fREQLBiX0c1gHrHM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=sy7ozQXYskoiRyAtZtwEyjfCsjAGRiVQKSZ2i3KrMthUfKmJJGr33q28amZr0BpW2oMb+EAu71HkcrglfQvI6DbV20pooeFJo0sBQPMrxLgShppA2dRKU1Ocl0OfE6AyzqcKLqouIXQN/BLP3kxLMyuDKvAsnFebJDNsnv54wfE= 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=UiMlLlop; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=gFUUiIHd; 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 From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1708282672; 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=0GibUZTFTeq8Azv+JjrVAmh6V7HAl4otIfefb2UG9wk=; b=UiMlLlop/JEpMBas0X+fajoIusei1Be/FpyJcoty5xeAu1KPqr30RJO4Hqf8X8OyGyDfXN nU4N3qCrcwCfyCoU3j+3RzzC96tUZFGkLzMmvIpCbG4POseS/+TEi98WGoMo/Zyz3K/YMe F/dZ2U45Azmi1NXFJX/PuiIfwJVVEGkhkbBKuu5yW2J4OfBtwmceEveWAu9QcNEa+xd6+1 5tjS6hUYg9cj0kG37YdxaCUukxh3+QoatNCcg9S1ejaC+ZS/pbp7beRR+3DY/OKSYzPF4F AfbBSmFwHRjJTseChgbZxHA9q41FgyWWNUd0Z6lBsrjGTPjwE/6NnKv2Z/j22Q== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1708282672; 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=0GibUZTFTeq8Azv+JjrVAmh6V7HAl4otIfefb2UG9wk=; b=gFUUiIHdAlO9f732mfLv2nx9vP+orySfBI5//27FsQFvL56KV9Ud3P30BMUojDQAZxZS0G GlaQl5HxOC/sgCDw== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org Subject: [PATCH printk v2 13/26] printk: Add @flags argument for console_is_usable() Date: Sun, 18 Feb 2024 20:03:13 +0106 Message-Id: <20240218185726.1994771-14-john.ogness@linutronix.de> In-Reply-To: <20240218185726.1994771-1-john.ogness@linutronix.de> References: <20240218185726.1994771-1-john.ogness@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791264385035857504 X-GMAIL-MSGID: 1791264385035857504 The caller of console_is_usable() usually needs @console->flags for its own checks. Rather than having console_is_usable() read its own copy, make the caller pass in the @flags. This also ensures that the caller saw the same @flags value. Signed-off-by: John Ogness Reviewed-by: Petr Mladek --- kernel/printk/internal.h | 8 ++------ kernel/printk/printk.c | 5 +++-- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/kernel/printk/internal.h b/kernel/printk/internal.h index 69c8861be92c..6780911fa8f2 100644 --- a/kernel/printk/internal.h +++ b/kernel/printk/internal.h @@ -83,13 +83,9 @@ void nbcon_free(struct console *con); * records. Note that this function does not consider the current context, * which can also play a role in deciding if @con can be used to print * records. - * - * Requires the console_srcu_read_lock. */ -static inline bool console_is_usable(struct console *con) +static inline bool console_is_usable(struct console *con, short flags) { - short flags = console_srcu_read_flags(con); - if (!(flags & CON_ENABLED)) return false; @@ -136,7 +132,7 @@ static inline bool nbcon_alloc(struct console *con) { return false; } static inline void nbcon_init(struct console *con) { } static inline void nbcon_free(struct console *con) { } -static inline bool console_is_usable(struct console *con) { return false; } +static inline bool console_is_usable(struct console *con, short flags) { return false; } #endif /* CONFIG_PRINTK */ diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index ecb50590815c..9d56ce5837f9 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -2939,9 +2939,10 @@ static bool console_flush_all(bool do_cond_resched, u64 *next_seq, bool *handove cookie = console_srcu_read_lock(); for_each_console_srcu(con) { + short flags = console_srcu_read_flags(con); bool progress; - if (!console_is_usable(con)) + if (!console_is_usable(con, flags)) continue; any_usable = true; @@ -3783,7 +3784,7 @@ static bool __pr_flush(struct console *con, int timeout_ms, bool reset_on_progre * that they make forward progress, so only increment * @diff for usable consoles. */ - if (!console_is_usable(c)) + if (!console_is_usable(c, flags)) continue; if (flags & CON_NBCON) { From patchwork Sun Feb 18 18:57:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 202845 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp912280dyc; Sun, 18 Feb 2024 11:01:04 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXrGcB8NW/Ak9/4Qlqxl+EXRkNkGTomYaD9zu0ii9JhS/XjvYVS+oybtkoispEXKyaBGzmQif5XaM+2Wk7xjarDwebZLw== X-Google-Smtp-Source: AGHT+IEkYCSnkQeXw0lVTu9CNr5SYvHmggVo0jQd9dFWIHX01n9Xw6uIf78fwaZBTYSg+F7iThrt X-Received: by 2002:ac8:5714:0:b0:42d:c289:7e53 with SMTP id 20-20020ac85714000000b0042dc2897e53mr13855821qtw.10.1708282864018; Sun, 18 Feb 2024 11:01:04 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708282864; cv=pass; d=google.com; s=arc-20160816; b=UzSlPvD118jn4MgC0J6tdfuDjYn2kh6p+eFklCl8Ibq5EEaKGC9TVqa8WKuC297VpX r6IulcvpROpNSsxFZASnJT0jhfJzYhJR2+bJ391s+nytwjY0yNHJniV6K1R/YbOZ9H6S xQp10POJseKWMdS0/Ppr2gHyKzlVXlRWHeXcs3dS/3NE9ZPHqugycNZeArhfuY7HHRaY OjLP4uOv16Cu4FH6xPJY1VGHaVHtLPerW3BC4PL9iNuYbG25JkRJKlAVZkIYgDjTupMK 3sSJldz8FVXd3av0RAbrFI2YGbPudKBl6Ysk9wRnpgU46lx6P/5vCi8gXmJM4GD4X4zN QUVQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:dkim-signature:dkim-signature:from; bh=glYrKDUJ7lHx0vPgFl5st9OXHzyL6p/mgGcT2k0j/yc=; fh=pKnPKUsir0uEGSsor+4Zc2vgbu+g+ayvUgsdzkuXaoA=; b=XrkCaiG7w/AKMBuAN2MOApHeHqmiDUrlk+kiA/qrlP4S2SmSmhXC6yGJ52Z135kBKa CNo5rYxPROLlPVhBBBoDZEjLc+441mErkRih5AWcW22smb0hFx842yeoJWtdLfhJr4TT Xfx8xc1nwHIeXtJFtiY1ilS6VMhhsRTB4/RI7RArgB2qWVbYBk3tCOt37D7HLmZhXmrN hAa3FMaf5SiSBwoDM546gO5N0ZDBqCNCQUJNC/HzBjSe+fjtk61oL/ghWv5xxRRcso2Y 469UNRISjYMCNOTQJ6aXYDc0X0XE81S1PhYxPyQjUeLDGsLArViNa+zG2qE6g4aUgk3O GLmQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=QP9FA40Y; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=FhOTMESp; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-70509-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-70509-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id c8-20020a05622a058800b0042c3846d27dsi5029167qtb.166.2024.02.18.11.01.03 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 18 Feb 2024 11:01:04 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-70509-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=QP9FA40Y; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=FhOTMESp; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-70509-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-70509-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id BDC4F1C20F1F for ; Sun, 18 Feb 2024 19:01:03 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C4CEC762DD; Sun, 18 Feb 2024 18:58:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="QP9FA40Y"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="FhOTMESp" 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 B6B956F520 for ; Sun, 18 Feb 2024 18:57:54 +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=1708282677; cv=none; b=OJseM3BEauP2lSo8Ys7Wd/NUTf8IdNHsgmhSGXWJoU97l0iPdBehceeR4CZf45zTzuehCj13B4PNDXTYSakU1VmvFA5Hm3e4/IZudCMeJijxU+Xj132xB0amLBWeKbgSO7ZELZY7LchKLc04aDbrmQXg9rHMHXjgAsd94diuRP4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708282677; c=relaxed/simple; bh=aVOu1/bqDAARdrnRU5+DODTSrgXpJ65t9RLdNz7m7TU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=ZQzItlAGpVE8bUo+Gye7NxtglewX8vomZEQktW7GCjhbY4OZCdG6kP/wNGMnl9LMJy8Tlh45T9wNWcMKsv2TXkWMoQvGfQH+0V6JIDzlgUBntiBm1ACqiTsYnGKG+BonfKuR8Mx82NCCuzgPzu3MWzBwcQEVX4deDQO6RRlj7Mo= 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=QP9FA40Y; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=FhOTMESp; 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 From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1708282672; 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=glYrKDUJ7lHx0vPgFl5st9OXHzyL6p/mgGcT2k0j/yc=; b=QP9FA40YAYELeVxUBZi0Zk2entx086hATCdFn7fwEWkwoePQdmQY0Zj0BaqefkCK4vyKhE yRkaQCR/GZDq+3tMY85Aso10KSnz9ewFoQR0uzw5xX7UEx2kQvU6snT7OpbrX6IUFeAuZ8 fOSXwvqW+QtcEVp3Oojb3qIw7rd/+Txlt4JS0gailqcqmpWZNwOF1AWvEl9rg0nLp1KJuz pO222FA/6ucaoV7cZ+z7J+PSOdW/EK/nUEaEJzVNFX95ipdWO4CLM5FJhy2oe4RcPyY6zw JrZHmJEV1me0Qx4e7u6kZE3qICmMgHtfiV/CuPCLnfNVRHS1Rgz5ka538z3gfw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1708282672; 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=glYrKDUJ7lHx0vPgFl5st9OXHzyL6p/mgGcT2k0j/yc=; b=FhOTMESp09Y0esdlb4LAnktBJn/wIjVMQZnSHidLDRzBe14BT9TOvFuRuyAZ4oZ7T1ZDDm /HeXGmslX87eNKBg== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org Subject: [PATCH printk v2 14/26] printk: nbcon: Provide function to flush using write_atomic() Date: Sun, 18 Feb 2024 20:03:14 +0106 Message-Id: <20240218185726.1994771-15-john.ogness@linutronix.de> In-Reply-To: <20240218185726.1994771-1-john.ogness@linutronix.de> References: <20240218185726.1994771-1-john.ogness@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791264412523681725 X-GMAIL-MSGID: 1791264412523681725 From: Thomas Gleixner Provide nbcon_atomic_flush_all() to perform flushing of all registered nbcon consoles using their write_atomic() callback. Like with legacy consoles, the nbcon consoles are flushed one record per console. This allows all nbcon consoles to print lines pseudo-simultaneously, rather than one console waiting for the full ringbuffer to dump to another console before printing anything. Unlike console_flush_all(), nbcon_atomic_flush_all() will only flush up through the newest record at the time of the call. This prevents a CPU from printing unbounded when other CPUs are adding records. Perform nbcon console atomic flushing in console_flush_on_panic(). This function is not only used in panic() but also other locations where there may be stored messages that need to be flushed. Co-developed-by: John Ogness Signed-off-by: John Ogness Signed-off-by: Thomas Gleixner (Intel) Reviewed-by: Petr Mladek --- kernel/printk/internal.h | 2 + kernel/printk/nbcon.c | 100 ++++++++++++++++++++++++++++++++++++++- kernel/printk/printk.c | 2 + 3 files changed, 102 insertions(+), 2 deletions(-) diff --git a/kernel/printk/internal.h b/kernel/printk/internal.h index 6780911fa8f2..d9a5205692fc 100644 --- a/kernel/printk/internal.h +++ b/kernel/printk/internal.h @@ -77,6 +77,7 @@ void nbcon_seq_force(struct console *con, u64 seq); bool nbcon_alloc(struct console *con); void nbcon_init(struct console *con); void nbcon_free(struct console *con); +void nbcon_atomic_flush_all(void); /* * Check if the given console is currently capable and allowed to print @@ -131,6 +132,7 @@ static inline void nbcon_seq_force(struct console *con, u64 seq) { } static inline bool nbcon_alloc(struct console *con) { return false; } static inline void nbcon_init(struct console *con) { } static inline void nbcon_free(struct console *con) { } +static inline void nbcon_atomic_flush_all(void) { } static inline bool console_is_usable(struct console *con, short flags) { return false; } diff --git a/kernel/printk/nbcon.c b/kernel/printk/nbcon.c index 02e8fdc1ea43..2eb2929c1027 100644 --- a/kernel/printk/nbcon.c +++ b/kernel/printk/nbcon.c @@ -539,7 +539,6 @@ static struct printk_buffers panic_nbcon_pbufs; * in an unsafe state. Otherwise, on success the caller may assume * the console is not in an unsafe state. */ -__maybe_unused static bool nbcon_context_try_acquire(struct nbcon_context *ctxt) { unsigned int cpu = smp_processor_id(); @@ -841,7 +840,6 @@ EXPORT_SYMBOL_GPL(nbcon_exit_unsafe); * When true is returned, @wctxt->ctxt.backlog indicates whether there are * still records pending in the ringbuffer, */ -__maybe_unused static bool nbcon_emit_next_record(struct nbcon_write_context *wctxt) { struct nbcon_context *ctxt = &ACCESS_PRIVATE(wctxt, ctxt); @@ -930,6 +928,104 @@ static bool nbcon_emit_next_record(struct nbcon_write_context *wctxt) return nbcon_context_exit_unsafe(ctxt); } +/** + * 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: False if the given console could not print a record or there + * are no more records to print, otherwise true. + * + * 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 = &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. + */ + if (!nbcon_emit_next_record(wctxt)) + return false; + + nbcon_context_release(ctxt); + + return ctxt->backlog; +} + +/** + * __nbcon_atomic_flush_all - Flush all nbcon consoles using their + * write_atomic() callback + * @stop_seq: Flush up until this record + */ +static void __nbcon_atomic_flush_all(u64 stop_seq) +{ + struct nbcon_write_context wctxt = { }; + struct nbcon_context *ctxt = &ACCESS_PRIVATE(&wctxt, ctxt); + struct console *con; + bool any_progress; + int cookie; + + do { + any_progress = false; + + cookie = console_srcu_read_lock(); + for_each_console_srcu(con) { + short flags = console_srcu_read_flags(con); + unsigned long irq_flags; + + if (!(flags & CON_NBCON)) + continue; + + if (!console_is_usable(con, flags)) + continue; + + if (nbcon_seq_read(con) >= stop_seq) + continue; + + memset(ctxt, 0, sizeof(*ctxt)); + ctxt->console = con; + ctxt->spinwait_max_us = 2000; + ctxt->prio = NBCON_PRIO_NORMAL; + + /* + * Atomic flushing does not use console driver + * synchronization (i.e. it does not hold the port + * lock for uart consoles). Therefore IRQs must be + * disabled to avoid being interrupted and then + * calling into a driver that will deadlock trying + * acquire console ownership. + */ + local_irq_save(irq_flags); + + any_progress |= nbcon_atomic_emit_one(&wctxt); + + local_irq_restore(irq_flags); + } + console_srcu_read_unlock(cookie); + } while (any_progress); +} + +/** + * nbcon_atomic_flush_all - Flush all nbcon consoles using their + * write_atomic() callback + * + * Flush the backlog up through the currently newest record. Any new + * records added while flushing will not be flushed. This is to avoid + * one CPU printing unbounded because other CPUs continue to add records. + */ +void nbcon_atomic_flush_all(void) +{ + __nbcon_atomic_flush_all(prb_next_reserve_seq(prb)); +} + /** * nbcon_alloc - Allocate buffers needed by the nbcon console * @con: Console to allocate buffers for diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index 9d56ce5837f9..ea170ade4d42 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -3169,6 +3169,8 @@ void console_flush_on_panic(enum con_flush_mode mode) console_srcu_read_unlock(cookie); } + nbcon_atomic_flush_all(); + console_flush_all(false, &next_seq, &handover); } From patchwork Sun Feb 18 18:57:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 202844 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp912082dyc; Sun, 18 Feb 2024 11:00:43 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXteG2uHICAFMftJy1yjXQvhzbW1pSoVLkKmH3uifu95AQyPv0rwELiZUT29CzpMiQI7Ofb1bHF+JibqYev2RVu1Epkug== X-Google-Smtp-Source: AGHT+IEwkloKEKIascEEHxuTn4f9uWI9tmQq1VFLMwvz6gWiAjWeg00vxyCgouH4c1YKxCIHtPq/ X-Received: by 2002:a37:e20d:0:b0:787:272a:e298 with SMTP id g13-20020a37e20d000000b00787272ae298mr10721638qki.62.1708282842872; Sun, 18 Feb 2024 11:00:42 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708282842; cv=pass; d=google.com; s=arc-20160816; b=i/zneWpKh9DmgeR0i60d8Pcy4BpPXVTmYNz6mY0bUjLPQjrL4W57HXDkrK0nXPgnTV GR06YOFK+FNS3vKmKl4/JTYywj+41svJubTWkoPZo6denUxFbizalU2NdfTOVpyY4LUY kihiJ/+YbuGmLV1nrA0Y2md5RM53NQKRpEW+iE29hl3P8w6/l1RvZYVIyacQx/mJQP3r /WUo/rh1fmOWfCm2pItNu3eJJ+CHpiBdh1q9HTu6fzMJ+NmVNuHeh2C+Zpj/KmHnuLxu gNz9ISqGfKHrVbvQ6DxmtJ4jV3DWosz6+eWyKKkkWSRHK502pdySC1OqMLeHTaHXTiBQ LIfw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:dkim-signature:dkim-signature:from; bh=QA/99sNBe74Zpg0DWyhl5wv3RvxapTRr2AVbgdHNKI4=; fh=pKnPKUsir0uEGSsor+4Zc2vgbu+g+ayvUgsdzkuXaoA=; b=fGNr42y6CW9ybAaN7L9hWvkHxpEP/v7KrtG4XkLiHk0kgurQewP4oVmupCNZRhbpdu ojO0QHdvJMjYlbktq+ejNpcGegwmk2qQ9KeUmVtsp2z4zRZVn56oH1bGvgOnMlDA/ary 4LNj2VrwQa4jUK41w+sf2Qh2OVYEx2LgNiLoibOG5Te+qUkTRjD50Kfl0JsaUMAfG+ad Mo7zmE3fxAAOHUxwwG59oclYj70aT4rUx1aMQ3qLBPaICkkmjy0Chbxi8h7EAHkg10v8 5E0idukHuaxXZWIsNCKQ6r0JTya4P9FQGhrtqwz4qVcEA9tfJzkqwrcXzqxNd2QFiQ25 Y8+g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b="rJ1/Wdf4"; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-70508-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-70508-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id pa10-20020a05620a830a00b007874f43dd5dsi4045760qkn.445.2024.02.18.11.00.42 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 18 Feb 2024 11:00:42 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-70508-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b="rJ1/Wdf4"; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-70508-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-70508-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id A884D1C20327 for ; Sun, 18 Feb 2024 19:00:42 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 474AE76054; Sun, 18 Feb 2024 18:58:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="rJ1/Wdf4"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="9QfHj5ew" 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 628406FB86 for ; Sun, 18 Feb 2024 18:57: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=1708282677; cv=none; b=miYAzYkJaujzTcoE3WgimXqdloJ2+rC6t5E7/Osr5tjSRXu++APozVRh2SV9trmSb9RNJ/UW6FophEf9rLC3AZpz1f04QrgOJ8zLgv/C0UaAaXkbUN7EbDZNA7G/4FjqNHVGKldYwmkVOi2WjQWAwzXAbjmrvWep4TxFfPtZy/c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708282677; c=relaxed/simple; bh=44GMokOuhofcbVPi1PR9Ui7+7904b0FBavmkwZ/WX3M=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=QUBl1w3al/mN1IT1Bi2CHZxDEnuuTrCip1GDUaPAWYNmQQP1sEB5qFoet0vUoJQ70fkew6aCl8vQ0Kh15cobEhijMrcowoUpdzQ1OgghTXPLuv3Aj4u072eECXOAeNJleCoTGV9/sGcOwVSLQm7ESoENFXUX3jfMe0HCHt3+Dt0= 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=rJ1/Wdf4; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=9QfHj5ew; 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 From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1708282673; 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=QA/99sNBe74Zpg0DWyhl5wv3RvxapTRr2AVbgdHNKI4=; b=rJ1/Wdf4YXXUQmodc7+URL0ljrOU8z6ZTYWtKB2i5KhN1BD61MJz2T+1+1cvhlgpLJwpQO /gbCtKVFxov4Q2DsM1zr+Me+kviqt+CDoGYOgzwqqZ4Ikf9ZRJVIf6E5btxSqpX7cAZzy1 YUZy+4lQK0+3DNveay7/3XOWXQu4DgJH1QDUlDn/RoCiorZULjjdyofJq6xsjOPs3ek93L 7679/EUmaZYUedbO9bv9jXkxFlBf4yL+8OrB1fzlv8hQa+D4Pnr1jGgci8IOfHhJjA0BP7 P/uJAfRzY/GoJovcz8Umt2cb91rwFg9Kw3848oKAb+h+XsWENrq49de0SqTqsQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1708282673; 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=QA/99sNBe74Zpg0DWyhl5wv3RvxapTRr2AVbgdHNKI4=; b=9QfHj5ew/k0LsjwUvp0IoPme/gb2gFwSzUmf3FCspKkLClGC+ux0FPNIurkWNS3ZRu814F ocrdcs+7MlSWVvAw== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org Subject: [PATCH printk v2 15/26] printk: Track registered boot consoles Date: Sun, 18 Feb 2024 20:03:15 +0106 Message-Id: <20240218185726.1994771-16-john.ogness@linutronix.de> In-Reply-To: <20240218185726.1994771-1-john.ogness@linutronix.de> References: <20240218185726.1994771-1-john.ogness@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791264390241408817 X-GMAIL-MSGID: 1791264390241408817 Unfortunately it is not known if a boot console and a regular (legacy or nbcon) console use the same hardware. For this reason they must not be allowed to print simultaneously. For legacy consoles this is not an issue because they are already synchronized with the boot consoles using the console lock. However nbcon consoles can be triggered separately. Add a global flag @have_boot_console to identify if any boot consoles are registered. This will be used in follow-up commits to ensure that boot consoles and nbcon consoles cannot print simultaneously. Signed-off-by: John Ogness Reviewed-by: Petr Mladek --- kernel/printk/printk.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index ea170ade4d42..1b14159990ba 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -463,6 +463,14 @@ static int console_msg_format = MSG_FORMAT_DEFAULT; /* syslog_lock protects syslog_* variables and write access to clear_seq. */ static DEFINE_MUTEX(syslog_lock); +/* + * Specifies if a boot console is registered. If boot consoles are present, + * nbcon consoles cannot print simultaneously and must be synchronized by + * the console lock. This is because boot consoles and nbcon consoles may + * have mapped the same hardware. + */ +bool have_boot_console; + #ifdef CONFIG_PRINTK DECLARE_WAIT_QUEUE_HEAD(log_wait); /* All 3 protected by @syslog_lock. */ @@ -3499,6 +3507,9 @@ void register_console(struct console *newcon) if (newcon->flags & CON_NBCON) nbcon_init(newcon); + if (newcon->flags & CON_BOOT) + have_boot_console = true; + /* * Put this console in the list - keep the * preferred driver at the head of the list. @@ -3551,6 +3562,8 @@ EXPORT_SYMBOL(register_console); /* Must be called under console_list_lock(). */ static int unregister_console_locked(struct console *console) { + bool found_boot_con = false; + struct console *c; int res; lockdep_assert_console_list_lock_held(); @@ -3598,6 +3611,17 @@ static int unregister_console_locked(struct console *console) if (console->exit) res = console->exit(console); + /* + * With this console gone, the global flags tracking registered + * console types may have changed. Update them. + */ + for_each_console(c) { + if (c->flags & CON_BOOT) + found_boot_con = true; + } + if (!found_boot_con) + have_boot_console = false; + return res; } From patchwork Sun Feb 18 18:57:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 202847 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp912578dyc; Sun, 18 Feb 2024 11:01:35 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCW9FjCubdhcMwyK3YZiZycNuL4ctcldnRY4IOl677Ak75QM1JDxLcTs+zhfOLJvT8pGRyD64F1YRRWHffpw5y3mLoVupw== X-Google-Smtp-Source: AGHT+IETpoglYru9SMDtZ3m10o3GDrPGv2INiUsiiYjM4INa5MEKM186k5hEZALPziHMALcg3u1V X-Received: by 2002:a05:6a00:9085:b0:6db:d978:9047 with SMTP id jo5-20020a056a00908500b006dbd9789047mr13163284pfb.1.1708282895392; Sun, 18 Feb 2024 11:01:35 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708282895; cv=pass; d=google.com; s=arc-20160816; b=xhusp1k2OgCHTwPhgVKHEEpEBIW+UJdTKT+g+7Kr7z+se5QAjLU7kGs9ee6wISr/kv GIONn9FNiD7ddxWwTOFIbp96yegdDh8gF4B89t5xlf2f+w2fqstdmYtPVxozi1anhhwj /s8EHiyWxXN16le1ADf37IvKreB4Xuj3lreDhAdxyWJ/Oqu6cc7KSN0uCVyA+H8Klft5 kjlqNO/R9ABkjNgvkm7+QmMjKOBxCvoVesCbK4/qqjPlEYapjeQ5qdfVV018GK6/hatc ggjjJsX6ig0SlXk2aG5wm2rupya1nzJvR1GMAjPX6mjwBOmvTxYPnDPJvlYYfLK4k9/X Viig== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:dkim-signature:dkim-signature:from; bh=2WpRiuHUchJ8PUhBQPppc9wlrZ+BaiMWpumcr51nxKc=; fh=pKnPKUsir0uEGSsor+4Zc2vgbu+g+ayvUgsdzkuXaoA=; b=RK5U42J0VCpY8wg5O9JLyuAZskqBUVJdUtGuwuWb+sV9/RQAvilySCV9abKwvsdOSf yKN1WhI2si8wZb/ATRcXwKXHinUeBzSwfxG3UI9IaaSdTnUkXh41uQhCOcI15xgspYwd 4YdQLJ+Pj06ziX/Xzuw2Q2+Z7O9YJxhN4sinesickVnYgQ9hlKIliAqrLkkQZdTQJhc9 SweC1cywsEadkk7gwN//vU54RxJHaWdIgRiy9gkAjCJ9fgaqbS+2mpBgIFM97trhFBWT 6ol2UZIru06sI/uXykUwvAg8G25ECkVtzU4m/USlbqp1O+txL2gP5jtjs74D4dW1MMBM fEMA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=X1pn8gUl; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-70510-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-70510-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id dr12-20020a056a020fcc00b005ced6c45233si3085547pgb.712.2024.02.18.11.01.35 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 18 Feb 2024 11:01:35 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-70510-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=X1pn8gUl; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-70510-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-70510-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 307A6281C48 for ; Sun, 18 Feb 2024 19:01:35 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8D61E76405; Sun, 18 Feb 2024 18:58:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="X1pn8gUl"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="uRlGqUPm" 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 627F86FB84 for ; Sun, 18 Feb 2024 18:57: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=1708282677; cv=none; b=DEGltN6YM9rIBkIlNY64Fek8hAZlWb29rTBsdvYT6UmFMGp+vOAjV/SaHd81kjJFbcQvwK5YScO+n/q15vMZeBIMSoxcPvg+6Pdvm3ScLuzSZOXA8IqyFHXkd5PYGQaogFIiDgPlDDEgNmr34AsJa87vnxlRV/JDR5yB5EsD/7M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708282677; c=relaxed/simple; bh=XNAFOxzMyR2DiCX23eg6uCGQcbosdfuXh1/QvXBV+3g=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=JRqiAAdJ7N95ew4LdmxCwK69cSShxTUxsdM9AoCw26HOqT+aYJG2BLX/BwWRWuGZpY7HasekPRSzU4Ax7ftWlpmPgq4rMwnJqqbPjVv2/kDKZ8Y1tcVNinwke1bk8HBpSvDHjuw2yDSZCR8+Y9sK7HVRpvllKD68AbV8/xojtDc= 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=X1pn8gUl; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=uRlGqUPm; 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 From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1708282673; 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=2WpRiuHUchJ8PUhBQPppc9wlrZ+BaiMWpumcr51nxKc=; b=X1pn8gUlKUoMEiWMnaptlfxcDZ/fGoV6vTRapTZO3rzlah99nQ7MUPx+Ha+jrZN1cvTGZK JrPWwd+KnMJUZjxwwHxTkgZVzelM+KIUL80N/0gM6KtqB55uszHNyVCyXY/pQk0wvOMwkK N6sB+qCR2oVPZG6QvDCPvmLZ57GaYjSgXdCKjpF4NqvFXXlZsZqnR2BmuZf9AIg8n8iGUl S8LlAegzwnddOuEvKG4KlklwB/76QjbzJ5Wyth4ktGSyyjuLFureb94qasBM6jQBt0Zwl7 aOLDzHlfdM2jKBlHAaa6J73DIx02d5aN2C4UQXkBVqFDNc0DtFwIBf7GnVdWRw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1708282673; 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=2WpRiuHUchJ8PUhBQPppc9wlrZ+BaiMWpumcr51nxKc=; b=uRlGqUPmvzNMGbcXT8nTGeSPZO0Nk1Wof15ZY2YyL6MAW1gTwVA2JE+R49msvY6HL7XMAh Ch1jTVfhrX2veLBQ== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org Subject: [PATCH printk v2 16/26] printk: nbcon: Use nbcon consoles in console_flush_all() Date: Sun, 18 Feb 2024 20:03:16 +0106 Message-Id: <20240218185726.1994771-17-john.ogness@linutronix.de> In-Reply-To: <20240218185726.1994771-1-john.ogness@linutronix.de> References: <20240218185726.1994771-1-john.ogness@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791264445759991389 X-GMAIL-MSGID: 1791264445759991389 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. Signed-off-by: John Ogness --- kernel/printk/internal.h | 6 ++++++ kernel/printk/nbcon.c | 45 ++++++++++++++++++++++++++++++++++++++++ kernel/printk/printk.c | 19 ++++++++++++----- 3 files changed, 65 insertions(+), 5 deletions(-) diff --git a/kernel/printk/internal.h b/kernel/printk/internal.h index d9a5205692fc..b34847ec6b0d 100644 --- a/kernel/printk/internal.h +++ b/kernel/printk/internal.h @@ -71,6 +71,8 @@ void defer_console_output(void); 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); u64 nbcon_seq_read(struct console *con); void nbcon_seq_force(struct console *con, u64 seq); @@ -78,6 +80,8 @@ bool nbcon_alloc(struct console *con); void nbcon_init(struct console *con); void nbcon_free(struct console *con); void nbcon_atomic_flush_all(void); +bool nbcon_legacy_emit_next_record(struct console *con, bool *handover, + int cookie); /* * Check if the given console is currently capable and allowed to print @@ -133,6 +137,8 @@ static inline bool nbcon_alloc(struct console *con) { return false; } static inline void nbcon_init(struct console *con) { } static inline void nbcon_free(struct console *con) { } static inline void nbcon_atomic_flush_all(void) { } +static inline bool nbcon_legacy_emit_next_record(struct console *con, bool *handover, + int cookie) { return false; } static inline bool console_is_usable(struct console *con, short flags) { return false; } diff --git a/kernel/printk/nbcon.c b/kernel/printk/nbcon.c index 2eb2929c1027..747f5cbfe5ee 100644 --- a/kernel/printk/nbcon.c +++ b/kernel/printk/nbcon.c @@ -532,6 +532,7 @@ static struct printk_buffers panic_nbcon_pbufs; * nbcon_context_try_acquire - Try to acquire nbcon console * @ctxt: The context of the caller * + * Context: Any context which could not be migrated to another CPU. * Return: True if the console was acquired. False otherwise. * * If the caller allowed an unsafe hostile takeover, on success the @@ -960,6 +961,50 @@ static bool nbcon_atomic_emit_one(struct nbcon_write_context *wctxt) 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 which could not be migrated to another CPU. + * Return: True if a record could be printed, otherwise false. + * + * This function is meant to be called by console_flush_all() to print records + * 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 = { }; + struct nbcon_context *ctxt = &ACCESS_PRIVATE(&wctxt, ctxt); + bool progress = false; + unsigned long flags; + + *handover = false; + + /* Use the same procedure as console_emit_next_record(). */ + printk_safe_enter_irqsave(flags); + console_lock_spinning_enable(); + stop_critical_timings(); + + ctxt->console = con; + ctxt->prio = NBCON_PRIO_NORMAL; + + progress = nbcon_atomic_emit_one(&wctxt); + + start_critical_timings(); + *handover = console_lock_spinning_disable_and_check(cookie); + printk_safe_exit_irqrestore(flags); + + return progress; +} + /** * __nbcon_atomic_flush_all - Flush all nbcon consoles using their * write_atomic() callback diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index 1b14159990ba..d91771fb306e 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -1871,7 +1871,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. @@ -1910,7 +1910,7 @@ static void console_lock_spinning_enable(void) * * 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; @@ -2948,13 +2948,22 @@ static bool console_flush_all(bool do_cond_resched, u64 *next_seq, bool *handove cookie = console_srcu_read_lock(); for_each_console_srcu(con) { short flags = console_srcu_read_flags(con); + u64 printk_seq; bool progress; if (!console_is_usable(con, flags)) continue; any_usable = true; - progress = console_emit_next_record(con, handover, cookie); + if (flags & CON_NBCON) { + progress = nbcon_legacy_emit_next_record(con, handover, cookie); + + printk_seq = nbcon_seq_read(con); + } else { + progress = console_emit_next_record(con, handover, cookie); + + printk_seq = con->seq; + } /* * If a handover has occurred, the SRCU read lock @@ -2964,8 +2973,8 @@ static bool console_flush_all(bool do_cond_resched, u64 *next_seq, bool *handove return false; /* Track the next of the highest seq flushed. */ - if (con->seq > *next_seq) - *next_seq = con->seq; + if (printk_seq > *next_seq) + *next_seq = printk_seq; if (!progress) continue; From patchwork Sun Feb 18 18:57:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 202846 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp912406dyc; Sun, 18 Feb 2024 11:01:16 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUA+18shv0IZpoXtNGVKNHVox52wOJGux9i8wWgi0dh2cP0uo+7dVPZvW3toACduDAGegDJMQEjgYF5bn4mQqeM/ARFIw== X-Google-Smtp-Source: AGHT+IHsG2Xtn650NkQ+g481QkMUtba/FdfDKmpVnlK7lRk7wqLt4Wm0G5nvMSeLqmEj68G0iGmP X-Received: by 2002:a05:622a:1b8d:b0:42c:4e93:ac11 with SMTP id bp13-20020a05622a1b8d00b0042c4e93ac11mr13814202qtb.28.1708282876598; Sun, 18 Feb 2024 11:01:16 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708282876; cv=pass; d=google.com; s=arc-20160816; b=tyxsuqW/jm3U6jJEj8Y55LiYl9zMEf75Up5Td5Rc2dO7S5WDM/q7Vq3W7Y0FhnszSb D7lQu0xiHC+o7TO+HMtEZT9rlCNbDmw4B/2qKchfJPTg7heh578jwbYeI1FjnbDiDebn T6UUkUxPAQXiP6fybZF74974MvpbDDGBfaU1G2Ch9vpGcGyswwXfljL09d2ROyQLfV/3 7zQRAhE78tfPTV5AqPsgAuZmGg8ZSa0dTERgPuEr+mN3kgemiV3wZyaQS6eZzqQJr5Ma lGt9E4xRIV7348yTQRdQGgmQz0ocpfNiem456qjIP5FnmzrWnFmjq5cjbUzRnk9bDjqk w/6g== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:dkim-signature:dkim-signature:from; bh=U8tKxZn6xYxnbLSfcQWQs6Fl73klYk0DkiEPSmtK48M=; fh=pKnPKUsir0uEGSsor+4Zc2vgbu+g+ayvUgsdzkuXaoA=; b=lK2WRxX4R5OnY97jrDZeJkpOVAha1HZJ9YJFep4Yf3pGkfZalMhFHw0QNiyl9auIBJ 8j/N9OcnWUjE/+8eWcdjODJhl/OFjcWkxDO4+csHZp1C2yb1MGxo5tlUvuZ3Ib2csncW fBv1bOMHVczX7+ylafrSuAFHz0IXEsOBxTsUGNdYNBrGWIymZQfRtFbguttd/VlQCQsh c48f+TdlVRP409zsJ3sREEVIHUeI1V/wBrrkEtI3dlbA1ErzQyCfsgHhe/1YatiO0OaO honDBhsx0+g1dsY19sRG8cjfWiBIdkh/4VaLCy+tlP8EROhY+yEZlrq6dqDZybDKSYY8 i1HQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=ct5W9yD3; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-70511-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-70511-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id s22-20020a05622a019600b0042dd4c93593si4778393qtw.759.2024.02.18.11.01.16 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 18 Feb 2024 11:01:16 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-70511-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=ct5W9yD3; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-70511-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-70511-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 5855E1C20F1F for ; Sun, 18 Feb 2024 19:01:16 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 249BB762FD; Sun, 18 Feb 2024 18:58:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="ct5W9yD3"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="bUykeJ6U" 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 CEB9371B2F for ; Sun, 18 Feb 2024 18:57: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=1708282677; cv=none; b=Y9mYu8xAWujFVHJL4YN45dcPm66F9YSqrRq/0uknJZazR7BDCC3xLdcyfXesUt5MLf7OlClVDuW+3bsgathwn/sq+uhKXsautDhq8kOOGvO3HCr9R113agEFc0npg1GsJuZtXmKpj2Po27X5qcQw15/BNB7++7fRr6vBojzCwK0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708282677; c=relaxed/simple; bh=cFmrlN6+bjkYvopWH2Q6A0YP81LxOASzKK6Wrrcc1LQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=GZqveQ+1skRgw8If4+KeMTOF0wIiYzgaUwwN/GTTR8EbWpcSaUPL1R2zUdCrj7y83FFyVW5AZPO05buv+BK3g8X4qcJ9fSiOX5W/03DFVpNf/2Sq0MiOwmsKpqeQXBS+ICdv3kp6T3eAaOuByrW353Mj4JLIHoH4AyEYymul3mI= 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=ct5W9yD3; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=bUykeJ6U; 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 From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1708282673; 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=U8tKxZn6xYxnbLSfcQWQs6Fl73klYk0DkiEPSmtK48M=; b=ct5W9yD3PDE9b+waw7Odwy0FtNYmwplTQMHj7vKc38guEZ6Q2ZlG5ci0CehFfccgGPgjg1 xZqnIMdEJjovy2Okdt4hNLdtviWsJkQMQN0n2nbQhErdFGOYg9ZzTMrM0pi4amHME0hrye OH2RgT8hoFRLlY/Y8Z0zhTm4rclmFiZfaEFNwdyqZlXrtPDR3/GYFGD/x5ITcjV5KRtdfo vOiXdA4PZ4vk9m9eKs6Ttp/l3XIPTrOwAH5o3V5aZ/fZia2chddSqPEWmtjRNtdHyudDrf 4p+ewt98SR4bpsirn1cFSPTvkL3eaCPv3WXTHg2oz33OW7u5fbqc+gYE7z2jag== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1708282673; 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=U8tKxZn6xYxnbLSfcQWQs6Fl73klYk0DkiEPSmtK48M=; b=bUykeJ6UlUC/VGxARJe/pHOyyjNV24ASEP11nA7i+rlF5J42Ds+TgwQLCsZcgLTvvgadip yi/pkG1662XnHSDg== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org Subject: [PATCH printk v2 17/26] printk: nbcon: Assign priority based on CPU state Date: Sun, 18 Feb 2024 20:03:17 +0106 Message-Id: <20240218185726.1994771-18-john.ogness@linutronix.de> In-Reply-To: <20240218185726.1994771-1-john.ogness@linutronix.de> References: <20240218185726.1994771-1-john.ogness@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791264425591130387 X-GMAIL-MSGID: 1791264425591130387 Use the current state of the CPU to determine which priority to assign to the printing context. Note: The uart_port wrapper, which is responsible for non-console- printing activities, will always use NORMAL priority. Signed-off-by: John Ogness Reviewed-by: Petr Mladek --- kernel/printk/internal.h | 2 ++ kernel/printk/nbcon.c | 30 ++++++++++++++++++++++++++++-- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/kernel/printk/internal.h b/kernel/printk/internal.h index b34847ec6b0d..70e9a1ea75be 100644 --- a/kernel/printk/internal.h +++ b/kernel/printk/internal.h @@ -79,6 +79,7 @@ void nbcon_seq_force(struct console *con, u64 seq); bool nbcon_alloc(struct console *con); void nbcon_init(struct console *con); void nbcon_free(struct console *con); +enum nbcon_prio nbcon_get_default_prio(void); void nbcon_atomic_flush_all(void); bool nbcon_legacy_emit_next_record(struct console *con, bool *handover, int cookie); @@ -136,6 +137,7 @@ static inline void nbcon_seq_force(struct console *con, u64 seq) { } static inline bool nbcon_alloc(struct console *con) { return false; } static inline void nbcon_init(struct console *con) { } 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_all(void) { } static inline bool nbcon_legacy_emit_next_record(struct console *con, bool *handover, int cookie) { return false; } diff --git a/kernel/printk/nbcon.c b/kernel/printk/nbcon.c index 747f5cbfe5ee..1a18549e43b8 100644 --- a/kernel/printk/nbcon.c +++ b/kernel/printk/nbcon.c @@ -961,6 +961,22 @@ static bool nbcon_atomic_emit_one(struct nbcon_write_context *wctxt) return ctxt->backlog; } +/** + * nbcon_get_default_prio - The appropriate nbcon priority to use for nbcon + * printing on the current CPU + * + * Context: Any context which could not be migrated to another CPU. + * Return: The nbcon_prio to use for acquiring an nbcon console in this + * context for printing. + */ +enum nbcon_prio nbcon_get_default_prio(void) +{ + if (this_cpu_in_panic()) + return NBCON_PRIO_PANIC; + + return NBCON_PRIO_NORMAL; +} + /** * nbcon_legacy_emit_next_record - Print one record for an nbcon console * in legacy contexts @@ -994,7 +1010,7 @@ bool nbcon_legacy_emit_next_record(struct console *con, bool *handover, stop_critical_timings(); ctxt->console = con; - ctxt->prio = NBCON_PRIO_NORMAL; + ctxt->prio = nbcon_get_default_prio(); progress = nbcon_atomic_emit_one(&wctxt); @@ -1038,7 +1054,6 @@ static void __nbcon_atomic_flush_all(u64 stop_seq) memset(ctxt, 0, sizeof(*ctxt)); ctxt->console = con; ctxt->spinwait_max_us = 2000; - ctxt->prio = NBCON_PRIO_NORMAL; /* * Atomic flushing does not use console driver @@ -1047,9 +1062,14 @@ static void __nbcon_atomic_flush_all(u64 stop_seq) * disabled to avoid being interrupted and then * calling into a driver that will deadlock trying * acquire console ownership. + * + * This also disables migration in order to get the + * current CPU priority. */ local_irq_save(irq_flags); + ctxt->prio = nbcon_get_default_prio(); + any_progress |= nbcon_atomic_emit_one(&wctxt); local_irq_restore(irq_flags); @@ -1161,6 +1181,9 @@ static inline bool uart_is_nbcon(struct uart_port *up) * * If @up is an nbcon console, this console will be acquired and marked as * unsafe. Otherwise this function does nothing. + * + * nbcon consoles acquired via the port lock wrapper always use priority + * NBCON_PRIO_NORMAL. */ void uart_nbcon_acquire(struct uart_port *up) { @@ -1195,6 +1218,9 @@ EXPORT_SYMBOL_GPL(uart_nbcon_acquire); * * If @up is an nbcon console, the console will be marked as safe and * released. Otherwise this function does nothing. + * + * nbcon consoles acquired via the port lock wrapper always use priority + * NBCON_PRIO_NORMAL. */ void uart_nbcon_release(struct uart_port *up) { From patchwork Sun Feb 18 18:57:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 202852 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp913130dyc; Sun, 18 Feb 2024 11:02:32 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXX0GSydu5AKJzz0BGwTVTY7Tq5RBSRqXPFhyb/VA2EJaCK3+9UZlIBewpSpLTDT/uhkgKLKlQel3/wJCKNeKSFIszVlg== X-Google-Smtp-Source: AGHT+IHoRJsdO66vXs0OXVBlNebKmNR1n+xblaQzcA1J7na1hHPlIHN7ftH4AuDGy/9FaWX2ImSK X-Received: by 2002:aca:2109:0:b0:3c0:3c3d:3671 with SMTP id 9-20020aca2109000000b003c03c3d3671mr10114106oiz.30.1708282952414; Sun, 18 Feb 2024 11:02:32 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708282952; cv=pass; d=google.com; s=arc-20160816; b=QF/sEV/SXunnqK458JkVrlSZfu3nba02YFgs5V08b3PhcnFhACUuSKU7ovNCJhYskF surtz4WwvC35yXRFJC9zRMEXJ2FhMa7XWR4L3ctGV3nBqtP+Hxxn3wFSS3u4tZiejG9X spiumHkCJRg7EjOcD3/Q4bh/Mecf9PENiMSjNrqQZ8niS12oNeRRlUl9dq6gXeyXGwS/ JnF6Z5HCtqr+VK6oGyopbMGj3KcS/vdkFLDnKI3hdgSi4PscOpXwPIa2m+zF9+hccHa4 qDi94rnGvbVrEivAgllC2gS/gYiUmna6AdcuqdfujMBD1OEL4kvznCiyGYjw2pJhFjR9 HUag== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:dkim-signature:dkim-signature:from; bh=Bzed56TBLrwPGrN35dvYqd3cTuWFkQirwReZT+CtxsI=; fh=pMHV3vVROQC8j6OjmPGyHfg2QSqtPT6fajBJ6BzWVsg=; b=YDoXrwyF59K+/qwf5KtePBX30IkL/wYzy/eP2eRJ2l9OtMB3XJidn1rNxtXrDTnlIT qWy4MVT/iQL/l0etBesyL0V30ZR7p9n4Nv5/k85RwHsFGVXWQLBkNPJVKmyXYiZpzhwy Nt1+rtudEiuMlV2lvmbyvQvU6Re0eqho50EP9s5L4rCWdRVEI71mPnQirCDAxv/BOq5E lKHOyZFS1CKzIimhcmub0qWYaLrpIo/mWE8jdlkUWCUcM3US25tzYE755kjSNWZnmmST IOAD5brJjsDFQtqnNpNJHYgAUK9muNdrZC2d9FQ9H862A3jLTRBemndzQlH9QLXlTPQV AGrw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=FXZwC3OF; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-70514-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-70514-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id fq10-20020a056214258a00b0068c82493a00si4838158qvb.25.2024.02.18.11.02.32 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 18 Feb 2024 11:02:32 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-70514-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=FXZwC3OF; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-70514-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-70514-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 3672D1C20F22 for ; Sun, 18 Feb 2024 19:02:32 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 811326F504; Sun, 18 Feb 2024 18:58:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="FXZwC3OF"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="Xzyu0Cxe" 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 4ECC36F091 for ; Sun, 18 Feb 2024 18:57: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=1708282678; cv=none; b=Miht3BAc8cu6YvwqSrL0YndnZdiGwNoGLPB1GaxXKhKuGhTjxKHFOWDrtkoaivOGyxinWNxSzi2Z4/x8g+8I2ojsNHFeVDQpJBkge4/1Mi9WR5YRqU0hlnrwe49bSyyzhwvgJF5dDEXgxA7Abi38d7FYOG6Ajv+724agfYPInzg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708282678; c=relaxed/simple; bh=81eO5T4mRHN1U1zZes/KHjNFY37KXcnTqwj3ihqj47c=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=O5KVFe1WHb+Y25CNsKZTtUSHpVBNMOugyJV+9Yw2K4BV6QAVnwvHaQYNzJnujrN4tFAGlQnCv5JuXrT06m3sH4vFBZ3O2QDOzeQ4BBH12W3gyUzu6GPJWMVWU2p33eGpUy7UbJKiFAfqRwRB6/6W1ep2Orj8npOkjZwXXCumeDc= 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=FXZwC3OF; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=Xzyu0Cxe; 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 From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1708282674; 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=Bzed56TBLrwPGrN35dvYqd3cTuWFkQirwReZT+CtxsI=; b=FXZwC3OFc25rzIrHikF4WtdBv2APWCF5VEmZ2scnH8HpzoR0dg4QM35v9Ua/AvOJKwkSPg THLEn5wdfOtxt0QIcDei+R59stZHcg5rB2mVzBiyQ5VtElXAAqf7EtAEJkdF8EziTDXF8I DNcTA52EkfWu8F29D2aq6RdaSElN8M+S6rjvlLTkhZ9XDBCQ/xspUVVPGh0Z/u7dCwNCEK HDo3YielB5lvVcH5N0jUymejn9XbGl3M4ne16/6+5y34jYUIDaO4Hm1lI/q8yuBzObKYLE BbO2oNQA1RVGAC33fMqMSK28dm6w5Oax8qBX3bPFiL28ehk7ZjMEd4t7kxCIzQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1708282674; 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=Bzed56TBLrwPGrN35dvYqd3cTuWFkQirwReZT+CtxsI=; b=Xzyu0CxexcMZiEDy4gQzCjfvKEd0rZp1n39XpIQTaMfLxZmfj0urMk/8z9PuagwSCHywl6 WDAJh5fw296pSIBQ== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org, Andrew Morton , Josh Poimboeuf , "Peter Zijlstra (Intel)" , Uros Bizjak , "Guilherme G. Piccoli" , Lukas Wunner , Arnd Bergmann Subject: [PATCH printk v2 18/26] printk: nbcon: Add unsafe flushing on panic Date: Sun, 18 Feb 2024 20:03:18 +0106 Message-Id: <20240218185726.1994771-19-john.ogness@linutronix.de> In-Reply-To: <20240218185726.1994771-1-john.ogness@linutronix.de> References: <20240218185726.1994771-1-john.ogness@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791264505310631390 X-GMAIL-MSGID: 1791264505310631390 Add nbcon_atomic_flush_unsafe() to flush all nbcon consoles using the write_atomic() callback and allowing unsafe hostile takeovers. Call this at the end of panic() as a final attempt to flush any pending messages. Note that legacy consoles use unsafe methods for flushing from the beginning of panic (see bust_spinlocks()). Therefore, systems using both legacy and nbcon consoles may still fail to see panic messages due to unsafe legacy console usage. Signed-off-by: John Ogness Reviewed-by: Petr Mladek --- include/linux/printk.h | 5 +++++ kernel/panic.c | 1 + kernel/printk/nbcon.c | 18 ++++++++++++++++-- 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/include/linux/printk.h b/include/linux/printk.h index ef57a4d93ae2..fe37395af9e2 100644 --- a/include/linux/printk.h +++ b/include/linux/printk.h @@ -199,6 +199,7 @@ extern asmlinkage void dump_stack(void) __cold; void printk_trigger_flush(void); extern void uart_nbcon_acquire(struct uart_port *up); extern void uart_nbcon_release(struct uart_port *up); +void nbcon_atomic_flush_unsafe(void); #else static inline __printf(1, 0) int vprintk(const char *s, va_list args) @@ -287,6 +288,10 @@ static inline void uart_nbcon_release(struct uart_port *up) { } +static inline void nbcon_atomic_flush_unsafe(void) +{ +} + #endif bool this_cpu_in_panic(void); diff --git a/kernel/panic.c b/kernel/panic.c index f22d8f33ea14..c039f8e1ddae 100644 --- a/kernel/panic.c +++ b/kernel/panic.c @@ -453,6 +453,7 @@ void panic(const char *fmt, ...) * Explicitly flush the kernel log buffer one last time. */ console_flush_on_panic(CONSOLE_FLUSH_PENDING); + nbcon_atomic_flush_unsafe(); local_irq_enable(); for (i = 0; ; i += PANIC_TIMER_STEP) { diff --git a/kernel/printk/nbcon.c b/kernel/printk/nbcon.c index 1a18549e43b8..64dedd79e880 100644 --- a/kernel/printk/nbcon.c +++ b/kernel/printk/nbcon.c @@ -1025,8 +1025,9 @@ bool nbcon_legacy_emit_next_record(struct console *con, bool *handover, * __nbcon_atomic_flush_all - Flush all nbcon consoles using their * write_atomic() callback * @stop_seq: Flush up until this record + * @allow_unsafe_takeover: True, to allow unsafe hostile takeovers */ -static void __nbcon_atomic_flush_all(u64 stop_seq) +static void __nbcon_atomic_flush_all(u64 stop_seq, bool allow_unsafe_takeover) { struct nbcon_write_context wctxt = { }; struct nbcon_context *ctxt = &ACCESS_PRIVATE(&wctxt, ctxt); @@ -1054,6 +1055,7 @@ static void __nbcon_atomic_flush_all(u64 stop_seq) memset(ctxt, 0, sizeof(*ctxt)); ctxt->console = con; ctxt->spinwait_max_us = 2000; + ctxt->allow_unsafe_takeover = allow_unsafe_takeover; /* * Atomic flushing does not use console driver @@ -1088,7 +1090,19 @@ static void __nbcon_atomic_flush_all(u64 stop_seq) */ void nbcon_atomic_flush_all(void) { - __nbcon_atomic_flush_all(prb_next_reserve_seq(prb)); + __nbcon_atomic_flush_all(prb_next_reserve_seq(prb), false); +} + +/** + * nbcon_atomic_flush_unsafe - Flush all nbcon consoles using their + * write_atomic() callback and allowing unsafe hostile takeovers + * + * Flush the backlog up through the currently newest record. Unsafe hostile + * takeovers will be performed, if necessary. + */ +void nbcon_atomic_flush_unsafe(void) +{ + __nbcon_atomic_flush_all(prb_next_reserve_seq(prb), true); } /** From patchwork Sun Feb 18 18:57:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 202849 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp913036dyc; Sun, 18 Feb 2024 11:02:23 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUQrH8nZWcKnSSqQX5BUyLQUpSGtkLpdPR1H6Xx9Ba2SLXuTIEVHMxhQHINc4cEOq0srSzw2/EkO80Gu2zUWzF3wVml1A== X-Google-Smtp-Source: AGHT+IHAVH+DhaZ1Ue/LFVflvQTic1tIfg1ZB5A1MM3zIzl55jSw8GvKQmTbYMXNEkxM0vSHhcSX X-Received: by 2002:a17:906:a1d4:b0:a3b:eaa3:ecc4 with SMTP id bx20-20020a170906a1d400b00a3beaa3ecc4mr7313745ejb.60.1708282942941; Sun, 18 Feb 2024 11:02:22 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708282942; cv=pass; d=google.com; s=arc-20160816; b=vOl3IJ3wlXY/LafvYv6e/5D2y2U0jyjKN4tSlR5GJfttYGNq0y5WF7X2FW2tN5O4aS /9f3SRIm9HZkX5ZYN/IqZTpt9MT8dXI9hAoe8fHsn68Lk7N4uj6BqHi13iJpee1UmX8w uY77oemvfPXwXd2uahiXEEameprQgsseTtaPJ2dRWH5VBNwlCTIjipdu+hcgFAGf78YZ R5Ek+ypI4cV8XleJhLzWMYc2trW/7Aj+iNDQPvKvxreNgpW7AgwxRk8OC3yy48od/EIM oCSqZ1NjbsGhOKFcqDvV6Yltw0a8ne4FbBDh1hlxzbKDzo1rBkwYFQF5F7v3BtKPl0k+ rrEQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:dkim-signature:dkim-signature:from; bh=OotBUrgxQCK8IqOMKIc8OhTnB4TB5YG6MBjdk6yC3WQ=; fh=pKnPKUsir0uEGSsor+4Zc2vgbu+g+ayvUgsdzkuXaoA=; b=Q22B+TFUIP+S0v9g49C0VC5pKFtkTcGjkfoUYbWmApKZygtYVqVpkush97M90IOpG1 WeE68y1hgt7CzZ2DFKvrx6PpejrpKuq8AyyffJTHACfJhtRKn7hqId2zHrM3Q1zU+WfV 3hF1lnVTV62+ys1V+evrEQUXkq3Flto9bGg25Prmhig2BrQwU8hrHAVw+wxRfguKCNVM QH4gsK1EkoVIGyzl2uK8Jz6LFTVBmD3+r3tyYcJ5LG9VckBH12Uev2VgunLq7PCQY6iB r9BAejewgBl5G1jAcidTiFR4WZPTyJNh0datvngjf+JCgIWt4KxZkZUzGq91GTDisOJo f+mw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=mjJqDNK5; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-70513-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-70513-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id d9-20020a1709067f0900b00a3d2fe8814fsi1820166ejr.251.2024.02.18.11.02.22 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 18 Feb 2024 11:02:22 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-70513-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=mjJqDNK5; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-70513-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-70513-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 6163C1F21A28 for ; Sun, 18 Feb 2024 19:02:22 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0876376C76; Sun, 18 Feb 2024 18:58:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="mjJqDNK5"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="G5yGs3GU" 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 1572B71B38 for ; Sun, 18 Feb 2024 18:57:56 +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=1708282678; cv=none; b=bLKuVVeqPeH+SyLFZ7iixn1Fi2aSJjOnfDDReA+am4t7ENjV4mhTjLludCnCQ2bz9N2F6JZVUVwG1pa9X0B7m1WgxyrW0f+UGOGr8kvwJO3ENmZyKtnczHzmu7SuCyUoArtba77KsPCmrmhhNamYu8yh7hSN7cFkQmFaoAltAZo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708282678; c=relaxed/simple; bh=MSC0yqFA6MdNJ32n25Ewi0S5rdt3EruLjFiW5QHefOM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=EsAIrrXpXwMaGkEG76BtnDf5qim/DgOUyUuzOgMbuLTgH12frpHMMka0k4cdjKWjHYsU3UvNux9M07m+A1Wx6i+d0v8fPyuzC3Q2/uamQWzVMuW94hFOcGr7pfH+z4+tOqw6XcRKBLOF6E8w/guSyVUuq/WoGEwbUVodo3aUZaI= 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=mjJqDNK5; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=G5yGs3GU; 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 From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1708282674; 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=OotBUrgxQCK8IqOMKIc8OhTnB4TB5YG6MBjdk6yC3WQ=; b=mjJqDNK5XCubYFdP056JtAZ04KsiV7Wk86CvvOfY+crckzRYKpiugcbGviQBzTNGVrijWt 19sbo16TQj7aQihMxIbDCyl7D5xYL8/MREaX5AQ/KkizNb+2e/SGoxVXzV/jVRxgR6prmc VbT+4J8w5mbBKFXAKVV69TvNrwhJb1gSVjxXZDEvV7UyOXWEHm55fkL5FUGeJVCbzxmNpV r25ozsl7yIb3rqJdDcsxfjNgfW755XFsGsDjwBoppaz2+gOVFzGOkB51UVA3pAzjBvfXFv 6o2jgsAtAAi+6uhHzM5W5s5TCWcl5FmLtd1KzyM488ITX4sN92pcHgGXDW908g== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1708282674; 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=OotBUrgxQCK8IqOMKIc8OhTnB4TB5YG6MBjdk6yC3WQ=; b=G5yGs3GUU0mAY87B/KytgBTfHgHysjBH+QIsv42gny1YAb8pS7ureudbJ1tyjF4DHEH3xi e6D3hDWWrHtK5iCg== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org Subject: [PATCH printk v2 19/26] printk: Avoid console_lock dance if no legacy or boot consoles Date: Sun, 18 Feb 2024 20:03:19 +0106 Message-Id: <20240218185726.1994771-20-john.ogness@linutronix.de> In-Reply-To: <20240218185726.1994771-1-john.ogness@linutronix.de> References: <20240218185726.1994771-1-john.ogness@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791264494974177893 X-GMAIL-MSGID: 1791264494974177893 Currently the console lock is used to attempt legacy-type printing even if there are no legacy or boot consoles registered. If no such consoles are registered, the console lock does not need to be taken. Add tracking of legacy console registration and use it with boot console tracking to avoid unnecessary code paths, i.e. do not use the console lock if there are no boot consoles and no legacy consoles. Signed-off-by: John Ogness --- kernel/printk/internal.h | 12 ++++++++ kernel/printk/printk.c | 59 ++++++++++++++++++++++++++++++---------- 2 files changed, 56 insertions(+), 15 deletions(-) diff --git a/kernel/printk/internal.h b/kernel/printk/internal.h index 70e9a1ea75be..74181c71776f 100644 --- a/kernel/printk/internal.h +++ b/kernel/printk/internal.h @@ -44,6 +44,16 @@ enum printk_info_flags { }; extern struct printk_ringbuffer *prb; +extern bool have_legacy_console; +extern bool have_boot_console; + +/* + * Specifies if the console lock/unlock dance is needed for console + * printing. If @have_boot_console is true, the nbcon consoles will + * be printed serially along with the legacy consoles because nbcon + * consoles cannot print simultaneously with boot consoles. + */ +#define printing_via_unlock (have_legacy_console || have_boot_console) __printf(4, 0) int vprintk_store(int facility, int level, @@ -123,6 +133,8 @@ static inline bool console_is_usable(struct console *con, short flags) #define PRINTK_MESSAGE_MAX 0 #define PRINTKRB_RECORD_MAX 0 +#define printing_via_unlock (false) + /* * In !PRINTK builds we still export console_sem * semaphore and some of console functions (console_unlock()/etc.), so diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index d91771fb306e..336dad179b99 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -463,6 +463,13 @@ static int console_msg_format = MSG_FORMAT_DEFAULT; /* syslog_lock protects syslog_* variables and write access to clear_seq. */ static DEFINE_MUTEX(syslog_lock); +/* + * Specifies if a legacy console is registered. If legacy consoles are + * present, it is necessary to perform the console_lock/console_unlock dance + * whenever console flushing should occur. + */ +bool have_legacy_console; + /* * Specifies if a boot console is registered. If boot consoles are present, * nbcon consoles cannot print simultaneously and must be synchronized by @@ -2344,7 +2351,7 @@ asmlinkage int vprintk_emit(int facility, int level, printed_len = vprintk_store(facility, level, dev_info, fmt, args); /* If called from the scheduler, we can not call up(). */ - if (!in_sched) { + if (!in_sched && printing_via_unlock) { /* * The caller may be holding system-critical or * timing-sensitive locks. Disable preemption during @@ -2645,7 +2652,7 @@ void resume_console(void) */ static int console_cpu_notify(unsigned int cpu) { - if (!cpuhp_tasks_frozen) { + if (!cpuhp_tasks_frozen && printing_via_unlock) { /* If trylock fails, someone else is doing the printing */ if (console_trylock()) console_unlock(); @@ -3188,7 +3195,8 @@ void console_flush_on_panic(enum con_flush_mode mode) nbcon_atomic_flush_all(); - console_flush_all(false, &next_seq, &handover); + if (printing_via_unlock) + console_flush_all(false, &next_seq, &handover); } /* @@ -3513,8 +3521,11 @@ void register_console(struct console *newcon) newcon->dropped = 0; console_init_seq(newcon, bootcon_registered); - if (newcon->flags & CON_NBCON) + if (newcon->flags & CON_NBCON) { nbcon_init(newcon); + } else { + have_legacy_console = true; + } if (newcon->flags & CON_BOOT) have_boot_console = true; @@ -3571,6 +3582,7 @@ EXPORT_SYMBOL(register_console); /* Must be called under console_list_lock(). */ static int unregister_console_locked(struct console *console) { + bool found_legacy_con = false; bool found_boot_con = false; struct console *c; int res; @@ -3627,9 +3639,13 @@ static int unregister_console_locked(struct console *console) for_each_console(c) { if (c->flags & CON_BOOT) found_boot_con = true; + if (!(c->flags & CON_NBCON)) + found_legacy_con = true; } if (!found_boot_con) have_boot_console = false; + if (!found_legacy_con) + have_legacy_console = false; return res; } @@ -3781,6 +3797,7 @@ static bool __pr_flush(struct console *con, int timeout_ms, bool reset_on_progre u64 last_diff = 0; u64 printk_seq; short flags; + bool locked; int cookie; u64 diff; u64 seq; @@ -3790,22 +3807,28 @@ static bool __pr_flush(struct console *con, int timeout_ms, bool reset_on_progre seq = prb_next_reserve_seq(prb); /* Flush the consoles so that records up to @seq are printed. */ - console_lock(); - console_unlock(); + if (printing_via_unlock) { + console_lock(); + console_unlock(); + } for (;;) { unsigned long begin_jiffies; unsigned long slept_jiffies; + locked = false; diff = 0; - /* - * Hold the console_lock to guarantee safe access to - * console->seq. Releasing console_lock flushes more - * records in case @seq is still not printed on all - * usable consoles. - */ - console_lock(); + if (printing_via_unlock) { + /* + * Hold the console_lock to guarantee safe access to + * console->seq. Releasing console_lock flushes more + * records in case @seq is still not printed on all + * usable consoles. + */ + console_lock(); + locked = true; + } cookie = console_srcu_read_lock(); for_each_console_srcu(c) { @@ -3825,6 +3848,7 @@ static bool __pr_flush(struct console *con, int timeout_ms, bool reset_on_progre if (flags & CON_NBCON) { printk_seq = nbcon_seq_read(c); } else { + WARN_ON_ONCE(!locked); printk_seq = c->seq; } @@ -3836,7 +3860,8 @@ static bool __pr_flush(struct console *con, int timeout_ms, bool reset_on_progre if (diff != last_diff && reset_on_progress) remaining_jiffies = timeout_jiffies; - console_unlock(); + if (locked) + console_unlock(); /* Note: @diff is 0 if there are no usable consoles. */ if (diff == 0 || remaining_jiffies == 0) @@ -3958,7 +3983,11 @@ 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); + int val = PRINTK_PENDING_WAKEUP; + + if (printing_via_unlock) + val |= PRINTK_PENDING_OUTPUT; + __wake_up_klogd(val); } void printk_trigger_flush(void) From patchwork Sun Feb 18 18:57:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 202848 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp912682dyc; Sun, 18 Feb 2024 11:01:48 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXMNi4GW4bQIVuhRAw7hqx1bXVGpmnauLDWRiytbOKwdrJLOJ8OD+Njl7Hc6E9YOJpwtx+xYIEGnt7Rz7BQt9QXoFRuig== X-Google-Smtp-Source: AGHT+IFh5Vm21LgFubVuWjFoHUMl4vYGbS8cGX3/8M8BZYoi8QG5hJeegvucRwo0TD8i7s6V7lxe X-Received: by 2002:a17:906:4a10:b0:a3e:8bd8:b711 with SMTP id w16-20020a1709064a1000b00a3e8bd8b711mr823353eju.37.1708282908203; Sun, 18 Feb 2024 11:01:48 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708282908; cv=pass; d=google.com; s=arc-20160816; b=QyEo7LtJq4Yn2uH76xveM2U2oA8bQqC/X+jfCyFegCkz3NYsWttiwO4gKT2BJBqKGa DAVKI+BMcrkRMr1bDQ4E5BSShAdLqjqd3E3nl78MCtTmck1PunpwCRG+eWfgSR7gCS/2 N2PztAaGP5MKdmMOlVlZ8x8G6mgl/SS7Wyoaxt3oc3KWnd7s832BfbSogMwcondZwrtK fbnbUmQOj4pVsnXRfswGlic3biEhZxydxgCoBrkp4pA0+xZnM+aMBDdnmNW1nyKtXOU5 gnthNhzhLSlAny9bL2jGwHkNRYzytWqqZo0vXcBi0t5uFHjBRAQtTuJ5g1w0YlwUy143 gHrw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:dkim-signature:dkim-signature:from; bh=5fJ6yqWdSDvmc7d434BHASreaek3tLpIi1BkLTUqxi8=; fh=pKnPKUsir0uEGSsor+4Zc2vgbu+g+ayvUgsdzkuXaoA=; b=aALzvLiynOp9y7MZXATBpo290Zc+/KXCv+vaAKUFtA+Kuwd6R6lsX76kfpG814xShn fa+fHlOctgT6+Kd5MoYD5XvCI3JKnL0VtBAn2860lF/vnmq9vfPhbJDXN1aDjYE69AxR 9xezVstXgpn3gJW9XfEzHNyKlfQlfxmlng+r1Chgdt96ZuHfPuBGDLVDVK1hDR7pQTHU sqcPJ8reNNmutGQ4YKm6lgboKGqhzSlkrjGKnC2zVG+qjxPRClkHKraBhfO+Sv5Ec6v2 RDkbt6C0n5a/n3ouSru0yVP1Bwiu/aJJXrPnoBIBVk3CdeBg6PU4ksMX2Nq483uV5cG4 T33g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=kipOVu39; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-70512-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-70512-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id g16-20020a1709067c5000b00a3e69ff13bdsi736103ejp.854.2024.02.18.11.01.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 18 Feb 2024 11:01:48 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-70512-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=kipOVu39; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-70512-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-70512-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 9ECE41F21097 for ; Sun, 18 Feb 2024 19:01:47 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E9303768E5; Sun, 18 Feb 2024 18:58:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="kipOVu39"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="zcuQRKgf" 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 53A3371B45 for ; Sun, 18 Feb 2024 18:57:56 +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=1708282678; cv=none; b=Bg/vGaOrKCNhSMJ2HEMBNBcVoKU6OpMxpmcc+diADPFoN/4om3Wbh7NhiJsd/n50Kmgrkb0gEL5uUWCP021BM9kY0QoJO/gqwIhIrk+ldpMVPB7TzQTGA3b4tyYPEwVDdvbCynKj5/wctxvUXAJZ/66z0uTGEHn+ZojTKFwEKIc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708282678; c=relaxed/simple; bh=QdXwnt6+PhX0aD+AlOZp4u+/7nviebzBO5H0/vlodlw=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Oslzbae/biHzS/wfmzj74Fj8vOEaCia7Thx97rh2mEVhNKp3y1gdo7c7/hVAKF5zT47thNzWKYKIXAYQcSycRp34BNIVaykEBp//W0l2IcfY1TCJW1/wH66ZmmP1fwwy/YZ4dyNjmZ52IwNGglkEz4cQTNJZOQI+xqVPydW4cMk= 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=kipOVu39; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=zcuQRKgf; 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 From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1708282674; 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=5fJ6yqWdSDvmc7d434BHASreaek3tLpIi1BkLTUqxi8=; b=kipOVu39ofseUoqPTQoCnM23+6kBri5ZY2eBYwv/o+FNAIZUzfw4DtLwp8jDymOfwfi2Pe 4hma6CyBwf2rY4nROH7z1tKEDIcig9XMyk0V+3kCWjCIev9z7q94K6jKZEwgEmANmkgtQ0 bS/5Lwdwmv2ns+NDsy19ux3NkvtqWruYfwTMeQjERAbsIcJigtdYrR0Y4hkaiA3YjLIUsO DUJlz+LqYzQ/w3nKk53Hx1EoymeoDaYPowaeN/AJn1sJwzWPYuKlX5k+OChheaPDPp6VLV 3SHQCtyqROdOxNvNM5LBsbIUXqd54/bZq1/bqjvyzP+MWwhrSn66ePh15T16OA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1708282674; 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=5fJ6yqWdSDvmc7d434BHASreaek3tLpIi1BkLTUqxi8=; b=zcuQRKgfxpNNB2OuJJiAlo1opLefEjxr6MexZJu4AsBTFQoMR2c3u1HnqC6qtG9R/LOa+M kOMUfgdZJyWjKTAQ== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org Subject: [PATCH printk v2 20/26] printk: Track nbcon consoles Date: Sun, 18 Feb 2024 20:03:20 +0106 Message-Id: <20240218185726.1994771-21-john.ogness@linutronix.de> In-Reply-To: <20240218185726.1994771-1-john.ogness@linutronix.de> References: <20240218185726.1994771-1-john.ogness@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791264458752703329 X-GMAIL-MSGID: 1791264458752703329 Add a global flag @have_nbcon_console to identify if any nbcon consoles are registered. This will be used in follow-up commits to preserve legacy behavior when no nbcon consoles are registered. Signed-off-by: John Ogness Reviewed-by: Petr Mladek --- kernel/printk/printk.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index 336dad179b99..2c4ab717c110 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -470,6 +470,13 @@ static DEFINE_MUTEX(syslog_lock); */ bool have_legacy_console; +/* + * Specifies if an nbcon console is registered. If nbcon consoles are present, + * synchronous printing of legacy consoles will not occur during panic until + * the backtrace has been stored to the ringbuffer. + */ +static bool have_nbcon_console; + /* * Specifies if a boot console is registered. If boot consoles are present, * nbcon consoles cannot print simultaneously and must be synchronized by @@ -3522,6 +3529,7 @@ void register_console(struct console *newcon) console_init_seq(newcon, bootcon_registered); if (newcon->flags & CON_NBCON) { + have_nbcon_console = true; nbcon_init(newcon); } else { have_legacy_console = true; @@ -3583,6 +3591,7 @@ EXPORT_SYMBOL(register_console); static int unregister_console_locked(struct console *console) { bool found_legacy_con = false; + bool found_nbcon_con = false; bool found_boot_con = false; struct console *c; int res; @@ -3639,13 +3648,18 @@ static int unregister_console_locked(struct console *console) for_each_console(c) { if (c->flags & CON_BOOT) found_boot_con = true; - if (!(c->flags & CON_NBCON)) + + if (c->flags & CON_NBCON) + found_nbcon_con = true; + else found_legacy_con = true; } if (!found_boot_con) have_boot_console = false; if (!found_legacy_con) have_legacy_console = false; + if (!found_nbcon_con) + have_nbcon_console = false; return res; } From patchwork Sun Feb 18 18:57:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 202854 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp913279dyc; Sun, 18 Feb 2024 11:02:47 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUPzN/NW9m1FuVeZpdTzFcUWzUe75qEef39P/mLrj53rk/SVDiR/U3VWVKZjPoITtV1Zph3An8JcA6gvcxOF2HB4eBnJQ== X-Google-Smtp-Source: AGHT+IHDQAVmdA3jlj5DIXdNNoEG9vHdyj4bjcjJrMNObd04g1PudUcFN12ZEcr40wI4zQPljo/v X-Received: by 2002:a05:6402:2051:b0:564:41a5:b976 with SMTP id bc17-20020a056402205100b0056441a5b976mr1777756edb.10.1708282966884; Sun, 18 Feb 2024 11:02:46 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708282966; cv=pass; d=google.com; s=arc-20160816; b=W/j+KhU4Ndhv0zy/j6ccSxUtmEALlL0gyVF87I85/BID5un1oApldu6g4JBauFSJ4K AK1dWx5omf6+793De1xsiJbKa9JQDIXos5/me2hGzZpzb6hebayT7zyBDxCQQZCA6h+5 uKkUbmufAxgphCAQZuUF3bJ1EGGTI59fgBA0e889rZnmSEfoe8XRwMkYTTOMFbV5nEFd 50FtYTDatHoNCLKno/NcoZDICbP79KTTFPTLRPh7j3tf6n4GSrWOPulStg2tG1+ciw6E HPcmqSd1d3JbF1i8DIFzz6zmP5vOynQqAKOt+R7lLwP8UZiMePNjFPdY9+AFE/PxmN3S 3DiQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:dkim-signature:dkim-signature:from; bh=gPQBcPF1TwjA3+5rOjGCeC1igurDrs1roxu0N8F4XyM=; fh=+yDMW7z2YTzd5MLGkAWGqbGBg6o8yp6ZPnyDOkf7LF8=; b=jTDLkLWy/KGFxFR52vfQ5Mlhpd83PVGk2mkuGXZdPjS/h0TNjI97XqjjtF8lTzxziD Xmt0mcWuaW9fg3/HIgnvJZemp0ZIuodiRE+bBhQmzfLcvglfHcMjJgb/huhpilM1OSpl d44n2euhj/Vz3v7fU7REIq4o7E6TrqulqjoMDp1c1kiex01nwBG9JF4WqbHbI5VWLZRk gYpzmzyA/5mM1gVDm4EXyizOoBwZuTIlteMUkPJnc1FWIqUwDI/uS61wNwsYtcbSnRaA ru7d9XLwH1DL3JEdZAAmuS7cgf4d1kPl6fuFr7dbtJeyaCSflIZWaiDRGkUjpZwzzaTI KmPA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=Lh2fhBGX; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-70518-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-70518-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id l25-20020aa7d959000000b005643b74ad91si1091893eds.483.2024.02.18.11.02.46 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 18 Feb 2024 11:02:46 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-70518-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=Lh2fhBGX; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-70518-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-70518-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 5B8981F21175 for ; Sun, 18 Feb 2024 19:02:46 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1B2C376C96; Sun, 18 Feb 2024 18:58:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="Lh2fhBGX"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="JfHPw2o3" 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 38E0D73168 for ; Sun, 18 Feb 2024 18:57:56 +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=1708282680; cv=none; b=PcMyacDuDXGNX3b/yePeBt4YduGU8jL9B5PEKlrlTdL9/Jld22cEESEg+25QeZOmE7zHR3EKtUSzB7wwple5E0J3Bp3lGAnqaTDeHNC9Q48lMwDULzCsMSd0K85gPafeGSVj0CS/jrugISUzWUHxvW5j0ghOYceOFms+gN68fa8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708282680; c=relaxed/simple; bh=pfK9qq9Tq8FSQB42rxPrvRkgcIJuLdvvsicEAYeKWHY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=owuA/VnO8X1PE/Qtt9I38T0bSGEzxI1lhFJU8ejO7uRmDRqbJhJYYLvtjlT7WM9TC/RcaPAyoQV/OMv+xEw/A457hnLggxwoQavOCXLwWYBDiHqeLjRwZmkEhHzWcagu3Pzdeh85cX4dakcmGJ8eto3rM/Ka1OqHY9zWNz860Dk= 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=Lh2fhBGX; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=JfHPw2o3; 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 From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1708282675; 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=gPQBcPF1TwjA3+5rOjGCeC1igurDrs1roxu0N8F4XyM=; b=Lh2fhBGXPEgFw0mxMWnVOm8TVECrZ8oSZeW1DqPuvyLg1K6EOxJ1YltQR3GFeVffPmLeEz UJsPBSJjeoYDTAOwY3CAQ7VT1dppthLr3OfLwstrC22Wk7QYtL5fulgWq93PIyyJSdvocr vNG6MNRG8TjgMqNiVuVLYAc4uHTirPbRvwCF/Kep93cVgxH5x62PiwBzGqV+KsZJFr/F1t tTOn2DCCr0uVyohozvfp7oV9IiHgSKuPM/t4FEkO0HORUloe3kWwEo5814T2Z5xIN4QFeK k85YZxNRhU5XYFWCWBavSCSwyz9TBgoy77P/3Htcopis1b4HlDOiG9TEhpLe+Q== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1708282675; 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=gPQBcPF1TwjA3+5rOjGCeC1igurDrs1roxu0N8F4XyM=; b=JfHPw2o3dPQ75TjOWAnNmUeoHWZOYo4xQfB2ra+PsaPjxjR4/cXbQzuej3vXFNHdr0KSDB ciyVw65Fm4ESxhBg== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org, Andrew Morton , Josh Poimboeuf , "Peter Zijlstra (Intel)" , Uros Bizjak , "Guilherme G. Piccoli" , Kefeng Wang , Arnd Bergmann Subject: [PATCH printk v2 21/26] printk: Coordinate direct printing in panic Date: Sun, 18 Feb 2024 20:03:21 +0106 Message-Id: <20240218185726.1994771-22-john.ogness@linutronix.de> In-Reply-To: <20240218185726.1994771-1-john.ogness@linutronix.de> References: <20240218185726.1994771-1-john.ogness@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791264520319508568 X-GMAIL-MSGID: 1791264520319508568 Perform printing by nbcon consoles on the panic CPU from the printk() caller context in order to get panic messages printed as soon as possible. If legacy and nbcon consoles are registered, the legacy consoles will no longer perform direct printing on the panic CPU until after the backtrace has been stored. This will give the safe nbcon consoles a chance to print the panic messages before allowing the unsafe legacy consoles to print. If no nbcon consoles are registered, there is no change in behavior (i.e. legacy consoles will always attempt to print from the printk() caller context). Signed-off-by: John Ogness --- include/linux/printk.h | 5 ++++ kernel/panic.c | 2 ++ kernel/printk/printk.c | 53 ++++++++++++++++++++++++++++++++++++------ 3 files changed, 53 insertions(+), 7 deletions(-) diff --git a/include/linux/printk.h b/include/linux/printk.h index fe37395af9e2..a2d40a637226 100644 --- a/include/linux/printk.h +++ b/include/linux/printk.h @@ -197,6 +197,7 @@ void show_regs_print_info(const char *log_lvl); extern asmlinkage void dump_stack_lvl(const char *log_lvl) __cold; extern asmlinkage void dump_stack(void) __cold; void printk_trigger_flush(void); +void printk_legacy_allow_panic_sync(void); extern void uart_nbcon_acquire(struct uart_port *up); extern void uart_nbcon_release(struct uart_port *up); void nbcon_atomic_flush_unsafe(void); @@ -280,6 +281,10 @@ static inline void printk_trigger_flush(void) { } +static inline void printk_legacy_allow_panic_sync(void) +{ +} + static inline void uart_nbcon_acquire(struct uart_port *up) { } diff --git a/kernel/panic.c b/kernel/panic.c index c039f8e1ddae..86813305510f 100644 --- a/kernel/panic.c +++ b/kernel/panic.c @@ -370,6 +370,8 @@ void panic(const char *fmt, ...) */ atomic_notifier_call_chain(&panic_notifier_list, 0, buf); + printk_legacy_allow_panic_sync(); + panic_print_sys_info(false); kmsg_dump(KMSG_DUMP_PANIC); diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index 2c4ab717c110..109cfdd988aa 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -2329,12 +2329,23 @@ int vprintk_store(int facility, int level, return ret; } +static bool legacy_allow_panic_sync; + +/* + * This acts as a one-way switch to allow legacy consoles to print from + * the printk() caller context on a panic CPU. + */ +void printk_legacy_allow_panic_sync(void) +{ + legacy_allow_panic_sync = true; +} + asmlinkage int vprintk_emit(int facility, int level, const struct dev_printk_info *dev_info, const char *fmt, va_list args) { + bool do_trylock_unlock = printing_via_unlock; int printed_len; - bool in_sched = false; /* Suppress unimportant messages after panic happens */ if (unlikely(suppress_printk)) @@ -2350,15 +2361,43 @@ asmlinkage int vprintk_emit(int facility, int level, if (level == LOGLEVEL_SCHED) { level = LOGLEVEL_DEFAULT; - in_sched = true; + /* If called from the scheduler, we can not call up(). */ + do_trylock_unlock = false; } printk_delay(level); printed_len = vprintk_store(facility, level, dev_info, fmt, args); - /* If called from the scheduler, we can not call up(). */ - if (!in_sched && printing_via_unlock) { + if (!have_boot_console && have_nbcon_console) { + bool is_panic_context = this_cpu_in_panic(); + + /* + * In panic, the legacy consoles are not allowed to print from + * the printk calling context unless explicitly allowed. This + * gives the safe nbcon consoles a chance to print out all the + * panic messages first. This restriction only applies if + * there are nbcon consoles registered. + */ + if (is_panic_context) + do_trylock_unlock &= legacy_allow_panic_sync; + + /* + * There are situations where nbcon atomic printing should + * happen in the printk() caller context: + * + * - When this CPU is in panic. + * + * Note that if boot consoles are registered, the + * console_lock/console_unlock dance must be relied upon + * instead because nbcon consoles cannot print simultaneously + * with boot consoles. + */ + if (is_panic_context) + nbcon_atomic_flush_all(); + } + + if (do_trylock_unlock) { /* * The caller may be holding system-critical or * timing-sensitive locks. Disable preemption during @@ -2378,10 +2417,10 @@ asmlinkage int vprintk_emit(int facility, int level, preempt_enable(); } - if (in_sched) - defer_console_output(); - else + if (do_trylock_unlock) wake_up_klogd(); + else + defer_console_output(); return printed_len; } From patchwork Sun Feb 18 18:57:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 202856 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp913293dyc; Sun, 18 Feb 2024 11:02:48 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVpvbTBBY6ufDXy8hNR8wUTM33+EcVTfSl1m9LrWQaLQ/z37GtoKAcX4VGXshKMkbPOG+bJoGca39EIMNPE3kOA3QKVYQ== X-Google-Smtp-Source: AGHT+IEIqdAFWTYr8oZnQ/SXFYZmtEI1XEk+TgZ/ysgU6mpGraL3JnvvNJvB32Hcv82HeB5LmTxU X-Received: by 2002:a05:6512:2037:b0:512:86fa:a427 with SMTP id s23-20020a056512203700b0051286faa427mr5898557lfs.9.1708282968238; Sun, 18 Feb 2024 11:02:48 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708282968; cv=pass; d=google.com; s=arc-20160816; b=ruFNga5fTvoPVK+DIa92vKL1ny0CT7IUhF0ykS1s7dLOofodr0OWr9IvRti8T4RUAw 2sTmroSbjavwTtvElhDjL3NR2lO9PgIHq4A1oKr6ajmzOQRHeo5E3n0acaAy2jAOoZ+K U4/BCcVdW0RoLJIYhmERzjdn44am2MKvJjpa3tVMZIS0N+aPZZ2utcVWcTt87Xn6Hzzj ++CGUZ0PizA2/ZdeXJ06yPBbu7Q4kfEFLvxegdQVcHVt20PG8jxlvKV4scNuElVYLEXr NsPbA5nC+3SwMPQRQD5OJ+l0DQq4G1zj/EjVKlr89KRNkUUiLPrxSzGaYf5Q3QSoBWaY GCEg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:dkim-signature:dkim-signature:from; bh=chNxmh0c/kNKxyDg+4LUMVdYUn+cMPiAIaQ2mbvqe3U=; fh=/NZX815RJy/ecOe1WbZ023sSZUJKZnpaeIZwQG5Ym7U=; b=Xh4LHx4x2c5qVfUsjfE1hlaZQ+1fRn5TO3trAfnfAMbdVryNHarABSbbm3wFLg5Iyf V5hoJZD/h+O2dkyMqIpf4QeKJqI/0o0ZrKASwgLKU8DWENz5pMM/WcpatJw4sV3ERsSx W9tbvhHgEYC73j33QD3Cwc4h0H2J0q+gc0WzLcLyMMgJBzY7njg0DQmxEXqkYjxx2bep z/5P15YIDGUoWUV5Dfo23MFn/xljz6DZp6sjzKIe3oFwu9h/kXBMkkY2ETe0sBWKHqK2 NePGsBUZPLTjBukCDK3ehoD/jkz0oyK1WpM7hqqSsGrrUWBdrIotzoJl+FnIjBDd9dDA R0WA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=Xc6CwIuS; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-70515-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-70515-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id g16-20020a1709067c5000b00a3e69ff13bdsi736103ejp.854.2024.02.18.11.02.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 18 Feb 2024 11:02:48 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-70515-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=Xc6CwIuS; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-70515-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-70515-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id AA6CB1F217A3 for ; Sun, 18 Feb 2024 19:02:47 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3BAF66F515; Sun, 18 Feb 2024 18:58:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="Xc6CwIuS"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="6uoS2Ttx" 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 1A51A73163 for ; Sun, 18 Feb 2024 18:57:57 +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=1708282679; cv=none; b=hOM2HIW6AwfQBPw6d3+4vJffe1XqCRfUeiwlcpN6L+9c5jFg1jaHqOKhsDVIp+OatbV6Z9R/1FBb+qR1pGfIX9gHZO/xBFE+n2uCNGpcd7ui6Q+gmwFKPcLMkNgIoJK/k/dE9Gm5WPIt5DYLvySPJMrbPMr+/qOXA4+PWZP/zu0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708282679; c=relaxed/simple; bh=e7GbIKGogj5AP6ontVh7TIYkL2C0F+okj8XJlpL+1uE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=NijXI4qtPuYeZIgLtkCbodndp3LIf1bf34QvzTLzpC6a6jKqyiTXOASDnLlp/zaI1s3B995pMw8dfPCpIPBPmP1qgNMYGVtL1+mh04n7bIJnIu5L1mPZXIdvFgs0p7HcE65W5xqSA9zsI64LSVJXH+FXDrR2ERoat13voRWP0tk= 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=Xc6CwIuS; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=6uoS2Ttx; 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 From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1708282675; 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=chNxmh0c/kNKxyDg+4LUMVdYUn+cMPiAIaQ2mbvqe3U=; b=Xc6CwIuSRTv33zta/xRJXtT995IlWZr+PW3IHK3NmPPkzQRlqeczv9xIUVQHzHdt6zWkck j+eSKHmhgiC3U2ixwJV/dsAGrvFq3Y61E+pqtbjUdQ/o6PKcyKo8034xNb7Ws8U0oqBitM BTfQnrNH4ZsVwVAJcyBuQsjk5TPpVz4UtVIv6r237wSB4l9sLvm/ojK414w0fk7vShQIho l3+O+D7tg7DgL7lZrpNwq24wY64WYt8NLSFYADeurj8xqiI281FQBmJn8KooIFhn3f1vX3 Undq8eHZ62YqCnIWv1lwALk/wrFHR0ci5e6ZNSiNwie7h9hzHAeidLYfk9jrCg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1708282675; 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=chNxmh0c/kNKxyDg+4LUMVdYUn+cMPiAIaQ2mbvqe3U=; b=6uoS2TtxoVJ82xFQcHORU233rpeZS6laROejmkz/b3nXsD/uFUQPj7lJrTjRfxK5DSLrtW ULed0kxJ4VUf8XDQ== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org, Greg Kroah-Hartman Subject: [PATCH printk v2 22/26] printk: nbcon: Implement emergency sections Date: Sun, 18 Feb 2024 20:03:22 +0106 Message-Id: <20240218185726.1994771-23-john.ogness@linutronix.de> In-Reply-To: <20240218185726.1994771-1-john.ogness@linutronix.de> References: <20240218185726.1994771-1-john.ogness@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791264521643163229 X-GMAIL-MSGID: 1791264521643163229 From: Thomas Gleixner In emergency situations (something has gone wrong but the system continues to operate), usually important information (such as a backtrace) is generated via printk(). Each individual printk record has little meaning. It is the collection of printk messages that is most often needed by developers and users. In order to help ensure that the collection of printk messages in an emergency situation are all stored to the ringbuffer as quickly as possible, disable console output for that CPU while it is in the emergency situation. When exiting the emergency situation, trigger the consoles to be flushed. Add per-CPU emergency nesting tracking because an emergency can arise while in an emergency situation. Add functions to mark the beginning and end of emergency sections where the urgent messages are generated. Do not print if the current CPU is in an emergency state. Trigger console flushing when exiting all emergency nesting. Note that the emergency state is not system-wide. While one CPU is in an emergency state, another CPU may continue to print console messages. Co-developed-by: John Ogness Signed-off-by: John Ogness Signed-off-by: Thomas Gleixner (Intel) --- include/linux/console.h | 4 ++ kernel/printk/nbcon.c | 81 +++++++++++++++++++++++++++++++++++++++++ kernel/printk/printk.c | 25 ++++++++++--- 3 files changed, 104 insertions(+), 6 deletions(-) diff --git a/include/linux/console.h b/include/linux/console.h index d8922282efa1..b1c870898181 100644 --- a/include/linux/console.h +++ b/include/linux/console.h @@ -478,10 +478,14 @@ static inline bool console_is_registered(const struct console *con) hlist_for_each_entry(con, &console_list, node) #ifdef CONFIG_PRINTK +extern void nbcon_cpu_emergency_enter(void); +extern void nbcon_cpu_emergency_exit(void); extern bool nbcon_can_proceed(struct nbcon_write_context *wctxt); extern bool nbcon_enter_unsafe(struct nbcon_write_context *wctxt); extern bool nbcon_exit_unsafe(struct nbcon_write_context *wctxt); #else +static inline void nbcon_cpu_emergency_enter(void) { } +static inline void nbcon_cpu_emergency_exit(void) { } static inline bool nbcon_can_proceed(struct nbcon_write_context *wctxt) { return false; } static inline bool nbcon_enter_unsafe(struct nbcon_write_context *wctxt) { return false; } static inline bool nbcon_exit_unsafe(struct nbcon_write_context *wctxt) { return false; } diff --git a/kernel/printk/nbcon.c b/kernel/printk/nbcon.c index 64dedd79e880..ce556c1f4dc5 100644 --- a/kernel/printk/nbcon.c +++ b/kernel/printk/nbcon.c @@ -929,6 +929,29 @@ static bool nbcon_emit_next_record(struct nbcon_write_context *wctxt) return nbcon_context_exit_unsafe(ctxt); } +/* Track the nbcon emergency nesting per CPU. */ +static DEFINE_PER_CPU(unsigned int, nbcon_pcpu_emergency_nesting); +static unsigned int early_nbcon_pcpu_emergency_nesting __initdata; + +/** + * nbcon_get_cpu_emergency_nesting - Get the per CPU emergency nesting pointer + * + * Return: Either a pointer to the per CPU emergency nesting counter of + * the current CPU or to the init data during early boot. + */ +static __ref unsigned int *nbcon_get_cpu_emergency_nesting(void) +{ + /* + * The value of __printk_percpu_data_ready gets set in normal + * context and before SMP initialization. As a result it could + * never change while inside an nbcon emergency section. + */ + if (!printk_percpu_data_ready()) + return &early_nbcon_pcpu_emergency_nesting; + + return this_cpu_ptr(&nbcon_pcpu_emergency_nesting); +} + /** * nbcon_atomic_emit_one - Print one record for an nbcon console using the * write_atomic() callback @@ -971,9 +994,15 @@ static bool nbcon_atomic_emit_one(struct nbcon_write_context *wctxt) */ enum nbcon_prio nbcon_get_default_prio(void) { + unsigned int *cpu_emergency_nesting; + if (this_cpu_in_panic()) return NBCON_PRIO_PANIC; + cpu_emergency_nesting = nbcon_get_cpu_emergency_nesting(); + if (*cpu_emergency_nesting) + return NBCON_PRIO_EMERGENCY; + return NBCON_PRIO_NORMAL; } @@ -1105,6 +1134,58 @@ void nbcon_atomic_flush_unsafe(void) __nbcon_atomic_flush_all(prb_next_reserve_seq(prb), true); } +/** + * nbcon_cpu_emergency_enter - Enter an emergency section where printk() + * messages for that CPU are only stored + * + * Upon exiting the emergency section, all stored messages are flushed. + * + * Context: Any context. Disables preemption. + * + * When within an emergency section, no printing occurs on that CPU. This + * is to allow all emergency messages to be dumped into the ringbuffer before + * flushing the ringbuffer. The actual printing occurs when exiting the + * outermost emergency section. + */ +void nbcon_cpu_emergency_enter(void) +{ + unsigned int *cpu_emergency_nesting; + + preempt_disable(); + + cpu_emergency_nesting = nbcon_get_cpu_emergency_nesting(); + (*cpu_emergency_nesting)++; +} + +/** + * nbcon_cpu_emergency_exit - Exit an emergency section and flush the + * stored messages + * + * Flushing only occurs when exiting all nesting for the CPU. + * + * Context: Any context. Enables preemption. + */ +void nbcon_cpu_emergency_exit(void) +{ + unsigned int *cpu_emergency_nesting; + bool do_trigger_flush = false; + + cpu_emergency_nesting = nbcon_get_cpu_emergency_nesting(); + + WARN_ON_ONCE(*cpu_emergency_nesting == 0); + + if (*cpu_emergency_nesting == 1) + do_trigger_flush = true; + + /* Undo the nesting count of nbcon_cpu_emergency_enter(). */ + (*cpu_emergency_nesting)--; + + preempt_enable(); + + if (do_trigger_flush) + printk_trigger_flush(); +} + /** * nbcon_alloc - Allocate buffers needed by the nbcon console * @con: Console to allocate buffers for diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index 109cfdd988aa..c8ad2b6ffe63 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -2404,16 +2404,29 @@ asmlinkage int vprintk_emit(int facility, int level, * printing of all remaining records to all consoles so that * this context can return as soon as possible. Hopefully * another printk() caller will take over the printing. + * + * Also, nbcon_get_default_prio() requires migration disabled. */ preempt_disable(); + /* - * Try to acquire and then immediately release the console - * semaphore. The release will print out buffers. With the - * spinning variant, this context tries to take over the - * printing from another printing context. + * Do not emit for EMERGENCY priority. The console will be + * explicitly flushed when exiting the emergency section. */ - if (console_trylock_spinning()) - console_unlock(); + if (nbcon_get_default_prio() == NBCON_PRIO_EMERGENCY) { + do_trylock_unlock = false; + } else { + /* + * Try to acquire and then immediately release the + * console semaphore. The release will print out + * buffers. With the spinning variant, this context + * tries to take over the printing from another + * printing context. + */ + if (console_trylock_spinning()) + console_unlock(); + } + preempt_enable(); } From patchwork Sun Feb 18 18:57:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 202855 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp913295dyc; Sun, 18 Feb 2024 11:02:48 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVXwwY1iTsUM9omMAjoEk9313NXRzw2WzMRqHc4NzToOlE8zv9rexAyKNij6Cvrx0CZRyLvTg1Z4FOAay8WOO6mOtTgIA== X-Google-Smtp-Source: AGHT+IFhcHT3xFW76HVYLDO07++M2+GA9WGHq+it9DXAO10zuRu5ACL8PII4sw4NlqFFGf6VkcBu X-Received: by 2002:a05:6a20:94c6:b0:19e:8866:9e56 with SMTP id ht6-20020a056a2094c600b0019e88669e56mr19727906pzb.11.1708282968363; Sun, 18 Feb 2024 11:02:48 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708282968; cv=pass; d=google.com; s=arc-20160816; b=0M9juBWlqehuXP8ZEaW4Z+dP74q/cb6kDRhSUPkK7DPpb4T8sgJ3zfWGw+wZTsHojK G+vFUK6/m7q8GPAYKGHKMm3Ku8yuXMLYDqXOk7wN0jKrlqQXVj9gJ51+Vp6AbAn2mwaj DPmRbRinywv5nzmDRWghSvk4Y1XNvit0S6cGqr+6AojfH47pgGeXjkFuxvJJSendbrVq VeVCSrFc01AjJg95bVYPLxxqE6tRnm2466GZvfHOs3/y4o/spRDePcCp3CYoG/oxxQUo 8+hyvBT1tA+KgyJm58A9uRKJdlr3w/FXmKJ5amfUE2tGqCasY3ccdQPEU/pbeDk1GEku HJCQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:dkim-signature:dkim-signature:from; bh=GUbvpoY1vkrIaf4t1+bOO9YGAlSrhJitnWRmUehFKmc=; fh=HcERdsKYkHJGsPxhUapFKZrjBQucHLNy3P6fbmo6vhw=; b=WNc6krjmE3vFvRiY3UvQ+dSI9JQKcpWjoFlBZQ5piCuP8yYSNyqSb2mnZh6FmTAmiz v6Tm6ELj1SOagXjz/L77vMi3ovnJQS96KszHcoSuxXRMHGB2ZqqdIHCIn4bQ10NdeggU yYff1CvfOoSYZuFpzTcLf2BLZ4rxC8tMF7KwIpYMSbLYA0qBzS4uTmdRebMoGbQLSo+n X6s3dz9z8zCSAJlhFnBw3NvfKWI9J5JlZmfg6udT/MRr8CwFuiQcnMPWPQwwrMkR2tXl oELmeb1fmCVXNnQw/5pCYMWVbhTa8aX4luAbkcaYeCMrProrAVq+MaZshzkS94B4xJiz SfyA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=kxf6wz3G; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-70516-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-70516-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id m22-20020a63f616000000b005d8e38097f8si3144797pgh.265.2024.02.18.11.02.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 18 Feb 2024 11:02:48 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-70516-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=kxf6wz3G; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-70516-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-70516-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id AC543B211F1 for ; Sun, 18 Feb 2024 19:02:27 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 524F976C85; Sun, 18 Feb 2024 18:58:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="kxf6wz3G"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="5wm9tfqa" 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 A292D7317A for ; Sun, 18 Feb 2024 18:57:57 +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=1708282679; cv=none; b=nPpM93eBy+4c56RG3dRpRKHaeKRaNf/2YxTC4zoABYBM+UdoBdn1veetzkAhV4YhLPrRX7mLRvR3CzqcVmHuHsgGESvJDu6ubKl2iCAf0oUCppHh6Es48s/nL0VuAL3oTk00GboafuvpyKdiH1BsNpj2VlIXJUZyEWa+xSQcGBo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708282679; c=relaxed/simple; bh=9MS2P3GionMP7c/6VZMtfIJf7yMWxofhT265EbuKiDI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=L5vW3rahW7wFn1bkbFGNkQ07MvFg9JSsoUWBYhIY7BefMZM+xCqcxUaN96gTGuym/OGCXJ9FlfU/3nWSaLcwIhP+meX8wQimcmQWS45MTMlHor8ACdZhfxqEYpukdpwkf8DbRLlV37zSFCR3KahtbErh2kmifDwebBTNLpPc65k= 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=kxf6wz3G; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=5wm9tfqa; 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 From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1708282676; 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=GUbvpoY1vkrIaf4t1+bOO9YGAlSrhJitnWRmUehFKmc=; b=kxf6wz3GUu4qdeFhzXpICe2cGfNBJSkLoT82KX/lAcZbK1dpaDV/emR2wz9uRLKOm+7pfV X+65xFM6mk8goNdIDmv2Jm7NzIGQE0DHhH/fVd+3jNKDsTSF/cfMY8YcxIz3z8RKWnF4lH 4yAjPwxF7ORRa1JtkbmQdQLOx04iIefHtB3a34F0yRu19Yl7rKB17/M3lnBFsI52GYqL3m kGPiT6n+5j5nKi6vPBIyJ0LRhiqo9I9qM6neXMzdICMbTtpcsLiU2b47FmUcOkziXOeCyY BmiguoKf+t3UIdk5pyMCAUtol6CnxZM50YfQ0OiQvu68h708WfRRiJUnaOqDbw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1708282676; 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=GUbvpoY1vkrIaf4t1+bOO9YGAlSrhJitnWRmUehFKmc=; b=5wm9tfqaTzyXeL2PKtyecqBe9en8uVauawNKYe+bAlM4JD8JFvwFjfMjY+AJsxeI8QH6y9 U5DlklXhgWwT55Aw== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org, Andrew Morton , Josh Poimboeuf , "Peter Zijlstra (Intel)" , Kefeng Wang , "Guilherme G. Piccoli" , Uros Bizjak , Arnd Bergmann Subject: [PATCH printk v2 23/26] panic: Mark emergency section in warn Date: Sun, 18 Feb 2024 20:03:23 +0106 Message-Id: <20240218185726.1994771-24-john.ogness@linutronix.de> In-Reply-To: <20240218185726.1994771-1-john.ogness@linutronix.de> References: <20240218185726.1994771-1-john.ogness@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791264521766850809 X-GMAIL-MSGID: 1791264521766850809 From: Thomas Gleixner Mark the full contents of __warn() as an emergency section. In this section, the CPU will not perform console output for the printk() calls. Instead, a flushing of the console output is triggered when exiting the emergency section. Co-developed-by: John Ogness Signed-off-by: John Ogness Signed-off-by: Thomas Gleixner (Intel) Reviewed-by: Petr Mladek --- kernel/panic.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/kernel/panic.c b/kernel/panic.c index 86813305510f..d30d261f9246 100644 --- a/kernel/panic.c +++ b/kernel/panic.c @@ -667,6 +667,8 @@ struct warn_args { void __warn(const char *file, int line, void *caller, unsigned taint, struct pt_regs *regs, struct warn_args *args) { + nbcon_cpu_emergency_enter(); + disable_trace_on_warning(); if (file) @@ -697,6 +699,8 @@ void __warn(const char *file, int line, void *caller, unsigned taint, /* Just a warning, don't kill lockdep. */ add_taint(taint, LOCKDEP_STILL_OK); + + nbcon_cpu_emergency_exit(); } #ifdef CONFIG_BUG From patchwork Sun Feb 18 18:57:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 202850 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp913065dyc; Sun, 18 Feb 2024 11:02:28 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVrGIoIO3VSSORULd0yN5HZBhlL2EedAS/rjTH0+k3HUZUzUwgK1NKK9zzLiyRG4L/sHof6yrw8a2z6D/fftgCLfwS+dQ== X-Google-Smtp-Source: AGHT+IH5+LxZBpGap1TLFkMGu/UAsJjLrDW2nr55hFRxLfXCV7kcjNUJmsX+pllPcf4QGNbqaBRg X-Received: by 2002:a17:906:5586:b0:a3e:6eee:f108 with SMTP id y6-20020a170906558600b00a3e6eeef108mr1182357ejp.52.1708282948313; Sun, 18 Feb 2024 11:02:28 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708282948; cv=pass; d=google.com; s=arc-20160816; b=rxCr1Gz7HNRU8JUkqqgSF8J6/x8GEde1LTOH0XANUCBqs6HoyyfAYv7ulOzfK+wNq7 owKo2Mwylw/mFP7435CVVLYOve0v17BVxqjAsPIn3EIEztgLZYLbvmqpHYeReUukqTxU 90JpvZdkT1M2cwCt79E0jFdzYJUybYmrArmI4mxA4CBcxTb88yDNskN1IGGzV0rWJFQ7 cIWjbsMCiE7ea2egBEPtQhn445DP8aB8nK7iuDjg9svAIu0JOiKLD57QijEp1W33QNlC RTL6HbBaoXMfUlxIYOQ2Bu7TrMHp3sqoSC+51pazc4i1BSGImbOXTCXuhgbQB1OZeS6f XgPw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:dkim-signature:dkim-signature:from; bh=vuY4H6DNfOvqdhuJgmJkGITg1xVtZYUjr6s1BV/VGVM=; fh=AqkoYHEBm5sznhcIUwO8PhD1+RF2lHOeWSnt73YGpuY=; b=sqznE+dX6wTjj+GI0gyPgbxOWMdmOkOwHZ+FgzDouWlWg/K1IAUeJCgpHR3vLSzLhJ nyy+LGBXclvn448Nnx9wd2jU+O1mn7lU95MpW606aFHOnIwcGMwB3urjEvDN1XIX9s+u BZ635q4+M6wKlfkrJsv9MfozpNVFwdpp3Hc8H3BMY10Iya2brxTKhIld+K/GgU0otdyc mqB+eFY4EyHV5YPGpkFP+x6YdIPRu1lUEJLqRxnQNsngDxvF7JbFny8tDVAJr+cRAqBS wU+SuHnVh8PrVzkGYrHueFppZ8UsvGHk4tJ8jnmdlaNMNk4ziXW9u7cHg7r65VloLB77 DDfQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=ctirOIaN; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-70517-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-70517-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id w12-20020a17090652cc00b00a3d06c73e18si1820790ejn.603.2024.02.18.11.02.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 18 Feb 2024 11:02:28 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-70517-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=ctirOIaN; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-70517-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-70517-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id E90BC1F21893 for ; Sun, 18 Feb 2024 19:02:27 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 569E476C87; Sun, 18 Feb 2024 18:58:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="ctirOIaN"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="RqqpxluB" 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 534B973198 for ; Sun, 18 Feb 2024 18:57:58 +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=1708282680; cv=none; b=FRfx2MhUkqDiKpd1FenA3lmhxgcxpSHOr6pmymypQNz1K531ATUuYHQI4fd3cZqekERkSNSmG6+yD0XnxaABv2x3V22oq/IyHUFZ3k5t0zU2CERFkO2AZOqqcnOQofpAoBTFwvnw1szfILnoKVtR8oAQFUfxqA/U5QADqiDArG4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708282680; c=relaxed/simple; bh=KzZOuY5lO3xJJiP/W1QN+WoXmg5dBEU4teyAhbH6PyM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=QhGxNcUIbkS9OP1rqDZcWodK6ojIBKL0YCafEtygoppKL6NOT6yQaELhUzbhjWoIeq8yngbOZNeQgWo0x04U/opmwg/ABi3cABNKy9hgS+NWyNq4e6N1Ittjwf1I81PbIb4mJoytunPeK+iyuVDZ6aC8QmiXQjzy+/Qi2+G13tQ= 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=ctirOIaN; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=RqqpxluB; 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 From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1708282676; 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=vuY4H6DNfOvqdhuJgmJkGITg1xVtZYUjr6s1BV/VGVM=; b=ctirOIaNRIvgvx3YlEoT7eH4LHmxuqM1FokSoyH0oWhdq5jTYW+lYL/44OKj6rsAY5RpHU frOqOjhxm1qw2g0xiZ155kVd/OxpvloShfzpNUx01Sk4PcAmjHDs5XFq5SY3zojwP44Niq kzuFFtUdhdYhkhJLWdxnh7H0aJNevyyCAHMDzAD1jkPltPwhfq/vDUtYAATl5c/c/QkGSh YhQOiylqDCC57M3b5lC4o3b+XocaT2fVAfMSuZLrpWxyx0vIeYKO/wyA9D9YvImqOK+KfG 4ygRkaJdPAqFfgSlKNV+NsklnZIxpcjlLBCaLg1NSY7N9DGFfkGz0zQmyiqZ5w== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1708282676; 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=vuY4H6DNfOvqdhuJgmJkGITg1xVtZYUjr6s1BV/VGVM=; b=RqqpxluB27iUY1upXjEPYku+xInDFnSzwmsETUKpBmIETtkeLCPFtzkFtxr0vooC1/lybD z01lu3AituTxVGBQ== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org, Andrew Morton , "Peter Zijlstra (Intel)" , Josh Poimboeuf , "Guilherme G. Piccoli" , Arnd Bergmann , Kefeng Wang , Uros Bizjak Subject: [PATCH printk v2 24/26] panic: Mark emergency section in oops Date: Sun, 18 Feb 2024 20:03:24 +0106 Message-Id: <20240218185726.1994771-25-john.ogness@linutronix.de> In-Reply-To: <20240218185726.1994771-1-john.ogness@linutronix.de> References: <20240218185726.1994771-1-john.ogness@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791264500768819036 X-GMAIL-MSGID: 1791264500768819036 Mark an emergency section beginning with oops_enter() until the end of oops_exit(). In this section, the CPU will not perform console output for the printk() calls. Instead, a flushing of the console output is triggered when exiting the emergency section. The very end of oops_exit() performs a kmsg_dump(). This is not included in the emergency section because it is another flushing mechanism that should occur after the consoles have been triggered to flush. Signed-off-by: John Ogness --- kernel/panic.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/kernel/panic.c b/kernel/panic.c index d30d261f9246..9fa44bc38f46 100644 --- a/kernel/panic.c +++ b/kernel/panic.c @@ -634,6 +634,7 @@ bool oops_may_print(void) */ void oops_enter(void) { + nbcon_cpu_emergency_enter(); tracing_off(); /* can't trust the integrity of the kernel anymore: */ debug_locks_off(); @@ -656,6 +657,7 @@ void oops_exit(void) { do_oops_enter_exit(); print_oops_end_marker(); + nbcon_cpu_emergency_exit(); kmsg_dump(KMSG_DUMP_OOPS); } From patchwork Sun Feb 18 18:57:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 202853 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp913161dyc; Sun, 18 Feb 2024 11:02:35 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXrR1xOiz/SO+NkrLcUkU03avloME7Cbw6/7pW+B5QMzN+esId822IKpqV8uP0pBbrn9zBtHIFFudppDty6e0QuSIcesw== X-Google-Smtp-Source: AGHT+IEn1IXkVoftXc/UI1lDI64boPC92TWjcOKpa361VsnecTVA8JeLr7ApcZlzDj/57BSY+VGj X-Received: by 2002:a0c:f2d0:0:b0:68e:fb17:e14b with SMTP id c16-20020a0cf2d0000000b0068efb17e14bmr9275833qvm.1.1708282955197; Sun, 18 Feb 2024 11:02:35 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708282955; cv=pass; d=google.com; s=arc-20160816; b=lAY6PqvZ+1lOjEx2UfqPlZ8vXuVco82fRrpoMtAgdyWmSkbherSQaQ5X9ZuVPq+Fkh 5oCWIY9TxgTNkjEo0Dxbd/yKa/gdPC2Ip9eqrjV0ym00FSvxwpCZtBeFGzS7+mXx8+si XRaEqkVUpFJeCQ5L52HOvqTna7e4M02MTUuJfSmoQWIa8Z651FSh6TTxtUcGkJMHrbJ6 9pcJE8p5murCNWKKoK/OOwQ+btnBJ1X1aVw4ve4zj4TSbY8I8zu+Dq7rDOWm6Csk3tys /ojwm5L51yprrrzSinGUGayNFrcrhINJsOeD/bz9texy68fbmoNJO5DxXpfKGLor2Cw1 eBYg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:dkim-signature:dkim-signature:from; bh=ou6pqnQIQ61CFk5TWsTCxvXU+rgsnFekoY9DjGSMLxI=; fh=Zc51f6kezQIPGE+VpfICBLFP+oyouiLrY2CJAQIy7as=; b=My/hqzeCb0XWfcPS2kBrd5qiufLzlmXAh46wIh7DhRGnrY1WOlkJUnTmPUpjSDf/Gw RRzhXi6hqg9WvzebegI5kzUuFUMTKefx49O+ZHIxgDH+rHrIGtcyXIeknvdFe96pHGQ5 d2Ytv+A5q7JKgJGKnjFtvZdwJIOh3t6D+RxM/dy6zyggRQ5oysjw1t1rBuTcPlsDzNDo ZkH91t44WjaM3usqWT7DAzX9rjjPZbNUFfuY+WKHuRb7qOv6VqpWohvr705NOu/gnFeH ISaZ7YL4FQpac9+nzkpgPIZoIgAK2CBCpbqi8EzDLM1EksTmh6DKXZ3YRUTWG1jAQirC J/uA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=NvT0XLwH; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-70519-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-70519-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id g6-20020a0562141cc600b0068f0699ab3csi4705012qvd.400.2024.02.18.11.02.35 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 18 Feb 2024 11:02:35 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-70519-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=NvT0XLwH; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-70519-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-70519-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id E55E51C2104F for ; Sun, 18 Feb 2024 19:02:34 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 962846F520; Sun, 18 Feb 2024 18:58:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="NvT0XLwH"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="x2/uK7ua" 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 CC39B745C5; Sun, 18 Feb 2024 18:57:58 +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=1708282680; cv=none; b=cg5yrMfKClgdurSo4WFQTfcirGT3AQiGDLONqxSOq23DY4mientcKtVdD/4EAX3CT1hcZWcG93J0NipwSgha8NC94mojwLs01mq16OF8odxNRinVkkGN3tVnZjgKU/9u7OaanBwOvXeGmtyGua6OvWTF4ZTFUeo4a4M1J2j9PLI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708282680; c=relaxed/simple; bh=OqtVB7F0XU7K6r/XkEXRYuJkg6/1ejUUWR2/2NldzE0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=DUx7BLSjnbQTproe28tJ6wVRqI/B5GCY9pbQ531R28jJF/SVNgTcyYkJIPweF4Cz/OYTLOKo6ejcTr8JN5t7VcajPfnBFdl3KXwpFs+ZZYzVmESXish6/uskqh542ASHDegfgjMw/g0J5kX7bXAOBRVVBgK7WXSUwWXYYdhJiiQ= 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=NvT0XLwH; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=x2/uK7ua; 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 From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1708282677; 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=ou6pqnQIQ61CFk5TWsTCxvXU+rgsnFekoY9DjGSMLxI=; b=NvT0XLwHYOh9+AxQfVwE3XtEQHME+T7jeyFjb+mH0NRGGQKCbh5EmRxPxr3TogqegumTxl DDyXyi39jg6SLdi/ZLLl2VJ++kV4V4Lz/rHgAjGEip9fKs7uqjgCN6IvPD+SAu54hjehKE /CVFyAJfTYhPJxBXicT0qE+9Cyw4/gJjnqsIh5QHCjZIARUcGp4Q1rminYa7+rRP9eMt8h JuZeaQCUDPY+POfG/+INo0985kWx6JRQpeJPA6LR8sIWTp0IY+ey6lprOPEmSZXBzWY0Y1 KnQoaFyYnphPLhcxg2bAOsdfSkm+OMMq40yl4e8g9g/OthkEZ/0mjKZWOZlSzw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1708282677; 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=ou6pqnQIQ61CFk5TWsTCxvXU+rgsnFekoY9DjGSMLxI=; b=x2/uK7uacN1qu3ts3Df1coB1t8Xae85UpjQ3ZkPOYdrYjk/NQ0AEn05N8/xeRAvDI8AjVt OKnGkqYsCYaKYSDg== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org, "Paul E. McKenney" , Frederic Weisbecker , Neeraj Upadhyay , Joel Fernandes , Josh Triplett , Boqun Feng , Mathieu Desnoyers , Lai Jiangshan , Zqiang , rcu@vger.kernel.org Subject: [PATCH printk v2 25/26] rcu: Mark emergency section in rcu stalls Date: Sun, 18 Feb 2024 20:03:25 +0106 Message-Id: <20240218185726.1994771-26-john.ogness@linutronix.de> In-Reply-To: <20240218185726.1994771-1-john.ogness@linutronix.de> References: <20240218185726.1994771-1-john.ogness@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791264508078501281 X-GMAIL-MSGID: 1791264508078501281 Mark an emergency section within print_other_cpu_stall(), where RCU stall information is printed. In this section, the CPU will not perform console output for the printk() calls. Instead, a flushing of the console output is triggered when exiting the emergency section. Signed-off-by: John Ogness Reviewed-by: Petr Mladek --- kernel/rcu/tree_stall.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/kernel/rcu/tree_stall.h b/kernel/rcu/tree_stall.h index ac8e86babe44..efb2be8939a2 100644 --- a/kernel/rcu/tree_stall.h +++ b/kernel/rcu/tree_stall.h @@ -9,6 +9,7 @@ #include #include +#include ////////////////////////////////////////////////////////////////////////////// // @@ -604,6 +605,8 @@ static void print_other_cpu_stall(unsigned long gp_seq, unsigned long gps) if (rcu_stall_is_suppressed()) return; + nbcon_cpu_emergency_enter(); + /* * OK, time to rat on our buddy... * See Documentation/RCU/stallwarn.rst for info on how to debug @@ -658,6 +661,8 @@ static void print_other_cpu_stall(unsigned long gp_seq, unsigned long gps) panic_on_rcu_stall(); rcu_force_quiescent_state(); /* Kick them all. */ + + nbcon_cpu_emergency_exit(); } static void print_cpu_stall(unsigned long gps) From patchwork Sun Feb 18 18:57:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Ogness X-Patchwork-Id: 202851 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp913114dyc; Sun, 18 Feb 2024 11:02:31 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVhqp6mpLegzwHw6Xik2x5q9hqaV2g0n49IRPmRnRkicX5x3QTnUfnAReB17W2EyqM4ZVONs3NnRa7nrw8nnvfxUTeu9A== X-Google-Smtp-Source: AGHT+IGfv9sW/UNivJ+eOruT7EVmgqJn3lbYMtczkv/iY6yUJjAOM1C1MyIzHpE2FHAlExVTQS/m X-Received: by 2002:a0c:e38e:0:b0:68f:3ecd:840b with SMTP id a14-20020a0ce38e000000b0068f3ecd840bmr7249866qvl.23.1708282951362; Sun, 18 Feb 2024 11:02:31 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708282951; cv=pass; d=google.com; s=arc-20160816; b=Jh3H+IdANlGgfHbNDPRKKFR+6/9HQ4A5avjmBNL0VF/DSbEQ8fSx2FUFxWFON4iQIr zRFVFKtzVmtbQ4T00R7gc3t04669BVK/s98p7p5tsrcQSl2Z+e12ADEU9808t+V2Q1M7 JWf0qzm52P1Msbqz819b2HN/ncdDsNC164HkLc1yIcH69FsTvLkXzwQfI6eLi/IXS0Y1 YBc01yYftqRMzi+I1HwdvfSegmai0VWIUi8QxSgYpe+OVzTKtd1EunAZWHb0NcmpUwmy zKZHwJWHQEuvfvswIoilvN0ueCBxgPavZDMmsiB85WHSSB92BOLMWFq3G6Jmu3Ex6Hpo GMOQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:dkim-signature:dkim-signature:from; bh=0lPBki68mVE7PCw7W4jrgk0lCFhQvBUvfvhYmuWjIeY=; fh=baLZk4VyAx6eqLoRrdDbCsrkF3EpnrHuPZYH860mNkA=; b=s8QHATmrJvnyCDQQVyp/+LC6BOI86kiP5TJn0JyrcYAGKoyYtQus2/3MljfVR/1Ute BxA8h52/79wnefjoQiIzIUIMp1Kgg/qxHJPAXHUHPdyR4MyaixkMLx2hiZFW7u8qZV1O Kk8E9rMNF03Y6qTRXGHNAIMJtRR+b6H8CjROx7WKNpMO0lZj/mLU0efOnsxw49QggeO4 fAAdK5hIWnejyvBwQQuWDooGzUWehNFXoCoyXlbdAhvXSaFuNInGp9dgf+D/CYzhb5+H dtVhESDnT548KD0xvcunFGyVvlOaz2R15AQ3cOQ9auF0OolfsMB+wWK1l4K8D3+ogTSC oxeg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=16iOEDIe; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-70520-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-70520-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id a6-20020ad45c46000000b0068f6bcd2108si951114qva.172.2024.02.18.11.02.31 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 18 Feb 2024 11:02:31 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-70520-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=16iOEDIe; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-70520-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-70520-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 29BCF1C20327 for ; Sun, 18 Feb 2024 19:02:31 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7640076C92; Sun, 18 Feb 2024 18:58:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="16iOEDIe"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="iHynVoQd" 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 1473B745D7 for ; Sun, 18 Feb 2024 18:57:59 +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=1708282680; cv=none; b=WFMpaxFt1JabkoBdfexDfTXiArKZQHl59pkHzwhBZJuB96EYGwDNFgcJRLXgxZjsWiNLHP9+goifnC71nJegZ36nMjSO0tEaKIwbmOOprF6poOx5iUWHRU2pg6fMJGPil3hXZLwPB0EKKh09aqFsqARmjIpj+nV/qL6BrViKzbo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708282680; c=relaxed/simple; bh=OagJvzD8CITXGM05wrJdLFbnK8R3FnQZlKkDZ7ArXY0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=tl+0ejlRmOjX/bpbMvekIMokL61zLSwCbpniIimvTW1ZpBQOai65e4a3Gu35+4SJZLoJjEVOOAiG7OHIHvoV08BhGtJGsr/2hLL7DuC+4+qLZZ6xCMh6Qmjo9PvWk0tES2fUVRTeNtv9IwIUrmSrrgCnyZbjYtwk9SVWJ0OIwwg= 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=16iOEDIe; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=iHynVoQd; 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 From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1708282677; 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=0lPBki68mVE7PCw7W4jrgk0lCFhQvBUvfvhYmuWjIeY=; b=16iOEDIef9bfi8hm5YKwdXMo0KA3BGTQYHPoFj515WihwX2bbE+vwFUVFaE5Du1RD7Y5W2 RPwwTqoL6dA2GLDE1UyNa3DkBrV1y2AT9dUZM10gr2IQ6QTaEIKAOA9R1vYmwRH7v5i/LW hBXv3pVUwSCOxaDFMsCTnMSJrRE+ezEIBTczVi/gszaGneoixpcpGkWyW361N2KLds8b9E T1VuopLugS5WomPG7SWkvrlSVJ/kiI4l4ux3mRbLXZo7iqt/NUSd2lWWwWiVtaTjb6MluE tD99NTIR2S1ylI9Jywrwdx9LaxGtztzqu6YDkz54DL0f/6KRyFckh8LM/JeqyQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1708282677; 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=0lPBki68mVE7PCw7W4jrgk0lCFhQvBUvfvhYmuWjIeY=; b=iHynVoQdMqQvQ5UY9zDTHbYAg0fKIK48nfTCXAbx3zmnVvmiXaZF3CIrbiq4IENzpgm/Yp wGM0dChF7tn7OlDQ== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org, Peter Zijlstra , Ingo Molnar , Will Deacon , Waiman Long , Boqun Feng Subject: [PATCH printk v2 26/26] lockdep: Mark emergency section in lockdep splats Date: Sun, 18 Feb 2024 20:03:26 +0106 Message-Id: <20240218185726.1994771-27-john.ogness@linutronix.de> In-Reply-To: <20240218185726.1994771-1-john.ogness@linutronix.de> References: <20240218185726.1994771-1-john.ogness@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791264504175917283 X-GMAIL-MSGID: 1791264504175917283 Mark an emergency section within print_usage_bug(), where lockdep bugs are printed. In this section, the CPU will not perform console output for the printk() calls. Instead, a flushing of the console output is triggered when exiting the emergency section. Signed-off-by: John Ogness --- kernel/locking/lockdep.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c index e85b5ad3e206..00465373d358 100644 --- a/kernel/locking/lockdep.c +++ b/kernel/locking/lockdep.c @@ -56,6 +56,7 @@ #include #include #include +#include #include @@ -3970,6 +3971,8 @@ print_usage_bug(struct task_struct *curr, struct held_lock *this, if (!debug_locks_off() || debug_locks_silent) return; + nbcon_cpu_emergency_enter(); + pr_warn("\n"); pr_warn("================================\n"); pr_warn("WARNING: inconsistent lock state\n"); @@ -3998,6 +4001,8 @@ print_usage_bug(struct task_struct *curr, struct held_lock *this, pr_warn("\nstack backtrace:\n"); dump_stack(); + + nbcon_cpu_emergency_exit(); } /*