Skip to content

Commit af1bae5

Browse files
rkrcmarbonzini
authored andcommitted
KVM: x86: bump KVM_MAX_VCPU_ID to 1023
kzalloc was replaced with kvm_kvzalloc to allow non-contiguous areas and rcu had to be modified to cope with it. The practical limit for KVM_MAX_VCPU_ID right now is INT_MAX, but lower value was chosen in case there were bugs. 1023 is sufficient maximum APIC ID for 288 VCPUs. Signed-off-by: Radim Krčmář <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]>
1 parent 682f732 commit af1bae5

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

arch/x86/include/asm/kvm_host.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636

3737
#define KVM_MAX_VCPUS 288
3838
#define KVM_SOFT_MAX_VCPUS 240
39+
#define KVM_MAX_VCPU_ID 1023
3940
#define KVM_USER_MEM_SLOTS 509
4041
/* memory slots that are not exposed to userspace */
4142
#define KVM_PRIVATE_MEM_SLOTS 3

arch/x86/kvm/lapic.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,13 @@ static inline bool kvm_apic_map_get_logical_dest(struct kvm_apic_map *map,
147147
}
148148
}
149149

150+
static void kvm_apic_map_free(struct rcu_head *rcu)
151+
{
152+
struct kvm_apic_map *map = container_of(rcu, struct kvm_apic_map, rcu);
153+
154+
kvfree(map);
155+
}
156+
150157
static void recalculate_apic_map(struct kvm *kvm)
151158
{
152159
struct kvm_apic_map *new, *old = NULL;
@@ -160,8 +167,8 @@ static void recalculate_apic_map(struct kvm *kvm)
160167
if (kvm_apic_present(vcpu))
161168
max_id = max(max_id, kvm_apic_id(vcpu->arch.apic));
162169

163-
new = kzalloc(sizeof(struct kvm_apic_map) +
164-
sizeof(struct kvm_lapic *) * (max_id + 1), GFP_KERNEL);
170+
new = kvm_kvzalloc(sizeof(struct kvm_apic_map) +
171+
sizeof(struct kvm_lapic *) * ((u64)max_id + 1));
165172

166173
if (!new)
167174
goto out;
@@ -206,7 +213,7 @@ static void recalculate_apic_map(struct kvm *kvm)
206213
mutex_unlock(&kvm->arch.apic_map_lock);
207214

208215
if (old)
209-
kfree_rcu(old, rcu);
216+
call_rcu(&old->rcu, kvm_apic_map_free);
210217

211218
kvm_make_scan_ioapic_request(kvm);
212219
}

arch/x86/kvm/x86.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7927,7 +7927,7 @@ void kvm_arch_destroy_vm(struct kvm *kvm)
79277927
kfree(kvm->arch.vpic);
79287928
kfree(kvm->arch.vioapic);
79297929
kvm_free_vcpus(kvm);
7930-
kfree(rcu_dereference_check(kvm->arch.apic_map, 1));
7930+
kvfree(rcu_dereference_check(kvm->arch.apic_map, 1));
79317931
kvm_mmu_uninit_vm(kvm);
79327932
}
79337933

0 commit comments

Comments
 (0)