Re: [PATCH v4 3/6] KVM: arm64: Add auto DBM support for hardware dirty tracking

From: Marc Zyngier

Date: Tue Jul 14 2026 - 03:23:34 EST


On Tue, 14 Jul 2026 02:14:45 +0100,
Tian Zheng <zhengtian10@xxxxxxxxxx> wrote:
>
>
> On 7/13/2026 7:17 PM, Leonardo Bras wrote:
> > On Thu, Jul 09, 2026 at 06:40:23PM +0800, Tian Zheng wrote:
> >> The DBM (Dirty Bit Modifier) attribute, introduced in ARMv8.1, enables
> >> hardware to automatically promote write-clean pages to write-dirty. This
> >> prevents the guest from being trapped in EL2 due to missing write
> >> permissions.
> >>
> >> In this design, DBM is controlled by the page-table level flag
> >> KVM_PGTABLE_S2_DBM rather than per-PTE software flags. DBM is
> >> automatically set for writable non-device pages when the page-table has
> >> KVM_PGTABLE_S2_DBM flag, which is determined at MMU init time based on
> >> hardware capability.
> >>
> >> The DBM bit is set in stage2_set_prot_attr() for initial mappings and
> >> hugepage splitting, and directly manipulated in
> >> kvm_pgtable_stage2_relax_perms() when removing write-protection. On
> >> W->RO downgrade, DBM is cleared to prevent hardware from silently
> >> upgrading RO+DBM back to W+dirty, which would bypass KVM's write
> >> tracking.
> >>
> >> kvm_pgtable_stage2_pte_prot() does not extract the DBM bit back into
> >> enum kvm_pgtable_prot because DBM is a page-table policy determined by
> >> pgt->flags, not a per-PTE property. Callers should check
> >> pgt->flags & KVM_PGTABLE_S2_DBM instead.
> >>
> >> This ensures DBM is consistently applied across all PTEs, including
> >> during hugepage splitting where child PTEs inherit DBM from the parent
> >> block entry via the pgt->flags mechanism.
> >>
> >> Safety: DBM bit is only interpreted by hardware when VTCR_EL2.HD=1.
> >> When HDBSS is not enabled (HD=0), ARM architecture guarantees hardware
> >> completely ignores DBM bit in PTEs.
> >>
> >> Co-developed-by: Eillon <yezhenyu2@xxxxxxxxxx>
> >> Signed-off-by: Eillon <yezhenyu2@xxxxxxxxxx>
> >> Co-developed-by: Leonardo Bras <leo.bras@xxxxxxx>
> >> Signed-off-by: Leonardo Bras <leo.bras@xxxxxxx>
> > Hello Tian,
> >
> > Have you added the above tags due to this patch being based on the below?
> > https://lore.kernel.org/all/20260629111820.1873540-2-leo.bras@xxxxxxx/
> >
> > Thanks!
> > Leo
>
> Hi Leo,
>
>
> Yes, I added your Signed-off-by because the DBM-related code in this patch

You really can't do that. Only Leo can give his SoB, you can't forge
it yourself.

>
> is based on your implementation in:
>
> https://lore.kernel.org/all/20260629111820.1873540-2-leo.bras@xxxxxxx/

Then take the patch as is, and add to it as a separate patch. Or work
out in private with Leo whether he's happy with a Co-dev. But never do
that unilaterally.

Thanks,

M.

--
Without deviation from the norm, progress is not possible.