From patchwork Sun May 7 23:46:16 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: 13233953 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 6AE7BC7EE2D for ; Sun, 7 May 2023 23:46:49 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A89386B0082; Sun, 7 May 2023 19:46:46 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A14FB6B0085; Sun, 7 May 2023 19:46:46 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7A1EC6B0087; Sun, 7 May 2023 19:46:46 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 451706B0082 for ; Sun, 7 May 2023 19:46:46 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 266F11401DB for ; Sun, 7 May 2023 23:46:46 +0000 (UTC) X-FDA: 80765096412.09.B39A04E Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by imf17.hostedemail.com (Postfix) with ESMTP id 0672740004 for ; Sun, 7 May 2023 23:46:43 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=V3mbjWnQ; spf=none (imf17.hostedemail.com: domain of kirill.shutemov@linux.intel.com has no SPF policy when checking 134.134.136.126) 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=1683503204; 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=cAZ5dclHmr3bPqqN6wlS/ms38HkegOt+k+1Qe8V3J/Y=; b=LPUCYnCLidRECPoua6pp7CBUDkwYVO735/O88diiQzRf9/4HZPA8r6yUaMV6ViMOy+tXms HsnOLriJ+MVfLE93SWlimypV8iz/KIshlE8J0jrKmClLpbhAIZNb5Re4771IG3+t+pyLfN MWqPPU/WfBtYNIuOTwo8SEWQr+CLvSc= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1683503204; a=rsa-sha256; cv=none; b=YeDYHUprWLza2VMpP0Fmqwkgq3hZBY9IfmqGFlTDKDHZK+k3cWoySbGQOfjP0/WpKW9t5S DlEqCnE7yLanqhAaEtir+A8TsiB88lbk3bWwYdilU+xgOgwbasi0ARrtc3octxzMcdxgKS +jo0n2HGvjtHE0QlWGg2rrSfm1uCwqQ= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=V3mbjWnQ; spf=none (imf17.hostedemail.com: domain of kirill.shutemov@linux.intel.com has no SPF policy when checking 134.134.136.126) smtp.mailfrom=kirill.shutemov@linux.intel.com; dmarc=pass (policy=none) header.from=intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1683503204; x=1715039204; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Eu57mUO9ct2ICW4Etq/GrS2vGWKQMEDS8IVWtzUCpBo=; b=V3mbjWnQsFPnD6hyzO6hvE7EAAq171caU5UEUyP0fE29sKKdB7aTiuKI Zpii+lfNXDYt4YaLiVKXLQjABhW87D6P3a4sw/0ZBflwE3N46blTn4QEg a/yyrtIPhEAC3y2WK+xvbRjZ32qmocARtSc/L1HfD5ycojaZRQTdVLyMh HUQiJVZxfp94jNrAKQqyvmSbTMIdrgVSmoL/4qZilJxhBIlHDozraDpqK M8VbebHolfIrQnaQ8f+q6UBooWgfrN6iFoh+lbDJxPAU8g8/SE9QZ5xAq EFaqk22UQDsZzfvE6gLm8JfW8ZdOw6JmyuwKtEti7kYSRDgvIaoRSqR1k Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10703"; a="333953576" X-IronPort-AV: E=Sophos;i="5.99,258,1677571200"; d="scan'208";a="333953576" Received: from orsmga006.jf.intel.com ([10.7.209.51]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 May 2023 16:46:41 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10703"; a="675852973" X-IronPort-AV: E=Sophos;i="5.99,258,1677571200"; d="scan'208";a="675852973" Received: from dancaspi-mobl1.ger.corp.intel.com (HELO box.shutemov.name) ([10.252.61.73]) by orsmga006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 May 2023 16:46:33 -0700 Received: by box.shutemov.name (Postfix, from userid 1000) id 6ACA110D476; Mon, 8 May 2023 02:46:20 +0300 (+03) From: "Kirill A. Shutemov" To: Borislav Petkov , Andy Lutomirski , Dave Hansen , 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 , 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: [PATCHv10 09/11] x86/tdx: Make _tdx_hypercall() and __tdx_module_call() available in boot stub Date: Mon, 8 May 2023 02:46:16 +0300 Message-Id: <20230507234618.18067-10-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20230507234618.18067-1-kirill.shutemov@linux.intel.com> References: <20230507234618.18067-1-kirill.shutemov@linux.intel.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 0672740004 X-Rspam-User: X-Rspamd-Server: rspam06 X-Stat-Signature: 8ds4ewmcx75dspb11t5551pjzbi179ti X-HE-Tag: 1683503203-883625 X-HE-Meta: U2FsdGVkX1+macnuVUwnMQsjW4f1IZoOhxiJXbZ2A3YRQi+kcjNUYkpb4MPljcPoLbe7Xg0EfVZabZQ1n2MkrwYWcBdEZ1J/WI4l6QbIPsSnew22UeFud/ecgDymF7oeQIMpELD59J1v1P67QSqLaAm4Xdk8Da9a9P4wHGJG5ewAueusX19WZyEXM36d/nqDCKu1dMXAo1oNCLBYPUQJ6vh1a9ExdRB/YebGph0k4hq82a8Cvkl9VHl0JAGKyeCS1o2ojZxkGcf6rMhlNQA4BvEMYMoSRNLhj5nlbmuHOxFzpZy9kOo281t9BD9KyQ1hAA+sZiFUNMoRD50d5Yk7PXW6HKMhjgiD99dVgQi5Uz5TWMAppBQ3mzn57D3O+jEEAWGMgl8G4HS1yeyiKHUO0uHYSx6J8Z78888Jg2g3dJZXunewUZwNMpR2CdVfBm8xeiTikQsZzl0LjetX6BMWRyllmQj5TwK8OrYUa9bTekSX7ZQnBwojbAkgIL5dyCxtaYZYX8d9CJWcVuZ8YyZcJL8KXdKLtiNDrt8kd7wFOT+nctalg8LPg3QK4fzSpYrzVCAaUhdVqpjT1vsztl1edgueUolGhRksReAhyDmRAfa31QVmqvhNxBpraqjJwcnFA3wqhowOoPFh2E10Fbd+ClJqCNHeuGMgubyiEcn+Y2qeU8NS+GctMqcKNpuWj8rPSm03m62FOcvJ53TJsOlob0XYlKUV39EGVGeIbFzwFYEVXcleKjVGWZvEcyNNtI/clgFdWlpDu3y9aGgQiXcHntAbapLj9dhohzHNgfx3mq/3siIDOLk8QwS+3qXpsCIp66uJ1SJDJfnqA42neEMEhiq6P5mKcJB6P1LXQS8OrD5jGOw6+M5HNrQzuNJ+39wemSsSJhIaSNPHJfoYPvfj1EoW8460tdTEmCpZ7VXoUH0Oesr59wznnmet0rvBu0cPxVu9cKgK91YXme38fXw jkDIBRDg g1LKe4eikBbeHHM9WgYuiT9YFL30REjDDffMrYZKpRbRv8hFx+NnkeCee5PHJG34sPf4+OEDcOWsJnVtgxn5dhsYUR0uyHyOvzYDHUEYTXeCx76pax4MHk8c8yH1A0lmLN15xAJTCqspBbiONf0hF19I2N5GdeBklerHdfSkAvSh243mxy5JikePn8cbR13FkBBJJ 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 e146b599260f..e6f4c2758a68 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); -} - /* 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 2631e01f6e0f..1ff0ee822961 100644 --- a/arch/x86/include/asm/shared/tdx.h +++ b/arch/x86/include/asm/shared/tdx.h @@ -10,6 +10,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__ /* @@ -37,8 +51,45 @@ struct tdx_hypercall_args { u64 __tdx_hypercall(struct tdx_hypercall_args *args); u64 __tdx_hypercall_ret(struct tdx_hypercall_args *args); +/* + * 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); +} + + /* 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);