Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp2622843rdg; Mon, 16 Oct 2023 09:39:46 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE2hymgdBKxjDLLGOaMyvRLMNITAa/dcSUWCOBB9y3UANE9KEr/W4mJgssevkKYmWutMDuc X-Received: by 2002:a05:6871:414b:b0:1e9:dfcd:6752 with SMTP id lb11-20020a056871414b00b001e9dfcd6752mr9510831oab.20.1697474385964; Mon, 16 Oct 2023 09:39:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697474385; cv=none; d=google.com; s=arc-20160816; b=lvn0V4TkZH5dR+luw1yYgWQAbMvLPjhvSH78xt04Z0fPjrBbkvgOrhDI96G/AtvSix vtGivcFMMWqy9x2J0gfer6MBx1pSDXfjPQqgqg9lCtYyWRSvchXr4ZYlEzTsj1GWTytp Rbt2zJ2nNqtwEagKJ1lYXnmK17Qurz9reHoKPFtrtYgBBmbdW5pubnw4H+acqosXCpfT ZN/W8lBytp8nWdTWhUP8O8O3YHhYTWDa83IPtHfeDWmddaTXRju9nsn2ixjVw6ggsAw5 /v//VpXL7hSgfSqkstvHOjZQcyjdq/aBcd/ZEoN0JWw0l5HpMmzz9I+Xo6E1+R6VOyCZ eLwA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=/BgLo3bU/nIsbk2fHb05o378oJI7RBQHedarGCpN/LU=; fh=lRdU2Q/1zx5DcPdZuWBjshA5VT5Oc9cEhB1tCFiV0Nw=; b=BjjzWs7dGV/mUf6RHIi1Ih4zFrFp5cx9OwCUBFkb05+8N2Lm1pCGEtlbbJF3E55MEb hGypDqdHrad5ow+Rfm3uC/KvcP8AHFn2nY0p53Sr8MR1sa8iymn0PYSYwm2YnDe4NH09 WjIMG6kDzC5k/wSKe3WDnFtc+F8sFOmMlhGeTlgOKY3X/iGHzmF8QywW0ZAkjIfK5Sv7 kDNudLJZTPlKbv/nx/g+vJTxUCTf60XYt3YDJpBdgHVwe0T/IWz7G0z+VeJcq3OCW58M GYDStI8dGPHPN9j1x006O1hkVG14nN3BKfbFsxM88qpUDXMrJAHkiEa3KNKyfcW5mUZS BQ8A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="bD/fpSG9"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id x15-20020a63170f000000b00578aedd8e8bsi10446981pgl.716.2023.10.16.09.39.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Oct 2023 09:39:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="bD/fpSG9"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 0836F802B405; Mon, 16 Oct 2023 09:39:45 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234290AbjJPQj3 (ORCPT + 99 others); Mon, 16 Oct 2023 12:39:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41240 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234568AbjJPQhu (ORCPT ); Mon, 16 Oct 2023 12:37:50 -0400 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C7AB1728D; Mon, 16 Oct 2023 09:22:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1697473362; x=1729009362; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=/xICi/lxQ3uFDdmNBJiK/bhHHl0zWMlhjZNjgKQB2ys=; b=bD/fpSG9k2YTM3I6/ZHpedWeeibrZ0rmDm3FVekNlDSZKjOCRJ6tdnYT +S3aXKkqBucBGE4vYj2dWlCWrgf7sJsaIWQEoW1UL1xTZ3XL/8de2d4sg URTazTA+UT1U8dPfOyC5rxH3ouF0JqYcjr0T7F9+o35JMWC97xd4RTPys VReZ+ecSjB2wJN6E2vIq1ecweesI00cXCGZQv/d3SYfr1FbQbgmanIp02 eRUyXzmpWY5//QRhdSXeY+kGVNhrDbkVy4r1cgGCgoyRfEOZVmuA9DurN WAJX5whFsoZqBiMxIRRB+/pWgh/nfcSRiQaQK4BBS21eMOMVdk6EfAEvR g==; X-IronPort-AV: E=McAfee;i="6600,9927,10865"; a="364922143" X-IronPort-AV: E=Sophos;i="6.03,229,1694761200"; d="scan'208";a="364922143" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Oct 2023 09:16:11 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10865"; a="1003006478" X-IronPort-AV: E=Sophos;i="6.03,229,1694761200"; d="scan'208";a="1003006478" Received: from ls.sc.intel.com (HELO localhost) ([172.25.112.31]) by fmsmga006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Oct 2023 09:16:11 -0700 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 , chen.bo@intel.com, hang.yuan@intel.com, tina.zhang@intel.com Subject: [PATCH v16 108/116] KVM: TDX: Add a method to ignore for TDX to ignore hypercall patch Date: Mon, 16 Oct 2023 09:15:00 -0700 Message-Id: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Mon, 16 Oct 2023 09:39:45 -0700 (PDT) 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 df84a12aa232..0d0af3fadc75 100644 --- a/arch/x86/kvm/vmx/main.c +++ b/arch/x86/kvm/vmx/main.c @@ -740,6 +740,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)) @@ -1008,7 +1021,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