From patchwork Thu Apr 27 20:06:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "H.J. Lu" X-Patchwork-Id: 68401 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 9002D3858C27 for ; Thu, 27 Apr 2023 20:06:41 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9002D3858C27 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1682626001; bh=1RxIQB6Hvb3j3PMIHO2AUZns26UOekbl8WJiDuXshHE=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=hSGYiILg43fwcrTjHOwhMatNhZeFcltgwX7TjWrwdWIuy3Hu0AEUAlL0hTB9jRT2e e4Ht0ODsu38gqkaabXSebqBpfbKn9yj4zSXhqI4omd3tOpjO7fa6jD9QmTS8RmA5l6 BwWiJrAje/LQk7+FqvQ7iX5CnWCk2612WjnMgGqs= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pf1-x42b.google.com (mail-pf1-x42b.google.com [IPv6:2607:f8b0:4864:20::42b]) by sourceware.org (Postfix) with ESMTPS id 9655B3858D37 for ; Thu, 27 Apr 2023 20:06:18 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9655B3858D37 Received: by mail-pf1-x42b.google.com with SMTP id d2e1a72fcca58-63b4bf2d74aso6889908b3a.2 for ; Thu, 27 Apr 2023 13:06:18 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682625977; x=1685217977; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=1RxIQB6Hvb3j3PMIHO2AUZns26UOekbl8WJiDuXshHE=; b=SURjU2K3wcLaUDN8D8zmXGyi+EcTnQ8VNXxJwU7ZSkO6smnHVfyWXCaLOOLTNa8R3o aIRZv3F/5tX1SgpTJ++dg5DtrH8kJA4ZWFQoFsjstyX3hcMQFlzpYe3vIOAw8YFs42Hq Iqjn5y0vMA1KrjnnEIfj4sK2VmhZJ5OeOW/VVAfZU+Qi1Tikl7JjGOAmOqw496FogMBq ep8OLukXsaoDDpGgWbFt2207dyKEKk4K+T43L8/MfkBRMPhWxU1qw4Dl6LYQW2aVB9vO efcddIXn6HdJ/borK7WhgS4/CipB/eIT++KVoXSz++iIjH1TTMSHAfDLWI4gSZJ21tuC 3C8A== X-Gm-Message-State: AC+VfDwXQ176Bd7MAG95j/X9cr1GpX53dh4279KoozR52/rsA6/r2zCz zM1z5rgQyxcpDiqrsMhPApx5gkQWKIc= X-Google-Smtp-Source: ACHHUZ5SAekCzTkdyXyZpJpDyuZ9tDGn2nVEzPwTpruz/oqEAiWm1ZZj79fUNynq+Z6eLiwXM7yF1g== X-Received: by 2002:a05:6a00:22d3:b0:63b:89a2:d624 with SMTP id f19-20020a056a0022d300b0063b89a2d624mr4453518pfj.12.1682625977234; Thu, 27 Apr 2023 13:06:17 -0700 (PDT) Received: from gnu-cfl-3.localdomain ([172.59.161.224]) by smtp.gmail.com with ESMTPSA id y5-20020a056a00180500b0063b733fdd33sm13588492pfa.89.2023.04.27.13.06.16 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Apr 2023 13:06:16 -0700 (PDT) Received: from gnu-cfl-3.. (localhost [IPv6:::1]) by gnu-cfl-3.localdomain (Postfix) with ESMTP id 6645174009A for ; Thu, 27 Apr 2023 13:06:15 -0700 (PDT) To: libc-alpha@sourceware.org Subject: [PATCH] __check_pf: Add a cancellation cleanup handler [BZ #20975] Date: Thu, 27 Apr 2023 13:06:15 -0700 Message-Id: <20230427200615.1496059-1-hjl.tools@gmail.com> X-Mailer: git-send-email 2.40.0 MIME-Version: 1.0 X-Spam-Status: No, score=-3025.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: "H.J. Lu via Libc-alpha" From: "H.J. Lu" Reply-To: "H.J. Lu" Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" 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. --- 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 aec7a94785..0160be8790 100644 --- a/sysdeps/unix/sysv/linux/Makefile +++ b/sysdeps/unix/sysv/linux/Makefile @@ -529,6 +529,8 @@ sysdep_headers += \ sysdep_routines += \ netlink_assert_response \ # sysdep_routines + +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 b157c5126c..2b0b8b6368 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)