Received: by 2002:a05:6358:7058:b0:131:369:b2a3 with SMTP id 24csp121808rwp; Wed, 12 Jul 2023 10:34:23 -0700 (PDT) X-Google-Smtp-Source: APBJJlG05Exq0FNMzLpYfa8zWiWhGh+TKZN29tK7P1CbDWC0Olpv3lMqk46hBSkyOe3ck8+A9xX9 X-Received: by 2002:a50:eb04:0:b0:51d:8aaf:5adc with SMTP id y4-20020a50eb04000000b0051d8aaf5adcmr18180425edp.14.1689183262830; Wed, 12 Jul 2023 10:34:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689183262; cv=none; d=google.com; s=arc-20160816; b=Mv2nsHjWoljYjx+UUxW2FO1S5mLdHsjjszQbPNjN92vsSr0ZcrmBhASY3pc9X9LvKz 4h7FssY57i6MTpGK2u780JPVTGZPH1kDZxkeRNhcvcc/AD1GK2HDM/ccnPT1z1rxQ1Q+ rT1HFiaxyJur0dUTsssd4FboNLlYaJOgqBPYo01CZ3vh67CVjs+7t4v8rhIKob0oqlSe WBoM+ThRn6QWqJyBR76HOi3W7ZmqY2XQm+zakbM4HkvTDzpeMtbiMdq+2Q6lTtYaUoBi 8PzzoHZlyHF7fwco3yiyZwsFu4MMKOKFDY4ewZYqKboJDHWM2Lkg6zqBA5MpUb15M9fL dncw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=nmU8GDqFORVZB/GJG20KAAkvGNSEL3nSuZMjnbfCcN4=; fh=KIjGkAxmv/xewVcbgJIacpYvCmB6XJK44imZqBcIWEI=; b=izfZx6j3ALdaTLSOp+bJ3Na2yJ2IHCZgqci6Lr1DuHfFCVViURW3qwVm2ulpPtIZdT DJTsLfnTGPTXX/HNXgO8SBK5NkRSfIaPAJFeyEAbpGP3suAu4yFL3AsxmhIzEIvvk9nR z0YXTK69+gGUPKXuQ+4at94PC+oOYnghixT9Yxlq99jv61RUmtadEkOLcEA4aoagx0cp c0audKNHJprrx5HbMtJWMpB5dELLfYpug2wxqKLafk3KQRQpD6lOMY8Ih1YZ3jJ81dsv Xn0vZnwtZKZKP9vL/6HqXG7WBvpAZ1nOd2FKPEGiOfEn8ABNjqF8b8017TLWrKuxykcS I1tQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=desiato.20200630 header.b=Mvp68jWo; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s7-20020aa7c547000000b0051836749133si5342545edr.494.2023.07.12.10.33.58; Wed, 12 Jul 2023 10:34:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=desiato.20200630 header.b=Mvp68jWo; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232417AbjGLRLy (ORCPT + 99 others); Wed, 12 Jul 2023 13:11:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60030 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231592AbjGLRLx (ORCPT ); Wed, 12 Jul 2023 13:11:53 -0400 Received: from desiato.infradead.org (desiato.infradead.org [IPv6:2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 754641BDA; Wed, 12 Jul 2023 10:11:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; 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=nmU8GDqFORVZB/GJG20KAAkvGNSEL3nSuZMjnbfCcN4=; b=Mvp68jWogX7ikHndL5UCqHoqQ6 nT2g+CN5wvlK/DJNprCTtYAJ+MqoYRsiOibsBBDP/XJdEMi9GoTWPcSLHgV8JUQjCwKELEKlLUi95 nSPU6t4oD26oKzSg2MdxIpYuNTDj+5UiLEGron1I4xy2lAL7EmSITZyk4aUAORL/IiLA2xIPtnz1h +0IN2f9fWb8kwN/dOoLciWDuc0NZPYfTUccGQCZjlzGtkCxdlR2Gzi6rEcTH8efPOFyUBtb9zFHL9 /0eZLzMZpiVf5Bw0EQrblLpkxAzwSxw68bpHsxbLCPH4cJE8/bFYRLA4c3KF7TqfP7zXpies+Qd4q 4Ykh3k3Q==; Received: from j130084.upc-j.chello.nl ([24.132.130.84] helo=noisy.programming.kicks-ass.net) by desiato.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1qJdNG-003jJ9-1s; Wed, 12 Jul 2023 17:11:34 +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 777623001FD; Wed, 12 Jul 2023 19:11:33 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 5FAD227E80242; Wed, 12 Jul 2023 19:11:33 +0200 (CEST) Date: Wed, 12 Jul 2023 19:11:33 +0200 From: Peter Zijlstra To: Kai Huang Cc: kirill.shutemov@linux.intel.com, linux-kernel@vger.kernel.org, dave.hansen@intel.com, tglx@linutronix.de, bp@alien8.de, mingo@redhat.com, hpa@zytor.com, x86@kernel.org, seanjc@google.com, pbonzini@redhat.com, kvm@vger.kernel.org, isaku.yamahata@intel.com, sathyanarayanan.kuppuswamy@linux.intel.com Subject: Re: [PATCH 07/10] x86/tdx: Extend TDX_MODULE_CALL to support more TDCALL/SEAMCALL leafs Message-ID: <20230712171133.GB3115257@hirez.programming.kicks-ass.net> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. /* xor-swap (%rsp) and %rax */ xorq (%rsp), %rax xorq %rax, (%rsp) xorq (%rsp), %rax movq %rsi, TDX_MODULE_rsi(%rax); movq %rax, %rsi popq %rax Isn't much better is it :/ Too bad xchg implies lock prefix. > + > + /* Copy additional output regs to the structure */ > + movq %r12, TDX_MODULE_r12(%rsi) > + movq %r13, TDX_MODULE_r13(%rsi) > + movq %r14, TDX_MODULE_r14(%rsi) > + movq %r15, TDX_MODULE_r15(%rsi) > + movq %rbx, TDX_MODULE_rbx(%rsi) > + movq %rdi, TDX_MODULE_rdi(%rsi) > + .endif /* \saved */ > + > /* Copy output regs to the structure */ > movq %rcx, TDX_MODULE_rcx(%rsi) > movq %rdx, TDX_MODULE_rdx(%rsi)