History log of /openbsd-current/sys/arch/arm/arm/pmap7.c
Revision (<<< Hide revision tags) (Show revision tags >>>) Date Author Comments
# 1.66 01-Jan-2023 miod

With the introduction of the PMAP_PREFER_{ALIGN,OFFSET} macros a long time ago,
there are actually no more uses of the PMAP_PREFER() macro left in the kernel.
Remove that macro but keep PMAP_PREFER as a simple #define for it to let uvm
knows the PMAP_PREFER_{ALIGN,OFFSET} macros are available.

ok mpi@


Revision tags: OPENBSD_7_2_BASE
# 1.65 12-Sep-2022 miod

Drop orphaned pv_flags values.


# 1.64 10-Sep-2022 miod

Remove pmap_collect() when a no-op, define __HAVE_PMAP_COLLECT otherwise.
Use that define to shunt uvm_swapout_threads(), which is a noop when
pmap_collect() does nothing.

ok mpi@


Revision tags: OPENBSD_7_1_BASE
# 1.63 21-Feb-2022 kettenis

Convert KVA allocation to km_alloc(9).

ok mpi@


# 1.62 01-Feb-2022 kettenis

Make sure we always pass a page-aligned address to pmap_grow_map().
Fixes an issue uncovered by the recent change to enlarge kva space where
an unaligned address was passed resulting in memset() writing past the
end of the newly allocated page.

ok miod@


Revision tags: OPENBSD_6_9_BASE OPENBSD_7_0_BASE
# 1.61 25-Mar-2021 jsg

remove uneeded includes in md armv7 files

based on include-what-you-use suggestions


# 1.60 11-Mar-2021 jsg

spelling


Revision tags: OPENBSD_6_7_BASE OPENBSD_6_8_BASE
# 1.59 19-Dec-2019 mpi

Convert boolean_t/TRUE/FALSE to int/1/0 for coherency with the rest of
the kernel.

ok patrick@


Revision tags: OPENBSD_6_5_BASE OPENBSD_6_6_BASE
# 1.58 10-Feb-2019 tedu

revert revert revert. there are many other archs that use custom allocs.


# 1.57 10-Feb-2019 tedu

make it possible to reduce kmem pressure by letting some pools use a more
accomodating allocator. an interrupt safe pool may also be used in process
context, as indicated by waitok flags. thanks to the garbage collector, we
can always free pages in process context. the only complication is where
to put the pages. solve this by saving the allocation flags in the pool
page header so the free function can examine them.
not actually used in this diff. (coming soon.)
arm testing and compile fixes from phessler


Revision tags: OPENBSD_6_2_BASE OPENBSD_6_3_BASE OPENBSD_6_4_BASE
# 1.56 08-Sep-2017 deraadt

If you use sys/param.h, you don't need sys/types.h


Revision tags: OPENBSD_6_1_BASE
# 1.55 22-Oct-2016 patrick

If an Access Flag fault happens while we were running the kernel and
it happened on a kernel page, we need to consult the kernel pmap
instead of the current proc's pmap. Fixes panic when using tmpfs.

ok kettenis@


# 1.54 19-Oct-2016 guenther

Change pmap_proc_iflush() to take a process instead of a proc
powerpc: rename second argument of pmap_proc_iflush() to match other archs

ok kettenis@


# 1.53 24-Sep-2016 kettenis

Remove a couple of unsused static inline functions. Also remove a comparis
of an array to a null pointer that is always false. Found with clang.

ok jsg@


# 1.52 15-Sep-2016 dlg

all pools have their ipl set via pool_setipl, so fold it into pool_init.

the ioff argument to pool_init() is unused and has been for many
years, so this replaces it with an ipl argument. because the ipl
will be set on init we no longer need pool_setipl.

most of these changes have been done with coccinelle using the spatch
below. cocci sucks at formatting code though, so i fixed that by hand.

the manpage and subr_pool.c bits i did myself.

ok tedu@ jmatthew@

@ipl@
expression pp;
expression ipl;
expression s, a, o, f, m, p;
@@
-pool_init(pp, s, a, o, f, m, p);
-pool_setipl(pp, ipl);
+pool_init(pp, s, a, ipl, f, m, p);


# 1.51 31-Aug-2016 jsg

In pmap_activate instead of doing disable_interrupts/enable_interrupts
nested inside of splhigh/splx just disable and enable interrupts
once with inline cps instructions.

Remove uneeded pcb_pl1vec block as well, suggested by kettenis.

ok kettenis@


# 1.50 27-Aug-2016 kettenis

Add support for the PXN bit in level 1 translation table descriptors and
enable it on CPUs that support it. When enabled, this prevents the kernel
from executing userland code.

ok jsg@, tom@


# 1.49 26-Aug-2016 kettenis

Remove cpu_cpwait() calls; they are no-ops on armv7.

ok tom@


# 1.48 26-Aug-2016 kettenis

Remove the code that switches around MMU domains on armv7. MMU domains are
basically a relic from the past. Using them doesn't make a lot of sense
the way our pmaps work. Support for MMU domains isn't present in
long-descriptor translation table format, so it is clearly on its way out.

Based on a diff from Artituri Alm.

ok patrick@


# 1.47 24-Aug-2016 kettenis

Replace pmap_fault_fixup() with an access flag fault handler on armv7.

ok tom@


# 1.46 20-Aug-2016 kettenis

Fix indentation.


# 1.45 20-Aug-2016 kettenis

Argh, commit from the wrong tree. Revert previous commit.


# 1.44 20-Aug-2016 kettenis

Fix indentation.


# 1.43 20-Aug-2016 kettenis

Correctly enter a mapping as writable if no "page modified" emulation
is needed.

ok visa@, patrick@


# 1.42 19-Aug-2016 kettenis

Start using to XN flag to enforce that mappings without PROT_EXEC are
non-executable.

ok visa@, deraadt@


# 1.41 19-Aug-2016 kettenis

Mark device memory as execute-never to prevent a speculative instruction fetch
to access it.


# 1.40 19-Aug-2016 kettenis

Use Access Flag to do page reference emulation.

ok visa@


# 1.39 18-Aug-2016 kettenis

Separate out the Access Flag bit from the Access Permission bits in the
armv7 pmap.

ok tom@


# 1.38 16-Aug-2016 kettenis

Fix typo/inconsistensy where L1_S_DOMAIN was used instead of L1_C_DOMAIN.
These are functionally equivolent so it didn't matter and the resulting
code doesn't change.


# 1.37 11-Aug-2016 kettenis

The ARMv7 ARM says that the TLB may hold translation table entries at any
level of the translation table, including entries that point to further
levels of the tables. This means that we have to do a TLB flush whenever
we invalidate an L1 slot too. Doing so fixes the pmap_fault_fixup
issue on Cortex-A7 processors.


# 1.36 09-Aug-2016 kettenis

The page tables are cached now, and given the significant speedup, I
don't think we'll ever go back. So let's ditch the code that tries to
check and patch up incorrect memory attributes.

Also realize that pmap_clean_page(pg, FALSE) doesn't do anything
anymore so remove those calls and drop the 2nd argument from
pmap_clean_page(pg, TRUE) calls.

Last but not least, get rid of pmap_pte_init_generic() here. The only
useful thing it did was setting pmap_copy_page_func() and
pmap_zero_page_func().

This diff should not introduce any change in behaviour.

ok visa@


# 1.35 08-Aug-2016 kettenis

Mapping non-cachable memory as cachable and subsequently changing the mapping
to non-cachable is retarded. Fix this by introducing PMAP_NOCACHE and
PMAP_DEVICE flags that can be or'ed into the physical address passed to
pmap_kenter(9), like we have on many of our other architectures. This way we
can also properly distinguish between device memory and normal (non-cachable)
memory.

ok visa@


# 1.34 08-Aug-2016 kettenis

ARMv7 data caches are "effectively" PIPT. This means there is in general
no need to clean and/or invalidate cached pages. So remove most of the
cache cleaning and invalidation from the pmap. We still need to synchronize
the instruction cache with the data cache in various places though. And we
also need to make sure that we clean and invalidate when we make a page
non-cachable.

Tested by Daniel Bolgheroni, mglocker@ and jsg@. on Cortex-A8 and myself on
Cortex-A9.

ok visa@


# 1.33 06-Aug-2016 kettenis

Put page tables in normal cachable memory on armv7. Check if the MMU walks
the page tables coherently and also skip flushing modified ptes out of the
cache in that case. Speeds up building a kernel with a factor of two on
Cortex-A9 (tested by me) and Cortex-A8 (tested by mglocker@).

ok patrick@


# 1.32 03-Aug-2016 kettenis

Simplify the way we handle TLB flushes. Since ARMv7 effectively has a
unified TLB there is not much point in optimizing TLB flushing for pages
that have never been executable. The only difference is a flush of the
branch predictor and even that isn't necessary anymore on all but the oldest
Cortex cores.

ok patrick@


# 1.31 31-Jul-2016 kettenis

Remove devmap stuff which is unused on armv7.

ok patrick@


# 1.30 31-Jul-2016 kettenis

According to te armv7 ARM TLB entries that caused a Permission fault might
be held in the TLB. On top of that valid page table entries might be
speculatively loaded into the TLB. As a result we need to flush TLB entries
even when the page in question has not been referenced.

Fixes pmap_fault_fixup messages on Cortex-A53, and presumably also on
Cortex-A7.

ok patrick@, guenther@


# 1.29 29-Jul-2016 patrick

Only flush the virtual page if it was actually mapped. Otherwise
we will run into translation faults.

ok tom@


# 1.28 27-Jul-2016 patrick

When pmap_page_remove() is called by UVM, a physical page is to be
removed from pmaps it currently is in. To check if a virtual address
pointing to that physical page has been mapped, the code uses
the l2pte_valid() function. Unfortunately there is a difference
between being valid and the PTE being zero. If a page is mapped
but has never been accessed, it will be non-zero but invalid.

In that case the PTE for that virtual address will not be zeroed
and the virtual address will be removed from the vm page struct.

The next time someone tries to map a page to that virtual address,
other pmap code will consider the virtual address to be already
mapped, even though that assumption is completely wrong.

To make sure this does not happen, check the PTE for zero. This way
the PTE will be zeroed correctly. The check for zero is how other
ARM pmap code also handles this issue.

ok kettenis@ tom@


Revision tags: OPENBSD_6_0_BASE
# 1.27 19-Jul-2016 tom

Remove what appears to be a copy-paste error setting cur_ttb
in pmap_free_l1().

from aalm@ - thanks

ok patrick@


# 1.26 18-Jul-2016 tom

Don't need a separate flags variable in armv7 pmap_clean_page() -
just use the pv_flags. ('Twas a copy-paste from arm's pmap_clean_page(),
which did need it.)

Also remove even less used flags variable from pmap_page_remove().

First part from a diff from aalm@ - thanks

ok kettenis@ "looks good" patrick@


# 1.25 07-Jun-2016 dlg

consistently set ipls on pmap pools.

this is a step toward making ipls unconditionaly on pools.

ok deraadt@ kettenis@


# 1.24 03-Mar-2016 jsg

When a physical address is needed to flush the secondary cache use
VM_PAGE_TO_PHYS() instead of unnecessarily calling pmap_extract().

From Patrick Wildt.


Revision tags: OPENBSD_5_9_BASE
# 1.23 01-Feb-2016 jsg

Fix the encoding of AP bits for large page second-level
short-descriptors with arm v7 (same as small page encoding, except XN is
in a different bit for the mask).

Expanded version of a diff from Patrick Wildt who also tested and
reviewed this.


# 1.22 31-Jan-2016 jsg

Switch from PSR_X_bit and X32_bit PSR macro names to just PSR_X.
This matches FreeBSD and makes things a bit more consistent.
Discussed with Patrick.


# 1.21 08-Sep-2015 kettenis

Give the pool page allocator backends more sensible names. We now have:
* pool_allocator_single: single page allocator, always interrupt safe
* pool_allocator_multi: multi-page allocator, interrupt safe
* pool_allocator_multi_ni: multi-page allocator, not interrupt-safe

ok deraadt@, dlg@


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE
# 1.20 02-Feb-2015 mlarkin

Remove some pmap locks that were #defined to be nothing (empty). Discussed
with many, ok kettenis@.


# 1.19 29-Jan-2015 deraadt

remove no-op simple locks
tested by jsg, ok miod


# 1.18 16-Nov-2014 deraadt

Replace a plethora of historical protection options with just
PROT_NONE, PROT_READ, PROT_WRITE, and PROT_EXEC from mman.h.
PROT_MASK is introduced as the one true way of extracting those bits.
Remove UVM_ADV_* wrapper, using the standard names.
ok doug guenther kettenis


# 1.17 27-Oct-2014 jsg

use #ifdef DDB for Debugger()


# 1.16 07-Oct-2014 jsg

Correct the l1 pte permission bits for armv7. Problem pointed out
by Patrick Wildt who made a similiar change in Bitrig.

ok miod@ rapha@


Revision tags: OPENBSD_5_6_BASE
# 1.15 12-Jul-2014 tedu

add a size argument to free. will be used soon, but for now default to 0.
after discussions with beck deraadt kettenis.


# 1.14 08-May-2014 miod

Format string fixes and removal of -Wno-format for arm kernels.


# 1.13 29-Mar-2014 guenther

It's been a quarter century: we can assume volatile is present with that name.

ok dlg@ mpi@ deraadt@


Revision tags: OPENBSD_5_5_BASE
# 1.12 04-Nov-2013 dlg

move the arm pmaps away from pool ctors to just initting memory after its
been allocated. also gets rid of a potential bug where pool_get could
return NULL and pmap_alloc_l2_ptp tried to blindly init it.

tests, tweaks, and ok patrick@


# 1.11 29-Oct-2013 patrick

The cache mask for ARMv7 is a little bit different from the one inited by
the generic function. While there, also set the cache bits manually.

ok aalm@


# 1.10 22-Oct-2013 patrick

Some current boards do not have write-through caching. For those,
we enable write-back, but it seems this is not working and those
boards hang on bootup. Until that is fixed, do not cache PTEs
on those boards.


# 1.9 03-Sep-2013 patrick

Rewrite the ARMv7 cache discovery, as some assumptions in the previous one
were utterly wrong. Fix Log2(), correct one taken from the scheduler code.

Tested by rapha@ and Artturi Alm.


Revision tags: OPENBSD_5_4_BASE
# 1.8 09-Jun-2013 miod

typo


# 1.7 22-May-2013 patrick

We're handling L2 there, so use the corresponding define, not the L1 one.

ok bmercer@


# 1.6 21-May-2013 patrick

When mapping a new entry, map it read-only, even though it should be
writable. This will cause a pmap fault on first write, so that we can
mark the page as modified. Also mask the bits used for the protection
settings, so that there aren't any leftovers.

ok bmercer@


# 1.5 09-May-2013 patrick

On ARMv7 we can't use the cache mask to check for coherency.
Therefore we add new macros to be able to check for it properly.

ok miod@


# 1.4 28-Apr-2013 patrick

Revert the ARMv7 header split introduced in pmap7.

ok bmercer@


# 1.3 16-Apr-2013 patrick

Add secondary cache flushes to armv7's pmap.

ok bmercer@


# 1.2 27-Mar-2013 patrick

Further updates to pmap7. Fixes some problems and removes debug printfs.

ok miod@


Revision tags: OPENBSD_5_3_BASE
# 1.1 17-Jan-2013 bmercer

New pmap for panda boards. Work from lots of folks.
OK miod@


# 1.65 12-Sep-2022 miod

Drop orphaned pv_flags values.


# 1.64 10-Sep-2022 miod

Remove pmap_collect() when a no-op, define __HAVE_PMAP_COLLECT otherwise.
Use that define to shunt uvm_swapout_threads(), which is a noop when
pmap_collect() does nothing.

ok mpi@


Revision tags: OPENBSD_7_1_BASE
# 1.63 21-Feb-2022 kettenis

Convert KVA allocation to km_alloc(9).

ok mpi@


# 1.62 01-Feb-2022 kettenis

Make sure we always pass a page-aligned address to pmap_grow_map().
Fixes an issue uncovered by the recent change to enlarge kva space where
an unaligned address was passed resulting in memset() writing past the
end of the newly allocated page.

ok miod@


Revision tags: OPENBSD_6_9_BASE OPENBSD_7_0_BASE
# 1.61 25-Mar-2021 jsg

remove uneeded includes in md armv7 files

based on include-what-you-use suggestions


# 1.60 11-Mar-2021 jsg

spelling


Revision tags: OPENBSD_6_7_BASE OPENBSD_6_8_BASE
# 1.59 19-Dec-2019 mpi

Convert boolean_t/TRUE/FALSE to int/1/0 for coherency with the rest of
the kernel.

ok patrick@


Revision tags: OPENBSD_6_5_BASE OPENBSD_6_6_BASE
# 1.58 10-Feb-2019 tedu

revert revert revert. there are many other archs that use custom allocs.


# 1.57 10-Feb-2019 tedu

make it possible to reduce kmem pressure by letting some pools use a more
accomodating allocator. an interrupt safe pool may also be used in process
context, as indicated by waitok flags. thanks to the garbage collector, we
can always free pages in process context. the only complication is where
to put the pages. solve this by saving the allocation flags in the pool
page header so the free function can examine them.
not actually used in this diff. (coming soon.)
arm testing and compile fixes from phessler


Revision tags: OPENBSD_6_2_BASE OPENBSD_6_3_BASE OPENBSD_6_4_BASE
# 1.56 08-Sep-2017 deraadt

If you use sys/param.h, you don't need sys/types.h


Revision tags: OPENBSD_6_1_BASE
# 1.55 22-Oct-2016 patrick

If an Access Flag fault happens while we were running the kernel and
it happened on a kernel page, we need to consult the kernel pmap
instead of the current proc's pmap. Fixes panic when using tmpfs.

ok kettenis@


# 1.54 19-Oct-2016 guenther

Change pmap_proc_iflush() to take a process instead of a proc
powerpc: rename second argument of pmap_proc_iflush() to match other archs

ok kettenis@


# 1.53 24-Sep-2016 kettenis

Remove a couple of unsused static inline functions. Also remove a comparis
of an array to a null pointer that is always false. Found with clang.

ok jsg@


# 1.52 15-Sep-2016 dlg

all pools have their ipl set via pool_setipl, so fold it into pool_init.

the ioff argument to pool_init() is unused and has been for many
years, so this replaces it with an ipl argument. because the ipl
will be set on init we no longer need pool_setipl.

most of these changes have been done with coccinelle using the spatch
below. cocci sucks at formatting code though, so i fixed that by hand.

the manpage and subr_pool.c bits i did myself.

ok tedu@ jmatthew@

@ipl@
expression pp;
expression ipl;
expression s, a, o, f, m, p;
@@
-pool_init(pp, s, a, o, f, m, p);
-pool_setipl(pp, ipl);
+pool_init(pp, s, a, ipl, f, m, p);


# 1.51 31-Aug-2016 jsg

In pmap_activate instead of doing disable_interrupts/enable_interrupts
nested inside of splhigh/splx just disable and enable interrupts
once with inline cps instructions.

Remove uneeded pcb_pl1vec block as well, suggested by kettenis.

ok kettenis@


# 1.50 27-Aug-2016 kettenis

Add support for the PXN bit in level 1 translation table descriptors and
enable it on CPUs that support it. When enabled, this prevents the kernel
from executing userland code.

ok jsg@, tom@


# 1.49 26-Aug-2016 kettenis

Remove cpu_cpwait() calls; they are no-ops on armv7.

ok tom@


# 1.48 26-Aug-2016 kettenis

Remove the code that switches around MMU domains on armv7. MMU domains are
basically a relic from the past. Using them doesn't make a lot of sense
the way our pmaps work. Support for MMU domains isn't present in
long-descriptor translation table format, so it is clearly on its way out.

Based on a diff from Artituri Alm.

ok patrick@


# 1.47 24-Aug-2016 kettenis

Replace pmap_fault_fixup() with an access flag fault handler on armv7.

ok tom@


# 1.46 20-Aug-2016 kettenis

Fix indentation.


# 1.45 20-Aug-2016 kettenis

Argh, commit from the wrong tree. Revert previous commit.


# 1.44 20-Aug-2016 kettenis

Fix indentation.


# 1.43 20-Aug-2016 kettenis

Correctly enter a mapping as writable if no "page modified" emulation
is needed.

ok visa@, patrick@


# 1.42 19-Aug-2016 kettenis

Start using to XN flag to enforce that mappings without PROT_EXEC are
non-executable.

ok visa@, deraadt@


# 1.41 19-Aug-2016 kettenis

Mark device memory as execute-never to prevent a speculative instruction fetch
to access it.


# 1.40 19-Aug-2016 kettenis

Use Access Flag to do page reference emulation.

ok visa@


# 1.39 18-Aug-2016 kettenis

Separate out the Access Flag bit from the Access Permission bits in the
armv7 pmap.

ok tom@


# 1.38 16-Aug-2016 kettenis

Fix typo/inconsistensy where L1_S_DOMAIN was used instead of L1_C_DOMAIN.
These are functionally equivolent so it didn't matter and the resulting
code doesn't change.


# 1.37 11-Aug-2016 kettenis

The ARMv7 ARM says that the TLB may hold translation table entries at any
level of the translation table, including entries that point to further
levels of the tables. This means that we have to do a TLB flush whenever
we invalidate an L1 slot too. Doing so fixes the pmap_fault_fixup
issue on Cortex-A7 processors.


# 1.36 09-Aug-2016 kettenis

The page tables are cached now, and given the significant speedup, I
don't think we'll ever go back. So let's ditch the code that tries to
check and patch up incorrect memory attributes.

Also realize that pmap_clean_page(pg, FALSE) doesn't do anything
anymore so remove those calls and drop the 2nd argument from
pmap_clean_page(pg, TRUE) calls.

Last but not least, get rid of pmap_pte_init_generic() here. The only
useful thing it did was setting pmap_copy_page_func() and
pmap_zero_page_func().

This diff should not introduce any change in behaviour.

ok visa@


# 1.35 08-Aug-2016 kettenis

Mapping non-cachable memory as cachable and subsequently changing the mapping
to non-cachable is retarded. Fix this by introducing PMAP_NOCACHE and
PMAP_DEVICE flags that can be or'ed into the physical address passed to
pmap_kenter(9), like we have on many of our other architectures. This way we
can also properly distinguish between device memory and normal (non-cachable)
memory.

ok visa@


# 1.34 08-Aug-2016 kettenis

ARMv7 data caches are "effectively" PIPT. This means there is in general
no need to clean and/or invalidate cached pages. So remove most of the
cache cleaning and invalidation from the pmap. We still need to synchronize
the instruction cache with the data cache in various places though. And we
also need to make sure that we clean and invalidate when we make a page
non-cachable.

Tested by Daniel Bolgheroni, mglocker@ and jsg@. on Cortex-A8 and myself on
Cortex-A9.

ok visa@


# 1.33 06-Aug-2016 kettenis

Put page tables in normal cachable memory on armv7. Check if the MMU walks
the page tables coherently and also skip flushing modified ptes out of the
cache in that case. Speeds up building a kernel with a factor of two on
Cortex-A9 (tested by me) and Cortex-A8 (tested by mglocker@).

ok patrick@


# 1.32 03-Aug-2016 kettenis

Simplify the way we handle TLB flushes. Since ARMv7 effectively has a
unified TLB there is not much point in optimizing TLB flushing for pages
that have never been executable. The only difference is a flush of the
branch predictor and even that isn't necessary anymore on all but the oldest
Cortex cores.

ok patrick@


# 1.31 31-Jul-2016 kettenis

Remove devmap stuff which is unused on armv7.

ok patrick@


# 1.30 31-Jul-2016 kettenis

According to te armv7 ARM TLB entries that caused a Permission fault might
be held in the TLB. On top of that valid page table entries might be
speculatively loaded into the TLB. As a result we need to flush TLB entries
even when the page in question has not been referenced.

Fixes pmap_fault_fixup messages on Cortex-A53, and presumably also on
Cortex-A7.

ok patrick@, guenther@


# 1.29 29-Jul-2016 patrick

Only flush the virtual page if it was actually mapped. Otherwise
we will run into translation faults.

ok tom@


# 1.28 27-Jul-2016 patrick

When pmap_page_remove() is called by UVM, a physical page is to be
removed from pmaps it currently is in. To check if a virtual address
pointing to that physical page has been mapped, the code uses
the l2pte_valid() function. Unfortunately there is a difference
between being valid and the PTE being zero. If a page is mapped
but has never been accessed, it will be non-zero but invalid.

In that case the PTE for that virtual address will not be zeroed
and the virtual address will be removed from the vm page struct.

The next time someone tries to map a page to that virtual address,
other pmap code will consider the virtual address to be already
mapped, even though that assumption is completely wrong.

To make sure this does not happen, check the PTE for zero. This way
the PTE will be zeroed correctly. The check for zero is how other
ARM pmap code also handles this issue.

ok kettenis@ tom@


Revision tags: OPENBSD_6_0_BASE
# 1.27 19-Jul-2016 tom

Remove what appears to be a copy-paste error setting cur_ttb
in pmap_free_l1().

from aalm@ - thanks

ok patrick@


# 1.26 18-Jul-2016 tom

Don't need a separate flags variable in armv7 pmap_clean_page() -
just use the pv_flags. ('Twas a copy-paste from arm's pmap_clean_page(),
which did need it.)

Also remove even less used flags variable from pmap_page_remove().

First part from a diff from aalm@ - thanks

ok kettenis@ "looks good" patrick@


# 1.25 07-Jun-2016 dlg

consistently set ipls on pmap pools.

this is a step toward making ipls unconditionaly on pools.

ok deraadt@ kettenis@


# 1.24 03-Mar-2016 jsg

When a physical address is needed to flush the secondary cache use
VM_PAGE_TO_PHYS() instead of unnecessarily calling pmap_extract().

From Patrick Wildt.


Revision tags: OPENBSD_5_9_BASE
# 1.23 01-Feb-2016 jsg

Fix the encoding of AP bits for large page second-level
short-descriptors with arm v7 (same as small page encoding, except XN is
in a different bit for the mask).

Expanded version of a diff from Patrick Wildt who also tested and
reviewed this.


# 1.22 31-Jan-2016 jsg

Switch from PSR_X_bit and X32_bit PSR macro names to just PSR_X.
This matches FreeBSD and makes things a bit more consistent.
Discussed with Patrick.


# 1.21 08-Sep-2015 kettenis

Give the pool page allocator backends more sensible names. We now have:
* pool_allocator_single: single page allocator, always interrupt safe
* pool_allocator_multi: multi-page allocator, interrupt safe
* pool_allocator_multi_ni: multi-page allocator, not interrupt-safe

ok deraadt@, dlg@


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE
# 1.20 02-Feb-2015 mlarkin

Remove some pmap locks that were #defined to be nothing (empty). Discussed
with many, ok kettenis@.


# 1.19 29-Jan-2015 deraadt

remove no-op simple locks
tested by jsg, ok miod


# 1.18 16-Nov-2014 deraadt

Replace a plethora of historical protection options with just
PROT_NONE, PROT_READ, PROT_WRITE, and PROT_EXEC from mman.h.
PROT_MASK is introduced as the one true way of extracting those bits.
Remove UVM_ADV_* wrapper, using the standard names.
ok doug guenther kettenis


# 1.17 27-Oct-2014 jsg

use #ifdef DDB for Debugger()


# 1.16 07-Oct-2014 jsg

Correct the l1 pte permission bits for armv7. Problem pointed out
by Patrick Wildt who made a similiar change in Bitrig.

ok miod@ rapha@


Revision tags: OPENBSD_5_6_BASE
# 1.15 12-Jul-2014 tedu

add a size argument to free. will be used soon, but for now default to 0.
after discussions with beck deraadt kettenis.


# 1.14 08-May-2014 miod

Format string fixes and removal of -Wno-format for arm kernels.


# 1.13 29-Mar-2014 guenther

It's been a quarter century: we can assume volatile is present with that name.

ok dlg@ mpi@ deraadt@


Revision tags: OPENBSD_5_5_BASE
# 1.12 04-Nov-2013 dlg

move the arm pmaps away from pool ctors to just initting memory after its
been allocated. also gets rid of a potential bug where pool_get could
return NULL and pmap_alloc_l2_ptp tried to blindly init it.

tests, tweaks, and ok patrick@


# 1.11 29-Oct-2013 patrick

The cache mask for ARMv7 is a little bit different from the one inited by
the generic function. While there, also set the cache bits manually.

ok aalm@


# 1.10 22-Oct-2013 patrick

Some current boards do not have write-through caching. For those,
we enable write-back, but it seems this is not working and those
boards hang on bootup. Until that is fixed, do not cache PTEs
on those boards.


# 1.9 03-Sep-2013 patrick

Rewrite the ARMv7 cache discovery, as some assumptions in the previous one
were utterly wrong. Fix Log2(), correct one taken from the scheduler code.

Tested by rapha@ and Artturi Alm.


Revision tags: OPENBSD_5_4_BASE
# 1.8 09-Jun-2013 miod

typo


# 1.7 22-May-2013 patrick

We're handling L2 there, so use the corresponding define, not the L1 one.

ok bmercer@


# 1.6 21-May-2013 patrick

When mapping a new entry, map it read-only, even though it should be
writable. This will cause a pmap fault on first write, so that we can
mark the page as modified. Also mask the bits used for the protection
settings, so that there aren't any leftovers.

ok bmercer@


# 1.5 09-May-2013 patrick

On ARMv7 we can't use the cache mask to check for coherency.
Therefore we add new macros to be able to check for it properly.

ok miod@


# 1.4 28-Apr-2013 patrick

Revert the ARMv7 header split introduced in pmap7.

ok bmercer@


# 1.3 16-Apr-2013 patrick

Add secondary cache flushes to armv7's pmap.

ok bmercer@


# 1.2 27-Mar-2013 patrick

Further updates to pmap7. Fixes some problems and removes debug printfs.

ok miod@


Revision tags: OPENBSD_5_3_BASE
# 1.1 17-Jan-2013 bmercer

New pmap for panda boards. Work from lots of folks.
OK miod@


# 1.64 10-Sep-2022 miod

Remove pmap_collect() when a no-op, define __HAVE_PMAP_COLLECT otherwise.
Use that define to shunt uvm_swapout_threads(), which is a noop when
pmap_collect() does nothing.

ok mpi@


Revision tags: OPENBSD_7_1_BASE
# 1.63 21-Feb-2022 kettenis

Convert KVA allocation to km_alloc(9).

ok mpi@


# 1.62 01-Feb-2022 kettenis

Make sure we always pass a page-aligned address to pmap_grow_map().
Fixes an issue uncovered by the recent change to enlarge kva space where
an unaligned address was passed resulting in memset() writing past the
end of the newly allocated page.

ok miod@


Revision tags: OPENBSD_6_9_BASE OPENBSD_7_0_BASE
# 1.61 25-Mar-2021 jsg

remove uneeded includes in md armv7 files

based on include-what-you-use suggestions


# 1.60 11-Mar-2021 jsg

spelling


Revision tags: OPENBSD_6_7_BASE OPENBSD_6_8_BASE
# 1.59 19-Dec-2019 mpi

Convert boolean_t/TRUE/FALSE to int/1/0 for coherency with the rest of
the kernel.

ok patrick@


Revision tags: OPENBSD_6_5_BASE OPENBSD_6_6_BASE
# 1.58 10-Feb-2019 tedu

revert revert revert. there are many other archs that use custom allocs.


# 1.57 10-Feb-2019 tedu

make it possible to reduce kmem pressure by letting some pools use a more
accomodating allocator. an interrupt safe pool may also be used in process
context, as indicated by waitok flags. thanks to the garbage collector, we
can always free pages in process context. the only complication is where
to put the pages. solve this by saving the allocation flags in the pool
page header so the free function can examine them.
not actually used in this diff. (coming soon.)
arm testing and compile fixes from phessler


Revision tags: OPENBSD_6_2_BASE OPENBSD_6_3_BASE OPENBSD_6_4_BASE
# 1.56 08-Sep-2017 deraadt

If you use sys/param.h, you don't need sys/types.h


Revision tags: OPENBSD_6_1_BASE
# 1.55 22-Oct-2016 patrick

If an Access Flag fault happens while we were running the kernel and
it happened on a kernel page, we need to consult the kernel pmap
instead of the current proc's pmap. Fixes panic when using tmpfs.

ok kettenis@


# 1.54 19-Oct-2016 guenther

Change pmap_proc_iflush() to take a process instead of a proc
powerpc: rename second argument of pmap_proc_iflush() to match other archs

ok kettenis@


# 1.53 24-Sep-2016 kettenis

Remove a couple of unsused static inline functions. Also remove a comparis
of an array to a null pointer that is always false. Found with clang.

ok jsg@


# 1.52 15-Sep-2016 dlg

all pools have their ipl set via pool_setipl, so fold it into pool_init.

the ioff argument to pool_init() is unused and has been for many
years, so this replaces it with an ipl argument. because the ipl
will be set on init we no longer need pool_setipl.

most of these changes have been done with coccinelle using the spatch
below. cocci sucks at formatting code though, so i fixed that by hand.

the manpage and subr_pool.c bits i did myself.

ok tedu@ jmatthew@

@ipl@
expression pp;
expression ipl;
expression s, a, o, f, m, p;
@@
-pool_init(pp, s, a, o, f, m, p);
-pool_setipl(pp, ipl);
+pool_init(pp, s, a, ipl, f, m, p);


# 1.51 31-Aug-2016 jsg

In pmap_activate instead of doing disable_interrupts/enable_interrupts
nested inside of splhigh/splx just disable and enable interrupts
once with inline cps instructions.

Remove uneeded pcb_pl1vec block as well, suggested by kettenis.

ok kettenis@


# 1.50 27-Aug-2016 kettenis

Add support for the PXN bit in level 1 translation table descriptors and
enable it on CPUs that support it. When enabled, this prevents the kernel
from executing userland code.

ok jsg@, tom@


# 1.49 26-Aug-2016 kettenis

Remove cpu_cpwait() calls; they are no-ops on armv7.

ok tom@


# 1.48 26-Aug-2016 kettenis

Remove the code that switches around MMU domains on armv7. MMU domains are
basically a relic from the past. Using them doesn't make a lot of sense
the way our pmaps work. Support for MMU domains isn't present in
long-descriptor translation table format, so it is clearly on its way out.

Based on a diff from Artituri Alm.

ok patrick@


# 1.47 24-Aug-2016 kettenis

Replace pmap_fault_fixup() with an access flag fault handler on armv7.

ok tom@


# 1.46 20-Aug-2016 kettenis

Fix indentation.


# 1.45 20-Aug-2016 kettenis

Argh, commit from the wrong tree. Revert previous commit.


# 1.44 20-Aug-2016 kettenis

Fix indentation.


# 1.43 20-Aug-2016 kettenis

Correctly enter a mapping as writable if no "page modified" emulation
is needed.

ok visa@, patrick@


# 1.42 19-Aug-2016 kettenis

Start using to XN flag to enforce that mappings without PROT_EXEC are
non-executable.

ok visa@, deraadt@


# 1.41 19-Aug-2016 kettenis

Mark device memory as execute-never to prevent a speculative instruction fetch
to access it.


# 1.40 19-Aug-2016 kettenis

Use Access Flag to do page reference emulation.

ok visa@


# 1.39 18-Aug-2016 kettenis

Separate out the Access Flag bit from the Access Permission bits in the
armv7 pmap.

ok tom@


# 1.38 16-Aug-2016 kettenis

Fix typo/inconsistensy where L1_S_DOMAIN was used instead of L1_C_DOMAIN.
These are functionally equivolent so it didn't matter and the resulting
code doesn't change.


# 1.37 11-Aug-2016 kettenis

The ARMv7 ARM says that the TLB may hold translation table entries at any
level of the translation table, including entries that point to further
levels of the tables. This means that we have to do a TLB flush whenever
we invalidate an L1 slot too. Doing so fixes the pmap_fault_fixup
issue on Cortex-A7 processors.


# 1.36 09-Aug-2016 kettenis

The page tables are cached now, and given the significant speedup, I
don't think we'll ever go back. So let's ditch the code that tries to
check and patch up incorrect memory attributes.

Also realize that pmap_clean_page(pg, FALSE) doesn't do anything
anymore so remove those calls and drop the 2nd argument from
pmap_clean_page(pg, TRUE) calls.

Last but not least, get rid of pmap_pte_init_generic() here. The only
useful thing it did was setting pmap_copy_page_func() and
pmap_zero_page_func().

This diff should not introduce any change in behaviour.

ok visa@


# 1.35 08-Aug-2016 kettenis

Mapping non-cachable memory as cachable and subsequently changing the mapping
to non-cachable is retarded. Fix this by introducing PMAP_NOCACHE and
PMAP_DEVICE flags that can be or'ed into the physical address passed to
pmap_kenter(9), like we have on many of our other architectures. This way we
can also properly distinguish between device memory and normal (non-cachable)
memory.

ok visa@


# 1.34 08-Aug-2016 kettenis

ARMv7 data caches are "effectively" PIPT. This means there is in general
no need to clean and/or invalidate cached pages. So remove most of the
cache cleaning and invalidation from the pmap. We still need to synchronize
the instruction cache with the data cache in various places though. And we
also need to make sure that we clean and invalidate when we make a page
non-cachable.

Tested by Daniel Bolgheroni, mglocker@ and jsg@. on Cortex-A8 and myself on
Cortex-A9.

ok visa@


# 1.33 06-Aug-2016 kettenis

Put page tables in normal cachable memory on armv7. Check if the MMU walks
the page tables coherently and also skip flushing modified ptes out of the
cache in that case. Speeds up building a kernel with a factor of two on
Cortex-A9 (tested by me) and Cortex-A8 (tested by mglocker@).

ok patrick@


# 1.32 03-Aug-2016 kettenis

Simplify the way we handle TLB flushes. Since ARMv7 effectively has a
unified TLB there is not much point in optimizing TLB flushing for pages
that have never been executable. The only difference is a flush of the
branch predictor and even that isn't necessary anymore on all but the oldest
Cortex cores.

ok patrick@


# 1.31 31-Jul-2016 kettenis

Remove devmap stuff which is unused on armv7.

ok patrick@


# 1.30 31-Jul-2016 kettenis

According to te armv7 ARM TLB entries that caused a Permission fault might
be held in the TLB. On top of that valid page table entries might be
speculatively loaded into the TLB. As a result we need to flush TLB entries
even when the page in question has not been referenced.

Fixes pmap_fault_fixup messages on Cortex-A53, and presumably also on
Cortex-A7.

ok patrick@, guenther@


# 1.29 29-Jul-2016 patrick

Only flush the virtual page if it was actually mapped. Otherwise
we will run into translation faults.

ok tom@


# 1.28 27-Jul-2016 patrick

When pmap_page_remove() is called by UVM, a physical page is to be
removed from pmaps it currently is in. To check if a virtual address
pointing to that physical page has been mapped, the code uses
the l2pte_valid() function. Unfortunately there is a difference
between being valid and the PTE being zero. If a page is mapped
but has never been accessed, it will be non-zero but invalid.

In that case the PTE for that virtual address will not be zeroed
and the virtual address will be removed from the vm page struct.

The next time someone tries to map a page to that virtual address,
other pmap code will consider the virtual address to be already
mapped, even though that assumption is completely wrong.

To make sure this does not happen, check the PTE for zero. This way
the PTE will be zeroed correctly. The check for zero is how other
ARM pmap code also handles this issue.

ok kettenis@ tom@


Revision tags: OPENBSD_6_0_BASE
# 1.27 19-Jul-2016 tom

Remove what appears to be a copy-paste error setting cur_ttb
in pmap_free_l1().

from aalm@ - thanks

ok patrick@


# 1.26 18-Jul-2016 tom

Don't need a separate flags variable in armv7 pmap_clean_page() -
just use the pv_flags. ('Twas a copy-paste from arm's pmap_clean_page(),
which did need it.)

Also remove even less used flags variable from pmap_page_remove().

First part from a diff from aalm@ - thanks

ok kettenis@ "looks good" patrick@


# 1.25 07-Jun-2016 dlg

consistently set ipls on pmap pools.

this is a step toward making ipls unconditionaly on pools.

ok deraadt@ kettenis@


# 1.24 03-Mar-2016 jsg

When a physical address is needed to flush the secondary cache use
VM_PAGE_TO_PHYS() instead of unnecessarily calling pmap_extract().

From Patrick Wildt.


Revision tags: OPENBSD_5_9_BASE
# 1.23 01-Feb-2016 jsg

Fix the encoding of AP bits for large page second-level
short-descriptors with arm v7 (same as small page encoding, except XN is
in a different bit for the mask).

Expanded version of a diff from Patrick Wildt who also tested and
reviewed this.


# 1.22 31-Jan-2016 jsg

Switch from PSR_X_bit and X32_bit PSR macro names to just PSR_X.
This matches FreeBSD and makes things a bit more consistent.
Discussed with Patrick.


# 1.21 08-Sep-2015 kettenis

Give the pool page allocator backends more sensible names. We now have:
* pool_allocator_single: single page allocator, always interrupt safe
* pool_allocator_multi: multi-page allocator, interrupt safe
* pool_allocator_multi_ni: multi-page allocator, not interrupt-safe

ok deraadt@, dlg@


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE
# 1.20 02-Feb-2015 mlarkin

Remove some pmap locks that were #defined to be nothing (empty). Discussed
with many, ok kettenis@.


# 1.19 29-Jan-2015 deraadt

remove no-op simple locks
tested by jsg, ok miod


# 1.18 16-Nov-2014 deraadt

Replace a plethora of historical protection options with just
PROT_NONE, PROT_READ, PROT_WRITE, and PROT_EXEC from mman.h.
PROT_MASK is introduced as the one true way of extracting those bits.
Remove UVM_ADV_* wrapper, using the standard names.
ok doug guenther kettenis


# 1.17 27-Oct-2014 jsg

use #ifdef DDB for Debugger()


# 1.16 07-Oct-2014 jsg

Correct the l1 pte permission bits for armv7. Problem pointed out
by Patrick Wildt who made a similiar change in Bitrig.

ok miod@ rapha@


Revision tags: OPENBSD_5_6_BASE
# 1.15 12-Jul-2014 tedu

add a size argument to free. will be used soon, but for now default to 0.
after discussions with beck deraadt kettenis.


# 1.14 08-May-2014 miod

Format string fixes and removal of -Wno-format for arm kernels.


# 1.13 29-Mar-2014 guenther

It's been a quarter century: we can assume volatile is present with that name.

ok dlg@ mpi@ deraadt@


Revision tags: OPENBSD_5_5_BASE
# 1.12 04-Nov-2013 dlg

move the arm pmaps away from pool ctors to just initting memory after its
been allocated. also gets rid of a potential bug where pool_get could
return NULL and pmap_alloc_l2_ptp tried to blindly init it.

tests, tweaks, and ok patrick@


# 1.11 29-Oct-2013 patrick

The cache mask for ARMv7 is a little bit different from the one inited by
the generic function. While there, also set the cache bits manually.

ok aalm@


# 1.10 22-Oct-2013 patrick

Some current boards do not have write-through caching. For those,
we enable write-back, but it seems this is not working and those
boards hang on bootup. Until that is fixed, do not cache PTEs
on those boards.


# 1.9 03-Sep-2013 patrick

Rewrite the ARMv7 cache discovery, as some assumptions in the previous one
were utterly wrong. Fix Log2(), correct one taken from the scheduler code.

Tested by rapha@ and Artturi Alm.


Revision tags: OPENBSD_5_4_BASE
# 1.8 09-Jun-2013 miod

typo


# 1.7 22-May-2013 patrick

We're handling L2 there, so use the corresponding define, not the L1 one.

ok bmercer@


# 1.6 21-May-2013 patrick

When mapping a new entry, map it read-only, even though it should be
writable. This will cause a pmap fault on first write, so that we can
mark the page as modified. Also mask the bits used for the protection
settings, so that there aren't any leftovers.

ok bmercer@


# 1.5 09-May-2013 patrick

On ARMv7 we can't use the cache mask to check for coherency.
Therefore we add new macros to be able to check for it properly.

ok miod@


# 1.4 28-Apr-2013 patrick

Revert the ARMv7 header split introduced in pmap7.

ok bmercer@


# 1.3 16-Apr-2013 patrick

Add secondary cache flushes to armv7's pmap.

ok bmercer@


# 1.2 27-Mar-2013 patrick

Further updates to pmap7. Fixes some problems and removes debug printfs.

ok miod@


Revision tags: OPENBSD_5_3_BASE
# 1.1 17-Jan-2013 bmercer

New pmap for panda boards. Work from lots of folks.
OK miod@


# 1.63 21-Feb-2022 kettenis

Convert KVA allocation to km_alloc(9).

ok mpi@


# 1.62 01-Feb-2022 kettenis

Make sure we always pass a page-aligned address to pmap_grow_map().
Fixes an issue uncovered by the recent change to enlarge kva space where
an unaligned address was passed resulting in memset() writing past the
end of the newly allocated page.

ok miod@


Revision tags: OPENBSD_6_9_BASE OPENBSD_7_0_BASE
# 1.61 25-Mar-2021 jsg

remove uneeded includes in md armv7 files

based on include-what-you-use suggestions


# 1.60 11-Mar-2021 jsg

spelling


Revision tags: OPENBSD_6_7_BASE OPENBSD_6_8_BASE
# 1.59 19-Dec-2019 mpi

Convert boolean_t/TRUE/FALSE to int/1/0 for coherency with the rest of
the kernel.

ok patrick@


Revision tags: OPENBSD_6_5_BASE OPENBSD_6_6_BASE
# 1.58 10-Feb-2019 tedu

revert revert revert. there are many other archs that use custom allocs.


# 1.57 10-Feb-2019 tedu

make it possible to reduce kmem pressure by letting some pools use a more
accomodating allocator. an interrupt safe pool may also be used in process
context, as indicated by waitok flags. thanks to the garbage collector, we
can always free pages in process context. the only complication is where
to put the pages. solve this by saving the allocation flags in the pool
page header so the free function can examine them.
not actually used in this diff. (coming soon.)
arm testing and compile fixes from phessler


Revision tags: OPENBSD_6_2_BASE OPENBSD_6_3_BASE OPENBSD_6_4_BASE
# 1.56 08-Sep-2017 deraadt

If you use sys/param.h, you don't need sys/types.h


Revision tags: OPENBSD_6_1_BASE
# 1.55 22-Oct-2016 patrick

If an Access Flag fault happens while we were running the kernel and
it happened on a kernel page, we need to consult the kernel pmap
instead of the current proc's pmap. Fixes panic when using tmpfs.

ok kettenis@


# 1.54 19-Oct-2016 guenther

Change pmap_proc_iflush() to take a process instead of a proc
powerpc: rename second argument of pmap_proc_iflush() to match other archs

ok kettenis@


# 1.53 24-Sep-2016 kettenis

Remove a couple of unsused static inline functions. Also remove a comparis
of an array to a null pointer that is always false. Found with clang.

ok jsg@


# 1.52 15-Sep-2016 dlg

all pools have their ipl set via pool_setipl, so fold it into pool_init.

the ioff argument to pool_init() is unused and has been for many
years, so this replaces it with an ipl argument. because the ipl
will be set on init we no longer need pool_setipl.

most of these changes have been done with coccinelle using the spatch
below. cocci sucks at formatting code though, so i fixed that by hand.

the manpage and subr_pool.c bits i did myself.

ok tedu@ jmatthew@

@ipl@
expression pp;
expression ipl;
expression s, a, o, f, m, p;
@@
-pool_init(pp, s, a, o, f, m, p);
-pool_setipl(pp, ipl);
+pool_init(pp, s, a, ipl, f, m, p);


# 1.51 31-Aug-2016 jsg

In pmap_activate instead of doing disable_interrupts/enable_interrupts
nested inside of splhigh/splx just disable and enable interrupts
once with inline cps instructions.

Remove uneeded pcb_pl1vec block as well, suggested by kettenis.

ok kettenis@


# 1.50 27-Aug-2016 kettenis

Add support for the PXN bit in level 1 translation table descriptors and
enable it on CPUs that support it. When enabled, this prevents the kernel
from executing userland code.

ok jsg@, tom@


# 1.49 26-Aug-2016 kettenis

Remove cpu_cpwait() calls; they are no-ops on armv7.

ok tom@


# 1.48 26-Aug-2016 kettenis

Remove the code that switches around MMU domains on armv7. MMU domains are
basically a relic from the past. Using them doesn't make a lot of sense
the way our pmaps work. Support for MMU domains isn't present in
long-descriptor translation table format, so it is clearly on its way out.

Based on a diff from Artituri Alm.

ok patrick@


# 1.47 24-Aug-2016 kettenis

Replace pmap_fault_fixup() with an access flag fault handler on armv7.

ok tom@


# 1.46 20-Aug-2016 kettenis

Fix indentation.


# 1.45 20-Aug-2016 kettenis

Argh, commit from the wrong tree. Revert previous commit.


# 1.44 20-Aug-2016 kettenis

Fix indentation.


# 1.43 20-Aug-2016 kettenis

Correctly enter a mapping as writable if no "page modified" emulation
is needed.

ok visa@, patrick@


# 1.42 19-Aug-2016 kettenis

Start using to XN flag to enforce that mappings without PROT_EXEC are
non-executable.

ok visa@, deraadt@


# 1.41 19-Aug-2016 kettenis

Mark device memory as execute-never to prevent a speculative instruction fetch
to access it.


# 1.40 19-Aug-2016 kettenis

Use Access Flag to do page reference emulation.

ok visa@


# 1.39 18-Aug-2016 kettenis

Separate out the Access Flag bit from the Access Permission bits in the
armv7 pmap.

ok tom@


# 1.38 16-Aug-2016 kettenis

Fix typo/inconsistensy where L1_S_DOMAIN was used instead of L1_C_DOMAIN.
These are functionally equivolent so it didn't matter and the resulting
code doesn't change.


# 1.37 11-Aug-2016 kettenis

The ARMv7 ARM says that the TLB may hold translation table entries at any
level of the translation table, including entries that point to further
levels of the tables. This means that we have to do a TLB flush whenever
we invalidate an L1 slot too. Doing so fixes the pmap_fault_fixup
issue on Cortex-A7 processors.


# 1.36 09-Aug-2016 kettenis

The page tables are cached now, and given the significant speedup, I
don't think we'll ever go back. So let's ditch the code that tries to
check and patch up incorrect memory attributes.

Also realize that pmap_clean_page(pg, FALSE) doesn't do anything
anymore so remove those calls and drop the 2nd argument from
pmap_clean_page(pg, TRUE) calls.

Last but not least, get rid of pmap_pte_init_generic() here. The only
useful thing it did was setting pmap_copy_page_func() and
pmap_zero_page_func().

This diff should not introduce any change in behaviour.

ok visa@


# 1.35 08-Aug-2016 kettenis

Mapping non-cachable memory as cachable and subsequently changing the mapping
to non-cachable is retarded. Fix this by introducing PMAP_NOCACHE and
PMAP_DEVICE flags that can be or'ed into the physical address passed to
pmap_kenter(9), like we have on many of our other architectures. This way we
can also properly distinguish between device memory and normal (non-cachable)
memory.

ok visa@


# 1.34 08-Aug-2016 kettenis

ARMv7 data caches are "effectively" PIPT. This means there is in general
no need to clean and/or invalidate cached pages. So remove most of the
cache cleaning and invalidation from the pmap. We still need to synchronize
the instruction cache with the data cache in various places though. And we
also need to make sure that we clean and invalidate when we make a page
non-cachable.

Tested by Daniel Bolgheroni, mglocker@ and jsg@. on Cortex-A8 and myself on
Cortex-A9.

ok visa@


# 1.33 06-Aug-2016 kettenis

Put page tables in normal cachable memory on armv7. Check if the MMU walks
the page tables coherently and also skip flushing modified ptes out of the
cache in that case. Speeds up building a kernel with a factor of two on
Cortex-A9 (tested by me) and Cortex-A8 (tested by mglocker@).

ok patrick@


# 1.32 03-Aug-2016 kettenis

Simplify the way we handle TLB flushes. Since ARMv7 effectively has a
unified TLB there is not much point in optimizing TLB flushing for pages
that have never been executable. The only difference is a flush of the
branch predictor and even that isn't necessary anymore on all but the oldest
Cortex cores.

ok patrick@


# 1.31 31-Jul-2016 kettenis

Remove devmap stuff which is unused on armv7.

ok patrick@


# 1.30 31-Jul-2016 kettenis

According to te armv7 ARM TLB entries that caused a Permission fault might
be held in the TLB. On top of that valid page table entries might be
speculatively loaded into the TLB. As a result we need to flush TLB entries
even when the page in question has not been referenced.

Fixes pmap_fault_fixup messages on Cortex-A53, and presumably also on
Cortex-A7.

ok patrick@, guenther@


# 1.29 29-Jul-2016 patrick

Only flush the virtual page if it was actually mapped. Otherwise
we will run into translation faults.

ok tom@


# 1.28 27-Jul-2016 patrick

When pmap_page_remove() is called by UVM, a physical page is to be
removed from pmaps it currently is in. To check if a virtual address
pointing to that physical page has been mapped, the code uses
the l2pte_valid() function. Unfortunately there is a difference
between being valid and the PTE being zero. If a page is mapped
but has never been accessed, it will be non-zero but invalid.

In that case the PTE for that virtual address will not be zeroed
and the virtual address will be removed from the vm page struct.

The next time someone tries to map a page to that virtual address,
other pmap code will consider the virtual address to be already
mapped, even though that assumption is completely wrong.

To make sure this does not happen, check the PTE for zero. This way
the PTE will be zeroed correctly. The check for zero is how other
ARM pmap code also handles this issue.

ok kettenis@ tom@


Revision tags: OPENBSD_6_0_BASE
# 1.27 19-Jul-2016 tom

Remove what appears to be a copy-paste error setting cur_ttb
in pmap_free_l1().

from aalm@ - thanks

ok patrick@


# 1.26 18-Jul-2016 tom

Don't need a separate flags variable in armv7 pmap_clean_page() -
just use the pv_flags. ('Twas a copy-paste from arm's pmap_clean_page(),
which did need it.)

Also remove even less used flags variable from pmap_page_remove().

First part from a diff from aalm@ - thanks

ok kettenis@ "looks good" patrick@


# 1.25 07-Jun-2016 dlg

consistently set ipls on pmap pools.

this is a step toward making ipls unconditionaly on pools.

ok deraadt@ kettenis@


# 1.24 03-Mar-2016 jsg

When a physical address is needed to flush the secondary cache use
VM_PAGE_TO_PHYS() instead of unnecessarily calling pmap_extract().

From Patrick Wildt.


Revision tags: OPENBSD_5_9_BASE
# 1.23 01-Feb-2016 jsg

Fix the encoding of AP bits for large page second-level
short-descriptors with arm v7 (same as small page encoding, except XN is
in a different bit for the mask).

Expanded version of a diff from Patrick Wildt who also tested and
reviewed this.


# 1.22 31-Jan-2016 jsg

Switch from PSR_X_bit and X32_bit PSR macro names to just PSR_X.
This matches FreeBSD and makes things a bit more consistent.
Discussed with Patrick.


# 1.21 08-Sep-2015 kettenis

Give the pool page allocator backends more sensible names. We now have:
* pool_allocator_single: single page allocator, always interrupt safe
* pool_allocator_multi: multi-page allocator, interrupt safe
* pool_allocator_multi_ni: multi-page allocator, not interrupt-safe

ok deraadt@, dlg@


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE
# 1.20 02-Feb-2015 mlarkin

Remove some pmap locks that were #defined to be nothing (empty). Discussed
with many, ok kettenis@.


# 1.19 29-Jan-2015 deraadt

remove no-op simple locks
tested by jsg, ok miod


# 1.18 16-Nov-2014 deraadt

Replace a plethora of historical protection options with just
PROT_NONE, PROT_READ, PROT_WRITE, and PROT_EXEC from mman.h.
PROT_MASK is introduced as the one true way of extracting those bits.
Remove UVM_ADV_* wrapper, using the standard names.
ok doug guenther kettenis


# 1.17 27-Oct-2014 jsg

use #ifdef DDB for Debugger()


# 1.16 07-Oct-2014 jsg

Correct the l1 pte permission bits for armv7. Problem pointed out
by Patrick Wildt who made a similiar change in Bitrig.

ok miod@ rapha@


Revision tags: OPENBSD_5_6_BASE
# 1.15 12-Jul-2014 tedu

add a size argument to free. will be used soon, but for now default to 0.
after discussions with beck deraadt kettenis.


# 1.14 08-May-2014 miod

Format string fixes and removal of -Wno-format for arm kernels.


# 1.13 29-Mar-2014 guenther

It's been a quarter century: we can assume volatile is present with that name.

ok dlg@ mpi@ deraadt@


Revision tags: OPENBSD_5_5_BASE
# 1.12 04-Nov-2013 dlg

move the arm pmaps away from pool ctors to just initting memory after its
been allocated. also gets rid of a potential bug where pool_get could
return NULL and pmap_alloc_l2_ptp tried to blindly init it.

tests, tweaks, and ok patrick@


# 1.11 29-Oct-2013 patrick

The cache mask for ARMv7 is a little bit different from the one inited by
the generic function. While there, also set the cache bits manually.

ok aalm@


# 1.10 22-Oct-2013 patrick

Some current boards do not have write-through caching. For those,
we enable write-back, but it seems this is not working and those
boards hang on bootup. Until that is fixed, do not cache PTEs
on those boards.


# 1.9 03-Sep-2013 patrick

Rewrite the ARMv7 cache discovery, as some assumptions in the previous one
were utterly wrong. Fix Log2(), correct one taken from the scheduler code.

Tested by rapha@ and Artturi Alm.


Revision tags: OPENBSD_5_4_BASE
# 1.8 09-Jun-2013 miod

typo


# 1.7 22-May-2013 patrick

We're handling L2 there, so use the corresponding define, not the L1 one.

ok bmercer@


# 1.6 21-May-2013 patrick

When mapping a new entry, map it read-only, even though it should be
writable. This will cause a pmap fault on first write, so that we can
mark the page as modified. Also mask the bits used for the protection
settings, so that there aren't any leftovers.

ok bmercer@


# 1.5 09-May-2013 patrick

On ARMv7 we can't use the cache mask to check for coherency.
Therefore we add new macros to be able to check for it properly.

ok miod@


# 1.4 28-Apr-2013 patrick

Revert the ARMv7 header split introduced in pmap7.

ok bmercer@


# 1.3 16-Apr-2013 patrick

Add secondary cache flushes to armv7's pmap.

ok bmercer@


# 1.2 27-Mar-2013 patrick

Further updates to pmap7. Fixes some problems and removes debug printfs.

ok miod@


Revision tags: OPENBSD_5_3_BASE
# 1.1 17-Jan-2013 bmercer

New pmap for panda boards. Work from lots of folks.
OK miod@


# 1.62 01-Feb-2022 kettenis

Make sure we always pass a page-aligned address to pmap_grow_map().
Fixes an issue uncovered by the recent change to enlarge kva space where
an unaligned address was passed resulting in memset() writing past the
end of the newly allocated page.

ok miod@


Revision tags: OPENBSD_6_9_BASE OPENBSD_7_0_BASE
# 1.61 25-Mar-2021 jsg

remove uneeded includes in md armv7 files

based on include-what-you-use suggestions


# 1.60 11-Mar-2021 jsg

spelling


Revision tags: OPENBSD_6_7_BASE OPENBSD_6_8_BASE
# 1.59 19-Dec-2019 mpi

Convert boolean_t/TRUE/FALSE to int/1/0 for coherency with the rest of
the kernel.

ok patrick@


Revision tags: OPENBSD_6_5_BASE OPENBSD_6_6_BASE
# 1.58 10-Feb-2019 tedu

revert revert revert. there are many other archs that use custom allocs.


# 1.57 10-Feb-2019 tedu

make it possible to reduce kmem pressure by letting some pools use a more
accomodating allocator. an interrupt safe pool may also be used in process
context, as indicated by waitok flags. thanks to the garbage collector, we
can always free pages in process context. the only complication is where
to put the pages. solve this by saving the allocation flags in the pool
page header so the free function can examine them.
not actually used in this diff. (coming soon.)
arm testing and compile fixes from phessler


Revision tags: OPENBSD_6_2_BASE OPENBSD_6_3_BASE OPENBSD_6_4_BASE
# 1.56 08-Sep-2017 deraadt

If you use sys/param.h, you don't need sys/types.h


Revision tags: OPENBSD_6_1_BASE
# 1.55 22-Oct-2016 patrick

If an Access Flag fault happens while we were running the kernel and
it happened on a kernel page, we need to consult the kernel pmap
instead of the current proc's pmap. Fixes panic when using tmpfs.

ok kettenis@


# 1.54 19-Oct-2016 guenther

Change pmap_proc_iflush() to take a process instead of a proc
powerpc: rename second argument of pmap_proc_iflush() to match other archs

ok kettenis@


# 1.53 24-Sep-2016 kettenis

Remove a couple of unsused static inline functions. Also remove a comparis
of an array to a null pointer that is always false. Found with clang.

ok jsg@


# 1.52 15-Sep-2016 dlg

all pools have their ipl set via pool_setipl, so fold it into pool_init.

the ioff argument to pool_init() is unused and has been for many
years, so this replaces it with an ipl argument. because the ipl
will be set on init we no longer need pool_setipl.

most of these changes have been done with coccinelle using the spatch
below. cocci sucks at formatting code though, so i fixed that by hand.

the manpage and subr_pool.c bits i did myself.

ok tedu@ jmatthew@

@ipl@
expression pp;
expression ipl;
expression s, a, o, f, m, p;
@@
-pool_init(pp, s, a, o, f, m, p);
-pool_setipl(pp, ipl);
+pool_init(pp, s, a, ipl, f, m, p);


# 1.51 31-Aug-2016 jsg

In pmap_activate instead of doing disable_interrupts/enable_interrupts
nested inside of splhigh/splx just disable and enable interrupts
once with inline cps instructions.

Remove uneeded pcb_pl1vec block as well, suggested by kettenis.

ok kettenis@


# 1.50 27-Aug-2016 kettenis

Add support for the PXN bit in level 1 translation table descriptors and
enable it on CPUs that support it. When enabled, this prevents the kernel
from executing userland code.

ok jsg@, tom@


# 1.49 26-Aug-2016 kettenis

Remove cpu_cpwait() calls; they are no-ops on armv7.

ok tom@


# 1.48 26-Aug-2016 kettenis

Remove the code that switches around MMU domains on armv7. MMU domains are
basically a relic from the past. Using them doesn't make a lot of sense
the way our pmaps work. Support for MMU domains isn't present in
long-descriptor translation table format, so it is clearly on its way out.

Based on a diff from Artituri Alm.

ok patrick@


# 1.47 24-Aug-2016 kettenis

Replace pmap_fault_fixup() with an access flag fault handler on armv7.

ok tom@


# 1.46 20-Aug-2016 kettenis

Fix indentation.


# 1.45 20-Aug-2016 kettenis

Argh, commit from the wrong tree. Revert previous commit.


# 1.44 20-Aug-2016 kettenis

Fix indentation.


# 1.43 20-Aug-2016 kettenis

Correctly enter a mapping as writable if no "page modified" emulation
is needed.

ok visa@, patrick@


# 1.42 19-Aug-2016 kettenis

Start using to XN flag to enforce that mappings without PROT_EXEC are
non-executable.

ok visa@, deraadt@


# 1.41 19-Aug-2016 kettenis

Mark device memory as execute-never to prevent a speculative instruction fetch
to access it.


# 1.40 19-Aug-2016 kettenis

Use Access Flag to do page reference emulation.

ok visa@


# 1.39 18-Aug-2016 kettenis

Separate out the Access Flag bit from the Access Permission bits in the
armv7 pmap.

ok tom@


# 1.38 16-Aug-2016 kettenis

Fix typo/inconsistensy where L1_S_DOMAIN was used instead of L1_C_DOMAIN.
These are functionally equivolent so it didn't matter and the resulting
code doesn't change.


# 1.37 11-Aug-2016 kettenis

The ARMv7 ARM says that the TLB may hold translation table entries at any
level of the translation table, including entries that point to further
levels of the tables. This means that we have to do a TLB flush whenever
we invalidate an L1 slot too. Doing so fixes the pmap_fault_fixup
issue on Cortex-A7 processors.


# 1.36 09-Aug-2016 kettenis

The page tables are cached now, and given the significant speedup, I
don't think we'll ever go back. So let's ditch the code that tries to
check and patch up incorrect memory attributes.

Also realize that pmap_clean_page(pg, FALSE) doesn't do anything
anymore so remove those calls and drop the 2nd argument from
pmap_clean_page(pg, TRUE) calls.

Last but not least, get rid of pmap_pte_init_generic() here. The only
useful thing it did was setting pmap_copy_page_func() and
pmap_zero_page_func().

This diff should not introduce any change in behaviour.

ok visa@


# 1.35 08-Aug-2016 kettenis

Mapping non-cachable memory as cachable and subsequently changing the mapping
to non-cachable is retarded. Fix this by introducing PMAP_NOCACHE and
PMAP_DEVICE flags that can be or'ed into the physical address passed to
pmap_kenter(9), like we have on many of our other architectures. This way we
can also properly distinguish between device memory and normal (non-cachable)
memory.

ok visa@


# 1.34 08-Aug-2016 kettenis

ARMv7 data caches are "effectively" PIPT. This means there is in general
no need to clean and/or invalidate cached pages. So remove most of the
cache cleaning and invalidation from the pmap. We still need to synchronize
the instruction cache with the data cache in various places though. And we
also need to make sure that we clean and invalidate when we make a page
non-cachable.

Tested by Daniel Bolgheroni, mglocker@ and jsg@. on Cortex-A8 and myself on
Cortex-A9.

ok visa@


# 1.33 06-Aug-2016 kettenis

Put page tables in normal cachable memory on armv7. Check if the MMU walks
the page tables coherently and also skip flushing modified ptes out of the
cache in that case. Speeds up building a kernel with a factor of two on
Cortex-A9 (tested by me) and Cortex-A8 (tested by mglocker@).

ok patrick@


# 1.32 03-Aug-2016 kettenis

Simplify the way we handle TLB flushes. Since ARMv7 effectively has a
unified TLB there is not much point in optimizing TLB flushing for pages
that have never been executable. The only difference is a flush of the
branch predictor and even that isn't necessary anymore on all but the oldest
Cortex cores.

ok patrick@


# 1.31 31-Jul-2016 kettenis

Remove devmap stuff which is unused on armv7.

ok patrick@


# 1.30 31-Jul-2016 kettenis

According to te armv7 ARM TLB entries that caused a Permission fault might
be held in the TLB. On top of that valid page table entries might be
speculatively loaded into the TLB. As a result we need to flush TLB entries
even when the page in question has not been referenced.

Fixes pmap_fault_fixup messages on Cortex-A53, and presumably also on
Cortex-A7.

ok patrick@, guenther@


# 1.29 29-Jul-2016 patrick

Only flush the virtual page if it was actually mapped. Otherwise
we will run into translation faults.

ok tom@


# 1.28 27-Jul-2016 patrick

When pmap_page_remove() is called by UVM, a physical page is to be
removed from pmaps it currently is in. To check if a virtual address
pointing to that physical page has been mapped, the code uses
the l2pte_valid() function. Unfortunately there is a difference
between being valid and the PTE being zero. If a page is mapped
but has never been accessed, it will be non-zero but invalid.

In that case the PTE for that virtual address will not be zeroed
and the virtual address will be removed from the vm page struct.

The next time someone tries to map a page to that virtual address,
other pmap code will consider the virtual address to be already
mapped, even though that assumption is completely wrong.

To make sure this does not happen, check the PTE for zero. This way
the PTE will be zeroed correctly. The check for zero is how other
ARM pmap code also handles this issue.

ok kettenis@ tom@


Revision tags: OPENBSD_6_0_BASE
# 1.27 19-Jul-2016 tom

Remove what appears to be a copy-paste error setting cur_ttb
in pmap_free_l1().

from aalm@ - thanks

ok patrick@


# 1.26 18-Jul-2016 tom

Don't need a separate flags variable in armv7 pmap_clean_page() -
just use the pv_flags. ('Twas a copy-paste from arm's pmap_clean_page(),
which did need it.)

Also remove even less used flags variable from pmap_page_remove().

First part from a diff from aalm@ - thanks

ok kettenis@ "looks good" patrick@


# 1.25 07-Jun-2016 dlg

consistently set ipls on pmap pools.

this is a step toward making ipls unconditionaly on pools.

ok deraadt@ kettenis@


# 1.24 03-Mar-2016 jsg

When a physical address is needed to flush the secondary cache use
VM_PAGE_TO_PHYS() instead of unnecessarily calling pmap_extract().

From Patrick Wildt.


Revision tags: OPENBSD_5_9_BASE
# 1.23 01-Feb-2016 jsg

Fix the encoding of AP bits for large page second-level
short-descriptors with arm v7 (same as small page encoding, except XN is
in a different bit for the mask).

Expanded version of a diff from Patrick Wildt who also tested and
reviewed this.


# 1.22 31-Jan-2016 jsg

Switch from PSR_X_bit and X32_bit PSR macro names to just PSR_X.
This matches FreeBSD and makes things a bit more consistent.
Discussed with Patrick.


# 1.21 08-Sep-2015 kettenis

Give the pool page allocator backends more sensible names. We now have:
* pool_allocator_single: single page allocator, always interrupt safe
* pool_allocator_multi: multi-page allocator, interrupt safe
* pool_allocator_multi_ni: multi-page allocator, not interrupt-safe

ok deraadt@, dlg@


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE
# 1.20 02-Feb-2015 mlarkin

Remove some pmap locks that were #defined to be nothing (empty). Discussed
with many, ok kettenis@.


# 1.19 29-Jan-2015 deraadt

remove no-op simple locks
tested by jsg, ok miod


# 1.18 16-Nov-2014 deraadt

Replace a plethora of historical protection options with just
PROT_NONE, PROT_READ, PROT_WRITE, and PROT_EXEC from mman.h.
PROT_MASK is introduced as the one true way of extracting those bits.
Remove UVM_ADV_* wrapper, using the standard names.
ok doug guenther kettenis


# 1.17 27-Oct-2014 jsg

use #ifdef DDB for Debugger()


# 1.16 07-Oct-2014 jsg

Correct the l1 pte permission bits for armv7. Problem pointed out
by Patrick Wildt who made a similiar change in Bitrig.

ok miod@ rapha@


Revision tags: OPENBSD_5_6_BASE
# 1.15 12-Jul-2014 tedu

add a size argument to free. will be used soon, but for now default to 0.
after discussions with beck deraadt kettenis.


# 1.14 08-May-2014 miod

Format string fixes and removal of -Wno-format for arm kernels.


# 1.13 29-Mar-2014 guenther

It's been a quarter century: we can assume volatile is present with that name.

ok dlg@ mpi@ deraadt@


Revision tags: OPENBSD_5_5_BASE
# 1.12 04-Nov-2013 dlg

move the arm pmaps away from pool ctors to just initting memory after its
been allocated. also gets rid of a potential bug where pool_get could
return NULL and pmap_alloc_l2_ptp tried to blindly init it.

tests, tweaks, and ok patrick@


# 1.11 29-Oct-2013 patrick

The cache mask for ARMv7 is a little bit different from the one inited by
the generic function. While there, also set the cache bits manually.

ok aalm@


# 1.10 22-Oct-2013 patrick

Some current boards do not have write-through caching. For those,
we enable write-back, but it seems this is not working and those
boards hang on bootup. Until that is fixed, do not cache PTEs
on those boards.


# 1.9 03-Sep-2013 patrick

Rewrite the ARMv7 cache discovery, as some assumptions in the previous one
were utterly wrong. Fix Log2(), correct one taken from the scheduler code.

Tested by rapha@ and Artturi Alm.


Revision tags: OPENBSD_5_4_BASE
# 1.8 09-Jun-2013 miod

typo


# 1.7 22-May-2013 patrick

We're handling L2 there, so use the corresponding define, not the L1 one.

ok bmercer@


# 1.6 21-May-2013 patrick

When mapping a new entry, map it read-only, even though it should be
writable. This will cause a pmap fault on first write, so that we can
mark the page as modified. Also mask the bits used for the protection
settings, so that there aren't any leftovers.

ok bmercer@


# 1.5 09-May-2013 patrick

On ARMv7 we can't use the cache mask to check for coherency.
Therefore we add new macros to be able to check for it properly.

ok miod@


# 1.4 28-Apr-2013 patrick

Revert the ARMv7 header split introduced in pmap7.

ok bmercer@


# 1.3 16-Apr-2013 patrick

Add secondary cache flushes to armv7's pmap.

ok bmercer@


# 1.2 27-Mar-2013 patrick

Further updates to pmap7. Fixes some problems and removes debug printfs.

ok miod@


Revision tags: OPENBSD_5_3_BASE
# 1.1 17-Jan-2013 bmercer

New pmap for panda boards. Work from lots of folks.
OK miod@


# 1.61 25-Mar-2021 jsg

remove uneeded includes in md armv7 files

based on include-what-you-use suggestions


# 1.60 11-Mar-2021 jsg

spelling


Revision tags: OPENBSD_6_7_BASE OPENBSD_6_8_BASE
# 1.59 19-Dec-2019 mpi

Convert boolean_t/TRUE/FALSE to int/1/0 for coherency with the rest of
the kernel.

ok patrick@


Revision tags: OPENBSD_6_5_BASE OPENBSD_6_6_BASE
# 1.58 10-Feb-2019 tedu

revert revert revert. there are many other archs that use custom allocs.


# 1.57 10-Feb-2019 tedu

make it possible to reduce kmem pressure by letting some pools use a more
accomodating allocator. an interrupt safe pool may also be used in process
context, as indicated by waitok flags. thanks to the garbage collector, we
can always free pages in process context. the only complication is where
to put the pages. solve this by saving the allocation flags in the pool
page header so the free function can examine them.
not actually used in this diff. (coming soon.)
arm testing and compile fixes from phessler


Revision tags: OPENBSD_6_2_BASE OPENBSD_6_3_BASE OPENBSD_6_4_BASE
# 1.56 08-Sep-2017 deraadt

If you use sys/param.h, you don't need sys/types.h


Revision tags: OPENBSD_6_1_BASE
# 1.55 22-Oct-2016 patrick

If an Access Flag fault happens while we were running the kernel and
it happened on a kernel page, we need to consult the kernel pmap
instead of the current proc's pmap. Fixes panic when using tmpfs.

ok kettenis@


# 1.54 19-Oct-2016 guenther

Change pmap_proc_iflush() to take a process instead of a proc
powerpc: rename second argument of pmap_proc_iflush() to match other archs

ok kettenis@


# 1.53 24-Sep-2016 kettenis

Remove a couple of unsused static inline functions. Also remove a comparis
of an array to a null pointer that is always false. Found with clang.

ok jsg@


# 1.52 15-Sep-2016 dlg

all pools have their ipl set via pool_setipl, so fold it into pool_init.

the ioff argument to pool_init() is unused and has been for many
years, so this replaces it with an ipl argument. because the ipl
will be set on init we no longer need pool_setipl.

most of these changes have been done with coccinelle using the spatch
below. cocci sucks at formatting code though, so i fixed that by hand.

the manpage and subr_pool.c bits i did myself.

ok tedu@ jmatthew@

@ipl@
expression pp;
expression ipl;
expression s, a, o, f, m, p;
@@
-pool_init(pp, s, a, o, f, m, p);
-pool_setipl(pp, ipl);
+pool_init(pp, s, a, ipl, f, m, p);


# 1.51 31-Aug-2016 jsg

In pmap_activate instead of doing disable_interrupts/enable_interrupts
nested inside of splhigh/splx just disable and enable interrupts
once with inline cps instructions.

Remove uneeded pcb_pl1vec block as well, suggested by kettenis.

ok kettenis@


# 1.50 27-Aug-2016 kettenis

Add support for the PXN bit in level 1 translation table descriptors and
enable it on CPUs that support it. When enabled, this prevents the kernel
from executing userland code.

ok jsg@, tom@


# 1.49 26-Aug-2016 kettenis

Remove cpu_cpwait() calls; they are no-ops on armv7.

ok tom@


# 1.48 26-Aug-2016 kettenis

Remove the code that switches around MMU domains on armv7. MMU domains are
basically a relic from the past. Using them doesn't make a lot of sense
the way our pmaps work. Support for MMU domains isn't present in
long-descriptor translation table format, so it is clearly on its way out.

Based on a diff from Artituri Alm.

ok patrick@


# 1.47 24-Aug-2016 kettenis

Replace pmap_fault_fixup() with an access flag fault handler on armv7.

ok tom@


# 1.46 20-Aug-2016 kettenis

Fix indentation.


# 1.45 20-Aug-2016 kettenis

Argh, commit from the wrong tree. Revert previous commit.


# 1.44 20-Aug-2016 kettenis

Fix indentation.


# 1.43 20-Aug-2016 kettenis

Correctly enter a mapping as writable if no "page modified" emulation
is needed.

ok visa@, patrick@


# 1.42 19-Aug-2016 kettenis

Start using to XN flag to enforce that mappings without PROT_EXEC are
non-executable.

ok visa@, deraadt@


# 1.41 19-Aug-2016 kettenis

Mark device memory as execute-never to prevent a speculative instruction fetch
to access it.


# 1.40 19-Aug-2016 kettenis

Use Access Flag to do page reference emulation.

ok visa@


# 1.39 18-Aug-2016 kettenis

Separate out the Access Flag bit from the Access Permission bits in the
armv7 pmap.

ok tom@


# 1.38 16-Aug-2016 kettenis

Fix typo/inconsistensy where L1_S_DOMAIN was used instead of L1_C_DOMAIN.
These are functionally equivolent so it didn't matter and the resulting
code doesn't change.


# 1.37 11-Aug-2016 kettenis

The ARMv7 ARM says that the TLB may hold translation table entries at any
level of the translation table, including entries that point to further
levels of the tables. This means that we have to do a TLB flush whenever
we invalidate an L1 slot too. Doing so fixes the pmap_fault_fixup
issue on Cortex-A7 processors.


# 1.36 09-Aug-2016 kettenis

The page tables are cached now, and given the significant speedup, I
don't think we'll ever go back. So let's ditch the code that tries to
check and patch up incorrect memory attributes.

Also realize that pmap_clean_page(pg, FALSE) doesn't do anything
anymore so remove those calls and drop the 2nd argument from
pmap_clean_page(pg, TRUE) calls.

Last but not least, get rid of pmap_pte_init_generic() here. The only
useful thing it did was setting pmap_copy_page_func() and
pmap_zero_page_func().

This diff should not introduce any change in behaviour.

ok visa@


# 1.35 08-Aug-2016 kettenis

Mapping non-cachable memory as cachable and subsequently changing the mapping
to non-cachable is retarded. Fix this by introducing PMAP_NOCACHE and
PMAP_DEVICE flags that can be or'ed into the physical address passed to
pmap_kenter(9), like we have on many of our other architectures. This way we
can also properly distinguish between device memory and normal (non-cachable)
memory.

ok visa@


# 1.34 08-Aug-2016 kettenis

ARMv7 data caches are "effectively" PIPT. This means there is in general
no need to clean and/or invalidate cached pages. So remove most of the
cache cleaning and invalidation from the pmap. We still need to synchronize
the instruction cache with the data cache in various places though. And we
also need to make sure that we clean and invalidate when we make a page
non-cachable.

Tested by Daniel Bolgheroni, mglocker@ and jsg@. on Cortex-A8 and myself on
Cortex-A9.

ok visa@


# 1.33 06-Aug-2016 kettenis

Put page tables in normal cachable memory on armv7. Check if the MMU walks
the page tables coherently and also skip flushing modified ptes out of the
cache in that case. Speeds up building a kernel with a factor of two on
Cortex-A9 (tested by me) and Cortex-A8 (tested by mglocker@).

ok patrick@


# 1.32 03-Aug-2016 kettenis

Simplify the way we handle TLB flushes. Since ARMv7 effectively has a
unified TLB there is not much point in optimizing TLB flushing for pages
that have never been executable. The only difference is a flush of the
branch predictor and even that isn't necessary anymore on all but the oldest
Cortex cores.

ok patrick@


# 1.31 31-Jul-2016 kettenis

Remove devmap stuff which is unused on armv7.

ok patrick@


# 1.30 31-Jul-2016 kettenis

According to te armv7 ARM TLB entries that caused a Permission fault might
be held in the TLB. On top of that valid page table entries might be
speculatively loaded into the TLB. As a result we need to flush TLB entries
even when the page in question has not been referenced.

Fixes pmap_fault_fixup messages on Cortex-A53, and presumably also on
Cortex-A7.

ok patrick@, guenther@


# 1.29 29-Jul-2016 patrick

Only flush the virtual page if it was actually mapped. Otherwise
we will run into translation faults.

ok tom@


# 1.28 27-Jul-2016 patrick

When pmap_page_remove() is called by UVM, a physical page is to be
removed from pmaps it currently is in. To check if a virtual address
pointing to that physical page has been mapped, the code uses
the l2pte_valid() function. Unfortunately there is a difference
between being valid and the PTE being zero. If a page is mapped
but has never been accessed, it will be non-zero but invalid.

In that case the PTE for that virtual address will not be zeroed
and the virtual address will be removed from the vm page struct.

The next time someone tries to map a page to that virtual address,
other pmap code will consider the virtual address to be already
mapped, even though that assumption is completely wrong.

To make sure this does not happen, check the PTE for zero. This way
the PTE will be zeroed correctly. The check for zero is how other
ARM pmap code also handles this issue.

ok kettenis@ tom@


Revision tags: OPENBSD_6_0_BASE
# 1.27 19-Jul-2016 tom

Remove what appears to be a copy-paste error setting cur_ttb
in pmap_free_l1().

from aalm@ - thanks

ok patrick@


# 1.26 18-Jul-2016 tom

Don't need a separate flags variable in armv7 pmap_clean_page() -
just use the pv_flags. ('Twas a copy-paste from arm's pmap_clean_page(),
which did need it.)

Also remove even less used flags variable from pmap_page_remove().

First part from a diff from aalm@ - thanks

ok kettenis@ "looks good" patrick@


# 1.25 07-Jun-2016 dlg

consistently set ipls on pmap pools.

this is a step toward making ipls unconditionaly on pools.

ok deraadt@ kettenis@


# 1.24 03-Mar-2016 jsg

When a physical address is needed to flush the secondary cache use
VM_PAGE_TO_PHYS() instead of unnecessarily calling pmap_extract().

From Patrick Wildt.


Revision tags: OPENBSD_5_9_BASE
# 1.23 01-Feb-2016 jsg

Fix the encoding of AP bits for large page second-level
short-descriptors with arm v7 (same as small page encoding, except XN is
in a different bit for the mask).

Expanded version of a diff from Patrick Wildt who also tested and
reviewed this.


# 1.22 31-Jan-2016 jsg

Switch from PSR_X_bit and X32_bit PSR macro names to just PSR_X.
This matches FreeBSD and makes things a bit more consistent.
Discussed with Patrick.


# 1.21 08-Sep-2015 kettenis

Give the pool page allocator backends more sensible names. We now have:
* pool_allocator_single: single page allocator, always interrupt safe
* pool_allocator_multi: multi-page allocator, interrupt safe
* pool_allocator_multi_ni: multi-page allocator, not interrupt-safe

ok deraadt@, dlg@


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE
# 1.20 02-Feb-2015 mlarkin

Remove some pmap locks that were #defined to be nothing (empty). Discussed
with many, ok kettenis@.


# 1.19 29-Jan-2015 deraadt

remove no-op simple locks
tested by jsg, ok miod


# 1.18 16-Nov-2014 deraadt

Replace a plethora of historical protection options with just
PROT_NONE, PROT_READ, PROT_WRITE, and PROT_EXEC from mman.h.
PROT_MASK is introduced as the one true way of extracting those bits.
Remove UVM_ADV_* wrapper, using the standard names.
ok doug guenther kettenis


# 1.17 27-Oct-2014 jsg

use #ifdef DDB for Debugger()


# 1.16 07-Oct-2014 jsg

Correct the l1 pte permission bits for armv7. Problem pointed out
by Patrick Wildt who made a similiar change in Bitrig.

ok miod@ rapha@


Revision tags: OPENBSD_5_6_BASE
# 1.15 12-Jul-2014 tedu

add a size argument to free. will be used soon, but for now default to 0.
after discussions with beck deraadt kettenis.


# 1.14 08-May-2014 miod

Format string fixes and removal of -Wno-format for arm kernels.


# 1.13 29-Mar-2014 guenther

It's been a quarter century: we can assume volatile is present with that name.

ok dlg@ mpi@ deraadt@


Revision tags: OPENBSD_5_5_BASE
# 1.12 04-Nov-2013 dlg

move the arm pmaps away from pool ctors to just initting memory after its
been allocated. also gets rid of a potential bug where pool_get could
return NULL and pmap_alloc_l2_ptp tried to blindly init it.

tests, tweaks, and ok patrick@


# 1.11 29-Oct-2013 patrick

The cache mask for ARMv7 is a little bit different from the one inited by
the generic function. While there, also set the cache bits manually.

ok aalm@


# 1.10 22-Oct-2013 patrick

Some current boards do not have write-through caching. For those,
we enable write-back, but it seems this is not working and those
boards hang on bootup. Until that is fixed, do not cache PTEs
on those boards.


# 1.9 03-Sep-2013 patrick

Rewrite the ARMv7 cache discovery, as some assumptions in the previous one
were utterly wrong. Fix Log2(), correct one taken from the scheduler code.

Tested by rapha@ and Artturi Alm.


Revision tags: OPENBSD_5_4_BASE
# 1.8 09-Jun-2013 miod

typo


# 1.7 22-May-2013 patrick

We're handling L2 there, so use the corresponding define, not the L1 one.

ok bmercer@


# 1.6 21-May-2013 patrick

When mapping a new entry, map it read-only, even though it should be
writable. This will cause a pmap fault on first write, so that we can
mark the page as modified. Also mask the bits used for the protection
settings, so that there aren't any leftovers.

ok bmercer@


# 1.5 09-May-2013 patrick

On ARMv7 we can't use the cache mask to check for coherency.
Therefore we add new macros to be able to check for it properly.

ok miod@


# 1.4 28-Apr-2013 patrick

Revert the ARMv7 header split introduced in pmap7.

ok bmercer@


# 1.3 16-Apr-2013 patrick

Add secondary cache flushes to armv7's pmap.

ok bmercer@


# 1.2 27-Mar-2013 patrick

Further updates to pmap7. Fixes some problems and removes debug printfs.

ok miod@


Revision tags: OPENBSD_5_3_BASE
# 1.1 17-Jan-2013 bmercer

New pmap for panda boards. Work from lots of folks.
OK miod@


# 1.60 11-Mar-2021 jsg

spelling


Revision tags: OPENBSD_6_7_BASE OPENBSD_6_8_BASE
# 1.59 19-Dec-2019 mpi

Convert boolean_t/TRUE/FALSE to int/1/0 for coherency with the rest of
the kernel.

ok patrick@


Revision tags: OPENBSD_6_5_BASE OPENBSD_6_6_BASE
# 1.58 10-Feb-2019 tedu

revert revert revert. there are many other archs that use custom allocs.


# 1.57 10-Feb-2019 tedu

make it possible to reduce kmem pressure by letting some pools use a more
accomodating allocator. an interrupt safe pool may also be used in process
context, as indicated by waitok flags. thanks to the garbage collector, we
can always free pages in process context. the only complication is where
to put the pages. solve this by saving the allocation flags in the pool
page header so the free function can examine them.
not actually used in this diff. (coming soon.)
arm testing and compile fixes from phessler


Revision tags: OPENBSD_6_2_BASE OPENBSD_6_3_BASE OPENBSD_6_4_BASE
# 1.56 08-Sep-2017 deraadt

If you use sys/param.h, you don't need sys/types.h


Revision tags: OPENBSD_6_1_BASE
# 1.55 22-Oct-2016 patrick

If an Access Flag fault happens while we were running the kernel and
it happened on a kernel page, we need to consult the kernel pmap
instead of the current proc's pmap. Fixes panic when using tmpfs.

ok kettenis@


# 1.54 19-Oct-2016 guenther

Change pmap_proc_iflush() to take a process instead of a proc
powerpc: rename second argument of pmap_proc_iflush() to match other archs

ok kettenis@


# 1.53 24-Sep-2016 kettenis

Remove a couple of unsused static inline functions. Also remove a comparis
of an array to a null pointer that is always false. Found with clang.

ok jsg@


# 1.52 15-Sep-2016 dlg

all pools have their ipl set via pool_setipl, so fold it into pool_init.

the ioff argument to pool_init() is unused and has been for many
years, so this replaces it with an ipl argument. because the ipl
will be set on init we no longer need pool_setipl.

most of these changes have been done with coccinelle using the spatch
below. cocci sucks at formatting code though, so i fixed that by hand.

the manpage and subr_pool.c bits i did myself.

ok tedu@ jmatthew@

@ipl@
expression pp;
expression ipl;
expression s, a, o, f, m, p;
@@
-pool_init(pp, s, a, o, f, m, p);
-pool_setipl(pp, ipl);
+pool_init(pp, s, a, ipl, f, m, p);


# 1.51 31-Aug-2016 jsg

In pmap_activate instead of doing disable_interrupts/enable_interrupts
nested inside of splhigh/splx just disable and enable interrupts
once with inline cps instructions.

Remove uneeded pcb_pl1vec block as well, suggested by kettenis.

ok kettenis@


# 1.50 27-Aug-2016 kettenis

Add support for the PXN bit in level 1 translation table descriptors and
enable it on CPUs that support it. When enabled, this prevents the kernel
from executing userland code.

ok jsg@, tom@


# 1.49 26-Aug-2016 kettenis

Remove cpu_cpwait() calls; they are no-ops on armv7.

ok tom@


# 1.48 26-Aug-2016 kettenis

Remove the code that switches around MMU domains on armv7. MMU domains are
basically a relic from the past. Using them doesn't make a lot of sense
the way our pmaps work. Support for MMU domains isn't present in
long-descriptor translation table format, so it is clearly on its way out.

Based on a diff from Artituri Alm.

ok patrick@


# 1.47 24-Aug-2016 kettenis

Replace pmap_fault_fixup() with an access flag fault handler on armv7.

ok tom@


# 1.46 20-Aug-2016 kettenis

Fix indentation.


# 1.45 20-Aug-2016 kettenis

Argh, commit from the wrong tree. Revert previous commit.


# 1.44 20-Aug-2016 kettenis

Fix indentation.


# 1.43 20-Aug-2016 kettenis

Correctly enter a mapping as writable if no "page modified" emulation
is needed.

ok visa@, patrick@


# 1.42 19-Aug-2016 kettenis

Start using to XN flag to enforce that mappings without PROT_EXEC are
non-executable.

ok visa@, deraadt@


# 1.41 19-Aug-2016 kettenis

Mark device memory as execute-never to prevent a speculative instruction fetch
to access it.


# 1.40 19-Aug-2016 kettenis

Use Access Flag to do page reference emulation.

ok visa@


# 1.39 18-Aug-2016 kettenis

Separate out the Access Flag bit from the Access Permission bits in the
armv7 pmap.

ok tom@


# 1.38 16-Aug-2016 kettenis

Fix typo/inconsistensy where L1_S_DOMAIN was used instead of L1_C_DOMAIN.
These are functionally equivolent so it didn't matter and the resulting
code doesn't change.


# 1.37 11-Aug-2016 kettenis

The ARMv7 ARM says that the TLB may hold translation table entries at any
level of the translation table, including entries that point to further
levels of the tables. This means that we have to do a TLB flush whenever
we invalidate an L1 slot too. Doing so fixes the pmap_fault_fixup
issue on Cortex-A7 processors.


# 1.36 09-Aug-2016 kettenis

The page tables are cached now, and given the significant speedup, I
don't think we'll ever go back. So let's ditch the code that tries to
check and patch up incorrect memory attributes.

Also realize that pmap_clean_page(pg, FALSE) doesn't do anything
anymore so remove those calls and drop the 2nd argument from
pmap_clean_page(pg, TRUE) calls.

Last but not least, get rid of pmap_pte_init_generic() here. The only
useful thing it did was setting pmap_copy_page_func() and
pmap_zero_page_func().

This diff should not introduce any change in behaviour.

ok visa@


# 1.35 08-Aug-2016 kettenis

Mapping non-cachable memory as cachable and subsequently changing the mapping
to non-cachable is retarded. Fix this by introducing PMAP_NOCACHE and
PMAP_DEVICE flags that can be or'ed into the physical address passed to
pmap_kenter(9), like we have on many of our other architectures. This way we
can also properly distinguish between device memory and normal (non-cachable)
memory.

ok visa@


# 1.34 08-Aug-2016 kettenis

ARMv7 data caches are "effectively" PIPT. This means there is in general
no need to clean and/or invalidate cached pages. So remove most of the
cache cleaning and invalidation from the pmap. We still need to synchronize
the instruction cache with the data cache in various places though. And we
also need to make sure that we clean and invalidate when we make a page
non-cachable.

Tested by Daniel Bolgheroni, mglocker@ and jsg@. on Cortex-A8 and myself on
Cortex-A9.

ok visa@


# 1.33 06-Aug-2016 kettenis

Put page tables in normal cachable memory on armv7. Check if the MMU walks
the page tables coherently and also skip flushing modified ptes out of the
cache in that case. Speeds up building a kernel with a factor of two on
Cortex-A9 (tested by me) and Cortex-A8 (tested by mglocker@).

ok patrick@


# 1.32 03-Aug-2016 kettenis

Simplify the way we handle TLB flushes. Since ARMv7 effectively has a
unified TLB there is not much point in optimizing TLB flushing for pages
that have never been executable. The only difference is a flush of the
branch predictor and even that isn't necessary anymore on all but the oldest
Cortex cores.

ok patrick@


# 1.31 31-Jul-2016 kettenis

Remove devmap stuff which is unused on armv7.

ok patrick@


# 1.30 31-Jul-2016 kettenis

According to te armv7 ARM TLB entries that caused a Permission fault might
be held in the TLB. On top of that valid page table entries might be
speculatively loaded into the TLB. As a result we need to flush TLB entries
even when the page in question has not been referenced.

Fixes pmap_fault_fixup messages on Cortex-A53, and presumably also on
Cortex-A7.

ok patrick@, guenther@


# 1.29 29-Jul-2016 patrick

Only flush the virtual page if it was actually mapped. Otherwise
we will run into translation faults.

ok tom@


# 1.28 27-Jul-2016 patrick

When pmap_page_remove() is called by UVM, a physical page is to be
removed from pmaps it currently is in. To check if a virtual address
pointing to that physical page has been mapped, the code uses
the l2pte_valid() function. Unfortunately there is a difference
between being valid and the PTE being zero. If a page is mapped
but has never been accessed, it will be non-zero but invalid.

In that case the PTE for that virtual address will not be zeroed
and the virtual address will be removed from the vm page struct.

The next time someone tries to map a page to that virtual address,
other pmap code will consider the virtual address to be already
mapped, even though that assumption is completely wrong.

To make sure this does not happen, check the PTE for zero. This way
the PTE will be zeroed correctly. The check for zero is how other
ARM pmap code also handles this issue.

ok kettenis@ tom@


Revision tags: OPENBSD_6_0_BASE
# 1.27 19-Jul-2016 tom

Remove what appears to be a copy-paste error setting cur_ttb
in pmap_free_l1().

from aalm@ - thanks

ok patrick@


# 1.26 18-Jul-2016 tom

Don't need a separate flags variable in armv7 pmap_clean_page() -
just use the pv_flags. ('Twas a copy-paste from arm's pmap_clean_page(),
which did need it.)

Also remove even less used flags variable from pmap_page_remove().

First part from a diff from aalm@ - thanks

ok kettenis@ "looks good" patrick@


# 1.25 07-Jun-2016 dlg

consistently set ipls on pmap pools.

this is a step toward making ipls unconditionaly on pools.

ok deraadt@ kettenis@


# 1.24 03-Mar-2016 jsg

When a physical address is needed to flush the secondary cache use
VM_PAGE_TO_PHYS() instead of unnecessarily calling pmap_extract().

From Patrick Wildt.


Revision tags: OPENBSD_5_9_BASE
# 1.23 01-Feb-2016 jsg

Fix the encoding of AP bits for large page second-level
short-descriptors with arm v7 (same as small page encoding, except XN is
in a different bit for the mask).

Expanded version of a diff from Patrick Wildt who also tested and
reviewed this.


# 1.22 31-Jan-2016 jsg

Switch from PSR_X_bit and X32_bit PSR macro names to just PSR_X.
This matches FreeBSD and makes things a bit more consistent.
Discussed with Patrick.


# 1.21 08-Sep-2015 kettenis

Give the pool page allocator backends more sensible names. We now have:
* pool_allocator_single: single page allocator, always interrupt safe
* pool_allocator_multi: multi-page allocator, interrupt safe
* pool_allocator_multi_ni: multi-page allocator, not interrupt-safe

ok deraadt@, dlg@


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE
# 1.20 02-Feb-2015 mlarkin

Remove some pmap locks that were #defined to be nothing (empty). Discussed
with many, ok kettenis@.


# 1.19 29-Jan-2015 deraadt

remove no-op simple locks
tested by jsg, ok miod


# 1.18 16-Nov-2014 deraadt

Replace a plethora of historical protection options with just
PROT_NONE, PROT_READ, PROT_WRITE, and PROT_EXEC from mman.h.
PROT_MASK is introduced as the one true way of extracting those bits.
Remove UVM_ADV_* wrapper, using the standard names.
ok doug guenther kettenis


# 1.17 27-Oct-2014 jsg

use #ifdef DDB for Debugger()


# 1.16 07-Oct-2014 jsg

Correct the l1 pte permission bits for armv7. Problem pointed out
by Patrick Wildt who made a similiar change in Bitrig.

ok miod@ rapha@


Revision tags: OPENBSD_5_6_BASE
# 1.15 12-Jul-2014 tedu

add a size argument to free. will be used soon, but for now default to 0.
after discussions with beck deraadt kettenis.


# 1.14 08-May-2014 miod

Format string fixes and removal of -Wno-format for arm kernels.


# 1.13 29-Mar-2014 guenther

It's been a quarter century: we can assume volatile is present with that name.

ok dlg@ mpi@ deraadt@


Revision tags: OPENBSD_5_5_BASE
# 1.12 04-Nov-2013 dlg

move the arm pmaps away from pool ctors to just initting memory after its
been allocated. also gets rid of a potential bug where pool_get could
return NULL and pmap_alloc_l2_ptp tried to blindly init it.

tests, tweaks, and ok patrick@


# 1.11 29-Oct-2013 patrick

The cache mask for ARMv7 is a little bit different from the one inited by
the generic function. While there, also set the cache bits manually.

ok aalm@


# 1.10 22-Oct-2013 patrick

Some current boards do not have write-through caching. For those,
we enable write-back, but it seems this is not working and those
boards hang on bootup. Until that is fixed, do not cache PTEs
on those boards.


# 1.9 03-Sep-2013 patrick

Rewrite the ARMv7 cache discovery, as some assumptions in the previous one
were utterly wrong. Fix Log2(), correct one taken from the scheduler code.

Tested by rapha@ and Artturi Alm.


Revision tags: OPENBSD_5_4_BASE
# 1.8 09-Jun-2013 miod

typo


# 1.7 22-May-2013 patrick

We're handling L2 there, so use the corresponding define, not the L1 one.

ok bmercer@


# 1.6 21-May-2013 patrick

When mapping a new entry, map it read-only, even though it should be
writable. This will cause a pmap fault on first write, so that we can
mark the page as modified. Also mask the bits used for the protection
settings, so that there aren't any leftovers.

ok bmercer@


# 1.5 09-May-2013 patrick

On ARMv7 we can't use the cache mask to check for coherency.
Therefore we add new macros to be able to check for it properly.

ok miod@


# 1.4 28-Apr-2013 patrick

Revert the ARMv7 header split introduced in pmap7.

ok bmercer@


# 1.3 16-Apr-2013 patrick

Add secondary cache flushes to armv7's pmap.

ok bmercer@


# 1.2 27-Mar-2013 patrick

Further updates to pmap7. Fixes some problems and removes debug printfs.

ok miod@


Revision tags: OPENBSD_5_3_BASE
# 1.1 17-Jan-2013 bmercer

New pmap for panda boards. Work from lots of folks.
OK miod@


# 1.59 19-Dec-2019 mpi

Convert boolean_t/TRUE/FALSE to int/1/0 for coherency with the rest of
the kernel.

ok patrick@


Revision tags: OPENBSD_6_5_BASE OPENBSD_6_6_BASE
# 1.58 10-Feb-2019 tedu

revert revert revert. there are many other archs that use custom allocs.


# 1.57 10-Feb-2019 tedu

make it possible to reduce kmem pressure by letting some pools use a more
accomodating allocator. an interrupt safe pool may also be used in process
context, as indicated by waitok flags. thanks to the garbage collector, we
can always free pages in process context. the only complication is where
to put the pages. solve this by saving the allocation flags in the pool
page header so the free function can examine them.
not actually used in this diff. (coming soon.)
arm testing and compile fixes from phessler


Revision tags: OPENBSD_6_2_BASE OPENBSD_6_3_BASE OPENBSD_6_4_BASE
# 1.56 08-Sep-2017 deraadt

If you use sys/param.h, you don't need sys/types.h


Revision tags: OPENBSD_6_1_BASE
# 1.55 22-Oct-2016 patrick

If an Access Flag fault happens while we were running the kernel and
it happened on a kernel page, we need to consult the kernel pmap
instead of the current proc's pmap. Fixes panic when using tmpfs.

ok kettenis@


# 1.54 19-Oct-2016 guenther

Change pmap_proc_iflush() to take a process instead of a proc
powerpc: rename second argument of pmap_proc_iflush() to match other archs

ok kettenis@


# 1.53 24-Sep-2016 kettenis

Remove a couple of unsused static inline functions. Also remove a comparis
of an array to a null pointer that is always false. Found with clang.

ok jsg@


# 1.52 15-Sep-2016 dlg

all pools have their ipl set via pool_setipl, so fold it into pool_init.

the ioff argument to pool_init() is unused and has been for many
years, so this replaces it with an ipl argument. because the ipl
will be set on init we no longer need pool_setipl.

most of these changes have been done with coccinelle using the spatch
below. cocci sucks at formatting code though, so i fixed that by hand.

the manpage and subr_pool.c bits i did myself.

ok tedu@ jmatthew@

@ipl@
expression pp;
expression ipl;
expression s, a, o, f, m, p;
@@
-pool_init(pp, s, a, o, f, m, p);
-pool_setipl(pp, ipl);
+pool_init(pp, s, a, ipl, f, m, p);


# 1.51 31-Aug-2016 jsg

In pmap_activate instead of doing disable_interrupts/enable_interrupts
nested inside of splhigh/splx just disable and enable interrupts
once with inline cps instructions.

Remove uneeded pcb_pl1vec block as well, suggested by kettenis.

ok kettenis@


# 1.50 27-Aug-2016 kettenis

Add support for the PXN bit in level 1 translation table descriptors and
enable it on CPUs that support it. When enabled, this prevents the kernel
from executing userland code.

ok jsg@, tom@


# 1.49 26-Aug-2016 kettenis

Remove cpu_cpwait() calls; they are no-ops on armv7.

ok tom@


# 1.48 26-Aug-2016 kettenis

Remove the code that switches around MMU domains on armv7. MMU domains are
basically a relic from the past. Using them doesn't make a lot of sense
the way our pmaps work. Support for MMU domains isn't present in
long-descriptor translation table format, so it is clearly on its way out.

Based on a diff from Artituri Alm.

ok patrick@


# 1.47 24-Aug-2016 kettenis

Replace pmap_fault_fixup() with an access flag fault handler on armv7.

ok tom@


# 1.46 20-Aug-2016 kettenis

Fix indentation.


# 1.45 20-Aug-2016 kettenis

Argh, commit from the wrong tree. Revert previous commit.


# 1.44 20-Aug-2016 kettenis

Fix indentation.


# 1.43 20-Aug-2016 kettenis

Correctly enter a mapping as writable if no "page modified" emulation
is needed.

ok visa@, patrick@


# 1.42 19-Aug-2016 kettenis

Start using to XN flag to enforce that mappings without PROT_EXEC are
non-executable.

ok visa@, deraadt@


# 1.41 19-Aug-2016 kettenis

Mark device memory as execute-never to prevent a speculative instruction fetch
to access it.


# 1.40 19-Aug-2016 kettenis

Use Access Flag to do page reference emulation.

ok visa@


# 1.39 18-Aug-2016 kettenis

Separate out the Access Flag bit from the Access Permission bits in the
armv7 pmap.

ok tom@


# 1.38 16-Aug-2016 kettenis

Fix typo/inconsistensy where L1_S_DOMAIN was used instead of L1_C_DOMAIN.
These are functionally equivolent so it didn't matter and the resulting
code doesn't change.


# 1.37 11-Aug-2016 kettenis

The ARMv7 ARM says that the TLB may hold translation table entries at any
level of the translation table, including entries that point to further
levels of the tables. This means that we have to do a TLB flush whenever
we invalidate an L1 slot too. Doing so fixes the pmap_fault_fixup
issue on Cortex-A7 processors.


# 1.36 09-Aug-2016 kettenis

The page tables are cached now, and given the significant speedup, I
don't think we'll ever go back. So let's ditch the code that tries to
check and patch up incorrect memory attributes.

Also realize that pmap_clean_page(pg, FALSE) doesn't do anything
anymore so remove those calls and drop the 2nd argument from
pmap_clean_page(pg, TRUE) calls.

Last but not least, get rid of pmap_pte_init_generic() here. The only
useful thing it did was setting pmap_copy_page_func() and
pmap_zero_page_func().

This diff should not introduce any change in behaviour.

ok visa@


# 1.35 08-Aug-2016 kettenis

Mapping non-cachable memory as cachable and subsequently changing the mapping
to non-cachable is retarded. Fix this by introducing PMAP_NOCACHE and
PMAP_DEVICE flags that can be or'ed into the physical address passed to
pmap_kenter(9), like we have on many of our other architectures. This way we
can also properly distinguish between device memory and normal (non-cachable)
memory.

ok visa@


# 1.34 08-Aug-2016 kettenis

ARMv7 data caches are "effectively" PIPT. This means there is in general
no need to clean and/or invalidate cached pages. So remove most of the
cache cleaning and invalidation from the pmap. We still need to synchronize
the instruction cache with the data cache in various places though. And we
also need to make sure that we clean and invalidate when we make a page
non-cachable.

Tested by Daniel Bolgheroni, mglocker@ and jsg@. on Cortex-A8 and myself on
Cortex-A9.

ok visa@


# 1.33 06-Aug-2016 kettenis

Put page tables in normal cachable memory on armv7. Check if the MMU walks
the page tables coherently and also skip flushing modified ptes out of the
cache in that case. Speeds up building a kernel with a factor of two on
Cortex-A9 (tested by me) and Cortex-A8 (tested by mglocker@).

ok patrick@


# 1.32 03-Aug-2016 kettenis

Simplify the way we handle TLB flushes. Since ARMv7 effectively has a
unified TLB there is not much point in optimizing TLB flushing for pages
that have never been executable. The only difference is a flush of the
branch predictor and even that isn't necessary anymore on all but the oldest
Cortex cores.

ok patrick@


# 1.31 31-Jul-2016 kettenis

Remove devmap stuff which is unused on armv7.

ok patrick@


# 1.30 31-Jul-2016 kettenis

According to te armv7 ARM TLB entries that caused a Permission fault might
be held in the TLB. On top of that valid page table entries might be
speculatively loaded into the TLB. As a result we need to flush TLB entries
even when the page in question has not been referenced.

Fixes pmap_fault_fixup messages on Cortex-A53, and presumably also on
Cortex-A7.

ok patrick@, guenther@


# 1.29 29-Jul-2016 patrick

Only flush the virtual page if it was actually mapped. Otherwise
we will run into translation faults.

ok tom@


# 1.28 27-Jul-2016 patrick

When pmap_page_remove() is called by UVM, a physical page is to be
removed from pmaps it currently is in. To check if a virtual address
pointing to that physical page has been mapped, the code uses
the l2pte_valid() function. Unfortunately there is a difference
between being valid and the PTE being zero. If a page is mapped
but has never been accessed, it will be non-zero but invalid.

In that case the PTE for that virtual address will not be zeroed
and the virtual address will be removed from the vm page struct.

The next time someone tries to map a page to that virtual address,
other pmap code will consider the virtual address to be already
mapped, even though that assumption is completely wrong.

To make sure this does not happen, check the PTE for zero. This way
the PTE will be zeroed correctly. The check for zero is how other
ARM pmap code also handles this issue.

ok kettenis@ tom@


Revision tags: OPENBSD_6_0_BASE
# 1.27 19-Jul-2016 tom

Remove what appears to be a copy-paste error setting cur_ttb
in pmap_free_l1().

from aalm@ - thanks

ok patrick@


# 1.26 18-Jul-2016 tom

Don't need a separate flags variable in armv7 pmap_clean_page() -
just use the pv_flags. ('Twas a copy-paste from arm's pmap_clean_page(),
which did need it.)

Also remove even less used flags variable from pmap_page_remove().

First part from a diff from aalm@ - thanks

ok kettenis@ "looks good" patrick@


# 1.25 07-Jun-2016 dlg

consistently set ipls on pmap pools.

this is a step toward making ipls unconditionaly on pools.

ok deraadt@ kettenis@


# 1.24 03-Mar-2016 jsg

When a physical address is needed to flush the secondary cache use
VM_PAGE_TO_PHYS() instead of unnecessarily calling pmap_extract().

From Patrick Wildt.


Revision tags: OPENBSD_5_9_BASE
# 1.23 01-Feb-2016 jsg

Fix the encoding of AP bits for large page second-level
short-descriptors with arm v7 (same as small page encoding, except XN is
in a different bit for the mask).

Expanded version of a diff from Patrick Wildt who also tested and
reviewed this.


# 1.22 31-Jan-2016 jsg

Switch from PSR_X_bit and X32_bit PSR macro names to just PSR_X.
This matches FreeBSD and makes things a bit more consistent.
Discussed with Patrick.


# 1.21 08-Sep-2015 kettenis

Give the pool page allocator backends more sensible names. We now have:
* pool_allocator_single: single page allocator, always interrupt safe
* pool_allocator_multi: multi-page allocator, interrupt safe
* pool_allocator_multi_ni: multi-page allocator, not interrupt-safe

ok deraadt@, dlg@


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE
# 1.20 02-Feb-2015 mlarkin

Remove some pmap locks that were #defined to be nothing (empty). Discussed
with many, ok kettenis@.


# 1.19 29-Jan-2015 deraadt

remove no-op simple locks
tested by jsg, ok miod


# 1.18 16-Nov-2014 deraadt

Replace a plethora of historical protection options with just
PROT_NONE, PROT_READ, PROT_WRITE, and PROT_EXEC from mman.h.
PROT_MASK is introduced as the one true way of extracting those bits.
Remove UVM_ADV_* wrapper, using the standard names.
ok doug guenther kettenis


# 1.17 27-Oct-2014 jsg

use #ifdef DDB for Debugger()


# 1.16 07-Oct-2014 jsg

Correct the l1 pte permission bits for armv7. Problem pointed out
by Patrick Wildt who made a similiar change in Bitrig.

ok miod@ rapha@


Revision tags: OPENBSD_5_6_BASE
# 1.15 12-Jul-2014 tedu

add a size argument to free. will be used soon, but for now default to 0.
after discussions with beck deraadt kettenis.


# 1.14 08-May-2014 miod

Format string fixes and removal of -Wno-format for arm kernels.


# 1.13 29-Mar-2014 guenther

It's been a quarter century: we can assume volatile is present with that name.

ok dlg@ mpi@ deraadt@


Revision tags: OPENBSD_5_5_BASE
# 1.12 04-Nov-2013 dlg

move the arm pmaps away from pool ctors to just initting memory after its
been allocated. also gets rid of a potential bug where pool_get could
return NULL and pmap_alloc_l2_ptp tried to blindly init it.

tests, tweaks, and ok patrick@


# 1.11 29-Oct-2013 patrick

The cache mask for ARMv7 is a little bit different from the one inited by
the generic function. While there, also set the cache bits manually.

ok aalm@


# 1.10 22-Oct-2013 patrick

Some current boards do not have write-through caching. For those,
we enable write-back, but it seems this is not working and those
boards hang on bootup. Until that is fixed, do not cache PTEs
on those boards.


# 1.9 03-Sep-2013 patrick

Rewrite the ARMv7 cache discovery, as some assumptions in the previous one
were utterly wrong. Fix Log2(), correct one taken from the scheduler code.

Tested by rapha@ and Artturi Alm.


Revision tags: OPENBSD_5_4_BASE
# 1.8 09-Jun-2013 miod

typo


# 1.7 22-May-2013 patrick

We're handling L2 there, so use the corresponding define, not the L1 one.

ok bmercer@


# 1.6 21-May-2013 patrick

When mapping a new entry, map it read-only, even though it should be
writable. This will cause a pmap fault on first write, so that we can
mark the page as modified. Also mask the bits used for the protection
settings, so that there aren't any leftovers.

ok bmercer@


# 1.5 09-May-2013 patrick

On ARMv7 we can't use the cache mask to check for coherency.
Therefore we add new macros to be able to check for it properly.

ok miod@


# 1.4 28-Apr-2013 patrick

Revert the ARMv7 header split introduced in pmap7.

ok bmercer@


# 1.3 16-Apr-2013 patrick

Add secondary cache flushes to armv7's pmap.

ok bmercer@


# 1.2 27-Mar-2013 patrick

Further updates to pmap7. Fixes some problems and removes debug printfs.

ok miod@


Revision tags: OPENBSD_5_3_BASE
# 1.1 17-Jan-2013 bmercer

New pmap for panda boards. Work from lots of folks.
OK miod@


# 1.58 10-Feb-2019 tedu

revert revert revert. there are many other archs that use custom allocs.


# 1.57 10-Feb-2019 tedu

make it possible to reduce kmem pressure by letting some pools use a more
accomodating allocator. an interrupt safe pool may also be used in process
context, as indicated by waitok flags. thanks to the garbage collector, we
can always free pages in process context. the only complication is where
to put the pages. solve this by saving the allocation flags in the pool
page header so the free function can examine them.
not actually used in this diff. (coming soon.)
arm testing and compile fixes from phessler


Revision tags: OPENBSD_6_2_BASE OPENBSD_6_3_BASE OPENBSD_6_4_BASE
# 1.56 08-Sep-2017 deraadt

If you use sys/param.h, you don't need sys/types.h


Revision tags: OPENBSD_6_1_BASE
# 1.55 22-Oct-2016 patrick

If an Access Flag fault happens while we were running the kernel and
it happened on a kernel page, we need to consult the kernel pmap
instead of the current proc's pmap. Fixes panic when using tmpfs.

ok kettenis@


# 1.54 19-Oct-2016 guenther

Change pmap_proc_iflush() to take a process instead of a proc
powerpc: rename second argument of pmap_proc_iflush() to match other archs

ok kettenis@


# 1.53 24-Sep-2016 kettenis

Remove a couple of unsused static inline functions. Also remove a comparis
of an array to a null pointer that is always false. Found with clang.

ok jsg@


# 1.52 15-Sep-2016 dlg

all pools have their ipl set via pool_setipl, so fold it into pool_init.

the ioff argument to pool_init() is unused and has been for many
years, so this replaces it with an ipl argument. because the ipl
will be set on init we no longer need pool_setipl.

most of these changes have been done with coccinelle using the spatch
below. cocci sucks at formatting code though, so i fixed that by hand.

the manpage and subr_pool.c bits i did myself.

ok tedu@ jmatthew@

@ipl@
expression pp;
expression ipl;
expression s, a, o, f, m, p;
@@
-pool_init(pp, s, a, o, f, m, p);
-pool_setipl(pp, ipl);
+pool_init(pp, s, a, ipl, f, m, p);


# 1.51 31-Aug-2016 jsg

In pmap_activate instead of doing disable_interrupts/enable_interrupts
nested inside of splhigh/splx just disable and enable interrupts
once with inline cps instructions.

Remove uneeded pcb_pl1vec block as well, suggested by kettenis.

ok kettenis@


# 1.50 27-Aug-2016 kettenis

Add support for the PXN bit in level 1 translation table descriptors and
enable it on CPUs that support it. When enabled, this prevents the kernel
from executing userland code.

ok jsg@, tom@


# 1.49 26-Aug-2016 kettenis

Remove cpu_cpwait() calls; they are no-ops on armv7.

ok tom@


# 1.48 26-Aug-2016 kettenis

Remove the code that switches around MMU domains on armv7. MMU domains are
basically a relic from the past. Using them doesn't make a lot of sense
the way our pmaps work. Support for MMU domains isn't present in
long-descriptor translation table format, so it is clearly on its way out.

Based on a diff from Artituri Alm.

ok patrick@


# 1.47 24-Aug-2016 kettenis

Replace pmap_fault_fixup() with an access flag fault handler on armv7.

ok tom@


# 1.46 20-Aug-2016 kettenis

Fix indentation.


# 1.45 20-Aug-2016 kettenis

Argh, commit from the wrong tree. Revert previous commit.


# 1.44 20-Aug-2016 kettenis

Fix indentation.


# 1.43 20-Aug-2016 kettenis

Correctly enter a mapping as writable if no "page modified" emulation
is needed.

ok visa@, patrick@


# 1.42 19-Aug-2016 kettenis

Start using to XN flag to enforce that mappings without PROT_EXEC are
non-executable.

ok visa@, deraadt@


# 1.41 19-Aug-2016 kettenis

Mark device memory as execute-never to prevent a speculative instruction fetch
to access it.


# 1.40 19-Aug-2016 kettenis

Use Access Flag to do page reference emulation.

ok visa@


# 1.39 18-Aug-2016 kettenis

Separate out the Access Flag bit from the Access Permission bits in the
armv7 pmap.

ok tom@


# 1.38 16-Aug-2016 kettenis

Fix typo/inconsistensy where L1_S_DOMAIN was used instead of L1_C_DOMAIN.
These are functionally equivolent so it didn't matter and the resulting
code doesn't change.


# 1.37 11-Aug-2016 kettenis

The ARMv7 ARM says that the TLB may hold translation table entries at any
level of the translation table, including entries that point to further
levels of the tables. This means that we have to do a TLB flush whenever
we invalidate an L1 slot too. Doing so fixes the pmap_fault_fixup
issue on Cortex-A7 processors.


# 1.36 09-Aug-2016 kettenis

The page tables are cached now, and given the significant speedup, I
don't think we'll ever go back. So let's ditch the code that tries to
check and patch up incorrect memory attributes.

Also realize that pmap_clean_page(pg, FALSE) doesn't do anything
anymore so remove those calls and drop the 2nd argument from
pmap_clean_page(pg, TRUE) calls.

Last but not least, get rid of pmap_pte_init_generic() here. The only
useful thing it did was setting pmap_copy_page_func() and
pmap_zero_page_func().

This diff should not introduce any change in behaviour.

ok visa@


# 1.35 08-Aug-2016 kettenis

Mapping non-cachable memory as cachable and subsequently changing the mapping
to non-cachable is retarded. Fix this by introducing PMAP_NOCACHE and
PMAP_DEVICE flags that can be or'ed into the physical address passed to
pmap_kenter(9), like we have on many of our other architectures. This way we
can also properly distinguish between device memory and normal (non-cachable)
memory.

ok visa@


# 1.34 08-Aug-2016 kettenis

ARMv7 data caches are "effectively" PIPT. This means there is in general
no need to clean and/or invalidate cached pages. So remove most of the
cache cleaning and invalidation from the pmap. We still need to synchronize
the instruction cache with the data cache in various places though. And we
also need to make sure that we clean and invalidate when we make a page
non-cachable.

Tested by Daniel Bolgheroni, mglocker@ and jsg@. on Cortex-A8 and myself on
Cortex-A9.

ok visa@


# 1.33 06-Aug-2016 kettenis

Put page tables in normal cachable memory on armv7. Check if the MMU walks
the page tables coherently and also skip flushing modified ptes out of the
cache in that case. Speeds up building a kernel with a factor of two on
Cortex-A9 (tested by me) and Cortex-A8 (tested by mglocker@).

ok patrick@


# 1.32 03-Aug-2016 kettenis

Simplify the way we handle TLB flushes. Since ARMv7 effectively has a
unified TLB there is not much point in optimizing TLB flushing for pages
that have never been executable. The only difference is a flush of the
branch predictor and even that isn't necessary anymore on all but the oldest
Cortex cores.

ok patrick@


# 1.31 31-Jul-2016 kettenis

Remove devmap stuff which is unused on armv7.

ok patrick@


# 1.30 31-Jul-2016 kettenis

According to te armv7 ARM TLB entries that caused a Permission fault might
be held in the TLB. On top of that valid page table entries might be
speculatively loaded into the TLB. As a result we need to flush TLB entries
even when the page in question has not been referenced.

Fixes pmap_fault_fixup messages on Cortex-A53, and presumably also on
Cortex-A7.

ok patrick@, guenther@


# 1.29 29-Jul-2016 patrick

Only flush the virtual page if it was actually mapped. Otherwise
we will run into translation faults.

ok tom@


# 1.28 27-Jul-2016 patrick

When pmap_page_remove() is called by UVM, a physical page is to be
removed from pmaps it currently is in. To check if a virtual address
pointing to that physical page has been mapped, the code uses
the l2pte_valid() function. Unfortunately there is a difference
between being valid and the PTE being zero. If a page is mapped
but has never been accessed, it will be non-zero but invalid.

In that case the PTE for that virtual address will not be zeroed
and the virtual address will be removed from the vm page struct.

The next time someone tries to map a page to that virtual address,
other pmap code will consider the virtual address to be already
mapped, even though that assumption is completely wrong.

To make sure this does not happen, check the PTE for zero. This way
the PTE will be zeroed correctly. The check for zero is how other
ARM pmap code also handles this issue.

ok kettenis@ tom@


Revision tags: OPENBSD_6_0_BASE
# 1.27 19-Jul-2016 tom

Remove what appears to be a copy-paste error setting cur_ttb
in pmap_free_l1().

from aalm@ - thanks

ok patrick@


# 1.26 18-Jul-2016 tom

Don't need a separate flags variable in armv7 pmap_clean_page() -
just use the pv_flags. ('Twas a copy-paste from arm's pmap_clean_page(),
which did need it.)

Also remove even less used flags variable from pmap_page_remove().

First part from a diff from aalm@ - thanks

ok kettenis@ "looks good" patrick@


# 1.25 07-Jun-2016 dlg

consistently set ipls on pmap pools.

this is a step toward making ipls unconditionaly on pools.

ok deraadt@ kettenis@


# 1.24 03-Mar-2016 jsg

When a physical address is needed to flush the secondary cache use
VM_PAGE_TO_PHYS() instead of unnecessarily calling pmap_extract().

From Patrick Wildt.


Revision tags: OPENBSD_5_9_BASE
# 1.23 01-Feb-2016 jsg

Fix the encoding of AP bits for large page second-level
short-descriptors with arm v7 (same as small page encoding, except XN is
in a different bit for the mask).

Expanded version of a diff from Patrick Wildt who also tested and
reviewed this.


# 1.22 31-Jan-2016 jsg

Switch from PSR_X_bit and X32_bit PSR macro names to just PSR_X.
This matches FreeBSD and makes things a bit more consistent.
Discussed with Patrick.


# 1.21 08-Sep-2015 kettenis

Give the pool page allocator backends more sensible names. We now have:
* pool_allocator_single: single page allocator, always interrupt safe
* pool_allocator_multi: multi-page allocator, interrupt safe
* pool_allocator_multi_ni: multi-page allocator, not interrupt-safe

ok deraadt@, dlg@


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE
# 1.20 02-Feb-2015 mlarkin

Remove some pmap locks that were #defined to be nothing (empty). Discussed
with many, ok kettenis@.


# 1.19 29-Jan-2015 deraadt

remove no-op simple locks
tested by jsg, ok miod


# 1.18 16-Nov-2014 deraadt

Replace a plethora of historical protection options with just
PROT_NONE, PROT_READ, PROT_WRITE, and PROT_EXEC from mman.h.
PROT_MASK is introduced as the one true way of extracting those bits.
Remove UVM_ADV_* wrapper, using the standard names.
ok doug guenther kettenis


# 1.17 27-Oct-2014 jsg

use #ifdef DDB for Debugger()


# 1.16 07-Oct-2014 jsg

Correct the l1 pte permission bits for armv7. Problem pointed out
by Patrick Wildt who made a similiar change in Bitrig.

ok miod@ rapha@


Revision tags: OPENBSD_5_6_BASE
# 1.15 12-Jul-2014 tedu

add a size argument to free. will be used soon, but for now default to 0.
after discussions with beck deraadt kettenis.


# 1.14 08-May-2014 miod

Format string fixes and removal of -Wno-format for arm kernels.


# 1.13 29-Mar-2014 guenther

It's been a quarter century: we can assume volatile is present with that name.

ok dlg@ mpi@ deraadt@


Revision tags: OPENBSD_5_5_BASE
# 1.12 04-Nov-2013 dlg

move the arm pmaps away from pool ctors to just initting memory after its
been allocated. also gets rid of a potential bug where pool_get could
return NULL and pmap_alloc_l2_ptp tried to blindly init it.

tests, tweaks, and ok patrick@


# 1.11 29-Oct-2013 patrick

The cache mask for ARMv7 is a little bit different from the one inited by
the generic function. While there, also set the cache bits manually.

ok aalm@


# 1.10 22-Oct-2013 patrick

Some current boards do not have write-through caching. For those,
we enable write-back, but it seems this is not working and those
boards hang on bootup. Until that is fixed, do not cache PTEs
on those boards.


# 1.9 03-Sep-2013 patrick

Rewrite the ARMv7 cache discovery, as some assumptions in the previous one
were utterly wrong. Fix Log2(), correct one taken from the scheduler code.

Tested by rapha@ and Artturi Alm.


Revision tags: OPENBSD_5_4_BASE
# 1.8 09-Jun-2013 miod

typo


# 1.7 22-May-2013 patrick

We're handling L2 there, so use the corresponding define, not the L1 one.

ok bmercer@


# 1.6 21-May-2013 patrick

When mapping a new entry, map it read-only, even though it should be
writable. This will cause a pmap fault on first write, so that we can
mark the page as modified. Also mask the bits used for the protection
settings, so that there aren't any leftovers.

ok bmercer@


# 1.5 09-May-2013 patrick

On ARMv7 we can't use the cache mask to check for coherency.
Therefore we add new macros to be able to check for it properly.

ok miod@


# 1.4 28-Apr-2013 patrick

Revert the ARMv7 header split introduced in pmap7.

ok bmercer@


# 1.3 16-Apr-2013 patrick

Add secondary cache flushes to armv7's pmap.

ok bmercer@


# 1.2 27-Mar-2013 patrick

Further updates to pmap7. Fixes some problems and removes debug printfs.

ok miod@


Revision tags: OPENBSD_5_3_BASE
# 1.1 17-Jan-2013 bmercer

New pmap for panda boards. Work from lots of folks.
OK miod@


Revision tags: OPENBSD_6_2_BASE
# 1.56 08-Sep-2017 deraadt

If you use sys/param.h, you don't need sys/types.h


Revision tags: OPENBSD_6_1_BASE
# 1.55 22-Oct-2016 patrick

If an Access Flag fault happens while we were running the kernel and
it happened on a kernel page, we need to consult the kernel pmap
instead of the current proc's pmap. Fixes panic when using tmpfs.

ok kettenis@


# 1.54 19-Oct-2016 guenther

Change pmap_proc_iflush() to take a process instead of a proc
powerpc: rename second argument of pmap_proc_iflush() to match other archs

ok kettenis@


# 1.53 24-Sep-2016 kettenis

Remove a couple of unsused static inline functions. Also remove a comparis
of an array to a null pointer that is always false. Found with clang.

ok jsg@


# 1.52 15-Sep-2016 dlg

all pools have their ipl set via pool_setipl, so fold it into pool_init.

the ioff argument to pool_init() is unused and has been for many
years, so this replaces it with an ipl argument. because the ipl
will be set on init we no longer need pool_setipl.

most of these changes have been done with coccinelle using the spatch
below. cocci sucks at formatting code though, so i fixed that by hand.

the manpage and subr_pool.c bits i did myself.

ok tedu@ jmatthew@

@ipl@
expression pp;
expression ipl;
expression s, a, o, f, m, p;
@@
-pool_init(pp, s, a, o, f, m, p);
-pool_setipl(pp, ipl);
+pool_init(pp, s, a, ipl, f, m, p);


# 1.51 31-Aug-2016 jsg

In pmap_activate instead of doing disable_interrupts/enable_interrupts
nested inside of splhigh/splx just disable and enable interrupts
once with inline cps instructions.

Remove uneeded pcb_pl1vec block as well, suggested by kettenis.

ok kettenis@


# 1.50 27-Aug-2016 kettenis

Add support for the PXN bit in level 1 translation table descriptors and
enable it on CPUs that support it. When enabled, this prevents the kernel
from executing userland code.

ok jsg@, tom@


# 1.49 26-Aug-2016 kettenis

Remove cpu_cpwait() calls; they are no-ops on armv7.

ok tom@


# 1.48 26-Aug-2016 kettenis

Remove the code that switches around MMU domains on armv7. MMU domains are
basically a relic from the past. Using them doesn't make a lot of sense
the way our pmaps work. Support for MMU domains isn't present in
long-descriptor translation table format, so it is clearly on its way out.

Based on a diff from Artituri Alm.

ok patrick@


# 1.47 24-Aug-2016 kettenis

Replace pmap_fault_fixup() with an access flag fault handler on armv7.

ok tom@


# 1.46 20-Aug-2016 kettenis

Fix indentation.


# 1.45 20-Aug-2016 kettenis

Argh, commit from the wrong tree. Revert previous commit.


# 1.44 20-Aug-2016 kettenis

Fix indentation.


# 1.43 20-Aug-2016 kettenis

Correctly enter a mapping as writable if no "page modified" emulation
is needed.

ok visa@, patrick@


# 1.42 19-Aug-2016 kettenis

Start using to XN flag to enforce that mappings without PROT_EXEC are
non-executable.

ok visa@, deraadt@


# 1.41 19-Aug-2016 kettenis

Mark device memory as execute-never to prevent a speculative instruction fetch
to access it.


# 1.40 19-Aug-2016 kettenis

Use Access Flag to do page reference emulation.

ok visa@


# 1.39 18-Aug-2016 kettenis

Separate out the Access Flag bit from the Access Permission bits in the
armv7 pmap.

ok tom@


# 1.38 16-Aug-2016 kettenis

Fix typo/inconsistensy where L1_S_DOMAIN was used instead of L1_C_DOMAIN.
These are functionally equivolent so it didn't matter and the resulting
code doesn't change.


# 1.37 11-Aug-2016 kettenis

The ARMv7 ARM says that the TLB may hold translation table entries at any
level of the translation table, including entries that point to further
levels of the tables. This means that we have to do a TLB flush whenever
we invalidate an L1 slot too. Doing so fixes the pmap_fault_fixup
issue on Cortex-A7 processors.


# 1.36 09-Aug-2016 kettenis

The page tables are cached now, and given the significant speedup, I
don't think we'll ever go back. So let's ditch the code that tries to
check and patch up incorrect memory attributes.

Also realize that pmap_clean_page(pg, FALSE) doesn't do anything
anymore so remove those calls and drop the 2nd argument from
pmap_clean_page(pg, TRUE) calls.

Last but not least, get rid of pmap_pte_init_generic() here. The only
useful thing it did was setting pmap_copy_page_func() and
pmap_zero_page_func().

This diff should not introduce any change in behaviour.

ok visa@


# 1.35 08-Aug-2016 kettenis

Mapping non-cachable memory as cachable and subsequently changing the mapping
to non-cachable is retarded. Fix this by introducing PMAP_NOCACHE and
PMAP_DEVICE flags that can be or'ed into the physical address passed to
pmap_kenter(9), like we have on many of our other architectures. This way we
can also properly distinguish between device memory and normal (non-cachable)
memory.

ok visa@


# 1.34 08-Aug-2016 kettenis

ARMv7 data caches are "effectively" PIPT. This means there is in general
no need to clean and/or invalidate cached pages. So remove most of the
cache cleaning and invalidation from the pmap. We still need to synchronize
the instruction cache with the data cache in various places though. And we
also need to make sure that we clean and invalidate when we make a page
non-cachable.

Tested by Daniel Bolgheroni, mglocker@ and jsg@. on Cortex-A8 and myself on
Cortex-A9.

ok visa@


# 1.33 06-Aug-2016 kettenis

Put page tables in normal cachable memory on armv7. Check if the MMU walks
the page tables coherently and also skip flushing modified ptes out of the
cache in that case. Speeds up building a kernel with a factor of two on
Cortex-A9 (tested by me) and Cortex-A8 (tested by mglocker@).

ok patrick@


# 1.32 03-Aug-2016 kettenis

Simplify the way we handle TLB flushes. Since ARMv7 effectively has a
unified TLB there is not much point in optimizing TLB flushing for pages
that have never been executable. The only difference is a flush of the
branch predictor and even that isn't necessary anymore on all but the oldest
Cortex cores.

ok patrick@


# 1.31 31-Jul-2016 kettenis

Remove devmap stuff which is unused on armv7.

ok patrick@


# 1.30 31-Jul-2016 kettenis

According to te armv7 ARM TLB entries that caused a Permission fault might
be held in the TLB. On top of that valid page table entries might be
speculatively loaded into the TLB. As a result we need to flush TLB entries
even when the page in question has not been referenced.

Fixes pmap_fault_fixup messages on Cortex-A53, and presumably also on
Cortex-A7.

ok patrick@, guenther@


# 1.29 29-Jul-2016 patrick

Only flush the virtual page if it was actually mapped. Otherwise
we will run into translation faults.

ok tom@


# 1.28 27-Jul-2016 patrick

When pmap_page_remove() is called by UVM, a physical page is to be
removed from pmaps it currently is in. To check if a virtual address
pointing to that physical page has been mapped, the code uses
the l2pte_valid() function. Unfortunately there is a difference
between being valid and the PTE being zero. If a page is mapped
but has never been accessed, it will be non-zero but invalid.

In that case the PTE for that virtual address will not be zeroed
and the virtual address will be removed from the vm page struct.

The next time someone tries to map a page to that virtual address,
other pmap code will consider the virtual address to be already
mapped, even though that assumption is completely wrong.

To make sure this does not happen, check the PTE for zero. This way
the PTE will be zeroed correctly. The check for zero is how other
ARM pmap code also handles this issue.

ok kettenis@ tom@


Revision tags: OPENBSD_6_0_BASE
# 1.27 19-Jul-2016 tom

Remove what appears to be a copy-paste error setting cur_ttb
in pmap_free_l1().

from aalm@ - thanks

ok patrick@


# 1.26 18-Jul-2016 tom

Don't need a separate flags variable in armv7 pmap_clean_page() -
just use the pv_flags. ('Twas a copy-paste from arm's pmap_clean_page(),
which did need it.)

Also remove even less used flags variable from pmap_page_remove().

First part from a diff from aalm@ - thanks

ok kettenis@ "looks good" patrick@


# 1.25 07-Jun-2016 dlg

consistently set ipls on pmap pools.

this is a step toward making ipls unconditionaly on pools.

ok deraadt@ kettenis@


# 1.24 03-Mar-2016 jsg

When a physical address is needed to flush the secondary cache use
VM_PAGE_TO_PHYS() instead of unnecessarily calling pmap_extract().

From Patrick Wildt.


Revision tags: OPENBSD_5_9_BASE
# 1.23 01-Feb-2016 jsg

Fix the encoding of AP bits for large page second-level
short-descriptors with arm v7 (same as small page encoding, except XN is
in a different bit for the mask).

Expanded version of a diff from Patrick Wildt who also tested and
reviewed this.


# 1.22 31-Jan-2016 jsg

Switch from PSR_X_bit and X32_bit PSR macro names to just PSR_X.
This matches FreeBSD and makes things a bit more consistent.
Discussed with Patrick.


# 1.21 08-Sep-2015 kettenis

Give the pool page allocator backends more sensible names. We now have:
* pool_allocator_single: single page allocator, always interrupt safe
* pool_allocator_multi: multi-page allocator, interrupt safe
* pool_allocator_multi_ni: multi-page allocator, not interrupt-safe

ok deraadt@, dlg@


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE
# 1.20 02-Feb-2015 mlarkin

Remove some pmap locks that were #defined to be nothing (empty). Discussed
with many, ok kettenis@.


# 1.19 29-Jan-2015 deraadt

remove no-op simple locks
tested by jsg, ok miod


# 1.18 16-Nov-2014 deraadt

Replace a plethora of historical protection options with just
PROT_NONE, PROT_READ, PROT_WRITE, and PROT_EXEC from mman.h.
PROT_MASK is introduced as the one true way of extracting those bits.
Remove UVM_ADV_* wrapper, using the standard names.
ok doug guenther kettenis


# 1.17 27-Oct-2014 jsg

use #ifdef DDB for Debugger()


# 1.16 07-Oct-2014 jsg

Correct the l1 pte permission bits for armv7. Problem pointed out
by Patrick Wildt who made a similiar change in Bitrig.

ok miod@ rapha@


Revision tags: OPENBSD_5_6_BASE
# 1.15 12-Jul-2014 tedu

add a size argument to free. will be used soon, but for now default to 0.
after discussions with beck deraadt kettenis.


# 1.14 08-May-2014 miod

Format string fixes and removal of -Wno-format for arm kernels.


# 1.13 29-Mar-2014 guenther

It's been a quarter century: we can assume volatile is present with that name.

ok dlg@ mpi@ deraadt@


Revision tags: OPENBSD_5_5_BASE
# 1.12 04-Nov-2013 dlg

move the arm pmaps away from pool ctors to just initting memory after its
been allocated. also gets rid of a potential bug where pool_get could
return NULL and pmap_alloc_l2_ptp tried to blindly init it.

tests, tweaks, and ok patrick@


# 1.11 29-Oct-2013 patrick

The cache mask for ARMv7 is a little bit different from the one inited by
the generic function. While there, also set the cache bits manually.

ok aalm@


# 1.10 22-Oct-2013 patrick

Some current boards do not have write-through caching. For those,
we enable write-back, but it seems this is not working and those
boards hang on bootup. Until that is fixed, do not cache PTEs
on those boards.


# 1.9 03-Sep-2013 patrick

Rewrite the ARMv7 cache discovery, as some assumptions in the previous one
were utterly wrong. Fix Log2(), correct one taken from the scheduler code.

Tested by rapha@ and Artturi Alm.


Revision tags: OPENBSD_5_4_BASE
# 1.8 09-Jun-2013 miod

typo


# 1.7 22-May-2013 patrick

We're handling L2 there, so use the corresponding define, not the L1 one.

ok bmercer@


# 1.6 21-May-2013 patrick

When mapping a new entry, map it read-only, even though it should be
writable. This will cause a pmap fault on first write, so that we can
mark the page as modified. Also mask the bits used for the protection
settings, so that there aren't any leftovers.

ok bmercer@


# 1.5 09-May-2013 patrick

On ARMv7 we can't use the cache mask to check for coherency.
Therefore we add new macros to be able to check for it properly.

ok miod@


# 1.4 28-Apr-2013 patrick

Revert the ARMv7 header split introduced in pmap7.

ok bmercer@


# 1.3 16-Apr-2013 patrick

Add secondary cache flushes to armv7's pmap.

ok bmercer@


# 1.2 27-Mar-2013 patrick

Further updates to pmap7. Fixes some problems and removes debug printfs.

ok miod@


Revision tags: OPENBSD_5_3_BASE
# 1.1 17-Jan-2013 bmercer

New pmap for panda boards. Work from lots of folks.
OK miod@