mirror of
https://github.com/Fishwaldo/Star64_linux.git
synced 2025-06-23 07:01:23 +00:00
KVM: x86: Add helper to consolidate core logic of SET_CPUID{2} flows
Move the core logic of SET_CPUID and SET_CPUID2 to a common helper, the only difference between the two ioctls() is the format of the userspace struct. A future fix will add yet more code to the core logic. No functional change intended. Cc: stable@vger.kernel.org Signed-off-by: Sean Christopherson <seanjc@google.com> Message-Id: <20211105095101.5384-2-pdurrant@amazon.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This commit is contained in:
parent
10c30de019
commit
8b44b174f6
1 changed files with 24 additions and 23 deletions
|
@ -239,6 +239,25 @@ u64 kvm_vcpu_reserved_gpa_bits_raw(struct kvm_vcpu *vcpu)
|
||||||
return rsvd_bits(cpuid_maxphyaddr(vcpu), 63);
|
return rsvd_bits(cpuid_maxphyaddr(vcpu), 63);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int kvm_set_cpuid(struct kvm_vcpu *vcpu, struct kvm_cpuid_entry2 *e2,
|
||||||
|
int nent)
|
||||||
|
{
|
||||||
|
int r;
|
||||||
|
|
||||||
|
r = kvm_check_cpuid(e2, nent);
|
||||||
|
if (r)
|
||||||
|
return r;
|
||||||
|
|
||||||
|
kvfree(vcpu->arch.cpuid_entries);
|
||||||
|
vcpu->arch.cpuid_entries = e2;
|
||||||
|
vcpu->arch.cpuid_nent = nent;
|
||||||
|
|
||||||
|
kvm_update_cpuid_runtime(vcpu);
|
||||||
|
kvm_vcpu_after_set_cpuid(vcpu);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
/* when an old userspace process fills a new kernel module */
|
/* when an old userspace process fills a new kernel module */
|
||||||
int kvm_vcpu_ioctl_set_cpuid(struct kvm_vcpu *vcpu,
|
int kvm_vcpu_ioctl_set_cpuid(struct kvm_vcpu *vcpu,
|
||||||
struct kvm_cpuid *cpuid,
|
struct kvm_cpuid *cpuid,
|
||||||
|
@ -275,18 +294,9 @@ int kvm_vcpu_ioctl_set_cpuid(struct kvm_vcpu *vcpu,
|
||||||
e2[i].padding[2] = 0;
|
e2[i].padding[2] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
r = kvm_check_cpuid(e2, cpuid->nent);
|
r = kvm_set_cpuid(vcpu, e2, cpuid->nent);
|
||||||
if (r) {
|
if (r)
|
||||||
kvfree(e2);
|
kvfree(e2);
|
||||||
goto out_free_cpuid;
|
|
||||||
}
|
|
||||||
|
|
||||||
kvfree(vcpu->arch.cpuid_entries);
|
|
||||||
vcpu->arch.cpuid_entries = e2;
|
|
||||||
vcpu->arch.cpuid_nent = cpuid->nent;
|
|
||||||
|
|
||||||
kvm_update_cpuid_runtime(vcpu);
|
|
||||||
kvm_vcpu_after_set_cpuid(vcpu);
|
|
||||||
|
|
||||||
out_free_cpuid:
|
out_free_cpuid:
|
||||||
kvfree(e);
|
kvfree(e);
|
||||||
|
@ -310,20 +320,11 @@ int kvm_vcpu_ioctl_set_cpuid2(struct kvm_vcpu *vcpu,
|
||||||
return PTR_ERR(e2);
|
return PTR_ERR(e2);
|
||||||
}
|
}
|
||||||
|
|
||||||
r = kvm_check_cpuid(e2, cpuid->nent);
|
r = kvm_set_cpuid(vcpu, e2, cpuid->nent);
|
||||||
if (r) {
|
if (r)
|
||||||
kvfree(e2);
|
kvfree(e2);
|
||||||
return r;
|
|
||||||
}
|
|
||||||
|
|
||||||
kvfree(vcpu->arch.cpuid_entries);
|
return r;
|
||||||
vcpu->arch.cpuid_entries = e2;
|
|
||||||
vcpu->arch.cpuid_nent = cpuid->nent;
|
|
||||||
|
|
||||||
kvm_update_cpuid_runtime(vcpu);
|
|
||||||
kvm_vcpu_after_set_cpuid(vcpu);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int kvm_vcpu_ioctl_get_cpuid2(struct kvm_vcpu *vcpu,
|
int kvm_vcpu_ioctl_get_cpuid2(struct kvm_vcpu *vcpu,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue