From patchwork Mon Aug 20 07:09:42 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Konstantin Khlebnikov X-Patchwork-Id: 10569965 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 CCD95139B for ; Mon, 20 Aug 2018 07:09:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AB3DE29174 for ; Mon, 20 Aug 2018 07:09:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9C27D29189; Mon, 20 Aug 2018 07:09:52 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1777229174 for ; Mon, 20 Aug 2018 07:09:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726009AbeHTKYQ (ORCPT ); Mon, 20 Aug 2018 06:24:16 -0400 Received: from forwardcorp1o.cmail.yandex.net ([37.9.109.47]:37287 "EHLO forwardcorp1o.cmail.yandex.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725944AbeHTKYP (ORCPT ); Mon, 20 Aug 2018 06:24:15 -0400 Received: from mxbackcorp1g.mail.yandex.net (mxbackcorp1g.mail.yandex.net [IPv6:2a02:6b8:0:1402::301]) by forwardcorp1o.cmail.yandex.net (Yandex) with ESMTP id 28FF720EC6; Mon, 20 Aug 2018 10:09:45 +0300 (MSK) Received: from smtpcorp1o.mail.yandex.net (smtpcorp1o.mail.yandex.net [2a02:6b8:0:1a2d::30]) by mxbackcorp1g.mail.yandex.net (nwsmtp/Yandex) with ESMTP id mWrWIfh9Ec-9i8aqtwZ; Mon, 20 Aug 2018 10:09:45 +0300 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1534748985; bh=v2UiUhFBFDW+wYuJgRzxbrXopFfwTO6oBrcAWPpFxCE=; h=Subject:From:To:Date:Message-ID; b=oBEeZzzCDN71Zye+HL3I7FkpsnS4zUCxulvxVDY5kQxM5pa3twoT8Z7EvGUua1BnX naBOgIsSjiIj1+iYmKjgLxvxmefQdLnUNbnLxvMrn8fjYz/isg3tO0aL5WOvvWHw4v IbfaoLQai0R9FqFJUOHKC6yKjpau4MikSwXejlC8= Received: from dynamic-red.dhcp.yndx.net (dynamic-red.dhcp.yndx.net [2a02:6b8:0:40c:ac1b:4357:f84c:a04a]) by smtpcorp1o.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id RYALdQGwKc-9iNmAwJh; Mon, 20 Aug 2018 10:09:44 +0300 (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client certificate not present) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1534748984; bh=v2UiUhFBFDW+wYuJgRzxbrXopFfwTO6oBrcAWPpFxCE=; h=Subject:From:To:Date:Message-ID; b=1MgYflPpAMOuW97ij7qwfZtupaRnzFsG+eiXldWsD8oXkS46dzo33ynOXc4UNdGhg 5JVzf2ANss6sbHzY2nUd4QWZ9ZQqSG7feEpKcC09KMxHQdvjpKlFaCpWY49rxZkRS6 57fiYJsdwA4DOqQ8+gVhYJa8CckWp8qgOuWDIuWM= Authentication-Results: smtpcorp1o.mail.yandex.net; dkim=pass header.i=@yandex-team.ru Subject: [PATCH] fanotify: use killable wait for waiting response for permission events From: Konstantin Khlebnikov To: linux-fsdevel@vger.kernel.org, Amir Goldstein , Jan Kara , linux-kernel@vger.kernel.org Date: Mon, 20 Aug 2018 10:09:42 +0300 Message-ID: <153474898224.6806.12518115530793064797.stgit@buzz> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Waiting in uninterruptible state for response from userspace easily produces deadlocks and hordes of unkillable tasks. This patch makes this wait killable. At receiving fatal signal task will remove queued event and die. If event is already handled then response will be received as usual. Signed-off-by: Konstantin Khlebnikov --- fs/notify/fanotify/fanotify.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/fs/notify/fanotify/fanotify.c b/fs/notify/fanotify/fanotify.c index eb4e75175cfb..7a0c37790c89 100644 --- a/fs/notify/fanotify/fanotify.c +++ b/fs/notify/fanotify/fanotify.c @@ -64,7 +64,27 @@ static int fanotify_get_response(struct fsnotify_group *group, pr_debug("%s: group=%p event=%p\n", __func__, group, event); - wait_event(group->fanotify_data.access_waitq, event->response); + ret = wait_event_killable(group->fanotify_data.access_waitq, + event->response); + if (ret) { + /* Try to remove pending event from the queue */ + spin_lock(&group->notification_lock); + if (!list_empty(&event->fae.fse.list)) + list_del_init(&event->fae.fse.list); + else + ret = 0; + spin_unlock(&group->notification_lock); + + if (ret) + return ret; + + /* + * We cannot return, this will destroy event while + * process_access_response() fills response. + * Just wait for wakeup and continue normal flow. + */ + wait_event(group->fanotify_data.access_waitq, event->response); + } /* userspace responded, convert to something usable */ switch (event->response & ~FAN_AUDIT) {