All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Philippe Mathieu-Daudé" <philmd@linaro.org>
To: qemu-devel@nongnu.org
Cc: "Miguel Luis" <miguel.luis@oracle.com>,
	"Richard Henderson" <richard.henderson@linaro.org>,
	kvm@vger.kernel.org, "Peter Maydell" <peter.maydell@linaro.org>,
	"Paolo Bonzini" <pbonzini@redhat.com>,
	"Haibo Xu" <haibo.xu@linaro.org>,
	"Mohamed Mediouni" <mohamed@unpredictable.fr>,
	"Mark Burton" <mburton@qti.qualcomm.com>,
	"Alexander Graf" <agraf@csgraf.de>,
	"Claudio Fontana" <cfontana@suse.de>,
	"Alex Bennée" <alex.bennee@linaro.org>,
	"Mads Ynddal" <mads@ynddal.dk>,
	"Eric Auger" <eric.auger@redhat.com>,
	qemu-arm@nongnu.org, "Cameron Esfahani" <dirty@apple.com>,
	"Philippe Mathieu-Daudé" <philmd@linaro.org>
Subject: [RFC PATCH 08/11] target/arm: Replace kvm_arm_el2_supported by host_cpu_feature_supported
Date: Mon, 11 Aug 2025 19:06:08 +0200	[thread overview]
Message-ID: <20250811170611.37482-9-philmd@linaro.org> (raw)
In-Reply-To: <20250811170611.37482-1-philmd@linaro.org>

Use the generic host_cpu_feature_supported() helper to
check for the EL2 feature support. This will allow to
expand to non-KVM accelerators such HVF.

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 target/arm/kvm_arm.h  | 11 -----------
 hw/arm/virt.c         |  8 +-------
 target/arm/kvm-stub.c |  5 -----
 target/arm/kvm.c      |  6 +++---
 4 files changed, 4 insertions(+), 26 deletions(-)

diff --git a/target/arm/kvm_arm.h b/target/arm/kvm_arm.h
index 364578c50d6..7e5755d76b2 100644
--- a/target/arm/kvm_arm.h
+++ b/target/arm/kvm_arm.h
@@ -191,12 +191,6 @@ bool kvm_arm_sve_supported(void);
  */
 bool kvm_arm_mte_supported(void);
 
-/**
- * kvm_arm_el2_supported:
- *
- * Returns true if KVM can enable EL2 and false otherwise.
- */
-bool kvm_arm_el2_supported(void);
 #else
 
 static inline bool kvm_arm_aarch32_supported(void)
@@ -213,11 +207,6 @@ static inline bool kvm_arm_mte_supported(void)
 {
     return false;
 }
-
-static inline bool kvm_arm_el2_supported(void)
-{
-    return false;
-}
 #endif
 
 /**
diff --git a/hw/arm/virt.c b/hw/arm/virt.c
index ef6be3660f5..c2f71ecbfa7 100644
--- a/hw/arm/virt.c
+++ b/hw/arm/virt.c
@@ -2267,13 +2267,7 @@ static void machvirt_init(MachineState *machine)
         exit(1);
     }
 
-    if (vms->virt && kvm_enabled() && !kvm_arm_el2_supported()) {
-        error_report("mach-virt: host kernel KVM does not support providing "
-                     "Virtualization extensions to the guest CPU");
-        exit(1);
-    }
-
-    if (vms->virt && !kvm_enabled() && !tcg_enabled() && !qtest_enabled()) {
+    if (vms->virt && !host_cpu_feature_supported(ARM_FEATURE_EL2, true)) {
         error_report("mach-virt: %s does not support providing "
                      "Virtualization extensions to the guest CPU",
                      current_accel_name());
diff --git a/target/arm/kvm-stub.c b/target/arm/kvm-stub.c
index 3beb336416d..35afcc7d6f9 100644
--- a/target/arm/kvm-stub.c
+++ b/target/arm/kvm-stub.c
@@ -42,11 +42,6 @@ bool kvm_arm_mte_supported(void)
     return false;
 }
 
-bool kvm_arm_el2_supported(void)
-{
-    return false;
-}
-
 /*
  * These functions should never actually be called without KVM support.
  */
diff --git a/target/arm/kvm.c b/target/arm/kvm.c
index 0fe0f89f931..a9f05bfa7ea 100644
--- a/target/arm/kvm.c
+++ b/target/arm/kvm.c
@@ -274,7 +274,7 @@ static bool kvm_arm_get_host_cpu_features(ARMHostCPUFeatures *ahcf)
     /*
      * Ask for EL2 if supported.
      */
-    el2_supported = kvm_arm_el2_supported();
+    el2_supported = host_cpu_feature_supported(ARM_FEATURE_EL2, false);
     if (el2_supported) {
         init.features[0] |= 1 << KVM_ARM_VCPU_HAS_EL2;
     }
@@ -1780,7 +1780,7 @@ bool arm_hw_accel_cpu_feature_supported(enum arm_features feat, bool can_emulate
     case ARM_FEATURE_PMU:
         return kvm_check_extension(kvm_state, KVM_CAP_ARM_PMU_V3);
     case ARM_FEATURE_EL2:
-        return kvm_arm_el2_supported();
+        return kvm_check_extension(kvm_state, KVM_CAP_ARM_EL2);
     case ARM_FEATURE_EL3:
         return false;
     default:
@@ -1918,7 +1918,7 @@ int kvm_arch_init_vcpu(CPUState *cs)
         cpu->kvm_init_features[0] |= (1 << KVM_ARM_VCPU_PTRAUTH_ADDRESS |
                                       1 << KVM_ARM_VCPU_PTRAUTH_GENERIC);
     }
-    if (cpu->has_el2 && kvm_arm_el2_supported()) {
+    if (cpu->has_el2 && host_cpu_feature_supported(ARM_FEATURE_EL2, false)) {
         cpu->kvm_init_features[0] |= 1 << KVM_ARM_VCPU_HAS_EL2;
     }
 
-- 
2.49.0


  parent reply	other threads:[~2025-08-11 17:06 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-08-11 17:06 [RFC PATCH 00/11] target/arm: Introduce host_cpu_feature_supported() API Philippe Mathieu-Daudé
2025-08-11 17:06 ` [RFC PATCH 01/11] accel/system: Introduce hwaccel_enabled() helper Philippe Mathieu-Daudé
2025-08-11 17:06 ` [RFC PATCH 02/11] target/arm: Use generic hwaccel_enabled() to check 'host' cpu type Philippe Mathieu-Daudé
2025-08-11 17:06 ` [RFC PATCH 03/11] target/arm: Restrict PMU to system mode Philippe Mathieu-Daudé
2025-08-12  0:02   ` Richard Henderson
2025-08-11 17:06 ` [RFC PATCH 04/11] target/arm: Factor hvf_psci_get_target_el() out Philippe Mathieu-Daudé
2025-08-12  0:26   ` Richard Henderson
2025-08-11 17:06 ` [RFC PATCH 05/11] target/arm: Introduce arm_hw_accel_cpu_feature_supported() Philippe Mathieu-Daudé
2025-08-12  0:35   ` Richard Henderson
2025-08-12  4:06     ` Philippe Mathieu-Daudé
2025-08-12  4:58     ` Philippe Mathieu-Daudé
2025-08-11 17:06 ` [RFC PATCH 06/11] target/arm: Introduce host_cpu_feature_supported() Philippe Mathieu-Daudé
2025-08-12  0:44   ` Richard Henderson
2025-08-12  4:30     ` Philippe Mathieu-Daudé
2025-08-11 17:06 ` [RFC PATCH 07/11] target/arm: Replace kvm_arm_pmu_supported by host_cpu_feature_supported Philippe Mathieu-Daudé
2025-08-12  0:48   ` Richard Henderson
2025-08-12  4:49     ` Philippe Mathieu-Daudé
2025-08-12  6:03       ` Philippe Mathieu-Daudé
2025-08-12  7:33         ` Philippe Mathieu-Daudé
2025-08-12 12:42           ` Richard Henderson
2025-08-12 13:12             ` Philippe Mathieu-Daudé
2025-08-11 17:06 ` Philippe Mathieu-Daudé [this message]
2025-08-11 17:06 ` [RFC PATCH 09/11] target/arm/hvf: Sync registers used at EL2 Philippe Mathieu-Daudé
2025-08-12  0:20   ` Richard Henderson
2025-08-13  7:20     ` Philippe Mathieu-Daudé
2025-08-11 17:06 ` [RFC PATCH 10/11] target/arm/hvf: Consider EL2 acceleration for Silicon M3+ chipsets Philippe Mathieu-Daudé
2025-08-11 17:06 ` [RFC PATCH 11/11] target/arm/hvf: Allow EL2/EL3 emulation on Silicon M1 / M2 Philippe Mathieu-Daudé
2025-08-12  0:23   ` Richard Henderson
2025-08-12  3:56     ` Philippe Mathieu-Daudé

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=20250811170611.37482-9-philmd@linaro.org \
    --to=philmd@linaro.org \
    --cc=agraf@csgraf.de \
    --cc=alex.bennee@linaro.org \
    --cc=cfontana@suse.de \
    --cc=dirty@apple.com \
    --cc=eric.auger@redhat.com \
    --cc=haibo.xu@linaro.org \
    --cc=kvm@vger.kernel.org \
    --cc=mads@ynddal.dk \
    --cc=mburton@qti.qualcomm.com \
    --cc=miguel.luis@oracle.com \
    --cc=mohamed@unpredictable.fr \
    --cc=pbonzini@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-arm@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=richard.henderson@linaro.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.