From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1E4A1352077; Tue, 26 Aug 2025 14:39:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756219170; cv=none; b=hbCAoBXtKjN+3UH6mBwWy68pSoMKvOw8ASXdmLoRhoZ821AQqaG34WK/eYb5Dj/R4Lss4DU9X3yKD5N6F0dtI1vjP8nMIQNJlu041dnsvrWDzQeh7IuZhSwiXMIEGAToRE9xZXDX6gagixN25mbEYLjQbiTpcWE+SwWs1VmWUIs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756219170; c=relaxed/simple; bh=Xf/4AUYMsArd68Gg3tiKwuhS1wmhzPZyBPpbloaT3a4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=OQB+rGwEdiNBS2n9uKwQFMf62gDT6HGb6mKHkg13CrdVcIa4HBePQzfAMEHJ1vbQkiAYW+aG2N2JtAxD78EK4nTCPg7SMmORj8dlIyhl5qNncxJigZi0dtupKe4QobYljUYus30uH77xnyT0Dzl0g+L0E+TzQRWSP/kE62w+mOo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=RizYOz/D; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="RizYOz/D" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9E677C4CEF1; Tue, 26 Aug 2025 14:39:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1756219170; bh=Xf/4AUYMsArd68Gg3tiKwuhS1wmhzPZyBPpbloaT3a4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RizYOz/Du0dkIIfT/oTihCKLXCj1lBDfKqI5llRsGvKmxvG/CYIV0wK16lX6U+W83 QHDIcysIgsDa3xruyxishNztnJtFwK+lT51CQ6GfEh1ibt1He8tlWBNUjtd8I6pCDl vIRXl66H5mEI5V4wJXjIt4GAqLdn9VU2AL+Ae/sA= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Waiman Long , Catalin Marinas , Andrew Morton Subject: [PATCH 5.4 279/403] mm/kmemleak: avoid soft lockup in __kmemleak_do_cleanup() Date: Tue, 26 Aug 2025 13:10:05 +0200 Message-ID: <20250826110914.509556162@linuxfoundation.org> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20250826110905.607690791@linuxfoundation.org> References: <20250826110905.607690791@linuxfoundation.org> User-Agent: quilt/0.68 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 5.4-stable review patch. If anyone has any objections, please let me know. ------------------ From: Waiman Long commit d1534ae23c2b6be350c8ab060803fbf6e9682adc upstream. A soft lockup warning was observed on a relative small system x86-64 system with 16 GB of memory when running a debug kernel with kmemleak enabled. watchdog: BUG: soft lockup - CPU#8 stuck for 33s! [kworker/8:1:134] The test system was running a workload with hot unplug happening in parallel. Then kemleak decided to disable itself due to its inability to allocate more kmemleak objects. The debug kernel has its CONFIG_DEBUG_KMEMLEAK_MEM_POOL_SIZE set to 40,000. The soft lockup happened in kmemleak_do_cleanup() when the existing kmemleak objects were being removed and deleted one-by-one in a loop via a workqueue. In this particular case, there are at least 40,000 objects that need to be processed and given the slowness of a debug kernel and the fact that a raw_spinlock has to be acquired and released in __delete_object(), it could take a while to properly handle all these objects. As kmemleak has been disabled in this case, the object removal and deletion process can be further optimized as locking isn't really needed. However, it is probably not worth the effort to optimize for such an edge case that should rarely happen. So the simple solution is to call cond_resched() at periodic interval in the iteration loop to avoid soft lockup. Link: https://lkml.kernel.org/r/20250728190248.605750-1-longman@redhat.com Signed-off-by: Waiman Long Acked-by: Catalin Marinas Cc: Signed-off-by: Andrew Morton Signed-off-by: Greg Kroah-Hartman --- mm/kmemleak.c | 5 +++++ 1 file changed, 5 insertions(+) --- a/mm/kmemleak.c +++ b/mm/kmemleak.c @@ -1849,6 +1849,7 @@ static const struct file_operations kmem static void __kmemleak_do_cleanup(void) { struct kmemleak_object *object, *tmp; + unsigned int cnt = 0; /* * Kmemleak has already been disabled, no need for RCU list traversal @@ -1857,6 +1858,10 @@ static void __kmemleak_do_cleanup(void) list_for_each_entry_safe(object, tmp, &object_list, object_list) { __remove_object(object); __delete_object(object); + + /* Call cond_resched() once per 64 iterations to avoid soft lockup */ + if (!(++cnt & 0x3f)) + cond_resched(); } }