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: 11824257 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 45AAC6CA for ; Thu, 8 Oct 2020 17:18:10 +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 D3631204EF for ; Thu, 8 Oct 2020 17:18:09 +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 D3631204EF 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+patchwork-qemu-devel=patchwork.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 1kQZYO-0006Ob-Oz for patchwork-qemu-devel@patchwork.kernel.org; Thu, 08 Oct 2020 13:18:08 -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+patchwork-qemu-devel=patchwork.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