From patchwork Tue Jul 2 04:25:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: zhangchun X-Patchwork-Id: 13718944 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 6C5BCC30658 for ; Tue, 2 Jul 2024 04:25:48 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 865FF6B0085; Tue, 2 Jul 2024 00:25:47 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 815986B0088; Tue, 2 Jul 2024 00:25:47 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6B6ED6B0089; Tue, 2 Jul 2024 00:25:47 -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 4558D6B0085 for ; Tue, 2 Jul 2024 00:25:47 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id E1D44A4728 for ; Tue, 2 Jul 2024 04:25:46 +0000 (UTC) X-FDA: 82293524292.14.2E7F8A5 Received: from h3cspam02-ex.h3c.com (smtp.h3c.com [60.191.123.50]) by imf26.hostedemail.com (Postfix) with ESMTP id B4532140003 for ; Tue, 2 Jul 2024 04:25:43 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf26.hostedemail.com: domain of zhang.chunA@h3c.com designates 60.191.123.50 as permitted sender) smtp.mailfrom=zhang.chunA@h3c.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1719894328; a=rsa-sha256; cv=none; b=vbPB4ljdGdrvNzfOwrtA3s6TOP9rjcDETgWfcUy6+36uDV2C5TiKG5e3mpVItPK/W4PNjn 83OLAqWU7MP+bxz5EFpS+03h10TCfAnwS/n+1JC2TOz1aodO8mH2GAQpUXCj/vpKLaLVtp VZ+iWWr/I7a9F7Hakmbi1yD2OCPRPQY= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf26.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=1719894328; 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=SuJc4OEyExGwACZMDCD/xYprfwvsJvTpP68zsYMaySc=; b=bnso13geo7QAsNk1M36NPbBvR/vhCIzylnzxKRrOCDpfA4OjSXFZrBcSVpAJm0SGuDGNbZ TfNzW+pkVuoJ6lPuxlyXo0uor0itUWqhkfLPrV13Sn7f7pEzUvF5BwZ4LX2k/JoblMZFbI N3u8ptpyYfiTH+P4C90agaCYyEVylMU= Received: from mail.maildlp.com ([172.25.15.154]) by h3cspam02-ex.h3c.com with ESMTP id 4624PGLn037323; Tue, 2 Jul 2024 12:25:16 +0800 (GMT-8) (envelope-from zhang.chunA@h3c.com) Received: from DAG6EX12-BJD.srv.huawei-3com.com (unknown [10.153.34.14]) by mail.maildlp.com (Postfix) with ESMTP id 472E02004BAA; Tue, 2 Jul 2024 12:29:20 +0800 (CST) Received: from DAG6EX09-BJD.srv.huawei-3com.com (10.153.34.11) by DAG6EX12-BJD.srv.huawei-3com.com (10.153.34.14) 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:25:17 +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:25:17 +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" Subject: =?utf-8?b?562U5aSNOiAgW1BBVENIXSBtbTogZml4IGttYXBfaGlnaCBkZWFkbG9j?= =?utf-8?b?ayBWMg==?= Thread-Topic: [PATCH] mm: fix kmap_high deadlock V2 Thread-Index: AdrMNwI2VvTxTh3MSgCT1mPrIo0cfg== Date: Tue, 2 Jul 2024 04:25:17 +0000 Message-ID: <7e855a8ff82743979be9bb15363f98dc@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 4624PGLn037323 X-Rspamd-Queue-Id: B4532140003 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: 3oe1x97kzqjotsxpiyy6p99zz7qwkx41 X-HE-Tag: 1719894343-894132 X-HE-Meta: U2FsdGVkX18PhRqCu2Be9MYsGecaCmKLC4lLqQbax6c0/z4K6pj6cQYN2ulKyNPjx8weQ3efpglY90ij32Cxl93uCaB4GjNm/W80wqOYJEFV44pHab63TX14ONQfkzjQvslJFyz1BB6XXUQHlDYcOi96qsHID0mpCzz1ZDQocltYKugE3cnpbtdLVWYLboskrtaSd2VBHVoCOokPy2Uu65cCF+oP7LDaSnqiSdFClZtBd7JDRiYBvgR/4eyk9DR9ZgS49d0fyQUQuAx28bqI7NRr2aLvXMW7oysIDVfjbNvJfzrlJ2PQK6m0q8/REDuasJVjlpHVxdW4Hi++C4QG5Hnq5ep4uonCxC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ity=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)