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

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