From mboxrd@z Thu Jan 1 00:00:00 1970 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 381E4C433F5 for ; Fri, 17 Dec 2021 05:49:34 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 36C356B0071; Fri, 17 Dec 2021 00:49:23 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 31C2C6B0072; Fri, 17 Dec 2021 00:49:23 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1BC6E6B0073; Fri, 17 Dec 2021 00:49:23 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0248.hostedemail.com [216.40.44.248]) by kanga.kvack.org (Postfix) with ESMTP id 0CE486B0071 for ; Fri, 17 Dec 2021 00:49:23 -0500 (EST) Received: from smtpin30.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id C72BD1809B39D for ; Fri, 17 Dec 2021 05:49:12 +0000 (UTC) X-FDA: 78926208144.30.0CA8BA6 Received: from mail-lf1-f54.google.com (mail-lf1-f54.google.com [209.85.167.54]) by imf27.hostedemail.com (Postfix) with ESMTP id EDA0E40013 for ; Fri, 17 Dec 2021 05:49:11 +0000 (UTC) Received: by mail-lf1-f54.google.com with SMTP id z7so2287208lfi.11 for ; Thu, 16 Dec 2021 21:49:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=kJXxCMLlnl74SOPAvvqBjx1//vDUCGH7WqNkH3jxEik=; b=H4pYx6uzx3vrhbNr7UU/dQSFvpKFweT4KzrWoPRjQOgBJ6VkLXhsuJXaRUDhKhrQb/ lTyjB4DZbpFGFTg1C6eS8pghNor88uDQXle8o6yZUzIizfLZq2AmW6+1pY4OCadBwHFm TZDCQSHbRMosW/SX2TbyU/vTgwwu7rZMo/0X54aB+yJuHYNMO8zc9WVBkRz7njtArvG4 vvw/Zsn05GSvegGK0cqQ+Fq6w7cRtnXB5asYz4J1qEal3DPAeoZYtbZPZRGdo2wZjAxb jljwvzvQLH3q3+IVL31/W/zLhe1sqURYyC1H6qpsj3IlWN3xq3a3IS4whv0EhUCbrSRX zXcA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=kJXxCMLlnl74SOPAvvqBjx1//vDUCGH7WqNkH3jxEik=; b=AL0+NL6ruoKMAnf26WHSEJHTdttCBkC4NzKxgPpgqKpdVTGsn9jYcMYsdBGw7GLAaM +bIL516q/02mci6WR/CrsakgiRE10MlezaqmyWSGnkEO0RqpsW9LXyrCOuMSOI1Yhi/y e3XU8511nEPpyppbDbI4560yoZtnhvC00ORnrY+f7gmP6HXgQz3YcIGNDQbnqiggYC+7 yBlaWw44bC5WLMob+ZI5aU+yOAJyFaYxMMEpQSi3HbxTZzZ/YqCDLT7PTfH8Mo1VYPpU lxc3dlvi2ius1GMg0CeIckELTjJ5Vh1djy/LwjWfux2hfQE0sH6HFp0DNjafk45WOrmk SvHw== X-Gm-Message-State: AOAM530Ljd1mmoD60GAdS/SZShl9slfqeANGOPFbA9lY2paDg6XO04Oh BGKHvaAU+PhAj6TtqdAxUtU= X-Google-Smtp-Source: ABdhPJwPCYfZNm4yPmp3mGS2OFTvaaHG1R/rccBp9eGXOJgQrvBqJoreHkhFUPyTg+shqHzDdL78ZQ== X-Received: by 2002:a05:6512:3050:: with SMTP id b16mr1510730lfb.290.1639720150719; Thu, 16 Dec 2021 21:49:10 -0800 (PST) Received: from localhost.localdomain ([131.228.2.21]) by smtp.gmail.com with ESMTPSA id q9sm1219904lfu.232.2021.12.16.21.49.09 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 16 Dec 2021 21:49:10 -0800 (PST) Subject: Re: [PATCH V3] mm/gup.c: stricter check on THP migration entry during follow_pmd_mask To: "Huang, Ying" Cc: linux-mm@kvack.org, akpm@linux-foundation.org, Zi Yan , "Kirill A. Shutemov" References: <20211217023418.731424-1-lixinhai.lxh@gmail.com> <87wnk4rl2w.fsf@yhuang6-desk2.ccr.corp.intel.com> From: Li Xinhai Message-ID: <2951c893-91e3-3aee-5446-f868336c5b11@gmail.com> Date: Fri, 17 Dec 2021 13:49:02 +0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.14.0 MIME-Version: 1.0 In-Reply-To: <87wnk4rl2w.fsf@yhuang6-desk2.ccr.corp.intel.com> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: EDA0E40013 X-Stat-Signature: 9f8wdynadaxcoesnuo8qrb5jsxz7nkkn Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=H4pYx6uz; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf27.hostedemail.com: domain of lixinhai.lxh@gmail.com designates 209.85.167.54 as permitted sender) smtp.mailfrom=lixinhai.lxh@gmail.com X-HE-Tag: 1639720151-533698 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: On 12/17/21 11:01 AM, Huang, Ying wrote: > Li Xinhai writes: > >> When BUG_ON check for THP migration entry, the exsiting code only check > > s/exsiting/existing/ > > Found some misspelling in the comments too. Please fix them with some > tool. > Yes, those need be fixed, thanks. > Best Regards, > Huang, Ying > >> 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