From nobody Thu May 23 19:42:15 2024 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 4VldqD0Jlkz5L9R1; Thu, 23 May 2024 19:42:16 +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 4VldqC4tPSz55Vx; Thu, 23 May 2024 19:42:15 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1716493335; 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=6/0oavsWMItGCsgtit3DY70gIOSFtqrIgoOAscdAHEM=; b=WvQlfuvMyV5ylZx5mJlqV33xYBLG1AAB+YlihtQLzVMqzgplToIaeI+2pwR5BrEMsK7xGL 9qc/g+ch1aV65pi+n9qgQEAsv1BN3x2fba6lmx+O779gTz9l8o1GCRWG5MVltt8PuiS5RK HwKwY7omoQtW8Kn2NhES/nlWi8AiCNCqN0+ugjxysB/5YXrKcVy+8e3Odk1sVaPCDeKZ6f 1x70mMI3ePFipU6zvSVgLmjTYIyCvMAwqoDfeBW6DYOAw3Ru3UYhZ+Q1I4EzADZ8SHHYt8 zMD3PnHAOYlOXufktFje9yg+XN8JsbvOdw1yZVeoQABmu2nx6ftbHcK5xD4+2Q== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1716493335; a=rsa-sha256; cv=none; b=JMeML5zlI4uXO2mCRWqCFOt1++HqHhngv3os8twJIAYkahCjSgYhuN3EqXQxeiLMJY73Ds DjXG42XBgwtEVuCOAsfkzleKGWXLGpHi7uTE2sni+Fg3ghAR7OXma9vnp8mIJK1rZzqRU2 mUvgJ+X9fjS37LqqIeV2oWIdZeDgyPmwW59+EwunnigUax6MHak+uaXbARJbyF9xnfJ2XT 8tiaFyY1SD0RAkDXZ2DMHGA0sTiT4vHw6hF6G34ToQ6XY54ufn15H9OV80jOueaW735YAs eG3EArYHXDyVdCy0G4H25RZHqY5KzJxURPh9Xb0UiuXSLJo6cKNXSc05lOvX2A== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1716493335; 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=6/0oavsWMItGCsgtit3DY70gIOSFtqrIgoOAscdAHEM=; b=Bkw/YlgyBiXXKqjfvGWiNv1XYWwZo66PTw/e4K7rb2NJ8awU9K6I/lFUrl+n8yqMKdurdt fLhXT7J110yQrcnJPDwgf1Ng22MqTLZ9fjV68FecPiWfaHnNeiQe1SjwjmCZO3QC7sWEVf 3bp353IDPJNXHipQetyk8wU03Lnjs++6Y2WGKdnGfATRbBTpMmc8n5lG9G01v5pETQ5Iuf LHOShr3LSIJf/Nq4sH0e9acKRg0pL0VqzrtLOjn/8Pav4Ybl7tmpTmbYLj2feweex5zWbm ne9IqNUSdT7Lk4IFkJjQSrooMO/Yf554kFngYk9Pb8zc9d29QkndqDC+t+B2lg== 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 4VldqC4SBgz12kw; Thu, 23 May 2024 19:42:15 +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 44NJgFA2082817; Thu, 23 May 2024 19:42:15 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 44NJgFKq082814; Thu, 23 May 2024 19:42:15 GMT (envelope-from git) Date: Thu, 23 May 2024 19:42:15 GMT Message-Id: <202405231942.44NJgFKq082814@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Warner Losh Subject: git: 97add684f530 - main - linux: Support POSIX message queues 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: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: imp X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 97add684f5306ebf93be238a0340597ba1898d0e Auto-Submitted: auto-generated The branch main has been updated by imp: URL: https://cgit.FreeBSD.org/src/commit/?id=97add684f5306ebf93be238a0340597ba1898d0e commit 97add684f5306ebf93be238a0340597ba1898d0e Author: Ricardo Branco AuthorDate: 2024-05-17 20:31:49 +0000 Commit: Warner Losh CommitDate: 2024-05-23 19:40:46 +0000 linux: Support POSIX message queues Reviewed by: imp, kib Pull Request: https://github.com/freebsd/freebsd-src/pull/1248 --- sys/amd64/linux/linux_dummy_machdep.c | 6 -- sys/amd64/linux32/linux32_dummy_machdep.c | 6 -- sys/arm64/linux/linux_dummy_machdep.c | 6 -- sys/compat/linux/linux_misc.c | 124 ++++++++++++++++++++++++++++++ sys/i386/linux/linux_machdep.c | 61 --------------- 5 files changed, 124 insertions(+), 79 deletions(-) diff --git a/sys/amd64/linux/linux_dummy_machdep.c b/sys/amd64/linux/linux_dummy_machdep.c index 759586d9f1fc..53bdb8099578 100644 --- a/sys/amd64/linux/linux_dummy_machdep.c +++ b/sys/amd64/linux/linux_dummy_machdep.c @@ -56,12 +56,6 @@ DUMMY(io_destroy); DUMMY(io_getevents); DUMMY(io_submit); DUMMY(io_cancel); -DUMMY(mq_open); -DUMMY(mq_unlink); -DUMMY(mq_timedsend); -DUMMY(mq_timedreceive); -DUMMY(mq_notify); -DUMMY(mq_getsetattr); DUMMY(readahead); DUMMY(restart_syscall); /* Linux 3.15: */ diff --git a/sys/amd64/linux32/linux32_dummy_machdep.c b/sys/amd64/linux32/linux32_dummy_machdep.c index c2206c81c528..1476d39b9c35 100644 --- a/sys/amd64/linux32/linux32_dummy_machdep.c +++ b/sys/amd64/linux32/linux32_dummy_machdep.c @@ -55,12 +55,6 @@ DUMMY(olduname); DUMMY(uname); DUMMY(bdflush); DUMMY(ptrace); -DUMMY(mq_open); -DUMMY(mq_unlink); -DUMMY(mq_timedsend); -DUMMY(mq_timedreceive); -DUMMY(mq_notify); -DUMMY(mq_getsetattr); /* Linux 4.11: */ DUMMY(arch_prctl); /* Linux 5.0: */ diff --git a/sys/arm64/linux/linux_dummy_machdep.c b/sys/arm64/linux/linux_dummy_machdep.c index a7a7795f573d..5ff6bfafe2d6 100644 --- a/sys/arm64/linux/linux_dummy_machdep.c +++ b/sys/arm64/linux/linux_dummy_machdep.c @@ -42,10 +42,4 @@ LIN_SDT_PROVIDER_DECLARE(LINUX_DTRACE); * Before adding new stubs to this file, please check if a stub can be added to * the machine-independent code in sys/compat/linux/linux_dummy.c. */ -DUMMY(mq_open); -DUMMY(mq_unlink); -DUMMY(mq_timedsend); -DUMMY(mq_timedreceive); -DUMMY(mq_notify); -DUMMY(mq_getsetattr); DUMMY(kexec_file_load); diff --git a/sys/compat/linux/linux_misc.c b/sys/compat/linux/linux_misc.c index 9b8ab193f2bd..14c36669efc8 100644 --- a/sys/compat/linux/linux_misc.c +++ b/sys/compat/linux/linux_misc.c @@ -29,6 +29,8 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#include "opt_posix.h" + #include #include #include @@ -36,6 +38,7 @@ #include #include #include +#include #include #include #include @@ -2963,3 +2966,124 @@ linux_ioprio_set(struct thread *td, struct linux_ioprio_set_args *args) } return (error); } + +/* The only flag is O_NONBLOCK */ +#define B2L_MQ_FLAGS(bflags) ((bflags) != 0 ? LINUX_O_NONBLOCK : 0) +#define L2B_MQ_FLAGS(lflags) ((lflags) != 0 ? O_NONBLOCK : 0) + +int +linux_mq_open(struct thread *td, struct linux_mq_open_args *args) +{ + struct mq_attr attr; + int error, flags; + + flags = linux_common_openflags(args->oflag); + if ((flags & O_ACCMODE) == O_ACCMODE || (flags & O_EXEC) != 0) + return (EINVAL); + flags = FFLAGS(flags); + if ((flags & O_CREAT) != 0 && args->attr != NULL) { + error = copyin(args->attr, &attr, sizeof(attr)); + if (error != 0) + return (error); + attr.mq_flags = L2B_MQ_FLAGS(attr.mq_flags); + } + + return (kern_kmq_open(td, args->name, flags, args->mode, + args->attr != NULL ? &attr : NULL)); +} + +int +linux_mq_unlink(struct thread *td, struct linux_mq_unlink_args *args) +{ + struct kmq_unlink_args bsd_args = { + .path = PTRIN(args->name) + }; + + return (sys_kmq_unlink(td, &bsd_args)); +} + +int +linux_mq_timedsend(struct thread *td, struct linux_mq_timedsend_args *args) +{ + struct timespec ts, *abs_timeout; + int error; + + if (args->abs_timeout == NULL) + abs_timeout = NULL; + else { + error = linux_get_timespec(&ts, args->abs_timeout); + if (error != 0) + return (error); + abs_timeout = &ts; + } + + return (kern_kmq_timedsend(td, args->mqd, PTRIN(args->msg_ptr), + args->msg_len, args->msg_prio, abs_timeout)); +} + +int +linux_mq_timedreceive(struct thread *td, struct linux_mq_timedreceive_args *args) +{ + struct timespec ts, *abs_timeout; + int error; + + if (args->abs_timeout == NULL) + abs_timeout = NULL; + else { + error = linux_get_timespec(&ts, args->abs_timeout); + if (error != 0) + return (error); + abs_timeout = &ts; + } + + return (kern_kmq_timedreceive(td, args->mqd, PTRIN(args->msg_ptr), + args->msg_len, args->msg_prio, abs_timeout)); +} + +int +linux_mq_notify(struct thread *td, struct linux_mq_notify_args *args) +{ + struct sigevent ev, *evp; + struct l_sigevent l_ev; + int error; + + if (args->sevp == NULL) + evp = NULL; + else { + error = copyin(args->sevp, &l_ev, sizeof(l_ev)); + if (error != 0) + return (error); + error = linux_convert_l_sigevent(&l_ev, &ev); + if (error != 0) + return (error); + evp = &ev; + } + + return (kern_kmq_notify(td, args->mqd, evp)); +} + +int +linux_mq_getsetattr(struct thread *td, struct linux_mq_getsetattr_args *args) +{ + struct mq_attr attr, oattr; + int error; + + if (args->attr != NULL) { + error = copyin(args->attr, &attr, sizeof(attr)); + if (error != 0) + return (error); + attr.mq_flags = L2B_MQ_FLAGS(attr.mq_flags); + } + + error = kern_kmq_setattr(td, args->mqd, args->attr != NULL ? &attr : NULL, + &oattr); + if (error == 0 && args->oattr != NULL) { + oattr.mq_flags = B2L_MQ_FLAGS(oattr.mq_flags); + bzero(oattr.__reserved, sizeof(oattr.__reserved)); + error = copyout(&oattr, args->oattr, sizeof(oattr)); + } + + return (error); +} + +MODULE_DEPEND(linux, mqueuefs, 1, 1, 1); diff --git a/sys/i386/linux/linux_machdep.c b/sys/i386/linux/linux_machdep.c index b5d42dc22162..0e056aadb4b5 100644 --- a/sys/i386/linux/linux_machdep.c +++ b/sys/i386/linux/linux_machdep.c @@ -592,67 +592,6 @@ linux_get_thread_area(struct thread *td, struct linux_get_thread_area_args *args return (0); } -/* XXX: this wont work with module - convert it */ -int -linux_mq_open(struct thread *td, struct linux_mq_open_args *args) -{ -#ifdef P1003_1B_MQUEUE - return (sys_kmq_open(td, (struct kmq_open_args *)args)); -#else - return (ENOSYS); -#endif -} - -int -linux_mq_unlink(struct thread *td, struct linux_mq_unlink_args *args) -{ -#ifdef P1003_1B_MQUEUE - return (sys_kmq_unlink(td, (struct kmq_unlink_args *)args)); -#else - return (ENOSYS); -#endif -} - -int -linux_mq_timedsend(struct thread *td, struct linux_mq_timedsend_args *args) -{ -#ifdef P1003_1B_MQUEUE - return (sys_kmq_timedsend(td, (struct kmq_timedsend_args *)args)); -#else - return (ENOSYS); -#endif -} - -int -linux_mq_timedreceive(struct thread *td, struct linux_mq_timedreceive_args *args) -{ -#ifdef P1003_1B_MQUEUE - return (sys_kmq_timedreceive(td, (struct kmq_timedreceive_args *)args)); -#else - return (ENOSYS); -#endif -} - -int -linux_mq_notify(struct thread *td, struct linux_mq_notify_args *args) -{ -#ifdef P1003_1B_MQUEUE - return (sys_kmq_notify(td, (struct kmq_notify_args *)args)); -#else - return (ENOSYS); -#endif -} - -int -linux_mq_getsetattr(struct thread *td, struct linux_mq_getsetattr_args *args) -{ -#ifdef P1003_1B_MQUEUE - return (sys_kmq_setattr(td, (struct kmq_setattr_args *)args)); -#else - return (ENOSYS); -#endif -} - void bsd_to_linux_regset(const struct reg *b_reg, struct linux_pt_regset *l_regset)