srcu: Improve comments about acceleration leak
Subsystems (2)
PATCH v2 1/1 srcu: Improve comments about acceleration leak
The comments added in commit 1ef990c4b36b ("srcu: No need to advance/accelerate if no callback enqueued") are a bit confusing to me. The comments are describing a scenario for code that was moved and is no longer the way it was (snapshot after advancing). Improve the code comments to reflect this and also document by acceleration can never fail.
---v1->v2: Fix typo in change log.
kernel/rcu/srcutree.c | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-)
kernel/rcu/srcutree.c +20 -4
@@ -1234,11 +1234,20 @@ static unsigned long srcu_gp_start_if_needed(struct srcu_struct *ssp,if (rhp)rcu_segcblist_enqueue (&sdp->srcu_cblist, rhp);/* -* The snapshot for acceleration must be taken _before_ the read of the -* current gp sequence used for advancing, otherwise advancing may fail -* and acceleration may then fail too. +* It's crucial to capture the snapshot 's' for acceleration before +* reading the current gp_seq that is used for advancing. This is +* essential because if the acceleration snapshot is taken after a +* failed advancement attempt, there's a risk that a grace period may +* conclude and a new one may start in the interim. If the snapshot is +* captured after this sequence of events, the acceleration snapshot 's' +* could be excessively advanced, leading to acceleration failure. +* In such a scenario, an 'acceleration leak' can occur, where new +* callbacks become indefinitely stuck in the RCU_NEXT_TAIL segment. +* Also note that encountering advancing failures is a normal +* occurrence when the grace period for RCU_WAIT_TAIL is in progress. * -* This could happen if: +* To see this, consider the following events which occur if +* rcu_seq_snap() were to be called after advance: * * 1) The RCU_WAIT_TAIL segment has callbacks (gp_num = X + 4) and the * RCU_NEXT_READY_TAIL also has callbacks (gp_num = X + 8).
@@ -1264,6 +1273,13 @@ static unsigned long srcu_gp_start_if_needed(struct srcu_struct *ssp,if (rhp) {rcu_segcblist_advance (&sdp->srcu_cblist,rcu_seq_current (&ssp->srcu_sup->srcu_gp_seq)); +/* +* Acceleration can never fail because the state of gp_seq used +* for advancing is <= the state of gp_seq used for +* acceleration. This means that RCU_NEXT_TAIL segment will +* always be able to be emptied by the acceleration into the +* RCU_NEXT_READY_TAIL or RCU_WAIT_TAIL segments. +*/ WARN_ON_ONCE (!rcu_segcblist_accelerate (&sdp->srcu_cblist, s)); }if (ULONG_CMP_LT (sdp->srcu_gp_seq_needed, s)) {
Signature · 1 line
2.43.0.472.g3155946c3a-goog
Quoted 11 lines · Joel Fernandes (Google)
The comments added in commit
1ef990c4b36b("srcu: No need to advance/accelerate if no callback enqueued") are a bit confusing to me. The comments are describing a scenario for code that was moved and is no longer the way it was (snapshot after advancing). Improve the code comments to reflect this and also document by acceleration can never fail.
Quoted 3 lines
Cc Frederic Weisbecker <[email protected]>Cc Neeraj Upadhyay <[email protected]>Signed-off-by Joel Fernandes (Google) <[email protected]>
Do we want to quick review and put it in Neeraj PR?
Or next merge window ok with me. Just that then I have to keep track of it ;-)
Thanks,
- Joel
Quoted 52 lines
---
v1->v2: Fix typo in change log.
kernel/rcu/srcutree.c| 24 ++++++++++++++++++++----1 file changed, 20 insertions(+), 4 deletions(-)kernel/rcu/srcutree.c +20
-4@@ -1234,11 +1234,20 @@ static unsigned long srcu_gp_start_if_needed(struct srcu_struct *ssp,if (rhp)rcu_segcblist_enqueue (&sdp->srcu_cblist, rhp);/* -* The snapshot for acceleration must be taken _before_ the read of the -* current gp sequence used for advancing, otherwise advancing may fail -* and acceleration may then fail too. +* It's crucial to capture the snapshot 's' for acceleration before +* reading the current gp_seq that is used for advancing. This is +* essential because if the acceleration snapshot is taken after a +* failed advancement attempt, there's a risk that a grace period may +* conclude and a new one may start in the interim. If the snapshot is +* captured after this sequence of events, the acceleration snapshot 's' +* could be excessively advanced, leading to acceleration failure. +* In such a scenario, an 'acceleration leak' can occur, where new +* callbacks become indefinitely stuck in the RCU_NEXT_TAIL segment. +* Also note that encountering advancing failures is a normal +* occurrence when the grace period for RCU_WAIT_TAIL is in progress. * -* This could happen if: +* To see this, consider the following events which occur if +* rcu_seq_snap() were to be called after advance: * * 1) The RCU_WAIT_TAIL segment has callbacks (gp_num = X + 4) and the * RCU_NEXT_READY_TAIL also has callbacks (gp_num = X + 8). @@ -1264,6 +1273,13 @@ static unsigned long srcu_gp_start_if_needed(struct srcu_struct *ssp,if (rhp) {rcu_segcblist_advance (&sdp->srcu_cblist,rcu_seq_current (&ssp->srcu_sup->srcu_gp_seq)); +/* +* Acceleration can never fail because the state of gp_seq used +* for advancing is <= the state of gp_seq used for +* acceleration. This means that RCU_NEXT_TAIL segment will +* always be able to be emptied by the acceleration into the +* RCU_NEXT_READY_TAIL or RCU_WAIT_TAIL segments. +*/ WARN_ON_ONCE (!rcu_segcblist_accelerate (&sdp->srcu_cblist, s)); }if (ULONG_CMP_LT (sdp->srcu_gp_seq_needed, s)) {Signature · 1 line
2.43.0.472.g3155946c3a-goog
Paul E. McKenney
maintainerQuoted 11 lines · Joel Fernandes
Quoted 11 lines · Joel Fernandes (Google)
The comments added in commit
1ef990c4b36b("srcu: No need to advance/accelerate if no callback enqueued") are a bit confusing to me. The comments are describing a scenario for code that was moved and is no longer the way it was (snapshot after advancing). Improve the code comments to reflect this and also document by acceleration can never fail.
Quoted 7 lines
Quoted 3 lines
Cc Frederic Weisbecker <[email protected]>Cc Neeraj Upadhyay <[email protected]>Signed-off-by Joel Fernandes (Google) <[email protected]>Do we want to quick review and put it in Neeraj PR?
Or next merge window ok with me. Just that then I have to keep track of it ;-)
Or it could get an ack and I could pull it into -rcu. ;-)
Thanx, Paul
Quoted 58 lines
Thanks,
- Joel
Quoted 52 lines
---
v1->v2: Fix typo in change log.
kernel/rcu/srcutree.c| 24 ++++++++++++++++++++----1 file changed, 20 insertions(+), 4 deletions(-)kernel/rcu/srcutree.c +20
-4@@ -1234,11 +1234,20 @@ static unsigned long srcu_gp_start_if_needed(struct srcu_struct *ssp,if (rhp)rcu_segcblist_enqueue (&sdp->srcu_cblist, rhp);/* -* The snapshot for acceleration must be taken _before_ the read of the -* current gp sequence used for advancing, otherwise advancing may fail -* and acceleration may then fail too. +* It's crucial to capture the snapshot 's' for acceleration before +* reading the current gp_seq that is used for advancing. This is +* essential because if the acceleration snapshot is taken after a +* failed advancement attempt, there's a risk that a grace period may +* conclude and a new one may start in the interim. If the snapshot is +* captured after this sequence of events, the acceleration snapshot 's' +* could be excessively advanced, leading to acceleration failure. +* In such a scenario, an 'acceleration leak' can occur, where new +* callbacks become indefinitely stuck in the RCU_NEXT_TAIL segment. +* Also note that encountering advancing failures is a normal +* occurrence when the grace period for RCU_WAIT_TAIL is in progress. * -* This could happen if: +* To see this, consider the following events which occur if +* rcu_seq_snap() were to be called after advance: * * 1) The RCU_WAIT_TAIL segment has callbacks (gp_num = X + 4) and the * RCU_NEXT_READY_TAIL also has callbacks (gp_num = X + 8). @@ -1264,6 +1273,13 @@ static unsigned long srcu_gp_start_if_needed(struct srcu_struct *ssp,if (rhp) {rcu_segcblist_advance (&sdp->srcu_cblist,rcu_seq_current (&ssp->srcu_sup->srcu_gp_seq)); +/* +* Acceleration can never fail because the state of gp_seq used +* for advancing is <= the state of gp_seq used for +* acceleration. This means that RCU_NEXT_TAIL segment will +* always be able to be emptied by the acceleration into the +* RCU_NEXT_READY_TAIL or RCU_WAIT_TAIL segments. +*/ WARN_ON_ONCE (!rcu_segcblist_accelerate (&sdp->srcu_cblist, s)); }if (ULONG_CMP_LT (sdp->srcu_gp_seq_needed, s)) {Signature · 1 line
2.43.0.472.g3155946c3a-goog
Frederic Weisbecker
maintainerQuoted 2 lines · Joel Fernandes (Google)
The comments added in commit
1ef990c4b36b("srcu: No need to advance/accelerate if no callback enqueued") are a bit confusing to me.
I know some maintainers who may argue that in the changelog world, the first person doesn't exist :-)
Quoted 3 lines
The comments are describing a scenario for code that was moved and is no longer the way it was (snapshot after advancing). Improve the code comments to reflect this and also document by acceleration can never
s/by/why
Quoted 41 lines
fail.
Cc Frederic Weisbecker <[email protected]>Cc Neeraj Upadhyay <[email protected]>Signed-off-by Joel Fernandes (Google) <[email protected]>---
v1->v2: Fix typo in change log.kernel/rcu/srcutree.c | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-)kernel/rcu/srcutree.c +13
-4@@ -1234,11 +1234,20 @@ static unsigned long srcu_gp_start_if_needed(struct srcu_struct *ssp,if (rhp)rcu_segcblist_enqueue (&sdp->srcu_cblist, rhp);/* -* The snapshot for acceleration must be taken _before_ the read of the -* current gp sequence used for advancing, otherwise advancing may fail -* and acceleration may then fail too. +* It's crucial to capture the snapshot 's' for acceleration before +* reading the current gp_seq that is used for advancing. This is +* essential because if the acceleration snapshot is taken after a +* failed advancement attempt, there's a risk that a grace period may +* conclude and a new one may start in the interim. If the snapshot is +* captured after this sequence of events, the acceleration snapshot 's' +* could be excessively advanced, leading to acceleration failure. +* In such a scenario, an 'acceleration leak' can occur, where new +* callbacks become indefinitely stuck in the RCU_NEXT_TAIL segment. +* Also note that encountering advancing failures is a normal +* occurrence when the grace period for RCU_WAIT_TAIL is in progress. * -* This could happen if: +* To see this, consider the following events which occur if +* rcu_seq_snap() were to be called after advance: * * 1) The RCU_WAIT_TAIL segment has callbacks (gp_num = X + 4) and the * RCU_NEXT_READY_TAIL also has callbacks (gp_num = X + 8).
kernel/rcu/srcutree.c static unsigned long srcu_gp_start_if_needed(struct srcu_struct *ssp, · line 1279
Quoted 7 lines
kernel/rcu/srcutree.c +4
-0@@ -1264,6 +1273,13 @@ static unsigned long srcu_gp_start_if_needed(struct srcu_struct *ssp,if (rhp) {rcu_segcblist_advance (&sdp->srcu_cblist,rcu_seq_current (&ssp->srcu_sup->srcu_gp_seq)); +/* +* Acceleration can never fail because the state of gp_seq used +* for advancing is <= the state of gp_seq used for +* acceleration.
What do you mean by "state" here? If it's the gp_seq number, that doesn't look right. The situation raising the initial bug also involved a gp_seq used for advancing <= the gp_seq used for acceleration.
Thanks.
Quoted 10 lines
kernel/rcu/srcutree.c +4
-0+This means that RCU_NEXT_TAIL segment will +* always be able to be emptied by the acceleration into the +* RCU_NEXT_READY_TAIL or RCU_WAIT_TAIL segments. +*/ WARN_ON_ONCE (!rcu_segcblist_accelerate (&sdp->srcu_cblist, s)); }if (ULONG_CMP_LT (sdp->srcu_gp_seq_needed, s)) {Signature · 1 line
2.43.0.472.g3155946c3a-goog
Quoted 7 lines · Frederic Weisbecker
Quoted 2 lines · Joel Fernandes (Google)
The comments added in commit
1ef990c4b36b("srcu: No need to advance/accelerate if no callback enqueued") are a bit confusing to me.I know some maintainers who may argue that in the changelog world, the first person doesn't exist :-)
Heh, that's fair. Ok I can drop the 'to me'. ;-)
Quoted 6 lines
Quoted 4 lines
The comments are describing a scenario for code that was moved and is no longer the way it was (snapshot after advancing). Improve the code comments to reflect this and also document by acceleration can never
s/by/why
Ok.
Quoted 42 lines
Quoted 42 lines
fail.
Cc Frederic Weisbecker <[email protected]>Cc Neeraj Upadhyay <[email protected]>Signed-off-by Joel Fernandes (Google) <[email protected]>---
v1->v2: Fix typo in change log.kernel/rcu/srcutree.c | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-)kernel/rcu/srcutree.c +13
-4@@ -1234,11 +1234,20 @@ static unsigned long srcu_gp_start_if_needed(struct srcu_struct *ssp,if (rhp)rcu_segcblist_enqueue (&sdp->srcu_cblist, rhp);/* -* The snapshot for acceleration must be taken _before_ the read of the -* current gp sequence used for advancing, otherwise advancing may fail -* and acceleration may then fail too. +* It's crucial to capture the snapshot 's' for acceleration before +* reading the current gp_seq that is used for advancing. This is +* essential because if the acceleration snapshot is taken after a +* failed advancement attempt, there's a risk that a grace period may +* conclude and a new one may start in the interim. If the snapshot is +* captured after this sequence of events, the acceleration snapshot 's' +* could be excessively advanced, leading to acceleration failure. +* In such a scenario, an 'acceleration leak' can occur, where new +* callbacks become indefinitely stuck in the RCU_NEXT_TAIL segment. +* Also note that encountering advancing failures is a normal +* occurrence when the grace period for RCU_WAIT_TAIL is in progress. * -* This could happen if: +* To see this, consider the following events which occur if +* rcu_seq_snap() were to be called after advance: * * 1) The RCU_WAIT_TAIL segment has callbacks (gp_num = X + 4) and the * RCU_NEXT_READY_TAIL also has callbacks (gp_num = X + 8). @@ -1264,6 +1273,13 @@ static unsigned long srcu_gp_start_if_needed(struct srcu_struct *ssp,if (rhp) {
Quoted 8 lines
kernel/rcu/srcutree.c static unsigned long srcu_gp_start_if_needed(struct srcu_struct *ssp,
Quoted 6 lines
kernel/rcu/srcutree.c +4
-0rcu_segcblist_advance (&sdp->srcu_cblist,rcu_seq_current (&ssp->srcu_sup->srcu_gp_seq)); +/* +* Acceleration can never fail because the state of gp_seq used +* for advancing is <= the state of gp_seq used for +* acceleration. What do you mean by "state" here?
State means "value at a certain point in time" here.
Quoted 1 line
If it's the
gp_seqnumber, that doesn't look right.
Uff, I screwed up the comment. I swapped "acceleration" and "advancing". I should say:
"Acceleration can never fail because the state of gp_seq value used for acceleration is <= the state of gp_seq used for advancing."
Does that sound correct now?
Quoted 1 line
The situation raising the initial bug also involved a
gp_seqused for advancing <= thegp_seqused for acceleration.
Right, which I understand is the bug.
thanks,
- Joel
Frederic Weisbecker
maintainerQuoted 4 lines · Joel Fernandes
"Acceleration can never fail because the state of
gp_seqvalue used for acceleration is <= the state ofgp_seqused for advancing."Does that sound correct now?
That can be confusing since acceleration relies on rcu_seq_snap() while advance relies on rcu_seq_current(). And rcu_seq_snap() returns a snapshot that may be above the subsequent rcu_seq_current() return value.
So it should rather be something like:
"The base current gp_seq value used to produce the snapshot has to be <= the gp_seq used for advancing."
Thanks.
Quoted 7 lines · Frederic Weisbecker
Quoted 4 lines · Joel Fernandes
"Acceleration can never fail because the state of
gp_seqvalue used for acceleration is <= the state ofgp_seqused for advancing."Does that sound correct now?
Quoted 8 lines
That can be confusing since acceleration relies on
rcu_seq_snap()while advance relies onrcu_seq_current(). Andrcu_seq_snap()returns a snapshot that may be above the subsequentrcu_seq_current()return value.So it should rather be something like:
"The base current
gp_seqvalue used to produce the snapshot has to be <= thegp_seqused for advancing."
Yeah "base current gp_seq" though probably equally confusing sounds a bit better, so I'll just use that instead of "state of gp_seq".
With that can I add your Review tag?
- Joel
Frederic Weisbecker
maintainerQuoted 14 lines · Joel Fernandes
Quoted 13 lines · Frederic Weisbecker
Quoted 4 lines · Joel Fernandes
"Acceleration can never fail because the state of
gp_seqvalue used for acceleration is <= the state ofgp_seqused for advancing."Does that sound correct now?
That can be confusing since acceleration relies on
rcu_seq_snap()while advance relies onrcu_seq_current(). Andrcu_seq_snap()returns a snapshot that may be above the subsequentrcu_seq_current()return value.So it should rather be something like:
Quoted 7 lines
Quoted 2 lines
"The base current
gp_seqvalue used to produce the snapshot has to be <= thegp_seqused for advancing."Yeah "base current
gp_seq" though probably equally confusing sounds a bit better, so I'll just use that instead of "state ofgp_seq".With that can I add your Review tag?
Sure, sounds good!
Thanks.
Quoted 3 lines
- Joel