From af3120fc8429e90a052afe5c57430e37cf09f27d Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Sat, 25 Jun 2022 16:34:32 +0200 Subject: [PATCH] 4.9-stable patches added patches: ata-libata-add-qc-flags-in-ata_qc_complete_template-tracepoint.patch dm-era-commit-metadata-in-postsuspend-after-worker-stops.patch --- ...-ata_qc_complete_template-tracepoint.patch | 30 ++++++ ...ta-in-postsuspend-after-worker-stops.patch | 91 +++++++++++++++++++ queue-4.9/series | 2 + 3 files changed, 123 insertions(+) create mode 100644 queue-4.9/ata-libata-add-qc-flags-in-ata_qc_complete_template-tracepoint.patch create mode 100644 queue-4.9/dm-era-commit-metadata-in-postsuspend-after-worker-stops.patch diff --git a/queue-4.9/ata-libata-add-qc-flags-in-ata_qc_complete_template-tracepoint.patch b/queue-4.9/ata-libata-add-qc-flags-in-ata_qc_complete_template-tracepoint.patch new file mode 100644 index 00000000000..e6cf9828271 --- /dev/null +++ b/queue-4.9/ata-libata-add-qc-flags-in-ata_qc_complete_template-tracepoint.patch @@ -0,0 +1,30 @@ +From 540a92bfe6dab7310b9df2e488ba247d784d0163 Mon Sep 17 00:00:00 2001 +From: Edward Wu +Date: Fri, 17 Jun 2022 11:32:20 +0800 +Subject: ata: libata: add qc->flags in ata_qc_complete_template tracepoint + +From: Edward Wu + +commit 540a92bfe6dab7310b9df2e488ba247d784d0163 upstream. + +Add flags value to check the result of ata completion + +Fixes: 255c03d15a29 ("libata: Add tracepoints") +Cc: stable@vger.kernel.org +Signed-off-by: Edward Wu +Signed-off-by: Damien Le Moal +Signed-off-by: Greg Kroah-Hartman +--- + include/trace/events/libata.h | 1 + + 1 file changed, 1 insertion(+) + +--- a/include/trace/events/libata.h ++++ b/include/trace/events/libata.h +@@ -248,6 +248,7 @@ DECLARE_EVENT_CLASS(ata_qc_complete_temp + __entry->hob_feature = qc->result_tf.hob_feature; + __entry->nsect = qc->result_tf.nsect; + __entry->hob_nsect = qc->result_tf.hob_nsect; ++ __entry->flags = qc->flags; + ), + + TP_printk("ata_port=%u ata_dev=%u tag=%d flags=%s status=%s " \ diff --git a/queue-4.9/dm-era-commit-metadata-in-postsuspend-after-worker-stops.patch b/queue-4.9/dm-era-commit-metadata-in-postsuspend-after-worker-stops.patch new file mode 100644 index 00000000000..3daf4fcde81 --- /dev/null +++ b/queue-4.9/dm-era-commit-metadata-in-postsuspend-after-worker-stops.patch @@ -0,0 +1,91 @@ +From 9ae6e8b1c9bbf6874163d1243e393137313762b7 Mon Sep 17 00:00:00 2001 +From: Nikos Tsironis +Date: Tue, 21 Jun 2022 15:24:03 +0300 +Subject: dm era: commit metadata in postsuspend after worker stops + +From: Nikos Tsironis + +commit 9ae6e8b1c9bbf6874163d1243e393137313762b7 upstream. + +During postsuspend dm-era does the following: + +1. Archives the current era +2. Commits the metadata, as part of the RPC call for archiving the + current era +3. Stops the worker + +Until the worker stops, it might write to the metadata again. Moreover, +these writes are not flushed to disk immediately, but are cached by the +dm-bufio client, which writes them back asynchronously. + +As a result, the committed metadata of a suspended dm-era device might +not be consistent with the in-core metadata. + +In some cases, this can result in the corruption of the on-disk +metadata. Suppose the following sequence of events: + +1. Load a new table, e.g. a snapshot-origin table, to a device with a + dm-era table +2. Suspend the device +3. dm-era commits its metadata, but the worker does a few more metadata + writes until it stops, as part of digesting an archived writeset +4. These writes are cached by the dm-bufio client +5. Load the dm-era table to another device. +6. The new instance of the dm-era target loads the committed, on-disk + metadata, which don't include the extra writes done by the worker + after the metadata commit. +7. Resume the new device +8. The new dm-era target instance starts using the metadata +9. Resume the original device +10. The destructor of the old dm-era target instance is called and + destroys the dm-bufio client, which results in flushing the cached + writes to disk +11. These writes might overwrite the writes done by the new dm-era + instance, hence corrupting its metadata. + +Fix this by committing the metadata after the worker stops running. + +stop_worker uses flush_workqueue to flush the current work. However, the +work item may re-queue itself and flush_workqueue doesn't wait for +re-queued works to finish. + +This could result in the worker changing the metadata after they have +been committed, or writing to the metadata concurrently with the commit +in the postsuspend thread. + +Use drain_workqueue instead, which waits until the work and all +re-queued works finish. + +Fixes: eec40579d8487 ("dm: add era target") +Cc: stable@vger.kernel.org # v3.15+ +Signed-off-by: Nikos Tsironis +Signed-off-by: Mike Snitzer +Signed-off-by: Greg Kroah-Hartman +--- + drivers/md/dm-era-target.c | 8 +++++++- + 1 file changed, 7 insertions(+), 1 deletion(-) + +--- a/drivers/md/dm-era-target.c ++++ b/drivers/md/dm-era-target.c +@@ -1398,7 +1398,7 @@ static void start_worker(struct era *era + static void stop_worker(struct era *era) + { + atomic_set(&era->suspended, 1); +- flush_workqueue(era->wq); ++ drain_workqueue(era->wq); + } + + /*---------------------------------------------------------------- +@@ -1583,6 +1583,12 @@ static void era_postsuspend(struct dm_ta + } + + stop_worker(era); ++ ++ r = metadata_commit(era->md); ++ if (r) { ++ DMERR("%s: metadata_commit failed", __func__); ++ /* FIXME: fail mode */ ++ } + } + + static int era_preresume(struct dm_target *ti) diff --git a/queue-4.9/series b/queue-4.9/series index 06f37217689..e349bfa39de 100644 --- a/queue-4.9/series +++ b/queue-4.9/series @@ -1,2 +1,4 @@ vt-drop-old-font-ioctls.patch random-schedule-mix_interrupt_randomness-less-often.patch +ata-libata-add-qc-flags-in-ata_qc_complete_template-tracepoint.patch +dm-era-commit-metadata-in-postsuspend-after-worker-stops.patch -- 2.47.3