Received: by 2002:a05:7412:5112:b0:fa:6e18:a558 with SMTP id fm18csp172337rdb; Mon, 22 Jan 2024 16:19:22 -0800 (PST) X-Google-Smtp-Source: AGHT+IHmTXIf/7BaPIlF4YbsBPvmVgLcOUnGYKYM6BbDcguyW0YjREPYeZnQmsuoI7ZfYw1CgkHg X-Received: by 2002:a05:6214:2582:b0:684:cf98:391a with SMTP id fq2-20020a056214258200b00684cf98391amr56400qvb.103.1705969161848; Mon, 22 Jan 2024 16:19:21 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705969161; cv=pass; d=google.com; s=arc-20160816; b=MzJ+wWxfZy1x2hOMNPWDAHTLypZCeat4ErQ/eyjBJL6io1isOHJHYYuihDNTlOT5xP 8QWpAprH3WswImQpbMsWS+df8i4bjLxuk1g+qEJniwHm2c3fmSefTdwtEhLqk8yq/mG1 sUGfcKKECXWTIyf7Q6NLFnjvs1rrXIxZiDwtVR0FLqPQzLwaOT7ej0SdNbJ++qzAEKru /1OgqPo5Tsh/JPt0rSFbDV5dOtOu3bRjXac0mVH5IzSjaIUih8pGNE9MvsV9ufMD3kNp cRMwfYwlmMGRlwlL25M/YtdQGiKebo9QQzJeyxoF0oB2ZPzsLWjBiIm9jZu9cCEnInA+ Tp5Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=W9hOFYMFKUPBYS2ySUk73sDOr6uCIDosa4mOpC0n1WQ=; fh=Itbyk7CEvizIrzGEESCqq3I2tZgG1kc/GkVOa3S7Hsg=; b=Y9TVPKlbkCgDxEZzi8s4PF7yOCFH8+zmoGU+n70eMaI+JC7kzaJDa9vryR/U090URp ofuNTWB8aSyRzGIF925ulRKaHxZhsSwucc9GC8TDaQjoUycGfBRqXIFPStJPsxri6c4H RyY0T8hFt4pEiK1zM9xpZf9IDpYxGpD33kHOw+h+CGFC8nH1u8+C8V2RlAUD7vH5uM7m vPsQLHF71FRLKRECgW0mXZWp+FhOHNUbLqM/dDxTM19Q3WgwTOXElzgFYn21prh/HtwH pajGPalUZxeOjEqc3CbeW3nHDuzhdSkMUe+zMdK1/GVRhpCtER1q07IBXPoowj5F1bLw yHtQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=WMtblFXD; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-34419-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-34419-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id x16-20020a0cb210000000b0068028d3a037si6915398qvd.154.2024.01.22.16.19.21 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Jan 2024 16:19:21 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-34419-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=WMtblFXD; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-34419-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-34419-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 9A40B1C268B9 for ; Tue, 23 Jan 2024 00:19:21 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 749957FBCD; Mon, 22 Jan 2024 23:56:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="WMtblFXD" Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C495A7E783; Mon, 22 Jan 2024 23:56:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.55.52.120 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705967772; cv=none; b=CR2Sf75HkPkhh5I8VFzBe7mHp8jCyRXmh8irpqJ5UMwX22Yu4R7xYslSyPtm+fyWYnZmYR8MWBUzAYmXy9i+u9M5wOZBj5F3V9wXswu1Y/BXRFfR4VB+tFgw/0fIS7dAl5odxmxHbrwCTo8Nm5yCyjb3CuVKNg5tr5HX8AMbiFA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705967772; c=relaxed/simple; bh=fWkG+QnbDV5OyHOrKYrSw9rXQ9AWwBja2tgCFwvWsXs=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=kX7gYwbAawW4Iw2tWgnee2ix3tZU/waLrlaf0IzRZrb1nDsHR0fHuqx2StfiQJyqsGrakGLnf9Q2h6NQ0BZNoDqhHaecHAYcTgg95FeK2pczSO/lfBMdsu3vVwFAK4ct4vE8T1mpk6abM/ecc51IZamExs81c0C+T7Z5nBSd9u0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=WMtblFXD; arc=none smtp.client-ip=192.55.52.120 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1705967770; x=1737503770; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=fWkG+QnbDV5OyHOrKYrSw9rXQ9AWwBja2tgCFwvWsXs=; b=WMtblFXDu28kZEZxZg1whk5O1amcW58/5UBqI34VyzyUeGH0ubtRfPCW /8TEiL7JH8xdTbYTrqtTMoxbfS7Rnr1yGO2epkVmjLsARmXuh5KjO0uB7 3pGTVCDdQzigvnmY95yhCJCRi9hV0gIbMJs8gsAcnUFEQmxlvgYTfaD8y Bgm8mpjRaYxXYpJQKl5YmqVFKYgzloetnb4wbC/yo5rS/8aFwkdhmB43r f+b1HX7QOczKA5KwDef6WY3CHaG6/VcCMAApRfSYC/WyhV/EoXaSrR1SF Ai38Poq8JR/ja5uKRDC5bMRoSaWHQzzrzIlkktj27bJolybHBgPiK8dVq g==; X-IronPort-AV: E=McAfee;i="6600,9927,10961"; a="400217917" X-IronPort-AV: E=Sophos;i="6.05,212,1701158400"; d="scan'208";a="400217917" Received: from fmviesa001.fm.intel.com ([10.60.135.141]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Jan 2024 15:55:56 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.05,212,1701158400"; d="scan'208";a="27818011" Received: from ls.sc.intel.com (HELO localhost) ([172.25.112.31]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Jan 2024 15:55:55 -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 , Kai Huang , chen.bo@intel.com, hang.yuan@intel.com, tina.zhang@intel.com Subject: [PATCH v18 108/121] KVM: TDX: Add methods to ignore guest instruction emulation Date: Mon, 22 Jan 2024 15:54:24 -0800 Message-Id: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 335b94301e2a..420c68330e61 100644 --- a/arch/x86/kvm/vmx/main.c +++ b/arch/x86/kvm/vmx/main.c @@ -335,6 +335,30 @@ static void vt_enable_smi_window(struct kvm_vcpu *vcpu) } #endif +static int vt_check_emulate_instruction(struct kvm_vcpu *vcpu, int emul_type, + void *insn, int insn_len) +{ + if (is_td_vcpu(vcpu)) + return X86EMUL_RETRY_INSTR; + + return vmx_check_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)) @@ -958,7 +982,7 @@ struct kvm_x86_ops vt_x86_ops __initdata = { .load_mmu_pgd = vt_load_mmu_pgd, - .check_intercept = vmx_check_intercept, + .check_intercept = vt_check_intercept, .handle_exit_irqoff = vt_handle_exit_irqoff, .request_immediate_exit = vt_request_immediate_exit, @@ -987,7 +1011,7 @@ struct kvm_x86_ops vt_x86_ops __initdata = { .enable_smi_window = vt_enable_smi_window, #endif - .check_emulate_instruction = vmx_check_emulate_instruction, + .check_emulate_instruction = vt_check_emulate_instruction, .apic_init_signal_blocked = vt_apic_init_signal_blocked, .migrate_timers = vmx_migrate_timers, -- 2.25.1