[PATCH] target/arm/kvm: Mark host feature cache valid last

Akihiko Odaki posted 1 patch 1 month, 1 week ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20260422-arm-v1-1-106a9a9e22dd@rsg.ci.i.u-tokyo.ac.jp
Maintainers: Peter Maydell <peter.maydell@linaro.org>, Paolo Bonzini <pbonzini@redhat.com>
There is a newer version of this series
target/arm/kvm.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
[PATCH] target/arm/kvm: Mark host feature cache valid last
Posted by Akihiko Odaki 1 month, 1 week ago
kvm_arm_set_cpu_features_from_host() treats dtb_compatible as the host
feature cache valid bit, but kvm_arm_get_host_cpu_features() set it
before later register reads could fail.

Set target and dtb_compatible only after the feature data is complete.

Signed-off-by: Akihiko Odaki <odaki@rsg.ci.i.u-tokyo.ac.jp>
---
This fixes a semantic issue I found while writing the next version of [1].
I am not aware of any case where it manifests as a real bug.

[1] http://lore.kernel.org/qemu-devel/20260225-kvm-v2-1-b8d743db0f73@rsg.ci.i.u-tokyo.ac.jp/
("[PATCH RFC v2] target/arm/kvm: Choose PMU backend")
---
 target/arm/kvm.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/target/arm/kvm.c b/target/arm/kvm.c
index d4a68874b880..03c3346d50ed 100644
--- a/target/arm/kvm.c
+++ b/target/arm/kvm.c
@@ -329,8 +329,6 @@ static bool kvm_arm_get_host_cpu_features(ARMHostCPUFeatures *ahcf)
         return false;
     }
 
-    ahcf->target = init.target;
-    ahcf->dtb_compatible = "arm,armv8";
     int fd = fdarray[2];
 
     err = get_host_cpu_reg(fd, ahcf, ID_AA64PFR0_EL1_IDX);
@@ -472,6 +470,8 @@ static bool kvm_arm_get_host_cpu_features(ARMHostCPUFeatures *ahcf)
     }
 
     ahcf->features = features;
+    ahcf->target = init.target;
+    ahcf->dtb_compatible = "arm,armv8";
 
     return true;
 }

---
base-commit: 98b060da3a4f92b2a994ead5b16a87e783baf77c
change-id: 20260422-arm-84b23dad0561

Best regards,
--  
Akihiko Odaki <odaki@rsg.ci.i.u-tokyo.ac.jp>
Re: [PATCH] target/arm/kvm: Mark host feature cache valid last
Posted by Peter Maydell 1 month ago
On Wed, 22 Apr 2026 at 13:13, Akihiko Odaki
<odaki@rsg.ci.i.u-tokyo.ac.jp> wrote:
>
> kvm_arm_set_cpu_features_from_host() treats dtb_compatible as the host
> feature cache valid bit, but kvm_arm_get_host_cpu_features() set it
> before later register reads could fail.
>
> Set target and dtb_compatible only after the feature data is complete.
>
> Signed-off-by: Akihiko Odaki <odaki@rsg.ci.i.u-tokyo.ac.jp>
> ---
> This fixes a semantic issue I found while writing the next version of [1].
> I am not aware of any case where it manifests as a real bug.

We're not currently consistent since we have one check that might
return false from kvm_arm_get_host_cpu_features() before we set
dtb_compatible and then several after. But I think that the
right thing to do is to set dtb_compatible right at the top,
and adjust kvm_arm_set_cpu_features_from_host() to copy
cpu->host_cpu_probe_failed in its "populate from cache" codepath.

That is, if we have an SMP config and we can't get the host
CPU features the first time we call kvm_arm_get_host_cpu_features()
there's no point in repeating that attempt over and over for
every other CPU. We should instead treat the "host probe failed"
indication as part of our cached data and copy that.

On the other hand, if we do that then the practical upshot will
be that we print the error message once per CPU rather than
just once...

thanks
-- PMM