From nobody Sun Aug 20 07:37:45 2023 X-Original-To: dev-commits-src-all@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 4RT6s60CmCz4qsMj; Sun, 20 Aug 2023 07:37:46 +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 4RT6s52Mffz3D9T; Sun, 20 Aug 2023 07:37:45 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1692517065; 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=4Rcs39Q7jR1STjgo8DZf6/6iHocrOFQRTnHmnjLuxSs=; b=UHf8yjn5eayubHvBvFZIlo0GV3JdWSmEmZQN15hCRLUq/pXW1AEZ0Oj5J0EJ2PaoyIx4VV p0nJRrxNlXoQDEXvpC68NAK8PCwyAZRAFoN4csvlRhnQ0DtUB15pvKNQsKh+AQyL1LyRt9 HwdXUUJQUEQAusvE2Mwsfhk/0mGrOVHvXwR2wtUQqV+7bGvaadOHNnX98bxeqSArlMivhD iQBotdXY/sV0BBrZndZiPpDRHWQtgnKMu+lSF+l+1d15rk5OBi56uFzAoY3dV9z/p9MD+G snxIuyHftVwusCieyOWfX1jsc4HsCBvjOVZExBuLWrWBKrrPRW/L9asJEhxP1A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1692517065; 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=4Rcs39Q7jR1STjgo8DZf6/6iHocrOFQRTnHmnjLuxSs=; b=F1ANyKwzpnxpqoBOAX8JY+7R4ZXa9Lu7nKdOxZsTtuW3If//Rw/3D6LOgSNsekVakvSftR Y+OUMEPAf3I+AIzvMrVlRHaa1xkJ7j35HkX15k+/y5WZKvUHr/MQl+ECGAjZLPaLf+CT9+ Zha8ldPRaH5xwu1NRIz+ggJLkuuYtBqya/UKtyL049vHhKClqgCQynHi0j01f5bb5ljuQc pP/EUuJy9B6nvyFLKPmtAPrio7MVWmdnlz53IYS6TDjMp49n0nM0eb+QpTMjaTxEfVRYfG bLh/8EaBEadtSLaTL4Kk47+nZyiPXyOdK46yZRxR0Wz84kyjdldu8dBzQxpzlA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1692517065; a=rsa-sha256; cv=none; b=rqLSap/FgKs0Ka9eazxyqkjNaeSySRwrDtJqaZmDnV36DkVapSc1aTHr6LeFEjW1ANI52E BsdkAW700Tm1xpaxJH6dxKscKTImVTDRzc6NNYQ1bLLckW/gCWPKfOH9+kHDeVoURIw/Jx XN6IpgpO5yOhi/9vIpP6/A1B6S2FjgpTxvlytkuTUiUPVNDlJZTdqVtmFijuaOBn+pqnm/ P39AiqdtzTTuPloMqrVXqO0qcWOmf06+XeV5B+dHbNYSoe7dvDYv8vjGwtGYeSRc4akRyi ST+GirqQ+bLRyHp9eGNU3o0oUjcHRl+UNNzruuY49nUAJ9u2miwDe6iSSY31tg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none 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 4RT6s51S0qzWcV; Sun, 20 Aug 2023 07:37:45 +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 37K7bjx4049607; Sun, 20 Aug 2023 07:37:45 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 37K7bjxW049604; Sun, 20 Aug 2023 07:37:45 GMT (envelope-from git) Date: Sun, 20 Aug 2023 07:37:45 GMT Message-Id: <202308200737.37K7bjxW049604@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: e58ff66464ac - main - linux(4): Add a write syscall wrapper List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@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: e58ff66464ac313296b683992c9131d7a85047de Auto-Submitted: auto-generated The branch main has been updated by dchagin: URL: https://cgit.FreeBSD.org/src/commit/?id=e58ff66464ac313296b683992c9131d7a85047de commit e58ff66464ac313296b683992c9131d7a85047de Author: Dmitry Chagin AuthorDate: 2023-08-20 07:36:29 +0000 Commit: Dmitry Chagin CommitDate: 2023-08-20 07:36:29 +0000 linux(4): Add a write syscall wrapper Adding a write syscall wrapper is needed due to Linux family of write syscalls doesn't distinguish between in kernel blocking operations and always returns EAGAIN while FreeBSD can return ENOBUFS. MFC after: 1 month --- sys/amd64/linux/linux_vdso_gtod.c | 2 +- sys/amd64/linux32/linux32_vdso_gtod.c | 2 +- sys/arm64/linux/linux_vdso_gtod.c | 2 +- sys/compat/linux/linux_file.c | 28 ++++++++++++++++++++++++++++ sys/compat/linux/linux_file.h | 4 ++++ sys/i386/linux/linux_vdso_gtod.c | 2 +- 6 files changed, 36 insertions(+), 4 deletions(-) diff --git a/sys/amd64/linux/linux_vdso_gtod.c b/sys/amd64/linux/linux_vdso_gtod.c index e2b5ebbec5ff..519ca2f2de93 100644 --- a/sys/amd64/linux/linux_vdso_gtod.c +++ b/sys/amd64/linux/linux_vdso_gtod.c @@ -61,7 +61,7 @@ write(int fd, const void *buf, size_t size) ( "syscall" : "=a"(res) - : "a"(LINUX_SYS_write), "D"(fd), "S"(buf), "d"(size) + : "a"(LINUX_SYS_linux_write), "D"(fd), "S"(buf), "d"(size) : "cc", "rcx", "r11", "memory" ); return (res); diff --git a/sys/amd64/linux32/linux32_vdso_gtod.c b/sys/amd64/linux32/linux32_vdso_gtod.c index 62e8dc3d3caf..ec5851c45c28 100644 --- a/sys/amd64/linux32/linux32_vdso_gtod.c +++ b/sys/amd64/linux32/linux32_vdso_gtod.c @@ -60,7 +60,7 @@ write(int fd, const void *buf, size_t size) ( "int $0x80" : "=a"(res) - : "a"(LINUX32_SYS_write), "b"(fd), "c"(buf), "d"(size) + : "a"(LINUX32_SYS_linux_write), "b"(fd), "c"(buf), "d"(size) : "cc", "memory" ); return (res); diff --git a/sys/arm64/linux/linux_vdso_gtod.c b/sys/arm64/linux/linux_vdso_gtod.c index 94a3c948d332..f7def68d88c4 100644 --- a/sys/arm64/linux/linux_vdso_gtod.c +++ b/sys/arm64/linux/linux_vdso_gtod.c @@ -50,7 +50,7 @@ uint32_t kern_tsc_selector = 0; static int write(int lfd, const void *lbuf, size_t lsize) { - register long svc asm("x8") = LINUX_SYS_write; + register long svc asm("x8") = LINUX_SYS_linux_write; register int fd asm("x0") = lfd; register const char *buf asm("x1") = lbuf; register long size asm("x2") = lsize; diff --git a/sys/compat/linux/linux_file.c b/sys/compat/linux/linux_file.c index 62094697e107..6a1f61984b08 100644 --- a/sys/compat/linux/linux_file.c +++ b/sys/compat/linux/linux_file.c @@ -40,6 +40,7 @@ #include #include #include +#include #include #include #include @@ -1827,3 +1828,30 @@ linux_close_range(struct thread *td, struct linux_close_range_args *args) flags |= CLOSE_RANGE_CLOEXEC; return (kern_close_range(td, flags, args->first, args->last)); } + +int +linux_enobufs2eagain(struct thread *td, int fd, int error) +{ + struct file *fp; + + if (error != ENOBUFS) + return (error); + if (fget(td, fd, &cap_no_rights, &fp) != 0) + return (error); + if (fp->f_type == DTYPE_SOCKET && (fp->f_flag & FNONBLOCK) != 0) + error = EAGAIN; + fdrop(fp, td); + return (error); +} + +int +linux_write(struct thread *td, struct linux_write_args *args) +{ + struct write_args bargs = { + .fd = args->fd, + .buf = args->buf, + .nbyte = args->nbyte, + }; + + return (linux_enobufs2eagain(td, args->fd, sys_write(td, &bargs))); +} diff --git a/sys/compat/linux/linux_file.h b/sys/compat/linux/linux_file.h index 0dcd7a5fd13e..ce9feca154ed 100644 --- a/sys/compat/linux/linux_file.h +++ b/sys/compat/linux/linux_file.h @@ -189,12 +189,16 @@ #define LINUX_HUGETLB_FLAG_ENCODE_2GB (31 << LINUX_HUGETLB_FLAG_ENCODE_SHIFT) #define LINUX_HUGETLB_FLAG_ENCODE_16GB (34U << LINUX_HUGETLB_FLAG_ENCODE_SHIFT) +#if defined(_KERNEL) struct l_file_handle { l_uint handle_bytes; l_int handle_type; unsigned char f_handle[0]; }; +int linux_enobufs2eagain(struct thread *, int, int); +#endif + /* * Look at linux_close_range() for an explanation. * diff --git a/sys/i386/linux/linux_vdso_gtod.c b/sys/i386/linux/linux_vdso_gtod.c index 2147dbd3a0f8..ca200ce04da7 100644 --- a/sys/i386/linux/linux_vdso_gtod.c +++ b/sys/i386/linux/linux_vdso_gtod.c @@ -60,7 +60,7 @@ write(int fd, const void *buf, size_t size) ( "int $0x80" : "=a"(res) - : "a"(LINUX_SYS_write), "b"(fd), "c"(buf), "d"(size) + : "a"(LINUX_SYS_linux_write), "b"(fd), "c"(buf), "d"(size) : "cc", "memory" ); return (res);