From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752500AbdK0Nvr (ORCPT ); Mon, 27 Nov 2017 08:51:47 -0500 Received: from foss.arm.com ([217.140.101.70]:38116 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752278AbdK0Nvp (ORCPT ); Mon, 27 Nov 2017 08:51:45 -0500 Date: Mon, 27 Nov 2017 13:51:36 +0000 From: Mark Rutland To: Greentime Hu Cc: greentime@andestech.com, linux-kernel@vger.kernel.org, arnd@arndb.de, linux-arch@vger.kernel.org, tglx@linutronix.de, jason@lakedaemon.net, marc.zyngier@arm.com, robh+dt@kernel.org, netdev@vger.kernel.org, deanbo422@gmail.com, devicetree@vger.kernel.org, viro@zeniv.linux.org.uk, dhowells@redhat.com, will.deacon@arm.com, daniel.lezcano@linaro.org, linux-serial@vger.kernel.org, Vincent Chen Subject: Re: [PATCH v2 06/35] nds32: MMU fault handling and page table management Message-ID: <20171127135136.3gnguzaf6d52tcpd@lakrids.cambridge.arm.com> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: NeoMutt/20170113 (1.7.2) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, On Mon, Nov 27, 2017 at 08:27:53PM +0800, Greentime Hu wrote: > +void do_page_fault(unsigned long entry, unsigned long addr, > + unsigned int error_code, struct pt_regs *regs) > +{ > + /* > + * 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; > + } > + } > + 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@arm.com ... for details and a test case. Thanks, Mark.