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=-10.2 required=3.0 tests=BAYES_00, 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 ED395C64E75 for ; Fri, 27 Nov 2020 09:44:29 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 4803821D93 for ; Fri, 27 Nov 2020 09:44:28 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4803821D93 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 3C1B96B0068; Fri, 27 Nov 2020 04:44:28 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 34BB36B006C; Fri, 27 Nov 2020 04:44:28 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 239996B006E; Fri, 27 Nov 2020 04:44:28 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0247.hostedemail.com [216.40.44.247]) by kanga.kvack.org (Postfix) with ESMTP id 0B55D6B0068 for ; Fri, 27 Nov 2020 04:44:28 -0500 (EST) Received: from smtpin26.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id C4E491450D for ; Fri, 27 Nov 2020 09:44:27 +0000 (UTC) X-FDA: 77529712974.26.crate55_270d9ef27387 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin26.hostedemail.com (Postfix) with ESMTP id A7C19180D8063 for ; Fri, 27 Nov 2020 09:44:27 +0000 (UTC) X-HE-Tag: crate55_270d9ef27387 X-Filterd-Recvd-Size: 3543 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by imf02.hostedemail.com (Postfix) with ESMTP for ; Fri, 27 Nov 2020 09:44:27 +0000 (UTC) Received: from gaia (unknown [95.146.230.165]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 5919121D81; Fri, 27 Nov 2020 09:44:24 +0000 (UTC) Date: Fri, 27 Nov 2020 09:44:21 +0000 From: Catalin Marinas To: Christophe Leroy Cc: Anshuman Khandual , linux-mm@kvack.org, akpm@linux-foundation.org, linux-kernel@vger.kernel.org, steven.price@arm.com, gerald.schaefer@linux.ibm.com, vgupta@synopsys.com, paul.walmsley@sifive.com Subject: Re: [PATCH 1/2] mm/debug_vm_pgtable/basic: Add validation for dirtiness after write protect Message-ID: <20201127094421.GA25070@gaia> References: <1606453584-15399-1-git-send-email-anshuman.khandual@arm.com> <1606453584-15399-2-git-send-email-anshuman.khandual@arm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) 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 Fri, Nov 27, 2020 at 09:22:24AM +0100, Christophe Leroy wrote: > Le 27/11/2020 =E0 06:06, Anshuman Khandual a =E9crit=A0: > > This adds validation tests for dirtiness after write protect conversi= on for > > each page table level. This is important for platforms such as arm64 = that > > removes the hardware dirty bit while making it an write protected one= . This > > also fixes pxx_wrprotect() related typos in the documentation file. >=20 > > diff --git a/mm/debug_vm_pgtable.c b/mm/debug_vm_pgtable.c > > index c05d9dcf7891..a5be11210597 100644 > > --- a/mm/debug_vm_pgtable.c > > +++ b/mm/debug_vm_pgtable.c > > @@ -70,6 +70,7 @@ static void __init pte_basic_tests(unsigned long pf= n, 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))); >=20 > Wondering what you are testing here exactly. >=20 > Do you expect that if PTE has the dirty bit, it gets cleared by pte_wrp= rotect() ? >=20 > Powerpc doesn't do that, it only clears the RW bit but the dirty bit re= mains > if it is set, until you call pte_mkclean() explicitely. Arm64 has an unusual way of setting a hardware dirty "bit", it actually clears the PTE_RDONLY bit. The pte_wrprotect() sets the PTE_RDONLY bit back and we can lose the dirty information. Will found this and posted patches to fix the arm64 pte_wprotect() to set a software PTE_DIRTY if !PTE_RDONLY (we do this for ptep_set_wrprotect() already). My concern was that we may inadvertently make a fresh/clean pte dirty with such change, hence the suggestion for the test. That said, I think we also need a test in the other direction, pte_wrprotect() should preserve any dirty information: WARN_ON(!pte_dirty(pte_wrprotect(pte_mkdirty(pte)))); If pte_mkwrite() makes a pte truly writable and potentially dirty, we could also add a test as below. However, I think that's valid for arm64, other architectures with a separate hardware dirty bit would fail this: WARN_ON(!pte_dirty(pte_wrprotect(pte_mkwrite(pte)))); --=20 Catalin