From nobody Sun Sep 18 00:34:42 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 4MVTN25Hslz4cKr8; Sun, 18 Sep 2022 00:34:42 +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 4MVTN24cR6z4Jlf; Sun, 18 Sep 2022 00:34:42 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1663461282; 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=b4Rlel0C+IzDiPSCtCMecaca+pZt+OtS0dVHJL0L3cc=; b=t5LjNmJG7orsjqNuogIN/jhiidkKQoYqWVWuUAwp9L4++CPk/auuJEhSNQP7pkmeKtiUn/ iE5oc6cRlCW3Jeuz6eA7y//dNOoo1jYKsAgVZGhHmIS59dxtW/GPFTQ0iEPRBYDRqJ92Do wNG2YrxCINkTLHnb71xamEYLrRYFou17I5bR/sjS0l/Q1nuqmkim0Co6BxwAMVp9vy3Zhj VJYDYWWnnJpO7nl8MDrQUnNWUoHhTs2DMS9jM2LuMXcqeElJeTGc23f3FRv/PyGQ5swQBS zR2uRs9BV8jHaP3yD51dNEwPX1XiSDgxsiHIRZap8jVnK9KaUyk0SLszZwHvcg== 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 4MVTN23ggMzsFk; Sun, 18 Sep 2022 00:34:42 +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 28I0Ygwa033419; Sun, 18 Sep 2022 00:34:42 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 28I0Ygqm033418; Sun, 18 Sep 2022 00:34:42 GMT (envelope-from git) Date: Sun, 18 Sep 2022 00:34:42 GMT Message-Id: <202209180034.28I0Ygqm033418@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Konstantin Belousov Subject: git: 982584532dc3 - stable/13 - rtld: mask signals for default read locks 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: kib X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 982584532dc3c8fba292b370c8444f6a2b3f3010 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1663461282; 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=b4Rlel0C+IzDiPSCtCMecaca+pZt+OtS0dVHJL0L3cc=; b=o9r0zbu2adqQokMqSRzIW5TiZjnG719REN+WqMa+/jVZXQpTPcpKoB1yUYJYRTn9SUkIvB 5ix14Uwki0/uikKSqnsMreD2jTcEej9BEfUHEi+ZxObhBH/HG/+2HUbhVLFKAM2Lu74S1f W1g/8P1bdIHSzj8Xcx9uW7xOZNbhhGaH1yoPAHf9gyBgsFm+/QmGaV4BCz6+ZTu4iDor20 OnMJor4Wv7sm7RquwidV7o044Husck5wCnUQ34Bd/ZfIL74ojGbXkS3KGdpEfDuhOYYbnT 0yadDSY/nMzZ/ej8OXYb9sY5eNlHKt47hdvnHgYQnFuCYSecvqvqM2mgFuxXEg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1663461282; a=rsa-sha256; cv=none; b=Sl4lOIjKQQNiA6yBvOquF9czH2p0/h/O921xO671+73AR+Fu+SO2oM+ABpHN1CZO/+96Io cIuA2INN0liUjwquwOBF0q7gGILpKqpHGPABpyj4xDw6xtl6B/GBA+OJ3zvBHHfLu3eNGK Egxb7Canb9sqTegU4M0MUndj9Vn4WYX66tHM4QIKl7eEqEQdj5UyF7V74ctQEfdDVYDYAB wn4eUDKM9bOut2Y+BjTiFplTH12eTue6sz0LWVpjQNeGQ5p4/xK+/WJRPOven7zsggtDWA BZYkqFNEDrcVUrk5zsJQ7FoZmzUxe0bNkSkhT2nTlRM77Z6HG3rUxwWJPWgUBQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=982584532dc3c8fba292b370c8444f6a2b3f3010 commit 982584532dc3c8fba292b370c8444f6a2b3f3010 Author: Konstantin Belousov AuthorDate: 2022-08-30 12:46:30 +0000 Commit: Konstantin Belousov CommitDate: 2022-09-18 00:33:45 +0000 rtld: mask signals for default read locks (cherry picked from commit a687683b997c5805ecd6d8278798b7ef00d9908f) --- libexec/rtld-elf/rtld_lock.c | 60 ++++++++++++++++++++++++++------------------ 1 file changed, 36 insertions(+), 24 deletions(-) diff --git a/libexec/rtld-elf/rtld_lock.c b/libexec/rtld-elf/rtld_lock.c index e501c03f0722..8b9a6a51e061 100644 --- a/libexec/rtld-elf/rtld_lock.c +++ b/libexec/rtld-elf/rtld_lock.c @@ -124,16 +124,6 @@ def_lock_destroy(void *lock) free(l->base); } -static void -def_rlock_acquire(void *lock) -{ - Lock *l = (Lock *)lock; - - atomic_add_acq_int(&l->lock, RC_INCR); - while (l->lock & WAFLAG) - ; /* Spin */ -} - static void sig_fastunblock(void) { @@ -145,24 +135,37 @@ sig_fastunblock(void) __sys_sigfastblock(SIGFASTBLOCK_UNBLOCK, NULL); } +static bool +def_lock_acquire_set(Lock *l, bool wlock) +{ + if (wlock) { + if (atomic_cmpset_acq_int(&l->lock, 0, WAFLAG)) + return (true); + } else { + atomic_add_acq_int(&l->lock, RC_INCR); + if ((l->lock & WAFLAG) == 0) + return (true); + atomic_add_int(&l->lock, -RC_INCR); + } + return (false); +} + static void -def_wlock_acquire(void *lock) +def_lock_acquire(Lock *l, bool wlock) { - Lock *l; sigset_t tmp_oldsigmask; - l = (Lock *)lock; if (ld_fast_sigblock) { for (;;) { atomic_add_32(&fsigblock, SIGFASTBLOCK_INC); - if (atomic_cmpset_acq_int(&l->lock, 0, WAFLAG)) + if (def_lock_acquire_set(l, wlock)) break; sig_fastunblock(); } } else { for (;;) { sigprocmask(SIG_BLOCK, &fullsigmask, &tmp_oldsigmask); - if (atomic_cmpset_acq_int(&l->lock, 0, WAFLAG)) + if (def_lock_acquire_set(l, wlock)) break; sigprocmask(SIG_SETMASK, &tmp_oldsigmask, NULL); } @@ -171,21 +174,30 @@ def_wlock_acquire(void *lock) } } +static void +def_rlock_acquire(void *lock) +{ + def_lock_acquire(lock, false); +} + +static void +def_wlock_acquire(void *lock) +{ + def_lock_acquire(lock, true); +} + static void def_lock_release(void *lock) { Lock *l; l = (Lock *)lock; - if ((l->lock & WAFLAG) == 0) - atomic_add_rel_int(&l->lock, -RC_INCR); - else { - atomic_add_rel_int(&l->lock, -WAFLAG); - if (ld_fast_sigblock) - sig_fastunblock(); - else if (atomic_fetchadd_int(&wnested, -1) == 1) - sigprocmask(SIG_SETMASK, &oldsigmask, NULL); - } + atomic_add_rel_int(&l->lock, -((l->lock & WAFLAG) == 0 ? + RC_INCR : WAFLAG)); + if (ld_fast_sigblock) + sig_fastunblock(); + else if (atomic_fetchadd_int(&wnested, -1) == 1) + sigprocmask(SIG_SETMASK, &oldsigmask, NULL); } static int