Skip to content

Commit 722b67c

Browse files
committed
cpuinfo: fix elf_hwcap change to bitmap
In 60c868eff2bc5 ("arm64/cpufeature: Store elf_hwcaps as a bitmap rather than unsigned long") the elf_hwcap variable on aarch64 was converted to a bitmap. Update the cpuinfo module to handle this. Orabug: 37894852 Signed-off-by: Stephen Brennan <[email protected]>
1 parent 5cec941 commit 722b67c

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

drgn_tools/cpuinfo.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from drgn import Object
1313
from drgn import Program
1414
from drgn import sizeof
15+
from drgn import TypeKind
1516
from drgn.helpers.linux.bitops import for_each_set_bit
1617
from drgn.helpers.linux.bitops import test_bit
1718
from drgn.helpers.linux.percpu import per_cpu
@@ -138,11 +139,18 @@ def aarch64_get_cpu_info(prog: Program) -> Dict[str, Any]:
138139
cpu_caps_list = []
139140

140141
hwcap_str = prog["hwcap_str"].read_()
141-
elf_hwcap = prog["elf_hwcap"].read_()
142+
elf_hwcap = prog["elf_hwcap"]
142143
num_caps = len(hwcap_str)
143144

145+
# Starting in v6.0, 60c868eff2bc5 ("arm64/cpufeature: Store elf_hwcaps as a
146+
# bitmap rather than unsigned long") converts what was an unsigned long, to
147+
# a bitmap. To make backwards compatibility easier, treat the old field as
148+
# bitmap by taking its address.
149+
if elf_hwcap.type_.kind == TypeKind.INT:
150+
elf_hwcap = elf_hwcap.address_of_()
151+
144152
for i in range(num_caps):
145-
if elf_hwcap & (1 << i):
153+
if test_bit(i, elf_hwcap):
146154
cpu_caps_list.append(hwcap_str[i].string_().decode("utf-8"))
147155

148156
midr_implementor = hex(

0 commit comments

Comments
 (0)