From: Ard Biesheuvel <ardb@kernel.org>
Currently, pgattr_change_is_safe() is overly pedantic when it comes to
descriptors with the contiguous hint attribute set, as it rejects
assignments even if the old and the new value are the same.
So relax the check to allow that.
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
---
arch/arm64/mm/mmu.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/arch/arm64/mm/mmu.c b/arch/arm64/mm/mmu.c
index c36422a3fae2..9d39de3cfe67 100644
--- a/arch/arm64/mm/mmu.c
+++ b/arch/arm64/mm/mmu.c
@@ -141,7 +141,7 @@ bool pgattr_change_is_safe(pteval_t old, pteval_t new)
return false;
/* live contiguous mappings may not be manipulated at all */
- if ((old | new) & PTE_CONT)
+ if ((old | new) & PTE_CONT && old != new)
return false;
/* Transitioning from Non-Global to Global is unsafe */
--
2.52.0.457.g6b5491de43-goog
On 26/01/2026 09:26, Ard Biesheuvel wrote: > From: Ard Biesheuvel <ardb@kernel.org> > > Currently, pgattr_change_is_safe() is overly pedantic when it comes to > descriptors with the contiguous hint attribute set, as it rejects > assignments even if the old and the new value are the same. > > So relax the check to allow that. But why do we require the relaxation? Why are we re-writing a PTE in the first place? Either the caller already knows it's the same in which case it can be avoided, or it doesn't know in which case it is accidentally the same and couple probably just as easily been accidentally different? So it's better to warn regardless I would think? I'm sure I'll get to the patch where this matters and change my mind :) > > Signed-off-by: Ard Biesheuvel <ardb@kernel.org> > --- > arch/arm64/mm/mmu.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/arch/arm64/mm/mmu.c b/arch/arm64/mm/mmu.c > index c36422a3fae2..9d39de3cfe67 100644 > --- a/arch/arm64/mm/mmu.c > +++ b/arch/arm64/mm/mmu.c > @@ -141,7 +141,7 @@ bool pgattr_change_is_safe(pteval_t old, pteval_t new) > return false; > > /* live contiguous mappings may not be manipulated at all */ > - if ((old | new) & PTE_CONT) > + if ((old | new) & PTE_CONT && old != new) > return false; > > /* Transitioning from Non-Global to Global is unsafe */
On Tue, 27 Jan 2026 at 10:45, Ryan Roberts <ryan.roberts@arm.com> wrote: > > On 26/01/2026 09:26, Ard Biesheuvel wrote: > > From: Ard Biesheuvel <ardb@kernel.org> > > > > Currently, pgattr_change_is_safe() is overly pedantic when it comes to > > descriptors with the contiguous hint attribute set, as it rejects > > assignments even if the old and the new value are the same. > > > > So relax the check to allow that. > > But why do we require the relaxation? Why are we re-writing a PTE in the first > place? Either the caller already knows it's the same in which case it can be > avoided, or it doesn't know in which case it is accidentally the same and couple > probably just as easily been accidentally different? So it's better to warn > regardless I would think? > Based on rule RJQQTC in your reply to another patch in this series, my conclusion here is that we can drop this check entirely.
On 27/01/2026 15:03, Ard Biesheuvel wrote: > On Tue, 27 Jan 2026 at 10:45, Ryan Roberts <ryan.roberts@arm.com> wrote: >> >> On 26/01/2026 09:26, Ard Biesheuvel wrote: >>> From: Ard Biesheuvel <ardb@kernel.org> >>> >>> Currently, pgattr_change_is_safe() is overly pedantic when it comes to >>> descriptors with the contiguous hint attribute set, as it rejects >>> assignments even if the old and the new value are the same. >>> >>> So relax the check to allow that. >> >> But why do we require the relaxation? Why are we re-writing a PTE in the first >> place? Either the caller already knows it's the same in which case it can be >> avoided, or it doesn't know in which case it is accidentally the same and couple >> probably just as easily been accidentally different? So it's better to warn >> regardless I would think? >> > > Based on rule RJQQTC in your reply to another patch in this series, my > conclusion here is that we can drop this check entirely. Hmm, I don't think that would be quite right; The rule permits _some_ bits of the PTE to change in a live mapping as long as the CONT bit remains unchanged. If you change the CONT bit on a live mapping, you could end up with overlapping TLB entries which would not go well on a system without bbml2.
On Tue, 27 Jan 2026, at 17:59, Ryan Roberts wrote: > On 27/01/2026 15:03, Ard Biesheuvel wrote: >> On Tue, 27 Jan 2026 at 10:45, Ryan Roberts <ryan.roberts@arm.com> wrote: >>> >>> On 26/01/2026 09:26, Ard Biesheuvel wrote: >>>> From: Ard Biesheuvel <ardb@kernel.org> >>>> >>>> Currently, pgattr_change_is_safe() is overly pedantic when it comes to >>>> descriptors with the contiguous hint attribute set, as it rejects >>>> assignments even if the old and the new value are the same. >>>> >>>> So relax the check to allow that. >>> >>> But why do we require the relaxation? Why are we re-writing a PTE in the first >>> place? Either the caller already knows it's the same in which case it can be >>> avoided, or it doesn't know in which case it is accidentally the same and couple >>> probably just as easily been accidentally different? So it's better to warn >>> regardless I would think? >>> >> >> Based on rule RJQQTC in your reply to another patch in this series, my >> conclusion here is that we can drop this check entirely. > > Hmm, I don't think that would be quite right; The rule permits _some_ bits of > the PTE to change in a live mapping as long as the CONT bit remains unchanged. > If you change the CONT bit on a live mapping, you could end up with overlapping > TLB entries which would not go well on a system without bbml2. I'm not suggesting we add it to 'mask', just to remove the check that forbids any manipulation of an entry that has PTE_CONT set. So toggling PTE_CONT itself would still be caught by the check.
On 27/01/2026 17:02, Ard Biesheuvel wrote: > > > On Tue, 27 Jan 2026, at 17:59, Ryan Roberts wrote: >> On 27/01/2026 15:03, Ard Biesheuvel wrote: >>> On Tue, 27 Jan 2026 at 10:45, Ryan Roberts <ryan.roberts@arm.com> wrote: >>>> >>>> On 26/01/2026 09:26, Ard Biesheuvel wrote: >>>>> From: Ard Biesheuvel <ardb@kernel.org> >>>>> >>>>> Currently, pgattr_change_is_safe() is overly pedantic when it comes to >>>>> descriptors with the contiguous hint attribute set, as it rejects >>>>> assignments even if the old and the new value are the same. >>>>> >>>>> So relax the check to allow that. >>>> >>>> But why do we require the relaxation? Why are we re-writing a PTE in the first >>>> place? Either the caller already knows it's the same in which case it can be >>>> avoided, or it doesn't know in which case it is accidentally the same and couple >>>> probably just as easily been accidentally different? So it's better to warn >>>> regardless I would think? >>>> >>> >>> Based on rule RJQQTC in your reply to another patch in this series, my >>> conclusion here is that we can drop this check entirely. >> >> Hmm, I don't think that would be quite right; The rule permits _some_ bits of >> the PTE to change in a live mapping as long as the CONT bit remains unchanged. >> If you change the CONT bit on a live mapping, you could end up with overlapping >> TLB entries which would not go well on a system without bbml2. > > I'm not suggesting we add it to 'mask', just to remove the check that forbids any manipulation of an entry that has PTE_CONT set. So toggling PTE_CONT itself would still be caught by the check. Ahh, sorry, wasn't looking at the whole function. Yes,I agree that makes sense then. Now that I'm looking at the function, I find it odd that PTE_UXN and PTE_USER are not included in the mask. These bits are used (along with PTE_PXN and PTE_WRITE, which are in the mask) to form the PI index, when PI is enabled. Seems odd that we can change some bits of the index but not others... But that is probably for another day.
© 2016 - 2026 Red Hat, Inc.