From patchwork Wed Jul 21 07:48:49 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 12390969 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CB541C636CA for ; Wed, 21 Jul 2021 13:45:35 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 5CDDC60FF1 for ; Wed, 21 Jul 2021 13:45:35 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5CDDC60FF1 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=bytedance.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 079376B0073; Wed, 21 Jul 2021 09:45:35 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 029BC6B0078; Wed, 21 Jul 2021 09:45:34 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E34026B007B; Wed, 21 Jul 2021 09:45:34 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0236.hostedemail.com [216.40.44.236]) by kanga.kvack.org (Postfix) with ESMTP id C83976B0073 for ; Wed, 21 Jul 2021 09:45:34 -0400 (EDT) Received: from forelay.prod.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by fograve01.hostedemail.com (Postfix) with ESMTP id BDB481854CE39 for ; Wed, 21 Jul 2021 07:49:37 +0000 (UTC) Received: from smtpin38.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 1107B23E55 for ; Wed, 21 Jul 2021 07:49:37 +0000 (UTC) X-FDA: 78385820394.38.0CA3584 Received: from mail-pj1-f51.google.com (mail-pj1-f51.google.com [209.85.216.51]) by imf02.hostedemail.com (Postfix) with ESMTP id 461BB7002A4D for ; Wed, 21 Jul 2021 07:49:35 +0000 (UTC) Received: by mail-pj1-f51.google.com with SMTP id d9-20020a17090ae289b0290172f971883bso3519980pjz.1 for ; Wed, 21 Jul 2021 00:49:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=5SiPzH0oQvD2cNeDSmkgLcQ+i377uBDVUSzyiSv2rLY=; b=qfZqotzquTXe7VSUITa6ZJmoYJKz5MciCfcteq60Ba+A+X0MqWUyOHtIOfjBfam0B6 3QWsfNofdh4IjaJNL5SUblYuQuGncudv8j1MvMsL1DabZlxjw78MeM/XxOqaGz/H1Fft n3JllH2c3ZnZI3L2e+b4ypu9jIdBhHitxhF/mxsjQVnxiUNAYqxx3/1dXk8uMh0yP8wy rLKkG8C6vxdmUZWCB8XUPI0so0ra6APk1hFy1X8dKU5Nyh4K1xrbNqSoraDVN+Dlm67m ZxhvR8YA0eXOZLEtH/iUGwcRtvupZCTc+4rlp94jQbhXdkmob9kOStBHvvAdJoJPA30B vVlg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=5SiPzH0oQvD2cNeDSmkgLcQ+i377uBDVUSzyiSv2rLY=; b=aCP/RpVn8bmxD6QsEG98weZOIzbGjXGWHyiAz91NLaLlo/O4swbWSDzZqTjI95X83X d6WGHVhP4L0qbuH3EQDnktqv9dRDm+YTAJipQwsIkqrHAJf04anj9/hR8/9i6i+vqoSe qhkyL5clEt1/d0/OVQGYg3gySdbFMO+beimn9XS2b0xVadQSPuoPMhoYXffkKkocRdY0 R8SHutmakuVpaj8rvc/s1CyCsI0ciHqiL4YNokqXRASWAZ5BDeFTF8lJcjC5j4A9o2Iw WTABO20bmW9YwsSCBcFYwwkksyZRu+MNp0+++uArRnOiICiBzPbcpM/MmorxFC3cX6tC eRTw== X-Gm-Message-State: AOAM531H4We57CfznKj8qaNGYRU84/eTGJ1oYMvoV+PJtJgzu8gAqiC8 7oSpwGLtGaf2yoEU8plsNvHKkw== X-Google-Smtp-Source: ABdhPJwVcTa6ayV2xNFTtcBA4UI1/B6NB25ALk4yhn4ZuTduJWQZ0/ET+0UopsBFy2MS3zrj2pWlvA== X-Received: by 2002:a17:90a:fa88:: with SMTP id cu8mr34258238pjb.198.1626853773904; Wed, 21 Jul 2021 00:49:33 -0700 (PDT) Received: from C02DW0BEMD6R.bytedance.net ([139.177.225.250]) by smtp.gmail.com with ESMTPSA id c83sm791163pfb.164.2021.07.21.00.49.26 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 21 Jul 2021 00:49:33 -0700 (PDT) From: Qi Zheng To: akpm@linux-foundation.org, tglx@linutronix.de, hannes@cmpxchg.org, mhocko@kernel.org, vdavydov.dev@gmail.com, kirill.shutemov@linux.intel.com Cc: linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, songmuchun@bytedance.com, Qi Zheng , stable@vger.kernel.org Subject: [PATCH v2] mm: fix the deadlock in finish_fault() Date: Wed, 21 Jul 2021 15:48:49 +0800 Message-Id: <20210721074849.57004-1-zhengqi.arch@bytedance.com> X-Mailer: git-send-email 2.24.3 (Apple Git-128) MIME-Version: 1.0 Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=bytedance-com.20150623.gappssmtp.com header.s=20150623 header.b=qfZqotzq; spf=pass (imf02.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.216.51 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com; dmarc=pass (policy=none) header.from=bytedance.com X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 461BB7002A4D X-Stat-Signature: 1frj8y5xthjpmk7d6pr66h64wrczuk87 X-HE-Tag: 1626853775-960172 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: The commit 63f3655f9501 ("mm, memcg: fix reclaim deadlock with writeback") fix the following ABBA deadlock by pre-allocating the pte page table without holding the page lock. lock_page(A) SetPageWriteback(A) unlock_page(A) lock_page(B) lock_page(B) pte_alloc_one shrink_page_list wait_on_page_writeback(A) SetPageWriteback(B) unlock_page(B) # flush A, B to clear the writeback The commit f9ce0be71d1f ("mm: Cleanup faultaround and finish_fault() codepaths") rework the relevant code but ignore this race. This will cause the deadlock above to appear again, so fix it. Fixes: f9ce0be71d1f ("mm: Cleanup faultaround and finish_fault() codepaths") Signed-off-by: Qi Zheng Acked-by: Kirill A. Shutemov CC: --- Changelog in v1 -> v2: - Update commit log mm/memory.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) -- 2.11.0 diff --git a/mm/memory.c b/mm/memory.c index db86558791f1..94a17a9a48ab 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -4026,8 +4026,17 @@ vm_fault_t finish_fault(struct vm_fault *vmf) return ret; } - if (unlikely(pte_alloc(vma->vm_mm, vmf->pmd))) + if (vmf->prealloc_pte) { + vmf->ptl = pmd_lock(vma->vm_mm, vmf->pmd); + if (likely(pmd_none(*vmf->pmd))) { + mm_inc_nr_ptes(vma->vm_mm); + pmd_populate(vma->vm_mm, vmf->pmd, vmf->prealloc_pte); + vmf->prealloc_pte = NULL; + } + spin_unlock(vmf->ptl); + } else if (unlikely(pte_alloc(vma->vm_mm, vmf->pmd))) { return VM_FAULT_OOM; + } } /* See comment in handle_pte_fault() */