From nobody Thu May 9 20:25:29 2024 Delivered-To: importer@patchew.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=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1604081357; cv=none; d=zohomail.com; s=zohoarc; b=LJfLuDhsT3wWCwQ+vp3hjNssEE0leQt6x/iisY6RFIhuOkgR9QJECKfv7eCkMw3EcmAZXOAVmVsnhokKB21kNHd/L98deAkvVWWOdpC54YepI2u32K22oZN/DtY0pHZMOJVbKhUMUoQXU9TbGzhQ8I4o4cgZVKoN5NtWTbYQqco= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1604081357; h=Content-Transfer-Encoding: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=x+cvpu7ceWHktnpLf54xiiETIbszTKNIsMfFS/95CA0=; b=MYKZwpPVCMV+vLsjvg9V3amBWuPFqgfHIVRQ9OeXUCnvJiAz0kBAHN6t8C06lPLD0B5Ymsm/XTlUNu/mEZ7+eF3BBHgNBZ+PipLfEtZ04xLNrBe16GVfpn198aFk9L8z2eunCbSKJ5MWk7AUZgMberVpOzZlJwPdTYdIrK6dVDI= 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 1604081357387228.45951736597817; Fri, 30 Oct 2020 11:09:17 -0700 (PDT) Received: from localhost ([::1]:48826 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kYYpv-0001M9-P2 for importer@patchew.org; Fri, 30 Oct 2020 14:09:15 -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) 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) 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) 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 Content-Transfer-Encoding: quoted-printable 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; 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" 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 =3D PCI_BUS_NUM(sid); iommu_pci_bus =3D iommu_find_iommu_pcibus(s, bus_n); if (iommu_pci_bus) { - devfn =3D sid & PCI_DEVFN_MAX; + devfn =3D sid & (PCI_DEVFN_MAX - 1); dev =3D iommu_pci_bus->pbdev[devfn]; if (dev) { return &dev->iommu_mr; --=20 2.29.1 From nobody Thu May 9 20:25:29 2024 Delivered-To: importer@patchew.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=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1604081357; cv=none; d=zohomail.com; s=zohoarc; b=Ny2h0znzYwGLf7aA0hg3j+s25kZXJtEWcYIpWh/ADgkBnmQPFIEaU3Cw/Gj7Q5vIJjSpM2WG7eX7457UHwQbw1xc//GDLTOD1/NT9YHEpoezILABN5Tl9/pOdnr7N0hswzBKOom+M6uJGDQv+AmbScL7YuzNECbwKM9b+RWKRJs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1604081357; h=Content-Transfer-Encoding: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=Mw5vfUgd3GO54+QgLOqJSliaESKLNNhHaEh4i2r3qrc=; b=LO8QQ9BQDcsFqCfNTC+CusOY99qqb2P3katnd6P8WOUwW5Gnmx9zOTAT169HR5kj2+Bgu2xpOTwOPcticwYMH3dGkNxlKLyCOg4slbPZlGTydvTq/fLEPZ41nzGV3Wt/LvzCQjdNxBMNSFzrC+4fEiLDLNdq51EOMrm+I6gfvAM= 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 1604081357786393.7182286016879; Fri, 30 Oct 2020 11:09:17 -0700 (PDT) Received: from localhost ([::1]:48866 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kYYpw-0001N5-Fs for importer@patchew.org; Fri, 30 Oct 2020 14:09:16 -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) 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) 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-Google-Smtp-Source: ABdhPJycaSUvMA0vq1XbEp92k9sEHPAbzzxILM/X75UZiZBl/B9AI8GhaB8Ui0Ahr43m9G5ZFwSM/g== X-Received: by 2002:a7b:c00b:: with SMTP id c11mr4036924wmb.96.1604081148980; 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 Content-Transfer-Encoding: quoted-printable 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; 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" 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(-) 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; =20 @@ -137,16 +138,19 @@ static VirtIOIOMMUEndpoint *virtio_iommu_get_endpoint= (VirtIOIOMMU *s, uint32_t ep_id) { VirtIOIOMMUEndpoint *ep; + IOMMUMemoryRegion *mr; =20 ep =3D g_tree_lookup(s->endpoints, GUINT_TO_POINTER(ep_id)); if (ep) { return ep; } - if (!virtio_iommu_mr(s, ep_id)) { + mr =3D virtio_iommu_mr(s, ep_id); + if (!mr) { return NULL; } ep =3D g_malloc0(sizeof(*ep)); ep->id =3D ep_id; + ep->iommu_mr =3D 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, gp= ointer value, VirtIOIOMMU *s =3D (VirtIOIOMMU *)data; VirtIOIOMMUDomain *d =3D (VirtIOIOMMUDomain *)value; VirtIOIOMMUEndpoint *iter; + IOMMUMemoryRegion *mr; =20 QLIST_FOREACH(iter, &d->endpoint_list, next) { + mr =3D virtio_iommu_mr(s, iter->id); + assert(mr); + iter->domain =3D d; + iter->iommu_mr =3D mr; g_tree_insert(s->endpoints, GUINT_TO_POINTER(iter->id), iter); } return false; /* continue the domain traversal */ --=20 2.29.1 From nobody Thu May 9 20:25:29 2024 Delivered-To: importer@patchew.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=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1604081462; cv=none; d=zohomail.com; s=zohoarc; b=lwMIl7kCB+YFdHbE/SJO74aODlewPGPwKb0TstOciOlWB0paijmY5RlAH6MUIicu6ZX607MCQtFp71kq4Y9x05WPyxugaf+J13KYwuefGbb7Zioucboitn3oEWcDqbcXAeG5gL4++WTaXS6znSTl31sVW3yEiC/g/JdVEJ15tbk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1604081462; h=Content-Transfer-Encoding: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=Ej1fodcMaFb0u/aG6D5WFwOmMShNXQ/JZRK7Jgg8zcU=; b=mBrc8+/DLxXgkZg0ySPH6CkynCDSGrMuRfZm6T2CyLDSMj8E9zJUw+c6WtCz7JLmUlOvtBq2OO2FhjlvbJtjGa/TzMQzNe+fyRIDoMDPLEUcjWjFxgkccYyQ3ldxalJ9p9gV+EArsQnMEQs5LmLQ4o4WrpRa1f37N/L3TWG2qds= 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 1604081462811117.27730951350964; Fri, 30 Oct 2020 11:11:02 -0700 (PDT) Received: from localhost ([::1]:54890 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kYYrd-0003vQ-JI for importer@patchew.org; Fri, 30 Oct 2020 14:11:01 -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) 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) 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) 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 Content-Transfer-Encoding: quoted-printable 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; 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" 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, gconstpointe= r b, gpointer user_data) } } =20 +static void virtio_iommu_notify_map(IOMMUMemoryRegion *mr, hwaddr virt_sta= rt, + hwaddr virt_end, hwaddr paddr, + uint32_t flags) +{ + IOMMUTLBEntry entry; + IOMMUAccessFlags perm =3D IOMMU_ACCESS_FLAG(flags & VIRTIO_IOMMU_MAP_F= _READ, + flags & VIRTIO_IOMMU_MAP_F_W= RITE); + + 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_en= d, + paddr, perm); + + entry.target_as =3D &address_space_memory; + entry.addr_mask =3D virt_end - virt_start; + entry.iova =3D virt_start; + entry.perm =3D perm; + entry.translated_addr =3D paddr; + + memory_region_notify_iommu(mr, 0, entry); +} + +static void virtio_iommu_notify_unmap(IOMMUMemoryRegion *mr, hwaddr virt_s= tart, + 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 =3D &address_space_memory; + entry.addr_mask =3D virt_end - virt_start; + entry.iova =3D virt_start; + 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) { @@ -315,6 +360,7 @@ static int virtio_iommu_map(VirtIOIOMMU *s, VirtIOIOMMUDomain *domain; VirtIOIOMMUInterval *interval; VirtIOIOMMUMapping *mapping; + VirtIOIOMMUEndpoint *ep; =20 if (flags & ~VIRTIO_IOMMU_MAP_F_MASK) { return VIRTIO_IOMMU_S_INVAL; @@ -344,6 +390,11 @@ static int virtio_iommu_map(VirtIOIOMMU *s, =20 g_tree_insert(domain->mappings, interval, mapping); =20 + QLIST_FOREACH(ep, &domain->endpoint_list, next) { + virtio_iommu_notify_map(ep->iommu_mr, virt_start, virt_end, phys_s= tart, + flags); + } + return VIRTIO_IOMMU_S_OK; } =20 @@ -356,6 +407,7 @@ static int virtio_iommu_unmap(VirtIOIOMMU *s, VirtIOIOMMUMapping *iter_val; VirtIOIOMMUInterval interval, *iter_key; VirtIOIOMMUDomain *domain; + VirtIOIOMMUEndpoint *ep; int ret =3D VIRTIO_IOMMU_S_OK; =20 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 =3D iter_key->high; =20 if (interval.low <=3D current_low && interval.high >=3D current_hi= gh) { + 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 domai= n=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_fill_resv_property(uint32_t devid, uint8_t subtype, uint64_t = start, uint64_t end) "dev=3D %d, type=3D%d start=3D0x%"PRIx64" end=3D0x%"PR= Ix64 +virtio_iommu_notify_map(const char *name, uint64_t virt_start, uint64_t vi= rt_end, uint64_t phys_start, uint32_t flags) "mr=3D%s virt_start=3D0x%"PRIx= 64" virt_end=3D0x%"PRIx64" phys_start=3D0x%"PRIx64" flags=3D%d" +virtio_iommu_notify_unmap(const char *name, uint64_t virt_start, uint64_t = virt_end) "mr=3D%s virt_start=3D0x%"PRIx64" virt_end=3D0x%"PRIx64 =20 # virtio-mem.c virtio_mem_send_response(uint16_t type) "type=3D%" PRIu16 --=20 2.29.1 From nobody Thu May 9 20:25:29 2024 Delivered-To: importer@patchew.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=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1604081262; cv=none; d=zohomail.com; s=zohoarc; b=PXtynjvCKa+7OKW1BegqXjv6YTQNA7G+zECXZI6vJuQ8zqsXFU8KRL0sGMasbQR0bQTBykTGySH7TtD2bGZ8X+vpDUTwIddCib3rmq1zyaBfGkWdrBs6zzHmeM+SdO0zh4bBlvA1+3DW7v1ZcwrInToXLL//dwvjb7G+ztsV3X8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1604081262; h=Content-Transfer-Encoding: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=Eu3dQfIpFEu6odtk6adJYWVijDRkJcSgv2bG/hnjotM=; b=c0Kb06eBpqfd3OHZI3IKohUU23MjJC70LlsbzH2OJXLj3cxQIRA/AmN9W8DsjUJBg0QGsYH8iAp694KzoBi4UXYZpylqlPv6OIumhoP2dRuCp/Afzc1rr+zydR3i4hhY04m+RGKjXeng8qHY99RAwsAZYEkqqRrD20l6Ku9iBFQ= 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 1604081262605268.45686561465254; Fri, 30 Oct 2020 11:07:42 -0700 (PDT) Received: from localhost ([::1]:41390 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kYYoP-0006l4-AP for importer@patchew.org; Fri, 30 Oct 2020 14:07: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) 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) 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-Google-Smtp-Source: ABdhPJx+XjjSXEOXZYplqrc43yAVnyTh1mNU8ls3qpMzwlgsVmYkvFiDTL1adBk019yPq/WEmiYZXA== X-Received: by 2002:a05:6000:83:: with SMTP id m3mr4465518wrx.147.1604081151314; 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 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 Content-Transfer-Encoding: quoted-printable 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; 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" 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(+) 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(IOMMUMemoryRegi= on *mr, hwaddr virt_start, memory_region_notify_iommu(mr, 0, entry); } =20 +static gboolean virtio_iommu_notify_unmap_cb(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); + + return false; +} + +static gboolean virtio_iommu_notify_map_cb(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, interval->high, + mapping->phys_addr, mapping->flags); + + return false; +} + static void virtio_iommu_detach_endpoint_from_domain(VirtIOIOMMUEndpoint *= ep) { + VirtIOIOMMUDomain *domain =3D 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 =3D NULL; } @@ -317,6 +345,10 @@ static int virtio_iommu_attach(VirtIOIOMMU *s, =20 ep->domain =3D domain; =20 + /* 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; } =20 --=20 2.29.1 From nobody Thu May 9 20:25:29 2024 Delivered-To: importer@patchew.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=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1604081264; cv=none; d=zohomail.com; s=zohoarc; b=JP14gqaBHY9Pma9kh7lw9uh9YWxOjinErUk6FbDGmg+bLLQoWlFyxzt2Ui8NmfgjBAhwFrnGCzxrggVAyfCbYqMldU/nrOrLA4gAjqi6RvGB1yC0zj0OLd5D4UlN9oeWFTkoCqU027y5OLMDAB6UNcvwbobvv6mHPjrOpdNtkRY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1604081264; h=Content-Transfer-Encoding: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=CgsfmPEJUSprxXHS+NXfbp1mG3kP5a7TnQouVrlttaA=; b=dDRDp0Fz1dMcrgvpG5rjmDBgqtWg+GVbQXJtzsQmtn6z/QphWEHi6NlJtTvv877uhj+bB9mE0EpitBv6jeGpwBNq3W9IWmhK03jqQ37uJ2BI8nhAkq9n9O0h+IGoLA0BnWrjprfnqJCg2dWxMe1PbMIXCsA0vsAj56B5vw2or0Q= 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 1604081264557639.5735770085187; Fri, 30 Oct 2020 11:07:44 -0700 (PDT) Received: from localhost ([::1]:41622 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kYYoR-0006qR-7D for importer@patchew.org; Fri, 30 Oct 2020 14:07:43 -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) 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) 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-Google-Smtp-Source: ABdhPJwA7D6uabCwMlbOTwVvZ1JkO+5scqE+mxWLvTru4Z0E3jvTsQF+zhYvIbTEyDn6mUVwGNMfTw== X-Received: by 2002:a1c:ddd7:: with SMTP id u206mr3464085wmg.27.1604081152746; Fri, 30 Oct 2020 11:05:52 -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 Content-Transfer-Encoding: quoted-printable 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; 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" 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(+) 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); } =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(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 =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); @@ -1076,6 +1115,7 @@ static void virtio_iommu_memory_region_class_init(Obj= ectClass *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 { 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 flag= s, uint32_t endpoint, uin virtio_iommu_fill_resv_property(uint32_t devid, uint8_t subtype, uint64_t = start, uint64_t end) "dev=3D %d, type=3D%d start=3D0x%"PRIx64" end=3D0x%"PR= Ix64 virtio_iommu_notify_map(const char *name, uint64_t virt_start, uint64_t vi= rt_end, uint64_t phys_start, uint32_t flags) "mr=3D%s virt_start=3D0x%"PRIx= 64" virt_end=3D0x%"PRIx64" phys_start=3D0x%"PRIx64" flags=3D%d" virtio_iommu_notify_unmap(const char *name, uint64_t virt_start, uint64_t = virt_end) "mr=3D%s virt_start=3D0x%"PRIx64" virt_end=3D0x%"PRIx64 +virtio_iommu_remap(const char *name, uint64_t virt_start, uint64_t virt_en= d, uint64_t phys_start) "mr=3D%s virt_start=3D0x%"PRIx64" virt_end=3D0x%"PR= Ix64" phys_start=3D0x%"PRIx64 =20 # virtio-mem.c virtio_mem_send_response(uint16_t type) "type=3D%" PRIu16 --=20 2.29.1 From nobody Thu May 9 20:25:29 2024 Delivered-To: importer@patchew.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=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1604081264; cv=none; d=zohomail.com; s=zohoarc; b=V3xBUE+8Fzx+nwaD32qD3FjXXotcrl3T8OiQ6octDrK2+UsJbriEeYasPTrlLQcXgSkQWbxDvheKcH2IZTACtIIGyC+3dw2MRH4bGd7YdU+tlWxIqCtgF4adXjClVB1X/0lBUzUvWR0RoyqK3Y3WcPgMAGdRhIQL9M0jvQynHDk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1604081264; h=Content-Transfer-Encoding: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=CcqYYL+qDjoLJPUdpp6J8eO2OBjnLk8kyGHylqAsx/4=; b=fv+ScFdRIvAMXYgtDCjb6x6Lyeuf3DDFXo/kWZV04WRv5h1bIm/sU1zMfy+3Bf9CPhN6nGC/XJ88tmKWVFQxw4r+QEvqAT8dw65AYKCYlJr/rFrmbv999TsCR41YnS0XA2/q16Iw9B7COCkqE4AWBtxC2NArJWEVhSEHFL6SV0o= 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 1604081264752712.3332725201659; Fri, 30 Oct 2020 11:07:44 -0700 (PDT) Received: from localhost ([::1]:41566 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kYYoR-0006p7-Bs for importer@patchew.org; Fri, 30 Oct 2020 14:07:43 -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) 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) 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) 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 Content-Transfer-Encoding: quoted-printable 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; 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" 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); } =20 +static int virtio_iommu_notify_flag_changed(IOMMUMemoryRegion *iommu_mr, + IOMMUNotifierFlag old, + IOMMUNotifierFlag new, + Error **errp) +{ + if (old =3D=3D IOMMU_NOTIFIER_NONE) { + trace_virtio_iommu_notify_flag_add(iommu_mr->parent_obj.name); + } else if (new =3D=3D 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 =3D VIRTIO_DEVICE(dev); @@ -1116,6 +1129,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 { 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 vi= rt_end, uint64_t phys_start, uint32_t flags) "mr=3D%s virt_start=3D0x%"PRIx= 64" virt_end=3D0x%"PRIx64" phys_start=3D0x%"PRIx64" flags=3D%d" virtio_iommu_notify_unmap(const char *name, uint64_t virt_start, uint64_t = virt_end) "mr=3D%s virt_start=3D0x%"PRIx64" virt_end=3D0x%"PRIx64 virtio_iommu_remap(const char *name, uint64_t virt_start, uint64_t virt_en= d, uint64_t phys_start) "mr=3D%s virt_start=3D0x%"PRIx64" virt_end=3D0x%"PR= Ix64" phys_start=3D0x%"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" =20 # virtio-mem.c virtio_mem_send_response(uint16_t type) "type=3D%" PRIu16 --=20 2.29.1 From nobody Thu May 9 20:25:29 2024 Delivered-To: importer@patchew.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=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1604081458; cv=none; d=zohomail.com; s=zohoarc; b=BA/8LtPbwInlK1nlc7riGht3T8Ccx+cPqm6XMApQnvfe4b05wAYvCMmrIt9FjrqFF54uBlzLkx/TzsFluR9juS35ntuB8zRpLzYOQ9vkrG4ZURNkbgV9T4+PCFXs3bScPAczmPY3TLfH73iJfv1keUJaiPdewpHcndGp+V8HanA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1604081458; h=Content-Transfer-Encoding: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=Ef4X5GDU46mHK5Ifa4jRh1y2HrDd3BRHGBVmcwvvC1M=; b=Uq1ZqiqmqxbwEN5WU9hQEDVO2kRmK5U2xr7leuAlRPpUf9ssgb91rwBNJXKX3zUBG9ygCc2ZhDk4da8beeTja9u7kyqbo++meOM0Eknx1OnFx0rV77iyeVr9069P9DvV3poGtWm3VmVYYRZrpFIujnRYWWKMDBb7jGWCALDSs90= 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 1604081458610975.6767314987811; Fri, 30 Oct 2020 11:10:58 -0700 (PDT) Received: from localhost ([::1]:54612 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kYYrZ-0003ob-AV for importer@patchew.org; Fri, 30 Oct 2020 14:10:57 -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) 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) 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-Google-Smtp-Source: ABdhPJyvjrVBuvWTLr1pBGxHh3iCxmc1/5yhCR4ruJjTbwytJSb8BSBlxnjnOMRAY5r0WFkO3t7MDg== X-Received: by 2002:a7b:cb54:: with SMTP id v20mr4098589wmj.149.1604081155108; 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 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 Content-Transfer-Encoding: quoted-printable 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; 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" 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(+) 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 pa= ge + * size mask limitations to the virtual IOMMU. + * + * Optional method: if this method is not provided, then the default g= lobal + * page mask is used. + * + * @iommu: the IOMMUMemoryRegion + * + * @page_size_mask: a bitmask of supported page sizes. At least one bi= t, + * representing the smallest page size, must be set. Additional set bi= ts + * 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 indiscrimin= ate + * 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); }; =20 typedef struct CoalescedMemoryRange CoalescedMemoryRange; @@ -1409,6 +1435,18 @@ int memory_region_iommu_attrs_to_index(IOMMUMemoryRe= gion *iommu_mr, */ int memory_region_iommu_num_indexes(IOMMUMemoryRegion *iommu_mr); =20 +/** + * 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(I= OMMUMemoryRegion *iommu_mr, return ret; } =20 +int memory_region_iommu_set_page_size_mask(IOMMUMemoryRegion *iommu_mr, + uint64_t page_size_mask, + Error **errp) +{ + IOMMUMemoryRegionClass *imrc =3D IOMMU_MEMORY_REGION_GET_CLASS(iommu_m= r); + int ret =3D 0; + + if (imrc->iommu_set_page_size_mask) { + ret =3D imrc->iommu_set_page_size_mask(iommu_mr, page_size_mask, e= rrp); + } + return ret; +} + int memory_region_register_iommu_notifier(MemoryRegion *mr, IOMMUNotifier *n, Error **errp) { --=20 2.29.1 From nobody Thu May 9 20:25:29 2024 Delivered-To: importer@patchew.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=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1604081359; cv=none; d=zohomail.com; s=zohoarc; b=K1mHRUf8BbjDUXWRVVOxhIU2HhRXA/bndZXget4cww+VTEcaVMK7Wn+2YTvEfjm9DKrHqOXjfdCIZV2+G4DwSwr6UBip9S5FwKmUOM3q5MNtECBUZZkJobMaxCy1Jmf6YfAIrRDNZGhH7/6z5Q9EPY+NeFO6KQyEJxbcIqE07pU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1604081359; h=Content-Transfer-Encoding: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=12Ju8kXQSFpn0papdnxccSNLTxeP7E2Kw7ISAbJMDvA=; b=Xal3M1biIeko1og8RKEHGMcrcWw2wgTzD2Fgc5EIxbvWfzqSKAZGf8lE091EC/WP6tAPEjQUtyOa/lJqH71IBP+dwnX1AO9zsWiEUDPiFvE7g150kPrCC99duPIueDl8OW1xYAQxu/Z61xXutT6iTUulS6ReSe7pcfJ7W6Iodh4= 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 1604081359635192.90241518173673; Fri, 30 Oct 2020 11:09:19 -0700 (PDT) Received: from localhost ([::1]:49050 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kYYpy-0001RW-DK for importer@patchew.org; Fri, 30 Oct 2020 14:09:18 -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) 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) 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) 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 Content-Transfer-Encoding: quoted-printable 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; 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" 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 *l= istener, int128_get64(llend), iommu_idx); =20 + ret =3D memory_region_iommu_set_page_size_mask(giommu->iommu, + container->pgsizes, + &err); + if (ret) { + g_free(giommu); + goto fail; + } + ret =3D memory_region_register_iommu_notifier(section->mr, &giommu= ->n, &err); if (ret) { --=20 2.29.1 From nobody Thu May 9 20:25:29 2024 Delivered-To: importer@patchew.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=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1604081556; cv=none; d=zohomail.com; s=zohoarc; b=H+luFXsJOZK33Jkaz1SsqBpzbmY30/nm7/WKJn7vva20hDVmmcS6Ko/pRD26/m+ocCQR8GCY70DPBDSzu/WTHGpEASI/yeZFK8HogU0O2Cr5LWPrhPWYdsev20xph/kq09UZsun9xxuwWLuqHUSPkycF4zV7tNuolooGvIdpAbA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1604081556; h=Content-Transfer-Encoding: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=Dg6KgMRhe+BDU/aQn0+rRvWHE//ly0GmnJbDrG3nhDE=; b=BLD0h5mHqTtC8y9mXJprPz7jnWI6w4ThrDYrqxV5mXiaAAWsAnyqfco5AkxxmpyjKBKovnwUs6X1Dd/odKOCWQSpv8PdLBgLN+TP4zKISOl0YrIWgDK92a6EaD6nwGZRC3O6GbmyQw3Y9Mxwo5Ae9Cre9vxjKUDl6nJgrTwWTbI= 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 1604081556602948.9788266862412; Fri, 30 Oct 2020 11:12:36 -0700 (PDT) Received: from localhost ([::1]:58524 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kYYt9-0005Pc-9z for importer@patchew.org; Fri, 30 Oct 2020 14:12:35 -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) 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) 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-Google-Smtp-Source: ABdhPJy3/qP4TMDnHcXus1pOkM+f0hcMY2/bDgqtnQRcC9NNwauMYaaelvovxL5LYEb6mZDalSqDLw== X-Received: by 2002:a1c:e006:: with SMTP id x6mr4150190wmg.107.1604081158148; 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 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 Content-Transfer-Encoding: quoted-printable 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; 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" 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(+) 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(IOMMUMemor= yRegion *iommu_mr, return 0; } =20 +/* + * The default mask (TARGET_PAGE_MASK) is the smallest supported guest gra= nule, + * for example 0xfffffffffffff000. When an assigned device has page size + * restrictions due to the hardware IOMMU configuration, apply this restri= ction + * to the mask. + */ +static int virtio_iommu_set_page_size_mask(IOMMUMemoryRegion *mr, + uint64_t new_mask, + Error **errp) +{ + IOMMUDevice *sdev =3D container_of(mr, IOMMUDevice, iommu_mr); + VirtIOIOMMU *s =3D sdev->viommu; + uint64_t cur_mask =3D 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) =3D=3D 0) { + error_setg(errp, "virtio-iommu page mask 0x%"PRIx64 + " is incompatible with mask 0x%"PRIx64, cur_mask, new_m= ask); + return -1; + } + + /* + * After the machine is finalized, we can't change the mask anymore. I= f 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 =3D ctz64(new_mask); + int cur_granule =3D ctz64(cur_mask); + + if (new_granule !=3D 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 !=3D 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 &=3D new_mask; + return 0; +} + static void virtio_iommu_device_realize(DeviceState *dev, Error **errp) { VirtIODevice *vdev =3D VIRTIO_DEVICE(dev); @@ -1130,6 +1179,7 @@ static void virtio_iommu_memory_region_class_init(Obj= ectClass *klass, imrc->translate =3D virtio_iommu_translate; imrc->replay =3D virtio_iommu_replay; imrc->notify_flag_changed =3D virtio_iommu_notify_flag_changed; + imrc->iommu_set_page_size_mask =3D virtio_iommu_set_page_size_mask; } =20 static const TypeInfo virtio_iommu_info =3D { 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 vi= rt_end, uint64_t phys_start, uint32_t flags) "mr=3D%s virt_start=3D0x%"PRIx= 64" virt_end=3D0x%"PRIx64" phys_start=3D0x%"PRIx64" flags=3D%d" virtio_iommu_notify_unmap(const char *name, uint64_t virt_start, uint64_t = virt_end) "mr=3D%s virt_start=3D0x%"PRIx64" virt_end=3D0x%"PRIx64 virtio_iommu_remap(const char *name, uint64_t virt_start, uint64_t virt_en= d, uint64_t phys_start) "mr=3D%s virt_start=3D0x%"PRIx64" virt_end=3D0x%"PR= Ix64" phys_start=3D0x%"PRIx64 +virtio_iommu_set_page_size_mask(const char *name, uint64_t old, uint64_t n= ew) "mr=3D%s old_mask=3D0x%"PRIx64" new_mask=3D0x%"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" =20 --=20 2.29.1 From nobody Thu May 9 20:25:29 2024 Delivered-To: importer@patchew.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=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1604081634; cv=none; d=zohomail.com; s=zohoarc; b=e6Byr4IMLb1LXPwt1/GbIlhWl8y3KdRR/jTjgeLBA+TpjwiscLR8rSsgT+G1xN6iBpCecdRGH7csm/eFbqXn0VnIdkb7YoWk7u6LfA7lpqv2BSTpSpyNgyD0EPCqXKXdKUudTywNZhBxkUi2gtGvbFubndx7WB25YPNFcFdZ1ss= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1604081634; h=Content-Transfer-Encoding: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=PVmUxGETfBJ3WJRj1ZG9T2/QT+bDC3bRHPQVEh7hMSk=; b=DR3YePrX23pd/4/gDEse3lo8IQya4M3QDCx6fYAPD4nTdtUExHaIAMm1CBK8HsS1uYlGJAJQjCAIpXmnqbDwJCuqzkj19fv5Rf/ILXiGKTdHxVJe/Yfn4BztLjfKoQDEDLwmWQOh32DePK7Rh5lJLFOMRFHySsGpjeErVg3kYdw= 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 1604081634492928.8096937274047; Fri, 30 Oct 2020 11:13:54 -0700 (PDT) Received: from localhost ([::1]:60638 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kYYuO-0006Kd-RB for importer@patchew.org; Fri, 30 Oct 2020 14:13:52 -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) 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) 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) 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 Content-Transfer-Encoding: quoted-printable 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; 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" 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 *l= istener, } =20 if (try_unmap) { + if (llsize =3D=3D int128_2_64()) { + /* The unmap ioctl doesn't accept a full 64-bit span. */ + llsize =3D int128_rshift(llsize, 1); + ret =3D vfio_dma_unmap(container, iova, int128_get64(llsize)); + if (ret) { + error_report("vfio_dma_unmap(%p, 0x%"HWADDR_PRIx", " + "0x%"HWADDR_PRIx") =3D %d (%m)", + container, iova, int128_get64(llsize), ret); + } + iova +=3D int128_get64(llsize); + } ret =3D vfio_dma_unmap(container, iova, int128_get64(llsize)); if (ret) { error_report("vfio_dma_unmap(%p, 0x%"HWADDR_PRIx", " --=20 2.29.1