From nobody Mon Feb 9 23:01:05 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.zohomail.com; dkim=fail; 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 15293762951121001.5081696074682; Mon, 18 Jun 2018 19:44:55 -0700 (PDT) Received: from localhost ([::1]:38730 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fV6dX-0005bD-8E for importer@patchew.org; Mon, 18 Jun 2018 22:44:51 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47467) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fV5kA-0003Xc-6e for qemu-devel@nongnu.org; Mon, 18 Jun 2018 21:47:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fV5k6-00017e-0q for qemu-devel@nongnu.org; Mon, 18 Jun 2018 21:47:38 -0400 Received: from mail-ot0-x235.google.com ([2607:f8b0:4003:c0f::235]:43694) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fV5k5-00017X-R8; Mon, 18 Jun 2018 21:47:33 -0400 Received: by mail-ot0-x235.google.com with SMTP id i19-v6so20746778otk.10; Mon, 18 Jun 2018 18:47:33 -0700 (PDT) Received: from localhost (76-251-165-188.lightspeed.austtx.sbcglobal.net. [76.251.165.188]) by smtp.gmail.com with ESMTPSA id f53-v6sm11185801otd.80.2018.06.18.18.47.31 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 18 Jun 2018 18:47:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=sp9Sqki9GKa8t8Wt70Tlcg1DoFD1V2Zut69xGlLPTJA=; b=bWDVsFB6v2c5+z97094FyK/BktJRVE20NP+UFPWrqlJhukhPUgdHswwdN6dBeQhiz7 x0djwtwj5VeeA+tUpbQuvrG9bv9tOOnTmfhGMfMH9QXQuPKvQEk6gjy5GlYuc0LSrb1b smlLujtz81ToxGfXYO99bBghGncKMcJxZM0vYFBZZJ/0brOfX4IuFZwTNE5s5YKA+ztE SQdQ2zKOnaZxkDc0wUhfh0UgeqlppcwcoQQDacZy2UQFYa+cTTLvYbnm+pwOFCgJNV8P PKRtNnqhry2u0scyJRrQtuOPzjpT7V3qewnn3cvY1UbJQk6PEu3rpgj8ts3bUG0jhO1h bIBw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=sp9Sqki9GKa8t8Wt70Tlcg1DoFD1V2Zut69xGlLPTJA=; b=BwRx5kEfcmaLxHeRv2R/VhBOa3V9NvOwEoY6D3+OPA+XWIdt37iSSZws52PxXmjGo1 jU+Ib201Dw24CDniZzG5vfAvewQvk5SLAr8nIeh0KkAulIrl1gVcbUKUgTWK1yxZ5ef8 oi6PjZcZ2VjrejO9Xtx6YY9rmlyhSUpKyMQzCuvkbCSuOGhdsUscStzTbjKnDffWZcRj uhzn22ZGneq5IN2KJd/bWJrnm+dGpEhMnLo1FemOZ1p/25BRsktFsyL8BJK5vVmoAPp3 13naNP9xn6O5glwrJVYlH5AD1cPqEl221iq4aolsQksST5ebC2xo8NjI6BGG3rLZ84zx P82w== X-Gm-Message-State: APt69E1NIwmOrF9IJdnPiJapI0HiC9updelj58n1EL7awFfjoIX9n6VW dhrECHci57dK1imYRXIATC4LHZzvIGk= X-Google-Smtp-Source: ADUXVKLspbWrt1X/rBaYF88EoCfDGBtEfiLpqRKlSGW+n6gfhe4UZECppTixLvk14RrV0pd7PRRBLg== X-Received: by 2002:a9d:5616:: with SMTP id e22-v6mr10019881oti.192.1529372852615; Mon, 18 Jun 2018 18:47:32 -0700 (PDT) From: Michael Roth To: qemu-devel@nongnu.org Date: Mon, 18 Jun 2018 20:42:57 -0500 Message-Id: <20180619014319.28272-92-mdroth@linux.vnet.ibm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180619014319.28272-1-mdroth@linux.vnet.ibm.com> References: <20180619014319.28272-1-mdroth@linux.vnet.ibm.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4003:c0f::235 Subject: [Qemu-devel] [PATCH 091/113] intel-iommu: only do page walk for MAP notifiers 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: qemu-stable@nongnu.org, Peter Xu , "Michael S . Tsirkin" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Peter Xu For UNMAP-only IOMMU notifiers, we don't need to walk the page tables. Fasten that procedure by skipping the page table walk. That should boost performance for UNMAP-only notifiers like vhost. CC: QEMU Stable Signed-off-by: Peter Xu Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin (cherry picked from commit 4f8a62a933a79094e44bc1b16b63bb23e62d67b4) Signed-off-by: Michael Roth --- hw/i386/intel_iommu.c | 44 ++++++++++++++++++++++++++++++++++++++-= ---- include/hw/i386/intel_iommu.h | 2 ++ 2 files changed, 41 insertions(+), 5 deletions(-) diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c index cfcd1046e7..3715fa327b 100644 --- a/hw/i386/intel_iommu.c +++ b/hw/i386/intel_iommu.c @@ -138,6 +138,12 @@ static inline void vtd_iommu_unlock(IntelIOMMUState *s) qemu_mutex_unlock(&s->iommu_lock); } =20 +/* Whether the address space needs to notify new mappings */ +static inline gboolean vtd_as_has_map_notifier(VTDAddressSpace *as) +{ + return as->notifier_flags & IOMMU_NOTIFIER_MAP; +} + /* GHashTable functions */ static gboolean vtd_uint64_equal(gconstpointer v1, gconstpointer v2) { @@ -1436,14 +1442,36 @@ static void vtd_iotlb_page_invalidate_notify(IntelI= OMMUState *s, VTDAddressSpace *vtd_as; VTDContextEntry ce; int ret; + hwaddr size =3D (1 << am) * VTD_PAGE_SIZE; =20 QLIST_FOREACH(vtd_as, &(s->vtd_as_with_notifiers), next) { ret =3D vtd_dev_to_context_entry(s, pci_bus_num(vtd_as->bus), vtd_as->devfn, &ce); if (!ret && domain_id =3D=3D VTD_CONTEXT_ENTRY_DID(ce.hi)) { - vtd_page_walk(&ce, addr, addr + (1 << am) * VTD_PAGE_SIZE, - vtd_page_invalidate_notify_hook, - (void *)&vtd_as->iommu, true, s->aw_bits); + if (vtd_as_has_map_notifier(vtd_as)) { + /* + * As long as we have MAP notifications registered in + * any of our IOMMU notifiers, we need to sync the + * shadow page table. + */ + vtd_page_walk(&ce, addr, addr + size, + vtd_page_invalidate_notify_hook, + (void *)&vtd_as->iommu, true, s->aw_bits); + } else { + /* + * For UNMAP-only notifiers, we don't need to walk the + * page tables. We just deliver the PSI down to + * invalidate caches. + */ + IOMMUTLBEntry entry =3D { + .target_as =3D &address_space_memory, + .iova =3D addr, + .translated_addr =3D 0, + .addr_mask =3D size - 1, + .perm =3D IOMMU_NONE, + }; + memory_region_notify_iommu(&vtd_as->iommu, entry); + } } } } @@ -2376,6 +2404,9 @@ static void vtd_iommu_notify_flag_changed(IOMMUMemory= Region *iommu, exit(1); } =20 + /* Update per-address-space notifier flags */ + vtd_as->notifier_flags =3D new; + if (old =3D=3D IOMMU_NOTIFIER_NONE) { QLIST_INSERT_HEAD(&s->vtd_as_with_notifiers, vtd_as, next); } else if (new =3D=3D IOMMU_NOTIFIER_NONE) { @@ -2884,8 +2915,11 @@ static void vtd_iommu_replay(IOMMUMemoryRegion *iomm= u_mr, IOMMUNotifier *n) PCI_FUNC(vtd_as->devfn), VTD_CONTEXT_ENTRY_DID(ce.hi), ce.hi, ce.lo); - vtd_page_walk(&ce, 0, ~0ULL, vtd_replay_hook, (void *)n, false, - s->aw_bits); + if (vtd_as_has_map_notifier(vtd_as)) { + /* This is required only for MAP typed notifiers */ + vtd_page_walk(&ce, 0, ~0ULL, vtd_replay_hook, (void *)n, false, + s->aw_bits); + } } else { trace_vtd_replay_ce_invalid(bus_n, PCI_SLOT(vtd_as->devfn), PCI_FUNC(vtd_as->devfn)); diff --git a/include/hw/i386/intel_iommu.h b/include/hw/i386/intel_iommu.h index 016e74bedb..156f35e919 100644 --- a/include/hw/i386/intel_iommu.h +++ b/include/hw/i386/intel_iommu.h @@ -93,6 +93,8 @@ struct VTDAddressSpace { IntelIOMMUState *iommu_state; VTDContextCacheEntry context_cache_entry; QLIST_ENTRY(VTDAddressSpace) next; + /* Superset of notifier flags that this address space has */ + IOMMUNotifierFlag notifier_flags; }; =20 struct VTDBus { --=20 2.11.0