From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1039) id D7D8D3858D35; Tue, 23 May 2023 23:41:18 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D7D8D3858D35 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1684885278; bh=VqK4Te0a3NQ9fr4ZXTw9KR33M0S7KDgzpXta9qvHlhQ=; h=From:To:Subject:Date:From; b=jb81V0zshrVYW56jNOFnR2XCjqOLonW2XqC66ymD9vIrp1VOijdYdilaxM22pcjAa XCe8F4u/oSO0rKrwhb28sTCMHmQs3YCHSJklmHkC8Qk9B/R2UzWG8+uazr1fdWAAMZ dEL5rVaDWW2QHl4nV/UDdYtIaBA9dfabcjFz1HEU= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: H.J. Lu To: glibc-cvs@sourceware.org Subject: [glibc/release/2.33/master] __check_pf: Add a cancellation cleanup handler [BZ #20975] X-Act-Checkin: glibc X-Git-Author: H.J. Lu X-Git-Refname: refs/heads/release/2.33/master X-Git-Oldrev: 017b9df5ea2694a8dc24b81934b9c5b014040c85 X-Git-Newrev: 24302748fcf85023fd64630de241973ec17f2dc1 Message-Id: <20230523234118.D7D8D3858D35@sourceware.org> Date: Tue, 23 May 2023 23:41:18 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=24302748fcf85023fd64630de241973ec17f2dc1 commit 24302748fcf85023fd64630de241973ec17f2dc1 Author: H.J. Lu Date: Thu Apr 27 13:06:15 2023 -0700 __check_pf: Add a cancellation cleanup handler [BZ #20975] There are reports for hang in __check_pf: https://github.com/JoeDog/siege/issues/4 It is reproducible only under specific configurations: 1. Large number of cores (>= 64) and large number of threads (> 3X of the number of cores) with long lived socket connection. 2. Low power (frequency) mode. 3. Power management is enabled. While holding lock, __check_pf calls make_request which calls __sendto and __recvmsg. Since __sendto and __recvmsg are cancellation points, lock held by __check_pf won't be released and can cause deadlock when thread cancellation happens in __sendto or __recvmsg. Add a cancellation cleanup handler for __check_pf to unlock the lock when cancelled by another thread. This fixes BZ #20975 and the siege hang issue. (cherry picked from commit a443bd3fb233186038b8b483959ecb7978d1abea) Diff: --- sysdeps/unix/sysv/linux/Makefile | 2 ++ sysdeps/unix/sysv/linux/check_pf.c | 15 +++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/sysdeps/unix/sysv/linux/Makefile b/sysdeps/unix/sysv/linux/Makefile index 9531641f82..410d5c19f6 100644 --- a/sysdeps/unix/sysv/linux/Makefile +++ b/sysdeps/unix/sysv/linux/Makefile @@ -256,6 +256,8 @@ sysdep_headers += netinet/if_fddi.h netinet/if_tr.h \ netrom/netrom.h netpacket/packet.h netrose/rose.h \ neteconet/ec.h netiucv/iucv.h sysdep_routines += netlink_assert_response + +CFLAGS-check_pf.c += -fexceptions endif # Don't compile the ctype glue code, since there is no old non-GNU C library. diff --git a/sysdeps/unix/sysv/linux/check_pf.c b/sysdeps/unix/sysv/linux/check_pf.c index 9fef28b7b4..863eeadbc7 100644 --- a/sysdeps/unix/sysv/linux/check_pf.c +++ b/sysdeps/unix/sysv/linux/check_pf.c @@ -292,6 +292,14 @@ make_request (int fd, pid_t pid) return NULL; } +#ifdef __EXCEPTIONS +static void +cancel_handler (void *arg __attribute__((unused))) +{ + /* Release the lock. */ + __libc_lock_unlock (lock); +} +#endif void attribute_hidden @@ -304,6 +312,10 @@ __check_pf (bool *seen_ipv4, bool *seen_ipv6, struct cached_data *olddata = NULL; struct cached_data *data = NULL; +#ifdef __EXCEPTIONS + /* Make sure that lock is released when the thread is cancelled. */ + __libc_cleanup_push (cancel_handler, NULL); +#endif __libc_lock_lock (lock); if (cache_valid_p ()) @@ -338,6 +350,9 @@ __check_pf (bool *seen_ipv4, bool *seen_ipv6, } } +#ifdef __EXCEPTIONS + __libc_cleanup_pop (0); +#endif __libc_lock_unlock (lock); if (data != NULL)