mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Bert Karwatzki <spasswolf@web.de>
To: "mikhail.v.gavrilov@gmail.com" <mikhail.v.gavrilov@gmail.com>,
	 linux-kernel@vger.kernel.org
Cc: linux-next@vger.kernel.org, linux-rt-devel@lists.linux.dev,
	 amd-gfx@lists.freedesktop.org,
	"# = v7 . 1" <stable@vger.kernel.org>,
	Alex Deucher <alexander.deucher@amd.com>,
	Rafal Ostrowski <rafal.ostrowski@amd.com>,
	Mario Limonciello	 <mario.limonciello@amd.com>,
	Sebastian Andrzej Siewior <bigeasy@linutronix.de>,
	 Thomas Gleixner <tglx@linutronix.de>,
	spasswolf@web.de
Subject: Re: [PATCH] drm/amd/display: fix usage of DC_FPU_{BEGIN,END} with PREEMPT_RT
Date: Wed, 29 Jul 2026 14:35:34 +0200	[thread overview]
Message-ID: <1ead313022bc62dce1f42af9f855727eb9074443.camel@web.de> (raw)
In-Reply-To: <ef1bc3d070c4156f1811c0c4a567ec98ac8fadaf.camel@gmail.com>

Am Dienstag, dem 28.07.2026 um 05:51 +0500 schrieb mikhail.v.gavrilov@gmail.com:
> On Mon, 2026-07-27 at 12:50 +0200, Bert Karwatzki wrote:
> > On PREEMPT_RT kernels kvzalloc_obj() can sleep because spin_lock is
> > converted to rt_mutex. dc_create_plane_state() can be called while
> > inside an FPU-guarded region, resuling in "scheduling while atomic"
> > errors on PREEMPT_RT kernels.
> >  Fix this by calling kvzalloc_obj() with
> > DC_RUN_WITH_PREEMPTION_ENABLED().
> > Also fix the error path in dc_create_stream_for_sink().
> > 
> > Fixes: 3539437f354b ("drm/amd/display: Move FPU Guards From DML To DC
> > - Part 1")
> > Link:
> > https://lore.kernel.org/lkml/20260723123449.6494-1-spasswolf@web.de/
> > 
> > Signed-off-by: Bert Karwatzki <spasswolf@web.de>
> > ---
> >  drivers/gpu/drm/amd/display/dc/core/dc_stream.c  | 5 +++--
> >  drivers/gpu/drm/amd/display/dc/core/dc_surface.c | 4 ++--
> >  2 files changed, 5 insertions(+), 4 deletions(-)
> > 
> > diff --git a/drivers/gpu/drm/amd/display/dc/core/dc_stream.c
> > b/drivers/gpu/drm/amd/display/dc/core/dc_stream.c
> > index dbc12640b01c..4ac835777b58 100644
> > --- a/drivers/gpu/drm/amd/display/dc/core/dc_stream.c
> > +++ b/drivers/gpu/drm/amd/display/dc/core/dc_stream.c
> > @@ -233,8 +233,9 @@ struct dc_stream_state
> > *dc_create_stream_for_sink(
> >  
> >  fail:
> >  	if (stream) {
> > -		kfree(stream->update_scratch);
> > -		kfree(stream);
> > +		if (stream->update_scratch)
> > +			DC_RUN_WITH_PREEMPTION_ENABLED(kfree(stream-
> > > update_scratch));
> > +		DC_RUN_WITH_PREEMPTION_ENABLED(kfree(stream));
> >  	}
> >  
> >  	return NULL;
> > diff --git a/drivers/gpu/drm/amd/display/dc/core/dc_surface.c
> > b/drivers/gpu/drm/amd/display/dc/core/dc_surface.c
> > index 88e825a6582c..d5c6427796b6 100644
> > --- a/drivers/gpu/drm/amd/display/dc/core/dc_surface.c
> > +++ b/drivers/gpu/drm/amd/display/dc/core/dc_surface.c
> > @@ -85,8 +85,8 @@ uint8_t  dc_plane_get_pipe_mask(struct dc_state
> > *dc_state, const struct dc_plane
> >  
> > *********************************************************************
> > *********/
> >  struct dc_plane_state *dc_create_plane_state(const struct dc *dc)
> >  {
> > -	struct dc_plane_state *plane_state =
> > kvzalloc_obj(*plane_state,
> > -							 
> > GFP_ATOMIC);
> > +	struct dc_plane_state *plane_state;
> > +	DC_RUN_WITH_PREEMPTION_ENABLED(plane_state =
> > kvzalloc_obj(*plane_state, GFP_ATOMIC));
> >  
> >  	if (NULL == plane_state)
> >  		return NULL;
> 
> Hi Bert,
> 
> You may not be aware that the same allocation is already wrapped once,
> at the dcn32 call site:
> 
>   183182235f6d ("drm/amd/display: Wrap DCN32 phantom-plane allocation
> in DC_RUN_WITH_PREEMPTION_ENABLED")
> 
> That one only covers the dcn32 DML1 path, while your trace goes through
> dcn401_validate_bandwidth() and dml21 - so wrapping the call site could
> never have caught your case.  Which is a good argument for guarding the
> allocation in the callee, as you do: dc_create_plane_state() is reached
> from every DCN and both DML generations.

I did try a different approach, using DC_RUN_WITH_PREEMPTION_ENABLED further
upward in the calltrace (This would have the slight benefit of more code
running with preemption enabled). This does not work because dml21_utils.c is compiled
as a _LINUX_FPU_COMPILATION_UNIT, so DC_RUN_WITH_PREEMPTION_ENABLED does nothing.
(see drivers/gpu/drm/amd/display/amdgpu_dm/dc_fpu.h)

diff --git a/drivers/gpu/drm/amd/display/dc/dml2_0/dml21/dml21_utils.c b/drivers/gpu/drm/amd/display/dc/dml2_0/dml21/dml21_utils.c
index 835fece1d46a..8c92deded8cd 100644
--- a/drivers/gpu/drm/amd/display/dc/dml2_0/dml21/dml21_utils.c
+++ b/drivers/gpu/drm/amd/display/dc/dml2_0/dml21/dml21_utils.c
@@ -286,7 +286,8 @@ static struct dc_plane_state *dml21_add_phantom_plane(struct dml2_context *dml_c
        (void)plane_programming;
        struct dc_plane_state *phantom_plane;
 
-       phantom_plane = dml_ctx->config.svp_pstate.callbacks.create_phantom_plane(dc, context, main_plane);
+       DC_RUN_WITH_PREEMPTION_ENABLED(phantom_plane
+                       = dml_ctx->config.svp_pstate.callbacks.create_phantom_plane(dc, context, main_plane));
        if (!phantom_plane)
                return NULL;
 
diff --git a/drivers/gpu/drm/amd/display/dc/dml2_0/dml2_mall_phantom.c b/drivers/gpu/drm/amd/display/dc/dml2_0/dml2_mall_phantom.c
index 4543a60a0683..464bab9fc13b 100644
--- a/drivers/gpu/drm/amd/display/dc/dml2_0/dml2_mall_phantom.c
+++ b/drivers/gpu/drm/amd/display/dc/dml2_0/dml2_mall_phantom.c
@@ -769,10 +769,11 @@ static void enable_phantom_plane(struct dml2_context *ctx,
                if (curr_pipe->top_pipe && curr_pipe->top_pipe->plane_state == curr_pipe->plane_state) {
                        phantom_plane = prev_phantom_plane;
                } else {
-                       phantom_plane = ctx->config.svp_pstate.callbacks.create_phantom_plane(
+                       DC_RUN_WITH_PREEMPTION_ENABLED(phantom_plane =
+                                       ctx->config.svp_pstate.callbacks.create_phantom_plane(
                                        ctx->config.svp_pstate.callbacks.dc,
                                        state,
-                                       curr_pipe->plane_state);
+                                       curr_pipe->plane_state));
                        if (!phantom_plane)
                                return;
                }




Bert Karwatzki

  reply	other threads:[~2026-07-29 12:36 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-23 12:34 kernel panic during shutdown in v7.2-rc4 and next-20260722 " Bert Karwatzki
2026-07-23 12:43 ` [Re] " Bert Karwatzki
2026-07-23 13:10   ` [Re] kernel panic during shutdown in v7.2-rc{3,4} " Bert Karwatzki
2026-07-23 13:23     ` Bert Karwatzki
2026-07-23 16:17       ` Bert Karwatzki
2026-07-23 22:51         ` [Re] kernel panic during shutdown in next-20260722 Bert Karwatzki
2026-07-24 15:08           ` Bert Karwatzki
2026-07-25 19:58             ` Bert Karwatzki
2026-07-25 23:16               ` Bert Karwatzki
2026-07-26 18:47                 ` Bert Karwatzki
2026-07-26 22:52                   ` Bert Karwatzki
2026-07-27 10:06                     ` [Re] kernel panic during shutdown in v7.1+ with PREEMPT_RT Bert Karwatzki
2026-07-27 10:35                       ` Ostrowski, Rafal
2026-07-27 10:50                         ` [PATCH] drm/amd/display: fix usage of DC_FPU_{BEGIN,END} " Bert Karwatzki
2026-07-27 11:11                           ` sashiko-bot
2026-07-28  0:51                           ` mikhail.v.gavrilov
2026-07-29 12:35                             ` Bert Karwatzki [this message]
2026-07-29 14:39                               ` Mikhail Gavrilov
2026-07-29 17:46                                 ` Bert Karwatzki
2026-08-01  7:17                                   ` Bert Karwatzki
2026-08-01  7:35                                     ` sashiko-bot
2026-08-01 10:17                                     ` Mikhail Gavrilov
2026-08-07 12:58                                       ` Bert Karwatzki
2026-08-07 13:31                                         ` sashiko-bot
2026-08-06  3:47                                     ` kernel test robot
2026-08-06  4:29                                     ` kernel test robot
2026-08-07 12:49                                       ` [PATCH v7.2-rc6] " Bert Karwatzki
2026-08-07 13:13                                         ` sashiko-bot
2026-08-07 14:00                                         ` Greg KH
2026-08-27 12:49                                         ` Sebastian Andrzej Siewior
2026-08-27 21:07                                           ` Bert Karwatzki
2026-08-28  9:55                                             ` Sebastian Andrzej Siewior
2026-09-01 14:01                                               ` Bert Karwatzki

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=1ead313022bc62dce1f42af9f855727eb9074443.camel@web.de \
    --to=spasswolf@web.de \
    --cc=alexander.deucher@amd.com \
    --cc=amd-gfx@lists.freedesktop.org \
    --cc=bigeasy@linutronix.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-next@vger.kernel.org \
    --cc=linux-rt-devel@lists.linux.dev \
    --cc=mario.limonciello@amd.com \
    --cc=mikhail.v.gavrilov@gmail.com \
    --cc=rafal.ostrowski@amd.com \
    --cc=stable@vger.kernel.org \
    --cc=tglx@linutronix.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®