From nobody Thu Jun 29 10:56:31 2023 X-Original-To: dev-commits-src-branches@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4QsFkS13kZz4k00Y; Thu, 29 Jun 2023 10:56:32 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4QsFkS0M1Cz3Lcn; Thu, 29 Jun 2023 10:56:32 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1688036192; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=IHnm/ry2Ca+85iLk+Jfkv5Jv+yJ+T7hNPLOl03zKdPU=; b=mAz7PDL2puSwsTI5Laq9Uwqwo+mI2kkNpegFDcMKnstsLwJxo7ZE+BJ0GwDsxZWD0ZfqH1 G8ua040y4P8ozyIvdH7iXf6SMyQzctW8QBpZ2DzAGZtfoYXNf53f1y93ia1eAaN74CL57P JBt/vHFFFP87Trb9ZC8ViZMiT8RjyzS1pcjrK/1s5WHtzii0ujfjNksm7cqb2B8nAk4pnb Spt33dejXLWBrrKStczATsmGUTScgfNmGklVFQs5WlVgB21WndfNJi7nuFyQko3hX9YSnm 95yR1Q0BrlLJKucplsHyO0/K3bdP21MHMC4QcXdtoM3QnjYPj8e6wkKm629b0g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1688036192; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=IHnm/ry2Ca+85iLk+Jfkv5Jv+yJ+T7hNPLOl03zKdPU=; b=G+XvhI4aBrLVAB4oKdt2u4ogrJPmbfqf8PnbngnIY+qlCY8d4MYDX25ZdLWP3vuAcd4774 f+wC5h1rV/sTfH/Nxt/BAK63tpa06O2eAXBeIZiltpec+z020NZewO03lMVoP8hgtmrrVS ntE2GK+VyzPTeh/ZHAe5qOhtT9/4XIznq4utyDp6VhDwhZeZVXYtTkpu1fQqiLoKb7uogJ ATctYTDVEO2JNE9IR3R8isaXylDPs342Ht3jQYPzDokXVxUn5xb5KbUIK+OoZrcMWANSrQ mOj7b2MCoDx7bQbp+of3j9IKRZdl/lF7WmGCkiXx4MH6VAyv8wt7qtXZCIIeyg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1688036192; a=rsa-sha256; cv=none; b=CvysQIC79jiaNJl0uai5PUO50NoVDfso+sN1iYARg9v9hx1YT/mmHeeRGM7cSFA8pQXend I3GQNrBPONky8/dl4AdB6L6Rwgeq9f1eQ96Y8gD3XZ/OJr+n6yc6SOTIAeQqTLr16in9kc bt5ihnElRcv7C34+8f35bolvJAOTyrkEpu8OTUxmLCn6w75wJ4lofy53FQzOES0Ajw08+K sLPlzZ1Ic71HgK/AY1mgnnwAl9w2yiJbD8Q3jk+sDRO5UbOwV+EoPCY2oS/TeRHqgdqgng sJhHC/NGn4z4D6ujFtxsQEUgNN66R4xJ/RSpE1zCGgfAuacGoEJXv3TPheTGnQ== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4QsFkR6WVDz1CtK; Thu, 29 Jun 2023 10:56:31 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 35TAuVrI038771; Thu, 29 Jun 2023 10:56:31 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 35TAuVAd038770; Thu, 29 Jun 2023 10:56:31 GMT (envelope-from git) Date: Thu, 29 Jun 2023 10:56:31 GMT Message-Id: <202306291056.35TAuVAd038770@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Dmitry Chagin Subject: git: 0f287f6a96ca - stable/13 - linux(4): Implement close_range over native List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-branches@freebsd.org X-BeenThere: dev-commits-src-branches@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: dchagin X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 0f287f6a96cacda32ee17447987add3e05aa5fc6 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by dchagin: URL: https://cgit.FreeBSD.org/src/commit/?id=0f287f6a96cacda32ee17447987add3e05aa5fc6 commit 0f287f6a96cacda32ee17447987add3e05aa5fc6 Author: Dmitry Chagin AuthorDate: 2023-04-04 20:24:04 +0000 Commit: Dmitry Chagin CommitDate: 2023-06-29 10:50:41 +0000 linux(4): Implement close_range over native Handling of the CLOSE_RANGE_UNSHARE flag is not implemented due to difference in fd unsharing mechanism in the Linux and FreeBSD. Reviewed by: mjg Differential revision: https://reviews.freebsd.org/D39398 MFC after: 2 weeks (cherry picked from commit 71bc17803edfaad545f0c1f1111ca892aed7a5c4) --- sys/compat/linux/linux_dummy.c | 1 - sys/compat/linux/linux_file.c | 26 ++++++++++++++++++++++++++ sys/compat/linux/linux_file.h | 7 +++++++ 3 files changed, 33 insertions(+), 1 deletion(-) diff --git a/sys/compat/linux/linux_dummy.c b/sys/compat/linux/linux_dummy.c index 45b0db6d6dde..e3812218514c 100644 --- a/sys/compat/linux/linux_dummy.c +++ b/sys/compat/linux/linux_dummy.c @@ -135,7 +135,6 @@ DUMMY(fsconfig); DUMMY(fsmount); DUMMY(fspick); DUMMY(pidfd_open); -DUMMY(close_range); DUMMY(openat2); DUMMY(pidfd_getfd); DUMMY(process_madvise); diff --git a/sys/compat/linux/linux_file.c b/sys/compat/linux/linux_file.c index 249318a2e619..4ce0a2cb4c0e 100644 --- a/sys/compat/linux/linux_file.c +++ b/sys/compat/linux/linux_file.c @@ -2083,3 +2083,29 @@ linux_splice(struct thread *td, struct linux_splice_args *args) */ return (EINVAL); } + +int +linux_close_range(struct thread *td, struct linux_close_range_args *args) +{ + u_int flags = 0; + + /* + * Implementing close_range(CLOSE_RANGE_UNSHARE) allows Linux to + * unshare filedesc table of the calling thread from others threads + * in a thread group (i.e., process in the FreeBSD) or others processes, + * which shares the same table, before closing the files. FreeBSD does + * not have compatible unsharing mechanism due to the fact that sharing + * process resources, including filedesc table, is at thread level in the + * Linux, while in the FreeBSD it is at the process level. + * Return EINVAL for now if the CLOSE_RANGE_UNSHARE flag is specified + * until this new Linux API stabilizes. + */ + + if ((args->flags & ~(LINUX_CLOSE_RANGE_CLOEXEC)) != 0) + return (EINVAL); + if (args->first > args->last) + return (EINVAL); + if ((args->flags & LINUX_CLOSE_RANGE_CLOEXEC) != 0) + flags |= CLOSE_RANGE_CLOEXEC; + return (kern_close_range(td, flags, args->first, args->last)); +} diff --git a/sys/compat/linux/linux_file.h b/sys/compat/linux/linux_file.h index 3f885f915411..061bd1fc2c24 100644 --- a/sys/compat/linux/linux_file.h +++ b/sys/compat/linux/linux_file.h @@ -197,4 +197,11 @@ struct l_file_handle { unsigned char f_handle[0]; }; +/* + * Look at linux_close_range() for an explanation. + * + * #define LINUX_CLOSE_RANGE_UNSHARE (1U << 1) + */ +#define LINUX_CLOSE_RANGE_CLOEXEC (1U << 2) + #endif /* !_LINUX_FILE_H_ */