Skip to content

Commit c7654cd

Browse files
committed
Expose the complete set of ID registers as defined in the current version
of ARMv8/ARMv9. Make sure we only expose the features that we know about and support in our kernel. This matches what Linux does. For now, mostly restrict ourselves to features defined in ARMv8.5 which means that we only actually implement support for ID_AA64ISAR0_EL1, ID_AA64ISAR1_EL1, ID_AA64PFR0_EL1 and ID_AA64PFR1_EL1. For the other registers we simply always return 0. ok deraadt@
1 parent 815de89 commit c7654cd

File tree

3 files changed

+58
-6
lines changed

3 files changed

+58
-6
lines changed

sys/arch/arm64/arm64/cpu.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $OpenBSD: cpu.c,v 1.72 2022/11/08 16:53:40 kettenis Exp $ */
1+
/* $OpenBSD: cpu.c,v 1.73 2022/11/24 14:43:16 kettenis Exp $ */
22

33
/*
44
* Copyright (c) 2016 Dale Rahn <[email protected]>
@@ -200,6 +200,8 @@ int cpu_node;
200200

201201
uint64_t cpu_id_aa64isar0;
202202
uint64_t cpu_id_aa64isar1;
203+
uint64_t cpu_id_aa64pfr0;
204+
uint64_t cpu_id_aa64pfr1;
203205

204206
#ifdef CRYPTO
205207
int arm64_has_aes;
@@ -380,6 +382,14 @@ cpu_identify(struct cpu_info *ci)
380382
printf("\n%s: mismatched ID_AA64ISAR1_EL1",
381383
ci->ci_dev->dv_xname);
382384
}
385+
if (READ_SPECIALREG(id_aa64pfr0_el1) != cpu_id_aa64pfr0) {
386+
printf("\n%s: mismatched ID_AA64PFR0_EL1",
387+
ci->ci_dev->dv_xname);
388+
}
389+
if (READ_SPECIALREG(id_aa64pfr1_el1) != cpu_id_aa64pfr1) {
390+
printf("\n%s: mismatched ID_AA64PFR1_EL1",
391+
ci->ci_dev->dv_xname);
392+
}
383393

384394
printf("\n%s: ", ci->ci_dev->dv_xname);
385395

@@ -732,6 +742,8 @@ cpu_attach(struct device *parent, struct device *dev, void *aux)
732742
#endif
733743
cpu_id_aa64isar0 = READ_SPECIALREG(id_aa64isar0_el1);
734744
cpu_id_aa64isar1 = READ_SPECIALREG(id_aa64isar1_el1);
745+
cpu_id_aa64pfr0 = READ_SPECIALREG(id_aa64pfr0_el1);
746+
cpu_id_aa64pfr1 = READ_SPECIALREG(id_aa64pfr1_el1);
735747

736748
cpu_identify(ci);
737749

sys/arch/arm64/arm64/machdep.c

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $OpenBSD: machdep.c,v 1.76 2022/11/21 20:19:21 kettenis Exp $ */
1+
/* $OpenBSD: machdep.c,v 1.77 2022/11/24 14:43:16 kettenis Exp $ */
22
/*
33
* Copyright (c) 2014 Patrick Wildt <[email protected]>
44
* Copyright (c) 2021 Mark Kettenis <[email protected]>
@@ -315,6 +315,8 @@ cpu_switchto(struct proc *old, struct proc *new)
315315

316316
extern uint64_t cpu_id_aa64isar0;
317317
extern uint64_t cpu_id_aa64isar1;
318+
extern uint64_t cpu_id_aa64pfr0;
319+
extern uint64_t cpu_id_aa64pfr1;
318320

319321
/*
320322
* machine dependent system variables.
@@ -326,6 +328,7 @@ cpu_sysctl(int *name, u_int namelen, void *oldp, size_t *oldlenp, void *newp,
326328
{
327329
char *compatible;
328330
int node, len, error;
331+
uint64_t value;
329332

330333
/* all sysctl names at this level are terminal */
331334
if (namelen != 1)
@@ -344,9 +347,30 @@ cpu_sysctl(int *name, u_int namelen, void *oldp, size_t *oldlenp, void *newp,
344347
free(compatible, M_TEMP, len);
345348
return error;
346349
case CPU_ID_AA64ISAR0:
347-
return sysctl_rdquad(oldp, oldlenp, newp, cpu_id_aa64isar0);
350+
value = cpu_id_aa64isar0 & ID_AA64ISAR0_MASK;
351+
value &= ~ID_AA64ISAR0_TLB_MASK;
352+
return sysctl_rdquad(oldp, oldlenp, newp, value);
348353
case CPU_ID_AA64ISAR1:
349-
return sysctl_rdquad(oldp, oldlenp, newp, cpu_id_aa64isar1);
354+
value = cpu_id_aa64isar1 & ID_AA64ISAR1_MASK;
355+
value &= ~ID_AA64ISAR1_SPECRES_MASK;
356+
return sysctl_rdquad(oldp, oldlenp, newp, value);
357+
case CPU_ID_AA64PFR0:
358+
value = 0;
359+
value |= cpu_id_aa64pfr0 & ID_AA64PFR0_FP_MASK;
360+
value |= cpu_id_aa64pfr0 & ID_AA64PFR0_ADV_SIMD_MASK;
361+
value |= cpu_id_aa64pfr0 & ID_AA64PFR0_DIT_MASK;
362+
return sysctl_rdquad(oldp, oldlenp, newp, value);
363+
case CPU_ID_AA64PFR1:
364+
value = 0;
365+
value |= cpu_id_aa64pfr1 & ID_AA64PFR1_SBSS_MASK;
366+
return sysctl_rdquad(oldp, oldlenp, newp, value);
367+
case CPU_ID_AA64ISAR2:
368+
case CPU_ID_AA64MMFR0:
369+
case CPU_ID_AA64MMFR1:
370+
case CPU_ID_AA64MMFR2:
371+
case CPU_ID_AA64SMFR0:
372+
case CPU_ID_AA64ZFR0:
373+
return sysctl_rdquad(oldp, oldlenp, newp, 0);
350374
default:
351375
return (EOPNOTSUPP);
352376
}

sys/arch/arm64/include/cpu.h

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $OpenBSD: cpu.h,v 1.30 2022/11/08 20:41:36 mlarkin Exp $ */
1+
/* $OpenBSD: cpu.h,v 1.31 2022/11/24 14:43:16 kettenis Exp $ */
22
/*
33
* Copyright (c) 2016 Dale Rahn <[email protected]>
44
*
@@ -28,13 +28,29 @@
2828
#define CPU_COMPATIBLE 1 /* compatible property */
2929
#define CPU_ID_AA64ISAR0 2
3030
#define CPU_ID_AA64ISAR1 3
31-
#define CPU_MAXID 4 /* number of valid machdep ids */
31+
#define CPU_ID_AA64ISAR2 4
32+
#define CPU_ID_AA64MMFR0 5
33+
#define CPU_ID_AA64MMFR1 6
34+
#define CPU_ID_AA64MMFR2 7
35+
#define CPU_ID_AA64PFR0 8
36+
#define CPU_ID_AA64PFR1 9
37+
#define CPU_ID_AA64SMFR0 10
38+
#define CPU_ID_AA64ZFR0 11
39+
#define CPU_MAXID 12 /* number of valid machdep ids */
3240

3341
#define CTL_MACHDEP_NAMES { \
3442
{ 0, 0 }, \
3543
{ "compatible", CTLTYPE_STRING }, \
3644
{ "id_aa64isar0", CTLTYPE_QUAD }, \
3745
{ "id_aa64isar1", CTLTYPE_QUAD }, \
46+
{ "id_aa64isar2", CTLTYPE_QUAD }, \
47+
{ "id_aa64mmfr0", CTLTYPE_QUAD }, \
48+
{ "id_aa64mmfr1", CTLTYPE_QUAD }, \
49+
{ "id_aa64mmfr2", CTLTYPE_QUAD }, \
50+
{ "id_aa64pfr0", CTLTYPE_QUAD }, \
51+
{ "id_aa64pfr1", CTLTYPE_QUAD }, \
52+
{ "id_aa64smfr0", CTLTYPE_QUAD }, \
53+
{ "id_aa64zfr0", CTLTYPE_QUAD }, \
3854
}
3955

4056
#ifdef _KERNEL

0 commit comments

Comments
 (0)