linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Zhangchun <zhang.chunA@h3c.com>
To: "akpm@linux-foundation.org" <akpm@linux-foundation.org>,
	"linux-mm@kvack.org" <linux-mm@kvack.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Cc: "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	Jiaoxupo <jiaoxupo@h3c.com>, Bailin <berlin@h3c.com>,
	Zhangzhansheng <zhang.zhansheng@h3c.com>,
	"linux-mm@kvack.org" <linux-mm@kvack.org>,
	wangyu <wang.yuI@h3c.com>,
	"shaohaojize@126.com" <shaohaojize@126.com>,
	Zhangzhengming <zhang.zhengming@h3c.com>
Subject: [PATCH] mm: fix kmap_high deadlock V2
Date: Tue, 2 Jul 2024 04:26:59 +0000	[thread overview]
Message-ID: <7caa255fa5fe4e8e9c6a05084a1faf72@h3c.com> (raw)


From: "zhang.chun" <zhang.chuna@h3c.com>

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 <zhang.chuna@h3c.com>

Reviewed-by: zhangzhengming <zhang.zhengming@h3c.com>
---
 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)
--
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!

             reply	other threads:[~2024-07-02  4:27 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-02  4:26 Zhangchun [this message]
2024-07-02  5:02 ` thington
2024-07-02  6:56 zhangchun
2024-07-02 11:37 ` Markus Elfring

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=7caa255fa5fe4e8e9c6a05084a1faf72@h3c.com \
    --to=zhang.chuna@h3c.com \
    --cc=akpm@linux-foundation.org \
    --cc=berlin@h3c.com \
    --cc=jiaoxupo@h3c.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=shaohaojize@126.com \
    --cc=wang.yuI@h3c.com \
    --cc=zhang.zhansheng@h3c.com \
    --cc=zhang.zhengming@h3c.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox