From nobody Mon Sep 15 11:35:36 2025 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A5699C54EBC for ; Thu, 12 Jan 2023 16:40:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240360AbjALQkz (ORCPT ); Thu, 12 Jan 2023 11:40:55 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42570 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235937AbjALQh2 (ORCPT ); Thu, 12 Jan 2023 11:37:28 -0500 Received: from mga06.intel.com (mga06b.intel.com [134.134.136.31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 767A1CE3C; Thu, 12 Jan 2023 08:33:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1673541228; x=1705077228; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=AH4oyT+fB/iCX2Fqde7niFGbiL+vs0/GDQpkC5Xb62I=; b=RsU09ARxIxQfGdOg3wLsrvclrucqcDkdJl5rN7giZAkJEsjGwAZpo7b5 VLY6MLIbJe1EObhOWQns/t8Jpv8ohL1ogE8O7fgHP+q8E1mMLm0//6yzy sE+0Gw7kOhxq6mpM/tGuMDDLd6ceEnzv0SmpRTomvDoD9krnxjySkbiB0 hSm7ZnnvGdRhrojE9Yf6eYnQDlqm2UtyTMFf8RhD4hdrIQfOlFrQrvBuc R+8bfXoT5NuegQs0QkEcGd38kxqVib6nj9soJQzoni/ThILz91jqrqE9t DVm44H1RaIT4TpLcJy2dqZ9FLMfs1VHqSJg0Xp69VgKD/phZgvPn+c6sh Q==; X-IronPort-AV: E=McAfee;i="6500,9779,10588"; a="386089785" X-IronPort-AV: E=Sophos;i="5.97,211,1669104000"; d="scan'208";a="386089785" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Jan 2023 08:33:38 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10588"; a="726372605" X-IronPort-AV: E=Sophos;i="5.97,211,1669104000"; d="scan'208";a="726372605" Received: from ls.sc.intel.com (HELO localhost) ([143.183.96.54]) by fmsmga004-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Jan 2023 08:33:38 -0800 From: isaku.yamahata@intel.com To: kvm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: isaku.yamahata@intel.com, isaku.yamahata@gmail.com, Paolo Bonzini , erdemaktas@google.com, Sean Christopherson , Sagi Shahar , David Matlack Subject: [PATCH v11 104/113] KVM: TDX: Add methods to ignore guest instruction emulation Date: Thu, 12 Jan 2023 08:32:52 -0800 Message-Id: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Isaku Yamahata Because TDX protects TDX guest state from VMM, instructions in guest memory cannot be emulated. Implement methods to ignore guest instruction emulator. Signed-off-by: Isaku Yamahata --- arch/x86/kvm/vmx/main.c | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/arch/x86/kvm/vmx/main.c b/arch/x86/kvm/vmx/main.c index c9d7d8fbd2d7..47c2b6e1e484 100644 --- a/arch/x86/kvm/vmx/main.c +++ b/arch/x86/kvm/vmx/main.c @@ -256,6 +256,30 @@ static void vt_enable_smi_window(struct kvm_vcpu *vcpu) } #endif =20 +static bool vt_can_emulate_instruction(struct kvm_vcpu *vcpu, int emul_typ= e, + void *insn, int insn_len) +{ + if (is_td_vcpu(vcpu)) + return false; + + return vmx_can_emulate_instruction(vcpu, emul_type, insn, insn_len); +} + +static int vt_check_intercept(struct kvm_vcpu *vcpu, + struct x86_instruction_info *info, + enum x86_intercept_stage stage, + struct x86_exception *exception) +{ + /* + * This call back is triggered by the x86 instruction emulator. TDX + * doesn't allow guest memory inspection. + */ + if (KVM_BUG_ON(is_td_vcpu(vcpu), vcpu->kvm)) + return X86EMUL_UNHANDLEABLE; + + return vmx_check_intercept(vcpu, info, stage, exception); +} + static bool vt_apic_init_signal_blocked(struct kvm_vcpu *vcpu) { if (is_td_vcpu(vcpu)) @@ -841,7 +865,7 @@ struct kvm_x86_ops vt_x86_ops __initdata =3D { =20 .load_mmu_pgd =3D vt_load_mmu_pgd, =20 - .check_intercept =3D vmx_check_intercept, + .check_intercept =3D vt_check_intercept, .handle_exit_irqoff =3D vt_handle_exit_irqoff, =20 .request_immediate_exit =3D vt_request_immediate_exit, @@ -870,7 +894,7 @@ struct kvm_x86_ops vt_x86_ops __initdata =3D { .enable_smi_window =3D vt_enable_smi_window, #endif =20 - .can_emulate_instruction =3D vmx_can_emulate_instruction, + .can_emulate_instruction =3D vt_can_emulate_instruction, .apic_init_signal_blocked =3D vt_apic_init_signal_blocked, .migrate_timers =3D vmx_migrate_timers, =20 --=20 2.25.1