From nobody Sat Sep 24 13:38:15 2022 X-Original-To: dev-commits-src-main@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 4MZVTM5b4Rz4ch3J; Sat, 24 Sep 2022 13:38:15 +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 4MZVTM51g7z41qT; Sat, 24 Sep 2022 13:38:15 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1664026695; 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=UJg0WeffbULKWNKojluqZkXiuYWjoDo9RT/PK9OLCsU=; b=IScO7vm69anQgisR2wbz9t7tnj6As4lYsTi4dqWVYLbJLr13jzmxYlCMglEAayVbAOPAfk yYKg9NzkSJo1mfgUfoAZIyuiOT0k2fEiEUesO46c3DMZ9hFwtmIZdpgcIYT9dpn3vEjy1F 6WCTrtMi9VixFCpkSN7W7v8pKVVUlCQ5oiOcqVoyHEKsgjzJL//11jdoSK5078PiXNy2Q0 nBTVc42l26ZC92/ar3UMX1G0oHr4EzumksWpnsbIssxRXIHS3NoiWD96W56Zz2VykPYtFL OOXt4T3zYfXsih65NkD9XIrwr6rddGK/UhxUAtdd9MA4jY6TnbAso608APYpWA== 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 4MZVTM3qhXz15Xr; Sat, 24 Sep 2022 13:38:15 +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 28ODcFB8023558; Sat, 24 Sep 2022 13:38:15 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 28ODcFWt023557; Sat, 24 Sep 2022 13:38:15 GMT (envelope-from git) Date: Sat, 24 Sep 2022 13:38:15 GMT Message-Id: <202209241338.28ODcFWt023557@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Mark Johnston Subject: git: 8694fd333556 - main - smr: Fix synchronization in smr_enter() List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@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/main X-Git-Reftype: branch X-Git-Commit: 8694fd333556addb97acfff1feca6a1e389201ce Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1664026695; 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=UJg0WeffbULKWNKojluqZkXiuYWjoDo9RT/PK9OLCsU=; b=TVjkXkb7pRG1vo+iRqPPZVF0i70HZqOXzGbmnGjftfzFV+XM73n+xzbKz+Giu6TxPiZPdZ /7SVsSHuXhygzBTp3c65ERrDzlGeoflk4+SsGia1+POzLvvVK/YsBejM+4Tvehn60S0bu4 vxCFPuGSuBOApaa6oXG1Pxq38Jio1aFTf85najR5KCDqiiZXnzqBULTFzXsE3gi7+p8YNG jA1dxl2TUojiyQE0DGvvzOjNtJd11uZIYaYBDmnaOYpXmOcQVKbEkXrjguWrCeFOXdSq/j ph2g+fFn0xoSmDNTCAoUNIf1zm4gpQ78B3i3Q2wh61ugggm/jeXgETmDEO3Yyw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1664026695; a=rsa-sha256; cv=none; b=E/WcNG0/GL/yRc1ce8qw74nrfH9NPXGMetFbGSy9liWVuDjc7kR9dXzgVA1Gpn4nkRO74q 2EXFrzgzQm6Few5+1pjwVHf0aBx6QZfFV1e7K5qFhYD/Ky3YL74gk75kGGCoXdWhfyxrnu zd3Tg/TjP9iKdYtgCR2yxfScqeNwSoJQ2+WbEUh8kOPxzH3bhrGWKwn6yninC+AgLh903n gcNzLjy7LopCDB8hC+IWBc2GAexBScHJ9PmZEC7HHxVRsow1yqH89X9LOI2UIRTwCD0Lf2 LiPkhxSX/DuM00qOCH/kycIn9UzCk6blAYG/sVw1zls/7SDR0+mLjAf7lHAV6A== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=8694fd333556addb97acfff1feca6a1e389201ce commit 8694fd333556addb97acfff1feca6a1e389201ce Author: Mark Johnston AuthorDate: 2022-09-24 13:18:04 +0000 Commit: Mark Johnston CommitDate: 2022-09-24 13:18:04 +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 MFC after: 2 weeks Differential Revision: https://reviews.freebsd.org/D36370 --- 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 } /*