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=-5.2 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,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 1818DC3F2C6 for ; Tue, 3 Mar 2020 05:55:49 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id C27FD20842 for ; Tue, 3 Mar 2020 05:55:48 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C27FD20842 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 736C76B0006; Tue, 3 Mar 2020 00:55:48 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 6E74A6B0007; Tue, 3 Mar 2020 00:55:48 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5FC846B0008; Tue, 3 Mar 2020 00:55:48 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0094.hostedemail.com [216.40.44.94]) by kanga.kvack.org (Postfix) with ESMTP id 480C56B0006 for ; Tue, 3 Mar 2020 00:55:48 -0500 (EST) Received: from smtpin13.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 36F218248047 for ; Tue, 3 Mar 2020 05:55:48 +0000 (UTC) X-FDA: 76552989576.13.foot03_89e9583f7e934 X-HE-Tag: foot03_89e9583f7e934 X-Filterd-Recvd-Size: 9577 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf01.hostedemail.com (Postfix) with ESMTP for ; Tue, 3 Mar 2020 05:55:47 +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 8AFF62F; Mon, 2 Mar 2020 21:55:46 -0800 (PST) Received: from [10.162.16.51] (p8cg001049571a15.blr.arm.com [10.162.16.51]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 88AF23F6CF; Mon, 2 Mar 2020 21:55:39 -0800 (PST) Subject: Re: [PATCH V14] mm/debug: Add tests validating architecture page table helpers To: Qian Cai , Christophe Leroy , linux-mm@kvack.org Cc: Andrew Morton , Mike Rapoport , Vineet Gupta , Catalin Marinas , Will Deacon , Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman , Heiko Carstens , Vasily Gorbik , Christian Borntraeger , Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H. Peter Anvin" , "Kirill A . Shutemov" , Paul Walmsley , Palmer Dabbelt , linux-snps-arc@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linuxppc-dev@lists.ozlabs.org, linux-s390@vger.kernel.org, linux-riscv@lists.infradead.org, x86@kernel.org, linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org References: <1581909460-19148-1-git-send-email-anshuman.khandual@arm.com> <1582726182.7365.123.camel@lca.pw> <7c707b7f-ce3d-993b-8042-44fdc1ed28bf@c-s.fr> <1582732318.7365.129.camel@lca.pw> <1583178042.7365.146.camel@lca.pw> From: Anshuman Khandual Message-ID: Date: Tue, 3 Mar 2020 11:25:37 +0530 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: <1583178042.7365.146.camel@lca.pw> Content-Type: text/plain; charset=utf-8 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 03/03/2020 01:10 AM, Qian Cai wrote: > On Wed, 2020-02-26 at 10:51 -0500, Qian Cai wrote: >> On Wed, 2020-02-26 at 15:45 +0100, Christophe Leroy wrote: >>> >>> Le 26/02/2020 =C3=A0 15:09, Qian Cai a =C3=A9crit=C2=A0: >>>> On Mon, 2020-02-17 at 08:47 +0530, Anshuman Khandual wrote: >>>>> This adds tests which will validate architecture page table helpers= and >>>>> other accessors in their compliance with expected generic MM semant= ics. >>>>> This will help various architectures in validating changes to exist= ing >>>>> page table helpers or addition of new ones. >>>>> >>>>> This test covers basic page table entry transformations including b= ut not >>>>> limited to old, young, dirty, clean, write, write protect etc at va= rious >>>>> level along with populating intermediate entries with next page tab= le page >>>>> and validating them. >>>>> >>>>> Test page table pages are allocated from system memory with require= d size >>>>> and alignments. The mapped pfns at page table levels are derived fr= om a >>>>> real pfn representing a valid kernel text symbol. This test gets ca= lled >>>>> inside kernel_init() right after async_synchronize_full(). >>>>> >>>>> This test gets built and run when CONFIG_DEBUG_VM_PGTABLE is select= ed. Any >>>>> architecture, which is willing to subscribe this test will need to = select >>>>> ARCH_HAS_DEBUG_VM_PGTABLE. For now this is limited to arc, arm64, x= 86, s390 >>>>> and ppc32 platforms where the test is known to build and run succes= sfully. >>>>> Going forward, other architectures too can subscribe the test after= fixing >>>>> any build or runtime problems with their page table helpers. Meanwh= ile for >>>>> better platform coverage, the test can also be enabled with CONFIG_= EXPERT >>>>> even without ARCH_HAS_DEBUG_VM_PGTABLE. >>>>> >>>>> Folks interested in making sure that a given platform's page table = helpers >>>>> conform to expected generic MM semantics should enable the above co= nfig >>>>> which will just trigger this test during boot. Any non conformity h= ere will >>>>> be reported as an warning which would need to be fixed. This test w= ill help >>>>> catch any changes to the agreed upon semantics expected from generi= c MM and >>>>> enable platforms to accommodate it thereafter. >>>> >>>> How useful is this that straightly crash the powerpc? >>>> >>>> [=C2=A0=C2=A0=C2=A023.263425][=C2=A0=C2=A0=C2=A0=C2=A0T1] debug_vm_p= gtable: debug_vm_pgtable: Validating >>>> architecture page table helpers >>>> [=C2=A0=C2=A0=C2=A023.263625][=C2=A0=C2=A0=C2=A0=C2=A0T1] ----------= --[ cut here ]------------ >>>> [=C2=A0=C2=A0=C2=A023.263649][=C2=A0=C2=A0=C2=A0=C2=A0T1] kernel BUG= at arch/powerpc/mm/pgtable.c:274! >>> >>> The problem on PPC64 is known and has to be investigated and fixed. >> >> It might be interesting to hear what powerpc64 maintainers would say a= bout it >> and if it is actually worth "fixing" in the arch code, but that BUG_ON= () was >> there since 2009 and had not been exposed until this patch comes alone= ? >=20 > This patch below makes it works on powerpc64 in order to dodge the BUG_= ON()s in=20 > assert_pte_locked() triggered by pte_clear_tests(). >=20 >=20 > diff --git a/mm/debug_vm_pgtable.c b/mm/debug_vm_pgtable.c > index 96dd7d574cef..50b385233971 100644 > --- a/mm/debug_vm_pgtable.c > +++ b/mm/debug_vm_pgtable.c > @@ -55,6 +55,8 @@ > =C2=A0#define RANDOM_ORVALUE GENMASK(BITS_PER_LONG - 1, S390_MASK_BITS) > =C2=A0#define RANDOM_NZVALUE GENMASK(7, 0) > =C2=A0 > +unsigned long vaddr; > + > =C2=A0static void __init pte_basic_tests(unsigned long pfn, pgprot_t pr= ot) > =C2=A0{ > =C2=A0 pte_t pte =3D pfn_pte(pfn, prot); > @@ -256,7 +258,7 @@ static void __init pte_clear_tests(struct mm_struct= *mm, > pte_t *ptep) > =C2=A0 > =C2=A0 pte =3D __pte(pte_val(pte) | RANDOM_ORVALUE); > =C2=A0 WRITE_ONCE(*ptep, pte); > - pte_clear(mm, 0, ptep); > + pte_clear(mm, vaddr, ptep); > =C2=A0 pte =3D READ_ONCE(*ptep); > =C2=A0 WARN_ON(!pte_none(pte)); > =C2=A0} > @@ -310,8 +312,9 @@ void __init debug_vm_pgtable(void) > =C2=A0 pgtable_t saved_ptep; > =C2=A0 pgprot_t prot; > =C2=A0 phys_addr_t paddr; > - unsigned long vaddr, pte_aligned, pmd_aligned; > + unsigned long pte_aligned, pmd_aligned; > =C2=A0 unsigned long pud_aligned, p4d_aligned, pgd_aligned; > + spinlock_t *ptl; > =C2=A0 > =C2=A0 pr_info("Validating architecture page table helpers\n"); > =C2=A0 prot =3D vm_get_page_prot(VMFLAGS); > @@ -344,7 +347,7 @@ void __init debug_vm_pgtable(void) > =C2=A0 p4dp =3D p4d_alloc(mm, pgdp, vaddr); > =C2=A0 pudp =3D pud_alloc(mm, p4dp, vaddr); > =C2=A0 pmdp =3D pmd_alloc(mm, pudp, vaddr); > - ptep =3D pte_alloc_map(mm, pmdp, vaddr); > + ptep =3D pte_alloc_map_lock(mm, pmdp, vaddr, &ptl); > =C2=A0 > =C2=A0 /* > =C2=A0 =C2=A0* Save all the page table page addresses as the page table > @@ -370,7 +373,7 @@ void __init debug_vm_pgtable(void) > =C2=A0 p4d_clear_tests(mm, p4dp); > =C2=A0 pgd_clear_tests(mm, pgdp); > =C2=A0 > - pte_unmap(ptep); > + pte_unmap_unlock(ptep, ptl); > =C2=A0 > =C2=A0 pmd_populate_tests(mm, pmdp, saved_ptep); > =C2=A0 pud_populate_tests(mm, pudp, saved_pmdp); >=20 Below is slightly modified version of your change above and should still prevent the bug on powerpc. Will it be possible for you to re-test this ? Once confirmed, will send a patch enabling this test on powerpc64 keeping your authorship. Thank you. mm/debug_vm_pgtable.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/mm/debug_vm_pgtable.c b/mm/debug_vm_pgtable.c index 96dd7d574cef..c310f52c2b80 100644 --- a/mm/debug_vm_pgtable.c +++ b/mm/debug_vm_pgtable.c @@ -250,13 +250,14 @@ static void __init pgd_populate_tests(struct mm_str= uct *mm, pgd_t *pgdp, } #endif -static void __init pte_clear_tests(struct mm_struct *mm, pte_t *ptep) +static void __init pte_clear_tests(struct mm_struct *mm, pte_t *ptep, + unsigned long vaddr) { pte_t pte =3D READ_ONCE(*ptep); pte =3D __pte(pte_val(pte) | RANDOM_ORVALUE); WRITE_ONCE(*ptep, pte); - pte_clear(mm, 0, ptep); + pte_clear(mm, vaddr, ptep); pte =3D READ_ONCE(*ptep); WARN_ON(!pte_none(pte)); } @@ -302,6 +303,7 @@ static unsigned long __init get_random_vaddr(void) void __init debug_vm_pgtable(void) { struct mm_struct *mm; + spinlock_t *uninitialized_var(ptl); pgd_t *pgdp; p4d_t *p4dp, *saved_p4dp; pud_t *pudp, *saved_pudp; @@ -344,7 +346,7 @@ void __init debug_vm_pgtable(void) p4dp =3D p4d_alloc(mm, pgdp, vaddr); pudp =3D pud_alloc(mm, p4dp, vaddr); pmdp =3D pmd_alloc(mm, pudp, vaddr); - ptep =3D pte_alloc_map(mm, pmdp, vaddr); + ptep =3D pte_alloc_map_lock(mm, pmdp, vaddr, &ptl); /* * Save all the page table page addresses as the page table @@ -364,13 +366,13 @@ void __init debug_vm_pgtable(void) p4d_basic_tests(p4d_aligned, prot); pgd_basic_tests(pgd_aligned, prot); - pte_clear_tests(mm, ptep); + pte_clear_tests(mm, ptep, vaddr); pmd_clear_tests(mm, pmdp); pud_clear_tests(mm, pudp); p4d_clear_tests(mm, p4dp); pgd_clear_tests(mm, pgdp); - pte_unmap(ptep); + pte_unmap_unlock(ptep, ptl); pmd_populate_tests(mm, pmdp, saved_ptep); pud_populate_tests(mm, pudp, saved_pmdp); --=20 2.20.1