From nobody Fri Mar 15 01:25:51 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 4Twmlz2Qfkz5F0QK; Fri, 15 Mar 2024 01:25:51 +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 4Twmlz1wm7z478T; Fri, 15 Mar 2024 01:25:51 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1710465951; 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=kd5frK3YffxEvHN9C/FozSpVLLUfaWt+r6aHQUEmqu4=; b=Ixg25t1yCp1i9PYl/OjQsRUoZanvVJ665H9Xer0X0f92k37Pz734QAFhjXKy4cnTmGvlk5 Om548HNk7U2vWyg3a5CrxauGrllJ6USD/eSsKjYkSkDjDlvQa/oKwhMvXpQZ593AZEcfzT Qq00QZl74aIrfGpxIAb+25W4GIQNLf8Qt8dg4inMHSlFV0CY7Khd2vQAmRvsCFMjgvJ0tU JW5j9fPK7OqVKHm9XWlrJM0vitrpLWFhPFWZtkLBEVVM6FfK0V34mHl4nhc0LMLf9b6HGr XeJSrC2iEoZa34HnLLiwu9PQOgx4QXIXHtgpHGQVOM5anr5ZByxUlqvbjpLDxQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1710465951; a=rsa-sha256; cv=none; b=DfeeidtHBegRaAFLEt8KFd92KF8rS9xyRpVVAMenIhcdq9yFmtL/bCEnpNRjEjkibjzDwu F2Vhamm+7X68wUKRkOA/7goe2+5qHc4oeDG5WlfD87hcjjYzvr0rHAJTcMAI22w82mhhNy uhxrwKsnENvHrgkR040fkQF4wIPVesalvUrAukEkvBahpV+WoJMxMwouZJnqLfECJ8jHTd bjggbmpjmfuEIGZpMrgaFeTQdChT7Cf4YQDKuIhZbnsgOV2icaUbV0uZSlM4LoTubRiiWe uUtFE1cd9sDJIEdWKj6bjZbiPq0PDGGzxwI9x25mfYYDHZPJWnXHYfJe/05DaQ== 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=1710465951; 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=kd5frK3YffxEvHN9C/FozSpVLLUfaWt+r6aHQUEmqu4=; b=T5zSt0Ju1smUaL3FKxN453raBTgxO+9ajctjsyVCsup+yxjUl91Hh9glrA0aiVhi+2rWQk AhOzetkbYjAaAee9DOYtOKBFkiFxwwckim1y2fnV93phK2zJFq1ZxzkYzn+Xa5DS5lmrFZ /28leBx/QCDczti6+oR7CVVCBYpn3q+aBuQg6rS5z75HPqXJxiYxk3EzOmnP314Jww3Yez GlAt7jQ4KvcHR/DISZUI0Z2OGNXAohEJH1mXVT7JZrybb1V4n7u8GQuXyzU1hthOO0STIl LGBnP1VyIZD3BGQwUdolv+HMQIGdrnDaWvRU352fYMtXdBtrhPhJtEtMM4mFTA== 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 4Twmlz1XG8zrTJ; Fri, 15 Mar 2024 01:25:51 +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 42F1PpwH028446; Fri, 15 Mar 2024 01:25:51 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 42F1PpGr028443; Fri, 15 Mar 2024 01:25:51 GMT (envelope-from git) Date: Fri, 15 Mar 2024 01:25:51 GMT Message-Id: <202403150125.42F1PpGr028443@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Kyle Evans Subject: git: 3705d679a634 - main - 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/main X-Git-Reftype: branch X-Git-Commit: 3705d679a6344c957cae7a1b6372a8bfb8c44f0e Auto-Submitted: auto-generated The branch main has been updated by kevans: URL: https://cgit.FreeBSD.org/src/commit/?id=3705d679a6344c957cae7a1b6372a8bfb8c44f0e commit 3705d679a6344c957cae7a1b6372a8bfb8c44f0e Author: Kyle Evans AuthorDate: 2024-03-15 01:19:18 +0000 Commit: Kyle Evans CommitDate: 2024-03-15 01:19:21 +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 MFC after: 1 week Reviewed by: andrew, zlei Differential Revision: https://reviews.freebsd.org/D44283 --- 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 c7649e2b4059..42c426ac1819 100644 --- a/sys/dev/wg/if_wg.c +++ b/sys/dev/wg/if_wg.c @@ -1517,8 +1517,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); } @@ -1590,8 +1589,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); } @@ -1647,7 +1645,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; @@ -1689,7 +1687,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;