Re: [PATCH v7 04/24] mm: Dont assume page-table invariance during faults

From: Matthew Wilcox
Date: Thu Feb 08 2018 - 10:01:21 EST


On Thu, Feb 08, 2018 at 03:35:58PM +0100, Laurent Dufour wrote:
> I reviewed that part of code, and I think I could now change the way
> pte_unmap_safe() is checking for the pte's value. Since we now have all the
> needed details in the vm_fault structure, I will pass it to
> pte_unamp_same() and deal with the VMA checks when locking for the pte as
> it is done in the other part of the page fault handler by calling
> pte_spinlock().

This does indeed look much better! Thank you!

> This means that this patch will be dropped, and pte_unmap_same() will become :
>
> static inline int pte_unmap_same(struct vm_fault *vmf, int *same)
> {
> int ret = 0;
>
> *same = 1;
> #if defined(CONFIG_SMP) || defined(CONFIG_PREEMPT)
> if (sizeof(pte_t) > sizeof(unsigned long)) {
> if (pte_spinlock(vmf)) {
> *same = pte_same(*vmf->pte, vmf->orig_pte);
> spin_unlock(vmf->ptl);
> }
> else
> ret = VM_FAULT_RETRY;
> }
> #endif
> pte_unmap(vmf->pte);
> return ret;
> }

I'm not a huge fan of auxiliary return values. Perhaps we could do this
instead:

ret = pte_unmap_same(vmf);
if (ret != VM_FAULT_NOTSAME) {
if (page)
put_page(page);
goto out;
}
ret = 0;

(we have a lot of unused bits in VM_FAULT_, so adding a new one shouldn't
be a big deal)