Received: by 2002:a05:6358:7058:b0:131:369:b2a3 with SMTP id 24csp862183rwp; Thu, 13 Jul 2023 02:11:35 -0700 (PDT) X-Google-Smtp-Source: APBJJlE0iVJ1qQ7FTF9CTUQCVVq/VzH5meA/ERtW18mdWC8ss/gFbP12vEErLUA64mrxRHDg+U1v X-Received: by 2002:aa7:cfcd:0:b0:514:9929:1b01 with SMTP id r13-20020aa7cfcd000000b0051499291b01mr1204880edy.8.1689239495196; Thu, 13 Jul 2023 02:11:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689239495; cv=none; d=google.com; s=arc-20160816; b=Tu0gRZf3teBUPMsu8/Fht+OzC4FIosAxZr419wqpAgNo8erMFuHBxlqRLduxLjQ146 c/Y9Ih9KqoFn4dadro1UsLoqx5C/lRAAqQnRQJfUJ+b50huxfWir/swZA4xlCxrEIUWu Dsjk7WakOWjTHPp+mF0Tg/gFEg5VbYw2+iGp4X/4woU16Uqm2PcoBI+v9G22D7JWYmgU BHzEKB9z40sHA4/u5QOTi54fp/s2UwpCSZXjUy6rmXEMWTJZlIV7M14QF5JOCpDcKn3H nXA+A27aIMm8RhIgR61dDfnPdt9CanB6ez2/UcJIFIL00dh5ZtUywwudKJ5pTZbNrVa2 JT3w== 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=SvFjQgh7iMrGngVir0RKl1OuGXHDDPqcLIw4Qq3ouqo=; fh=N+OK3Z4UlsoYtYFjfiw+LF5DCixo9u8YyFGQpJCZL3w=; b=kgwA62rT0O9jDsnU8dvFOC2GB4uX+zdN2B0VF8SACUU5dB2ewOdgt4zT/6XfX4YLB6 MF9QUau+ztYQ0MLU5ynd4jKiAM3u/0wDO5MOaKXHu+vJY1p7Raw0I6fDKupPMJA9PdMz zGsnmPhsKAQu4u17d6Xyygbc0nBeAytXCJ+BOQ2HO7FYFLJugPbK526BE/syZk/StXRy FKFoYVHrP0OM6j2AP7QwGd9lR7FPNOIvoskUyqyh/04dAHlcGb4rIb67jeo0GDzytqw8 FCooHr6FAxcYHIs8+DDLJTa8WKN7R8ix0CFEutFTLW3b507CWStTgUHE8YqxvVYjhjKl OWMw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=Z8O9ONkl; 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 l12-20020aa7c30c000000b0051dd22715c4si1063777edq.196.2023.07.13.02.11.11; Thu, 13 Jul 2023 02:11:35 -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=casper.20170209 header.b=Z8O9ONkl; 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 S234239AbjGMJCo (ORCPT + 99 others); Thu, 13 Jul 2023 05:02:44 -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: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE 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 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.