From nobody Mon Feb 9 18:45:34 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1659428893; cv=none; d=zohomail.com; s=zohoarc; b=eAICNMC1Q92OzGDaji6m/yR5w5JxscShQ3WApu9KlogXW85G8bVCW9u7NNsy3A1e9mP3fLMWBNyKSgQcFL8b8ojuKgtCmIHfxcn/hLvrwlsLt6kax6MG+yRbMM9oXTbMNxoq+4ie1BZBPZeaYNZxWs8/ojgWAk9hj4KGQXIkG8Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1659428893; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=O0YXxLphu7ChJGfYvL83gBNhQcCe//we0qTYz4J9bRE=; b=dGsyTLJbxjQIv8Lz9I/c61L1/63A/l3rJ8G9DeBOjASlfGlwWrgkBzYfhpbtDP550Z9q+AV5jZF080VhkpHiIo46Uzw7RYOt6vimX1fbnxT7iLi2t47YyemP1kQ2ivrn+wJX1fS7SAdvdumzGR7TcYSgdj5a+4o3+xdkbEZNwFE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1659428893558378.2974350923241; Tue, 2 Aug 2022 01:28:13 -0700 (PDT) Received: from localhost ([::1]:55698 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oInG8-0004sM-F0 for importer@patchew.org; Tue, 02 Aug 2022 04:28:12 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57958) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oImeP-00052k-S4 for qemu-devel@nongnu.org; Tue, 02 Aug 2022 03:49:18 -0400 Received: from mga07.intel.com ([134.134.136.100]:3339) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oImeN-0005rJ-UQ for qemu-devel@nongnu.org; Tue, 02 Aug 2022 03:49:13 -0400 Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Aug 2022 00:49:10 -0700 Received: from lxy-dell.sh.intel.com ([10.239.48.38]) by orsmga008.jf.intel.com with ESMTP; 02 Aug 2022 00:49:03 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1659426551; x=1690962551; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=b+HzW5c7XvFuB0TCYHRkd1qtT9ZaB9lHKEdvBROcKxs=; b=BOI365/FMGVYPkcJTJCwhgdInyH/pV/VSz3xyaaRSzpPcARW+Za0mmvN 4oTxDEHK1zewq4YXUMXWmKaeDMm8mSGENimwk9BjEk7H8BE77uy1+BTMW 0POeZaUnGv8jcEOHfh91M7GAWAUtnQH/f4ZcssFezqqIKXBw4WV1c+rhA rKSVvswdSqYmn/KuhaVPYIPuJB53BS1SOoxhrO8zKsVFi64JKVJRnsF2x oH7IPblEQvolLnrdz5LV/bVwhUg7EA45eKT4OsojLYbGBie8HL2uPdoWG fOcgZ5qttsdyaRhIqx68gJDcE80aZL2SSMaIP0dDmDz8JF+cctTsK/m0t g==; X-IronPort-AV: E=McAfee;i="6400,9594,10426"; a="353352353" X-IronPort-AV: E=Sophos;i="5.93,210,1654585200"; d="scan'208";a="353352353" X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.93,210,1654585200"; d="scan'208";a="630604052" From: Xiaoyao Li To: Paolo Bonzini , Isaku Yamahata , Gerd Hoffmann , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Richard Henderson , "Michael S . Tsirkin" , Marcel Apfelbaum , Cornelia Huck , Marcelo Tosatti , Laszlo Ersek , Eric Blake Cc: Connor Kuehl , erdemaktas@google.com, kvm@vger.kernel.org, qemu-devel@nongnu.org, seanjc@google.com, xiaoyao.li@intel.com Subject: [PATCH v1 17/40] i386/tdx: Validate TD attributes Date: Tue, 2 Aug 2022 15:47:27 +0800 Message-Id: <20220802074750.2581308-18-xiaoyao.li@intel.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20220802074750.2581308-1-xiaoyao.li@intel.com> References: <20220802074750.2581308-1-xiaoyao.li@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=134.134.136.100; envelope-from=xiaoyao.li@intel.com; helo=mga07.intel.com X-Spam_score_int: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, HK_RANDOM_ENVFROM=0.998, HK_RANDOM_FROM=0.998, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1659428894323100001 Content-Type: text/plain; charset="utf-8" Validate TD attributes with tdx_caps that fixed-0 bits must be zero and fixed-1 bits must be set. Besides, sanity check the attribute bits that have not been supported by QEMU yet. e.g., debug bit, it will be allowed in the future when debug TD support lands in QEMU. Signed-off-by: Xiaoyao Li Acked-by: Gerd Hoffmann --- target/i386/kvm/tdx.c | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/target/i386/kvm/tdx.c b/target/i386/kvm/tdx.c index f2372002077d..42cef484c574 100644 --- a/target/i386/kvm/tdx.c +++ b/target/i386/kvm/tdx.c @@ -30,6 +30,7 @@ (1U << KVM_FEATURE_PV_SCHED_YIELD) | \ (1U << KVM_FEATURE_MSI_EXT_DEST_ID)) =20 +#define TDX_TD_ATTRIBUTES_DEBUG BIT_ULL(0) #define TDX_TD_ATTRIBUTES_SEPT_VE_DISABLE BIT_ULL(28) #define TDX_TD_ATTRIBUTES_PKS BIT_ULL(30) #define TDX_TD_ATTRIBUTES_PERFMON BIT_ULL(63) @@ -462,13 +463,32 @@ int tdx_kvm_init(MachineState *ms, Error **errp) return 0; } =20 -static void setup_td_guest_attributes(X86CPU *x86cpu) +static int tdx_validate_attributes(TdxGuest *tdx) +{ + if (((tdx->attributes & tdx_caps->attrs_fixed0) | tdx_caps->attrs_fixe= d1) !=3D + tdx->attributes) { + error_report("Invalid attributes 0x%lx for TDX VM (fixed0 0x%l= lx, fixed1 0x%llx)", + tdx->attributes, tdx_caps->attrs_fixed0, tdx_cap= s->attrs_fixed1); + return -EINVAL; + } + + if (tdx->attributes & TDX_TD_ATTRIBUTES_DEBUG) { + error_report("Current QEMU doesn't support attributes.debug[bit 0]= for TDX VM"); + return -EINVAL; + } + + return 0; +} + +static int setup_td_guest_attributes(X86CPU *x86cpu) { CPUX86State *env =3D &x86cpu->env; =20 tdx_guest->attributes |=3D (env->features[FEAT_7_0_ECX] & CPUID_7_0_EC= X_PKS) ? TDX_TD_ATTRIBUTES_PKS : 0; tdx_guest->attributes |=3D x86cpu->enable_pmu ? TDX_TD_ATTRIBUTES_PERF= MON : 0; + + return tdx_validate_attributes(tdx_guest); } =20 int tdx_pre_create_vcpu(CPUState *cpu) @@ -484,7 +504,10 @@ int tdx_pre_create_vcpu(CPUState *cpu) goto out; } =20 - setup_td_guest_attributes(x86cpu); + r =3D setup_td_guest_attributes(x86cpu); + if (r) { + goto out; + } =20 memset(&init_vm, 0, sizeof(init_vm)); init_vm.cpuid.nent =3D kvm_x86_arch_cpuid(env, init_vm.entries, 0); --=20 2.27.0