net-sysfs: convert dev->operstate reads to lockless ones
[ Upstream commit 004d138364fd10dd5ff8ceb54cfdc2d792a7b338 ] operstate_show() can omit dev_base_lock acquisition only to read dev->operstate. Annotate accesses to dev->operstate. Writers still acquire dev_base_lock for mutual exclusion. Signed-off-by: Eric Dumazet <edumazet@google.com> Signed-off-by: David S. Miller <davem@davemloft.net> Stable-dep-of: 4893b8b3ef8d ("hsr: Simplify code for announcing HSR nodes timer setup") Signed-off-by: Sasha Levin <sashal@kernel.org>
This commit is contained in:
parent
8745a8d74b
commit
1c2b0f0823
|
@ -455,7 +455,8 @@ static int br_fill_ifinfo(struct sk_buff *skb,
|
|||
u32 filter_mask, const struct net_device *dev,
|
||||
bool getlink)
|
||||
{
|
||||
u8 operstate = netif_running(dev) ? dev->operstate : IF_OPER_DOWN;
|
||||
u8 operstate = netif_running(dev) ? READ_ONCE(dev->operstate) :
|
||||
IF_OPER_DOWN;
|
||||
struct nlattr *af = NULL;
|
||||
struct net_bridge *br;
|
||||
struct ifinfomsg *hdr;
|
||||
|
|
|
@ -67,7 +67,7 @@ static void rfc2863_policy(struct net_device *dev)
|
|||
{
|
||||
unsigned char operstate = default_operstate(dev);
|
||||
|
||||
if (operstate == dev->operstate)
|
||||
if (operstate == READ_ONCE(dev->operstate))
|
||||
return;
|
||||
|
||||
write_lock(&dev_base_lock);
|
||||
|
@ -87,7 +87,7 @@ static void rfc2863_policy(struct net_device *dev)
|
|||
break;
|
||||
}
|
||||
|
||||
dev->operstate = operstate;
|
||||
WRITE_ONCE(dev->operstate, operstate);
|
||||
|
||||
write_unlock(&dev_base_lock);
|
||||
}
|
||||
|
|
|
@ -307,11 +307,9 @@ static ssize_t operstate_show(struct device *dev,
|
|||
const struct net_device *netdev = to_net_dev(dev);
|
||||
unsigned char operstate;
|
||||
|
||||
read_lock(&dev_base_lock);
|
||||
operstate = netdev->operstate;
|
||||
operstate = READ_ONCE(netdev->operstate);
|
||||
if (!netif_running(netdev))
|
||||
operstate = IF_OPER_DOWN;
|
||||
read_unlock(&dev_base_lock);
|
||||
|
||||
if (operstate >= ARRAY_SIZE(operstates))
|
||||
return -EINVAL; /* should not happen */
|
||||
|
|
|
@ -880,9 +880,9 @@ static void set_operstate(struct net_device *dev, unsigned char transition)
|
|||
break;
|
||||
}
|
||||
|
||||
if (dev->operstate != operstate) {
|
||||
if (READ_ONCE(dev->operstate) != operstate) {
|
||||
write_lock(&dev_base_lock);
|
||||
dev->operstate = operstate;
|
||||
WRITE_ONCE(dev->operstate, operstate);
|
||||
write_unlock(&dev_base_lock);
|
||||
netdev_state_change(dev);
|
||||
}
|
||||
|
|
|
@ -31,8 +31,8 @@ static bool is_slave_up(struct net_device *dev)
|
|||
static void __hsr_set_operstate(struct net_device *dev, int transition)
|
||||
{
|
||||
write_lock(&dev_base_lock);
|
||||
if (dev->operstate != transition) {
|
||||
dev->operstate = transition;
|
||||
if (READ_ONCE(dev->operstate) != transition) {
|
||||
WRITE_ONCE(dev->operstate, transition);
|
||||
write_unlock(&dev_base_lock);
|
||||
netdev_state_change(dev);
|
||||
} else {
|
||||
|
@ -78,14 +78,14 @@ static void hsr_check_announce(struct net_device *hsr_dev,
|
|||
|
||||
hsr = netdev_priv(hsr_dev);
|
||||
|
||||
if (hsr_dev->operstate == IF_OPER_UP && old_operstate != IF_OPER_UP) {
|
||||
if (READ_ONCE(hsr_dev->operstate) == IF_OPER_UP && old_operstate != IF_OPER_UP) {
|
||||
/* Went up */
|
||||
hsr->announce_count = 0;
|
||||
mod_timer(&hsr->announce_timer,
|
||||
jiffies + msecs_to_jiffies(HSR_ANNOUNCE_INTERVAL));
|
||||
}
|
||||
|
||||
if (hsr_dev->operstate != IF_OPER_UP && old_operstate == IF_OPER_UP)
|
||||
if (READ_ONCE(hsr_dev->operstate) != IF_OPER_UP && old_operstate == IF_OPER_UP)
|
||||
/* Went down */
|
||||
del_timer(&hsr->announce_timer);
|
||||
}
|
||||
|
@ -100,7 +100,7 @@ void hsr_check_carrier_and_operstate(struct hsr_priv *hsr)
|
|||
/* netif_stacked_transfer_operstate() cannot be used here since
|
||||
* it doesn't set IF_OPER_LOWERLAYERDOWN (?)
|
||||
*/
|
||||
old_operstate = master->dev->operstate;
|
||||
old_operstate = READ_ONCE(master->dev->operstate);
|
||||
has_carrier = hsr_check_carrier(master);
|
||||
hsr_set_operstate(master, has_carrier);
|
||||
hsr_check_announce(master->dev, old_operstate);
|
||||
|
|
|
@ -6011,7 +6011,7 @@ static int inet6_fill_ifinfo(struct sk_buff *skb, struct inet6_dev *idev,
|
|||
(dev->ifindex != dev_get_iflink(dev) &&
|
||||
nla_put_u32(skb, IFLA_LINK, dev_get_iflink(dev))) ||
|
||||
nla_put_u8(skb, IFLA_OPERSTATE,
|
||||
netif_running(dev) ? dev->operstate : IF_OPER_DOWN))
|
||||
netif_running(dev) ? READ_ONCE(dev->operstate) : IF_OPER_DOWN))
|
||||
goto nla_put_failure;
|
||||
protoinfo = nla_nest_start_noflag(skb, IFLA_PROTINFO);
|
||||
if (!protoinfo)
|
||||
|
|
Loading…
Reference in New Issue