3636#include "protobuf.h"
3737#include "images/pagemap.pb-c.h"
3838
39+ struct madv_guard_region {
40+ unsigned long start ;
41+ size_t len ;
42+
43+ struct list_head l ;
44+ };
45+
3946static int task_reset_dirty_track (int pid )
4047{
4148 int ret ;
@@ -1131,12 +1138,29 @@ static int premap_priv_vmas(struct pstree_item *t, struct vm_area_list *vmas, vo
11311138 return ret ;
11321139}
11331140
1141+ static int register_madv_guard_region (unsigned long start , size_t len , struct list_head * to )
1142+ {
1143+ struct madv_guard_region * madv_guard_region ;
1144+
1145+ madv_guard_region = xzalloc (sizeof (* madv_guard_region ));
1146+ if (!madv_guard_region )
1147+ return -1 ;
1148+
1149+ madv_guard_region -> start = start ;
1150+ madv_guard_region -> len = len ;
1151+
1152+ list_add_tail (& madv_guard_region -> l , to );
1153+
1154+ return 0 ;
1155+ }
1156+
11341157static int restore_priv_vma_content (struct pstree_item * t , struct page_read * pr )
11351158{
11361159 struct vma_area * vma ;
11371160 int ret = 0 ;
11381161 struct list_head * vmas = & rsti (t )-> vmas .h ;
11391162 struct list_head * vma_io = & rsti (t )-> vma_io ;
1163+ struct list_head * madv_guard_region = & rsti (t )-> madv_guard_region ;
11401164
11411165 unsigned int nr_restored = 0 ;
11421166 unsigned int nr_shared = 0 ;
@@ -1173,6 +1197,14 @@ static int restore_priv_vma_content(struct pstree_item *t, struct page_read *pr)
11731197 continue ;
11741198 }
11751199
1200+ if (pagemap_guard (pr -> pe )) {
1201+ if (register_madv_guard_region (va , nr_pages * PAGE_SIZE , madv_guard_region ))
1202+ return -1 ;
1203+
1204+ pr -> skip_pages (pr , nr_pages * PAGE_SIZE );
1205+ continue ;
1206+ }
1207+
11761208 for (i = 0 ; i < nr_pages ; i ++ ) {
11771209 unsigned char buf [PAGE_SIZE ];
11781210 void * p ;
@@ -1494,6 +1526,29 @@ int open_vmas(struct pstree_item *t)
14941526 return 0 ;
14951527}
14961528
1529+ static int prepare_madv_guards (struct list_head * from , struct task_restore_args * ta )
1530+ {
1531+ struct madv_guard_region * madv_guard_region ;
1532+
1533+ ta -> madv_guard_regions = (struct rst_madv_guard_region * )rst_mem_align_cpos (RM_PRIVATE );
1534+ ta -> madv_guard_regions_n = 0 ;
1535+
1536+ list_for_each_entry (madv_guard_region , from , l ) {
1537+ struct rst_madv_guard_region * region ;
1538+
1539+ region = rst_mem_alloc (sizeof (* region ), RM_PRIVATE );
1540+ if (!region )
1541+ return -1 ;
1542+
1543+ region -> start = madv_guard_region -> start ;
1544+ region -> len = madv_guard_region -> len ;
1545+
1546+ ta -> madv_guard_regions_n ++ ;
1547+ }
1548+
1549+ return 0 ;
1550+ }
1551+
14971552static int prepare_vma_ios (struct pstree_item * t , struct task_restore_args * ta )
14981553{
14991554 struct cr_img * pages ;
@@ -1526,6 +1581,7 @@ static int prepare_vma_ios(struct pstree_item *t, struct task_restore_args *ta)
15261581
15271582int prepare_vmas (struct pstree_item * t , struct task_restore_args * ta )
15281583{
1584+ int ret = 0 ;
15291585 struct vma_area * vma ;
15301586 struct vm_area_list * vmas = & rsti (t )-> vmas ;
15311587
@@ -1549,5 +1605,13 @@ int prepare_vmas(struct pstree_item *t, struct task_restore_args *ta)
15491605 vma_premmaped_start (vme ) = vma -> premmaped_addr ;
15501606 }
15511607
1552- return prepare_vma_ios (t , ta );
1608+ ret = prepare_vma_ios (t , ta );
1609+ if (ret )
1610+ return ret ;
1611+
1612+ ret = prepare_madv_guards (& rsti (t )-> madv_guard_region , ta );
1613+ if (ret )
1614+ return ret ;
1615+
1616+ return ret ;
15531617}
0 commit comments