From nobody Tue Oct 11 14:10:44 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 4MmyP063r9z4fnZs; Tue, 11 Oct 2022 14:10:44 +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 4MmyP059bxz3mPm; Tue, 11 Oct 2022 14:10:44 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1665497444; 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=kgaGvGB7YGd11JZXBl2yixCRiVbXg0uKGKG2oOW93Vk=; b=A8p4OMklKAxZiLYjC9gShrPn751phHpMd60ERUBYRoDNsq9sCr9Og2HvB2pfnAQTND08PB 3ZLN9AxNrqHklX0hmEFXY/3NXJZFGHXrAksV2iC98MkxRpXEF+PrBarU6IfFptrX1jf5i7 QaeT/4I7kgHDgj2J+QjDeKJlBFcg1Gf+Q+bFWI4RCBZOYL8rwjIM6Xtq+h8MemK1lgbCyG K/Vfx0aQFMUXcFWYHpvcehsTUrCOmw1fqR2hAHXxNUOTWvhkF/6uhUvu+7pf9uM9dZBpbf /9P1Du/mYNJRryGZM9J6UyT9kU3QZuCLJSTZLIb7i4lSqrqs4PNnXqrTgo97zg== 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 4MmyP04FmPz104y; Tue, 11 Oct 2022 14:10:44 +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 29BEAiPv022295; Tue, 11 Oct 2022 14:10:44 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 29BEAils022294; Tue, 11 Oct 2022 14:10:44 GMT (envelope-from git) Date: Tue, 11 Oct 2022 14:10:44 GMT Message-Id: <202210111410.29BEAils022294@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Mark Johnston Subject: git: 65641500dbb7 - stable/13 - smr: Fix synchronization in smr_enter() 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: markj X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 65641500dbb7a93de4a6195de90c507f9d629b84 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1665497444; 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=kgaGvGB7YGd11JZXBl2yixCRiVbXg0uKGKG2oOW93Vk=; b=YmpprAuWphgUgdvDBcwZRYwFh+DTzzaBhC1fsV9FQYEHiM2KMFoE4BxF778Pyl08Fjsb8T AC+SwhVeuKZodR20VUIdKNQWyBUW2O0lTfaCGT0cT0JhPBSjooc6X9ujjeGLar90Ftr4W4 YE9ArO3wVnofPzTI+X3Y0EQSozzRV8GQUfL1ptW/YLlkz6ALRsPjWFLNK3vU7WHUPvEspC 4KYCtdax8fY4s1aOyolPkPX3oEM4rP5EWOrYWW3Gh/n1ij5Il7sDWSo4FY8O5wCY4khG13 1y3O+HzoSCTOgi8u/AChec0Han7+KKVHCAQNt/1JwSrDPbZHCiqOmqv09OEAsQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1665497444; a=rsa-sha256; cv=none; b=ke9bSyIjDVNIEBUIFL3Kx+B8RZpq3noF2N45dTRuXt3iYGfFQlHwVTrOUe5imc7VvVdnlS VADkC+nf0Noev291zPh+uinqiQYzT2nqZs2xDrY5JtRMMBxgJQx4pDW+U5wLEK/CLMUdSF 1MYDn4VT3p3KICTaAWRPW7K7+PrPa0RxwB4f7L1ruh3FHqlgKGK94nX02tdN+xRd4ic3xS 4RuXa1JJcBLSlkq2CEe71UgEPXWng/pPjIQuPqqdwozAfbjCLTY4U9qyNgpiKuO8jO4LCO SHnXTvMEcc7sjd9qbZVsQSKpDbYmptY74yBSGGiNCYkF7EqSMc4IoqhZySGhUg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=65641500dbb7a93de4a6195de90c507f9d629b84 commit 65641500dbb7a93de4a6195de90c507f9d629b84 Author: Mark Johnston AuthorDate: 2022-09-24 13:18:04 +0000 Commit: Mark Johnston CommitDate: 2022-10-11 13:37:15 +0000 smr: Fix synchronization in smr_enter() smr_enter() must publish its observed read sequence number before issuing any subsequent memory operations. The ordering provided by atomic_add_acq_int() is insufficient on some platforms, at least on arm64, because it permits reordering of subsequent loads with the store to c_seq. Thus, use atomic_thread_fence_seq_cst() to issue a store-load barrier after publishing the read sequence number. On x86, take advantage of the fact that memory operations are not reordered with locked instructions to improve code density: we can store the observed read sequence and provide a store-load barrier with a single operation. Based on a patch from Pierre Habouzit . PR: 265974 Reviewed by: alc (cherry picked from commit 8694fd333556addb97acfff1feca6a1e389201ce) --- sys/sys/smr.h | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/sys/sys/smr.h b/sys/sys/smr.h index c110be9a66c2..1319e2bf465b 100644 --- a/sys/sys/smr.h +++ b/sys/sys/smr.h @@ -122,8 +122,12 @@ smr_enter(smr_t smr) * Frees that are newer than this stored value will be * deferred until we call smr_exit(). * - * An acquire barrier is used to synchronize with smr_exit() - * and smr_poll(). + * Subsequent loads must not be re-ordered with the store. On + * x86 platforms, any locked instruction will provide this + * guarantee, so as an optimization we use a single operation to + * both store the cached write sequence number and provide the + * requisite barrier, taking advantage of the fact that + * SMR_SEQ_INVALID is zero. * * It is possible that a long delay between loading the wr_seq * and storing the c_seq could create a situation where the @@ -132,8 +136,12 @@ smr_enter(smr_t smr) * the load. See smr_poll() for details on how this condition * is detected and handled there. */ - /* This is an add because we do not have atomic_store_acq_int */ +#if defined(__amd64__) || defined(__i386__) atomic_add_acq_int(&smr->c_seq, smr_shared_current(smr->c_shared)); +#else + atomic_store_int(&smr->c_seq, smr_shared_current(smr->c_shared)); + atomic_thread_fence_seq_cst(); +#endif } /*