Message ID | tencent_AA60553AD4DF41859328E9CACC367EFDCF08@qq.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel+bounces-79972-ouuuleilei=gmail.com@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp1425167dyb; Sat, 24 Feb 2024 20:08:17 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUVq9iMyqenK0uCMjoWABwLjcSGD+UFToaPb9XLLS9XNAPSdLmC3xONvjiSXNdsLUyUTJD5app+nCLMDBMENfu6nq286w== X-Google-Smtp-Source: AGHT+IETNJSH7XRiaInfr+c6iZrFr0wqMA4rtB7EG6L3j5UplAFmBK2puY1iLnrBMFhvGpMEpuSC X-Received: by 2002:a05:6a21:3512:b0:1a0:a091:ee97 with SMTP id zc18-20020a056a21351200b001a0a091ee97mr5728154pzb.19.1708834097571; Sat, 24 Feb 2024 20:08:17 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708834097; cv=pass; d=google.com; s=arc-20160816; b=kaTsiwJMgLlHxNJFSn6C59ILivvYE8BeUuPz8ZaAedfkEzb2mN2VNeJSKFxDdvstav 7mUSPQ3c+iQG8ShmqLox0rMZNhOTo6hoQ/AfiqMy1Eia27MPleKvwkf+8w3goBniU1Xx LWbMZZRrRrsB/IWEVhcVO92bYh28Cs99w3icnA2fVaze+o6LL3kmJfNQi32I1U0KsgZY RcE1DwuZUOfzDjtdBgOG0wDwH+avufVaty6ysi/49YeNtVe4vaqMgUWLSTUHq2rSXA1n OU4PBqx/tTHIbmHMsBVD7QDoUU+SzMSWx3fuvtpBjKTG4IE+dsuks2sEhtKqanKEABLQ 8fOw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:date :subject:cc:to:from:message-id:dkim-signature; bh=QzjzGYwHl8mJJbJ/GLAvGi7Pny0jhSARgE05jH5zKak=; fh=VClCbdleh3D5sabtQ0BRdkkta2krUeLv9TtunNGfjzw=; b=AGK3+AJBB1Xu1+4pTwBjwUM767FdtZWqXCF8MXMefXjDYw/yLQWd1euX9YblsixbAD jBMx4am8/4UER/Rrd1ACBEd0j/Us+G2y6YIoOEwawDJD4MoAwbncfgjwRM91k4L99H2H WvL9VIoZprxhOCVj3XjhoKEG5znSjiKyIj89d6W1udjDSBT4YfRATgooC6NSSWqwB6TS 097O1ncq35i2C+jW9mtvgNTAVKuinflMO3IfCipgEy44E4fcUY13PqTqZuILxrLIQ5Gf gq86UXhsbCEKBXPGNuSiCVM6wbko/J2EPVr1XMAjyh78TzbLls1a3+tUBYMebUiuZff0 v4QA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@foxmail.com header.s=s201512 header.b=g7oQi2Lo; arc=pass (i=1 spf=pass spfdomain=foxmail.com dkim=pass dkdomain=foxmail.com dmarc=pass fromdomain=foxmail.com); spf=pass (google.com: domain of linux-kernel+bounces-79972-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-79972-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=foxmail.com Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id i23-20020a631317000000b005ce05e5d57bsi1718260pgl.574.2024.02.24.20.08.17 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 24 Feb 2024 20:08:17 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-79972-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@foxmail.com header.s=s201512 header.b=g7oQi2Lo; arc=pass (i=1 spf=pass spfdomain=foxmail.com dkim=pass dkdomain=foxmail.com dmarc=pass fromdomain=foxmail.com); spf=pass (google.com: domain of linux-kernel+bounces-79972-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-79972-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=foxmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 4CE87281FEE for <ouuuleilei@gmail.com>; Sun, 25 Feb 2024 04:08:17 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 370BB9454; Sun, 25 Feb 2024 04:08:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=foxmail.com header.i=@foxmail.com header.b="g7oQi2Lo" Received: from out203-205-221-210.mail.qq.com (out203-205-221-210.mail.qq.com [203.205.221.210]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D9E808BFB for <linux-kernel@vger.kernel.org>; Sun, 25 Feb 2024 04:08:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=203.205.221.210 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708834084; cv=none; b=kmvH3J90Uqro/ogzXWklmcWZhlR6PG5NJx9pxOZyxfE+ZS95vQugt8rebPSh13NOBmO/diMfreOnBMXrDUeG4OimqZxLu1hfNYyNNbi7jYS3GU/9V8fINYb6IKXhKKZb18hRKJ4y+vkl2Gae23Henl+YmMBtKayfuxuZvDbxVZw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708834084; c=relaxed/simple; bh=x/f9hZGAQVRLuG2BwE0elvw8ixnOBltGJfsVT75HSnk=; h=Message-ID:From:To:Cc:Subject:Date:In-Reply-To:References: MIME-Version; b=efhg1OcyoXPvSVXun0nvY2dGKk6FUIojD1cXrPn0abJ8NWgid09SYjrK1C1y0K68/ey5CLEFLsPIwMmFwOltWF04dgSYLtLQ40ajnqU9atTMc2ktx5lPg1bFY7sAtq/4JWgff5JHllGhSNCHkKXrlx/JzZD7cpDPTtJHK4gY4HI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=foxmail.com; spf=pass smtp.mailfrom=foxmail.com; dkim=pass (1024-bit key) header.d=foxmail.com header.i=@foxmail.com header.b=g7oQi2Lo; arc=none smtp.client-ip=203.205.221.210 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=foxmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=foxmail.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foxmail.com; s=s201512; t=1708834080; bh=QzjzGYwHl8mJJbJ/GLAvGi7Pny0jhSARgE05jH5zKak=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=g7oQi2Lo8n3LChx+C58v2YnIuB78Z/R12XvbbRDjg1mP54HjM7ArkYGcGCBLDdk3N +KiZiHVSrcEgkFBDLqepLY/KmuMCKmMZoVfwwcjv15OlDJrj/CEh+umwNbBSbV8LHu +rklxbdmPLlbH8dYRNySJLgC2OXv1BI5CUszT91U= Received: from localhost.localdomain ([2409:8a60:2a61:ef40:480f:5c56:cca3:1b20]) by newxmesmtplogicsvrszb6-0.qq.com (NewEsmtp) with SMTP id 18993038; Sun, 25 Feb 2024 12:06:09 +0800 X-QQ-mid: xmsmtpt1708834068tyhcili55 Message-ID: <tencent_AA60553AD4DF41859328E9CACC367EFDCF08@qq.com> X-QQ-XMAILINFO: N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C2nPogoFA= X-QQ-XMRINFO: OD9hHCdaPRBwq3WW+NvGbIU= From: wenyang.linux@foxmail.com To: Luis Chamberlain <mcgrof@kernel.org>, Kees Cook <keescook@chromium.org>, Joel Granados <j.granados@samsung.com>, Christian Brauner <brauner@kernel.org>, davem@davemloft.net, David Ahern <dsahern@kernel.org>, Eric Dumazet <edumazet@google.com>, Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com> Cc: Wen Yang <wenyang.linux@foxmail.com>, "Eric W. Biederman" <ebiederm@xmission.com>, Shuah Khan <skhan@linuxfoundation.org>, linux-kernel@vger.kernel.org Subject: [PATCH 8/8] ucounts: delete these duplicate static variables ue_zero and ue_int_max Date: Sun, 25 Feb 2024 12:05:38 +0800 X-OQ-MSGID: <20240225040538.845899-9-wenyang.linux@foxmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240225040538.845899-1-wenyang.linux@foxmail.com> References: <20240225040538.845899-1-wenyang.linux@foxmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: <linux-kernel.vger.kernel.org> List-Subscribe: <mailto:linux-kernel+subscribe@vger.kernel.org> List-Unsubscribe: <mailto:linux-kernel+unsubscribe@vger.kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791842422394097615 X-GMAIL-MSGID: 1791842422394097615 |
Series |
[1/8] sysctl: introduce sysctl SYSCTL_U8_MAX and SYSCTL_LONG_S32_MAX
|
|
Commit Message
Wen Yang
Feb. 25, 2024, 4:05 a.m. UTC
From: Wen Yang <wenyang.linux@foxmail.com> Since these static variables (ue_zero and ue_int_max) are only used for boundary checks and will not be changed, remove it and use the ones in our shared const array. Signed-off-by: Wen Yang <wenyang.linux@foxmail.com> Cc: Luis Chamberlain <mcgrof@kernel.org> Cc: Kees Cook <keescook@chromium.org> Cc: Joel Granados <j.granados@samsung.com> Cc: Christian Brauner <brauner@kernel.org> Cc: "Eric W. Biederman" <ebiederm@xmission.com> Cc: Shuah Khan <skhan@linuxfoundation.org> Cc: linux-kernel@vger.kernel.org --- kernel/ucount.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)
Comments
wenyang.linux@foxmail.com writes: > From: Wen Yang <wenyang.linux@foxmail.com> > > Since these static variables (ue_zero and ue_int_max) are only used for > boundary checks and will not be changed, remove it and use the ones in > our shared const array. What happened to the plans to kill the shared const array? You can still save a lot more by turning .extra1 and .extra2 into longs instead of keeping them as pointers and needing constants to be pointed at somewhere. As I recall the last version of this actually broke the code, (but not on little endian). This one if the constants are properly named looks better than that, but I don't see any reason why you want shared constants for such a handful of things. Especially when it has proven to be error prone in the past. The only people I can see who find a significant benefit by consolidating all of the constants into one place are people who know how to stomp kernel memory. Eric > > Signed-off-by: Wen Yang <wenyang.linux@foxmail.com> > Cc: Luis Chamberlain <mcgrof@kernel.org> > Cc: Kees Cook <keescook@chromium.org> > Cc: Joel Granados <j.granados@samsung.com> > Cc: Christian Brauner <brauner@kernel.org> > Cc: "Eric W. Biederman" <ebiederm@xmission.com> > Cc: Shuah Khan <skhan@linuxfoundation.org> > Cc: linux-kernel@vger.kernel.org > --- > kernel/ucount.c | 7 ++----- > 1 file changed, 2 insertions(+), 5 deletions(-) > > diff --git a/kernel/ucount.c b/kernel/ucount.c > index 4aa6166cb856..05bbba02ae4f 100644 > --- a/kernel/ucount.c > +++ b/kernel/ucount.c > @@ -58,17 +58,14 @@ static struct ctl_table_root set_root = { > .permissions = set_permissions, > }; > > -static long ue_zero = 0; > -static long ue_int_max = INT_MAX; > - > #define UCOUNT_ENTRY(name) \ > { \ > .procname = name, \ > .maxlen = sizeof(long), \ > .mode = 0644, \ > .proc_handler = proc_doulongvec_minmax, \ > - .extra1 = &ue_zero, \ > - .extra2 = &ue_int_max, \ > + .extra1 = SYSCTL_LONG_ZERO, \ > + .extra2 = SYSCTL_LONG_S32_MAX, \ > } > static struct ctl_table user_table[] = { > UCOUNT_ENTRY("max_user_namespaces"),
On 2024/2/25 20:29, Eric W. Biederman wrote: > wenyang.linux@foxmail.com writes: > >> From: Wen Yang <wenyang.linux@foxmail.com> >> >> Since these static variables (ue_zero and ue_int_max) are only used for >> boundary checks and will not be changed, remove it and use the ones in >> our shared const array. > > What happened to the plans to kill the shared const array? > > You can still save a lot more by turning .extra1 and .extra2 > into longs instead of keeping them as pointers and needing > constants to be pointed at somewhere. > > As I recall the last version of this actually broke the code, > (but not on little endian). > Thank you. While developing a driver recently, we accidentally discovered some redundant code related to extra1/extra2, so we tried to optimize it a bit. Thank you for your comments. This plan (kill the shared const array) seems meaningful and should require some work. We are very willing to participate. I am glad to receive your feedback. This plan (kill the shared const array) seems meaningful and should require a lot of work. We are very willing to participate. > This one if the constants are properly named looks better > than that, but I don't see any reason why you want shared > constants for such a handful of things. Especially when > it has proven to be error prone in the past. > This patch series replaces multiple static variables (such as zero, two_five_five, n_65535, ue_int_max, etc) with some unified macros (such as SYSCTL_U8_ZERO, SYSCTL_U8_MAX, SYSCTL_U16_MAX, etc.). Although according to the current implementation of sysctl, these macros are currently defined as pointers to the elements of this shared array, and they can also be easily switched from pointers to appropriate numbers when the shared array of sysctl is removed according to the above plan. So the current patch series is also beneficial for subsequent optimization, that is, deleting this shared const array. > The only people I can see who find a significant benefit by > consolidating all of the constants into one place are people who know > how to stomp kernel memory. > As above, thanks. -- Best wishes, Wen > > >> >> Signed-off-by: Wen Yang <wenyang.linux@foxmail.com> >> Cc: Luis Chamberlain <mcgrof@kernel.org> >> Cc: Kees Cook <keescook@chromium.org> >> Cc: Joel Granados <j.granados@samsung.com> >> Cc: Christian Brauner <brauner@kernel.org> >> Cc: "Eric W. Biederman" <ebiederm@xmission.com> >> Cc: Shuah Khan <skhan@linuxfoundation.org> >> Cc: linux-kernel@vger.kernel.org >> --- >> kernel/ucount.c | 7 ++----- >> 1 file changed, 2 insertions(+), 5 deletions(-) >> >> diff --git a/kernel/ucount.c b/kernel/ucount.c >> index 4aa6166cb856..05bbba02ae4f 100644 >> --- a/kernel/ucount.c >> +++ b/kernel/ucount.c >> @@ -58,17 +58,14 @@ static struct ctl_table_root set_root = { >> .permissions = set_permissions, >> }; >> >> -static long ue_zero = 0; >> -static long ue_int_max = INT_MAX; >> - >> #define UCOUNT_ENTRY(name) \ >> { \ >> .procname = name, \ >> .maxlen = sizeof(long), \ >> .mode = 0644, \ >> .proc_handler = proc_doulongvec_minmax, \ >> - .extra1 = &ue_zero, \ >> - .extra2 = &ue_int_max, \ >> + .extra1 = SYSCTL_LONG_ZERO, \ >> + .extra2 = SYSCTL_LONG_S32_MAX, \ >> } >> static struct ctl_table user_table[] = { >> UCOUNT_ENTRY("max_user_namespaces"),
diff --git a/kernel/ucount.c b/kernel/ucount.c index 4aa6166cb856..05bbba02ae4f 100644 --- a/kernel/ucount.c +++ b/kernel/ucount.c @@ -58,17 +58,14 @@ static struct ctl_table_root set_root = { .permissions = set_permissions, }; -static long ue_zero = 0; -static long ue_int_max = INT_MAX; - #define UCOUNT_ENTRY(name) \ { \ .procname = name, \ .maxlen = sizeof(long), \ .mode = 0644, \ .proc_handler = proc_doulongvec_minmax, \ - .extra1 = &ue_zero, \ - .extra2 = &ue_int_max, \ + .extra1 = SYSCTL_LONG_ZERO, \ + .extra2 = SYSCTL_LONG_S32_MAX, \ } static struct ctl_table user_table[] = { UCOUNT_ENTRY("max_user_namespaces"),