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=-15.2 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, 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 1849BC64E8A for ; Wed, 2 Dec 2020 11:17:05 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 500F822206 for ; Wed, 2 Dec 2020 11:17:03 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 500F822206 Authentication-Results: mail.kernel.org; dmarc=fail (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 285536B005C; Wed, 2 Dec 2020 06:17:03 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 2362D8D0002; Wed, 2 Dec 2020 06:17:03 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 14DB18D0001; Wed, 2 Dec 2020 06:17:03 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0146.hostedemail.com [216.40.44.146]) by kanga.kvack.org (Postfix) with ESMTP id F33026B005C for ; Wed, 2 Dec 2020 06:17:02 -0500 (EST) Received: from smtpin14.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id ACBE51EF2 for ; Wed, 2 Dec 2020 11:17:02 +0000 (UTC) X-FDA: 77548090284.14.train59_0e14772273b2 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin14.hostedemail.com (Postfix) with ESMTP id 6B6A318229835 for ; Wed, 2 Dec 2020 11:17:02 +0000 (UTC) X-HE-Tag: train59_0e14772273b2 X-Filterd-Recvd-Size: 9986 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf19.hostedemail.com (Postfix) with ESMTP for ; Wed, 2 Dec 2020 11:17:01 +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 1F55B1042; Wed, 2 Dec 2020 03:17:01 -0800 (PST) Received: from [192.168.1.179] (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id BD5973F66B; Wed, 2 Dec 2020 03:16:59 -0800 (PST) Subject: Re: [PATCH V2 1/2] mm/debug_vm_pgtable/basic: Add validation for dirtiness after write protect To: Anshuman Khandual , linux-mm@kvack.org, akpm@linux-foundation.org Cc: linux-kernel@vger.kernel.org, catalin.marinas@arm.com, christophe.leroy@csgroup.eu, gerald.schaefer@linux.ibm.com, vgupta@synopsys.com, paul.walmsley@sifive.com References: <1606825169-5229-1-git-send-email-anshuman.khandual@arm.com> <1606825169-5229-2-git-send-email-anshuman.khandual@arm.com> From: Steven Price Message-ID: <5d07e798-aa91-ec00-36af-108ff0b19709@arm.com> Date: Wed, 2 Dec 2020 11:16:54 +0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: <1606825169-5229-2-git-send-email-anshuman.khandual@arm.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-GB Content-Transfer-Encoding: 7bit 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 01/12/2020 12:19, Anshuman Khandual wrote: > This adds validation tests for dirtiness after write protect conversion for > each page table level. There are two new separate test types involved here. > > The first test ensures that a given page table entry does not become dirty > after pxx_wrprotect(). This is important for platforms like arm64 which > transfers and drops the hardware dirty bit (!PTE_RDONLY) to the software > dirty bit while making it an write protected one. This test ensures that > no fresh page table entry could be created with hardware dirty bit set. > The second test ensures that a given page table entry always preserve the > dirty information across pxx_wrprotect(). > > This adds two previously missing PUD level basic tests and while here fixes > pxx_wrprotect() related typos in the documentation file. > > Cc: Andrew Morton > Cc: linux-mm@kvack.org > Cc: linux-kernel@vger.kernel.org > Suggested-by: Catalin Marinas > Signed-off-by: Anshuman Khandual > --- > Documentation/vm/arch_pgtable_helpers.rst | 8 ++--- > mm/debug_vm_pgtable.c | 42 +++++++++++++++++++++++ > 2 files changed, 46 insertions(+), 4 deletions(-) > > diff --git a/Documentation/vm/arch_pgtable_helpers.rst b/Documentation/vm/arch_pgtable_helpers.rst > index f3591ee3aaa8..552567d863b8 100644 > --- a/Documentation/vm/arch_pgtable_helpers.rst > +++ b/Documentation/vm/arch_pgtable_helpers.rst > @@ -50,7 +50,7 @@ PTE Page Table Helpers > +---------------------------+--------------------------------------------------+ > | pte_mkwrite | Creates a writable PTE | > +---------------------------+--------------------------------------------------+ > -| pte_mkwrprotect | Creates a write protected PTE | > +| pte_wrprotect | Creates a write protected PTE | > +---------------------------+--------------------------------------------------+ > | pte_mkspecial | Creates a special PTE | > +---------------------------+--------------------------------------------------+ > @@ -120,7 +120,7 @@ PMD Page Table Helpers > +---------------------------+--------------------------------------------------+ > | pmd_mkwrite | Creates a writable PMD | > +---------------------------+--------------------------------------------------+ > -| pmd_mkwrprotect | Creates a write protected PMD | > +| pmd_wrprotect | Creates a write protected PMD | > +---------------------------+--------------------------------------------------+ > | pmd_mkspecial | Creates a special PMD | > +---------------------------+--------------------------------------------------+ > @@ -186,7 +186,7 @@ PUD Page Table Helpers > +---------------------------+--------------------------------------------------+ > | pud_mkwrite | Creates a writable PUD | > +---------------------------+--------------------------------------------------+ > -| pud_mkwrprotect | Creates a write protected PUD | > +| pud_wrprotect | Creates a write protected PUD | > +---------------------------+--------------------------------------------------+ > | pud_mkdevmap | Creates a ZONE_DEVICE mapped PUD | > +---------------------------+--------------------------------------------------+ > @@ -224,7 +224,7 @@ HugeTLB Page Table Helpers > +---------------------------+--------------------------------------------------+ > | huge_pte_mkwrite | Creates a writable HugeTLB | > +---------------------------+--------------------------------------------------+ > -| huge_pte_mkwrprotect | Creates a write protected HugeTLB | > +| huge_pte_wrprotect | Creates a write protected HugeTLB | > +---------------------------+--------------------------------------------------+ > | huge_ptep_get_and_clear | Clears a HugeTLB | > +---------------------------+--------------------------------------------------+ > diff --git a/mm/debug_vm_pgtable.c b/mm/debug_vm_pgtable.c > index c05d9dcf7891..c6fffea54522 100644 > --- a/mm/debug_vm_pgtable.c > +++ b/mm/debug_vm_pgtable.c > @@ -63,6 +63,17 @@ static void __init pte_basic_tests(unsigned long pfn, pgprot_t prot) > pte_t pte = pfn_pte(pfn, prot); > > pr_debug("Validating PTE basic\n"); > + > + /* > + * This test needs to execute right after the given page > + * table entry is created with pfn_pte() to make sure that > + * protection_map[idx] does not have the dirty bit enabled > + * from the beginning. This is particularly important for > + * platforms like arm64 where (!PTE_RDONLY) indicate dirty > + * bit being set. > + */ Unless I'm seriously mistaken this comment is misleading - the likes of pte_wrprotect() take the PTE *by value* and return the modified version. So none of these tests actually modify the variable 'pte'. So there shouldn't actually be any restrictions on the ordering. Or am I missing something? Steve > + WARN_ON(pte_dirty(pte_wrprotect(pte))); > + > WARN_ON(!pte_same(pte, pte)); > WARN_ON(!pte_young(pte_mkyoung(pte_mkold(pte)))); > WARN_ON(!pte_dirty(pte_mkdirty(pte_mkclean(pte)))); > @@ -70,6 +81,8 @@ static void __init pte_basic_tests(unsigned long pfn, pgprot_t prot) > WARN_ON(pte_young(pte_mkold(pte_mkyoung(pte)))); > WARN_ON(pte_dirty(pte_mkclean(pte_mkdirty(pte)))); > WARN_ON(pte_write(pte_wrprotect(pte_mkwrite(pte)))); > + WARN_ON(pte_dirty(pte_wrprotect(pte_mkclean(pte)))); > + WARN_ON(!pte_dirty(pte_wrprotect(pte_mkdirty(pte)))); > } > > static void __init pte_advanced_tests(struct mm_struct *mm, > @@ -137,6 +150,18 @@ static void __init pmd_basic_tests(unsigned long pfn, pgprot_t prot) > return; > > pr_debug("Validating PMD basic\n"); > + > + /* > + * This test needs to execute right after the given page > + * table entry is created with pfn_pmd() to make sure that > + * protection_map[idx] does not have the dirty bit enabled > + * from the beginning. This is particularly important for > + * platforms like arm64 where (!PTE_RDONLY) indicate dirty > + * bit being set. > + */ > + WARN_ON(pmd_dirty(pmd_wrprotect(pmd))); > + > + > WARN_ON(!pmd_same(pmd, pmd)); > WARN_ON(!pmd_young(pmd_mkyoung(pmd_mkold(pmd)))); > WARN_ON(!pmd_dirty(pmd_mkdirty(pmd_mkclean(pmd)))); > @@ -144,6 +169,8 @@ static void __init pmd_basic_tests(unsigned long pfn, pgprot_t prot) > WARN_ON(pmd_young(pmd_mkold(pmd_mkyoung(pmd)))); > WARN_ON(pmd_dirty(pmd_mkclean(pmd_mkdirty(pmd)))); > WARN_ON(pmd_write(pmd_wrprotect(pmd_mkwrite(pmd)))); > + WARN_ON(pmd_dirty(pmd_wrprotect(pmd_mkclean(pmd)))); > + WARN_ON(!pmd_dirty(pmd_wrprotect(pmd_mkdirty(pmd)))); > /* > * A huge page does not point to next level page table > * entry. Hence this must qualify as pmd_bad(). > @@ -257,11 +284,26 @@ static void __init pud_basic_tests(unsigned long pfn, pgprot_t prot) > return; > > pr_debug("Validating PUD basic\n"); > + > + /* > + * This test needs to execute right after the given page > + * table entry is created with pfn_pud() to make sure that > + * protection_map[idx] does not have the dirty bit enabled > + * from the beginning. This is particularly important for > + * platforms like arm64 where (!PTE_RDONLY) indicate dirty > + * bit being set. > + */ > + WARN_ON(pud_dirty(pud_wrprotect(pud))); > + > WARN_ON(!pud_same(pud, pud)); > WARN_ON(!pud_young(pud_mkyoung(pud_mkold(pud)))); > + WARN_ON(!pud_dirty(pud_mkdirty(pud_mkclean(pud)))); > + WARN_ON(pud_dirty(pud_mkclean(pud_mkdirty(pud)))); > WARN_ON(!pud_write(pud_mkwrite(pud_wrprotect(pud)))); > WARN_ON(pud_write(pud_wrprotect(pud_mkwrite(pud)))); > WARN_ON(pud_young(pud_mkold(pud_mkyoung(pud)))); > + WARN_ON(pud_dirty(pud_wrprotect(pud_mkclean(pud)))); > + WARN_ON(!pud_dirty(pud_wrprotect(pud_mkdirty(pud)))); > > if (mm_pmd_folded(mm)) > return; >