[PATCH v5 13/15] KVM: arm64: Add HDBSS buffer size ioctl for dirty-bitmap mode

Leonardo Bras leo.bras at arm.com
Mon Nov 2 07:12:04 PST 2026


On Tue, Sep 29, 2026 at 06:36:53PM +0800, Tian Zheng wrote:
> In dirty-bitmap mode, a larger HDBSS buffer lets the guest dirty more
> pages between VM exits, at the cost of memory. The default of one page
> per vCPU is a reasonable starting point, so allow userspace to opt
> into a larger buffer via KVM_CAP_ARM_HDBSS_BUFFER_SIZE.
> 
> The size is specified in bytes through KVM_ENABLE_CAP and must be a
> power of two in [PAGE_SIZE, SZ_2M]: the upper bound is the largest
> HDBSSBR_EL2.SZ encoding, and the power-of-two requirement matches the
> buddy allocator. It must be set before any vCPU is created: -EINVAL
> after vCPUs exist, -EBUSY if already set.
> 
> The capability is rejected in dirty-ring mode, where the size is
> pinned by kvm_arch_dirty_ring_size_updated().
> 
> KVM_CHECK_EXTENSION returns the configured size for a VM, or SZ_2M
> when queried globally with a NULL kvm.
> 
> Signed-off-by: Tian Zheng <zhengtian10 at huawei.com>
> ---
>  arch/arm64/kvm/arm.c     | 34 ++++++++++++++++++++++++++++++++++
>  include/uapi/linux/kvm.h |  1 +
>  2 files changed, 35 insertions(+)
> 
> diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c
> index 5a7046acb62e..eadbf3a88d31 100644
> --- a/arch/arm64/kvm/arm.c
> +++ b/arch/arm64/kvm/arm.c
> @@ -19,6 +19,7 @@
>  #include <linux/kvm.h>
>  #include <linux/kvm_irqfd.h>
>  #include <linux/irqbypass.h>
> +#include <linux/log2.h>
>  #include <linux/sched/stat.h>
>  #include <linux/psci.h>
>  #include <trace/events/kvm.h>
> @@ -203,6 +204,31 @@ int kvm_vm_ioctl_enable_cap(struct kvm *kvm,
>  		r = 0;
>  		set_bit(KVM_ARCH_FLAG_EXIT_SEA, &kvm->arch.flags);
>  		break;
> +	case KVM_CAP_ARM_HDBSS_BUFFER_SIZE: {
> +		u64 size = cap->args[0];
> +
> +		if (!system_supports_hdbss())
> +			break;
> +		if (kvm->dirty_ring_size)
> +			break;
> +		if (size < KVM_ARM_HDBSS_DEFAULT_SIZE ||
> +		    size > KVM_ARM_HDBSS_MAX_SIZE)
> +			break;
> +		if (!is_power_of_2(size))
> +			break;
> +
> +		mutex_lock(&kvm->lock);
> +		if (kvm->created_vcpus) {
> +			r = -EINVAL;
> +		} else if (kvm->arch.hdbss_buffer_size) {
> +			r = -EBUSY;
> +		} else {
> +			kvm->arch.hdbss_buffer_size = size;
> +			r = 0;
> +		}
> +		mutex_unlock(&kvm->lock);
> +		break;
> +	}
>  	default:
>  		break;
>  	}
> @@ -500,6 +526,14 @@ int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext)
>  		else
>  			r = KVM_ARM_EAGER_SPLIT_CHUNK_SIZE_DEFAULT;
>  		break;
> +	case KVM_CAP_ARM_HDBSS_BUFFER_SIZE:
> +		if (!system_supports_hdbss())
> +			r = 0;
> +		else if (kvm)
> +			r = kvm->arch.hdbss_buffer_size ?: KVM_ARM_HDBSS_DEFAULT_SIZE;

This whole thing of allowing hdbss_buf_size to be set only once makes 
everything more complex. Why do we have this limitation again?

I mean, if we want to restrict size changes after the first hdbss buffer 
gets allocated, it makes sense, other than that, I would like to understand 
the reason for that.

Thanks!
Leo



More information about the linux-arm-kernel mailing list