From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wr1-f50.google.com (mail-wr1-f50.google.com [209.85.221.50]) (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 9862C1EF0B9 for ; Fri, 12 Dec 2025 14:04:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.50 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765548253; cv=none; b=dBpRQwvGHIjXjL+zo1IU6oNd2l9E9jSsxgdKzFyCGh66llPJJwgoGpbeaGhX97N6YfrvEP6olAAw4ku7ZiDLH82BW6VLNawxOYGoMzC9ih28Cq/FOPpzu4Q1Wis9oNx4xQtKv4frBCiXBaP3+d1aast/nkdbedPxarip8obaZ9M= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765548253; c=relaxed/simple; bh=zXTWLfIV1wWz8GJ6vmfkQuCt6sFjJ2cPsO5E5+inAgY=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Wf1iWg37KxPsH3Lhtcjdoje8s+NPEBI7KE+u1kChvTlGgIbEzgDSMTG0zjObzyeEwm+CNRn3kYFfHBE+KNUo6ZKUUNFdb+K2ufvyGOFcuYWZG/u5EP2WDQgg5WWQeo41sPs3baMVhHrrVla+IJlgDUIcrpxbFi17DfKzS8SI+qw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b=Ci9+XZUA; arc=none smtp.client-ip=209.85.221.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b="Ci9+XZUA" Received: by mail-wr1-f50.google.com with SMTP id ffacd0b85a97d-42e2d52c24dso715182f8f.1 for ; Fri, 12 Dec 2025 06:04:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1765548249; x=1766153049; darn=vger.kernel.org; h=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=B/lCGk0Xj5r7Z84mWhn/ryEjCedBvpSLS2J0w2Qt8V8=; b=Ci9+XZUA6qxoeNtgcUDWNhmJJ+odzZU4rcmn2eThS/2Ln4eQfj0AXrnua3+FSGYXRK yX0JA+esgwFh2xJYkoruYw7iOTo/j567jK1ZRS5mS4I6Axh/sTO0MMOumjIDgZCuJoQ+ NexFd0YPoFKay3L5e8CwSJ3lsHH9gF+Jvr6LPPBshKFrCkVSQSq7JZUkcjab1it6ixgz LdHr9kVeFFrIOoduMmInvTlM+wGN0PHTFOYbv7I9xKI+XqduXvWtX5mnyvOxHcj/i/uw zi4E+uXQy21cVcxN4mJmIAB4TarwK0WE/cleLxeXQqby5F+utomLasVOVOwBKU6Zm5/f PKIA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1765548249; x=1766153049; h=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=B/lCGk0Xj5r7Z84mWhn/ryEjCedBvpSLS2J0w2Qt8V8=; b=Z8DFqeO/W73O9HG8Dub9n9S1vqqHQQHCE5pAlbB4tdiWSdyNgaxu7kONY9XUxwTNFI wwzvtnK0g7CLGOB1Fva++EM2/zvlHlyfPt5i5uILbOiaRbPVTY+Oifo6L1x7Q/6gLM9A YV8YieCOMNQbAtYDNtpRKjlNt30GXt2xvQnnl6TjlDg2hgN5jcfK6glYR5o9A2qdmf0F kVo+XKqmaUxzgWviHUzN9T1ZIbFX3MLZQrUvPSSpc+4MzjmsG8hEAxW9XSh++xwDvd/v Il0XjFx2yG99bLg91JMn0hyEnb3tfHmWGkgL6fnOmuC9Qq6RGPGsGl59tF2uRACWBoLB ukxQ== X-Gm-Message-State: AOJu0YzUuoWpVvOgJnPyUfoSQTjpLr4ViIHDJznoe/Xwf8gAjrmY5AhW KSHUyKrlryMfle0CCo6fv3yUa/3m2dI7hL8zGx3D5DUZZYuj79i0ppRryvpwV83oe/19zY51371 HCmQR X-Gm-Gg: AY/fxX58alxhXprqh2ombzTmVHw2hTiF97rzU3Xk71ogGRdkdcfTTbr5p0GzZMmUNpy I7yWJoLXwV7HpRR0aBhpFBR+5y58s/uwNRW5pkSIJw7bLpa3Mu7FCPHzZNwJYWt2IbGQaGJssUr 0RlmhzynH7pPgP0WJiwrmfkGIQBGsR0jSiYk9TrKyQfe7IJucUtCB7XmhrE7DKmLYpWvoQS1rAe WXs5xIY6G/+D7GWgpbfXKle9r6rViZURqxxx5In8BnuUj5ol5qlmjjcZh/mmKS9Avl1K0GHH0K9 bZAfKWJtpakn28umXlHJ9blk9mGs3z9J+z6p7lLb3g0olYG4K8nZpdlMhYnAJyjr8X0EpRwhW65 QiX7tPOqWn07g220qVCCCLXZf1BKvjxh3JtRLaLGf7GYQdw8IyvsyAe6w5MAJcPO35YRwHkEwh6 Y2vXsesS0v7byT6A== X-Google-Smtp-Source: AGHT+IF3i9fknIT6iwZAKx8Wk65ttt98+cBfB4fQyDEVkR6flm/lRoxKxJx5tG6Sgeg5GF1T23jMnw== X-Received: by 2002:a05:6000:40e1:b0:42b:3023:66be with SMTP id ffacd0b85a97d-42fb48fc262mr2516711f8f.32.1765548248739; Fri, 12 Dec 2025 06:04:08 -0800 (PST) Received: from pathway ([176.114.240.130]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-42fa8b9b20dsm12318988f8f.38.2025.12.12.06.04.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Dec 2025 06:04:08 -0800 (PST) Date: Fri, 12 Dec 2025 15:04:06 +0100 From: Petr Mladek To: Chris Down Cc: linux-kernel@vger.kernel.org, Greg Kroah-Hartman , Sergey Senozhatsky , Steven Rostedt , John Ogness , Geert Uytterhoeven , Tony Lindgren , kernel-team@fb.com Subject: Re: [PATCH v8 14/21] printk: console: Introduce sysfs interface for per-console loglevels Message-ID: References: <84b8d91693e56f6026271bc40553bcb6657ab24d.1764272407.git.chris@chrisdown.name> 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: <84b8d91693e56f6026271bc40553bcb6657ab24d.1764272407.git.chris@chrisdown.name> On Fri 2025-11-28 03:44:06, Chris Down wrote: > A sysfs interface under /sys/class/console/ is created that permits > viewing and configuring per-console attributes. This is the main > interface with which we expect users to interact with and configure > per-console loglevels. > > Each console device now has its own directory (for example, > /sys/class/console/ttyS0/) containing the following attributes: > > - effective_loglevel (ro): The effective loglevel for the console after > considering all loglevel authorities (e.g., global loglevel, > per-console loglevel). > - effective_loglevel_source (ro): The source of the effective loglevel > (e.g., local, global, ignore_loglevel). > - loglevel (rw): The per-console loglevel. Writing a value between 0 > (KERN_EMERG) and 8 (KERN_DEBUG + 1) sets the per-console loglevel. > Writing -1 disables the per-console loglevel. > > --- a/kernel/printk/printk.c > +++ b/kernel/printk/printk.c > @@ -200,6 +200,24 @@ static int __init control_devkmsg(char *str) > } > __setup("printk.devkmsg=", control_devkmsg); > > +/** > + * console_clamp_loglevel - Clamp a loglevel to valid console loglevel range > + * > + * @level: The loglevel to clamp > + * > + * Console loglevels must be within the range [LOGLEVEL_ALERT, LOGLEVEL_DEBUG + 1]. > + * This function clamps a given level to this valid range. > + * > + * Note: This does not allow LOGLEVEL_EMERG (0) for per-console loglevels, as > + * level 0 is reserved for emergency messages that should always go to all consoles. > + * > + * Return: The clamped loglevel value > + */ > +int console_clamp_loglevel(int level) > +{ > + return clamp(level, LOGLEVEL_ALERT, LOGLEVEL_DEBUG + 1); > +} > + > char devkmsg_log_str[DEVKMSG_STR_MAX_SIZE] = "ratelimit"; > #if defined(CONFIG_PRINTK) && defined(CONFIG_SYSCTL) > int devkmsg_sysctl_set_loglvl(const struct ctl_table *table, int write, > --- /dev/null > +++ b/kernel/printk/sysfs.c [...] > +static ssize_t loglevel_store(struct device *dev, struct device_attribute *attr, > + const char *buf, size_t size) > +{ > + struct console *con = dev_get_drvdata(dev); > + ssize_t ret; > + int level; > + > + ret = kstrtoint(buf, 10, &level); > + if (ret < 0) > + return ret; > + > + /* -1 means "use global loglevel" */ > + if (level == -1) > + goto out; > + > + /* > + * Reject level 0 (KERN_EMERG) - per-console loglevel must be > 0. > + * Emergency messages should go to all consoles, so they cannot be > + * filtered per-console. > + */ > + if (level == 0) > + return -ERANGE; Nit: The above check is not needed. It is handled and explained in console_clamp_loglevel() called right below. > + > + if (console_clamp_loglevel(level) != level) > + return -ERANGE; > + > + /* > + * If the system has a minimum console loglevel set (via sysctl or > + * kernel parameter), enforce it. This prevents setting per-console > + * loglevels below the system minimum. > + */ > + if (minimum_console_loglevel > CONSOLE_LOGLEVEL_MIN && > + level < minimum_console_loglevel) > + return -ERANGE; > + > +out: > + console_sysfs_write_loglevel(con, level); > + return size; > +} Otherwise, it looks good to me. With the duplicit check removed: Reviewed-by: Petr Mladek Best Regards, Petr