Received: by 2002:a25:f815:0:0:0:0:0 with SMTP id u21csp632129ybd; Sat, 22 Jun 2019 11:04:23 -0700 (PDT) X-Google-Smtp-Source: APXvYqxctiLmSsQJjRtfpHCCp39SR29qn48xtm8pdDhDqqsMM+iuOBRizffxgqVt+V0YkAmnsh/j X-Received: by 2002:a17:90a:71cb:: with SMTP id m11mr7075193pjs.40.1561226663664; Sat, 22 Jun 2019 11:04:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561226663; cv=none; d=google.com; s=arc-20160816; b=UTwHY9v1pOio3eEvuSXPLZJhdu/nKawrT8ACblKddTZ4lZOvYFT+WXPPEPvEZEhU4O vGa9vYiYQyxM4tEb8E8z+vzZwzesoQcKpSNCsoN2Fs0Rup0cT1bUT9WRMbilYJKa3lHt 9AxOgO2wa7kdtWmUvB+hlU9P+CLSus0Vgko2fJCDirwomZphFPJPs3aqO0wdt+4dipgI VGmj7WxGyXbE5rtspUHLAzoDkT+38dYwalEcq278AqeMAIDPSZlRbSyI9wujrCCZ5qVO Ao8GTfGpOJx6nF6ZwUJRBQuP/M7dMxU/oReXcNC5s/TNaqT0QwEHmrg8DsazelSeVA3V 2ECA== 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 :in-reply-to:references:mime-version:dkim-signature; bh=rTVQwNdpEANBFFxnKdTYMSvJa37ECLsEqk9sL0w2aCY=; b=cXkDEb31AtHP0r5FPS+Kb/SKnS/mdkzeLGAk0BW7HYuXHMMugdPlFhPUyhi6kPJi5b 8760oobEgc15N4/CxypvdV3vxYlr4jR/jiIOtY1IFdis+Pl0834er56xYU1rBHTVsn0x sLI31sZn4EV5YDA6aiymDYIJ1R9hFgZYedACxpBAItIJNhn9ijg88/5yDWik/cikqBHc yERnVCVTUB10WTmvHmp8ljZO10a2bDGplk8/nmjLfocfJxDLqj7froS5C6n7iY5TFPRd GK6JYysH40LRzt3xaKcOj5nXDU+0KUSqAprttYmFR0imgG9nwzCVLNrQw/7YDUT0lDgJ YO0Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b=NHX+A4Hn; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h76si6143186pfe.76.2019.06.22.11.04.05; Sat, 22 Jun 2019 11:04:23 -0700 (PDT) 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=@linux-foundation.org header.s=google header.b=NHX+A4Hn; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726445AbfFVSDJ (ORCPT + 99 others); Sat, 22 Jun 2019 14:03:09 -0400 Received: from mail-lf1-f67.google.com ([209.85.167.67]:32982 "EHLO mail-lf1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726286AbfFVSDI (ORCPT ); Sat, 22 Jun 2019 14:03:08 -0400 Received: by mail-lf1-f67.google.com with SMTP id y17so7228417lfe.0 for ; Sat, 22 Jun 2019 11:03:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=rTVQwNdpEANBFFxnKdTYMSvJa37ECLsEqk9sL0w2aCY=; b=NHX+A4Hn+9k1GJ8KSdLWDJGit6XGMQmGE4DEU3fZsyRFWfBpw3wMmna3jspZ8npHAG uKBQSW6kfbmK1saH4HAnCB+CK4PhAc0azGjSfqk5NUcxI70V/w92Nb9Dpol9ZFldVFig uzoE3MUGDKRzt4OKUC0byx12pDyJL1JGvGwcI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=rTVQwNdpEANBFFxnKdTYMSvJa37ECLsEqk9sL0w2aCY=; b=LI1g+YoWyb//1IpmmT6GQpydyFNKnNvwelUHZUYUAWKt5p1aLzLE5flErxEgwcKdWZ d56aHgSQ4NUcxAu3WjTyig7Unu5YKaiD+VojCoeMckBKQnSxPsgeu7oOeltXawdwTdfp pmIkjlBZ35wd51kV9fWIDGPs3RxgjYx/IesmOIzLpi5YC7JkVRcBFOmvAJ1xUOnzLcUp Xn1ac8SxiRg4bf7bR7GyQEuayaGHqjutlEKDne9hRWGBTn6egVFcfGOQxWLlKnBWcJeO inWQ6a1PH1lJOkexD73p1t5iWbYsj2aI41wHclXSxrYZx7DqE1KgKlvfAz/suJ8N6A3K CWDg== X-Gm-Message-State: APjAAAVOq/X2swiLAEu2SQKIshRbtJGqHcKiuFPRDqajo1jMGuW+NjmV 36HcbvNzcPKoHw7/pk/5zm1yZ3/+T3U= X-Received: by 2002:a19:7607:: with SMTP id c7mr23415847lff.28.1561226585587; Sat, 22 Jun 2019 11:03:05 -0700 (PDT) Received: from mail-lj1-f176.google.com (mail-lj1-f176.google.com. [209.85.208.176]) by smtp.gmail.com with ESMTPSA id p5sm935792ljb.91.2019.06.22.11.03.04 for (version=TLS1_3 cipher=AEAD-AES128-GCM-SHA256 bits=128/128); Sat, 22 Jun 2019 11:03:04 -0700 (PDT) Received: by mail-lj1-f176.google.com with SMTP id i21so8820765ljj.3 for ; Sat, 22 Jun 2019 11:03:04 -0700 (PDT) X-Received: by 2002:a2e:9a58:: with SMTP id k24mr30871577ljj.165.1561226584112; Sat, 22 Jun 2019 11:03:04 -0700 (PDT) MIME-Version: 1.0 References: <20190620022008.19172-1-peterx@redhat.com> <20190620022008.19172-3-peterx@redhat.com> In-Reply-To: <20190620022008.19172-3-peterx@redhat.com> From: Linus Torvalds Date: Sat, 22 Jun 2019 11:02:48 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v5 02/25] mm: userfault: return VM_FAULT_RETRY on signals To: Peter Xu Cc: Linux-MM , Linux List Kernel Mailing , David Hildenbrand , Hugh Dickins , Maya Gokhale , Jerome Glisse , Pavel Emelyanov , Johannes Weiner , Martin Cracauer , Denis Plotnikov , Shaohua Li , Andrea Arcangeli , Mike Kravetz , Marty McFadden , Mike Rapoport , Mel Gorman , "Kirill A . Shutemov" , "Dr . David Alan Gilbert" 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 So I still think this all *may* ok, but at a minimum some of the comments are misleading, and we need more docs on what happens with normal signals. I'm picking on just the first one I noticed, but I think there were other architectures with this too: On Wed, Jun 19, 2019 at 7:20 PM Peter Xu wrote: > > diff --git a/arch/arc/mm/fault.c b/arch/arc/mm/fault.c > index 6836095251ed..3517820aea07 100644 > --- a/arch/arc/mm/fault.c > +++ b/arch/arc/mm/fault.c > @@ -139,17 +139,14 @@ void do_page_fault(unsigned long address, struct pt_regs *regs) > */ > fault = handle_mm_fault(vma, address, flags); > > - if (fatal_signal_pending(current)) { > - > + if (unlikely((fault & VM_FAULT_RETRY) && signal_pending(current))) { > + if (fatal_signal_pending(current) && !user_mode(regs)) > + goto no_context; > /* > * if fault retry, mmap_sem already relinquished by core mm > * so OK to return to user mode (with signal handled first) > */ > - if (fault & VM_FAULT_RETRY) { > - if (!user_mode(regs)) > - goto no_context; > - return; > - } > + return; > } So note how the end result of this is: (a) if a fatal signal is pending, and we're returning to kernel mode, we do the exception handling (b) otherwise, if *any* signal is pending, we'll just return and retry the page fault I have nothing against (a), and (b) is likely also ok, but it's worth noting that (b) happens for kernel returns too. But the comment talks about returning to user mode. Is it ok to return to kernel mode when signals are pending? The signal won't be handled, and we'll just retry the access. Will we possibly keep retrying forever? When we take the fault again, we'll set the FAULT_FLAG_ALLOW_RETRY again, so any fault handler that says "if it allows retry, and signals are pending, just return" would keep never making any progress, and we'd be stuck taking page faults in kernel mode forever. So I think the x86 code sequence is the much safer and more correct one, because it will actually retry once, and set FAULT_FLAG_TRIED (and it will clear the "FAULT_FLAG_ALLOW_RETRY" flag - but you'll remove that clearing later in the series). > diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c > index 46df4c6aae46..dcd7c1393be3 100644 > --- a/arch/x86/mm/fault.c > +++ b/arch/x86/mm/fault.c > @@ -1463,16 +1463,20 @@ void do_user_addr_fault(struct pt_regs *regs, > * that we made any progress. Handle this case first. > */ > if (unlikely(fault & VM_FAULT_RETRY)) { > + bool is_user = flags & FAULT_FLAG_USER; > + > /* Retry at most once */ > if (flags & FAULT_FLAG_ALLOW_RETRY) { > flags &= ~FAULT_FLAG_ALLOW_RETRY; > flags |= FAULT_FLAG_TRIED; > + if (is_user && signal_pending(tsk)) > + return; > if (!fatal_signal_pending(tsk)) > goto retry; > } > > /* User mode? Just return to handle the fatal exception */ > - if (flags & FAULT_FLAG_USER) > + if (is_user) > return; > > /* Not returning to user mode? Handle exceptions or die: */ However, I think the real issue is that it just needs documentation that a fault handler must not react to signal_pending() as part of the fault handling itself (ie the VM_FAULT_RETRY can not be *because* of a non-fatal signal), and there needs to be some guarantee of forward progress. At that point the "infinite page faults in kernel mode due to pending signals" issue goes away. But it's not obvious in this patch, at least. Linus