Received: by 2002:a89:288:0:b0:1f7:eeee:6653 with SMTP id j8csp159878lqh; Mon, 6 May 2024 14:54:40 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVvjFMiJtTikKxco5c5x+H76FF70jOnaB4Se/BmBEqZcCrNc58PhGiBC0ipgHnaZm6y3PRy1Gqf8x/oJwR1eoAP3eyI0AsRtDIDB5MKdA== X-Google-Smtp-Source: AGHT+IGVAxyf4Xr4ph1T0Xxn+1bF9L2oO2G6qkMqFa+T7NIJy8JteNjx9fxCSHPbI8xs4CdJlMSo X-Received: by 2002:a05:620a:1a21:b0:790:f387:c2bb with SMTP id bk33-20020a05620a1a2100b00790f387c2bbmr12833850qkb.14.1715032480410; Mon, 06 May 2024 14:54:40 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715032480; cv=pass; d=google.com; s=arc-20160816; b=YPmGtsUJnlaaQLiB3FkbBdDMgcrkJ7yp2mDhxVSHOJruu4jd5I+wrfrSaP8nrYntcR r8jq+xDgTthKpkZpOyvGrBif7rSBbLULOEW6ndguM4lb+cHEuDalY97VuMEBZAMJl9Ud fuJC8f/Pvt1Z9SDFQtTZchUUR4isC+ezhPctdB4GsOKVUf38FiFopssfttcrJHWRtOsj rfekmnOIPpRR1xBitdsoi9Gdip6xQazGtdiLN0ESgVe5DD5q68Tv6JuJYPFK69i3jnl/ GLy7kWIman0pPN1OlOHhx/sHfw/g/x47JjCxjQmBclaHTm/0m621rdiWjtI9LCEm44Yf 5P8A== 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:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=unRpkwwh5dJFFHedeUaWdr6DvAi5Mpoz54YPBsP5M3Q=; fh=VnT+uWheY36Da2W5fbL53Yx6nMpGwJw9M6S68Twltig=; b=ztAymza0bzsIL6Cn+paRw1cNYMeTW7PiWlmmaP+gRspd8KhLt1qFKUjePsOkAeq7pV Zq1tXcFOSMIa5dAg9RxRflV3jUfRl/EfYTxyX64nvQPpBDL7wKILop8LoSNxVX/9nOfn OKb3E2N64WwSoVGBFlWlGiuEMsc6OcGBvSopKlkYQiOjRW1ldFYmCrdrvoK3abiBCBWK BkjhmBSQGt9IZTxPjrQZOuOSLnk+wPqpT82wQIHYpi0uoZxwduuoTxKNWew8Rk/rwmBD x7zEa2+3+sddojNpITGgDJhD0x4beZMI21OPpTG0QqV5K5nJjY89OtTTO/UY0Ucoecjo uPEg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@broadcom.com header.s=google header.b=PP564QTo; arc=pass (i=1 dkim=pass dkdomain=broadcom.com dmarc=pass fromdomain=broadcom.com); spf=pass (google.com: domain of linux-kernel+bounces-170453-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-170453-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=broadcom.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id pa15-20020a05620a830f00b0079158f66be8si9895553qkn.372.2024.05.06.14.54.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 May 2024 14:54:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-170453-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@broadcom.com header.s=google header.b=PP564QTo; arc=pass (i=1 dkim=pass dkdomain=broadcom.com dmarc=pass fromdomain=broadcom.com); spf=pass (google.com: domain of linux-kernel+bounces-170453-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-170453-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 1A37C1C221C4 for ; Mon, 6 May 2024 21:54:40 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7488D15E207; Mon, 6 May 2024 21:53:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=broadcom.com header.i=@broadcom.com header.b="PP564QTo" Received: from mail-pf1-f178.google.com (mail-pf1-f178.google.com [209.85.210.178]) (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 CD71815D5B6 for ; Mon, 6 May 2024 21:53:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.178 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715032420; cv=none; b=QKw5lXuQM4utpC2rY0CSrpmzjKuW3VnEavoF0tbnRgbqifrwn2nJGjAaXqSquKPqUcfGjr7ktc0mZKYlZwGNClOeXBdCYLyR+mXddgSin6SPkpWMQ3j1GR4+fI7NWy/4xMEdbGtF587f6ZTwjYp2DUZmffFGSu1h2GeFIOC8JsU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715032420; c=relaxed/simple; bh=+b5WVE8Zl/oL6yUg8wqjTrG63YhiMX5zZ8A4o/ecnHA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=gFDSdl/EBsu6IHBUJs2mt5LAELGtHEIjYRsNLjm/rI0zC3Oh03FU/tCNPYybrGqUxdcYbgQC6Ncab/iQnAghoy+NkQz4GXfe2S94vfe1aTrCtqfC8rlMsO4D3TqpSQCpq7657rjBbt1hZ7657ZVwu9+hM4rR3J58C0IuB3lL7E8= 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=PP564QTo; arc=none smtp.client-ip=209.85.210.178 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-pf1-f178.google.com with SMTP id d2e1a72fcca58-6edc61d0ff6so2310847b3a.2 for ; Mon, 06 May 2024 14:53:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; t=1715032418; x=1715637218; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=unRpkwwh5dJFFHedeUaWdr6DvAi5Mpoz54YPBsP5M3Q=; b=PP564QToJ/RgCPF9pEdEuxzyXNcNpLY1hIfwdi7BELtXdrCb8sFL/oqMJJqv333aaC w3JlotrpSC9lPb6gcfOkJyTn3vhiRW22LuHJHgxHbagngtyIUh6E25bTVtRTHgzY1O2a /B3yZKfcx//UcmI9UX4kq/Ffb32CI0AA8oKfQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715032418; x=1715637218; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=unRpkwwh5dJFFHedeUaWdr6DvAi5Mpoz54YPBsP5M3Q=; b=EYujYAriKwl6HZZ0++U1KSs7AqzTXKYxOspd5h3mlIyIFKQNZ+7goiE4gBVWJMdn2W IxuUxCwmYUXyYGqJUIlKMvJD797fZbzo+YIjOHvV9ZjiZ9al6t87lzSuFEJIiOLwT7np wrfsevsJ6Efe205GgCIDhk2syGJMu9lu1n5H+90jjDLdVUM/jdBUuuk3CeFdo4BQgdgV 0HL0nf8c7ELD4o5VfKxmSOT8s0FQFHlUbJF0V5PYQACIknjQAZpD4dE7XUmFQDov5Zm0 EBzM5jz2ZZNNRL6VdxLcdsFoBBePhqFMv8MAbYkX4RfSoUlr/TzQYhQyDf3hMTWlchwl KWzw== X-Gm-Message-State: AOJu0Yxjy75X1fm5q4Uqqr6ZlSL15+ZUovGpmC5NX072cUG2tDlVzflQ 3D3UymFoaECbwpMuKyGD0n9yv3hNszbntI0/bd4JBBSKGKXEWh1L55r109WfKe/BT82J5qvtymY AGhw74mYI5Ot3Qtgmpvrr049U/4cnCgwTLuggR0YcQbN3+u30KPyR3Uykv6pl6E0RRKXMADhhgu GA1vAN8oOPEZqQ8npVVuNGqL5J8LhfYzIt11Kk/MVtZ9jyX7emDTkS X-Received: by 2002:a05:6a20:7347:b0:1ad:7e66:659a with SMTP id v7-20020a056a20734700b001ad7e66659amr15303766pzc.15.1715032417415; Mon, 06 May 2024 14:53:37 -0700 (PDT) Received: from amakhalov-build-vm.eng.vmware.com ([128.177.82.146]) by smtp.gmail.com with ESMTPSA id h8-20020a170902f54800b001ed6868e257sm5664008plf.123.2024.05.06.14.53.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 May 2024 14:53:36 -0700 (PDT) From: Alexey Makhalov 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, Alexey Makhalov , Nadav Amit Subject: [PATCH v9 1/8] x86/vmware: Move common macros to vmware.h Date: Mon, 6 May 2024 14:52:58 -0700 Message-Id: <20240506215305.30756-2-alexey.makhalov@broadcom.com> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20240506215305.30756-1-alexey.makhalov@broadcom.com> References: <20240505182829.GBZjfPzeEijTsBUth5@fat_crate.local> <20240506215305.30756-1-alexey.makhalov@broadcom.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Move VMware hypercall macros to vmware.h. This is a prerequisite for the introduction of vmware_hypercall API. No functional changes besides exporting vmware_hypercall_mode symbol. Signed-off-by: Alexey Makhalov Reviewed-by: Nadav Amit --- arch/x86/include/asm/vmware.h | 72 +++++++++++++++++++++++++++++------ arch/x86/kernel/cpu/vmware.c | 49 +----------------------- 2 files changed, 62 insertions(+), 59 deletions(-) diff --git a/arch/x86/include/asm/vmware.h b/arch/x86/include/asm/vmware.h index ac9fc51e2b18..de2533337611 100644 --- a/arch/x86/include/asm/vmware.h +++ b/arch/x86/include/asm/vmware.h @@ -8,25 +8,34 @@ /* * 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. + * 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. + * number if the I/O port method is used. */ -/* Old port-based version */ -#define VMWARE_HYPERVISOR_PORT 0x5658 -#define VMWARE_HYPERVISOR_PORT_HB 0x5659 +#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) -/* Current vmcall / vmmcall version */ -#define VMWARE_HYPERVISOR_HB BIT(0) -#define VMWARE_HYPERVISOR_OUT BIT(1) +extern u8 vmware_hypercall_mode; /* The low bandwidth call. The low word of edx is presumed clear. */ #define VMWARE_HYPERCALL \ @@ -54,4 +63,43 @@ "rep insb", \ "vmcall", X86_FEATURE_VMCALL, \ "vmmcall", X86_FEATURE_VMW_VMMCALL) + +#define VMWARE_PORT(cmd, eax, ebx, ecx, edx) \ + __asm__("inl (%%dx), %%eax" : \ + "=a"(eax), "=c"(ecx), "=d"(edx), "=b"(ebx) : \ + "a"(VMWARE_HYPERVISOR_MAGIC), \ + "c"(VMWARE_CMD_##cmd), \ + "d"(VMWARE_HYPERVISOR_PORT), "b"(UINT_MAX) : \ + "memory") + +#define VMWARE_VMCALL(cmd, eax, ebx, ecx, edx) \ + __asm__("vmcall" : \ + "=a"(eax), "=c"(ecx), "=d"(edx), "=b"(ebx) : \ + "a"(VMWARE_HYPERVISOR_MAGIC), \ + "c"(VMWARE_CMD_##cmd), \ + "d"(0), "b"(UINT_MAX) : \ + "memory") + +#define VMWARE_VMMCALL(cmd, eax, ebx, ecx, edx) \ + __asm__("vmmcall" : \ + "=a"(eax), "=c"(ecx), "=d"(edx), "=b"(ebx) : \ + "a"(VMWARE_HYPERVISOR_MAGIC), \ + "c"(VMWARE_CMD_##cmd), \ + "d"(0), "b"(UINT_MAX) : \ + "memory") + +#define VMWARE_CMD(cmd, eax, ebx, ecx, edx) do { \ + switch (vmware_hypercall_mode) { \ + case CPUID_VMWARE_FEATURES_ECX_VMCALL: \ + VMWARE_VMCALL(cmd, eax, ebx, ecx, edx); \ + break; \ + case CPUID_VMWARE_FEATURES_ECX_VMMCALL: \ + VMWARE_VMMCALL(cmd, eax, ebx, ecx, edx); \ + break; \ + default: \ + VMWARE_PORT(cmd, eax, ebx, ecx, edx); \ + break; \ + } \ + } while (0) + #endif diff --git a/arch/x86/kernel/cpu/vmware.c b/arch/x86/kernel/cpu/vmware.c index 11f83d07925e..68d812e12e52 100644 --- a/arch/x86/kernel/cpu/vmware.c +++ b/arch/x86/kernel/cpu/vmware.c @@ -41,60 +41,14 @@ #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 #define STEALCLOCK_ENABLED 1 -#define VMWARE_PORT(cmd, eax, ebx, ecx, edx) \ - __asm__("inl (%%dx), %%eax" : \ - "=a"(eax), "=c"(ecx), "=d"(edx), "=b"(ebx) : \ - "a"(VMWARE_HYPERVISOR_MAGIC), \ - "c"(VMWARE_CMD_##cmd), \ - "d"(VMWARE_HYPERVISOR_PORT), "b"(UINT_MAX) : \ - "memory") - -#define VMWARE_VMCALL(cmd, eax, ebx, ecx, edx) \ - __asm__("vmcall" : \ - "=a"(eax), "=c"(ecx), "=d"(edx), "=b"(ebx) : \ - "a"(VMWARE_HYPERVISOR_MAGIC), \ - "c"(VMWARE_CMD_##cmd), \ - "d"(0), "b"(UINT_MAX) : \ - "memory") - -#define VMWARE_VMMCALL(cmd, eax, ebx, ecx, edx) \ - __asm__("vmmcall" : \ - "=a"(eax), "=c"(ecx), "=d"(edx), "=b"(ebx) : \ - "a"(VMWARE_HYPERVISOR_MAGIC), \ - "c"(VMWARE_CMD_##cmd), \ - "d"(0), "b"(UINT_MAX) : \ - "memory") - -#define VMWARE_CMD(cmd, eax, ebx, ecx, edx) do { \ - switch (vmware_hypercall_mode) { \ - case CPUID_VMWARE_FEATURES_ECX_VMCALL: \ - VMWARE_VMCALL(cmd, eax, ebx, ecx, edx); \ - break; \ - case CPUID_VMWARE_FEATURES_ECX_VMMCALL: \ - VMWARE_VMMCALL(cmd, eax, ebx, ecx, edx); \ - break; \ - default: \ - VMWARE_PORT(cmd, eax, ebx, ecx, edx); \ - break; \ - } \ - } while (0) - struct vmware_steal_time { union { uint64_t clock; /* stolen time counter in units of vtsc */ @@ -108,7 +62,8 @@ struct vmware_steal_time { }; static unsigned long vmware_tsc_khz __ro_after_init; -static u8 vmware_hypercall_mode __ro_after_init; +u8 vmware_hypercall_mode __ro_after_init; +EXPORT_SYMBOL_GPL(vmware_hypercall_mode); static inline int __vmware_platform(void) { -- 2.39.0