From patchwork Fri Jun 29 18:20:05 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexey Brodkin X-Patchwork-Id: 937077 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=linux-snps-arc-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=synopsys.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="tlZyGKz9"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=synopsys.com header.i=@synopsys.com header.b="mZtNydWi"; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 41HQ1L6g2Rz9s1B for ; Sat, 30 Jun 2018 04:20:22 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Owner; bh=bsV1hujjRdIBNaNwgED55mFnRvV3WCkVs9w5t0iqZeI=; b=tlZ yGKz9yneKKne+MDMaAGiFN5c8P3Sr+NhjwEJrIyPHogm0ykbj4qB3cSAVBC3KnfKbNBdXcy6Hw45n AZpzNDZiEmvB6dleiI3szGmRM3fyISKXrLNbV5PaSTCvIB9tAS2Dk42Vcb9Bg0xlrcWB8sJU86knz OG502IiM+X3GU43J3gJ4IgbQwIByGGtrFclyRfnrn4Q5iJ5qSlH0QDn9VSbiZZrDzBblwAboE8q9p UMC8sTi2LVFqAB1250U/O2MPZv+u+tHp82Qu+7/VtVimTJ0172f0VM8uZh11S86X2rtHHrMiW6tcW OgnbQ3Pg/XoQjtQgfHnZokAPkeyy6LQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1fYy0K-0008Rq-Pf; Fri, 29 Jun 2018 18:20:20 +0000 Received: from smtprelay4.synopsys.com ([198.182.47.9] helo=smtprelay.synopsys.com) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fYy0H-0007bA-1o for linux-snps-arc@lists.infradead.org; Fri, 29 Jun 2018 18:20:19 +0000 Received: from mailhost.synopsys.com (mailhost2.synopsys.com [10.13.184.66]) by smtprelay.synopsys.com (Postfix) with ESMTP id 6A3C624E09A8; Fri, 29 Jun 2018 11:20:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1530296406; bh=KCm8HG6HhE6dU3GZSW4gdapqL4xYaaELj6oQgAphV9g=; h=From:To:Cc:Subject:Date:From; b=mZtNydWinR3/3a9jfUd10oEHRyxDFOXm1CW/OMUXRREuzux0JeUmeg55vHKuHObxY egRTm6LsavPfMvgCyP2wUl6tgwt0cpT+5gtK3kKWIjM0LHn7QH7V9ASy4GRk2Wfmy9 HXdUZsIvQdoIwUOHvJcAmwEGTdU2mBZaBqWfbhQ8LZAhnkLJSCxvPRMNmtwTCqQvWJ 6+kj8VzMi5RR4unawpb+bKmZOKgmBR4lnuC1vddqQIQd9jf6DvTkRopuJJXjPG0JMB wgPxNoPMzQsMy4JgV+MCh5HHNOTu9v5IYRS4vTrPvEJGj5wfOgvlc472NYMZWZoSbn 14kvVtCgf+hnQ== Received: from abrodkin-7480l.internal.synopsys.com (abrodkin-7480l.internal.synopsys.com [10.9.128.133]) by mailhost.synopsys.com (Postfix) with ESMTP id 54B4039E5; Fri, 29 Jun 2018 11:20:06 -0700 (PDT) From: Alexey Brodkin To: linux-snps-arc@lists.infradead.org Subject: [PATCH] ARC: Improve handling of fatal signals in do_page_fault() Date: Fri, 29 Jun 2018 11:20:05 -0700 Message-Id: <20180629182005.10243-1-abrodkin@synopsys.com> X-Mailer: git-send-email 2.17.1 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180629_112017_180875_3523EBB0 X-CRM114-Status: GOOD ( 11.93 ) X-Spam-Score: -0.1 (/) X-Spam-Report: SpamAssassin version 3.4.1 on bombadil.infradead.org summary: Content analysis details: (-0.1 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at http://www.dnswl.org/, no trust [198.182.47.9 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature X-BeenThere: linux-snps-arc@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Linux on Synopsys ARC Processors List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Vineet Gupta , Alexey Brodkin , linux-kernel@vger.kernel.org MIME-Version: 1.0 Sender: "linux-snps-arc" Errors-To: linux-snps-arc-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org This was triggered by investigation of a deadlock after OOM killer invocation, see [1] for more details. Looks like our handling of fatal signal in do_page_fault() has some issues: 1. We only want to do special (read "early") handling of fatal signal if handle_mm_fault() returned VM_FAULT_RETRY so that we don't loop in retry loop endlessly, otherwise we'll handle that signal normally on exit from exception handler. 2. up_read() is not needed as indeed it will be done in __lock_page_or_retry() in mm/filemap.c. With above comments in mind simplified version should be like that: ------------------------------->8--------------------------- if (fatal_signal_pending(current) if (fault & VM_FAULT_RETRY) if (user_mode(regs)) return; ------------------------------->8--------------------------- But looks like there's a room for improvement, see [2]. Instead of proceeding forward and then inevitably hitting retry path we short-cut right to kernel fix-up code in no_context. [1] http://lists.infradead.org/pipermail/linux-snps-arc/2018-February/003403.html [2] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=746a272e44141af24a02f6c9b0f65f4c4598ed42 Signed-off-by: Alexey Brodkin --- arch/arc/mm/fault.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/arch/arc/mm/fault.c b/arch/arc/mm/fault.c index a0b7bd6d030d..17ed78e2f5eb 100644 --- a/arch/arc/mm/fault.c +++ b/arch/arc/mm/fault.c @@ -139,12 +139,16 @@ void do_page_fault(unsigned long address, struct pt_regs *regs) */ fault = handle_mm_fault(vma, address, flags); - /* If Pagefault was interrupted by SIGKILL, exit page fault "early" */ + /* 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 (unlikely(fatal_signal_pending(current))) { - if ((fault & VM_FAULT_ERROR) && !(fault & VM_FAULT_RETRY)) - up_read(&mm->mmap_sem); - if (user_mode(regs)) + if (fault & VM_FAULT_RETRY) { + if (!user_mode(regs)) + goto no_context; return; + } } perf_sw_event(PERF_COUNT_SW_PAGE_FAULTS, 1, regs, address);