Received: by 2002:a05:6a10:c604:0:0:0:0 with SMTP id y4csp238790pxt; Wed, 4 Aug 2021 21:22:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyZYSwWYhtcsIeG21ZYyhRB6Juo6MIwVeCs7+kuYAAhS3ds5fswSnVbiP34V4uvPZw9FFij X-Received: by 2002:a05:6602:38d:: with SMTP id f13mr319722iov.153.1628137332471; Wed, 04 Aug 2021 21:22:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628137332; cv=none; d=google.com; s=arc-20160816; b=bMupWwnuK5mwl28n2IbKJBBCaA2o6N9XzVe9FY4ZO2AkIQZw2Z7eY37FWhmOO+95M3 bNJ7N8eKfECPbHc5smB9teqghdGxG2C3mnteNdbiGY78bzV7aRmB+sOq/X2zCNnQoz84 h9v32BSYRt2JWYnf6aE9/oY9ulvGuCXs/5CyF4dPpDD/RSer2z9XqyFKTrreUaBf+UFm I89lk6DbhphLZFOBqP5nFKr2PFPoIk7IbtJIDyTVmbRDr1HQNTqncvMNnV4z+rZxhfIE 4F4EJO6y6llsOsKNM6rWWuBcQ6o1LihDygvuXOTn676HKkpS48GdzU5vKKIQuT1HLWUD HpYA== 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; bh=K+cOw/ONh34rNhh0sHUWk0rmWwaqgyrM7G2CTPnyyZ4=; b=XAYqtTa2ucqCWppOJmtPNXaozduj/aKH/SM/dr3FwBjXXPTZBjSZp6nLq2LA4Xct90 gj4uFqvuYYIPCeJ8l9sg8pWxl4gqp7EP+o+VtVkRUQYKlMLdTJ763Kf4GrNx6uT1Gqin FBaXj7Fngk+LGxVqxqI7zFv6JniQXwFMLCF+Phip9U7JXii9jpfn5x4fpB/2a7za8ODJ zBIi16V0fue1ue3TgpE/oMP+sa+PwCGGZVoDV7pqoRe76B6yaU2X/mZxrLV1v/TFWbUs xcqJ1DZfFLtApuMQJKtP/P3cApR8dHVkZUhif4pSLYzOhWpsY6uVYJTq1Yy8zDEp8Q8J u5fA== 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 x5si4609144ilq.85.2021.08.04.21.22.01; Wed, 04 Aug 2021 21:22:12 -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 S236726AbhHEAyG (ORCPT + 99 others); Wed, 4 Aug 2021 20:54:06 -0400 Received: from mga02.intel.com ([134.134.136.20]:12129 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236596AbhHEAxn (ORCPT ); Wed, 4 Aug 2021 20:53:43 -0400 X-IronPort-AV: E=McAfee;i="6200,9189,10066"; a="201215429" X-IronPort-AV: E=Sophos;i="5.84,296,1620716400"; d="scan'208";a="201215429" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Aug 2021 17:53:29 -0700 X-IronPort-AV: E=Sophos;i="5.84,296,1620716400"; d="scan'208";a="437617203" Received: from mjkendri-mobl.amr.corp.intel.com (HELO skuppusw-desk1.amr.corp.intel.com) ([10.254.17.117]) by orsmga002-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Aug 2021 17:53:27 -0700 From: Kuppuswamy Sathyanarayanan To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Peter Zijlstra , Andy Lutomirski , Bjorn Helgaas , Richard Henderson , Thomas Bogendoerfer , James E J Bottomley , Helge Deller , "David S . Miller" , Arnd Bergmann , Jonathan Corbet , "Michael S . Tsirkin" Cc: Peter H Anvin , Dave Hansen , Tony Luck , Dan Williams , Andi Kleen , Kirill Shutemov , Sean Christopherson , Kuppuswamy Sathyanarayanan , x86@kernel.org, linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, linux-alpha@vger.kernel.org, linux-mips@vger.kernel.org, linux-parisc@vger.kernel.org, sparclinux@vger.kernel.org, linux-arch@vger.kernel.org, linux-doc@vger.kernel.org, virtualization@lists.linux-foundation.org Subject: [PATCH v4 04/15] x86/tdx: Add helper to do MapGPA hypercall Date: Wed, 4 Aug 2021 17:52:07 -0700 Message-Id: <20210805005218.2912076-5-sathyanarayanan.kuppuswamy@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210805005218.2912076-1-sathyanarayanan.kuppuswamy@linux.intel.com> References: <20210805005218.2912076-1-sathyanarayanan.kuppuswamy@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 Reviewed-by: Tony Luck Signed-off-by: Kuppuswamy Sathyanarayanan --- Changes since v3: * None Changes since v1: * Modified tdx_hcall_gpa_intent() to use _tdx_hypercall() instead of tdx_hypercall(). arch/x86/include/asm/tdx.h | 18 ++++++++++++++++++ arch/x86/kernel/tdx.c | 25 +++++++++++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/arch/x86/include/asm/tdx.h b/arch/x86/include/asm/tdx.h index 1e2a1c6a1898..665c8cf57d5b 100644 --- a/arch/x86/include/asm/tdx.h +++ b/arch/x86/include/asm/tdx.h @@ -56,6 +56,15 @@ struct ve_info { u32 instr_info; }; +/* + * 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 void __init tdx_early_init(void); @@ -79,6 +88,9 @@ bool tdg_early_handle_ve(struct pt_regs *regs); 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); + /* * To support I/O port access in decompressor or early kernel init * code, since #VE exception handler cannot be used, use paravirt @@ -149,6 +161,12 @@ static inline bool tdg_early_handle_ve(struct pt_regs *regs) { return false; } 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 d316fe33f52f..ccbad600a422 100644 --- a/arch/x86/kernel/tdx.c +++ b/arch/x86/kernel/tdx.c @@ -18,6 +18,9 @@ #define TDINFO 1 #define TDGETVEINFO 3 +/* TDX hypercall Leaf IDs */ +#define TDVMCALL_MAP_GPA 0x10001 + #define VE_IS_IO_OUT(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) @@ -97,6 +100,28 @@ 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, + NULL); + + return ret ? -EIO : 0; +} + static __cpuidle void tdg_halt(void) { u64 ret; -- 2.25.1