From nobody Sat Apr 5 15:05:38 2025 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=1743516163; cv=none; d=zohomail.com; s=zohoarc; b=cGk5Qzr8xUaWxpOP0MSK5FBY8LAXzXtEjNsJGAknGhKH+l9h4E8fj8avh8kXxw4mI/IWReflegc2JeVFrK/Pu+qEtfjfE4aqDBum5EHbIZTqiZVA/FFoqkpOGInAiiah3/Wkg3QGAH5YYeTdYBdfdUWfnwuDhNEruUwLy27TG3w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1743516163; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=s3eVVN/HQgjR9xatBk6jrErFkVEvC/RMcXRjTYEAM4Y=; b=f/lsLRYIzoyMF6/V124k9kiIVtsDA0mI87pohukMTXgM04/1I7PSoX+zl+vNlbp7SBvwFqgBNJSnJTycXgBPTs4CmmlP0om/cSrdMr9A6gcksC5pyUjtQn7uEDg+jhnQPrwkptQ4Q2sP7IRTk5+0VitXohW2h37k8R3TG0pDxBo= 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 174351616338253.175067307180484; Tue, 1 Apr 2025 07:02:43 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tzbyU-0004xC-FN; Tue, 01 Apr 2025 09:48:20 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tzbvN-00026f-Pm for qemu-devel@nongnu.org; Tue, 01 Apr 2025 09:45:06 -0400 Received: from mgamail.intel.com ([192.198.163.16]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tzbvL-0006XQ-St for qemu-devel@nongnu.org; Tue, 01 Apr 2025 09:45:05 -0400 Received: from fmviesa008.fm.intel.com ([10.60.135.148]) by fmvoesa110.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Apr 2025 06:43:27 -0700 Received: from lxy-clx-4s.sh.intel.com ([10.239.48.52]) by fmviesa008.fm.intel.com with ESMTP; 01 Apr 2025 06:43:25 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1743515104; x=1775051104; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Koh+nRw4jmZ1Op1sYV3lYvpDb8Uq9tjL8EWr3Rspt5U=; b=YwVOoZ0tCzwRhjA50VHu5uMVFzUB34cpqf4lTf3OUc/EG3/B6y7Bq38t jJpoYk9sriWk0uk3fq1AlH64UQocuS/Fb6JSkme66JuQznQzLEtnnpg8G JRQfVQfJVcZ9yHpZiIyttC54p9FvFCs+B68gzVHcZ9zgHMVjBSlxcyXVt IDuRrubY0QzKVdnHLwjRicIu5rDM5fynu8wXKofdPX0aMLC+Bsw+fCVmh ox6tQkcaUNbhf+AaUGSyTIP7/5ph6R/fx084woN4sh6ND3BF6P7OBvFyP L9EmFfVZd1m5dyYypSUYSaqGZ9PqdpIJiAZyOTbWjga15Po6voLEUa9ty A==; X-CSE-ConnectionGUID: tU0QZlniQ7KaRuTn05+RCA== X-CSE-MsgGUID: +ojHv8EhTKm8f1CqODKOpw== X-IronPort-AV: E=McAfee;i="6700,10204,11391"; a="32433608" X-IronPort-AV: E=Sophos;i="6.14,293,1736841600"; d="scan'208";a="32433608" X-CSE-ConnectionGUID: 9mN3EbrUSq2Pf/nGt3yShw== X-CSE-MsgGUID: Mmuf2A6TQmSeLar6DINvkQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.14,293,1736841600"; d="scan'208";a="126640302" From: Xiaoyao Li To: Paolo Bonzini , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= Cc: "Michael S. Tsirkin" , Markus Armbruster , Francesco Lavra , Marcelo Tosatti , qemu-devel@nongnu.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Rick Edgecombe , Xiaoyao Li Subject: [PATCH v8 54/55] i386/tdx: Validate phys_bits against host value Date: Tue, 1 Apr 2025 09:02:04 -0400 Message-Id: <20250401130205.2198253-55-xiaoyao.li@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250401130205.2198253-1-xiaoyao.li@intel.com> References: <20250401130205.2198253-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=192.198.163.16; envelope-from=xiaoyao.li@intel.com; helo=mgamail.intel.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.997, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, HK_RANDOM_ENVFROM=0.001, HK_RANDOM_FROM=0.999, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1743516164426019100 Content-Type: text/plain; charset="utf-8" For TDX guest, the phys_bits is not configurable and can only be host/native value. Validate phys_bits inside tdx_check_features(). Signed-off-by: Xiaoyao Li Reviewed-by: Daniel P. Berrang=C3=A9 --- target/i386/host-cpu.c | 2 +- target/i386/host-cpu.h | 1 + target/i386/kvm/tdx.c | 8 ++++++++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/target/i386/host-cpu.c b/target/i386/host-cpu.c index 3e4e85e729c8..8a15af458b05 100644 --- a/target/i386/host-cpu.c +++ b/target/i386/host-cpu.c @@ -15,7 +15,7 @@ #include "system/system.h" =20 /* Note: Only safe for use on x86(-64) hosts */ -static uint32_t host_cpu_phys_bits(void) +uint32_t host_cpu_phys_bits(void) { uint32_t eax; uint32_t host_phys_bits; diff --git a/target/i386/host-cpu.h b/target/i386/host-cpu.h index 6a9bc918baa4..b97ec01c9bec 100644 --- a/target/i386/host-cpu.h +++ b/target/i386/host-cpu.h @@ -10,6 +10,7 @@ #ifndef HOST_CPU_H #define HOST_CPU_H =20 +uint32_t host_cpu_phys_bits(void); void host_cpu_instance_init(X86CPU *cpu); void host_cpu_max_instance_init(X86CPU *cpu); bool host_cpu_realizefn(CPUState *cs, Error **errp); diff --git a/target/i386/kvm/tdx.c b/target/i386/kvm/tdx.c index 8f075ba5a4de..c8fffa94c7d2 100644 --- a/target/i386/kvm/tdx.c +++ b/target/i386/kvm/tdx.c @@ -25,6 +25,7 @@ =20 #include "cpu.h" #include "cpu-internal.h" +#include "host-cpu.h" #include "hw/i386/e820_memory_layout.h" #include "hw/i386/tdvf.h" #include "hw/i386/x86.h" @@ -875,6 +876,13 @@ static int tdx_check_features(X86ConfidentialGuest *cg= , CPUState *cs) return -1; } =20 + if (cpu->phys_bits !=3D host_cpu_phys_bits()) { + error_report("TDX requires guest CPU physical bits (%u) " + "to match host CPU physical bits (%u)", + cpu->phys_bits, host_cpu_phys_bits()); + exit(1); + } + return 0; } =20 --=20 2.34.1