@@ -287,6 +287,7 @@ enum loongarch_features {
LOONGARCH_FEATURE_LASX,
LOONGARCH_FEATURE_LBT, /* loongson binary translation extension */
LOONGARCH_FEATURE_PMU,
+ LOONGARCH_FEATURE_PV_IPI,
};
typedef struct LoongArchBT {
@@ -310,6 +311,7 @@ typedef struct CPUArchState {
lbt_t lbt;
uint32_t cpucfg[21];
+ uint32_t pv_features;
/* LoongArch CSRs */
uint64_t CSR_CRMD;
@@ -8,7 +8,7 @@
#include "qemu/osdep.h"
#include <sys/ioctl.h>
#include <linux/kvm.h>
-
+#include "asm-loongarch/kvm_para.h"
#include "qapi/error.h"
#include "qemu/timer.h"
#include "qemu/error-report.h"
@@ -875,6 +875,12 @@ static bool kvm_feature_supported(CPUState *cs, enum loongarch_features feature)
ret = kvm_vm_ioctl(kvm_state, KVM_HAS_DEVICE_ATTR, &attr);
return (ret == 0);
+ case LOONGARCH_FEATURE_PV_IPI:
+ attr.group = KVM_LOONGARCH_VM_FEAT_CTRL;
+ attr.attr = KVM_LOONGARCH_VM_FEAT_PV_IPI;
+ ret = kvm_vm_ioctl(kvm_state, KVM_HAS_DEVICE_ATTR, &attr);
+ return (ret == 0);
+
default:
return false;
}
@@ -973,6 +979,29 @@ static int kvm_cpu_check_pmu(CPUState *cs, Error **errp)
return 0;
}
+static int kvm_cpu_check_pv_features(CPUState *cs, Error **errp)
+{
+ LoongArchCPU *cpu = LOONGARCH_CPU(cs);
+ CPULoongArchState *env = cpu_env(cs);
+ bool kvm_supported;
+
+ kvm_supported = kvm_feature_supported(cs, LOONGARCH_FEATURE_PV_IPI);
+ if (cpu->kvm_pv_ipi == ON_OFF_AUTO_ON) {
+ if (!kvm_supported) {
+ error_setg(errp, "'pv_ipi' feature not supported by KVM host");
+ return -ENOTSUP;
+ }
+ } else if (cpu->kvm_pv_ipi != ON_OFF_AUTO_AUTO) {
+ kvm_supported = false;
+ }
+
+ if (kvm_supported) {
+ env->pv_features |= BIT(KVM_FEATURE_IPI);
+ }
+
+ return 0;
+}
+
int kvm_arch_init_vcpu(CPUState *cs)
{
uint64_t val;
@@ -1006,6 +1035,11 @@ int kvm_arch_init_vcpu(CPUState *cs)
error_report_err(local_err);
}
+ ret = kvm_cpu_check_pv_features(cs, &local_err);
+ if (ret < 0) {
+ error_report_err(local_err);
+ }
+
return ret;
}
Paravirt ipi feature is OnOffAuto type, feature detection is added to check whether it is supported by KVM host. Signed-off-by: Bibo Mao <maobibo@loongson.cn> --- target/loongarch/cpu.h | 2 ++ target/loongarch/kvm/kvm.c | 36 +++++++++++++++++++++++++++++++++++- 2 files changed, 37 insertions(+), 1 deletion(-)