thebeanogamer / rpms / qemu-kvm

Forked from rpms/qemu-kvm 5 months ago
Clone

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

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