From patchwork Sat Dec 2 09:15:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yan Zhao X-Patchwork-Id: 172760 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp1672824vqy; Sat, 2 Dec 2023 01:44:15 -0800 (PST) X-Google-Smtp-Source: AGHT+IERvcMu7x5Wgoz+dslZPeSKZaE5/ZrNcz2TJZs2laUNFsOnWS7gkjttwhAl7SR8bFa+es+5 X-Received: by 2002:a05:6a00:4508:b0:6ce:2e16:3771 with SMTP id cw8-20020a056a00450800b006ce2e163771mr242861pfb.22.1701510255423; Sat, 02 Dec 2023 01:44:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701510255; cv=none; d=google.com; s=arc-20160816; b=b+6oLK7cr0PXqVfTVT3mRIZxbtC+DJ8AF4Gi9/Hh/3TMOV0mOCRG07CjcWYYrntaSu 1g8yCr9FXgktI3ngslfmjWsSd9YMcoHtdO74cvpmtcwdCQbwpvaPaTJPFTDYns08atEU dc5zLxreTi7IS9e4o0cKwQTREFtnLagiSEeaK6yD05IM/x5v9C4xzVc7elt4OrEqSI7+ 3yASMePDtANpIpjS8DqCo+IejEPTDhnMW4mv//nIf8mkIoHg2WvfhrPJux75LQWmEzD6 rrMr/xdJvx3vI3L2LGmVmcE4WdGhGoYFn+9sGwXqiYXFjk7bmYI07N2YuIFaJ6oTf970 I02Q== 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=EHuoUixOnGbYp9alj07dgLStGOBNLp83ShQKRnacKIQ=; fh=+WI4m5k3dRLR+dR3neThuZkNBTzIm/a8HgtddERL9fA=; b=Yweh6CFIyn/UfooiBney9p0EU4qfBHrR1USVUzt9sGGOGy8L0MH2DCm8iYwM3IhUxX DOYIQY1WcD31w2CN7Uh6KFKcWgqm10nwSJXfEn/NojygmjE3g1I+rItH8/WE5yhpVXQD KPq4k4MOqVyg7j4qQOkvY7uym3o1Kk5teExTBaQyutIcG6X4ryorbtL8DOWeo15k3vRP 2UW51mUK6w0nXBandzWYqHsXiEO1ZuNP4ezuPTC2xOqHCIvHGbeL9W+kwQaVaDIf4yjF IKB5oflsCApIiCvd7UbYBXgffZifwUyuupz8CM1FYMG4CSISP3jMH5Ke8OgbWXuLyC7o scSQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=jX5SEbC7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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 snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id z3-20020a63c043000000b00578c64433d5si4616440pgi.877.2023.12.02.01.44.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 02 Dec 2023 01:44:15 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=jX5SEbC7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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 snail.vger.email (Postfix) with ESMTP id 5120B804E809; Sat, 2 Dec 2023 01:44:14 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231982AbjLBJoD (ORCPT + 99 others); Sat, 2 Dec 2023 04:44:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52650 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229451AbjLBJoD (ORCPT ); Sat, 2 Dec 2023 04:44:03 -0500 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.11]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A322D134; Sat, 2 Dec 2023 01:44:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1701510250; x=1733046250; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=USlqd3EMMW16iV2fDYRyDyMhXnAPYPczuIPu2d6BNb0=; b=jX5SEbC74aFHJecVVTiCJTOY+Pt/jWQ8UiSj4vnW1eIyWNWYs81zSLIG sIc4+4RJyPASsSJRR/+8npA2etrkDOMxiK49PraGEKkbF/pZKMztQk2TT 8g1tkA32BAAL3/WtfMN5K6aotm/hvjxJIL00mv47O+AE4wCP/0yW1qXIV PWVi/0BgDQggis2aeuc5pSrgYD2y1pf3fXk9JhhTl/MqylbF3Kj088j8e GaaumgWkTZFP8Q5+ook68MxEKEO/sHaTNMuV1VsMAkL6ZkiAk7S23aGpa a9BN9kCkAi6aaHmN0i9L2b5hr/C74KHO0PzEiJHRkSxoBTRen2i74AhfE g==; X-IronPort-AV: E=McAfee;i="6600,9927,10911"; a="444223" X-IronPort-AV: E=Sophos;i="6.04,245,1695711600"; d="scan'208";a="444223" Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmvoesa105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Dec 2023 01:44:09 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10911"; a="943354101" X-IronPort-AV: E=Sophos;i="6.04,245,1695711600"; d="scan'208";a="943354101" Received: from yzhao56-desk.sh.intel.com ([10.239.159.62]) by orsmga005-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Dec 2023 01:44:05 -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 02/42] KVM: x86: Arch header for kvm to export TDP for Intel Date: Sat, 2 Dec 2023 17:15:04 +0800 Message-Id: <20231202091504.13502-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=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE, SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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 (snail.vger.email [0.0.0.0]); Sat, 02 Dec 2023 01:44:14 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784162817648940346 X-GMAIL-MSGID: 1784162817648940346 Headers to define Intel specific meta data for TDP page tables exported by KVM. The meta data includes page table type, level, HPA of root page, max huge page level, and reserved zero bits currently. (Note, each vendor can define their own meta data format .e.g. it could be kvm_exported_tdp_meta_svm on AMD platform.) The consumer of the exported TDP (e.g. Intel vt-d driver) can retrieve and check the vendor specific meta data before loading the KVM exported TDP page tables to their own secondary MMU. Signed-off-by: Yan Zhao --- arch/x86/include/asm/kvm_exported_tdp.h | 43 +++++++++++++++++++++++++ include/linux/kvm_types.h | 12 +++++++ 2 files changed, 55 insertions(+) create mode 100644 arch/x86/include/asm/kvm_exported_tdp.h diff --git a/arch/x86/include/asm/kvm_exported_tdp.h b/arch/x86/include/asm/kvm_exported_tdp.h new file mode 100644 index 0000000000000..c7fe3f3cf89fb --- /dev/null +++ b/arch/x86/include/asm/kvm_exported_tdp.h @@ -0,0 +1,43 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _ASM_X86_KVM_EXPORTED_TDP_H +#define _ASM_X86_KVM_EXPORTED_TDP_H +#define PT64_ROOT_MAX_LEVEL 5 + +#include +/** + * struct kvm_exported_tdp_meta_vmx - Intel specific meta data format of TDP + * page tables exported by KVM. + * + * Importers of KVM exported TDPs can decode meta data of the page tables with + * this structure. + * + * @type: Type defined across platforms to identify hardware + * platform of a KVM exported TDP. Importers of KVM + * exported TDP need to first check the type before + * decoding page table meta data. + * @level: Levels of the TDP exported by KVM. + * @root_hpa: HPA of the root page of TDP exported by KVM. + * @max_huge_page_level: Max huge page level allowed on the TDP exported by KVM. + * @rsvd_bits_mask: The must-be-zero bits of leaf and non-leaf PTEs. + * rsvd_bits_mask[0] or rsvd_bits_mask[1] is selected by + * bit 7 or a PTE. + * This field is provided as a way for importers to check + * if the must-be-zero bits from KVM is compatible to the + * importer side. KVM will ensure that the must-be-zero + * bits must not be set even for software purpose. + * (e.g. on Intel platform, bit 11 is usually used by KVM + * to identify a present SPTE, though bit 11 is ignored by + * EPT. However, Intel vt-d requires the bit 11 to be 0. + * Before importing KVM TDP, Intel vt-d driver needs to + * check if bit 11 is set in the must-be-zero bits by KVM + * to avoid possible DMAR fault.) + */ +struct kvm_exported_tdp_meta_vmx { + enum kvm_exported_tdp_type type; + int level; + hpa_t root_hpa; + int max_huge_page_level; + u64 rsvd_bits_mask[2][PT64_ROOT_MAX_LEVEL]; +}; + +#endif diff --git a/include/linux/kvm_types.h b/include/linux/kvm_types.h index 6f4737d5046a4..04deb8334ce42 100644 --- a/include/linux/kvm_types.h +++ b/include/linux/kvm_types.h @@ -123,4 +123,16 @@ struct kvm_vcpu_stat_generic { #define KVM_STATS_NAME_SIZE 48 +/** + * enum kvm_exported_tdp_type - Type defined across platforms for TDP exported + * by KVM. + * + * @KVM_TDP_TYPE_EPT: The TDP is of type EPT running on Intel platform. + * + * Currently, @KVM_TDP_TYPE_EPT is the only supported type for TDPs exported by + * KVM. + */ +enum kvm_exported_tdp_type { + KVM_TDP_TYPE_EPT = 1, +}; #endif /* __KVM_TYPES_H__ */