From nobody Fri Aug 11 10:09:02 2023 X-Original-To: dev-commits-src-branches@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4RMfdq275vz4pqv6; Fri, 11 Aug 2023 10:09:03 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4RMfdp6hgcz3Vsj; Fri, 11 Aug 2023 10:09:02 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1691748542; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=6fOLL4sP4cDiX8eiqglMZB79glWtvAxA3kTdZeq1KMU=; b=NhI8lu60fCvzUZpuy0PuB3JF/8rCV2fyxTkAiBjpcOvTOgoGIV9tKr6fBuBmLuDISMWGhe 74S+NAhouNSQij4WVgv5B8rOldCplw7fnmbX0NYa9FhPZ7DGhNyE0R84Z8y2NHfknedSjz hq3autkBZvCBdgzBGPp/amUkrpGEWD/e2DYvi9PDZL9Mjx+tmENcvywTHbo9n1CNCWibGM S6CEA3mXSheDr/5+kkQwaKhWOjpgt7ZRDD2W4hXHK0lzpakQveIBRKo/I49KxsoNJIon3/ R8x3f0PYmPOOOXqpaVnMn4CH/0HhLl0XuYVmMs63o0XqAwvrhNfNy68liOiV1Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1691748542; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=6fOLL4sP4cDiX8eiqglMZB79glWtvAxA3kTdZeq1KMU=; b=vAM80zGojhJrCFENx/DnldsOGbqnkogJbP9Wtej+cnE3maY2xYkcBn1L3DyG2RGoXz83/z OQc5fZRD1IhOwEawpYVdQaYi9Wlf6a8u2BbUG1hMubPOgyW+iKOUlGNUokWPXqOhnj8fOz kqgui2LjOMjgvLsak1uX1MF7C4BjCEBhZcVjBeZ79/GwXSgnAp9eHxuFBSab+isZxbsSIa YneLpp7je5p0W4yrDt3EiNKUzO+TpgnU6sBC8NZeJNwkfkgJDGOYZp7tStPK5LZCfYIrJf Zu1j7Erw+l9CJnVLB/3wtEHE4aetBCtCwiaZMfqEhq5qWo/559Pwa3UoFlRsfw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1691748542; a=rsa-sha256; cv=none; b=aBFW8CXDWFqk3KU22W07naQddsDJqEZeDADoLxe2PNs7ZqqTUpqrGT0a3CexT9Kyrt8N5P hkOEla1XyU3iVOtcV9KeQA8ecRM8TV/FAa+tfLSj00bJHV7wufZ3OEovA66BCP8PsDYn8P OPNULzm5UW9gA25+Rk60rS98R4c34++16JpjcB5t5wdpSSPONS5G3y+dJPTP57CLfs5k5Q BmkE11libYEDRqzBcBPe+5rzn2wL4HaOdNJhqlA6Nhx3CQ7b6/Y52NIWKqudV2PUzIiQpw xJsAlCxha0Frwj4imE4VlCK5ok8hDvyM7JtiqerVrhtJLq2IAWrNv0KwKKoNTg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4RMfdp5gNBzbLC; Fri, 11 Aug 2023 10:09:02 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 37BA92hN093817; Fri, 11 Aug 2023 10:09:02 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 37BA92oG093814; Fri, 11 Aug 2023 10:09:02 GMT (envelope-from git) Date: Fri, 11 Aug 2023 10:09:02 GMT Message-Id: <202308111009.37BA92oG093814@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Dmitry Chagin Subject: git: 97cbac33c6d2 - stable/13 - linux(4): Add elf_hwcap2 to x86 List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-branches@freebsd.org X-BeenThere: dev-commits-src-branches@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: dchagin X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 97cbac33c6d223617b0084a64bd55b0e3b8ec549 Auto-Submitted: auto-generated The branch stable/13 has been updated by dchagin: URL: https://cgit.FreeBSD.org/src/commit/?id=97cbac33c6d223617b0084a64bd55b0e3b8ec549 commit 97cbac33c6d223617b0084a64bd55b0e3b8ec549 Author: Dmitry Chagin AuthorDate: 2023-07-28 08:56:59 +0000 Commit: Dmitry Chagin CommitDate: 2023-08-11 10:08:31 +0000 linux(4): Add elf_hwcap2 to x86 On x86 Linux via AT_HWCAP2 the user controlled (by tunables) processor capabilities are exposed. Reviewed by: Differential Revision: https://reviews.freebsd.org/D41165 MFC after: 2 weeks (cherry picked from commit 4281dab8bc11b3b2f3b58be5e0f67806329bddae) --- sys/amd64/linux/linux_sysvec.c | 2 +- sys/amd64/linux32/linux32_sysvec.c | 2 +- sys/i386/linux/linux.h | 2 +- sys/i386/linux/linux_sysvec.c | 1 + sys/x86/linux/linux_x86.c | 18 +++++++++++++++++- sys/x86/linux/linux_x86.h | 6 ++++++ 6 files changed, 27 insertions(+), 4 deletions(-) diff --git a/sys/amd64/linux/linux_sysvec.c b/sys/amd64/linux/linux_sysvec.c index 290e21247b0d..dde7ae571524 100644 --- a/sys/amd64/linux/linux_sysvec.c +++ b/sys/amd64/linux/linux_sysvec.c @@ -232,7 +232,7 @@ linux64_arch_copyout_auxargs(struct image_params *imgp, Elf_Auxinfo **pos) AUXARGS_ENTRY((*pos), LINUX_AT_SYSINFO_EHDR, linux_vdso_base); AUXARGS_ENTRY((*pos), LINUX_AT_HWCAP, cpu_feature); - AUXARGS_ENTRY((*pos), LINUX_AT_HWCAP2, 0); + AUXARGS_ENTRY((*pos), LINUX_AT_HWCAP2, linux_x86_elf_hwcap2()); AUXARGS_ENTRY((*pos), LINUX_AT_PLATFORM, PTROUT(linux_platform)); } diff --git a/sys/amd64/linux32/linux32_sysvec.c b/sys/amd64/linux32/linux32_sysvec.c index 2a7860cc3381..da5f585a2696 100644 --- a/sys/amd64/linux32/linux32_sysvec.c +++ b/sys/amd64/linux32/linux32_sysvec.c @@ -146,7 +146,7 @@ linux32_arch_copyout_auxargs(struct image_params *imgp, Elf_Auxinfo **pos) AUXARGS_ENTRY((*pos), LINUX_AT_SYSINFO, __kernel_vsyscall); AUXARGS_ENTRY((*pos), LINUX_AT_SYSINFO_EHDR, linux_vdso_base); AUXARGS_ENTRY((*pos), LINUX_AT_HWCAP, cpu_feature); - AUXARGS_ENTRY((*pos), LINUX_AT_HWCAP2, 0); + AUXARGS_ENTRY((*pos), LINUX_AT_HWCAP2, linux_x86_elf_hwcap2()); AUXARGS_ENTRY((*pos), LINUX_AT_PLATFORM, PTROUT(linux_platform)); } diff --git a/sys/i386/linux/linux.h b/sys/i386/linux/linux.h index 4784be5b0f77..dff4ed449943 100644 --- a/sys/i386/linux/linux.h +++ b/sys/i386/linux/linux.h @@ -94,7 +94,7 @@ typedef struct { /* * Miscellaneous */ -#define LINUX_AT_COUNT 21 /* Count of used aux entry types. +#define LINUX_AT_COUNT 22 /* Count of used aux entry types. * Keep this synchronized with * linux_copyout_auxargs() code. */ diff --git a/sys/i386/linux/linux_sysvec.c b/sys/i386/linux/linux_sysvec.c index c486fe1a09a5..09f11340b414 100644 --- a/sys/i386/linux/linux_sysvec.c +++ b/sys/i386/linux/linux_sysvec.c @@ -145,6 +145,7 @@ linux32_arch_copyout_auxargs(struct image_params *imgp, Elf_Auxinfo **pos) AUXARGS_ENTRY((*pos), LINUX_AT_SYSINFO_EHDR, linux_vdso_base); AUXARGS_ENTRY((*pos), LINUX_AT_SYSINFO, __kernel_vsyscall); AUXARGS_ENTRY((*pos), LINUX_AT_HWCAP, cpu_feature); + AUXARGS_ENTRY((*pos), LINUX_AT_HWCAP2, linux_x86_elf_hwcap2()); AUXARGS_ENTRY((*pos), LINUX_AT_PLATFORM, PTROUT(linux_platform)); } diff --git a/sys/x86/linux/linux_x86.c b/sys/x86/linux/linux_x86.c index 34ae66ec4954..c72102d9f426 100644 --- a/sys/x86/linux/linux_x86.c +++ b/sys/x86/linux/linux_x86.c @@ -31,7 +31,9 @@ __FBSDID("$FreeBSD$"); #include #include +#include #include +#include #include @@ -96,4 +98,18 @@ bsd_to_linux_trapcode(int code) return (code < nitems(_bsd_to_linux_trapcode) ? _bsd_to_linux_trapcode[code] : LINUX_T_UNKNOWN); -} \ No newline at end of file +} + +u_int +linux_x86_elf_hwcap2(void) +{ + static u_int elf_hwcap2 = 0; + static bool elf_hwcap2_valid = false; + + if (!elf_hwcap2_valid) { + if ((cpu_stdext_feature & CPUID_STDEXT_FSGSBASE) != 0) + elf_hwcap2 |= LINUX_HWCAP2_FSGSBASE; + elf_hwcap2_valid = true; + } + return (elf_hwcap2); +} diff --git a/sys/x86/linux/linux_x86.h b/sys/x86/linux/linux_x86.h index 2763b60f1649..5ce0852d9a18 100644 --- a/sys/x86/linux/linux_x86.h +++ b/sys/x86/linux/linux_x86.h @@ -32,10 +32,16 @@ #define LINUX_VDSO_CPU_RDPID 1 #define LINUX_VDSO_CPU_RDTSCP 2 +/* More machine dependent hints about processor capabilities. */ +#define LINUX_HWCAP2_RING3MWAIT 0x00000001 +#define LINUX_HWCAP2_FSGSBASE 0x00000002 + int linux_vdso_tsc_selector_idx(void); int linux_vdso_cpu_selector_idx(void); int linux_translate_traps(int, int); int bsd_to_linux_trapcode(int); +u_int linux_x86_elf_hwcap2(void); + #endif /* _X86_INCLUDE_LINUX_LINUX_X86_H_ */