Page MenuHomeFreeBSD

Switch to 16-byte stack alignment on N32 and N64.
ClosedPublic

Authored by jhb on Jan 11 2018, 7:52 PM.
Tags
None
Referenced Files
Unknown Object (File)
Fri, Dec 20, 10:24 AM
Unknown Object (File)
Sat, Dec 7, 5:12 AM
Unknown Object (File)
Mon, Nov 25, 1:08 PM
Unknown Object (File)
Mon, Nov 25, 6:26 AM
Unknown Object (File)
Sat, Nov 23, 4:42 AM
Unknown Object (File)
Nov 22 2024, 2:27 PM
Unknown Object (File)
Nov 21 2024, 3:45 AM
Unknown Object (File)
Nov 18 2024, 10:42 PM
Subscribers

Details

Summary

Add a STACK_ALIGN constant rather than hardcoding sizeof(int64_t) when
aligning the stack during thread and process creation as well as when
constructing a signal frame.

Use a value of 16 for STACK_ALIGN on N32 and N64 and a value of 8 for
O32.

Test Plan
  • booted o32, n32, and n64 kernels under qemu

Diff Detail

Repository
rS FreeBSD src repository - subversion
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

Also fix alignment in cpu_set_upcall in vm_machdep.c?

Also, lib/libc/mips/gen/makecontext.c uses its own constants, and should likely be pulled out of the conditional, after subtracting enough registers' worth o' room.

  • Use STACK_ALIGN in cpu_set_upcall() as well.
  • Update comments in __makecontext().

I'm not quite sure what you would like to do for makecontext. It is already using the right value (16 for newabi), but I don't know if it's really safe to expose STACK_ALIGN to userland (perhaps I can include <machine/md_var.h> to get it in this file?) If the comment is really stale and there is no gap for newabi, then I don't think we can collapse the #ifdef's down any further in makecontext() aside from perhaps using STACK_ALIGN.

lib/libc/mips/gen/makecontext.c
108 ↗(On Diff #38022)

Hopefully this can be resolved during this review? Given the logic earlier for subtracting from 'sp' to make room, I think the code is correct and that the comment on line 106 should not talk about a gap but just say "pass remaining arguments on the stack".

Ping. Anyone have any thoughts on my last questions?

In D13875#292023, @jhb wrote:

I'm not quite sure what you would like to do for makecontext. It is already using the right value (16 for newabi), but I don't know if it's really safe to expose STACK_ALIGN to userland (perhaps I can include <machine/md_var.h> to get it in this file?)

I feel like the stack alignment ought to be derived from some shared definition for consistency, and used wherever needed. <machine/asm.h> has lots of similar/related things (which could perhaps be used instead? see ALMASK), but that's for assembly. I don't know if we have a consistent header for use in C (and perhaps also used in assembly.) I feel like a new header along the lines of <machine/abi.h> might be something we want to contain a bunch of things into.

I'm fine with this going in as is, but definitely feel like unification and consistency has benefits if we can do it right. Possibly in such a way as sets an example for adding new ABIs to other architectures, which I imagine you have some thoughts and insights into for, say, x32.

lib/libc/mips/gen/makecontext.c
108 ↗(On Diff #38022)

Yeah, I can't reason about the comment and think your interpretation is correct.

This revision is now accepted and ready to land.Jan 24 2018, 9:47 PM

I've done some more reading and I think I have a grip on the makecontext() stuff, but it's turned into a bigger ball of wax so I'm going to defer fixes there until later.

I did look at ALMASK since we also use CALLFRAME_SIZ in C. I don't like that ALMASK use '-' instead of '~' though. (And in fact, I can't find anything in the tree that uses ALSK or ALMASK currently). -8 and -16 would work though. That bug goes back to when these cosntants were added in NetBSD's asm.h. I feel like I'd rather just add the single STACK_ALIGN perhaps in machine/asm.h and drop the ALSK and ALMASK constants as they are named poorly.

I'd concur, and I had already pared down from NetBSD some in what's in that file when fixing various ABIs, IIRC, and I think it's reasonable to remove other things that are wrong or misleading.

  • Remove duplicate STACK_ALIGN and remove banal comment.
  • Add <machine/abi.h> and move some bits of <machine/asm.h> + STACK_ALIGN to it.
This revision now requires review to proceed.Jan 30 2018, 11:10 PM

Strong approve; this is a great improvement. Thank you!

This revision is now accepted and ready to land.Jan 31 2018, 12:23 AM
This revision was automatically updated to reflect the committed changes.