From mboxrd@z Thu Jan 1 00:00:00 1970 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 DC7C3C433DB for ; Fri, 15 Jan 2021 12:17:03 +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 981CF20691 for ; Fri, 15 Jan 2021 12:17:03 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 981CF20691 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=axhHUhw+91w7FfOqh1hCJPcVUNkfHuHFBbbFIunmRJA=; b=oGvvUB2A1wQRyk6ls+pZYJvsk7 3lI9npqNKPDdRk1KiI+Y3CjXg9FzEbpVXZEKPGAhMvBpcemgEmHCgnO1H7893drQiNKb/uIWjYkqx uZBCXjbQwaUSbjLh1Q1MPHgxvxMAzFn2jMEiRxRYbPmOTGvRVvsiCa1+c1NzR8N1XrrI4JzXNAPZN +5zXDGJfMtNECnsY4viusJRbBGcp9zno6BFx/0RH3dfQ+pX8wOJxeunpAp9gIOTJQLPUS/lUtM7dJ aeM99amIkad2Mm2w4jl00DBxRxPpo++TmlLWcH+2dk9z8SF/1ZI2wrGy1JYN8XkdK/1EdeLpafIK6 gYNspfDA==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1l0O0k-0007Ys-Dt; Fri, 15 Jan 2021 12:15:26 +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 1l0O03-0007GV-Ei for linux-arm-kernel@lists.infradead.org; Fri, 15 Jan 2021 12:14:53 +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 6EE1C14BF; Fri, 15 Jan 2021 04:14:42 -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 EC5FA3F70D; Fri, 15 Jan 2021 04:14:37 -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 10/15] iommu/virtio: Prepare to add attach pasid table infrastructure Date: Fri, 15 Jan 2021 17:43:37 +0530 Message-Id: <20210115121342.15093-11-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_071443_636627_D591AE8F X-CRM114-Status: GOOD ( 21.24 ) 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 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org In preparation to add attach pasid table op, separate out the existing attach request code to a separate method. 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 | 73 +++++++++++++++++++++++++----------- 1 file changed, 51 insertions(+), 22 deletions(-) diff --git a/drivers/iommu/virtio-iommu.c b/drivers/iommu/virtio-iommu.c index 12d73321dbf4..ae5dfd3f8269 100644 --- a/drivers/iommu/virtio-iommu.c +++ b/drivers/iommu/virtio-iommu.c @@ -52,6 +52,8 @@ struct viommu_dev { /* Supported MAP flags */ u32 map_flags; u32 probe_size; + + bool has_map:1; }; struct viommu_mapping { @@ -60,6 +62,11 @@ struct viommu_mapping { u32 flags; }; +struct viommu_mm { + struct io_pgtable_ops *ops; + struct viommu_domain *domain; +}; + struct viommu_domain { struct iommu_domain domain; struct viommu_dev *viommu; @@ -67,12 +74,20 @@ struct viommu_domain { unsigned int id; u32 map_flags; + /* Default address space when a table is bound */ + struct viommu_mm mm; + + /* When no table is bound, use generic mappings */ spinlock_t mappings_lock; struct rb_root_cached mappings; unsigned long nr_endpoints; }; +#define vdev_for_each_id(i, eid, vdev) \ + for (i = 0; i < vdev->dev->iommu->fwspec->num_ids && \ + ({ eid = vdev->dev->iommu->fwspec->ids[i]; 1; }); i++) + struct viommu_endpoint { struct device *dev; struct viommu_dev *viommu; @@ -750,12 +765,40 @@ static void viommu_domain_free(struct iommu_domain *domain) kfree(vdomain); } +static int viommu_simple_attach(struct viommu_domain *vdomain, + struct viommu_endpoint *vdev) +{ + int i, eid, ret; + struct virtio_iommu_req_attach req = { + .head.type = VIRTIO_IOMMU_T_ATTACH, + .domain = cpu_to_le32(vdomain->id), + }; + + if (!vdomain->viommu->has_map) + return -ENODEV; + + vdev_for_each_id(i, eid, vdev) { + req.endpoint = cpu_to_le32(eid); + + ret = viommu_send_req_sync(vdomain->viommu, &req, sizeof(req)); + if (ret) + return ret; + } + + if (!vdomain->nr_endpoints) { + /* + * This endpoint is the first to be attached to the domain. + * Replay existing mappings if any (e.g. SW MSI). + */ + ret = viommu_replay_mappings(vdomain); + } + + return ret; +} + static int viommu_attach_dev(struct iommu_domain *domain, struct device *dev) { - int i; int ret = 0; - struct virtio_iommu_req_attach req; - struct iommu_fwspec *fwspec = dev_iommu_fwspec_get(dev); struct viommu_endpoint *vdev = dev_iommu_priv_get(dev); struct viommu_domain *vdomain = to_viommu_domain(domain); @@ -790,25 +833,9 @@ static int viommu_attach_dev(struct iommu_domain *domain, struct device *dev) if (vdev->vdomain) vdev->vdomain->nr_endpoints--; - req = (struct virtio_iommu_req_attach) { - .head.type = VIRTIO_IOMMU_T_ATTACH, - .domain = cpu_to_le32(vdomain->id), - }; - - for (i = 0; i < fwspec->num_ids; i++) { - req.endpoint = cpu_to_le32(fwspec->ids[i]); - - ret = viommu_send_req_sync(vdomain->viommu, &req, sizeof(req)); - if (ret) - return ret; - } - - if (!vdomain->nr_endpoints) { - /* - * This endpoint is the first to be attached to the domain. - * Replay existing mappings (e.g. SW MSI). - */ - ret = viommu_replay_mappings(vdomain); + if (!vdomain->mm.ops) { + /* If we couldn't bind any table, use the mapping tree */ + ret = viommu_simple_attach(vdomain, vdev); if (ret) return ret; } @@ -1142,6 +1169,8 @@ static int viommu_probe(struct virtio_device *vdev) struct virtio_iommu_config, probe_size, &viommu->probe_size); + viommu->has_map = virtio_has_feature(vdev, VIRTIO_IOMMU_F_MAP_UNMAP); + viommu->geometry = (struct iommu_domain_geometry) { .aperture_start = input_start, .aperture_end = input_end, -- 2.17.1 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel