Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp4575187ybb; Tue, 14 Apr 2020 09:55:37 -0700 (PDT) X-Google-Smtp-Source: APiQypJV8C0Vvj9jWnVWKLnqI4p7cUNoFjRbZbjoALQbueC1Y4UgqNkQwyuD94OJcWqFXPnEkRvp X-Received: by 2002:a17:906:951:: with SMTP id j17mr1099021ejd.33.1586883337442; Tue, 14 Apr 2020 09:55:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1586883337; cv=none; d=google.com; s=arc-20160816; b=TrkcHDU0eynPgm9rCX8h6YzFqWdSthr1n/E42j7AkgIS2NCQRt3/W7FsCvpwYe+uWu VkNp9KpYvAZNJpLfj1Jfb/2TRptPJZ6fSRl8afCL001CpwwhVAceIuiKc053aHnY9y9G ++VG1B58Rtnrw/IJqXN3+Zvg8N+Rgpx9pXD/VCk/nN0abuuotTo9ePdgVCZNjIvmHS4u jMOviSsEo2stmvmk2cCVU3FCH7Nx5AFo3hLXMYUZoN74lxki4g4P5wm1KXvv69Ago9pi sthkXZ1kqy5G0blt/FMaRuz74yLgLTGl+MqOqZik6zxvpdsfOG2PbpL8mvmFVgEKUEDw 8ZMA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=hZ2ZtNnGXnyUgL1WENewzG8fdgRXTiQCFKmqoVMaPAQ=; b=dp07KEX3JZ6vO9VzbOXKsSnNqqTmbpVfp1csF2e7fo8yQCdt+LEUlZh+V05Q+vpQsR 5UyRATRN/43E7LTXHCJb5lne5zv8YKXvsqs1p/gQHhuy3pXGkq3Frp7jgi7+VOQ4fTpf nkFvjt3+AP/JNj96RwvT/+lhqCR7VKfGNuw5wg0EGFVzGCZP4YioaUhGRZTz+r+Cxp08 hC/ZwUGHxSGG8A+m5f0SEK71rGqjz4/hxMEwEdPTjVEVbZ0ELs7DD1ZrhA6alCVeu+TN AErJK5H0FsxoXr4BQt0jI2zlUc5zAo29Fke9Bklq6kdA0+zrXRyGuJZEutqNtoIBuH3e 2irA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=XdzuMuJK; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id 4si8855325ejw.237.2020.04.14.09.55.13; Tue, 14 Apr 2020 09:55:37 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=XdzuMuJK; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391311AbgDNQFY (ORCPT + 99 others); Tue, 14 Apr 2020 12:05:24 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:22065 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2391295AbgDNQFJ (ORCPT ); Tue, 14 Apr 2020 12:05:09 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1586880307; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=hZ2ZtNnGXnyUgL1WENewzG8fdgRXTiQCFKmqoVMaPAQ=; b=XdzuMuJK1jKJuXP8dg8mvq22iCxURdVHENZzZF7DejPw7TBuj3x3wb64Ov6BoUbFH1svuo bG3WRpKvBcR0gxW4EVFgVR9JeGsLXXqSI2D87BiAy+224csztppScp0L2h6X7I3lGAcf63 ZYjBNqDJio5+VE1O++1hTeDAQWfkP0k= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-148-ugqth5v9OAOHZ9ntkLmB5Q-1; Tue, 14 Apr 2020 12:05:05 -0400 X-MC-Unique: ugqth5v9OAOHZ9ntkLmB5Q-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 25EE18017F6; Tue, 14 Apr 2020 16:05:04 +0000 (UTC) Received: from kamzik.brq.redhat.com (unknown [10.40.194.89]) by smtp.corp.redhat.com (Postfix) with ESMTPS id F33DC1036D2F; Tue, 14 Apr 2020 16:04:41 +0000 (UTC) Date: Tue, 14 Apr 2020 18:04:39 +0200 From: Andrew Jones To: Sean Christopherson Cc: Paolo Bonzini , Christian Borntraeger , Janosch Frank , David Hildenbrand , Cornelia Huck , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Peter Xu , Wainer dos Santos Moschetta Subject: Re: [PATCH 03/10] KVM: selftests: Add util to delete memory region Message-ID: <20200414160439.ca52vt5jgri7jcxw@kamzik.brq.redhat.com> References: <20200410231707.7128-1-sean.j.christopherson@intel.com> <20200410231707.7128-4-sean.j.christopherson@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200410231707.7128-4-sean.j.christopherson@intel.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Apr 10, 2020 at 04:17:00PM -0700, Sean Christopherson wrote: > Add a utility to delete a memory region, it will be used by x86's > set_memory_region_test. > > Signed-off-by: Sean Christopherson > --- > .../testing/selftests/kvm/include/kvm_util.h | 1 + > tools/testing/selftests/kvm/lib/kvm_util.c | 56 +++++++++++++------ > 2 files changed, 40 insertions(+), 17 deletions(-) > > diff --git a/tools/testing/selftests/kvm/include/kvm_util.h b/tools/testing/selftests/kvm/include/kvm_util.h > index 2f329e785c58..d4c3e4d9cd92 100644 > --- a/tools/testing/selftests/kvm/include/kvm_util.h > +++ b/tools/testing/selftests/kvm/include/kvm_util.h > @@ -114,6 +114,7 @@ int _vcpu_ioctl(struct kvm_vm *vm, uint32_t vcpuid, unsigned long ioctl, > void vm_ioctl(struct kvm_vm *vm, unsigned long ioctl, void *arg); > void vm_mem_region_set_flags(struct kvm_vm *vm, uint32_t slot, uint32_t flags); > void vm_mem_region_move(struct kvm_vm *vm, uint32_t slot, uint64_t new_gpa); > +void vm_mem_region_delete(struct kvm_vm *vm, uint32_t slot); > void vm_vcpu_add(struct kvm_vm *vm, uint32_t vcpuid); > vm_vaddr_t vm_vaddr_alloc(struct kvm_vm *vm, size_t sz, vm_vaddr_t vaddr_min, > uint32_t data_memslot, uint32_t pgd_memslot); > diff --git a/tools/testing/selftests/kvm/lib/kvm_util.c b/tools/testing/selftests/kvm/lib/kvm_util.c > index 105ee9bc09f0..ab5b7ea60f4b 100644 > --- a/tools/testing/selftests/kvm/lib/kvm_util.c > +++ b/tools/testing/selftests/kvm/lib/kvm_util.c > @@ -433,34 +433,38 @@ void kvm_vm_release(struct kvm_vm *vmp) > " vmp->kvm_fd: %i rc: %i errno: %i", vmp->kvm_fd, ret, errno); > } > > +static void __vm_mem_region_delete(struct kvm_vm *vm, > + struct userspace_mem_region *region) > +{ > + int ret; > + > + list_del(®ion->list); > + > + region->region.memory_size = 0; > + ret = ioctl(vm->fd, KVM_SET_USER_MEMORY_REGION, ®ion->region); > + TEST_ASSERT(ret == 0, "KVM_SET_USER_MEMORY_REGION IOCTL failed, " > + "rc: %i errno: %i", ret, errno); > + > + sparsebit_free(®ion->unused_phy_pages); > + ret = munmap(region->mmap_start, region->mmap_size); > + TEST_ASSERT(ret == 0, "munmap failed, rc: %i errno: %i", ret, errno); > + > + free(region); > +} > + > /* > * Destroys and frees the VM pointed to by vmp. > */ > void kvm_vm_free(struct kvm_vm *vmp) > { > struct userspace_mem_region *region, *tmp; > - int ret; > > if (vmp == NULL) > return; > > /* Free userspace_mem_regions. */ > - list_for_each_entry_safe(region, tmp, &vmp->userspace_mem_regions, list) { > - list_del(®ion->list); > - > - region->region.memory_size = 0; > - ret = ioctl(vmp->fd, KVM_SET_USER_MEMORY_REGION, > - ®ion->region); > - TEST_ASSERT(ret == 0, "KVM_SET_USER_MEMORY_REGION IOCTL failed, " > - "rc: %i errno: %i", ret, errno); > - > - sparsebit_free(®ion->unused_phy_pages); > - ret = munmap(region->mmap_start, region->mmap_size); > - TEST_ASSERT(ret == 0, "munmap failed, rc: %i errno: %i", > - ret, errno); > - > - free(region); > - } > + list_for_each_entry_safe(region, tmp, &vmp->userspace_mem_regions, list) > + __vm_mem_region_delete(vmp, region); > > /* Free sparsebit arrays. */ > sparsebit_free(&vmp->vpages_valid); > @@ -775,6 +779,24 @@ void vm_mem_region_move(struct kvm_vm *vm, uint32_t slot, uint64_t new_gpa) > ret, errno, slot, new_gpa); > } > > +/* > + * VM Memory Region Delete > + * > + * Input Args: > + * vm - Virtual Machine > + * slot - Slot of the memory region to delete > + * > + * Output Args: None > + * > + * Return: None > + * > + * Delete a memory region. > + */ > +void vm_mem_region_delete(struct kvm_vm *vm, uint32_t slot) > +{ > + __vm_mem_region_delete(vm, memslot2region(vm, slot)); > +} > + > /* > * VCPU mmap Size > * > -- > 2.26.0 > Reviewed-by: Andrew Jones