From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.7 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C89EAC49ED7 for ; Mon, 23 Sep 2019 04:26:14 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 8ACFE20820 for ; Mon, 23 Sep 2019 04:26:14 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8ACFE20820 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 3A6CA6B026C; Mon, 23 Sep 2019 00:26:14 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 37D4A6B026D; Mon, 23 Sep 2019 00:26:14 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 294316B026E; Mon, 23 Sep 2019 00:26:14 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0168.hostedemail.com [216.40.44.168]) by kanga.kvack.org (Postfix) with ESMTP id 07F8A6B026C for ; Mon, 23 Sep 2019 00:26:14 -0400 (EDT) Received: from smtpin21.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with SMTP id A4D1A8243768 for ; Mon, 23 Sep 2019 04:26:13 +0000 (UTC) X-FDA: 75964898226.21.tooth57_706aa80b9651d X-HE-Tag: tooth57_706aa80b9651d X-Filterd-Recvd-Size: 7734 Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by imf17.hostedemail.com (Postfix) with ESMTP for ; Mon, 23 Sep 2019 04:26:12 +0000 (UTC) Received: from mail-pl1-f199.google.com (mail-pl1-f199.google.com [209.85.214.199]) (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 7A3ACC0546FC for ; Mon, 23 Sep 2019 04:26:11 +0000 (UTC) Received: by mail-pl1-f199.google.com with SMTP id x5so7976286pln.5 for ; Sun, 22 Sep 2019 21:26:11 -0700 (PDT) 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=GXIovqwqm63wtxzzyeIbAQrpQWpcAdR9JxWJf3/Rl1Y=; b=OBgzJ4QmUtT80IxDvgWldZyszJAS2Lea9qoq4Je5S0YpMXq8nt4iNBrKrvgBcm5tG+ nULDiwTj1dm+5SWuR+k57U874oOdwfeUdUwlckxQiPb05WYcPJ6+t9GOddunWGRy2fcq O/v03mzw8N7VrEA4Ozt0R+kVfyiL5yZb3yv5B7Y/sEewhnQxWWpYAAEb+8+q8JZaD5d9 qVSqQt0gfQVCpM2d3XVIDpnKlcGRd/j3VC8kAI2zOAASpUo1Se98qktv1/0S5h3LgaDO RzqarGMtVqn5xRfEA1hF3aMb92jVZA9yHAGi/Rov4X+L/fRLBPFAoKxLU3B5z1Ub/y59 KHCg== X-Gm-Message-State: APjAAAVQa1jeUoso1dY/UQgEDZiyRNq/11vt7XK6nJqR+Lu2TCF0pNAV bC0rLY4K3H7sk9FnhvGa5HTpmTvdFgV9VljFZ8LUB5WRMufmOrAOfI+YOl+pm5kk1v0ScjNXsaN FmsgtHs9p/1E= X-Received: by 2002:aa7:8acf:: with SMTP id b15mr24586112pfd.191.1569212770634; Sun, 22 Sep 2019 21:26:10 -0700 (PDT) X-Google-Smtp-Source: APXvYqx6iUJWUgZ29uQGs7aHG+ZKt7JXzV+Gz1NXrFI6pYw3jfFgBbkb+Z15GkLEoauMRbp2DWsMsw== X-Received: by 2002:aa7:8acf:: with SMTP id b15mr24586091pfd.191.1569212770425; Sun, 22 Sep 2019 21:26:10 -0700 (PDT) Received: from xz-x1.redhat.com ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id x20sm11781867pfp.120.2019.09.22.21.26.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 22 Sep 2019 21:26:09 -0700 (PDT) From: Peter Xu To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: David Hildenbrand , Hugh Dickins , Maya Gokhale , Jerome Glisse , Pavel Emelyanov , Johannes Weiner , peterx@redhat.com, Martin Cracauer , Marty McFadden , Shaohua Li , Andrea Arcangeli , Mike Kravetz , Denis Plotnikov , Mike Rapoport , Linus Torvalds , Mel Gorman , "Kirill A . Shutemov" , "Dr . David Alan Gilbert" Subject: [PATCH v4 04/10] mm: Introduce FAULT_FLAG_INTERRUPTIBLE Date: Mon, 23 Sep 2019 12:25:17 +0800 Message-Id: <20190923042523.10027-5-peterx@redhat.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190923042523.10027-1-peterx@redhat.com> References: <20190923042523.10027-1-peterx@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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: handle_userfaultfd() is currently the only one place in the kernel page fault procedures that can respond to non-fatal userspace signals. It was trying to detect such an allowance by checking against USER & KILLABLE flags, which was "un-official". In this patch, we introduced a new flag (FAULT_FLAG_INTERRUPTIBLE) to show that the fault handler allows the fault procedure to respond even to non-fatal signals. Meanwhile, add this new flag to the default fault flags so that all the page fault handlers can benefit from the new flag. With that, replacing the userfault check to this one. Since the line is getting even longer, clean up the fault flags a bit too to ease TTY users. Although we've got a new flag and applied it, we shouldn't have any functional change with this patch so far. Suggested-by: Linus Torvalds Reviewed-by: David Hildenbrand Signed-off-by: Peter Xu --- fs/userfaultfd.c | 4 +--- include/linux/mm.h | 39 ++++++++++++++++++++++++++++----------- 2 files changed, 29 insertions(+), 14 deletions(-) diff --git a/fs/userfaultfd.c b/fs/userfaultfd.c index fe6d804a38dc..3c55ee64bcb1 100644 --- a/fs/userfaultfd.c +++ b/fs/userfaultfd.c @@ -462,9 +462,7 @@ vm_fault_t handle_userfault(struct vm_fault *vmf, uns= igned long reason) uwq.ctx =3D ctx; uwq.waken =3D false; =20 - return_to_userland =3D - (vmf->flags & (FAULT_FLAG_USER|FAULT_FLAG_KILLABLE)) =3D=3D - (FAULT_FLAG_USER|FAULT_FLAG_KILLABLE); + return_to_userland =3D vmf->flags & FAULT_FLAG_INTERRUPTIBLE; blocking_state =3D return_to_userland ? TASK_INTERRUPTIBLE : TASK_KILLABLE; =20 diff --git a/include/linux/mm.h b/include/linux/mm.h index 57fb5c535f8e..53ec7abb8472 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -383,22 +383,38 @@ extern unsigned int kobjsize(const void *objp); */ extern pgprot_t protection_map[16]; =20 -#define FAULT_FLAG_WRITE 0x01 /* Fault was a write access */ -#define FAULT_FLAG_MKWRITE 0x02 /* Fault was mkwrite of existing pte */ -#define FAULT_FLAG_ALLOW_RETRY 0x04 /* Retry fault if blocking */ -#define FAULT_FLAG_RETRY_NOWAIT 0x08 /* Don't drop mmap_sem and wait whe= n retrying */ -#define FAULT_FLAG_KILLABLE 0x10 /* The fault task is in SIGKILL killabl= e region */ -#define FAULT_FLAG_TRIED 0x20 /* Second try */ -#define FAULT_FLAG_USER 0x40 /* The fault originated in userspace */ -#define FAULT_FLAG_REMOTE 0x80 /* faulting for non current tsk/mm */ -#define FAULT_FLAG_INSTRUCTION 0x100 /* The fault was during an instruc= tion fetch */ +/** + * Fault flag definitions. + * + * @FAULT_FLAG_WRITE: Fault was a write fault. + * @FAULT_FLAG_MKWRITE: Fault was mkwrite of existing PTE. + * @FAULT_FLAG_ALLOW_RETRY: Allow to retry the fault if blocked. + * @FAULT_FLAG_RETRY_NOWAIT: Don't drop mmap_sem and wait when retrying. + * @FAULT_FLAG_KILLABLE: The fault task is in SIGKILL killable region. + * @FAULT_FLAG_TRIED: The fault has been tried once. + * @FAULT_FLAG_USER: The fault originated in userspace. + * @FAULT_FLAG_REMOTE: The fault is not for current task/mm. + * @FAULT_FLAG_INSTRUCTION: The fault was during an instruction fetch. + * @FAULT_FLAG_INTERRUPTIBLE: The fault can be interrupted by non-fatal = signals. + */ +#define FAULT_FLAG_WRITE 0x01 +#define FAULT_FLAG_MKWRITE 0x02 +#define FAULT_FLAG_ALLOW_RETRY 0x04 +#define FAULT_FLAG_RETRY_NOWAIT 0x08 +#define FAULT_FLAG_KILLABLE 0x10 +#define FAULT_FLAG_TRIED 0x20 +#define FAULT_FLAG_USER 0x40 +#define FAULT_FLAG_REMOTE 0x80 +#define FAULT_FLAG_INSTRUCTION 0x100 +#define FAULT_FLAG_INTERRUPTIBLE 0x200 =20 /* * The default fault flags that should be used by most of the * arch-specific page fault handlers. */ #define FAULT_FLAG_DEFAULT (FAULT_FLAG_ALLOW_RETRY | \ - FAULT_FLAG_KILLABLE) + FAULT_FLAG_KILLABLE | \ + FAULT_FLAG_INTERRUPTIBLE) =20 #define FAULT_FLAG_TRACE \ { FAULT_FLAG_WRITE, "WRITE" }, \ @@ -409,7 +425,8 @@ extern pgprot_t protection_map[16]; { FAULT_FLAG_TRIED, "TRIED" }, \ { FAULT_FLAG_USER, "USER" }, \ { FAULT_FLAG_REMOTE, "REMOTE" }, \ - { FAULT_FLAG_INSTRUCTION, "INSTRUCTION" } + { FAULT_FLAG_INSTRUCTION, "INSTRUCTION" }, \ + { FAULT_FLAG_INTERRUPTIBLE, "INTERRUPTIBLE" } =20 /* * vm_fault is filled by the the pagefault handler and passed to the vma= 's --=20 2.21.0