Skip to content

Commit cc03492

Browse files
q2venkuba-moo
authored andcommitted
neighbour: Annotate access to struct pneigh_entry.{flags,protocol}.
We will convert pneigh readers to RCU, and its flags and protocol will be read locklessly. Let's annotate the access to the two fields. Note that all access to pn->permanent is under RTNL (neigh_add() and pneigh_ifdown_and_unlock()), so WRITE_ONCE() and READ_ONCE() are not needed. Signed-off-by: Kuniyuki Iwashima <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent d539d8f commit cc03492

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

net/core/neighbour.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2044,10 +2044,10 @@ static int neigh_add(struct sk_buff *skb, struct nlmsghdr *nlh,
20442044
err = -ENOBUFS;
20452045
pn = pneigh_create(tbl, net, dst, dev);
20462046
if (pn) {
2047-
pn->flags = ndm_flags;
2047+
WRITE_ONCE(pn->flags, ndm_flags);
20482048
pn->permanent = !!(ndm->ndm_state & NUD_PERMANENT);
20492049
if (protocol)
2050-
pn->protocol = protocol;
2050+
WRITE_ONCE(pn->protocol, protocol);
20512051
err = 0;
20522052
}
20532053
goto out;
@@ -2678,13 +2678,15 @@ static int pneigh_fill_info(struct sk_buff *skb, struct pneigh_entry *pn,
26782678
u32 neigh_flags, neigh_flags_ext;
26792679
struct nlmsghdr *nlh;
26802680
struct ndmsg *ndm;
2681+
u8 protocol;
26812682

26822683
nlh = nlmsg_put(skb, pid, seq, type, sizeof(*ndm), flags);
26832684
if (nlh == NULL)
26842685
return -EMSGSIZE;
26852686

2686-
neigh_flags_ext = pn->flags >> NTF_EXT_SHIFT;
2687-
neigh_flags = pn->flags & NTF_OLD_MASK;
2687+
neigh_flags = READ_ONCE(pn->flags);
2688+
neigh_flags_ext = neigh_flags >> NTF_EXT_SHIFT;
2689+
neigh_flags &= NTF_OLD_MASK;
26882690

26892691
ndm = nlmsg_data(nlh);
26902692
ndm->ndm_family = tbl->family;
@@ -2698,7 +2700,8 @@ static int pneigh_fill_info(struct sk_buff *skb, struct pneigh_entry *pn,
26982700
if (nla_put(skb, NDA_DST, tbl->key_len, pn->key))
26992701
goto nla_put_failure;
27002702

2701-
if (pn->protocol && nla_put_u8(skb, NDA_PROTOCOL, pn->protocol))
2703+
protocol = READ_ONCE(pn->protocol);
2704+
if (protocol && nla_put_u8(skb, NDA_PROTOCOL, protocol))
27022705
goto nla_put_failure;
27032706
if (neigh_flags_ext && nla_put_u32(skb, NDA_FLAGS_EXT, neigh_flags_ext))
27042707
goto nla_put_failure;

0 commit comments

Comments
 (0)