From patchwork Mon Mar 27 18:22:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Brauner X-Patchwork-Id: 7283 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1711039vqo; Mon, 27 Mar 2023 11:32:22 -0700 (PDT) X-Google-Smtp-Source: AKy350aNJfNyCS9Pe4ZXZfRhG1XACH2vxj/mZEer8cGr/ntvkNjBGCUXNwS1QUApQJvcA1lyp5Yv X-Received: by 2002:a17:906:9512:b0:92f:1418:27f0 with SMTP id u18-20020a170906951200b0092f141827f0mr13914540ejx.34.1679941942433; Mon, 27 Mar 2023 11:32:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679941942; cv=none; d=google.com; s=arc-20160816; b=J2T2w9vmV6q+/PFTsfPoRJyFbTFW+m3fiDYfrBgqlBs+uQ7dbT+U3WMxINIW86WF/j /jaIPlfw96+31QfM6RPweAAT+OjSlWkRQ3iJG8BxsU6dsJwix5bqWsGRZd8FvlDf5o27 c2+MeJsi/LlUPvYz4u/3uSrtA0f8KVgEnh3SziNa21X3WxJPYYvwEbGxLTMeIDJU6ken bcuvBrgPfQf8Xc9ZPhkqbXRv6POeKhI/LWeNwyRaiO6ZvU9VST9donogIlMmjxP09YLR nUg4xKdAYdUP7FROFvLcuw5hAiiGLzeoKrOgghZ5UoD4nLhwVPmwyLKRgqtd7fiVaHCG P8ug== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:content-transfer-encoding:mime-version :message-id:date:subject:from:dkim-signature; bh=ix9mqBdZ2ltEAdOhrMX4KrDDYquYzmJ1PhCOdqSe/kY=; b=Ts2wblXB3uKlMq+UiwnMRlsfoKRX2Kcehio4S/f4J5zelqRjR6rRczzZIxxAaBGbQx lVRDxWUL1SJzFmDqLLid2JOtOvgfmntF9iEOI/1FlC9i9bbzwllzPnSE9G1zgQXTve6F zpZthJo3nt8hmHhL8p8pAANk44X9gclzO6eA6c7mQ4PYxPkl32ffjuFIRh0G1vyDVzaR SMH3hj8MdO45Z/sgTLsOY5NlUWoenbMxqt4u230ehBMvLAgVJ2qBBUizNkiwHp1Ru9lL dHWBnS58ZMlwTavr888RqSCJiRitmdT5Ve1JRCI7ZD88wkEr7nqvcECpsGwSS567/VhY c2lw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=BQRGKboN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id cx18-20020a170906c81200b0092be625bf1dsi26540404ejb.826.2023.03.27.11.31.58; Mon, 27 Mar 2023 11:32:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=BQRGKboN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232019AbjC0SXE (ORCPT + 99 others); Mon, 27 Mar 2023 14:23:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33788 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229479AbjC0SXC (ORCPT ); Mon, 27 Mar 2023 14:23:02 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D65A42D4F; Mon, 27 Mar 2023 11:23:01 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 83B22B816D6; Mon, 27 Mar 2023 18:23:00 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A5A61C433EF; Mon, 27 Mar 2023 18:22:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1679941379; bh=OqeOKOE1wERV1W7qLi4nymfleT0u4Hl2VHEg6Hh+1/0=; h=From:Subject:Date:To:Cc:From; b=BQRGKboNv6ZIi2V2OtSnsz3oHYDGIjuT117tRJJTAsNK73Q5WKlxMfDjJzA9rHDZZ +tjVwMp6CAHHj7QrFbusmkLhD5xGETpfYC3hPN5xiunwx4+YE1bczghD8677ChtxJF U9Dilalz9H3b0lgEAqKAhndC0jyq4eTkYEQRB2SDUDxQC4YCkyy7eHKBP/bsxOOU+B /SbRZg/HuCpq42tbxs4+bNhwLJxy3VIs7YuUCO7MaYctY8NfU1qNJAg3NGS4JuXnq3 ouY0pnpV+0uxwPNVFCd4SvIi4DoObtnLFZ9vG0NHHYoxtv5ekDjoP7WZmFGrtMG7U7 IAvRmUsPjyuxw== From: Christian Brauner Subject: [PATCH 0/3] pidfd: add pidfd_prepare() Date: Mon, 27 Mar 2023 20:22:50 +0200 Message-Id: <20230327-pidfd-file-api-v1-0-5c0e9a3158e4@kernel.org> MIME-Version: 1.0 X-B4-Tracking: v=1; b=H4sIAPreIWQC/x2NQQrCMBAAv1L27JaYSI1+RTxsko1d0Bg2UoTSv 5t6HJhhVmiswg2uwwrKizR5lw7HwwBxpvJglNQZrLHOOHvGKiknzPJkpCrog/Vp8jEbukCPAjX GoFTivGcvah/WcZlGhxpPu1GVs3z/y9t9237oUI/4ggAAAA== To: linux-fsdevel@vger.kernel.org Cc: Jan Kara , Amir Goldstein , Matthew Bobrowski , linux-kernel@vger.kernel.org, Christian Brauner X-Mailer: b4 0.13-dev-00303 X-Developer-Signature: v=1; a=openpgp-sha256; l=1220; i=brauner@kernel.org; h=from:subject:message-id; bh=OqeOKOE1wERV1W7qLi4nymfleT0u4Hl2VHEg6Hh+1/0=; b=owGbwMvMwCU28Zj0gdSKO4sYT6slMaQo3me4qf7wrMVXPy/RsrPtrPp50ZKre3LeJaWXmvRpquwv Lb/YUcrCIMbFICumyOLQbhIut5ynYrNRpgbMHFYmkCEMXJwCMBGODQz/FK1Ld8zy+n+95nnEY7fvDy pysi/YSD3SWSZkH5guVCQmw8jwYwu79bT5l91unjqYu2ra2b8Xt8mVHemYdb7X+NqE5lMXuAE= X-Developer-Key: i=brauner@kernel.org; a=openpgp; fpr=4880B8C9BD0E5106FC070F4F7B3C391EFEA93624 X-Spam-Status: No, score=-5.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI,SPF_HELO_NONE, SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1761546802359089735?= X-GMAIL-MSGID: =?utf-8?q?1761546802359089735?= This adds the pidfd_prepare() helper which allows the caller to reserve a pidfd number and allocates a new pidfd file that stashes the provided struct pid. This will allow us to remove places that either open code this functionality e.g., during copy_process() or that currently call pidfd_create() but then have to call close_fd() because there are still failure points after pidfd_create() has been called. Other functionality wants to make use of pidfd's as well and they need a pidfd_prepare() internal api as well. I've tested the fanotify and fork changes via LTP which provides coverage for all the affected codepaths. Signed-off-by: Christian Brauner --- Christian Brauner (3): pid: add pidfd_prepare() fork: use pidfd_prepare() fanotify: use pidfd_prepare() fs/notify/fanotify/fanotify_user.c | 13 ++++--- include/linux/pid.h | 1 + kernel/fork.c | 12 +------ kernel/pid.c | 69 +++++++++++++++++++++++++++++++------- 4 files changed, 68 insertions(+), 27 deletions(-) --- base-commit: 197b6b60ae7bc51dd0814953c562833143b292aa change-id: 20230327-pidfd-file-api-8b28d68cf0a9