From patchwork Thu Mar 30 11:49:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Kirill A . Shutemov" X-Patchwork-Id: 13194079 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 600F2C77B60 for ; Thu, 30 Mar 2023 11:50:52 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DFF0C6B0088; Thu, 30 Mar 2023 07:50:41 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D5F496B0089; Thu, 30 Mar 2023 07:50:41 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BDF78900002; Thu, 30 Mar 2023 07:50:41 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id A5B906B0089 for ; Thu, 30 Mar 2023 07:50:41 -0400 (EDT) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 7868D1201B4 for ; Thu, 30 Mar 2023 11:50:41 +0000 (UTC) X-FDA: 80625397482.24.193EA63 Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by imf11.hostedemail.com (Postfix) with ESMTP id 553C54001A for ; Thu, 30 Mar 2023 11:50:39 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=EFXNcdOi; spf=none (imf11.hostedemail.com: domain of kirill.shutemov@linux.intel.com has no SPF policy when checking 192.55.52.120) smtp.mailfrom=kirill.shutemov@linux.intel.com; dmarc=pass (policy=none) header.from=intel.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1680177039; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=/VRyLYcUziIyvK5rDEWkSsh184m1aPMbQy/X3mwxy8E=; b=G4O2OusA3yQH9Ym2k7SVR6AX5NUiB5efYEHBGmYQNHAR5LPBZYJKMSaGtQrlUiZ60kXx4E hHf0dnl0wTroDCqc0IAoxlkfh0grr2NbHK6UXhhv3MN3iuzETLn+qlwMQTLH91Mwt/aY5P 5cBP4Vw5efMQ+2WMBI2NOjT1eOsGlvM= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=EFXNcdOi; spf=none (imf11.hostedemail.com: domain of kirill.shutemov@linux.intel.com has no SPF policy when checking 192.55.52.120) smtp.mailfrom=kirill.shutemov@linux.intel.com; dmarc=pass (policy=none) header.from=intel.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1680177039; a=rsa-sha256; cv=none; b=Kz9Z2yWPgVCmizR6Yf5vct0A9l3BzvoKkk+gBdvPW/AIUa1fa9n8Lgdt8f0CgaT7+2Wl97 0ZGitbykbfG8pZ1J/L9AZzQ1HQLT5l2jmMBBQ4Zm2Yu9BaSTraYVkN1I6kRVqZYTqXH6LX Tgok5YIrrxYzsoEvjPMAGZjnESDsM8k= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1680177039; x=1711713039; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=aSDNa5qy6AjyVCvAMnDoppa8Rk9jEp1+/qGA3XqX6A0=; b=EFXNcdOiOEnRjfOrpRNt3t12aA14K3WbwBmFRcnJhqgOlEiNsxIaV+lO 0pKWy0PBoClDUfqmPpkbxvhHMpCYVbrNr415MXG/F+rNwno9auM0iA0JT vrBspFfwEsGaEcD2kclJ2cBY2URdwCVb5ms6DTY403ZNpIHG1j8kW0cjg RuWMlzb/Z36EZEh3lnqlJ+wkhsTqlAB6i+lbDtFO4i+qt/C3oE1Zd3Y// 9MGP2Esr8gKnam7yZvVxVac0TmjSIJyLhRcwHwOkKvBL3UrqohP48FCCs 2j+CCr/RHsyQckmcqCmk6emP9lEO5+nvtVRZeHLHS2Q3JLsdCc74eQM2X w==; X-IronPort-AV: E=McAfee;i="6600,9927,10664"; a="339868528" X-IronPort-AV: E=Sophos;i="5.98,303,1673942400"; d="scan'208";a="339868528" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Mar 2023 04:50:25 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10664"; a="1014401453" X-IronPort-AV: E=Sophos;i="5.98,303,1673942400"; d="scan'208";a="1014401453" Received: from ngreburx-mobl.ger.corp.intel.com (HELO box.shutemov.name) ([10.251.209.91]) by fmsmga005-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Mar 2023 04:50:17 -0700 Received: by box.shutemov.name (Postfix, from userid 1000) id 6BA50104CA8; Thu, 30 Mar 2023 14:50:00 +0300 (+03) From: "Kirill A. Shutemov" To: Borislav Petkov , Andy Lutomirski , Sean Christopherson , Andrew Morton , Joerg Roedel , Ard Biesheuvel Cc: Andi Kleen , Kuppuswamy Sathyanarayanan , David Rientjes , Vlastimil Babka , Tom Lendacky , Thomas Gleixner , Peter Zijlstra , Paolo Bonzini , Ingo Molnar , Dario Faggioli , Dave Hansen , Mike Rapoport , David Hildenbrand , Mel Gorman , marcelo.cerri@canonical.com, tim.gardner@canonical.com, khalid.elmously@canonical.com, philip.cox@canonical.com, aarcange@redhat.com, peterx@redhat.com, x86@kernel.org, linux-mm@kvack.org, linux-coco@lists.linux.dev, linux-efi@vger.kernel.org, linux-kernel@vger.kernel.org, "Kirill A. Shutemov" , Dave Hansen Subject: [PATCHv9 12/14] x86/tdx: Make _tdx_hypercall() and __tdx_module_call() available in boot stub Date: Thu, 30 Mar 2023 14:49:54 +0300 Message-Id: <20230330114956.20342-13-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230330114956.20342-1-kirill.shutemov@linux.intel.com> References: <20230330114956.20342-1-kirill.shutemov@linux.intel.com> MIME-Version: 1.0 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 553C54001A X-Rspam-User: X-Stat-Signature: xxtux7k3sbn7zorx5ie3bpzwww75nrub X-HE-Tag: 1680177039-234827 X-HE-Meta: U2FsdGVkX1+ihHpzD0/HA2ZmS3+ppyuc6+h+/9PKCduIysL7huClCPisHuF+CxJ6jgq1sQhusvEOJ5uipvPzBI6bXOAAhpEVqRNnS9M1U+UYZjl9Xepf2x8TIO36c4xRzWbYRKePb5HF69o1kaODQbXkC3DGDoD1GjSu+KoNFGfqWIezxdkdgY4anyADU8cJ6vihDE4iq97x4RL2oAeDMMf2xi0rjWSzSSk7DahGSYC30HnOh/O7WzPjjv2D1+MhKVurwKVD3rxo8czNs6oLSMdzFi7MwIuvPPHC3g3gHW3jITUBeSUUEAtkX6zw8Ho9ZnKqbk/fLm2Hxb1AT19a8+JZS/wrUeEzhMvj0qau7plYcsYM77aDgPE6GkL5b+dQFqvDuNkgPIoB8uB6XB5G6jaEvZln0+LEkODHD4jmocgZjzx/RlvL+juXwN6lIWiejUbjDtiDG3EixzL3NtKRrkFuv10HUx04Y/UJil1d44nEdCw7xjLF6QA5QUXIhaJoTUzy3zbq+6SeRJeueGVTd8POalbbCfsRupmakCkhwcthmtlUOyGugpZjC0g/zc3fyLGONV8/sjxTJc/Ka6keptGzDYwP0XKyipL83GofO3mMXbOalTOfl4ndk5zI7KizLi7O+PYeuI4GXkRqRiI3sj3CqiBjZJXxtT7k2HoRBcyvkWoVkw8p8yVG/Z4hDw542YPJqCVUQme5IaPRxwO9GriiDjGBuEXsDFshohgkVLkNiuAYIFZaIkf9qs8NL/sFBAlAAPW1agxM4SacJie/eEbku828m0OCQO/fdqEK2miMLIgs2q72qqx90Q82MYh2Z4dmkYjDcNW7W0n6ZSrsvwG/yFFCq9aTg8EQlxZdMiDm28RXFYJE1A/LyrOYbXYqgzXJnBLk1Lo9UWel6uEeRFrUm4q3V8KKVmSaZZbZkR0py1pPLx88u5BFsH/Y4FzLw7GshO3VraR+Tx+qr5v BeuhitBO bEOOoJQU4ej0YKhhSzerxP+H5lsoyG5Pl270Trz0T06y6ckNEzF17F1EE+zBOeMYZAb3tJtBhDqtun9tCWU5jUgQlaEUpss15R4f1QOOz3pmaZ/MK1nTy0hE8EY4KiOwPd9YeBWJIVeKmxk8Y/uqeT+5tciSXl9YiYh+KC4mB7vFLoObBoqhOpkCJdpyeMiet7Y83+w1RiE71Nrc= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Memory acceptance requires a hypercall and one or multiple module calls. Make helpers for the calls available in boot stub. It has to accept memory where kernel image and initrd are placed. Signed-off-by: Kirill A. Shutemov Reviewed-by: Dave Hansen --- arch/x86/coco/tdx/tdx.c | 32 ------------------- arch/x86/include/asm/shared/tdx.h | 51 +++++++++++++++++++++++++++++++ arch/x86/include/asm/tdx.h | 19 ------------ 3 files changed, 51 insertions(+), 51 deletions(-) diff --git a/arch/x86/coco/tdx/tdx.c b/arch/x86/coco/tdx/tdx.c index 055300e08fb3..a9893f44288f 100644 --- a/arch/x86/coco/tdx/tdx.c +++ b/arch/x86/coco/tdx/tdx.c @@ -14,20 +14,6 @@ #include #include -/* TDX module Call Leaf IDs */ -#define TDX_GET_INFO 1 -#define TDX_GET_VEINFO 3 -#define TDX_GET_REPORT 4 -#define TDX_ACCEPT_PAGE 6 -#define TDX_WR 8 - -/* TDCS fields. To be used by TDG.VM.WR and TDG.VM.RD module calls */ -#define TDCS_NOTIFY_ENABLES 0x9100000000000010 - -/* TDX hypercall Leaf IDs */ -#define TDVMCALL_MAP_GPA 0x10001 -#define TDVMCALL_REPORT_FATAL_ERROR 0x10003 - /* MMIO direction */ #define EPT_READ 0 #define EPT_WRITE 1 @@ -51,24 +37,6 @@ #define TDREPORT_SUBTYPE_0 0 -/* - * Wrapper for standard use of __tdx_hypercall with no output aside from - * return code. - */ -static inline u64 _tdx_hypercall(u64 fn, u64 r12, u64 r13, u64 r14, u64 r15) -{ - struct tdx_hypercall_args args = { - .r10 = TDX_HYPERCALL_STANDARD, - .r11 = fn, - .r12 = r12, - .r13 = r13, - .r14 = r14, - .r15 = r15, - }; - - return __tdx_hypercall(&args, 0); -} - /* Called from __tdx_hypercall() for unrecoverable failure */ noinstr void __tdx_hypercall_failed(void) { diff --git a/arch/x86/include/asm/shared/tdx.h b/arch/x86/include/asm/shared/tdx.h index 4a03993e0785..562b3f4cbde8 100644 --- a/arch/x86/include/asm/shared/tdx.h +++ b/arch/x86/include/asm/shared/tdx.h @@ -12,6 +12,20 @@ #define TDX_CPUID_LEAF_ID 0x21 #define TDX_IDENT "IntelTDX " +/* TDX module Call Leaf IDs */ +#define TDX_GET_INFO 1 +#define TDX_GET_VEINFO 3 +#define TDX_GET_REPORT 4 +#define TDX_ACCEPT_PAGE 6 +#define TDX_WR 8 + +/* TDCS fields. To be used by TDG.VM.WR and TDG.VM.RD module calls */ +#define TDCS_NOTIFY_ENABLES 0x9100000000000010 + +/* TDX hypercall Leaf IDs */ +#define TDVMCALL_MAP_GPA 0x10001 +#define TDVMCALL_REPORT_FATAL_ERROR 0x10003 + #ifndef __ASSEMBLY__ /* @@ -38,8 +52,45 @@ struct tdx_hypercall_args { /* Used to request services from the VMM */ u64 __tdx_hypercall(struct tdx_hypercall_args *args, unsigned long flags); +/* + * Wrapper for standard use of __tdx_hypercall with no output aside from + * return code. + */ +static inline u64 _tdx_hypercall(u64 fn, u64 r12, u64 r13, u64 r14, u64 r15) +{ + struct tdx_hypercall_args args = { + .r10 = TDX_HYPERCALL_STANDARD, + .r11 = fn, + .r12 = r12, + .r13 = r13, + .r14 = r14, + .r15 = r15, + }; + + return __tdx_hypercall(&args, 0); +} + + /* Called from __tdx_hypercall() for unrecoverable failure */ void __tdx_hypercall_failed(void); +/* + * Used in __tdx_module_call() to gather the output registers' values of the + * TDCALL instruction when requesting services from the TDX module. This is a + * software only structure and not part of the TDX module/VMM ABI + */ +struct tdx_module_output { + u64 rcx; + u64 rdx; + u64 r8; + u64 r9; + u64 r10; + u64 r11; +}; + +/* Used to communicate with the TDX module */ +u64 __tdx_module_call(u64 fn, u64 rcx, u64 rdx, u64 r8, u64 r9, + struct tdx_module_output *out); + #endif /* !__ASSEMBLY__ */ #endif /* _ASM_X86_SHARED_TDX_H */ diff --git a/arch/x86/include/asm/tdx.h b/arch/x86/include/asm/tdx.h index 28d889c9aa16..234197ec17e4 100644 --- a/arch/x86/include/asm/tdx.h +++ b/arch/x86/include/asm/tdx.h @@ -20,21 +20,6 @@ #ifndef __ASSEMBLY__ -/* - * Used to gather the output registers values of the TDCALL and SEAMCALL - * instructions when requesting services from the TDX module. - * - * This is a software only structure and not part of the TDX module/VMM ABI. - */ -struct tdx_module_output { - u64 rcx; - u64 rdx; - u64 r8; - u64 r9; - u64 r10; - u64 r11; -}; - /* * Used by the #VE exception handler to gather the #VE exception * info from the TDX module. This is a software only structure @@ -55,10 +40,6 @@ struct ve_info { void __init tdx_early_init(void); -/* Used to communicate with the TDX module */ -u64 __tdx_module_call(u64 fn, u64 rcx, u64 rdx, u64 r8, u64 r9, - struct tdx_module_output *out); - void tdx_get_ve_info(struct ve_info *ve); bool tdx_handle_virt_exception(struct pt_regs *regs, struct ve_info *ve);