[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <74ca7e8a61f051eadc895cf8b29e591cc3d0f548.camel@intel.com>
Date: Tue, 6 Oct 2020 17:45:24 +0000
From: "Bae, Chang Seok" <chang.seok.bae@...el.com>
To: "Dave.Martin@....com" <Dave.Martin@....com>
CC: "mingo@...nel.org" <mingo@...nel.org>,
"linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>,
"hjl.tools@...il.com" <hjl.tools@...il.com>,
"bp@...e.de" <bp@...e.de>,
"tglx@...utronix.de" <tglx@...utronix.de>,
"linux-api@...r.kernel.org" <linux-api@...r.kernel.org>,
"libc-alpha@...rceware.org" <libc-alpha@...rceware.org>,
"x86@...nel.org" <x86@...nel.org>,
"luto@...nel.org" <luto@...nel.org>,
"Shankar, Ravi V" <ravi.v.shankar@...el.com>,
"Hansen, Dave" <dave.hansen@...el.com>,
"Luck, Tony" <tony.luck@...el.com>,
"Brown, Len" <len.brown@...el.com>,
"linux-arch@...r.kernel.org" <linux-arch@...r.kernel.org>,
"mpe@...erman.id.au" <mpe@...erman.id.au>
Subject: Re: [RFC PATCH 1/4] x86/signal: Introduce helpers to get the maximum
signal frame size
On Mon, 2020-10-05 at 14:42 +0100, Dave Martin wrote:
> On Tue, Sep 29, 2020 at 01:57:43PM -0700, Chang S. Bae wrote:
> >
> > +/*
> > + * The FP state frame contains an XSAVE buffer which must be 64-byte aligned.
> > + * If a signal frame starts at an unaligned address, extra space is required.
> > + * This is the max alignment padding, conservatively.
> > + */
> > +#define MAX_XSAVE_PADDING 63UL
> > +
> > +/*
> > + * The frame data is composed of the following areas and laid out as:
> > + *
> > + * -------------------------
> > + * | alignment padding |
> > + * -------------------------
> > + * | (f)xsave frame |
> > + * -------------------------
> > + * | fsave header |
> > + * -------------------------
> > + * | siginfo + ucontext |
> > + * -------------------------
> > + */
> > +
> > +/* max_frame_size tells userspace the worst case signal stack size. */
> > +static unsigned long __ro_after_init max_frame_size;
> > +
> > +void __init init_sigframe_size(void)
> > +{
> > + /*
> > + * Use the largest of possible structure formats. This might
> > + * slightly oversize the frame for 64-bit apps.
> > + */
> > +
> > + if (IS_ENABLED(CONFIG_X86_32) ||
> > + IS_ENABLED(CONFIG_IA32_EMULATION))
> > + max_frame_size = max((unsigned long)SIZEOF_sigframe_ia32,
> > + (unsigned long)SIZEOF_rt_sigframe_ia32);
> > +
> > + if (IS_ENABLED(CONFIG_X86_X32_ABI))
> > + max_frame_size = max(max_frame_size, (unsigned long)SIZEOF_rt_sigframe_x32);
> > +
> > + if (IS_ENABLED(CONFIG_X86_64))
> > + max_frame_size = max(max_frame_size, (unsigned long)SIZEOF_rt_sigframe);
> > +
> > + max_frame_size += fpu__get_fpstate_sigframe_size() + MAX_XSAVE_PADDING;
>
> For arm64, we round the worst-case padding up by one.
>
Yeah, I saw that. The ARM code adds the max padding, too:
signal_minsigstksz = sigframe_size(&user) +
round_up(sizeof(struct frame_record), 16) +
16; /* max alignment padding */
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/arch/arm64/kernel/signal.c#n973
> I can't remember the full rationale for this, but it at least seemed a
> bit weird to report a size that is not a multiple of the alignment.
>
Because the last state size of XSAVE may not be 64B aligned, the (reported)
sum of xstate size here does not guarantee 64B alignment.
> I'm can't think of a clear argument as to why it really matters, though.
We care about the start of XSAVE buffer for the XSAVE instructions, to be
64B-aligned.
Thanks,
Chang
Powered by blists - more mailing lists