From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-yb1-xb29.google.com (mail-yb1-xb29.google.com [IPv6:2607:f8b0:4864:20::b29]) by sourceware.org (Postfix) with ESMTPS id 4C53E3858D37; Mon, 22 May 2023 20:38:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4C53E3858D37 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-yb1-xb29.google.com with SMTP id 3f1490d57ef6-ba81ded8d3eso9664442276.3; Mon, 22 May 2023 13:38:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1684787884; x=1687379884; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=Olw8JiUsxI3P0fs5vEsObJmorB8udf0X/Wz1MZCuVCQ=; b=WqdMcoinJtjc3z4dhn5tb6Ixra1fZtHLkxEWDfglkE6HC6idHOmeYtW+4qiX1eamq9 8JHCzslh7+zuW4fgBuQ/5WczKkVW8PEM2U5418NbQk7nSNnEamroaS2WZtFWI0UUApj9 JICmfHecZlRp4FXtU7ucRHadSi3W1ad7XpA9hyh5igmj4S6xQApydLUscbwa+0rg4aeB D6/5rtyjtqO2cHBi0xEXd0rCYMfApJVgoVsCYObRtg3NEGhOxXJqHBQcdgd2rVMj/VE3 u/L1eRkW0ZV/DKqvi5ohb+pDJFEESMa9E3NseWPaULaEiMS9O3UYBztGGlJs9ZjPX5zV gfoQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684787884; x=1687379884; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Olw8JiUsxI3P0fs5vEsObJmorB8udf0X/Wz1MZCuVCQ=; b=XRUvQMJDITun0+chINIG2bz+NJR5kckaJB31XiVo3YQJp+Lc/9v3t7ni3eR8rqIrsz bxiJJ6hPxZUqAQKhXr24KYnREt4C6tN1fphuzEJMUtMlIH/lpSZgIT16dkRfvaC3wa0L dVRCMSQrASwMOLvEJW3Dvj2Bh3FzedHgvOCUNqie0t1f+U34KS3QynuCKCk+k288LpAq nTuFzzs3A0YnXqD3T0+IdRQ0tvOccr2sLN1dbIAUITOkCzRjPgyARYsy/n9SODJS0YVo JItq4ruIRS06ZgzxC+hJUqdvdGunbAxyYuy9YDTdZeQoYsZCNsADhCBLMAGyhDD9VxP3 WBWw== X-Gm-Message-State: AC+VfDyD822cjxEQCShTwXYrgkMA7JZbxCD6v5N3O7yMsb5C40fMkGtb f/4c0E/z/D8sOF45R5EP+cnGCl2yUUsE4YB+/1ullacQ X-Google-Smtp-Source: ACHHUZ5lcagvalAEO+EKgGAWqmIGF9ThNl4wzhjb5eBSwPU3RpkGWcSU2BEkp6CWdRaTZbzP1ipb10PnuPWpjguD/Xc= X-Received: by 2002:a25:71d5:0:b0:ba1:d8a6:d2b2 with SMTP id m204-20020a2571d5000000b00ba1d8a6d2b2mr12228044ybc.7.1684787884557; Mon, 22 May 2023 13:38:04 -0700 (PDT) MIME-Version: 1.0 References: <20230427200615.1496059-1-hjl.tools@gmail.com> In-Reply-To: From: "H.J. Lu" Date: Mon, 22 May 2023 13:37:28 -0700 Message-ID: Subject: Re: [PATCH] __check_pf: Add a cancellation cleanup handler [BZ #20975] To: Noah Goldstein , Libc-stable Mailing List Cc: libc-alpha@sourceware.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-3022.2 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 List-Id: On Fri, Apr 28, 2023 at 12:17=E2=80=AFPM Noah Goldstein wrote: > > On Thu, Apr 27, 2023 at 3:06=E2=80=AFPM H.J. Lu via Libc-alpha > wrote: > > > > 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 (>=3D 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 cancellati= on > > 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 +=3D \ > > sysdep_routines +=3D \ > > netlink_assert_response \ > > # sysdep_routines > > + > > +CFLAGS-check_pf.c +=3D -fexceptions > > endif > > > > # Don't compile the ctype glue code, since there is no old non-GNU C l= ibrary. > > diff --git a/sysdeps/unix/sysv/linux/check_pf.c b/sysdeps/unix/sysv/lin= ux/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 =3D NULL; > > struct cached_data *data =3D 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 !=3D NULL) > > -- > > 2.40.0 > > > > LGTM. OK for release branches? Thanks. --=20 H.J.