From mboxrd@z Thu Jan 1 00:00:00 1970 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 41A6CEB64D7 for ; Fri, 30 Jun 2023 15:14:49 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8ECA88E0018; Fri, 30 Jun 2023 11:14:48 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8753D8E000F; Fri, 30 Jun 2023 11:14:48 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6EF188E0018; Fri, 30 Jun 2023 11:14:48 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 5BA598E000F for ; Fri, 30 Jun 2023 11:14:48 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 2625CA0181 for ; Fri, 30 Jun 2023 15:14:48 +0000 (UTC) X-FDA: 80959761456.16.43F88C5 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf13.hostedemail.com (Postfix) with ESMTP id 93E5020030 for ; Fri, 30 Jun 2023 15:14:44 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=DRkzwZdn; dmarc=none; spf=none (imf13.hostedemail.com: domain of peterz@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=peterz@infradead.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1688138085; 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-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=W6sjO6kMUAzQUdib394q0FOg+FPBU//DVwrbnuX1BOI=; b=TJ0jNU3qK9mH2lprh4UI5t7rM0p+sP3esNMYZhZZ65PPmNs1Z+EGFexvMHxMgkAWaz75KS E6yv+r2UyUgzMLXi3uADoTUwRse9q8r9foX2uXQaQq416HNGNIW4lUdxyYOZ6XNFKpyApM M5iq1/7vQIlA9GsSfVb0mEkGYKeJ/vU= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=DRkzwZdn; dmarc=none; spf=none (imf13.hostedemail.com: domain of peterz@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=peterz@infradead.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1688138085; a=rsa-sha256; cv=none; b=PGAtu2OqjHHQhCzjjylTbsguX6iInT6mTT23METQsd1NDYODguUYmXkaP0+C818+TBe7mN Yz5FyRlRQCuzgWYOrseYFFeBJpk6T0bO5hjmZmIF9Truj52akqmy16R9Z+41aLCqnF2vyV PFDoWnnMQfr+Omdzl/+rwQGLL7F7YU0= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=W6sjO6kMUAzQUdib394q0FOg+FPBU//DVwrbnuX1BOI=; b=DRkzwZdnOgjRI8VZ00V7KPTI+Z t7+XBmemrUnsGULbnPANM4lpiDmXojlLYDkxt2fvFP3mZmdO8s4skmtu//QjxY+6F8eBEd/6VW7P2 HF+pwfelAvfbwg56kv1FegIcEAvpYp/hudtWSpnSRrrEq8rnLclZW7RNf5vHwFLhNP3SsYsiEjwYT XXIDBNgeyJi2vLb5iHYLjRctT/ZUbdwSlsMyr6oSX35RzSfr/Rn6j9+y8NW0YOD8x7np7KlwFYkpI Fk/myStHYRF3ob8qImCsfS542js3IGtMiAl3A2/McroOYmtCnv8wG9Il9Zg7c2R/Dg+Dd44BHtAhw o09lJbrw==; Received: from j130084.upc-j.chello.nl ([24.132.130.84] helo=noisy.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1qFFpQ-005nkP-7n; Fri, 30 Jun 2023 15:14:32 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id B8B71300164; Fri, 30 Jun 2023 17:14:30 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 9C63F24810094; Fri, 30 Jun 2023 17:14:30 +0200 (CEST) Date: Fri, 30 Jun 2023 17:14:30 +0200 From: Peter Zijlstra To: "Huang, Kai" Cc: "kvm@vger.kernel.org" , "Raj, Ashok" , "Hansen, Dave" , "david@redhat.com" , "bagasdotme@gmail.com" , "Luck, Tony" , "ak@linux.intel.com" , "Wysocki, Rafael J" , "linux-kernel@vger.kernel.org" , "Christopherson,, Sean" , "mingo@redhat.com" , "pbonzini@redhat.com" , "linux-mm@kvack.org" , "tglx@linutronix.de" , "kirill.shutemov@linux.intel.com" , "Chatre, Reinette" , "Yamahata, Isaku" , "nik.borisov@suse.com" , "hpa@zytor.com" , "Shahar, Sagi" , "imammedo@redhat.com" , "bp@alien8.de" , "Gao, Chao" , "Brown, Len" , "sathyanarayanan.kuppuswamy@linux.intel.com" , "Huang, Ying" , "Williams, Dan J" , "x86@kernel.org" Subject: Re: [PATCH v12 20/22] x86/virt/tdx: Allow SEAMCALL to handle #UD and #GP Message-ID: <20230630151430.GC2534364@hirez.programming.kicks-ass.net> References: <20230628152900.GI2438817@hirez.programming.kicks-ass.net> <20230628203823.GR38236@hirez.programming.kicks-ass.net> <42e13ccf7f27a68c0dd64640eed378c38ef40967.camel@intel.com> <20230630100659.GF2533791@hirez.programming.kicks-ass.net> <20230630102141.GA2534364@hirez.programming.kicks-ass.net> <20230630120650.GB2534364@hirez.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230630120650.GB2534364@hirez.programming.kicks-ass.net> X-Rspamd-Queue-Id: 93E5020030 X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: ah7w7ystrxairccz8yj15twqutpo5dq4 X-HE-Tag: 1688138084-220728 X-HE-Meta: U2FsdGVkX1/f1KuoXDHb61W3InI9MV2el9BryDskxNW6I2Wsp7Twqu7yQMa1d1W0bQ1eeibl+Ov1MCrOzz2i0dNRaoc9ivydojrDMebYgkQ693yuRcWDFWfr/a4DR4Z3sHkUW1lKqcudIfbaMMviTZXfkYBE3E4Ki8I5XWyignnyRHYJixKjwY0aQS1DK6MmjtKyce1r7mGDGQN3kFaq8V6NgO6G64qp07aYKejUytWd7/dwHSKMI5qTpLKJh2w7vPjOcx/UlyABgMjlgNSMo7lB2qo14/Saqfh2n6f5rnSAOK5BA09Dbo2A+S9seOrKLEbtqnPpUXjNl2ucPJ5zKJTvGND/YC91y3fcwEDH6ij5nO8b9WhJ3xVEhW2AADCUW5vTBcpFjilnvyFTyn5xI2/QhylTH+FmISGnQe8iqyPOqabHlSF1AJeqnPecudayVrYUTrZHUx34xdJEgxIGXnj8n2KN32UhEJrxNE1Fqk0nVoLdG03ccX4UbGhSpvnlL2QzVohnQmyGWNvTZk0KaYSNcLFZMt10Up9952JOdPkTDEAGeC1/OGSI1AbyaAMV1XKcH6J3jBwMQL7XAsDRD23bZ3az87WAt9+QMLHaU5ew4qvUgrSBMdyp1LWz0fPEO+mbxtAbJD6UUwYk31UNFfO0RXoWaJgburHYKnBlR63GBYI09Ptt/UPae4ujOXrOVUm1WaTO6R1dMP7ZUmOoa8vPKtDpm61IcX1ac6VzSZeqh75pZLugv8JTxUp12xhicErVSQFaicE3qpWJQ0Q9nDeTEk/kJgoKPMPKJJimIgOmZbf46hM+aN38Na1hrPfy7VcZDeb8APNWobMJup+foIn/quY6VTQTvQCqXa3KXNbMNroxN4TWzm/5uUjRXVup+IpS/msRoykzwVzaDaGOIGkAh7pvlwzZ/lQ+UQoNV0b/Ok59LBZEVmt1rNyUf4p8+hObiYKA/vkFI6bVde3 IKWe9Bio 0QuUG/lm77SF+/CJykyS/0ibbbFwRgL1zMYU2DYo2Nmc82sSYUly7QPyDSQmuUFm8/G4M72fdlrgxHUWB/WVmQVDblZLjm5hhWZrrTCqUOyF2mQdlgiLtlVyydtlnc+pX3iJpVuHKBORl7N8O++dcb28VACoQIT5ySH7eszFDu8IkgAns4pIeT7C3Tw== 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: On Fri, Jun 30, 2023 at 02:06:50PM +0200, Peter Zijlstra wrote: > /* > * Used for input/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_args { > /* callee-clobbered */ > u64 rdx; > u64 rcx; > u64 r8; > u64 r9; > /* extra callee-clobbered */ > u64 r10; > u64 r11; > /* callee-saved + rdi/rsi */ > u64 rdi; > u64 rsi; > u64 rbx; > u64 r12; > u64 r13; > u64 r14; > u64 r15; > }; > > > > /* > * TDX_MODULE_CALL - common helper macro for both > * TDCALL and SEAMCALL instructions. > * > * TDCALL - used by TDX guests to make requests to the > * TDX module and hypercalls to the VMM. > * > * SEAMCALL - used by TDX hosts to make requests to the > * TDX module. > * > *------------------------------------------------------------------------- > * TDCALL/SEAMCALL ABI: > *------------------------------------------------------------------------- > * Input Registers: > * > * RAX - Leaf number. > * RCX,RDX,R8-R11 - Leaf specific input registers. > * RDI,RSI,RBX,R11-R15 - VP.VMCALL VP.ENTER > * > * Output Registers: > * > * RAX - instruction error code. > * RCX,RDX,R8-R11 - Leaf specific output registers. > * RDI,RSI,RBX,R12-R15 - VP.VMCALL VP.ENTER > * > *------------------------------------------------------------------------- > * > * So while the common core (RAX,RCX,RDX,R8-R11) fits nicely in the > * callee-clobbered registers and even leaves RDI,RSI free to act as a base > * pointer some rare leafs (VP.VMCALL, VP.ENTER) make a giant mess of things. > * > * For simplicity, assume that anything that needs the callee-saved regs also > * tramples on RDI,RSI. This isn't strictly true, see for example EXPORT.MEM. > */ > .macro TDX_MODULE_CALL host:req ret:req saved:0 > FRAME_BEGIN > > movq %rdi, %rax > > movq TDX_MODULE_rcx(%rsi), %rcx > movq TDX_MODULE_rdx(%rsi), %rdx > movq TDX_MODULE_r8(%rsi), %r8 > movq TDX_MODULE_r9(%rsi), %r9 > movq TDX_MODULE_r10(%rsi), %r10 > movq TDX_MODULE_r11(%rsi), %r11 > > .if \saved > pushq rbx > pushq r12 > pushq r13 > pushq r14 > pushq r15 > > movq TDX_MODULE_rbx(%rsi), %rbx > movq TDX_MODULE_r12(%rsi), %r12 > movq TDX_MODULE_r13(%rsi), %r13 > movq TDX_MODULE_r14(%rsi), %r14 > movq TDX_MODULE_r15(%rsi), %r15 > > /* VP.VMCALL and VP.ENTER */ > .if \ret > pushq %rsi > .endif > movq TDX_MODULE_rdi(%rsi), %rdi > movq TDX_MODULE_rsi(%rsi), %rsi > .endif > > .Lcall: > .if \host > seamcall > /* > * SEAMCALL instruction is essentially a VMExit from VMX root > * mode to SEAM VMX root mode. VMfailInvalid (CF=1) indicates > * that the targeted SEAM firmware is not loaded or disabled, > * or P-SEAMLDR is busy with another SEAMCALL. RAX is not > * changed in this case. > */ > jc .Lseamfail > > .if \saved && \ret > /* > * VP.ENTER clears RSI on output, use it to restore state. > */ > popq %rsi > xor %edi,%edi > movq %rdi, TDX_MODULE_rdi(%rsi) > movq %rdi, TDX_MODULE_rsi(%rsi) > .endif > .else > tdcall > > /* > * RAX!=0 indicates a failure, assume no return values. > */ > testq %rax, %rax > jne .Lerror > > .if \saved && \ret > /* > * Since RAX==0, it can be used as a scratch register to restore state. > * > * [ assumes \saved implies \ret ] This comment is wrong. As should be obvious from the condition above. > */ > popq %rax > movq %rdi, TDX_MODULE_rdi(%rax) > movq %rsi, TDX_MODULE_rsi(%rax) > movq %rax, %rsi > xor %eax, %eax; > .endif > .endif // \host > > .if \ret > /* RSI is restored */ > movq %rcx, TDX_MODULE_rcx(%rsi) > movq %rdx, TDX_MODULE_rdx(%rsi) > movq %r8, TDX_MODULE_r8(%rsi) > movq %r9, TDX_MODULE_r9(%rsi) > movq %r10, TDX_MODULE_r10(%rsi) > movq %r11, TDX_MODULE_r11(%rsi) > .if \saved > movq %rbx, TDX_MODULE_rbx(%rsi) > movq %r12, TDX_MODULE_r12(%rsi) > movq %r13, TDX_MODULE_r13(%rsi) > movq %r14, TDX_MODULE_r14(%rsi) > movq %r15, TDX_MODULE_r15(%rsi) > .endif > .endif // \ret > > .Lout: > .if \saved > popq %r15 > popq %r14 > popq %r13 > popq %r12 > popq %rbx > .endif > FRAME_END > RET > > /* > * Error and exception handling at .Lcall. Ignore \ret on failure. > */ > .Lerror: > .if \saved && \ret > popq %rsi > .endif > jmp .Lout > > .if \host > .Lseamfail: > /* > * Set RAX to TDX_SEAMCALL_VMFAILINVALID for VMfailInvalid. > * This value will never be used as actual SEAMCALL error code as > * it is from the Reserved status code class. > */ > movq $TDX_SEAMCALL_VMFAILINVALID, %rax > jmp .Lerror > > .Lfault: > /* > * SEAMCALL caused #GP or #UD. Per _ASM_EXTABLE_FAULT() RAX > * contains the trap number, convert to a TDX error code by > * setting the high word to TDX_SW_ERROR. > */ > mov $TDX_SW_ERROR, %rdi > or %rdi, %rax > jmp .Lerror > > _ASM_EXTABLE_FAULT(.Lcall, .Lfault) > .endif > .endm