From patchwork Sat Dec 11 15:10:13 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Xinhai X-Patchwork-Id: 12671817 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 DF92FC433F5 for ; Sat, 11 Dec 2021 15:10:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DC0E96B0072; Sat, 11 Dec 2021 10:10:33 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id D70566B0073; Sat, 11 Dec 2021 10:10:33 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C379E6B0074; Sat, 11 Dec 2021 10:10:33 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id B59BD6B0072 for ; Sat, 11 Dec 2021 10:10:33 -0500 (EST) Received: from smtpin15.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 8D2D587CB6 for ; Sat, 11 Dec 2021 15:10:23 +0000 (UTC) X-FDA: 78905849526.15.DB1B61F Received: from mail-lf1-f47.google.com (mail-lf1-f47.google.com [209.85.167.47]) by imf06.hostedemail.com (Postfix) with ESMTP id 7834E180006 for ; Sat, 11 Dec 2021 15:10:22 +0000 (UTC) Received: by mail-lf1-f47.google.com with SMTP id bu18so23295987lfb.0 for ; Sat, 11 Dec 2021 07:10:22 -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=ue/sMLc2JhhHEXQmTDlYbrafOGSrNrcZPciTPeeDWOQ=; b=p6/zmM0WAxKzS0MAx4nZCYXpto3hiPU7/9GN3YK/F3RVCpuidwGi09BkPNBPuTYdlv RPeKAxQaL0eFjO0nJSoGcEeevgmIHb+J4UooZqi7qBZ8+f/Yf2TY9ttdLocSccRO+v6Z aeHlp/TFBXTe7mPRN3TaWlAVKt3w1+DJC4yOzKSVkdFXUwHdQUjz6Rrkz0JfTqW5KsP+ bQuNzwceZRNDuchxv8GqJf1PrSBL55xijvdQ2Ty+H1ht1pMdvHMWlQ1RzlyS0zc9SDBP zcSttfGaBF2lQvJ0X86cEnC5gwCKu0XvkHyMSjP824s1TkE0RUv34PFei070ksbV2R+n 0MEA== 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=ue/sMLc2JhhHEXQmTDlYbrafOGSrNrcZPciTPeeDWOQ=; b=oEPLgLiXRS2GZ+cEIy1SfVj4WLiwk2XRYMv8gWKnyX4I218PxreGnE76NYH953p+xr /kpWfDquqmg5FoF0aqo04xjSo0ASpnS+xal/Qj2tlP5En52zkoYM70Ec2Ylhijuu9WFD +eEbs5xT58gAlJjq2tnLiFGJlSSgkIHLYpZYmCnyVopDKU93dvcwaRYAHFW1JPE2AnVL 2wvyIhjiQMpAFqOxR3239kzViYWQ8il4PRw3xXvwDqsmTG9pg+POxFCq/TdTW8DhKacO KPiQghPc5nBQQf6t4sJjxlxnITvNqlQgFlQJxBe+tkIPgcBPl4DW6xv3C54b+b/Pi/D/ uXmA== X-Gm-Message-State: AOAM533RCVx5IMWpoNXBKyipq8bP2ImSReilg/kbZtLpDTdh9DGdMmGH xv8udlTeywoyP6ROGpv0F9/1v+8CKFQ= X-Google-Smtp-Source: ABdhPJyKLgiKlDhv2WXcDshgEy2MOKH8cVYYGyrIFeCIacHvfLa1QeDAqiiqyHbiyOKv8+Pb8NWozg== X-Received: by 2002:a19:c797:: with SMTP id x145mr17528094lff.533.1639235421240; Sat, 11 Dec 2021 07:10:21 -0800 (PST) Received: from localhost.localdomain ([131.228.2.21]) by smtp.gmail.com with ESMTPSA id l19sm680547lji.27.2021.12.11.07.10.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 11 Dec 2021 07:10:20 -0800 (PST) From: Li Xinhai To: linux-mm@kvack.org Cc: akpm@linux-foundation.org Subject: [PATCH V2] mm/gup.c: stricter check on THP migration entry during follow_pmd_mask Date: Sat, 11 Dec 2021 23:10:13 +0800 Message-Id: <20211211151014.650778-1-lixinhai.lxh@gmail.com> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 7834E180006 X-Stat-Signature: st54rep54w7ywtbbf14cowzmnag6jj15 Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b="p6/zmM0W"; spf=pass (imf06.hostedemail.com: domain of lixinhai.lxh@gmail.com designates 209.85.167.47 as permitted sender) smtp.mailfrom=lixinhai.lxh@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-HE-Tag: 1639235422-291213 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000067, 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. 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 --- 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