Received: by 2002:a05:6358:7058:b0:131:369:b2a3 with SMTP id 24csp1510890rwp; Thu, 13 Jul 2023 12:00:01 -0700 (PDT) X-Google-Smtp-Source: APBJJlEyHxh7oKYTmOIITYaFEGP4XNFMPrXQpuGuIl8GYk3aompQDmm2d8dYuh1VUyIl7F9vnuAZ X-Received: by 2002:a17:902:f54a:b0:1b8:b382:f6c3 with SMTP id h10-20020a170902f54a00b001b8b382f6c3mr1826411plf.13.1689274801422; Thu, 13 Jul 2023 12:00:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689274801; cv=none; d=google.com; s=arc-20160816; b=g1CP+G/IVRMp8DqsVdNjZI+oEOzAyW2djgyoUPJsl3rBBDdOF8uZcFQud0QyYZ7a9b 7Wpz7jHBmJ0BSI74hAyVUhUStQPa/f4Me1Z74oTxL9L+zHxqlgzBc8zBNIbYe1D5T/hx VIVrOaa9fzPG5dPZ7d24yLI2KV896ycM760v0KADEqCNjlB29s2e6CXr8CYMBvdHHrRb nEjXRShwCNMuVS39x7vMRKoZredsXct/ksXJCLOM6Uj3sfNvxR+vhr9p3wqM8HY9ClhV ktso5kIa8l1DWQhTMFNqRBp8s79TvR7CIuu2PLeAQCxKMfXbSwM+CsKf/p+rBUf6TDTU Hn5A== 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-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=FlzbEka2wU8r+IIPq0C/1MLd6rbjhZvGX4VmkZaz3Po=; fh=MG+ncPVfyvb80UtlIOSIRwWaKnsV/85uVXeN4CCqt9A=; b=OLJ+s30mVuJGVdzBApCufMbdfXwq8uKJBEGw1qkPw5Jo3tAA2skStkddEzAxi1y/Wz nOMeAL/yTm7Ffo6GkBptvGbgIRlcCYZZ5T5XbcMi+dnD5yB7dqLo4oh1JLAtGOU8ErQS VQW6FWsllOdrB9if50v2DFWPIeSrEXEV0CjEXHRSISFyLBmacp7STq0GKOdRfHv/5vUr 7+dDansDCpkC/rbJ50sND63D9b/EzPeb9tHYEG9hN5wxCXqMxDrcexhR1SbS1R6rCI6g 6m0y8xnpfQH3tzDsIK9DUWzFUS/4C9+t8weu5MLieXHS8nMBwZ6N6EhxmeXcZFik4phw EYbg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=c3IWrdCE; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z14-20020a170903018e00b001b8a88cba84si5855496plg.129.2023.07.13.11.59.49; Thu, 13 Jul 2023 12:00:01 -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=@gmail.com header.s=20221208 header.b=c3IWrdCE; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231925AbjGMSol (ORCPT + 99 others); Thu, 13 Jul 2023 14:44:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43214 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231626AbjGMSoj (ORCPT ); Thu, 13 Jul 2023 14:44:39 -0400 Received: from mail-pg1-x52a.google.com (mail-pg1-x52a.google.com [IPv6:2607:f8b0:4864:20::52a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 976DB2D46; Thu, 13 Jul 2023 11:44:36 -0700 (PDT) Received: by mail-pg1-x52a.google.com with SMTP id 41be03b00d2f7-53482b44007so709266a12.2; Thu, 13 Jul 2023 11:44:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1689273876; x=1691865876; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:from:to :cc:subject:date:message-id:reply-to; bh=FlzbEka2wU8r+IIPq0C/1MLd6rbjhZvGX4VmkZaz3Po=; b=c3IWrdCES97dEa1eiXbLQkdl4KiPjQ8/X5E/eiHyJ7rKeztC/1jAAl9yjpO+HT4AAt hGjiI9VLabS5+n5zFkUM4sX7wFkFdPCLHC8SgeEw9Ktm9b/ELip1ncIGDX9aakgX3XQf rl6eVLJDhSh74H7N/07Mc3luxHZNmym3TzOEM1vX1dGPw/IqY3zCaykr1r8OYkC7M2bC zNaBW1O2w9ZKHT5nWGXHZM66lHJFbSGzsCb9vqcy9smQ34GYPvcmW1VA/Ek93d0NNOyZ xmpacVqUtfc+MXelITIjQZ+mNmEtGMpzfSZmyYPXAcIOCB/Uezz+shrEydainEmnOglR k/xg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689273876; x=1691865876; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=FlzbEka2wU8r+IIPq0C/1MLd6rbjhZvGX4VmkZaz3Po=; b=Z834/u8WZlWAb7RZxe1fqmkxQFQvpW8HKSdGCHyh718vmlKksiHh2/Alg5DwDgm7i2 DixhYog7I7IJf4O5ZYTyZ9svOeD4mMGkH1pbpG9KeggFQoAzOGlrBYu6zA8QlB9mIyxB GkkVqqIAOKI1D/wphMalMV/1/Ch5jc8shJQyo8C5oJq0RsqRZf6n4wjOxKpxA9XsK1mo tGR4OVOXhrrkvEEldAMi5F5jq0XmXU6T+KrhkNwZKn5iofTAOjV/yuvr/rlk1zK4ZWrH RX+n2CC6yx/35BJTcSX4ZRAXXy7M5k17mvTo4mYEAen5/9VV4QX28PdsUJ7J6SzeX6aW sOfg== X-Gm-Message-State: ABy/qLbHIByuHQAWD1SQEv3GR9A+3FWgve11QaA/CK+9rqPdQ/ykBG4H I9J0itwBECpoHjS3tYzUxtVgTK1qIrA= X-Received: by 2002:a05:6a20:6a0c:b0:126:a80d:4936 with SMTP id p12-20020a056a206a0c00b00126a80d4936mr2038014pzk.27.1689273875910; Thu, 13 Jul 2023 11:44:35 -0700 (PDT) Received: from localhost ([192.55.54.50]) by smtp.gmail.com with ESMTPSA id u1-20020aa78381000000b0065434edd521sm5682072pfm.196.2023.07.13.11.44.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Jul 2023 11:44:35 -0700 (PDT) Date: Thu, 13 Jul 2023 11:44:34 -0700 From: Isaku Yamahata To: "Huang, Kai" Cc: "isaku.yamahata@gmail.com" , "Hansen, Dave" , "Christopherson,, Sean" , "bp@alien8.de" , "x86@kernel.org" , "peterz@infradead.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 09/10] x86/virt/tdx: Wire up basic SEAMCALL functions Message-ID: <20230713184434.GH3894444@ls.amr.corp.intel.com> References: <41b7e5503a3e6057dc168b3c5a9693651c501d22.1689151537.git.kai.huang@intel.com> <20230712221510.GG3894444@ls.amr.corp.intel.com> <4202b26acdb3fe926dd1a9a46c2c7c35a5d85529.camel@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <4202b26acdb3fe926dd1a9a46c2c7c35a5d85529.camel@intel.com> X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,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 03:46:52AM +0000, "Huang, Kai" wrote: > On Wed, 2023-07-12 at 15:15 -0700, Isaku Yamahata wrote: > > > The SEAMCALL ABI is very similar to the TDCALL ABI and leverages much > > > TDCALL infrastructure.  Wire up basic functions to make SEAMCALLs for > > > the basic TDX support: __seamcall(), __seamcall_ret() and > > > __seamcall_saved_ret() which is for TDH.VP.ENTER leaf function. > > > > Hi.  __seamcall_saved_ret() uses struct tdx_module_arg as input and output.  For > > KVM TDH.VP.ENTER case, those arguments are already in unsigned long > > kvm_vcpu_arch::regs[].  It's silly to move those values twice.  From > > kvm_vcpu_arch::regs to tdx_module_args.  From tdx_module_args to real registers. > > > > If TDH.VP.ENTER is the only user of __seamcall_saved_ret(), can we make it to > > take unsigned long kvm_vcpu_argh::regs[NR_VCPU_REGS]?  Maybe I can make the > > change with TDX KVM patch series. > > The assembly code assumes the second argument is a pointer to 'struct > tdx_module_args'. I don't know how can we change __seamcall_saved_ret() to > achieve what you said. We might change the kvm_vcpu_argh::regs[NR_VCPU_REGS] to > match 'struct tdx_module_args''s layout and manually convert part of "regs" to > the structure and pass to __seamcall_saved_ret(), but it's too hacky I suppose. > > This was one concern that I mentioned VP.ENTER can be implemented by KVM in its > own assembly in the TDX host v12 discussion. I kinda agree we should leverage > KVM's existing kvm_vcpu_arch::regs[NR_CPU_REGS] infrastructure to minimize the > code change to the KVM's common infrastructure. If so, I guess we have to carry > this memory copy burden between two structures. > > Btw, I do find KVM's VP.ENTER code is a little bit redundant to the common > SEAMCALL assembly, which is a good reason for KVM to use __seamcall() variants > for TDH.VP.ENTER. > > So it's a tradeoff I think. > > On the other hand, given CoCo VMs normally don't expose all GPRs to VMM, it's > also debatable whether we should invent another infrastructure to the KVM code > to handle register access of CoCo VMs too, e.g., we can catch bugs easily when > KVM tries to access the registers that it shouldn't access. Yes, we'd like to save/restore GPRs only for TDVMCALL. Otherwise skip save/restore. -- Isaku Yamahata