From 14e1b1a9fca25c4315d35c9f84a7e80fc273e88a Mon Sep 17 00:00:00 2001 From: Zhang Junyang Date: Sun, 26 May 2024 17:53:44 +0000 Subject: [PATCH] Rename various concepts related to memory management --- docs/src/framework/a-100-line-kernel.md | 2 +- .../src/arch/x86/boot/linux_boot/mod.rs | 2 +- .../src/arch/x86/boot/multiboot/mod.rs | 2 +- .../src/arch/x86/boot/multiboot2/mod.rs | 2 +- .../src/arch/x86/iommu/context_table.rs | 8 ++-- .../aster-frame/src/arch/x86/iommu/fault.rs | 2 +- .../aster-frame/src/arch/x86/iommu/mod.rs | 2 +- .../src/arch/x86/iommu/remapping.rs | 2 +- .../src/arch/x86/iommu/second_stage.rs | 2 +- .../src/arch/x86/kernel/acpi/dmar.rs | 2 +- .../src/arch/x86/kernel/acpi/mod.rs | 2 +- .../src/arch/x86/kernel/apic/ioapic.rs | 2 +- .../src/arch/x86/kernel/apic/xapic.rs | 4 +- framework/aster-frame/src/arch/x86/mm/mod.rs | 2 +- .../aster-frame/src/arch/x86/tdx_guest.rs | 2 +- .../aster-frame/src/arch/x86/timer/hpet.rs | 2 +- .../aster-frame/src/boot/memory_region.rs | 2 +- framework/aster-frame/src/bus/mmio/device.rs | 2 +- framework/aster-frame/src/bus/mmio/mod.rs | 4 +- .../src/bus/pci/capability/msix.rs | 2 +- .../aster-frame/src/collections/xarray.rs | 2 +- framework/aster-frame/src/error.rs | 2 +- framework/aster-frame/src/io_mem.rs | 2 +- framework/aster-frame/src/lib.rs | 14 +++--- .../src/{vm => mm}/dma/dma_coherent.rs | 12 ++--- .../src/{vm => mm}/dma/dma_stream.rs | 14 +++--- .../aster-frame/src/{vm => mm}/dma/mod.rs | 2 +- .../src/{vm => mm}/heap_allocator.rs | 2 +- framework/aster-frame/src/{vm => mm}/io.rs | 2 +- .../aster-frame/src/{vm => mm}/kspace.rs | 2 +- framework/aster-frame/src/{vm => mm}/mod.rs | 2 +- .../aster-frame/src/{vm => mm}/offset.rs | 0 .../aster-frame/src/{vm => mm}/options.rs | 8 ++-- .../src/{vm => mm}/page/allocator.rs | 16 +++---- .../aster-frame/src/{vm => mm}/page/frame.rs | 41 +++++++--------- .../aster-frame/src/{vm => mm}/page/meta.rs | 4 +- .../aster-frame/src/{vm => mm}/page/mod.rs | 16 +++---- .../src/{vm => mm}/page/segment.rs | 32 ++++++------- .../src/{vm => mm}/page/vm_frame_vec.rs | 24 +++++----- .../aster-frame/src/{vm => mm}/page_prop.rs | 0 .../src/{vm => mm}/page_table/boot_pt.rs | 6 +-- .../src/{vm => mm}/page_table/cursor.rs | 24 +++++----- .../src/{vm => mm}/page_table/frame.rs | 48 +++++++++---------- .../src/{vm => mm}/page_table/mod.rs | 8 ++-- .../src/{vm => mm}/page_table/test.rs | 6 +-- framework/aster-frame/src/{vm => mm}/space.rs | 12 ++--- framework/aster-frame/src/prelude.rs | 2 +- framework/aster-frame/src/task/task.rs | 10 ++-- framework/aster-frame/src/user.rs | 2 +- kernel/aster-nix/src/device/tty/driver.rs | 2 +- kernel/aster-nix/src/fs/exfat/dentry.rs | 2 +- kernel/aster-nix/src/fs/exfat/fs.rs | 8 ++-- kernel/aster-nix/src/fs/exfat/inode.rs | 6 +-- kernel/aster-nix/src/fs/exfat/mod.rs | 10 ++-- kernel/aster-nix/src/fs/ext2/block_group.rs | 6 +-- kernel/aster-nix/src/fs/ext2/fs.rs | 16 +++---- .../src/fs/ext2/indirect_block_cache.rs | 2 +- kernel/aster-nix/src/fs/ext2/inode.rs | 20 ++++---- kernel/aster-nix/src/fs/ext2/prelude.rs | 2 +- kernel/aster-nix/src/fs/ramfs/fs.rs | 6 +-- kernel/aster-nix/src/fs/utils/page_cache.rs | 16 +++---- kernel/aster-nix/src/prelude.rs | 2 +- kernel/aster-nix/src/process/clone.rs | 2 +- .../src/process/process_vm/init_stack/mod.rs | 2 +- .../process/program_loader/elf/load_elf.rs | 2 +- .../aster-nix/src/syscall/rt_sigprocmask.rs | 2 +- kernel/aster-nix/src/util/mod.rs | 2 +- .../aster-nix/src/util/net/options/utils.rs | 2 +- kernel/aster-nix/src/vdso.rs | 6 +-- kernel/aster-nix/src/vm/perms.rs | 2 +- kernel/aster-nix/src/vm/vmar/dyn_cap.rs | 6 +-- kernel/aster-nix/src/vm/vmar/mod.rs | 11 +---- kernel/aster-nix/src/vm/vmar/options.rs | 10 ++-- kernel/aster-nix/src/vm/vmar/static_cap.rs | 6 +-- kernel/aster-nix/src/vm/vmar/vm_mapping.rs | 6 +-- kernel/aster-nix/src/vm/vmo/dyn_cap.rs | 4 +- kernel/aster-nix/src/vm/vmo/mod.rs | 40 ++++++++-------- kernel/aster-nix/src/vm/vmo/options.rs | 26 +++++----- kernel/aster-nix/src/vm/vmo/pager.rs | 4 +- kernel/aster-nix/src/vm/vmo/static_cap.rs | 4 +- kernel/comps/block/src/bio.rs | 16 +++---- kernel/comps/block/src/impl_block_device.rs | 30 +++++------- kernel/comps/block/src/lib.rs | 2 +- kernel/comps/console/src/lib.rs | 2 +- kernel/comps/framebuffer/src/lib.rs | 4 +- kernel/comps/network/src/buffer.rs | 2 +- kernel/comps/network/src/dma_pool.rs | 2 +- kernel/comps/network/src/driver.rs | 2 +- .../comps/virtio/src/device/block/device.rs | 2 +- .../comps/virtio/src/device/console/device.rs | 2 +- .../comps/virtio/src/device/input/device.rs | 2 +- kernel/comps/virtio/src/dma_buf.rs | 2 +- kernel/comps/virtio/src/queue.rs | 4 +- .../comps/virtio/src/transport/mmio/device.rs | 2 +- kernel/comps/virtio/src/transport/mod.rs | 2 +- .../comps/virtio/src/transport/pci/device.rs | 2 +- kernel/libs/aster-util/src/safe_ptr.rs | 6 +-- 97 files changed, 331 insertions(+), 353 deletions(-) rename framework/aster-frame/src/{vm => mm}/dma/dma_coherent.rs (97%) rename framework/aster-frame/src/{vm => mm}/dma/dma_stream.rs (97%) rename framework/aster-frame/src/{vm => mm}/dma/mod.rs (97%) rename framework/aster-frame/src/{vm => mm}/heap_allocator.rs (98%) rename framework/aster-frame/src/{vm => mm}/io.rs (99%) rename framework/aster-frame/src/{vm => mm}/kspace.rs (99%) rename framework/aster-frame/src/{vm => mm}/mod.rs (98%) rename framework/aster-frame/src/{vm => mm}/offset.rs (100%) rename framework/aster-frame/src/{vm => mm}/options.rs (94%) rename framework/aster-frame/src/{vm => mm}/page/allocator.rs (85%) rename framework/aster-frame/src/{vm => mm}/page/frame.rs (78%) rename framework/aster-frame/src/{vm => mm}/page/meta.rs (99%) rename framework/aster-frame/src/{vm => mm}/page/mod.rs (93%) rename framework/aster-frame/src/{vm => mm}/page/segment.rs (86%) rename framework/aster-frame/src/{vm => mm}/page/vm_frame_vec.rs (87%) rename framework/aster-frame/src/{vm => mm}/page_prop.rs (100%) rename framework/aster-frame/src/{vm => mm}/page_table/boot_pt.rs (97%) rename framework/aster-frame/src/{vm => mm}/page_table/cursor.rs (97%) rename framework/aster-frame/src/{vm => mm}/page_table/frame.rs (94%) rename framework/aster-frame/src/{vm => mm}/page_table/mod.rs (98%) rename framework/aster-frame/src/{vm => mm}/page_table/test.rs (98%) rename framework/aster-frame/src/{vm => mm}/space.rs (98%) diff --git a/docs/src/framework/a-100-line-kernel.md b/docs/src/framework/a-100-line-kernel.md index a908544f6..7faf71073 100644 --- a/docs/src/framework/a-100-line-kernel.md +++ b/docs/src/framework/a-100-line-kernel.md @@ -75,7 +75,7 @@ fn create_user_space(program: &[u8]) -> UserSpace { let nframes = program.len().align_up(PAGE_SIZE) / PAGE_SIZE; let vm_frames = VmAllocOptions::new(nframes).alloc().unwrap(); // Phyiscal memory pages can be only accessed - // via the VmFrame abstraction. + // via the Frame abstraction. vm_frames.write_bytes(0, program).unwrap(); vm_frames }; diff --git a/framework/aster-frame/src/arch/x86/boot/linux_boot/mod.rs b/framework/aster-frame/src/arch/x86/boot/linux_boot/mod.rs index c2e18bb6a..16c354e69 100644 --- a/framework/aster-frame/src/arch/x86/boot/linux_boot/mod.rs +++ b/framework/aster-frame/src/arch/x86/boot/linux_boot/mod.rs @@ -15,7 +15,7 @@ use crate::{ memory_region::{non_overlapping_regions_from, MemoryRegion, MemoryRegionType}, BootloaderAcpiArg, BootloaderFramebufferArg, }, - vm::kspace::{paddr_to_vaddr, LINEAR_MAPPING_BASE_VADDR}, + mm::kspace::{paddr_to_vaddr, LINEAR_MAPPING_BASE_VADDR}, }; static BOOT_PARAMS: Once = Once::new(); diff --git a/framework/aster-frame/src/arch/x86/boot/multiboot/mod.rs b/framework/aster-frame/src/arch/x86/boot/multiboot/mod.rs index aaed17abd..631dc0265 100644 --- a/framework/aster-frame/src/arch/x86/boot/multiboot/mod.rs +++ b/framework/aster-frame/src/arch/x86/boot/multiboot/mod.rs @@ -12,7 +12,7 @@ use crate::{ memory_region::{non_overlapping_regions_from, MemoryRegion, MemoryRegionType}, BootloaderAcpiArg, BootloaderFramebufferArg, }, - vm::kspace::{paddr_to_vaddr, LINEAR_MAPPING_BASE_VADDR}, + mm::kspace::{paddr_to_vaddr, LINEAR_MAPPING_BASE_VADDR}, }; global_asm!(include_str!("header.S")); diff --git a/framework/aster-frame/src/arch/x86/boot/multiboot2/mod.rs b/framework/aster-frame/src/arch/x86/boot/multiboot2/mod.rs index 40c6fb739..bee78e40b 100644 --- a/framework/aster-frame/src/arch/x86/boot/multiboot2/mod.rs +++ b/framework/aster-frame/src/arch/x86/boot/multiboot2/mod.rs @@ -15,7 +15,7 @@ use crate::{ memory_region::{non_overlapping_regions_from, MemoryRegion, MemoryRegionType}, BootloaderAcpiArg, BootloaderFramebufferArg, }, - vm::kspace::paddr_to_vaddr, + mm::kspace::paddr_to_vaddr, }; global_asm!(include_str!("header.S")); diff --git a/framework/aster-frame/src/arch/x86/iommu/context_table.rs b/framework/aster-frame/src/arch/x86/iommu/context_table.rs index 37eafcaef..16c010d5f 100644 --- a/framework/aster-frame/src/arch/x86/iommu/context_table.rs +++ b/framework/aster-frame/src/arch/x86/iommu/context_table.rs @@ -9,11 +9,11 @@ use pod::Pod; use super::second_stage::{DeviceMode, PageTableEntry, PagingConsts}; use crate::{ bus::pci::PciDeviceLocation, - vm::{ + mm::{ dma::Daddr, page_prop::{CachePolicy, PageProperty, PrivilegedPageFlags as PrivFlags}, page_table::PageTableError, - Paddr, PageFlags, PageTable, VmAllocOptions, VmFrame, VmIo, PAGE_SIZE, + Frame, Paddr, PageFlags, PageTable, VmAllocOptions, VmIo, PAGE_SIZE, }, }; @@ -36,7 +36,7 @@ impl RootEntry { pub struct RootTable { /// Total 256 bus, each entry is 128 bits. - root_frame: VmFrame, + root_frame: Frame, // TODO: Use radix tree instead. context_tables: BTreeMap, } @@ -233,7 +233,7 @@ pub enum AddressWidth { pub struct ContextTable { /// Total 32 devices, each device has 8 functions. - entries_frame: VmFrame, + entries_frame: Frame, page_tables: BTreeMap>, } diff --git a/framework/aster-frame/src/arch/x86/iommu/fault.rs b/framework/aster-frame/src/arch/x86/iommu/fault.rs index 93079c3e1..7943a1c33 100644 --- a/framework/aster-frame/src/arch/x86/iommu/fault.rs +++ b/framework/aster-frame/src/arch/x86/iommu/fault.rs @@ -10,7 +10,7 @@ use trapframe::TrapFrame; use volatile::{access::ReadWrite, Volatile}; use super::remapping::Capability; -use crate::{trap::IrqLine, vm::Vaddr}; +use crate::{mm::Vaddr, trap::IrqLine}; #[derive(Debug)] pub struct FaultEventRegisters { diff --git a/framework/aster-frame/src/arch/x86/iommu/mod.rs b/framework/aster-frame/src/arch/x86/iommu/mod.rs index a7a0efa22..1e7fa3dae 100644 --- a/framework/aster-frame/src/arch/x86/iommu/mod.rs +++ b/framework/aster-frame/src/arch/x86/iommu/mod.rs @@ -13,8 +13,8 @@ use spin::Once; use crate::{ arch::iommu::context_table::RootTable, bus::pci::PciDeviceLocation, + mm::{dma::Daddr, page_table::PageTableError, Paddr, PageTable}, sync::Mutex, - vm::{dma::Daddr, page_table::PageTableError, Paddr, PageTable}, }; #[derive(Debug)] diff --git a/framework/aster-frame/src/arch/x86/iommu/remapping.rs b/framework/aster-frame/src/arch/x86/iommu/remapping.rs index 91d85cc01..c82e4b660 100644 --- a/framework/aster-frame/src/arch/x86/iommu/remapping.rs +++ b/framework/aster-frame/src/arch/x86/iommu/remapping.rs @@ -17,7 +17,7 @@ use crate::{ ACPI_TABLES, }, }, - vm::paddr_to_vaddr, + mm::paddr_to_vaddr, }; #[derive(Debug)] diff --git a/framework/aster-frame/src/arch/x86/iommu/second_stage.rs b/framework/aster-frame/src/arch/x86/iommu/second_stage.rs index 18d908388..a1549747a 100644 --- a/framework/aster-frame/src/arch/x86/iommu/second_stage.rs +++ b/framework/aster-frame/src/arch/x86/iommu/second_stage.rs @@ -4,7 +4,7 @@ use core::ops::Range; use pod::Pod; -use crate::vm::{ +use crate::mm::{ page_prop::{CachePolicy, PageFlags, PrivilegedPageFlags as PrivFlags}, page_table::{PageTableEntryTrait, PageTableMode}, Paddr, PageProperty, PagingConstsTrait, PagingLevel, Vaddr, diff --git a/framework/aster-frame/src/arch/x86/kernel/acpi/dmar.rs b/framework/aster-frame/src/arch/x86/kernel/acpi/dmar.rs index 6b1e4f140..0465f29c5 100644 --- a/framework/aster-frame/src/arch/x86/kernel/acpi/dmar.rs +++ b/framework/aster-frame/src/arch/x86/kernel/acpi/dmar.rs @@ -9,7 +9,7 @@ use super::{ remapping::{Andd, Atsr, Drhd, Rhsa, Rmrr, Satc, Sidp}, SdtHeaderWrapper, }; -use crate::vm::paddr_to_vaddr; +use crate::mm::paddr_to_vaddr; /// DMA Remapping structure. When IOMMU is enabled, the structure should be present in the ACPI table, /// and the user can use the DRHD table in this structure to obtain the register base addresses used to configure functions such as IOMMU. diff --git a/framework/aster-frame/src/arch/x86/kernel/acpi/mod.rs b/framework/aster-frame/src/arch/x86/kernel/acpi/mod.rs index 59aefb916..44c7d5680 100644 --- a/framework/aster-frame/src/arch/x86/kernel/acpi/mod.rs +++ b/framework/aster-frame/src/arch/x86/kernel/acpi/mod.rs @@ -15,8 +15,8 @@ use spin::Once; use crate::{ boot::{self, BootloaderAcpiArg}, + mm::paddr_to_vaddr, sync::SpinLock, - vm::paddr_to_vaddr, }; /// RSDP information, key is the signature, value is the virtual address of the signature diff --git a/framework/aster-frame/src/arch/x86/kernel/apic/ioapic.rs b/framework/aster-frame/src/arch/x86/kernel/apic/ioapic.rs index 7ff5c8723..b68e00bc8 100644 --- a/framework/aster-frame/src/arch/x86/kernel/apic/ioapic.rs +++ b/framework/aster-frame/src/arch/x86/kernel/apic/ioapic.rs @@ -12,7 +12,7 @@ use spin::Once; #[cfg(feature = "intel_tdx")] use crate::arch::tdx_guest; use crate::{ - arch::x86::kernel::acpi::ACPI_TABLES, sync::SpinLock, trap::IrqLine, vm::paddr_to_vaddr, Error, + arch::x86::kernel::acpi::ACPI_TABLES, mm::paddr_to_vaddr, sync::SpinLock, trap::IrqLine, Error, Result, }; diff --git a/framework/aster-frame/src/arch/x86/kernel/apic/xapic.rs b/framework/aster-frame/src/arch/x86/kernel/apic/xapic.rs index ad62ab8ed..9ebb20b2c 100644 --- a/framework/aster-frame/src/arch/x86/kernel/apic/xapic.rs +++ b/framework/aster-frame/src/arch/x86/kernel/apic/xapic.rs @@ -4,7 +4,7 @@ use spin::Once; use x86::apic::xapic; use super::ApicTimer; -use crate::{sync::Mutex, vm}; +use crate::{mm, sync::Mutex}; const IA32_APIC_BASE_MSR: u32 = 0x1B; const IA32_APIC_BASE_MSR_BSP: u32 = 0x100; // Processor is a BSP @@ -24,7 +24,7 @@ impl XApic { if !Self::has_xapic() { return None; } - let address = vm::paddr_to_vaddr(get_apic_base_address()); + let address = mm::paddr_to_vaddr(get_apic_base_address()); let region: &'static mut [u32] = unsafe { &mut *(address as *mut [u32; 256]) }; Some(Self { mmio_region: region, diff --git a/framework/aster-frame/src/arch/x86/mm/mod.rs b/framework/aster-frame/src/arch/x86/mm/mod.rs index f12beff88..6d1b3f45b 100644 --- a/framework/aster-frame/src/arch/x86/mm/mod.rs +++ b/framework/aster-frame/src/arch/x86/mm/mod.rs @@ -6,7 +6,7 @@ use core::ops::Range; use pod::Pod; use x86_64::{instructions::tlb, structures::paging::PhysFrame, VirtAddr}; -use crate::vm::{ +use crate::mm::{ page_prop::{CachePolicy, PageFlags, PageProperty, PrivilegedPageFlags as PrivFlags}, page_table::PageTableEntryTrait, Paddr, PagingConstsTrait, PagingLevel, Vaddr, PAGE_SIZE, diff --git a/framework/aster-frame/src/arch/x86/tdx_guest.rs b/framework/aster-frame/src/arch/x86/tdx_guest.rs index 42a5ee9b7..3d9fa70bc 100644 --- a/framework/aster-frame/src/arch/x86/tdx_guest.rs +++ b/framework/aster-frame/src/arch/x86/tdx_guest.rs @@ -13,7 +13,7 @@ use trapframe::TrapFrame; use crate::{ arch::mm::PageTableFlags, - vm::{ + mm::{ kspace::KERNEL_PAGE_TABLE, paddr_to_vaddr, page_prop::{CachePolicy, PageProperty, PrivilegedPageFlags as PrivFlags}, diff --git a/framework/aster-frame/src/arch/x86/timer/hpet.rs b/framework/aster-frame/src/arch/x86/timer/hpet.rs index f33c544f6..12ca28b88 100644 --- a/framework/aster-frame/src/arch/x86/timer/hpet.rs +++ b/framework/aster-frame/src/arch/x86/timer/hpet.rs @@ -11,8 +11,8 @@ use volatile::{ use crate::{ arch::x86::kernel::{acpi::ACPI_TABLES, apic::ioapic}, + mm::paddr_to_vaddr, trap::IrqLine, - vm::paddr_to_vaddr, }; static HPET_INSTANCE: Once = Once::new(); diff --git a/framework/aster-frame/src/boot/memory_region.rs b/framework/aster-frame/src/boot/memory_region.rs index 4bf2c7d08..e36a7844d 100644 --- a/framework/aster-frame/src/boot/memory_region.rs +++ b/framework/aster-frame/src/boot/memory_region.rs @@ -6,7 +6,7 @@ use alloc::{vec, vec::Vec}; use core::mem::swap; -use crate::vm::kspace::kernel_loaded_offset; +use crate::mm::kspace::kernel_loaded_offset; /// The type of initial memory regions that are needed for the kernel. #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Debug)] diff --git a/framework/aster-frame/src/bus/mmio/device.rs b/framework/aster-frame/src/bus/mmio/device.rs index 35989bae4..136ba35e6 100644 --- a/framework/aster-frame/src/bus/mmio/device.rs +++ b/framework/aster-frame/src/bus/mmio/device.rs @@ -6,8 +6,8 @@ use log::info; use super::VIRTIO_MMIO_MAGIC; use crate::{ io_mem::IoMem, + mm::{paddr_to_vaddr, Paddr, VmIo}, trap::IrqLine, - vm::{paddr_to_vaddr, Paddr, VmIo}, }; /// MMIO Common device. diff --git a/framework/aster-frame/src/bus/mmio/mod.rs b/framework/aster-frame/src/bus/mmio/mod.rs index 25a54a9d3..73be216ae 100644 --- a/framework/aster-frame/src/bus/mmio/mod.rs +++ b/framework/aster-frame/src/bus/mmio/mod.rs @@ -16,8 +16,8 @@ use self::bus::MmioBus; #[cfg(feature = "intel_tdx")] use crate::arch::tdx_guest; use crate::{ - arch::kernel::IO_APIC, bus::mmio::device::MmioCommonDevice, sync::SpinLock, trap::IrqLine, - vm::paddr_to_vaddr, + arch::kernel::IO_APIC, bus::mmio::device::MmioCommonDevice, mm::paddr_to_vaddr, sync::SpinLock, + trap::IrqLine, }; const VIRTIO_MMIO_MAGIC: u32 = 0x74726976; diff --git a/framework/aster-frame/src/bus/pci/capability/msix.rs b/framework/aster-frame/src/bus/pci/capability/msix.rs index 36f3c0964..f6e9e588e 100644 --- a/framework/aster-frame/src/bus/pci/capability/msix.rs +++ b/framework/aster-frame/src/bus/pci/capability/msix.rs @@ -13,8 +13,8 @@ use crate::{ common_device::PciCommonDevice, device_info::PciDeviceLocation, }, + mm::VmIo, trap::IrqLine, - vm::VmIo, }; /// MSI-X capability. It will set the BAR space it uses to be hidden. diff --git a/framework/aster-frame/src/collections/xarray.rs b/framework/aster-frame/src/collections/xarray.rs index 6416ef6e2..7fadbf3d6 100644 --- a/framework/aster-frame/src/collections/xarray.rs +++ b/framework/aster-frame/src/collections/xarray.rs @@ -5,4 +5,4 @@ extern crate xarray as xarray_crate; pub use xarray_crate::{Cursor, CursorMut, XArray, XMark}; -pub use crate::vm::page::VmFrameRef; +pub use crate::mm::page::VmFrameRef; diff --git a/framework/aster-frame/src/error.rs b/framework/aster-frame/src/error.rs index eeef63875..2cb0725bf 100644 --- a/framework/aster-frame/src/error.rs +++ b/framework/aster-frame/src/error.rs @@ -1,6 +1,6 @@ // SPDX-License-Identifier: MPL-2.0 -use crate::vm::page_table::PageTableError; +use crate::mm::page_table::PageTableError; /// The error type which is returned from the APIs of this crate. #[derive(Clone, Copy, PartialEq, Eq, Debug)] diff --git a/framework/aster-frame/src/io_mem.rs b/framework/aster-frame/src/io_mem.rs index 2c5b3b035..bf4b4bbf5 100644 --- a/framework/aster-frame/src/io_mem.rs +++ b/framework/aster-frame/src/io_mem.rs @@ -5,7 +5,7 @@ use core::{mem::size_of, ops::Range}; use pod::Pod; use crate::{ - vm::{kspace::LINEAR_MAPPING_BASE_VADDR, paddr_to_vaddr, HasPaddr, Paddr, Vaddr, VmIo}, + mm::{kspace::LINEAR_MAPPING_BASE_VADDR, paddr_to_vaddr, HasPaddr, Paddr, Vaddr, VmIo}, Error, Result, }; diff --git a/framework/aster-frame/src/lib.rs b/framework/aster-frame/src/lib.rs index 2d4b97d0f..8d0993fb2 100644 --- a/framework/aster-frame/src/lib.rs +++ b/framework/aster-frame/src/lib.rs @@ -38,13 +38,13 @@ pub mod cpu; mod error; pub mod io_mem; pub mod logger; +pub mod mm; pub mod panicking; pub mod prelude; pub mod sync; pub mod task; pub mod trap; pub mod user; -pub mod vm; #[cfg(feature = "intel_tdx")] use tdx_guest::init_tdx; @@ -64,20 +64,20 @@ pub fn init() { td_info.attributes ); - vm::heap_allocator::init(); + mm::heap_allocator::init(); boot::init(); - vm::page::allocator::init(); - let mut boot_pt = vm::get_boot_pt(); - let meta_pages = vm::init_page_meta(&mut boot_pt); - vm::misc_init(); + mm::page::allocator::init(); + let mut boot_pt = mm::get_boot_pt(); + let meta_pages = mm::init_page_meta(&mut boot_pt); + mm::misc_init(); trap::init(); arch::after_all_init(); bus::init(); - vm::kspace::init_kernel_page_table(boot_pt, meta_pages); + mm::kspace::init_kernel_page_table(boot_pt, meta_pages); invoke_ffi_init_funcs(); } diff --git a/framework/aster-frame/src/vm/dma/dma_coherent.rs b/framework/aster-frame/src/mm/dma/dma_coherent.rs similarity index 97% rename from framework/aster-frame/src/vm/dma/dma_coherent.rs rename to framework/aster-frame/src/mm/dma/dma_coherent.rs index e91ae0094..95273018a 100644 --- a/framework/aster-frame/src/vm/dma/dma_coherent.rs +++ b/framework/aster-frame/src/mm/dma/dma_coherent.rs @@ -11,11 +11,11 @@ use super::{check_and_insert_dma_mapping, remove_dma_mapping, DmaError, HasDaddr use crate::arch::tdx_guest; use crate::{ arch::iommu, - vm::{ + mm::{ dma::{dma_type, Daddr, DmaType}, kspace::{paddr_to_vaddr, KERNEL_PAGE_TABLE}, page_prop::CachePolicy, - HasPaddr, Paddr, VmIo, VmReader, VmSegment, VmWriter, PAGE_SIZE, + HasPaddr, Paddr, Segment, VmIo, VmReader, VmWriter, PAGE_SIZE, }, }; @@ -32,7 +32,7 @@ pub struct DmaCoherent { #[derive(Debug)] struct DmaCoherentInner { - vm_segment: VmSegment, + vm_segment: Segment, start_daddr: Daddr, is_cache_coherent: bool, } @@ -47,7 +47,7 @@ impl DmaCoherent { /// /// The method fails if any part of the given VM segment /// already belongs to a DMA mapping. - pub fn map(vm_segment: VmSegment, is_cache_coherent: bool) -> Result { + pub fn map(vm_segment: Segment, is_cache_coherent: bool) -> Result { let frame_count = vm_segment.nframes(); let start_paddr = vm_segment.start_paddr(); if !check_and_insert_dma_mapping(start_paddr, frame_count) { @@ -109,7 +109,7 @@ impl HasDaddr for DmaCoherent { } impl Deref for DmaCoherent { - type Target = VmSegment; + type Target = Segment; fn deref(&self) -> &Self::Target { &self.inner.vm_segment } @@ -190,7 +190,7 @@ mod test { use alloc::vec; use super::*; - use crate::vm::VmAllocOptions; + use crate::mm::VmAllocOptions; #[ktest] fn map_with_coherent_device() { diff --git a/framework/aster-frame/src/vm/dma/dma_stream.rs b/framework/aster-frame/src/mm/dma/dma_stream.rs similarity index 97% rename from framework/aster-frame/src/vm/dma/dma_stream.rs rename to framework/aster-frame/src/mm/dma/dma_stream.rs index f41b7cac7..e55299a57 100644 --- a/framework/aster-frame/src/vm/dma/dma_stream.rs +++ b/framework/aster-frame/src/mm/dma/dma_stream.rs @@ -12,9 +12,9 @@ use crate::arch::tdx_guest; use crate::{ arch::iommu, error::Error, - vm::{ + mm::{ dma::{dma_type, Daddr, DmaType}, - HasPaddr, Paddr, VmIo, VmReader, VmSegment, VmWriter, PAGE_SIZE, + HasPaddr, Paddr, Segment, VmIo, VmReader, VmWriter, PAGE_SIZE, }, }; @@ -30,7 +30,7 @@ pub struct DmaStream { #[derive(Debug)] struct DmaStreamInner { - vm_segment: VmSegment, + vm_segment: Segment, start_daddr: Daddr, is_cache_coherent: bool, direction: DmaDirection, @@ -46,11 +46,11 @@ pub enum DmaDirection { } impl DmaStream { - /// Establish DMA stream mapping for a given `VmSegment`. + /// Establish DMA stream mapping for a given `Segment`. /// /// The method fails if the segment already belongs to a DMA mapping. pub fn map( - vm_segment: VmSegment, + vm_segment: Segment, direction: DmaDirection, is_cache_coherent: bool, ) -> Result { @@ -104,7 +104,7 @@ impl DmaStream { /// after the DMA mapping is established because /// there is a chance that the device is updating /// the memory. Do this at your own risk. - pub fn vm_segment(&self) -> &VmSegment { + pub fn vm_segment(&self) -> &Segment { &self.inner.vm_segment } @@ -294,7 +294,7 @@ mod test { use alloc::vec; use super::*; - use crate::vm::VmAllocOptions; + use crate::mm::VmAllocOptions; #[ktest] fn streaming_map() { diff --git a/framework/aster-frame/src/vm/dma/mod.rs b/framework/aster-frame/src/mm/dma/mod.rs similarity index 97% rename from framework/aster-frame/src/vm/dma/mod.rs rename to framework/aster-frame/src/mm/dma/mod.rs index 7d5c22f34..73ebc6cfc 100644 --- a/framework/aster-frame/src/vm/dma/mod.rs +++ b/framework/aster-frame/src/mm/dma/mod.rs @@ -11,7 +11,7 @@ use inherit_methods_macro::inherit_methods; use spin::Once; use super::Paddr; -use crate::{arch::iommu::has_iommu, sync::SpinLock, vm::PAGE_SIZE}; +use crate::{arch::iommu::has_iommu, mm::PAGE_SIZE, sync::SpinLock}; /// If a device performs DMA to read or write system /// memory, the addresses used by the device are device addresses. diff --git a/framework/aster-frame/src/vm/heap_allocator.rs b/framework/aster-frame/src/mm/heap_allocator.rs similarity index 98% rename from framework/aster-frame/src/vm/heap_allocator.rs rename to framework/aster-frame/src/mm/heap_allocator.rs index 0947e4889..02e612fb8 100644 --- a/framework/aster-frame/src/vm/heap_allocator.rs +++ b/framework/aster-frame/src/mm/heap_allocator.rs @@ -11,10 +11,10 @@ use log::debug; use super::paddr_to_vaddr; use crate::{ + mm::{page::allocator::FRAME_ALLOCATOR, PAGE_SIZE}, prelude::*, sync::SpinLock, trap::disable_local, - vm::{page::allocator::FRAME_ALLOCATOR, PAGE_SIZE}, Error, }; diff --git a/framework/aster-frame/src/vm/io.rs b/framework/aster-frame/src/mm/io.rs similarity index 99% rename from framework/aster-frame/src/vm/io.rs rename to framework/aster-frame/src/mm/io.rs index 618b9d07d..278985d91 100644 --- a/framework/aster-frame/src/vm/io.rs +++ b/framework/aster-frame/src/mm/io.rs @@ -9,7 +9,7 @@ use pod::Pod; use crate::prelude::*; /// A trait that enables reading/writing data from/to a VM object, -/// e.g., `VmSpace`, `VmFrameVec`, and `VmFrame`. +/// e.g., `VmSpace`, `VmFrameVec`, and `Frame`. /// /// # Concurrency /// diff --git a/framework/aster-frame/src/vm/kspace.rs b/framework/aster-frame/src/mm/kspace.rs similarity index 99% rename from framework/aster-frame/src/vm/kspace.rs rename to framework/aster-frame/src/mm/kspace.rs index 7d20e97a2..5fd0ef013 100644 --- a/framework/aster-frame/src/vm/kspace.rs +++ b/framework/aster-frame/src/mm/kspace.rs @@ -76,7 +76,7 @@ const KERNEL_CODE_BASE_VADDR: usize = 0xffff_ffff_8000_0000 << ADDR_WIDTH_SHIFT; const FRAME_METADATA_CAP_VADDR: Vaddr = 0xffff_e100_0000_0000 << ADDR_WIDTH_SHIFT; const FRAME_METADATA_BASE_VADDR: Vaddr = 0xffff_e000_0000_0000 << ADDR_WIDTH_SHIFT; -pub(in crate::vm) const FRAME_METADATA_RANGE: Range = +pub(in crate::mm) const FRAME_METADATA_RANGE: Range = FRAME_METADATA_BASE_VADDR..FRAME_METADATA_CAP_VADDR; const VMALLOC_BASE_VADDR: Vaddr = 0xffff_c000_0000_0000 << ADDR_WIDTH_SHIFT; diff --git a/framework/aster-frame/src/vm/mod.rs b/framework/aster-frame/src/mm/mod.rs similarity index 98% rename from framework/aster-frame/src/vm/mod.rs rename to framework/aster-frame/src/mm/mod.rs index 64c4c1944..cee2bd68b 100644 --- a/framework/aster-frame/src/vm/mod.rs +++ b/framework/aster-frame/src/mm/mod.rs @@ -28,7 +28,7 @@ pub use self::{ dma::{Daddr, DmaCoherent, DmaDirection, DmaStream, DmaStreamSlice, HasDaddr}, io::{VmIo, VmReader, VmWriter}, options::VmAllocOptions, - page::{FrameVecIter, VmFrame, VmFrameVec, VmSegment}, + page::{Frame, FrameVecIter, Segment, VmFrameVec}, page_prop::{CachePolicy, PageFlags, PageProperty}, space::{VmMapOptions, VmSpace}, }; diff --git a/framework/aster-frame/src/vm/offset.rs b/framework/aster-frame/src/mm/offset.rs similarity index 100% rename from framework/aster-frame/src/vm/offset.rs rename to framework/aster-frame/src/mm/offset.rs diff --git a/framework/aster-frame/src/vm/options.rs b/framework/aster-frame/src/mm/options.rs similarity index 94% rename from framework/aster-frame/src/vm/options.rs rename to framework/aster-frame/src/mm/options.rs index ca4aad47b..1069705df 100644 --- a/framework/aster-frame/src/vm/options.rs +++ b/framework/aster-frame/src/mm/options.rs @@ -1,6 +1,6 @@ // SPDX-License-Identifier: MPL-2.0 -use super::{page::allocator, VmFrame, VmFrameVec, VmSegment}; +use super::{page::allocator, Frame, Segment, VmFrameVec}; use crate::{prelude::*, Error}; /// Options for allocating physical memory pages (or frames). @@ -66,7 +66,7 @@ impl VmAllocOptions { } /// Allocate a single page frame according to the given options. - pub fn alloc_single(&self) -> Result { + pub fn alloc_single(&self) -> Result { if self.nframes != 1 { return Err(Error::InvalidArgs); } @@ -81,8 +81,8 @@ impl VmAllocOptions { /// Allocate a contiguous range of page frames according to the given options. /// - /// The returned `VmSegment` contains at least one page frame. - pub fn alloc_contiguous(&self) -> Result { + /// The returned `Segment` contains at least one page frame. + pub fn alloc_contiguous(&self) -> Result { // It's no use to checking `self.is_contiguous` here. if self.nframes == 0 { return Err(Error::InvalidArgs); diff --git a/framework/aster-frame/src/vm/page/allocator.rs b/framework/aster-frame/src/mm/page/allocator.rs similarity index 85% rename from framework/aster-frame/src/vm/page/allocator.rs rename to framework/aster-frame/src/mm/page/allocator.rs index bfe927aef..12aed71a7 100644 --- a/framework/aster-frame/src/vm/page/allocator.rs +++ b/framework/aster-frame/src/mm/page/allocator.rs @@ -7,10 +7,10 @@ use buddy_system_allocator::FrameAllocator; use log::info; use spin::Once; -use super::{meta::FrameMeta, Page, VmFrame, VmFrameVec, VmSegment}; -use crate::{boot::memory_region::MemoryRegionType, sync::SpinLock, vm::PAGE_SIZE}; +use super::{meta::FrameMeta, Frame, Page, Segment, VmFrameVec}; +use crate::{boot::memory_region::MemoryRegionType, mm::PAGE_SIZE, sync::SpinLock}; -pub(in crate::vm) static FRAME_ALLOCATOR: Once> = Once::new(); +pub(in crate::mm) static FRAME_ALLOCATOR: Once> = Once::new(); pub(crate) fn alloc(nframes: usize) -> Option { FRAME_ALLOCATOR @@ -23,7 +23,7 @@ pub(crate) fn alloc(nframes: usize) -> Option { for i in 0..nframes { let paddr = (start + i) * PAGE_SIZE; // SAFETY: The frame index is valid. - let frame = VmFrame { + let frame = Frame { page: Page::::from_unused(paddr).unwrap(), }; vector.push(frame); @@ -32,16 +32,16 @@ pub(crate) fn alloc(nframes: usize) -> Option { }) } -pub(crate) fn alloc_single() -> Option { +pub(crate) fn alloc_single() -> Option { FRAME_ALLOCATOR.get().unwrap().lock().alloc(1).map(|idx| { let paddr = idx * PAGE_SIZE; - VmFrame { + Frame { page: Page::::from_unused(paddr).unwrap(), } }) } -pub(crate) fn alloc_contiguous(nframes: usize) -> Option { +pub(crate) fn alloc_contiguous(nframes: usize) -> Option { FRAME_ALLOCATOR .get() .unwrap() @@ -50,7 +50,7 @@ pub(crate) fn alloc_contiguous(nframes: usize) -> Option { .map(|start| // SAFETY: The range of page frames is contiguous and valid. unsafe { - VmSegment::new( + Segment::new( start * PAGE_SIZE, nframes, ) diff --git a/framework/aster-frame/src/vm/page/frame.rs b/framework/aster-frame/src/mm/page/frame.rs similarity index 78% rename from framework/aster-frame/src/vm/page/frame.rs rename to framework/aster-frame/src/mm/page/frame.rs index ee87f856e..aae4379ea 100644 --- a/framework/aster-frame/src/vm/page/frame.rs +++ b/framework/aster-frame/src/mm/page/frame.rs @@ -8,7 +8,7 @@ use super::{ Page, }; use crate::{ - vm::{ + mm::{ io::{VmIo, VmReader, VmWriter}, paddr_to_vaddr, HasPaddr, Paddr, PagingLevel, PAGE_SIZE, }, @@ -17,30 +17,25 @@ use crate::{ /// A handle to a page frame. /// -/// The referenced page frame could either be huge or regular, which can be -/// told by the [`VmFrame::size`] method. It is ensured that there would be -/// only one TLB entry for such a frame if it is mapped to a virtual address -/// and the architecture supports huge TLB entries. -/// -/// An instance of `VmFrame` is a handle to a page frame (a physical memory -/// page). A cloned `VmFrame` refers to the same page frame as the original. +/// An instance of `Frame` is a handle to a page frame (a physical memory +/// page). A cloned `Frame` refers to the same page frame as the original. /// As the original and cloned instances point to the same physical address, /// they are treated as equal to each other. Behind the scene, a reference /// counter is maintained for each page frame so that when all instances of -/// `VmFrame` that refer to the same page frame are dropped, the page frame +/// `Frame` that refer to the same page frame are dropped, the page frame /// will be globally freed. #[derive(Debug, Clone)] -pub struct VmFrame { - pub(in crate::vm) page: Page, +pub struct Frame { + pub(in crate::mm) page: Page, } -impl HasPaddr for VmFrame { +impl HasPaddr for Frame { fn paddr(&self) -> Paddr { self.start_paddr() } } -impl VmFrame { +impl Frame { /// Returns the physical address of the page frame. pub fn start_paddr(&self) -> Paddr { self.page.paddr() @@ -73,7 +68,7 @@ impl VmFrame { paddr_to_vaddr(self.start_paddr()) as *mut u8 } - pub fn copy_from(&self, src: &VmFrame) { + pub fn copy_from(&self, src: &Frame) { if self.paddr() == src.paddr() { return; } @@ -84,7 +79,7 @@ impl VmFrame { } } -impl<'a> VmFrame { +impl<'a> Frame { /// Returns a reader to read data from it. pub fn reader(&'a self) -> VmReader<'a> { // SAFETY: the memory of the page is contiguous and is valid during `'a`. @@ -98,7 +93,7 @@ impl<'a> VmFrame { } } -impl VmIo for VmFrame { +impl VmIo for Frame { fn read_bytes(&self, offset: usize, buf: &mut [u8]) -> Result<()> { // Do bound check with potential integer overflow in mind let max_offset = offset.checked_add(buf.len()).ok_or(Error::Overflow)?; @@ -134,23 +129,23 @@ impl PageMeta for FrameMeta { use core::{marker::PhantomData, ops::Deref}; -/// `VmFrameRef` is a struct that can work as `&'a VmFrame`. +/// `VmFrameRef` is a struct that can work as `&'a Frame`. pub struct VmFrameRef<'a> { - inner: ManuallyDrop, - _marker: PhantomData<&'a VmFrame>, + inner: ManuallyDrop, + _marker: PhantomData<&'a Frame>, } impl<'a> Deref for VmFrameRef<'a> { - type Target = VmFrame; + type Target = Frame; fn deref(&self) -> &Self::Target { &self.inner } } -// SAFETY: `VmFrame` is essentially an `*const FrameMeta` that could be used as a `*const` pointer. +// SAFETY: `Frame` is essentially an `*const FrameMeta` that could be used as a `*const` pointer. // The pointer is also aligned to 4. -unsafe impl xarray::ItemEntry for VmFrame { +unsafe impl xarray::ItemEntry for Frame { type Ref<'a> = VmFrameRef<'a> where Self: 'a; fn into_raw(self) -> *const () { @@ -165,7 +160,7 @@ unsafe impl xarray::ItemEntry for VmFrame { unsafe fn raw_as_ref<'a>(raw: *const ()) -> Self::Ref<'a> { Self::Ref { - inner: ManuallyDrop::new(VmFrame::from_raw(raw)), + inner: ManuallyDrop::new(Frame::from_raw(raw)), _marker: PhantomData, } } diff --git a/framework/aster-frame/src/vm/page/meta.rs b/framework/aster-frame/src/mm/page/meta.rs similarity index 99% rename from framework/aster-frame/src/vm/page/meta.rs rename to framework/aster-frame/src/mm/page/meta.rs index 70fba8a46..3c32e083c 100644 --- a/framework/aster-frame/src/vm/page/meta.rs +++ b/framework/aster-frame/src/mm/page/meta.rs @@ -9,7 +9,7 @@ pub mod mapping { use core::mem::size_of; use super::MetaSlot; - use crate::vm::{kspace::FRAME_METADATA_RANGE, Paddr, PagingConstsTrait, Vaddr, PAGE_SIZE}; + use crate::mm::{kspace::FRAME_METADATA_RANGE, Paddr, PagingConstsTrait, Vaddr, PAGE_SIZE}; /// Convert a physical address of a base page to the virtual address of the metadata slot. pub const fn page_to_meta(paddr: Paddr) -> Vaddr { @@ -40,7 +40,7 @@ use static_assertions::const_assert_eq; use super::Page; use crate::{ arch::mm::{PageTableEntry, PagingConsts}, - vm::{ + mm::{ paddr_to_vaddr, page::allocator::FRAME_ALLOCATOR, page_size, diff --git a/framework/aster-frame/src/vm/page/mod.rs b/framework/aster-frame/src/mm/page/mod.rs similarity index 93% rename from framework/aster-frame/src/vm/page/mod.rs rename to framework/aster-frame/src/mm/page/mod.rs index 9a6d44002..e3ebe12b2 100644 --- a/framework/aster-frame/src/vm/page/mod.rs +++ b/framework/aster-frame/src/mm/page/mod.rs @@ -11,10 +11,10 @@ //! address space of the users are backed by frames. pub(crate) mod allocator; -pub(in crate::vm) mod meta; +pub(in crate::mm) mod meta; use meta::{mapping, MetaSlot, PageMeta}; mod frame; -pub use frame::{VmFrame, VmFrameRef}; +pub use frame::{Frame, VmFrameRef}; mod vm_frame_vec; pub use vm_frame_vec::{FrameVecIter, VmFrameVec}; mod segment; @@ -23,10 +23,10 @@ use core::{ sync::atomic::{AtomicU32, AtomicUsize, Ordering}, }; -pub use segment::VmSegment; +pub use segment::Segment; use super::PAGE_SIZE; -use crate::vm::{paddr_to_vaddr, Paddr, PagingConsts, Vaddr}; +use crate::mm::{paddr_to_vaddr, Paddr, PagingConsts, Vaddr}; static MAX_PADDR: AtomicUsize = AtomicUsize::new(0); @@ -54,7 +54,7 @@ pub enum PageHandleError { impl Page { /// Convert an unused page to a `Page` handle for a specific usage. - pub(in crate::vm) fn from_unused(paddr: Paddr) -> Result { + pub(in crate::mm) fn from_unused(paddr: Paddr) -> Result { if paddr % PAGE_SIZE != 0 { return Err(PageHandleError::NotAligned); } @@ -100,7 +100,7 @@ impl Page { /// /// Also, the caller ensures that the usage of the page is correct. There's /// no checking of the usage in this function. - pub(in crate::vm) unsafe fn restore(paddr: Paddr) -> Self { + pub(in crate::mm) unsafe fn restore(paddr: Paddr) -> Self { let vaddr = mapping::page_to_meta::(paddr); let ptr = vaddr as *const MetaSlot; @@ -118,7 +118,7 @@ impl Page { /// # Safety /// /// The safety requirements are the same as [`Page::restore`]. - pub(in crate::vm) unsafe fn clone_restore(paddr: &Paddr) -> Self { + pub(in crate::mm) unsafe fn clone_restore(paddr: &Paddr) -> Self { let vaddr = mapping::page_to_meta::(*paddr); let ptr = vaddr as *const MetaSlot; @@ -158,7 +158,7 @@ impl Page { /// # Safety /// /// The caller should be sure that the page is exclusively owned. - pub(in crate::vm) unsafe fn meta_mut(&mut self) -> &mut M { + pub(in crate::mm) unsafe fn meta_mut(&mut self) -> &mut M { unsafe { &mut *(self.ptr as *mut M) } } diff --git a/framework/aster-frame/src/vm/page/segment.rs b/framework/aster-frame/src/mm/page/segment.rs similarity index 86% rename from framework/aster-frame/src/vm/page/segment.rs rename to framework/aster-frame/src/mm/page/segment.rs index 2a2f7081d..c394b6889 100644 --- a/framework/aster-frame/src/vm/page/segment.rs +++ b/framework/aster-frame/src/mm/page/segment.rs @@ -5,19 +5,19 @@ use core::ops::Range; use super::{ allocator, meta::{PageMeta, PageUsage, SegmentHeadMeta}, - Page, VmFrame, + Frame, Page, }; use crate::{ - vm::{HasPaddr, Paddr, VmIo, VmReader, VmWriter, PAGE_SIZE}, + mm::{HasPaddr, Paddr, VmIo, VmReader, VmWriter, PAGE_SIZE}, Error, Result, }; /// A handle to a contiguous range of page frames (physical memory pages). /// -/// The biggest difference between `VmSegment` and `VmFrameVec` is that -/// the page frames must be contiguous for `VmSegment`. +/// The biggest difference between `Segment` and `VmFrameVec` is that +/// the page frames must be contiguous for `Segment`. /// -/// A cloned `VmSegment` refers to the same page frames as the original. +/// A cloned `Segment` refers to the same page frames as the original. /// As the original and cloned instances point to the same physical address, /// they are treated as equal to each other. /// @@ -30,25 +30,25 @@ use crate::{ /// vm_segment.write_bytes(0, buf)?; /// ``` #[derive(Debug, Clone)] -pub struct VmSegment { +pub struct Segment { head_page: Page, range: Range, } -impl HasPaddr for VmSegment { +impl HasPaddr for Segment { fn paddr(&self) -> Paddr { self.start_paddr() } } -impl VmSegment { - /// Creates a new `VmSegment`. +impl Segment { + /// Creates a new `Segment`. /// /// # Safety /// /// The given range of page frames must be contiguous and valid for use. /// The given range of page frames must not have been allocated before, - /// as part of either a `VmFrame` or `VmSegment`. + /// as part of either a `Frame` or `Segment`. pub(crate) unsafe fn new(paddr: Paddr, nframes: usize) -> Self { let mut head = Page::::from_unused(paddr).unwrap(); head.meta_mut().seg_len = (nframes * PAGE_SIZE) as u64; @@ -58,11 +58,11 @@ impl VmSegment { } } - /// Returns a part of the `VmSegment`. + /// Returns a part of the `Segment`. /// /// # Panic /// - /// If `range` is not within the range of this `VmSegment`, + /// If `range` is not within the range of this `Segment`, /// then the method panics. pub fn range(&self, range: Range) -> Self { let orig_range = &self.range; @@ -108,7 +108,7 @@ impl VmSegment { } } -impl<'a> VmSegment { +impl<'a> Segment { /// Returns a reader to read data from it. pub fn reader(&'a self) -> VmReader<'a> { // SAFETY: the memory of the page frames is contiguous and is valid during `'a`. @@ -122,7 +122,7 @@ impl<'a> VmSegment { } } -impl VmIo for VmSegment { +impl VmIo for Segment { fn read_bytes(&self, offset: usize, buf: &mut [u8]) -> Result<()> { // Do bound check with potential integer overflow in mind let max_offset = offset.checked_add(buf.len()).ok_or(Error::Overflow)?; @@ -156,8 +156,8 @@ impl PageMeta for SegmentHeadMeta { } } -impl From for VmSegment { - fn from(frame: VmFrame) -> Self { +impl From for Segment { + fn from(frame: Frame) -> Self { Self { head_page: frame.page.into(), range: 0..1, diff --git a/framework/aster-frame/src/vm/page/vm_frame_vec.rs b/framework/aster-frame/src/mm/page/vm_frame_vec.rs similarity index 87% rename from framework/aster-frame/src/vm/page/vm_frame_vec.rs rename to framework/aster-frame/src/mm/page/vm_frame_vec.rs index f3babb91c..64e34552b 100644 --- a/framework/aster-frame/src/vm/page/vm_frame_vec.rs +++ b/framework/aster-frame/src/mm/page/vm_frame_vec.rs @@ -3,26 +3,26 @@ use alloc::{vec, vec::Vec}; use crate::{ - vm::{VmFrame, VmIo, VmReader, VmWriter, PAGE_SIZE}, + mm::{Frame, VmIo, VmReader, VmWriter, PAGE_SIZE}, Error, Result, }; /// A collection of base page frames (regular physical memory pages). /// -/// For the most parts, `VmFrameVec` is like `Vec`. But the +/// For the most parts, `VmFrameVec` is like `Vec`. But the /// implementation may or may not be based on `Vec`. Having a dedicated /// type to represent a series of page frames is convenient because, /// more often than not, one needs to operate on a batch of frames rather /// a single frame. #[derive(Debug, Clone)] -pub struct VmFrameVec(pub(crate) Vec); +pub struct VmFrameVec(pub(crate) Vec); impl VmFrameVec { - pub fn get(&self, index: usize) -> Option<&VmFrame> { + pub fn get(&self, index: usize) -> Option<&Frame> { self.0.get(index) } - /// returns an empty VmFrame vec + /// returns an empty Frame vec pub fn empty() -> Self { Self(Vec::new()) } @@ -32,17 +32,17 @@ impl VmFrameVec { } /// Pushs a new frame to the collection. - pub fn push(&mut self, new_frame: VmFrame) { + pub fn push(&mut self, new_frame: Frame) { self.0.push(new_frame); } /// Pop a frame from the collection. - pub fn pop(&mut self) -> Option { + pub fn pop(&mut self) -> Option { self.0.pop() } /// Removes a frame at a position. - pub fn remove(&mut self, at: usize) -> VmFrame { + pub fn remove(&mut self, at: usize) -> Frame { self.0.remove(at) } @@ -63,7 +63,7 @@ impl VmFrameVec { } /// Returns an iterator - pub fn iter(&self) -> core::slice::Iter<'_, VmFrame> { + pub fn iter(&self) -> core::slice::Iter<'_, Frame> { self.0.iter() } @@ -84,13 +84,13 @@ impl VmFrameVec { self.0.len() * PAGE_SIZE } - pub fn from_one_frame(frame: VmFrame) -> Self { + pub fn from_one_frame(frame: Frame) -> Self { Self(vec![frame]) } } impl IntoIterator for VmFrameVec { - type Item = VmFrame; + type Item = Frame; type IntoIter = alloc::vec::IntoIter; @@ -154,7 +154,7 @@ impl<'a> FrameVecIter<'a> { } impl<'a> Iterator for FrameVecIter<'a> { - type Item = &'a VmFrame; + type Item = &'a Frame; fn next(&mut self) -> Option { if self.current >= self.frames.0.len() { diff --git a/framework/aster-frame/src/vm/page_prop.rs b/framework/aster-frame/src/mm/page_prop.rs similarity index 100% rename from framework/aster-frame/src/vm/page_prop.rs rename to framework/aster-frame/src/mm/page_prop.rs diff --git a/framework/aster-frame/src/vm/page_table/boot_pt.rs b/framework/aster-frame/src/mm/page_table/boot_pt.rs similarity index 97% rename from framework/aster-frame/src/vm/page_table/boot_pt.rs rename to framework/aster-frame/src/mm/page_table/boot_pt.rs index f5019a918..142c7f9ec 100644 --- a/framework/aster-frame/src/vm/page_table/boot_pt.rs +++ b/framework/aster-frame/src/mm/page_table/boot_pt.rs @@ -9,7 +9,7 @@ use alloc::vec::Vec; use super::{pte_index, PageTableEntryTrait}; use crate::{ arch::mm::{PageTableEntry, PagingConsts}, - vm::{ + mm::{ paddr_to_vaddr, page::allocator::FRAME_ALLOCATOR, PageProperty, PagingConstsTrait, Vaddr, PAGE_SIZE, }, @@ -26,7 +26,7 @@ pub struct BootPageTable< > { root_pt: FrameNumber, // The frames allocated for this page table are not tracked with - // metadata [`crate::vm::frame::meta`]. Here is a record of it + // metadata [`crate::mm::frame::meta`]. Here is a record of it // for deallocation. frames: Vec, _pretend_to_use: core::marker::PhantomData<(E, C)>, @@ -101,7 +101,7 @@ fn test_boot_pt() { use super::page_walk; use crate::{ arch::mm::{PageTableEntry, PagingConsts}, - vm::{CachePolicy, PageFlags, VmAllocOptions}, + mm::{CachePolicy, PageFlags, VmAllocOptions}, }; let root_frame = VmAllocOptions::new(1).alloc_single().unwrap(); diff --git a/framework/aster-frame/src/vm/page_table/cursor.rs b/framework/aster-frame/src/mm/page_table/cursor.rs similarity index 97% rename from framework/aster-frame/src/vm/page_table/cursor.rs rename to framework/aster-frame/src/mm/page_table/cursor.rs index 190daf16f..0de8a39c1 100644 --- a/framework/aster-frame/src/vm/page_table/cursor.rs +++ b/framework/aster-frame/src/mm/page_table/cursor.rs @@ -56,9 +56,9 @@ use align_ext::AlignExt; use super::{ page_size, pte_index, Child, KernelMode, PageTable, PageTableEntryTrait, PageTableError, - PageTableFrame, PageTableMode, PagingConstsTrait, PagingLevel, + PageTableMode, PageTableNode, PagingConstsTrait, PagingLevel, }; -use crate::vm::{Paddr, PageProperty, Vaddr, VmFrame}; +use crate::mm::{Frame, Paddr, PageProperty, Vaddr}; #[derive(Clone, Debug)] pub(crate) enum PageTableQueryResult { @@ -68,7 +68,7 @@ pub(crate) enum PageTableQueryResult { }, Mapped { va: Vaddr, - frame: VmFrame, + frame: Frame, prop: PageProperty, }, MappedUntracked { @@ -94,7 +94,7 @@ where [(); C::NR_LEVELS as usize]:, { pt: &'a PageTable, - guards: [Option>; C::NR_LEVELS as usize], + guards: [Option>; C::NR_LEVELS as usize], level: PagingLevel, // current level guard_level: PagingLevel, // from guard_level to level, the locks are held va: Vaddr, // current virtual address @@ -246,7 +246,7 @@ where } } - fn cur_node(&self) -> &PageTableFrame { + fn cur_node(&self) -> &PageTableNode { self.guards[(C::NR_LEVELS - self.level) as usize] .as_ref() .unwrap() @@ -267,7 +267,7 @@ where /// Tell if the current virtual range must contain untracked mappings. /// - /// In the kernel mode, this is aligned with the definition in [`crate::vm::kspace`]. + /// In the kernel mode, this is aligned with the definition in [`crate::mm::kspace`]. /// Only linear mappings in the kernel are considered as untracked mappings. /// /// All mappings in the user mode are tracked. And all mappings in the IOMMU @@ -275,7 +275,7 @@ where fn in_untracked_range(&self) -> bool { TypeId::of::() == TypeId::of::() || TypeId::of::() == TypeId::of::() - && !crate::vm::kspace::VMALLOC_VADDR_RANGE.contains(&self.va) + && !crate::mm::kspace::VMALLOC_VADDR_RANGE.contains(&self.va) } } @@ -385,7 +385,7 @@ where } } - /// Map the range starting from the current address to a `VmFrame`. + /// Map the range starting from the current address to a `Frame`. /// /// # Panic /// @@ -398,7 +398,7 @@ where /// /// The caller should ensure that the virtual range being mapped does /// not affect kernel's memory safety. - pub(crate) unsafe fn map(&mut self, frame: VmFrame, prop: PageProperty) { + pub(crate) unsafe fn map(&mut self, frame: Frame, prop: PageProperty) { let end = self.0.va + frame.size(); assert!(end <= self.0.barrier_va.end); debug_assert!(!self.0.in_untracked_range()); @@ -599,7 +599,7 @@ where /// Consume itself and leak the root guard for the caller if it locked the root level. /// /// It is useful when the caller wants to keep the root guard while the cursor should be dropped. - pub(super) fn leak_root_guard(mut self) -> Option> { + pub(super) fn leak_root_guard(mut self) -> Option> { if self.0.guard_level != C::NR_LEVELS { return None; } @@ -616,7 +616,7 @@ where /// This method will create a new child frame and go down to it. fn level_down_create(&mut self) { debug_assert!(self.0.level > 1); - let new_frame = PageTableFrame::::alloc(self.0.level - 1); + let new_frame = PageTableNode::::alloc(self.0.level - 1); let idx = self.0.cur_idx(); let untracked = self.0.in_untracked_range(); self.cur_node_mut() @@ -640,7 +640,7 @@ where self.0.guards[(C::NR_LEVELS - self.0.level) as usize] = Some(new_frame.lock()); } - fn cur_node_mut(&mut self) -> &mut PageTableFrame { + fn cur_node_mut(&mut self) -> &mut PageTableNode { self.0.guards[(C::NR_LEVELS - self.0.level) as usize] .as_mut() .unwrap() diff --git a/framework/aster-frame/src/vm/page_table/frame.rs b/framework/aster-frame/src/mm/page_table/frame.rs similarity index 94% rename from framework/aster-frame/src/vm/page_table/frame.rs rename to framework/aster-frame/src/mm/page_table/frame.rs index 2a1221c21..6aa3fdf2c 100644 --- a/framework/aster-frame/src/vm/page_table/frame.rs +++ b/framework/aster-frame/src/mm/page_table/frame.rs @@ -28,7 +28,7 @@ use core::{marker::PhantomData, mem::ManuallyDrop, ops::Range, panic, sync::atom use super::{nr_subpage_per_huge, page_size, PageTableEntryTrait}; use crate::{ arch::mm::{PageTableEntry, PagingConsts}, - vm::{ + mm::{ paddr_to_vaddr, page::{ allocator::FRAME_ALLOCATOR, @@ -36,7 +36,7 @@ use crate::{ Page, }, page_prop::PageProperty, - Paddr, PagingConstsTrait, PagingLevel, VmFrame, PAGE_SIZE, + Frame, Paddr, PagingConstsTrait, PagingLevel, PAGE_SIZE, }, }; @@ -47,9 +47,9 @@ use crate::{ /// the page table frame and subsequent children will be freed. /// /// Only the CPU or a PTE can access a page table frame using a raw handle. To access the page -/// table frame from the kernel code, use the handle [`PageTableFrame`]. +/// table frame from the kernel code, use the handle [`PageTableNode`]. #[derive(Debug)] -pub(super) struct RawPageTableFrame +pub(super) struct RawPageTableNode where [(); C::NR_LEVELS as usize]:, { @@ -58,7 +58,7 @@ where _phantom: PhantomData<(E, C)>, } -impl RawPageTableFrame +impl RawPageTableNode where [(); C::NR_LEVELS as usize]:, { @@ -67,7 +67,7 @@ where } /// Convert a raw handle to an accessible handle by pertaining the lock. - pub(super) fn lock(self) -> PageTableFrame { + pub(super) fn lock(self) -> PageTableNode { let page = unsafe { Page::>::restore(self.paddr()) }; debug_assert!(page.meta().level == self.level); // Acquire the lock. @@ -81,7 +81,7 @@ where } // Prevent dropping the handle. let _ = ManuallyDrop::new(self); - PageTableFrame:: { page } + PageTableNode:: { page } } /// Create a copy of the handle. @@ -116,7 +116,7 @@ where use crate::{ arch::mm::{activate_page_table, current_page_table_paddr}, - vm::CachePolicy, + mm::CachePolicy, }; debug_assert_eq!(self.level, PagingConsts::NR_LEVELS); @@ -137,7 +137,7 @@ where // Decrement the reference count of the last activated page table. - // Boot page tables are not tracked with [`PageTableFrame`], but + // Boot page tables are not tracked with [`PageTableNode`], but // all page tables after the boot stage are tracked. // // TODO: the `cpu_local` implementation currently is underpowered, @@ -158,7 +158,7 @@ where } } -impl Drop for RawPageTableFrame +impl Drop for RawPageTableNode where [(); C::NR_LEVELS as usize]:, { @@ -175,7 +175,7 @@ where /// table frame has no references. You can set the page table frame as a child of another /// page table frame. #[derive(Debug)] -pub(super) struct PageTableFrame< +pub(super) struct PageTableNode< E: PageTableEntryTrait = PageTableEntry, C: PagingConstsTrait = PagingConsts, > where @@ -190,14 +190,14 @@ pub(super) enum Child), - Frame(VmFrame), + PageTable(RawPageTableNode), + Frame(Frame), /// Frames not tracked by handles. Untracked(Paddr), None, } -impl PageTableFrame +impl PageTableNode where [(); C::NR_LEVELS as usize]:, { @@ -227,12 +227,12 @@ where } /// Convert the handle into a raw handle to be stored in a PTE or CPU. - pub(super) fn into_raw(self) -> RawPageTableFrame { + pub(super) fn into_raw(self) -> RawPageTableNode { let level = self.level(); let raw = self.page.paddr(); self.page.meta().lock.store(0, Ordering::Release); core::mem::forget(self); - RawPageTableFrame { + RawPageTableNode { raw, level, _phantom: PhantomData, @@ -240,9 +240,9 @@ where } /// Get a raw handle while still preserving the original handle. - pub(super) fn clone_raw(&self) -> RawPageTableFrame { + pub(super) fn clone_raw(&self) -> RawPageTableNode { core::mem::forget(self.page.clone()); - RawPageTableFrame { + RawPageTableNode { raw: self.page.paddr(), level: self.level(), _phantom: PhantomData, @@ -261,7 +261,7 @@ where core::mem::forget(unsafe { Page::>::clone_restore(&paddr) }); - Child::PageTable(RawPageTableFrame { + Child::PageTable(RawPageTableNode { raw: paddr, level: self.level() - 1, _phantom: PhantomData, @@ -269,7 +269,7 @@ where } else if tracked { let page = unsafe { Page::::restore(paddr) }; core::mem::forget(page.clone()); - Child::Frame(VmFrame { page }) + Child::Frame(Frame { page }) } else { Child::Untracked(paddr) } @@ -335,7 +335,7 @@ where pub(super) fn set_child_pt( &mut self, idx: usize, - pt: RawPageTableFrame, + pt: RawPageTableNode, in_untracked_range: bool, ) { // They should be ensured by the cursor. @@ -348,7 +348,7 @@ where } /// Map a frame at a given index. - pub(super) fn set_child_frame(&mut self, idx: usize, frame: VmFrame, prop: PageProperty) { + pub(super) fn set_child_frame(&mut self, idx: usize, frame: Frame, prop: PageProperty) { // They should be ensured by the cursor. debug_assert!(idx < nr_subpage_per_huge::()); debug_assert_eq!(frame.level(), self.level()); @@ -391,7 +391,7 @@ where panic!("`split_untracked_huge` not called on an untracked huge page"); }; let prop = self.read_pte_prop(idx); - let mut new_frame = PageTableFrame::::alloc(self.level() - 1); + let mut new_frame = PageTableNode::::alloc(self.level() - 1); for i in 0..nr_subpage_per_huge::() { let small_pa = pa + i * page_size::(self.level() - 1); unsafe { new_frame.set_child_untracked(i, small_pa, prop) }; @@ -467,7 +467,7 @@ where } } -impl Drop for PageTableFrame +impl Drop for PageTableNode where [(); C::NR_LEVELS as usize]:, { diff --git a/framework/aster-frame/src/vm/page_table/mod.rs b/framework/aster-frame/src/mm/page_table/mod.rs similarity index 98% rename from framework/aster-frame/src/vm/page_table/mod.rs rename to framework/aster-frame/src/mm/page_table/mod.rs index c37272d91..2278dbe23 100644 --- a/framework/aster-frame/src/vm/page_table/mod.rs +++ b/framework/aster-frame/src/mm/page_table/mod.rs @@ -18,7 +18,7 @@ pub(crate) use cursor::{Cursor, CursorMut, PageTableQueryResult}; #[cfg(ktest)] mod test; -pub(in crate::vm) mod boot_pt; +pub(in crate::mm) mod boot_pt; #[derive(Clone, Copy, PartialEq, Eq, Debug)] pub enum PageTableError { @@ -82,7 +82,7 @@ pub(crate) struct PageTable< > where [(); C::NR_LEVELS as usize]:, { - root: RawPageTableFrame, + root: RawPageTableNode, _phantom: PhantomData, } @@ -160,7 +160,7 @@ impl PageTable { let mut root_frame = self.root.copy_handle().lock(); for i in start..end { if !root_frame.read_pte(i).is_present() { - let frame = PageTableFrame::alloc(PagingConsts::NR_LEVELS - 1); + let frame = PageTableNode::alloc(PagingConsts::NR_LEVELS - 1); root_frame.set_child_pt(i, frame.into_raw(), i < NR_PTES_PER_NODE * 3 / 4); } } @@ -174,7 +174,7 @@ where /// Create a new empty page table. Useful for the kernel page table and IOMMU page tables only. pub(crate) fn empty() -> Self { PageTable { - root: PageTableFrame::::alloc(C::NR_LEVELS).into_raw(), + root: PageTableNode::::alloc(C::NR_LEVELS).into_raw(), _phantom: PhantomData, } } diff --git a/framework/aster-frame/src/vm/page_table/test.rs b/framework/aster-frame/src/mm/page_table/test.rs similarity index 98% rename from framework/aster-frame/src/vm/page_table/test.rs rename to framework/aster-frame/src/mm/page_table/test.rs index 211fdb2ed..fa149a1e9 100644 --- a/framework/aster-frame/src/vm/page_table/test.rs +++ b/framework/aster-frame/src/mm/page_table/test.rs @@ -3,7 +3,7 @@ use core::mem::ManuallyDrop; use super::*; -use crate::vm::{ +use crate::mm::{ kspace::LINEAR_MAPPING_BASE_VADDR, page_prop::{CachePolicy, PageFlags}, VmAllocOptions, @@ -43,7 +43,7 @@ fn test_tracked_map_unmap() { #[ktest] fn test_untracked_map_unmap() { let pt = PageTable::::empty(); - const UNTRACKED_OFFSET: usize = crate::vm::kspace::LINEAR_MAPPING_BASE_VADDR; + const UNTRACKED_OFFSET: usize = crate::mm::kspace::LINEAR_MAPPING_BASE_VADDR; let from_ppn = 13245..512 * 512 + 23456; let to_ppn = from_ppn.start - 11010..from_ppn.end - 11010; @@ -172,7 +172,7 @@ impl PagingConstsTrait for VeryHugePagingConsts { #[ktest] fn test_untracked_large_protect_query() { let pt = PageTable::::empty(); - const UNTRACKED_OFFSET: usize = crate::vm::kspace::LINEAR_MAPPING_BASE_VADDR; + const UNTRACKED_OFFSET: usize = crate::mm::kspace::LINEAR_MAPPING_BASE_VADDR; let gmult = 512 * 512; let from_ppn = gmult - 512..gmult + gmult + 514; diff --git a/framework/aster-frame/src/vm/space.rs b/framework/aster-frame/src/mm/space.rs similarity index 98% rename from framework/aster-frame/src/vm/space.rs rename to framework/aster-frame/src/mm/space.rs index d6e0828b0..7819eeba9 100644 --- a/framework/aster-frame/src/vm/space.rs +++ b/framework/aster-frame/src/mm/space.rs @@ -13,11 +13,11 @@ use crate::{ arch::mm::{ tlb_flush_addr_range, tlb_flush_all_excluding_global, PageTableEntry, PagingConsts, }, - prelude::*, - vm::{ + mm::{ page_table::{Cursor, PageTableQueryResult as PtQr}, - VmFrame, MAX_USERSPACE_VADDR, + Frame, MAX_USERSPACE_VADDR, }, + prelude::*, Error, }; @@ -31,7 +31,7 @@ use crate::{ /// /// A newly-created `VmSpace` is not backed by any physical memory pages. /// To provide memory pages for a `VmSpace`, one can allocate and map -/// physical memory (`VmFrame`s) to the `VmSpace`. +/// physical memory (`Frame`s) to the `VmSpace`. #[derive(Debug)] pub struct VmSpace { pt: PageTable, @@ -103,7 +103,7 @@ impl VmSpace { }; for frame in frames.into_iter() { - // SAFETY: mapping in the user space with `VmFrame` is safe. + // SAFETY: mapping in the user space with `Frame` is safe. unsafe { cursor.map(frame, prop); } @@ -299,7 +299,7 @@ pub enum VmQueryResult { }, Mapped { va: Vaddr, - frame: VmFrame, + frame: Frame, prop: PageProperty, }, } diff --git a/framework/aster-frame/src/prelude.rs b/framework/aster-frame/src/prelude.rs index 739caa5b2..3f2bab9db 100644 --- a/framework/aster-frame/src/prelude.rs +++ b/framework/aster-frame/src/prelude.rs @@ -11,6 +11,6 @@ pub use aster_main::aster_main; pub use crate::{ early_print as print, early_println as println, + mm::{Paddr, Vaddr}, panicking::abort, - vm::{Paddr, Vaddr}, }; diff --git a/framework/aster-frame/src/task/task.rs b/framework/aster-frame/src/task/task.rs index c6e5d79e4..9d4d45d8d 100644 --- a/framework/aster-frame/src/task/task.rs +++ b/framework/aster-frame/src/task/task.rs @@ -12,10 +12,10 @@ use super::{ pub(crate) use crate::arch::task::{context_switch, TaskContext}; use crate::{ cpu::CpuSet, + mm::{kspace::KERNEL_PAGE_TABLE, PageFlags, Segment, VmAllocOptions, PAGE_SIZE}, prelude::*, sync::{SpinLock, SpinLockGuard}, user::UserSpace, - vm::{kspace::KERNEL_PAGE_TABLE, PageFlags, VmAllocOptions, VmSegment, PAGE_SIZE}, }; pub const KERNEL_STACK_SIZE: usize = PAGE_SIZE * 64; @@ -35,7 +35,7 @@ pub trait TaskContextApi { } pub struct KernelStack { - segment: VmSegment, + segment: Segment, has_guard_page: bool, } @@ -56,7 +56,7 @@ impl KernelStack { let page_table = KERNEL_PAGE_TABLE.get().unwrap(); let guard_page_vaddr = { let guard_page_paddr = stack_segment.start_paddr(); - crate::vm::paddr_to_vaddr(guard_page_paddr) + crate::mm::paddr_to_vaddr(guard_page_paddr) }; // SAFETY: the segment allocated is not used by others so we can protect it. unsafe { @@ -84,7 +84,7 @@ impl Drop for KernelStack { let page_table = KERNEL_PAGE_TABLE.get().unwrap(); let guard_page_vaddr = { let guard_page_paddr = self.segment.start_paddr(); - crate::vm::paddr_to_vaddr(guard_page_paddr) + crate::mm::paddr_to_vaddr(guard_page_paddr) }; // SAFETY: the segment allocated is not used by others so we can protect it. unsafe { @@ -293,7 +293,7 @@ impl TaskOptions { // to at least 16 bytes. And a larger alignment is needed if larger arguments // are passed to the function. The `kernel_task_entry` function does not // have any arguments, so we only need to align the stack pointer to 16 bytes. - ctx.set_stack_pointer(crate::vm::paddr_to_vaddr(new_task.kstack.end_paddr() - 16)); + ctx.set_stack_pointer(crate::mm::paddr_to_vaddr(new_task.kstack.end_paddr() - 16)); Ok(Arc::new(new_task)) } diff --git a/framework/aster-frame/src/user.rs b/framework/aster-frame/src/user.rs index 0c50c94dc..a7a919ae2 100644 --- a/framework/aster-frame/src/user.rs +++ b/framework/aster-frame/src/user.rs @@ -4,7 +4,7 @@ use trapframe::TrapFrame; -use crate::{cpu::UserContext, prelude::*, task::Task, vm::VmSpace}; +use crate::{cpu::UserContext, mm::VmSpace, prelude::*, task::Task}; /// A user space. /// diff --git a/kernel/aster-nix/src/device/tty/driver.rs b/kernel/aster-nix/src/device/tty/driver.rs index d4ececf35..3ec1e8ee8 100644 --- a/kernel/aster-nix/src/device/tty/driver.rs +++ b/kernel/aster-nix/src/device/tty/driver.rs @@ -1,7 +1,7 @@ // SPDX-License-Identifier: MPL-2.0 pub use aster_frame::arch::console; -use aster_frame::vm::VmReader; +use aster_frame::mm::VmReader; use spin::Once; use crate::{ diff --git a/kernel/aster-nix/src/fs/exfat/dentry.rs b/kernel/aster-nix/src/fs/exfat/dentry.rs index 63d7bbe8c..8dee44714 100644 --- a/kernel/aster-nix/src/fs/exfat/dentry.rs +++ b/kernel/aster-nix/src/fs/exfat/dentry.rs @@ -2,7 +2,7 @@ use core::ops::Range; -use aster_frame::vm::VmIo; +use aster_frame::mm::VmIo; use aster_rights::Full; use super::{ diff --git a/kernel/aster-nix/src/fs/exfat/fs.rs b/kernel/aster-nix/src/fs/exfat/fs.rs index d38ca7b1a..8ed3ad3ed 100644 --- a/kernel/aster-nix/src/fs/exfat/fs.rs +++ b/kernel/aster-nix/src/fs/exfat/fs.rs @@ -3,8 +3,8 @@ use core::{num::NonZeroUsize, ops::Range, sync::atomic::AtomicU64}; use aster_block::{bio::BioWaiter, id::BlockId, BlockDevice}; -use aster_frame::vm::VmFrame; -pub(super) use aster_frame::vm::VmIo; +use aster_frame::mm::Frame; +pub(super) use aster_frame::mm::VmIo; use hashbrown::HashMap; use lru::LruCache; @@ -361,7 +361,7 @@ impl ExfatFS { } impl PageCacheBackend for ExfatFS { - fn read_page(&self, idx: usize, frame: &VmFrame) -> Result { + fn read_page(&self, idx: usize, frame: &Frame) -> Result { if self.fs_size() < idx * PAGE_SIZE { return_errno_with_message!(Errno::EINVAL, "invalid read size") } @@ -371,7 +371,7 @@ impl PageCacheBackend for ExfatFS { Ok(waiter) } - fn write_page(&self, idx: usize, frame: &VmFrame) -> Result { + fn write_page(&self, idx: usize, frame: &Frame) -> Result { if self.fs_size() < idx * PAGE_SIZE { return_errno_with_message!(Errno::EINVAL, "invalid write size") } diff --git a/kernel/aster-nix/src/fs/exfat/inode.rs b/kernel/aster-nix/src/fs/exfat/inode.rs index f75c90058..aee1e2349 100644 --- a/kernel/aster-nix/src/fs/exfat/inode.rs +++ b/kernel/aster-nix/src/fs/exfat/inode.rs @@ -9,7 +9,7 @@ use aster_block::{ id::{Bid, BlockId}, BLOCK_SIZE, }; -use aster_frame::vm::{VmAllocOptions, VmFrame, VmIo}; +use aster_frame::mm::{Frame, VmAllocOptions, VmIo}; use aster_rights::Full; use super::{ @@ -132,7 +132,7 @@ struct ExfatInodeInner { } impl PageCacheBackend for ExfatInode { - fn read_page(&self, idx: usize, frame: &VmFrame) -> Result { + fn read_page(&self, idx: usize, frame: &Frame) -> Result { let inner = self.inner.read(); if inner.size < idx * PAGE_SIZE { return_errno_with_message!(Errno::EINVAL, "Invalid read size") @@ -145,7 +145,7 @@ impl PageCacheBackend for ExfatInode { Ok(waiter) } - fn write_page(&self, idx: usize, frame: &VmFrame) -> Result { + fn write_page(&self, idx: usize, frame: &Frame) -> Result { let inner = self.inner.read(); let sector_size = inner.fs().sector_size(); diff --git a/kernel/aster-nix/src/fs/exfat/mod.rs b/kernel/aster-nix/src/fs/exfat/mod.rs index c83a9f3fc..0bd5af9a9 100644 --- a/kernel/aster-nix/src/fs/exfat/mod.rs +++ b/kernel/aster-nix/src/fs/exfat/mod.rs @@ -21,7 +21,7 @@ mod test { bio::{BioEnqueueError, BioStatus, BioType, SubmittedBio}, BlockDevice, }; - use aster_frame::vm::{VmAllocOptions, VmIo, VmSegment}; + use aster_frame::mm::{Segment, VmAllocOptions, VmIo}; use rand::{rngs::SmallRng, RngCore, SeedableRng}; use crate::{ @@ -37,10 +37,10 @@ mod test { /// Followings are implementations of memory simulated block device pub const SECTOR_SIZE: usize = 512; - struct ExfatMemoryBioQueue(VmSegment); + struct ExfatMemoryBioQueue(Segment); impl ExfatMemoryBioQueue { - pub fn new(segment: VmSegment) -> Self { + pub fn new(segment: Segment) -> Self { ExfatMemoryBioQueue(segment) } @@ -54,7 +54,7 @@ mod test { } impl ExfatMemoryDisk { - pub fn new(segment: VmSegment) -> Self { + pub fn new(segment: Segment) -> Self { ExfatMemoryDisk { queue: ExfatMemoryBioQueue::new(segment), } @@ -100,7 +100,7 @@ mod test { static EXFAT_IMAGE: &[u8] = include_bytes!("../../../../../regression/build/exfat.img"); /// Read exfat disk image - fn new_vm_segment_from_image() -> VmSegment { + fn new_vm_segment_from_image() -> Segment { let vm_segment = { VmAllocOptions::new(EXFAT_IMAGE.len() / PAGE_SIZE) .is_contiguous(true) diff --git a/kernel/aster-nix/src/fs/ext2/block_group.rs b/kernel/aster-nix/src/fs/ext2/block_group.rs index b21cdc1a0..5a33086d6 100644 --- a/kernel/aster-nix/src/fs/ext2/block_group.rs +++ b/kernel/aster-nix/src/fs/ext2/block_group.rs @@ -28,7 +28,7 @@ struct BlockGroupImpl { impl BlockGroup { /// Loads and constructs a block group. pub fn load( - group_descriptors_segment: &VmSegment, + group_descriptors_segment: &Segment, idx: usize, block_device: &dyn BlockDevice, super_block: &SuperBlock, @@ -318,12 +318,12 @@ impl Debug for BlockGroup { } impl PageCacheBackend for BlockGroupImpl { - fn read_page(&self, idx: usize, frame: &VmFrame) -> Result { + fn read_page(&self, idx: usize, frame: &Frame) -> Result { let bid = self.inode_table_bid + idx as Ext2Bid; self.fs.upgrade().unwrap().read_block_async(bid, frame) } - fn write_page(&self, idx: usize, frame: &VmFrame) -> Result { + fn write_page(&self, idx: usize, frame: &Frame) -> Result { let bid = self.inode_table_bid + idx as Ext2Bid; self.fs.upgrade().unwrap().write_block_async(bid, frame) } diff --git a/kernel/aster-nix/src/fs/ext2/fs.rs b/kernel/aster-nix/src/fs/ext2/fs.rs index f11ecb69e..69594998e 100644 --- a/kernel/aster-nix/src/fs/ext2/fs.rs +++ b/kernel/aster-nix/src/fs/ext2/fs.rs @@ -21,7 +21,7 @@ pub struct Ext2 { blocks_per_group: Ext2Bid, inode_size: usize, block_size: usize, - group_descriptors_segment: VmSegment, + group_descriptors_segment: Segment, self_ref: Weak, } @@ -55,7 +55,7 @@ impl Ext2 { // Load the block groups information let load_block_groups = |fs: Weak, block_device: &dyn BlockDevice, - group_descriptors_segment: &VmSegment| + group_descriptors_segment: &Segment| -> Result> { let block_groups_count = super_block.block_groups_count() as usize; let mut block_groups = Vec::with_capacity(block_groups_count); @@ -291,7 +291,7 @@ impl Ext2 { } /// Reads contiguous blocks starting from the `bid` synchronously. - pub(super) fn read_blocks(&self, bid: Ext2Bid, segment: &VmSegment) -> Result<()> { + pub(super) fn read_blocks(&self, bid: Ext2Bid, segment: &Segment) -> Result<()> { let status = self .block_device .read_blocks_sync(Bid::new(bid as u64), segment)?; @@ -302,7 +302,7 @@ impl Ext2 { } /// Reads one block indicated by the `bid` synchronously. - pub(super) fn read_block(&self, bid: Ext2Bid, frame: &VmFrame) -> Result<()> { + pub(super) fn read_block(&self, bid: Ext2Bid, frame: &Frame) -> Result<()> { let status = self .block_device .read_block_sync(Bid::new(bid as u64), frame)?; @@ -313,13 +313,13 @@ impl Ext2 { } /// Reads one block indicated by the `bid` asynchronously. - pub(super) fn read_block_async(&self, bid: Ext2Bid, frame: &VmFrame) -> Result { + pub(super) fn read_block_async(&self, bid: Ext2Bid, frame: &Frame) -> Result { let waiter = self.block_device.read_block(Bid::new(bid as u64), frame)?; Ok(waiter) } /// Writes contiguous blocks starting from the `bid` synchronously. - pub(super) fn write_blocks(&self, bid: Ext2Bid, segment: &VmSegment) -> Result<()> { + pub(super) fn write_blocks(&self, bid: Ext2Bid, segment: &Segment) -> Result<()> { let status = self .block_device .write_blocks_sync(Bid::new(bid as u64), segment)?; @@ -330,7 +330,7 @@ impl Ext2 { } /// Writes one block indicated by the `bid` synchronously. - pub(super) fn write_block(&self, bid: Ext2Bid, frame: &VmFrame) -> Result<()> { + pub(super) fn write_block(&self, bid: Ext2Bid, frame: &Frame) -> Result<()> { let status = self .block_device .write_block_sync(Bid::new(bid as u64), frame)?; @@ -341,7 +341,7 @@ impl Ext2 { } /// Writes one block indicated by the `bid` asynchronously. - pub(super) fn write_block_async(&self, bid: Ext2Bid, frame: &VmFrame) -> Result { + pub(super) fn write_block_async(&self, bid: Ext2Bid, frame: &Frame) -> Result { let waiter = self.block_device.write_block(Bid::new(bid as u64), frame)?; Ok(waiter) } diff --git a/kernel/aster-nix/src/fs/ext2/indirect_block_cache.rs b/kernel/aster-nix/src/fs/ext2/indirect_block_cache.rs index dc6b3261b..f6247b4eb 100644 --- a/kernel/aster-nix/src/fs/ext2/indirect_block_cache.rs +++ b/kernel/aster-nix/src/fs/ext2/indirect_block_cache.rs @@ -124,7 +124,7 @@ impl IndirectBlockCache { /// Represents a single indirect block buffer cached by the `IndirectCache`. #[derive(Clone, Debug)] pub struct IndirectBlock { - frame: VmFrame, + frame: Frame, state: State, } diff --git a/kernel/aster-nix/src/fs/ext2/inode.rs b/kernel/aster-nix/src/fs/ext2/inode.rs index 7fcba9859..9c6907a78 100644 --- a/kernel/aster-nix/src/fs/ext2/inode.rs +++ b/kernel/aster-nix/src/fs/ext2/inode.rs @@ -838,7 +838,7 @@ impl InodeImpl_ { self.inode().fs() } - pub fn read_block_async(&self, bid: Ext2Bid, block: &VmFrame) -> Result { + pub fn read_block_async(&self, bid: Ext2Bid, block: &Frame) -> Result { if bid >= self.desc.blocks_count() { return_errno!(Errno::EINVAL); } @@ -852,14 +852,14 @@ impl InodeImpl_ { self.fs().read_block_async(device_range.start, block) } - pub fn read_block_sync(&self, bid: Ext2Bid, block: &VmFrame) -> Result<()> { + pub fn read_block_sync(&self, bid: Ext2Bid, block: &Frame) -> Result<()> { match self.read_block_async(bid, block)?.wait() { Some(BioStatus::Complete) => Ok(()), _ => return_errno!(Errno::EIO), } } - pub fn write_block_async(&self, bid: Ext2Bid, block: &VmFrame) -> Result { + pub fn write_block_async(&self, bid: Ext2Bid, block: &Frame) -> Result { if bid >= self.desc.blocks_count() { return_errno!(Errno::EINVAL); } @@ -872,7 +872,7 @@ impl InodeImpl_ { Ok(waiter) } - pub fn write_block_sync(&self, bid: Ext2Bid, block: &VmFrame) -> Result<()> { + pub fn write_block_sync(&self, bid: Ext2Bid, block: &Frame) -> Result<()> { match self.write_block_async(bid, block)?.wait() { Some(BioStatus::Complete) => Ok(()), _ => return_errno!(Errno::EIO), @@ -1525,19 +1525,19 @@ impl InodeImpl { self.0.read().desc.ctime } - pub fn read_block_sync(&self, bid: Ext2Bid, block: &VmFrame) -> Result<()> { + pub fn read_block_sync(&self, bid: Ext2Bid, block: &Frame) -> Result<()> { self.0.read().read_block_sync(bid, block) } - pub fn read_block_async(&self, bid: Ext2Bid, block: &VmFrame) -> Result { + pub fn read_block_async(&self, bid: Ext2Bid, block: &Frame) -> Result { self.0.read().read_block_async(bid, block) } - pub fn write_block_sync(&self, bid: Ext2Bid, block: &VmFrame) -> Result<()> { + pub fn write_block_sync(&self, bid: Ext2Bid, block: &Frame) -> Result<()> { self.0.read().write_block_sync(bid, block) } - pub fn write_block_async(&self, bid: Ext2Bid, block: &VmFrame) -> Result { + pub fn write_block_async(&self, bid: Ext2Bid, block: &Frame) -> Result { self.0.read().write_block_async(bid, block) } @@ -1612,12 +1612,12 @@ impl InodeImpl { } impl PageCacheBackend for InodeImpl { - fn read_page(&self, idx: usize, frame: &VmFrame) -> Result { + fn read_page(&self, idx: usize, frame: &Frame) -> Result { let bid = idx as Ext2Bid; self.read_block_async(bid, frame) } - fn write_page(&self, idx: usize, frame: &VmFrame) -> Result { + fn write_page(&self, idx: usize, frame: &Frame) -> Result { let bid = idx as Ext2Bid; self.write_block_async(bid, frame) } diff --git a/kernel/aster-nix/src/fs/ext2/prelude.rs b/kernel/aster-nix/src/fs/ext2/prelude.rs index fe5e50975..18ee16867 100644 --- a/kernel/aster-nix/src/fs/ext2/prelude.rs +++ b/kernel/aster-nix/src/fs/ext2/prelude.rs @@ -12,8 +12,8 @@ pub(super) use aster_block::{ BlockDevice, BLOCK_SIZE, }; pub(super) use aster_frame::{ + mm::{Frame, Segment, VmAllocOptions, VmIo}, sync::{RwMutex, RwMutexReadGuard, RwMutexWriteGuard}, - vm::{VmAllocOptions, VmFrame, VmIo, VmSegment}, }; pub(super) use aster_rights::Full; pub(super) use static_assertions::const_assert; diff --git a/kernel/aster-nix/src/fs/ramfs/fs.rs b/kernel/aster-nix/src/fs/ramfs/fs.rs index 522a5968d..f9f618f12 100644 --- a/kernel/aster-nix/src/fs/ramfs/fs.rs +++ b/kernel/aster-nix/src/fs/ramfs/fs.rs @@ -7,8 +7,8 @@ use core::{ use aster_block::bio::BioWaiter; use aster_frame::{ + mm::{Frame, VmIo}, sync::RwMutexWriteGuard, - vm::{VmFrame, VmIo}, }; use aster_rights::Full; use aster_util::slot_vec::SlotVec; @@ -436,13 +436,13 @@ impl RamInode { } impl PageCacheBackend for RamInode { - fn read_page(&self, _idx: usize, frame: &VmFrame) -> Result { + fn read_page(&self, _idx: usize, frame: &Frame) -> Result { // Initially, any block/page in a RamFs inode contains all zeros frame.writer().fill(0); Ok(BioWaiter::new()) } - fn write_page(&self, _idx: usize, _frame: &VmFrame) -> Result { + fn write_page(&self, _idx: usize, _frame: &Frame) -> Result { // do nothing Ok(BioWaiter::new()) } diff --git a/kernel/aster-nix/src/fs/utils/page_cache.rs b/kernel/aster-nix/src/fs/utils/page_cache.rs index 4352561e7..8ad72e375 100644 --- a/kernel/aster-nix/src/fs/utils/page_cache.rs +++ b/kernel/aster-nix/src/fs/utils/page_cache.rs @@ -3,7 +3,7 @@ use core::ops::Range; use aster_block::bio::{BioStatus, BioWaiter}; -use aster_frame::vm::{VmAllocOptions, VmFrame}; +use aster_frame::mm::{Frame, VmAllocOptions}; use aster_rights::Full; use lru::LruCache; @@ -151,7 +151,7 @@ impl Debug for PageCacheManager { } impl Pager for PageCacheManager { - fn commit_page(&self, idx: usize) -> Result { + fn commit_page(&self, idx: usize) -> Result { if let Some(page) = self.pages.lock().get(&idx) { return Ok(page.frame.clone()); } @@ -202,7 +202,7 @@ impl Pager for PageCacheManager { #[derive(Debug)] struct Page { - frame: VmFrame, + frame: Frame, state: PageState, } @@ -223,7 +223,7 @@ impl Page { }) } - pub fn frame(&self) -> &VmFrame { + pub fn frame(&self) -> &Frame { &self.frame } @@ -252,16 +252,16 @@ enum PageState { /// This trait represents the backend for the page cache. pub trait PageCacheBackend: Sync + Send { /// Reads a page from the backend asynchronously. - fn read_page(&self, idx: usize, frame: &VmFrame) -> Result; + fn read_page(&self, idx: usize, frame: &Frame) -> Result; /// Writes a page to the backend asynchronously. - fn write_page(&self, idx: usize, frame: &VmFrame) -> Result; + fn write_page(&self, idx: usize, frame: &Frame) -> Result; /// Returns the number of pages in the backend. fn npages(&self) -> usize; } impl dyn PageCacheBackend { /// Reads a page from the backend synchronously. - fn read_page_sync(&self, idx: usize, frame: &VmFrame) -> Result<()> { + fn read_page_sync(&self, idx: usize, frame: &Frame) -> Result<()> { let waiter = self.read_page(idx, frame)?; match waiter.wait() { Some(BioStatus::Complete) => Ok(()), @@ -269,7 +269,7 @@ impl dyn PageCacheBackend { } } /// Writes a page to the backend synchronously. - fn write_page_sync(&self, idx: usize, frame: &VmFrame) -> Result<()> { + fn write_page_sync(&self, idx: usize, frame: &Frame) -> Result<()> { let waiter = self.write_page(idx, frame)?; match waiter.wait() { Some(BioStatus::Complete) => Ok(()), diff --git a/kernel/aster-nix/src/prelude.rs b/kernel/aster-nix/src/prelude.rs index 3a30f5c1a..1bc354704 100644 --- a/kernel/aster-nix/src/prelude.rs +++ b/kernel/aster-nix/src/prelude.rs @@ -14,8 +14,8 @@ pub(crate) use alloc::{ pub(crate) use core::{any::Any, ffi::CStr, fmt::Debug}; pub(crate) use aster_frame::{ + mm::{Vaddr, PAGE_SIZE}, sync::{Mutex, MutexGuard, RwLock, RwMutex, SpinLock, SpinLockGuard}, - vm::{Vaddr, PAGE_SIZE}, }; pub(crate) use bitflags::bitflags; pub(crate) use int_to_c_enum::TryFromInt; diff --git a/kernel/aster-nix/src/process/clone.rs b/kernel/aster-nix/src/process/clone.rs index 22141f31b..0d417d356 100644 --- a/kernel/aster-nix/src/process/clone.rs +++ b/kernel/aster-nix/src/process/clone.rs @@ -4,8 +4,8 @@ use core::sync::atomic::Ordering; use aster_frame::{ cpu::UserContext, + mm::VmIo, user::{UserContextApi, UserSpace}, - vm::VmIo, }; use aster_rights::Full; diff --git a/kernel/aster-nix/src/process/process_vm/init_stack/mod.rs b/kernel/aster-nix/src/process/process_vm/init_stack/mod.rs index e9b182b6c..18b1a3eb6 100644 --- a/kernel/aster-nix/src/process/process_vm/init_stack/mod.rs +++ b/kernel/aster-nix/src/process/process_vm/init_stack/mod.rs @@ -17,7 +17,7 @@ use core::{ }; use align_ext::AlignExt; -use aster_frame::vm::{VmIo, MAX_USERSPACE_VADDR}; +use aster_frame::mm::{VmIo, MAX_USERSPACE_VADDR}; use aster_rights::{Full, Rights}; use self::aux_vec::{AuxKey, AuxVec}; diff --git a/kernel/aster-nix/src/process/program_loader/elf/load_elf.rs b/kernel/aster-nix/src/process/program_loader/elf/load_elf.rs index f8ae19381..c310eafef 100644 --- a/kernel/aster-nix/src/process/program_loader/elf/load_elf.rs +++ b/kernel/aster-nix/src/process/program_loader/elf/load_elf.rs @@ -4,7 +4,7 @@ //! When create a process from elf file, we will use the elf_load_info to construct the VmSpace use align_ext::AlignExt; -use aster_frame::{task::Task, vm::VmIo}; +use aster_frame::{mm::VmIo, task::Task}; use aster_rights::{Full, Rights}; use xmas_elf::program::{self, ProgramHeader64}; diff --git a/kernel/aster-nix/src/syscall/rt_sigprocmask.rs b/kernel/aster-nix/src/syscall/rt_sigprocmask.rs index a7bb39244..a8c7ee156 100644 --- a/kernel/aster-nix/src/syscall/rt_sigprocmask.rs +++ b/kernel/aster-nix/src/syscall/rt_sigprocmask.rs @@ -1,6 +1,6 @@ // SPDX-License-Identifier: MPL-2.0 -use aster_frame::vm::VmIo; +use aster_frame::mm::VmIo; use super::SyscallReturn; use crate::{ diff --git a/kernel/aster-nix/src/util/mod.rs b/kernel/aster-nix/src/util/mod.rs index 4b9d09adc..718637731 100644 --- a/kernel/aster-nix/src/util/mod.rs +++ b/kernel/aster-nix/src/util/mod.rs @@ -2,7 +2,7 @@ use core::mem; -use aster_frame::vm::VmIo; +use aster_frame::mm::VmIo; use aster_rights::Full; use crate::{prelude::*, vm::vmar::Vmar}; diff --git a/kernel/aster-nix/src/util/net/options/utils.rs b/kernel/aster-nix/src/util/net/options/utils.rs index aadcd9fca..87d8a5164 100644 --- a/kernel/aster-nix/src/util/net/options/utils.rs +++ b/kernel/aster-nix/src/util/net/options/utils.rs @@ -2,7 +2,7 @@ use core::time::Duration; -use aster_frame::vm::VmIo; +use aster_frame::mm::VmIo; use aster_rights::Full; use crate::{ diff --git a/kernel/aster-nix/src/vdso.rs b/kernel/aster-nix/src/vdso.rs index a9eaa0943..a0a7dac0b 100644 --- a/kernel/aster-nix/src/vdso.rs +++ b/kernel/aster-nix/src/vdso.rs @@ -15,8 +15,8 @@ use alloc::{boxed::Box, sync::Arc}; use core::{mem::ManuallyDrop, time::Duration}; use aster_frame::{ + mm::{Frame, VmIo, PAGE_SIZE}, sync::SpinLock, - vm::{VmFrame, VmIo, PAGE_SIZE}, }; use aster_rights::Rights; use aster_time::{read_monotonic_time, Instant}; @@ -196,9 +196,9 @@ struct Vdso { data: SpinLock, /// The vmo of the entire VDSO, including the library text and the VDSO data. vmo: Arc, - /// The `VmFrame` that contains the VDSO data. This frame is contained in and + /// The `Frame` that contains the VDSO data. This frame is contained in and /// will not be removed from the VDSO vmo. - data_frame: VmFrame, + data_frame: Frame, } /// A `SpinLock` for the `seq` field in `VdsoData`. diff --git a/kernel/aster-nix/src/vm/perms.rs b/kernel/aster-nix/src/vm/perms.rs index 37180ff24..852db0bf6 100644 --- a/kernel/aster-nix/src/vm/perms.rs +++ b/kernel/aster-nix/src/vm/perms.rs @@ -1,6 +1,6 @@ // SPDX-License-Identifier: MPL-2.0 -use aster_frame::vm::PageFlags; +use aster_frame::mm::PageFlags; use aster_rights::Rights; use bitflags::bitflags; diff --git a/kernel/aster-nix/src/vm/vmar/dyn_cap.rs b/kernel/aster-nix/src/vm/vmar/dyn_cap.rs index 1a7a92321..101df672f 100644 --- a/kernel/aster-nix/src/vm/vmar/dyn_cap.rs +++ b/kernel/aster-nix/src/vm/vmar/dyn_cap.rs @@ -2,7 +2,7 @@ use core::ops::Range; -use aster_frame::vm::VmIo; +use aster_frame::mm::VmIo; use aster_rights::Rights; use super::{ @@ -26,8 +26,8 @@ impl Vmar { /// # Example /// /// ``` - /// use aster_std::prelude::*; - /// use aster_std::vm::{PAGE_SIZE, Vmar, VmoOptions}; + /// use aster_nix::prelude::*; + /// use aster_nix::vm::{PAGE_SIZE, Vmar, VmoOptions}; /// /// let vmar = Vmar::new().unwrap(); /// let vmo = VmoOptions::new(PAGE_SIZE).alloc().unwrap(); diff --git a/kernel/aster-nix/src/vm/vmar/mod.rs b/kernel/aster-nix/src/vm/vmar/mod.rs index 7c4b13801..f26da87ec 100644 --- a/kernel/aster-nix/src/vm/vmar/mod.rs +++ b/kernel/aster-nix/src/vm/vmar/mod.rs @@ -11,7 +11,7 @@ pub mod vm_mapping; use core::{cmp::min, ops::Range}; use align_ext::AlignExt; -use aster_frame::vm::{VmSpace, MAX_USERSPACE_VADDR}; +use aster_frame::mm::{VmSpace, MAX_USERSPACE_VADDR}; use aster_rights::Rights; use self::{ @@ -39,15 +39,6 @@ use crate::{prelude::*, vm::perms::VmPerms}; /// /// VMARs are implemented with two flavors of capabilities: /// the dynamic one (`Vmar`) and the static one (`Vmar). -/// -/// # Implementation -/// -/// `Vmar` provides high-level APIs for address space management by wrapping -/// around its low-level counterpart `_frame::vm::VmFrames`. -/// Compared with `VmFrames`, -/// `Vmar` is easier to use (by offering more powerful APIs) and -/// harder to misuse (thanks to its nature of being capability). -/// pub struct Vmar(Arc, R); pub trait VmarRightsOp { diff --git a/kernel/aster-nix/src/vm/vmar/options.rs b/kernel/aster-nix/src/vm/vmar/options.rs index dff8e658c..c37859bc4 100644 --- a/kernel/aster-nix/src/vm/vmar/options.rs +++ b/kernel/aster-nix/src/vm/vmar/options.rs @@ -2,7 +2,7 @@ //! Options for allocating child VMARs. -use aster_frame::{vm::PAGE_SIZE, Error, Result}; +use aster_frame::{mm::PAGE_SIZE, Error, Result}; use super::Vmar; @@ -14,7 +14,7 @@ use super::Vmar; /// A child VMAR created from a parent VMAR of _dynamic_ capability is also a /// _dynamic_ capability. /// ``` -/// use aster_std::vm::{PAGE_SIZE, Vmar}; +/// use aster_nix::vm::{PAGE_SIZE, Vmar}; /// /// let parent_vmar = Vmar::new(); /// let child_size = 10 * PAGE_SIZE; @@ -29,8 +29,8 @@ use super::Vmar; /// A child VMAR created from a parent VMAR of _static_ capability is also a /// _static_ capability. /// ``` -/// use aster_std::prelude::*; -/// use aster_std::vm::{PAGE_SIZE, Vmar}; +/// use aster_nix::prelude::*; +/// use aster_nix::vm::{PAGE_SIZE, Vmar}; /// /// let parent_vmar: Vmar = Vmar::new(); /// let child_size = 10 * PAGE_SIZE; @@ -135,7 +135,7 @@ impl VmarChildOptions { #[cfg(ktest)] mod test { - use aster_frame::vm::VmIo; + use aster_frame::mm::VmIo; use aster_rights::Full; use super::*; diff --git a/kernel/aster-nix/src/vm/vmar/static_cap.rs b/kernel/aster-nix/src/vm/vmar/static_cap.rs index 14aab5124..eee6e1a4b 100644 --- a/kernel/aster-nix/src/vm/vmar/static_cap.rs +++ b/kernel/aster-nix/src/vm/vmar/static_cap.rs @@ -2,7 +2,7 @@ use core::ops::Range; -use aster_frame::vm::VmIo; +use aster_frame::mm::VmIo; use aster_rights::{Dup, Rights, TRightSet, TRights}; use aster_rights_proc::require; @@ -31,8 +31,8 @@ impl Vmar> { /// # Example /// /// ``` - /// use aster_std::prelude::*; - /// use aster_std::vm::{PAGE_SIZE, Vmar, VmoOptions}; + /// use aster_nix::prelude::*; + /// use aster_nix::vm::{PAGE_SIZE, Vmar, VmoOptions}; /// /// let vmar = Vmar::>::new().unwrap(); /// let vmo = VmoOptions::new(PAGE_SIZE).alloc().unwrap(); diff --git a/kernel/aster-nix/src/vm/vmar/vm_mapping.rs b/kernel/aster-nix/src/vm/vmar/vm_mapping.rs index e57b6483a..256688f44 100644 --- a/kernel/aster-nix/src/vm/vmar/vm_mapping.rs +++ b/kernel/aster-nix/src/vm/vmar/vm_mapping.rs @@ -2,7 +2,7 @@ use core::ops::Range; -use aster_frame::vm::{PageFlags, VmFrame, VmFrameVec, VmIo, VmMapOptions, VmSpace}; +use aster_frame::mm::{Frame, PageFlags, VmFrameVec, VmIo, VmMapOptions, VmSpace}; use super::{interval::Interval, is_intersected, Vmar, Vmar_}; use crate::{ @@ -143,7 +143,7 @@ impl VmMapping { pub(super) fn map_one_page( &self, page_idx: usize, - frame: VmFrame, + frame: Frame, is_readonly: bool, ) -> Result<()> { let parent = self.parent.upgrade().unwrap(); @@ -458,7 +458,7 @@ impl VmMappingInner { vmo: &Vmo, vm_space: &VmSpace, page_idx: usize, - frame: VmFrame, + frame: Frame, is_readonly: bool, ) -> Result<()> { let map_addr = self.page_map_addr(page_idx); diff --git a/kernel/aster-nix/src/vm/vmo/dyn_cap.rs b/kernel/aster-nix/src/vm/vmo/dyn_cap.rs index 45fbe7a8b..c02d5c596 100644 --- a/kernel/aster-nix/src/vm/vmo/dyn_cap.rs +++ b/kernel/aster-nix/src/vm/vmo/dyn_cap.rs @@ -2,7 +2,7 @@ use core::ops::Range; -use aster_frame::vm::{VmFrame, VmIo}; +use aster_frame::mm::{Frame, VmIo}; use aster_rights::{Rights, TRights}; use super::{ @@ -68,7 +68,7 @@ impl Vmo { } /// commit a page at specific offset - pub fn commit_page(&self, offset: usize) -> Result { + pub fn commit_page(&self, offset: usize) -> Result { self.check_rights(Rights::WRITE)?; self.0.commit_page(offset, false) } diff --git a/kernel/aster-nix/src/vm/vmo/mod.rs b/kernel/aster-nix/src/vm/vmo/mod.rs index 34f9ce660..33ab70a6e 100644 --- a/kernel/aster-nix/src/vm/vmo/mod.rs +++ b/kernel/aster-nix/src/vm/vmo/mod.rs @@ -7,7 +7,7 @@ use core::ops::Range; use align_ext::AlignExt; use aster_frame::{ collections::xarray::{CursorMut, XArray, XMark}, - vm::{VmAllocOptions, VmFrame, VmReader, VmWriter}, + mm::{Frame, VmAllocOptions, VmReader, VmWriter}, }; use aster_rights::Rights; @@ -139,8 +139,8 @@ pub(super) enum VmoMark { /// The VMO whose `pages` is marked as `CowVmo` may require a Copy-On-Write (COW) operation /// when performing a write action. CowVmo, - /// Marks used for the `VmFrame` stored within the pages marked as `CowVmo`, - /// `VmFrame`s marked as `ExclusivePage` are newly created through the COW mechanism + /// Marks used for the `Frame` stored within the pages marked as `CowVmo`, + /// `Frame`s marked as `ExclusivePage` are newly created through the COW mechanism /// and do not require further COW operations. ExclusivePage, } @@ -154,19 +154,19 @@ impl From for XMark { } } -/// `Pages` is the struct that manages the `VmFrame`s stored in `Vmo_`. +/// `Pages` is the struct that manages the `Frame`s stored in `Vmo_`. pub(super) enum Pages { /// `Pages` that cannot be resized. This kind of `Pages` will have a constant size. - Nonresizable(Arc>>, usize), + Nonresizable(Arc>>, usize), /// `Pages` that can be resized and have a variable size, and such `Pages` cannot /// be shared between different VMOs. - Resizable(Mutex<(XArray, usize)>), + Resizable(Mutex<(XArray, usize)>), } impl Pages { fn with(&self, func: F) -> R where - F: FnOnce(&mut XArray, usize) -> R, + F: FnOnce(&mut XArray, usize) -> R, { match self { Self::Nonresizable(pages, size) => func(&mut pages.lock(), *size), @@ -194,14 +194,14 @@ pub(super) struct Vmo_ { pages: Pages, } -fn clone_page(page: &VmFrame) -> Result { +fn clone_page(page: &Frame) -> Result { let new_page = VmAllocOptions::new(1).alloc_single()?; new_page.copy_from(page); Ok(new_page) } impl Vmo_ { - /// Prepare a new `VmFrame` for the target index in pages, returning the new page as well as + /// Prepare a new `Frame` for the target index in pages, returning the new page as well as /// whether this page needs to be marked as exclusive. /// /// Based on the type of VMO and the impending operation on the prepared page, there are 3 conditions: @@ -216,7 +216,7 @@ impl Vmo_ { page_idx: usize, is_cow_vmo: bool, will_write: bool, - ) -> Result<(VmFrame, bool)> { + ) -> Result<(Frame, bool)> { let (page, should_mark_exclusive) = match &self.pager { None => { // Condition 1. The new anonymous page only need to be marked as `ExclusivePage` @@ -227,8 +227,8 @@ impl Vmo_ { let page = pager.commit_page(page_idx)?; // The prerequisite for triggering the COW mechanism here is that the current // VMO requires COW and the prepared page is about to undergo a write operation. - // At this point, the `VmFrame` obtained from the pager needs to be cloned to - // avoid subsequent modifications affecting the content of the `VmFrame` in the pager. + // At this point, the `Frame` obtained from the pager needs to be cloned to + // avoid subsequent modifications affecting the content of the `Frame` in the pager. let trigger_cow = is_cow_vmo && will_write; if trigger_cow { // Condition 3. @@ -244,10 +244,10 @@ impl Vmo_ { fn commit_with_cursor( &self, - cursor: &mut CursorMut<'_, VmFrame, VmoMark>, + cursor: &mut CursorMut<'_, Frame, VmoMark>, is_cow_vmo: bool, will_write: bool, - ) -> Result { + ) -> Result { let (new_page, is_exclusive) = { let is_exclusive = cursor.is_marked(VmoMark::ExclusivePage); if let Some(committed_page) = cursor.load() { @@ -276,7 +276,7 @@ impl Vmo_ { /// Commit the page corresponding to the target offset in the VMO and return that page. /// If the current offset has already been committed, the page will be returned directly. /// During the commit process, the Copy-On-Write (COW) mechanism may be triggered depending on the circumstances. - pub fn commit_page(&self, offset: usize, will_write: bool) -> Result { + pub fn commit_page(&self, offset: usize, will_write: bool) -> Result { let page_idx = offset / PAGE_SIZE + self.page_idx_offset; self.pages.with(|pages, size| { let is_cow_vmo = pages.is_marked(VmoMark::CowVmo); @@ -310,7 +310,7 @@ impl Vmo_ { will_write: bool, ) -> Result<()> where - F: FnMut(VmFrame), + F: FnMut(Frame), { self.pages.with(|pages, size| { if range.end > size { @@ -348,7 +348,7 @@ impl Vmo_ { let mut read_offset = offset % PAGE_SIZE; let mut buf_writer: VmWriter = buf.into(); - let read = move |page: VmFrame| { + let read = move |page: Frame| { page.reader().skip(read_offset).read(&mut buf_writer); read_offset = 0; }; @@ -363,7 +363,7 @@ impl Vmo_ { let mut write_offset = offset % PAGE_SIZE; let mut buf_reader: VmReader = buf.into(); - let write = move |page: VmFrame| { + let write = move |page: Frame| { page.writer().skip(write_offset).write(&mut buf_reader); write_offset = 0; }; @@ -518,7 +518,7 @@ impl Vmo_ { fn decommit_pages( &self, - pages: &mut XArray, + pages: &mut XArray, range: Range, ) -> Result<()> { let raw_page_idx_range = get_page_idx_range(&range); @@ -575,7 +575,7 @@ impl Vmo { self.0.is_page_committed(page_idx) } - pub fn get_committed_frame(&self, page_idx: usize, write_page: bool) -> Result { + pub fn get_committed_frame(&self, page_idx: usize, write_page: bool) -> Result { self.0.commit_page(page_idx * PAGE_SIZE, write_page) } diff --git a/kernel/aster-nix/src/vm/vmo/options.rs b/kernel/aster-nix/src/vm/vmo/options.rs index 34735982b..e12c342fc 100644 --- a/kernel/aster-nix/src/vm/vmo/options.rs +++ b/kernel/aster-nix/src/vm/vmo/options.rs @@ -7,7 +7,7 @@ use core::{marker::PhantomData, ops::Range}; use align_ext::AlignExt; use aster_frame::{ collections::xarray::XArray, - vm::{VmAllocOptions, VmFrame}, + mm::{Frame, VmAllocOptions}, }; use aster_rights::{Dup, Rights, TRightSet, TRights, Write}; use aster_rights_proc::require; @@ -22,7 +22,7 @@ use crate::{prelude::*, vm::vmo::Vmo_}; /// /// Creating a VMO as a _dynamic_ capability with full access rights: /// ``` -/// use aster_std::vm::{PAGE_SIZE, VmoOptions}; +/// use aster_nix::vm::{PAGE_SIZE, VmoOptions}; /// /// let vmo = VmoOptions::new(PAGE_SIZE) /// .alloc() @@ -31,8 +31,8 @@ use crate::{prelude::*, vm::vmo::Vmo_}; /// /// Creating a VMO as a _static_ capability with all access rights: /// ``` -/// use aster_std::prelude::*; -/// use aster_std::vm::{PAGE_SIZE, VmoOptions}; +/// use aster_nix::prelude::*; +/// use aster_nix::vm::{PAGE_SIZE, VmoOptions}; /// /// let vmo = VmoOptions::::new(PAGE_SIZE) /// .alloc() @@ -43,7 +43,7 @@ use crate::{prelude::*, vm::vmo::Vmo_}; /// physically contiguous: /// /// ``` -/// use aster_std::vm::{PAGE_SIZE, VmoOptions, VmoFlags}; +/// use aster_nix::vm::{PAGE_SIZE, VmoOptions, VmoFlags}; /// /// let vmo = VmoOptions::new(10 * PAGE_SIZE) /// .flags(VmoFlags::RESIZABLE) @@ -140,7 +140,7 @@ fn alloc_vmo_(size: usize, flags: VmoFlags, pager: Option>) -> Re }) } -fn committed_pages_if_continuous(flags: VmoFlags, size: usize) -> Result> { +fn committed_pages_if_continuous(flags: VmoFlags, size: usize) -> Result> { if flags.contains(VmoFlags::CONTIGUOUS) { // if the vmo is continuous, we need to allocate frames for the vmo let frames_num = size / PAGE_SIZE; @@ -168,7 +168,7 @@ fn committed_pages_if_continuous(flags: VmoFlags, size: usize) -> Result Result = VmoOptions::new(PAGE_SIZE) /// .alloc() @@ -200,7 +200,7 @@ fn committed_pages_if_continuous(flags: VmoFlags, size: usize) -> Result Result::new(PAGE_SIZE) /// .alloc() @@ -231,7 +231,7 @@ fn committed_pages_if_continuous(flags: VmoFlags, size: usize) -> Result Result; + fn commit_page(&self, idx: usize) -> Result; /// Notify the pager that the frame at a specified index has been updated. /// diff --git a/kernel/aster-nix/src/vm/vmo/static_cap.rs b/kernel/aster-nix/src/vm/vmo/static_cap.rs index bb4d4679e..cc0b77d96 100644 --- a/kernel/aster-nix/src/vm/vmo/static_cap.rs +++ b/kernel/aster-nix/src/vm/vmo/static_cap.rs @@ -2,7 +2,7 @@ use core::ops::Range; -use aster_frame::vm::{VmFrame, VmIo}; +use aster_frame::mm::{Frame, VmIo}; use aster_rights::{Dup, Rights, TRightSet, TRights, Write}; use aster_rights_proc::require; @@ -68,7 +68,7 @@ impl Vmo> { } /// commit a page at specific offset - pub fn commit_page(&self, offset: usize) -> Result { + pub fn commit_page(&self, offset: usize) -> Result { self.check_rights(Rights::WRITE)?; self.0.commit_page(offset, false) } diff --git a/kernel/comps/block/src/bio.rs b/kernel/comps/block/src/bio.rs index b2e24690d..f8ac61478 100644 --- a/kernel/comps/block/src/bio.rs +++ b/kernel/comps/block/src/bio.rs @@ -2,8 +2,8 @@ use align_ext::AlignExt; use aster_frame::{ + mm::{Frame, Segment, VmReader, VmWriter}, sync::WaitQueue, - vm::{VmFrame, VmReader, VmSegment, VmWriter}, }; use int_to_c_enum::TryFromInt; @@ -359,7 +359,7 @@ pub enum BioStatus { #[derive(Debug, Clone)] pub struct BioSegment { /// The contiguous pages on which this segment resides. - pages: VmSegment, + pages: Segment, /// The starting offset (in bytes) within the first page. /// The offset should always be aligned to the sector size and /// must not exceed the size of a single page. @@ -373,8 +373,8 @@ pub struct BioSegment { const SECTOR_SIZE: u16 = super::SECTOR_SIZE as u16; impl<'a> BioSegment { - /// Constructs a new `BioSegment` from `VmSegment`. - pub fn from_segment(segment: VmSegment, offset: usize, len: usize) -> Self { + /// Constructs a new `BioSegment` from `Segment`. + pub fn from_segment(segment: Segment, offset: usize, len: usize) -> Self { assert!(offset + len <= segment.nbytes()); Self { @@ -384,12 +384,12 @@ impl<'a> BioSegment { } } - /// Constructs a new `BioSegment` from `VmFrame`. - pub fn from_frame(frame: VmFrame, offset: usize, len: usize) -> Self { + /// Constructs a new `BioSegment` from `Frame`. + pub fn from_frame(frame: Frame, offset: usize, len: usize) -> Self { assert!(offset + len <= super::BLOCK_SIZE); Self { - pages: VmSegment::from(frame), + pages: Segment::from(frame), offset: AlignedUsize::::new(offset).unwrap(), len: AlignedUsize::::new(len).unwrap(), } @@ -411,7 +411,7 @@ impl<'a> BioSegment { } /// Returns the contiguous pages on which this segment resides. - pub fn pages(&self) -> &VmSegment { + pub fn pages(&self) -> &Segment { &self.pages } diff --git a/kernel/comps/block/src/impl_block_device.rs b/kernel/comps/block/src/impl_block_device.rs index 1f165b78a..e4177882d 100644 --- a/kernel/comps/block/src/impl_block_device.rs +++ b/kernel/comps/block/src/impl_block_device.rs @@ -1,6 +1,6 @@ // SPDX-License-Identifier: MPL-2.0 -use aster_frame::vm::{VmAllocOptions, VmFrame, VmIo, VmSegment}; +use aster_frame::mm::{Frame, Segment, VmAllocOptions, VmIo}; use super::{ bio::{Bio, BioEnqueueError, BioSegment, BioStatus, BioType, BioWaiter, SubmittedBio}, @@ -16,7 +16,7 @@ impl dyn BlockDevice { pub fn read_blocks_sync( &self, bid: Bid, - segment: &VmSegment, + segment: &Segment, ) -> Result { let bio = create_bio_from_segment(BioType::Read, bid, segment); let status = bio.submit_sync(self)?; @@ -24,20 +24,20 @@ impl dyn BlockDevice { } /// Asynchronously reads contiguous blocks starting from the `bid`. - pub fn read_blocks(&self, bid: Bid, segment: &VmSegment) -> Result { + pub fn read_blocks(&self, bid: Bid, segment: &Segment) -> Result { let bio = create_bio_from_segment(BioType::Read, bid, segment); bio.submit(self) } /// Synchronously reads one block indicated by the `bid`. - pub fn read_block_sync(&self, bid: Bid, frame: &VmFrame) -> Result { + pub fn read_block_sync(&self, bid: Bid, frame: &Frame) -> Result { let bio = create_bio_from_frame(BioType::Read, bid, frame); let status = bio.submit_sync(self)?; Ok(status) } /// Asynchronously reads one block indicated by the `bid`. - pub fn read_block(&self, bid: Bid, frame: &VmFrame) -> Result { + pub fn read_block(&self, bid: Bid, frame: &Frame) -> Result { let bio = create_bio_from_frame(BioType::Read, bid, frame); bio.submit(self) } @@ -46,7 +46,7 @@ impl dyn BlockDevice { pub fn write_blocks_sync( &self, bid: Bid, - segment: &VmSegment, + segment: &Segment, ) -> Result { let bio = create_bio_from_segment(BioType::Write, bid, segment); let status = bio.submit_sync(self)?; @@ -54,28 +54,20 @@ impl dyn BlockDevice { } /// Asynchronously writes contiguous blocks starting from the `bid`. - pub fn write_blocks( - &self, - bid: Bid, - segment: &VmSegment, - ) -> Result { + pub fn write_blocks(&self, bid: Bid, segment: &Segment) -> Result { let bio = create_bio_from_segment(BioType::Write, bid, segment); bio.submit(self) } /// Synchronously writes one block indicated by the `bid`. - pub fn write_block_sync( - &self, - bid: Bid, - frame: &VmFrame, - ) -> Result { + pub fn write_block_sync(&self, bid: Bid, frame: &Frame) -> Result { let bio = create_bio_from_frame(BioType::Write, bid, frame); let status = bio.submit_sync(self)?; Ok(status) } /// Asynchronously writes one block indicated by the `bid`. - pub fn write_block(&self, bid: Bid, frame: &VmFrame) -> Result { + pub fn write_block(&self, bid: Bid, frame: &Frame) -> Result { let bio = create_bio_from_frame(BioType::Write, bid, frame); bio.submit(self) } @@ -202,7 +194,7 @@ impl dyn BlockDevice { } // TODO: Maybe we should have a builder for `Bio`. -fn create_bio_from_segment(type_: BioType, bid: Bid, segment: &VmSegment) -> Bio { +fn create_bio_from_segment(type_: BioType, bid: Bid, segment: &Segment) -> Bio { let bio_segment = BioSegment::from_segment(segment.clone(), 0, segment.nbytes()); Bio::new( type_, @@ -213,7 +205,7 @@ fn create_bio_from_segment(type_: BioType, bid: Bid, segment: &VmSegment) -> Bio } // TODO: Maybe we should have a builder for `Bio`. -fn create_bio_from_frame(type_: BioType, bid: Bid, frame: &VmFrame) -> Bio { +fn create_bio_from_frame(type_: BioType, bid: Bid, frame: &Frame) -> Bio { let bio_segment = BioSegment::from_frame(frame.clone(), 0, BLOCK_SIZE); Bio::new( type_, diff --git a/kernel/comps/block/src/lib.rs b/kernel/comps/block/src/lib.rs index d4124f673..4b4c6a937 100644 --- a/kernel/comps/block/src/lib.rs +++ b/kernel/comps/block/src/lib.rs @@ -49,7 +49,7 @@ use self::{ prelude::*, }; -pub const BLOCK_SIZE: usize = aster_frame::vm::PAGE_SIZE; +pub const BLOCK_SIZE: usize = aster_frame::mm::PAGE_SIZE; pub const SECTOR_SIZE: usize = 512; pub trait BlockDevice: Send + Sync + Any + Debug { diff --git a/kernel/comps/console/src/lib.rs b/kernel/comps/console/src/lib.rs index 999a06da2..77fa95fb2 100644 --- a/kernel/comps/console/src/lib.rs +++ b/kernel/comps/console/src/lib.rs @@ -10,7 +10,7 @@ extern crate alloc; use alloc::{collections::BTreeMap, fmt::Debug, string::String, sync::Arc, vec::Vec}; use core::any::Any; -use aster_frame::{sync::SpinLock, vm::VmReader}; +use aster_frame::{mm::VmReader, sync::SpinLock}; use component::{init_component, ComponentInitError}; use spin::Once; diff --git a/kernel/comps/framebuffer/src/lib.rs b/kernel/comps/framebuffer/src/lib.rs index 3c3911c2b..f634292cb 100644 --- a/kernel/comps/framebuffer/src/lib.rs +++ b/kernel/comps/framebuffer/src/lib.rs @@ -16,8 +16,8 @@ use core::{ use aster_frame::{ boot, io_mem::IoMem, + mm::{VmIo, PAGE_SIZE}, sync::SpinLock, - vm::{VmIo, PAGE_SIZE}, }; use component::{init_component, ComponentInitError}; use font8x8::UnicodeFonts; @@ -39,7 +39,7 @@ pub(crate) fn init() { let mut writer = { let framebuffer = boot::framebuffer_arg(); let mut size = 0; - for i in aster_frame::vm::FRAMEBUFFER_REGIONS.get().unwrap().iter() { + for i in aster_frame::mm::FRAMEBUFFER_REGIONS.get().unwrap().iter() { size = i.len(); } diff --git a/kernel/comps/network/src/buffer.rs b/kernel/comps/network/src/buffer.rs index a2ecaad92..748585248 100644 --- a/kernel/comps/network/src/buffer.rs +++ b/kernel/comps/network/src/buffer.rs @@ -4,8 +4,8 @@ use alloc::{collections::LinkedList, sync::Arc}; use align_ext::AlignExt; use aster_frame::{ + mm::{Daddr, DmaDirection, DmaStream, HasDaddr, VmAllocOptions, VmReader, VmWriter, PAGE_SIZE}, sync::SpinLock, - vm::{Daddr, DmaDirection, DmaStream, HasDaddr, VmAllocOptions, VmReader, VmWriter, PAGE_SIZE}, }; use pod::Pod; use spin::Once; diff --git a/kernel/comps/network/src/dma_pool.rs b/kernel/comps/network/src/dma_pool.rs index de6c64862..c726dcfe5 100644 --- a/kernel/comps/network/src/dma_pool.rs +++ b/kernel/comps/network/src/dma_pool.rs @@ -9,8 +9,8 @@ use alloc::{ use core::ops::Range; use aster_frame::{ + mm::{Daddr, DmaDirection, DmaStream, HasDaddr, VmAllocOptions, VmReader, VmWriter, PAGE_SIZE}, sync::{RwLock, SpinLock}, - vm::{Daddr, DmaDirection, DmaStream, HasDaddr, VmAllocOptions, VmReader, VmWriter, PAGE_SIZE}, }; use bitvec::{array::BitArray, prelude::Lsb0}; use ktest::ktest; diff --git a/kernel/comps/network/src/driver.rs b/kernel/comps/network/src/driver.rs index 734263af3..21eb31a93 100644 --- a/kernel/comps/network/src/driver.rs +++ b/kernel/comps/network/src/driver.rs @@ -2,7 +2,7 @@ use alloc::vec; -use aster_frame::vm::VmWriter; +use aster_frame::mm::VmWriter; use smoltcp::{phy, time::Instant}; use crate::{buffer::RxBuffer, AnyNetworkDevice}; diff --git a/kernel/comps/virtio/src/device/block/device.rs b/kernel/comps/virtio/src/device/block/device.rs index 4c70432b3..3968e9450 100644 --- a/kernel/comps/virtio/src/device/block/device.rs +++ b/kernel/comps/virtio/src/device/block/device.rs @@ -9,9 +9,9 @@ use aster_block::{ }; use aster_frame::{ io_mem::IoMem, + mm::{DmaDirection, DmaStream, DmaStreamSlice, VmAllocOptions, VmIo}, sync::SpinLock, trap::TrapFrame, - vm::{DmaDirection, DmaStream, DmaStreamSlice, VmAllocOptions, VmIo}, }; use aster_util::safe_ptr::SafePtr; use id_alloc::IdAlloc; diff --git a/kernel/comps/virtio/src/device/console/device.rs b/kernel/comps/virtio/src/device/console/device.rs index fc926ae04..0e6f94c16 100644 --- a/kernel/comps/virtio/src/device/console/device.rs +++ b/kernel/comps/virtio/src/device/console/device.rs @@ -6,9 +6,9 @@ use core::hint::spin_loop; use aster_console::{AnyConsoleDevice, ConsoleCallback}; use aster_frame::{ io_mem::IoMem, + mm::{DmaDirection, DmaStream, DmaStreamSlice, VmAllocOptions, VmReader}, sync::{RwLock, SpinLock}, trap::TrapFrame, - vm::{DmaDirection, DmaStream, DmaStreamSlice, VmAllocOptions, VmReader}, }; use aster_util::safe_ptr::SafePtr; use log::debug; diff --git a/kernel/comps/virtio/src/device/input/device.rs b/kernel/comps/virtio/src/device/input/device.rs index 948fc3197..a79e22318 100644 --- a/kernel/comps/virtio/src/device/input/device.rs +++ b/kernel/comps/virtio/src/device/input/device.rs @@ -10,10 +10,10 @@ use core::{fmt::Debug, iter, mem}; use aster_frame::{ io_mem::IoMem, + mm::{DmaDirection, DmaStream, HasDaddr, VmAllocOptions, VmIo, PAGE_SIZE}, offset_of, sync::{RwLock, SpinLock}, trap::TrapFrame, - vm::{DmaDirection, DmaStream, HasDaddr, VmAllocOptions, VmIo, PAGE_SIZE}, }; use aster_input::{ key::{Key, KeyStatus}, diff --git a/kernel/comps/virtio/src/dma_buf.rs b/kernel/comps/virtio/src/dma_buf.rs index 777527491..c24c90b78 100644 --- a/kernel/comps/virtio/src/dma_buf.rs +++ b/kernel/comps/virtio/src/dma_buf.rs @@ -1,6 +1,6 @@ // SPDX-License-Identifier: MPL-2.0 -use aster_frame::vm::{DmaCoherent, DmaStream, DmaStreamSlice, HasDaddr}; +use aster_frame::mm::{DmaCoherent, DmaStream, DmaStreamSlice, HasDaddr}; use aster_network::{DmaSegment, RxBuffer, TxBuffer}; /// A DMA-capable buffer. diff --git a/kernel/comps/virtio/src/queue.rs b/kernel/comps/virtio/src/queue.rs index c7e05dfd3..8631aa3b4 100644 --- a/kernel/comps/virtio/src/queue.rs +++ b/kernel/comps/virtio/src/queue.rs @@ -10,8 +10,8 @@ use core::{ use aster_frame::{ io_mem::IoMem, + mm::{DmaCoherent, VmAllocOptions}, offset_of, - vm::{DmaCoherent, VmAllocOptions}, }; use aster_rights::{Dup, TRightSet, TRights, Write}; use aster_util::{field_ptr, safe_ptr::SafePtr}; @@ -74,7 +74,7 @@ impl VirtQueue { let (descriptor_ptr, avail_ring_ptr, used_ring_ptr) = if transport.is_legacy_version() { // FIXME: How about pci legacy? - // Currently, we use one VmFrame to place the descriptors and avaliable rings, one VmFrame to place used rings + // Currently, we use one Frame to place the descriptors and avaliable rings, one Frame to place used rings // because the virtio-mmio legacy required the address to be continuous. The max queue size is 128. if size > 128 { return Err(QueueError::InvalidArgs); diff --git a/kernel/comps/virtio/src/transport/mmio/device.rs b/kernel/comps/virtio/src/transport/mmio/device.rs index 28c0d74d8..2ddc1cc17 100644 --- a/kernel/comps/virtio/src/transport/mmio/device.rs +++ b/kernel/comps/virtio/src/transport/mmio/device.rs @@ -9,10 +9,10 @@ use aster_frame::{ device::{MmioCommonDevice, VirtioMmioVersion}, }, io_mem::IoMem, + mm::{DmaCoherent, PAGE_SIZE}, offset_of, sync::RwLock, trap::IrqCallbackFunction, - vm::{DmaCoherent, PAGE_SIZE}, }; use aster_rights::{ReadOp, WriteOp}; use aster_util::{field_ptr, safe_ptr::SafePtr}; diff --git a/kernel/comps/virtio/src/transport/mod.rs b/kernel/comps/virtio/src/transport/mod.rs index 9dfbe80d1..60f4523ee 100644 --- a/kernel/comps/virtio/src/transport/mod.rs +++ b/kernel/comps/virtio/src/transport/mod.rs @@ -3,7 +3,7 @@ use alloc::boxed::Box; use core::fmt::Debug; -use aster_frame::{io_mem::IoMem, trap::IrqCallbackFunction, vm::DmaCoherent}; +use aster_frame::{io_mem::IoMem, mm::DmaCoherent, trap::IrqCallbackFunction}; use aster_util::safe_ptr::SafePtr; use self::{mmio::virtio_mmio_init, pci::virtio_pci_init}; diff --git a/kernel/comps/virtio/src/transport/pci/device.rs b/kernel/comps/virtio/src/transport/pci/device.rs index 174bdd02b..b5cb79973 100644 --- a/kernel/comps/virtio/src/transport/pci/device.rs +++ b/kernel/comps/virtio/src/transport/pci/device.rs @@ -11,9 +11,9 @@ use aster_frame::{ BusProbeError, }, io_mem::IoMem, + mm::DmaCoherent, offset_of, trap::IrqCallbackFunction, - vm::DmaCoherent, }; use aster_util::{field_ptr, safe_ptr::SafePtr}; use log::{info, warn}; diff --git a/kernel/libs/aster-util/src/safe_ptr.rs b/kernel/libs/aster-util/src/safe_ptr.rs index 540582e87..14a401948 100644 --- a/kernel/libs/aster-util/src/safe_ptr.rs +++ b/kernel/libs/aster-util/src/safe_ptr.rs @@ -3,7 +3,7 @@ use core::{fmt::Debug, marker::PhantomData}; use aster_frame::{ - vm::{Daddr, DmaStream, HasDaddr, HasPaddr, Paddr, VmIo}, + mm::{Daddr, DmaStream, HasDaddr, HasPaddr, Paddr, VmIo}, Result, }; use aster_rights::{Dup, Exec, Full, Read, Signal, TRightSet, TRights, Write}; @@ -56,7 +56,7 @@ pub use typeflags_util::SetContain; /// /// The generic parameter `M` of `SafePtr<_, M, _>` must implement the `VmIo` /// trait. The most important `VmIo` types are `Vmar`, `Vmo`, `IoMem`, and -/// `VmFrame`. The blanket implementations of `VmIo` also include pointer-like +/// `Frame`. The blanket implementations of `VmIo` also include pointer-like /// types that refer to a `VmIo` type. Some examples are `&Vmo`, `Box`, /// and `Arc`. /// @@ -382,7 +382,7 @@ impl Debug for SafePtr { macro_rules! field_ptr { ($ptr:expr, $type:ty, $($field:tt)+) => {{ use aster_frame::offset_of; - use aster_frame::vm::VmIo; + use aster_frame::mm::VmIo; use aster_rights::Dup; use aster_rights::TRightSet; use aster_rights::TRights;