From nobody Thu Oct 30 05:22:44 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 (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1525403888935597.3054129425237; Thu, 3 May 2018 20:18:08 -0700 (PDT) Received: from localhost ([::1]:60211 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fEREW-0000N9-77 for importer@patchew.org; Thu, 03 May 2018 23:18:08 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33542) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fER6C-0002ID-SO for qemu-devel@nongnu.org; Thu, 03 May 2018 23:09:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fER68-00061f-LV for qemu-devel@nongnu.org; Thu, 03 May 2018 23:09:32 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:39294 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 1fER68-00061R-FH for qemu-devel@nongnu.org; Thu, 03 May 2018 23:09:28 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 201FB818592A; Fri, 4 May 2018 03:09:28 +0000 (UTC) Received: from xz-mi.redhat.com (ovpn-12-46.pek2.redhat.com [10.72.12.46]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1179F11166E0; Fri, 4 May 2018 03:09:17 +0000 (UTC) From: Peter Xu To: qemu-devel@nongnu.org Date: Fri, 4 May 2018 11:08:11 +0800 Message-Id: <20180504030811.28111-11-peterx@redhat.com> In-Reply-To: <20180504030811.28111-1-peterx@redhat.com> References: <20180504030811.28111-1-peterx@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Fri, 04 May 2018 03:09:28 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Fri, 04 May 2018 03:09:28 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.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] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH v2 10/10] intel-iommu: remove notify_unmap for page walk 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: Tian Kevin , "Michael S . Tsirkin" , Jason Wang , peterx@redhat.com, Alex Williamson , Jintack Lim 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" Now after previous changes, we will always pass that parameter as true now. Remove it. After removing that variable, now we can greatly simplify the page walking logic. No functional change at all. Signed-off-by: Peter Xu --- hw/i386/intel_iommu.c | 70 +++++++++++++++++-------------------------- hw/i386/trace-events | 1 - 2 files changed, 28 insertions(+), 43 deletions(-) diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c index 9439103cac..c156235135 100644 --- a/hw/i386/intel_iommu.c +++ b/hw/i386/intel_iommu.c @@ -759,7 +759,6 @@ typedef struct { VTDAddressSpace *as; vtd_page_walk_hook hook_fn; void *private; - bool notify_unmap; } vtd_page_walk_info; =20 static int vtd_page_walk_one(IOMMUTLBEntry *entry, int level, @@ -900,45 +899,34 @@ static int vtd_page_walk_level(dma_addr_t addr, uint6= 4_t start, */ entry_valid =3D read_cur | write_cur; =20 - entry.target_as =3D &address_space_memory; - entry.iova =3D iova & subpage_mask; - entry.perm =3D IOMMU_ACCESS_FLAG(read_cur, write_cur); - entry.addr_mask =3D ~subpage_mask; - - if (vtd_is_last_slpte(slpte, level)) { - /* NOTE: this is only meaningful if entry_valid =3D=3D true */ - entry.translated_addr =3D vtd_get_slpte_addr(slpte, aw); - if (!entry_valid && !info->notify_unmap) { - trace_vtd_page_walk_skip_perm(iova, iova_next); - goto next; - } - ret =3D vtd_page_walk_one(&entry, level, info); - if (ret < 0) { - return ret; - } - } else { - if (!entry_valid) { - if (info->notify_unmap) { - /* - * The whole entry is invalid; unmap it all. - * Translated address is meaningless, zero it. - */ - entry.translated_addr =3D 0x0; - ret =3D vtd_page_walk_one(&entry, level, info); - if (ret < 0) { - return ret; - } - } else { - trace_vtd_page_walk_skip_perm(iova, iova_next); - } - goto next; - } + if (!vtd_is_last_slpte(slpte, level) && entry_valid) { + /* + * This is a valid PDE (or even bigger than PDE). We need + * to walk one further level. + */ ret =3D vtd_page_walk_level(vtd_get_slpte_addr(slpte, aw), iova, MIN(iova_next, end), level - 1, read_cur, write_cur, info); - if (ret < 0) { - return ret; - } + } else { + /* + * This means we are either: + * + * (1) the real page entry (either 4K page, or huge page) + * (2) the whole range is invalid + * + * In either case, we send an IOTLB notification down. + */ + entry.target_as =3D &address_space_memory; + entry.iova =3D iova & subpage_mask; + entry.perm =3D IOMMU_ACCESS_FLAG(read_cur, write_cur); + entry.addr_mask =3D ~subpage_mask; + /* NOTE: this is only meaningful if entry_valid =3D=3D true */ + entry.translated_addr =3D vtd_get_slpte_addr(slpte, aw); + ret =3D vtd_page_walk_one(&entry, level, info); + } + + if (ret < 0) { + return ret; } =20 next: @@ -960,7 +948,7 @@ next: */ static int vtd_page_walk(VTDContextEntry *ce, uint64_t start, uint64_t end, vtd_page_walk_hook hook_fn, void *private, - bool notify_unmap, VTDAddressSpace *as) + VTDAddressSpace *as) { dma_addr_t addr =3D vtd_ce_get_slpt_base(ce); uint32_t level =3D vtd_ce_get_level(ce); @@ -968,7 +956,6 @@ static int vtd_page_walk(VTDContextEntry *ce, uint64_t = start, uint64_t end, vtd_page_walk_info info =3D { .hook_fn =3D hook_fn, .private =3D private, - .notify_unmap =3D notify_unmap, .as =3D as, }; =20 @@ -1542,7 +1529,7 @@ static void vtd_iotlb_page_invalidate_notify(IntelIOM= MUState *s, */ vtd_page_walk(&ce, addr, addr + size, vtd_page_invalidate_notify_hook, - (void *)&vtd_as->iommu, true, vtd_as); + (void *)&vtd_as->iommu, vtd_as); } else { /* * For UNMAP-only notifiers, we don't need to walk the @@ -3013,8 +3000,7 @@ static void vtd_iommu_replay(IOMMUMemoryRegion *iommu= _mr, IOMMUNotifier *n) ce.hi, ce.lo); if (vtd_as_notify_mappings(vtd_as)) { /* This is required only for MAP typed notifiers */ - vtd_page_walk(&ce, 0, ~0ULL, vtd_replay_hook, (void *)n, true, - vtd_as); + vtd_page_walk(&ce, 0, ~0ULL, vtd_replay_hook, (void *)n, vtd_a= s); } else { vtd_address_space_unmap(vtd_as, n); } diff --git a/hw/i386/trace-events b/hw/i386/trace-events index 677f83420d..eb23ace5fb 100644 --- a/hw/i386/trace-events +++ b/hw/i386/trace-events @@ -43,7 +43,6 @@ vtd_page_walk_one(uint32_t level, uint64_t iova, uint64_t= gpa, uint64_t mask, in vtd_page_walk_one_skip_map(uint64_t iova, uint64_t mask, uint64_t start, u= int64_t end) "iova 0x%"PRIx64" mask 0x%"PRIx64" start 0x%"PRIx64" end 0x%"P= RIx64 vtd_page_walk_one_skip_unmap(uint64_t iova, uint64_t mask) "iova 0x%"PRIx6= 4" mask 0x%"PRIx64 vtd_page_walk_skip_read(uint64_t iova, uint64_t next) "Page walk skip iova= 0x%"PRIx64" - 0x%"PRIx64" due to unable to read" -vtd_page_walk_skip_perm(uint64_t iova, uint64_t next) "Page walk skip iova= 0x%"PRIx64" - 0x%"PRIx64" due to perm empty" vtd_page_walk_skip_reserve(uint64_t iova, uint64_t next) "Page walk skip i= ova 0x%"PRIx64" - 0x%"PRIx64" due to rsrv set" vtd_switch_address_space(uint8_t bus, uint8_t slot, uint8_t fn, bool on) "= Device %02x:%02x.%x switching address space (iommu enabled=3D%d)" vtd_as_unmap_whole(uint8_t bus, uint8_t slot, uint8_t fn, uint64_t iova, u= int64_t size) "Device %02x:%02x.%x start 0x%"PRIx64" size 0x%"PRIx64 --=20 2.17.0