[CRIU] Re: [PATCH cr 09/16] restorer: remap private vmas to correct places

Andrew Vagin avagin at parallels.com
Wed Oct 31 07:46:10 EDT 2012


On Tue, Oct 30, 2012 at 08:34:57PM +0400, Pavel Emelyanov wrote:
> >  
> > +static int vma_remap(unsigned long src, unsigned long dst, unsigned long len)
> > +{
> > +	unsigned long guard = 0, tmp;
> > +
> > +	pr_info("Remap %lx->%lx len %lx\n", src, dst, len);
> > +
> > +	if (src - dst < len)
> > +		guard = dst;
> > +	else if (dst - src < len)
> > +		guard = dst + len - PAGE_SIZE;
> > +
> > +	if (src == dst)
> > +		return 0;
> > +
> > +	if (guard == 0) {
> > +		tmp = sys_mremap(src, len, len, MREMAP_MAYMOVE | MREMAP_FIXED, dst);
> > +		if (tmp != dst) {
> > +			pr_err("Unable to remap %lx -> %lx\n", src, dst);
> > +			return -1;
> > +		}
> > +	} else {
> > +		/* Regions are overlapped */
> > +		unsigned long addr;
> > +
> > +		/* Prevent overlapping with a temporary place */
> > +		tmp = sys_mmap((void *) guard, PAGE_SIZE, PROT_NONE,
> > +					MAP_PRIVATE | MAP_ANONYMOUS, 0, 0);
> 
> What is this guard for? Why is it not unmapped after the vma remap?

We have
                   |g|       |___________vma___________|
We want
                   |___________vma___________|
A tmp vma w/o guard can be overlaped again with a target vma
|___________vma___________|

> 
> > +		if (tmp != guard) {
> > +			pr_err("Unable to map a guard page %lx (%lx)\n", guard, tmp);
> > +			return -1;
> > +		}
> > +
> > +		/* Choose a temporary place */
> > +		addr = sys_mmap(NULL, len, PROT_NONE,
> > +					MAP_PRIVATE | MAP_ANONYMOUS, 0, 0);
> > +		if (addr == (unsigned long) MAP_FAILED) {
> > +			pr_err("Unable to reserve memory (%lx)\n", addr);
> > +			return -1;
> > +		}
> > +
> > +		tmp = sys_mremap(src, len, len,
> > +					MREMAP_MAYMOVE | MREMAP_FIXED, addr);
> > +		if (tmp != addr) {
> > +			pr_err("Unable to remap %lx -> %lx (%lx)\n", src, addr, tmp);
> > +			return -1;
> > +		}
> > +
> > +		tmp = sys_mremap(addr, len, len,
> > +					MREMAP_MAYMOVE | MREMAP_FIXED, dst);
> 
> This should be merged with the above if (guard == 0) case for better readability.

Ok.

> 
> > +		if (tmp != dst) {
> > +			pr_err("Unable to remap %lx -> %lx (%lx)\n", addr, dst, tmp);
> > +			return -1;
> > +		}
> > +	}
> > +
> > +	return 0;


More information about the CRIU mailing list