From patchwork Tue Nov 26 13:16:26 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mihail Atanassov X-Patchwork-Id: 11262309 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 27FE213A4 for ; Tue, 26 Nov 2019 13:16:55 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 0BCD820727 for ; Tue, 26 Nov 2019 13:16:55 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0BCD820727 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=arm.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id A9EA56E366; Tue, 26 Nov 2019 13:16:46 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from EUR04-VI1-obe.outbound.protection.outlook.com (mail-vi1eur04on062c.outbound.protection.outlook.com [IPv6:2a01:111:f400:fe0e::62c]) by gabe.freedesktop.org (Postfix) with ESMTPS id F2CDF6E353 for ; Tue, 26 Nov 2019 13:16:38 +0000 (UTC) Received: from VI1PR08CA0100.eurprd08.prod.outlook.com (2603:10a6:800:d3::26) by AM0PR08MB4209.eurprd08.prod.outlook.com (2603:10a6:208:10c::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2474.16; Tue, 26 Nov 2019 13:16:36 +0000 Received: from DB5EUR03FT029.eop-EUR03.prod.protection.outlook.com (2a01:111:f400:7e0a::204) by VI1PR08CA0100.outlook.office365.com (2603:10a6:800:d3::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2474.17 via Frontend Transport; Tue, 26 Nov 2019 13:16:36 +0000 Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 63.35.35.123 as permitted sender) receiver=protection.outlook.com; client-ip=63.35.35.123; helo=64aa7808-outbound-1.mta.getcheckrecipient.com; Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by DB5EUR03FT029.mail.protection.outlook.com (10.152.20.131) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2474.17 via Frontend Transport; Tue, 26 Nov 2019 13:16:36 +0000 Received: ("Tessian outbound f7868d7ede10:v33"); Tue, 26 Nov 2019 13:16:33 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: d914095c1eeeccd7 X-CR-MTA-TID: 64aa7808 Received: from a4bda1e7f4c9.2 (ip-172-16-0-2.eu-west-1.compute.internal [104.47.4.58]) by 64aa7808-outbound-1.mta.getcheckrecipient.com id 09D6DE19-468D-4F1F-B9A4-A85333043EAF.1; Tue, 26 Nov 2019 13:16:28 +0000 Received: from EUR02-AM5-obe.outbound.protection.outlook.com (mail-am5eur02lp2058.outbound.protection.outlook.com [104.47.4.58]) by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id a4bda1e7f4c9.2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Tue, 26 Nov 2019 13:16:28 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=KTvJXLYIp5rAgMJhpUqkBWq3XTa26jZ9m+gtVPjhbyA7cgnsQVLFfv38rkhHNWGnnDpumkBQdzZ1hlCXgKjtemyi64DDXZqmIGDpShjaZlfsGAHBoTPL87/TgxWrbuv/D5TMfMf0UoeLnHmBSefSzwfgdwVSK8/4ZuCJOsgwp1wqEqp2UY56mqia2D4Syq+bONRLO3+wXF3WHVcSqutNfNcJNwdNSy1plOfnG/rZFlk47zxkiohVxIWtGSNl5V9WFpeHmf3R3kKBYDBHrzwMJQV2uUXUsD8IzMbziF1nicFZhfvGo6n/qjgc/u13KaKetUHgAmBLEr1VdrjVI85hfQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=22yLRF+OD4SGmB+ZPAp6mmB9i3wb2rmCRZA/8wtNzW4=; b=K0B24MUoiItjJ47K++yO57G7RyvV4IPku5eQ5IFON30OWCql68WD16tLxn4oN1zojh5QVorDbdPYtRFvHcaFhRrkQEUrA9kksZeT0zItE+DiPd0lFcdnrCN/hQebo5N5Lq58l8RMSzivmwnDR+KgrDRa1Wf7Z+ISb3YUKF58XYk2IXbT00f4SmDOQn7CWAkpElKmFnC77+RJwL4YWXerdG0O2H8GLP8k4/Gi2WpJXmA1w0KmOQTs6dEo5T1jogFf8O/x01zkaxiBLRpQ/g/Apa76Yn8XdFnGe9LKxZOGZ2kq2ZJdq8TKv7hMdm19qWEUZ8whR1Ti/SJOEgEMA+W38A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=arm.com; dmarc=pass action=none header.from=arm.com; dkim=pass header.d=arm.com; arc=none Received: from VI1PR08MB4078.eurprd08.prod.outlook.com (20.178.127.92) by VI1PR08MB4560.eurprd08.prod.outlook.com (20.179.24.80) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2474.19; Tue, 26 Nov 2019 13:16:27 +0000 Received: from VI1PR08MB4078.eurprd08.prod.outlook.com ([fe80::8191:f0ac:574a:d24d]) by VI1PR08MB4078.eurprd08.prod.outlook.com ([fe80::8191:f0ac:574a:d24d%3]) with mapi id 15.20.2474.023; Tue, 26 Nov 2019 13:16:27 +0000 From: Mihail Atanassov To: "dri-devel@lists.freedesktop.org" Subject: [PATCH 29/30] drm/bridge: add support for device links to bridge Thread-Topic: [PATCH 29/30] drm/bridge: add support for device links to bridge Thread-Index: AQHVpFu1iHJCIvZyo0WUUQNtpUlixw== Date: Tue, 26 Nov 2019 13:16:26 +0000 Message-ID: <20191126131541.47393-30-mihail.atanassov@arm.com> References: <20191126131541.47393-1-mihail.atanassov@arm.com> In-Reply-To: <20191126131541.47393-1-mihail.atanassov@arm.com> Accept-Language: en-GB, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [217.140.106.55] x-clientproxiedby: LO2P265CA0453.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:e::33) To VI1PR08MB4078.eurprd08.prod.outlook.com (2603:10a6:803:e5::28) x-mailer: git-send-email 2.23.0 Authentication-Results-Original: spf=none (sender IP is ) smtp.mailfrom=Mihail.Atanassov@arm.com; x-ms-exchange-messagesentrepresentingtype: 1 x-ms-publictraffictype: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 42ffda81-6bea-4a46-4735-08d77272dd82 X-MS-TrafficTypeDiagnostic: VI1PR08MB4560:|VI1PR08MB4560:|AM0PR08MB4209: x-ms-exchange-transport-forked: True X-Microsoft-Antispam-PRVS: x-checkrecipientrouted: true x-ms-oob-tlc-oobclassifiers: OLM:5797;OLM:5797; x-forefront-prvs: 0233768B38 X-Forefront-Antispam-Report-Untrusted: SFV:NSPM; SFS:(10009020)(4636009)(376002)(366004)(346002)(136003)(39860400002)(396003)(189003)(199004)(71190400001)(478600001)(1076003)(66476007)(186003)(26005)(5640700003)(52116002)(64756008)(256004)(8676002)(2351001)(66946007)(54906003)(81156014)(44832011)(3846002)(6116002)(6436002)(2616005)(66556008)(71200400001)(2906002)(11346002)(66446008)(99286004)(14454004)(81166006)(6916009)(5660300002)(25786009)(2501003)(8936002)(102836004)(5024004)(66066001)(36756003)(6486002)(6512007)(386003)(14444005)(4326008)(50226002)(76176011)(316002)(86362001)(7736002)(446003)(6506007)(305945005); DIR:OUT; SFP:1101; SCL:1; SRVR:VI1PR08MB4560; H:VI1PR08MB4078.eurprd08.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; received-spf: None (protection.outlook.com: arm.com does not designate permitted sender hosts) X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: IEzpmioFC9HXH/GMPwyuotFzMFChNW9v7z9ednY2Nth2mD3q3HnLQ3/mNFUDO/sQp+pcQWCqRKZG6KrCamm8dDmYhrp5wF1Aam/k9S4N+M1WBbAABYYF9nbc65dMhgKjCNp4YvHOHR0NMIB9Axx77gHi0VUNwDqTJ7R7aQN8r9xujdQofBGY3aZmVhfRicIya/rnP6IvfWPZVzCu2n0pMaSnlqMREjNE71OFOH9FfEflz4+4yWA8mB5ftPtuXMPOAvKkEzdpKeTzE+ut63Ht0YmIJXXQEJNA40mxLpqfW/Wjb9zvrgn+by7e9CODVdLH4hGQHndF/VOFF+R76FIrrp4fP7MiWYM2fioB/xmNTYpDOW+0GAWDJd3h+rx3qjoibmbhQmRxzqA/t954RRsApcjxzmKXdqKQhfE9BV9ODLkhh24tQ+92Y6HuSZxNQIQA MIME-Version: 1.0 X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR08MB4560 Original-Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Mihail.Atanassov@arm.com; X-EOPAttributedMessage: 0 X-MS-Exchange-Transport-CrossTenantHeadersStripped: DB5EUR03FT029.eop-EUR03.prod.protection.outlook.com X-Forefront-Antispam-Report: CIP:63.35.35.123; IPV:CAL; SCL:-1; CTRY:IE; EFV:NLI; SFV:NSPM; SFS:(10009020)(4636009)(396003)(376002)(346002)(39860400002)(136003)(199004)(189003)(22756006)(26826003)(50226002)(47776003)(8746002)(70586007)(8936002)(81156014)(2906002)(81166006)(8676002)(14444005)(6486002)(25786009)(5024004)(316002)(54906003)(386003)(478600001)(66066001)(76176011)(186003)(70206006)(99286004)(2351001)(76130400001)(6506007)(26005)(5660300002)(1076003)(356004)(446003)(11346002)(2616005)(6512007)(6116002)(3846002)(86362001)(36756003)(5640700003)(23756003)(6916009)(4326008)(2501003)(336012)(107886003)(102836004)(106002)(50466002)(305945005)(14454004)(7736002); DIR:OUT; SFP:1101; SCL:1; SRVR:AM0PR08MB4209; H:64aa7808-outbound-1.mta.getcheckrecipient.com; FPR:; SPF:Pass; LANG:en; PTR:ec2-63-35-35-123.eu-west-1.compute.amazonaws.com; A:1; MX:1; X-MS-Office365-Filtering-Correlation-Id-Prvs: a0850149-8228-499b-51bd-08d77272d7b7 NoDisclaimer: True X-Forefront-PRVS: 0233768B38 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: qHsbkF9x3YnJVgGA6DmuUtOD3+53P3GHGJnIAiTQ1wmADKYkBvOPV1KuIWY8I0iTzLUJtcfA8hHZ+KO4KE0XJ2uQEvDB1JhK3+xvQ05q4WN4Dyl8/T+sft2mZZkscKr+LhC+rzaTItnIVPxp/q0NnSp/JDWJaRN/96bnuJjiISxBs2MPQG05YyjQ0imJMCM3at9KUpZr8kKCb1MGpnGaaWbWUgm+RBP2+V5WHTeE+uMJiCwHXj5ei/6naQgkqB+SfPYhlLMiIn3AdUGo1IfbI/VJcnC8AxLA1JM4JQf2mzgDyYhEooFsYRqn/KkInKuG7aauEuRXRMSU6wckHFYtBiJfqJ3aGDB/cp50Qz8ADdo3FnGZ4HsYHwSLdvfVZD6IUI7oHgW31zWsvvBhd4lJqNkdH3bE55/wTE81Vg8AYjAQHT3zbvdTIQcCLkAEz+d6 X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Nov 2019 13:16:36.3814 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 42ffda81-6bea-4a46-4735-08d77272dd82 X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=f34e5979-57d9-4aaa-ad4d-b122a662184d; Ip=[63.35.35.123]; Helo=[64aa7808-outbound-1.mta.getcheckrecipient.com] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR08MB4209 X-Mailman-Original-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=22yLRF+OD4SGmB+ZPAp6mmB9i3wb2rmCRZA/8wtNzW4=; b=BtYl6AfDKJf5AUHeLBp1Xu0b0ZWHwd5Kh/QJ2ght1+5FzJH9v/eKebCg67AEiuxR9pnVsPfjW9c/W9jwqIaldk62TvrQcyZFLoGTYcTXGwuleChjMm79AZ3MdtrY/77WSmKVoMNm4tOJlcekRAp4ILsksN029qCkcTxVAL8DDhE= X-Mailman-Original-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=22yLRF+OD4SGmB+ZPAp6mmB9i3wb2rmCRZA/8wtNzW4=; b=BtYl6AfDKJf5AUHeLBp1Xu0b0ZWHwd5Kh/QJ2ght1+5FzJH9v/eKebCg67AEiuxR9pnVsPfjW9c/W9jwqIaldk62TvrQcyZFLoGTYcTXGwuleChjMm79AZ3MdtrY/77WSmKVoMNm4tOJlcekRAp4ILsksN029qCkcTxVAL8DDhE= X-Mailman-Original-Authentication-Results: spf=pass (sender IP is 63.35.35.123) smtp.mailfrom=arm.com; lists.freedesktop.org; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com;lists.freedesktop.org; dmarc=bestguesspass action=none header.from=arm.com; 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: Mihail Atanassov , David Airlie , "linux-kernel@vger.kernel.org" , Russell King , nd Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" From: Russell King Bridge devices have been a potential for kernel oops as their lifetime is independent of the DRM device that they are bound to. Hence, if a bridge device is unbound while the parent DRM device is using them, the parent happily continues to use the bridge device, calling the driver and accessing its objects that have been freed. This can cause kernel memory corruption and kernel oops. To control this, use device links to ensure that the parent DRM device is unbound when the bridge device is unbound, and when the bridge device is re-bound, automatically rebind the parent DRM device. Signed-off-by: Russell King Tested-by: Mihail Atanassov [reworked to use drm_bridge_init() for setting bridge->device] Signed-off-by: Mihail Atanassov --- drivers/gpu/drm/drm_bridge.c | 49 ++++++++++++++++++++++++++---------- include/drm/drm_bridge.h | 4 +++ 2 files changed, 40 insertions(+), 13 deletions(-) diff --git a/drivers/gpu/drm/drm_bridge.c b/drivers/gpu/drm/drm_bridge.c index cbe680aa6eac..e1f8db84651a 100644 --- a/drivers/gpu/drm/drm_bridge.c +++ b/drivers/gpu/drm/drm_bridge.c @@ -26,6 +26,7 @@ #include #include +#include #include #include "drm_crtc_internal.h" @@ -109,6 +110,7 @@ void drm_bridge_init(struct drm_bridge *bridge, struct device *dev, bridge->encoder = NULL; bridge->next = NULL; + bridge->device = dev; #ifdef CONFIG_OF bridge->of_node = dev->of_node; #endif @@ -492,6 +494,32 @@ void drm_atomic_bridge_enable(struct drm_bridge *bridge, EXPORT_SYMBOL(drm_atomic_bridge_enable); #ifdef CONFIG_OF +static struct drm_bridge *drm_bridge_find(struct drm_device *dev, + struct device_node *np, bool link) +{ + struct drm_bridge *bridge, *found = NULL; + struct device_link *dl; + + mutex_lock(&bridge_lock); + + list_for_each_entry(bridge, &bridge_list, list) + if (bridge->of_node == np) { + found = bridge; + break; + } + + if (found && link) { + dl = device_link_add(dev->dev, found->device, + DL_FLAG_AUTOPROBE_CONSUMER); + if (!dl) + found = NULL; + } + + mutex_unlock(&bridge_lock); + + return found; +} + /** * of_drm_find_bridge - find the bridge corresponding to the device node in * the global bridge list @@ -503,21 +531,16 @@ EXPORT_SYMBOL(drm_atomic_bridge_enable); */ struct drm_bridge *of_drm_find_bridge(struct device_node *np) { - struct drm_bridge *bridge; - - mutex_lock(&bridge_lock); - - list_for_each_entry(bridge, &bridge_list, list) { - if (bridge->of_node == np) { - mutex_unlock(&bridge_lock); - return bridge; - } - } - - mutex_unlock(&bridge_lock); - return NULL; + return drm_bridge_find(NULL, np, false); } EXPORT_SYMBOL(of_drm_find_bridge); + +struct drm_bridge *of_drm_find_bridge_devlink(struct drm_device *dev, + struct device_node *np) +{ + return drm_bridge_find(dev, np, true); +} +EXPORT_SYMBOL(of_drm_find_bridge_devlink); #endif MODULE_AUTHOR("Ajay Kumar "); diff --git a/include/drm/drm_bridge.h b/include/drm/drm_bridge.h index d6d9d5301551..68b27c69cc3d 100644 --- a/include/drm/drm_bridge.h +++ b/include/drm/drm_bridge.h @@ -382,6 +382,8 @@ struct drm_bridge { struct drm_encoder *encoder; /** @next: the next bridge in the encoder chain */ struct drm_bridge *next; + /** @device: Linux driver model device */ + struct device *device; #ifdef CONFIG_OF /** @of_node: device node pointer to the bridge */ struct device_node *of_node; @@ -407,6 +409,8 @@ void drm_bridge_init(struct drm_bridge *bridge, struct device *dev, const struct drm_bridge_timings *timings, void *driver_private); struct drm_bridge *of_drm_find_bridge(struct device_node *np); +struct drm_bridge *of_drm_find_bridge_devlink(struct drm_device *dev, + struct device_node *np); int drm_bridge_attach(struct drm_encoder *encoder, struct drm_bridge *bridge, struct drm_bridge *previous);