linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* AMDGPU and 16B stack alignment
@ 2019-10-14 22:22 Nick Desaulniers
       [not found] ` <9e4d6378-5032-8521-13a9-d9d9519d07de@amd.com>
  0 siblings, 1 reply; 11+ messages in thread
From: Nick Desaulniers @ 2019-10-14 22:22 UTC (permalink / raw)
  To: Harry Wentland, Deucher, Alexander
  Cc: yshuiv7, andrew.cooper3, Arnd Bergmann, clang-built-linux,
	Matthias Kaehlcke, S, Shirish, Zhou, David(ChunMing),
	Koenig, Christian, amd-gfx list, LKML

Hello!

The x86 kernel is compiled with an 8B stack alignment via
    `-mpreferred-stack-boundary=3` for GCC since 3.6-rc1 via
    commit d9b0cde91c60 ("x86-64, gcc: Use
-mpreferred-stack-boundary=3 if supported")
    or `-mstack-alignment=8` for Clang. Parts of the AMDGPU driver are
    compiled with 16B stack alignment.

    Generally, the stack alignment is part of the ABI. Linking together two
    different translation units with differing stack alignment is dangerous,
    particularly when the translation unit with the smaller stack alignment
    makes calls into the translation unit with the larger stack alignment.
    While 8B aligned stacks are sometimes also 16B aligned, they are not
    always.

    Multiple users have reported General Protection Faults (GPF) when using
    the AMDGPU driver compiled with Clang. Clang is placing objects in stack
    slots assuming the stack is 16B aligned, and selecting instructions that
    require 16B aligned memory operands. At runtime, syscalls handling 8B
    stack aligned code calls into code that assumes 16B stack alignment.
    When the stack is a multiple of 8B but not 16B, these instructions
    result in a GPF.

    GCC doesn't select instructions with alignment requirements, so the GPFs
    aren't observed, but it is still considered an ABI breakage to mix and
    match stack alignment.

I have patches that basically remove -mpreferred-stack-boundary=4 and
-mstack-alignment=16 from AMDGPU:
https://github.com/ClangBuiltLinux/linux/issues/735#issuecomment-541247601
Yuxuan has tested with Clang and GCC and reported it fixes the GPF's observed.

I've split the patch into 4; same commit message but different Fixes
tags so that they backport to stable on finer granularity. 2 questions
BEFORE I send the series:

1. Would you prefer 4 patches with unique `fixes` tags, or 1 patch?
2. Was there or is there still a good reason for the stack alignment mismatch?

(Further, I think we can use -msse2 for BOTH clang+gcc after my patch,
but I don't have hardware to test on. I'm happy to write/send the
follow up patch, but I'd need help testing).
-- 
Thanks,
~Nick Desaulniers

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2019-10-16 23:05 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-14 22:22 AMDGPU and 16B stack alignment Nick Desaulniers
     [not found] ` <9e4d6378-5032-8521-13a9-d9d9519d07de@amd.com>
2019-10-15  7:19   ` Arnd Bergmann
2019-10-15 10:48     ` David Laight
2019-10-15 18:05     ` Nick Desaulniers
2019-10-15 18:11       ` Nick Desaulniers
2019-10-15 18:30       ` Alex Deucher
2019-10-15 20:15         ` Nick Desaulniers
2019-10-15 20:26       ` Arvind Sankar
2019-10-16  1:51         ` Nick Desaulniers
2019-10-16 18:55           ` Arvind Sankar
2019-10-16 23:05             ` Nick Desaulniers

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).