Skip to content

Commit dbb48d9

Browse files
committed
batman-adv: replace non-atomic hardif config fields with (READ|WRITE)_ONCE
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>
1 parent 6a4f30e commit dbb48d9

7 files changed

Lines changed: 20 additions & 20 deletions

File tree

net/batman-adv/bat_iv_ogm.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1218,7 +1218,7 @@ static bool batadv_iv_ogm_calc_tq(struct batadv_orig_node *orig_node,
12181218
inv_asym_penalty = BATADV_TQ_MAX_VALUE * neigh_rq_inv_cube;
12191219
inv_asym_penalty /= neigh_rq_max_cube;
12201220
tq_asym_penalty = BATADV_TQ_MAX_VALUE - inv_asym_penalty;
1221-
tq_iface_hop_penalty -= atomic_read(&if_incoming->hop_penalty);
1221+
tq_iface_hop_penalty -= READ_ONCE(if_incoming->hop_penalty);
12221222

12231223
/* penalize if the OGM is forwarded on the same interface. WiFi
12241224
* interfaces and other half duplex devices suffer from throughput

net/batman-adv/bat_v.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
#include "bat_v.h"
88
#include "main.h"
99

10-
#include <linux/atomic.h>
1110
#include <linux/cache.h>
1211
#include <linux/compiler.h>
1312
#include <linux/errno.h>
@@ -813,8 +812,8 @@ void batadv_v_hardif_init(struct batadv_hard_iface *hard_iface)
813812
/* enable link throughput auto-detection by setting the throughput
814813
* override to zero
815814
*/
816-
atomic_set(&hard_iface->bat_v.throughput_override, 0);
817-
atomic_set(&hard_iface->bat_v.elp_interval, 500);
815+
WRITE_ONCE(hard_iface->bat_v.throughput_override, 0);
816+
WRITE_ONCE(hard_iface->bat_v.elp_interval, 500);
818817

819818
hard_iface->bat_v.aggr_len = 0;
820819
skb_queue_head_init(&hard_iface->bat_v.aggr_list);

net/batman-adv/bat_v_elp.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <linux/atomic.h>
1111
#include <linux/bitops.h>
1212
#include <linux/byteorder/generic.h>
13+
#include <linux/compiler.h>
1314
#include <linux/container_of.h>
1415
#include <linux/errno.h>
1516
#include <linux/etherdevice.h>
@@ -62,7 +63,7 @@ static void batadv_v_elp_start_timer(struct batadv_hard_iface *hard_iface)
6263
{
6364
unsigned int msecs;
6465

65-
msecs = atomic_read(&hard_iface->bat_v.elp_interval) - BATADV_JITTER;
66+
msecs = READ_ONCE(hard_iface->bat_v.elp_interval) - BATADV_JITTER;
6667
msecs += get_random_u32_below(2 * BATADV_JITTER);
6768

6869
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,
9899
/* if the user specified a customised value for this interface, then
99100
* return it directly
100101
*/
101-
throughput = atomic_read(&hard_iface->bat_v.throughput_override);
102+
throughput = READ_ONCE(hard_iface->bat_v.throughput_override);
102103
if (throughput != 0) {
103104
*pthroughput = throughput;
104105
return true;
@@ -324,7 +325,7 @@ static void batadv_v_elp_periodic_work(struct work_struct *work)
324325

325326
elp_packet = (struct batadv_elp_packet *)skb->data;
326327
elp_packet->seqno = htonl(atomic_read(&hard_iface->bat_v.elp_seqno));
327-
elp_interval = atomic_read(&hard_iface->bat_v.elp_interval);
328+
elp_interval = READ_ONCE(hard_iface->bat_v.elp_interval);
328329
elp_packet->elp_interval = htonl(elp_interval);
329330

330331
batadv_dbg(BATADV_DBG_BATMAN, bat_priv,

net/batman-adv/bat_v_ogm.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -486,9 +486,9 @@ static u32 batadv_v_forward_penalty(struct batadv_priv *bat_priv,
486486
struct batadv_hard_iface *if_outgoing,
487487
u32 throughput)
488488
{
489-
int if_hop_penalty = atomic_read(&if_incoming->hop_penalty);
490-
int hop_penalty = READ_ONCE(bat_priv->hop_penalty);
491-
int hop_penalty_max = BATADV_TQ_MAX_VALUE;
489+
u32 if_hop_penalty = READ_ONCE(if_incoming->hop_penalty);
490+
u32 hop_penalty = READ_ONCE(bat_priv->hop_penalty);
491+
u32 hop_penalty_max = BATADV_TQ_MAX_VALUE;
492492

493493
/* Apply per hardif hop penalty */
494494
throughput = throughput * (hop_penalty_max - if_hop_penalty) /

net/batman-adv/hard-interface.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -910,7 +910,7 @@ batadv_hardif_add_interface(struct net_device *net_dev)
910910
if (batadv_is_wifi_hardif(hard_iface))
911911
hard_iface->num_bcasts = BATADV_NUM_BCASTS_WIRELESS;
912912

913-
atomic_set(&hard_iface->hop_penalty, 0);
913+
WRITE_ONCE(hard_iface->hop_penalty, 0);
914914

915915
batadv_v_hardif_init(hard_iface);
916916

net/batman-adv/netlink.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -811,16 +811,16 @@ static int batadv_netlink_hardif_fill(struct sk_buff *msg,
811811
}
812812

813813
if (nla_put_u8(msg, BATADV_ATTR_HOP_PENALTY,
814-
atomic_read(&hard_iface->hop_penalty)))
814+
READ_ONCE(hard_iface->hop_penalty)))
815815
goto nla_put_failure;
816816

817817
#ifdef CONFIG_BATMAN_ADV_BATMAN_V
818818
if (nla_put_u32(msg, BATADV_ATTR_ELP_INTERVAL,
819-
atomic_read(&hard_iface->bat_v.elp_interval)))
819+
READ_ONCE(hard_iface->bat_v.elp_interval)))
820820
goto nla_put_failure;
821821

822822
if (nla_put_u32(msg, BATADV_ATTR_THROUGHPUT_OVERRIDE,
823-
atomic_read(&hard_iface->bat_v.throughput_override)))
823+
READ_ONCE(hard_iface->bat_v.throughput_override)))
824824
goto nla_put_failure;
825825
#endif /* CONFIG_BATMAN_ADV_BATMAN_V */
826826

@@ -913,21 +913,21 @@ static int batadv_netlink_set_hardif(struct sk_buff *skb,
913913
if (info->attrs[BATADV_ATTR_HOP_PENALTY]) {
914914
attr = info->attrs[BATADV_ATTR_HOP_PENALTY];
915915

916-
atomic_set(&hard_iface->hop_penalty, nla_get_u8(attr));
916+
WRITE_ONCE(hard_iface->hop_penalty, nla_get_u8(attr));
917917
}
918918

919919
#ifdef CONFIG_BATMAN_ADV_BATMAN_V
920920

921921
if (info->attrs[BATADV_ATTR_ELP_INTERVAL]) {
922922
attr = info->attrs[BATADV_ATTR_ELP_INTERVAL];
923923

924-
atomic_set(&hard_iface->bat_v.elp_interval, nla_get_u32(attr));
924+
WRITE_ONCE(hard_iface->bat_v.elp_interval, nla_get_u32(attr));
925925
}
926926

927927
if (info->attrs[BATADV_ATTR_THROUGHPUT_OVERRIDE]) {
928928
attr = info->attrs[BATADV_ATTR_THROUGHPUT_OVERRIDE];
929929

930-
atomic_set(&hard_iface->bat_v.throughput_override,
930+
WRITE_ONCE(hard_iface->bat_v.throughput_override,
931931
nla_get_u32(attr));
932932
}
933933
#endif /* CONFIG_BATMAN_ADV_BATMAN_V */

net/batman-adv/types.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ enum batadv_v_hard_iface_flags {
114114
*/
115115
struct batadv_hard_iface_bat_v {
116116
/** @elp_interval: time interval between two ELP transmissions */
117-
atomic_t elp_interval;
117+
u32 elp_interval;
118118

119119
/** @elp_seqno: current ELP sequence number */
120120
atomic_t elp_seqno;
@@ -138,7 +138,7 @@ struct batadv_hard_iface_bat_v {
138138
* @throughput_override: throughput override to disable link
139139
* auto-detection
140140
*/
141-
atomic_t throughput_override;
141+
u32 throughput_override;
142142

143143
/** @flags: interface specific flags */
144144
u8 flags;
@@ -236,7 +236,7 @@ struct batadv_hard_iface {
236236
* @hop_penalty: penalty which will be applied to the tq-field
237237
* of an OGM received via this interface
238238
*/
239-
atomic_t hop_penalty;
239+
u8 hop_penalty;
240240

241241
/** @bat_iv: per hard-interface B.A.T.M.A.N. IV data */
242242
struct batadv_hard_iface_bat_iv bat_iv;

0 commit comments

Comments
 (0)