From patchwork Sat Dec 2 09:16:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yan Zhao X-Patchwork-Id: 172763 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp1673438vqy; Sat, 2 Dec 2023 01:46:31 -0800 (PST) X-Google-Smtp-Source: AGHT+IEUOcLBIfLKKGTk/VmEXTXO1CA23pAJEnWC6rkIfuHe836DaKLg2vlIyNMfF0TBbGCe5s6E X-Received: by 2002:a05:6358:2908:b0:16b:fdb2:76fa with SMTP id y8-20020a056358290800b0016bfdb276famr1481217rwb.23.1701510391088; Sat, 02 Dec 2023 01:46:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701510391; cv=none; d=google.com; s=arc-20160816; b=CbikEI3mSYKq6qU2qmq2WEkf7im9K+DjDs4wLZMwnez7lDUsOFiUGDHVeoHfq3tvlp vWDWF9t87BwSmJQBsjYJkBVKwYIWtkRkJohDKDiUOkwZAG3UuswT320eavHZQM9Y1gqB OAdLsDVr38enYnqqXouOFR6ddziRUZGRlVQxp+6LTYsOYSnfp3CZV65RTUOxNbTIoLjU /rpo7z8sxry4NFSj+FwPCUlxwdD8OaOmTa8B4hq3+2v9xnIUipIqnrFqE4qp0rNjcX3h kFXDshlshebTWj2FL6R1UJBeo5trN58yhVG0zjbJckCA9YYW213FXJapWmH2KUFaDOeU S4FA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from:dkim-signature; bh=FMiIkQd1kF37Yo+AWpgxXvQQot48lzBkr7Z1TC/bbmU=; fh=+WI4m5k3dRLR+dR3neThuZkNBTzIm/a8HgtddERL9fA=; b=Bx5v8XVokJ0g/KZxMdswwkNZofj7L5JLrpRHe//zYIWeWDJ0qiXSvNYqPxpbk11b4J E0ydrIoQGYrctAkB5btvgNcXJCzfmOZTrGE6zbYfyFpF9Z4YCZ/tNWzpv6uPNtrLSi72 Z8IEbGHLcp4q/yeUsNmOLvyJur+72WvJNM0IE2ugH8exQc/+YFRt2EVXBjNBMibm7d0g FZjGhp1/NhqPU5Mg6rLT9jD6HhLnBDi6VUAs2QV52hS0dWN0zbGuO+ZfVv1DlLqmUOGA KsY7vBtW0bgeFLLndX8qFArjTO4wAKtcb9blUaVRRa9MKxYMWccryyzE2anI5cTf6ui2 j+qA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=cvnSYbts; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from pete.vger.email (pete.vger.email. [2620:137:e000::3:6]) by mx.google.com with ESMTPS id f8-20020a654008000000b005bde6fae09asi414908pgp.135.2023.12.02.01.46.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 02 Dec 2023 01:46:31 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) client-ip=2620:137:e000::3:6; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=cvnSYbts; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id F3B2280A07FD; Sat, 2 Dec 2023 01:46:06 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232310AbjLBJp6 (ORCPT + 99 others); Sat, 2 Dec 2023 04:45:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44302 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229451AbjLBJp5 (ORCPT ); Sat, 2 Dec 2023 04:45:57 -0500 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.10]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E02B71A6; Sat, 2 Dec 2023 01:46:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1701510364; x=1733046364; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=i9OyDLqUL8MDcPXZYwlSXijUUvemlGAamKue93VaY0k=; b=cvnSYbts+s4GoWYobm/2DkUYUfrDOubaPo2zk169Kai1B3S1t6zn0sRq 4ZrXjgSJEOvrh1W5WAAPAp3UZM9sTPbpekEDKGwDB0rLAUFR0rI+qubzR TN+/ELfGzAOfNsBcAJkgszuYi90xyCJE3c/omEs3ArXUUHDQvAmFRDeZ1 /gWOkuWgQ0RSvZq22tlqcN+Jh/l1oVq7BCeL2ipPPNefMVf55kpWDjjJd 5rNZ2lMIjjwBli7sgjhHt1S/E7gD7l6uXyLLenidaXR6kZk8dsxrPV+lp wJeWZ78jz03rDZzUjukKn0onBtjnh3w6yeJjq8N3y6mGHnLFalrx3Ba4D w==; X-IronPort-AV: E=McAfee;i="6600,9927,10911"; a="6886198" X-IronPort-AV: E=Sophos;i="6.04,245,1695711600"; d="scan'208";a="6886198" Received: from orsmga006.jf.intel.com ([10.7.209.51]) by orvoesa102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Dec 2023 01:46:03 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10911"; a="746278747" X-IronPort-AV: E=Sophos;i="6.04,245,1695711600"; d="scan'208";a="746278747" Received: from yzhao56-desk.sh.intel.com ([10.239.159.62]) by orsmga006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Dec 2023 01:45:59 -0800 From: Yan Zhao To: iommu@lists.linux.dev, kvm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: alex.williamson@redhat.com, jgg@nvidia.com, pbonzini@redhat.com, seanjc@google.com, joro@8bytes.org, will@kernel.org, robin.murphy@arm.com, kevin.tian@intel.com, baolu.lu@linux.intel.com, dwmw2@infradead.org, yi.l.liu@intel.com, Yan Zhao Subject: [RFC PATCH 05/42] KVM: Embed "arch" object and call arch init/destroy in TDP FD Date: Sat, 2 Dec 2023 17:16:59 +0800 Message-Id: <20231202091659.13707-1-yan.y.zhao@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20231202091211.13376-1-yan.y.zhao@intel.com> References: <20231202091211.13376-1-yan.y.zhao@intel.com> X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (pete.vger.email [0.0.0.0]); Sat, 02 Dec 2023 01:46:07 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784162959918534628 X-GMAIL-MSGID: 1784162959918534628 Embed "arch" object in private "kvm_exported_tdp" object of KVM TDP FD object in order to associate a TDP page table to this private object. With later patches for arch x86, the overall data structure hierarchy on x86 for TDP FD to export TDP is outlined below for preview. kvm_tdp_fd .------ | ops-|-->kvm_exported_tdp_ops | file | public ----------------------------------------------------------------------- | priv-|-->kvm_exported_tdp private '------' .-----------. | tdp_fd | | as_id | | kvm | | importers | | arch -|-->kvm_arch_exported_tdp | list_node | .------. '-----------' | mmu -|--> kvm_exported_tdp_mmu | meta | .-----------. '--|---' | common -|--> kvm_mmu_common | | root_page | | '-----------' | | | +-->kvm_exported_tdp_meta_vmx .--------------------. | type | | level | | root_hpa | | max_huge_page_level| | rsvd_bits_mask | '--------------------' Signed-off-by: Yan Zhao --- include/linux/kvm_host.h | 17 +++++++++++++++++ virt/kvm/tdp_fd.c | 12 +++++++++--- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h index 122f47c94ecae..5a74b2b0ac81f 100644 --- a/include/linux/kvm_host.h +++ b/include/linux/kvm_host.h @@ -2327,6 +2327,9 @@ static inline void kvm_account_pgtable_pages(void *virt, int nr) #ifdef CONFIG_HAVE_KVM_EXPORTED_TDP struct kvm_exported_tdp { +#ifdef __KVM_HAVE_ARCH_EXPORTED_TDP + struct kvm_arch_exported_tdp arch; +#endif struct kvm_tdp_fd *tdp_fd; struct kvm *kvm; @@ -2335,5 +2338,19 @@ struct kvm_exported_tdp { struct list_head list_node; }; +#ifdef __KVM_HAVE_ARCH_EXPORTED_TDP +int kvm_arch_exported_tdp_init(struct kvm *kvm, struct kvm_exported_tdp *tdp); +void kvm_arch_exported_tdp_destroy(struct kvm_exported_tdp *tdp); +#else +static inline int kvm_arch_exported_tdp_init(struct kvm *kvm, + struct kvm_exported_tdp *tdp) +{ + return -EOPNOTSUPP; +} +static inline void kvm_arch_exported_tdp_destroy(struct kvm_exported_tdp *tdp) +{ +} +#endif /* __KVM_HAVE_ARCH_EXPORTED_TDP */ + #endif /* CONFIG_HAVE_KVM_EXPORTED_TDP */ #endif diff --git a/virt/kvm/tdp_fd.c b/virt/kvm/tdp_fd.c index a5c4c3597e94f..7e68199ea9643 100644 --- a/virt/kvm/tdp_fd.c +++ b/virt/kvm/tdp_fd.c @@ -52,17 +52,20 @@ int kvm_create_tdp_fd(struct kvm *kvm, struct kvm_create_tdp_fd *ct) goto out; } tdp->kvm = kvm; + ret = kvm_arch_exported_tdp_init(kvm, tdp); + if (ret) + goto out; tdp_fd->file = anon_inode_getfile("tdp_fd", &kvm_tdp_fd_fops, tdp_fd, O_RDWR | O_CLOEXEC); if (!tdp_fd->file) { ret = -EFAULT; - goto out; + goto out_uninit; } fd = get_unused_fd_flags(O_RDWR | O_CLOEXEC); if (fd < 0) - goto out; + goto out_uninit; fd_install(fd, tdp_fd->file); ct->fd = fd; @@ -73,10 +76,12 @@ int kvm_create_tdp_fd(struct kvm *kvm, struct kvm_create_tdp_fd *ct) spin_unlock(&kvm->exported_tdplist_lock); return 0; -out: +out_uninit: if (tdp_fd->file) fput(tdp_fd->file); + kvm_arch_exported_tdp_destroy(tdp); +out: if (tdp->kvm) kvm_put_kvm_no_destroy(tdp->kvm); kfree(tdp); @@ -102,6 +107,7 @@ static int kvm_tdp_fd_release(struct inode *inode, struct file *file) list_del(&tdp->list_node); spin_unlock(&tdp->kvm->exported_tdplist_lock); + kvm_arch_exported_tdp_destroy(tdp); kvm_put_kvm(tdp->kvm); kfree(tdp); kfree(tdp_fd);