Received: by 2002:a05:7412:5112:b0:fa:6e18:a558 with SMTP id fm18csp172830rdb; Mon, 22 Jan 2024 16:20:36 -0800 (PST) X-Google-Smtp-Source: AGHT+IFmI4CRCiZxYcd1AC5K9RpEwkIL0hZc3uDA961SAgFxsiJoB2Gkuo6UqNDrYto/U4nc2a6p X-Received: by 2002:ac8:5dd2:0:b0:42a:4e74:a657 with SMTP id e18-20020ac85dd2000000b0042a4e74a657mr62019qtx.48.1705969236318; Mon, 22 Jan 2024 16:20:36 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705969236; cv=pass; d=google.com; s=arc-20160816; b=CZ3uSn84xbHjQtfZYeLudXIdp5wlyzbHT6kVAXuArYkJ+k2Ez3/e42RU08K0YlpVqx elrhaYYGAGo38+RiJjGB3Itp3hP+27pQD7gOJee+ed6TZzqnpmP3BxwK10wFk+WlDbyI 1vrH11rbpwXRhv9y6gxV0l7IZi7FtjTu/oEcTGRCH9hN9EZVVkpIL7YdGWtbMWZvPu2E WyWyqNlEEW6JvPls0tBRQUU7/AU6VAP9gwtZv2dXvfM1UyaNbL7adH5ouarQmMVKVtY4 vxsOECOBqUoyxqOhKUjSQ/O4YnJTZy5FWTeCBqK2ZXm38aBq35r6EyD8coSfZkPSaTTu JN6g== 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=rXXCa3N97oTdgGXK0vYmgIAUdNx0A6FSUX6A+SGvZz8=; fh=Itbyk7CEvizIrzGEESCqq3I2tZgG1kc/GkVOa3S7Hsg=; b=aA3ELvq2mvrbAwXS469Rax/6o1zkqKp+uLoqJg36lBdWjw9O/0O58PK2FLdfzUGPM9 IjXNFEoOnoOTu8lZgxHzFhXdJGygUKxHhiBIyCzCxSRdprcg1eQoNP7wiMLX+uLNGvll LBej3uPztlLQIMm4F77og/Bjhc9/CX9yfFtY/6hOn0JK74h63OpyX5vc8Jbk3FY8ywEo WMoednkf9tl6tkS91gjD16vKQbBbJBgW4eU45RKHPSY3SeF9WNA6PtLKkm+rsH0RN75g XKdBiIrv6BtNz2BfipEw/r6rHP5sfkmpV7DywA72ZfcjmcL8TBOUFJPzK5EqBU9ZW5gj x3lg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=XRcOEWl6; 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-34422-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-34422-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. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id u12-20020ac858cc000000b0042a4e7b0f38si298952qta.519.2024.01.22.16.20.36 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Jan 2024 16:20:36 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-34422-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=XRcOEWl6; 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-34422-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-34422-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 5C7071C24C5A for ; Tue, 23 Jan 2024 00:20:33 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 45CE681AB3; Mon, 22 Jan 2024 23:56:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="XRcOEWl6" 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 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: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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, -- 2.25.1