Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp440666pxb; Tue, 3 Nov 2020 03:48:31 -0800 (PST) X-Google-Smtp-Source: ABdhPJw1GntekFT4xA5KJpPs2m1bBbJYEeUKaGKPEhc8FXpzQjaElVSF+ASHgUHEXRwa17eDmd1Y X-Received: by 2002:a50:930d:: with SMTP id m13mr12273975eda.117.1604404111033; Tue, 03 Nov 2020 03:48:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604404111; cv=none; d=google.com; s=arc-20160816; b=yA7KlZs8KG8k/MU5GnGLMAB1XvKQfKFTlZGqVxvKn+TxpGkYWxFzTaLi3Gpi1D6in8 cIagaYUwmBQegTf1mRhX9J72+ZD652gObsJDchma2iPdPWWeaWPLuOcndmP4x6RvQvMR zoreN+NqgejK6oGZ7NF6Gw7EAyr0d6GWFQVgQ2CCquBQLYcoALX4s9G31pqEwF7ruRmD +FHBZEL+BodsytV7j9cBGwfBZILvkmZK6wNjqpTvVwFOmJN+n6TH+aNz3T22T6fY3YHO 7n7PjE38HlnllbwbYqKY36rv4WriTJScDDV22srW09BLVkgMrvqIMvpMHfxcbsljmiZe GZ5g== 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-transfer-encoding :content-disposition:mime-version:references:mail-followup-to :message-id:subject:cc:to:from:date:dkim-signature; bh=v9zBxXo2df1AnoezGK/wVV9EmN0bJs0g58KZVKvJadk=; b=sPz3D3x3kqgnabkzOJOe843q260x5yUTs3Yn2b7bQ9chg5jVOR7m0uSLDlwutXZZWS EW5Vnmf0iZzjwjAdhqyBHikXCIejNSQNLf8Cz5u5YUTnc1ubnN+aHa91Cs8bnDfBwrjI ccQpSfV8YQKPCZCSTUcQmeSb880XO3BC7AvFZNwGyrAgG9rM8zhxWqOeVU/SVuACzCkT uxwn17RSoLSaPw662dXWbbL3kQ9NGsVSalg4KBkNugF2kdBK/Ej88mzKrmEqZ19W64t2 qFGOm5/CqMRBpleBtmCHSdjll6ppAwd7RbWWUZ67QDFVN5LgjS0GqDDPRZG6LzBz37yU Lyqw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ffwll.ch header.s=google header.b=f3Pd+fns; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r29si8956582edc.378.2020.11.03.03.48.08; Tue, 03 Nov 2020 03:48:31 -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=@ffwll.ch header.s=google header.b=f3Pd+fns; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728573AbgKCLqn (ORCPT + 99 others); Tue, 3 Nov 2020 06:46:43 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50224 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727665AbgKCLqm (ORCPT ); Tue, 3 Nov 2020 06:46:42 -0500 Received: from mail-wr1-x443.google.com (mail-wr1-x443.google.com [IPv6:2a00:1450:4864:20::443]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 65AF8C0613D1 for ; Tue, 3 Nov 2020 03:46:40 -0800 (PST) Received: by mail-wr1-x443.google.com with SMTP id y12so18192619wrp.6 for ; Tue, 03 Nov 2020 03:46:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ffwll.ch; s=google; h=date:from:to:cc:subject:message-id:mail-followup-to:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to; bh=v9zBxXo2df1AnoezGK/wVV9EmN0bJs0g58KZVKvJadk=; b=f3Pd+fnslyKGUR5dMhHC/JdwkhW8K1KStcRWAllCfNjxd7FMqAup5EA7Gqw09toU4N 2Pomxt0E7/SsCkhP9R7Gkts+9wd2X5a54VImwV546onxGlbM9OyiRkBLym/5lbxBdiX4 JqJ4sL78YQoO5YnliwAc4IR+RY00pswxdOg7A= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id :mail-followup-to:references:mime-version:content-disposition :content-transfer-encoding:in-reply-to; bh=v9zBxXo2df1AnoezGK/wVV9EmN0bJs0g58KZVKvJadk=; b=aElanfuZrFE7MwYb/xpriXz8xecujZGdL11S+kvNTxsCurwOz8o1vJoWJ7ayfHNo1x xwhcb9UHVaDqv/sXtioMnJDx6vUfoAvPN5aQObv443DusBF5xaUWy5m7Lghk30AoQj4Q OcZwsgh9qBhbCbU/YOs4QTUNSzG/SqIrEnGxhI15oXG5f/NXwO5DhDx+kpcvgEEnbKde Cm8NyL4NKkAbAFZe/x+4TEQkst/0vGvKCQFZ4DbGI3b0xH+tCzra9oTXSGyoEkE1NCZK XoX2jnPHZR9/Zh1KczYdTvbo5ta3SQSpE0HGcQui5tBl8T9bJZp1BYI6SOePIgZaXkul NQ4w== X-Gm-Message-State: AOAM530N1Z2NBOT4Li2z0UPClSLjQoafoCHuIxMgNcEBjC3IEs3M5jNg v6zZNMuggNIn27gs/ooorYDIXw== X-Received: by 2002:a5d:4c4b:: with SMTP id n11mr25281388wrt.171.1604403999151; Tue, 03 Nov 2020 03:46:39 -0800 (PST) Received: from phenom.ffwll.local ([2a02:168:57f4:0:efd0:b9e5:5ae6:c2fa]) by smtp.gmail.com with ESMTPSA id e2sm27170785wrr.85.2020.11.03.03.46.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Nov 2020 03:46:38 -0800 (PST) Date: Tue, 3 Nov 2020 12:46:36 +0100 From: Daniel Vetter To: Thomas Zimmermann Cc: Maxime Ripard , 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: <20201103114636.GH401619@phenom.ffwll.local> Mail-Followup-To: Thomas Zimmermann , Maxime Ripard , Tian Tao , maarten.lankhorst@linux.intel.com, airlied@linux.ie, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org References: <1604369441-65254-1-git-send-email-tiantao6@hisilicon.com> <20201103095205.ywabphbc2xbop6ae@gilmour.lan> <20201103103832.gwjqf4urrn5y7zk5@gilmour.lan> <20201103105508.GD401619@phenom.ffwll.local> <2c364588-7636-f6ad-4cc6-0800088c511b@suse.de> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <2c364588-7636-f6ad-4cc6-0800088c511b@suse.de> X-Operating-System: Linux phenom 5.7.0-1-amd64 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Nov 03, 2020 at 12:25:06PM +0100, Thomas Zimmermann wrote: > Hi > > Am 03.11.20 um 11:55 schrieb Daniel Vetter: > > 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 > >>> > >>> 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 *parent, > >>>>> return ret; > >>>>> } > >>>>> > >>>>> +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 = drm_irq_install(dev, irq); > >>>>> + if (ret) > >>>>> + return ret; > >>>>> + > >>>>> + ret = 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); > >>>>> + > >>>> > >>>> Shouldn't we tie the IRQ to the drm device (so with drmm_add_action) > >>>> instead of tying it to the underlying device? > >>> > >>> 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. > > > > 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. > > > >> 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. > > > > Don't do that, it's broken :-) > > Umm, I just saw that hibmc doesn't use devm_drm_dev_alloc. So maybe we > have to convert it first before using the managed irq function. OTOH > converting it is a good idea in any case, so why not. :) Yeah that doesn't work as-is. I guess the second option would be if devm_drm_dev_irqinstall would take a drm_dev_get() reference of its own. Not sure that's a good idea, but it would make the thing a bit more flexible. -Daniel > > Best regards > Thomas > > > > >> 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. > > > > Most drivers get their drm_device lifetime completely wrong. That's why I > > typed drmm_ stuff. So this isn't a surprise at all, but it might motiveate > > a bunch more people to fix this up correctly. > > > > Also, these drm_irq functions are 100% optional helpers (should maybe > > rename them to make this clearer) for modern drivers. They're only built > > in for DRIVER_LEGACY, because hysterical raisins. > > -Daniel > > > > -- > Thomas Zimmermann > Graphics Driver Developer > SUSE Software Solutions Germany GmbH > Maxfeldstr. 5, 90409 N?rnberg, Germany > (HRB 36809, AG N?rnberg) > Gesch?ftsf?hrer: Felix Imend?rffer > _______________________________________________ > dri-devel mailing list > dri-devel@lists.freedesktop.org > https://lists.freedesktop.org/mailman/listinfo/dri-devel -- Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch