From nobody Fri Mar 22 18:40:17 2024 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 4V1WNK3LJBz5F4BD; Fri, 22 Mar 2024 18:40:17 +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 4V1WNK2TVRz4rvD; Fri, 22 Mar 2024 18:40:17 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1711132817; 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=RLkmp0rQv8aIxdp9Dn+bEyfb5v+z9h52PLnxG7AAsA0=; b=MeCeuOJPHlL2XTHZRPlP86cIWTjuQzAgnHwkZnOXx+Qra7tY3/PezvB4F7wYfTEtBdf4Ot 2Stx0D/GAWT5RiFKTvK4U2p/CrI2IUwoo+NAyEJWLqD1T+C3C3uA3J6y9GIPk+mn+Tqdmn LVEDUaTm73lnaviXY9cOSdBu+Auqcbanx/aAnjHyEbigrBfNLv2UR27X3rqPubfGmyX4Ra x919+NyXFRRvjIkFXme5zXzDG8ck8sfmx52ZjzH3DnvR/Gk/wNo1COcoC2z+1cSOIecx63 +BcRIMBujibhaGo4HeyaBizb6LixK/JBGZb1Zmcw6do1LcrCUaI07bHSJJkdLw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1711132817; a=rsa-sha256; cv=none; b=YXO7NvcJAe3gUcB4NllotX54gbxuAQHnMBv9UNRg52gIKeWFXj1tPrM37YyK5f5ZmCDl+6 pr1yOxcSpAzavb6qLhas2LTpDC2ujoNlyL6pTz5hS3RGoegSxtwWpeTLAYSoZzDEtdghlr uD9YY22Jm9ojf9BNi8831lxdHR4WnFnCqh4aYR+V62MXT/1XZzUtZzYkW7y8Kwbzxs7lYW dFHJ9BA6YicePicOMrHOBM21b2dBXXhumJtUk20FQkBV7ntMpLsSyhAWX9sJTVUINcqu71 f/0AMzgou2ItGhkTkJ9PSdxRKho88w5rUNZg1SgObkhQ8UnPbfmIhHNyabAfeg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1711132817; 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=RLkmp0rQv8aIxdp9Dn+bEyfb5v+z9h52PLnxG7AAsA0=; b=uU2xgjH8Eoo98VY/iGRWNSqTYudgkkD9eq2I6PhIPzdFdPWPUV2zAMdBpgQuRJ//JKj27d HtPbrH99lzYmj0YLxtE19G7yeFxH4vuBVeliWRgLQ5K7ZmMr9sTUUCYIBbrQ9hytLMNvAu vOR1bzLjBOXhVOh0UBCL2W6k+LIQQ+FlUqu/C+BJBUXo7mM45rr9e2E/k1ii8HshJtbXsR nKw0YqsPOkct77L8Fl5Fl/IRKGAahSNrlTtZoZ5JPx77AqEctplKD+zE9FgxdGyWzy+gUp gjxF91fz0ziF1SF53DZ27eYGCy3UrFfRdEcDQrCIhmFORVTjpbWAUkvKvYokhg== 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 4V1WNK22G6zFnM; Fri, 22 Mar 2024 18:40:17 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 42MIeHlx021561; Fri, 22 Mar 2024 18:40:17 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 42MIeHce021553; Fri, 22 Mar 2024 18:40:17 GMT (envelope-from git) Date: Fri, 22 Mar 2024 18:40:17 GMT Message-Id: <202403221840.42MIeHce021553@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Kyle Evans Subject: git: 590e02d3c088 - stable/14 - if_wg: use proper barriers around pkt->p_state 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: kevans X-Git-Repository: src X-Git-Refname: refs/heads/stable/14 X-Git-Reftype: branch X-Git-Commit: 590e02d3c088b220c19d53ce40a5aecc6fa099e4 Auto-Submitted: auto-generated The branch stable/14 has been updated by kevans: URL: https://cgit.FreeBSD.org/src/commit/?id=590e02d3c088b220c19d53ce40a5aecc6fa099e4 commit 590e02d3c088b220c19d53ce40a5aecc6fa099e4 Author: Kyle Evans AuthorDate: 2024-03-15 01:19:18 +0000 Commit: Kyle Evans CommitDate: 2024-03-22 15:21:39 +0000 if_wg: use proper barriers around pkt->p_state Without appropriate load-synchronization to pair with store barriers in wg_encrypt() and wg_decrypt(), the compiler and hardware are often allowed to reorder these loads in wg_deliver_out() and wg_deliver_in() such that we end up with a garbage or intermediate mbuf that we try to pass on. The issue is particularly prevalent with the weaker memory models of !x86 platforms. Switch from the big-hammer wmb() to more explicit acq/rel atomics to both make it obvious what we're syncing up with, and to avoid somewhat hefty fences on platforms that don't necessarily need this. With this patch, my dual-iperf3 reproducer is dramatically more stable than it is without on aarch64. PR: 264115 Reviewed by: andrew, zlei (cherry picked from commit 3705d679a6344c957cae7a1b6372a8bfb8c44f0e) --- sys/dev/wg/if_wg.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/sys/dev/wg/if_wg.c b/sys/dev/wg/if_wg.c index c324b5fb048b..25fa53c2e672 100644 --- a/sys/dev/wg/if_wg.c +++ b/sys/dev/wg/if_wg.c @@ -1515,8 +1515,7 @@ wg_encrypt(struct wg_softc *sc, struct wg_packet *pkt) state = WG_PACKET_CRYPTED; out: pkt->p_mbuf = m; - wmb(); - pkt->p_state = state; + atomic_store_rel_int(&pkt->p_state, state); GROUPTASK_ENQUEUE(&peer->p_send); noise_remote_put(remote); } @@ -1588,8 +1587,7 @@ wg_decrypt(struct wg_softc *sc, struct wg_packet *pkt) state = WG_PACKET_CRYPTED; out: pkt->p_mbuf = m; - wmb(); - pkt->p_state = state; + atomic_store_rel_int(&pkt->p_state, state); GROUPTASK_ENQUEUE(&peer->p_recv); noise_remote_put(remote); } @@ -1645,7 +1643,7 @@ wg_deliver_out(struct wg_peer *peer) wg_peer_get_endpoint(peer, &endpoint); while ((pkt = wg_queue_dequeue_serial(&peer->p_encrypt_serial)) != NULL) { - if (pkt->p_state != WG_PACKET_CRYPTED) + if (atomic_load_acq_int(&pkt->p_state) != WG_PACKET_CRYPTED) goto error; m = pkt->p_mbuf; @@ -1687,7 +1685,7 @@ wg_deliver_in(struct wg_peer *peer) struct epoch_tracker et; while ((pkt = wg_queue_dequeue_serial(&peer->p_decrypt_serial)) != NULL) { - if (pkt->p_state != WG_PACKET_CRYPTED) + if (atomic_load_acq_int(&pkt->p_state) != WG_PACKET_CRYPTED) goto error; m = pkt->p_mbuf;