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.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT autolearn=ham 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 1C7F6C4360C for ; Thu, 26 Sep 2019 09:41:36 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id D2B0C222C3 for ; Thu, 26 Sep 2019 09:41:35 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D2B0C222C3 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 6DB208E0006; Thu, 26 Sep 2019 05:41:35 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 665448E0005; Thu, 26 Sep 2019 05:41:35 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 504AF8E0006; Thu, 26 Sep 2019 05:41:35 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 29C328E0005 for ; Thu, 26 Sep 2019 05:41:35 -0400 (EDT) Received: from smtpin02.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with SMTP id D341729227 for ; Thu, 26 Sep 2019 09:41:34 +0000 (UTC) X-FDA: 75976579308.02.foot06_8225b3cc81b0e X-HE-Tag: foot06_8225b3cc81b0e X-Filterd-Recvd-Size: 6606 Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by imf01.hostedemail.com (Postfix) with ESMTP for ; Thu, 26 Sep 2019 09:41:34 +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 7C394C05683F for ; Thu, 26 Sep 2019 09:41:33 +0000 (UTC) Received: by mail-pl1-f200.google.com with SMTP id m8so1164252plt.14 for ; Thu, 26 Sep 2019 02:41:33 -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=N4oZOlVdiq1iUNu2ipKdKrBjjBpOUecRmSvPVqDDXZc=; b=csTBdIeuc8BK6UXWcpclyohD5cVf284wKOS0o3b1BwyO/0LXWSwjK2ZRLvG8QrVLQn EIHEzkUTkCdorco5HTuS5Z0eH/Gq9hI50wx+T93hY7lqf1WvMYtGsta9y/qSL+cA+sGk yeOymtSXCvEUS3RGPsfNqbm9g0gF4sdbhavNyoIJ7aoQL53xqOTCcbWdHKqAxlTFhU9o mdKlUrnJCftXYf/5B+h6rwXAcml1DAOmTo8LVbHRDdkYRNeW5XmEFRckE4r9hN9/4/o+ udtIfgeXKp+EMRDGxC9di5Kw9Vz7BsRe+IbId10eOdH4wzKQ6WXG6Ss6oZ7NTUd/9MZQ Qo8g== X-Gm-Message-State: APjAAAX8wQ7B1VQ95ZR82NTuh8OKgl4bFv4qvBNVfBv9wjIccqT1QZpk aXeRnonjGu2OIr5k6kj06EY9lK0PD4O5pZNhIWdJbeULEJDYj1MdtcXgv3o4bJ0iMZmxgFWjEAU pjP6r+9wquWk= X-Received: by 2002:a63:f74a:: with SMTP id f10mr2441667pgk.171.1569490892245; Thu, 26 Sep 2019 02:41:32 -0700 (PDT) X-Google-Smtp-Source: APXvYqzXg+JR19ww+nQnL8fkRXYx+C2hv4fDrwyyYRZ7ETfndG7uYUVVmTKADTP0SGN/MJh50aMeMQ== X-Received: by 2002:a63:f74a:: with SMTP id f10mr2441638pgk.171.1569490892002; Thu, 26 Sep 2019 02:41:32 -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.41.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Sep 2019 02:41:31 -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 16/16] mm/userfaultfd: Honor FAULT_FLAG_KILLABLE in fault path Date: Thu, 26 Sep 2019 17:39:04 +0800 Message-Id: <20190926093904.5090-17-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: Userfaultfd fault path was by default killable even if the caller does not have FAULT_FLAG_KILLABLE. That makes sense before in that when with gup we don't have FAULT_FLAG_KILLABLE properly set before. Now after previous patch we've got FAULT_FLAG_KILLABLE applied even for gup code so it should also make sense to let userfaultfd to honor the FAULT_FLAG_KILLABLE. Because we're unconditionally setting FAULT_FLAG_KILLABLE in gup code right now, this patch should have no functional change. It also cleaned the code a little bit by introducing some helpers. Signed-off-by: Peter Xu --- fs/userfaultfd.c | 36 ++++++++++++++++++++++++++++-------- 1 file changed, 28 insertions(+), 8 deletions(-) diff --git a/fs/userfaultfd.c b/fs/userfaultfd.c index 2b3b48e94ae4..8c5863ccbf0e 100644 --- a/fs/userfaultfd.c +++ b/fs/userfaultfd.c @@ -334,6 +334,30 @@ static inline bool userfaultfd_must_wait(struct user= faultfd_ctx *ctx, return ret; } =20 +/* Should pair with userfaultfd_signal_pending() */ +static inline long userfaultfd_get_blocking_state(unsigned int flags) +{ + if (flags & FAULT_FLAG_INTERRUPTIBLE) + return TASK_INTERRUPTIBLE; + + if (flags & FAULT_FLAG_KILLABLE) + return TASK_KILLABLE; + + return TASK_UNINTERRUPTIBLE; +} + +/* Should pair with userfaultfd_get_blocking_state() */ +static inline bool userfaultfd_signal_pending(unsigned int flags) +{ + if (flags & FAULT_FLAG_INTERRUPTIBLE) + return signal_pending(current); + + if (flags & FAULT_FLAG_KILLABLE) + return fatal_signal_pending(current); + + return false; +} + /* * The locking rules involved in returning VM_FAULT_RETRY depending on * FAULT_FLAG_ALLOW_RETRY, FAULT_FLAG_RETRY_NOWAIT and @@ -355,7 +379,7 @@ vm_fault_t handle_userfault(struct vm_fault *vmf, uns= igned long reason) struct userfaultfd_ctx *ctx; struct userfaultfd_wait_queue uwq; vm_fault_t ret =3D VM_FAULT_SIGBUS; - bool must_wait, return_to_userland; + bool must_wait; long blocking_state; =20 /* @@ -462,9 +486,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_INTERRUPTIBLE; - blocking_state =3D return_to_userland ? TASK_INTERRUPTIBLE : - TASK_KILLABLE; + blocking_state =3D userfaultfd_get_blocking_state(vmf->flags); =20 spin_lock_irq(&ctx->fault_pending_wqh.lock); /* @@ -490,8 +512,7 @@ vm_fault_t handle_userfault(struct vm_fault *vmf, uns= igned long reason) up_read(&mm->mmap_sem); =20 if (likely(must_wait && !READ_ONCE(ctx->released) && - (return_to_userland ? !signal_pending(current) : - !fatal_signal_pending(current)))) { + userfaultfd_signal_pending(vmf->flags))) { wake_up_poll(&ctx->fd_wqh, EPOLLIN); schedule(); ret |=3D VM_FAULT_MAJOR; @@ -513,8 +534,7 @@ vm_fault_t handle_userfault(struct vm_fault *vmf, uns= igned long reason) set_current_state(blocking_state); if (READ_ONCE(uwq.waken) || READ_ONCE(ctx->released) || - (return_to_userland ? signal_pending(current) : - fatal_signal_pending(current))) + userfaultfd_signal_pending(vmf->flags)) break; schedule(); } --=20 2.21.0