mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Sasha Levin <sashal@kernel.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: Qian Cai <cai@lca.pw>, Andrew Morton <akpm@linux-foundation.org>,
	Vlastimil Babka <vbabka@suse.cz>,
	Christoph Lameter <cl@linux.com>,
	Pekka Enberg <penberg@kernel.org>,
	David Rientjes <rientjes@google.com>,
	Joonsoo Kim <iamjoonsoo.kim@lge.com>,
	Linus Torvalds <torvalds@linux-foundation.org>,
	Sasha Levin <sashal@kernel.org>,
	linux-mm@kvack.org
Subject: [PATCH AUTOSEL 4.9 10/74] mm/slab.c: fix an infinite loop in leaks_show()
Date: Sat,  1 Jun 2019 09:23:57 -0400	[thread overview]
Message-ID: <20190601132501.27021-10-sashal@kernel.org> (raw)
In-Reply-To: <20190601132501.27021-1-sashal@kernel.org>

From: Qian Cai <cai@lca.pw>

[ Upstream commit 745e10146c31b1c6ed3326286704ae251b17f663 ]

"cat /proc/slab_allocators" could hang forever on SMP machines with
kmemleak or object debugging enabled due to other CPUs running do_drain()
will keep making kmemleak_object or debug_objects_cache dirty and unable
to escape the first loop in leaks_show(),

do {
	set_store_user_clean(cachep);
	drain_cpu_caches(cachep);
	...

} while (!is_store_user_clean(cachep));

For example,

do_drain
  slabs_destroy
    slab_destroy
      kmem_cache_free
        __cache_free
          ___cache_free
            kmemleak_free_recursive
              delete_object_full
                __delete_object
                  put_object
                    free_object_rcu
                      kmem_cache_free
                        cache_free_debugcheck --> dirty kmemleak_object

One approach is to check cachep->name and skip both kmemleak_object and
debug_objects_cache in leaks_show().  The other is to set store_user_clean
after drain_cpu_caches() which leaves a small window between
drain_cpu_caches() and set_store_user_clean() where per-CPU caches could
be dirty again lead to slightly wrong information has been stored but
could also speed up things significantly which sounds like a good
compromise.  For example,

 # cat /proc/slab_allocators
 0m42.778s # 1st approach
 0m0.737s  # 2nd approach

[akpm@linux-foundation.org: tweak comment]
Link: http://lkml.kernel.org/r/20190411032635.10325-1-cai@lca.pw
Fixes: d31676dfde25 ("mm/slab: alternative implementation for DEBUG_SLAB_LEAK")
Signed-off-by: Qian Cai <cai@lca.pw>
Reviewed-by: Andrew Morton <akpm@linux-foundation.org>
Cc: Vlastimil Babka <vbabka@suse.cz>
Cc: Christoph Lameter <cl@linux.com>
Cc: Pekka Enberg <penberg@kernel.org>
Cc: David Rientjes <rientjes@google.com>
Cc: Joonsoo Kim <iamjoonsoo.kim@lge.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 mm/slab.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/mm/slab.c b/mm/slab.c
index d2c0499c6b15d..9547f02b4af96 100644
--- a/mm/slab.c
+++ b/mm/slab.c
@@ -4365,8 +4365,12 @@ static int leaks_show(struct seq_file *m, void *p)
 	 * whole processing.
 	 */
 	do {
-		set_store_user_clean(cachep);
 		drain_cpu_caches(cachep);
+		/*
+		 * drain_cpu_caches() could make kmemleak_object and
+		 * debug_objects_cache dirty, so reset afterwards.
+		 */
+		set_store_user_clean(cachep);
 
 		x[1] = 0;
 
-- 
2.20.1


  parent reply	other threads:[~2019-06-01 13:31 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-06-01 13:23 [PATCH AUTOSEL 4.9 01/74] rapidio: fix a NULL pointer dereference when create_workqueue() fails Sasha Levin
2019-06-01 13:23 ` [PATCH AUTOSEL 4.9 02/74] fs/fat/file.c: issue flush after the writeback of FAT Sasha Levin
2019-06-01 13:23 ` [PATCH AUTOSEL 4.9 03/74] sysctl: return -EINVAL if val violates minmax Sasha Levin
2019-06-01 13:23 ` [PATCH AUTOSEL 4.9 04/74] ipc: prevent lockup on alloc_msg and free_msg Sasha Levin
2019-06-01 13:23 ` [PATCH AUTOSEL 4.9 05/74] ARM: prevent tracing IPI_CPU_BACKTRACE Sasha Levin
2019-06-01 13:23 ` [PATCH AUTOSEL 4.9 06/74] hugetlbfs: on restore reserve error path retain subpool reservation Sasha Levin
2019-06-01 13:23 ` [PATCH AUTOSEL 4.9 07/74] mem-hotplug: fix node spanned pages when we have a node with only ZONE_MOVABLE Sasha Levin
2019-06-01 13:23 ` [PATCH AUTOSEL 4.9 08/74] mm/cma.c: fix crash on CMA allocation if bitmap allocation fails Sasha Levin
2019-06-01 13:23 ` [PATCH AUTOSEL 4.9 09/74] mm/cma_debug.c: fix the break condition in cma_maxchunk_get() Sasha Levin
2019-06-01 13:23 ` Sasha Levin [this message]
2019-06-01 13:23 ` [PATCH AUTOSEL 4.9 11/74] kernel/sys.c: prctl: fix false positive in validate_prctl_map() Sasha Levin
2019-06-01 13:23 ` [PATCH AUTOSEL 4.9 12/74] drivers: thermal: tsens: Don't print error message on -EPROBE_DEFER Sasha Levin
2019-06-01 13:24 ` [PATCH AUTOSEL 4.9 13/74] mfd: tps65912-spi: Add missing of table registration Sasha Levin
2019-06-01 13:24 ` [PATCH AUTOSEL 4.9 14/74] mfd: intel-lpss: Set the device in reset state when init Sasha Levin
2019-06-01 13:24 ` [PATCH AUTOSEL 4.9 15/74] mfd: twl6040: Fix device init errors for ACCCTL register Sasha Levin
2019-06-01 13:24 ` [PATCH AUTOSEL 4.9 16/74] perf/x86/intel: Allow PEBS multi-entry in watermark mode Sasha Levin
2019-06-01 13:24 ` [PATCH AUTOSEL 4.9 17/74] drm/bridge: adv7511: Fix low refresh rate selection Sasha Levin
2019-06-01 13:24 ` [PATCH AUTOSEL 4.9 18/74] objtool: Don't use ignore flag for fake jumps Sasha Levin
2019-06-01 13:24 ` [PATCH AUTOSEL 4.9 19/74] NFS4: Fix v4.0 client state corruption when mount Sasha Levin
2019-06-01 13:24 ` [PATCH AUTOSEL 4.9 20/74] pwm: meson: Use the spin-lock only to protect register modifications Sasha Levin
2019-06-01 13:24 ` [PATCH AUTOSEL 4.9 21/74] ntp: Allow TAI-UTC offset to be set to zero Sasha Levin
2019-06-01 13:24 ` [PATCH AUTOSEL 4.9 22/74] f2fs: fix to avoid panic in do_recover_data() Sasha Levin
2019-06-01 13:24 ` [PATCH AUTOSEL 4.9 23/74] f2fs: fix to clear dirty inode in error path of f2fs_iget() Sasha Levin
2019-06-01 13:24 ` [PATCH AUTOSEL 4.9 24/74] f2fs: fix to do sanity check on valid block count of segment Sasha Levin
2019-06-01 13:24 ` [PATCH AUTOSEL 4.9 25/74] tracing: Fix partial reading of trace event's id file Sasha Levin
2019-06-01 13:24 ` [PATCH AUTOSEL 4.9 26/74] configfs: fix possible use-after-free in configfs_register_group Sasha Levin
2019-06-01 13:24 ` [PATCH AUTOSEL 4.9 27/74] uml: fix a boot splat wrt use of cpu_all_mask Sasha Levin
2019-06-01 13:24 ` [PATCH AUTOSEL 4.9 28/74] mips: Make sure dt memory regions are valid Sasha Levin
2019-06-01 13:24 ` [PATCH AUTOSEL 4.9 29/74] watchdog: Use depends instead of select for pretimeout governors Sasha Levin
2019-06-01 13:24 ` [PATCH AUTOSEL 4.9 30/74] watchdog: imx2_wdt: Fix set_timeout for big timeout values Sasha Levin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190601132501.27021-10-sashal@kernel.org \
    --to=sashal@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=cai@lca.pw \
    --cc=cl@linux.com \
    --cc=iamjoonsoo.kim@lge.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=penberg@kernel.org \
    --cc=rientjes@google.com \
    --cc=stable@vger.kernel.org \
    --cc=torvalds@linux-foundation.org \
    --cc=vbabka@suse.cz \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome