From patchwork Tue Jul 2 06:56:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: zhangchun X-Patchwork-Id: 13719029 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 E610BC3064D for ; Tue, 2 Jul 2024 06:55:59 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2DB216B007B; Tue, 2 Jul 2024 02:55:59 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 28A936B0089; Tue, 2 Jul 2024 02:55:59 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 152C46B0096; Tue, 2 Jul 2024 02:55:59 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id EC0526B007B for ; Tue, 2 Jul 2024 02:55:58 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 93437121A79 for ; Tue, 2 Jul 2024 06:55:58 +0000 (UTC) X-FDA: 82293902796.28.ACE951A Received: from h3cspam02-ex.h3c.com (smtp.h3c.com [60.191.123.50]) by imf28.hostedemail.com (Postfix) with ESMTP id BC671C0012 for ; Tue, 2 Jul 2024 06:55:55 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=none; spf=pass (imf28.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=1719903345; 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=fEx/o3byeO9tYtE91wvbJwNxd1Rfmzfro2VNp5ASqOQ=; b=8E3tolIwr4OubMxZZL1nodL1Dw5/ONxIL358DWuLVS/vXmoTgutTuUoPt6MawK+EZ3PiPQ +ucbIklQb5vX+TM9ldApuByRYBPQ0Gvi3hoWIH5DxQtDhG5zr6eii9TmmFrLmnFbXtekTA dQWeNTQIvDxFM6pjfJ5uz4Y+PMzZjcU= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=none; spf=pass (imf28.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=1719903345; a=rsa-sha256; cv=none; b=LNWQy6mpYJm5w4FPO/JTgxshW/E+dttwHeS3Z1rXiV54XKvrKsSeZp511JzWhf8Fwiae0T NzYtFA4VTEeGprZMuaX8/RS4X4Rjs7iuV4RWJE6GIORgxac2K6mHoOxO52gxIyjzRflFq6 T/0BqCTI9RHJ8a+yPSGl7b3qCVpR6Ms= Received: from mail.maildlp.com ([172.25.15.154]) by h3cspam02-ex.h3c.com with ESMTP id 4626smGA034206; Tue, 2 Jul 2024 14:54:48 +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 75DE92004BB3; Tue, 2 Jul 2024 14:58:53 +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, 2 Jul 2024 14:54:50 +0800 From: zhangchun To: CC: , , , , , , zhangchun Subject: [PATCH] mm: fix kmap_high deadlock V2 Date: Tue, 2 Jul 2024 14:56:09 +0800 Message-ID: <1719903369-35385-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 4626smGA034206 X-Rspamd-Server: rspam11 X-Rspamd-Queue-Id: BC671C0012 X-Stat-Signature: s4cx7roonrttnzsdoaa9tq9ndwpx8uc1 X-Rspam-User: X-HE-Tag: 1719903355-941726 X-HE-Meta: U2FsdGVkX1/T+hjGc60YhTGjveAJ8Jj3LGzO6omlxSNGdOMKD7AXWCmQ5/m3e+ez17Wr4z2X8R9tKDF7Sa5J3MSQeicZAhYdSB+cGGhtzL2lB26KOl83RfBgi0WHmJRZfSexVPP0K+W8W3Zu9iFU4YsYFvYP6GVGOSMG0d7R0mvTf5w5UlOy8IZpBb28GsK/bh5iQn42NInGweF4epBaVtzqtgAktJYuWiRBcax4hjhANwQQE++icjioe3oRNt6ZVtgTZOkq8EdLO50XDSGpWB1pb2lbcQsWnKinK/hhAIJGlX3bAwRc4BrjZ+nw+Lq727+xL2WkS7Sup7PN2CME1pqg1h19R19u25M9ob6osP/rhI7CMdqDaLsRjGI7pcGLcEl+DKhX2+v7jhpCt9PqFHaIbzyYqgJ8DsGpq06mEG5OJLSgO4p1g5rEIPak6q/KUtTbPVA+L+LaeQ/uHCxkxEVdWkOud6hAbEdd83Ohae38uRp7zDwIVjVrizT2lSil9K1RIuZ53xKG9fl9PqjvqluHaLCvbv8HmwcMO422Q0MkSbO0+hE0q2buwuXipmoy5hqDt0QciohX7zovGDpqyo3q+efidrmQw388F/2TqTDnT4yqGwPU2KEeNVNpnMNQ7ybVvP2s0u5DdSN0fUxc88v7haifQriuOs4EG9BRTdG6HUKYr4UBByWqycGQxOWs1eS3q3lDdR4WUsE0Rjc/ydC9xkS5D3wJT4xLlWr+22c4wJNB3rVUXGyQQFM+OqBefZVkdovUAdgvr75dYsZg9+68JKJvLDMvPeuhHGNjEkaqXSPLGphk4NvXSl0+CDbM2lQ8cxnsWODJEPZ+JhHndMKred7gc846I+ouudCjf7dUOT1e2IPit7xhJC8IrITf4P2+YB0bdEyR7BAX0a6Pb2N3gvpBSTd4ispvpuVWX/3Ahad+pHpJkgmbVojJzm1Svi9AApj1YjNrpCTePYg t7qEd4DI JqLFySgnPJewYPFM68ZXBhKrdf4YYa00Atf8BKQiB999jGji4bmi0i61STsAQyQQQ9Z/WaPYfrMIPJOMwGII+sum/CkeEtZbr6BBX1RjTrPcuMWiob+F62s7XsC31ZWw7j14B6Qwy88VgLxCjeP/QE77lbF6oZULwawYzXySNLYV/ypBX7XzxmnkbXc3GsKcMrUrEo3ttaNludgM9gKOdwHOYi65Q+AnPkb4o 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: 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(-) 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)