From mboxrd@z Thu Jan 1 00:00:00 1970 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id BA958CD8C9D for ; Mon, 8 Jun 2026 14:43:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=I2tAi1OTnASuVlFhJ1cCmPRkVOKAQHZQQcIMYfbFDVU=; b=y4HBMd2hCD1Vr/ nzLYBgfXxeY+wzkbS4LeoBMWSyPWdrN3Ur9gRlHW+58JVOi2n9VGZSn8ZBpIFe7BqWvVUGdi/j2ha 9txeoF6cbQVANLAN3eVyA84bMpOO22SFnz+dBECsj48WQRtlllHJpntu1HQEquOBM6NX72QT6DVlr YEroiwWMFEppjTjRx67s3WXDl7DympsaKxw0ga4j3pGd/o3R8CtPQiexOnOdOLJEZJrNQrzZCtLPI CY5qQ4Cj9dkV7DR4JQMfMvY/HZcA2M7Z+wDirV03uxC+cVEraiSmEI0raIefPWTMfqi+zdwibvn9H BcmcvJAd4MIvpIznWapg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.99.1 #2 (Red Hat Linux)) id 1wWbC9-00000003pcJ-0wK1; Mon, 08 Jun 2026 14:43:17 +0000 Received: from mail.8bytes.org ([85.214.250.239]) by bombadil.infradead.org with esmtp (Exim 4.99.1 #2 (Red Hat Linux)) id 1wWbC4-00000003pTL-3Z11 for kvm-riscv@lists.infradead.org; Mon, 08 Jun 2026 14:43:14 +0000 Received: from io.home.8bytes.org (p4ffe1d30.dip0.t-ipconnect.de [79.254.29.48]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mail.8bytes.org (Postfix) with ESMTPSA id E5A762028AC; Mon, 8 Jun 2026 16:43:06 +0200 (CEST) From: =?UTF-8?q?J=C3=B6rg=20R=C3=B6del?= To: Paolo Bonzini , Sean Christopherson Cc: Tom Lendacky , ashish.kalra@amd.com, michael.roth@amd.com, nsaenz@amazon.com, anelkz@amazon.de, James.Bottomley@HansenPartnership.com, Melody Wang , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, kvmarm@lists.linux.dev, loongarch@lists.linux.dev, linux-mips@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, kvm-riscv@lists.infradead.org, x86@kernel.org, coconut-svsm@lists.linux.dev, joerg.roedel@amd.com Subject: [PATCH 09/60] kvm: Introduce struct kvm_plane Date: Mon, 8 Jun 2026 16:42:01 +0200 Message-ID: <20260608144252.351443-10-joro@8bytes.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260608144252.351443-1-joro@8bytes.org> References: <20260608144252.351443-1-joro@8bytes.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.9.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20260608_074313_070359_0C6909BA X-CRM114-Status: GOOD ( 13.60 ) X-BeenThere: kvm-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "kvm-riscv" Errors-To: kvm-riscv-bounces+kvm-riscv=archiver.kernel.org@lists.infradead.org From: Paolo Bonzini Introduce a data structure to keep VM-wide per-plane state. Initialize the structure with a back-pointer to struct kvm and the plane level the structure represents. Signed-off-by: Paolo Bonzini Co-developed-by: Joerg Roedel Signed-off-by: Joerg Roedel --- include/linux/kvm_host.h | 7 +++++++ include/uapi/linux/kvm.h | 6 ++++++ virt/kvm/kvm_main.c | 41 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 54 insertions(+) diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h index 4c14aee1fb06..5be4c9f118b4 100644 --- a/include/linux/kvm_host.h +++ b/include/linux/kvm_host.h @@ -767,6 +767,11 @@ struct kvm_memslots { int node_idx; }; +struct kvm_plane { + struct kvm *kvm; + unsigned level; +}; + struct kvm { #ifdef KVM_HAVE_MMU_RWLOCK rwlock_t mmu_lock; @@ -806,6 +811,8 @@ struct kvm { spinlock_t gpc_lock; struct list_head gpc_list; + struct kvm_plane *planes[KVM_MAX_PLANES]; + /* * created_vcpus is protected by kvm->lock, and is incremented * at the beginning of KVM_CREATE_VCPU. online_vcpus is only diff --git a/include/uapi/linux/kvm.h b/include/uapi/linux/kvm.h index 6c8afa2047bf..813f964a6dc1 100644 --- a/include/uapi/linux/kvm.h +++ b/include/uapi/linux/kvm.h @@ -730,6 +730,11 @@ struct kvm_enable_cap { #define KVM_GET_EMULATED_CPUID _IOWR(KVMIO, 0x09, struct kvm_cpuid2) #define KVM_GET_MSR_FEATURE_INDEX_LIST _IOWR(KVMIO, 0x0a, struct kvm_msr_list) +/* + * Maximum number of supported planes + */ +#define KVM_MAX_PLANES 16 + /* * Extension capability list. */ @@ -996,6 +1001,7 @@ struct kvm_enable_cap { #define KVM_CAP_S390_USER_OPEREXEC 246 #define KVM_CAP_S390_KEYOP 247 #define KVM_CAP_S390_VSIE_ESAMODE 248 +#define KVM_CAP_PLANES 249 struct kvm_irq_routing_irqchip { __u32 irqchip; diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index 881f92d7a469..a68469c6d12e 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -1095,6 +1095,38 @@ static inline struct kvm_io_bus *kvm_get_bus_for_destruction(struct kvm *kvm, static int kvm_enable_virtualization(void); static void kvm_disable_virtualization(void); +static struct kvm_plane *kvm_create_plane(struct kvm *kvm, unsigned plane_level) +{ + struct kvm_plane *plane = kzalloc(sizeof(*plane), GFP_KERNEL_ACCOUNT); + + if (!plane) + return NULL; + + plane->kvm = kvm; + plane->level = plane_level; + + kvm->planes[plane_level] = plane; + + return plane; +} + +static void kvm_destroy_one_plane(struct kvm_plane *plane) +{ + kfree(plane); +} + +static void kvm_destroy_planes(struct kvm *kvm) +{ + int i; + + for (i = 0; i < KVM_MAX_PLANES; ++i) { + if (kvm->planes[i] == NULL) + continue; + kvm_destroy_one_plane(kvm->planes[i]); + kvm->planes[i] = NULL; + } +} + static struct kvm *kvm_create_vm(unsigned long type, const char *fdname) { struct kvm *kvm = kvm_arch_alloc_vm(); @@ -1127,6 +1159,12 @@ static struct kvm *kvm_create_vm(unsigned long type, const char *fdname) BUILD_BUG_ON(KVM_MEM_SLOTS_NUM > SHRT_MAX); + /* Initialize planes array and allocate plane 0 */ + if (kvm_create_plane(kvm, 0) == NULL) { + r = -ENOMEM; + goto out_no_planes; + } + /* * Force subsequent debugfs file creations to fail if the VM directory * is not created (by kvm_create_vm_debugfs()). @@ -1225,6 +1263,8 @@ static struct kvm *kvm_create_vm(unsigned long type, const char *fdname) out_err_no_irq_srcu: cleanup_srcu_struct(&kvm->srcu); out_err_no_srcu: + kvm_destroy_planes(kvm); +out_no_planes: kvm_arch_free_vm(kvm); mmdrop(current->mm); return ERR_PTR(r); @@ -1304,6 +1344,7 @@ static void kvm_destroy_vm(struct kvm *kvm) xa_destroy(&kvm->mem_attr_array); #endif kvm_arch_free_vm(kvm); + kvm_destroy_planes(kvm); preempt_notifier_dec(); kvm_disable_virtualization(); mmdrop(mm); -- 2.53.0 -- kvm-riscv mailing list kvm-riscv@lists.infradead.org http://lists.infradead.org/mailman/listinfo/kvm-riscv