From patchwork Wed Jul 7 20:06:17 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hugh Dickins X-Patchwork-Id: 12364009 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=-23.6 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_IN_DEF_DKIM_WL 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 1317CC07E95 for ; Wed, 7 Jul 2021 20:06:39 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 8A25561CC2 for ; Wed, 7 Jul 2021 20:06:38 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8A25561CC2 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 0CD9A6B0011; Wed, 7 Jul 2021 16:06:38 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 07DDB6B005D; Wed, 7 Jul 2021 16:06:38 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E38CE6B006C; Wed, 7 Jul 2021 16:06:37 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0122.hostedemail.com [216.40.44.122]) by kanga.kvack.org (Postfix) with ESMTP id B60B76B0011 for ; Wed, 7 Jul 2021 16:06:37 -0400 (EDT) Received: from smtpin37.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 1BEC623116 for ; Wed, 7 Jul 2021 20:06:37 +0000 (UTC) X-FDA: 78336874434.37.086CA16 Received: from mail-oo1-f50.google.com (mail-oo1-f50.google.com [209.85.161.50]) by imf18.hostedemail.com (Postfix) with ESMTP id B2362400208B for ; Wed, 7 Jul 2021 20:06:36 +0000 (UTC) Received: by mail-oo1-f50.google.com with SMTP id h8-20020a4ad0080000b029025b08dc951fso348045oor.9 for ; Wed, 07 Jul 2021 13:06:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:message-id:mime-version; bh=6qeso0vnhBwFs3iCYpWzxPK0i6KQqKKfr8ULWEkbKXE=; b=E4XHqX1GTIF3abK36LazO2Q/rAwhiw0uDpwxHRBjNPI0ptyVYh43DYr17icgNSzNtB 0/l/8Pqy8JjsnqgavgUC69qzF0JNtN+UGO1Hb1cDGMQOkF2hSSx6+RbyIHdblu2e26dB 3ObW5x1VTMLukGemHCj8VN/+JPYeOwwkBEnNJZKDlQPpkB+2g4uHfB+yRj19WmejuxrQ C1NyxojgX1ducwOiw4uUespqSgx8+tGJSDH8u5fhcG1l/EcTS3AudTXMYxx3bgpMmFZq WlTEGxCDfxB9UXGyu0goYz33hEhKhJYCWR04ludzqgYKCiID6ohesXIVBi22LvODtxZU 6woQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version; bh=6qeso0vnhBwFs3iCYpWzxPK0i6KQqKKfr8ULWEkbKXE=; b=CLJjaczonZTjxmUQeUN2++J6KCo8jswrgX6ER7PUlecmMmFmEmprEYDHheCpkNxw9f 5O6aWXxRYMEu2QBtvXW9pQQrK5GkZhxuB+whYNJbLXA2f28FYFwaPzRelnlGNl5wVRpw Z0Eoh8IEhkOP0qdqfvw1RGzdbAtDCGqWANbSPCBnINK+GhwT4Ak3zp/4t+ALeLatAOf0 I76HaAERt5kjmBe7SFuQYtofu4AaowJBJIF1SNKNeWHfpU7ewWTTbpxhqZQhnw4y6Xn1 jdBEVzh1mVopsVX7jiFXgsdp7/NJl6OPWSxAKORQNQlVQBBMP/9dXWKy58NvGBHAKnih ZJZQ== X-Gm-Message-State: AOAM53098S/9vKEJI5p8HuW+N8A6QJH+gcqlu85EL6kWwimIIaXrR3rm HIVAXcB47jezDLhQq1zBJkPZEA== X-Google-Smtp-Source: ABdhPJyi4Lm5LdstNhafbuakxVCafg4zCdocLCQA6UnRmid6Qr2q0/4YqFwgBUmok/SVzq5TKaqulg== X-Received: by 2002:a4a:9e02:: with SMTP id t2mr19518865ook.73.1625688395773; Wed, 07 Jul 2021 13:06:35 -0700 (PDT) Received: from ripple.attlocal.net (172-10-233-147.lightspeed.sntcca.sbcglobal.net. [172.10.233.147]) by smtp.gmail.com with ESMTPSA id x29sm3635856ooj.10.2021.07.07.13.06.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Jul 2021 13:06:35 -0700 (PDT) Date: Wed, 7 Jul 2021 13:06:17 -0700 (PDT) From: Hugh Dickins X-X-Sender: hugh@ripple.anvils To: Andrew Morton cc: Hugh Dickins , Alistair Popple , Jason Gunthorpe , Ralph Campbell , Christoph Hellwig , Yang Shi , "Kirill A. Shutemov" , Shakeel Butt , linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 1/4] mm/rmap: fix comments left over from recent changes Message-ID: <563ce5b2-7a44-5b4d-1dfd-59a0e65932a9@google.com> MIME-Version: 1.0 X-Rspam-User: nil Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=google.com header.s=20161025 header.b=E4XHqX1G; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf18.hostedemail.com: domain of hughd@google.com designates 209.85.161.50 as permitted sender) smtp.mailfrom=hughd@google.com X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: B2362400208B X-Stat-Signature: 3eu5geke74gq7tfuhpzcqks8ksod9pj7 X-HE-Tag: 1625688396-346393 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: Parallel developments in mm/rmap.c have left behind some out-of-date comments: try_to_migrate_one() also accepts TTU_SYNC (already commented in try_to_migrate() itself), and try_to_migrate() returns nothing at all. TTU_SPLIT_FREEZE has just been deleted, so reword the comment about it in mm/huge_memory.c; and TTU_IGNORE_ACCESS was removed in 5.11, so delete the "recently referenced" comment from try_to_unmap_one() (once upon a time the comment was near the removed codeblock, but they drifted apart). Signed-off-by: Hugh Dickins Reviewed-by: Shakeel Butt Reviewed-by: Alistair Popple --- mm/huge_memory.c | 2 +- mm/rmap.c | 7 +------ 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/mm/huge_memory.c b/mm/huge_memory.c index 8b731d53e9f4..afff3ac87067 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -2331,7 +2331,7 @@ static void remap_page(struct page *page, unsigned int nr) { int i; - /* If TTU_SPLIT_FREEZE is ever extended to file, remove this check */ + /* If unmap_page() uses try_to_migrate() on file, remove this check */ if (!PageAnon(page)) return; if (PageTransHuge(page)) { diff --git a/mm/rmap.c b/mm/rmap.c index 37c24672125c..746013e282c3 100644 --- a/mm/rmap.c +++ b/mm/rmap.c @@ -1439,8 +1439,6 @@ static bool try_to_unmap_one(struct page *page, struct vm_area_struct *vma, while (page_vma_mapped_walk(&pvmw)) { /* * If the page is mlock()d, we cannot swap it out. - * If it's recently referenced (perhaps page_referenced - * skipped over this mm) then we should reactivate it. */ if (!(flags & TTU_IGNORE_MLOCK)) { if (vma->vm_flags & VM_LOCKED) { @@ -1687,8 +1685,7 @@ void try_to_unmap(struct page *page, enum ttu_flags flags) * @arg: enum ttu_flags will be passed to this argument. * * If TTU_SPLIT_HUGE_PMD is specified any PMD mappings will be split into PTEs - * containing migration entries. This and TTU_RMAP_LOCKED are the only supported - * flags. + * containing migration entries. */ static bool try_to_migrate_one(struct page *page, struct vm_area_struct *vma, unsigned long address, void *arg) @@ -1928,8 +1925,6 @@ static bool try_to_migrate_one(struct page *page, struct vm_area_struct *vma, * * Tries to remove all the page table entries which are mapping this page and * replace them with special swap entries. Caller must hold the page lock. - * - * If is successful, return true. Otherwise, false. */ void try_to_migrate(struct page *page, enum ttu_flags flags) { From patchwork Wed Jul 7 20:08:53 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hugh Dickins X-Patchwork-Id: 12364019 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=-23.6 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_IN_DEF_DKIM_WL autolearn=unavailable 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 7B4C5C07E95 for ; Wed, 7 Jul 2021 20:39:37 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id E367E61C5F for ; Wed, 7 Jul 2021 20:39:36 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E367E61C5F Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 977816B0011; Wed, 7 Jul 2021 16:39:36 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 94E236B005D; Wed, 7 Jul 2021 16:39:36 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7EEFA6B006C; Wed, 7 Jul 2021 16:39:36 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0045.hostedemail.com [216.40.44.45]) by kanga.kvack.org (Postfix) with ESMTP id 5D6726B0011 for ; Wed, 7 Jul 2021 16:39:36 -0400 (EDT) Received: from smtpin28.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id AB5A227706 for ; Wed, 7 Jul 2021 20:39:35 +0000 (UTC) X-FDA: 78336957510.28.584C32B Received: from mail-oi1-f181.google.com (mail-oi1-f181.google.com [209.85.167.181]) by imf17.hostedemail.com (Postfix) with ESMTP id 49DD6F001FB7 for ; Wed, 7 Jul 2021 20:39:35 +0000 (UTC) Received: by mail-oi1-f181.google.com with SMTP id t3so4960813oic.5 for ; Wed, 07 Jul 2021 13:39:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:in-reply-to:message-id:references :mime-version; bh=AEUjbJEHgjwZH84O8/yOmL96IkupdJt703GIG/Lw/Sw=; b=aIfEXDg7X8c6i6RMt2XjPCogxnvkLnZWUZiLZ79qAP2eZuzQiThqTe/Wt23LFK/d7N k5hF8xQNkmVcxNu3wCGxN8L3VJungjMW9tWj0G+iUEcY6hZlHdjRSKfQzIIf+z+y9Jzh QNficFcQho0jB2dIVnAssiHtmbwVSgh8cAQI56fRqelW/syOtyiwPFHRwF9M86BFkIFW QvQXm/BAjmg/ClC5HPMT/QsmFc1D5/6INGIn9IUq4Yq2yLZOr+9X116mQy+W8Hzar+qh QieIJ96JHJlqH6Wnxd7BDUWPkIvipTfS9+3awv6YTUQ438T23gxjXb/F2y3VlzRa5z/j ZgGQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:in-reply-to:message-id :references:mime-version; bh=AEUjbJEHgjwZH84O8/yOmL96IkupdJt703GIG/Lw/Sw=; b=aHZzxDBgEmmHijUwftQfpFwYXkkLQJv/4cqMog7tKgoK/sWUlIxwMwtmUwnSKfNMpp wJHzu4rg/kPOo11FEdOOC/3u2NjiBgYBllF3G0LjJH0gaNQqHy/KJdR131BpOjDwckgL rWxer2Dj9hYJEYOshSy0sXroFXSU0onn6ZVOzHGbpvws+SFnOpoZY15BLzGtNkSuDEgx F4GU6Z55r7IXtuRJFxu40pIT31rr9M0TAubUtb/42qbAPdK/QSa5aHuPJfatiiY3yeV2 m5afF9ywUInb2U3OfP1oknP9guGJ8cmio/5J4XVQJ2JjUmm8fM7rn/ixPHYyshk4LFga Uc0A== X-Gm-Message-State: AOAM530BKpktnvV/PvpsL+aIERILmvSPKObJdtg+zG0JK4MgQbXb/Jzt VGIcLKl4Sp5WGTtr0itXT/apxYBdAno1dw== X-Google-Smtp-Source: ABdhPJwtImQxt1QzEcdZdsVyVe8aD+gMiqiWoksjK7o9JOc9vBTzXLdVlrO6UFB4z710wRyFTr0zXQ== X-Received: by 2002:aca:db44:: with SMTP id s65mr11399367oig.139.1625688536945; Wed, 07 Jul 2021 13:08:56 -0700 (PDT) Received: from ripple.attlocal.net (172-10-233-147.lightspeed.sntcca.sbcglobal.net. [172.10.233.147]) by smtp.gmail.com with ESMTPSA id 25sm3729500oir.58.2021.07.07.13.08.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Jul 2021 13:08:56 -0700 (PDT) Date: Wed, 7 Jul 2021 13:08:53 -0700 (PDT) From: Hugh Dickins X-X-Sender: hugh@ripple.anvils To: Andrew Morton cc: Hugh Dickins , Alistair Popple , Jason Gunthorpe , Ralph Campbell , Christoph Hellwig , Yang Shi , "Kirill A. Shutemov" , Shakeel Butt , linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 2/4] mm/rmap: fix old bug: munlocking THP missed other mlocks In-Reply-To: <563ce5b2-7a44-5b4d-1dfd-59a0e65932a9@google.com> Message-ID: References: <563ce5b2-7a44-5b4d-1dfd-59a0e65932a9@google.com> MIME-Version: 1.0 Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=google.com header.s=20161025 header.b=aIfEXDg7; spf=pass (imf17.hostedemail.com: domain of hughd@google.com designates 209.85.167.181 as permitted sender) smtp.mailfrom=hughd@google.com; dmarc=pass (policy=reject) header.from=google.com X-Rspamd-Server: rspam05 X-Stat-Signature: mzz7d8hrtzym5w1crkd7g5xjaimo33ie X-Rspamd-Queue-Id: 49DD6F001FB7 X-Rspam-User: nil X-HE-Tag: 1625690375-575199 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 kernel recovers in due course from missing Mlocked pages: but there was no point in calling page_mlock() (formerly known as try_to_munlock()) on a THP, because nothing got done even when it was found to be mapped in another VM_LOCKED vma. It's true that we need to be careful: Mlocked accounting of pte-mapped THPs is too difficult (so consistently avoided); but Mlocked accounting of only-pmd-mapped THPs is supposed to work, even when multiple mappings are mlocked and munlocked or munmapped. Refine the tests. There is already a VM_BUG_ON_PAGE(PageDoubleMap) in page_mlock(), so page_mlock_one() does not even have to worry about that complication. (I said the kernel recovers: but would page reclaim be likely to split THP before rediscovering that it's VM_LOCKED? I've not followed that up.) Fixes: 9a73f61bdb8a ("thp, mlock: do not mlock PTE-mapped file huge pages") Signed-off-by: Hugh Dickins Reviewed-by: Shakeel Butt Signed-off-by: Hugh Dickins Acked-by: Kirill A. Shutemov --- mm/rmap.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/mm/rmap.c b/mm/rmap.c index 746013e282c3..0e83c3be8568 100644 --- a/mm/rmap.c +++ b/mm/rmap.c @@ -1442,8 +1442,9 @@ static bool try_to_unmap_one(struct page *page, struct vm_area_struct *vma, */ if (!(flags & TTU_IGNORE_MLOCK)) { if (vma->vm_flags & VM_LOCKED) { - /* PTE-mapped THP are never mlocked */ - if (!PageTransCompound(page)) { + /* PTE-mapped THP are never marked as mlocked */ + if (!PageTransCompound(page) || + (PageHead(page) && !PageDoubleMap(page))) { /* * Holding pte lock, we do *not* need * mmap_lock here @@ -1984,9 +1985,11 @@ static bool page_mlock_one(struct page *page, struct vm_area_struct *vma, * munlock_vma_pages_range(). */ if (vma->vm_flags & VM_LOCKED) { - /* PTE-mapped THP are never mlocked */ - if (!PageTransCompound(page)) - mlock_vma_page(page); + /* + * PTE-mapped THP are never marked as mlocked, but + * this function is never called when PageDoubleMap(). + */ + mlock_vma_page(page); page_vma_mapped_walk_done(&pvmw); } From patchwork Wed Jul 7 20:11:24 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hugh Dickins X-Patchwork-Id: 12364013 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=-23.6 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_IN_DEF_DKIM_WL 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 3791DC07E95 for ; Wed, 7 Jul 2021 20:11:30 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id E2B6061CC8 for ; Wed, 7 Jul 2021 20:11:29 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E2B6061CC8 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 903AF6B0011; Wed, 7 Jul 2021 16:11:29 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8B3476B005D; Wed, 7 Jul 2021 16:11:29 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7546E6B006C; Wed, 7 Jul 2021 16:11:29 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0026.hostedemail.com [216.40.44.26]) by kanga.kvack.org (Postfix) with ESMTP id 567B06B0011 for ; Wed, 7 Jul 2021 16:11:29 -0400 (EDT) Received: from smtpin13.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id B370722BEB for ; Wed, 7 Jul 2021 20:11:28 +0000 (UTC) X-FDA: 78336886656.13.7E3FAF1 Received: from mail-oi1-f176.google.com (mail-oi1-f176.google.com [209.85.167.176]) by imf05.hostedemail.com (Postfix) with ESMTP id 48B0C50060BE for ; Wed, 7 Jul 2021 20:11:28 +0000 (UTC) Received: by mail-oi1-f176.google.com with SMTP id 65so2887755oie.11 for ; Wed, 07 Jul 2021 13:11:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:in-reply-to:message-id:references :mime-version; bh=tkLvj3QVD7vexG4Xax0/Xf4fPxWesEvFOVTsRIctnbE=; b=DimYOBmWYQW/QLOGazZvGUH0cOp4BjeBWl22T5GUbw5wwRvZulCYsVwboNvrRtKgwq UttP+xcQqopqEmJD6lfcDBMwkXxLRzo/f/SBb31xXzpSiqzRSlNAV4u7fPRnCbdERf4M N43sXq0FVsEMNu1titCD6BMLDkz2zpPN+ncx2ARPRKlKM0SG0Y9sN34VgP4rYpAXkPYc HpInlzLrD5mBPl85Y5sp4MFCMAAgFK19Mv8ZUq5Hulea2JKiig9Mxr0xe7UzBOP8pluX u20w9JsZtnjA02ns/eiQtUMDKhoqTN12wsem090lv3CIc1F2oPoQwstOetuD2ObZUZom mcZw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:in-reply-to:message-id :references:mime-version; bh=tkLvj3QVD7vexG4Xax0/Xf4fPxWesEvFOVTsRIctnbE=; b=RJz6HrzWRmBAouyzDe7Mz1KIrMqmIi/XEm2gWRfUK0/Vu4mzojyFp5G8WUnefUW1oj TJ/4eM4rRnQJHnYsM+jrQGqIA21yZ8rlwNwQ57d8l9+MxmWnW47waQ2XMYPRKQGt9t6v Y1JjZjNyLD/1QI4+X97LJMuO+VKZOj5deLN3PQCGMPM3rePr68SxLQMsyH/q9ZzD1fea Ic8qvzxGq5fOuaPxOg/Ckg9P41HpeRcBlUszOXDEbWJxzldh2ywtSs5eklwQ1q4RP+ZG 8YcfIbimSU2AN0yumQSiYMq9z/uglNSFrJ3ANXhNeqAeObpwhYaja5o+a/pBj9fgOGI8 IXfw== X-Gm-Message-State: AOAM531734SlHQgfV7DeCyAUirF7RyvchuefuA/efDVYjZATVgGWXTQa 4T/kMtdAYpwNrgXSVEGP+bhbig== X-Google-Smtp-Source: ABdhPJwD0mdBR7pybFHVGT2gLPjXxfazv3v8K3DlmpChS+1CEKZFMvIAsAQKMffg4mopu3SD6qgumw== X-Received: by 2002:aca:4288:: with SMTP id p130mr20635827oia.80.1625688687563; Wed, 07 Jul 2021 13:11:27 -0700 (PDT) Received: from ripple.attlocal.net (172-10-233-147.lightspeed.sntcca.sbcglobal.net. [172.10.233.147]) by smtp.gmail.com with ESMTPSA id o2sm455650oia.47.2021.07.07.13.11.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Jul 2021 13:11:27 -0700 (PDT) Date: Wed, 7 Jul 2021 13:11:24 -0700 (PDT) From: Hugh Dickins X-X-Sender: hugh@ripple.anvils To: Andrew Morton cc: Hugh Dickins , Alistair Popple , Jason Gunthorpe , Ralph Campbell , Christoph Hellwig , Yang Shi , "Kirill A. Shutemov" , Shakeel Butt , linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 3/4] mm/rmap: fix new bug: premature return from page_mlock_one() In-Reply-To: <563ce5b2-7a44-5b4d-1dfd-59a0e65932a9@google.com> Message-ID: References: <563ce5b2-7a44-5b4d-1dfd-59a0e65932a9@google.com> MIME-Version: 1.0 X-Rspam-User: nil Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=google.com header.s=20161025 header.b=DimYOBmW; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf05.hostedemail.com: domain of hughd@google.com designates 209.85.167.176 as permitted sender) smtp.mailfrom=hughd@google.com X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 48B0C50060BE X-Stat-Signature: 6syfcr3eu8wx4j88hes5j475qsj93rid X-HE-Tag: 1625688688-633904 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: In the unlikely race case that page_mlock_one() finds VM_LOCKED has been cleared by the time it got page table lock, page_vma_mapped_walk_done() must be called before returning, either explicitly, or by a final call to page_vma_mapped_walk() - otherwise the page table remains locked. Fixes: cd62734ca60d ("mm/rmap: split try_to_munlock from try_to_unmap") Signed-off-by: Hugh Dickins Reviewed-by: Shakeel Butt Reviewed-by: Alistair Popple --- mm/rmap.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/mm/rmap.c b/mm/rmap.c index 0e83c3be8568..1235368f0628 100644 --- a/mm/rmap.c +++ b/mm/rmap.c @@ -1990,14 +1990,13 @@ static bool page_mlock_one(struct page *page, struct vm_area_struct *vma, * this function is never called when PageDoubleMap(). */ mlock_vma_page(page); + /* + * No need to scan further once the page is marked + * as mlocked. + */ page_vma_mapped_walk_done(&pvmw); + return false; } - - /* - * no need to continue scanning other vma's if the page has - * been locked. - */ - return false; } return true; From patchwork Wed Jul 7 20:13:33 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hugh Dickins X-Patchwork-Id: 12364015 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=-23.6 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_IN_DEF_DKIM_WL 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 DE574C07E95 for ; Wed, 7 Jul 2021 20:13:40 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 88ECD61CC3 for ; Wed, 7 Jul 2021 20:13:40 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 88ECD61CC3 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 445D06B0011; Wed, 7 Jul 2021 16:13:40 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3CE786B005D; Wed, 7 Jul 2021 16:13:40 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 221B46B006C; Wed, 7 Jul 2021 16:13:40 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0110.hostedemail.com [216.40.44.110]) by kanga.kvack.org (Postfix) with ESMTP id EAB956B0011 for ; Wed, 7 Jul 2021 16:13:39 -0400 (EDT) Received: from smtpin03.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 509EF1F848 for ; Wed, 7 Jul 2021 20:13:39 +0000 (UTC) X-FDA: 78336892158.03.49C375C Received: from mail-ot1-f45.google.com (mail-ot1-f45.google.com [209.85.210.45]) by imf24.hostedemail.com (Postfix) with ESMTP id 7125DB00009F for ; Wed, 7 Jul 2021 20:13:38 +0000 (UTC) Received: by mail-ot1-f45.google.com with SMTP id 59-20020a9d0ac10000b0290462f0ab0800so3472456otq.11 for ; Wed, 07 Jul 2021 13:13:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:in-reply-to:message-id:references :mime-version; bh=G6BcXcovuKQX32KS++TwaxPjbkiZXZqUSnhVU2rIm8s=; b=tEoOzZ1g/YIreTbMKj6zR9yAyFeSivYOPq+hYIi/iDVJTtoF1Dx2vOc1HmT845PkjJ HVFDPmHUa2mnIjl65c316SoGWqSvWJyUHmTIFEBuFA9EJB8y0j54IiKnPm46oqAmE0UJ 7nb+3RnYxAKvlpIYin4xVMD9zayJEep6XK6OrCbBURG2UgCrgXWfTkIknWqG6TRl3mcC DMTgMDTNtXYMBJt8thR1IXs+E4mZBLCQi4Wn9mz6hGrj6++7FlJYZnTtX9bliBmrxNu4 yueKDYwBhsRbwMj3G9SUSZIz5rJ+f+UnY3xAfh9my7EdN+KYkS6Fy5LgRQqbgnWjDNjx kd6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:in-reply-to:message-id :references:mime-version; bh=G6BcXcovuKQX32KS++TwaxPjbkiZXZqUSnhVU2rIm8s=; b=AAdxRTK3TT75CZHJsnJttZ0Mv4X6fAUAX9QerCTLd3TjdHZtNcPhURx6PNpxXKxX9f wUW60sPHCN8ygfGsSiZUZO16OsUMoT6U9jcaFWnEoZT3tFitKGEkpuMsdIhXtcionzKO OxBO5srg+ksezFvhbQVl73bQVOxuegbC6BugjabHmyOfB+fAYtIUoDpA9jf2Iboob9E3 +uQJCcgufKub91nw7UI32uobcpEk5SBbfkSmbSnQD5mBNH17cTA7Xcxt8ELWch7PWvmB w4PLdOZdnhMp5tJ/oYuKjyBoHtAH35gQ1p0ikm6VAzi7zwFG534kCLj2s3yA6CsCccS/ RJyg== X-Gm-Message-State: AOAM531ZZayqY1wi3nCF5xHkXXMmWRowznEp/ihf8FJ8SR5K/nhZm1iR a1vp1iZftqa3dDmnBBu3cCH08Q== X-Google-Smtp-Source: ABdhPJy9GtfO7ixk82n+CnnqjqGznRdZMsyMi+BKZGN7Xsa/CU+WOyCKUSI8ZFeoVZcOXySTcqI/AQ== X-Received: by 2002:a9d:6a81:: with SMTP id l1mr12953964otq.239.1625688817503; Wed, 07 Jul 2021 13:13:37 -0700 (PDT) Received: from ripple.attlocal.net (172-10-233-147.lightspeed.sntcca.sbcglobal.net. [172.10.233.147]) by smtp.gmail.com with ESMTPSA id s131sm4318378oib.52.2021.07.07.13.13.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Jul 2021 13:13:37 -0700 (PDT) Date: Wed, 7 Jul 2021 13:13:33 -0700 (PDT) From: Hugh Dickins X-X-Sender: hugh@ripple.anvils To: Andrew Morton cc: Hugh Dickins , Alistair Popple , Jason Gunthorpe , Ralph Campbell , Christoph Hellwig , Yang Shi , "Kirill A. Shutemov" , Shakeel Butt , linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 4/4] mm/rmap: try_to_migrate() skip zone_device !device_private In-Reply-To: <563ce5b2-7a44-5b4d-1dfd-59a0e65932a9@google.com> Message-ID: <1241d356-8ec9-f47b-a5ec-9b2bf66d242@google.com> References: <563ce5b2-7a44-5b4d-1dfd-59a0e65932a9@google.com> MIME-Version: 1.0 X-Rspam-User: nil Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=google.com header.s=20161025 header.b=tEoOzZ1g; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf24.hostedemail.com: domain of hughd@google.com designates 209.85.210.45 as permitted sender) smtp.mailfrom=hughd@google.com X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 7125DB00009F X-Stat-Signature: ufd1pc8wsp9kcubs1487s4b5px7zfopz X-HE-Tag: 1625688818-42909 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: I know nothing about zone_device pages and !device_private pages; but if try_to_migrate_one() will do nothing for them, then it's better that try_to_migrate() filter them first, than trawl through all their vmas. Signed-off-by: Hugh Dickins Reviewed-by: Shakeel Butt Reviewed-by: Alistair Popple --- mm/rmap.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mm/rmap.c b/mm/rmap.c index 1235368f0628..795f9d5f8386 100644 --- a/mm/rmap.c +++ b/mm/rmap.c @@ -1703,9 +1703,6 @@ static bool try_to_migrate_one(struct page *page, struct vm_area_struct *vma, struct mmu_notifier_range range; enum ttu_flags flags = (enum ttu_flags)(long)arg; - if (is_zone_device_page(page) && !is_device_private_page(page)) - return true; - /* * When racing against e.g. zap_pte_range() on another cpu, * in between its ptep_get_and_clear_full() and page_remove_rmap(), @@ -1944,6 +1941,9 @@ void try_to_migrate(struct page *page, enum ttu_flags flags) TTU_SYNC))) return; + if (is_zone_device_page(page) && !is_device_private_page(page)) + return; + /* * During exec, a temporary VMA is setup and later moved. * The VMA is moved under the anon_vma lock but not the