diff options
author | Michael Anthony Knyszek <mknyszek@google.com> | 2020-04-22 21:36:11 +0000 |
---|---|---|
committer | Michael Knyszek <mknyszek@google.com> | 2020-04-27 21:37:31 +0000 |
commit | 287d1ec96c1271de532c6b1160cd9cbbe717ee34 (patch) | |
tree | 63c19da7e5e16975f951b27de9f06f9df7762c11 /src/runtime/mpagecache.go | |
parent | 9a3f22be7a3a28bd8f33a86925e2b05f2314ead2 (diff) | |
download | go-287d1ec96c1271de532c6b1160cd9cbbe717ee34.tar.gz go-287d1ec96c1271de532c6b1160cd9cbbe717ee34.zip |
runtime: ensure allocToCache updates searchAddr in a valid way
Currently allocToCache assumes it can move the search address past the
block it allocated the cache from, which violates the property that
searchAddr should always point to mapped memory (i.e. memory represented
by pageAlloc.inUse).
This bug was already fixed once for pageAlloc.alloc in the Go 1.14
release via CL 216697, but that changed failed to take into account
allocToCache.
Fixes #38605.
Change-Id: Id08180aa10d19dc0f9f551a1d9e327a295560dff
Reviewed-on: https://go-review.googlesource.com/c/go/+/229577
Run-TryBot: Michael Knyszek <mknyszek@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: David Chase <drchase@google.com>
Diffstat (limited to 'src/runtime/mpagecache.go')
-rw-r--r-- | src/runtime/mpagecache.go | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/src/runtime/mpagecache.go b/src/runtime/mpagecache.go index 5b679d357d..fae54d7cdd 100644 --- a/src/runtime/mpagecache.go +++ b/src/runtime/mpagecache.go @@ -148,9 +148,14 @@ func (s *pageAlloc) allocToCache() pageCache { // Update as an allocation, but note that it's not contiguous. s.update(c.base, pageCachePages, false, true) - // We're always searching for the first free page, and we always know the - // up to pageCache size bits will be allocated, so we can always move the - // searchAddr past the cache. - s.searchAddr = c.base + pageSize*pageCachePages + // Set the search address to the last page represented by the cache. + // Since all of the pages in this block are going to the cache, and we + // searched for the first free page, we can confidently start at the + // next page. + // + // However, s.searchAddr is not allowed to point into unmapped heap memory + // unless it is maxSearchAddr, so make it the last page as opposed to + // the page after. + s.searchAddr = c.base + pageSize*(pageCachePages-1) return c } |