From nobody Fri Dec 19 09:10:03 2025 Received: from h3cspam02-ex.h3c.com (smtp.h3c.com [60.191.123.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 51B46372 for ; Tue, 2 Jul 2024 04:27:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=60.191.123.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719894449; cv=none; b=AF3uKESgZxQsMeQ5kJ2CebP6MbBG9PXav30rSD+aKhOuLk8mFFFVCPH02x1vGlRoR450Cjlm2F11dba9xiMF16+AxbcxR21NIR6ZyZwX/IpTh05liIWppgN4NdnwSrU5GwPd+xQ2buTTGCm1tBfcgDn+GlRm7QH9jREw1cDtNM4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719894449; c=relaxed/simple; bh=r66APsfbuZwhaGtdICg8m8ISseHQCJgnvESBj7Fq7W0=; h=From:To:CC:Subject:Date:Message-ID:Content-Type:MIME-Version; b=IvaoTP9KARM1x5oJNFtjExnE5m12M5hrc18zTDVn7Qz4FZ23ltRstyFnNeX9eWSBxfqf5L4cFoeNk9K+coLIx86MtC9uO8XZlO7NUN9GF5rEXAb6WRngzXtUf++1CEOe0ghkQp1mUHRMJLALNCod0bOIVbkKhM+4N8hFrARriDY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=h3c.com; spf=pass smtp.mailfrom=h3c.com; arc=none smtp.client-ip=60.191.123.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=h3c.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=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-sender-location: DAG2 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-DNSRBL: X-SPAM-SOURCE-CHECK: pass X-MAIL: h3cspam02-ex.h3c.com 4624QwPG039760 From: "zhang.chun" I work with zhangzhansheng(from h3c) find that some situation may casue dea= dlock when we use kmap_high and kmap_XXX or kumap_xxx between differt core= s at the same time, kmap_high->map_new_virtual-> flush_all_zero_pkmaps->fl= ush_tlb_kernel_range->on_each_cpu. On this condition, kmap_high hold the km= ap_lock=EF=BC=8Cwait the other cores respond to ipi. But the others may dis= able 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(-) 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 =3D 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) -- 2.34.1 ---------------------------------------------------------------------------= ---------------------------------------------------------- =E6=9C=AC=E9=82=AE=E4=BB=B6=E5=8F=8A=E5=85=B6=E9=99=84=E4=BB=B6=E5=90=AB=E6= =9C=89=E6=96=B0=E5=8D=8E=E4=B8=89=E9=9B=86=E5=9B=A2=E7=9A=84=E4=BF=9D=E5=AF= =86=E4=BF=A1=E6=81=AF=EF=BC=8C=E4=BB=85=E9=99=90=E4=BA=8E=E5=8F=91=E9=80=81= =E7=BB=99=E4=B8=8A=E9=9D=A2=E5=9C=B0=E5=9D=80=E4=B8=AD=E5=88=97=E5=87=BA =E7=9A=84=E4=B8=AA=E4=BA=BA=E6=88=96=E7=BE=A4=E7=BB=84=E3=80=82=E7=A6=81=E6= =AD=A2=E4=BB=BB=E4=BD=95=E5=85=B6=E4=BB=96=E4=BA=BA=E4=BB=A5=E4=BB=BB=E4=BD= =95=E5=BD=A2=E5=BC=8F=E4=BD=BF=E7=94=A8=EF=BC=88=E5=8C=85=E6=8B=AC=E4=BD=86= =E4=B8=8D=E9=99=90=E4=BA=8E=E5=85=A8=E9=83=A8=E6=88=96=E9=83=A8=E5=88=86=E5= =9C=B0=E6=B3=84=E9=9C=B2=E3=80=81=E5=A4=8D=E5=88=B6=E3=80=81 =E6=88=96=E6=95=A3=E5=8F=91=EF=BC=89=E6=9C=AC=E9=82=AE=E4=BB=B6=E4=B8=AD=E7= =9A=84=E4=BF=A1=E6=81=AF=E3=80=82=E5=A6=82=E6=9E=9C=E6=82=A8=E9=94=99=E6=94= =B6=E4=BA=86=E6=9C=AC=E9=82=AE=E4=BB=B6=EF=BC=8C=E8=AF=B7=E6=82=A8=E7=AB=8B= =E5=8D=B3=E7=94=B5=E8=AF=9D=E6=88=96=E9=82=AE=E4=BB=B6=E9=80=9A=E7=9F=A5=E5= =8F=91=E4=BB=B6=E4=BA=BA=E5=B9=B6=E5=88=A0=E9=99=A4=E6=9C=AC =E9=82=AE=E4=BB=B6=EF=BC=81 This e-mail and its attachments contain confidential information from New H= 3C, which is intended only for the person or entity whose address is listed above. Any u= se of the information contained herein in any way (including, but not limited to, tot= al or partial disclosure, reproduction, or dissemination) by persons other than the inten= ded recipient(s) is prohibited. If you receive this e-mail in error, please not= ify the sender by phone or email immediately and delete it!