Received: by 2002:a25:824b:0:0:0:0:0 with SMTP id d11csp1787236ybn; Thu, 26 Sep 2019 02:09:24 -0700 (PDT) X-Google-Smtp-Source: APXvYqwgpgDfNEsfAdiC5E7GfH3N32isOWmFm9bVHKR8TuC1OAtOfKOsofyjiIjAAB+M4HG2qQQd X-Received: by 2002:a17:906:f6d1:: with SMTP id jo17mr2154584ejb.62.1569488964009; Thu, 26 Sep 2019 02:09:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1569488964; cv=none; d=google.com; s=arc-20160816; b=CzL2Y9uk3uGriqNu9HOI2qPeEpfCkAQTso9/hInOe0L6+lTG9lhk/PRpzatvv2WvIZ FysKZzcWsdEbOG05iBWMEbfZ2TLEmKCQEux+GHMEL74on5f3+ldRNN0L5EjZofG/Ub2s rB/vQFbxVkLrWrhCs8BKfLN/DBv0DI8BiVq1HlFzmlTC1gIJn2mm6BD6KHOauzqeeGaq gQX91hWqq1eo1Hh77ns+gpfhwQm7bJMhrJAKGgga4JRz/rtfhmnxDDmxHgp3cFzzz0Kc H7mlWQcFP/yhs08Dq0cXYk/4pehE5d/ZliLa6zyYCmizchqVypU7ngT2EVjDIKwb0m39 5uFQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=MVVdJVVftHCK7lBNfTgeBJYp8/OUkMMp5X/iUBYMtxE=; b=TsfLAWjKNIIvz010S3ngKtQgM5gSzyBH1y7g8SfCYWJmmN4azJ8gywxeZ9pFJp1FCU oJnrH6tgBJIvrxu5Ffo6qpNSuJA4G4K3Ufi2fxdkWsZaU8HXZOWuPl1LuO0vz2bYIzQ5 N5mtSDYnfx2+O4U/e8sFxcYsR0xUUBlGVIgfvYKuDqiCKghDuz8yk14csOogAs3csdn6 mhna3mZjJCQC9/uTzek4Nl8sZwX45dL88Jy4KVZXBIjnMiOIULUbPoM6dpMgAMxijMqR VbkFKnOeWuCHNSU+rgt/2RgPptJlwwjt4uw6mRwtKWvV+pVdObTLgCuwpytnLLx1BkP3 V0YQ== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (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 h14si901679edb.425.2019.09.26.02.09.00; Thu, 26 Sep 2019 02:09: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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2411586AbfIYDqo (ORCPT + 99 others); Tue, 24 Sep 2019 23:46:44 -0400 Received: from mx1.redhat.com ([209.132.183.28]:33392 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2405131AbfIYDqo (ORCPT ); Tue, 24 Sep 2019 23:46:44 -0400 Received: from mail-pg1-f198.google.com (mail-pg1-f198.google.com [209.85.215.198]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 894D786662 for ; Wed, 25 Sep 2019 03:46:43 +0000 (UTC) Received: by mail-pg1-f198.google.com with SMTP id 6so2710579pgi.10 for ; Tue, 24 Sep 2019 20:46:43 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=MVVdJVVftHCK7lBNfTgeBJYp8/OUkMMp5X/iUBYMtxE=; b=AYyu1zsd+7VBgYbVTOCcMpr7bU38GTGo7ks/QDRQUEp7KSereg9uFJMLiTko9Ovida dcuDlTMTBYlq9hsC9wgLhcpLa1h80e+NtSo3bTVcykBIWitlWzIU1cs+AjiApT4XdJCl N7+QjkdHNE7Ugu2jQV9DfJRw1Rzw8KfarVHVKW9Ww4SFRfLkuy3U1OtO7MjDrq5I4K0A CAJ9DT2E8Md6bDtIquBaXKEnHRItbFaEhidiBxsvgV8tL4DFszn8ySRjXhyoHYVNlWXk 3ctS/1FccsivuKMSWM1VZqnBhX4bEBRqgy7EzP/tu5fJM2OKgqoH4u1lExoozrYZhpx2 RKLQ== X-Gm-Message-State: APjAAAXgSaHz3B+S2xWWSX1jkcuwcnkzShmYoZiRvyQmE70hG+3fDeqT OQcL0s6uxlwdO0hwyaf6z/nshmCKMr0zjmChd22yGTpQUdMU/H5CYB0+nfOuHTpmGpKXxGkTgRM KqLExL5qCes5DP0FR96mrx/j4 X-Received: by 2002:a63:2744:: with SMTP id n65mr6586799pgn.277.1569383202805; Tue, 24 Sep 2019 20:46:42 -0700 (PDT) X-Received: by 2002:a63:2744:: with SMTP id n65mr6586777pgn.277.1569383202521; Tue, 24 Sep 2019 20:46:42 -0700 (PDT) Received: from xz-x1 ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id g5sm7399135pgd.82.2019.09.24.20.46.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Sep 2019 20:46:41 -0700 (PDT) Date: Wed, 25 Sep 2019 11:46:27 +0800 From: Peter Xu To: Matthew Wilcox Cc: Linus Torvalds , Linux-MM , Linux Kernel Mailing List , David Hildenbrand , Hugh Dickins , Maya Gokhale , Jerome Glisse , Pavel Emelyanov , Johannes Weiner , Martin Cracauer , Marty McFadden , Shaohua Li , Andrea Arcangeli , Mike Kravetz , Denis Plotnikov , Mike Rapoport , Mel Gorman , "Kirill A . Shutemov" , "Dr . David Alan Gilbert" Subject: Re: [PATCH v4 05/10] mm: Return faster for non-fatal signals in user mode faults Message-ID: <20190925034627.GJ28074@xz-x1> References: <20190923042523.10027-1-peterx@redhat.com> <20190923042523.10027-6-peterx@redhat.com> <20190924024721.GD28074@xz-x1> <20190924025447.GE1855@bombadil.infradead.org> <20190924031908.GF28074@xz-x1> <20190924154518.GG1855@bombadil.infradead.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20190924154518.GG1855@bombadil.infradead.org> User-Agent: Mutt/1.11.4 (2019-03-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Sep 24, 2019 at 08:45:18AM -0700, Matthew Wilcox wrote: > On Tue, Sep 24, 2019 at 11:19:08AM +0800, Peter Xu wrote: > > On Mon, Sep 23, 2019 at 07:54:47PM -0700, Matthew Wilcox wrote: > > > On Tue, Sep 24, 2019 at 10:47:21AM +0800, Peter Xu wrote: > > > > On Mon, Sep 23, 2019 at 11:03:49AM -0700, Linus Torvalds wrote: > > > > > On Sun, Sep 22, 2019 at 9:26 PM Peter Xu wrote: > > > > > > > > > > > > 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. > > > > > > > > > > So I really wish saome other vm person would also review these things, > > > > > but looking over this series once more, this is the patch I probably > > > > > like the least. > > > > > > > > > > And the reason I like it the least is that I have a hard time > > > > > explaining to myself what the code does and why, and why it's so full > > > > > of this pattern: > > > > > > > > > > > - if ((fault & VM_FAULT_RETRY) && fatal_signal_pending(current)) > > > > > > + if ((fault & VM_FAULT_RETRY) && > > > > > > + fault_should_check_signal(user_mode(regs))) > > > > > > return; > > > > > > > > > > which isn't all that pretty. > > > > > > > > > > Why isn't this just > > > > > > > > > > static bool fault_signal_pending(unsigned int fault_flags, struct > > > > > pt_regs *regs) > > > > > { > > > > > return (fault_flags & VM_FAULT_RETRY) && > > > > > (fatal_signal_pending(current) || > > > > > (user_mode(regs) && signal_pending(current))); > > > > > } > > > > > > > > > > and then most of the users would be something like > > > > > > > > > > if (fault_signal_pending(fault, regs)) > > > > > return; > > > > > > > > > > and the exceptions could do their own thing. > > > > > > > > > > Now the code is prettier and more understandable, I feel. > > > > > > > > > > And if something doesn't follow this pattern, maybe it either _should_ > > > > > follow that pattern or it should just not use the helper but explain > > > > > why it has an unusual pattern. > > > > > > > +++ b/arch/alpha/mm/fault.c > > > > @@ -150,7 +150,7 @@ do_page_fault(unsigned long address, unsigned long mmcsr, > > > > the fault. */ > > > > fault = handle_mm_fault(vma, address, flags); > > > > > > > > - if ((fault & VM_FAULT_RETRY) && fatal_signal_pending(current)) > > > > + if (fault_signal_pending(fault, regs)) > > > > return; > > > > > > > > if (unlikely(fault & VM_FAULT_ERROR)) { > > > > > > > +++ b/arch/arm/mm/fault.c > > > > @@ -301,6 +301,11 @@ do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs) > > > > return 0; > > > > } > > > > > > > > + /* Fast path to handle user mode signals */ > > > > + if ((fault & VM_FAULT_RETRY) && user_mode(regs) && > > > > + signal_pending(current)) > > > > + return 0; > > > > > > But _why_ are they different? This is a good opportunity to make more > > > code the same between architectures. > > > > (Thanks for joining the discussion) > > > > I'd like to do these - my only worry is that I can't really test them > > well simply because I don't have all the hardwares. For now the > > changes are mostly straightforward so I'm relatively confident (not to > > mention the code needs proper reviews too, and of course I would > > appreciate much if anyone wants to smoke test it). If I change it in > > a drastic way, I won't be that confident without some tests at least > > on multiple archs (not to mention that even smoke testing across major > > archs will be a huge amount of work...). So IMHO those might be more > > suitable as follow-up for per-arch developers if we can at least reach > > a consensus on the whole idea of this patchset. > > I think the way to do this is to introduce fault_signal_pending(), > converting the architectures to it that match that pattern. Then one > patch per architecture to convert the ones which use a different pattern > to the same pattern. Fair enough. I can start with a fault_signal_pending() only keeps the sigkill handling just like before, then convert all the archs, with the last patch to only touch fault_signal_pending() for non-fatal signals. > > Oh, and while you're looking at the callers of handle_mm_fault(), a > lot of them don't check conditions in the right order. x86, at least, > handles FAULT_RETRY before handling FAULT_ERROR, which is clearly wrong. > > Kirill and I recently discussed it here: > https://lore.kernel.org/linux-mm/20190911152338.gqqgxrmqycodfocb@box/T/ Hmm sure. These sound very reasonable. I must admit that I am not brave enough to continue grow my patchset on my own. The condition I'm facing right now is that I can't really find enough reviewers for this series (Linus helped me quite a lot, I really, really, appreciated that), while it's still growing. I hope the started discussion means that you'll be at least another potential reviewer (oh, should I count Kirill in as well? :) at least to the coming patches for the things mentioned above. Thanks, -- Peter Xu