Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 29 additions & 18 deletions pkg/sentry/platform/kvm/machine_amd64.go
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,31 @@ func (c *vCPU) SwitchToUser(switchOpts ring0.SwitchOpts, info *linux.SignalInfo)
}
}

func (m *machine) mapUpperHalfRegion(
pageTable *pagetables.PageTables,
virtual uintptr, length uintptr,
opts pagetables.MapOpts,
) {
for length != 0 {
physical, plength, ok := translateToPhysical(virtual)
if !ok || plength == 0 {
panic(fmt.Sprintf("impossible translation: virtual %x length %x", virtual, length))
}
if plength > length {
plength = length
}

pageTable.Map(
hostarch.Addr(ring0.KernelStartAddress|virtual),
plength,
opts,
physical)

length -= plength
virtual += plength
}
}

func (m *machine) mapUpperHalf(pageTable *pagetables.PageTables) {
// Map all the executable regions so that all the entry functions
// are mapped in the upper half.
Expand All @@ -506,30 +531,16 @@ func (m *machine) mapUpperHalf(pageTable *pagetables.PageTables) {

if vr.accessType.Execute {
r := vr.region
physical, length, ok := translateToPhysical(r.virtual)
if !ok || length < r.length {
panic("impossible translation")
}
pageTable.Map(
hostarch.Addr(ring0.KernelStartAddress|r.virtual),
r.length,
pagetables.MapOpts{AccessType: hostarch.Execute, Global: true},
physical)
m.mapUpperHalfRegion(pageTable, r.virtual, r.length,
pagetables.MapOpts{AccessType: hostarch.Execute, Global: true})
}
}); err != nil {
panic(fmt.Sprintf("error parsing /proc/self/maps: %v", err))
}
for start, end := range m.kernel.EntryRegions() {
regionLen := end - start
physical, length, ok := translateToPhysical(start)
if !ok || length < regionLen {
panic("impossible translation")
}
pageTable.Map(
hostarch.Addr(ring0.KernelStartAddress|start),
regionLen,
pagetables.MapOpts{AccessType: hostarch.ReadWrite, Global: true},
physical)
m.mapUpperHalfRegion(pageTable, start, regionLen,
pagetables.MapOpts{AccessType: hostarch.ReadWrite, Global: true})
}
}

Expand Down
Loading