From nobody Wed Nov 5 16:54:41 2025 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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1536147218756744.7027127977075; Wed, 5 Sep 2018 04:33:38 -0700 (PDT) Received: from localhost ([::1]:55171 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fxW3v-0002g5-TY for importer@patchew.org; Wed, 05 Sep 2018 07:33:31 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50960) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fxW2g-0000zN-Ty for qemu-devel@nongnu.org; Wed, 05 Sep 2018 07:32:15 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fxW2d-0004a8-OO for qemu-devel@nongnu.org; Wed, 05 Sep 2018 07:32:14 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:53034 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fxW2d-0004Zh-Jd; Wed, 05 Sep 2018 07:32:11 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0349A804BAAC; Wed, 5 Sep 2018 11:32:11 +0000 (UTC) Received: from xz-x1.redhat.com (ovpn-12-80.pek2.redhat.com [10.72.12.80]) by smtp.corp.redhat.com (Postfix) with ESMTP id E5E2EFA961; Wed, 5 Sep 2018 11:32:02 +0000 (UTC) From: Peter Xu To: qemu-devel@nongnu.org Date: Wed, 5 Sep 2018 19:31:58 +0800 Message-Id: <20180905113158.23734-1-peterx@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Wed, 05 Sep 2018 11:32:11 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Wed, 05 Sep 2018 11:32:11 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'peterx@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH] intel_iommu: do address space switching when reset 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: Alex Williamson , QEMU Stable , Jason Wang , peterx@redhat.com, "Michael S . Tsirkin" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RDMRC_1 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" We will drop all the mappings when system reset, however we'll still keep the existing memory layouts. That'll be problematic since if IOMMU is enabled in the guest and then reboot the guest, SeaBIOS will try to drive a device that with no page mapped there. What we need to do is to rebuild the GPA->HPA mapping when system resets, hence ease SeaBIOS. Without this patch, a guest that boots on an assigned NVMe device might fail to find the boot device after a system reboot/reset and we'll be able to observe SeaBIOS errors if turned on: WARNING - Timeout at nvme_wait:144! With the patch applied, the guest will be able to find the NVMe drive and bootstrap there even after multiple reboots or system resets. Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=3D1625173 CC: QEMU Stable Tested-by: Cong Li Signed-off-by: Peter Xu --- hw/i386/intel_iommu.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c index 3dfada19a6..d3eb068d43 100644 --- a/hw/i386/intel_iommu.c +++ b/hw/i386/intel_iommu.c @@ -3231,6 +3231,14 @@ static void vtd_reset(DeviceState *dev) * When device reset, throw away all mappings and external caches */ vtd_address_space_unmap_all(s); + + /* + * Switch address spaces if needed (e.g., when reboot from a + * kernel that has IOMMU enabled, we should switch address spaces + * to rebuild the GPA->HPA mappings otherwise SeaBIOS might + * encounter DMA errors when running with e.g. a NVMe card). + */ + vtd_switch_address_space_all(s); } =20 static AddressSpace *vtd_host_dma_iommu(PCIBus *bus, void *opaque, int dev= fn) --=20 2.17.1