Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp925067pxp; Wed, 16 Mar 2022 21:31:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz7McW9hbO80HCuH0Hd9vyY2AG5SjnOWrJaZrxnhliOCyShVCEz2OQvgoTooK+2ECtQNbiG X-Received: by 2002:a17:90a:66c3:b0:1bc:cfab:86ec with SMTP id z3-20020a17090a66c300b001bccfab86ecmr13899054pjl.74.1647491468624; Wed, 16 Mar 2022 21:31:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647491468; cv=none; d=google.com; s=arc-20160816; b=H8RBO7in//o95glegzG6TXLKuRHEY+U3kctaHjjYPofgmST0jAScPWW19o/MVB2K6g ODINRUV6cgh2vVH0M6RRnIW9Ql2PlN0k/ShecF6uk6VnOz8Y0KphVRnCH9NE7+/WpeBh otfoJFsR8KFM8Hs9LLigsuMT0sBvxJ0YZ/wMl/BKegaFAUnb90bjcW/urEmbVm4fWAuV xEgSuKXlJp6mS7uVjYfAtZgQvode3MzPHi1juc0THccSig8mHojNA8zE56URfy1NVf77 f1ZMLhoZGRLnoIircAqqLp5UAyl3be7zezWmDgbnw1vG2jBa3+YlmKRp29CZT6mrOPHn 8VZg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:references :in-reply-to:subject:cc:to:dkim-signature:dkim-signature:from; bh=2GryFkB1dgZgZSqpGGOfeLWHK3kOlc0ZY6tliFW5tjY=; b=HMhmYDWIvqNKtdSb+3uwiZe4222WahbUZB5CbUezNS8ZF69VwHE0EKys+Unhu1sBkD AbAPkpFCzdpvmDRD54768/8DLZOvXF15emsw1DcY9Ei1THwrHZy6pdfqidKqk1AP/VDD asZ2Z/lsRy2VvCXaNzcp/R7d3+BJMbNJ4Crr0GBlovMjfdYySTmmI8GA+J01WCYvZEgM NSYXgyTKWE2U1go+nsL1WP/hKzwoeQEQ5JaLQLCtE2ZWUxuIPDLYWFSqP09svEXLqGWd yJlmRa17lgnLCZ4DqlCAIaNh/oa8RgIVJaAU0xr4KGtE+qZOgewElZs2jiQ4aJqgeGbc IqGg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=i9UXGI5z; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=mI4a7x9a; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id m9-20020a1709026bc900b0014f8b7e5699si3265956plt.411.2022.03.16.21.31.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Mar 2022 21:31:08 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=i9UXGI5z; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=mI4a7x9a; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id CE0F5105A91; Wed, 16 Mar 2022 21:00:22 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240615AbiCPXfS (ORCPT + 99 others); Wed, 16 Mar 2022 19:35:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39208 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232408AbiCPXfQ (ORCPT ); Wed, 16 Mar 2022 19:35:16 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AB189AE63 for ; Wed, 16 Mar 2022 16:34:01 -0700 (PDT) From: Thomas Gleixner DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1647473639; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=2GryFkB1dgZgZSqpGGOfeLWHK3kOlc0ZY6tliFW5tjY=; b=i9UXGI5zY+83qU3gwG/iOxk8bfzzANkyE4w3tEYZ6ICEEFBdQK/qrMzWmYuzSn9UHsFqEW qqaiPCWbHfUX8gmTR0271NXFdmV2y3EWxFC/l2l/Jka2xfqB/VRtPM1BcAl7SB1DfNf2pI Zftqi+qnEMSGqukOkG/c2YGMw2/8V1cyT/tDtOz+t85HrUripQTQldJBF45X9bEofw8uV0 Jy+zRuLHtqd3eJhKKqpTbGW91BY66xT4g/RvZXLc7C57MiMLxxAjQkZvaLFRfomqgS4Yyc 7lXqKZuUh8/RspguVQuA9nsnNj5LJT360Rl7BjUrbRtl9XouVUd8KhNKW6YFvQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1647473639; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=2GryFkB1dgZgZSqpGGOfeLWHK3kOlc0ZY6tliFW5tjY=; b=mI4a7x9aOuphAbMwIQSw6y/Ay0HsSNJoqqrzWxxF2vO8hN/D5pw24Qev1PfP7HcHp4gEWM 8B/N2R3q+i9kdlAg== To: "Kirill A. Shutemov" , mingo@redhat.com, bp@alien8.de, dave.hansen@intel.com, luto@kernel.org, peterz@infradead.org Cc: sathyanarayanan.kuppuswamy@linux.intel.com, aarcange@redhat.com, ak@linux.intel.com, dan.j.williams@intel.com, david@redhat.com, hpa@zytor.com, jgross@suse.com, jmattson@google.com, joro@8bytes.org, jpoimboe@redhat.com, knsathya@kernel.org, pbonzini@redhat.com, sdeep@vmware.com, seanjc@google.com, tony.luck@intel.com, vkuznets@redhat.com, wanpengli@tencent.com, thomas.lendacky@amd.com, brijesh.singh@amd.com, x86@kernel.org, linux-kernel@vger.kernel.org, "Kirill A. Shutemov" , Dave Hansen Subject: Re: [PATCHv6 02/30] x86/tdx: Provide common base for SEAMCALL and TDCALL C wrappers In-Reply-To: <20220316020856.24435-3-kirill.shutemov@linux.intel.com> References: <20220316020856.24435-1-kirill.shutemov@linux.intel.com> <20220316020856.24435-3-kirill.shutemov@linux.intel.com> Date: Thu, 17 Mar 2022 00:33:58 +0100 Message-ID: <87lex9321l.ffs@tglx> MIME-Version: 1.0 Content-Type: text/plain X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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 Kirrill, On Wed, Mar 16 2022 at 05:08, Kirill A. Shutemov wrote: > Define an assembly macro that can be used to implement C wrapper for > both TDCALL and SEAMCALL. > > TDCALL wrapper will be implemented using the macro later in the series. > SEAMCALL wrapper is out-of-scope for the series and will be implemented > as part of TDX host enabling. This paragraph makes no sense in the changelog once it's merged. That's a reviewer/maintainer info which wants to be below the --- > +/* > + * 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. > + * > + * Both instruction are supported in Binutils >= 2.36. > + */ > +#define tdcall .byte 0x66,0x0f,0x01,0xcc > +#define seamcall .byte 0x66,0x0f,0x01,0xcf Bah. I really hate this #define glue. The comment documents TDX_MODULE_CALL. The defines for the instructions are a seperate problem. So please move them above the whole thing with their own comment. > +.macro TDX_MODULE_CALL host:req > + /* > + * R12 will be used as temporary storage for struct tdx_module_output > + * pointer. Since R12-R15 registers are not used by TDCALL/SEAMCALL > + * services supported by this function, it can be reused. > + */ > + > + /* Callee saved, so preserve it */ > + push %r12 > + > + /* > + * Push output pointer to stack. > + * After the operation, it will be fetched into R12 register. > + */ > + push %r9 > + > + /* Mangle function call ABI into TDCALL/SEAMCALL ABI: */ > + /* Move Leaf ID to RAX */ > + mov %rdi, %rax > + /* Move input 4 to R9 */ > + mov %r8, %r9 > + /* Move input 3 to R8 */ > + mov %rcx, %r8 > + /* Move input 1 to RCX */ > + mov %rsi, %rcx > + /* Leave input param 2 in RDX */ > + > + .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. > + * > + * 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. > + */ > + jnc .Lno_vmfailinvalid > + mov $TDX_SEAMCALL_VMFAILINVALID, %rax > +.Lno_vmfailinvalid: Please add a new line between the label and the .else for readability sake. > + .else > + tdcall > + .endif > + > + /* > + * Fetch output pointer from stack to R12 (It is used > + * as temporary storage) > + */ > + pop %r12 > + > + /* > + * Since this function can be initiated without an output pointer, > + * check if caller provided an output struct before storing output > + * registers. The function is a macro. It's not initiated, it's invoked. It always has an output pointer in R12, but that can be NULL. With those nitpicks addressed: Reviewed-by: Thomas Gleixner