From patchwork Fri Oct 27 18:22:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 13438958 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 77B77C25B48 for ; Fri, 27 Oct 2023 18:23:49 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2C8C180027; Fri, 27 Oct 2023 14:23:32 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 252A580018; Fri, 27 Oct 2023 14:23:32 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E8F2A80027; Fri, 27 Oct 2023 14:23:31 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id D303E80018 for ; Fri, 27 Oct 2023 14:23:31 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id A7281B60AA for ; Fri, 27 Oct 2023 18:23:31 +0000 (UTC) X-FDA: 81392064222.08.AC741E4 Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) by imf15.hostedemail.com (Postfix) with ESMTP id DE60FA0006 for ; Fri, 27 Oct 2023 18:23:29 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=aJXekSVK; spf=pass (imf15.hostedemail.com: domain of 3IQA8ZQYKCEIwierngksskpi.gsqpmry1-qqozego.svk@flex--seanjc.bounces.google.com designates 209.85.219.202 as permitted sender) smtp.mailfrom=3IQA8ZQYKCEIwierngksskpi.gsqpmry1-qqozego.svk@flex--seanjc.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1698431009; 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=rHCSEdVT91A5ySy8HWpIrikDyrYgztwmDmnD7EhGGWM=; b=wX6uUKSWsOq9Dg8cF3XZIVHFSYoZCTZTKq6518Qoa3DXtyiAVaeoP5b8FEXNPeGgpK+yAL no1ohSNztRj5FpG49rK1Um+ISaTWyz3/HQdQAPUXBrQjfzEXsWM1/nP34nDD2FANV+60PJ aNO2UwFIbTSAo6+pIglTxgEcTfl7z0M= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1698431009; a=rsa-sha256; cv=none; b=jFex/q3ydMY3ZWvkbEXwEObd/cK5EVBXc6N3ODZxWTkwYxpCNzFJv7PwDllhpC+orZ9aWr BsAFGqrPa997lzXcgXCGWdtL1/0yotcqRE3B1AVY5DIx61+w9FDrP72ow+dQ0hkGq+DDAq pZBZ9rXX9Y7S/mECqjExTaKn6HQ6zok= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=aJXekSVK; spf=pass (imf15.hostedemail.com: domain of 3IQA8ZQYKCEIwierngksskpi.gsqpmry1-qqozego.svk@flex--seanjc.bounces.google.com designates 209.85.219.202 as permitted sender) smtp.mailfrom=3IQA8ZQYKCEIwierngksskpi.gsqpmry1-qqozego.svk@flex--seanjc.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-d9bc6447193so1955419276.3 for ; Fri, 27 Oct 2023 11:23:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1698431009; x=1699035809; 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=rHCSEdVT91A5ySy8HWpIrikDyrYgztwmDmnD7EhGGWM=; b=aJXekSVKXAVk3OqEJyEQ+QV5MktM2tPRi3Wusg3mGJ0XGyDdd3ykOT7r1O1i35TUeS VzI8E+zzvuB9xjQ/mN8r8huKHHC80FLc+XUs5lLRczgcQEJ4V11JADsbxlg+hGXUKZR0 ax8XBMmVvdonPRac6n7lJAEch+2M+tSiAO2TVp719n18hze6VKHXxvJV8CYqD12LmDm/ MDq03IoQE3nBXt99Ll8gox4UQmvPot29wmaqKwc4UqvKt1D1E46dwqcJRYBu2pp335Fq ZNCpKeh9gMU5wVc7+8LNFB4MJxyj8ElNTkLjnkHFSFJz39KGkrR6XscDiqlysmy15arA /GRw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698431009; x=1699035809; 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=rHCSEdVT91A5ySy8HWpIrikDyrYgztwmDmnD7EhGGWM=; b=Dn2q2eG9dsfxdJr991tsl2C8E+5R+RT2e9tmTPItsLEEZWoTxM7jyXT/0QUzo8JOxj Qox2SgNti8lx9065yBgjc902twQnaQjJNy3XVpOBnWlpFmnNoLQ7zoWkHoDPRItkYR/i MQ1/lVHu/TB8Y0/wxF+js6aU5Rzd+YAOe6QBlvi6+dnIU65WWNiGqSENVPR56WKBqkxI YE+May0aD5lSOMuJmO27zB2cQvCbDtNqUJ8suiTpq+bj9gSALNHBqYjObQ16y0JXGq1H +JkT68MO7Bbux57MDumExZjnPdFrtyBWNlp0esJ5fhbVCTTJqaJrLiwcLh41q45tGQDZ rwEw== X-Gm-Message-State: AOJu0YwSo1IpSTIJwKIuFQFGbeP/bjKS7PFKtu38MK+tELgixNs8hi6n l+e/OxoBVUCtjlTK12PYnUAX5bh3KE8= X-Google-Smtp-Source: AGHT+IGBlPG7wn0887XfDb8cENXXLGU58G9yJP5jBeCkKIucbC9oYDwWXkdT4FgaevehYCQITd+4fshLciA= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a05:6902:565:b0:da0:c979:fd70 with SMTP id a5-20020a056902056500b00da0c979fd70mr69913ybt.9.1698431009012; Fri, 27 Oct 2023 11:23:29 -0700 (PDT) Reply-To: Sean Christopherson Date: Fri, 27 Oct 2023 11:22:14 -0700 In-Reply-To: <20231027182217.3615211-1-seanjc@google.com> Mime-Version: 1.0 References: <20231027182217.3615211-1-seanjc@google.com> X-Mailer: git-send-email 2.42.0.820.g83a721a137-goog Message-ID: <20231027182217.3615211-33-seanjc@google.com> Subject: [PATCH v13 32/35] 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 , Alexander Viro , Christian Brauner , "Matthew Wilcox (Oracle)" , Andrew Morton 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-kernel@vger.kernel.org, Xiaoyao Li , Xu Yilun , Chao Peng , Fuad Tabba , Jarkko Sakkinen , Anish Moorthy , David Matlack , Yu Zhang , Isaku Yamahata , " =?utf-8?q?Micka=C3=ABl_Sala?= =?utf-8?q?=C3=BCn?= " , Vlastimil Babka , Vishal Annapurve , Ackerley Tng , Maciej Szmigiero , David Hildenbrand , Quentin Perret , Michael Roth , Wang , Liam Merwick , Isaku Yamahata , "Kirill A . Shutemov" X-Stat-Signature: ox4jknmp11mk54napiwoke17wh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z4LsUswkjNiuRqFVrfqBBBakruT/QL270gg7iv7TY79QFT17RFblYgSxnzFAE6VQrZ9OlIiaIuuzIoP6H9EaRX/TAUB6mhSI8m6Fber3K0JjM/iQidZV9WkCtyEsVvgOyRNPHyUDH23ixlFcvP77vSAw3bdywuKczDUTzLOi+p22JkitM3zOjMWnB+zxaHaFSBPgh7z1LUOXv6M57SLgcsPcDPFCoCqe/3+GILdxCAweH9UAp/sfnCNaNgmkF6zqrkDumX7DWMipESa+ENT8ClQvWaRv4wwNp/dA0WwK4nOyQAMhyWA8mLW/I2ndf1wl3rd5wclXfgRN6/n5+BD90pwBaNPEc/8MGTdcTVUoQQR5zm0DjmEfiImqJ1s3IW37DXrIe+MQpMYR3JZVHwTPInLHlJiVFj6pavEF3AANULWH7ekprUuimRhaWVmGu/JAcGJAhHUcGkjg0Oo8uiWQN8b0aPhv+54hiBY7vyNNDUoLxi3hsB00OJf2nZdCvehj1R3++5PxSUOBhSzcTyTu7IC1k2t5DE84VuFz4vGrA5MEiqKGXbEvppu7tIdZyQr3e+XxTZQkKdsCbavpK57p0n4YQ+cI6hg84bK6OJOoB0mIAuq4RF+LzEBxFa0GA314jTPtjUGz49wdp5Jl1CdturNsbdJd0u4Kmz9YEDPE+JJt7dpBs8QDnkxlPfVXiqsddI7xX/Dvw4fO7Xc8U/nJL61In+/lN4sDmB3Ob1i925/+rRbJvNPqD2psfOih2nTbHQ+6SPYza78SVHEzEoloTxxxj8EJfqtZvmSyOyr782a705VmEGKj7nr2BYNAhy60RbCz+9wgA2WbpJTjJgcKl6bwiA== 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: List-Subscribe: List-Unsubscribe: From: Chao Peng Add helpers to invoke KVM_SET_USER_MEMORY_REGION2 directly so that tests can validate of features that are unique to "version 2" of "set user memory region", e.g. do negative testing on gmem_fd and gmem_offset. 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 Signed-off-by: Sean Christopherson --- .../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 157508c071f3..8ec122f5fcc8 100644 --- a/tools/testing/selftests/kvm/include/kvm_util_base.h +++ b/tools/testing/selftests/kvm/include/kvm_util_base.h @@ -522,6 +522,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 guest_memfd, uint64_t guest_memfd_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 guest_memfd, uint64_t guest_memfd_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 52b131e3aca5..1620452c1cf7 100644 --- a/tools/testing/selftests/kvm/lib/kvm_util.c +++ b/tools/testing/selftests/kvm/lib/kvm_util.c @@ -873,6 +873,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 guest_memfd, uint64_t guest_memfd_offset) +{ + struct kvm_userspace_memory_region2 region = { + .slot = slot, + .flags = flags, + .guest_phys_addr = gpa, + .memory_size = size, + .userspace_addr = (uintptr_t)hva, + .guest_memfd = guest_memfd, + .guest_memfd_offset = guest_memfd_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 guest_memfd, uint64_t guest_memfd_offset) +{ + int ret = __vm_set_user_memory_region2(vm, slot, flags, gpa, size, hva, + guest_memfd, guest_memfd_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,