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

Unify MMU translation APIs #533

Merged
merged 1 commit into from
Jan 4, 2025
Merged

Conversation

ChinYikMing
Copy link
Collaborator

@ChinYikMing ChinYikMing commented Jan 3, 2025

To enable guest OS to run SDL applications using bidirectional queues, the VMM or system emulator must access the guest OS's virtual memory, as the queues are defined there. This requires MMU translation. In addition, the queues event data size likely larger than a word (maybe a page), thus the existing rv->io.mem_{read,write}_w do not sufficient for such memory manipulation.

Export rv->io.mem_translate() to perform gVA2gPA translation. Unifying MMU translation logic by using
rv->io.mem_translate(), eliminating redundant flows: mmu_walk -> check_pg_fault -> check_signal -> get_ppn_and_offset.
Also, this interface allowing src/syscall_sdl.c to handle virtual memory by first translating the gVA2gPA, followed by memory_{read/write} the chunk of data at once.

TODO: dTLB can be introduced in rv->io.mem_trans() to cache the gVA2gPA translation.

See: #310, #510

src/riscv.h Outdated
* ifetch do not leverage this translation because basic block
* might be retranslated and the corresponding PTE is NULL.
*/
typedef riscv_word_t (*riscv_mem_trans)(riscv_t *rv,
Copy link
Contributor

Choose a reason for hiding this comment

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

Specify _t suffix for typedef.

Copy link
Contributor

@jserv jserv Jan 4, 2025

Choose a reason for hiding this comment

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

I am not sure if riscv_mem_trans is meaningful enough. How about mmu_translate_t or mem_translate_t?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Specify _t suffix for typedef.

For only this one? What about the others?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I am not sure if riscv_mem_trans is meaningful enough. How about mmu_translate_t or mem_translate_t?

Use riscv prefix for consistency with others. I would go with riscv_mem_translate_t, is it OK?

Copy link
Contributor

Choose a reason for hiding this comment

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

Use riscv prefix for consistency with others. I would go with riscv_mem_translate_t, is it OK?

It looks good.

The reason not to use "trans" is that it is an existing adjective which might not be intended to mean "translate." See https://dictionary.cambridge.org/dictionary/english/trans

To enable guest OS to run SDL applications using bidirectional queues,
the VMM or system emulator must access the guest OS's virtual memory,
as the queues are defined there. This requires MMU translation. In
addition, the queues event data size likely larger than a word (maybe a
page), thus the existing rv->io.mem_{read,write}_w do not sufficient for
such memory manipulation.

Export rv->io.mem_translate() to perform gVA2gPA translation. Unifying
MMU translation logic by using rv->io.mem_translate(), eliminating
redundant flows:
mmu_walk -> check_pg_fault -> check_signal -> get_ppn_and_offset.
Also, this interface allowing src/syscall_sdl.c to handle virtual
memory by first translating the gVA2gPA, followed by memory_{read/write}
the chunk of data at once.

TODO: dTLB can be introduced in rv->io.mem_trans() to cache the gVA2gPA
translation.

See: sysprog21#310, sysprog21#510
@jserv jserv merged commit 61f5882 into sysprog21:master Jan 4, 2025
8 checks passed
@jserv
Copy link
Contributor

jserv commented Jan 4, 2025

Thank @ChinYikMing for contributing!

@ChinYikMing ChinYikMing deleted the unify-mmu-trans branch January 4, 2025 05:52
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