From nobody Mon Apr 29 02:10:11 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1502949450088806.8379000346943; Wed, 16 Aug 2017 22:57:30 -0700 (PDT) Received: from localhost ([::1]:34211 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1diDo8-00051C-Cq for importer@patchew.org; Thu, 17 Aug 2017 01:57:28 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37018) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1diDnK-0004e8-Ah for qemu-devel@nongnu.org; Thu, 17 Aug 2017 01:56:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1diDnF-0008Mv-E6 for qemu-devel@nongnu.org; Thu, 17 Aug 2017 01:56:38 -0400 Received: from mx1.redhat.com ([209.132.183.28]:32774) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1diDnF-0008MK-7d for qemu-devel@nongnu.org; Thu, 17 Aug 2017 01:56:33 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id DEB777CBA8 for ; Thu, 17 Aug 2017 05:56:31 +0000 (UTC) Received: from pxdev.xzpeter.org.com (dhcp-15-224.nay.redhat.com [10.66.15.224]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0360161289; Thu, 17 Aug 2017 05:56:18 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com DEB777CBA8 Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=peterx@redhat.com From: Peter Xu To: qemu-devel@nongnu.org Date: Thu, 17 Aug 2017 13:56:14 +0800 Message-Id: <1502949374-3061-1-git-send-email-peterx@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Thu, 17 Aug 2017 05:56:32 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH for-2.11] intel_iommu: fix missing BQL in pt fast path X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , Jason Wang , peterx@redhat.com, "Michael S . Tsirkin" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" In vtd_switch_address_space() we did the memory region switch, however it's possible that the caller of it has not taken the BQL at all. Make sure we have it. CC: Paolo Bonzini CC: Jason Wang CC: Michael S. Tsirkin Signed-off-by: Peter Xu --- Paolo: I noticed this qemu_mutex_iothread_locked() function, which might simplify the fix, so I decided to use it. Using bottom half should be ok as well, but after a second thought it can be complicated: consider the case when guest firstly triggered the pt fast path then quickly re-enables the IOMMU region before the bottom half being executed. Then looks like we need special care on the sync of bottom half task as well. That's over-complicated I guess (if with that, I'd prefer to remove the pt fast path since it's even not really the default path when pt is used...). Please let me know if you don't think so. --- hw/i386/intel_iommu.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c index a7bf87a..3a5bb0b 100644 --- a/hw/i386/intel_iommu.c +++ b/hw/i386/intel_iommu.c @@ -957,6 +957,8 @@ static bool vtd_dev_pt_enabled(VTDAddressSpace *as) static bool vtd_switch_address_space(VTDAddressSpace *as) { bool use_iommu; + /* Whether we need to take the BQL on our own */ + bool take_bql =3D !qemu_mutex_iothread_locked(); =20 assert(as); =20 @@ -967,6 +969,15 @@ static bool vtd_switch_address_space(VTDAddressSpace *= as) VTD_PCI_FUNC(as->devfn), use_iommu); =20 + /* + * It's possible that we reach here without BQL, e.g., when called + * from vtd_pt_enable_fast_path(). However the memory APIs need + * it. We'd better make sure we have had it already, or, take it. + */ + if (take_bql) { + qemu_mutex_lock_iothread(); + } + /* Turn off first then on the other */ if (use_iommu) { memory_region_set_enabled(&as->sys_alias, false); @@ -976,6 +987,10 @@ static bool vtd_switch_address_space(VTDAddressSpace *= as) memory_region_set_enabled(&as->sys_alias, true); } =20 + if (take_bql) { + qemu_mutex_unlock_iothread(); + } + return use_iommu; } =20 --=20 2.7.4