From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f181.google.com (mail-pl1-f181.google.com [209.85.214.181]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0DC21306B0C for ; Thu, 27 Nov 2025 19:43:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.181 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764272613; cv=none; b=Fr9QbN+Xl7Uhk+j3SClkwnyT+/lW1fODNOTXTLGlmMpDjkuvEwj7AfGRidHg1syW7MDK4W6h29JryhH71uOuJTodi98yiHdMP2xjwVgdMeGbeLIoSRzgV55MqkrJifoqrOo19OWnVUsPaAyWAH4OrGW2vzo7lr4q9QQnBk7XX+c= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764272613; c=relaxed/simple; bh=obBJTWf5MzBFyGPZf0g8sWcwIi1VbOnlrYJPHX5q2rU=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=OGWBFHOBG+jiW/2uQNeb2DQlwtMCSjZOd1DyIkXIfr4CJu7gxyi0quKG7jlXpkhGMLU/IOf+6EDK/zErTn9nDvKqvXqQdrZhTkYiTwLA7EgReaRHBiGL9CQKr5UaoGREAjUVLWbYiOHLxBHj1Ajn/Fc5gLlSQdDFKd5MvXL5mCQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=chrisdown.name; spf=pass smtp.mailfrom=chrisdown.name; dkim=pass (1024-bit key) header.d=chrisdown.name header.i=@chrisdown.name header.b=oryCNTr2; arc=none smtp.client-ip=209.85.214.181 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=chrisdown.name Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chrisdown.name Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chrisdown.name header.i=@chrisdown.name header.b="oryCNTr2" Received: by mail-pl1-f181.google.com with SMTP id d9443c01a7336-299d40b0845so18615435ad.3 for ; Thu, 27 Nov 2025 11:43:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chrisdown.name; s=google; t=1764272611; x=1764877411; darn=vger.kernel.org; h=user-agent:in-reply-to:content-disposition:mime-version:references :message-id:subject:cc:to:from:date:from:to:cc:subject:date :message-id:reply-to; bh=zqqaWk0c2AyXmPKybhbXo9SwoFt2H0cm8I/zyNuOvLo=; b=oryCNTr2PgsTlKIi1fZ30QcEzQQnYb6Ges0lipTwN7v7rQsocTQqhT9e8FO6bGYBTK zEpE983BBl09JCXrFz/e/9a37LxwGNDpzeeKFskI19cmGwZEkdR0vebmav6e2uIPixn5 yWrkrSFat40OlDWBHcbNouF2i0CQjzg0wJ4uA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1764272611; x=1764877411; h=user-agent:in-reply-to:content-disposition:mime-version:references :message-id:subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=zqqaWk0c2AyXmPKybhbXo9SwoFt2H0cm8I/zyNuOvLo=; b=lYwcqC3jAMj6qzj31g7OcUrYBipy5uv4UYZmZUOi0Y9Jwx2eQblaYizKWqtG161LWQ VQgaKYmxvo+5jJl+SbgudC6Z7BMQB9m99us9qn+gNcR9LeLCeqRkMM3SbgfTgQxFG+ev nG1naFQmMQzdaeDodLfLmaGThdHfB4NpC4Yt0WyyiavF/nowjNPdy3yLEizNs38xlLX8 1n/TiePQzuXTJRHLJq76b8aJutmdloiJ6rhUVOXrj4Z+DTquxDl6nu/hdsiB188jvovO 5PuJ9WXK5d8G8FuRbgNHJSyi/wDNLLuzhw1Fw0IEmrDZeXNxret/pc3uRMBL8bXNCblQ g70g== X-Gm-Message-State: AOJu0YwgIPDsTOQyJRc/HElR9qD0QomZ2xKkNebS0Hnj/1QawYp5fnUm MwkADiqZ2xbl2D2h9x7FUjPOu7GMRGQuKiFP0tBzi9n5w98g9R3rnBjcN9Q+Hmtw+jI= X-Gm-Gg: ASbGncvUKzyOrIdDgxD/6OCaip/B23mYrbXPEdG7YeF13XjooJBkYD1fn98Zu0CvkFh YMqGDTzUq0uYNJei7vef7akEedWqiFbhNvPdYADz+cYaa5vvU8RKaisjipXOIdTeXDk/hmiZWkS qhf2j5wbjCbh6D8oKPFZzYYT1CIVqfyxl0ubGcU2cv/ZacMHJJT18J8FE0EBUKmyahRLhxvsyYK 6VRDXwrFxetmEydowr2mVTb+4MFq62GypooJD0kMD3wP0OseDXnSX6GdcZ0Zn7acnT2WnJMbcKd m+QNsx3PL2qc1cCl3e0dyCnym8mdgA2IYO+HmvaAyy3A2cus7PmJne610sX8hqa8nPhNcrhDP0D OlJeyvy45zrey18UvE7wnO5f8z6j0ufO8hz8OB4taVw3RCa4lbNQH7TnkkgWSweERr6jxt9zSv9 xzOxjY4CfS X-Google-Smtp-Source: AGHT+IGnUJbTyu6KoH7eEGPjzeFs1lsNk+EN6lcTTOsw+Jni6u7WhM7Hg7o06wkTeU3snyhvhwnD/g== X-Received: by 2002:a17:903:46c8:b0:295:1a5b:f406 with SMTP id d9443c01a7336-29baafb7f5amr146114785ad.25.1764272611410; Thu, 27 Nov 2025 11:43:31 -0800 (PST) Received: from localhost ([116.86.198.140]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-29bceb4026bsm24603955ad.71.2025.11.27.11.43.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Nov 2025 11:43:31 -0800 (PST) Date: Fri, 28 Nov 2025 03:43:29 +0800 From: Chris Down To: Petr Mladek Cc: linux-kernel@vger.kernel.org, Greg Kroah-Hartman , Sergey Senozhatsky , Steven Rostedt , John Ogness , Geert Uytterhoeven , Tony Lindgren , kernel-team@fb.com Subject: [PATCH v8 05/21] printk: console: Add per-console loglevel support to struct console Message-ID: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/2.2.15 (2b349c5e) (2025-10-02) The printk subsystem currently uses a single global console_loglevel to control which messages are emitted to all consoles. This works well when all consoles have similar characteristics, but consoles can have vastly different latencies and throughputs. For example, writing a message to the serial console can take on the order of tens of milliseconds to get the UART to successfully write a message. While this is fine for a single, one-off message, this can cause significant application-level stalls when the kernel writes large amounts of information to the console. In preparation for allowing each console to filter messages at its own loglevel, this commit adds the basic infrastructure to support that. Each struct console now has a level field, and a new console_srcu_read_loglevel() helper is added to safely read it under SRCU. Reviewed-by: Petr Mladek Signed-off-by: Chris Down --- include/linux/console.h | 36 ++++++++++++++++++++++++++++++++++++ kernel/printk/printk.c | 3 +++ 2 files changed, 39 insertions(+) diff --git a/include/linux/console.h b/include/linux/console.h index 8f10d0a85bb4..a670c40623ad 100644 --- a/include/linux/console.h +++ b/include/linux/console.h @@ -314,6 +314,8 @@ struct nbcon_write_context { * @match: Callback for matching a console (Optional) * @flags: Console flags. See enum cons_flags * @index: Console index, e.g. port number + * @level: Per-console loglevel. -1 means use global console_loglevel, + * values > 0 specify console-specific filtering level * @cflag: TTY control mode flags * @ispeed: TTY input speed * @ospeed: TTY output speed @@ -342,6 +344,7 @@ struct console { int (*match)(struct console *co, char *name, int idx, char *options); short flags; short index; + int level; int cflag; uint ispeed; uint ospeed; @@ -544,6 +547,39 @@ static inline void console_srcu_write_flags(struct console *con, short flags) WRITE_ONCE(con->flags, flags); } +/** + * console_srcu_read_loglevel - Locklessly read the console specific loglevel + * of a possibly registered console + * @con: struct console pointer of console to read loglevel from + * + * Locklessly reading @con->level provides a consistent read value because + * there is at most one CPU modifying @con->level and that CPU is using only + * read-modify-write operations to do so. + * + * Requires console_srcu_read_lock to be held, which implies that @con might + * be a registered console. The purpose of holding console_srcu_read_lock is + * to guarantee that the console state is valid (CON_SUSPENDED/CON_ENABLED) + * and that no exit/cleanup routines will run if the console is currently + * undergoing unregistration. + * + * If the caller is holding the console_list_lock or it is _certain_ that + * @con is not and will not become registered, the caller may read + * @con->level directly instead. + * + * Context: Any context. + * Return: The current value of the @con->level field. + */ +static inline int console_srcu_read_loglevel(const struct console *con) +{ + WARN_ON_ONCE(!console_srcu_read_lock_is_held()); + + /* + * The READ_ONCE() matches the WRITE_ONCE() when @level is modified + * for registered consoles. + */ + return data_race(READ_ONCE(con->level)); +} + /* Variant of console_is_registered() when the console_list_lock is held. */ static inline bool console_is_registered_locked(const struct console *con) { diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index 9f40ebfac0c1..c6b56f4d8072 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -3848,6 +3848,9 @@ static int try_enable_preferred_console(struct console *newcon, if (newcon->index < 0) newcon->index = c->index; + /* TODO: will be configurable in a later patch */ + newcon->level = LOGLEVEL_DEFAULT; + if (_braille_register_console(newcon, c)) return 0; -- 2.51.2