From patchwork Tue Jul 2 04:26:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: zhangchun X-Patchwork-Id: 13718945 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 29F6CC3064D for ; Tue, 2 Jul 2024 04:27:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7F23D6B0085; Tue, 2 Jul 2024 00:27:21 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7A2336B0089; Tue, 2 Jul 2024 00:27:21 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 642AA6B008A; Tue, 2 Jul 2024 00:27:21 -0400 (EDT) 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 44DA66B0085 for ; Tue, 2 Jul 2024 00:27:21 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id E48C71A1ECE for ; Tue, 2 Jul 2024 04:27:20 +0000 (UTC) X-FDA: 82293528240.19.9099A3A Received: from h3cspam02-ex.h3c.com (smtp.h3c.com [60.191.123.50]) by imf19.hostedemail.com (Postfix) with ESMTP id 49FB61A0004 for ; Tue, 2 Jul 2024 04:27:17 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf19.hostedemail.com: domain of zhang.chunA@h3c.com designates 60.191.123.50 as permitted sender) smtp.mailfrom=zhang.chunA@h3c.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1719894417; 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=r66APsfbuZwhaGtdICg8m8ISseHQCJgnvESBj7Fq7W0=; b=xJ/FU3ZnLinhibnltzD5NMej8ues3wrft0UglNff45QU8FfcvEIDJzg2nCqw3dxzLCvtN0 yR2dssChRMu2wsk2Z+pZbTABtZq3VHFN1RtLClr3BTVZbUDEMM2z7FSSfYRAEqL/6sndvm vkERpZLjP8h+BBOgWtnjhdnTb6p22us= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1719894417; a=rsa-sha256; cv=none; b=CqbM7sSK0MY3txDdkjXXxfStRupAdkxprN4Lk9DWs3ZUoc9a/7wqXd8HuR0OJokP5yVjlK 1vqpAiNUNUB5eSx7983wyWrkZCOGJziWoUT1Vahu6VpyAZcF4KqiIVIuVOKwPKvplkhD9O 6mbvbqqL/UXmm76G9DwVhfZ96lwAKac= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf19.hostedemail.com: domain of zhang.chunA@h3c.com designates 60.191.123.50 as permitted sender) smtp.mailfrom=zhang.chunA@h3c.com Received: from mail.maildlp.com ([172.25.15.154]) by h3cspam02-ex.h3c.com with ESMTP id 4624QwPG039760; Tue, 2 Jul 2024 12:26:58 +0800 (GMT-8) (envelope-from zhang.chunA@h3c.com) Received: from DAG6EX11-BJD.srv.huawei-3com.com (unknown [10.153.34.13]) by mail.maildlp.com (Postfix) with ESMTP id 630F62004BA2; Tue, 2 Jul 2024 12:31:02 +0800 (CST) Received: from DAG6EX09-BJD.srv.huawei-3com.com (10.153.34.11) by DAG6EX11-BJD.srv.huawei-3com.com (10.153.34.13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1258.27; Tue, 2 Jul 2024 12:26:59 +0800 Received: from DAG6EX09-BJD.srv.huawei-3com.com ([fe80::bdc5:ad7:2347:12a5]) by DAG6EX09-BJD.srv.huawei-3com.com ([fe80::bdc5:ad7:2347:12a5%4]) with mapi id 15.02.1258.027; Tue, 2 Jul 2024 12:26:59 +0800 From: Zhangchun To: "akpm@linux-foundation.org" , "linux-mm@kvack.org" , "linux-kernel@vger.kernel.org" CC: "linux-kernel@vger.kernel.org" , Jiaoxupo , Bailin , Zhangzhansheng , "linux-mm@kvack.org" , wangyu , "shaohaojize@126.com" , Zhangzhengming Subject: [PATCH] mm: fix kmap_high deadlock V2 Thread-Topic: [PATCH] mm: fix kmap_high deadlock V2 Thread-Index: AdrMNwI2VvTxTh3MSgCT1mPrIo0cfgAAO7Gg Date: Tue, 2 Jul 2024 04:26:59 +0000 Message-ID: <7caa255fa5fe4e8e9c6a05084a1faf72@h3c.com> Accept-Language: en-US Content-Language: zh-CN X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.135.168.35] x-sender-location: DAG2 MIME-Version: 1.0 X-DNSRBL: X-MAIL: h3cspam02-ex.h3c.com 4624QwPG039760 X-Rspamd-Queue-Id: 49FB61A0004 X-Stat-Signature: wks7pmx38umuzm3fboby4bhen4ypjfrp X-Rspamd-Server: rspam09 X-Rspam-User: X-HE-Tag: 1719894437-309839 X-HE-Meta: U2FsdGVkX19Op5TwIDOglonmSEo2ye79mh2iDrJHSDybuypiWxafnI+uKP+1m9FfR/b/+o6c6gCBRH9nYkA6qQYVsX++k0VHRyx7KOBFfOdO4cgBSvtYmOiKxcdpA9l3shI+7fQGLWF0lA5oKzU1RKJgUCl4M8cj+IkWpq9YG2AO5M6L3NRjLgGdOWq1XzbfzCKt0Orz22TPd2Jt8fuv8tyBnCOjab9I7Y0LuWzQWEulUDAfyMPVXir1W3zRvJnyTbKGR8Ju3mlE2mwCAQ0IiZVQ+16128xlFE3ZXMgfeLw1U1+Fo+YM1r8Qel3TdD8L8qejvhpOZ99eAbopXbveaeP5RCenHk2N1pXB1UqrMvUkDsleALtmlnAsqNMoDIyBLYFESaWuxu5Rcp/s10QOn4uSHK6fjOP6jiopgw8v1ihlQ5C8Hj5WrXqJoNgDHQs9s304J/yzCZI939IXeJroG7TPdR2uttHw9qhWT7JKOXSPCAMKfUZr+n/fHnbWhFKV+9xOeADE8oj5cE+BKJ0vtcAToiELR7yNQzKTTggGaRGTyXx63+xVrlcx/la09RGSikIrkYqoVukmDZV8ODXWTu/gge6Afh2AbI5s5ZZtj9g9vkz01Wrwq+Ql9DLnYg7X59i+hxHeyXu/Wz0ef9B00mJJzpPDeSSF6VsctsPekXeZqZrnFNY8nzsHjXIKL6Ilu8b3I33uZQS7WNtFXGsmw1JPVYBc+JnDMx0etHRZdqxOrennGCgHYwAKeB40G1ebfM8nfoIowIvwqxwTZwO7kYv/5s/KKh5xCV09m/C/Tf2PH/G/qc0USzY9p9VpGwidrt8wBWOX2Nkamxa1RmZv9YUEPkcragwNK6vJ8+ByLS8IaAOGJHaqZRVL1XVeIhx+DIs8cD+/nHZKrC4qQGLkTbAziTifzJoQB2s6UVVKKuvkptbmPVIOEoJ3v74Qpzru19py3CzpKoTxhfbLkrQ 6I24dv+a Mh+hzvnakbcBBpHMcW3ZPdHmCKxAZF7R5u26bbbZ+vsCbJr+8A0O9wjQUXopbpiQ2ALADKRzWGGx7uNBkNVBYNW1aBEESt8SS0CjlRxRWiPx1rm4OnSjr5VZKy+QBJ79TLq4kDs4z6QTZzHBrjLHinOapb7mtcj+4d7FegNrwZtuBLZpc7FHGzj1BP2CVLKGSse8LrJkqN7d72gwPeZpdHmIS1axSJ5ZZ2vg9RKpOjYCpXlhX+EoIHVKPwN/RQX8gpoAFi0Y4J5v5gningfjBflf9wgVfjIL9QjUXmMhP+Ni53rrSUnS94fnk6Z9euRU0XQwHfapY6IN8xzwwnAPQGrsgEi7XfbauuP9cG544Bic8D1FMGtv83IU58oaZwEEhs37n 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: From: "zhang.chun" I work with zhangzhansheng(from h3c) find that some situation may casue deadlock when we use kmap_high and kmap_XXX or kumap_xxx between differt cores at the same time, kmap_high->map_new_virtual-> flush_all_zero_pkmaps->flush_tlb_kernel_range->on_each_cpu. On this condition, kmap_high hold the kmap_lock,wait the other cores respond to ipi. But the others may disable irq and wait kmap_lock, this is some deadlock condition. I think it's necessary to give kmap_lock before call flush_tlb_kernel_range. Like this: spin_unlock(&kmap_lock); flush_tlb_kernel_range(xxx); spin_lock(&kmap_lock); CPU 0: cpu 1: kmap_xxx() { xxx irq_disable(); kmap_high(); spin_lock(&kmap_lock) xxx yyyyyyy spin_unlock(&kmap_lock) irq_enable(); } kmap_high detail: kmap_high() { zzz spin_lock(&kmap_lock) map_new_virtual-> flush_all_zero_pkmaps-> flush_tlb_kernel_range-> on_each_cpu /* if cpu 1 irq_disabled, the cpu 1 cannot ack, then cpu 0 and cpu 1 may hangup. */ spin_unlock(&kmap_lock) zzz } Signed-off-by: zhangchun Reviewed-by: zhangzhengming --- mm/highmem.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) -- 2.34.1 ------------------------------------------------------------------------------------------------------------------------------------- 本邮件及其附件含有新华三集团的保密信息,仅限于发送给上面地址中列出 的个人或群组。禁止任何其他人以任何形式使用(包括但不限于全部或部分地泄露、复制、 或散发)本邮件中的信息。如果您错收了本邮件,请您立即电话或邮件通知发件人并删除本 邮件! This e-mail and its attachments contain confidential information from New H3C, which is intended only for the person or entity whose address is listed above. Any use of the information contained herein in any way (including, but not limited to, total or partial disclosure, reproduction, or dissemination) by persons other than the intended recipient(s) is prohibited. If you receive this e-mail in error, please notify the sender by phone or email immediately and delete it! diff --git a/mm/highmem.c b/mm/highmem.c index bd48ba4..841b370 100644 --- a/mm/highmem.c +++ b/mm/highmem.c @@ -220,8 +220,11 @@ static void flush_all_zero_pkmaps(void) set_page_address(page, NULL); need_flush = 1; } - if (need_flush) + if (need_flush) { + spin_unlock(&kmap_lock); flush_tlb_kernel_range(PKMAP_ADDR(0), PKMAP_ADDR(LAST_PKMAP)); + spin_lock(&kmap_lock); + } } void __kmap_flush_unused(void)