Skip to content

Commit

Permalink
pagemap: handle short reads
Browse files Browse the repository at this point in the history
  • Loading branch information
avagin committed Mar 18, 2024
1 parent f8b1428 commit 9405da0
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 5 deletions.
16 changes: 11 additions & 5 deletions criu/pagemap-cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ static int pmc_fill_cache(pmc_t *pmc, const struct vma_area *vma)
unsigned long low = vma->e->start & PMC_MASK;
unsigned long high = low + PMC_SIZE;
size_t len = vma_area_len(vma);
size_t size_map;
size_t size_map, off;

if (high > kdat.task_size)
high = kdat.task_size;
Expand Down Expand Up @@ -153,10 +153,16 @@ static int pmc_fill_cache(pmc_t *pmc, const struct vma_area *vma)
BUG_ON(pmc->map_len < size_map);
BUG_ON(pmc->fd < 0);

if (pread(pmc->fd, pmc->map, size_map, PAGEMAP_PFN_OFF(pmc->start)) != size_map) {
pmc_zap(pmc);
pr_perror("Can't read %d's pagemap file", pmc->pid);
return -1;
for (off = 0; off != size_map;) {
ssize_t ret;

ret = pread(pmc->fd, ((void *)pmc->map) + off, size_map - off, PAGEMAP_PFN_OFF(pmc->start) + off);
if (ret == -1) {
pmc_zap(pmc);
pr_perror("Can't read %d's pagemap file", pmc->pid);
return -1;
}
off += ret;
}

return 0;
Expand Down
1 change: 1 addition & 0 deletions test/zdtm/static/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ TST_NOFILE := \
maps05 \
maps09 \
maps10 \
maps_prot_none \
mlock_setuid \
xids00 \
groups \
Expand Down
31 changes: 31 additions & 0 deletions test/zdtm/static/maps_prot_none.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#include <stdint.h>
#include <signal.h>
#include <sys/mman.h>
#include <sys/types.h>
#include <sys/wait.h>
#include "zdtmtst.h"

const char *test_doc = "Test a huge PROT_NONE mapping that requires "
"to read more than MAX_RW_COUNT from the pagemap file.";
const char *test_author = "Bui Quang Minh <minhquangbui99@gmail.com>";

#define MEM_SIZE (2UL << 40)

int main(int argc, char **argv)
{
void *addr;

test_init(argc, argv);

addr = mmap(NULL, MEM_SIZE, PROT_NONE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_NORESERVE, 0, 0);
if (addr == MAP_FAILED) {
pr_perror("Map failed");
return 1;
}

test_daemon();
test_waitsig();

pass();
return 1;
}

0 comments on commit 9405da0

Please sign in to comment.