From nobody Tue Feb 10 03:36:51 2026 Delivered-To: importer@patchew.org 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; Authentication-Results: mx.zohomail.com; dkim=pass; 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=marvell.com ARC-Seal: i=1; a=rsa-sha256; t=1584953530; cv=none; d=zohomail.com; s=zohoarc; b=eKRNAMV4YmA2Ydz+YvBgz0gbZuMnfLJ19rPHiLUwBNEAoeon/8GSE4AcErUcdENX2S9bn0z+3kpWnENjsVyRYJqu1yaCx7MKpRyMwMc7HLvH3SCK+/uhAfQ2je3oE2h9lKndblg71ndVwKax7qpQ+XcZPn87ysuEqOj49dh/Fk8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1584953530; h=Content-Type:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Hl/XyCKAJ1EEPKyfPSElXYvi1a0lw4Ra95KpUJUtj48=; b=V/AwTGXwa6KxjE7qDIHd1jajJ1G+pxGeDwOcvwi4ryp0QXJvUk3uEewzCUxJeMesXZn+JLEZ/beNac/fwtBozUcnn62ZaRpRE07dMeA6xR7hgnVHO1+zRcQnN3F2ULUElem2YuH7vnwy2f3KqiEqaXT1XtRnApqZ87ZGX1C56k8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1584953530382610.3945352944155; Mon, 23 Mar 2020 01:52:10 -0700 (PDT) Received: from localhost ([::1]:58750 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jGIob-00076F-7i for importer@patchew.org; Mon, 23 Mar 2020 04:52:09 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48511) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jGIjp-0000BI-1n for qemu-devel@nongnu.org; Mon, 23 Mar 2020 04:47:14 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jGIjn-0003Gi-Ct for qemu-devel@nongnu.org; Mon, 23 Mar 2020 04:47:12 -0400 Received: from mx0a-0016f401.pphosted.com ([67.231.148.174]:51134 helo=mx0b-0016f401.pphosted.com) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jGIjn-0003FA-4J; Mon, 23 Mar 2020 04:47:11 -0400 Received: from pps.filterd (m0045849.ppops.net [127.0.0.1]) by mx0a-0016f401.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 02N8eAku010847; Mon, 23 Mar 2020 01:47:08 -0700 Received: from sc-exch01.marvell.com ([199.233.58.181]) by mx0a-0016f401.pphosted.com with ESMTP id 2ywg9ndrx5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Mon, 23 Mar 2020 01:47:08 -0700 Received: from SC-EXCH03.marvell.com (10.93.176.83) by SC-EXCH01.marvell.com (10.93.176.81) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Mon, 23 Mar 2020 01:47:06 -0700 Received: from bbhushan2.marvell.com (10.93.176.43) by SC-EXCH03.marvell.com (10.93.176.83) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Mon, 23 Mar 2020 01:47:02 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type; s=pfpt0818; bh=Hl/XyCKAJ1EEPKyfPSElXYvi1a0lw4Ra95KpUJUtj48=; b=fiuIkYT8TdNFxpSIVM3lmovpu+wPxAWI8lQFeyTohtExktEWTG11LH8mxsgIumzXpFgm CO9VSOaBSOden30k7WtSos8K0aCilpDPmC24pRiL5Pdi3NPY4AK048tpDWut2LPhD8rB zk3yiTHcoqaF25rWSJ6/VjCSX5liGsZvamyOsnGS/gCmDkL9pjWdmL9OYYxQ53w9lqqN sLcJfWS7+8je7Svh7ScDvZc6t29R4BzHa+XVi3o2WCqpzE8En69KY2TG4P641oTGVr7K X64TtjY2ZwEmOarz8Frutmtpkp9wN58QHPaGCrEZP9DhSCAnjs7HrmOeOPAjXYUKce84 og== From: Bharat Bhushan To: , , , , , , , , , , , , , Subject: [PATCH v9 7/9] virtio-iommu: add iommu replay Date: Mon, 23 Mar 2020 14:16:15 +0530 Message-ID: <20200323084617.1782-8-bbhushan2@marvell.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200323084617.1782-1-bbhushan2@marvell.com> References: <20200323084617.1782-1-bbhushan2@marvell.com> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.138, 18.0.645 definitions=2020-03-23_02:2020-03-21, 2020-03-23 signatures=0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] X-Received-From: 67.231.148.174 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Bharat Bhushan Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @marvell.com) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Default replay does not work with virtio-iommu, so this patch provide virtio-iommu replay functionality. Signed-off-by: Bharat Bhushan --- hw/virtio/virtio-iommu.c | 44 ++++++++++++++++++++++++++++++++++++++++ hw/virtio/trace-events | 1 + 2 files changed, 45 insertions(+) diff --git a/hw/virtio/virtio-iommu.c b/hw/virtio/virtio-iommu.c index 88849aa7b9..747e3cf1da 100644 --- a/hw/virtio/virtio-iommu.c +++ b/hw/virtio/virtio-iommu.c @@ -770,6 +770,49 @@ static void virtio_iommu_set_page_size_mask(IOMMUMemor= yRegion *mr, sdev->page_size_mask =3D page_size_mask; } =20 +static gboolean virtio_iommu_remap(gpointer key, gpointer value, gpointer = data) +{ + VirtIOIOMMUMapping *mapping =3D (VirtIOIOMMUMapping *) value; + VirtIOIOMMUInterval *interval =3D (VirtIOIOMMUInterval *) key; + IOMMUMemoryRegion *mr =3D (IOMMUMemoryRegion *) data; + + trace_virtio_iommu_remap(interval->low, mapping->phys_addr, + interval->high - interval->low + 1); + /* unmap previous entry and map again */ + virtio_iommu_notify_unmap(mr, interval->low, + interval->high - interval->low + 1); + + virtio_iommu_notify_map(mr, interval->low, mapping->phys_addr, + interval->high - interval->low + 1); + return false; +} + +static void virtio_iommu_replay(IOMMUMemoryRegion *mr, IOMMUNotifier *n) +{ + IOMMUDevice *sdev =3D container_of(mr, IOMMUDevice, iommu_mr); + VirtIOIOMMU *s =3D sdev->viommu; + uint32_t sid; + VirtIOIOMMUEndpoint *ep; + + sid =3D virtio_iommu_get_bdf(sdev); + + qemu_mutex_lock(&s->mutex); + + if (!s->endpoints) { + goto unlock; + } + + ep =3D g_tree_lookup(s->endpoints, GUINT_TO_POINTER(sid)); + if (!ep || !ep->domain) { + goto unlock; + } + + g_tree_foreach(ep->domain->mappings, virtio_iommu_remap, mr); + +unlock: + qemu_mutex_unlock(&s->mutex); +} + static void virtio_iommu_device_realize(DeviceState *dev, Error **errp) { VirtIODevice *vdev =3D VIRTIO_DEVICE(dev); @@ -988,6 +1031,7 @@ static void virtio_iommu_memory_region_class_init(Obje= ctClass *klass, =20 imrc->translate =3D virtio_iommu_translate; imrc->iommu_set_page_size_mask =3D virtio_iommu_set_page_size_mask; + imrc->replay =3D virtio_iommu_replay; } =20 static const TypeInfo virtio_iommu_info =3D { diff --git a/hw/virtio/trace-events b/hw/virtio/trace-events index d94a1cd8a3..8bae651191 100644 --- a/hw/virtio/trace-events +++ b/hw/virtio/trace-events @@ -75,3 +75,4 @@ virtio_iommu_translate_out(uint64_t virt_addr, uint64_t p= hys_addr, uint32_t sid) virtio_iommu_report_fault(uint8_t reason, uint32_t flags, uint32_t endpoin= t, uint64_t addr) "FAULT reason=3D%d flags=3D%d endpoint=3D%d address =3D0x= %"PRIx64 virtio_iommu_notify_map(const char *name, uint64_t iova, uint64_t paddr, u= int64_t map_size) "mr=3D%s iova=3D0x%"PRIx64" pa=3D0x%" PRIx64" size=3D0x%"= PRIx64 virtio_iommu_notify_unmap(const char *name, uint64_t iova, uint64_t map_si= ze) "mr=3D%s iova=3D0x%"PRIx64" size=3D0x%"PRIx64 +virtio_iommu_remap(uint64_t iova, uint64_t pa, uint64_t size) "iova=3D0x%"= PRIx64" pa=3D0x%" PRIx64" size=3D0x%"PRIx64"" --=20 2.17.1