Skip to content

Commit 5c4b4f5

Browse files
avagingvisor-bot
authored andcommitted
kvm/arm64: queue DABT (Data Abort) to force Sentry returning to the host
SError-s are blocked in the kernel context (A-bit in PSTATE). Fixes #6629 PiperOrigin-RevId: 754196342
1 parent 0c66b7e commit 5c4b4f5

File tree

4 files changed

+25
-13
lines changed

4 files changed

+25
-13
lines changed

pkg/sentry/platform/kvm/bluepill_arm64_unsafe.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,14 @@ func bluepillSigBus(c *vCPU) {
111111
},
112112
}
113113

114+
if !c.switchingToUser.Load() {
115+
// In the kernel mode (Sentry), Serrors are masked.
116+
// DABT (Data Abort) will force the Sentry returns back
117+
// to the host.
118+
bluepillExtDabt(c)
119+
return
120+
}
121+
114122
// Host must support ARM64_HAS_RAS_EXTN.
115123
if errno := hostsyscall.RawSyscallErrno( // escapes: no.
116124
unix.SYS_IOCTL,

pkg/sentry/platform/kvm/kvm_safecopy_test.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,6 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
// FIXME(gvisor.dev/issue/6629): These tests don't pass on ARM64.
16-
//
17-
//go:build amd64
18-
// +build amd64
19-
2015
package kvm
2116

2217
import (

pkg/sentry/platform/kvm/machine_arm64.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323

2424
"golang.org/x/sys/unix"
2525
"gvisor.dev/gvisor/pkg/abi/linux"
26+
"gvisor.dev/gvisor/pkg/atomicbitops"
2627
"gvisor.dev/gvisor/pkg/hostarch"
2728
"gvisor.dev/gvisor/pkg/hostsyscall"
2829
"gvisor.dev/gvisor/pkg/ring0"
@@ -35,6 +36,11 @@ type vCPUArchState struct {
3536
//
3637
// This starts above fixedKernelPCID.
3738
PCIDs *pagetables.PCIDs
39+
40+
// switchingToUser indicates whether the vCPU is in the process of
41+
// switching to user mode. It is set before the SwitchToUser call
42+
// and unset after.
43+
switchingToUser atomicbitops.Bool
3844
}
3945

4046
const (

pkg/sentry/platform/kvm/machine_arm64_unsafe.go

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -214,8 +214,8 @@ func (c *vCPU) getTSC() error {
214214
reg.addr = uint64(reflect.ValueOf(&data).Pointer())
215215
reg.id = _KVM_ARM64_REGS_TIMER_CNT
216216

217-
if err := c.getOneRegister(&reg); err != nil {
218-
return err
217+
if errno := c.getOneRegister(&reg); errno != 0 {
218+
return fmt.Errorf("error getting KVM_ARM64_REGS_TIMER_CNT: %w", errno)
219219
}
220220

221221
return nil
@@ -265,6 +265,7 @@ func (c *vCPU) loadSegments(tid uint64) {
265265
c.tid.Store(tid)
266266
}
267267

268+
//go:nosplit
268269
func (c *vCPU) setOneRegister(reg *kvmOneReg) error {
269270
if errno := hostsyscall.RawSyscallErrno(
270271
unix.SYS_IOCTL,
@@ -276,15 +277,13 @@ func (c *vCPU) setOneRegister(reg *kvmOneReg) error {
276277
return nil
277278
}
278279

279-
func (c *vCPU) getOneRegister(reg *kvmOneReg) error {
280-
if errno := hostsyscall.RawSyscallErrno(
280+
//go:nosplit
281+
func (c *vCPU) getOneRegister(reg *kvmOneReg) unix.Errno {
282+
return hostsyscall.RawSyscallErrno(
281283
unix.SYS_IOCTL,
282284
uintptr(c.fd),
283285
_KVM_GET_ONE_REG,
284-
uintptr(unsafe.Pointer(reg))); errno != 0 {
285-
return fmt.Errorf("error getting one register: %v", errno)
286-
}
287-
return nil
286+
uintptr(unsafe.Pointer(reg)))
288287
}
289288

290289
// SwitchToUser unpacks architectural-details.
@@ -317,11 +316,15 @@ func (c *vCPU) SwitchToUser(switchOpts ring0.SwitchOpts, info *linux.SignalInfo)
317316
appRegs := switchOpts.Registers
318317
c.SetAppAddr(ring0.KernelStartAddress | uintptr(unsafe.Pointer(appRegs)))
319318

319+
c.switchingToUser.Store(true)
320+
320321
entersyscall()
321322
bluepill(c)
322323
vector = c.CPU.SwitchToUser(switchOpts)
323324
exitsyscall()
324325

326+
c.switchingToUser.Store(false)
327+
325328
switch vector {
326329
case ring0.Syscall:
327330
// Fast path: system call executed.

0 commit comments

Comments
 (0)