Received: by 2002:a05:6358:7058:b0:131:369:b2a3 with SMTP id 24csp779939rwp; Thu, 13 Jul 2023 00:23:19 -0700 (PDT) X-Google-Smtp-Source: APBJJlHho5pqH4tyeyykXt55LfVbOBpp3F2ogOV3x7aX1yMHXC93TDXdQFXUxdqzSIKTkHoEnU+x X-Received: by 2002:aa7:c64c:0:b0:51e:57ba:cb8e with SMTP id z12-20020aa7c64c000000b0051e57bacb8emr1000906edr.5.1689232998930; Thu, 13 Jul 2023 00:23:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689232998; cv=none; d=google.com; s=arc-20160816; b=FQZ8vzidDzhwsNtvC2g1Jt81h3DirKNFvLK3Pj3BywTGj6wZckRP81QThyWzY0Xf11 /1yvfSOgzA64r2iG2Bs7mQThr1poeSNQHCBqnSy2JvbyLoo9D2ljVxYzk7renZw50+WQ GQuuM0ntnAPTrFwkjgw7tV9PtJd+V1NFX6RaUYMlaGOUrXBwUH5BePNj85Yz9P2XF0/G L0Pz3fu8n4IaiTlx7US/LM+cfSRvXomGSUWEurp18ZzRLlfMRW+5f8AFM55vG0G9Gs/X 94lHPxQtkDlcBlxI9PTrfKGb8eY0wwBnJif55SFTamxdWVTWMVX+sI7orWkCwpK6jRka BFyw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=qm0I7W09gmyPv7lEWa75AQp/SAR5gFKSAphZwnUBMmM=; fh=Qzq6QG5Ym7V0kmH2SoXkUw/ygx1leQFSgoXNlS2xy4o=; b=viQCCTwM2Y6Rd4us3pb0v69n69EO8cGNec8iI9GDd220QJfmiSqDsKLIUu+9XuPYac ITg9SbGwpXoyATFHER/nAesE7uPOCM/3ZxzWOa3aSbdGIOwsdAOOpNRQDomof9QpRlHD TDMLelkKbuQLFk0YK7ulxGrYqaPYsE1E8HlZ3WJg9m1cbaByofSi7kALxx2GGg7QpbnY BfPUt+ipb5PxVuuirWhOWZMeVXUKwe5KLfQ28ww6dXNRJYySEoRxDk5SKlG9tKVumIWu XlRe38wYAleVujyNoaDAnSNookoBjEMzPPJx9e/kloM5/rQ4bI56hVES+upxOkOttNUb 8A7g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n1-20020a05640206c100b0051e33b5ee68si6752533edy.250.2023.07.13.00.22.55; Thu, 13 Jul 2023 00:23:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229890AbjGMHPf (ORCPT + 99 others); Thu, 13 Jul 2023 03:15:35 -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: 8bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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/pgtable.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 = pte_mkdirty(pte); + pte = set_pte_bit(pte, __pgprot(PTE_DIRTY)); pte = clear_pte_bit(pte, __pgprot(PTE_WRITE)); pte = set_pte_bit(pte, __pgprot(PTE_RDONLY)); @@ -823,7 +823,8 @@ static inline pte_t pte_modify(pte_t pte, pgprot_t newprot) PTE_ATTRINDX_MASK; /* preserve the hardware dirty information */ if (pte_hw_dirty(pte)) - pte = pte_mkdirty(pte); + pte = set_pte_bit(pte, __pgprot(PTE_DIRTY)); + pte_val(pte) = (pte_val(pte) & ~mask) | (pgprot_val(newprot) & mask); return pte; } -- 2.30.2