Skip to contentSkip to conversation

rocker: fix neigh tbl index increment race

PATCH Applied [email protected] 3 participants 3 messages Jun 13, 2015 – Jun 15, 2015

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 rocker: fix neigh tbl index increment race

From: Scott Feldman <[email protected]>

rocker->neigh_tbl_next_index is used to generate unique indices for neigh entries programmed into the device. The way new indices were generated was racy with the new prepare-commit transaction model. A simple fix here removes the race. The race was with two processes getting the same index, one process using prepare-commit, the other not:

Proc A Proc B

PREPARE phase
get neigh_tbl_next_index

NONE phase
get neigh_tbl_next_index neigh_tbl_next_index++

COMMIT phase
neigh_tbl_next_index++

Both A and B got the same index. The fix is to store and increment neigh_tbl_next_index in the PREPARE (or NONE) phase and use value in COMMIT phase:

Proc A Proc B

PREPARE phase
get neigh_tbl_next_index
neigh_tbl_next_index++

NONE phase
get neigh_tbl_next_index neigh_tbl_next_index++

COMMIT phase
// use value stashed in PREPARE phase

---
 drivers/net/ethernet/rocker/rocker.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/ethernet/rocker/rocker.c +2 -2
index c6a6e3c..a9d1559 100644
@@ -2901,10 +2901,10 @@ static void _rocker_neigh_add(struct rocker *rocker,
 			      enum switchdev_trans trans,
 			      struct rocker_neigh_tbl_entry *entry)
 {
-	entry->index = rocker->neigh_tbl_next_index;
+	if (trans != SWITCHDEV_TRANS_COMMIT)
+		entry->index = rocker->neigh_tbl_next_index++;
 	if (trans == SWITCHDEV_TRANS_PREPARE)
 		return;
-	rocker->neigh_tbl_next_index++;
 	entry->ref_count++;
 	hash_add(rocker->neigh_tbl, &entry->entry,
 		 be32_to_cpu(entry->ip_addr));
Signature · 1 line
1.7.10.4
Reviewed-by on v1 1/1
#1 lore raw
Quoted 34 lines · On Fri, Jun 12, 2015 at 09:24:40PM -0700, [email protected] wrote:

From: Scott Feldman <[email protected]>

rocker->neigh_tbl_next_index is used to generate unique indices for neigh entries programmed into the device. The way new indices were generated was racy with the new prepare-commit transaction model. A simple fix here removes the race. The race was with two processes getting the same index, one process using prepare-commit, the other not:

Proc A Proc B

PREPARE phase
get neigh_tbl_next_index

NONE phase
get neigh_tbl_next_index neigh_tbl_next_index++

COMMIT phase
neigh_tbl_next_index++

Both A and B got the same index. The fix is to store and increment neigh_tbl_next_index in the PREPARE (or NONE) phase and use value in COMMIT phase:

Proc A Proc B

PREPARE phase
get neigh_tbl_next_index
neigh_tbl_next_index++

NONE phase
get neigh_tbl_next_index neigh_tbl_next_index++

Quoted 5 lines

COMMIT phase
// use value stashed in PREPARE phase

Quoted 24 lines
---
 drivers/net/ethernet/rocker/rocker.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/ethernet/rocker/rocker.c +2 -2
index c6a6e3c..a9d1559 100644
@@ -2901,10 +2901,10 @@ static void _rocker_neigh_add(struct rocker *rocker,
 			      enum switchdev_trans trans,
 			      struct rocker_neigh_tbl_entry *entry)
 {
-	entry->index = rocker->neigh_tbl_next_index;
+	if (trans != SWITCHDEV_TRANS_COMMIT)
+		entry->index = rocker->neigh_tbl_next_index++;
 	if (trans == SWITCHDEV_TRANS_PREPARE)
 		return;
-	rocker->neigh_tbl_next_index++;
 	entry->ref_count++;
 	hash_add(rocker->neigh_tbl, &entry->entry,
 		 be32_to_cpu(entry->ip_addr));
Signature · 1 line
1.7.10.4
maintainer Applied
#2 lore raw
In reply to [email protected]

From: [email protected]
Date: Fri, 12 Jun 2015 21:24:40 -0700

Quoted 7 lines

From: Scott Feldman <[email protected]>

rocker->neigh_tbl_next_index is used to generate unique indices for neigh entries programmed into the device. The way new indices were generated was racy with the new prepare-commit transaction model. A simple fix here removes the race. The race was with two processes getting the same index, one process using prepare-commit, the other not:

...

Quoted 2 lines

Applied.