Received: by 2002:a05:7412:5112:b0:fa:6e18:a558 with SMTP id fm18csp187338rdb; Mon, 22 Jan 2024 16:59:59 -0800 (PST) X-Google-Smtp-Source: AGHT+IFixnQ3rJPirwXnLknoiieg5rw9p+tnM9reD8fU2vLY2nTjuNaPGUa8BoiWHUoUhu3+NKgL X-Received: by 2002:ac2:5548:0:b0:50e:278f:6dfc with SMTP id l8-20020ac25548000000b0050e278f6dfcmr1912908lfk.125.1705971599137; Mon, 22 Jan 2024 16:59:59 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705971599; cv=pass; d=google.com; s=arc-20160816; b=dVhc3253W2Voh5qZLaqZ3E4zR00Yd1UPnJKfcfGDFerZC2NamFzuUCyDyuqxj3jk5s IVxmWUxDfY5rpv6IRYsLs7EXuZtVhotZ4aGjf3rw27Fta3EOxXqoVZH9JpvzYlOF3//v HgHQPg1eifcER/zYLi6rCFzPUGZvVtnTtPyqKTBlVirw7lU3CeKBNo56DwKTtdcAfII4 PqWuNPUZxleKMDvbCCC/lSsrxlQWOdVfQEryq0/q24gZu7weMTB45HGnIgwoosU9RfUU WRwvEJ1eqG3d+RxefXOtucEc/q9GjJgdXM6EOCHeTSLDHWNLDA7+4HOBz+8e3OacVGKK QU4w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:references:in-reply-to :user-agent:subject:cc:to:from:date:dkim-signature:dkim-filter; bh=naevb4PslKTi+uWE0rIwkjLfQkOH3+GqKQddGwCKH50=; fh=+GDpGPweUWEhu5Po3HVNh0QroCq1KGz2KTkhK7WxOWM=; b=sowjQO2kJEDR+KL9gK/Zo0Gwp4JIVKRY3UKBbfxqezYOKNv4ltRXeMkjOJY72Cioh+ aW89SJ8F54QtHTNLgQrav8lGOgng2pvQ9SlGjbssXQC6vcq15bDd9mBeN5C2u5L+PEzB hbPi9Q+HPRBHP+ASUbUstddCo5EKI5HXzDyiT5PWbLLVN9tPYB4hv2ee0XRBZ/zWeFzS Kn98wHO+NlgHgw2SnDbCtx3KYK6e0QgVzo/+51E9pdIV1xPMc41y3cKuvkCV1QB3nS+I ZVzDcAnM7f/mbqhs2e0CplpbcdFt7fq8QF5ocWFygjJwGgC1k+ICvVtNSPV3HojHYGfP xCJA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@zytor.com header.s=2024011201 header.b="NR/AlsA7"; arc=pass (i=1 spf=pass spfdomain=zytor.com dkim=pass dkdomain=zytor.com dmarc=pass fromdomain=zytor.com); spf=pass (google.com: domain of linux-kernel+bounces-34447-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-34447-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=zytor.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id bj24-20020a170906b05800b00a2c2b089242si11328635ejb.433.2024.01.22.16.59.59 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Jan 2024 16:59:59 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-34447-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@zytor.com header.s=2024011201 header.b="NR/AlsA7"; arc=pass (i=1 spf=pass spfdomain=zytor.com dkim=pass dkdomain=zytor.com dmarc=pass fromdomain=zytor.com); spf=pass (google.com: domain of linux-kernel+bounces-34447-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-34447-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=zytor.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 am.mirrors.kernel.org (Postfix) with ESMTPS id DD9801F28618 for ; Tue, 23 Jan 2024 00:59:58 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 400E414C59E; Tue, 23 Jan 2024 00:21:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=zytor.com header.i=@zytor.com header.b="NR/AlsA7" Received: from mail.zytor.com (terminus.zytor.com [198.137.202.136]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C02B514AD2B; Tue, 23 Jan 2024 00:21:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.137.202.136 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705969269; cv=none; b=IlyxtpcUI2EZS6ivS8enF4XZSvlRjnw0r7ePWsK8Pevm9/3fVMXTRlGk/9QFXZIsLVc5UGv09MEOl//uwV/SELL84YCMxH0ghuPEnytFyR5uIaAM9iWNckYjPuHlzUA5o45fMTv7w43YkX820HD2EgAfKULZFbgDk0paYucWQ/s= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705969269; c=relaxed/simple; bh=m55lPpC+NBSE/XcmCcD0E6mFq9o/I9MNWdauqqDofbk=; h=Date:From:To:CC:Subject:In-Reply-To:References:Message-ID: MIME-Version:Content-Type; b=liJsnAWKL7UqpFgQyy2vA+WRWaS+h2d31h89skP4AMlVG9JMHh5g0df7F8wDKL1pLsPsCCP3ZCCNh96OnqAveMeyMQU2uxhLI6RYLQ/yk8+fqGJc+tic1eW9vy/TwTfQmvVrj2ECIxgixR7apGslRXWsRFobtxD8J7a1cnnJJEY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=zytor.com; spf=pass smtp.mailfrom=zytor.com; dkim=pass (2048-bit key) header.d=zytor.com header.i=@zytor.com header.b=NR/AlsA7; arc=none smtp.client-ip=198.137.202.136 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=zytor.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=zytor.com Received: from [127.0.0.1] ([76.133.66.138]) (authenticated bits=0) by mail.zytor.com (8.17.2/8.17.1) with ESMTPSA id 40N0HoLc2798528 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NO); Mon, 22 Jan 2024 16:17:50 -0800 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.zytor.com 40N0HoLc2798528 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zytor.com; s=2024011201; t=1705969072; bh=naevb4PslKTi+uWE0rIwkjLfQkOH3+GqKQddGwCKH50=; h=Date:From:To:CC:Subject:In-Reply-To:References:From; b=NR/AlsA7je5VAyZlNPTZHvXBBzujylBLOIxmnxF4bzZa+iaBvnN8bscZ+p5JkQaJH ktK2PFVspY/AnvBR1rDjgiy5C0pQbhgGOCSnz2c+7QoE2VKG/r5QNRvd9rUsX6u926 B18RybD5ChPM2oeC+/dkh75st/RyLCw4gBhEDZ/8NXV1GEGVVBn5HwNKITtSiD+b6B RNxHsmhbX42aaKRVUIOUymXOHS/xUCX8Nxf7gg67sU9XnG8TdgCwPUGRJ89WxOxQA0 OHPPuDDGIkVBhGIrtxVa5Ur7uJX/H/QbZqQXpUttoMMbAuhTGzmigvLcbNcDG5iX8f xhMr6LuORnThg== Date: Mon, 22 Jan 2024 16:17:48 -0800 From: "H. Peter Anvin" To: Alexey Makhalov , 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 Subject: Re: [PATCH v6 7/7] x86/vmware: Add TDX hypercall support User-Agent: K-9 Mail for Android In-Reply-To: References: <20240109084052.58661-1-amakhalov@vmware.com> <20240109084052.58661-8-amakhalov@vmware.com> <4CF87BC4-E8C8-4584-A275-5A985D5A18A1@zytor.com> Message-ID: <351B1153-9CBE-4774-9FAF-770F9F36856E@zytor.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On January 22, 2024 4:04:33 PM PST, Alexey Makhalov wrote: > > >On 1/22/24 10:28 AM, H=2E 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 =3D VMWARE_TDX_VENDOR_LEAF; >>>> + args->r11 =3D VMWARE_TDX_HCALL_FUNC; >>>> + args->r12 =3D VMWARE_HYPERVISOR_MAGIC; >>>> + args->r13 =3D cmd; >>>> + args->r15 =3D 0; /* CPL */ >>>> + >>>> + __tdx_hypercall(args); >>>> + >>>> + return args->r12; >>>> +} >>>> +EXPORT_SYMBOL_GPL(vmware_tdx_hypercall); >>>> +#endif >>>=20 >>> This is the kind of wrapper that I was hoping for=2E Thanks=2E >>>=20 >>> Acked-by: Dave Hansen >>>=20 >>=20 >> I'm slightly confused by this TBH=2E >>=20 >> Why are the arguments passed in as a structure, which is modified by th= e wrapper to boot? This is analogous to a system call interface=2E >>=20 >> Furthermore, this is an out-of-line function; it should never be called= with !X86_HYPER_VMWARE or you are introducing overhead for other hyperviso= rs; I believe a pr_warn_once() is in order at least, just as you have for t= he out-of-range test=2E >>=20 > >This patch series introduces vmware_hypercall family of functions similar= to kvm_hypercall=2E Similarity: both vmware and kvm implementations are st= atic inline functions and both of them use __tdx_hypercall (global not expo= rted symbol)=2E Difference: kvm_hypercall functions are used _only_ within = the kernel, but vmware_hypercall are also used by modules=2E >Exporting __tdx_hypercall function is an original Dave's concern=2E >So we ended up with exporting wrapper, not generic, but VMware specific w= ith added checks against arbitrary use=2E >vmware_tdx_hypercall is not designed for !X86_HYPER_VMWARE callers=2E But= such a calls are not forbidden=2E >Arguments in a structure is an API for __tdx_hypercall()=2E Input and out= put argument handling are done by vmware_hypercall callers, while VMware sp= ecific dress up is inside the wrapper=2E > >Peter, do you think code comments are required to make it clear for the r= eader? > > TBH that explanation didn't make much sense to me=2E=2E=2E