Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp19379781rwd; Wed, 28 Jun 2023 08:33:51 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5a2iyBP8ZuVrYqitEMPQKq+hsCR2ArDUmFOF4RXoaHQ5kFoJgBK4Osvj3sKid8xjlk8LKz X-Received: by 2002:a17:907:97c9:b0:98e:3dac:6260 with SMTP id js9-20020a17090797c900b0098e3dac6260mr1762547ejc.13.1687966431390; Wed, 28 Jun 2023 08:33:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687966431; cv=none; d=google.com; s=arc-20160816; b=ie9LqdltX6gfMHar/bSEGu9D6Z2JUIiybTTlXKq1UQbEbwYyAunXoz2M1rt21KbOk9 nQvmo5EfldwAkt71FauaJTZVOlW/rkaV5qe1Kz0w73CUPVElWKa6TmVEOOznT7Q1nwNJ VXPJEyxavPRVMe8mrfUHtqbGD0VaVUrY2YOY/e/SCfDI8oh4ARuwIOYeqP8C2FaE2V1T ZjZdsRmpD8kTxO8r9MlV4Rx1Vc+JIXtfor+Khdp7CH9NJ9UEXA1FKOqJF6zW0pjORDh1 Yx4ZTMF07AYZyzvCtJMYio9k6MBrOTFCGb1aTY8vVzijGuvlq8bBzTXz5tW6Abt3SWtN 7qmg== 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=yx7U6Q1zu/jZUmaTgwSAgFdK87Ilf4lSewGXSOlnpeM=; fh=J+tAcrUWMfKfAQtqVbrwcZxyy6a1S2hUqiWhIWyDv7Y=; b=o8hAT+w5moRiMnM39ZOwnW7vDEOgaR8TI8Np+b8DwmJxYATG1wpmoFl8W1kNP18Fiz 553g4j1jyuxvBC4FunyBfOioy98RGfB1KRp4BFXOLzsNJSYS1sgusVFwxBvR/TyYRYQy BLXAcH8o+b+AJtq1d7MMr9corcT7iXJDHa9DYfP7F7Pk+UJ7MbH1fqwMM7S+XzxgcEgc GVjuxiH2MVFjfWnNbJMz1P/JSTYhF2Dp9I4Zo3r5wGdI+CncuyV5HkWfkGpWghS6tdRY 8gQtA3nu3eJg3DSvk6XuobiSduIpiQB/OFBDlAxtGQ1NvmKpVloFFl7Us/fh9fYgF4Ns fqxg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=desiato.20200630 header.b="j/HFTVj/"; 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 lu10-20020a170906faca00b0098df6fba6casi5380579ejb.47.2023.06.28.08.33.23; Wed, 28 Jun 2023 08:33:51 -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="j/HFTVj/"; 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 S232143AbjF1PaF (ORCPT + 99 others); Wed, 28 Jun 2023 11:30:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60416 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232098AbjF1PaA (ORCPT ); Wed, 28 Jun 2023 11:30:00 -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 AFEAA268F; Wed, 28 Jun 2023 08:29:59 -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=yx7U6Q1zu/jZUmaTgwSAgFdK87Ilf4lSewGXSOlnpeM=; b=j/HFTVj/s4oubzmOZQkbXs2rGy m89lVq7Gr97cfnYWa6xARbldnNMVFMkRq8W1AjOORgsbE+JDe1bw/SVj909aNMoaQgR33VCyocwnB jMyRPT/RNe6DUCMNQAbSh+QXX1aa+EunTFd0+s08kp6YUsHL37mxE+tFruQTX09nNF/z4QHlhYdw/ Q5Ev1yPX6SCK8BzGSUJsl0YZ9yclM8o4/U1hfdZUH6Q02BMUKP1h+1S3pQ/wYL/2iY2EjTmEFlAP+ boThf77OadEYRu9XDFgab10EyNjLhgCEc6jrk8JIR2EiwsURk08sQ48aUNIfNGmiKUfXlxu01rmoL unCslgyg==; 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 1qEX6M-005iuP-1l; Wed, 28 Jun 2023 15:29:02 +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) server-digest SHA256) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id 16CA73002D6; Wed, 28 Jun 2023 17:29:01 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id F340423B2EE90; Wed, 28 Jun 2023 17:29:00 +0200 (CEST) Date: Wed, 28 Jun 2023 17:29:00 +0200 From: Peter Zijlstra To: Kai Huang Cc: linux-kernel@vger.kernel.org, kvm@vger.kernel.org, linux-mm@kvack.org, x86@kernel.org, dave.hansen@intel.com, kirill.shutemov@linux.intel.com, tony.luck@intel.com, tglx@linutronix.de, bp@alien8.de, mingo@redhat.com, hpa@zytor.com, seanjc@google.com, pbonzini@redhat.com, david@redhat.com, dan.j.williams@intel.com, rafael.j.wysocki@intel.com, ashok.raj@intel.com, reinette.chatre@intel.com, len.brown@intel.com, ak@linux.intel.com, isaku.yamahata@intel.com, ying.huang@intel.com, chao.gao@intel.com, sathyanarayanan.kuppuswamy@linux.intel.com, nik.borisov@suse.com, bagasdotme@gmail.com, sagis@google.com, imammedo@redhat.com Subject: Re: [PATCH v12 20/22] x86/virt/tdx: Allow SEAMCALL to handle #UD and #GP Message-ID: <20230628152900.GI2438817@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 Tue, Jun 27, 2023 at 02:12:50AM +1200, Kai Huang wrote: > diff --git a/arch/x86/virt/vmx/tdx/tdxcall.S b/arch/x86/virt/vmx/tdx/tdxcall.S > index 49a54356ae99..757b0c34be10 100644 > --- a/arch/x86/virt/vmx/tdx/tdxcall.S > +++ b/arch/x86/virt/vmx/tdx/tdxcall.S > @@ -1,6 +1,7 @@ > /* SPDX-License-Identifier: GPL-2.0 */ > #include > #include > +#include > > /* > * TDCALL and SEAMCALL are supported in Binutils >= 2.36. > @@ -45,6 +46,7 @@ > /* Leave input param 2 in RDX */ > > .if \host > +1: > seamcall So what registers are actually clobbered by SEAMCALL ? There's a distinct lack of it in SDM Vol.2 instruction list :-( > /* > * SEAMCALL instruction is essentially a VMExit from VMX root > @@ -57,10 +59,23 @@ > * This value will never be used as actual SEAMCALL error code as > * it is from the Reserved status code class. > */ > - jnc .Lno_vmfailinvalid > + jnc .Lseamcall_out > mov $TDX_SEAMCALL_VMFAILINVALID, %rax > -.Lno_vmfailinvalid: > + jmp .Lseamcall_out > +2: > + /* > + * SEAMCALL caused #GP or #UD. By reaching here %eax contains > + * the trap number. Convert the trap number to the TDX error > + * code by setting TDX_SW_ERROR to the high 32-bits of %rax. > + * > + * Note cannot OR TDX_SW_ERROR directly to %rax as OR instruction > + * only accepts 32-bit immediate at most. > + */ > + mov $TDX_SW_ERROR, %r12 > + orq %r12, %rax > > + _ASM_EXTABLE_FAULT(1b, 2b) > +.Lseamcall_out: This is all pretty atrocious code flow... would it at all be possible to write it like: SYM_FUNC_START(...) .if \host 1: seamcall cmovc %spare, %rax 2: .else tdcall .endif ..... RET 3: mov $TDX_SW_ERROR, %r12 orq %r12, %rax jmp 2b _ASM_EXTABLE_FAULT(1b, 3b) SYM_FUNC_END() That is, having all that inline in the hotpath is quite horrific.