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: 10336487 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 267CD6053C for ; Wed, 11 Apr 2018 18:56:54 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 159C427E63 for ; Wed, 11 Apr 2018 18:56:54 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0978C27F89; Wed, 11 Apr 2018 18:56:54 +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=-2.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 7822E27EED for ; Wed, 11 Apr 2018 18:56:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.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=sdZnEdtcesWT6Sk+3OhMAzyK4ynDsKkcn73pn+iq/oo=; b=NA8Ie6ogFqda+npp6c7GqOJsZi aVaqDZO2u91RYF6ss5GijspvG0UI66zzcFYbwlwvb+cw8YWlOKMXFHQVdijB63ApJO4AzT3DzQlq5 GLVgiVstnEYWOH9kOTEFuCvDSJANRsv8MKkUo3/lyZy/vaE+X5QRb0JAmtYzHk8Ty/Mb+F0Mmr7NG /Wt/9s7a8iN3ea6AdT0RFDOvv2Ufe9eL5QFDET/utd2yVNtlHTNVbJkbF0cXAlcaeqGdJ8LllwtGy UfWC+0so4Jb2Rpon3Kdms164bLnWg7FLsf//fpcBS+QNOrvoEGa0g/j4g/HucKuoOnohmySDSueXu Lkil0H9A==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1f6KvE-0003po-5t; Wed, 11 Apr 2018 18:56:44 +0000 Received: from smtp.codeaurora.org ([198.145.29.96]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1f6Ku0-0002tB-0C for linux-arm-kernel@lists.infradead.org; Wed, 11 Apr 2018 18:55:32 +0000 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id CE43760F6D; 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-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180411_115528_143260_2516A4A8 X-CRM114-Status: GOOD ( 15.56 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: 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, robdclark@gmail.com, freedreno@lists.freedesktop.org, linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org 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;