Skip to content

Conversation

@Arielfoever
Copy link
Contributor

@Arielfoever Arielfoever commented Nov 1, 2025

Add callbacks for each step of the page table walk process, and an option to log them.

Fixes #1356

@Arielfoever Arielfoever marked this pull request as ready for review November 2, 2025 13:42
@Arielfoever Arielfoever force-pushed the pr/callback branch 3 times, most recently from af9de2e to 7350b4a Compare November 2, 2025 14:16
@github-actions
Copy link

github-actions bot commented Nov 2, 2025

Test Results

2 115 tests  ±0   2 115 ✅ ±0   20m 59s ⏱️ -9s
    1 suites ±0       0 💤 ±0 
    1 files   ±0       0 ❌ ±0 

Results for commit 48410f5. ± Comparison against base commit 2eafe6d.

♻️ This comment has been updated with latest results.

@Timmmm
Copy link
Collaborator

Timmmm commented Nov 3, 2025

Looks pretty good. I think we probably don't want to convert things to strings though. Now that we use a generated header maybe we can use the actual generated types? zPrivilege and so on.

Copy link
Collaborator

@arichardson arichardson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding these makes a lot of sense. A few comments

@Arielfoever
Copy link
Contributor Author

I think we need to take into meeting due to divergence from #1372

@Arielfoever
Copy link
Contributor Author

We will add an option ptw-trace.

@Arielfoever Arielfoever marked this pull request as draft November 3, 2025 15:31
@jordancarlin
Copy link
Collaborator

We will add an option ptw-trace.

It should be --trace-ptw to be consistent with the other trace related flags.

@Arielfoever
Copy link
Contributor Author

Arielfoever commented Nov 3, 2025

We will add an option ptw-trace.

It should be --trace-ptw to be consistent with the other trace related flags.

I really hate add a lot of options for trace. we should have some modern log system that support subscript.

Go #1204

@Arielfoever
Copy link
Contributor Author

Looks pretty good. I think we probably don't want to convert things to strings though. Now that we use a generated header maybe we can use the actual generated types? zPrivilege and so on.

A little off topic - do we have a comparison table between C and sail and sail-riscv? like int in sail for sail-int for C.

@Timmmm
Copy link
Collaborator

Timmmm commented Nov 3, 2025

do we have a comparison table between C and sail and sail-riscv? like int in sail for sail-int for C.

There are three options:

  • fbits (alias for uint64_t) - when the type's size is statically known.
  • sbits - when it's not statically known but is statically known to be <= 64 bits.
  • lbits - if neither of the above applies.

Copy link
Collaborator

@Timmmm Timmmm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks pretty good. It's a shame we don't get the full address in these callbacks, but maybe those should be separate callbacks (translation_start_callback etc.), in a future PR.

Arielfoever added a commit to Arielfoever/sail-riscv that referenced this pull request Nov 7, 2025
Arielfoever added a commit to Arielfoever/sail-riscv that referenced this pull request Nov 7, 2025
@Arielfoever Arielfoever requested a review from Timmmm November 7, 2025 12:32
Arielfoever added a commit to Arielfoever/sail-riscv that referenced this pull request Nov 7, 2025
Arielfoever added a commit to Arielfoever/sail-riscv that referenced this pull request Nov 7, 2025
Arielfoever added a commit to Arielfoever/sail-riscv that referenced this pull request Dec 1, 2025
Fix riscv#1370 (comment)

Signed-off-by: Ariel Xiong <[email protected]>
@Arielfoever Arielfoever requested a review from nadime15 December 1, 2025 07:04
Arielfoever added a commit to Arielfoever/sail-riscv that referenced this pull request Dec 1, 2025
Fix riscv#1370 (comment)

Fix riscv#1370 (comment)

Fix riscv#1370 (comment)

Co-authored-by: Nadime Barhoumi <[email protected]>
Signed-off-by: Ariel Xiong <[email protected]>
Arielfoever and others added 7 commits December 1, 2025 22:41
Signed-off-by: Ariel Xiong <[email protected]>
Fix riscv#1370 (comment)

Signed-off-by: Ariel Xiong <[email protected]>
Signed-off-by: Ariel Xiong <[email protected]>
Signed-off-by: Ariel Xiong <[email protected]>
Fix riscv#1370 (comment)

Fix riscv#1370 (comment)

Fix riscv#1370 (comment)

Co-authored-by: Nadime Barhoumi <[email protected]>
Signed-off-by: Ariel Xiong <[email protected]>
Signed-off-by: Ariel Xiong <[email protected]>
Copy link
Collaborator

@Timmmm Timmmm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks for this!

@Timmmm Timmmm changed the title Add callback for pt walk Add callbacks and logging for page table walks Dec 1, 2025
@Timmmm Timmmm added the will be merged Scheduled to be merged soon if nobody objects label Dec 1, 2025
Copy link
Collaborator

@arichardson arichardson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we print the level as well? Otherwise LGTM.

Co-authored-by: Jordan Carlin <[email protected]>
Signed-off-by: Ariel Xiong <[email protected]>
Signed-off-by: Ariel Xiong <[email protected]>
Comment on lines +2 to +12
val ptw_start_callback = pure {c: "ptw_start_callback"} : (/* vpn */ bits(64), /* access type */ MemoryAccessType(ext_access_type), /* privilege */ Privilege) -> unit
function ptw_start_callback(_) = ()

val ptw_step_callback = pure {c: "ptw_step_callback"} : (/* level */ int, /* pte_addr */ physaddrbits, /* pte */ bits(64)) -> unit
function ptw_step_callback(_) = ()

val ptw_success_callback = pure {c: "ptw_success_callback"} : (/* final_ppn */ bits(64), /* level */ int) -> unit
function ptw_success_callback(_) = ()

val ptw_fail_callback = pure {c: "ptw_fail_callback"} : (/* error_type */ PTW_Error, /* level */ int, /* pte_addr */ physaddrbits) -> unit
function ptw_fail_callback(_) = ()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of using int for level, couldnt this be a range(0, 4)? If so, would that be a different type than sail_int, allowing you to keep fprintf instead of switching to gmp_fprintf? Anyway, this is probably a minor detail and not really important.

Suggested change
val ptw_start_callback = pure {c: "ptw_start_callback"} : (/* vpn */ bits(64), /* access type */ MemoryAccessType(ext_access_type), /* privilege */ Privilege) -> unit
function ptw_start_callback(_) = ()
val ptw_step_callback = pure {c: "ptw_step_callback"} : (/* level */ int, /* pte_addr */ physaddrbits, /* pte */ bits(64)) -> unit
function ptw_step_callback(_) = ()
val ptw_success_callback = pure {c: "ptw_success_callback"} : (/* final_ppn */ bits(64), /* level */ int) -> unit
function ptw_success_callback(_) = ()
val ptw_fail_callback = pure {c: "ptw_fail_callback"} : (/* error_type */ PTW_Error, /* level */ int, /* pte_addr */ physaddrbits) -> unit
function ptw_fail_callback(_) = ()
val ptw_start_callback = pure {c: "ptw_start_callback"} : (/* vpn */ bits(64), /* access type */ MemoryAccessType(ext_access_type), /* privilege */ Privilege) -> unit
function ptw_start_callback(_) = ()
val ptw_step_callback = pure {c: "ptw_step_callback"} : (/* level */ int, /* pte_addr */ physaddrbits, /* pte */ bits(64)) -> unit
function ptw_step_callback(_) = ()
val ptw_success_callback = pure {c: "ptw_success_callback"} : (/* final_ppn */ bits(64), /* level */ int) -> unit
function ptw_success_callback(_) = ()
val ptw_fail_callback = pure {c: "ptw_fail_callback"} : (/* error_type */ PTW_Error, /* level */ range(0, 4), /* pte_addr */ physaddrbits) -> unit
function ptw_fail_callback(_) = ()

@arichardson
Copy link
Collaborator

Using range(0, 4) sounds good to me. Should we hold of on this until #1274 is merged?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

will be merged Scheduled to be merged soon if nobody objects

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add PTW callbacks

5 participants