From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f46.google.com (mail-wm1-f46.google.com [209.85.128.46]) (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 BDD5237AA9E for ; Fri, 29 May 2026 17:18:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.46 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780075138; cv=none; b=jEdg7Yiw1I0UqVESCLKwK9j4GGpPQdYXg2gcDsusgOr4GeK3d+85UIdgsu8izPMVobzMmOImVW42K96ETXPI1KuMEYaqNE4qy2qeHomoU1WufyUzDPbroCL+SoP5LlaC8u/TQY/wYN24p2EqzXtKxzTzHbgEsTGDwnoxJSWlv+g= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780075138; c=relaxed/simple; bh=kPRFGm1PpzKTojZpkl1fpPxcxPliwE6WJk5XhCUxa50=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=dHHP2YAPegPyGpiMP34hPp/7rqHIYrJKERXa5I66ro55mN3Be3ugwXNExgC1MKfEHrWDL9PNN5AI5LmbGgjmAa5SEIDuO7IYArdqMVd8dSG6bWVO6rGhQCe1CtVAXtfzfyzQWOlFBAr9v9jel4R2HZnj/+i3qhRvZrWXPJsI2g4= 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=XonvL2ID; arc=none smtp.client-ip=209.85.128.46 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="XonvL2ID" Received: by mail-wm1-f46.google.com with SMTP id 5b1f17b1804b1-4904c1ce4c1so84354355e9.3 for ; Fri, 29 May 2026 10:18:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1780075135; x=1780679935; 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=tZ4vZVcUxh57FWknF9iHwYSifIVXpEFpUueO53nt890=; b=XonvL2ID72Jf20vseryt3U/cWL6sigpsbaS4/H0uOGkaflCi29fQAf8aFbmKUTncht 4e6THe0bsCmM3mhph4+pRG9yFmBEkrBGwuvGnBaVPTc1B1ZhwkbdSDmTWgMCLeUM74ub q+u7c/q/DS+wVlyLhh/OSwPIM5wrw4KiqkO/lPs5aDNq4rtk/fWw/Am/p5l8wiUo9NPl e8/IhmYEVEYjiBXaPAa4yhZEYYXX6XMyKeARBP00qWOyaJTX6BLChSecONVEfl4uE4IM wFfGzDo40ufTWHAsOS06iMzbWG/xF0qjvGjDXQSIMjMxjgIgVmnZvE4O9LD5k86f3q6v HdWg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780075135; x=1780679935; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=tZ4vZVcUxh57FWknF9iHwYSifIVXpEFpUueO53nt890=; b=HLbsx0LHCW/OzlOHZ2PA0TtNT+X/1M71pZdiDVIhzzyUA9hC00b4XImTqsAx2osWMF UGn2HLrYgSgAYqLzm687lxgNV7IBK3RBfVo4Fwm+o/RetgAPtt4lJ4gyPYNTF94ioHcV cJQaoO6Ig029kGZg6sMimN5VC8rH6Gnw9hUHtOJ8JdN5lfa7tL0G/ltWXPLfZY3se1R9 nHOn0h2CBgzUmDnL6rIBTSQLA87DtzZYNazQSH6im07d9kWZHRt8AQt2ONuVnIaUEJ5d NTLz6x/TZdAWJwsi6ANnaEL3W5idjtkIm6Fy7Nm3Jj8cK3//ok8HEnt0iYZtqABRcD/g E2Gg== X-Forwarded-Encrypted: i=1; AFNElJ/X78vv98zN7l/ck63YuQLM36JhCJk4MLUTWI4C5OZcueGs6xgf6deJd10gLnMH3IIoBsGo2fn0Q4ldiWc=@vger.kernel.org X-Gm-Message-State: AOJu0YzcF/eSEjn3PFvQk0KkoRgvzRdDxph1cBbfOX4x9rKYv8vOH0fH P15/efxM5P66rXrMq9Egrv9Jt/dHreYhf0ERZtyEaLi0rMLqzSovwWhC X-Gm-Gg: Acq92OGe47UMA6NO7uVveCMnXzG3O4YQ7rpVW9oGxgCctTqAOrHo9ETRYqwBeyZ4r2l Oar4Qw/CM948y9+MXv61bmpDiibMJAiY+SkDVSWALHpvEwahUhVEwCKYTFejCP7IWYX50xIFXK+ t+4peakcp2RmXuq32TDtqVH3W4gkT+N2R6KmYRsDpTfaSTejT5w93U/v2E6T1H+qmirf4lB3t5f EPy273sBx6X7KuR7QUHI8V5l48A2D5xlnudJScVjjeTr+nvpaSf9XRKzRr5w0zxoi/5M/KNRwAu uE3LlVaNE9riH51mlA445LDawp9nuF0RmadjryK6VonemJ0Baqj/Tiv7xb9vG9O6FapRjtd811l gEPCgwMt3L1Yi9bxsAz35XrpsageuMqJR+lJVY7n7OYSLnHSNAg06h91iQStknm5BCrSYOoybTB Ayk254ChyGCCwmjN5wkGYd9Q7bQ1VdCkniME+9yhYC9I67MGCXC6ZWcLw+hPh6JuDAUtUoJxBIc uYPKeahiANW X-Received: by 2002:a05:600c:c3ce:20b0:48f:e230:2a21 with SMTP id 5b1f17b1804b1-490a2975173mr6658095e9.32.1780075134846; Fri, 29 May 2026 10:18:54 -0700 (PDT) Received: from f.. (cst-prg-92-135.cust.vodafone.cz. [46.135.92.135]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4909caa7faasm56255375e9.11.2026.05.29.10.18.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 May 2026 10:18:54 -0700 (PDT) From: Mateusz Guzik To: brauner@kernel.org Cc: viro@zeniv.linux.org.uk, jack@suse.cz, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, adobriyan@gmail.com Subject: [PATCH v4 1/3] proc: allow to mark /proc files permanent outside of fs/proc/ Date: Fri, 29 May 2026 19:18:38 +0200 Message-ID: <20260529171840.2576445-2-mjguzik@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260529171840.2576445-1-mjguzik@gmail.com> References: <20260529171840.2576445-1-mjguzik@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Alexey Dobriyan Add proc_make_permanent() function to mark PDE as permanent to speed up open/read/close (one alloc/free and lock/unlock less). Enable it for built-in code and for compiled-in modules. This function becomes nop magically in modular code. Note, note, note! If built-in code creates and deletes PDEs dynamically (not in init hook), then proc_make_permanent() must not be used. It is intended for simple code: static int __init xxx_module_init(void) { g_pde = proc_create_single(); proc_make_permanent(g_pde); return 0; } static void __exit xxx_module_exit(void) { remove_proc_entry(g_pde); } If module is built-in then exit hook never executed and PDE is permanent so it is OK to mark it as such. If module is module then rmmod will yank PDE, but proc_make_permanent() is nop and core /proc code will do everything right. Signed-off-by: Alexey Dobriyan --- fs/proc/generic.c | 12 ++++++++++++ fs/proc/internal.h | 3 +++ include/linux/proc_fs.h | 10 ++++++++++ 3 files changed, 25 insertions(+) diff --git a/fs/proc/generic.c b/fs/proc/generic.c index 8bb81e58c9d8..5f82c0b4a8bb 100644 --- a/fs/proc/generic.c +++ b/fs/proc/generic.c @@ -841,3 +841,15 @@ ssize_t proc_simple_write(struct file *f, const char __user *ubuf, size_t size, kfree(buf); return ret == 0 ? size : ret; } + +/* + * Not exported to modules: + * modules' /proc files aren't permanent because modules aren't permanent. + */ +void impl_proc_make_permanent(struct proc_dir_entry *pde); +void impl_proc_make_permanent(struct proc_dir_entry *pde) +{ + if (pde) { + pde_make_permanent(pde); + } +} diff --git a/fs/proc/internal.h b/fs/proc/internal.h index d31984c3c797..b232e1098117 100644 --- a/fs/proc/internal.h +++ b/fs/proc/internal.h @@ -79,8 +79,11 @@ static inline bool pde_is_permanent(const struct proc_dir_entry *pde) return pde->flags & PROC_ENTRY_PERMANENT; } +/* This is for builtin code, not even for modules which are compiled in. */ static inline void pde_make_permanent(struct proc_dir_entry *pde) { + /* Ensure magic flag does something. */ + static_assert(PROC_ENTRY_PERMANENT != 0); pde->flags |= PROC_ENTRY_PERMANENT; } diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h index ec123c277d49..96a22109a0bf 100644 --- a/include/linux/proc_fs.h +++ b/include/linux/proc_fs.h @@ -249,4 +249,14 @@ static inline struct pid_namespace *proc_pid_ns(struct super_block *sb) bool proc_ns_file(const struct file *file); +static inline void proc_make_permanent(struct proc_dir_entry *pde) +{ + /* Don't give matches to modules. */ +#if defined CONFIG_PROC_FS && !defined MODULE + /* This mess is created by defining "struct proc_dir_entry" elsewhere. */ + void impl_proc_make_permanent(struct proc_dir_entry *pde); + impl_proc_make_permanent(pde); +#endif +} + #endif /* _LINUX_PROC_FS_H */ -- 2.48.1