Commit Graph

138 Commits

Author SHA1 Message Date
Bin Lu 6adbdfe232 supporting sError in guest kernel on Arm64
For test case 'TestBounce', we use KVM_SET_VCPU_EVENTS to trigger sError
to leave guest.

Signed-off-by: Bin Lu <bin.lu@arm.com>
2020-01-29 07:50:38 -05:00
Adin Scannell 0e2f1b7abd Update package locations.
Because the abi will depend on the core types for marshalling (usermem,
context, safemem, safecopy), these need to be flattened from the sentry
directory. These packages contain no sentry-specific details.

PiperOrigin-RevId: 291811289
2020-01-27 15:31:32 -08:00
Adin Scannell 90ec596166 Fix licenses.
The preferred Copyright holder is "The gVisor Authors".

PiperOrigin-RevId: 291786657
2020-01-27 13:23:57 -08:00
Adin Scannell d29e59af9f Standardize on tools directory.
PiperOrigin-RevId: 291745021
2020-01-27 12:21:00 -08:00
Michael Pratt 7a79715504 Check for EINTR from KVM_CREATE_VM
The kernel may return EINTR from:

kvm_create_vm
  kvm_init_mmu_notifier
    mmu_notifier_register
      do_mmu_notifier_register
        mm_take_all_locks

Go 1.14's preemptive scheduling signals make hitting this much more likely.

PiperOrigin-RevId: 291212669
2020-01-23 11:49:02 -08:00
gVisor bot b3405a719c Merge pull request #1275 from lubinszARM:pr_ring0_5
PiperOrigin-RevId: 290839263
2020-01-21 16:09:25 -08:00
gVisor bot 16694ad2ba Merge pull request #1274 from lubinszARM:pr_ring0_4
PiperOrigin-RevId: 290811598
2020-01-21 13:56:48 -08:00
gVisor bot fea1ce655d Merge pull request #1272 from lubinszARM:pr_ring0_2
PiperOrigin-RevId: 290113719
2020-01-16 11:56:09 -08:00
gVisor bot 2ebd21478e Merge pull request #1540 from laijs:fix-PCIDs
PiperOrigin-RevId: 289925133
2020-01-15 13:48:51 -08:00
Ian Gudger 27500d529f New sync package.
* Rename syncutil to sync.
* Add aliases to sync types.
* Replace existing usage of standard library sync package.

This will make it easier to swap out synchronization primitives. For example,
this will allow us to use primitives from github.com/sasha-s/go-deadlock to
check for lock ordering violations.

Updates #1472

PiperOrigin-RevId: 289033387
2020-01-09 22:02:24 -08:00
Lai Jiangshan fdfa05ff2c Avoid panic when c.PCIDs is nil
When PCID is disabled, there would throw a panic
when dropPageTables() access to c.PCID without check.

Signed-off-by: Lai Jiangshan <eag0628@gmail.com>
2020-01-09 09:18:33 +00:00
gVisor bot bb96f52576 Merge pull request #1273 from lubinszARM:pr_ring_3
PiperOrigin-RevId: 288743614
2020-01-08 11:48:34 -08:00
Andrei Vagin 17c18241cd platform/syscall: use syscall + int3 to execute a system call in a stub process
Right now, we need to call ptrace(PTRACE_SYSCALL) and wait() twice to execute
one system call in a stub process. With these changes, we will need to call
ptrace + wait only once.

In addition, this allows to workaround the kernel bug when a stub process
doesn't stop on syscall-exit-stop and starts executing the next system call.

Reported-by: syzbot+37143cafa8dc3b5008ee@syzkaller.appspotmail.com
PiperOrigin-RevId: 288393029
2020-01-06 15:54:53 -08:00
gVisor bot 5b9034cc18 Merge pull request #1461 from xiaobo55x:ptrace_sysemu
PiperOrigin-RevId: 287225250
2019-12-26 14:19:34 -08:00
gVisor bot 7b5a59d503 Merge pull request #1460 from lubinszARM:pr_clean_code1
PiperOrigin-RevId: 287221280
2019-12-26 13:42:39 -08:00
Bin Lu 7b83d21856 slight changes to ring0&pagetables for Arm64
There are 2 jobs have been finished in this patch:
1, a comment was added to explain the purpose of the extra NOPs in Vectors().
2, some merge errors were fixed.

Signed-off-by: Bin Lu <bin.lu@arm.com>
2019-12-24 10:50:11 +08:00
Haibo Xu b6e31aadaa Replace syscall.PTRACE_SYSEMU with unix.PTRACE_SYSEMU
Linux PTRACE_SYSEMU support on arm64 was merged to mainline from
V5.3, and the corresponding support in go also enabled recently.

Since the "syscall" package is locked down from go 1.4, so the ptrace
PTRACE_SYSEMU definition can't be added to package "syscall" on arm64.
According to the golang community, updates required by new systems or
versions should use the corresponding package in the golang.org/x/sys
repository instead(https://golang.org/pkg/syscall/).

Signed-off-by: Haibo Xu <haibo.xu@arm.com>
Change-Id: I2f917bb2be62f990c3e158e2bb99e094ea03f751
2019-12-23 06:42:03 +00:00
gVisor bot 98e8246ad1 Merge pull request #890 from lubinszARM:pr_phyap
PiperOrigin-RevId: 286299056
2019-12-18 17:37:30 -08:00
gVisor bot ac3b3bb40e Merge pull request #1322 from lubinszARM:pr_vfp_ring0
PiperOrigin-RevId: 286259750
2019-12-18 14:52:35 -08:00
Bin Lu eb868be743 supporting lazy-fpsimd in guest on Arm64
Several jobs were finished in this patch:
1, provide functions to get/set fpcr/fpsr/vregs
2, support lazy-fpsimd-context-switch in el1

Signed-off-by: Bin Lu <bin.lu@arm.com>
2019-12-18 16:45:15 +08:00
Michael Pratt 91f1ac7319 Mark enableCpuidFault nosplit
This is called after fork, so it must be nosplit.

Updates #1408

PiperOrigin-RevId: 286053054
2019-12-17 14:18:54 -08:00
gVisor bot e416724fb3 Merge pull request #1321 from lubinszARM:pr_testutils_vfp
PiperOrigin-RevId: 286042427
2019-12-17 13:10:50 -08:00
lubinszARM 6b42453039 enable kvm to support arm64
There are 4 jobs were finished in this package:
  	1, Virtual machine initialization.
	2, Bluepill implementation.
	3, Move ring0.Vectors() into the address with 11-bits alignment.
	4, Basic support for "SwitchToUser".
Signed-off-by: Bin Lu <bin.lu@arm.com>
COPYBARA_INTEGRATE_REVIEW=https://github.com/google/gvisor/pull/919 from lubinszARM:pr_kvm eedea52db451bf62722759009a9f14c54a69c55f
PiperOrigin-RevId: 285501256
2019-12-13 17:11:23 -08:00
Bin Lu 70b68bb058 Add a floating test case for Arm64
Signed-off-by: Bin Lu <bin.lu@arm.com>
2019-12-04 16:28:28 +08:00
Haibo Xu 03760e5623 platform/ptrace: make some operations arch specific
Make the patchSignalInfo/cpuid faulting/initial thread seccomp rules
operations architecture dependent.

Signed-off-by: Haibo Xu <haibo.xu@arm.com>
Change-Id: Iaf692dbe3700d2e01168ec2f1b4beeda9136fd62
2019-12-03 07:17:34 +00:00
Bin Lu 3f0e91b004 passed the kvm test case of "TestApplicationFault" on Arm64 platform
For test case "TestApplicationFault",
Memory-fault in guest user level will be trapped in el0_da.
And in el0_da, we use mmio_exit to leave the KVM guest.

Signed-off-by: Bin Lu <bin.lu@arm.com>
2019-11-26 16:00:00 +08:00
Bin Lu 3e00624806 passed the kvm test case of "TestApplicationSyscall" on Arm64 platform
For test case "TestApplicationSyscall",
Syscall in guest user level will be trapped in el0_svc.
And in el0_svc, we use mmio_exit to leave the KVM guest for now.

Signed-off-by: Bin Lu <bin.lu@arm.com>
2019-11-26 15:57:15 +08:00
Bin Lu e710f65401 Prepare the vcpu environment for a container application
Mainly 2 jobs were finished in this patch:
    1, context switching for a container application:
        a, R0-R30 b, pc\pstate\sp_el0 c, pagetable_el0 for container application
       This job can help us to pass the following test cases:
       "TestApplicationSyscall", "TestApplicationFault"
    2, checking pagetable_el0 is empty
       This job can help us to pass the following test case: "TestInvalidate"

Signed-off-by: Bin Lu <bin.lu@arm.com>
2019-11-26 15:53:30 +08:00
Bin Lu e91c1675cd passed the kvm test case of "TestKernelFault" on Arm64 platform
Signed-off-by: Bin Lu <bin.lu@arm.com>
2019-11-26 15:32:55 +08:00
lubinszARM 07635d20d4 enable ring0/pagetables to support arm64
Signed-off-by: Bin Lu <bin.lu@arm.com>
COPYBARA_INTEGRATE_REVIEW=https://github.com/google/gvisor/pull/891 from lubinszARM:pr_pagetable 2385de75a8662af3ab1ae289dd74dd0e5dcfaf66
PiperOrigin-RevId: 282013224
2019-11-22 12:05:35 -08:00
Andrei Vagin 26b3341b9a platform/ptrace: use host.GetCPU instead of the getcpu syscall
This should save ~200ns from switchToApp (on ptrace too). // mpratt

PiperOrigin-RevId: 281159895
2019-11-18 14:56:49 -08:00
gVisor bot 07f9041187 Merge pull request #918 from lubinszARM:pr_ring0
PiperOrigin-RevId: 279840214
2019-11-11 16:15:12 -08:00
Andrei Vagin f7dbddaf77 platform/kvm: calll sigtimedwait with zero timeout
sigtimedwait is used to check pending signals and
it should not block.

PiperOrigin-RevId: 277777269
2019-10-31 12:29:04 -07:00
lubinszARM ca933329fa support using KVM_MEM_READONLY for arm64 regions
On Arm platform, "setMemoryRegion" has extra permission checks.
In virt/kvm/arm/mmu.c: kvm_arch_prepare_memory_region()
      ....
      if (writable && !(vma->vm_flags & VM_WRITE)) {
             ret = -EPERM;
             break;
       }
        ....
So, for Arm platform, the "flags" for kvm_memory_region is required.
And on x86 platform, the "flags" can be always set as '0'.

Signed-off-by: Bin Lu <bin.lu@arm.com>
COPYBARA_INTEGRATE_REVIEW=https://github.com/google/gvisor/pull/810 from lubinszARM:pr_setregion 8c99b19cfb0c859c6630a1cfff951db65fcf87ac
PiperOrigin-RevId: 277602603
2019-10-30 15:53:31 -07:00
Michael Pratt c0b8fd4b6a Update build tags to allow Go 1.14
Currently there are no ABI changes. We should check again closer to release.

PiperOrigin-RevId: 277349744
2019-10-29 13:18:16 -07:00
Andrei Vagin fd598912be platform/ptrace: use tgkill instead of kill
The syscall filters don't allow kill, just tgkill.

PiperOrigin-RevId: 276718421
2019-10-25 11:19:20 -07:00
Bin Lu 345f140169 Optimize kvm/physical_map.go on Arm platform
Signed-off-by: Bin Lu <bin.lu@arm.com>
2019-10-23 03:32:50 +00:00
Andrei Vagin e63ff6d923 platform/ptrace: exit without panic if a stub process has been killed by SIGKILL
SIGKILL can be sent only by an user or OOM-killer. In both cases, we don't
need to panic.

PiperOrigin-RevId: 276150120
2019-10-22 14:57:23 -07:00
Bin Lu 2cee066929 enable ring0 to support arm64
This patch enabled the basic framework for arm64 guest.

Serveral jobs were finished in this patch:
1, ring0.Vectors()
2, switchToUser()
3, basic framwork for Arm64 guest.

Signed-off-by: Bin Lu <bin.lu@arm.com>
2019-10-22 08:33:39 +00:00
Kevin Krakauer 2a82d5ad68 Reorder BUILD license and load functions in gvisor.
PiperOrigin-RevId: 275139066
2019-10-16 16:40:30 -07:00
gVisor bot 7a2d5b2fa7 Merge pull request #811 from lubinszARM:pr_testutil
PiperOrigin-RevId: 273781641
2019-10-09 12:00:53 -07:00
gVisor bot 76ff1947b6 gvisor: change syscall.RawSyscall to syscall.RawSyscall6 where required
Before https://golang.org/cl/173160 syscall.RawSyscall would zero out
the last three register arguments to the system call. That no longer happens.
For system calls that take more than three arguments, use RawSyscall6 to
ensure that we pass zero, not random data, for the additional arguments.

PiperOrigin-RevId: 271062527
2019-09-24 23:47:42 -07:00
Bin Lu 8e73e2cec5 enable kvm/testutil to support arm64
enable kvm/testutil to support arm64

The Arm64 user-mode execution stat consists of:
1, X0- X30
2, PC, SP, PSTATE
3, TPIDR_EL0, used for TLS
4, V0-V31: 32 128-bit registers for floating point and simd
5, FPSR

Currently, we first try to achieve goals 1 and 2.

This patch provids basic test utils for goals 1 & 2

Signed-off-by: Bin Lu <bin.lu@arm.com>
2019-09-18 09:57:59 +00:00
Andrei Vagin 3b7119a7c9 platform/ptrace: log exit code for stub processes
PiperOrigin-RevId: 269631877
2019-09-17 12:45:22 -07:00
Michael Pratt df5d377521 Remove go_test from go_stateify and go_marshal
They are no-ops, so the standard rule works fine.

PiperOrigin-RevId: 268776264
2019-09-12 15:10:17 -07:00
Adin Scannell 67a2ab1438 Impose order on test scripts.
The simple test script has gotten out of control. Shard this script into
different pieces and attempt to impose order on overall test structure. This
change helps lay some of the foundations for future improvements.

 * The runsc/test directories are moved into just test/.
 * The runsc/test/testutil package is split into logical pieces.
 * The scripts/ directory contains new top-level targets.
 * Each test is now responsible for building targets it requires.
 * The install functionality is moved into `runsc` itself for simplicity.
 * The existing kokoro run_tests.sh file now just calls all (can be split).

After this change is merged,  I will create multiple distinct workflows for
Kokoro, one for each of the scripts currently targeted by `run_tests.sh` today,
which should dramatically reduce the time-to-run for the Kokoro tests, and
provides a better foundation for further improvements to the infrastructure.

PiperOrigin-RevId: 267081397
2019-09-03 22:02:43 -07:00
Andrei Vagin 2a1303357c ptrace: detect if a stub process exited unexpectedly
PiperOrigin-RevId: 263880577
2019-08-16 17:33:28 -07:00
Haibo Xu 1c9da886e7 Add initial ptrace stub and syscall support for arm64.
Signed-off-by: Haibo Xu <haibo.xu@arm.com>
Change-Id: I1dbd23bb240cca71d0cc30fc75ca5be28cb4c37c
PiperOrigin-RevId: 262619519
2019-08-09 13:18:11 -07:00
Andrei Vagin ec906e46c0 kvm: fix race between machine.Put and machine.Get
m.available.Signal() has to be called under m.mu.RLock, otherwise it can
race with machine.Get:

m.Get			| m.Put
-------------------------------------
m.mu.Lock()		|
Seatching available vcpu|
			| m.available.Signal()
m.available.Wait	|

PiperOrigin-RevId: 259394051
2019-07-22 13:28:16 -07:00
Andrei Vagin 6a8ff6daef kvm: wake up all waiter of vCPU.state
Now we call FUTEX_WAKE with ^uintptr(0) of waiters, but in this case only one
waiter will be waked up. If we want to wake up all of them, the number of
waiters has to be set to math.MaxInt32.

PiperOrigin-RevId: 258285286
2019-07-15 19:27:18 -07:00