yeahuh / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone

Blame SOURCES/kvm-job-Fix-nested-aio_poll-hanging-in-job_txn_apply.patch

ae23c9
From bdc8bf786dcd258488ffd64fa37ecb0e801141ce Mon Sep 17 00:00:00 2001
ae23c9
From: Kevin Wolf <kwolf@redhat.com>
ae23c9
Date: Wed, 10 Oct 2018 20:21:54 +0100
ae23c9
Subject: [PATCH 28/49] job: Fix nested aio_poll() hanging in job_txn_apply
ae23c9
ae23c9
RH-Author: Kevin Wolf <kwolf@redhat.com>
ae23c9
Message-id: <20181010202213.7372-16-kwolf@redhat.com>
ae23c9
Patchwork-id: 82605
ae23c9
O-Subject: [RHEL-8 qemu-kvm PATCH 25/44] job: Fix nested aio_poll() hanging in job_txn_apply
ae23c9
Bugzilla: 1637976
ae23c9
RH-Acked-by: Max Reitz <mreitz@redhat.com>
ae23c9
RH-Acked-by: John Snow <jsnow@redhat.com>
ae23c9
RH-Acked-by: Thomas Huth <thuth@redhat.com>
ae23c9
ae23c9
From: Fam Zheng <famz@redhat.com>
ae23c9
ae23c9
All callers have acquired ctx already. Doing that again results in
ae23c9
aio_poll() hang. This fixes the problem that a BDRV_POLL_WHILE() in the
ae23c9
callback cannot make progress because ctx is recursively locked, for
ae23c9
example, when drive-backup finishes.
ae23c9
ae23c9
There are two callers of job_finalize():
ae23c9
ae23c9
    fam@lemon:~/work/qemu [master]$ git grep -w -A1 '^\s*job_finalize'
ae23c9
    blockdev.c:    job_finalize(&job->job, errp);
ae23c9
    blockdev.c-    aio_context_release(aio_context);
ae23c9
    --
ae23c9
    job-qmp.c:    job_finalize(job, errp);
ae23c9
    job-qmp.c-    aio_context_release(aio_context);
ae23c9
    --
ae23c9
    tests/test-blockjob.c:    job_finalize(&job->job, &error_abort);
ae23c9
    tests/test-blockjob.c-    assert(job->job.status == JOB_STATUS_CONCLUDED);
ae23c9
ae23c9
Ignoring the test, it's easy to see both callers to job_finalize (and
ae23c9
job_do_finalize) have acquired the context.
ae23c9
ae23c9
Cc: qemu-stable@nongnu.org
ae23c9
Reported-by: Gu Nini <ngu@redhat.com>
ae23c9
Reviewed-by: Eric Blake <eblake@redhat.com>
ae23c9
Signed-off-by: Fam Zheng <famz@redhat.com>
ae23c9
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
ae23c9
(cherry picked from commit 49880165a44f26dc84651858750facdee31f2513)
ae23c9
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
ae23c9
Signed-off-by: Danilo C. L. de Paula <ddepaula@redhat.com>
ae23c9
---
ae23c9
 job.c | 18 +++++-------------
ae23c9
 1 file changed, 5 insertions(+), 13 deletions(-)
ae23c9
ae23c9
diff --git a/job.c b/job.c
ae23c9
index dfba4bc..5d117fb 100644
ae23c9
--- a/job.c
ae23c9
+++ b/job.c
ae23c9
@@ -136,21 +136,13 @@ static void job_txn_del_job(Job *job)
ae23c9
     }
ae23c9
 }
ae23c9
 
ae23c9
-static int job_txn_apply(JobTxn *txn, int fn(Job *), bool lock)
ae23c9
+static int job_txn_apply(JobTxn *txn, int fn(Job *))
ae23c9
 {
ae23c9
-    AioContext *ctx;
ae23c9
     Job *job, *next;
ae23c9
     int rc = 0;
ae23c9
 
ae23c9
     QLIST_FOREACH_SAFE(job, &txn->jobs, txn_list, next) {
ae23c9
-        if (lock) {
ae23c9
-            ctx = job->aio_context;
ae23c9
-            aio_context_acquire(ctx);
ae23c9
-        }
ae23c9
         rc = fn(job);
ae23c9
-        if (lock) {
ae23c9
-            aio_context_release(ctx);
ae23c9
-        }
ae23c9
         if (rc) {
ae23c9
             break;
ae23c9
         }
ae23c9
@@ -775,11 +767,11 @@ static void job_do_finalize(Job *job)
ae23c9
     assert(job && job->txn);
ae23c9
 
ae23c9
     /* prepare the transaction to complete */
ae23c9
-    rc = job_txn_apply(job->txn, job_prepare, true);
ae23c9
+    rc = job_txn_apply(job->txn, job_prepare);
ae23c9
     if (rc) {
ae23c9
         job_completed_txn_abort(job);
ae23c9
     } else {
ae23c9
-        job_txn_apply(job->txn, job_finalize_single, true);
ae23c9
+        job_txn_apply(job->txn, job_finalize_single);
ae23c9
     }
ae23c9
 }
ae23c9
 
ae23c9
@@ -825,10 +817,10 @@ static void job_completed_txn_success(Job *job)
ae23c9
         assert(other_job->ret == 0);
ae23c9
     }
ae23c9
 
ae23c9
-    job_txn_apply(txn, job_transition_to_pending, false);
ae23c9
+    job_txn_apply(txn, job_transition_to_pending);
ae23c9
 
ae23c9
     /* If no jobs need manual finalization, automatically do so */
ae23c9
-    if (job_txn_apply(txn, job_needs_finalize, false) == 0) {
ae23c9
+    if (job_txn_apply(txn, job_needs_finalize) == 0) {
ae23c9
         job_do_finalize(job);
ae23c9
     }
ae23c9
 }
ae23c9
-- 
ae23c9
1.8.3.1
ae23c9