Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp310276pxj; Thu, 27 May 2021 00:12:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyHD4/42xw/07bkg3/ydUv2wv32PnYXO72jQWgeigwm/9cfalylGp/NZSzhOqab81Z3V1OL X-Received: by 2002:a17:906:fa81:: with SMTP id lt1mr2193414ejb.465.1622099534551; Thu, 27 May 2021 00:12:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622099534; cv=none; d=google.com; s=arc-20160816; b=g9JRPQCre1JHijEVX8hzL9DQrxGm9U8wotCBNxupc+m42hg9fTDWTCAF73uALZuAi7 t9p3LeFos47CdMObDoY7STEJvHYY7ATovXAzTopwZW3+6erXFlVfpfEn6QeeO6oFERYe LM7TIZA5OFKWpGOE8rFVXvaM0UYi13hkDK/TrClpJ57rLiofnZTuDKBrwpQpsPuAOEvw RQ8n15SB04TsLWB1oKixO3cm/CR1tjHwGt6nxdeZEopIRidz++l2//VUTEu5QNhex9GR uhWBiItncBgVdQIJEkTmAE4drNUFh3yCiQECpx3rKCWzXDU2BAd4i2joGKCOg6RTthIb 6DRQ== 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 :ironport-sdr:ironport-sdr; bh=U/4LWWRrmiVR2OccXM3qjhIDj7wS5kEQuOlBBZQLhls=; b=sNJNh+7PoMRLY6Uamklx2gQYBMuAN9Ksl4mQFr3puPHXJqWQROm2Oo15/jmskovptu Wb6NMvCWtmnqyeYXiPr9sBlXnGPJvp1ooK3m/9YJs55oA+LyP44k/oPuWo31Elib4SWY o4+1fAZFf1an1ocQOI1/lUxWA3bol14VFyoS/UMugEglZji6mZMN7uTV+0UAidC7VsKa KFbBfyzAUE+EJ0PmEK0ma3cy1BMKzVOc/heEjP/q7W0lil9GWHcLqIPGpYkYuuYrekzZ ogr0SzkH2+z/mOO0FUJQR4D7vY3gezN9deA3gbqcJOHpp/6QVuuyvCozNiT4l7YwdORu WgrA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id au19si1436491ejc.562.2021.05.27.00.11.50; Thu, 27 May 2021 00:12:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234436AbhE0E6V (ORCPT + 99 others); Thu, 27 May 2021 00:58:21 -0400 Received: from mga14.intel.com ([192.55.52.115]:29423 "EHLO mga14.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233424AbhE0E6U (ORCPT ); Thu, 27 May 2021 00:58:20 -0400 IronPort-SDR: /Un19rduIl/0g1gNalq8OTkfx7q50H35HM0OkSGs/lW+oL5MbTNm5YEIpBLgPx6B6G18ToWBqA NrXrhun+j5iw== X-IronPort-AV: E=McAfee;i="6200,9189,9996"; a="202411868" X-IronPort-AV: E=Sophos;i="5.82,333,1613462400"; d="scan'208";a="202411868" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 May 2021 21:56:45 -0700 IronPort-SDR: eTyRWFmly24HJWPrqsRiLIgtNJHdppHF4cp1Y4Pv9xZVOIr8tshTpBccaalr8WEHcrO+AjGKgk mqVkzzGUsvpg== X-IronPort-AV: E=Sophos;i="5.82,333,1613462400"; d="scan'208";a="633830957" Received: from skgangad-mobl.amr.corp.intel.com (HELO skuppusw-desk1.amr.corp.intel.com) ([10.254.33.45]) by fmsmga005-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 May 2021 21:56:45 -0700 From: Kuppuswamy Sathyanarayanan To: Peter Zijlstra , Andy Lutomirski , Dave Hansen , Tony Luck , Dan Williams Cc: Andi Kleen , Kirill Shutemov , Kuppuswamy Sathyanarayanan , Raj Ashok , Sean Christopherson , Kuppuswamy Sathyanarayanan , linux-kernel@vger.kernel.org Subject: [RFC v2-fix-v1 1/1] x86/tdx: Add helper to do MapGPA hypercall Date: Wed, 26 May 2021 21:56:38 -0700 Message-Id: <20210527045638.3985072-1-sathyanarayanan.kuppuswamy@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <57690b33-e7da-e345-dfae-b2e18f9a1467@linux.intel.com> References: <57690b33-e7da-e345-dfae-b2e18f9a1467@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: "Kirill A. Shutemov" MapGPA hypercall is used by TDX guests to request VMM convert the existing mapping of given GPA address range between private/shared. tdx_hcall_gpa_intent() is the wrapper used for making MapGPA hypercall. Signed-off-by: Kirill A. Shutemov Reviewed-by: Andi Kleen Signed-off-by: Kuppuswamy Sathyanarayanan --- Changes since RFC v2: * Renamed tdg_map_gpa() to tdx_hcall_gpa_intent(). * Fixed commit log and comments as per review comments. arch/x86/include/asm/tdx.h | 17 +++++++++++++++++ arch/x86/kernel/tdx.c | 24 ++++++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/arch/x86/include/asm/tdx.h b/arch/x86/include/asm/tdx.h index a93528246595..eb9fa5f4d0e3 100644 --- a/arch/x86/include/asm/tdx.h +++ b/arch/x86/include/asm/tdx.h @@ -7,6 +7,15 @@ #ifndef __ASSEMBLY__ +/* + * Page mapping type enum. This is software construct not + * part of any hardware or VMM ABI. + */ +enum tdx_map_type { + TDX_MAP_PRIVATE, + TDX_MAP_SHARED, +}; + #ifdef CONFIG_INTEL_TDX_GUEST #include @@ -119,6 +128,8 @@ do { \ #endif extern phys_addr_t tdg_shared_mask(void); +extern int tdx_hcall_gpa_intent(phys_addr_t gpa, int numpages, + enum tdx_map_type map_type); #else // !CONFIG_INTEL_TDX_GUEST @@ -143,6 +154,12 @@ static inline phys_addr_t tdg_shared_mask(void) { return 0; } + +static inline int tdx_hcall_gpa_intent(phys_addr_t gpa, int numpages, + enum tdx_map_type map_type) +{ + return -ENODEV; +} #endif /* CONFIG_INTEL_TDX_GUEST */ #ifdef CONFIG_INTEL_TDX_GUEST_KVM diff --git a/arch/x86/kernel/tdx.c b/arch/x86/kernel/tdx.c index 0c8b10b78f32..a8ebd2d10093 100644 --- a/arch/x86/kernel/tdx.c +++ b/arch/x86/kernel/tdx.c @@ -16,6 +16,9 @@ #define TDINFO 1 #define TDGETVEINFO 3 +/* TDX hypercall Leaf IDs */ +#define TDVMCALL_MAP_GPA 0x10001 + #define VE_GET_IO_TYPE(exit_qual) (((exit_qual) & 8) ? 0 : 1) #define VE_GET_IO_SIZE(exit_qual) (((exit_qual) & 7) + 1) #define VE_GET_PORT_NUM(exit_qual) ((exit_qual) >> 16) @@ -122,6 +125,27 @@ static void tdg_get_info(void) physical_mask &= ~tdg_shared_mask(); } +/* + * Inform the VMM of the guest's intent for this physical page: + * shared with the VMM or private to the guest. The VMM is + * expected to change its mapping of the page in response. + * + * Note: shared->private conversions require further guest + * action to accept the page. + */ +int tdx_hcall_gpa_intent(phys_addr_t gpa, int numpages, + enum tdx_map_type map_type) +{ + u64 ret; + + if (map_type == TDX_MAP_SHARED) + gpa |= tdg_shared_mask(); + + ret = tdx_hypercall(TDVMCALL_MAP_GPA, gpa, PAGE_SIZE * numpages, 0, 0); + + return ret ? -EIO : 0; +} + static __cpuidle void tdg_halt(void) { u64 ret; -- 2.25.1