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.9 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,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 683ACC11D0B for ; Thu, 20 Feb 2020 16:09:03 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 22ABB2465D for ; Thu, 20 Feb 2020 16:09:03 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="Jk95eNhx" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 22ABB2465D 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 97DE06B0003; Thu, 20 Feb 2020 11:09:02 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 92E366B0008; Thu, 20 Feb 2020 11:09:02 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 81D596B000A; Thu, 20 Feb 2020 11:09:02 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0054.hostedemail.com [216.40.44.54]) by kanga.kvack.org (Postfix) with ESMTP id 5D27D6B0003 for ; Thu, 20 Feb 2020 11:09:02 -0500 (EST) Received: from smtpin16.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id D9C601807B55A for ; Thu, 20 Feb 2020 16:09:01 +0000 (UTC) X-FDA: 76510989282.16.pin11_557ac5c3c5203 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin16.hostedemail.com (Postfix) with ESMTP id 06B9F100E9C1D for ; Thu, 20 Feb 2020 16:03:07 +0000 (UTC) X-HE-Tag: pin11_557ac5c3c5203 X-Filterd-Recvd-Size: 7510 Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) by imf35.hostedemail.com (Postfix) with ESMTP for ; Thu, 20 Feb 2020 16:03:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582214587; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=JvJzoPIlr6yAaDSCxmp+qpBa8SX8LjTplurXQDeeCco=; b=Jk95eNhxWQ0pSSC4wghv3vDbKFB/nbpZbW914QXQKza7/BsOwBEiTta12Uw9s8NfTQQz2d JiyvhY++RKVyc7MeoVU1brliWUU87pFqHM/2MFincKQyeORxfh7eImCrYW6ZBLgd6QI4JZ MnBLgIzln6qsVc0AnnvA7K8/xclM2r4= Received: from mail-qt1-f198.google.com (mail-qt1-f198.google.com [209.85.160.198]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-207-S0oluZ5TOtqBRdGEt3sePA-1; Thu, 20 Feb 2020 11:03:03 -0500 Received: by mail-qt1-f198.google.com with SMTP id p12so2891912qtu.6 for ; Thu, 20 Feb 2020 08:03:03 -0800 (PST) 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=lwNlsBs8NIb6Y77atButveT5DrFFM9+Zoa3o5H5cFjw=; b=WZl/88k0UG/vtI8kVPt/u60Me4jWbZk1nB0WAgQCHts1RmUXfwB0bpujbpugSdGBUe W7oJYlgQInb7yrjsMq7wA9+46bfNPf6Wrf4sJ0fsKl0TqSx5nWfYGIMOQE1EEp/VMiZt tgr4lm/INCELHFSG7tJw0+RQjF1kvJlG79OPRJ4ZDzTb6A7Xi/yJWMnjjUZqJ8fPKyQc Rjld3rlv935YajcTRRToBwU/umlgEzf5az3ihHx5rOpUa3XSHg/cY9DqXExYaw9DfRB3 vBNBsmjGDsXyP0lo/MCnse1FtdLL20lkQEaqGkUo7DKS2hznrnH0qrpEgfCnHaVENqPn woqg== X-Gm-Message-State: APjAAAXcDNnNP+2q3s3zyAq1/2oZ7dHk+TADLES1zI196r51FlDnp8Vw STByDrVV0La4k55DPYZPu8u6P+j9LdWthxlq4WCgwq49oLlJMteEn6oPh/SS4ouHlQwmOAoga/T 8FB+CxnHJ+z4= X-Received: by 2002:a37:6343:: with SMTP id x64mr12490175qkb.469.1582214582493; Thu, 20 Feb 2020 08:03:02 -0800 (PST) X-Google-Smtp-Source: APXvYqx2aPDTTJLSGD106eUq72NgEiCCqnnnqxrNnv6B6KzmA2UMTNOcP0AD9i+lrW6IWJ9nODQY9g== X-Received: by 2002:a37:6343:: with SMTP id x64mr12490151qkb.469.1582214582267; Thu, 20 Feb 2020 08:03:02 -0800 (PST) Received: from xz-x1.redhat.com ([104.156.64.75]) by smtp.gmail.com with ESMTPSA id n123sm1857635qke.58.2020.02.20.08.03.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Feb 2020 08:03:01 -0800 (PST) From: Peter Xu To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Peter Xu , Martin Cracauer , Mike Rapoport , Hugh Dickins , Jerome Glisse , "Kirill A . Shutemov" , Matthew Wilcox , Pavel Emelyanov , Brian Geffon , Maya Gokhale , Denis Plotnikov , Andrea Arcangeli , Johannes Weiner , "Dr . David Alan Gilbert" , Linus Torvalds , Mike Kravetz , Marty McFadden , David Hildenbrand , Bobby Powers , Mel Gorman Subject: [PATCH RESEND v6 16/16] mm/userfaultfd: Honor FAULT_FLAG_KILLABLE in fault path Date: Thu, 20 Feb 2020 11:03:00 -0500 Message-Id: <20200220160300.9941-1-peterx@redhat.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200220155353.8676-1-peterx@redhat.com> References: MIME-Version: 1.0 X-MC-Unique: S0oluZ5TOtqBRdGEt3sePA-1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII 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 c076d3295958..703c1c3faa6e 100644 --- a/fs/userfaultfd.c +++ b/fs/userfaultfd.c @@ -334,6 +334,30 @@ static inline bool userfaultfd_must_wait(struct userfa= ultfd_ctx *ctx, =09return ret; } =20 +/* Should pair with userfaultfd_signal_pending() */ +static inline long userfaultfd_get_blocking_state(unsigned int flags) +{ +=09if (flags & FAULT_FLAG_INTERRUPTIBLE) +=09=09return TASK_INTERRUPTIBLE; + +=09if (flags & FAULT_FLAG_KILLABLE) +=09=09return TASK_KILLABLE; + +=09return TASK_UNINTERRUPTIBLE; +} + +/* Should pair with userfaultfd_get_blocking_state() */ +static inline bool userfaultfd_signal_pending(unsigned int flags) +{ +=09if (flags & FAULT_FLAG_INTERRUPTIBLE) +=09=09return signal_pending(current); + +=09if (flags & FAULT_FLAG_KILLABLE) +=09=09return fatal_signal_pending(current); + +=09return 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, unsig= ned long reason) =09struct userfaultfd_ctx *ctx; =09struct userfaultfd_wait_queue uwq; =09vm_fault_t ret =3D VM_FAULT_SIGBUS; -=09bool must_wait, return_to_userland; +=09bool must_wait; =09long blocking_state; =20 =09/* @@ -462,9 +486,7 @@ vm_fault_t handle_userfault(struct vm_fault *vmf, unsig= ned long reason) =09uwq.ctx =3D ctx; =09uwq.waken =3D false; =20 -=09return_to_userland =3D vmf->flags & FAULT_FLAG_INTERRUPTIBLE; -=09blocking_state =3D return_to_userland ? TASK_INTERRUPTIBLE : -=09=09=09 TASK_KILLABLE; +=09blocking_state =3D userfaultfd_get_blocking_state(vmf->flags); =20 =09spin_lock_irq(&ctx->fault_pending_wqh.lock); =09/* @@ -490,8 +512,7 @@ vm_fault_t handle_userfault(struct vm_fault *vmf, unsig= ned long reason) =09up_read(&mm->mmap_sem); =20 =09if (likely(must_wait && !READ_ONCE(ctx->released) && -=09=09 (return_to_userland ? !signal_pending(current) : -=09=09 !fatal_signal_pending(current)))) { +=09=09 !userfaultfd_signal_pending(vmf->flags))) { =09=09wake_up_poll(&ctx->fd_wqh, EPOLLIN); =09=09schedule(); =09=09ret |=3D VM_FAULT_MAJOR; @@ -513,8 +534,7 @@ vm_fault_t handle_userfault(struct vm_fault *vmf, unsig= ned long reason) =09=09=09set_current_state(blocking_state); =09=09=09if (READ_ONCE(uwq.waken) || =09=09=09 READ_ONCE(ctx->released) || -=09=09=09 (return_to_userland ? signal_pending(current) : -=09=09=09 fatal_signal_pending(current))) +=09=09=09 userfaultfd_signal_pending(vmf->flags)) =09=09=09=09break; =09=09=09schedule(); =09=09} --=20 2.24.1