From patchwork Fri Apr 21 13:41:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Brauner X-Patchwork-Id: 86319 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1080326vqo; Fri, 21 Apr 2023 06:49:28 -0700 (PDT) X-Google-Smtp-Source: AKy350Z4mPx7bPxOiN2IHTKgM11x6mtNCFLefWXsL36bAhFd4VVOVZhiCIZJ0+OhB3biAsffSueR X-Received: by 2002:a17:90b:190:b0:24b:27e1:92fc with SMTP id t16-20020a17090b019000b0024b27e192fcmr5021882pjs.44.1682084967979; Fri, 21 Apr 2023 06:49:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682084967; cv=none; d=google.com; s=arc-20160816; b=F+NHQHStf4VGNloLlmFHgARt1nSVrUed1uIIO1OPEr1qJ4r1iLwcdoOmNstYO0/B9R 2qeW4Ka1b/BlmXUrBBckFtdFktoqw2NZc73ygZJiod01Y04j+xNqqEN70UV+3Gu63OV7 hDMjE3DBHKVFgKuS+fl3dmsTcJJEZm6G5EZEAqt4GyCoRHkvXjbQTaZPJS/FXVWEQH4F sy7iv4fIA5k+SHWUQufdpeUrNtfzIBFw4i7RQxflJRTTbHNDquhPYHn39dqsC9sbmQB0 I5Yuny42ScTOV/oE7qSIkbaIJz4Ev+eIbwaMmOeZV3BpdXZm6GPZcPJsuKiCJcg2p1tZ M3iw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=Pd7NFu8o9BL7AClYLIT0MTRySF/7BKRzAhMvG16bp+M=; b=m0+WxwbycN1RWHO4mp37UlGq4F5BeavOjF+6Uk/J0VY8oTFcTPCE3mKU+fhkSxB1nJ R9mnPMs53SHkiAi0F3fYOGT1K8BG9i2xacrudKYDTb5x1s+9tr1RtQiROMRMzCSpQYlj bDFvATezW+WRGUpYJBooc+YrLQ8LPdx/KBIKc3cbRk4wphsNpLd9hFc11deR25QxOefT f3DE5rajmgfyqTWYFB5QbXT6Zs27upyrXaXVdYFIObd0tuB/cS0BjNkQ5EVC5dlX09tn 8L819QKhxRNr6S7Xfg0VtWiJA+3yIK2d7BlhUcVYVabFI07GABXcSrVC+ljN8jeQfEQi 9rrA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=JNn1DqAb; 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 lp7-20020a17090b4a8700b00240263ef11bsi5205306pjb.120.2023.04.21.06.49.14; Fri, 21 Apr 2023 06:49:27 -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=JNn1DqAb; 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 S232438AbjDUNnQ (ORCPT + 99 others); Fri, 21 Apr 2023 09:43:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58922 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232422AbjDUNmt (ORCPT ); Fri, 21 Apr 2023 09:42:49 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 201861386C; Fri, 21 Apr 2023 06:42:13 -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 dfw.source.kernel.org (Postfix) with ESMTPS id 27E7A616E9; Fri, 21 Apr 2023 13:42:02 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 32791C433EF; Fri, 21 Apr 2023 13:42:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1682084521; bh=jsN16Cs8YsE77h9jjLEg6GRIme2CQpBrwqLQqDJd2TQ=; h=From:To:Cc:Subject:Date:From; b=JNn1DqAbNx/sCs/osw5eIeOedCZVdloVIQo9EhPsYfTNj3HmFkVv/m43vOH5beif6 vaYLCAtdjcIF6mod/8BpKqSg7Dqhpvs9L0+UH68IZ8RGWVv6AdrDEDANMd/x+AdRKL 5nwqm4HJRu9y3RLi2PY/NVlciFSQv0+fhS02th9Jw7yMru8lHNc5VSM8tyBN61dCA+ usXloyPOuciyHmpABQk8tKSykCsGT8r1MKlaILdk+5zdmIIDso+C8xWz1gfWArJw8V k6qsAopG5fhOlg+QqbjyXJHiR0toLNZCoYbk6RkXQ+c4ntim1hKzj1XLPforMFlEJH SmC/QhxcC0cbQ== From: Christian Brauner To: Linus Torvalds Cc: Christian Brauner , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [GIT PULL] pidfd updates Date: Fri, 21 Apr 2023 15:41:10 +0200 Message-Id: <20230421-kurstadt-stempeln-3459a64aef0c@brauner> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2760; i=brauner@kernel.org; h=from:subject:message-id; bh=jsN16Cs8YsE77h9jjLEg6GRIme2CQpBrwqLQqDJd2TQ=; b=owGbwMvMwCU28Zj0gdSKO4sYT6slMaQ4Tfy1OuXJjEcvXBwfnbry4m3250vnTTL4LSOr/1+12yez fOLeix2lLAxiXAyyYoosDu0m4XLLeSo2G2VqwMxhZQIZwsDFKQATsZNi+O8YtvTPjkVFjsvevOw6c3 pTt8G639cM+X7t77yZKH/UKTaPkeGL1hPBYuHrt37ePcE6wdp4Rc+ilPR3kgd3eRWuW/9mfTQHAA== X-Developer-Key: i=brauner@kernel.org; a=openpgp; fpr=4880B8C9BD0E5106FC070F4F7B3C391EFEA93624 X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham 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?1763793927491662184?= X-GMAIL-MSGID: =?utf-8?q?1763793927491662184?= Hey Linus, /* Summary */ This adds a new pidfd_prepare() helper which allows the caller to reserve a pidfd number and allocates a new pidfd file that stashes the provided struct pid. It should be avoided installing a file descriptor into a task's file descriptor table just to close it again via close_fd() in case an error occurs. The fd has been visible to userspace and might already be in use. Instead, a file descriptor should be reserved but not installed into the caller's file descriptor table. If another failure path is hit then the reserved file descriptor and file can just be put without any userspace visible side-effects. And if all failure paths are cleared the file descriptor and file can be installed into the task's file descriptor table. This helper is now used in all places that open coded this functionality before. For example, this is currently done during copy_process() and fanotify used pidfd_create(), which returns a pidfd that has already been made visibile in the caller's file descriptor table, but then closed it using close_fd(). In one of the next merge windows there is also new functionality coming to unix domain sockets that will have to rely on pidfd_prepare(). /* Testing */ clang: Ubuntu clang version 15.0.6 gcc: (Ubuntu 12.2.0-3ubuntu1) 12.2.0 All patches are based on 6.3-rc4 and have been sitting in linux-next. No build failures or warnings were observed. All old and new tests in fstests, selftests, and LTP pass without regressions. /* Conflicts */ At the time of creating this PR no merge conflicts were reported from linux-next and no merge conflicts showed up doing a test-merge with current mainline. The following changes since commit 197b6b60ae7bc51dd0814953c562833143b292aa: Linux 6.3-rc4 (2023-03-26 14:40:20 -0700) are available in the Git repository at: git@gitolite.kernel.org:pub/scm/linux/kernel/git/brauner/linux tags/v6.4/pidfd.file for you to fetch changes up to eee3a0e93924f2aab8ebaa7f2e26fd0f3b33f9e7: fanotify: use pidfd_prepare() (2023-04-03 11:16:57 +0200) Please consider pulling these changes from the signed v6.4/pidfd.file tag. Thanks! Christian ---------------------------------------------------------------- v6.4/pidfd.file ---------------------------------------------------------------- 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 | 98 +++++++++++++++++++++++++++++++++----- kernel/pid.c | 19 +++----- 4 files changed, 104 insertions(+), 27 deletions(-)