From patchwork Tue Jul 18 23:45:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 13317896 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 D3A8DEB64DD for ; Tue, 18 Jul 2023 23:49:40 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C7101280019; Tue, 18 Jul 2023 19:49:24 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id BF91E8D0012; Tue, 18 Jul 2023 19:49:24 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A7341280019; Tue, 18 Jul 2023 19:49:24 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 90F638D0012 for ; Tue, 18 Jul 2023 19:49:24 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 6788F1404BE for ; Tue, 18 Jul 2023 23:49:24 +0000 (UTC) X-FDA: 81026376648.09.AAE8C6D Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) by imf04.hostedemail.com (Postfix) with ESMTP id 818D040012 for ; Tue, 18 Jul 2023 23:49:22 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=YRRA1+3r; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf04.hostedemail.com: domain of 3ASW3ZAYKCFQE0w95y2AA270.yA8749GJ-886Hwy6.AD2@flex--seanjc.bounces.google.com designates 209.85.128.202 as permitted sender) smtp.mailfrom=3ASW3ZAYKCFQE0w95y2AA270.yA8749GJ-886Hwy6.AD2@flex--seanjc.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1689724162; 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=v06h+ALMtOOYf7fX/Ew5y3Hfc7UGMHCjlt3bjyKHsv0=; b=uqud1SMXeQ/9xoZ3XjrIlzPORlRSUdpy+YxqU0Q9thmhHNlFWBUx66EJZ1GUd1zFNZk0JY acofIjYqK3GGKEujhFbKEe/XObXldSi0r8ZUq4Dsnpz8D0WsZxQttEFWH90mZr2Co7+28i zWoLlznO8wKM2fiXTBYa/KdfgB+EXnM= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=YRRA1+3r; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf04.hostedemail.com: domain of 3ASW3ZAYKCFQE0w95y2AA270.yA8749GJ-886Hwy6.AD2@flex--seanjc.bounces.google.com designates 209.85.128.202 as permitted sender) smtp.mailfrom=3ASW3ZAYKCFQE0w95y2AA270.yA8749GJ-886Hwy6.AD2@flex--seanjc.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1689724162; a=rsa-sha256; cv=none; b=ZEbveLFso2uJZU4hFbKo31OXada0oRgLWhHguZ6JSlAQnk0iNcPLfXf4O0nueEqDsxCdYv oc/k+v5bux9/FCLcjTteU0NKtEc32bbWA5Oyb55an3wAcwW8EXdAv+xzsiu+HiWG8/W/el wW9Eh9gj9cNuQrQCF4L/dH+mghjlqds= Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-573cacf4804so55413267b3.1 for ; Tue, 18 Jul 2023 16:49:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1689724161; x=1692316161; 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=v06h+ALMtOOYf7fX/Ew5y3Hfc7UGMHCjlt3bjyKHsv0=; b=YRRA1+3rdyppDplfs3XH3aJvhxtsAMd7YC9o1tjP/IyjupywaQyvKq+rps81DQn6n1 IfT/9T8MBfb/05cpg+uFjPqU9WMKZxQ9fzOPBnRI+m2vIHPLSV2s/3KQGxo5DIXUHwOZ GdmSnQGPnvE14OEYqjCx4Fm+ABerxK8mDpsKlW+8NItJ+M4Kcnqzj3n4Y+k+3R/C1UBu wvL5E8Pm7bjCuwRxFwoKwRUML3nMWrNZ+3vwOtoXEZiYJEJR64OEqgs5nwKpwCN2Ct+r TXr64pWKwZcTWMIuNy53NUZP6UdwEiJkjqYQFxPcJ5UQJleLQ7qGIFzyDTx8Cn3NQNJC aywg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689724161; x=1692316161; 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=v06h+ALMtOOYf7fX/Ew5y3Hfc7UGMHCjlt3bjyKHsv0=; b=Z9xDbG1Og24GrybadQAjsEM97LfXOkM3wV2C2esUhNjsko7ABsbT9yocRfrMviZI58 Hqt1mdhRXJX0mwL7M0q9ZsoDZG+HgYq7tpiglooVrT17yG1NelfVQ8t+7G78WeajJdFg rxs9BrQY85BBZiUPgmp1VhEj8pPKbUeaAzhlQ9kSeyQIl7S0nL3NJWXfzEpy1fv2tcct W+Hj4ZnJ26Cs2IAbGHa+L12t33/W7Ci/LYT3R8Xe7Uqaz+3NjR4EhfHQqNrrq2gby11p XI5qD1lEeN22uWyBIyJm45T48HwALXeOwdqERJjYI2MVyZL1aVhRDpLP78j8N9aCij8N hVrA== X-Gm-Message-State: ABy/qLawtjFyDpdt8F7tj+5Jv5k1dzFq3/OD3BJHX7/ZIi+ikHuj6OO3 95LmKl1tZm4VnNuet5kXh2XJjX+g/TA= X-Google-Smtp-Source: APBJJlHpdLxbHGSEDlhfQMIka8AkYqbvfykkp39Gd8+LzOAP/g6chkA545wiuNlxw+N3wiN86qnMnz3hgbE= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a81:b306:0:b0:56c:fce1:7d8d with SMTP id r6-20020a81b306000000b0056cfce17d8dmr185110ywh.6.1689724161668; Tue, 18 Jul 2023 16:49:21 -0700 (PDT) Reply-To: Sean Christopherson Date: Tue, 18 Jul 2023 16:45:09 -0700 In-Reply-To: <20230718234512.1690985-1-seanjc@google.com> Mime-Version: 1.0 References: <20230718234512.1690985-1-seanjc@google.com> X-Mailer: git-send-email 2.41.0.255.g8b1d071c50-goog Message-ID: <20230718234512.1690985-27-seanjc@google.com> Subject: [RFC PATCH v11 26/29] KVM: selftests: Add KVM_SET_USER_MEMORY_REGION2 helper 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 , Yu Zhang , Vishal Annapurve , Ackerley Tng , Maciej Szmigiero , Vlastimil Babka , David Hildenbrand , Quentin Perret , Michael Roth , Wang , Liam Merwick , Isaku Yamahata , "Kirill A . Shutemov" X-Rspamd-Queue-Id: 818D040012 X-Rspam-User: X-Rspamd-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T OmrGoRXJPSNpBTZSwcp0ftPKqGeLhKNK1qEVUMtSnrmhJ/PK72RiiyRExP3DQvgBVxazrXsxuezvk22DSl2AKmQLTTV1kqu/RseddhMI7aMO8pGlzSXB2v2aueGKbAw4uEcMnlK/QERi+U2QUdUDC+OwC7IHZjO/Pu6whTt8MigezEyknjxZ7HnuolBTLJdVNzT2bUrBWEyPHb3QNaPV7PunbNo1d7olw0+2HLe4FqEC1MmHM0LuZRIbReznrdJfn276a355Ty8bG8K8SHWCwAEYwc/uTHi9QwYy/5d9EadA8C9X5RHsVjyUQ3bFIea/VhQ6uF9GjVisoz8DfZmVl9V9+jOAFr2In7wiEj8uSHVcQSKxD5R27VatxW5aTRxxJO6/UoEliHGjgDqNDoPdAiVcEU2BiKgBirhJwVQbm4FFvLq8WSgLAjmeYxqiikpiueAMBY/CTDiRKqJzkn9B8jnvLR6AAKSThvLTtFbm2My74DZMpfd5BNNTOckHbNVhLsyNBfYfPxUG2yi7yAlMyIlRkz6Gw62/dTInwkHSehn+xu4mtkFLLcRN93ZgY05dAu0GxjwK7+LsjY4VI54g4R7arK0SpAPaWs5oj+WYEKP31K/QZZYw4s7WDneSFl0QFKizxhL7/r9e1wc8quzflBg/LoQrD8DRq6cnKccXhnNv23XKB/EVZtvds7i9JWTNYpdzhOQnFAUKkyYMXifZhqPDVhwDJMyTTpRe7EFmq91Akizcrv1I3qqibaU/RBQ3+JPdX5XcFfa+jN37kOftFecUT7y5KlWNQHqQLKyv9JEmYvvLfsInW/MW3hqUDDee6OEWh4cme4q9eoJkkwYHpQuStGg== 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: From: Chao Peng Provide a raw version as well as an assert-success version to reduce the amount of boilerplate code need for basic usage. Signed-off-by: Chao Peng Signed-off-by: Ackerley Tng --- .../selftests/kvm/include/kvm_util_base.h | 7 +++++ tools/testing/selftests/kvm/lib/kvm_util.c | 29 +++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/tools/testing/selftests/kvm/include/kvm_util_base.h b/tools/testing/selftests/kvm/include/kvm_util_base.h index 856440294013..334df27a6f43 100644 --- a/tools/testing/selftests/kvm/include/kvm_util_base.h +++ b/tools/testing/selftests/kvm/include/kvm_util_base.h @@ -492,6 +492,13 @@ void vm_set_user_memory_region(struct kvm_vm *vm, uint32_t slot, uint32_t flags, uint64_t gpa, uint64_t size, void *hva); int __vm_set_user_memory_region(struct kvm_vm *vm, uint32_t slot, uint32_t flags, uint64_t gpa, uint64_t size, void *hva); +void vm_set_user_memory_region2(struct kvm_vm *vm, uint32_t slot, + uint32_t flags, uint64_t gpa, uint64_t size, + void *hva, uint32_t gmem_fd, uint64_t gmem_offset); +int __vm_set_user_memory_region2(struct kvm_vm *vm, uint32_t slot, + uint32_t flags, uint64_t gpa, uint64_t size, + void *hva, uint32_t gmem_fd, uint64_t gmem_offset); + void vm_userspace_mem_region_add(struct kvm_vm *vm, enum vm_mem_backing_src_type src_type, uint64_t guest_paddr, uint32_t slot, uint64_t npages, diff --git a/tools/testing/selftests/kvm/lib/kvm_util.c b/tools/testing/selftests/kvm/lib/kvm_util.c index 64221c320389..f7b8b5eb3e8f 100644 --- a/tools/testing/selftests/kvm/lib/kvm_util.c +++ b/tools/testing/selftests/kvm/lib/kvm_util.c @@ -868,6 +868,35 @@ void vm_set_user_memory_region(struct kvm_vm *vm, uint32_t slot, uint32_t flags, errno, strerror(errno)); } +int __vm_set_user_memory_region2(struct kvm_vm *vm, uint32_t slot, + uint32_t flags, uint64_t gpa, uint64_t size, + void *hva, uint32_t gmem_fd, uint64_t gmem_offset) +{ + struct kvm_userspace_memory_region2 region = { + .slot = slot, + .flags = flags, + .guest_phys_addr = gpa, + .memory_size = size, + .userspace_addr = (uintptr_t)hva, + .gmem_fd = gmem_fd, + .gmem_offset = gmem_offset, + }; + + return ioctl(vm->fd, KVM_SET_USER_MEMORY_REGION2, ®ion); +} + +void vm_set_user_memory_region2(struct kvm_vm *vm, uint32_t slot, + uint32_t flags, uint64_t gpa, uint64_t size, + void *hva, uint32_t gmem_fd, uint64_t gmem_offset) +{ + int ret = __vm_set_user_memory_region2(vm, slot, flags, gpa, size, hva, + gmem_fd, gmem_offset); + + TEST_ASSERT(!ret, "KVM_SET_USER_MEMORY_REGION2 failed, errno = %d (%s)", + errno, strerror(errno)); +} + + /* FIXME: This thing needs to be ripped apart and rewritten. */ void vm_mem_add(struct kvm_vm *vm, enum vm_mem_backing_src_type src_type, uint64_t guest_paddr, uint32_t slot, uint64_t npages,