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 972D6C7EE2D for ; Mon, 27 Feb 2023 08:31:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231983AbjB0Ib5 (ORCPT ); Mon, 27 Feb 2023 03:31:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38626 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232007AbjB0IaW (ORCPT ); Mon, 27 Feb 2023 03:30:22 -0500 Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8FED01E1FE; Mon, 27 Feb 2023 00:27:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1677486425; x=1709022425; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ZWV7hCkAnYam2QtQ43gFRUgp5krxkouJSB0YkN4Z1BQ=; b=WhHOADGfr8S7ldyDtCgwcIzVLy1eGFHdiUFQwXGpo55zujOrA2H5xIRV hyj+03wLDTwhhW3E6wPke4YrO8QOsf3lnHAoGAKgwWOmmN3zfuB/Yr6Uo RIyIAlh1yypZZsYfHQb8wu+o5Kwlz4t9ki51Ggclka73pBehGTkoOgXVz lgtwDOcG0BGybW6HVa7dLdOl32GCKR4pcUvCvlE9wFGzk6Jtw7c3Heiy5 cdKlEW8U6NdJFaChEzPBbxO+21XT8SiTsu0sS0NlAoCoZ1PI5xOyB2UCt 00RFF3nKSUoxvP6rGt8+nwyASDvB/HU2LLAyS5fkgs2C+9ffuSMp8kA2I Q==; X-IronPort-AV: E=McAfee;i="6500,9779,10633"; a="317609111" X-IronPort-AV: E=Sophos;i="5.97,331,1669104000"; d="scan'208";a="317609111" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Feb 2023 00:24:21 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10633"; a="783242448" X-IronPort-AV: E=Sophos;i="5.97,331,1669104000"; d="scan'208";a="783242448" Received: from ls.sc.intel.com (HELO localhost) ([143.183.96.54]) by fmsmga002-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Feb 2023 00:24:21 -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 , Kai Huang , Zhi Wang Subject: [PATCH v12 101/106] KVM: TDX: Add a method to ignore for TDX to ignore hypercall patch Date: Mon, 27 Feb 2023 00:23:40 -0800 Message-Id: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Isaku Yamahata Because guest TD memory is protected, VMM patching guest binary for hypercall instruction isn't possible. Add a method to ignore hypercall patching with a warning. Note: guest TD kernel needs to be modified to use TDG.VP.VMCALL for hypercall. Signed-off-by: Isaku Yamahata --- arch/x86/kvm/vmx/main.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/arch/x86/kvm/vmx/main.c b/arch/x86/kvm/vmx/main.c index 73ea15754102..6a63d99ddf07 100644 --- a/arch/x86/kvm/vmx/main.c +++ b/arch/x86/kvm/vmx/main.c @@ -703,6 +703,19 @@ static u32 vt_get_interrupt_shadow(struct kvm_vcpu *vcpu) return vmx_get_interrupt_shadow(vcpu); } +static void vt_patch_hypercall(struct kvm_vcpu *vcpu, + unsigned char *hypercall) +{ + /* + * Because guest memory is protected, guest can't be patched. TD kernel + * is modified to use TDG.VP.VMCAL for hypercall. + */ + if (KVM_BUG_ON(is_td_vcpu(vcpu), vcpu->kvm)) + return; + + vmx_patch_hypercall(vcpu, hypercall); +} + static void vt_inject_irq(struct kvm_vcpu *vcpu, bool reinjected) { if (is_td_vcpu(vcpu)) @@ -972,7 +985,7 @@ struct kvm_x86_ops vt_x86_ops __initdata = { .update_emulated_instruction = vmx_update_emulated_instruction, .set_interrupt_shadow = vt_set_interrupt_shadow, .get_interrupt_shadow = vt_get_interrupt_shadow, - .patch_hypercall = vmx_patch_hypercall, + .patch_hypercall = vt_patch_hypercall, .inject_irq = vt_inject_irq, .inject_nmi = vt_inject_nmi, .inject_exception = vt_inject_exception, -- 2.25.1