Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp3270736rwl; Mon, 27 Mar 2023 11:32:14 -0700 (PDT) X-Google-Smtp-Source: AKy350bltz3ap/jVnFWZK57mTJl9sxLAGkZHmFy+nZcKtgx4nT9LkMBQ6PKUPXerZGh+97WeFDoJ X-Received: by 2002:a05:6402:20d:b0:4fa:c17d:8fdd with SMTP id t13-20020a056402020d00b004fac17d8fddmr11926397edv.34.1679941933999; Mon, 27 Mar 2023 11:32:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679941933; cv=none; d=google.com; s=arc-20160816; b=RuHSzkBtdhKiy3bMl8RO8jHk7vtZE0L4a9awYMN6HalwwIxA1Q5WJ0e7T2nYoZOOOI 16krQIa4R+8528PEnrrCEQzsXC1UMNbPYBeKTUMjM00ypTPHo2dChi9JbJ+DmBXNY3BD szyH33XFBWrHy+aRXEUKVlARBag7aaRFGN43+l6pQnE1EbfsOTgahj9eDn47Xx225ueL P2UK/jBXmuaE/RlXsupVt6czmINCPzje5oCyjbLg4dW/mCdsFD6EZAm8MdT9y3kYnDJR UOxkETWBGUb2lEql9ZDlqMDDo7KnKJiBH2QcuHBaj0ByBZeYzfkHExFubPOG4Lpbqc7k qJvA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:in-reply-to:references:message-id :content-transfer-encoding:mime-version:subject:date:from :dkim-signature; bh=6JyXm7w4vJYaYrYJDM3q7TW0HsDwf6nBA5bbe8nWoAc=; b=zmWJdaKmvRX73iZFFVpoSjrczc3qj9c1hQmX97tT480GXqkNudV2wImFZ684+x+aU4 bEVwfv+GHWr1GNRte51cO4C7GGtili0hZZK5Q7/E+kbuJjQYm1A8zVJ2QmlAONrL/4gQ OPRGxxf9i7zRJMQ7C8+J8YkMg3ObVuuc07brpAR3B2sypU93AyZwDGXQSGmBhoxaAEAr h0eGVFHmb95newDM7wGCgFs5d/zFWUmzi9T+jbK0od0lEk7sJvM8a5CuWEVnbN2JvYKg mlx5BQiKyZTOd9k9eHRxojQSKJ0hUcqowGaSeDBmfmRuv49dBn3zG5aZahzCq+PRb/jD b20A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=lSV0tP4+; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 12-20020a170906018c00b00933fa612352si19792334ejb.906.2023.03.27.11.31.49; Mon, 27 Mar 2023 11:32:13 -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=lSV0tP4+; 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 S232377AbjC0SXK (ORCPT + 99 others); Mon, 27 Mar 2023 14:23:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33858 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229720AbjC0SXG (ORCPT ); Mon, 27 Mar 2023 14:23:06 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 719613585; Mon, 27 Mar 2023 11:23:05 -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 3902AB818A9; Mon, 27 Mar 2023 18:23:04 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 94982C433EF; Mon, 27 Mar 2023 18:23:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1679941383; bh=JEKlM+bqF/R1VFyTBMpRBCAf1N5vKq7gxUYcEFId+N0=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=lSV0tP4+v61vHHux+QcFowZFvdqJuXNaO0NRfRWwPXSE2tk2V/dEba8BGdLmrq+Sv 3CDMY5JEyQjvPRnDKOpwZ+0egZSMOL/TEBgPvw31cNiV2EL4IWJVAjkIGyifXA1bb6 gUECJyYvFgCDaWVLlatV/nRarSUe0l9WAfkFLW6f4vjPK1A06lYc5zgqji7QSK1liX mH4FcK2EEih3HkI7xufQoy3s0osbxcei59XxE44iiFmOMCWGiqIh6o4zN78dYSg6vp X5WqEYZxlF1VHXb5dEqBrQXdyR53OlJ48whrPXGLzG92Xf1i5228XqdfX25VQviPLY FT5OASAZtck6A== From: Christian Brauner Date: Mon, 27 Mar 2023 20:22:52 +0200 Subject: [PATCH 2/3] fork: use pidfd_prepare() MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20230327-pidfd-file-api-v1-2-5c0e9a3158e4@kernel.org> References: <20230327-pidfd-file-api-v1-0-5c0e9a3158e4@kernel.org> In-Reply-To: <20230327-pidfd-file-api-v1-0-5c0e9a3158e4@kernel.org> 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=1162; i=brauner@kernel.org; h=from:subject:message-id; bh=JEKlM+bqF/R1VFyTBMpRBCAf1N5vKq7gxUYcEFId+N0=; b=owGbwMvMwCU28Zj0gdSKO4sYT6slMaQo3mf0SZAs/5tQ151pd9fkgc+LhkS7TY/+rj7JwhizkMvD 7t6sjlIWBjEuBlkxRRaHdpNwueU8FZuNMjVg5rAygQxh4OIUgInsWsTIsDnPKfanzNml95aniu4Pf8 15pGtb258Ihv3GP39of1hfdI6R4eCSYmVlCUHbeW8f8E0uaws7Vi0buLto6ZWggE8LGi9cYQcA X-Developer-Key: i=brauner@kernel.org; a=openpgp; fpr=4880B8C9BD0E5106FC070F4F7B3C391EFEA93624 X-Spam-Status: No, score=-2.5 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,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 Stop open-coding get_unused_fd_flags() and anon_inode_getfile(). That's brittle just for keeping the flags between both calls in sync. Use the dedicated helper. Signed-off-by: Christian Brauner --- kernel/fork.c | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/kernel/fork.c b/kernel/fork.c index c0257cbee093..1f5eb854ba3e 100644 --- a/kernel/fork.c +++ b/kernel/fork.c @@ -2291,21 +2291,11 @@ static __latent_entropy struct task_struct *copy_process( * if the fd table isn't shared). */ if (clone_flags & CLONE_PIDFD) { - retval = get_unused_fd_flags(O_RDWR | O_CLOEXEC); + retval = pidfd_prepare(pid, O_RDWR | O_CLOEXEC, &pidfile); if (retval < 0) goto bad_fork_free_pid; - pidfd = retval; - pidfile = anon_inode_getfile("[pidfd]", &pidfd_fops, pid, - O_RDWR | O_CLOEXEC); - if (IS_ERR(pidfile)) { - put_unused_fd(pidfd); - retval = PTR_ERR(pidfile); - goto bad_fork_free_pid; - } - get_pid(pid); /* held by pidfile now */ - retval = put_user(pidfd, args->pidfd); if (retval) goto bad_fork_put_pidfd; -- 2.34.1