From patchwork Thu Mar 21 15:11:42 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Kara X-Patchwork-Id: 10863769 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 1161917E0 for ; Thu, 21 Mar 2019 15:12:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EBA5B2A0C1 for ; Thu, 21 Mar 2019 15:12:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DFC3B2A2F8; Thu, 21 Mar 2019 15:12:08 +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=-7.9 required=2.0 tests=BAYES_00,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 4C30529ED6 for ; Thu, 21 Mar 2019 15:12:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728138AbfCUPMD (ORCPT ); Thu, 21 Mar 2019 11:12:03 -0400 Received: from mx2.suse.de ([195.135.220.15]:56032 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727857AbfCUPMD (ORCPT ); Thu, 21 Mar 2019 11:12:03 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 68874AEE6; Thu, 21 Mar 2019 15:12:01 +0000 (UTC) Received: by quack2.suse.cz (Postfix, from userid 1000) id 6A0161E0CE4; Thu, 21 Mar 2019 16:12:00 +0100 (CET) From: Jan Kara To: Cc: Orion Poplawski , Vivek Trivedi , Amir Goldstein , , LKML , "Eric W. Biederman" , Jan Kara Subject: [PATCH] fanotify: Make wait for permission events interruptible Date: Thu, 21 Mar 2019 16:11:42 +0100 Message-Id: <20190321151142.17104-1-jack@suse.cz> X-Mailer: git-send-email 2.16.4 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 Switch waiting for response to fanotify permission events interruptible. This allows e.g. the system to be suspended while there are some fanotify permission events pending (which is reportedly pretty common when for example AV solution is in use). However just making the wait interruptible can result in e.g. open(2) returning -EINTR where previously such error code never happened in practice. To avoid confusion of userspace due to this error code, return -ERESTARTNOINTR instead. Signed-off-by: Jan Kara --- fs/notify/fanotify/fanotify.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) Orion, can you give this patch some testing with your usecase? Also if anybody sees any issue with returning -ERESTARTNOINTR I have missed, please speak up. diff --git a/fs/notify/fanotify/fanotify.c b/fs/notify/fanotify/fanotify.c index 6b9c27548997..eb790853844b 100644 --- a/fs/notify/fanotify/fanotify.c +++ b/fs/notify/fanotify/fanotify.c @@ -92,10 +92,17 @@ static int fanotify_get_response(struct fsnotify_group *group, pr_debug("%s: group=%p event=%p\n", __func__, group, event); - ret = wait_event_killable(group->fanotify_data.access_waitq, - event->state == FAN_EVENT_ANSWERED); + ret = wait_event_interruptible(group->fanotify_data.access_waitq, + event->state == FAN_EVENT_ANSWERED); /* Signal pending? */ if (ret < 0) { + /* + * Force restarting a syscall so that this is mostly invisible + * for userspace which is not prepared for handling EINTR e.g. + * from open(2). + */ + if (ret == -ERESTARTSYS) + ret = -ERESTARTNOINTR; spin_lock(&group->notification_lock); /* Event reported to userspace and no answer yet? */ if (event->state == FAN_EVENT_REPORTED) {