Skip to content

Commit 1e702d9

Browse files
Alex Williamsonmatosatti
authored andcommitted
KVM: struct kvm_memory_slot.id -> short
We're currently offering a whopping 32 memory slots to user space, an int is a bit excessive for storing this. We would like to increase our memslots, but SHRT_MAX should be more than enough. Reviewed-by: Gleb Natapov <gleb@redhat.com> Signed-off-by: Alex Williamson <alex.williamson@redhat.com> Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
1 parent 6104f47 commit 1e702d9

2 files changed

Lines changed: 4 additions & 2 deletions

File tree

‎include/linux/kvm_host.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ struct kvm_memory_slot {
270270
struct kvm_arch_memory_slot arch;
271271
unsigned long userspace_addr;
272272
u32 flags;
273-
int id;
273+
short id;
274274
bool user_alloc;
275275
};
276276

@@ -330,7 +330,7 @@ struct kvm_memslots {
330330
u64 generation;
331331
struct kvm_memory_slot memslots[KVM_MEM_SLOTS_NUM];
332332
/* The mapping table from slot id to the index in memslots[]. */
333-
int id_to_index[KVM_MEM_SLOTS_NUM];
333+
short id_to_index[KVM_MEM_SLOTS_NUM];
334334
};
335335

336336
struct kvm {

‎virt/kvm/kvm_main.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,8 @@ static struct kvm *kvm_create_vm(unsigned long type)
474474
INIT_HLIST_HEAD(&kvm->irq_ack_notifier_list);
475475
#endif
476476

477+
BUILD_BUG_ON(KVM_MEM_SLOTS_NUM > SHRT_MAX);
478+
477479
r = -ENOMEM;
478480
kvm->memslots = kzalloc(sizeof(struct kvm_memslots), GFP_KERNEL);
479481
if (!kvm->memslots)

0 commit comments

Comments
 (0)