From nobody Mon Feb 9 15:09:25 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6D266EB64DD for ; Thu, 13 Jul 2023 07:15:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234134AbjGMHPg (ORCPT ); Thu, 13 Jul 2023 03:15:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40990 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234010AbjGMHPd (ORCPT ); Thu, 13 Jul 2023 03:15:33 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 0377DE4F for ; Thu, 13 Jul 2023 00:15:32 -0700 (PDT) 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 211861570; Thu, 13 Jul 2023 00:16:14 -0700 (PDT) Received: from a077893.arm.com (unknown [10.163.49.144]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 2EE083F73F; Thu, 13 Jul 2023 00:15:28 -0700 (PDT) From: Anshuman Khandual To: linux-arm-kernel@lists.infradead.org Cc: david@redhat.com, Anshuman Khandual , Catalin Marinas , Will Deacon , Mark Rutland , linux-kernel@vger.kernel.org Subject: [PATCH] arm64/mm: Set only the PTE_DIRTY bit while preserving the HW dirty state Date: Thu, 13 Jul 2023 12:45:18 +0530 Message-Id: <20230713071518.628440-1-anshuman.khandual@arm.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" pte_mkdirty() creates dirty states both in SW and HW bits, which is really not required, either in pte_wrprotect() or pte_modify() for preserving the HW dirty state. Because pte_mkdirty() sets PTE_DIRTY and clears PTE_RDONLY as pte_write() always evaluates to be true - otherwise pte_hw_dirty() will not test out in the first place. Clearing PTE_RDONLY again is not required here because the pte is already in pte_hw_dirty() but might soon loose its dirty state thus requiring preservation in SW dirty bit i.e PTE_DIRTY. Cc: Catalin Marinas Cc: Will Deacon Cc: Mark Rutland Cc: linux-arm-kernel@lists.infradead.org Cc: linux-kernel@vger.kernel.org Signed-off-by: Anshuman Khandual Acked-by: Catalin Marinas Reviewed-by: David Hildenbrand --- This applies on v6.5-rc1 arch/arm64/include/asm/pgtable.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/arch/arm64/include/asm/pgtable.h b/arch/arm64/include/asm/pgta= ble.h index 0bd18de9fd97..171d6d7f8087 100644 --- a/arch/arm64/include/asm/pgtable.h +++ b/arch/arm64/include/asm/pgtable.h @@ -212,7 +212,7 @@ static inline pte_t pte_wrprotect(pte_t pte) * clear), set the PTE_DIRTY bit. */ if (pte_hw_dirty(pte)) - pte =3D pte_mkdirty(pte); + pte =3D set_pte_bit(pte, __pgprot(PTE_DIRTY)); =20 pte =3D clear_pte_bit(pte, __pgprot(PTE_WRITE)); pte =3D set_pte_bit(pte, __pgprot(PTE_RDONLY)); @@ -823,7 +823,8 @@ static inline pte_t pte_modify(pte_t pte, pgprot_t newp= rot) PTE_ATTRINDX_MASK; /* preserve the hardware dirty information */ if (pte_hw_dirty(pte)) - pte =3D pte_mkdirty(pte); + pte =3D set_pte_bit(pte, __pgprot(PTE_DIRTY)); + pte_val(pte) =3D (pte_val(pte) & ~mask) | (pgprot_val(newprot) & mask); return pte; } --=20 2.30.2