From: Biju Das <biju.das.jz@bp.renesas.com>
To: Tommaso Merciai <tommaso.merciai.xr@bp.renesas.com>
Cc: Tommaso Merciai <tomm.merciai@gmail.com>,
Prabhakar Mahadev Lad <prabhakar.mahadev-lad.rj@bp.renesas.com>,
"linux-renesas-soc@vger.kernel.org"
<linux-renesas-soc@vger.kernel.org>,
David Airlie <airlied@gmail.com>, Simona Vetter <simona@ffwll.ch>,
Maarten Lankhorst <maarten.lankhorst@linux.intel.com>,
Maxime Ripard <mripard@kernel.org>,
Thomas Zimmermann <tzimmermann@suse.de>,
Rob Herring <robh@kernel.org>,
Krzysztof Kozlowski <krzk+dt@kernel.org>,
Conor Dooley <conor+dt@kernel.org>,
Geert Uytterhoeven <geert+renesas@glider.be>,
"magnus.damm" <magnus.damm@gmail.com>,
Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>,
"dri-devel@lists.freedesktop.org"
<dri-devel@lists.freedesktop.org>,
"devicetree@vger.kernel.org" <devicetree@vger.kernel.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: RE: [PATCH v10 08/12] drm: renesas: rz-du: Separate the DU instance from the DRM device
Date: Wed, 25 Nov 2026 13:49:21 +0000 [thread overview]
Message-ID: <OS3PR01MB6596FE927C038F264BE0C97186432@OS3PR01MB6596.jpnprd01.prod.outlook.com> (raw)
In-Reply-To: <awbm6f3ovtva5gg2@tom-desktop>
Hi Tommaso,
> -----Original Message-----
> From: Tommaso Merciai <tommaso.merciai.xr@bp.renesas.com>
> Sent: 25 November 2026 13:47
> Subject: Re: [PATCH v10 08/12] drm: renesas: rz-du: Separate the DU instance from the DRM device
>
> Hi Biju,
>
> On Wed, Nov 25, 2026 at 07:07:00AM +0000, Biju Das wrote:
> > Hi Tommaso,
> >
> > > -----Original Message-----
> > > From: Tommaso Merciai <tommaso.merciai.xr@bp.renesas.com>
> > > Sent: 24 November 2026 18:50
> > > Subject: Re: [PATCH v10 08/12] drm: renesas: rz-du: Separate the DU
> > > instance from the DRM device
> > >
> > > Hi Biju,
> > >
> > > On Tue, Nov 24, 2026 at 04:04:48PM +0000, Biju Das wrote:
> > > > Hi Tommaso,
> > > >
> > > > > -----Original Message-----
> > > > > From: Tommaso Merciai <tommaso.merciai.xr@bp.renesas.com>
> > > > > Sent: 24 November 2026 15:24
> > > > > Subject: Re: [PATCH v10 08/12] drm: renesas: rz-du: Separate the
> > > > > DU instance from the DRM device
> > > > >
> > > > > Hi Biju,
> > > > >
> > > > > On Tue, Nov 24, 2026 at 12:51:18PM +0000, Biju Das wrote:
> > > > > >
> > > > > > Hi Tommaso,
> > > > > >
> > > > > > > -----Original Message-----
> > > > > > > From: Tommaso Merciai <tommaso.merciai.xr@bp.renesas.com>
> > > > > > > Sent: 24 November 2026 11:59
> > > > > > > Subject: Re: [PATCH v10 08/12] drm: renesas: rz-du: Separate
> > > > > > > the DU instance from the DRM device
> > > > > > >
> > > > > > > Hi Biju,
> > > > > > >
> > > > > > > On Tue, Nov 24, 2026 at 09:33:13AM +0000, Biju Das wrote:
> > > > > > > > Hi Tommaso,
> > > > > > > >
> > > > > > > > > -----Original Message-----
> > > > > > > > > From: Tommaso Merciai
> > > > > > > > > <tommaso.merciai.xr@bp.renesas.com>
> > > > > > > > > Sent: 24 November 2026 09:21
> > > > > > > > > Subject: Re: [PATCH v10 08/12] drm: renesas: rz-du:
> > > > > > > > > Separate the DU instance from the DRM device
> > > > > > > > >
> > > > > > > > > Hi Biju,
> > > > > > > > > Thanks for your review.
> > > > > > > > >
> > > > > > > > > On Mon, Nov 23, 2026 at 04:59:32PM +0000, Biju Das wrote:
> > > > > > > > > > Hi Tommaso,
> > > > > > > > > >
> > > > > > > > > > > -----Original Message-----
> > > > > > > > > > > From: Tommaso Merciai
> > > > > > > > > > > <tommaso.merciai.xr@bp.renesas.com>
> > > > > > > > > > > Sent: 13 November 2026 12:20
> > > > > > > > > > > Subject: [PATCH v10 08/12] drm: renesas: rz-du:
> > > > > > > > > > > Separate the DU instance from the DRM device
> > > > > > > > > > >
> > > > > > > > > > > On RZ/G3E two DU instances share a DRM device, which
> > > > > > > > > > > can only be created once both instances have been probed.
> > > > > > > > > > >
> > > > > > > > > > > Split the DU device structure: keep the match data
> > > > > > > > > > > and the registers in a structure allocated with the
> > > > > > > > > > > platform device, and allocate the KMS objects with
> > > > > > > > > > > the DRM device in a new
> > > > > > > > > > > rzg2l_du_instance_init() helper, as they are
> > > > > > > > > > > released
> > > > > > > > > with it.
> > > > > > > > > > >
> > > > > > > > > > > No functional change intended.
> > > > > > > > > > >
> > > > > > > > > > > Signed-off-by: Tommaso Merciai
> > > > > > > > > > > <tommaso.merciai.xr@bp.renesas.com>
> > > > > > > > > > > ---
> > > > > > > > > > > v9->v10:
> > > > > > > > > > > - New patch.
> > > > > > > > > > >
> > > > > > > > > > > drivers/gpu/drm/renesas/rz-du/rzg2l_du_drv.c | 61
> > > > > > > > > > > ++++++++++++++------
> > > > > > > > > > > 1 file changed, 44 insertions(+), 17 deletions(-)
> > > > > > > > > > >
> > > > > > > > > > > diff --git
> > > > > > > > > > > a/drivers/gpu/drm/renesas/rz-du/rzg2l_du_drv.c
> > > > > > > > > > > b/drivers/gpu/drm/renesas/rz- du/rzg2l_du_drv.c
> > > > > > > > > > > index
> > > > > > > > > > > d3cccbdf9012..d102876c07e1 100644
> > > > > > > > > > > --- a/drivers/gpu/drm/renesas/rz-du/rzg2l_du_drv.c
> > > > > > > > > > > +++ b/drivers/gpu/drm/renesas/rz-du/rzg2l_du_drv.c
> > > > > > > > > > > @@ -162,6 +162,27 @@ static int
> > > > > > > > > > > rzg2l_du_pm_resume(struct device
> > > > > > > > > > > *dev) static DEFINE_SIMPLE_DEV_PM_OPS(rzg2l_du_pm_ops,
> > > > > > > > > > > rzg2l_du_pm_suspend, rzg2l_du_pm_resume);
> > > > > > > > > > >
> > > > > > > > > > > +/*
> > > > > > > > > > > +---------------------------------------------------
> > > > > > > > > > > +----
> > > > > > > > > > > +----
> > > > > > > > > > > +----
> > > > > > > > > > > +----
> > > > > > > > > > > +----
> > > > > > > > > > > +------
> > > > > > > > > > > + * DU instance
> > > > > > > > > > > + */
> > > > > > > > > > > +
> > > > > > > > > > > +static int rzg2l_du_instance_init(struct rzg2l_du_device *du,
> > > > > > > > > > > + struct drm_device *ddev) {
> > > > > > > > > > > + struct rzg2l_du_device *rcdu;
> > > > > > > > > > > +
> > > > > > > > > > > + rcdu = drmm_kzalloc(ddev, sizeof(*rcdu), GFP_KERNEL);
> > > > > > > > > > > + if (!rcdu)
> > > > > > > > > > > + return -ENOMEM;
> > > > > > > > > >
> > > > > > > > > > Why there is duplicate allocation of rcdu? One in
> > > > > > > > > > probe() and here
> > > > > > > > >
> > > > > > > > > The two allocations have different lifetimes.
> > > > > > > > >
> > > > > > > > > The one in rzg2l_du_probe() is tied to the platform device.
> > > > > > > > > It holds what is needed before the DRM device exists and
> > > > > > > > > outside of the component bind (dev, info, mmio, and
> > > > > > > > > ddev/is_master for the master, PM and remove), as on
> > > > > > > > > RZ/G3E
> > > > > > > the DRM device is only created once both instances have been probed.
> > > > > > > > >
> > > > > > > > > The one in rzg2l_du_instance_init() holds the KMS
> > > > > > > > > objects (crtcs, vsps, lvds, index). Their drmm cleanup
> > > > > > > > > handlers point into it and run when the DRM device is
> > > > > > > > > released, which can happen after the platform device has
> > > > > > > > > been unbound,
> > > > > > > so it has to be allocated with the DRM device.
> > > > > > > >
> > > > > > > > Then there is an issue right, platform unbound will unmap
> > > > > > > > mmio and other data structures it allocated in
> > > > > > > > rzg2l_du_probe()and drm driver is using after that( Use
> > > > > > > > after free Bug)
> > > > > > >
> > > > > > > Mmmm In theory no.
> > > > > > >
> > > > > > > The KMS part keeps its own copy of dev, info and mmio, and
> > > > > > > its drmm cleanup handlers only drop references, they don't access the hardware.
> > > > > >
> > > > > > Can you please make sure these variables set to NULL, after
> > > > > > Platform unbound?
> > > > >
> > > > > Please correct me if I'm wrong but IMHO this patch keeps the
> > > > > same behaviour as the driver before this series.
> > > > >
> > > > > Where rcdu is embedded in the DRM device (devm_drm_dev_alloc())
> > > > > and mmio is devm managed. Setting the pointers to NULL would
> > > > > only turn an invalid access into a NULL
> > > dereference no?
> > > >
> > > > Ack.
> > > >
> > > > But why you need copy? What preventing to use original allocated
> > > > rcdu in rzg2l_du_modeset_init_du()?
> > >
> > > The copy is needed because the two DUs share one DRM device, which
> > > can only be created at bind time, once both instances have been probed.
> >
> > That is ok. Both DU's share 1 DRM device.
> >
> > >
> > > Before this series, the DRM device was allocated in probe with
> > > devm_drm_dev_alloc(), and rcdu was embedded in it.
> > >
> >
> > OK.
> >
> > > Now each instance needs its own structure at probe time (dev, info,
> > > mmio), before the DRM device is allocated with devm_drm_dev_alloc() in the master bind, so it is
> allocated with devm_kzalloc().
> > >
> >
> > That is ok.
> >
> > > The KMS objects (crtcs[], vsps[]) belong to the shared DRM device,
> > > so at bind time each instance allocates its own structure for them with drmm_kzalloc(), released
> with the DRM device.
> >
> > Why we need drmm_kzalloc() here? Can't we use pointer allocated with
> > devm_kzalloc() to avoid another copy?
> >
> > >
> > > Each instance copies its own dev, info and mmio into that structure,
> > > as they are used by the KMS code, e.g.
> > > rzg2l_du_crtc_set_display_timing()
> > > (mmio), rzg2l_du_encoders_init() (info) and rzg2l_du_crtc_create() (dev).
> >
> > Since each probe's DU allocates rcdu, can't we reuse same rcdu for
> > holding dev, info and mmio and pass the pointer to KMS code to reuse
> > mmio,info and dev in rzg2l_du_crtc_set_display_timing(),
> > rzg2l_du_encoders_init() and
> > rzg2l_du_crtc_create()
> >
> > Is the below code[1] does not work? Do you see any issues?
> >
> > [1]
> > static int rzg2l_du_instance_init(struct rzg2l_du_device *du,
> > struct drm_device *ddev)
> > {
> > du->ddev = ddev;
> >
> > du->index = ddev->mode_config.num_crtc;
> >
> > ret = rzg2l_du_modeset_init_du(du);
> > if (ret < 0)
> > return ret;
> >
> > if (WARN_ON(drm_crtc_index(&du->crtcs[0].crtc) != du ->index))
> > return -EINVAL;
> >
> > return 0;
> > }
>
> TO avoid the copy maybe we can do:
>
> static int rzg2l_du_instance_init(struct device *dev, struct drm_device *ddev) {
> struct rzg2l_du_device *rcdu;
> int ret;
>
> rcdu = drmm_kzalloc(ddev, sizeof(*rcdu), GFP_KERNEL);
> if (!rcdu)
> return -ENOMEM;
>
> rcdu->dev = dev;
> rcdu->info = of_device_get_match_data(dev);
> rcdu->ddev = ddev;
>
> rcdu->mmio = devm_platform_ioremap_resource(to_platform_device(dev), 0);
> if (IS_ERR(rcdu->mmio))
> return PTR_ERR(rcdu->mmio);
>
> rcdu->index = ddev->mode_config.num_crtc;
>
> ret = rzg2l_du_modeset_init_du(rcdu);
> if (ret < 0)
> return ret;
>
> if (WARN_ON(drm_crtc_index(&rcdu->crtcs[0].crtc) != rcdu->index))
> return -EINVAL;
>
> return 0;
> }
>
> In this way we can drop the devm_kzalloc() from the rzg2l_du_probe().
> Will be fine for you?
Much better.
Cheers,
Biju
next prev parent reply other threads:[~2026-11-25 13:49 UTC|newest]
Thread overview: 41+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-13 12:19 [PATCH v10 00/12] drm: renesas: rz-du: Add RZ/G3E support Tommaso Merciai
2026-11-13 12:19 ` [PATCH v10 01/12] dt-bindings: display: renesas,rzg2l-du: Add support for RZ/G3E SoC Tommaso Merciai
2026-11-13 12:19 ` [PATCH v10 02/12] drm: renesas: rz-du: vsp: Keep the planes in the VSP Tommaso Merciai
2026-11-18 14:09 ` Biju Das
2026-11-18 18:08 ` Tommaso Merciai
2026-11-13 12:19 ` [PATCH v10 03/12] drm: renesas: rz-du: Reference the DRM device by pointer Tommaso Merciai
2026-11-23 15:55 ` Biju Das
2026-11-13 12:20 ` [PATCH v10 04/12] drm: renesas: rz-du: Count all registered encoders for the possible clones Tommaso Merciai
2026-11-23 16:16 ` Biju Das
2026-11-13 12:20 ` [PATCH v10 05/12] drm: renesas: rz-du: Split the mode setting initialization Tommaso Merciai
2026-11-23 16:31 ` Biju Das
2026-11-13 12:20 ` [PATCH v10 06/12] drm: renesas: rz-du: Make the CRTC index relative to the DRM device Tommaso Merciai
2026-11-23 16:37 ` Biju Das
2026-11-13 12:20 ` [PATCH v10 07/12] drm: renesas: rz-du: Share the encoder of an output driven by several DUs Tommaso Merciai
2026-11-23 16:44 ` Biju Das
2026-11-13 12:20 ` [PATCH v10 08/12] drm: renesas: rz-du: Separate the DU instance from the DRM device Tommaso Merciai
2026-11-23 16:59 ` Biju Das
2026-11-24 9:20 ` Tommaso Merciai
2026-11-24 9:33 ` Biju Das
2026-11-24 11:59 ` Tommaso Merciai
2026-11-24 12:51 ` Biju Das
2026-11-24 15:24 ` Tommaso Merciai
2026-11-24 16:04 ` Biju Das
2026-11-24 18:49 ` Tommaso Merciai
2026-11-25 7:07 ` Biju Das
2026-11-25 13:47 ` Tommaso Merciai
2026-11-25 13:49 ` Biju Das [this message]
2026-11-13 12:20 ` [PATCH v10 09/12] drm: renesas: rz-du: Move the DRM device initialization to helpers Tommaso Merciai
2026-11-13 12:20 ` [PATCH v10 10/12] drm: renesas: rz-du: Support several DU instances in one DRM device Tommaso Merciai
2026-11-24 7:47 ` Biju Das
2026-11-24 11:53 ` Tommaso Merciai
2026-11-24 13:18 ` Biju Das
2026-11-24 13:59 ` Tommaso Merciai
2026-11-24 14:11 ` Biju Das
2026-11-24 14:52 ` Tommaso Merciai
2026-11-25 7:28 ` Biju Das
2026-11-25 13:36 ` Tommaso Merciai
2026-11-25 13:45 ` Biju Das
2026-11-25 14:13 ` Tommaso Merciai
2026-11-13 12:20 ` [PATCH v10 11/12] drm: renesas: rz-du: Add RZ/G3E (R9A09G047) DU support Tommaso Merciai
2026-11-13 12:20 ` [PATCH v10 12/12] arm64: dts: renesas: r9a09g047: Add DU{0,1} nodes Tommaso Merciai
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=OS3PR01MB6596FE927C038F264BE0C97186432@OS3PR01MB6596.jpnprd01.prod.outlook.com \
--to=biju.das.jz@bp.renesas.com \
--cc=airlied@gmail.com \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=dri-devel@lists.freedesktop.org \
--cc=geert+renesas@glider.be \
--cc=krzk+dt@kernel.org \
--cc=laurent.pinchart+renesas@ideasonboard.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-renesas-soc@vger.kernel.org \
--cc=maarten.lankhorst@linux.intel.com \
--cc=magnus.damm@gmail.com \
--cc=mripard@kernel.org \
--cc=prabhakar.mahadev-lad.rj@bp.renesas.com \
--cc=robh@kernel.org \
--cc=simona@ffwll.ch \
--cc=tomm.merciai@gmail.com \
--cc=tommaso.merciai.xr@bp.renesas.com \
--cc=tzimmermann@suse.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®