From nobody Tue Apr 4 20:24:20 2023 X-Original-To: dev-commits-src-main@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 4PrfPK24NBz447Wk; Tue, 4 Apr 2023 20:24:21 +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 4PrfPK1Vgcz4PZ8; Tue, 4 Apr 2023 20:24:21 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1680639861; 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=NPuZMQuv2eaByYGyh5e/+8Kakk3hjA0ueh9l8aiTWOk=; b=cKobkJkDSumk6Ebyma2c04ZTOt8pArKLQhrsdKKw8P/rWIdQGm+lqQcgroolRp5PFf3A3I onJN4S1spEgK/yYS0etYohXkYR2If+6ZIZBR0bc9H2LZMgfsfDkQvNWFoOQaVRxAnrh4hz vUwNrfiG98cv7fw5QITPCecI4iHY1WJXCobeAc8BMpT85bU/Quiqfy621WMSeQFm/OFXsm bOEI5moL/OewQMbEL76TvV8HikzIE6ASvGqnYNX97SwhEnVx8DW0zguPIk4brHlLuvx7sH 3PVN7MHYO7v6pP9eEEK+UN+Z7G+I+dAhENOCeaAwZuZ+A900O+UHATARY6icEg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1680639861; 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=NPuZMQuv2eaByYGyh5e/+8Kakk3hjA0ueh9l8aiTWOk=; b=fhOGMeN6rD6R5dbgoGWQpS9P6AiQ36plub0p9H7Wj5xPyiC5LpRCjDE0QBtTPqUfvKddn2 a436M7ME51vSpvvOxJQ32/hnXfF8WqLTPyewhoqkYraWBdkOAgqpylpxXY7ltzOz8+Slnl N9AxfLCJjVvX1Ive6unCUF73iP0UkZiyQPJhqa1bv02wDDGuxmZ+KbV661Mm6xG4eComHR jRKI7MtqO/uqgAInGVcfXOwnW5h/WrIKp7knDIxxLpkuE99EBqgWP0/SLzV7+JKF+3Z8Ba 1IZWyUsjfnQ0at3Tt9Fpc53OPZ6skKdhGXuMQ+hP1G5Ztvj5kOigkqLsoGTmlg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1680639861; a=rsa-sha256; cv=none; b=Zh8bipujW99mS2tFuaBDxl3b7VqsY/HJlgVVrxAKNhYQKoVOKEUCzmGpPy+TKTofJc0u9N Zp7emFG911sdHPBAdqq9QvnV+uyogS69mLMC9dGm2QKoXuexz42eY8ErAJMHVhjcuRFBb9 DYHozA6I6r6hdPgfGQ6YmdAP6PoCfyPMXm6n2arf652eFFPEc2fNUuun/teB2/Rl/DH+Cs 0PWISz5tRi50+pMBYi1y49F9RZ4KSIdNNP0K6VGvH0k3ywDFRK3gbUaASwJ+oZX7FStKHp 0W1ZDS3K4tjn2zb+KlFsOXyJLmGwuS+kViOcyVmqvgns5b0ofmXyl3vDsX4a3g== 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 4PrfPK0Zmxzv11; Tue, 4 Apr 2023 20:24:21 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 334KOKub091660; Tue, 4 Apr 2023 20:24:20 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 334KOKNN091659; Tue, 4 Apr 2023 20:24:20 GMT (envelope-from git) Date: Tue, 4 Apr 2023 20:24:20 GMT Message-Id: <202304042024.334KOKNN091659@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Dmitry Chagin Subject: git: 71bc17803edf - main - linux(4): Implement close_range over native List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@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/main X-Git-Reftype: branch X-Git-Commit: 71bc17803edfaad545f0c1f1111ca892aed7a5c4 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by dchagin: URL: https://cgit.FreeBSD.org/src/commit/?id=71bc17803edfaad545f0c1f1111ca892aed7a5c4 commit 71bc17803edfaad545f0c1f1111ca892aed7a5c4 Author: Dmitry Chagin AuthorDate: 2023-04-04 20:24:04 +0000 Commit: Dmitry Chagin CommitDate: 2023-04-04 20:24:04 +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 --- 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 db4b1151bc60..5e2236dc7502 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_ */