From: "Huang, Kai" <kai.huang@intel.com>
To: "peterz@infradead.org" <peterz@infradead.org>
Cc: "Hansen, Dave" <dave.hansen@intel.com>, "Christopherson,,
Sean" <seanjc@google.com>, "bp@alien8.de" <bp@alien8.de>,
"x86@kernel.org" <x86@kernel.org>,
"hpa@zytor.com" <hpa@zytor.com>,
"mingo@redhat.com" <mingo@redhat.com>,
"kirill.shutemov@linux.intel.com"
<kirill.shutemov@linux.intel.com>,
"tglx@linutronix.de" <tglx@linutronix.de>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"pbonzini@redhat.com" <pbonzini@redhat.com>,
"Yamahata, Isaku" <isaku.yamahata@intel.com>,
"kvm@vger.kernel.org" <kvm@vger.kernel.org>,
"sathyanarayanan.kuppuswamy@linux.intel.com"
<sathyanarayanan.kuppuswamy@linux.intel.com>
Subject: Re: [PATCH 10/10] x86/virt/tdx: Allow SEAMCALL to handle #UD and #GP
Date: Thu, 13 Jul 2023 09:58:40 +0000 [thread overview]
Message-ID: <00ae5246b3b4e1f812ee061b7bfa21b5ab2ec0a3.camel@intel.com> (raw)
In-Reply-To: <20230713080745.GB3139243@hirez.programming.kicks-ass.net>
On Thu, 2023-07-13 at 10:07 +0200, Peter Zijlstra wrote:
> On Wed, Jul 12, 2023 at 08:55:24PM +1200, Kai Huang wrote:
> > @@ -85,6 +86,7 @@
> > .endif /* \saved */
> >
> > .if \host
> > +1:
> > seamcall
> > /*
> > * SEAMCALL instruction is essentially a VMExit from VMX root
> > @@ -99,6 +101,7 @@
> > */
> > mov $TDX_SEAMCALL_VMFAILINVALID, %rdi
> > cmovc %rdi, %rax
> > +2:
> > .else
> > tdcall
> > .endif
>
> This is just wrong, if the thing traps you should not do the return
> registers. And at this point the mov/cmovc thing doesn't make much sense
> either.
OK will do. Yes "do return registers" isn't necessary. I thought to keep code
simple we can just do it. The trap/VMFAILINVALID code path isn't in performance
path anyway.
This is a problem in the current upstream code too. I'll fix it first in a
separate patch.
>
> > @@ -185,4 +188,21 @@
> >
> > FRAME_END
> > RET
> > +
> > + .if \host
> > +3:
> > + /*
> > + * SEAMCALL caused #GP or #UD. By reaching here %eax contains
> > + * the trap number. Convert the trap number to the TDX error
> > + * code by setting TDX_SW_ERROR to the high 32-bits of %rax.
> > + *
> > + * Note cannot OR TDX_SW_ERROR directly to %rax as OR instruction
> > + * only accepts 32-bit immediate at most.
> > + */
> > + movq $TDX_SW_ERROR, %r12
> > + orq %r12, %rax
> > + jmp 2b
> > +
> > + _ASM_EXTABLE_FAULT(1b, 3b)
> > + .endif /* \host */
> > .endm
>
> Also, please used named labels where possible and *please* keep asm
> directives unindented.
Yes will do.
>
>
> --- a/arch/x86/virt/vmx/tdx/tdxcall.S
> +++ b/arch/x86/virt/vmx/tdx/tdxcall.S
> @@ -56,7 +56,7 @@
> movq TDX_MODULE_r10(%rsi), %r10
> movq TDX_MODULE_r11(%rsi), %r11
>
> - .if \saved
> +.if \saved
> /*
> * Move additional input regs from the structure. For simplicity
> * assume that anything needs the callee-saved regs also tramples
> @@ -75,18 +75,18 @@
> movq TDX_MODULE_r15(%rsi), %r15
> movq TDX_MODULE_rbx(%rsi), %rbx
>
> - .if \ret
> +.if \ret
> /* Save the structure pointer as %rsi is about to be clobbered */
> pushq %rsi
> - .endif
> +.endif
>
> movq TDX_MODULE_rdi(%rsi), %rdi
> /* %rsi needs to be done at last */
> movq TDX_MODULE_rsi(%rsi), %rsi
> - .endif /* \saved */
> +.endif /* \saved */
>
> - .if \host
> -1:
> +.if \host
> +.Lseamcall:
> seamcall
> /*
> * SEAMCALL instruction is essentially a VMExit from VMX root
> @@ -99,15 +99,13 @@
> * This value will never be used as actual SEAMCALL error code as
> * it is from the Reserved status code class.
> */
> - mov $TDX_SEAMCALL_VMFAILINVALID, %rdi
> - cmovc %rdi, %rax
> -2:
> - .else
> + jc .Lseamfail
> +.else
> tdcall
> - .endif
> +.endif
>
> - .if \ret
> - .if \saved
> +.if \ret
> +.if \saved
> /*
> * Restore the structure from stack to saved the output registers
> *
> @@ -136,7 +134,7 @@
> movq %r15, TDX_MODULE_r15(%rsi)
> movq %rbx, TDX_MODULE_rbx(%rsi)
> movq %rdi, TDX_MODULE_rdi(%rsi)
> - .endif /* \saved */
> +.endif /* \saved */
>
> /* Copy output regs to the structure */
> movq %rcx, TDX_MODULE_rcx(%rsi)
> @@ -145,10 +143,11 @@
> movq %r9, TDX_MODULE_r9(%rsi)
> movq %r10, TDX_MODULE_r10(%rsi)
> movq %r11, TDX_MODULE_r11(%rsi)
> - .endif /* \ret */
> +.endif /* \ret */
>
> - .if \saved
> - .if \ret
> +.Lout:
> +.if \saved
> +.if \ret
> /*
> * Clear registers shared by guest for VP.ENTER and VP.VMCALL to
> * prevent speculative use of values from guest/VMM, including
> @@ -170,13 +169,8 @@
> xorq %r9, %r9
> xorq %r10, %r10
> xorq %r11, %r11
> - xorq %r12, %r12
> - xorq %r13, %r13
> - xorq %r14, %r14
> - xorq %r15, %r15
> - xorq %rbx, %rbx
> xorq %rdi, %rdi
> - .endif /* \ret */
> +.endif /* \ret */
>
> /* Restore callee-saved GPRs as mandated by the x86_64 ABI */
> popq %r15
> @@ -184,13 +178,17 @@
> popq %r13
> popq %r12
> popq %rbx
> - .endif /* \saved */
> +.endif /* \saved */
>
> FRAME_END
> RET
>
> - .if \host
> -3:
> +.if \host
> +.Lseamfail:
> + mov $TDX_SEAMCALL_VMFAILINVALID, %rax
> + jmp .Lout
> +
> +.Lseamtrap:
> /*
> * SEAMCALL caused #GP or #UD. By reaching here %eax contains
> * the trap number. Convert the trap number to the TDX error
> @@ -201,8 +199,8 @@
> */
> movq $TDX_SW_ERROR, %r12
> orq %r12, %rax
> - jmp 2b
> + jmp .Lout
Thanks for the code.
There might be stack balancing issue here. I'll double check when updating this
patch.
Thanks!
>
> - _ASM_EXTABLE_FAULT(1b, 3b)
> - .endif /* \host */
> + _ASM_EXTABLE_FAULT(.Lseamcall, .Lseamtrap)
> +.endif /* \host */
> .endm
prev parent reply other threads:[~2023-07-13 9:59 UTC|newest]
Thread overview: 58+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-07-12 8:55 [PATCH 00/10] Unify TDCALL/SEAMCALL and TDVMCALL assembly Kai Huang
2023-07-12 8:55 ` [PATCH 01/10] x86/tdx: Zero out the missing RSI in TDX_HYPERCALL macro Kai Huang
2023-07-12 19:19 ` Sathyanarayanan Kuppuswamy
2023-07-12 8:55 ` [PATCH 02/10] x86/tdx: Use cmovc to save a label in TDX_MODULE_CALL asm Kai Huang
2023-07-12 19:27 ` Sathyanarayanan Kuppuswamy
2023-07-13 10:32 ` Huang, Kai
2023-07-12 8:55 ` [PATCH 03/10] x86/tdx: Move FRAME_BEGIN/END to TDX_MODULE_CALL asm macro Kai Huang
2023-07-12 19:57 ` Sathyanarayanan Kuppuswamy
2023-07-12 22:05 ` Isaku Yamahata
2023-07-12 8:55 ` [PATCH 04/10] x86/tdx: Make macros of TDCALLs consistent with the spec Kai Huang
2023-07-14 12:28 ` Nikolay Borisov
2023-07-14 12:28 ` Nikolay Borisov
2023-07-17 0:57 ` Huang, Kai
2023-07-12 8:55 ` [PATCH 05/10] x86/tdx: Rename __tdx_module_call() to __tdcall() Kai Huang
2023-07-12 8:55 ` [PATCH 06/10] x86/tdx: Pass TDCALL/SEAMCALL input/output registers via a structure Kai Huang
2023-07-12 8:55 ` [PATCH 07/10] x86/tdx: Extend TDX_MODULE_CALL to support more TDCALL/SEAMCALL leafs Kai Huang
2023-07-12 16:53 ` Peter Zijlstra
2023-07-12 16:59 ` Peter Zijlstra
2023-07-13 8:02 ` Huang, Kai
2023-07-13 8:43 ` Peter Zijlstra
2023-07-13 10:19 ` Huang, Kai
2023-07-13 10:24 ` Huang, Kai
2023-07-13 10:39 ` Peter Zijlstra
2023-07-13 10:37 ` Peter Zijlstra
2023-07-13 10:47 ` Huang, Kai
2023-07-13 11:22 ` Andrew Cooper
2023-07-13 11:40 ` Huang, Kai
2023-07-13 7:48 ` Huang, Kai
2023-07-13 8:46 ` Peter Zijlstra
2023-07-13 9:34 ` Huang, Kai
2023-07-13 9:40 ` Peter Zijlstra
2023-07-12 17:11 ` Peter Zijlstra
2023-07-13 8:09 ` Huang, Kai
2023-07-13 9:01 ` Peter Zijlstra
2023-07-13 9:15 ` Huang, Kai
2023-07-13 9:25 ` Peter Zijlstra
2023-07-13 10:01 ` Huang, Kai
2023-07-12 8:55 ` [PATCH 08/10] x86/tdx: Unify TDX_HYPERCALL and TDX_MODULE_CALL assembly Kai Huang
2023-07-15 10:05 ` Nikolay Borisov
2023-07-17 6:35 ` Huang, Kai
2023-07-17 7:02 ` Nikolay Borisov
2023-07-17 7:58 ` Huang, Kai
2023-07-18 10:32 ` Huang, Kai
2023-07-12 8:55 ` [PATCH 09/10] x86/virt/tdx: Wire up basic SEAMCALL functions Kai Huang
2023-07-12 22:15 ` Isaku Yamahata
2023-07-13 3:46 ` Huang, Kai
2023-07-13 7:42 ` Peter Zijlstra
2023-07-13 8:18 ` Huang, Kai
2023-07-13 9:03 ` Peter Zijlstra
2023-07-13 9:20 ` Huang, Kai
2023-07-13 14:51 ` Sean Christopherson
2023-07-17 3:52 ` Huang, Kai
2023-07-13 18:44 ` Isaku Yamahata
2023-08-08 9:16 ` Yuan Yao
2023-08-14 20:37 ` Isaku Yamahata
2023-07-12 8:55 ` [PATCH 10/10] x86/virt/tdx: Allow SEAMCALL to handle #UD and #GP Kai Huang
2023-07-13 8:07 ` Peter Zijlstra
2023-07-13 9:58 ` Huang, Kai [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=00ae5246b3b4e1f812ee061b7bfa21b5ab2ec0a3.camel@intel.com \
--to=kai.huang@intel.com \
--cc=bp@alien8.de \
--cc=dave.hansen@intel.com \
--cc=hpa@zytor.com \
--cc=isaku.yamahata@intel.com \
--cc=kirill.shutemov@linux.intel.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=pbonzini@redhat.com \
--cc=peterz@infradead.org \
--cc=sathyanarayanan.kuppuswamy@linux.intel.com \
--cc=seanjc@google.com \
--cc=tglx@linutronix.de \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Powered by JetHome