Linux-mm Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Muchun Song <muchun.song@linux.dev>
To: James Houghton <jthoughton@google.com>
Cc: Will Deacon <will@kernel.org>,
	Catalin Marinas <catalin.marinas@arm.com>,
	Oscar Salvador <osalvador@suse.de>,
	Nikos Nikoleris <nikos.nikoleris@arm.com>,
	Linu Cherian <linu.cherian@arm.com>,
	Mark Rutland <mark.rutland@arm.com>,
	David Hildenbrand <david@kernel.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	Ryan Roberts <ryan.roberts@arm.com>,
	Nanyong Sun <sunnanyong@huawei.com>, Yu Zhao <yuzhao@google.com>,
	Frank van der Linden <fvdl@google.com>,
	David Rientjes <rientjes@google.com>,
	linux-kernel@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org
Subject: Re: [PATCH 00/18] Another attempt at HVO support on arm64
Date: Mon, 13 Jul 2026 15:41:35 +0800	[thread overview]
Message-ID: <9C56FB0F-AE0E-4975-9D89-AFF110433C49@linux.dev> (raw)
In-Reply-To: <CADrL8HXNoRA_cnR7KVPwN6zA32E744OKOfTmDMReoykzR39H8Q@mail.gmail.com>



> On Jul 13, 2026, at 12:59, James Houghton <jthoughton@google.com> wrote:
> 
> On Thu, Jul 9, 2026 at 9:59 PM Muchun Song <muchun.song@linux.dev> wrote:
>>> On Jul 8, 2026, at 11:11, James Houghton <jthoughton@google.com> wrote:
>>> 
>>> Hi everyone,
>>> 
>>> This patch series uses a trick with the Access Flag on CPUs that support
>>> hardware update of the AF to update vmemmap page table entries without
>>> introducing a time window where CPUs accessing the vmemmap might fault.
>> 
>> Hi James,
>> 
>> I was just looking into the Arm ARM specification regarding the TLB caching
>> behavior to better understand the "AF trick" used here, and came across a few
>> sections that got me a bit confused.
>> 
>> Specifically, Section D8.5.1 [1] states Rule RDWZCQ:
>> 
>>        "Descriptors with AF set to zero can never be cached in a TLB. For more
>>         information about when translation table entries are permitted to be
>>         cached in a TLB, see Translation Lookaside Buffers."
>> 
>> This indeed seems to support the core assumption of the AF trick. However, when
>> following the reference to Section D8.16 "Translation Lookaside Buffers" [2], it
>> defines the following rule for permitted caching (RSQBCS):
>> 
>>        "When address translation is enabled, a translation table entry for an
>>         in-context translation regime that does not cause a Translation fault,
>>         an Address size fault, or an Access flag fault is permitted to be cached
>>         in a TLB or intermediate TLB caching structure as the result of an
>>         explicit or speculative access."
>> 
>> This is exactly where my confusion lies, as these two descriptions in the spec
>> feel directly contradictory when FEAT_HAF(hardware management of the Access flag)
>> is enabled.
> 
> I don't think it intends to say that "translation table entries with
> AF=0 may be cached" just because they don't cause Access flag faults.
> 
> It is likely that this clause was written before FEAT_HAFDBS/FEAT_HAF
> existed. Re-reading it with that in mind makes the meaning clearer:
> PTEs with AF=1 may be cached if the architecture otherwise allows it.
> 
> There is another clause, in D8.5 "Hardware updates of the translation
> tables", I_RGQLZ: "If hardware does not update the AF from 0 to 1,
> then the descriptor is not permitted to be cached in a TLB." I think
> this supports my interpretation.
> 
> I am convinced that it is impossible for an implementation not to
> conform to Rule R_DWZCQ (PTEs with AF=0 cannot be cached) while
> supporting HW AF correctly. Let me try to explain why.
> 
> For HW AF to function correctly:
> 1. Setting AF=1 must be done atomically, otherwise hardware could set
> a bit in an invalid PTE. (This would break Linux swp_entrys.)
> 2. The AF=0 translation cannot be used, otherwise we could
> potentially drop AF updates.
> 
> If an implementation used the translation before coherently setting
> AF=1 to perform an architectural memory access, then it must choose
> either to set AF=1 on a PTE that may have since changed (perhaps to an
> invalid PTE) or drop the AF update entirely. Either way HW AF is
> broken.
> 
> Please also see I_GXGPN: "When the translation of an architecturally
> executed memory access occurs, the architecture requires that AF is
> set to 1."

Thanks for your excellent explanation.

> 
>> On one hand, Section D8.5.1 [1] explicitly uses the word "never" for AF=0
>> descriptors. On the other hand, under FEAT_HAF, an entry with AF=0 does not cause
>> an Access flag fault anymore, because the hardware is capable of updating the AF
>> automatically. This technically makes it eligible for speculative caching under
>> Rule RSQBCS in Section D8.16 [2].
>> 
>> My question is: which part of the spec reflects the actual architectural intent
>> when FEAT_HAF is enabled? Is an entry with AF=0 permitted to be speculatively
>> cached in the TLB by the hardware under FEAT_HAF, or does the "never" in RDWZCQ
>> still hold absolute priority?
>> 
>> Please let me know if I have misread the specification or missed some overriding
>> constraints here.
> 
> Thanks for making me look a little harder into this; it's a good
> question. I hope my reply above makes you more comfortable with the AF

At least to me, what you're saying makes sense.

> trick. I also hope to hear more from the Arm folks as well.

Yes, it would be best to have an ARM expert here to confirm that our
understanding of the manual is completely accurate.

Thanks.

> 
> Thanks Muchun!




  reply	other threads:[~2026-07-13  7:42 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-08  3:11 [PATCH 00/18] Another attempt at HVO support on arm64 James Houghton
2026-07-08  3:11 ` [PATCH 01/18] hugetlb_vmemmap: Always flush TLB if needed upon PTE remapping James Houghton
2026-07-08  3:11 ` [PATCH 02/18] hugetlb_vmemmap: Move vmemmap_get_tail up James Houghton
2026-07-08  3:11 ` [PATCH 03/18] hugetlb_vmemmap: Leave pages partially HVOed upon restore failure James Houghton
2026-07-08  3:11 ` [PATCH 04/18] hugetlb_vmemmap: Use try_update_vmemmap_pte to update in-use PTEs James Houghton
2026-07-08  3:11 ` [PATCH 05/18] hugetlb_vmemmap: Allow architectures not to allow HVO at runtime James Houghton
2026-07-08  3:11 ` [PATCH 06/18] arm64: Rename cpu_has_hw_af to system_has_hw_af James Houghton
2026-07-08  3:11 ` [PATCH 07/18] arm64: Add system_supports_hvo James Houghton
2026-07-08  3:11 ` [PATCH 08/18] arm64: Implement try_update_vmemmap_pte using the AF trick James Houghton
2026-07-08  3:11 ` [PATCH 09/18] arm64: Prevent HVO if the HVO system feature is not enabled James Houghton
2026-07-08  3:11 ` [PATCH 10/18] arm64: Support hugetlb vmemmap optimization James Houghton
2026-07-08  3:11 ` [PATCH 11/18] hugetlb_vmemmap: Use try_populate_vmemmap_pmd for replacing in-use PMDs James Houghton
2026-07-08  3:11 ` [PATCH 12/18] arm64: Implement try_populate_vmemmap_pmd using AF trick James Houghton
2026-07-08  3:11 ` [PATCH 13/18] arm64: Drop BBML2_NOABORT requirement for HVO James Houghton
2026-07-08  3:11 ` [PATCH 14/18] hugetlb_vmemmap: Rename mm/hugetlb_vmemmap.h to mm/hugetlb_vmemmap_internal.h James Houghton
2026-07-08  3:11 ` [PATCH 15/18] hugetlb_vmemmap: Add a way to permanently disable HVO when needed James Houghton
2026-07-08  3:11 ` [PATCH 16/18] arm64: Allow "optional" CPU features to be required sometimes James Houghton
2026-07-08  3:11 ` [PATCH 17/18] arm64: Permit onlining of HVO-incompatible late CPUs if HVO is not in use James Houghton
2026-07-08  3:11 ` [PATCH 18/18] arm64: Remove user-selectable HVO Kconfig James Houghton
2026-07-08  8:40 ` [PATCH 00/18] Another attempt at HVO support on arm64 Muchun Song
2026-07-08 16:49   ` James Houghton
2026-07-09  9:54     ` Muchun Song
2026-07-09 19:04       ` James Houghton
2026-07-10  3:40         ` Muchun Song
2026-07-13  4:09           ` James Houghton
2026-07-11  2:22         ` Muchun Song
2026-07-13  4:09           ` James Houghton
2026-07-09  9:58 ` David Hildenbrand (Arm)
2026-07-10  4:58 ` Muchun Song
2026-07-13  4:59   ` James Houghton
2026-07-13  7:41     ` Muchun Song [this message]
2026-07-13 11:26       ` Dev Jain

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=9C56FB0F-AE0E-4975-9D89-AFF110433C49@linux.dev \
    --to=muchun.song@linux.dev \
    --cc=akpm@linux-foundation.org \
    --cc=catalin.marinas@arm.com \
    --cc=david@kernel.org \
    --cc=fvdl@google.com \
    --cc=jthoughton@google.com \
    --cc=linu.cherian@arm.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mark.rutland@arm.com \
    --cc=nikos.nikoleris@arm.com \
    --cc=osalvador@suse.de \
    --cc=rientjes@google.com \
    --cc=ryan.roberts@arm.com \
    --cc=sunnanyong@huawei.com \
    --cc=will@kernel.org \
    --cc=yuzhao@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox