From nobody Fri Jun 17 19:37:09 2022 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 4E1E285A5AE; Fri, 17 Jun 2022 19:37:10 +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 4LPq796q5rz3PVH; Fri, 17 Jun 2022 19:37:09 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1655494630; 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=YD9HBXr24Nlfgn0LJfEQ1A+1QGAC6qZr1woYZ5PbNiE=; b=qpjTb4yQRuM4feeyMofBt/XKGjCWqoM4pAsPlVZIOXP7KcfaoK6WING2uLpC8SJ0EU+qSN z0HCZkjf9tKnBQv3ixg+G4G9VgG72466ywggnz/ZrgUDXTpPwmjEwZqgq/0oUR7pHTgcIA zkd8tB9rrqbcXPdq8lYz8zuNs3PyTjkI9SMuF1II6y/FTHKC4TOJZY2/CCFuyz95+CCWOy m1T/JHIeJIJbiCz6WvN+s0Y/Rj+3XHoWHfYWz5SYCDF0SFndk5BL+4AF6cXV6cyhfppJxq 2xLnXMrXG/NWXWiSo1RbpaV0t/w/xus2Vug5l5RJWcMy7SSMYfT1JvN5WEkAJw== 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 ABE42257CF; Fri, 17 Jun 2022 19:37:09 +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 25HJb9qM012985; Fri, 17 Jun 2022 19:37:09 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 25HJb97W012984; Fri, 17 Jun 2022 19:37:09 GMT (envelope-from git) Date: Fri, 17 Jun 2022 19:37:09 GMT Message-Id: <202206171937.25HJb97W012984@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: 6698c1a28d09 - stable/13 - linux(4): Allow musl brand to use FUTEX_REQUEUE op. 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/stable/13 X-Git-Reftype: branch X-Git-Commit: 6698c1a28d09b58fbb0921ec727b9917fd5d2b7a Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1655494630; 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=YD9HBXr24Nlfgn0LJfEQ1A+1QGAC6qZr1woYZ5PbNiE=; b=v+a5sdbcCz/pN/IXdSzZd9xOFOPYy8iFlkkYPYZSkqRR/sKPQg5IJ9qBL+2q18CgkK/PY0 mB9owi1YvwihjObyW+hCvRJjYptcgBtR9hAu8sPDuRib2fjkq2FNZgWAFjGvoBmA2Dk0Op EiJtHX8NYb1QSOWKelchZvcC5XjdJ041tyrt4ZpzBZjvpMoqjTjGZGEisTmWBkilt1dKyZ O10HFJTUD6dkLJ8XJ8UUYgjnWy75VgBAiKBDyYirBLs/a1WI7fH0B0lBU1Hk2o8EorHdYH b3keWlawkr4KS5V0GlD8odxTkaNUVcWoC8e29q9BMTRHkOs32Kbaie4TGLBMfQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1655494630; a=rsa-sha256; cv=none; b=Nlp8ika43U7ENKesLaTJNQgeNGBaK948byJbvf8nTcCkDqRxqFVwY03X757+BNKdJGYXhN AVUYdYv8S40DUS71fUEndF2MDjQedMC1tO7r8fXAvyO++jMTc8coJzEF/TGdDFcQnJ6rrF iC6BK8jG3JXTj3nre2elu6QLQ5xL2rul1aCUG/VMiqL/dx1IPdeH+Mc6OY0AD8z81CinqG wqzu7PUOncmzb6J+/PvavOQOHOeDOErXAdNwW9dTzjOep38tdeFEsAY+v/ed9Bb9q/LZXp vEUec0K7GSIu62nfO84MkzLz/1D7lCSpJXk+FA+sS5IAZrXj5u2/sSV0fRDWEQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by dchagin: URL: https://cgit.FreeBSD.org/src/commit/?id=6698c1a28d09b58fbb0921ec727b9917fd5d2b7a commit 6698c1a28d09b58fbb0921ec727b9917fd5d2b7a Author: Dmitry Chagin AuthorDate: 2021-07-20 11:39:20 +0000 Commit: Dmitry Chagin CommitDate: 2022-06-17 19:33:12 +0000 linux(4): Allow musl brand to use FUTEX_REQUEUE op. Initial patch from submitter was adapted by me to prevent unconditional FUTEX_REQUEUE use. PR: 255947 Submitted by: Philippe Michaud-Boudreault Differential Revision: https://reviews.freebsd.org/D30332 (cherry picked from commit cf8d74e3fe63da7359d6ca7e0b4b57c5684c2845) --- sys/amd64/linux/linux_sysvec.c | 3 ++- sys/amd64/linux32/linux32_sysvec.c | 3 ++- sys/compat/linux/linux.h | 5 ++++ sys/compat/linux/linux_futex.c | 49 +++++++++++++++++++++++++------------- sys/i386/linux/linux_sysvec.c | 3 ++- 5 files changed, 43 insertions(+), 20 deletions(-) diff --git a/sys/amd64/linux/linux_sysvec.c b/sys/amd64/linux/linux_sysvec.c index e098779e518e..08b9a5f1650f 100644 --- a/sys/amd64/linux/linux_sysvec.c +++ b/sys/amd64/linux/linux_sysvec.c @@ -985,7 +985,8 @@ static Elf64_Brandinfo linux_muslbrand = { .sysvec = &elf_linux_sysvec, .interp_newpath = NULL, .brand_note = &linux64_brandnote, - .flags = BI_CAN_EXEC_DYN | BI_BRAND_NOTE + .flags = BI_CAN_EXEC_DYN | BI_BRAND_NOTE | + LINUX_BI_FUTEX_REQUEUE }; Elf64_Brandinfo *linux_brandlist[] = { diff --git a/sys/amd64/linux32/linux32_sysvec.c b/sys/amd64/linux32/linux32_sysvec.c index 9e77c5e8ac7d..77d6c612c359 100644 --- a/sys/amd64/linux32/linux32_sysvec.c +++ b/sys/amd64/linux32/linux32_sysvec.c @@ -1145,7 +1145,8 @@ static Elf32_Brandinfo linux_muslbrand = { .sysvec = &elf_linux_sysvec, .interp_newpath = NULL, .brand_note = &linux32_brandnote, - .flags = BI_CAN_EXEC_DYN | BI_BRAND_NOTE + .flags = BI_CAN_EXEC_DYN | BI_BRAND_NOTE | + LINUX_BI_FUTEX_REQUEUE }; Elf32_Brandinfo *linux_brandlist[] = { diff --git a/sys/compat/linux/linux.h b/sys/compat/linux/linux.h index 5656b67251ff..2ec12fd64d58 100644 --- a/sys/compat/linux/linux.h +++ b/sys/compat/linux/linux.h @@ -30,6 +30,11 @@ #include +/* + * Private Brandinfo flags + */ +#define LINUX_BI_FUTEX_REQUEUE 0x01000000 + /* * poll() */ diff --git a/sys/compat/linux/linux_futex.c b/sys/compat/linux/linux_futex.c index 1ba11ed3fc57..2ee18c26cf24 100644 --- a/sys/compat/linux/linux_futex.c +++ b/sys/compat/linux/linux_futex.c @@ -46,6 +46,7 @@ __KERNEL_RCSID(1, "$NetBSD: linux_futex.c,v 1.7 2006/07/24 19:01:49 manu Exp $") #include #include #include +#include #include #include #include @@ -234,6 +235,7 @@ struct linux_futex_args { struct timespec *ts; uint32_t *uaddr2; uint32_t val3; + bool val3_compare; struct timespec kts; }; @@ -648,6 +650,7 @@ static int linux_futex(struct thread *td, struct linux_futex_args *args) { struct linux_pemuldata *pem; + struct proc *p; if (args->op & LINUX_FUTEX_PRIVATE_FLAG) { args->flags = 0; @@ -695,6 +698,33 @@ linux_futex(struct thread *td, struct linux_futex_args *args) return (linux_futex_wake(td, args)); + case LINUX_FUTEX_REQUEUE: + /* + * Glibc does not use this operation since version 2.3.3, + * as it is racy and replaced by FUTEX_CMP_REQUEUE operation. + * Glibc versions prior to 2.3.3 fall back to FUTEX_WAKE when + * FUTEX_REQUEUE returned EINVAL. + */ + pem = pem_find(td->td_proc); + if ((pem->flags & LINUX_XDEPR_REQUEUEOP) == 0) { + linux_msg(td, "unsupported FUTEX_REQUEUE"); + pem->flags |= LINUX_XDEPR_REQUEUEOP; + LIN_SDT_PROBE0(futex, linux_futex, + deprecated_requeue); + } + + /* + * The above is true, however musl libc does make use of the + * futex requeue operation, allow operation for brands which + * set LINUX_BI_FUTEX_REQUEUE bit of Brandinfo flags. + */ + p = td->td_proc; + Elf_Brandinfo *bi = p->p_elf_brandinfo; + if (bi == NULL || ((bi->flags & LINUX_BI_FUTEX_REQUEUE)) == 0) + return (EINVAL); + args->val3_compare = false; + /* FALLTHROUGH */ + case LINUX_FUTEX_CMP_REQUEUE: LIN_SDT_PROBE5(futex, linux_futex, debug_cmp_requeue, args->uaddr, args->val, args->val3, args->uaddr2, @@ -749,22 +779,6 @@ linux_futex(struct thread *td, struct linux_futex_args *args) } return (ENOSYS); - case LINUX_FUTEX_REQUEUE: - /* - * Glibc does not use this operation since version 2.3.3, - * as it is racy and replaced by FUTEX_CMP_REQUEUE operation. - * Glibc versions prior to 2.3.3 fall back to FUTEX_WAKE when - * FUTEX_REQUEUE returned EINVAL. - */ - pem = pem_find(td->td_proc); - if ((pem->flags & LINUX_XDEPR_REQUEUEOP) == 0) { - linux_msg(td, "unsupported FUTEX_REQUEUE"); - pem->flags |= LINUX_XDEPR_REQUEUEOP; - LIN_SDT_PROBE0(futex, linux_futex, - deprecated_requeue); - } - return (EINVAL); - case LINUX_FUTEX_WAIT_REQUEUE_PI: /* not yet implemented */ pem = pem_find(td->td_proc); @@ -921,7 +935,7 @@ retry: error); return (error); } - if (val != args->val3) { + if (args->val3_compare == true && val != args->val3) { LIN_SDT_PROBE2(futex, linux_futex, debug_cmp_requeue_value_neq, args->val, val); LINUX_CTR2(sys_futex, "CMP_REQUEUE val 0x%x != uval 0x%x", @@ -1016,6 +1030,7 @@ linux_sys_futex(struct thread *td, struct linux_sys_futex_args *args) .ts = NULL, .uaddr2 = args->uaddr2, .val3 = args->val3, + .val3_compare = true, }; struct l_timespec lts; int error; diff --git a/sys/i386/linux/linux_sysvec.c b/sys/i386/linux/linux_sysvec.c index 15fec674f8c5..3a12f4eb7689 100644 --- a/sys/i386/linux/linux_sysvec.c +++ b/sys/i386/linux/linux_sysvec.c @@ -1096,7 +1096,8 @@ static Elf32_Brandinfo linux_muslbrand = { .sysvec = &elf_linux_sysvec, .interp_newpath = NULL, .brand_note = &linux_brandnote, - .flags = BI_CAN_EXEC_DYN | BI_BRAND_NOTE + .flags = BI_CAN_EXEC_DYN | BI_BRAND_NOTE | + LINUX_BI_FUTEX_REQUEUE }; Elf32_Brandinfo *linux_brandlist[] = {