Keith Randall would like Michael Pratt to review this change.
runtime: on android/arm64, don't read outside 16-byte regions
Because MTE might be enforced.
Update #59090
Update #27610
diff --git a/src/internal/bytealg/indexbyte_arm64.s b/src/internal/bytealg/indexbyte_arm64.s
index 92a61a4..1101122ec 100644
--- a/src/internal/bytealg/indexbyte_arm64.s
+++ b/src/internal/bytealg/indexbyte_arm64.s
@@ -34,6 +34,9 @@
// identify exactly which byte has matched.
CBZ R1, fail
+#ifdef GOOS_android
+ ADD R0, R1, R20 // R20 = end of data
+#endif
MOVD R0, R11
// Magic constant 0x40100401 allows us to identify
// which lane matches the requested byte.
@@ -51,7 +54,17 @@
// Input string is not 32-byte aligned. We calculate the
// syndrome value for the aligned 32 bytes block containing
// the first bytes and mask off the irrelevant part.
+#ifdef GOOS_android
+ // Android requires us to not read outside an aligned 16-byte
+ // region because MTE might be enforced.
+ VLD1.P (R3), [V1.B16]
+ CMP R3, R20
+ BLS 2(PC)
+ VLD1 (R3), [V2.B16]
+ ADD $0x10, R3
+#else
VLD1.P (R3), [V1.B16, V2.B16]
+#endif
SUB $0x20, R9, R4
ADDS R4, R1, R1
VCMEQ V0.B16, V1.B16, V3.B16
@@ -71,7 +84,15 @@
CBNZ R6, tail
loop:
+#ifdef GOOS_android
+ VLD1.P (R3), [V1.B16]
+ CMP R3, R20
+ BLS 2(PC)
+ VLD1 (R3), [V2.B16]
+ ADD $0x10, R3
+#else
VLD1.P (R3), [V1.B16, V2.B16]
+#endif
SUBS $0x20, R1, R1
VCMEQ V0.B16, V1.B16, V3.B16
VCMEQ V0.B16, V2.B16, V4.B16
diff --git a/src/runtime/string.go b/src/runtime/string.go
index 15b3868..b911c0c 100644
--- a/src/runtime/string.go
+++ b/src/runtime/string.go
@@ -8,6 +8,7 @@
"internal/abi"
"internal/bytealg"
"internal/goarch"
+ "internal/goos"
"internal/runtime/math"
"internal/runtime/sys"
"internal/strconv"
@@ -505,7 +506,9 @@
// It must be the minimum page size for any architecture Go
// runs on. It's okay (just a minor performance loss) if the
// actual system page size is larger than this value.
- const pageSize = 4096
+ // For Android, we set the page size to the MTE size, as MTE
+ // might be enforced. See issue 59090.
+ const pageSize = 4096 - 4080*goos.IsAndroid
offset := 0
ptr := unsafe.Pointer(s)
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Commit-Queue | +1 |
I looked through internal/bytealg/*_arm64.s and runtime/*_arm64.s and I think this is the only case where we read outside the passed-in ranges. So this CL might be a reasonably complete fix for MTE compatibility.
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Commit-Queue | +1 |
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
Update #27610I assume that this patch won't make valgrind happy, since it still reads beyond the end of the object, just limited to MTE's minimum resolution.
VLD1.P (R3), [V1.B16]I'm not too familiar with arm64 vector instructions or our arm64 assembly syntax, so just to check, this is the post-index variant, which writes R3+16 back to R3?
ADD $0x10, R3Why add manually instead of using VLD1.P?
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
ADD $0x10, R3Why add manually instead of using VLD1.P?
We still need to do the ADD $16 even when we don't do the load, so they have to be separate. (We could use VLD1.P, but then we need a separate ADD $16 somewhere else.)
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Code-Review | +2 |
ADD $0x10, R3Keith RandallWhy add manually instead of using VLD1.P?
We still need to do the ADD $16 even when we don't do the load, so they have to be separate. (We could use VLD1.P, but then we need a separate ADD $16 somewhere else.)
Ah, right, thanks.
const pageSize = 4096 - 4080*goos.IsAndroidThis is pretty confusing. IMO it would be clearer as
```suggestion
const pageSize = 4096*(1-goos.IsAndroid) + 16*goos.IsAndroid
```
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Auto-Submit | +1 |
This is pretty confusing. IMO it would be clearer as
```suggestion
const pageSize = 4096*(1-goos.IsAndroid) + 16*goos.IsAndroid
```
Sure, done.
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
1 is the latest approved patch-set.
The change was submitted with unreviewed changes in the following files:
```
The name of the file: src/runtime/string.go
Insertions: 1, Deletions: 1.
@@ -508,7 +508,7 @@
// actual system page size is larger than this value.
// For Android, we set the page size to the MTE size, as MTE
// might be enforced. See issue 59090.
- const pageSize = 4096 - 4080*goos.IsAndroid
+ const pageSize = 4096*(1-goos.IsAndroid) + 16*goos.IsAndroid
offset := 0
ptr := unsafe.Pointer(s)
```
runtime: on android/arm64, don't read outside 16-byte regions
Because MTE might be enforced.
Update #59090
Update #27610
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |