From patchwork Fri May 18 21:34:59 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jordan Crouse X-Patchwork-Id: 10412301 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 B96A0602CB for ; Fri, 18 May 2018 21:36:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A622C28980 for ; Fri, 18 May 2018 21:36:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9765428AF1; Fri, 18 May 2018 21:36:15 +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 2478228980 for ; Fri, 18 May 2018 21:36:15 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id BFBA36EF43; Fri, 18 May 2018 21:35:36 +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 D40706EF3B; Fri, 18 May 2018 21:35:30 +0000 (UTC) Received: by smtp.codeaurora.org (Postfix, from userid 1000) id 696E760FF8; Fri, 18 May 2018 21:35:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1526679330; bh=3xxM8jMKgs4FK5NB8sf+9P+j6Cd7ulPhCCyzc0qla5U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=icKom+qSPUplaX5oTq+n7Yl8D1FaoP1aFM1DDtHJUa3oDICwdy0a8NDlrYKoiKSxS iYg5LJCvmWYYdDYY7GrqYLgRWQ1Odz3ii9CXJzq/sYPmcW008LJrMwTzcQYl3QjrXE FR9lwycbbMt7dZjYr6T5UY//TDUkgynbWMAghfvo= 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 017F661150; Fri, 18 May 2018 21:35:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1526679319; bh=3xxM8jMKgs4FK5NB8sf+9P+j6Cd7ulPhCCyzc0qla5U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Iez9hkG/HajySgeviUl19pPthcAVX7EZNnoFowCy3sKD5KTp0hcz6DDIw7hMyy3U8 eCjPxABVagNxFZ1E6eiPVZQzhDqHcgICTtfxQve5qcv7x+4pbzM8MhhJHy4Rk2CMhz 07Zf23xj268wZX3iuNKYUWdz4EYnM5Gdmlo8if+0= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org 017F661150 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: freedreno@lists.freedesktop.org Subject: [PATCH 15/16] iommu: Gracefully allow drivers to not attach to a default domain Date: Fri, 18 May 2018 15:34:59 -0600 Message-Id: <20180518213500.31595-16-jcrouse@codeaurora.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180518213500.31595-1-jcrouse@codeaurora.org> References: <20180518213500.31595-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: jean-philippe.brucker@arm.com, linux-arm-msm@vger.kernel.org, dri-devel@lists.freedesktop.org, tfiga@chromium.org, iommu@lists.linux-foundation.org, vivek.gautam@codeaurora.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 | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index 0ba3d27f2300..a255b5d6c495 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -599,7 +599,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. */ @@ -625,7 +625,8 @@ 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); @@ -1238,8 +1239,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;