Message ID | 20230707053331.510041-1-anshuman.khandual@arm.com |
---|---|
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9f45:0:b0:3ea:f831:8777 with SMTP id v5csp3039602vqx; Thu, 6 Jul 2023 22:37:13 -0700 (PDT) X-Google-Smtp-Source: APBJJlG1nXjNFNriWSK5lYILoe12WWXfVKGlzSXeV5F3DNWUiZynPZZSMdpfSmUuuk391KIjevq7 X-Received: by 2002:a05:6358:2609:b0:134:c37f:4b60 with SMTP id l9-20020a056358260900b00134c37f4b60mr4305424rwc.32.1688708232977; Thu, 06 Jul 2023 22:37:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688708232; cv=none; d=google.com; s=arc-20160816; b=v4CCIhL/cJ9Iorf4TlSL7v4mTzhtyZ84CFjk/eYpZ9wqCnxgnuQWGqXryZYA4rZ1Bf W+wXpjFF0rN1jTHodCapDoMiCKiRYlNj4bz7O4uCbgjpwvfV0V4ijjkSz9liVD+GzElT nDKIyGXQsudr2fx1jMboybdqGGoVjp9ShYiBM9ZWGsBrVjlfzh1nH56sGc5be7fKPjeE mLanmKhxWgaXgQPZhYh4NpQ+GPAFaxmTro7EWyBwMEBGlQQntHiY7H/hxRHUls+qH+dU A0tAt+sCcZ2V0jM0izhXQXM/6+cwUJNfZ7lnqdkUoKdp8xJTzsXk3Z531zitZH1FA2CE LsLg== 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=Ila06ZoIudNWB24oRchymB+LfcgWr1qsLdSzszmFK/k=; fh=v8WkW07D8QHzh6geYHFbL/t66J83/bx/yAuOgJXvUtg=; b=E2H32ld8h7eERxL5lbAIMTUbB/LsLI3ldOXdL2aw7feqKqgkbPZ8zQiRVOhg4/SnrD baKK8vNnynlnlWuUfxufU/7NG8yFqWdrGqTQMf73+XbaTBAPWfDmzxpSokFYpIncj9v8 VMD3E2WOleExuhwzLpWB92P8Wq4ChXzO1xaHzeNTFtHylISekvWpAHLj/jrWRC7bkCvI cdADnqNnK3/YzZ65ZoGEajt8vlbTJtUV6FguCjykicpbH2QLIYmYs2/b0F8MlCfIRsLw K+bsbZ3frgQqJ2hTsFiVcoJmnCIE8QtY+AYJscQLnqdjXD6y+ClgUOqve6eF9XR/vZYL P6JQ== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n7-20020a6543c7000000b0053b8874ceddsi1140615pgp.148.2023.07.06.22.37.00; Thu, 06 Jul 2023 22:37:12 -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 S230022AbjGGFds (ORCPT <rfc822;hadasmailinglist@gmail.com> + 99 others); Fri, 7 Jul 2023 01:33:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47298 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229529AbjGGFdq (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Fri, 7 Jul 2023 01:33:46 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 86EBA171D; Thu, 6 Jul 2023 22:33:44 -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 DE846D75; Thu, 6 Jul 2023 22:34:25 -0700 (PDT) Received: from a077893.arm.com (unknown [10.163.48.50]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 2B8CE3F740; Thu, 6 Jul 2023 22:33:38 -0700 (PDT) From: Anshuman Khandual <anshuman.khandual@arm.com> To: linux-arm-kernel@lists.infradead.org Cc: Anshuman Khandual <anshuman.khandual@arm.com>, Catalin Marinas <catalin.marinas@arm.com>, Will Deacon <will@kernel.org>, Ryan Roberts <ryan.roberts@arm.com>, Mark Rutland <mark.rutland@arm.com>, Andrew Morton <akpm@linux-foundation.org>, David Hildenbrand <david@redhat.com>, Jonathan Corbet <corbet@lwn.net>, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org Subject: [RFC 0/4] arm64/mm: Clean up pte_dirty() state management Date: Fri, 7 Jul 2023 11:03:27 +0530 Message-Id: <20230707053331.510041-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=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, 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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1770738923964447983?= X-GMAIL-MSGID: =?utf-8?q?1770738923964447983?= |
Series |
arm64/mm: Clean up pte_dirty() state management
|
|
Message
Anshuman Khandual
July 7, 2023, 5:33 a.m. UTC
These pte_dirty() changes make things explicitly clear, while improving the code readability. This optimizes HW dirty state transfer into SW dirty bit. This also adds a new arm64 documentation explaining overall pte dirty state management in detail. This series applies on the latest mainline kernel. Cc: Catalin Marinas <catalin.marinas@arm.com> Cc: Will Deacon <will@kernel.org> Cc: Ryan Roberts <ryan.roberts@arm.com> Cc: Mark Rutland <mark.rutland@arm.com> Cc: Andrew Morton <akpm@linux-foundation.org> Cc: David Hildenbrand <david@redhat.com> Cc: Jonathan Corbet <corbet@lwn.net> Cc: linux-arm-kernel@lists.infradead.org Cc: linux-kernel@vger.kernel.org Cc: linux-doc@vger.kernel.org Anshuman Khandual (4): arm64/mm: Add SW and HW dirty state helpers arm64/mm: Call pte_sw_mkdirty() while preserving the HW dirty state arm64/mm: Add pte_preserve_hw_dirty() docs: arm64: Add help document for pte dirty state management Documentation/arch/arm64/index.rst | 1 + Documentation/arch/arm64/pte-dirty.rst | 95 ++++++++++++++++++++++++++ arch/arm64/include/asm/pgtable.h | 66 ++++++++++++++---- 3 files changed, 147 insertions(+), 15 deletions(-) create mode 100644 Documentation/arch/arm64/pte-dirty.rst
Comments
On 07.07.23 07:33, Anshuman Khandual wrote: > These pte_dirty() changes make things explicitly clear, while improving the > code readability. This optimizes HW dirty state transfer into SW dirty bit. > This also adds a new arm64 documentation explaining overall pte dirty state > management in detail. This series applies on the latest mainline kernel. > > I skimmed over most of the series, and I am not convinced that this is actually a cleanup. If we cannot really always differentiate between sw/hw clearing, why have separate primitives that give one the illusion that it could be done and that they are two different concepts? Maybe there are other opinions, but at least for me this made the code harder to grasp. I do appreciate a doc update, though :)
On 7/7/23 17:41, David Hildenbrand wrote: > On 07.07.23 07:33, Anshuman Khandual wrote: >> These pte_dirty() changes make things explicitly clear, while improving the >> code readability. This optimizes HW dirty state transfer into SW dirty bit. >> This also adds a new arm64 documentation explaining overall pte dirty state >> management in detail. This series applies on the latest mainline kernel. >> >> > > I skimmed over most of the series, and I am not convinced that this is actually a cleanup. If we cannot really always differentiate between sw/hw clearing, why have separate primitives that give one the illusion that it could be done and that they are two different concepts? These are indeed two different concepts working together, the current code just obscures that. Without these primitives it's even hard to follow how the SW and HW dirty parts are intertwined in implementing the generic pte_dirty() state. The current code acknowledges these two different concepts in identifying them i.e via pte_hw_dirty() and pte_sw_dirty(). #define pte_hw_dirty(pte) (pte_write(pte) && !(pte_val(pte) & PTE_RDONLY)) #define pte_sw_dirty(pte) (!!(pte_val(pte) & PTE_DIRTY)) But then falls short in demonstrating how these two states are being managed i.e created and cleared. The first patch tries to clear the situation to some extent. > > Maybe there are other opinions, but at least for me this made the code harder to grasp. > > I do appreciate a doc update, though :) These two changes also streamline HW dirty bit saving in SW dirty bit efficiently, skipping the re-doing of HW dirty bits setting which might be cleared off. That is the primary reason for saving it off in SW dirty bit in the first place. arm64/mm: Call pte_sw_mkdirty() while preserving the HW dirty state arm64/mm: Add pte_preserve_hw_dirty( Regardless, I am still trying to understand how the first patch does not improve the clarity in modifying the PTE dirty state.
On 10.07.23 04:20, Anshuman Khandual wrote: > > > On 7/7/23 17:41, David Hildenbrand wrote: >> On 07.07.23 07:33, Anshuman Khandual wrote: >>> These pte_dirty() changes make things explicitly clear, while improving the >>> code readability. This optimizes HW dirty state transfer into SW dirty bit. >>> This also adds a new arm64 documentation explaining overall pte dirty state >>> management in detail. This series applies on the latest mainline kernel. >>> >>> >> >> I skimmed over most of the series, and I am not convinced that this is actually a cleanup. If we cannot really always differentiate between sw/hw clearing, why have separate primitives that give one the illusion that it could be done and that they are two different concepts? > > These are indeed two different concepts working together, the current code just > obscures that. Without these primitives it's even hard to follow how the SW and > HW dirty parts are intertwined in implementing the generic pte_dirty() state. > > The current code acknowledges these two different concepts in identifying them > i.e via pte_hw_dirty() and pte_sw_dirty(). > > #define pte_hw_dirty(pte) (pte_write(pte) && !(pte_val(pte) & PTE_RDONLY)) > #define pte_sw_dirty(pte) (!!(pte_val(pte) & PTE_DIRTY)) > ^ these primitives make sense to me, but not the clearing part. If there is only one way to clear both, then only have one primitive to clear both and state there, that separate clearing is impossible because both are intertwined.
On Fri, Jul 07, 2023 at 11:03:27AM +0530, Anshuman Khandual wrote: > These pte_dirty() changes make things explicitly clear, while improving the > code readability. This optimizes HW dirty state transfer into SW dirty bit. > This also adds a new arm64 documentation explaining overall pte dirty state > management in detail. This series applies on the latest mainline kernel. TBH, I think this is all swings and roundabouts, and I'm not sure this is worthwhile. I appreciate that as-is some people find this confusing, but I don't think the end result of this series is actually better, and it adds more code/documentation to maintain. In particular, I don't think that we should add Documentation/ files for this, as it's very likely that won't be updated together with the code, and I think it's more of a maintenance burden than a help. If we want some introductory text to explain how the HW/SW dirty bits work, I think that should be a comment block in <asm/pgtable.h>, clearly associated with the code. Overall, I'd prefer to leave the code as-is. Thanks, Mark. > > Cc: Catalin Marinas <catalin.marinas@arm.com> > Cc: Will Deacon <will@kernel.org> > Cc: Ryan Roberts <ryan.roberts@arm.com> > Cc: Mark Rutland <mark.rutland@arm.com> > Cc: Andrew Morton <akpm@linux-foundation.org> > Cc: David Hildenbrand <david@redhat.com> > Cc: Jonathan Corbet <corbet@lwn.net> > Cc: linux-arm-kernel@lists.infradead.org > Cc: linux-kernel@vger.kernel.org > Cc: linux-doc@vger.kernel.org > > Anshuman Khandual (4): > arm64/mm: Add SW and HW dirty state helpers > arm64/mm: Call pte_sw_mkdirty() while preserving the HW dirty state > arm64/mm: Add pte_preserve_hw_dirty() > docs: arm64: Add help document for pte dirty state management > > Documentation/arch/arm64/index.rst | 1 + > Documentation/arch/arm64/pte-dirty.rst | 95 ++++++++++++++++++++++++++ > arch/arm64/include/asm/pgtable.h | 66 ++++++++++++++---- > 3 files changed, 147 insertions(+), 15 deletions(-) > create mode 100644 Documentation/arch/arm64/pte-dirty.rst > > -- > 2.30.2 >
On 7/10/23 16:55, Mark Rutland wrote: > On Fri, Jul 07, 2023 at 11:03:27AM +0530, Anshuman Khandual wrote: >> These pte_dirty() changes make things explicitly clear, while improving the >> code readability. This optimizes HW dirty state transfer into SW dirty bit. >> This also adds a new arm64 documentation explaining overall pte dirty state >> management in detail. This series applies on the latest mainline kernel. > TBH, I think this is all swings and roundabouts, and I'm not sure this is > worthwhile. I appreciate that as-is some people find this confusing, but I Current situation for pte_dirty() management is confusing when there are two distinct mechanisms to track PTE dirty states, but both are forced to work together because - HW DBM cannot track non-writable dirty state (PTE_DBM == PTE_WRITE) - Runtime check for HW DBM is avoided > don't think the end result of this series is actually better, and it adds more > code/documentation to maintain. Agreed, it does add more code and documentation but still trying to understand why it is not worthwhile. Regardless, following patch does optimize a situation where we dont need to call pte_mkdirty() knowing it will be cleared afterwards. [RFC 2/4] arm64/mm: Call pte_sw_mkdirty() while preserving the HW dirty state > > In particular, I don't think that we should add Documentation/ files for this, > as it's very likely that won't be updated together with the code, and I think > it's more of a maintenance burden than a help. If we want some introductory There are many documentation files such as Documentation/arm64/memory.rst which needs to be updated when kernel virtual address layout changes again. I am just wondering - should not there be any documentation for internal implementation details, just because they need updating with code changes. > text to explain how the HW/SW dirty bits work, I think that should be a comment > block in <asm/pgtable.h>, clearly associated with the code. Sure, will add that. > > Overall, I'd prefer to leave the code as-is. Even if we discount individual dirty clearing functions, why should not HW dirty bit transfer to SW dirty be optimized and wrapped around in a helper.
On Wed, Jul 12, 2023 at 09:31:39AM +0530, Anshuman Khandual wrote: > On 7/10/23 16:55, Mark Rutland wrote: > > On Fri, Jul 07, 2023 at 11:03:27AM +0530, Anshuman Khandual wrote: > >> These pte_dirty() changes make things explicitly clear, while improving the > >> code readability. This optimizes HW dirty state transfer into SW dirty bit. > >> This also adds a new arm64 documentation explaining overall pte dirty state > >> management in detail. This series applies on the latest mainline kernel. > > > > TBH, I think this is all swings and roundabouts, and I'm not sure this is > > worthwhile. I appreciate that as-is some people find this confusing, but I I'm pretty much on the same lines, though maybe I looked too much at this code that I don't like any further changes to it ;). > Current situation for pte_dirty() management is confusing when there are two > distinct mechanisms to track PTE dirty states, but both are forced to work > together because > > - HW DBM cannot track non-writable dirty state (PTE_DBM == PTE_WRITE) > - Runtime check for HW DBM is avoided Depending on how you look at it, we can say that any writeable PTE (as in page table permission, PTE_RDONLY cleared) is dirty and we only have a software mechanism for tracking the dirty state. The DBM feature is not actually giving us a dirty bit but an automated way to make a PTE writeable on access (for some historical reasons like the SMMU not having such mechanism in place). Maybe we can clean the code a bit based on the above perspective. E.g. instead of pte_hw_dirty() just have a !pte_hw_rdonly() macro. It may help with the confusion of having two mechanisms. OTOH, with PIE, we can have a true dirty bit but at that point we can eliminate the pte_sw_dirty() use entirely and allow soft-dirty using the current PTE_DIRTY (with some static labels based on the feature). > > don't think the end result of this series is actually better, and it adds more > > code/documentation to maintain. > > Agreed, it does add more code and documentation but still trying to understand > why it is not worthwhile. Regardless, following patch does optimize a situation > where we dont need to call pte_mkdirty() knowing it will be cleared afterwards. > > [RFC 2/4] arm64/mm: Call pte_sw_mkdirty() while preserving the HW dirty state I wonder whether the compiler eliminates much of this duplication since there are some checks for pte_write() before. We may be able to remove some checks. For example, does pte_hw_dirty() actually need to check pte_write()? A !PTE_RDONLY entry is dirty automatically since we can't trap any write access to it (prior to PIE; I need to check Joey's patches on how it treats writeable+clean PTEs; still on holiday). As for the fourth patch, I'd rather add documentation in the header file, it's more likely to be looked at and updated.