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 X-Spam-Level: X-Spam-Status: No, score=-8.1 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 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 4C086C43603 for ; Thu, 12 Dec 2019 14:04:44 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id E910521655 for ; Thu, 12 Dec 2019 14:04:43 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=shipmail.org header.i=@shipmail.org header.b="DzhFO2Cz" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E910521655 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=shipmail.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 7504C8E0005; Thu, 12 Dec 2019 09:04:43 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 701F58E0001; Thu, 12 Dec 2019 09:04:43 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5EFC08E0005; Thu, 12 Dec 2019 09:04:43 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0081.hostedemail.com [216.40.44.81]) by kanga.kvack.org (Postfix) with ESMTP id 4985C8E0001 for ; Thu, 12 Dec 2019 09:04:43 -0500 (EST) Received: from smtpin08.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with SMTP id EC0288249980 for ; Thu, 12 Dec 2019 14:04:42 +0000 (UTC) X-FDA: 76256660004.08.boat18_45f553eeae20d X-HE-Tag: boat18_45f553eeae20d X-Filterd-Recvd-Size: 11114 Received: from pio-pvt-msa2.bahnhof.se (pio-pvt-msa2.bahnhof.se [79.136.2.41]) by imf06.hostedemail.com (Postfix) with ESMTP for ; Thu, 12 Dec 2019 14:04:40 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by pio-pvt-msa2.bahnhof.se (Postfix) with ESMTP id F285A3F6E0; Thu, 12 Dec 2019 15:04:38 +0100 (CET) Authentication-Results: pio-pvt-msa2.bahnhof.se; dkim=pass (1024-bit key; unprotected) header.d=shipmail.org header.i=@shipmail.org header.b=DzhFO2Cz; dkim-atps=neutral X-Virus-Scanned: Debian amavisd-new at bahnhof.se Received: from pio-pvt-msa2.bahnhof.se ([127.0.0.1]) by localhost (pio-pvt-msa2.bahnhof.se [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Q3s48xuWPFsv; Thu, 12 Dec 2019 15:04:33 +0100 (CET) Received: from mail1.shipmail.org (h-205-35.A357.priv.bahnhof.se [155.4.205.35]) (Authenticated sender: mb878879) by pio-pvt-msa2.bahnhof.se (Postfix) with ESMTPA id 2F78D3F617; Thu, 12 Dec 2019 15:04:30 +0100 (CET) Received: from localhost.localdomain (h-205-35.A357.priv.bahnhof.se [155.4.205.35]) by mail1.shipmail.org (Postfix) with ESMTPSA id 13DC43621B7; Thu, 12 Dec 2019 15:04:30 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=shipmail.org; s=mail; t=1576159470; bh=+81VifpPufQx1Ghf7UgamHghIAtblxqdt1z4rpeKwjw=; h=Subject:To:Cc:References:From:Date:In-Reply-To:From; b=DzhFO2Czsj4dlxMRNekZ5HARyubeVf/Z0IFsk9SHs7ghuuNJfX/lCADJRkbNKu9Xc chbNsFXIChLsKn2EMmrTWPks59Fk6Fc5P78vIRgrPvZQpWVKd2JOGzA2NNOUv4e8Ig IMiWhXAy3y1WXfta2R8hBYxsV4ji02fQFhFx/csY= Subject: Re: [PATCH v16 11/25] mm: pagewalk: Add p4d_entry() and pgd_entry() To: Steven Price Cc: Mark Rutland , x86@kernel.org, Zong Li , Arnd Bergmann , Ard Biesheuvel , Peter Zijlstra , Catalin Marinas , Dave Hansen , linux-kernel@vger.kernel.org, "linux-mm@kvack.org" , =?UTF-8?B?SsOpcsO0bWUgR2xpc3Nl?= , Ingo Molnar , Borislav Petkov , Andy Lutomirski , "H. Peter Anvin" , James Morse , Thomas Gleixner , Will Deacon , Andrew Morton , linux-arm-kernel@lists.infradead.org, "Liang, Kan" References: <20191206135316.47703-1-steven.price@arm.com> <20191206135316.47703-12-steven.price@arm.com> <13280f9e-6f03-e1fd-659a-31462ba185b0@shipmail.org> <7fd20e9f-822a-897d-218e-bddf135fd33d@shipmail.org> From: =?UTF-8?Q?Thomas_Hellstr=c3=b6m_=28VMware=29?= Organization: VMware Inc. Message-ID: <16b2ecbc-316a-33f8-ace2-e54cd8001b24@shipmail.org> Date: Thu, 12 Dec 2019 15:04:29 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: quoted-printable 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/12/19 2:15 PM, Steven Price wrote: > On 12/12/2019 11:33, Thomas Hellstr=C3=B6m (VMware) wrote: >> On 12/12/19 12:23 PM, Thomas Hellstr=C3=B6m (VMware) wrote: >>> On 12/6/19 2:53 PM, Steven Price wrote: >>>> pgd_entry() and pud_entry() were removed by commit 0b1fbfe50006c410 >>>> ("mm/pagewalk: remove pgd_entry() and pud_entry()") because there we= re >>>> no users. We're about to add users so reintroduce them, along with >>>> p4d_entry() as we now have 5 levels of tables. >>>> >>>> Note that commit a00cc7d9dd93d66a ("mm, x86: add support for >>>> PUD-sized transparent hugepages") already re-added pud_entry() but=20 >>>> with >>>> different semantics to the other callbacks. Since there have never >>>> been upstream users of this, revert the semantics back to match the >>>> other callbacks. This means pud_entry() is called for all entries, n= ot >>>> just transparent huge pages. > > When I wrote that there were no upstream users, which sadly shows how > long ago that was :( > >>> Actually, there are two users of pud_entry(), in hmm.c and since=20 >>> 5.5rc1 also mapping_dirty_helpers.c. The latter one is unproblematic=20 >>> and requires no attention but the one in hmm.c is probably largely=20 >>> untested, and seems to assume it was called outside of the spinlock. >>> >>> The problem with the current patch is that the hmm pud_entry will=20 >>> traverse also pmds, so that will be done twice now. >>> >>> In another thread we were discussing a means of rerunning the level=20 >>> (in case of a race), or continuing after a level, based on the=20 >>> return value after the callback. The change was fairly invasive, >>> >> Hmm. Forgot to remove the above text that appears twice. :(. The=20 >> correct one is inline below. >> >>> >>>> Tested-by: Zong Li >>>> Signed-off-by: Steven Price >>>> --- >>>> =C2=A0 include/linux/pagewalk.h | 19 +++++++++++++------ >>>> =C2=A0 mm/pagewalk.c=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0 | 27 ++++++++++++++++----------- >>>> =C2=A0 2 files changed, 29 insertions(+), 17 deletions(-) >>>> >>>> diff --git a/include/linux/pagewalk.h b/include/linux/pagewalk.h >>>> index 6ec82e92c87f..06790f23957f 100644 >>>> --- a/include/linux/pagewalk.h >>>> +++ b/include/linux/pagewalk.h >>>> @@ -8,15 +8,15 @@ struct mm_walk; >>>> =C2=A0 =C2=A0 /** >>>> =C2=A0=C2=A0 * mm_walk_ops - callbacks for walk_page_range >>>> - * @pud_entry:=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if set, ca= lled for each non-empty PUD=20 >>>> (2nd-level) entry >>>> - *=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= this handler should only handle pud_trans_huge() puds. >>>> - *=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= the pmd_entry or pte_entry callbacks will be used for >>>> - *=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= regular PUDs. >>>> - * @pmd_entry:=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if set, ca= lled for each non-empty PMD=20 >>>> (3rd-level) entry >>>> + * @pgd_entry:=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if set, ca= lled for each non-empty PGD=20 >>>> (top-level) entry >>>> + * @p4d_entry:=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if set, ca= lled for each non-empty P4D entry >>>> + * @pud_entry:=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if set, ca= lled for each non-empty PUD entry >>>> + * @pmd_entry:=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if set, ca= lled for each non-empty PMD entry >>>> =C2=A0=C2=A0 *=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0 this handler is required to be able to handle >>>> =C2=A0=C2=A0 *=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0 pmd_trans_huge() pmds.=C2=A0 They may simply choose to >>>> =C2=A0=C2=A0 *=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0 split_huge_page() instead of handling it explicitly. >>>> - * @pte_entry:=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if set, ca= lled for each non-empty PTE=20 >>>> (4th-level) entry >>>> + * @pte_entry:=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if set, ca= lled for each non-empty PTE=20 >>>> (lowest-level) >>>> + *=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= entry >>>> =C2=A0=C2=A0 * @pte_hole:=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 = if set, called for each hole at all levels >>>> =C2=A0=C2=A0 * @hugetlb_entry:=C2=A0=C2=A0=C2=A0 if set, called for = each hugetlb entry >>>> =C2=A0=C2=A0 * @test_walk:=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= caller specific callback function to=20 >>>> determine whether >>>> @@ -27,8 +27,15 @@ struct mm_walk; >>>> =C2=A0=C2=A0 * @pre_vma:=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0 if set, called before starting walk on a=20 >>>> non-null vma. >>>> =C2=A0=C2=A0 * @post_vma:=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0 if set, called after a walk on a non-null=20 >>>> vma, provided >>>> =C2=A0=C2=A0 *=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 = that @pre_vma and the vma walk succeeded. >>>> + * >>>> + * p?d_entry callbacks are called even if those levels are folded=20 >>>> on a >>>> + * particular architecture/configuration. >>>> =C2=A0=C2=A0 */ >>>> =C2=A0 struct mm_walk_ops { >>>> +=C2=A0=C2=A0=C2=A0 int (*pgd_entry)(pgd_t *pgd, unsigned long addr, >>>> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0 unsigned long next, struct mm_walk *walk); >>>> +=C2=A0=C2=A0=C2=A0 int (*p4d_entry)(p4d_t *p4d, unsigned long addr, >>>> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0 unsigned long next, struct mm_walk *walk); >>>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 int (*pud_entry)(pud_t *pud, unsigned= long addr, >>>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0 unsigned long next, struct mm_walk *walk); >>>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 int (*pmd_entry)(pmd_t *pmd, unsigned= long addr, >>>> diff --git a/mm/pagewalk.c b/mm/pagewalk.c >>>> index ea0b9e606ad1..c089786e7a7f 100644 >>>> --- a/mm/pagewalk.c >>>> +++ b/mm/pagewalk.c >>>> @@ -94,15 +94,9 @@ static int walk_pud_range(p4d_t *p4d, unsigned=20 >>>> long addr, unsigned long end, >>>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 } >>>> =C2=A0 =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if (op= s->pud_entry) { >>>> -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 = spinlock_t *ptl =3D pud_trans_huge_lock(pud, walk->vma); >>>> - >>>> -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 = if (ptl) { >>>> -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0 err =3D ops->pud_entry(pud, addr, next, walk); >>>> -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0 spin_unlock(ptl); >>>> -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0 if (err) >>>> -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 break; >>>> -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0 continue; >>>> -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 = } >>>> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 = err =3D ops->pud_entry(pud, addr, next, walk); >>>> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 = if (err) >>>> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0 break; >>> >>> Actually, there are two current users of pud_entry(), in hmm.c and=20 >>> since 5.5rc1 also mapping_dirty_helpers.c. The latter one is=20 >>> unproblematic and requires no attention but the one in hmm.c is=20 >>> probably largely untested, and seems to assume it was called outside=20 >>> of the spinlock. > > Thanks for pointing that out, I guess the simplest fix would be to > squash in something like the below which should restore the old > behaviour for hmm.c without affecting others. > > Steve=20 I'm not fully sure that the old behaviour is the correct one, but definit= ely hmm's pud_entry needs some fixing. I'm more concerned with the pagewalk code. With your patch it actually sp= lits all huge puds present in the page-table on each page walk which is not what we want. One idea would be to add a new member to struct_mm_walk: enum page_walk_ret_action { ACTION_SUBTREE =3D 0, ACTION_CONTINUE =3D 1, ACTION_AGAIN =3D 2 /* Only for levels that thave p?d_unstable */ }; struct mm_walk { ... enum page_walk_ret_action action; /* or perhaps as an enum */ }; if (ops->pud_entry) { walk->action =3D ACTION_SUBTREE; ... ... ... if (walk->action =3D=3D ACTION_AGAIN) /* Callback tried to split huge e= ntry, but failed */ goto again; else if (walk->action =3D=3D ACTION_CONTINUE) /* Done with this subtree.= Probably huge entry handled. */ continue; /* ACTION_SUBTREE falls through */ } we discussed something similar before on linux-mm, but the idea then was = to redefine the positive return value of the callback to the action, but that meant c= hanging those existing callbacks that relied on a positive return value. The above would be helpful also for pmd_entry. /Thomas