浏览代码

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>
Alex Williamson 13 年之前
父节点
当前提交
1e702d9af5
共有 2 个文件被更改,包括 4 次插入2 次删除
  1. 2 2
      include/linux/kvm_host.h
  2. 2 0
      virt/kvm/kvm_main.c

+ 2 - 2
include/linux/kvm_host.h

@@ -270,7 +270,7 @@ struct kvm_memory_slot {
 	struct kvm_arch_memory_slot arch;
 	struct kvm_arch_memory_slot arch;
 	unsigned long userspace_addr;
 	unsigned long userspace_addr;
 	u32 flags;
 	u32 flags;
-	int id;
+	short id;
 	bool user_alloc;
 	bool user_alloc;
 };
 };
 
 
@@ -330,7 +330,7 @@ struct kvm_memslots {
 	u64 generation;
 	u64 generation;
 	struct kvm_memory_slot memslots[KVM_MEM_SLOTS_NUM];
 	struct kvm_memory_slot memslots[KVM_MEM_SLOTS_NUM];
 	/* The mapping table from slot id to the index in memslots[]. */
 	/* The mapping table from slot id to the index in memslots[]. */
-	int id_to_index[KVM_MEM_SLOTS_NUM];
+	short id_to_index[KVM_MEM_SLOTS_NUM];
 };
 };
 
 
 struct kvm {
 struct kvm {

+ 2 - 0
virt/kvm/kvm_main.c

@@ -474,6 +474,8 @@ static struct kvm *kvm_create_vm(unsigned long type)
 	INIT_HLIST_HEAD(&kvm->irq_ack_notifier_list);
 	INIT_HLIST_HEAD(&kvm->irq_ack_notifier_list);
 #endif
 #endif
 
 
+	BUILD_BUG_ON(KVM_MEM_SLOTS_NUM > SHRT_MAX);
+
 	r = -ENOMEM;
 	r = -ENOMEM;
 	kvm->memslots = kzalloc(sizeof(struct kvm_memslots), GFP_KERNEL);
 	kvm->memslots = kzalloc(sizeof(struct kvm_memslots), GFP_KERNEL);
 	if (!kvm->memslots)
 	if (!kvm->memslots)