Re: [PATCH v7 3/3] mm: fix double page fault on arm64 if PTE_AF is cleared
From: Jia He <hidden>
Date: 2019-09-21 13:19:56
Also in:
linux-mm, lkml
[On behalf of justin.he@arm.com] Hi Matthew On 2019/9/20 23:53, Matthew Wilcox wrote:
On Fri, Sep 20, 2019 at 09:54:37PM +0800, Jia He wrote:quoted
-static inline void cow_user_page(struct page *dst, struct page *src, unsigned long va, struct vm_area_struct *vma) +static inline int cow_user_page(struct page *dst, struct page *src, + struct vm_fault *vmf) {Can we talk about the return type here?quoted
+ } else { + /* Other thread has already handled the fault + * and we don't need to do anything. If it's + * not the case, the fault will be triggered + * again on the same address. + */ + pte_unmap_unlock(vmf->pte, vmf->ptl); + return -1;...quoted
+ return 0; }So -1 for "try again" and 0 for "succeeded".quoted
+ if (cow_user_page(new_page, old_page, vmf)) {Then we use it like a bool. But it's kind of backwards from a bool because false is success.quoted
+ /* COW failed, if the fault was solved by other, + * it's fine. If not, userspace would re-fault on + * the same address and we will handle the fault + * from the second attempt. + */ + put_page(new_page); + if (old_page) + put_page(old_page); + return 0;And we don't use the return value; in fact we invert it. Would this make more sense: static inline bool cow_user_page(struct page *dst, struct page *src, struct vm_fault *vmf) ... pte_unmap_unlock(vmf->pte, vmf->ptl); return false; ... return true; ... if (!cow_user_page(new_page, old_page, vmf)) { That reads more sensibly for me. We could also go with returning a vm_fault_t, but that would be more complex than needed today, I think.
Ok, will change the return type to bool as you suggested. Thanks --- Cheers, Justin (Jia He) _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel