Received: by 2002:a05:6358:bb9e:b0:b9:5105:a5b4 with SMTP id df30csp3305505rwb; Mon, 5 Sep 2022 09:22:41 -0700 (PDT) X-Google-Smtp-Source: AA6agR4pB7BRLnf6gupXAosxmiKulN6CBLm3YCcla4+MfbaPXUyZ9OKUCg2Oee6QP5tymvanC1DK X-Received: by 2002:a17:90b:1d83:b0:1fb:6795:5cc9 with SMTP id pf3-20020a17090b1d8300b001fb67955cc9mr20781700pjb.162.1662394961102; Mon, 05 Sep 2022 09:22:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662394961; cv=none; d=google.com; s=arc-20160816; b=J3W8jC6DWW5POSJBc6z+CO4glOxBN+A7r0ppoTLmtylKop4hgHBYABD4Ffyo0GQifY T4/rdtd34UxFN43L8QbVoyhUt46UxiV+EQZf/3Znkg0Q1o/hACUnVKMfN+CGHH3s7R1w alGWoEz85JkZ4Sh9h4p/88Enmk2RHFcbDou4hKp9lBGe0njGqyXeG0lIVNOKIOYXMvyp GoZEjGlXZY34MNpd5g7Zm6hmTb7gjO7zE5BC3a3xdRwvgWCdv03FO21qjFyrZOM4FDjo 4jCSFTuRGwvwMTzxa/BwaRLpAhYA0WkKcjdu1GxXo0b71plyLppiXgiDGpJyqrEZcr3/ /D1Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=hObMCSRjGaA64MN6hMJJwF3Wk1+3FIhA8Eih0G9Sk6M=; b=G5NgRrWu6CjKHdo7X49ZQBAjR3Z9SM58PiBENuvLUjWqIWWga7FEgEBoi4bS76c+bm UKqfx+8v10F6EbqjNqO50UkQreflIv0mnQmAoR/QYIdEU4T+q5MZ5t2gwZ48VcXfL3iN 2O7GgT7hJh/stpkkh3jA3GiKVK4tvVdcEmOsYOMzSD/1sOLVX94OxHmvQ68dcoMYi+5J cMtMnenhIb/Cq/H90uXyZrLfxW8CR5Hc+uC2w1ePeBvbyU4sDfTxxCgUEAzyyOLQUggK FXB/+xRLzPah393XXI84DrpE3U8lgH5Wq6Ihw/krEhQZa5q4eR1skiBU3Pqh1hbK9/8q I4Gw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=KUKqOkYy; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s70-20020a637749000000b0042b8554684bsi11269843pgc.558.2022.09.05.09.22.29; Mon, 05 Sep 2022 09:22:41 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=KUKqOkYy; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237720AbiIEPNU (ORCPT + 99 others); Mon, 5 Sep 2022 11:13:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58086 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237816AbiIEPM6 (ORCPT ); Mon, 5 Sep 2022 11:12:58 -0400 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4B3B3110E for ; Mon, 5 Sep 2022 08:12:21 -0700 (PDT) Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id 7C66933D1E; Mon, 5 Sep 2022 15:12:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1662390739; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=hObMCSRjGaA64MN6hMJJwF3Wk1+3FIhA8Eih0G9Sk6M=; b=KUKqOkYyi0ZGXOi+VsoZ+82tPLXeo8b3WwgMisIXJtiTHPQYcDVHdo19gWHgi0DkRw2h5i r9sptFXXj4iXpj3MKE9TxOcUXL2/UNcD+5n3o4Ttnq3K8ljffRsr8iTirBCkNPPa95s6HZ km0u2Ixv1mFBq+MUS+THBK3Z/4sgJT4= Received: from suse.cz (unknown [10.100.208.146]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by relay2.suse.de (Postfix) with ESMTPS id 1D7BB2C141; Mon, 5 Sep 2022 15:12:18 +0000 (UTC) Date: Mon, 5 Sep 2022 17:12:15 +0200 From: Petr Mladek To: Chris Down Cc: linux-kernel@vger.kernel.org, Greg Kroah-Hartman , Sergey Senozhatsky , Steven Rostedt , John Ogness , Geert Uytterhoeven , kernel-team@fb.com Subject: Re: [PATCH v3 2/2] printk: console: Support console-specific loglevels Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon 2022-09-05 15:07:44, Chris Down wrote: > Hi Petr, > > Thanks a lot for getting back! :-) > > Any comments not explicitly addressed are acked. > > Petr Mladek writes: > > On Wed 2022-07-20 18:48:16, Chris Down wrote: > > > In terms of technical implementation, this patch embeds a device pointer > > > in the console struct, and registers each console using it so we can > > > expose attributes in sysfs. > > > > > > For information on the precedence and application of the new controls, > > > see Documentation/ABI/testing/sysfs-class-console and > > > Documentation/admin-guide/per-console-loglevel.rst. > > > @@ -1701,12 +1806,14 @@ int do_syslog(int type, char __user *buf, int len, int source) > > > break; > > > /* Disable logging to console */ > > > case SYSLOG_ACTION_CONSOLE_OFF: > > > + warn_on_local_loglevel(); > > > if (saved_console_loglevel == LOGLEVEL_DEFAULT) > > > saved_console_loglevel = console_loglevel; > > > console_loglevel = minimum_console_loglevel; > > > break; > > > > We actually could disable logging on all consoles by setting > > ignore_per_console_loglevel. Something like: > > > > case SYSLOG_ACTION_CONSOLE_OFF: > > if (saved_console_loglevel == LOGLEVEL_DEFAULT) { > > saved_console_loglevel = console_loglevel; > > saved_ignore_per_console_loglevel = ignore_per_console_loglevel; > > } > > console_loglevel = minimum_console_loglevel; > > ignore_per_console_loglevel = true; > > break; > > Oh, that's very true. Thanks! > > > > + warn_on_local_loglevel(); > > > > I would keep it simple: > > > > if (!ignore_per_console_loglevel) > > pr_warn_once("SYSLOG_ACTION_CONSOLE_LEVEL is ignored by consoles with explicitely set per-console loglevel, see Documentation/admin-guide/per-console-loglevel\n"); > > My concern with this is that this will then warn on basically any first > syslog() use, even for people who don't care about the per-console loglevel > semantics. They will now get the warning, since by default > ignore_per_console_loglevel isn't true -- however no per-console loglevel is > set either, so it's not really relevant. > > That's why I implemented it as warn_on_local_loglevel() checking for > CON_LOGLEVEL, because otherwise it seems noisy for those that are not using > the feature. IMHO, the question is if any commonly used tool is using syslog SYSLOG_ACTION_CONSOLE_ON/OFF these days. It is supported by dmesg but I am not sure if anyone is really using it. And I am not sure if anyone uses this during boot, suspend, or so. I think that I really should open the discussion whether to obsolete syslog syscall in general. I am sure that it won't me possible to remove it anytime soon, maybe it would need to stay forever. Anyway, it has many problems because they modify global variables. And even reading does not work well when there are more readers. I am going to send it. Well, I would need to some time to think about it. In the meantime, you could either do it the conservative way or always show it for these operations. It would be simple to fix when anyone complains. > > > +static ssize_t loglevel_store(struct device *dev, struct device_attribute *attr, > > > + const char *buf, size_t size) > > > +{ > > > + struct console *con = classdev_to_console(dev); > > > + ssize_t ret; > > > + int tmp; > > > + > > > + if (!strcmp(buf, "unset") || !strcmp(buf, "unset\n")) { > > > + con->flags &= ~CON_LOGLEVEL; > > > + return size; > > > + } > > > + > > > + ret = kstrtoint(buf, 10, &tmp); > > > + if (ret < 0) > > > + return ret; > > > + > > > + if (tmp < LOGLEVEL_EMERG || tmp > LOGLEVEL_DEBUG + 1) > > > + return -ERANGE; > > > + > > > + if (tmp < minimum_console_loglevel) > > > + return -EINVAL; > > > > This looks superfluous. Please, use minimum_console_loglevel > > instead of LOGLEVEL_EMERG in the above range check. > > That's fair. In which case we probably end up with one error for all cases: > do you prefer we should return -EINVAL or -ERANGE? I prefer -ERANGE. > > > + > > > static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write, > > > void *buffer, size_t *lenp, loff_t *ppos) > > > { > > > @@ -76,6 +122,22 @@ static struct ctl_table printk_sysctls[] = { > > > .extra1 = SYSCTL_ZERO, > > > .extra2 = SYSCTL_TWO, > > > }, > > > + { > > > + .procname = "console_loglevel", > > > + .data = &console_loglevel, > > > + .maxlen = sizeof(int), > > > + .mode = 0644, > > > + .proc_handler = printk_console_loglevel, > > > + }, > > > + { > > > + .procname = "default_message_loglevel", > > > + .data = &default_message_loglevel, > > > + .maxlen = sizeof(int), > > > + .mode = 0644, > > > + .proc_handler = proc_dointvec_minmax, > > > + .extra1 = &min_loglevel, > > > + .extra2 = &max_loglevel, > > > + }, > > > > Is there any chance to add this into /sys/class/console instead? > > I mean: > > > > /sys/class/console/loglevel > > /sys/class/console/default_message_loglevel > > > > It would be nice to have the things are on the same place. > > Especially it would be nice to have the global loglevel there. > > I think this one is a little complicated: on the one hand, yes, it does seem > more ergonomic to keep everything together in /sys/class/console. On the > other hand, this means that users can no longer use the sysctl > infrastructure, which makes things more unwieldy than with kernel.printk. > > Not really a problem with sysfs as much as a problem with userspace > ergonomics: sysctls have a really easy way to set them at boot, but sysfs > stuff, not so. You can hack it with systemd-tmpfiles, a boot unit, or > similar, but the infrastructure is a lot less specialised and requires more > work. I am worried that people may complain that that's unhelpful, > especially since we're deprecating kernel.printk. Good point. Let's keep the global values in /proc so that they might be modified by sysctl. Best Regards, Petr