Received: by 2002:ab2:6f44:0:b0:1fd:c486:4f03 with SMTP id l4csp51356lqq; Wed, 12 Jun 2024 16:28:04 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVZWDzJTC9aPrH7XV0pebgwSKms3F6YEwQewB1o1uOXWJO2VnQEZQDKCFL1bITZApUyuxoCzNriTCl+I/ZT1xByib3u6ojwzsePIZLktw== X-Google-Smtp-Source: AGHT+IEEhSQgsToBRyrVfi2MAZ6FkPhnKA3a2HMG7NoLl6iHb304AkG89v6zx1ZEtyflqx17D5sl X-Received: by 2002:a17:906:7190:b0:a6f:3996:517c with SMTP id a640c23a62f3a-a6f524147e2mr67111566b.18.1718234884701; Wed, 12 Jun 2024 16:28:04 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1718234884; cv=pass; d=google.com; s=arc-20160816; b=sN838Dk4gI/I8SjZG4qrIcs/oUzDgV+D7qsj/jJX7M/cRA/XmRaU3ZJUTeBwfi44/a rrXKhTtp5qz+XWFsHlm4mE9V0iD4O9ufwUog4Vv0UmSu3sL2mzL3ISC7lUVn6ixfjaIg vEHBQ85u0dLDKKNEMBTWNdfOt5RGg034jewfXLmIypLRoQoSwZA1oSkSjNpBh25B1vdR 4XqZQZRK4NbsmoSQp/Ziqnl0fjLKwAg4UlRjtjb88rWbbmsv3tFVUxEjKHx+0xs5bniv 6FqpITTlmUYY00bQa1hUOTXLbo0kWyuwzQXctYY4/+v2AimO+PWe2gW0yCcDGXTJJzCf aRpg== 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 :content-language:references:cc:to:subject:user-agent:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:date:message-id :dkim-signature; bh=ppMASZ0eIvj/5FKG8wqGN0hZDHJf87zO9TYcK304HR8=; fh=Fp7GGSC/vH7XjVB0rOU5bQ3Cp8XCC6kBd34kNpY+XH8=; b=x4Tn8nUWZmW81rp0Zv5cveumVGYRHhKUw3yqEc1bNklMeyMpU3N51ExkHHKiUosqwW dbd1Xx0CT3Da3QB9vISTEmZu+shW5agwKCKdyoprRdawOcmnL68K4S75I7Wejwzu7AV2 gV6Zfqa6s8cZn4xfm8Esh2hyEpjYu88d7x8+9+icIhBVV26EJtKnzjPM7gVZ2ZM6dPUF BOHbThi4t0Ez+GpyWvY0CYYS0yOlPeXjsM/Pqg7I/WxslzcC6jkvdpQr8kZYJUQH7Efd qJynuocyVp1rz5T6jQa1JaPxVpjhRs/9KHwWXMPAD9n2oAgJf9OGNHDaDzmf/9xo21CS UEnQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@broadcom.com header.s=google header.b=YWctxtXy; arc=pass (i=1 dkim=pass dkdomain=broadcom.com dmarc=pass fromdomain=broadcom.com); spf=pass (google.com: domain of linux-kernel+bounces-212307-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-212307-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=broadcom.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id a640c23a62f3a-a6f56d21ad3si5971966b.130.2024.06.12.16.28.04 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Jun 2024 16:28:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-212307-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@broadcom.com header.s=google header.b=YWctxtXy; arc=pass (i=1 dkim=pass dkdomain=broadcom.com dmarc=pass fromdomain=broadcom.com); spf=pass (google.com: domain of linux-kernel+bounces-212307-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-212307-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 am.mirrors.kernel.org (Postfix) with ESMTPS id 9AA1F1F23CF0 for ; Wed, 12 Jun 2024 22:12:20 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 03812391; Wed, 12 Jun 2024 22:12:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=broadcom.com header.i=@broadcom.com header.b="YWctxtXy" Received: from mail-yw1-f179.google.com (mail-yw1-f179.google.com [209.85.128.179]) (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 995B3127E3A for ; Wed, 12 Jun 2024 22:12:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.179 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718230323; cv=none; b=L5iMD6ZimFJmrqTckQs3dMaICb6z+We733tTeCrZ1VFZPCXA/Ch3hRaeeqR3SWQVrU31I0mjwAhqzwdS3ldIZkndCXfIiu8MqUwkRtHQwesT5glTNNlp+B6VtGP+D1sYH3KAbv7flSbI0ytPJqeCOoAQzWkKXl6zl9v0zWsDO4Y= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718230323; c=relaxed/simple; bh=TiHhlZo7HZR1yfnnJSa1w/GEHdI4xtxB224R88h4Vnk=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=pJXsDCbJZaOuWxWCHZKX7MCcbcI6mZ9IwyMAcKxEj4rLRhS9lG64l/pYwnF0lbsQsHj2HG+OweHLUJf2YytCTPfOJNexFGcuJv21soLt5Z3q010NUl88dU+EcSWXO19ZA8dXb7xKGcAQdDyFu5qZb7FJyFeZScv8Rt0xgXSbfxA= 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=YWctxtXy; arc=none smtp.client-ip=209.85.128.179 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-yw1-f179.google.com with SMTP id 00721157ae682-62f8dcbd4b5so4595947b3.0 for ; Wed, 12 Jun 2024 15:12:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; t=1718230320; x=1718835120; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:autocrypt:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:from:to:cc:subject:date:message-id:reply-to; bh=ppMASZ0eIvj/5FKG8wqGN0hZDHJf87zO9TYcK304HR8=; b=YWctxtXy/hP6KtX0NkoDimSBPyoGypgZxFYLuv9hZhJkZ1NUqe+XoRQXANgpzhd0nP V+zYY5Oa6R7uLD3Y7UFRoTKdRlHoyoZY8qZo2B1F69NQBgRKK/pPf93DltBbamDmy/Jt jG9EG8uKS7IRHezQXxLEvDE+UwFqjTphC7Ez8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718230320; x=1718835120; h=content-transfer-encoding:in-reply-to:autocrypt:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=ppMASZ0eIvj/5FKG8wqGN0hZDHJf87zO9TYcK304HR8=; b=EEWkIXKkJvrc2fUaSfkXaxY6ChLbzzgPYLMkBQvhoeL/0Uww3InbHBMV8O1hoeHZVA YueiWNef3WCLudl1c6KhKmy84TNb+xc0P1XagS1y3OJVfyWnIc/EA+vwo2nNXI8y58Qv hd96/f9D5hsbzQigCNgLQu2LyCXGgjTtYuwF4pTOIE/XebuxCrV0L2q4KezsoL259QDV RRuOxewZ0zdsSbQrIpPnsmqj+pyqSKPWqBvG5VFvPYeRgfhtkizlgvRgJJhWTX0ZLpv7 hcb0ZGf+Wv16CGYtcbpSwx9cZ/Dn03pEUj7n+zepX7FfYlJDJHZMCOsJQmNrmu3bMvPE PSbg== X-Gm-Message-State: AOJu0YyUB+42jmAqVPvGBBeSx40tl49n0cnL3gitZvitwVjS5/m/Vpsp PtPPWRZ/Ebhft4z6vlq9WFW9rJglmsRiNBFk8O+eoPLeVF9jUxa+IlCyX8E69iJy7vYZU6AWqCN JJ7bIdi4XPTVAET1q+ncKQyWPsM7Yh2HUIzSRGZ3ZeN9qlMUpOfoQ5EB3CebIvQ1CIxNwZ6eSAl xJTFLIBGcyWbNMqk4GfN0BKh2hP+a+h/fszHKh5XjiIbRWo3wgjphY X-Received: by 2002:a0d:ee45:0:b0:627:c0ab:22b9 with SMTP id 00721157ae682-62fb847de6emr29993107b3.21.1718230319867; Wed, 12 Jun 2024 15:11:59 -0700 (PDT) Received: from [192.168.0.212] ([50.35.46.55]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6b2a5c20435sm309356d6.49.2024.06.12.15.11.56 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 12 Jun 2024 15:11:59 -0700 (PDT) Message-ID: Date: Wed, 12 Jun 2024 15:11:54 -0700 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 v11 1/8] x86/vmware: Introduce VMware hypercall API To: linux-kernel@vger.kernel.org, virtualization@lists.linux.dev, bp@alien8.de, hpa@zytor.com, 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, timothym@vmware.com, akaher@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: <3d6ec46c-53c2-4a13-90ff-eb419863c1d5@broadcom.com> <20240606232334.41384-1-alexey.makhalov@broadcom.com> Content-Language: en-US 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 VrqNoqwW8fObMCHbd6C3m75lzerq1HhrSvLyU4UfprEyAcjOI1C0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fLIi1ek3tpwJWj08+Zo+M47X6B65g7wdrwCiiFfclhXhI1eJNy fqqZgi3rxgu4sc5lmR846emZ/Tx85/nizqWCv7xUBxQwmhRPZRW+37vS2OLpyrTtBj3/tEM9 m9GMmTZqaJFeK7WCpprJV4jNHpWZuNAsQrdK1MrceIxb0/6wYe0xK79lScxms+zs9pGTrO4U 5RoS4gXK65ECcBH8/mumV6oBmLrNxKUrzTczdo9PnkmRyZcAa6AndbjmQDznwxvTZu2LjMPC EuY0 In-Reply-To: <20240606232334.41384-1-alexey.makhalov@broadcom.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Borislav, please review v11 implementation of 1/8 based on your proposal. I'm waiting for your feedback before sending full v11 patchset. Thanks, --Alexey On 6/6/24 4:23 PM, Alexey Makhalov wrote: > Introduce vmware_hypercall family of functions. It is a common > implementation to be used by the VMware guest code and virtual > device drivers in architecture independent manner. > > The API consists of vmware_hypercallX and vmware_hypercall_hb_{out,in} > set of functions by analogy with KVM hypercall API. Architecture > specific implementation is hidden inside. > > It will simplify future enhancements in VMware hypercalls such > as SEV-ES and TDX related changes without needs to modify a > caller in device drivers code. > > Current implementation extends an idea from commit bac7b4e84323 > ("x86/vmware: Update platform detection code for VMCALL/VMMCALL > hypercalls") to have a slow, but safe path vmware_hypercall_slow() > earlier during the boot when alternatives are not yet applied. > The code inherits VMWARE_CMD logic from the commit mentioned above. > > Move common macros from vmware.c to vmware.h. > > Signed-off-by: Alexey Makhalov > --- > arch/x86/include/asm/vmware.h | 279 ++++++++++++++++++++++++++++++++-- > arch/x86/kernel/cpu/vmware.c | 58 ++++++- > 2 files changed, 315 insertions(+), 22 deletions(-) > > diff --git a/arch/x86/include/asm/vmware.h b/arch/x86/include/asm/vmware.h > index ac9fc51e2b18..724c8b9b4b8d 100644 > --- a/arch/x86/include/asm/vmware.h > +++ b/arch/x86/include/asm/vmware.h > @@ -7,26 +7,277 @@ > #include > > /* > - * The hypercall definitions differ in the low word of the %edx argument > - * in the following way: the old port base interface uses the port > - * number to distinguish between high- and low bandwidth versions. > + * VMware hypercall ABI. > + * > + * - Low bandwidth (LB) hypercalls (I/O port based, vmcall and vmmcall) > + * have up to 6 input and 6 output arguments passed and returned using > + * registers: %eax (arg0), %ebx (arg1), %ecx (arg2), %edx (arg3), > + * %esi (arg4), %edi (arg5). > + * The following input arguments must be initialized by the caller: > + * arg0 - VMWARE_HYPERVISOR_MAGIC > + * arg2 - Hypercall command > + * arg3 bits [15:0] - Port number, LB and direction flags > + * > + * - High bandwidth (HB) hypercalls are I/O port based only. They have > + * up to 7 input and 7 output arguments passed and returned using > + * registers: %eax (arg0), %ebx (arg1), %ecx (arg2), %edx (arg3), > + * %esi (arg4), %edi (arg5), %ebp (arg6). > + * The following input arguments must be initialized by the caller: > + * arg0 - VMWARE_HYPERVISOR_MAGIC > + * arg1 - Hypercall command > + * arg3 bits [15:0] - Port number, HB and direction flags > + * > + * For compatibility purposes, x86_64 systems use only lower 32 bits > + * for input and output arguments. > + * > + * The hypercall definitions differ in the low word of the %edx (arg3) > + * in the following way: the old I/O port based interface uses the port > + * number to distinguish between high- and low bandwidth versions, and > + * uses IN/OUT instructions to define transfer direction. > * > * The new vmcall interface instead uses a set of flags to select > * bandwidth mode and transfer direction. The flags should be loaded > - * into %dx by any user and are automatically replaced by the port > - * number if the VMWARE_HYPERVISOR_PORT method is used. > - * > - * In short, new driver code should strictly use the new definition of > - * %dx content. > + * into arg3 by any user and are automatically replaced by the port > + * number if the I/O port method is used. > + */ > + > +#define VMWARE_HYPERVISOR_HB BIT(0) > +#define VMWARE_HYPERVISOR_OUT BIT(1) > + > +#define VMWARE_HYPERVISOR_PORT 0x5658 > +#define VMWARE_HYPERVISOR_PORT_HB (VMWARE_HYPERVISOR_PORT | \ > + VMWARE_HYPERVISOR_HB) > + > +#define VMWARE_HYPERVISOR_MAGIC 0x564d5868U > + > +#define VMWARE_CMD_GETVERSION 10 > +#define VMWARE_CMD_GETHZ 45 > +#define VMWARE_CMD_GETVCPU_INFO 68 > +#define VMWARE_CMD_STEALCLOCK 91 > + > +#define CPUID_VMWARE_FEATURES_ECX_VMMCALL BIT(0) > +#define CPUID_VMWARE_FEATURES_ECX_VMCALL BIT(1) > + > +extern unsigned long vmware_hypercall_slow(unsigned long cmd, > + unsigned long in1, unsigned long in3, > + unsigned long in4, unsigned long in5, > + u32 *out1, u32 *out2, u32 *out3, > + u32 *out4, u32 *out5); > + > +/* > + * The low bandwidth call. The low word of %edx is presumed to have OUT bit > + * set. The high word of %edx may contain input data from the caller. > */ > +#define VMWARE_HYPERCALL \ > + ALTERNATIVE_2("movw %[port], %%dx\n\t" \ > + "inl (%%dx), %%eax", \ > + "vmcall", X86_FEATURE_VMCALL, \ > + "vmmcall", X86_FEATURE_VMW_VMMCALL) > + > +static inline > +unsigned long vmware_hypercall1(unsigned long cmd, unsigned long in1) > +{ > + unsigned long out0; > + > + if (unlikely(!alternatives_patched) && !__is_defined(MODULE)) > + return vmware_hypercall_slow(cmd, in1, 0, 0, 0, > + NULL, NULL, NULL, NULL, NULL); > + > + asm_inline volatile (VMWARE_HYPERCALL > + : "=a" (out0) > + : [port] "i" (VMWARE_HYPERVISOR_PORT), > + "a" (VMWARE_HYPERVISOR_MAGIC), > + "b" (in1), > + "c" (cmd), > + "d" (0) > + : "cc", "memory"); > + return out0; > +} > + > +static inline > +unsigned long vmware_hypercall3(unsigned long cmd, unsigned long in1, > + u32 *out1, u32 *out2) > +{ > + unsigned long out0; > + > + if (unlikely(!alternatives_patched) && !__is_defined(MODULE)) > + return vmware_hypercall_slow(cmd, in1, 0, 0, 0, > + out1, out2, NULL, NULL, NULL); > + > + asm_inline volatile (VMWARE_HYPERCALL > + : "=a" (out0), "=b" (*out1), "=c" (*out2) > + : [port] "i" (VMWARE_HYPERVISOR_PORT), > + "a" (VMWARE_HYPERVISOR_MAGIC), > + "b" (in1), > + "c" (cmd), > + "d" (0) > + : "cc", "memory"); > + return out0; > +} > + > +static inline > +unsigned long vmware_hypercall4(unsigned long cmd, unsigned long in1, > + u32 *out1, u32 *out2, u32 *out3) > +{ > + unsigned long out0; > + > + if (unlikely(!alternatives_patched) && !__is_defined(MODULE)) > + return vmware_hypercall_slow(cmd, in1, 0, 0, 0, > + out1, out2, out3, NULL, NULL); > + > + asm_inline volatile (VMWARE_HYPERCALL > + : "=a" (out0), "=b" (*out1), "=c" (*out2), "=d" (*out3) > + : [port] "i" (VMWARE_HYPERVISOR_PORT), > + "a" (VMWARE_HYPERVISOR_MAGIC), > + "b" (in1), > + "c" (cmd), > + "d" (0) > + : "cc", "memory"); > + return out0; > +} > + > +static inline > +unsigned long vmware_hypercall5(unsigned long cmd, unsigned long in1, > + unsigned long in3, unsigned long in4, > + unsigned long in5, u32 *out2) > +{ > + unsigned long out0; > + > + if (unlikely(!alternatives_patched) && !__is_defined(MODULE)) > + return vmware_hypercall_slow(cmd, in1, in3, in4, in5, > + NULL, out2, NULL, NULL, NULL); > + > + asm_inline volatile (VMWARE_HYPERCALL > + : "=a" (out0), "=c" (*out2) > + : [port] "i" (VMWARE_HYPERVISOR_PORT), > + "a" (VMWARE_HYPERVISOR_MAGIC), > + "b" (in1), > + "c" (cmd), > + "d" (in3), > + "S" (in4), > + "D" (in5) > + : "cc", "memory"); > + return out0; > +} > + > +static inline > +unsigned long vmware_hypercall6(unsigned long cmd, unsigned long in1, > + unsigned long in3, u32 *out2, > + u32 *out3, u32 *out4, u32 *out5) > +{ > + unsigned long out0; > + > + if (unlikely(!alternatives_patched) && !__is_defined(MODULE)) > + return vmware_hypercall_slow(cmd, in1, in3, 0, 0, > + NULL, out2, out3, out4, out5); > + > + asm_inline volatile (VMWARE_HYPERCALL > + : "=a" (out0), "=c" (*out2), "=d" (*out3), "=S" (*out4), > + "=D" (*out5) > + : [port] "i" (VMWARE_HYPERVISOR_PORT), > + "a" (VMWARE_HYPERVISOR_MAGIC), > + "b" (in1), > + "c" (cmd), > + "d" (in3) > + : "cc", "memory"); > + return out0; > +} > + > +static inline > +unsigned long vmware_hypercall7(unsigned long cmd, unsigned long in1, > + unsigned long in3, unsigned long in4, > + unsigned long in5, u32 *out1, > + u32 *out2, u32 *out3) > +{ > + unsigned long out0; > + > + if (unlikely(!alternatives_patched) && !__is_defined(MODULE)) > + return vmware_hypercall_slow(cmd, in1, in3, in4, in5, > + out1, out2, out3, NULL, NULL); > + > + asm_inline volatile (VMWARE_HYPERCALL > + : "=a" (out0), "=b" (*out1), "=c" (*out2), "=d" (*out3) > + : [port] "i" (VMWARE_HYPERVISOR_PORT), > + "a" (VMWARE_HYPERVISOR_MAGIC), > + "b" (in1), > + "c" (cmd), > + "d" (in3), > + "S" (in4), > + "D" (in5) > + : "cc", "memory"); > + return out0; > +} > + > +#ifdef CONFIG_X86_64 > +#define VMW_BP_CONSTRAINT "r" > +#else > +#define VMW_BP_CONSTRAINT "m" > +#endif > + > +/* > + * High bandwidth calls are not supported on encrypted memory guests. > + * The caller should check cc_platform_has(CC_ATTR_MEM_ENCRYPT) and use > + * low bandwidth hypercall if memory encryption is set. > + * This assumption simplifies HB hypercall implementation to just I/O port > + * based approach without alternative patching. > + */ > +static inline > +unsigned long vmware_hypercall_hb_out(unsigned long cmd, unsigned long in2, > + unsigned long in3, unsigned long in4, > + unsigned long in5, unsigned long in6, > + u32 *out1) > +{ > + unsigned long out0; > + > + asm_inline volatile ( > + UNWIND_HINT_SAVE > + "push %%" _ASM_BP "\n\t" > + UNWIND_HINT_UNDEFINED > + "mov %[in6], %%" _ASM_BP "\n\t" > + "rep outsb\n\t" > + "pop %%" _ASM_BP "\n\t" > + UNWIND_HINT_RESTORE > + : "=a" (out0), "=b" (*out1) > + : "a" (VMWARE_HYPERVISOR_MAGIC), > + "b" (cmd), > + "c" (in2), > + "d" (in3 | VMWARE_HYPERVISOR_PORT_HB), > + "S" (in4), > + "D" (in5), > + [in6] VMW_BP_CONSTRAINT (in6) > + : "cc", "memory"); > + return out0; > +} > > -/* Old port-based version */ > -#define VMWARE_HYPERVISOR_PORT 0x5658 > -#define VMWARE_HYPERVISOR_PORT_HB 0x5659 > +static inline > +unsigned long vmware_hypercall_hb_in(unsigned long cmd, unsigned long in2, > + unsigned long in3, unsigned long in4, > + unsigned long in5, unsigned long in6, > + u32 *out1) > +{ > + unsigned long out0; > > -/* Current vmcall / vmmcall version */ > -#define VMWARE_HYPERVISOR_HB BIT(0) > -#define VMWARE_HYPERVISOR_OUT BIT(1) > + asm_inline volatile ( > + UNWIND_HINT_SAVE > + "push %%" _ASM_BP "\n\t" > + UNWIND_HINT_UNDEFINED > + "mov %[in6], %%" _ASM_BP "\n\t" > + "rep insb\n\t" > + "pop %%" _ASM_BP "\n\t" > + UNWIND_HINT_RESTORE > + : "=a" (out0), "=b" (*out1) > + : "a" (VMWARE_HYPERVISOR_MAGIC), > + "b" (cmd), > + "c" (in2), > + "d" (in3 | VMWARE_HYPERVISOR_PORT_HB), > + "S" (in4), > + "D" (in5), > + [in6] VMW_BP_CONSTRAINT (in6) > + : "cc", "memory"); > + return out0; > +} > +#undef VMW_BP_CONSTRAINT > +#undef VMWARE_HYPERCALL > > /* The low bandwidth call. The low word of edx is presumed clear. */ > #define VMWARE_HYPERCALL \ > diff --git a/arch/x86/kernel/cpu/vmware.c b/arch/x86/kernel/cpu/vmware.c > index 11f83d07925e..533ac2d1de88 100644 > --- a/arch/x86/kernel/cpu/vmware.c > +++ b/arch/x86/kernel/cpu/vmware.c > @@ -41,17 +41,9 @@ > > #define CPUID_VMWARE_INFO_LEAF 0x40000000 > #define CPUID_VMWARE_FEATURES_LEAF 0x40000010 > -#define CPUID_VMWARE_FEATURES_ECX_VMMCALL BIT(0) > -#define CPUID_VMWARE_FEATURES_ECX_VMCALL BIT(1) > > -#define VMWARE_HYPERVISOR_MAGIC 0x564D5868 > - > -#define VMWARE_CMD_GETVERSION 10 > -#define VMWARE_CMD_GETHZ 45 > -#define VMWARE_CMD_GETVCPU_INFO 68 > #define VMWARE_CMD_LEGACY_X2APIC 3 > #define VMWARE_CMD_VCPU_RESERVED 31 > -#define VMWARE_CMD_STEALCLOCK 91 > > #define STEALCLOCK_NOT_AVAILABLE (-1) > #define STEALCLOCK_DISABLED 0 > @@ -110,6 +102,56 @@ struct vmware_steal_time { > static unsigned long vmware_tsc_khz __ro_after_init; > static u8 vmware_hypercall_mode __ro_after_init; > > +unsigned long vmware_hypercall_slow(unsigned long cmd, > + unsigned long in1, unsigned long in3, > + unsigned long in4, unsigned long in5, > + u32 *out1, u32 *out2, u32 *out3, > + u32 *out4, u32 *out5) > +{ > + unsigned long out0; > + > + switch (vmware_hypercall_mode) { > + case CPUID_VMWARE_FEATURES_ECX_VMCALL: > + asm_inline volatile ("vmcall" > + : "=a" (out0), "=b" (*out1), "=c" (*out2), > + "=d" (*out3), "=S" (*out4), "=D" (*out5) > + : "a" (VMWARE_HYPERVISOR_MAGIC), > + "b" (in1), > + "c" (cmd), > + "d" (in3), > + "S" (in4), > + "D" (in5) > + : "cc", "memory"); > + break; > + case CPUID_VMWARE_FEATURES_ECX_VMMCALL: > + asm_inline volatile ("vmmcall" > + : "=a" (out0), "=b" (*out1), "=c" (*out2), > + "=d" (*out3), "=S" (*out4), "=D" (*out5) > + : "a" (VMWARE_HYPERVISOR_MAGIC), > + "b" (in1), > + "c" (cmd), > + "d" (in3), > + "S" (in4), > + "D" (in5) > + : "cc", "memory"); > + break; > + default: > + asm_inline volatile ("movw %[port], %%dx; inl (%%dx), %%eax" > + : "=a" (out0), "=b" (*out1), "=c" (*out2), > + "=d" (*out3), "=S" (*out4), "=D" (*out5) > + : [port] "i" (VMWARE_HYPERVISOR_PORT), > + "a" (VMWARE_HYPERVISOR_MAGIC), > + "b" (in1), > + "c" (cmd), > + "d" (in3), > + "S" (in4), > + "D" (in5) > + : "cc", "memory"); > + break; > + } > + return out0; > +} > + > static inline int __vmware_platform(void) > { > uint32_t eax, ebx, ecx, edx;