Received: by 2002:a05:7412:3290:b0:fa:6e18:a558 with SMTP id ev16csp412240rdb; Thu, 25 Jan 2024 21:59:47 -0800 (PST) X-Google-Smtp-Source: AGHT+IHlNAdggy1dmkAcwqRg3i4JnxZNbREMUy1/WddxlZP++KVCKsljpB5i1uzhYOaYiuhKlb2Z X-Received: by 2002:a17:90a:7344:b0:28f:fa54:eb30 with SMTP id j4-20020a17090a734400b0028ffa54eb30mr466619pjs.37.1706248787181; Thu, 25 Jan 2024 21:59:47 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706248787; cv=pass; d=google.com; s=arc-20160816; b=Gh+HeJhR4ZVl2ZtQStAey3Z4fBC0pOT1TsyXoUt4QFBzfJc9QPUJNtaKM41njywtnD e4ybf/2sVPZI2s1LkdflrFA4zvo9ufyJWQUqYtc4hGvACrR4aX/eQTrhielgefo/n3xG OSWGjPZeFgBZhxxKfoLWePqOGY4Tld4915Q+UYnAVPrfKoZM38/GjeUqeYinvHmNv9zi 1XqCVGPGRtXLIO8WBumDUO8kCQwVwgTQqD15vy7HXU502gQxNn9G2nPKcG+NC/au8Yao 797k/eN+C1i7ndJMp2SJX/mIjsEuS8SBGnN9dt6OoZv5S1wl5a6F84F9CqJIx3GFbWLT dIEg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:autocrypt:from:references:cc :to:content-language:subject:user-agent:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:date:message-id :dkim-signature; bh=nBYHdpy2T+P9z5bpa228oc6wr1+9JH26Mg1COdKLLrI=; fh=u5cn5dhfJDb4CYIjVKzlZSN6XRVQAoEIfyjV0JmUfxY=; b=it5YvExv6MnaWrQHnY4bXfkR/kvqQcjBt6b10sqsMMI/So+nas2x/RRZ9o83AQb7po GimTJJb7yULqNpSycJ1/qKBaz3CCoiTePBYi4U13BGA6XMf7mAykVPXDYc17/bVgAfiv YkF2ptFX68bt2eSTbOpid/xVU6Q9T7es2xERQK0EQTFV8+8zdggRaaVqWl3vcWLHiYCp /6Zhx4LCM/iT/unyMrLw6OQm3k6MyRCizwrMMvsgmbylLIM8mNAmcxM0QLHhOCC1DDB4 K2VsB2j+XeMB1VFUnjqNpiVOcoeRFyQgX1osEENTtqL1sDCJJ1e/Bki5P6VXXf0YhNo9 /MSA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@broadcom.com header.s=google header.b=cXlvFKYY; arc=pass (i=1 dkim=pass dkdomain=broadcom.com dmarc=pass fromdomain=broadcom.com); spf=pass (google.com: domain of linux-kernel+bounces-39476-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-39476-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=broadcom.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id q4-20020a170902c9c400b001d72d1e205bsi546646pld.414.2024.01.25.21.59.46 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Jan 2024 21:59:47 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-39476-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@broadcom.com header.s=google header.b=cXlvFKYY; arc=pass (i=1 dkim=pass dkdomain=broadcom.com dmarc=pass fromdomain=broadcom.com); spf=pass (google.com: domain of linux-kernel+bounces-39476-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-39476-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=broadcom.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id A77C1B230E3 for ; Fri, 26 Jan 2024 00:55:29 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7714267C66; Fri, 26 Jan 2024 00:55:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=broadcom.com header.i=@broadcom.com header.b="cXlvFKYY" Received: from mail-oa1-f52.google.com (mail-oa1-f52.google.com [209.85.160.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 16884399 for ; Fri, 26 Jan 2024 00:55:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.52 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706230512; cv=none; b=Ang1jN/T/6jh4K3KRuv7RkZt7RF0tk+go6KFZgoBYdhM5Ca+2L9PPca+HalAMj06H1eCiR7A5E+hCftM1e8nrpBcTWwoRK1fp5mZB08tpiffJS+c3pVtJtPxOzJM5cFV6DGKIiyRA2NT74vszWe9LvaCKx49niDekD/O598Rxlo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706230512; c=relaxed/simple; bh=woblf5qNFHrtXcpv2ZP53wuaAZhx3ECN/TDEQZ6mz3o=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=EQuAsHtJKBs1dN0ZEBlX4eLRQpBoZVWn64abmkbU7aTziVVKRTF+do3WDEaiiPR2ODZmI59iz1MnV6f9LSxkaP0B/fx/6rfi1/m6T+DIGT1vVt8+UXCW4KSQElmDAjbClp7Gjm8mCJzqwVePNzVx7hT2vcULmx63rIIMq6H0qGI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=broadcom.com; spf=fail smtp.mailfrom=broadcom.com; dkim=pass (1024-bit key) header.d=broadcom.com header.i=@broadcom.com header.b=cXlvFKYY; arc=none smtp.client-ip=209.85.160.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=broadcom.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=broadcom.com Received: by mail-oa1-f52.google.com with SMTP id 586e51a60fabf-214cd4bce34so838370fac.1 for ; Thu, 25 Jan 2024 16:55:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; t=1706230509; x=1706835309; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:autocrypt:from:references:cc :to:content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=nBYHdpy2T+P9z5bpa228oc6wr1+9JH26Mg1COdKLLrI=; b=cXlvFKYYNYfFXDH07WZqAl091+w+1N93HPVe43n0bXHTxvpmeE2wrWueS0dPKknPpM c8L8pOalNHvL7hqr4mVPEBWqWNrobL2iTMsjDGnKgX8YQ4tKesXZdDkxNXz6EMwHDlVK QTYDcTbpsLg2FMm/e90lhmwdA9vdnxO6DjD0I= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706230509; x=1706835309; h=content-transfer-encoding:in-reply-to:autocrypt:from:references:cc :to:content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=nBYHdpy2T+P9z5bpa228oc6wr1+9JH26Mg1COdKLLrI=; b=lYTiPgQrTNpGB1sAIP0XnoQSQOpgsl2uk98gArKo/3V+Sj70zJcp2sS+t478BMF1U8 bUMyvJW0jtEPplULglhPiTTTmHYZuhP8QMGAXjNCEFD2ud8Gfz6VPRLJJjuldqbd53kU QD4b6k0a65fU2goXuHxUb+CBlesSTpMZ254KiVKUHz/xF8l0/L0jn8h7oaJdiedAS34D llt4bF2CwCVsTD8YqBpF3ljkCoZSUXGfryq3Bd9cN6RlXpKE86RzpAj+WIawE5NNNnFo bdfhJotEt0oIjWQq2lDnOS+mOzZaLelLPoDBsUXNB1iPlJ07QcIk049weC1akPQFLOkL +V0g== X-Gm-Message-State: AOJu0YzTKaK2MZC15C5cYGMytuxMkx8q6cbSuFrOwLgLEhYC5zv9ztmf 51QRtwTMjPRk1GPnOXZCX+NQnB1BQCyK8OFx0bglmK0LQZC1PgE+Tr+bU98beA== X-Received: by 2002:a05:6871:7a2:b0:214:cf50:83a8 with SMTP id o34-20020a05687107a200b00214cf5083a8mr549113oap.31.1706230509086; Thu, 25 Jan 2024 16:55:09 -0800 (PST) Received: from [192.168.0.212] ([50.47.85.47]) by smtp.gmail.com with ESMTPSA id l17-20020a635b51000000b005cd64ff9a42sm117219pgm.64.2024.01.25.16.55.06 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 25 Jan 2024 16:55:08 -0800 (PST) Message-ID: Date: Thu, 25 Jan 2024 16:55:05 -0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v6 7/7] x86/vmware: Add TDX hypercall support Content-Language: en-US To: "H. Peter Anvin" , Dave Hansen , linux-kernel@vger.kernel.org, virtualization@lists.linux.dev, bp@alien8.de, dave.hansen@linux.intel.com, mingo@redhat.com, tglx@linutronix.de Cc: x86@kernel.org, netdev@vger.kernel.org, richardcochran@gmail.com, linux-input@vger.kernel.org, dmitry.torokhov@gmail.com, zackr@vmware.com, linux-graphics-maintainer@vmware.com, pv-drivers@vmware.com, namit@vmware.com, timothym@vmware.com, akaher@vmware.com, jsipek@vmware.com, dri-devel@lists.freedesktop.org, daniel@ffwll.ch, airlied@gmail.com, tzimmermann@suse.de, mripard@kernel.org, maarten.lankhorst@linux.intel.com, horms@kernel.org, kirill.shutemov@linux.intel.com References: <20240109084052.58661-1-amakhalov@vmware.com> <20240109084052.58661-8-amakhalov@vmware.com> <4CF87BC4-E8C8-4584-A275-5A985D5A18A1@zytor.com> <351B1153-9CBE-4774-9FAF-770F9F36856E@zytor.com> From: Alexey Makhalov Autocrypt: addr=alexey.makhalov@broadcom.com; keydata= xsFNBGVo9lkBEACeouRIm6Q3QTvjcnPczfBqgLffURstVJz5nqjnrNR4T+8dwNrZB8PTgOWA QdGV4bIyqtNG7UHQuZ7sVKr2tx0gYJyQ5uZgncEHB5YIuhQ/CyAHrVmO+5/0/xWCLI0g44rF ZJqsYw2JQ2+vayTWbR65rkOiKL8GOVFNZanDg80BRh6qCmCEMXd/tymxvgnvWpHtxMgukexk 4vV9nV4XhxRVYdpLk8mBxsh+AEbHE+nbWgIuJDrmrZDGI2Dha7JFoB0Mi6hbbYd9BdkcHKQ7 6c+S1xOrZL3jX7OIFhb4NNnEOhh8/+BDlyby478p6YsimNa7TgAUbrygGyfVG8usrZy8SvO+ vUbVQwqjcJaCK1xazK12dfuZm2kSMJUrJqa9ng6OMjkE2/WrtnK8ruFNSCdytzbuheT0nYUJ Uwy84cU4p2K/N2C4vYjcn+IT+l1BFr5FViKYruoRLVH6zK/WOoZjA+Fc6tdM5nC1pgSB9c7h XLQqDSzYPzk3nqeHWG1qJ0Hu7pscIrjxyNTIZ5le0TlpblJdoRcL5maDNw22yle8m4D18ERF VrqNoqwW8fObMCHbd6C3m75lzerq1HhrSvLyU4UfprEyAcjOI1C0319SXfYlXDjKXRQyaDZP wxln8uShSitSSnx0AsSAjcUa8Cc7km81+G2WSK3S2wVIAN11awARAQABzS5BbGV4ZXkgTWFr aGFsb3YgPGFsZXhleS5tYWtoYWxvdkBicm9hZGNvbS5jb20+wsGNBBMBCAA3FiEEjLzRtST/ a5u42vOKbM7yHr5SJ3cFAmVo9lwFCQ0oaIACGwMECwkIBwUVCAkKCwUWAgMBAAAK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Tczdo9PnkmRyZcAa6AndbjmQDznwxvTZu2LjMPC EuY0 In-Reply-To: <351B1153-9CBE-4774-9FAF-770F9F36856E@zytor.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 1/22/24 4:17 PM, H. Peter Anvin wrote: > On January 22, 2024 4:04:33 PM PST, Alexey Makhalov wrote: >> >> >> On 1/22/24 10:28 AM, H. Peter Anvin wrote: >>> On January 22, 2024 8:32:22 AM PST, Dave Hansen wrote: >>>> On 1/9/24 00:40, Alexey Makhalov wrote: >>>>> +#ifdef CONFIG_INTEL_TDX_GUEST >>>>> +unsigned long vmware_tdx_hypercall(unsigned long cmd, >>>>> + struct tdx_module_args *args) >>>>> +{ >>>>> + if (!hypervisor_is_type(X86_HYPER_VMWARE)) >>>>> + return ULONG_MAX; >>>>> + >>>>> + if (cmd & ~VMWARE_CMD_MASK) { >>>>> + pr_warn_once("Out of range command %lx\n", cmd); >>>>> + return ULONG_MAX; >>>>> + } >>>>> + >>>>> + args->r10 = VMWARE_TDX_VENDOR_LEAF; >>>>> + args->r11 = VMWARE_TDX_HCALL_FUNC; >>>>> + args->r12 = VMWARE_HYPERVISOR_MAGIC; >>>>> + args->r13 = cmd; >>>>> + args->r15 = 0; /* CPL */ >>>>> + >>>>> + __tdx_hypercall(args); >>>>> + >>>>> + return args->r12; >>>>> +} >>>>> +EXPORT_SYMBOL_GPL(vmware_tdx_hypercall); >>>>> +#endif >>>> >>>> This is the kind of wrapper that I was hoping for. Thanks. >>>> >>>> Acked-by: Dave Hansen >>>> >>> >>> I'm slightly confused by this TBH. >>> >>> Why are the arguments passed in as a structure, which is modified by the wrapper to boot? This is analogous to a system call interface. >>> >>> Furthermore, this is an out-of-line function; it should never be called with !X86_HYPER_VMWARE or you are introducing overhead for other hypervisors; I believe a pr_warn_once() is in order at least, just as you have for the out-of-range test. >>> >> >> This patch series introduces vmware_hypercall family of functions similar to kvm_hypercall. Similarity: both vmware and kvm implementations are static inline functions and both of them use __tdx_hypercall (global not exported symbol). Difference: kvm_hypercall functions are used _only_ within the kernel, but vmware_hypercall are also used by modules. >> Exporting __tdx_hypercall function is an original Dave's concern. >> So we ended up with exporting wrapper, not generic, but VMware specific with added checks against arbitrary use. >> vmware_tdx_hypercall is not designed for !X86_HYPER_VMWARE callers. But such a calls are not forbidden. >> Arguments in a structure is an API for __tdx_hypercall(). Input and output argument handling are done by vmware_hypercall callers, while VMware specific dress up is inside the wrapper. >> >> Peter, do you think code comments are required to make it clear for the reader? >> >> > > TBH that explanation didn't make much sense to me... Peter, I would like to understand your concerns. 1. Are you suggesting to move structure (tdx parameters) initialization in one please, instead of one part there another part here? Do you prefer to pass all arguments as is to vmware_tdx_hypercall() and only define tdx_module_args there? 2. And second suggestion is to add pr_warn_once under "if (!hypervisor_is_type(X86_HYPER_VMWARE))" ? --Alexey