From nobody Thu May 2 14:12:39 2024 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=fail; 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=fail(p=none dis=none) header.from=marvell.com ARC-Seal: i=1; a=rsa-sha256; t=1584110270; cv=none; d=zohomail.com; s=zohoarc; b=E9Lj6YRiMpF/Otz3eiEvUwzsHxF2rncosV5imMzN17e424QDtGiwYdLEHzopKEo45vIEUjhUoehbBNVxLbgIogRS89gzOE0g+/8HE6Q79ipBrg7n8kjxIRSNUSoFcpCT31sJTNSl8yVWNd66L/bM/AHphsheM162rvnR/3v3yIA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1584110270; 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=qEAv6IpogbV7YHyhj2l6c6UjHVFT5rsptczJTs+HL8c=; b=KEn9cdltImNp9wpn1FtwT1gneoEvw1PTC+BozpUmvzbLQhIWPgCwq+ya2xlNs2L6bAAUqK5VtQN3h5DYxSmkSJFuE3t1tIPdFmz2U0C4t5JS3tjaz3p+fJCS89jiP4YuWIfRsd9/fExJguN5qT9ktWzxrB9j5Ra0x43XQPLYNxM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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=fail 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 1584110270781281.55740901084107; Fri, 13 Mar 2020 07:37:50 -0700 (PDT) Received: from localhost ([::1]:60030 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jClRd-0003La-On for importer@patchew.org; Fri, 13 Mar 2020 10:37:49 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60930) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jCf3X-0005sr-Gq for qemu-devel@nongnu.org; Fri, 13 Mar 2020 03:48:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jCf3W-0001av-GE for qemu-devel@nongnu.org; Fri, 13 Mar 2020 03:48:31 -0400 Received: from mx0a-0016f401.pphosted.com ([67.231.148.174]:14992 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 1jCf3U-0001V8-Bv; Fri, 13 Mar 2020 03:48:28 -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 02D7jiWU023265; Fri, 13 Mar 2020 00:48:25 -0700 Received: from sc-exch01.marvell.com ([199.233.58.181]) by mx0a-0016f401.pphosted.com with ESMTP id 2yqt7t2v9w-3 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Fri, 13 Mar 2020 00:48:25 -0700 Received: from DC5-EXCH02.marvell.com (10.69.176.39) by SC-EXCH01.marvell.com (10.93.176.81) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Fri, 13 Mar 2020 00:48:24 -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:23 -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:18 -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=qEAv6IpogbV7YHyhj2l6c6UjHVFT5rsptczJTs+HL8c=; b=iVe/ipo9dIab1/pUn/lnIVmy4KIa8U27A5fis00wp1p4uP/uOmGRhxYR+0SeyxXOHMiP wxx0cFsla1+tHkYQYpfvb/YPDBChdTjBA72EjOFutrfpn2j+vqWdaiTSRh0TYzL8BEo6 ZN2y3SIAboiedJYH3Nktlt2GrMqugdZXU6vdk7RIsGdzz4ZXzN26N4XydQ/abQBl1nIC okJbYuPYvqxJGebVX0l0FVmWG+ZpPPRJZtPRV9ZZeLR8zkYW5b1fHVvWYohWGL2T+8hJ MZbLjK1XNke+UogX94Uf0XvubseVxQcbLMM4ynsfTVkUlKnJ0qMTi88veOGKQYshOQPF fg== From: Bharat Bhushan To: , , , , , , , , , , , Subject: [PATCH v7 1/5] hw/vfio/common: Remove error print on mmio region translation by viommu Date: Fri, 13 Mar 2020 13:18:07 +0530 Message-ID: <20200313074811.27175-2-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.148.174 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: Eric Auger , Bharat Bhushan Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" On ARM, the MSI doorbell is translated by the virtual IOMMU. As such address_space_translate() returns the MSI controller MMIO region and we get an "iommu map to non memory area" message. Let's remove this latter. Signed-off-by: Eric Auger Signed-off-by: Bharat Bhushan --- hw/vfio/common.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/hw/vfio/common.c b/hw/vfio/common.c index 5ca11488d6..c586edf47a 100644 --- a/hw/vfio/common.c +++ b/hw/vfio/common.c @@ -426,8 +426,6 @@ static bool vfio_get_vaddr(IOMMUTLBEntry *iotlb, void *= *vaddr, &xlat, &len, writable, MEMTXATTRS_UNSPECIFIED); if (!memory_region_is_ram(mr)) { - error_report("iommu map to non memory area %"HWADDR_PRIx"", - xlat); return false; } =20 --=20 2.17.1 From nobody Thu May 2 14:12:39 2024 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=fail; 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=fail(p=none dis=none) header.from=marvell.com ARC-Seal: i=1; a=rsa-sha256; t=1584110434; cv=none; d=zohomail.com; s=zohoarc; b=KYaaUdBl5qNS19OwSC85ydVnwSC4XGigWxoWNnoAQmvuhNU45gRuDQsSob+1hjUaii+eL2wC76ZQe6szpDNmV7Rt+jxGMA3sTFa8KSn3C0iFZhZDbuO/2fHqYWcn3y7IpEpsG3TG8C8TsWWz7PKRK4iMk4T6he4l7j6enRr5osw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1584110434; 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=LjywHiaOudVGVnAq4/GJUsKnBJ0ndzG4l4NRbVS34SM=; b=Epe05npDlfnzYUi/1p+uZiUhXVpXXS5O1IP/McfY3E/mp3TFSwfXgDo0rVKEWsd8MZQ4ZRE4MLlrJHGzVcQBtALxo3QE3eDqJ94zDNwbHECDntW/vQ1TwlRbT1Y1FUiecYZUgbU5R5CGUmxmRapdQR/DNxg+eBIXzAuJyKQeE/8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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=fail 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 1584110434767271.58240654683175; Fri, 13 Mar 2020 07:40:34 -0700 (PDT) Received: from localhost ([::1]:60116 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jClUH-0001Bd-Lh for importer@patchew.org; Fri, 13 Mar 2020 10:40:33 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:32845) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jCf3c-0005uf-4w for qemu-devel@nongnu.org; Fri, 13 Mar 2020 03:48:37 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jCf3a-0001pE-U2 for qemu-devel@nongnu.org; Fri, 13 Mar 2020 03:48:36 -0400 Received: from mx0a-0016f401.pphosted.com ([67.231.148.174]:40254 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 1jCf3Y-0001cn-1v; Fri, 13 Mar 2020 03:48:32 -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 02D7iq87022612; Fri, 13 Mar 2020 00:48:29 -0700 Received: from sc-exch02.marvell.com ([199.233.58.182]) by mx0a-0016f401.pphosted.com with ESMTP id 2yqt7t2va8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Fri, 13 Mar 2020 00:48:29 -0700 Received: from SC-EXCH04.marvell.com (10.93.176.84) by SC-EXCH02.marvell.com (10.93.176.82) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Fri, 13 Mar 2020 00:48:28 -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:24 -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=LjywHiaOudVGVnAq4/GJUsKnBJ0ndzG4l4NRbVS34SM=; b=c6eKI6qkQOk7Iv5QgcY/3s1pJzpwcfn4kj+4NYmjwgMSD8S4p5IiNwGrEHwlpz8n1hd/ qPyHPw8TWxXQnBbdhR+040pX2/jxWeGjyOl933BCU0npAP6VnhQnfqKveipwMk7hugK1 9olorg6YkcC/tRT4fdM1ra/ESE313aP88FZ05t9l/3z4Ggi3DTu90A7s8RyPv0zisLeY FWCdlYcTa7aky3vxW6Ox8xPjF1hISYtCSvYmyAJF+kpQW0pIQ5uqTH3PHbYwbQDigFIh zqE6MViHKzf4x+iikQjtDWHGhJRKBiu1Bu+Kv+JzIHZBc4sXhR0eqF8SOY0rLKoKjNY+ xQ== From: Bharat Bhushan To: , , , , , , , , , , , Subject: [PATCH v7 2/5] virtio-iommu: Add iommu notifier for map/unmap Date: Fri, 13 Mar 2020 13:18:08 +0530 Message-ID: <20200313074811.27175-3-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.148.174 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: Eric Auger , Bharat Bhushan Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" This patch extends VIRTIO_IOMMU_T_MAP/UNMAP request to notify registered iommu-notifier. Which will call vfio notifier to map/unmap region in iommu. Signed-off-by: Bharat Bhushan Signed-off-by: Eric Auger --- hw/virtio/trace-events | 2 + hw/virtio/virtio-iommu.c | 66 +++++++++++++++++++++++++++++++- include/hw/virtio/virtio-iommu.h | 6 +++ 3 files changed, 73 insertions(+), 1 deletion(-) diff --git a/hw/virtio/trace-events b/hw/virtio/trace-events index e83500bee9..d94a1cd8a3 100644 --- a/hw/virtio/trace-events +++ b/hw/virtio/trace-events @@ -73,3 +73,5 @@ virtio_iommu_get_domain(uint32_t domain_id) "Alloc domain= =3D%d" virtio_iommu_put_domain(uint32_t domain_id) "Free domain=3D%d" virtio_iommu_translate_out(uint64_t virt_addr, uint64_t phys_addr, uint32_= t sid) "0x%"PRIx64" -> 0x%"PRIx64 " for sid=3D%d" 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 diff --git a/hw/virtio/virtio-iommu.c b/hw/virtio/virtio-iommu.c index 4cee8083bc..e51344a53e 100644 --- a/hw/virtio/virtio-iommu.c +++ b/hw/virtio/virtio-iommu.c @@ -123,6 +123,38 @@ static gint interval_cmp(gconstpointer a, gconstpointe= r b, gpointer user_data) } } =20 +static void virtio_iommu_notify_map(IOMMUMemoryRegion *mr, hwaddr iova, + hwaddr paddr, hwaddr size) +{ + IOMMUTLBEntry entry; + + entry.target_as =3D &address_space_memory; + entry.addr_mask =3D size - 1; + + entry.iova =3D iova; + trace_virtio_iommu_notify_map(mr->parent_obj.name, iova, paddr, size); + entry.perm =3D IOMMU_RW; + entry.translated_addr =3D paddr; + + memory_region_notify_iommu(mr, 0, entry); +} + +static void virtio_iommu_notify_unmap(IOMMUMemoryRegion *mr, hwaddr iova, + hwaddr size) +{ + IOMMUTLBEntry entry; + + entry.target_as =3D &address_space_memory; + entry.addr_mask =3D size - 1; + + entry.iova =3D iova; + trace_virtio_iommu_notify_unmap(mr->parent_obj.name, iova, size); + entry.perm =3D IOMMU_NONE; + entry.translated_addr =3D 0; + + memory_region_notify_iommu(mr, 0, entry); +} + static void virtio_iommu_detach_endpoint_from_domain(VirtIOIOMMUEndpoint *= ep) { if (!ep->domain) { @@ -307,9 +339,12 @@ static int virtio_iommu_map(VirtIOIOMMU *s, uint64_t virt_start =3D le64_to_cpu(req->virt_start); uint64_t virt_end =3D le64_to_cpu(req->virt_end); uint32_t flags =3D le32_to_cpu(req->flags); + hwaddr size =3D virt_end - virt_start + 1; + VirtioIOMMUNotifierNode *node; VirtIOIOMMUDomain *domain; VirtIOIOMMUInterval *interval; VirtIOIOMMUMapping *mapping; + VirtIOIOMMUEndpoint *ep; =20 if (flags & ~VIRTIO_IOMMU_MAP_F_MASK) { return VIRTIO_IOMMU_S_INVAL; @@ -339,9 +374,37 @@ static int virtio_iommu_map(VirtIOIOMMU *s, =20 g_tree_insert(domain->mappings, interval, mapping); =20 + /* All devices in an address-space share mapping */ + QLIST_FOREACH(node, &s->notifiers_list, next) { + QLIST_FOREACH(ep, &domain->endpoint_list, next) { + if (ep->id =3D=3D node->iommu_dev->devfn) { + virtio_iommu_notify_map(&node->iommu_dev->iommu_mr, + virt_start, phys_start, size); + } + } + } + return VIRTIO_IOMMU_S_OK; } =20 +static void virtio_iommu_remove_mapping(VirtIOIOMMU *s, VirtIOIOMMUDomain = *domain, + VirtIOIOMMUInterval *interval) +{ + VirtioIOMMUNotifierNode *node; + VirtIOIOMMUEndpoint *ep; + + QLIST_FOREACH(node, &s->notifiers_list, next) { + QLIST_FOREACH(ep, &domain->endpoint_list, next) { + if (ep->id =3D=3D node->iommu_dev->devfn) { + virtio_iommu_notify_unmap(&node->iommu_dev->iommu_mr, + interval->low, + interval->high - interval->low += 1); + } + } + } + g_tree_remove(domain->mappings, (gpointer)(interval)); +} + static int virtio_iommu_unmap(VirtIOIOMMU *s, struct virtio_iommu_req_unmap *req) { @@ -368,7 +431,7 @@ static int virtio_iommu_unmap(VirtIOIOMMU *s, uint64_t current_high =3D iter_key->high; =20 if (interval.low <=3D current_low && interval.high >=3D current_hi= gh) { - g_tree_remove(domain->mappings, iter_key); + virtio_iommu_remove_mapping(s, domain, iter_key); trace_virtio_iommu_unmap_done(domain_id, current_low, current_= high); } else { ret =3D VIRTIO_IOMMU_S_RANGE; @@ -655,6 +718,7 @@ static void virtio_iommu_device_realize(DeviceState *de= v, Error **errp) VirtIODevice *vdev =3D VIRTIO_DEVICE(dev); VirtIOIOMMU *s =3D VIRTIO_IOMMU(dev); =20 + QLIST_INIT(&s->notifiers_list); virtio_init(vdev, "virtio-iommu", VIRTIO_ID_IOMMU, sizeof(struct virtio_iommu_config)); =20 diff --git a/include/hw/virtio/virtio-iommu.h b/include/hw/virtio/virtio-io= mmu.h index 6f67f1020a..4539c8ae72 100644 --- a/include/hw/virtio/virtio-iommu.h +++ b/include/hw/virtio/virtio-iommu.h @@ -44,6 +44,11 @@ typedef struct IOMMUPciBus { IOMMUDevice *pbdev[0]; /* Parent array is sparse, so dynamically allo= c */ } IOMMUPciBus; =20 +typedef struct VirtioIOMMUNotifierNode { + IOMMUDevice *iommu_dev; + QLIST_ENTRY(VirtioIOMMUNotifierNode) next; +} VirtioIOMMUNotifierNode; + typedef struct VirtIOIOMMU { VirtIODevice parent_obj; VirtQueue *req_vq; @@ -56,6 +61,7 @@ typedef struct VirtIOIOMMU { GTree *domains; QemuMutex mutex; GTree *endpoints; + QLIST_HEAD(, VirtioIOMMUNotifierNode) notifiers_list; } VirtIOIOMMU; =20 #endif --=20 2.17.1 From nobody Thu May 2 14:12:39 2024 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 From nobody Thu May 2 14:12:39 2024 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=1584110523; cv=none; d=zohomail.com; s=zohoarc; b=Z1FBt53OO4MukKwfuMuQJLhnnhEdUnQDNBvHKN1Elfc2KmdH+Qxl/nMtL1oS2jQYf+FGgHg4rwENbAPdV6+lwB3xf/rsQXXkQ9FrRPjp/CQY9Z3eVzxHVedqvJn0qULD2wl1JZj1BPkYUr/q/plMprJaytjbnUfNCbFUsRncWjA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1584110523; 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=+icZQ+2dZ1MJRUktX6WWQN23OKRsL0uBg2iaa3i4miw=; b=c3LNbQFVshRu2V7WxXGODipLfv0rFvUZ6rpY1l3LU/eQmYzOC+X3YoCSOKhgyjryPAnH9nQiD/cYsYNlBo4UpvtA08Z5zS0c0rPFqAWNQtfxpPUhITQ80GrhdkQCZ0crJp7J8fJkizpKd/EfwY6xKUl/MxPryL8VxIYfYQ+mKcw= 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 1584110523993879.7547219272788; Fri, 13 Mar 2020 07:42:03 -0700 (PDT) Received: from localhost ([::1]:60192 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jClVi-0004DL-VB for importer@patchew.org; Fri, 13 Mar 2020 10:42:02 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:33138) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jCf3m-00064x-8o for qemu-devel@nongnu.org; Fri, 13 Mar 2020 03:48:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jCf3k-0002CY-Rk for qemu-devel@nongnu.org; Fri, 13 Mar 2020 03:48:46 -0400 Received: from mx0b-0016f401.pphosted.com ([67.231.156.173]:13678) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jCf3i-00025A-H8; Fri, 13 Mar 2020 03:48:42 -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 02D7kFxk020335; Fri, 13 Mar 2020 00:48:40 -0700 Received: from sc-exch04.marvell.com ([199.233.58.184]) by mx0b-0016f401.pphosted.com with ESMTP id 2yqt7f2vpn-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Fri, 13 Mar 2020 00:48:40 -0700 Received: from SC-EXCH04.marvell.com (10.93.176.84) 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:38 -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:34 -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=+icZQ+2dZ1MJRUktX6WWQN23OKRsL0uBg2iaa3i4miw=; b=lQtB4j7IX/jaoJkpYZQ2CqoykXc8FSnnNFY7aabGIAn3us4XGxr+2OH7msZZ26FA3JAB BX4GMiNV0VrVg885P9Bm3rdBthcrOPDFAUvIF3KRS9k5UBEUZj1XxNlsJXKj4O5Hg+Ia 5jyXoapEWU76CyVmTlAspcDzsaJS9Z+YfpKTMPkjeN2iBWtFpevIbajTkNk31muup6VJ /d/MOBgvMdIE0vtCkVqCK5j+1KXORRQ2K3G+iyZ9VXC2PG49hLFbdD7tiTkJcbD2X2oJ KrbX7tqZvnSTzpR4WTIUdDor3mCY84lwoN5dNarMI8J0HTgyNN5LR33e/8Ku3XdWegco Zg== From: Bharat Bhushan To: , , , , , , , , , , , Subject: [PATCH v7 4/5] virtio-iommu: add iommu replay Date: Fri, 13 Mar 2020 13:18:10 +0530 Message-ID: <20200313074811.27175-5-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:06 -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" Default replay does not work with virtio-iommu, so this patch provide virtio-iommu replay functionality. Signed-off-by: Bharat Bhushan --- hw/virtio/trace-events | 1 + hw/virtio/virtio-iommu.c | 44 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) 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"" diff --git a/hw/virtio/virtio-iommu.c b/hw/virtio/virtio-iommu.c index 2006f72901..bcc9895b76 100644 --- a/hw/virtio/virtio-iommu.c +++ b/hw/virtio/virtio-iommu.c @@ -760,6 +760,49 @@ static gint int_cmp(gconstpointer a, gconstpointer b, = gpointer user_data) return (ua > ub) - (ua < ub); } =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); @@ -976,6 +1019,7 @@ static void virtio_iommu_memory_region_class_init(Obje= ctClass *klass, IOMMUMemoryRegionClass *imrc =3D IOMMU_MEMORY_REGION_CLASS(klass); =20 imrc->translate =3D virtio_iommu_translate; + imrc->replay =3D virtio_iommu_replay; } =20 static const TypeInfo virtio_iommu_info =3D { --=20 2.17.1 From nobody Thu May 2 14:12:39 2024 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=1584110520; cv=none; d=zohomail.com; s=zohoarc; b=cO6OrfZ0g7Rq9yz4+Jc6uL5JFLbAk0obH8SwSUVS/QoXGODeP3mqXEaFkX7rW3khRlcxlN54J88s7D8c8LWHEmpF8O+MSlCLPibvsdMuc+4yYrGTOVt0ZbUyFj9Zcc+XMzx7AuD43iEhPAj9eK4SP+8rl8HD4R5kYljbholhW40= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1584110520; 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=d2iWCXJz4dJ2g2X4/WjavG5MxgCZeaMWghSwegVnILA=; b=hXXRyV59Z48zmnIguRFb1GYgQFTRp/za4OgMDfWefV37yvZsrupSO616d+B/It2RnI6QRXs0InX5CldOs3ubD/QFPmgpNTCYk/502LiD8EDgA+qe0bLk/xfXwtQB49JaJC+93keX9HRZyRy40V2AHodp3W1OiPPC6HawdT8ETdY= 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 1584110520256131.01878894568847; Fri, 13 Mar 2020 07:42:00 -0700 (PDT) Received: from localhost ([::1]:60184 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jClVf-00045s-9o for importer@patchew.org; Fri, 13 Mar 2020 10:41:59 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:33282) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jCf3r-000666-Ib for qemu-devel@nongnu.org; Fri, 13 Mar 2020 03:48:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jCf3q-0002Mn-Di for qemu-devel@nongnu.org; Fri, 13 Mar 2020 03:48:51 -0400 Received: from mx0b-0016f401.pphosted.com ([67.231.156.173]:62722) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jCf3n-0002Gc-TO; Fri, 13 Mar 2020 03:48:47 -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 02D7jtkP020297; Fri, 13 Mar 2020 00:48:45 -0700 Received: from sc-exch03.marvell.com ([199.233.58.183]) by mx0b-0016f401.pphosted.com with ESMTP id 2yqt7f2vpy-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Fri, 13 Mar 2020 00:48:45 -0700 Received: from SC-EXCH04.marvell.com (10.93.176.84) by SC-EXCH03.marvell.com (10.93.176.83) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Fri, 13 Mar 2020 00:48:43 -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:39 -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=d2iWCXJz4dJ2g2X4/WjavG5MxgCZeaMWghSwegVnILA=; b=w6P2iJT7tLEhvYJ0kNUy0zsfOUW7F2AGR4rCyBgaCNMJhIXPESSy4xj3aRYzZ5a1W0cz v+N2VFoMbPDk/cX+qlSH00+GlruvD9K4ATh0/mjGuCwnt+efvL6hElsGSE8k7FGWoeGK DOIdF+vmH3Dwmw34a2cgvM1dl+gRJ3ZPgww5k7IQwO9Q4LCithpuk0wQS0C6EaNse/6t w+4iFwYHjHs1ngw2tUvtKLiTVuQYmukRf3jKJbbxSI/ZW7VBJWsGUqsbDeBm5hs/jxQx q0gxNnTkxmKT5hCk5A421GHamJcDJP7eSKDIagXZ/Cx4C7EdmPK624zs2tPJerzcYX0L Lg== From: Bharat Bhushan To: , , , , , , , , , , , Subject: [PATCH v7 5/5] virtio-iommu: add iommu notifier memory-region Date: Fri, 13 Mar 2020 13:18:11 +0530 Message-ID: <20200313074811.27175-6-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:06 -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" Finally add notify_flag_changed() to for memory-region access flag iommu flag change notifier Finally add the memory notifier Signed-off-by: Bharat Bhushan --- hw/virtio/trace-events | 2 ++ hw/virtio/virtio-iommu.c | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/hw/virtio/trace-events b/hw/virtio/trace-events index 8bae651191..a486adcf6d 100644 --- a/hw/virtio/trace-events +++ b/hw/virtio/trace-events @@ -76,3 +76,5 @@ virtio_iommu_report_fault(uint8_t reason, uint32_t flags,= uint32_t endpoint, uin 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"" +virtio_iommu_notify_flag_add(const char *iommu) "Add virtio-iommu notifier= node for memory region %s" +virtio_iommu_notify_flag_del(const char *iommu) "Del virtio-iommu notifier= node for memory region %s" diff --git a/hw/virtio/virtio-iommu.c b/hw/virtio/virtio-iommu.c index bcc9895b76..7744410f72 100644 --- a/hw/virtio/virtio-iommu.c +++ b/hw/virtio/virtio-iommu.c @@ -803,6 +803,37 @@ unlock: qemu_mutex_unlock(&s->mutex); } =20 +static int virtio_iommu_notify_flag_changed(IOMMUMemoryRegion *iommu_mr, + IOMMUNotifierFlag old, + IOMMUNotifierFlag new, + Error **errp) +{ + IOMMUDevice *sdev =3D container_of(iommu_mr, IOMMUDevice, iommu_mr); + VirtIOIOMMU *s =3D sdev->viommu; + VirtioIOMMUNotifierNode *node =3D NULL; + VirtioIOMMUNotifierNode *next_node =3D NULL; + + if (old =3D=3D IOMMU_NOTIFIER_NONE) { + trace_virtio_iommu_notify_flag_add(iommu_mr->parent_obj.name); + node =3D g_malloc0(sizeof(*node)); + node->iommu_dev =3D sdev; + QLIST_INSERT_HEAD(&s->notifiers_list, node, next); + return 0; + } + + /* update notifier node with new flags */ + QLIST_FOREACH_SAFE(node, &s->notifiers_list, next, next_node) { + if (node->iommu_dev =3D=3D sdev) { + if (new =3D=3D IOMMU_NOTIFIER_NONE) { + trace_virtio_iommu_notify_flag_del(iommu_mr->parent_obj.na= me); + QLIST_REMOVE(node, next); + g_free(node); + } + } + } + return 0; +} + static void virtio_iommu_device_realize(DeviceState *dev, Error **errp) { VirtIODevice *vdev =3D VIRTIO_DEVICE(dev); @@ -1020,6 +1051,7 @@ static void virtio_iommu_memory_region_class_init(Obj= ectClass *klass, =20 imrc->translate =3D virtio_iommu_translate; imrc->replay =3D virtio_iommu_replay; + imrc->notify_flag_changed =3D virtio_iommu_notify_flag_changed; } =20 static const TypeInfo virtio_iommu_info =3D { --=20 2.17.1