summaryrefslogtreecommitdiff
path: root/vm
AgeCommit message (Collapse)Author
2023-07-03vm: Allow coalescing null object with an internal objectSergey Bugaev
Previously, vm_object_coalesce would only succeed with next_object being VM_OBJECT_NULL (and with the previous patch, with the two object references pointing to the same object). This patch additionally allows the inverse: prev_object being VM_OBJECT_NULL and next_object being some internal VM object that we have not created a pager port for, provided the offset of the existing mapping in the object allows for placing the new mapping before it. This is not used anywhere at the moment (the only caller, vm_map_enter, ensures that next_object is either VM_OBJECT_NULL or an object that has a pager port), but it will get used with the next patch. Message-Id: <20230626112656.435622-4-bugaevc@gmail.com>
2023-07-03vm: Allow coalescing a VM object with itselfSergey Bugaev
If a mapping of an object is made right next to another mapping of the same object have the same properties (protection, inheritance, etc.), Mach will now expand the previous VM map entry to cover the new address range instead of creating a new entry. Message-Id: <20230626112656.435622-3-bugaevc@gmail.com>
2023-07-03Shrink struct vm_page sizeSergey Bugaev
struct vm_page is supposed to be a "small structure", but it takes up 96 bytes on x86_64 (to represent a 4k page). By utilizing bitfields and strategically reordering members to avoid excessive padding, it can be shrunk to 80 bytes. - page_lock and unlock_request only need to store a bitmask of VM_PROT_READ, VM_PROT_WRITE, and VM_PROT_EXECUTE. Even though the special values VM_PROT_NO_CHANGE and VM_PROT_NOTIFY are defined, they are not used for the two struct vm_page members. - type and seg_index both need to store one of the four possible values in the range from 0 to 3. Two bits are sufficient for this. - order needs to store a number from 0 to VM_PAGE_NR_FREE_LISTS (which is 11), or a special value VM_PAGE_ORDER_UNLISTED. Four bits are sufficient for this. No functional change. Message-Id: <20230626112656.435622-2-bugaevc@gmail.com>
2023-02-09memory_object_create_proxy: avoid casting parameters to 32 bits since the ↵Flavio Cruz
types are correct now Message-Id: <Y+SfNtIRuwj0Zap1@jupiter.tail36e24.ts.net>
2023-02-09vm_page.c: add missing object lockEtienne Brateau
The documentation of vm_page_insert says that the object must be locked. Moreover, the unlock call is here but no call was present. Message-Id: <20230208225436.23365-1-etienne.brateau@gmail.com>
2023-02-08slock: Fix initialization of statically-allocated slocksSamuel Thibault
(this is actually a no-op for i386)
2023-01-31Define rpc_vm_size_array_t and rpc_vm_offset_array_tFlavio Cruz
When generating stubs, Mig will will take the vm_size_array_t and define the input request struct using rpc_vm_size_t since the size is variable. This will turn cause a mismatch between types (vm_size_t* vs rpc_vm_size_t*). We could also ask Mig to produce a prototype by using rpc_vm_size_t*, however we would need to change the implementation of the RPC to use rpc_* types anyway since we want to avoid another allocation of the array. Message-Id: <Y9iwScHpmsgY3V0N@jupiter.tail36e24.ts.net>
2023-01-25Fix several warnings for -Wmissing-prototypes (part 2)Flavio Cruz
* i386/i386/io_map.c: code is unused. * i386/i386/io_perm.c: include mig prototypes. * i386/i386/mp_desc.c: Deleted interrupt_stack_alloc since it is not used. * i386/i386/seg.h: Moved descriptor structs to i386/include/mach/i386/mach_i386_types.h as that represents the interface types for RPCs. Defined aliases for real_descriptor since those are used by the i386 RPCs. Inlined many functions here too and removed seg.c. * i386/i386/seg.c: Removed. All the functions are inline now. * i386/i386/trap.c: Use static. * i386/i386/trap.h: Define missing prototypes. * i386/i386/tss.h: Use static inline for ltr. * i386/i386/user_ldt.c: Include mig prototypes. * i386/include/mach/i386/mach_i386.defs: Define real_descriptor_t types since those are used in the RPC definition. Now both prototypes and definitions will match. * i386/include/mach/i386/mach_i386_types.h: Move struct descriptor from seg.h since we need those for the RPC interfaces. Removed include of io_perm.h since it generates circular includes otherwise. * i386/intel/pmap.c: pmap_map is unused. Added static qualifier for several functions. * i386/intel/pmap.h: pmap_update_interrupt declared for non-SMP and SMP. Message-Id: <Y89+R2VekOQK4IUo@jupiter.lan>
2023-01-19Remove existing old style definitions and use -Wold-style-definition.Flavio Cruz
Message-Id: <Y8mYd/pt/og4Tj5I@mercury.tail36e24.ts.net>
2023-01-19Include mig generated headers to avoid warnings with -Wmissing-prototypes.Flavio Cruz
This also reverts 566c227636481b246d928772ebeaacbc7c37145b and 963b1794d7117064cee8ab5638b329db51dad854 Message-Id: <Y8d75KSqNL4FFInm@mercury.tail36e24.ts.net>
2023-01-18Add static qualifiersFlavio Cruz
stack_statistics, swapin_thread_continue, and memory_object_lock_page are not used outside their module.
2023-01-13Create kern/mach4.h and kern/mach_host.h and define the RPC prototypes for ↵Flavio Cruz
mach4.defs and mach_host.defs. Also move more mach_debug rpcs to kern/mach_debug.h. Message-Id: <Y7+LPMLOafUQrNHZ@jupiter.tail36e24.ts.net>
2022-12-27Fix some warnings with -Wmissing-prototypes.Flavio Cruz
Marked some functions as static (private) as needed and added missing includes. This also revealed some dead code which was removed. Note that -Wmissing-prototypes is not enabled here since there is a bunch more warnings. Message-Id: <Y6j72lWRL9rsYy4j@mars>
2022-12-22Warn only once about not being able to recycle pagesSamuel Thibault
2022-12-21Use -Wstrict-prototypes and fix warningsFlavio Cruz
Most of the changes include defining and using proper function type declarations (with argument types declared) and avoiding using the K&R style of function declarations. Message-Id: <Y6Jazsuis1QA0lXI@mars>
2022-12-18vm_page_evict: avoid crashingSamuel Thibault
It seems we hit he "unable to recycle any page" even when there is no memory pressure, probably just because the pageout thread somehow to kicked but there's nothing to page out left.
2022-12-15Use __builtin_ffs instead of libc provided ffs in vm_map.cFlavio Cruz
We already use this built-in in other places and this will move us closer to being able to build the kernel without libc. Message-Id: <Y5l80/VUFvJYZTjy@jupiter.tail36e24.ts.net>
2022-12-06Define vm_size_t and vm_offset_t as __mach_uintptr_t.Flavio Cruz
This allows *printf to use %zd/%zu/%zx to print vm_size_t and vm_offset_t. Warnings using the incorrect specifiers were fixed. Note that MACH_PORT_NULL became just 0 because GCC thinks that we were comparing a pointer to a character (due to it being an unsigned int) so I removed the explicit cast. Message-Id: <Y47UNdcUF35Ag4Vw@reue>
2022-11-27vm_wire_all: Fix vm_map_protect caseSamuel Thibault
If a "wire_required" process calls vm_map_protect(0), the memory gets unwired as expected. But if the process then calls vm_map_protect(VM_PROT_READ) again, we need to wire that memory. (This happens to be exactly what glibc does for its heap) This fixes Hurd hangs on lack of memory, during which mach was swapping pieces of mach-defpager out.
2022-08-28hack vm memory object proxy creation for vm arraysLuca Dariz
* vm/memory_object_proxy.c: truncate vm array types as if they were the rpc_ version because MIG can't handle that. This rpc can't handle more than one element anyway. Note that the same issue with vm arrays is present at least with syscall emulation, but that functionality seems unused for now. A better fix could be to add a vm descriptor type in include/mach/message.h, but then probably we don't need to use the rpc_ types in MIG anymore, they would be needed only for the syscall definitions. Signed-off-by: Luca Dariz <luca@orpolo.org> Message-Id: <20220628101054.446126-15-luca@orpolo.org>
2022-08-28sign-extend mask in vm_map() with 32-bit userspaceLuca Dariz
* vm/vm_user.c: sign-extend mask with USER32 Signed-off-by: Luca Dariz <luca@orpolo.org> Message-Id: <20220628101054.446126-6-luca@orpolo.org>
2022-08-27fix warnings for 32 bit buildsLuca Dariz
Signed-off-by: Luca Dariz <luca@orpolo.org> Message-Id: <20220628101054.446126-13-luca@orpolo.org>
2022-08-21gnumach: vm_allocate_contiguous: Allow small power 2 alignmentsDamien Zammit
This allows contiguous allocations aligned to values smaller than one page, but still a power of 2, by forcing the alignment to be to the nearest page. This works because PAGE_SIZE is a power of two. Message-Id: <20220821065732.269573-1-damien@zamaudio.com>
2022-02-18vm_object_page_map: update prototypeSamuel Thibault
2022-02-17vm_allocate_contiguous: fix checking the end of the allocationSamuel Thibault
2022-02-17mach_vm_object_pages: Print a warning if the physical address is beyond 4GiBSamuel Thibault
vpi_offset is not currently large enough to store it.
2022-02-17vm_allocate_contiguous: Make sure we enforce physical addresses contraintsSamuel Thibault
2022-02-17projected_buffer_*: Fix storing physical addressSamuel Thibault
2022-02-16vm_object: Fix vm_object_page_map map function prototypeSamuel Thibault
The map function is supposed to return physical addresses, thus phys_addr_t.
2021-12-16vm_wire: extend per-task wiring limit to 8MiBSamuel Thibault
Like Linux just did.
2021-11-28Fix rejecting the mapping of some pagesSamuel Thibault
The memmmap method may reject some offsets (because it falls in non-device ranges), so device_map_page has to notice this and report the error. device_pager_data_request then has to notice as well and report.
2021-11-07vm_region_get_proxy: rename to create_proxySergey Bugaev
For coherency with memory_object_create_proxy.
2021-11-07Memory proxies: Add support for anonymous mappingsSergey Bugaev
* vm/vm_map.c (vm_region_get_proxy): - Return KERN_INVALID_ARGUMENT when the entry is a submap. - Create a pager for the vm_object when the entry doesn't have any yet, since it's an anonymous mapping. Message-Id: <20211106081333.10366-3-jlledom@mailfence.com>
2021-11-07vm: vm_region_get_proxyJoan Lledó
To get a proxy to the region a given address belongs to, with protection and range limited to the region ones. * include/mach/mach4.defs: vm_region_get_proxy RPC declaration * vm/vm_map.c: vm_region_get_proxy implementation Message-Id: <20211106081333.10366-2-jlledom@mailfence.com>
2021-11-07memory_object_create_proxy: Fix and check coherency with RPCSamuel Thibault
* vm/memory_object_proxy.c: Include kern/mach4.server.h. (memory_object_create_proxy): Drop const qualifiers.
2021-10-17memory_object_create_proxy: Make len parameter vm_size_array_tSamuel Thibault
This is a no-op on i386. * i386/include/mach/i386/vm_types.h (vm_size_array_t): New type. * include/mach/mach4.defs (vm_size_array_t): New type. (memory_object_create_proxy): Turn len parameter from vm_offset_array_t to vm_size_array_t. * vm/memory_object_proxy.c (memory_object_create_proxy): Turn len parameter from const vm_offset_t * to const vm_size_t *.
2021-08-27vm_page_grab: allow allocating in high memorySamuel Thibault
vm_page_grab was systematically using the VM_PAGE_SEL_DIRECTMAP selector to play safe with existing code. This adds a flags parameter to let callers of vm_page_grab specify their constraints. Linux drivers need 32bit dmas, Xen drivers use kvtophys to clear some data. Callers of kmem_pagealloc_physmem and vm_page_grab_phys_addr also use kvtophys. Otherwise allocations can go to highmem. This fixes the allocation jam in the directmap segment. * vm/vm_page.h (VM_PAGE_DMA, VM_PAGE_DMA32, VM_PAGE_DIRECTMAP, VM_PAGE_HIGHMEM): New macros. (vm_page_grab): Add flags parameter. * vm/vm_resident.c (vm_page_grab): Choose allocation selector according to flags parameter. (vm_page_convert, vm_page_alloc): Pass VM_PAGE_HIGHMEM to vm_page_grab. (vm_page_grab_phys_addr): Pass VM_PAGE_DIRECTMAP to vm_page_grab. * vm/vm_fault.c (vm_fault_page): Pass VM_PAGE_HIGHMEM to vm_page_grab. * vm/vm_map.c (vm_map_copy_steal_pages): Pass VM_PAGE_HIGHMEM to vm_page_grab. * kern/slab.c (kmem_pagealloc_physmem): Pass VM_PAGE_DIRECTMAP to vm_page_grab. * i386/intel/pmap.c (pmap_page_table_page_alloc): Pass VM_PAGE_DIRECTMAP to vm_page_grab. * xen/block.c (device_read): Pass VM_PAGE_DIRECTMAP to vm_page_grab. * linux/dev/glue/block.c (alloc_buffer): Pass VM_PAGE_DMA32 to vm_page_grab.
2021-08-23db_show_vmstat: Show segment name rather than its numberSamuel Thibault
2021-08-22db_show_vmstat: Also show segment sizeSamuel Thibault
* vm/vm_page.c (db_show_vmstat): Add printing the segment size.
2021-08-22db_show_vmstat: Drop duplicate outputSamuel Thibault
* vm/vm_page.c (db_show_vmstat): Drop displaying cache numbers a second time.
2021-08-21db show vmstat: also show segments statsSamuel Thibault
* vm/vm_page.c (db_show_vmstat)
2021-08-21db: Add show vmstat commandSamuel Thibault
with an output similar to the userland vmstat command * vm/vm_page.c (db_show_vmstat): New function. * vm/vm_page.h (db_show_vmstat): New prototype. * ddb/db_command.c (db_show_cmds): Add vmstat command.
2021-08-09memory_object_proxy: Deliver no-sender notifications on a separate portv1.8+git202108091.8+git20210809Samuel Thibault
Otherwise userland can send spurious notifications.
2021-08-09memory_object_proxy: Fix send port right leakSamuel Thibault
On success we'd have to clean the port right. Just consume it.
2021-08-09memory_object_proxy: Fix checking proxy lengthSamuel Thibault
We want to prevent subproxies from requesting larger sizes than what a proxy initially allowed.
2021-08-09Memory object proxy: add support for ranges and nestingJoan Lledó
2021-08-09memory_object_proxy: release resources on no-send notificationSamuel Thibault
2021-06-06vm_map: Allow exagerated max_prot for nowSamuel Thibault
glibc's mmap implementation assumes that gnumach will cap the prot for it, so for now let's revert back to capping rather than rejecting. That fixes mmap(SHARED|READ) for read-only objects.
2021-05-24Revert "vm_map: Allow passing the name of a memory object"Samuel Thibault
This reverts commit af9f471b500bcd0c1023259c7577e074fe6d3ee5.
2021-05-24vm_map: Fix proxy object protection checkSergey Bugaev
* If not making a copy, don't cap protection to the limit enforced by the proxy, and only require read access. This fixes mapping parts of read-only files MAP_ANON + PROT_READ|PROT_WRITE. * Instead of silently capping protection, return KERN_PROTECTION_FAILURE to the caller like the other vm_*() routines do.