From patchwork Fri Dec 1 23:24:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexey Makhalov X-Patchwork-Id: 13476602 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=vmware.com header.i=@vmware.com header.b="s93TrmUJ" Received: from MW2PR02CU001.outbound.protection.outlook.com (mail-westus2azon11012013.outbound.protection.outlook.com [52.101.48.13]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9F77E85; Fri, 1 Dec 2023 15:25:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=CrVAHURCecxAqg+7JqxLP23FN7xYVLDKOKagNyluO5EkCrq/0XNC64U3lDABYfyurRcmF/qON1zOiFllz9MgEy2pW9TWppXICU1wko+0w4yTedtbu4bS8+vxGWcrROH1B+118O+KX25aEPZPgJ8nukTtxAQ/CgmqfJIjd4FQVNphcaXXt5wlxanqrgyn37a2jOEYNZIrNtnNTvaiN+Lr39LN6UPraFUPUgocXwoyo6CA61rHAmZ//3SUzire21dswtkL1SfZ6KE2g2+/UqYdB49wHdgAjNOxE3VJKQvf/Mi1GiZirXWxYP2nXVqFYivC5aGMRlozsCVWVZYY9l0trA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=DJ+gRkoGbU3l0zmNQ1Fq7uSrv1o6gbhB8z13Z2qxmkg=; b=gupRcuu7cXw/K9tmWUOpZV/uv6ufIIBJaCStX+kgFDF5DZySwRDMbqRf3Quy7CTU1yC/H0OOSwYd3UP7XK4xYKCyZtVKe6uqdJA0fpridZGLtwQP5nI+KCIogfieBxeoK7kRnhxobNyeeyDJ5H3v5lMERSmz02/OgsK61FiEC8qM3ovNOoY2vBbLxX78CyziaVTWE2rrCFSf55Zrk0OJbgnkJE+VwiFFtnh0aalYTLiys6zYd5z+3r8Td72AwYq1fA/fAvYTsm0Gb77mqMXo63BkhvmmKkjLT5LN6vLEvrQ2gZNVvP2CUSZpLbXSiuwNHEpyhOuwXrGfDIbCqbLALQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=vmware.com; dmarc=pass action=none header.from=vmware.com; dkim=pass header.d=vmware.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vmware.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=DJ+gRkoGbU3l0zmNQ1Fq7uSrv1o6gbhB8z13Z2qxmkg=; b=s93TrmUJuzvg4VLrLkDUG7Brm4gzBeXZxkhHcAWQ11CGFoMKiYn7VFeyrIXkuuag1njzJJZTXxjrLPY0d0ic5SDePnO859iUsIsYNBbQPEQ2PdpmRjGruEIpOvmWRKZc2kBCeDNjSmFj2a1vLUgHIMgwUNQmZXANDREYdECfWBM= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=vmware.com; Received: from MWHPR05MB3648.namprd05.prod.outlook.com (2603:10b6:301:45::23) by SJ0PR05MB7787.namprd05.prod.outlook.com (2603:10b6:a03:2e4::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7046.27; Fri, 1 Dec 2023 23:25:06 +0000 Received: from MWHPR05MB3648.namprd05.prod.outlook.com ([fe80::10f0:590a:708:4ad7]) by MWHPR05MB3648.namprd05.prod.outlook.com ([fe80::10f0:590a:708:4ad7%2]) with mapi id 15.20.7025.021; Fri, 1 Dec 2023 23:25:06 +0000 From: Alexey Makhalov To: linux-kernel@vger.kernel.org, virtualization@lists.linux.dev, hpa@zytor.com, dave.hansen@linux.intel.co, bp@alien8.d, 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 Subject: [PATCH v2 1/6] x86/vmware: Move common macros to vmware.h Date: Fri, 1 Dec 2023 15:24:47 -0800 Message-Id: <20231201232452.220355-2-amakhalov@vmware.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231201232452.220355-1-amakhalov@vmware.com> References: <20231122233058.185601-8-amakhalov@vmware.com> <20231201232452.220355-1-amakhalov@vmware.com> X-ClientProxiedBy: SJ2PR07CA0017.namprd07.prod.outlook.com (2603:10b6:a03:505::17) To MWHPR05MB3648.namprd05.prod.outlook.com (2603:10b6:301:45::23) Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MWHPR05MB3648:EE_|SJ0PR05MB7787:EE_ X-MS-Office365-Filtering-Correlation-Id: a170113b-653f-4522-f9ea-08dbf2c4c09e X-LD-Processed: b39138ca-3cee-4b4a-a4d6-cd83d9dd62f0,ExtFwd,ExtAddr X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: E+ue7dd1rPbX6VHLHTmuxXx3D9L+CVQwNr3VRjn+J7eXXB31915SmtXQWdmHE4pXF20dzrAU843AQ95Q1RA2Y/bYZP/lBUX5NiSTAQQr4nl2ySvCFw6RcWDo7g79j2DmNHoufQW9L4ZLosYlJszTUTefUZZvhzev/cL3/WUDXP1vCDx3eDwDzyixfq/fWR0m5ZvO44BpTpslsyto3n8vpRmqlZCl0mk0JEti6xuxpofs7RG15VKdl8x6T9zvVpZUjH5/XHbmoJCk/+6fJGl3ZamHkzbsIA0cabL5fSVi9sCwiEfRoDl7+VwZna4XszkVCRgG/eFTnripIqUPw0ysdMK//tfUYyrG2de6rNwDv7jNcw5hGngVWe53ovsq1uUKmYVK+FFvBlQDqrrd2gcD4VRGwfAE7F+y0/3YZ/D3KK5Jc1eDQKmW2kEtf0n9/4YYxsrSr4cD8gu2zfhWvFzDninMR19aaj3QAp7u9PdZ9Sz0qN83qjYZtYgcWckkfwoO1iBbmeQaJlod/zaN+9jJWsAyeFpyve49fPNg/gXv2VdSurl1gVoakTEsy26LCPR2ZS5VbQfoHNOTj+Aomnvq+r8yMl1WiS0Nwz08hTYAgHXarW7Mh1GnQn8d56AnWS/pbE+xXpvjRYFrRdmRMMFBZi3X3Tp0JEq0Jixmptw0rlM= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:MWHPR05MB3648.namprd05.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(39860400002)(346002)(366004)(376002)(396003)(136003)(230922051799003)(451199024)(186009)(1800799012)(64100799003)(36756003)(8936002)(316002)(66556008)(66946007)(66476007)(8676002)(4326008)(478600001)(6486002)(41300700001)(2906002)(7416002)(86362001)(5660300002)(38350700005)(38100700002)(2616005)(26005)(1076003)(6666004)(6506007)(52116002)(83380400001)(6512007);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: KB2Qp5y40fjnaSAe/oDoEDyi9u85tGoF4sAu9zMPD9ZahkaXTeDPG8xnzTEH7baMO9Js6tYGp2Ex1o8lx49crJOddPeuoOyP3JtEZ2+2MevcgkAO6F4LI61c+2n02kvK+/TELZ3oZ3nYb5BlDa2JLhK0LhOGxA0eVpzFGuPVuxIN7tBqwBDQUyooS+ESqeY4hHafjrKESkqZrngTjpEQRy1UHFkM3GY+b58vCIdGS8YxjPvdM++GLP5dVHN++uuVHXKsz/IMViRO+5zUUem3C+sWZpeWE98T4G92JEQf7O6WEE67OJ7vn7RkFxD/4nq5xylPpvCfzyJuoA4/jyDq8bVlvGVcNm71sIvOOE6Is/jrsdeK6bYKzjWj7T8yzge2el5eGJxs5VJZ12CJo4MIhj0T+38H/bpEG4s+JyRBGJYvJ66DHpKgGMvJWy6zWm4CcNboZB1Sc4mL0WxX4XByFJOV4dXFkIw7n06QMQppaOLYwMAWLZ+ziED6yTPqibdsT8FxwN0t0DqaqZZghX1VlnzZ+RCDLZIavKq0hrN5vC/lEmfVgKtVtC28hSYSZ4dGzb2ng8vUMPZeLEf7VpDG6/UTMzCNjOAhWhs1m7OwmQBvBCxsGoOwn+aP9deoHoc+1E8DUWdnpBdjobMaNXvd4Ap4yYdFTjd4qJ0pC16xBaZ8M7IUQ9rxA/Fmv1FU0XOOVMqkDEooXKUqOwn6Z8UQQWvspHBKF9IumNO5KsPiSf0RSy6cA0/X6ihos3zGSREvRhhVuJ+YkwUMFveeAwOEr/6KV0nreaAxozetZd3d9jmFOEhsNK0fW+q0cvmGNc4KsrvDlc68h5UsRz4Vx7w1tbj2ka8h0TqGNuN40ET8yZcBZVYhjowGE4KnUmy6BS1BqnQzgzN1TfmnZ07vTCwJCMqWGS0z+Lf8BsehbLHG+A545C/95zr2HQHC4RRGgml16pmAlpHXI+YrmQ9qylhoMePN0653y10kYm3r/1jT2eFa8Zr+ZVlyehRrvnMDLCoA0imhpAoUhb65C5wqfmWeKcli4R+todhUUKRGIxs7+zOGK87tIu3fJlme5235CcVFqPUechuuj32VX3qKJY7jhZp3L6GSy57OevsSUal+JcvWiyHRvAx2f1c6AnNrxnRl4za5UkuGZqXrgmIa/dWbRsqsSQhBO0s3F9Hddw0Y7opTUmH7mrxAMfL3rvM8oVHw98YE+KoXSm7u3H9o75dOETZNdkQWKeiROdSRdpifWaA0qa+Xp4iOp3AXbH0aCHCSyxeFOtDDCymMuZdYA5hnmkVnJxvp9txx6CaZvtzyYxbo09i3nh4o3XTtQQmAipsny8gQCptHFVLQXz4oDW0XYneO8cGtfG693uFeNQfAZL9oDmFn/1KM3TT2m7xHYgaq//EA0Bf+MgYCGjAJ3Dfktv2QytGRlesoZ+yAJd3Q8YDvsTIuMh2l0ylq8pKOlJATtibZhRICe/QWw6IOrSx1/qJeO2Tu2KKya6Lykkmhj3jDMYIFtLGu5KLm6Ba8988duVJ/pEsVClO++35LWjpCoL0+snuo+0EFylE5oMWfA6h2SDOr3dsQrleD/ByXw2aj X-OriginatorOrg: vmware.com X-MS-Exchange-CrossTenant-Network-Message-Id: a170113b-653f-4522-f9ea-08dbf2c4c09e X-MS-Exchange-CrossTenant-AuthSource: MWHPR05MB3648.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Dec 2023 23:25:06.5954 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: b39138ca-3cee-4b4a-a4d6-cd83d9dd62f0 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: PE28J+N4xO8yaunaFew+Thwnx4Mkw9unuu6t9r5UeV9ngu1ExT5a++pXG8lHMDyJBBvP66POXvK2WllQ6b8ZeQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR05MB7787 Move VMware hypercall macros to vmware.h as a preparation step for the next commit. No functional changes besides exporting vmware_hypercall_mode symbol. Signed-off-by: Alexey Makhalov Reviewed-by: Nadav Amit --- arch/x86/include/asm/vmware.h | 69 ++++++++++++++++++++++++++++++----- arch/x86/kernel/cpu/vmware.c | 57 +++-------------------------- 2 files changed, 66 insertions(+), 60 deletions(-) diff --git a/arch/x86/include/asm/vmware.h b/arch/x86/include/asm/vmware.h index ac9fc51e2b18..8cabf4a577bf 100644 --- a/arch/x86/include/asm/vmware.h +++ b/arch/x86/include/asm/vmware.h @@ -8,25 +8,37 @@ /* * 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. + * number if the I/O port method is used. * * In short, new driver code should strictly use the new definition of * %dx content. */ -/* 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) -/* Current vmcall / vmmcall version */ -#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 u8 vmware_hypercall_mode; /* The low bandwidth call. The low word of edx is presumed clear. */ #define VMWARE_HYPERCALL \ @@ -54,4 +66,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..4db8e1daa4a1 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 VCPU_LEGACY_X2APIC 3 +#define VCPU_RESERVED 31 #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) { @@ -476,8 +431,8 @@ static bool __init vmware_legacy_x2apic_available(void) { uint32_t eax, ebx, ecx, edx; VMWARE_CMD(GETVCPU_INFO, eax, ebx, ecx, edx); - return !(eax & BIT(VMWARE_CMD_VCPU_RESERVED)) && - (eax & BIT(VMWARE_CMD_LEGACY_X2APIC)); + return !(eax & BIT(VCPU_RESERVED)) && + (eax & BIT(VCPU_LEGACY_X2APIC)); } #ifdef CONFIG_AMD_MEM_ENCRYPT From patchwork Fri Dec 1 23:24:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexey Makhalov X-Patchwork-Id: 13476603 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=vmware.com header.i=@vmware.com header.b="LuJdenvU" Received: from MW2PR02CU001.outbound.protection.outlook.com (mail-westus2azon11012013.outbound.protection.outlook.com [52.101.48.13]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6C971103; Fri, 1 Dec 2023 15:25:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=crg/T9eqrSGh5QBXe2jHqYD8FZn6+LHSYxFERPVNjpOnA+KW0UcKOw0FrGjNio2OU0qA1WQEuGco1DtoTEZXGqZVAzaqjgeaz2+uoNBjeKgLJlbsxtQ0h4sy8bwTdqs8sSVvjquWZqkfokSdWcVbC2mFNGK1fD3noRa/rFx88QZ46iuJmlrDIg+HO7NSbTkP/+b6zVGE659yGXgtQXjAj/jR5cVuv43JSqqjElivfGgtZ00ZTY0FbcrzqwpFExmy6uezRqgJtRGG9Y5GgHgky2mtjmTq6RZssL1s6k5y1719nrmiS0dGMzQ1r4bBX0y0XYNcjuihOALQglyPjtK6wQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=16Jiqcw4y5HDF4lK3qfi7xjzPgfVe2rKDSyYxNFchE4=; b=HJY5VcUDndI+QhjqXHqW/ZX017k2n4zmvjfF1XdZrhhkBa8zok/2R1eLnsWQFxWADyvhuo98mZ8smNg+IZDLzV/pJzjWmgRyWX2RirLhRZefyZS3wvJXj8P4bbTKzeepEhxIWB6KILTE4Hzv1VYSRowqLlUd5Jbku9MaZrx9Vp4Eyz5UrrvlWGBg6XsScwjUvOHNOIe+MWynxnawdsjzVvOKVGvCpJN/G4epmuCPtGWZ8XjS1o0czt1hlzK3gv6vZcEex3l32MVFhpWwWp1/d5C9cMhM5hgGEDpC/n9sYskWS/l4lBDnJoHUy3+CjjVkfk82Tc2AK66t+scNPXFHXw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=vmware.com; dmarc=pass action=none header.from=vmware.com; dkim=pass header.d=vmware.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vmware.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=16Jiqcw4y5HDF4lK3qfi7xjzPgfVe2rKDSyYxNFchE4=; b=LuJdenvUiv9BdWPUYBQ8dkWSNJRXC4VVewU5C6hbS6Rhar751PHkJVFH8nMAvEhQc28iKcDZiYB0SG8yXqGeYkZD1xwaUXlwSz0gQin1MwKNt5QLW6C6AQhRmMdY8zi/AP50SJq0cyBfnSk1P4ORZ1d9rfA65wNogmfJQlNC2Bk= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=vmware.com; Received: from MWHPR05MB3648.namprd05.prod.outlook.com (2603:10b6:301:45::23) by SJ0PR05MB7787.namprd05.prod.outlook.com (2603:10b6:a03:2e4::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7046.27; Fri, 1 Dec 2023 23:25:07 +0000 Received: from MWHPR05MB3648.namprd05.prod.outlook.com ([fe80::10f0:590a:708:4ad7]) by MWHPR05MB3648.namprd05.prod.outlook.com ([fe80::10f0:590a:708:4ad7%2]) with mapi id 15.20.7025.021; Fri, 1 Dec 2023 23:25:07 +0000 From: Alexey Makhalov To: linux-kernel@vger.kernel.org, virtualization@lists.linux.dev, hpa@zytor.com, dave.hansen@linux.intel.co, bp@alien8.d, 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 Subject: [PATCH v2 2/6] x86/vmware: Introduce vmware_hypercall API Date: Fri, 1 Dec 2023 15:24:48 -0800 Message-Id: <20231201232452.220355-3-amakhalov@vmware.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231201232452.220355-1-amakhalov@vmware.com> References: <20231122233058.185601-8-amakhalov@vmware.com> <20231201232452.220355-1-amakhalov@vmware.com> X-ClientProxiedBy: SJ2PR07CA0017.namprd07.prod.outlook.com (2603:10b6:a03:505::17) To MWHPR05MB3648.namprd05.prod.outlook.com (2603:10b6:301:45::23) Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MWHPR05MB3648:EE_|SJ0PR05MB7787:EE_ X-MS-Office365-Filtering-Correlation-Id: e9de836f-3e44-4ad1-2c85-08dbf2c4c154 X-LD-Processed: b39138ca-3cee-4b4a-a4d6-cd83d9dd62f0,ExtFwd,ExtAddr X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: iZXYon++i/r1ZzNXcHj1ANEHOBU/Kg3u40VP0iNYtHJe2jhECTyhKn9pmtN0lCEXaabwRK9zSzWQzcbhMHXKvEsUWEdvRZlGsdmEstorwRmfiBXpd4jnF55+aPkkxGrQMijefutc81wyZnaW0q4cLT9b+idreoYAHbkeWpgkIbS6GuWuWGUl3iBbW9wyuZF4CpA5pRWrNDmQjNha91cTkavPJTeyJrnmGwNnUeIOWA8CSX05GFuXtRP/e9QEgsvosfJ+yQtmtF0uP9+6N25rJlFTAgTyGMglM0H3RHhD8GeR0sfEIcOWX6WuGuHmXVPUkLMC2gPgbur+EWdwPP9pLyaKuwJvvT8Ksbd/Q+tLcBLQ5LTBY7ftFVnch17TID7QjA9fw3CzzWYRdOk9s4+C3tFe2tmxgxIgscMW+cCj4lOOWCiwdX2mW4QkuSSpl5aZsB8riaIxuXMQv3TnJRwCs8rv3FshshKE0No0ztVyaF13mXJQ5hgBVuoyLff/OnJy+W+55J54Aa1dlo5J/wL3yal0XiQLSr+0Mya8MIgxD9rM67cGLV9tPemLK2rj59zZDdKFgoMqDYYul8s8/lACKNrnCxtZrUW3D/YIFu91kwllt7gLik/29D4qvm8S9App4XPlRBLO1oYotSxXK+Wr4avmOlmGev+o2HpXHQut2CU= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:MWHPR05MB3648.namprd05.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(39860400002)(346002)(366004)(376002)(396003)(136003)(230922051799003)(451199024)(186009)(1800799012)(64100799003)(36756003)(8936002)(316002)(66556008)(66946007)(66476007)(8676002)(4326008)(478600001)(6486002)(41300700001)(2906002)(7416002)(86362001)(30864003)(5660300002)(38350700005)(38100700002)(2616005)(26005)(1076003)(6666004)(6506007)(52116002)(83380400001)(6512007);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: zJkTbv3UKpmFn2EF7wjjcsU22wiuAwwpUtrocCIQjhuStykoeYj0+UL6jEA+CU6Q8JXmINOkzM1FqNraeBQwq51qps9aVu21DYrs+LydoY1WkPoT/SnNyuETLn9i7YWOcuoQup589bfMdDf2WdVGVLAeoRFJxUzr9sq9kXkpYCNp4A+cRGK9o3yE8yJiz0VbdQioXAsMXjBs2bBVCRL7BkGHSr1Glx71v+JdPntShZYQWRMTOIHyZd5Ea9LLXaqOvIo/PPJH988+PtmuYZChUa6QHppNGz2SuEj2KfDGwUtMR4gUojALIo4wd47xXXo2e1rPCOkScktp84t4qHFLdk3PNa87rwPmw3p+zbFq1ruvslCz5GWAkcpUXBVLIhv4K7wX97BttHjLFVDNp2ADZ26epqKaPuaA5k9EILdgy9GlIve90Bw//HbIMWzkymPxxT22xOspCOIpSntWBWaWliY0S4LKEC9XK77g7yfK24SHUAbhuX1EQoUKf9KrU9MKpiiy0iC4/QxsFrmj/JqdAnsQiYLsWuWlrbjwOtZDiXsjbij/zb1dX1yR9k3qvBCFAKAm7oH/xA1IftBl/pleuOzQm1IAZaVBbd8uYyBKEoOMa/tj3z1H9MsQFAAdZ5aRfHy/mxWARIhvhfa3dM3dCBq2SB6YeHH9zzohBQJaE4V8qyyM2I+W615f34zPcSFWuoLlfFgimQ0fzeaAie/KzHC9qmEtJ1gyHbged58xPOoluEZEqYGY0mkyWG+sFQt6NLbGhfKggKxiZCxRJ/EQrZHj1Vf6IdLIAbkH07he2W0t9RpYeSwfznrho6VvqdhscajqTp5Wb2gzrIuhGV1drtK/PIKQuaEtVM+qKtQP0fpnW4B8C7ilLX6UaAcrRskRLrIaNiRV1CTtrmR4lgFONbSa0I027Cl6hLvvSqQonngpwInE9ix0f0Navcg6EfDmEsnhMPu886lTa1mXJr5t44JWl01vyZkjLGlY1GOsN36uEhKoejA0x4+TPv5h9U7IxA/mF1n3O6LiAOCDs//YYy4HfHRN8nxiULCUwHD1Lmrq9NtPUFI2EnGeUtnR//sFVhMOaS4ua+hsbFUq9rc0zQ7jU4dvfX76ZdsszUG/mQc6J88DIvVySktDepKzvk3nYPW+zaAfOkXmBWPkvbZfui84Df+h+zFLX5DKSzfU+u+s6S8IZw9+ydwCAAF/PMDdkZFi1DliPwPs+yyZd28KXNopsBRPbzY3oz8cuw6h0IH30PeX4/jlQed3Ku4sY4sh+2meKNVNXDDZMxfpgCWaPXv3AaaSd+3gqMF27m7kjSe4+UWBalvFMScwtANsotqoU+GBbsOcqGizYQEXQBkSvpyKvCDuGGUjgXk5S8V6IuO36eqIKYbva6f6c3bpN/jwncMRJZ8/vB0HksJIDamepYoEcTih2MA3mJZEhnQr3gw27APLX/HGHpLmHfeKrVkF6AfV+zQynVZa/cpdYypR+/6x2HXXNq8S6U9XzBBXUifWlByGaTGIABTn1IyydTsmyFd7YtTCJnUEK4QvV0iumkdZOkwz/U+C5BHcOwA4B9B/64fqccCRK5xBGXbraBub X-OriginatorOrg: vmware.com X-MS-Exchange-CrossTenant-Network-Message-Id: e9de836f-3e44-4ad1-2c85-08dbf2c4c154 X-MS-Exchange-CrossTenant-AuthSource: MWHPR05MB3648.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Dec 2023 23:25:07.7502 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: b39138ca-3cee-4b4a-a4d6-cd83d9dd62f0 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: fsFvB4jPwhNtb3SlHHZq9u9wXdFzDolKgQobd57Jx8+TPTs2uUYNMpzlt0h8Bw9eHjaBRPpPRM5AZtVQhaycUg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR05MB7787 Introducing vmware_hypercall family of functions as a common implementation to be used by the VMware guest code and virtual device drivers in architecture independent manner. By analogy with KVM hypercall API, vmware_hypercallX and vmware_hypercall_hb_{out,in} set of functions was added to achieve that. Architecture specific implementation should be 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 in VMWARE_HYPERCALL earlier during the boot when alternatives are not yet applied. This logic was inherited from VMWARE_CMD from the commit mentioned above. Default alternative code was optimized by size to reduce excessive nop alignment once alternatives are applied. Total default code size is 26 bytes, in worse case (3 bytes alternative) remaining 23 bytes will be aligned by only 3 long NOP instructions. Signed-off-by: Alexey Makhalov Reviewed-by: Nadav Amit Reviewed-by: Jeff Sipek --- arch/x86/include/asm/vmware.h | 262 ++++++++++++++++++++++++++-------- arch/x86/kernel/cpu/vmware.c | 35 ++--- 2 files changed, 220 insertions(+), 77 deletions(-) diff --git a/arch/x86/include/asm/vmware.h b/arch/x86/include/asm/vmware.h index 8cabf4a577bf..17091eba68cb 100644 --- a/arch/x86/include/asm/vmware.h +++ b/arch/x86/include/asm/vmware.h @@ -40,69 +40,219 @@ extern u8 vmware_hypercall_mode; -/* The low bandwidth call. The low word of edx is presumed clear. */ -#define VMWARE_HYPERCALL \ - ALTERNATIVE_2("movw $" __stringify(VMWARE_HYPERVISOR_PORT) ", %%dx; " \ - "inl (%%dx), %%eax", \ - "vmcall", X86_FEATURE_VMCALL, \ - "vmmcall", X86_FEATURE_VMW_VMMCALL) - /* - * The high bandwidth out call. The low word of edx is presumed to have the - * HB and OUT bits set. + * 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_HB_OUT \ - ALTERNATIVE_2("movw $" __stringify(VMWARE_HYPERVISOR_PORT_HB) ", %%dx; " \ - "rep outsb", \ +#define VMWARE_HYPERCALL \ + ALTERNATIVE_3("cmpb $" \ + __stringify(CPUID_VMWARE_FEATURES_ECX_VMMCALL) \ + ", %[mode]\n\t" \ + "jg 2f\n\t" \ + "je 1f\n\t" \ + "movw %[port], %%dx\n\t" \ + "inl (%%dx), %%eax\n\t" \ + "jmp 3f\n\t" \ + "1: vmmcall\n\t" \ + "jmp 3f\n\t" \ + "2: vmcall\n\t" \ + "3:\n\t", \ + "movw %[port], %%dx\n\t" \ + "inl (%%dx), %%eax", X86_FEATURE_HYPERVISOR, \ "vmcall", X86_FEATURE_VMCALL, \ "vmmcall", X86_FEATURE_VMW_VMMCALL) +static inline +unsigned long vmware_hypercall1(unsigned long cmd, unsigned long in1) +{ + unsigned long out0; + + asm_inline volatile (VMWARE_HYPERCALL + : "=a" (out0) + : [port] "i" (VMWARE_HYPERVISOR_PORT), + [mode] "m" (vmware_hypercall_mode), + "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, + uint32_t *out1, uint32_t *out2) +{ + unsigned long out0; + + asm_inline volatile (VMWARE_HYPERCALL + : "=a" (out0), "=b" (*out1), "=c" (*out2) + : [port] "i" (VMWARE_HYPERVISOR_PORT), + [mode] "m" (vmware_hypercall_mode), + "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, + uint32_t *out1, uint32_t *out2, + uint32_t *out3) +{ + unsigned long out0; + + asm_inline volatile (VMWARE_HYPERCALL + : "=a" (out0), "=b" (*out1), "=c" (*out2), "=d" (*out3) + : [port] "i" (VMWARE_HYPERVISOR_PORT), + [mode] "m" (vmware_hypercall_mode), + "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, uint32_t *out2) +{ + unsigned long out0; + + asm_inline volatile (VMWARE_HYPERCALL + : "=a" (out0), "=c" (*out2) + : [port] "i" (VMWARE_HYPERVISOR_PORT), + [mode] "m" (vmware_hypercall_mode), + "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, uint32_t *out2, + uint32_t *out3, uint32_t *out4, + uint32_t *out5) +{ + unsigned long out0; + + asm_inline volatile (VMWARE_HYPERCALL + : "=a" (out0), "=c" (*out2), "=d" (*out3), "=S" (*out4), + "=D" (*out5) + : [port] "i" (VMWARE_HYPERVISOR_PORT), + [mode] "m" (vmware_hypercall_mode), + "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, uint32_t *out1, + uint32_t *out2, uint32_t *out3) +{ + unsigned long out0; + + asm_inline volatile (VMWARE_HYPERCALL + : "=a" (out0), "=b" (*out1), "=c" (*out2), "=d" (*out3) + : [port] "i" (VMWARE_HYPERVISOR_PORT), + [mode] "m" (vmware_hypercall_mode), + "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_REG "%%rbp" +#define VMW_BP_CONSTRAINT "r" +#else +#define VMW_BP_REG "%%ebp" +#define VMW_BP_CONSTRAINT "m" +#endif + /* - * The high bandwidth in call. The low word of edx is presumed to have the - * HB bit set. + * 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 it memory encryption is set. + * This assumption simplifies HB hypercall impementation to just I/O port + * based approach without alternative patching. */ -#define VMWARE_HYPERCALL_HB_IN \ - ALTERNATIVE_2("movw $" __stringify(VMWARE_HYPERVISOR_PORT_HB) ", %%dx; " \ - "rep insb", \ - "vmcall", X86_FEATURE_VMCALL, \ - "vmmcall", X86_FEATURE_VMW_VMMCALL) +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, + uint32_t *out1) +{ + unsigned long out0; + + asm_inline volatile ( + UNWIND_HINT_SAVE + "push " VMW_BP_REG "\n\t" + UNWIND_HINT_UNDEFINED + "mov %[in6], " VMW_BP_REG "\n\t" + "rep outsb\n\t" + "pop " VMW_BP_REG "\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; +} + +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, + uint32_t *out1) +{ + unsigned long out0; -#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) + asm_inline volatile ( + UNWIND_HINT_SAVE + "push " VMW_BP_REG "\n\t" + UNWIND_HINT_UNDEFINED + "mov %[in6], " VMW_BP_REG "\n\t" + "rep insb\n\t" + "pop " VMW_BP_REG "\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_REG +#undef VMW_BP_CONSTRAINT +#undef VMWARE_HYPERCALL #endif diff --git a/arch/x86/kernel/cpu/vmware.c b/arch/x86/kernel/cpu/vmware.c index 4db8e1daa4a1..3aa1adaed18f 100644 --- a/arch/x86/kernel/cpu/vmware.c +++ b/arch/x86/kernel/cpu/vmware.c @@ -67,9 +67,10 @@ EXPORT_SYMBOL_GPL(vmware_hypercall_mode); static inline int __vmware_platform(void) { - uint32_t eax, ebx, ecx, edx; - VMWARE_CMD(GETVERSION, eax, ebx, ecx, edx); - return eax != (uint32_t)-1 && ebx == VMWARE_HYPERVISOR_MAGIC; + uint32_t eax, ebx, ecx; + + eax = vmware_hypercall3(VMWARE_CMD_GETVERSION, 0, &ebx, &ecx); + return eax != UINT_MAX && ebx == VMWARE_HYPERVISOR_MAGIC; } static unsigned long vmware_get_tsc_khz(void) @@ -121,21 +122,12 @@ static void __init vmware_cyc2ns_setup(void) pr_info("using clock offset of %llu ns\n", d->cyc2ns_offset); } -static int vmware_cmd_stealclock(uint32_t arg1, uint32_t arg2) +static int vmware_cmd_stealclock(uint32_t addr_hi, uint32_t addr_lo) { - uint32_t result, info; - - asm volatile (VMWARE_HYPERCALL : - "=a"(result), - "=c"(info) : - "a"(VMWARE_HYPERVISOR_MAGIC), - "b"(0), - "c"(VMWARE_CMD_STEALCLOCK), - "d"(0), - "S"(arg1), - "D"(arg2) : - "memory"); - return result; + uint32_t info; + + return vmware_hypercall5(VMWARE_CMD_STEALCLOCK, 0, 0, addr_hi, addr_lo, + &info); } static bool stealclock_enable(phys_addr_t pa) @@ -344,10 +336,10 @@ static void __init vmware_set_capabilities(void) static void __init vmware_platform_setup(void) { - uint32_t eax, ebx, ecx, edx; + uint32_t eax, ebx, ecx; uint64_t lpj, tsc_khz; - VMWARE_CMD(GETHZ, eax, ebx, ecx, edx); + eax = vmware_hypercall3(VMWARE_CMD_GETHZ, UINT_MAX, &ebx, &ecx); if (ebx != UINT_MAX) { lpj = tsc_khz = eax | (((uint64_t)ebx) << 32); @@ -429,8 +421,9 @@ static uint32_t __init vmware_platform(void) /* Checks if hypervisor supports x2apic without VT-D interrupt remapping. */ static bool __init vmware_legacy_x2apic_available(void) { - uint32_t eax, ebx, ecx, edx; - VMWARE_CMD(GETVCPU_INFO, eax, ebx, ecx, edx); + uint32_t eax; + + eax = vmware_hypercall1(VMWARE_CMD_GETVCPU_INFO, 0); return !(eax & BIT(VCPU_RESERVED)) && (eax & BIT(VCPU_LEGACY_X2APIC)); } From patchwork Fri Dec 1 23:24:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexey Makhalov X-Patchwork-Id: 13476600 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=vmware.com header.i=@vmware.com header.b="XBRX7jbI" Received: from CO1PR02CU001.outbound.protection.outlook.com (mail-westus2azon11011010.outbound.protection.outlook.com [52.101.47.10]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CE0661AD; Fri, 1 Dec 2023 15:25:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=kK+n8BnbJ3lEzU1v4eYkiqKlgou6fKoZmZhHqxPzsoA6Zf3896f6A9H2PI0/2ITlyRS+//QEEOmGFLrLNDtwbVRrbM0AlCCxe0tfIbXokpX387d0llGU7Q0DJ6qZwjJn5oUPRq5RVrfRW1CR5ui1u9bperPbvzKQMUfuNNiKH6wC9EIFZlMzbcOMEloNy0J2rFZLKcufLkGQwypW54GA2fscJOskv/tEZyP+o2tfnTW2ZanPn+rU6o3Y8wcWlFCEC64mR4XWdGkFES9En/hOHFU+3hpOzVJfl/3PWE2liAowHyigiZ8cHeCsRveAIRnpqLm+QjOLFgS26URhawB84Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=yQMnr6IIrr6r/3xHLijqfAqg6Qi305k2X4S6yputISE=; b=RasGtO2sHYgdD2qbMHqciQCgH5fLKPumunQ3c4eYe4UlL0u5xvjiiW+GqwIklxBzaLBDHaoPvHquV6TJHUg35W++ODT3JmorruCe6+o8odpPppjnsNrsgt5uWTJxETj30LfEbL1dyafXN5L5yvPAWfNH9jqSr4+9FEcqsXg8mokdTLJhudEx0VFypQcIMimhpouYSlGuG1C1dQhZzq1YvVp4vbZwk18ahR2J1/QmCgIUv/yF8YGO7VhmNWDIUjLBx+joYIHqH8p954hNbI0xuXmTGCeo58YMGwNUPJgYLKJpMP8UeTkowhrw4NXlWNqYyq7qwBY4JgrxIbrVVm6uIQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=vmware.com; dmarc=pass action=none header.from=vmware.com; dkim=pass header.d=vmware.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vmware.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=yQMnr6IIrr6r/3xHLijqfAqg6Qi305k2X4S6yputISE=; b=XBRX7jbIW4DkQ5qDuOVO8/tPOLBM1H29oOFVTMKOZggTsD3FwfHRcsbEjEqd7+QYzFAdOnruKeIguvXzsq5xYJa3yG/sukb9t0Zpv983JtlKSh4JrCMA09brBSxENiPaMFVQ8RruBAOozGBLwaR6z/BpQRLhz+EHgaXEhGif5io= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=vmware.com; Received: from MWHPR05MB3648.namprd05.prod.outlook.com (2603:10b6:301:45::23) by SJ0PR05MB7787.namprd05.prod.outlook.com (2603:10b6:a03:2e4::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7046.27; Fri, 1 Dec 2023 23:25:09 +0000 Received: from MWHPR05MB3648.namprd05.prod.outlook.com ([fe80::10f0:590a:708:4ad7]) by MWHPR05MB3648.namprd05.prod.outlook.com ([fe80::10f0:590a:708:4ad7%2]) with mapi id 15.20.7025.021; Fri, 1 Dec 2023 23:25:08 +0000 From: Alexey Makhalov To: linux-kernel@vger.kernel.org, virtualization@lists.linux.dev, hpa@zytor.com, dave.hansen@linux.intel.co, bp@alien8.d, 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 Subject: [PATCH v2 3/6] ptp/vmware: Use vmware_hypercall API Date: Fri, 1 Dec 2023 15:24:49 -0800 Message-Id: <20231201232452.220355-4-amakhalov@vmware.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231201232452.220355-1-amakhalov@vmware.com> References: <20231122233058.185601-8-amakhalov@vmware.com> <20231201232452.220355-1-amakhalov@vmware.com> X-ClientProxiedBy: SJ2PR07CA0017.namprd07.prod.outlook.com (2603:10b6:a03:505::17) To MWHPR05MB3648.namprd05.prod.outlook.com (2603:10b6:301:45::23) Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MWHPR05MB3648:EE_|SJ0PR05MB7787:EE_ X-MS-Office365-Filtering-Correlation-Id: 18e50ccc-7eba-4e90-37f3-08dbf2c4c202 X-LD-Processed: b39138ca-3cee-4b4a-a4d6-cd83d9dd62f0,ExtFwd,ExtAddr X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: jvNaZEq4Qok8L6voJiYOFPKpJzd+4r9/WqWqhvsh5/9XbEHUKtruasq/0N12+rhx1LKFzPhL0tH6oFuyWPFZD44zHMIEdVOvImX8spN01tFJ/6KchWsmuWv7Q4Bt9AACtBGvyhVwi3wLa0+A98xkdTzpI12dpzJznrlZATpTHg9Buc1kLNRaKPZXruP6zgEgsQFbt5EGThFvqYn5fc5efSQ3sX3svKcP1gm8Bnum1Z+saoHS3IE3RzG35BAzdrGDWC10Z5xHxJfil6JmsZNuOFXg5rm/XVOsLyTvW6AVANEKHvY17gDHNNZpqQFeaeXuAakJHyujRK5FcY2pTcX9s9SybCqxxR4NnkQGFwC1KjrBkkiV12BWY/6JbyBbv1PHFYA7wa8l7jCjBCu8tlN6hqByakufFrq2AgYkQBWaUrngph4rRchcpycBzyYJYYwilF4b42JzlXktglHllf1i/2YhU8UNXqmdkK+W6bj98j2+xcVq66xIKmEL5Gly+A2CXUZQWvj5IgaGMfLy0y7jTOhIIk1yT1Xm5TfLKtCNPvtcgeBcdru0zty8UWo+lXutwOz0a1BHBE7U/XO16Qd+S9+15YrZzezya88KGT89S1KoxnenEyOns+HIXY+Y8iEN71IK8T0iwnRQVoRjdx49nOSm9JaO5MGXmS8y/C+bQok= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:MWHPR05MB3648.namprd05.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(39860400002)(346002)(366004)(376002)(396003)(136003)(230922051799003)(451199024)(186009)(1800799012)(64100799003)(36756003)(8936002)(316002)(66556008)(66946007)(66476007)(8676002)(4326008)(478600001)(6486002)(41300700001)(2906002)(7416002)(86362001)(5660300002)(38350700005)(38100700002)(2616005)(26005)(1076003)(6666004)(6506007)(52116002)(83380400001)(6512007);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: TcQiiocl86W2OYPwgwwXFlHZclGMaWjx6ns+NfwwLbb8ROt+tJMEXoMBXGEn+9FgNGv/RgkkwdGJ3S7PgdzwXGK5JwlifxYmM+uuadjxSs8TeMWWS21tLkXgYwvAk8diIKO+xnNmqvqqojJRI100QwB68IodWWhWy6EKW45ZYUg/vwOc/2qCMZt1rWDKhD3u33CVx86hoD3a3OUi96VixDOGTgEdiawtzAODn9RKcwAsnTZmhvP5BjMg3SEQ6J/Ov+etH3uLj51e/hiDs77HfISHtpoY1n/1BwGdy4z+4DEq+fIVyGiXLSSqcIuQGcHtVlw4URcftk0hgjnJ7m1D0JTtL/zmNQToNH7ysQLAYsOFvqlbnY01XBoCNSdcmB7/rRi6pLWiLLKj3hKi/FLcmN7sZuAhdtTW0MxGZ7ScuxhnrY/cpMifhLOgn+PAny58on3L3ErxgzlaA6M6LLNWeo32snVim5o+lQNIkct362i8jiVQbLBv2/k1xnxU05+1OiGSyUywmYKeK/8G0e5AbhNUNmy90S3iQ45zgYnV3zUCVWjvsvhQz8lrZ+CbnAF/J2JUxZyEk9BpwR9M7ss+pdTX3J/eIxtPiKM48XtB5mgo2xDbcZhDb7hfVn5csVZVVQC/t3vWfkr3HAUKDj3hWxn7sWcH/tcEoFnVK9bGcDy6yfIbRkuiR51HPCUB6SQHW+QjZMyuarJ23DYJPwsS/DmPhTyk9lrVFgBTM3OAYr8vdMJHhhydo3h1vbT0aYyVLQYAN4Z6vUnoS4SWMwHktGfndDhTSPVRbysABe2giMgmvhfknTDtCEzp+s6RGkcm7pxlc4wRDK3RWy4nX6ovarJLrjwiXDb4Lz4rOzuenMEXByI03XmkM9Rzflo1h4BGgkrJlsajQvBHusaNP497X73T+pcT0yw6LBSJEtr5CDzMr+txiNM/gKYwdOpclottzpWN4j3DeR/tgxgxB8irvGaFxLkrOKY2NaWQDSXKgVMApnZZ865PwKYVQnEwkob0o+GrUhCtVqXXClMkw2iKmJq16+ifaySg0Ggq7oF+cJW7IbE864eDq29HVSRZbnmoY6MMiyeNxnW0Pdk57+tx7momPTcujHxzrpRiqfuzauY4InMYJBwTR5vXuI+qmipacs5haY2kS2jq0C9osT4dnonPR7OfwcLIlvIOWDWp/3Vxr8mQKvdPjXEt/MUAv2EQJ1EaTRZRewHbs+HKhYTmDrsNw5ocrdl6BqlTK5e/DlRdMQCpmB6ZstnyPRGn38qfvmlG2NB9fZ2JIMlGIQ3JFd6bU962RlKe4Q0fUtGOrwMTLDylPXRTd4Ji02u01bAhWsvGH6ipP/gjwtmtJzpLWc172mdnCIXScowjnc/iAGM4okUQ/Ex+7SotO8ufSz1hJKYzjBpehsFQ5Gq4nROaLCI3mnW/4ZYFY32XvQxkpteQl0+9UecGTLSke6Zd9JT8MdUe1F9XsHUvlfYcXntnHEqF3k1/I2Rf9LbpLuDlkJQ1EMUSuB/U/Pm0v5s/yFAkcE+RxUHAZY7+buu/2TVNAoLAE1/xQfhaa11BAyJctoJlfOB/2Egai/cInIp6AfES X-OriginatorOrg: vmware.com X-MS-Exchange-CrossTenant-Network-Message-Id: 18e50ccc-7eba-4e90-37f3-08dbf2c4c202 X-MS-Exchange-CrossTenant-AuthSource: MWHPR05MB3648.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Dec 2023 23:25:08.9204 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: b39138ca-3cee-4b4a-a4d6-cd83d9dd62f0 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: FVGT8+3/V/8HueJczbwYKpejP21NGaBGlwdZKNXx0Z2z5N8M7mRlU7zpGssDxenwzv+XbTS0RKx6JAomxWgNdQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR05MB7787 Switch from VMWARE_HYPERCALL macro to vmware_hypercall API. Eliminate arch specific code. No functional changes intended. Signed-off-by: Alexey Makhalov Reviewed-by: Nadav Amit Reviewed-by: Jeff Sipek --- drivers/ptp/ptp_vmw.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/drivers/ptp/ptp_vmw.c b/drivers/ptp/ptp_vmw.c index 27c5547aa8a9..e5bb521b9b82 100644 --- a/drivers/ptp/ptp_vmw.c +++ b/drivers/ptp/ptp_vmw.c @@ -14,7 +14,6 @@ #include #include -#define VMWARE_MAGIC 0x564D5868 #define VMWARE_CMD_PCLK(nr) ((nr << 16) | 97) #define VMWARE_CMD_PCLK_GETTIME VMWARE_CMD_PCLK(0) @@ -24,15 +23,10 @@ static struct ptp_clock *ptp_vmw_clock; static int ptp_vmw_pclk_read(u64 *ns) { - u32 ret, nsec_hi, nsec_lo, unused1, unused2, unused3; - - asm volatile (VMWARE_HYPERCALL : - "=a"(ret), "=b"(nsec_hi), "=c"(nsec_lo), "=d"(unused1), - "=S"(unused2), "=D"(unused3) : - "a"(VMWARE_MAGIC), "b"(0), - "c"(VMWARE_CMD_PCLK_GETTIME), "d"(0) : - "memory"); + u32 ret, nsec_hi, nsec_lo; + ret = vmware_hypercall3(VMWARE_CMD_PCLK_GETTIME, 0, + &nsec_hi, &nsec_lo); if (ret == 0) *ns = ((u64)nsec_hi << 32) | nsec_lo; return ret; From patchwork Fri Dec 1 23:24:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexey Makhalov X-Patchwork-Id: 13476601 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=vmware.com header.i=@vmware.com header.b="NxWwv+eE" Received: from CO1PR02CU001.outbound.protection.outlook.com (mail-westus2azon11011010.outbound.protection.outlook.com [52.101.47.10]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2A7D01A4; Fri, 1 Dec 2023 15:25:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=JWT4waEo1UjYw0WyNaUiRszgsm4GWvItIuHKrN6FXSKRHVSIdMSRbLd6jUlUeNmgzWO44jFFSeloerFByBcSVCKnH6jUr+eiWvG4LTthFrn78XYmo5NY3ZX2c5749yo0FXA+lIosQfQAtfzyGVePTccl6r1O25GH/4N2F5xhuu/n8iQeywk/OfqnqL+HYWnff4mAnlQCsyd54kMu/nRT0rtSfHezCl0qPS1bOoyqS6ezf2Rg+5A2CwrZ7HL2K82yBhMssqEf2sftSF/PO13eXf/miT5C8lqRn0an2yihBCJlQ0nDsZpuT/nj3oFsbiBFfOph4g9i9s1KT7YcOb/Shw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=mdkUc/pA38ALpvd6mjLBu7dvMz+DWcEcW0kh5so235U=; b=lHAwuohqYBf3Lik3Lak/C0hzWwPxKVH4A5ALumWGuq9Kyvc6CQJlmUJbjxCVYxbVwQl5ujFE21asGBl7217DcpfCqnbvpn46hOYUs1LHGPIJY4MGRdK6fBGhLy6apKhbLLwBufnvOsc6GcwssJjam0LxkCqo60vHOXbwnXgw6KVkLvBVlMPmqzF5ZhbPcE87KgM+7Q4Gp7iTqP9rf40bRxLOlv/FBl/M7CsXmo7t5Y2pF6YX36x7beaInNoaiSzZFfUwCuO+KsNugSL2VO+r+nHlj7AGKcPcNsK9W0oV6ErGFG9keYH9yzU3MUwnzjwtvDGk49S7DfED8yZYuYPc0w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=vmware.com; dmarc=pass action=none header.from=vmware.com; dkim=pass header.d=vmware.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vmware.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=mdkUc/pA38ALpvd6mjLBu7dvMz+DWcEcW0kh5so235U=; b=NxWwv+eEJPjlLCXmPcdf5yms49xrIWKONSsjhcONnY7mdLUybIHo0dA19B/hfMSuAxeMYJSVHwlaL3ts5anUpzf/WcPPto02meegq3jsX7SGAm5COdpq/MeOHacx7Panz9nU37SGxvTbAWHA59KZTgkTB7bt76O6ihaelYET8yc= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=vmware.com; Received: from MWHPR05MB3648.namprd05.prod.outlook.com (2603:10b6:301:45::23) by SJ0PR05MB7787.namprd05.prod.outlook.com (2603:10b6:a03:2e4::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7046.27; Fri, 1 Dec 2023 23:25:10 +0000 Received: from MWHPR05MB3648.namprd05.prod.outlook.com ([fe80::10f0:590a:708:4ad7]) by MWHPR05MB3648.namprd05.prod.outlook.com ([fe80::10f0:590a:708:4ad7%2]) with mapi id 15.20.7025.021; Fri, 1 Dec 2023 23:25:10 +0000 From: Alexey Makhalov To: linux-kernel@vger.kernel.org, virtualization@lists.linux.dev, hpa@zytor.com, dave.hansen@linux.intel.co, bp@alien8.d, 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 Subject: [PATCH v2 4/6] input/vmmouse: Use vmware_hypercall API Date: Fri, 1 Dec 2023 15:24:50 -0800 Message-Id: <20231201232452.220355-5-amakhalov@vmware.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231201232452.220355-1-amakhalov@vmware.com> References: <20231122233058.185601-8-amakhalov@vmware.com> <20231201232452.220355-1-amakhalov@vmware.com> X-ClientProxiedBy: SJ2PR07CA0017.namprd07.prod.outlook.com (2603:10b6:a03:505::17) To MWHPR05MB3648.namprd05.prod.outlook.com (2603:10b6:301:45::23) Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MWHPR05MB3648:EE_|SJ0PR05MB7787:EE_ X-MS-Office365-Filtering-Correlation-Id: 0775764e-2b44-4a7f-a5da-08dbf2c4c2b2 X-LD-Processed: b39138ca-3cee-4b4a-a4d6-cd83d9dd62f0,ExtFwd,ExtAddr X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: WaAYWmy8i6J66vkWjYSc6hVwgeRZJSSPwfvv390LaxFDd8kEdPwzaDaRrO0XVewReOM6n9bfp67AxgfXh+iKp9DVPVDDcboKmnGBtzNJ6J0A7I4cfO85htnmGIsjRmHOKkr6Ju1C7iB9c86kx0STTUPU9MzlKje5EW0OZ/5jDgf1ouUgP2LIN3a79XqU91EL4jjnZxcSQyxG3p/RPLsJeuWTX/IChI+IxofXq2ipZNChQq0b6Zz4xf68QLl7kQMrgY8YPhq5ayz/TKfak3WggUN3OsZrMvwPra1RFAgsJnq7qi3PBOt4GJGfT/xzUPWRuK/sk0no4c+0lb5EsDJMW0GNQFVq+Qa53sfd+zU68jcTu6SYAh/NIkTYXWG03pPeGIsLfSBCvPbOy+twwphWv//HgLTcTuTxyu051g+U62QtiF3XF4pKD/BE95y6R6qy4N9y929rcnhdJETOzKvwqELr69WNr2noYhSNDHXHIG+WDw5C5iqvsJQv0phlGuKeMy8iDnoiHPgTYPzpnMKmcOh38pEUqb2RXIphjNP8xn0xNXPjt2gmLKvWJyOjfIlBFWQrPsOG/3OLW170OuXl4p1esQcsbyKdsNLZYToj/WHPvI3hWpp2wdsFPQbjZZKjPUpR0dIqmpNteYKN6SYHEcYt5YEGkilP3qwsvcDbzZQ= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:MWHPR05MB3648.namprd05.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(39860400002)(346002)(366004)(376002)(396003)(136003)(230922051799003)(451199024)(186009)(1800799012)(64100799003)(36756003)(8936002)(316002)(66556008)(66946007)(66476007)(8676002)(4326008)(478600001)(6486002)(41300700001)(2906002)(7416002)(86362001)(5660300002)(38350700005)(38100700002)(2616005)(26005)(1076003)(6666004)(6506007)(52116002)(83380400001)(6512007);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 6EjP0s4EDY6jygLYOoM4tL6MANKAiNK2Xlu2SCwJdzttU5E9ndwtwyxVKKtuzSww+SK1qiprvXK1lKc0d3obOpPppiYJwsS+JKC4vHAa7f9i7Lqc99M+hj/DHX+2UBMoLdgflYb9oRb+Rk5olDdzUQ/1Qb3n8dtSHXxj2aEeRy2b1SXsG1Crb/d+e10i+u5mjtn/g8pRNvUv340VQwZsDO7IYXfTQrEeVawBCn481il3XcIBcRw0r0lvDjo2wNrZDRZp21Y8AgxpcW+uGXV7QgqcTzPtNEM/6WLqAeQep9N6CUp3HngDER0FW7nhkCZa5wZ9t6sYxNo7Xc8gUSFncPKDH0xVO8oOYYz9fzcbeZXqiI6Dzhp0FH194Ly5LkR3G0r8YKk59m0agy3AwQP+Iwc/iQe0j5y3xq7i/lQ3KxBsj3D7SAgWstPu/2PGZUESS5TBMEpJJ2O9V/T1SU4ziziK5aWMs9KGWnQmYDhuPEcD+k/LkvJmh7pumecOVKZvhua8AunJa+OnuKCaLQYAxohvwtAvNQsXWjZG2iLNQvcLkJtrRfc8uRf91A7urIApdL5hok+oNwN7FhQz69/8TqugMrDGiMHxjF7WbZRY6+1F58yygl6JiC/3ZFwYRRiJrItfuCZLBMWPFMQ2zvfaOYFWhB31YOeZq8vSNqpB7ab9C9YWHAvX3knBIW/XR5nMfMidlfiSPsZNodQbX99z0n3bEriFXPl8mxaBMKr1ojfRpCwFMb56deK8drhAZLUxUp8P6Z240klcW4JMOExpbxcNIlirsiuKysvmNc1ifok3dHDA8csVjmIavKvtw3tLrwGiVVt2yUCM6WnfGQCagym9KPg+6gHHkt71g/8Ze4tnUtXu5itDnal5yEri41splovV1cdlwYzdv5OP36TrUYo8XnMGjX7iDvUVIzjplRRgmGqobnQRxy+XtjTg3U5kjgjD9/2nmuv2CMdqpFWdEa/ZRF64aEEnthE3SL6mhQwcS4cHOHNr+bkYqwfO3NltEKtcugIs9a2gx1ILEfkVV4WccfVa47/wHH3nOozsYR/LhRMb+5wFfYy/8rEw1uEh6p94/lw3i7fi7JOwkz1IgGscphAXrC73lcIV8H+mUnpzJlzcgR/zAwrsSmVMrgQVSjI1UoNYJ9F5KftwMSGrm4qcPulJxQzszzBlutxqsJLqPmQC+Mzb0txra8ZbCa2HNpKioZtUaAVkEbydVqNIYXjZGqHEI2qI8reSUK1k68FqBRZXDvx9OqQrS1w4HOk7/k3+RDKL/VRQgtVFq9SDwYuGNCIyYFVFtY7qq80MwnCo2UbfR6b9PXDmSjP3Y8ZKAR72pOTyozbxzKyNtrxINJKa/hCICcf4i4BuCfDv7+p3xWR2gq8ZTbyYsXlUd1WkZUM1u+aGgBFQXy8HjNklNpMhpZdzrZfgzbBkNphRZokBpaZlHRYxiWw1xYwQt3974E+xTARv/5AE2us4zsPH5oiSf6O29i4jHKmhikWjUvYHeTrfq0yP4Ex2KrVAj2Xlp37VqjpJYqNty7Z7Nr30sT8x49WS0okwXPoDUzbnaThJ4f7VleOV0B7BSqmQNhPB X-OriginatorOrg: vmware.com X-MS-Exchange-CrossTenant-Network-Message-Id: 0775764e-2b44-4a7f-a5da-08dbf2c4c2b2 X-MS-Exchange-CrossTenant-AuthSource: MWHPR05MB3648.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Dec 2023 23:25:10.0449 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: b39138ca-3cee-4b4a-a4d6-cd83d9dd62f0 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: oi0Kv7qN5arCsQjnoY6eF1mfdjTMRJSTR3lNY6ps4WBUi3IKibVVr+kUF/zYoLNalTxebTvpOzoWk7GyX6g0mg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR05MB7787 Switch from VMWARE_HYPERCALL macro to vmware_hypercall API. Eliminate arch specific code. No functional changes intended. Signed-off-by: Alexey Makhalov Reviewed-by: Nadav Amit Reviewed-by: Zack Rusin Acked-by: Dmitry Torokhov --- drivers/input/mouse/vmmouse.c | 76 ++++++++++------------------------- 1 file changed, 22 insertions(+), 54 deletions(-) diff --git a/drivers/input/mouse/vmmouse.c b/drivers/input/mouse/vmmouse.c index ea9eff7c8099..fb1d986a6895 100644 --- a/drivers/input/mouse/vmmouse.c +++ b/drivers/input/mouse/vmmouse.c @@ -21,19 +21,16 @@ #include "psmouse.h" #include "vmmouse.h" -#define VMMOUSE_PROTO_MAGIC 0x564D5868U - /* * Main commands supported by the vmmouse hypervisor port. */ -#define VMMOUSE_PROTO_CMD_GETVERSION 10 -#define VMMOUSE_PROTO_CMD_ABSPOINTER_DATA 39 -#define VMMOUSE_PROTO_CMD_ABSPOINTER_STATUS 40 -#define VMMOUSE_PROTO_CMD_ABSPOINTER_COMMAND 41 -#define VMMOUSE_PROTO_CMD_ABSPOINTER_RESTRICT 86 +#define VMWARE_CMD_ABSPOINTER_DATA 39 +#define VMWARE_CMD_ABSPOINTER_STATUS 40 +#define VMWARE_CMD_ABSPOINTER_COMMAND 41 +#define VMWARE_CMD_ABSPOINTER_RESTRICT 86 /* - * Subcommands for VMMOUSE_PROTO_CMD_ABSPOINTER_COMMAND + * Subcommands for VMWARE_CMD_ABSPOINTER_COMMAND */ #define VMMOUSE_CMD_ENABLE 0x45414552U #define VMMOUSE_CMD_DISABLE 0x000000f5U @@ -76,28 +73,6 @@ struct vmmouse_data { char dev_name[128]; }; -/* - * Hypervisor-specific bi-directional communication channel - * implementing the vmmouse protocol. Should never execute on - * bare metal hardware. - */ -#define VMMOUSE_CMD(cmd, in1, out1, out2, out3, out4) \ -({ \ - unsigned long __dummy1, __dummy2; \ - __asm__ __volatile__ (VMWARE_HYPERCALL : \ - "=a"(out1), \ - "=b"(out2), \ - "=c"(out3), \ - "=d"(out4), \ - "=S"(__dummy1), \ - "=D"(__dummy2) : \ - "a"(VMMOUSE_PROTO_MAGIC), \ - "b"(in1), \ - "c"(VMMOUSE_PROTO_CMD_##cmd), \ - "d"(0) : \ - "memory"); \ -}) - /** * vmmouse_report_button - report button state on the correct input device * @@ -145,14 +120,12 @@ static psmouse_ret_t vmmouse_report_events(struct psmouse *psmouse) struct input_dev *abs_dev = priv->abs_dev; struct input_dev *pref_dev; u32 status, x, y, z; - u32 dummy1, dummy2, dummy3; unsigned int queue_length; unsigned int count = 255; while (count--) { /* See if we have motion data. */ - VMMOUSE_CMD(ABSPOINTER_STATUS, 0, - status, dummy1, dummy2, dummy3); + status = vmware_hypercall1(VMWARE_CMD_ABSPOINTER_STATUS, 0); if ((status & VMMOUSE_ERROR) == VMMOUSE_ERROR) { psmouse_err(psmouse, "failed to fetch status data\n"); /* @@ -172,7 +145,8 @@ static psmouse_ret_t vmmouse_report_events(struct psmouse *psmouse) } /* Now get it */ - VMMOUSE_CMD(ABSPOINTER_DATA, 4, status, x, y, z); + status = vmware_hypercall4(VMWARE_CMD_ABSPOINTER_DATA, 4, + &x, &y, &z); /* * And report what we've got. Prefer to report button @@ -247,14 +221,10 @@ static psmouse_ret_t vmmouse_process_byte(struct psmouse *psmouse) static void vmmouse_disable(struct psmouse *psmouse) { u32 status; - u32 dummy1, dummy2, dummy3, dummy4; - - VMMOUSE_CMD(ABSPOINTER_COMMAND, VMMOUSE_CMD_DISABLE, - dummy1, dummy2, dummy3, dummy4); - VMMOUSE_CMD(ABSPOINTER_STATUS, 0, - status, dummy1, dummy2, dummy3); + vmware_hypercall1(VMWARE_CMD_ABSPOINTER_COMMAND, VMMOUSE_CMD_DISABLE); + status = vmware_hypercall1(VMWARE_CMD_ABSPOINTER_STATUS, 0); if ((status & VMMOUSE_ERROR) != VMMOUSE_ERROR) psmouse_warn(psmouse, "failed to disable vmmouse device\n"); } @@ -271,26 +241,24 @@ static void vmmouse_disable(struct psmouse *psmouse) static int vmmouse_enable(struct psmouse *psmouse) { u32 status, version; - u32 dummy1, dummy2, dummy3, dummy4; /* * Try enabling the device. If successful, we should be able to * read valid version ID back from it. */ - VMMOUSE_CMD(ABSPOINTER_COMMAND, VMMOUSE_CMD_ENABLE, - dummy1, dummy2, dummy3, dummy4); + vmware_hypercall1(VMWARE_CMD_ABSPOINTER_COMMAND, VMMOUSE_CMD_ENABLE); /* * See if version ID can be retrieved. */ - VMMOUSE_CMD(ABSPOINTER_STATUS, 0, status, dummy1, dummy2, dummy3); + status = vmware_hypercall1(VMWARE_CMD_ABSPOINTER_STATUS, 0); if ((status & 0x0000ffff) == 0) { psmouse_dbg(psmouse, "empty flags - assuming no device\n"); return -ENXIO; } - VMMOUSE_CMD(ABSPOINTER_DATA, 1 /* single item */, - version, dummy1, dummy2, dummy3); + version = vmware_hypercall1(VMWARE_CMD_ABSPOINTER_DATA, + 1 /* single item */); if (version != VMMOUSE_VERSION_ID) { psmouse_dbg(psmouse, "Unexpected version value: %u vs %u\n", (unsigned) version, VMMOUSE_VERSION_ID); @@ -301,11 +269,11 @@ static int vmmouse_enable(struct psmouse *psmouse) /* * Restrict ioport access, if possible. */ - VMMOUSE_CMD(ABSPOINTER_RESTRICT, VMMOUSE_RESTRICT_CPL0, - dummy1, dummy2, dummy3, dummy4); + vmware_hypercall1(VMWARE_CMD_ABSPOINTER_RESTRICT, + VMMOUSE_RESTRICT_CPL0); - VMMOUSE_CMD(ABSPOINTER_COMMAND, VMMOUSE_CMD_REQUEST_ABSOLUTE, - dummy1, dummy2, dummy3, dummy4); + vmware_hypercall1(VMWARE_CMD_ABSPOINTER_COMMAND, + VMMOUSE_CMD_REQUEST_ABSOLUTE); return 0; } @@ -342,7 +310,7 @@ static bool vmmouse_check_hypervisor(void) */ int vmmouse_detect(struct psmouse *psmouse, bool set_properties) { - u32 response, version, dummy1, dummy2; + u32 response, version, type; if (!vmmouse_check_hypervisor()) { psmouse_dbg(psmouse, @@ -351,9 +319,9 @@ int vmmouse_detect(struct psmouse *psmouse, bool set_properties) } /* Check if the device is present */ - response = ~VMMOUSE_PROTO_MAGIC; - VMMOUSE_CMD(GETVERSION, 0, version, response, dummy1, dummy2); - if (response != VMMOUSE_PROTO_MAGIC || version == 0xffffffffU) + response = ~VMWARE_HYPERVISOR_MAGIC; + version = vmware_hypercall3(VMWARE_CMD_GETVERSION, 0, &response, &type); + if (response != VMWARE_HYPERVISOR_MAGIC || version == 0xffffffffU) return -ENXIO; if (set_properties) { From patchwork Fri Dec 1 23:24:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexey Makhalov X-Patchwork-Id: 13476604 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=vmware.com header.i=@vmware.com header.b="wFZjEral" Received: from CO1PR02CU001.outbound.protection.outlook.com (mail-westus2azon11011010.outbound.protection.outlook.com [52.101.47.10]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7DCB41A6; Fri, 1 Dec 2023 15:25:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=WVK9GvyT/R417zBrNA01oSU5fGv/9377ejab8o5OMw20ZjaLyRh7nS2Rc4btBaEEsBby+JX3euz4yMQHlrue9HKF2l4+OKvs/0aGoPtCYFY57ak6W5kBVhMwKA4j0bkQ1cFsOGkkb1WLhUkZeolUd1rMpHaT3lbxBNHSC5kzIcyNdkStPxdOhk7pCbb1Qc66b/zUhk8l6wp67A5uXB/oAypXwAInYnwFYtcYB+NvBpAZaNENzCt0P0jQk1oRo8L9TmXkHN8c0Dqh8lysnH0hGojySdLuqg5e0v7XirTOd9/rLcio4ARlb5t4B1bbgZgwLD1tMVlgoLiOMMT/NNofUg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=0qOQp4vCw1n/B0stHkNT+j5TQt26dX3fliNC93hQmv8=; b=V/As/qLIl9heVlG+xkHiV1ibep+fxHgu29QUmFamaUqZsI9rDE5+Mx3lxDc1PV+m0PaNReTblIx0UETMr/r14fl6mf1lD2qVJs7Hz6qA7FVV/XgDB89q6cyHBNt44DgnGwK8lR4CCjgvmZuPfXrBiEmebnhFQHxvic/N/cvWiF9OiQHT+c5tDfQYBwQnmovAa90xb98J/iAdtwqu1UGg+USkcnjHuAPtsePfNNIQENTUpPzQKOJvW7n3Uro5+3bOJQOR1zQsH1KG/iubSrXUOcA8MBXwp14RFMMDkHW18ohqhYB4IIxmZFfM7Z2bSpQcGmt3PWIwQLB30ESLPdp5Pw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=vmware.com; dmarc=pass action=none header.from=vmware.com; dkim=pass header.d=vmware.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vmware.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=0qOQp4vCw1n/B0stHkNT+j5TQt26dX3fliNC93hQmv8=; b=wFZjEral4YQ3cz9LDa+LZ4FVjiqtYFvenIQqSL8TfxDZAH0kjMYjWQfRfzoq1TC4mYvb34yfU1QhaFaV7MZ3sQMqq727rl57koOJ/MMiE/m/JckMqP2CyarrFTrhtm/ZD5ne/eMNW9zvhqEfjaBFVvlRMVvHveIJecSNkIdJjQY= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=vmware.com; Received: from MWHPR05MB3648.namprd05.prod.outlook.com (2603:10b6:301:45::23) by SJ0PR05MB7787.namprd05.prod.outlook.com (2603:10b6:a03:2e4::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7046.27; Fri, 1 Dec 2023 23:25:11 +0000 Received: from MWHPR05MB3648.namprd05.prod.outlook.com ([fe80::10f0:590a:708:4ad7]) by MWHPR05MB3648.namprd05.prod.outlook.com ([fe80::10f0:590a:708:4ad7%2]) with mapi id 15.20.7025.021; Fri, 1 Dec 2023 23:25:11 +0000 From: Alexey Makhalov To: linux-kernel@vger.kernel.org, virtualization@lists.linux.dev, hpa@zytor.com, dave.hansen@linux.intel.co, bp@alien8.d, 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 Subject: [PATCH v2 5/6] drm/vmwgfx: Use vmware_hypercall API Date: Fri, 1 Dec 2023 15:24:51 -0800 Message-Id: <20231201232452.220355-6-amakhalov@vmware.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231201232452.220355-1-amakhalov@vmware.com> References: <20231122233058.185601-8-amakhalov@vmware.com> <20231201232452.220355-1-amakhalov@vmware.com> X-ClientProxiedBy: SJ2PR07CA0017.namprd07.prod.outlook.com (2603:10b6:a03:505::17) To MWHPR05MB3648.namprd05.prod.outlook.com (2603:10b6:301:45::23) Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MWHPR05MB3648:EE_|SJ0PR05MB7787:EE_ X-MS-Office365-Filtering-Correlation-Id: 0b5d0077-0360-4de1-13b6-08dbf2c4c363 X-LD-Processed: b39138ca-3cee-4b4a-a4d6-cd83d9dd62f0,ExtFwd,ExtAddr X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 4o/ib0Z9oQcErNMbaNgQnZetEcnk30nu3h5vPGibtDEc8BnbtZ56YRjba31AbxfwfVlOTSJgnsexse3uUAB/Y8tGSWL3uuztcAASl0ZE7+jnnpldmIgnhOBxSy6fUcNfOmtbumOb3DQ4mSR1MnfDWn9gxy86gj6GPeeSAEzCDsV1R8DyNY8mcrvZZHyxWamKdaf2nPgFIqopehE6opcSb0SZj0op8CR5fb6M08aWNCMcjh0CsRPMCXYncPXt5dxpzEWCnrcxqdyAo5avlNvRhodgSSGAM2B1APTH9LfjIp6pRbBYT7wNrjXOdelcVLDpYNE0zZAxCRJKqmceWafbHexD3Yfw+ZZ4+3LZaYLO53y9osqPgIsvDp4eyJs8R135WBWSBu7s4ND8zeRcy+lX3Tk1kBV+5Hxmv+T2W3jcjVYpck1a0OUJT4Xbqzj1XCOCjgVpBFp6Cbi1O19hPUvmOFo/2mblZKviOUFTQ3funJw4Gt95UsCVfsZ24ufulWo5+0mISB9V1B00mtlxq75/W6YtQzrfUS5Dw9gY97vcI6WbRoaLhu30fYLCxwMc4otZo+jMVt8liyOe0irGlcXZFkSH4TxBkx4RnLQlipE2OYnzUykm5luD0ml11tozEpboiuJVSKIe23sFdgeqFD8Hf7YtcvtNHHeRBcGPvhbXU5I= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:MWHPR05MB3648.namprd05.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(39860400002)(346002)(366004)(376002)(396003)(136003)(230922051799003)(451199024)(186009)(1800799012)(64100799003)(36756003)(8936002)(316002)(66556008)(66946007)(66476007)(8676002)(4326008)(478600001)(6486002)(41300700001)(2906002)(7416002)(86362001)(30864003)(5660300002)(38350700005)(38100700002)(2616005)(26005)(1076003)(6666004)(6506007)(52116002)(83380400001)(6512007);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: xQt2OC3VMOussdwLC4XJKO+Mk52xeKlqcchmYRTXsnzilrriRtg8uyzCgoXBUxUPIBo+o00RdSsbMUIGRueQ0SwzJ8rU0XMassf5JBd2Mw5ovSXkdsKUT3o2oKXNa2qh499P66TOtY4eSRMOzeZu9SKdbRFfsA3ZITUu1/cF46q1QAy5/WM4h9eJo3IkkOub/iUUaMJFUVbhmUn/7thnlpVAwJfj06twpmxRsOTh0fjh0BLEC78Sbc7xih1j3D1CwnTczjgitEWactXNWRGfoMRsaicEW2/kl3TLYSNQ85E8Npa+EmqqwLVBOcOR9W5tXEPHyEu/Vp5cZdDQl8lpnzTCVFw4AfZ5kGjp2sr/0//X9mFURvWoHO0EvJ1QgHc4BcrYSkNQqoLCk6UZgAp7zny7ee0qeE1/6HXF9c5tU8aM2x4ZJQ3ykscbP7lZQ2jyNhcHHA2tXOCJDQoerbEUQJsJGM1gtL7kNZoUlIEDR17u7OBSPZWWVKfrONTtvmnoh4kVQdnTiQerOjfImayePl7P6uRHVI3Tt433xyuIINeTfN4hjwHw0K5FW8vjGS00rwkDFVz943YIGEA0+FP5I05ScOSxjNhKndg6/nGstAL8mGJHokKqAEyf+CJwp4Nwwn9wOsOGPhbd1tGP2hBblfuuQnr681kgVxU6tyM5ev70VF99X65yEDWoJo17eu81pKKcWtBm+PgWpRr0D+33Z/dvFAlsMIZ0JqOtuAv04NYP9QUxRSFPps4j/dJ+OLrz87nwRb55bcKCHDlQCeciEuASSWAZEvTKgA4iSdItF4b1j/YuxhCSQXit8XcsftQAc4edPZXCpNigd7BltTKiZ1nLdN2n/Dghe6fLUob72L8xB+AH7H87fdstATevNQpOd3gqyJy9nqmdZEJn3n8Xf4pDZ3SLL5uyhT8SuyWaVmRraL/OlqkUhZPnVj3nYEl124K0X7R03FySEet2oAWiHcws6GCLcjJDct+HdaalCCrZsX6UcUjnXX1xHlqMevX6vWAWtMCqeGJEjbpfDhz0I5KYZo0FPLoM30edpDdHS5wR2GhVQpwhjsBEP6EazBoHLzrHDRZDeMUv71li8Pk7q7xzBa1RluY97XSJAWOMAlGsnCtcIRgsTUUMZWO6iFX3qXiOZ2THjKCEanU9p5qwrBUsMqw3Iz+rrSFFys0NfMlH3RSBpnfz4IBKKJTlcn4P+dr5IaYhZ4ITcBp2vLR4FHs5Z6BLRKhQiZ/CCH/lrXTqLwH8geHdO0l6hhGt9a0ZQd7N4NpYVhEPj7Wh79QemIsf5fHD5C1QDibNrinxHsDj3d4th/KHuoUk/3scxYxCVTQeCgQENvaFVUiklXXXQDOC+WgE+lIQjoCdLdHVMaEAUodP0o1YSLBOvNo/3/b8r1vejqjDGPKZ7WrW6FhMW+aHrCfKy6PsayvxG80/bL/Vi0/Kigon88zBsYy+l61kAqKgRumEzAU8zxNcEyQZfVNVmFOVpEHI6yt4yb+hogzYm0VRo1xBxYx3p/va1B2+/9Z2cFm+QV79EU+TaJzHwprH8w0FTO//bQhj0s22LWIK1UnFiPxEh0quBBDwH+fj X-OriginatorOrg: vmware.com X-MS-Exchange-CrossTenant-Network-Message-Id: 0b5d0077-0360-4de1-13b6-08dbf2c4c363 X-MS-Exchange-CrossTenant-AuthSource: MWHPR05MB3648.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Dec 2023 23:25:11.1503 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: b39138ca-3cee-4b4a-a4d6-cd83d9dd62f0 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: qGu6ZjdOT12EyRk1WP0NkYSTP2kF8PAGjEtoOAwQrO8UWwpJg9jrQW1bG1f0WU9xQUFDHtkx2LNwBZu19jZbbQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR05MB7787 Switch from VMWARE_HYPERCALL macro to vmware_hypercall API. Eliminate arch specific code. drivers/gpu/drm/vmwgfx/vmwgfx_msg_arm64.h: implement arm64 variant of vmware_hypercall here for now. The move of these functions to arch/arm64/include/asm/vmware.h as well as removal of drivers/gpu/drm/vmwgfx/vmwgfx_msg_{x86,arm64}.h header files will be performed in the follow up patchset. Signed-off-by: Alexey Makhalov Reviewed-by: Nadav Amit Reviewed-by: Zack Rusin --- drivers/gpu/drm/vmwgfx/vmwgfx_msg.c | 173 +++++++------------ drivers/gpu/drm/vmwgfx/vmwgfx_msg_arm64.h | 197 +++++++++++++++------- drivers/gpu/drm/vmwgfx/vmwgfx_msg_x86.h | 185 -------------------- 3 files changed, 197 insertions(+), 358 deletions(-) diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_msg.c b/drivers/gpu/drm/vmwgfx/vmwgfx_msg.c index 2651fe0ef518..1f15990d3934 100644 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_msg.c +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_msg.c @@ -48,8 +48,6 @@ #define RETRIES 3 -#define VMW_HYPERVISOR_MAGIC 0x564D5868 - #define VMW_PORT_CMD_MSG 30 #define VMW_PORT_CMD_HB_MSG 0 #define VMW_PORT_CMD_OPEN_CHANNEL (MSG_TYPE_OPEN << 16 | VMW_PORT_CMD_MSG) @@ -104,20 +102,18 @@ static const char* const mksstat_kern_name_desc[MKSSTAT_KERN_COUNT][2] = */ static int vmw_open_channel(struct rpc_channel *channel, unsigned int protocol) { - unsigned long eax, ebx, ecx, edx, si = 0, di = 0; + u32 ecx, edx, esi, edi; - VMW_PORT(VMW_PORT_CMD_OPEN_CHANNEL, - (protocol | GUESTMSG_FLAG_COOKIE), si, di, - 0, - VMW_HYPERVISOR_MAGIC, - eax, ebx, ecx, edx, si, di); + vmware_hypercall6(VMW_PORT_CMD_OPEN_CHANNEL, + (protocol | GUESTMSG_FLAG_COOKIE), 0, + &ecx, &edx, &esi, &edi); if ((HIGH_WORD(ecx) & MESSAGE_STATUS_SUCCESS) == 0) return -EINVAL; channel->channel_id = HIGH_WORD(edx); - channel->cookie_high = si; - channel->cookie_low = di; + channel->cookie_high = esi; + channel->cookie_low = edi; return 0; } @@ -133,17 +129,13 @@ static int vmw_open_channel(struct rpc_channel *channel, unsigned int protocol) */ static int vmw_close_channel(struct rpc_channel *channel) { - unsigned long eax, ebx, ecx, edx, si, di; - - /* Set up additional parameters */ - si = channel->cookie_high; - di = channel->cookie_low; + u32 ecx; - VMW_PORT(VMW_PORT_CMD_CLOSE_CHANNEL, - 0, si, di, - channel->channel_id << 16, - VMW_HYPERVISOR_MAGIC, - eax, ebx, ecx, edx, si, di); + vmware_hypercall5(VMW_PORT_CMD_CLOSE_CHANNEL, + 0, channel->channel_id << 16, + channel->cookie_high, + channel->cookie_low, + &ecx); if ((HIGH_WORD(ecx) & MESSAGE_STATUS_SUCCESS) == 0) return -EINVAL; @@ -163,24 +155,18 @@ static int vmw_close_channel(struct rpc_channel *channel) static unsigned long vmw_port_hb_out(struct rpc_channel *channel, const char *msg, bool hb) { - unsigned long si, di, eax, ebx, ecx, edx; + u32 ebx, ecx; unsigned long msg_len = strlen(msg); /* HB port can't access encrypted memory. */ if (hb && !cc_platform_has(CC_ATTR_MEM_ENCRYPT)) { - unsigned long bp = channel->cookie_high; - u32 channel_id = (channel->channel_id << 16); - - si = (uintptr_t) msg; - di = channel->cookie_low; - - VMW_PORT_HB_OUT( + vmware_hypercall_hb_out( (MESSAGE_STATUS_SUCCESS << 16) | VMW_PORT_CMD_HB_MSG, - msg_len, si, di, - VMWARE_HYPERVISOR_HB | channel_id | - VMWARE_HYPERVISOR_OUT, - VMW_HYPERVISOR_MAGIC, bp, - eax, ebx, ecx, edx, si, di); + msg_len, + channel->channel_id << 16, + (uintptr_t) msg, channel->cookie_low, + channel->cookie_high, + &ebx); return ebx; } @@ -194,14 +180,13 @@ static unsigned long vmw_port_hb_out(struct rpc_channel *channel, memcpy(&word, msg, bytes); msg_len -= bytes; msg += bytes; - si = channel->cookie_high; - di = channel->cookie_low; - - VMW_PORT(VMW_PORT_CMD_MSG | (MSG_TYPE_SENDPAYLOAD << 16), - word, si, di, - channel->channel_id << 16, - VMW_HYPERVISOR_MAGIC, - eax, ebx, ecx, edx, si, di); + + vmware_hypercall5(VMW_PORT_CMD_MSG | + (MSG_TYPE_SENDPAYLOAD << 16), + word, channel->channel_id << 16, + channel->cookie_high, + channel->cookie_low, + &ecx); } return ecx; @@ -220,22 +205,17 @@ static unsigned long vmw_port_hb_out(struct rpc_channel *channel, static unsigned long vmw_port_hb_in(struct rpc_channel *channel, char *reply, unsigned long reply_len, bool hb) { - unsigned long si, di, eax, ebx, ecx, edx; + u32 ebx, ecx, edx; /* HB port can't access encrypted memory */ if (hb && !cc_platform_has(CC_ATTR_MEM_ENCRYPT)) { - unsigned long bp = channel->cookie_low; - u32 channel_id = (channel->channel_id << 16); - - si = channel->cookie_high; - di = (uintptr_t) reply; - - VMW_PORT_HB_IN( + vmware_hypercall_hb_in( (MESSAGE_STATUS_SUCCESS << 16) | VMW_PORT_CMD_HB_MSG, - reply_len, si, di, - VMWARE_HYPERVISOR_HB | channel_id, - VMW_HYPERVISOR_MAGIC, bp, - eax, ebx, ecx, edx, si, di); + reply_len, + channel->channel_id << 16, + channel->cookie_high, + (uintptr_t) reply, channel->cookie_low, + &ebx); return ebx; } @@ -245,14 +225,13 @@ static unsigned long vmw_port_hb_in(struct rpc_channel *channel, char *reply, while (reply_len) { unsigned int bytes = min_t(unsigned long, reply_len, 4); - si = channel->cookie_high; - di = channel->cookie_low; - - VMW_PORT(VMW_PORT_CMD_MSG | (MSG_TYPE_RECVPAYLOAD << 16), - MESSAGE_STATUS_SUCCESS, si, di, - channel->channel_id << 16, - VMW_HYPERVISOR_MAGIC, - eax, ebx, ecx, edx, si, di); + vmware_hypercall7(VMW_PORT_CMD_MSG | + (MSG_TYPE_RECVPAYLOAD << 16), + MESSAGE_STATUS_SUCCESS, + channel->channel_id << 16, + channel->cookie_high, + channel->cookie_low, + &ebx, &ecx, &edx); if ((HIGH_WORD(ecx) & MESSAGE_STATUS_SUCCESS) == 0) break; @@ -276,22 +255,18 @@ static unsigned long vmw_port_hb_in(struct rpc_channel *channel, char *reply, */ static int vmw_send_msg(struct rpc_channel *channel, const char *msg) { - unsigned long eax, ebx, ecx, edx, si, di; + u32 ebx, ecx; size_t msg_len = strlen(msg); int retries = 0; while (retries < RETRIES) { retries++; - /* Set up additional parameters */ - si = channel->cookie_high; - di = channel->cookie_low; - - VMW_PORT(VMW_PORT_CMD_SENDSIZE, - msg_len, si, di, - channel->channel_id << 16, - VMW_HYPERVISOR_MAGIC, - eax, ebx, ecx, edx, si, di); + vmware_hypercall5(VMW_PORT_CMD_SENDSIZE, + msg_len, channel->channel_id << 16, + channel->cookie_high, + channel->cookie_low, + &ecx); if ((HIGH_WORD(ecx) & MESSAGE_STATUS_SUCCESS) == 0) { /* Expected success. Give up. */ @@ -329,7 +304,7 @@ STACK_FRAME_NON_STANDARD(vmw_send_msg); static int vmw_recv_msg(struct rpc_channel *channel, void **msg, size_t *msg_len) { - unsigned long eax, ebx, ecx, edx, si, di; + u32 ebx, ecx, edx; char *reply; size_t reply_len; int retries = 0; @@ -341,15 +316,11 @@ static int vmw_recv_msg(struct rpc_channel *channel, void **msg, while (retries < RETRIES) { retries++; - /* Set up additional parameters */ - si = channel->cookie_high; - di = channel->cookie_low; - - VMW_PORT(VMW_PORT_CMD_RECVSIZE, - 0, si, di, - channel->channel_id << 16, - VMW_HYPERVISOR_MAGIC, - eax, ebx, ecx, edx, si, di); + vmware_hypercall7(VMW_PORT_CMD_RECVSIZE, + 0, channel->channel_id << 16, + channel->cookie_high, + channel->cookie_low, + &ebx, &ecx, &edx); if ((HIGH_WORD(ecx) & MESSAGE_STATUS_SUCCESS) == 0) { DRM_ERROR("Failed to get reply size for host message.\n"); @@ -384,16 +355,12 @@ static int vmw_recv_msg(struct rpc_channel *channel, void **msg, reply[reply_len] = '\0'; - - /* Ack buffer */ - si = channel->cookie_high; - di = channel->cookie_low; - - VMW_PORT(VMW_PORT_CMD_RECVSTATUS, - MESSAGE_STATUS_SUCCESS, si, di, - channel->channel_id << 16, - VMW_HYPERVISOR_MAGIC, - eax, ebx, ecx, edx, si, di); + vmware_hypercall5(VMW_PORT_CMD_RECVSTATUS, + MESSAGE_STATUS_SUCCESS, + channel->channel_id << 16, + channel->cookie_high, + channel->cookie_low, + &ecx); if ((HIGH_WORD(ecx) & MESSAGE_STATUS_SUCCESS) == 0) { kfree(reply); @@ -652,13 +619,7 @@ static inline void reset_ppn_array(PPN64 *arr, size_t size) */ static inline void hypervisor_ppn_reset_all(void) { - unsigned long eax, ebx, ecx, edx, si = 0, di = 0; - - VMW_PORT(VMW_PORT_CMD_MKSGS_RESET, - 0, si, di, - 0, - VMW_HYPERVISOR_MAGIC, - eax, ebx, ecx, edx, si, di); + vmware_hypercall1(VMW_PORT_CMD_MKSGS_RESET, 0); } /** @@ -669,13 +630,7 @@ static inline void hypervisor_ppn_reset_all(void) */ static inline void hypervisor_ppn_add(PPN64 pfn) { - unsigned long eax, ebx, ecx, edx, si = 0, di = 0; - - VMW_PORT(VMW_PORT_CMD_MKSGS_ADD_PPN, - (unsigned long)pfn, si, di, - 0, - VMW_HYPERVISOR_MAGIC, - eax, ebx, ecx, edx, si, di); + vmware_hypercall1(VMW_PORT_CMD_MKSGS_ADD_PPN, (unsigned long)pfn); } /** @@ -686,13 +641,7 @@ static inline void hypervisor_ppn_add(PPN64 pfn) */ static inline void hypervisor_ppn_remove(PPN64 pfn) { - unsigned long eax, ebx, ecx, edx, si = 0, di = 0; - - VMW_PORT(VMW_PORT_CMD_MKSGS_REMOVE_PPN, - (unsigned long)pfn, si, di, - 0, - VMW_HYPERVISOR_MAGIC, - eax, ebx, ecx, edx, si, di); + vmware_hypercall1(VMW_PORT_CMD_MKSGS_REMOVE_PPN, (unsigned long)pfn); } #if IS_ENABLED(CONFIG_DRM_VMWGFX_MKSSTATS) diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_msg_arm64.h b/drivers/gpu/drm/vmwgfx/vmwgfx_msg_arm64.h index 4f40167ad61f..29bd0af83038 100644 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_msg_arm64.h +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_msg_arm64.h @@ -34,6 +34,8 @@ #define VMWARE_HYPERVISOR_HB BIT(0) #define VMWARE_HYPERVISOR_OUT BIT(1) +#define VMWARE_HYPERVISOR_MAGIC 0x564D5868 + #define X86_IO_MAGIC 0x86 #define X86_IO_W7_SIZE_SHIFT 0 @@ -45,86 +47,159 @@ #define X86_IO_W7_IMM_SHIFT 5 #define X86_IO_W7_IMM_MASK (0xff << X86_IO_W7_IMM_SHIFT) -static inline void vmw_port(unsigned long cmd, unsigned long in_ebx, - unsigned long in_si, unsigned long in_di, - unsigned long flags, unsigned long magic, - unsigned long *eax, unsigned long *ebx, - unsigned long *ecx, unsigned long *edx, - unsigned long *si, unsigned long *di) +static inline +unsigned long vmware_hypercall1(unsigned long cmd, unsigned long in1) { - register u64 x0 asm("x0") = magic; - register u64 x1 asm("x1") = in_ebx; + register u64 x0 asm("x0") = VMWARE_HYPERVISOR_MAGIC; + register u64 x1 asm("x1") = in1; register u64 x2 asm("x2") = cmd; - register u64 x3 asm("x3") = flags | VMWARE_HYPERVISOR_PORT; - register u64 x4 asm("x4") = in_si; - register u64 x5 asm("x5") = in_di; + register u64 x3 asm("x3") = VMWARE_HYPERVISOR_PORT; + register u64 x7 asm("x7") = ((u64)X86_IO_MAGIC << 32) | + X86_IO_W7_WITH | + X86_IO_W7_DIR | + (2 << X86_IO_W7_SIZE_SHIFT); + asm_inline volatile ( + "mrs xzr, mdccsr_el0; " + : "+r" (x0) + : "r" (x1), "r" (x2), "r" (x3), "r" (x7) + : "memory"); + + return x0; +} + +static inline +unsigned long vmware_hypercall5(unsigned long cmd, unsigned long in1, + unsigned long in3, unsigned long in4, + unsigned long in5, uint32_t *out2) +{ + register u64 x0 asm("x0") = VMWARE_HYPERVISOR_MAGIC; + register u64 x1 asm("x1") = in1; + register u64 x2 asm("x2") = cmd; + register u64 x3 asm("x3") = in3 | VMWARE_HYPERVISOR_PORT; + register u64 x4 asm("x4") = in4; + register u64 x5 asm("x5") = in5; register u64 x7 asm("x7") = ((u64)X86_IO_MAGIC << 32) | X86_IO_W7_WITH | X86_IO_W7_DIR | (2 << X86_IO_W7_SIZE_SHIFT); - asm volatile("mrs xzr, mdccsr_el0 \n\t" - : "+r"(x0), "+r"(x1), "+r"(x2), - "+r"(x3), "+r"(x4), "+r"(x5) - : "r"(x7) - :); - *eax = x0; - *ebx = x1; - *ecx = x2; - *edx = x3; - *si = x4; - *di = x5; + asm_inline volatile ( + "mrs xzr, mdccsr_el0; " + : "+r" (x0), "+r" (x2) + : "r" (x1), "r" (x3), "r" (x4), "r" (x5), "r" (x7) + : "memory"); + + *out2 = x2; + return x0; } -static inline void vmw_port_hb(unsigned long cmd, unsigned long in_ecx, - unsigned long in_si, unsigned long in_di, - unsigned long flags, unsigned long magic, - unsigned long bp, u32 w7dir, - unsigned long *eax, unsigned long *ebx, - unsigned long *ecx, unsigned long *edx, - unsigned long *si, unsigned long *di) +static inline +unsigned long vmware_hypercall6(unsigned long cmd, unsigned long in1, + unsigned long in3, uint32_t *out2, + uint32_t *out3, uint32_t *out4, + uint32_t *out5) { - register u64 x0 asm("x0") = magic; + register u64 x0 asm("x0") = VMWARE_HYPERVISOR_MAGIC; + register u64 x1 asm("x1") = in1; + register u64 x2 asm("x2") = cmd; + register u64 x3 asm("x3") = in3 | VMWARE_HYPERVISOR_PORT; + register u64 x4 asm("x4"); + register u64 x5 asm("x5"); + register u64 x7 asm("x7") = ((u64)X86_IO_MAGIC << 32) | + X86_IO_W7_WITH | + X86_IO_W7_DIR | + (2 << X86_IO_W7_SIZE_SHIFT); + + asm_inline volatile ( + "mrs xzr, mdccsr_el0; " + : "+r" (x0), "+r" (x2), "+r" (x3), "=r" (x4), "=r" (x5) + : "r" (x1), "r" (x7) + : "memory"); + + *out2 = x2; + *out3 = x3; + *out4 = x4; + *out5 = x5; + return x0; +} + +static inline +unsigned long vmware_hypercall7(unsigned long cmd, unsigned long in1, + unsigned long in3, unsigned long in4, + unsigned long in5, uint32_t *out1, + uint32_t *out2, uint32_t *out3) +{ + register u64 x0 asm("x0") = VMWARE_HYPERVISOR_MAGIC; + register u64 x1 asm("x1") = in1; + register u64 x2 asm("x2") = cmd; + register u64 x3 asm("x3") = in3 | VMWARE_HYPERVISOR_PORT; + register u64 x4 asm("x4") = in4; + register u64 x5 asm("x5") = in5; + register u64 x7 asm("x7") = ((u64)X86_IO_MAGIC << 32) | + X86_IO_W7_WITH | + X86_IO_W7_DIR | + (2 << X86_IO_W7_SIZE_SHIFT); + + asm_inline volatile ( + "mrs xzr, mdccsr_el0; " + : "+r" (x0), "+r" (x1), "+r" (x2), "+r" (x3) + : "r" (x4), "r" (x5), "r" (x7) + : "memory"); + + *out1 = x1; + *out2 = x2; + *out3 = x3; + return x0; +} + +static inline +unsigned long vmware_hypercall_hb(unsigned long cmd, unsigned long in2, + unsigned long in3, unsigned long in4, + unsigned long in5, unsigned long in6, + uint32_t *out1, int dir) +{ + register u64 x0 asm("x0") = VMWARE_HYPERVISOR_MAGIC; register u64 x1 asm("x1") = cmd; - register u64 x2 asm("x2") = in_ecx; - register u64 x3 asm("x3") = flags | VMWARE_HYPERVISOR_PORT_HB; - register u64 x4 asm("x4") = in_si; - register u64 x5 asm("x5") = in_di; - register u64 x6 asm("x6") = bp; + register u64 x2 asm("x2") = in2; + register u64 x3 asm("x3") = in3 | VMWARE_HYPERVISOR_PORT_HB; + register u64 x4 asm("x4") = in4; + register u64 x5 asm("x5") = in5; + register u64 x6 asm("x6") = in6; register u64 x7 asm("x7") = ((u64)X86_IO_MAGIC << 32) | X86_IO_W7_STR | X86_IO_W7_WITH | - w7dir; - - asm volatile("mrs xzr, mdccsr_el0 \n\t" - : "+r"(x0), "+r"(x1), "+r"(x2), - "+r"(x3), "+r"(x4), "+r"(x5) - : "r"(x6), "r"(x7) - :); - *eax = x0; - *ebx = x1; - *ecx = x2; - *edx = x3; - *si = x4; - *di = x5; -} + dir; -#define VMW_PORT(cmd, in_ebx, in_si, in_di, flags, magic, eax, ebx, ecx, edx, \ - si, di) \ - vmw_port(cmd, in_ebx, in_si, in_di, flags, magic, &eax, &ebx, &ecx, \ - &edx, &si, &di) + asm_inline volatile ( + "mrs xzr, mdccsr_el0; " + : "+r" (x0), "+r" (x1) + : "r" (x2), "r" (x3), "r" (x4), "r" (x5), + "r" (x6), "r" (x7) + : "memory"); -#define VMW_PORT_HB_OUT(cmd, in_ecx, in_si, in_di, flags, magic, bp, eax, ebx, \ - ecx, edx, si, di) \ - vmw_port_hb(cmd, in_ecx, in_si, in_di, flags, magic, bp, \ - 0, &eax, &ebx, &ecx, &edx, &si, &di) + *out1 = x1; + return x0; +} -#define VMW_PORT_HB_IN(cmd, in_ecx, in_si, in_di, flags, magic, bp, eax, ebx, \ - ecx, edx, si, di) \ - vmw_port_hb(cmd, in_ecx, in_si, in_di, flags, magic, bp, \ - X86_IO_W7_DIR, &eax, &ebx, &ecx, &edx, &si, &di) +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, + uint32_t *out1) +{ + return vmware_hypercall_hb(cmd, in2, in3, in4, in5, in6, out1, 0); +} +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, + uint32_t *out1) +{ + return vmware_hypercall_hb(cmd, in2, in3, in4, in5, in6, out1, + X86_IO_W7_DIR); +} #endif #endif /* _VMWGFX_MSG_ARM64_H */ diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_msg_x86.h b/drivers/gpu/drm/vmwgfx/vmwgfx_msg_x86.h index 23899d743a90..13304d34cc6e 100644 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_msg_x86.h +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_msg_x86.h @@ -37,191 +37,6 @@ #include -/** - * Hypervisor-specific bi-directional communication channel. Should never - * execute on bare metal hardware. The caller must make sure to check for - * supported hypervisor before using these macros. - * - * The last two parameters are both input and output and must be initialized. - * - * @cmd: [IN] Message Cmd - * @in_ebx: [IN] Message Len, through EBX - * @in_si: [IN] Input argument through SI, set to 0 if not used - * @in_di: [IN] Input argument through DI, set ot 0 if not used - * @flags: [IN] hypercall flags + [channel id] - * @magic: [IN] hypervisor magic value - * @eax: [OUT] value of EAX register - * @ebx: [OUT] e.g. status from an HB message status command - * @ecx: [OUT] e.g. status from a non-HB message status command - * @edx: [OUT] e.g. channel id - * @si: [OUT] - * @di: [OUT] - */ -#define VMW_PORT(cmd, in_ebx, in_si, in_di, \ - flags, magic, \ - eax, ebx, ecx, edx, si, di) \ -({ \ - asm volatile (VMWARE_HYPERCALL : \ - "=a"(eax), \ - "=b"(ebx), \ - "=c"(ecx), \ - "=d"(edx), \ - "=S"(si), \ - "=D"(di) : \ - "a"(magic), \ - "b"(in_ebx), \ - "c"(cmd), \ - "d"(flags), \ - "S"(in_si), \ - "D"(in_di) : \ - "memory"); \ -}) - - -/** - * Hypervisor-specific bi-directional communication channel. Should never - * execute on bare metal hardware. The caller must make sure to check for - * supported hypervisor before using these macros. - * - * The last 3 parameters are both input and output and must be initialized. - * - * @cmd: [IN] Message Cmd - * @in_ecx: [IN] Message Len, through ECX - * @in_si: [IN] Input argument through SI, set to 0 if not used - * @in_di: [IN] Input argument through DI, set to 0 if not used - * @flags: [IN] hypercall flags + [channel id] - * @magic: [IN] hypervisor magic value - * @bp: [IN] - * @eax: [OUT] value of EAX register - * @ebx: [OUT] e.g. status from an HB message status command - * @ecx: [OUT] e.g. status from a non-HB message status command - * @edx: [OUT] e.g. channel id - * @si: [OUT] - * @di: [OUT] - */ -#ifdef __x86_64__ - -#define VMW_PORT_HB_OUT(cmd, in_ecx, in_si, in_di, \ - flags, magic, bp, \ - eax, ebx, ecx, edx, si, di) \ -({ \ - asm volatile ( \ - UNWIND_HINT_SAVE \ - "push %%rbp;" \ - UNWIND_HINT_UNDEFINED \ - "mov %12, %%rbp;" \ - VMWARE_HYPERCALL_HB_OUT \ - "pop %%rbp;" \ - UNWIND_HINT_RESTORE : \ - "=a"(eax), \ - "=b"(ebx), \ - "=c"(ecx), \ - "=d"(edx), \ - "=S"(si), \ - "=D"(di) : \ - "a"(magic), \ - "b"(cmd), \ - "c"(in_ecx), \ - "d"(flags), \ - "S"(in_si), \ - "D"(in_di), \ - "r"(bp) : \ - "memory", "cc"); \ -}) - - -#define VMW_PORT_HB_IN(cmd, in_ecx, in_si, in_di, \ - flags, magic, bp, \ - eax, ebx, ecx, edx, si, di) \ -({ \ - asm volatile ( \ - UNWIND_HINT_SAVE \ - "push %%rbp;" \ - UNWIND_HINT_UNDEFINED \ - "mov %12, %%rbp;" \ - VMWARE_HYPERCALL_HB_IN \ - "pop %%rbp;" \ - UNWIND_HINT_RESTORE : \ - "=a"(eax), \ - "=b"(ebx), \ - "=c"(ecx), \ - "=d"(edx), \ - "=S"(si), \ - "=D"(di) : \ - "a"(magic), \ - "b"(cmd), \ - "c"(in_ecx), \ - "d"(flags), \ - "S"(in_si), \ - "D"(in_di), \ - "r"(bp) : \ - "memory", "cc"); \ -}) - -#elif defined(__i386__) - -/* - * In the 32-bit version of this macro, we store bp in a memory location - * because we've ran out of registers. - * Now we can't reference that memory location while we've modified - * %esp or %ebp, so we first push it on the stack, just before we push - * %ebp, and then when we need it we read it from the stack where we - * just pushed it. - */ -#define VMW_PORT_HB_OUT(cmd, in_ecx, in_si, in_di, \ - flags, magic, bp, \ - eax, ebx, ecx, edx, si, di) \ -({ \ - asm volatile ("push %12;" \ - "push %%ebp;" \ - "mov 0x04(%%esp), %%ebp;" \ - VMWARE_HYPERCALL_HB_OUT \ - "pop %%ebp;" \ - "add $0x04, %%esp;" : \ - "=a"(eax), \ - "=b"(ebx), \ - "=c"(ecx), \ - "=d"(edx), \ - "=S"(si), \ - "=D"(di) : \ - "a"(magic), \ - "b"(cmd), \ - "c"(in_ecx), \ - "d"(flags), \ - "S"(in_si), \ - "D"(in_di), \ - "m"(bp) : \ - "memory", "cc"); \ -}) - - -#define VMW_PORT_HB_IN(cmd, in_ecx, in_si, in_di, \ - flags, magic, bp, \ - eax, ebx, ecx, edx, si, di) \ -({ \ - asm volatile ("push %12;" \ - "push %%ebp;" \ - "mov 0x04(%%esp), %%ebp;" \ - VMWARE_HYPERCALL_HB_IN \ - "pop %%ebp;" \ - "add $0x04, %%esp;" : \ - "=a"(eax), \ - "=b"(ebx), \ - "=c"(ecx), \ - "=d"(edx), \ - "=S"(si), \ - "=D"(di) : \ - "a"(magic), \ - "b"(cmd), \ - "c"(in_ecx), \ - "d"(flags), \ - "S"(in_si), \ - "D"(in_di), \ - "m"(bp) : \ - "memory", "cc"); \ -}) -#endif /* defined(__i386__) */ - #endif /* defined(__i386__) || defined(__x86_64__) */ #endif /* _VMWGFX_MSG_X86_H */ From patchwork Fri Dec 1 23:24:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexey Makhalov X-Patchwork-Id: 13476599 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=vmware.com header.i=@vmware.com header.b="YWONjgkj" Received: from MW2PR02CU001.outbound.protection.outlook.com (mail-westus2azon11012013.outbound.protection.outlook.com [52.101.48.13]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DAC88F4; Fri, 1 Dec 2023 15:25:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=l+vRhlaBFLqe9flKDM3ZXQqTFLsA0kCBoiG3wg1xXyEG2jUyTh5aReHaXQFDrpzPLVy82NjsItlm1NZUDKIysrl7LtM6qXQMgeL26YmDzVwT8hiTY2zNOfz9LakVMbCd6CvzjjsaSKsVr+8OZZjwh2WbUJVBlmBTMo2zCsHst3Vy479wq98gd2iq13qjZjydW/nPPhFqte/UhdC4dzB7J7PXK7/LNl/5XzWx12CGZMy9lr3mQFT+VLZMBHW8LIpik2LGogfEXT9zR2qVjdwQSchXSBKYEwiOIMIeK94xUC3uUOFZoWSCkkjp2KsNTff41SToxs0FHTR6cfY96IELnA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=DnvCXNRaNSyI9Q+GsIxdfvkjsqqBUgxzGsmIWEDF5QE=; b=BYX6/wZfResrSL688LZgXo6VDuag4GZc80VQzJfZ7W5OFZt94fW2tRFEFQyLQ68OGE3MsVRBNARODiPFUHj5l2Jxx7rCJXZCG/hT2RyYVoTL5ZdKniojipIVx4I3r2L77a0LYuEe1/obdwhaiTQM7FZ798QM7VHNdECg+IArbyQ1pfgF72u9RTvTQ4I27GSV+hhl/5LejLnTwUUgMw5wGkCM0mm5TUqg4BVgtyKp7xkkGvw4M0/sZzx7LYZrhVULcBXu2WMDETg6ta4FFFzxuEEAR1KGNyqLKLD65xAA1b+PAOGpbiQdKuPDLY6jSOYJQxfK0np1PRVpP+IptDnFwg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=vmware.com; dmarc=pass action=none header.from=vmware.com; dkim=pass header.d=vmware.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vmware.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=DnvCXNRaNSyI9Q+GsIxdfvkjsqqBUgxzGsmIWEDF5QE=; b=YWONjgkjlorV3rJcwilKkM1Zv5gaRfv7Q0vK41CHeYzMytJ4gHsGoKM+erKQERac90ti05QZZof6RdKXd+JMn3Qj53PRL6AEy3Z0RAfOpChh/wVykPE+XtP/yVrXioKqad5Dvn1MOEr+wC+OCK9w+a+atOEJxf4azBBpZrrE8Nk= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=vmware.com; Received: from MWHPR05MB3648.namprd05.prod.outlook.com (2603:10b6:301:45::23) by SJ0PR05MB7787.namprd05.prod.outlook.com (2603:10b6:a03:2e4::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7046.27; Fri, 1 Dec 2023 23:25:12 +0000 Received: from MWHPR05MB3648.namprd05.prod.outlook.com ([fe80::10f0:590a:708:4ad7]) by MWHPR05MB3648.namprd05.prod.outlook.com ([fe80::10f0:590a:708:4ad7%2]) with mapi id 15.20.7025.021; Fri, 1 Dec 2023 23:25:12 +0000 From: Alexey Makhalov To: linux-kernel@vger.kernel.org, virtualization@lists.linux.dev, hpa@zytor.com, dave.hansen@linux.intel.co, bp@alien8.d, 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 Subject: [PATCH v2 6/6] x86/vmware: Add TDX hypercall support Date: Fri, 1 Dec 2023 15:24:52 -0800 Message-Id: <20231201232452.220355-7-amakhalov@vmware.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231201232452.220355-1-amakhalov@vmware.com> References: <20231122233058.185601-8-amakhalov@vmware.com> <20231201232452.220355-1-amakhalov@vmware.com> X-ClientProxiedBy: SJ2PR07CA0017.namprd07.prod.outlook.com (2603:10b6:a03:505::17) To MWHPR05MB3648.namprd05.prod.outlook.com (2603:10b6:301:45::23) Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MWHPR05MB3648:EE_|SJ0PR05MB7787:EE_ X-MS-Office365-Filtering-Correlation-Id: 08de7b74-f127-42ac-95cf-08dbf2c4c407 X-LD-Processed: b39138ca-3cee-4b4a-a4d6-cd83d9dd62f0,ExtFwd,ExtAddr X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ImnGLxS+aveyw1T9XXfBa6xuPwFu8a7McVUhVD0P7yagd24DLNwiRpKsNRPaGW3Z83h0PeUibaznS4mg6dqbU6nVdXhWzhc3mLLJFaXxl2HeyXy3a4UNWfKD74Y1MqTqrak8N23OkjqQ382QUyfbemq2B9XBesZ14HLdBXfKUNp9ARX+8wS4gPf5yYB3oXHzu+IoC1j2ZiGRX/xDmyBwExTfoj6H1ddIBdf7o+WVgjKjyJXG750nKVmYGO3FdJZHeyWmYSw27R6HIMG2t+9CrGiScn+gVJVc2Gn2Q/ghj8sat+UxR58mAzsLCs2/zksgE8E90gpA7fewR6TKpJCTbO50/sDhw2XnN8m1ovFmjfcxLISQB6YrkIBuOZYz7PuHbxeJt6fsR3uwK9rFGg9awTUr9yRRElvRlQziA0/tT8pVFQ22dThT/HWio/NP/S8cq2V/WnU5/YFqKCI3bja65IS1iqvvsD5O9JxDxMsmsrpS1dbVoAn8D6nrTemL8hxrBAFlq7PBpXxunbCtj/7Lb00jJLOQLWOXwWBXN9SI7L+6aYYQbSCPntqARv+nZZgucdvQsaVc48xtrty2UQYQk2B4JBYPApfLGFI3ekXQtZZw+Gl7bmdFLvLN2lt2AAHM+tAWC+H6EW70cMdufX2XaUjmACUTjI0BsY3C3+75wd0= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:MWHPR05MB3648.namprd05.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(39860400002)(346002)(366004)(376002)(396003)(136003)(230922051799003)(451199024)(186009)(1800799012)(64100799003)(36756003)(8936002)(316002)(66556008)(66946007)(66476007)(8676002)(4326008)(478600001)(6486002)(41300700001)(2906002)(7416002)(86362001)(5660300002)(38350700005)(38100700002)(2616005)(26005)(1076003)(6666004)(6506007)(52116002)(6512007);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: G4kT+4q+8Cpn+A933JEKyFep+x+ivgCQGmBflVcW4ePD1d4HQyy4Ct87/6fpY1I2BYfIML2ij0m6oV5LvLcsZN1JiiiLTcrMuHO0vlPPAxXn4obZIB+fN+B9Q7UTC1EC9uYbc/8HeJ7KN0Ds1oBRteVJUYJSs+/xFylDjHuP3zG/6GE5CcIBy9W5GNHbQWgUCGupGetbnGEIkU8e8ogesJxgp0WtrQmn/W3qyQ64GDPqMC6YoxN/4iLcOQ6JRcUdpAmVNvBOVQ4fwvGB05D4pjpJjAkgbTeTre+zFoj5vm32tK78ESnLF9X6aq1PNGV9CzRH6DwW1yHoIXMiBlzBPRMy5nGRr16tNRL9DRdHEvkbUmfKnYHhhKAYcd+Jskf+HhhGHXAIQ62VTbg7EgPC+3806woE2/Ru5jbyO7NZ/tpwu2/j76Do+9jUIPbfs348h8EzA061sl/a9kikLHe4UGbHV40jWFYREKvWUgAKBeTW+a7D17960C3HgWuoplbB41z+rGJh98RSF9N3yaRI2v0Yt0qyC6PgryjgbxaDKS2nSqeTb3EFZO6pdRIFA0JSxRXeQyoTpdJKI0dOv75QXEV4KzJ4n/tyb83XzJTT+cS1RZijsKcpjaiFxriTD/U7VyizD8V7l9gbX/gXYBUZE99VtJhOpAfVHNLw7UR+J18oYfHy5roVcXlI3Wy9/DYCHnJI+KhyMmjFcWCGubbOYkhUXadL5E/ZDCSGs6ttRHouveinlE+/zrj2EO07m1UD5DF8xtzgDZp0+HvAbIyo49bK3VIzQtoQeIxzIBkQUhFdhcfRmQWJKfrY8AasyEEo+qI7E+t3GvSNBZqYtqjH1+GNWxddXd4F1hdWSP435lgn0f+sq53eS+/pLSUVBosI9K2/FxN50dOEZJN7htjVTHNKVk6iuKlZLCMPZslPJ2GOxoaLQ6FTOJeSBgfcktLWNUyCg8+/QQraO74xfkCdiT3K3wS83xvxHKsvE+VwGhXpR3TNKX3Mv2Hga9hC2rHCLZPKJMmpHQ3hpllROYh84jn6hh/FW+OtU8zMP3cOAqbtctBnrrja8PGX4C38UZq1CxepspZP78QR6XiUn/8O7PYi09YZLaXqdOTxXyWuobj8mOevlHrVbZkSTJoPJy3EUPdl4WTxP03zOykZRdUILbFvIh59xyQQZYwZ/8JJivtSakY3iKxKCmzBMamBpOlOFYM18G2UDufSl+riwrV3CLfsxahr/+WEbo6m0I3JnqAWxXDIGaGicLjDBrW8mzPz8PFj23P6zuPCOVwMLXOgJGG6EU4wYKz7nNN7ENBLZyLSYPKmNna4an5J6HLWGghuIV+VxJ+AEU8mlhoMeKY+yIVS1a/jpSrSoawjBwhIgSpLW2Jq+FNFjbq9TVAEIxtelASyU/76ouITHX0IfCDsgc2018E2VLlhgRFmDh9Kw4/1fgwp11ot3TvSYJ98SUPPoiZFxv9WZ09PQKi89ttedSFMNHh4kWiAeMgojA5LtPCm+Xu6JGEKpPoPI6Q/o16x6qG3nBOcXZvm2NWlH2b4rDjL8LmODyI9Lr1T7kt6zzNs69ySJPEdvGxQeGr/Nldb X-OriginatorOrg: vmware.com X-MS-Exchange-CrossTenant-Network-Message-Id: 08de7b74-f127-42ac-95cf-08dbf2c4c407 X-MS-Exchange-CrossTenant-AuthSource: MWHPR05MB3648.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Dec 2023 23:25:12.2320 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: b39138ca-3cee-4b4a-a4d6-cd83d9dd62f0 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: PCc2TZpunx7Fak09pEewKMNlZBcwTnYKrnhRnKoZCHXbGgZE8NnH5s61s4wS7ZikOiyaK6MMMeLTzT1xSrGekQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR05MB7787 VMware hypercalls use I/O port, VMCALL or VMMCALL instructions. Add __tdx_hypercall path to support TDX guests. No change in high bandwidth hypercalls, as only low bandwidth ones are supported for TDX guests. Co-developed-by: Tim Merrifield Signed-off-by: Tim Merrifield Signed-off-by: Alexey Makhalov Reviewed-by: Nadav Amit --- arch/x86/include/asm/vmware.h | 72 +++++++++++++++++++++++++++++++++++ arch/x86/kernel/cpu/vmware.c | 9 +++++ 2 files changed, 81 insertions(+) diff --git a/arch/x86/include/asm/vmware.h b/arch/x86/include/asm/vmware.h index 17091eba68cb..cd58ff8ef1af 100644 --- a/arch/x86/include/asm/vmware.h +++ b/arch/x86/include/asm/vmware.h @@ -40,6 +40,54 @@ extern u8 vmware_hypercall_mode; +#define VMWARE_TDX_VENDOR_LEAF 0x1AF7E4909ULL +#define VMWARE_TDX_HCALL_FUNC 1 + +extern void vmware_tdx_hypercall_args(struct tdx_module_args *args); + +/* + * TDCALL[TDG.VP.VMCALL] uses rax (arg0) and rcx (arg2), while the use of + * rbp (arg6) is discouraged by the TDX specification. Therefore, we + * remap those registers to r12, r13 and r14, respectively. + */ +static inline +unsigned long vmware_tdx_hypercall(unsigned long cmd, unsigned long in1, + unsigned long in3, unsigned long in4, + unsigned long in5, unsigned long in6, + uint32_t *out1, uint32_t *out2, + uint32_t *out3, uint32_t *out4, + uint32_t *out5, uint32_t *out6) +{ + struct tdx_module_args args = { + .r10 = VMWARE_TDX_VENDOR_LEAF, + .r11 = VMWARE_TDX_HCALL_FUNC, + .r12 = VMWARE_HYPERVISOR_MAGIC, + .r13 = cmd, + .rbx = in1, + .rdx = in3, + .rsi = in4, + .rdi = in5, + .r14 = in6, + }; + + vmware_tdx_hypercall_args(&args); + + if (out1) + *out1 = args.rbx; + if (out2) + *out2 = args.r13; + if (out3) + *out3 = args.rdx; + if (out4) + *out4 = args.rsi; + if (out5) + *out5 = args.rdi; + if (out6) + *out6 = args.r14; + + return args.r12; +} + /* * 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. @@ -67,6 +115,10 @@ unsigned long vmware_hypercall1(unsigned long cmd, unsigned long in1) { unsigned long out0; + if (cpu_feature_enabled(X86_FEATURE_TDX_GUEST)) + return vmware_tdx_hypercall(cmd, in1, 0, 0, 0, 0, NULL, NULL, + NULL, NULL, NULL, NULL); + asm_inline volatile (VMWARE_HYPERCALL : "=a" (out0) : [port] "i" (VMWARE_HYPERVISOR_PORT), @@ -85,6 +137,10 @@ unsigned long vmware_hypercall3(unsigned long cmd, unsigned long in1, { unsigned long out0; + if (cpu_feature_enabled(X86_FEATURE_TDX_GUEST)) + return vmware_tdx_hypercall(cmd, in1, 0, 0, 0, 0, out1, out2, + NULL, NULL, NULL, NULL); + asm_inline volatile (VMWARE_HYPERCALL : "=a" (out0), "=b" (*out1), "=c" (*out2) : [port] "i" (VMWARE_HYPERVISOR_PORT), @@ -104,6 +160,10 @@ unsigned long vmware_hypercall4(unsigned long cmd, unsigned long in1, { unsigned long out0; + if (cpu_feature_enabled(X86_FEATURE_TDX_GUEST)) + return vmware_tdx_hypercall(cmd, in1, 0, 0, 0, 0, out1, out2, + out3, NULL, NULL, NULL); + asm_inline volatile (VMWARE_HYPERCALL : "=a" (out0), "=b" (*out1), "=c" (*out2), "=d" (*out3) : [port] "i" (VMWARE_HYPERVISOR_PORT), @@ -123,6 +183,10 @@ unsigned long vmware_hypercall5(unsigned long cmd, unsigned long in1, { unsigned long out0; + if (cpu_feature_enabled(X86_FEATURE_TDX_GUEST)) + return vmware_tdx_hypercall(cmd, in1, in3, in4, in5, 0, NULL, + out2, NULL, NULL, NULL, NULL); + asm_inline volatile (VMWARE_HYPERCALL : "=a" (out0), "=c" (*out2) : [port] "i" (VMWARE_HYPERVISOR_PORT), @@ -145,6 +209,10 @@ unsigned long vmware_hypercall6(unsigned long cmd, unsigned long in1, { unsigned long out0; + if (cpu_feature_enabled(X86_FEATURE_TDX_GUEST)) + return vmware_tdx_hypercall(cmd, in1, in3, 0, 0, 0, NULL, out2, + out3, out4, out5, NULL); + asm_inline volatile (VMWARE_HYPERCALL : "=a" (out0), "=c" (*out2), "=d" (*out3), "=S" (*out4), "=D" (*out5) @@ -166,6 +234,10 @@ unsigned long vmware_hypercall7(unsigned long cmd, unsigned long in1, { unsigned long out0; + if (cpu_feature_enabled(X86_FEATURE_TDX_GUEST)) + return vmware_tdx_hypercall(cmd, in1, in3, in4, in5, 0, out1, + out2, out3, NULL, NULL, NULL); + asm_inline volatile (VMWARE_HYPERCALL : "=a" (out0), "=b" (*out1), "=c" (*out2), "=d" (*out3) : [port] "i" (VMWARE_HYPERVISOR_PORT), diff --git a/arch/x86/kernel/cpu/vmware.c b/arch/x86/kernel/cpu/vmware.c index 3aa1adaed18f..0207e8ced92c 100644 --- a/arch/x86/kernel/cpu/vmware.c +++ b/arch/x86/kernel/cpu/vmware.c @@ -428,6 +428,15 @@ static bool __init vmware_legacy_x2apic_available(void) (eax & BIT(VCPU_LEGACY_X2APIC)); } +#ifdef CONFIG_INTEL_TDX_GUEST +/* __tdx_hypercall() is not exported. So, export the wrapper */ +void vmware_tdx_hypercall_args(struct tdx_module_args *args) +{ + __tdx_hypercall(args); +} +EXPORT_SYMBOL_GPL(vmware_tdx_hypercall_args); +#endif + #ifdef CONFIG_AMD_MEM_ENCRYPT static void vmware_sev_es_hcall_prepare(struct ghcb *ghcb, struct pt_regs *regs)