md: Set prev_flush_start and flush_bio in an atomic way
Subsystems (2)
From: Xiao Ni <[email protected]>
One customer reports a crash problem which causes by flush request. It triggers a warning before crash.
/* new request after previous flush is completed */
if (ktime_after(req_start, mddev->prev_flush_start)) {
WARN_ON(mddev->flush_bio);
mddev->flush_bio = bio;
bio = NULL;
}The WARN_ON is triggered. We use spin lock to protect prev_flush_start and flush_bio in md_flush_request. But there is no lock protection in md_submit_flush_data. It can set flush_bio to NULL first because of compiler reordering write instructions.
For example, flush bio1 sets flush bio to NULL first in md_submit_flush_data. An interrupt or vmware causing an extended stall happen between updating flush_bio and prev_flush_start. Because flush_bio is NULL, flush bio2 can get the lock and submit to underlayer disks. Then flush bio1 updates prev_flush_start after the interrupt or extended stall.
Then flush bio3 enters in md_flush_request. The start time req_start is behind prev_flush_start. The flush_bio is not NULL(flush bio2 hasn't finished). So it can trigger the WARN_ON now. Then it calls INIT_WORK again. INIT_WORK() will re-initialize the list pointers in the work_struct, which then can result in a corrupted work list and the work_struct queued a second time. With the work list corrupted, it can lead in invalid work items being used and cause a crash in process_one_work.
We need to make sure only one flush bio can be handled at one same time. So add spin lock in md_submit_flush_data to protect prev_flush_start and flush_bio in an atomic way.
--- drivers/md/md.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/md/md.c +2 -0
@@ -639,8 +639,10 @@ static void md_submit_flush_data(struct work_struct *ws)* could wait for this and below md_handle_request could wait for those * bios because of suspend check */ +spin_lock_irq (&mddev->lock); mddev->last_flush = mddev->start_flush; mddev->flush_bio =NULL ; +spin_unlock_irq (&mddev->lock);wake_up (&mddev->sb_wait);if (bio->bi_iter.bi_size ==0 ) {
Signature · 1 line
2.25.1
Greg KH
maintainerQuoted 62 lines · Jack Wang
From: Xiao Ni <[email protected]>
One customer reports a crash problem which causes by flush request. It triggers a warning before crash.
/* new request after previous flush is completed */ if (ktime_after(req_start, mddev->prev_flush_start)) { WARN_ON(mddev->flush_bio); mddev->flush_bio = bio; bio = NULL; }The
WARN_ONis triggered. We use spin lock to protectprev_flush_startandflush_bioinmd_flush_request. But there is no lock protection inmd_submit_flush_data. It can setflush_bioto NULL first because of compiler reordering write instructions.For example, flush bio1 sets flush bio to NULL first in
md_submit_flush_data. An interrupt or vmware causing an extended stall happen between updatingflush_bioandprev_flush_start. Becauseflush_biois NULL, flush bio2 can get the lock and submit to underlayer disks. Then flush bio1 updatesprev_flush_startafter the interrupt or extended stall.Then flush bio3 enters in
md_flush_request. The start timereq_startis behindprev_flush_start. Theflush_biois not NULL(flush bio2 hasn't finished). So it can trigger theWARN_ONnow. Then it callsINIT_WORKagain.INIT_WORK()will re-initialize the list pointers in thework_struct, which then can result in a corrupted work list and thework_structqueued a second time. With the work list corrupted, it can lead in invalid work items being used and cause a crash inprocess_one_work.We need to make sure only one flush bio can be handled at one same time. So add spin lock in
md_submit_flush_datato protectprev_flush_startandflush_bioin an atomic way.Reviewed-by David Jeffery <[email protected]>Signed-off-by Xiao Ni <[email protected]>Signed-off-by Song Liu <[email protected]>[jwang: backport dc5d17a3c39b06aef866afca19245a9cfb533a79 to 4.19]Signed-off-by Jack Wang <[email protected]>--- drivers/md/md.c | 2 ++ 1 file changed, 2 insertions(+)drivers/md/md.c +2
-0@@ -639,8 +639,10 @@ static void md_submit_flush_data(struct work_struct *ws)* could wait for this and below md_handle_request could wait for those * bios because of suspend check */ +spin_lock_irq (&mddev->lock); mddev->last_flush = mddev->start_flush; mddev->flush_bio =NULL ; +spin_unlock_irq (&mddev->lock);wake_up (&mddev->sb_wait);if (bio->bi_iter.bi_size ==0 ) {Signature · 1 line
2.25.1
Now queued up, thanks.
greg k-h
Quoted 61 lines · Greg KH
Quoted 59 lines · Jack Wang
From: Xiao Ni <[email protected]>
One customer reports a crash problem which causes by flush request. It triggers a warning before crash.
/* new request after previous flush is completed */ if (ktime_after(req_start, mddev->prev_flush_start)) { WARN_ON(mddev->flush_bio); mddev->flush_bio = bio; bio = NULL; }The
WARN_ONis triggered. We use spin lock to protectprev_flush_startandflush_bioinmd_flush_request. But there is no lock protection inmd_submit_flush_data. It can setflush_bioto NULL first because of compiler reordering write instructions.For example, flush bio1 sets flush bio to NULL first in
md_submit_flush_data. An interrupt or vmware causing an extended stall happen between updatingflush_bioandprev_flush_start. Becauseflush_biois NULL, flush bio2 can get the lock and submit to underlayer disks. Then flush bio1 updatesprev_flush_startafter the interrupt or extended stall.Then flush bio3 enters in
md_flush_request. The start timereq_startis behindprev_flush_start. Theflush_biois not NULL(flush bio2 hasn't finished). So it can trigger theWARN_ONnow. Then it callsINIT_WORKagain.INIT_WORK()will re-initialize the list pointers in thework_struct, which then can result in a corrupted work list and thework_structqueued a second time. With the work list corrupted, it can lead in invalid work items being used and cause a crash inprocess_one_work.We need to make sure only one flush bio can be handled at one same time. So add spin lock in
md_submit_flush_datato protectprev_flush_startandflush_bioin an atomic way.Reviewed-by David Jeffery <[email protected]>Signed-off-by Xiao Ni <[email protected]>Signed-off-by Song Liu <[email protected]>[jwang: backport dc5d17a3c39b06aef866afca19245a9cfb533a79 to 4.19]Signed-off-by Jack Wang <[email protected]>--- drivers/md/md.c | 2 ++ 1 file changed, 2 insertions(+)drivers/md/md.c +2
-0@@ -639,8 +639,10 @@ static void md_submit_flush_data(struct work_struct *ws)* could wait for this and below md_handle_request could wait for those * bios because of suspend check */ +spin_lock_irq (&mddev->lock); mddev->last_flush = mddev->start_flush; mddev->flush_bio =NULL ; +spin_unlock_irq (&mddev->lock);wake_up (&mddev->sb_wait);
Quoted 7 lines
Quoted 3 lines
drivers/md/md.c +0
-1if (bio->bi_iter.bi_size ==0 ) { --2.25.1
Now queued up, thanks.
greg k-h
Thanks, I see only this patch got applied. Do you have concern regarding first 7 patches?
Regards!
Greg KH
maintainerQuoted 68 lines · Jinpu Wang
Quoted 67 lines · Greg KH
Quoted 61 lines · Jack Wang
From: Xiao Ni <[email protected]>
One customer reports a crash problem which causes by flush request. It triggers a warning before crash.
/* new request after previous flush is completed */ if (ktime_after(req_start, mddev->prev_flush_start)) { WARN_ON(mddev->flush_bio); mddev->flush_bio = bio; bio = NULL; }The
WARN_ONis triggered. We use spin lock to protectprev_flush_startandflush_bioinmd_flush_request. But there is no lock protection inmd_submit_flush_data. It can setflush_bioto NULL first because of compiler reordering write instructions.For example, flush bio1 sets flush bio to NULL first in
md_submit_flush_data. An interrupt or vmware causing an extended stall happen between updatingflush_bioandprev_flush_start. Becauseflush_biois NULL, flush bio2 can get the lock and submit to underlayer disks. Then flush bio1 updatesprev_flush_startafter the interrupt or extended stall.Then flush bio3 enters in
md_flush_request. The start timereq_startis behindprev_flush_start. Theflush_biois not NULL(flush bio2 hasn't finished). So it can trigger theWARN_ONnow. Then it callsINIT_WORKagain.INIT_WORK()will re-initialize the list pointers in thework_struct, which then can result in a corrupted work list and thework_structqueued a second time. With the work list corrupted, it can lead in invalid work items being used and cause a crash inprocess_one_work.We need to make sure only one flush bio can be handled at one same time. So add spin lock in
md_submit_flush_datato protectprev_flush_startandflush_bioin an atomic way.Reviewed-by David Jeffery <[email protected]>Signed-off-by Xiao Ni <[email protected]>Signed-off-by Song Liu <[email protected]>[jwang: backport dc5d17a3c39b06aef866afca19245a9cfb533a79 to 4.19]Signed-off-by Jack Wang <[email protected]>--- drivers/md/md.c | 2 ++ 1 file changed, 2 insertions(+)drivers/md/md.c +2
-1@@ -639,8 +639,10 @@ static void md_submit_flush_data(struct work_struct *ws)* could wait for this and below md_handle_request could wait for those * bios because of suspend check */ +spin_lock_irq (&mddev->lock); mddev->last_flush = mddev->start_flush; mddev->flush_bio =NULL ; +spin_unlock_irq (&mddev->lock);wake_up (&mddev->sb_wait);if (bio->bi_iter.bi_size ==0 ) { --Quoted 1 line
2.25.1
Now queued up, thanks.
Quoted 3 lines
Quoted 1 line
greg k-h
Thanks, I see only this patch got applied. Do you have concern regarding first 7 patches?
I only see this one patch. Please resend anything else you wish to have applied as I think I said that I dropped everything you submitted before, right?
thanks,
greg k-h
Quoted 70 lines · Greg KH
Quoted 68 lines · Jinpu Wang
Quoted 67 lines · Greg KH
Quoted 61 lines · Jack Wang
From: Xiao Ni <[email protected]>
One customer reports a crash problem which causes by flush request. It triggers a warning before crash.
/* new request after previous flush is completed */ if (ktime_after(req_start, mddev->prev_flush_start)) { WARN_ON(mddev->flush_bio); mddev->flush_bio = bio; bio = NULL; }The
WARN_ONis triggered. We use spin lock to protectprev_flush_startandflush_bioinmd_flush_request. But there is no lock protection inmd_submit_flush_data. It can setflush_bioto NULL first because of compiler reordering write instructions.For example, flush bio1 sets flush bio to NULL first in
md_submit_flush_data. An interrupt or vmware causing an extended stall happen between updatingflush_bioandprev_flush_start. Becauseflush_biois NULL, flush bio2 can get the lock and submit to underlayer disks. Then flush bio1 updatesprev_flush_startafter the interrupt or extended stall.Then flush bio3 enters in
md_flush_request. The start timereq_startis behindprev_flush_start. Theflush_biois not NULL(flush bio2 hasn't finished). So it can trigger theWARN_ONnow. Then it callsINIT_WORKagain.INIT_WORK()will re-initialize the list pointers in thework_struct, which then can result in a corrupted work list and thework_structqueued a second time. With the work list corrupted, it can lead in invalid work items being used and cause a crash inprocess_one_work.We need to make sure only one flush bio can be handled at one same time. So add spin lock in
md_submit_flush_datato protectprev_flush_startandflush_bioin an atomic way.Reviewed-by David Jeffery <[email protected]>Signed-off-by Xiao Ni <[email protected]>Signed-off-by Song Liu <[email protected]>[jwang: backport dc5d17a3c39b06aef866afca19245a9cfb533a79 to 4.19]Signed-off-by Jack Wang <[email protected]>--- drivers/md/md.c | 2 ++ 1 file changed, 2 insertions(+)drivers/md/md.c +2
-1@@ -639,8 +639,10 @@ static void md_submit_flush_data(struct work_struct *ws)* could wait for this and below md_handle_request could wait for those * bios because of suspend check */ +spin_lock_irq (&mddev->lock); mddev->last_flush = mddev->start_flush; mddev->flush_bio =NULL ; +spin_unlock_irq (&mddev->lock);wake_up (&mddev->sb_wait);if (bio->bi_iter.bi_size ==0 ) { --Quoted 1 line
2.25.1
Now queued up, thanks.
Quoted 7 lines
Quoted 3 lines
Quoted 1 line
greg k-h
Thanks, I see only this patch got applied. Do you have concern regarding first 7 patches?
I only see this one patch. Please resend anything else you wish to have applied as I think I said that I dropped everything you submitted before, right?
Ah, ok, I misunderstood your comments, I will resend them.
Quoted 4 lines
thanks,
greg k-h
Thanks.