mirror of
https://github.com/torvalds/linux.git
synced 2026-07-27 09:36:22 +02:00
bridge: provide lockless access to p->path_cost
Add READ_ONCE()/WRITE_ONCE() annotations around p->path_cost. This is needed at least for sysfs show_path_cost(), BRCTL_GET_PORT_INFO and upcoming RTNL avoidance in "ip link" dumps (cf br_port_fill_attrs()). Signed-off-by: Eric Dumazet <edumazet@google.com> Acked-by: Nikolay Aleksandrov <razor@blackwall.org> Reviewed-by: Ido Schimmel <idosch@nvidia.com> Link: https://patch.msgid.link/20260604141343.2124500-6-edumazet@google.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
This commit is contained in:
parent
2013ebb9b3
commit
f236240c9b
|
|
@ -78,7 +78,7 @@ void br_port_carrier_check(struct net_bridge_port *p, bool *notified)
|
|||
|
||||
if (!test_bit(BR_ADMIN_COST_BIT, &p->flags) &&
|
||||
netif_running(dev) && netif_oper_up(dev))
|
||||
p->path_cost = port_cost(dev);
|
||||
WRITE_ONCE(p->path_cost, port_cost(dev));
|
||||
|
||||
*notified = false;
|
||||
if (!netif_running(br->dev))
|
||||
|
|
|
|||
|
|
@ -259,7 +259,7 @@ int br_dev_siocdevprivate(struct net_device *dev, struct ifreq *rq,
|
|||
memcpy(&p.designated_bridge, &pt->designated_bridge, 8);
|
||||
p.port_id = pt->port_id;
|
||||
p.designated_port = pt->designated_port;
|
||||
p.path_cost = pt->path_cost;
|
||||
p.path_cost = READ_ONCE(pt->path_cost);
|
||||
p.designated_cost = pt->designated_cost;
|
||||
p.state = pt->state;
|
||||
p.top_change_ack = pt->topology_change_ack;
|
||||
|
|
|
|||
|
|
@ -240,7 +240,7 @@ static int br_port_fill_attrs(struct sk_buff *skb,
|
|||
|
||||
if (nla_put_u8(skb, IFLA_BRPORT_STATE, p->state) ||
|
||||
nla_put_u16(skb, IFLA_BRPORT_PRIORITY, p->priority) ||
|
||||
nla_put_u32(skb, IFLA_BRPORT_COST, p->path_cost) ||
|
||||
nla_put_u32(skb, IFLA_BRPORT_COST, READ_ONCE(p->path_cost)) ||
|
||||
nla_put_u8(skb, IFLA_BRPORT_MODE, mode) ||
|
||||
nla_put_u8(skb, IFLA_BRPORT_GUARD, !!(p->flags & BR_BPDU_GUARD)) ||
|
||||
nla_put_u8(skb, IFLA_BRPORT_PROTECT,
|
||||
|
|
|
|||
|
|
@ -102,8 +102,9 @@ struct net_bridge_port *br_get_port(struct net_bridge *br, u16 port_no)
|
|||
static int br_should_become_root_port(const struct net_bridge_port *p,
|
||||
u16 root_port)
|
||||
{
|
||||
struct net_bridge *br;
|
||||
u32 p_path_cost, rp_path_cost;
|
||||
struct net_bridge_port *rp;
|
||||
struct net_bridge *br;
|
||||
int t;
|
||||
|
||||
br = p->br;
|
||||
|
|
@ -125,11 +126,14 @@ static int br_should_become_root_port(const struct net_bridge_port *p,
|
|||
else if (t > 0)
|
||||
return 0;
|
||||
|
||||
if (p->designated_cost + p->path_cost <
|
||||
rp->designated_cost + rp->path_cost)
|
||||
p_path_cost = READ_ONCE(p->path_cost);
|
||||
rp_path_cost = READ_ONCE(rp->path_cost);
|
||||
|
||||
if (p->designated_cost + p_path_cost <
|
||||
rp->designated_cost + rp_path_cost)
|
||||
return 1;
|
||||
else if (p->designated_cost + p->path_cost >
|
||||
rp->designated_cost + rp->path_cost)
|
||||
else if (p->designated_cost + p_path_cost >
|
||||
rp->designated_cost + rp_path_cost)
|
||||
return 0;
|
||||
|
||||
t = memcmp(&p->designated_bridge, &rp->designated_bridge, 8);
|
||||
|
|
@ -187,7 +191,8 @@ static void br_root_selection(struct net_bridge *br)
|
|||
} else {
|
||||
p = br_get_port(br, root_port);
|
||||
br->designated_root = p->designated_root;
|
||||
br->root_path_cost = p->designated_cost + p->path_cost;
|
||||
br->root_path_cost = p->designated_cost +
|
||||
READ_ONCE(p->path_cost);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -341,7 +341,7 @@ int br_stp_set_path_cost(struct net_bridge_port *p, unsigned long path_cost)
|
|||
return -ERANGE;
|
||||
|
||||
set_bit(BR_ADMIN_COST_BIT, &p->flags);
|
||||
p->path_cost = path_cost;
|
||||
WRITE_ONCE(p->path_cost, path_cost);
|
||||
br_configuration_update(p->br);
|
||||
br_port_state_selection(p->br);
|
||||
return 0;
|
||||
|
|
|
|||
|
|
@ -83,7 +83,7 @@ static int store_flag(struct net_bridge_port *p, unsigned long v,
|
|||
|
||||
static ssize_t show_path_cost(struct net_bridge_port *p, char *buf)
|
||||
{
|
||||
return sysfs_emit(buf, "%d\n", p->path_cost);
|
||||
return sysfs_emit(buf, "%d\n", READ_ONCE(p->path_cost));
|
||||
}
|
||||
|
||||
static int store_path_cost(struct net_bridge_port *p, unsigned long v)
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user