Received: by 2002:a25:23cc:0:0:0:0:0 with SMTP id j195csp495585ybj; Tue, 5 May 2020 02:32:21 -0700 (PDT) X-Google-Smtp-Source: APiQypIQy6SI5Q5BPBeZwkbM7tN3+gAZHz4OEhpYs8KVNfolyXiXDliw+YBEuAAU6pdbUi1Q53gc X-Received: by 2002:a17:906:2410:: with SMTP id z16mr1833833eja.1.1588671141088; Tue, 05 May 2020 02:32:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588671141; cv=none; d=google.com; s=arc-20160816; b=qoSUAWOvtRLiyxcDxxxnhmg46nxqAUHTNPP9kQXOwUbQqf980SyjP+uVOvx5r+lBui 8qQByuRgt4rRpPu52mC9JO9+VcwiW9BmnQ3vQANVNBfMDrOBXIRbXtKdJcgHTJRTfi8C W2YaX9oM+GzAbREX43dZPbLQIvJLd/vaHHyXdz3PQbidprPvmE531GiC6Eeo9S6Hol7d 519WogQoTLtgAXSzswNOnPPvmr2KNZXdJW2bH9+4ItRSPWxOS2Y7i8PiSruSBxb1UGPT 5SnzjvVmQ2Q5bo6nXPCznc1CfgBElHBb1iMhsgkEOVycg7jcVS1+vbgjw0G2c1Yu3isK Xm+Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:subject:cc :to:from:dkim-signature; bh=qLR97FpW5SzS4jbbK0Z8VGx3bL/TgT3yyQI+fufG2xU=; b=PBP69pRJ0kpoZWtn3Dwx9Moyq012L6BY26gou1sgK0ICUnLcppZoRG2KIhPGHyr6WI IQw2BW6EwhIOmMnng67C7/Emhp5CrtqtiIMoV5PszJct2X8qFJr9YaI/QsOq1MiYrjyZ 0OinbKV+PuaGpZcliafbehBX8du7rOU1VvgdNNnSMitDHFRFqpY0kiZP8pHvcm8D0vZq 9VWM34pNtMm/XRW6rUGJ3fpMVEL84bcM4B2EgQNG1Q1EkyOwrVo32IubyIDMfVn598QC cNAtXDkWv+SIh0L0yPHp9nnaqEJgi9H+JEXYNx6fzHr0CotTA0QfvEa7vA2WrYIBfJwX owlw== ARC-Authentication-Results: i=1; mx.google.com; dkim=temperror (no key for signature) header.i=@marvell.com header.s=pfpt0818 header.b=f1G3mDXp; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=marvell.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v29si1082053eda.533.2020.05.05.02.31.58; Tue, 05 May 2020 02:32:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=temperror (no key for signature) header.i=@marvell.com header.s=pfpt0818 header.b=f1G3mDXp; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=marvell.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728631AbgEEJaV (ORCPT + 99 others); Tue, 5 May 2020 05:30:21 -0400 Received: from mx0a-0016f401.pphosted.com ([67.231.148.174]:17172 "EHLO mx0b-0016f401.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725766AbgEEJaU (ORCPT ); Tue, 5 May 2020 05:30:20 -0400 Received: from pps.filterd (m0045849.ppops.net [127.0.0.1]) by mx0a-0016f401.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 0459U3Mk007690; Tue, 5 May 2020 02:30:12 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com; h=from : to : cc : subject : date : message-id : mime-version : content-type; s=pfpt0818; bh=qLR97FpW5SzS4jbbK0Z8VGx3bL/TgT3yyQI+fufG2xU=; b=f1G3mDXpEBN01P1JgrM53qO13JquvwgFGYFZnBZNUzVbhktmoMkG6VX3ncGyRVp7VJEv KjkfjzOo5mAoaQNvcTa4GxfhNoy33SOasWM3Glu0BL+8ZUeoJh2wpCAAAYfWHyGcOyB0 Q3BgJ0+DU+llmqhSsbVcaGUFTJDJmrthqZ5pN8LXAKr+hc8ism6pDXfeNN/izomxQYmj rou/r4B964+AxpxeXiyrbFVFstK1MMzN+iiV8WYhsA3aTsIkmnd5SG7hoX6sdtjr9OUS PtfVtBSoYZu9aus9UR7xV7hkpf+AM0RisxgYd+Fg9nG9/izlmg1otBdU9PGnjVOZk+8z gQ== Received: from sc-exch04.marvell.com ([199.233.58.184]) by mx0a-0016f401.pphosted.com with ESMTP id 30s67qbdwe-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Tue, 05 May 2020 02:30:12 -0700 Received: from DC5-EXCH02.marvell.com (10.69.176.39) by SC-EXCH04.marvell.com (10.93.176.84) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Tue, 5 May 2020 02:30:10 -0700 Received: from bbhushan2.marvell.com (10.69.176.80) by DC5-EXCH02.marvell.com (10.69.176.39) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Tue, 5 May 2020 02:30:07 -0700 From: Bharat Bhushan To: , , , , , , , , CC: Bharat Bhushan Subject: [PATCH v5] iommu/virtio: Use page size bitmap supported by endpoint Date: Tue, 5 May 2020 15:00:04 +0530 Message-ID: <20200505093004.1935-1-bbhushan2@marvell.com> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 Content-Type: text/plain X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.138,18.0.676 definitions=2020-05-05_06:2020-05-04,2020-05-05 signatures=0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Different endpoint can support different page size, probe endpoint if it supports specific page size otherwise use global page sizes. Signed-off-by: Bharat Bhushan --- v4->v5: - Rebase to Linux v5.7-rc4 v3->v4: - Fix whitespace error v2->v3: - Fixed error return for incompatible endpoint - __u64 changed to __le64 in header file drivers/iommu/virtio-iommu.c | 48 ++++++++++++++++++++++++++++--- include/uapi/linux/virtio_iommu.h | 7 +++++ 2 files changed, 51 insertions(+), 4 deletions(-) diff --git a/drivers/iommu/virtio-iommu.c b/drivers/iommu/virtio-iommu.c index d5cac4f46ca5..9513d2ab819e 100644 --- a/drivers/iommu/virtio-iommu.c +++ b/drivers/iommu/virtio-iommu.c @@ -78,6 +78,7 @@ struct viommu_endpoint { struct viommu_dev *viommu; struct viommu_domain *vdomain; struct list_head resv_regions; + u64 pgsize_bitmap; }; struct viommu_request { @@ -415,6 +416,19 @@ static int viommu_replay_mappings(struct viommu_domain *vdomain) return ret; } +static int viommu_set_pgsize_bitmap(struct viommu_endpoint *vdev, + struct virtio_iommu_probe_pgsize_mask *mask, + size_t len) +{ + u64 pgsize_bitmap = le64_to_cpu(mask->pgsize_bitmap); + + if (len < sizeof(*mask)) + return -EINVAL; + + vdev->pgsize_bitmap = pgsize_bitmap; + return 0; +} + static int viommu_add_resv_mem(struct viommu_endpoint *vdev, struct virtio_iommu_probe_resv_mem *mem, size_t len) @@ -499,6 +513,9 @@ static int viommu_probe_endpoint(struct viommu_dev *viommu, struct device *dev) case VIRTIO_IOMMU_PROBE_T_RESV_MEM: ret = viommu_add_resv_mem(vdev, (void *)prop, len); break; + case VIRTIO_IOMMU_PROBE_T_PAGE_SIZE_MASK: + ret = viommu_set_pgsize_bitmap(vdev, (void *)prop, len); + break; default: dev_err(dev, "unknown viommu prop 0x%x\n", type); } @@ -630,7 +647,7 @@ static int viommu_domain_finalise(struct viommu_endpoint *vdev, vdomain->id = (unsigned int)ret; - domain->pgsize_bitmap = viommu->pgsize_bitmap; + domain->pgsize_bitmap = vdev->pgsize_bitmap; domain->geometry = viommu->geometry; vdomain->map_flags = viommu->map_flags; @@ -654,6 +671,29 @@ static void viommu_domain_free(struct iommu_domain *domain) kfree(vdomain); } +/* + * Check whether the endpoint's capabilities are compatible with other + * endpoints in the domain. Report any inconsistency. + */ +static bool viommu_endpoint_is_compatible(struct viommu_endpoint *vdev, + struct viommu_domain *vdomain) +{ + struct device *dev = vdev->dev; + + if (vdomain->viommu != vdev->viommu) { + dev_err(dev, "cannot attach to foreign vIOMMU\n"); + return false; + } + + if (vdomain->domain.pgsize_bitmap != vdev->pgsize_bitmap) { + dev_err(dev, "incompatible domain bitmap 0x%lx != 0x%llx\n", + vdomain->domain.pgsize_bitmap, vdev->pgsize_bitmap); + return false; + } + + return true; +} + static int viommu_attach_dev(struct iommu_domain *domain, struct device *dev) { int i; @@ -670,9 +710,8 @@ static int viommu_attach_dev(struct iommu_domain *domain, struct device *dev) * owns it. */ ret = viommu_domain_finalise(vdev, domain); - } else if (vdomain->viommu != vdev->viommu) { - dev_err(dev, "cannot attach to foreign vIOMMU\n"); - ret = -EXDEV; + } else if (!viommu_endpoint_is_compatible(vdev, vdomain)) { + ret = -EINVAL; } mutex_unlock(&vdomain->mutex); @@ -886,6 +925,7 @@ static int viommu_add_device(struct device *dev) vdev->dev = dev; vdev->viommu = viommu; + vdev->pgsize_bitmap = viommu->pgsize_bitmap; INIT_LIST_HEAD(&vdev->resv_regions); dev_iommu_priv_set(dev, vdev); diff --git a/include/uapi/linux/virtio_iommu.h b/include/uapi/linux/virtio_iommu.h index 48e3c29223b5..2cced7accc99 100644 --- a/include/uapi/linux/virtio_iommu.h +++ b/include/uapi/linux/virtio_iommu.h @@ -111,6 +111,7 @@ struct virtio_iommu_req_unmap { #define VIRTIO_IOMMU_PROBE_T_NONE 0 #define VIRTIO_IOMMU_PROBE_T_RESV_MEM 1 +#define VIRTIO_IOMMU_PROBE_T_PAGE_SIZE_MASK 2 #define VIRTIO_IOMMU_PROBE_T_MASK 0xfff @@ -119,6 +120,12 @@ struct virtio_iommu_probe_property { __le16 length; }; +struct virtio_iommu_probe_pgsize_mask { + struct virtio_iommu_probe_property head; + __u8 reserved[4]; + __le64 pgsize_bitmap; +}; + #define VIRTIO_IOMMU_RESV_MEM_T_RESERVED 0 #define VIRTIO_IOMMU_RESV_MEM_T_MSI 1 -- 2.17.1