Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp429348pxb; Tue, 3 Nov 2020 03:27:44 -0800 (PST) X-Google-Smtp-Source: ABdhPJwl5lyO+UPiYnWm6l9SHSloywnIhsxmyupQcJU4RK2qDzlARCPXtjR++3Arm5IugYvqTagc X-Received: by 2002:a50:f61a:: with SMTP id c26mr21544643edn.324.1604402864706; Tue, 03 Nov 2020 03:27:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604402864; cv=none; d=google.com; s=arc-20160816; b=Y8E5h459AY84axnq5mpUMW+0omA846BHB7aQkzVboirLYAOaN45WXZxqkNfYJGfBDb rT4Rmk0WGqL7yTPe+Oo+1fJ/bGCZSKVwZ6rx8MtIIH370E/VIT87rFrZvjFx2Kxbfii0 HTzopA3R4xhKZfoO1fv44KQroTAaBLeSjTXxv31QPhdBVC9GxpqWK8n+MTVZH+yjL5M6 osvotp0qrGe5/4vWPGD11oyp6DxY58dLDfNFSWutGkPmgqCZsqPphHrzV8iY5zy2FmFL vnpjCtE9LKsK1RL97itsK94y4LT3QptsBbkkniIkHwICGiZLpJQinXFvAkn9yL4Krap3 L/1A== 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:to:from:date:dkim-signature :dkim-signature; bh=9K7ZUeG7Ei19ZU1lw4LTHV9xBo3MS7gvaamZszlYvNM=; b=fb+4c9PBIacJl9wq4PfZZWwtv8Vm27H87UXOcWP1mL8+JAoW8WHOlKJQAXLjE8CNjf niCp+YY35Z4F4RsTO0pytiLuIrPITb37UsRv921C+vY+S2xwApbfAuzOv1pifanbTmHl qwSeNCYhcEyA8zfzDrSih9Oh91bTMFQhB8jzRhveNPO8/oQDlmsFhLoMAnxJTXs5UBO2 yaQ+nkJ10EoxyuuLyBEd8IeQpyhyWEqJ1zRuVNXh+uIFDPiVIAhrYwQcFlGDjTfrU9bw kySdaNYwQwtZEI+/nhHrQgypmaia+VuJF5PvdmdkfZseTFYCfXIzJF9I2NhUd89wcAAr Zebw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cerno.tech header.s=fm1 header.b=ZStu7JyN; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b=qMTZjzWj; 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 e15si9124920eje.12.2020.11.03.03.27.22; Tue, 03 Nov 2020 03:27:44 -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=ZStu7JyN; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b=qMTZjzWj; 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 S1728483AbgKCLZ3 (ORCPT + 99 others); Tue, 3 Nov 2020 06:25:29 -0500 Received: from wout2-smtp.messagingengine.com ([64.147.123.25]:50277 "EHLO wout2-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726058AbgKCLZ2 (ORCPT ); Tue, 3 Nov 2020 06:25:28 -0500 Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailout.west.internal (Postfix) with ESMTP id 09888B17; Tue, 3 Nov 2020 06:25:26 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Tue, 03 Nov 2020 06:25:27 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cerno.tech; h= date:from:to:subject:message-id:references:mime-version :content-type:in-reply-to; s=fm1; bh=9K7ZUeG7Ei19ZU1lw4LTHV9xBo3 MS7gvaamZszlYvNM=; b=ZStu7JyNauLjo9d/Oy5VlNq2SAK77bUhJ7UpsF8Yly4 HfN8Wwk+J2pmmYe4cAQw7Cz/tiSvDWsDfbh0dk7cg7WTZeKBWsvYAX4p6XcUAtgr Z+Jt52dmaF1dQt2nHEkrGdjfcOwPKU4+/e2Q4NrXhS8Qi5EUI7udpDm3kIo1y/DP HBnUaadCvgzu4RgcH3lcqMV9euCTvZ9ZA3KwpWKVpEwTsjyut0l3tmODlqJqtaE9 FZ6VjOBWsOFI1OjmY6iAYRZYOEaSRsfJAgl4bopm0tuJeTqZvjqmnICdQ+/ytoiX 4LtSAIax8SVhgeRiwmkzEMG1dCsgSAnCjN2wNQhxtkQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=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=9K7ZUe G7Ei19ZU1lw4LTHV9xBo3MS7gvaamZszlYvNM=; b=qMTZjzWjOEHjSDRK8zNZOr rPZ5yXql14hB9cohmRodzmeUTT0xlaWlrO4HMZraKjm42W2mE0iXfsEV2vhz/8L/ hS2mI2U68SAVLMMRwE/X99gVAiKO0RUxfH+ds5fZ6r9D5XOdWDW2hElSXlcMvaIO eLxVdq7vGeZzyV+fddLX7V2QKjfHpCFntkBv2u4FAbuqhxvC2t3StzfYNTMpUmS1 f+Ms4y2kAdRTSsLhgZUrUTc7iHOYdKBew+UWIBD040FKW2Yyk+tm5jfl2AmjAeLI EeHNKklWMNtr3jt0CeRWgOu3ydNSve/MpQXnW7bID5Bf3cX1wJ/pM/lnA3D+D4IQ == X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedujedruddtfedgvdekucetufdoteggodetrfdotf 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 E0DCC3280064; Tue, 3 Nov 2020 06:25:24 -0500 (EST) Date: Tue, 3 Nov 2020 12:25:22 +0100 From: Maxime Ripard To: Thomas Zimmermann , Tian Tao , maarten.lankhorst@linux.intel.com, airlied@linux.ie, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2] drm: Add the new api to install irq Message-ID: <20201103112522.oescqpkrzbwohhnq@gilmour.lan> References: <1604369441-65254-1-git-send-email-tiantao6@hisilicon.com> <20201103095205.ywabphbc2xbop6ae@gilmour.lan> <20201103103832.gwjqf4urrn5y7zk5@gilmour.lan> <20201103105508.GD401619@phenom.ffwll.local> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="w6qgqecl3tuig3lx" Content-Disposition: inline In-Reply-To: <20201103105508.GD401619@phenom.ffwll.local> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --w6qgqecl3tuig3lx Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Hi! On Tue, Nov 03, 2020 at 11:55:08AM +0100, Daniel Vetter wrote: > On Tue, Nov 03, 2020 at 11:38:32AM +0100, Maxime Ripard wrote: > > 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 *p= arent, > > > >> 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? > >=20 > > 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. >=20 > drm_device is guaranteed to outlive devm_, plus the hooks are meant to > shut down hw. hw isn't around anymore when we do drmm_ cleanup, at least > not in full generality. drm_dev_put is either called through devm or in remove / unbind, and the drm_device takes a reference on its parent device, so how can the drm_device outlive its parent 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. > >=20 > > 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. >=20 > Don't do that, it's broken :-) Well, yeah it's usually a pretty bad situation, but if we can fix it for free it doesn't hurt? Maxime --w6qgqecl3tuig3lx Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iHUEABYIAB0WIQRcEzekXsqa64kGDp7j7w1vZxhRxQUCX6E+IgAKCRDj7w1vZxhR xek5AP0SMGil1aZhgogOLSvo2WtgLW3tKgKD4MVdLNpykAcXswEAmr8AwkzvO7Sk hbQN0dAM7pUC2KnH4glLBzIZsHccxAk= =NZuN -----END PGP SIGNATURE----- --w6qgqecl3tuig3lx--