vaibhav
vaibhav

Reputation: 116

Cleared RW (write protect) flag for PTEs of a process in kernel yet no segmentation fault on write

I implemented incremental process checkpointing at page level(I just dump the data from the process address space into a file).

The approach I used is as follows. I used two system calls:

  1. Complete Checkpoint: copy entire address space. Also if write bit is set for a page, clear it.

  2. Incremental checkpoint: only dump data if write bit is set and clear it again. So basically, I check if write bit is set for an incremental checkpoint. If yes, dump the page data.

Test program:

char a[10000];
sys_cp_range(a,a+10000);
a[3]='A'; 
sys_incr_cp_range(a,a+10000);

From what I know, the kernel should be doing page fault and handle illegal write case by killing the process with SIGSEGV. Yet the program is successfully checkpointed. What is exactly happening here ?

Upvotes: 1

Views: 509

Answers (1)

Alexey Frunze
Alexey Frunze

Reputation: 62106

If you modify a PTE when it's still cached in the TLB, the effect of the modification may be unseen for a while (until the PTE gets evicted from the TLB and has to be reread from the page table).

You need to invalidate the PTE in the TLB with the invlpg (I'm assuming x86) instruction after PTE modification. And it has to be done on all CPUs. There must be a dedicated function for this purpose in the kernel.

Also it wouldn't hurt to double check that the compiler didn't reorder or throw away anything from the above code.

Upvotes: 2

Related Questions