From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id C04BDC4167B for ; Fri, 1 Dec 2023 22:22:34 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3645B6B04D8; Fri, 1 Dec 2023 17:22:34 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 314126B04D9; Fri, 1 Dec 2023 17:22:34 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 202C76B04DA; Fri, 1 Dec 2023 17:22:34 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 10A326B04D8 for ; Fri, 1 Dec 2023 17:22:34 -0500 (EST) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id E5492A06E9 for ; Fri, 1 Dec 2023 22:22:33 +0000 (UTC) X-FDA: 81519674586.26.C4BDD30 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf22.hostedemail.com (Postfix) with ESMTP id 0BFD3C000E for ; Fri, 1 Dec 2023 22:22:30 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="DUt/IwMz"; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf22.hostedemail.com: domain of longman@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=longman@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1701469351; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=gr/vivmu3OY8SoUw97PpQV6NswBnu4o/GskzZwhXj8I=; b=bEVAvN2Sf3YAVmA/JWQEgo7q9wW+BojUXVavm6NsJn74uooG3DZopCdp51nZ2C6Z9kXs05 gVftB1X/1Up0fi0PiyIELjlg2T8jkjnZcEF2PsCsqmO8IRmSQyx8B/DwZWKHJ1oGPy2jUf 0fSBXmBUkDgH8eDt498GkpE97f6o8EI= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="DUt/IwMz"; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf22.hostedemail.com: domain of longman@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=longman@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1701469351; a=rsa-sha256; cv=none; b=Uzr+vXXXqZiEiA1lWoFytYv2/RuIBZwxFhgKl+uKKVEfWN2N4bIy1QpYsqRV13JaxPTn0/ Vfrm6GglyML94fdWoZUsbOycBOSP1O2XpfWY/MfDJhEB4SfCIcUC7rQUh17H3rKLDFUi7u +fR4cQPnj/+6/9DrTWAy8y9aXVHIAWs= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1701469350; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=gr/vivmu3OY8SoUw97PpQV6NswBnu4o/GskzZwhXj8I=; b=DUt/IwMzF7JgW85/fDcX7Nu/mZZLNeadpiNrPurwo7mQjpnEk2j+E6/ywnbaGwJf1LIJSe 9xXIyQlZpmlMdbIH3dN86vwdIGdemtjNhDBj7PUFgEX6RMdM2D1v8L0Z7yp3704yoYpr2g UmTFYM2lOfTx0n35lLWd+VfIapNKO+E= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-150-0eC6rJOgP7O6kmED4n3ZYA-1; Fri, 01 Dec 2023 17:22:27 -0500 X-MC-Unique: 0eC6rJOgP7O6kmED4n3ZYA-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (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 mimecast-mx02.redhat.com (Postfix) with ESMTPS id 4208529ABA39; Fri, 1 Dec 2023 22:22:27 +0000 (UTC) Received: from [10.22.17.155] (unknown [10.22.17.155]) by smtp.corp.redhat.com (Postfix) with ESMTP id E9FEE40C6EB9; Fri, 1 Dec 2023 22:22:26 +0000 (UTC) Message-ID: <597352bb-6afa-4fa4-a5ee-1f0aa14e61be@redhat.com> Date: Fri, 1 Dec 2023 17:22:26 -0500 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] kmemleak: Avoid RCU stalls when freeing metadata for per-CPU pointers Content-Language: en-US To: Catalin Marinas , linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org, Andrew Morton References: <20231201190829.825856-1-catalin.marinas@arm.com> From: Waiman Long In-Reply-To: <20231201190829.825856-1-catalin.marinas@arm.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.2 X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 0BFD3C000E X-Stat-Signature: nz1k165xrefrnkk31e9wwiat7b5pu51i X-HE-Tag: 1701469350-831116 X-HE-Meta: U2FsdGVkX19e4sQIXavQaDNCeDyW6BPnPXpwn6VCO3BDzt60gJSKr0ur1araGw4SAdTDRoOOBFDBEkoGS/rUfJnnemj1l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hZKyy2CR2IT+zJE0keyP4R4kVrj+tYAOtFoBCkh2EpK3zfOgsTFGeJhZO4cDOJgveOYXkkRqT3MrqyfcZkLI/gXLnD/zr3dZeFp/evFaTCB2N/5SA7GfFdPjKZVb+1e35SFyTopx1niE6ZBDz53bW4lei5TIclG0Ld7CPzInxwU5JS2e8+jte89uLa4r5ZNt1Gnok6wARcPxsFOdydFSqVmXWfMeDcQNA== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On 12/1/23 14:08, Catalin Marinas wrote: > On systems with large number of CPUs, the following soft lockup splat > might sometimes happen: > > [ 2656.001617] watchdog: BUG: soft lockup - CPU#364 stuck for 21s! [ksoftirqd/364:2206] > : > [ 2656.141194] RIP: 0010:_raw_spin_unlock_irqrestore+0x3d/0x70 > : > 2656.241214] Call Trace: > [ 2656.243971] > [ 2656.246237] ? show_trace_log_lvl+0x1c4/0x2df > [ 2656.251152] ? show_trace_log_lvl+0x1c4/0x2df > [ 2656.256066] ? kmemleak_free_percpu+0x11f/0x1f0 > [ 2656.261173] ? watchdog_timer_fn+0x379/0x470 > [ 2656.265984] ? __pfx_watchdog_timer_fn+0x10/0x10 > [ 2656.271179] ? __hrtimer_run_queues+0x5f3/0xd00 > [ 2656.276283] ? __pfx___hrtimer_run_queues+0x10/0x10 > [ 2656.281783] ? ktime_get_update_offsets_now+0x95/0x2c0 > [ 2656.287573] ? ktime_get_update_offsets_now+0xdd/0x2c0 > [ 2656.293380] ? hrtimer_interrupt+0x2e9/0x780 > [ 2656.298221] ? __sysvec_apic_timer_interrupt+0x184/0x640 > [ 2656.304211] ? sysvec_apic_timer_interrupt+0x8e/0xc0 > [ 2656.309807] > [ 2656.312169] > [ 2656.326110] kmemleak_free_percpu+0x11f/0x1f0 > [ 2656.331015] free_percpu.part.0+0x1b/0xe70 > [ 2656.335635] free_vfsmnt+0xb9/0x100 > [ 2656.339567] rcu_do_batch+0x3c8/0xe30 > [ 2656.363693] rcu_core+0x3de/0x5a0 > [ 2656.367433] __do_softirq+0x2d0/0x9a8 > [ 2656.381119] run_ksoftirqd+0x36/0x60 > [ 2656.385145] smpboot_thread_fn+0x556/0x910 > [ 2656.394971] kthread+0x2a4/0x350 > [ 2656.402826] ret_from_fork+0x29/0x50 > [ 2656.406861] > > The issue is caused by kmemleak registering each per_cpu_ptr() > corresponding to the __percpu pointer. This is unnecessary since such > individual per-CPU pointers are not tracked anyway. Create a new > object_percpu_tree_root rbtree that stores a single __percpu pointer > together with an OBJECT_PERCPU flag for the kmemleak metadata. Scanning > needs to be done for all per_cpu_ptr() pointers with a cond_resched() > between each CPU iteration to avoid RCU stalls. > > Signed-off-by: Catalin Marinas > Reported-by: Waiman Long > Link: https://lore.kernel.org/r/20231127194153.289626-1-longman@redhat.com > Cc: Andrew Morton > --- > > The only difference from the inlined patch I posted previously is some updated > comments to include the new object tree. > > mm/kmemleak.c | 178 +++++++++++++++++++++++++++----------------------- > 1 file changed, 97 insertions(+), 81 deletions(-) > > diff --git a/mm/kmemleak.c b/mm/kmemleak.c > index 1eacca03bedd..eb6cdc3e9af2 100644 > --- a/mm/kmemleak.c > +++ b/mm/kmemleak.c > @@ -14,17 +14,15 @@ > * The following locks and mutexes are used by kmemleak: > * > * - kmemleak_lock (raw_spinlock_t): protects the object_list as well as > - * del_state modifications and accesses to the object_tree_root (or > - * object_phys_tree_root). The object_list is the main list holding the > - * metadata (struct kmemleak_object) for the allocated memory blocks. > - * The object_tree_root and object_phys_tree_root are red > - * black trees used to look-up metadata based on a pointer to the > - * corresponding memory block. The object_phys_tree_root is for objects > - * allocated with physical address. The kmemleak_object structures are > - * added to the object_list and object_tree_root (or object_phys_tree_root) > - * in the create_object() function called from the kmemleak_alloc() (or > - * kmemleak_alloc_phys()) callback and removed in delete_object() called from > - * the kmemleak_free() callback > + * del_state modifications and accesses to the object trees > + * (object_tree_root, object_phys_tree_root, object_percpu_tree_root). The > + * object_list is the main list holding the metadata (struct > + * kmemleak_object) for the allocated memory blocks. The object trees are > + * red black trees used to look-up metadata based on a pointer to the > + * corresponding memory block. The kmemleak_object structures are added to > + * the object_list and the object tree root in the create_object() function > + * called from the kmemleak_alloc() (or kmemleak_alloc_phys()) callback and > + * removed in delete_object() called from the kmemleak_free() callback Just a minor nit. For completeness, should we mention kmemleak_alloc_percpu() and kmemleak_free_percpu() here? Anyway, I won't mind if you want to keep it as it is. Reviewed-by: Waiman Long