Skip to content

Commit 8b44b17

Browse files
sean-jcbonzini
authored andcommitted
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: [email protected] Signed-off-by: Sean Christopherson <[email protected]> Message-Id: <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]>
1 parent 10c30de commit 8b44b17

File tree

1 file changed

+24
-23
lines changed

1 file changed

+24
-23
lines changed

arch/x86/kvm/cpuid.c

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,25 @@ u64 kvm_vcpu_reserved_gpa_bits_raw(struct kvm_vcpu *vcpu)
239239
return rsvd_bits(cpuid_maxphyaddr(vcpu), 63);
240240
}
241241

242+
static int kvm_set_cpuid(struct kvm_vcpu *vcpu, struct kvm_cpuid_entry2 *e2,
243+
int nent)
244+
{
245+
int r;
246+
247+
r = kvm_check_cpuid(e2, nent);
248+
if (r)
249+
return r;
250+
251+
kvfree(vcpu->arch.cpuid_entries);
252+
vcpu->arch.cpuid_entries = e2;
253+
vcpu->arch.cpuid_nent = nent;
254+
255+
kvm_update_cpuid_runtime(vcpu);
256+
kvm_vcpu_after_set_cpuid(vcpu);
257+
258+
return 0;
259+
}
260+
242261
/* when an old userspace process fills a new kernel module */
243262
int kvm_vcpu_ioctl_set_cpuid(struct kvm_vcpu *vcpu,
244263
struct kvm_cpuid *cpuid,
@@ -275,18 +294,9 @@ int kvm_vcpu_ioctl_set_cpuid(struct kvm_vcpu *vcpu,
275294
e2[i].padding[2] = 0;
276295
}
277296

278-
r = kvm_check_cpuid(e2, cpuid->nent);
279-
if (r) {
297+
r = kvm_set_cpuid(vcpu, e2, cpuid->nent);
298+
if (r)
280299
kvfree(e2);
281-
goto out_free_cpuid;
282-
}
283-
284-
kvfree(vcpu->arch.cpuid_entries);
285-
vcpu->arch.cpuid_entries = e2;
286-
vcpu->arch.cpuid_nent = cpuid->nent;
287-
288-
kvm_update_cpuid_runtime(vcpu);
289-
kvm_vcpu_after_set_cpuid(vcpu);
290300

291301
out_free_cpuid:
292302
kvfree(e);
@@ -310,20 +320,11 @@ int kvm_vcpu_ioctl_set_cpuid2(struct kvm_vcpu *vcpu,
310320
return PTR_ERR(e2);
311321
}
312322

313-
r = kvm_check_cpuid(e2, cpuid->nent);
314-
if (r) {
323+
r = kvm_set_cpuid(vcpu, e2, cpuid->nent);
324+
if (r)
315325
kvfree(e2);
316-
return r;
317-
}
318326

319-
kvfree(vcpu->arch.cpuid_entries);
320-
vcpu->arch.cpuid_entries = e2;
321-
vcpu->arch.cpuid_nent = cpuid->nent;
322-
323-
kvm_update_cpuid_runtime(vcpu);
324-
kvm_vcpu_after_set_cpuid(vcpu);
325-
326-
return 0;
327+
return r;
327328
}
328329

329330
int kvm_vcpu_ioctl_get_cpuid2(struct kvm_vcpu *vcpu,

0 commit comments

Comments
 (0)