]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
batman-adv: replace non-atomic hardif config fields with (READ|WRITE)_ONCE
authorSven Eckelmann <sven@narfation.org>
Tue, 12 May 2026 17:37:05 +0000 (19:37 +0200)
committerSven Eckelmann <sven@narfation.org>
Mon, 1 Jun 2026 12:22:01 +0000 (14:22 +0200)
The hardif configuration values are only accessed as plain loads/stores and
do not require full atomic_t semantics. Convert these fields to native
integer types and replace their users with READ_ONCE()/WRITE_ONCE() to
avoid load/store tearing.

Signed-off-by: Sven Eckelmann <sven@narfation.org>
net/batman-adv/bat_iv_ogm.c
net/batman-adv/bat_v.c
net/batman-adv/bat_v_elp.c
net/batman-adv/bat_v_ogm.c
net/batman-adv/hard-interface.c
net/batman-adv/netlink.c
net/batman-adv/types.h

index 5628017bee511545b7c38e9c7c605996843ee939..df8e64588e1e73f848d194262af7717582122b3c 100644 (file)
@@ -1218,7 +1218,7 @@ static bool batadv_iv_ogm_calc_tq(struct batadv_orig_node *orig_node,
        inv_asym_penalty = BATADV_TQ_MAX_VALUE * neigh_rq_inv_cube;
        inv_asym_penalty /= neigh_rq_max_cube;
        tq_asym_penalty = BATADV_TQ_MAX_VALUE - inv_asym_penalty;
-       tq_iface_hop_penalty -= atomic_read(&if_incoming->hop_penalty);
+       tq_iface_hop_penalty -= READ_ONCE(if_incoming->hop_penalty);
 
        /* penalize if the OGM is forwarded on the same interface. WiFi
         * interfaces and other half duplex devices suffer from throughput
index 492058a87682b9464d3949d3d17fd1eeba052bbe..ac2932da5472d3b04c16f1b2cef657466dd3ed36 100644 (file)
@@ -7,7 +7,6 @@
 #include "bat_v.h"
 #include "main.h"
 
-#include <linux/atomic.h>
 #include <linux/cache.h>
 #include <linux/compiler.h>
 #include <linux/errno.h>
@@ -813,8 +812,8 @@ void batadv_v_hardif_init(struct batadv_hard_iface *hard_iface)
        /* enable link throughput auto-detection by setting the throughput
         * override to zero
         */
-       atomic_set(&hard_iface->bat_v.throughput_override, 0);
-       atomic_set(&hard_iface->bat_v.elp_interval, 500);
+       WRITE_ONCE(hard_iface->bat_v.throughput_override, 0);
+       WRITE_ONCE(hard_iface->bat_v.elp_interval, 500);
 
        hard_iface->bat_v.aggr_len = 0;
        skb_queue_head_init(&hard_iface->bat_v.aggr_list);
index e207093de79fe9ecbc9228cf444b217be7f26930..0190fafcbed2d235491d36f4031c4ebe1bdfda63 100644 (file)
@@ -10,6 +10,7 @@
 #include <linux/atomic.h>
 #include <linux/bitops.h>
 #include <linux/byteorder/generic.h>
+#include <linux/compiler.h>
 #include <linux/container_of.h>
 #include <linux/errno.h>
 #include <linux/etherdevice.h>
@@ -62,7 +63,7 @@ static void batadv_v_elp_start_timer(struct batadv_hard_iface *hard_iface)
 {
        unsigned int msecs;
 
-       msecs = atomic_read(&hard_iface->bat_v.elp_interval) - BATADV_JITTER;
+       msecs = READ_ONCE(hard_iface->bat_v.elp_interval) - BATADV_JITTER;
        msecs += get_random_u32_below(2 * BATADV_JITTER);
 
        queue_delayed_work(batadv_event_workqueue, &hard_iface->bat_v.elp_wq,
@@ -98,7 +99,7 @@ static bool batadv_v_elp_get_throughput(struct batadv_hardif_neigh_node *neigh,
        /* if the user specified a customised value for this interface, then
         * return it directly
         */
-       throughput =  atomic_read(&hard_iface->bat_v.throughput_override);
+       throughput =  READ_ONCE(hard_iface->bat_v.throughput_override);
        if (throughput != 0) {
                *pthroughput = throughput;
                return true;
@@ -324,7 +325,7 @@ static void batadv_v_elp_periodic_work(struct work_struct *work)
 
        elp_packet = (struct batadv_elp_packet *)skb->data;
        elp_packet->seqno = htonl(atomic_read(&hard_iface->bat_v.elp_seqno));
-       elp_interval = atomic_read(&hard_iface->bat_v.elp_interval);
+       elp_interval = READ_ONCE(hard_iface->bat_v.elp_interval);
        elp_packet->elp_interval = htonl(elp_interval);
 
        batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
index 28f28b61ad6bc187185706f9f189de4fd366991d..f4cd8cad97e0cd362627266e97f37d204f750146 100644 (file)
@@ -486,9 +486,9 @@ static u32 batadv_v_forward_penalty(struct batadv_priv *bat_priv,
                                    struct batadv_hard_iface *if_outgoing,
                                    u32 throughput)
 {
-       int if_hop_penalty = atomic_read(&if_incoming->hop_penalty);
-       int hop_penalty = READ_ONCE(bat_priv->hop_penalty);
-       int hop_penalty_max = BATADV_TQ_MAX_VALUE;
+       u32 if_hop_penalty = READ_ONCE(if_incoming->hop_penalty);
+       u32 hop_penalty = READ_ONCE(bat_priv->hop_penalty);
+       u32 hop_penalty_max = BATADV_TQ_MAX_VALUE;
 
        /* Apply per hardif hop penalty */
        throughput = throughput * (hop_penalty_max - if_hop_penalty) /
index e89aa4b61a7cd9b37b4c63d787fd81aafa6f2b7d..86e7d10864e2f96cb77cc2be006d296fb9072d67 100644 (file)
@@ -910,7 +910,7 @@ batadv_hardif_add_interface(struct net_device *net_dev)
        if (batadv_is_wifi_hardif(hard_iface))
                hard_iface->num_bcasts = BATADV_NUM_BCASTS_WIRELESS;
 
-       atomic_set(&hard_iface->hop_penalty, 0);
+       WRITE_ONCE(hard_iface->hop_penalty, 0);
 
        batadv_v_hardif_init(hard_iface);
 
index 027e9fe1042a23fbe3014e865de6a5f309c0deb1..368072f0513c2f6d2e95b07b16cbf0b6eab4cfc8 100644 (file)
@@ -811,16 +811,16 @@ static int batadv_netlink_hardif_fill(struct sk_buff *msg,
        }
 
        if (nla_put_u8(msg, BATADV_ATTR_HOP_PENALTY,
-                      atomic_read(&hard_iface->hop_penalty)))
+                      READ_ONCE(hard_iface->hop_penalty)))
                goto nla_put_failure;
 
 #ifdef CONFIG_BATMAN_ADV_BATMAN_V
        if (nla_put_u32(msg, BATADV_ATTR_ELP_INTERVAL,
-                       atomic_read(&hard_iface->bat_v.elp_interval)))
+                       READ_ONCE(hard_iface->bat_v.elp_interval)))
                goto nla_put_failure;
 
        if (nla_put_u32(msg, BATADV_ATTR_THROUGHPUT_OVERRIDE,
-                       atomic_read(&hard_iface->bat_v.throughput_override)))
+                       READ_ONCE(hard_iface->bat_v.throughput_override)))
                goto nla_put_failure;
 #endif /* CONFIG_BATMAN_ADV_BATMAN_V */
 
@@ -913,7 +913,7 @@ static int batadv_netlink_set_hardif(struct sk_buff *skb,
        if (info->attrs[BATADV_ATTR_HOP_PENALTY]) {
                attr = info->attrs[BATADV_ATTR_HOP_PENALTY];
 
-               atomic_set(&hard_iface->hop_penalty, nla_get_u8(attr));
+               WRITE_ONCE(hard_iface->hop_penalty, nla_get_u8(attr));
        }
 
 #ifdef CONFIG_BATMAN_ADV_BATMAN_V
@@ -921,13 +921,13 @@ static int batadv_netlink_set_hardif(struct sk_buff *skb,
        if (info->attrs[BATADV_ATTR_ELP_INTERVAL]) {
                attr = info->attrs[BATADV_ATTR_ELP_INTERVAL];
 
-               atomic_set(&hard_iface->bat_v.elp_interval, nla_get_u32(attr));
+               WRITE_ONCE(hard_iface->bat_v.elp_interval, nla_get_u32(attr));
        }
 
        if (info->attrs[BATADV_ATTR_THROUGHPUT_OVERRIDE]) {
                attr = info->attrs[BATADV_ATTR_THROUGHPUT_OVERRIDE];
 
-               atomic_set(&hard_iface->bat_v.throughput_override,
+               WRITE_ONCE(hard_iface->bat_v.throughput_override,
                           nla_get_u32(attr));
        }
 #endif /* CONFIG_BATMAN_ADV_BATMAN_V */
index c4845b5e43be017b96b789a8ce3d201707a97d82..dd63cd28914d786f253d5d751795de2a06d43796 100644 (file)
@@ -114,7 +114,7 @@ enum batadv_v_hard_iface_flags {
  */
 struct batadv_hard_iface_bat_v {
        /** @elp_interval: time interval between two ELP transmissions */
-       atomic_t elp_interval;
+       u32 elp_interval;
 
        /** @elp_seqno: current ELP sequence number */
        atomic_t elp_seqno;
@@ -138,7 +138,7 @@ struct batadv_hard_iface_bat_v {
         * @throughput_override: throughput override to disable link
         *  auto-detection
         */
-       atomic_t throughput_override;
+       u32 throughput_override;
 
        /** @flags: interface specific flags */
        u8 flags;
@@ -236,7 +236,7 @@ struct batadv_hard_iface {
         * @hop_penalty: penalty which will be applied to the tq-field
         * of an OGM received via this interface
         */
-       atomic_t hop_penalty;
+       u8 hop_penalty;
 
        /** @bat_iv: per hard-interface B.A.T.M.A.N. IV data */
        struct batadv_hard_iface_bat_iv bat_iv;