Received: by 2002:a05:7412:31a9:b0:e2:908c:2ebd with SMTP id et41csp3847342rdb; Thu, 14 Sep 2023 04:47:27 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF4iAuqFF6AjkrmdvrbYzhkulhEBQlmoZlYCeUScpkr321Cd+xS67ecNuZYzROUHWDK8XKL X-Received: by 2002:a17:902:d491:b0:1b8:76ce:9dab with SMTP id c17-20020a170902d49100b001b876ce9dabmr6321566plg.41.1694692046859; Thu, 14 Sep 2023 04:47:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694692046; cv=none; d=google.com; s=arc-20160816; b=Yh/biqpNHJ7jcZ7JnUq31zKrqTocrSFmhRdNB1rMo/5w6ufDI6E3DzoxTuCmMuUzHd 7dmudKMyShC8YNBf0QmZN4AgYoxyFvTJ4cPKG0gx1X14uC42BO1lH4zGOBhUAPGhbC9v 9KWsgI2W5RJQIUYr+pqybqnKsLmbA2kKsDkFKfZ3gDe0jaEAvnMj8zPmSDP7eH3QI/mm ngPjOkIC9dNVXIY2koSK3F/8Jtu1gIcfk5z7wCxoVivpuNczo+Bfg600l2/SWtbPyr6C 9Yh9LuwBW9BdmIalc3icMbVQZ24Ct6GtFhi5IoJYLjsKpbbjb/P1n6LEEDvgkCXQ5kY3 aIzg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:reply-to:dkim-signature; bh=f+Cn7aLXsoRGXB5YrbWUVJE/B3mEfo3u49dlyQ3c6p4=; fh=61hsfVoef5Tbbo+Rm06/Hxsz4fAtyORDF8Po5ZVRZDI=; b=quzvUnNHmF8UKsZ4RjBZHU3xkHUqh09QHOL/IiCju8tYNKYBIkCIVg/rCG5ONI5tc8 elkELXJnhFt58CHjGc1TsMJMlh2yTFlhCwwP+DqjHzvU2FQ7YFbT3WUgql7gq0NinjBt indDRv4q6m6AEZHq0ep1ACgcqurl+YlztSt2vNzRZlAjaKj/N8//6BjUaPQ5Qb7J5HwH FFBwgLgHb48zDRB/b/NdiN4b700e6GmTvrvM2Mglf3fJykoyrMXkmhM346LzhAnpA+O+ iL/IUILj9i3oRAjvIjxsZUATfaO/fQRAoMYO3WtAATJVkEvxScB9MbLzwseyfwkoJ9zH JHWw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=ZkdMn9En; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id c17-20020a170902d49100b001b9e9b21287si1681503plg.427.2023.09.14.04.47.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Sep 2023 04:47:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=ZkdMn9En; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id B414083EE9C2; Wed, 13 Sep 2023 19:00:28 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234350AbjINCA2 (ORCPT + 99 others); Wed, 13 Sep 2023 22:00:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58774 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233862AbjINB7e (ORCPT ); Wed, 13 Sep 2023 21:59:34 -0400 Received: from mail-yw1-x1149.google.com (mail-yw1-x1149.google.com [IPv6:2607:f8b0:4864:20::1149]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 48CD735B6 for ; Wed, 13 Sep 2023 18:56:22 -0700 (PDT) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-59bdb9fe821so6911937b3.0 for ; Wed, 13 Sep 2023 18:56:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1694656581; x=1695261381; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:from:to:cc:subject:date:message-id:reply-to; bh=f+Cn7aLXsoRGXB5YrbWUVJE/B3mEfo3u49dlyQ3c6p4=; b=ZkdMn9EnFVm5kC4o5+K3CfgcGW1To6dmvtlY3b1Ve8enp3sXd8IWEJTYj9usKiLhvH Q3RJBkDux71r9EnUIy6QkQspl/2md6ViQ/4maMHMZXLiiU1owR6MfApO/SlUdoBUk5Px fupMXDFjjlBv4ZprRIbHV7DQoyeHcZkXnndmNkNQZXEpKwcIdMq4jy7kV5jk0/l/QciC hUfSQvHbWjmD7KDnirzfoezSwHcdq6RxlDzrEtdoTJtLNLCb5g7xhE02FdoJJ2Fa2IEx cCQq54DuyRcOqYR5VGLwBDO4cIQzgPL8xtrAjxBAvGFVkkzgWShhh8h2PAhQ7izlDUOx apzg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694656581; x=1695261381; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=f+Cn7aLXsoRGXB5YrbWUVJE/B3mEfo3u49dlyQ3c6p4=; b=mzhVN1ystJB06wkBJ4P4RCXjkblHpg6RDZpEyMfYX+8S91sKJ/qgAeZTwvJZ4eT4Rm EUQR7HzIyStc2UtZ/0qmwt25LwBXtbOxCYLnQ5w/iHuFd6bJ39tKPNhXFfAXc7GdO4gs eLdoBaDt24BoQUw/EKIgMUuhXHjjNUggr02uVMITxGL3Ba3dPwyYhuoMQ0jlYHT0DZLb L7MalPOOI1PVsFwZnJqv53U0PP+Dadx72qzyVQKdwnwueEvRNgi3aXKev68O0jyGYVef pAz5B4WUg/tK4LDUcDQh3jZnTNjHcmGgvyo8cfYP4R+LsS17sHRE1eo0t9Kda/AD0mIs kQbw== X-Gm-Message-State: AOJu0YwzlzvjZktblY7nUvIFDc7EeciNzi4y5gLmvBPcPSvWBhvRC+8D Vb3P4Jb9CJHiysGDfDuuIy9cqSLiYR4= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a05:690c:2513:b0:59b:eea4:a5a6 with SMTP id dt19-20020a05690c251300b0059beea4a5a6mr5435ywb.0.1694656581441; Wed, 13 Sep 2023 18:56:21 -0700 (PDT) Reply-To: Sean Christopherson Date: Wed, 13 Sep 2023 18:55:21 -0700 In-Reply-To: <20230914015531.1419405-1-seanjc@google.com> Mime-Version: 1.0 References: <20230914015531.1419405-1-seanjc@google.com> X-Mailer: git-send-email 2.42.0.283.g2d96d420d3-goog Message-ID: <20230914015531.1419405-24-seanjc@google.com> Subject: [RFC PATCH v12 23/33] KVM: selftests: Convert lib's mem regions to KVM_SET_USER_MEMORY_REGION2 From: Sean Christopherson To: Paolo Bonzini , Marc Zyngier , Oliver Upton , Huacai Chen , Michael Ellerman , Anup Patel , Paul Walmsley , Palmer Dabbelt , Albert Ou , Sean Christopherson , "Matthew Wilcox (Oracle)" , Andrew Morton , Paul Moore , James Morris , "Serge E. Hallyn" Cc: kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-mips@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-security-module@vger.kernel.org, linux-kernel@vger.kernel.org, Chao Peng , Fuad Tabba , Jarkko Sakkinen , Anish Moorthy , Yu Zhang , Isaku Yamahata , Xu Yilun , Vlastimil Babka , Vishal Annapurve , Ackerley Tng , Maciej Szmigiero , David Hildenbrand , Quentin Perret , Michael Roth , Wang , Liam Merwick , Isaku Yamahata , "Kirill A . Shutemov" Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Wed, 13 Sep 2023 19:00:29 -0700 (PDT) Use KVM_SET_USER_MEMORY_REGION2 throughough KVM's selftests library so that support for guest private memory can be added without needing an entirely separate set of helpers. Signed-off-by: Sean Christopherson --- .../selftests/kvm/include/kvm_util_base.h | 2 +- tools/testing/selftests/kvm/lib/kvm_util.c | 19 ++++++++++--------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/tools/testing/selftests/kvm/include/kvm_util_base.h b/tools/testing/selftests/kvm/include/kvm_util_base.h index 967eaaeacd75..9f144841c2ee 100644 --- a/tools/testing/selftests/kvm/include/kvm_util_base.h +++ b/tools/testing/selftests/kvm/include/kvm_util_base.h @@ -44,7 +44,7 @@ typedef uint64_t vm_paddr_t; /* Virtual Machine (Guest) physical address */ typedef uint64_t vm_vaddr_t; /* Virtual Machine (Guest) virtual address */ struct userspace_mem_region { - struct kvm_userspace_memory_region region; + struct kvm_userspace_memory_region2 region; struct sparsebit *unused_phy_pages; int fd; off_t offset; diff --git a/tools/testing/selftests/kvm/lib/kvm_util.c b/tools/testing/selftests/kvm/lib/kvm_util.c index f09295d56c23..3676b37bea38 100644 --- a/tools/testing/selftests/kvm/lib/kvm_util.c +++ b/tools/testing/selftests/kvm/lib/kvm_util.c @@ -453,8 +453,9 @@ void kvm_vm_restart(struct kvm_vm *vmp) vm_create_irqchip(vmp); hash_for_each(vmp->regions.slot_hash, ctr, region, slot_node) { - int ret = ioctl(vmp->fd, KVM_SET_USER_MEMORY_REGION, ®ion->region); - TEST_ASSERT(ret == 0, "KVM_SET_USER_MEMORY_REGION IOCTL failed,\n" + int ret = ioctl(vmp->fd, KVM_SET_USER_MEMORY_REGION2, ®ion->region); + + TEST_ASSERT(ret == 0, "KVM_SET_USER_MEMORY_REGION2 IOCTL failed,\n" " rc: %i errno: %i\n" " slot: %u flags: 0x%x\n" " guest_phys_addr: 0x%llx size: 0x%llx", @@ -657,7 +658,7 @@ static void __vm_mem_region_delete(struct kvm_vm *vm, } region->region.memory_size = 0; - vm_ioctl(vm, KVM_SET_USER_MEMORY_REGION, ®ion->region); + vm_ioctl(vm, KVM_SET_USER_MEMORY_REGION2, ®ion->region); sparsebit_free(®ion->unused_phy_pages); ret = munmap(region->mmap_start, region->mmap_size); @@ -1014,8 +1015,8 @@ void vm_userspace_mem_region_add(struct kvm_vm *vm, region->region.guest_phys_addr = guest_paddr; region->region.memory_size = npages * vm->page_size; region->region.userspace_addr = (uintptr_t) region->host_mem; - ret = __vm_ioctl(vm, KVM_SET_USER_MEMORY_REGION, ®ion->region); - TEST_ASSERT(ret == 0, "KVM_SET_USER_MEMORY_REGION IOCTL failed,\n" + ret = __vm_ioctl(vm, KVM_SET_USER_MEMORY_REGION2, ®ion->region); + TEST_ASSERT(ret == 0, "KVM_SET_USER_MEMORY_REGION2 IOCTL failed,\n" " rc: %i errno: %i\n" " slot: %u flags: 0x%x\n" " guest_phys_addr: 0x%lx size: 0x%lx", @@ -1097,9 +1098,9 @@ void vm_mem_region_set_flags(struct kvm_vm *vm, uint32_t slot, uint32_t flags) region->region.flags = flags; - ret = __vm_ioctl(vm, KVM_SET_USER_MEMORY_REGION, ®ion->region); + ret = __vm_ioctl(vm, KVM_SET_USER_MEMORY_REGION2, ®ion->region); - TEST_ASSERT(ret == 0, "KVM_SET_USER_MEMORY_REGION IOCTL failed,\n" + TEST_ASSERT(ret == 0, "KVM_SET_USER_MEMORY_REGION2 IOCTL failed,\n" " rc: %i errno: %i slot: %u flags: 0x%x", ret, errno, slot, flags); } @@ -1127,9 +1128,9 @@ void vm_mem_region_move(struct kvm_vm *vm, uint32_t slot, uint64_t new_gpa) region->region.guest_phys_addr = new_gpa; - ret = __vm_ioctl(vm, KVM_SET_USER_MEMORY_REGION, ®ion->region); + ret = __vm_ioctl(vm, KVM_SET_USER_MEMORY_REGION2, ®ion->region); - TEST_ASSERT(!ret, "KVM_SET_USER_MEMORY_REGION failed\n" + TEST_ASSERT(!ret, "KVM_SET_USER_MEMORY_REGION2 failed\n" "ret: %i errno: %i slot: %u new_gpa: 0x%lx", ret, errno, slot, new_gpa); } -- 2.42.0.283.g2d96d420d3-goog