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

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