From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f176.google.com (mail-pl1-f176.google.com [209.85.214.176]) (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 1D189285C9F for ; Thu, 27 Nov 2025 19:43:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.176 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764272590; cv=none; b=YQhKGPTNRPCmUxZTTb1YNQso4500KpUiy5xMAMU1LzGsUscU/dEr04ggjm4MCWCDMUdGMZOC94sxuu2AF/XlLfTDUR/epDvQxrXqoJhb5mWAbgi2Vf97bHZ/CFByrPVwSTEjouEJjwAm5vXIER1kAif0R/nhIkS2gAST8diBPTA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764272590; c=relaxed/simple; bh=2Y5MRb59Il2I8/81TiBgDcHeZLXszi+IFx0rLJqMw6k=; h=Date:From:To:Cc:Subject:Message-ID:MIME-Version:Content-Type: Content-Disposition; b=PlN/qXI5fpYzBwbucMR/94/Sv/w+KnieZ5W/oxpibYJMw0x5fKVMGWff5ULP3nwaXAG8qTpVjW00QInjPEiZhH70P+84SjwX6z+j8W8EbEBlFFsnJi2kVig/xicJ801xyuBVtipGChsjkkentbRLN15y4ILk+PpqdS+/rrc1yIM= 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=YgOkhpYr; arc=none smtp.client-ip=209.85.214.176 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="YgOkhpYr" Received: by mail-pl1-f176.google.com with SMTP id d9443c01a7336-29ba9249e9dso13105545ad.3 for ; Thu, 27 Nov 2025 11:43:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chrisdown.name; s=google; t=1764272588; x=1764877388; darn=vger.kernel.org; h=user-agent:content-disposition:mime-version:message-id:subject:cc :to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=GTVm/cErTRqbeA2nojP2jZuJQFY2Jy4BWGZfI5R1rOE=; b=YgOkhpYrW7NAefd2M0IYsF8BRDJ2v9Gq9JicWr+AAdcXFvm9HaiEI+lmcBOY2F3isX bUahrCLlCLOMXcLvBJt4kuxreJGy/A7emVcNN0lQw6rk5phJlBB8VXx2od9aOJ5FI2eK j6fYTGjlbWlJp11mUQEG6iztWqrFHY/vYtRcA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1764272588; x=1764877388; h=user-agent:content-disposition:mime-version:message-id:subject:cc :to:from:date:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=GTVm/cErTRqbeA2nojP2jZuJQFY2Jy4BWGZfI5R1rOE=; b=aTH/Al4z7RdkA5pgJW4O8k02Kzwi0JS/N6MSnzGGY5M3WqD5d6qguy8AGmblJ5qPUV K7BT/Ei75/ZhUzyPeZca9m/T9D4NCUlQt6QQRHC7VtWguhoaCflVBruPZG+qdNdJUg32 76gG96t3aQLLgj+Dnd/pj3nKfJHwveKiDRumIRH4GFh2g/VYcnPfTAB2IN96EMCeQ0mI sTtIXighf9wIU534upCpB+zk41Dzqc2I04HUpzeX6tzmNP4eluAHnOKj2fSp3TX9nxUH SumKBoNcQSFeAfPhgNJF9bhKKJ62VAAlg+tHBk1+w3BwXqow815Swc9uMUdJ9H6BtG0c 7jUQ== X-Gm-Message-State: AOJu0YyWJlei22cVCFmVULxnMiPo3HRq2k/zZ4IMh2jgFOV+/jXhHyKg cI3gTmYbDPbGqyu8z7uYBTM5pZKWwVpn8bopGDIq2AFlCQVOplpMPodz+r4qRTIwqCQY8pEiJxW 8SI6qfwB0RQ== X-Gm-Gg: ASbGncsoqGfjHhXMeFJHCzmI7QD/JtSeVO8JZ1+f4QXHBoxWrCPPRx39UhKYfinvu/G O12kzMbxWgdq4u04aVtRe3OEwSkuvdfqOzuXQjf4vPVlPjbrWuzijt4qH/P2qovbHwhWY6/Lz/W Xb5fG5CMPj50fV3Ni/P0GDZSCwhaeIvfT5evdQCuLJPPOmL320F7Ddy+yEtOEGGkmpMhOKCDOsU teJboGcL1wgGWKH6Azz9An1/8TpMGXGTqak1M1eisTtQhJV31mMW4H54jbl+denE5m7J7j717io ANnSHimOIDd6ABmW+GcRHhRs0RSe/1Wc2OjA9EBYXXTubdTb5V5dvQ78UqZxqOaqXEMe1E8TpbR M1SFxZ5XwoNpretDI2P9fVicSh4F8iUcN7fBrXu4Gi8rfegrJsmYHUd9E3sX0sBOJUkldqI8+2K X4NzHelgWCmHsLfXFg45U= X-Google-Smtp-Source: AGHT+IFeyQ6PmtJSnH8VZg+EsXW4PaBG7JD6lmV19PPA1Fejo0p5oddoWDqCAcNPaJJLvpTah3ND/A== X-Received: by 2002:a17:902:d4d1:b0:295:512f:5060 with SMTP id d9443c01a7336-29b6c3c802fmr285319215ad.7.1764272588244; Thu, 27 Nov 2025 11:43:08 -0800 (PST) Received: from localhost ([116.86.198.140]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-29bceb450dasm24441085ad.76.2025.11.27.11.43.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Nov 2025 11:43:07 -0800 (PST) Date: Fri, 28 Nov 2025 03:43:05 +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 00/21] printk: console: Per-console loglevels Message-ID: 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 User-Agent: Mutt/2.2.15 (2b349c5e) (2025-10-02) v8: - Fully resolve loglevel before printk_delay to aid LOGLEVEL_DEFAULT - Prioritise user-specified console options over SPCR/DT - Synchronise console unregistration against atomic flushers in nbcon - Optimise printk_delay to avoid SRCU walk when no delay set - Restored accidentally deleted comment in console_srcu_read_flags - Removed extra put_device() in console unregistration - Changed open coded console_srcu_read_lock usage to functions - Removed redundant newcon->classdev = NULL initialisation - Fixed off-by-one errors in loglevel examples in docs (4 vs >4) - In docs clarified "messages won't appear" edge case - In docs, rewrote performance impact section per Petr - In docs, removed obsolete minimum_console_loglevel section - Removed redundant newcon->level init in try_enable_preferred_console - Split up commits some more where reasonable (with tags kept) - Make SYSLOG_ACTION_CONSOLE_{ON,OFF} only restore IPCL when they did it - Drop sysrq loglevel overrides, just use ignore_per_console_loglevel - Set options to NULL if empty so drivers keep baud - Copy console= option strings before stripping loglevel for mips/jazz - Initialise consoles with LOGLEVEL_DEFAULT so sysfs never exposes 0 - Clamp sysrq loglevels v7: - Disallow writing -1 to the global console_loglevel sysctl - Change printk_get_next_message() to take effective loglevel - Update suppress_message_printing() to take effective loglevel - Use CONSOLE_LOGLEVEL_MOTORMOUTH for devkmsg_read() - Fix documentation per Petr's review comments - Add console_srcu_read_loglevel() for lockless reading - Rename per_console_loglevel_is_set() to has_per_console_loglevel() - Refactor API to take int con_level for better lockdep checking - Update callers to read con_level using console_srcu_read_loglevel() - Remove hierarchy comment since it's obvious from the code - Use LOGLEVEL_DEFAULT as base level instead of hardcoded -1 - Use pr_warn_once() in sysrq handling instead of manual warned variable - Split sysrq handling into separate commit - Update code/ABI documentation to change loglevel bounds from 0 to 1 - Remove 'enabled' attribute from sysfs interface - Move #ifdefs out of sysfs.c - Fix console_clamp_loglevel() to use documented bounds - Initialise classdev and level in try_enable_default_console() - Fix race condition, use console_list_lock() in console_setup_class() - Remove NULL check before device_unregister() - Add data_race() annotations to READ_ONCE/WRITE_ONCE for KCSAN - Remove pr_warn() for unknown loglevel source - Add error handling for kzalloc() failure - Make console_class constant via class_register() per Greg - Export do_proc_dointvec() and do_proc_dointvec_conv() - Refactor to use @conv callback approach - Rename printk_console_loglevel() to proc_dointvec_console_loglevel() - Simplify level assignment to `newcon->level = c->level;` per Petr - Add missing loglevel= parameter documentation - Change printk_sysctl_deprecated to proc_dointvec_printk_deprecated - Add missing kernel parameter documentation for ignore_loglevel - Reject KERN_EMERG (0) consistently - Add comprehensive usage examples to per-console-loglevel.rst - Add troubleshooting section with common issues and solutions - Update ABI documentation with error conditions and permissions - Document new struct console fields (level and classdev) - Rename clamp_loglevel() to console_clamp_loglevel() for clarity - Add kernel doc comments for internal API functions where it helps - Initialise classdev in try_enable_default_console() explicitly - Mark console devices with device_set_pm_not_required() - Add syslog_lock around SYSLOG_ACTION_CONSOLE_{OFF,ON} v6: - Add .rst suffix to documentation in do_syslog - Add loglevel table to per-console-loglevel.rst and serial-console.rst - Add newlines between multiline bullets in per-console-loglevel.rst - Make effective_loglevel doc more clear - Remove ignore_per_console_loglevel doc, it's not shown in sysfs now - Use READ_ONCE/WRITE_ONCE for con->level - Ignore/restore per console loglevel in sysrq - Add new fields to comment above struct console - Remove now unused flags field on console_cmdline - Remove WARN_ON_ONCE(!con) in effective loglevel checks - Avoid underflow in find_and_remove_console_option if val_buf_size == 0 - Better error message on oversize in find_and_remove_loglevel_option - Reject if clamped in find_and_remove_loglevel_option - Clarify level setting logic in __add_preferred_console - Move console emission check to printk_delay itself - Use console_src_read_flags in enabled_show - Infer if extended from con in printk_get_next_message, don't pass args - Remove misleading comment about early consoles in console_init - Use a goto in loglevel_store to avoid setting level in multiple places - Mention only @flags and @level are valid in printk_get_next_message - Use LOGLEVEL_DEBUG for max clamp in sysctls - Update for class_create interface changes - Move sysctl functionality out to sysfs.c - Purge default_console_loglevel - Update sysctl docs for kernel.printk deprecation v5: - Fix syntax in boot_delay v4: - Change base to Linus' master - Use SRCU iterators for console walks - Override per-console loglevels on magic sysrq - Fix htmldocs - Fix mistaken __user annotation in sysctl callbacks - Consistently use indexed names (eg. ttyS0 instead of ttyS) - Remove "The loglevel for a console can be set in many places" comment - Remove CON_LOGLEVEL flag and infer based on >0 - Open code our dev_get_drvdata console stashing - Split out console_effective_loglevel functions per Petr's suggestion - Make boot_delay_msec/printk_delay check if it would be emitted - Simplify warning on SYSLOG_ACTION_CONSOLE_LEVEL - Save/restore ignore_per_console_loglevel on syslog console actions - Unify min/max level checks across sysfs/proc/syslog - Add find_and_remove_console_option to avoid affecting io/mmio options v3: - Update to work with John's kthread patches - Remove force_console_loglevel, now we only have global and local levels - Remove minimum_console_loglevel control and document how to change it - The minimum loglevel is now only honoured on setting global/local level - Add ignore_per_console_loglevel - Return -EINVAL if trying to set below minimum console level - Add parser for named console= options - Fix docs around ignore_loglevel: it can be changed at runtime - Fix ordering in "in order of authority" docs - Remove duplicated default_console_loglevel doc - Only warn once on syslog() use v2: - Dynamically allocate struct device* - Document sysfs attributes in Documentation/ABI/ - Use sysfs_emit() instead of sprintf() in dev sysfs files - Remove WARN_ON() for device_add/IS_ERR(console_class) - Remove "soon" comment for kernel.printk - Fix !CONFIG_PRINTK build - Fix device_unregister() NULL dereference if called before class setup - Add new documentation to MAINTAINERS Chris Down (21): printk: Fully resolve loglevel before deciding printk delay suppression printk: Avoid spuriously delaying messages not solicited by any console printk: Prioritise user-specified configuration over SPCR/DT printk: Use effective loglevel for suppression and extended console state printk: console: Add per-console loglevel support to struct console printk: nbcon: Synchronise console unregistration against atomic flushers printk: Introduce per-console loglevel support printk: Iterate registered consoles for delay suppression decisions printk: Optimise printk_delay() to avoid walking consoles under SRCU printk: Add synchronisation for concurrent console state changes printk: Add ignore_per_console_loglevel module parameter printk: Ensure sysrq output bypasses per-console filtering printk: Toggle ignore_per_console_loglevel via syslog printk: console: Introduce sysfs interface for per-console loglevels printk: sysrq: Clamp console loglevel to valid range printk: Constrain hardware-addressed console checks to name position printk: Support setting initial console loglevel via console= on cmdline printk: Deconstruct kernel.printk into discrete sysctl controls printk: docs: Add comprehensive guidance for per-console loglevels printk: Deprecate the kernel.printk sysctl interface printk: Purge default_console_loglevel Documentation/ABI/testing/sysfs-class-console | 58 +++ Documentation/admin-guide/index.rst | 1 + .../admin-guide/kernel-parameters.txt | 31 +- .../admin-guide/per-console-loglevel.rst | 252 +++++++++ Documentation/admin-guide/serial-console.rst | 37 +- Documentation/admin-guide/sysctl/kernel.rst | 25 +- Documentation/core-api/printk-basics.rst | 35 +- Documentation/networking/netconsole.rst | 16 + MAINTAINERS | 2 + drivers/tty/sysrq.c | 8 +- include/linux/console.h | 40 ++ include/linux/printk.h | 4 +- include/linux/sysctl.h | 7 + kernel/printk/Makefile | 2 +- kernel/printk/console_cmdline.h | 1 + kernel/printk/internal.h | 20 +- kernel/printk/nbcon.c | 34 +- kernel/printk/printk.c | 489 ++++++++++++++++-- kernel/printk/sysctl.c | 77 ++- kernel/printk/sysfs.c | 290 +++++++++++ kernel/sysctl.c | 18 +- 21 files changed, 1362 insertions(+), 85 deletions(-) create mode 100644 Documentation/ABI/testing/sysfs-class-console create mode 100644 Documentation/admin-guide/per-console-loglevel.rst create mode 100644 kernel/printk/sysfs.c base-commit: a9f349e3c0bebe7ae97750b32a72f452bdf707e2 -- 2.51.2