Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp402625pxb; Tue, 3 Nov 2020 02:40:13 -0800 (PST) X-Google-Smtp-Source: ABdhPJzJjs2q5TdP9h1Xlet0tgWqn4FtuGWq3r8qfi5JWSfBzrjOwDtwcKEmmzCqkDwJ37v78/GD X-Received: by 2002:a17:906:1352:: with SMTP id x18mr16338717ejb.476.1604400013567; Tue, 03 Nov 2020 02:40:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604400013; cv=none; d=google.com; s=arc-20160816; b=0cLQfvUaTcipJ8y2wqJTTDgnCpLpesKQZg/na5DpYppYW6ToFoGwwEGwqFlgwLuQPm nfkI66Xte3gS6QAUhweGAT9hdtOyD06ftT1LTxaOWWbEVOBFlJEHidlSzgqEeT/DB8EZ cKBKuaeSGqnArzzCEGoClkYISNkj6mlGCSVkLibwzgINcq/9TtqxtT4ZjguPpFRU/XQd lASpfXKnhUN6tibjKbfmBtaU2YtDSkFJiVSAapJcy7QFqc0ZzZt4/xRttbd/VrkbvR3W D6idWPoG5K8v/t1lvktYUO8hFKQmcKo903LnwS91OzuGnZll6sS23bpZglkBHsLb58Dv T3fQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature :dkim-signature; bh=MX0g5U1cLJF88fJdoeBP1gFRJooWD/MUJDmMlQmqW5U=; b=JXR8lPDvmNGi7+wPGRdR08wiMVkqhb782escEhwJ/U+c+GD3NpJUlMjpsO5JloS6h0 TCTy8ovGa7xkUp5wcwof25LgmNb0vaYWAWyqIhiNlNJOTlzg+NFvb4qNTO+Kr325OHP3 9LUTRjkYtbihAYg7/xz89RkNG6kfflKUwG5tWFL1NFmeuLHH9HQKvmRemVUNBU/7ubYj UnnBdyzvQMhwhyIl++Kqu0dHvi7vv/WvrgYxLRrDNQe1unhBbw0PqmTS6NHSsZyt3OsY tDer2A5J+Jh1ug5nXqI6/UFK8E6f2Q4WIVobk9YFoP6S7EtvyIxXvvS40OtE0/1gTBrV dvpA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cerno.tech header.s=fm1 header.b=J5GCTTi8; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b="cDny/sPl"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=cerno.tech Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id x4si8568221edv.297.2020.11.03.02.39.51; Tue, 03 Nov 2020 02:40:13 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@cerno.tech header.s=fm1 header.b=J5GCTTi8; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b="cDny/sPl"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=cerno.tech Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728180AbgKCKii (ORCPT + 99 others); Tue, 3 Nov 2020 05:38:38 -0500 Received: from wout2-smtp.messagingengine.com ([64.147.123.25]:41755 "EHLO wout2-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728150AbgKCKii (ORCPT ); Tue, 3 Nov 2020 05:38:38 -0500 Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailout.west.internal (Postfix) with ESMTP id CD78FB58; Tue, 3 Nov 2020 05:38:36 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Tue, 03 Nov 2020 05:38:37 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cerno.tech; h= date:from:to:cc:subject:message-id:references:mime-version :content-type:in-reply-to; s=fm1; bh=MX0g5U1cLJF88fJdoeBP1gFRJoo WD/MUJDmMlQmqW5U=; b=J5GCTTi8WvYIEA706yNjNF4nrkuOrRV+jrSTG0Fy5ik AOHfX3wvvRDXKpbElyk7cYysGU455VWMDQhXbn+20s+tK6H3vJR1wrh+9Hgq6XbA K5YXuaWK34yxh9vDULhkptZwkKtC5dbWZRXMPXJ0hRdi6YA1eaev3zNzI8/mOpvT LZ/UMvgx3K0Q5yJq6wV+Pf9ANtkgqAjzu6v4v8nqU90dM7Y80GoXFb9KV/y9E+6S w9OfMsjSsmc7p/m6Hlow1JYZSofOjK+bkB9CRAIQZux3Wor52+U305PVo2/C/2rN 0ao5Un0dgxhTjGBGLz5KCEZQStInnQfWtVV0z0S51aA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm1; bh=MX0g5U 1cLJF88fJdoeBP1gFRJooWD/MUJDmMlQmqW5U=; b=cDny/sPlEVLhEnHkenX0io BRLscEMIsxcOGlmvpCJ8IY8ZRbPUN6EQz506awE5vTCwHHvusJBC48TYnTf0vhWm 9MtDgT6eeME1MXyFsMI2Wmx4RSlpMvFhEk394Uuu26IIRmq1vsSx9f34AWi9O+kV m8UdoMef4LtaLGkUlTST6qykCqW2xtY3CDmIPDB1OXjXaWa4kMi6XCorqvfsfd6H HgwZZu3p5SJHFtazlQm5a7jgR1fM0H6WDJiDwdmTkXJwF0zG9H58uAuz1VuGI+EL UVtptkatTZ3GUvyXDmfQG4Kosw7N/gErUNG1QFGxfm/mEwPjRr3qNgKIt8v47ZSw == X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedujedruddtfedgudekucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvffukfhfgggtuggjsehgtderredttddvnecuhfhrohhmpeforgigihhm vgcutfhiphgrrhguuceomhgrgihimhgvsegtvghrnhhordhtvggthheqnecuggftrfgrth htvghrnhepleekgeehhfdutdeljefgleejffehfffgieejhffgueefhfdtveetgeehieeh gedunecukfhppeeltddrkeelrdeikedrjeeinecuvehluhhsthgvrhfuihiivgeptdenuc frrghrrghmpehmrghilhhfrhhomhepmhgrgihimhgvsegtvghrnhhordhtvggthh X-ME-Proxy: Received: from localhost (lfbn-tou-1-1502-76.w90-89.abo.wanadoo.fr [90.89.68.76]) by mail.messagingengine.com (Postfix) with ESMTPA id 7B1BD328005A; Tue, 3 Nov 2020 05:38:34 -0500 (EST) Date: Tue, 3 Nov 2020 11:38:32 +0100 From: Maxime Ripard To: Thomas Zimmermann Cc: Tian Tao , maarten.lankhorst@linux.intel.com, airlied@linux.ie, daniel@ffwll.ch, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2] drm: Add the new api to install irq Message-ID: <20201103103832.gwjqf4urrn5y7zk5@gilmour.lan> References: <1604369441-65254-1-git-send-email-tiantao6@hisilicon.com> <20201103095205.ywabphbc2xbop6ae@gilmour.lan> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="oeooz33tgxv72ou6" Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --oeooz33tgxv72ou6 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Tue, Nov 03, 2020 at 11:10:27AM +0100, Thomas Zimmermann wrote: > Hi >=20 > Am 03.11.20 um 10:52 schrieb Maxime Ripard: > > On Tue, Nov 03, 2020 at 10:10:41AM +0800, Tian Tao wrote: > >> Add new api devm_drm_irq_install() to register interrupts, > >> no need to call drm_irq_uninstall() when the drm module is removed. > >> > >> v2: > >> fixed the wrong parameter. > >> > >> Signed-off-by: Tian Tao > >> --- > >> drivers/gpu/drm/drm_drv.c | 23 +++++++++++++++++++++++ > >> include/drm/drm_drv.h | 3 ++- > >> 2 files changed, 25 insertions(+), 1 deletion(-) > >> > >> diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c > >> index cd162d4..0fe5243 100644 > >> --- a/drivers/gpu/drm/drm_drv.c > >> +++ b/drivers/gpu/drm/drm_drv.c > >> @@ -39,6 +39,7 @@ > >> #include > >> #include > >> #include > >> +#include > >> #include > >> #include > >> #include > >> @@ -678,6 +679,28 @@ static int devm_drm_dev_init(struct device *paren= t, > >> return ret; > >> } > >> =20 > >> +static void devm_drm_dev_irq_uninstall(void *data) > >> +{ > >> + drm_irq_uninstall(data); > >> +} > >> + > >> +int devm_drm_irq_install(struct device *parent, > >> + struct drm_device *dev, int irq) > >> +{ > >> + int ret; > >> + > >> + ret =3D drm_irq_install(dev, irq); > >> + if (ret) > >> + return ret; > >> + > >> + ret =3D devm_add_action(parent, devm_drm_dev_irq_uninstall, dev); > >> + if (ret) > >> + devm_drm_dev_irq_uninstall(dev); > >> + > >> + return ret; > >> +} > >> +EXPORT_SYMBOL(devm_drm_irq_install); > >> + > >=20 > > Shouldn't we tie the IRQ to the drm device (so with drmm_add_action) > > instead of tying it to the underlying device? >=20 > If the HW device goes away, there won't be any more interrupts. So it's > similar to devm_ functions for I/O memory. Why would you use the drmm_ > interface? drm_irq_install/uninstall do more that just calling request_irq and free_irq though, they will also run (among other things) the irq-related hooks in the drm driver (irq_preinstall, irq_postinstall irq_uninstall) and wake anything waiting for a vblank to occur, so we need the DRM device and driver to still be around when we run drm_irq_uninstall. That's why (I assume) you have to pass the drm_device as an argument and not simply the device. This probably works in most case since you would allocate the drm_device with devm_drm_dev_alloc, and then run drm_irq_install, so in the undoing phase you would have first drm_irq_uninstall to run, and everything is fine. However, if one doesn't use devm_drm_dev_alloc but would use devm_drm_irq_install, you would have first remove being called that would free the drm device, and then drm_irq_uninstall which will use a free'd pointer. So yeah, even though the interrupt line itself is tied to the device, all the logic we have around the interrupt that is dealt with in drm_irq_install is really tied to the drm_device. And since we tie the life of drm_device to its underlying device already (either implicitly through devm_drm_dev_alloc, or explictly through manual allocation in probe and free in remove) we can't end up in a situation where the drm_device outlives its device. Maxime --oeooz33tgxv72ou6 Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iHUEABYIAB0WIQRcEzekXsqa64kGDp7j7w1vZxhRxQUCX6EzKAAKCRDj7w1vZxhR xYXHAQDK62VGz5kiFX28FD/Ad8gOyU18dwf6P+Kf7ujlHSflhAD7Bgq3u+SyxPLF gDMzG4LU5oCFwaNNi3YfaMjC7wAIKQI= =rc5S -----END PGP SIGNATURE----- --oeooz33tgxv72ou6--