Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp7076494ybi; Thu, 13 Jun 2019 09:10:16 -0700 (PDT) X-Google-Smtp-Source: APXvYqw9x0TJKuoAx/9sUI70BNIoH7xHQlIdFoCAQOkj7wrIk/WUBUwmDOayIkVFM90O/PI+VgvM X-Received: by 2002:a17:902:b705:: with SMTP id d5mr52727179pls.274.1560442216803; Thu, 13 Jun 2019 09:10:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560442216; cv=none; d=google.com; s=arc-20160816; b=ba7RAT78cKnDmPmaZc9/4KZZGKrc50Sq1FmLrvSS5LhPC9JvtC31260iWcBHgMJKD3 6ssf48BTh9N3v3dd8NWJGhBKa6FBMYKh3eEjdl37kNoC/VHRreVxIFNieKjRv2ODiyuS 4psL+M2lWFnI03HHW0D9ym/D1pYfp4gzeXzXfqQA9C8LgWHWDpw+4lhOIBPjboTco9Xo pUeXp7NugRoZY3YPNQizRlztRNLMil1xV/ofm/IKt1ObuogCIXu4eREEAun8Qzpys0Kw LRO9UmzEDZhz6LDtc4JgTN3IsB0JMlA4zPTDn2y1Fnn28H/WXaM7LMef5fZBF0TL6HiI Ir7g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=VxY04p13KxxKIpuKjJUAVlcCce9ozVPn1dkIGsKGG9U=; b=GBh7+eWTagh7x5JJYk0GZTEDGDsV/9uOryavLUfE8ywxWiabXF45RQOiLbv5N3jBWs Cr7Ayq5Ohr7cFvariHGJomT8MvhvPXWgwbRpD9akEYARYsUzRIS2sTGWkbN7GJMTf+Gv zdlzne98TAijNYKi2PAgG8azO5/lkUzH+oSqeZCkDKJi+yv9taZXcKfJaahuRYtIkrkE GmJ0Ba3DwLUgaCcDR3EZk29uFYoQP3pdeBI8eUXowKgSZfTLQWcBc0ALbx4RiQw4PeeD aBb26SWTg6afVvLDFGLuzDxI0HLbtCt5+snc1pG0ffE4e6auY+6oTEB41ALnpgkDHji3 R1dw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=UB0en7RY; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v204si153630pgb.80.2019.06.13.09.10.02; Thu, 13 Jun 2019 09:10:16 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=UB0en7RY; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1733063AbfFMQIo (ORCPT + 99 others); Thu, 13 Jun 2019 12:08:44 -0400 Received: from mail.kernel.org ([198.145.29.99]:33762 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731283AbfFMIo7 (ORCPT ); Thu, 13 Jun 2019 04:44:59 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 3426C2175B; Thu, 13 Jun 2019 08:44:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1560415498; bh=rUrvbvH38CopufLnqpRn9sw2QyPuTREiClmjys0lCnY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UB0en7RY94q+SiLvJ/5/wzhMNsNovcNx+miaBT/g/OIqyKoCEPEwxt8rtgboyVGsG W3Vx4Fj8rVrFbfFvuG/TZT/GH5ugZrkeURJ9aJMkRAjA76J5OT/f7qW6oZUamNrUkk YZeXXGikk4u6PiAFq5VXoCWvMz1Q3LULbAzBfMn8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Qian Cai , Andrew Morton , Vlastimil Babka , Christoph Lameter , Pekka Enberg , David Rientjes , Joonsoo Kim , Linus Torvalds , Sasha Levin Subject: [PATCH 5.1 023/155] mm/slab.c: fix an infinite loop in leaks_show() Date: Thu, 13 Jun 2019 10:32:15 +0200 Message-Id: <20190613075654.079935534@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190613075652.691765927@linuxfoundation.org> References: <20190613075652.691765927@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org [ 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 Reviewed-by: Andrew Morton Cc: Vlastimil Babka Cc: Christoph Lameter Cc: Pekka Enberg Cc: David Rientjes Cc: Joonsoo Kim Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Sasha Levin --- mm/slab.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/mm/slab.c b/mm/slab.c index 9142ee992493..fbbef79e1ad5 100644 --- a/mm/slab.c +++ b/mm/slab.c @@ -4328,8 +4328,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