From patchwork Mon Jan 22 23:54:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Isaku Yamahata X-Patchwork-Id: 13526537 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 CF33280023; Mon, 22 Jan 2024 23:56:13 +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=1705967775; cv=none; b=VHS1uyXTnHaGQKjUt7o+QlNkHe9B/F3luM98jnFscc1MzsvlLnY7WJVIelAAz3YfT5DsM0+8+yPJmjsvhHiD8voatBu68I9wEdxIQ2LrmZ36fV5UJoRLkJmnf4NzPxUhZ0P2+ssO4Olk769lOdQINHTEvb7lVYUSLWJoohmwINk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705967775; c=relaxed/simple; bh=NDzqinCAvUqFr69GAWQ6ymS7GapfCevHMH8hVlFGFds=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=bAl+hrgMVomSlTYoYEdmkpLGipkURBeZPas3IaMxyXlm1WEonPL6gOX/Jx49isgI1dOB0I2jodhw1eKofT7DblfEqndKJ5Ow6Z0Kt6HWJtsrI4hkWQ8JfVcF/G5t7q0khxMYOmF1XN18I8EENtl9zUeYfC+czNMHb+eaGuu9FlE= 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=XRcOEWl6; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="XRcOEWl6" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1705967773; x=1737503773; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=NDzqinCAvUqFr69GAWQ6ymS7GapfCevHMH8hVlFGFds=; b=XRcOEWl6WBIcSfm8+UGQUla+5D9d5hf6mDndAmhec/hZowIngaD5WaAQ anB535sE+/sBgKQtscXcjMeGO5FY5g+O31KWgtc5j5pz31pWsjL9TvEhJ 6yBz8xPVsWNCw2MobKljXA5rwCAMmsH6KRCB5afr2vfe0lvS6ca05BhZa qNPAdypt49tOvGkaOvvf8Igq+NtLF5hDM5us/4npo4CWbJ7ppBRGrt8Vz cKVyfxE2dA6KUWYzQO7AOTlInSxbdw6erZFZ6A/HNQtUM1KY3TkRPYa9l tjCK2qbWve66Y6B0KuFprCcORYnViqJNIn8TV9THd/oe3pv38Idr4dg+m A==; X-IronPort-AV: E=McAfee;i="6600,9927,10961"; a="400217937" X-IronPort-AV: E=Sophos;i="6.05,212,1701158400"; d="scan'208";a="400217937" 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:57 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.05,212,1701158400"; d="scan'208";a="27818028" 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:57 -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 113/121] KVM: TDX: Add a method to ignore for TDX to ignore hypercall patch Date: Mon, 22 Jan 2024 15:54:29 -0800 Message-Id: <3de4fd58d341de8419b39f5e6c0171b183e5b86e.1705965635.git.isaku.yamahata@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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 3a5cd705694e..905ff83e66c7 100644 --- a/arch/x86/kvm/vmx/main.c +++ b/arch/x86/kvm/vmx/main.c @@ -744,6 +744,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)) @@ -1012,7 +1025,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,