Skip to content

Commit bdc3a75

Browse files
committed
cpu: add HPDS, LOR, PAN detection for arm64
This CL gets ID_AA64MMFR1_EL1, Memory Model Feature Register 1, and grabs HPDS, LOR, PAN features from its bits. Fixes golang/go#75472.
1 parent 28c5bda commit bdc3a75

File tree

7 files changed

+38
-4
lines changed

7 files changed

+38
-4
lines changed

cpu/cpu.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,9 @@ var ARM64 struct {
9292
HasSHA2 bool // SHA2 hardware implementation
9393
HasCRC32 bool // CRC32 hardware implementation
9494
HasATOMICS bool // Atomic memory operation instruction set
95+
HasHPDS bool // Hierarchical permission disables in translations tables
96+
HasLOR bool // Limited ordering regions
97+
HasPAN bool // Privileged access never
9598
HasFPHP bool // Half precision floating-point instruction set
9699
HasASIMDHP bool // Advanced SIMD half precision instruction set
97100
HasCPUID bool // CPUID identification scheme registers

cpu/cpu_arm64.go

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,10 @@ func setMinimalFeatures() {
6565
func readARM64Registers() {
6666
Initialized = true
6767

68-
parseARM64SystemRegisters(getisar0(), getisar1(), getpfr0())
68+
parseARM64SystemRegisters(getisar0(), getisar1(), getmmfr1(), getpfr0())
6969
}
7070

71-
func parseARM64SystemRegisters(isar0, isar1, pfr0 uint64) {
71+
func parseARM64SystemRegisters(isar0, isar1, mmfr1, pfr0 uint64) {
7272
// ID_AA64ISAR0_EL1
7373
switch extractBits(isar0, 4, 7) {
7474
case 1:
@@ -152,6 +152,22 @@ func parseARM64SystemRegisters(isar0, isar1, pfr0 uint64) {
152152
ARM64.HasI8MM = true
153153
}
154154

155+
// ID_AA64MMFR1_EL1
156+
switch extractBits(mmfr1, 12, 15) {
157+
case 1:
158+
ARM64.HasHPDS = true
159+
}
160+
161+
switch extractBits(mmfr1, 16, 19) {
162+
case 1:
163+
ARM64.HasLOR = true
164+
}
165+
166+
switch extractBits(mmfr1, 20, 23) {
167+
case 1:
168+
ARM64.HasPAN = true
169+
}
170+
155171
// ID_AA64PFR0_EL1
156172
switch extractBits(pfr0, 16, 19) {
157173
case 0:

cpu/cpu_arm64.s

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,14 @@ TEXT ·getisar1(SB),NOSPLIT,$0-8
2222
MOVD R0, ret+0(FP)
2323
RET
2424

25+
// func getmmfr1() uint64
26+
TEXT ·getmmfr1(SB),NOSPLIT,$0-8
27+
// get SVE Feature Register 0 into x0
28+
// mrs x0, ID_AA64MMFR1_EL1 = d5380720
29+
WORD $0xd5380720
30+
MOVD R0, ret+0(FP)
31+
RET
32+
2533
// func getpfr0() uint64
2634
TEXT ·getpfr0(SB),NOSPLIT,$0-8
2735
// get Processor Feature Register 0 into x0

cpu/cpu_gc_arm64.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@ package cpu
88

99
func getisar0() uint64
1010
func getisar1() uint64
11+
func getmmfr1() uint64
1112
func getpfr0() uint64
1213
func getzfr0() uint64

cpu/cpu_gccgo_arm64.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ package cpu
88

99
func getisar0() uint64 { return 0 }
1010
func getisar1() uint64 { return 0 }
11+
func getmmfr1() uint64 { return 0 }
1112
func getpfr0() uint64 { return 0 }

cpu/cpu_netbsd_arm64.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ func doinit() {
167167
setMinimalFeatures()
168168
return
169169
}
170-
parseARM64SystemRegisters(cpuid.aa64isar0, cpuid.aa64isar1, cpuid.aa64pfr0)
170+
parseARM64SystemRegisters(cpuid.aa64isar0, cpuid.aa64isar1, cpuid.aa64pfr0, cpuid.aa64pfr0)
171171

172172
Initialized = true
173173
}

cpu/cpu_openbsd_arm64.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ const (
1919
// From OpenBSD's machine/cpu.h.
2020
_CPU_ID_AA64ISAR0 = 2
2121
_CPU_ID_AA64ISAR1 = 3
22+
_CPU_ID_AA64PFR0 = 8
2223
)
2324

2425
// Implemented in the runtime package (runtime/sys_openbsd3.go)
@@ -59,7 +60,11 @@ func doinit() {
5960
if !ok {
6061
return
6162
}
62-
parseARM64SystemRegisters(isar0, isar1, 0)
63+
pfr0, ok := sysctlUint64([]uint32{_CTL_MACHDEP, _CPU_ID_AA64PFR0})
64+
if !ok {
65+
return
66+
}
67+
parseARM64SystemRegisters(isar0, isar1, 0, pfr0)
6368

6469
Initialized = true
6570
}

0 commit comments

Comments
 (0)