DynamoRIO / dynamorio

Dynamic Instrumentation Tool Platform
Other
2.63k stars 557 forks source link

Handle changes in SVE vector length on AArch64 #6625

Open jackgallagher-arm opened 8 months ago

jackgallagher-arm commented 8 months ago

In the discussion for #6544 @derekbruening and @abhinav92003 raised the issue of applications which change the vector length at runtime. Currently DynamoRIO assumes that the VL doesn't change at run time, but it is possible that applications can do it anyway using the Linux prctl() system call.

@derekbruening said:

Generally, we want to be able to run any program that the hardware supports, not just those that follow software conventions in compilers or ABIs, since there always seem to be real programs that violate those conventions, and there are cases where DR is used to run deliberately violating programs (analyzing malware, etc.). Only when such support is intractable do we reluctantly relax that and assume conventions: such as some rseq corner cases. So if it is practical to support it changing we would want to do that. We should add a handler for the prctl call that at least detects a change and provides a warning or error with a TODO to actually handle it.

The places I think of off the top of my head where changing VL definitely matters are:

  1. Scatter/gather expansion. The expanded sequence is an unrolled loop based on the number of elements in the vector. If the vector length changes, so does the number of elements so the expansion won't be valid any more.

  2. Machine context switching. We use ldr/str to save and restore the Z and P registers. Changing the vector length will scale the size of the offsets and transfer size for those instructions.

  3. drmemtrace/raw2trace. We will need to record any vector length changes in the raw trace so it can be handled in raw2trace and any tools which decode instructions