From nobody Fri May 17 07:47:27 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1676346215; cv=none; d=zohomail.com; s=zohoarc; b=M41hn4bCPkHvcXQU4QDgCmukGMhIbrBrflwt2PNhpi4TQpU76svs2uznvOpri+ouO7mz1fU7pQpSGEdT70GB4jJlEjTUDobk9FYTZtpIP2AU+CjaOdQOyzlV8KJ601Lucxz6nwynwDDy962LZo9zkj7RGaNtz2dQm9QGhyRgKCI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1676346215; h=Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=zhONfp+aTl/wo3UZh2XTFBpaWFXbSFgiJrK2ql0OBHY=; b=Of0evZhrpBmFDdP1UuZo9v+7R0Nv+EW8tXi/kHRnEiwJaXkN/GzFTd1lwqwPSG8efEOxC5eK2Q9A9oVafILAkz3tnoTKoc8rcro6ykILgZkmXBNREoGvEsrKV2Y4ULc6BdMvkK0GmVyWf9FPmB+d8O05gobsFX4djrExy5+0J/Q= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1676346215075565.1444880137581; Mon, 13 Feb 2023 19:43:35 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pRmDZ-0005an-Pf; Mon, 13 Feb 2023 22:42:57 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pRmDX-0005aP-Gw for qemu-devel@nongnu.org; Mon, 13 Feb 2023 22:42:55 -0500 Received: from mga05.intel.com ([192.55.52.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pRmDV-00032N-Sv for qemu-devel@nongnu.org; Mon, 13 Feb 2023 22:42:55 -0500 Received: from orsmga007.jf.intel.com ([10.7.209.58]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Feb 2023 19:42:50 -0800 Received: from duan-server-s2600bt.bj.intel.com ([10.240.192.143]) by orsmga007-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Feb 2023 19:42:47 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1676346173; x=1707882173; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=ZOf2JFSITzrDcOXcY+ZJK4LaY48M4IaCLmb/ZuvYsnQ=; b=T7o0DqAQ9tSLUBveMQxS+POzYzdzLLWUKPcNgUcjspIUjyjO1KmT6snP RLIw4umD3qqalCjkEQLbo+H6maa74K/7oFsI/9PUKVT5pGPMF0rar790t OKAom2wUW7j80oZlN3ihiOp4muRXYMNpX2tU84O8GQVppbZaqnQ04APP2 lbRHw6YLyPos3A6ALOysCNHjefPj1YXdz002kUSLnov+05M/UJ5jPH5VQ Ar21XsLQA6YdhX/sc1GLbaWgR0fCnWDPomnfS/tosxveJYopGSTr0JMfg jSpchzOXYla8+zIHr18Pd1SSVSI9XUY0f6vrRNB9I57aTnnetq0Chkc8J g==; X-IronPort-AV: E=McAfee;i="6500,9779,10620"; a="417284863" X-IronPort-AV: E=Sophos;i="5.97,294,1669104000"; d="scan'208";a="417284863" X-IronPort-AV: E=McAfee;i="6500,9779,10620"; a="662410558" X-IronPort-AV: E=Sophos;i="5.97,294,1669104000"; d="scan'208";a="662410558" From: Zhenzhong Duan To: qemu-devel@nongnu.org Cc: mst@redhat.com, peterx@redhat.com, jasowang@redhat.com, pbonzini@redhat.com, richard.henderson@linaro.org, eduardo@habkost.net, marcel.apfelbaum@gmail.com, david@redhat.com, philmd@linaro.org Subject: [PATCH] memory: Optimize replay of guest mapping Date: Tue, 14 Feb 2023 11:42:11 +0800 Message-Id: <20230214034211.683203-1-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=192.55.52.43; envelope-from=zhenzhong.duan@intel.com; helo=mga05.intel.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1676346215689100001 Content-Type: text/plain; charset="utf-8" On x86, there are two notifiers registered due to vtd-ir memory region splitting the whole address space. During replay of the address space for each notifier, the whole address space is scanned which is unnecessory. We only need to scan the space belong to notifier montiored space. Signed-off-by: Zhenzhong Duan --- Tested only on x86 with a net card passed to guest, ping/ssh pass. hw/i386/intel_iommu.c | 2 +- softmmu/memory.c | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c index 98a5c304a7d7..6b1de80e8573 100644 --- a/hw/i386/intel_iommu.c +++ b/hw/i386/intel_iommu.c @@ -3831,7 +3831,7 @@ static void vtd_iommu_replay(IOMMUMemoryRegion *iommu= _mr, IOMMUNotifier *n) .domain_id =3D vtd_get_domain_id(s, &ce, vtd_as->pasid), }; =20 - vtd_page_walk(s, &ce, 0, ~0ULL, &info, vtd_as->pasid); + vtd_page_walk(s, &ce, n->start, n->end, &info, vtd_as->pasid); } } else { trace_vtd_replay_ce_invalid(bus_n, PCI_SLOT(vtd_as->devfn), diff --git a/softmmu/memory.c b/softmmu/memory.c index 9d64efca269b..f096716e6e78 100644 --- a/softmmu/memory.c +++ b/softmmu/memory.c @@ -1923,7 +1923,6 @@ uint64_t memory_region_iommu_get_min_page_size(IOMMUM= emoryRegion *iommu_mr) =20 void memory_region_iommu_replay(IOMMUMemoryRegion *iommu_mr, IOMMUNotifier= *n) { - MemoryRegion *mr =3D MEMORY_REGION(iommu_mr); IOMMUMemoryRegionClass *imrc =3D IOMMU_MEMORY_REGION_GET_CLASS(iommu_m= r); hwaddr addr, granularity; IOMMUTLBEntry iotlb; @@ -1936,7 +1935,7 @@ void memory_region_iommu_replay(IOMMUMemoryRegion *io= mmu_mr, IOMMUNotifier *n) =20 granularity =3D memory_region_iommu_get_min_page_size(iommu_mr); =20 - for (addr =3D 0; addr < memory_region_size(mr); addr +=3D granularity)= { + for (addr =3D n->start; addr < n->end; addr +=3D granularity) { iotlb =3D imrc->translate(iommu_mr, addr, IOMMU_NONE, n->iommu_idx= ); if (iotlb.perm !=3D IOMMU_NONE) { n->notify(n, &iotlb); --=20 2.25.1