From patchwork Fri Jul 12 03:13:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miaohe Lin X-Patchwork-Id: 13731260 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 3898AC3DA49 for ; Fri, 12 Jul 2024 03:17:51 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 988C76B0092; Thu, 11 Jul 2024 23:17:50 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 938C46B0098; Thu, 11 Jul 2024 23:17:50 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 800846B009A; Thu, 11 Jul 2024 23:17:50 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 624636B0092 for ; Thu, 11 Jul 2024 23:17:50 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 0B15FC08F5 for ; Fri, 12 Jul 2024 03:17:50 +0000 (UTC) X-FDA: 82329641100.14.C82D4D4 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by imf29.hostedemail.com (Postfix) with ESMTP id 62FD8120009 for ; Fri, 12 Jul 2024 03:17:47 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf29.hostedemail.com: domain of linmiaohe@huawei.com designates 45.249.212.255 as permitted sender) smtp.mailfrom=linmiaohe@huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1720754230; 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: references; bh=OMT19V2qu2/Gj9cpb4WJL5UL45be7fV15mj3l2ZEeZs=; b=3ogUWGmg5dWv2veoaqqKxI2X67gYd5u+p5SojIhSGzuCcXGXr+GqtF9cUOknnStQaaBQLY Va8xC0TG1gPh4aX4mrrmdDa0koU9pixIauWdAq3gmotg/qfg4iYuS40pP648CkeVnnA/c2 P0j8jVvHvWdhlz9wFmgyQOKG834aURU= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1720754230; a=rsa-sha256; cv=none; b=r7xNvi+T/N4x3dHw5d61WiA9b8oBfft8rpuelrv5iv2CSpjblR4AAKcHyWKcU2lR4ycNni n2DxFghONoGBBpwxx8f2o94W/aJAeeJz0Axz+LU45iCn/eHLnHLoiK7tIPHji/4H2hjzN9 rrsoyGT9MeHaOTgfFirnZgo10GxsxaM= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf29.hostedemail.com: domain of linmiaohe@huawei.com designates 45.249.212.255 as permitted sender) smtp.mailfrom=linmiaohe@huawei.com Received: from mail.maildlp.com (unknown [172.19.163.48]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4WKxVd2l1Dz1T67S; Fri, 12 Jul 2024 11:12:57 +0800 (CST) Received: from kwepemd200019.china.huawei.com (unknown [7.221.188.193]) by mail.maildlp.com (Postfix) with ESMTPS id 2547818009B; Fri, 12 Jul 2024 11:17:42 +0800 (CST) Received: from huawei.com (10.173.127.72) by kwepemd200019.china.huawei.com (7.221.188.193) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Fri, 12 Jul 2024 11:17:41 +0800 From: Miaohe Lin To: , CC: , , Subject: [PATCH v2] mm/hugetlb: fix possible recursive locking detected warning Date: Fri, 12 Jul 2024 11:13:14 +0800 Message-ID: <20240712031314.2570452-1-linmiaohe@huawei.com> X-Mailer: git-send-email 2.33.0 MIME-Version: 1.0 X-Originating-IP: [10.173.127.72] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To kwepemd200019.china.huawei.com (7.221.188.193) X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 62FD8120009 X-Stat-Signature: c9xt5srr3xqiyah4jxkq8mgwfasxrrop X-Rspam-User: X-HE-Tag: 1720754267-487779 X-HE-Meta: U2FsdGVkX1+z3Zs4GUhPGzK9184SKO5LJoQ3MPfqcEMX1G8LMyFbGu8V5Cjww7bzKIpb92iTca0iYby/O2UU2rovp110zrw0DkG0BrJ6gTfuaiy+6ZjvmkvG3+nsgH2N91WV/jqxypw39q4F9IxvT7MCxQlGsVcqt+MtNbz44py/AN2GnvnWZfuQuWFWaVHpWak9RZHCgL7r/0SIVIMlKkoRoJRKEUT9nrt+e79OglG3+XKTjzE2nTGG3JgGW/pQGoCFUbcpsM9q+npPRahX4QUatr7/nsvK4YqaGmx8OMBOZ9N2x9RogWfvf7L5A9fcEwtRfNWz/b0wQjR7c3ltE43IYXHZbJD0emUTn15s3xux7I1OiLajlCpUgR269l/WPNsv6VGeBM/yvSBsmg5bsiDKLRC8LJ58jroBaBodMFQGDEBlBisnQpkBni90yj7bUpfyJuwNxldWWmeqFMzJNsJ4wWeCl3CnH4fEAtpw0r8iHwkTlmd8WcmMdGn+RD1dpk+GU203UbnAl9qFmQ9NxzaJouNwM1Fy9iMK0pfBuMEBJKdSt9arZhv64m+/z+c9B/foxlcWFnTVz0VxjMYAPT+5LI/aceJnQBrkHsN4dtxG+fV49BLH3w6i+ImVbDIXvuGlCTm49vg/3uQd8h1XkbVQt1YW6kCt42qxJaOnplWj8sUd7CxpMyBMhSMeb0fmazFj96HceNttZXRFzD/IwAh0AZFK00a1NadYio/mirbUAWvVcRnN+pqPYqet0pCKgg4D9L5yBRpwpDIr2qGN2fLSrTU+4cxt1TjVWsEsEgXkiI1Ov/UjfMPkHuNQ6TlAcrWDk0RbySFAYksX6CHt3eIT3+qJTzFGX45STRxrOqv6gAGIka5Y8gI/RjEbflKXOS0ZyHtfDRTBPh0wJQ+u2FHYNUAj6QTua6RFo1fF5RE2gre7LDYCpK6xShEkR6DktuPI0sV5n+43oMtujKd iWMMSOgB LQS9JYCP/+5Puy4P5l5hZyb0XbqkT+cucUypQ99PCBli9JM+9epiek7ctYXqqxss5M3uYe/SSRmllHQ0rAJiy1zY41EGBFaeZ7tOjkMpR8kb0xfwpleaJs/v9adiymzUHkim2NRKonxT4tfLQvb1ZwvGNK8qK1H04wbSYBZrXeNkc9fHrfPEea4jCLkxZOwbtKWlG 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: When tries to demote 1G hugetlb folios, a lockdep warning is observed: ============================================ WARNING: possible recursive locking detected 6.10.0-rc6-00452-ga4d0275fa660-dirty #79 Not tainted -------------------------------------------- bash/710 is trying to acquire lock: ffffffff8f0a7850 (&h->resize_lock){+.+.}-{3:3}, at: demote_store+0x244/0x460 but task is already holding lock: ffffffff8f0a6f48 (&h->resize_lock){+.+.}-{3:3}, at: demote_store+0xae/0x460 other info that might help us debug this: Possible unsafe locking scenario: CPU0 ---- lock(&h->resize_lock); lock(&h->resize_lock); *** DEADLOCK *** May be due to missing lock nesting notation 4 locks held by bash/710: #0: ffff8f118439c3f0 (sb_writers#5){.+.+}-{0:0}, at: ksys_write+0x64/0xe0 #1: ffff8f11893b9e88 (&of->mutex#2){+.+.}-{3:3}, at: kernfs_fop_write_iter+0xf8/0x1d0 #2: ffff8f1183dc4428 (kn->active#98){.+.+}-{0:0}, at: kernfs_fop_write_iter+0x100/0x1d0 #3: ffffffff8f0a6f48 (&h->resize_lock){+.+.}-{3:3}, at: demote_store+0xae/0x460 stack backtrace: CPU: 3 PID: 710 Comm: bash Not tainted 6.10.0-rc6-00452-ga4d0275fa660-dirty #79 Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.14.0-0-g155821a1990b-prebuilt.qemu.org 04/01/2014 Call Trace: dump_stack_lvl+0x68/0xa0 __lock_acquire+0x10f2/0x1ca0 lock_acquire+0xbe/0x2d0 __mutex_lock+0x6d/0x400 demote_store+0x244/0x460 kernfs_fop_write_iter+0x12c/0x1d0 vfs_write+0x380/0x540 ksys_write+0x64/0xe0 do_syscall_64+0xb9/0x1d0 entry_SYSCALL_64_after_hwframe+0x77/0x7f RIP: 0033:0x7fa61db14887 RSP: 002b:00007ffc56c48358 EFLAGS: 00000246 ORIG_RAX: 0000000000000001 RAX: ffffffffffffffda RBX: 0000000000000002 RCX: 00007fa61db14887 RDX: 0000000000000002 RSI: 000055a030050220 RDI: 0000000000000001 RBP: 000055a030050220 R08: 00007fa61dbd1460 R09: 000000007fffffff R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000002 R13: 00007fa61dc1b780 R14: 00007fa61dc17600 R15: 00007fa61dc16a00 Lockdep considers this an AA deadlock because the different resize_lock mutexes reside in the same lockdep class, but this is a false positive. Place them in distinct classes to avoid these warnings. Fixes: 8531fc6f52f5 ("hugetlb: add hugetlb demote page support") Signed-off-by: Miaohe Lin Acked-by: Muchun Song --- v2: move lock_class_key into struct hstate and use __mutex_init per Muchun. Thanks. --- include/linux/hugetlb.h | 1 + mm/hugetlb.c | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/include/linux/hugetlb.h b/include/linux/hugetlb.h index 98c2c1106500..b84da6f6ac40 100644 --- a/include/linux/hugetlb.h +++ b/include/linux/hugetlb.h @@ -649,6 +649,7 @@ HPAGEFLAG(RawHwpUnreliable, raw_hwp_unreliable) /* Defines one hugetlb page size */ struct hstate { struct mutex resize_lock; + struct lock_class_key resize_key; int next_nid_to_alloc; int next_nid_to_free; unsigned int order; diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 45fd3bc75332..926b89e165bd 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -4670,7 +4670,7 @@ void __init hugetlb_add_hstate(unsigned int order) BUG_ON(hugetlb_max_hstate >= HUGE_MAX_HSTATE); BUG_ON(order < order_base_2(__NR_USED_SUBPAGE)); h = &hstates[hugetlb_max_hstate++]; - mutex_init(&h->resize_lock); + __mutex_init(&h->resize_lock, "resize mutex", &h->resize_key); h->order = order; h->mask = ~(huge_page_size(h) - 1); for (i = 0; i < MAX_NUMNODES; ++i)