From patchwork Wed Nov 15 08:21:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liu Shixin X-Patchwork-Id: 13456356 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 EB77EC47072 for ; Wed, 15 Nov 2023 07:23:25 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 746CF900002; Wed, 15 Nov 2023 02:23:25 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 6F70880010; Wed, 15 Nov 2023 02:23:25 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5BFA8900004; Wed, 15 Nov 2023 02:23:25 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 4C2B4900002 for ; Wed, 15 Nov 2023 02:23:25 -0500 (EST) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 17813C02B4 for ; Wed, 15 Nov 2023 07:23:25 +0000 (UTC) X-FDA: 81459347970.01.A9A424D Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by imf07.hostedemail.com (Postfix) with ESMTP id 4B3E840005 for ; Wed, 15 Nov 2023 07:23:21 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf07.hostedemail.com: domain of liushixin2@huawei.com designates 45.249.212.187 as permitted sender) smtp.mailfrom=liushixin2@huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1700033003; 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; bh=K2blGegzYk3uSrXQL2dmeHhIs5/9ZtceTeJt5PigS7o=; b=nUthsgBlZKo/WAuNNPsPeGSRodVdfDxoRaFcGZqMTrQgFdu0nEp+IaWQDpyjDBPxlS6PCn ebccmEvAZsGyXxsN4V2m+mGSQsy3e1nrvPyLtvuQAjflaZTA3ngwqdkcZb/TKzDnz7PCq0 Pow+uimEjKhTVz5yh40I180d+YVKXDk= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf07.hostedemail.com: domain of liushixin2@huawei.com designates 45.249.212.187 as permitted sender) smtp.mailfrom=liushixin2@huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1700033003; a=rsa-sha256; cv=none; b=Qw4BHotnbGvAgF3AHlTxKA9hhT5zdlyEW0pG7IfP9RzrFqo1AkhX7gqEjZZjUcoz4Ora/w 3OpNSlVIuDaEdvXCSaY0zvuJtFXBUoZaUaXFCIKl2Hbai2kWRyGMj/3kjAQV+w7HdbE+qp PXL9Vbjp8T2pwWClz9HWoJLuoqIbJRc= Received: from dggpemd200004.china.huawei.com (unknown [172.30.72.55]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4SVZLQ44mKzmWMr; Wed, 15 Nov 2023 15:19:58 +0800 (CST) Received: from huawei.com (10.175.113.32) by dggpemd200004.china.huawei.com (7.185.36.141) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.2.1258.23; Wed, 15 Nov 2023 15:23:18 +0800 From: Liu Shixin To: Geert Uytterhoeven , Catalin Marinas , Patrick Wang , Andrew Morton , Kefeng Wang CC: , , Linux-Renesas , Liu Shixin Subject: [PATCH 1/2] Revert "mm/kmemleak: move the initialisation of object to __link_object" Date: Wed, 15 Nov 2023 16:21:37 +0800 Message-ID: <20231115082138.2649870-2-liushixin2@huawei.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231115082138.2649870-1-liushixin2@huawei.com> References: <20231115082138.2649870-1-liushixin2@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.113.32] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To dggpemd200004.china.huawei.com (7.185.36.141) X-CFilter-Loop: Reflected X-Rspamd-Queue-Id: 4B3E840005 X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: bgcum9n1gct3mk55jij3cqqe9y8644fz X-HE-Tag: 1700033001-115424 X-HE-Meta: U2FsdGVkX19xy5D6AFFz9hp6vV+dyanGq0LX+wF0NV5YO00dgf53EQeq3lL961qd6mulAunqlhspTeplWrhCxxEHfHrwjUYF0M4Cwnt4t3gw9W1y+Wgomlh68dah/ry9W5+TCldfgOCq/g08F6Mmf7RMFrdcDqd4IG5lycvI9hBIMzy2YFX7wCsBvdso9MS6+Uo5uTghN4VBL16d1wZKCcu3faiT9/Sq0fXdza7F5YRc02+qh6PeqTsKqJKUNKfiJRJgHFIjK67v2BfCxP9TXPOGMoBwv16s7rIj9oh5WmvpmqONVRAq1MOLg903GgL8z7MbSNEkfPYcWpVMRDKYudyZI+/kDiUIhQXGSf6KlxrfPV/OSmkbDLlzHkqPef7UOY+QyNtvALoXH16w9Sl6dGRlqNTuwf2Y3EGi3aVNUMcScwCV33JAqzqRZ+5fyafSoy8ekFfYbS959q69jPqssn5vK0mZBgon9cNia3ZdQVBHzE0gvVZ/8wVQLvMLr53/5lkALlE4Xx/99UD+dCTomy3CV2Q5YkKY7dNjsB0ybqBE7jQ2hLIoIFptUrP7Elb5YfA7BVsWBm5fs8UQy2aijcQyBJryiz25H35Z17Krtgk7U5MkwJm9jKw3i6p7S3AdY7ESPlzN+7pekPJyROxFoG0upYjcyfPXP3C2hwDyFCOh3DTS9hyKNuxsCgB71RNo7FM37WQLIG20E9VZdVMKeKEDd7LDsZIGe8HBbWCSJp6H9kaYZhfXrPIeNtvrmBrwDR3PmYINhWEMRGbD5U3PGRvX+hZS/AmSIkIYKPJXFjhnrFZCwwknTrb1NDo5gm5cQlZgLxG7QeB9AxtDvdlc3BHdTxyX7asavsPD/wCkO/vVmspjZ47ZF/TWUYPyWceRgs1So51/SxB+HaKyWTBcnb41tt6gQh2g0wWDSRVy3EnK3ILziSlMmh0DgsPwr3f8gfuH8aqz25VyeBbOkOf kO4KynhD K2FEoq99UdMEEJ+ccp3kqlZzG6M5uHHyTDT4dZMrzmipWENJxralQDTSi/4gszeMnxEW8BpNt0bKgqG6t4xB49D2v9c0huvjSMES3WbBMkML7ZspknB7MMKwXQkQzkxPj7PaX+Hu0ZlSobvkrcKGEVEUlYEQBA0wZ3vfdxRPYYVtmx64LBLMFm6V2VxGqL0uUXHYw3D5Tn1V+2b3JXHP3MiHbNLRRA1ko1bPhS4jT0CC+RShzJ50WKFIQ/sZE1NmZ1nuKctjNYwq6u5A= 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: Move the initialisation of object back to__alloc_object() because set_track_prepare() attempt to acquire zone->lock(spinlocks) while __link_object is holding kmemleak_lock(raw_spinlocks). This is not right for RT mode. This reverts commit 245245c2fffd0050772a3f30ba50e2be92537a32. Signed-off-by: Liu Shixin Reported-by: Geert Uytterhoeven Acked-by: Catalin Marinas --- mm/kmemleak.c | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/mm/kmemleak.c b/mm/kmemleak.c index 1eacca03bedd..22bab3738a9e 100644 --- a/mm/kmemleak.c +++ b/mm/kmemleak.c @@ -642,32 +642,16 @@ static struct kmemleak_object *__alloc_object(gfp_t gfp) if (!object) { pr_warn("Cannot allocate a kmemleak_object structure\n"); kmemleak_disable(); + return NULL; } - return object; -} - -static int __link_object(struct kmemleak_object *object, unsigned long ptr, - size_t size, int min_count, bool is_phys) -{ - - struct kmemleak_object *parent; - struct rb_node **link, *rb_parent; - unsigned long untagged_ptr; - unsigned long untagged_objp; - INIT_LIST_HEAD(&object->object_list); INIT_LIST_HEAD(&object->gray_list); INIT_HLIST_HEAD(&object->area_list); raw_spin_lock_init(&object->lock); atomic_set(&object->use_count, 1); - object->flags = OBJECT_ALLOCATED | (is_phys ? OBJECT_PHYS : 0); - object->pointer = ptr; - object->size = kfence_ksize((void *)ptr) ?: size; object->excess_ref = 0; - object->min_count = min_count; object->count = 0; /* white color initially */ - object->jiffies = jiffies; object->checksum = 0; object->del_state = 0; @@ -692,6 +676,24 @@ static int __link_object(struct kmemleak_object *object, unsigned long ptr, /* kernel backtrace */ object->trace_handle = set_track_prepare(); + return object; +} + +static int __link_object(struct kmemleak_object *object, unsigned long ptr, + size_t size, int min_count, bool is_phys) +{ + + struct kmemleak_object *parent; + struct rb_node **link, *rb_parent; + unsigned long untagged_ptr; + unsigned long untagged_objp; + + object->flags = OBJECT_ALLOCATED | (is_phys ? OBJECT_PHYS : 0); + object->pointer = ptr; + object->size = kfence_ksize((void *)ptr) ?: size; + object->min_count = min_count; + object->jiffies = jiffies; + untagged_ptr = (unsigned long)kasan_reset_tag((void *)ptr); /* * Only update min_addr and max_addr with object From patchwork Wed Nov 15 08:21:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liu Shixin X-Patchwork-Id: 13456357 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 0A82DC07548 for ; Wed, 15 Nov 2023 07:23:48 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 96AF180016; Wed, 15 Nov 2023 02:23:47 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 91A6A80010; Wed, 15 Nov 2023 02:23:47 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8092880016; Wed, 15 Nov 2023 02:23:47 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 6F83780010 for ; Wed, 15 Nov 2023 02:23:47 -0500 (EST) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 42D2B120194 for ; Wed, 15 Nov 2023 07:23:47 +0000 (UTC) X-FDA: 81459348894.23.ACF3B6C Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by imf26.hostedemail.com (Postfix) with ESMTP id EE27B14000E for ; Wed, 15 Nov 2023 07:23:44 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=none; spf=pass (imf26.hostedemail.com: domain of liushixin2@huawei.com designates 45.249.212.188 as permitted sender) smtp.mailfrom=liushixin2@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1700033025; 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; bh=dWEp5LP/lk97XoDnaQ1bOjlQHlNvBdIb/QRK/NsXLAE=; b=qyTnxjMxiR21meKB+gbLZme27OFChbTwIxP/nKyasOT35IiP5DqssCUoBJST2WlaGKaR24 /gXO0nGhY1VBNqoJ03ruMHPMheY7uN0waVfxO/t1CNC6BaoRunhIWB1zUERuPTZbba+Gyd 0fUmF53xM6jHJrvoQGg87aIi5U9J3T0= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=none; spf=pass (imf26.hostedemail.com: domain of liushixin2@huawei.com designates 45.249.212.188 as permitted sender) smtp.mailfrom=liushixin2@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1700033025; a=rsa-sha256; cv=none; b=lNeQmSyu5ZFJpkj+B77kTRvZiDpV5i8TcVjWnXjoCdI5t3x+YzoAEJFwi0PnKEp0dscBXJ tBDH2IM1g7RUWOEPEAPJydy7eZaetExUqyMXJlH6ccnAR0X+VO2CY6MunAhXTKa/1IlIp7 pMSnepGLpwoGZ6Gz+kD6TOXtgeUW+8E= Received: from dggpemd200004.china.huawei.com (unknown [172.30.72.54]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4SVZPz6L0VzWhG1; Wed, 15 Nov 2023 15:23:03 +0800 (CST) Received: from huawei.com (10.175.113.32) by dggpemd200004.china.huawei.com (7.185.36.141) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.2.1258.23; Wed, 15 Nov 2023 15:23:26 +0800 From: Liu Shixin To: Geert Uytterhoeven , Catalin Marinas , Patrick Wang , Andrew Morton , Kefeng Wang CC: , , Linux-Renesas , Liu Shixin Subject: [PATCH 2/2] mm/kmemleak: move set_track_prepare() outside raw_spinlocks Date: Wed, 15 Nov 2023 16:21:38 +0800 Message-ID: <20231115082138.2649870-3-liushixin2@huawei.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231115082138.2649870-1-liushixin2@huawei.com> References: <20231115082138.2649870-1-liushixin2@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.113.32] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To dggpemd200004.china.huawei.com (7.185.36.141) X-CFilter-Loop: Reflected X-Rspamd-Queue-Id: EE27B14000E X-Rspam-User: X-Stat-Signature: ti1nugmjxcq8xop3qm46mu8dt4frbzw4 X-Rspamd-Server: rspam01 X-HE-Tag: 1700033024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zAwumKM2a/TLWE46BQvOVwxcKmXO7Xos9/CEaS6VLVmiYNINVsAM7+S+z9veQuRT9SyiFFkWb4G+CulJTkm2yST3zkMZrT6eAY2e6e00FjlSSga7S2kECWWxvH9m6ECh9D/hOEJXirAJBLTBk5s0sRpss/m8uRsWXi+Es2f5GPAWLDThvS9Hb9EJ5WtdBNI= 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: set_track_prepare() will call __alloc_pages() which attempt to acquire zone->lock(spinlocks), so move it outside object->lock(raw_spinlocks) because it's not right to acquire spinlocks while holding raw_spinlocks in RT mode. Signed-off-by: Liu Shixin Acked-by: Catalin Marinas --- mm/kmemleak.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/mm/kmemleak.c b/mm/kmemleak.c index 22bab3738a9e..5501363d6b31 100644 --- a/mm/kmemleak.c +++ b/mm/kmemleak.c @@ -1152,6 +1152,7 @@ EXPORT_SYMBOL_GPL(kmemleak_free_percpu); void __ref kmemleak_update_trace(const void *ptr) { struct kmemleak_object *object; + depot_stack_handle_t trace_handle; unsigned long flags; pr_debug("%s(0x%px)\n", __func__, ptr); @@ -1168,8 +1169,9 @@ void __ref kmemleak_update_trace(const void *ptr) return; } + trace_handle = set_track_prepare(); raw_spin_lock_irqsave(&object->lock, flags); - object->trace_handle = set_track_prepare(); + object->trace_handle = trace_handle; raw_spin_unlock_irqrestore(&object->lock, flags); put_object(object);