From patchwork Fri Oct 30 18:05:01 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jean-Philippe Brucker X-Patchwork-Id: 316474 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0B09EC00A89 for ; Fri, 30 Oct 2020 18:09:14 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 5E212206E5 for ; Fri, 30 Oct 2020 18:09:13 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="jnPcSnIR" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5E212206E5 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:48826 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kYYps-0001M9-BZ for qemu-devel@archiver.kernel.org; Fri, 30 Oct 2020 14:09:12 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44746) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kYYmf-00055G-Ih for qemu-devel@nongnu.org; Fri, 30 Oct 2020 14:05:54 -0400 Received: from mail-wm1-x343.google.com ([2a00:1450:4864:20::343]:34926) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kYYmb-0004ot-DP for qemu-devel@nongnu.org; Fri, 30 Oct 2020 14:05:53 -0400 Received: by mail-wm1-x343.google.com with SMTP id h22so3768341wmb.0 for ; Fri, 30 Oct 2020 11:05:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=x+cvpu7ceWHktnpLf54xiiETIbszTKNIsMfFS/95CA0=; b=jnPcSnIREOXzqoUrjsQz/YmUF5n172hh7fbdxLDHsmBohlCVOTi6HSQvNf2N4Qtcnj ZCzDmF6fta5TR2MdxOsjBU2ZBHh2DwO3HXEq7fN+fKknA2EbEZQsL4FqzoDA1tnH6AAY 8UXDj9992XoQehqM9IJKmixG4k2WRE8phwSOGqMMgYksdidkEqYiBHO4ZaIxUon+OZ2T TjHN9BJsS7xGILH7Ywf7vHB/FY9hZskxQ77IQQYwGjflGIkcI4CRSr9nXsWbQu9nRoXb yYVLLb25oG9hPwPUTZCuThJqCXIyws2M9UwKJbtFLEQrQC4i6NjTaFEF+D7nh5A9QGq6 cEIw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=x+cvpu7ceWHktnpLf54xiiETIbszTKNIsMfFS/95CA0=; b=S4DY8x4mDwggJb+NH5RWqo+xQxLUkdxDZFdVCnLNDBD8RD+HwyOzaK4JF6CM96wx4O PBz8L3E/2Y9SgpvrZiwsk2CGXVxewPOPXniVfJRwijegPJsIG6VN4uwFbHYhXhw4LIkF /yBmNxygV9DOjtLQN2uPNP3k+eC0dv1Bde6dFTFlEa9/AZMlZphnfRpTZT35AYMo5ax+ NGiezFAyHwP6wahhr/xDm0tihmqwSRt76aLnmAEiUUVXigg/JuHCUEF97P2zmMrXOCHC an2bPUKPodt9ZjcgZsHaKyoovmYLhNQ3exRMEnhu+zk7isrbQrLEe0O0UOMqTQqqW0pW q1yg== X-Gm-Message-State: AOAM533EolInXVeFm6ROqbF/a7cZbb+EEAoLKP9DiEFnRWgVZ7WVnYFS lTn6zHfZvYkd1yXS5JbQ/Cs92w== X-Google-Smtp-Source: ABdhPJycfkGqQGLXB82Im0P3inWb2CLLsnwg522WPSaDqlKEi3SEAOhK1eZG3/wW/7cPjj4cvJE2Sg== X-Received: by 2002:a1c:c2c5:: with SMTP id s188mr4185427wmf.174.1604081147547; Fri, 30 Oct 2020 11:05:47 -0700 (PDT) Received: from localhost.localdomain ([2001:1715:4e26:a7e0:116c:c27a:3e7f:5eaf]) by smtp.gmail.com with ESMTPSA id u3sm10044438wro.33.2020.10.30.11.05.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Oct 2020 11:05:46 -0700 (PDT) From: Jean-Philippe Brucker To: eric.auger@redhat.com, alex.williamson@redhat.com Subject: [PATCH v11 01/10] virtio-iommu: Fix virtio_iommu_mr() Date: Fri, 30 Oct 2020 19:05:01 +0100 Message-Id: <20201030180510.747225-2-jean-philippe@linaro.org> X-Mailer: git-send-email 2.29.1 In-Reply-To: <20201030180510.747225-1-jean-philippe@linaro.org> References: <20201030180510.747225-1-jean-philippe@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::343; envelope-from=jean-philippe@linaro.org; helo=mail-wm1-x343.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jean-Philippe Brucker , mst@redhat.com, qemu-devel@nongnu.org, peterx@redhat.com, QEMU Stable , pbonzini@redhat.com, bbhushan2@marvell.com Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Due to an invalid mask, virtio_iommu_mr() may return the wrong memory region. It hasn't been too problematic so far because the function was only used to test existence of an endpoint, but that is about to change. Fixes: cfb42188b24d ("virtio-iommu: Implement attach/detach command") Cc: QEMU Stable Acked-by: Eric Auger Reviewed-by: Peter Xu Signed-off-by: Jean-Philippe Brucker --- hw/virtio/virtio-iommu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hw/virtio/virtio-iommu.c b/hw/virtio/virtio-iommu.c index 21ec63b1082..4c8f3909b7d 100644 --- a/hw/virtio/virtio-iommu.c +++ b/hw/virtio/virtio-iommu.c @@ -101,7 +101,7 @@ static IOMMUMemoryRegion *virtio_iommu_mr(VirtIOIOMMU *s, uint32_t sid) bus_n = PCI_BUS_NUM(sid); iommu_pci_bus = iommu_find_iommu_pcibus(s, bus_n); if (iommu_pci_bus) { - devfn = sid & PCI_DEVFN_MAX; + devfn = sid & (PCI_DEVFN_MAX - 1); dev = iommu_pci_bus->pbdev[devfn]; if (dev) { return &dev->iommu_mr; From patchwork Fri Oct 30 18:05:02 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jean-Philippe Brucker X-Patchwork-Id: 320026 Delivered-To: patch@linaro.org Received: by 2002:a92:7b12:0:0:0:0:0 with SMTP id w18csp1640119ilc; Fri, 30 Oct 2020 11:08:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzHZMs35mD4be/nHs8VDOM40d+4FOKlIS+kxSfGC22H/wYRumDx7McFrlR/fAei68yxduzt X-Received: by 2002:a05:620a:16b6:: with SMTP id s22mr3257550qkj.422.1604081312449; Fri, 30 Oct 2020 11:08:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1604081312; cv=none; d=google.com; s=arc-20160816; b=cGrv18MNsmHGGrNz9y1Ve8vHtSRINZumRrwqZS9FSfeVcDCthbi6mwDunrxjFdbhvR 8Vg1nQDIyqgAUqpQPOS4Eez1fwZbn0jnZE2TVmbkh0mj2irr4yzdH9vlbi7/oE+WSqDx QGQwCC263xs6C8YsbMIu6KVnZ7FZYK/eZvvCFvo8texdGecr7X/KUjeFucWIVHPgBkN7 rUz+jM1PUi2sNUYFj3m8ixoZDlYveWEBlq1ffY+qlyTrvybltpupiIoJoAW3P8GNNd0l BbCypTBGJ0S9hvUHp6rQv8cagzKV9BFntdiiIP6SICnD+uvRb6BehY51FFis8SZN8cOf pS3Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=Mw5vfUgd3GO54+QgLOqJSliaESKLNNhHaEh4i2r3qrc=; b=qJVMNBZJEQAVqLbkiE2f0Q0Y9EYAOP37aUyVljF2O9ckX0VCVp/YxX+YFB0NeLoG+g FB3sXRUnDp8Tuv8Yc6PelRQzxjMi3B6DaGKE3SNC2B7J9WDFnJM6Hxxxnxww0McY4EpO 6walsEAME5q2sGG7JVxPmbfH5TBVFI5hjDRaBx2qXNWHGti9N71EZx7Sg2aTyBbvsvpo JzW6T5Z/TrKL6goVEVmzVWGu6mYU9n42ibY77rWjKEdRfxjMiYHz1CEBxFXvVK5ocoQ1 tdmS3IsOMA1k6xzgLBOjgqvfbqcQkVKoucdm+cuXBMdRQtG1zJnx+9pf8Pe8aHmddkYd hzxg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=vU4qTx3G; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id b11si3756463qkk.219.2020.10.30.11.08.32 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 30 Oct 2020 11:08:32 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=vU4qTx3G; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:45762 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kYYpD-0008WM-VT for patch@linaro.org; Fri, 30 Oct 2020 14:08:32 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44842) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kYYmp-00058l-Kj for qemu-devel@nongnu.org; Fri, 30 Oct 2020 14:06:05 -0400 Received: from mail-wm1-x343.google.com ([2a00:1450:4864:20::343]:36204) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kYYmd-0004p4-E4 for qemu-devel@nongnu.org; Fri, 30 Oct 2020 14:06:01 -0400 Received: by mail-wm1-x343.google.com with SMTP id e2so3756362wme.1 for ; Fri, 30 Oct 2020 11:05:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Mw5vfUgd3GO54+QgLOqJSliaESKLNNhHaEh4i2r3qrc=; b=vU4qTx3GvdgOkCNTIIx8G8HEwOfAcbWYzevJTZmgD3BOBeKslRw82JU1nDk02rEF+k ZYa5ClthndZBW++m6t8gDMRjsco/Zxyp/gt1ZRXF5cFikHjy8cz+Yk8FH9StNOHRlQrs fVX4MWIFxDgMi9tUOXfgF2xe+C8mBErSZnIOJ3axK1WGM4BwsyEYOlojI8xojTxFQ02J 36EnOS3JX+rQbbbn/1528tC0zu21tLo2NqEp6k4/Ncwg7UDmQlcg0VbyJFzscTglU38k /qW5KQnwZwDfcOkjnL/EERo9EwxW93GohF/a8QQSbgRmp1EDXkSdjSRP8J9GRC4CKkLL YZ3w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Mw5vfUgd3GO54+QgLOqJSliaESKLNNhHaEh4i2r3qrc=; b=gePScHTyP8XtJvjlPKAthhummKu0ULCAihhtdTmeWCFBdYN7tb2216AXnYMV1n6oER jUKN7fjAO1a28aGMhz2XJUu5x6iLtc2tQBMC+tJxUGy+m/BJb6gwWmoJVohLnpnokFXD RUy2g5KR6J8t9UJu7yOtyHygHgs1hkDDWMhKz05+TmFt3lzCR3uOXAdz5WQXxBEFG9HT m0ml6iVAuudjoycl6jYbvq8+WgyCxJW54hmKnWcme49pLPNbgD3iPnkYGMl/T7RtbPjh 7G4sHq0qAZMf2YONNo+rX4xRN5BcCW7bIXfjW0ju/ZrmwO4PT4OUvROg+wka904Zi9Vf H24w== X-Gm-Message-State: AOAM530NHaEao2iop8d71Ia2d/OCeAvpuHyDPpCRr7LdJhks2OdNVGQf LyTi9a+SRx3g9qnaSdDB3o+pAw== X-Received: by 2002:a7b:c00b:: with SMTP id c11mr4036924wmb.96.1604081148980; Fri, 30 Oct 2020 11:05:48 -0700 (PDT) Received: from localhost.localdomain ([2001:1715:4e26:a7e0:116c:c27a:3e7f:5eaf]) by smtp.gmail.com with ESMTPSA id u3sm10044438wro.33.2020.10.30.11.05.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Oct 2020 11:05:48 -0700 (PDT) From: Jean-Philippe Brucker To: eric.auger@redhat.com, alex.williamson@redhat.com Subject: [PATCH v11 02/10] virtio-iommu: Store memory region in endpoint struct Date: Fri, 30 Oct 2020 19:05:02 +0100 Message-Id: <20201030180510.747225-3-jean-philippe@linaro.org> X-Mailer: git-send-email 2.29.1 In-Reply-To: <20201030180510.747225-1-jean-philippe@linaro.org> References: <20201030180510.747225-1-jean-philippe@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::343; envelope-from=jean-philippe@linaro.org; helo=mail-wm1-x343.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jean-Philippe Brucker , mst@redhat.com, qemu-devel@nongnu.org, peterx@redhat.com, pbonzini@redhat.com, bbhushan2@marvell.com Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Store the memory region associated to each endpoint into the endpoint structure, to allow efficient memory notification on map/unmap. Acked-by: Eric Auger Signed-off-by: Jean-Philippe Brucker --- hw/virtio/virtio-iommu.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) -- 2.29.1 diff --git a/hw/virtio/virtio-iommu.c b/hw/virtio/virtio-iommu.c index 4c8f3909b7d..a5c2d69aad6 100644 --- a/hw/virtio/virtio-iommu.c +++ b/hw/virtio/virtio-iommu.c @@ -49,6 +49,7 @@ typedef struct VirtIOIOMMUDomain { typedef struct VirtIOIOMMUEndpoint { uint32_t id; VirtIOIOMMUDomain *domain; + IOMMUMemoryRegion *iommu_mr; QLIST_ENTRY(VirtIOIOMMUEndpoint) next; } VirtIOIOMMUEndpoint; @@ -137,16 +138,19 @@ static VirtIOIOMMUEndpoint *virtio_iommu_get_endpoint(VirtIOIOMMU *s, uint32_t ep_id) { VirtIOIOMMUEndpoint *ep; + IOMMUMemoryRegion *mr; ep = g_tree_lookup(s->endpoints, GUINT_TO_POINTER(ep_id)); if (ep) { return ep; } - if (!virtio_iommu_mr(s, ep_id)) { + mr = virtio_iommu_mr(s, ep_id); + if (!mr) { return NULL; } ep = g_malloc0(sizeof(*ep)); ep->id = ep_id; + ep->iommu_mr = mr; trace_virtio_iommu_get_endpoint(ep_id); g_tree_insert(s->endpoints, GUINT_TO_POINTER(ep_id), ep); return ep; @@ -910,9 +914,14 @@ static gboolean reconstruct_endpoints(gpointer key, gpointer value, VirtIOIOMMU *s = (VirtIOIOMMU *)data; VirtIOIOMMUDomain *d = (VirtIOIOMMUDomain *)value; VirtIOIOMMUEndpoint *iter; + IOMMUMemoryRegion *mr; QLIST_FOREACH(iter, &d->endpoint_list, next) { + mr = virtio_iommu_mr(s, iter->id); + assert(mr); + iter->domain = d; + iter->iommu_mr = mr; g_tree_insert(s->endpoints, GUINT_TO_POINTER(iter->id), iter); } return false; /* continue the domain traversal */ From patchwork Fri Oct 30 18:05:03 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jean-Philippe Brucker X-Patchwork-Id: 316472 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1530DC00A89 for ; Fri, 30 Oct 2020 18:11:00 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 6E376206E5 for ; Fri, 30 Oct 2020 18:10:59 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="xlBHFdmh" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6E376206E5 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:54890 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kYYra-0003vQ-EP for qemu-devel@archiver.kernel.org; Fri, 30 Oct 2020 14:10:58 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44824) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kYYmo-000587-1f for qemu-devel@nongnu.org; Fri, 30 Oct 2020 14:06:03 -0400 Received: from mail-wr1-x42e.google.com ([2a00:1450:4864:20::42e]:45394) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kYYmf-0004q3-2V for qemu-devel@nongnu.org; Fri, 30 Oct 2020 14:05:58 -0400 Received: by mail-wr1-x42e.google.com with SMTP id a9so7413718wrg.12 for ; Fri, 30 Oct 2020 11:05:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Ej1fodcMaFb0u/aG6D5WFwOmMShNXQ/JZRK7Jgg8zcU=; b=xlBHFdmhXjztVOxAH++ajnfav437zwW1ucZZwyrJKmfe8GNEdDAGnDR+ZkyT6SVz/v esCnG92y5+82iM778VESCuSyABhC+Bjse0dy3G8LYRYP9GN7N5NWyWmAGdGbav9cw/2W E+lJxMXFZuo4ENIntUCbHWEGxDBv5CwF0nuxhjoNM6L2p8uYoSCQpgXzKjLuWaAv7BTg RlG1eA2NwkLyf5QhDpxfpWrM8Q8k5FHNYbgcSTNgSdz/jUTV52zUMID+Uxpa5sOHkCos cLuBl5Y/1xiaU574aaBeXQh4h5R8DVY4JyoQIPDsws/GltTK4PiEomQfs5epJkFy3Arz DLHw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Ej1fodcMaFb0u/aG6D5WFwOmMShNXQ/JZRK7Jgg8zcU=; b=ual1/JxYYhxFZHt42anllGgvrmLndH/C638zvzCV4950IqeoViTIhY6nrrfZPOOLnP 205D1i+0uia5DYL3tXM3KDPXMh2/wh8BlBadQKNZR3Cox4+hRc//FoEIwepU9rJhL0Wp Bz38B98LEoFeC0lxN3eKfu9/Xjs0sBbYOiicIUzxLhWOpWu3+IIHf3Q7KHPhODRUruPA 7COcdNF0Ks0SiCPse5/xO0baji8jgh8FfG6d7dpYZy49PLMMjinIhvqfkzzqwt/XXufO w5U8f6qA4VyVetFc9oPTfpq2QztwJgVdAkCMuR6QCDMHWi1EnaFvLc0mJHcKLuAKlSUt Py0Q== X-Gm-Message-State: AOAM532tH9SQMmd42Eveb/Y3DEC8WaqW+ILOgqdXw8qG6kK6aDe21Qbd uksasJtuDEKflfqjlgKkeO2Stg== X-Google-Smtp-Source: ABdhPJzTChbKCWnZ4AHdX0vjIlWD00tnrSOJrTIdekAes8OFpua+LUu3B2xS/66oyVhrrZdxhSbNHw== X-Received: by 2002:adf:ec47:: with SMTP id w7mr4714098wrn.253.1604081150164; Fri, 30 Oct 2020 11:05:50 -0700 (PDT) Received: from localhost.localdomain ([2001:1715:4e26:a7e0:116c:c27a:3e7f:5eaf]) by smtp.gmail.com with ESMTPSA id u3sm10044438wro.33.2020.10.30.11.05.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Oct 2020 11:05:49 -0700 (PDT) From: Jean-Philippe Brucker To: eric.auger@redhat.com, alex.williamson@redhat.com Subject: [PATCH v11 03/10] virtio-iommu: Add memory notifiers for map/unmap Date: Fri, 30 Oct 2020 19:05:03 +0100 Message-Id: <20201030180510.747225-4-jean-philippe@linaro.org> X-Mailer: git-send-email 2.29.1 In-Reply-To: <20201030180510.747225-1-jean-philippe@linaro.org> References: <20201030180510.747225-1-jean-philippe@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::42e; envelope-from=jean-philippe@linaro.org; helo=mail-wr1-x42e.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jean-Philippe Brucker , mst@redhat.com, qemu-devel@nongnu.org, peterx@redhat.com, pbonzini@redhat.com, bbhushan2@marvell.com Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" From: Bharat Bhushan Extend VIRTIO_IOMMU_T_MAP/UNMAP request to notify memory listeners. It will call VFIO notifier to map/unmap regions in the physical IOMMU. Signed-off-by: Bharat Bhushan Signed-off-by: Eric Auger Signed-off-by: Jean-Philippe Brucker --- v11: * Forward permissions from the MAP request * Don't notify MMIO mappings --- hw/virtio/virtio-iommu.c | 56 ++++++++++++++++++++++++++++++++++++++++ hw/virtio/trace-events | 2 ++ 2 files changed, 58 insertions(+) diff --git a/hw/virtio/virtio-iommu.c b/hw/virtio/virtio-iommu.c index a5c2d69aad6..7dd15c5eacd 100644 --- a/hw/virtio/virtio-iommu.c +++ b/hw/virtio/virtio-iommu.c @@ -125,6 +125,51 @@ static gint interval_cmp(gconstpointer a, gconstpointer b, gpointer user_data) } } +static void virtio_iommu_notify_map(IOMMUMemoryRegion *mr, hwaddr virt_start, + hwaddr virt_end, hwaddr paddr, + uint32_t flags) +{ + IOMMUTLBEntry entry; + IOMMUAccessFlags perm = IOMMU_ACCESS_FLAG(flags & VIRTIO_IOMMU_MAP_F_READ, + flags & VIRTIO_IOMMU_MAP_F_WRITE); + + if (!(mr->iommu_notify_flags & IOMMU_NOTIFIER_MAP) || + (flags & VIRTIO_IOMMU_MAP_F_MMIO) || !perm) { + return; + } + + trace_virtio_iommu_notify_map(mr->parent_obj.name, virt_start, virt_end, + paddr, perm); + + entry.target_as = &address_space_memory; + entry.addr_mask = virt_end - virt_start; + entry.iova = virt_start; + entry.perm = perm; + entry.translated_addr = paddr; + + memory_region_notify_iommu(mr, 0, entry); +} + +static void virtio_iommu_notify_unmap(IOMMUMemoryRegion *mr, hwaddr virt_start, + hwaddr virt_end) +{ + IOMMUTLBEntry entry; + + if (!(mr->iommu_notify_flags & IOMMU_NOTIFIER_UNMAP)) { + return; + } + + trace_virtio_iommu_notify_unmap(mr->parent_obj.name, virt_start, virt_end); + + entry.target_as = &address_space_memory; + entry.addr_mask = virt_end - virt_start; + entry.iova = virt_start; + entry.perm = IOMMU_NONE; + entry.translated_addr = 0; + + memory_region_notify_iommu(mr, 0, entry); +} + static void virtio_iommu_detach_endpoint_from_domain(VirtIOIOMMUEndpoint *ep) { if (!ep->domain) { @@ -315,6 +360,7 @@ static int virtio_iommu_map(VirtIOIOMMU *s, VirtIOIOMMUDomain *domain; VirtIOIOMMUInterval *interval; VirtIOIOMMUMapping *mapping; + VirtIOIOMMUEndpoint *ep; if (flags & ~VIRTIO_IOMMU_MAP_F_MASK) { return VIRTIO_IOMMU_S_INVAL; @@ -344,6 +390,11 @@ static int virtio_iommu_map(VirtIOIOMMU *s, g_tree_insert(domain->mappings, interval, mapping); + QLIST_FOREACH(ep, &domain->endpoint_list, next) { + virtio_iommu_notify_map(ep->iommu_mr, virt_start, virt_end, phys_start, + flags); + } + return VIRTIO_IOMMU_S_OK; } @@ -356,6 +407,7 @@ static int virtio_iommu_unmap(VirtIOIOMMU *s, VirtIOIOMMUMapping *iter_val; VirtIOIOMMUInterval interval, *iter_key; VirtIOIOMMUDomain *domain; + VirtIOIOMMUEndpoint *ep; int ret = VIRTIO_IOMMU_S_OK; trace_virtio_iommu_unmap(domain_id, virt_start, virt_end); @@ -373,6 +425,10 @@ static int virtio_iommu_unmap(VirtIOIOMMU *s, uint64_t current_high = iter_key->high; if (interval.low <= current_low && interval.high >= current_high) { + QLIST_FOREACH(ep, &domain->endpoint_list, next) { + virtio_iommu_notify_unmap(ep->iommu_mr, current_low, + current_high); + } g_tree_remove(domain->mappings, iter_key); trace_virtio_iommu_unmap_done(domain_id, current_low, current_high); } else { diff --git a/hw/virtio/trace-events b/hw/virtio/trace-events index cf1e59de302..b87a3974069 100644 --- a/hw/virtio/trace-events +++ b/hw/virtio/trace-events @@ -106,6 +106,8 @@ virtio_iommu_put_domain(uint32_t domain_id) "Free domain=%d" virtio_iommu_translate_out(uint64_t virt_addr, uint64_t phys_addr, uint32_t sid) "0x%"PRIx64" -> 0x%"PRIx64 " for sid=%d" virtio_iommu_report_fault(uint8_t reason, uint32_t flags, uint32_t endpoint, uint64_t addr) "FAULT reason=%d flags=%d endpoint=%d address =0x%"PRIx64 virtio_iommu_fill_resv_property(uint32_t devid, uint8_t subtype, uint64_t start, uint64_t end) "dev= %d, type=%d start=0x%"PRIx64" end=0x%"PRIx64 +virtio_iommu_notify_map(const char *name, uint64_t virt_start, uint64_t virt_end, uint64_t phys_start, uint32_t flags) "mr=%s virt_start=0x%"PRIx64" virt_end=0x%"PRIx64" phys_start=0x%"PRIx64" flags=%d" +virtio_iommu_notify_unmap(const char *name, uint64_t virt_start, uint64_t virt_end) "mr=%s virt_start=0x%"PRIx64" virt_end=0x%"PRIx64 # virtio-mem.c virtio_mem_send_response(uint16_t type) "type=%" PRIu16 From patchwork Fri Oct 30 18:05:04 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jean-Philippe Brucker X-Patchwork-Id: 320022 Delivered-To: patch@linaro.org Received: by 2002:a92:7b12:0:0:0:0:0 with SMTP id w18csp1638509ilc; Fri, 30 Oct 2020 11:06:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxpVOLA8dkFFv57p4gNUI3kSb+arbfxjj8XtSmj2gpajn9p2Eo+bkTgyUxNCuVCplL8giT5 X-Received: by 2002:aed:31e3:: with SMTP id 90mr3445294qth.300.1604081201861; Fri, 30 Oct 2020 11:06:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1604081201; cv=none; d=google.com; s=arc-20160816; b=sKAk4sn9DpA/7+9EBe5CtsDSBba+iXIH8Pua7D0KpdsLVTbG9PLeJU0BFGr3ANSePm vveSdPrTmZ+tY9U8DsFfw+jXE5BrCBdeD+QF0aLXUspllYzO9WpQjaDuUs12xGOSeIrK N8SH+IaCy3LlA5RFscwwLwpRO6XpdmxTApI7CwWBD6EvGKbhqMDl0ye+caZBigfndXGq 0Kx1s4dqmXrfgIDqjzCQcI7NSmYvaRHHOlGSq7dOwawsFqdNnSERdr7qBKg5tS9ECdaO LLwZnc1rlAZPlH4g9D/FaOFAWYQK2AtxcSoaIlrKXvoRniQttTaIoyXQeGIQZ3l9bkyo 502g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=Eu3dQfIpFEu6odtk6adJYWVijDRkJcSgv2bG/hnjotM=; b=EC96yLTmtpDqa7pvtohTwgrnureby8mK4id/DwWuc2PymF+ZUgF7QygHt3Kk7u8o0J ABeLTEYyCmL+f/uoddbLuUaGL8vxENJjyxteoI5c/2U9eptv3OyQKUUi/0HEZlnLj2l4 K8AkqG2TrB6VsMVfofS/wVqgHSELAxevxhXEb2FWcOwC9KZ7Fx+l+jnuzRIPkwtb9Knr 0h2it3y7wKclPHJdXt3OolNtW9i9BzS3S/DylcHXM+sl6QkSeo5GRBOCukxLtZyN0Fbv X2ALRhlOWZ740ib5h8xvR7o9Ivr52XZZ4yNeq0l0haZcetDpwcQa5TyQbmnJ2UD1k3r9 3VAQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=XrBSSSMP; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id y1si4057324qtd.203.2020.10.30.11.06.41 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 30 Oct 2020 11:06:41 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=XrBSSSMP; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:37468 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kYYnR-000586-C2 for patch@linaro.org; Fri, 30 Oct 2020 14:06:41 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44802) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kYYml-00056t-7s for qemu-devel@nongnu.org; Fri, 30 Oct 2020 14:05:59 -0400 Received: from mail-wr1-x442.google.com ([2a00:1450:4864:20::442]:38448) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kYYmf-0004qM-2l for qemu-devel@nongnu.org; Fri, 30 Oct 2020 14:05:56 -0400 Received: by mail-wr1-x442.google.com with SMTP id n18so7437728wrs.5 for ; Fri, 30 Oct 2020 11:05:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Eu3dQfIpFEu6odtk6adJYWVijDRkJcSgv2bG/hnjotM=; b=XrBSSSMPcfWhvaAs8QTr5lBqsN4ERI5rf+hGVeIS5zfAtMFkPI6SICPchaJ2Qz2Sw8 cCra2I84SkoRrWOC/6LBDtAnpZrF623k3vGQ7u7dzccO4FbimAP6IWajfpLUrUe1T4up 33xU59uBRu41iFm0FHx0MQpP2nFgvu9PXUxLlZmwqZno//LI02YRC6x7MgjpZNA69m90 r36iQtBo9DOEmpwcvLev6wkmlQMWKIus7E3y56+zhley0X50nLKc85Wl4nr6rOw4L8/d 3ys44RB5elYj5DlkxnmxDynhZh1ie5L0echLmU0Sx7Sy0Ay8N6q3q9nW6u1HPUEeim7X lv1g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Eu3dQfIpFEu6odtk6adJYWVijDRkJcSgv2bG/hnjotM=; b=GHxTfKvroq58hTQV+YOiyCbJUl1o1adlHuoOmbJSrN+Yo6EkskS/270Cz1tdikSdGl Qou5F0E6LIqGIpeyM09phTJpSr8DiV1+4Gihv1dnI/uOzQ/QpfkoQyPS2uBqkp5gw+QT uqVKAlthU46Egka9JPchrm9QuRLXxMmX6HXs2PQKnppYcTUNZhMYDzl/7rSYi3Rv4tSo ji5yZ/RW0/yFZdLCjWzPos47qo4F/Lp1jMI8hDFSg4YeZlIn5UCy7aFw10Ab2gqELFVb 6Mi/H8dhWMUx3hnW0598aH0Wo9qngF0oFEOpuE8sDQZfh3vhNjcPfkRjSctwmLIzcMqz E/uA== X-Gm-Message-State: AOAM531xhMj2WqhPe/x625/wTrXZi5UDS4VgSs5QqetPw7eaTG/DEM5Q sMwf+L/osHXVlykgp5xMR0DzSA== X-Received: by 2002:a05:6000:83:: with SMTP id m3mr4465518wrx.147.1604081151314; Fri, 30 Oct 2020 11:05:51 -0700 (PDT) Received: from localhost.localdomain ([2001:1715:4e26:a7e0:116c:c27a:3e7f:5eaf]) by smtp.gmail.com with ESMTPSA id u3sm10044438wro.33.2020.10.30.11.05.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Oct 2020 11:05:50 -0700 (PDT) From: Jean-Philippe Brucker To: eric.auger@redhat.com, alex.williamson@redhat.com Subject: [PATCH v11 04/10] virtio-iommu: Call memory notifiers in attach/detach Date: Fri, 30 Oct 2020 19:05:04 +0100 Message-Id: <20201030180510.747225-5-jean-philippe@linaro.org> X-Mailer: git-send-email 2.29.1 In-Reply-To: <20201030180510.747225-1-jean-philippe@linaro.org> References: <20201030180510.747225-1-jean-philippe@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::442; envelope-from=jean-philippe@linaro.org; helo=mail-wr1-x442.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jean-Philippe Brucker , mst@redhat.com, qemu-devel@nongnu.org, peterx@redhat.com, pbonzini@redhat.com, bbhushan2@marvell.com Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Bharat Bhushan Call the memory notifiers when attaching an endpoint to a domain, to replay existing mappings, and when detaching the endpoint, to remove all mappings. Signed-off-by: Bharat Bhushan Signed-off-by: Jean-Philippe Brucker --- v11: Pass mapping permissions to the notifiers --- hw/virtio/virtio-iommu.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) -- 2.29.1 diff --git a/hw/virtio/virtio-iommu.c b/hw/virtio/virtio-iommu.c index 7dd15c5eacd..7b648923517 100644 --- a/hw/virtio/virtio-iommu.c +++ b/hw/virtio/virtio-iommu.c @@ -170,11 +170,39 @@ static void virtio_iommu_notify_unmap(IOMMUMemoryRegion *mr, hwaddr virt_start, memory_region_notify_iommu(mr, 0, entry); } +static gboolean virtio_iommu_notify_unmap_cb(gpointer key, gpointer value, + gpointer data) +{ + VirtIOIOMMUInterval *interval = (VirtIOIOMMUInterval *) key; + IOMMUMemoryRegion *mr = (IOMMUMemoryRegion *) data; + + virtio_iommu_notify_unmap(mr, interval->low, interval->high); + + return false; +} + +static gboolean virtio_iommu_notify_map_cb(gpointer key, gpointer value, + gpointer data) +{ + VirtIOIOMMUMapping *mapping = (VirtIOIOMMUMapping *) value; + VirtIOIOMMUInterval *interval = (VirtIOIOMMUInterval *) key; + IOMMUMemoryRegion *mr = (IOMMUMemoryRegion *) data; + + virtio_iommu_notify_map(mr, interval->low, interval->high, + mapping->phys_addr, mapping->flags); + + return false; +} + static void virtio_iommu_detach_endpoint_from_domain(VirtIOIOMMUEndpoint *ep) { + VirtIOIOMMUDomain *domain = ep->domain; + if (!ep->domain) { return; } + g_tree_foreach(domain->mappings, virtio_iommu_notify_unmap_cb, + ep->iommu_mr); QLIST_REMOVE(ep, next); ep->domain = NULL; } @@ -317,6 +345,10 @@ static int virtio_iommu_attach(VirtIOIOMMU *s, ep->domain = domain; + /* Replay domain mappings on the associated memory region */ + g_tree_foreach(domain->mappings, virtio_iommu_notify_map_cb, + ep->iommu_mr); + return VIRTIO_IOMMU_S_OK; } From patchwork Fri Oct 30 18:05:05 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jean-Philippe Brucker X-Patchwork-Id: 320024 Delivered-To: patch@linaro.org Received: by 2002:a92:7b12:0:0:0:0:0 with SMTP id w18csp1638614ilc; Fri, 30 Oct 2020 11:06:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxWRLIbrD3gGqWcr8Auu4GLO8PgUhBwQ59xkfVUP+plKSdr+5DYyPz7m1lqlTUWwBONmpwM X-Received: by 2002:a67:ea46:: with SMTP id r6mr7352358vso.40.1604081208896; Fri, 30 Oct 2020 11:06:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1604081208; cv=none; d=google.com; s=arc-20160816; b=HliSIE5YeQIjAI0vxcXhYDm67iL69MlxfXqZHMYaRIcp4We2i3NezKSuu/GEzGmBWA WFS+KQZcLbp8JuBOV7UMFf2NqyHjcxz16p0tMW+QLa0GpnbmqrdR5c3d4MoQsb3ethOP /FHW8W8NU8HegXc15xx44XlappGeWeRCoJlB6BgzG1F/IDXHw7G49hEbLR5d8y6HPdMi uoilLxQ3LGfkNCBSRT1iIVdY6anpxu/l5fkCnKg3N4OXtNkBb5I1DET7wlQvHdoDKuK2 MzKQjPc0d13Fu+DHg1Bihgma/0qMehNcu+coyFoPSThhJN0fYbmLKx2H3UjFmtQzHG/s /BgQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=CgsfmPEJUSprxXHS+NXfbp1mG3kP5a7TnQouVrlttaA=; b=YbmmLFwEdCq3f/ZVAXbWjidexKzvQm/Z7yju4eEWfZ0Zg+uj89opMqQZo5fuLlOg7o WZ7BKE9iAiGkMQndRDIEMgMhy13mkFxRxfOAL0fygsCUKHSKaGAMclTzeh6Rc7ifyHD4 tRJtQ2utTxiwUV1omUAHER8Es9pYp1vXr75puEavhMnSVlhmyRcM4GzN8Pix7bnzZLbh 2rJ2CJZTle89SorOKYuBg3uAKAPKcQUrV81tsem11+uLpekxqtWiaA/ZKd8nrgxh+nZe jXOJrgdrFafkLDhUiywFtQHwdtzibW4BlJbyDpbgUw4hNzB7BMTuchDj7wC7ot3NlDh5 n/YQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=nasy0kWm; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id h13si1236232vsq.319.2020.10.30.11.06.48 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 30 Oct 2020 11:06:48 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=nasy0kWm; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:37658 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kYYnY-0005DF-A0 for patch@linaro.org; Fri, 30 Oct 2020 14:06:48 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44844) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kYYmp-00058u-N3 for qemu-devel@nongnu.org; Fri, 30 Oct 2020 14:06:05 -0400 Received: from mail-wm1-x329.google.com ([2a00:1450:4864:20::329]:39038) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kYYmi-0004qU-U5 for qemu-devel@nongnu.org; Fri, 30 Oct 2020 14:06:03 -0400 Received: by mail-wm1-x329.google.com with SMTP id d3so3744603wma.4 for ; Fri, 30 Oct 2020 11:05:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=CgsfmPEJUSprxXHS+NXfbp1mG3kP5a7TnQouVrlttaA=; b=nasy0kWmxeuCUKXqITCACoFBLGFhObiWEANa57TLgLljdkPGx1puu45zIc03VCDaWi yKejtuMHuAi16mfQ86p8C3hfNTMO6yr4rx3K9puCXMq97gN5JCF/rcPesHsolj+Y41Cd VAxpl51DW87YfdtfqNuk5mGynURvRTmewO/Qf4H3zheNjIi3BuzvXJSnUqEdmyoXVKoV UsU8pDB4KYsHUtZNUrwCU3v3J2O1vycrgxRh3vm7AquA4SnU1vWfdXgKfJ5ivHPNHZn2 3NgBS0WUDOGViIDW5EIIkyt0gBv4j298dVV/RBhgpzeALTvq7rhcKU6nuxtS5hDChY/q kiNg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=CgsfmPEJUSprxXHS+NXfbp1mG3kP5a7TnQouVrlttaA=; b=UtnG6/Hk/Zpz+1BksFMepG3UF2a96AcXqdGLLJ7OcEqD0cVq9AHWLPkCF2L4AZ3lLw 06rVy6S2WhydsqTEP6f8smq9MmBiSG11dDTy+sm8Ec6fzmEfKJGYJ1XIGJ7cNK1ZWc1i NeVsxW9dt8oA44MMNIdTyZLgx6wKcY9XRpELgpQzJkWDbc3NC5x/cHqOKYCZNb0b5X2x ZByODBdahiWjzj6mhlFOLHDpq5TMObnxiN9dZ4t44xnCPwYeMSsVabm99eZ++A4p5LrZ FAgNhjZ344ycGcFaH+HeUP3rXVB0DItEGux3QIy2GjeKYhDTM8//WDRjZlpN8sAp+W2h sW6A== X-Gm-Message-State: AOAM530oiqEJ9ZL6b0X7RvGOMBSj8uk7eNxHiTeN9u+UFC1I5W1lPJHO x1l+Sxfiy4Zm62tN9Xn2vNiNEw== X-Received: by 2002:a1c:ddd7:: with SMTP id u206mr3464085wmg.27.1604081152746; Fri, 30 Oct 2020 11:05:52 -0700 (PDT) Received: from localhost.localdomain ([2001:1715:4e26:a7e0:116c:c27a:3e7f:5eaf]) by smtp.gmail.com with ESMTPSA id u3sm10044438wro.33.2020.10.30.11.05.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Oct 2020 11:05:51 -0700 (PDT) From: Jean-Philippe Brucker To: eric.auger@redhat.com, alex.williamson@redhat.com Subject: [PATCH v11 05/10] virtio-iommu: Add replay() memory region callback Date: Fri, 30 Oct 2020 19:05:05 +0100 Message-Id: <20201030180510.747225-6-jean-philippe@linaro.org> X-Mailer: git-send-email 2.29.1 In-Reply-To: <20201030180510.747225-1-jean-philippe@linaro.org> References: <20201030180510.747225-1-jean-philippe@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::329; envelope-from=jean-philippe@linaro.org; helo=mail-wm1-x329.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jean-Philippe Brucker , mst@redhat.com, qemu-devel@nongnu.org, peterx@redhat.com, pbonzini@redhat.com, bbhushan2@marvell.com Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Bharat Bhushan Implement the replay callback to setup all mappings for a new memory region. Signed-off-by: Bharat Bhushan Signed-off-by: Jean-Philippe Brucker --- v11: Don't notify unmap before map, add permission flags --- hw/virtio/virtio-iommu.c | 40 ++++++++++++++++++++++++++++++++++++++++ hw/virtio/trace-events | 1 + 2 files changed, 41 insertions(+) -- 2.29.1 diff --git a/hw/virtio/virtio-iommu.c b/hw/virtio/virtio-iommu.c index 7b648923517..985257c88fd 100644 --- a/hw/virtio/virtio-iommu.c +++ b/hw/virtio/virtio-iommu.c @@ -847,6 +847,45 @@ static gint int_cmp(gconstpointer a, gconstpointer b, gpointer user_data) return (ua > ub) - (ua < ub); } +static gboolean virtio_iommu_remap(gpointer key, gpointer value, gpointer data) +{ + VirtIOIOMMUMapping *mapping = (VirtIOIOMMUMapping *) value; + VirtIOIOMMUInterval *interval = (VirtIOIOMMUInterval *) key; + IOMMUMemoryRegion *mr = (IOMMUMemoryRegion *) data; + + trace_virtio_iommu_remap(mr->parent_obj.name, interval->low, interval->high, + mapping->phys_addr); + virtio_iommu_notify_map(mr, interval->low, interval->high, + mapping->phys_addr, mapping->flags); + return false; +} + +static void virtio_iommu_replay(IOMMUMemoryRegion *mr, IOMMUNotifier *n) +{ + IOMMUDevice *sdev = container_of(mr, IOMMUDevice, iommu_mr); + VirtIOIOMMU *s = sdev->viommu; + uint32_t sid; + VirtIOIOMMUEndpoint *ep; + + sid = virtio_iommu_get_bdf(sdev); + + qemu_mutex_lock(&s->mutex); + + if (!s->endpoints) { + goto unlock; + } + + ep = 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 = VIRTIO_DEVICE(dev); @@ -1076,6 +1115,7 @@ static void virtio_iommu_memory_region_class_init(ObjectClass *klass, IOMMUMemoryRegionClass *imrc = IOMMU_MEMORY_REGION_CLASS(klass); imrc->translate = virtio_iommu_translate; + imrc->replay = virtio_iommu_replay; } static const TypeInfo virtio_iommu_info = { diff --git a/hw/virtio/trace-events b/hw/virtio/trace-events index b87a3974069..ea3c3b25ad7 100644 --- a/hw/virtio/trace-events +++ b/hw/virtio/trace-events @@ -108,6 +108,7 @@ virtio_iommu_report_fault(uint8_t reason, uint32_t flags, uint32_t endpoint, uin virtio_iommu_fill_resv_property(uint32_t devid, uint8_t subtype, uint64_t start, uint64_t end) "dev= %d, type=%d start=0x%"PRIx64" end=0x%"PRIx64 virtio_iommu_notify_map(const char *name, uint64_t virt_start, uint64_t virt_end, uint64_t phys_start, uint32_t flags) "mr=%s virt_start=0x%"PRIx64" virt_end=0x%"PRIx64" phys_start=0x%"PRIx64" flags=%d" virtio_iommu_notify_unmap(const char *name, uint64_t virt_start, uint64_t virt_end) "mr=%s virt_start=0x%"PRIx64" virt_end=0x%"PRIx64 +virtio_iommu_remap(const char *name, uint64_t virt_start, uint64_t virt_end, uint64_t phys_start) "mr=%s virt_start=0x%"PRIx64" virt_end=0x%"PRIx64" phys_start=0x%"PRIx64 # virtio-mem.c virtio_mem_send_response(uint16_t type) "type=%" PRIu16 From patchwork Fri Oct 30 18:05:06 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jean-Philippe Brucker X-Patchwork-Id: 316475 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D58B4C00A89 for ; Fri, 30 Oct 2020 18:07:40 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 4C79F22273 for ; Fri, 30 Oct 2020 18:07:40 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="IgRfTVVW" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4C79F22273 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:41566 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kYYoN-0006p7-71 for qemu-devel@archiver.kernel.org; Fri, 30 Oct 2020 14:07:39 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44858) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kYYmr-00059C-VL for qemu-devel@nongnu.org; Fri, 30 Oct 2020 14:06:07 -0400 Received: from mail-wm1-x32a.google.com ([2a00:1450:4864:20::32a]:37654) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kYYmj-0004qj-92 for qemu-devel@nongnu.org; Fri, 30 Oct 2020 14:06:05 -0400 Received: by mail-wm1-x32a.google.com with SMTP id c16so3755205wmd.2 for ; Fri, 30 Oct 2020 11:05:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=CcqYYL+qDjoLJPUdpp6J8eO2OBjnLk8kyGHylqAsx/4=; b=IgRfTVVWoxTFkqJnX3D3RFI9lwDRshD+Ef3rxGCo7sBeRdJjXpqoXxSzJE8sgs/WmE Z5L2X3yXCSonnPdPOdFb6JWn7Q3ExZaJV7HxXWDborLoPUxoWrKHniGL9HOrPzWqpznU 4Juorja+br0h3jKNNjyTb9z1v1NAaaim+/lMaHQdlLUJH7MLhjl4ReJfSxK+a9pDKy9L MTPx8SoKHRj1cDtQV6Rvg/9z43q59zQJmz9txOIoOdhxI42PQ7PoaEDGwV7Cc5otLjIz 1MfFh9HjKco7T3yjUEZR4rGIcIoSB1yzqybW2ZF0YR1Dvw33S/RG9heqRu8UUGnE4V/G pGLA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=CcqYYL+qDjoLJPUdpp6J8eO2OBjnLk8kyGHylqAsx/4=; b=ipePdVsm9QpN6vWKdOl8xdggYg8x/R8FpdX3Yxxk+RjQJRq701sAVrgik+Prx1wjOJ UzcDmDbrCB5m6nk1YnV01u8F+Klc+/ir5HkmxO0NYIXZXoZXplJ0YdGWg5fhBXoqvsKq guts13GUr6KtZ48DopJDjOhBB1eIbQ+h7wR55XPhG41RZc+yX3wO7BN8cJwDGuxvCGtA 9luYYxb4Lp4IPQUzyuYibfuE6a6GV0RyEm/5gxmwCPhOxPahiV8koGJdX+2j4Bboe1bN EPFmALV/xX1AMHOBnpQIndAhezqhqf3k3UzGu0XHCA7Iij54ymd0Xt0vcfvFAlagZKzT Pl8g== X-Gm-Message-State: AOAM531neQD+BL3WptKMrh0DOIjiokTwRLkTdnDUVIo/xbJd8XLifPQA MFMxwgZS7FENJWUwR3ylGQT/yg== X-Google-Smtp-Source: ABdhPJya4irfSZJRDCkzpFm7tEZrkFmRZi94s59f3BkhZn0L+LftDSGq2fk/Hx/u8mDKGAbjikiv1Q== X-Received: by 2002:a05:600c:22cc:: with SMTP id 12mr2040903wmg.9.1604081153958; Fri, 30 Oct 2020 11:05:53 -0700 (PDT) Received: from localhost.localdomain ([2001:1715:4e26:a7e0:116c:c27a:3e7f:5eaf]) by smtp.gmail.com with ESMTPSA id u3sm10044438wro.33.2020.10.30.11.05.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Oct 2020 11:05:53 -0700 (PDT) From: Jean-Philippe Brucker To: eric.auger@redhat.com, alex.williamson@redhat.com Subject: [PATCH v11 06/10] virtio-iommu: Add notify_flag_changed() memory region callback Date: Fri, 30 Oct 2020 19:05:06 +0100 Message-Id: <20201030180510.747225-7-jean-philippe@linaro.org> X-Mailer: git-send-email 2.29.1 In-Reply-To: <20201030180510.747225-1-jean-philippe@linaro.org> References: <20201030180510.747225-1-jean-philippe@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::32a; envelope-from=jean-philippe@linaro.org; helo=mail-wm1-x32a.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jean-Philippe Brucker , mst@redhat.com, qemu-devel@nongnu.org, peterx@redhat.com, pbonzini@redhat.com, bbhushan2@marvell.com Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" From: Bharat Bhushan Add notify_flag_changed() to notice when memory listeners are added and removed. Acked-by: Eric Auger Signed-off-by: Bharat Bhushan Signed-off-by: Jean-Philippe Brucker --- v11: improve tracepoint string --- hw/virtio/virtio-iommu.c | 14 ++++++++++++++ hw/virtio/trace-events | 2 ++ 2 files changed, 16 insertions(+) diff --git a/hw/virtio/virtio-iommu.c b/hw/virtio/virtio-iommu.c index 985257c88fd..78e07aa40a5 100644 --- a/hw/virtio/virtio-iommu.c +++ b/hw/virtio/virtio-iommu.c @@ -886,6 +886,19 @@ unlock: qemu_mutex_unlock(&s->mutex); } +static int virtio_iommu_notify_flag_changed(IOMMUMemoryRegion *iommu_mr, + IOMMUNotifierFlag old, + IOMMUNotifierFlag new, + Error **errp) +{ + if (old == IOMMU_NOTIFIER_NONE) { + trace_virtio_iommu_notify_flag_add(iommu_mr->parent_obj.name); + } else if (new == IOMMU_NOTIFIER_NONE) { + trace_virtio_iommu_notify_flag_del(iommu_mr->parent_obj.name); + } + return 0; +} + static void virtio_iommu_device_realize(DeviceState *dev, Error **errp) { VirtIODevice *vdev = VIRTIO_DEVICE(dev); @@ -1116,6 +1129,7 @@ static void virtio_iommu_memory_region_class_init(ObjectClass *klass, imrc->translate = virtio_iommu_translate; imrc->replay = virtio_iommu_replay; + imrc->notify_flag_changed = virtio_iommu_notify_flag_changed; } static const TypeInfo virtio_iommu_info = { diff --git a/hw/virtio/trace-events b/hw/virtio/trace-events index ea3c3b25ad7..982d0002a65 100644 --- a/hw/virtio/trace-events +++ b/hw/virtio/trace-events @@ -109,6 +109,8 @@ virtio_iommu_fill_resv_property(uint32_t devid, uint8_t subtype, uint64_t start, virtio_iommu_notify_map(const char *name, uint64_t virt_start, uint64_t virt_end, uint64_t phys_start, uint32_t flags) "mr=%s virt_start=0x%"PRIx64" virt_end=0x%"PRIx64" phys_start=0x%"PRIx64" flags=%d" virtio_iommu_notify_unmap(const char *name, uint64_t virt_start, uint64_t virt_end) "mr=%s virt_start=0x%"PRIx64" virt_end=0x%"PRIx64 virtio_iommu_remap(const char *name, uint64_t virt_start, uint64_t virt_end, uint64_t phys_start) "mr=%s virt_start=0x%"PRIx64" virt_end=0x%"PRIx64" phys_start=0x%"PRIx64 +virtio_iommu_notify_flag_add(const char *name) "add notifier to mr %s" +virtio_iommu_notify_flag_del(const char *name) "del notifier from mr %s" # virtio-mem.c virtio_mem_send_response(uint16_t type) "type=%" PRIu16 From patchwork Fri Oct 30 18:05:07 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jean-Philippe Brucker X-Patchwork-Id: 320028 Delivered-To: patch@linaro.org Received: by 2002:a92:7b12:0:0:0:0:0 with SMTP id w18csp1641403ilc; Fri, 30 Oct 2020 11:10:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz3oD2EAlz+78KIKSeZrMQf/vrqJCyMv+7Cy3qZbhu1Bj+JsRNM5/p0lvzpyoJfziDciatb X-Received: by 2002:a0c:bd2d:: with SMTP id m45mr10703192qvg.36.1604081404740; Fri, 30 Oct 2020 11:10:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1604081404; cv=none; d=google.com; s=arc-20160816; b=dA0xgzrK8xY65U0Kp+3PVMuJfx0lgxHGbAb9AGG/Pi0n6NV36ecOXarW18uIWTTAVl EJ4FinFL0RoNGhoZ6lyLx6ClTQA6pV0dv16VKG3MbniBZ8IUMWV+Jofbu6ov1eES1tdp TJAiS0vdEpCuj2p0CccsJDulPQM6EorSL+7m1vNvcRHS2MdsVBzcD3wkWLua5/aoKkk9 p5TqGQPhCUaPnbQ4sKaqVU2lc62j4ZrTm1KL8kNhrwY4uyFhDHav+eSqxBcjrrpwywKH yS8r2hVB5Ne4sk+nMPgru+9pW1DKqXZVn6xFlj3OXk+I626lwvgoCPiykmvTkRdtw0Vu 1KBg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=Ef4X5GDU46mHK5Ifa4jRh1y2HrDd3BRHGBVmcwvvC1M=; b=AhMGax8/XGuwPfmRZhMb///wKGvpOGe/1EQP6UrzEIP0tlAGbHgXggDqqRqT+eV6ej BKLegBEEE0d8pd+QqAh0FUQjwCvBw6jMLmLUXiL+1C/OaCG1KyVhrNv6iEdlzh/v9n9A TlQz+F89BnXhw+hVFoCG6KdQP3IjjFKz/BmAq/+TQIGBJPAk9OLSZOnwBlTGLwcdF93g 5UinC8zMUku2t3pawRuRbDmR0aTTT3OfTclkeaRQFjTG/XFV2am1iMIVaULoMIQGiJI2 FQkNjahM43IcAX+F24wgFXvYfd8mhMb0+JuMDzWfKOTfbqIWy2gE5ooe9jl0tK4vlNUS QlFA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=D3iCA7Ty; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id h20si3934339qka.194.2020.10.30.11.10.04 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 30 Oct 2020 11:10:04 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=D3iCA7Ty; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:52330 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kYYqi-0002mO-0B for patch@linaro.org; Fri, 30 Oct 2020 14:10:04 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44874) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kYYmx-00059t-0C for qemu-devel@nongnu.org; Fri, 30 Oct 2020 14:06:11 -0400 Received: from mail-wm1-x342.google.com ([2a00:1450:4864:20::342]:36204) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kYYmi-0004qn-UI for qemu-devel@nongnu.org; Fri, 30 Oct 2020 14:06:09 -0400 Received: by mail-wm1-x342.google.com with SMTP id e2so3756650wme.1 for ; Fri, 30 Oct 2020 11:05:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Ef4X5GDU46mHK5Ifa4jRh1y2HrDd3BRHGBVmcwvvC1M=; b=D3iCA7TyC2/fLSoOAU3HkjFQRW9DGyLVcztyJuZ4q2zNGgFJzkvd4aZbLPvI4tBdsD uSfwCkAV65ZMU/yBRomGlj/svfHckWeMx9xgPxkmnr0dGZZHURrHPBPse2K3vy8Tn7Bs 3sc5W1zK8o4C0jqSskg5Y6fcywZRg9MItLNKRpRv/WXOMrlCRVQ3A/ADQjeAzxCG9/6K GfxHXYBu+XBtatWPvTKReTb0zl5YY+aQdA4MKBcc3SMwSKE0ty/47T6PMVVKgH1BO3Ig 6o2xL3HLcpwB+cw9J+zucU2PEMUOsfrcUxNvMHJpwpZYguT/bNuhh/dIDDk69TEumi/l VUbw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Ef4X5GDU46mHK5Ifa4jRh1y2HrDd3BRHGBVmcwvvC1M=; b=hGmfkLYgi7NX1sx/9zN2Uug0IkdoGN2knXDLm0LllVRExGj738qF8YXMEikVsejjTo Yr5FKLE/avjVald/awpzF6BdNdsHL4P4aTJM637edFZlZLk5dg1sNIfBYZNP3SfeDR1A I780SiTOlRXnDvTpGWC0bYSjJJ8RdB7qGHw13lC4hH2nIH/a+KidYL1KDfax77grBn34 /hye4Q0xDYvzUN+lBOp95CzIVnViFyKAT2gSGJNZVqFOAurmHlAEhxCFcDLMUndpfshr 6H99Us/HmIlAAxPTDXXZUj8f+6wDgU7H6dMlGXnXTasZfquVHv5XDa4DUjkVf+eLP4JG d1pA== X-Gm-Message-State: AOAM530Lp/28zsTqLLaT0/2+q0Tzdk+ncccrB/KE7wCIYUxwfX1aB7Zl sqhJYKR8rRqWi9k/UXH7t5Eo8g== X-Received: by 2002:a7b:cb54:: with SMTP id v20mr4098589wmj.149.1604081155108; Fri, 30 Oct 2020 11:05:55 -0700 (PDT) Received: from localhost.localdomain ([2001:1715:4e26:a7e0:116c:c27a:3e7f:5eaf]) by smtp.gmail.com with ESMTPSA id u3sm10044438wro.33.2020.10.30.11.05.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Oct 2020 11:05:54 -0700 (PDT) From: Jean-Philippe Brucker To: eric.auger@redhat.com, alex.williamson@redhat.com Subject: [PATCH v11 07/10] memory: Add interface to set iommu page size mask Date: Fri, 30 Oct 2020 19:05:07 +0100 Message-Id: <20201030180510.747225-8-jean-philippe@linaro.org> X-Mailer: git-send-email 2.29.1 In-Reply-To: <20201030180510.747225-1-jean-philippe@linaro.org> References: <20201030180510.747225-1-jean-philippe@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::342; envelope-from=jean-philippe@linaro.org; helo=mail-wm1-x342.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action 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: Jean-Philippe Brucker , mst@redhat.com, qemu-devel@nongnu.org, peterx@redhat.com, pbonzini@redhat.com, bbhushan2@marvell.com Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Bharat Bhushan Allow to set the page size mask supported by an iommu memory region. This enables a vIOMMU to communicate the page size granule supported by an assigned device, on hosts that use page sizes greater than 4kB. Acked-by: Peter Xu Reviewed-by: Eric Auger Signed-off-by: Bharat Bhushan Signed-off-by: Jean-Philippe Brucker --- v11: improve comment --- include/exec/memory.h | 38 ++++++++++++++++++++++++++++++++++++++ softmmu/memory.c | 13 +++++++++++++ 2 files changed, 51 insertions(+) -- 2.29.1 diff --git a/include/exec/memory.h b/include/exec/memory.h index aff6ef76053..0f3e6bcd5e7 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -397,6 +397,32 @@ struct IOMMUMemoryRegionClass { * @iommu: the IOMMUMemoryRegion */ int (*num_indexes)(IOMMUMemoryRegion *iommu); + + /** + * @iommu_set_page_size_mask: + * + * Restrict the page size mask that can be supported with a given IOMMU + * memory region. Used for example to propagate host physical IOMMU page + * size mask limitations to the virtual IOMMU. + * + * Optional method: if this method is not provided, then the default global + * page mask is used. + * + * @iommu: the IOMMUMemoryRegion + * + * @page_size_mask: a bitmask of supported page sizes. At least one bit, + * representing the smallest page size, must be set. Additional set bits + * represent supported block sizes. For example a host physical IOMMU that + * uses page tables with a page size of 4kB, and supports 2MB and 4GB + * blocks, will set mask 0x40201000. A granule of 4kB with indiscriminate + * block sizes is specified with mask 0xfffffffffffff000. + * + * Returns 0 on success, or a negative error. In case of failure, the error + * object must be created. + */ + int (*iommu_set_page_size_mask)(IOMMUMemoryRegion *iommu, + uint64_t page_size_mask, + Error **errp); }; typedef struct CoalescedMemoryRange CoalescedMemoryRange; @@ -1409,6 +1435,18 @@ int memory_region_iommu_attrs_to_index(IOMMUMemoryRegion *iommu_mr, */ int memory_region_iommu_num_indexes(IOMMUMemoryRegion *iommu_mr); +/** + * memory_region_iommu_set_page_size_mask: set the supported page + * sizes for a given IOMMU memory region + * + * @iommu_mr: IOMMU memory region + * @page_size_mask: supported page size mask + * @errp: pointer to Error*, to store an error if it happens. + */ +int memory_region_iommu_set_page_size_mask(IOMMUMemoryRegion *iommu_mr, + uint64_t page_size_mask, + Error **errp); + /** * memory_region_name: get a memory region's name * diff --git a/softmmu/memory.c b/softmmu/memory.c index ee4a6bc1685..bb40d2a1d8b 100644 --- a/softmmu/memory.c +++ b/softmmu/memory.c @@ -1841,6 +1841,19 @@ static int memory_region_update_iommu_notify_flags(IOMMUMemoryRegion *iommu_mr, return ret; } +int memory_region_iommu_set_page_size_mask(IOMMUMemoryRegion *iommu_mr, + uint64_t page_size_mask, + Error **errp) +{ + IOMMUMemoryRegionClass *imrc = IOMMU_MEMORY_REGION_GET_CLASS(iommu_mr); + int ret = 0; + + if (imrc->iommu_set_page_size_mask) { + ret = imrc->iommu_set_page_size_mask(iommu_mr, page_size_mask, errp); + } + return ret; +} + int memory_region_register_iommu_notifier(MemoryRegion *mr, IOMMUNotifier *n, Error **errp) { From patchwork Fri Oct 30 18:05:08 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jean-Philippe Brucker X-Patchwork-Id: 316473 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id DEFAAC55178 for ; Fri, 30 Oct 2020 18:09:16 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 37380206E5 for ; Fri, 30 Oct 2020 18:09:16 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="gnHqDIsV" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 37380206E5 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:49050 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kYYpv-0001RW-67 for qemu-devel@archiver.kernel.org; Fri, 30 Oct 2020 14:09:15 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44876) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kYYmx-00059u-0E for qemu-devel@nongnu.org; Fri, 30 Oct 2020 14:06:11 -0400 Received: from mail-wr1-x441.google.com ([2a00:1450:4864:20::441]:45684) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kYYmm-0004qu-49 for qemu-devel@nongnu.org; Fri, 30 Oct 2020 14:06:10 -0400 Received: by mail-wr1-x441.google.com with SMTP id a9so7414032wrg.12 for ; Fri, 30 Oct 2020 11:05:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=12Ju8kXQSFpn0papdnxccSNLTxeP7E2Kw7ISAbJMDvA=; b=gnHqDIsVm60CzSvp3ox9M41hiKc0xgMyTHFXNxMiCYt9+Hc7FXB3f3JQdpN6xctB65 17tPqA3r6A5TiHmwMlYTfmNqHG+bJuhsw5JK7dUAhIEe/n+xdL+nNOfQkrFDfBcNuRcV tsEgz1Dz8+YwrzDwkxQQhjcT/jX/GhaGv7K4mVI6mu2razq1xXywif76cD1aHXOyP9YV AzN6OAJ+DP9iZsQEhN8EXNcwiGD+FEPORgnkWN1OB3i5qdJdzmnVfScp2KbLNePy0TrA T/31/OODvxU3jZUcC7FtJMAKcQzrFybCg5e3hG/AYO57GrzFZnPjlqWM2g6JMiel57q5 LQPg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=12Ju8kXQSFpn0papdnxccSNLTxeP7E2Kw7ISAbJMDvA=; b=oqzsxvug3Fn8rI0YHS6M/GfYZpyKU1kZ7p6BuBZB62SAEfb9ClTVc8raDzLE2Jjh3p pOt3Tx6Ko6Jlgy3A2gOWyUJ2o7ZFQooLzwpTqnbI8gRfp5FHYC7KU/xuk+WV6EHWdj6G MspPBotLgVOG6xZeRdv7MtmsfP37qir5sZ5+/4QZJUEP882W65KLuQLUpYE+ZCtrRkyp v0larOvciFY3MuE+1sPPtR+ne/nMPOQ5BNzDfxu4UCX01uwF0FecxXVWC+Y4EaBXsqLa JMjkf31BQpTL0KVqY+S9cl55VRUCBxMkqjT9l2agT+pC4bHKbydA/8i1QTXgGYDpJ6/y 4GXQ== X-Gm-Message-State: AOAM531E0T3Qzt089bfvh1Z31gl1ZyHT1b+cvPv3JuOIDoj4RCtpacnc CWHYArPq7ipEl5yba3KcOoNxCg== X-Google-Smtp-Source: ABdhPJwbx4BxAg0T9Wm7S4xKTvG8ISfboebdWxrXsuZnP4IbjVwQLiW45u0wJrbGmuNDyC9noc0ROg== X-Received: by 2002:adf:80c8:: with SMTP id 66mr4795705wrl.415.1604081156768; Fri, 30 Oct 2020 11:05:56 -0700 (PDT) Received: from localhost.localdomain ([2001:1715:4e26:a7e0:116c:c27a:3e7f:5eaf]) by smtp.gmail.com with ESMTPSA id u3sm10044438wro.33.2020.10.30.11.05.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Oct 2020 11:05:55 -0700 (PDT) From: Jean-Philippe Brucker To: eric.auger@redhat.com, alex.williamson@redhat.com Subject: [PATCH v11 08/10] vfio: Set IOMMU page size as per host supported page size Date: Fri, 30 Oct 2020 19:05:08 +0100 Message-Id: <20201030180510.747225-9-jean-philippe@linaro.org> X-Mailer: git-send-email 2.29.1 In-Reply-To: <20201030180510.747225-1-jean-philippe@linaro.org> References: <20201030180510.747225-1-jean-philippe@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::441; envelope-from=jean-philippe@linaro.org; helo=mail-wr1-x441.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jean-Philippe Brucker , mst@redhat.com, qemu-devel@nongnu.org, peterx@redhat.com, pbonzini@redhat.com, bbhushan2@marvell.com Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" From: Bharat Bhushan Set IOMMU supported page size mask same as host Linux supported page size mask. Acked-by: Alex Williamson Reviewed-by: Eric Auger Signed-off-by: Bharat Bhushan Signed-off-by: Jean-Philippe Brucker --- --- hw/vfio/common.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/hw/vfio/common.c b/hw/vfio/common.c index 13471ae2943..e66054b02a7 100644 --- a/hw/vfio/common.c +++ b/hw/vfio/common.c @@ -636,6 +636,14 @@ static void vfio_listener_region_add(MemoryListener *listener, int128_get64(llend), iommu_idx); + ret = memory_region_iommu_set_page_size_mask(giommu->iommu, + container->pgsizes, + &err); + if (ret) { + g_free(giommu); + goto fail; + } + ret = memory_region_register_iommu_notifier(section->mr, &giommu->n, &err); if (ret) { From patchwork Fri Oct 30 18:05:09 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jean-Philippe Brucker X-Patchwork-Id: 320030 Delivered-To: patch@linaro.org Received: by 2002:a92:7b12:0:0:0:0:0 with SMTP id w18csp1643014ilc; Fri, 30 Oct 2020 11:12:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxuKJNrT3lhVFtjkdOjvHH4XenlFxdjFFMHuR0KnOjFN7EyzR3rCgqrypXAVNrrB46fHTXh X-Received: by 2002:a37:9042:: with SMTP id s63mr3329468qkd.395.1604081527055; Fri, 30 Oct 2020 11:12:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1604081527; cv=none; d=google.com; s=arc-20160816; b=AnWeRs+oCE88pbiaxgYZ8WwU8wDbnfxMxTYOPcPdMmltlc1tq3pGPp2BLENFDNCSHS zMLte+5Rvng4fFjkp4r4NcAXISgWMBmR8giKcBHUDKcZoX4eG4dTjT1E6o7Qa+HAggXc o0gsrxfveIO2iGJxi15kKnERzRr5Q0nb5j78AGDWcvRjkiXCZ4TWg2SBeTTboMVjEsRL dms0hLV+T9Cw35HqQwgEJoJnxUwImYnwQV5wvTLwU7HNXWS+OZXSta+/flcw94oWlHsn WLJUiHBsU+2RI3NbHW0aLf3Sw4C1oIZ5j02lLVuw/EhkSg1qzkrjNVWQB5v7VngVXNSz m+Gw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=Dg6KgMRhe+BDU/aQn0+rRvWHE//ly0GmnJbDrG3nhDE=; b=t5pstNy1kLmpy8lmqqDvlV77TtNBeYUduPnfSFB0XD4aBDrICb+e8atiqTfvV0Zmr+ Bkfh6MzQtF6RS6FLDR/jUAg0vNe6oyMHse4wcQqjs+bpZ83o9BmIR2INIHM5zuPsT7CG ruLFnWMjowr/FJMpg06qxHKggMZDnUaEIskhEZ0j4JASDPRj0lcJF+ibwaKA8kqKUVh3 y+M5fOBNPK4Wc+Njx1BA1ptNo0mKDp4GoQwaO5B4fy/SLsmESRoUGBq3azO9IJUsaHXM 7rEo0rmqhiLxjVePOQ4B/fUf+Qd6+dOd7Fm5NF+eAkvarholAZzjEsxz1ZiO3cGvTuEj pkLA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=HpJEUqpV; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id f6si4419912qko.338.2020.10.30.11.12.06 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 30 Oct 2020 11:12:07 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=HpJEUqpV; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:57130 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kYYsg-0004p2-IX for patch@linaro.org; Fri, 30 Oct 2020 14:12:06 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44864) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kYYmt-00059Y-Ce for qemu-devel@nongnu.org; Fri, 30 Oct 2020 14:06:08 -0400 Received: from mail-wm1-x32a.google.com ([2a00:1450:4864:20::32a]:38254) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kYYmn-0004qz-Pc for qemu-devel@nongnu.org; Fri, 30 Oct 2020 14:06:07 -0400 Received: by mail-wm1-x32a.google.com with SMTP id l8so3745943wmg.3 for ; Fri, 30 Oct 2020 11:05:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Dg6KgMRhe+BDU/aQn0+rRvWHE//ly0GmnJbDrG3nhDE=; b=HpJEUqpVFuZPcKweNR+djPDKqDFedR/o2qpdMNLvABKExA2TPXSgJ7JxXoWngFAmx3 V/NSmJrOk5L+nMXKZHqTnYv+KjSjL7i4mQKUT0XxTnuLbGTgDuqpNtkvFrlMb4+fXEHW gWZqqQN75cbM0s7SYbg4+gFuxcXN6U7bsyEEbic1jq/ILoMo03CMZa437sZavEXUIUIl oDbWFkJ+81nhKA7rZbExldBmTffNe1cyKGk9TwS9zo1btTje3owy1dnTosr3iXWi8PYt WdurYylCGWV2unzSmAyVGhGoG1yg+td/zuTI8/h/HmsHk4xX3LFLOyzV9xYNFd5wRL35 jFDw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Dg6KgMRhe+BDU/aQn0+rRvWHE//ly0GmnJbDrG3nhDE=; b=EK94SQTvEhGGojHxfq64a9uSmxPF8+4WGuEmUhBMyNqQtxsus2mxHRkxCfdBazeCUW N+E27qviu7bozgpPZsHnY9PtNoYrQxp5jZ6xniwurIXbYM9/Jj/BHuitvRuYaNSTd58/ oARP6wRBWxo8/JJ0MtnNSAJNGE1ZPI4MQPUrk3X0T3YCJE07k22nusAmFy3aKv6L1VYj C+qcOyF6ijnPIJE7XpFvcJhuqswK8lIHLNLkuBEtEnbecUwLqAwSoV14I1rR8uFMzDpM R8eqkuKCa3IKt97cm5r1Uo221/9UEsT68eFf4yGAD/d4ONZ0dBZH44XehzxNbWxgy64k SLLg== X-Gm-Message-State: AOAM532Yh+9vKI7ORtv86aicveW/ElgniTPcL7EJ61c1hcd3qh41SCXZ RN+L/ovM73jGJcVT+NUSyrnToA== X-Received: by 2002:a1c:e006:: with SMTP id x6mr4150190wmg.107.1604081158148; Fri, 30 Oct 2020 11:05:58 -0700 (PDT) Received: from localhost.localdomain ([2001:1715:4e26:a7e0:116c:c27a:3e7f:5eaf]) by smtp.gmail.com with ESMTPSA id u3sm10044438wro.33.2020.10.30.11.05.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Oct 2020 11:05:57 -0700 (PDT) From: Jean-Philippe Brucker To: eric.auger@redhat.com, alex.williamson@redhat.com Subject: [PATCH v11 09/10] virtio-iommu: Set supported page size mask Date: Fri, 30 Oct 2020 19:05:09 +0100 Message-Id: <20201030180510.747225-10-jean-philippe@linaro.org> X-Mailer: git-send-email 2.29.1 In-Reply-To: <20201030180510.747225-1-jean-philippe@linaro.org> References: <20201030180510.747225-1-jean-philippe@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::32a; envelope-from=jean-philippe@linaro.org; helo=mail-wm1-x32a.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jean-Philippe Brucker , mst@redhat.com, qemu-devel@nongnu.org, peterx@redhat.com, pbonzini@redhat.com, bbhushan2@marvell.com Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Bharat Bhushan The virtio-iommu device can deal with arbitrary page sizes for virtual endpoints, but for endpoints assigned with VFIO it must follow the page granule used by the host IOMMU driver. Implement the interface to set the vIOMMU page size mask, called by VFIO for each endpoint. We assume that all host IOMMU drivers use the same page granule (the host page granule). Override the page_size_mask field in the virtio config space. Signed-off-by: Bharat Bhushan Signed-off-by: Jean-Philippe Brucker --- v11: Simplify the update logic slightly --- hw/virtio/virtio-iommu.c | 50 ++++++++++++++++++++++++++++++++++++++++ hw/virtio/trace-events | 1 + 2 files changed, 51 insertions(+) -- 2.29.1 diff --git a/hw/virtio/virtio-iommu.c b/hw/virtio/virtio-iommu.c index 78e07aa40a5..fc5c75d6933 100644 --- a/hw/virtio/virtio-iommu.c +++ b/hw/virtio/virtio-iommu.c @@ -899,6 +899,55 @@ static int virtio_iommu_notify_flag_changed(IOMMUMemoryRegion *iommu_mr, return 0; } +/* + * The default mask (TARGET_PAGE_MASK) is the smallest supported guest granule, + * for example 0xfffffffffffff000. When an assigned device has page size + * restrictions due to the hardware IOMMU configuration, apply this restriction + * to the mask. + */ +static int virtio_iommu_set_page_size_mask(IOMMUMemoryRegion *mr, + uint64_t new_mask, + Error **errp) +{ + IOMMUDevice *sdev = container_of(mr, IOMMUDevice, iommu_mr); + VirtIOIOMMU *s = sdev->viommu; + uint64_t cur_mask = s->config.page_size_mask; + + trace_virtio_iommu_set_page_size_mask(mr->parent_obj.name, cur_mask, + new_mask); + + if ((cur_mask & new_mask) == 0) { + error_setg(errp, "virtio-iommu page mask 0x%"PRIx64 + " is incompatible with mask 0x%"PRIx64, cur_mask, new_mask); + return -1; + } + + /* + * After the machine is finalized, we can't change the mask anymore. If by + * chance the hotplugged device supports the same granule, we can still + * accept it. Having a different masks is possible but the guest will use + * sub-optimal block sizes, so warn about it. + */ + if (qdev_hotplug) { + int new_granule = ctz64(new_mask); + int cur_granule = ctz64(cur_mask); + + if (new_granule != cur_granule) { + error_setg(errp, "virtio-iommu page mask 0x%"PRIx64 + " is incompatible with mask 0x%"PRIx64, cur_mask, + new_mask); + return -1; + } else if (new_mask != cur_mask) { + warn_report("virtio-iommu page mask 0x%"PRIx64 + " does not match 0x%"PRIx64, cur_mask, new_mask); + } + return 0; + } + + s->config.page_size_mask &= new_mask; + return 0; +} + static void virtio_iommu_device_realize(DeviceState *dev, Error **errp) { VirtIODevice *vdev = VIRTIO_DEVICE(dev); @@ -1130,6 +1179,7 @@ static void virtio_iommu_memory_region_class_init(ObjectClass *klass, imrc->translate = virtio_iommu_translate; imrc->replay = virtio_iommu_replay; imrc->notify_flag_changed = virtio_iommu_notify_flag_changed; + imrc->iommu_set_page_size_mask = virtio_iommu_set_page_size_mask; } static const TypeInfo virtio_iommu_info = { diff --git a/hw/virtio/trace-events b/hw/virtio/trace-events index 982d0002a65..2060a144a2f 100644 --- a/hw/virtio/trace-events +++ b/hw/virtio/trace-events @@ -109,6 +109,7 @@ virtio_iommu_fill_resv_property(uint32_t devid, uint8_t subtype, uint64_t start, virtio_iommu_notify_map(const char *name, uint64_t virt_start, uint64_t virt_end, uint64_t phys_start, uint32_t flags) "mr=%s virt_start=0x%"PRIx64" virt_end=0x%"PRIx64" phys_start=0x%"PRIx64" flags=%d" virtio_iommu_notify_unmap(const char *name, uint64_t virt_start, uint64_t virt_end) "mr=%s virt_start=0x%"PRIx64" virt_end=0x%"PRIx64 virtio_iommu_remap(const char *name, uint64_t virt_start, uint64_t virt_end, uint64_t phys_start) "mr=%s virt_start=0x%"PRIx64" virt_end=0x%"PRIx64" phys_start=0x%"PRIx64 +virtio_iommu_set_page_size_mask(const char *name, uint64_t old, uint64_t new) "mr=%s old_mask=0x%"PRIx64" new_mask=0x%"PRIx64 virtio_iommu_notify_flag_add(const char *name) "add notifier to mr %s" virtio_iommu_notify_flag_del(const char *name) "del notifier from mr %s" From patchwork Fri Oct 30 18:05:10 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jean-Philippe Brucker X-Patchwork-Id: 316471 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8A61CC00A89 for ; Fri, 30 Oct 2020 18:13:52 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id BC63220702 for ; Fri, 30 Oct 2020 18:13:51 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="g+9jC9AR" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org BC63220702 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:60638 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kYYuM-0006Kd-Ib for qemu-devel@archiver.kernel.org; Fri, 30 Oct 2020 14:13:50 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44870) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kYYmw-00059r-Vr for qemu-devel@nongnu.org; Fri, 30 Oct 2020 14:06:11 -0400 Received: from mail-wm1-x344.google.com ([2a00:1450:4864:20::344]:39338) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kYYmp-0004r8-Bf for qemu-devel@nongnu.org; Fri, 30 Oct 2020 14:06:08 -0400 Received: by mail-wm1-x344.google.com with SMTP id d3so3744894wma.4 for ; Fri, 30 Oct 2020 11:06:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=PVmUxGETfBJ3WJRj1ZG9T2/QT+bDC3bRHPQVEh7hMSk=; b=g+9jC9ARXcJYS9wk6JShPK0IRscgnd175zibqDgx1TEtnKBEIblpqRm/JsBC55eedU HjIEUTBqmMOrVvv7HlmAmhl/foKaXr0BagZBcIu55oTrSMjw5jXrRfl/cukSMYLylx3A RdZLejB+sNr3bhOK0HT24bQMQuLmtVOQpudBe7UXIZ1oi0+GVmE2xeuN/xnwmCusqtbI kt0LmacAPfm54eCLIceMGUlSizjc8ipSkOf7XjZs9IAd47vveQ4mtQv8/gyB3JnowfGx vKgJ/9GAFDFWASt3H4DPRm6hBHzIzYAl98BNHAvFCXArERnXPjSaQsBeFD7Jn1HduVUE becQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=PVmUxGETfBJ3WJRj1ZG9T2/QT+bDC3bRHPQVEh7hMSk=; b=YabIkV4vRRcRKhY6zN3jIDNjgHXmKpvOvfIuq971xh62qi5mWcyuR7N1VoQj7RDYof ugrI1dMD3u5Hb2+8ijlljsEsfTh8mBbVWjQMfVveV6Z6Yf9xxiL8KUBFHjqcSJLY9d/j PPgsCVI9u78wSpFxXga1ArvqknWr581JPw7I5ftAaBT7Ilq7N315t1D8dA1MkpTXPsYH dj3y2i3HbYeKWDndYdon3M6T8r6NAZGkTkxH+qcCXw3IO6lMs1p9Rh9IslXFvh6uc0h5 YDPZPRCM5m0tEUrALo6IxQULEZpd179uaIe9YaUVajsamruNmolzNvDeK8hMAhprg/ta 4mHA== X-Gm-Message-State: AOAM531WBPW2Xj0O1pmmD7USVBBbcHMaR6vK526CZNseFGH15n1LkhHO xoCuxV3ChYh8xhHiHBmPvbXJnxEwyW0y0A== X-Google-Smtp-Source: ABdhPJwwjv7DyC8JVHbJe6mnqo8R72gOAGxCzLVg88Me9to2SYVOKUMFNtmzMb/4WBFI99796anwqg== X-Received: by 2002:a7b:c4d6:: with SMTP id g22mr4295594wmk.106.1604081159183; Fri, 30 Oct 2020 11:05:59 -0700 (PDT) Received: from localhost.localdomain ([2001:1715:4e26:a7e0:116c:c27a:3e7f:5eaf]) by smtp.gmail.com with ESMTPSA id u3sm10044438wro.33.2020.10.30.11.05.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Oct 2020 11:05:58 -0700 (PDT) From: Jean-Philippe Brucker To: eric.auger@redhat.com, alex.williamson@redhat.com Subject: [PATCH v11 10/10] vfio: Don't issue full 2^64 unmap Date: Fri, 30 Oct 2020 19:05:10 +0100 Message-Id: <20201030180510.747225-11-jean-philippe@linaro.org> X-Mailer: git-send-email 2.29.1 In-Reply-To: <20201030180510.747225-1-jean-philippe@linaro.org> References: <20201030180510.747225-1-jean-philippe@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::344; envelope-from=jean-philippe@linaro.org; helo=mail-wm1-x344.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jean-Philippe Brucker , mst@redhat.com, qemu-devel@nongnu.org, peterx@redhat.com, pbonzini@redhat.com, bbhushan2@marvell.com Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" IOMMUs may declare memory regions spanning from 0 to UINT64_MAX. When attempting to deal with such region, vfio_listener_region_del() passes a size of 2^64 to int128_get64() which throws an assertion failure. Even ignoring this, the VFIO_IOMMU_DMA_MAP ioctl cannot handle this size since the size field is 64-bit. Split the request in two. Acked-by: Alex Williamson Reviewed-by: Eric Auger Signed-off-by: Jean-Philippe Brucker --- For me this happens when memory_region_iommu_set_page_size_mask() returns an error because a hotplugged endpoint uses an incompatible page mask. vfio_connect_container() releases the memory listener which calls region_del() with the 2^64 IOMMU region. There are probably other ways to reach this. --- hw/vfio/common.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/hw/vfio/common.c b/hw/vfio/common.c index e66054b02a7..e90a89c389e 100644 --- a/hw/vfio/common.c +++ b/hw/vfio/common.c @@ -797,6 +797,17 @@ static void vfio_listener_region_del(MemoryListener *listener, } if (try_unmap) { + if (llsize == int128_2_64()) { + /* The unmap ioctl doesn't accept a full 64-bit span. */ + llsize = int128_rshift(llsize, 1); + ret = vfio_dma_unmap(container, iova, int128_get64(llsize)); + if (ret) { + error_report("vfio_dma_unmap(%p, 0x%"HWADDR_PRIx", " + "0x%"HWADDR_PRIx") = %d (%m)", + container, iova, int128_get64(llsize), ret); + } + iova += int128_get64(llsize); + } ret = vfio_dma_unmap(container, iova, int128_get64(llsize)); if (ret) { error_report("vfio_dma_unmap(%p, 0x%"HWADDR_PRIx", "