From patchwork Thu Sep 30 18:50:51 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jean-Philippe Brucker X-Patchwork-Id: 514971 Delivered-To: patch@linaro.org Received: by 2002:a02:606e:0:0:0:0:0 with SMTP id d46csp65224jaf; Thu, 30 Sep 2021 11:54:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxJluHJ+fj41X/Hkh2UN4t6ro2t5jigJnmHVNcPmUN7CkxTgPs4vfr+Jq07C4l/6LkBZzp5 X-Received: by 2002:ac8:1e86:: with SMTP id c6mr8201099qtm.21.1633028042845; Thu, 30 Sep 2021 11:54:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633028042; cv=none; d=google.com; s=arc-20160816; b=NzIRD3XvHemWP5ThDq9IWjgEFDDPVj6bU8qqt5jFwbCRoWv2cClNG9wndUrp87uJMK h53L9LRVrxZvdZXzhXMuU1hNLxoKuMdbhF3ZWw/8Wv5lOQjuYgw0umnRHQ5yiidaPJBW HCsvnhPqnBFsLISMOiqzN2wOXmnnwSBHRCTMNmQtyWm+vqTRQ0pntsHUm/FfRT/sB3/2 p9qPD5N3qeAe059u3AaRxK4zlvLLuCtR7A1A/I9piXCmO/bVohU7/39xbmc+ZSWPyLPa rjitSxpX207PHe03Sx0E3MXNzr65qegCpLBpND8Q4C8j7VSuzvWXPpytODvfNyovWsp8 tZ5Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=m263Z0MNZ9eUo84q1kegZSPB7SgF/ZysplashCzc5DE=; b=HGgca5r+FbVxpEs3QDPRgwIPtWJos8dLyzCcNuru8WmubM3WqrQgZU9agTKBYXMNL0 5qBZXkgzE1smar7XDPhaaJFywH2PwYUZDQMPZJTQjQ9bRRA7zC+PmJfteKxQ93ZOabPs Nc7snLZ63YVvcfXD1JAmSqRiNXcsmK4b2+xaL8AJOsjCd686yGjg5yMH1Lk6EOlDP33a GWAmvj/QjYRQdzOknsAqXEUVWR0b2OEUFFYCSoewzLVf5uNqrlVYYfAiC8FKs8h5AEIF 8WDWFr+kZOUaeM5LINc52vsFL8LbnDm7O861+eaGAFRcLKaPH7NnXlJYbePLI2ncoWOj YBmQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=Qzb02E1v; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id k11si2306407qtg.226.2021.09.30.11.54.02 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 30 Sep 2021 11:54:02 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=Qzb02E1v; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:43614 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mW1By-0001F2-5I for patch@linaro.org; Thu, 30 Sep 2021 14:54:02 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59500) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mW1AV-0001C9-Oh for qemu-devel@nongnu.org; Thu, 30 Sep 2021 14:52:31 -0400 Received: from mail-wm1-x32b.google.com ([2a00:1450:4864:20::32b]:50690) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mW1AT-0004LE-P7 for qemu-devel@nongnu.org; Thu, 30 Sep 2021 14:52:31 -0400 Received: by mail-wm1-x32b.google.com with SMTP id j27so5473517wms.0 for ; Thu, 30 Sep 2021 11:52:29 -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=m263Z0MNZ9eUo84q1kegZSPB7SgF/ZysplashCzc5DE=; b=Qzb02E1vvwhwz9YJulKPE033dXvAppjtW6r8b7nywLNXl0coowTcU53r/19Fz3NJLb dLve29YhnYx2GrseAD/2yq7hR5jxg1I3b/NQviN+ISKoSHOwZOylFI/mmA1ibsGavAxw ItXy4T2x0CIPSbidH67QlNza1Xc7n3KsB5xlvDi9eZoXvv60cElelbSczohu8p6F5+nP n/KpLp1P9KBZEHNXz+Kw9WHnVcNAPTa2LXNeKdYR5uDW+dB9/5YFxM/XvJFiEubM5HLJ jFYTGIIAxvlAqf/UuQ/mGb2EV7D4OMgSKKhGTuQyhWR+kUTZdvlR1KOHi4N3YNIn0gZi lH/g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=m263Z0MNZ9eUo84q1kegZSPB7SgF/ZysplashCzc5DE=; b=fgieLzkQgl37bFzkvVNiVhdQYELX6Wqn22yv5iycDXRFkVj7+XZpINmhN0hfYvn7ST Z+H1kepgbYWOC/Eg3xY2TdWFxREO8hUxjfmYlWrX0on4pFGetx5n9RVZXthJj4HW2GRJ AsUEaFo24sS9qdo6peZeMdkQf9ULnpyLxtlBIHtT4LRoIfiPvQIuFgf7rbJ/Vdg4rJD6 M1aIk6casaH6CJDRyaMR10EhzCfWw4go2j6OskoXfUOhk37dG3zgRF/YMqozHzzbhwwn YaZgPewIoLgfqXHhpIt+dnSC6rQyuBgqZgcyclKKH46U1R/LJGCb80GNp8sw7P0KNhE6 5Q2Q== X-Gm-Message-State: AOAM5306mDLM86eHIzwVJCKa4tcaIt8mgovvXRWzpIeNePpI6OvzbreT JsN3au37eZwKWybWmvWa+ZRlTg== X-Received: by 2002:a05:600c:41c2:: with SMTP id t2mr704530wmh.16.1633027948494; Thu, 30 Sep 2021 11:52:28 -0700 (PDT) Received: from localhost.localdomain (cpc92880-cmbg19-2-0-cust679.5-4.cable.virginm.net. [82.27.106.168]) by smtp.gmail.com with ESMTPSA id l124sm5487151wml.8.2021.09.30.11.52.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Sep 2021 11:52:28 -0700 (PDT) From: Jean-Philippe Brucker To: eric.auger@redhat.com Subject: [PATCH 3/3] virtio-iommu: Support bypass domain Date: Thu, 30 Sep 2021 19:50:51 +0100 Message-Id: <20210930185050.262759-4-jean-philippe@linaro.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210930185050.262759-1-jean-philippe@linaro.org> References: <20210930185050.262759-1-jean-philippe@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::32b; envelope-from=jean-philippe@linaro.org; helo=mail-wm1-x32b.google.com X-Spam_score_int: -1 X-Spam_score: -0.2 X-Spam_bar: / X-Spam_report: (-0.2 / 5.0 requ) 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 , qemu-devel@nongnu.org, mst@redhat.com Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" The driver can create a bypass domain by passing the VIRTIO_IOMMU_ATTACH_F_BYPASS flag on the ATTACH request. Bypass domains perform slightly better than domains with identity mappings since they skip translation. Signed-off-by: Jean-Philippe Brucker --- hw/virtio/virtio-iommu.c | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) -- 2.33.0 diff --git a/hw/virtio/virtio-iommu.c b/hw/virtio/virtio-iommu.c index 82edeaa101..4f0207a3eb 100644 --- a/hw/virtio/virtio-iommu.c +++ b/hw/virtio/virtio-iommu.c @@ -42,6 +42,7 @@ typedef struct VirtIOIOMMUDomain { uint32_t id; + bool bypass; GTree *mappings; QLIST_HEAD(, VirtIOIOMMUEndpoint) endpoint_list; } VirtIOIOMMUDomain; @@ -257,12 +258,16 @@ static void virtio_iommu_put_endpoint(gpointer data) } static VirtIOIOMMUDomain *virtio_iommu_get_domain(VirtIOIOMMU *s, - uint32_t domain_id) + uint32_t domain_id, + bool bypass) { VirtIOIOMMUDomain *domain; domain = g_tree_lookup(s->domains, GUINT_TO_POINTER(domain_id)); if (domain) { + if (domain->bypass != bypass) { + return NULL; + } return domain; } domain = g_malloc0(sizeof(*domain)); @@ -270,6 +275,7 @@ static VirtIOIOMMUDomain *virtio_iommu_get_domain(VirtIOIOMMU *s, domain->mappings = g_tree_new_full((GCompareDataFunc)interval_cmp, NULL, (GDestroyNotify)g_free, (GDestroyNotify)g_free); + domain->bypass = bypass; g_tree_insert(s->domains, GUINT_TO_POINTER(domain_id), domain); QLIST_INIT(&domain->endpoint_list); trace_virtio_iommu_get_domain(domain_id); @@ -333,11 +339,16 @@ static int virtio_iommu_attach(VirtIOIOMMU *s, { uint32_t domain_id = le32_to_cpu(req->domain); uint32_t ep_id = le32_to_cpu(req->endpoint); + uint32_t flags = le32_to_cpu(req->flags); VirtIOIOMMUDomain *domain; VirtIOIOMMUEndpoint *ep; trace_virtio_iommu_attach(domain_id, ep_id); + if (flags & ~VIRTIO_IOMMU_ATTACH_F_BYPASS) { + return VIRTIO_IOMMU_S_INVAL; + } + ep = virtio_iommu_get_endpoint(s, ep_id); if (!ep) { return VIRTIO_IOMMU_S_NOENT; @@ -355,7 +366,12 @@ static int virtio_iommu_attach(VirtIOIOMMU *s, } } - domain = virtio_iommu_get_domain(s, domain_id); + domain = virtio_iommu_get_domain(s, domain_id, + flags & VIRTIO_IOMMU_ATTACH_F_BYPASS); + if (!domain) { + /* Incompatible flags */ + return VIRTIO_IOMMU_S_INVAL; + } QLIST_INSERT_HEAD(&domain->endpoint_list, ep, next); ep->domain = domain; @@ -418,6 +434,10 @@ static int virtio_iommu_map(VirtIOIOMMU *s, return VIRTIO_IOMMU_S_NOENT; } + if (domain->bypass) { + return VIRTIO_IOMMU_S_INVAL; + } + interval = g_malloc0(sizeof(*interval)); interval->low = virt_start; @@ -463,6 +483,11 @@ static int virtio_iommu_unmap(VirtIOIOMMU *s, if (!domain) { return VIRTIO_IOMMU_S_NOENT; } + + if (domain->bypass) { + return VIRTIO_IOMMU_S_INVAL; + } + interval.low = virt_start; interval.high = virt_end; @@ -779,6 +804,9 @@ static IOMMUTLBEntry virtio_iommu_translate(IOMMUMemoryRegion *mr, hwaddr addr, entry.perm = flag; } goto unlock; + } else if (ep->domain->bypass) { + entry.perm = flag; + goto unlock; } found = g_tree_lookup_extended(ep->domain->mappings, (gpointer)(&interval),