Received: by 2002:a05:6a10:a841:0:0:0:0 with SMTP id d1csp1464878pxy; Fri, 23 Apr 2021 08:39:01 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwJnE9qCPWciPywqDpjfebTnT7d/V+1yOjbSEA6Qb76hVKE7hMEbVmiyvC3m8KMhbj0D3PI X-Received: by 2002:aa7:83d0:0:b029:241:8fa3:3c6f with SMTP id j16-20020aa783d00000b02902418fa33c6fmr4440605pfn.73.1619192341511; Fri, 23 Apr 2021 08:39:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1619192341; cv=none; d=google.com; s=arc-20160816; b=sD68t9FconzzCjBFnLWtO49qTcP1jBk66ZpbyaJnOsOTNaZHLZfPMu+tGasrZgJjwX TZKqJEc4BQ2lbW3NrPB8oCGawK72TxfJAbicKB6puWbNrgo0l8EonpPf69JGaJl7A97E ZxwLvG8W7X6UHgCr+373iggcA8jsbUtwLTfuWF4SDUR1Guw6bXiogoj9FW3GoHNBkkFF AjrtTdDsl0+TF3v2adeoZtY0XYthIq02fHS9p5uMEkPMFEA7nS2e0BjpynmmIFmlV106 Qxy3j1CbsfwNrG8DLb3vM+K0u7hPS3NyIa/TggDnUMMGT/DxSwYRG2F4fkRtIViwpPCZ h8yQ== 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:ironport-sdr :ironport-sdr; bh=lVwj4rq7k/cTngFcbozUQVLBygqIgCYlK5+09jxpXms=; b=v0w33iqIcjDoJKcv/bP/6sXiSeWRPiL3CijNk1aeB09jbNtEtyEd02fy3ylfoCMswG XqO0XMLzO/edj2rAT3VUCuLKHcq0+0KkSXi0dTUMgKBrlZATXD26g43wfznYUfjzFKnY rm1b6i2Swupj8oJg+6+1pwrjgbSIHhVMfj3UhzsJ69RT+8aj+QWfgQpMUPB7t8wb3zhp X0tEWsmZy0ayIlkhzDbIxrL7Dj9v2XJV+YCoSvAK5WN6vgIHDvnKsitXK38bSS5pQXll js1D52w7mmipHxSElmrpOStc36KHzdN5U7r2huE7ytti+ZCUHcgJLXQ8seUr27hbOcuH GlyA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id x12si6746866pgj.61.2021.04.23.08.38.49; Fri, 23 Apr 2021 08:39:01 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242623AbhDWPix (ORCPT + 99 others); Fri, 23 Apr 2021 11:38:53 -0400 Received: from mga04.intel.com ([192.55.52.120]:46575 "EHLO mga04.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231437AbhDWPiu (ORCPT ); Fri, 23 Apr 2021 11:38:50 -0400 IronPort-SDR: BCIuvbWxEFgUV4bjIFDiFbc5bHvPct+aCkPeWNOu96+wf4z/dUB6GErT3Qp6aa2te2GEoC/sUq 8JrLIVT9pQYg== X-IronPort-AV: E=McAfee;i="6200,9189,9963"; a="193970046" X-IronPort-AV: E=Sophos;i="5.82,246,1613462400"; d="scan'208";a="193970046" Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Apr 2021 08:38:12 -0700 IronPort-SDR: aH4akTIP2teA/UjFL9N/7tOnMKBK0JgtC5Q2nwl/rVNAiWUaBIfBqeSRdp58Gu6Es0yMZhrrhD ASnKQuOVr3kQ== X-IronPort-AV: E=Sophos;i="5.82,246,1613462400"; d="scan'208";a="385123549" Received: from tassilo.jf.intel.com ([10.54.74.11]) by orsmga003-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Apr 2021 08:38:12 -0700 Date: Fri, 23 Apr 2021 08:38:10 -0700 From: Andi Kleen To: Dan Williams Cc: Sean Christopherson , Dave Hansen , "Kuppuswamy, Sathyanarayanan" , Peter Zijlstra , Andy Lutomirski , Kirill Shutemov , Kuppuswamy Sathyanarayanan , Raj Ashok , Linux Kernel Mailing List Subject: Re: [PATCH v2 1/1] x86/tdx: Add __tdcall() and __tdvmcall() helper functions Message-ID: <20210423153810.GL1401198@tassilo.jf.intel.com> References: <77a13ae9-0220-030e-7ae4-fd26edd7b110@intel.com> <2a3f6b3d-cd80-0734-ce83-c067666c8326@linux.intel.com> <14332abf-c78c-3bc2-9a7c-ceacfa7a0661@intel.com> <596175e3-9d1e-6c9c-fadb-ad02c396e3ad@linux.intel.com> <9161efc0-fd25-d239-32b7-5d2c726579b0@linux.intel.com> <4ac4ed35-212b-f7ad-55f4-937946ffec1a@intel.com> <20210423013546.GK1401198@tassilo.jf.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Apr 23, 2021 at 08:28:45AM -0700, Dan Williams wrote: > On Fri, Apr 23, 2021 at 8:15 AM Sean Christopherson wrote: > > > > On Thu, Apr 22, 2021, Andi Kleen wrote: > > > On Thu, Apr 22, 2021 at 06:21:07PM -0700, Dave Hansen wrote: > > > > On 4/22/21 6:09 PM, Kuppuswamy, Sathyanarayanan wrote: > > > > > But let me try to explain it here. What I meant by complication is, > > > > > for in/out instruction, we use alternative_io() to substitute in/out > > > > > instructions with tdg_in()/tdg_out() assembly calls. So we have to ensure > > > > > that we don't corrupt registers or stack from the substituted instructions > > > > > > > > > > If you check the implementation of tdg_in()/tdg_out(), you will notice > > > > > that we have added code to preserve the caller registers. So, if we use > > > > > C wrapper for this use case, there is a chance that it might mess > > > > > the caller registers or stack. > > > > > > > > > > alternative_io("in" #bwl " %w2, %" #bw "0", \ > > > > > "call tdg_in" #bwl, X86_FEATURE_TDX_GUEST, \ > > > > Has Intel "officially" switched to "tdg" as the acronym for TDX guest? As much > > as I dislike having to juggle "TDX host" vs "TDX guest" concepts, tdx_ vs tdg_ > > isn't any better IMO. The latter looks an awful lot like a typo, grepping for > > "tdx" to find relevant code will get fail (sometimes), and confusion seems > > inevitable as keeping "TDX" out of guest code/comments/documentation will be > > nigh impossible. > > > > If we do decide to go with "tdg" for the guest stuff, then _all_ of the guest > > stuff, file names included, should use tdg. Maybe X86_FEATURE_TDX_GUEST could > > be left as a breadcrumb for translating TDX->TDG. > > > > > > > "=a"(value), "d"(port)) > > > > > > > > Are you saying that calling C functions from inline assembly might > > > > corrupt the stack or registers? Are you suggesting that you simply > > > > > > It's possible, but you would need to mark a lot more registers clobbered > > > (the x86-64 ABI allows to clobber many registers) > > > > > > I don't think the stack would be messed up, but there might be problems > > > with writing the correct unwind information (which tends to be tricky) > > > > > > Usually it's better to avoid it. > > > > For me, the more important justification is that, if calling from alternative_io, > > the input parameters will be in the wrong registers. The OUT wrapper would be > > especially gross as RAX (the value to write) isn't an input param, i.e. shifting > > via "ignored" params wouldn't work. > > > > But to Dave's point, that justfication needs to be in the changelog. > > It's not clear to me that in()/out() need to be inline asm with an > alternative vs out-of-line function calls with a static branch? I doubt it matters at all on a modern machine (the cost of a IO port access is many orders of magnitudes greater than a call), but it might have mattered on really old systems, like 486 class. Maybe if someone is still running those moving it out of line could be a problem. But likely it's fine. I think actually for the main kernel we could just rely on #VE here and drop it all. Doing it without #VE only really matters for the old boot code, where performance doesn't really matter. -Andi