@@ -69,6 +69,7 @@ bool kvm_arm_create_scratch_host_vcpu(const uint32_t *cpus_to_try,
int *fdarray,
struct kvm_vcpu_init *init)
{
+ struct kvm_vcpu_init try;
int ret = 0, kvmfd = -1, vmfd = -1, cpufd = -1;
kvmfd = qemu_open_old("/dev/kvm", O_RDWR);
@@ -89,15 +90,9 @@ bool kvm_arm_create_scratch_host_vcpu(const uint32_t *cpus_to_try,
goto finish;
}
- if (init->target == -1) {
- struct kvm_vcpu_init preferred;
-
- ret = ioctl(vmfd, KVM_ARM_PREFERRED_TARGET, &preferred);
- if (!ret) {
- init->target = preferred.target;
- }
- }
- if (ret >= 0) {
+ ret = ioctl(vmfd, KVM_ARM_PREFERRED_TARGET, &try);
+ if (!ret) {
+ init->target = try.target;
ret = ioctl(cpufd, KVM_ARM_VCPU_INIT, init);
if (ret < 0) {
goto err;
@@ -108,8 +103,6 @@ bool kvm_arm_create_scratch_host_vcpu(const uint32_t *cpus_to_try,
* creating one kind of guest CPU which is its preferred
* CPU type.
*/
- struct kvm_vcpu_init try;
-
while (*cpus_to_try != QEMU_KVM_ARM_TARGET_NONE) {
try.target = *cpus_to_try++;
memcpy(try.features, init->features, sizeof(init->features));
@@ -515,11 +515,9 @@ bool kvm_arm_get_host_cpu_features(ARMHostCPUFeatures *ahcf)
KVM_ARM_TARGET_CORTEX_A57,
QEMU_KVM_ARM_TARGET_NONE
};
- /*
- * target = -1 informs kvm_arm_create_scratch_host_vcpu()
- * to use the preferred target
- */
- struct kvm_vcpu_init init = { .target = -1, };
+ struct kvm_vcpu_init init = {
+ .features[0] = 0;
+ };
if (!kvm_arm_create_scratch_host_vcpu(cpus_to_try, fdarray, &init)) {
return false;
@@ -742,8 +740,7 @@ void kvm_arm_sve_get_vls(CPUState *cs, unsigned long *map)
*/
if (!probed) {
struct kvm_vcpu_init init = {
- .target = -1,
- .features[0] = (1 << KVM_ARM_VCPU_SVE),
+ .features[0] = 0,
};
struct kvm_one_reg reg = {
.id = KVM_REG_ARM64_SVE_VLS,
@@ -753,6 +750,7 @@ void kvm_arm_sve_get_vls(CPUState *cs, unsigned long *map)
probed = true;
+ init.features[0] = (1 << KVM_ARM_VCPU_SVE);
if (!kvm_arm_create_scratch_host_vcpu(NULL, fdarray, &init)) {
error_report("failed to create scratch VCPU with SVE enabled");
abort();
@init->target is always -1 and preferred target is retrieved from host when @init isn't NULL in kvm_arm_create_scratch_host_vcpu(). So we can have the assumption that preferred target retrived from host is tried prior to the specified target list. Signed-off-by: Gavin Shan <gshan@redhat.com> --- target/arm/kvm.c | 15 ++++----------- target/arm/kvm64.c | 12 +++++------- 2 files changed, 9 insertions(+), 18 deletions(-)