Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp3775894pxv; Mon, 26 Jul 2021 11:43:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwhd4fAM9FkgDCzYToJprteqgHduKbzQ7Y+yGFnZxqqoNon5N97OO/OUrTW7cS0l8rfSmsF X-Received: by 2002:a02:2a88:: with SMTP id w130mr17746134jaw.60.1627324986702; Mon, 26 Jul 2021 11:43:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627324986; cv=none; d=google.com; s=arc-20160816; b=Q9vGKMPiy0rizOcSGhC9uscFWAitqZEPlvAJ6XIvKGYZh/avt8neF+OrXoSG+cM8e+ 1nU9mlB/Jf+T2rZoiCUaz2WtvMPA2ynTTtd/6O6QGEslFaOoWP/Q30zQXB91onfXissA /j2zEFrn/XMO6JrJ/mOeIYZ8zKaLxLD7xY87Rmq9ZQDfMlowCE12Vh3WR/MJCT33KLka dhV9zSKYODfKMfHD8vSgrPNLYKr84ilPFJJXOGLoF8yxH73CrQPeMvi0KbqUc0SOo2f2 fbPpoeLMp+iS9ZOVdgxCJQorlK2+tFPNRbBvkXK4QPv7ikD1wJhI9OQJQ6ZpFclmPGuC yjPQ== 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:references:mime-version :message-id:in-reply-to:date:dkim-signature; bh=8yNu6qbpILTbh+UzH48Yh1lHlgrQw9nlbePevAAANOg=; b=om7KIcAdJPCfWB5hv4u2G/H7Qys6h62QxOpdarcbkAgfYdHyuNlCt5GG9ESDum9nEi FA1QXYOu9rdpzLdhk40DoJ5wOZCFa878HasiIiKoguGQtdh7qrtif4mdNgkriBmGvh3j DmAkj1z/WjcbhOFWK+I1Dd+nIlpSP3BtYco8NC/BzMNMrxhmYNU0QwKMCC8BHbU8N8Op lZhgGdwKwebm/SKT6Wi9ftMxvy7tWzrBisZXHeRZQ4FoiQFFh9nXxUlClumwSdWOo7SP N7bnyVgTufkcQfuk/R4L6HWSgF9vgmsjhsyZ8Iz0G8zOG02bR54ahMP11PeTdDuRAmq8 xxag== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=BQ6cipGm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h3si574588ila.128.2021.07.26.11.42.49; Mon, 26 Jul 2021 11:43:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=BQ6cipGm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231674AbhGZSBS (ORCPT + 99 others); Mon, 26 Jul 2021 14:01:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60674 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231362AbhGZSBR (ORCPT ); Mon, 26 Jul 2021 14:01:17 -0400 Received: from mail-pj1-x104a.google.com (mail-pj1-x104a.google.com [IPv6:2607:f8b0:4864:20::104a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1096AC061757 for ; Mon, 26 Jul 2021 11:41:46 -0700 (PDT) Received: by mail-pj1-x104a.google.com with SMTP id 1-20020a17090a1a41b0290176eb6a7a2dso172448pjl.1 for ; Mon, 26 Jul 2021 11:41:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=8yNu6qbpILTbh+UzH48Yh1lHlgrQw9nlbePevAAANOg=; b=BQ6cipGmLFFAawNsq6cd/QslSsDWcxh/L0hhNO4UuL0lYHSTgbshPfw5nzgolWJ3Ag 7TmKWWgq4/Y4Y8Yh2fkaUu4KgXAXMKgqRMy0zY/0CYYgUqGbJ3xzq75uFIDwfDGoo2tT OxHxH2NbA/BUbQoB7IHbrm8wacMpD9VBnjoeka6zPF7POsIGOaRnRPZckDy1Queg45jM YSQTjMrBia2dBUpUINRjDtfMtAmwyEFcgWPmHhQJM2zqyvRVWTlXIs/HQuhHFgfE9z3R izOUEKZ3NbCjEe6RSqJ9Au1l90EQiFftdccyc/Fx+4FsMKIJQlJGa3fXfxVSVpQKzPjT 380w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=8yNu6qbpILTbh+UzH48Yh1lHlgrQw9nlbePevAAANOg=; b=Rcz0PvB/KBRIUcUqVVUdFRKfiIqcNGwOfTgK5YNjrBlbYgwBlGx9jBBmfRXrgKlErO KO3oUDFa1Tko5VIyhQ9HHtEfrQMsdpj6zVLnyqmFjgh8j36CmdbSC6EMXPCsFExQjPGV f0PtODayVklmJyE8sJx5mbBSNMJ1cWb0Bh292kon5FEM61akGpg/LAZqPIMNzt8VvWTS UGVZKFCw8WvWNJ9qxkxR3c1HBWDhj9tNaqhhhbybK0G5/anhN9cJsiutASRtG+afChRh 1UKUMlHdyUu/1PMXiBR5QkiYG0sFj6XZmel9u59iTn92QVN1sf2kwSMrGJ5WoVpMK5NZ 2/8Q== X-Gm-Message-State: AOAM533FTngzxYB+1S58FN/se8YJY49Iwcyoa4R8wnGnLAwmpK4Ci0BU zKTNF75guvOnTDaKMv38xnKn+LRXtyRB2/wN X-Received: from nehir.kir.corp.google.com ([2620:15c:29:204:e222:115f:790c:cd0f]) (user=erdemaktas job=sendgmr) by 2002:a05:6a00:b46:b029:334:54db:af17 with SMTP id p6-20020a056a000b46b029033454dbaf17mr19321862pfo.26.1627324905486; Mon, 26 Jul 2021 11:41:45 -0700 (PDT) Date: Mon, 26 Jul 2021 11:37:54 -0700 In-Reply-To: <20210726183816.1343022-1-erdemaktas@google.com> Message-Id: <20210726183816.1343022-2-erdemaktas@google.com> Mime-Version: 1.0 References: <20210726183816.1343022-1-erdemaktas@google.com> X-Mailer: git-send-email 2.32.0.432.gabb21c7263-goog Subject: [RFC PATCH 1/4] KVM: selftests: Add support for creating non-default type VMs From: Erdem Aktas To: linux-kselftest@vger.kernel.org Cc: erdemaktas@google.com, Sean Christopherson , Peter Gonda , Marc Orr , Sagi Shahar , Paolo Bonzini , Shuah Khan , Andrew Jones , Ben Gardon , Peter Xu , David Matlack , Emanuele Giuseppe Esposito , Christian Borntraeger , Ricardo Koller , Eric Auger , Yanan Wang , Aaron Lewis , Jim Mattson , Oliver Upton , Vitaly Kuznetsov , Peter Shier , Axel Rasmussen , Zhenzhong Duan , "Maciej S. Szmigiero" , Like Xu , open list , "open list:KERNEL VIRTUAL MACHINE (KVM)" Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Currently vm_create function only creates KVM_X86_LEGACY_VM type VMs. Changing the vm_create function to accept type parameter to create new VM types. Signed-off-by: Erdem Aktas Reviewed-by: Sean Christopherson Reviewed-by: Peter Gonda Reviewed-by: Marc Orr Reviewed-by: Sagi Shahar --- .../testing/selftests/kvm/include/kvm_util.h | 1 + tools/testing/selftests/kvm/lib/kvm_util.c | 29 +++++++++++++++++-- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/tools/testing/selftests/kvm/include/kvm_util.h b/tools/testing/selftests/kvm/include/kvm_util.h index d53bfadd2..c63df42d6 100644 --- a/tools/testing/selftests/kvm/include/kvm_util.h +++ b/tools/testing/selftests/kvm/include/kvm_util.h @@ -88,6 +88,7 @@ int vcpu_enable_cap(struct kvm_vm *vm, uint32_t vcpu_id, void vm_enable_dirty_ring(struct kvm_vm *vm, uint32_t ring_size); struct kvm_vm *vm_create(enum vm_guest_mode mode, uint64_t phy_pages, int perm); +struct kvm_vm *__vm_create(enum vm_guest_mode mode, uint64_t phy_pages, int perm, int type); void kvm_vm_free(struct kvm_vm *vmp); void kvm_vm_restart(struct kvm_vm *vmp, int perm); void kvm_vm_release(struct kvm_vm *vmp); diff --git a/tools/testing/selftests/kvm/lib/kvm_util.c b/tools/testing/selftests/kvm/lib/kvm_util.c index e5fbf16f7..70caa3882 100644 --- a/tools/testing/selftests/kvm/lib/kvm_util.c +++ b/tools/testing/selftests/kvm/lib/kvm_util.c @@ -180,13 +180,36 @@ _Static_assert(sizeof(vm_guest_mode_params)/sizeof(struct vm_guest_mode_params) * Return: * Pointer to opaque structure that describes the created VM. * - * Creates a VM with the mode specified by mode (e.g. VM_MODE_P52V48_4K). + * Wrapper VM Create function to create a VM with default type (0). + */ +struct kvm_vm *vm_create(enum vm_guest_mode mode, uint64_t phy_pages, int perm) +{ + return __vm_create(mode, phy_pages, perm, 0); +} + +/* + * VM Create with a custom type + * + * Input Args: + * mode - VM Mode (e.g. VM_MODE_P52V48_4K) + * phy_pages - Physical memory pages + * perm - permission + * type - VM type + * + * Output Args: None + * + * Return: + * Pointer to opaque structure that describes the created VM. + * + * Creates a VM with the mode specified by mode (e.g. VM_MODE_P52V48_4K) and the + * type specified in type (e.g. KVM_X86_LEGACY_VM, KVM_X86_TDX_VM ...). * When phy_pages is non-zero, a memory region of phy_pages physical pages * is created and mapped starting at guest physical address 0. The file * descriptor to control the created VM is created with the permissions * given by perm (e.g. O_RDWR). */ -struct kvm_vm *vm_create(enum vm_guest_mode mode, uint64_t phy_pages, int perm) +struct kvm_vm *__vm_create(enum vm_guest_mode mode, uint64_t phy_pages, + int perm, int type) { struct kvm_vm *vm; @@ -200,7 +223,7 @@ struct kvm_vm *vm_create(enum vm_guest_mode mode, uint64_t phy_pages, int perm) INIT_LIST_HEAD(&vm->userspace_mem_regions); vm->mode = mode; - vm->type = 0; + vm->type = type; vm->pa_bits = vm_guest_mode_params[mode].pa_bits; vm->va_bits = vm_guest_mode_params[mode].va_bits; -- 2.32.0.432.gabb21c7263-goog