From nobody Mon Feb 9 19:54:20 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=1584110363; cv=none; d=zohomail.com; s=zohoarc; b=GiWBhSCwceSxZuIi6zxxd59rIMGXUxWfS9d4Wwr4a9h4EE6Y8N29l9ii8WFdf+cDR0SRJlk14h4SWmQGDpFsR8mY1wQGYBVr0o5kkjDJZj7Qpf4CO6IKv8x/0JdU+EgpOHPSMmGZFt2VNy0lHfogAh2qDzkoCwOVBeprReozUC8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1584110363; 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=bxcH3jTGSpUws5gjNrL1mqbtHaE1FJNRhfGJgv67EnU=; b=b0YScCHWuyqkkm3nUNkduxi5o1c2S9S3qKTUuw2BcO4n/HIYuLjFT9wdicefaqyjjH5n/tulapotWK5rb+ps2aarOXAviAxk6iPkhdueOUe7B8+TmiAMN6JMqzdqA25V8SfEc4WyWrJNdNcOetarfQOb/sRd3wPmfVltwfNFoXM= 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 1584110363056197.40320850378612; Fri, 13 Mar 2020 07:39:23 -0700 (PDT) Received: from localhost ([::1]:60080 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jClT8-0007Fv-1E for importer@patchew.org; Fri, 13 Mar 2020 10:39:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:33005) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jCf3h-0005y9-HO for qemu-devel@nongnu.org; Fri, 13 Mar 2020 03:48:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jCf3g-00021p-Gc for qemu-devel@nongnu.org; Fri, 13 Mar 2020 03:48:41 -0400 Received: from mx0b-0016f401.pphosted.com ([67.231.156.173]:17458) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jCf3e-0001xF-14; Fri, 13 Mar 2020 03:48:38 -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 02D7kDwP020331; Fri, 13 Mar 2020 00:48:36 -0700 Received: from sc-exch04.marvell.com ([199.233.58.184]) by mx0b-0016f401.pphosted.com with ESMTP id 2yqt7f2vpd-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Fri, 13 Mar 2020 00:48:36 -0700 Received: from DC5-EXCH02.marvell.com (10.69.176.39) by SC-EXCH04.marvell.com (10.93.176.84) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Fri, 13 Mar 2020 00:48:34 -0700 Received: from SC-EXCH04.marvell.com (10.93.176.84) by DC5-EXCH02.marvell.com (10.69.176.39) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Fri, 13 Mar 2020 00:48:33 -0700 Received: from bbhushan2.marvell.com (10.93.176.43) by SC-EXCH04.marvell.com (10.93.176.84) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Fri, 13 Mar 2020 00:48:29 -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=bxcH3jTGSpUws5gjNrL1mqbtHaE1FJNRhfGJgv67EnU=; b=gUTAH0FIpQieLuDSAKYaFVFa7hz2J2C/cyf2vb0dlt6KXtQsHUpH5rMxP4GH9URgialX bFun9ehjw2XUuAdACD0ck8J11Ap7IPB22wGjcvtrUEz+D5Sw3AJUULRLhh4U6FUyHGR8 E7lQz0IfQCCeOoeJab/GIdvldWRF8StdhnQaKzGTNm2c/ggPWk8uQNLklzjtV6sPTous PCXCaUDhO0rMCWVc2//8Mb2svqlP4mGeuizMX0+VqUtyLfdUWHRz5iMZ0mnULsb3Rkjz /Js8wQq7iYdQ+O1ZI6P4pNRPnSQaEBTqH81MtWUKEOzIY4AFcnKRE3k4/XGyAIJ8+Y+D sw== From: Bharat Bhushan To: , , , , , , , , , , , Subject: [PATCH v7 3/5] virtio-iommu: Call iommu notifier for attach/detach Date: Fri, 13 Mar 2020 13:18:09 +0530 Message-ID: <20200313074811.27175-4-bbhushan2@marvell.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200313074811.27175-1-bbhushan2@marvell.com> References: <20200313074811.27175-1-bbhushan2@marvell.com> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.138, 18.0.572 definitions=2020-03-13_03:2020-03-11, 2020-03-13 signatures=0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] X-Received-From: 67.231.156.173 X-Mailman-Approved-At: Fri, 13 Mar 2020 10:36:05 -0400 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 Reported-by: Bharat Bhushan --- hw/virtio/virtio-iommu.c | 47 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/hw/virtio/virtio-iommu.c b/hw/virtio/virtio-iommu.c index e51344a53e..2006f72901 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,8 +156,44 @@ static void virtio_iommu_notify_unmap(IOMMUMemoryRegio= n *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) { + VirtioIOMMUNotifierNode *node; + VirtIOIOMMU *s =3D ep->viommu; + VirtIOIOMMUDomain *domain =3D ep->domain; + + QLIST_FOREACH(node, &s->notifiers_list, next) { + if (ep->id =3D=3D node->iommu_dev->devfn) { + g_tree_foreach(domain->mappings, virtio_iommu_mapping_unmap, + &node->iommu_dev->iommu_mr); + } + } + if (!ep->domain) { return; } @@ -178,6 +215,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; @@ -272,6 +310,7 @@ static int virtio_iommu_attach(VirtIOIOMMU *s, { uint32_t domain_id =3D le32_to_cpu(req->domain); uint32_t ep_id =3D le32_to_cpu(req->endpoint); + VirtioIOMMUNotifierNode *node; VirtIOIOMMUDomain *domain; VirtIOIOMMUEndpoint *ep; =20 @@ -299,6 +338,14 @@ static int virtio_iommu_attach(VirtIOIOMMU *s, =20 ep->domain =3D domain; =20 + /* Replay existing address space mappings on the associated memory reg= ion */ + QLIST_FOREACH(node, &s->notifiers_list, next) { + if (ep_id =3D=3D node->iommu_dev->devfn) { + g_tree_foreach(domain->mappings, virtio_iommu_mapping_map, + &node->iommu_dev->iommu_mr); + } + } + return VIRTIO_IOMMU_S_OK; } =20 --=20 2.17.1