[RFC patch 2/5] RISC-V: Reserve about 5K space in mcontext_t to support future ISA expansion.
Vincent Chen
vincent.chen@sifive.com
Sat Sep 18 03:04:18 GMT 2021
On Thu, Sep 16, 2021 at 4:14 PM Florian Weimer <fweimer@redhat.com> wrote:
>
> * Vincent Chen:
>
> >> > This changes the size of struct ucontext_t, which is an ABI break
> >> > (getcontext callers are supposed to provide their own object).
> >> >
> >
> > The riscv vector registers are all caller-saved registers except for
> > VCSR. Therefore, the struct mcontext_t needs to reserve a space for
> > it. In addition, RISCV ISA is growing, so I also hope the struct
> > mcontext_t has a space for future expansion. Based on the above ideas,
> > I reserved a 5K space here.
>
> You have reserved space in ucontext_t that you could use for this.
>
Sorry, I cannot really understand what you mean. The following is the
contents of ucontext_t
typedef struct ucontext_t
{
unsigned long int __uc_flags;
struct ucontext_t *uc_link;
stack_t uc_stack;
sigset_t uc_sigmask;
/* There's some padding here to allow sigset_t to be expanded in the
future. Though this is unlikely, other architectures put uc_sigmask
at the end of this structure and explicitly state it can be
expanded, so we didn't want to box ourselves in here. */
char __glibc_reserved[1024 / 8 - sizeof (sigset_t)];
/* We can't put uc_sigmask at the end of this structure because we need
to be able to expand sigcontext in the future. For example, the
vector ISA extension will almost certainly add ISA state. We want
to ensure all user-visible ISA state can be saved and restored via a
ucontext, so we're putting this at the end in order to allow for
infinite extensibility. Since we know this will be extended and we
assume sigset_t won't be extended an extreme amount, we're
prioritizing this. */
mcontext_t uc_mcontext;
} ucontext_t;
Currently, we only reserve a space, __glibc_reserved[], for the future
expansion of sigset_t.
Do you mean I could use __glibc_reserved[] to for future expansion of
ISA as well?
> >> > This shouldn't be necessary if the additional vector registers are
> >> > caller-saved.
> >
> > Here I am a little confused about the usage of struct mcontext_t. As
> > far as I know, the struct mcontext_t is used to save the
> > machine-specific information in user context operation. Therefore, in
> > this case, the struct mcontext_t is allowed to reserve the space only
> > for saving caller-saved registers. However, in the signal handler, the
> > user seems to be allowed to use uc_mcontext whose data type is struct
> > mcontext_t to access the content of the signal context. In this case,
> > the struct mcontext_t may need to be the same as the struct sigcontext
> > defined at kernel. However, it will have a conflict with your
> > suggestion because the struct sigcontext cannot just reserve a space
> > for saving caller-saved registers. Could you help me point out my
> > misunderstanding? Thank you.
>
> struct sigcontext is allocated by the kernel, so you can have pointers
> in reserved fields to out-of-line start, or after struct sigcontext.
>
> I don't know how the kernel implements this, but there is considerable
> flexibility and extensibility. The main issues comes from small stacks
> which are incompatible with large register files.
>
I have the same concern as you for reserving a huge space in
mcontext_t. If the content of mcontext_t is allowed to be different
from the content of sigcontext_t, and it has been confirmed that VCSR
should not be saved or restored by the *context function, then there
seems to be no need to reserve a space in mcontext to support V
extension. I will review it again. Thank you !!
> Thanks,
> Florian
>
More information about the Libc-alpha
mailing list