summaryrefslogtreecommitdiffhomepage
path: root/pkg/sentry/platform/ring0/pagetables
diff options
context:
space:
mode:
authorAdin Scannell <ascannell@google.com>2018-08-22 14:14:32 -0700
committerShentubot <shentubot@google.com>2018-08-22 14:16:04 -0700
commita7a8d07d7d6bd551d96621ee841b1b0e0f217ca3 (patch)
tree5f38abf432d5713731f6555a17d5e4ea27c1e64d /pkg/sentry/platform/ring0/pagetables
parentbbee911179aaf925f58051de4392502743539802 (diff)
Add separate Recycle method for allocator.
This improves debugging for pagetable-related issues. PiperOrigin-RevId: 209827795 Change-Id: I4cfa11664b0b52f26f6bc90a14c5bb106f01e038
Diffstat (limited to 'pkg/sentry/platform/ring0/pagetables')
-rw-r--r--pkg/sentry/platform/ring0/pagetables/allocator.go19
1 files changed, 16 insertions, 3 deletions
diff --git a/pkg/sentry/platform/ring0/pagetables/allocator.go b/pkg/sentry/platform/ring0/pagetables/allocator.go
index 1499623fb..049fd0247 100644
--- a/pkg/sentry/platform/ring0/pagetables/allocator.go
+++ b/pkg/sentry/platform/ring0/pagetables/allocator.go
@@ -27,8 +27,12 @@ type Allocator interface {
// LookupPTEs looks up PTEs by physical address.
LookupPTEs(physical uintptr) *PTEs
- // FreePTEs frees a set of PTEs.
+ // FreePTEs marks a set of PTEs a freed, although they may not be available
+ // for use again until Recycle is called, below.
FreePTEs(ptes *PTEs)
+
+ // Recycle makes freed PTEs available for use again.
+ Recycle()
}
// RuntimeAllocator is a trivial allocator.
@@ -42,6 +46,9 @@ type RuntimeAllocator struct {
// pool is the set of free-to-use PTEs.
pool []*PTEs
+
+ // freed is the set of recently-freed PTEs.
+ freed []*PTEs
}
// NewRuntimeAllocator returns an allocator that uses runtime allocation.
@@ -51,8 +58,15 @@ func NewRuntimeAllocator() *RuntimeAllocator {
}
}
+// Recycle returns freed pages to the pool.
+func (r *RuntimeAllocator) Recycle() {
+ r.pool = append(r.pool, r.freed...)
+ r.freed = r.freed[:0]
+}
+
// Drain empties the pool.
func (r *RuntimeAllocator) Drain() {
+ r.Recycle()
for i, ptes := range r.pool {
// Zap the entry in the underlying array to ensure that it can
// be properly garbage collected.
@@ -104,6 +118,5 @@ func (r *RuntimeAllocator) LookupPTEs(physical uintptr) *PTEs {
//
//go:nosplit
func (r *RuntimeAllocator) FreePTEs(ptes *PTEs) {
- // Add to the pool.
- r.pool = append(r.pool, ptes)
+ r.freed = append(r.freed, ptes)
}