Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7BF9EC6FD1C for ; Sun, 12 Mar 2023 18:06:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232123AbjCLSG5 (ORCPT ); Sun, 12 Mar 2023 14:06:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51972 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232086AbjCLSFG (ORCPT ); Sun, 12 Mar 2023 14:05:06 -0400 Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E7AED2749E; Sun, 12 Mar 2023 11:00:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1678644058; x=1710180058; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=lC9b+jCMN37urCD3ZweW5IngmqofJ7QkmkiunNN6XdE=; b=Kd9Q/kMMosjTXXRRViAn842CCMJlz+y+PRNzgytPyKNTGIMZkSzXnSlH MwDtOmrzF2/4YTkAKuodgEMKD2YJYB3pBwZ0a+blm6GLY2dvP70dh27Tj XRW8WKjyNI5F1r/VHv0czGYzlJ2sPPy58/5+GC+ajFdul393d3OtDX3DH fGFdMmXmbmJxMqDhB6pABffK5jpmjqMKXuI95v7YivpYNZk1CqsxZ8Q/m RuNKqWddzhhOmhdJFalkGlQoMkjB4nBqH+W+mXbMNpwp9S+qKW0+JgUzu qjEHWx7zKpKomtisCMQxswvvplfWoEnjVD5PqW2/R10I0HfKEe6IMqu7w w==; X-IronPort-AV: E=McAfee;i="6500,9779,10647"; a="316660094" X-IronPort-AV: E=Sophos;i="5.98,254,1673942400"; d="scan'208";a="316660094" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Mar 2023 10:58:15 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10647"; a="742596828" X-IronPort-AV: E=Sophos;i="5.98,254,1673942400"; d="scan'208";a="742596828" Received: from ls.sc.intel.com (HELO localhost) ([143.183.96.54]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Mar 2023 10:58:15 -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 Subject: [PATCH v13 098/113] KVM: TDX: Handle TDX PV map_gpa hypercall Date: Sun, 12 Mar 2023 10:57:02 -0700 Message-Id: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Isaku Yamahata Wire up TDX PV map_gpa hypercall to the kvm/mmu backend. Signed-off-by: Isaku Yamahata --- arch/x86/kvm/vmx/tdx.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/arch/x86/kvm/vmx/tdx.c b/arch/x86/kvm/vmx/tdx.c index 0c6386fe4684..853cfda99fed 100644 --- a/arch/x86/kvm/vmx/tdx.c +++ b/arch/x86/kvm/vmx/tdx.c @@ -1216,6 +1216,24 @@ static int tdx_emulate_wrmsr(struct kvm_vcpu *vcpu) return 1; } +static int tdx_map_gpa(struct kvm_vcpu *vcpu) +{ + struct kvm *kvm = vcpu->kvm; + gpa_t gpa = tdvmcall_a0_read(vcpu); + gpa_t size = tdvmcall_a1_read(vcpu); + gpa_t end = gpa + size; + + if (!IS_ALIGNED(gpa, PAGE_SIZE) || !IS_ALIGNED(size, PAGE_SIZE) || + end < gpa || + end > kvm_gfn_shared_mask(kvm) << (PAGE_SHIFT + 1) || + kvm_is_private_gpa(kvm, gpa) != kvm_is_private_gpa(kvm, end)) { + tdvmcall_set_return_code(vcpu, TDG_VP_VMCALL_INVALID_OPERAND); + return 1; + } + + return tdx_vp_vmcall_to_user(vcpu); +} + static int handle_tdvmcall(struct kvm_vcpu *vcpu) { if (tdvmcall_exit_type(vcpu)) @@ -1241,6 +1259,8 @@ static int handle_tdvmcall(struct kvm_vcpu *vcpu) * guest TD doesn't make sense. No argument check is done. */ return tdx_vp_vmcall_to_user(vcpu); + case TDG_VP_VMCALL_MAP_GPA: + return tdx_map_gpa(vcpu); default: break; } -- 2.25.1