From patchwork Wed Nov 21 06:20:59 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 10691991 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7977413BF for ; Wed, 21 Nov 2018 06:21:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 68BA62B871 for ; Wed, 21 Nov 2018 06:21:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5BF6E2B888; Wed, 21 Nov 2018 06:21:23 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D18FC2B862 for ; Wed, 21 Nov 2018 06:21:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CD6E86B2483; Wed, 21 Nov 2018 01:21:21 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id C86AE6B2484; Wed, 21 Nov 2018 01:21:21 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B4EF96B2485; Wed, 21 Nov 2018 01:21:21 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-qk1-f197.google.com (mail-qk1-f197.google.com [209.85.222.197]) by kanga.kvack.org (Postfix) with ESMTP id 86DCC6B2483 for ; Wed, 21 Nov 2018 01:21:21 -0500 (EST) Received: by mail-qk1-f197.google.com with SMTP id x125so5639221qka.17 for ; Tue, 20 Nov 2018 22:21:21 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id; bh=P5yGr5N67VLN0q7lBDM7+CdXDq+zGxpvLiFHJptrB4s=; b=e9EWrBjrK2/ygbRmCtU7jMW5JVXwhfC77TUaJ5ldjhc61Tnb7ZBHZ9KwsPnMN67z58 pk+pWSUdGykctOwVhcKqbafAZmHO91zFh/o+1JrpJ1aJ0DEd2kvycdo/OCkGewC8RV8O WFfT8modicA2GjSVynhZ+oTv4LRK/qWvAGs0L2Qui9a26oY8NhlyTz+SdNM1EreohCt2 7/+g7D+cRwwWex2qRH2aLsuCC9SNY1clyAEEnu/ACWGLatn9ZUyG+uQyrPvoxuPJPEKn 0XhvR/WM83/eDKzBzSxYJldoy56K45dDrH3dyRuuOCOkZH0N+B//Zy6DkuVeJ2SfKI9C D8Rw== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of peterx@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com X-Gm-Message-State: AA+aEWbevvVICVh0p3sWouRh/cpOlLs/2qPI2Qi5NHJCIG9ifuE/autM G8oiz7kW7dKXZzr56W5y5YIQS6N7jjUGIPq3zEsw0u3CYJCWUhRc6WcPkc0dsxaSzOQ81opXdd4 NdhtRz9xs1dgchkqgaeTEIDsn6vigpab4mBt3ek5AFFYt5NE6f+7urr4chtlsSvRypw== X-Received: by 2002:a37:58c6:: with SMTP id m189mr4342639qkb.161.1542781281250; Tue, 20 Nov 2018 22:21:21 -0800 (PST) X-Google-Smtp-Source: AFSGD/XxSghyJI8T5aAyodQN/lnPznmK20pg0OaDgiIxmz2bc/hqqBtMngDjgXEXO5cbMckiFWVr X-Received: by 2002:a37:58c6:: with SMTP id m189mr4342604qkb.161.1542781280443; Tue, 20 Nov 2018 22:21:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542781280; cv=none; d=google.com; s=arc-20160816; b=Hjdrgchi6gcG24MvNrNAuUVNWmEYXbGJNr6sCldIPnV8+Pg1HJBiY83f0IQGVHlulb TT9mSZr2sUQC8MeyubD8WqKDkwQHQYrtTWP5uGt3dQeb4QCi9bIkDHS0b2d60FWVCUEh NUIj6gDxp/jKvR/5CK3FbqVxppRL0LQdcN8ZBn0KBlfddcNmv3Zn1slaCC5LwLhw9ZG9 mDTAYxXlnoCnPGmUulYAZMLXv6/cCh43SjCpppTl6mOstLyxHMkBO3PWMPVzVLwwD+mE 12vP0gcz9m577BjTDEnbTB0CBod8Gq/pRl7ux3RPP6JQdhnCbqabAkcldbw2VizcPYpJ aQtg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=message-id:date:subject:cc:to:from; bh=P5yGr5N67VLN0q7lBDM7+CdXDq+zGxpvLiFHJptrB4s=; b=ELGVtQ8s87RBSRKNdyMpJ5YZeWyb0t5hJU6vBCYGcgTSGAtPje94BwAm2tviYCJzx2 B8cDWCEgWLDkUDH3sjJcdSlPF9/BXxXJUhOU86Z3KjgZnaePlXD0OsnalzYCnCkdwPOi gIK/5lXJF5nIexHawp3itV/XgVxyA+Gw3dI+4rXAJU+tToO+yns1aRHRAmO5um8o3iHg cQREFgM8k7CrH/y9+vmSC55pmHcHDZN4FCCVGQNtxrUcwDi35/NKXrURLSn/wGEL0e4g aHeBGb5J9lvxThLvPqGnyeMoz+EUW2CcLuviZxiE9hOfFLjpIX05eU9gxfctIFFD76kx WBzg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of peterx@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from mx1.redhat.com (mx1.redhat.com. [209.132.183.28]) by mx.google.com with ESMTPS id v1si835080qtc.391.2018.11.20.22.21.20 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 20 Nov 2018 22:21:20 -0800 (PST) Received-SPF: pass (google.com: domain of peterx@redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; Authentication-Results: mx.google.com; spf=pass (google.com: domain of peterx@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 467DF356D3; Wed, 21 Nov 2018 06:21:19 +0000 (UTC) Received: from xz-x1.nay.redhat.com (dhcp-14-128.nay.redhat.com [10.66.14.128]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7980D600C5; Wed, 21 Nov 2018 06:21:05 +0000 (UTC) From: Peter Xu To: linux-kernel@vger.kernel.org Cc: Keith Busch , Jerome Glisse , peterx@redhat.com, Dan Williams , linux-mm@kvack.org, Matthew Wilcox , Al Viro , Andrea Arcangeli , Huang Ying , Mike Kravetz , Mike Rapoport , Linus Torvalds , "Michael S. Tsirkin" , "Kirill A . Shutemov" , Michal Hocko , Vlastimil Babka , Pavel Tatashin , Andrew Morton Subject: [PATCH RFC v3 0/4] mm: some enhancements to the page fault mechanism Date: Wed, 21 Nov 2018 14:20:59 +0800 Message-Id: <20181121062103.18835-1-peterx@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Wed, 21 Nov 2018 06:21:19 +0000 (UTC) X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP v3: - fix up issues that krobot reported, rebase This is an RFC series as cleanup and enhancements to current page fault logic. The whole idea comes from the discussion between Andrea and Linus on the bug reported by syzbot here: https://lkml.org/lkml/2017/11/2/833 Basically it does two things: (a) Allows the page fault logic to be more interactive on not only SIGKILL, but also the rest of userspace signals, and, (b) Allows the page fault retry (VM_FAULT_RETRY) to happen for more than once. For (a): with the changes we should be able to react faster when page faults are working in parallel with userspace signals like SIGSTOP and SIGCONT (and more), and with that we can remove the buggy part in userfaultfd and benefit the whole page fault mechanism on faster signal processing to reach the userspace. For (b), we should be able to allow the page fault handler to loop for even more than twice. Some context: for now since we have FAULT_FLAG_ALLOW_RETRY we can allow to retry the page fault once with the same interrupt context, however never more than twice. This can be not only a potential cleanup to remove this assumption since AFAIU the code itself doesn't really have this twice-only limitation (though that should be a protective approach in the past), at the same time it'll greatly simplify future works like userfaultfd write-protect where it's possible to retry for more than twice (please have a look at [1] below for a possible user that might require the page fault to be handled for a third time; if we can remove the retry limitation we can simply drop that patch and those complexity). Some more details on each of the patch (even more in commit messages): Patch 1: A cleanup of existing GUP code to rename the confusing "nonblocking" parameter to "locked" which seems suite more. Patch 2: Complete the page fault faster for non-sigkill signals Patch 3: Remove the limitation to only allow to retry page fault for twice (page fault part) Patch 4: Similar work of patch 3, but for GUP. The series is only lightly tested. Before running more tests, I'd be really glad to see whether there's any feedback first. Looking forward to your comments. Thanks, [1] https://git.kernel.org/pub/scm/linux/kernel/git/andrea/aa.git/commit/?h=userfault&id=b245ecf6cf59156966f3da6e6b674f6695a5ffa5 Peter Xu (4): mm: gup: rename "nonblocking" to "locked" where proper mm: userfault: return VM_FAULT_RETRY on signals mm: allow VM_FAULT_RETRY for multiple times mm: gup: allow VM_FAULT_RETRY for multiple times arch/alpha/mm/fault.c | 4 +-- arch/arc/mm/fault.c | 12 ++++---- arch/arm/mm/fault.c | 17 ++++++----- arch/arm64/mm/fault.c | 11 ++----- arch/hexagon/mm/vm_fault.c | 3 +- arch/ia64/mm/fault.c | 3 +- arch/m68k/mm/fault.c | 5 +--- arch/microblaze/mm/fault.c | 3 +- arch/mips/mm/fault.c | 3 +- arch/nds32/mm/fault.c | 7 ++--- arch/nios2/mm/fault.c | 5 +--- arch/openrisc/mm/fault.c | 3 +- arch/parisc/mm/fault.c | 4 +-- arch/powerpc/mm/fault.c | 9 ++---- arch/riscv/mm/fault.c | 9 ++---- arch/s390/mm/fault.c | 14 ++++----- arch/sh/mm/fault.c | 5 +++- arch/sparc/mm/fault_32.c | 4 ++- arch/sparc/mm/fault_64.c | 4 ++- arch/um/kernel/trap.c | 6 ++-- arch/unicore32/mm/fault.c | 10 ++----- arch/x86/mm/fault.c | 13 ++++++-- arch/xtensa/mm/fault.c | 4 ++- fs/userfaultfd.c | 24 --------------- mm/gup.c | 61 +++++++++++++++++++++----------------- mm/hugetlb.c | 8 ++--- 26 files changed, 114 insertions(+), 137 deletions(-)