Received: by 10.223.164.202 with SMTP id h10csp4046853wrb; Tue, 28 Nov 2017 23:26:46 -0800 (PST) X-Google-Smtp-Source: AGs4zMaOPXu+E99W1jlOEyISIMqr8RXlYrQw90Ab1hBKKFKc5REk8OONgzCyrGaekEQJFF/AQeWW X-Received: by 10.159.218.75 with SMTP id x11mr2018742plv.141.1511940406647; Tue, 28 Nov 2017 23:26:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1511940406; cv=none; d=google.com; s=arc-20160816; b=m+9LK+J6loDdULlAskfTLc6uDuOOSAyLKLmI3AolyP+ES/p5TtYGVtQKZzi47VZtNz 0oII8sMYQwxgxG/DIKS5bvrx53sFPm9HHkJZJvjMz2pxwLAk/BeDuxoqUeB3WBfx+t0+ p9amWp/6BR7SQwz+SzNPwjMTEemGw1tYFVL7SkIz/t0Jd+McpGkp92j7yHgYUntH7LiU EZkxubG7HAPIvppkYWnQTCigumJWWfoVMv+ySOavwST7PcXLa8NlbpSzbNzGktGgZ6TA ZCcEx2tuOpvjHMSci5knxEsfjjAzTKznxsyzwTPx2XimM2LOoUmI+K/2DBpZXulDpQsX o0wg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature :arc-authentication-results; bh=4E2VDL4n8AeCTWcMVvDZ+G54v5A3mqqr6gSviKKI0KY=; b=f67YeFWK6mcaL9jW/CG9x6FdlCakPoAu6J2zHFyelHidyiANw8GzOTlVfdPFH9YWde 2wysLP06s5WJ/IerECzn3Kcu9rIlquNsiuaVGlUNaUisbVi1/iNr4q96nF8z7MMtI1Vu LbGvMINc6N+jrwruD4x2RpRAmFmjw7WlvxZv+aXISZYJwF8/0zf6DIPj8Az9jiS3rC8n /DaaO2VWLByvLglBU2DOaT1ndtLyuBW/PiBGAqUwSmCGm28+Sme2zZ2QEyn4QyAiszQc 8nHvyNLIvW4AIkTSL/63hBOmMGmCUhquxWjamKGnAerhK+cPPLlVXu6XNwA51sHSKIp3 yO1w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=I8NRkgIA; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r87si870876pfa.254.2017.11.28.23.26.36; Tue, 28 Nov 2017 23:26:46 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=I8NRkgIA; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752157AbdK2HZC (ORCPT + 71 others); Wed, 29 Nov 2017 02:25:02 -0500 Received: from mail-vk0-f67.google.com ([209.85.213.67]:35170 "EHLO mail-vk0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750818AbdK2HY6 (ORCPT ); Wed, 29 Nov 2017 02:24:58 -0500 Received: by mail-vk0-f67.google.com with SMTP id n63so620855vkf.2; Tue, 28 Nov 2017 23:24:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=4E2VDL4n8AeCTWcMVvDZ+G54v5A3mqqr6gSviKKI0KY=; b=I8NRkgIAC8MtSCLdepU+6wIyw3aD/WLtcmuUZ9ui3O5X0+B0VE4jtQioCoVj7wETm+ JYfhE/xFTVBSu7JmlDZIU1fl3/7YcoEguuDwcd4VSK7FzDkOg6lu+983TtkywEAtt9QG tCNNdSurfU/Rb1RHmMgMWxj3p0PBKgmU7BD10auRC05H6h29J1+Mf8Tih5UGs89gFeBU /RQY4lzQa8P8xG0W1VhRqWuhJ2SHrI2KvBcbTOEfpxywVCfLTXYn56z47UGn7ov4UXRA 8ags8ZVu9LcSLqEVlMcnjk7pG4fWa4nv67lQIIDl8vJqQuwD7VUZUUzecpHJ6XGJuKjR 9f6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=4E2VDL4n8AeCTWcMVvDZ+G54v5A3mqqr6gSviKKI0KY=; b=p/+xH6ld5UAzm5e96koFXzWH/xzinIRjOk779mLoc9FitydFRzhtTMlJXE7s3InueT txbN5Bg+zz3EK0wrYJ6Rz456hEdsbZzjh99ttfvPbfs3q2XVuCiAQwZAJunHnuD9+ubX /XHYIAoMUcCuHa2O3waAJQPcMBp1MpMoRfXEuhe2iigxWTiAgZWwi7CuPeCFt/tGNJDl qo+8ZWPX/+HJN9RNkds/REY31Ggv+djcA5UnUa8cxizTGsQ0TLrdBooc6YLiipuVg4HY tGPyIfpNv+22PnB7XHRVc2Ir02G2oYiRVIIMNGmmmmad3LlbG8Tw2svhYQJLb3GU8W3W 0qyQ== X-Gm-Message-State: AJaThX4narMVaDRPb/NhmSVBpcAM1uocpCE0Y+RZkPyLwJBnP9eR0zwm JZLMo5FXXlKYAQVnLxnIVtkqDH5Z07niybFK8Go= X-Received: by 10.31.56.10 with SMTP id f10mr1469183vka.106.1511940297019; Tue, 28 Nov 2017 23:24:57 -0800 (PST) MIME-Version: 1.0 Received: by 10.176.27.105 with HTTP; Tue, 28 Nov 2017 23:24:16 -0800 (PST) In-Reply-To: <20171127135136.3gnguzaf6d52tcpd@lakrids.cambridge.arm.com> References: <20171127135136.3gnguzaf6d52tcpd@lakrids.cambridge.arm.com> From: Greentime Hu Date: Wed, 29 Nov 2017 15:24:16 +0800 Message-ID: Subject: Re: [PATCH v2 06/35] nds32: MMU fault handling and page table management To: Mark Rutland Cc: Greentime , Linux Kernel Mailing List , Arnd Bergmann , linux-arch , Thomas Gleixner , Jason Cooper , Marc Zyngier , Rob Herring , netdev , Vincent Chen , DTML , Al Viro , David Howells , Will Deacon , Daniel Lezcano , linux-serial@vger.kernel.org, Vincent Chen Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, Mark: 2017-11-27 21:51 GMT+08:00 Mark Rutland : > 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 for your teatcase and patch. It works. I will apply it to the next version patch. From 1585227514213721425@xxx Mon Nov 27 13:52:45 +0000 2017 X-GM-THRID: 1585223876827739467 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread