Received: by 2002:a05:6a10:a841:0:0:0:0 with SMTP id d1csp3847243pxy; Mon, 26 Apr 2021 11:08:23 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxoKW04id4XduhrpcO00CEqVP0YkPCJTCBV6beDLKvm2/fmk0/5f2hQZHIAfdd6LSnGW4L3 X-Received: by 2002:a50:e702:: with SMTP id a2mr23076232edn.3.1619460503372; Mon, 26 Apr 2021 11:08:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1619460503; cv=none; d=google.com; s=arc-20160816; b=w76UURYUWBlDvvZ8vk92I1xdw3Sj8MudP2Zb57am3JkojjCMcNdYDfj2jxowqVhrSz +7t85zCB5FmhlAoj5mGDxthuLgKbTMdWAX3dKSNL7rW4z1zUoNH2A6iyMTCGfH/sasFi JLrcbHdW7DxAGbfCUyIkODG7LSt+/qNP5sNl+yt5ew6aD6KJRGfs3bHXrAdx6cf2WCuC qiw7LR372j4ukMXwiYcOmPh7Nrck+x8SR8mjAy6zsLrozwV6CjPhaPf00WvnibNJje7f tmIhlLXTDI00EOztp+SqcbIfkaecxvbmPbpY00Ih/yE6VI0GNl8/qi6Dxh48i7NiNPCj /q7Q== 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=zzdCXdvlW7vqeuXlL4y62XUHz4Mth62ZobZ9q5eqYdE=; b=AoMPICrxW6l2h3b9bY6ERlrXyU+sWSn145JiLqLql6rP9tt/vPMDZB3+jUJVoRAdiG rmw5fWS1UxBS6kXNhXU36SPZqjkQ6bXmdJqF0R/AgCTEPmsuOKX9MXMh6XRul121Ikk2 ALWaBfJU+EAi/7uvcAUewtmAvDCs0wjem+kugAVXU524+Rjgk41C/GBA8Idi2sSry6Gs VdKpm5GjKXOwKuv3jMoryE+QJS1gDGV4pDweNYv+0njjFkoRftvvSGbbsP5GhM0DUFTF SoHbEb4TRVZuQ7XmdZQxNpkGxsxLhIqIQrOyedNJD9/aZ8RmtOXGDNegg79SXhpb5gWk +mZA== 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 y23si13457140ejr.356.2021.04.26.11.07.59; Mon, 26 Apr 2021 11:08:23 -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 S236251AbhDZSFb (ORCPT + 99 others); Mon, 26 Apr 2021 14:05:31 -0400 Received: from mga06.intel.com ([134.134.136.31]:20703 "EHLO mga06.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234332AbhDZSDn (ORCPT ); Mon, 26 Apr 2021 14:03:43 -0400 IronPort-SDR: /cLCCydUj5EWjQGJMDnSFAOEcEL/gNNM3dTyIZyywcgPmt8em8MDYw6Cr7yZg0XjK9ury13QHG 5+3YG+Ey9S/g== X-IronPort-AV: E=McAfee;i="6200,9189,9966"; a="257683621" X-IronPort-AV: E=Sophos;i="5.82,252,1613462400"; d="scan'208";a="257683621" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Apr 2021 11:02:57 -0700 IronPort-SDR: c7r8uBpw/DRcK2HKy1W1UJV7XGAIA7MmmcGl3XXUKt+HZP4hnsBqEMUBOCeqynRTx7H0ObSVdj Pr7k5Eb7UXNA== X-IronPort-AV: E=Sophos;i="5.82,252,1613462400"; d="scan'208";a="447353452" Received: from ssumanpx-mobl.amr.corp.intel.com (HELO skuppusw-mobl5.amr.corp.intel.com) ([10.254.34.197]) by fmsmga004-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Apr 2021 11:02:56 -0700 From: Kuppuswamy Sathyanarayanan To: Peter Zijlstra , Andy Lutomirski , Dave Hansen , Dan Williams , Tony Luck Cc: Andi Kleen , Kirill Shutemov , Kuppuswamy Sathyanarayanan , Raj Ashok , Sean Christopherson , linux-kernel@vger.kernel.org, Kuppuswamy Sathyanarayanan Subject: [RFC v2 29/32] x86/tdx: Add helper to do MapGPA TDVMALL Date: Mon, 26 Apr 2021 11:01:56 -0700 Message-Id: <7d43f57c3b178a905ef2505cef5313844c497984.1619458733.git.sathyanarayanan.kuppuswamy@linux.intel.com> 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: "Kirill A. Shutemov" MapGPA TDVMCALL requests the host VMM to map a GPA range as private or shared memory mappings. Shared GPA mappings can be used for communication beteen TD guest and host VMM, for example for paravirtualized IO. The new helper tdx_map_gpa() provides access to the operation. Signed-off-by: Kirill A. Shutemov Reviewed-by: Andi Kleen Signed-off-by: Kuppuswamy Sathyanarayanan --- arch/x86/include/asm/tdx.h | 13 +++++++++++++ arch/x86/kernel/tdx.c | 13 +++++++++++++ 2 files changed, 26 insertions(+) diff --git a/arch/x86/include/asm/tdx.h b/arch/x86/include/asm/tdx.h index dc80cf7f7d08..4789798d7737 100644 --- a/arch/x86/include/asm/tdx.h +++ b/arch/x86/include/asm/tdx.h @@ -7,6 +7,11 @@ #ifndef __ASSEMBLY__ +enum tdx_map_type { + TDX_MAP_PRIVATE, + TDX_MAP_SHARED, +}; + #ifdef CONFIG_INTEL_TDX_GUEST #include @@ -112,6 +117,8 @@ unsigned short tdg_inw(unsigned short port); unsigned int tdg_inl(unsigned short port); extern phys_addr_t tdg_shared_mask(void); +extern int tdg_map_gpa(phys_addr_t gpa, int numpages, + enum tdx_map_type map_type); #else // !CONFIG_INTEL_TDX_GUEST @@ -155,6 +162,12 @@ static inline phys_addr_t tdg_shared_mask(void) { return 0; } + +static inline int tdg_map_gpa(phys_addr_t gpa, int numpages, + enum tdx_map_type map_type) +{ + return -ENODEV; +} #endif /* CONFIG_INTEL_TDX_GUEST */ #endif /* __ASSEMBLY__ */ #endif /* _ASM_X86_TDX_H */ diff --git a/arch/x86/kernel/tdx.c b/arch/x86/kernel/tdx.c index 7e391cd7aa2b..074136473011 100644 --- a/arch/x86/kernel/tdx.c +++ b/arch/x86/kernel/tdx.c @@ -15,6 +15,8 @@ #include "tdx-kvm.c" #endif +#define TDVMCALL_MAP_GPA 0x10001 + static struct { unsigned int gpa_width; unsigned long attributes; @@ -98,6 +100,17 @@ static void tdg_get_info(void) physical_mask &= ~tdg_shared_mask(); } +int tdg_map_gpa(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 = tdvmcall(TDVMCALL_MAP_GPA, gpa, PAGE_SIZE * numpages, 0, 0); + return ret ? -EIO : 0; +} + static __cpuidle void tdg_halt(void) { u64 ret; -- 2.25.1