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.2 required=3.0 tests=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 7BC24C43603 for ; Thu, 12 Dec 2019 13:15:36 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 0C36C22527 for ; Thu, 12 Dec 2019 13:15:35 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0C36C22527 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=arm.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 727138E0005; Thu, 12 Dec 2019 08:15:35 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 6B13F8E0001; Thu, 12 Dec 2019 08:15:35 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5A0028E0005; Thu, 12 Dec 2019 08:15:35 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0150.hostedemail.com [216.40.44.150]) by kanga.kvack.org (Postfix) with ESMTP id 424A68E0001 for ; Thu, 12 Dec 2019 08:15:35 -0500 (EST) Received: from smtpin15.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with SMTP id DC5F7181AEF1A for ; Thu, 12 Dec 2019 13:15:34 +0000 (UTC) X-FDA: 76256536188.15.blow56_4db8c10a81640 X-HE-Tag: blow56_4db8c10a81640 X-Filterd-Recvd-Size: 10932 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf30.hostedemail.com (Postfix) with ESMTP for ; Thu, 12 Dec 2019 13:15:33 +0000 (UTC) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id EA36030E; Thu, 12 Dec 2019 05:15:32 -0800 (PST) Received: from [10.37.9.115] (unknown [10.37.9.115]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 3C7D53F718; Thu, 12 Dec 2019 05:15:28 -0800 (PST) From: Steven Price Subject: Re: [PATCH v16 11/25] mm: pagewalk: Add p4d_entry() and pgd_entry() To: =?UTF-8?Q?Thomas_Hellstr=c3=b6m_=28VMware=29?= 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> Message-ID: Date: Thu, 12 Dec 2019 13:15:25 +0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.2.1 MIME-Version: 1.0 In-Reply-To: <7fd20e9f-822a-897d-218e-bddf135fd33d@shipmail.org> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-GB 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/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 wer= e >>> 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 wi= th >>> 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, no= t >>> 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 return=20 >> value after the callback. The change was fairly invasive, >> > Hmm. Forgot to remove the above text that appears twice. :(. The correc= t=20 > one is inline below. >=20 >> >>> 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, cal= led 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, cal= led 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, cal= led 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, cal= led for each non-empty P4D entry >>> + * @pud_entry:=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if set, cal= led for each non-empty PUD entry >>> + * @pmd_entry:=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if set, cal= led 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, cal= led 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, cal= led 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 i= f set, called for each hole at all levels >>> =C2=A0=C2=A0 * @hugetlb_entry:=C2=A0=C2=A0=C2=A0 if set, called for e= ach 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 tha= t @pre_vma and the vma walk succeeded. >>> + * >>> + * p?d_entry callbacks are called even if those levels are folded 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 (ops= ->pud_entry) { >>> -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 s= pinlock_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 i= f (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 e= rr =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 i= f (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 ---8<---- diff --git a/mm/hmm.c b/mm/hmm.c index d379cb6496ae..744b6644d0e4 100644 --- a/mm/hmm.c +++ b/mm/hmm.c @@ -478,19 +478,26 @@ static int hmm_vma_walk_pud(pud_t *pudp, unsigned l= ong start, unsigned long end, pmd_t *pmdp; pud_t pud; int ret; + spinlock_t *ptl =3D pud_trans_huge_lock(pudp, walk->vma); + if (!ptl) + return 0; =20 again: pud =3D READ_ONCE(*pudp); - if (pud_none(pud)) - return hmm_vma_walk_hole(start, end, walk); + if (pud_none(pud)) { + ret =3D hmm_vma_walk_hole(start, end, walk); + goto out_unlock; + } =20 if (pud_huge(pud) && pud_devmap(pud)) { unsigned long i, npages, pfn; uint64_t *pfns, cpu_flags; bool fault, write_fault; =20 - if (!pud_present(pud)) - return hmm_vma_walk_hole(start, end, walk); + if (!pud_present(pud)) { + ret =3D hmm_vma_walk_hole(start, end, walk); + goto out_unlock; + } =20 i =3D (addr - range->start) >> PAGE_SHIFT; npages =3D (end - addr) >> PAGE_SHIFT; @@ -499,16 +506,20 @@ static int hmm_vma_walk_pud(pud_t *pudp, unsigned l= ong start, unsigned long end, cpu_flags =3D pud_to_hmm_pfn_flags(range, pud); hmm_range_need_fault(hmm_vma_walk, pfns, npages, cpu_flags, &fault, &write_fault); - if (fault || write_fault) - return hmm_vma_walk_hole_(addr, end, fault, - write_fault, walk); + if (fault || write_fault) { + ret =3D hmm_vma_walk_hole_(addr, end, fault, + write_fault, walk); + goto out_unlock; + } =20 pfn =3D pud_pfn(pud) + ((addr & ~PUD_MASK) >> PAGE_SHIFT); for (i =3D 0; i < npages; ++i, ++pfn) { hmm_vma_walk->pgmap =3D get_dev_pagemap(pfn, hmm_vma_walk->pgmap); - if (unlikely(!hmm_vma_walk->pgmap)) - return -EBUSY; + if (unlikely(!hmm_vma_walk->pgmap)) { + ret =3D -EBUSY; + goto out_unlock; + } pfns[i] =3D hmm_device_entry_from_pfn(range, pfn) | cpu_flags; } @@ -517,7 +528,8 @@ static int hmm_vma_walk_pud(pud_t *pudp, unsigned lon= g start, unsigned long end, hmm_vma_walk->pgmap =3D NULL; } hmm_vma_walk->last =3D end; - return 0; + ret =3D 0; + goto out_unlock; } =20 split_huge_pud(walk->vma, pudp, addr); @@ -529,10 +541,14 @@ static int hmm_vma_walk_pud(pud_t *pudp, unsigned l= ong start, unsigned long end, next =3D pmd_addr_end(addr, end); ret =3D hmm_vma_walk_pmd(pmdp, addr, next, walk); if (ret) - return ret; + goto out_unlock; } while (pmdp++, addr =3D next, addr !=3D end); =20 - return 0; + ret =3D 0; + +out_unlock: + spin_unlock(ptl); + return ret; } #else #define hmm_vma_walk_pud NULL