Received: by 2002:a05:6358:a55:b0:ec:fcf4:3ecf with SMTP id 21csp564864rwb; Thu, 12 Jan 2023 09:22:29 -0800 (PST) X-Google-Smtp-Source: AMrXdXs5l+rqvVLftePl1H2XAzXUlhw0yiXS6z4tDy/AYxvLWZb+LkTMFR6LMYP1NkPgJaAdIK4+ X-Received: by 2002:a05:6402:4015:b0:46a:3bd0:4784 with SMTP id d21-20020a056402401500b0046a3bd04784mr75528070eda.7.1673544148944; Thu, 12 Jan 2023 09:22:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673544148; cv=none; d=google.com; s=arc-20160816; b=buC1QvCS+492wgB4xYxJqzJLUjGQGezFRhS13G2J04zB99aFP4M9vK6hU97yGbEbji dGLYupNaNCr9SjdRQY/ILBSmC/RTnX8unduMjicvXb9xpLtrcev5j9SKMPdjSVtnmxiU J5l9QSOrZVUU9ilXSC6x8zRhSfIwpWNPihPfh3M9o8zskiXqV72XE25Q+8bl4wz7n6ng U0MwJjBJiCgxKlV/oQ9krQqSbD/aoeLuGzftnIY+QeZQqHKJ7XbRo0uOdo3FIWVqc5VK cUq0pIgZKNts+KB1dsuSqggERxWtrnbHJeTAaeyri22rhEBP0Zi/V3/P/CrMqgX/14GN 05iA== 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=QVEa2MtcV+mB5IWOOQ1ty/eTor3lfq58k7j4Tbs4vao=; b=ndvIlQHk9s7Cz2j8Ntc8+VFrveuZHK2ytxidzFmjuVH0L3BuLCOwwcnLZCuCb/t9oO xNQEVYrJIFe7Up4NyvjJ7yyproCPoizq8JSSvTLaLmVmzUk4U+8mJwrVSyf5XF95+zlN 7//KDjwFoaDda/DildF2QPc4tSfPDF38wAPW1cxb4YF7DcYPwV4F6Q2J58pTRrJvntVi RT1q7489w2S89EL7IxOY+txCE5ccdvBjOnBVSU0wgZQfMHy51v6uAlzCMH4h4YAKPzjI VctJ+RXnubm8wmcYn4MfMNg64lh15/B/ilQY5rSNsNAQmJUh/ulAPux03CO9WiXz1qHe IcdQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=SkzHrodj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id eo6-20020a056402530600b00482efc40d58si17506359edb.400.2023.01.12.09.22.16; Thu, 12 Jan 2023 09:22:28 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=SkzHrodj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240681AbjALQls (ORCPT + 50 others); Thu, 12 Jan 2023 11:41:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41944 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231249AbjALQha (ORCPT ); Thu, 12 Jan 2023 11:37:30 -0500 Received: from mga06.intel.com (mga06b.intel.com [134.134.136.31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 21B23E097; Thu, 12 Jan 2023 08:33:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1673541230; x=1705077230; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=pilhTCweue1+PbuczyB/QPsyX11hXK2Pngiv7/yacGw=; b=SkzHrodjv7pjPm+frJnSaD0b13z+kyr4TF2r9foecmHkfYDyqg8wXr/W qJ3S030e5QetkU+eBJ8QcaYEjIDBe1MnMnyc/teuHbwYKadLgS1gDHw5k uNeJgPvnmEbRMgEw9QXu4UctJUf6g6soEZsa++PKYYFrIqgM3HaXS6O6q DSrGHwd8KSS02RJgPE7vT6jJ8+gU4fSWmgAaIcHgUV3NZVkCeNVU7cpe3 /D64UBxdFD6tcqXrSbCdNePKprIHvhYHrm5+GBfoA/0D9ye+11HTwA8pp FH3Uyvy9w3pCzChUyfaHWISHWpCYgDDVIqTG968yawKM5afMEmb9b4zxj A==; X-IronPort-AV: E=McAfee;i="6500,9779,10588"; a="386089819" X-IronPort-AV: E=Sophos;i="5.97,211,1669104000"; d="scan'208";a="386089819" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Jan 2023 08:33:39 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10588"; a="726372626" X-IronPort-AV: E=Sophos;i="5.97,211,1669104000"; d="scan'208";a="726372626" Received: from ls.sc.intel.com (HELO localhost) ([143.183.96.54]) by fmsmga004-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Jan 2023 08:33:39 -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 Subject: [PATCH v11 109/113] KVM: TDX: Add a method to ignore for TDX to ignore hypercall patch Date: Thu, 12 Jan 2023 08:32:57 -0800 Message-Id: <5140cd4ba6803ea7de4437ded2c58637106adff5.1673539699.git.isaku.yamahata@intel.com> 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=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, 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 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 b4d1cc3736a6..994ead1b6788 100644 --- a/arch/x86/kvm/vmx/main.c +++ b/arch/x86/kvm/vmx/main.c @@ -642,6 +642,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)) @@ -895,7 +908,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