Skip to content

Commit 88ecc4e

Browse files
edumazetgregkh
authored andcommitted
net/packet: convert po->pressure to an atomic flag
[ Upstream commit 791a3e9 ] Not only this removes some READ_ONCE()/WRITE_ONCE(), this also removes one integer. Signed-off-by: Eric Dumazet <edumazet@google.com> Signed-off-by: David S. Miller <davem@davemloft.net> Stable-dep-of: 1a35da3 ("packet: synchronize pressure clearing with ring reconfiguration") Signed-off-by: Sasha Levin <sashal@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent d40a28a commit 88ecc4e

2 files changed

Lines changed: 9 additions & 7 deletions

File tree

net/packet/af_packet.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1358,22 +1358,23 @@ static int __packet_rcv_has_room(const struct packet_sock *po,
13581358

13591359
static int packet_rcv_has_room(struct packet_sock *po, struct sk_buff *skb)
13601360
{
1361-
int pressure, ret;
1361+
bool pressure;
1362+
int ret;
13621363

13631364
ret = __packet_rcv_has_room(po, skb);
13641365
pressure = ret != ROOM_NORMAL;
13651366

1366-
if (READ_ONCE(po->pressure) != pressure)
1367-
WRITE_ONCE(po->pressure, pressure);
1367+
if (packet_sock_flag(po, PACKET_SOCK_PRESSURE) != pressure)
1368+
packet_sock_flag_set(po, PACKET_SOCK_PRESSURE, pressure);
13681369

13691370
return ret;
13701371
}
13711372

13721373
static void packet_rcv_try_clear_pressure(struct packet_sock *po)
13731374
{
1374-
if (READ_ONCE(po->pressure) &&
1375+
if (packet_sock_flag(po, PACKET_SOCK_PRESSURE) &&
13751376
__packet_rcv_has_room(po, NULL) == ROOM_NORMAL)
1376-
WRITE_ONCE(po->pressure, 0);
1377+
packet_sock_flag_set(po, PACKET_SOCK_PRESSURE, false);
13771378
}
13781379

13791380
static void packet_sock_destruct(struct sock *sk)
@@ -1462,7 +1463,8 @@ static unsigned int fanout_demux_rollover(struct packet_fanout *f,
14621463
i = j = min_t(int, po->rollover->sock, num - 1);
14631464
do {
14641465
po_next = pkt_sk(rcu_dereference(f->arr[i]));
1465-
if (po_next != po_skip && !READ_ONCE(po_next->pressure) &&
1466+
if (po_next != po_skip &&
1467+
!packet_sock_flag(po_next, PACKET_SOCK_PRESSURE) &&
14661468
packet_rcv_has_room(po_next, skb) == ROOM_NORMAL) {
14671469
if (i != j)
14681470
po->rollover->sock = i;

net/packet/internal.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,6 @@ struct packet_sock {
117117
spinlock_t bind_lock;
118118
struct mutex pg_vec_lock;
119119
unsigned long flags;
120-
int pressure;
121120
int ifindex; /* bound device */
122121
__be16 num;
123122
struct packet_rollover *rollover;
@@ -146,6 +145,7 @@ enum packet_sock_flags {
146145
PACKET_SOCK_TP_LOSS,
147146
PACKET_SOCK_HAS_VNET_HDR,
148147
PACKET_SOCK_RUNNING,
148+
PACKET_SOCK_PRESSURE,
149149
};
150150

151151
static inline void packet_sock_flag_set(struct packet_sock *po,

0 commit comments

Comments
 (0)