Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp1058792ybb; Fri, 10 Apr 2020 16:19:48 -0700 (PDT) X-Google-Smtp-Source: APiQypKOBatpwf9vXNLOrDFumIa5/LmiwFxwAKhG8V1gG/PGJsnhiT+449QPgrXXjuNwRpaLeSFL X-Received: by 2002:a37:7347:: with SMTP id o68mr6304207qkc.463.1586560788752; Fri, 10 Apr 2020 16:19:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1586560788; cv=none; d=google.com; s=arc-20160816; b=qMZTBZbLzAfC/wFPTbw8NzosQEI155ISHIgojst22Z08oQsNSPe7JdzZ97QRPCGOcO dgJqYj0IvYGxxr6gl9sKE2q1TsQqBgjUdjA+bSeNKWBbCJ7X6fMfps2OqX+OUcxEqEm1 3LX+7PNbqodicbU2UfPlLFTn05ypJTy828Jj4L3HFTMgftzHungcoDat5UFj1w/tLoGF H7ZaFKIVHJ1s7VnIR9ku4Dh7UmCr0jomYF2cQ5AOYTm4mHdiOmJkqXV0JR6kXuyyZIfc A9A5rO5CNcGV8Q9f4x1+AaZoFA5hUv5t00zP5WRYP8GCjLacGAXp/BgOlFz/9f6VOAuI GWEA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :ironport-sdr:ironport-sdr; bh=YGhEzZJI0EpoTF6Z35hh4klEgy6YNxgA3FFJ3VyRuSA=; b=y40LQfUL6BD9JxHQCJOLzLf/oN4KMH4lMI8q4LBft1gjPdH1Iy/dcWOhhyX1Wayh1S /fafEh8s29lAeJyKylIba6hnHFiDpZElQ696VgdaIWBQf38RHVHE14Nnvfxkxm+o0uQN OdCodBRjMMDiBhhdxmLEFuezWJV66PdUDZnj18RrxL9IQ1qRQpIxEKkaGZUfa7c+tw1t 3dgwVd4U0D86aibkFWwO3hskvt43tqlG3yNFZBMtjeFYkT3ox9jU0aYOQf3OQ7z4Pjpk hgE+jW1Ghl2MaUinjs53Z6BLJji4RB/RgwDzqnE/7wJ8/998am4JZJBOCPmthw+m1N6W ZRyw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 26si2272011qks.280.2020.04.10.16.19.34; Fri, 10 Apr 2020 16:19:48 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726926AbgDJXRr (ORCPT + 99 others); Fri, 10 Apr 2020 19:17:47 -0400 Received: from mga02.intel.com ([134.134.136.20]:20814 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726721AbgDJXRK (ORCPT ); Fri, 10 Apr 2020 19:17:10 -0400 IronPort-SDR: zXaX8TPs9n25n01XElJb20nFOG0I+hqLkbXjz+55XBPF0y5a88KPYKjpCGzOvXcxCDwejlMWqg j1ybAM/6WouA== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Apr 2020 16:17:10 -0700 IronPort-SDR: 2Cu09jbKFyvsJU+NIboKqwB91wTC7sS18HZ68K9UU8zhRc8mGbfSkbfLtQJ+oGUqjjs63AbrEa cHF/j8wCSsjA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.72,368,1580803200"; d="scan'208";a="452542224" Received: from sjchrist-coffee.jf.intel.com ([10.54.74.202]) by fmsmga005.fm.intel.com with ESMTP; 10 Apr 2020 16:17:09 -0700 From: Sean Christopherson To: Paolo Bonzini , Christian Borntraeger , Janosch Frank Cc: David Hildenbrand , Cornelia Huck , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Sean Christopherson , Peter Xu , Andrew Jones , Wainer dos Santos Moschetta Subject: [PATCH 03/10] KVM: selftests: Add util to delete memory region Date: Fri, 10 Apr 2020 16:17:00 -0700 Message-Id: <20200410231707.7128-4-sean.j.christopherson@intel.com> X-Mailer: git-send-email 2.26.0 In-Reply-To: <20200410231707.7128-1-sean.j.christopherson@intel.com> References: <20200410231707.7128-1-sean.j.christopherson@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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