From patchwork Sat Nov 23 18:11:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jinliang Zheng X-Patchwork-Id: 13883908 Received: from mail-pl1-f181.google.com (mail-pl1-f181.google.com [209.85.214.181]) (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 867892AE90; Sat, 23 Nov 2024 18:11:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732385499; cv=none; b=oAuPTyEl0hMvB/f29k6d4wqxt9X77VBMOJZZzUwlJab/7XjQF5kcAQtNJDq4oEOCKpDK62w8qEvbWgIQ4q+NyFRf/4sFxtflHRp5jvoHGiIQhybvhoJT7Zu2wQc30uyFcniJyedeC1KMwddFam12CZ3xHh6mbsrdV03zzAdZEvQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732385499; c=relaxed/simple; bh=4OWydb0uad+cSg6XEwN8/7A1yX2vzbSXD+Cg2vpFN7I=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=nLMNze4D655FfIPPlgesv7TECZsuCndQaFs91AAvtbvBGQgh+Cu4qNuv4uNVKiJbPBqGW1HYQzR7Cm9y2PADBk6FIjBu5jPtSp8nRaYVxa9jV21G/eUq/Yrkzsm/9uZJ5d1RABqd+1V4pgp6oyRTEr/zzKGPXmJFThyhENdyAvs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=FxS6rn8K; arc=none smtp.client-ip=209.85.214.181 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="FxS6rn8K" Received: by mail-pl1-f181.google.com with SMTP id d9443c01a7336-2126408cf52so26888745ad.1; Sat, 23 Nov 2024 10:11:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1732385498; x=1732990298; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=aRKUntj3FsK+vGHd9SV+LXgOh6pOpY3AJO079Y2j5WQ=; b=FxS6rn8KH1KB466XUAMWQaXix9z7Q93LOzvWdl6cw/oOIATqrJviNV5SdNDyqbYzY7 Ts6o25nv71JUFtr++A6Os8W+KBuPwtUP3TECcAgIXNgtajL9v4dklbK1T0JEgX8qxLFE 9LJNKqPKaAIM/8X3pGDYxz5bCCrkKug+cSKK0I5j0CRs9WA9rjvCmh23j972wdTgCf+d MQoo1fwhl8dhKFHVE+xoaetbRBrzugyKxaWcAJkRrgrZ1bvcZGDZFdBn7aQqNq40+Ihy NFQuJ06vnperJm7vNETc6xG8GRO9SgQX/LqGAu5Oi0kiHNc2UAkllNo+jaiCRhixNakR A06g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732385498; x=1732990298; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=aRKUntj3FsK+vGHd9SV+LXgOh6pOpY3AJO079Y2j5WQ=; b=AufvZ9IwmY2g3cVWELmsmZsfgIbrqw3VD2j4zU4i/VEja3HkpYmCj4EzmmHM7r8VVp zKh2yvSAdOCgplUWEUpZyXW3OW/LyHt+50kVuESLuM45SOBfc8NX8y/PkSZk6/zDc5XZ xH4B9fZC1ETxpMx2AzBdRCOuiGh/uze8t8OossLFTwB6S+qXIq2VNGg3LS6wTMGynm5L 2pBH24jhD6jlmYou5LAcnlfOO5ae4X0CZAeBYvkz+yuoEr/V/AWLYC0RD4itvaxtN3PK qt8M7hQKBKrr2GMl6908D45RRGHSOwN+HVpC0/Q6QcTV5Bb7pQFKjQZlk7hTfbev5qP8 mFhA== X-Forwarded-Encrypted: i=1; AJvYcCVdyPMaAkTg7SNSXEdKjIttGvYmMDlC3MIw/A/8mg8wbwUyfT0CHqCPhQROO98jSqtAFR5AHtRhlILqqZ7L@vger.kernel.org, AJvYcCXbmPuKdyfc/s6Bl6h/nss0Qt1Z+tOtRGLGhgJmM6HpqpZsjA7j2xGmROnK397QccejVrkDZXZf9dad+LIp@vger.kernel.org X-Gm-Message-State: AOJu0YxSvf7SV3rKzP5syhJkUJZIbAvOh5EDOAcBguE/iIOgtzkLTSqV baF176GI3JaJo+mEp/lGDNiKUyhjI9CsTIC5V8g1hRI4g9hnPsHu X-Gm-Gg: ASbGncuDzpcVbDHjd8R9mQvx6Y5wxjsLAJbcn/VhpfZekpCBPjy+6M+6HCVknJ/gUCO nWm8cy4kwQnBlkKuPLd9Kd+b1+XW1CFZ5FIOcjcm16NzrjpC85y8aZ3jJrZ9HT6FFgBIvys4qWc w5tjh3gyinuPkbD6GtqBcRrXE4SYU2w/ggCz0IeQ2lIlQDs/GXOZj5MkOAG2sHoGbyHCy1NXHbm BXUJdrfEBFVmEKubjBFfVDmx+ko8Qn/3LK1BsGgMqbl5XEakCfmFG/hTyqFgd4u1g== X-Google-Smtp-Source: AGHT+IH7JsT2i9QyVrPXyB5XpQoB19pl05nm3HgNi3l9Ub1OwD1IcHz4rt2GMP3yfLk7QKZTpx7TiA== X-Received: by 2002:a17:902:fc50:b0:212:9b1:e580 with SMTP id d9443c01a7336-2129f7d6f95mr91193985ad.56.1732385497753; Sat, 23 Nov 2024 10:11:37 -0800 (PST) Received: from localhost.localdomain ([119.28.17.178]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2129dc2c5fcsm34512885ad.280.2024.11.23.10.11.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 23 Nov 2024 10:11:37 -0800 (PST) From: Jinliang Zheng X-Google-Original-From: Jinliang Zheng To: alexjlzheng@gmail.com Cc: adobriyan@gmail.com, alexjlzheng@tencent.com, brauner@kernel.org, flyingpeng@tencent.com, jack@suse.cz, joel.granados@kernel.org, kees@kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, mcgrof@kernel.org, viro@zeniv.linux.org.uk Subject: [PATCH 1/6] fs: fix proc_handler for sysctl_nr_open Date: Sun, 24 Nov 2024 02:11:28 +0800 Message-ID: <20241123181128.183232-1-alexjlzheng@tencent.com> X-Mailer: git-send-email 2.41.1 In-Reply-To: <20241123180901.181825-1-alexjlzheng@tencent.com> References: <20241123180901.181825-1-alexjlzheng@tencent.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Use proc_douintvec_minmax() instead of proc_dointvec_minmax() to handle sysctl_nr_open, because its data type is unsigned int, not int. Fixes: 9b80a184eaad ("fs/file: more unsigned file descriptors") Signed-off-by: Jinliang Zheng --- fs/file_table.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/file_table.c b/fs/file_table.c index 976736be47cb..502b81f614d9 100644 --- a/fs/file_table.c +++ b/fs/file_table.c @@ -128,7 +128,7 @@ static struct ctl_table fs_stat_sysctls[] = { .data = &sysctl_nr_open, .maxlen = sizeof(unsigned int), .mode = 0644, - .proc_handler = proc_dointvec_minmax, + .proc_handler = proc_douintvec_minmax, .extra1 = &sysctl_nr_open_min, .extra2 = &sysctl_nr_open_max, }, From patchwork Sat Nov 23 18:11:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jinliang Zheng X-Patchwork-Id: 13883910 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 2347B2AE90; Sat, 23 Nov 2024 18:11:50 +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=1732385512; cv=none; b=LyXAsxz6i1fpYuHC8XwjaKAzRDLJSXZhG/VPJmt5WfyIkzJfOZwCoQRdTArlH88Hw7l9P8Bx/y7W/gPUU8JB8l69bLFuCIIgGTfpw9rcJBi2zK9NFbo1weZQBTYfnZIwgk4Jl8NUYOFSyybqvIGA4kYe8hR95hA31LVgLc4gUdc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732385512; c=relaxed/simple; bh=6Lkxdcvm3/ZmAjlL+//suKh6QLcBqL8pEISGSo1cVUQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=RZ2JOkDo7UrmGMDQIZiAsMrBJTDE+JvONb/FNIooe9S6bsThXI7rp9406I1MWMH8KvJdR0RMFTK+i1+xdyLZKspbh0dfmL8DXVjkjXgj2oVHq0Iwpi0TrWsLAhH6XipwMkcFMWWz8LsYsyHjvukCwpUWaeJpym8bKKb4e7smIJE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=AWPkESJX; arc=none smtp.client-ip=209.85.214.176 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="AWPkESJX" Received: by mail-pl1-f176.google.com with SMTP id d9443c01a7336-21285c1b196so31316965ad.3; Sat, 23 Nov 2024 10:11:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1732385510; x=1732990310; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=HCmWUQINcg5l3Cgf2L+6a//c0M8qj41ig28Jyltnuf4=; b=AWPkESJXNMlMwwViPTi7eh5BR8XNsVosYV1/KY22iBeoBK9o1pYu+xd+bV9H9TXB6W QUBfIXloOYK0PHIRQKcjIy9FN1jn5+4xwqqvhmzcXcS6T2IkOV+RlqZckFj39D1IG1zn PZV3ORBAn1s8Bo/pMJZnnNBgFbRhYa4mg1hiy9vLo9ZDdTRgmNMsYoJjAYJgzYyh0GwK TNHeQJbZOunJGOMEQ5a3L5w7Hq/6oqq/SttpRsUYveujxiRGI7ZFnqUv/qvDb+0hMqcm ezKG5ebZ//uvMdoFlWz/iHDQIEmObs/SGcLP54i8MSrV+sPlMd0KgKpntE+nNSkru0lq Mj6Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732385510; x=1732990310; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=HCmWUQINcg5l3Cgf2L+6a//c0M8qj41ig28Jyltnuf4=; b=NjZPg5HdWDvHbWB529x4TywjYF2ExBeQZ+5n7nughltbH2OFk6zmADQAYSklA1kXEA zEP5JYj2AQt74QJCZS3co+5vPUTaLmTfoX00LVWFrRdy3IMcZXUPANHZ0fQaN7dq3q8m d38Ti5givI6Pi8bpCEmsya5f1/2+Zz8UpKRDTzFMdT7P2njbQp48QeLl5O9u7G2Gc00Y 4S94xnRu9Ci+Xs+ExMnpGuS4pZzAh+F1TPJnwQYywdXrCqm8PQEk8PYyJrDsShdIF9Np xdZtCfWkYMbSoBUQ0pqt4DG6vXjDjEWXdQj4Rru1soDUDBaK399PpOds6NFzDGujDOoj kIcw== X-Forwarded-Encrypted: i=1; AJvYcCVx1kE0fSqQWUCNHrJxDN3JMjuOmBIHCIoVD5lHZ/bhvygaayaCE0NHn5AfJSbxt5A9YaMBBBLtGkhPunqp@vger.kernel.org, AJvYcCWPzT0pZHEAjJlBpWf1P+byfQdPhcx5K8IRC/SHRnE3cnmxbjEEamKJICaDZbz2T0AfwUKkxiawXjsEmgtx@vger.kernel.org X-Gm-Message-State: AOJu0YxmTTsAzCq2qbdI9dLzTpD32Edod2cFSHb7loCbRsZf7F30yePP dEtUINw/L75UB8JBbqgO1Kfa5Z8V5J6oqIPX5/vRvMLF9updeifY X-Gm-Gg: ASbGncus+iPA4wzTeTO6kLCnIlmcW7dPpv7zjUh/vZQ+e2O/rVBhsnNtd8b6JaaIKSF V6060erEmjvgC2IWCgvUg90Ufl7ac/50VDwOIQnSiwUBstVdU+OYpDR7M7LOXfcXFcadC/joesa BzHNLkpZUMYLiHlBL5YQvwGT8AaxQ+5I332N9FljflwR/VBsPuusvfTYm0dfv37AzLXUuKnqb3R F1+bBocqiUdl/XHy+cmHJyO9bkUjwwxUGoVeYAomOV29x4aMqev+ceMmjRYeVm+Jw== X-Google-Smtp-Source: AGHT+IFOmL3z7QsI/HxpFfU6TXZZCU9ZEbUdhUtFEqpEdw322/gxmm1e6D4TXoJ+iqGIuTiRKOS6sQ== X-Received: by 2002:a17:902:e843:b0:20b:a6f5:2768 with SMTP id d9443c01a7336-2129f65c738mr109443585ad.10.1732385510490; Sat, 23 Nov 2024 10:11:50 -0800 (PST) Received: from localhost.localdomain ([119.28.17.178]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-724e0fca304sm3359333b3a.175.2024.11.23.10.11.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 23 Nov 2024 10:11:50 -0800 (PST) From: Jinliang Zheng X-Google-Original-From: Jinliang Zheng To: alexjlzheng@gmail.com Cc: adobriyan@gmail.com, alexjlzheng@tencent.com, brauner@kernel.org, flyingpeng@tencent.com, jack@suse.cz, joel.granados@kernel.org, kees@kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, mcgrof@kernel.org, viro@zeniv.linux.org.uk Subject: [PATCH 2/6] fs: make files_stat globally visible Date: Sun, 24 Nov 2024 02:11:44 +0800 Message-ID: <20241123181144.183326-1-alexjlzheng@tencent.com> X-Mailer: git-send-email 2.41.1 In-Reply-To: <20241123180901.181825-1-alexjlzheng@tencent.com> References: <20241123180901.181825-1-alexjlzheng@tencent.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Signed-off-by: Jinliang Zheng --- fs/file_table.c | 2 +- include/linux/fs.h | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/fs/file_table.c b/fs/file_table.c index 502b81f614d9..db3d3a9cb421 100644 --- a/fs/file_table.c +++ b/fs/file_table.c @@ -33,7 +33,7 @@ #include "internal.h" /* sysctl tunables... */ -static struct files_stat_struct files_stat = { +struct files_stat_struct files_stat = { .max_files = NR_FILE }; diff --git a/include/linux/fs.h b/include/linux/fs.h index 7e29433c5ecc..931076faadde 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -89,6 +89,7 @@ extern void __init files_maxfiles_init(void); extern unsigned long get_max_files(void); extern unsigned int sysctl_nr_open; +extern struct files_stat_struct files_stat; typedef __kernel_rwf_t rwf_t; From patchwork Sat Nov 23 18:12:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jinliang Zheng X-Patchwork-Id: 13883912 Received: from mail-pl1-f175.google.com (mail-pl1-f175.google.com [209.85.214.175]) (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 F2D92195; Sat, 23 Nov 2024 18:12:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.175 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732385572; cv=none; b=N9hgXHDeW2BhdqDPp5nsyJrIJ0HAJUcMOfRC9E547iH5y3GDuPAQ+NWdAzhFO9RmwLIxxOwlHPFqR0TPGaZBOQ7y6N/Cw97VmbivVKQH4MwmygteuS6vrkoyhTiecEjWdaYNn6hxRttXDe839IJ5XErDgUj1oE29zdc0IsfzyCc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732385572; c=relaxed/simple; bh=R2R1bJvC1JbLXYePWO1fLTwbinni8hNJ5PB3vLNn5K0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=VlSLwBDm8/8nLVp2xvFi1agAfL94NWmSi8QLN6xFCJYIpcf3+ETlehbnOrJC8ycPofmg7je3BW33eqII2QecKw7zNTzUSsRiAEVtgxfFWW8pGM0OWG8LcaJPyS81aJ5w6DD6m2GFzTsJv04O2jGdUZBX1EK/N3j4VLzbZ1d/HFE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=BsSutRg6; arc=none smtp.client-ip=209.85.214.175 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="BsSutRg6" Received: by mail-pl1-f175.google.com with SMTP id d9443c01a7336-2126408cf31so23483575ad.0; Sat, 23 Nov 2024 10:12:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1732385570; x=1732990370; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=6mGwjePj2X/S6Q0LK/ColR4L57+PTf7RXOd0t5g9s6I=; b=BsSutRg6PUsPAXcFapMwIij4D7xLGQtWmq82EZGmNKfddgjPBlnKxdalTQucRBeyZf PciDs+WrkyxKoJTY3eWa+6Y75R/bbwR/bPiAgJg2K3WDCF49pTDmszp2aZBpDgTAWTwb jx7dhb1pMYj53iRI04+yv574Xl9Kf9WCKGLFoHJ5tquvJZJB0kwZLI2bL4/U5JoczD9r WryAuQUsRAt4diNxdzm3poQXLht+eqebkjiugzyz/N80/OooS3UMlH5daGbgMr9So/Sb GKsDym9r2QtodimeIB+s5e9QDg+7lMevy3myuWXWhezYzYnX2DB470GTtnpISLjkL00d tczw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732385570; x=1732990370; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=6mGwjePj2X/S6Q0LK/ColR4L57+PTf7RXOd0t5g9s6I=; b=vUUyUVu8uwuHUbiDALYVBJQSRxl0EKU2I3Oh766Wc1GnvZt/lv7CHC3VbOnyE0/Nfj 2igp+P16gXKI6wvE6ZlR1v77uBJpcHQFUEZYYeRqHQNxDc2XGLuO4wwKWQsawqGMUfHA Z5mcDOR8hupMjKCFvyspof6o4THsB8wuXQQwJqdu6vl0YDXTX8xBfkVluCl1bBv0HCmi 48BRU4bfmnpLl3FORHRWxDxpPNmGcHInJk4APkRkq2d9l2wzJ3HTRReMkAGoE3uUI5eo HPTeLKUB5fl1RGDmDXHlV33VUPpTNqdVGL3WUWz+8VZGa9L6+z0oC1BRmN233OJKQfbL /88A== X-Forwarded-Encrypted: i=1; AJvYcCU9Y0XlLnlFo9sQL4LBVqnHlKmski0BP3DSno6r6WUGkTj1IDk6eAqIBG8GVDXRs3H+UlFbSsY/MBBFU4MU@vger.kernel.org, AJvYcCWJmPm9myCd4F0gCYqC3rwQrMkRU7cyKh/rYIpuwgXpIDJtqXkd76Qu2Ylm7++WxN3kWgKHLtLcFxlZG8+8@vger.kernel.org X-Gm-Message-State: AOJu0YwWj0baP1pGVZRfNvtCd23W2d4drDP6Fcmsd9bTCgWL0XRsS7L9 sLS6Ydw5uZ0RcW2DbSPqhi3s8fCK6UeU4wIcBkI6gYsEq4Jzr2+jkwYq8w== X-Gm-Gg: ASbGncsEGRO7iZJ4bZlbaxkXdeqgyoLuQAOjGE6g36OgpqGX2mV8fLm4sJIqc+OWyJ9 H+AQQez9NJ/6kkzIQY6WxGsux/XDeB8KvnXV5Ru32czRoGROkJfPNHX3ZMLXBhIZRkv9ycJnar1 tU5SjRaQUb6oagTDeGJH/idlso+KIV2ujr4pCKXZ+83kTSoDxE427u8c2ilI/7X461IEIZP7SgT XN8DxxAWvamHjcjUrvrQmlCMBsDJUYGuTX5p8IqmlAhA97PCVhlsGS/CutTm16/Ww== X-Google-Smtp-Source: AGHT+IFp9UCIDEv0Gz0cA9PNGKtpFJy6qbbAmWV3AZj7ST53U3JGReI0r6WzfznTycx67ZquKXpIZA== X-Received: by 2002:a17:902:dac5:b0:212:500:74e with SMTP id d9443c01a7336-2129f51d2c6mr104835925ad.11.1732385570210; Sat, 23 Nov 2024 10:12:50 -0800 (PST) Received: from localhost.localdomain ([119.28.17.178]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2129dc1746fsm35555305ad.219.2024.11.23.10.12.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 23 Nov 2024 10:12:49 -0800 (PST) From: Jinliang Zheng X-Google-Original-From: Jinliang Zheng To: alexjlzheng@gmail.com Cc: adobriyan@gmail.com, alexjlzheng@tencent.com, brauner@kernel.org, flyingpeng@tencent.com, jack@suse.cz, joel.granados@kernel.org, kees@kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, mcgrof@kernel.org, viro@zeniv.linux.org.uk Subject: [PATCH 3/6] sysctl: refactor __do_proc_doulongvec_minmax() Date: Sun, 24 Nov 2024 02:12:44 +0800 Message-ID: <20241123181244.183918-1-alexjlzheng@tencent.com> X-Mailer: git-send-email 2.41.1 In-Reply-To: <20241123180901.181825-1-alexjlzheng@tencent.com> References: <20241123180901.181825-1-alexjlzheng@tencent.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Extract the local variables min and max as parameters in __do_proc_doulongvec_minmax() to facilitate code reuse in subsequent patches. There are no functional changes. Signed-off-by: Jinliang Zheng --- kernel/sysctl.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/kernel/sysctl.c b/kernel/sysctl.c index 79e6cb1d5c48..05b48b204ed4 100644 --- a/kernel/sysctl.c +++ b/kernel/sysctl.c @@ -1020,9 +1020,10 @@ static int sysrq_sysctl_handler(const struct ctl_table *table, int write, static int __do_proc_doulongvec_minmax(void *data, const struct ctl_table *table, int write, void *buffer, size_t *lenp, loff_t *ppos, - unsigned long convmul, unsigned long convdiv) + unsigned long convmul, unsigned long convdiv, + unsigned long *min, unsigned long *max) { - unsigned long *i, *min, *max; + unsigned long *i; int vleft, first = 1, err = 0; size_t left; char *p; @@ -1033,8 +1034,6 @@ static int __do_proc_doulongvec_minmax(void *data, } i = data; - min = table->extra1; - max = table->extra2; vleft = table->maxlen / sizeof(unsigned long); left = *lenp; @@ -1095,8 +1094,10 @@ static int do_proc_doulongvec_minmax(const struct ctl_table *table, int write, void *buffer, size_t *lenp, loff_t *ppos, unsigned long convmul, unsigned long convdiv) { + unsigned long *min = table->extra1; + unsigned long *max = table->extra2; return __do_proc_doulongvec_minmax(table->data, table, write, - buffer, lenp, ppos, convmul, convdiv); + buffer, lenp, ppos, convmul, convdiv, min, max); } /** From patchwork Sat Nov 23 18:12:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jinliang Zheng X-Patchwork-Id: 13883913 Received: from mail-pg1-f172.google.com (mail-pg1-f172.google.com [209.85.215.172]) (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 9BEB02AE90; Sat, 23 Nov 2024 18:13:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732385584; cv=none; b=clLQF4LgT9kk20Jw21JgUMHx3z2avLL81SqbWYgT1Yauex/JHKkiJskkQk5Fv6ulSM1bZVsfim1Or1v2BBxEA3GSSn7iOInjbb7OxyT6MxjvumyRcN8kYCI7ONN9vWDUoQ2+eOBK0VACZl+3GxeUY2aB3S9ADWstE7PLSlTdaXY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732385584; c=relaxed/simple; bh=ByC/Z6r7l+hea8zqsjcZiQtqqoWRnkIS18YTDSe6o88=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Xf0KgYhpYL3IGbrCLgoGTIVfL1GX7f0H1gg1Te2kKL811pfHs/UqQ0dKyG6C/h3F2kDS45l7oIegvEyPo5kDfKCbx2EIJjuaX7mTw8MRQJHgWQfy6H0jA6QlazoaHtl7SWPABMO4hQwpq7bqswmIYTNtMv7+7WMP5z/0ggiMQBM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=G4/zPpNJ; arc=none smtp.client-ip=209.85.215.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="G4/zPpNJ" Received: by mail-pg1-f172.google.com with SMTP id 41be03b00d2f7-7ee6edc47abso2382738a12.3; Sat, 23 Nov 2024 10:13:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1732385582; x=1732990382; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Yi7/4Il6m4z1prw3HItGvYyciFoIT2EmfSe3QDrC7Gk=; b=G4/zPpNJKlSNuK873l43xZeedWtAChB+5jVLE/cqKoDdfOyHBraFbL/Ak81PeSlUwY a+W2Q3V4IVyQ3Onbdu16u6bpEsaRKrBtsySVMgkF3Pqvb6NA/NOQqbg6iO44iX/XFzca +IQ6p1s4av30kM8LKi/lHTsyL2vW9kT2+YJ04ZR4Tr620WJ68p6+Zx2KJ/hKIvlNV4C5 nxco7zJ2D+hnhfxp7hgfciu+uc8LnV5cdKaBLGPSLm/I9KpRk5QLTddPfGtC3fyUmWTF 6wJTofSsrxU4XfXxHRnqimeUFrTsLm1JbOpEjkT4DP7Duh2mPTZRLk/ZkhSGkVfQJgRs HOVA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732385582; x=1732990382; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Yi7/4Il6m4z1prw3HItGvYyciFoIT2EmfSe3QDrC7Gk=; b=Ux6yLdercpI5EuvSIUVkn9HYEBt3VoVBd8+gsu/X6vckAgDJUuQgSEIPLAuGSaOEzp pQnKx9lj1VtZ1c577fTAo71b9xGyr2mcw6nD0uaHOTC4EiGP3l963vWdNp+bY5vqBWKg cUkaclXy5jQvsgWJXSkSL/RSVCpDC4fGKlbobCHUSc1AUMIKFotjsnEVRkOITcRcae4a HzYOt7bzaMxKQFiBdfxA8bdDbAHqZXADrMdItCQO5PxlrfR2Xk0TRMJgViXDGIHFoL0u RNq2/3HrrqArCz00S95QZ27q4VYHB3hcc/LmcU3N81yspKjTHlhLotylOmPdAOD59dRS rCsQ== X-Forwarded-Encrypted: i=1; AJvYcCVZjNCplmvqWunsPgSrWMR4xG9GpKaxL3+t9Ptg35pAsdbS4oywxg5BOt3hDybm0+dNYR1uq2rjEWFalILZ@vger.kernel.org, AJvYcCXZk+a7cmVvacw/NZRhWxBeYwbDOrRm0IavU+gEzS+4hl9Qak8TWzPA5C7X0msWVQzyg1/cpRPp+yMxUFwP@vger.kernel.org X-Gm-Message-State: AOJu0YyvVoSFapU0HR2DL3/frmVd5rqEURF3dg9S+niJ5yQc8Dd6R/JY J+wqHwOj9m+GwCGifv0HqQucJHvcLnPXohMFOt6qiCKSS/WxsBkH X-Gm-Gg: ASbGncvGQmKfazWZQ2lK1rR5ImtTjnuWbXgcpFThMTI6Bu+Dp1ZkjVef400tH1/07Tz ap0F080CqvOZk2EvOqMsmeLOrdo8lFLnCe2SNwqkYb9hpSW3LdQSIi8vJRlG4+emPzIa9Wj9Qxa 7qh8qm1dLpcN2U5wa05zZNy7SoLKmpKsDBKNezDQvla3A/ds5CacgteFK0Tl8KfqvGma8dNi5eH EtGMKuTEZpDEUVYh8tTUXbY+7FudVhN8WoHchxUKdfUWmT2xzkrKz27ArQ0QeU2zQ== X-Google-Smtp-Source: AGHT+IGVB/psrgXrHZ5x7kwrUPVWwcgPghBpElQMOKTK2PDbio6Qo4nr3pWgdKBTbACDka6k2gWrBg== X-Received: by 2002:a05:6a21:78a8:b0:1db:e49a:d54a with SMTP id adf61e73a8af0-1e09e45744emr10208153637.19.1732385581909; Sat, 23 Nov 2024 10:13:01 -0800 (PST) Received: from localhost.localdomain ([119.28.17.178]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-724ec041406sm2321062b3a.79.2024.11.23.10.12.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 23 Nov 2024 10:13:01 -0800 (PST) From: Jinliang Zheng X-Google-Original-From: Jinliang Zheng To: alexjlzheng@gmail.com Cc: adobriyan@gmail.com, alexjlzheng@tencent.com, brauner@kernel.org, flyingpeng@tencent.com, jack@suse.cz, joel.granados@kernel.org, kees@kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, mcgrof@kernel.org, viro@zeniv.linux.org.uk Subject: [PATCH 4/6] sysctl: ensure files_stat.max_files is not less than sysctl_nr_open Date: Sun, 24 Nov 2024 02:12:56 +0800 Message-ID: <20241123181256.184004-1-alexjlzheng@tencent.com> X-Mailer: git-send-email 2.41.1 In-Reply-To: <20241123180901.181825-1-alexjlzheng@tencent.com> References: <20241123180901.181825-1-alexjlzheng@tencent.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Introduce proc_doulongvec_maxfiles_minmax(), ensure the value of files_stat.max_files is not less than sysctl_nr_open. Signed-off-by: Jinliang Zheng --- fs/file_table.c | 2 +- include/linux/sysctl.h | 2 ++ kernel/sysctl.c | 17 +++++++++++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/fs/file_table.c b/fs/file_table.c index db3d3a9cb421..01faa9c2869e 100644 --- a/fs/file_table.c +++ b/fs/file_table.c @@ -119,7 +119,7 @@ static struct ctl_table fs_stat_sysctls[] = { .data = &files_stat.max_files, .maxlen = sizeof(files_stat.max_files), .mode = 0644, - .proc_handler = proc_doulongvec_minmax, + .proc_handler = proc_doulongvec_maxfiles_minmax, .extra1 = SYSCTL_LONG_ZERO, .extra2 = SYSCTL_LONG_MAX, }, diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h index aa4c6d44aaa0..4ecf945de956 100644 --- a/include/linux/sysctl.h +++ b/include/linux/sysctl.h @@ -82,6 +82,8 @@ int proc_dointvec_userhz_jiffies(const struct ctl_table *, int, void *, size_t * int proc_dointvec_ms_jiffies(const struct ctl_table *, int, void *, size_t *, loff_t *); int proc_doulongvec_minmax(const struct ctl_table *, int, void *, size_t *, loff_t *); +int proc_doulongvec_maxfiles_minmax(const struct ctl_table *, int, void *, + size_t *, loff_t *); int proc_doulongvec_ms_jiffies_minmax(const struct ctl_table *table, int, void *, size_t *, loff_t *); int proc_do_large_bitmap(const struct ctl_table *, int, void *, size_t *, loff_t *); diff --git a/kernel/sysctl.c b/kernel/sysctl.c index 05b48b204ed4..5ee2bfc7fcbe 100644 --- a/kernel/sysctl.c +++ b/kernel/sysctl.c @@ -1122,6 +1122,23 @@ int proc_doulongvec_minmax(const struct ctl_table *table, int write, return do_proc_doulongvec_minmax(table, write, buffer, lenp, ppos, 1l, 1l); } +/* + * Used for 'sysctl -w fs.file-max', ensuring its value will not be less + * than sysctl_nr_open. + */ +int proc_doulongvec_maxfiles_minmax(const struct ctl_table *table, int write, + void *buffer, size_t *lenp, loff_t *ppos) +{ + unsigned long *min = table->extra1; + unsigned long *max = table->extra2; + unsigned long nr_open = sysctl_nr_open; + + if (write) + min = &nr_open; + return __do_proc_doulongvec_minmax(table->data, table, write, + buffer, lenp, ppos, 1l, 1l, min, max); +} + /** * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values * @table: the sysctl table From patchwork Sat Nov 23 18:13:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jinliang Zheng X-Patchwork-Id: 13883914 Received: from mail-pj1-f42.google.com (mail-pj1-f42.google.com [209.85.216.42]) (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 6CE5D156F3A; Sat, 23 Nov 2024 18:13:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732385596; cv=none; b=XrhU1UH5rfGzSdtbUTDQuVyO9SKQ6Nho19CCTFf4A8nmCRD84K3DyEfpO9G90pM6lX/NPZn9/S4LWCepbFLW+DDIGzLRhLAg87LbP2C3W+4qvlSJF5K5koCIez0Qp/Ada6BVtnExDXW2D/XhX6b+XTu8a8YCptNtvnwa7Sjvpyw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732385596; c=relaxed/simple; bh=Npxa+HJYQa0mjfNuQEiqTLLB9c3WY8PZwAVhQU8fIaM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=JfhKpAgBSoXLp3gdtJ6rOIIZtGZM14g65Vs9++YDvUBwl/JPlowE8euT01bWZAptC0B9jFGUox2x0b5WSeB/NGkYVv0sgfW3NUq6gvx4opYmEONde3Aog8p+5YEJHf0ywHxHklSmM3sXtpvIObhLQyh7u4D0Ia8Su7+UTaYCDIk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=iWDVR0rV; arc=none smtp.client-ip=209.85.216.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="iWDVR0rV" Received: by mail-pj1-f42.google.com with SMTP id 98e67ed59e1d1-2ea4d429e43so2572241a91.3; Sat, 23 Nov 2024 10:13:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1732385595; x=1732990395; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=kHYJzxn/9mDcQtzwabJ2ppWw/ZPZ6ejLQTI/1mfqL54=; b=iWDVR0rVTvqI5cwDIERWcD2qx+2D+u0MKaFFuis8ShxbVYnfRZK2LhuyDggVWfdfNu hzk/tIiwXI5x1VrMRrK5lj2CBAB8U/RxWGn1RpWOswIdo3e4jp6tcN1gn9wYdzAdBVcl roKhsCU1wjqNIO5M4IZwLxLbN6NzES3lgCSlf4AxKzbaR64/OgY4/W9eu2ODDz8zEGvp np55D46pz2HO3U4wC4giyGajXw1/J+SdZwG8HeYE3vABiuyTGqhhrDEyAay8u0JlSXXT al8ZuEUGOrsYl3ZbbYIePRWl5vfk+WKuOUjgJf3A3+H588s7A1Mml1JEW1VTW6EGqP8o panA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732385595; x=1732990395; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=kHYJzxn/9mDcQtzwabJ2ppWw/ZPZ6ejLQTI/1mfqL54=; b=mJgp/9S7QS7+st9iqN/zObA0HGmWt7PRPB3Uh0MqQgz8uDaW6pwnA4MK2Hkp7eUUlY QJhO0F7wFf7cd2WuRQCH2AGckMT22VnR3ZHzUya7IKfkSzyIpq9UxkOAs2kMw8/bOs08 ce/0xqAX5AFIrhxwpkuKa7rNaLyAV4exgZ0oXrjh7yYZSo8o9aVnwQge+iIx7NSMIac/ uiGDnXFpmiUJksxsqpwQvzMMdJQusTi3D0zl/Fi7G3oQ9JRPJZPGZ09hh1okliuOcCW4 eNV9Mo28wP3mk+kqMoPmG3px8hp2M0CPblkbixNc/6AzPos7pw/G8a83djNue51He7ZL g69w== X-Forwarded-Encrypted: i=1; AJvYcCV2VzCnTRWJau4ntrD0lORLjbQwcJN8SLedvhjZnmYVpWSqYpdTZGt0shdzdQ5f0paQ81njoV8tQgWBRM02@vger.kernel.org, AJvYcCXFMDPibKIsy93bevfsIz0ICCaXUF95ajaoruAjCRqp8saQhpBb5sG2gq3SOToIkElKWAMQPNLa5Hy7M464@vger.kernel.org X-Gm-Message-State: AOJu0YzpRkq0mRR8bYqZwpUUccKTfjOZyrw65Ku/JQzI/E8bxEMYBxxL gENX4AC39JJ3mHoifcpLOcDlOuID77cxsOdvhBBo8xtPBI936RZW X-Gm-Gg: ASbGncvyna9icn6ewk7YCaXo1DzIqa5cMul49y0KkuShptdMSmI1TwFSQGadNNXjC4e jbqkr0Duo6fPubDaDsJzjOQAj/93SHKX6fQLLZeze5nRL0x8uzYmBuaETKtANOSlumlVKTGEruh 9NxrGOTvXkRhliBO2A8yYtz+wuUQbHAH9m+O0xz9y1m0llbXINaxJCrpP+ZOKWUL+sZq0EW1enU kgT3CvmRzkyKcUZtrdXCfU71lnW/1wZWFoxQBQY8IURlxlqyc2U4N9LuUcVJXXdKQ== X-Google-Smtp-Source: AGHT+IFvWLR++Afy5oXhKNrCYBN0L6MI4zrKjPePWbQ71RPvoIuQKWS++OBaafYZ/LTctWs2dNcatA== X-Received: by 2002:a17:90b:38ca:b0:2ea:97b6:c44d with SMTP id 98e67ed59e1d1-2eb0e2369f2mr9572206a91.15.1732385594656; Sat, 23 Nov 2024 10:13:14 -0800 (PST) Received: from localhost.localdomain ([119.28.17.178]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2eaafadde27sm6692793a91.0.2024.11.23.10.13.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 23 Nov 2024 10:13:14 -0800 (PST) From: Jinliang Zheng X-Google-Original-From: Jinliang Zheng To: alexjlzheng@gmail.com Cc: adobriyan@gmail.com, alexjlzheng@tencent.com, brauner@kernel.org, flyingpeng@tencent.com, jack@suse.cz, joel.granados@kernel.org, kees@kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, mcgrof@kernel.org, viro@zeniv.linux.org.uk Subject: [PATCH 5/6] sysctl: ensure sysctl_nr_open is not greater than files_stat.max_files Date: Sun, 24 Nov 2024 02:13:08 +0800 Message-ID: <20241123181308.184294-1-alexjlzheng@tencent.com> X-Mailer: git-send-email 2.41.1 In-Reply-To: <20241123180901.181825-1-alexjlzheng@tencent.com> References: <20241123180901.181825-1-alexjlzheng@tencent.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Introduce proc_douintvec_nropen_minmax(), ensure the value of sysctl_nr_open is not greater than files_stat.max_files. Signed-off-by: Jinliang Zheng --- fs/file_table.c | 2 +- include/linux/sysctl.h | 2 ++ kernel/sysctl.c | 21 +++++++++++++++++++++ 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/fs/file_table.c b/fs/file_table.c index 01faa9c2869e..43838354ce6d 100644 --- a/fs/file_table.c +++ b/fs/file_table.c @@ -128,7 +128,7 @@ static struct ctl_table fs_stat_sysctls[] = { .data = &sysctl_nr_open, .maxlen = sizeof(unsigned int), .mode = 0644, - .proc_handler = proc_douintvec_minmax, + .proc_handler = proc_douintvec_nropen_minmax, .extra1 = &sysctl_nr_open_min, .extra2 = &sysctl_nr_open_max, }, diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h index 4ecf945de956..ed7400841f82 100644 --- a/include/linux/sysctl.h +++ b/include/linux/sysctl.h @@ -72,6 +72,8 @@ int proc_douintvec(const struct ctl_table *, int, void *, size_t *, loff_t *); int proc_dointvec_minmax(const struct ctl_table *, int, void *, size_t *, loff_t *); int proc_douintvec_minmax(const struct ctl_table *table, int write, void *buffer, size_t *lenp, loff_t *ppos); +int proc_douintvec_nropen_minmax(const struct ctl_table *, int, void *, + size_t *, loff_t *); int proc_dou8vec_minmax(const struct ctl_table *table, int write, void *buffer, size_t *lenp, loff_t *ppos); int proc_dointvec_jiffies(const struct ctl_table *, int, void *, size_t *, loff_t *); diff --git a/kernel/sysctl.c b/kernel/sysctl.c index 5ee2bfc7fcbe..d8ce18368ab3 100644 --- a/kernel/sysctl.c +++ b/kernel/sysctl.c @@ -944,6 +944,27 @@ int proc_douintvec_minmax(const struct ctl_table *table, int write, do_proc_douintvec_minmax_conv, ¶m); } +/* + * Used for 'sysctl -w fs.nr_open', ensuring its value will not be greater + * than files_stat.max_files. + */ +int proc_douintvec_nropen_minmax(const struct ctl_table *table, int write, + void *buffer, size_t *lenp, loff_t *ppos) +{ + unsigned int file_max; + struct do_proc_douintvec_minmax_conv_param param = { + .min = (unsigned int *) table->extra1, + .max = (unsigned int *) table->extra2, + }; + + file_max = min_t(unsigned int, files_stat.max_files, + *(unsigned int *)table->extra2); + if (write) + param.max = &file_max; + return do_proc_douintvec(table, write, buffer, lenp, ppos, + do_proc_douintvec_minmax_conv, ¶m); +} + /** * proc_dou8vec_minmax - read a vector of unsigned chars with min/max values * @table: the sysctl table From patchwork Sat Nov 23 18:13:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jinliang Zheng X-Patchwork-Id: 13883915 Received: from mail-pj1-f49.google.com (mail-pj1-f49.google.com [209.85.216.49]) (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 EBB2413D531; Sat, 23 Nov 2024 18:13:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732385610; cv=none; b=ADy+BRTrKSoVT3K5SVB8TkJiHyEa9EeYx+LcUphDi7ZsUXidkj3vK3FxrP3ybDU7dbjvknZ3MYI33Y+OdWL/pDat2JEhGgwsA2SCcRb7hznw2wCI/ZqEOWMuMPicmpixxAU3zL1onFAsn+OoH+p+4k64WqD/QX+uFrLEa8r7d10= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732385610; c=relaxed/simple; bh=3yuaf8wLNYOLNE2OcdI3jAv0e14pIlTWgpltyhkp7T0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=piNv8Pif6e67YPYVpxux+qtp4i+QJD2MA7s1h+aIlzAG5pzDgQK5eTqvCmNVoh7tbtxrfQ45mKWlNZSTeXwLISsJAjE9OZCOpdEclh0qbohJpWvcvz40bN379HJuaA5pW1ohIeqXv6mjroOq5/bxDOCtJbEb7k0PATXz5avlpjg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=QHJ0pD+N; arc=none smtp.client-ip=209.85.216.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="QHJ0pD+N" Received: by mail-pj1-f49.google.com with SMTP id 98e67ed59e1d1-2ea4c5b8fbcso2310010a91.0; Sat, 23 Nov 2024 10:13:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1732385608; x=1732990408; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=tg3VWdEHX6oI8z2oKUcIZ37Iko16y24re5yLowPrn/U=; b=QHJ0pD+NWOeUz5rWkE9bWm8ru2Th0bj11UP3uABVJuTGrTHa/qXQRpNged5SDi+mK1 8xoPmnYtQgRiiVf/HO77a8mTDf86bUktKGl8mucd71qblSwy34x871u70YkxIHT3d7W/ zqBGyJ9NrQEHG/m18yFeEu5fL0cAFoHFVL/qjZWpMpRaychkcLgH/P54pvJSrj4gpAEk qHTYSVU0mF+sA0TazlFYBSm/y4KwK9EnLzP9baR6NzXMVzjniVvbuoBdVj41TdsQl13h aVzImPoO/1BrVhO2kHzd3ebK1a4Txn92z4DK72qxRKkf6/3G1Rg8Yo0WnlOGUP2SQfFT RDRw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732385608; x=1732990408; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=tg3VWdEHX6oI8z2oKUcIZ37Iko16y24re5yLowPrn/U=; b=ejZnTvq4BlP+jNLTr0TdzKax8ZHw4gCjFh2SSuRKkCW31knHLE/L3Uk+CaqYdzb8Uf mUL+XDhDCEZBoV0vPMASC92CvoGpulwRAInWzLwMa+8rlwWPpaslcI3+AxOfdcX9Vb3z +EOJQ3R3towwYOd8IrOFQRTIahuRfmD7PoXsZrkJILOiZzhS1ORUyxws5J7/uyDyZ7iv Uf8pVGsr8Sxo0DZWr6NUuuQsFM65XzmqaNZxSczXP3zyQe6X7Ku7dnRgoGTawDneJxQe Hv8U3MY/BIl+w6dOMpqsFlEVLEu4CtKvgxvhaG/rP0H3DYfBCK4jii6yptjP4G7Yb5OP B+tA== X-Forwarded-Encrypted: i=1; AJvYcCUEpchNN2v8HTyABTB5/Jue0llcusx5ikCNxBRpwoumNxAjA3mUAHSaWvnjiW8cqNOx1KDvkR2MUGY21B/F@vger.kernel.org, AJvYcCXCXBvApknd3Cg5uNE5wkQHudBj9Jwqw4/H5ElYxSrn82KcFxZ7C6jlp4ewZgUtpz7YXJqlbuWerst1VTbB@vger.kernel.org X-Gm-Message-State: AOJu0YzHKXrmW8C/taH3CpR7F9l8Y+nFZCaTW1D/NhlmHXm4EoGSwMUa PVwVN2x/3gHnGrtBIoEjKYmu666ph4wpmj6Qz5ZlqwerfyIR4DeX X-Gm-Gg: ASbGncsXeC+FyCkwLTIDYt9TUbpVPFwhluPWnZk+7DHq+V6h3ykoqXuQemnpS08oc+P y2Ix2a/OTT53s5SuVBm8bciwEFGKST6EmjKNYM7mXag4jRWQVhFXF0wDyl5BeV/pr8rfo7YJlaM QxBCdEvj0pQZLApDVAfrsFdlTB8YKHDwU9rzrlDUXyIQaFzMkpe2v/oB/kPcCWndJJEXG2aPrZo bciL4V/rVK0wFgCkpBtDp5J52NX/bPXUPQYj49T5v2owAMd0Zc/kUk2rQwb4lMizQ== X-Google-Smtp-Source: AGHT+IFe7yUTW8Zy8xp6HGcEUJRGWfXgagHJd97k1DPmATdS2e6a25O4OwpAwbp6FQdqOqQwZI1+vg== X-Received: by 2002:a17:90b:4b0c:b0:2ea:a9ac:eeec with SMTP id 98e67ed59e1d1-2eb0cbc715cmr11118732a91.18.1732385608169; Sat, 23 Nov 2024 10:13:28 -0800 (PST) Received: from localhost.localdomain ([119.28.17.178]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2eb0cfe4b25sm3662235a91.11.2024.11.23.10.13.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 23 Nov 2024 10:13:27 -0800 (PST) From: Jinliang Zheng X-Google-Original-From: Jinliang Zheng To: alexjlzheng@gmail.com Cc: adobriyan@gmail.com, alexjlzheng@tencent.com, brauner@kernel.org, flyingpeng@tencent.com, jack@suse.cz, joel.granados@kernel.org, kees@kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, mcgrof@kernel.org, viro@zeniv.linux.org.uk Subject: [PATCH 6/6] fs: synchronize the access of fs.file-max and fs.nr_open Date: Sun, 24 Nov 2024 02:13:22 +0800 Message-ID: <20241123181323.184391-1-alexjlzheng@tencent.com> X-Mailer: git-send-email 2.41.1 In-Reply-To: <20241123180901.181825-1-alexjlzheng@tencent.com> References: <20241123180901.181825-1-alexjlzheng@tencent.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Signed-off-by: Jinliang Zheng --- fs/file_table.c | 9 ++++++++- include/linux/fs.h | 1 + kernel/sysctl.c | 18 ++++++++++++++---- 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/fs/file_table.c b/fs/file_table.c index 43838354ce6d..4c0113912d9b 100644 --- a/fs/file_table.c +++ b/fs/file_table.c @@ -37,6 +37,8 @@ struct files_stat_struct files_stat = { .max_files = NR_FILE }; +DECLARE_RWSEM(file_number_sem); + /* SLAB cache for file structures */ static struct kmem_cache *filp_cachep __ro_after_init; static struct kmem_cache *bfilp_cachep __ro_after_init; @@ -102,8 +104,13 @@ EXPORT_SYMBOL_GPL(get_max_files); static int proc_nr_files(const struct ctl_table *table, int write, void *buffer, size_t *lenp, loff_t *ppos) { + int ret; + + down_read(&file_number_sem); files_stat.nr_files = get_nr_files(); - return proc_doulongvec_minmax(table, write, buffer, lenp, ppos); + ret = proc_doulongvec_minmax(table, write, buffer, lenp, ppos); + up_read(&file_number_sem); + return ret; } static struct ctl_table fs_stat_sysctls[] = { diff --git a/include/linux/fs.h b/include/linux/fs.h index 931076faadde..f8f983e5dde6 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -90,6 +90,7 @@ extern void __init files_maxfiles_init(void); extern unsigned long get_max_files(void); extern unsigned int sysctl_nr_open; extern struct files_stat_struct files_stat; +extern struct rw_semaphore file_number_sem; typedef __kernel_rwf_t rwf_t; diff --git a/kernel/sysctl.c b/kernel/sysctl.c index d8ce18368ab3..cf860d0e2c8b 100644 --- a/kernel/sysctl.c +++ b/kernel/sysctl.c @@ -951,18 +951,22 @@ int proc_douintvec_minmax(const struct ctl_table *table, int write, int proc_douintvec_nropen_minmax(const struct ctl_table *table, int write, void *buffer, size_t *lenp, loff_t *ppos) { + int ret; unsigned int file_max; struct do_proc_douintvec_minmax_conv_param param = { .min = (unsigned int *) table->extra1, .max = (unsigned int *) table->extra2, }; + down_write(&file_number_sem); file_max = min_t(unsigned int, files_stat.max_files, *(unsigned int *)table->extra2); if (write) param.max = &file_max; - return do_proc_douintvec(table, write, buffer, lenp, ppos, + ret = do_proc_douintvec(table, write, buffer, lenp, ppos, do_proc_douintvec_minmax_conv, ¶m); + up_write(&file_number_sem); + return ret; } /** @@ -1150,14 +1154,20 @@ int proc_doulongvec_minmax(const struct ctl_table *table, int write, int proc_doulongvec_maxfiles_minmax(const struct ctl_table *table, int write, void *buffer, size_t *lenp, loff_t *ppos) { + int ret; unsigned long *min = table->extra1; unsigned long *max = table->extra2; - unsigned long nr_open = sysctl_nr_open; + unsigned long nr_open; - if (write) + down_write(&file_number_sem); + if (write) { + nr_open = sysctl_nr_open; min = &nr_open; - return __do_proc_doulongvec_minmax(table->data, table, write, + } + ret = __do_proc_doulongvec_minmax(table->data, table, write, buffer, lenp, ppos, 1l, 1l, min, max); + up_write(&file_number_sem); + return ret; } /**