mirror of
https://github.com/netbirdio/gvisor.git
synced 2026-05-22 17:12:49 -07:00
amd64: don't check vcpu in bluepill()
m.Get() has guaranteed that if any OS thread TID is in guest, m.vCPUs[TID] points to the vCPU in which the OS thread TID is running. So if m.Get() returns with the corrent context in guest, the vCPU of it must be the same as what Get() returns. So bluepill() doesn't need to check if the vCPU is matched or not. The check need to access to %gs register which will not points to vCPU later when KPTI for gvisor is enabled. We can still fetch the vCPU pointer from %gs later (when %gs points to kernelEntry), but it needs the ENTRY_CPU_SELF which is generated by ring0/offset_amd64.go. So we just simply remove the check. Signed-off-by: Lai Jiangshan <jiangshan.ljs@antfin.com> Signed-off-by: Lai Jiangshan <laijs@linux.alibaba.com>
This commit is contained in:
committed by
Lai Jiangshan
parent
c4d364c7ce
commit
d17425082d
@@ -14,16 +14,6 @@
|
||||
|
||||
#include "textflag.h"
|
||||
|
||||
// VCPU_CPU is the location of the CPU in the vCPU struct.
|
||||
//
|
||||
// This is guaranteed to be zero.
|
||||
#define VCPU_CPU 0x0
|
||||
|
||||
// CPU_SELF is the self reference in ring0's percpu.
|
||||
//
|
||||
// This is guaranteed to be zero.
|
||||
#define CPU_SELF 0x0
|
||||
|
||||
// Context offsets.
|
||||
//
|
||||
// Only limited use of the context is done in the assembly stub below, most is
|
||||
@@ -39,18 +29,8 @@
|
||||
|
||||
// See bluepill.go.
|
||||
TEXT ·bluepill(SB),NOSPLIT,$0
|
||||
begin:
|
||||
MOVQ vcpu+0(FP), AX
|
||||
LEAQ VCPU_CPU(AX), BX
|
||||
BYTE CLI;
|
||||
check_vcpu:
|
||||
MOVQ CPU_SELF(GS), CX
|
||||
CMPQ BX, CX
|
||||
JE right_vCPU
|
||||
wrong_vcpu:
|
||||
CALL ·redpill(SB)
|
||||
JMP begin
|
||||
right_vCPU:
|
||||
RET
|
||||
|
||||
// sighandler: see bluepill.go for documentation.
|
||||
|
||||
@@ -339,6 +339,11 @@ func (m *machine) Destroy() {
|
||||
// Get gets an available vCPU.
|
||||
//
|
||||
// This will return with the OS thread locked.
|
||||
//
|
||||
// It is guaranteed that if any OS thread TID is in guest, m.vCPUs[TID] points
|
||||
// to the vCPU in which the OS thread TID is running. So if Get() returns with
|
||||
// the corrent context in guest, the vCPU of it must be the same as what
|
||||
// Get() returns.
|
||||
func (m *machine) Get() *vCPU {
|
||||
m.mu.RLock()
|
||||
runtime.LockOSThread()
|
||||
|
||||
Reference in New Issue
Block a user