Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp2666066rwd; Sun, 28 May 2023 21:44:21 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4PXm6l4IgS6c82ZbkRUlVjtUijQTRimutjtZXUCjnbc+YdSEEbgqpIlU8XSQ1b+NNOgd70 X-Received: by 2002:a05:6a20:54a6:b0:10c:8f0c:f81c with SMTP id i38-20020a056a2054a600b0010c8f0cf81cmr7714451pzk.53.1685335461020; Sun, 28 May 2023 21:44:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685335461; cv=none; d=google.com; s=arc-20160816; b=Md2VhXdZKu1+aBR103voX1TWk5P95uU98UPjwCuSfcTRmcXCPnvDAg/05COYKQUsn3 1pkaT+c5aVZ4pHD2YzRGB18HBibMnGr+fySn9fTVTC0C7hX8FZgzN4ENi4T0CuBX2Sy9 IuBwmB5hBsYjk3oTXVHiK+pxBGkzw4TKg+OUVi5M+H/Ir+FMbbxk72l1kZfeNfawaTSB xjBB3dK5dSRwyfGcuVQxlcgyn3Z5RTVCvSyWtOgggB4Okv3ZzJDOY064zYZUWr/y67ZT 8LxY9R73ne4yiOmmUoyyHlt/u5F2zTYwoaHljRTEnbxWSL3590dmOpb2LE+Fy7hFA3c/ jOjw== 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=D3i+ospvLlk6FxPsqqGknK06YP6YtBM1J4zgob94pnM=; b=W0YCyTIx98W6irJYUkl5r41w0jy4PscwnKMjBcg4pWaNFbiKiCY8OdFwZIQxEuS4k/ T0njEi+N46SL+5felbfjPdpba6IIGBK/7kiw6zr6FIdHew7RjF6Di7dSsndxYltaOY8f 8Lpix+KPI2VcHUchZbMbaRe8ZwLpABnNUw1vCLvfD/tx0wbUnEabOPB4lcg7NeopJ760 MSvlybzVfjQ6udAgQOz/AXHeo+t1qspBkYhkvvs67Z3NDowEFa12QTwQCbA/qv4zsBA+ 0RKL2hwELYi5OPOMeVC+Ng5XmtJjTEd9Aim2F+K5hVW5NRZjY/BuAahmMzNb/2ihGWPI loWw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=MJHICeKt; 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 v202-20020a6361d3000000b005287f5fbf5esi4600240pgb.254.2023.05.28.21.44.05; Sun, 28 May 2023 21:44:20 -0700 (PDT) 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=MJHICeKt; 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 S232576AbjE2EfB (ORCPT + 99 others); Mon, 29 May 2023 00:35:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49050 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231991AbjE2E3K (ORCPT ); Mon, 29 May 2023 00:29:10 -0400 Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6B4E81998; Sun, 28 May 2023 21:25:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1685334328; x=1716870328; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=JVQ423flpS6zMEfcjv4HwA+Rc/6Vb8NUaLxVF3cEBYg=; b=MJHICeKtcWP7sRuyAMZ6I8caLSk/2ZABTcJKTgXCwtn829mVliR46gZn 2PRjJGih7mOUdCxlSca5pX6apYiPLzeA4SAYi/KH1xmDMP+57GPd06IeG pASQMoAubB6h52hEOWPCIjJT0wgiWcgvEC59QpTHgbAFhmLr8bTtI0iGb TEU5HygwJixxb9ggNYVxzpqzCbp+s6bBzYptt4sL1zSUrM+4bcCWAjY8Z iQZqXi1faFHKJRzBHgf3CJtmtmZ0rVRfAed+teT3oq+/ERUInZhzIQykL htYqZCnh8US9HsumRBOvQ3zDQUfLYmh+ey3DhdalNrXUfsmgOv/3Cg3TH g==; X-IronPort-AV: E=McAfee;i="6600,9927,10724"; a="356993532" X-IronPort-AV: E=Sophos;i="6.00,200,1681196400"; d="scan'208";a="356993532" Received: from orsmga004.jf.intel.com ([10.7.209.38]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 May 2023 21:21:53 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10724"; a="830223596" X-IronPort-AV: E=Sophos;i="6.00,200,1681196400"; d="scan'208";a="830223596" Received: from ls.sc.intel.com (HELO localhost) ([172.25.112.31]) by orsmga004-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 May 2023 21:21:53 -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 Subject: [PATCH v14 107/113] KVM: TDX: Add a method to ignore for TDX to ignore hypercall patch Date: Sun, 28 May 2023 21:20:29 -0700 Message-Id: <451313eb35308a72dd19c90bc68ceebc16e564ec.1685333728.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.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE 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 23e6caaa4cfc..90a6eb851854 100644 --- a/arch/x86/kvm/vmx/main.c +++ b/arch/x86/kvm/vmx/main.c @@ -724,6 +724,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)) @@ -993,7 +1006,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