From 13ed231a0fad6e5988673dc8fde3996ad0136735 Mon Sep 17 00:00:00 2001 From: Jan Beulich Date: Thu, 17 Mar 2022 11:05:11 +0100 Subject: [PATCH] x86: never set i386_cpu_flags' "unused" field Setting this field risks cpu_flags_all_zero() mistakenly returning "false" when the object passed in was e.g. the result of ANDing together two objects which had the bit set, or ANDNing together an object with the field set and one with the field clear. While there also avoid setting CpuNo64: Like Cpu64 this is driven differently anyway and hence shouldn't be set anywhere by default. Note that the moving of the two items in i386-gen.c's cpu_flags[] is only for documentation purposes (and slight reducing of overhead), as the fields are sorted anyway upon program start. --- opcodes/i386-gen.c | 9 +++++---- opcodes/i386-init.h | 2 +- opcodes/i386-opc.h | 4 ++++ 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/opcodes/i386-gen.c b/opcodes/i386-gen.c index ae650d89597..d18a7d27545 100644 --- a/opcodes/i386-gen.c +++ b/opcodes/i386-gen.c @@ -628,8 +628,6 @@ static bitfield cpu_flags[] = BITFIELD (CpuPREFETCHWT1), BITFIELD (CpuSE1), BITFIELD (CpuCLWB), - BITFIELD (Cpu64), - BITFIELD (CpuNo64), BITFIELD (CpuMPX), BITFIELD (CpuAVX512IFMA), BITFIELD (CpuAVX512VBMI), @@ -676,6 +674,8 @@ static bitfield cpu_flags[] = BITFIELD (CpuINVLPGB), BITFIELD (CpuTLBSYNC), BITFIELD (CpuSNP), + BITFIELD (Cpu64), + BITFIELD (CpuNo64), #ifdef CpuUnused BITFIELD (CpuUnused), #endif @@ -1068,9 +1068,10 @@ process_i386_cpu_flag (FILE *table, char *flag, int macro, else next = flag + 1; - /* First we turn on everything except for cpu64. */ + /* First we turn on everything except for cpu64, cpuno64, and - if + present - the padding field. */ for (i = 0; i < ARRAY_SIZE (flags); i++) - if (flags[i].position != Cpu64) + if (flags[i].position < Cpu64) flags[i].value = 1; /* Turn off selective bits. */ diff --git a/opcodes/i386-init.h b/opcodes/i386-init.h index 393fdcabe6f..df2f7bcd498 100644 --- a/opcodes/i386-init.h +++ b/opcodes/i386-init.h @@ -25,7 +25,7 @@ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, \ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, \ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, \ - 1, 1, 0, 1, 1 } } + 1, 1, 0, 0, 0 } } #define CPU_GENERIC32_FLAGS \ { { 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \ diff --git a/opcodes/i386-opc.h b/opcodes/i386-opc.h index a7acaebe4bd..cba7cd2d36a 100644 --- a/opcodes/i386-opc.h +++ b/opcodes/i386-opc.h @@ -272,6 +272,9 @@ enum CpuTLBSYNC, /* SNP instructions required */ CpuSNP, + + /* NOTE: These last three items need to remain last and in this order. */ + /* 64bit support required */ Cpu64, /* Not supported in the 64bit mode */ @@ -417,6 +420,7 @@ typedef union i386_cpu_flags unsigned int cpuinvlpgb:1; unsigned int cputlbsync:1; unsigned int cpusnp:1; + /* NOTE: These last three fields need to remain last and in this order. */ unsigned int cpu64:1; unsigned int cpuno64:1; #ifdef CpuUnused -- 2.30.2