From patchwork Tue Jul 2 20:26:18 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rob Clark X-Patchwork-Id: 11028677 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id AE42A14C0 for ; Tue, 2 Jul 2019 20:27:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 95B092882D for ; Tue, 2 Jul 2019 20:27:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8796528924; Tue, 2 Jul 2019 20:27:00 +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.2 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED 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 37BB22882D for ; Tue, 2 Jul 2019 20:26:59 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id B3EC66E03A; Tue, 2 Jul 2019 20:26:58 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-qt1-x841.google.com (mail-qt1-x841.google.com [IPv6:2607:f8b0:4864:20::841]) by gabe.freedesktop.org (Postfix) with ESMTPS id C7CD66E03A for ; Tue, 2 Jul 2019 20:26:57 +0000 (UTC) Received: by mail-qt1-x841.google.com with SMTP id m29so41949qtu.1 for ; Tue, 02 Jul 2019 13:26:57 -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:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=J/H70/FePQbdKZEz0YI3H5/o3CPPkZQZGrIygUbL5uE=; b=AjsxAMBJx2Qo3Nhcu1OdJXzdBC9c8pd9Seg8I615EIKGF+oN+8fLLXEi8OcpwqhAgU JlYaYdJQbUGqpMNPyX6HbAGrXoH+1UgVNUY3MZ6HpkzWKUSyn5OM5EgTkQqnjscHvgBz XcbpV7dinjniIqmhFrfJavTHFaKf0CWVLTuFBgw1c0jkxSx1UtUwBL/cubWwq5GnbIhh 51nwF4sfHTyMTdJhAVywiPEdDar6tCOGZ/c26HQ5V+7Pq5WUsg6Gi0tBMeGVOgh+UJKG bFhIlUoSRD+nA75HoE5VJrduWX8Vkn73vvy/rE2hPvVwIJYbg9swamZFkTMFKGZznjHz o5mA== X-Gm-Message-State: APjAAAU7xlresv0fl7jx6dRxoYq2VMQmwU43y+S8+gBWlcgWEhZ30I5/ mkBamTMluDnwoJTV5gbPqG4= X-Google-Smtp-Source: APXvYqwBpRrG3Pu/9gU8tjH7/kzX84pSdwZg+HHw7dt535o3fbveN8pbp8WelpaRmR8Le4djtZu+DQ== X-Received: by 2002:ac8:36b9:: with SMTP id a54mr27547900qtc.300.1562099216912; Tue, 02 Jul 2019 13:26:56 -0700 (PDT) Received: from localhost ([2601:184:4780:7861:5010:5849:d76d:b714]) by smtp.gmail.com with ESMTPSA id d38sm7249904qtb.95.2019.07.02.13.26.56 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Tue, 02 Jul 2019 13:26:56 -0700 (PDT) From: Rob Clark To: iommu@lists.linux-foundation.org, dri-devel@lists.freedesktop.org Subject: [PATCH 1/2] iommu: add support for drivers that manage iommu explicitly Date: Tue, 2 Jul 2019 13:26:18 -0700 Message-Id: <20190702202631.32148-2-robdclark@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190702202631.32148-1-robdclark@gmail.com> References: <20190702202631.32148-1-robdclark@gmail.com> MIME-Version: 1.0 X-Mailman-Original-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=J/H70/FePQbdKZEz0YI3H5/o3CPPkZQZGrIygUbL5uE=; b=TCnekBuPYD3hUrz8zIp0zu2L4/GpJvf48ABFai2kUMx5JRSj+cJ9F4qllXaSyBUW3P jUaysD401DDUnfOo3Klccf/XsoXJ16g19L5I8D93FmKem3TenRjTAPawa623RFJCL6qK d63Y6sMyeBjwYA4P/+VM58+DDKEo538UFqKZCsoF75gu8J+6hJVvOWOGyd58UpTYAb57 q5Ld3cG0P/Xnf8kMmLLMqTAZ1oqG80KTqDM7j+N5I9qC+N6LWOdROwCPko32+cCB7Ltn Y3vEBK04m3JwgwmnrrbIBtdJmXO9XPmSAo0oShklDieS2klivlvOqFdhJBLIoDcBywvk KvSQ== 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: Rob Clark , aarch64-laptops@lists.linaro.org, Ulf Hansson , Heikki Krogerus , Greg Kroah-Hartman , "Rafael J. Wysocki" , Rasmus Villemoes , linux-kernel@vger.kernel.org, Vivek Gautam , Sudeep Holla , Joe Perches , Bartosz Golaszewski Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Rob Clark Avoid attaching any non-driver managed domain if the driver indicates that it manages the iommu directly. This solves a couple problems that drm/msm + arm-smmu has with the iommu framework: 1) In some cases the bootloader takes the iommu out of bypass and enables the display. This is in particular a problem on the aarch64 laptops that exist these days, and modern snapdragon android devices. (Older devices also enabled the display in bootloader but did not take the iommu out of bypass.) Attaching a DMA or IDENTITY domain while scanout is active, before the driver has a chance to intervene, makes things go *boom* 2) We are currently blocked on landing support for GPU per-context pagetables because of the domain attached before driver's ->probe() is called. This solves both problems. Signed-off-by: Rob Clark --- drivers/iommu/iommu.c | 11 +++++++++++ include/linux/device.h | 3 ++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index 0c674d80c37f..efa0957f9772 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -1573,6 +1573,17 @@ static int __iommu_attach_device(struct iommu_domain *domain, domain->ops->is_attach_deferred(domain, dev)) return 0; + /* + * If driver is going to manage iommu directly, then avoid + * attaching any non driver managed domain. There could + * be already active dma underway (ie. scanout in case of + * bootloader enabled display), and interfering with that + * will make things go *boom* + */ + if ((domain->type != IOMMU_DOMAIN_UNMANAGED) && + dev->driver && dev->driver->driver_manages_iommu) + return 0; + if (unlikely(domain->ops->attach_dev == NULL)) return -ENODEV; diff --git a/include/linux/device.h b/include/linux/device.h index e138baabe01e..d98aa4d3c8c3 100644 --- a/include/linux/device.h +++ b/include/linux/device.h @@ -282,7 +282,8 @@ struct device_driver { struct module *owner; const char *mod_name; /* used for built-in modules */ - bool suppress_bind_attrs; /* disables bind/unbind via sysfs */ + bool suppress_bind_attrs:1; /* disables bind/unbind via sysfs */ + bool driver_manages_iommu:1; /* driver manages IOMMU explicitly */ enum probe_type probe_type; const struct of_device_id *of_match_table;