From patchwork Fri Dec 17 02:34:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Xinhai X-Patchwork-Id: 12683591 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 2BD9DC433EF for ; Fri, 17 Dec 2021 02:34:50 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8F4756B0071; Thu, 16 Dec 2021 21:34:39 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 866DE6B0072; Thu, 16 Dec 2021 21:34:39 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6BA506B0073; Thu, 16 Dec 2021 21:34:39 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0044.hostedemail.com [216.40.44.44]) by kanga.kvack.org (Postfix) with ESMTP id 57A146B0071 for ; Thu, 16 Dec 2021 21:34:39 -0500 (EST) Received: from smtpin26.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 1DFEC18084F49 for ; Fri, 17 Dec 2021 02:34:29 +0000 (UTC) X-FDA: 78925717458.26.CEB86DA Received: from mail-lj1-f177.google.com (mail-lj1-f177.google.com [209.85.208.177]) by imf21.hostedemail.com (Postfix) with ESMTP id E698C1C0017 for ; Fri, 17 Dec 2021 02:34:25 +0000 (UTC) Received: by mail-lj1-f177.google.com with SMTP id v15so1156692ljc.0 for ; Thu, 16 Dec 2021 18:34:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=LSOFWKG4dFbEKl7uoRTwVqPN3AB/yY27vUvKToCOD80=; b=GtQU5+4NXljtG+TvFMYazUcXXcntmzFGsxDuB32YFY19deGdiXOYzYA/5G1K5U8r6D p1v6Z+C1MlGQt8IVFf2kDcwC2XqYt8PhEdBLziNLYLGv79FtOCYAFaWmpjS3k32B2MK1 Jv3YyOaF9zL63vWyrpnwzcc8IJj0qr1d3NwIJqveA6TC0InnCunRlq/qkVQ9LBE252OH N3z0UrZXuXVc/RiYd2ZRgSVLwCb+Xxru7naThO1OQt0TihkTfrtHyNKiRqWrDINKdLxw 3C/pkrWe6bT3zw+3PWBg4t/pWQA/PPl4ikZn4GMTSGW33qtSkpR6BXTU7LsvjnvgquZH Hh2Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=LSOFWKG4dFbEKl7uoRTwVqPN3AB/yY27vUvKToCOD80=; b=GNpCA/y5FoJeGReIqdkA4Hj94Ytcx3jQigAXT+x9UShzVkbPFMNeB4hadSgOzdRib2 LGZEZssSYn/eDDYrN+evZ65epWUfvYZppBn8n093xfxiVfIxn0alFqLNTokIeemu8EHZ pbnGv2Ud4b7Ka8erd5wvepCdUgYKsC6vmvRZ7CvkVPaeUoaEkM0cJyviagR3vKHPrOWG aTeOv8TTFGgbTrumuGECsGTYay3TUGYxlcAEdsvsd+fhCYb8tNYJCb0XTKecUKfUp2y4 uLHUwl97dzJ3ORHwvo5T52x3RIFbi6gA4zlHjR8Q3E/DlwidqC7jCcjgqOzMD1LAV/ei FqVA== X-Gm-Message-State: AOAM5311V2bXwplCmA7LrrFIGl3AGnawuqvuf4kbDELE6l9J4Xz9YYH3 P+2Rl+gNJfBQjuctaLTluKyOyWIEYDU= X-Google-Smtp-Source: ABdhPJzWBDr6hLCXAYxAo6LrCc94PL/rTIerU0y6SY/eEqr4584IN09qlzycGfcyuUhGgOlVnVf/fQ== X-Received: by 2002:a2e:8189:: with SMTP id e9mr852666ljg.333.1639708466940; Thu, 16 Dec 2021 18:34:26 -0800 (PST) Received: from localhost.localdomain ([131.228.2.20]) by smtp.gmail.com with ESMTPSA id g27sm1153676lfe.55.2021.12.16.18.34.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Dec 2021 18:34:26 -0800 (PST) From: Li Xinhai To: linux-mm@kvack.org Cc: akpm@linux-foundation.org, Zi Yan , "Huang, Ying" , "Kirill A. Shutemov" Subject: [PATCH V3] mm/gup.c: stricter check on THP migration entry during follow_pmd_mask Date: Fri, 17 Dec 2021 10:34:18 +0800 Message-Id: <20211217023418.731424-1-lixinhai.lxh@gmail.com> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 X-Rspamd-Queue-Id: E698C1C0017 X-Stat-Signature: pdn6duzeah81rfgjf14kujceb78oytc5 Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=GtQU5+4N; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf21.hostedemail.com: domain of lixinhai.lxh@gmail.com designates 209.85.208.177 as permitted sender) smtp.mailfrom=lixinhai.lxh@gmail.com X-Rspamd-Server: rspam11 X-HE-Tag: 1639708465-170528 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: When BUG_ON check for THP migration entry, the exsiting code only check thp_migration_supported case, but not for !thp_migration_supported case. If !thp_migration_supported() and !pmd_present(), the original code may dead loop in theory. To make the BUG_ON check consistent, we need catch both cases. Move the BUG_ON check one step eariler, because if the bug happen we should know it instead of depend on FOLL_MIGRATION been used by caller. Because pmdval instead of *pmd is read by the is_pmd_migration_entry() check, the existing code don't help to avoid useless locking within pmd_migration_entry_wait(), so remove that check. Signed-off-by: Li Xinhai Cc: Zi Yan Cc: "Huang, Ying" Cc: "Kirill A. Shutemov" --- V2->V3: mention about the dead loop in commit message. V1->V2: Move the BUG_ON() check before if(!(flags & FOLL_MIGRATION)); and add comments for it. mm/gup.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/mm/gup.c b/mm/gup.c index 2c51e9748a6a..94d0e586ca0b 100644 --- a/mm/gup.c +++ b/mm/gup.c @@ -642,12 +642,17 @@ static struct page *follow_pmd_mask(struct vm_area_struct *vma, } retry: if (!pmd_present(pmdval)) { + /* + * Should never reach here, if thp migration is not supported; + * Otherwise, it must be a thp miration entry. + */ + VM_BUG_ON(!thp_migration_supported() || + !is_pmd_migration_entry(pmdval)); + if (likely(!(flags & FOLL_MIGRATION))) return no_page_table(vma, flags); - VM_BUG_ON(thp_migration_supported() && - !is_pmd_migration_entry(pmdval)); - if (is_pmd_migration_entry(pmdval)) - pmd_migration_entry_wait(mm, pmd); + + pmd_migration_entry_wait(mm, pmd); pmdval = READ_ONCE(*pmd); /* * MADV_DONTNEED may convert the pmd to null because