From patchwork Fri Jan 15 12:13:34 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vivek Kumar Gautam X-Patchwork-Id: 12022423 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E1C73C433E6 for ; Fri, 15 Jan 2021 12:17:05 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (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 9722E20691 for ; Fri, 15 Jan 2021 12:17:05 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9722E20691 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=arm.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:MIME-Version:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:References:In-Reply-To:Message-Id:Date:Subject:To: From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=AYb+A67OnT7JnMXW23qbbEEdRNJwFlAmj8jvYYajD2A=; b=TKIhcq6u/OXpuFLafEfZyRZP44 0lSCkneAzzLEjVxEgqcDtTr1QqKMGKGWbkkHtrQLM75JaQ0mp8hD+vO9jsbL7RmQPM57FEeRCmzCb fQouvKpwpAB/RfoTSDBNbUaF8xGgGUCIhSvGZPikpt3zkA4V756tl7yjv0lJOtsaezn/iAqG+UGui uKW4+z5EN+QDHF3SbIXOSfq/Ou1FtAm38AvRtEKCIFC5hoWWrRSfgy1f8Xqqlsg+LBOu9ML6PtUt4 0RCa+bzqwnpoCD9HWdv3JNgVpq17jxl/TllHm4gMjkkq0le3RJ2mCgHgBbJLJ/+7GscNUxDUwSzTw kW08B1VQ==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1l0O0B-0007Il-C6; Fri, 15 Jan 2021 12:14:51 +0000 Received: from foss.arm.com ([217.140.110.172]) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1l0Nzo-0007Ae-N0 for linux-arm-kernel@lists.infradead.org; Fri, 15 Jan 2021 12:14:31 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 7D53313D5; Fri, 15 Jan 2021 04:14:27 -0800 (PST) Received: from usa.arm.com (a074945.blr.arm.com [10.162.16.71]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 069603F70D; Fri, 15 Jan 2021 04:14:22 -0800 (PST) From: Vivek Gautam To: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, iommu@lists.linux-foundation.org, virtualization@lists.linux-foundation.org Subject: [PATCH RFC v1 07/15] iommu/virtio: Add table format probing Date: Fri, 15 Jan 2021 17:43:34 +0530 Message-Id: <20210115121342.15093-8-vivek.gautam@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210115121342.15093-1-vivek.gautam@arm.com> References: <20210115121342.15093-1-vivek.gautam@arm.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210115_071428_903442_7F5FDA11 X-CRM114-Status: GOOD ( 19.19 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: jean-philippe@linaro.org, kevin.tian@intel.com, jacob.jun.pan@linux.intel.com, mst@redhat.com, joro@8bytes.org, will.deacon@arm.com, shameerali.kolothum.thodi@huawei.com, eric.auger@redhat.com, alex.williamson@redhat.com, yi.l.liu@intel.com, vivek.gautam@arm.com, lorenzo.pieralisi@arm.com, robin.murphy@arm.com MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Jean-Philippe Brucker The device may provide information about hardware tables and additional capabilities for each device. Parse the new probe fields. Signed-off-by: Jean-Philippe Brucker [Vivek: Refactor to use "struct virtio_iommu_probe_table_format" rather than separate structures for page table and pasid table format.] Signed-off-by: Vivek Gautam Cc: Joerg Roedel Cc: Will Deacon Cc: Michael S. Tsirkin Cc: Robin Murphy Cc: Jean-Philippe Brucker Cc: Eric Auger Cc: Alex Williamson Cc: Kevin Tian Cc: Jacob Pan Cc: Liu Yi L Cc: Lorenzo Pieralisi Cc: Shameerali Kolothum Thodi --- drivers/iommu/virtio-iommu.c | 102 ++++++++++++++++++++++++++++++++++- 1 file changed, 101 insertions(+), 1 deletion(-) diff --git a/drivers/iommu/virtio-iommu.c b/drivers/iommu/virtio-iommu.c index 2bfdd5734844..12d73321dbf4 100644 --- a/drivers/iommu/virtio-iommu.c +++ b/drivers/iommu/virtio-iommu.c @@ -78,6 +78,17 @@ struct viommu_endpoint { struct viommu_dev *viommu; struct viommu_domain *vdomain; struct list_head resv_regions; + + /* properties of the physical IOMMU */ + u64 pgsize_mask; + u64 input_start; + u64 input_end; + u8 output_bits; + u8 pasid_bits; + /* Preferred PASID table format */ + void *pstf; + /* Preferred page table format */ + void *pgtf; }; struct viommu_request { @@ -457,6 +468,72 @@ static int viommu_add_resv_mem(struct viommu_endpoint *vdev, return 0; } +static int viommu_add_pgsize_mask(struct viommu_endpoint *vdev, + struct virtio_iommu_probe_page_size_mask *prop, + size_t len) +{ + if (len < sizeof(*prop)) + return -EINVAL; + vdev->pgsize_mask = le64_to_cpu(prop->mask); + return 0; +} + +static int viommu_add_input_range(struct viommu_endpoint *vdev, + struct virtio_iommu_probe_input_range *prop, + size_t len) +{ + if (len < sizeof(*prop)) + return -EINVAL; + vdev->input_start = le64_to_cpu(prop->start); + vdev->input_end = le64_to_cpu(prop->end); + return 0; +} + +static int viommu_add_output_size(struct viommu_endpoint *vdev, + struct virtio_iommu_probe_output_size *prop, + size_t len) +{ + if (len < sizeof(*prop)) + return -EINVAL; + vdev->output_bits = prop->bits; + return 0; +} + +static int viommu_add_pasid_size(struct viommu_endpoint *vdev, + struct virtio_iommu_probe_pasid_size *prop, + size_t len) +{ + if (len < sizeof(*prop)) + return -EINVAL; + vdev->pasid_bits = prop->bits; + return 0; +} + +static int viommu_add_pgtf(struct viommu_endpoint *vdev, void *pgtf, size_t len) +{ + /* Select the first page table format available */ + if (len < sizeof(struct virtio_iommu_probe_table_format) || vdev->pgtf) + return -EINVAL; + + vdev->pgtf = kmemdup(pgtf, len, GFP_KERNEL); + if (!vdev->pgtf) + return -ENOMEM; + + return 0; +} + +static int viommu_add_pstf(struct viommu_endpoint *vdev, void *pstf, size_t len) +{ + if (len < sizeof(struct virtio_iommu_probe_table_format) || vdev->pstf) + return -EINVAL; + + vdev->pstf = kmemdup(pstf, len, GFP_KERNEL); + if (!vdev->pstf) + return -ENOMEM; + + return 0; +} + static int viommu_probe_endpoint(struct viommu_dev *viommu, struct device *dev) { int ret; @@ -493,11 +570,30 @@ static int viommu_probe_endpoint(struct viommu_dev *viommu, struct device *dev) while (type != VIRTIO_IOMMU_PROBE_T_NONE && cur < viommu->probe_size) { + void *value = prop; len = le16_to_cpu(prop->length) + sizeof(*prop); switch (type) { case VIRTIO_IOMMU_PROBE_T_RESV_MEM: - ret = viommu_add_resv_mem(vdev, (void *)prop, len); + ret = viommu_add_resv_mem(vdev, value, len); + break; + case VIRTIO_IOMMU_PROBE_T_PAGE_SIZE_MASK: + ret = viommu_add_pgsize_mask(vdev, value, len); + break; + case VIRTIO_IOMMU_PROBE_T_INPUT_RANGE: + ret = viommu_add_input_range(vdev, value, len); + break; + case VIRTIO_IOMMU_PROBE_T_OUTPUT_SIZE: + ret = viommu_add_output_size(vdev, value, len); + break; + case VIRTIO_IOMMU_PROBE_T_PASID_SIZE: + ret = viommu_add_pasid_size(vdev, value, len); + break; + case VIRTIO_IOMMU_PROBE_T_PAGE_TABLE_FMT: + ret = viommu_add_pgtf(vdev, value, len); + break; + case VIRTIO_IOMMU_PROBE_T_PASID_TABLE_FMT: + ret = viommu_add_pstf(vdev, value, len); break; default: dev_err(dev, "unknown viommu prop 0x%x\n", type); @@ -899,6 +995,8 @@ static struct iommu_device *viommu_probe_device(struct device *dev) err_free_dev: generic_iommu_put_resv_regions(dev, &vdev->resv_regions); + kfree(vdev->pstf); + kfree(vdev->pgtf); kfree(vdev); return ERR_PTR(ret); @@ -915,6 +1013,8 @@ static void viommu_release_device(struct device *dev) vdev = dev_iommu_priv_get(dev); generic_iommu_put_resv_regions(dev, &vdev->resv_regions); + kfree(vdev->pstf); + kfree(vdev->pgtf); kfree(vdev); }