From patchwork Tue Jul 9 09:17:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: zhangchun X-Patchwork-Id: 13727521 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 D80FEC2BD09 for ; Tue, 9 Jul 2024 09:17:19 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2A8606B0099; Tue, 9 Jul 2024 05:17:19 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 257186B009A; Tue, 9 Jul 2024 05:17:19 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 11F626B009B; Tue, 9 Jul 2024 05:17:19 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id E71F56B0099 for ; Tue, 9 Jul 2024 05:17:18 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 8D980A17B6 for ; Tue, 9 Jul 2024 09:17:18 +0000 (UTC) X-FDA: 82319660556.09.365A205 Received: from h3cspam02-ex.h3c.com (smtp.h3c.com [60.191.123.50]) by imf20.hostedemail.com (Postfix) with ESMTP id 23C4B1C000C for ; Tue, 9 Jul 2024 09:17:14 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=none; spf=pass (imf20.hostedemail.com: domain of zhang.chunA@h3c.com designates 60.191.123.50 as permitted sender) smtp.mailfrom=zhang.chunA@h3c.com; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1720516621; 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=bVbdthIE8nohe75PwZ3e3nfZCpdbnOzXkVDgll1QtBk=; b=G5GRnxGa7wD2LbbfU5wjYVupKCV4SisL22FNf4BZ50I6Tm8GwZcGY1RQfd2aqibKkAFWpb /ocP9Yuu/PMr2txJAI867igUMfOyhu7vj9M3kr+4xDCmD0iH6f6hKicDGCZREcS6G4SSEi 9xdg8DmRjA7sktKnMdLpqUgpAmhC6cI= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=none; spf=pass (imf20.hostedemail.com: domain of zhang.chunA@h3c.com designates 60.191.123.50 as permitted sender) smtp.mailfrom=zhang.chunA@h3c.com; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1720516621; a=rsa-sha256; cv=none; b=BcjuNIZcEuWalbqT1nRshiwnIcXisjVKJhyRZqmzkg9ohd0ZhMjPIGNofpV7KbFEgSnMPI qoJGod/pJxAw7V7+uE3ofmwyCtBAyva/WobEkqQ/TglfdiyGTcVgnf1lAypnkP6enz+OhX kVysHkJzPwbd4mmuNVULU0UQKxijfdI= Received: from mail.maildlp.com ([172.25.15.154]) by h3cspam02-ex.h3c.com with ESMTP id 4699GLTr005458; Tue, 9 Jul 2024 17:16:21 +0800 (GMT-8) (envelope-from zhang.chunA@h3c.com) Received: from DAG6EX09-BJD.srv.huawei-3com.com (unknown [10.153.34.11]) by mail.maildlp.com (Postfix) with ESMTP id 64CB22302CD1; Tue, 9 Jul 2024 17:20:36 +0800 (CST) Received: from localhost.localdomain.com (10.99.206.13) by DAG6EX09-BJD.srv.huawei-3com.com (10.153.34.11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.2.1258.27; Tue, 9 Jul 2024 17:16:23 +0800 From: zhangchun To: CC: , , , , , , zhangchun Subject: [PATCH] =?utf-8?q?mm=3A_Give_kmap=5Flock_before_call_flush=5Ftlb=5F?= =?utf-8?q?kernel=5Frang=EF=BC=8Cavoid_kmap=5Fhigh_deadlock=2E?= Date: Tue, 9 Jul 2024 17:17:38 +0800 Message-ID: <1720516658-50434-1-git-send-email-zhang.chuna@h3c.com> X-Mailer: git-send-email 1.8.3.1 MIME-Version: 1.0 X-Originating-IP: [10.99.206.13] X-ClientProxiedBy: BJSMTP01-EX.srv.huawei-3com.com (10.63.20.132) To DAG6EX09-BJD.srv.huawei-3com.com (10.153.34.11) X-DNSRBL: X-MAIL: h3cspam02-ex.h3c.com 4699GLTr005458 X-Rspamd-Server: rspam03 X-Rspam-User: X-Rspamd-Queue-Id: 23C4B1C000C X-Stat-Signature: y5gdbmukkpnwgkymk191wr57nuiwzc3w X-HE-Tag: 1720516634-343577 X-HE-Meta: U2FsdGVkX1/dyWKVhBkz6AF8UqperPYY0J68KAmP7czLKfX13gMuYoAj8AOqk2WYf7EH8ihzFTfHj1KIUscv9KR8BoryMgiIxcJA3KDYXFgyUuoA0bgq/JB8Z4c0+xBzHEvvQ9E1yuCTlMRGCX0sQtUpH1lYSzKQeM/uF/y/PozycVLcA4ZqbkEDsDxccjs6s3ihZeIwqSV1AFTXLrlfkty6xHHxEvoG8f1QfxI+iFVR7hSsSidfusTsn2xhZsMo5Xqr2GRm5vAk9ltLoYQBrSqZ3Ce8u1D4yqmSJLp+0EXXKoEpSE2YJflyUsE06NpjmvV+VC7nKYvs49lf3vYgHYunL2U9ndpcw8Avkn1VL0MnYHecltvhelmzVVgrSFjUBxMsoo3TfpQLX3MH5FlOX8evNmklUmdPfZ87kk1Z9ioLSPggDbUTgQfGmOZia1qbRsoykdFicKCvh7BEDNe0S382hWV2V5kBtdxCNZJwgu18kvvBh9heLbS0/sfC2Z2Vstd83agHZ1jSjLfvRv+02skrwr2fKuFgnsHVBweX0F84q16jpGYNv6+t8mRCiXVaKzpLkY0uewvSM3LgndRtkJsEfLV3php+rFdgW4qtGy7MQiFj57xyqKXmEC2MlzuAXrxeb9rMsAHKOjqvOfdu59psNXbb95Znohf8vaTW5FdsC+I6VsODqH4uOMSK73Inkp4xK35gbrOonulWqkttUzKyKEWLWW4R/kJTB9gCe8SW2FB7wNCFk80O8PqTpeq5SC87mVhwE5c7CdgmcHM5d4b7b3V/KRbkriu8rs/Hl1GM4DrnD6Qq2btbvwc/+G0MC0krX3KCqjAPJbCv3dy0Z8ZeSE3nL6X4ADZy3dU0qRo7HqIkpXAqFKudgkkhuo/ANaCSIVhn1s1DbLaBf8MTLCsqNFN7HYysix65u28vYxYwWJBcyB9A+umV3nq0bcZH0UKCH1tjTJbO8CXUWgv YdOlmprN SOoXg9cZZL4usGk3iR0awfJdlUla+QZ9nGafjIQcSVEU4JGxOjpKKTa4URNOrTclRIOzaYH03dj+2+4W1oTWCz/JpgLQwzLNUcGO2b/2d4w36RmDudB8EIlr0/H6R76sfane0xVJ/XwOJ2SKqYNojo4NKeN6J5iU4ULj3IQexOYO4KYVpngBYtZkHVL07Sfttu9PVUlg/6Yd8bjhCuza321pzQmNG7nEt2XqVo8xmAMj6LuuhI4bZlDLMxyuQSKjSeVbu7hz2iHyBZqOD4hsoQO58M8wzZ91G7miI 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: Use kmap_high and kmap_XXX or kumap_xxx among differt cores at the same time may cause deadlock. The issue is like this: CPU 0: CPU 1: kmap_high(){ kmap_xxx() { ... irq_disable(); spin_lock(&kmap_lock) ... map_new_virtual ... flush_all_zero_pkmaps flush_tlb_kernel_range /* CPU0 holds the kmap_lock */ smp_call_function_many spin_lock(&kmap_lock) ... .... spin_unlock(&kmap_lock) ... CPU 0 holds the kmap_lock, waiting for CPU 1 respond to IPI. But CPU 1 has disabled irqs, waiting for kmap_lock, cannot answer the IPI. Fix this by releasing kmap_lock before call flush_tlb_kernel_range, avoid kmap_lock deadlock. Fixes: 3297e760776a ("highmem: atomic highmem kmap page pinning") Signed-off-by: zhangchun Co-developed-by: zhangzhansheng Signed-off-by: zhangzhansheng 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 = 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)