The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Marc Zyngier <maz@kernel.org>
To: Karl Mehltretter <kmehltretter@gmail.com>
Cc: Oliver Upton <oupton@kernel.org>,
	kvmarm@lists.linux.dev, Fuad Tabba <fuad.tabba@linux.dev>,
	Joey Gouly <joey.gouly@arm.com>,
	Steffen Eiden <seiden@linux.ibm.com>,
	Suzuki K Poulose <suzuki.poulose@arm.com>,
	Zenghui Yu <yuzenghui@huawei.com>,
	Catalin Marinas <catalin.marinas@arm.com>,
	Will Deacon <will@kernel.org>,
	Paolo Bonzini <pbonzini@redhat.com>,
	Shuah Khan <shuah@kernel.org>, Eric Auger <eric.auger@redhat.com>,
	kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org
Subject: Re: [RFC PATCH 1/2] KVM: arm64: vgic-v3: Roll back failed redistributor region setup
Date: Mon, 10 Aug 2026 15:03:44 +0100	[thread overview]
Message-ID: <86tsp2139b.wl-maz@kernel.org> (raw)
In-Reply-To: <4e00fc25aa61ec52e6ef033a53588ce3f5550982.1786344511.git.kmehltretter@gmail.com>

On Mon, 10 Aug 2026 07:52:16 +0100,
Karl Mehltretter <kmehltretter@gmail.com> wrote:

I'm sorry, but I find it difficult understand what you are trying to
explain here:

> A later REDIST_REGION attribute can be inserted successfully and then

Later than what?

> fail while registering redistributor iodevs. For example, a region that
> overlaps the distributor is caught by vgic_v3_check_base() when the first
> unassigned vCPU is processed.
>
> The existing rollback unregisters all previously registered
> redistributor iodevs. It leaves their rd_iodev.base_addr values set, so a
> corrected retry skips re-registering those stale vCPUs and succeeds with
> holes in the MMIO bus.

Holes in the MMIO space are the norm. The IPA space can multi-TB
large, and there is no reason why it'd cover everything (where would
you place the RAM otherwise?).

Is the problem here that you are left with vcpus that seem to have
been matched to an RD (base_addr being set), but that really are left
unconnected?

> 
> A failure from kvm_io_bus_register_dev() can leave another hole. The

MMIO hole? Coverage hole?

> failing vCPU already has its base address and region assigned, but the
> old i < c rollback does not include it.

What is "it"?

> 
> Preserve devices assigned by earlier successful setters. On failure,
> unregister only vCPUs associated with the newly inserted region, clear
> their cached base addresses, and free that region. This also includes the
> current vCPU when iodev registration itself fails.

What I don't see here is an argument explaining that doing this
doesn't change the guest-visible assignment of RDs, which would be a
regression.

> 
> Fixes: c011f4ea106b ("KVM: arm/arm64: Check vcpu redist base before registering an iodev")
> Assisted-by: Codex:gpt-5.6-sol
> Signed-off-by: Karl Mehltretter <kmehltretter@gmail.com>
> ---
>  arch/arm64/kvm/vgic/vgic-mmio-v3.c | 42 ++++++++++++++++++------------
>  1 file changed, 26 insertions(+), 16 deletions(-)
> 
> diff --git a/arch/arm64/kvm/vgic/vgic-mmio-v3.c b/arch/arm64/kvm/vgic/vgic-mmio-v3.c
> index 5913a20d83019..832a7fe65984c 100644
> --- a/arch/arm64/kvm/vgic/vgic-mmio-v3.c
> +++ b/arch/arm64/kvm/vgic/vgic-mmio-v3.c
> @@ -841,6 +841,31 @@ void vgic_unregister_redist_iodev(struct kvm_vcpu *vcpu)
>  	kvm_io_bus_unregister_dev(vcpu->kvm, KVM_MMIO_BUS, &rd_dev->dev);
>  }
>  
> +static void vgic_v3_rollback_redist_region(struct kvm *kvm, u32 index)
> +{
> +	struct vgic_redist_region *rdreg;
> +	struct kvm_vcpu *vcpu;
> +	unsigned long c;
> +
> +	lockdep_assert_held(&kvm->slots_lock);
> +
> +	rdreg = vgic_v3_rdist_region_from_index(kvm, index);
> +
> +	kvm_for_each_vcpu(c, vcpu, kvm) {
> +		if (vcpu->arch.vgic_cpu.rdreg == rdreg)
> +			vgic_unregister_redist_iodev(vcpu);
> +	}
> +
> +	guard(mutex)(&kvm->arch.config_lock);
> +
> +	kvm_for_each_vcpu(c, vcpu, kvm) {
> +		if (vcpu->arch.vgic_cpu.rdreg == rdreg)
> +			vcpu->arch.vgic_cpu.rd_iodev.base_addr = VGIC_ADDR_UNDEF;
> +	}
> +
> +	vgic_v3_free_redist_region(kvm, rdreg);
> +}
> +
>  static int vgic_register_all_redist_iodevs(struct kvm *kvm)
>  {
>  	struct kvm_vcpu *vcpu;
> @@ -855,16 +880,6 @@ static int vgic_register_all_redist_iodevs(struct kvm *kvm)
>  			break;
>  	}
>  
> -	if (ret) {
> -		/* The current c failed, so iterate over the previous ones. */
> -		int i;
> -
> -		for (i = 0; i < c; i++) {
> -			vcpu = kvm_get_vcpu(kvm, i);
> -			vgic_unregister_redist_iodev(vcpu);
> -		}
> -	}
> -
>  	return ret;
>  }
>  
> @@ -984,12 +999,7 @@ int vgic_v3_set_redist_base(struct kvm *kvm, u32 index, u64 addr, u32 count)
>  	 */
>  	ret = vgic_register_all_redist_iodevs(kvm);
>  	if (ret) {
> -		struct vgic_redist_region *rdreg;
> -
> -		mutex_lock(&kvm->arch.config_lock);
> -		rdreg = vgic_v3_rdist_region_from_index(kvm, index);
> -		vgic_v3_free_redist_region(kvm, rdreg);
> -		mutex_unlock(&kvm->arch.config_lock);
> +		vgic_v3_rollback_redist_region(kvm, index);
>  		return ret;
>  	}
>  

Based on what I understand of your earlier description, why isn't this
as simple as this untested hack:

diff --git a/arch/arm64/kvm/vgic/vgic-mmio-v3.c b/arch/arm64/kvm/vgic/vgic-mmio-v3.c
index 5913a20d83019..804fcc69cbd48 100644
--- a/arch/arm64/kvm/vgic/vgic-mmio-v3.c
+++ b/arch/arm64/kvm/vgic/vgic-mmio-v3.c
@@ -859,7 +859,7 @@ static int vgic_register_all_redist_iodevs(struct kvm *kvm)
 		/* The current c failed, so iterate over the previous ones. */
 		int i;
 
-		for (i = 0; i < c; i++) {
+		for (i = 0; i <= c; i++) {
 			vcpu = kvm_get_vcpu(kvm, i);
 			vgic_unregister_redist_iodev(vcpu);
 		}
@@ -960,8 +960,10 @@ void vgic_v3_free_redist_region(struct kvm *kvm, struct vgic_redist_region *rdre
 
 	/* Garbage collect the region */
 	kvm_for_each_vcpu(c, vcpu, kvm) {
-		if (vcpu->arch.vgic_cpu.rdreg == rdreg)
+		if (vcpu->arch.vgic_cpu.rdreg == rdreg) {
 			vcpu->arch.vgic_cpu.rdreg = NULL;
+			vcpu->arch.vgic_cpu.rd_iodev.base_addr = VGIC_ADDR_UNDEF;
+		}
 	}
 
 	list_del(&rdreg->list);

I don't mind the cleaning up, but not as part of fixing the issue,
which has to be as small as possible (think of the backports).

Thanks,

	M.

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

  reply	other threads:[~2026-08-10 14:03 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-10  6:52 [RFC PATCH 0/2] KVM: arm64: fix VGICv3 redistributor rollback Karl Mehltretter
2026-08-10  6:52 ` [RFC PATCH 1/2] KVM: arm64: vgic-v3: Roll back failed redistributor region setup Karl Mehltretter
2026-08-10 14:03   ` Marc Zyngier [this message]
2026-08-10  6:52 ` [RFC PATCH 2/2] KVM: arm64: selftests: Test VGICv3 redistributor region retry Karl Mehltretter

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=86tsp2139b.wl-maz@kernel.org \
    --to=maz@kernel.org \
    --cc=catalin.marinas@arm.com \
    --cc=eric.auger@redhat.com \
    --cc=fuad.tabba@linux.dev \
    --cc=joey.gouly@arm.com \
    --cc=kmehltretter@gmail.com \
    --cc=kvm@vger.kernel.org \
    --cc=kvmarm@lists.linux.dev \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=oupton@kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=seiden@linux.ibm.com \
    --cc=shuah@kernel.org \
    --cc=suzuki.poulose@arm.com \
    --cc=will@kernel.org \
    --cc=yuzenghui@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