From nobody Thu Nov 6 06:39:19 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 1539071300767577.862667321915; Tue, 9 Oct 2018 00:48:20 -0700 (PDT) Received: from localhost ([::1]:50062 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g9mkd-0001pt-PA for importer@patchew.org; Tue, 09 Oct 2018 03:48:19 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52720) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g9mj4-000130-M8 for qemu-devel@nongnu.org; Tue, 09 Oct 2018 03:46:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g9miz-0000Og-La for qemu-devel@nongnu.org; Tue, 09 Oct 2018 03:46:42 -0400 Received: from mx1.redhat.com ([209.132.183.28]:19946) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1g9miy-0000JZ-AY for qemu-devel@nongnu.org; Tue, 09 Oct 2018 03:46:37 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id DE100C05D3E5 for ; Tue, 9 Oct 2018 07:46:31 +0000 (UTC) Received: from xz-x1.nay.redhat.com (dhcp-14-128.nay.redhat.com [10.66.14.128]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9041B194B7; Tue, 9 Oct 2018 07:46:13 +0000 (UTC) From: Peter Xu To: qemu-devel@nongnu.org Date: Tue, 9 Oct 2018 15:45:42 +0800 Message-Id: <20181009074543.6013-2-peterx@redhat.com> In-Reply-To: <20181009074543.6013-1-peterx@redhat.com> References: <20181009074543.6013-1-peterx@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Tue, 09 Oct 2018 07:46:31 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v3 1/2] intel_iommu: move ce fetching out when sync shadow 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: "Michael S . Tsirkin" , Jason Wang , Alex Williamson , peterx@redhat.com, Eric Auger , Maxime Coquelin , Pei Zhang Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RDMRC_1 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" There are two callers for vtd_sync_shadow_page_table_range(): one provided a valid context entry and one not. Move that fetching operation into the caller vtd_sync_shadow_page_table() where we need to fetch the context entry. Meanwhile, remove the error_report_once() directly since we're already tracing all the error cases in the previous call. Instead, return error number back to caller. This will not change anything functional since callers are dropping it after all. We do this move majorly because we want to do something more later in vtd_sync_shadow_page_table(). Reviewed-by: Eric Auger Signed-off-by: Peter Xu --- dtc | 2 +- hw/i386/intel_iommu.c | 41 +++++++++++++---------------------------- 2 files changed, 14 insertions(+), 29 deletions(-) diff --git a/dtc b/dtc index 88f18909db..e54388015a 160000 --- a/dtc +++ b/dtc @@ -1 +1 @@ -Subproject commit 88f18909db731a627456f26d779445f84e449536 +Subproject commit e54388015af1fb4bf04d0bca99caba1074d9cc42 diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c index 3dfada19a6..d6b4f8705d 100644 --- a/hw/i386/intel_iommu.c +++ b/hw/i386/intel_iommu.c @@ -1035,7 +1035,6 @@ static int vtd_sync_shadow_page_hook(IOMMUTLBEntry *e= ntry, return 0; } =20 -/* If context entry is NULL, we'll try to fetch it on our own. */ static int vtd_sync_shadow_page_table_range(VTDAddressSpace *vtd_as, VTDContextEntry *ce, hwaddr addr, hwaddr size) @@ -1047,39 +1046,25 @@ static int vtd_sync_shadow_page_table_range(VTDAddr= essSpace *vtd_as, .notify_unmap =3D true, .aw =3D s->aw_bits, .as =3D vtd_as, + .domain_id =3D VTD_CONTEXT_ENTRY_DID(ce->hi), }; - VTDContextEntry ce_cache; - int ret; - - if (ce) { - /* If the caller provided context entry, use it */ - ce_cache =3D *ce; - } else { - /* If the caller didn't provide ce, try to fetch */ - ret =3D vtd_dev_to_context_entry(s, pci_bus_num(vtd_as->bus), - vtd_as->devfn, &ce_cache); - if (ret) { - /* - * This should not really happen, but in case it happens, - * we just skip the sync for this time. After all we even - * don't have the root table pointer! - */ - error_report_once("%s: invalid context entry for bus 0x%x" - " devfn 0x%x", - __func__, pci_bus_num(vtd_as->bus), - vtd_as->devfn); - return 0; - } - } =20 - info.domain_id =3D VTD_CONTEXT_ENTRY_DID(ce_cache.hi); - - return vtd_page_walk(&ce_cache, addr, addr + size, &info); + return vtd_page_walk(ce, addr, addr + size, &info); } =20 static int vtd_sync_shadow_page_table(VTDAddressSpace *vtd_as) { - return vtd_sync_shadow_page_table_range(vtd_as, NULL, 0, UINT64_MAX); + int ret; + VTDContextEntry ce; + + ret =3D vtd_dev_to_context_entry(vtd_as->iommu_state, + pci_bus_num(vtd_as->bus), + vtd_as->devfn, &ce); + if (ret) { + return ret; + } + + return vtd_sync_shadow_page_table_range(vtd_as, &ce, 0, UINT64_MAX); } =20 /* --=20 2.17.1