From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on gnuweeb.org X-Spam-Level: ** X-Spam-Status: No, score=2.5 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SORTED_RECIPS,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=3.4.6 Authentication-Results: gnuweeb.org; dmarc=none (p=none dis=none) header.from=tinylab.org Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=43.155.67.158; helo=bg4.exmail.qq.com; envelope-from=falcon@tinylab.org; receiver= Received: from bg4.exmail.qq.com (bg4.exmail.qq.com [43.155.67.158]) by gnuweeb.org (Postfix) with ESMTPS id AE5F224B175 for ; Sat, 26 Aug 2023 23:37:14 +0700 (WIB) X-QQ-mid: bizesmtp70t1693067817txikufn0 Received: from linux-lab-host.localdomain ( [116.30.128.222]) by bizesmtp.qq.com (ESMTP) with id ; Sun, 27 Aug 2023 00:36:47 +0800 (CST) X-QQ-SSF: 00200000000000E0Y000000A0000000 X-QQ-FEAT: WP/PdQRFMYsz/mSHuYOc6yi0FsMCGeBxAKUoOgqZy23x0rBGJvn2x/KL90lrP bE7bw+BW+HcwR0Wx9fBAxXVJ6ODEsOef9drEx0WZRrMsllZTqPDJaJtb7NhbvfZS9qq8rZv AbBFW9iwhhklLPXquXvk7JbzunYsacKSTELJbuageFmXtCmGjgH4qwCiPwqSNL2s/s7F1JK Fb8DYEHrZc6IkhJ4/mNvkyGj0KRd1ZlFr4e04Y7vy+VVmzAg449AZOoFfLlY2eouEJomg1E +dLAaO3/fcAUsTmaDchwMd8j3RjUdsYPLF65FkAYn6vhjQ2q/YEUGijIG9UuGQq1hW+ITt/ fsHkIr0gfGTlGq8wTnkMOIxYWhp9g== X-QQ-GoodBg: 0 X-BIZMAIL-ID: 9061740249613107006 From: Zhangjin Wu To: ammarfaizi2@gnuweeb.org Cc: falcon@tinylab.org, gwml@vger.gnuweeb.org, inori@vnlx.org, linux-kernel@vger.kernel.org, linux@weissschuh.net, moe@gnuweeb.org, w@1wt.eu Subject: Re: [PATCH v1 0/1] Fix a stack misalign bug on _start Date: Sun, 27 Aug 2023 00:36:47 +0800 Message-Id: <20230826163647.8178-1-falcon@tinylab.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:tinylab.org:qybglogicsvrgz:qybglogicsvrgz5a-1 List-Id: Hi, Ammar > On Sat, Aug 26, 2023 at 11:20:24PM +0800, Zhangjin Wu wrote: > > > $eax : 0x56559000 → 0x00003f90 > > > $ebx : 0x56559000 → 0x00003f90 > > > $ecx : 0x1 > > > $edx : 0xf7fcaaa0 → endbr32 > > > $esp : 0xffffcdbc → 0x00000001 > > > $ebp : 0x0 > > > $esi : 0xffffce7c → 0xffffd096 > > > $edi : 0x56556060 → <_start+0> xor %ebp, %ebp > > > $eip : 0x56556489 → movaps %xmm0, 0x30(%esp) > > > > > > pop %eax > > > add $0x2b85, %eax > > > movups -0x1fd0(%eax), %xmm0 > > > → movaps %xmm0, 0x30(%esp) <== trapping instruction > > > movups -0x1fe0(%eax), %xmm1 > > > movaps %xmm1, 0x20(%esp) > > > movups -0x1ff0(%eax), %xmm2 > > > movaps %xmm2, 0x10(%esp) > > > movups -0x2000(%eax), %xmm3 > > > > > > [#0] Id 1, Name: "test", stopped 0x56556489 in sse_pq_add (), reason: SIGSEGV > > > > > > (gdb) bt > > > #0 0x56556489 in sse_pq_add () > > > #1 0x5655608e in main () > > > > > > > Since we have a new 'startup' test group, do you have a short function > > to trigger this error? > > Here is a simple program to test the stack alignment. > > #include "tools/include/nolibc/nolibc.h" > > __asm__ ( > "main:\n" > /* > * When the call main is executed, the > * %esp is 16 bytes aligned. > * > * Then, on function entry (%esp mod 16) == 12 > * because the call instruction pushes 4 bytes > * onto the stack. > * > * subl $12, %esp will make (%esp mod 16) == 0 > * again. > */ > "subl $12, %esp\n" > > /* > * These move instructions will crash if %esp is > * not a multiple of 16. > */ > "movdqa (%esp), %xmm0\n" > "movdqa %xmm0, (%esp)\n" > "movaps (%esp), %xmm0\n" > "movaps %xmm0, (%esp)\n" > > "addl $12, %esp\n" > "xorl %eax, %eax\n" > "ret\n" > ); > Thanks very much for sharing this code. > > Perhaps it is time for us to add a new 'stack alignment' test case for > > all of the architectures. > > I don't know the alignment rules for other architectures (I only work on > x86 and x86-64). While waiting for the maintainers' comment, I'll leave > the test case decision to you. Feel free to take the above code. > Yes, the stack alignment rule is architecture dependent, so, we need more discussion and more work, not sure if there is a 'C' test function for all, let's delay this after v6.6. > Extra: > It's also fine if you take my patch with the 'sub $(16 - 4), %esp' > change and batch it together in your next series. > Ammar, your fixup patch is urgent since our _start_c() is for v6.6-rc1 (already in linux-next), let's wait for comments from Thomas or Willy, they will determine that merge it directly or require a v2. I'm ok with v1 code, but the old comment looks not that clear. Thanks, Zhangjin > -- > Ammar Faizi