Skip to content

Commit 5802057

Browse files
committed
batman-adv: replace non-atomic packet_size_max with (READ|WRITE)_ONCE
The maximum packet size of an meshif is only accessed as plain loads/stores and does not require full atomic_t semantics. Convert to a native integer and replace its users with READ_ONCE()/WRITE_ONCE() to avoid load/store tearing. Signed-off-by: Sven Eckelmann <sven@narfation.org>
1 parent 2b2450e commit 5802057

4 files changed

Lines changed: 6 additions & 7 deletions

File tree

net/batman-adv/hard-interface.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
#include "hard-interface.h"
88
#include "main.h"
99

10-
#include <linux/atomic.h>
1110
#include <linux/bug.h>
1211
#include <linux/byteorder/generic.h>
1312
#include <linux/compiler.h>
@@ -629,7 +628,7 @@ int batadv_hardif_min_mtu(struct net_device *mesh_iface)
629628
* overhead). For example, this value is used by TT to compute the
630629
* maximum local table size
631630
*/
632-
atomic_set(&bat_priv->packet_size_max, min_mtu);
631+
WRITE_ONCE(bat_priv->packet_size_max, min_mtu);
633632

634633
/* the real mesh-interface MTU is computed by removing the payload
635634
* overhead from the maximum amount of bytes that was just computed.

net/batman-adv/mesh-interface.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -779,7 +779,7 @@ static int batadv_meshif_init_late(struct net_device *dev)
779779
WRITE_ONCE(bat_priv->log_level, 0);
780780
#endif
781781
WRITE_ONCE(bat_priv->fragmentation, 1);
782-
atomic_set(&bat_priv->packet_size_max, BATADV_MAX_MTU);
782+
WRITE_ONCE(bat_priv->packet_size_max, BATADV_MAX_MTU);
783783
atomic_set(&bat_priv->bcast_queue_left, BATADV_BCAST_QUEUE_LEN);
784784
atomic_set(&bat_priv->batman_queue_left, BATADV_BATMAN_QUEUE_LEN);
785785

net/batman-adv/translation-table.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -649,7 +649,7 @@ bool batadv_tt_local_add(struct net_device *mesh_iface, const u8 *addr,
649649
/* Ignore the client if we cannot send it in a full table response. */
650650
table_size = batadv_tt_local_table_transmit_size(bat_priv);
651651
table_size += batadv_tt_len(1);
652-
packet_size_max = atomic_read(&bat_priv->packet_size_max);
652+
packet_size_max = READ_ONCE(bat_priv->packet_size_max);
653653
if (table_size > packet_size_max) {
654654
net_ratelimited_function(batadv_info, mesh_iface,
655655
"Local translation table size (%i) exceeds maximum packet size (%i); Ignoring new local tt entry: %pM\n",
@@ -3069,7 +3069,7 @@ static bool batadv_send_other_tt_response(struct batadv_priv *bat_priv,
30693069

30703070
/* Don't send the response, if larger than fragmented packet. */
30713071
tt_len = sizeof(struct batadv_unicast_tvlv_packet) + tvlv_len;
3072-
if (tt_len > atomic_read(&bat_priv->packet_size_max)) {
3072+
if (tt_len > READ_ONCE(bat_priv->packet_size_max)) {
30733073
net_ratelimited_function(batadv_info, bat_priv->mesh_iface,
30743074
"Ignoring TT_REQUEST from %pM; Response size exceeds max packet size.\n",
30753075
res_dst_orig_node->orig);
@@ -3932,7 +3932,7 @@ bool batadv_tt_add_temporary_global_entry(struct batadv_priv *bat_priv,
39323932
void batadv_tt_local_resize_to_mtu(struct net_device *mesh_iface)
39333933
{
39343934
struct batadv_priv *bat_priv = netdev_priv(mesh_iface);
3935-
int packet_size_max = atomic_read(&bat_priv->packet_size_max);
3935+
int packet_size_max = READ_ONCE(bat_priv->packet_size_max);
39363936
int table_size, timeout = BATADV_TT_LOCAL_TIMEOUT / 2;
39373937
bool reduced = false;
39383938

net/batman-adv/types.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1570,7 +1570,7 @@ struct batadv_priv {
15701570
* multiple fragmented skbs or a single frame if fragmentation is
15711571
* disabled
15721572
*/
1573-
atomic_t packet_size_max;
1573+
int packet_size_max;
15741574

15751575
/**
15761576
* @frag_seqno: incremental counter to identify chains of egress

0 commit comments

Comments
 (0)