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=-23.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_IN_DEF_DKIM_WL 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 86AEDC433B4 for ; Tue, 20 Apr 2021 01:35:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 67FB5613AC for ; Tue, 20 Apr 2021 01:35:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229875AbhDTBgY (ORCPT ); Mon, 19 Apr 2021 21:36:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51414 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229699AbhDTBgX (ORCPT ); Mon, 19 Apr 2021 21:36:23 -0400 Received: from mail-pj1-x1036.google.com (mail-pj1-x1036.google.com [IPv6:2607:f8b0:4864:20::1036]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BC79FC061763 for ; Mon, 19 Apr 2021 18:35:52 -0700 (PDT) Received: by mail-pj1-x1036.google.com with SMTP id lt13so10105008pjb.1 for ; Mon, 19 Apr 2021 18:35:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=eVivNCAEGUtIZChmB441G4IvsrobxBqjmpKfkg3ZBEk=; b=grJ7DVi57J0SaIJWOaPF8sXgyFe+vVrdEyBcKgBfsvtLsPY61oHKYPjDUKEolHMRRb Xsj5Q+xBdF2JpCfkh4kPQKdcO9FY1hGv6yCS0uvxNya12Jvs8F4ZUBtLj7rtONRnerdN FlB0gmP1KiHPFgVPjeynUSp+7yoES7DvuTL8hZCGKadIMYxtMNAjkmS4hUWqK4TX9FWf byNyUyA+77y8g+dC+OsmyUsqMntNg2ucwdmzse9H8kRmtoy8+XHc69c+7Ac6D4Mj1LYJ MCcpOEqVfLlD0wfOksPK/7kDfWrr3DDBAYjPDbPca/LlpOiGr7RRopeVfPEhop2KG2MP MDHA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=eVivNCAEGUtIZChmB441G4IvsrobxBqjmpKfkg3ZBEk=; b=dm9wKcfNjMvX4JvReueY8iGVvsS09XjdTF5CEMfwblIHdj3kdxxm+qEX6vrunpWlqv SKsTvAV3JC0krAS/DIhtO7bQSW+o6I9J7gVbS6mgR021bR5uyuqQkmiyga94/srBCpup vVFzaaXeMJE3Uz/jpSsCRYcjhWMFK1QLwtL0Z30DA/rhXuN/awb/sFpvIixlvyidOCRS TqeIf63Zub8ed3muri26PlHWr15U4R+YUvTANPXlBpM+Vo5of5ahyjvFZyma0tYXIDnK cGhKsfePI9SHMe0eR5t7+6pSN8uWyYpbgioHWb1BxPjx9cSBwrGb4gFodOlLPGubSDfT yT3g== X-Gm-Message-State: AOAM5307rrUxgt09BLNiyyOX97MRp4U9v4QiaGCeveprggXe/8PDoLAz qRUTn2/nw9+lRJbjFKOP1y4SUA== X-Google-Smtp-Source: ABdhPJyelHplD4uxiUo1PCbwBtzL2HFMEzpwg1oHLv4pc0yVWWKsLcX4TDhlPnLQxbpW1PE1NSTMWg== X-Received: by 2002:a17:902:a988:b029:eb:679:462b with SMTP id bh8-20020a170902a988b02900eb0679462bmr26251625plb.67.1618882552050; Mon, 19 Apr 2021 18:35:52 -0700 (PDT) Received: from google.com ([2401:fa00:9:211:3810:ca7:eb2a:d336]) by smtp.gmail.com with ESMTPSA id ft3sm603136pjb.54.2021.04.19.18.35.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Apr 2021 18:35:51 -0700 (PDT) Date: Tue, 20 Apr 2021 11:35:39 +1000 From: Matthew Bobrowski To: Jan Kara Cc: amir73il@gmail.com, christian.brauner@ubuntu.com, linux-api@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: Re: [PATCH 2/2] fanotify: Add pidfd support to the fanotify API Message-ID: References: <20210419102139.GD8706@quack2.suse.cz> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210419102139.GD8706@quack2.suse.cz> Precedence: bulk List-ID: X-Mailing-List: linux-api@vger.kernel.org On Mon, Apr 19, 2021 at 12:21:39PM +0200, Jan Kara wrote: > On Fri 16-04-21 09:22:25, Matthew Bobrowski wrote: > > Introduce a new flag FAN_REPORT_PIDFD for fanotify_init(2) which > > allows userspace applications to control whether a pidfd is to be > > returned instead of a pid for `struct fanotify_event_metadata.pid`. > > > > FAN_REPORT_PIDFD is mutually exclusive with FAN_REPORT_TID as the > > pidfd API is currently restricted to only support pidfd generation for > > thread-group leaders. Attempting to set them both when calling > > fanotify_init(2) will result in -EINVAL being returned to the > > caller. As the pidfd API evolves and support is added for tids, this > > is something that could be relaxed in the future. > > > > If pidfd creation fails, the pid in struct fanotify_event_metadata is > > set to FAN_NOPIDFD(-1). Falling back and providing a pid instead of a > > pidfd on pidfd creation failures was considered, although this could > > possibly lead to confusion and unpredictability within userspace > > applications as distinguishing between whether an actual pidfd or pid > > was returned could be difficult, so it's best to be explicit. > > > > Signed-off-by: Matthew Bobrowski > Overall this looks OK to me. Just one style nit & one question below in > addition to what Amir wrote. Thanks for the quick review Jan! > > --- > > fs/notify/fanotify/fanotify_user.c | 33 +++++++++++++++++++++++++++--- > > include/linux/fanotify.h | 2 +- > > include/uapi/linux/fanotify.h | 2 ++ > > 3 files changed, 33 insertions(+), 4 deletions(-) > > > > diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c > > index 9e0c1afac8bd..fd8ae88796a8 100644 > > --- a/fs/notify/fanotify/fanotify_user.c > > +++ b/fs/notify/fanotify/fanotify_user.c > > @@ -329,7 +329,7 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group, > > struct fanotify_info *info = fanotify_event_info(event); > > unsigned int fid_mode = FAN_GROUP_FLAG(group, FANOTIFY_FID_BITS); > > struct file *f = NULL; > > - int ret, fd = FAN_NOFD; > > + int ret, pidfd, fd = FAN_NOFD; > > int info_type = 0; > > > > pr_debug("%s: group=%p event=%p\n", __func__, group, event); > > @@ -340,7 +340,25 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group, > > metadata.vers = FANOTIFY_METADATA_VERSION; > > metadata.reserved = 0; > > metadata.mask = event->mask & FANOTIFY_OUTGOING_EVENTS; > > - metadata.pid = pid_vnr(event->pid); > > + > > + if (FAN_GROUP_FLAG(group, FAN_REPORT_PIDFD) && > > + pid_has_task(event->pid, PIDTYPE_TGID)) { > > Please align the rest of the condition to the opening brace. I.e., like: > > if (FAN_GROUP_FLAG(group, FAN_REPORT_PIDFD) && > pid_has_task(event->pid, PIDTYPE_TGID)) { ACK. > BTW, why is the pid_has_task() check here? My thought was that we add a means of ensuring that event->pid holds a reference to a thread-group leader as pidfds aren't supported for individual threads just yet. The same check is implemented in pidfd_open(), so I thought to make the preliminary checks consistent. Actually, now that I've writeten that, perhaps the pid_has_task() check can be rolled up into pidfd_create()? > And why is it OK to fall back to returning pid if pid_has_task() is > false? Ah, I see, it's not OK. Good catch Jan! I will need to fix this up in the follow up series. /M