From nobody Sun Apr 28 00:20:07 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.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 1494838351483372.8093426679475; Mon, 15 May 2017 01:52:31 -0700 (PDT) Received: from localhost ([::1]:35454 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dABjw-0004R1-GG for importer@patchew.org; Mon, 15 May 2017 04:52:28 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34151) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dABin-0003pD-VR for qemu-devel@nongnu.org; Mon, 15 May 2017 04:51:18 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dABik-0005Y0-D5 for qemu-devel@nongnu.org; Mon, 15 May 2017 04:51:18 -0400 Received: from mx1.redhat.com ([209.132.183.28]:43868) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dABik-0005Xq-7a for qemu-devel@nongnu.org; Mon, 15 May 2017 04:51:14 -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 303E3C059722; Mon, 15 May 2017 08:51:13 +0000 (UTC) Received: from pxdev.xzpeter.org.com (vpn1-5-116.pek2.redhat.com [10.72.5.116]) by smtp.corp.redhat.com (Postfix) with ESMTP id C4B535C888; Mon, 15 May 2017 08:51:10 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 303E3C059722 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 303E3C059722 From: Peter Xu To: qemu-devel@nongnu.org Date: Mon, 15 May 2017 16:50:57 +0800 Message-Id: <1494838260-30439-2-git-send-email-peterx@redhat.com> In-Reply-To: <1494838260-30439-1-git-send-email-peterx@redhat.com> References: <1494838260-30439-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]); Mon, 15 May 2017 08:51:13 +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 1/4] exec: simplify phys_page_find() params 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 , "Michael S . Tsirkin" , peterx@redhat.com, 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" It really only plays with the dispatchers, so the parameter list does not need that complexity. This helps for readability at least. Signed-off-by: Peter Xu Reviewed-by: David Gibson Tested-by: Maxime Coquelin --- exec.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/exec.c b/exec.c index eac6085..1d76c63 100644 --- a/exec.c +++ b/exec.c @@ -371,10 +371,11 @@ static inline bool section_covers_addr(const MemoryRe= gionSection *section, int128_getlo(section->size), addr); } =20 -static MemoryRegionSection *phys_page_find(PhysPageEntry lp, hwaddr addr, - Node *nodes, MemoryRegionSectio= n *sections) +static MemoryRegionSection *phys_page_find(AddressSpaceDispatch *d, hwaddr= addr) { - PhysPageEntry *p; + PhysPageEntry lp =3D d->phys_map, *p; + Node *nodes =3D d->map.nodes; + MemoryRegionSection *sections =3D d->map.sections; hwaddr index =3D addr >> TARGET_PAGE_BITS; int i; =20 @@ -412,8 +413,7 @@ static MemoryRegionSection *address_space_lookup_region= (AddressSpaceDispatch *d, section_covers_addr(section, addr)) { update =3D false; } else { - section =3D phys_page_find(d->phys_map, addr, d->map.nodes, - d->map.sections); + section =3D phys_page_find(d, addr); update =3D true; } if (resolve_subpage && section->mr->subpage) { @@ -1246,8 +1246,7 @@ static void register_subpage(AddressSpaceDispatch *d,= MemoryRegionSection *secti subpage_t *subpage; hwaddr base =3D section->offset_within_address_space & TARGET_PAGE_MASK; - MemoryRegionSection *existing =3D phys_page_find(d->phys_map, base, - d->map.nodes, d->map.se= ctions); + MemoryRegionSection *existing =3D phys_page_find(d, base); MemoryRegionSection subsection =3D { .offset_within_address_space =3D base, .size =3D int128_make64(TARGET_PAGE_SIZE), --=20 2.7.4 From nobody Sun Apr 28 00:20:07 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.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 1494838445499206.91546758894083; Mon, 15 May 2017 01:54:05 -0700 (PDT) Received: from localhost ([::1]:35461 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dABlT-0005pt-AU for importer@patchew.org; Mon, 15 May 2017 04:54:03 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34166) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dABio-0003pI-Tl for qemu-devel@nongnu.org; Mon, 15 May 2017 04:51:19 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dABio-0005Yx-3e for qemu-devel@nongnu.org; Mon, 15 May 2017 04:51:19 -0400 Received: from mx1.redhat.com ([209.132.183.28]:33748) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dABin-0005Yg-V8 for qemu-devel@nongnu.org; Mon, 15 May 2017 04:51:18 -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 F0A00C0467CB; Mon, 15 May 2017 08:51:16 +0000 (UTC) Received: from pxdev.xzpeter.org.com (vpn1-5-116.pek2.redhat.com [10.72.5.116]) by smtp.corp.redhat.com (Postfix) with ESMTP id BC7985C888; Mon, 15 May 2017 08:51:13 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com F0A00C0467CB Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=peterx@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com F0A00C0467CB From: Peter Xu To: qemu-devel@nongnu.org Date: Mon, 15 May 2017 16:50:58 +0800 Message-Id: <1494838260-30439-3-git-send-email-peterx@redhat.com> In-Reply-To: <1494838260-30439-1-git-send-email-peterx@redhat.com> References: <1494838260-30439-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.31]); Mon, 15 May 2017 08:51:17 +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 2/4] exec: rename resolve_subpage 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 , "Michael S . Tsirkin" , peterx@redhat.com, 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" It is not easy for people to know "what this parameter does" before knowing "what is subpage". Let's use "is_mmio" to make it easier to understand. Signed-off-by: Peter Xu Tested-by: Maxime Coquelin --- exec.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/exec.c b/exec.c index 1d76c63..0adae94 100644 --- a/exec.c +++ b/exec.c @@ -403,7 +403,7 @@ bool memory_region_is_unassigned(MemoryRegion *mr) /* Called from RCU critical section */ static MemoryRegionSection *address_space_lookup_region(AddressSpaceDispat= ch *d, hwaddr addr, - bool resolve_subpa= ge) + bool is_mmio) { MemoryRegionSection *section =3D atomic_read(&d->mru_section); subpage_t *subpage; @@ -416,7 +416,7 @@ static MemoryRegionSection *address_space_lookup_region= (AddressSpaceDispatch *d, section =3D phys_page_find(d, addr); update =3D true; } - if (resolve_subpage && section->mr->subpage) { + if (is_mmio && section->mr->subpage) { subpage =3D container_of(section->mr, subpage_t, iomem); section =3D &d->map.sections[subpage->sub_section[SUBPAGE_IDX(addr= )]]; } @@ -429,13 +429,13 @@ static MemoryRegionSection *address_space_lookup_regi= on(AddressSpaceDispatch *d, /* Called from RCU critical section */ static MemoryRegionSection * address_space_translate_internal(AddressSpaceDispatch *d, hwaddr addr, hwa= ddr *xlat, - hwaddr *plen, bool resolve_subpage) + hwaddr *plen, bool is_mmio) { MemoryRegionSection *section; MemoryRegion *mr; Int128 diff; =20 - section =3D address_space_lookup_region(d, addr, resolve_subpage); + section =3D address_space_lookup_region(d, addr, is_mmio); /* Compute offset within MemoryRegionSection */ addr -=3D section->offset_within_address_space; =20 --=20 2.7.4 From nobody Sun Apr 28 00:20:07 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.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 1494838446688321.2553841087339; Mon, 15 May 2017 01:54:06 -0700 (PDT) Received: from localhost ([::1]:35462 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dABlU-0005qk-K9 for importer@patchew.org; Mon, 15 May 2017 04:54:04 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34184) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dABis-0003rR-Hp for qemu-devel@nongnu.org; Mon, 15 May 2017 04:51:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dABir-0005aa-RH for qemu-devel@nongnu.org; Mon, 15 May 2017 04:51:22 -0400 Received: from mx1.redhat.com ([209.132.183.28]:60418) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dABir-0005aW-Lj for qemu-devel@nongnu.org; Mon, 15 May 2017 04:51:21 -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 A7F4B51443; Mon, 15 May 2017 08:51:20 +0000 (UTC) Received: from pxdev.xzpeter.org.com (vpn1-5-116.pek2.redhat.com [10.72.5.116]) by smtp.corp.redhat.com (Postfix) with ESMTP id 882765C3FD; Mon, 15 May 2017 08:51:17 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com A7F4B51443 Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=peterx@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com A7F4B51443 From: Peter Xu To: qemu-devel@nongnu.org Date: Mon, 15 May 2017 16:50:59 +0800 Message-Id: <1494838260-30439-4-git-send-email-peterx@redhat.com> In-Reply-To: <1494838260-30439-1-git-send-email-peterx@redhat.com> References: <1494838260-30439-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.39]); Mon, 15 May 2017 08:51:20 +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 3/4] exec: further use is_mmio 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 , "Michael S . Tsirkin" , peterx@redhat.com, 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 is MMIO-specific tunes on the size. Let's skip it for non-MMIO translations. Signed-off-by: Peter Xu Tested-by: Maxime Coquelin --- exec.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exec.c b/exec.c index 0adae94..32e5394 100644 --- a/exec.c +++ b/exec.c @@ -455,7 +455,7 @@ address_space_translate_internal(AddressSpaceDispatch *= d, hwaddr addr, hwaddr *x * everything works fine. If the incoming length is large, however, * the caller really has to do the clamping through memory_access_size. */ - if (memory_region_is_ram(mr)) { + if (is_mmio && memory_region_is_ram(mr)) { diff =3D int128_sub(section->size, int128_make64(addr)); *plen =3D int128_get64(int128_min(diff, int128_make64(*plen))); } --=20 2.7.4 From nobody Sun Apr 28 00:20:07 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.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 149483851865260.05812831180049; Mon, 15 May 2017 01:55:18 -0700 (PDT) Received: from localhost ([::1]:35471 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dABmf-0006cv-Cj for importer@patchew.org; Mon, 15 May 2017 04:55:17 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34204) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dABj4-0003zo-Bt for qemu-devel@nongnu.org; Mon, 15 May 2017 04:51:35 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dABiz-0005eU-Dp for qemu-devel@nongnu.org; Mon, 15 May 2017 04:51:34 -0400 Received: from mx1.redhat.com ([209.132.183.28]:37472) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dABiz-0005dd-5c for qemu-devel@nongnu.org; Mon, 15 May 2017 04:51:29 -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 2D4C680C0D; Mon, 15 May 2017 08:51:28 +0000 (UTC) Received: from pxdev.xzpeter.org.com (vpn1-5-116.pek2.redhat.com [10.72.5.116]) by smtp.corp.redhat.com (Postfix) with ESMTP id 342DD5C3FD; Mon, 15 May 2017 08:51:20 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 2D4C680C0D 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=pass smtp.mailfrom=peterx@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 2D4C680C0D From: Peter Xu To: qemu-devel@nongnu.org Date: Mon, 15 May 2017 16:51:00 +0800 Message-Id: <1494838260-30439-5-git-send-email-peterx@redhat.com> In-Reply-To: <1494838260-30439-1-git-send-email-peterx@redhat.com> References: <1494838260-30439-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.26]); Mon, 15 May 2017 08:51:28 +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 4/4] exec: abstract address_space_do_translate() 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 , "Michael S . Tsirkin" , peterx@redhat.com, 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 is an abstraction helper for address_space_translate() and address_space_get_iotlb_entry(). It does the lookup of address into memory region section, then do proper IOMMU translation if necessary. With that, refactor the two existing functions a bit to use it. Signed-off-by: Peter Xu Tested-by: Maxime Coquelin --- exec.c | 99 +++++++++++++++++++++++++++++++++++++++++++-------------------= ---- 1 file changed, 65 insertions(+), 34 deletions(-) diff --git a/exec.c b/exec.c index 32e5394..efc80a8 100644 --- a/exec.c +++ b/exec.c @@ -463,18 +463,20 @@ 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, - bool is_write) +static MemoryRegionSection address_space_do_translate(AddressSpace *as, + hwaddr addr, + hwaddr *xlat, + hwaddr *plen, + bool is_write, + bool is_mmio) { - IOMMUTLBEntry iotlb =3D {0}; + IOMMUTLBEntry iotlb; MemoryRegionSection *section; MemoryRegion *mr; =20 for (;;) { AddressSpaceDispatch *d =3D atomic_rcu_read(&as->dispatch); - section =3D address_space_lookup_region(d, addr, false); - addr =3D addr - section->offset_within_address_space - + section->offset_within_region; + section =3D address_space_translate_internal(d, addr, &addr, plen,= is_mmio); mr =3D section->mr; =20 if (!mr->iommu_ops) { @@ -482,55 +484,84 @@ IOMMUTLBEntry address_space_get_iotlb_entry(AddressSp= ace *as, hwaddr addr, } =20 iotlb =3D mr->iommu_ops->translate(mr, addr, is_write); + addr =3D ((iotlb.translated_addr & ~iotlb.addr_mask) + | (addr & iotlb.addr_mask)); + *plen =3D MIN(*plen, (addr | iotlb.addr_mask) - addr + 1); if (!(iotlb.perm & (1 << is_write))) { - iotlb.target_as =3D NULL; - break; + goto translate_fail; } =20 - addr =3D ((iotlb.translated_addr & ~iotlb.addr_mask) - | (addr & iotlb.addr_mask)); as =3D iotlb.target_as; } =20 - return iotlb; + *xlat =3D addr; + + return *section; + +translate_fail: + return (MemoryRegionSection) { .mr =3D &io_mem_unassigned }; } =20 /* Called from RCU critical section */ -MemoryRegion *address_space_translate(AddressSpace *as, hwaddr addr, - hwaddr *xlat, hwaddr *plen, - bool is_write) +IOMMUTLBEntry address_space_get_iotlb_entry(AddressSpace *as, hwaddr addr, + bool is_write) { - IOMMUTLBEntry iotlb; - MemoryRegionSection *section; - MemoryRegion *mr; + MemoryRegionSection section; + hwaddr xlat, plen; =20 - for (;;) { - AddressSpaceDispatch *d =3D atomic_rcu_read(&as->dispatch); - section =3D address_space_translate_internal(d, addr, &addr, plen,= true); - mr =3D section->mr; + /* Try to get maximum page mask during translation. */ + plen =3D (hwaddr)-1; =20 - if (!mr->iommu_ops) { - break; - } + /* This can never be MMIO. */ + section =3D address_space_do_translate(as, addr, &xlat, &plen, + is_write, false); =20 - iotlb =3D mr->iommu_ops->translate(mr, addr, is_write); - addr =3D ((iotlb.translated_addr & ~iotlb.addr_mask) - | (addr & iotlb.addr_mask)); - *plen =3D MIN(*plen, (addr | iotlb.addr_mask) - addr + 1); - if (!(iotlb.perm & (1 << is_write))) { - mr =3D &io_mem_unassigned; - break; - } + /* Illegal translation */ + if (section.mr =3D=3D &io_mem_unassigned) { + goto iotlb_fail; + } =20 - as =3D iotlb.target_as; + if (plen =3D=3D (hwaddr)-1) { + /* + * We use default page size here. Logically it only happens + * for identity mappings. + */ + plen =3D TARGET_PAGE_SIZE; } =20 + /* Convert to address mask */ + plen -=3D 1; + + return (IOMMUTLBEntry) { + .target_as =3D section.address_space, + .iova =3D addr & ~plen, + .translated_addr =3D xlat & ~plen, + .addr_mask =3D plen, + /* IOTLBs are for DMAs, and DMA only allows on RAMs. */ + .perm =3D IOMMU_RW, + }; + +iotlb_fail: + return (IOMMUTLBEntry) {0}; +} + +/* Called from RCU critical section */ +MemoryRegion *address_space_translate(AddressSpace *as, hwaddr addr, + hwaddr *xlat, hwaddr *plen, + bool is_write) +{ + MemoryRegion *mr; + MemoryRegionSection section; + + /* This can be MMIO, so setup MMIO bit. */ + section =3D address_space_do_translate(as, addr, xlat, plen, is_write,= true); + mr =3D section.mr; + if (xen_enabled() && memory_access_is_direct(mr, is_write)) { hwaddr page =3D ((addr & TARGET_PAGE_MASK) + TARGET_PAGE_SIZE) - a= ddr; *plen =3D MIN(page, *plen); } =20 - *xlat =3D addr; return mr; } =20 --=20 2.7.4