All of lore.kernel.org
 help / color / mirror / Atom feed
From: Kees Cook <keescook@chromium.org>
To: Jani Nikula <jani.nikula@linux.intel.com>
Cc: intel-gfx@lists.freedesktop.org,
	Alexander Potapenko <glider@google.com>,
	linux-kernel@vger.kernel.org
Subject: Re: [Intel-gfx] [PATCH] drm/i915: Distribute switch variables for initialization
Date: Thu, 20 Feb 2020 15:42:11 -0800	[thread overview]
Message-ID: <202002201541.1B5347ABAD@keescook> (raw)
In-Reply-To: <877e0hv9t1.fsf@intel.com>

On Thu, Feb 20, 2020 at 12:21:14PM +0200, Jani Nikula wrote:
> On Wed, 19 Feb 2020, Kees Cook <keescook@chromium.org> wrote:
> > Variables declared in a switch statement before any case statements
> > cannot be automatically initialized with compiler instrumentation (as
> > they are not part of any execution flow). With GCC's proposed automatic
> > stack variable initialization feature, this triggers a warning (and they
> > don't get initialized). Clang's automatic stack variable initialization
> > (via CONFIG_INIT_STACK_ALL=y) doesn't throw a warning, but it also
> > doesn't initialize such variables[1]. Note that these warnings (or silent
> > skipping) happen before the dead-store elimination optimization phase,
> > so even when the automatic initializations are later elided in favor of
> > direct initializations, the warnings remain.
> >
> > To avoid these problems, move such variables into the "case" where
> > they're used or lift them up into the main function body.
> >
> > drivers/gpu/drm/i915/display/intel_display.c: In function ‘check_digital_port_conflicts’:
> > drivers/gpu/drm/i915/display/intel_display.c:12963:17: warning: statement will never be executed [-Wswitch-unreachable]
> > 12963 |    unsigned int port_mask;
> >       |                 ^~~~~~~~~
> >
> > drivers/gpu/drm/i915/intel_pm.c: In function ‘vlv_get_fifo_size’:
> > drivers/gpu/drm/i915/intel_pm.c:474:7: warning: statement will never be executed [-Wswitch-unreachable]
> >   474 |   u32 dsparb, dsparb2, dsparb3;
> >       |       ^~~~~~
> > drivers/gpu/drm/i915/intel_pm.c: In function ‘vlv_atomic_update_fifo’:
> > drivers/gpu/drm/i915/intel_pm.c:1997:7: warning: statement will never be executed [-Wswitch-unreachable]
> >  1997 |   u32 dsparb, dsparb2, dsparb3;
> >       |       ^~~~~~
> >
> > [1] https://bugs.llvm.org/show_bug.cgi?id=44916
> >
> > Signed-off-by: Kees Cook <keescook@chromium.org>
> 
> Reviewed-by: Jani Nikula <jani.nikula@intel.com>

Thanks!

> 
> If you look at i915/Makefile, you'll see that we don't shy away from
> enabling lots of extra warnings, and we run our CI with -Werror to keep
> it clean. It does not seem like -Wswitch-unreachable does me any good,
> though... is it new?

It's already enabled by default, but the GCC feature that tweaks it
doesn't exist yet. But it points out a problem that exists for Clang
today, but Clang doesn't actually warn on (yet). So this is a fix to
avoid the silent Clang problem and fix future warnings before they
happen.

-Kees

> 
> BR,
> Jani.
> 
> 
> > ---
> >  drivers/gpu/drm/i915/display/intel_display.c |    6 ++++--
> >  drivers/gpu/drm/i915/intel_pm.c              |    4 ++--
> >  2 files changed, 6 insertions(+), 4 deletions(-)
> >
> > diff --git a/drivers/gpu/drm/i915/display/intel_display.c b/drivers/gpu/drm/i915/display/intel_display.c
> > index 064dd99bbc49..c829cd26f99e 100644
> > --- a/drivers/gpu/drm/i915/display/intel_display.c
> > +++ b/drivers/gpu/drm/i915/display/intel_display.c
> > @@ -12960,14 +12960,15 @@ static bool check_digital_port_conflicts(struct intel_atomic_state *state)
> >  		WARN_ON(!connector_state->crtc);
> >  
> >  		switch (encoder->type) {
> > -			unsigned int port_mask;
> >  		case INTEL_OUTPUT_DDI:
> >  			if (WARN_ON(!HAS_DDI(to_i915(dev))))
> >  				break;
> >  			/* else, fall through */
> >  		case INTEL_OUTPUT_DP:
> >  		case INTEL_OUTPUT_HDMI:
> > -		case INTEL_OUTPUT_EDP:
> > +		case INTEL_OUTPUT_EDP: {
> > +			unsigned int port_mask;
> > +
> >  			port_mask = 1 << encoder->port;
> >  
> >  			/* the same port mustn't appear more than once */
> > @@ -12976,6 +12977,7 @@ static bool check_digital_port_conflicts(struct intel_atomic_state *state)
> >  
> >  			used_ports |= port_mask;
> >  			break;
> > +		}
> >  		case INTEL_OUTPUT_DP_MST:
> >  			used_mst_ports |=
> >  				1 << encoder->port;
> > diff --git a/drivers/gpu/drm/i915/intel_pm.c b/drivers/gpu/drm/i915/intel_pm.c
> > index bd2d30ecc030..17d8833787c4 100644
> > --- a/drivers/gpu/drm/i915/intel_pm.c
> > +++ b/drivers/gpu/drm/i915/intel_pm.c
> > @@ -469,9 +469,9 @@ static void vlv_get_fifo_size(struct intel_crtc_state *crtc_state)
> >  	struct vlv_fifo_state *fifo_state = &crtc_state->wm.vlv.fifo_state;
> >  	enum pipe pipe = crtc->pipe;
> >  	int sprite0_start, sprite1_start;
> > +	u32 dsparb, dsparb2, dsparb3;
> >  
> >  	switch (pipe) {
> > -		u32 dsparb, dsparb2, dsparb3;
> >  	case PIPE_A:
> >  		dsparb = I915_READ(DSPARB);
> >  		dsparb2 = I915_READ(DSPARB2);
> > @@ -1969,6 +1969,7 @@ static void vlv_atomic_update_fifo(struct intel_atomic_state *state,
> >  	const struct vlv_fifo_state *fifo_state =
> >  		&crtc_state->wm.vlv.fifo_state;
> >  	int sprite0_start, sprite1_start, fifo_size;
> > +	u32 dsparb, dsparb2, dsparb3;
> >  
> >  	if (!crtc_state->fifo_changed)
> >  		return;
> > @@ -1994,7 +1995,6 @@ static void vlv_atomic_update_fifo(struct intel_atomic_state *state,
> >  	spin_lock(&uncore->lock);
> >  
> >  	switch (crtc->pipe) {
> > -		u32 dsparb, dsparb2, dsparb3;
> >  	case PIPE_A:
> >  		dsparb = intel_uncore_read_fw(uncore, DSPARB);
> >  		dsparb2 = intel_uncore_read_fw(uncore, DSPARB2);
> >
> 
> -- 
> Jani Nikula, Intel Open Source Graphics Center

-- 
Kees Cook
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

WARNING: multiple messages have this Message-ID (diff)
From: Kees Cook <keescook@chromium.org>
To: Jani Nikula <jani.nikula@linux.intel.com>
Cc: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>,
	Rodrigo Vivi <rodrigo.vivi@intel.com>,
	Alexander Potapenko <glider@google.com>,
	intel-gfx@lists.freedesktop.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] drm/i915: Distribute switch variables for initialization
Date: Thu, 20 Feb 2020 15:42:11 -0800	[thread overview]
Message-ID: <202002201541.1B5347ABAD@keescook> (raw)
In-Reply-To: <877e0hv9t1.fsf@intel.com>

On Thu, Feb 20, 2020 at 12:21:14PM +0200, Jani Nikula wrote:
> On Wed, 19 Feb 2020, Kees Cook <keescook@chromium.org> wrote:
> > Variables declared in a switch statement before any case statements
> > cannot be automatically initialized with compiler instrumentation (as
> > they are not part of any execution flow). With GCC's proposed automatic
> > stack variable initialization feature, this triggers a warning (and they
> > don't get initialized). Clang's automatic stack variable initialization
> > (via CONFIG_INIT_STACK_ALL=y) doesn't throw a warning, but it also
> > doesn't initialize such variables[1]. Note that these warnings (or silent
> > skipping) happen before the dead-store elimination optimization phase,
> > so even when the automatic initializations are later elided in favor of
> > direct initializations, the warnings remain.
> >
> > To avoid these problems, move such variables into the "case" where
> > they're used or lift them up into the main function body.
> >
> > drivers/gpu/drm/i915/display/intel_display.c: In function ‘check_digital_port_conflicts’:
> > drivers/gpu/drm/i915/display/intel_display.c:12963:17: warning: statement will never be executed [-Wswitch-unreachable]
> > 12963 |    unsigned int port_mask;
> >       |                 ^~~~~~~~~
> >
> > drivers/gpu/drm/i915/intel_pm.c: In function ‘vlv_get_fifo_size’:
> > drivers/gpu/drm/i915/intel_pm.c:474:7: warning: statement will never be executed [-Wswitch-unreachable]
> >   474 |   u32 dsparb, dsparb2, dsparb3;
> >       |       ^~~~~~
> > drivers/gpu/drm/i915/intel_pm.c: In function ‘vlv_atomic_update_fifo’:
> > drivers/gpu/drm/i915/intel_pm.c:1997:7: warning: statement will never be executed [-Wswitch-unreachable]
> >  1997 |   u32 dsparb, dsparb2, dsparb3;
> >       |       ^~~~~~
> >
> > [1] https://bugs.llvm.org/show_bug.cgi?id=44916
> >
> > Signed-off-by: Kees Cook <keescook@chromium.org>
> 
> Reviewed-by: Jani Nikula <jani.nikula@intel.com>

Thanks!

> 
> If you look at i915/Makefile, you'll see that we don't shy away from
> enabling lots of extra warnings, and we run our CI with -Werror to keep
> it clean. It does not seem like -Wswitch-unreachable does me any good,
> though... is it new?

It's already enabled by default, but the GCC feature that tweaks it
doesn't exist yet. But it points out a problem that exists for Clang
today, but Clang doesn't actually warn on (yet). So this is a fix to
avoid the silent Clang problem and fix future warnings before they
happen.

-Kees

> 
> BR,
> Jani.
> 
> 
> > ---
> >  drivers/gpu/drm/i915/display/intel_display.c |    6 ++++--
> >  drivers/gpu/drm/i915/intel_pm.c              |    4 ++--
> >  2 files changed, 6 insertions(+), 4 deletions(-)
> >
> > diff --git a/drivers/gpu/drm/i915/display/intel_display.c b/drivers/gpu/drm/i915/display/intel_display.c
> > index 064dd99bbc49..c829cd26f99e 100644
> > --- a/drivers/gpu/drm/i915/display/intel_display.c
> > +++ b/drivers/gpu/drm/i915/display/intel_display.c
> > @@ -12960,14 +12960,15 @@ static bool check_digital_port_conflicts(struct intel_atomic_state *state)
> >  		WARN_ON(!connector_state->crtc);
> >  
> >  		switch (encoder->type) {
> > -			unsigned int port_mask;
> >  		case INTEL_OUTPUT_DDI:
> >  			if (WARN_ON(!HAS_DDI(to_i915(dev))))
> >  				break;
> >  			/* else, fall through */
> >  		case INTEL_OUTPUT_DP:
> >  		case INTEL_OUTPUT_HDMI:
> > -		case INTEL_OUTPUT_EDP:
> > +		case INTEL_OUTPUT_EDP: {
> > +			unsigned int port_mask;
> > +
> >  			port_mask = 1 << encoder->port;
> >  
> >  			/* the same port mustn't appear more than once */
> > @@ -12976,6 +12977,7 @@ static bool check_digital_port_conflicts(struct intel_atomic_state *state)
> >  
> >  			used_ports |= port_mask;
> >  			break;
> > +		}
> >  		case INTEL_OUTPUT_DP_MST:
> >  			used_mst_ports |=
> >  				1 << encoder->port;
> > diff --git a/drivers/gpu/drm/i915/intel_pm.c b/drivers/gpu/drm/i915/intel_pm.c
> > index bd2d30ecc030..17d8833787c4 100644
> > --- a/drivers/gpu/drm/i915/intel_pm.c
> > +++ b/drivers/gpu/drm/i915/intel_pm.c
> > @@ -469,9 +469,9 @@ static void vlv_get_fifo_size(struct intel_crtc_state *crtc_state)
> >  	struct vlv_fifo_state *fifo_state = &crtc_state->wm.vlv.fifo_state;
> >  	enum pipe pipe = crtc->pipe;
> >  	int sprite0_start, sprite1_start;
> > +	u32 dsparb, dsparb2, dsparb3;
> >  
> >  	switch (pipe) {
> > -		u32 dsparb, dsparb2, dsparb3;
> >  	case PIPE_A:
> >  		dsparb = I915_READ(DSPARB);
> >  		dsparb2 = I915_READ(DSPARB2);
> > @@ -1969,6 +1969,7 @@ static void vlv_atomic_update_fifo(struct intel_atomic_state *state,
> >  	const struct vlv_fifo_state *fifo_state =
> >  		&crtc_state->wm.vlv.fifo_state;
> >  	int sprite0_start, sprite1_start, fifo_size;
> > +	u32 dsparb, dsparb2, dsparb3;
> >  
> >  	if (!crtc_state->fifo_changed)
> >  		return;
> > @@ -1994,7 +1995,6 @@ static void vlv_atomic_update_fifo(struct intel_atomic_state *state,
> >  	spin_lock(&uncore->lock);
> >  
> >  	switch (crtc->pipe) {
> > -		u32 dsparb, dsparb2, dsparb3;
> >  	case PIPE_A:
> >  		dsparb = intel_uncore_read_fw(uncore, DSPARB);
> >  		dsparb2 = intel_uncore_read_fw(uncore, DSPARB2);
> >
> 
> -- 
> Jani Nikula, Intel Open Source Graphics Center

-- 
Kees Cook

  reply	other threads:[~2020-02-20 23:42 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-20  6:22 [Intel-gfx] [PATCH] drm/i915: Distribute switch variables for initialization Kees Cook
2020-02-20  6:22 ` Kees Cook
2020-02-20  7:02 ` [Intel-gfx] ✓ Fi.CI.BAT: success for " Patchwork
2020-02-20 10:21 ` [Intel-gfx] [PATCH] " Jani Nikula
2020-02-20 10:21   ` Jani Nikula
2020-02-20 23:42   ` Kees Cook [this message]
2020-02-20 23:42     ` Kees Cook
2020-02-20 13:47 ` [Intel-gfx] " Ville Syrjälä
2020-02-20 13:47   ` Ville Syrjälä

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=202002201541.1B5347ABAD@keescook \
    --to=keescook@chromium.org \
    --cc=glider@google.com \
    --cc=intel-gfx@lists.freedesktop.org \
    --cc=jani.nikula@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.