mirror of
https://github.com/netbirdio/gvisor.git
synced 2026-05-22 17:12:49 -07:00
Enable automated marshalling for mempolicy syscalls.
PiperOrigin-RevId: 308170679
This commit is contained in:
committed by
gVisor bot
parent
696feaf10c
commit
f01f2132d8
+11
-6
@@ -90,14 +90,19 @@ const (
|
||||
MS_SYNC = 1 << 2
|
||||
)
|
||||
|
||||
// NumaPolicy is the NUMA memory policy for a memory range. See numa(7).
|
||||
//
|
||||
// +marshal
|
||||
type NumaPolicy int32
|
||||
|
||||
// Policies for get_mempolicy(2)/set_mempolicy(2).
|
||||
const (
|
||||
MPOL_DEFAULT = 0
|
||||
MPOL_PREFERRED = 1
|
||||
MPOL_BIND = 2
|
||||
MPOL_INTERLEAVE = 3
|
||||
MPOL_LOCAL = 4
|
||||
MPOL_MAX = 5
|
||||
MPOL_DEFAULT NumaPolicy = 0
|
||||
MPOL_PREFERRED NumaPolicy = 1
|
||||
MPOL_BIND NumaPolicy = 2
|
||||
MPOL_INTERLEAVE NumaPolicy = 3
|
||||
MPOL_LOCAL NumaPolicy = 4
|
||||
MPOL_MAX NumaPolicy = 5
|
||||
)
|
||||
|
||||
// Flags for get_mempolicy(2).
|
||||
|
||||
@@ -484,7 +484,7 @@ type Task struct {
|
||||
// bit.
|
||||
//
|
||||
// numaPolicy and numaNodeMask are protected by mu.
|
||||
numaPolicy int32
|
||||
numaPolicy linux.NumaPolicy
|
||||
numaNodeMask uint64
|
||||
|
||||
// netns is the task's network namespace. netns is never nil.
|
||||
|
||||
@@ -653,14 +653,14 @@ func (t *Task) SetNiceness(n int) {
|
||||
}
|
||||
|
||||
// NumaPolicy returns t's current numa policy.
|
||||
func (t *Task) NumaPolicy() (policy int32, nodeMask uint64) {
|
||||
func (t *Task) NumaPolicy() (policy linux.NumaPolicy, nodeMask uint64) {
|
||||
t.mu.Lock()
|
||||
defer t.mu.Unlock()
|
||||
return t.numaPolicy, t.numaNodeMask
|
||||
}
|
||||
|
||||
// SetNumaPolicy sets t's numa policy.
|
||||
func (t *Task) SetNumaPolicy(policy int32, nodeMask uint64) {
|
||||
func (t *Task) SetNumaPolicy(policy linux.NumaPolicy, nodeMask uint64) {
|
||||
t.mu.Lock()
|
||||
defer t.mu.Unlock()
|
||||
t.numaPolicy = policy
|
||||
|
||||
+2
-1
@@ -35,6 +35,7 @@
|
||||
package mm
|
||||
|
||||
import (
|
||||
"gvisor.dev/gvisor/pkg/abi/linux"
|
||||
"gvisor.dev/gvisor/pkg/safemem"
|
||||
"gvisor.dev/gvisor/pkg/sentry/arch"
|
||||
"gvisor.dev/gvisor/pkg/sentry/fsbridge"
|
||||
@@ -286,7 +287,7 @@ type vma struct {
|
||||
mlockMode memmap.MLockMode
|
||||
|
||||
// numaPolicy is the NUMA policy for this vma set by mbind().
|
||||
numaPolicy int32
|
||||
numaPolicy linux.NumaPolicy
|
||||
|
||||
// numaNodemask is the NUMA nodemask for this vma set by mbind().
|
||||
numaNodemask uint64
|
||||
|
||||
@@ -974,7 +974,7 @@ func (mm *MemoryManager) MLockAll(ctx context.Context, opts MLockAllOpts) error
|
||||
}
|
||||
|
||||
// NumaPolicy implements the semantics of Linux's get_mempolicy(MPOL_F_ADDR).
|
||||
func (mm *MemoryManager) NumaPolicy(addr usermem.Addr) (int32, uint64, error) {
|
||||
func (mm *MemoryManager) NumaPolicy(addr usermem.Addr) (linux.NumaPolicy, uint64, error) {
|
||||
mm.mappingMu.RLock()
|
||||
defer mm.mappingMu.RUnlock()
|
||||
vseg := mm.vmas.FindSegment(addr)
|
||||
@@ -986,7 +986,7 @@ func (mm *MemoryManager) NumaPolicy(addr usermem.Addr) (int32, uint64, error) {
|
||||
}
|
||||
|
||||
// SetNumaPolicy implements the semantics of Linux's mbind().
|
||||
func (mm *MemoryManager) SetNumaPolicy(addr usermem.Addr, length uint64, policy int32, nodemask uint64) error {
|
||||
func (mm *MemoryManager) SetNumaPolicy(addr usermem.Addr, length uint64, policy linux.NumaPolicy, nodemask uint64) error {
|
||||
if !addr.IsPageAligned() {
|
||||
return syserror.EINVAL
|
||||
}
|
||||
|
||||
@@ -162,10 +162,10 @@ func GetMempolicy(t *kernel.Task, args arch.SyscallArguments) (uintptr, *kernel.
|
||||
if err != nil {
|
||||
return 0, nil, err
|
||||
}
|
||||
policy = 0 // maxNodes == 1
|
||||
policy = linux.MPOL_DEFAULT // maxNodes == 1
|
||||
}
|
||||
if mode != 0 {
|
||||
if _, err := t.CopyOut(mode, policy); err != nil {
|
||||
if _, err := policy.CopyOut(t, mode); err != nil {
|
||||
return 0, nil, err
|
||||
}
|
||||
}
|
||||
@@ -199,10 +199,10 @@ func GetMempolicy(t *kernel.Task, args arch.SyscallArguments) (uintptr, *kernel.
|
||||
if policy&^linux.MPOL_MODE_FLAGS != linux.MPOL_INTERLEAVE {
|
||||
return 0, nil, syserror.EINVAL
|
||||
}
|
||||
policy = 0 // maxNodes == 1
|
||||
policy = linux.MPOL_DEFAULT // maxNodes == 1
|
||||
}
|
||||
if mode != 0 {
|
||||
if _, err := t.CopyOut(mode, policy); err != nil {
|
||||
if _, err := policy.CopyOut(t, mode); err != nil {
|
||||
return 0, nil, err
|
||||
}
|
||||
}
|
||||
@@ -216,7 +216,7 @@ func GetMempolicy(t *kernel.Task, args arch.SyscallArguments) (uintptr, *kernel.
|
||||
|
||||
// SetMempolicy implements the syscall set_mempolicy(2).
|
||||
func SetMempolicy(t *kernel.Task, args arch.SyscallArguments) (uintptr, *kernel.SyscallControl, error) {
|
||||
modeWithFlags := args[0].Int()
|
||||
modeWithFlags := linux.NumaPolicy(args[0].Int())
|
||||
nodemask := args[1].Pointer()
|
||||
maxnode := args[2].Uint()
|
||||
|
||||
@@ -233,7 +233,7 @@ func SetMempolicy(t *kernel.Task, args arch.SyscallArguments) (uintptr, *kernel.
|
||||
func Mbind(t *kernel.Task, args arch.SyscallArguments) (uintptr, *kernel.SyscallControl, error) {
|
||||
addr := args[0].Pointer()
|
||||
length := args[1].Uint64()
|
||||
mode := args[2].Int()
|
||||
mode := linux.NumaPolicy(args[2].Int())
|
||||
nodemask := args[3].Pointer()
|
||||
maxnode := args[4].Uint()
|
||||
flags := args[5].Uint()
|
||||
@@ -258,9 +258,9 @@ func Mbind(t *kernel.Task, args arch.SyscallArguments) (uintptr, *kernel.Syscall
|
||||
return 0, nil, err
|
||||
}
|
||||
|
||||
func copyInMempolicyNodemask(t *kernel.Task, modeWithFlags int32, nodemask usermem.Addr, maxnode uint32) (int32, uint64, error) {
|
||||
flags := modeWithFlags & linux.MPOL_MODE_FLAGS
|
||||
mode := modeWithFlags &^ linux.MPOL_MODE_FLAGS
|
||||
func copyInMempolicyNodemask(t *kernel.Task, modeWithFlags linux.NumaPolicy, nodemask usermem.Addr, maxnode uint32) (linux.NumaPolicy, uint64, error) {
|
||||
flags := linux.NumaPolicy(modeWithFlags & linux.MPOL_MODE_FLAGS)
|
||||
mode := linux.NumaPolicy(modeWithFlags &^ linux.MPOL_MODE_FLAGS)
|
||||
if flags == linux.MPOL_MODE_FLAGS {
|
||||
// Can't specify both mode flags simultaneously.
|
||||
return 0, 0, syserror.EINVAL
|
||||
|
||||
Reference in New Issue
Block a user