From patchwork Thu Jul 11 07:10:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miaohe Lin X-Patchwork-Id: 13730079 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 3C496C3271E for ; Thu, 11 Jul 2024 07:14:35 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AE5DF6B0093; Thu, 11 Jul 2024 03:14:34 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A94006B0095; Thu, 11 Jul 2024 03:14:34 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 95D2D6B0096; Thu, 11 Jul 2024 03:14:34 -0400 (EDT) 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 788A16B0093 for ; Thu, 11 Jul 2024 03:14:34 -0400 (EDT) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 28FF61A045E for ; Thu, 11 Jul 2024 07:14:34 +0000 (UTC) X-FDA: 82326608868.27.994197E Received: from szxga06-in.huawei.com (szxga06-in.huawei.com [45.249.212.32]) by imf17.hostedemail.com (Postfix) with ESMTP id 61FAA40005 for ; Thu, 11 Jul 2024 07:14:30 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=none; spf=pass (imf17.hostedemail.com: domain of linmiaohe@huawei.com designates 45.249.212.32 as permitted sender) smtp.mailfrom=linmiaohe@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1720682055; a=rsa-sha256; cv=none; b=JEH0aVXSl1cmvSR8gMrcRrVV0wVsN3IeZYk44jhF1z+c3xRmx+V7Zz8CSV2pjBYUA2g4p4 ItEwkbS94ceYFFovlteCkMdbVyaJGHEQoyztbC7/Z/GtXN+cSBOv5w/sdwZiO9dEPJJOHA xe8prlgeCxPTKKGTa34y6FFjorJuLp8= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=none; spf=pass (imf17.hostedemail.com: domain of linmiaohe@huawei.com designates 45.249.212.32 as permitted sender) smtp.mailfrom=linmiaohe@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=1720682055; 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=LP0D52Z2Tzhp9uFLhDfMkr+BjdvorS0kFGrcAm/iZNs=; b=fI88bWp6/qhzQMxIHNoKHV2q7yk3WcO8XsNcL/59DvOj9X9sK0prn1zmT5en2g6oOYTy98 O7RBT46CjK+5rDrQTZVZRmRqmBEcHMRMaavAJiPEak/xN8Lm4lQ+8qTYei2U3mHUSsN8eu rp1tPGHROJoJHu5X95fRizGCdmFV/cE= Received: from mail.maildlp.com (unknown [172.19.163.44]) by szxga06-in.huawei.com (SkyGuard) with ESMTP id 4WKQss6qrbz1xtVx; Thu, 11 Jul 2024 15:12:49 +0800 (CST) Received: from kwepemd200019.china.huawei.com (unknown [7.221.188.193]) by mail.maildlp.com (Postfix) with ESMTPS id 1D5E014010C; Thu, 11 Jul 2024 15:14:26 +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; Thu, 11 Jul 2024 15:14:25 +0800 From: Miaohe Lin To: , CC: , , Subject: [PATCH] mm/hugetlb: fix possible recursive locking detected warning Date: Thu, 11 Jul 2024 15:10:01 +0800 Message-ID: <20240711071001.3475337-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: dggems702-chm.china.huawei.com (10.3.19.179) To kwepemd200019.china.huawei.com (7.221.188.193) X-Stat-Signature: bkxu4fbzb9fph8n3dwxa9xmqec6rd1wb X-Rspamd-Queue-Id: 61FAA40005 X-Rspam-User: X-Rspamd-Server: rspam10 X-HE-Tag: 1720682070-524731 X-HE-Meta: U2FsdGVkX1+U0/sYXO4snU8VILFYKXbQvqfK9bnFEpnLzaKks56EX+63j6zJR8ax4ec4yfPwSZXAgygNTYBxZTK1tt2NzKVOEVl0aMAkJTF1kJGcaeA2s8LxRZo48PxBGChKSxm4NtoRbENE1Fg0YvxYWt/+ss8FeLzATB3W6STtVL0tHEUfZH6BoV9iDhosszHzCOAuSK2rql0ZKF+aNMoX+jh4n9xz1L/LSL05ztnDFWwvUitGKiwZ7dp9Yqvj8koAX0PBbBRo3elsjLrgOG5xQzzyKcZi8pech9967Kcgm5kRi5eyzVHFo9QmarCjjLJVMGDHqLqsv6mEIFcUREG/qYlszemjBlt488cua+yI3Eg9/WoQ1n7er4fAGAsupxG4gUlyypnr/WAfhjqq8TKMiaDatJ4FZ3Z3SHW4E8NZBIHRZaJNpitGED0NJqCDh/iljJyqcP5NlaBoDCnIMj/cniIHZYQxbAHSZLOn3Fy/bvsDrA9dkuk5a3+Hq9oQO3ZOaXzKOoynoq2JQyh3U7AqLh0AXBj0VoAWgnUuMQ9lFncBCc7zbnDBTj5Tqn8GDGQL6PWwD0WEJPDhcyk0P21Mkxkl9gwN1bVhBN0UG0PKiAgrMgzfQlN8w6xYE2wWiKQNNvVXPLMFsDIL99NYW9GcpZavIuTQw3JQpi03waw+7tbKm2FedrM4vPu50f8sZMDyYmmjAQRDiEGEfv1b5b+Es1b/Njn8BGTNF8wCAQzl1gMKclsRPS4AfApSH+Hz4H0ECjOoLBlsWKcWTD09alsSQKm52AKhq1KiwAYwcdf7bztu4McBi7BoGXXpRBAp8UCYCPWBjVeYUa363CWNXpM+c/h2c6yZCqqAVn7tb7hbCqU0enI/BGey9WtuQJ92efalRwapNEJ+wnM6tKDe8bolDYBmUql+TXyrAHxKs0mCuENKNTV9eArEpmA/B7x/Ns4Qxa8x4bIscVXNmJV ksN3fcKN dau5KXvZJOBol1M6ZGzNcwI4OGxJKjizqSeIXypGpuO0ntl2Z+nCXEEPfTZd5PqYDc7UaHLWQbWvLZCeFGYIKD3FhBfyVxHzJ0hQcPkQisOmcufCtf9CdeGAQiJyE2vbqvQNFOdWFkryQyNuJ+wcZqpBOFM2+OJMslNXpfPFFllj9Lr3jCd367BWriSeLe34NunFt 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 --- mm/hugetlb.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 45fd3bc75332..2004e6d3f7ca 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -4659,6 +4659,8 @@ bool __init __attribute((weak)) arch_hugetlb_valid_size(unsigned long size) return size == HPAGE_SIZE; } +static struct lock_class_key hugetlb_resize_keys[HUGE_MAX_HSTATE]; + void __init hugetlb_add_hstate(unsigned int order) { struct hstate *h; @@ -4671,6 +4673,7 @@ void __init hugetlb_add_hstate(unsigned int order) BUG_ON(order < order_base_2(__NR_USED_SUBPAGE)); h = &hstates[hugetlb_max_hstate++]; mutex_init(&h->resize_lock); + lockdep_set_class(&h->resize_lock, &hugetlb_resize_keys[hstate_index(h)]); h->order = order; h->mask = ~(huge_page_size(h) - 1); for (i = 0; i < MAX_NUMNODES; ++i)