Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp5508195pxb; Mon, 7 Feb 2022 03:44:50 -0800 (PST) X-Google-Smtp-Source: ABdhPJxZKAR/rcJ3k4h716ww63XLknkDiiqR6todj1Zi/x1pkEDq36KAXpk6jDnPsk9GrDlkXjMB X-Received: by 2002:a17:902:b683:: with SMTP id c3mr16413718pls.144.1644234290050; Mon, 07 Feb 2022 03:44:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644234290; cv=none; d=google.com; s=arc-20160816; b=rfn7LIeyfDudhhEJEo6tDgYbVt6+wC6dIyikzWJHgpTO/f5Ojh3HR61RsEdGKjroqo ucdwPC0OpsCOyvfvKRBt2rALf81+o8BX+g1d9oFUcpVCo3e/+CUnUKoDy9tQIdtLJ4C0 Hq/yVRh1O5DVzmhDxs+7f6akWtz2K+Rqz1rD15cnvGNxyFIxl4Vt7eOn0aKUFO91zrc8 UpqKso6CUxD+iCrfFkn7EFWh9N5ZS5BOW3WsXDUa8e0D9ruEySe+ZtQLTIONWr0PKlKi qh7MaAkDVESh91qJcuEE2mnK+WyWuSWYAFO2OtPWsRiS/GnAVwHyoqe/mfD0RfVe1D99 Mhmg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=fbFqkdP84PS1UhA02bf+46KGcJveEqXXFxkI1fr80hc=; b=LUIoSuLffzb2ApO4GdiP/lvaq+4teOEvYXxIZinmbs53yYa/DT26IfH0Vc9+zbPj79 93547wYrudCyJlJvqXrh5rOe7tOVgbO78fTcw/bMGOzFxCmfhXTsaf5O24Nxjf2UQgpN o21EyeD02sUEOq8gQ4USZmz0bbBHNQP/XQX+7VWNqYAInAIf2uGWelCeDJ/Uq/KtG+Cw 3SgQTvdf6sNPVESB3hJbUXa2w37p572bwH08LqXzNrztb0vA6ArcaYBNoK9QntJR5SMN WNMDwMSr7ai4JL1ZpVFJxPwUbM8xyWKtVSzD7cIw6XuiAPwjQOxHU2oyUdjx5DDXxOO7 62LA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=EFIFtkI6; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x16si1545708pjr.116.2022.02.07.03.44.38; Mon, 07 Feb 2022 03:44:50 -0800 (PST) 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=@intel.com header.s=Intel header.b=EFIFtkI6; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1357865AbiBDJvr (ORCPT + 99 others); Fri, 4 Feb 2022 04:51:47 -0500 Received: from mga03.intel.com ([134.134.136.65]:62513 "EHLO mga03.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345599AbiBDJvq (ORCPT ); Fri, 4 Feb 2022 04:51:46 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1643968306; x=1675504306; h=date:from:to:cc:subject:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=VpvsouKtfytZM1zm826Tw50a4we77vDGpg9yQSoAclw=; b=EFIFtkI6/fPWEyXvUx1jH0H6qHdLvqTbQSP6E9RycMMi+RasH70xFfAR ePoVNgEIU2zV1bmCNTYof7c3VS1gdZRfAmdoyhZEWvL5Q0PY7nkEOxCZv R+YezfxAKXhd0S2gRAWr+8R7pjhSlou+p5/dAvi/cZv6B4wnu6ZenCv6P xmm10AGiM96tF2RLZjtNMgabbkoRVgu/xtiGV8LA+yrDCwE4ZbCAO/AgI GIMNntQu8CqxP8OjzT/p9DhGsVgQNkfHopYpXpdGWL0oSqLjgcApVidPK pQJRT91hpxhqW/LvcAUzm2D7wyTuEX2uY4UviinK86YsPqyo5GMx2igBy w==; X-IronPort-AV: E=McAfee;i="6200,9189,10247"; a="248290998" X-IronPort-AV: E=Sophos;i="5.88,342,1635231600"; d="scan'208";a="248290998" Received: from orsmga006.jf.intel.com ([10.7.209.51]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Feb 2022 01:51:46 -0800 X-IronPort-AV: E=Sophos;i="5.88,342,1635231600"; d="scan'208";a="483563833" Received: from rkothand-mobl1.amr.corp.intel.com (HELO khuang2-desk.gar.corp.intel.com) ([10.255.86.47]) by orsmga006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Feb 2022 01:51:40 -0800 Date: Fri, 4 Feb 2022 22:51:38 +1300 From: Kai Huang To: "Kirill A. Shutemov" Cc: Thomas Gleixner , , , , , , , , , , , , , , , , , , , , , , , , Subject: Re: [PATCHv2 03/29] x86/tdx: Add __tdx_module_call() and __tdx_hypercall() helper functions Message-Id: <20220204225138.e76f6e98e0208d746606099d@intel.com> In-Reply-To: <20220204034312.43rotpihciik2gk6@black.fi.intel.com> References: <20220124150215.36893-1-kirill.shutemov@linux.intel.com> <20220124150215.36893-4-kirill.shutemov@linux.intel.com> <87a6faz7cs.ffs@tglx> <20220202025519.csymm7r23b3ltpia@black.fi.intel.com> <20220202235910.c512857813ea5b14aa73267f@intel.com> <20220203144403.ytyw5vcv4gshxyhn@black.fi.intel.com> <20220204034312.43rotpihciik2gk6@black.fi.intel.com> X-Mailer: Sylpheed 3.7.0 (GTK+ 2.24.33; x86_64-redhat-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org > + > +.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. > + */ > + jnc .Lno_vmfailinvalid > + mov $TDX_SEAMCALL_VMFAILINVALID, %rax > + jmp .Lno_output_struct If I read correctly, in case of VMfailInvalid, another "pop %r12" is needed before jmp to .Lno_output_struct, otherwise it doesn't match the stack (pushed twice). However, since "test %rax, %rax" will also catch TDX_SEAMCALL_VMFAILINVALID, it seems we can just delete above "jmp .Lno_output_struct"? > +.Lno_vmfailinvalid: > + .else > + tdcall > + .endif > + > + /* > + * Fetch output pointer from stack to R12 (It is used > + * as temporary storage) > + */ > + pop %r12 > + > + /* Check for success: 0 - Successful, otherwise failed */ > + test %rax, %rax > + jnz .Lno_output_struct > + > + /* > + * Since this function can be initiated without an output pointer, > + * check if caller provided an output struct before storing > + * output registers. > + */ > + test %r12, %r12 > + jz .Lno_output_struct > + > + /* Copy result registers to output struct: */ > + movq %rcx, TDX_MODULE_rcx(%r12) > + movq %rdx, TDX_MODULE_rdx(%r12) > + movq %r8, TDX_MODULE_r8(%r12) > + movq %r9, TDX_MODULE_r9(%r12) > + movq %r10, TDX_MODULE_r10(%r12) > + movq %r11, TDX_MODULE_r11(%r12) > + > +.Lno_output_struct: > + /* Restore the state of R12 register */ > + pop %r12 > +.endm > -- > Kirill A. Shutemov