From patchwork Sun Jul 18 04:30:27 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 12384139 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,URIBL_BLOCKED,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 4F458C636CA for ; Sun, 18 Jul 2021 04:30:59 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id A1CDD61166 for ; Sun, 18 Jul 2021 04:30:58 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A1CDD61166 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 4675C8D00F5; Sun, 18 Jul 2021 00:30:58 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 43D1C8D00EC; Sun, 18 Jul 2021 00:30:58 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2DCD38D00F5; Sun, 18 Jul 2021 00:30:58 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0135.hostedemail.com [216.40.44.135]) by kanga.kvack.org (Postfix) with ESMTP id 09BC18D00EC for ; Sun, 18 Jul 2021 00:30:58 -0400 (EDT) Received: from smtpin16.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 9B810181AEF15 for ; Sun, 18 Jul 2021 04:30:56 +0000 (UTC) X-FDA: 78374433312.16.3E9EC68 Received: from mail-pg1-f174.google.com (mail-pg1-f174.google.com [209.85.215.174]) by imf05.hostedemail.com (Postfix) with ESMTP id 45866500F98E for ; Sun, 18 Jul 2021 04:30:56 +0000 (UTC) Received: by mail-pg1-f174.google.com with SMTP id d12so15146675pgd.9 for ; Sat, 17 Jul 2021 21:30:56 -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:in-reply-to:references :mime-version:content-transfer-encoding; bh=1D+eAaGntlq2QOmwIyhlRVot25FA5YhpCPiOnZm25IM=; b=Qyx3IP0s0+OyV2QXjMtUZosvefFPI5SxuXcZvuw12DQIchNsKYaA7Y324lin3Q3w+3 /fy+w58NKJSaNdtz0J8baLNfUjScDvyq6RhhknyE4l6DsBxPqvIBVyh2+kl9yyEWNQyK 69m/ABFt3Daq93p3dSOE9Om7KBMDekB3UgWd9g39jK09/au7qsI+027GxHv5fwJakXmo IwS/sSdn1T11/ANYZz6qEWJ5Tw7dx6StcjaunhM3BmlEmNezYL/AhoB52qWYxNjv8LjF 6CIyS7SofjWAZ97G2R4axMD/JQsXYbw9V4bhF5PaWfhLKn3E6stvaxHtiU8nw2yWEiwg 0qow== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=1D+eAaGntlq2QOmwIyhlRVot25FA5YhpCPiOnZm25IM=; b=s4VQ2Jk1Xwde7fPpRe+Aj5J7DgMZzuK3vIf9/rJAhK221QzOoYpNY+SI5ZVm5trvqA wS0X4nzVNychuG0aGN0qmkxrOhDPbqKE99svaur9no3lxG6FMjLZR+FXP/M8iNXF+xGX 7OFTKQyjpTI+bC9GTlL04ToreYEZqDFxUPnQh3hdlVbi2JXjzWdjIaIOP6/P/te+l5wB XBMwUGFYg/KPBs7efwvRAJtQa9DPIy7AGun40KTnhk0GXNwF28Xef84Ryt6kfV9rPqeZ r7To5MDT34aHDW+O4gznLKmn4ZLjX079wXQdd96X+Zqn//9nlsAQ+lu8pfS+K/cdRKiW SXPw== X-Gm-Message-State: AOAM533U8nMTRNO2bwvN+XIqwSYy0WpxeHg+IZtLvRIX4gRRzB09Svvl uO6gkNN4dLPX3BETSPAUA+XhNg== X-Google-Smtp-Source: ABdhPJxCY5XIl075+j64oirxKlFOza8NBbgGhZNYT4TQ9zNONZTLttfahLdGHJ0Piy+bp6+IkUEaLQ== X-Received: by 2002:a63:4607:: with SMTP id t7mr18238045pga.31.1626582655459; Sat, 17 Jul 2021 21:30:55 -0700 (PDT) Received: from C02DW0BEMD6R.bytedance.net ([139.177.225.253]) by smtp.gmail.com with ESMTPSA id a22sm16263217pgv.84.2021.07.17.21.30.51 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sat, 17 Jul 2021 21:30:55 -0700 (PDT) From: Qi Zheng To: akpm@linux-foundation.org, tglx@linutronix.de, hannes@cmpxchg.org, mhocko@kernel.org, vdavydov.dev@gmail.com Cc: linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, songmuchun@bytedance.com, Qi Zheng Subject: [PATCH 1/7] mm: fix the deadlock in finish_fault() Date: Sun, 18 Jul 2021 12:30:27 +0800 Message-Id: <20210718043034.76431-2-zhengqi.arch@bytedance.com> X-Mailer: git-send-email 2.24.3 (Apple Git-128) In-Reply-To: <20210718043034.76431-1-zhengqi.arch@bytedance.com> References: <20210718043034.76431-1-zhengqi.arch@bytedance.com> MIME-Version: 1.0 Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=bytedance-com.20150623.gappssmtp.com header.s=20150623 header.b=Qyx3IP0s; spf=pass (imf05.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.215.174 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com; dmarc=pass (policy=none) header.from=bytedance.com X-Rspamd-Server: rspam02 X-Stat-Signature: 3qukzqkx8jfxwxm47dsmhgbun8cibetm X-Rspamd-Queue-Id: 45866500F98E X-HE-Tag: 1626582656-819891 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 a deadlock bug by pre-allocating the pte page table outside of the page lock, the commit f9ce0be71d1f(mm: Cleanup faultaround and finish_fault() codepaths) rework the relevant code but ignore this race, fix it. Fixes: f9ce0be71d1f(mm: Cleanup faultaround and finish_fault() codepaths) Signed-off-by: Qi Zheng Acked-by: Kirill A. Shutemov --- mm/memory.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) 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() */