From nobody Sun Feb 8 12:38: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 1532378458978222.03879665014995; Mon, 23 Jul 2018 13:40:58 -0700 (PDT) Received: from localhost ([::1]:36453 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fhhdZ-0003u0-W2 for importer@patchew.org; Mon, 23 Jul 2018 16:40:58 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41154) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fhhIl-0001qu-SQ for qemu-devel@nongnu.org; Mon, 23 Jul 2018 16:19:28 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fhhIk-0003Cd-7M for qemu-devel@nongnu.org; Mon, 23 Jul 2018 16:19:27 -0400 Received: from mail-oi0-x231.google.com ([2607:f8b0:4003:c06::231]:42531) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fhhIk-0003CN-1V; Mon, 23 Jul 2018 16:19:26 -0400 Received: by mail-oi0-x231.google.com with SMTP id n84-v6so3462201oib.9; Mon, 23 Jul 2018 13:19:25 -0700 (PDT) Received: from localhost (76-251-165-188.lightspeed.austtx.sbcglobal.net. [76.251.165.188]) by smtp.gmail.com with ESMTPSA id y85-v6sm10623996oie.25.2018.07.23.13.19.23 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 23 Jul 2018 13:19:23 -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=GyQ1vIoBPmPJ8juY4kfmrKlZq3tVvoPLM+z7ItIsYqA=; b=FNnFu+zCcsVQXYF7KuVLwEFBh/p3B9OL4PIv74/fjdnN9lBIRwYY3TjO5iHP8xisK0 81SB+dCxVPszPhDXVGsXAW/tMv31dlHnBU/L+UnKKFd7A80MdD+ydBFnayTSZblEQq8a D+49y86C2BS7FDlBgHViKNxA2h2hQ9JjcCaSL6diTffdX9yzvhBtxvT1ChOxbwn0njFG 1q7htsO6jy5s5cut8lyYOyh49eps5Gg7cMyqyJEwgCsDJTeamnpYSAtRbncHXMmlam7B RE4iVBVQFtxRs7ynUfvWUfxPw882GE8Srbut+uqxkIDyMFqNQIwhKhpQSe/uSGl2UH/K PyMw== 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=GyQ1vIoBPmPJ8juY4kfmrKlZq3tVvoPLM+z7ItIsYqA=; b=rGROOiUYjdly4tBF6jAkJoPj/qStSnW7UPiGaCytjYoZ7cv5QXlVu8u9zuJcT+0Tew AtwTeLvplxkcGPjBT4tpgAp9hXBVdBxaUlKKTdD2xUNnn/hMoN5IHHQO6XFYzB4VxXzA WZDMnsRd1XmZxF0uh1m6CqPLbRd2C0jljKo8POZKw2G0PQc/m8hGaUNAekTgMnQOeydg MF+PAjcfJm9qbj5vO2UzGHY2AfJ4mH+LrF9gR2Yctu0vlwMmttDQ8Iwn8LeF2nmq9fPc 5TslKKgJabcKIdjGnHiZ7fI7TXgbfsUhEDeDZ/cTGT9PQXTiQGkZF1ULUFRu7i7H0TK2 IlUA== X-Gm-Message-State: AOUpUlHNCTTR+uVq0WZh//Zh1h+hvgbrKEkUT0yzQ5CX6qTSAlFeZMgl So/3e8UQVhMIez794hpXQisJEqq0ius= X-Google-Smtp-Source: AAOMgpemIH7vNUBt/qY1/j6/lh4WXoFmGml4m+Zbt6hP/5QTseIFUEt0nASTulFmXIkgC7k2L1uT1A== X-Received: by 2002:aca:cf43:: with SMTP id f64-v6mr307286oig.113.1532377164820; Mon, 23 Jul 2018 13:19:24 -0700 (PDT) From: Michael Roth To: qemu-devel@nongnu.org Date: Mon, 23 Jul 2018 15:16:37 -0500 Message-Id: <20180723201748.25573-29-mdroth@linux.vnet.ibm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180723201748.25573-1-mdroth@linux.vnet.ibm.com> References: <20180723201748.25573-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:c06::231 Subject: [Qemu-devel] [PATCH 28/99] 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 8d4069de9f..38ccc741f9 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); + } } } } @@ -2383,6 +2411,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) { @@ -2891,8 +2922,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.17.1