From patchwork Thu Sep 14 01:55:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 13384030 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4338BEE0212 for ; Thu, 14 Sep 2023 01:56:42 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7CA378D0006; Wed, 13 Sep 2023 21:56:24 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7769D8D0001; Wed, 13 Sep 2023 21:56:24 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5A8718D0006; Wed, 13 Sep 2023 21:56:24 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 474FD8D0001 for ; Wed, 13 Sep 2023 21:56:24 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 25A55B429E for ; Thu, 14 Sep 2023 01:56:24 +0000 (UTC) X-FDA: 81233538288.12.C59D261 Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) by imf18.hostedemail.com (Postfix) with ESMTP id 50E561C0015 for ; Thu, 14 Sep 2023 01:56:22 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b="SD/+qdO5"; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf18.hostedemail.com: domain of 3RWgCZQYKCE48uq3zsw44w1u.s421y3AD-220Bqs0.47w@flex--seanjc.bounces.google.com designates 209.85.128.202 as permitted sender) smtp.mailfrom=3RWgCZQYKCE48uq3zsw44w1u.s421y3AD-220Bqs0.47w@flex--seanjc.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1694656582; h=from:from:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=f+Cn7aLXsoRGXB5YrbWUVJE/B3mEfo3u49dlyQ3c6p4=; b=Y/I/mmZHqkv3MhalJtvbuToWvM+9iQX327WAKpLcuC4UQKlxdhPdSFBbpP1dF2B+xufzrd +/w1+NkXy4LROZLzdWoEsccuZIJAYz8KmiYDo1QKf0+jOawMNgFhSa/poW418AjxgsfdNr 2Ck5wVKMIty9WK7KK4UZxg2znCRnimM= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b="SD/+qdO5"; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf18.hostedemail.com: domain of 3RWgCZQYKCE48uq3zsw44w1u.s421y3AD-220Bqs0.47w@flex--seanjc.bounces.google.com designates 209.85.128.202 as permitted sender) smtp.mailfrom=3RWgCZQYKCE48uq3zsw44w1u.s421y3AD-220Bqs0.47w@flex--seanjc.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1694656582; a=rsa-sha256; cv=none; b=JhTAiqM6nW49wox/1kp4JjkI/RL+06n4tuuf2q8bB4WFb7k+HIpVCGyaWg+ibZFQX1t3Gm fCFZafo+cKafBZ9XlkcsFOtX1zGLiqrTfFl1+GzqQGp0rCm3iRWWPvxWqIVFjpQkCCleF6 EGfD5rKE+3q2cpUcSCu9QuS78D/lVok= Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-59b56dab74bso6575637b3.2 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=kvack.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=SD/+qdO5NLWcVazui8ugoI5oCj5IBSEat/oYRXZhr19bZrOVkuGyNhf7G8x9faDoRh lMdd646k3VYUvYSdU0DpC+05Vn/00cEmSU3hOrjEMMLWNG91nxZiA99pzNGQ5cHfk0C8 B06EkTFvufBzyTQeTaJxs/mYaxuaKyFScjgLhMuZIWcrS3QqVe3lK2P68Xu8N9jz+r6o t3Z6kkvD9jHN5VQfhuJfeY5dNJbTBGxvSzcevXIuNO8XiztmxcClYfYDW5pG2+pr2pXX X7yuNzljaNDifBFE9H+h7935xlj4LSC7LTT0WvPl8sA/IvxPo9xNF5wNPQxaZCbmybrd roZg== 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=CfPWVz/EeQi71i1MsBUsJFv2RFzfy4seBvzp5zmuLzBSZu9VeuTNzYjZOn3gho0FEV r2nKG106bweyIV1z9TtgDV9d1wclpAr4gvNYC+Yb26qaw16RIwkg1UCPHvi0THbWe1Md w1zM2Hk7e38YXZ15f7Hb+C2exDNv7/HD5kQ3buM1e1cdg93E+OTZRhLt7+K9PbGktmsi gY98JC3oPp1g+RGZZCw4c8hvpUBN04dHh0CM2GxlY072Qw3j1XtAz7NBhOxXu0+sqVJv GCRwm7vhJnQ9Hy/pl3ZcDkGx/mq3RZNVDhw4bVX2ANDYZz4aTezrCgBpJIG6s1vigr75 +bBg== X-Gm-Message-State: AOJu0YzTgDmOYs0KsycxWTdgDbHN+KCDfiyRUCSzJvPO3SJ0OjlLgXpD hE3ax0svbihZh+tj9yYM1USg7LXdTdk= X-Google-Smtp-Source: AGHT+IGqSdh70dZcwo/Z1+tDjuCpmZBS7POD57w/4oolbNcAVORh1dC9oB0tdW5CJRUNXoVwQDptkL+JHt0= 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" X-Rsp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MciI1UZX0SqXlar1vR nwk/9+Eg DIQ4IrP6X6K/WMXjr1SLw1PwsyeAajTFUuvX9FbxJvnx8iSpsE1KgF+f2e/7EQmaRL2T/3HAIJ2ePGyveXnoXpnNAmVXbW973MFjkq6ISM68QrMTvwk31DGrw6H5xl+wBBHtuaw6G5VLd/8m3rohNf3rWoPrJlpSDpXUmIKmlO1td+JKo2QQgHjnxGmxLRjXDFkW/JFm4Gq2qPIiG+K/EX/8IkrKLYRk/XucFJSsAeaaAssf5Y53jDs+sK+g5cEbTGeOsZldur+5+fJHMGBggg/6NY0lYiK1YxfgiUTB1/Epth+GBxAA6q1XH6K+kwvYJ4BWmeK7w1X7tux12Ig/qZ55IqV0eJNgvNQnsNtbZaHIrEiB9v3G0Rb8Fkih378l/VP0s3VpstSCvwiErsm7IlTf2SF9jzIj3GrkyouVIvPXhFZmAXRATIHLWXaeDl0aIdkqVfAbDkFr//a2QRCq792cbdRyDAzJ8LuSbTH6PbnrkolYfObcASR0GWPTaTR3zFHIr6oHicxyBJvaB3QYw5XW/lJYWyYnS5XAe2osdu6ejpzNAiSw5v1NdqUiKSmwNy8w3Wy0FHyTFHrGXc0M6dwu8KChH8oVW56ZurnokxwBDd1H8cFfOaXU8RjEX5JrrxrsRqhwM/eGGoX0qCkDgRbOmx5/vyJH538EPOlCvemSLOXbdBJdQSrdaGl04gvAL0R58cMU5/aC3SXaRZmwN2EIgjRz4qLQMeX1NNi4+hDllFqMtxIM2lDW8DB+n3O8gRJnKt+owaeY5qzXnmw+PuD3TdPWZ1ahneuf1a36lb7M41atP0PiKTrLZUQ== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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); }