From patchwork Wed Nov 4 18:41:57 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 320562 Delivered-To: patch@linaro.org Received: by 2002:a92:7b12:0:0:0:0:0 with SMTP id w18csp5667113ilc; Wed, 4 Nov 2020 10:49:02 -0800 (PST) X-Google-Smtp-Source: ABdhPJylgQveusRJXbyfmDQv7LyIRL/QN1fbWhHEsX/S0JdXR/fWz8rT315qd4QLe2OUqLHddpec X-Received: by 2002:a5b:f4f:: with SMTP id y15mr7654462ybr.226.1604515741932; Wed, 04 Nov 2020 10:49:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604515741; cv=none; d=google.com; s=arc-20160816; b=z0ZP3zg3PbmfXTDYrAJJcGI1qPY++2myoL6uWdpwBSSM3+bMq3KGoRcIhrtyLIck6U sTnidcfsfUL0Ju0+GOeXYgbIB9LkziW+ye/2xdFFx3JNZnbAF5I1o1XvON+kHinM+fjl LLU5bHcYozMTskszl6Eyy07ND8UlXVGgE6rHl1ZHnyTs2ms2sUbeJ5xoMTkeKwK9clFf OJu8Z6vwFbMWV0TVMsHeYLQpIKuDd9Qxd8gtnAENpOtJtbO2bkjOATuIjGrDft/kIAnk Ri4NRsCQMKDWwWZ3rnYzmBpoMlfI080kXaNU6KGlgh9BG9ZhVmAX5dtD5dbFxvwgATgl dldQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-disposition:in-reply-to :mime-version:references:message-id:subject:to:from:date :dkim-signature; bh=tvJ0s3bSV9g9bsoYugn7fOSbhCEdSfwOqB79D2kkBqw=; b=ntt6GZZgFvovMobpEyOpJPBU+Epg3pe6cR7YL0jfJuk7IneOUCXngxrlA5saDSU18T PUmU4fXLNn52mBu3aJTKabxS7NxxbJj6pvmFT6MWUrJn9Hje/kNlMuH9V1QdVZdK0oZi C49dt7/wCi+sUYXmK8Qwiz91ebxkiwFqbyMPmhTLYvM2T7RM41NByuHB9crMLHl39Yvg ipz8T3XoHbhLz+3dwYO/D/XKNQJkUAerzBf+HUIFL0Kp8kpGnO01f9+u5kXzXZsYo4cg BYU8gv57gnEoh2RNGZ2lBV64Foi3DGHke4veChK0sCFasOvsBGlgG++P/ubv4geAeoyU joZg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@redhat.com header.s=mimecast20190719 header.b=QSSLW0JQ; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id j18si3001138ybm.276.2020.11.04.10.49.01 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 04 Nov 2020 10:49:01 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@redhat.com header.s=mimecast20190719 header.b=QSSLW0JQ; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from localhost ([::1]:41010 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kaNq9-00029N-BB for patch@linaro.org; Wed, 04 Nov 2020 13:49:01 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:52422) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kaNjS-00016X-E0 for qemu-devel@nongnu.org; Wed, 04 Nov 2020 13:42:06 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:23010) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kaNjP-00022Y-Vt for qemu-devel@nongnu.org; Wed, 04 Nov 2020 13:42:06 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1604515323; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=tvJ0s3bSV9g9bsoYugn7fOSbhCEdSfwOqB79D2kkBqw=; b=QSSLW0JQcsLfV8t2b3++I3hq+uDC/IKOJKXXSda0HJaXrATW5hVFxLHzt3OUMY00WuHpST yqV7TvuwdxPZG5lW3RJ5K8Bvz9gKf1z6BL4s83ys9bwwjMri1ZYtBeaptT9fyOv0a3cvrW QOVvHa+drUCmXuhvo+o5hGvB1xrH0c8= Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-306-feUFggKJNGSwbSMd1jKBSA-1; Wed, 04 Nov 2020 13:42:01 -0500 X-MC-Unique: feUFggKJNGSwbSMd1jKBSA-1 Received: by mail-wr1-f72.google.com with SMTP id h8so9633889wrt.9 for ; Wed, 04 Nov 2020 10:42:01 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=tvJ0s3bSV9g9bsoYugn7fOSbhCEdSfwOqB79D2kkBqw=; b=lm9vumkS8YTvaYJ6kvp8vbkIbzCe7QT6Aag2kXzAg1WWyeloW30E6rDgj7urmCCBJq tQwVE5LBIEe1UG9wHtBxQA0I/caxoP0j1mbfMlVUd6ifvPq0s55DC9MgIVwzwxlRuqlq u6SSDOfSOD0Wtugji8i41Kfn1UoNDVFg6fIGECaWw2DFjbE6IiVkN5VuNdj4bO5mUXHu M+vhPqtOqimNBd7lZVfkA9Wcqgta/d/Ms+OnyPQ9UkSDv4sFSyFUE8r6Gw0S8lvBLvWq gHSI0ZchTPSc2EFn63DtXYJ0RVEp4RWESvPyQaZ4Hf9KSk3Lrf3k9xAuwuVxzBfObuVp lXdw== X-Gm-Message-State: AOAM531ou/HpITKp4FDbHNYuuCYbqqoNPce06aBn5EAxxPWvsg00a69+ coTfin80YKA/DZVEJOl6qFYI1rw1j+2pCjaYgBNS4R+q3wuGavJEogBg1koLvttoTOiO6W1Qov6 l+PN+wtDVL9oyjwQ= X-Received: by 2002:a05:6000:1109:: with SMTP id z9mr31002987wrw.388.1604515319654; Wed, 04 Nov 2020 10:41:59 -0800 (PST) X-Received: by 2002:a05:6000:1109:: with SMTP id z9mr31002970wrw.388.1604515319464; Wed, 04 Nov 2020 10:41:59 -0800 (PST) Received: from redhat.com (bzq-79-176-118-93.red.bezeqint.net. [79.176.118.93]) by smtp.gmail.com with ESMTPSA id z5sm3862094wrw.87.2020.11.04.10.41.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Nov 2020 10:41:58 -0800 (PST) Date: Wed, 4 Nov 2020 13:41:57 -0500 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Subject: [PULL v3 14/31] virtio-iommu: Store memory region in endpoint struct Message-ID: <20201104184040.285057-15-mst@redhat.com> References: <20201104184040.285057-1-mst@redhat.com> MIME-Version: 1.0 In-Reply-To: <20201104184040.285057-1-mst@redhat.com> X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=mst@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline Received-SPF: pass client-ip=63.128.21.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/03 22:09:52 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] 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, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, 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: Peter Maydell , Eric Auger , Jean-Philippe Brucker Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Jean-Philippe Brucker 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 Message-Id: <20201030180510.747225-3-jean-philippe@linaro.org> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- hw/virtio/virtio-iommu.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) -- MST diff --git a/hw/virtio/virtio-iommu.c b/hw/virtio/virtio-iommu.c index 4c8f3909b7..a5c2d69aad 100644 --- a/hw/virtio/virtio-iommu.c +++ b/hw/virtio/virtio-iommu.c @@ -49,6 +49,7 @@ typedef struct VirtIOIOMMUDomain { typedef struct VirtIOIOMMUEndpoint { uint32_t id; VirtIOIOMMUDomain *domain; + IOMMUMemoryRegion *iommu_mr; QLIST_ENTRY(VirtIOIOMMUEndpoint) next; } VirtIOIOMMUEndpoint; @@ -137,16 +138,19 @@ static VirtIOIOMMUEndpoint *virtio_iommu_get_endpoint(VirtIOIOMMU *s, uint32_t ep_id) { VirtIOIOMMUEndpoint *ep; + IOMMUMemoryRegion *mr; ep = g_tree_lookup(s->endpoints, GUINT_TO_POINTER(ep_id)); if (ep) { return ep; } - if (!virtio_iommu_mr(s, ep_id)) { + mr = virtio_iommu_mr(s, ep_id); + if (!mr) { return NULL; } ep = g_malloc0(sizeof(*ep)); ep->id = ep_id; + ep->iommu_mr = mr; trace_virtio_iommu_get_endpoint(ep_id); g_tree_insert(s->endpoints, GUINT_TO_POINTER(ep_id), ep); return ep; @@ -910,9 +914,14 @@ static gboolean reconstruct_endpoints(gpointer key, gpointer value, VirtIOIOMMU *s = (VirtIOIOMMU *)data; VirtIOIOMMUDomain *d = (VirtIOIOMMUDomain *)value; VirtIOIOMMUEndpoint *iter; + IOMMUMemoryRegion *mr; QLIST_FOREACH(iter, &d->endpoint_list, next) { + mr = virtio_iommu_mr(s, iter->id); + assert(mr); + iter->domain = d; + iter->iommu_mr = mr; g_tree_insert(s->endpoints, GUINT_TO_POINTER(iter->id), iter); } return false; /* continue the domain traversal */