From d01d36fdd86a070c1ec8b40f077e0dd89e9f9c81 Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Sat, 10 Sep 2022 08:27:10 +0200 Subject: [PATCH] 5.15-stable patches added patches: debugfs-add-debugfs_lookup_and_remove.patch drm-amd-display-fix-memory-leak-when-using-debugfs_lookup.patch sched-debug-fix-dentry-leak-in-update_sched_domain_debugfs.patch --- ...ebugfs-add-debugfs_lookup_and_remove.patch | 79 +++++++++++++++++++ ...emory-leak-when-using-debugfs_lookup.patch | 58 ++++++++++++++ ...-leak-in-update_sched_domain_debugfs.patch | 49 ++++++++++++ queue-5.15/series | 3 + 4 files changed, 189 insertions(+) create mode 100644 queue-5.15/debugfs-add-debugfs_lookup_and_remove.patch create mode 100644 queue-5.15/drm-amd-display-fix-memory-leak-when-using-debugfs_lookup.patch create mode 100644 queue-5.15/sched-debug-fix-dentry-leak-in-update_sched_domain_debugfs.patch diff --git a/queue-5.15/debugfs-add-debugfs_lookup_and_remove.patch b/queue-5.15/debugfs-add-debugfs_lookup_and_remove.patch new file mode 100644 index 00000000000..336bca9ea83 --- /dev/null +++ b/queue-5.15/debugfs-add-debugfs_lookup_and_remove.patch @@ -0,0 +1,79 @@ +From dec9b2f1e0455a151a7293c367da22ab973f713e Mon Sep 17 00:00:00 2001 +From: Greg Kroah-Hartman +Date: Fri, 2 Sep 2022 16:59:15 +0200 +Subject: debugfs: add debugfs_lookup_and_remove() + +From: Greg Kroah-Hartman + +commit dec9b2f1e0455a151a7293c367da22ab973f713e upstream. + +There is a very common pattern of using +debugfs_remove(debufs_lookup(..)) which results in a dentry leak of the +dentry that was looked up. Instead of having to open-code the correct +pattern of calling dput() on the dentry, create +debugfs_lookup_and_remove() to handle this pattern automatically and +properly without any memory leaks. + +Cc: stable +Reported-by: Kuyo Chang +Tested-by: Kuyo Chang +Link: https://lore.kernel.org/r/YxIaQ8cSinDR881k@kroah.com +Signed-off-by: Greg Kroah-Hartman +--- + fs/debugfs/inode.c | 22 ++++++++++++++++++++++ + include/linux/debugfs.h | 6 ++++++ + 2 files changed, 28 insertions(+) + +--- a/fs/debugfs/inode.c ++++ b/fs/debugfs/inode.c +@@ -735,6 +735,28 @@ void debugfs_remove(struct dentry *dentr + EXPORT_SYMBOL_GPL(debugfs_remove); + + /** ++ * debugfs_lookup_and_remove - lookup a directory or file and recursively remove it ++ * @name: a pointer to a string containing the name of the item to look up. ++ * @parent: a pointer to the parent dentry of the item. ++ * ++ * This is the equlivant of doing something like ++ * debugfs_remove(debugfs_lookup(..)) but with the proper reference counting ++ * handled for the directory being looked up. ++ */ ++void debugfs_lookup_and_remove(const char *name, struct dentry *parent) ++{ ++ struct dentry *dentry; ++ ++ dentry = debugfs_lookup(name, parent); ++ if (!dentry) ++ return; ++ ++ debugfs_remove(dentry); ++ dput(dentry); ++} ++EXPORT_SYMBOL_GPL(debugfs_lookup_and_remove); ++ ++/** + * debugfs_rename - rename a file/directory in the debugfs filesystem + * @old_dir: a pointer to the parent dentry for the renamed object. This + * should be a directory dentry. +--- a/include/linux/debugfs.h ++++ b/include/linux/debugfs.h +@@ -91,6 +91,8 @@ struct dentry *debugfs_create_automount( + void debugfs_remove(struct dentry *dentry); + #define debugfs_remove_recursive debugfs_remove + ++void debugfs_lookup_and_remove(const char *name, struct dentry *parent); ++ + const struct file_operations *debugfs_real_fops(const struct file *filp); + + int debugfs_file_get(struct dentry *dentry); +@@ -225,6 +227,10 @@ static inline void debugfs_remove(struct + static inline void debugfs_remove_recursive(struct dentry *dentry) + { } + ++static inline void debugfs_lookup_and_remove(const char *name, ++ struct dentry *parent) ++{ } ++ + const struct file_operations *debugfs_real_fops(const struct file *filp); + + static inline int debugfs_file_get(struct dentry *dentry) diff --git a/queue-5.15/drm-amd-display-fix-memory-leak-when-using-debugfs_lookup.patch b/queue-5.15/drm-amd-display-fix-memory-leak-when-using-debugfs_lookup.patch new file mode 100644 index 00000000000..42de22fb660 --- /dev/null +++ b/queue-5.15/drm-amd-display-fix-memory-leak-when-using-debugfs_lookup.patch @@ -0,0 +1,58 @@ +From cbfac7fa491651c57926c99edeb7495c6c1aeac2 Mon Sep 17 00:00:00 2001 +From: Greg Kroah-Hartman +Date: Fri, 2 Sep 2022 15:01:05 +0200 +Subject: drm/amd/display: fix memory leak when using debugfs_lookup() +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +From: Greg Kroah-Hartman + +commit cbfac7fa491651c57926c99edeb7495c6c1aeac2 upstream. + +When calling debugfs_lookup() the result must have dput() called on it, +otherwise the memory will leak over time. Fix this up by properly +calling dput(). + +Cc: Harry Wentland +Cc: Leo Li +Cc: Rodrigo Siqueira +Cc: Alex Deucher +Cc: "Christian König" +Cc: "Pan, Xinhui" +Cc: David Airlie +Cc: Daniel Vetter +Cc: Wayne Lin +Cc: hersen wu +Cc: Wenjing Liu +Cc: Patrik Jakobsson +Cc: Thelford Williams +Cc: Fangzhi Zuo +Cc: Yongzhi Liu +Cc: Mikita Lipski +Cc: Jiapeng Chong +Cc: Bhanuprakash Modem +Cc: Sean Paul +Cc: amd-gfx@lists.freedesktop.org +Cc: dri-devel@lists.freedesktop.org +Cc: stable@vger.kernel.org +Reviewed-by: Rodrigo Siqueira +Signed-off-by: Greg Kroah-Hartman +Signed-off-by: Rodrigo Siqueira +Signed-off-by: Alex Deucher +Signed-off-by: Greg Kroah-Hartman +--- + drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_debugfs.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +--- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_debugfs.c ++++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_debugfs.c +@@ -3007,7 +3007,7 @@ void crtc_debugfs_init(struct drm_crtc * + &crc_win_y_end_fops); + debugfs_create_file_unsafe("crc_win_update", 0644, dir, crtc, + &crc_win_update_fops); +- ++ dput(dir); + } + #endif + /* diff --git a/queue-5.15/sched-debug-fix-dentry-leak-in-update_sched_domain_debugfs.patch b/queue-5.15/sched-debug-fix-dentry-leak-in-update_sched_domain_debugfs.patch new file mode 100644 index 00000000000..9316a2f89e8 --- /dev/null +++ b/queue-5.15/sched-debug-fix-dentry-leak-in-update_sched_domain_debugfs.patch @@ -0,0 +1,49 @@ +From c2e406596571659451f4b95e37ddfd5a8ef1d0dc Mon Sep 17 00:00:00 2001 +From: Greg Kroah-Hartman +Date: Fri, 2 Sep 2022 14:31:07 +0200 +Subject: sched/debug: fix dentry leak in update_sched_domain_debugfs + +From: Greg Kroah-Hartman + +commit c2e406596571659451f4b95e37ddfd5a8ef1d0dc upstream. + +Kuyo reports that the pattern of using debugfs_remove(debugfs_lookup()) +leaks a dentry and with a hotplug stress test, the machine eventually +runs out of memory. + +Fix this up by using the newly created debugfs_lookup_and_remove() call +instead which properly handles the dentry reference counting logic. + +Cc: Major Chen +Cc: stable +Cc: Ingo Molnar +Cc: Peter Zijlstra +Cc: Juri Lelli +Cc: Vincent Guittot +Cc: Dietmar Eggemann +Cc: Steven Rostedt +Cc: Ben Segall +Cc: Mel Gorman +Cc: Daniel Bristot de Oliveira +Cc: Valentin Schneider +Cc: Matthias Brugger +Reported-by: Kuyo Chang +Tested-by: Kuyo Chang +Acked-by: Peter Zijlstra (Intel) +Link: https://lore.kernel.org/r/20220902123107.109274-2-gregkh@linuxfoundation.org +Signed-off-by: Greg Kroah-Hartman +--- + kernel/sched/debug.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +--- a/kernel/sched/debug.c ++++ b/kernel/sched/debug.c +@@ -416,7 +416,7 @@ void update_sched_domain_debugfs(void) + char buf[32]; + + snprintf(buf, sizeof(buf), "cpu%d", cpu); +- debugfs_remove(debugfs_lookup(buf, sd_dentry)); ++ debugfs_lookup_and_remove(buf, sd_dentry); + d_cpu = debugfs_create_dir(buf, sd_dentry); + + i = 0; diff --git a/queue-5.15/series b/queue-5.15/series index 1c75f004bec..0ce96597ef6 100644 --- a/queue-5.15/series +++ b/queue-5.15/series @@ -33,3 +33,6 @@ tracing-fix-to-check-event_mutex-is-held-while-accessing-trigger-list.patch btrfs-zoned-set-pseudo-max-append-zone-limit-in-zone-emulation-mode.patch vfio-type1-unpin-zero-pages.patch kprobes-prohibit-probes-in-gate-area.patch +debugfs-add-debugfs_lookup_and_remove.patch +sched-debug-fix-dentry-leak-in-update_sched_domain_debugfs.patch +drm-amd-display-fix-memory-leak-when-using-debugfs_lookup.patch -- 2.47.3