通过getauxval检测Power8内核密码? [英] Detect Power8 in-core crypto through getauxval?
问题描述
我正在使用GCC112,这是一台运行Linux的低端Power8计算机。 Power8具有核心加密提供AES,SHA和其他一些有用的功能。我正在尝试使用 getauxval
确定运行时功能的可用性。用例是为具有最小功能的计算机构建发行版,我们需要在运行时交换更快的功能。
hwcaps.h
如下所示,但是它缺少Power8,AES,SHA等的特定位。但是,我相信Power8是ISA 2.07,而ISA 2.07具有 PPC_FEATURE2_ARCH_2_07
的位。
我不是很明显,Power8内核加密是可选的,就像ARMv8下的ARM加密一样。我找不到明确说明要求的文档,并且我没有 OpenPower 的成员身份才能访问ISA文件。 (另一种可能性是,它已声明,但我在文档中错过了它。)
是否有可能使用 getauxval
在运行时环境中查询功能?如果不是,那么我们如何确定运行时的功能可用性?
也许更笼统地说,我们如何确定Power6,Power7和Power8运行时环境?
auxv.h
大部分为空。头文件包括 hwcaps.h
。
$ cat / usr / include / bits / hwcap.h
...
/ *位号必须与内核的asm / cputable.h中的位号匹配。 * /
/ * AT_HWCAP中的功能定义。 * /
#定义PPC_FEATURE_32 0x80000000 / * 32位模式。 * /
#定义PPC_FEATURE_64 0x40000000 / * 64位模式。 * /
#define PPC_FEATURE_601_INSTR 0x20000000 / * 601芯片,旧POWER ISA。 * /
#定义PPC_FEATURE_HAS_ALTIVEC 0x10000000 / * SIMD /向量单元。 * /
#定义PPC_FEATURE_HAS_FPU 0x08000000 / *浮点单元。 * /
#定义PPC_FEATURE_HAS_MMU 0x04000000 / *内存管理单元。 * /
#定义PPC_FEATURE_HAS_4xxMAC 0x02000000 / * 4xx乘法累加器。 * /
#定义PPC_FEATURE_UNIFIED_CACHE 0x01000000 / *统一I / D缓存。 * /
#define PPC_FEATURE_HAS_SPE 0x00800000 / *信号处理分机* /
#define PPC_FEATURE_HAS_EFP_SINGLE 0x00400000 / * SPE浮动。 * /
#定义PPC_FEATURE_HAS_EFP_DOUBLE 0x00200000 / * SPE Double。 * /
#define PPC_FEATURE_NO_TB 0x00100000 / * 601 / 403gx没有时基* /
#define PPC_FEATURE_POWER4 0x00080000 / * POWER4 ISA 2.00 * /
#define PPC_FEATURE_POWER5 0x00040000 / * 5
#define PPC_FEATURE_POWER5_PLUS 0x00020000 / * POWER5 + ISA 2.03 * /
#define PPC_FEATURE_CELL_BE 0x00010000 / * CELL宽带引擎* /
#define PPC_FEATURE_BOOKE 0x00008000 / * ISA类别嵌入式* / $ b定义PPC_FEATURE_SMT 0x00004000 / *同时执行
多线程* /
#define PPC_FEATURE_ICACHE_SNOOP 0x00002000
#define PPC_FEATURE_ARCH_2_05 0x00001000 / * ISA 2.05 * /
x_PAT_PAT_T * PFA6_6核心* /
#define PPC_FEATURE_HAS_DFP 0x00000400 / *十进制FP单元* /
#define PPC_FEATURE_POWER6_EXT 0x00000200 / * P6 + mffgpr / mftgpr * /
#define PPC_FEATURE_ARCH_2_06 0x 00000100 / * ISA 2.06 * /
#定义PPC_FEATURE_HAS_VSX 0x00000080 / * P7向量扩展名。 * /
#define PPC_FEATURE_PSERIES_PERFMON_COMPAT 0x00000040
#define PPC_FEATURE_TRUE_LE 0x00000002
#define PPC_FEATURE_PPC_LE 0x00000001
/ * AT_HWCAP2中的功能定义。 * /
#define PPC_FEATURE2_ARCH_2_07 0x80000000 / * ISA 2.07 * /
#define PPC_FEATURE2_HAS_HTM 0x40000000 / *硬件事务性
内存* /
#define PPC_FEATURE2_HAS_DSCR 0x20000000b / *数据流$ b寄存器* /
#define PPC_FEATURE2_HAS_EBB 0x10000000 / *事件分支* /
#define PPC_FEATURE2_HAS_ISEL 0x08000000 / *整数选择* /
#define PPC_FEATURE2_HAS_TAR 0x04000000 / *目标地址寄存器b $ b
我会说 getauxval ()
将是最好的方法; HWCAP
& HWCAP2
值恰好用于确定硬件功能。您列表中缺少的是 PPC_FEATURE2_VEC_CRYPTO
,它表示存在矢量加密指令,听起来像您需要的那个。
作为旁注:您可能不想检测处理器实现,但是要检测处理器功能。具体来说,请检查单个功能,而不要尝试检查提供该功能的过程。 (例如,直接检测 VEC_CRYPTO
,而不是尝试检查POWER8,并假定这暗示了加密功能)。
作为一点细节,Linux的可计算条目指定 HWCAP
/ HWCAP2
值。以POWER8为例:
#define COMMON_USER2_POWER8(PPC_FEATURE2_ARCH_2_07 | \
$ p
PPC_FEATURE2_HTM_COMP | \
PPC_FEATURE2_HTM_NOSC_COMP | \
PPC_FEATURE2_DSCR | \
PPC_FEATURE2_ISEL | PPC_FEATURE2_TAR | \
PPC_FEATURE2_VEC_CRYPTO)
来自内核中的
arch / powerpc / include / asm / cputable.h
(还提供了实际的hwcap位
最后,我很确定您不需要成为OpenPOWER基金会成员即可下载ISA(最新版本为3.0B)-您只需要在网站上注册一个帐户即可。
I'm on GCC112, which is a little-endian Power8 machine running Linux. Power8 has in-core crypto providing AES, SHA and a few other useful features. I'm trying to determine the availability of the features at runtime using
getauxval
. The use case is distros building for a "minimum" capable machine, and we need to swap-in a faster function at runtime.The dump of
hwcaps.h
is shown below, but it lacks specific bits for Power8, AES, SHA and others. However, I believe Power8 is ISA 2.07, and ISA 2.07 has the bitPPC_FEATURE2_ARCH_2_07
.The thing I am not clear on is, is Power8 in-core crypto optional like ARM's crypto under ARMv8. I can't find a document that clearly states the requirement, and I don't have a membership to OpenPower to access ISA documents. (Another possibility is, it is stated but I missed it in the docs).
Is it possible to use
getauxval
to query the runtime environment for the features? If not, then how do we determine feature availability at runtime? Is CPU probing the only alternative available?Maybe more generally, how do we determine Power6, Power7 and Power8 runtime environments?
auxv.h
is mostly empty. The header file includeshwcaps.h
.$ cat /usr/include/bits/hwcap.h ... /* The bit numbers must match those in the kernel's asm/cputable.h. */ /* Feature definitions in AT_HWCAP. */ #define PPC_FEATURE_32 0x80000000 /* 32-bit mode. */ #define PPC_FEATURE_64 0x40000000 /* 64-bit mode. */ #define PPC_FEATURE_601_INSTR 0x20000000 /* 601 chip, Old POWER ISA. */ #define PPC_FEATURE_HAS_ALTIVEC 0x10000000 /* SIMD/Vector Unit. */ #define PPC_FEATURE_HAS_FPU 0x08000000 /* Floating Point Unit. */ #define PPC_FEATURE_HAS_MMU 0x04000000 /* Memory Management Unit. */ #define PPC_FEATURE_HAS_4xxMAC 0x02000000 /* 4xx Multiply Accumulator. */ #define PPC_FEATURE_UNIFIED_CACHE 0x01000000 /* Unified I/D cache. */ #define PPC_FEATURE_HAS_SPE 0x00800000 /* Signal Processing ext. */ #define PPC_FEATURE_HAS_EFP_SINGLE 0x00400000 /* SPE Float. */ #define PPC_FEATURE_HAS_EFP_DOUBLE 0x00200000 /* SPE Double. */ #define PPC_FEATURE_NO_TB 0x00100000 /* 601/403gx have no timebase */ #define PPC_FEATURE_POWER4 0x00080000 /* POWER4 ISA 2.00 */ #define PPC_FEATURE_POWER5 0x00040000 /* POWER5 ISA 2.02 */ #define PPC_FEATURE_POWER5_PLUS 0x00020000 /* POWER5+ ISA 2.03 */ #define PPC_FEATURE_CELL_BE 0x00010000 /* CELL Broadband Engine */ #define PPC_FEATURE_BOOKE 0x00008000 /* ISA Category Embedded */ #define PPC_FEATURE_SMT 0x00004000 /* Simultaneous Multi-Threading */ #define PPC_FEATURE_ICACHE_SNOOP 0x00002000 #define PPC_FEATURE_ARCH_2_05 0x00001000 /* ISA 2.05 */ #define PPC_FEATURE_PA6T 0x00000800 /* PA Semi 6T Core */ #define PPC_FEATURE_HAS_DFP 0x00000400 /* Decimal FP Unit */ #define PPC_FEATURE_POWER6_EXT 0x00000200 /* P6 + mffgpr/mftgpr */ #define PPC_FEATURE_ARCH_2_06 0x00000100 /* ISA 2.06 */ #define PPC_FEATURE_HAS_VSX 0x00000080 /* P7 Vector Extension. */ #define PPC_FEATURE_PSERIES_PERFMON_COMPAT 0x00000040 #define PPC_FEATURE_TRUE_LE 0x00000002 #define PPC_FEATURE_PPC_LE 0x00000001 /* Feature definitions in AT_HWCAP2. */ #define PPC_FEATURE2_ARCH_2_07 0x80000000 /* ISA 2.07 */ #define PPC_FEATURE2_HAS_HTM 0x40000000 /* Hardware Transactional Memory */ #define PPC_FEATURE2_HAS_DSCR 0x20000000 /* Data Stream Control Register */ #define PPC_FEATURE2_HAS_EBB 0x10000000 /* Event Base Branching */ #define PPC_FEATURE2_HAS_ISEL 0x08000000 /* Integer Select */ #define PPC_FEATURE2_HAS_TAR 0x04000000 /* Target Address Register */
解决方案I'd say that
getauxval()
would be the best way to do this; theHWCAP
&HWCAP2
values are exactly for determining hardware features. Missing from your list is thePPC_FEATURE2_VEC_CRYPTO
, which indicates the presence of the vector crypto instructions, which sounds like the one you need.As a side note: you probably don't want to detect processor implementations, but processor features. Specifically, check for the individual feature, rather than trying to check for a process that provides that feature. (eg., detect
VEC_CRYPTO
directly, rather than trying to check for POWER8, and assume that that implies crypto functionality).As a bit of detail, Linux's cputable entries specify the
HWCAP
/HWCAP2
values. Using POWER8 as an example:#define COMMON_USER2_POWER8 (PPC_FEATURE2_ARCH_2_07 | \ PPC_FEATURE2_HTM_COMP | \ PPC_FEATURE2_HTM_NOSC_COMP | \ PPC_FEATURE2_DSCR | \ PPC_FEATURE2_ISEL | PPC_FEATURE2_TAR | \ PPC_FEATURE2_VEC_CRYPTO)
That's from
arch/powerpc/include/asm/cputable.h
in the kernel (which also provides the actual hwcap bits that can be set in the aux vector).Finally, I'm fairly sure you don't need to be an OpenPOWER foundation member to download the ISA (latest is 3.0B) - you just need an account on the website.
这篇关于通过getauxval检测Power8内核密码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!