From patchwork Wed Nov 7 06:06:39 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 10671871 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 A9E2915A6 for ; Wed, 7 Nov 2018 06:07:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 98BAC28755 for ; Wed, 7 Nov 2018 06:07:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8B6D1289B6; Wed, 7 Nov 2018 06:07:05 +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 E348028755 for ; Wed, 7 Nov 2018 06:07:04 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2A92A6B04B2; Wed, 7 Nov 2018 01:07:03 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 259456B04B3; Wed, 7 Nov 2018 01:07:03 -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 121996B04B4; Wed, 7 Nov 2018 01:07:03 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-qk1-f199.google.com (mail-qk1-f199.google.com [209.85.222.199]) by kanga.kvack.org (Postfix) with ESMTP id DA2C86B04B2 for ; Wed, 7 Nov 2018 01:07:02 -0500 (EST) Received: by mail-qk1-f199.google.com with SMTP id k203so29546978qke.2 for ; Tue, 06 Nov 2018 22:07:02 -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=z9DLjNTD5xfG+tbx031gLHzNtmK4W9cv53MP2KrnP4I=; b=CSHHJZ/Qdz4LHStWmZADUaPGCqO+B43YfyA7zuZ89HrzmhyL/NPwUE2EMKPJDcDwSa ECesHiELDGbANBpiWbE6icvQtHcumlVkk8kc+0xFdr/uX+HNSgzzP16HUY0o2JGIDu33 mwwYc+dCTgyJIL8jnUxyhX+nZDy1FAI6N2PMDc5AaaKx2j7lJUhDMNtCXxoAc15R8gkM kv83zEOdHq+ohYT3s2aY5TqjCXXweaHcpA3bJmd4MF5HRA7uhrebCvb0rOXDzUOtsj1c ZsLFS/W9HvTlRBd50JGFmIo77w7pcMvKjIpsh9rhc1z9o/QpajeP7crMvou6IJmpDesQ Jr1Q== 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: AGRZ1gKEewO8w/SftUC3CLa2yKEDr0eYsqfgS0lknLILwEWAbbsJyc7c p/axasRaQJWGO+cBCfTTtmbDW+Wa9wzr6u9COrAV6WoqJ51svygGjlf/l+7CspmRMAri+DOEEuq b2bk/uln7G+zQDXvV+yN46Mvpe7HRW5J5yhpBzxWB+ZgVf4jCo3xpq46OkKs0eE/Yyg== X-Received: by 2002:a0c:ad16:: with SMTP id u22mr528694qvc.240.1541570822552; Tue, 06 Nov 2018 22:07:02 -0800 (PST) X-Google-Smtp-Source: AJdET5cbaFl2RmhvYqOqfhzlZcDy8vG44uPUGxW5t0QbegM4/pWrpJO61H+UlgkpfcCK9fE3wjmW X-Received: by 2002:a0c:ad16:: with SMTP id u22mr528661qvc.240.1541570821779; Tue, 06 Nov 2018 22:07:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541570821; cv=none; d=google.com; s=arc-20160816; b=sHIp1CsaNl9luDA87oIqpfIscStHL9Q9wvGUhIZ32UeaCz3dPoltP87TY9uzusBFK9 LxvAoN5lBxrcbhdPNy8Alr3zE/w+loqAo8h0Km8zXAuAPlPDKb4ViaD7ByusSh90l/OB X+tK/Wd+QrssaFcZIHkIEnmEDoGmZ9no3hT+wKorUc6mLObvxg8lh4c1HcspmmFsZ7Oo 95lNHXUCv/HCu+/3cUOpAzoyXm1aRb3Lb9kgb4Ku4CZuxryvK4gY9yl+ruVkp44Zilcn BA7TgELhqc3QRofsLy6YLnekWzNhS9WQYHYPiEbTmPpAaEGnmSJzOMIVfsb5TLyyEU+I DZyA== 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=z9DLjNTD5xfG+tbx031gLHzNtmK4W9cv53MP2KrnP4I=; b=Cz2FWo90RI2mANt5cThidUZLKYLm3dRAwNuD28vkFzIM34cxFEuUErymQ/BYRWAmhl 0OtcvkYv/Qy6GEN3/CDLicvfcb5PKVsJbSLujOmRJEJ0oSLeEnyrp/Q1rWcQxYXqyNdj WqLXPpv8ByxT7oOaF6tWbM5ek6F29xAiz09LGUNJddG6U920NPVtfEjbI9x4jfW+xQ1j tr92tbVWPMsvRUL0g2jh3aqUxKhe45WYc3uJWa1yxHPKFI1afLD3aQMNlvWcCUF5D/Oe WR6AHkjhKTQr5Agj497ykjMNFE7tviLUG52P0sd62jyJPgJfw80RFEeqK0meAGCQNtgg pJnQ== 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 k15si2033618qke.86.2018.11.06.22.07.01 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 06 Nov 2018 22:07:01 -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-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7B20B3097043; Wed, 7 Nov 2018 06:07:00 +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 943291057053; Wed, 7 Nov 2018 06:06:47 +0000 (UTC) From: Peter Xu To: linux-kernel@vger.kernel.org Cc: Keith Busch , Linus Torvalds , peterx@redhat.com, Dan Williams , linux-mm@kvack.org, Matthew Wilcox , Al Viro , Andrea Arcangeli , Huang Ying , Mike Kravetz , Mike Rapoport , Jerome Glisse , "Michael S. Tsirkin" , "Kirill A . Shutemov" , Michal Hocko , Vlastimil Babka , Pavel Tatashin , Andrew Morton Subject: [PATCH RFC v2 0/4] mm: some enhancements to the page fault mechanism Date: Wed, 7 Nov 2018 14:06:39 +0800 Message-Id: <20181107060643.10950-1-peterx@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.43]); Wed, 07 Nov 2018 06:07:00 +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 (sorry I got the cc list messed up; am sending another one with no change but only to fix the cc list) 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 more tests, I'd be really glad to see whether there's any feedbacks on these changes, on whether the changes make any sense, or anything important that I may have missed, or any suggestions on how to better test the work, etc... 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(-)