Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp829992ybv; Thu, 20 Feb 2020 08:03:21 -0800 (PST) X-Google-Smtp-Source: APXvYqyW6rsQxxhtrLnQnqsWSGD0nL/SuJ3NdGVI2RtVX5PFM/geitN+y0bZ0iLl8Xa1ZtFazHGR X-Received: by 2002:a05:6830:1289:: with SMTP id z9mr25415303otp.317.1582214601065; Thu, 20 Feb 2020 08:03:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582214601; cv=none; d=google.com; s=arc-20160816; b=G8RgWnts17K4UZUwtpis8b/l/0+3LYeNgps4aJvOnPtu6vxkE4fxEvr4r1nw4YLQya RsbJFxtBWnnQflFQCKXf1uKe8FwEgafysB8hCz/Sk9qgG26PTNS4SbUmr1e/+2VVskU4 8KpS0Nds6kvEjOu48AQHbmEA/GrzWZF6BltzarDsF1z2lruzLZsCpiwW/vbAKa+5w5dq E6978gpOkU3bg60llPFbrwd1rdxnDO3ZS9ZQmBb1gj1WhK7+Uc73r+S6opKzWLM+FubG yXpaMgdEeBIwH+B/T/yUd0MSaNVIZO+ahdc8+PthAk5G/AVbku3lgbg4mnqrmtzt9f+8 b8vQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=ZV5sRyntf0+M2WjfLiyPs+XgTlCWnjkOIA0alCn5h7M=; b=VWJA1TFgiGi+JfSCL0V3eCqt9b+6UreRfQMPTofbXjD11QHWSfZrk+Ua3t2TK3U00c Ing4T7/NxURRMGAh6K7+pwWlALjTvWir9FD7Hb2/NJNIIWiV5fqjUDS83z0D626465MG C3b6e0wEtspRehJ1Gw5r+ZFaHnP+4tTCzvnm91qcv/KCYAACJhAVZMy2y8RAf7CEda5I +xL6RA3Knu1Y4Sz2zL5P/iEwv/Ex9XQzLp9EBjkcK4OzTQXbNNOEH1uVuEoYf0OuxIoA zo7T6DDoYYlCkzR26moIJRmEPqqFJbThIGpo8RcBj8EOudxj/a8XYB3QmxUtGtFACuRG z4/Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=BststaqZ; 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=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v23si1771692oto.81.2020.02.20.08.03.04; Thu, 20 Feb 2020 08:03:20 -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=@redhat.com header.s=mimecast20190719 header.b=BststaqZ; 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=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728733AbgBTQCl (ORCPT + 99 others); Thu, 20 Feb 2020 11:02:41 -0500 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:47390 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728620AbgBTQCl (ORCPT ); Thu, 20 Feb 2020 11:02:41 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582214559; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ZV5sRyntf0+M2WjfLiyPs+XgTlCWnjkOIA0alCn5h7M=; b=BststaqZdMi7noN1+a8Oy6uBxprcTISqjGdXlzf7ejlSAO+5yqrPCA2siujzBwdPu5YAnU feBJMkgLAt446rV/QFSCZaVFaL9G/uFmCROoe9Kno6CUVeRms+h5JQwZ/hRw5vRs/YLmE5 m9Vi05UyvqejUMPgi82SPb+nco1CLUk= Received: from mail-qv1-f72.google.com (mail-qv1-f72.google.com [209.85.219.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-167-Vokvh5G4MRqzJEjgFJtF2A-1; Thu, 20 Feb 2020 11:02:33 -0500 X-MC-Unique: Vokvh5G4MRqzJEjgFJtF2A-1 Received: by mail-qv1-f72.google.com with SMTP id v3so2877742qvm.2 for ; Thu, 20 Feb 2020 08:02:33 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ZV5sRyntf0+M2WjfLiyPs+XgTlCWnjkOIA0alCn5h7M=; b=bX/U2WK5qb5gDzBGOxRVVBFwL356c0ziXudAB/mh8UIa9WzJDw0oRvIBqmx/0wxrC6 yajcvGZXCkhmTnKqFB0Z/xbS8yrGIngj2Nz0W8gMtn3vDw4UB89QSgjRXKLb2SOkIlh/ SHELisefIC3ngwcLLrntj4jKuLm/RKXF4FjVlVoGApVL6AMAggajdgPXPd6DumZDHtfV OlqUyEsYe15RrWw60DbwV+Q/fmv9yYrok8tnSeUfG0HPCPO8CSMyQJugE8eTwuXL+gTw FWVbmgml3DFkgaYp9iid7F8INDzwrFKmPIpB1bcB1fWlCqy0G6negV963zn7zVzwcviO fb+g== X-Gm-Message-State: APjAAAWGuTOrIIt5ZTnfEnYtVnhE9aQZStsHEpMfWpQtTAEHlRlUzEdA jn5bRz2kQ25+0aUgEKvFgzAMpif2OuH9W2fmI3PB+gEnMtnbtwkXnMoMKSr8HrFPU9FuTdiRTZj I4mGj1foYX1dXMlRWLadlj7Dm X-Received: by 2002:a37:714:: with SMTP id 20mr28851963qkh.347.1582214553471; Thu, 20 Feb 2020 08:02:33 -0800 (PST) X-Received: by 2002:a37:714:: with SMTP id 20mr28851937qkh.347.1582214553239; Thu, 20 Feb 2020 08:02:33 -0800 (PST) Received: from xz-x1.redhat.com ([104.156.64.75]) by smtp.gmail.com with ESMTPSA id g18sm2301qki.13.2020.02.20.08.02.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Feb 2020 08:02:32 -0800 (PST) From: Peter Xu To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Peter Xu , Martin Cracauer , Mike Rapoport , Hugh Dickins , Jerome Glisse , "Kirill A . Shutemov" , Matthew Wilcox , Pavel Emelyanov , Brian Geffon , Maya Gokhale , Denis Plotnikov , Andrea Arcangeli , Johannes Weiner , "Dr . David Alan Gilbert" , Linus Torvalds , Mike Kravetz , Marty McFadden , David Hildenbrand , Bobby Powers , Mel Gorman Subject: [PATCH RESEND v6 09/16] mm: Return faster for non-fatal signals in user mode faults Date: Thu, 20 Feb 2020 11:02:30 -0500 Message-Id: <20200220160230.9598-1-peterx@redhat.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200220155353.8676-1-peterx@redhat.com> References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The idea comes from the upstream discussion between Linus and Andrea: https://lore.kernel.org/lkml/20171102193644.GB22686@redhat.com/ A summary to the issue: there was a special path in handle_userfault() in the past that we'll return a VM_FAULT_NOPAGE when we detected non-fatal signals when waiting for userfault handling. We did that by reacquiring the mmap_sem before returning. However that brings a risk in that the vmas might have changed when we retake the mmap_sem and even we could be holding an invalid vma structure. This patch is a preparation of removing that special path by allowing the page fault to return even faster if we were interrupted by a non-fatal signal during a user-mode page fault handling routine. Suggested-by: Linus Torvalds Suggested-by: Andrea Arcangeli Signed-off-by: Peter Xu --- include/linux/sched/signal.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/include/linux/sched/signal.h b/include/linux/sched/signal.h index 4c87ffce64d1..09d40ce6a162 100644 --- a/include/linux/sched/signal.h +++ b/include/linux/sched/signal.h @@ -379,7 +379,8 @@ static inline bool fault_signal_pending(unsigned int fault_flags, struct pt_regs *regs) { return unlikely((fault_flags & VM_FAULT_RETRY) && - fatal_signal_pending(current)); + (fatal_signal_pending(current) || + (user_mode(regs) && signal_pending(current)))); } /* -- 2.24.1