From: Leonardo Bras <leo.bras@arm.com>
To: Tian Zheng <zhengtian10@huawei.com>
Cc: Leonardo Bras <leo.bras@arm.com>,
sashiko-reviews@lists.linux.dev, kvmarm@lists.linux.dev,
kvm@vger.kernel.org, Marc Zyngier <maz@kernel.org>,
Oliver Upton <oupton@kernel.org>,
liuyonglong <liuyonglong@huawei.com>
Subject: Re: [PATCH v5 11/15] KVM: arm64: Reserve dirty ring space for the HDBSS buffer
Date: Mon, 9 Nov 2026 18:07:17 +0000 [thread overview]
Message-ID: <avIL1UFsFmQFXwew@LeoBrasDK> (raw)
In-Reply-To: <494abfd0-b19b-4ef3-a035-d21626828a6a@huawei.com>
On Mon, Nov 09, 2026 at 06:03:03PM +0800, Tian Zheng wrote:
>
>
> On 9/29/2026 7:00 PM, sashiko-bot@kernel.org wrote:
> > Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
> > - [High] arm64: kvm: UAPI breakage for dirty ring size on 64KB page systems
> > --
> >
> > commit 38dde0ab2f10c37402c620c7b1328624808205ad
> > Author: Tian Zheng <zhengtian10@huawei.com>
> >
> > KVM: arm64: Reserve dirty ring space for the HDBSS buffer
> >
> > This commit reserves space in the dirty ring for CPU-side dirty buffers by
> > implementing kvm_cpu_dirty_log_size(). It also pins the HDBSS buffer size to
> > PAGE_SIZE when the dirty ring is enabled.
> >
> > > diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c
> > > index 7bf82d65041c8..c1e09ba98d48a 100644
> > > --- a/arch/arm64/kvm/mmu.c
> > > +++ b/arch/arm64/kvm/mmu.c
> > [ ... ]
> > > @@ -2841,3 +2841,11 @@ void kvm_toggle_cache(struct kvm_vcpu *vcpu, bool was_enabled)
> > > trace_kvm_toggle_cache(*vcpu_pc(vcpu), was_enabled, now_enabled);
> > > }
> > > +
> > > +int kvm_cpu_dirty_log_size(struct kvm *kvm)
> > > +{
> > > + if (!system_supports_hdbss())
> > > + return 0;
> > > +
> > > + return kvm_hdbss_buffer_size(kvm) / sizeof(u64);
> > > +}
> >
> > [Severity: High]
> > Does this calculation break the UAPI for standard dirty ring size requests on
> > 64KB page systems?
> >
> > Since KVM_ARM_HDBSS_DEFAULT_SIZE is tied to PAGE_SIZE, this calculation scales
> > with the system page size. On a 64KB page system, kvm_hdbss_buffer_size() yields
> > 65536 bytes, returning 8192 reserved entries (65536 / 8).
> >
> > When a userspace process requests a standard dirty ring size of 65536 bytes
> > (64KB) via KVM_ENABLE_CAP for KVM_CAP_DIRTY_LOG_RING, it seems the ioctl will
> > now fail:
> >
> > virt/kvm/kvm_main.c:kvm_vm_ioctl_enable_cap() {
> > ...
> > if (size < kvm_dirty_ring_get_rsvd_entries(kvm) *
> > sizeof(struct kvm_dirty_gfn) || size < PAGE_SIZE)
> > return -EINVAL;
> > ...
> > }
> >
> > Because (8192 + 64) * 16 = 132096 bytes is greater than the requested 65536
> > bytes, the ioctl rejects previously valid userspace configurations with -EINVAL,
> > which would cause QEMU and other VMMs to fail to start VMs.
> >
> > Could this buffer size be decoupled from PAGE_SIZE to avoid the entry inflation
> > and ABI breakage on 64KB page systems?
> >
>
> You were right, this is a real UAPI break on 64KB-page kernels. The
> PAGE_SIZE default made the ring reservation scale with the kernel page
> size, so a standard 64KB ring request got rejected there.
>
> Leo, the PAGE_SIZE default goes back to your suggestion in the v4
> discussion at [1]:
>
> > That means 512 entries in 4kB pagesize, an 8K entries in 64kB
> pagesize.
>
> > I mean, yes, maybe we could allocate a 64k page, and set SZ=4K in
> HDBSSBR, but that would be a waste of memory, right?
>
> If we keep PAGE_SIZE, the ring ABI stays broken on larger-page kernels,
> since the reservation keeps scaling with the page size. With SZ_4K there
> is still some breakage, the smallest ring sizes (4KB and 8KB), but that
> is the smallest scope we can get, because 4KB is the smallest buffer the
> hardware can encode. Defaulting to SZ_4K also brings our ring
> requirements in line with x86, where PML reserves the same fixed 576
> entries.
>
> Do you think we should default to SZ_4K and accept the page waste you
> pointed out, or keep PAGE_SIZE?
>
Maybe we should rethink the way of handling this, and maybe reserved
entries is not the way out.
(It was for x86, but it's a very different architecture, as I mentioned
before)
Another approach could be to those reserved pages to not be counted in the
ring size limit, but that could become really messy.
Thanks!
Leo
next prev parent reply other threads:[~2026-11-09 18:07 UTC|newest]
Thread overview: 69+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-29 10:36 [PATCH v5 00/15] KVM: arm64: FEAT_HDBSS support for stage-2 dirty tracking Tian Zheng
2026-09-29 10:36 ` [PATCH v5 01/15] KVM: arm64: pgtables: Change write bit from S2AP_W to DBM Tian Zheng
2026-09-30 0:25 ` Oliver Upton
2026-09-30 2:44 ` Tian Zheng
2026-10-26 15:02 ` Leonardo Bras
2026-10-29 7:08 ` Tian Zheng
2026-09-29 10:36 ` [PATCH v5 02/15] KVM: arm64: Add KVM_PGTABLE_PROT_DIRTY Tian Zheng
2026-09-30 0:35 ` Oliver Upton
2026-09-30 2:57 ` Tian Zheng
2026-09-29 10:36 ` [PATCH v5 03/15] KVM: arm64: Introduce a dedicated walker for stage2 write-protect Tian Zheng
2026-09-29 10:36 ` [PATCH v5 04/15] KVM: arm64: Add KVM_REQ_RELOAD_STAGE2 Tian Zheng
2026-09-29 10:50 ` sashiko-bot
2026-09-30 1:44 ` Tian Zheng
2026-09-29 10:36 ` [PATCH v5 05/15] KVM: arm64: Harvest stage-2 dirty state into the host folio account Tian Zheng
2026-10-26 18:05 ` Leonardo Bras
2026-10-29 14:02 ` Tian Zheng
2026-10-30 12:24 ` Leonardo Bras
2026-11-06 3:16 ` Tian Zheng
2026-11-06 12:04 ` Leonardo Bras
2026-09-29 10:36 ` [PATCH v5 06/15] KVM: arm64: Add support for FEAT_HDBSS Tian Zheng
2026-10-26 18:12 ` Leonardo Bras
2026-10-30 2:53 ` Tian Zheng
2026-10-30 14:15 ` Leonardo Bras
2026-09-29 10:36 ` [PATCH v5 07/15] KVM: arm64: Add HDBSS per-vCPU buffer management Tian Zheng
2026-10-26 18:27 ` Leonardo Bras
2026-10-30 3:47 ` Tian Zheng
2026-10-30 14:47 ` Leonardo Bras
2026-11-06 8:49 ` Tian Zheng
2026-11-06 15:21 ` Leonardo Bras
2026-09-29 10:36 ` [PATCH v5 08/15] KVM: arm64: Flush the HDBSS buffer on VM exit Tian Zheng
2026-10-27 18:13 ` Leonardo Bras
2026-10-30 4:57 ` Tian Zheng
2026-10-30 16:52 ` Leonardo Bras
2026-11-06 9:02 ` Tian Zheng
2026-09-29 10:36 ` [PATCH v5 09/15] KVM: arm64: Handle HDBSS faults Tian Zheng
2026-09-29 10:53 ` sashiko-bot
2026-11-09 7:36 ` Tian Zheng
2026-11-02 14:34 ` Leonardo Bras
2026-11-06 9:44 ` Tian Zheng
2026-09-29 10:36 ` [PATCH v5 10/15] KVM: Add kvm_arch_dirty_ring_size_updated() hook Tian Zheng
2026-09-29 10:52 ` sashiko-bot
2026-11-09 6:37 ` Tian Zheng
2026-09-29 10:36 ` [PATCH v5 11/15] KVM: arm64: Reserve dirty ring space for the HDBSS buffer Tian Zheng
2026-09-29 11:00 ` sashiko-bot
2026-11-09 10:03 ` Tian Zheng
2026-11-09 18:07 ` Leonardo Bras [this message]
2026-11-02 14:54 ` Leonardo Bras
2026-11-06 10:36 ` Tian Zheng
2026-11-06 15:36 ` Leonardo Bras
2026-11-09 4:00 ` Tian Zheng
2026-11-09 18:18 ` Leonardo Bras
2026-11-10 8:54 ` Tian Zheng
2026-11-10 12:49 ` Leonardo Bras
2026-11-12 13:15 ` Tian Zheng
2026-11-12 15:26 ` Leonardo Bras
2026-11-06 10:58 ` Tian Zheng
2026-09-29 10:36 ` [PATCH v5 12/15] KVM: arm64: Derive the VM hardware dirty mode from dirty logging Tian Zheng
2026-09-29 11:16 ` sashiko-bot
2026-09-30 8:27 ` Tian Zheng
2026-11-02 15:03 ` Leonardo Bras
2026-11-06 10:46 ` Tian Zheng
2026-11-06 15:37 ` Leonardo Bras
2026-09-29 10:36 ` [PATCH v5 13/15] KVM: arm64: Add HDBSS buffer size ioctl for dirty-bitmap mode Tian Zheng
2026-11-02 15:12 ` Leonardo Bras
2026-11-06 10:27 ` Tian Zheng
2026-11-06 15:37 ` Leonardo Bras
2026-09-29 10:36 ` [PATCH v5 14/15] KVM: arm64: Document HDBSS buffer size ioctl Tian Zheng
2026-09-29 11:06 ` sashiko-bot
2026-09-29 10:36 ` [PATCH v5 15/15] KVM: arm64: selftests: Add HDBSS buffer size ioctl interface test Tian Zheng
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=avIL1UFsFmQFXwew@LeoBrasDK \
--to=leo.bras@arm.com \
--cc=kvm@vger.kernel.org \
--cc=kvmarm@lists.linux.dev \
--cc=liuyonglong@huawei.com \
--cc=maz@kernel.org \
--cc=oupton@kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=zhengtian10@huawei.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