From nobody Mon Feb 9 21:36:51 2026 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.zoho.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 1494403616315332.6042584894428; Wed, 10 May 2017 01:06:56 -0700 (PDT) Received: from localhost ([::1]:41012 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d8Me5-0000gd-So for importer@patchew.org; Wed, 10 May 2017 04:06:53 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57663) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d8Ma4-00068v-CK for qemu-devel@nongnu.org; Wed, 10 May 2017 04:02:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d8Ma2-00016B-8x for qemu-devel@nongnu.org; Wed, 10 May 2017 04:02:44 -0400 Received: from mx1.redhat.com ([209.132.183.28]:49506) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1d8Ma2-00015y-07 for qemu-devel@nongnu.org; Wed, 10 May 2017 04:02:42 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D9D37C059724; Wed, 10 May 2017 08:02:40 +0000 (UTC) Received: from pxdev.xzpeter.org.com (vpn1-5-83.pek2.redhat.com [10.72.5.83]) by smtp.corp.redhat.com (Postfix) with ESMTP id 690F51710B; Wed, 10 May 2017 08:02:37 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com D9D37C059724 Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=peterx@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com D9D37C059724 From: Peter Xu To: qemu-devel@nongnu.org Date: Wed, 10 May 2017 16:01:47 +0800 Message-Id: <1494403315-12760-5-git-send-email-peterx@redhat.com> In-Reply-To: <1494403315-12760-1-git-send-email-peterx@redhat.com> References: <1494403315-12760-1-git-send-email-peterx@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Wed, 10 May 2017 08:02:41 +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 v3 04/12] memory: fix address_space_get_iotlb_entry() 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: Lan Tianyu , yi.l.liu@intel.com, "Michael S . Tsirkin" , Jason Wang , peterx@redhat.com, Marcel Apfelbaum , Paolo Bonzini , David Gibson 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" This function has an assumption that we will definitely call translate() once (or say, the addr will be located inside one IOMMU memory region), otherwise an empty IOTLB will be returned. Nevertheless, this is not what we want. When there is no IOMMU memory region, we should build up a static mapping for the caller, instead of an invalid IOTLB. We won't trigger this path before VT-d passthrough mode. When passthrough mode for a vhost device is setup, VT-d is possible to disable the IOMMU region for that device. Without current patch, we'll get a vhost boot failure, and it'll be failed over to virtio userspace mode. CC: Paolo Bonzini CC: Jason Wang CC: Michael S. Tsirkin Signed-off-by: Peter Xu --- exec.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/exec.c b/exec.c index 072de5d..5cfdacd 100644 --- a/exec.c +++ b/exec.c @@ -463,12 +463,13 @@ address_space_translate_internal(AddressSpaceDispatch= *d, hwaddr addr, hwaddr *x } =20 /* Called from RCU critical section */ -IOMMUTLBEntry address_space_get_iotlb_entry(AddressSpace *as, hwaddr addr, +IOMMUTLBEntry address_space_get_iotlb_entry(AddressSpace *as, hwaddr iova, bool is_write) { IOMMUTLBEntry iotlb =3D {0}; MemoryRegionSection *section; MemoryRegion *mr; + hwaddr addr =3D iova, psize; =20 for (;;) { AddressSpaceDispatch *d =3D atomic_rcu_read(&as->dispatch); @@ -478,6 +479,23 @@ IOMMUTLBEntry address_space_get_iotlb_entry(AddressSpa= ce *as, hwaddr addr, mr =3D section->mr; =20 if (!mr->iommu_ops) { + /* + * We didn't translate() but reached here. It possibly + * means it's a static mapping. If so (it should be RAM), + * we set the IOTLB up. + */ + if (!iotlb.target_as && memory_region_is_ram(mr) && + !memory_region_is_rom(mr)) { + psize =3D mr->ram_block->page_size; + iova &=3D ~(psize - 1); + iotlb =3D (IOMMUTLBEntry) { + .target_as =3D &address_space_memory, + .iova =3D iova, + .translated_addr =3D iova, + .addr_mask =3D psize - 1, + .perm =3D IOMMU_RW, + }; + } break; } =20 --=20 2.7.4