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 403E8C432C2 for ; Thu, 26 Sep 2019 09:41:02 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 070D5222C5 for ; Thu, 26 Sep 2019 09:41:02 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 070D5222C5 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 AFC606B000D; Thu, 26 Sep 2019 05:41:01 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id AAD466B026C; Thu, 26 Sep 2019 05:41:01 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9E7BA6B026D; Thu, 26 Sep 2019 05:41:01 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0050.hostedemail.com [216.40.44.50]) by kanga.kvack.org (Postfix) with ESMTP id 7E2106B000D for ; Thu, 26 Sep 2019 05:41:01 -0400 (EDT) Received: from smtpin01.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with SMTP id 0396C181AC9AE for ; Thu, 26 Sep 2019 09:41:01 +0000 (UTC) X-FDA: 75976577922.01.rail23_7d39a1718e04f X-HE-Tag: rail23_7d39a1718e04f X-Filterd-Recvd-Size: 7764 Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by imf31.hostedemail.com (Postfix) with ESMTP for ; Thu, 26 Sep 2019 09:41:00 +0000 (UTC) Received: from mail-pl1-f200.google.com (mail-pl1-f200.google.com [209.85.214.200]) (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 B2D6489AC6 for ; Thu, 26 Sep 2019 09:40:59 +0000 (UTC) Received: by mail-pl1-f200.google.com with SMTP id k9so1167487pls.13 for ; Thu, 26 Sep 2019 02:40:59 -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=UEirX6W09H+Oy9OrZHOkhdVkpbnjvhUTE+ZWBlFtC7w=; b=YnnJgc7BNGwGNjm6522sTo3AqflxuR0fCyCT1IVq3w/4SFbvSPi1tt3ZuVyn97fWj7 kfve2mPC4aCIbDvW1ZshZP49bEdnixrJsQqueAcIzM3wiRUE2cDPThFT3i4NUevb/d9U AiQr8++9ISNQJg37+Q2ajKz72Cc1h6htQr6M5b659xzeNXOVfgfaPMxmjZSc8TKYjPMF r4L7MmMOXiEKpoFA52iHu4Ou4/e645zFE7n0McjwnWyx72HNaU54++3qiB1v/CYxSsrp I+9k4p+X9MYBukqGEH/v7zLDXJOGQD7DBGGDZTna4A9lX7BAKlCDFdtrQkBcOZs4sk1x 97tg== X-Gm-Message-State: APjAAAVc0ec4HUlb6KnyBwCCvpcXpm6TzNYoECo/WJDUx70aIaQqb5Mj 9qagpgOe238tkrnOyzJ1wcryBVVlQQW+xBWl6wdZkfr/bGXWYAbeDf5pg6KrwBCp9sGJP/DXCjt nvv44OLGPz1w= X-Received: by 2002:a62:2d3:: with SMTP id 202mr2656247pfc.141.1569490858762; Thu, 26 Sep 2019 02:40:58 -0700 (PDT) X-Google-Smtp-Source: APXvYqwx9cpUuoqIPyEG4ywrhXDy3ZMiLq/Jfm7c9EInxtKmK2nYnXyeWPAuexsbI6aD+tXF7a843Q== X-Received: by 2002:a62:2d3:: with SMTP id 202mr2656215pfc.141.1569490858520; Thu, 26 Sep 2019 02:40:58 -0700 (PDT) Received: from xz-x1.redhat.com ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id p68sm3224982pfp.9.2019.09.26.02.40.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Sep 2019 02:40:57 -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 , Matthew Wilcox , Shaohua Li , Marty McFadden , Andrea Arcangeli , Mike Kravetz , Denis Plotnikov , Mike Rapoport , Linus Torvalds , Mel Gorman , "Kirill A . Shutemov" , "Dr . David Alan Gilbert" Subject: [PATCH v5 12/16] mm: Introduce FAULT_FLAG_INTERRUPTIBLE Date: Thu, 26 Sep 2019 17:39:00 +0800 Message-Id: <20190926093904.5090-13-peterx@redhat.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190926093904.5090-1-peterx@redhat.com> References: <20190926093904.5090-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 d8777146bae7..2b3b48e94ae4 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