From patchwork Mon Feb 14 12:43:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jean-Philippe Brucker X-Patchwork-Id: 542523 Delivered-To: patch@linaro.org Received: by 2002:adf:df0e:0:0:0:0:0 with SMTP id y14csp655333wrl; Mon, 14 Feb 2022 05:57:12 -0800 (PST) X-Google-Smtp-Source: ABdhPJwitzIOzNANUb/K0d6CFJ2Rve7lIpNBRyVgiaGyypwK9VxSmamgyyGVIou6IJwAu0o8hfCP X-Received: by 2002:a25:fc23:: with SMTP id v35mr12031695ybd.279.1644847032114; Mon, 14 Feb 2022 05:57:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644847032; cv=none; d=google.com; s=arc-20160816; b=LlJpGSn2qd660IRcKXMTAUMWkyUS6A3Xp9SYfuq1ThRFWkSHqpE0DQDHAqLbagAxXE 3lSXGBJqGpXN0qLedgi2Poex6B7Ud7d12tXOlBplGjkQnXW+9c/AodpNECpWbcJVVFiQ OnGZOwWJF+mj+JwxUQZf2MUsXU0gWzRZhvDT9Bf6K/WYHDOiDncaDp2VUwSqAcU43lnS 5ayxSnG6b0HvRLwl8sCgeeBviP7b+xFXOzajqsm28C/9sc41vqaUgSFr1GMGTQVj5CAt d9vvZ9IYNwicxfjHtWRNlNE5NX4D/cBHxPZGBolCbFff+uEcTkO5iT0Ye7+wHsRKaprZ fOxg== 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=YUYnrQqqGt6VO0wBXzTWKHRMyxBgs3jc8GgoAC9EgW0=; b=Efu67CiZxKlqihBvokATXg+GM7u960LB2vJWGTGtyqIo5h0Cp1vMcs/HdbypGCpI0L 77fVujzRAB3fktm0VjmNttLQmUCezPlkwUVaTOBHl/vblReXT1UnhTP/Ix453+dpj26+ UcbkxceTCbGbr/hR70opE8t8XR/auZ3mmttgT52SvW6wcZ4qNeixYJGaRRqwgGrvCj5o Wf3mo5Kbj6h47Ah6ilHpjouG17z9lo0gqh3weaNTrSmNlzCoaRy5uzA0VmvB7tcVzE3Q epld2P9Vcmxcu2wEHxBqqd65L3svQz88JfkrS2wfx/t60iwcpiYm8vfObg37YKhCDLFY ivcg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=Gy9n5Xgd; 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 x189si13746333ybe.233.2022.02.14.05.57.11 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 14 Feb 2022 05:57:12 -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=@linaro.org header.s=google header.b=Gy9n5Xgd; 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]:52960 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nJbqp-0000K2-G0 for patch@linaro.org; Mon, 14 Feb 2022 08:57:11 -0500 Received: from eggs.gnu.org ([209.51.188.92]:51830) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nJasM-0001yy-BD for qemu-devel@nongnu.org; Mon, 14 Feb 2022 07:54:42 -0500 Received: from [2a00:1450:4864:20::12e] (port=40842 helo=mail-lf1-x12e.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nJasI-0006vi-UD for qemu-devel@nongnu.org; Mon, 14 Feb 2022 07:54:41 -0500 Received: by mail-lf1-x12e.google.com with SMTP id b9so6221967lfv.7 for ; Mon, 14 Feb 2022 04:54:38 -0800 (PST) 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=YUYnrQqqGt6VO0wBXzTWKHRMyxBgs3jc8GgoAC9EgW0=; b=Gy9n5Xgdtbe3O5j3G0yqY/goMl2QWCn4OmNQZ6JzdIKb1y1QxEKCJ4fVjzDjnRYVib xOxllatiDQWRjslQysxpQyzA/GOglRAL0lqxnlCAHc6pPIjhQz9aqzv5McSHRTou8uws C9ICMLuLRryhoaTiIYWg5LEXFsEkWN2u6ith8iNXQw5HTuWfa1lrRPF1z2ckKErRFvCq P/CV1JIrGohrH08CGR8SYa2em7KzWZllzu3t1bKF3xiSyOrBSy3vlBmOeuRS11sjErfR t1S1L7DKCZdXdPSEkDOcz5KICnfzgl/mv3i8LPppobFl+nlsG3Edko2EcDzK7MuxR3/K 08Lg== 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=YUYnrQqqGt6VO0wBXzTWKHRMyxBgs3jc8GgoAC9EgW0=; b=jXUS25hR20yCMOKQiC2924eqHif2B8Ek523JCqFWneilViNes26mYbe6/+S/gy5Nd3 P22jLjXNK/vImwxAvUJ7ENzi7Vl4XiEtopCu5QxRpIZ75vl4/22iz+4UCQvlOLhxT7U7 4+JX3CpfYGwcYhTPmDJzr06d+Fcw9lulB80EueneBIFBX8BfOpvdDSgf0uIoErnWpAzV lchGS2Gpv/UqJ17kejSZ4P/KxmztWAlqvKCJl9qhFZxAZ2Ev21Smzfy/MXGaaP7HAIKp o5RLshfGH4CuCWds6IR5TrpRGla1+b0/ofuyClHE2sS0mjYOydDhv1flnUiRO3C0xfsi oZOA== X-Gm-Message-State: AOAM532HFEV/hPEDaTCXUlezXwK6sFg8mmB57GoOJS+GhU3GcT8GPHTi GWZ9+Xz2Ra8wFmo0FkkH94+bJxe7viTgtw== X-Received: by 2002:a17:907:3f26:: with SMTP id hq38mr10596646ejc.391.1644842857833; Mon, 14 Feb 2022 04:47:37 -0800 (PST) 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 kq17sm1475422ejb.205.2022.02.14.04.47.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Feb 2022 04:47:37 -0800 (PST) From: Jean-Philippe Brucker To: eric.auger@redhat.com Subject: [PATCH v3 3/4] virtio-iommu: Support bypass domain Date: Mon, 14 Feb 2022 12:43:55 +0000 Message-Id: <20220214124356.872985-4-jean-philippe@linaro.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220214124356.872985-1-jean-philippe@linaro.org> References: <20220214124356.872985-1-jean-philippe@linaro.org> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::12e (failed) Received-SPF: pass client-ip=2a00:1450:4864:20::12e; envelope-from=jean-philippe@linaro.org; helo=mail-lf1-x12e.google.com X-Spam_score_int: -6 X-Spam_score: -0.7 X-Spam_bar: / X-Spam_report: (-0.7 / 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, PDS_HP_HELO_NORDNS=0.635, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: lvivier@redhat.com, Jean-Philippe Brucker , thuth@redhat.com, mst@redhat.com, cohuck@redhat.com, qemu-devel@nongnu.org, dgilbert@redhat.com, pasic@linux.ibm.com, pbonzini@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 | 39 ++++++++++++++++++++++++++++++++++----- 1 file changed, 34 insertions(+), 5 deletions(-) diff --git a/hw/virtio/virtio-iommu.c b/hw/virtio/virtio-iommu.c index 4ca36db4ac..239fe97b12 100644 --- a/hw/virtio/virtio-iommu.c +++ b/hw/virtio/virtio-iommu.c @@ -43,6 +43,7 @@ typedef struct VirtIOIOMMUDomain { uint32_t id; + bool bypass; GTree *mappings; QLIST_HEAD(, VirtIOIOMMUEndpoint) endpoint_list; } VirtIOIOMMUDomain; @@ -258,12 +259,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)); @@ -271,6 +276,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); @@ -334,11 +340,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; @@ -356,7 +367,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 bypass flag */ + return VIRTIO_IOMMU_S_INVAL; + } QLIST_INSERT_HEAD(&domain->endpoint_list, ep, next); ep->domain = domain; @@ -419,6 +435,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; @@ -464,6 +484,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; @@ -780,6 +805,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), @@ -1139,8 +1167,8 @@ static const VMStateDescription vmstate_endpoint = { static const VMStateDescription vmstate_domain = { .name = "domain", - .version_id = 1, - .minimum_version_id = 1, + .version_id = 2, + .minimum_version_id = 2, .pre_load = domain_preload, .fields = (VMStateField[]) { VMSTATE_UINT32(id, VirtIOIOMMUDomain), @@ -1149,6 +1177,7 @@ static const VMStateDescription vmstate_domain = { VirtIOIOMMUInterval, VirtIOIOMMUMapping), VMSTATE_QLIST_V(endpoint_list, VirtIOIOMMUDomain, 1, vmstate_endpoint, VirtIOIOMMUEndpoint, next), + VMSTATE_BOOL_V(bypass, VirtIOIOMMUDomain, 2), VMSTATE_END_OF_LIST() } }; @@ -1186,7 +1215,7 @@ static const VMStateDescription vmstate_virtio_iommu_device = { .version_id = 2, .post_load = iommu_post_load, .fields = (VMStateField[]) { - VMSTATE_GTREE_DIRECT_KEY_V(domains, VirtIOIOMMU, 1, + VMSTATE_GTREE_DIRECT_KEY_V(domains, VirtIOIOMMU, 2, &vmstate_domain, VirtIOIOMMUDomain), VMSTATE_UINT8_V(config.bypass, VirtIOIOMMU, 2), VMSTATE_END_OF_LIST()