From nobody Mon Feb 9 20:35:12 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=1584953525; cv=none; d=zohomail.com; s=zohoarc; b=O9vo86dfy11IKYUHP+YllCLEkV89QFNytrcbEk5ksHERnYKGBLIH6VcB2CK0gtNY5ka0xIatJSgt/xbflpv8/pmhmmCun8S3zzTyb/BFLOQnASoTjreVWa35knHGvzvYG+Dz86Y7bSQQmilHkr60/LYsZ9DOtJMI7XCsyC0/Pxw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1584953525; 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=6uTNrZsOxWL293QbnMDHDEcZhVh+4bvO0bI5PoXuaQw=; b=Lc0irqEqSuVBk14XpxlkL0OjF53vssOxyYorttB5rQGMY49Yt9UlVIGN0NXeBOOl+4HjxT803GtE+sa352QshUKMCHbC9JsSqv5uyjQ6ESEqKSSKDjyOQa/lZz6hj2aOgA59t76WEu72tOrpZVXyhfdfg/O8su+Fks61hr4DKFc= 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 1584953525981475.37371761915415; Mon, 23 Mar 2020 01:52:05 -0700 (PDT) Received: from localhost ([::1]:58746 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jGIoW-0006zf-OL for importer@patchew.org; Mon, 23 Mar 2020 04:52:04 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48500) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jGIjn-00009P-JQ for qemu-devel@nongnu.org; Mon, 23 Mar 2020 04:47:12 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jGIjm-0003F4-BD for qemu-devel@nongnu.org; Mon, 23 Mar 2020 04:47:11 -0400 Received: from mx0b-0016f401.pphosted.com ([67.231.156.173]:10634) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jGIji-0003CP-Jq; Mon, 23 Mar 2020 04:47:06 -0400 Received: from pps.filterd (m0045851.ppops.net [127.0.0.1]) by mx0b-0016f401.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 02N8ePfP013763; Mon, 23 Mar 2020 01:47:04 -0700 Received: from sc-exch04.marvell.com ([199.233.58.184]) by mx0b-0016f401.pphosted.com with ESMTP id 2ywvkqkxcm-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Mon, 23 Mar 2020 01:47:04 -0700 Received: from DC5-EXCH01.marvell.com (10.69.176.38) by SC-EXCH04.marvell.com (10.93.176.84) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Mon, 23 Mar 2020 01:47:01 -0700 Received: from SC-EXCH03.marvell.com (10.93.176.83) by DC5-EXCH01.marvell.com (10.69.176.38) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Mon, 23 Mar 2020 01:47:01 -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:46:56 -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=6uTNrZsOxWL293QbnMDHDEcZhVh+4bvO0bI5PoXuaQw=; b=IxKd0egvumpqD+jjivEF0CZQiDPWXIU5qb2XL+zYpDUwtN2m4q8tQHcTbHztHx2fQ0gw DN8DBbZKzU5962T9kqfPxj61B0ob78zzdcc2M+Dl+fDAB/gukga9LTeWdA5i541adS/0 6vdkFpsPmP+zPcsKp+4CXX8zTrb8h8vmpApaXt+HfZkvPs39iGpp8u5y7hv7JCxMHNm+ gGzrHk4YJ8rvEfrl4YfZjzat3XFLjK6+RsdxU1fz5mzL6syuHeGJv5lfPOD5x52cDGM1 KdvIPSOn+f9VnaVYQLD3ONfXSUvg9qhriQRAm8PdpHoKfIHf6JN1wKshZznjREh5w6tQ Gg== From: Bharat Bhushan To: , , , , , , , , , , , , , Subject: [PATCH v9 6/9] virtio-iommu: Call iommu notifier for attach/detach Date: Mon, 23 Mar 2020 14:16:14 +0530 Message-ID: <20200323084617.1782-7-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.156.173 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" iommu-notifier are called when a device is attached or detached to as address-space. This is needed for VFIO. Signed-off-by: Bharat Bhushan --- hw/virtio/virtio-iommu.c | 49 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/hw/virtio/virtio-iommu.c b/hw/virtio/virtio-iommu.c index bd464d4fb3..88849aa7b9 100644 --- a/hw/virtio/virtio-iommu.c +++ b/hw/virtio/virtio-iommu.c @@ -49,6 +49,7 @@ typedef struct VirtIOIOMMUEndpoint { uint32_t id; VirtIOIOMMUDomain *domain; QLIST_ENTRY(VirtIOIOMMUEndpoint) next; + VirtIOIOMMU *viommu; } VirtIOIOMMUEndpoint; =20 typedef struct VirtIOIOMMUInterval { @@ -155,11 +156,48 @@ static void virtio_iommu_notify_unmap(IOMMUMemoryRegi= on *mr, hwaddr iova, memory_region_notify_iommu(mr, 0, entry); } =20 +static gboolean virtio_iommu_mapping_unmap(gpointer key, gpointer value, + gpointer data) +{ + VirtIOIOMMUInterval *interval =3D (VirtIOIOMMUInterval *) key; + IOMMUMemoryRegion *mr =3D (IOMMUMemoryRegion *) data; + + virtio_iommu_notify_unmap(mr, interval->low, + interval->high - interval->low + 1); + + return false; +} + +static gboolean virtio_iommu_mapping_map(gpointer key, gpointer value, + gpointer data) +{ + VirtIOIOMMUMapping *mapping =3D (VirtIOIOMMUMapping *) value; + VirtIOIOMMUInterval *interval =3D (VirtIOIOMMUInterval *) key; + IOMMUMemoryRegion *mr =3D (IOMMUMemoryRegion *) data; + + virtio_iommu_notify_map(mr, interval->low, mapping->phys_addr, + interval->high - interval->low + 1); + + return false; +} + static void virtio_iommu_detach_endpoint_from_domain(VirtIOIOMMUEndpoint *= ep) { + VirtIOIOMMU *s =3D ep->viommu; + VirtIOIOMMUDomain *domain =3D ep->domain; + IOMMUDevice *sdev; + if (!ep->domain) { return; } + + QLIST_FOREACH(sdev, &s->notifiers_list, next) { + if (ep->id =3D=3D sdev->devfn) { + g_tree_foreach(domain->mappings, virtio_iommu_mapping_unmap, + &sdev->iommu_mr); + } + } + QLIST_REMOVE(ep, next); ep->domain =3D NULL; } @@ -178,6 +216,7 @@ static VirtIOIOMMUEndpoint *virtio_iommu_get_endpoint(V= irtIOIOMMU *s, } ep =3D g_malloc0(sizeof(*ep)); ep->id =3D ep_id; + ep->viommu =3D s; trace_virtio_iommu_get_endpoint(ep_id); g_tree_insert(s->endpoints, GUINT_TO_POINTER(ep_id), ep); return ep; @@ -274,6 +313,7 @@ static int virtio_iommu_attach(VirtIOIOMMU *s, uint32_t ep_id =3D le32_to_cpu(req->endpoint); VirtIOIOMMUDomain *domain; VirtIOIOMMUEndpoint *ep; + IOMMUDevice *sdev; =20 trace_virtio_iommu_attach(domain_id, ep_id); =20 @@ -299,6 +339,14 @@ static int virtio_iommu_attach(VirtIOIOMMU *s, =20 ep->domain =3D domain; =20 + /* Replay domain mappings on the associated memory region */ + QLIST_FOREACH(sdev, &s->notifiers_list, next) { + if (ep_id =3D=3D sdev->devfn) { + g_tree_foreach(domain->mappings, virtio_iommu_mapping_map, + &sdev->iommu_mr); + } + } + return VIRTIO_IOMMU_S_OK; } =20 @@ -872,6 +920,7 @@ static gboolean reconstruct_endpoints(gpointer key, gpo= inter value, =20 QLIST_FOREACH(iter, &d->endpoint_list, next) { iter->domain =3D d; + iter->viommu =3D s; g_tree_insert(s->endpoints, GUINT_TO_POINTER(iter->id), iter); } return false; /* continue the domain traversal */ --=20 2.17.1