From patchwork Wed Apr 11 18:55:09 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jordan Crouse X-Patchwork-Id: 10336445 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id EAA596053C for ; Wed, 11 Apr 2018 18:55:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DA0CC205FC for ; Wed, 11 Apr 2018 18:55:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CEB99279E0; Wed, 11 Apr 2018 18:55:26 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 88894205FC for ; Wed, 11 Apr 2018 18:55:26 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id AF4856E6F5; Wed, 11 Apr 2018 18:55:21 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from smtp.codeaurora.org (smtp.codeaurora.org [198.145.29.96]) by gabe.freedesktop.org (Postfix) with ESMTPS id 9E3066E6E3; Wed, 11 Apr 2018 18:55:17 +0000 (UTC) Received: by smtp.codeaurora.org (Postfix, from userid 1000) id 82CA160F91; Wed, 11 Apr 2018 18:55:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1523472917; bh=180Cw1smljz+cUWTEsPkr9qa03zW6BVoxKx7BrUyGKw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hNPuKVDvnVI9iOF+XWqu+CGsUz8We9ik7HpBDpxfMmuAUYrt00+b/DvijwdU0w1K7 I0uQvKOveiUMe5OuFMYrznNGrVpv0F6kV6LUMmA4JxU3wQyUvXjFOPtnigDgXGdNr1 Yg9LmIPVj8DnpZlfKJkNoqMEUtd3CKz7XRgxx6+0= Received: from jcrouse-lnx.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: jcrouse@smtp.codeaurora.org) by smtp.codeaurora.org (Postfix) with ESMTPSA id 5F98260807; Wed, 11 Apr 2018 18:55:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1523472917; bh=180Cw1smljz+cUWTEsPkr9qa03zW6BVoxKx7BrUyGKw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hNPuKVDvnVI9iOF+XWqu+CGsUz8We9ik7HpBDpxfMmuAUYrt00+b/DvijwdU0w1K7 I0uQvKOveiUMe5OuFMYrznNGrVpv0F6kV6LUMmA4JxU3wQyUvXjFOPtnigDgXGdNr1 Yg9LmIPVj8DnpZlfKJkNoqMEUtd3CKz7XRgxx6+0= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org 5F98260807 Authentication-Results: pdx-caf-mail.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: pdx-caf-mail.web.codeaurora.org; spf=none smtp.mailfrom=jcrouse@codeaurora.org From: Jordan Crouse To: will.deacon@arm.com, robin.murphy@arm.com Subject: [PATCH 1/2] iommu: Gracefully allow drivers to not attach to a default domain Date: Wed, 11 Apr 2018 12:55:09 -0600 Message-Id: <20180411185510.11594-2-jcrouse@codeaurora.org> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20180411185510.11594-1-jcrouse@codeaurora.org> References: <20180411185510.11594-1-jcrouse@codeaurora.org> X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-arm-msm@vger.kernel.org, iommu@lists.linux-foundation.org, dri-devel@lists.freedesktop.org, freedreno@lists.freedesktop.org, linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP Provide individual device drivers the chance to gracefully refuse to attach a device to the default domain. If the attach_device op returns -ENOTSUPP don't print a error message and don't set group->domain but still return success from iommu_group_add_dev(). This allows all the usual APIs to work and the next domain to try to attach will take group->domain for itself and everything will proceed as normal. Signed-off-by: Jordan Crouse --- drivers/iommu/iommu.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index 69fef991c651..2403cce138d2 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -592,7 +592,7 @@ int iommu_group_add_device(struct iommu_group *group, struct device *dev) if (group->domain) ret = __iommu_attach_device(group->domain, dev); mutex_unlock(&group->mutex); - if (ret) + if (ret && ret != -ENOTSUPP) goto err_put_group; /* Notify any listeners about change to group. */ @@ -617,7 +617,9 @@ int iommu_group_add_device(struct iommu_group *group, struct device *dev) sysfs_remove_link(&dev->kobj, "iommu_group"); err_free_device: kfree(device); - pr_err("Failed to add device %s to group %d: %d\n", dev_name(dev), group->id, ret); + if (ret != -ENOTSUPP) + pr_err("Failed to add device %s to group %d: %d\n", + dev_name(dev), group->id, ret); return ret; } EXPORT_SYMBOL_GPL(iommu_group_add_device); @@ -1039,8 +1041,16 @@ struct iommu_group *iommu_group_get_for_dev(struct device *dev) ret = iommu_group_add_device(group, dev); if (ret) { - iommu_group_put(group); - return ERR_PTR(ret); + /* + * If the driver chooses not to bind the device, reset + * group->domain so a new domain can be added later + */ + if (ret == -ENOTSUPP) + group->domain = NULL; + else { + iommu_group_put(group); + return ERR_PTR(ret); + } } return group;