History log of /haiku/src/system/kernel/arch/x86/arch_vm.cpp
Revision Date Author Comments
# b5d23373 14-Apr-2019 Augustin Cavalier <waddlesplash@gmail.com>

kernel/x86: Move the add_memory_type_range tracing to level "2".

We usually set level "1" by default, so this will hide it.
It's not really that useful when debugging problems in general
at this point.

OK'ed by tqh.


# c73d1301 08-Nov-2015 Michael Lotz <mmlr@mlotz.ch>

kernel: Use anonymous namespaces to avoid type collisions.

The anonymous namespace makes type definitions local to the translation
unit (like static does for objects). For pretty much any type not shared
across multiple files this is what one wants to happen (and might
erroneously expect to happen automatically).

This commit solves some actual collisions that were present:

* The VFS and the rootfs both used an incompatible VnodeHash struct for
their BOpenHashTable.
* XSI semaphores and message queues both used queued_thread, Ipc and
IpcHashTableDefinition.

For release builds these did not cause problems as the types were fully
inlined. Debug builds would crash at boot however because parts of a
BOpenHashTable<VnodeHash> from the rootfs meant to operate on struct
rootfs_vnode would be applied to one from the VFS expecting struct
vnode.

As such collisions are violations of the one definition rule, the code
is at fault and unfortunatley the compiler isn't required to diagnose
such problems across translation units (which isn't actually trivial).
This can lead to subtle and hard to debug problems and it's therefore
best to avoid leaking types into the global namespace whenever possible.


# 966f2076 06-Mar-2013 Pawel Dziepak <pdziepak@quarnos.org>

x86: enable data execution prevention

Set execute disable bit for any page that belongs to area with neither
B_EXECUTE_AREA nor B_KERNEL_EXECUTE_AREA set.

In order to take advanage of NX bit in 32 bit protected mode PAE must be
enabled. Thus, from now on it is also enabled when the CPU supports NX bit.

vm_page_fault() takes additional argument which indicates whether page fault
was caused by an illegal instruction fetch.


# fa6327c9 09-Aug-2012 Alex Smith <alex@alex-smith.me.uk>

Compile remaining x86 bits for x86_64.

The IOAPIC and IRQ routing code now gets compiled for x86_64, though
they won't be used yet as there is no ACPI support currently.


# cc248cf2 08-Jul-2012 Alex Smith <alex@alex-smith.me.uk>

A couple of bug fixes.

* mmu_get_virtual_mapping() should check that the page directory entry is
present rather than assuming there's a page table there. This was resulting
in some invalid mappings being created in the 64-bit virtual address space.
* arch_vm_init_end() should clear from KERNEL_LOAD_BASE to virtual_end, not
from KERNEL_BASE. On x86_64 this was causing it to loop through ~512GB of
address space, which obviously was taking quite a while.


# 4988ca58 04-Jul-2012 Alex Smith <alex@alex-smith.me.uk>

Build arch_vm.cpp for x86_64. No changes required except for temporarily disabling bios_init call.


# 45bd7bb3 25-Jun-2010 Ingo Weinhold <ingo_weinhold@gmx.de>

Removed unnecessary inclusions of <boot/kernel_args.h> in private kernel
headers and respectively added includes in source files.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@37259 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 12f0b50c 08-Jun-2010 Ingo Weinhold <ingo_weinhold@gmx.de>

Removed not needed and no longer existing header. Fixes the build.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@37067 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 64d79eff 27-May-2010 Ingo Weinhold <ingo_weinhold@gmx.de>

* Changed physical_entry::{address,size} to phys_{addr,size}_t and changed
map_physical_memory()'s physicalAddress parameter type from void* to
phys_addr_t. This breaks source compatibility, but -- as long as
phys_{addr,size}_t remain 32 bit wide -- keeps binary compatibility with
BeOS.
* Adjusted all code using the affected interfaces (Oh what fun!). Added a few
TODOs in places where the wrong types (e.g. void* for physical addresses
are used). Looks like quite a few drivers aren't 64 bit safe and others
will break with PAE.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@36960 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 147133b7 25-May-2010 Ingo Weinhold <ingo_weinhold@gmx.de>

* First run through the kernel's private parts to use phys_{addr,size}_t
where appropriate.
* Typedef'ed page_num_t to phys_addr_t and used it in more places in
vm_page.{h,cpp}.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@36937 a95241bf-73f2-0310-859d-f6bbb57e9c96


# fa0c1e96 02-May-2010 Ingo Weinhold <ingo_weinhold@gmx.de>

Hopefully the last work on the MTRR code for the time being:
Since we also force uncacheability via the PTEs, it is no longer necessary to
use MTRRs for uncacheable ranges. It is recommended, which is why we still do
it, if possible, but when we run out of MTRRs, the algorithm ignores
uncacheable ranges now -- iteratively it increases the minimum size of ranges
to drop until the available MTRRs suffice.
Should fix #5703 and #5865.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@36591 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 3b0c1b52 01-May-2010 Ingo Weinhold <ingo_weinhold@gmx.de>

* VMArea: Made memory_type private and added setter and getter methods.
* Don't set the VMArea's memory type in arch_vm_set_memory_type(), but let the
callers do that.
* vm_set_area_memory_type(): Does nothing, if the memory type doesn't change.



git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@36573 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 40f1dd84 01-May-2010 Ingo Weinhold <ingo_weinhold@gmx.de>

arch_vm_supports_protection(): Fixed broken check.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@36570 a95241bf-73f2-0310-859d-f6bbb57e9c96


# a915c50a 04-Mar-2010 Ingo Weinhold <ingo_weinhold@gmx.de>

panic() when running out of MTRRs. I know I'm gonna regret this...


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@35755 a95241bf-73f2-0310-859d-f6bbb57e9c96


# affb4716 04-Mar-2010 Ingo Weinhold <ingo_weinhold@gmx.de>

add_mtrrs_for_range(): Fixed computation of the register ranges. Per power of
2 size we might need to use two registers (for the start and the end of the
range).


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@35753 a95241bf-73f2-0310-859d-f6bbb57e9c96


# d40a9355 02-Mar-2010 Ingo Weinhold <ingo_weinhold@gmx.de>

Boot loader (x86 mmu.cpp):
* Made the page table allocation more flexible. Got rid of sMaxVirtualAddress
and added new virtual_end address to the architecture specific kernel args.
* Increased the virtual space we reserve for the kernel to 16 MB. That
should suffice for quite a while. The previous 2 MB were too tight when
building the kernel with debug info.
* mmu_init(): The way we were translating the BIOS' extended memory map to
our physical ranges arrays was broken. Small gaps between usable memory
ranges would be ignored and instead marked allocated. This worked fine for
the boot loader and during the early kernel initialization, but after the
VM has been fully set up it frees all physical ranges that have not been
claimed otherwise. So those ranges could be entered into the free pages
list and would be used later. This could possibly cause all kinds of weird
problems, probably including ACPI issues. Now we add only the actually
usable ranges to our list.

Kernel:
* vm_page_init(): The pages of the ranges between the usable physical memory
ranges are now marked PAGE_STATE_UNUSED, the allocated ranges
PAGE_STATE_WIRED.
* unmap_and_free_physical_pages(): Don't free pages marked as unused.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@35726 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 682c3066 23-Feb-2010 Ingo Weinhold <ingo_weinhold@gmx.de>

Don't complain about running out of MTRRs before the CPU modules have been
loaded in the first place.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@35585 a95241bf-73f2-0310-859d-f6bbb57e9c96


# dac21d8b 18-Feb-2010 Ingo Weinhold <ingo_weinhold@gmx.de>

* map_physical_memory() does now always set a memory type. If none is given (it
needs to be or'ed to the address specification), "uncached" is assumed.
* Set the memory type for the "BIOS" and "DMA" areas to write-back. Not sure, if
that's correct, but that's what was effectively used on my machines before.
* Changed x86_set_mtrrs() and the CPU module hook to also set the default memory
type.
* Rewrote the MTRR computation once more:
- Now we know all used memory ranges, so we are free to extend used ranges
into unused ones in order to simplify them for MTRR setup.
- Leverage the subtractive properties of uncached and write-through ranges to
simplify ranges of any other respectively write-back type.
- Set the default memory type to write-back, so we don't need MTRRs for the
RAM ranges.
- If a new range intersects with an existing one, we no longer just fail.
Instead we use the strictest requirements implied by the ranges. This fixes
#5383.

Overall the new algorithm should be sufficient with far less MTRRs than before
(on my desktop machine 4 are used at maximum, while 8 didn't quite suffice
before). A drawback of the current implementation is that it doesn't deal with
the case of running out of MTRRs at all, which might result in some ranges
having weaker caching/memory ordering properties than requested.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@35515 a95241bf-73f2-0310-859d-f6bbb57e9c96


# bbd97b4b 03-Dec-2009 Ingo Weinhold <ingo_weinhold@gmx.de>

Made the VMArea fields base and size private and added accessors instead.
This makes it more explicit where the fields are modified.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@34464 a95241bf-73f2-0310-859d-f6bbb57e9c96


# f34a1dd5 02-Dec-2009 Ingo Weinhold <ingo_weinhold@gmx.de>

Created VMArea.{h,cpp} and moved VMArea and the global area hash table (new
class VMAreaHash) there.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@34450 a95241bf-73f2-0310-859d-f6bbb57e9c96


# e50cf876 02-Dec-2009 Ingo Weinhold <ingo_weinhold@gmx.de>

* Moved the VM headers into subdirectory vm/.
* Renamed vm_cache.h/vm_address_space.h to VMCache.h/VMAddressSpace.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@34449 a95241bf-73f2-0310-859d-f6bbb57e9c96


# a99eb6b5 01-Dec-2009 Ingo Weinhold <ingo_weinhold@gmx.de>

vm_area -> VMArea


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@34423 a95241bf-73f2-0310-859d-f6bbb57e9c96


# b0db552c 01-Dec-2009 Ingo Weinhold <ingo_weinhold@gmx.de>

Renamed vm_address_space to VMAddressSpace.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@34422 a95241bf-73f2-0310-859d-f6bbb57e9c96


# bb163c02 23-Nov-2009 Ingo Weinhold <ingo_weinhold@gmx.de>

* Added a set_mtrrs() hook to x86_cpu_module_info, which is supposed to set
all MTRRs at once.
* Added a respective x86_set_mtrrs() kernel function.
* x86 CPU module:
- Implemented the new hook.
- Prefixed most debug output with the CPU index. Otherwise it gets quite
confusing with multiple CPUs.
- generic_init_mtrrs(): No longer clear all MTRRs, if they are already
enabled. This lets us benefit from the BIOS's setup until we install our
own -- otherwise with caching disabled things are *really* slow.
* arch_vm.cpp: Completely rewrote the MTRR handling as the old one was not
only slow (O(2^n)), but also broken (resulting in incorrect setups (e.g.
with cachable ranges larger than requested)), and not working by design for
certain cases (subtractive setups intersecting ranges added later).
Now we maintain an array with the successfully set ranges. When a new range
is added, we recompute the complete MTRR setup as we need to. The new
algorithm analyzing the ranges has linear complexity and also handles range
base addresses with an alignment not matching the range size (e.g. a range
at address 0x1000 with size 0x2000) and joining of adjacent/overlapping
ranges of the same type.

This fixes the slow graphics on my 4 GB machine (though unfortunately the
8 MTRRs aren't enough to fully cover the complete frame buffer (about 35
pixel lines remain uncachable), but that can't be helped without rounding up
the frame buffer size, for which we don't have enough information). It might
also fix #1823.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@34197 a95241bf-73f2-0310-859d-f6bbb57e9c96


# f835a75f 13-Jun-2009 Michael Lotz <mmlr@mlotz.ch>

Make two runs of MTRR setting when setting memory ranges to write-back. At the
first run only set up uncacheable MTRRs and in the second run set the write-back
ones up. If this order is not followed, we could set too large ranges to
cacheable first and then limit it back to uncacheable later. On systems with
enough physical memory this would lead to a temporary situation in which areas
become cacheable that must not be, resulting in system hangs or other unexpected
behaviour. Fixes last part of #4018.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@31027 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 9a42ad7a 22-Oct-2008 Ingo Weinhold <ingo_weinhold@gmx.de>

When switching to a kernel thread we no longer set the page directory.
This is not necessary, since userland teams' page directories also
contain the kernel mappings, and avoids unnecessary TLB flushes. To make
that possible the vm_translation_map_arch_info objects are reference
counted now.

This optimization reduces the kernel time of the Haiku build on my
machine with SMP disabled a few percent, but interestingly the total
time decreases only marginally. Haven't tested with SMP yet, but for
full impact CPU affinity would be needed.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@28287 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 47c40a10 19-Oct-2008 Ingo Weinhold <ingo_weinhold@gmx.de>

* Prefixed memset_physical() and memcpy_to_physical() with "vm_",
added vm_memcpy_from_physical() and vm_memcpy_physical_page(), and
added respective functions to the vm_translation_map operations. The
architecture specific implementation can now decide how to implement
them most efficiently. Added generic implementations that can be used,
though.
* Changed vm_{get,put}_physical_page(). The former no longer accepts
flags (the only flag PHYSICAL_PAGE_DONT_WAIT wasn't needed anymore).
Instead it returns an implementation-specific handle that has to be
passed to the latter. Added vm_{get,put}_physical_page_current_cpu()
and *_debug() variants, that work only for the current CPU,
respectively when in the kernel debugger. Also adjusted the
vm_translation_map operations accordingly.
* Made consequent use of the physical memory operations in the source
tree.
* Also adjusted the m68k and ppc implementations with respect to the
vm_translation_map operation changes, but they are probably broken,
nevertheless.
* For x86 the generic physical page mapper isn't used anymore. It is
suboptimal in any case. For systems with small memory it is too much
overhead, since one can just map the complete physical memory (that's
not done yet, though). For systems with large memory it counteracts
the VM strategy to reuse the least recently used pages. Since those
pages will most likely not be mapped by the page mapper anymore, it
will keep remapping chunks. This was also the reason why building
Haiku in Haiku was significantly faster with only 256 MB RAM (since
that much could be kept mapped all the time).
Now we're using a different strategy: We have small pools of virtual
page slots per CPU that are used for the physical page operations
(memset_physical(), memcpy_*_physical()) with CPU-pinned thread.
Furthermore we have four slots per translation map, which are used to
map page tables.

These changes speed up the Haiku image build in Haiku significantly. On
my Core2 Duo 2.2 GHz 2 GB machine about 40% to 20 min 40 s (KDEBUG
disabled, block cache debug disabled). Still more than factor 3 slower
than FreeBSD and Linux, though.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@28244 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 74785e79 07-Oct-2008 Ingo Weinhold <ingo_weinhold@gmx.de>

* Added "from" address space parameter to vm_swap_address_space()/
arch_vm_aspace_swap().
* The x86 implementation does now maintain a bit mask per
vm_translation_map_arch_info indicating on which CPUs the address
space is active. This allows flush_tmap() to avoid ICI for user
address spaces when the team isn't currently running on any other CPU.
In this context ICI is relatively expensive, particularly since we map
most pages via vm_map_page() and therefore invoke flush_tmap() pretty
much for every single page.
This optimization speeds up a "hello world" compilation about 20% on
my machine (KDEBUG turned off, freshly booted), but interestingly it
has virtually no effect on the "-j2" haiku build time.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@27912 a95241bf-73f2-0310-859d-f6bbb57e9c96


# b50e6202 02-Oct-2008 Ingo Weinhold <ingo_weinhold@gmx.de>

Fixed various warnings.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@27841 a95241bf-73f2-0310-859d-f6bbb57e9c96


# f7c655c7 07-Jun-2008 Jérôme Duval <korli@users.berlios.de>

find_nearest() now saves a solution when reaching the max number of solutions and not near enough


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@25859 a95241bf-73f2-0310-859d-f6bbb57e9c96


# c103aef2 12-Apr-2008 Jérôme Duval <korli@users.berlios.de>

disabled check for memory overlaps for the time being


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@24946 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 7522f308 30-Mar-2008 Jérôme Duval <korli@users.berlios.de>

reduced MTRR min size to 512KB


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@24679 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 9fcee65e 27-Mar-2008 Jérôme Duval <korli@users.berlios.de>

take into account areas starting or ending equally


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@24612 a95241bf-73f2-0310-859d-f6bbb57e9c96


# cd9ce121 25-Mar-2008 Jérôme Duval <korli@users.berlios.de>

now checks if another mtrr range is extended by a new one and extends it


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@24582 a95241bf-73f2-0310-859d-f6bbb57e9c96


# e958cea5 20-Mar-2008 Jérôme Duval <korli@users.berlios.de>

now fails if a write combining overlaps


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@24494 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 4e8c60ce 19-Mar-2008 Jérôme Duval <korli@users.berlios.de>

style cleanup
replaced addr_t by uint64
more debug output


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@24476 a95241bf-73f2-0310-859d-f6bbb57e9c96


# b20d05b4 18-Mar-2008 Jérôme Duval <korli@users.berlios.de>

clean up, comments, header


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@24452 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 48e299e2 17-Mar-2008 Ingo Weinhold <ingo_weinhold@gmx.de>

Fixed warning.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@24438 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 4f893e39 17-Mar-2008 Jérôme Duval <korli@users.berlios.de>

algorithm to find best suited mtrr values to match a memory region. tested ok with 3071MB.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@24424 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 2d2212bd 05-Mar-2008 Jérôme Duval <korli@users.berlios.de>

here with 3GB of memory, a 4GB MTRR slot is being written, which triggers a reboot.
we now split more than 2GB MTRR slot, we might improve this and split more and more.
this could fix the bug #1711.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@24244 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 393fceb5 27-Sep-2007 Axel Dörfler <axeld@pinc-software.de>

* Cleaned up vm_types.h a bit, and made vm_page, vm_cache, and vm_area
opaque types for C.
* As a result, I've renamed some more source files to .cpp, and fixed
all warnings caused by that.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@22326 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 966f207668d19610dae34d5331150e3742815bcf 06-Mar-2013 Pawel Dziepak <pdziepak@quarnos.org>

x86: enable data execution prevention

Set execute disable bit for any page that belongs to area with neither
B_EXECUTE_AREA nor B_KERNEL_EXECUTE_AREA set.

In order to take advanage of NX bit in 32 bit protected mode PAE must be
enabled. Thus, from now on it is also enabled when the CPU supports NX bit.

vm_page_fault() takes additional argument which indicates whether page fault
was caused by an illegal instruction fetch.


# fa6327c9f48f89f3be1f229d5aca749241b55bf0 09-Aug-2012 Alex Smith <alex@alex-smith.me.uk>

Compile remaining x86 bits for x86_64.

The IOAPIC and IRQ routing code now gets compiled for x86_64, though
they won't be used yet as there is no ACPI support currently.


# cc248cf2b37b96f8f86d652e0121be105b23d192 08-Jul-2012 Alex Smith <alex@alex-smith.me.uk>

A couple of bug fixes.

* mmu_get_virtual_mapping() should check that the page directory entry is
present rather than assuming there's a page table there. This was resulting
in some invalid mappings being created in the 64-bit virtual address space.
* arch_vm_init_end() should clear from KERNEL_LOAD_BASE to virtual_end, not
from KERNEL_BASE. On x86_64 this was causing it to loop through ~512GB of
address space, which obviously was taking quite a while.


# 4988ca58a0b6f12e48286fe17ee651be490e0f24 04-Jul-2012 Alex Smith <alex@alex-smith.me.uk>

Build arch_vm.cpp for x86_64. No changes required except for temporarily disabling bios_init call.


# 45bd7bb3db9d9e4dcb02b89a3e7c2bf382c0a88c 25-Jun-2010 Ingo Weinhold <ingo_weinhold@gmx.de>

Removed unnecessary inclusions of <boot/kernel_args.h> in private kernel
headers and respectively added includes in source files.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@37259 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 12f0b50c3afee6af6337b2a1d47dcfa9e7f004bd 08-Jun-2010 Ingo Weinhold <ingo_weinhold@gmx.de>

Removed not needed and no longer existing header. Fixes the build.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@37067 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 64d79eff7290437d24b1a420537c3ed5c144ab96 27-May-2010 Ingo Weinhold <ingo_weinhold@gmx.de>

* Changed physical_entry::{address,size} to phys_{addr,size}_t and changed
map_physical_memory()'s physicalAddress parameter type from void* to
phys_addr_t. This breaks source compatibility, but -- as long as
phys_{addr,size}_t remain 32 bit wide -- keeps binary compatibility with
BeOS.
* Adjusted all code using the affected interfaces (Oh what fun!). Added a few
TODOs in places where the wrong types (e.g. void* for physical addresses
are used). Looks like quite a few drivers aren't 64 bit safe and others
will break with PAE.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@36960 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 147133b76cbb1603bdbff295505f5b830cb4e688 25-May-2010 Ingo Weinhold <ingo_weinhold@gmx.de>

* First run through the kernel's private parts to use phys_{addr,size}_t
where appropriate.
* Typedef'ed page_num_t to phys_addr_t and used it in more places in
vm_page.{h,cpp}.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@36937 a95241bf-73f2-0310-859d-f6bbb57e9c96


# fa0c1e96a06b6dce8bcdfb1c07ddfbc231a31603 02-May-2010 Ingo Weinhold <ingo_weinhold@gmx.de>

Hopefully the last work on the MTRR code for the time being:
Since we also force uncacheability via the PTEs, it is no longer necessary to
use MTRRs for uncacheable ranges. It is recommended, which is why we still do
it, if possible, but when we run out of MTRRs, the algorithm ignores
uncacheable ranges now -- iteratively it increases the minimum size of ranges
to drop until the available MTRRs suffice.
Should fix #5703 and #5865.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@36591 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 3b0c1b5227ab487b1963faea4d046cba4d0622ff 01-May-2010 Ingo Weinhold <ingo_weinhold@gmx.de>

* VMArea: Made memory_type private and added setter and getter methods.
* Don't set the VMArea's memory type in arch_vm_set_memory_type(), but let the
callers do that.
* vm_set_area_memory_type(): Does nothing, if the memory type doesn't change.



git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@36573 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 40f1dd8443cfa756b74952cadcc40a2ad64cdf44 01-May-2010 Ingo Weinhold <ingo_weinhold@gmx.de>

arch_vm_supports_protection(): Fixed broken check.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@36570 a95241bf-73f2-0310-859d-f6bbb57e9c96


# a915c50a6038062d92d69d9f7b7f1447a5009a59 04-Mar-2010 Ingo Weinhold <ingo_weinhold@gmx.de>

panic() when running out of MTRRs. I know I'm gonna regret this...


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@35755 a95241bf-73f2-0310-859d-f6bbb57e9c96


# affb47166b296b9c375f1a1f6c3480c7471531f4 04-Mar-2010 Ingo Weinhold <ingo_weinhold@gmx.de>

add_mtrrs_for_range(): Fixed computation of the register ranges. Per power of
2 size we might need to use two registers (for the start and the end of the
range).


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@35753 a95241bf-73f2-0310-859d-f6bbb57e9c96


# d40a9355605dff41924273711f9dc9df6da496d2 02-Mar-2010 Ingo Weinhold <ingo_weinhold@gmx.de>

Boot loader (x86 mmu.cpp):
* Made the page table allocation more flexible. Got rid of sMaxVirtualAddress
and added new virtual_end address to the architecture specific kernel args.
* Increased the virtual space we reserve for the kernel to 16 MB. That
should suffice for quite a while. The previous 2 MB were too tight when
building the kernel with debug info.
* mmu_init(): The way we were translating the BIOS' extended memory map to
our physical ranges arrays was broken. Small gaps between usable memory
ranges would be ignored and instead marked allocated. This worked fine for
the boot loader and during the early kernel initialization, but after the
VM has been fully set up it frees all physical ranges that have not been
claimed otherwise. So those ranges could be entered into the free pages
list and would be used later. This could possibly cause all kinds of weird
problems, probably including ACPI issues. Now we add only the actually
usable ranges to our list.

Kernel:
* vm_page_init(): The pages of the ranges between the usable physical memory
ranges are now marked PAGE_STATE_UNUSED, the allocated ranges
PAGE_STATE_WIRED.
* unmap_and_free_physical_pages(): Don't free pages marked as unused.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@35726 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 682c3066c7af1cda421891c05db37b73e91ff5d2 23-Feb-2010 Ingo Weinhold <ingo_weinhold@gmx.de>

Don't complain about running out of MTRRs before the CPU modules have been
loaded in the first place.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@35585 a95241bf-73f2-0310-859d-f6bbb57e9c96


# dac21d8bfe3fcb0ee34a4a0c866c2474bfb8b155 18-Feb-2010 Ingo Weinhold <ingo_weinhold@gmx.de>

* map_physical_memory() does now always set a memory type. If none is given (it
needs to be or'ed to the address specification), "uncached" is assumed.
* Set the memory type for the "BIOS" and "DMA" areas to write-back. Not sure, if
that's correct, but that's what was effectively used on my machines before.
* Changed x86_set_mtrrs() and the CPU module hook to also set the default memory
type.
* Rewrote the MTRR computation once more:
- Now we know all used memory ranges, so we are free to extend used ranges
into unused ones in order to simplify them for MTRR setup.
- Leverage the subtractive properties of uncached and write-through ranges to
simplify ranges of any other respectively write-back type.
- Set the default memory type to write-back, so we don't need MTRRs for the
RAM ranges.
- If a new range intersects with an existing one, we no longer just fail.
Instead we use the strictest requirements implied by the ranges. This fixes
#5383.

Overall the new algorithm should be sufficient with far less MTRRs than before
(on my desktop machine 4 are used at maximum, while 8 didn't quite suffice
before). A drawback of the current implementation is that it doesn't deal with
the case of running out of MTRRs at all, which might result in some ranges
having weaker caching/memory ordering properties than requested.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@35515 a95241bf-73f2-0310-859d-f6bbb57e9c96


# bbd97b4bb41cc03735528962ff53d89a2a2d7ff2 03-Dec-2009 Ingo Weinhold <ingo_weinhold@gmx.de>

Made the VMArea fields base and size private and added accessors instead.
This makes it more explicit where the fields are modified.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@34464 a95241bf-73f2-0310-859d-f6bbb57e9c96


# f34a1dd5d701373687b6f3f0e6e76bd2b1ae6007 02-Dec-2009 Ingo Weinhold <ingo_weinhold@gmx.de>

Created VMArea.{h,cpp} and moved VMArea and the global area hash table (new
class VMAreaHash) there.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@34450 a95241bf-73f2-0310-859d-f6bbb57e9c96


# e50cf8765be50a7454c9488db38b638cf90805af 02-Dec-2009 Ingo Weinhold <ingo_weinhold@gmx.de>

* Moved the VM headers into subdirectory vm/.
* Renamed vm_cache.h/vm_address_space.h to VMCache.h/VMAddressSpace.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@34449 a95241bf-73f2-0310-859d-f6bbb57e9c96


# a99eb6b56f61bd847d246e44885618fdeaa313a1 01-Dec-2009 Ingo Weinhold <ingo_weinhold@gmx.de>

vm_area -> VMArea


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@34423 a95241bf-73f2-0310-859d-f6bbb57e9c96


# b0db552cd921ff16d61400ee5a5f855f392e8b87 01-Dec-2009 Ingo Weinhold <ingo_weinhold@gmx.de>

Renamed vm_address_space to VMAddressSpace.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@34422 a95241bf-73f2-0310-859d-f6bbb57e9c96


# bb163c0289ef6ea5d1d6162f0178273c8933a7c0 23-Nov-2009 Ingo Weinhold <ingo_weinhold@gmx.de>

* Added a set_mtrrs() hook to x86_cpu_module_info, which is supposed to set
all MTRRs at once.
* Added a respective x86_set_mtrrs() kernel function.
* x86 CPU module:
- Implemented the new hook.
- Prefixed most debug output with the CPU index. Otherwise it gets quite
confusing with multiple CPUs.
- generic_init_mtrrs(): No longer clear all MTRRs, if they are already
enabled. This lets us benefit from the BIOS's setup until we install our
own -- otherwise with caching disabled things are *really* slow.
* arch_vm.cpp: Completely rewrote the MTRR handling as the old one was not
only slow (O(2^n)), but also broken (resulting in incorrect setups (e.g.
with cachable ranges larger than requested)), and not working by design for
certain cases (subtractive setups intersecting ranges added later).
Now we maintain an array with the successfully set ranges. When a new range
is added, we recompute the complete MTRR setup as we need to. The new
algorithm analyzing the ranges has linear complexity and also handles range
base addresses with an alignment not matching the range size (e.g. a range
at address 0x1000 with size 0x2000) and joining of adjacent/overlapping
ranges of the same type.

This fixes the slow graphics on my 4 GB machine (though unfortunately the
8 MTRRs aren't enough to fully cover the complete frame buffer (about 35
pixel lines remain uncachable), but that can't be helped without rounding up
the frame buffer size, for which we don't have enough information). It might
also fix #1823.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@34197 a95241bf-73f2-0310-859d-f6bbb57e9c96


# f835a75f3165281a653b891f6bb1a502cc60f65b 13-Jun-2009 Michael Lotz <mmlr@mlotz.ch>

Make two runs of MTRR setting when setting memory ranges to write-back. At the
first run only set up uncacheable MTRRs and in the second run set the write-back
ones up. If this order is not followed, we could set too large ranges to
cacheable first and then limit it back to uncacheable later. On systems with
enough physical memory this would lead to a temporary situation in which areas
become cacheable that must not be, resulting in system hangs or other unexpected
behaviour. Fixes last part of #4018.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@31027 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 9a42ad7a77f11cf1b857e84ec70d21b1afaa71cd 22-Oct-2008 Ingo Weinhold <ingo_weinhold@gmx.de>

When switching to a kernel thread we no longer set the page directory.
This is not necessary, since userland teams' page directories also
contain the kernel mappings, and avoids unnecessary TLB flushes. To make
that possible the vm_translation_map_arch_info objects are reference
counted now.

This optimization reduces the kernel time of the Haiku build on my
machine with SMP disabled a few percent, but interestingly the total
time decreases only marginally. Haven't tested with SMP yet, but for
full impact CPU affinity would be needed.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@28287 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 47c40a10a10dc615e078754503f2c19b9f98c38d 19-Oct-2008 Ingo Weinhold <ingo_weinhold@gmx.de>

* Prefixed memset_physical() and memcpy_to_physical() with "vm_",
added vm_memcpy_from_physical() and vm_memcpy_physical_page(), and
added respective functions to the vm_translation_map operations. The
architecture specific implementation can now decide how to implement
them most efficiently. Added generic implementations that can be used,
though.
* Changed vm_{get,put}_physical_page(). The former no longer accepts
flags (the only flag PHYSICAL_PAGE_DONT_WAIT wasn't needed anymore).
Instead it returns an implementation-specific handle that has to be
passed to the latter. Added vm_{get,put}_physical_page_current_cpu()
and *_debug() variants, that work only for the current CPU,
respectively when in the kernel debugger. Also adjusted the
vm_translation_map operations accordingly.
* Made consequent use of the physical memory operations in the source
tree.
* Also adjusted the m68k and ppc implementations with respect to the
vm_translation_map operation changes, but they are probably broken,
nevertheless.
* For x86 the generic physical page mapper isn't used anymore. It is
suboptimal in any case. For systems with small memory it is too much
overhead, since one can just map the complete physical memory (that's
not done yet, though). For systems with large memory it counteracts
the VM strategy to reuse the least recently used pages. Since those
pages will most likely not be mapped by the page mapper anymore, it
will keep remapping chunks. This was also the reason why building
Haiku in Haiku was significantly faster with only 256 MB RAM (since
that much could be kept mapped all the time).
Now we're using a different strategy: We have small pools of virtual
page slots per CPU that are used for the physical page operations
(memset_physical(), memcpy_*_physical()) with CPU-pinned thread.
Furthermore we have four slots per translation map, which are used to
map page tables.

These changes speed up the Haiku image build in Haiku significantly. On
my Core2 Duo 2.2 GHz 2 GB machine about 40% to 20 min 40 s (KDEBUG
disabled, block cache debug disabled). Still more than factor 3 slower
than FreeBSD and Linux, though.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@28244 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 74785e79db32355e0a8ee6b488672ac09ad57b1b 07-Oct-2008 Ingo Weinhold <ingo_weinhold@gmx.de>

* Added "from" address space parameter to vm_swap_address_space()/
arch_vm_aspace_swap().
* The x86 implementation does now maintain a bit mask per
vm_translation_map_arch_info indicating on which CPUs the address
space is active. This allows flush_tmap() to avoid ICI for user
address spaces when the team isn't currently running on any other CPU.
In this context ICI is relatively expensive, particularly since we map
most pages via vm_map_page() and therefore invoke flush_tmap() pretty
much for every single page.
This optimization speeds up a "hello world" compilation about 20% on
my machine (KDEBUG turned off, freshly booted), but interestingly it
has virtually no effect on the "-j2" haiku build time.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@27912 a95241bf-73f2-0310-859d-f6bbb57e9c96


# b50e620202c4faf76869721957973c0f72e83155 02-Oct-2008 Ingo Weinhold <ingo_weinhold@gmx.de>

Fixed various warnings.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@27841 a95241bf-73f2-0310-859d-f6bbb57e9c96


# f7c655c7e0590089e3de5bb71198fe02cd4afb21 07-Jun-2008 Jérôme Duval <korli@users.berlios.de>

find_nearest() now saves a solution when reaching the max number of solutions and not near enough


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@25859 a95241bf-73f2-0310-859d-f6bbb57e9c96


# c103aef2b3aef83d8f657812e0ef5e3d8fec0593 12-Apr-2008 Jérôme Duval <korli@users.berlios.de>

disabled check for memory overlaps for the time being


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@24946 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 7522f3082d8a249e7ab59381dd35212d52ab398a 30-Mar-2008 Jérôme Duval <korli@users.berlios.de>

reduced MTRR min size to 512KB


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@24679 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 9fcee65eafeef7419d272ed23f29cbb7b501dae9 27-Mar-2008 Jérôme Duval <korli@users.berlios.de>

take into account areas starting or ending equally


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@24612 a95241bf-73f2-0310-859d-f6bbb57e9c96


# cd9ce121d91c3bad01b46c0f10cc65c90ff7cda5 25-Mar-2008 Jérôme Duval <korli@users.berlios.de>

now checks if another mtrr range is extended by a new one and extends it


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@24582 a95241bf-73f2-0310-859d-f6bbb57e9c96


# e958cea5145fb240403dbe836a2a4bbec7aec6e3 20-Mar-2008 Jérôme Duval <korli@users.berlios.de>

now fails if a write combining overlaps


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@24494 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 4e8c60ce4bbb1a2ff3cf1b17729c6a582bfaa383 19-Mar-2008 Jérôme Duval <korli@users.berlios.de>

style cleanup
replaced addr_t by uint64
more debug output


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@24476 a95241bf-73f2-0310-859d-f6bbb57e9c96


# b20d05b4f7bd20ba177d8e46be427b76fcb46db8 18-Mar-2008 Jérôme Duval <korli@users.berlios.de>

clean up, comments, header


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@24452 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 48e299e2efbfb85b2e0dbd598ef4a20c5d15ccdc 17-Mar-2008 Ingo Weinhold <ingo_weinhold@gmx.de>

Fixed warning.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@24438 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 4f893e39ab9363aac919466fd5044afa78a97e39 17-Mar-2008 Jérôme Duval <korli@users.berlios.de>

algorithm to find best suited mtrr values to match a memory region. tested ok with 3071MB.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@24424 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 2d2212bd711f09275aca556bf4d097484e037c25 05-Mar-2008 Jérôme Duval <korli@users.berlios.de>

here with 3GB of memory, a 4GB MTRR slot is being written, which triggers a reboot.
we now split more than 2GB MTRR slot, we might improve this and split more and more.
this could fix the bug #1711.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@24244 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 393fceb5a0d8bd8b73059481ca0f20d285ac7a89 27-Sep-2007 Axel Dörfler <axeld@pinc-software.de>

* Cleaned up vm_types.h a bit, and made vm_page, vm_cache, and vm_area
opaque types for C.
* As a result, I've renamed some more source files to .cpp, and fixed
all warnings caused by that.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@22326 a95241bf-73f2-0310-859d-f6bbb57e9c96