From patchwork Wed Nov 22 23:30:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexey Makhalov X-Patchwork-Id: 13465572 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=vmware.com header.i=@vmware.com header.b="kKI4Zh/v" Received: from DM4PR02CU002.outbound.protection.outlook.com (mail-centralusazon11013021.outbound.protection.outlook.com [52.101.64.21]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EC655199; Wed, 22 Nov 2023 15:31:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=BGk3QPY94D/adLvcML7teVcEPttH5dSVwCHmhKHBglIgscYVvxHRd8nTfMVM/JEotCX8sVnfuWtSlsv91kxBeYpWBtKMl+LiJl8x0CwptesRZtH2cqjcMRpPSU8jei0VwcOS8OsuzqUgofUxXUbpj+WMBjhaq1vEWP0mGZ8vbXNap3yE0IDDf6NfSGrmCgJEaDpTJc2r1WTgVA1sV2PZMi4IpT0h2HNulgn0THseYzy4HQSlnTuH337Tuy5H9HckFeHIq4a5Kf86eF9D/RnZMlGqHLfNpoQQuhu/gN11s1oJYl1jeGVJbPcnXOwLTPKfbE3/kjkbiJWglJbUNsIf+g== 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=LQOF4vl58JYmp9N8tajjHVKmG0zId2Y/E+sOOYf8I8A=; b=hINSEKFcZsTDE6GV7oKu1/FqUnHD3zTOECm7pmO0bGayBDwMehTdhrPCP4m1n6BA6rROqccBX7fCY52WnfKFtEu7v/ik8bz10OG4g3EJj5i5GZzsIYi0zP3gT7WHsW/w3w2dRrEVZJdZXgOeh25C3SgsVS2DnLadZQMXjyKUrfnx47VEYKrtyRs6c/T7UdhKr5PL5XpaaK1dRmfZk07lNlrXiPAGV3frMBxO4kGVsqic321/2XrIq00jci2ibKRrns0rX+Aq2/H4YT508A3giUCg6mq+H/eEo1E/n7Z2ZzujH1G2B+G8bLQGflJLJtWtNOHtdocENNjK0zdqgP+LNw== 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=LQOF4vl58JYmp9N8tajjHVKmG0zId2Y/E+sOOYf8I8A=; b=kKI4Zh/v1C3IsnuZBjZGxFjoum4FWZR/pLpgEaSSXBf9adkCKc/gNUYIM4hn+vn0AoczrBKTYsMf5+gVmSrVZQ2d6XAOnEvQS7eEVYuq0Oh49psxYU9YdzyB0Upd+qa0gNcFc2+KlbqBplxBLUAskGehcj8t7cETSwvF3ULHSL4= 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 BY3PR05MB8275.namprd05.prod.outlook.com (2603:10b6:a03:3b6::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7025.18; Wed, 22 Nov 2023 23:31:16 +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.019; Wed, 22 Nov 2023 23:31:16 +0000 From: Alexey Makhalov To: linux-kernel@vger.kernel.org, virtualization@lists.linux.dev, hpa@zytor.com, x86@kernel.org, dave.hansen@linux.intel.co, bp@alien8.d, mingo@redhat.com, tglx@linutronix.de, zackr@vmware.com, timothym@vmware.com, dri-devel@lists.freedesktop.org, daniel@ffwll.ch, airlied@gmail.com, tzimmermann@suse.de, mripard@kernel.org, maarten.lankhorst@linux.intel.com Cc: netdev@vger.kernel.org, richardcochran@gmail.com, linux-input@vger.kernel.org, dmitry.torokhov@gmail.com, linux-graphics-maintainer@vmware.com, pv-drivers@vmware.com, namit@vmware.com, akaher@vmware.com, jsipek@vmware.com, Alexey Makhalov Subject: [PATCH 1/6] x86/vmware: Move common macros to vmware.h Date: Wed, 22 Nov 2023 15:30:46 -0800 Message-Id: <20231122233058.185601-2-amakhalov@vmware.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231122233058.185601-1-amakhalov@vmware.com> References: <20231122233058.185601-1-amakhalov@vmware.com> X-ClientProxiedBy: BYAPR05CA0039.namprd05.prod.outlook.com (2603:10b6:a03:74::16) 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_|BY3PR05MB8275:EE_ X-MS-Office365-Filtering-Correlation-Id: 4e406b35-b32b-4780-a590-08dbebb31f39 X-LD-Processed: b39138ca-3cee-4b4a-a4d6-cd83d9dd62f0,ExtAddr X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: +l6kpTPXJ9fMakQ3Wnh45SRuRLoZaV5f/Nzq1kR0Q9ynd7xNRa/o8qDvX1ohXE4tC/9SKY6EOY5M6L7AXZa+RJcAgsti/TPwzRuLL2ajeQ0CO5bq4I3kumXwe6PP4qI33lGZbTrMYclRNZ/28ZjH7fN1Pqlx2na/73dGt9NJx2j3gO+3NVsRlruhdsct10qRwXdABm7jieDccVIziPn0XZD0lpXQO+OVdfoHFpw5m0vI/K4cwgnJTgTF0/fi8rEEDan4ebOxx7r7pFyoVh1Nh6M72bPHKuYEolBV6jJ/vbmoyRApVzal+v1a06vcKiNe7oLpqzW0ns0U7OB1KIT3luZJb5So2/NTR/qf4tJqXFLWEKfeXZL1PqAGADc3r7n+sfepClWdpfkBBcEjRMCDeS3b1cbJdN3nEVvp2Po3Hvu34B7i3b7TfeTZbbKyc26Gw80CRFBGIsV95uKBZmU498yj9o6hZDPXVMFUAfqnbyzvBOStRKJ6Hb/7iLfg0mwgTxL1XL7lUsSuz5VQHZZkn3JK5/PDSsUdiX15p3Z9tWBJlnUsLFhMPx1SlZUldaB9xOBppY1SkP2YqE7aB9WzD9tvkguStktNBAv5LHrHwFNjDsiPEG4AhWg/urCyekqaxxZmzYo2kD/kngu3oGQKJm54FuTnz/o1ZK/iKI4Xgy5Cw6Y0QTXo3RLTdpkxBkn1 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)(396003)(366004)(376002)(136003)(39860400002)(346002)(230922051799003)(1800799012)(186009)(451199024)(64100799003)(6486002)(4326008)(8676002)(8936002)(5660300002)(7416002)(2616005)(107886003)(478600001)(83380400001)(38350700005)(6666004)(2906002)(66946007)(66556008)(66476007)(38100700002)(316002)(41300700001)(6506007)(6512007)(52116002)(26005)(36756003)(86362001)(921008)(1076003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: bwMmQmJrVZWcRn0JNQP4xYNVBlktE1tC9KfExlYx3h/8iM56cLeOJ6dG8TFmCeHwQ2YpASHr3W/RmrVv6vYEu3KLOgZvW7VNUAk7x1kjSEXUZzhy6zP/KxAsHeyAw3/g4t4Dv487ut1/3hi5ESFWRg1TyBXHdnlM1dLoq9u4tPpMCnRzbOKedtXcRis5Mp7nPyyCF3N63ST0yeRBGoZ7riTSgjMICzbhsTq/+x3e9NyZl4oCXak/PpU/9bkJ1qhCZrYCk38CMRERNFEwXZNMnci1+vk8G3Vo+VcH69yFgMLaCLsTc+dRmBPN+DjrXCfod5vcHAWGGvyJLXxMe+l2b9OULxFmT7t4FPn14jIaDXoOqGYH2WYRjNZSKCSr94LCGlR57Q6gILHLh8K8j/jdFwm/0pas1qwJO8epIAwMrDghKX4ie4Jiqb1hhKZjkQHKd/ggafzIcBIIMkKcu+y4j1gY6n9dAm56n/DTFHsCi53T7pCwzeJZ5D/f7CUhmUwnKpmUspaUmUQWtVifG8R6sHpkGLVQgHNVismg9fwy+BwVJz7zgtM9yi+pdgG0KqDWx5CSnCU2sRaDEdg5W+G9g9V2Vr9wu6Wpp3fSWLhXFYvA/SOS25m2QWqy1p8ZkODgj9KscalfEaY5MgPZT60tPSu7SA3z9IFXNQRA/l6iga5BZIE3GbvJWXw/dFu3mgJtwfAWLMeYDndFvj3ati79Z8t+M1lAhs6iRzUz8s3kBO3MQGp6A/CTEaF+BoxpCYqT+2pi9a37x0BBsBuaJf3vZEA+0ErcAqaKoMSDL57Q8PATHFXGgQmz5EYXm1U3J2DcjoV79qT0zrDh6Abnfwim9tJCTZ1u1y5WS+eItSStkB/frRO7WB9ZXLhGrsKY6OrDfnkDZ+NDARAQ6aorqfe7zIQ7LlyO83asrEhunwr37PguTnmdR7/5et2UAULKv3RrQAKDDGblUyKDh8IgIelRuswq5EfQSUxe9JeKkbmSe7jEl+dTIAKV9+HrvkjVz93HrPymPrRBWwgrWG/tJerYrRSwBnNVaKvMqlYoj2XLYjfMqnij2H+r0qpHijg5ALw4FniN5vavLnc8f5RSp8px22iLNT8JnwTP47bE7bB9OMS7g2CB+sme0UXXLBVz53C2/JgQ+lvCjIkPhgJa/3I26EUN78qGKDPW5wZqFiM34gZgOCvbdzowCsLfFZAlFfT4LT40h69F7+PsKI7lo6OFYvmbf7F+1PyT//tiLgq/VN6M/LQ1y8waBvZJuFTQJWYljdTUvgXR19FwGEaoPQ4kgeofU2OnHboxcK+Dw8Y4GxTu/0Y+3mdYhjGXYxM5w3BzJirAZjwnoqL00PN3qoZ++VH73JjEEjctiI/8PrxrDdK/cKwU2tDkzECDiEo233sFr4muEG3etvKpDdclBqWlY5h3wneoZZ6ODNbdzpFYZTcv//luxbvXtUNJWozz7JSn+jMQZ1q+cBsNGZ46k1QkIShSY2qKGKnBzr81ZwsSWk69MqX8ZB5pCfli9qUZAtk/6Pbbfn6J/qhajpg+9nEUt7rc/QyruwOGlyXdxC4TcAUG2EDiM9/CBcTw+bKK2S6W X-OriginatorOrg: vmware.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4e406b35-b32b-4780-a590-08dbebb31f39 X-MS-Exchange-CrossTenant-AuthSource: MWHPR05MB3648.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Nov 2023 23:31:16.1937 (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: tofoRFKvLr3H99sxO5oj5jI6u8OZz7woGSyz6rUPSWTwjKM3BiIAlGWZdjUoMJpJ1Kr2pzILAXF0OvVQUQtWjA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY3PR05MB8275 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 --- 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 Wed Nov 22 23:30: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: 13465573 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=vmware.com header.i=@vmware.com header.b="v9TTXIrJ" Received: from DM4PR02CU002.outbound.protection.outlook.com (mail-centralusazon11013021.outbound.protection.outlook.com [52.101.64.21]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 317A2110; Wed, 22 Nov 2023 15:31:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=WSSL4a0VZzHLZxbV/ewI6ssdeBlhNqVVJCUJhXz2dpTgLME0HOlfBZWdNVC5p9Ojsnql0NeNcvUVPIxmnIWoLib+koMmP0yoiFFrUfpMn1pDH18s7WWFmcTNAnNcDMpGU3nkQ49mZP6kuSXnd94y+RsW03Jf8dBjHKeDgvrgNCIt+b+r/2kcPYWVpl12t7BIoGwdzuBw34KoeVQzTpa6TL3FWI4vpQX17RQ4Yre1kS0hZtgSa03pjX3DGwCBSdOgLAJ6Ty8cqsEEm6XlOFMHv5w7Dvn4tdItil6nazI9hFR/nIf+NxnLj/K6XbyLQSh2iHgIz3+6Be1F1r2L8XLnfA== 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=V0HUf4HJkx84wehooDLbcZ1NvSDXpPSeL5U4lnZJnFU=; b=eheWFD6zHr3eqKyhIlogQEkPVJNTjN8Rsux5Or8tmZDHhWiYgE/FydgQnpX+t9L/GusOPOP0RdaCezBqJsUX5lv4uMX5RdITKp6GhXGmkbmEFDGpQL2ERg/cyXMhhzXGgqQKX8GSKK0VWbT4hRkiSO7O3Fr0iQ60vJGFIGGfV/TvP26+CXrbcL37JJFnr11LspKL3pxhXdKETKoDHm4gL0PTDoQpFCfEk0eGgf4RM9snHZsjq1YF1kCr3GUYWGux3OqPWEq7jdDGOxdpxKz8oD3f/PLug1Li4PPv5U+K/K0OekkBW46iIbrKVm92cYyDly5EFos2Gz0Sp5kitut8vg== 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=V0HUf4HJkx84wehooDLbcZ1NvSDXpPSeL5U4lnZJnFU=; b=v9TTXIrJvgO9CeWi0w6zwfZ8+vS/Cica0yTKdO2bKUiJ6w6mUro633WmKK/wQmcPnV3PqHW1OTPV7/Lv8P5M9vPxKtz6CPfKyWXuqerPd/W3PJf7rtz6OMVS9PyZf+oq1Rt1BzRsXcWnfHZ5MoLiJpZHCtREdNDyOf6KSIOomQ0= 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 BY3PR05MB8275.namprd05.prod.outlook.com (2603:10b6:a03:3b6::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7025.18; Wed, 22 Nov 2023 23:31:17 +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.019; Wed, 22 Nov 2023 23:31:17 +0000 From: Alexey Makhalov To: linux-kernel@vger.kernel.org, virtualization@lists.linux.dev, hpa@zytor.com, x86@kernel.org, dave.hansen@linux.intel.co, bp@alien8.d, mingo@redhat.com, tglx@linutronix.de, zackr@vmware.com, timothym@vmware.com, dri-devel@lists.freedesktop.org, daniel@ffwll.ch, airlied@gmail.com, tzimmermann@suse.de, mripard@kernel.org, maarten.lankhorst@linux.intel.com Cc: netdev@vger.kernel.org, richardcochran@gmail.com, linux-input@vger.kernel.org, dmitry.torokhov@gmail.com, linux-graphics-maintainer@vmware.com, pv-drivers@vmware.com, namit@vmware.com, akaher@vmware.com, jsipek@vmware.com, Alexey Makhalov Subject: [PATCH 2/6] x86/vmware: Introduce vmware_hypercall API Date: Wed, 22 Nov 2023 15:30:47 -0800 Message-Id: <20231122233058.185601-3-amakhalov@vmware.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231122233058.185601-1-amakhalov@vmware.com> References: <20231122233058.185601-1-amakhalov@vmware.com> X-ClientProxiedBy: BYAPR05CA0039.namprd05.prod.outlook.com (2603:10b6:a03:74::16) 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_|BY3PR05MB8275:EE_ X-MS-Office365-Filtering-Correlation-Id: af5cbc1d-3422-4c7a-ec78-08dbebb31fe2 X-LD-Processed: b39138ca-3cee-4b4a-a4d6-cd83d9dd62f0,ExtAddr X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: JxHBoUR0C7SwzNntTiWfdyuMKa5hxKj9vh3yVBEsrZJcBHmy8EfoIUXD1eRLwtALckgKPIrKxRo/gwnCA6kObb9vTv4HhNBneUyAE1ISIRozln7owh4UIRMLJ1kwh6tS1zSSDjvfrr1HPdTl/NCMH2FEYxGiT7KPc0NxdOUptF9plnqqOJ35AHpQuaCVR60txdsIFKqBFR5rY7y0I6IZhatrjhUtzBvL5N++jl7zL2spJyuLGDDrnUqXT/UCYE6qbb85KUtR3aLnG3ZnbKoy+GNegcKLs/gQKa5cM8kO4aiZWD1/FY7LGSGN5gfesydaTga96ky8rWFKRZ5WxSOavz0u7W+C0QBdN8VsGQYizjWOjEVQiga1gU4gaBZis3j/Xqe+JJafZRqa75sOKQ7tlxxUXvdsx79+jhkMKtXwcS5iRQQ54Z8uGLQeDCmFzzON7pyBJso5u0iksT0Mc/Ss1Pd/zGCMFVt9mQvkLP+Y3V8b+QrOkVGdv7+l2sfeJDesuiI9nL/aVPT91jN3Cl5ZoOEMgEhujIimD+g1MhtUtZYSRJHZpRWqk3pRS38aeJv7AS3QJWwzE9YJVVdHQ/R4gmjiKDvQnMxwoftqCtox6NQcVLVeu3rn+tgomgEKPWNfWU0wvIaliRAROysPsgzyC8VIf+i802hcET+L/Btdimjg0vNyyrx+rTDU/GK/Tjna 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)(396003)(366004)(376002)(136003)(39860400002)(346002)(230922051799003)(1800799012)(186009)(451199024)(64100799003)(6486002)(4326008)(8676002)(8936002)(5660300002)(7416002)(2616005)(107886003)(478600001)(83380400001)(38350700005)(6666004)(2906002)(30864003)(66946007)(66556008)(66476007)(38100700002)(316002)(41300700001)(6506007)(6512007)(52116002)(26005)(36756003)(86362001)(921008)(1076003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: RpjEKzBdh+9u0qyCYHuETe7TueIwD5oOlhQbOxg4O8gWo7eh64V+jZL8AJXZZJ5gtCs2U9PVC9JUbP+xDO2mDdcHYX+SGo1MNtkXCBzgS9XtY7ee1PMgthe2chDRDPtXCNu9h3IPrqwnOWrPxn7x2sLee0B6WgBXi62N2YAMDxEi3wRiKJTjQ2n3RiAcZbxBg1p6eAAH9t26dTaErKTY8/NrpYmcbdeFcILIj+nLA+yAw2XZBD+PmMTpVTymd4m8mOPmo8u3I+U1SfHT7l4sDwTSauCDrf2Ar/eKYakRIFhINcLDYipG+HqSm9v5EOHb5Xt7sLc3Xq1o8mqH2Zv3XJuXZFu6cnoTGHbequsize+EtCrvPsbLTCIpPP9pYSWXA55IfNKyOrK/hmRRSeHlL3vCJP99HDe3Ci1CoSBbkLPg/633TZBqHzBKz1Q4Mnf8yrDD/DBFGXTyYPbuivqF8CF0VUV94I8WDVvMQsTzo04LJycDBBc14iyhGIi4dJ4fj09mxqkdmteArekvhjUansSzPHopZzo13DguZyQ8V7zMCN7ViZuW8wqq3n0tPx7vBeqkpaOXlp9FK6y+oxnSnDLnOLqL7xTmHiHuJC87xNU4Yu1HtFL9VbwogAF/e/BLkiT3tviD78HpZHNAL1Yhtt2b5XDT2UNZBCNupcf9ZKnFToRVu1irlkZzGEntVabgrgReRFCMH1wkDsR2/gQmnNw1k7C9vRhdNP7xl9oq5U/OwJdK+XmcjATL5QO8NwxD5cL6j6/OHpqkAzkhlBWBG97DwxS0ppPH84f2dpcYs/syj/zJvYoWQ+7QzEr7IUD8vUOkqyJRQhXemSPHHOPFuOvsVgcK9KN0WeoSlCqVEVLou5mBh9PXBJFrAGrYd4SA1W0Ku6pq2HrPeUwj6TQfOIarkzmXZH61ITAsEtE7+1Pkm8wLgBVUXL3tmSSuB7k7/zmAbotqP7VH0qvWon6eR2iEzO80krU1j/l1QAifWYp6dqzVzypkRT7chIy8OdaodECtwBRhseFq3RVIimdnbnkzqbiuf8ZI0Rf3o5OA6gNMgq0jLVeI+qHSbvf+rTfz8WMnnUQJcMoE6gAaE69hTdhZLAHROsO7ZX7t8v+CMGvGKhO16Q4EOZLjb+G3WEHZmYEcvKykUR2JehnEUS1sHdpabuQK1MWVljsqUZZTyjU7UFc/ntWgyRz1/70G6Q13eFCDrsy1g5cL4HfoGHR+POp15WPZiKIJ4a5E5peHjU/DZxLW3H0RZQqb0fGp/MRE/Pg/8cWf3Rv6VD7zJVxanueEFrAied08jZV3jXdRJlwThkz8zHwJkaxNMm2kCnr/9aGz9KyNEZE2/DzGT9JR5y0OzQqDthqicnOc8gG0mTz2k/jAbAdKDLkcZFMlbxx8yhz16AGaHmGUXKrOohAyBDet0BNGLC3q56dWlyd7v5uJ2BHv/uPULmTEPtfS/xMzBhbSRdnxMfepCh7rO+qaAOWN+yMkpp10ye+i+UQ5vYwp8F4/4Rc8umdMM5Q+yB/07A/KddmFTZDi5VrG68/snIppQrSyycqdJqSbDcppbp8s7p9TdA9MNy9yGv+4c0qU X-OriginatorOrg: vmware.com X-MS-Exchange-CrossTenant-Network-Message-Id: af5cbc1d-3422-4c7a-ec78-08dbebb31fe2 X-MS-Exchange-CrossTenant-AuthSource: MWHPR05MB3648.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Nov 2023 23:31:17.3303 (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: eUGiB+bZXf8a8BUmNHgL9eV3swQhmxKOGO1xG7WWv8WkyrFsys4ExlQmayw9/O6dILaZtpY6ArrBxeiSYJ1NUg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY3PR05MB8275 Introducing vmware_hypercall family of functions as a common implementation to be used by the VMware guest code and virtual device drivers in arhitecture 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 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 reduse 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 --- 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 Wed Nov 22 23:30: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: 13465574 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=vmware.com header.i=@vmware.com header.b="NFPP9chv" Received: from DM4PR02CU002.outbound.protection.outlook.com (mail-centralusazon11013021.outbound.protection.outlook.com [52.101.64.21]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6A01911F; Wed, 22 Nov 2023 15:31:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=TJMLfZYayKTr6G4KeNwP/bfwIG80ws8bT71CvMCZuGn3RJyKeHGQGGH9lfCU5Oz+IHY2YlRm+1JOIdo2Jta+KDucOpky3d0gTI5ql2FE87N6j8fP+jet4jrHZypJUw0IeM+uB9cGnsDUJa3UCObJP3zfwzoYyNS2khMej7k9g+7gcs5/8AmGgBR2YhF4ZXJ8wfBK6Wh7XCiTW06OpIxk3R5XTra+/m5QvfqUc2BM2ASVKAlQ6rk/SgtzGwOK9Sg/ZespQlLzPhfgnaAG/iNEhIfrk54OKsgLRIHysjWBgYcccDaZNSVwVTlG11dwlrkuYbV0QFdVLsDsT1tw6oaZqA== 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=mYs7K700gBSzwO+6j/TEg+wWDBD31/tUc3OwiVR/muA=; b=MczAU5kb9PIXAeEKJREyPG/jqMAcx5gCCWsH0EkWzIfaA1fbnB66A/pEWrG5ZwX+vem55Q2oKVIXSx1ZhlVgdK+SJg+XVC0qjnuUAPhD9hbbz4bWlQlFvJzT1EH3S9yc4bqkVvzTRKuDx5B5YdRJXNyBa9LBl/QEq4pD4KUaAL4H6tY+4U1AdQtwT7BUf+L4Ol+zCRyDnxaymRK/aUNRZXkfpZxpkGJRLRl7UUp+oluJ9xCrAKeRM18pkAtmuhsbGcAHkWUOhwZfSteYrtxk/o4SV637RbPKgsciwS3iq99j88no2gHkHaes2eZZHa5K+tDHntNptFZxN4o7jQWq/w== 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=mYs7K700gBSzwO+6j/TEg+wWDBD31/tUc3OwiVR/muA=; b=NFPP9chvVfP+nB2/OVWAWrRxgh5c8bIx0FkyTNwgHKkK2MHVzZr0ZH5LzMwkVT4bHPnYS1NOh+j1cPernQy87fP94jzy8dN/diqC7uUgJqKVIGdyFmTHhC1VraV6CGd3+BjH5IFhkaADEZjvYehFn5eGGItqpCp8bFkS0tr+ZqU= 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 BY3PR05MB8275.namprd05.prod.outlook.com (2603:10b6:a03:3b6::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7025.18; Wed, 22 Nov 2023 23:31:18 +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.019; Wed, 22 Nov 2023 23:31:18 +0000 From: Alexey Makhalov To: linux-kernel@vger.kernel.org, virtualization@lists.linux.dev, hpa@zytor.com, x86@kernel.org, dave.hansen@linux.intel.co, bp@alien8.d, mingo@redhat.com, tglx@linutronix.de, zackr@vmware.com, timothym@vmware.com, dri-devel@lists.freedesktop.org, daniel@ffwll.ch, airlied@gmail.com, tzimmermann@suse.de, mripard@kernel.org, maarten.lankhorst@linux.intel.com Cc: netdev@vger.kernel.org, richardcochran@gmail.com, linux-input@vger.kernel.org, dmitry.torokhov@gmail.com, linux-graphics-maintainer@vmware.com, pv-drivers@vmware.com, namit@vmware.com, akaher@vmware.com, jsipek@vmware.com, Alexey Makhalov Subject: [PATCH 3/6] ptp/vmware: Use vmware_hypercall API Date: Wed, 22 Nov 2023 15:30:48 -0800 Message-Id: <20231122233058.185601-4-amakhalov@vmware.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231122233058.185601-1-amakhalov@vmware.com> References: <20231122233058.185601-1-amakhalov@vmware.com> X-ClientProxiedBy: BYAPR05CA0039.namprd05.prod.outlook.com (2603:10b6:a03:74::16) 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_|BY3PR05MB8275:EE_ X-MS-Office365-Filtering-Correlation-Id: 98b75b00-f732-4a7a-95a5-08dbebb3208e X-LD-Processed: b39138ca-3cee-4b4a-a4d6-cd83d9dd62f0,ExtAddr X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: vS1UzhG/8f1ttObSqTeli1ZwkoHZX+gUOir4RJHPSHSta8qyRc/ndyVDvwy5rmMNv9ivScrSPW/fN0BWRblqsauzWQ1TVhaIO+phuCOQDOnfKtAySS9Ja+YWqYicQ0A8HzwQmOisyjkqliDVPcLinJi/b8yPn89h60T8sI9u3Pnl/RCJJ7WFMv7vz2bUl/h+cSb6G+M706u26VORuWFa4+VY59+iiEF/QXO26/8pmRrp+/l57PnJP6A4X+4125d/ZQAsPZRMwslWVwe8TQuQSrjG8MsL6CH2INWI4uBotitQfNBQxaLaSm5qXkjcp3aErxHRdtAAr6dvKBQItIbOoU1MtWNF5EzruAIKT7eFKQjqGBZ2D0/UwxXPSXQO1GCvhkO4kyDGjvqCAYRctyyne1+G12j8QPNcHNCMtznDdaPlUPaYfj53D73gDYDg0nmgeBoN8OlI+Ql401xa+rJmViNfTapbkkA1u4wafhzGW8Fx8MW/wCLm14ZVTfEan2E/fSwyPEuq9/TKV13yUqA8OG7I8QIb3rcNrvZQNTKxTTAwThMHtX6biFzcWnBk8wmsqf0W9VXX3wCYc4NT1B2y5cCEKaOqlHAlGfzOfTRdc3WNq0GL2YXRDXKu/A9cv9EfqvG8FLJVY0L61SxmKYE++1dFiRpJwjL0gU98CZN2BSWD/qp1y4LoMBtoDTs5D1C2 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)(396003)(366004)(376002)(136003)(39860400002)(346002)(230922051799003)(1800799012)(186009)(451199024)(64100799003)(6486002)(4326008)(8676002)(8936002)(5660300002)(7416002)(2616005)(107886003)(478600001)(83380400001)(38350700005)(6666004)(2906002)(66946007)(66556008)(66476007)(38100700002)(316002)(41300700001)(6506007)(6512007)(52116002)(26005)(36756003)(86362001)(921008)(1076003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: e6+hzPGNOXYwl+1WB4rmrFHy2qOXsnCovcTqY37vuB+0cb6H4d8qQWohyK5iJrtxWYmse1EGL761iUjgc3gD4BeL5X0clPoOpKaU2sPEGgi9/RsN3E6UVXwO1Mw2jcDkZuRkjlAcwxNpViXa3amzNMvikJDHQlcSJW4MJBQCDZC2JYI4VyCdkvvgAXgDiDMVxc2lY3zsduRXk4JF7zAuciQtVztFK476tGu2lYsor5lbe405EZo2i6UdC3/3yLDa7MMYQJk+9Y/iX5+6jffz93SbHv/hiKQpmIiO4IKNKrF/yp37TQMf6vIrRosKxg+a5JbadbCZh0eaxLhXZ4G5YMI30u82ijUiwPLKbLua2qoXa9k7ubjzItyptEHrm83EMoefifA/DVloxBkSeXJMhpkD3plS0PZzHes2jX9Bkgw8YwoxX2+5GFk288MvYEhTMtCu7NbQi61YeQHNjl4j+n8C0d4jFSqvFaH+7cdAb3JA8UL7gOb84l2FEWyHrFFd3APHEw52DvyEXH8pbkYaVwJxejty4bKEssJUhsm892X6zHdcpMyqG5Yl9Zzh8/WcGQojs8oyZ3iasqggmkm1oTTybm8K8Cy2rcpG7g9GXL/UEf8xxmwuoVFfHvAnPdYZ9J+GKZJBe40AkAeYVDRAA+/x1oVXNx7r8ACqyzPFM5q4CjFMUY7QtSENPuUALHBOYwRH8pCcKWpgsf0WFK6dBDjqHt0ZJ4OXGvN8g8MGBklSNrfLlGBDju5DcZORLU5dnYZTJFOrcWaVW2o/b7xVWzFxK6zPM7+WoAUHXwanPFBv4sMFuXy0/AyBcifPxVsn58JkjsaIOTYxlyb85n0xDvUQocvm4RosUsdBuhzOCYj+D5LoH3oxt3COqunQHCaO8xi6FA5xnD4UGaakBsL16MZ9Vfq2AqLeSjyjHZ8iowISp2ZPK9hWQekuQ0fdlvJ2UjbjX/mpw3a+c7bPLrEWTj8WhA2rP4Q6Hrhi9SLISQ+kIC1d+0C/TI6itlRk5YCtNvZuJ68imIqdYwdCe24c0OTGk7vc9ijrJxYyb4+ukEnWmvPiCt1JT5sY7PxxjtoahfgSuQ/QZL/H1Ulxv2DGa7GO3c5AKbIY9mL1nKzZs5pAloZBdivdvlxJwqnRZ2aUQ+MR6m3KSoZ/wiO8Bs4WqUsGik8bea9lTXbMrEzMtNywGx1MbUN99o1KsNvf1Mcagt3HEnM+MAX0jq1oRXYGCgYamSp+uW4qoNPH9lguZeKsT6uByAJVI4hg8wX8b/pqW5Au21UKTz+eQ7RlTmJKc/beJub3twdyQgbxeJOdT+VrK7TAOMb7gho7YhpLGlz2q3YJUFSqEMgLK08Ai8Nk6AWS0R+2zY4SOUz/nRZhBe69jES0p/3DfkmBPQRogJDJVKs5tExteh6JEV/WL21nLLDTWvLfOm2dNu0d+TARpRCTemRDgzQDZPfYEhMjzs/WVzmP6hrbZpybK1XJ+FBd8DIf6H6bQS2a3yf0CaAwOrrSGmjTUw7v9BGxOOXuKwCZIiOpWBCtEzzMlH9lFw6JoDMqKvPreriEGvb+DM/Lt6r4ztPoWbvtYdbKXTCS6u/4 X-OriginatorOrg: vmware.com X-MS-Exchange-CrossTenant-Network-Message-Id: 98b75b00-f732-4a7a-95a5-08dbebb3208e X-MS-Exchange-CrossTenant-AuthSource: MWHPR05MB3648.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Nov 2023 23:31:18.3896 (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: JPJWNlHafRHXCYzdfuU89IWdFuKSF27tSBMTG0LYWCbaF3C7VjKQw3O37v4tefvkb5H3lU30kU1GoKQRrkxO1A== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY3PR05MB8275 Switch from VMWARE_HYPERCALL macro to vmware_hypercall API. Eliminate arch specific code. No functional changes intended. Signed-off-by: Alexey Makhalov --- 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 Wed Nov 22 23:30: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: 13465575 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=vmware.com header.i=@vmware.com header.b="lkvKa23K" Received: from DM4PR02CU002.outbound.protection.outlook.com (mail-centralusazon11013021.outbound.protection.outlook.com [52.101.64.21]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 41BDE1AE; Wed, 22 Nov 2023 15:31:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=NeGsIFpIHwj3qhdn5d+klHvUqQS4llm8mbZyPMala9uHNpdnxP9IDyF6X7U5mXLK+Zkl0QymSLrg6WSltbaE+KF95B/lnMI62s29ltGxCm3TQvDPgmly8Nl6hLwV4s3TT3tRSmxtCmykycf5r1Oxil9U/uwaDqDucbYAo3hJkQGt7+iRZ+6UvloNSW6LGgAxn+FRPSWD2hTk8eRsBE34KxlwexKMXlyh9SF3gktiY9PMRn12sPx+qjO+cnf9Hjh9Q7LY3g5MiTCCB0qZ8BWIT2ss2ieNSEP1oBnynZ55Z7xHd8Zu4LUwQbN7AAZof/auTap6NDvdhfp+CC9I9506WQ== 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=HVWzCjlcVgTSrRlWhpddvTqNCqboahtiFGaNpLw//j0=; b=D7o/yGOfOopaajjudNI+QFCHhFzWJqlfP449hOM+aGfKHAqOfEVbqV8QNO4V/sBFzAJ5GoeJA47PBvMKLftPktQ3z/ozpqDaiMxDFWOMRGNZ9YpoOKH8MKPvf6s7beiJ31hLNk45o5lsp0f1eZdqFt3+EH9YXNPSb8WkTldq6uOfi0N661oyXNhwGs40jWqhvGja07vYERuLTSxVqZ+C2jPUUO55MWc3XS7pw9bdfPB8x8bEu+0YTrz6sRA0DvfT9Sq1KPBHXZH1Vgh7fMzd8qc667wxXEOPngmZf/gGLHR5rsSadqGs4GTts9NpMupCGFU3QFk5/d2sU2m6tbp9Pg== 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=HVWzCjlcVgTSrRlWhpddvTqNCqboahtiFGaNpLw//j0=; b=lkvKa23KmkmgrtV+ruIozbDQvkt7mf/q24mGVYf3HxKzQND/sVL8Y6KgNtl3E70zf08j77ilLoUlrbO/dhKEH/hz7j6Pxypvhf6vmSfixPDIn8T3uzAdD0CNLBFVrCRBWZAYJ1F4D+K5a2DCb4riqpuETesMOq9pcrucbgrGueE= 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 BY3PR05MB8275.namprd05.prod.outlook.com (2603:10b6:a03:3b6::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7025.18; Wed, 22 Nov 2023 23:31:19 +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.019; Wed, 22 Nov 2023 23:31:19 +0000 From: Alexey Makhalov To: linux-kernel@vger.kernel.org, virtualization@lists.linux.dev, hpa@zytor.com, x86@kernel.org, dave.hansen@linux.intel.co, bp@alien8.d, mingo@redhat.com, tglx@linutronix.de, zackr@vmware.com, timothym@vmware.com, dri-devel@lists.freedesktop.org, daniel@ffwll.ch, airlied@gmail.com, tzimmermann@suse.de, mripard@kernel.org, maarten.lankhorst@linux.intel.com Cc: netdev@vger.kernel.org, richardcochran@gmail.com, linux-input@vger.kernel.org, dmitry.torokhov@gmail.com, linux-graphics-maintainer@vmware.com, pv-drivers@vmware.com, namit@vmware.com, akaher@vmware.com, jsipek@vmware.com, Alexey Makhalov Subject: [PATCH 4/6] input/vmmouse: Use vmware_hypercall API Date: Wed, 22 Nov 2023 15:30:49 -0800 Message-Id: <20231122233058.185601-5-amakhalov@vmware.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231122233058.185601-1-amakhalov@vmware.com> References: <20231122233058.185601-1-amakhalov@vmware.com> X-ClientProxiedBy: BYAPR05CA0039.namprd05.prod.outlook.com (2603:10b6:a03:74::16) 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_|BY3PR05MB8275:EE_ X-MS-Office365-Filtering-Correlation-Id: 71ede83a-c3b1-47c3-b55a-08dbebb32130 X-LD-Processed: b39138ca-3cee-4b4a-a4d6-cd83d9dd62f0,ExtAddr X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: PYmivN7UaTLQ4tHYozn9HKP4SXYLqb/dUtxEsCBq8p/IH0sYjuMj/mbNNJ/ttPTwlFz4Q9Y1PrG9Y9VXWTxPqLiOCFmvjcExcz1YTcbXFAOQ+OrXWbKnyTbHi4Mc4pIR++VOpDZx9GKhiQOVYXQLSuYr1stLe5udgqUNft55tlKPC/+UAAi+LWQ6++fWqRcVDxWy6xu5tSOogG/Vq76xYOwJ96xfI4CRYGE3dFdvfq0TXSJJ3gmK0BHQlE284uj193K0XSOD8ZITd2jop/PNP3FQraFUbwbXt7guSpxlUT+xaTQOon4qRaY1BhA81mi1jSRjthdDj0TI+xMCFQEu97xLKPfDQdloEow8FHGdGSuLsu0/6QGUFus4g80d8Ja66YfuyyOGuHXwUrK0CAihpgy+5LWY7KEaVDk3l9xGQuMThMoZFhwFYK23y8cjEFSC5cHxm5CWZlhPz6AetW4MJTX8pso6mAoX0Nn2pb8ASvfyOMyK7PqTHCZnO3U0lHYfST/H5HbSNrb1gRtc3/kOkNcF4GXLnMEIKV1gouoP34jmsCd5yo6QMpOwG8k+NO/czq6HDUsWKRumATAKt7KcgkEWm0MU+2BkuEELerrK2mhvq5k+0uoWXXUUkYcsZHmOm8ahx+rF7K38MnVMpSuMpjdAZEHw51wqda/X1rPk7R0cGvXUIM9MHaGVOgZjNFVO 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)(396003)(366004)(376002)(136003)(39860400002)(346002)(230922051799003)(1800799012)(186009)(451199024)(64100799003)(6486002)(4326008)(8676002)(8936002)(5660300002)(7416002)(2616005)(107886003)(478600001)(83380400001)(38350700005)(6666004)(2906002)(66946007)(66556008)(66476007)(38100700002)(316002)(41300700001)(6506007)(6512007)(52116002)(26005)(36756003)(86362001)(921008)(1076003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: oQugOxds/UQP5hj90hUe4u0OUREVYEv/08osMjXUPXVi1maxiYR04S1VCbHn4dsRVELurBiG0DeQmV3SJYNjzIoBzvYfBgSwTJ3UY733nIITLhkL6He1HnFufn957CeqmMn/VGbRm0oKKVrVUenXei50082fFkkp7vx5Xkx6K1x/+6f1EnMgc7zPxOBeg76DqOQM0xn4eIs7nWfqhXbRqaquCLdLrhRspK3vjX4LslT6Ml+TQLMUgQZI4A5wbdAgMQ9a9004iNnB3BglDiRjqR5qiyvUPNEQQbmV2yumdv+60cZ9SM1iqg7tpcUh+LN7MadGsykELZZt+Dsu55mIBEluoQfL0J0iKeD1zuzz02EoaQ99iMBNLamWBSS9pUgRCP5Sdh0zY0Ie54SAZNaxWvX4Li9Zyc70+GTmspftTMI58Weca6lhHHSMuuDaOx51d59ooe8zjdh89CqhzsM4/sh854G6rjI5Z4BkyW/5fuKI16IOtNtweEqLtHwMuMW2OSyIQvTrloC0khaIaS+PjYF4o/UGSQFS4Z6IJwtZKq6iIePuXRA3V7WDqmHk8jga5EXD9F19VYn9UUAudIpD7mCeFS0kt9yscvHpLrXZFzGMVqtKkDdOmQRMBcvSBf8rFg6ge0QA+XUTZl52nHZHjn7Sfm7a8JGlmi55+RvdvnLI25H3+sTjST77/GIlV1Lk/SAGA+Qe/XLHKvvQOIjH1YxMm1Wd6nW8KM8nv4no/RvOe0RbrKCQ8AA6njjPH4hFpQPCKbyC79zy+AvgXzNTJ9gqrTK2/yVt3DLS1K+g9M9kRvdzn8nEwfi0S4Eyi29FLsIqBHnndoQIHftoOPa+JKYxonbjm/utJQwFb9xPnoXtIYBnJazWtAeyf5kPxlmViCDE1iezpnaIj7nA3bS/LXv2+bLEqcRkedytY2+IPnl9A2yhKezV7Puturry9Sao/hbt8VZ6DOkWUIzFxzXMX9iHC5S6nsqpyIrV/xSU79sp7Bs3Aj8sT/7Lmm7ro4vmL7Je/bIu/1ONHaEkMxKjvr7+q5Dw14Koxw2XrBQ4tvETAUrG4WRqdkWU7YLHH16JWF9a/N1lQ4EcgAb/0zIVsTR1JOhcsTao8qSDGtoye15l/OSoT6JzOYI1YnMdNDmR/DPmJVFYdpmmTqS/z8cGVqWkPrJGbChAEaPazlWW5ysgWI6LzS496HwvR+4HTcuW1fj04NYAVNusxkiPB2P/pqHIhgl1HLQyxQjGNqp8jngop1Ty6EZGf1vMrN0HjEOcr+5hG2JBV1sCeFcVJYn3ABwfS6NepAMB8WgRPTj8ycBF3+FpgXVTODhmmWRsU4VOcoJ0OKz2OU+36eiTB/ZlYl8m71oqNAM9YolH7duA0AHOoSA+ikl6PDqtdpZoXsZ5g8vr02JaXHT5R8tX+m7R1vCuPta43CGK6m7gx+VyJ8hXgCjSb/lEzVfA6ESgliCqSsO9ltoRp5BoyNWoIaqKtaRIkHa9fNIqciS/aOsuEqoXtXtdNc5Fn92Hnofb5e35drnt6dSHa9DmHvmVD8+ZdKIJKXI/9ocXzPeqPU86xYxaXCpWBU7K53zBHR8Oc3gZ X-OriginatorOrg: vmware.com X-MS-Exchange-CrossTenant-Network-Message-Id: 71ede83a-c3b1-47c3-b55a-08dbebb32130 X-MS-Exchange-CrossTenant-AuthSource: MWHPR05MB3648.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Nov 2023 23:31:19.5216 (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: SicE/8Et9vMT6oqshLK//05lzvGPv1e80iadQYOCHzF7AoBT9KYTpRMA1wSvQEwnTbk2pD8HAtmeEZ4WTNc+Lg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY3PR05MB8275 Switch from VMWARE_HYPERCALL macro to vmware_hypercall API. Eliminate arch specific code. No functional changes intended. Signed-off-by: Alexey Makhalov 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 Wed Nov 22 23:30: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: 13465576 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=vmware.com header.i=@vmware.com header.b="bhOvE0bI" Received: from DM4PR02CU002.outbound.protection.outlook.com (mail-centralusazon11013021.outbound.protection.outlook.com [52.101.64.21]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6FF5A19D; Wed, 22 Nov 2023 15:31:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=WuNx1T9dzky0YDMT/cpMEMm6kXog0ypaN+VBXJQMQw3TU26JPcnYDEyjcEzB9CMF13Y1M5leEYgPxuhQNkSuVf+qxQlAG+449b34wzAB2X1tX72pIvrY9jTqxUMKh8voxVLMrDdb8vZdvCIyVwIUNrLCLUVi6l3rqf6mJag/e7xldjwz3CDGkOGyCAaGyP+YI8iUEudfd99kjRZllM7pDVQmwIu98qzA1NnloFQmskr9hyrG95rj/gc1/u4SDFhnYSUBGb2S0jkxOt6HFig592opYaQ8gOXveZxTOC/TWv+MU+/WbkloXdkOpftZH8iL3wkYYvl0V9FsSycCtAAq0g== 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=KufTTWTxBDVDJFf4k/BwR5w4RwkyLCjRKdiUARMhlSw=; b=Mdl65z+uYTqF53QggZMlEu8odmZ6C3f575AQ1jed0QXZN3Cd/UjUgjTBtldT35BNOf6SioLgM4VC4Ng/O3Eg8nfDPNgAWsNOQkJZiTtqnIvSeaV+BYVdVYweN44eow5YFWqVOenc4FJyW3PoL7l3wpT1ys1ae1+1XxZXPW6TE2G/Rmf8ssJU1CgLlNG67sCVT30oPOBwZwcAAefSA0harbyRpCMokNvIF4qkMMrvo0poC9xh+blGo1pclhce9pVvGo9+n5yEPBtdCVJZ2BcukIraN5N4Rh+PiiTSnHfPzXSf40v8Kn8b5KRfq10iFRFHX8vZ2JeUSXOpZqfP4W3Iww== 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=KufTTWTxBDVDJFf4k/BwR5w4RwkyLCjRKdiUARMhlSw=; b=bhOvE0bIFekUsrLDZBWzNVPQVGYOXBM9/F2zULQZtpHy7qPd65kCv8tPKNo0nXwgbwH6WgUErbd/ZkD6JLcUtWW2Weu+dcv8tQr21U5npYPvT+l0TsPT4UrvLY5jbK1PEriUcYZIcYeRHRN32iME+GRCDVYzMVnakZ6b2swLidA= 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 BY3PR05MB8275.namprd05.prod.outlook.com (2603:10b6:a03:3b6::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7025.18; Wed, 22 Nov 2023 23:31:20 +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.019; Wed, 22 Nov 2023 23:31:20 +0000 From: Alexey Makhalov To: linux-kernel@vger.kernel.org, virtualization@lists.linux.dev, hpa@zytor.com, x86@kernel.org, dave.hansen@linux.intel.co, bp@alien8.d, mingo@redhat.com, tglx@linutronix.de, zackr@vmware.com, timothym@vmware.com, dri-devel@lists.freedesktop.org, daniel@ffwll.ch, airlied@gmail.com, tzimmermann@suse.de, mripard@kernel.org, maarten.lankhorst@linux.intel.com Cc: netdev@vger.kernel.org, richardcochran@gmail.com, linux-input@vger.kernel.org, dmitry.torokhov@gmail.com, linux-graphics-maintainer@vmware.com, pv-drivers@vmware.com, namit@vmware.com, akaher@vmware.com, jsipek@vmware.com, Alexey Makhalov Subject: [PATCH 5/6] drm/vmwgfx: Use vmware_hypercall API Date: Wed, 22 Nov 2023 15:30:50 -0800 Message-Id: <20231122233058.185601-6-amakhalov@vmware.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231122233058.185601-1-amakhalov@vmware.com> References: <20231122233058.185601-1-amakhalov@vmware.com> X-ClientProxiedBy: BYAPR05CA0039.namprd05.prod.outlook.com (2603:10b6:a03:74::16) 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_|BY3PR05MB8275:EE_ X-MS-Office365-Filtering-Correlation-Id: 0c9001ad-9057-4d56-5e60-08dbebb321dc X-LD-Processed: b39138ca-3cee-4b4a-a4d6-cd83d9dd62f0,ExtAddr X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 2IlJGtmh063f4E4aUcZzwzZDaFZe33eL3SrvCOWR4OFpv02wow4pIiZ2TdTBP4lwK0MQjk36lddERnr5J3Q5jEiWcejCbmAJeCUQBiTrcXV+EWdQEkTIhf1ySYPu6KFElsjPfKZ5qFiukzBi0KeS2G99wKdSiUJ58BmHryCaf4jolKMxqyjVj2uLHHKB7CKO8cWSjxViOZ3LwV2PUMfojw5u556Ueczigdsk7fl2m2VCqwMaA5rKbpyn7MoVcfXBSD+6kDY6Q4yGgt9l9+5xnS76G2kDPgbhy8pfB0h+i7yfTqhaqR3jzrqk95zu6S1e/UsSpA9EyOqMQKAPuJqMitxERQtqQyJPatwJXRfRkEOSI9n4pUawbIzlz32ubxkKw6ml+qHZwwG800yS8V0PNLJWqgBuzlQp08Q4eyoxeYPvLgdbDT06RqWb8e+Cx3z0mdDJ+z/nVOJXCrERUbwaEOHFF0xiLu7U9c9s0F5qv+rARNnh0XYGAq/PInLmL1X3a6SIrsJp7j3IXsAb7HPoSzNKmPSu3i49iMCEG2QrQo56v1ZfChiQDDte4a0fuSuQYfeEkcvRpG3Wlw5X2oPwOU1E8J3b5UTEXKSzNxj0IWZNaS3W6kT/Oom5t8dI9H69D9hN3da+30FZiyQRtEwV15E1pLdpYY/zkL4hZObQmUMBjqQRsw0Bp8iqjkog+D65 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)(396003)(366004)(376002)(136003)(39860400002)(346002)(230922051799003)(1800799012)(186009)(451199024)(64100799003)(6486002)(4326008)(8676002)(8936002)(5660300002)(7416002)(2616005)(107886003)(478600001)(83380400001)(38350700005)(6666004)(2906002)(30864003)(66946007)(66556008)(66476007)(38100700002)(316002)(41300700001)(6506007)(6512007)(52116002)(26005)(36756003)(86362001)(921008)(1076003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: H8Rplem4ZDK78BlPzINx+ouROvfRl+sYnBSucdUqnbbAjY5ibpnH13MqwnuNpSLIFWbpPh+e2H+lH62kX0tAAl5TORTx+NrRa9Ls5Uw+zgeyVyy44uUvpH594PHKOfFqHkj9q/f52QQTJ9M/VXPbdbkgx1BcWR73DQYOpjq4FrZMG9zAJkPX80wU9NFbqKxK3NHSW3eTWI3GWtp+uXSBGEvwWPHYJDtF0HBg+E8CLKY1CmfQohQm5LGauWpJz0A+2w3XijDARDXHOZ012dET24Xkf/2qy83enqHCYJJMFPRf/G3mHLe9BHYhc1+jXuLb6352J/Qtqj56xq3Mqs29ie+MCR3xIWjVAt10REbHmspTWqL3AEtC8l19mo+gyYp51Mvi2n3rOxVY/wE75F0uO2AChFpIoCfpbod7SAC88LoYLbLqRi9XA0GnWrVQop1fxAotlxLFIVcCfoHjGyZsv1kkPMF7znrgN9IuoyHGmWWhc664NI+RPAc3dUv4j4Fli7XDeZWe+OmWBjpAMEHA1OMNOd2fcrowF5CwUIHqaAVm0azUnz8w/Aj1OpA8pGvyMbsTFH4U+q8M2hXmgKjYpVG1HBb3keBGhimbsE5k/QDgrwYvNRaWHJyzRMnKmQG9iknLvg/mOfccaBbJ36ZJGubllmcgwMpgwVh8XXHkUMlEOz/+XRmQraGxVWwJ5FTz2FCxYL9LKoBx3+IrZITIipmMttwaF7NqCUOSKWOnHK5pvu0GC8vLbCwfFJzJW1ItWzfRfCtIJSFcdp3BWQoJylhqQ75QL+InGikLMNYbIgBgz8VSga/5uQAFWwR8ZJ8xQQq9nejYW1UoPl+TxWMziVExcXBp7NVR/YD4qEMx/kdPS5iVE6Tapk4sKpG4LIBnaeK1Pte6sLE6d89CwYtnnZbffFc0tOwtkEXd2/AkTnp7whVJ//Y4xZNLrOx4PHMTM5jOmunj6MtY/3jpOW5LOzT2PqXTAhXFL7p7WR7RnUENxYIISzAiJp5qxJRtqEg+MFMCmsOCE+w2p+qRLx9gsaOco/yXQUTK6WrXXQVynduenwavrBlsA4QsqNQ/yWsWy4aHl9rwul96hoytZss9mxHV7jg04Q8hdTO4Z6rES30O8IKmI3zy3bL34zjuqygb0wAA9QsqiDohQrpyz93mdDy1F19LnXOwFtkAQbjH0xZPKj7LloBouTjvyq8ZisjcdOQ0raRdJVNemxndwn3LqyCGFv2zXMC01OcurJpn5oNuAKeBUbD8cbgXefCSe2fLceCMk3FDF6ea2SP43hxorhcyinwl66+GXM7FV6DXQIvhgC8yrHnjH7FxTgv3+saY1WNB1FzK//0kqkyEy3Q11Pt6KZo/soUK8rmK8cPana/PeyivzfOUoPWiqIv1LZeKbNr0nEtnJEy5TotfdvILOY2HQiZUlTzabdA8PqBysi3gNJVM+9nZWonSvlpC7foT7E0id5x3ASUHYqXXo2/dlpSPaEIz7PGzHADpwJRIKOhaj52Pa0THK1bRk5svO7bXAbdI1gPCgajn5DQe92FpcSak5JuLNaZW3v9ieirSFAoqyqjDgBF10k1mDb5eio0C X-OriginatorOrg: vmware.com X-MS-Exchange-CrossTenant-Network-Message-Id: 0c9001ad-9057-4d56-5e60-08dbebb321dc X-MS-Exchange-CrossTenant-AuthSource: MWHPR05MB3648.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Nov 2023 23:31:20.6092 (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: qwRKPVVDqdz0QRDrQ80HnJR6V0VO99QXf5p89AS+21KzC4W8Tb2N9VCDf6iIBZ33x7e/W/zZ8g+1X7lUSEZcbA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY3PR05MB8275 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. To be moved to arch/arm64/include/asm/vmware.h later. Signed-off-by: Alexey Makhalov --- 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 Wed Nov 22 23:30: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: 13465578 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=vmware.com header.i=@vmware.com header.b="QtZpEhd2" Received: from DM4PR02CU002.outbound.protection.outlook.com (mail-centralusazon11013021.outbound.protection.outlook.com [52.101.64.21]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3FF27D44; Wed, 22 Nov 2023 15:31:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=NIyEtPOzjHet0x2UuykGZhY8iT/zzw3uvVgXRqTJG07VVw1uow26paAEkoQAn/nuC7nusC2gPbkfQZ5uPeoX/nx6KY4TUD3R8CM5UlACJwIrmX//POr+9wJmK4UyrGGwmmC4LhxuZx0gpst2emEnH4NO/x4hm8kvzBZGT94nDWRtxi4U8/qlE+zXdlL7Vuf+Cl/vvFgUO/6tJcfPLDqsIWQpTdnQ5jT6/YXDumpi3ZnRkv3oA2ODF6hlAG74UtzXEz1t0YG1azUXtVHePqJ6k2QSmrYMWqlBCPa/1DA6Dr396QINFyL4hHzmF4nosrbnGEFDav8wZXgAGxc6IcZXTw== 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=FzRNOgWnmwpHxYcLc3yQ1p3QI8GkO9/CsPYKHZtJL0s=; b=m1Tsi+Qyg8h4IHTiA50Qlg8Mg4E6oavlL8a2ZtRY/NUtQTOD1OPDR4/0GZme4kLFCC4ceWLKc8lbxgkoGPi8AO4DQsv9DBIDku/tA0WPE2uOvrDKeXN9oKkoeuIKf6Yowwu0+9v+MHrTmHsdXD5hTNfggsrG/kfOA6oNjzzm+JwOOFIsHesvmVu8LQ+ljSQf+A/R/T013TP36axUv6+UzyAAvJUECig1wAzY2HAx9dw7XTU4xYy5SH/1Je2LH4O5pd6ZVMpm32q5bvKdvjEcIG7+enLv87oAEBrUnIm+Xkd4a7du3Bze1yEjTrlGVQdNI+leXv5bh2ttLs2xp9QXMw== 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=FzRNOgWnmwpHxYcLc3yQ1p3QI8GkO9/CsPYKHZtJL0s=; b=QtZpEhd2aZ0x0qr7oQo1hCCzmMoxrdPemOCXkH4uM9uSTi3hHo4dMM+S3sWclBcyS/qlB06Nk5T6JWofn2YHmf7V6Rf0DJ3AGlxi8h/jh9YlESRHlro3b/j8EBXfW+xllRAE+5/Uoruk1UouFSIf2Uwf6ARwS4fFfa6gUge6H4g= 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 BY3PR05MB8275.namprd05.prod.outlook.com (2603:10b6:a03:3b6::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7025.18; Wed, 22 Nov 2023 23:31:21 +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.019; Wed, 22 Nov 2023 23:31:21 +0000 From: Alexey Makhalov To: linux-kernel@vger.kernel.org, virtualization@lists.linux.dev, hpa@zytor.com, x86@kernel.org, dave.hansen@linux.intel.co, bp@alien8.d, mingo@redhat.com, tglx@linutronix.de, zackr@vmware.com, timothym@vmware.com, dri-devel@lists.freedesktop.org, daniel@ffwll.ch, airlied@gmail.com, tzimmermann@suse.de, mripard@kernel.org, maarten.lankhorst@linux.intel.com Cc: netdev@vger.kernel.org, richardcochran@gmail.com, linux-input@vger.kernel.org, dmitry.torokhov@gmail.com, linux-graphics-maintainer@vmware.com, pv-drivers@vmware.com, namit@vmware.com, akaher@vmware.com, jsipek@vmware.com, Alexey Makhalov Subject: [PATCH 6/6] x86/vmware: Add TDX hypercall support Date: Wed, 22 Nov 2023 15:30:51 -0800 Message-Id: <20231122233058.185601-7-amakhalov@vmware.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231122233058.185601-1-amakhalov@vmware.com> References: <20231122233058.185601-1-amakhalov@vmware.com> X-ClientProxiedBy: BYAPR05CA0039.namprd05.prod.outlook.com (2603:10b6:a03:74::16) 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_|BY3PR05MB8275:EE_ X-MS-Office365-Filtering-Correlation-Id: c2970139-a825-4373-0777-08dbebb32288 X-LD-Processed: b39138ca-3cee-4b4a-a4d6-cd83d9dd62f0,ExtAddr X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: aBXyMGmKIvJrDeK99N4H2BXrIuazQUJ5y+vlunU3W2EW6J6e44Alr9sxUyhrIeAgv1QckjnDFK+CAFbJNhgUlHZOhoOBOnr6fHgtkMl8JxZvfxiDojg1ldnediBEVCuyDYbuhCtpqrvxo8RpaQ+bEI2cE1q69dHFyQcHi8dFtIf3YeUJXwk6irSVKR2T2yWnB/dehmkMnKAzb0e8bAMGIVP++LjBdI6mv9lxSALUl2uk6AoAp71gt2AXOX4Fp2GDCwrFdaCLvieB53EwVuMqmA+tPmQyam/40qkTiitjCyFL6EGTY2DxVQvG3y4r8/Ovj9GlM/JwH3+Nx9K7pr4HEBf48j3wWkR5MyUYrwfJQWd63+4SUnr4gzQrNBOVdwm2Soy+B4kOEs2I31zqmbXE32CR+LBtCxs3xGHrEzR0Ih6NxAHNSAOu6hKMa3NarqagyoZdNJ/oYmqK1cP5v7KFZgCZ6RlEgtwu6UmoVyd9mnuRlppVRfQmP+Ic24pl8sQ/oc6792JcskvW9i5jpspYHPVkAfJXnWl5vF4C4dgvwRatwgEm8B2RIKtUpW/xV53fjuiQZqhCXutrNZHcRNPwT6sUI8iRS9zi3PtKvGpVB4Hwu4VQkflVIdfd64Fshz2HNH0MCdabe4M+bPMjqOyS1l/dylnTCCtFttuymD49JkzROweeh2Gn8UHSmt1OUcFu 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)(396003)(366004)(376002)(136003)(39860400002)(346002)(230922051799003)(1800799012)(186009)(451199024)(64100799003)(6486002)(4326008)(8676002)(8936002)(5660300002)(7416002)(2616005)(107886003)(478600001)(38350700005)(6666004)(2906002)(66946007)(66556008)(66476007)(38100700002)(316002)(41300700001)(6506007)(6512007)(52116002)(26005)(36756003)(86362001)(921008)(1076003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: IyAIthwmpJK2xq+OYxTl4DEDQ7r026qIdEmgblnPIDe0KlGKTbpt+P5MpDVi6iQrwsJfh162B8oiZL96nr/B6gVRNM2D9OccdNE4TZZ3ZDxNIKuFWuwxJgbPxV26egV17irxUHibEy+z14Q0TOtL2EYc61VrGAtqaPaA5XiH4TzPfvio9mHmZD+JME8Xed5LrjsbyAQf673C9y2C+7iwGcHZodjXitCkvL72FDO56E50Dw2/acgmVUluYTsYoKd3lqSnMPjTIQ6lJfLayMtN+d1WQkVUNdfEukGIQlZXWxEdi/eSXIhF5b+JVJoSw0UxfaWR6tMHLjOZIM5yON8gT2PSwFIBnQ7Ruy+tmUuKNJoZvo/l+qu55Y0OB2G3z0KMgxeedLPWUXQdj+BVKjfVXFu9k1qmVScIbNMucbp7V1RGPR0PNKQK1SRadWVnIAPZGkCpSq4R3LvtPze9xfiLxaUiqTsS6D8qSMf2NfyVj+3yWO3kTehS5iH8ohjPOhvES+sDqxWd3E/c8nfbbxdF/TOSaer7I11xHWqH25oGg6mdn5EJ6p/iaQmDAvhiwavQYx9yDLEVlmsFu6WIQTJ/WH29m8IRRdjb9tvTxv7c4z7w1A7lNQ1ceEaH/WZPlPEL5N2JIV+lQcxCd5bFsVe1QP20Pwad3ssADnOB9S4m8AxSXNcmt76hDt4F45JgCGEBh7DRYEMK83zorQjCwfw+kir6acFMeJCBuVfWo79vHNThC9cZqhLMx8ORNTum89V1f1/7veROpmK5E3Sko1UQOKA0hOJ6oiXMvRl2xNdUcelwgq/yhjYD9HYWe4gSMtnWuWetGedUFp8XbC6bsWD9JBjtm5NN2cqEFWhfZ9BW7RyUW1374mLR/NrIe5yjH86TzvoM7ZzX1v1GlJN128eVqf9YL5RV8jyEHSUBg5aFeuhGe+EIJz92mjou29cz3K/oK031bKkcbp8/LS847cApdYeXh+wfosg56YQM2EFIIt1B1Snur0ZQzbxkT9qsDfdMBFUvplcvOGb/teZp86mHtj3tBkEVY79oaR74Pgum38hSVuKOEdzxWy7m68T5u1cFY4DRAngYgV86YVfmWqqIv5zlH/Z0gCkw9AShc2no4oO9htjJeGdnVhhQlcLBBa0kgGnSiCu1v4uMx2RPQM2bAmZRlCSwkExjwa9+LMlgwE5eu9udU4Mim7jtIIr1iwdZiAMswzt08HZrZg+ui2LhtCWlinCe5XVS9/IoFj6QY1FMK4lP7kcqhfFv28GnP4eo1qVMRMK91OSzpg94givNGd96qluU0uIQLzKg3zihQDFT+YnQ3ljds2ElqRVznj7Jvxar4/ZrIdvgoE1jJNIDBwPzW5iaL+gyYVjrs1ZIP0H42IqlKGfmFdYpDl+hhNsH5A382CfTvScrjdo9GZcO4d1P2G3xfFAldsh/GZaPnIvsWN1ozurhHBpZ8kMHe14hLeOwIt1471o3M7HTNoHkBcZvkoOf6k/y0A6axJNYgrc11Yc/oMuX484tEyin8oOUEq1wK6Hvo1gMKb0Os8Fjk/FpsvZ2Sud0RpL3Pk4LYdQEEtYmghZsIaCNrfpxZD7z X-OriginatorOrg: vmware.com X-MS-Exchange-CrossTenant-Network-Message-Id: c2970139-a825-4373-0777-08dbebb32288 X-MS-Exchange-CrossTenant-AuthSource: MWHPR05MB3648.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Nov 2023 23:31:21.7230 (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: +y6PAigsyXOJNLutnlfU9C0CJE1QKpHcjiRR1cepe3facbjDP8BBvpbsc6vy+6NVXPh6c66PkotIMwOwe/Ep3g== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY3PR05MB8275 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 --- 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)