@@ -30,6 +30,33 @@ void Machine::permanent_remote_connect(Machine& other)
3030 other.remote_connect (*this , true );
3131}
3232
33+ void Machine::remote_update_gigapage_mappings (Machine& remote)
34+ {
35+ auto & caller = *this ;
36+ const auto remote_vmem = remote.main_memory ().vmem ();
37+ static constexpr uint64_t PDE64_ADDR_MASK = ~0x8000000000000FFF ;
38+ auto * main_pml4 = caller.main_memory ().page_at (caller.main_memory ().page_tables );
39+ auto * main_pdpt = caller.main_memory ().page_at (main_pml4[0 ] & PDE64_ADDR_MASK);
40+
41+ auto * remote_pml4 = remote.main_memory ().page_at (remote.main_memory ().page_tables );
42+ auto * remote_pdpt = remote.main_memory ().page_at (remote_pml4[0 ] & PDE64_ADDR_MASK);
43+
44+ // Gigabyte starting index and end index (rounded up)
45+ const auto begin = remote_vmem.physbase >> 30 ;
46+ const auto end = (remote_vmem.remote_end + 0x3FFFFFFF ) >> 30 ;
47+
48+ for (size_t i = begin; i < end; i++)
49+ {
50+ if (main_pdpt[i] != remote_pdpt[i]) {
51+ if constexpr (VERBOSE_REMOTE) {
52+ fprintf (stderr, " Updating remote PDPT entry %zu from 0x%lX to 0x%lX\n " ,
53+ i, main_pdpt[i], remote_pdpt[i]);
54+ }
55+ main_pdpt[i] = remote_pdpt[i];
56+ }
57+ }
58+
59+ }
3360void Machine::remote_connect (Machine& remote, bool connect_now)
3461{
3562 const auto remote_vmem = remote.main_memory ().vmem ();
@@ -50,25 +77,7 @@ void Machine::remote_connect(Machine& remote, bool connect_now)
5077 if (connect_now)
5178 {
5279 // Copy gigabyte entries covered by remote memory into these page tables
53- static constexpr uint64_t PDE64_ADDR_MASK = ~0x8000000000000FFF ;
54- auto * main_pml4 = this ->main_memory ().page_at (this ->main_memory ().page_tables );
55- auto * main_pdpt = this ->main_memory ().page_at (main_pml4[0 ] & PDE64_ADDR_MASK);
56-
57- auto * remote_pml4 = remote.main_memory ().page_at (remote.main_memory ().page_tables );
58- auto * remote_pdpt = remote.main_memory ().page_at (remote_pml4[0 ] & PDE64_ADDR_MASK);
59-
60- // Gigabyte starting index and end index (rounded up)
61- const auto begin = remote_vmem.physbase >> 30 ;
62- const auto end = (remote_vmem.remote_end + 0x3FFFFFFF ) >> 30 ;
63- if (UNLIKELY (begin >= 512 || end > 512 || begin >= end))
64- throw MachineException (" Remote memory produced invalid indexes (>512GB?)" );
65-
66- // Install gigabyte entries from remote VM into this VM
67- // The VM and page tables technically support 2MB region alignments.
68- for (size_t i = begin; i < end; i++)
69- {
70- main_pdpt[i] = remote_pdpt[i]; // GB-page
71- }
80+ this ->remote_update_gigapage_mappings (remote);
7281 }
7382
7483 // Finalize
@@ -118,7 +127,7 @@ void Machine::ipre_remote_resume_now(bool save_all, std::function<void(Machine&)
118127
119128 const auto remote_cow_counter = remote ().memory .cow_written_pages .size ();
120129 bool do_prepare = false ;
121- if (this ->m_remote_cow_counter != remote_cow_counter) {
130+ if (true || this ->m_remote_cow_counter != remote_cow_counter) {
122131 this ->m_remote_cow_counter = remote_cow_counter;
123132 // New working memory pages have been created in the remote,
124133 // so we need to make sure we see the latest changes.
0 commit comments