From mboxrd@z Thu Jan 1 00:00:00 1970 From: mtosatti@redhat.com Subject: [patch 4/4] KVM: x86: disallow changing a slots size Date: Mon, 27 Apr 2009 17:06:24 -0300 Message-ID: <20090427200757.092796919@amt.cnet> References: <20090427200620.389589459@amt.cnet> Cc: Marcelo Tosatti To: kvm@vger.kernel.org Return-path: Received: from mx2.redhat.com ([66.187.237.31]:59314 "EHLO mx2.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757168AbZD0UJr (ORCPT ); Mon, 27 Apr 2009 16:09:47 -0400 Received: from int-mx2.corp.redhat.com (int-mx2.corp.redhat.com [172.16.27.26]) by mx2.redhat.com (8.13.8/8.13.8) with ESMTP id n3RK9mUM018575 for ; Mon, 27 Apr 2009 16:09:48 -0400 Content-Disposition: inline; filename=disallow-alias-size-change Sender: kvm-owner@vger.kernel.org List-ID: Support to shrinking aliases complicates kernel code unnecessarily, while userspace can do the same with two operations, delete an alias, and create a new alias. Signed-off-by: Marcelo Tosatti Index: kvm/arch/x86/kvm/x86.c =================================================================== --- kvm.orig/arch/x86/kvm/x86.c +++ kvm/arch/x86/kvm/x86.c @@ -1707,6 +1707,7 @@ static int kvm_vm_ioctl_set_memory_alias { int r, n; struct kvm_mem_alias *p; + unsigned long npages; r = -EINVAL; /* General sanity checks */ @@ -1728,9 +1729,12 @@ static int kvm_vm_ioctl_set_memory_alias p = &kvm->arch.aliases[alias->slot]; - /* FIXME: either disallow shrinking alias slots or disable - * size changes as done with memslots - */ + /* Disallow changing an alias slot's size. */ + npages = alias->memory_size >> PAGE_SHIFT; + r = -EINVAL; + if (npages && p->npages && npages != p->npages) + goto out_unlock; + if (!alias->memory_size) { r = -EBUSY; if (kvm_root_gfn_in_range(kvm, p->base_gfn,