Skip to content

Commit d335af9

Browse files
committed
Export the ID_AA64ISARn_EL1 registers to userspace through sysctl(2) such
that we can detect which instruction set extensions are supported without relying in catching SIGILL. ok deraadt@
1 parent cf11bf5 commit d335af9

File tree

3 files changed

+30
-4
lines changed

3 files changed

+30
-4
lines changed

sys/arch/arm64/arm64/cpu.c

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $OpenBSD: cpu.c,v 1.61 2022/03/02 12:45:35 kettenis Exp $ */
1+
/* $OpenBSD: cpu.c,v 1.62 2022/03/23 23:36:35 kettenis Exp $ */
22

33
/*
44
* Copyright (c) 2016 Dale Rahn <[email protected]>
@@ -173,6 +173,9 @@ const struct implementers {
173173
char cpu_model[64];
174174
int cpu_node;
175175

176+
uint64_t cpu_id_aa64isar0;
177+
uint64_t cpu_id_aa64isar1;
178+
176179
#ifdef CRYPTO
177180
int arm64_has_aes;
178181
#endif
@@ -344,6 +347,15 @@ cpu_identify(struct cpu_info *ci)
344347
* Print CPU features encoded in the ID registers.
345348
*/
346349

350+
if (READ_SPECIALREG(id_aa64isar0_el1) != cpu_id_aa64isar0) {
351+
printf("\n%s: mismatched ID_AA64ISAR0_EL1",
352+
ci->ci_dev->dv_xname);
353+
}
354+
if (READ_SPECIALREG(id_aa64isar1_el1) != cpu_id_aa64isar1) {
355+
printf("\n%s: mismatched ID_AA64ISAR1_EL1",
356+
ci->ci_dev->dv_xname);
357+
}
358+
347359
printf("\n%s: ", ci->ci_dev->dv_xname);
348360

349361
/*
@@ -684,6 +696,9 @@ cpu_attach(struct device *parent, struct device *dev, void *aux)
684696
}
685697
} else {
686698
#endif
699+
cpu_id_aa64isar0 = READ_SPECIALREG(id_aa64isar0_el1);
700+
cpu_id_aa64isar1 = READ_SPECIALREG(id_aa64isar1_el1);
701+
687702
cpu_identify(ci);
688703

689704
if (OF_getproplen(ci->ci_node, "clocks") > 0) {

sys/arch/arm64/arm64/machdep.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $OpenBSD: machdep.c,v 1.68 2022/02/25 13:51:02 visa Exp $ */
1+
/* $OpenBSD: machdep.c,v 1.69 2022/03/23 23:36:35 kettenis Exp $ */
22
/*
33
* Copyright (c) 2014 Patrick Wildt <[email protected]>
44
* Copyright (c) 2021 Mark Kettenis <[email protected]>
@@ -313,6 +313,9 @@ cpu_switchto(struct proc *old, struct proc *new)
313313
cpu_switchto_asm(old, new);
314314
}
315315

316+
extern uint64_t cpu_id_aa64isar0;
317+
extern uint64_t cpu_id_aa64isar1;
318+
316319
/*
317320
* machine dependent system variables.
318321
*/
@@ -340,6 +343,10 @@ cpu_sysctl(int *name, u_int namelen, void *oldp, size_t *oldlenp, void *newp,
340343
error = sysctl_rdstring(oldp, oldlenp, newp, compatible);
341344
free(compatible, M_TEMP, len);
342345
return error;
346+
case CPU_ID_AA64ISAR0:
347+
return sysctl_rdquad(oldp, oldlenp, newp, cpu_id_aa64isar0);
348+
case CPU_ID_AA64ISAR1:
349+
return sysctl_rdquad(oldp, oldlenp, newp, cpu_id_aa64isar1);
343350
default:
344351
return (EOPNOTSUPP);
345352
}

sys/arch/arm64/include/cpu.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $OpenBSD: cpu.h,v 1.24 2022/01/01 18:52:37 kettenis Exp $ */
1+
/* $OpenBSD: cpu.h,v 1.25 2022/03/23 23:36:35 kettenis Exp $ */
22
/*
33
* Copyright (c) 2016 Dale Rahn <[email protected]>
44
*
@@ -26,11 +26,15 @@
2626
* CTL_MACHDEP definitions.
2727
*/
2828
#define CPU_COMPATIBLE 1 /* compatible property */
29-
#define CPU_MAXID 2 /* number of valid machdep ids */
29+
#define CPU_ID_AA64ISAR0 2
30+
#define CPU_ID_AA64ISAR1 3
31+
#define CPU_MAXID 4 /* number of valid machdep ids */
3032

3133
#define CTL_MACHDEP_NAMES { \
3234
{ 0, 0 }, \
3335
{ "compatible", CTLTYPE_STRING }, \
36+
{ "id_aa64isar0", CTLTYPE_QUAD }, \
37+
{ "id_aa64isar1", CTLTYPE_QUAD }, \
3438
}
3539

3640
#ifdef _KERNEL

0 commit comments

Comments
 (0)