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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7C755C001B0 for ; Thu, 13 Jul 2023 09:02:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234264AbjGMJCp (ORCPT ); Thu, 13 Jul 2023 05:02:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59308 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232357AbjGMJCT (ORCPT ); Thu, 13 Jul 2023 05:02:19 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 147392D43; Thu, 13 Jul 2023 02:01:33 -0700 (PDT) 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=SvFjQgh7iMrGngVir0RKl1OuGXHDDPqcLIw4Qq3ouqo=; b=Z8O9ONkl5y8vJdFIYe/+RdrdE0 URpFWy9AVayh4SUvAYwyCgJSzmdK/eGYR+dzAxL8ORuOhVzjb5Q8SDsBSRq/XWEpV7Ctn+oJpthk4 3dYqwmZXPs/Lvjewhs5lqdmjGPBcAUkqtYrE+BTqbbe/Zh9cHGZi4QJaD3nUGZ4IGnoi5ZBskicoR 1tKJNIZM/WlxMIvDPsvbqKdqMwgE8A4GESceWXs9MmpwkhPD3MCgHEHGmXu3ER0qBQug9pfi/I99u UceBkoaLJh89wEYiPuoF5gGM+ySaIhW9Lp+0G5aAefFFzwxWco3AbQDmjND45FE9eNYzJE/967n0h ele+Q0MQ==; 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 1qJsCG-00HaMu-C1; Thu, 13 Jul 2023 09:01:12 +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 B7F26300222; Thu, 13 Jul 2023 11:01:10 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 9FB33245CA111; Thu, 13 Jul 2023 11:01:10 +0200 (CEST) Date: Thu, 13 Jul 2023 11:01:10 +0200 From: Peter Zijlstra To: "Huang, Kai" Cc: "Hansen, Dave" , "Christopherson,, Sean" , "bp@alien8.de" , "x86@kernel.org" , "hpa@zytor.com" , "mingo@redhat.com" , "kirill.shutemov@linux.intel.com" , "tglx@linutronix.de" , "linux-kernel@vger.kernel.org" , "pbonzini@redhat.com" , "Yamahata, Isaku" , "kvm@vger.kernel.org" , "sathyanarayanan.kuppuswamy@linux.intel.com" Subject: Re: [PATCH 07/10] x86/tdx: Extend TDX_MODULE_CALL to support more TDCALL/SEAMCALL leafs Message-ID: <20230713090110.GC3138667@hirez.programming.kicks-ass.net> References: <20230712171133.GB3115257@hirez.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jul 13, 2023 at 08:09:33AM +0000, Huang, Kai wrote: > On Wed, 2023-07-12 at 19:11 +0200, Peter Zijlstra wrote: > > On Wed, Jul 12, 2023 at 08:55:21PM +1200, Kai Huang wrote: > > > @@ -65,6 +104,37 @@ > > > .endif > > > > > > .if \ret > > > + .if \saved > > > + /* > > > + * Restore the structure from stack to saved the output registers > > > + * > > > + * In case of VP.ENTER returns due to TDVMCALL, all registers are > > > + * valid thus no register can be used as spare to restore the > > > + * structure from the stack (see "TDH.VP.ENTER Output Operands > > > + * Definition on TDCALL(TDG.VP.VMCALL) Following a TD Entry"). > > > + * For this case, need to make one register as spare by saving it > > > + * to the stack and then manually load the structure pointer to > > > + * the spare register. > > > + * > > > + * Note for other TDCALLs/SEAMCALLs there are spare registers > > > + * thus no need for such hack but just use this for all for now. > > > + */ > > > + pushq %rax /* save the TDCALL/SEAMCALL return code */ > > > + movq 8(%rsp), %rax /* restore the structure pointer */ > > > + movq %rsi, TDX_MODULE_rsi(%rax) /* save %rsi */ > > > + movq %rax, %rsi /* use %rsi as structure pointer */ > > > + popq %rax /* restore the return code */ > > > + popq %rsi /* pop the structure pointer */ > > > > Urgghh... At least for the \host case you can simply pop %rsi, no? > > VP.ENTER returns with 0 there IIRC. > > No VP.ENTER doesn't return 0 for RAX. Firstly, VP.ENTER can return for many No, but it *does* return 0 for: RBX,RSI,RDI,R10-R15. So for \host you can simply do: pop %rsi mov $0, TDX_MODULE_rsi(%rsi) and call it a day.