From patchwork Thu Oct 8 17:15:49 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: 271809 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 A13DDC433DF for ; Thu, 8 Oct 2020 17:20:35 +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 E8030221FD for ; Thu, 8 Oct 2020 17:20:32 +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="v9HfeWHe" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E8030221FD 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]:57754 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kQZah-00019o-Rj for qemu-devel@archiver.kernel.org; Thu, 08 Oct 2020 13:20:31 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50504) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kQZXA-0004gx-DI for qemu-devel@nongnu.org; Thu, 08 Oct 2020 13:16:52 -0400 Received: from mail-wr1-x443.google.com ([2a00:1450:4864:20::443]:36737) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kQZX8-0006e1-Qr for qemu-devel@nongnu.org; Thu, 08 Oct 2020 13:16:52 -0400 Received: by mail-wr1-x443.google.com with SMTP id z1so7457095wrt.3 for ; Thu, 08 Oct 2020 10:16: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=wm2zb0owiv9tq4nre7MhuXhiCixqU1B1oDsIMQzJnyg=; b=v9HfeWHeCnq5E8/UUljUKtOmYwMtBoNa3MA940kpi6NUdfJCJRyM/BhMa86iJKBhVH yjxfKh28Mhz/w7dDLYGNYHDrm4YM7+FvX+FFQMuQ7YkW4wBOa5yNeBqkhS8UeLJmwDvX z8cgcF4l6tfkNCeaeHmHKSLnGP7VY8mkwHHIy2ubF73Se/46CKINlF5owwJ4E/lj1i4X s7AHV+bs2PZc2GRgMFQg6TIrf/gmJ1gVKJFsfCQ5n/8NlXfdrNK+a3Dbd9mbsHhJe8Xl WGcN3ugtgFQJUSjcIFrA2CrYgN0yfwPkjhey0dJ4irrYU1oba+QBtGZj13wrdm6+A1dw l91A== 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=wm2zb0owiv9tq4nre7MhuXhiCixqU1B1oDsIMQzJnyg=; b=JkqouV016rcTUBzvYF9oCNLSDvYIf9dWC366kUV9Q8S1ZKLb2N4YzFvYHHGcd+36Dp dG2dCbrMW2OLpXWzKq8zGCXrhmNNJ8uhM1KuUiv0s+akhj8AxUED3SDpCZZ+po8U+wHU y6ApUrj2NMTDWcq4fksjskLbs0od6ibXK8dkpOeC+GLZTw5oL2kU48FXFmiPL6N0OqpT j/RRxt6vhZueMM30m7Q4kHeA4PV0crJ0O9IlZcKCtdJqZ9R15QWMfVSk4atBLdvjKv6K q4pu4HV9G6H6+MkuYW5pF8JCTaehiRHNH51NK0/s9YZIW3sUCTrYHvlCmMxgAo/AVHth Ns6Q== X-Gm-Message-State: AOAM530/iRc4PrWTouTbEkGFy1fIWzhhUZWTNKMNmB93yGrl0pwC4RSD z7GCYyjjinzjxVMmWzZiBbTgmw== X-Google-Smtp-Source: ABdhPJwPB4T3aZZHNUYRyJocMaJAoJqGIzqz7WLsjsOpJgV5jAkMELcDyh2mFNm8NBppHWs+3rrgoA== X-Received: by 2002:adf:c5c3:: with SMTP id v3mr10793943wrg.205.1602177409417; Thu, 08 Oct 2020 10:16:49 -0700 (PDT) Received: from localhost.localdomain ([2001:1715:4e26:a7e0:116c:c27a:3e7f:5eaf]) by smtp.gmail.com with ESMTPSA id x1sm719413wrl.41.2020.10.08.10.16.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Oct 2020 10:16:48 -0700 (PDT) From: Jean-Philippe Brucker To: eric.auger@redhat.com, alex.williamson@redhat.com Subject: [PATCH v10 01/10] virtio-iommu: Fix virtio_iommu_mr() Date: Thu, 8 Oct 2020 19:15:49 +0200 Message-Id: <20201008171558.410886-2-jean-philippe@linaro.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201008171558.410886-1-jean-philippe@linaro.org> References: <20201008171558.410886-1-jean-philippe@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::443; envelope-from=jean-philippe@linaro.org; helo=mail-wr1-x443.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" 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") Signed-off-by: Jean-Philippe Brucker Acked-by: Eric Auger Reviewed-by: Peter Xu --- 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 a91fa2f674c..543fbbb24fb 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 Thu Oct 8 17:15:50 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: 303420 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 12EF8C433E7 for ; Thu, 8 Oct 2020 17:18:20 +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 49E5B204EF for ; Thu, 8 Oct 2020 17:18:19 +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="mj6EG3yT" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 49E5B204EF 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]:49956 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kQZYY-0006Im-2W for qemu-devel@archiver.kernel.org; Thu, 08 Oct 2020 13:18:18 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50540) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kQZXB-0004h6-Jr for qemu-devel@nongnu.org; Thu, 08 Oct 2020 13:16:53 -0400 Received: from mail-wr1-x441.google.com ([2a00:1450:4864:20::441]:33630) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kQZX9-0006eB-U8 for qemu-devel@nongnu.org; Thu, 08 Oct 2020 13:16:53 -0400 Received: by mail-wr1-x441.google.com with SMTP id m6so7473181wrn.0 for ; Thu, 08 Oct 2020 10:16: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=gIAtQOZ+zrlWQfjLRgAdZMIze9gG8ZgbjrmwZekQ+1A=; b=mj6EG3yT0yJc/G6ZQvoBaj4avhGX07sIpd+W4SBW+osrHKGbtvS47H/hVgf8QyfUHe A0auhOk72VcwzoVaK00/aISFnJryUfozXWqiWS7B/5m5Zjgf3i/PhZcT9HyhB2f+vDQy XgoRYwtXVuE+6G8TKL7KbxrBauOpsVJFOqvC0wD+RllsoWfeb+Jd8syWJhIfKEVQ3cNC LFkKzwpLCqRSyp8A8UNzjXlbnJExQ+eSTYRoTa1RFPuYaPHFumI7h6hBfvi+ldhWo3wX opZoiY+DINBx/YqI/6S6l5uutKSUWpgKurJYu/YIG4J7VdbfNNLBZ4TTbb3j+mc5AMXm BvUA== 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=gIAtQOZ+zrlWQfjLRgAdZMIze9gG8ZgbjrmwZekQ+1A=; b=cgHChoJVAnP63htJE6jXWvofaZxunEIi6Ogn8t7Hg1fbd+l6pZFWFADqlhJVswSB2Y 2WofPacnHwTrtlV821gPIxUDcWm9Lc3vinuxdfHU5fzihp/BjWEPDOKvfZXNIGJEwFG3 OiftpqB+VAJWZNOcHna58sVI6VKrBBg8qwbA4cvG2Zw0fPULg1gdWS4VLdSPZH78krb1 gVThSYVk1xidOnguwsQxRChney3ptDEQjF0UYm14jgDzmZ+K+PJKpjORvlojfbReIwSO RxforAA5ZP3PXW4Xz0/MbSZkIf7M74tsPnEfeGaCvGhVaJgywTbVl0mOVhv41o/tTpo3 v9cg== X-Gm-Message-State: AOAM533nOk85rgTgSqL4Jj6npmsbjLG8izUYqKs41EKKlUky/hLb+A03 CynYhf4JAoeS2FeSvzNlkjT94Q== X-Google-Smtp-Source: ABdhPJyF/1ViTi2qRMbTXgKqpTpGV0nnp1HpSKSEeLboXZzCr42byYjowas4ASKTAXN5tJjxEFJ+8A== X-Received: by 2002:adf:f3c4:: with SMTP id g4mr11146586wrp.207.1602177410647; Thu, 08 Oct 2020 10:16:50 -0700 (PDT) Received: from localhost.localdomain ([2001:1715:4e26:a7e0:116c:c27a:3e7f:5eaf]) by smtp.gmail.com with ESMTPSA id x1sm719413wrl.41.2020.10.08.10.16.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Oct 2020 10:16:49 -0700 (PDT) From: Jean-Philippe Brucker To: eric.auger@redhat.com, alex.williamson@redhat.com Subject: [PATCH v10 02/10] virtio-iommu: Store memory region in endpoint struct Date: Thu, 8 Oct 2020 19:15:50 +0200 Message-Id: <20201008171558.410886-3-jean-philippe@linaro.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201008171558.410886-1-jean-philippe@linaro.org> References: <20201008171558.410886-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" Store the memory region associated to each endpoint into the endpoint structure, to allow efficient memory notification on map/unmap. Signed-off-by: Jean-Philippe Brucker Acked-by: Eric Auger --- Not super confident about the reconstruct_endpoint() change since I haven't tested migration yet. Does it make sense? --- 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 543fbbb24fb..33115e82186 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; @@ -927,9 +931,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 Thu Oct 8 17:15:51 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: 303418 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 1BE5EC433DF for ; Thu, 8 Oct 2020 17:20: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 59600221FD for ; Thu, 8 Oct 2020 17:20:39 +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="eoIzj+ky" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 59600221FD 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]:58350 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kQZao-0001PT-AX for qemu-devel@archiver.kernel.org; Thu, 08 Oct 2020 13:20:38 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50558) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kQZXC-0004iV-Mi for qemu-devel@nongnu.org; Thu, 08 Oct 2020 13:16:54 -0400 Received: from mail-wr1-x443.google.com ([2a00:1450:4864:20::443]:33632) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kQZXA-0006eK-S2 for qemu-devel@nongnu.org; Thu, 08 Oct 2020 13:16:54 -0400 Received: by mail-wr1-x443.google.com with SMTP id m6so7473227wrn.0 for ; Thu, 08 Oct 2020 10:16: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=sY2gqdsWkBuC1sxr+Mc5QVPkGv0Pgw0vmK023u1HBuc=; b=eoIzj+ky+pMBGTHy3Jp4GnEMiUPXXAeYrO6omxTuH5UjMdyduCUAuQbD+isZgYVypO +WEKD2IqKrLJccgkCcmntOfU/jUJx0bK1+cojk9oEhF1IAzhsKAS3Bm65xzscAi1cyYX lCJdiSrZy+ZEA01rQonPassj9SO0rCD7bT52JYHkK8lNp3kVNEUsL67rOI5si4f/e7l4 yiSimzyxXZzSQF7ShWaMdIy0pZ5yDGgJzuBOwWQPqUvn3/9PuXKqV6eVMScnzljD5ehD A02yZ7QbiY11YDDU096GAnbsK60Hzf1jphWCArjSxyGf5y9b1lhD6lpDOpXB8Ijt4ATk Z6ag== 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=sY2gqdsWkBuC1sxr+Mc5QVPkGv0Pgw0vmK023u1HBuc=; b=qCwHnHaPL/Q4isWzuGWDixs6Tb8nL36SabvZMkdEzl3Pep8Oi929h18ZP3bzPCGJXT B4Ku/WKKDWUpfJGXtkvki7FpJPn7MsTN1Aeyb03RtdiNnfamIkBY1bZG1Nq9cwQLECuT PS3gFKWiWBdZ5aqLtqPfhYnoNh33RLgZ5YRU7JvrHwK7OxMg3kWU2Yn9fsG4WSbLNxYF snQ/ATTBKMA6vxzFkwmeZPXst88wfOLDOSiAQq21n64fk6mf/3PVxr5drvDGGBMY6Wf+ L9ZQzJVZ4zc8JOf+Xu/Fx0gN3z5Gx+YMMe3eMq+O8ej0CQE36/Jyi68Q0KOLnQo/e+2o uBUA== X-Gm-Message-State: AOAM533aEcQRqSXWsKHXaYhmPWQuhk3VWVDxr+Pz7BWgej+U3Q+AEmyV Fod4ckeoNWI3h25OJo6mB8xpkw== X-Google-Smtp-Source: ABdhPJzHEesWpc8s+O1FhavdOedGl7qTR5WFSSwbEw7s3JLpgll1m4MYOpAsADYrTPV9qP7ZMG+wzQ== X-Received: by 2002:adf:ec92:: with SMTP id z18mr11265072wrn.53.1602177411646; Thu, 08 Oct 2020 10:16:51 -0700 (PDT) Received: from localhost.localdomain ([2001:1715:4e26:a7e0:116c:c27a:3e7f:5eaf]) by smtp.gmail.com with ESMTPSA id x1sm719413wrl.41.2020.10.08.10.16.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Oct 2020 10:16:51 -0700 (PDT) From: Jean-Philippe Brucker To: eric.auger@redhat.com, alex.williamson@redhat.com Subject: [PATCH v10 03/10] virtio-iommu: Add memory notifiers for map/unmap Date: Thu, 8 Oct 2020 19:15:51 +0200 Message-Id: <20201008171558.410886-4-jean-philippe@linaro.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201008171558.410886-1-jean-philippe@linaro.org> References: <20201008171558.410886-1-jean-philippe@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::443; envelope-from=jean-philippe@linaro.org; helo=mail-wr1-x443.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 --- v10: * Use the flags from IOMMUMemoryRegion * Pass virt_start/virt_end rather than size, to avoid dealing with overflow and for consistency. --- hw/virtio/virtio-iommu.c | 53 ++++++++++++++++++++++++++++++++++++++++ hw/virtio/trace-events | 2 ++ 2 files changed, 55 insertions(+) diff --git a/hw/virtio/virtio-iommu.c b/hw/virtio/virtio-iommu.c index 33115e82186..fcdf3a819f8 100644 --- a/hw/virtio/virtio-iommu.c +++ b/hw/virtio/virtio-iommu.c @@ -125,6 +125,49 @@ 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) +{ + IOMMUTLBEntry entry; + IOMMUNotifierFlag flags = mr->iommu_notify_flags; + + if (!(flags & IOMMU_NOTIFIER_MAP)) { + return; + } + + trace_virtio_iommu_notify_map(mr->parent_obj.name, virt_start, virt_end, + paddr); + + entry.target_as = &address_space_memory; + entry.addr_mask = virt_end - virt_start; + entry.iova = virt_start; + entry.perm = IOMMU_RW; + 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; + IOMMUNotifierFlag flags = mr->iommu_notify_flags; + + if (!(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 +358,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 +388,10 @@ 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); + } + return VIRTIO_IOMMU_S_OK; } @@ -356,6 +404,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 +422,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..65a48555c78 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) "mr=%s virt_start=0x%"PRIx64" virt_end=0x%"PRIx64" phys_start=0x%"PRIx64 +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 Thu Oct 8 17:15:52 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: 271807 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 A2C7BC433E7 for ; Thu, 8 Oct 2020 17:23:02 +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 0E2DD221FE for ; Thu, 8 Oct 2020 17:23:00 +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="cQhGCYAk" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0E2DD221FE 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]:37656 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kQZd4-0004bc-UW for qemu-devel@archiver.kernel.org; Thu, 08 Oct 2020 13:22:58 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50570) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kQZXD-0004jh-JJ for qemu-devel@nongnu.org; Thu, 08 Oct 2020 13:16:55 -0400 Received: from mail-wm1-x343.google.com ([2a00:1450:4864:20::343]:34342) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kQZXC-0006eV-14 for qemu-devel@nongnu.org; Thu, 08 Oct 2020 13:16:55 -0400 Received: by mail-wm1-x343.google.com with SMTP id l15so7216271wmh.1 for ; Thu, 08 Oct 2020 10:16: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=MBcMMP4Ua2k2Hsawb+KgncwLSiAkybM0QPyQamrDzng=; b=cQhGCYAksbtlKV5fVTngQBBHJnM5wvHFTUnjin/wrRSyu3dp/V4Ru57dsLeZS8ntIm 8W68x4aLKaDH+zJstPU/eSxmZkiOu2TI99X2+ppDEUFFtdxo0QHu7D/cN8OvpLANd1tj TS1pIn0zokptu7dCp3mYJkVLkFEjh7g/IfgczAqw9l1TeVHJh+3HmO4/NiyobhiDqiyH xGqpHrFjOPYXQ60WznRuJdfFSS12VY7ljTEYqbuaMUhUbyIluFVlrG8Vp3QpqCy1nWdS I1fdgg1Hg7GX+XBNFe66WA9oQXqwdX+RrdwOnhmwkCJw7Lmy9FkHErH0EyED5tLEoput p1Fg== 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=MBcMMP4Ua2k2Hsawb+KgncwLSiAkybM0QPyQamrDzng=; b=P6Qi6YyCSrDM6YrYBDKizS7IhFfPhpwvuHhtQCMKyu3oP0vCZgsTfSQIchVOH2MMbl QoXNbBEBXA7xRUpyp+7yfJZMGcyfMLbtxUrKNMfA/LQrAJECcK8+zf7y6vBuAfcYeOsM 4u93RXmKJg2iTTo0Ngk/oJNbWgfwKdlXp4KF/r06p9Qhg211Rp/lC5t0zB/r04Ly1+V0 gmcD0lEkZODgoXrlhebJs33bda+x7pQs6M9IbavrHhzLtXc1vvrx0hsJaNuKR45+c1t5 GPT7qAaawBitGtTU9u5GFC3Y26Xu/fXU26lgk21AfMXzGm+jABhjb1z+7Gn7jVFZ4Qsw fBTw== X-Gm-Message-State: AOAM532XK+iuG7Jk8Ol9Y5HhCiKS2u/QZybE8nxY8wvR8bldvprMNEPT N4UY3vWlLsix3re1u8pOuxVlMQ== X-Google-Smtp-Source: ABdhPJwZyBPp/LT5cmBkbGm2v3+sMkXAaevxR/o2y+UkDgTmn3IJiSXmrkWUggS6ci2wWNB4Qrxg3A== X-Received: by 2002:a7b:c92c:: with SMTP id h12mr9138951wml.134.1602177412717; Thu, 08 Oct 2020 10:16:52 -0700 (PDT) Received: from localhost.localdomain ([2001:1715:4e26:a7e0:116c:c27a:3e7f:5eaf]) by smtp.gmail.com with ESMTPSA id x1sm719413wrl.41.2020.10.08.10.16.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Oct 2020 10:16:52 -0700 (PDT) From: Jean-Philippe Brucker To: eric.auger@redhat.com, alex.williamson@redhat.com Subject: [PATCH v10 04/10] virtio-iommu: Call memory notifiers in attach/detach Date: Thu, 8 Oct 2020 19:15:52 +0200 Message-Id: <20201008171558.410886-5-jean-philippe@linaro.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201008171558.410886-1-jean-philippe@linaro.org> References: <20201008171558.410886-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+qemu-devel=archiver.kernel.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 --- v10: Remove notifiers_list, rename callbacks --- 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 fcdf3a819f8..7e6e3cf5200 100644 --- a/hw/virtio/virtio-iommu.c +++ b/hw/virtio/virtio-iommu.c @@ -168,11 +168,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); + + 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; } @@ -315,6 +343,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 Thu Oct 8 17:15:53 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: 271810 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 882B2C433DF for ; Thu, 8 Oct 2020 17:18:22 +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 F29A4204EF for ; Thu, 8 Oct 2020 17:18:21 +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="dzT+qNN+" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org F29A4204EF 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]:50186 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kQZYa-0006Ob-Vq for qemu-devel@archiver.kernel.org; Thu, 08 Oct 2020 13:18:21 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50584) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kQZXE-0004l6-NC for qemu-devel@nongnu.org; Thu, 08 Oct 2020 13:16:56 -0400 Received: from mail-wm1-x344.google.com ([2a00:1450:4864:20::344]:40892) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kQZXD-0006em-5H for qemu-devel@nongnu.org; Thu, 08 Oct 2020 13:16:56 -0400 Received: by mail-wm1-x344.google.com with SMTP id k18so7288246wmj.5 for ; Thu, 08 Oct 2020 10:16: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=NJrvaC5noK4efDDLaUGkLxKqKY1PX0xU/3AIPEZvhbU=; b=dzT+qNN+eKGJOeFUDV5XHrMlR8z7nCm0BZWsg0blZMM+1BGXNgJgyQsa6lnRIA6C8w 8dOb8VLy3Y6ispRHzlN1WK3fmC3+rRj6xStC8VFmwFh2icwdwXZIAAx24ktpKl1EuN8k i7y0HA+fKE5r0SCU8c8kfD0Obx/jxemmCU9O/E8IgH94I/f3/0qwZN6lhuXK/N5BDjAM 5XjYyglb1YPke8aAR+I6BAj7Mk79n8qLttsUfLmQtbMq3ovsDFQkW8JzAezsf5H+xDqO 1ML6j4xKaXXlMiCTFiGAYNL9Qp6CxT2cG1NN961Tsxk/d99OOTKeKxww/3SV652PQ2Vm dIpw== 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=NJrvaC5noK4efDDLaUGkLxKqKY1PX0xU/3AIPEZvhbU=; b=jmOJv38Ummf1ABviQ0Sh5p24zGZkJx1idFXezHupwaweovnB9Uc1+UZedWKDe5GHIJ zzAOMwWqm9tYjg7gAfZJbqMwEsAOMXDsf8p2k+0o2TCKy4/aGu+ZiCLc0u4CpeFJqQRJ kyHY3hEHCzlRMq4IJhBsmkYI/5m+FTIu5PktuyPBfCoXrqCviXRjrhw+dJ3lvRT13ENw fh5CltQ/U9nbS7t759hhhoVyn2xmNDJVsXBRk5bytFdfJVCec73om5NEio7I7KIIvXun uRZzyWpBWZGVazmDNHgu8eH6pDEVY2JYKJsNKedgs6uSKuZ44QpL/4JGm74/CliKDDlW r/0Q== X-Gm-Message-State: AOAM530JPtwF+7pooGpzgnOeCbqyWkHFxML2E6mbECT5MuEzBclbDyJY snTVaJdxA7ijqI7yIjDo6XAa8Q== X-Google-Smtp-Source: ABdhPJyZWc0+arHc1pWWdBi6KR0sZbywZXBWTzUet4ceabFsKGD7jPDlyEl9MMyZRnDYRc/URdOn9Q== X-Received: by 2002:a1c:f008:: with SMTP id a8mr10339193wmb.155.1602177413901; Thu, 08 Oct 2020 10:16:53 -0700 (PDT) Received: from localhost.localdomain ([2001:1715:4e26:a7e0:116c:c27a:3e7f:5eaf]) by smtp.gmail.com with ESMTPSA id x1sm719413wrl.41.2020.10.08.10.16.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Oct 2020 10:16:53 -0700 (PDT) From: Jean-Philippe Brucker To: eric.auger@redhat.com, alex.williamson@redhat.com Subject: [PATCH v10 05/10] virtio-iommu: Add replay() memory region callback Date: Thu, 8 Oct 2020 19:15:53 +0200 Message-Id: <20201008171558.410886-6-jean-philippe@linaro.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201008171558.410886-1-jean-philippe@linaro.org> References: <20201008171558.410886-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" 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 --- v10: Homogenize tracepoint arguments --- hw/virtio/virtio-iommu.c | 41 ++++++++++++++++++++++++++++++++++++++++ hw/virtio/trace-events | 1 + 2 files changed, 42 insertions(+) diff --git a/hw/virtio/virtio-iommu.c b/hw/virtio/virtio-iommu.c index 7e6e3cf5200..d2b96846134 100644 --- a/hw/virtio/virtio-iommu.c +++ b/hw/virtio/virtio-iommu.c @@ -861,6 +861,46 @@ 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_unmap(mr, interval->low, interval->high); + virtio_iommu_notify_map(mr, interval->low, interval->high, + mapping->phys_addr); + 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); @@ -1091,6 +1131,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 65a48555c78..16f4729db4b 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) "mr=%s virt_start=0x%"PRIx64" virt_end=0x%"PRIx64" phys_start=0x%"PRIx64 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 Thu Oct 8 17:15:54 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: 271808 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 A1CCBC433E7 for ; Thu, 8 Oct 2020 17:20:41 +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 170EE221FD for ; Thu, 8 Oct 2020 17:20:41 +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="doi9cAZQ" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 170EE221FD 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]:58560 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kQZaq-0001Ub-3I for qemu-devel@archiver.kernel.org; Thu, 08 Oct 2020 13:20:40 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50606) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kQZXG-0004oV-Bs for qemu-devel@nongnu.org; Thu, 08 Oct 2020 13:16:58 -0400 Received: from mail-wr1-x444.google.com ([2a00:1450:4864:20::444]:40481) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kQZXE-0006f3-D8 for qemu-devel@nongnu.org; Thu, 08 Oct 2020 13:16:58 -0400 Received: by mail-wr1-x444.google.com with SMTP id j2so7460392wrx.7 for ; Thu, 08 Oct 2020 10:16: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=ljSwi0VqUen6R8hy1IfuL/+6iifQubTRGt68McPlcgo=; b=doi9cAZQ0koh8PNw4YY9QDkciPnH/LbV+T6Q80+0i0SHilBA53fWya7Q9c4w81Ydf5 2HDiKCbLTbPqZm5xKUd7WzeoDQjq6PghKXBGP1CI/TeJRfaiFbUdjscq2IHULl6w7p5W H8DxkJWLHvrAA4P+JTmHMIkrFmy9uXmXwkyieQ6nb5TscQWtjeCud607umKraQOU7v11 C5mixESvp3VV7pNEbvmJiUm326NOoUIcs0zhAobiyDAhc2K/i77LoOqecnRmfenKlXcn sP2KG4He2BOeZHE1sjwVZjRtYffBiIMwvH5Y0GO4Ra+IlWTQq4IBP0iuq9hdm3vlKEOw cddA== 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=ljSwi0VqUen6R8hy1IfuL/+6iifQubTRGt68McPlcgo=; b=dp9HXK5WWIcXO27phfJjex0gfi/6XqDfngjfkan5SFb3yAR8FTBkcYYXZ6+JCpBkZ5 Dsf/feFnqa+EUlOqRq1vmInYjPI5InJIR3tdqGPzv8XnfQI1G2B/fLxQleGcCCk5raQT 2VZqKXwNDckmo0JpI6mZkOjs73E+70fsK/s2pVVqZqdKesmJXnvP8CmjcaM3ST4p6ETL eDyI8/Xzkv6RYm9MFZ3rMPaktI6wCdOFpFcUnscOPuk1k6cQcCNN9Q+rHIJJWZGGfaAZ nPHJ6o453Qs2L/UDqUXQtP8Ug1rKJPinYekNE7/ZdrY/aSVOrH5C4OZ8Olv3YroQ+HoV bT9w== X-Gm-Message-State: AOAM531m8/7ZzhkV3WEal14GDd2baLtv0GJgl9CH0hNLPLzqz6eCGqLD zIhOdyQjS4imiEUzlMuNhLixVA== X-Google-Smtp-Source: ABdhPJxEM/eWuc6hOMW1CY3bl61h0Z3/m0E+EokTzVraBb7ekuAI0ZADWeIiWkAtj6XjVUx8HIyx/w== X-Received: by 2002:adf:d089:: with SMTP id y9mr10091800wrh.234.1602177414971; Thu, 08 Oct 2020 10:16:54 -0700 (PDT) Received: from localhost.localdomain ([2001:1715:4e26:a7e0:116c:c27a:3e7f:5eaf]) by smtp.gmail.com with ESMTPSA id x1sm719413wrl.41.2020.10.08.10.16.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Oct 2020 10:16:54 -0700 (PDT) From: Jean-Philippe Brucker To: eric.auger@redhat.com, alex.williamson@redhat.com Subject: [PATCH v10 06/10] virtio-iommu: Add notify_flag_changed() memory region callback Date: Thu, 8 Oct 2020 19:15:54 +0200 Message-Id: <20201008171558.410886-7-jean-philippe@linaro.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201008171558.410886-1-jean-philippe@linaro.org> References: <20201008171558.410886-1-jean-philippe@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::444; envelope-from=jean-philippe@linaro.org; helo=mail-wr1-x444.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. Signed-off-by: Bharat Bhushan Signed-off-by: Jean-Philippe Brucker Acked-by: Eric Auger --- v10: * Use notifier flags instead of notifiers_list * Homogenize tracepoints --- 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 d2b96846134..8823bfc804a 100644 --- a/hw/virtio/virtio-iommu.c +++ b/hw/virtio/virtio-iommu.c @@ -901,6 +901,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); @@ -1132,6 +1145,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 16f4729db4b..9108992bcc3 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) "mr=%s virt_start=0x%"PRIx64" virt_end=0x%"PRIx64" phys_start=0x%"PRIx64 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 mr=%s" +virtio_iommu_notify_flag_del(const char *name) "del notifier mr=%s" # virtio-mem.c virtio_mem_send_response(uint16_t type) "type=%" PRIu16 From patchwork Thu Oct 8 17:15:55 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: 303417 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 D1B6BC43457 for ; Thu, 8 Oct 2020 17:23:02 +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 2D853221FF for ; Thu, 8 Oct 2020 17:23:01 +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="W8K24xAa" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2D853221FF 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]:37776 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kQZd7-0004eL-0o for qemu-devel@archiver.kernel.org; Thu, 08 Oct 2020 13:23:01 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50612) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kQZXH-0004qG-1S for qemu-devel@nongnu.org; Thu, 08 Oct 2020 13:16:59 -0400 Received: from mail-wr1-x444.google.com ([2a00:1450:4864:20::444]:44870) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kQZXF-0006fM-DC for qemu-devel@nongnu.org; Thu, 08 Oct 2020 13:16:58 -0400 Received: by mail-wr1-x444.google.com with SMTP id t9so7447621wrq.11 for ; Thu, 08 Oct 2020 10:16: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=+aXjyG0i9oQTA80CkQjiRbI+6mZLaGZ14n2CNbod0io=; b=W8K24xAan3nU461ZtUCOJDnTvMW8hiJpuiuR+l0BiT6hp/MaLrTs/mPdK610q8iff2 h3khiJ/AvmxtnO4UGE38f0TRsVf2rjop4Um+LPsUl6Z/ZlH9fg32zkrxnKgQzdJyykim 6wjoUqhW/Y7i3rM00i4OC7eW7UKkFzH99i0evDP/FbclG0ywi7wMD0wBbeAWe3q9qkY9 PHpAtwv/derzbP7jZhq5YhfMP3NhnMc4ssIDudguGfaP/q+V43PVamSJld+8P5halW1i Ikz7qqp7h4q0269BwbLLz7VLstT8b2emi5chL4K2B0Kjr1tzaNZFU02w7yVlkfijETzR B/MQ== 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=+aXjyG0i9oQTA80CkQjiRbI+6mZLaGZ14n2CNbod0io=; b=NwQOtu8ehBpg3olmQrzQ8M3hBJAjJ22snwxs/wbuoIf1taYjQzYPPMQSSBbCX7Ab/c BxEbhq0pn4i2BBTlXbM7pe5RqKkGiuPEndq8E2fPSjnyx12Hy8iB20yCDtrfD/E295aT l9UoyjAR2gBZOT6AN3FeUtLV9Vzi8wtev+n04IxQ6pqD4n+Eshdv4PqIYhr9HnAxaG+s WLvBI2Hkvw5hPyhZLhvaRSOH+KxqFrSARiGH7M87ynzTFkx0doBE7cwoblOOMIekQhIA IZqeAp7nAJZy+VCSBe+2clqXqtjZI3/MyKPdGKaBb1tsyxPr+iTja31iY4nKDczuzZB0 /w9Q== X-Gm-Message-State: AOAM530Oxq7AD/ESXr4P9ejEQK3FqisyMud9TgbbwaBRdx2Z3LBmroLw 1hASNrGhtQSL6P6yhDBtjPg8Jw== X-Google-Smtp-Source: ABdhPJxoYgK5NxUIsI+NyZx99DfZ0TKTcLWZnW0VkuBDeHAa7nLJ/VEaTVU+dl3Zhbk8KvWiTNOdCg== X-Received: by 2002:a5d:5482:: with SMTP id h2mr1057165wrv.165.1602177416053; Thu, 08 Oct 2020 10:16:56 -0700 (PDT) Received: from localhost.localdomain ([2001:1715:4e26:a7e0:116c:c27a:3e7f:5eaf]) by smtp.gmail.com with ESMTPSA id x1sm719413wrl.41.2020.10.08.10.16.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Oct 2020 10:16:55 -0700 (PDT) From: Jean-Philippe Brucker To: eric.auger@redhat.com, alex.williamson@redhat.com Subject: [PATCH v10 07/10] memory: Add interface to set iommu page size mask Date: Thu, 8 Oct 2020 19:15:55 +0200 Message-Id: <20201008171558.410886-8-jean-philippe@linaro.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201008171558.410886-1-jean-philippe@linaro.org> References: <20201008171558.410886-1-jean-philippe@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::444; envelope-from=jean-philippe@linaro.org; helo=mail-wr1-x444.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 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. Signed-off-by: Bharat Bhushan Signed-off-by: Jean-Philippe Brucker Reviewed-by: Eric Auger Acked-by: Peter Xu --- v10: Add errp parameter --- include/exec/memory.h | 26 ++++++++++++++++++++++++++ softmmu/memory.c | 13 +++++++++++++ 2 files changed, 39 insertions(+) diff --git a/include/exec/memory.h b/include/exec/memory.h index dee09851622..c2da8381bec 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -382,6 +382,20 @@ struct IOMMUMemoryRegionClass { * @iommu: the IOMMUMemoryRegion */ int (*num_indexes)(IOMMUMemoryRegion *iommu); + + /* + * Set supported IOMMU page size + * + * If supported, allows to restrict the page size mask that can be supported + * with a given IOMMU memory region. For example, to propagate host physical + * IOMMU page size mask limitations to the virtual IOMMU. + * + * 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; @@ -1389,6 +1403,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 fa280a19f7f..5c855a02704 100644 --- a/softmmu/memory.c +++ b/softmmu/memory.c @@ -1811,6 +1811,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 Thu Oct 8 17:15:56 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: 303416 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 6DF9CC433E7 for ; Thu, 8 Oct 2020 17:24:34 +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 C36FA204EF for ; Thu, 8 Oct 2020 17:24:33 +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="EyrxZREV" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C36FA204EF 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]:42016 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kQZea-0006NB-B9 for qemu-devel@archiver.kernel.org; Thu, 08 Oct 2020 13:24:32 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50628) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kQZXI-0004tL-Ad for qemu-devel@nongnu.org; Thu, 08 Oct 2020 13:17:00 -0400 Received: from mail-wr1-x441.google.com ([2a00:1450:4864:20::441]:45192) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kQZXG-0006fW-N2 for qemu-devel@nongnu.org; Thu, 08 Oct 2020 13:16:59 -0400 Received: by mail-wr1-x441.google.com with SMTP id e17so7441976wru.12 for ; Thu, 08 Oct 2020 10:16: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=L1iwuBZlH4emBp6JRkoZKYjiVdXM0akqIZ599ofxEZI=; b=EyrxZREVUHgy5vw5UiEmWm03eUn0arKOFhK+mjzTZ7AeN/CRCExxvbDQ6i6krXVuKe 9UFs4pVf6DVAHtgUO6pf2MNpnc8BdOkkcJU958m577J4kFZMZPVdvEQCUHhYFQ+VLdrx txNKQIIhOwSYvr8xV5DGNiIkAf972NCmn8JKUVa1lR05vRXh37sRheKkUw0S9H4cY0wk T/+FQQuKpwFB9C6hrT0Jg/Tj5RZ8KaOq5RS4A1bFs+xoV3JcEUHhLpFqdnDGgcX96tNB DBaWdY4tfrXFvEO6cjSiV9GE3DMh39O2Q1q86+QrS6/N4UoEMNBTa1LO63XzJ10wx3wp 6vgw== 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=L1iwuBZlH4emBp6JRkoZKYjiVdXM0akqIZ599ofxEZI=; b=mPlDbWP+GL/VBMVT6hgjpAju1gp3hZ0BxDR1XMgGeenDUNdceswJby8DpWKGnBjoJP 86Q4p/7aYhezczNoVIfX9KjM6FWI3/jNlYUgB+bQK+DMLnHT7Am8HhCD+Hda/fZBzkIG nWQRnGux/QhW5N6B6MatQqUhV49MH2Sg5KSpTndDiZQAa8KRx33wFZ5Ielseaersop3u LF9WdgAokWdLJuoNfavQia4eviRoelep8QDq25xQJ3hdf0YpUrJJrLpKgO855HGkvxtY 1sdn8kR/b8IhnE4V/Z64a/qkfXO/5VXUcN/+oowtEds1rcR39JXiU57bhIkq36rfcoqY 9aYg== X-Gm-Message-State: AOAM5320+PBYlewNvX5KLDBRNj2KaSp3vGqew1e5IybRRRhM+BZYvkFd NFWrFIwGZg4lOtPtQhUWs5zcdA== X-Google-Smtp-Source: ABdhPJwUD5wqrfTkVf7dJLrztglZojWpDXiWoQLF71FQHxzME82ACP02kH50uvUg3wnfQsj9ZFwVzQ== X-Received: by 2002:a5d:5146:: with SMTP id u6mr11122776wrt.255.1602177417377; Thu, 08 Oct 2020 10:16:57 -0700 (PDT) Received: from localhost.localdomain ([2001:1715:4e26:a7e0:116c:c27a:3e7f:5eaf]) by smtp.gmail.com with ESMTPSA id x1sm719413wrl.41.2020.10.08.10.16.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Oct 2020 10:16:56 -0700 (PDT) From: Jean-Philippe Brucker To: eric.auger@redhat.com, alex.williamson@redhat.com Subject: [PATCH v10 08/10] vfio: Set IOMMU page size as per host supported page size Date: Thu, 8 Oct 2020 19:15:56 +0200 Message-Id: <20201008171558.410886-9-jean-philippe@linaro.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201008171558.410886-1-jean-philippe@linaro.org> References: <20201008171558.410886-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. Signed-off-by: Bharat Bhushan Signed-off-by: Jean-Philippe Brucker Acked-by: Alex Williamson Reviewed-by: Eric Auger --- 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 Thu Oct 8 17:15:57 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: 303419 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 B2E99C433DF for ; Thu, 8 Oct 2020 17:18:46 +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 31E3F204EF for ; Thu, 8 Oct 2020 17:18:46 +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="rgYl28lo" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 31E3F204EF 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]:50808 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kQZYy-0006ev-4F for qemu-devel@archiver.kernel.org; Thu, 08 Oct 2020 13:18:44 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50656) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kQZXJ-0004wR-R7 for qemu-devel@nongnu.org; Thu, 08 Oct 2020 13:17:01 -0400 Received: from mail-wm1-x343.google.com ([2a00:1450:4864:20::343]:39760) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kQZXH-0006fh-W2 for qemu-devel@nongnu.org; Thu, 08 Oct 2020 13:17:01 -0400 Received: by mail-wm1-x343.google.com with SMTP id d3so7298077wma.4 for ; Thu, 08 Oct 2020 10:16:59 -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=7wgbcRbIFliMePbKm6Q5mkeuUC4ljzQPMAK2NaADXH4=; b=rgYl28lo9ds5EHPl0QJhjUSisk9hqTi+rpnJ+tzy1oNSxphqXM+RSDQ+kUTk5a3SeO OHw4Hr8d4NQsXhQdJI+0jRq8+kqTArBO47w2Kun2wxsye3bNsGj41MlpTcGYwOoGn6+0 VT1detNeMxGshnx85IFnUMLBK7LmrvzT9bRDNoGSrJl1fMiPzRljktUvHXHPuqDAENzU HfCfYwdnjKaFLRy6+ctuyQNS9+qEvrn1IXRjdwBWizSiWOr6dloJjVJl6tEJ5/RqHua2 A3clYucgXXTD5kUkD6lxjM+ka4Trt4ObNM7vRpFBhPu+aE0Ckiy5s1ohlfPKdjgk/KG1 OxVg== 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=7wgbcRbIFliMePbKm6Q5mkeuUC4ljzQPMAK2NaADXH4=; b=ZTwh1BpvyWMoKXh5fqjPfD2lwYBNbZspih0WowPYn8+/eovcyILFk6RcSlGfXjkD5A +bXcbJEoJoRSTUhoGWMch/WR0ca3THTLhW3nU5y2nNQUvyK7Ns6qbeWhPVQBKFTkmOqJ 8THrf6QpdNu8W4BlPT16Wd5Hfw8H2FjFb5ETxYOYwvgRvkHg6zBwsrF8KiZdx/3Si4rV rfK+LjQ7bg94PyPmc10Gn1bSbtbvePIgGJRArS0WKyyG6P0qC5lGqSmhLSWFdLBZEw00 7RjVme3J8XD+94GSxw63BcWoXAJ1jxSAZJZCo9ePEX4fK3fJiNUL9yJj2CM4pRMm75Co D3bw== X-Gm-Message-State: AOAM533PoLcWfmVLLTl2iqLIZAJvhSoth/rtBZXf8MI9NI7yP3JbxLsF mTLrMsEofI/P7uw2sV1UGGzUDQ== X-Google-Smtp-Source: ABdhPJw7Hs3XKpGnf7TX8L0e5srtXTzJGGpauZIcG45vs78HB+CHxcBJCukiCuECFnYOQ8zOoW8XDg== X-Received: by 2002:a1c:b103:: with SMTP id a3mr10049448wmf.68.1602177418602; Thu, 08 Oct 2020 10:16:58 -0700 (PDT) Received: from localhost.localdomain ([2001:1715:4e26:a7e0:116c:c27a:3e7f:5eaf]) by smtp.gmail.com with ESMTPSA id x1sm719413wrl.41.2020.10.08.10.16.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Oct 2020 10:16:57 -0700 (PDT) From: Jean-Philippe Brucker To: eric.auger@redhat.com, alex.williamson@redhat.com Subject: [PATCH v10 09/10] virtio-iommu: Set supported page size mask Date: Thu, 8 Oct 2020 19:15:57 +0200 Message-Id: <20201008171558.410886-10-jean-philippe@linaro.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201008171558.410886-1-jean-philippe@linaro.org> References: <20201008171558.410886-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+qemu-devel=archiver.kernel.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 --- v10: Use global page mask, allowing VFIO to override it until boot. --- hw/virtio/virtio-iommu.c | 51 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/hw/virtio/virtio-iommu.c b/hw/virtio/virtio-iommu.c index 8823bfc804a..dd0b3093d1b 100644 --- a/hw/virtio/virtio-iommu.c +++ b/hw/virtio/virtio-iommu.c @@ -914,6 +914,56 @@ static int virtio_iommu_notify_flag_changed(IOMMUMemoryRegion *iommu_mr, return 0; } +static int virtio_iommu_set_page_size_mask(IOMMUMemoryRegion *mr, + uint64_t page_size_mask, + Error **errp) +{ + int new_granule, old_granule; + IOMMUDevice *sdev = container_of(mr, IOMMUDevice, iommu_mr); + VirtIOIOMMU *s = sdev->viommu; + + if (!page_size_mask) { + return -1; + } + + new_granule = ctz64(page_size_mask); + old_granule = ctz64(s->config.page_size_mask); + + /* + * Modifying the page size after machine initialization isn't supported. + * Having a different mask is possible but the guest will use sub-optimal + * block sizes, so warn about it. + */ + if (qdev_hotplug) { + if (new_granule != old_granule) { + error_setg(errp, + "virtio-iommu page mask 0x%"PRIx64 + " is incompatible with mask 0x%"PRIx64, + s->config.page_size_mask, page_size_mask); + return -1; + } else if (page_size_mask != s->config.page_size_mask) { + warn_report("virtio-iommu page mask 0x%"PRIx64 + " does not match 0x%"PRIx64, + s->config.page_size_mask, page_size_mask); + } + return 0; + } + + /* + * Disallow shrinking the page size. For example if an endpoint only + * supports 64kB pages, we can't globally enable 4kB pages. But that + * shouldn't happen, the host is unlikely to setup differing page granules. + * The other bits are only hints describing optimal block sizes. + */ + if (new_granule < old_granule) { + error_setg(errp, "memory region shrinks the virtio-iommu page granule"); + return -1; + } + + s->config.page_size_mask = page_size_mask; + return 0; +} + static void virtio_iommu_device_realize(DeviceState *dev, Error **errp) { VirtIODevice *vdev = VIRTIO_DEVICE(dev); @@ -1146,6 +1196,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 = { From patchwork Thu Oct 8 17:15:58 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: 271806 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 52BA4C433E7 for ; Thu, 8 Oct 2020 17:24:18 +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 AC772204EF for ; Thu, 8 Oct 2020 17:24:17 +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="yIw1MAKa" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org AC772204EF 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]:41912 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kQZeK-0006Kf-MS for qemu-devel@archiver.kernel.org; Thu, 08 Oct 2020 13:24:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50662) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kQZXK-0004yX-Mw for qemu-devel@nongnu.org; Thu, 08 Oct 2020 13:17:02 -0400 Received: from mail-wr1-x444.google.com ([2a00:1450:4864:20::444]:33634) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kQZXJ-0006fr-0P for qemu-devel@nongnu.org; Thu, 08 Oct 2020 13:17:02 -0400 Received: by mail-wr1-x444.google.com with SMTP id m6so7473672wrn.0 for ; Thu, 08 Oct 2020 10:17: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=p50MWhGLP7hiQqo9k1Cd/hlKchaRnczIO062DRXykeA=; b=yIw1MAKayAf8CcmYBRcz1zSVjIHA2H8NHC5brGv6QPyhJgr59niuFEFagtORN2/L+6 SBrmOgZrXrubkw/AYVv5yvyRT8vpolsAF2dvulie5Jhh17xRagfltp8WJ0RiYsx8DeeN VRNkCa7H9gpm9aa3znGgwNLHsIcFovDaosH/88DzCkMZjFjbkJ7NAjcvcg2XbK2Lz3/x UimfQmNn1qHLhsud3Yq+W3j5p4FQPsE5b2kTt3uMe9RdaY4E9oSUpN5lkQ9qvOMvgpDp 7uiI2AIpUu1FEoUpnvqhPPf/APQ4MZtV/SajK83EaqHUw9gdqtfRtkZ5hyExbyLZ09XP Q2XA== 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=p50MWhGLP7hiQqo9k1Cd/hlKchaRnczIO062DRXykeA=; b=OG0v0mVV/b27B/iW+JL8+IEGKOWSaHL0wqYm8aJhky8YmqAMNkCpmX6U069Ap1GzQT mLWyRfLEJUoaZkcjd1ZRRc00U6Mj427dR4oqNNo4bXraqzyYSAkrY2XZ+47sYx/1oxmw jrWrz4ZL8jzdEg0WTnTcqkWgahXnR8JxXw/VAACjldPDUdG8SLsE4eNw8UaMzJ3LD6tn P0JskkKQmP0KVXHAABpM3QYlAAH1TL++l212u5ekIQNQibrFJBUXUVEoL5MpVdTD0zLO e2mI4d9D8HVzr+T3isH7grn2HDRybpX2tddT2bbvvOBd8B88M/s8CZQMWYTxhLbURJtt Fawg== X-Gm-Message-State: AOAM530nDnL+Wr51gdb7yYttYS1GBvj/Tz4hD1wojka+k7smBhKl7mMs BXlTgs74QvVYK66Hb57Udje94A== X-Google-Smtp-Source: ABdhPJz4WnokWMCtKF28HBnMb9p1e5OoHBhB5yOGo+66ZSP6TVJY6+dY+UIDqeJLVinwMxq9tkMbVw== X-Received: by 2002:a5d:4d01:: with SMTP id z1mr10377411wrt.366.1602177419675; Thu, 08 Oct 2020 10:16:59 -0700 (PDT) Received: from localhost.localdomain ([2001:1715:4e26:a7e0:116c:c27a:3e7f:5eaf]) by smtp.gmail.com with ESMTPSA id x1sm719413wrl.41.2020.10.08.10.16.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Oct 2020 10:16:59 -0700 (PDT) From: Jean-Philippe Brucker To: eric.auger@redhat.com, alex.williamson@redhat.com Subject: [PATCH v10 10/10] vfio: Don't issue full 2^64 unmap Date: Thu, 8 Oct 2020 19:15:58 +0200 Message-Id: <20201008171558.410886-11-jean-philippe@linaro.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201008171558.410886-1-jean-philippe@linaro.org> References: <20201008171558.410886-1-jean-philippe@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::444; envelope-from=jean-philippe@linaro.org; helo=mail-wr1-x444.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. Signed-off-by: Jean-Philippe Brucker Acked-by: Alex Williamson Reviewed-by: Eric Auger Acked-by: Michael S. Tsirkin --- 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", "