From nobody Mon Dec 1 22:03:44 2025 Received: from mail-pl1-f170.google.com (mail-pl1-f170.google.com [209.85.214.170]) (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 1A8C7285C9F for ; Thu, 27 Nov 2025 19:43:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764272597; cv=none; b=Z83Mg078/ewuyZ0C2SE06O1xBBs9WSQTQclm/VIy6ZmN+ksViteW74xZf77YsuGdFAfsju4QMlkOAa+IbH6BjmpspGGEz9RrnUrVn2mhU7eiTRS8Kc4kGOdnmN6Wn0yHj9Njw6PpqfwVmv8xJj8BsHM0dqgYQXoaP0LZaC2e7jA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764272597; c=relaxed/simple; bh=n3akGEfQ7fRZ3wJb5emw6xq91JmUE1xHh1jJuMLWhcI=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=HG4mhoUr0/ZDLy/+cGfPuzuWaIJUEzkBcgvMKHe5dy8TtbyqlFYhJRZQvMnENoRNqR3dgSh6NnFDxJc8N0L2QCDqRL1AjfXhtFhxRWTcCOTXHA0nUgZHueRTp4SZ6KEILjghOnutd9OtPPF7Q7++CiCgq0Vb4INZ63/vcV9LXqQ= 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=aLlMJa96; arc=none smtp.client-ip=209.85.214.170 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="aLlMJa96" Received: by mail-pl1-f170.google.com with SMTP id d9443c01a7336-297dc3e299bso11075645ad.1 for ; Thu, 27 Nov 2025 11:43:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chrisdown.name; s=google; t=1764272595; x=1764877395; 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=xpT4K8H5VKmUUUsoQx/FQ8x3hRru7sMrdfd3sP8sTL4=; b=aLlMJa96+KY5akWKoHuu1jyh5lZO0FzodLuY8yteprfDv5wOJhYTuRZggxqGTck1A1 dQ8hf+WJyY/l0yTXZWStmyOsntrtwRCg7ZtNOVpfJi0Y8n2QkRHB2RWuuZy49KDfUfcp C2pxHtKhpco6v08OSaNKf9i+2ZGv0JYhK7NAI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1764272595; x=1764877395; 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=xpT4K8H5VKmUUUsoQx/FQ8x3hRru7sMrdfd3sP8sTL4=; b=bGJtR7m+N0Zuna+3KABoBMAd67DxvDof1I8D+OHN8hpfMWxqIa9OBCLcgAXIeuGVaa Wz4loMwjVKVfEj9Hlp5t340VjSSfrvOEhh/u243aDQyYSSoV/cxgLYvJ9iay60xTxUPx PzOlbMTaxyc8XNOu1xYRErl429oP+YD45w/g+FzCIkG5ZGr9dPK5IMWTj/bmQxba2Kl+ tPiWJZbswko8cpax2SflF4d0CuE+KxopyXWdTOPePtgXt/Vkhrjc1oYACo8UgcKI8cFh WPqPNnnZwyJifQ8zLPHZ2qWPYw0g0WvV6orCx0yLNirGVmBY1kxvzYZJiS5TboBQiTp1 o10g== X-Gm-Message-State: AOJu0Yxth2qQc3jyvTEaQok+I6bUvfxrMig+bAIWny4rms8/dITMyW9a NBlWojrZRfMfnmsVkRM1z5XL7o4mOiMnwJFMUqsIcpf5zDPoUIoKFwXGrkWz4y9w0bI= X-Gm-Gg: ASbGncvNKGYDWwKm6Ly5y/awxur2o5WaF8qfoOhz5OlvonN+NyOoU9RjBy6aib73/aC MqXULgyl6keq0cv+qOaJ8xuZbr74DEzcz+YZNWJ6lPX2igASdSIb6bEqG2MOPK/oY+uUlrkaYNa WUOo7rQ8Kn1WeGmjws86r1FLLe8qNQETnliKQUxgQ6wc7hIVHLcZoU1DH1u2lIDJoPfzu9IGYxP aroyuu1rk6cEfy7/MkAy4Gzqgnw9eGcggohoLhm+ZKMVeAU+Sns3TfGs8MrOSF/n3Bhw/b9DnfQ qPBF51TiEFibekuxmZECVvEYr41AikD70pgecxwSKD2pPz8Kw+SZCWNcuy3LiBtv7Xh9LYWM2Ue 2Kx3koCIdHNxHeXhJpa5m/gejlxqQllyzZLbfr8ycaWGjdCToB7BqQJLHtFvpRPQeKXBbzgpqRs H0SDy8k6RC X-Google-Smtp-Source: AGHT+IEErEZqC7AaSPq5CnB2UnNsihO8qjBcBC8oGCp7Dv0aGB3KghdXi8LBPMXoWKdlOBU3UzXEoA== X-Received: by 2002:a17:902:e945:b0:298:485d:5571 with SMTP id d9443c01a7336-29bab1d746dmr139445105ad.54.1764272595352; Thu, 27 Nov 2025 11:43:15 -0800 (PST) Received: from localhost ([116.86.198.140]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-3476a7c3f1asm6533466a91.16.2025.11.27.11.43.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Nov 2025 11:43:14 -0800 (PST) Date: Fri, 28 Nov 2025 03:43:12 +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 01/21] printk: Fully resolve loglevel before deciding printk delay suppression Message-ID: <62f3a734401016a387b59bda8ecd39252a8da849.1764272407.git.chris@chrisdown.name> References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/2.2.15 (2b349c5e) (2025-10-02) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" When printk_delay() is called from vprintk_emit(), the level argument may be LOGLEVEL_DEFAULT (-1) if the loglevel was not explicitly provided by the caller. If printk_delay() relies on comparing level against the console loglevel (e.g. for suppression), receiving -1 results in incorrect behaviour because -1 is treated as a high priority (so not suppressed), causing unnecessary delays for default-level messages. Parse the format string prefix to resolve the actual loglevel before passing it to printk_delay(). Signed-off-by: Chris Down --- kernel/printk/printk.c | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index 5aee9ffb16b9..f002744b9a90 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -2179,6 +2179,32 @@ u16 printk_parse_prefix(const char *text, int *level, return prefix_len; } =20 +/** + * printk_resolve_loglevel - Resolve the effective loglevel for a message + * + * @facility: The log facility (0 for kernel messages) + * @level: The initial loglevel, may be LOGLEVEL_DEFAULT + * @fmt: The format string, potentially containing a loglevel prefix + * + * Determines the actual loglevel to use for a printk message. If the level + * is LOGLEVEL_DEFAULT and the facility indicates a kernel message, parses + * the format string prefix to extract an embedded loglevel. If no loglevel + * is found, falls back to the default_message_loglevel. + * + * Return: The resolved loglevel value + */ +static inline int printk_resolve_loglevel(int facility, int level, + const char *fmt) +{ + if (facility =3D=3D 0 && level =3D=3D LOGLEVEL_DEFAULT && fmt) + printk_parse_prefix(fmt, &level, NULL); + + if (level =3D=3D LOGLEVEL_DEFAULT) + level =3D default_message_loglevel; + + return level; +} + __printf(5, 0) static u16 printk_sprint(char *text, u16 size, int facility, enum printk_info_flags *flags, const char *fmt, @@ -2394,7 +2420,7 @@ asmlinkage int vprintk_emit(int facility, int level, ft.legacy_direct =3D false; } =20 - printk_delay(level); + printk_delay(printk_resolve_loglevel(facility, level, fmt)); =20 printed_len =3D vprintk_store(facility, level, dev_info, fmt, args); =20 --=20 2.51.2