From patchwork Wed Oct 3 21:25:32 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 10625321 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 7ABAC1515 for ; Wed, 3 Oct 2018 21:25:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6B4D629075 for ; Wed, 3 Oct 2018 21:25:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5F12E2907B; Wed, 3 Oct 2018 21:25: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,FREEMAIL_FROM,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 0FC3729075 for ; Wed, 3 Oct 2018 21:25:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726277AbeJDEP5 (ORCPT ); Thu, 4 Oct 2018 00:15:57 -0400 Received: from mail-wm1-f68.google.com ([209.85.128.68]:34233 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725871AbeJDEP5 (ORCPT ); Thu, 4 Oct 2018 00:15:57 -0400 Received: by mail-wm1-f68.google.com with SMTP id z25-v6so159727wmf.1 for ; Wed, 03 Oct 2018 14:25:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=d+xj9mYOfQOIoJAsD1P4D2sHGzPIj13ANhwoNK+JALI=; b=Z9ZBNb1eVAHVIqIOuuroWcOE+Xk3W0hMDH18RuG75VtqPIUyKfwn4M94bInH1msz4Y itcciJxJH0uDCg2ickbHJnfWsgvBIusdZJZRLefyyXyhkKArsg8yYTYnnyCZMRscg64G PpVqbusDVFOUxy9DIPXxeNpLQzPiIh+H8KzRuYmcbzTQ1upfPb+RtsBO5cdj0GJqQ0FZ qGjapDT6TpgqenbaXkIbm5ezM4w1ydlVBH5zhMoR4vk9kLiRV93EV+Mnm3W64nAGKb5r SotyMezuXwjk2lOmknhcWcbMNkr0dlE3wyvqrGgVLFR9TGGwYtsjRUtN1THoSGwjUbcq H4QQ== 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; bh=d+xj9mYOfQOIoJAsD1P4D2sHGzPIj13ANhwoNK+JALI=; b=pcEYiZcguxs96xpbdfS6bfgNusBk3PoIVN1ZHXO3R5JkSxtEPpvklDiYYq8O32eyxi O9RWoiLlMh0Z5EG7eWMOwHSI0BKjKPGs3+O7+Dmb8jaSibGfNxAWu3bwI6IvKHwOQkzb 4LseHh0eyK++3i3nysnY3RO4pcx9QPmFKXGwVrlvuuVoNQo30CwLT9PkwA8RoyVTzOF7 ycXuhO1IAbDxQW07IL460we68bhJyh9JauQ5g9iMSNqMX+8EN8XT42X/tMO7kiMKF8rZ uygZkuoHADnvOv0mBTePYRZtuaxhnckaM2kLgFXzvrpDtAtaoUDy3hkkrADuphGN3gMe P2Ew== X-Gm-Message-State: ABuFfoj0EDBpHyHaQjmuKCVfgKKRMY7zcZA85pk+YTeOQx7iwYXCfoxN igPivoc/DWTIg6gjaXij8N/O+IvF X-Google-Smtp-Source: ACcGV6091cpMU5hq50J46a2r9qKnlYPKLd0v5NCTraOwSR/a3J7tFJQMp+yXmHlraYYzFAz3EER7HA== X-Received: by 2002:a1c:adce:: with SMTP id w197-v6mr631226wme.11.1538601949496; Wed, 03 Oct 2018 14:25:49 -0700 (PDT) Received: from localhost.localdomain ([141.226.14.107]) by smtp.gmail.com with ESMTPSA id 193-v6sm4073866wmj.21.2018.10.03.14.25.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 03 Oct 2018 14:25:49 -0700 (PDT) From: Amir Goldstein To: Jan Kara Cc: linux-fsdevel@vger.kernel.org Subject: [PATCH v3 1/8] fanotify: fix collision of internal and uapi mark flags Date: Thu, 4 Oct 2018 00:25:32 +0300 Message-Id: <20181003212539.2384-2-amir73il@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181003212539.2384-1-amir73il@gmail.com> References: <20181003212539.2384-1-amir73il@gmail.com> 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 The new mark flag FAN_MARK_FILESYSTEMS collides with existing internal flag FAN_MARK_ONDIR. Change internal flag value to avoid the collision. Fixes: d54f4fba889b ("fanotify: add API to attach/detach super block mark") Signed-off-by: Amir Goldstein --- include/linux/fanotify.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/linux/fanotify.h b/include/linux/fanotify.h index 9c5ea3bdfaa0..e70fccc3757e 100644 --- a/include/linux/fanotify.h +++ b/include/linux/fanotify.h @@ -5,7 +5,7 @@ #include /* not valid from userspace, only kernel internal */ -#define FAN_MARK_ONDIR 0x00000100 +#define FAN_MARK_ONDIR 0x80000000 #define FAN_GROUP_FLAG(group, flag) \ ((group)->fanotify_data.flags & (flag)) From patchwork Wed Oct 3 21:25:33 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 10625323 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 CE46F1515 for ; Wed, 3 Oct 2018 21:25:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BFB6E2907A for ; Wed, 3 Oct 2018 21:25:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B26412907B; Wed, 3 Oct 2018 21:25:53 +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,FREEMAIL_FROM,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 4CB1A29075 for ; Wed, 3 Oct 2018 21:25:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726426AbeJDEP6 (ORCPT ); Thu, 4 Oct 2018 00:15:58 -0400 Received: from mail-wr1-f67.google.com ([209.85.221.67]:35254 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725747AbeJDEP6 (ORCPT ); Thu, 4 Oct 2018 00:15:58 -0400 Received: by mail-wr1-f67.google.com with SMTP id w5-v6so7694004wrt.2 for ; Wed, 03 Oct 2018 14:25:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=OiboQWa8g8E/+1lfti7v/DhBkShJu2jya4W+TAcS7u8=; b=f4rkh0Iy1isiXYe1X7RbWO7sU3ad8ZQuIU7OUwJrHbIyjtQ9SqSJ1ozdk3VRW5yoOw ZAcXuQDXGVbqPdsQOglypZ+SkQCTWjGdJ5JQGlCa7/XhcJpl+1xfyigsxSrQlY5463UA NzyJOL8axKva7AGoY0MMsmnndJnNkb90pWhTGZJWXSAix2XGbpXMU2BwBS5/4tTvAtZj uLWu8MIBaWfKopCQ47YykTyJCF6Cr46NLX/U9//unRwEgm2zeWU/NS/jUqeuWtHrshKe drxsfIsu5NB+t1UiNkfCXtBBZGpTrHTkTXa9j9F1f+aRvhesdnMrGpqPySvWsmMhmumQ yc9Q== 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; bh=OiboQWa8g8E/+1lfti7v/DhBkShJu2jya4W+TAcS7u8=; b=I0YebBHnpNZ0bPL2Ormr0aMO1n19NiDfmLf6cx1tU9eoDw3gkLv8F5pdiiee14dmR+ 8UFf7Bk9gObHRCEeVlY5NO/fq9XVqbvTUi9I2dtq57hRWdBbHdh0ZE2E48AIed1jwcDh /kgkCN2B1osNXf6Mn51JTvOYuX5+wS8g9wfw7eEHwvqW3xxXiuD346aJ5EBLu+45C2QR dSJq9uAMA+hWqzhpu3b2oIEEbCl+vnfN8/7iiJKZLB+xFNIOdXuw4zDYnizuhXd6s1v6 khU8xrKESf6OSo4vDf37alFV3SkoFxSnBadFLVBur+X0X+8OR8rp+qcQfBZaYebwSXU/ DSRA== X-Gm-Message-State: ABuFfoh9zqo+jK8nTuh0DrEvV1Efm11+fDgsOmxeUWAw8aGYlsKhwpG2 sZcjqjg3LLjyIsBPHwu2Xnw= X-Google-Smtp-Source: ACcGV61tWaw2QHzPzuSE8KCfev3foUMU8YIw5UIzDdhUVgGXOShRu86AjYApq6SaRlTNFdcGJVa06A== X-Received: by 2002:adf:da43:: with SMTP id r3-v6mr2673572wrl.221.1538601950616; Wed, 03 Oct 2018 14:25:50 -0700 (PDT) Received: from localhost.localdomain ([141.226.14.107]) by smtp.gmail.com with ESMTPSA id 193-v6sm4073866wmj.21.2018.10.03.14.25.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 03 Oct 2018 14:25:50 -0700 (PDT) From: Amir Goldstein To: Jan Kara Cc: linux-fsdevel@vger.kernel.org Subject: [PATCH v3 2/8] fsnotify: generalize handling of extra event flags Date: Thu, 4 Oct 2018 00:25:33 +0300 Message-Id: <20181003212539.2384-3-amir73il@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181003212539.2384-1-amir73il@gmail.com> References: <20181003212539.2384-1-amir73il@gmail.com> 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 FS_EVENT_ON_CHILD gets a special treatment in fsnotify() because it is not a flag specifying an event type, but rather an extra flags that may be reported along with another event and control the handling of the event by the backend. FS_ISDIR is also an "extra flag" and not an "event type" and therefore desrves the same treatment. With inotify/dnotify backends it was never possible to set FS_ISDIR in mark masks, so it did not matter. With fanotify backend, mark adding code jumps through hoops to avoid setting the FS_ISDIR in the commulative object mask. Separate the constant ALL_FSNOTIFY_EVENTS to ALL_FSNOTIFY_FLAGS and ALL_FSNOTIFY_EVENTS, so the latter can be used to test for specific event types. Signed-off-by: Amir Goldstein --- fs/notify/fsnotify.c | 7 +++---- include/linux/fsnotify_backend.h | 9 +++++++-- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/fs/notify/fsnotify.c b/fs/notify/fsnotify.c index 422fbc6dffde..7391a02bf723 100644 --- a/fs/notify/fsnotify.c +++ b/fs/notify/fsnotify.c @@ -196,7 +196,7 @@ static int send_to_group(struct inode *to_tell, struct fsnotify_iter_info *iter_info) { struct fsnotify_group *group = NULL; - __u32 test_mask = (mask & ~FS_EVENT_ON_CHILD); + __u32 test_mask = (mask & ALL_FSNOTIFY_EVENTS); __u32 marks_mask = 0; __u32 marks_ignored_mask = 0; struct fsnotify_mark *mark; @@ -329,8 +329,7 @@ int fsnotify(struct inode *to_tell, __u32 mask, const void *data, int data_is, struct mount *mnt = NULL; __u32 mnt_or_sb_mask = 0; int ret = 0; - /* global tests shouldn't care about events on child only the specific event */ - __u32 test_mask = (mask & ~FS_EVENT_ON_CHILD); + __u32 test_mask = (mask & ALL_FSNOTIFY_EVENTS); if (data_is == FSNOTIFY_EVENT_PATH) { mnt = real_mount(((const struct path *)data)->mnt); @@ -396,7 +395,7 @@ static __init int fsnotify_init(void) { int ret; - BUG_ON(hweight32(ALL_FSNOTIFY_EVENTS) != 23); + BUG_ON(hweight32(ALL_FSNOTIFY_BITS) != 23); ret = init_srcu_struct(&fsnotify_mark_srcu); if (ret) diff --git a/include/linux/fsnotify_backend.h b/include/linux/fsnotify_backend.h index 8e91341cbd8a..135b973e44d1 100644 --- a/include/linux/fsnotify_backend.h +++ b/include/linux/fsnotify_backend.h @@ -68,15 +68,20 @@ #define ALL_FSNOTIFY_PERM_EVENTS (FS_OPEN_PERM | FS_ACCESS_PERM) +/* Events that can be reported to backends */ #define ALL_FSNOTIFY_EVENTS (FS_ACCESS | FS_MODIFY | FS_ATTRIB | \ FS_CLOSE_WRITE | FS_CLOSE_NOWRITE | FS_OPEN | \ FS_MOVED_FROM | FS_MOVED_TO | FS_CREATE | \ FS_DELETE | FS_DELETE_SELF | FS_MOVE_SELF | \ FS_UNMOUNT | FS_Q_OVERFLOW | FS_IN_IGNORED | \ - FS_OPEN_PERM | FS_ACCESS_PERM | FS_EXCL_UNLINK | \ - FS_ISDIR | FS_IN_ONESHOT | FS_DN_RENAME | \ + FS_OPEN_PERM | FS_ACCESS_PERM | FS_DN_RENAME) + +/* Extra flags that may be reported with event or control handling of events */ +#define ALL_FSNOTIFY_FLAGS (FS_EXCL_UNLINK | FS_ISDIR | FS_IN_ONESHOT | \ FS_DN_MULTISHOT | FS_EVENT_ON_CHILD) +#define ALL_FSNOTIFY_BITS (ALL_FSNOTIFY_EVENTS | ALL_FSNOTIFY_FLAGS) + struct fsnotify_group; struct fsnotify_event; struct fsnotify_mark; From patchwork Wed Oct 3 21:25:34 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 10625325 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 E851F1515 for ; Wed, 3 Oct 2018 21:25:54 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D98CB2907A for ; Wed, 3 Oct 2018 21:25:54 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CDBA429080; Wed, 3 Oct 2018 21:25:54 +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,FREEMAIL_FROM,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 6DCB52907A for ; Wed, 3 Oct 2018 21:25:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726449AbeJDEQA (ORCPT ); Thu, 4 Oct 2018 00:16:00 -0400 Received: from mail-wr1-f66.google.com ([209.85.221.66]:47077 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725871AbeJDEP7 (ORCPT ); Thu, 4 Oct 2018 00:15:59 -0400 Received: by mail-wr1-f66.google.com with SMTP id a2-v6so605862wrc.13 for ; Wed, 03 Oct 2018 14:25:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=lczJRDZf5gF/P9LPeBol0NCVj9AqNwkjgYSN6nlBwEo=; b=LdspMe0olJC81g4bxrpvykRe1Wft2vTcwjASpzhPfu8WQUW4Fdi774SC49inHM61uS OlueF8fy0E8SANdqKA1WMSNI2UnCaUm+MFGm9ATDRZXCLHiU+Z9j1dfo70Zu95xgEwrz FLiF0ueV5Aj0t6beEwKbf9wKziT/Vj8oS9oAVMjML9GVN8BqKsfwNRhvpMSxo3p03oEu IZYEGVNXTicWMrYbuCX0JxGtHMMX1rQtatYObJtwicMHQu1te2cme2tLG1hMtmtkm1XJ 8v/GO0pXm845XeLlSmkSfw4lviVcXjs55KIpNYYpG/9pzp5ZQvfLw6jIBfMIrRD2yb6n RLLg== 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; bh=lczJRDZf5gF/P9LPeBol0NCVj9AqNwkjgYSN6nlBwEo=; b=FOsQ2mbDSsSYnxG/xHpsmhNGC/ppM9isY/MikK4pwOMKwDfqAfN6xnurYvH4/EFc1/ qa8H3h+gyjABW6hWMD2nMs5bCMEcDCnwqHHHdmmq/lXyNSPQ7dRWgTj96oa977ysladC +Bd5mXivFAAPGS4moPayHV/WDwVqSgn7sHXWjXPlaCrT22JGrqYHY5HG6mdY4EwuT4oT g/wmGjPRdU6V7l4m2zIO+aRZpTTDA7rnuOhTRqr1oB8wO5Qf0gs7U76BTtX0WsZuec1B m0vOi9iYDChRqDpTa6YkPe1rJMQaY4C/+C13pevp0WXg+SpuNp7gftCNWVppQRZifeH3 TraQ== X-Gm-Message-State: ABuFfogn9SwENF5tsF+PMpX/4+DjwfMIQqhekCZtN23NUcsX6hDbqSUO BLZk9cxX7i+FXaFbOO7dcKc= X-Google-Smtp-Source: ACcGV62GYwr3C+wLhaTUJIGrMuHbgBhPLgcDsYr1HdwO0oNmQrNzaQKd1FqHPBaD/I1N2B6hCWOYRw== X-Received: by 2002:a5d:6490:: with SMTP id r16-v6mr2422392wru.99.1538601951638; Wed, 03 Oct 2018 14:25:51 -0700 (PDT) Received: from localhost.localdomain ([141.226.14.107]) by smtp.gmail.com with ESMTPSA id 193-v6sm4073866wmj.21.2018.10.03.14.25.50 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 03 Oct 2018 14:25:51 -0700 (PDT) From: Amir Goldstein To: Jan Kara Cc: linux-fsdevel@vger.kernel.org Subject: [PATCH v3 3/8] fanotify: simplify handling of FAN_ONDIR Date: Thu, 4 Oct 2018 00:25:34 +0300 Message-Id: <20181003212539.2384-4-amir73il@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181003212539.2384-1-amir73il@gmail.com> References: <20181003212539.2384-1-amir73il@gmail.com> 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 fanotify mark add/remove code jumps through hoops to avoid setting the FS_ISDIR in the commulative object mask. That was just papering over a bug in fsnotify() handling of the FS_ISDIR extra flag. This bug is now fixed, so all the hoops can be removed along with the unneeded internal flag FAN_MARK_ONDIR. Signed-off-by: Amir Goldstein --- fs/notify/fanotify/fanotify_user.c | 32 +++++------------------------- include/linux/fanotify.h | 3 --- 2 files changed, 5 insertions(+), 30 deletions(-) diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c index 15719d4aa4b5..34b511407035 100644 --- a/fs/notify/fanotify/fanotify_user.c +++ b/fs/notify/fanotify/fanotify_user.c @@ -506,18 +506,10 @@ static __u32 fanotify_mark_remove_from_mask(struct fsnotify_mark *fsn_mark, spin_lock(&fsn_mark->lock); if (!(flags & FAN_MARK_IGNORED_MASK)) { - __u32 tmask = fsn_mark->mask & ~mask; - - if (flags & FAN_MARK_ONDIR) - tmask &= ~FAN_ONDIR; - oldmask = fsn_mark->mask; - fsn_mark->mask = tmask; + fsn_mark->mask &= ~mask; } else { - __u32 tmask = fsn_mark->ignored_mask & ~mask; - if (flags & FAN_MARK_ONDIR) - tmask &= ~FAN_ONDIR; - fsn_mark->ignored_mask = tmask; + fsn_mark->ignored_mask &= ~mask; } *destroy = !(fsn_mark->mask | fsn_mark->ignored_mask); spin_unlock(&fsn_mark->lock); @@ -586,19 +578,10 @@ static __u32 fanotify_mark_add_to_mask(struct fsnotify_mark *fsn_mark, spin_lock(&fsn_mark->lock); if (!(flags & FAN_MARK_IGNORED_MASK)) { - __u32 tmask = fsn_mark->mask | mask; - - if (flags & FAN_MARK_ONDIR) - tmask |= FAN_ONDIR; - oldmask = fsn_mark->mask; - fsn_mark->mask = tmask; + fsn_mark->mask |= mask; } else { - __u32 tmask = fsn_mark->ignored_mask | mask; - if (flags & FAN_MARK_ONDIR) - tmask |= FAN_ONDIR; - - fsn_mark->ignored_mask = tmask; + fsn_mark->ignored_mask |= mask; if (flags & FAN_MARK_IGNORED_SURV_MODIFY) fsn_mark->flags |= FSNOTIFY_MARK_FLAG_IGNORED_SURV_MODIFY; } @@ -820,7 +803,7 @@ static int do_fanotify_mark(int fanotify_fd, unsigned int flags, __u64 mask, struct fsnotify_group *group; struct fd f; struct path path; - u32 valid_mask = FAN_ALL_EVENTS | FAN_EVENT_ON_CHILD; + u32 valid_mask = FAN_ALL_EVENTS | FAN_EVENT_ON_CHILD | FAN_ONDIR; unsigned int mark_type = flags & FAN_MARK_TYPE_MASK; int ret; @@ -857,11 +840,6 @@ static int do_fanotify_mark(int fanotify_fd, unsigned int flags, __u64 mask, return -EINVAL; } - if (mask & FAN_ONDIR) { - flags |= FAN_MARK_ONDIR; - mask &= ~FAN_ONDIR; - } - if (IS_ENABLED(CONFIG_FANOTIFY_ACCESS_PERMISSIONS)) valid_mask |= FAN_ALL_PERM_EVENTS; diff --git a/include/linux/fanotify.h b/include/linux/fanotify.h index e70fccc3757e..a8c3fc54276d 100644 --- a/include/linux/fanotify.h +++ b/include/linux/fanotify.h @@ -4,9 +4,6 @@ #include -/* not valid from userspace, only kernel internal */ -#define FAN_MARK_ONDIR 0x80000000 - #define FAN_GROUP_FLAG(group, flag) \ ((group)->fanotify_data.flags & (flag)) From patchwork Wed Oct 3 21:25:35 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 10625327 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 351911731 for ; Wed, 3 Oct 2018 21:25:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 25A3429080 for ; Wed, 3 Oct 2018 21:25:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 19F2A2908B; Wed, 3 Oct 2018 21:25:57 +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,FREEMAIL_FROM,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 4C95A29080 for ; Wed, 3 Oct 2018 21:25:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726511AbeJDEQB (ORCPT ); Thu, 4 Oct 2018 00:16:01 -0400 Received: from mail-wm1-f66.google.com ([209.85.128.66]:39879 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725747AbeJDEQB (ORCPT ); Thu, 4 Oct 2018 00:16:01 -0400 Received: by mail-wm1-f66.google.com with SMTP id q8-v6so6973493wmq.4; Wed, 03 Oct 2018 14:25:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=MoZGxZzQ8dOuY58ErQ9EkwAlPrUfRD3SIXaTQMFbzOA=; b=tD2tS5Lc2Tb3wGJUMDe8WZOmc3aQhDbzw4BkUmldLRH2rmGz8/LS2cj/7tbiRFDw0J mzVBL7W2UYfAYemKNCwhvVnIaHbNM000qh2H0HqepIhhn+9eRcVKE30wcSNQtcQVTYs6 66TwppGct/3IqS40xtfky98NSs3cW6yefgSMYGIo6cJqfLqg41rcqiWuXkI+MXu3GaWf MWqIItnaRro6b9qqPa5RqL1v2uV7aGpbWG2llYo1oPotNNYHjld08RMdMskldOtByXPV GJikYx4E1vm4UdWXI2UqviF/Cgd6gCyqNl3lg5COVEf1CbDlemgpg2XLVlmGCcZOk+jK O9sQ== 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; bh=MoZGxZzQ8dOuY58ErQ9EkwAlPrUfRD3SIXaTQMFbzOA=; b=VzKLUBklqBXYwAOUUkKcy/CCc9Ct6Dd+NxtySTFZShfy7TkPyZ0LgKpHG1IASXyxry ouGdpoV2+nFHx3Zf+mFGk3YDlnQrdrmzPLoJAhb4TQOvVta4JbgkI9c6WqhzGQwl20id 4o2OtymtlqNBpTKm8u9KNTjDGGWgqi0gsg1EOkRlbcHHI73RwreOg4lYrx79IzB/eZgr QTEJQPWy/yj+pfMmrFtJTGxIU1DWeKEZ0IMTwwxOevXh6KsbOUbBhQ7YiVRkBz2dUa2l vPh+TnhMJPAewk9Ta/v2Xp78BvpB/jhuGA0SNIB2+pZWKxUlrzUdXupYUlEGKZuRyELY 3oLA== X-Gm-Message-State: ABuFfoiX01PfjbfMAb0iYr6lDse1w1+h8R/6CkVkacP/0irCDe1W84IR 5MuXEW+xp7dhH9wSdQkDbag= X-Google-Smtp-Source: ACcGV63L+tHIam5/Ty8HiTqWSqzqIwFsmDX4MZakRSGCXmq4jeKGxhsrGrJV4vMamaNQjEp7oPaeBA== X-Received: by 2002:a1c:1943:: with SMTP id 64-v6mr2470082wmz.89.1538601952931; Wed, 03 Oct 2018 14:25:52 -0700 (PDT) Received: from localhost.localdomain ([141.226.14.107]) by smtp.gmail.com with ESMTPSA id 193-v6sm4073866wmj.21.2018.10.03.14.25.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 03 Oct 2018 14:25:52 -0700 (PDT) From: Amir Goldstein To: Jan Kara Cc: linux-fsdevel@vger.kernel.org, linux-api@vger.kernel.org Subject: [PATCH v3 4/8] fanotify: deprecate uapi FAN_ALL_* constants Date: Thu, 4 Oct 2018 00:25:35 +0300 Message-Id: <20181003212539.2384-5-amir73il@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181003212539.2384-1-amir73il@gmail.com> References: <20181003212539.2384-1-amir73il@gmail.com> 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 We do not want to add new bits to the FAN_ALL_* uapi constants because they have been exposed to userspace. If there are programs out there using these constants, those programs could break if re-compiled with modified FAN_ALL_* constants and run on an old kernel. We deprecate the uapi constants FAN_ALL_* and define new FANOTIFY_* constants for internal use to replace them. New feature bits will be added only to the new constants. Cc: Signed-off-by: Amir Goldstein --- fs/notify/fanotify/fanotify.c | 6 ++-- fs/notify/fanotify/fanotify.h | 2 +- fs/notify/fanotify/fanotify_user.c | 22 +++++++------- include/linux/fanotify.h | 47 ++++++++++++++++++++++++++++++ include/uapi/linux/fanotify.h | 18 ++++++------ 5 files changed, 71 insertions(+), 24 deletions(-) diff --git a/fs/notify/fanotify/fanotify.c b/fs/notify/fanotify/fanotify.c index 94b52157bf8d..03498eb995be 100644 --- a/fs/notify/fanotify/fanotify.c +++ b/fs/notify/fanotify/fanotify.c @@ -131,8 +131,8 @@ static bool fanotify_should_send_event(struct fsnotify_iter_info *iter_info, !(marks_mask & FS_ISDIR & ~marks_ignored_mask)) return false; - if (event_mask & FAN_ALL_OUTGOING_EVENTS & marks_mask & - ~marks_ignored_mask) + if (event_mask & FANOTIFY_OUTGOING_EVENTS & + marks_mask & ~marks_ignored_mask) return true; return false; @@ -236,7 +236,7 @@ static int fanotify_handle_event(struct fsnotify_group *group, ret = fsnotify_add_event(group, fsn_event, fanotify_merge); if (ret) { /* Permission events shouldn't be merged */ - BUG_ON(ret == 1 && mask & FAN_ALL_PERM_EVENTS); + BUG_ON(ret == 1 && mask & FANOTIFY_PERM_EVENTS); /* Our event wasn't used in the end. Free it. */ fsnotify_destroy_event(group, fsn_event); diff --git a/fs/notify/fanotify/fanotify.h b/fs/notify/fanotify/fanotify.h index 8609ba06f474..88a8290a61cb 100644 --- a/fs/notify/fanotify/fanotify.h +++ b/fs/notify/fanotify/fanotify.h @@ -44,7 +44,7 @@ FANOTIFY_PE(struct fsnotify_event *fse) static inline bool fanotify_is_perm_event(u32 mask) { return IS_ENABLED(CONFIG_FANOTIFY_ACCESS_PERMISSIONS) && - mask & FAN_ALL_PERM_EVENTS; + mask & FANOTIFY_PERM_EVENTS; } static inline struct fanotify_event_info *FANOTIFY_E(struct fsnotify_event *fse) diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c index 34b511407035..530e5e486105 100644 --- a/fs/notify/fanotify/fanotify_user.c +++ b/fs/notify/fanotify/fanotify_user.c @@ -131,7 +131,7 @@ static int fill_event_metadata(struct fsnotify_group *group, metadata->metadata_len = FAN_EVENT_METADATA_LEN; metadata->vers = FANOTIFY_METADATA_VERSION; metadata->reserved = 0; - metadata->mask = fsn_event->mask & FAN_ALL_OUTGOING_EVENTS; + metadata->mask = fsn_event->mask & FANOTIFY_OUTGOING_EVENTS; metadata->pid = pid_vnr(event->tgid); if (unlikely(fsn_event->mask & FAN_Q_OVERFLOW)) metadata->fd = FAN_NOFD; @@ -395,7 +395,7 @@ static int fanotify_release(struct inode *ignored, struct file *file) */ while (!fsnotify_notify_queue_is_empty(group)) { fsn_event = fsnotify_remove_first_event(group); - if (!(fsn_event->mask & FAN_ALL_PERM_EVENTS)) { + if (!(fsn_event->mask & FANOTIFY_PERM_EVENTS)) { spin_unlock(&group->notification_lock); fsnotify_destroy_event(group, fsn_event); spin_lock(&group->notification_lock); @@ -691,9 +691,9 @@ SYSCALL_DEFINE2(fanotify_init, unsigned int, flags, unsigned int, event_f_flags) return -EPERM; #ifdef CONFIG_AUDITSYSCALL - if (flags & ~(FAN_ALL_INIT_FLAGS | FAN_ENABLE_AUDIT)) + if (flags & ~(FANOTIFY_INIT_FLAGS | FAN_ENABLE_AUDIT)) #else - if (flags & ~FAN_ALL_INIT_FLAGS) + if (flags & ~FANOTIFY_INIT_FLAGS) #endif return -EINVAL; @@ -745,7 +745,7 @@ SYSCALL_DEFINE2(fanotify_init, unsigned int, flags, unsigned int, event_f_flags) group->fanotify_data.f_flags = event_f_flags; init_waitqueue_head(&group->fanotify_data.access_waitq); INIT_LIST_HEAD(&group->fanotify_data.access_list); - switch (flags & FAN_ALL_CLASS_BITS) { + switch (flags & FANOTIFY_CLASS_BITS) { case FAN_CLASS_NOTIF: group->priority = FS_PRIO_0; break; @@ -803,8 +803,8 @@ static int do_fanotify_mark(int fanotify_fd, unsigned int flags, __u64 mask, struct fsnotify_group *group; struct fd f; struct path path; - u32 valid_mask = FAN_ALL_EVENTS | FAN_EVENT_ON_CHILD | FAN_ONDIR; - unsigned int mark_type = flags & FAN_MARK_TYPE_MASK; + u32 valid_mask = FANOTIFY_EVENTS | FAN_EVENT_ON_CHILD | FAN_ONDIR; + unsigned int mark_type = flags & FANOTIFY_MARK_TYPE_BITS; int ret; pr_debug("%s: fanotify_fd=%d flags=%x dfd=%d pathname=%p mask=%llx\n", @@ -814,7 +814,7 @@ static int do_fanotify_mark(int fanotify_fd, unsigned int flags, __u64 mask, if (mask & ((__u64)0xffffffff << 32)) return -EINVAL; - if (flags & ~FAN_ALL_MARK_FLAGS) + if (flags & ~FANOTIFY_MARK_FLAGS) return -EINVAL; switch (mark_type) { @@ -833,7 +833,7 @@ static int do_fanotify_mark(int fanotify_fd, unsigned int flags, __u64 mask, return -EINVAL; break; case FAN_MARK_FLUSH: - if (flags & ~(FAN_MARK_TYPE_MASK | FAN_MARK_FLUSH)) + if (flags & ~(FANOTIFY_MARK_TYPE_BITS | FAN_MARK_FLUSH)) return -EINVAL; break; default: @@ -841,7 +841,7 @@ static int do_fanotify_mark(int fanotify_fd, unsigned int flags, __u64 mask, } if (IS_ENABLED(CONFIG_FANOTIFY_ACCESS_PERMISSIONS)) - valid_mask |= FAN_ALL_PERM_EVENTS; + valid_mask |= FANOTIFY_PERM_EVENTS; if (mask & ~valid_mask) return -EINVAL; @@ -861,7 +861,7 @@ static int do_fanotify_mark(int fanotify_fd, unsigned int flags, __u64 mask, * allowed to set permissions events. */ ret = -EINVAL; - if (mask & FAN_ALL_PERM_EVENTS && + if (mask & FANOTIFY_PERM_EVENTS && group->priority == FS_PRIO_0) goto fput_and_out; diff --git a/include/linux/fanotify.h b/include/linux/fanotify.h index a8c3fc54276d..4519b0988afe 100644 --- a/include/linux/fanotify.h +++ b/include/linux/fanotify.h @@ -7,4 +7,51 @@ #define FAN_GROUP_FLAG(group, flag) \ ((group)->fanotify_data.flags & (flag)) +/* + * Flags allowed to be passed from/to userspace. + * + * We intentionally do not add new bits to the old FAN_ALL_* constants, because + * they are uapi exposed constants. If there are programs out there using + * these constant, the programs may break if re-compiled with new uapi headers + * and then run on an old kernel. + */ +#define FANOTIFY_CLASS_BITS (FAN_CLASS_NOTIF | FAN_CLASS_CONTENT | \ + FAN_CLASS_PRE_CONTENT) + +#define FANOTIFY_INIT_FLAGS (FANOTIFY_CLASS_BITS | \ + FAN_CLOEXEC | FAN_NONBLOCK | \ + FAN_UNLIMITED_QUEUE | FAN_UNLIMITED_MARKS) + +#define FANOTIFY_MARK_TYPE_BITS (FAN_MARK_INODE | FAN_MARK_MOUNT | \ + FAN_MARK_FILESYSTEM) + +#define FANOTIFY_MARK_FLAGS (FANOTIFY_MARK_TYPE_BITS | \ + FAN_MARK_ADD | \ + FAN_MARK_REMOVE | \ + FAN_MARK_DONT_FOLLOW | \ + FAN_MARK_ONLYDIR | \ + FAN_MARK_IGNORED_MASK | \ + FAN_MARK_IGNORED_SURV_MODIFY | \ + FAN_MARK_FLUSH) + +/* Events that user can request to be notified on */ +#define FANOTIFY_EVENTS (FAN_ACCESS | FAN_MODIFY | \ + FAN_CLOSE | FAN_OPEN) + +/* Events that require a permission response from user */ +#define FANOTIFY_PERM_EVENTS (FAN_OPEN_PERM | FAN_ACCESS_PERM) + +/* Events that may be reported to user */ +#define FANOTIFY_OUTGOING_EVENTS (FANOTIFY_EVENTS | \ + FANOTIFY_PERM_EVENTS | \ + FAN_Q_OVERFLOW) + +/* Do not use these old uapi constants internally */ +#undef FAN_ALL_CLASS_BITS +#undef FAN_ALL_INIT_FLAGS +#undef FAN_ALL_MARK_FLAGS +#undef FAN_ALL_EVENTS +#undef FAN_ALL_PERM_EVENTS +#undef FAN_ALL_OUTGOING_EVENTS + #endif /* _LINUX_FANOTIFY_H */ diff --git a/include/uapi/linux/fanotify.h b/include/uapi/linux/fanotify.h index ad81234d1919..d0c05de670ef 100644 --- a/include/uapi/linux/fanotify.h +++ b/include/uapi/linux/fanotify.h @@ -31,6 +31,8 @@ #define FAN_CLASS_NOTIF 0x00000000 #define FAN_CLASS_CONTENT 0x00000004 #define FAN_CLASS_PRE_CONTENT 0x00000008 + +/* Deprecated - do not use this in programs and do not add new flags here! */ #define FAN_ALL_CLASS_BITS (FAN_CLASS_NOTIF | FAN_CLASS_CONTENT | \ FAN_CLASS_PRE_CONTENT) @@ -38,6 +40,7 @@ #define FAN_UNLIMITED_MARKS 0x00000020 #define FAN_ENABLE_AUDIT 0x00000040 +/* Deprecated - do not use this in programs and do not add new flags here! */ #define FAN_ALL_INIT_FLAGS (FAN_CLOEXEC | FAN_NONBLOCK | \ FAN_ALL_CLASS_BITS | FAN_UNLIMITED_QUEUE |\ FAN_UNLIMITED_MARKS) @@ -57,23 +60,18 @@ #define FAN_MARK_INODE 0x00000000 #define FAN_MARK_MOUNT 0x00000010 #define FAN_MARK_FILESYSTEM 0x00000100 -#define FAN_MARK_TYPE_MASK (FAN_MARK_INODE | FAN_MARK_MOUNT | \ - FAN_MARK_FILESYSTEM) +/* Deprecated - do not use this in programs and do not add new flags here! */ #define FAN_ALL_MARK_FLAGS (FAN_MARK_ADD |\ FAN_MARK_REMOVE |\ FAN_MARK_DONT_FOLLOW |\ FAN_MARK_ONLYDIR |\ + FAN_MARK_MOUNT |\ FAN_MARK_IGNORED_MASK |\ FAN_MARK_IGNORED_SURV_MODIFY |\ - FAN_MARK_FLUSH|\ - FAN_MARK_TYPE_MASK) + FAN_MARK_FLUSH) -/* - * All of the events - we build the list by hand so that we can add flags in - * the future and not break backward compatibility. Apps will get only the - * events that they originally wanted. Be sure to add new events here! - */ +/* Deprecated - do not use this in programs and do not add new flags here! */ #define FAN_ALL_EVENTS (FAN_ACCESS |\ FAN_MODIFY |\ FAN_CLOSE |\ @@ -82,9 +80,11 @@ /* * All events which require a permission response from userspace */ +/* Deprecated - do not use this in programs and do not add new flags here! */ #define FAN_ALL_PERM_EVENTS (FAN_OPEN_PERM |\ FAN_ACCESS_PERM) +/* Deprecated - do not use this in programs and do not add new flags here! */ #define FAN_ALL_OUTGOING_EVENTS (FAN_ALL_EVENTS |\ FAN_ALL_PERM_EVENTS |\ FAN_Q_OVERFLOW) From patchwork Wed Oct 3 21:25:36 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 10625329 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 77C12174A for ; Wed, 3 Oct 2018 21:25:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6793729080 for ; Wed, 3 Oct 2018 21:25:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5BB0C29087; Wed, 3 Oct 2018 21:25:57 +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,FREEMAIL_FROM,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 0B0F52908A for ; Wed, 3 Oct 2018 21:25:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726587AbeJDEQC (ORCPT ); Thu, 4 Oct 2018 00:16:02 -0400 Received: from mail-wr1-f65.google.com ([209.85.221.65]:35256 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725871AbeJDEQB (ORCPT ); Thu, 4 Oct 2018 00:16:01 -0400 Received: by mail-wr1-f65.google.com with SMTP id w5-v6so7694112wrt.2 for ; Wed, 03 Oct 2018 14:25:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=YonemN/ftK59afoDWH4/F3Cc455oNw6EYOsiL2eZ7gY=; b=YWFzKuOTR2rYuQDYZFCsREM0bubczQEduteJKAfMtf9loI7vRXbzAGqBQTHCnwO//8 ITCWyrLmL+dfcFLc9dUSh+BX/XAFjeHzq53ujf3/rK0KwxTtdVztlmGfLdHNEdPrVU37 SPdzIb1PaWqPhCGk1+vduINBMI7Ulhyh/pO4oRXU/hRDtVV2Wlz1hT2WsgUmdkuPO2ex GFML88Yrmlb7VSCRs8lrCvrcxuCNvWsUaMfVauU5ih+IEaxjd+nkZJLOew6pG3aS3Wcz Si2s29sBQahAthSmxU2PzY32gFiVV+3K7EQVNqFKn40lLDwkZ1lqDB3x9a6BVqjT8tTI 835Q== 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; bh=YonemN/ftK59afoDWH4/F3Cc455oNw6EYOsiL2eZ7gY=; b=TPDO/X7J40YNV5XreEoMFfOW0R+TGIQi7TR2DIeEENXMh/ITVc1nNUzVtY3lEmUZWu h33IUVF7PqI/eWIrwWkqfUhg+hcW0ANekBjShs2Epa74/iA/K0n1LZK1qKhFH9p8ck9S /Ifu3gx0rScAPfj6I6btPRaWHGBau19bBX6Om6O663IxdZyHrdWO0ILQGCUkISPc6rXw q3s9qQUVzewrcwB9uY72coHt9qiVZvW9APjuZCSv3dXxxB2mDZrBTd+iCDk8MJ3SnFQz wBD+nNPpSz6cQazh2De5QgCCtoVZ+4FZtpqQ0BZv8oWtko+haAUJuJPwtaRflAJIkAJe rODA== X-Gm-Message-State: ABuFfoggekd4OQOUGWuYwbSsmaiuz4vjBgiWO48gl3pQHwoiqAeW2jql mn7Cy7UxNKwdf5bfPl0gQpIBLQjZ X-Google-Smtp-Source: ACcGV61gwNfkuLZ0QB/0JZtDpitCZWWssV1LKb82zZEmO9kTC4pHEAods9aRAdiq7Y5AeMJbg1vyWA== X-Received: by 2002:adf:df8b:: with SMTP id z11-v6mr2545937wrl.113.1538601954186; Wed, 03 Oct 2018 14:25:54 -0700 (PDT) Received: from localhost.localdomain ([141.226.14.107]) by smtp.gmail.com with ESMTPSA id 193-v6sm4073866wmj.21.2018.10.03.14.25.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 03 Oct 2018 14:25:53 -0700 (PDT) From: Amir Goldstein To: Jan Kara Cc: linux-fsdevel@vger.kernel.org Subject: [PATCH v3 5/8] fsnotify: convert runtime BUG_ON() to BUILD_BUG_ON() Date: Thu, 4 Oct 2018 00:25:36 +0300 Message-Id: <20181003212539.2384-6-amir73il@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181003212539.2384-1-amir73il@gmail.com> References: <20181003212539.2384-1-amir73il@gmail.com> 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 The BUG_ON() statements to verify number of bits in ALL_FSNOTIFY_BITS and ALL_INOTIFY_BITS are converted to build time check of the constant. Signed-off-by: Amir Goldstein --- fs/notify/fsnotify.c | 2 +- fs/notify/inotify/inotify_user.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/fs/notify/fsnotify.c b/fs/notify/fsnotify.c index 7391a02bf723..875975504409 100644 --- a/fs/notify/fsnotify.c +++ b/fs/notify/fsnotify.c @@ -395,7 +395,7 @@ static __init int fsnotify_init(void) { int ret; - BUG_ON(hweight32(ALL_FSNOTIFY_BITS) != 23); + BUILD_BUG_ON(HWEIGHT32(ALL_FSNOTIFY_BITS) != 23); ret = init_srcu_struct(&fsnotify_mark_srcu); if (ret) diff --git a/fs/notify/inotify/inotify_user.c b/fs/notify/inotify/inotify_user.c index ac6978d3208c..105576daca4a 100644 --- a/fs/notify/inotify/inotify_user.c +++ b/fs/notify/inotify/inotify_user.c @@ -815,7 +815,7 @@ static int __init inotify_user_setup(void) BUILD_BUG_ON(IN_ISDIR != FS_ISDIR); BUILD_BUG_ON(IN_ONESHOT != FS_IN_ONESHOT); - BUG_ON(hweight32(ALL_INOTIFY_BITS) != 22); + BUILD_BUG_ON(HWEIGHT32(ALL_INOTIFY_BITS) != 22); inotify_inode_mark_cachep = KMEM_CACHE(inotify_inode_mark, SLAB_PANIC|SLAB_ACCOUNT); From patchwork Wed Oct 3 21:25:37 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 10625331 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 2F0BC1515 for ; Wed, 3 Oct 2018 21:25:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2007E28FF9 for ; Wed, 3 Oct 2018 21:25:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 146E329087; Wed, 3 Oct 2018 21:25:58 +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,FREEMAIL_FROM,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 ACD2729080 for ; Wed, 3 Oct 2018 21:25:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726722AbeJDEQD (ORCPT ); Thu, 4 Oct 2018 00:16:03 -0400 Received: from mail-wm1-f68.google.com ([209.85.128.68]:37617 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725871AbeJDEQC (ORCPT ); Thu, 4 Oct 2018 00:16:02 -0400 Received: by mail-wm1-f68.google.com with SMTP id 185-v6so7007603wmt.2 for ; Wed, 03 Oct 2018 14:25:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=VubmMs8lPgeCW9ugJpKFb18KZPGzApJG7PlMPdpS+NA=; b=QkwPDqZR73AwjjVCZBkGoA1Qdta39LqPvfPhI7u0OxcyzLWykBnn8hBOCcLZ0HZp7i 0w3lDW+WKUC1L1SwxmLtNypJ+eof7vLhzbLED4CGcQeCWbSHS96c0Srsc/UTUswg4+xz u9DKNC8IqJjGBcd/Vz5NkSkSEKT68nnKn+8njpSEXYCyXieWgHmH3PwbzkdbbQHPIgeQ CsVOC1YJu2/FsN1cShFOgeS6e9SD5RIRFnhbgTQVCSC+N/LDjtITrai4uRJb7C2ZVe6M q8U4F2HFNs+f2qRRAZ/KN60Ll2+7GXze5Z8DPGMv1qC53D5CNcrUAHDRZtk3LaESJzqw TLUQ== 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; bh=VubmMs8lPgeCW9ugJpKFb18KZPGzApJG7PlMPdpS+NA=; b=PwU9od6Y6QsQAgFYoSqSoBujXk8Wr5hM9usVgpXqR09CY4KA6qygqVQx5d8oWrE4Ml /4/fxg3kByyJX4WDMtvfTpx/pepkLhO8WS4l5HXdw9QRiHNRsQPC4SE1SwMlJ2fltxIj OH9DcpzgK2Aa3Sj7Awc1w/32lP1FQCpw5/oGq/jza5mYkROFyXQUZsq/oLYicck5c70g w79AuYK51tYBDYx93anwak5dObqYQXtOIrkU40ZHK/PgHr5i67zBGrvbjeu/4HetI7DE 4JwIoL/j1bFDbjrjYpUCBpPJzisBAZSV6JyjRVTPjYnm2mOu1aPHbpjVEfJVE7Dmlh2S Uz4Q== X-Gm-Message-State: ABuFfoi0xtRIr2oz0F0uZYwoZpt+PgMXbMDZIiP5XxLg+A29f9E14i/u nup093dNi/V+IEq1MkCIaktdUsJv X-Google-Smtp-Source: ACcGV62Tgm6FbUCkWTFl6XnK21qjLTL3ExG8eQAzCOGBl22nOF+DDLgLf3bkYQfBs22yMZd3QIetXg== X-Received: by 2002:a1c:de88:: with SMTP id v130-v6mr2644647wmg.59.1538601955307; Wed, 03 Oct 2018 14:25:55 -0700 (PDT) Received: from localhost.localdomain ([141.226.14.107]) by smtp.gmail.com with ESMTPSA id 193-v6sm4073866wmj.21.2018.10.03.14.25.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 03 Oct 2018 14:25:54 -0700 (PDT) From: Amir Goldstein To: Jan Kara Cc: linux-fsdevel@vger.kernel.org Subject: [PATCH v3 6/8] fanotify: add BUILD_BUG_ON() to count the bits of fanotify constants Date: Thu, 4 Oct 2018 00:25:37 +0300 Message-Id: <20181003212539.2384-7-amir73il@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181003212539.2384-1-amir73il@gmail.com> References: <20181003212539.2384-1-amir73il@gmail.com> 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 Also define the FANOTIFY_EVENT_FLAGS consisting of the extra flags FAN_ONDIR and FAN_ON_CHILD. Signed-off-by: Amir Goldstein --- fs/notify/fanotify/fanotify.c | 2 ++ fs/notify/fanotify/fanotify_user.c | 5 ++++- include/linux/fanotify.h | 8 ++++++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/fs/notify/fanotify/fanotify.c b/fs/notify/fanotify/fanotify.c index 03498eb995be..361e3a0a445c 100644 --- a/fs/notify/fanotify/fanotify.c +++ b/fs/notify/fanotify/fanotify.c @@ -205,6 +205,8 @@ static int fanotify_handle_event(struct fsnotify_group *group, BUILD_BUG_ON(FAN_ACCESS_PERM != FS_ACCESS_PERM); BUILD_BUG_ON(FAN_ONDIR != FS_ISDIR); + BUILD_BUG_ON(HWEIGHT32(ALL_FANOTIFY_EVENT_BITS) != 10); + if (!fanotify_should_send_event(iter_info, mask, data, data_type)) return 0; diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c index 530e5e486105..14594e491d2b 100644 --- a/fs/notify/fanotify/fanotify_user.c +++ b/fs/notify/fanotify/fanotify_user.c @@ -803,7 +803,7 @@ static int do_fanotify_mark(int fanotify_fd, unsigned int flags, __u64 mask, struct fsnotify_group *group; struct fd f; struct path path; - u32 valid_mask = FANOTIFY_EVENTS | FAN_EVENT_ON_CHILD | FAN_ONDIR; + u32 valid_mask = FANOTIFY_EVENTS | FANOTIFY_EVENT_FLAGS; unsigned int mark_type = flags & FANOTIFY_MARK_TYPE_BITS; int ret; @@ -944,6 +944,9 @@ COMPAT_SYSCALL_DEFINE6(fanotify_mark, */ static int __init fanotify_user_setup(void) { + BUILD_BUG_ON(HWEIGHT32(FANOTIFY_INIT_FLAGS) != 6); + BUILD_BUG_ON(HWEIGHT32(FANOTIFY_MARK_FLAGS) != 9); + fanotify_mark_cache = KMEM_CACHE(fsnotify_mark, SLAB_PANIC|SLAB_ACCOUNT); fanotify_event_cachep = KMEM_CACHE(fanotify_event_info, SLAB_PANIC); diff --git a/include/linux/fanotify.h b/include/linux/fanotify.h index 4519b0988afe..afddd7e0d5a1 100644 --- a/include/linux/fanotify.h +++ b/include/linux/fanotify.h @@ -41,11 +41,19 @@ /* Events that require a permission response from user */ #define FANOTIFY_PERM_EVENTS (FAN_OPEN_PERM | FAN_ACCESS_PERM) +/* Extra flags that may be reported with event or control handling of events */ +#define FANOTIFY_EVENT_FLAGS (FAN_EVENT_ON_CHILD | FAN_ONDIR) + /* Events that may be reported to user */ #define FANOTIFY_OUTGOING_EVENTS (FANOTIFY_EVENTS | \ FANOTIFY_PERM_EVENTS | \ FAN_Q_OVERFLOW) +#define ALL_FANOTIFY_EVENT_BITS (FANOTIFY_EVENTS | \ + FANOTIFY_PERM_EVENTS | \ + FANOTIFY_EVENT_FLAGS | \ + FANOTIFY_OUTGOING_EVENTS) + /* Do not use these old uapi constants internally */ #undef FAN_ALL_CLASS_BITS #undef FAN_ALL_INIT_FLAGS From patchwork Wed Oct 3 21:25:38 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 10625333 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 1710C1731 for ; Wed, 3 Oct 2018 21:26:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0819129080 for ; Wed, 3 Oct 2018 21:26:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F09D32908A; Wed, 3 Oct 2018 21:26:00 +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,FREEMAIL_FROM,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 7CFB029080 for ; Wed, 3 Oct 2018 21:26:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726770AbeJDEQG (ORCPT ); Thu, 4 Oct 2018 00:16:06 -0400 Received: from mail-wm1-f66.google.com ([209.85.128.66]:40623 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725871AbeJDEQF (ORCPT ); Thu, 4 Oct 2018 00:16:05 -0400 Received: by mail-wm1-f66.google.com with SMTP id z204-v6so6158072wmc.5 for ; Wed, 03 Oct 2018 14:25:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=Of+1832wB5nEvkGcr3xBQ2mHK0QBsVUpt4R7Z1J/Nes=; b=f5mX66jjLEfD6/Xs1Oep2XnA6OVMxGkaO4kzMqSnCHK2J1VeRUcNvkMc3ky1YjAlME agaDAyWzHTt782SjR6kz0dGx3Scy/3H3+yDoUQuIvC7CNj3VZg51/SJGf1ZH4Vz50OYB E7mCGG1YPMqmwGBizPH5LLj2QmBz5lAsXBYuC9y8UNtpSTNDjOe1xMDBEMcJdzk9GWKH uJqjYoPWf7R4tZbTkaqo20LKmv0O5PR4hElk3J9P/rBOYWT2FJwPFTk2cMVfBmPdm+/3 s/X5ZWoJ3R/6b04bSbcGDWiph2OPODk0mqnR+zZqUQdMswPypqHSn5EyXf7EFyiArqjy BKKA== 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; bh=Of+1832wB5nEvkGcr3xBQ2mHK0QBsVUpt4R7Z1J/Nes=; b=FoTTZVRtDWeIBCWLvybxzwAWHGssEuc/jOydLksbEwUUh/LD/cDSzo7rU7X88/4v0H 7+MU8mykC/qvgJ24TnUYkgaszBJABfjKeuuq0NvfESEgB4t2zmW0q1eUUh8UWBdukhGD O+KT56syQFz7FSXSDB85+N6qWpdBOcAs0FE+4hUNzooo4GGdpem/WAvFL1JQKCVsCHRI wCqu+RL3PBe+3uSnaTPOIJoGo4Ra4lRpuZvrdGAugJKaEoHFNeYvVcHUnW4uP4l0lo8a og0wlLQiP2/qaMY7dWo4dZXyu42yjMQqxHuGWOIjdhhEFZregUzMGOGtBqJSE/2EzKsw Bh/Q== X-Gm-Message-State: ABuFfogCLnuYYQYyVXe5+29lMbkUYb/zeI6wN7O7C06p29x1kswHEMVv h4FrfjMLk6J8PCP4/mEYAuzS9Vty X-Google-Smtp-Source: ACcGV60RKnY1m78lUYx4L6REw3WdyNeP7eOQ3XpuRs3TmiC8ljAMboQVolujaqwsEmQxjMSoDljRPw== X-Received: by 2002:a7b:c150:: with SMTP id z16-v6mr2725232wmi.25.1538601956473; Wed, 03 Oct 2018 14:25:56 -0700 (PDT) Received: from localhost.localdomain ([141.226.14.107]) by smtp.gmail.com with ESMTPSA id 193-v6sm4073866wmj.21.2018.10.03.14.25.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 03 Oct 2018 14:25:55 -0700 (PDT) From: Amir Goldstein To: Jan Kara Cc: linux-fsdevel@vger.kernel.org, nixiaoming Subject: [PATCH v3 7/8] fanotify: support reporting thread id instead of process id Date: Thu, 4 Oct 2018 00:25:38 +0300 Message-Id: <20181003212539.2384-8-amir73il@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181003212539.2384-1-amir73il@gmail.com> References: <20181003212539.2384-1-amir73il@gmail.com> 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 In order to identify which thread triggered the event in a multi-threaded program, add the FAN_EVENT_INFO_TID flag in fanotify_init to opt-in for reporting the event creator's thread id information. Signed-off-by: nixiaoming Signed-off-by: Amir Goldstein --- fs/notify/fanotify/fanotify.c | 9 ++++++--- fs/notify/fanotify/fanotify.h | 2 +- fs/notify/fanotify/fanotify_user.c | 4 ++-- include/linux/fanotify.h | 3 +++ include/uapi/linux/fanotify.h | 3 +++ 5 files changed, 15 insertions(+), 6 deletions(-) diff --git a/fs/notify/fanotify/fanotify.c b/fs/notify/fanotify/fanotify.c index 361e3a0a445c..2c57186caa2e 100644 --- a/fs/notify/fanotify/fanotify.c +++ b/fs/notify/fanotify/fanotify.c @@ -25,7 +25,7 @@ static bool should_merge(struct fsnotify_event *old_fsn, old = FANOTIFY_E(old_fsn); new = FANOTIFY_E(new_fsn); - if (old_fsn->inode == new_fsn->inode && old->tgid == new->tgid && + if (old_fsn->inode == new_fsn->inode && old->pid == new->pid && old->path.mnt == new->path.mnt && old->path.dentry == new->path.dentry) return true; @@ -171,7 +171,10 @@ struct fanotify_event_info *fanotify_alloc_event(struct fsnotify_group *group, goto out; init: __maybe_unused fsnotify_init_event(&event->fse, inode, mask); - event->tgid = get_pid(task_tgid(current)); + if (FAN_GROUP_FLAG(group, FAN_EVENT_INFO_TID)) + event->pid = get_pid(task_pid(current)); + else + event->pid = get_pid(task_tgid(current)); if (path) { event->path = *path; path_get(&event->path); @@ -270,7 +273,7 @@ static void fanotify_free_event(struct fsnotify_event *fsn_event) event = FANOTIFY_E(fsn_event); path_put(&event->path); - put_pid(event->tgid); + put_pid(event->pid); if (fanotify_is_perm_event(fsn_event->mask)) { kmem_cache_free(fanotify_perm_event_cachep, FANOTIFY_PE(fsn_event)); diff --git a/fs/notify/fanotify/fanotify.h b/fs/notify/fanotify/fanotify.h index 88a8290a61cb..ea05b8a401e7 100644 --- a/fs/notify/fanotify/fanotify.h +++ b/fs/notify/fanotify/fanotify.h @@ -19,7 +19,7 @@ struct fanotify_event_info { * during this object's lifetime */ struct path path; - struct pid *tgid; + struct pid *pid; }; /* diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c index 14594e491d2b..e03be5071362 100644 --- a/fs/notify/fanotify/fanotify_user.c +++ b/fs/notify/fanotify/fanotify_user.c @@ -132,7 +132,7 @@ static int fill_event_metadata(struct fsnotify_group *group, metadata->vers = FANOTIFY_METADATA_VERSION; metadata->reserved = 0; metadata->mask = fsn_event->mask & FANOTIFY_OUTGOING_EVENTS; - metadata->pid = pid_vnr(event->tgid); + metadata->pid = pid_vnr(event->pid); if (unlikely(fsn_event->mask & FAN_Q_OVERFLOW)) metadata->fd = FAN_NOFD; else { @@ -944,7 +944,7 @@ COMPAT_SYSCALL_DEFINE6(fanotify_mark, */ static int __init fanotify_user_setup(void) { - BUILD_BUG_ON(HWEIGHT32(FANOTIFY_INIT_FLAGS) != 6); + BUILD_BUG_ON(HWEIGHT32(FANOTIFY_INIT_FLAGS) != 7); BUILD_BUG_ON(HWEIGHT32(FANOTIFY_MARK_FLAGS) != 9); fanotify_mark_cache = KMEM_CACHE(fsnotify_mark, diff --git a/include/linux/fanotify.h b/include/linux/fanotify.h index afddd7e0d5a1..05b696b4856b 100644 --- a/include/linux/fanotify.h +++ b/include/linux/fanotify.h @@ -18,7 +18,10 @@ #define FANOTIFY_CLASS_BITS (FAN_CLASS_NOTIF | FAN_CLASS_CONTENT | \ FAN_CLASS_PRE_CONTENT) +#define FANOTIFY_EVENT_INFO_FLAGS (FAN_EVENT_INFO_TID) + #define FANOTIFY_INIT_FLAGS (FANOTIFY_CLASS_BITS | \ + FANOTIFY_EVENT_INFO_FLAGS | \ FAN_CLOEXEC | FAN_NONBLOCK | \ FAN_UNLIMITED_QUEUE | FAN_UNLIMITED_MARKS) diff --git a/include/uapi/linux/fanotify.h b/include/uapi/linux/fanotify.h index d0c05de670ef..00b2304ed124 100644 --- a/include/uapi/linux/fanotify.h +++ b/include/uapi/linux/fanotify.h @@ -40,6 +40,9 @@ #define FAN_UNLIMITED_MARKS 0x00000020 #define FAN_ENABLE_AUDIT 0x00000040 +/* Flags to determine fanotify event format */ +#define FAN_EVENT_INFO_TID 0x00000100 /* event->pid is thread id */ + /* Deprecated - do not use this in programs and do not add new flags here! */ #define FAN_ALL_INIT_FLAGS (FAN_CLOEXEC | FAN_NONBLOCK | \ FAN_ALL_CLASS_BITS | FAN_UNLIMITED_QUEUE |\ From patchwork Wed Oct 3 21:25:39 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 10625335 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 B9F751731 for ; Wed, 3 Oct 2018 21:26:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AB2D128FF9 for ; Wed, 3 Oct 2018 21:26:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9F86D29087; Wed, 3 Oct 2018 21:26:01 +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,FREEMAIL_FROM,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 3E91D28FF9 for ; Wed, 3 Oct 2018 21:26:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726840AbeJDEQG (ORCPT ); Thu, 4 Oct 2018 00:16:06 -0400 Received: from mail-wm1-f65.google.com ([209.85.128.65]:53292 "EHLO mail-wm1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726730AbeJDEQG (ORCPT ); Thu, 4 Oct 2018 00:16:06 -0400 Received: by mail-wm1-f65.google.com with SMTP id b19-v6so7061509wme.3 for ; Wed, 03 Oct 2018 14:25:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=WJ7ONiEM5USfpIMIZ0NsRrcFmQplKm8MWJZ3PZDI0Tk=; b=g8c6412p4F9rNLmsG9NI3xEmfnQy13H1tM488cRSzjtNDeoQO2x2L/rbW7VGFtKtCM q941X6yhb4o70HzEj7i3kU5lkP9JrTF+xrSJ5MBNVgJXssmMxXCzFaJyrbPtSV/ETuFt jmTKpj/RcJaL0iC73UL95wIROAgbkz1cmxtrhbspDaKStrVAObRLDbooFidZj73sFSog AzBaJLRslvV5bwbMxmPd7+Xtaoh172bUck4WNoOVegCrFwi8Zl1kJh/BG16EEu8g8Lef lD/MRd3ZOSGy24SxWtvbio9nWqccf9E3Y7H64gZ+bcg+2dRSiDXC/KX+Md4NiGezlv+z Rsvw== 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; bh=WJ7ONiEM5USfpIMIZ0NsRrcFmQplKm8MWJZ3PZDI0Tk=; b=BV/6vCVjlYFz24aXBTOIy/I2lTjJdOgh8pUrbVTp2YzGu4Iy6WDqZ5npczdb7D7QEC n4Zjt/3mlRnbXrid9wvsbsPd025tFuYIZRWxxh3xlUA9YPsum0m+xCLbV9FTVCcsN1+l vhbzOYqD6YGRiGQBisifQJ5eeDb4/Sqo3jV8TvwyOrASJPJh97V50hiadv3yRMB5MNIQ RnMrvT8rbLTYqsTJ+Gs++xYSNTxJphJZMIOwpFIiwdLqwmMASLHUDnZOfctqRqzdhRhD mG1pfEJXvXGFDSOWXmjCAxrtWHZHdF+jHmS99yZC+qrNHJ2qtcMdGndWrVKnPrjBYEOx kGMw== X-Gm-Message-State: ABuFfohdnFh8YrrHu47AodQ8EMMQBpls3qTHd82pwoTMcELxZDSdjCXf DrGBcw0mMs80B5C6xTOZ8+GHBoXz X-Google-Smtp-Source: ACcGV63QWo7jfX7j4AK3gyyaYMPQgOflZ26Aq7p57XfjpnbhE4Lur1TpKd86qA2oYA9uzO+nshbrRg== X-Received: by 2002:a1c:c444:: with SMTP id u65-v6mr2781803wmf.10.1538601957703; Wed, 03 Oct 2018 14:25:57 -0700 (PDT) Received: from localhost.localdomain ([141.226.14.107]) by smtp.gmail.com with ESMTPSA id 193-v6sm4073866wmj.21.2018.10.03.14.25.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 03 Oct 2018 14:25:57 -0700 (PDT) From: Amir Goldstein To: Jan Kara Cc: linux-fsdevel@vger.kernel.org Subject: [PATCH v3 8/8] fsnotify: optimize away srcu_read_lock() for events on directories Date: Thu, 4 Oct 2018 00:25:39 +0300 Message-Id: <20181003212539.2384-9-amir73il@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181003212539.2384-1-amir73il@gmail.com> References: <20181003212539.2384-1-amir73il@gmail.com> 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 inotify and dnotify are always interested in events on directories. fanotify is interested in events on directories only if user requested them by flag FAN_ONDIR. For the fanotify supported events on directories (open/access/close), if there is no inotify/dnotify associated marks and if none of the associated fanotify marks have the FS_ISDIR flag, we can skip iterating the marks and we avoid taking the srcu_read_lock() for all events on directories. In order to enable this check in fsnotify() we set the FS_ISDIR flag explicitly on all dnotify/inotify marks. Signed-off-by: Amir Goldstein --- fs/notify/dnotify/dnotify.c | 5 +++-- fs/notify/fsnotify.c | 9 ++++++++- fs/notify/inotify/inotify_user.c | 4 ++-- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/fs/notify/dnotify/dnotify.c b/fs/notify/dnotify/dnotify.c index 58d77dc696eb..55f0ae5fe0ba 100644 --- a/fs/notify/dnotify/dnotify.c +++ b/fs/notify/dnotify/dnotify.c @@ -89,7 +89,7 @@ static int dnotify_handle_event(struct fsnotify_group *group, struct dnotify_struct *dn; struct dnotify_struct **prev; struct fown_struct *fown; - __u32 test_mask = mask & ~FS_EVENT_ON_CHILD; + __u32 test_mask = mask & ALL_FSNOTIFY_EVENTS; /* not a dir, dnotify doesn't care */ if (!S_ISDIR(inode->i_mode)) @@ -197,7 +197,8 @@ void dnotify_flush(struct file *filp, fl_owner_t id) /* this conversion is done only at watch creation */ static __u32 convert_arg(unsigned long arg) { - __u32 new_mask = FS_EVENT_ON_CHILD; + /* Interested in events on children including subdirs */ + __u32 new_mask = FS_EVENT_ON_CHILD | FS_ISDIR; if (arg & DN_MULTISHOT) new_mask |= FS_DN_MULTISHOT; diff --git a/fs/notify/fsnotify.c b/fs/notify/fsnotify.c index 875975504409..a0ad06285450 100644 --- a/fs/notify/fsnotify.c +++ b/fs/notify/fsnotify.c @@ -332,9 +332,16 @@ int fsnotify(struct inode *to_tell, __u32 mask, const void *data, int data_is, __u32 test_mask = (mask & ALL_FSNOTIFY_EVENTS); if (data_is == FSNOTIFY_EVENT_PATH) { - mnt = real_mount(((const struct path *)data)->mnt); + const struct path *path = data; + + mnt = real_mount(path->mnt); sb = mnt->mnt.mnt_sb; mnt_or_sb_mask = mnt->mnt_fsnotify_mask | sb->s_fsnotify_mask; + + /* Is anybody is interested in events on directories? */ + if (d_is_dir(path->dentry) && + !(FS_ISDIR & (to_tell->i_fsnotify_mask | mnt_or_sb_mask))) + return 0; } /* diff --git a/fs/notify/inotify/inotify_user.c b/fs/notify/inotify/inotify_user.c index 105576daca4a..8d163b96a86a 100644 --- a/fs/notify/inotify/inotify_user.c +++ b/fs/notify/inotify/inotify_user.c @@ -91,9 +91,9 @@ static inline __u32 inotify_arg_to_mask(u32 arg) /* * everything should accept their own ignored, cares about children, - * and should receive events when the inode is unmounted + * directories, and should receive events when the inode is unmounted. */ - mask = (FS_IN_IGNORED | FS_EVENT_ON_CHILD | FS_UNMOUNT); + mask = (FS_IN_IGNORED | FS_EVENT_ON_CHILD | FS_ISDIR | FS_UNMOUNT); /* mask off the flags used to open the fd */ mask |= (arg & (IN_ALL_EVENTS | IN_ONESHOT | IN_EXCL_UNLINK));