From nobody Wed Oct 28 20:35:53 2026 X-Original-To: dev-commits-src-branches@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 4jFJzG2j5fz6x6BW for ; Wed, 28 Oct 2026 20:35:54 +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) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 4jFJzG0Cw9z4RGB for ; Wed, 28 Oct 2026 20:35:54 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1793219754; 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=0ltBP124aN2es9qIksdkqql1mW8FrlXZaKSW7hfuimg=; b=N39e0bB5BZl5dulZVjV2qoszNdSSIJxLTPlQ73POKR1bfsradREuuew5bSor1PV1ii88hg Uga26Dx2uC3LcvMzxqNfkrPexoq9Uac5AdaU6gxU3ngBze7tJZCzA49y0JwQpRLHKWQxTx SqRjarfeqVSs3A60Dp+PRkZhNqUrWiD9AeqbzPmBLbHzalO+8Lnukpd4AzaY0ivNR5mIYn AUoK2jAsqxr0WmBPr2C+lwxLsevSuB9shKFtlefhNQAHz0N6uEkpIl9utjBqNjjnoHm7LY aomi5H6szeIPUz9KYHYvnAB4beUpiMap5DVW0O/xboXyw8UJzZTIbcsaLiddcQ== ARC-Seal: i=1; a=rsa-sha256; d=freebsd.org; s=dkim; cv=none; t=1793219754; b=jw3lrOW4AJtAyeoAOABOXkOXaSSSmCbfBVn7GqhSomIKHsq8F1sOgx8XBCo5kfCKv5z8Sw U2HRjP0SXBcKo5aG/BPxF5X7wpENqwwqoTQ3mVem/e35ZgU7qHCCp2KBURuq7fHto86u5J BE5i3ydsGuTAAQehb3Mu4s4rWsANmW57B8UamyI81LRzDtxevDzJ46scYw2aSxwZiReuK2 Qx/k/y1Obb5VxXfxAy5Rcoh+KgXc9LShuRuOdlSki/ovzngdVXRcum31EgCTnfDZZ1mycX 9FyJazyjAus6k7iU2bgUAuUyMrv3pStm9zkfvtL2sk0Ik4SbDuq8af4KujqUvA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1793219754; 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=0ltBP124aN2es9qIksdkqql1mW8FrlXZaKSW7hfuimg=; b=bCCd+zA+0oknFLx7+sgoJEbrB3UdN0yvsbUlb/zKCKM6zHGDj7oujwda+08pMiJNZxagIE 13HokhP1rXIhhJbgzIeskDzSX0TKR5K+h2LZs6HJq6bhxAjhZ+mbBnppWHoCRPn0XF1Ew/ Vdl1O0o4v9sV3IRl7X3tGWuT4Kolv8F99RdbPGX/PlGbC69f51qNPSKj7dYvjzwc9+IFo/ tvY3os3nBDHjCcBbUtFeUDUcIWWBxb8LLAtXfLr9MSzo3JsqxFhMyWwOR/nQvCFAUHnSAe cU8FV9ZdeQXdg0eNM3nfClRzKJf6WKWeyUYT6ObCXp+lKZHYgnYNyMXoSlPEIw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4jFJzF70lvz1N4q for ; Wed, 28 Oct 2026 20:35:53 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 1d626 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Wed, 28 Oct 2026 20:35:53 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: R. Christian McDonald Subject: git: 70700e989983 - stable/15 - rms: Order a writer's stores before its readers see it leave List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches X-BeenThere: dev-commits-src-branches@freebsd.org Sender: owner-dev-commits-src-branches@FreeBSD.org List-Id: Commits to the stable branches of the FreeBSD src repository List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: rcm X-Git-Repository: src X-Git-Refname: refs/heads/stable/15 X-Git-Reftype: branch X-Git-Commit: 70700e98998325ad88ae7f230c21ea44806d4032 Auto-Submitted: auto-generated Date: Wed, 28 Oct 2026 20:35:53 +0000 Message-Id: <6ae25ca9.1d626.7ea2ad85@gitrepo.freebsd.org> The branch stable/15 has been updated by rcm: URL: https://cgit.FreeBSD.org/src/commit/?id=70700e98998325ad88ae7f230c21ea44806d4032 commit 70700e98998325ad88ae7f230c21ea44806d4032 Author: R. Christian McDonald AuthorDate: 2026-10-12 20:44:32 +0000 Commit: R. Christian McDonald CommitDate: 2026-10-28 20:34:12 +0000 rms: Order a writer's stores before its readers see it leave Readers check rms->writers without a fence, and rms_wunlock() drops it with a plain store. rms_wlock() interrupts every CPU before the first writer blocks readers, but nothing orders them when the last writer leaves: on a weakly ordered CPU a reader can see the count reach zero and still read what the writer replaced, such as callbacks of a module unloaded under the lock. Fence every CPU before the last writer drops the count: rename rms_wlock_switch() to rms_block_readers() and add rms_unblock_readers(), a wrapper for cpus_fence_seq_cst(). Readers stay fence-free; the cost lands on the rare unlock. Reviewed by: mjg Discussed with: kib Fixes: 1f162fef76a0 ("Add read-mostly sleepable locks") MFC after: 2 weeks Sponsored by: Rubicon Communications, LLC ("Netgate") Differential Revision: https://reviews.freebsd.org/D60658 (cherry picked from commit 2b911d947b5c1157a495454123ea972a18e4743d) --- sys/kern/kern_rmlock.c | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/sys/kern/kern_rmlock.c b/sys/kern/kern_rmlock.c index 7206572ffc02..fb75c0c0ba49 100644 --- a/sys/kern/kern_rmlock.c +++ b/sys/kern/kern_rmlock.c @@ -875,7 +875,9 @@ db_show_rm(const struct lock_object *lock) * * Neither rms_rlock nor rms_runlock use thread fences. Instead interrupt * fences are inserted to ensure ordering with the code executed in the IPI - * handler. + * handler. Writers interrupt all CPUs both to block readers and to unblock + * them, so a reader that sees no writer also sees what the last writer + * stored. * * No attempt is made to track which CPUs read locked at least once, * consequently write locking sends IPIs to all of them. This will become a @@ -1171,7 +1173,7 @@ rms_assert_no_pcpu_readers(struct rmslock *rms) #endif static void -rms_wlock_switch(struct rmslock *rms) +rms_block_readers(struct rmslock *rms) { struct rmslock_ipi rmsipi; @@ -1188,6 +1190,19 @@ rms_wlock_switch(struct rmslock *rms) &rmsipi.srcra); } +/* + * Order the writer's stores before the count readers check without a fence. + */ +static void +rms_unblock_readers(struct rmslock *rms) +{ + + MPASS(rms->readers == 0); + MPASS(rms->writers == 1); + + cpus_fence_seq_cst(); +} + void rms_wlock(struct rmslock *rms) { @@ -1210,7 +1225,7 @@ rms_wlock(struct rmslock *rms) KASSERT(rms->owner == RMS_NOOWNER, ("%s: unexpected owner value %p\n", __func__, rms->owner)); - rms_wlock_switch(rms); + rms_block_readers(rms); rms_assert_no_pcpu_readers(rms); if (rms->readers > 0) { @@ -1235,6 +1250,8 @@ rms_wunlock(struct rmslock *rms) ("%s: unexpected owner value %p\n", __func__, rms->owner)); MPASS(rms->writers >= 1); MPASS(rms->readers == 0); + if (rms->writers == 1) + rms_unblock_readers(rms); rms->writers--; if (rms->writers > 0) { wakeup_one(&rms->owner);