From patchwork Fri May 31 19:38:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Hubbard X-Patchwork-Id: 13682045 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2063.outbound.protection.outlook.com [40.107.244.63]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5E14817E479; Fri, 31 May 2024 19:38:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.244.63 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717184332; cv=fail; b=e8rgw9rNBNn/3iUlC//HeCbvdkVDPU49DgFtKy34wNMKXi/y5wwVWj5Q5kbpeFh3rOC+bhxcrNFoDdJJIB70WbObS6GhbaAKXAK0UKhAprwIatGxVKAmB8vA4clKjeOc50BOdkPIiPpexywsaxP59dSCZiJ8rtfqEzsCkscsR4E= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717184332; c=relaxed/simple; bh=mBCT2MCnrTyQltQDei7ef7SuHYpumNtvDyYn7JVI9yc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=PAbKV+VIBTpyrq6wWhxx2tuULMGS4xDLqu50JIGOxreNk2UPK7yl5d9GDpMgCnyOk4H5sxlEK/+5F2uzCMUIwF2AaY2g2uN6gKmyqphREtH8tXATZaQvvxgGNGfMICyO5Ml0K9zMtZhLpNFMV0H0oMk1mGYTyk7LLdjWr0gENjo= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=AeO6DSEi; arc=fail smtp.client-ip=40.107.244.63 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="AeO6DSEi" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=jObT7CsRZuUVVi6Vv1e8SVO2Rd2knKVMCR+JYf5OE3Cw/UO8jwdbxrJ8Owr2+ELOGVCxpH69JI4MbLInNSoP7bSJfqQwEgdOvXQDAVwhcBHTd/dl/BRmoNZHkwEmMIjjUBcSyQmg+TvVy98pcAjSbZYEr7X4sJD2T+R1R/GrjEKEkJZyRlcmwubLc8x91kY371VQ/Qr6CDOuxcFw+u9xXiAkF9knmZiVqJDu3ypN3fVFVwMh7ou4bkoC1HpIiCSzKjfxVu0pXclNS0quOIxF+COrsRqX+Ps8w86whlDvDWzivd2LfnOeuxuqBstqhNgWcURP8eL6eowYYlFKP+GcQg== 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=/tkbxLO6jAdxUKHgdSlhyseHH0AZgmarl1xrRnVbabo=; b=LO2crAuIUt/aVXXuKe1I2QyDX16BdNmmvhUdRL/0cF1gMw0/onC/fPDoUyRtImiZTuvsTZ49FMENm9BcBaGqAs7cKX7AdaBcnzkAxD04yFsCxxePNOjdRR5XpE0PacLwuOjwL2TwDB2DXZ5/ba4JaNfZl3BUweWV0EDpUfpjLolGZ/Wehsf/EYq12wEwHIPmke0AxYrhWWPX8Qs0Aq9ctgHDP68G4MyCiDwyZaRiN1EcmBAv7Cyut4O/rDbbEJ/DOzuOx8aCfQmosx9zlgfC8wMXff9FG4TFKIf5RDZYWgjqcnb72TB1PQ3wrlkboO1/fy8YfgHCXE7Vh6vxlPDLZQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=/tkbxLO6jAdxUKHgdSlhyseHH0AZgmarl1xrRnVbabo=; b=AeO6DSEiVWTbRwjUSfG7hUoCdaKBoUpX+5Nvf1SQn6H1DzEDdlvuzpLQj4xufTPxGS6UbRuqlrJqrAEXn3hc5pvZWb817Gb4MUlD6Hxat6FVfjy8LjG6W/Lw0opy9t/4834celb7siZgw9L6a3HRHt1b1eZcu2ZqQDxfAlkL2ydRSmQHwyIiTLoOI/Kef9mdwPWn7AQMBTXNXtnOG8tUQFTk7Cv36uyCARX+wjcco1aWikPuRbc3+H+Yr873/95BzyG8Kn/NVi/u25+WycCo6PN41I5gvhfk961603CXmZQfxII3dPrjJcds8bMrU4KV36FLtkHoPt3Q8efuVU/8XQ== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from BY5PR12MB4130.namprd12.prod.outlook.com (2603:10b6:a03:20b::16) by IA1PR12MB7712.namprd12.prod.outlook.com (2603:10b6:208:420::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7611.29; Fri, 31 May 2024 19:38:42 +0000 Received: from BY5PR12MB4130.namprd12.prod.outlook.com ([fe80::2cf4:5198:354a:cd07]) by BY5PR12MB4130.namprd12.prod.outlook.com ([fe80::2cf4:5198:354a:cd07%4]) with mapi id 15.20.7633.021; Fri, 31 May 2024 19:38:42 +0000 From: John Hubbard To: Shuah Khan Cc: angquan yu , "Kirill A . Shutemov" , Ingo Molnar , Binbin Wu , Alexey Dobriyan , Rick Edgecombe , Sohil Mehta , Yu-cheng Yu , Dave Hansen , Muhammad Usama Anjum , Valentin Obst , linux-kselftest@vger.kernel.org, LKML , llvm@lists.linux.dev, x86@kernel.org, John Hubbard Subject: [PATCH v3 3/7] selftests/x86: build fsgsbase_restore.c with clang Date: Fri, 31 May 2024 12:38:34 -0700 Message-ID: <20240531193838.108454-4-jhubbard@nvidia.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240531193838.108454-1-jhubbard@nvidia.com> References: <20240531193838.108454-1-jhubbard@nvidia.com> X-NVConfidentiality: public X-ClientProxiedBy: SJ0PR05CA0020.namprd05.prod.outlook.com (2603:10b6:a03:33b::25) To BY5PR12MB4130.namprd12.prod.outlook.com (2603:10b6:a03:20b::16) Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BY5PR12MB4130:EE_|IA1PR12MB7712:EE_ X-MS-Office365-Filtering-Correlation-Id: 41ec0ea3-9747-4a06-4d20-08dc81a94726 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|1800799015|376005|7416005|366007; X-Microsoft-Antispam-Message-Info: QyHmoPwtXAhotRQJvtysALnE/bU3lDpBCr0ga7s41aKTuNwNsa4TPp30AUdcr2QthQUYwidBOd6nv1ignUNk/Q/p6apwB+k3ny4KdbpzAOCgN0qZlw3yQepB2G5RMhDLnnqKZ4DxcNoCWN9BycaCrwmb9Kj/hp95zz3Otvl4i7dSIqCDsO6Ew6sh+M9Oz5qD8vTtb/iUTizFeL9BV8tFmq8gsg84tG0AlbXq4iG9sK8K/sWY+7Spi6Jx2PDk7rfDuPQpxVI3kNJrpov78n1VCylhHLwKCS0uw+KsuOPhtQveHfD3kZA9mFfrhJFPe0KRA/DI8xhXSOa0nXv3+v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;CAT:NONE;SFS:(13230031)(1800799015)(376005)(7416005)(366007);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: r/EPgmt8j3KggWG+L4lY0sOTlnbjPNzLXrxQRJ9zNtL/1pNzf3po7GAX4USRT2OMt8vgBWve/WYGPAILzsJqDtbLsEBjJRnfYK1PAlyf+UKJ/pQT1T1q5+02o76NSl287G+ooMyvh7qZaS39N0t94t6mTfaQdNGf85eNmMiXDfnVw7iL0nUGapZ03t8zRMQQmMVJqhA5qaoog04yZiO3Hh5kpuGEik+L+IjN0CYj5d1q4V6g67j73213Qbm6ZH8OCNh4MyiszCZ3LIK+EWhLe+tqlA9hGnup+LKj9s6n1+xJ26bpArYJk1p8WD7322knQUPRfSWn8VqQY/m+xLquXsGJrS2V/8sggxHj/vnnugB6Lj7TZ1WvIQaUeW38o/hcqsIf4uC5VdKjy02k2QuLYCtPYecgihrV+5oT+hZVREOEuayYFZJp8Igvtabq5ALLI74PyE3ImhIZDRSMMYGYKonaWByPaGpABi0n4RUYJJVlvVcJCFK4Nu0mj2/unNc22R0Eijpml2G8W1tKlor7gF9n3XzXFUIQU6ReGUblmknJvmm13Ca8ZreJCBm4jY+mza1H0asTnVaQluU9KPhEeQfo3atjgDD633Oc9fOvH1hvSepB+q3AyXa/KNeecANKB1XBMHRrFesGNrsowtD3GolDhKsJdLlgOFapDdXhdTa+Zrmd8SShdMdrIrLaGhckW8yr9+BFClQ8gLFjjvyRf9c5O6OoGeSt11OqisOxL/r9uwdPdFI6AxPLOX7Bgbln+f3WPsxj9b631y2kCC/ZkGBF1vosaZg0ijR80pQ4TnA78eajgJN3kUtv+D1S7ChMV2GwbhuYRUMqqbNrVMea9LEv+Q2WxTj+P6gKIPhqzRo600PdaMgoh35m3wv2tG1WdhAAh50+8K+hkYEWJBJBE/FWjZ0jBfG5xiYT0U9pbBLVIBQHAllYxBIid0xIYDbQtzCzA6AYHYhPrdELVwWpVWhVGgmnbNhs7axBsgzJ4LTXB32QG4/NyFmgdU6jyzEPPDtiglYfH37teBl9ByphWCMgGSab401k05syOIx2qrbSJ8fauo9AZkN6xQCHx71S1cEpkQeirx4HsLqeRY1yVnHR4Hc+FcHMV0qyL7fc14eHiU0w2qygJvnrw61xAM25AYIirksj0hj03sCJHC9mEb4DXnVLGGTJgPCszoVMgzCHG9677Hoev3O6Tuvr+TVyHsOZrDL5i2gb5Hu4SdlCsVaFPFW6NgIubXX+5IinyCb3HdEicLcaUl/cFH1teYW/KkwQzbLMlEwrVisoMaIy1tjrdp0Km8REQbzhtAgvrQDxM3Czl/qDBaTKuYNvbnnTkDKRfCMW/B6hp45YOvMQPT6rCpzyxBvhjTNLphDD/kNr/QiyDcqVSJoutebiQ2QK0Cp9I3ZEmF2NpfQfxK/gjwumEJFmH7vq/WJssT79+rKpLTwZ9Dpd/PykkX07g2UybUHEqGXpihpcGj6V/7GK+kyGOo46/AaD1MzQJZV2FpfHDehRL9kQJ1Zt8boVB4dC5h3M1g+M9Umi0mYcmfTE04YxM+3GqAHEuiBGR3T4n9E3Dd1xZgkk9VG3mYVmEXG7 X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 41ec0ea3-9747-4a06-4d20-08dc81a94726 X-MS-Exchange-CrossTenant-AuthSource: BY5PR12MB4130.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 May 2024 19:38:42.3617 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: Rz/TvqQZPWRsrcDomN7e6KpAjq7Knvl1XKZj3YHQt4wBAaljqJT8kBP8eul2+sTBttnt5Gj2DpylX3fITAcNRg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR12MB7712 When building with clang, via: make LLVM=1 -C tools/testing/selftests Fix this by moving the inline asm to "pure" assembly, in two new files: clang_helpers_32.S, clang_helpers_64.S. As a bonus, the pure asm avoids the need for ifdefs, and is now very simple and easy on the eyes. Signed-off-by: John Hubbard --- tools/testing/selftests/x86/Makefile | 2 ++ tools/testing/selftests/x86/clang_helpers_32.S | 11 +++++++++++ tools/testing/selftests/x86/clang_helpers_64.S | 12 ++++++++++++ tools/testing/selftests/x86/fsgsbase_restore.c | 11 +++++------ 4 files changed, 30 insertions(+), 6 deletions(-) create mode 100644 tools/testing/selftests/x86/clang_helpers_32.S create mode 100644 tools/testing/selftests/x86/clang_helpers_64.S diff --git a/tools/testing/selftests/x86/Makefile b/tools/testing/selftests/x86/Makefile index c1269466e0f8..99bc2ef84f5a 100644 --- a/tools/testing/selftests/x86/Makefile +++ b/tools/testing/selftests/x86/Makefile @@ -113,6 +113,8 @@ endef $(eval $(call extra-files,sysret_ss_attrs_64,thunks.S)) $(eval $(call extra-files,ptrace_syscall_32,raw_syscall_helper_32.S)) $(eval $(call extra-files,test_syscall_vdso_32,thunks_32.S)) +$(eval $(call extra-files,fsgsbase_restore_64,clang_helpers_64.S)) +$(eval $(call extra-files,fsgsbase_restore_32,clang_helpers_32.S)) # check_initial_reg_state is special: it needs a custom entry, and it # needs to be static so that its interpreter doesn't destroy its initial diff --git a/tools/testing/selftests/x86/clang_helpers_32.S b/tools/testing/selftests/x86/clang_helpers_32.S new file mode 100644 index 000000000000..dc16271bac70 --- /dev/null +++ b/tools/testing/selftests/x86/clang_helpers_32.S @@ -0,0 +1,11 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * 32-bit assembly helpers for asm operations that lack support in both gcc and + * clang. For example, clang asm does not support segment prefixes. + */ +.global dereference_seg_base +dereference_seg_base: + mov %fs:(0), %eax + ret + +.section .note.GNU-stack,"",%progbits diff --git a/tools/testing/selftests/x86/clang_helpers_64.S b/tools/testing/selftests/x86/clang_helpers_64.S new file mode 100644 index 000000000000..0d81c71cad97 --- /dev/null +++ b/tools/testing/selftests/x86/clang_helpers_64.S @@ -0,0 +1,12 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * 64-bit assembly helpers for asm operations that lack support in both gcc and + * clang. For example, clang asm does not support segment prefixes. + */ +.global dereference_seg_base + +dereference_seg_base: + mov %gs:(0), %rax + ret + +.section .note.GNU-stack,"",%progbits diff --git a/tools/testing/selftests/x86/fsgsbase_restore.c b/tools/testing/selftests/x86/fsgsbase_restore.c index 6fffadc51579..224058c1e4b2 100644 --- a/tools/testing/selftests/x86/fsgsbase_restore.c +++ b/tools/testing/selftests/x86/fsgsbase_restore.c @@ -39,12 +39,11 @@ # define SEG "%fs" #endif -static unsigned int dereference_seg_base(void) -{ - int ret; - asm volatile ("mov %" SEG ":(0), %0" : "=rm" (ret)); - return ret; -} +/* + * Defined in clang_helpers_[32|64].S, because unlike gcc, clang inline asm does + * not support segmentation prefixes. + */ +unsigned int dereference_seg_base(void); static void init_seg(void) {