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

Optimize Notdirty write #2031

Merged
merged 5 commits into from
Oct 31, 2024
Merged

Conversation

PhilippTakacs
Copy link
Contributor

This enables notdirty_write when used with snapshots. To do this the tlb is cleared on a snapshot and the priority of the mr is compared with the snapshot level.

It also fixes a bug when the mmu doesn't map 1:1. Before this the memory region was looked up with the vaddr, but memory regions are mapped at the paddr.

It's currently a draft because I also want to improve the MEM_HOOK check. As you already noticed in #2029 there are some hooks missing in the check. I would also include a range check for the hooks so only skip the optimization when there is a hook on this address.

@PhilippTakacs PhilippTakacs force-pushed the notdirty_write branch 2 times, most recently from 443e28d to 2717b79 Compare October 22, 2024 13:25
@PhilippTakacs PhilippTakacs marked this pull request as ready for review October 22, 2024 14:10
@wtdcode
Copy link
Member

wtdcode commented Oct 29, 2024

Is it ready?

@PhilippTakacs
Copy link
Contributor Author

Not yet, I have to adjust the check for tlb_reset_dirty_by_vaddr() in tb_gen_code()

Snapshots only happens when the priority of the memory region is smaller
then the snapshot_level. After a snapshot notdirty can be set.
When SMC access the memory region more then once the
tb must be rebuild multible times.

fixes unicorn-engine#2029
Check all relevant memory hooks before enabling notdirty write.
This also checks if the memory hook is registered for the affected
region. So it is possible to use notdirty write and have some hooks
on different addresses.
when self modifying code does unaligned memory accese sometimes
uc->size_recur_mem is changed but for notdirty write not changed back.
This causes mem_hooks to be missed. To fix this uc->size_recur_mem is
set to 0 before each cpu_exec() call.
@PhilippTakacs
Copy link
Contributor Author

@wtdcode now it's ready

@wtdcode
Copy link
Member

wtdcode commented Oct 31, 2024

@wtdcode now it's ready

Cool, look pretty good to me and thanks a lot for adding tests. Would you like to amend your commit history?

@PhilippTakacs
Copy link
Contributor Author

The comment history is already in the way I would like it.

@wtdcode wtdcode merged commit ab23d4c into unicorn-engine:dev Oct 31, 2024
36 checks passed
@wtdcode
Copy link
Member

wtdcode commented Oct 31, 2024

Thanks!

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

Successfully merging this pull request may close these issues.

2 participants