From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (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 7713E40D586 for ; Sat, 13 Jun 2026 10:45:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781347532; cv=none; b=SRXNesTwpOgMPK7wAFp76FNUu8CwzSBYidPli7rrq2oSuisqAVQwJiCrahuie5+xnJupzO2rcd9olHYZrNTWFkTIWC/CwexFLVC3LPyGRkmr2wnd6nG7sw2+Olu4u1mLlO/3062g0ArxdXsqwyNZbAd3IdL0X/PHibUubeMPdsY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781347532; c=relaxed/simple; bh=emc8m6OlD7VMdxRW7IDvqajEHlfMACphdp9G63UhcRA=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Ic4MbmoYugJ1OOulruQKJC/D3ttLftWu6+lpEDAnDJq3Ek3ofOy/KPGL4xumV99uH3IJnKITnRChsDAXFG1uN2eBVtiGDptAhcQvTYnUjteZ9De2I/jHdzmkNs0H+h+VRzZTztO2unKA6V4ABe31ojOx8Es6KurchRmTAjhFFhE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=QGaLKj9G; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="QGaLKj9G" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1781347530; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=t0Rdn7ZGItclRk/+njrMNwKPmYdf4WznHl68jVY8zfQ=; b=QGaLKj9G3jwcObv5HIBCbJsRPdToyY7WpvLIf8jfWFsmr7VZRM+N//eTPo2EbjkyEafqP7 7gXeGgxHef3ULjw611bjERNKHcBOAmvwCHpNapEAEPz7vAl+0s7sotj9ZC9Yyw5eYJ931Z 4ePMGPa0Bq/1ODQukSe6HNSPAb/yJys= Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-592-1KrHt5iEPg-CfOpTqeYkSw-1; Sat, 13 Jun 2026 06:45:26 -0400 X-MC-Unique: 1KrHt5iEPg-CfOpTqeYkSw-1 X-Mimecast-MFC-AGG-ID: 1KrHt5iEPg-CfOpTqeYkSw_1781347525 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 33E3719540C3; Sat, 13 Jun 2026 10:45:25 +0000 (UTC) Received: from fedora (unknown [10.22.88.101]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with SMTP id D834D180049F; Sat, 13 Jun 2026 10:45:21 +0000 (UTC) Received: by fedora (nbSMTP-1.00) for uid 1000 oleg@redhat.com; Sat, 13 Jun 2026 12:45:24 +0200 (CEST) Date: Sat, 13 Jun 2026 12:45:20 +0200 From: Oleg Nesterov To: Breno Leitao Cc: Catalin Marinas , Andrew Morton , lance.yang@linux.dev, Davidlohr Bueso , Qian Cai , linux-mm@kvack.org, linux-kernel@vger.kernel.org, kernel-team@meta.com, stable@vger.kernel.org Subject: Re: [PATCH v2] mm/kmemleak: avoid soft lockup when scanning task stacks Message-ID: References: <20260612-kmemleak-stack-resched-v2-1-53240de79e88@debian.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20260612-kmemleak-stack-resched-v2-1-53240de79e88@debian.org> X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 To avoid the confusion, I see nothing wrong in this patch, but see the question at the end. On 06/12, Breno Leitao wrote: > > +/* > + * Briefly drop the RCU read lock to reschedule during the task stack scan. > + * Both cursors are pinned across the gap; return false if either one was > + * unhashed meanwhile, so the caller stops this round instead of walking a > + * stale list. > + */ > +static bool kmemleak_stack_scan_break(struct task_struct *g, > + struct task_struct *p) > +{ > + bool can_cont; > + > + get_task_struct(g); > + get_task_struct(p); > + > + rcu_read_unlock(); > + cond_resched(); > + rcu_read_lock(); > + > + can_cont = pid_alive(g) && pid_alive(p); > + > + put_task_struct(p); > + put_task_struct(g); > + > + return can_cont; > +} Perhaps we can rename and export rcu_lock_break() to avoid the duplication... And, this is slightly off-topic, please ignore, but this reminds me about [PATCH 1/2] introduce for_each_process_thread_break() and for_each_process_thread_continue() https://lore.kernel.org/all/20180912163335.GA18748@redhat.com/ > @@ -1890,11 +1917,21 @@ static void kmemleak_scan(void) > rcu_read_lock(); > for_each_process_thread(g, p) { > void *stack = try_get_task_stack(p); > + > if (stack) { > scan_block(stack, stack + THREAD_SIZE, NULL); > put_task_stack(p); > } > + /* > + * This is an expensive loop, we must to call the > + * scheduler to avoid lockups > + */ > + if (need_resched() && !kmemleak_stack_scan_break(g, p)) { > + aborted = true; > + goto unlock; Can this need_resched() check actually help if CONFIG_PREEMPTION && CONFIG_PREEMPT_RCU ? In this case (lets ignore PREEMPT_DYNAMIC to simplify) rcu_read_lock() doesn't disable preemption and cond_resched() is nop, need_resched() is (almost) never true. Right? I guess even in this case it makes sense to not abuse rcu_read_lock() "too much", but perhaps we need something more clever than need_resched() ? Note that check_hung_uninterruptible_tasks() uses time_after()... Oleg.