Jui-min Lee has uploaded this change for review. (
https://gem5-review.googlesource.com/c/public/gem5/+/58289 )
Change subject: mem: Align mmap offset to page boundary
......................................................................
mem: Align mmap offset to page boundary
If we create abstract memories with a sub-page size on a system with
shared backstore, the offset of next mmap might become non-page-align
and cause an invalid argument error.
In this CL, we always upscale the range size to multiple of page before
updating the offset, so the offset is always on page boundary.
Change-Id: I3a6adf312f2cb5a09ee6a24a87adc62b630eac66
---
M src/mem/physical.cc
M src/mem/physical.hh
2 files changed, 24 insertions(+), 2 deletions(-)
diff --git a/src/mem/physical.cc b/src/mem/physical.cc
index cae37a0..94438db 100644
--- a/src/mem/physical.cc
+++ b/src/mem/physical.cc
@@ -50,6 +50,7 @@
#include <iostream>
#include <string>
+#include "base/intmath.hh"
#include "base/trace.hh"
#include "debug/AddrRanges.hh"
#include "debug/Checkpoint.hh"
@@ -81,7 +82,8 @@
const std::string& shared_backstore,
bool auto_unlink_shared_backstore) :
_name(_name), size(0), mmapUsingNoReserve(mmap_using_noreserve),
- sharedBackstore(shared_backstore), sharedBackstoreSize(0)
+ sharedBackstore(shared_backstore), sharedBackstoreSize(0),
+ pageSize(sysconf(_SC_PAGE_SIZE))
{
// Register cleanup callback if requested.
if (auto_unlink_shared_backstore && !sharedBackstore.empty()) {
@@ -217,7 +219,9 @@
} else {
// Newly create backstore will be located after previous one.
map_offset = sharedBackstoreSize;
- sharedBackstoreSize += range.size();
+ // mmap requires the offset to be multiple of page, so we need to
+ // upscale the range size.
+ sharedBackstoreSize += divCeil(range.size(), pageSize) * pageSize;
DPRINTF(AddrRanges, "Sharing backing store as %s at offset %llu\n",
sharedBackstore.c_str(), (uint64_t)map_offset);
shm_fd = shm_open(sharedBackstore.c_str(), O_CREAT | O_RDWR, 0666);
diff --git a/src/mem/physical.hh b/src/mem/physical.hh
index 3a976ed..4997d80 100644
--- a/src/mem/physical.hh
+++ b/src/mem/physical.hh
@@ -156,6 +156,8 @@
const std::string sharedBackstore;
uint64_t sharedBackstoreSize;
+ long pageSize;
+
// The physical memory used to provide the memory in the simulated
// system
std::vector<BackingStoreEntry> backingStore;
--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/58289
To unsubscribe, or for help writing mail filters, visit
https://gem5-review.googlesource.com/settings
Gerrit-Project: public/gem5
Gerrit-Branch: develop
Gerrit-Change-Id: I3a6adf312f2cb5a09ee6a24a87adc62b630eac66
Gerrit-Change-Number: 58289
Gerrit-PatchSet: 1
Gerrit-Owner: Jui-min Lee <f...@google.com>
Gerrit-MessageType: newchange
_______________________________________________
gem5-dev mailing list -- gem5-dev@gem5.org
To unsubscribe send an email to gem5-dev-le...@gem5.org
%(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s