Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement save_fpstate on AArch64 #2629

Closed
fhahn opened this issue Sep 8, 2017 · 7 comments · Fixed by #4596
Closed

Implement save_fpstate on AArch64 #2629

fhahn opened this issue Sep 8, 2017 · 7 comments · Fixed by #4596

Comments

@fhahn
Copy link
Contributor

fhahn commented Sep 8, 2017

It is not implemented at the moment. We should also add a test that requires save_fpstate, because it looks like there is non for AArch64 at the moment.

xref #1569

@egrimley
Copy link
Contributor

egrimley commented Sep 8, 2017

But what should save_fpstate do on AArch64? The comment in AArch64's proc_save_fpstate says:

    /* All registers are saved by insert_push_all_registers so nothing extra
     * needs to be saved here.
     */

And there's the comment in proc.h:

/* On ARM/AArch64 proc_save_fpstate saves nothing, so use the smallest
 * legal size for an array.
 */
# define DR_FPSTATE_BUF_SIZE 1

Clearly save_fpstate is not the same thing as proc_save_fpstate, but perhaps the solution for save_fpstate is to replace ASSERT_NOT_IMPLEMENTED with ASSERT_NOT_REACHED: perhaps the function is required by an API but should not be called on ARM/AArch64?

@egrimley
Copy link
Contributor

egrimley commented Sep 8, 2017

On ARM and AArch64 the only use of save_fpstate is in thread_set_self_context, which (on any architecture) is only used by check_wait_at_safe_spot, sometimes via thread_set_self_mcontext.

@abhinav92003
Copy link
Contributor

On ARM and AArch64 the only use of save_fpstate is in thread_set_self_context, which (on any architecture) is only used by check_wait_at_safe_spot, sometimes via thread_set_self_mcontext.

@egrimley Is this just an observation of the existing code's state, or are you pointing out that we do need the save_fpstate in thread_set_self_context.

For context: I'm working on PR #4507 and we're trying to figure out whether we need this call or not for AArch64 (see comment thread on PR).

@derekbruening
Copy link
Contributor

Both save_fpstate and proc_save_fpstate only exist because the x87 floating point registers and status words are not kept in the dr_mcontext_t. save_fpstate is used to update the x87 state when a signal is delayed and the state stored by the kernel needs updating in case the app ran x87 instructions in the delay window; proc_save_fpstate is for when DR or a client uses x87 instructions and keeps that use from clobbering the native x87 state which is what the app uses.

But, on arm and aarch64, the entire register state is in dr_mcontext_t, including all the SIMD registers which are used for floating-point operations. Right? So I don't think we need either save_fpstate nor proc_save_fpstate on any aarchxx architecture.

@AssadHashmi
Copy link
Contributor

But, on arm and aarch64, the entire register state is in dr_mcontext_t, including all the SIMD registers which are used for floating-point operations. Right? So I don't think we need either save_fpstate nor proc_save_fpstate on any aarchxx architecture.

That sounds right. I've not done any work in this area and need to spend some time on it if I'm to be of any use for reviewing and patching.

@derekbruening
Copy link
Contributor

So maybe the only action item here is to add clarifications to the API docs and internal code as to which platforms/situations they apply. Probably we should clarify what "floating point state" means for x86 as well: that it's only x87 state plus mmx registers (occupying the same silicon) and not xmm/ymm/zmm.

@egrimley-arm
Copy link
Contributor

On ARM and AArch64 the only use of save_fpstate is in thread_set_self_context, which (on any architecture) is only used by check_wait_at_safe_spot, sometimes via thread_set_self_mcontext.

@egrimley Is this just an observation of the existing code's state

Yes.

Provided you're using an architecture variant that has the registers, the SIMD registers on AArch64 aren't usually treated much differently from any other register. I've seen a compiler spill an integer value to a SIMD register, for example.

abhinav92003 added a commit that referenced this issue Nov 5, 2020
Implements some missing AArch64 pieces for invoking dynamorio_sigreturn.

Fixes dispatch assert to allow threads to enter dispatch after reset. The current condition allows it only when sending threads native. This affected x86 and AArch64 both.

Fixes a bug in setting xsp for sigreturn on AArchXX.

Skips save_fpstate for AArch64 as that is not needed.

Changes reset trigger for Linux reset tests to -reset_at_nth_thread. To increase coverage of these tests, we need to trigger reset at a time when multiple threads are active. This is difficult to do using the -reset_at_fragment_count option, which may need to be tuned regularly to its ideal value, which also differs based on platform.


Issue #2629 
Fixes #4496
Fixes #4497
gregcawthorne pushed a commit that referenced this issue Nov 28, 2020
Implements some missing AArch64 pieces for invoking dynamorio_sigreturn.

Fixes dispatch assert to allow threads to enter dispatch after reset. The current condition allows it only when sending threads native. This affected x86 and AArch64 both.

Fixes a bug in setting xsp for sigreturn on AArchXX.

Skips save_fpstate for AArch64 as that is not needed.

Changes reset trigger for Linux reset tests to -reset_at_nth_thread. To increase coverage of these tests, we need to trigger reset at a time when multiple threads are active. This is difficult to do using the -reset_at_fragment_count option, which may need to be tuned regularly to its ideal value, which also differs based on platform.


Issue #2629 
Fixes #4496
Fixes #4497
derekbruening added a commit that referenced this issue Dec 8, 2020
Clarifies the prose documentation and API routine documentation on
what floating-point state is preserved and what is not by DR and what
the various explicit "fpstate" preservation routines operate on: only
the *x87* floating-point state.

Fixes #2629
derekbruening added a commit that referenced this issue Dec 9, 2020
Clarifies the prose documentation and API routine documentation on
what floating-point state is preserved and what is not by DR and what
the various explicit "fpstate" preservation routines operate on: only
the *x87* floating-point state.

Fixes #2629
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants