Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp3489128rwb; Fri, 30 Sep 2022 04:29:12 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5SRO1F8wUwqs1pPW17clYDlh0xrLVLS8k/oE9WhZNifnvTmTaXF9Z3xD7LZlBvSmMHfix6 X-Received: by 2002:a17:906:cc10:b0:77b:df70:efd2 with SMTP id ml16-20020a170906cc1000b0077bdf70efd2mr6177421ejb.590.1664537351705; Fri, 30 Sep 2022 04:29:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664537351; cv=none; d=google.com; s=arc-20160816; b=sVhp0spW83MVmXGThBkl/u7dT05f1c09fTUAB009tLAJk9A0gSHie4qc0Y7xVPSXiL b//iRj1lRFtCgyBBxXVBQ4e5dcBvkxxk4i7RE3g4O1fOZpk5N5K5uBbrTMICeN0tu8LD yU1QG0xPsslQAuqYKdyQotZbzAirWM46K1XgW9YiA8xRnfZK72JQ1NaNHwfwkkoY2opv fG7VVQ9x+VhdTDfXnVW082oJ2ky+ci4QumpYEmMSF5vv/9FYSS0Tc1PZMGkhfE4GJXiD s37R3mcD23hRSAG2KmnwQ3nQGXD5CUIVv4UUqtdR8hNbiZh70EC4OT/aHLFKUTHf6OZ9 eJAg== 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=D+ZuZsgSjMpuPTHxUgs8ZafcgN+NGgUkHLh1fBGUgi0=; b=KxxDxPOwTFvLfxKM9U/9a52iiLc4avNwO8lNWGxScfUfWukWTz7OblPLbZTrtggNr+ 0yncVLMdQsFVfgAMGWgkNU2sJ5CMf2rFCvXq5ekw/UzdMQ8gTx2FHHUAXDhQSyvX6GMX bi5yZsQ5iG4ag9gQ9stpxjlzcS8sVhPdd3arAVoG+v5o9SaJZvMmOeA0MQyxfRm0FnLr 8GZSIwYNz6R/o/kwFgSzUgEDsBgYrWzIDQw7w48ePu724wTLfxEfLz+Qr7Rl8dkEglmX /Cj/6LCCgW+M20i+tW86LiZbfLnVUZaW84AXN9hAFFzZFEp9geRse7Mf9CtbmuMAqjaS RZnw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Ab01ajwD; 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 i8-20020a05640242c800b0044f231c89edsi2200274edc.20.2022.09.30.04.28.46; Fri, 30 Sep 2022 04:29:11 -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=Ab01ajwD; 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 S232426AbiI3K1y (ORCPT + 99 others); Fri, 30 Sep 2022 06:27:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55170 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232491AbiI3KZY (ORCPT ); Fri, 30 Sep 2022 06:25:24 -0400 Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6D8B236405; Fri, 30 Sep 2022 03:19:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1664533200; x=1696069200; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=CEku3Y+5uD95iizZnUIZvdPui7y5N0fIpv5aBviNf2w=; b=Ab01ajwDbNhkdhb1llHFTlOs4fpcibA4IptKRdH+aQq+4dEfIX5rXaUT b6yGUPVeg7FI966LSnY+M+PncA8JmsJENuX6ingEr2h2/i2K2rZ8TWj1S hWvlub94utUL6OWdIAvktT3xJo4Ppv0F4t/VOrcyuJBKxdMC3nj8dPnRd j8E1vpXvNmucqhe5gDrgC1/F+A3NNQa/P/IcU8nrhrTQ9zduJ6wE8fnhF Cf1+SLFg8Zjv89HzZrKN8Xizaz/Tnpjztj4m42Z8dwyuVC83nCZ0nUu4c bUyhORQyPwslCE2jrr4BZKe+CCw3/C0h2t8r3hjtsHP67WTOsGRl0KHkO w==; X-IronPort-AV: E=McAfee;i="6500,9779,10485"; a="328540179" X-IronPort-AV: E=Sophos;i="5.93,358,1654585200"; d="scan'208";a="328540179" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Sep 2022 03:19:08 -0700 X-IronPort-AV: E=McAfee;i="6500,9779,10485"; a="726807830" X-IronPort-AV: E=Sophos;i="5.93,358,1654585200"; d="scan'208";a="726807830" Received: from ls.sc.intel.com (HELO localhost) ([143.183.96.54]) by fmsmga002-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Sep 2022 03:19:08 -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 Subject: [PATCH v9 098/105] KVM: TDX: Handle TDX PV map_gpa hypercall Date: Fri, 30 Sep 2022 03:18:32 -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=-7.2 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,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 Wire up TDX PV map_gpa hypercall to the kvm/mmu backend. Signed-off-by: Isaku Yamahata --- arch/x86/kvm/vmx/tdx.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/arch/x86/kvm/vmx/tdx.c b/arch/x86/kvm/vmx/tdx.c index a7cf08d60744..6318c0c09c0d 100644 --- a/arch/x86/kvm/vmx/tdx.c +++ b/arch/x86/kvm/vmx/tdx.c @@ -1078,6 +1078,37 @@ static int tdx_report_fatal_error(struct kvm_vcpu *vcpu) return 0; } +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; + gfn_t s = gpa_to_gfn(gpa) & ~kvm_gfn_shared_mask(kvm); + gfn_t e = gpa_to_gfn(end) & ~kvm_gfn_shared_mask(kvm); + bool map_private = kvm_is_private_gpa(kvm, gpa); + int ret; + + if (!IS_ALIGNED(gpa, 4096) || !IS_ALIGNED(size, 4096) || + 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; + } + + ret = kvm_mmu_map_gpa(vcpu, &s, e, map_private); + if (ret == -EAGAIN) { + tdvmcall_set_return_code(vcpu, TDG_VP_VMCALL_RETRY); + tdvmcall_set_return_val(vcpu, gfn_to_gpa(s)); + } else if (ret) + tdvmcall_set_return_code(vcpu, TDG_VP_VMCALL_INVALID_OPERAND); + else + tdvmcall_set_return_code(vcpu, TDG_VP_VMCALL_SUCCESS); + + return 1; +} + static int handle_tdvmcall(struct kvm_vcpu *vcpu) { if (tdvmcall_exit_type(vcpu)) @@ -1098,6 +1129,8 @@ static int handle_tdvmcall(struct kvm_vcpu *vcpu) return tdx_emulate_wrmsr(vcpu); case TDG_VP_VMCALL_REPORT_FATAL_ERROR: return tdx_report_fatal_error(vcpu); + case TDG_VP_VMCALL_MAP_GPA: + return tdx_map_gpa(vcpu); default: break; } -- 2.25.1