Intel-XE Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Nathan Chancellor <nathan@kernel.org>
To: Lucas De Marchi <lucas.demarchi@intel.com>
Cc: intel-xe@lists.freedesktop.org,
	Michal Wajdeczko <michal.wajdeczko@intel.com>,
	llvm@lists.linux.dev
Subject: Re: [PATCH] drm/xe: Fix warning on unreachable statement
Date: Sun, 21 Jul 2024 12:25:34 -0700	[thread overview]
Message-ID: <20240721192534.GA3459346@thelio-3990X> (raw)
In-Reply-To: <20240719191534.3845469-1-lucas.demarchi@intel.com>

Hi Lucas,

On Fri, Jul 19, 2024 at 12:15:34PM -0700, Lucas De Marchi wrote:
> eu_type_to_str() relies on -Wswitch to warn (and -Werror) to make sure
> it handles all enum values. However it's perfectly legal to pass an int
> to that function so in the end that function may happen to return
> nothing. A smart compiler could notice eu_type is never assigned to
> anything other than those values.

Well that assignment happens in load_eu_mask(), which is obviously
called before xe_gt_topology_dump() in xe_gt_topology_init(), but I
don't see how the compiler could assume that eu_type is always one of
those two values when xe_gt_topology_dump() is not static and could be
called from anywhere (i.e., when eu_type is potentially some other
value)? I might be missing something though.

> Trying to reproduce this issue, none of gcc-9, gcc-10 and gcc-13
> triggered for me, but this was reported in a different system with
> gcc-10:
> 
> 	drivers/gpu/drm/xe/xe.o: warning: objtool: xe_gt_topology_dump() falls through to next function xe_gt_topology_init()

I have been seeing similar warnings with clang as well, such as:

  drivers/gpu/drm/xe/xe.o: warning: objtool: xe_gt_topology_dump+0x77: sibling call from callable instruction with modified stack frame

  drivers/gpu/drm/xe/xe.o: warning: objtool: xe_gt_topology_dump() falls through to next function xe_dss_mask_group_ffs()

  drivers/gpu/drm/xe/xe.o: warning: objtool: xe_gt_topology_dump+0x77: can't find jump dest instruction at .text.xe_gt_topology_dump+0xc0

The final warning happens when LTO and CFI are enabled and I see a CFI
failure that appears to be a result of that.

[  +0.008116] Missing ENDBR: __cfi_init_module+0x0/0x10 [xe]
[  +0.000226] ------------[ cut here ]------------
[  +0.000001] kernel BUG at arch/x86/kernel/cet.c:102!
[  +0.000014] Oops: invalid opcode: 0000 [#1] PREEMPT SMP NOPTI
[  +0.000004] CPU: 3 PID: 335 Comm: (udev-worker) Not tainted 6.10.0-rc3-debug-01858-g7108b4a589cd #1 6163aa9290b9c012af9bc3cd405d04758721ac11
[  +0.000005] Hardware name: AZW MINI S/MINI S, BIOS ADLNV105 12/12/2023
...
[  +0.000002]  ? __cfi_init_module+0x10/0x10 [xe 257ff34a29c86b7d55c1c838833ff13eec5c3393]
[  +0.000167]  ? xe_hw_fence_module_init+0x40/0x40 [xe 257ff34a29c86b7d55c1c838833ff13eec5c3393]
[  +0.000171]  ? __cfi_init_module+0x10/0x10 [xe 257ff34a29c86b7d55c1c838833ff13eec5c3393]
[  +0.000174]  ? do_one_initcall+0x147/0x350

> Since that is not really possible, just take the simple approach and
> return NULL.

Indeed, bare unreachable() is generally considered harmful and can introduce
undefined behavior. Commits

  d652d5f1eeeb ("drm/edid: fix objtool warning in drm_cvt_modes()")

and

  3764647b255a ("bcachefs: Remove undefined behavior in bch2_dev_buckets_reserved()")

come to mind as instances like this.

> Cc: Michal Wajdeczko <michal.wajdeczko@intel.com>
> Signed-off-by: Lucas De Marchi <lucas.demarchi@intel.com>

This change resolves all the issues I have noted above, so thank you!

Reviewed-by: Nathan Chancellor <nathan@kernel.org>
Tested-by: Nathan Chancellor <nathan@kernel.org>

> ---
>  drivers/gpu/drm/xe/xe_gt_topology.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/gpu/drm/xe/xe_gt_topology.c b/drivers/gpu/drm/xe/xe_gt_topology.c
> index 5a1559edf3e9..0662f71c6ede 100644
> --- a/drivers/gpu/drm/xe/xe_gt_topology.c
> +++ b/drivers/gpu/drm/xe/xe_gt_topology.c
> @@ -233,7 +233,7 @@ static const char *eu_type_to_str(enum xe_gt_eu_type eu_type)
>  		return "simd8";
>  	}
>  
> -	unreachable();
> +	return NULL;
>  }
>  
>  void
> -- 
> 2.43.0
> 

  parent reply	other threads:[~2024-07-21 19:25 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-19 19:15 [PATCH] drm/xe: Fix warning on unreachable statement Lucas De Marchi
2024-07-19 19:20 ` ✓ CI.Patch_applied: success for " Patchwork
2024-07-19 19:20 ` ✓ CI.checkpatch: " Patchwork
2024-07-19 19:21 ` ✗ CI.KUnit: failure " Patchwork
2024-07-19 19:59 ` [PATCH] " Matthew Brost
2024-07-19 20:38   ` Lucas De Marchi
2024-07-19 21:59 ` Michal Wajdeczko
2024-07-21 19:25 ` Nathan Chancellor [this message]
2024-07-22 16:39   ` Lucas De Marchi

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=20240721192534.GA3459346@thelio-3990X \
    --to=nathan@kernel.org \
    --cc=intel-xe@lists.freedesktop.org \
    --cc=llvm@lists.linux.dev \
    --cc=lucas.demarchi@intel.com \
    --cc=michal.wajdeczko@intel.com \
    /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