Thread (92 messages) 92 messages, 13 authors, 2017-12-08

Re: [PATCH v2 06/35] nds32: MMU fault handling and page table management

From: Greentime Hu <hidden>
Date: 2017-11-29 07:25:02
Also in: linux-devicetree, linux-serial, lkml, netdev

Hi, Mark:

2017-11-27 21:51 GMT+08:00 Mark Rutland [off-list ref]:
Hi,

On Mon, Nov 27, 2017 at 08:27:53PM +0800, Greentime Hu wrote:
quoted
+void do_page_fault(unsigned long entry, unsigned long addr,
+                unsigned int error_code, struct pt_regs *regs)
+{
quoted
+     /*
+      * As per x86, we may deadlock here. However, since the kernel only
+      * validly references user space from well defined areas of the code,
+      * we can bug out early if this is from code which shouldn't.
+      */
+     if (unlikely(!down_read_trylock(&mm->mmap_sem))) {
+             if (!user_mode(regs) &&
+                 !search_exception_tables(instruction_pointer(regs)))
+                     goto no_context;
+retry:
+             down_read(&mm->mmap_sem);
+     } else {
+             /*
+              * The above down_read_trylock() might have succeeded in which
+              * case, we'll have missed the might_sleep() from down_read().
+              */
+             might_sleep();
+             if (IS_ENABLED(CONFIG_DEBUG_VM)) {
+                     if (!user_mode(regs) &&
+                         !search_exception_tables(instruction_pointer(regs)))
+                             goto no_context;
+             }
+     }
quoted
+     fault = handle_mm_fault(vma, addr, flags);
+
+     /*
+      * If we need to retry but a fatal signal is pending, handle the
+      * signal first. We do not need to release the mmap_sem because it
+      * would already be released in __lock_page_or_retry in mm/filemap.c.
+      */
+     if ((fault & VM_FAULT_RETRY) && fatal_signal_pending(current))
+             return;
I believe you can get stuck in a livelock here (with an unkillable
task), if a uaccess primitive tries to access a region protected by a
userfaultfd. Please see:

  https://lkml.kernel.org/r/1499782590-31366-1-git-send-email-mark.rutland-5wv7dgnIgG8@public.gmane.org

... for details and a test case.
Thanks for your teatcase and patch. It works.
I will apply it to the next version patch.
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help