From nobody Fri Oct 28 20:55:59 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 4MzZZl2tNfz4h4pM; Fri, 28 Oct 2022 20:55:59 +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 4MzZZl2GQdz4Pvx; Fri, 28 Oct 2022 20:55:59 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1666990559; 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=XBeZr/rNVRYsBAE/X7+u4qei3OwjoIlj0zfv1lu31rM=; b=qZorTSxvLYAHURF9a0ZurjEeus59tmRlilCdgBtrJj3E3YpJlPDGZPDzr8hk1QzhKuCXBr ld2t3ZZp52NvHTzQxmmyRciRxLTxzAKOXb31ATQxKy+jrbJXEPDHo99+ZcCg4KBJJHZiMh t+OdJxeiiCZ+BVXdTGqfmvOb2scYzTqvqWkWDzvoghRC43sG3dPM+Fp2WG2YpD9woVbIIA Ys3STnPn0v4hLTGYBOlN/SSPDmHAhb2zpCXoRPeCYM0LA0P1nD96amR+e36Syzv2H+yCKL sw5yJGmSH9qQ8vjb9qa6fSG+Uamge1rwXVWgrKkyrFshLVUPcS3GXD0VO+oFeA== 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 4MzZZl1Jdvzs1T; Fri, 28 Oct 2022 20:55:59 +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 29SKtxFE007156; Fri, 28 Oct 2022 20:55:59 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 29SKtxjY007155; Fri, 28 Oct 2022 20:55:59 GMT (envelope-from git) Date: Fri, 28 Oct 2022 20:55:59 GMT Message-Id: <202210282055.29SKtxjY007155@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: John Baldwin Subject: git: e32e1a160e01 - main - wg: Use atomic(9) instead of concurrency-kit atomics. 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: jhb X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: e32e1a160e01a5a0ca9e0b76ace37e58dc1379b5 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1666990559; 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=XBeZr/rNVRYsBAE/X7+u4qei3OwjoIlj0zfv1lu31rM=; b=Fd6vPAJQdBMjCzOODZjQtasU5fxon4fTr35XSt1iq+lcPGgp50YpblBjEaanNzmzVHaTyo Im/8Kk0gE+/U1MMUTxmkFpvA2ToVyhRLHyYR1VRzvDhewskshNS8Uxzzi2Ma5sAt14sudt GQ3C1a6tonZY8ulINXHZ1XlsPdvZ2n7ChIexq3ROh/Bpqn6hpCBmG7wziu3H/EDH2liUTh J7ogBFBMC2V1gaL/o49ESbMTzI3yQ0mE52C/9E4tp9N1LhuHzLJO4Uk2BFDVItr60LCD4R LOeUT5abt+16RN1d4wHfpuDx+rbE+pfXNPvV/+ua3NkIsY3HLwHLLMRpqA1giA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1666990559; a=rsa-sha256; cv=none; b=ZejFDmYnt7jVIJ8GXkut3sZukrk9bxkjHxJpwRCPyOydz3OlvCwCog0OZxV9FLw6Uk6onC f/ynzNhFKBPIAUiT+8oCcd+cYp10B9J36If3t/k5tJ2P0+n6y6j5a1stO2YFHsEY0o1ZBy wP2k3yR+0KH8NMxlP4bRVnrpuNKSC9Y9EOlraY90UcYK4JoRb3+Abq7VoptEOlNRxTHW0Q 4BMuinlpbgqrWerVFp1BsvFqsOK/pDZ3RUDT84EwP9R/2f7Kd3bnh1wintgGjR4BljUtOy vTylPmCb+nWnMBwyDG1Mo1v2V1QBkr+BKWp/d/p7rHgiCiHQ6X5gTqEm9+l1/Q== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by jhb: URL: https://cgit.FreeBSD.org/src/commit/?id=e32e1a160e01a5a0ca9e0b76ace37e58dc1379b5 commit e32e1a160e01a5a0ca9e0b76ace37e58dc1379b5 Author: John Baldwin AuthorDate: 2022-10-28 20:36:13 +0000 Commit: John Baldwin CommitDate: 2022-10-28 20:36:13 +0000 wg: Use atomic(9) instead of concurrency-kit atomics. Kernel sanitizers only support atomic(9) operations. Reviewed by: kevans, markj, emaste Reported by: markj Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D36910 --- sys/dev/wg/if_wg.c | 52 ++++++++++++++++++----------------- sys/dev/wg/wg_noise.c | 76 +++++++++++++++++++++++++-------------------------- 2 files changed, 65 insertions(+), 63 deletions(-) diff --git a/sys/dev/wg/if_wg.c b/sys/dev/wg/if_wg.c index 59979c087db2..59a8d949e8c1 100644 --- a/sys/dev/wg/if_wg.c +++ b/sys/dev/wg/if_wg.c @@ -769,10 +769,10 @@ wg_socket_set(struct wg_softc *sc, struct socket *new_so4, struct socket *new_so sx_assert(&sc->sc_lock, SX_XLOCKED); - so4 = ck_pr_load_ptr(&so->so_so4); - so6 = ck_pr_load_ptr(&so->so_so6); - ck_pr_store_ptr(&so->so_so4, new_so4); - ck_pr_store_ptr(&so->so_so6, new_so6); + so4 = atomic_load_ptr(&so->so_so4); + so6 = atomic_load_ptr(&so->so_so6); + atomic_store_ptr(&so->so_so4, new_so4); + atomic_store_ptr(&so->so_so6, new_so6); if (!so4 && !so6) return; @@ -877,8 +877,8 @@ wg_send(struct wg_softc *sc, struct wg_endpoint *e, struct mbuf *m) sa = &e->e_remote.r_sa; NET_EPOCH_ENTER(et); - so4 = ck_pr_load_ptr(&so->so_so4); - so6 = ck_pr_load_ptr(&so->so_so6); + so4 = atomic_load_ptr(&so->so_so4); + so6 = atomic_load_ptr(&so->so_so6); if (e->e_remote.r_sa.sa_family == AF_INET && so4 != NULL) ret = sosend(so4, sa, NULL, m, control, 0, curthread); else if (e->e_remote.r_sa.sa_family == AF_INET6 && so6 != NULL) @@ -931,7 +931,7 @@ out: static void wg_timers_enable(struct wg_peer *peer) { - ck_pr_store_bool(&peer->p_enabled, true); + atomic_store_bool(&peer->p_enabled, true); wg_timers_run_persistent_keepalive(peer); } @@ -950,9 +950,9 @@ wg_timers_disable(struct wg_peer *peer) * * We should also pull NET_EPOCH_WAIT out of the FOREACH(peer) loops, but the * performance impact is acceptable for the time being. */ - ck_pr_store_bool(&peer->p_enabled, false); + atomic_store_bool(&peer->p_enabled, false); NET_EPOCH_WAIT(); - ck_pr_store_bool(&peer->p_need_another_keepalive, false); + atomic_store_bool(&peer->p_need_another_keepalive, false); callout_stop(&peer->p_new_handshake); callout_stop(&peer->p_send_keepalive); @@ -966,9 +966,9 @@ wg_timers_set_persistent_keepalive(struct wg_peer *peer, uint16_t interval) { struct epoch_tracker et; if (interval != peer->p_persistent_keepalive_interval) { - ck_pr_store_16(&peer->p_persistent_keepalive_interval, interval); + atomic_store_16(&peer->p_persistent_keepalive_interval, interval); NET_EPOCH_ENTER(et); - if (ck_pr_load_bool(&peer->p_enabled)) + if (atomic_load_bool(&peer->p_enabled)) wg_timers_run_persistent_keepalive(peer); NET_EPOCH_EXIT(et); } @@ -988,7 +988,8 @@ wg_timers_event_data_sent(struct wg_peer *peer) { struct epoch_tracker et; NET_EPOCH_ENTER(et); - if (ck_pr_load_bool(&peer->p_enabled) && !callout_pending(&peer->p_new_handshake)) + if (atomic_load_bool(&peer->p_enabled) && + !callout_pending(&peer->p_new_handshake)) callout_reset(&peer->p_new_handshake, MSEC_2_TICKS( NEW_HANDSHAKE_TIMEOUT * 1000 + arc4random_uniform(REKEY_TIMEOUT_JITTER)), @@ -1001,13 +1002,14 @@ wg_timers_event_data_received(struct wg_peer *peer) { struct epoch_tracker et; NET_EPOCH_ENTER(et); - if (ck_pr_load_bool(&peer->p_enabled)) { + if (atomic_load_bool(&peer->p_enabled)) { if (!callout_pending(&peer->p_send_keepalive)) callout_reset(&peer->p_send_keepalive, MSEC_2_TICKS(KEEPALIVE_TIMEOUT * 1000), wg_timers_run_send_keepalive, peer); else - ck_pr_store_bool(&peer->p_need_another_keepalive, true); + atomic_store_bool(&peer->p_need_another_keepalive, + true); } NET_EPOCH_EXIT(et); } @@ -1030,8 +1032,8 @@ wg_timers_event_any_authenticated_packet_traversal(struct wg_peer *peer) struct epoch_tracker et; uint16_t interval; NET_EPOCH_ENTER(et); - interval = ck_pr_load_16(&peer->p_persistent_keepalive_interval); - if (ck_pr_load_bool(&peer->p_enabled) && interval > 0) + interval = atomic_load_16(&peer->p_persistent_keepalive_interval); + if (atomic_load_bool(&peer->p_enabled) && interval > 0) callout_reset(&peer->p_persistent_keepalive, MSEC_2_TICKS(interval * 1000), wg_timers_run_persistent_keepalive, peer); @@ -1043,7 +1045,7 @@ wg_timers_event_handshake_initiated(struct wg_peer *peer) { struct epoch_tracker et; NET_EPOCH_ENTER(et); - if (ck_pr_load_bool(&peer->p_enabled)) + if (atomic_load_bool(&peer->p_enabled)) callout_reset(&peer->p_retry_handshake, MSEC_2_TICKS( REKEY_TIMEOUT * 1000 + arc4random_uniform(REKEY_TIMEOUT_JITTER)), @@ -1056,7 +1058,7 @@ wg_timers_event_handshake_complete(struct wg_peer *peer) { struct epoch_tracker et; NET_EPOCH_ENTER(et); - if (ck_pr_load_bool(&peer->p_enabled)) { + if (atomic_load_bool(&peer->p_enabled)) { mtx_lock(&peer->p_handshake_mtx); callout_stop(&peer->p_retry_handshake); peer->p_handshake_retries = 0; @@ -1072,7 +1074,7 @@ wg_timers_event_session_derived(struct wg_peer *peer) { struct epoch_tracker et; NET_EPOCH_ENTER(et); - if (ck_pr_load_bool(&peer->p_enabled)) + if (atomic_load_bool(&peer->p_enabled)) callout_reset(&peer->p_zero_key_material, MSEC_2_TICKS(REJECT_AFTER_TIME * 3 * 1000), wg_timers_run_zero_key_material, peer); @@ -1084,7 +1086,7 @@ wg_timers_event_want_initiation(struct wg_peer *peer) { struct epoch_tracker et; NET_EPOCH_ENTER(et); - if (ck_pr_load_bool(&peer->p_enabled)) + if (atomic_load_bool(&peer->p_enabled)) wg_timers_run_send_initiation(peer, false); NET_EPOCH_EXIT(et); } @@ -1124,7 +1126,7 @@ wg_timers_run_retry_handshake(void *_peer) callout_stop(&peer->p_send_keepalive); wg_queue_purge(&peer->p_stage_queue); NET_EPOCH_ENTER(et); - if (ck_pr_load_bool(&peer->p_enabled) && + if (atomic_load_bool(&peer->p_enabled) && !callout_pending(&peer->p_zero_key_material)) callout_reset(&peer->p_zero_key_material, MSEC_2_TICKS(REJECT_AFTER_TIME * 3 * 1000), @@ -1141,9 +1143,9 @@ wg_timers_run_send_keepalive(void *_peer) wg_send_keepalive(peer); NET_EPOCH_ENTER(et); - if (ck_pr_load_bool(&peer->p_enabled) && - ck_pr_load_bool(&peer->p_need_another_keepalive)) { - ck_pr_store_bool(&peer->p_need_another_keepalive, false); + if (atomic_load_bool(&peer->p_enabled) && + atomic_load_bool(&peer->p_need_another_keepalive)) { + atomic_store_bool(&peer->p_need_another_keepalive, false); callout_reset(&peer->p_send_keepalive, MSEC_2_TICKS(KEEPALIVE_TIMEOUT * 1000), wg_timers_run_send_keepalive, peer); @@ -1180,7 +1182,7 @@ wg_timers_run_persistent_keepalive(void *_peer) { struct wg_peer *peer = _peer; - if (ck_pr_load_16(&peer->p_persistent_keepalive_interval) > 0) + if (atomic_load_16(&peer->p_persistent_keepalive_interval) > 0) wg_send_keepalive(peer); } diff --git a/sys/dev/wg/wg_noise.c b/sys/dev/wg/wg_noise.c index 756b5c07c10a..095da9dd4a7b 100644 --- a/sys/dev/wg/wg_noise.c +++ b/sys/dev/wg/wg_noise.c @@ -564,16 +564,16 @@ noise_remote_keypairs_clear(struct noise_remote *r) struct noise_keypair *kp; mtx_lock(&r->r_keypair_mtx); - kp = ck_pr_load_ptr(&r->r_next); - ck_pr_store_ptr(&r->r_next, NULL); + kp = atomic_load_ptr(&r->r_next); + atomic_store_ptr(&r->r_next, NULL); noise_keypair_drop(kp); - kp = ck_pr_load_ptr(&r->r_current); - ck_pr_store_ptr(&r->r_current, NULL); + kp = atomic_load_ptr(&r->r_current); + atomic_store_ptr(&r->r_current, NULL); noise_keypair_drop(kp); - kp = ck_pr_load_ptr(&r->r_previous); - ck_pr_store_ptr(&r->r_previous, NULL); + kp = atomic_load_ptr(&r->r_previous); + atomic_store_ptr(&r->r_previous, NULL); noise_keypair_drop(kp); mtx_unlock(&r->r_keypair_mtx); } @@ -587,12 +587,12 @@ noise_remote_expire_current(struct noise_remote *r) noise_remote_handshake_clear(r); NET_EPOCH_ENTER(et); - kp = ck_pr_load_ptr(&r->r_next); + kp = atomic_load_ptr(&r->r_next); if (kp != NULL) - ck_pr_store_bool(&kp->kp_can_send, false); - kp = ck_pr_load_ptr(&r->r_current); + atomic_store_bool(&kp->kp_can_send, false); + kp = atomic_load_ptr(&r->r_current); if (kp != NULL) - ck_pr_store_bool(&kp->kp_can_send, false); + atomic_store_bool(&kp->kp_can_send, false); NET_EPOCH_EXIT(et); } @@ -606,24 +606,24 @@ noise_add_new_keypair(struct noise_local *l, struct noise_remote *r, /* Insert into the keypair table */ mtx_lock(&r->r_keypair_mtx); - next = ck_pr_load_ptr(&r->r_next); - current = ck_pr_load_ptr(&r->r_current); - previous = ck_pr_load_ptr(&r->r_previous); + next = atomic_load_ptr(&r->r_next); + current = atomic_load_ptr(&r->r_current); + previous = atomic_load_ptr(&r->r_previous); if (kp->kp_is_initiator) { if (next != NULL) { - ck_pr_store_ptr(&r->r_next, NULL); - ck_pr_store_ptr(&r->r_previous, next); + atomic_store_ptr(&r->r_next, NULL); + atomic_store_ptr(&r->r_previous, next); noise_keypair_drop(current); } else { - ck_pr_store_ptr(&r->r_previous, current); + atomic_store_ptr(&r->r_previous, current); } noise_keypair_drop(previous); - ck_pr_store_ptr(&r->r_current, kp); + atomic_store_ptr(&r->r_current, kp); } else { - ck_pr_store_ptr(&r->r_next, kp); + atomic_store_ptr(&r->r_next, kp); noise_keypair_drop(next); - ck_pr_store_ptr(&r->r_previous, NULL); + atomic_store_ptr(&r->r_previous, NULL); noise_keypair_drop(previous); } @@ -704,10 +704,10 @@ noise_keypair_current(struct noise_remote *r) struct noise_keypair *kp, *ret = NULL; NET_EPOCH_ENTER(et); - kp = ck_pr_load_ptr(&r->r_current); - if (kp != NULL && ck_pr_load_bool(&kp->kp_can_send)) { + kp = atomic_load_ptr(&r->r_current); + if (kp != NULL && atomic_load_bool(&kp->kp_can_send)) { if (noise_timer_expired(kp->kp_birthdate, REJECT_AFTER_TIME, 0)) - ck_pr_store_bool(&kp->kp_can_send, false); + atomic_store_bool(&kp->kp_can_send, false); else if (refcount_acquire_if_not_zero(&kp->kp_refcnt)) ret = kp; } @@ -728,20 +728,20 @@ noise_keypair_received_with(struct noise_keypair *kp) struct noise_keypair *old; struct noise_remote *r = kp->kp_remote; - if (kp != ck_pr_load_ptr(&r->r_next)) + if (kp != atomic_load_ptr(&r->r_next)) return (0); mtx_lock(&r->r_keypair_mtx); - if (kp != ck_pr_load_ptr(&r->r_next)) { + if (kp != atomic_load_ptr(&r->r_next)) { mtx_unlock(&r->r_keypair_mtx); return (0); } - old = ck_pr_load_ptr(&r->r_previous); - ck_pr_store_ptr(&r->r_previous, ck_pr_load_ptr(&r->r_current)); + old = atomic_load_ptr(&r->r_previous); + atomic_store_ptr(&r->r_previous, atomic_load_ptr(&r->r_current)); noise_keypair_drop(old); - ck_pr_store_ptr(&r->r_current, kp); - ck_pr_store_ptr(&r->r_next, NULL); + atomic_store_ptr(&r->r_current, kp); + atomic_store_ptr(&r->r_next, NULL); mtx_unlock(&r->r_keypair_mtx); return (ECONNRESET); @@ -793,11 +793,11 @@ noise_keypair_remote(struct noise_keypair *kp) int noise_keypair_nonce_next(struct noise_keypair *kp, uint64_t *send) { - if (!ck_pr_load_bool(&kp->kp_can_send)) + if (!atomic_load_bool(&kp->kp_can_send)) return (EINVAL); #ifdef __LP64__ - *send = ck_pr_faa_64(&kp->kp_nonce_send, 1); + *send = atomic_fetchadd_64(&kp->kp_nonce_send, 1); #else rw_wlock(&kp->kp_nonce_lock); *send = kp->kp_nonce_send++; @@ -805,7 +805,7 @@ noise_keypair_nonce_next(struct noise_keypair *kp, uint64_t *send) #endif if (*send < REJECT_AFTER_MESSAGES) return (0); - ck_pr_store_bool(&kp->kp_can_send, false); + atomic_store_bool(&kp->kp_can_send, false); return (EINVAL); } @@ -836,7 +836,7 @@ noise_keypair_nonce_check(struct noise_keypair *kp, uint64_t recv) (i + index_current) & ((COUNTER_BITS_TOTAL / COUNTER_BITS) - 1)] = 0; #ifdef __LP64__ - ck_pr_store_64(&kp->kp_nonce_recv, recv); + atomic_store_64(&kp->kp_nonce_recv, recv); #else kp->kp_nonce_recv = recv; #endif @@ -863,12 +863,12 @@ noise_keep_key_fresh_send(struct noise_remote *r) uint64_t nonce; NET_EPOCH_ENTER(et); - current = ck_pr_load_ptr(&r->r_current); - keep_key_fresh = current != NULL && ck_pr_load_bool(¤t->kp_can_send); + current = atomic_load_ptr(&r->r_current); + keep_key_fresh = current != NULL && atomic_load_bool(¤t->kp_can_send); if (!keep_key_fresh) goto out; #ifdef __LP64__ - nonce = ck_pr_load_64(¤t->kp_nonce_send); + nonce = atomic_load_64(¤t->kp_nonce_send); #else rw_rlock(¤t->kp_nonce_lock); nonce = current->kp_nonce_send; @@ -892,8 +892,8 @@ noise_keep_key_fresh_recv(struct noise_remote *r) int keep_key_fresh; NET_EPOCH_ENTER(et); - current = ck_pr_load_ptr(&r->r_current); - keep_key_fresh = current != NULL && ck_pr_load_bool(¤t->kp_can_send) && + current = atomic_load_ptr(&r->r_current); + keep_key_fresh = current != NULL && atomic_load_bool(¤t->kp_can_send) && current->kp_is_initiator && noise_timer_expired(current->kp_birthdate, REJECT_AFTER_TIME - KEEPALIVE_TIMEOUT - REKEY_TIMEOUT, 0); NET_EPOCH_EXIT(et); @@ -921,7 +921,7 @@ noise_keypair_decrypt(struct noise_keypair *kp, uint64_t nonce, struct mbuf *m) int ret; #ifdef __LP64__ - cur_nonce = ck_pr_load_64(&kp->kp_nonce_recv); + cur_nonce = atomic_load_64(&kp->kp_nonce_recv); #else rw_rlock(&kp->kp_nonce_lock); cur_nonce = kp->kp_nonce_recv;