Introduce kvm_arm_create_init_scratch_vcpu() that allows to create
and initialize a scratch vcpu from cpu settings. We want to use
this in arm-qmp-cmds code as well as kvm_arm_destroy_scratch_host_vcpu
so export them.

Signed-off-by: Eric Auger <[email protected]>

---

v9 -> v10:
- pass the fdarray as a param
---
 target/arm/kvm_arm.h  | 19 ++++++++++++++++++-
 target/arm/kvm-stub.c | 10 ++++++++++
 target/arm/kvm.c      | 13 +++++++++++++
 3 files changed, 41 insertions(+), 1 deletion(-)

diff --git a/target/arm/kvm_arm.h b/target/arm/kvm_arm.h
index ccab33e571..2e7e02e4a4 100644
--- a/target/arm/kvm_arm.h
+++ b/target/arm/kvm_arm.h
@@ -118,11 +118,28 @@ struct kvm_vcpu_init;
 bool kvm_arm_create_scratch_host_vcpu(int *fdarray,
                                       struct kvm_vcpu_init *init, Error 
**errp);
 
+/**
+ * kvm_arm_create_init_scratch_vcpu:
+ * @cpu: ARMCPU whose kvm init features to inherit
+ * @fdarray: array of fds filled as by kvm_arm_create_scratch_host_vcpu
+ *
+ * Create and initialize a scratch vcpu inheriting the features set
+ * on @cpu.
+ *
+ * Return the vcpu fd on success or -1 on failure with a corresponding
+ * Error handle. On success, @fdarray is populated and must be torn down
+ * with kvm_arm_destroy_scratch_host_vcpu().
+ */
+int kvm_arm_create_init_scratch_vcpu(ARMCPU *cpu, int *fdarray, Error **errp);
+
+
 /**
  * kvm_arm_destroy_scratch_host_vcpu:
  * @fdarray: array of fds as set up by kvm_arm_create_scratch_host_vcpu
+ *           or kvm_arm_create_init_scratch_vcpu
  *
- * Tear down the scratch vcpu created by kvm_arm_create_scratch_host_vcpu.
+ * Tear down the scratch vcpu created by kvm_arm_create_scratch_host_vcpu
+ * or kvm_arm_create_init_scratch_vcpu.
  */
 void kvm_arm_destroy_scratch_host_vcpu(int *fdarray);
 
diff --git a/target/arm/kvm-stub.c b/target/arm/kvm-stub.c
index 8e6fae0a4d..c9387f5c8c 100644
--- a/target/arm/kvm-stub.c
+++ b/target/arm/kvm-stub.c
@@ -126,3 +126,13 @@ bool kvm_idreg_write_scratch_vcpu(ARMCPU *cpu, int cpufd,
 {
     g_assert_not_reached();
 }
+
+int kvm_arm_create_init_scratch_vcpu(ARMCPU *cpu, int *fdarray, Error **errp)
+{
+    g_assert_not_reached();
+}
+
+void kvm_arm_destroy_scratch_host_vcpu(int *fdarray)
+{
+    g_assert_not_reached();
+}
diff --git a/target/arm/kvm.c b/target/arm/kvm.c
index 840501f9bf..ebe4f408e2 100644
--- a/target/arm/kvm.c
+++ b/target/arm/kvm.c
@@ -2228,6 +2228,19 @@ static void kvm_arm_vcpu_prepare_init_features(ARMCPU 
*cpu)
     }
 }
 
+int kvm_arm_create_init_scratch_vcpu(ARMCPU *cpu, int *fdarray, Error **errp)
+{
+    struct kvm_vcpu_init init = {.target = cpu->kvm_target, };
+
+    kvm_arm_vcpu_prepare_init_features(cpu);
+    memcpy(init.features, cpu->kvm_init_features, sizeof(init.features));
+
+    if (!kvm_arm_create_scratch_host_vcpu(fdarray, &init, errp)) {
+        return -1;
+    }
+    return fdarray[2];
+}
+
 int kvm_arch_init_vcpu(CPUState *cs, Error **errp)
 {
     int ret;
-- 
2.53.0


Reply via email to