Blame SOURCES/kvm-intel_iommu-fix-missing-BQL-in-pt-fast-path.patch

4a2fec
From f2fb460ba2b9c5547f8bcf4d7542a5e17bbe09bd Mon Sep 17 00:00:00 2001
4a2fec
From: Peter Xu <peterx@redhat.com>
4a2fec
Date: Mon, 9 Oct 2017 06:51:32 +0200
4a2fec
Subject: [PATCH 05/69] intel_iommu: fix missing BQL in pt fast path
4a2fec
4a2fec
RH-Author: Peter Xu <peterx@redhat.com>
4a2fec
Message-id: <20171009065132.5597-2-peterx@redhat.com>
4a2fec
Patchwork-id: 76929
4a2fec
O-Subject: [RHEV-7.5 qemu-kvm-rhev PATCH 1/1] intel_iommu: fix missing BQL in pt fast path
4a2fec
Bugzilla: 1449067
4a2fec
RH-Acked-by: Paolo Bonzini <pbonzini@redhat.com>
4a2fec
RH-Acked-by: Laszlo Ersek <lersek@redhat.com>
4a2fec
RH-Acked-by: Thomas Huth <thuth@redhat.com>
4a2fec
4a2fec
In vtd_switch_address_space() we did the memory region switch, however
4a2fec
it's possible that the caller of it has not taken the BQL at all. Make
4a2fec
sure we have it.
4a2fec
4a2fec
CC: Paolo Bonzini <pbonzini@redhat.com>
4a2fec
CC: Jason Wang <jasowang@redhat.com>
4a2fec
CC: Michael S. Tsirkin <mst@redhat.com>
4a2fec
Signed-off-by: Peter Xu <peterx@redhat.com>
4a2fec
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
4a2fec
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
4a2fec
(cherry picked from commit 66a4a0318e6b9539505491e4576fb93a708095d8)
4a2fec
Signed-off-by: Peter Xu <peterx@redhat.com>
4a2fec
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
4a2fec
---
4a2fec
 hw/i386/intel_iommu.c | 15 +++++++++++++++
4a2fec
 1 file changed, 15 insertions(+)
4a2fec
4a2fec
diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c
4a2fec
index a7bf87a..3a5bb0b 100644
4a2fec
--- a/hw/i386/intel_iommu.c
4a2fec
+++ b/hw/i386/intel_iommu.c
4a2fec
@@ -957,6 +957,8 @@ static bool vtd_dev_pt_enabled(VTDAddressSpace *as)
4a2fec
 static bool vtd_switch_address_space(VTDAddressSpace *as)
4a2fec
 {
4a2fec
     bool use_iommu;
4a2fec
+    /* Whether we need to take the BQL on our own */
4a2fec
+    bool take_bql = !qemu_mutex_iothread_locked();
4a2fec
 
4a2fec
     assert(as);
4a2fec
 
4a2fec
@@ -967,6 +969,15 @@ static bool vtd_switch_address_space(VTDAddressSpace *as)
4a2fec
                                    VTD_PCI_FUNC(as->devfn),
4a2fec
                                    use_iommu);
4a2fec
 
4a2fec
+    /*
4a2fec
+     * It's possible that we reach here without BQL, e.g., when called
4a2fec
+     * from vtd_pt_enable_fast_path(). However the memory APIs need
4a2fec
+     * it. We'd better make sure we have had it already, or, take it.
4a2fec
+     */
4a2fec
+    if (take_bql) {
4a2fec
+        qemu_mutex_lock_iothread();
4a2fec
+    }
4a2fec
+
4a2fec
     /* Turn off first then on the other */
4a2fec
     if (use_iommu) {
4a2fec
         memory_region_set_enabled(&as->sys_alias, false);
4a2fec
@@ -976,6 +987,10 @@ static bool vtd_switch_address_space(VTDAddressSpace *as)
4a2fec
         memory_region_set_enabled(&as->sys_alias, true);
4a2fec
     }
4a2fec
 
4a2fec
+    if (take_bql) {
4a2fec
+        qemu_mutex_unlock_iothread();
4a2fec
+    }
4a2fec
+
4a2fec
     return use_iommu;
4a2fec
 }
4a2fec
 
4a2fec
-- 
4a2fec
1.8.3.1
4a2fec