mm: properly implement page locking

This commit is contained in:
Matheus
2026-07-08 01:37:12 -03:00
parent af30088c0d
commit 1512b2f3c6
14 changed files with 123 additions and 45 deletions
+4 -2
View File
@@ -66,10 +66,12 @@ size_t iovec_iterator_read_from_ringbuffer(iovec_iterator_t *iovec_iterator, rin
// NOTE: the iovec can have userspace addresses. in this case, the copy can possibly fail with RINGBUFFER_USER_COPY_FAILED
size_t iovec_iterator_peek_from_ringbuffer(iovec_iterator_t *iovec_iterator, ringbuffer_t *ringbuffer, size_t byte_count, uintmax_t ringbuffer_offset);
// returns the physical address of the next page in the iovec_iterator, adding a reference count while at it
// returns the physical address of the next page in the iovec_iterator, adding a reference count and locking it for DMA.
// The write bool controls whether the hint passed to mm_get_physical_address is a read or write (i.e. reading data from the page or
// writing data to the page)
// sets the page_offset to the offset in the page, page_remaining to the remaining number of bytes in the page and page to the physical address of the page
// if no more pages in iovec_iterator, returns success with page being set to NULL
// fails with EFAULT if the page is not mapped
int iovec_iterator_next_page(iovec_iterator_t *iovec_iterator, size_t *page_offset, size_t *page_remaining, void **page);
int iovec_iterator_next_page(iovec_iterator_t *iovec_iterator, size_t *page_offset, size_t *page_remaining, void **page, bool write);
#endif
+2
View File
@@ -90,6 +90,8 @@ void mm_switch_context(mm_context_t *ctx);
#define MM_GET_PHYSICAL_ADDRESS_FLAGS_HOLD 1
#define MM_GET_PHYSICAL_ADDRESS_FLAGS_LOCK 2
#define MM_GET_PHYSICAL_ADDRESS_FLAGS_LOCK_HINT_READ 4
#define MM_GET_PHYSICAL_ADDRESS_FLAGS_LOCK_HINT_WRITE 8
void *mm_get_physical_address(void *addr, int flags);
void mm_apinit();
void mm_init();
+4
View File
@@ -3,6 +3,7 @@
#include <stddef.h>
#include <stdint.h>
#include <stdbool.h>
#define MEMORY_SECTION_COUNT 3
#define MEMORY_SECTION_1MB 0
@@ -44,11 +45,14 @@ page_t *mm_get_page(void *addr);
void *mm_get_page_address(page_t *);
void mm_hold_page(void *addr);
void mm_release_page(void *addr);
void mm_unlock_and_release_page(void *addr);
void mm_force_free_page(void *address, size_t count);
void *mm_alloc_pages(size_t size, int section);
void mm_release_range(void *addr, size_t size);
void mm_page_init();
void mm_get_page_statistics(size_t *total_pages, size_t *free_pages);
void mm_unlock_page(page_t *page);
bool mm_is_page_locked(page_t *page);
extern uintptr_t hhdm_base;
+1
View File
@@ -322,6 +322,7 @@ struct xhci_submission {
list_node_t list_node;
// Set whenever a submission is queued
bool valid;
bool unlock_pages;
struct xhci_ring *ring;
// The data associated with this submission