From patchwork Tue Jun 2 07:43:59 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: You-Sheng Yang X-Patchwork-Id: 1302171 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=canonical.com Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 49bkdS4WP3z9sT6; Tue, 2 Jun 2020 17:46:52 +1000 (AEST) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1jg1dG-0003kC-EX; Tue, 02 Jun 2020 07:46:46 +0000 Received: from mail-pl1-f194.google.com ([209.85.214.194]) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1jg1cd-0003Aa-A7 for kernel-team@lists.ubuntu.com; Tue, 02 Jun 2020 07:46:07 +0000 Received: by mail-pl1-f194.google.com with SMTP id y18so1023461plr.4 for ; Tue, 02 Jun 2020 00:46:07 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=xM2ts5+wDgOXQU5rk+Iq1g+jXyXmKGSW+R2QMPkfcv0=; b=RCBL+jYDF3zI+7qSLDwW9PXlcAO3AzCz7d818nP04YJmtD6s+eJgpoI5qZ9GufFKYH 5zp/2w3wrNYgliavuP6go4oT3jCSHf7sN0zOkX6u4DOIwFtAbH6aEpq89qbaJMY4iGZd E3reZO6WLBd7sPI9ml3uTzI1KL02WrcOzquE0tuzEL/M22GbF0WJmU5ZDcDL+fQ1KSG9 gT5/wuT+f4nCcfCoHgwxrJRLLSmov0INIYMQGbFL6d3XA/HURpRYVgFFfjAAJ9AQK+F8 a4uTzdzGStMR/fKkaVPxv9kG6p1IxzO7XmzWxuDrYhdf+glq9On1ugKVLAD+Dy5fxmi6 dLTA== X-Gm-Message-State: AOAM533lKyIvOxrBlP+9aLnhDGDvS5IoPcJxvPAqaBtO6OaeMA3tsfZY VfcWlbAcFfEVY8yeb0XSYeJCOsD+soc= X-Google-Smtp-Source: ABdhPJwrgsD79gnTkrkwm+GSys6cSor48rftKRR17sBDAzA61hutiKccgcnkRLydEmYo2yf7PwborA== X-Received: by 2002:a17:90a:f40e:: with SMTP id ch14mr4143468pjb.197.1591083964031; Tue, 02 Jun 2020 00:46:04 -0700 (PDT) Received: from localhost (61-220-137-37.HINET-IP.hinet.net. [61.220.137.37]) by smtp.gmail.com with ESMTPSA id ds11sm1543862pjb.0.2020.06.02.00.46.02 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jun 2020 00:46:03 -0700 (PDT) From: You-Sheng Yang To: kernel-team@lists.ubuntu.com Subject: [PATCH v2 38/60][SRU][OEM-5.6] iommu/virtio: Convert to probe/release_device() call-backs Date: Tue, 2 Jun 2020 15:43:59 +0800 Message-Id: <20200602074421.1742802-39-vicamo.yang@canonical.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200602074421.1742802-1-vicamo.yang@canonical.com> References: <20200602074421.1742802-1-vicamo.yang@canonical.com> MIME-Version: 1.0 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Joerg Roedel BugLink: https://bugs.launchpad.net/bugs/1876707 Convert the VirtIO IOMMU driver to use the probe_device() and release_device() call-backs of iommu_ops, so that the iommu core code does the group and sysfs setup. Signed-off-by: Joerg Roedel Link: https://lore.kernel.org/r/20200429133712.31431-21-joro@8bytes.org Signed-off-by: Joerg Roedel (cherry picked from commit 21acf6599cfb4407e9745b36f69c93cf99a3d189 linux-next) Signed-off-by: You-Sheng Yang --- drivers/iommu/virtio-iommu.c | 41 +++++++++--------------------------- 1 file changed, 10 insertions(+), 31 deletions(-) diff --git a/drivers/iommu/virtio-iommu.c b/drivers/iommu/virtio-iommu.c index b0b53d67c9be..e1544a89c426 100644 --- a/drivers/iommu/virtio-iommu.c +++ b/drivers/iommu/virtio-iommu.c @@ -855,24 +855,23 @@ static struct viommu_dev *viommu_get_by_fwnode(struct fwnode_handle *fwnode) return dev ? dev_to_virtio(dev)->priv : NULL; } -static int viommu_add_device(struct device *dev) +static struct iommu_device *viommu_probe_device(struct device *dev) { int ret; - struct iommu_group *group; struct viommu_endpoint *vdev; struct viommu_dev *viommu = NULL; struct iommu_fwspec *fwspec = dev_iommu_fwspec_get(dev); if (!fwspec || fwspec->ops != &viommu_ops) - return -ENODEV; + return ERR_PTR(-ENODEV); viommu = viommu_get_by_fwnode(fwspec->iommu_fwnode); if (!viommu) - return -ENODEV; + return ERR_PTR(-ENODEV); vdev = kzalloc(sizeof(*vdev), GFP_KERNEL); if (!vdev) - return -ENOMEM; + return ERR_PTR(-ENOMEM); vdev->dev = dev; vdev->viommu = viommu; @@ -886,45 +885,25 @@ static int viommu_add_device(struct device *dev) goto err_free_dev; } - ret = iommu_device_link(&viommu->iommu, dev); - if (ret) - goto err_free_dev; + return &viommu->iommu; - /* - * Last step creates a default domain and attaches to it. Everything - * must be ready. - */ - group = iommu_group_get_for_dev(dev); - if (IS_ERR(group)) { - ret = PTR_ERR(group); - goto err_unlink_dev; - } - - iommu_group_put(group); - - return PTR_ERR_OR_ZERO(group); - -err_unlink_dev: - iommu_device_unlink(&viommu->iommu, dev); err_free_dev: generic_iommu_put_resv_regions(dev, &vdev->resv_regions); kfree(vdev); - return ret; + return ERR_PTR(ret); } -static void viommu_remove_device(struct device *dev) +static void viommu_release_device(struct device *dev) { - struct viommu_endpoint *vdev; struct iommu_fwspec *fwspec = dev_iommu_fwspec_get(dev); + struct viommu_endpoint *vdev; if (!fwspec || fwspec->ops != &viommu_ops) return; vdev = dev_iommu_priv_get(dev); - iommu_group_remove_device(dev); - iommu_device_unlink(&vdev->viommu->iommu, dev); generic_iommu_put_resv_regions(dev, &vdev->resv_regions); kfree(vdev); } @@ -950,8 +929,8 @@ static struct iommu_ops viommu_ops = { .unmap = viommu_unmap, .iova_to_phys = viommu_iova_to_phys, .iotlb_sync = viommu_iotlb_sync, - .add_device = viommu_add_device, - .remove_device = viommu_remove_device, + .probe_device = viommu_probe_device, + .release_device = viommu_release_device, .device_group = viommu_device_group, .get_resv_regions = viommu_get_resv_regions, .put_resv_regions = generic_iommu_put_resv_regions,