Jui-min Lee has submitted this change. ( 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
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/58289
Reviewed-by: Gabe Black <gabe.bl...@gmail.com>
Maintainer: Gabe Black <gabe.bl...@gmail.com>
Reviewed-by: Boris Shingarov <shinga...@labware.com>
Tested-by: kokoro <noreply+kok...@google.com>
---
M src/mem/physical.cc
M src/mem/physical.hh
2 files changed, 29 insertions(+), 2 deletions(-)

Approvals:
  Boris Shingarov: Looks good to me, approved
Gabe Black: Looks good to me, but someone else must approve; Looks good to me, approved
  kokoro: Regressions pass




diff --git a/src/mem/physical.cc b/src/mem/physical.cc
index cae37a0..06f2cdc 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 += roundUp(range.size(), 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: 3
Gerrit-Owner: Jui-min Lee <f...@google.com>
Gerrit-Reviewer: Boris Shingarov <shinga...@labware.com>
Gerrit-Reviewer: Earl Ou <shunhsin...@google.com>
Gerrit-Reviewer: Gabe Black <gabe.bl...@gmail.com>
Gerrit-Reviewer: Jui-min Lee <f...@google.com>
Gerrit-Reviewer: Nikos Nikoleris <nikos.nikole...@arm.com>
Gerrit-Reviewer: Yu-hsin Wang <yuhsi...@google.com>
Gerrit-Reviewer: kokoro <noreply+kok...@google.com>
Gerrit-MessageType: merged
_______________________________________________
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

Reply via email to