History log of /netbsd-current/sys/arch/aarch64/aarch64/pmap.c
Revision (<<< Hide revision tags) (Show revision tags >>>) Date Author Comments
# 1.151 16-Feb-2024 andvar

Replace obsolete pv_dump() call with pmap_db_mdpg_print().

It was rewritten on rev 1.107, but not replaced with new implementation in
PMAP_PV_DEBUG guarded block.


# 1.150 07-Feb-2024 msaitoh

Remove ryo@'s mail addresses.


Revision tags: thorpej-ifq-base thorpej-altq-separation-base
# 1.149 20-Apr-2023 skrll

Provide a shared pmap_devmap implementation and convert all pmap_devmap
arrays to use DEVMAP_ENTRY{,_END}


# 1.148 16-Apr-2023 skrll

Rename VM_KERNEL_IO_ADDRESS to VM_KERNEL_IO_BASE to match RISC-V

It's less letters, matches other similar variables and will help with
sharing code between the two architectures.

NFCI.


Revision tags: netbsd-10-0-RC4 netbsd-10-0-RC3 netbsd-10-0-RC2 netbsd-10-0-RC1 netbsd-10-base
# 1.147 30-Oct-2022 riastradh

aarch64/pmap: Fix criterion in previous.

Use the pte bit that says whether this is a PMAP_WIRED page, not the
bit that says whether this is a non-global page.

(Forgot to git commit --amend before exporting to CVS, sorry!)


# 1.146 30-Oct-2022 riastradh

aarch64/pmap(9): Teach pmap_protect about pmap_kenter_pa mappings.

Pages mapped with pmap_kenter_pa are necessarily unmanaged, so there
are no P->V records, and pmap_kenter_pa leaves pp->pp_pv.pv_va zero
with no modified/referenced state.

However, pmap_protect erroneously examined pp->pp_pv.pv_va to
ascertain the modified/referenced state -- and if the page was not
marked referenced, pmap_protect would clear the LX_BLKPAG_AF bit
(Access Flag), with the effect that subsequent uses of the page fault
and require a detour through pmap_fault_fixup.

This caused problems for the kernel module loader:

- When loading the text section, kobj_load first allocates kva with
uvm_km_alloc(UVM_KMF_WIRED|UVM_KMF_EXEC), which creates ptes with
pmap_kenter_pa. These ptes are writable, so we can copy the text
section into them, and have LX_BLKPAG_AF set so there will be no
fault when they are used by the kernel.

- But then kobj_affix makes the text section read/execute-only (and
nonwritable) with uvm_km_protect(VM_PROT_READ|VM_PROT_EXECUTE),
which updates the ptes with pmap_protect. This _should_ leave
LX_BLKPAG_AF set, but by inadvertently treating the page as managed
when it should be unmanaged, pmap_protect cleared it instead.

- Most of the time, clearing LX_BLKPAG_AF caused no problem, because
pmap_fault_fixup would silently resolve it. But if a hard
interrupt handler tried to use any page in the module's text (or
rodata, I suspect) that was not yet fixed up, the CPU would fault
and enter pmap_fault_fixup -- which would promptly crash (or hang)
by trying to take the pmap lock in interrupt context, which is
forbidden.

I observed this by loading dtrace.kmod early at boot and trying to
dtrace hard interrupt handlers.

With this change, pmap_protect now recognizes wired mappings (as
created by pmap_kenter_pa) before consulting pp->pp_pv.pv_va, and
preserves then LX_BLKPAG_AF bit in that case.

ok skrll


# 1.145 29-Oct-2022 skrll

fix a spello in a comment


# 1.144 28-Oct-2022 skrll

Remove some empty lines


# 1.143 23-Oct-2022 skrll

Use UVMHIST_CALLARGS in pmap_bootstrap


# 1.142 23-Oct-2022 skrll

Only define the EFI variable if EFI_RUNTIME


# 1.141 20-Oct-2022 skrll

KNF


# 1.140 15-Oct-2022 jmcneill

Use "non-posted" instead of "strongly ordered" to describe nGnRnE mappings

Rename the following defines:
- _ARM_BUS_SPACE_MAP_STRONGLY_ORDERED to BUS_SPACE_MAP_NONPOSTED
- PMAP_DEV_SO to PMAP_DEV_NP
- LX_BLKPAG_ATTR_DEVICE_MEM_SO to LX_BLKPAG_ATTR_DEVICE_MEM_NP
Rename the following option:
- AARCH64_DEVICE_MEM_STRONGLY_ORDERED to AARCH64_DEVICE_MEM_NONPOSTED


Revision tags: bouyer-sunxi-drm-base
# 1.139 19-Aug-2022 ryo

Fixed a bug that pte's __BIT(63,48) could be set when accessing addresses above 0x0001000000000000 in /dev/mem with mmap().


# 1.138 19-Aug-2022 ryo

When accessed in mmap by the device pager, pmap_enter() may be called with prot == PROT_WRITE.


# 1.137 03-May-2022 skrll

Sprinkle some KASSERT(kpreempt_disabled());


# 1.136 27-Apr-2022 ryo

since pmap_activate_efirt() rewrites TTBR0, it is necessary to pmap_activate() again after pmap_deactivate_efirt() to restore the original TTBR0.

- Fix to do pmap_{de,}activate() before/after pmap_{,de}activate_efirt().
- moved kpreempt_{disable,enable}() to the caller since everything between
arm_efirt_md_enter() and arm_efirt_md_exit() should be kpreempt disabled.

ok skrll@


# 1.135 17-Apr-2022 skrll

Add the missing kpreempt_enable to pmap_deactivate_efirt


# 1.134 10-Apr-2022 skrll

No need to flush icache for EFI RT mappings as bootaa64.efi flushed
the full icache for us. (Also this avoids traps)


# 1.133 09-Apr-2022 riastradh

sys: Use membar_release/acquire around reference drop.

This just goes through my recent reference count membar audit and
changes membar_exit to membar_release and membar_enter to
membar_acquire -- this should make everything cheaper on most CPUs
without hurting correctness, because membar_acquire is generally
cheaper than membar_enter.


# 1.132 02-Apr-2022 skrll

Update to support EFI runtime outside the kernel virtual address space
by creating an EFI RT pmap that can be activated / deactivated when
required.

Adds support for EFI RT to ARM_MMU_EXTENDED (ASID) 32-bit Arm machines.

On Arm64 the usage of pmapboot_enter is reduced and the mappings are
created much later in the boot process -- now in cpu_startup_hook.
Backward compatiblity for KVA mapped RT from old bootaa64.efi is
maintained.

Adding support to other platforms should be easier as a result.


# 1.131 19-Mar-2022 skrll

Slight code re-organisation. NFCI.


# 1.130 12-Mar-2022 riastradh

sys: Membar audit around reference count releases.

If two threads are using an object that is freed when the reference
count goes to zero, we need to ensure that all memory operations
related to the object happen before freeing the object.

Using an atomic_dec_uint_nv(&refcnt) == 0 ensures that only one
thread takes responsibility for freeing, but it's not enough to
ensure that the other thread's memory operations happen before the
freeing.

Consider:

Thread A Thread B
obj->foo = 42; obj->baz = 73;
mumble(&obj->bar); grumble(&obj->quux);
/* membar_exit(); */ /* membar_exit(); */
atomic_dec -- not last atomic_dec -- last
/* membar_enter(); */
KASSERT(invariant(obj->foo,
obj->bar));
free_stuff(obj);

The memory barriers ensure that

obj->foo = 42;
mumble(&obj->bar);

in thread A happens before

KASSERT(invariant(obj->foo, obj->bar));
free_stuff(obj);

in thread B. Without them, this ordering is not guaranteed.

So in general it is necessary to do

membar_exit();
if (atomic_dec_uint_nv(&obj->refcnt) != 0)
return;
membar_enter();

to release a reference, for the `last one out hit the lights' style
of reference counting. (This is in contrast to the style where one
thread blocks new references and then waits under a lock for existing
ones to drain with a condvar -- no membar needed thanks to mutex(9).)

I searched for atomic_dec to find all these. Obviously we ought to
have a better abstraction for this because there's so much copypasta.
This is a stop-gap measure to fix actual bugs until we have that. It
would be nice if an abstraction could gracefully handle the different
styles of reference counting in use -- some years ago I drafted an
API for this, but making it cover everything got a little out of hand
(particularly with struct vnode::v_usecount) and I ended up setting
it aside to work on psref/localcount instead for better scalability.

I got bored of adding #ifdef __HAVE_ATOMIC_AS_MEMBAR everywhere, so I
only put it on things that look performance-critical on 5sec review.
We should really adopt membar_enter_preatomic/membar_exit_postatomic
or something (except they are applicable only to atomic r/m/w, not to
atomic_load/store_*, making the naming annoying) and get rid of all
the ifdefs.


# 1.129 05-Mar-2022 skrll

Slight comment improvement.


# 1.128 16-Feb-2022 andvar

fix various typos, mainly in comments.


# 1.127 31-Jan-2022 ryo

add support Hardware updates to Access flag and Dirty state (FEAT_HAFDBS)

- The DBM bit of the PTE is now used to determine if it is writable, and
the AF bit is treated entirely as a reference bit. A valid PTE is always
treated as readable. There can be no valid PTE that is not readable.
- LX_BLKPAG_OS_{READ,WRITE} are used only for debugging purposes,
and has been superseded by LX_BLKPAG_AF and LX_BLKPAG_DBM.
- Improve comment

The need for reference/modify emulation has been eliminated,
and access/permission faults have been reduced, however,
there has been little change in overall performance.


# 1.126 31-Jan-2022 ryo

Skip unnecessary PTE operations and TLB invalidation.


# 1.125 16-Jan-2022 rillig

aarch64/pmap: remove stray semicolon

No binary change.


# 1.124 15-Jan-2022 skrll

The translations that need invalidation are always last level so remove
the (dubious) logic around tracking the level. The "any level" TLB
invalidation maintenance operation are used, but this may change after
further testing.

before
======
1661.0u 420.2s 2:53.82 1197.3% 231+29k 10+33918io 102pf+0w
1646.8u 425.2s 2:52.96 1198.0% 232+29k 1+33937io 49pf+0w
1647.9u 425.7s 2:52.58 1201.6% 232+29k 0+33940io 32pf+0w

After
=====
1602.5u 420.8s 2:49.09 1196.6% 238+30k 24+33893io 54pf+0w
1600.7u 421.3s 2:51.53 1178.8% 238+30k 1+33914io 33pf+0w
1597.5u 424.3s 2:50.46 1186.1% 238+30k 0+33915io 17pf+0w

LGTM from ryo@


# 1.123 14-Jan-2022 skrll

Restore the previous pmap_remove_all behaviour as the new method meant
the n1sdp couldn't complete a build.

No noticeable change in kernel build performance.


# 1.122 04-Jan-2022 skrll

KNF


# 1.121 10-Dec-2021 andvar

s/occured/occurred/ in comments, log messages and man pages.


# 1.120 07-Dec-2021 andvar

fix various typos, mainly in comments.


# 1.119 23-Oct-2021 skrll

Fix non-UVMHIST build


# 1.118 16-Oct-2021 ryo

fix non-MULTIPROCESSOR build


# 1.117 10-Oct-2021 skrll

Use sys/uvm/pmap/pmap_tlb.c on Aarch64 in the same way that some Arm, MIPS,
and some PPC kernels do. This removes the limitation of 256 processes on
CPUs with 8bit ASID field, e.g. Apple M1.

Additionally the following changes have been made

- removed a couple of unnecessary aarch64_tlbi_all calls
- removed any invalidation after freeing page tables due to
_pmap_sweep_pdp. This was never necessary afaict.
- all kernel mappings are marked global and userland mapping not-global.

Performance testing hasn't show a significant difference. The data here
is from building a kernel on an lx2k system with nvme.

before
1489.6u 400.4s 2:40.65 1176.5% 228+224k 0+32289io 57pf+0w
1482.6u 403.2s 2:38.49 1189.9% 228+222k 0+32274io 46pf+0w
1485.4u 402.2s 2:37.27 1200.2% 228+222k 0+32275io 12pf+0w

after
1493.9u 404.6s 2:37.50 1205.4% 227+221k 0+32265io 48pf+0w
1485.0u 408.0s 2:38.54 1194.0% 227+222k 0+32272io 36pf+0w
1484.3u 407.0s 2:35.88 1213.3% 228+224k 0+32268io 14pf+0w

>>> stats.ttest_ind([160.65,158.49,157.27], [157.5,158.54,155.88])
Ttest_indResult(statistic=1.1923622711296888, pvalue=0.2990182944606766)
>>>


# 1.116 30-Sep-2021 skrll

Ensure TCR_EPD0 is set on entry to pmap_activate and ensure it is set as
early as possible for APs.


# 1.115 26-Sep-2021 skrll

Use UVMHIST_CALLARGS


# 1.114 26-Sep-2021 skrll

'\n' is not required in KASSERTMSG either.


# 1.113 26-Sep-2021 skrll

"\n" is not required in KERNHIST


# 1.112 15-Sep-2021 skrll

Use __SHIFTIN. Same code before and after.


# 1.111 12-Sep-2021 skrll

pmap_page_remove: simply and reduce the code size slightly.


# 1.110 09-Sep-2021 skrll

In pmap_icache_sync_range change

for (...) {
...
if (condition) {
// do stuff
}
}

to

for (...) {
...
if (!conditional)
continue;
// do stuff
}

to save on indentation. Same code (modulo register usage) before and
after.


# 1.109 09-Sep-2021 skrll

KNF


Revision tags: thorpej-i2c-spi-conf2-base thorpej-futex2-base thorpej-cfargs2-base cjep_sun2x-base1 cjep_sun2x-base cjep_staticlib_x-base1 thorpej-i2c-spi-conf-base
# 1.108 29-May-2021 skrll

Deal with the pmap limitation of maxproc in a more complete way and
recognise CPUs with only 8bit ASIDs.


Revision tags: cjep_staticlib_x-base
# 1.107 30-Apr-2021 skrll

branches: 1.107.2;
Make the ddb for pmap / pte information pmap agnostic


# 1.106 29-Apr-2021 skrll

Remove some unnecessary tlb invalidate in pmap_growkernel and ASAN shadow
map. Ensure the shadow map mappings are visible to the TLB walkers.


# 1.105 21-Apr-2021 ryo

branches: 1.105.2;
added more attributes of PTE displayed by "ddb>machine pte"


Revision tags: thorpej-cfargs-base
# 1.104 17-Apr-2021 mrg

remove KERNHIST_INIT_STATIC(). it stradles the line between usable
early in boot and broken early in boot by requiring a partly static
structure with another structure that must be present by the time
any uses are performed. theoretically platform code could allocate
a chunk while seting up memory and assign it here, giving a dynamic
sizing for the entry list, but the reality is that all users have
a statically allocated entry list as well.

the existing KERNHIST_LINK_STATIC() is used in conjunction with
KERNHIST_INITIALIZER() instead.

this stops a NULL pointer deref when the _LOG() macro is called
before the storage is linked in, which happens with GCC 10 on OCTEON
with UVMHIST enabled, crashing in very early kernel init.


Revision tags: thorpej-futex-base
# 1.103 09-Mar-2021 ryo

branches: 1.103.2;
fix build error without options DDB.

kvtopte() is referenced from arm/acpi/acpi_machdep.c


# 1.102 13-Feb-2021 ryo

No assignment is needed here.

the loop in pmap_page_remove() always removes the first pv,
and since the list is managed by _pmap_remove_pv(), pp->pp_pv.pv_next always points to the first.


# 1.101 01-Feb-2021 ryo

It is enough to make a page accessible instead of writable.
same fix as r1.76


# 1.100 31-Jan-2021 ryo

implement pmap_remove_all().

The size of struct pv_entry has increased, but speed of kernel build has improved by about 1%
exec and exit should have been improved.


# 1.99 20-Dec-2020 skrll

Improve the English in the previous comment fix.


# 1.98 19-Dec-2020 skrll

Tweak a comment


# 1.97 11-Dec-2020 skrll

s:aarch64/cpufunc.h:arm/cpufunc.h:

a baby step in the grand arm header unification challenge


# 1.96 10-Nov-2020 skrll

AA64 is not MIPS.

Change all KSEG references to directmap


# 1.95 07-Nov-2020 skrll

In pmap_devmap_bootstrap only set pmap_devmap_bootstrap_done if there
is an entry and ALL of the entries have been done. The entry required
for EARLYCONS might not be the first/only one...


# 1.94 01-Nov-2020 jmcneill

branches: 1.94.2;
No need to disable translation table walks in pmap_activate().


# 1.93 22-Oct-2020 skrll

Use the isb macro - missed in previous commit


# 1.92 22-Oct-2020 skrll

Use the dmb/dsb/isb macros... if nothing else they're all now consistent
about the "memory" assembler contraint.

No binary change


# 1.91 28-Sep-2020 skrll

Only set pmap_devmap_bootstrap_done if something gets mapped.

Think acpi_platform_devmap


# 1.90 19-Sep-2020 skrll

Make __md_palloc pmap agnostic (think sys/uvm/pmap)


# 1.89 14-Sep-2020 ryo

PID_MAX is just an initial value (soft maximum). Don't use it for CTASSERT.
defined __HAVE_CPU_MAXPROC to use function cpu_maxproc().

pointed out by mrg@, thanks.


# 1.88 06-Sep-2020 ryo

Fix panic caused by modload. http://mail-index.netbsd.org/port-arm/2020/08/30/msg006960.html

The address space reserved for modules may not be mapped in L1-L3.


# 1.87 14-Aug-2020 skrll

Whitespace


# 1.86 12-Aug-2020 skrll

Part IV of ad's performance improvements for aarch64

- Implement pmap_growkernel(), and update kernel pmap's stats with atomics.

- Then, pmap_kenter_pa() and pmap_kremove() no longer need to allocate
memory nor take pm_lock, because they only modify L3 PTEs.

- Then, pm_lock and pp_lock can be adaptive mutexes at IPL_NONE which are
cheaper than spin mutexes.

- Take the pmap's lock in pmap_extract() if not the kernel's pmap, otherwise
pmap_extract() might see inconsistent state.


# 1.85 09-Aug-2020 skrll

Fix another UVMHIST so it doesn't use %s


# 1.84 16-Jul-2020 skrll

pmapboot_enter simplication
- bootpage_alloc in asm becomes pmapboot_pagealloc in C
- PMAPBOOT_ENTER_NOBLOCK is removed as it's not used
- PMAPBOOT_ENTER_NOOVERWRITE is removed as it's now always on
- physpage_allocator argument is removed as it's always
pmapboot_pagealloc
- Support for EARLYCONS without CONSADDR is removed so that the identity
map for CONSADDR is always known.

For the assembly files:
2 files changed, 40 insertions(+), 89 deletions(-)

LGTM ryo


# 1.83 04-Jul-2020 rin

Use tlen for temporary length variable instead of l, which is usually
used for struct lwp *.

No binary changes.


# 1.82 02-Jul-2020 rin

pmap_procwr(): sync icache even if p != curproc. This fixes applications
like GDB for arm32, that rewrite text of other process.

Thanks to ryo@ for discussion.


# 1.81 02-Jul-2020 rin

Set uvmexp.ncolors appropriately, which is required for some CPU
models with VIPT icache.

Otherwise, alias in virtual address results in inconsistent results,
at least for applications that rewrite text of other process, e.g.,
GDB for arm32.

Also, this hopefully fixes other unexpected failures due to alias.

Confirmed that there's no observable regression in performance;
difference in ``time make -j8'' for GENERIC64 kernel on BCM2837
with and without setting uvmexp.ncolors is within 0.1%.

Thanks to ryo@ for discussion.


# 1.80 27-Jun-2020 rin

Fix typo in name of evcnt(4) counter.


# 1.79 24-Jun-2020 ryo

Fix bug with incorrect range calculation when doing icache sync.
This is called by sysarch(ARM_SYNC_ICACHE) from aarch32 (compat_netbsd32) emul process.

pointed out by rin@, thanks.

XXX pullup-9


# 1.78 14-Jun-2020 ad

- Fix a lock order reversal in pmap_page_protect().

- Make sure pmap is always locked when updating stats; atomics no longer
needed to do that.

- Remove unneeded traversal of pv list in pmap_enter_pv().

- Shrink struct vm_page from 136 to 128 bytes (cache line sized) and struct
pv_entry from 48 to 32 bytes (power of 2 sized).

- Embed a pv_entry in each vm_page. This means PV entries don't need to
be allocated for private anonymous memory / COW pages / most UBC mappings.
Dynamic PV entries are then used only for stuff like shared libraries and
shared memory.

Proposed on port-arm@.


# 1.77 10-Jun-2020 ad

- Wired/resident stats shouldn't covered by PMAPCOUNTERS.
- Rename need_update_pv -> need_enter_pv.

Ok ryo@


# 1.76 01-Jun-2020 ryo

no need to make the PTE writable to do icache_sync, enough to accessible.


# 1.75 15-May-2020 skrll

Use __diagused


# 1.74 15-May-2020 tnn

fix non-diag build


# 1.73 14-May-2020 skrll

Use MUTEX_NODEBUG for PV locks as is commonly done. OK ryo.


# 1.72 13-May-2020 jmcneill

Implement pmap_extract_coherency


Revision tags: bouyer-xenpvh-base2 phil-wifi-20200421 bouyer-xenpvh-base1
# 1.71 18-Apr-2020 skrll

PMAP_DEBUG has been deleted on arm


# 1.70 13-Apr-2020 maxv

Add support for Branch Target Identification (BTI).

On the executable pages that have the GP (Guarded Page) bit, the semantic
of the "br" and "blr" instructions is changed: the CPU expects the first
instruction of the jump/call target to be "bti", and faults if it isn't.

We add the GP bit on the kernel .text pages (and incidentally the .rodata
pages, but we don't care). The compiler adds a "bti c" instruction at the
beginning of each C function. We modify the ENTRY() macros to manually add
"bti c" in the asm functions.

cpuswitch.S needs a specific change: with "br x27" the CPU expects "bti j",
which is bad because the functions begin with "bti c"; switch to "br x16",
for the CPU to accept "bti c".

BTI helps defend against JOP/COP. Tested on Qemu.


Revision tags: phil-wifi-20200411 bouyer-xenpvh-base
# 1.69 08-Apr-2020 ryo

branches: 1.69.2;
use PMAP_PAGE_INIT() to initialize mutex in pmap_page.

VM_MDPAGE_INIT() in pmap_free_pdp() had initialized pp_flags,
so it unintentionally cleared PMAP_PAGE_FLAGS_PV_TRACKED.
use PMAP_PAGE_INIT to avoid using PMAP_PAGE_FLAGS_PV_TRACKED.

pointed out by tnn@, thanks


Revision tags: phil-wifi-20200406
# 1.68 14-Mar-2020 ad

pmap_remove_all(): Return a boolean value to indicate the behaviour. If
true, all mappings have been removed, the pmap is totally cleared out, and
UVM can then avoid doing the work to call pmap_remove() for each map entry.
If false, either nothing has been done, or some helpful arch-specific voodoo
has taken place.


Revision tags: is-mlppp-base
# 1.67 02-Mar-2020 ryo

oops, fix incorrect usage of daif_enable() in my previous commit.


# 1.66 29-Feb-2020 ryo

Fix pmap to work correctly with tagged addresses

- when fault, untag from address before passing to uvm/pmap functions
- pmap_extract() checks more strictly and consider the address tag


# 1.65 29-Feb-2020 ryo

use pmapboot_enter_range()


Revision tags: ad-namecache-base3
# 1.64 10-Feb-2020 ryo

use LIST(3) instead of TAILQ(3) to save one word in struct vm_page and struct pmap.

pointed out by riastradh@. thanks


# 1.63 03-Feb-2020 ryo

add support pmap_pv(9)

Patch originally from jmcneill@. thanks


# 1.62 03-Feb-2020 ryo

separate struct vm_page_md into vm_page_md and pmap_page
for preparation pmap_pv(9)


Revision tags: ad-namecache-base2 ad-namecache-base1
# 1.61 09-Jan-2020 ryo

fix behaviour mmap()/mprotect() when passed only PROT_EXEC.

when mmap()/mprotect() with only PROT_EXEC, syscall will be successful,
but the page actually hadn't been mapped.
it should be mapped with PROT_READ|PROT_EXEC implicitly. (r-x)


Revision tags: ad-namecache-base
# 1.60 30-Dec-2019 skrll

branches: 1.60.2;
Update pmap_map_chunk to allow L[12] block mappings and L3 page mappings


# 1.59 30-Dec-2019 skrll

Remove unnecessary brackets and unwrap a conditional. Same code before
and after.


# 1.58 28-Dec-2019 jmcneill

Do not use Early Write Acknowledge for PCIe I/O and config space.


# 1.57 27-Dec-2019 jmcneill

Enable early write acknowledge for device memory mappings.


# 1.56 19-Dec-2019 skrll

G/C kasan_shadow_map call in pmap_enter

pmap_growkernel calls kasan_shadow_map for KVA


# 1.55 18-Dec-2019 ryo

atomic_add_16() is not used in pmap.c anymore. no need decl here.


# 1.54 18-Dec-2019 ryo

space to tab


# 1.53 14-Dec-2019 skrll

Fix build... wire_count probably doesn't need atomics


# 1.52 13-Dec-2019 skrll

Fix KASAN support by calling kasan_shadow_map in pmap_growkernel


# 1.51 10-Dec-2019 ad

pg->phys_addr -> VM_PAGE_TO_PHYS(pg)


Revision tags: phil-wifi-20191119
# 1.50 14-Nov-2019 maxv

Mark several kASan functions with __nothing, to avoid annoying #ifdefs.
Same as kCSan and kMSan.


# 1.49 14-Nov-2019 maxv

Don't include "opt_kasan.h" when there's already <sys/asan.h> included.


# 1.48 29-Oct-2019 maya

Define PMAP_NEED_PROCWR, providing strategically placed i-cache
synchronization where just-changed memory is about to be executed.

Fixes SIGILLs seen when running Mono 6 on QEMU Cortex-A57.

ok ryo


# 1.47 22-Sep-2019 jmcneill

Disable translation table walks using TTBR0 while changing its value and
when deactivating a pmap. Fixes stability issues on Ampere eMAG CPUs.


# 1.46 20-Sep-2019 ryo

ref/mod bit should be set according to 'flags' argument, not 'prot'. r1.44 was incomplete.


# 1.45 13-Sep-2019 ryo

In pmap_devmap_bootstrap(), cpu_earlydevice_va_p() must not return true until *all* devmap tables have been enabled.
console mapping may be present in the last table.


# 1.44 07-Sep-2019 ryo

- remove incorrect KASSERT. mmap(2) with prot=PROT_WRITE calls pmap_enter(..., PROT_WRITE) internally.
- fix to update page reference flags when only PROT_WRITE or PROT_EXECUTE specified


# 1.43 15-Aug-2019 skrll

Make pmap_db_pte_print more terse so it's quicker on serial consoles


# 1.42 12-Aug-2019 skrll

Use PMAP_DEV in DEVMAP_ENTRY rather than pmap_map_chunk. It's clearer and
means pmap_map_chunk can be made to map other memory types.


Revision tags: netbsd-9-base phil-wifi-20190609
# 1.41 17-May-2019 mrg

branches: 1.41.2;
apply some __diagused.


Revision tags: isaki-audio2-base
# 1.40 08-Apr-2019 ryo

- free empty page tables pages if reach a certain usage.
- need to lock at removing an old pg (_pmap_remove_pv) in _pmap_enter()


# 1.39 06-Apr-2019 ryo

Fix race conditions about pmap_page_protect() and pmap_enter().

while handling same PTE by these functions in same time, there
is a critical path that the number of valid PTEs and wire_count
are inconsistent, and it caused KASSERT.
Need to hold a pv_lock while modifying them.


# 1.38 20-Mar-2019 ryo

spinkle __printflike(), and use PRIxxx


# 1.37 19-Mar-2019 ryo

- add ddb command "machine ttbr" to dump MMU tables.
- tidy up descriptions, usages and messages.


# 1.36 19-Mar-2019 ryo

- free L1-L3 pages that has been emptied by pmap_remove().
- if no memories, pmap_enter will return correctly ENOMEM if PMAP_CANFAIL, or wait until available any memories if !PMAP_CANFAIL.

These changes improves the stability when we use a huge virtual memory spaces with mmap.


# 1.35 06-Feb-2019 ryo

improve pmap_remove
- don't lock/unlock per page in pmap_remove()
- speedup pte lookup for continuous addresses
- bring out pool_cache_put(&_pmap_pv_pool, pv) from lock/unlock section


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226
# 1.34 21-Dec-2018 ryo

- add workaround for Cavium ThunderX errata 27456.
- add cpufuncs table in cpu_info. each cpu clusters may have different erratum. (e.g. big.LITTLE)


Revision tags: pgoyette-compat-1126
# 1.33 01-Nov-2018 maxv

Add kASan support for aarch64. Stack tracking needs more investigation
and will come in a separate commit.

Reviewed by ryo@ jmcneill@ skrll@.


# 1.32 31-Oct-2018 ryo

invalidate icache correctly.
l3pte_executable() should be used for only valid pte.


Revision tags: pgoyette-compat-1020
# 1.31 18-Oct-2018 skrll

Provide generic start code that assumes the MMU is off and caches are
disabled as per the linux booting protocol for ARMv6 and ARMv7 boards.
u-boot image type should be changed to 'linux' for correct behaviour.

The new start code builds a minimal "bootstrap" L1PT with cached access
disabled and uses the same table for all processors. AP startup is
performed in less steps and more code is written in C.

The bootstrap tables and stack are placed into an (orphaned) section
"_init_memory" which is given to uvm when it is no longer used.

Various kernels have been converted to use this code and tested. Some
boards were provided by TNF. Thanks!

The GENERIC kernel now boots on boards using the TEGRA, SUNXI and EXYNOS
kernels. The GENERIC kernel will also work on RPI2 using u-boot.

Thanks to martin@ and aymeric@ for testing on parallella and nanosoc
respectively


# 1.30 14-Oct-2018 skrll

Use __nothing


# 1.29 12-Oct-2018 ryo

add initial support of COMPAT_NETBSD32 on AArch64.
arm ELF32 EABI binaries could be execute in AArch32 state on AArch64. A32 THUMB mode is not supported yet.


# 1.28 12-Oct-2018 ryo

- cleanup checking address ranges with IN_RANGE macro
- change PM_ADDR_CHECK macro to KASSERTMSG
- restore fast lookup cases with IN_RANGE macro for pmap_extract changed in my previous commit.


# 1.27 12-Oct-2018 ryo

rewrite pmap_pte_lookup() to share similar code.


# 1.26 04-Oct-2018 ryo

cleanup locore, and changed the way to map memories during boot.
- add functions bootpage_enter() and bootpage_alloc() to adapt various layout
of physical memory map. especially for 64bit physical memory layout.
pmapboot_alloc() allocates pagetable pages from _end[].
- changed to map only the required amount for PA=VA identity mapping
(kernel image, UART device, and FDT blob) with L2_BLOCK(2Mbyte).
- changing page permission for kernel image, and making KSEG mapping are done
at cpu_kernel_vm_init() instead of at locore.
- optimize PTE entries with PTE Contiguous bit. it is enabled on devmap only for now.

reviewed by skrll@, thanks.


# 1.25 04-Oct-2018 ryo

* define LX_BLKPAG_{OS,ATTR}_* for OS dependent PTE attributes in pmap.h
* cleanup macros


Revision tags: pgoyette-compat-0930
# 1.24 17-Sep-2018 ryo

delete debug printf and KASSERT.


# 1.23 10-Sep-2018 maxv

Replace KDASSERT by panic.


# 1.22 10-Sep-2018 maxv

Rename _pmap_alloc_pdp -> pmap_alloc_pdp, and make it public.


# 1.21 10-Sep-2018 ryo

cleanup aarch64 mpstart and fdt bootstrap
* arm_cpu_hatch_arg is a bad idea. avoid serializing CPU startup, and eliminate arm_cpu_hatch_arg.
in mpstart, resolve own cpu index using array of cpu_mpidr[] (aarch64)
* add support fdt enable-method "spin-table"
* add support fdt enable-method "brcm,bcm2836-smp" (for 32bit RaspberryPi)
* use arm_fdt_cpu_bootstrap() instead of psci_fdt_bootstrap()
* rename "arm/fdt/psci_fdt.h" to "arm/fdt/psci_fdtvar.h" because of conflict of include file for needs-flag
* add devmap for cpu spin-table of raspberrypi3/aarch64
* no need to force hatch APs for raspberrypi3/arm32 ifndef MULTIPROCESSOR.
* fix to work pmap_extract(kerneltext/data/bss) even if before calling pmap_bootstrap

idea to use cpu_mpidr[] by jmcneill@. reviewd by skrll@. thanks.


Revision tags: pgoyette-compat-0906
# 1.20 27-Aug-2018 ryo

need to add VM_PROT_READ when pmap_kenter_pa(va, pa, VM_PROT_WRITE, 0) or pmap_kenter_pa(va, pa, VM_PROT_EXECUTE, 0).
VM_PROT_READ is treated as an access permission inernally.


# 1.19 11-Aug-2018 ryo

change to minimum invalidation of TLB.
specifying not only va but also asid, and not invalidate L0-L2 entry using tlbi_*_ll() if needed.


# 1.18 10-Aug-2018 ryo

treat kernel-exec attr and user-exec attr separately.
kernel cannot execute userland exec page, and user cannot execute kernel page.


# 1.17 06-Aug-2018 ryo

set kernel text/rodata readonly by default.
add function db_write_text() for setting ddb breakpoint.


# 1.16 31-Jul-2018 skrll

Define and use VPRINTF


Revision tags: pgoyette-compat-0728
# 1.15 27-Jul-2018 ryo

changes of pmap.c r1.13 seems to be unstable.
In order to invalidate icache, not to invalidate all icache,
but temporary to make the page writable and invalidate target address only.


# 1.14 24-Jul-2018 ryo

don't call pool_cache_put with locking pmap. pool_cache_put call pmap_kenter_pa internally.
(pool_cache_put_paddr -> pool_cache_put_slow -> pool_get -> pmap_kenter_pa)


# 1.13 23-Jul-2018 ryo

* fix icache invalidations.
* "ic ivau" (aarch64_icache_sync_range) with VA generates permission fault in some situations, therefore use KSEG address for now.


# 1.12 23-Jul-2018 ryo

rather than using flags to resolve nested locks, reserve pool_cache before locking.


# 1.11 21-Jul-2018 ryo

* avoid deadlock. mutex_owned() works only for adaptive lock, therefore we cannot use it for spinlock...
* add more NULL check
* clear pte when pmap_enter() fails


# 1.10 17-Jul-2018 ryo

Use __debugused


# 1.9 17-Jul-2018 christos

Add missing casts, remove unused variables.


# 1.8 09-Jul-2018 ryo

need locks in pmap_kremove() and pmap_fault_fixup()


Revision tags: phil-wifi-base pgoyette-compat-0625 pgoyette-compat-0521
# 1.7 20-May-2018 ryo

branches: 1.7.2;
pmap_enter() must update modified/referenced flags by 'flags' not 'prot'.


# 1.6 16-May-2018 ryo

Fix memory leak. it was leaking one page every pmap_create().
pm->pm_vmlist must be initialized before calling _pmap_alloc_pdp().


Revision tags: pgoyette-compat-0502
# 1.5 29-Apr-2018 ryo

fix KASSERT panic. pv_entry may not be exists in pvlist when pmap_remove().


# 1.4 29-Apr-2018 ryo

delete unused code


# 1.3 27-Apr-2018 ryo

fix instability behavior of bufcache on aarch64.
* fix to return correct ref/mod when PMAP_WIRED.
* changed to keep wired flags in pte instead of pv_entry, and cleanup.


Revision tags: pgoyette-compat-0422 pgoyette-compat-0415 pgoyette-compat-0407
# 1.2 01-Apr-2018 ryo

Add initial support for ARMv8 (AARCH64) (by nisimura@ and ryo@)

- sys/arch/evbarm64 is gone and integrated into sys/arch/evbarm. (by skrll@)
- add support fdt. evbarm/conf/GENERIC64 fdt (bcm2837,sunxi,tegra) based generic 64bit kernel config. (by skrll@, jmcneill@)


Revision tags: netbsd-8-2-RELEASE netbsd-8-1-RELEASE netbsd-8-1-RC1 netbsd-7-2-RELEASE netbsd-8-0-RELEASE netbsd-8-0-RC2 netbsd-8-0-RC1 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 netbsd-7-1-2-RELEASE pgoyette-compat-base netbsd-7-1-1-RELEASE tls-maxphys-base-20171202 matt-nb8-mediatek-base nick-nhusb-base-20170825 perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base pgoyette-localcount-20170320 netbsd-7-1-RELEASE netbsd-7-1-RC2 nick-nhusb-base-20170204 netbsd-7-nhusb-base-20170116 bouyer-socketcan-base pgoyette-localcount-20170107 netbsd-7-1-RC1 nick-nhusb-base-20161204 pgoyette-localcount-20161104 netbsd-7-0-2-RELEASE nick-nhusb-base-20161004 localcount-20160914 netbsd-7-nhusb-base pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907 nick-nhusb-base-20160529 netbsd-7-0-1-RELEASE nick-nhusb-base-20160422 nick-nhusb-base-20160319 nick-nhusb-base-20151226 netbsd-7-0-RELEASE nick-nhusb-base-20150921 netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 nick-nhusb-base-20150606 nick-nhusb-base-20150406 nick-nhusb-base tls-maxphys-base netbsd-7-base
# 1.1 10-Aug-2014 matt

branches: 1.1.4; 1.1.28;
Preliminary files for AARCH64 (64-bit ARM) support.
Enough for a distribution build.


# 1.150 07-Feb-2024 msaitoh

Remove ryo@'s mail addresses.


Revision tags: thorpej-ifq-base thorpej-altq-separation-base
# 1.149 20-Apr-2023 skrll

Provide a shared pmap_devmap implementation and convert all pmap_devmap
arrays to use DEVMAP_ENTRY{,_END}


# 1.148 16-Apr-2023 skrll

Rename VM_KERNEL_IO_ADDRESS to VM_KERNEL_IO_BASE to match RISC-V

It's less letters, matches other similar variables and will help with
sharing code between the two architectures.

NFCI.


Revision tags: netbsd-10-0-RC4 netbsd-10-0-RC3 netbsd-10-0-RC2 netbsd-10-0-RC1 netbsd-10-base
# 1.147 30-Oct-2022 riastradh

aarch64/pmap: Fix criterion in previous.

Use the pte bit that says whether this is a PMAP_WIRED page, not the
bit that says whether this is a non-global page.

(Forgot to git commit --amend before exporting to CVS, sorry!)


# 1.146 30-Oct-2022 riastradh

aarch64/pmap(9): Teach pmap_protect about pmap_kenter_pa mappings.

Pages mapped with pmap_kenter_pa are necessarily unmanaged, so there
are no P->V records, and pmap_kenter_pa leaves pp->pp_pv.pv_va zero
with no modified/referenced state.

However, pmap_protect erroneously examined pp->pp_pv.pv_va to
ascertain the modified/referenced state -- and if the page was not
marked referenced, pmap_protect would clear the LX_BLKPAG_AF bit
(Access Flag), with the effect that subsequent uses of the page fault
and require a detour through pmap_fault_fixup.

This caused problems for the kernel module loader:

- When loading the text section, kobj_load first allocates kva with
uvm_km_alloc(UVM_KMF_WIRED|UVM_KMF_EXEC), which creates ptes with
pmap_kenter_pa. These ptes are writable, so we can copy the text
section into them, and have LX_BLKPAG_AF set so there will be no
fault when they are used by the kernel.

- But then kobj_affix makes the text section read/execute-only (and
nonwritable) with uvm_km_protect(VM_PROT_READ|VM_PROT_EXECUTE),
which updates the ptes with pmap_protect. This _should_ leave
LX_BLKPAG_AF set, but by inadvertently treating the page as managed
when it should be unmanaged, pmap_protect cleared it instead.

- Most of the time, clearing LX_BLKPAG_AF caused no problem, because
pmap_fault_fixup would silently resolve it. But if a hard
interrupt handler tried to use any page in the module's text (or
rodata, I suspect) that was not yet fixed up, the CPU would fault
and enter pmap_fault_fixup -- which would promptly crash (or hang)
by trying to take the pmap lock in interrupt context, which is
forbidden.

I observed this by loading dtrace.kmod early at boot and trying to
dtrace hard interrupt handlers.

With this change, pmap_protect now recognizes wired mappings (as
created by pmap_kenter_pa) before consulting pp->pp_pv.pv_va, and
preserves then LX_BLKPAG_AF bit in that case.

ok skrll


# 1.145 29-Oct-2022 skrll

fix a spello in a comment


# 1.144 28-Oct-2022 skrll

Remove some empty lines


# 1.143 23-Oct-2022 skrll

Use UVMHIST_CALLARGS in pmap_bootstrap


# 1.142 23-Oct-2022 skrll

Only define the EFI variable if EFI_RUNTIME


# 1.141 20-Oct-2022 skrll

KNF


# 1.140 15-Oct-2022 jmcneill

Use "non-posted" instead of "strongly ordered" to describe nGnRnE mappings

Rename the following defines:
- _ARM_BUS_SPACE_MAP_STRONGLY_ORDERED to BUS_SPACE_MAP_NONPOSTED
- PMAP_DEV_SO to PMAP_DEV_NP
- LX_BLKPAG_ATTR_DEVICE_MEM_SO to LX_BLKPAG_ATTR_DEVICE_MEM_NP
Rename the following option:
- AARCH64_DEVICE_MEM_STRONGLY_ORDERED to AARCH64_DEVICE_MEM_NONPOSTED


Revision tags: bouyer-sunxi-drm-base
# 1.139 19-Aug-2022 ryo

Fixed a bug that pte's __BIT(63,48) could be set when accessing addresses above 0x0001000000000000 in /dev/mem with mmap().


# 1.138 19-Aug-2022 ryo

When accessed in mmap by the device pager, pmap_enter() may be called with prot == PROT_WRITE.


# 1.137 03-May-2022 skrll

Sprinkle some KASSERT(kpreempt_disabled());


# 1.136 27-Apr-2022 ryo

since pmap_activate_efirt() rewrites TTBR0, it is necessary to pmap_activate() again after pmap_deactivate_efirt() to restore the original TTBR0.

- Fix to do pmap_{de,}activate() before/after pmap_{,de}activate_efirt().
- moved kpreempt_{disable,enable}() to the caller since everything between
arm_efirt_md_enter() and arm_efirt_md_exit() should be kpreempt disabled.

ok skrll@


# 1.135 17-Apr-2022 skrll

Add the missing kpreempt_enable to pmap_deactivate_efirt


# 1.134 10-Apr-2022 skrll

No need to flush icache for EFI RT mappings as bootaa64.efi flushed
the full icache for us. (Also this avoids traps)


# 1.133 09-Apr-2022 riastradh

sys: Use membar_release/acquire around reference drop.

This just goes through my recent reference count membar audit and
changes membar_exit to membar_release and membar_enter to
membar_acquire -- this should make everything cheaper on most CPUs
without hurting correctness, because membar_acquire is generally
cheaper than membar_enter.


# 1.132 02-Apr-2022 skrll

Update to support EFI runtime outside the kernel virtual address space
by creating an EFI RT pmap that can be activated / deactivated when
required.

Adds support for EFI RT to ARM_MMU_EXTENDED (ASID) 32-bit Arm machines.

On Arm64 the usage of pmapboot_enter is reduced and the mappings are
created much later in the boot process -- now in cpu_startup_hook.
Backward compatiblity for KVA mapped RT from old bootaa64.efi is
maintained.

Adding support to other platforms should be easier as a result.


# 1.131 19-Mar-2022 skrll

Slight code re-organisation. NFCI.


# 1.130 12-Mar-2022 riastradh

sys: Membar audit around reference count releases.

If two threads are using an object that is freed when the reference
count goes to zero, we need to ensure that all memory operations
related to the object happen before freeing the object.

Using an atomic_dec_uint_nv(&refcnt) == 0 ensures that only one
thread takes responsibility for freeing, but it's not enough to
ensure that the other thread's memory operations happen before the
freeing.

Consider:

Thread A Thread B
obj->foo = 42; obj->baz = 73;
mumble(&obj->bar); grumble(&obj->quux);
/* membar_exit(); */ /* membar_exit(); */
atomic_dec -- not last atomic_dec -- last
/* membar_enter(); */
KASSERT(invariant(obj->foo,
obj->bar));
free_stuff(obj);

The memory barriers ensure that

obj->foo = 42;
mumble(&obj->bar);

in thread A happens before

KASSERT(invariant(obj->foo, obj->bar));
free_stuff(obj);

in thread B. Without them, this ordering is not guaranteed.

So in general it is necessary to do

membar_exit();
if (atomic_dec_uint_nv(&obj->refcnt) != 0)
return;
membar_enter();

to release a reference, for the `last one out hit the lights' style
of reference counting. (This is in contrast to the style where one
thread blocks new references and then waits under a lock for existing
ones to drain with a condvar -- no membar needed thanks to mutex(9).)

I searched for atomic_dec to find all these. Obviously we ought to
have a better abstraction for this because there's so much copypasta.
This is a stop-gap measure to fix actual bugs until we have that. It
would be nice if an abstraction could gracefully handle the different
styles of reference counting in use -- some years ago I drafted an
API for this, but making it cover everything got a little out of hand
(particularly with struct vnode::v_usecount) and I ended up setting
it aside to work on psref/localcount instead for better scalability.

I got bored of adding #ifdef __HAVE_ATOMIC_AS_MEMBAR everywhere, so I
only put it on things that look performance-critical on 5sec review.
We should really adopt membar_enter_preatomic/membar_exit_postatomic
or something (except they are applicable only to atomic r/m/w, not to
atomic_load/store_*, making the naming annoying) and get rid of all
the ifdefs.


# 1.129 05-Mar-2022 skrll

Slight comment improvement.


# 1.128 16-Feb-2022 andvar

fix various typos, mainly in comments.


# 1.127 31-Jan-2022 ryo

add support Hardware updates to Access flag and Dirty state (FEAT_HAFDBS)

- The DBM bit of the PTE is now used to determine if it is writable, and
the AF bit is treated entirely as a reference bit. A valid PTE is always
treated as readable. There can be no valid PTE that is not readable.
- LX_BLKPAG_OS_{READ,WRITE} are used only for debugging purposes,
and has been superseded by LX_BLKPAG_AF and LX_BLKPAG_DBM.
- Improve comment

The need for reference/modify emulation has been eliminated,
and access/permission faults have been reduced, however,
there has been little change in overall performance.


# 1.126 31-Jan-2022 ryo

Skip unnecessary PTE operations and TLB invalidation.


# 1.125 16-Jan-2022 rillig

aarch64/pmap: remove stray semicolon

No binary change.


# 1.124 15-Jan-2022 skrll

The translations that need invalidation are always last level so remove
the (dubious) logic around tracking the level. The "any level" TLB
invalidation maintenance operation are used, but this may change after
further testing.

before
======
1661.0u 420.2s 2:53.82 1197.3% 231+29k 10+33918io 102pf+0w
1646.8u 425.2s 2:52.96 1198.0% 232+29k 1+33937io 49pf+0w
1647.9u 425.7s 2:52.58 1201.6% 232+29k 0+33940io 32pf+0w

After
=====
1602.5u 420.8s 2:49.09 1196.6% 238+30k 24+33893io 54pf+0w
1600.7u 421.3s 2:51.53 1178.8% 238+30k 1+33914io 33pf+0w
1597.5u 424.3s 2:50.46 1186.1% 238+30k 0+33915io 17pf+0w

LGTM from ryo@


# 1.123 14-Jan-2022 skrll

Restore the previous pmap_remove_all behaviour as the new method meant
the n1sdp couldn't complete a build.

No noticeable change in kernel build performance.


# 1.122 04-Jan-2022 skrll

KNF


# 1.121 10-Dec-2021 andvar

s/occured/occurred/ in comments, log messages and man pages.


# 1.120 07-Dec-2021 andvar

fix various typos, mainly in comments.


# 1.119 23-Oct-2021 skrll

Fix non-UVMHIST build


# 1.118 16-Oct-2021 ryo

fix non-MULTIPROCESSOR build


# 1.117 10-Oct-2021 skrll

Use sys/uvm/pmap/pmap_tlb.c on Aarch64 in the same way that some Arm, MIPS,
and some PPC kernels do. This removes the limitation of 256 processes on
CPUs with 8bit ASID field, e.g. Apple M1.

Additionally the following changes have been made

- removed a couple of unnecessary aarch64_tlbi_all calls
- removed any invalidation after freeing page tables due to
_pmap_sweep_pdp. This was never necessary afaict.
- all kernel mappings are marked global and userland mapping not-global.

Performance testing hasn't show a significant difference. The data here
is from building a kernel on an lx2k system with nvme.

before
1489.6u 400.4s 2:40.65 1176.5% 228+224k 0+32289io 57pf+0w
1482.6u 403.2s 2:38.49 1189.9% 228+222k 0+32274io 46pf+0w
1485.4u 402.2s 2:37.27 1200.2% 228+222k 0+32275io 12pf+0w

after
1493.9u 404.6s 2:37.50 1205.4% 227+221k 0+32265io 48pf+0w
1485.0u 408.0s 2:38.54 1194.0% 227+222k 0+32272io 36pf+0w
1484.3u 407.0s 2:35.88 1213.3% 228+224k 0+32268io 14pf+0w

>>> stats.ttest_ind([160.65,158.49,157.27], [157.5,158.54,155.88])
Ttest_indResult(statistic=1.1923622711296888, pvalue=0.2990182944606766)
>>>


# 1.116 30-Sep-2021 skrll

Ensure TCR_EPD0 is set on entry to pmap_activate and ensure it is set as
early as possible for APs.


# 1.115 26-Sep-2021 skrll

Use UVMHIST_CALLARGS


# 1.114 26-Sep-2021 skrll

'\n' is not required in KASSERTMSG either.


# 1.113 26-Sep-2021 skrll

"\n" is not required in KERNHIST


# 1.112 15-Sep-2021 skrll

Use __SHIFTIN. Same code before and after.


# 1.111 12-Sep-2021 skrll

pmap_page_remove: simply and reduce the code size slightly.


# 1.110 09-Sep-2021 skrll

In pmap_icache_sync_range change

for (...) {
...
if (condition) {
// do stuff
}
}

to

for (...) {
...
if (!conditional)
continue;
// do stuff
}

to save on indentation. Same code (modulo register usage) before and
after.


# 1.109 09-Sep-2021 skrll

KNF


Revision tags: thorpej-i2c-spi-conf2-base thorpej-futex2-base thorpej-cfargs2-base cjep_sun2x-base1 cjep_sun2x-base cjep_staticlib_x-base1 thorpej-i2c-spi-conf-base
# 1.108 29-May-2021 skrll

Deal with the pmap limitation of maxproc in a more complete way and
recognise CPUs with only 8bit ASIDs.


Revision tags: cjep_staticlib_x-base
# 1.107 30-Apr-2021 skrll

branches: 1.107.2;
Make the ddb for pmap / pte information pmap agnostic


# 1.106 29-Apr-2021 skrll

Remove some unnecessary tlb invalidate in pmap_growkernel and ASAN shadow
map. Ensure the shadow map mappings are visible to the TLB walkers.


# 1.105 21-Apr-2021 ryo

branches: 1.105.2;
added more attributes of PTE displayed by "ddb>machine pte"


Revision tags: thorpej-cfargs-base
# 1.104 17-Apr-2021 mrg

remove KERNHIST_INIT_STATIC(). it stradles the line between usable
early in boot and broken early in boot by requiring a partly static
structure with another structure that must be present by the time
any uses are performed. theoretically platform code could allocate
a chunk while seting up memory and assign it here, giving a dynamic
sizing for the entry list, but the reality is that all users have
a statically allocated entry list as well.

the existing KERNHIST_LINK_STATIC() is used in conjunction with
KERNHIST_INITIALIZER() instead.

this stops a NULL pointer deref when the _LOG() macro is called
before the storage is linked in, which happens with GCC 10 on OCTEON
with UVMHIST enabled, crashing in very early kernel init.


Revision tags: thorpej-futex-base
# 1.103 09-Mar-2021 ryo

branches: 1.103.2;
fix build error without options DDB.

kvtopte() is referenced from arm/acpi/acpi_machdep.c


# 1.102 13-Feb-2021 ryo

No assignment is needed here.

the loop in pmap_page_remove() always removes the first pv,
and since the list is managed by _pmap_remove_pv(), pp->pp_pv.pv_next always points to the first.


# 1.101 01-Feb-2021 ryo

It is enough to make a page accessible instead of writable.
same fix as r1.76


# 1.100 31-Jan-2021 ryo

implement pmap_remove_all().

The size of struct pv_entry has increased, but speed of kernel build has improved by about 1%
exec and exit should have been improved.


# 1.99 20-Dec-2020 skrll

Improve the English in the previous comment fix.


# 1.98 19-Dec-2020 skrll

Tweak a comment


# 1.97 11-Dec-2020 skrll

s:aarch64/cpufunc.h:arm/cpufunc.h:

a baby step in the grand arm header unification challenge


# 1.96 10-Nov-2020 skrll

AA64 is not MIPS.

Change all KSEG references to directmap


# 1.95 07-Nov-2020 skrll

In pmap_devmap_bootstrap only set pmap_devmap_bootstrap_done if there
is an entry and ALL of the entries have been done. The entry required
for EARLYCONS might not be the first/only one...


# 1.94 01-Nov-2020 jmcneill

branches: 1.94.2;
No need to disable translation table walks in pmap_activate().


# 1.93 22-Oct-2020 skrll

Use the isb macro - missed in previous commit


# 1.92 22-Oct-2020 skrll

Use the dmb/dsb/isb macros... if nothing else they're all now consistent
about the "memory" assembler contraint.

No binary change


# 1.91 28-Sep-2020 skrll

Only set pmap_devmap_bootstrap_done if something gets mapped.

Think acpi_platform_devmap


# 1.90 19-Sep-2020 skrll

Make __md_palloc pmap agnostic (think sys/uvm/pmap)


# 1.89 14-Sep-2020 ryo

PID_MAX is just an initial value (soft maximum). Don't use it for CTASSERT.
defined __HAVE_CPU_MAXPROC to use function cpu_maxproc().

pointed out by mrg@, thanks.


# 1.88 06-Sep-2020 ryo

Fix panic caused by modload. http://mail-index.netbsd.org/port-arm/2020/08/30/msg006960.html

The address space reserved for modules may not be mapped in L1-L3.


# 1.87 14-Aug-2020 skrll

Whitespace


# 1.86 12-Aug-2020 skrll

Part IV of ad's performance improvements for aarch64

- Implement pmap_growkernel(), and update kernel pmap's stats with atomics.

- Then, pmap_kenter_pa() and pmap_kremove() no longer need to allocate
memory nor take pm_lock, because they only modify L3 PTEs.

- Then, pm_lock and pp_lock can be adaptive mutexes at IPL_NONE which are
cheaper than spin mutexes.

- Take the pmap's lock in pmap_extract() if not the kernel's pmap, otherwise
pmap_extract() might see inconsistent state.


# 1.85 09-Aug-2020 skrll

Fix another UVMHIST so it doesn't use %s


# 1.84 16-Jul-2020 skrll

pmapboot_enter simplication
- bootpage_alloc in asm becomes pmapboot_pagealloc in C
- PMAPBOOT_ENTER_NOBLOCK is removed as it's not used
- PMAPBOOT_ENTER_NOOVERWRITE is removed as it's now always on
- physpage_allocator argument is removed as it's always
pmapboot_pagealloc
- Support for EARLYCONS without CONSADDR is removed so that the identity
map for CONSADDR is always known.

For the assembly files:
2 files changed, 40 insertions(+), 89 deletions(-)

LGTM ryo


# 1.83 04-Jul-2020 rin

Use tlen for temporary length variable instead of l, which is usually
used for struct lwp *.

No binary changes.


# 1.82 02-Jul-2020 rin

pmap_procwr(): sync icache even if p != curproc. This fixes applications
like GDB for arm32, that rewrite text of other process.

Thanks to ryo@ for discussion.


# 1.81 02-Jul-2020 rin

Set uvmexp.ncolors appropriately, which is required for some CPU
models with VIPT icache.

Otherwise, alias in virtual address results in inconsistent results,
at least for applications that rewrite text of other process, e.g.,
GDB for arm32.

Also, this hopefully fixes other unexpected failures due to alias.

Confirmed that there's no observable regression in performance;
difference in ``time make -j8'' for GENERIC64 kernel on BCM2837
with and without setting uvmexp.ncolors is within 0.1%.

Thanks to ryo@ for discussion.


# 1.80 27-Jun-2020 rin

Fix typo in name of evcnt(4) counter.


# 1.79 24-Jun-2020 ryo

Fix bug with incorrect range calculation when doing icache sync.
This is called by sysarch(ARM_SYNC_ICACHE) from aarch32 (compat_netbsd32) emul process.

pointed out by rin@, thanks.

XXX pullup-9


# 1.78 14-Jun-2020 ad

- Fix a lock order reversal in pmap_page_protect().

- Make sure pmap is always locked when updating stats; atomics no longer
needed to do that.

- Remove unneeded traversal of pv list in pmap_enter_pv().

- Shrink struct vm_page from 136 to 128 bytes (cache line sized) and struct
pv_entry from 48 to 32 bytes (power of 2 sized).

- Embed a pv_entry in each vm_page. This means PV entries don't need to
be allocated for private anonymous memory / COW pages / most UBC mappings.
Dynamic PV entries are then used only for stuff like shared libraries and
shared memory.

Proposed on port-arm@.


# 1.77 10-Jun-2020 ad

- Wired/resident stats shouldn't covered by PMAPCOUNTERS.
- Rename need_update_pv -> need_enter_pv.

Ok ryo@


# 1.76 01-Jun-2020 ryo

no need to make the PTE writable to do icache_sync, enough to accessible.


# 1.75 15-May-2020 skrll

Use __diagused


# 1.74 15-May-2020 tnn

fix non-diag build


# 1.73 14-May-2020 skrll

Use MUTEX_NODEBUG for PV locks as is commonly done. OK ryo.


# 1.72 13-May-2020 jmcneill

Implement pmap_extract_coherency


Revision tags: bouyer-xenpvh-base2 phil-wifi-20200421 bouyer-xenpvh-base1
# 1.71 18-Apr-2020 skrll

PMAP_DEBUG has been deleted on arm


# 1.70 13-Apr-2020 maxv

Add support for Branch Target Identification (BTI).

On the executable pages that have the GP (Guarded Page) bit, the semantic
of the "br" and "blr" instructions is changed: the CPU expects the first
instruction of the jump/call target to be "bti", and faults if it isn't.

We add the GP bit on the kernel .text pages (and incidentally the .rodata
pages, but we don't care). The compiler adds a "bti c" instruction at the
beginning of each C function. We modify the ENTRY() macros to manually add
"bti c" in the asm functions.

cpuswitch.S needs a specific change: with "br x27" the CPU expects "bti j",
which is bad because the functions begin with "bti c"; switch to "br x16",
for the CPU to accept "bti c".

BTI helps defend against JOP/COP. Tested on Qemu.


Revision tags: phil-wifi-20200411 bouyer-xenpvh-base
# 1.69 08-Apr-2020 ryo

branches: 1.69.2;
use PMAP_PAGE_INIT() to initialize mutex in pmap_page.

VM_MDPAGE_INIT() in pmap_free_pdp() had initialized pp_flags,
so it unintentionally cleared PMAP_PAGE_FLAGS_PV_TRACKED.
use PMAP_PAGE_INIT to avoid using PMAP_PAGE_FLAGS_PV_TRACKED.

pointed out by tnn@, thanks


Revision tags: phil-wifi-20200406
# 1.68 14-Mar-2020 ad

pmap_remove_all(): Return a boolean value to indicate the behaviour. If
true, all mappings have been removed, the pmap is totally cleared out, and
UVM can then avoid doing the work to call pmap_remove() for each map entry.
If false, either nothing has been done, or some helpful arch-specific voodoo
has taken place.


Revision tags: is-mlppp-base
# 1.67 02-Mar-2020 ryo

oops, fix incorrect usage of daif_enable() in my previous commit.


# 1.66 29-Feb-2020 ryo

Fix pmap to work correctly with tagged addresses

- when fault, untag from address before passing to uvm/pmap functions
- pmap_extract() checks more strictly and consider the address tag


# 1.65 29-Feb-2020 ryo

use pmapboot_enter_range()


Revision tags: ad-namecache-base3
# 1.64 10-Feb-2020 ryo

use LIST(3) instead of TAILQ(3) to save one word in struct vm_page and struct pmap.

pointed out by riastradh@. thanks


# 1.63 03-Feb-2020 ryo

add support pmap_pv(9)

Patch originally from jmcneill@. thanks


# 1.62 03-Feb-2020 ryo

separate struct vm_page_md into vm_page_md and pmap_page
for preparation pmap_pv(9)


Revision tags: ad-namecache-base2 ad-namecache-base1
# 1.61 09-Jan-2020 ryo

fix behaviour mmap()/mprotect() when passed only PROT_EXEC.

when mmap()/mprotect() with only PROT_EXEC, syscall will be successful,
but the page actually hadn't been mapped.
it should be mapped with PROT_READ|PROT_EXEC implicitly. (r-x)


Revision tags: ad-namecache-base
# 1.60 30-Dec-2019 skrll

branches: 1.60.2;
Update pmap_map_chunk to allow L[12] block mappings and L3 page mappings


# 1.59 30-Dec-2019 skrll

Remove unnecessary brackets and unwrap a conditional. Same code before
and after.


# 1.58 28-Dec-2019 jmcneill

Do not use Early Write Acknowledge for PCIe I/O and config space.


# 1.57 27-Dec-2019 jmcneill

Enable early write acknowledge for device memory mappings.


# 1.56 19-Dec-2019 skrll

G/C kasan_shadow_map call in pmap_enter

pmap_growkernel calls kasan_shadow_map for KVA


# 1.55 18-Dec-2019 ryo

atomic_add_16() is not used in pmap.c anymore. no need decl here.


# 1.54 18-Dec-2019 ryo

space to tab


# 1.53 14-Dec-2019 skrll

Fix build... wire_count probably doesn't need atomics


# 1.52 13-Dec-2019 skrll

Fix KASAN support by calling kasan_shadow_map in pmap_growkernel


# 1.51 10-Dec-2019 ad

pg->phys_addr -> VM_PAGE_TO_PHYS(pg)


Revision tags: phil-wifi-20191119
# 1.50 14-Nov-2019 maxv

Mark several kASan functions with __nothing, to avoid annoying #ifdefs.
Same as kCSan and kMSan.


# 1.49 14-Nov-2019 maxv

Don't include "opt_kasan.h" when there's already <sys/asan.h> included.


# 1.48 29-Oct-2019 maya

Define PMAP_NEED_PROCWR, providing strategically placed i-cache
synchronization where just-changed memory is about to be executed.

Fixes SIGILLs seen when running Mono 6 on QEMU Cortex-A57.

ok ryo


# 1.47 22-Sep-2019 jmcneill

Disable translation table walks using TTBR0 while changing its value and
when deactivating a pmap. Fixes stability issues on Ampere eMAG CPUs.


# 1.46 20-Sep-2019 ryo

ref/mod bit should be set according to 'flags' argument, not 'prot'. r1.44 was incomplete.


# 1.45 13-Sep-2019 ryo

In pmap_devmap_bootstrap(), cpu_earlydevice_va_p() must not return true until *all* devmap tables have been enabled.
console mapping may be present in the last table.


# 1.44 07-Sep-2019 ryo

- remove incorrect KASSERT. mmap(2) with prot=PROT_WRITE calls pmap_enter(..., PROT_WRITE) internally.
- fix to update page reference flags when only PROT_WRITE or PROT_EXECUTE specified


# 1.43 15-Aug-2019 skrll

Make pmap_db_pte_print more terse so it's quicker on serial consoles


# 1.42 12-Aug-2019 skrll

Use PMAP_DEV in DEVMAP_ENTRY rather than pmap_map_chunk. It's clearer and
means pmap_map_chunk can be made to map other memory types.


Revision tags: netbsd-9-base phil-wifi-20190609
# 1.41 17-May-2019 mrg

branches: 1.41.2;
apply some __diagused.


Revision tags: isaki-audio2-base
# 1.40 08-Apr-2019 ryo

- free empty page tables pages if reach a certain usage.
- need to lock at removing an old pg (_pmap_remove_pv) in _pmap_enter()


# 1.39 06-Apr-2019 ryo

Fix race conditions about pmap_page_protect() and pmap_enter().

while handling same PTE by these functions in same time, there
is a critical path that the number of valid PTEs and wire_count
are inconsistent, and it caused KASSERT.
Need to hold a pv_lock while modifying them.


# 1.38 20-Mar-2019 ryo

spinkle __printflike(), and use PRIxxx


# 1.37 19-Mar-2019 ryo

- add ddb command "machine ttbr" to dump MMU tables.
- tidy up descriptions, usages and messages.


# 1.36 19-Mar-2019 ryo

- free L1-L3 pages that has been emptied by pmap_remove().
- if no memories, pmap_enter will return correctly ENOMEM if PMAP_CANFAIL, or wait until available any memories if !PMAP_CANFAIL.

These changes improves the stability when we use a huge virtual memory spaces with mmap.


# 1.35 06-Feb-2019 ryo

improve pmap_remove
- don't lock/unlock per page in pmap_remove()
- speedup pte lookup for continuous addresses
- bring out pool_cache_put(&_pmap_pv_pool, pv) from lock/unlock section


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226
# 1.34 21-Dec-2018 ryo

- add workaround for Cavium ThunderX errata 27456.
- add cpufuncs table in cpu_info. each cpu clusters may have different erratum. (e.g. big.LITTLE)


Revision tags: pgoyette-compat-1126
# 1.33 01-Nov-2018 maxv

Add kASan support for aarch64. Stack tracking needs more investigation
and will come in a separate commit.

Reviewed by ryo@ jmcneill@ skrll@.


# 1.32 31-Oct-2018 ryo

invalidate icache correctly.
l3pte_executable() should be used for only valid pte.


Revision tags: pgoyette-compat-1020
# 1.31 18-Oct-2018 skrll

Provide generic start code that assumes the MMU is off and caches are
disabled as per the linux booting protocol for ARMv6 and ARMv7 boards.
u-boot image type should be changed to 'linux' for correct behaviour.

The new start code builds a minimal "bootstrap" L1PT with cached access
disabled and uses the same table for all processors. AP startup is
performed in less steps and more code is written in C.

The bootstrap tables and stack are placed into an (orphaned) section
"_init_memory" which is given to uvm when it is no longer used.

Various kernels have been converted to use this code and tested. Some
boards were provided by TNF. Thanks!

The GENERIC kernel now boots on boards using the TEGRA, SUNXI and EXYNOS
kernels. The GENERIC kernel will also work on RPI2 using u-boot.

Thanks to martin@ and aymeric@ for testing on parallella and nanosoc
respectively


# 1.30 14-Oct-2018 skrll

Use __nothing


# 1.29 12-Oct-2018 ryo

add initial support of COMPAT_NETBSD32 on AArch64.
arm ELF32 EABI binaries could be execute in AArch32 state on AArch64. A32 THUMB mode is not supported yet.


# 1.28 12-Oct-2018 ryo

- cleanup checking address ranges with IN_RANGE macro
- change PM_ADDR_CHECK macro to KASSERTMSG
- restore fast lookup cases with IN_RANGE macro for pmap_extract changed in my previous commit.


# 1.27 12-Oct-2018 ryo

rewrite pmap_pte_lookup() to share similar code.


# 1.26 04-Oct-2018 ryo

cleanup locore, and changed the way to map memories during boot.
- add functions bootpage_enter() and bootpage_alloc() to adapt various layout
of physical memory map. especially for 64bit physical memory layout.
pmapboot_alloc() allocates pagetable pages from _end[].
- changed to map only the required amount for PA=VA identity mapping
(kernel image, UART device, and FDT blob) with L2_BLOCK(2Mbyte).
- changing page permission for kernel image, and making KSEG mapping are done
at cpu_kernel_vm_init() instead of at locore.
- optimize PTE entries with PTE Contiguous bit. it is enabled on devmap only for now.

reviewed by skrll@, thanks.


# 1.25 04-Oct-2018 ryo

* define LX_BLKPAG_{OS,ATTR}_* for OS dependent PTE attributes in pmap.h
* cleanup macros


Revision tags: pgoyette-compat-0930
# 1.24 17-Sep-2018 ryo

delete debug printf and KASSERT.


# 1.23 10-Sep-2018 maxv

Replace KDASSERT by panic.


# 1.22 10-Sep-2018 maxv

Rename _pmap_alloc_pdp -> pmap_alloc_pdp, and make it public.


# 1.21 10-Sep-2018 ryo

cleanup aarch64 mpstart and fdt bootstrap
* arm_cpu_hatch_arg is a bad idea. avoid serializing CPU startup, and eliminate arm_cpu_hatch_arg.
in mpstart, resolve own cpu index using array of cpu_mpidr[] (aarch64)
* add support fdt enable-method "spin-table"
* add support fdt enable-method "brcm,bcm2836-smp" (for 32bit RaspberryPi)
* use arm_fdt_cpu_bootstrap() instead of psci_fdt_bootstrap()
* rename "arm/fdt/psci_fdt.h" to "arm/fdt/psci_fdtvar.h" because of conflict of include file for needs-flag
* add devmap for cpu spin-table of raspberrypi3/aarch64
* no need to force hatch APs for raspberrypi3/arm32 ifndef MULTIPROCESSOR.
* fix to work pmap_extract(kerneltext/data/bss) even if before calling pmap_bootstrap

idea to use cpu_mpidr[] by jmcneill@. reviewd by skrll@. thanks.


Revision tags: pgoyette-compat-0906
# 1.20 27-Aug-2018 ryo

need to add VM_PROT_READ when pmap_kenter_pa(va, pa, VM_PROT_WRITE, 0) or pmap_kenter_pa(va, pa, VM_PROT_EXECUTE, 0).
VM_PROT_READ is treated as an access permission inernally.


# 1.19 11-Aug-2018 ryo

change to minimum invalidation of TLB.
specifying not only va but also asid, and not invalidate L0-L2 entry using tlbi_*_ll() if needed.


# 1.18 10-Aug-2018 ryo

treat kernel-exec attr and user-exec attr separately.
kernel cannot execute userland exec page, and user cannot execute kernel page.


# 1.17 06-Aug-2018 ryo

set kernel text/rodata readonly by default.
add function db_write_text() for setting ddb breakpoint.


# 1.16 31-Jul-2018 skrll

Define and use VPRINTF


Revision tags: pgoyette-compat-0728
# 1.15 27-Jul-2018 ryo

changes of pmap.c r1.13 seems to be unstable.
In order to invalidate icache, not to invalidate all icache,
but temporary to make the page writable and invalidate target address only.


# 1.14 24-Jul-2018 ryo

don't call pool_cache_put with locking pmap. pool_cache_put call pmap_kenter_pa internally.
(pool_cache_put_paddr -> pool_cache_put_slow -> pool_get -> pmap_kenter_pa)


# 1.13 23-Jul-2018 ryo

* fix icache invalidations.
* "ic ivau" (aarch64_icache_sync_range) with VA generates permission fault in some situations, therefore use KSEG address for now.


# 1.12 23-Jul-2018 ryo

rather than using flags to resolve nested locks, reserve pool_cache before locking.


# 1.11 21-Jul-2018 ryo

* avoid deadlock. mutex_owned() works only for adaptive lock, therefore we cannot use it for spinlock...
* add more NULL check
* clear pte when pmap_enter() fails


# 1.10 17-Jul-2018 ryo

Use __debugused


# 1.9 17-Jul-2018 christos

Add missing casts, remove unused variables.


# 1.8 09-Jul-2018 ryo

need locks in pmap_kremove() and pmap_fault_fixup()


Revision tags: phil-wifi-base pgoyette-compat-0625 pgoyette-compat-0521
# 1.7 20-May-2018 ryo

branches: 1.7.2;
pmap_enter() must update modified/referenced flags by 'flags' not 'prot'.


# 1.6 16-May-2018 ryo

Fix memory leak. it was leaking one page every pmap_create().
pm->pm_vmlist must be initialized before calling _pmap_alloc_pdp().


Revision tags: pgoyette-compat-0502
# 1.5 29-Apr-2018 ryo

fix KASSERT panic. pv_entry may not be exists in pvlist when pmap_remove().


# 1.4 29-Apr-2018 ryo

delete unused code


# 1.3 27-Apr-2018 ryo

fix instability behavior of bufcache on aarch64.
* fix to return correct ref/mod when PMAP_WIRED.
* changed to keep wired flags in pte instead of pv_entry, and cleanup.


Revision tags: pgoyette-compat-0422 pgoyette-compat-0415 pgoyette-compat-0407
# 1.2 01-Apr-2018 ryo

Add initial support for ARMv8 (AARCH64) (by nisimura@ and ryo@)

- sys/arch/evbarm64 is gone and integrated into sys/arch/evbarm. (by skrll@)
- add support fdt. evbarm/conf/GENERIC64 fdt (bcm2837,sunxi,tegra) based generic 64bit kernel config. (by skrll@, jmcneill@)


Revision tags: netbsd-8-2-RELEASE netbsd-8-1-RELEASE netbsd-8-1-RC1 netbsd-7-2-RELEASE netbsd-8-0-RELEASE netbsd-8-0-RC2 netbsd-8-0-RC1 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 netbsd-7-1-2-RELEASE pgoyette-compat-base netbsd-7-1-1-RELEASE tls-maxphys-base-20171202 matt-nb8-mediatek-base nick-nhusb-base-20170825 perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base pgoyette-localcount-20170320 netbsd-7-1-RELEASE netbsd-7-1-RC2 nick-nhusb-base-20170204 netbsd-7-nhusb-base-20170116 bouyer-socketcan-base pgoyette-localcount-20170107 netbsd-7-1-RC1 nick-nhusb-base-20161204 pgoyette-localcount-20161104 netbsd-7-0-2-RELEASE nick-nhusb-base-20161004 localcount-20160914 netbsd-7-nhusb-base pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907 nick-nhusb-base-20160529 netbsd-7-0-1-RELEASE nick-nhusb-base-20160422 nick-nhusb-base-20160319 nick-nhusb-base-20151226 netbsd-7-0-RELEASE nick-nhusb-base-20150921 netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 nick-nhusb-base-20150606 nick-nhusb-base-20150406 nick-nhusb-base tls-maxphys-base netbsd-7-base
# 1.1 10-Aug-2014 matt

branches: 1.1.4; 1.1.28;
Preliminary files for AARCH64 (64-bit ARM) support.
Enough for a distribution build.


# 1.149 20-Apr-2023 skrll

Provide a shared pmap_devmap implementation and convert all pmap_devmap
arrays to use DEVMAP_ENTRY{,_END}


# 1.148 16-Apr-2023 skrll

Rename VM_KERNEL_IO_ADDRESS to VM_KERNEL_IO_BASE to match RISC-V

It's less letters, matches other similar variables and will help with
sharing code between the two architectures.

NFCI.


Revision tags: netbsd-10-base
# 1.147 30-Oct-2022 riastradh

aarch64/pmap: Fix criterion in previous.

Use the pte bit that says whether this is a PMAP_WIRED page, not the
bit that says whether this is a non-global page.

(Forgot to git commit --amend before exporting to CVS, sorry!)


# 1.146 30-Oct-2022 riastradh

aarch64/pmap(9): Teach pmap_protect about pmap_kenter_pa mappings.

Pages mapped with pmap_kenter_pa are necessarily unmanaged, so there
are no P->V records, and pmap_kenter_pa leaves pp->pp_pv.pv_va zero
with no modified/referenced state.

However, pmap_protect erroneously examined pp->pp_pv.pv_va to
ascertain the modified/referenced state -- and if the page was not
marked referenced, pmap_protect would clear the LX_BLKPAG_AF bit
(Access Flag), with the effect that subsequent uses of the page fault
and require a detour through pmap_fault_fixup.

This caused problems for the kernel module loader:

- When loading the text section, kobj_load first allocates kva with
uvm_km_alloc(UVM_KMF_WIRED|UVM_KMF_EXEC), which creates ptes with
pmap_kenter_pa. These ptes are writable, so we can copy the text
section into them, and have LX_BLKPAG_AF set so there will be no
fault when they are used by the kernel.

- But then kobj_affix makes the text section read/execute-only (and
nonwritable) with uvm_km_protect(VM_PROT_READ|VM_PROT_EXECUTE),
which updates the ptes with pmap_protect. This _should_ leave
LX_BLKPAG_AF set, but by inadvertently treating the page as managed
when it should be unmanaged, pmap_protect cleared it instead.

- Most of the time, clearing LX_BLKPAG_AF caused no problem, because
pmap_fault_fixup would silently resolve it. But if a hard
interrupt handler tried to use any page in the module's text (or
rodata, I suspect) that was not yet fixed up, the CPU would fault
and enter pmap_fault_fixup -- which would promptly crash (or hang)
by trying to take the pmap lock in interrupt context, which is
forbidden.

I observed this by loading dtrace.kmod early at boot and trying to
dtrace hard interrupt handlers.

With this change, pmap_protect now recognizes wired mappings (as
created by pmap_kenter_pa) before consulting pp->pp_pv.pv_va, and
preserves then LX_BLKPAG_AF bit in that case.

ok skrll


# 1.145 29-Oct-2022 skrll

fix a spello in a comment


# 1.144 28-Oct-2022 skrll

Remove some empty lines


# 1.143 23-Oct-2022 skrll

Use UVMHIST_CALLARGS in pmap_bootstrap


# 1.142 23-Oct-2022 skrll

Only define the EFI variable if EFI_RUNTIME


# 1.141 20-Oct-2022 skrll

KNF


# 1.140 15-Oct-2022 jmcneill

Use "non-posted" instead of "strongly ordered" to describe nGnRnE mappings

Rename the following defines:
- _ARM_BUS_SPACE_MAP_STRONGLY_ORDERED to BUS_SPACE_MAP_NONPOSTED
- PMAP_DEV_SO to PMAP_DEV_NP
- LX_BLKPAG_ATTR_DEVICE_MEM_SO to LX_BLKPAG_ATTR_DEVICE_MEM_NP
Rename the following option:
- AARCH64_DEVICE_MEM_STRONGLY_ORDERED to AARCH64_DEVICE_MEM_NONPOSTED


Revision tags: bouyer-sunxi-drm-base
# 1.139 19-Aug-2022 ryo

Fixed a bug that pte's __BIT(63,48) could be set when accessing addresses above 0x0001000000000000 in /dev/mem with mmap().


# 1.138 19-Aug-2022 ryo

When accessed in mmap by the device pager, pmap_enter() may be called with prot == PROT_WRITE.


# 1.137 03-May-2022 skrll

Sprinkle some KASSERT(kpreempt_disabled());


# 1.136 27-Apr-2022 ryo

since pmap_activate_efirt() rewrites TTBR0, it is necessary to pmap_activate() again after pmap_deactivate_efirt() to restore the original TTBR0.

- Fix to do pmap_{de,}activate() before/after pmap_{,de}activate_efirt().
- moved kpreempt_{disable,enable}() to the caller since everything between
arm_efirt_md_enter() and arm_efirt_md_exit() should be kpreempt disabled.

ok skrll@


# 1.135 17-Apr-2022 skrll

Add the missing kpreempt_enable to pmap_deactivate_efirt


# 1.134 10-Apr-2022 skrll

No need to flush icache for EFI RT mappings as bootaa64.efi flushed
the full icache for us. (Also this avoids traps)


# 1.133 09-Apr-2022 riastradh

sys: Use membar_release/acquire around reference drop.

This just goes through my recent reference count membar audit and
changes membar_exit to membar_release and membar_enter to
membar_acquire -- this should make everything cheaper on most CPUs
without hurting correctness, because membar_acquire is generally
cheaper than membar_enter.


# 1.132 02-Apr-2022 skrll

Update to support EFI runtime outside the kernel virtual address space
by creating an EFI RT pmap that can be activated / deactivated when
required.

Adds support for EFI RT to ARM_MMU_EXTENDED (ASID) 32-bit Arm machines.

On Arm64 the usage of pmapboot_enter is reduced and the mappings are
created much later in the boot process -- now in cpu_startup_hook.
Backward compatiblity for KVA mapped RT from old bootaa64.efi is
maintained.

Adding support to other platforms should be easier as a result.


# 1.131 19-Mar-2022 skrll

Slight code re-organisation. NFCI.


# 1.130 12-Mar-2022 riastradh

sys: Membar audit around reference count releases.

If two threads are using an object that is freed when the reference
count goes to zero, we need to ensure that all memory operations
related to the object happen before freeing the object.

Using an atomic_dec_uint_nv(&refcnt) == 0 ensures that only one
thread takes responsibility for freeing, but it's not enough to
ensure that the other thread's memory operations happen before the
freeing.

Consider:

Thread A Thread B
obj->foo = 42; obj->baz = 73;
mumble(&obj->bar); grumble(&obj->quux);
/* membar_exit(); */ /* membar_exit(); */
atomic_dec -- not last atomic_dec -- last
/* membar_enter(); */
KASSERT(invariant(obj->foo,
obj->bar));
free_stuff(obj);

The memory barriers ensure that

obj->foo = 42;
mumble(&obj->bar);

in thread A happens before

KASSERT(invariant(obj->foo, obj->bar));
free_stuff(obj);

in thread B. Without them, this ordering is not guaranteed.

So in general it is necessary to do

membar_exit();
if (atomic_dec_uint_nv(&obj->refcnt) != 0)
return;
membar_enter();

to release a reference, for the `last one out hit the lights' style
of reference counting. (This is in contrast to the style where one
thread blocks new references and then waits under a lock for existing
ones to drain with a condvar -- no membar needed thanks to mutex(9).)

I searched for atomic_dec to find all these. Obviously we ought to
have a better abstraction for this because there's so much copypasta.
This is a stop-gap measure to fix actual bugs until we have that. It
would be nice if an abstraction could gracefully handle the different
styles of reference counting in use -- some years ago I drafted an
API for this, but making it cover everything got a little out of hand
(particularly with struct vnode::v_usecount) and I ended up setting
it aside to work on psref/localcount instead for better scalability.

I got bored of adding #ifdef __HAVE_ATOMIC_AS_MEMBAR everywhere, so I
only put it on things that look performance-critical on 5sec review.
We should really adopt membar_enter_preatomic/membar_exit_postatomic
or something (except they are applicable only to atomic r/m/w, not to
atomic_load/store_*, making the naming annoying) and get rid of all
the ifdefs.


# 1.129 05-Mar-2022 skrll

Slight comment improvement.


# 1.128 16-Feb-2022 andvar

fix various typos, mainly in comments.


# 1.127 31-Jan-2022 ryo

add support Hardware updates to Access flag and Dirty state (FEAT_HAFDBS)

- The DBM bit of the PTE is now used to determine if it is writable, and
the AF bit is treated entirely as a reference bit. A valid PTE is always
treated as readable. There can be no valid PTE that is not readable.
- LX_BLKPAG_OS_{READ,WRITE} are used only for debugging purposes,
and has been superseded by LX_BLKPAG_AF and LX_BLKPAG_DBM.
- Improve comment

The need for reference/modify emulation has been eliminated,
and access/permission faults have been reduced, however,
there has been little change in overall performance.


# 1.126 31-Jan-2022 ryo

Skip unnecessary PTE operations and TLB invalidation.


# 1.125 16-Jan-2022 rillig

aarch64/pmap: remove stray semicolon

No binary change.


# 1.124 15-Jan-2022 skrll

The translations that need invalidation are always last level so remove
the (dubious) logic around tracking the level. The "any level" TLB
invalidation maintenance operation are used, but this may change after
further testing.

before
======
1661.0u 420.2s 2:53.82 1197.3% 231+29k 10+33918io 102pf+0w
1646.8u 425.2s 2:52.96 1198.0% 232+29k 1+33937io 49pf+0w
1647.9u 425.7s 2:52.58 1201.6% 232+29k 0+33940io 32pf+0w

After
=====
1602.5u 420.8s 2:49.09 1196.6% 238+30k 24+33893io 54pf+0w
1600.7u 421.3s 2:51.53 1178.8% 238+30k 1+33914io 33pf+0w
1597.5u 424.3s 2:50.46 1186.1% 238+30k 0+33915io 17pf+0w

LGTM from ryo@


# 1.123 14-Jan-2022 skrll

Restore the previous pmap_remove_all behaviour as the new method meant
the n1sdp couldn't complete a build.

No noticeable change in kernel build performance.


# 1.122 04-Jan-2022 skrll

KNF


# 1.121 10-Dec-2021 andvar

s/occured/occurred/ in comments, log messages and man pages.


# 1.120 07-Dec-2021 andvar

fix various typos, mainly in comments.


# 1.119 23-Oct-2021 skrll

Fix non-UVMHIST build


# 1.118 16-Oct-2021 ryo

fix non-MULTIPROCESSOR build


# 1.117 10-Oct-2021 skrll

Use sys/uvm/pmap/pmap_tlb.c on Aarch64 in the same way that some Arm, MIPS,
and some PPC kernels do. This removes the limitation of 256 processes on
CPUs with 8bit ASID field, e.g. Apple M1.

Additionally the following changes have been made

- removed a couple of unnecessary aarch64_tlbi_all calls
- removed any invalidation after freeing page tables due to
_pmap_sweep_pdp. This was never necessary afaict.
- all kernel mappings are marked global and userland mapping not-global.

Performance testing hasn't show a significant difference. The data here
is from building a kernel on an lx2k system with nvme.

before
1489.6u 400.4s 2:40.65 1176.5% 228+224k 0+32289io 57pf+0w
1482.6u 403.2s 2:38.49 1189.9% 228+222k 0+32274io 46pf+0w
1485.4u 402.2s 2:37.27 1200.2% 228+222k 0+32275io 12pf+0w

after
1493.9u 404.6s 2:37.50 1205.4% 227+221k 0+32265io 48pf+0w
1485.0u 408.0s 2:38.54 1194.0% 227+222k 0+32272io 36pf+0w
1484.3u 407.0s 2:35.88 1213.3% 228+224k 0+32268io 14pf+0w

>>> stats.ttest_ind([160.65,158.49,157.27], [157.5,158.54,155.88])
Ttest_indResult(statistic=1.1923622711296888, pvalue=0.2990182944606766)
>>>


# 1.116 30-Sep-2021 skrll

Ensure TCR_EPD0 is set on entry to pmap_activate and ensure it is set as
early as possible for APs.


# 1.115 26-Sep-2021 skrll

Use UVMHIST_CALLARGS


# 1.114 26-Sep-2021 skrll

'\n' is not required in KASSERTMSG either.


# 1.113 26-Sep-2021 skrll

"\n" is not required in KERNHIST


# 1.112 15-Sep-2021 skrll

Use __SHIFTIN. Same code before and after.


# 1.111 12-Sep-2021 skrll

pmap_page_remove: simply and reduce the code size slightly.


# 1.110 09-Sep-2021 skrll

In pmap_icache_sync_range change

for (...) {
...
if (condition) {
// do stuff
}
}

to

for (...) {
...
if (!conditional)
continue;
// do stuff
}

to save on indentation. Same code (modulo register usage) before and
after.


# 1.109 09-Sep-2021 skrll

KNF


Revision tags: thorpej-i2c-spi-conf2-base thorpej-futex2-base thorpej-cfargs2-base cjep_sun2x-base1 cjep_sun2x-base cjep_staticlib_x-base1 thorpej-i2c-spi-conf-base
# 1.108 29-May-2021 skrll

Deal with the pmap limitation of maxproc in a more complete way and
recognise CPUs with only 8bit ASIDs.


Revision tags: cjep_staticlib_x-base
# 1.107 30-Apr-2021 skrll

branches: 1.107.2;
Make the ddb for pmap / pte information pmap agnostic


# 1.106 29-Apr-2021 skrll

Remove some unnecessary tlb invalidate in pmap_growkernel and ASAN shadow
map. Ensure the shadow map mappings are visible to the TLB walkers.


# 1.105 21-Apr-2021 ryo

branches: 1.105.2;
added more attributes of PTE displayed by "ddb>machine pte"


Revision tags: thorpej-cfargs-base
# 1.104 17-Apr-2021 mrg

remove KERNHIST_INIT_STATIC(). it stradles the line between usable
early in boot and broken early in boot by requiring a partly static
structure with another structure that must be present by the time
any uses are performed. theoretically platform code could allocate
a chunk while seting up memory and assign it here, giving a dynamic
sizing for the entry list, but the reality is that all users have
a statically allocated entry list as well.

the existing KERNHIST_LINK_STATIC() is used in conjunction with
KERNHIST_INITIALIZER() instead.

this stops a NULL pointer deref when the _LOG() macro is called
before the storage is linked in, which happens with GCC 10 on OCTEON
with UVMHIST enabled, crashing in very early kernel init.


Revision tags: thorpej-futex-base
# 1.103 09-Mar-2021 ryo

branches: 1.103.2;
fix build error without options DDB.

kvtopte() is referenced from arm/acpi/acpi_machdep.c


# 1.102 13-Feb-2021 ryo

No assignment is needed here.

the loop in pmap_page_remove() always removes the first pv,
and since the list is managed by _pmap_remove_pv(), pp->pp_pv.pv_next always points to the first.


# 1.101 01-Feb-2021 ryo

It is enough to make a page accessible instead of writable.
same fix as r1.76


# 1.100 31-Jan-2021 ryo

implement pmap_remove_all().

The size of struct pv_entry has increased, but speed of kernel build has improved by about 1%
exec and exit should have been improved.


# 1.99 20-Dec-2020 skrll

Improve the English in the previous comment fix.


# 1.98 19-Dec-2020 skrll

Tweak a comment


# 1.97 11-Dec-2020 skrll

s:aarch64/cpufunc.h:arm/cpufunc.h:

a baby step in the grand arm header unification challenge


# 1.96 10-Nov-2020 skrll

AA64 is not MIPS.

Change all KSEG references to directmap


# 1.95 07-Nov-2020 skrll

In pmap_devmap_bootstrap only set pmap_devmap_bootstrap_done if there
is an entry and ALL of the entries have been done. The entry required
for EARLYCONS might not be the first/only one...


# 1.94 01-Nov-2020 jmcneill

branches: 1.94.2;
No need to disable translation table walks in pmap_activate().


# 1.93 22-Oct-2020 skrll

Use the isb macro - missed in previous commit


# 1.92 22-Oct-2020 skrll

Use the dmb/dsb/isb macros... if nothing else they're all now consistent
about the "memory" assembler contraint.

No binary change


# 1.91 28-Sep-2020 skrll

Only set pmap_devmap_bootstrap_done if something gets mapped.

Think acpi_platform_devmap


# 1.90 19-Sep-2020 skrll

Make __md_palloc pmap agnostic (think sys/uvm/pmap)


# 1.89 14-Sep-2020 ryo

PID_MAX is just an initial value (soft maximum). Don't use it for CTASSERT.
defined __HAVE_CPU_MAXPROC to use function cpu_maxproc().

pointed out by mrg@, thanks.


# 1.88 06-Sep-2020 ryo

Fix panic caused by modload. http://mail-index.netbsd.org/port-arm/2020/08/30/msg006960.html

The address space reserved for modules may not be mapped in L1-L3.


# 1.87 14-Aug-2020 skrll

Whitespace


# 1.86 12-Aug-2020 skrll

Part IV of ad's performance improvements for aarch64

- Implement pmap_growkernel(), and update kernel pmap's stats with atomics.

- Then, pmap_kenter_pa() and pmap_kremove() no longer need to allocate
memory nor take pm_lock, because they only modify L3 PTEs.

- Then, pm_lock and pp_lock can be adaptive mutexes at IPL_NONE which are
cheaper than spin mutexes.

- Take the pmap's lock in pmap_extract() if not the kernel's pmap, otherwise
pmap_extract() might see inconsistent state.


# 1.85 09-Aug-2020 skrll

Fix another UVMHIST so it doesn't use %s


# 1.84 16-Jul-2020 skrll

pmapboot_enter simplication
- bootpage_alloc in asm becomes pmapboot_pagealloc in C
- PMAPBOOT_ENTER_NOBLOCK is removed as it's not used
- PMAPBOOT_ENTER_NOOVERWRITE is removed as it's now always on
- physpage_allocator argument is removed as it's always
pmapboot_pagealloc
- Support for EARLYCONS without CONSADDR is removed so that the identity
map for CONSADDR is always known.

For the assembly files:
2 files changed, 40 insertions(+), 89 deletions(-)

LGTM ryo


# 1.83 04-Jul-2020 rin

Use tlen for temporary length variable instead of l, which is usually
used for struct lwp *.

No binary changes.


# 1.82 02-Jul-2020 rin

pmap_procwr(): sync icache even if p != curproc. This fixes applications
like GDB for arm32, that rewrite text of other process.

Thanks to ryo@ for discussion.


# 1.81 02-Jul-2020 rin

Set uvmexp.ncolors appropriately, which is required for some CPU
models with VIPT icache.

Otherwise, alias in virtual address results in inconsistent results,
at least for applications that rewrite text of other process, e.g.,
GDB for arm32.

Also, this hopefully fixes other unexpected failures due to alias.

Confirmed that there's no observable regression in performance;
difference in ``time make -j8'' for GENERIC64 kernel on BCM2837
with and without setting uvmexp.ncolors is within 0.1%.

Thanks to ryo@ for discussion.


# 1.80 27-Jun-2020 rin

Fix typo in name of evcnt(4) counter.


# 1.79 24-Jun-2020 ryo

Fix bug with incorrect range calculation when doing icache sync.
This is called by sysarch(ARM_SYNC_ICACHE) from aarch32 (compat_netbsd32) emul process.

pointed out by rin@, thanks.

XXX pullup-9


# 1.78 14-Jun-2020 ad

- Fix a lock order reversal in pmap_page_protect().

- Make sure pmap is always locked when updating stats; atomics no longer
needed to do that.

- Remove unneeded traversal of pv list in pmap_enter_pv().

- Shrink struct vm_page from 136 to 128 bytes (cache line sized) and struct
pv_entry from 48 to 32 bytes (power of 2 sized).

- Embed a pv_entry in each vm_page. This means PV entries don't need to
be allocated for private anonymous memory / COW pages / most UBC mappings.
Dynamic PV entries are then used only for stuff like shared libraries and
shared memory.

Proposed on port-arm@.


# 1.77 10-Jun-2020 ad

- Wired/resident stats shouldn't covered by PMAPCOUNTERS.
- Rename need_update_pv -> need_enter_pv.

Ok ryo@


# 1.76 01-Jun-2020 ryo

no need to make the PTE writable to do icache_sync, enough to accessible.


# 1.75 15-May-2020 skrll

Use __diagused


# 1.74 15-May-2020 tnn

fix non-diag build


# 1.73 14-May-2020 skrll

Use MUTEX_NODEBUG for PV locks as is commonly done. OK ryo.


# 1.72 13-May-2020 jmcneill

Implement pmap_extract_coherency


Revision tags: bouyer-xenpvh-base2 phil-wifi-20200421 bouyer-xenpvh-base1
# 1.71 18-Apr-2020 skrll

PMAP_DEBUG has been deleted on arm


# 1.70 13-Apr-2020 maxv

Add support for Branch Target Identification (BTI).

On the executable pages that have the GP (Guarded Page) bit, the semantic
of the "br" and "blr" instructions is changed: the CPU expects the first
instruction of the jump/call target to be "bti", and faults if it isn't.

We add the GP bit on the kernel .text pages (and incidentally the .rodata
pages, but we don't care). The compiler adds a "bti c" instruction at the
beginning of each C function. We modify the ENTRY() macros to manually add
"bti c" in the asm functions.

cpuswitch.S needs a specific change: with "br x27" the CPU expects "bti j",
which is bad because the functions begin with "bti c"; switch to "br x16",
for the CPU to accept "bti c".

BTI helps defend against JOP/COP. Tested on Qemu.


Revision tags: phil-wifi-20200411 bouyer-xenpvh-base
# 1.69 08-Apr-2020 ryo

branches: 1.69.2;
use PMAP_PAGE_INIT() to initialize mutex in pmap_page.

VM_MDPAGE_INIT() in pmap_free_pdp() had initialized pp_flags,
so it unintentionally cleared PMAP_PAGE_FLAGS_PV_TRACKED.
use PMAP_PAGE_INIT to avoid using PMAP_PAGE_FLAGS_PV_TRACKED.

pointed out by tnn@, thanks


Revision tags: phil-wifi-20200406
# 1.68 14-Mar-2020 ad

pmap_remove_all(): Return a boolean value to indicate the behaviour. If
true, all mappings have been removed, the pmap is totally cleared out, and
UVM can then avoid doing the work to call pmap_remove() for each map entry.
If false, either nothing has been done, or some helpful arch-specific voodoo
has taken place.


Revision tags: is-mlppp-base
# 1.67 02-Mar-2020 ryo

oops, fix incorrect usage of daif_enable() in my previous commit.


# 1.66 29-Feb-2020 ryo

Fix pmap to work correctly with tagged addresses

- when fault, untag from address before passing to uvm/pmap functions
- pmap_extract() checks more strictly and consider the address tag


# 1.65 29-Feb-2020 ryo

use pmapboot_enter_range()


Revision tags: ad-namecache-base3
# 1.64 10-Feb-2020 ryo

use LIST(3) instead of TAILQ(3) to save one word in struct vm_page and struct pmap.

pointed out by riastradh@. thanks


# 1.63 03-Feb-2020 ryo

add support pmap_pv(9)

Patch originally from jmcneill@. thanks


# 1.62 03-Feb-2020 ryo

separate struct vm_page_md into vm_page_md and pmap_page
for preparation pmap_pv(9)


Revision tags: ad-namecache-base2 ad-namecache-base1
# 1.61 09-Jan-2020 ryo

fix behaviour mmap()/mprotect() when passed only PROT_EXEC.

when mmap()/mprotect() with only PROT_EXEC, syscall will be successful,
but the page actually hadn't been mapped.
it should be mapped with PROT_READ|PROT_EXEC implicitly. (r-x)


Revision tags: ad-namecache-base
# 1.60 30-Dec-2019 skrll

branches: 1.60.2;
Update pmap_map_chunk to allow L[12] block mappings and L3 page mappings


# 1.59 30-Dec-2019 skrll

Remove unnecessary brackets and unwrap a conditional. Same code before
and after.


# 1.58 28-Dec-2019 jmcneill

Do not use Early Write Acknowledge for PCIe I/O and config space.


# 1.57 27-Dec-2019 jmcneill

Enable early write acknowledge for device memory mappings.


# 1.56 19-Dec-2019 skrll

G/C kasan_shadow_map call in pmap_enter

pmap_growkernel calls kasan_shadow_map for KVA


# 1.55 18-Dec-2019 ryo

atomic_add_16() is not used in pmap.c anymore. no need decl here.


# 1.54 18-Dec-2019 ryo

space to tab


# 1.53 14-Dec-2019 skrll

Fix build... wire_count probably doesn't need atomics


# 1.52 13-Dec-2019 skrll

Fix KASAN support by calling kasan_shadow_map in pmap_growkernel


# 1.51 10-Dec-2019 ad

pg->phys_addr -> VM_PAGE_TO_PHYS(pg)


Revision tags: phil-wifi-20191119
# 1.50 14-Nov-2019 maxv

Mark several kASan functions with __nothing, to avoid annoying #ifdefs.
Same as kCSan and kMSan.


# 1.49 14-Nov-2019 maxv

Don't include "opt_kasan.h" when there's already <sys/asan.h> included.


# 1.48 29-Oct-2019 maya

Define PMAP_NEED_PROCWR, providing strategically placed i-cache
synchronization where just-changed memory is about to be executed.

Fixes SIGILLs seen when running Mono 6 on QEMU Cortex-A57.

ok ryo


# 1.47 22-Sep-2019 jmcneill

Disable translation table walks using TTBR0 while changing its value and
when deactivating a pmap. Fixes stability issues on Ampere eMAG CPUs.


# 1.46 20-Sep-2019 ryo

ref/mod bit should be set according to 'flags' argument, not 'prot'. r1.44 was incomplete.


# 1.45 13-Sep-2019 ryo

In pmap_devmap_bootstrap(), cpu_earlydevice_va_p() must not return true until *all* devmap tables have been enabled.
console mapping may be present in the last table.


# 1.44 07-Sep-2019 ryo

- remove incorrect KASSERT. mmap(2) with prot=PROT_WRITE calls pmap_enter(..., PROT_WRITE) internally.
- fix to update page reference flags when only PROT_WRITE or PROT_EXECUTE specified


# 1.43 15-Aug-2019 skrll

Make pmap_db_pte_print more terse so it's quicker on serial consoles


# 1.42 12-Aug-2019 skrll

Use PMAP_DEV in DEVMAP_ENTRY rather than pmap_map_chunk. It's clearer and
means pmap_map_chunk can be made to map other memory types.


Revision tags: netbsd-9-base phil-wifi-20190609
# 1.41 17-May-2019 mrg

branches: 1.41.2;
apply some __diagused.


Revision tags: isaki-audio2-base
# 1.40 08-Apr-2019 ryo

- free empty page tables pages if reach a certain usage.
- need to lock at removing an old pg (_pmap_remove_pv) in _pmap_enter()


# 1.39 06-Apr-2019 ryo

Fix race conditions about pmap_page_protect() and pmap_enter().

while handling same PTE by these functions in same time, there
is a critical path that the number of valid PTEs and wire_count
are inconsistent, and it caused KASSERT.
Need to hold a pv_lock while modifying them.


# 1.38 20-Mar-2019 ryo

spinkle __printflike(), and use PRIxxx


# 1.37 19-Mar-2019 ryo

- add ddb command "machine ttbr" to dump MMU tables.
- tidy up descriptions, usages and messages.


# 1.36 19-Mar-2019 ryo

- free L1-L3 pages that has been emptied by pmap_remove().
- if no memories, pmap_enter will return correctly ENOMEM if PMAP_CANFAIL, or wait until available any memories if !PMAP_CANFAIL.

These changes improves the stability when we use a huge virtual memory spaces with mmap.


# 1.35 06-Feb-2019 ryo

improve pmap_remove
- don't lock/unlock per page in pmap_remove()
- speedup pte lookup for continuous addresses
- bring out pool_cache_put(&_pmap_pv_pool, pv) from lock/unlock section


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226
# 1.34 21-Dec-2018 ryo

- add workaround for Cavium ThunderX errata 27456.
- add cpufuncs table in cpu_info. each cpu clusters may have different erratum. (e.g. big.LITTLE)


Revision tags: pgoyette-compat-1126
# 1.33 01-Nov-2018 maxv

Add kASan support for aarch64. Stack tracking needs more investigation
and will come in a separate commit.

Reviewed by ryo@ jmcneill@ skrll@.


# 1.32 31-Oct-2018 ryo

invalidate icache correctly.
l3pte_executable() should be used for only valid pte.


Revision tags: pgoyette-compat-1020
# 1.31 18-Oct-2018 skrll

Provide generic start code that assumes the MMU is off and caches are
disabled as per the linux booting protocol for ARMv6 and ARMv7 boards.
u-boot image type should be changed to 'linux' for correct behaviour.

The new start code builds a minimal "bootstrap" L1PT with cached access
disabled and uses the same table for all processors. AP startup is
performed in less steps and more code is written in C.

The bootstrap tables and stack are placed into an (orphaned) section
"_init_memory" which is given to uvm when it is no longer used.

Various kernels have been converted to use this code and tested. Some
boards were provided by TNF. Thanks!

The GENERIC kernel now boots on boards using the TEGRA, SUNXI and EXYNOS
kernels. The GENERIC kernel will also work on RPI2 using u-boot.

Thanks to martin@ and aymeric@ for testing on parallella and nanosoc
respectively


# 1.30 14-Oct-2018 skrll

Use __nothing


# 1.29 12-Oct-2018 ryo

add initial support of COMPAT_NETBSD32 on AArch64.
arm ELF32 EABI binaries could be execute in AArch32 state on AArch64. A32 THUMB mode is not supported yet.


# 1.28 12-Oct-2018 ryo

- cleanup checking address ranges with IN_RANGE macro
- change PM_ADDR_CHECK macro to KASSERTMSG
- restore fast lookup cases with IN_RANGE macro for pmap_extract changed in my previous commit.


# 1.27 12-Oct-2018 ryo

rewrite pmap_pte_lookup() to share similar code.


# 1.26 04-Oct-2018 ryo

cleanup locore, and changed the way to map memories during boot.
- add functions bootpage_enter() and bootpage_alloc() to adapt various layout
of physical memory map. especially for 64bit physical memory layout.
pmapboot_alloc() allocates pagetable pages from _end[].
- changed to map only the required amount for PA=VA identity mapping
(kernel image, UART device, and FDT blob) with L2_BLOCK(2Mbyte).
- changing page permission for kernel image, and making KSEG mapping are done
at cpu_kernel_vm_init() instead of at locore.
- optimize PTE entries with PTE Contiguous bit. it is enabled on devmap only for now.

reviewed by skrll@, thanks.


# 1.25 04-Oct-2018 ryo

* define LX_BLKPAG_{OS,ATTR}_* for OS dependent PTE attributes in pmap.h
* cleanup macros


Revision tags: pgoyette-compat-0930
# 1.24 17-Sep-2018 ryo

delete debug printf and KASSERT.


# 1.23 10-Sep-2018 maxv

Replace KDASSERT by panic.


# 1.22 10-Sep-2018 maxv

Rename _pmap_alloc_pdp -> pmap_alloc_pdp, and make it public.


# 1.21 10-Sep-2018 ryo

cleanup aarch64 mpstart and fdt bootstrap
* arm_cpu_hatch_arg is a bad idea. avoid serializing CPU startup, and eliminate arm_cpu_hatch_arg.
in mpstart, resolve own cpu index using array of cpu_mpidr[] (aarch64)
* add support fdt enable-method "spin-table"
* add support fdt enable-method "brcm,bcm2836-smp" (for 32bit RaspberryPi)
* use arm_fdt_cpu_bootstrap() instead of psci_fdt_bootstrap()
* rename "arm/fdt/psci_fdt.h" to "arm/fdt/psci_fdtvar.h" because of conflict of include file for needs-flag
* add devmap for cpu spin-table of raspberrypi3/aarch64
* no need to force hatch APs for raspberrypi3/arm32 ifndef MULTIPROCESSOR.
* fix to work pmap_extract(kerneltext/data/bss) even if before calling pmap_bootstrap

idea to use cpu_mpidr[] by jmcneill@. reviewd by skrll@. thanks.


Revision tags: pgoyette-compat-0906
# 1.20 27-Aug-2018 ryo

need to add VM_PROT_READ when pmap_kenter_pa(va, pa, VM_PROT_WRITE, 0) or pmap_kenter_pa(va, pa, VM_PROT_EXECUTE, 0).
VM_PROT_READ is treated as an access permission inernally.


# 1.19 11-Aug-2018 ryo

change to minimum invalidation of TLB.
specifying not only va but also asid, and not invalidate L0-L2 entry using tlbi_*_ll() if needed.


# 1.18 10-Aug-2018 ryo

treat kernel-exec attr and user-exec attr separately.
kernel cannot execute userland exec page, and user cannot execute kernel page.


# 1.17 06-Aug-2018 ryo

set kernel text/rodata readonly by default.
add function db_write_text() for setting ddb breakpoint.


# 1.16 31-Jul-2018 skrll

Define and use VPRINTF


Revision tags: pgoyette-compat-0728
# 1.15 27-Jul-2018 ryo

changes of pmap.c r1.13 seems to be unstable.
In order to invalidate icache, not to invalidate all icache,
but temporary to make the page writable and invalidate target address only.


# 1.14 24-Jul-2018 ryo

don't call pool_cache_put with locking pmap. pool_cache_put call pmap_kenter_pa internally.
(pool_cache_put_paddr -> pool_cache_put_slow -> pool_get -> pmap_kenter_pa)


# 1.13 23-Jul-2018 ryo

* fix icache invalidations.
* "ic ivau" (aarch64_icache_sync_range) with VA generates permission fault in some situations, therefore use KSEG address for now.


# 1.12 23-Jul-2018 ryo

rather than using flags to resolve nested locks, reserve pool_cache before locking.


# 1.11 21-Jul-2018 ryo

* avoid deadlock. mutex_owned() works only for adaptive lock, therefore we cannot use it for spinlock...
* add more NULL check
* clear pte when pmap_enter() fails


# 1.10 17-Jul-2018 ryo

Use __debugused


# 1.9 17-Jul-2018 christos

Add missing casts, remove unused variables.


# 1.8 09-Jul-2018 ryo

need locks in pmap_kremove() and pmap_fault_fixup()


Revision tags: phil-wifi-base pgoyette-compat-0625 pgoyette-compat-0521
# 1.7 20-May-2018 ryo

branches: 1.7.2;
pmap_enter() must update modified/referenced flags by 'flags' not 'prot'.


# 1.6 16-May-2018 ryo

Fix memory leak. it was leaking one page every pmap_create().
pm->pm_vmlist must be initialized before calling _pmap_alloc_pdp().


Revision tags: pgoyette-compat-0502
# 1.5 29-Apr-2018 ryo

fix KASSERT panic. pv_entry may not be exists in pvlist when pmap_remove().


# 1.4 29-Apr-2018 ryo

delete unused code


# 1.3 27-Apr-2018 ryo

fix instability behavior of bufcache on aarch64.
* fix to return correct ref/mod when PMAP_WIRED.
* changed to keep wired flags in pte instead of pv_entry, and cleanup.


Revision tags: pgoyette-compat-0422 pgoyette-compat-0415 pgoyette-compat-0407
# 1.2 01-Apr-2018 ryo

Add initial support for ARMv8 (AARCH64) (by nisimura@ and ryo@)

- sys/arch/evbarm64 is gone and integrated into sys/arch/evbarm. (by skrll@)
- add support fdt. evbarm/conf/GENERIC64 fdt (bcm2837,sunxi,tegra) based generic 64bit kernel config. (by skrll@, jmcneill@)


Revision tags: netbsd-8-2-RELEASE netbsd-8-1-RELEASE netbsd-8-1-RC1 netbsd-7-2-RELEASE netbsd-8-0-RELEASE netbsd-8-0-RC2 netbsd-8-0-RC1 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 netbsd-7-1-2-RELEASE pgoyette-compat-base netbsd-7-1-1-RELEASE tls-maxphys-base-20171202 matt-nb8-mediatek-base nick-nhusb-base-20170825 perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base pgoyette-localcount-20170320 netbsd-7-1-RELEASE netbsd-7-1-RC2 nick-nhusb-base-20170204 netbsd-7-nhusb-base-20170116 bouyer-socketcan-base pgoyette-localcount-20170107 netbsd-7-1-RC1 nick-nhusb-base-20161204 pgoyette-localcount-20161104 netbsd-7-0-2-RELEASE nick-nhusb-base-20161004 localcount-20160914 netbsd-7-nhusb-base pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907 nick-nhusb-base-20160529 netbsd-7-0-1-RELEASE nick-nhusb-base-20160422 nick-nhusb-base-20160319 nick-nhusb-base-20151226 netbsd-7-0-RELEASE nick-nhusb-base-20150921 netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 nick-nhusb-base-20150606 nick-nhusb-base-20150406 nick-nhusb-base tls-maxphys-base netbsd-7-base
# 1.1 10-Aug-2014 matt

branches: 1.1.4; 1.1.28;
Preliminary files for AARCH64 (64-bit ARM) support.
Enough for a distribution build.


# 1.147 30-Oct-2022 riastradh

aarch64/pmap: Fix criterion in previous.

Use the pte bit that says whether this is a PMAP_WIRED page, not the
bit that says whether this is a non-global page.

(Forgot to git commit --amend before exporting to CVS, sorry!)


# 1.146 30-Oct-2022 riastradh

aarch64/pmap(9): Teach pmap_protect about pmap_kenter_pa mappings.

Pages mapped with pmap_kenter_pa are necessarily unmanaged, so there
are no P->V records, and pmap_kenter_pa leaves pp->pp_pv.pv_va zero
with no modified/referenced state.

However, pmap_protect erroneously examined pp->pp_pv.pv_va to
ascertain the modified/referenced state -- and if the page was not
marked referenced, pmap_protect would clear the LX_BLKPAG_AF bit
(Access Flag), with the effect that subsequent uses of the page fault
and require a detour through pmap_fault_fixup.

This caused problems for the kernel module loader:

- When loading the text section, kobj_load first allocates kva with
uvm_km_alloc(UVM_KMF_WIRED|UVM_KMF_EXEC), which creates ptes with
pmap_kenter_pa. These ptes are writable, so we can copy the text
section into them, and have LX_BLKPAG_AF set so there will be no
fault when they are used by the kernel.

- But then kobj_affix makes the text section read/execute-only (and
nonwritable) with uvm_km_protect(VM_PROT_READ|VM_PROT_EXECUTE),
which updates the ptes with pmap_protect. This _should_ leave
LX_BLKPAG_AF set, but by inadvertently treating the page as managed
when it should be unmanaged, pmap_protect cleared it instead.

- Most of the time, clearing LX_BLKPAG_AF caused no problem, because
pmap_fault_fixup would silently resolve it. But if a hard
interrupt handler tried to use any page in the module's text (or
rodata, I suspect) that was not yet fixed up, the CPU would fault
and enter pmap_fault_fixup -- which would promptly crash (or hang)
by trying to take the pmap lock in interrupt context, which is
forbidden.

I observed this by loading dtrace.kmod early at boot and trying to
dtrace hard interrupt handlers.

With this change, pmap_protect now recognizes wired mappings (as
created by pmap_kenter_pa) before consulting pp->pp_pv.pv_va, and
preserves then LX_BLKPAG_AF bit in that case.

ok skrll


# 1.145 29-Oct-2022 skrll

fix a spello in a comment


# 1.144 28-Oct-2022 skrll

Remove some empty lines


# 1.143 23-Oct-2022 skrll

Use UVMHIST_CALLARGS in pmap_bootstrap


# 1.142 23-Oct-2022 skrll

Only define the EFI variable if EFI_RUNTIME


# 1.141 20-Oct-2022 skrll

KNF


# 1.140 15-Oct-2022 jmcneill

Use "non-posted" instead of "strongly ordered" to describe nGnRnE mappings

Rename the following defines:
- _ARM_BUS_SPACE_MAP_STRONGLY_ORDERED to BUS_SPACE_MAP_NONPOSTED
- PMAP_DEV_SO to PMAP_DEV_NP
- LX_BLKPAG_ATTR_DEVICE_MEM_SO to LX_BLKPAG_ATTR_DEVICE_MEM_NP
Rename the following option:
- AARCH64_DEVICE_MEM_STRONGLY_ORDERED to AARCH64_DEVICE_MEM_NONPOSTED


Revision tags: bouyer-sunxi-drm-base
# 1.139 19-Aug-2022 ryo

Fixed a bug that pte's __BIT(63,48) could be set when accessing addresses above 0x0001000000000000 in /dev/mem with mmap().


# 1.138 19-Aug-2022 ryo

When accessed in mmap by the device pager, pmap_enter() may be called with prot == PROT_WRITE.


# 1.137 03-May-2022 skrll

Sprinkle some KASSERT(kpreempt_disabled());


# 1.136 27-Apr-2022 ryo

since pmap_activate_efirt() rewrites TTBR0, it is necessary to pmap_activate() again after pmap_deactivate_efirt() to restore the original TTBR0.

- Fix to do pmap_{de,}activate() before/after pmap_{,de}activate_efirt().
- moved kpreempt_{disable,enable}() to the caller since everything between
arm_efirt_md_enter() and arm_efirt_md_exit() should be kpreempt disabled.

ok skrll@


# 1.135 17-Apr-2022 skrll

Add the missing kpreempt_enable to pmap_deactivate_efirt


# 1.134 10-Apr-2022 skrll

No need to flush icache for EFI RT mappings as bootaa64.efi flushed
the full icache for us. (Also this avoids traps)


# 1.133 09-Apr-2022 riastradh

sys: Use membar_release/acquire around reference drop.

This just goes through my recent reference count membar audit and
changes membar_exit to membar_release and membar_enter to
membar_acquire -- this should make everything cheaper on most CPUs
without hurting correctness, because membar_acquire is generally
cheaper than membar_enter.


# 1.132 02-Apr-2022 skrll

Update to support EFI runtime outside the kernel virtual address space
by creating an EFI RT pmap that can be activated / deactivated when
required.

Adds support for EFI RT to ARM_MMU_EXTENDED (ASID) 32-bit Arm machines.

On Arm64 the usage of pmapboot_enter is reduced and the mappings are
created much later in the boot process -- now in cpu_startup_hook.
Backward compatiblity for KVA mapped RT from old bootaa64.efi is
maintained.

Adding support to other platforms should be easier as a result.


# 1.131 19-Mar-2022 skrll

Slight code re-organisation. NFCI.


# 1.130 12-Mar-2022 riastradh

sys: Membar audit around reference count releases.

If two threads are using an object that is freed when the reference
count goes to zero, we need to ensure that all memory operations
related to the object happen before freeing the object.

Using an atomic_dec_uint_nv(&refcnt) == 0 ensures that only one
thread takes responsibility for freeing, but it's not enough to
ensure that the other thread's memory operations happen before the
freeing.

Consider:

Thread A Thread B
obj->foo = 42; obj->baz = 73;
mumble(&obj->bar); grumble(&obj->quux);
/* membar_exit(); */ /* membar_exit(); */
atomic_dec -- not last atomic_dec -- last
/* membar_enter(); */
KASSERT(invariant(obj->foo,
obj->bar));
free_stuff(obj);

The memory barriers ensure that

obj->foo = 42;
mumble(&obj->bar);

in thread A happens before

KASSERT(invariant(obj->foo, obj->bar));
free_stuff(obj);

in thread B. Without them, this ordering is not guaranteed.

So in general it is necessary to do

membar_exit();
if (atomic_dec_uint_nv(&obj->refcnt) != 0)
return;
membar_enter();

to release a reference, for the `last one out hit the lights' style
of reference counting. (This is in contrast to the style where one
thread blocks new references and then waits under a lock for existing
ones to drain with a condvar -- no membar needed thanks to mutex(9).)

I searched for atomic_dec to find all these. Obviously we ought to
have a better abstraction for this because there's so much copypasta.
This is a stop-gap measure to fix actual bugs until we have that. It
would be nice if an abstraction could gracefully handle the different
styles of reference counting in use -- some years ago I drafted an
API for this, but making it cover everything got a little out of hand
(particularly with struct vnode::v_usecount) and I ended up setting
it aside to work on psref/localcount instead for better scalability.

I got bored of adding #ifdef __HAVE_ATOMIC_AS_MEMBAR everywhere, so I
only put it on things that look performance-critical on 5sec review.
We should really adopt membar_enter_preatomic/membar_exit_postatomic
or something (except they are applicable only to atomic r/m/w, not to
atomic_load/store_*, making the naming annoying) and get rid of all
the ifdefs.


# 1.129 05-Mar-2022 skrll

Slight comment improvement.


# 1.128 16-Feb-2022 andvar

fix various typos, mainly in comments.


# 1.127 31-Jan-2022 ryo

add support Hardware updates to Access flag and Dirty state (FEAT_HAFDBS)

- The DBM bit of the PTE is now used to determine if it is writable, and
the AF bit is treated entirely as a reference bit. A valid PTE is always
treated as readable. There can be no valid PTE that is not readable.
- LX_BLKPAG_OS_{READ,WRITE} are used only for debugging purposes,
and has been superseded by LX_BLKPAG_AF and LX_BLKPAG_DBM.
- Improve comment

The need for reference/modify emulation has been eliminated,
and access/permission faults have been reduced, however,
there has been little change in overall performance.


# 1.126 31-Jan-2022 ryo

Skip unnecessary PTE operations and TLB invalidation.


# 1.125 16-Jan-2022 rillig

aarch64/pmap: remove stray semicolon

No binary change.


# 1.124 15-Jan-2022 skrll

The translations that need invalidation are always last level so remove
the (dubious) logic around tracking the level. The "any level" TLB
invalidation maintenance operation are used, but this may change after
further testing.

before
======
1661.0u 420.2s 2:53.82 1197.3% 231+29k 10+33918io 102pf+0w
1646.8u 425.2s 2:52.96 1198.0% 232+29k 1+33937io 49pf+0w
1647.9u 425.7s 2:52.58 1201.6% 232+29k 0+33940io 32pf+0w

After
=====
1602.5u 420.8s 2:49.09 1196.6% 238+30k 24+33893io 54pf+0w
1600.7u 421.3s 2:51.53 1178.8% 238+30k 1+33914io 33pf+0w
1597.5u 424.3s 2:50.46 1186.1% 238+30k 0+33915io 17pf+0w

LGTM from ryo@


# 1.123 14-Jan-2022 skrll

Restore the previous pmap_remove_all behaviour as the new method meant
the n1sdp couldn't complete a build.

No noticeable change in kernel build performance.


# 1.122 04-Jan-2022 skrll

KNF


# 1.121 10-Dec-2021 andvar

s/occured/occurred/ in comments, log messages and man pages.


# 1.120 07-Dec-2021 andvar

fix various typos, mainly in comments.


# 1.119 23-Oct-2021 skrll

Fix non-UVMHIST build


# 1.118 16-Oct-2021 ryo

fix non-MULTIPROCESSOR build


# 1.117 10-Oct-2021 skrll

Use sys/uvm/pmap/pmap_tlb.c on Aarch64 in the same way that some Arm, MIPS,
and some PPC kernels do. This removes the limitation of 256 processes on
CPUs with 8bit ASID field, e.g. Apple M1.

Additionally the following changes have been made

- removed a couple of unnecessary aarch64_tlbi_all calls
- removed any invalidation after freeing page tables due to
_pmap_sweep_pdp. This was never necessary afaict.
- all kernel mappings are marked global and userland mapping not-global.

Performance testing hasn't show a significant difference. The data here
is from building a kernel on an lx2k system with nvme.

before
1489.6u 400.4s 2:40.65 1176.5% 228+224k 0+32289io 57pf+0w
1482.6u 403.2s 2:38.49 1189.9% 228+222k 0+32274io 46pf+0w
1485.4u 402.2s 2:37.27 1200.2% 228+222k 0+32275io 12pf+0w

after
1493.9u 404.6s 2:37.50 1205.4% 227+221k 0+32265io 48pf+0w
1485.0u 408.0s 2:38.54 1194.0% 227+222k 0+32272io 36pf+0w
1484.3u 407.0s 2:35.88 1213.3% 228+224k 0+32268io 14pf+0w

>>> stats.ttest_ind([160.65,158.49,157.27], [157.5,158.54,155.88])
Ttest_indResult(statistic=1.1923622711296888, pvalue=0.2990182944606766)
>>>


# 1.116 30-Sep-2021 skrll

Ensure TCR_EPD0 is set on entry to pmap_activate and ensure it is set as
early as possible for APs.


# 1.115 26-Sep-2021 skrll

Use UVMHIST_CALLARGS


# 1.114 26-Sep-2021 skrll

'\n' is not required in KASSERTMSG either.


# 1.113 26-Sep-2021 skrll

"\n" is not required in KERNHIST


# 1.112 15-Sep-2021 skrll

Use __SHIFTIN. Same code before and after.


# 1.111 12-Sep-2021 skrll

pmap_page_remove: simply and reduce the code size slightly.


# 1.110 09-Sep-2021 skrll

In pmap_icache_sync_range change

for (...) {
...
if (condition) {
// do stuff
}
}

to

for (...) {
...
if (!conditional)
continue;
// do stuff
}

to save on indentation. Same code (modulo register usage) before and
after.


# 1.109 09-Sep-2021 skrll

KNF


Revision tags: thorpej-i2c-spi-conf2-base thorpej-futex2-base thorpej-cfargs2-base cjep_sun2x-base1 cjep_sun2x-base cjep_staticlib_x-base1 thorpej-i2c-spi-conf-base
# 1.108 29-May-2021 skrll

Deal with the pmap limitation of maxproc in a more complete way and
recognise CPUs with only 8bit ASIDs.


Revision tags: cjep_staticlib_x-base
# 1.107 30-Apr-2021 skrll

branches: 1.107.2;
Make the ddb for pmap / pte information pmap agnostic


# 1.106 29-Apr-2021 skrll

Remove some unnecessary tlb invalidate in pmap_growkernel and ASAN shadow
map. Ensure the shadow map mappings are visible to the TLB walkers.


# 1.105 21-Apr-2021 ryo

branches: 1.105.2;
added more attributes of PTE displayed by "ddb>machine pte"


Revision tags: thorpej-cfargs-base
# 1.104 17-Apr-2021 mrg

remove KERNHIST_INIT_STATIC(). it stradles the line between usable
early in boot and broken early in boot by requiring a partly static
structure with another structure that must be present by the time
any uses are performed. theoretically platform code could allocate
a chunk while seting up memory and assign it here, giving a dynamic
sizing for the entry list, but the reality is that all users have
a statically allocated entry list as well.

the existing KERNHIST_LINK_STATIC() is used in conjunction with
KERNHIST_INITIALIZER() instead.

this stops a NULL pointer deref when the _LOG() macro is called
before the storage is linked in, which happens with GCC 10 on OCTEON
with UVMHIST enabled, crashing in very early kernel init.


Revision tags: thorpej-futex-base
# 1.103 09-Mar-2021 ryo

branches: 1.103.2;
fix build error without options DDB.

kvtopte() is referenced from arm/acpi/acpi_machdep.c


# 1.102 13-Feb-2021 ryo

No assignment is needed here.

the loop in pmap_page_remove() always removes the first pv,
and since the list is managed by _pmap_remove_pv(), pp->pp_pv.pv_next always points to the first.


# 1.101 01-Feb-2021 ryo

It is enough to make a page accessible instead of writable.
same fix as r1.76


# 1.100 31-Jan-2021 ryo

implement pmap_remove_all().

The size of struct pv_entry has increased, but speed of kernel build has improved by about 1%
exec and exit should have been improved.


# 1.99 20-Dec-2020 skrll

Improve the English in the previous comment fix.


# 1.98 19-Dec-2020 skrll

Tweak a comment


# 1.97 11-Dec-2020 skrll

s:aarch64/cpufunc.h:arm/cpufunc.h:

a baby step in the grand arm header unification challenge


# 1.96 10-Nov-2020 skrll

AA64 is not MIPS.

Change all KSEG references to directmap


# 1.95 07-Nov-2020 skrll

In pmap_devmap_bootstrap only set pmap_devmap_bootstrap_done if there
is an entry and ALL of the entries have been done. The entry required
for EARLYCONS might not be the first/only one...


# 1.94 01-Nov-2020 jmcneill

branches: 1.94.2;
No need to disable translation table walks in pmap_activate().


# 1.93 22-Oct-2020 skrll

Use the isb macro - missed in previous commit


# 1.92 22-Oct-2020 skrll

Use the dmb/dsb/isb macros... if nothing else they're all now consistent
about the "memory" assembler contraint.

No binary change


# 1.91 28-Sep-2020 skrll

Only set pmap_devmap_bootstrap_done if something gets mapped.

Think acpi_platform_devmap


# 1.90 19-Sep-2020 skrll

Make __md_palloc pmap agnostic (think sys/uvm/pmap)


# 1.89 14-Sep-2020 ryo

PID_MAX is just an initial value (soft maximum). Don't use it for CTASSERT.
defined __HAVE_CPU_MAXPROC to use function cpu_maxproc().

pointed out by mrg@, thanks.


# 1.88 06-Sep-2020 ryo

Fix panic caused by modload. http://mail-index.netbsd.org/port-arm/2020/08/30/msg006960.html

The address space reserved for modules may not be mapped in L1-L3.


# 1.87 14-Aug-2020 skrll

Whitespace


# 1.86 12-Aug-2020 skrll

Part IV of ad's performance improvements for aarch64

- Implement pmap_growkernel(), and update kernel pmap's stats with atomics.

- Then, pmap_kenter_pa() and pmap_kremove() no longer need to allocate
memory nor take pm_lock, because they only modify L3 PTEs.

- Then, pm_lock and pp_lock can be adaptive mutexes at IPL_NONE which are
cheaper than spin mutexes.

- Take the pmap's lock in pmap_extract() if not the kernel's pmap, otherwise
pmap_extract() might see inconsistent state.


# 1.85 09-Aug-2020 skrll

Fix another UVMHIST so it doesn't use %s


# 1.84 16-Jul-2020 skrll

pmapboot_enter simplication
- bootpage_alloc in asm becomes pmapboot_pagealloc in C
- PMAPBOOT_ENTER_NOBLOCK is removed as it's not used
- PMAPBOOT_ENTER_NOOVERWRITE is removed as it's now always on
- physpage_allocator argument is removed as it's always
pmapboot_pagealloc
- Support for EARLYCONS without CONSADDR is removed so that the identity
map for CONSADDR is always known.

For the assembly files:
2 files changed, 40 insertions(+), 89 deletions(-)

LGTM ryo


# 1.83 04-Jul-2020 rin

Use tlen for temporary length variable instead of l, which is usually
used for struct lwp *.

No binary changes.


# 1.82 02-Jul-2020 rin

pmap_procwr(): sync icache even if p != curproc. This fixes applications
like GDB for arm32, that rewrite text of other process.

Thanks to ryo@ for discussion.


# 1.81 02-Jul-2020 rin

Set uvmexp.ncolors appropriately, which is required for some CPU
models with VIPT icache.

Otherwise, alias in virtual address results in inconsistent results,
at least for applications that rewrite text of other process, e.g.,
GDB for arm32.

Also, this hopefully fixes other unexpected failures due to alias.

Confirmed that there's no observable regression in performance;
difference in ``time make -j8'' for GENERIC64 kernel on BCM2837
with and without setting uvmexp.ncolors is within 0.1%.

Thanks to ryo@ for discussion.


# 1.80 27-Jun-2020 rin

Fix typo in name of evcnt(4) counter.


# 1.79 24-Jun-2020 ryo

Fix bug with incorrect range calculation when doing icache sync.
This is called by sysarch(ARM_SYNC_ICACHE) from aarch32 (compat_netbsd32) emul process.

pointed out by rin@, thanks.

XXX pullup-9


# 1.78 14-Jun-2020 ad

- Fix a lock order reversal in pmap_page_protect().

- Make sure pmap is always locked when updating stats; atomics no longer
needed to do that.

- Remove unneeded traversal of pv list in pmap_enter_pv().

- Shrink struct vm_page from 136 to 128 bytes (cache line sized) and struct
pv_entry from 48 to 32 bytes (power of 2 sized).

- Embed a pv_entry in each vm_page. This means PV entries don't need to
be allocated for private anonymous memory / COW pages / most UBC mappings.
Dynamic PV entries are then used only for stuff like shared libraries and
shared memory.

Proposed on port-arm@.


# 1.77 10-Jun-2020 ad

- Wired/resident stats shouldn't covered by PMAPCOUNTERS.
- Rename need_update_pv -> need_enter_pv.

Ok ryo@


# 1.76 01-Jun-2020 ryo

no need to make the PTE writable to do icache_sync, enough to accessible.


# 1.75 15-May-2020 skrll

Use __diagused


# 1.74 15-May-2020 tnn

fix non-diag build


# 1.73 14-May-2020 skrll

Use MUTEX_NODEBUG for PV locks as is commonly done. OK ryo.


# 1.72 13-May-2020 jmcneill

Implement pmap_extract_coherency


Revision tags: bouyer-xenpvh-base2 phil-wifi-20200421 bouyer-xenpvh-base1
# 1.71 18-Apr-2020 skrll

PMAP_DEBUG has been deleted on arm


# 1.70 13-Apr-2020 maxv

Add support for Branch Target Identification (BTI).

On the executable pages that have the GP (Guarded Page) bit, the semantic
of the "br" and "blr" instructions is changed: the CPU expects the first
instruction of the jump/call target to be "bti", and faults if it isn't.

We add the GP bit on the kernel .text pages (and incidentally the .rodata
pages, but we don't care). The compiler adds a "bti c" instruction at the
beginning of each C function. We modify the ENTRY() macros to manually add
"bti c" in the asm functions.

cpuswitch.S needs a specific change: with "br x27" the CPU expects "bti j",
which is bad because the functions begin with "bti c"; switch to "br x16",
for the CPU to accept "bti c".

BTI helps defend against JOP/COP. Tested on Qemu.


Revision tags: phil-wifi-20200411 bouyer-xenpvh-base
# 1.69 08-Apr-2020 ryo

branches: 1.69.2;
use PMAP_PAGE_INIT() to initialize mutex in pmap_page.

VM_MDPAGE_INIT() in pmap_free_pdp() had initialized pp_flags,
so it unintentionally cleared PMAP_PAGE_FLAGS_PV_TRACKED.
use PMAP_PAGE_INIT to avoid using PMAP_PAGE_FLAGS_PV_TRACKED.

pointed out by tnn@, thanks


Revision tags: phil-wifi-20200406
# 1.68 14-Mar-2020 ad

pmap_remove_all(): Return a boolean value to indicate the behaviour. If
true, all mappings have been removed, the pmap is totally cleared out, and
UVM can then avoid doing the work to call pmap_remove() for each map entry.
If false, either nothing has been done, or some helpful arch-specific voodoo
has taken place.


Revision tags: is-mlppp-base
# 1.67 02-Mar-2020 ryo

oops, fix incorrect usage of daif_enable() in my previous commit.


# 1.66 29-Feb-2020 ryo

Fix pmap to work correctly with tagged addresses

- when fault, untag from address before passing to uvm/pmap functions
- pmap_extract() checks more strictly and consider the address tag


# 1.65 29-Feb-2020 ryo

use pmapboot_enter_range()


Revision tags: ad-namecache-base3
# 1.64 10-Feb-2020 ryo

use LIST(3) instead of TAILQ(3) to save one word in struct vm_page and struct pmap.

pointed out by riastradh@. thanks


# 1.63 03-Feb-2020 ryo

add support pmap_pv(9)

Patch originally from jmcneill@. thanks


# 1.62 03-Feb-2020 ryo

separate struct vm_page_md into vm_page_md and pmap_page
for preparation pmap_pv(9)


Revision tags: ad-namecache-base2 ad-namecache-base1
# 1.61 09-Jan-2020 ryo

fix behaviour mmap()/mprotect() when passed only PROT_EXEC.

when mmap()/mprotect() with only PROT_EXEC, syscall will be successful,
but the page actually hadn't been mapped.
it should be mapped with PROT_READ|PROT_EXEC implicitly. (r-x)


Revision tags: ad-namecache-base
# 1.60 30-Dec-2019 skrll

branches: 1.60.2;
Update pmap_map_chunk to allow L[12] block mappings and L3 page mappings


# 1.59 30-Dec-2019 skrll

Remove unnecessary brackets and unwrap a conditional. Same code before
and after.


# 1.58 28-Dec-2019 jmcneill

Do not use Early Write Acknowledge for PCIe I/O and config space.


# 1.57 27-Dec-2019 jmcneill

Enable early write acknowledge for device memory mappings.


# 1.56 19-Dec-2019 skrll

G/C kasan_shadow_map call in pmap_enter

pmap_growkernel calls kasan_shadow_map for KVA


# 1.55 18-Dec-2019 ryo

atomic_add_16() is not used in pmap.c anymore. no need decl here.


# 1.54 18-Dec-2019 ryo

space to tab


# 1.53 14-Dec-2019 skrll

Fix build... wire_count probably doesn't need atomics


# 1.52 13-Dec-2019 skrll

Fix KASAN support by calling kasan_shadow_map in pmap_growkernel


# 1.51 10-Dec-2019 ad

pg->phys_addr -> VM_PAGE_TO_PHYS(pg)


Revision tags: phil-wifi-20191119
# 1.50 14-Nov-2019 maxv

Mark several kASan functions with __nothing, to avoid annoying #ifdefs.
Same as kCSan and kMSan.


# 1.49 14-Nov-2019 maxv

Don't include "opt_kasan.h" when there's already <sys/asan.h> included.


# 1.48 29-Oct-2019 maya

Define PMAP_NEED_PROCWR, providing strategically placed i-cache
synchronization where just-changed memory is about to be executed.

Fixes SIGILLs seen when running Mono 6 on QEMU Cortex-A57.

ok ryo


# 1.47 22-Sep-2019 jmcneill

Disable translation table walks using TTBR0 while changing its value and
when deactivating a pmap. Fixes stability issues on Ampere eMAG CPUs.


# 1.46 20-Sep-2019 ryo

ref/mod bit should be set according to 'flags' argument, not 'prot'. r1.44 was incomplete.


# 1.45 13-Sep-2019 ryo

In pmap_devmap_bootstrap(), cpu_earlydevice_va_p() must not return true until *all* devmap tables have been enabled.
console mapping may be present in the last table.


# 1.44 07-Sep-2019 ryo

- remove incorrect KASSERT. mmap(2) with prot=PROT_WRITE calls pmap_enter(..., PROT_WRITE) internally.
- fix to update page reference flags when only PROT_WRITE or PROT_EXECUTE specified


# 1.43 15-Aug-2019 skrll

Make pmap_db_pte_print more terse so it's quicker on serial consoles


# 1.42 12-Aug-2019 skrll

Use PMAP_DEV in DEVMAP_ENTRY rather than pmap_map_chunk. It's clearer and
means pmap_map_chunk can be made to map other memory types.


Revision tags: netbsd-9-base phil-wifi-20190609
# 1.41 17-May-2019 mrg

branches: 1.41.2;
apply some __diagused.


Revision tags: isaki-audio2-base
# 1.40 08-Apr-2019 ryo

- free empty page tables pages if reach a certain usage.
- need to lock at removing an old pg (_pmap_remove_pv) in _pmap_enter()


# 1.39 06-Apr-2019 ryo

Fix race conditions about pmap_page_protect() and pmap_enter().

while handling same PTE by these functions in same time, there
is a critical path that the number of valid PTEs and wire_count
are inconsistent, and it caused KASSERT.
Need to hold a pv_lock while modifying them.


# 1.38 20-Mar-2019 ryo

spinkle __printflike(), and use PRIxxx


# 1.37 19-Mar-2019 ryo

- add ddb command "machine ttbr" to dump MMU tables.
- tidy up descriptions, usages and messages.


# 1.36 19-Mar-2019 ryo

- free L1-L3 pages that has been emptied by pmap_remove().
- if no memories, pmap_enter will return correctly ENOMEM if PMAP_CANFAIL, or wait until available any memories if !PMAP_CANFAIL.

These changes improves the stability when we use a huge virtual memory spaces with mmap.


# 1.35 06-Feb-2019 ryo

improve pmap_remove
- don't lock/unlock per page in pmap_remove()
- speedup pte lookup for continuous addresses
- bring out pool_cache_put(&_pmap_pv_pool, pv) from lock/unlock section


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226
# 1.34 21-Dec-2018 ryo

- add workaround for Cavium ThunderX errata 27456.
- add cpufuncs table in cpu_info. each cpu clusters may have different erratum. (e.g. big.LITTLE)


Revision tags: pgoyette-compat-1126
# 1.33 01-Nov-2018 maxv

Add kASan support for aarch64. Stack tracking needs more investigation
and will come in a separate commit.

Reviewed by ryo@ jmcneill@ skrll@.


# 1.32 31-Oct-2018 ryo

invalidate icache correctly.
l3pte_executable() should be used for only valid pte.


Revision tags: pgoyette-compat-1020
# 1.31 18-Oct-2018 skrll

Provide generic start code that assumes the MMU is off and caches are
disabled as per the linux booting protocol for ARMv6 and ARMv7 boards.
u-boot image type should be changed to 'linux' for correct behaviour.

The new start code builds a minimal "bootstrap" L1PT with cached access
disabled and uses the same table for all processors. AP startup is
performed in less steps and more code is written in C.

The bootstrap tables and stack are placed into an (orphaned) section
"_init_memory" which is given to uvm when it is no longer used.

Various kernels have been converted to use this code and tested. Some
boards were provided by TNF. Thanks!

The GENERIC kernel now boots on boards using the TEGRA, SUNXI and EXYNOS
kernels. The GENERIC kernel will also work on RPI2 using u-boot.

Thanks to martin@ and aymeric@ for testing on parallella and nanosoc
respectively


# 1.30 14-Oct-2018 skrll

Use __nothing


# 1.29 12-Oct-2018 ryo

add initial support of COMPAT_NETBSD32 on AArch64.
arm ELF32 EABI binaries could be execute in AArch32 state on AArch64. A32 THUMB mode is not supported yet.


# 1.28 12-Oct-2018 ryo

- cleanup checking address ranges with IN_RANGE macro
- change PM_ADDR_CHECK macro to KASSERTMSG
- restore fast lookup cases with IN_RANGE macro for pmap_extract changed in my previous commit.


# 1.27 12-Oct-2018 ryo

rewrite pmap_pte_lookup() to share similar code.


# 1.26 04-Oct-2018 ryo

cleanup locore, and changed the way to map memories during boot.
- add functions bootpage_enter() and bootpage_alloc() to adapt various layout
of physical memory map. especially for 64bit physical memory layout.
pmapboot_alloc() allocates pagetable pages from _end[].
- changed to map only the required amount for PA=VA identity mapping
(kernel image, UART device, and FDT blob) with L2_BLOCK(2Mbyte).
- changing page permission for kernel image, and making KSEG mapping are done
at cpu_kernel_vm_init() instead of at locore.
- optimize PTE entries with PTE Contiguous bit. it is enabled on devmap only for now.

reviewed by skrll@, thanks.


# 1.25 04-Oct-2018 ryo

* define LX_BLKPAG_{OS,ATTR}_* for OS dependent PTE attributes in pmap.h
* cleanup macros


Revision tags: pgoyette-compat-0930
# 1.24 17-Sep-2018 ryo

delete debug printf and KASSERT.


# 1.23 10-Sep-2018 maxv

Replace KDASSERT by panic.


# 1.22 10-Sep-2018 maxv

Rename _pmap_alloc_pdp -> pmap_alloc_pdp, and make it public.


# 1.21 10-Sep-2018 ryo

cleanup aarch64 mpstart and fdt bootstrap
* arm_cpu_hatch_arg is a bad idea. avoid serializing CPU startup, and eliminate arm_cpu_hatch_arg.
in mpstart, resolve own cpu index using array of cpu_mpidr[] (aarch64)
* add support fdt enable-method "spin-table"
* add support fdt enable-method "brcm,bcm2836-smp" (for 32bit RaspberryPi)
* use arm_fdt_cpu_bootstrap() instead of psci_fdt_bootstrap()
* rename "arm/fdt/psci_fdt.h" to "arm/fdt/psci_fdtvar.h" because of conflict of include file for needs-flag
* add devmap for cpu spin-table of raspberrypi3/aarch64
* no need to force hatch APs for raspberrypi3/arm32 ifndef MULTIPROCESSOR.
* fix to work pmap_extract(kerneltext/data/bss) even if before calling pmap_bootstrap

idea to use cpu_mpidr[] by jmcneill@. reviewd by skrll@. thanks.


Revision tags: pgoyette-compat-0906
# 1.20 27-Aug-2018 ryo

need to add VM_PROT_READ when pmap_kenter_pa(va, pa, VM_PROT_WRITE, 0) or pmap_kenter_pa(va, pa, VM_PROT_EXECUTE, 0).
VM_PROT_READ is treated as an access permission inernally.


# 1.19 11-Aug-2018 ryo

change to minimum invalidation of TLB.
specifying not only va but also asid, and not invalidate L0-L2 entry using tlbi_*_ll() if needed.


# 1.18 10-Aug-2018 ryo

treat kernel-exec attr and user-exec attr separately.
kernel cannot execute userland exec page, and user cannot execute kernel page.


# 1.17 06-Aug-2018 ryo

set kernel text/rodata readonly by default.
add function db_write_text() for setting ddb breakpoint.


# 1.16 31-Jul-2018 skrll

Define and use VPRINTF


Revision tags: pgoyette-compat-0728
# 1.15 27-Jul-2018 ryo

changes of pmap.c r1.13 seems to be unstable.
In order to invalidate icache, not to invalidate all icache,
but temporary to make the page writable and invalidate target address only.


# 1.14 24-Jul-2018 ryo

don't call pool_cache_put with locking pmap. pool_cache_put call pmap_kenter_pa internally.
(pool_cache_put_paddr -> pool_cache_put_slow -> pool_get -> pmap_kenter_pa)


# 1.13 23-Jul-2018 ryo

* fix icache invalidations.
* "ic ivau" (aarch64_icache_sync_range) with VA generates permission fault in some situations, therefore use KSEG address for now.


# 1.12 23-Jul-2018 ryo

rather than using flags to resolve nested locks, reserve pool_cache before locking.


# 1.11 21-Jul-2018 ryo

* avoid deadlock. mutex_owned() works only for adaptive lock, therefore we cannot use it for spinlock...
* add more NULL check
* clear pte when pmap_enter() fails


# 1.10 17-Jul-2018 ryo

Use __debugused


# 1.9 17-Jul-2018 christos

Add missing casts, remove unused variables.


# 1.8 09-Jul-2018 ryo

need locks in pmap_kremove() and pmap_fault_fixup()


Revision tags: phil-wifi-base pgoyette-compat-0625 pgoyette-compat-0521
# 1.7 20-May-2018 ryo

branches: 1.7.2;
pmap_enter() must update modified/referenced flags by 'flags' not 'prot'.


# 1.6 16-May-2018 ryo

Fix memory leak. it was leaking one page every pmap_create().
pm->pm_vmlist must be initialized before calling _pmap_alloc_pdp().


Revision tags: pgoyette-compat-0502
# 1.5 29-Apr-2018 ryo

fix KASSERT panic. pv_entry may not be exists in pvlist when pmap_remove().


# 1.4 29-Apr-2018 ryo

delete unused code


# 1.3 27-Apr-2018 ryo

fix instability behavior of bufcache on aarch64.
* fix to return correct ref/mod when PMAP_WIRED.
* changed to keep wired flags in pte instead of pv_entry, and cleanup.


Revision tags: pgoyette-compat-0422 pgoyette-compat-0415 pgoyette-compat-0407
# 1.2 01-Apr-2018 ryo

Add initial support for ARMv8 (AARCH64) (by nisimura@ and ryo@)

- sys/arch/evbarm64 is gone and integrated into sys/arch/evbarm. (by skrll@)
- add support fdt. evbarm/conf/GENERIC64 fdt (bcm2837,sunxi,tegra) based generic 64bit kernel config. (by skrll@, jmcneill@)


Revision tags: netbsd-8-2-RELEASE netbsd-8-1-RELEASE netbsd-8-1-RC1 netbsd-7-2-RELEASE netbsd-8-0-RELEASE netbsd-8-0-RC2 netbsd-8-0-RC1 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 netbsd-7-1-2-RELEASE pgoyette-compat-base netbsd-7-1-1-RELEASE tls-maxphys-base-20171202 matt-nb8-mediatek-base nick-nhusb-base-20170825 perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base pgoyette-localcount-20170320 netbsd-7-1-RELEASE netbsd-7-1-RC2 nick-nhusb-base-20170204 netbsd-7-nhusb-base-20170116 bouyer-socketcan-base pgoyette-localcount-20170107 netbsd-7-1-RC1 nick-nhusb-base-20161204 pgoyette-localcount-20161104 netbsd-7-0-2-RELEASE nick-nhusb-base-20161004 localcount-20160914 netbsd-7-nhusb-base pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907 nick-nhusb-base-20160529 netbsd-7-0-1-RELEASE nick-nhusb-base-20160422 nick-nhusb-base-20160319 nick-nhusb-base-20151226 netbsd-7-0-RELEASE nick-nhusb-base-20150921 netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 nick-nhusb-base-20150606 nick-nhusb-base-20150406 nick-nhusb-base tls-maxphys-base netbsd-7-base
# 1.1 10-Aug-2014 matt

branches: 1.1.4; 1.1.28;
Preliminary files for AARCH64 (64-bit ARM) support.
Enough for a distribution build.


# 1.145 29-Oct-2022 skrll

fix a spello in a comment


# 1.144 28-Oct-2022 skrll

Remove some empty lines


# 1.143 23-Oct-2022 skrll

Use UVMHIST_CALLARGS in pmap_bootstrap


# 1.142 23-Oct-2022 skrll

Only define the EFI variable if EFI_RUNTIME


# 1.141 20-Oct-2022 skrll

KNF


# 1.140 15-Oct-2022 jmcneill

Use "non-posted" instead of "strongly ordered" to describe nGnRnE mappings

Rename the following defines:
- _ARM_BUS_SPACE_MAP_STRONGLY_ORDERED to BUS_SPACE_MAP_NONPOSTED
- PMAP_DEV_SO to PMAP_DEV_NP
- LX_BLKPAG_ATTR_DEVICE_MEM_SO to LX_BLKPAG_ATTR_DEVICE_MEM_NP
Rename the following option:
- AARCH64_DEVICE_MEM_STRONGLY_ORDERED to AARCH64_DEVICE_MEM_NONPOSTED


Revision tags: bouyer-sunxi-drm-base
# 1.139 19-Aug-2022 ryo

Fixed a bug that pte's __BIT(63,48) could be set when accessing addresses above 0x0001000000000000 in /dev/mem with mmap().


# 1.138 19-Aug-2022 ryo

When accessed in mmap by the device pager, pmap_enter() may be called with prot == PROT_WRITE.


# 1.137 03-May-2022 skrll

Sprinkle some KASSERT(kpreempt_disabled());


# 1.136 27-Apr-2022 ryo

since pmap_activate_efirt() rewrites TTBR0, it is necessary to pmap_activate() again after pmap_deactivate_efirt() to restore the original TTBR0.

- Fix to do pmap_{de,}activate() before/after pmap_{,de}activate_efirt().
- moved kpreempt_{disable,enable}() to the caller since everything between
arm_efirt_md_enter() and arm_efirt_md_exit() should be kpreempt disabled.

ok skrll@


# 1.135 17-Apr-2022 skrll

Add the missing kpreempt_enable to pmap_deactivate_efirt


# 1.134 10-Apr-2022 skrll

No need to flush icache for EFI RT mappings as bootaa64.efi flushed
the full icache for us. (Also this avoids traps)


# 1.133 09-Apr-2022 riastradh

sys: Use membar_release/acquire around reference drop.

This just goes through my recent reference count membar audit and
changes membar_exit to membar_release and membar_enter to
membar_acquire -- this should make everything cheaper on most CPUs
without hurting correctness, because membar_acquire is generally
cheaper than membar_enter.


# 1.132 02-Apr-2022 skrll

Update to support EFI runtime outside the kernel virtual address space
by creating an EFI RT pmap that can be activated / deactivated when
required.

Adds support for EFI RT to ARM_MMU_EXTENDED (ASID) 32-bit Arm machines.

On Arm64 the usage of pmapboot_enter is reduced and the mappings are
created much later in the boot process -- now in cpu_startup_hook.
Backward compatiblity for KVA mapped RT from old bootaa64.efi is
maintained.

Adding support to other platforms should be easier as a result.


# 1.131 19-Mar-2022 skrll

Slight code re-organisation. NFCI.


# 1.130 12-Mar-2022 riastradh

sys: Membar audit around reference count releases.

If two threads are using an object that is freed when the reference
count goes to zero, we need to ensure that all memory operations
related to the object happen before freeing the object.

Using an atomic_dec_uint_nv(&refcnt) == 0 ensures that only one
thread takes responsibility for freeing, but it's not enough to
ensure that the other thread's memory operations happen before the
freeing.

Consider:

Thread A Thread B
obj->foo = 42; obj->baz = 73;
mumble(&obj->bar); grumble(&obj->quux);
/* membar_exit(); */ /* membar_exit(); */
atomic_dec -- not last atomic_dec -- last
/* membar_enter(); */
KASSERT(invariant(obj->foo,
obj->bar));
free_stuff(obj);

The memory barriers ensure that

obj->foo = 42;
mumble(&obj->bar);

in thread A happens before

KASSERT(invariant(obj->foo, obj->bar));
free_stuff(obj);

in thread B. Without them, this ordering is not guaranteed.

So in general it is necessary to do

membar_exit();
if (atomic_dec_uint_nv(&obj->refcnt) != 0)
return;
membar_enter();

to release a reference, for the `last one out hit the lights' style
of reference counting. (This is in contrast to the style where one
thread blocks new references and then waits under a lock for existing
ones to drain with a condvar -- no membar needed thanks to mutex(9).)

I searched for atomic_dec to find all these. Obviously we ought to
have a better abstraction for this because there's so much copypasta.
This is a stop-gap measure to fix actual bugs until we have that. It
would be nice if an abstraction could gracefully handle the different
styles of reference counting in use -- some years ago I drafted an
API for this, but making it cover everything got a little out of hand
(particularly with struct vnode::v_usecount) and I ended up setting
it aside to work on psref/localcount instead for better scalability.

I got bored of adding #ifdef __HAVE_ATOMIC_AS_MEMBAR everywhere, so I
only put it on things that look performance-critical on 5sec review.
We should really adopt membar_enter_preatomic/membar_exit_postatomic
or something (except they are applicable only to atomic r/m/w, not to
atomic_load/store_*, making the naming annoying) and get rid of all
the ifdefs.


# 1.129 05-Mar-2022 skrll

Slight comment improvement.


# 1.128 16-Feb-2022 andvar

fix various typos, mainly in comments.


# 1.127 31-Jan-2022 ryo

add support Hardware updates to Access flag and Dirty state (FEAT_HAFDBS)

- The DBM bit of the PTE is now used to determine if it is writable, and
the AF bit is treated entirely as a reference bit. A valid PTE is always
treated as readable. There can be no valid PTE that is not readable.
- LX_BLKPAG_OS_{READ,WRITE} are used only for debugging purposes,
and has been superseded by LX_BLKPAG_AF and LX_BLKPAG_DBM.
- Improve comment

The need for reference/modify emulation has been eliminated,
and access/permission faults have been reduced, however,
there has been little change in overall performance.


# 1.126 31-Jan-2022 ryo

Skip unnecessary PTE operations and TLB invalidation.


# 1.125 16-Jan-2022 rillig

aarch64/pmap: remove stray semicolon

No binary change.


# 1.124 15-Jan-2022 skrll

The translations that need invalidation are always last level so remove
the (dubious) logic around tracking the level. The "any level" TLB
invalidation maintenance operation are used, but this may change after
further testing.

before
======
1661.0u 420.2s 2:53.82 1197.3% 231+29k 10+33918io 102pf+0w
1646.8u 425.2s 2:52.96 1198.0% 232+29k 1+33937io 49pf+0w
1647.9u 425.7s 2:52.58 1201.6% 232+29k 0+33940io 32pf+0w

After
=====
1602.5u 420.8s 2:49.09 1196.6% 238+30k 24+33893io 54pf+0w
1600.7u 421.3s 2:51.53 1178.8% 238+30k 1+33914io 33pf+0w
1597.5u 424.3s 2:50.46 1186.1% 238+30k 0+33915io 17pf+0w

LGTM from ryo@


# 1.123 14-Jan-2022 skrll

Restore the previous pmap_remove_all behaviour as the new method meant
the n1sdp couldn't complete a build.

No noticeable change in kernel build performance.


# 1.122 04-Jan-2022 skrll

KNF


# 1.121 10-Dec-2021 andvar

s/occured/occurred/ in comments, log messages and man pages.


# 1.120 07-Dec-2021 andvar

fix various typos, mainly in comments.


# 1.119 23-Oct-2021 skrll

Fix non-UVMHIST build


# 1.118 16-Oct-2021 ryo

fix non-MULTIPROCESSOR build


# 1.117 10-Oct-2021 skrll

Use sys/uvm/pmap/pmap_tlb.c on Aarch64 in the same way that some Arm, MIPS,
and some PPC kernels do. This removes the limitation of 256 processes on
CPUs with 8bit ASID field, e.g. Apple M1.

Additionally the following changes have been made

- removed a couple of unnecessary aarch64_tlbi_all calls
- removed any invalidation after freeing page tables due to
_pmap_sweep_pdp. This was never necessary afaict.
- all kernel mappings are marked global and userland mapping not-global.

Performance testing hasn't show a significant difference. The data here
is from building a kernel on an lx2k system with nvme.

before
1489.6u 400.4s 2:40.65 1176.5% 228+224k 0+32289io 57pf+0w
1482.6u 403.2s 2:38.49 1189.9% 228+222k 0+32274io 46pf+0w
1485.4u 402.2s 2:37.27 1200.2% 228+222k 0+32275io 12pf+0w

after
1493.9u 404.6s 2:37.50 1205.4% 227+221k 0+32265io 48pf+0w
1485.0u 408.0s 2:38.54 1194.0% 227+222k 0+32272io 36pf+0w
1484.3u 407.0s 2:35.88 1213.3% 228+224k 0+32268io 14pf+0w

>>> stats.ttest_ind([160.65,158.49,157.27], [157.5,158.54,155.88])
Ttest_indResult(statistic=1.1923622711296888, pvalue=0.2990182944606766)
>>>


# 1.116 30-Sep-2021 skrll

Ensure TCR_EPD0 is set on entry to pmap_activate and ensure it is set as
early as possible for APs.


# 1.115 26-Sep-2021 skrll

Use UVMHIST_CALLARGS


# 1.114 26-Sep-2021 skrll

'\n' is not required in KASSERTMSG either.


# 1.113 26-Sep-2021 skrll

"\n" is not required in KERNHIST


# 1.112 15-Sep-2021 skrll

Use __SHIFTIN. Same code before and after.


# 1.111 12-Sep-2021 skrll

pmap_page_remove: simply and reduce the code size slightly.


# 1.110 09-Sep-2021 skrll

In pmap_icache_sync_range change

for (...) {
...
if (condition) {
// do stuff
}
}

to

for (...) {
...
if (!conditional)
continue;
// do stuff
}

to save on indentation. Same code (modulo register usage) before and
after.


# 1.109 09-Sep-2021 skrll

KNF


Revision tags: thorpej-i2c-spi-conf2-base thorpej-futex2-base thorpej-cfargs2-base cjep_sun2x-base1 cjep_sun2x-base cjep_staticlib_x-base1 thorpej-i2c-spi-conf-base
# 1.108 29-May-2021 skrll

Deal with the pmap limitation of maxproc in a more complete way and
recognise CPUs with only 8bit ASIDs.


Revision tags: cjep_staticlib_x-base
# 1.107 30-Apr-2021 skrll

branches: 1.107.2;
Make the ddb for pmap / pte information pmap agnostic


# 1.106 29-Apr-2021 skrll

Remove some unnecessary tlb invalidate in pmap_growkernel and ASAN shadow
map. Ensure the shadow map mappings are visible to the TLB walkers.


# 1.105 21-Apr-2021 ryo

branches: 1.105.2;
added more attributes of PTE displayed by "ddb>machine pte"


Revision tags: thorpej-cfargs-base
# 1.104 17-Apr-2021 mrg

remove KERNHIST_INIT_STATIC(). it stradles the line between usable
early in boot and broken early in boot by requiring a partly static
structure with another structure that must be present by the time
any uses are performed. theoretically platform code could allocate
a chunk while seting up memory and assign it here, giving a dynamic
sizing for the entry list, but the reality is that all users have
a statically allocated entry list as well.

the existing KERNHIST_LINK_STATIC() is used in conjunction with
KERNHIST_INITIALIZER() instead.

this stops a NULL pointer deref when the _LOG() macro is called
before the storage is linked in, which happens with GCC 10 on OCTEON
with UVMHIST enabled, crashing in very early kernel init.


Revision tags: thorpej-futex-base
# 1.103 09-Mar-2021 ryo

branches: 1.103.2;
fix build error without options DDB.

kvtopte() is referenced from arm/acpi/acpi_machdep.c


# 1.102 13-Feb-2021 ryo

No assignment is needed here.

the loop in pmap_page_remove() always removes the first pv,
and since the list is managed by _pmap_remove_pv(), pp->pp_pv.pv_next always points to the first.


# 1.101 01-Feb-2021 ryo

It is enough to make a page accessible instead of writable.
same fix as r1.76


# 1.100 31-Jan-2021 ryo

implement pmap_remove_all().

The size of struct pv_entry has increased, but speed of kernel build has improved by about 1%
exec and exit should have been improved.


# 1.99 20-Dec-2020 skrll

Improve the English in the previous comment fix.


# 1.98 19-Dec-2020 skrll

Tweak a comment


# 1.97 11-Dec-2020 skrll

s:aarch64/cpufunc.h:arm/cpufunc.h:

a baby step in the grand arm header unification challenge


# 1.96 10-Nov-2020 skrll

AA64 is not MIPS.

Change all KSEG references to directmap


# 1.95 07-Nov-2020 skrll

In pmap_devmap_bootstrap only set pmap_devmap_bootstrap_done if there
is an entry and ALL of the entries have been done. The entry required
for EARLYCONS might not be the first/only one...


# 1.94 01-Nov-2020 jmcneill

branches: 1.94.2;
No need to disable translation table walks in pmap_activate().


# 1.93 22-Oct-2020 skrll

Use the isb macro - missed in previous commit


# 1.92 22-Oct-2020 skrll

Use the dmb/dsb/isb macros... if nothing else they're all now consistent
about the "memory" assembler contraint.

No binary change


# 1.91 28-Sep-2020 skrll

Only set pmap_devmap_bootstrap_done if something gets mapped.

Think acpi_platform_devmap


# 1.90 19-Sep-2020 skrll

Make __md_palloc pmap agnostic (think sys/uvm/pmap)


# 1.89 14-Sep-2020 ryo

PID_MAX is just an initial value (soft maximum). Don't use it for CTASSERT.
defined __HAVE_CPU_MAXPROC to use function cpu_maxproc().

pointed out by mrg@, thanks.


# 1.88 06-Sep-2020 ryo

Fix panic caused by modload. http://mail-index.netbsd.org/port-arm/2020/08/30/msg006960.html

The address space reserved for modules may not be mapped in L1-L3.


# 1.87 14-Aug-2020 skrll

Whitespace


# 1.86 12-Aug-2020 skrll

Part IV of ad's performance improvements for aarch64

- Implement pmap_growkernel(), and update kernel pmap's stats with atomics.

- Then, pmap_kenter_pa() and pmap_kremove() no longer need to allocate
memory nor take pm_lock, because they only modify L3 PTEs.

- Then, pm_lock and pp_lock can be adaptive mutexes at IPL_NONE which are
cheaper than spin mutexes.

- Take the pmap's lock in pmap_extract() if not the kernel's pmap, otherwise
pmap_extract() might see inconsistent state.


# 1.85 09-Aug-2020 skrll

Fix another UVMHIST so it doesn't use %s


# 1.84 16-Jul-2020 skrll

pmapboot_enter simplication
- bootpage_alloc in asm becomes pmapboot_pagealloc in C
- PMAPBOOT_ENTER_NOBLOCK is removed as it's not used
- PMAPBOOT_ENTER_NOOVERWRITE is removed as it's now always on
- physpage_allocator argument is removed as it's always
pmapboot_pagealloc
- Support for EARLYCONS without CONSADDR is removed so that the identity
map for CONSADDR is always known.

For the assembly files:
2 files changed, 40 insertions(+), 89 deletions(-)

LGTM ryo


# 1.83 04-Jul-2020 rin

Use tlen for temporary length variable instead of l, which is usually
used for struct lwp *.

No binary changes.


# 1.82 02-Jul-2020 rin

pmap_procwr(): sync icache even if p != curproc. This fixes applications
like GDB for arm32, that rewrite text of other process.

Thanks to ryo@ for discussion.


# 1.81 02-Jul-2020 rin

Set uvmexp.ncolors appropriately, which is required for some CPU
models with VIPT icache.

Otherwise, alias in virtual address results in inconsistent results,
at least for applications that rewrite text of other process, e.g.,
GDB for arm32.

Also, this hopefully fixes other unexpected failures due to alias.

Confirmed that there's no observable regression in performance;
difference in ``time make -j8'' for GENERIC64 kernel on BCM2837
with and without setting uvmexp.ncolors is within 0.1%.

Thanks to ryo@ for discussion.


# 1.80 27-Jun-2020 rin

Fix typo in name of evcnt(4) counter.


# 1.79 24-Jun-2020 ryo

Fix bug with incorrect range calculation when doing icache sync.
This is called by sysarch(ARM_SYNC_ICACHE) from aarch32 (compat_netbsd32) emul process.

pointed out by rin@, thanks.

XXX pullup-9


# 1.78 14-Jun-2020 ad

- Fix a lock order reversal in pmap_page_protect().

- Make sure pmap is always locked when updating stats; atomics no longer
needed to do that.

- Remove unneeded traversal of pv list in pmap_enter_pv().

- Shrink struct vm_page from 136 to 128 bytes (cache line sized) and struct
pv_entry from 48 to 32 bytes (power of 2 sized).

- Embed a pv_entry in each vm_page. This means PV entries don't need to
be allocated for private anonymous memory / COW pages / most UBC mappings.
Dynamic PV entries are then used only for stuff like shared libraries and
shared memory.

Proposed on port-arm@.


# 1.77 10-Jun-2020 ad

- Wired/resident stats shouldn't covered by PMAPCOUNTERS.
- Rename need_update_pv -> need_enter_pv.

Ok ryo@


# 1.76 01-Jun-2020 ryo

no need to make the PTE writable to do icache_sync, enough to accessible.


# 1.75 15-May-2020 skrll

Use __diagused


# 1.74 15-May-2020 tnn

fix non-diag build


# 1.73 14-May-2020 skrll

Use MUTEX_NODEBUG for PV locks as is commonly done. OK ryo.


# 1.72 13-May-2020 jmcneill

Implement pmap_extract_coherency


Revision tags: bouyer-xenpvh-base2 phil-wifi-20200421 bouyer-xenpvh-base1
# 1.71 18-Apr-2020 skrll

PMAP_DEBUG has been deleted on arm


# 1.70 13-Apr-2020 maxv

Add support for Branch Target Identification (BTI).

On the executable pages that have the GP (Guarded Page) bit, the semantic
of the "br" and "blr" instructions is changed: the CPU expects the first
instruction of the jump/call target to be "bti", and faults if it isn't.

We add the GP bit on the kernel .text pages (and incidentally the .rodata
pages, but we don't care). The compiler adds a "bti c" instruction at the
beginning of each C function. We modify the ENTRY() macros to manually add
"bti c" in the asm functions.

cpuswitch.S needs a specific change: with "br x27" the CPU expects "bti j",
which is bad because the functions begin with "bti c"; switch to "br x16",
for the CPU to accept "bti c".

BTI helps defend against JOP/COP. Tested on Qemu.


Revision tags: phil-wifi-20200411 bouyer-xenpvh-base
# 1.69 08-Apr-2020 ryo

branches: 1.69.2;
use PMAP_PAGE_INIT() to initialize mutex in pmap_page.

VM_MDPAGE_INIT() in pmap_free_pdp() had initialized pp_flags,
so it unintentionally cleared PMAP_PAGE_FLAGS_PV_TRACKED.
use PMAP_PAGE_INIT to avoid using PMAP_PAGE_FLAGS_PV_TRACKED.

pointed out by tnn@, thanks


Revision tags: phil-wifi-20200406
# 1.68 14-Mar-2020 ad

pmap_remove_all(): Return a boolean value to indicate the behaviour. If
true, all mappings have been removed, the pmap is totally cleared out, and
UVM can then avoid doing the work to call pmap_remove() for each map entry.
If false, either nothing has been done, or some helpful arch-specific voodoo
has taken place.


Revision tags: is-mlppp-base
# 1.67 02-Mar-2020 ryo

oops, fix incorrect usage of daif_enable() in my previous commit.


# 1.66 29-Feb-2020 ryo

Fix pmap to work correctly with tagged addresses

- when fault, untag from address before passing to uvm/pmap functions
- pmap_extract() checks more strictly and consider the address tag


# 1.65 29-Feb-2020 ryo

use pmapboot_enter_range()


Revision tags: ad-namecache-base3
# 1.64 10-Feb-2020 ryo

use LIST(3) instead of TAILQ(3) to save one word in struct vm_page and struct pmap.

pointed out by riastradh@. thanks


# 1.63 03-Feb-2020 ryo

add support pmap_pv(9)

Patch originally from jmcneill@. thanks


# 1.62 03-Feb-2020 ryo

separate struct vm_page_md into vm_page_md and pmap_page
for preparation pmap_pv(9)


Revision tags: ad-namecache-base2 ad-namecache-base1
# 1.61 09-Jan-2020 ryo

fix behaviour mmap()/mprotect() when passed only PROT_EXEC.

when mmap()/mprotect() with only PROT_EXEC, syscall will be successful,
but the page actually hadn't been mapped.
it should be mapped with PROT_READ|PROT_EXEC implicitly. (r-x)


Revision tags: ad-namecache-base
# 1.60 30-Dec-2019 skrll

branches: 1.60.2;
Update pmap_map_chunk to allow L[12] block mappings and L3 page mappings


# 1.59 30-Dec-2019 skrll

Remove unnecessary brackets and unwrap a conditional. Same code before
and after.


# 1.58 28-Dec-2019 jmcneill

Do not use Early Write Acknowledge for PCIe I/O and config space.


# 1.57 27-Dec-2019 jmcneill

Enable early write acknowledge for device memory mappings.


# 1.56 19-Dec-2019 skrll

G/C kasan_shadow_map call in pmap_enter

pmap_growkernel calls kasan_shadow_map for KVA


# 1.55 18-Dec-2019 ryo

atomic_add_16() is not used in pmap.c anymore. no need decl here.


# 1.54 18-Dec-2019 ryo

space to tab


# 1.53 14-Dec-2019 skrll

Fix build... wire_count probably doesn't need atomics


# 1.52 13-Dec-2019 skrll

Fix KASAN support by calling kasan_shadow_map in pmap_growkernel


# 1.51 10-Dec-2019 ad

pg->phys_addr -> VM_PAGE_TO_PHYS(pg)


Revision tags: phil-wifi-20191119
# 1.50 14-Nov-2019 maxv

Mark several kASan functions with __nothing, to avoid annoying #ifdefs.
Same as kCSan and kMSan.


# 1.49 14-Nov-2019 maxv

Don't include "opt_kasan.h" when there's already <sys/asan.h> included.


# 1.48 29-Oct-2019 maya

Define PMAP_NEED_PROCWR, providing strategically placed i-cache
synchronization where just-changed memory is about to be executed.

Fixes SIGILLs seen when running Mono 6 on QEMU Cortex-A57.

ok ryo


# 1.47 22-Sep-2019 jmcneill

Disable translation table walks using TTBR0 while changing its value and
when deactivating a pmap. Fixes stability issues on Ampere eMAG CPUs.


# 1.46 20-Sep-2019 ryo

ref/mod bit should be set according to 'flags' argument, not 'prot'. r1.44 was incomplete.


# 1.45 13-Sep-2019 ryo

In pmap_devmap_bootstrap(), cpu_earlydevice_va_p() must not return true until *all* devmap tables have been enabled.
console mapping may be present in the last table.


# 1.44 07-Sep-2019 ryo

- remove incorrect KASSERT. mmap(2) with prot=PROT_WRITE calls pmap_enter(..., PROT_WRITE) internally.
- fix to update page reference flags when only PROT_WRITE or PROT_EXECUTE specified


# 1.43 15-Aug-2019 skrll

Make pmap_db_pte_print more terse so it's quicker on serial consoles


# 1.42 12-Aug-2019 skrll

Use PMAP_DEV in DEVMAP_ENTRY rather than pmap_map_chunk. It's clearer and
means pmap_map_chunk can be made to map other memory types.


Revision tags: netbsd-9-base phil-wifi-20190609
# 1.41 17-May-2019 mrg

branches: 1.41.2;
apply some __diagused.


Revision tags: isaki-audio2-base
# 1.40 08-Apr-2019 ryo

- free empty page tables pages if reach a certain usage.
- need to lock at removing an old pg (_pmap_remove_pv) in _pmap_enter()


# 1.39 06-Apr-2019 ryo

Fix race conditions about pmap_page_protect() and pmap_enter().

while handling same PTE by these functions in same time, there
is a critical path that the number of valid PTEs and wire_count
are inconsistent, and it caused KASSERT.
Need to hold a pv_lock while modifying them.


# 1.38 20-Mar-2019 ryo

spinkle __printflike(), and use PRIxxx


# 1.37 19-Mar-2019 ryo

- add ddb command "machine ttbr" to dump MMU tables.
- tidy up descriptions, usages and messages.


# 1.36 19-Mar-2019 ryo

- free L1-L3 pages that has been emptied by pmap_remove().
- if no memories, pmap_enter will return correctly ENOMEM if PMAP_CANFAIL, or wait until available any memories if !PMAP_CANFAIL.

These changes improves the stability when we use a huge virtual memory spaces with mmap.


# 1.35 06-Feb-2019 ryo

improve pmap_remove
- don't lock/unlock per page in pmap_remove()
- speedup pte lookup for continuous addresses
- bring out pool_cache_put(&_pmap_pv_pool, pv) from lock/unlock section


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226
# 1.34 21-Dec-2018 ryo

- add workaround for Cavium ThunderX errata 27456.
- add cpufuncs table in cpu_info. each cpu clusters may have different erratum. (e.g. big.LITTLE)


Revision tags: pgoyette-compat-1126
# 1.33 01-Nov-2018 maxv

Add kASan support for aarch64. Stack tracking needs more investigation
and will come in a separate commit.

Reviewed by ryo@ jmcneill@ skrll@.


# 1.32 31-Oct-2018 ryo

invalidate icache correctly.
l3pte_executable() should be used for only valid pte.


Revision tags: pgoyette-compat-1020
# 1.31 18-Oct-2018 skrll

Provide generic start code that assumes the MMU is off and caches are
disabled as per the linux booting protocol for ARMv6 and ARMv7 boards.
u-boot image type should be changed to 'linux' for correct behaviour.

The new start code builds a minimal "bootstrap" L1PT with cached access
disabled and uses the same table for all processors. AP startup is
performed in less steps and more code is written in C.

The bootstrap tables and stack are placed into an (orphaned) section
"_init_memory" which is given to uvm when it is no longer used.

Various kernels have been converted to use this code and tested. Some
boards were provided by TNF. Thanks!

The GENERIC kernel now boots on boards using the TEGRA, SUNXI and EXYNOS
kernels. The GENERIC kernel will also work on RPI2 using u-boot.

Thanks to martin@ and aymeric@ for testing on parallella and nanosoc
respectively


# 1.30 14-Oct-2018 skrll

Use __nothing


# 1.29 12-Oct-2018 ryo

add initial support of COMPAT_NETBSD32 on AArch64.
arm ELF32 EABI binaries could be execute in AArch32 state on AArch64. A32 THUMB mode is not supported yet.


# 1.28 12-Oct-2018 ryo

- cleanup checking address ranges with IN_RANGE macro
- change PM_ADDR_CHECK macro to KASSERTMSG
- restore fast lookup cases with IN_RANGE macro for pmap_extract changed in my previous commit.


# 1.27 12-Oct-2018 ryo

rewrite pmap_pte_lookup() to share similar code.


# 1.26 04-Oct-2018 ryo

cleanup locore, and changed the way to map memories during boot.
- add functions bootpage_enter() and bootpage_alloc() to adapt various layout
of physical memory map. especially for 64bit physical memory layout.
pmapboot_alloc() allocates pagetable pages from _end[].
- changed to map only the required amount for PA=VA identity mapping
(kernel image, UART device, and FDT blob) with L2_BLOCK(2Mbyte).
- changing page permission for kernel image, and making KSEG mapping are done
at cpu_kernel_vm_init() instead of at locore.
- optimize PTE entries with PTE Contiguous bit. it is enabled on devmap only for now.

reviewed by skrll@, thanks.


# 1.25 04-Oct-2018 ryo

* define LX_BLKPAG_{OS,ATTR}_* for OS dependent PTE attributes in pmap.h
* cleanup macros


Revision tags: pgoyette-compat-0930
# 1.24 17-Sep-2018 ryo

delete debug printf and KASSERT.


# 1.23 10-Sep-2018 maxv

Replace KDASSERT by panic.


# 1.22 10-Sep-2018 maxv

Rename _pmap_alloc_pdp -> pmap_alloc_pdp, and make it public.


# 1.21 10-Sep-2018 ryo

cleanup aarch64 mpstart and fdt bootstrap
* arm_cpu_hatch_arg is a bad idea. avoid serializing CPU startup, and eliminate arm_cpu_hatch_arg.
in mpstart, resolve own cpu index using array of cpu_mpidr[] (aarch64)
* add support fdt enable-method "spin-table"
* add support fdt enable-method "brcm,bcm2836-smp" (for 32bit RaspberryPi)
* use arm_fdt_cpu_bootstrap() instead of psci_fdt_bootstrap()
* rename "arm/fdt/psci_fdt.h" to "arm/fdt/psci_fdtvar.h" because of conflict of include file for needs-flag
* add devmap for cpu spin-table of raspberrypi3/aarch64
* no need to force hatch APs for raspberrypi3/arm32 ifndef MULTIPROCESSOR.
* fix to work pmap_extract(kerneltext/data/bss) even if before calling pmap_bootstrap

idea to use cpu_mpidr[] by jmcneill@. reviewd by skrll@. thanks.


Revision tags: pgoyette-compat-0906
# 1.20 27-Aug-2018 ryo

need to add VM_PROT_READ when pmap_kenter_pa(va, pa, VM_PROT_WRITE, 0) or pmap_kenter_pa(va, pa, VM_PROT_EXECUTE, 0).
VM_PROT_READ is treated as an access permission inernally.


# 1.19 11-Aug-2018 ryo

change to minimum invalidation of TLB.
specifying not only va but also asid, and not invalidate L0-L2 entry using tlbi_*_ll() if needed.


# 1.18 10-Aug-2018 ryo

treat kernel-exec attr and user-exec attr separately.
kernel cannot execute userland exec page, and user cannot execute kernel page.


# 1.17 06-Aug-2018 ryo

set kernel text/rodata readonly by default.
add function db_write_text() for setting ddb breakpoint.


# 1.16 31-Jul-2018 skrll

Define and use VPRINTF


Revision tags: pgoyette-compat-0728
# 1.15 27-Jul-2018 ryo

changes of pmap.c r1.13 seems to be unstable.
In order to invalidate icache, not to invalidate all icache,
but temporary to make the page writable and invalidate target address only.


# 1.14 24-Jul-2018 ryo

don't call pool_cache_put with locking pmap. pool_cache_put call pmap_kenter_pa internally.
(pool_cache_put_paddr -> pool_cache_put_slow -> pool_get -> pmap_kenter_pa)


# 1.13 23-Jul-2018 ryo

* fix icache invalidations.
* "ic ivau" (aarch64_icache_sync_range) with VA generates permission fault in some situations, therefore use KSEG address for now.


# 1.12 23-Jul-2018 ryo

rather than using flags to resolve nested locks, reserve pool_cache before locking.


# 1.11 21-Jul-2018 ryo

* avoid deadlock. mutex_owned() works only for adaptive lock, therefore we cannot use it for spinlock...
* add more NULL check
* clear pte when pmap_enter() fails


# 1.10 17-Jul-2018 ryo

Use __debugused


# 1.9 17-Jul-2018 christos

Add missing casts, remove unused variables.


# 1.8 09-Jul-2018 ryo

need locks in pmap_kremove() and pmap_fault_fixup()


Revision tags: phil-wifi-base pgoyette-compat-0625 pgoyette-compat-0521
# 1.7 20-May-2018 ryo

branches: 1.7.2;
pmap_enter() must update modified/referenced flags by 'flags' not 'prot'.


# 1.6 16-May-2018 ryo

Fix memory leak. it was leaking one page every pmap_create().
pm->pm_vmlist must be initialized before calling _pmap_alloc_pdp().


Revision tags: pgoyette-compat-0502
# 1.5 29-Apr-2018 ryo

fix KASSERT panic. pv_entry may not be exists in pvlist when pmap_remove().


# 1.4 29-Apr-2018 ryo

delete unused code


# 1.3 27-Apr-2018 ryo

fix instability behavior of bufcache on aarch64.
* fix to return correct ref/mod when PMAP_WIRED.
* changed to keep wired flags in pte instead of pv_entry, and cleanup.


Revision tags: pgoyette-compat-0422 pgoyette-compat-0415 pgoyette-compat-0407
# 1.2 01-Apr-2018 ryo

Add initial support for ARMv8 (AARCH64) (by nisimura@ and ryo@)

- sys/arch/evbarm64 is gone and integrated into sys/arch/evbarm. (by skrll@)
- add support fdt. evbarm/conf/GENERIC64 fdt (bcm2837,sunxi,tegra) based generic 64bit kernel config. (by skrll@, jmcneill@)


Revision tags: netbsd-8-2-RELEASE netbsd-8-1-RELEASE netbsd-8-1-RC1 netbsd-7-2-RELEASE netbsd-8-0-RELEASE netbsd-8-0-RC2 netbsd-8-0-RC1 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 netbsd-7-1-2-RELEASE pgoyette-compat-base netbsd-7-1-1-RELEASE tls-maxphys-base-20171202 matt-nb8-mediatek-base nick-nhusb-base-20170825 perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base pgoyette-localcount-20170320 netbsd-7-1-RELEASE netbsd-7-1-RC2 nick-nhusb-base-20170204 netbsd-7-nhusb-base-20170116 bouyer-socketcan-base pgoyette-localcount-20170107 netbsd-7-1-RC1 nick-nhusb-base-20161204 pgoyette-localcount-20161104 netbsd-7-0-2-RELEASE nick-nhusb-base-20161004 localcount-20160914 netbsd-7-nhusb-base pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907 nick-nhusb-base-20160529 netbsd-7-0-1-RELEASE nick-nhusb-base-20160422 nick-nhusb-base-20160319 nick-nhusb-base-20151226 netbsd-7-0-RELEASE nick-nhusb-base-20150921 netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 nick-nhusb-base-20150606 nick-nhusb-base-20150406 nick-nhusb-base tls-maxphys-base netbsd-7-base
# 1.1 10-Aug-2014 matt

branches: 1.1.4; 1.1.28;
Preliminary files for AARCH64 (64-bit ARM) support.
Enough for a distribution build.


# 1.143 23-Oct-2022 skrll

Use UVMHIST_CALLARGS in pmap_bootstrap


# 1.142 23-Oct-2022 skrll

Only define the EFI variable if EFI_RUNTIME


# 1.141 20-Oct-2022 skrll

KNF


# 1.140 15-Oct-2022 jmcneill

Use "non-posted" instead of "strongly ordered" to describe nGnRnE mappings

Rename the following defines:
- _ARM_BUS_SPACE_MAP_STRONGLY_ORDERED to BUS_SPACE_MAP_NONPOSTED
- PMAP_DEV_SO to PMAP_DEV_NP
- LX_BLKPAG_ATTR_DEVICE_MEM_SO to LX_BLKPAG_ATTR_DEVICE_MEM_NP
Rename the following option:
- AARCH64_DEVICE_MEM_STRONGLY_ORDERED to AARCH64_DEVICE_MEM_NONPOSTED


Revision tags: bouyer-sunxi-drm-base
# 1.139 19-Aug-2022 ryo

Fixed a bug that pte's __BIT(63,48) could be set when accessing addresses above 0x0001000000000000 in /dev/mem with mmap().


# 1.138 19-Aug-2022 ryo

When accessed in mmap by the device pager, pmap_enter() may be called with prot == PROT_WRITE.


# 1.137 03-May-2022 skrll

Sprinkle some KASSERT(kpreempt_disabled());


# 1.136 27-Apr-2022 ryo

since pmap_activate_efirt() rewrites TTBR0, it is necessary to pmap_activate() again after pmap_deactivate_efirt() to restore the original TTBR0.

- Fix to do pmap_{de,}activate() before/after pmap_{,de}activate_efirt().
- moved kpreempt_{disable,enable}() to the caller since everything between
arm_efirt_md_enter() and arm_efirt_md_exit() should be kpreempt disabled.

ok skrll@


# 1.135 17-Apr-2022 skrll

Add the missing kpreempt_enable to pmap_deactivate_efirt


# 1.134 10-Apr-2022 skrll

No need to flush icache for EFI RT mappings as bootaa64.efi flushed
the full icache for us. (Also this avoids traps)


# 1.133 09-Apr-2022 riastradh

sys: Use membar_release/acquire around reference drop.

This just goes through my recent reference count membar audit and
changes membar_exit to membar_release and membar_enter to
membar_acquire -- this should make everything cheaper on most CPUs
without hurting correctness, because membar_acquire is generally
cheaper than membar_enter.


# 1.132 02-Apr-2022 skrll

Update to support EFI runtime outside the kernel virtual address space
by creating an EFI RT pmap that can be activated / deactivated when
required.

Adds support for EFI RT to ARM_MMU_EXTENDED (ASID) 32-bit Arm machines.

On Arm64 the usage of pmapboot_enter is reduced and the mappings are
created much later in the boot process -- now in cpu_startup_hook.
Backward compatiblity for KVA mapped RT from old bootaa64.efi is
maintained.

Adding support to other platforms should be easier as a result.


# 1.131 19-Mar-2022 skrll

Slight code re-organisation. NFCI.


# 1.130 12-Mar-2022 riastradh

sys: Membar audit around reference count releases.

If two threads are using an object that is freed when the reference
count goes to zero, we need to ensure that all memory operations
related to the object happen before freeing the object.

Using an atomic_dec_uint_nv(&refcnt) == 0 ensures that only one
thread takes responsibility for freeing, but it's not enough to
ensure that the other thread's memory operations happen before the
freeing.

Consider:

Thread A Thread B
obj->foo = 42; obj->baz = 73;
mumble(&obj->bar); grumble(&obj->quux);
/* membar_exit(); */ /* membar_exit(); */
atomic_dec -- not last atomic_dec -- last
/* membar_enter(); */
KASSERT(invariant(obj->foo,
obj->bar));
free_stuff(obj);

The memory barriers ensure that

obj->foo = 42;
mumble(&obj->bar);

in thread A happens before

KASSERT(invariant(obj->foo, obj->bar));
free_stuff(obj);

in thread B. Without them, this ordering is not guaranteed.

So in general it is necessary to do

membar_exit();
if (atomic_dec_uint_nv(&obj->refcnt) != 0)
return;
membar_enter();

to release a reference, for the `last one out hit the lights' style
of reference counting. (This is in contrast to the style where one
thread blocks new references and then waits under a lock for existing
ones to drain with a condvar -- no membar needed thanks to mutex(9).)

I searched for atomic_dec to find all these. Obviously we ought to
have a better abstraction for this because there's so much copypasta.
This is a stop-gap measure to fix actual bugs until we have that. It
would be nice if an abstraction could gracefully handle the different
styles of reference counting in use -- some years ago I drafted an
API for this, but making it cover everything got a little out of hand
(particularly with struct vnode::v_usecount) and I ended up setting
it aside to work on psref/localcount instead for better scalability.

I got bored of adding #ifdef __HAVE_ATOMIC_AS_MEMBAR everywhere, so I
only put it on things that look performance-critical on 5sec review.
We should really adopt membar_enter_preatomic/membar_exit_postatomic
or something (except they are applicable only to atomic r/m/w, not to
atomic_load/store_*, making the naming annoying) and get rid of all
the ifdefs.


# 1.129 05-Mar-2022 skrll

Slight comment improvement.


# 1.128 16-Feb-2022 andvar

fix various typos, mainly in comments.


# 1.127 31-Jan-2022 ryo

add support Hardware updates to Access flag and Dirty state (FEAT_HAFDBS)

- The DBM bit of the PTE is now used to determine if it is writable, and
the AF bit is treated entirely as a reference bit. A valid PTE is always
treated as readable. There can be no valid PTE that is not readable.
- LX_BLKPAG_OS_{READ,WRITE} are used only for debugging purposes,
and has been superseded by LX_BLKPAG_AF and LX_BLKPAG_DBM.
- Improve comment

The need for reference/modify emulation has been eliminated,
and access/permission faults have been reduced, however,
there has been little change in overall performance.


# 1.126 31-Jan-2022 ryo

Skip unnecessary PTE operations and TLB invalidation.


# 1.125 16-Jan-2022 rillig

aarch64/pmap: remove stray semicolon

No binary change.


# 1.124 15-Jan-2022 skrll

The translations that need invalidation are always last level so remove
the (dubious) logic around tracking the level. The "any level" TLB
invalidation maintenance operation are used, but this may change after
further testing.

before
======
1661.0u 420.2s 2:53.82 1197.3% 231+29k 10+33918io 102pf+0w
1646.8u 425.2s 2:52.96 1198.0% 232+29k 1+33937io 49pf+0w
1647.9u 425.7s 2:52.58 1201.6% 232+29k 0+33940io 32pf+0w

After
=====
1602.5u 420.8s 2:49.09 1196.6% 238+30k 24+33893io 54pf+0w
1600.7u 421.3s 2:51.53 1178.8% 238+30k 1+33914io 33pf+0w
1597.5u 424.3s 2:50.46 1186.1% 238+30k 0+33915io 17pf+0w

LGTM from ryo@


# 1.123 14-Jan-2022 skrll

Restore the previous pmap_remove_all behaviour as the new method meant
the n1sdp couldn't complete a build.

No noticeable change in kernel build performance.


# 1.122 04-Jan-2022 skrll

KNF


# 1.121 10-Dec-2021 andvar

s/occured/occurred/ in comments, log messages and man pages.


# 1.120 07-Dec-2021 andvar

fix various typos, mainly in comments.


# 1.119 23-Oct-2021 skrll

Fix non-UVMHIST build


# 1.118 16-Oct-2021 ryo

fix non-MULTIPROCESSOR build


# 1.117 10-Oct-2021 skrll

Use sys/uvm/pmap/pmap_tlb.c on Aarch64 in the same way that some Arm, MIPS,
and some PPC kernels do. This removes the limitation of 256 processes on
CPUs with 8bit ASID field, e.g. Apple M1.

Additionally the following changes have been made

- removed a couple of unnecessary aarch64_tlbi_all calls
- removed any invalidation after freeing page tables due to
_pmap_sweep_pdp. This was never necessary afaict.
- all kernel mappings are marked global and userland mapping not-global.

Performance testing hasn't show a significant difference. The data here
is from building a kernel on an lx2k system with nvme.

before
1489.6u 400.4s 2:40.65 1176.5% 228+224k 0+32289io 57pf+0w
1482.6u 403.2s 2:38.49 1189.9% 228+222k 0+32274io 46pf+0w
1485.4u 402.2s 2:37.27 1200.2% 228+222k 0+32275io 12pf+0w

after
1493.9u 404.6s 2:37.50 1205.4% 227+221k 0+32265io 48pf+0w
1485.0u 408.0s 2:38.54 1194.0% 227+222k 0+32272io 36pf+0w
1484.3u 407.0s 2:35.88 1213.3% 228+224k 0+32268io 14pf+0w

>>> stats.ttest_ind([160.65,158.49,157.27], [157.5,158.54,155.88])
Ttest_indResult(statistic=1.1923622711296888, pvalue=0.2990182944606766)
>>>


# 1.116 30-Sep-2021 skrll

Ensure TCR_EPD0 is set on entry to pmap_activate and ensure it is set as
early as possible for APs.


# 1.115 26-Sep-2021 skrll

Use UVMHIST_CALLARGS


# 1.114 26-Sep-2021 skrll

'\n' is not required in KASSERTMSG either.


# 1.113 26-Sep-2021 skrll

"\n" is not required in KERNHIST


# 1.112 15-Sep-2021 skrll

Use __SHIFTIN. Same code before and after.


# 1.111 12-Sep-2021 skrll

pmap_page_remove: simply and reduce the code size slightly.


# 1.110 09-Sep-2021 skrll

In pmap_icache_sync_range change

for (...) {
...
if (condition) {
// do stuff
}
}

to

for (...) {
...
if (!conditional)
continue;
// do stuff
}

to save on indentation. Same code (modulo register usage) before and
after.


# 1.109 09-Sep-2021 skrll

KNF


Revision tags: thorpej-i2c-spi-conf2-base thorpej-futex2-base thorpej-cfargs2-base cjep_sun2x-base1 cjep_sun2x-base cjep_staticlib_x-base1 thorpej-i2c-spi-conf-base
# 1.108 29-May-2021 skrll

Deal with the pmap limitation of maxproc in a more complete way and
recognise CPUs with only 8bit ASIDs.


Revision tags: cjep_staticlib_x-base
# 1.107 30-Apr-2021 skrll

branches: 1.107.2;
Make the ddb for pmap / pte information pmap agnostic


# 1.106 29-Apr-2021 skrll

Remove some unnecessary tlb invalidate in pmap_growkernel and ASAN shadow
map. Ensure the shadow map mappings are visible to the TLB walkers.


# 1.105 21-Apr-2021 ryo

branches: 1.105.2;
added more attributes of PTE displayed by "ddb>machine pte"


Revision tags: thorpej-cfargs-base
# 1.104 17-Apr-2021 mrg

remove KERNHIST_INIT_STATIC(). it stradles the line between usable
early in boot and broken early in boot by requiring a partly static
structure with another structure that must be present by the time
any uses are performed. theoretically platform code could allocate
a chunk while seting up memory and assign it here, giving a dynamic
sizing for the entry list, but the reality is that all users have
a statically allocated entry list as well.

the existing KERNHIST_LINK_STATIC() is used in conjunction with
KERNHIST_INITIALIZER() instead.

this stops a NULL pointer deref when the _LOG() macro is called
before the storage is linked in, which happens with GCC 10 on OCTEON
with UVMHIST enabled, crashing in very early kernel init.


Revision tags: thorpej-futex-base
# 1.103 09-Mar-2021 ryo

branches: 1.103.2;
fix build error without options DDB.

kvtopte() is referenced from arm/acpi/acpi_machdep.c


# 1.102 13-Feb-2021 ryo

No assignment is needed here.

the loop in pmap_page_remove() always removes the first pv,
and since the list is managed by _pmap_remove_pv(), pp->pp_pv.pv_next always points to the first.


# 1.101 01-Feb-2021 ryo

It is enough to make a page accessible instead of writable.
same fix as r1.76


# 1.100 31-Jan-2021 ryo

implement pmap_remove_all().

The size of struct pv_entry has increased, but speed of kernel build has improved by about 1%
exec and exit should have been improved.


# 1.99 20-Dec-2020 skrll

Improve the English in the previous comment fix.


# 1.98 19-Dec-2020 skrll

Tweak a comment


# 1.97 11-Dec-2020 skrll

s:aarch64/cpufunc.h:arm/cpufunc.h:

a baby step in the grand arm header unification challenge


# 1.96 10-Nov-2020 skrll

AA64 is not MIPS.

Change all KSEG references to directmap


# 1.95 07-Nov-2020 skrll

In pmap_devmap_bootstrap only set pmap_devmap_bootstrap_done if there
is an entry and ALL of the entries have been done. The entry required
for EARLYCONS might not be the first/only one...


# 1.94 01-Nov-2020 jmcneill

branches: 1.94.2;
No need to disable translation table walks in pmap_activate().


# 1.93 22-Oct-2020 skrll

Use the isb macro - missed in previous commit


# 1.92 22-Oct-2020 skrll

Use the dmb/dsb/isb macros... if nothing else they're all now consistent
about the "memory" assembler contraint.

No binary change


# 1.91 28-Sep-2020 skrll

Only set pmap_devmap_bootstrap_done if something gets mapped.

Think acpi_platform_devmap


# 1.90 19-Sep-2020 skrll

Make __md_palloc pmap agnostic (think sys/uvm/pmap)


# 1.89 14-Sep-2020 ryo

PID_MAX is just an initial value (soft maximum). Don't use it for CTASSERT.
defined __HAVE_CPU_MAXPROC to use function cpu_maxproc().

pointed out by mrg@, thanks.


# 1.88 06-Sep-2020 ryo

Fix panic caused by modload. http://mail-index.netbsd.org/port-arm/2020/08/30/msg006960.html

The address space reserved for modules may not be mapped in L1-L3.


# 1.87 14-Aug-2020 skrll

Whitespace


# 1.86 12-Aug-2020 skrll

Part IV of ad's performance improvements for aarch64

- Implement pmap_growkernel(), and update kernel pmap's stats with atomics.

- Then, pmap_kenter_pa() and pmap_kremove() no longer need to allocate
memory nor take pm_lock, because they only modify L3 PTEs.

- Then, pm_lock and pp_lock can be adaptive mutexes at IPL_NONE which are
cheaper than spin mutexes.

- Take the pmap's lock in pmap_extract() if not the kernel's pmap, otherwise
pmap_extract() might see inconsistent state.


# 1.85 09-Aug-2020 skrll

Fix another UVMHIST so it doesn't use %s


# 1.84 16-Jul-2020 skrll

pmapboot_enter simplication
- bootpage_alloc in asm becomes pmapboot_pagealloc in C
- PMAPBOOT_ENTER_NOBLOCK is removed as it's not used
- PMAPBOOT_ENTER_NOOVERWRITE is removed as it's now always on
- physpage_allocator argument is removed as it's always
pmapboot_pagealloc
- Support for EARLYCONS without CONSADDR is removed so that the identity
map for CONSADDR is always known.

For the assembly files:
2 files changed, 40 insertions(+), 89 deletions(-)

LGTM ryo


# 1.83 04-Jul-2020 rin

Use tlen for temporary length variable instead of l, which is usually
used for struct lwp *.

No binary changes.


# 1.82 02-Jul-2020 rin

pmap_procwr(): sync icache even if p != curproc. This fixes applications
like GDB for arm32, that rewrite text of other process.

Thanks to ryo@ for discussion.


# 1.81 02-Jul-2020 rin

Set uvmexp.ncolors appropriately, which is required for some CPU
models with VIPT icache.

Otherwise, alias in virtual address results in inconsistent results,
at least for applications that rewrite text of other process, e.g.,
GDB for arm32.

Also, this hopefully fixes other unexpected failures due to alias.

Confirmed that there's no observable regression in performance;
difference in ``time make -j8'' for GENERIC64 kernel on BCM2837
with and without setting uvmexp.ncolors is within 0.1%.

Thanks to ryo@ for discussion.


# 1.80 27-Jun-2020 rin

Fix typo in name of evcnt(4) counter.


# 1.79 24-Jun-2020 ryo

Fix bug with incorrect range calculation when doing icache sync.
This is called by sysarch(ARM_SYNC_ICACHE) from aarch32 (compat_netbsd32) emul process.

pointed out by rin@, thanks.

XXX pullup-9


# 1.78 14-Jun-2020 ad

- Fix a lock order reversal in pmap_page_protect().

- Make sure pmap is always locked when updating stats; atomics no longer
needed to do that.

- Remove unneeded traversal of pv list in pmap_enter_pv().

- Shrink struct vm_page from 136 to 128 bytes (cache line sized) and struct
pv_entry from 48 to 32 bytes (power of 2 sized).

- Embed a pv_entry in each vm_page. This means PV entries don't need to
be allocated for private anonymous memory / COW pages / most UBC mappings.
Dynamic PV entries are then used only for stuff like shared libraries and
shared memory.

Proposed on port-arm@.


# 1.77 10-Jun-2020 ad

- Wired/resident stats shouldn't covered by PMAPCOUNTERS.
- Rename need_update_pv -> need_enter_pv.

Ok ryo@


# 1.76 01-Jun-2020 ryo

no need to make the PTE writable to do icache_sync, enough to accessible.


# 1.75 15-May-2020 skrll

Use __diagused


# 1.74 15-May-2020 tnn

fix non-diag build


# 1.73 14-May-2020 skrll

Use MUTEX_NODEBUG for PV locks as is commonly done. OK ryo.


# 1.72 13-May-2020 jmcneill

Implement pmap_extract_coherency


Revision tags: bouyer-xenpvh-base2 phil-wifi-20200421 bouyer-xenpvh-base1
# 1.71 18-Apr-2020 skrll

PMAP_DEBUG has been deleted on arm


# 1.70 13-Apr-2020 maxv

Add support for Branch Target Identification (BTI).

On the executable pages that have the GP (Guarded Page) bit, the semantic
of the "br" and "blr" instructions is changed: the CPU expects the first
instruction of the jump/call target to be "bti", and faults if it isn't.

We add the GP bit on the kernel .text pages (and incidentally the .rodata
pages, but we don't care). The compiler adds a "bti c" instruction at the
beginning of each C function. We modify the ENTRY() macros to manually add
"bti c" in the asm functions.

cpuswitch.S needs a specific change: with "br x27" the CPU expects "bti j",
which is bad because the functions begin with "bti c"; switch to "br x16",
for the CPU to accept "bti c".

BTI helps defend against JOP/COP. Tested on Qemu.


Revision tags: phil-wifi-20200411 bouyer-xenpvh-base
# 1.69 08-Apr-2020 ryo

branches: 1.69.2;
use PMAP_PAGE_INIT() to initialize mutex in pmap_page.

VM_MDPAGE_INIT() in pmap_free_pdp() had initialized pp_flags,
so it unintentionally cleared PMAP_PAGE_FLAGS_PV_TRACKED.
use PMAP_PAGE_INIT to avoid using PMAP_PAGE_FLAGS_PV_TRACKED.

pointed out by tnn@, thanks


Revision tags: phil-wifi-20200406
# 1.68 14-Mar-2020 ad

pmap_remove_all(): Return a boolean value to indicate the behaviour. If
true, all mappings have been removed, the pmap is totally cleared out, and
UVM can then avoid doing the work to call pmap_remove() for each map entry.
If false, either nothing has been done, or some helpful arch-specific voodoo
has taken place.


Revision tags: is-mlppp-base
# 1.67 02-Mar-2020 ryo

oops, fix incorrect usage of daif_enable() in my previous commit.


# 1.66 29-Feb-2020 ryo

Fix pmap to work correctly with tagged addresses

- when fault, untag from address before passing to uvm/pmap functions
- pmap_extract() checks more strictly and consider the address tag


# 1.65 29-Feb-2020 ryo

use pmapboot_enter_range()


Revision tags: ad-namecache-base3
# 1.64 10-Feb-2020 ryo

use LIST(3) instead of TAILQ(3) to save one word in struct vm_page and struct pmap.

pointed out by riastradh@. thanks


# 1.63 03-Feb-2020 ryo

add support pmap_pv(9)

Patch originally from jmcneill@. thanks


# 1.62 03-Feb-2020 ryo

separate struct vm_page_md into vm_page_md and pmap_page
for preparation pmap_pv(9)


Revision tags: ad-namecache-base2 ad-namecache-base1
# 1.61 09-Jan-2020 ryo

fix behaviour mmap()/mprotect() when passed only PROT_EXEC.

when mmap()/mprotect() with only PROT_EXEC, syscall will be successful,
but the page actually hadn't been mapped.
it should be mapped with PROT_READ|PROT_EXEC implicitly. (r-x)


Revision tags: ad-namecache-base
# 1.60 30-Dec-2019 skrll

branches: 1.60.2;
Update pmap_map_chunk to allow L[12] block mappings and L3 page mappings


# 1.59 30-Dec-2019 skrll

Remove unnecessary brackets and unwrap a conditional. Same code before
and after.


# 1.58 28-Dec-2019 jmcneill

Do not use Early Write Acknowledge for PCIe I/O and config space.


# 1.57 27-Dec-2019 jmcneill

Enable early write acknowledge for device memory mappings.


# 1.56 19-Dec-2019 skrll

G/C kasan_shadow_map call in pmap_enter

pmap_growkernel calls kasan_shadow_map for KVA


# 1.55 18-Dec-2019 ryo

atomic_add_16() is not used in pmap.c anymore. no need decl here.


# 1.54 18-Dec-2019 ryo

space to tab


# 1.53 14-Dec-2019 skrll

Fix build... wire_count probably doesn't need atomics


# 1.52 13-Dec-2019 skrll

Fix KASAN support by calling kasan_shadow_map in pmap_growkernel


# 1.51 10-Dec-2019 ad

pg->phys_addr -> VM_PAGE_TO_PHYS(pg)


Revision tags: phil-wifi-20191119
# 1.50 14-Nov-2019 maxv

Mark several kASan functions with __nothing, to avoid annoying #ifdefs.
Same as kCSan and kMSan.


# 1.49 14-Nov-2019 maxv

Don't include "opt_kasan.h" when there's already <sys/asan.h> included.


# 1.48 29-Oct-2019 maya

Define PMAP_NEED_PROCWR, providing strategically placed i-cache
synchronization where just-changed memory is about to be executed.

Fixes SIGILLs seen when running Mono 6 on QEMU Cortex-A57.

ok ryo


# 1.47 22-Sep-2019 jmcneill

Disable translation table walks using TTBR0 while changing its value and
when deactivating a pmap. Fixes stability issues on Ampere eMAG CPUs.


# 1.46 20-Sep-2019 ryo

ref/mod bit should be set according to 'flags' argument, not 'prot'. r1.44 was incomplete.


# 1.45 13-Sep-2019 ryo

In pmap_devmap_bootstrap(), cpu_earlydevice_va_p() must not return true until *all* devmap tables have been enabled.
console mapping may be present in the last table.


# 1.44 07-Sep-2019 ryo

- remove incorrect KASSERT. mmap(2) with prot=PROT_WRITE calls pmap_enter(..., PROT_WRITE) internally.
- fix to update page reference flags when only PROT_WRITE or PROT_EXECUTE specified


# 1.43 15-Aug-2019 skrll

Make pmap_db_pte_print more terse so it's quicker on serial consoles


# 1.42 12-Aug-2019 skrll

Use PMAP_DEV in DEVMAP_ENTRY rather than pmap_map_chunk. It's clearer and
means pmap_map_chunk can be made to map other memory types.


Revision tags: netbsd-9-base phil-wifi-20190609
# 1.41 17-May-2019 mrg

branches: 1.41.2;
apply some __diagused.


Revision tags: isaki-audio2-base
# 1.40 08-Apr-2019 ryo

- free empty page tables pages if reach a certain usage.
- need to lock at removing an old pg (_pmap_remove_pv) in _pmap_enter()


# 1.39 06-Apr-2019 ryo

Fix race conditions about pmap_page_protect() and pmap_enter().

while handling same PTE by these functions in same time, there
is a critical path that the number of valid PTEs and wire_count
are inconsistent, and it caused KASSERT.
Need to hold a pv_lock while modifying them.


# 1.38 20-Mar-2019 ryo

spinkle __printflike(), and use PRIxxx


# 1.37 19-Mar-2019 ryo

- add ddb command "machine ttbr" to dump MMU tables.
- tidy up descriptions, usages and messages.


# 1.36 19-Mar-2019 ryo

- free L1-L3 pages that has been emptied by pmap_remove().
- if no memories, pmap_enter will return correctly ENOMEM if PMAP_CANFAIL, or wait until available any memories if !PMAP_CANFAIL.

These changes improves the stability when we use a huge virtual memory spaces with mmap.


# 1.35 06-Feb-2019 ryo

improve pmap_remove
- don't lock/unlock per page in pmap_remove()
- speedup pte lookup for continuous addresses
- bring out pool_cache_put(&_pmap_pv_pool, pv) from lock/unlock section


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226
# 1.34 21-Dec-2018 ryo

- add workaround for Cavium ThunderX errata 27456.
- add cpufuncs table in cpu_info. each cpu clusters may have different erratum. (e.g. big.LITTLE)


Revision tags: pgoyette-compat-1126
# 1.33 01-Nov-2018 maxv

Add kASan support for aarch64. Stack tracking needs more investigation
and will come in a separate commit.

Reviewed by ryo@ jmcneill@ skrll@.


# 1.32 31-Oct-2018 ryo

invalidate icache correctly.
l3pte_executable() should be used for only valid pte.


Revision tags: pgoyette-compat-1020
# 1.31 18-Oct-2018 skrll

Provide generic start code that assumes the MMU is off and caches are
disabled as per the linux booting protocol for ARMv6 and ARMv7 boards.
u-boot image type should be changed to 'linux' for correct behaviour.

The new start code builds a minimal "bootstrap" L1PT with cached access
disabled and uses the same table for all processors. AP startup is
performed in less steps and more code is written in C.

The bootstrap tables and stack are placed into an (orphaned) section
"_init_memory" which is given to uvm when it is no longer used.

Various kernels have been converted to use this code and tested. Some
boards were provided by TNF. Thanks!

The GENERIC kernel now boots on boards using the TEGRA, SUNXI and EXYNOS
kernels. The GENERIC kernel will also work on RPI2 using u-boot.

Thanks to martin@ and aymeric@ for testing on parallella and nanosoc
respectively


# 1.30 14-Oct-2018 skrll

Use __nothing


# 1.29 12-Oct-2018 ryo

add initial support of COMPAT_NETBSD32 on AArch64.
arm ELF32 EABI binaries could be execute in AArch32 state on AArch64. A32 THUMB mode is not supported yet.


# 1.28 12-Oct-2018 ryo

- cleanup checking address ranges with IN_RANGE macro
- change PM_ADDR_CHECK macro to KASSERTMSG
- restore fast lookup cases with IN_RANGE macro for pmap_extract changed in my previous commit.


# 1.27 12-Oct-2018 ryo

rewrite pmap_pte_lookup() to share similar code.


# 1.26 04-Oct-2018 ryo

cleanup locore, and changed the way to map memories during boot.
- add functions bootpage_enter() and bootpage_alloc() to adapt various layout
of physical memory map. especially for 64bit physical memory layout.
pmapboot_alloc() allocates pagetable pages from _end[].
- changed to map only the required amount for PA=VA identity mapping
(kernel image, UART device, and FDT blob) with L2_BLOCK(2Mbyte).
- changing page permission for kernel image, and making KSEG mapping are done
at cpu_kernel_vm_init() instead of at locore.
- optimize PTE entries with PTE Contiguous bit. it is enabled on devmap only for now.

reviewed by skrll@, thanks.


# 1.25 04-Oct-2018 ryo

* define LX_BLKPAG_{OS,ATTR}_* for OS dependent PTE attributes in pmap.h
* cleanup macros


Revision tags: pgoyette-compat-0930
# 1.24 17-Sep-2018 ryo

delete debug printf and KASSERT.


# 1.23 10-Sep-2018 maxv

Replace KDASSERT by panic.


# 1.22 10-Sep-2018 maxv

Rename _pmap_alloc_pdp -> pmap_alloc_pdp, and make it public.


# 1.21 10-Sep-2018 ryo

cleanup aarch64 mpstart and fdt bootstrap
* arm_cpu_hatch_arg is a bad idea. avoid serializing CPU startup, and eliminate arm_cpu_hatch_arg.
in mpstart, resolve own cpu index using array of cpu_mpidr[] (aarch64)
* add support fdt enable-method "spin-table"
* add support fdt enable-method "brcm,bcm2836-smp" (for 32bit RaspberryPi)
* use arm_fdt_cpu_bootstrap() instead of psci_fdt_bootstrap()
* rename "arm/fdt/psci_fdt.h" to "arm/fdt/psci_fdtvar.h" because of conflict of include file for needs-flag
* add devmap for cpu spin-table of raspberrypi3/aarch64
* no need to force hatch APs for raspberrypi3/arm32 ifndef MULTIPROCESSOR.
* fix to work pmap_extract(kerneltext/data/bss) even if before calling pmap_bootstrap

idea to use cpu_mpidr[] by jmcneill@. reviewd by skrll@. thanks.


Revision tags: pgoyette-compat-0906
# 1.20 27-Aug-2018 ryo

need to add VM_PROT_READ when pmap_kenter_pa(va, pa, VM_PROT_WRITE, 0) or pmap_kenter_pa(va, pa, VM_PROT_EXECUTE, 0).
VM_PROT_READ is treated as an access permission inernally.


# 1.19 11-Aug-2018 ryo

change to minimum invalidation of TLB.
specifying not only va but also asid, and not invalidate L0-L2 entry using tlbi_*_ll() if needed.


# 1.18 10-Aug-2018 ryo

treat kernel-exec attr and user-exec attr separately.
kernel cannot execute userland exec page, and user cannot execute kernel page.


# 1.17 06-Aug-2018 ryo

set kernel text/rodata readonly by default.
add function db_write_text() for setting ddb breakpoint.


# 1.16 31-Jul-2018 skrll

Define and use VPRINTF


Revision tags: pgoyette-compat-0728
# 1.15 27-Jul-2018 ryo

changes of pmap.c r1.13 seems to be unstable.
In order to invalidate icache, not to invalidate all icache,
but temporary to make the page writable and invalidate target address only.


# 1.14 24-Jul-2018 ryo

don't call pool_cache_put with locking pmap. pool_cache_put call pmap_kenter_pa internally.
(pool_cache_put_paddr -> pool_cache_put_slow -> pool_get -> pmap_kenter_pa)


# 1.13 23-Jul-2018 ryo

* fix icache invalidations.
* "ic ivau" (aarch64_icache_sync_range) with VA generates permission fault in some situations, therefore use KSEG address for now.


# 1.12 23-Jul-2018 ryo

rather than using flags to resolve nested locks, reserve pool_cache before locking.


# 1.11 21-Jul-2018 ryo

* avoid deadlock. mutex_owned() works only for adaptive lock, therefore we cannot use it for spinlock...
* add more NULL check
* clear pte when pmap_enter() fails


# 1.10 17-Jul-2018 ryo

Use __debugused


# 1.9 17-Jul-2018 christos

Add missing casts, remove unused variables.


# 1.8 09-Jul-2018 ryo

need locks in pmap_kremove() and pmap_fault_fixup()


Revision tags: phil-wifi-base pgoyette-compat-0625 pgoyette-compat-0521
# 1.7 20-May-2018 ryo

branches: 1.7.2;
pmap_enter() must update modified/referenced flags by 'flags' not 'prot'.


# 1.6 16-May-2018 ryo

Fix memory leak. it was leaking one page every pmap_create().
pm->pm_vmlist must be initialized before calling _pmap_alloc_pdp().


Revision tags: pgoyette-compat-0502
# 1.5 29-Apr-2018 ryo

fix KASSERT panic. pv_entry may not be exists in pvlist when pmap_remove().


# 1.4 29-Apr-2018 ryo

delete unused code


# 1.3 27-Apr-2018 ryo

fix instability behavior of bufcache on aarch64.
* fix to return correct ref/mod when PMAP_WIRED.
* changed to keep wired flags in pte instead of pv_entry, and cleanup.


Revision tags: pgoyette-compat-0422 pgoyette-compat-0415 pgoyette-compat-0407
# 1.2 01-Apr-2018 ryo

Add initial support for ARMv8 (AARCH64) (by nisimura@ and ryo@)

- sys/arch/evbarm64 is gone and integrated into sys/arch/evbarm. (by skrll@)
- add support fdt. evbarm/conf/GENERIC64 fdt (bcm2837,sunxi,tegra) based generic 64bit kernel config. (by skrll@, jmcneill@)


Revision tags: netbsd-8-2-RELEASE netbsd-8-1-RELEASE netbsd-8-1-RC1 netbsd-7-2-RELEASE netbsd-8-0-RELEASE netbsd-8-0-RC2 netbsd-8-0-RC1 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 netbsd-7-1-2-RELEASE pgoyette-compat-base netbsd-7-1-1-RELEASE tls-maxphys-base-20171202 matt-nb8-mediatek-base nick-nhusb-base-20170825 perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base pgoyette-localcount-20170320 netbsd-7-1-RELEASE netbsd-7-1-RC2 nick-nhusb-base-20170204 netbsd-7-nhusb-base-20170116 bouyer-socketcan-base pgoyette-localcount-20170107 netbsd-7-1-RC1 nick-nhusb-base-20161204 pgoyette-localcount-20161104 netbsd-7-0-2-RELEASE nick-nhusb-base-20161004 localcount-20160914 netbsd-7-nhusb-base pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907 nick-nhusb-base-20160529 netbsd-7-0-1-RELEASE nick-nhusb-base-20160422 nick-nhusb-base-20160319 nick-nhusb-base-20151226 netbsd-7-0-RELEASE nick-nhusb-base-20150921 netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 nick-nhusb-base-20150606 nick-nhusb-base-20150406 nick-nhusb-base tls-maxphys-base netbsd-7-base
# 1.1 10-Aug-2014 matt

branches: 1.1.4; 1.1.28;
Preliminary files for AARCH64 (64-bit ARM) support.
Enough for a distribution build.


# 1.141 20-Oct-2022 skrll

KNF


# 1.140 15-Oct-2022 jmcneill

Use "non-posted" instead of "strongly ordered" to describe nGnRnE mappings

Rename the following defines:
- _ARM_BUS_SPACE_MAP_STRONGLY_ORDERED to BUS_SPACE_MAP_NONPOSTED
- PMAP_DEV_SO to PMAP_DEV_NP
- LX_BLKPAG_ATTR_DEVICE_MEM_SO to LX_BLKPAG_ATTR_DEVICE_MEM_NP
Rename the following option:
- AARCH64_DEVICE_MEM_STRONGLY_ORDERED to AARCH64_DEVICE_MEM_NONPOSTED


Revision tags: bouyer-sunxi-drm-base
# 1.139 19-Aug-2022 ryo

Fixed a bug that pte's __BIT(63,48) could be set when accessing addresses above 0x0001000000000000 in /dev/mem with mmap().


# 1.138 19-Aug-2022 ryo

When accessed in mmap by the device pager, pmap_enter() may be called with prot == PROT_WRITE.


# 1.137 03-May-2022 skrll

Sprinkle some KASSERT(kpreempt_disabled());


# 1.136 27-Apr-2022 ryo

since pmap_activate_efirt() rewrites TTBR0, it is necessary to pmap_activate() again after pmap_deactivate_efirt() to restore the original TTBR0.

- Fix to do pmap_{de,}activate() before/after pmap_{,de}activate_efirt().
- moved kpreempt_{disable,enable}() to the caller since everything between
arm_efirt_md_enter() and arm_efirt_md_exit() should be kpreempt disabled.

ok skrll@


# 1.135 17-Apr-2022 skrll

Add the missing kpreempt_enable to pmap_deactivate_efirt


# 1.134 10-Apr-2022 skrll

No need to flush icache for EFI RT mappings as bootaa64.efi flushed
the full icache for us. (Also this avoids traps)


# 1.133 09-Apr-2022 riastradh

sys: Use membar_release/acquire around reference drop.

This just goes through my recent reference count membar audit and
changes membar_exit to membar_release and membar_enter to
membar_acquire -- this should make everything cheaper on most CPUs
without hurting correctness, because membar_acquire is generally
cheaper than membar_enter.


# 1.132 02-Apr-2022 skrll

Update to support EFI runtime outside the kernel virtual address space
by creating an EFI RT pmap that can be activated / deactivated when
required.

Adds support for EFI RT to ARM_MMU_EXTENDED (ASID) 32-bit Arm machines.

On Arm64 the usage of pmapboot_enter is reduced and the mappings are
created much later in the boot process -- now in cpu_startup_hook.
Backward compatiblity for KVA mapped RT from old bootaa64.efi is
maintained.

Adding support to other platforms should be easier as a result.


# 1.131 19-Mar-2022 skrll

Slight code re-organisation. NFCI.


# 1.130 12-Mar-2022 riastradh

sys: Membar audit around reference count releases.

If two threads are using an object that is freed when the reference
count goes to zero, we need to ensure that all memory operations
related to the object happen before freeing the object.

Using an atomic_dec_uint_nv(&refcnt) == 0 ensures that only one
thread takes responsibility for freeing, but it's not enough to
ensure that the other thread's memory operations happen before the
freeing.

Consider:

Thread A Thread B
obj->foo = 42; obj->baz = 73;
mumble(&obj->bar); grumble(&obj->quux);
/* membar_exit(); */ /* membar_exit(); */
atomic_dec -- not last atomic_dec -- last
/* membar_enter(); */
KASSERT(invariant(obj->foo,
obj->bar));
free_stuff(obj);

The memory barriers ensure that

obj->foo = 42;
mumble(&obj->bar);

in thread A happens before

KASSERT(invariant(obj->foo, obj->bar));
free_stuff(obj);

in thread B. Without them, this ordering is not guaranteed.

So in general it is necessary to do

membar_exit();
if (atomic_dec_uint_nv(&obj->refcnt) != 0)
return;
membar_enter();

to release a reference, for the `last one out hit the lights' style
of reference counting. (This is in contrast to the style where one
thread blocks new references and then waits under a lock for existing
ones to drain with a condvar -- no membar needed thanks to mutex(9).)

I searched for atomic_dec to find all these. Obviously we ought to
have a better abstraction for this because there's so much copypasta.
This is a stop-gap measure to fix actual bugs until we have that. It
would be nice if an abstraction could gracefully handle the different
styles of reference counting in use -- some years ago I drafted an
API for this, but making it cover everything got a little out of hand
(particularly with struct vnode::v_usecount) and I ended up setting
it aside to work on psref/localcount instead for better scalability.

I got bored of adding #ifdef __HAVE_ATOMIC_AS_MEMBAR everywhere, so I
only put it on things that look performance-critical on 5sec review.
We should really adopt membar_enter_preatomic/membar_exit_postatomic
or something (except they are applicable only to atomic r/m/w, not to
atomic_load/store_*, making the naming annoying) and get rid of all
the ifdefs.


# 1.129 05-Mar-2022 skrll

Slight comment improvement.


# 1.128 16-Feb-2022 andvar

fix various typos, mainly in comments.


# 1.127 31-Jan-2022 ryo

add support Hardware updates to Access flag and Dirty state (FEAT_HAFDBS)

- The DBM bit of the PTE is now used to determine if it is writable, and
the AF bit is treated entirely as a reference bit. A valid PTE is always
treated as readable. There can be no valid PTE that is not readable.
- LX_BLKPAG_OS_{READ,WRITE} are used only for debugging purposes,
and has been superseded by LX_BLKPAG_AF and LX_BLKPAG_DBM.
- Improve comment

The need for reference/modify emulation has been eliminated,
and access/permission faults have been reduced, however,
there has been little change in overall performance.


# 1.126 31-Jan-2022 ryo

Skip unnecessary PTE operations and TLB invalidation.


# 1.125 16-Jan-2022 rillig

aarch64/pmap: remove stray semicolon

No binary change.


# 1.124 15-Jan-2022 skrll

The translations that need invalidation are always last level so remove
the (dubious) logic around tracking the level. The "any level" TLB
invalidation maintenance operation are used, but this may change after
further testing.

before
======
1661.0u 420.2s 2:53.82 1197.3% 231+29k 10+33918io 102pf+0w
1646.8u 425.2s 2:52.96 1198.0% 232+29k 1+33937io 49pf+0w
1647.9u 425.7s 2:52.58 1201.6% 232+29k 0+33940io 32pf+0w

After
=====
1602.5u 420.8s 2:49.09 1196.6% 238+30k 24+33893io 54pf+0w
1600.7u 421.3s 2:51.53 1178.8% 238+30k 1+33914io 33pf+0w
1597.5u 424.3s 2:50.46 1186.1% 238+30k 0+33915io 17pf+0w

LGTM from ryo@


# 1.123 14-Jan-2022 skrll

Restore the previous pmap_remove_all behaviour as the new method meant
the n1sdp couldn't complete a build.

No noticeable change in kernel build performance.


# 1.122 04-Jan-2022 skrll

KNF


# 1.121 10-Dec-2021 andvar

s/occured/occurred/ in comments, log messages and man pages.


# 1.120 07-Dec-2021 andvar

fix various typos, mainly in comments.


# 1.119 23-Oct-2021 skrll

Fix non-UVMHIST build


# 1.118 16-Oct-2021 ryo

fix non-MULTIPROCESSOR build


# 1.117 10-Oct-2021 skrll

Use sys/uvm/pmap/pmap_tlb.c on Aarch64 in the same way that some Arm, MIPS,
and some PPC kernels do. This removes the limitation of 256 processes on
CPUs with 8bit ASID field, e.g. Apple M1.

Additionally the following changes have been made

- removed a couple of unnecessary aarch64_tlbi_all calls
- removed any invalidation after freeing page tables due to
_pmap_sweep_pdp. This was never necessary afaict.
- all kernel mappings are marked global and userland mapping not-global.

Performance testing hasn't show a significant difference. The data here
is from building a kernel on an lx2k system with nvme.

before
1489.6u 400.4s 2:40.65 1176.5% 228+224k 0+32289io 57pf+0w
1482.6u 403.2s 2:38.49 1189.9% 228+222k 0+32274io 46pf+0w
1485.4u 402.2s 2:37.27 1200.2% 228+222k 0+32275io 12pf+0w

after
1493.9u 404.6s 2:37.50 1205.4% 227+221k 0+32265io 48pf+0w
1485.0u 408.0s 2:38.54 1194.0% 227+222k 0+32272io 36pf+0w
1484.3u 407.0s 2:35.88 1213.3% 228+224k 0+32268io 14pf+0w

>>> stats.ttest_ind([160.65,158.49,157.27], [157.5,158.54,155.88])
Ttest_indResult(statistic=1.1923622711296888, pvalue=0.2990182944606766)
>>>


# 1.116 30-Sep-2021 skrll

Ensure TCR_EPD0 is set on entry to pmap_activate and ensure it is set as
early as possible for APs.


# 1.115 26-Sep-2021 skrll

Use UVMHIST_CALLARGS


# 1.114 26-Sep-2021 skrll

'\n' is not required in KASSERTMSG either.


# 1.113 26-Sep-2021 skrll

"\n" is not required in KERNHIST


# 1.112 15-Sep-2021 skrll

Use __SHIFTIN. Same code before and after.


# 1.111 12-Sep-2021 skrll

pmap_page_remove: simply and reduce the code size slightly.


# 1.110 09-Sep-2021 skrll

In pmap_icache_sync_range change

for (...) {
...
if (condition) {
// do stuff
}
}

to

for (...) {
...
if (!conditional)
continue;
// do stuff
}

to save on indentation. Same code (modulo register usage) before and
after.


# 1.109 09-Sep-2021 skrll

KNF


Revision tags: thorpej-i2c-spi-conf2-base thorpej-futex2-base thorpej-cfargs2-base cjep_sun2x-base1 cjep_sun2x-base cjep_staticlib_x-base1 thorpej-i2c-spi-conf-base
# 1.108 29-May-2021 skrll

Deal with the pmap limitation of maxproc in a more complete way and
recognise CPUs with only 8bit ASIDs.


Revision tags: cjep_staticlib_x-base
# 1.107 30-Apr-2021 skrll

branches: 1.107.2;
Make the ddb for pmap / pte information pmap agnostic


# 1.106 29-Apr-2021 skrll

Remove some unnecessary tlb invalidate in pmap_growkernel and ASAN shadow
map. Ensure the shadow map mappings are visible to the TLB walkers.


# 1.105 21-Apr-2021 ryo

branches: 1.105.2;
added more attributes of PTE displayed by "ddb>machine pte"


Revision tags: thorpej-cfargs-base
# 1.104 17-Apr-2021 mrg

remove KERNHIST_INIT_STATIC(). it stradles the line between usable
early in boot and broken early in boot by requiring a partly static
structure with another structure that must be present by the time
any uses are performed. theoretically platform code could allocate
a chunk while seting up memory and assign it here, giving a dynamic
sizing for the entry list, but the reality is that all users have
a statically allocated entry list as well.

the existing KERNHIST_LINK_STATIC() is used in conjunction with
KERNHIST_INITIALIZER() instead.

this stops a NULL pointer deref when the _LOG() macro is called
before the storage is linked in, which happens with GCC 10 on OCTEON
with UVMHIST enabled, crashing in very early kernel init.


Revision tags: thorpej-futex-base
# 1.103 09-Mar-2021 ryo

branches: 1.103.2;
fix build error without options DDB.

kvtopte() is referenced from arm/acpi/acpi_machdep.c


# 1.102 13-Feb-2021 ryo

No assignment is needed here.

the loop in pmap_page_remove() always removes the first pv,
and since the list is managed by _pmap_remove_pv(), pp->pp_pv.pv_next always points to the first.


# 1.101 01-Feb-2021 ryo

It is enough to make a page accessible instead of writable.
same fix as r1.76


# 1.100 31-Jan-2021 ryo

implement pmap_remove_all().

The size of struct pv_entry has increased, but speed of kernel build has improved by about 1%
exec and exit should have been improved.


# 1.99 20-Dec-2020 skrll

Improve the English in the previous comment fix.


# 1.98 19-Dec-2020 skrll

Tweak a comment


# 1.97 11-Dec-2020 skrll

s:aarch64/cpufunc.h:arm/cpufunc.h:

a baby step in the grand arm header unification challenge


# 1.96 10-Nov-2020 skrll

AA64 is not MIPS.

Change all KSEG references to directmap


# 1.95 07-Nov-2020 skrll

In pmap_devmap_bootstrap only set pmap_devmap_bootstrap_done if there
is an entry and ALL of the entries have been done. The entry required
for EARLYCONS might not be the first/only one...


# 1.94 01-Nov-2020 jmcneill

branches: 1.94.2;
No need to disable translation table walks in pmap_activate().


# 1.93 22-Oct-2020 skrll

Use the isb macro - missed in previous commit


# 1.92 22-Oct-2020 skrll

Use the dmb/dsb/isb macros... if nothing else they're all now consistent
about the "memory" assembler contraint.

No binary change


# 1.91 28-Sep-2020 skrll

Only set pmap_devmap_bootstrap_done if something gets mapped.

Think acpi_platform_devmap


# 1.90 19-Sep-2020 skrll

Make __md_palloc pmap agnostic (think sys/uvm/pmap)


# 1.89 14-Sep-2020 ryo

PID_MAX is just an initial value (soft maximum). Don't use it for CTASSERT.
defined __HAVE_CPU_MAXPROC to use function cpu_maxproc().

pointed out by mrg@, thanks.


# 1.88 06-Sep-2020 ryo

Fix panic caused by modload. http://mail-index.netbsd.org/port-arm/2020/08/30/msg006960.html

The address space reserved for modules may not be mapped in L1-L3.


# 1.87 14-Aug-2020 skrll

Whitespace


# 1.86 12-Aug-2020 skrll

Part IV of ad's performance improvements for aarch64

- Implement pmap_growkernel(), and update kernel pmap's stats with atomics.

- Then, pmap_kenter_pa() and pmap_kremove() no longer need to allocate
memory nor take pm_lock, because they only modify L3 PTEs.

- Then, pm_lock and pp_lock can be adaptive mutexes at IPL_NONE which are
cheaper than spin mutexes.

- Take the pmap's lock in pmap_extract() if not the kernel's pmap, otherwise
pmap_extract() might see inconsistent state.


# 1.85 09-Aug-2020 skrll

Fix another UVMHIST so it doesn't use %s


# 1.84 16-Jul-2020 skrll

pmapboot_enter simplication
- bootpage_alloc in asm becomes pmapboot_pagealloc in C
- PMAPBOOT_ENTER_NOBLOCK is removed as it's not used
- PMAPBOOT_ENTER_NOOVERWRITE is removed as it's now always on
- physpage_allocator argument is removed as it's always
pmapboot_pagealloc
- Support for EARLYCONS without CONSADDR is removed so that the identity
map for CONSADDR is always known.

For the assembly files:
2 files changed, 40 insertions(+), 89 deletions(-)

LGTM ryo


# 1.83 04-Jul-2020 rin

Use tlen for temporary length variable instead of l, which is usually
used for struct lwp *.

No binary changes.


# 1.82 02-Jul-2020 rin

pmap_procwr(): sync icache even if p != curproc. This fixes applications
like GDB for arm32, that rewrite text of other process.

Thanks to ryo@ for discussion.


# 1.81 02-Jul-2020 rin

Set uvmexp.ncolors appropriately, which is required for some CPU
models with VIPT icache.

Otherwise, alias in virtual address results in inconsistent results,
at least for applications that rewrite text of other process, e.g.,
GDB for arm32.

Also, this hopefully fixes other unexpected failures due to alias.

Confirmed that there's no observable regression in performance;
difference in ``time make -j8'' for GENERIC64 kernel on BCM2837
with and without setting uvmexp.ncolors is within 0.1%.

Thanks to ryo@ for discussion.


# 1.80 27-Jun-2020 rin

Fix typo in name of evcnt(4) counter.


# 1.79 24-Jun-2020 ryo

Fix bug with incorrect range calculation when doing icache sync.
This is called by sysarch(ARM_SYNC_ICACHE) from aarch32 (compat_netbsd32) emul process.

pointed out by rin@, thanks.

XXX pullup-9


# 1.78 14-Jun-2020 ad

- Fix a lock order reversal in pmap_page_protect().

- Make sure pmap is always locked when updating stats; atomics no longer
needed to do that.

- Remove unneeded traversal of pv list in pmap_enter_pv().

- Shrink struct vm_page from 136 to 128 bytes (cache line sized) and struct
pv_entry from 48 to 32 bytes (power of 2 sized).

- Embed a pv_entry in each vm_page. This means PV entries don't need to
be allocated for private anonymous memory / COW pages / most UBC mappings.
Dynamic PV entries are then used only for stuff like shared libraries and
shared memory.

Proposed on port-arm@.


# 1.77 10-Jun-2020 ad

- Wired/resident stats shouldn't covered by PMAPCOUNTERS.
- Rename need_update_pv -> need_enter_pv.

Ok ryo@


# 1.76 01-Jun-2020 ryo

no need to make the PTE writable to do icache_sync, enough to accessible.


# 1.75 15-May-2020 skrll

Use __diagused


# 1.74 15-May-2020 tnn

fix non-diag build


# 1.73 14-May-2020 skrll

Use MUTEX_NODEBUG for PV locks as is commonly done. OK ryo.


# 1.72 13-May-2020 jmcneill

Implement pmap_extract_coherency


Revision tags: bouyer-xenpvh-base2 phil-wifi-20200421 bouyer-xenpvh-base1
# 1.71 18-Apr-2020 skrll

PMAP_DEBUG has been deleted on arm


# 1.70 13-Apr-2020 maxv

Add support for Branch Target Identification (BTI).

On the executable pages that have the GP (Guarded Page) bit, the semantic
of the "br" and "blr" instructions is changed: the CPU expects the first
instruction of the jump/call target to be "bti", and faults if it isn't.

We add the GP bit on the kernel .text pages (and incidentally the .rodata
pages, but we don't care). The compiler adds a "bti c" instruction at the
beginning of each C function. We modify the ENTRY() macros to manually add
"bti c" in the asm functions.

cpuswitch.S needs a specific change: with "br x27" the CPU expects "bti j",
which is bad because the functions begin with "bti c"; switch to "br x16",
for the CPU to accept "bti c".

BTI helps defend against JOP/COP. Tested on Qemu.


Revision tags: phil-wifi-20200411 bouyer-xenpvh-base
# 1.69 08-Apr-2020 ryo

branches: 1.69.2;
use PMAP_PAGE_INIT() to initialize mutex in pmap_page.

VM_MDPAGE_INIT() in pmap_free_pdp() had initialized pp_flags,
so it unintentionally cleared PMAP_PAGE_FLAGS_PV_TRACKED.
use PMAP_PAGE_INIT to avoid using PMAP_PAGE_FLAGS_PV_TRACKED.

pointed out by tnn@, thanks


Revision tags: phil-wifi-20200406
# 1.68 14-Mar-2020 ad

pmap_remove_all(): Return a boolean value to indicate the behaviour. If
true, all mappings have been removed, the pmap is totally cleared out, and
UVM can then avoid doing the work to call pmap_remove() for each map entry.
If false, either nothing has been done, or some helpful arch-specific voodoo
has taken place.


Revision tags: is-mlppp-base
# 1.67 02-Mar-2020 ryo

oops, fix incorrect usage of daif_enable() in my previous commit.


# 1.66 29-Feb-2020 ryo

Fix pmap to work correctly with tagged addresses

- when fault, untag from address before passing to uvm/pmap functions
- pmap_extract() checks more strictly and consider the address tag


# 1.65 29-Feb-2020 ryo

use pmapboot_enter_range()


Revision tags: ad-namecache-base3
# 1.64 10-Feb-2020 ryo

use LIST(3) instead of TAILQ(3) to save one word in struct vm_page and struct pmap.

pointed out by riastradh@. thanks


# 1.63 03-Feb-2020 ryo

add support pmap_pv(9)

Patch originally from jmcneill@. thanks


# 1.62 03-Feb-2020 ryo

separate struct vm_page_md into vm_page_md and pmap_page
for preparation pmap_pv(9)


Revision tags: ad-namecache-base2 ad-namecache-base1
# 1.61 09-Jan-2020 ryo

fix behaviour mmap()/mprotect() when passed only PROT_EXEC.

when mmap()/mprotect() with only PROT_EXEC, syscall will be successful,
but the page actually hadn't been mapped.
it should be mapped with PROT_READ|PROT_EXEC implicitly. (r-x)


Revision tags: ad-namecache-base
# 1.60 30-Dec-2019 skrll

branches: 1.60.2;
Update pmap_map_chunk to allow L[12] block mappings and L3 page mappings


# 1.59 30-Dec-2019 skrll

Remove unnecessary brackets and unwrap a conditional. Same code before
and after.


# 1.58 28-Dec-2019 jmcneill

Do not use Early Write Acknowledge for PCIe I/O and config space.


# 1.57 27-Dec-2019 jmcneill

Enable early write acknowledge for device memory mappings.


# 1.56 19-Dec-2019 skrll

G/C kasan_shadow_map call in pmap_enter

pmap_growkernel calls kasan_shadow_map for KVA


# 1.55 18-Dec-2019 ryo

atomic_add_16() is not used in pmap.c anymore. no need decl here.


# 1.54 18-Dec-2019 ryo

space to tab


# 1.53 14-Dec-2019 skrll

Fix build... wire_count probably doesn't need atomics


# 1.52 13-Dec-2019 skrll

Fix KASAN support by calling kasan_shadow_map in pmap_growkernel


# 1.51 10-Dec-2019 ad

pg->phys_addr -> VM_PAGE_TO_PHYS(pg)


Revision tags: phil-wifi-20191119
# 1.50 14-Nov-2019 maxv

Mark several kASan functions with __nothing, to avoid annoying #ifdefs.
Same as kCSan and kMSan.


# 1.49 14-Nov-2019 maxv

Don't include "opt_kasan.h" when there's already <sys/asan.h> included.


# 1.48 29-Oct-2019 maya

Define PMAP_NEED_PROCWR, providing strategically placed i-cache
synchronization where just-changed memory is about to be executed.

Fixes SIGILLs seen when running Mono 6 on QEMU Cortex-A57.

ok ryo


# 1.47 22-Sep-2019 jmcneill

Disable translation table walks using TTBR0 while changing its value and
when deactivating a pmap. Fixes stability issues on Ampere eMAG CPUs.


# 1.46 20-Sep-2019 ryo

ref/mod bit should be set according to 'flags' argument, not 'prot'. r1.44 was incomplete.


# 1.45 13-Sep-2019 ryo

In pmap_devmap_bootstrap(), cpu_earlydevice_va_p() must not return true until *all* devmap tables have been enabled.
console mapping may be present in the last table.


# 1.44 07-Sep-2019 ryo

- remove incorrect KASSERT. mmap(2) with prot=PROT_WRITE calls pmap_enter(..., PROT_WRITE) internally.
- fix to update page reference flags when only PROT_WRITE or PROT_EXECUTE specified


# 1.43 15-Aug-2019 skrll

Make pmap_db_pte_print more terse so it's quicker on serial consoles


# 1.42 12-Aug-2019 skrll

Use PMAP_DEV in DEVMAP_ENTRY rather than pmap_map_chunk. It's clearer and
means pmap_map_chunk can be made to map other memory types.


Revision tags: netbsd-9-base phil-wifi-20190609
# 1.41 17-May-2019 mrg

branches: 1.41.2;
apply some __diagused.


Revision tags: isaki-audio2-base
# 1.40 08-Apr-2019 ryo

- free empty page tables pages if reach a certain usage.
- need to lock at removing an old pg (_pmap_remove_pv) in _pmap_enter()


# 1.39 06-Apr-2019 ryo

Fix race conditions about pmap_page_protect() and pmap_enter().

while handling same PTE by these functions in same time, there
is a critical path that the number of valid PTEs and wire_count
are inconsistent, and it caused KASSERT.
Need to hold a pv_lock while modifying them.


# 1.38 20-Mar-2019 ryo

spinkle __printflike(), and use PRIxxx


# 1.37 19-Mar-2019 ryo

- add ddb command "machine ttbr" to dump MMU tables.
- tidy up descriptions, usages and messages.


# 1.36 19-Mar-2019 ryo

- free L1-L3 pages that has been emptied by pmap_remove().
- if no memories, pmap_enter will return correctly ENOMEM if PMAP_CANFAIL, or wait until available any memories if !PMAP_CANFAIL.

These changes improves the stability when we use a huge virtual memory spaces with mmap.


# 1.35 06-Feb-2019 ryo

improve pmap_remove
- don't lock/unlock per page in pmap_remove()
- speedup pte lookup for continuous addresses
- bring out pool_cache_put(&_pmap_pv_pool, pv) from lock/unlock section


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226
# 1.34 21-Dec-2018 ryo

- add workaround for Cavium ThunderX errata 27456.
- add cpufuncs table in cpu_info. each cpu clusters may have different erratum. (e.g. big.LITTLE)


Revision tags: pgoyette-compat-1126
# 1.33 01-Nov-2018 maxv

Add kASan support for aarch64. Stack tracking needs more investigation
and will come in a separate commit.

Reviewed by ryo@ jmcneill@ skrll@.


# 1.32 31-Oct-2018 ryo

invalidate icache correctly.
l3pte_executable() should be used for only valid pte.


Revision tags: pgoyette-compat-1020
# 1.31 18-Oct-2018 skrll

Provide generic start code that assumes the MMU is off and caches are
disabled as per the linux booting protocol for ARMv6 and ARMv7 boards.
u-boot image type should be changed to 'linux' for correct behaviour.

The new start code builds a minimal "bootstrap" L1PT with cached access
disabled and uses the same table for all processors. AP startup is
performed in less steps and more code is written in C.

The bootstrap tables and stack are placed into an (orphaned) section
"_init_memory" which is given to uvm when it is no longer used.

Various kernels have been converted to use this code and tested. Some
boards were provided by TNF. Thanks!

The GENERIC kernel now boots on boards using the TEGRA, SUNXI and EXYNOS
kernels. The GENERIC kernel will also work on RPI2 using u-boot.

Thanks to martin@ and aymeric@ for testing on parallella and nanosoc
respectively


# 1.30 14-Oct-2018 skrll

Use __nothing


# 1.29 12-Oct-2018 ryo

add initial support of COMPAT_NETBSD32 on AArch64.
arm ELF32 EABI binaries could be execute in AArch32 state on AArch64. A32 THUMB mode is not supported yet.


# 1.28 12-Oct-2018 ryo

- cleanup checking address ranges with IN_RANGE macro
- change PM_ADDR_CHECK macro to KASSERTMSG
- restore fast lookup cases with IN_RANGE macro for pmap_extract changed in my previous commit.


# 1.27 12-Oct-2018 ryo

rewrite pmap_pte_lookup() to share similar code.


# 1.26 04-Oct-2018 ryo

cleanup locore, and changed the way to map memories during boot.
- add functions bootpage_enter() and bootpage_alloc() to adapt various layout
of physical memory map. especially for 64bit physical memory layout.
pmapboot_alloc() allocates pagetable pages from _end[].
- changed to map only the required amount for PA=VA identity mapping
(kernel image, UART device, and FDT blob) with L2_BLOCK(2Mbyte).
- changing page permission for kernel image, and making KSEG mapping are done
at cpu_kernel_vm_init() instead of at locore.
- optimize PTE entries with PTE Contiguous bit. it is enabled on devmap only for now.

reviewed by skrll@, thanks.


# 1.25 04-Oct-2018 ryo

* define LX_BLKPAG_{OS,ATTR}_* for OS dependent PTE attributes in pmap.h
* cleanup macros


Revision tags: pgoyette-compat-0930
# 1.24 17-Sep-2018 ryo

delete debug printf and KASSERT.


# 1.23 10-Sep-2018 maxv

Replace KDASSERT by panic.


# 1.22 10-Sep-2018 maxv

Rename _pmap_alloc_pdp -> pmap_alloc_pdp, and make it public.


# 1.21 10-Sep-2018 ryo

cleanup aarch64 mpstart and fdt bootstrap
* arm_cpu_hatch_arg is a bad idea. avoid serializing CPU startup, and eliminate arm_cpu_hatch_arg.
in mpstart, resolve own cpu index using array of cpu_mpidr[] (aarch64)
* add support fdt enable-method "spin-table"
* add support fdt enable-method "brcm,bcm2836-smp" (for 32bit RaspberryPi)
* use arm_fdt_cpu_bootstrap() instead of psci_fdt_bootstrap()
* rename "arm/fdt/psci_fdt.h" to "arm/fdt/psci_fdtvar.h" because of conflict of include file for needs-flag
* add devmap for cpu spin-table of raspberrypi3/aarch64
* no need to force hatch APs for raspberrypi3/arm32 ifndef MULTIPROCESSOR.
* fix to work pmap_extract(kerneltext/data/bss) even if before calling pmap_bootstrap

idea to use cpu_mpidr[] by jmcneill@. reviewd by skrll@. thanks.


Revision tags: pgoyette-compat-0906
# 1.20 27-Aug-2018 ryo

need to add VM_PROT_READ when pmap_kenter_pa(va, pa, VM_PROT_WRITE, 0) or pmap_kenter_pa(va, pa, VM_PROT_EXECUTE, 0).
VM_PROT_READ is treated as an access permission inernally.


# 1.19 11-Aug-2018 ryo

change to minimum invalidation of TLB.
specifying not only va but also asid, and not invalidate L0-L2 entry using tlbi_*_ll() if needed.


# 1.18 10-Aug-2018 ryo

treat kernel-exec attr and user-exec attr separately.
kernel cannot execute userland exec page, and user cannot execute kernel page.


# 1.17 06-Aug-2018 ryo

set kernel text/rodata readonly by default.
add function db_write_text() for setting ddb breakpoint.


# 1.16 31-Jul-2018 skrll

Define and use VPRINTF


Revision tags: pgoyette-compat-0728
# 1.15 27-Jul-2018 ryo

changes of pmap.c r1.13 seems to be unstable.
In order to invalidate icache, not to invalidate all icache,
but temporary to make the page writable and invalidate target address only.


# 1.14 24-Jul-2018 ryo

don't call pool_cache_put with locking pmap. pool_cache_put call pmap_kenter_pa internally.
(pool_cache_put_paddr -> pool_cache_put_slow -> pool_get -> pmap_kenter_pa)


# 1.13 23-Jul-2018 ryo

* fix icache invalidations.
* "ic ivau" (aarch64_icache_sync_range) with VA generates permission fault in some situations, therefore use KSEG address for now.


# 1.12 23-Jul-2018 ryo

rather than using flags to resolve nested locks, reserve pool_cache before locking.


# 1.11 21-Jul-2018 ryo

* avoid deadlock. mutex_owned() works only for adaptive lock, therefore we cannot use it for spinlock...
* add more NULL check
* clear pte when pmap_enter() fails


# 1.10 17-Jul-2018 ryo

Use __debugused


# 1.9 17-Jul-2018 christos

Add missing casts, remove unused variables.


# 1.8 09-Jul-2018 ryo

need locks in pmap_kremove() and pmap_fault_fixup()


Revision tags: phil-wifi-base pgoyette-compat-0625 pgoyette-compat-0521
# 1.7 20-May-2018 ryo

branches: 1.7.2;
pmap_enter() must update modified/referenced flags by 'flags' not 'prot'.


# 1.6 16-May-2018 ryo

Fix memory leak. it was leaking one page every pmap_create().
pm->pm_vmlist must be initialized before calling _pmap_alloc_pdp().


Revision tags: pgoyette-compat-0502
# 1.5 29-Apr-2018 ryo

fix KASSERT panic. pv_entry may not be exists in pvlist when pmap_remove().


# 1.4 29-Apr-2018 ryo

delete unused code


# 1.3 27-Apr-2018 ryo

fix instability behavior of bufcache on aarch64.
* fix to return correct ref/mod when PMAP_WIRED.
* changed to keep wired flags in pte instead of pv_entry, and cleanup.


Revision tags: pgoyette-compat-0422 pgoyette-compat-0415 pgoyette-compat-0407
# 1.2 01-Apr-2018 ryo

Add initial support for ARMv8 (AARCH64) (by nisimura@ and ryo@)

- sys/arch/evbarm64 is gone and integrated into sys/arch/evbarm. (by skrll@)
- add support fdt. evbarm/conf/GENERIC64 fdt (bcm2837,sunxi,tegra) based generic 64bit kernel config. (by skrll@, jmcneill@)


Revision tags: netbsd-8-2-RELEASE netbsd-8-1-RELEASE netbsd-8-1-RC1 netbsd-7-2-RELEASE netbsd-8-0-RELEASE netbsd-8-0-RC2 netbsd-8-0-RC1 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 netbsd-7-1-2-RELEASE pgoyette-compat-base netbsd-7-1-1-RELEASE tls-maxphys-base-20171202 matt-nb8-mediatek-base nick-nhusb-base-20170825 perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base pgoyette-localcount-20170320 netbsd-7-1-RELEASE netbsd-7-1-RC2 nick-nhusb-base-20170204 netbsd-7-nhusb-base-20170116 bouyer-socketcan-base pgoyette-localcount-20170107 netbsd-7-1-RC1 nick-nhusb-base-20161204 pgoyette-localcount-20161104 netbsd-7-0-2-RELEASE nick-nhusb-base-20161004 localcount-20160914 netbsd-7-nhusb-base pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907 nick-nhusb-base-20160529 netbsd-7-0-1-RELEASE nick-nhusb-base-20160422 nick-nhusb-base-20160319 nick-nhusb-base-20151226 netbsd-7-0-RELEASE nick-nhusb-base-20150921 netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 nick-nhusb-base-20150606 nick-nhusb-base-20150406 nick-nhusb-base tls-maxphys-base netbsd-7-base
# 1.1 10-Aug-2014 matt

branches: 1.1.4; 1.1.28;
Preliminary files for AARCH64 (64-bit ARM) support.
Enough for a distribution build.


# 1.140 15-Oct-2022 jmcneill

Use "non-posted" instead of "strongly ordered" to describe nGnRnE mappings

Rename the following defines:
- _ARM_BUS_SPACE_MAP_STRONGLY_ORDERED to BUS_SPACE_MAP_NONPOSTED
- PMAP_DEV_SO to PMAP_DEV_NP
- LX_BLKPAG_ATTR_DEVICE_MEM_SO to LX_BLKPAG_ATTR_DEVICE_MEM_NP
Rename the following option:
- AARCH64_DEVICE_MEM_STRONGLY_ORDERED to AARCH64_DEVICE_MEM_NONPOSTED


Revision tags: bouyer-sunxi-drm-base
# 1.139 19-Aug-2022 ryo

Fixed a bug that pte's __BIT(63,48) could be set when accessing addresses above 0x0001000000000000 in /dev/mem with mmap().


# 1.138 19-Aug-2022 ryo

When accessed in mmap by the device pager, pmap_enter() may be called with prot == PROT_WRITE.


# 1.137 03-May-2022 skrll

Sprinkle some KASSERT(kpreempt_disabled());


# 1.136 27-Apr-2022 ryo

since pmap_activate_efirt() rewrites TTBR0, it is necessary to pmap_activate() again after pmap_deactivate_efirt() to restore the original TTBR0.

- Fix to do pmap_{de,}activate() before/after pmap_{,de}activate_efirt().
- moved kpreempt_{disable,enable}() to the caller since everything between
arm_efirt_md_enter() and arm_efirt_md_exit() should be kpreempt disabled.

ok skrll@


# 1.135 17-Apr-2022 skrll

Add the missing kpreempt_enable to pmap_deactivate_efirt


# 1.134 10-Apr-2022 skrll

No need to flush icache for EFI RT mappings as bootaa64.efi flushed
the full icache for us. (Also this avoids traps)


# 1.133 09-Apr-2022 riastradh

sys: Use membar_release/acquire around reference drop.

This just goes through my recent reference count membar audit and
changes membar_exit to membar_release and membar_enter to
membar_acquire -- this should make everything cheaper on most CPUs
without hurting correctness, because membar_acquire is generally
cheaper than membar_enter.


# 1.132 02-Apr-2022 skrll

Update to support EFI runtime outside the kernel virtual address space
by creating an EFI RT pmap that can be activated / deactivated when
required.

Adds support for EFI RT to ARM_MMU_EXTENDED (ASID) 32-bit Arm machines.

On Arm64 the usage of pmapboot_enter is reduced and the mappings are
created much later in the boot process -- now in cpu_startup_hook.
Backward compatiblity for KVA mapped RT from old bootaa64.efi is
maintained.

Adding support to other platforms should be easier as a result.


# 1.131 19-Mar-2022 skrll

Slight code re-organisation. NFCI.


# 1.130 12-Mar-2022 riastradh

sys: Membar audit around reference count releases.

If two threads are using an object that is freed when the reference
count goes to zero, we need to ensure that all memory operations
related to the object happen before freeing the object.

Using an atomic_dec_uint_nv(&refcnt) == 0 ensures that only one
thread takes responsibility for freeing, but it's not enough to
ensure that the other thread's memory operations happen before the
freeing.

Consider:

Thread A Thread B
obj->foo = 42; obj->baz = 73;
mumble(&obj->bar); grumble(&obj->quux);
/* membar_exit(); */ /* membar_exit(); */
atomic_dec -- not last atomic_dec -- last
/* membar_enter(); */
KASSERT(invariant(obj->foo,
obj->bar));
free_stuff(obj);

The memory barriers ensure that

obj->foo = 42;
mumble(&obj->bar);

in thread A happens before

KASSERT(invariant(obj->foo, obj->bar));
free_stuff(obj);

in thread B. Without them, this ordering is not guaranteed.

So in general it is necessary to do

membar_exit();
if (atomic_dec_uint_nv(&obj->refcnt) != 0)
return;
membar_enter();

to release a reference, for the `last one out hit the lights' style
of reference counting. (This is in contrast to the style where one
thread blocks new references and then waits under a lock for existing
ones to drain with a condvar -- no membar needed thanks to mutex(9).)

I searched for atomic_dec to find all these. Obviously we ought to
have a better abstraction for this because there's so much copypasta.
This is a stop-gap measure to fix actual bugs until we have that. It
would be nice if an abstraction could gracefully handle the different
styles of reference counting in use -- some years ago I drafted an
API for this, but making it cover everything got a little out of hand
(particularly with struct vnode::v_usecount) and I ended up setting
it aside to work on psref/localcount instead for better scalability.

I got bored of adding #ifdef __HAVE_ATOMIC_AS_MEMBAR everywhere, so I
only put it on things that look performance-critical on 5sec review.
We should really adopt membar_enter_preatomic/membar_exit_postatomic
or something (except they are applicable only to atomic r/m/w, not to
atomic_load/store_*, making the naming annoying) and get rid of all
the ifdefs.


# 1.129 05-Mar-2022 skrll

Slight comment improvement.


# 1.128 16-Feb-2022 andvar

fix various typos, mainly in comments.


# 1.127 31-Jan-2022 ryo

add support Hardware updates to Access flag and Dirty state (FEAT_HAFDBS)

- The DBM bit of the PTE is now used to determine if it is writable, and
the AF bit is treated entirely as a reference bit. A valid PTE is always
treated as readable. There can be no valid PTE that is not readable.
- LX_BLKPAG_OS_{READ,WRITE} are used only for debugging purposes,
and has been superseded by LX_BLKPAG_AF and LX_BLKPAG_DBM.
- Improve comment

The need for reference/modify emulation has been eliminated,
and access/permission faults have been reduced, however,
there has been little change in overall performance.


# 1.126 31-Jan-2022 ryo

Skip unnecessary PTE operations and TLB invalidation.


# 1.125 16-Jan-2022 rillig

aarch64/pmap: remove stray semicolon

No binary change.


# 1.124 15-Jan-2022 skrll

The translations that need invalidation are always last level so remove
the (dubious) logic around tracking the level. The "any level" TLB
invalidation maintenance operation are used, but this may change after
further testing.

before
======
1661.0u 420.2s 2:53.82 1197.3% 231+29k 10+33918io 102pf+0w
1646.8u 425.2s 2:52.96 1198.0% 232+29k 1+33937io 49pf+0w
1647.9u 425.7s 2:52.58 1201.6% 232+29k 0+33940io 32pf+0w

After
=====
1602.5u 420.8s 2:49.09 1196.6% 238+30k 24+33893io 54pf+0w
1600.7u 421.3s 2:51.53 1178.8% 238+30k 1+33914io 33pf+0w
1597.5u 424.3s 2:50.46 1186.1% 238+30k 0+33915io 17pf+0w

LGTM from ryo@


# 1.123 14-Jan-2022 skrll

Restore the previous pmap_remove_all behaviour as the new method meant
the n1sdp couldn't complete a build.

No noticeable change in kernel build performance.


# 1.122 04-Jan-2022 skrll

KNF


# 1.121 10-Dec-2021 andvar

s/occured/occurred/ in comments, log messages and man pages.


# 1.120 07-Dec-2021 andvar

fix various typos, mainly in comments.


# 1.119 23-Oct-2021 skrll

Fix non-UVMHIST build


# 1.118 16-Oct-2021 ryo

fix non-MULTIPROCESSOR build


# 1.117 10-Oct-2021 skrll

Use sys/uvm/pmap/pmap_tlb.c on Aarch64 in the same way that some Arm, MIPS,
and some PPC kernels do. This removes the limitation of 256 processes on
CPUs with 8bit ASID field, e.g. Apple M1.

Additionally the following changes have been made

- removed a couple of unnecessary aarch64_tlbi_all calls
- removed any invalidation after freeing page tables due to
_pmap_sweep_pdp. This was never necessary afaict.
- all kernel mappings are marked global and userland mapping not-global.

Performance testing hasn't show a significant difference. The data here
is from building a kernel on an lx2k system with nvme.

before
1489.6u 400.4s 2:40.65 1176.5% 228+224k 0+32289io 57pf+0w
1482.6u 403.2s 2:38.49 1189.9% 228+222k 0+32274io 46pf+0w
1485.4u 402.2s 2:37.27 1200.2% 228+222k 0+32275io 12pf+0w

after
1493.9u 404.6s 2:37.50 1205.4% 227+221k 0+32265io 48pf+0w
1485.0u 408.0s 2:38.54 1194.0% 227+222k 0+32272io 36pf+0w
1484.3u 407.0s 2:35.88 1213.3% 228+224k 0+32268io 14pf+0w

>>> stats.ttest_ind([160.65,158.49,157.27], [157.5,158.54,155.88])
Ttest_indResult(statistic=1.1923622711296888, pvalue=0.2990182944606766)
>>>


# 1.116 30-Sep-2021 skrll

Ensure TCR_EPD0 is set on entry to pmap_activate and ensure it is set as
early as possible for APs.


# 1.115 26-Sep-2021 skrll

Use UVMHIST_CALLARGS


# 1.114 26-Sep-2021 skrll

'\n' is not required in KASSERTMSG either.


# 1.113 26-Sep-2021 skrll

"\n" is not required in KERNHIST


# 1.112 15-Sep-2021 skrll

Use __SHIFTIN. Same code before and after.


# 1.111 12-Sep-2021 skrll

pmap_page_remove: simply and reduce the code size slightly.


# 1.110 09-Sep-2021 skrll

In pmap_icache_sync_range change

for (...) {
...
if (condition) {
// do stuff
}
}

to

for (...) {
...
if (!conditional)
continue;
// do stuff
}

to save on indentation. Same code (modulo register usage) before and
after.


# 1.109 09-Sep-2021 skrll

KNF


Revision tags: thorpej-i2c-spi-conf2-base thorpej-futex2-base thorpej-cfargs2-base cjep_sun2x-base1 cjep_sun2x-base cjep_staticlib_x-base1 thorpej-i2c-spi-conf-base
# 1.108 29-May-2021 skrll

Deal with the pmap limitation of maxproc in a more complete way and
recognise CPUs with only 8bit ASIDs.


Revision tags: cjep_staticlib_x-base
# 1.107 30-Apr-2021 skrll

branches: 1.107.2;
Make the ddb for pmap / pte information pmap agnostic


# 1.106 29-Apr-2021 skrll

Remove some unnecessary tlb invalidate in pmap_growkernel and ASAN shadow
map. Ensure the shadow map mappings are visible to the TLB walkers.


# 1.105 21-Apr-2021 ryo

branches: 1.105.2;
added more attributes of PTE displayed by "ddb>machine pte"


Revision tags: thorpej-cfargs-base
# 1.104 17-Apr-2021 mrg

remove KERNHIST_INIT_STATIC(). it stradles the line between usable
early in boot and broken early in boot by requiring a partly static
structure with another structure that must be present by the time
any uses are performed. theoretically platform code could allocate
a chunk while seting up memory and assign it here, giving a dynamic
sizing for the entry list, but the reality is that all users have
a statically allocated entry list as well.

the existing KERNHIST_LINK_STATIC() is used in conjunction with
KERNHIST_INITIALIZER() instead.

this stops a NULL pointer deref when the _LOG() macro is called
before the storage is linked in, which happens with GCC 10 on OCTEON
with UVMHIST enabled, crashing in very early kernel init.


Revision tags: thorpej-futex-base
# 1.103 09-Mar-2021 ryo

branches: 1.103.2;
fix build error without options DDB.

kvtopte() is referenced from arm/acpi/acpi_machdep.c


# 1.102 13-Feb-2021 ryo

No assignment is needed here.

the loop in pmap_page_remove() always removes the first pv,
and since the list is managed by _pmap_remove_pv(), pp->pp_pv.pv_next always points to the first.


# 1.101 01-Feb-2021 ryo

It is enough to make a page accessible instead of writable.
same fix as r1.76


# 1.100 31-Jan-2021 ryo

implement pmap_remove_all().

The size of struct pv_entry has increased, but speed of kernel build has improved by about 1%
exec and exit should have been improved.


# 1.99 20-Dec-2020 skrll

Improve the English in the previous comment fix.


# 1.98 19-Dec-2020 skrll

Tweak a comment


# 1.97 11-Dec-2020 skrll

s:aarch64/cpufunc.h:arm/cpufunc.h:

a baby step in the grand arm header unification challenge


# 1.96 10-Nov-2020 skrll

AA64 is not MIPS.

Change all KSEG references to directmap


# 1.95 07-Nov-2020 skrll

In pmap_devmap_bootstrap only set pmap_devmap_bootstrap_done if there
is an entry and ALL of the entries have been done. The entry required
for EARLYCONS might not be the first/only one...


# 1.94 01-Nov-2020 jmcneill

branches: 1.94.2;
No need to disable translation table walks in pmap_activate().


# 1.93 22-Oct-2020 skrll

Use the isb macro - missed in previous commit


# 1.92 22-Oct-2020 skrll

Use the dmb/dsb/isb macros... if nothing else they're all now consistent
about the "memory" assembler contraint.

No binary change


# 1.91 28-Sep-2020 skrll

Only set pmap_devmap_bootstrap_done if something gets mapped.

Think acpi_platform_devmap


# 1.90 19-Sep-2020 skrll

Make __md_palloc pmap agnostic (think sys/uvm/pmap)


# 1.89 14-Sep-2020 ryo

PID_MAX is just an initial value (soft maximum). Don't use it for CTASSERT.
defined __HAVE_CPU_MAXPROC to use function cpu_maxproc().

pointed out by mrg@, thanks.


# 1.88 06-Sep-2020 ryo

Fix panic caused by modload. http://mail-index.netbsd.org/port-arm/2020/08/30/msg006960.html

The address space reserved for modules may not be mapped in L1-L3.


# 1.87 14-Aug-2020 skrll

Whitespace


# 1.86 12-Aug-2020 skrll

Part IV of ad's performance improvements for aarch64

- Implement pmap_growkernel(), and update kernel pmap's stats with atomics.

- Then, pmap_kenter_pa() and pmap_kremove() no longer need to allocate
memory nor take pm_lock, because they only modify L3 PTEs.

- Then, pm_lock and pp_lock can be adaptive mutexes at IPL_NONE which are
cheaper than spin mutexes.

- Take the pmap's lock in pmap_extract() if not the kernel's pmap, otherwise
pmap_extract() might see inconsistent state.


# 1.85 09-Aug-2020 skrll

Fix another UVMHIST so it doesn't use %s


# 1.84 16-Jul-2020 skrll

pmapboot_enter simplication
- bootpage_alloc in asm becomes pmapboot_pagealloc in C
- PMAPBOOT_ENTER_NOBLOCK is removed as it's not used
- PMAPBOOT_ENTER_NOOVERWRITE is removed as it's now always on
- physpage_allocator argument is removed as it's always
pmapboot_pagealloc
- Support for EARLYCONS without CONSADDR is removed so that the identity
map for CONSADDR is always known.

For the assembly files:
2 files changed, 40 insertions(+), 89 deletions(-)

LGTM ryo


# 1.83 04-Jul-2020 rin

Use tlen for temporary length variable instead of l, which is usually
used for struct lwp *.

No binary changes.


# 1.82 02-Jul-2020 rin

pmap_procwr(): sync icache even if p != curproc. This fixes applications
like GDB for arm32, that rewrite text of other process.

Thanks to ryo@ for discussion.


# 1.81 02-Jul-2020 rin

Set uvmexp.ncolors appropriately, which is required for some CPU
models with VIPT icache.

Otherwise, alias in virtual address results in inconsistent results,
at least for applications that rewrite text of other process, e.g.,
GDB for arm32.

Also, this hopefully fixes other unexpected failures due to alias.

Confirmed that there's no observable regression in performance;
difference in ``time make -j8'' for GENERIC64 kernel on BCM2837
with and without setting uvmexp.ncolors is within 0.1%.

Thanks to ryo@ for discussion.


# 1.80 27-Jun-2020 rin

Fix typo in name of evcnt(4) counter.


# 1.79 24-Jun-2020 ryo

Fix bug with incorrect range calculation when doing icache sync.
This is called by sysarch(ARM_SYNC_ICACHE) from aarch32 (compat_netbsd32) emul process.

pointed out by rin@, thanks.

XXX pullup-9


# 1.78 14-Jun-2020 ad

- Fix a lock order reversal in pmap_page_protect().

- Make sure pmap is always locked when updating stats; atomics no longer
needed to do that.

- Remove unneeded traversal of pv list in pmap_enter_pv().

- Shrink struct vm_page from 136 to 128 bytes (cache line sized) and struct
pv_entry from 48 to 32 bytes (power of 2 sized).

- Embed a pv_entry in each vm_page. This means PV entries don't need to
be allocated for private anonymous memory / COW pages / most UBC mappings.
Dynamic PV entries are then used only for stuff like shared libraries and
shared memory.

Proposed on port-arm@.


# 1.77 10-Jun-2020 ad

- Wired/resident stats shouldn't covered by PMAPCOUNTERS.
- Rename need_update_pv -> need_enter_pv.

Ok ryo@


# 1.76 01-Jun-2020 ryo

no need to make the PTE writable to do icache_sync, enough to accessible.


# 1.75 15-May-2020 skrll

Use __diagused


# 1.74 15-May-2020 tnn

fix non-diag build


# 1.73 14-May-2020 skrll

Use MUTEX_NODEBUG for PV locks as is commonly done. OK ryo.


# 1.72 13-May-2020 jmcneill

Implement pmap_extract_coherency


Revision tags: bouyer-xenpvh-base2 phil-wifi-20200421 bouyer-xenpvh-base1
# 1.71 18-Apr-2020 skrll

PMAP_DEBUG has been deleted on arm


# 1.70 13-Apr-2020 maxv

Add support for Branch Target Identification (BTI).

On the executable pages that have the GP (Guarded Page) bit, the semantic
of the "br" and "blr" instructions is changed: the CPU expects the first
instruction of the jump/call target to be "bti", and faults if it isn't.

We add the GP bit on the kernel .text pages (and incidentally the .rodata
pages, but we don't care). The compiler adds a "bti c" instruction at the
beginning of each C function. We modify the ENTRY() macros to manually add
"bti c" in the asm functions.

cpuswitch.S needs a specific change: with "br x27" the CPU expects "bti j",
which is bad because the functions begin with "bti c"; switch to "br x16",
for the CPU to accept "bti c".

BTI helps defend against JOP/COP. Tested on Qemu.


Revision tags: phil-wifi-20200411 bouyer-xenpvh-base
# 1.69 08-Apr-2020 ryo

branches: 1.69.2;
use PMAP_PAGE_INIT() to initialize mutex in pmap_page.

VM_MDPAGE_INIT() in pmap_free_pdp() had initialized pp_flags,
so it unintentionally cleared PMAP_PAGE_FLAGS_PV_TRACKED.
use PMAP_PAGE_INIT to avoid using PMAP_PAGE_FLAGS_PV_TRACKED.

pointed out by tnn@, thanks


Revision tags: phil-wifi-20200406
# 1.68 14-Mar-2020 ad

pmap_remove_all(): Return a boolean value to indicate the behaviour. If
true, all mappings have been removed, the pmap is totally cleared out, and
UVM can then avoid doing the work to call pmap_remove() for each map entry.
If false, either nothing has been done, or some helpful arch-specific voodoo
has taken place.


Revision tags: is-mlppp-base
# 1.67 02-Mar-2020 ryo

oops, fix incorrect usage of daif_enable() in my previous commit.


# 1.66 29-Feb-2020 ryo

Fix pmap to work correctly with tagged addresses

- when fault, untag from address before passing to uvm/pmap functions
- pmap_extract() checks more strictly and consider the address tag


# 1.65 29-Feb-2020 ryo

use pmapboot_enter_range()


Revision tags: ad-namecache-base3
# 1.64 10-Feb-2020 ryo

use LIST(3) instead of TAILQ(3) to save one word in struct vm_page and struct pmap.

pointed out by riastradh@. thanks


# 1.63 03-Feb-2020 ryo

add support pmap_pv(9)

Patch originally from jmcneill@. thanks


# 1.62 03-Feb-2020 ryo

separate struct vm_page_md into vm_page_md and pmap_page
for preparation pmap_pv(9)


Revision tags: ad-namecache-base2 ad-namecache-base1
# 1.61 09-Jan-2020 ryo

fix behaviour mmap()/mprotect() when passed only PROT_EXEC.

when mmap()/mprotect() with only PROT_EXEC, syscall will be successful,
but the page actually hadn't been mapped.
it should be mapped with PROT_READ|PROT_EXEC implicitly. (r-x)


Revision tags: ad-namecache-base
# 1.60 30-Dec-2019 skrll

branches: 1.60.2;
Update pmap_map_chunk to allow L[12] block mappings and L3 page mappings


# 1.59 30-Dec-2019 skrll

Remove unnecessary brackets and unwrap a conditional. Same code before
and after.


# 1.58 28-Dec-2019 jmcneill

Do not use Early Write Acknowledge for PCIe I/O and config space.


# 1.57 27-Dec-2019 jmcneill

Enable early write acknowledge for device memory mappings.


# 1.56 19-Dec-2019 skrll

G/C kasan_shadow_map call in pmap_enter

pmap_growkernel calls kasan_shadow_map for KVA


# 1.55 18-Dec-2019 ryo

atomic_add_16() is not used in pmap.c anymore. no need decl here.


# 1.54 18-Dec-2019 ryo

space to tab


# 1.53 14-Dec-2019 skrll

Fix build... wire_count probably doesn't need atomics


# 1.52 13-Dec-2019 skrll

Fix KASAN support by calling kasan_shadow_map in pmap_growkernel


# 1.51 10-Dec-2019 ad

pg->phys_addr -> VM_PAGE_TO_PHYS(pg)


Revision tags: phil-wifi-20191119
# 1.50 14-Nov-2019 maxv

Mark several kASan functions with __nothing, to avoid annoying #ifdefs.
Same as kCSan and kMSan.


# 1.49 14-Nov-2019 maxv

Don't include "opt_kasan.h" when there's already <sys/asan.h> included.


# 1.48 29-Oct-2019 maya

Define PMAP_NEED_PROCWR, providing strategically placed i-cache
synchronization where just-changed memory is about to be executed.

Fixes SIGILLs seen when running Mono 6 on QEMU Cortex-A57.

ok ryo


# 1.47 22-Sep-2019 jmcneill

Disable translation table walks using TTBR0 while changing its value and
when deactivating a pmap. Fixes stability issues on Ampere eMAG CPUs.


# 1.46 20-Sep-2019 ryo

ref/mod bit should be set according to 'flags' argument, not 'prot'. r1.44 was incomplete.


# 1.45 13-Sep-2019 ryo

In pmap_devmap_bootstrap(), cpu_earlydevice_va_p() must not return true until *all* devmap tables have been enabled.
console mapping may be present in the last table.


# 1.44 07-Sep-2019 ryo

- remove incorrect KASSERT. mmap(2) with prot=PROT_WRITE calls pmap_enter(..., PROT_WRITE) internally.
- fix to update page reference flags when only PROT_WRITE or PROT_EXECUTE specified


# 1.43 15-Aug-2019 skrll

Make pmap_db_pte_print more terse so it's quicker on serial consoles


# 1.42 12-Aug-2019 skrll

Use PMAP_DEV in DEVMAP_ENTRY rather than pmap_map_chunk. It's clearer and
means pmap_map_chunk can be made to map other memory types.


Revision tags: netbsd-9-base phil-wifi-20190609
# 1.41 17-May-2019 mrg

branches: 1.41.2;
apply some __diagused.


Revision tags: isaki-audio2-base
# 1.40 08-Apr-2019 ryo

- free empty page tables pages if reach a certain usage.
- need to lock at removing an old pg (_pmap_remove_pv) in _pmap_enter()


# 1.39 06-Apr-2019 ryo

Fix race conditions about pmap_page_protect() and pmap_enter().

while handling same PTE by these functions in same time, there
is a critical path that the number of valid PTEs and wire_count
are inconsistent, and it caused KASSERT.
Need to hold a pv_lock while modifying them.


# 1.38 20-Mar-2019 ryo

spinkle __printflike(), and use PRIxxx


# 1.37 19-Mar-2019 ryo

- add ddb command "machine ttbr" to dump MMU tables.
- tidy up descriptions, usages and messages.


# 1.36 19-Mar-2019 ryo

- free L1-L3 pages that has been emptied by pmap_remove().
- if no memories, pmap_enter will return correctly ENOMEM if PMAP_CANFAIL, or wait until available any memories if !PMAP_CANFAIL.

These changes improves the stability when we use a huge virtual memory spaces with mmap.


# 1.35 06-Feb-2019 ryo

improve pmap_remove
- don't lock/unlock per page in pmap_remove()
- speedup pte lookup for continuous addresses
- bring out pool_cache_put(&_pmap_pv_pool, pv) from lock/unlock section


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226
# 1.34 21-Dec-2018 ryo

- add workaround for Cavium ThunderX errata 27456.
- add cpufuncs table in cpu_info. each cpu clusters may have different erratum. (e.g. big.LITTLE)


Revision tags: pgoyette-compat-1126
# 1.33 01-Nov-2018 maxv

Add kASan support for aarch64. Stack tracking needs more investigation
and will come in a separate commit.

Reviewed by ryo@ jmcneill@ skrll@.


# 1.32 31-Oct-2018 ryo

invalidate icache correctly.
l3pte_executable() should be used for only valid pte.


Revision tags: pgoyette-compat-1020
# 1.31 18-Oct-2018 skrll

Provide generic start code that assumes the MMU is off and caches are
disabled as per the linux booting protocol for ARMv6 and ARMv7 boards.
u-boot image type should be changed to 'linux' for correct behaviour.

The new start code builds a minimal "bootstrap" L1PT with cached access
disabled and uses the same table for all processors. AP startup is
performed in less steps and more code is written in C.

The bootstrap tables and stack are placed into an (orphaned) section
"_init_memory" which is given to uvm when it is no longer used.

Various kernels have been converted to use this code and tested. Some
boards were provided by TNF. Thanks!

The GENERIC kernel now boots on boards using the TEGRA, SUNXI and EXYNOS
kernels. The GENERIC kernel will also work on RPI2 using u-boot.

Thanks to martin@ and aymeric@ for testing on parallella and nanosoc
respectively


# 1.30 14-Oct-2018 skrll

Use __nothing


# 1.29 12-Oct-2018 ryo

add initial support of COMPAT_NETBSD32 on AArch64.
arm ELF32 EABI binaries could be execute in AArch32 state on AArch64. A32 THUMB mode is not supported yet.


# 1.28 12-Oct-2018 ryo

- cleanup checking address ranges with IN_RANGE macro
- change PM_ADDR_CHECK macro to KASSERTMSG
- restore fast lookup cases with IN_RANGE macro for pmap_extract changed in my previous commit.


# 1.27 12-Oct-2018 ryo

rewrite pmap_pte_lookup() to share similar code.


# 1.26 04-Oct-2018 ryo

cleanup locore, and changed the way to map memories during boot.
- add functions bootpage_enter() and bootpage_alloc() to adapt various layout
of physical memory map. especially for 64bit physical memory layout.
pmapboot_alloc() allocates pagetable pages from _end[].
- changed to map only the required amount for PA=VA identity mapping
(kernel image, UART device, and FDT blob) with L2_BLOCK(2Mbyte).
- changing page permission for kernel image, and making KSEG mapping are done
at cpu_kernel_vm_init() instead of at locore.
- optimize PTE entries with PTE Contiguous bit. it is enabled on devmap only for now.

reviewed by skrll@, thanks.


# 1.25 04-Oct-2018 ryo

* define LX_BLKPAG_{OS,ATTR}_* for OS dependent PTE attributes in pmap.h
* cleanup macros


Revision tags: pgoyette-compat-0930
# 1.24 17-Sep-2018 ryo

delete debug printf and KASSERT.


# 1.23 10-Sep-2018 maxv

Replace KDASSERT by panic.


# 1.22 10-Sep-2018 maxv

Rename _pmap_alloc_pdp -> pmap_alloc_pdp, and make it public.


# 1.21 10-Sep-2018 ryo

cleanup aarch64 mpstart and fdt bootstrap
* arm_cpu_hatch_arg is a bad idea. avoid serializing CPU startup, and eliminate arm_cpu_hatch_arg.
in mpstart, resolve own cpu index using array of cpu_mpidr[] (aarch64)
* add support fdt enable-method "spin-table"
* add support fdt enable-method "brcm,bcm2836-smp" (for 32bit RaspberryPi)
* use arm_fdt_cpu_bootstrap() instead of psci_fdt_bootstrap()
* rename "arm/fdt/psci_fdt.h" to "arm/fdt/psci_fdtvar.h" because of conflict of include file for needs-flag
* add devmap for cpu spin-table of raspberrypi3/aarch64
* no need to force hatch APs for raspberrypi3/arm32 ifndef MULTIPROCESSOR.
* fix to work pmap_extract(kerneltext/data/bss) even if before calling pmap_bootstrap

idea to use cpu_mpidr[] by jmcneill@. reviewd by skrll@. thanks.


Revision tags: pgoyette-compat-0906
# 1.20 27-Aug-2018 ryo

need to add VM_PROT_READ when pmap_kenter_pa(va, pa, VM_PROT_WRITE, 0) or pmap_kenter_pa(va, pa, VM_PROT_EXECUTE, 0).
VM_PROT_READ is treated as an access permission inernally.


# 1.19 11-Aug-2018 ryo

change to minimum invalidation of TLB.
specifying not only va but also asid, and not invalidate L0-L2 entry using tlbi_*_ll() if needed.


# 1.18 10-Aug-2018 ryo

treat kernel-exec attr and user-exec attr separately.
kernel cannot execute userland exec page, and user cannot execute kernel page.


# 1.17 06-Aug-2018 ryo

set kernel text/rodata readonly by default.
add function db_write_text() for setting ddb breakpoint.


# 1.16 31-Jul-2018 skrll

Define and use VPRINTF


Revision tags: pgoyette-compat-0728
# 1.15 27-Jul-2018 ryo

changes of pmap.c r1.13 seems to be unstable.
In order to invalidate icache, not to invalidate all icache,
but temporary to make the page writable and invalidate target address only.


# 1.14 24-Jul-2018 ryo

don't call pool_cache_put with locking pmap. pool_cache_put call pmap_kenter_pa internally.
(pool_cache_put_paddr -> pool_cache_put_slow -> pool_get -> pmap_kenter_pa)


# 1.13 23-Jul-2018 ryo

* fix icache invalidations.
* "ic ivau" (aarch64_icache_sync_range) with VA generates permission fault in some situations, therefore use KSEG address for now.


# 1.12 23-Jul-2018 ryo

rather than using flags to resolve nested locks, reserve pool_cache before locking.


# 1.11 21-Jul-2018 ryo

* avoid deadlock. mutex_owned() works only for adaptive lock, therefore we cannot use it for spinlock...
* add more NULL check
* clear pte when pmap_enter() fails


# 1.10 17-Jul-2018 ryo

Use __debugused


# 1.9 17-Jul-2018 christos

Add missing casts, remove unused variables.


# 1.8 09-Jul-2018 ryo

need locks in pmap_kremove() and pmap_fault_fixup()


Revision tags: phil-wifi-base pgoyette-compat-0625 pgoyette-compat-0521
# 1.7 20-May-2018 ryo

branches: 1.7.2;
pmap_enter() must update modified/referenced flags by 'flags' not 'prot'.


# 1.6 16-May-2018 ryo

Fix memory leak. it was leaking one page every pmap_create().
pm->pm_vmlist must be initialized before calling _pmap_alloc_pdp().


Revision tags: pgoyette-compat-0502
# 1.5 29-Apr-2018 ryo

fix KASSERT panic. pv_entry may not be exists in pvlist when pmap_remove().


# 1.4 29-Apr-2018 ryo

delete unused code


# 1.3 27-Apr-2018 ryo

fix instability behavior of bufcache on aarch64.
* fix to return correct ref/mod when PMAP_WIRED.
* changed to keep wired flags in pte instead of pv_entry, and cleanup.


Revision tags: pgoyette-compat-0422 pgoyette-compat-0415 pgoyette-compat-0407
# 1.2 01-Apr-2018 ryo

Add initial support for ARMv8 (AARCH64) (by nisimura@ and ryo@)

- sys/arch/evbarm64 is gone and integrated into sys/arch/evbarm. (by skrll@)
- add support fdt. evbarm/conf/GENERIC64 fdt (bcm2837,sunxi,tegra) based generic 64bit kernel config. (by skrll@, jmcneill@)


Revision tags: netbsd-8-2-RELEASE netbsd-8-1-RELEASE netbsd-8-1-RC1 netbsd-7-2-RELEASE netbsd-8-0-RELEASE netbsd-8-0-RC2 netbsd-8-0-RC1 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 netbsd-7-1-2-RELEASE pgoyette-compat-base netbsd-7-1-1-RELEASE tls-maxphys-base-20171202 matt-nb8-mediatek-base nick-nhusb-base-20170825 perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base pgoyette-localcount-20170320 netbsd-7-1-RELEASE netbsd-7-1-RC2 nick-nhusb-base-20170204 netbsd-7-nhusb-base-20170116 bouyer-socketcan-base pgoyette-localcount-20170107 netbsd-7-1-RC1 nick-nhusb-base-20161204 pgoyette-localcount-20161104 netbsd-7-0-2-RELEASE nick-nhusb-base-20161004 localcount-20160914 netbsd-7-nhusb-base pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907 nick-nhusb-base-20160529 netbsd-7-0-1-RELEASE nick-nhusb-base-20160422 nick-nhusb-base-20160319 nick-nhusb-base-20151226 netbsd-7-0-RELEASE nick-nhusb-base-20150921 netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 nick-nhusb-base-20150606 nick-nhusb-base-20150406 nick-nhusb-base tls-maxphys-base netbsd-7-base
# 1.1 10-Aug-2014 matt

branches: 1.1.4; 1.1.28;
Preliminary files for AARCH64 (64-bit ARM) support.
Enough for a distribution build.


# 1.139 19-Aug-2022 ryo

Fixed a bug that pte's __BIT(63,48) could be set when accessing addresses above 0x0001000000000000 in /dev/mem with mmap().


# 1.138 19-Aug-2022 ryo

When accessed in mmap by the device pager, pmap_enter() may be called with prot == PROT_WRITE.


# 1.137 03-May-2022 skrll

Sprinkle some KASSERT(kpreempt_disabled());


# 1.136 27-Apr-2022 ryo

since pmap_activate_efirt() rewrites TTBR0, it is necessary to pmap_activate() again after pmap_deactivate_efirt() to restore the original TTBR0.

- Fix to do pmap_{de,}activate() before/after pmap_{,de}activate_efirt().
- moved kpreempt_{disable,enable}() to the caller since everything between
arm_efirt_md_enter() and arm_efirt_md_exit() should be kpreempt disabled.

ok skrll@


# 1.135 17-Apr-2022 skrll

Add the missing kpreempt_enable to pmap_deactivate_efirt


# 1.134 10-Apr-2022 skrll

No need to flush icache for EFI RT mappings as bootaa64.efi flushed
the full icache for us. (Also this avoids traps)


# 1.133 09-Apr-2022 riastradh

sys: Use membar_release/acquire around reference drop.

This just goes through my recent reference count membar audit and
changes membar_exit to membar_release and membar_enter to
membar_acquire -- this should make everything cheaper on most CPUs
without hurting correctness, because membar_acquire is generally
cheaper than membar_enter.


# 1.132 02-Apr-2022 skrll

Update to support EFI runtime outside the kernel virtual address space
by creating an EFI RT pmap that can be activated / deactivated when
required.

Adds support for EFI RT to ARM_MMU_EXTENDED (ASID) 32-bit Arm machines.

On Arm64 the usage of pmapboot_enter is reduced and the mappings are
created much later in the boot process -- now in cpu_startup_hook.
Backward compatiblity for KVA mapped RT from old bootaa64.efi is
maintained.

Adding support to other platforms should be easier as a result.


# 1.131 19-Mar-2022 skrll

Slight code re-organisation. NFCI.


# 1.130 12-Mar-2022 riastradh

sys: Membar audit around reference count releases.

If two threads are using an object that is freed when the reference
count goes to zero, we need to ensure that all memory operations
related to the object happen before freeing the object.

Using an atomic_dec_uint_nv(&refcnt) == 0 ensures that only one
thread takes responsibility for freeing, but it's not enough to
ensure that the other thread's memory operations happen before the
freeing.

Consider:

Thread A Thread B
obj->foo = 42; obj->baz = 73;
mumble(&obj->bar); grumble(&obj->quux);
/* membar_exit(); */ /* membar_exit(); */
atomic_dec -- not last atomic_dec -- last
/* membar_enter(); */
KASSERT(invariant(obj->foo,
obj->bar));
free_stuff(obj);

The memory barriers ensure that

obj->foo = 42;
mumble(&obj->bar);

in thread A happens before

KASSERT(invariant(obj->foo, obj->bar));
free_stuff(obj);

in thread B. Without them, this ordering is not guaranteed.

So in general it is necessary to do

membar_exit();
if (atomic_dec_uint_nv(&obj->refcnt) != 0)
return;
membar_enter();

to release a reference, for the `last one out hit the lights' style
of reference counting. (This is in contrast to the style where one
thread blocks new references and then waits under a lock for existing
ones to drain with a condvar -- no membar needed thanks to mutex(9).)

I searched for atomic_dec to find all these. Obviously we ought to
have a better abstraction for this because there's so much copypasta.
This is a stop-gap measure to fix actual bugs until we have that. It
would be nice if an abstraction could gracefully handle the different
styles of reference counting in use -- some years ago I drafted an
API for this, but making it cover everything got a little out of hand
(particularly with struct vnode::v_usecount) and I ended up setting
it aside to work on psref/localcount instead for better scalability.

I got bored of adding #ifdef __HAVE_ATOMIC_AS_MEMBAR everywhere, so I
only put it on things that look performance-critical on 5sec review.
We should really adopt membar_enter_preatomic/membar_exit_postatomic
or something (except they are applicable only to atomic r/m/w, not to
atomic_load/store_*, making the naming annoying) and get rid of all
the ifdefs.


# 1.129 05-Mar-2022 skrll

Slight comment improvement.


# 1.128 16-Feb-2022 andvar

fix various typos, mainly in comments.


# 1.127 31-Jan-2022 ryo

add support Hardware updates to Access flag and Dirty state (FEAT_HAFDBS)

- The DBM bit of the PTE is now used to determine if it is writable, and
the AF bit is treated entirely as a reference bit. A valid PTE is always
treated as readable. There can be no valid PTE that is not readable.
- LX_BLKPAG_OS_{READ,WRITE} are used only for debugging purposes,
and has been superseded by LX_BLKPAG_AF and LX_BLKPAG_DBM.
- Improve comment

The need for reference/modify emulation has been eliminated,
and access/permission faults have been reduced, however,
there has been little change in overall performance.


# 1.126 31-Jan-2022 ryo

Skip unnecessary PTE operations and TLB invalidation.


# 1.125 16-Jan-2022 rillig

aarch64/pmap: remove stray semicolon

No binary change.


# 1.124 15-Jan-2022 skrll

The translations that need invalidation are always last level so remove
the (dubious) logic around tracking the level. The "any level" TLB
invalidation maintenance operation are used, but this may change after
further testing.

before
======
1661.0u 420.2s 2:53.82 1197.3% 231+29k 10+33918io 102pf+0w
1646.8u 425.2s 2:52.96 1198.0% 232+29k 1+33937io 49pf+0w
1647.9u 425.7s 2:52.58 1201.6% 232+29k 0+33940io 32pf+0w

After
=====
1602.5u 420.8s 2:49.09 1196.6% 238+30k 24+33893io 54pf+0w
1600.7u 421.3s 2:51.53 1178.8% 238+30k 1+33914io 33pf+0w
1597.5u 424.3s 2:50.46 1186.1% 238+30k 0+33915io 17pf+0w

LGTM from ryo@


# 1.123 14-Jan-2022 skrll

Restore the previous pmap_remove_all behaviour as the new method meant
the n1sdp couldn't complete a build.

No noticeable change in kernel build performance.


# 1.122 04-Jan-2022 skrll

KNF


# 1.121 10-Dec-2021 andvar

s/occured/occurred/ in comments, log messages and man pages.


# 1.120 07-Dec-2021 andvar

fix various typos, mainly in comments.


# 1.119 23-Oct-2021 skrll

Fix non-UVMHIST build


# 1.118 16-Oct-2021 ryo

fix non-MULTIPROCESSOR build


# 1.117 10-Oct-2021 skrll

Use sys/uvm/pmap/pmap_tlb.c on Aarch64 in the same way that some Arm, MIPS,
and some PPC kernels do. This removes the limitation of 256 processes on
CPUs with 8bit ASID field, e.g. Apple M1.

Additionally the following changes have been made

- removed a couple of unnecessary aarch64_tlbi_all calls
- removed any invalidation after freeing page tables due to
_pmap_sweep_pdp. This was never necessary afaict.
- all kernel mappings are marked global and userland mapping not-global.

Performance testing hasn't show a significant difference. The data here
is from building a kernel on an lx2k system with nvme.

before
1489.6u 400.4s 2:40.65 1176.5% 228+224k 0+32289io 57pf+0w
1482.6u 403.2s 2:38.49 1189.9% 228+222k 0+32274io 46pf+0w
1485.4u 402.2s 2:37.27 1200.2% 228+222k 0+32275io 12pf+0w

after
1493.9u 404.6s 2:37.50 1205.4% 227+221k 0+32265io 48pf+0w
1485.0u 408.0s 2:38.54 1194.0% 227+222k 0+32272io 36pf+0w
1484.3u 407.0s 2:35.88 1213.3% 228+224k 0+32268io 14pf+0w

>>> stats.ttest_ind([160.65,158.49,157.27], [157.5,158.54,155.88])
Ttest_indResult(statistic=1.1923622711296888, pvalue=0.2990182944606766)
>>>


# 1.116 30-Sep-2021 skrll

Ensure TCR_EPD0 is set on entry to pmap_activate and ensure it is set as
early as possible for APs.


# 1.115 26-Sep-2021 skrll

Use UVMHIST_CALLARGS


# 1.114 26-Sep-2021 skrll

'\n' is not required in KASSERTMSG either.


# 1.113 26-Sep-2021 skrll

"\n" is not required in KERNHIST


# 1.112 15-Sep-2021 skrll

Use __SHIFTIN. Same code before and after.


# 1.111 12-Sep-2021 skrll

pmap_page_remove: simply and reduce the code size slightly.


# 1.110 09-Sep-2021 skrll

In pmap_icache_sync_range change

for (...) {
...
if (condition) {
// do stuff
}
}

to

for (...) {
...
if (!conditional)
continue;
// do stuff
}

to save on indentation. Same code (modulo register usage) before and
after.


# 1.109 09-Sep-2021 skrll

KNF


Revision tags: thorpej-i2c-spi-conf2-base thorpej-futex2-base thorpej-cfargs2-base cjep_sun2x-base1 cjep_sun2x-base cjep_staticlib_x-base1 thorpej-i2c-spi-conf-base
# 1.108 29-May-2021 skrll

Deal with the pmap limitation of maxproc in a more complete way and
recognise CPUs with only 8bit ASIDs.


Revision tags: cjep_staticlib_x-base
# 1.107 30-Apr-2021 skrll

branches: 1.107.2;
Make the ddb for pmap / pte information pmap agnostic


# 1.106 29-Apr-2021 skrll

Remove some unnecessary tlb invalidate in pmap_growkernel and ASAN shadow
map. Ensure the shadow map mappings are visible to the TLB walkers.


# 1.105 21-Apr-2021 ryo

branches: 1.105.2;
added more attributes of PTE displayed by "ddb>machine pte"


Revision tags: thorpej-cfargs-base
# 1.104 17-Apr-2021 mrg

remove KERNHIST_INIT_STATIC(). it stradles the line between usable
early in boot and broken early in boot by requiring a partly static
structure with another structure that must be present by the time
any uses are performed. theoretically platform code could allocate
a chunk while seting up memory and assign it here, giving a dynamic
sizing for the entry list, but the reality is that all users have
a statically allocated entry list as well.

the existing KERNHIST_LINK_STATIC() is used in conjunction with
KERNHIST_INITIALIZER() instead.

this stops a NULL pointer deref when the _LOG() macro is called
before the storage is linked in, which happens with GCC 10 on OCTEON
with UVMHIST enabled, crashing in very early kernel init.


Revision tags: thorpej-futex-base
# 1.103 09-Mar-2021 ryo

branches: 1.103.2;
fix build error without options DDB.

kvtopte() is referenced from arm/acpi/acpi_machdep.c


# 1.102 13-Feb-2021 ryo

No assignment is needed here.

the loop in pmap_page_remove() always removes the first pv,
and since the list is managed by _pmap_remove_pv(), pp->pp_pv.pv_next always points to the first.


# 1.101 01-Feb-2021 ryo

It is enough to make a page accessible instead of writable.
same fix as r1.76


# 1.100 31-Jan-2021 ryo

implement pmap_remove_all().

The size of struct pv_entry has increased, but speed of kernel build has improved by about 1%
exec and exit should have been improved.


# 1.99 20-Dec-2020 skrll

Improve the English in the previous comment fix.


# 1.98 19-Dec-2020 skrll

Tweak a comment


# 1.97 11-Dec-2020 skrll

s:aarch64/cpufunc.h:arm/cpufunc.h:

a baby step in the grand arm header unification challenge


# 1.96 10-Nov-2020 skrll

AA64 is not MIPS.

Change all KSEG references to directmap


# 1.95 07-Nov-2020 skrll

In pmap_devmap_bootstrap only set pmap_devmap_bootstrap_done if there
is an entry and ALL of the entries have been done. The entry required
for EARLYCONS might not be the first/only one...


# 1.94 01-Nov-2020 jmcneill

branches: 1.94.2;
No need to disable translation table walks in pmap_activate().


# 1.93 22-Oct-2020 skrll

Use the isb macro - missed in previous commit


# 1.92 22-Oct-2020 skrll

Use the dmb/dsb/isb macros... if nothing else they're all now consistent
about the "memory" assembler contraint.

No binary change


# 1.91 28-Sep-2020 skrll

Only set pmap_devmap_bootstrap_done if something gets mapped.

Think acpi_platform_devmap


# 1.90 19-Sep-2020 skrll

Make __md_palloc pmap agnostic (think sys/uvm/pmap)


# 1.89 14-Sep-2020 ryo

PID_MAX is just an initial value (soft maximum). Don't use it for CTASSERT.
defined __HAVE_CPU_MAXPROC to use function cpu_maxproc().

pointed out by mrg@, thanks.


# 1.88 06-Sep-2020 ryo

Fix panic caused by modload. http://mail-index.netbsd.org/port-arm/2020/08/30/msg006960.html

The address space reserved for modules may not be mapped in L1-L3.


# 1.87 14-Aug-2020 skrll

Whitespace


# 1.86 12-Aug-2020 skrll

Part IV of ad's performance improvements for aarch64

- Implement pmap_growkernel(), and update kernel pmap's stats with atomics.

- Then, pmap_kenter_pa() and pmap_kremove() no longer need to allocate
memory nor take pm_lock, because they only modify L3 PTEs.

- Then, pm_lock and pp_lock can be adaptive mutexes at IPL_NONE which are
cheaper than spin mutexes.

- Take the pmap's lock in pmap_extract() if not the kernel's pmap, otherwise
pmap_extract() might see inconsistent state.


# 1.85 09-Aug-2020 skrll

Fix another UVMHIST so it doesn't use %s


# 1.84 16-Jul-2020 skrll

pmapboot_enter simplication
- bootpage_alloc in asm becomes pmapboot_pagealloc in C
- PMAPBOOT_ENTER_NOBLOCK is removed as it's not used
- PMAPBOOT_ENTER_NOOVERWRITE is removed as it's now always on
- physpage_allocator argument is removed as it's always
pmapboot_pagealloc
- Support for EARLYCONS without CONSADDR is removed so that the identity
map for CONSADDR is always known.

For the assembly files:
2 files changed, 40 insertions(+), 89 deletions(-)

LGTM ryo


# 1.83 04-Jul-2020 rin

Use tlen for temporary length variable instead of l, which is usually
used for struct lwp *.

No binary changes.


# 1.82 02-Jul-2020 rin

pmap_procwr(): sync icache even if p != curproc. This fixes applications
like GDB for arm32, that rewrite text of other process.

Thanks to ryo@ for discussion.


# 1.81 02-Jul-2020 rin

Set uvmexp.ncolors appropriately, which is required for some CPU
models with VIPT icache.

Otherwise, alias in virtual address results in inconsistent results,
at least for applications that rewrite text of other process, e.g.,
GDB for arm32.

Also, this hopefully fixes other unexpected failures due to alias.

Confirmed that there's no observable regression in performance;
difference in ``time make -j8'' for GENERIC64 kernel on BCM2837
with and without setting uvmexp.ncolors is within 0.1%.

Thanks to ryo@ for discussion.


# 1.80 27-Jun-2020 rin

Fix typo in name of evcnt(4) counter.


# 1.79 24-Jun-2020 ryo

Fix bug with incorrect range calculation when doing icache sync.
This is called by sysarch(ARM_SYNC_ICACHE) from aarch32 (compat_netbsd32) emul process.

pointed out by rin@, thanks.

XXX pullup-9


# 1.78 14-Jun-2020 ad

- Fix a lock order reversal in pmap_page_protect().

- Make sure pmap is always locked when updating stats; atomics no longer
needed to do that.

- Remove unneeded traversal of pv list in pmap_enter_pv().

- Shrink struct vm_page from 136 to 128 bytes (cache line sized) and struct
pv_entry from 48 to 32 bytes (power of 2 sized).

- Embed a pv_entry in each vm_page. This means PV entries don't need to
be allocated for private anonymous memory / COW pages / most UBC mappings.
Dynamic PV entries are then used only for stuff like shared libraries and
shared memory.

Proposed on port-arm@.


# 1.77 10-Jun-2020 ad

- Wired/resident stats shouldn't covered by PMAPCOUNTERS.
- Rename need_update_pv -> need_enter_pv.

Ok ryo@


# 1.76 01-Jun-2020 ryo

no need to make the PTE writable to do icache_sync, enough to accessible.


# 1.75 15-May-2020 skrll

Use __diagused


# 1.74 15-May-2020 tnn

fix non-diag build


# 1.73 14-May-2020 skrll

Use MUTEX_NODEBUG for PV locks as is commonly done. OK ryo.


# 1.72 13-May-2020 jmcneill

Implement pmap_extract_coherency


Revision tags: bouyer-xenpvh-base2 phil-wifi-20200421 bouyer-xenpvh-base1
# 1.71 18-Apr-2020 skrll

PMAP_DEBUG has been deleted on arm


# 1.70 13-Apr-2020 maxv

Add support for Branch Target Identification (BTI).

On the executable pages that have the GP (Guarded Page) bit, the semantic
of the "br" and "blr" instructions is changed: the CPU expects the first
instruction of the jump/call target to be "bti", and faults if it isn't.

We add the GP bit on the kernel .text pages (and incidentally the .rodata
pages, but we don't care). The compiler adds a "bti c" instruction at the
beginning of each C function. We modify the ENTRY() macros to manually add
"bti c" in the asm functions.

cpuswitch.S needs a specific change: with "br x27" the CPU expects "bti j",
which is bad because the functions begin with "bti c"; switch to "br x16",
for the CPU to accept "bti c".

BTI helps defend against JOP/COP. Tested on Qemu.


Revision tags: phil-wifi-20200411 bouyer-xenpvh-base
# 1.69 08-Apr-2020 ryo

branches: 1.69.2;
use PMAP_PAGE_INIT() to initialize mutex in pmap_page.

VM_MDPAGE_INIT() in pmap_free_pdp() had initialized pp_flags,
so it unintentionally cleared PMAP_PAGE_FLAGS_PV_TRACKED.
use PMAP_PAGE_INIT to avoid using PMAP_PAGE_FLAGS_PV_TRACKED.

pointed out by tnn@, thanks


Revision tags: phil-wifi-20200406
# 1.68 14-Mar-2020 ad

pmap_remove_all(): Return a boolean value to indicate the behaviour. If
true, all mappings have been removed, the pmap is totally cleared out, and
UVM can then avoid doing the work to call pmap_remove() for each map entry.
If false, either nothing has been done, or some helpful arch-specific voodoo
has taken place.


Revision tags: is-mlppp-base
# 1.67 02-Mar-2020 ryo

oops, fix incorrect usage of daif_enable() in my previous commit.


# 1.66 29-Feb-2020 ryo

Fix pmap to work correctly with tagged addresses

- when fault, untag from address before passing to uvm/pmap functions
- pmap_extract() checks more strictly and consider the address tag


# 1.65 29-Feb-2020 ryo

use pmapboot_enter_range()


Revision tags: ad-namecache-base3
# 1.64 10-Feb-2020 ryo

use LIST(3) instead of TAILQ(3) to save one word in struct vm_page and struct pmap.

pointed out by riastradh@. thanks


# 1.63 03-Feb-2020 ryo

add support pmap_pv(9)

Patch originally from jmcneill@. thanks


# 1.62 03-Feb-2020 ryo

separate struct vm_page_md into vm_page_md and pmap_page
for preparation pmap_pv(9)


Revision tags: ad-namecache-base2 ad-namecache-base1
# 1.61 09-Jan-2020 ryo

fix behaviour mmap()/mprotect() when passed only PROT_EXEC.

when mmap()/mprotect() with only PROT_EXEC, syscall will be successful,
but the page actually hadn't been mapped.
it should be mapped with PROT_READ|PROT_EXEC implicitly. (r-x)


Revision tags: ad-namecache-base
# 1.60 30-Dec-2019 skrll

branches: 1.60.2;
Update pmap_map_chunk to allow L[12] block mappings and L3 page mappings


# 1.59 30-Dec-2019 skrll

Remove unnecessary brackets and unwrap a conditional. Same code before
and after.


# 1.58 28-Dec-2019 jmcneill

Do not use Early Write Acknowledge for PCIe I/O and config space.


# 1.57 27-Dec-2019 jmcneill

Enable early write acknowledge for device memory mappings.


# 1.56 19-Dec-2019 skrll

G/C kasan_shadow_map call in pmap_enter

pmap_growkernel calls kasan_shadow_map for KVA


# 1.55 18-Dec-2019 ryo

atomic_add_16() is not used in pmap.c anymore. no need decl here.


# 1.54 18-Dec-2019 ryo

space to tab


# 1.53 14-Dec-2019 skrll

Fix build... wire_count probably doesn't need atomics


# 1.52 13-Dec-2019 skrll

Fix KASAN support by calling kasan_shadow_map in pmap_growkernel


# 1.51 10-Dec-2019 ad

pg->phys_addr -> VM_PAGE_TO_PHYS(pg)


Revision tags: phil-wifi-20191119
# 1.50 14-Nov-2019 maxv

Mark several kASan functions with __nothing, to avoid annoying #ifdefs.
Same as kCSan and kMSan.


# 1.49 14-Nov-2019 maxv

Don't include "opt_kasan.h" when there's already <sys/asan.h> included.


# 1.48 29-Oct-2019 maya

Define PMAP_NEED_PROCWR, providing strategically placed i-cache
synchronization where just-changed memory is about to be executed.

Fixes SIGILLs seen when running Mono 6 on QEMU Cortex-A57.

ok ryo


# 1.47 22-Sep-2019 jmcneill

Disable translation table walks using TTBR0 while changing its value and
when deactivating a pmap. Fixes stability issues on Ampere eMAG CPUs.


# 1.46 20-Sep-2019 ryo

ref/mod bit should be set according to 'flags' argument, not 'prot'. r1.44 was incomplete.


# 1.45 13-Sep-2019 ryo

In pmap_devmap_bootstrap(), cpu_earlydevice_va_p() must not return true until *all* devmap tables have been enabled.
console mapping may be present in the last table.


# 1.44 07-Sep-2019 ryo

- remove incorrect KASSERT. mmap(2) with prot=PROT_WRITE calls pmap_enter(..., PROT_WRITE) internally.
- fix to update page reference flags when only PROT_WRITE or PROT_EXECUTE specified


# 1.43 15-Aug-2019 skrll

Make pmap_db_pte_print more terse so it's quicker on serial consoles


# 1.42 12-Aug-2019 skrll

Use PMAP_DEV in DEVMAP_ENTRY rather than pmap_map_chunk. It's clearer and
means pmap_map_chunk can be made to map other memory types.


Revision tags: netbsd-9-base phil-wifi-20190609
# 1.41 17-May-2019 mrg

branches: 1.41.2;
apply some __diagused.


Revision tags: isaki-audio2-base
# 1.40 08-Apr-2019 ryo

- free empty page tables pages if reach a certain usage.
- need to lock at removing an old pg (_pmap_remove_pv) in _pmap_enter()


# 1.39 06-Apr-2019 ryo

Fix race conditions about pmap_page_protect() and pmap_enter().

while handling same PTE by these functions in same time, there
is a critical path that the number of valid PTEs and wire_count
are inconsistent, and it caused KASSERT.
Need to hold a pv_lock while modifying them.


# 1.38 20-Mar-2019 ryo

spinkle __printflike(), and use PRIxxx


# 1.37 19-Mar-2019 ryo

- add ddb command "machine ttbr" to dump MMU tables.
- tidy up descriptions, usages and messages.


# 1.36 19-Mar-2019 ryo

- free L1-L3 pages that has been emptied by pmap_remove().
- if no memories, pmap_enter will return correctly ENOMEM if PMAP_CANFAIL, or wait until available any memories if !PMAP_CANFAIL.

These changes improves the stability when we use a huge virtual memory spaces with mmap.


# 1.35 06-Feb-2019 ryo

improve pmap_remove
- don't lock/unlock per page in pmap_remove()
- speedup pte lookup for continuous addresses
- bring out pool_cache_put(&_pmap_pv_pool, pv) from lock/unlock section


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226
# 1.34 21-Dec-2018 ryo

- add workaround for Cavium ThunderX errata 27456.
- add cpufuncs table in cpu_info. each cpu clusters may have different erratum. (e.g. big.LITTLE)


Revision tags: pgoyette-compat-1126
# 1.33 01-Nov-2018 maxv

Add kASan support for aarch64. Stack tracking needs more investigation
and will come in a separate commit.

Reviewed by ryo@ jmcneill@ skrll@.


# 1.32 31-Oct-2018 ryo

invalidate icache correctly.
l3pte_executable() should be used for only valid pte.


Revision tags: pgoyette-compat-1020
# 1.31 18-Oct-2018 skrll

Provide generic start code that assumes the MMU is off and caches are
disabled as per the linux booting protocol for ARMv6 and ARMv7 boards.
u-boot image type should be changed to 'linux' for correct behaviour.

The new start code builds a minimal "bootstrap" L1PT with cached access
disabled and uses the same table for all processors. AP startup is
performed in less steps and more code is written in C.

The bootstrap tables and stack are placed into an (orphaned) section
"_init_memory" which is given to uvm when it is no longer used.

Various kernels have been converted to use this code and tested. Some
boards were provided by TNF. Thanks!

The GENERIC kernel now boots on boards using the TEGRA, SUNXI and EXYNOS
kernels. The GENERIC kernel will also work on RPI2 using u-boot.

Thanks to martin@ and aymeric@ for testing on parallella and nanosoc
respectively


# 1.30 14-Oct-2018 skrll

Use __nothing


# 1.29 12-Oct-2018 ryo

add initial support of COMPAT_NETBSD32 on AArch64.
arm ELF32 EABI binaries could be execute in AArch32 state on AArch64. A32 THUMB mode is not supported yet.


# 1.28 12-Oct-2018 ryo

- cleanup checking address ranges with IN_RANGE macro
- change PM_ADDR_CHECK macro to KASSERTMSG
- restore fast lookup cases with IN_RANGE macro for pmap_extract changed in my previous commit.


# 1.27 12-Oct-2018 ryo

rewrite pmap_pte_lookup() to share similar code.


# 1.26 04-Oct-2018 ryo

cleanup locore, and changed the way to map memories during boot.
- add functions bootpage_enter() and bootpage_alloc() to adapt various layout
of physical memory map. especially for 64bit physical memory layout.
pmapboot_alloc() allocates pagetable pages from _end[].
- changed to map only the required amount for PA=VA identity mapping
(kernel image, UART device, and FDT blob) with L2_BLOCK(2Mbyte).
- changing page permission for kernel image, and making KSEG mapping are done
at cpu_kernel_vm_init() instead of at locore.
- optimize PTE entries with PTE Contiguous bit. it is enabled on devmap only for now.

reviewed by skrll@, thanks.


# 1.25 04-Oct-2018 ryo

* define LX_BLKPAG_{OS,ATTR}_* for OS dependent PTE attributes in pmap.h
* cleanup macros


Revision tags: pgoyette-compat-0930
# 1.24 17-Sep-2018 ryo

delete debug printf and KASSERT.


# 1.23 10-Sep-2018 maxv

Replace KDASSERT by panic.


# 1.22 10-Sep-2018 maxv

Rename _pmap_alloc_pdp -> pmap_alloc_pdp, and make it public.


# 1.21 10-Sep-2018 ryo

cleanup aarch64 mpstart and fdt bootstrap
* arm_cpu_hatch_arg is a bad idea. avoid serializing CPU startup, and eliminate arm_cpu_hatch_arg.
in mpstart, resolve own cpu index using array of cpu_mpidr[] (aarch64)
* add support fdt enable-method "spin-table"
* add support fdt enable-method "brcm,bcm2836-smp" (for 32bit RaspberryPi)
* use arm_fdt_cpu_bootstrap() instead of psci_fdt_bootstrap()
* rename "arm/fdt/psci_fdt.h" to "arm/fdt/psci_fdtvar.h" because of conflict of include file for needs-flag
* add devmap for cpu spin-table of raspberrypi3/aarch64
* no need to force hatch APs for raspberrypi3/arm32 ifndef MULTIPROCESSOR.
* fix to work pmap_extract(kerneltext/data/bss) even if before calling pmap_bootstrap

idea to use cpu_mpidr[] by jmcneill@. reviewd by skrll@. thanks.


Revision tags: pgoyette-compat-0906
# 1.20 27-Aug-2018 ryo

need to add VM_PROT_READ when pmap_kenter_pa(va, pa, VM_PROT_WRITE, 0) or pmap_kenter_pa(va, pa, VM_PROT_EXECUTE, 0).
VM_PROT_READ is treated as an access permission inernally.


# 1.19 11-Aug-2018 ryo

change to minimum invalidation of TLB.
specifying not only va but also asid, and not invalidate L0-L2 entry using tlbi_*_ll() if needed.


# 1.18 10-Aug-2018 ryo

treat kernel-exec attr and user-exec attr separately.
kernel cannot execute userland exec page, and user cannot execute kernel page.


# 1.17 06-Aug-2018 ryo

set kernel text/rodata readonly by default.
add function db_write_text() for setting ddb breakpoint.


# 1.16 31-Jul-2018 skrll

Define and use VPRINTF


Revision tags: pgoyette-compat-0728
# 1.15 27-Jul-2018 ryo

changes of pmap.c r1.13 seems to be unstable.
In order to invalidate icache, not to invalidate all icache,
but temporary to make the page writable and invalidate target address only.


# 1.14 24-Jul-2018 ryo

don't call pool_cache_put with locking pmap. pool_cache_put call pmap_kenter_pa internally.
(pool_cache_put_paddr -> pool_cache_put_slow -> pool_get -> pmap_kenter_pa)


# 1.13 23-Jul-2018 ryo

* fix icache invalidations.
* "ic ivau" (aarch64_icache_sync_range) with VA generates permission fault in some situations, therefore use KSEG address for now.


# 1.12 23-Jul-2018 ryo

rather than using flags to resolve nested locks, reserve pool_cache before locking.


# 1.11 21-Jul-2018 ryo

* avoid deadlock. mutex_owned() works only for adaptive lock, therefore we cannot use it for spinlock...
* add more NULL check
* clear pte when pmap_enter() fails


# 1.10 17-Jul-2018 ryo

Use __debugused


# 1.9 17-Jul-2018 christos

Add missing casts, remove unused variables.


# 1.8 09-Jul-2018 ryo

need locks in pmap_kremove() and pmap_fault_fixup()


Revision tags: phil-wifi-base pgoyette-compat-0625 pgoyette-compat-0521
# 1.7 20-May-2018 ryo

branches: 1.7.2;
pmap_enter() must update modified/referenced flags by 'flags' not 'prot'.


# 1.6 16-May-2018 ryo

Fix memory leak. it was leaking one page every pmap_create().
pm->pm_vmlist must be initialized before calling _pmap_alloc_pdp().


Revision tags: pgoyette-compat-0502
# 1.5 29-Apr-2018 ryo

fix KASSERT panic. pv_entry may not be exists in pvlist when pmap_remove().


# 1.4 29-Apr-2018 ryo

delete unused code


# 1.3 27-Apr-2018 ryo

fix instability behavior of bufcache on aarch64.
* fix to return correct ref/mod when PMAP_WIRED.
* changed to keep wired flags in pte instead of pv_entry, and cleanup.


Revision tags: pgoyette-compat-0422 pgoyette-compat-0415 pgoyette-compat-0407
# 1.2 01-Apr-2018 ryo

Add initial support for ARMv8 (AARCH64) (by nisimura@ and ryo@)

- sys/arch/evbarm64 is gone and integrated into sys/arch/evbarm. (by skrll@)
- add support fdt. evbarm/conf/GENERIC64 fdt (bcm2837,sunxi,tegra) based generic 64bit kernel config. (by skrll@, jmcneill@)


Revision tags: netbsd-8-2-RELEASE netbsd-8-1-RELEASE netbsd-8-1-RC1 netbsd-7-2-RELEASE netbsd-8-0-RELEASE netbsd-8-0-RC2 netbsd-8-0-RC1 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 netbsd-7-1-2-RELEASE pgoyette-compat-base netbsd-7-1-1-RELEASE tls-maxphys-base-20171202 matt-nb8-mediatek-base nick-nhusb-base-20170825 perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base pgoyette-localcount-20170320 netbsd-7-1-RELEASE netbsd-7-1-RC2 nick-nhusb-base-20170204 netbsd-7-nhusb-base-20170116 bouyer-socketcan-base pgoyette-localcount-20170107 netbsd-7-1-RC1 nick-nhusb-base-20161204 pgoyette-localcount-20161104 netbsd-7-0-2-RELEASE nick-nhusb-base-20161004 localcount-20160914 netbsd-7-nhusb-base pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907 nick-nhusb-base-20160529 netbsd-7-0-1-RELEASE nick-nhusb-base-20160422 nick-nhusb-base-20160319 nick-nhusb-base-20151226 netbsd-7-0-RELEASE nick-nhusb-base-20150921 netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 nick-nhusb-base-20150606 nick-nhusb-base-20150406 nick-nhusb-base tls-maxphys-base netbsd-7-base
# 1.1 10-Aug-2014 matt

branches: 1.1.4; 1.1.28;
Preliminary files for AARCH64 (64-bit ARM) support.
Enough for a distribution build.


# 1.137 03-May-2022 skrll

Sprinkle some KASSERT(kpreempt_disabled());


# 1.136 27-Apr-2022 ryo

since pmap_activate_efirt() rewrites TTBR0, it is necessary to pmap_activate() again after pmap_deactivate_efirt() to restore the original TTBR0.

- Fix to do pmap_{de,}activate() before/after pmap_{,de}activate_efirt().
- moved kpreempt_{disable,enable}() to the caller since everything between
arm_efirt_md_enter() and arm_efirt_md_exit() should be kpreempt disabled.

ok skrll@


# 1.135 17-Apr-2022 skrll

Add the missing kpreempt_enable to pmap_deactivate_efirt


# 1.134 10-Apr-2022 skrll

No need to flush icache for EFI RT mappings as bootaa64.efi flushed
the full icache for us. (Also this avoids traps)


# 1.133 09-Apr-2022 riastradh

sys: Use membar_release/acquire around reference drop.

This just goes through my recent reference count membar audit and
changes membar_exit to membar_release and membar_enter to
membar_acquire -- this should make everything cheaper on most CPUs
without hurting correctness, because membar_acquire is generally
cheaper than membar_enter.


# 1.132 02-Apr-2022 skrll

Update to support EFI runtime outside the kernel virtual address space
by creating an EFI RT pmap that can be activated / deactivated when
required.

Adds support for EFI RT to ARM_MMU_EXTENDED (ASID) 32-bit Arm machines.

On Arm64 the usage of pmapboot_enter is reduced and the mappings are
created much later in the boot process -- now in cpu_startup_hook.
Backward compatiblity for KVA mapped RT from old bootaa64.efi is
maintained.

Adding support to other platforms should be easier as a result.


# 1.131 19-Mar-2022 skrll

Slight code re-organisation. NFCI.


# 1.130 12-Mar-2022 riastradh

sys: Membar audit around reference count releases.

If two threads are using an object that is freed when the reference
count goes to zero, we need to ensure that all memory operations
related to the object happen before freeing the object.

Using an atomic_dec_uint_nv(&refcnt) == 0 ensures that only one
thread takes responsibility for freeing, but it's not enough to
ensure that the other thread's memory operations happen before the
freeing.

Consider:

Thread A Thread B
obj->foo = 42; obj->baz = 73;
mumble(&obj->bar); grumble(&obj->quux);
/* membar_exit(); */ /* membar_exit(); */
atomic_dec -- not last atomic_dec -- last
/* membar_enter(); */
KASSERT(invariant(obj->foo,
obj->bar));
free_stuff(obj);

The memory barriers ensure that

obj->foo = 42;
mumble(&obj->bar);

in thread A happens before

KASSERT(invariant(obj->foo, obj->bar));
free_stuff(obj);

in thread B. Without them, this ordering is not guaranteed.

So in general it is necessary to do

membar_exit();
if (atomic_dec_uint_nv(&obj->refcnt) != 0)
return;
membar_enter();

to release a reference, for the `last one out hit the lights' style
of reference counting. (This is in contrast to the style where one
thread blocks new references and then waits under a lock for existing
ones to drain with a condvar -- no membar needed thanks to mutex(9).)

I searched for atomic_dec to find all these. Obviously we ought to
have a better abstraction for this because there's so much copypasta.
This is a stop-gap measure to fix actual bugs until we have that. It
would be nice if an abstraction could gracefully handle the different
styles of reference counting in use -- some years ago I drafted an
API for this, but making it cover everything got a little out of hand
(particularly with struct vnode::v_usecount) and I ended up setting
it aside to work on psref/localcount instead for better scalability.

I got bored of adding #ifdef __HAVE_ATOMIC_AS_MEMBAR everywhere, so I
only put it on things that look performance-critical on 5sec review.
We should really adopt membar_enter_preatomic/membar_exit_postatomic
or something (except they are applicable only to atomic r/m/w, not to
atomic_load/store_*, making the naming annoying) and get rid of all
the ifdefs.


# 1.129 05-Mar-2022 skrll

Slight comment improvement.


# 1.128 16-Feb-2022 andvar

fix various typos, mainly in comments.


# 1.127 31-Jan-2022 ryo

add support Hardware updates to Access flag and Dirty state (FEAT_HAFDBS)

- The DBM bit of the PTE is now used to determine if it is writable, and
the AF bit is treated entirely as a reference bit. A valid PTE is always
treated as readable. There can be no valid PTE that is not readable.
- LX_BLKPAG_OS_{READ,WRITE} are used only for debugging purposes,
and has been superseded by LX_BLKPAG_AF and LX_BLKPAG_DBM.
- Improve comment

The need for reference/modify emulation has been eliminated,
and access/permission faults have been reduced, however,
there has been little change in overall performance.


# 1.126 31-Jan-2022 ryo

Skip unnecessary PTE operations and TLB invalidation.


# 1.125 16-Jan-2022 rillig

aarch64/pmap: remove stray semicolon

No binary change.


# 1.124 15-Jan-2022 skrll

The translations that need invalidation are always last level so remove
the (dubious) logic around tracking the level. The "any level" TLB
invalidation maintenance operation are used, but this may change after
further testing.

before
======
1661.0u 420.2s 2:53.82 1197.3% 231+29k 10+33918io 102pf+0w
1646.8u 425.2s 2:52.96 1198.0% 232+29k 1+33937io 49pf+0w
1647.9u 425.7s 2:52.58 1201.6% 232+29k 0+33940io 32pf+0w

After
=====
1602.5u 420.8s 2:49.09 1196.6% 238+30k 24+33893io 54pf+0w
1600.7u 421.3s 2:51.53 1178.8% 238+30k 1+33914io 33pf+0w
1597.5u 424.3s 2:50.46 1186.1% 238+30k 0+33915io 17pf+0w

LGTM from ryo@


# 1.123 14-Jan-2022 skrll

Restore the previous pmap_remove_all behaviour as the new method meant
the n1sdp couldn't complete a build.

No noticeable change in kernel build performance.


# 1.122 04-Jan-2022 skrll

KNF


# 1.121 10-Dec-2021 andvar

s/occured/occurred/ in comments, log messages and man pages.


# 1.120 07-Dec-2021 andvar

fix various typos, mainly in comments.


# 1.119 23-Oct-2021 skrll

Fix non-UVMHIST build


# 1.118 16-Oct-2021 ryo

fix non-MULTIPROCESSOR build


# 1.117 10-Oct-2021 skrll

Use sys/uvm/pmap/pmap_tlb.c on Aarch64 in the same way that some Arm, MIPS,
and some PPC kernels do. This removes the limitation of 256 processes on
CPUs with 8bit ASID field, e.g. Apple M1.

Additionally the following changes have been made

- removed a couple of unnecessary aarch64_tlbi_all calls
- removed any invalidation after freeing page tables due to
_pmap_sweep_pdp. This was never necessary afaict.
- all kernel mappings are marked global and userland mapping not-global.

Performance testing hasn't show a significant difference. The data here
is from building a kernel on an lx2k system with nvme.

before
1489.6u 400.4s 2:40.65 1176.5% 228+224k 0+32289io 57pf+0w
1482.6u 403.2s 2:38.49 1189.9% 228+222k 0+32274io 46pf+0w
1485.4u 402.2s 2:37.27 1200.2% 228+222k 0+32275io 12pf+0w

after
1493.9u 404.6s 2:37.50 1205.4% 227+221k 0+32265io 48pf+0w
1485.0u 408.0s 2:38.54 1194.0% 227+222k 0+32272io 36pf+0w
1484.3u 407.0s 2:35.88 1213.3% 228+224k 0+32268io 14pf+0w

>>> stats.ttest_ind([160.65,158.49,157.27], [157.5,158.54,155.88])
Ttest_indResult(statistic=1.1923622711296888, pvalue=0.2990182944606766)
>>>


# 1.116 30-Sep-2021 skrll

Ensure TCR_EPD0 is set on entry to pmap_activate and ensure it is set as
early as possible for APs.


# 1.115 26-Sep-2021 skrll

Use UVMHIST_CALLARGS


# 1.114 26-Sep-2021 skrll

'\n' is not required in KASSERTMSG either.


# 1.113 26-Sep-2021 skrll

"\n" is not required in KERNHIST


# 1.112 15-Sep-2021 skrll

Use __SHIFTIN. Same code before and after.


# 1.111 12-Sep-2021 skrll

pmap_page_remove: simply and reduce the code size slightly.


# 1.110 09-Sep-2021 skrll

In pmap_icache_sync_range change

for (...) {
...
if (condition) {
// do stuff
}
}

to

for (...) {
...
if (!conditional)
continue;
// do stuff
}

to save on indentation. Same code (modulo register usage) before and
after.


# 1.109 09-Sep-2021 skrll

KNF


Revision tags: thorpej-i2c-spi-conf2-base thorpej-futex2-base thorpej-cfargs2-base cjep_sun2x-base1 cjep_sun2x-base cjep_staticlib_x-base1 thorpej-i2c-spi-conf-base
# 1.108 29-May-2021 skrll

Deal with the pmap limitation of maxproc in a more complete way and
recognise CPUs with only 8bit ASIDs.


Revision tags: cjep_staticlib_x-base
# 1.107 30-Apr-2021 skrll

branches: 1.107.2;
Make the ddb for pmap / pte information pmap agnostic


# 1.106 29-Apr-2021 skrll

Remove some unnecessary tlb invalidate in pmap_growkernel and ASAN shadow
map. Ensure the shadow map mappings are visible to the TLB walkers.


# 1.105 21-Apr-2021 ryo

branches: 1.105.2;
added more attributes of PTE displayed by "ddb>machine pte"


Revision tags: thorpej-cfargs-base
# 1.104 17-Apr-2021 mrg

remove KERNHIST_INIT_STATIC(). it stradles the line between usable
early in boot and broken early in boot by requiring a partly static
structure with another structure that must be present by the time
any uses are performed. theoretically platform code could allocate
a chunk while seting up memory and assign it here, giving a dynamic
sizing for the entry list, but the reality is that all users have
a statically allocated entry list as well.

the existing KERNHIST_LINK_STATIC() is used in conjunction with
KERNHIST_INITIALIZER() instead.

this stops a NULL pointer deref when the _LOG() macro is called
before the storage is linked in, which happens with GCC 10 on OCTEON
with UVMHIST enabled, crashing in very early kernel init.


Revision tags: thorpej-futex-base
# 1.103 09-Mar-2021 ryo

branches: 1.103.2;
fix build error without options DDB.

kvtopte() is referenced from arm/acpi/acpi_machdep.c


# 1.102 13-Feb-2021 ryo

No assignment is needed here.

the loop in pmap_page_remove() always removes the first pv,
and since the list is managed by _pmap_remove_pv(), pp->pp_pv.pv_next always points to the first.


# 1.101 01-Feb-2021 ryo

It is enough to make a page accessible instead of writable.
same fix as r1.76


# 1.100 31-Jan-2021 ryo

implement pmap_remove_all().

The size of struct pv_entry has increased, but speed of kernel build has improved by about 1%
exec and exit should have been improved.


# 1.99 20-Dec-2020 skrll

Improve the English in the previous comment fix.


# 1.98 19-Dec-2020 skrll

Tweak a comment


# 1.97 11-Dec-2020 skrll

s:aarch64/cpufunc.h:arm/cpufunc.h:

a baby step in the grand arm header unification challenge


# 1.96 10-Nov-2020 skrll

AA64 is not MIPS.

Change all KSEG references to directmap


# 1.95 07-Nov-2020 skrll

In pmap_devmap_bootstrap only set pmap_devmap_bootstrap_done if there
is an entry and ALL of the entries have been done. The entry required
for EARLYCONS might not be the first/only one...


# 1.94 01-Nov-2020 jmcneill

branches: 1.94.2;
No need to disable translation table walks in pmap_activate().


# 1.93 22-Oct-2020 skrll

Use the isb macro - missed in previous commit


# 1.92 22-Oct-2020 skrll

Use the dmb/dsb/isb macros... if nothing else they're all now consistent
about the "memory" assembler contraint.

No binary change


# 1.91 28-Sep-2020 skrll

Only set pmap_devmap_bootstrap_done if something gets mapped.

Think acpi_platform_devmap


# 1.90 19-Sep-2020 skrll

Make __md_palloc pmap agnostic (think sys/uvm/pmap)


# 1.89 14-Sep-2020 ryo

PID_MAX is just an initial value (soft maximum). Don't use it for CTASSERT.
defined __HAVE_CPU_MAXPROC to use function cpu_maxproc().

pointed out by mrg@, thanks.


# 1.88 06-Sep-2020 ryo

Fix panic caused by modload. http://mail-index.netbsd.org/port-arm/2020/08/30/msg006960.html

The address space reserved for modules may not be mapped in L1-L3.


# 1.87 14-Aug-2020 skrll

Whitespace


# 1.86 12-Aug-2020 skrll

Part IV of ad's performance improvements for aarch64

- Implement pmap_growkernel(), and update kernel pmap's stats with atomics.

- Then, pmap_kenter_pa() and pmap_kremove() no longer need to allocate
memory nor take pm_lock, because they only modify L3 PTEs.

- Then, pm_lock and pp_lock can be adaptive mutexes at IPL_NONE which are
cheaper than spin mutexes.

- Take the pmap's lock in pmap_extract() if not the kernel's pmap, otherwise
pmap_extract() might see inconsistent state.


# 1.85 09-Aug-2020 skrll

Fix another UVMHIST so it doesn't use %s


# 1.84 16-Jul-2020 skrll

pmapboot_enter simplication
- bootpage_alloc in asm becomes pmapboot_pagealloc in C
- PMAPBOOT_ENTER_NOBLOCK is removed as it's not used
- PMAPBOOT_ENTER_NOOVERWRITE is removed as it's now always on
- physpage_allocator argument is removed as it's always
pmapboot_pagealloc
- Support for EARLYCONS without CONSADDR is removed so that the identity
map for CONSADDR is always known.

For the assembly files:
2 files changed, 40 insertions(+), 89 deletions(-)

LGTM ryo


# 1.83 04-Jul-2020 rin

Use tlen for temporary length variable instead of l, which is usually
used for struct lwp *.

No binary changes.


# 1.82 02-Jul-2020 rin

pmap_procwr(): sync icache even if p != curproc. This fixes applications
like GDB for arm32, that rewrite text of other process.

Thanks to ryo@ for discussion.


# 1.81 02-Jul-2020 rin

Set uvmexp.ncolors appropriately, which is required for some CPU
models with VIPT icache.

Otherwise, alias in virtual address results in inconsistent results,
at least for applications that rewrite text of other process, e.g.,
GDB for arm32.

Also, this hopefully fixes other unexpected failures due to alias.

Confirmed that there's no observable regression in performance;
difference in ``time make -j8'' for GENERIC64 kernel on BCM2837
with and without setting uvmexp.ncolors is within 0.1%.

Thanks to ryo@ for discussion.


# 1.80 27-Jun-2020 rin

Fix typo in name of evcnt(4) counter.


# 1.79 24-Jun-2020 ryo

Fix bug with incorrect range calculation when doing icache sync.
This is called by sysarch(ARM_SYNC_ICACHE) from aarch32 (compat_netbsd32) emul process.

pointed out by rin@, thanks.

XXX pullup-9


# 1.78 14-Jun-2020 ad

- Fix a lock order reversal in pmap_page_protect().

- Make sure pmap is always locked when updating stats; atomics no longer
needed to do that.

- Remove unneeded traversal of pv list in pmap_enter_pv().

- Shrink struct vm_page from 136 to 128 bytes (cache line sized) and struct
pv_entry from 48 to 32 bytes (power of 2 sized).

- Embed a pv_entry in each vm_page. This means PV entries don't need to
be allocated for private anonymous memory / COW pages / most UBC mappings.
Dynamic PV entries are then used only for stuff like shared libraries and
shared memory.

Proposed on port-arm@.


# 1.77 10-Jun-2020 ad

- Wired/resident stats shouldn't covered by PMAPCOUNTERS.
- Rename need_update_pv -> need_enter_pv.

Ok ryo@


# 1.76 01-Jun-2020 ryo

no need to make the PTE writable to do icache_sync, enough to accessible.


# 1.75 15-May-2020 skrll

Use __diagused


# 1.74 15-May-2020 tnn

fix non-diag build


# 1.73 14-May-2020 skrll

Use MUTEX_NODEBUG for PV locks as is commonly done. OK ryo.


# 1.72 13-May-2020 jmcneill

Implement pmap_extract_coherency


Revision tags: bouyer-xenpvh-base2 phil-wifi-20200421 bouyer-xenpvh-base1
# 1.71 18-Apr-2020 skrll

PMAP_DEBUG has been deleted on arm


# 1.70 13-Apr-2020 maxv

Add support for Branch Target Identification (BTI).

On the executable pages that have the GP (Guarded Page) bit, the semantic
of the "br" and "blr" instructions is changed: the CPU expects the first
instruction of the jump/call target to be "bti", and faults if it isn't.

We add the GP bit on the kernel .text pages (and incidentally the .rodata
pages, but we don't care). The compiler adds a "bti c" instruction at the
beginning of each C function. We modify the ENTRY() macros to manually add
"bti c" in the asm functions.

cpuswitch.S needs a specific change: with "br x27" the CPU expects "bti j",
which is bad because the functions begin with "bti c"; switch to "br x16",
for the CPU to accept "bti c".

BTI helps defend against JOP/COP. Tested on Qemu.


Revision tags: phil-wifi-20200411 bouyer-xenpvh-base
# 1.69 08-Apr-2020 ryo

branches: 1.69.2;
use PMAP_PAGE_INIT() to initialize mutex in pmap_page.

VM_MDPAGE_INIT() in pmap_free_pdp() had initialized pp_flags,
so it unintentionally cleared PMAP_PAGE_FLAGS_PV_TRACKED.
use PMAP_PAGE_INIT to avoid using PMAP_PAGE_FLAGS_PV_TRACKED.

pointed out by tnn@, thanks


Revision tags: phil-wifi-20200406
# 1.68 14-Mar-2020 ad

pmap_remove_all(): Return a boolean value to indicate the behaviour. If
true, all mappings have been removed, the pmap is totally cleared out, and
UVM can then avoid doing the work to call pmap_remove() for each map entry.
If false, either nothing has been done, or some helpful arch-specific voodoo
has taken place.


Revision tags: is-mlppp-base
# 1.67 02-Mar-2020 ryo

oops, fix incorrect usage of daif_enable() in my previous commit.


# 1.66 29-Feb-2020 ryo

Fix pmap to work correctly with tagged addresses

- when fault, untag from address before passing to uvm/pmap functions
- pmap_extract() checks more strictly and consider the address tag


# 1.65 29-Feb-2020 ryo

use pmapboot_enter_range()


Revision tags: ad-namecache-base3
# 1.64 10-Feb-2020 ryo

use LIST(3) instead of TAILQ(3) to save one word in struct vm_page and struct pmap.

pointed out by riastradh@. thanks


# 1.63 03-Feb-2020 ryo

add support pmap_pv(9)

Patch originally from jmcneill@. thanks


# 1.62 03-Feb-2020 ryo

separate struct vm_page_md into vm_page_md and pmap_page
for preparation pmap_pv(9)


Revision tags: ad-namecache-base2 ad-namecache-base1
# 1.61 09-Jan-2020 ryo

fix behaviour mmap()/mprotect() when passed only PROT_EXEC.

when mmap()/mprotect() with only PROT_EXEC, syscall will be successful,
but the page actually hadn't been mapped.
it should be mapped with PROT_READ|PROT_EXEC implicitly. (r-x)


Revision tags: ad-namecache-base
# 1.60 30-Dec-2019 skrll

branches: 1.60.2;
Update pmap_map_chunk to allow L[12] block mappings and L3 page mappings


# 1.59 30-Dec-2019 skrll

Remove unnecessary brackets and unwrap a conditional. Same code before
and after.


# 1.58 28-Dec-2019 jmcneill

Do not use Early Write Acknowledge for PCIe I/O and config space.


# 1.57 27-Dec-2019 jmcneill

Enable early write acknowledge for device memory mappings.


# 1.56 19-Dec-2019 skrll

G/C kasan_shadow_map call in pmap_enter

pmap_growkernel calls kasan_shadow_map for KVA


# 1.55 18-Dec-2019 ryo

atomic_add_16() is not used in pmap.c anymore. no need decl here.


# 1.54 18-Dec-2019 ryo

space to tab


# 1.53 14-Dec-2019 skrll

Fix build... wire_count probably doesn't need atomics


# 1.52 13-Dec-2019 skrll

Fix KASAN support by calling kasan_shadow_map in pmap_growkernel


# 1.51 10-Dec-2019 ad

pg->phys_addr -> VM_PAGE_TO_PHYS(pg)


Revision tags: phil-wifi-20191119
# 1.50 14-Nov-2019 maxv

Mark several kASan functions with __nothing, to avoid annoying #ifdefs.
Same as kCSan and kMSan.


# 1.49 14-Nov-2019 maxv

Don't include "opt_kasan.h" when there's already <sys/asan.h> included.


# 1.48 29-Oct-2019 maya

Define PMAP_NEED_PROCWR, providing strategically placed i-cache
synchronization where just-changed memory is about to be executed.

Fixes SIGILLs seen when running Mono 6 on QEMU Cortex-A57.

ok ryo


# 1.47 22-Sep-2019 jmcneill

Disable translation table walks using TTBR0 while changing its value and
when deactivating a pmap. Fixes stability issues on Ampere eMAG CPUs.


# 1.46 20-Sep-2019 ryo

ref/mod bit should be set according to 'flags' argument, not 'prot'. r1.44 was incomplete.


# 1.45 13-Sep-2019 ryo

In pmap_devmap_bootstrap(), cpu_earlydevice_va_p() must not return true until *all* devmap tables have been enabled.
console mapping may be present in the last table.


# 1.44 07-Sep-2019 ryo

- remove incorrect KASSERT. mmap(2) with prot=PROT_WRITE calls pmap_enter(..., PROT_WRITE) internally.
- fix to update page reference flags when only PROT_WRITE or PROT_EXECUTE specified


# 1.43 15-Aug-2019 skrll

Make pmap_db_pte_print more terse so it's quicker on serial consoles


# 1.42 12-Aug-2019 skrll

Use PMAP_DEV in DEVMAP_ENTRY rather than pmap_map_chunk. It's clearer and
means pmap_map_chunk can be made to map other memory types.


Revision tags: netbsd-9-base phil-wifi-20190609
# 1.41 17-May-2019 mrg

branches: 1.41.2;
apply some __diagused.


Revision tags: isaki-audio2-base
# 1.40 08-Apr-2019 ryo

- free empty page tables pages if reach a certain usage.
- need to lock at removing an old pg (_pmap_remove_pv) in _pmap_enter()


# 1.39 06-Apr-2019 ryo

Fix race conditions about pmap_page_protect() and pmap_enter().

while handling same PTE by these functions in same time, there
is a critical path that the number of valid PTEs and wire_count
are inconsistent, and it caused KASSERT.
Need to hold a pv_lock while modifying them.


# 1.38 20-Mar-2019 ryo

spinkle __printflike(), and use PRIxxx


# 1.37 19-Mar-2019 ryo

- add ddb command "machine ttbr" to dump MMU tables.
- tidy up descriptions, usages and messages.


# 1.36 19-Mar-2019 ryo

- free L1-L3 pages that has been emptied by pmap_remove().
- if no memories, pmap_enter will return correctly ENOMEM if PMAP_CANFAIL, or wait until available any memories if !PMAP_CANFAIL.

These changes improves the stability when we use a huge virtual memory spaces with mmap.


# 1.35 06-Feb-2019 ryo

improve pmap_remove
- don't lock/unlock per page in pmap_remove()
- speedup pte lookup for continuous addresses
- bring out pool_cache_put(&_pmap_pv_pool, pv) from lock/unlock section


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226
# 1.34 21-Dec-2018 ryo

- add workaround for Cavium ThunderX errata 27456.
- add cpufuncs table in cpu_info. each cpu clusters may have different erratum. (e.g. big.LITTLE)


Revision tags: pgoyette-compat-1126
# 1.33 01-Nov-2018 maxv

Add kASan support for aarch64. Stack tracking needs more investigation
and will come in a separate commit.

Reviewed by ryo@ jmcneill@ skrll@.


# 1.32 31-Oct-2018 ryo

invalidate icache correctly.
l3pte_executable() should be used for only valid pte.


Revision tags: pgoyette-compat-1020
# 1.31 18-Oct-2018 skrll

Provide generic start code that assumes the MMU is off and caches are
disabled as per the linux booting protocol for ARMv6 and ARMv7 boards.
u-boot image type should be changed to 'linux' for correct behaviour.

The new start code builds a minimal "bootstrap" L1PT with cached access
disabled and uses the same table for all processors. AP startup is
performed in less steps and more code is written in C.

The bootstrap tables and stack are placed into an (orphaned) section
"_init_memory" which is given to uvm when it is no longer used.

Various kernels have been converted to use this code and tested. Some
boards were provided by TNF. Thanks!

The GENERIC kernel now boots on boards using the TEGRA, SUNXI and EXYNOS
kernels. The GENERIC kernel will also work on RPI2 using u-boot.

Thanks to martin@ and aymeric@ for testing on parallella and nanosoc
respectively


# 1.30 14-Oct-2018 skrll

Use __nothing


# 1.29 12-Oct-2018 ryo

add initial support of COMPAT_NETBSD32 on AArch64.
arm ELF32 EABI binaries could be execute in AArch32 state on AArch64. A32 THUMB mode is not supported yet.


# 1.28 12-Oct-2018 ryo

- cleanup checking address ranges with IN_RANGE macro
- change PM_ADDR_CHECK macro to KASSERTMSG
- restore fast lookup cases with IN_RANGE macro for pmap_extract changed in my previous commit.


# 1.27 12-Oct-2018 ryo

rewrite pmap_pte_lookup() to share similar code.


# 1.26 04-Oct-2018 ryo

cleanup locore, and changed the way to map memories during boot.
- add functions bootpage_enter() and bootpage_alloc() to adapt various layout
of physical memory map. especially for 64bit physical memory layout.
pmapboot_alloc() allocates pagetable pages from _end[].
- changed to map only the required amount for PA=VA identity mapping
(kernel image, UART device, and FDT blob) with L2_BLOCK(2Mbyte).
- changing page permission for kernel image, and making KSEG mapping are done
at cpu_kernel_vm_init() instead of at locore.
- optimize PTE entries with PTE Contiguous bit. it is enabled on devmap only for now.

reviewed by skrll@, thanks.


# 1.25 04-Oct-2018 ryo

* define LX_BLKPAG_{OS,ATTR}_* for OS dependent PTE attributes in pmap.h
* cleanup macros


Revision tags: pgoyette-compat-0930
# 1.24 17-Sep-2018 ryo

delete debug printf and KASSERT.


# 1.23 10-Sep-2018 maxv

Replace KDASSERT by panic.


# 1.22 10-Sep-2018 maxv

Rename _pmap_alloc_pdp -> pmap_alloc_pdp, and make it public.


# 1.21 10-Sep-2018 ryo

cleanup aarch64 mpstart and fdt bootstrap
* arm_cpu_hatch_arg is a bad idea. avoid serializing CPU startup, and eliminate arm_cpu_hatch_arg.
in mpstart, resolve own cpu index using array of cpu_mpidr[] (aarch64)
* add support fdt enable-method "spin-table"
* add support fdt enable-method "brcm,bcm2836-smp" (for 32bit RaspberryPi)
* use arm_fdt_cpu_bootstrap() instead of psci_fdt_bootstrap()
* rename "arm/fdt/psci_fdt.h" to "arm/fdt/psci_fdtvar.h" because of conflict of include file for needs-flag
* add devmap for cpu spin-table of raspberrypi3/aarch64
* no need to force hatch APs for raspberrypi3/arm32 ifndef MULTIPROCESSOR.
* fix to work pmap_extract(kerneltext/data/bss) even if before calling pmap_bootstrap

idea to use cpu_mpidr[] by jmcneill@. reviewd by skrll@. thanks.


Revision tags: pgoyette-compat-0906
# 1.20 27-Aug-2018 ryo

need to add VM_PROT_READ when pmap_kenter_pa(va, pa, VM_PROT_WRITE, 0) or pmap_kenter_pa(va, pa, VM_PROT_EXECUTE, 0).
VM_PROT_READ is treated as an access permission inernally.


# 1.19 11-Aug-2018 ryo

change to minimum invalidation of TLB.
specifying not only va but also asid, and not invalidate L0-L2 entry using tlbi_*_ll() if needed.


# 1.18 10-Aug-2018 ryo

treat kernel-exec attr and user-exec attr separately.
kernel cannot execute userland exec page, and user cannot execute kernel page.


# 1.17 06-Aug-2018 ryo

set kernel text/rodata readonly by default.
add function db_write_text() for setting ddb breakpoint.


# 1.16 31-Jul-2018 skrll

Define and use VPRINTF


Revision tags: pgoyette-compat-0728
# 1.15 27-Jul-2018 ryo

changes of pmap.c r1.13 seems to be unstable.
In order to invalidate icache, not to invalidate all icache,
but temporary to make the page writable and invalidate target address only.


# 1.14 24-Jul-2018 ryo

don't call pool_cache_put with locking pmap. pool_cache_put call pmap_kenter_pa internally.
(pool_cache_put_paddr -> pool_cache_put_slow -> pool_get -> pmap_kenter_pa)


# 1.13 23-Jul-2018 ryo

* fix icache invalidations.
* "ic ivau" (aarch64_icache_sync_range) with VA generates permission fault in some situations, therefore use KSEG address for now.


# 1.12 23-Jul-2018 ryo

rather than using flags to resolve nested locks, reserve pool_cache before locking.


# 1.11 21-Jul-2018 ryo

* avoid deadlock. mutex_owned() works only for adaptive lock, therefore we cannot use it for spinlock...
* add more NULL check
* clear pte when pmap_enter() fails


# 1.10 17-Jul-2018 ryo

Use __debugused


# 1.9 17-Jul-2018 christos

Add missing casts, remove unused variables.


# 1.8 09-Jul-2018 ryo

need locks in pmap_kremove() and pmap_fault_fixup()


Revision tags: phil-wifi-base pgoyette-compat-0625 pgoyette-compat-0521
# 1.7 20-May-2018 ryo

branches: 1.7.2;
pmap_enter() must update modified/referenced flags by 'flags' not 'prot'.


# 1.6 16-May-2018 ryo

Fix memory leak. it was leaking one page every pmap_create().
pm->pm_vmlist must be initialized before calling _pmap_alloc_pdp().


Revision tags: pgoyette-compat-0502
# 1.5 29-Apr-2018 ryo

fix KASSERT panic. pv_entry may not be exists in pvlist when pmap_remove().


# 1.4 29-Apr-2018 ryo

delete unused code


# 1.3 27-Apr-2018 ryo

fix instability behavior of bufcache on aarch64.
* fix to return correct ref/mod when PMAP_WIRED.
* changed to keep wired flags in pte instead of pv_entry, and cleanup.


Revision tags: pgoyette-compat-0422 pgoyette-compat-0415 pgoyette-compat-0407
# 1.2 01-Apr-2018 ryo

Add initial support for ARMv8 (AARCH64) (by nisimura@ and ryo@)

- sys/arch/evbarm64 is gone and integrated into sys/arch/evbarm. (by skrll@)
- add support fdt. evbarm/conf/GENERIC64 fdt (bcm2837,sunxi,tegra) based generic 64bit kernel config. (by skrll@, jmcneill@)


Revision tags: netbsd-8-2-RELEASE netbsd-8-1-RELEASE netbsd-8-1-RC1 netbsd-7-2-RELEASE netbsd-8-0-RELEASE netbsd-8-0-RC2 netbsd-8-0-RC1 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 netbsd-7-1-2-RELEASE pgoyette-compat-base netbsd-7-1-1-RELEASE tls-maxphys-base-20171202 matt-nb8-mediatek-base nick-nhusb-base-20170825 perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base pgoyette-localcount-20170320 netbsd-7-1-RELEASE netbsd-7-1-RC2 nick-nhusb-base-20170204 netbsd-7-nhusb-base-20170116 bouyer-socketcan-base pgoyette-localcount-20170107 netbsd-7-1-RC1 nick-nhusb-base-20161204 pgoyette-localcount-20161104 netbsd-7-0-2-RELEASE nick-nhusb-base-20161004 localcount-20160914 netbsd-7-nhusb-base pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907 nick-nhusb-base-20160529 netbsd-7-0-1-RELEASE nick-nhusb-base-20160422 nick-nhusb-base-20160319 nick-nhusb-base-20151226 netbsd-7-0-RELEASE nick-nhusb-base-20150921 netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 nick-nhusb-base-20150606 nick-nhusb-base-20150406 nick-nhusb-base tls-maxphys-base netbsd-7-base
# 1.1 10-Aug-2014 matt

branches: 1.1.4; 1.1.28;
Preliminary files for AARCH64 (64-bit ARM) support.
Enough for a distribution build.


# 1.136 27-Apr-2022 ryo

since pmap_activate_efirt() rewrites TTBR0, it is necessary to pmap_activate() again after pmap_deactivate_efirt() to restore the original TTBR0.

- Fix to do pmap_{de,}activate() before/after pmap_{,de}activate_efirt().
- moved kpreempt_{disable,enable}() to the caller since everything between
arm_efirt_md_enter() and arm_efirt_md_exit() should be kpreempt disabled.

ok skrll@


# 1.135 17-Apr-2022 skrll

Add the missing kpreempt_enable to pmap_deactivate_efirt


# 1.134 10-Apr-2022 skrll

No need to flush icache for EFI RT mappings as bootaa64.efi flushed
the full icache for us. (Also this avoids traps)


# 1.133 09-Apr-2022 riastradh

sys: Use membar_release/acquire around reference drop.

This just goes through my recent reference count membar audit and
changes membar_exit to membar_release and membar_enter to
membar_acquire -- this should make everything cheaper on most CPUs
without hurting correctness, because membar_acquire is generally
cheaper than membar_enter.


# 1.132 02-Apr-2022 skrll

Update to support EFI runtime outside the kernel virtual address space
by creating an EFI RT pmap that can be activated / deactivated when
required.

Adds support for EFI RT to ARM_MMU_EXTENDED (ASID) 32-bit Arm machines.

On Arm64 the usage of pmapboot_enter is reduced and the mappings are
created much later in the boot process -- now in cpu_startup_hook.
Backward compatiblity for KVA mapped RT from old bootaa64.efi is
maintained.

Adding support to other platforms should be easier as a result.


# 1.131 19-Mar-2022 skrll

Slight code re-organisation. NFCI.


# 1.130 12-Mar-2022 riastradh

sys: Membar audit around reference count releases.

If two threads are using an object that is freed when the reference
count goes to zero, we need to ensure that all memory operations
related to the object happen before freeing the object.

Using an atomic_dec_uint_nv(&refcnt) == 0 ensures that only one
thread takes responsibility for freeing, but it's not enough to
ensure that the other thread's memory operations happen before the
freeing.

Consider:

Thread A Thread B
obj->foo = 42; obj->baz = 73;
mumble(&obj->bar); grumble(&obj->quux);
/* membar_exit(); */ /* membar_exit(); */
atomic_dec -- not last atomic_dec -- last
/* membar_enter(); */
KASSERT(invariant(obj->foo,
obj->bar));
free_stuff(obj);

The memory barriers ensure that

obj->foo = 42;
mumble(&obj->bar);

in thread A happens before

KASSERT(invariant(obj->foo, obj->bar));
free_stuff(obj);

in thread B. Without them, this ordering is not guaranteed.

So in general it is necessary to do

membar_exit();
if (atomic_dec_uint_nv(&obj->refcnt) != 0)
return;
membar_enter();

to release a reference, for the `last one out hit the lights' style
of reference counting. (This is in contrast to the style where one
thread blocks new references and then waits under a lock for existing
ones to drain with a condvar -- no membar needed thanks to mutex(9).)

I searched for atomic_dec to find all these. Obviously we ought to
have a better abstraction for this because there's so much copypasta.
This is a stop-gap measure to fix actual bugs until we have that. It
would be nice if an abstraction could gracefully handle the different
styles of reference counting in use -- some years ago I drafted an
API for this, but making it cover everything got a little out of hand
(particularly with struct vnode::v_usecount) and I ended up setting
it aside to work on psref/localcount instead for better scalability.

I got bored of adding #ifdef __HAVE_ATOMIC_AS_MEMBAR everywhere, so I
only put it on things that look performance-critical on 5sec review.
We should really adopt membar_enter_preatomic/membar_exit_postatomic
or something (except they are applicable only to atomic r/m/w, not to
atomic_load/store_*, making the naming annoying) and get rid of all
the ifdefs.


# 1.129 05-Mar-2022 skrll

Slight comment improvement.


# 1.128 16-Feb-2022 andvar

fix various typos, mainly in comments.


# 1.127 31-Jan-2022 ryo

add support Hardware updates to Access flag and Dirty state (FEAT_HAFDBS)

- The DBM bit of the PTE is now used to determine if it is writable, and
the AF bit is treated entirely as a reference bit. A valid PTE is always
treated as readable. There can be no valid PTE that is not readable.
- LX_BLKPAG_OS_{READ,WRITE} are used only for debugging purposes,
and has been superseded by LX_BLKPAG_AF and LX_BLKPAG_DBM.
- Improve comment

The need for reference/modify emulation has been eliminated,
and access/permission faults have been reduced, however,
there has been little change in overall performance.


# 1.126 31-Jan-2022 ryo

Skip unnecessary PTE operations and TLB invalidation.


# 1.125 16-Jan-2022 rillig

aarch64/pmap: remove stray semicolon

No binary change.


# 1.124 15-Jan-2022 skrll

The translations that need invalidation are always last level so remove
the (dubious) logic around tracking the level. The "any level" TLB
invalidation maintenance operation are used, but this may change after
further testing.

before
======
1661.0u 420.2s 2:53.82 1197.3% 231+29k 10+33918io 102pf+0w
1646.8u 425.2s 2:52.96 1198.0% 232+29k 1+33937io 49pf+0w
1647.9u 425.7s 2:52.58 1201.6% 232+29k 0+33940io 32pf+0w

After
=====
1602.5u 420.8s 2:49.09 1196.6% 238+30k 24+33893io 54pf+0w
1600.7u 421.3s 2:51.53 1178.8% 238+30k 1+33914io 33pf+0w
1597.5u 424.3s 2:50.46 1186.1% 238+30k 0+33915io 17pf+0w

LGTM from ryo@


# 1.123 14-Jan-2022 skrll

Restore the previous pmap_remove_all behaviour as the new method meant
the n1sdp couldn't complete a build.

No noticeable change in kernel build performance.


# 1.122 04-Jan-2022 skrll

KNF


# 1.121 10-Dec-2021 andvar

s/occured/occurred/ in comments, log messages and man pages.


# 1.120 07-Dec-2021 andvar

fix various typos, mainly in comments.


# 1.119 23-Oct-2021 skrll

Fix non-UVMHIST build


# 1.118 16-Oct-2021 ryo

fix non-MULTIPROCESSOR build


# 1.117 10-Oct-2021 skrll

Use sys/uvm/pmap/pmap_tlb.c on Aarch64 in the same way that some Arm, MIPS,
and some PPC kernels do. This removes the limitation of 256 processes on
CPUs with 8bit ASID field, e.g. Apple M1.

Additionally the following changes have been made

- removed a couple of unnecessary aarch64_tlbi_all calls
- removed any invalidation after freeing page tables due to
_pmap_sweep_pdp. This was never necessary afaict.
- all kernel mappings are marked global and userland mapping not-global.

Performance testing hasn't show a significant difference. The data here
is from building a kernel on an lx2k system with nvme.

before
1489.6u 400.4s 2:40.65 1176.5% 228+224k 0+32289io 57pf+0w
1482.6u 403.2s 2:38.49 1189.9% 228+222k 0+32274io 46pf+0w
1485.4u 402.2s 2:37.27 1200.2% 228+222k 0+32275io 12pf+0w

after
1493.9u 404.6s 2:37.50 1205.4% 227+221k 0+32265io 48pf+0w
1485.0u 408.0s 2:38.54 1194.0% 227+222k 0+32272io 36pf+0w
1484.3u 407.0s 2:35.88 1213.3% 228+224k 0+32268io 14pf+0w

>>> stats.ttest_ind([160.65,158.49,157.27], [157.5,158.54,155.88])
Ttest_indResult(statistic=1.1923622711296888, pvalue=0.2990182944606766)
>>>


# 1.116 30-Sep-2021 skrll

Ensure TCR_EPD0 is set on entry to pmap_activate and ensure it is set as
early as possible for APs.


# 1.115 26-Sep-2021 skrll

Use UVMHIST_CALLARGS


# 1.114 26-Sep-2021 skrll

'\n' is not required in KASSERTMSG either.


# 1.113 26-Sep-2021 skrll

"\n" is not required in KERNHIST


# 1.112 15-Sep-2021 skrll

Use __SHIFTIN. Same code before and after.


# 1.111 12-Sep-2021 skrll

pmap_page_remove: simply and reduce the code size slightly.


# 1.110 09-Sep-2021 skrll

In pmap_icache_sync_range change

for (...) {
...
if (condition) {
// do stuff
}
}

to

for (...) {
...
if (!conditional)
continue;
// do stuff
}

to save on indentation. Same code (modulo register usage) before and
after.


# 1.109 09-Sep-2021 skrll

KNF


Revision tags: thorpej-i2c-spi-conf2-base thorpej-futex2-base thorpej-cfargs2-base cjep_sun2x-base1 cjep_sun2x-base cjep_staticlib_x-base1 thorpej-i2c-spi-conf-base
# 1.108 29-May-2021 skrll

Deal with the pmap limitation of maxproc in a more complete way and
recognise CPUs with only 8bit ASIDs.


Revision tags: cjep_staticlib_x-base
# 1.107 30-Apr-2021 skrll

branches: 1.107.2;
Make the ddb for pmap / pte information pmap agnostic


# 1.106 29-Apr-2021 skrll

Remove some unnecessary tlb invalidate in pmap_growkernel and ASAN shadow
map. Ensure the shadow map mappings are visible to the TLB walkers.


# 1.105 21-Apr-2021 ryo

branches: 1.105.2;
added more attributes of PTE displayed by "ddb>machine pte"


Revision tags: thorpej-cfargs-base
# 1.104 17-Apr-2021 mrg

remove KERNHIST_INIT_STATIC(). it stradles the line between usable
early in boot and broken early in boot by requiring a partly static
structure with another structure that must be present by the time
any uses are performed. theoretically platform code could allocate
a chunk while seting up memory and assign it here, giving a dynamic
sizing for the entry list, but the reality is that all users have
a statically allocated entry list as well.

the existing KERNHIST_LINK_STATIC() is used in conjunction with
KERNHIST_INITIALIZER() instead.

this stops a NULL pointer deref when the _LOG() macro is called
before the storage is linked in, which happens with GCC 10 on OCTEON
with UVMHIST enabled, crashing in very early kernel init.


Revision tags: thorpej-futex-base
# 1.103 09-Mar-2021 ryo

branches: 1.103.2;
fix build error without options DDB.

kvtopte() is referenced from arm/acpi/acpi_machdep.c


# 1.102 13-Feb-2021 ryo

No assignment is needed here.

the loop in pmap_page_remove() always removes the first pv,
and since the list is managed by _pmap_remove_pv(), pp->pp_pv.pv_next always points to the first.


# 1.101 01-Feb-2021 ryo

It is enough to make a page accessible instead of writable.
same fix as r1.76


# 1.100 31-Jan-2021 ryo

implement pmap_remove_all().

The size of struct pv_entry has increased, but speed of kernel build has improved by about 1%
exec and exit should have been improved.


# 1.99 20-Dec-2020 skrll

Improve the English in the previous comment fix.


# 1.98 19-Dec-2020 skrll

Tweak a comment


# 1.97 11-Dec-2020 skrll

s:aarch64/cpufunc.h:arm/cpufunc.h:

a baby step in the grand arm header unification challenge


# 1.96 10-Nov-2020 skrll

AA64 is not MIPS.

Change all KSEG references to directmap


# 1.95 07-Nov-2020 skrll

In pmap_devmap_bootstrap only set pmap_devmap_bootstrap_done if there
is an entry and ALL of the entries have been done. The entry required
for EARLYCONS might not be the first/only one...


# 1.94 01-Nov-2020 jmcneill

branches: 1.94.2;
No need to disable translation table walks in pmap_activate().


# 1.93 22-Oct-2020 skrll

Use the isb macro - missed in previous commit


# 1.92 22-Oct-2020 skrll

Use the dmb/dsb/isb macros... if nothing else they're all now consistent
about the "memory" assembler contraint.

No binary change


# 1.91 28-Sep-2020 skrll

Only set pmap_devmap_bootstrap_done if something gets mapped.

Think acpi_platform_devmap


# 1.90 19-Sep-2020 skrll

Make __md_palloc pmap agnostic (think sys/uvm/pmap)


# 1.89 14-Sep-2020 ryo

PID_MAX is just an initial value (soft maximum). Don't use it for CTASSERT.
defined __HAVE_CPU_MAXPROC to use function cpu_maxproc().

pointed out by mrg@, thanks.


# 1.88 06-Sep-2020 ryo

Fix panic caused by modload. http://mail-index.netbsd.org/port-arm/2020/08/30/msg006960.html

The address space reserved for modules may not be mapped in L1-L3.


# 1.87 14-Aug-2020 skrll

Whitespace


# 1.86 12-Aug-2020 skrll

Part IV of ad's performance improvements for aarch64

- Implement pmap_growkernel(), and update kernel pmap's stats with atomics.

- Then, pmap_kenter_pa() and pmap_kremove() no longer need to allocate
memory nor take pm_lock, because they only modify L3 PTEs.

- Then, pm_lock and pp_lock can be adaptive mutexes at IPL_NONE which are
cheaper than spin mutexes.

- Take the pmap's lock in pmap_extract() if not the kernel's pmap, otherwise
pmap_extract() might see inconsistent state.


# 1.85 09-Aug-2020 skrll

Fix another UVMHIST so it doesn't use %s


# 1.84 16-Jul-2020 skrll

pmapboot_enter simplication
- bootpage_alloc in asm becomes pmapboot_pagealloc in C
- PMAPBOOT_ENTER_NOBLOCK is removed as it's not used
- PMAPBOOT_ENTER_NOOVERWRITE is removed as it's now always on
- physpage_allocator argument is removed as it's always
pmapboot_pagealloc
- Support for EARLYCONS without CONSADDR is removed so that the identity
map for CONSADDR is always known.

For the assembly files:
2 files changed, 40 insertions(+), 89 deletions(-)

LGTM ryo


# 1.83 04-Jul-2020 rin

Use tlen for temporary length variable instead of l, which is usually
used for struct lwp *.

No binary changes.


# 1.82 02-Jul-2020 rin

pmap_procwr(): sync icache even if p != curproc. This fixes applications
like GDB for arm32, that rewrite text of other process.

Thanks to ryo@ for discussion.


# 1.81 02-Jul-2020 rin

Set uvmexp.ncolors appropriately, which is required for some CPU
models with VIPT icache.

Otherwise, alias in virtual address results in inconsistent results,
at least for applications that rewrite text of other process, e.g.,
GDB for arm32.

Also, this hopefully fixes other unexpected failures due to alias.

Confirmed that there's no observable regression in performance;
difference in ``time make -j8'' for GENERIC64 kernel on BCM2837
with and without setting uvmexp.ncolors is within 0.1%.

Thanks to ryo@ for discussion.


# 1.80 27-Jun-2020 rin

Fix typo in name of evcnt(4) counter.


# 1.79 24-Jun-2020 ryo

Fix bug with incorrect range calculation when doing icache sync.
This is called by sysarch(ARM_SYNC_ICACHE) from aarch32 (compat_netbsd32) emul process.

pointed out by rin@, thanks.

XXX pullup-9


# 1.78 14-Jun-2020 ad

- Fix a lock order reversal in pmap_page_protect().

- Make sure pmap is always locked when updating stats; atomics no longer
needed to do that.

- Remove unneeded traversal of pv list in pmap_enter_pv().

- Shrink struct vm_page from 136 to 128 bytes (cache line sized) and struct
pv_entry from 48 to 32 bytes (power of 2 sized).

- Embed a pv_entry in each vm_page. This means PV entries don't need to
be allocated for private anonymous memory / COW pages / most UBC mappings.
Dynamic PV entries are then used only for stuff like shared libraries and
shared memory.

Proposed on port-arm@.


# 1.77 10-Jun-2020 ad

- Wired/resident stats shouldn't covered by PMAPCOUNTERS.
- Rename need_update_pv -> need_enter_pv.

Ok ryo@


# 1.76 01-Jun-2020 ryo

no need to make the PTE writable to do icache_sync, enough to accessible.


# 1.75 15-May-2020 skrll

Use __diagused


# 1.74 15-May-2020 tnn

fix non-diag build


# 1.73 14-May-2020 skrll

Use MUTEX_NODEBUG for PV locks as is commonly done. OK ryo.


# 1.72 13-May-2020 jmcneill

Implement pmap_extract_coherency


Revision tags: bouyer-xenpvh-base2 phil-wifi-20200421 bouyer-xenpvh-base1
# 1.71 18-Apr-2020 skrll

PMAP_DEBUG has been deleted on arm


# 1.70 13-Apr-2020 maxv

Add support for Branch Target Identification (BTI).

On the executable pages that have the GP (Guarded Page) bit, the semantic
of the "br" and "blr" instructions is changed: the CPU expects the first
instruction of the jump/call target to be "bti", and faults if it isn't.

We add the GP bit on the kernel .text pages (and incidentally the .rodata
pages, but we don't care). The compiler adds a "bti c" instruction at the
beginning of each C function. We modify the ENTRY() macros to manually add
"bti c" in the asm functions.

cpuswitch.S needs a specific change: with "br x27" the CPU expects "bti j",
which is bad because the functions begin with "bti c"; switch to "br x16",
for the CPU to accept "bti c".

BTI helps defend against JOP/COP. Tested on Qemu.


Revision tags: phil-wifi-20200411 bouyer-xenpvh-base
# 1.69 08-Apr-2020 ryo

branches: 1.69.2;
use PMAP_PAGE_INIT() to initialize mutex in pmap_page.

VM_MDPAGE_INIT() in pmap_free_pdp() had initialized pp_flags,
so it unintentionally cleared PMAP_PAGE_FLAGS_PV_TRACKED.
use PMAP_PAGE_INIT to avoid using PMAP_PAGE_FLAGS_PV_TRACKED.

pointed out by tnn@, thanks


Revision tags: phil-wifi-20200406
# 1.68 14-Mar-2020 ad

pmap_remove_all(): Return a boolean value to indicate the behaviour. If
true, all mappings have been removed, the pmap is totally cleared out, and
UVM can then avoid doing the work to call pmap_remove() for each map entry.
If false, either nothing has been done, or some helpful arch-specific voodoo
has taken place.


Revision tags: is-mlppp-base
# 1.67 02-Mar-2020 ryo

oops, fix incorrect usage of daif_enable() in my previous commit.


# 1.66 29-Feb-2020 ryo

Fix pmap to work correctly with tagged addresses

- when fault, untag from address before passing to uvm/pmap functions
- pmap_extract() checks more strictly and consider the address tag


# 1.65 29-Feb-2020 ryo

use pmapboot_enter_range()


Revision tags: ad-namecache-base3
# 1.64 10-Feb-2020 ryo

use LIST(3) instead of TAILQ(3) to save one word in struct vm_page and struct pmap.

pointed out by riastradh@. thanks


# 1.63 03-Feb-2020 ryo

add support pmap_pv(9)

Patch originally from jmcneill@. thanks


# 1.62 03-Feb-2020 ryo

separate struct vm_page_md into vm_page_md and pmap_page
for preparation pmap_pv(9)


Revision tags: ad-namecache-base2 ad-namecache-base1
# 1.61 09-Jan-2020 ryo

fix behaviour mmap()/mprotect() when passed only PROT_EXEC.

when mmap()/mprotect() with only PROT_EXEC, syscall will be successful,
but the page actually hadn't been mapped.
it should be mapped with PROT_READ|PROT_EXEC implicitly. (r-x)


Revision tags: ad-namecache-base
# 1.60 30-Dec-2019 skrll

branches: 1.60.2;
Update pmap_map_chunk to allow L[12] block mappings and L3 page mappings


# 1.59 30-Dec-2019 skrll

Remove unnecessary brackets and unwrap a conditional. Same code before
and after.


# 1.58 28-Dec-2019 jmcneill

Do not use Early Write Acknowledge for PCIe I/O and config space.


# 1.57 27-Dec-2019 jmcneill

Enable early write acknowledge for device memory mappings.


# 1.56 19-Dec-2019 skrll

G/C kasan_shadow_map call in pmap_enter

pmap_growkernel calls kasan_shadow_map for KVA


# 1.55 18-Dec-2019 ryo

atomic_add_16() is not used in pmap.c anymore. no need decl here.


# 1.54 18-Dec-2019 ryo

space to tab


# 1.53 14-Dec-2019 skrll

Fix build... wire_count probably doesn't need atomics


# 1.52 13-Dec-2019 skrll

Fix KASAN support by calling kasan_shadow_map in pmap_growkernel


# 1.51 10-Dec-2019 ad

pg->phys_addr -> VM_PAGE_TO_PHYS(pg)


Revision tags: phil-wifi-20191119
# 1.50 14-Nov-2019 maxv

Mark several kASan functions with __nothing, to avoid annoying #ifdefs.
Same as kCSan and kMSan.


# 1.49 14-Nov-2019 maxv

Don't include "opt_kasan.h" when there's already <sys/asan.h> included.


# 1.48 29-Oct-2019 maya

Define PMAP_NEED_PROCWR, providing strategically placed i-cache
synchronization where just-changed memory is about to be executed.

Fixes SIGILLs seen when running Mono 6 on QEMU Cortex-A57.

ok ryo


# 1.47 22-Sep-2019 jmcneill

Disable translation table walks using TTBR0 while changing its value and
when deactivating a pmap. Fixes stability issues on Ampere eMAG CPUs.


# 1.46 20-Sep-2019 ryo

ref/mod bit should be set according to 'flags' argument, not 'prot'. r1.44 was incomplete.


# 1.45 13-Sep-2019 ryo

In pmap_devmap_bootstrap(), cpu_earlydevice_va_p() must not return true until *all* devmap tables have been enabled.
console mapping may be present in the last table.


# 1.44 07-Sep-2019 ryo

- remove incorrect KASSERT. mmap(2) with prot=PROT_WRITE calls pmap_enter(..., PROT_WRITE) internally.
- fix to update page reference flags when only PROT_WRITE or PROT_EXECUTE specified


# 1.43 15-Aug-2019 skrll

Make pmap_db_pte_print more terse so it's quicker on serial consoles


# 1.42 12-Aug-2019 skrll

Use PMAP_DEV in DEVMAP_ENTRY rather than pmap_map_chunk. It's clearer and
means pmap_map_chunk can be made to map other memory types.


Revision tags: netbsd-9-base phil-wifi-20190609
# 1.41 17-May-2019 mrg

branches: 1.41.2;
apply some __diagused.


Revision tags: isaki-audio2-base
# 1.40 08-Apr-2019 ryo

- free empty page tables pages if reach a certain usage.
- need to lock at removing an old pg (_pmap_remove_pv) in _pmap_enter()


# 1.39 06-Apr-2019 ryo

Fix race conditions about pmap_page_protect() and pmap_enter().

while handling same PTE by these functions in same time, there
is a critical path that the number of valid PTEs and wire_count
are inconsistent, and it caused KASSERT.
Need to hold a pv_lock while modifying them.


# 1.38 20-Mar-2019 ryo

spinkle __printflike(), and use PRIxxx


# 1.37 19-Mar-2019 ryo

- add ddb command "machine ttbr" to dump MMU tables.
- tidy up descriptions, usages and messages.


# 1.36 19-Mar-2019 ryo

- free L1-L3 pages that has been emptied by pmap_remove().
- if no memories, pmap_enter will return correctly ENOMEM if PMAP_CANFAIL, or wait until available any memories if !PMAP_CANFAIL.

These changes improves the stability when we use a huge virtual memory spaces with mmap.


# 1.35 06-Feb-2019 ryo

improve pmap_remove
- don't lock/unlock per page in pmap_remove()
- speedup pte lookup for continuous addresses
- bring out pool_cache_put(&_pmap_pv_pool, pv) from lock/unlock section


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226
# 1.34 21-Dec-2018 ryo

- add workaround for Cavium ThunderX errata 27456.
- add cpufuncs table in cpu_info. each cpu clusters may have different erratum. (e.g. big.LITTLE)


Revision tags: pgoyette-compat-1126
# 1.33 01-Nov-2018 maxv

Add kASan support for aarch64. Stack tracking needs more investigation
and will come in a separate commit.

Reviewed by ryo@ jmcneill@ skrll@.


# 1.32 31-Oct-2018 ryo

invalidate icache correctly.
l3pte_executable() should be used for only valid pte.


Revision tags: pgoyette-compat-1020
# 1.31 18-Oct-2018 skrll

Provide generic start code that assumes the MMU is off and caches are
disabled as per the linux booting protocol for ARMv6 and ARMv7 boards.
u-boot image type should be changed to 'linux' for correct behaviour.

The new start code builds a minimal "bootstrap" L1PT with cached access
disabled and uses the same table for all processors. AP startup is
performed in less steps and more code is written in C.

The bootstrap tables and stack are placed into an (orphaned) section
"_init_memory" which is given to uvm when it is no longer used.

Various kernels have been converted to use this code and tested. Some
boards were provided by TNF. Thanks!

The GENERIC kernel now boots on boards using the TEGRA, SUNXI and EXYNOS
kernels. The GENERIC kernel will also work on RPI2 using u-boot.

Thanks to martin@ and aymeric@ for testing on parallella and nanosoc
respectively


# 1.30 14-Oct-2018 skrll

Use __nothing


# 1.29 12-Oct-2018 ryo

add initial support of COMPAT_NETBSD32 on AArch64.
arm ELF32 EABI binaries could be execute in AArch32 state on AArch64. A32 THUMB mode is not supported yet.


# 1.28 12-Oct-2018 ryo

- cleanup checking address ranges with IN_RANGE macro
- change PM_ADDR_CHECK macro to KASSERTMSG
- restore fast lookup cases with IN_RANGE macro for pmap_extract changed in my previous commit.


# 1.27 12-Oct-2018 ryo

rewrite pmap_pte_lookup() to share similar code.


# 1.26 04-Oct-2018 ryo

cleanup locore, and changed the way to map memories during boot.
- add functions bootpage_enter() and bootpage_alloc() to adapt various layout
of physical memory map. especially for 64bit physical memory layout.
pmapboot_alloc() allocates pagetable pages from _end[].
- changed to map only the required amount for PA=VA identity mapping
(kernel image, UART device, and FDT blob) with L2_BLOCK(2Mbyte).
- changing page permission for kernel image, and making KSEG mapping are done
at cpu_kernel_vm_init() instead of at locore.
- optimize PTE entries with PTE Contiguous bit. it is enabled on devmap only for now.

reviewed by skrll@, thanks.


# 1.25 04-Oct-2018 ryo

* define LX_BLKPAG_{OS,ATTR}_* for OS dependent PTE attributes in pmap.h
* cleanup macros


Revision tags: pgoyette-compat-0930
# 1.24 17-Sep-2018 ryo

delete debug printf and KASSERT.


# 1.23 10-Sep-2018 maxv

Replace KDASSERT by panic.


# 1.22 10-Sep-2018 maxv

Rename _pmap_alloc_pdp -> pmap_alloc_pdp, and make it public.


# 1.21 10-Sep-2018 ryo

cleanup aarch64 mpstart and fdt bootstrap
* arm_cpu_hatch_arg is a bad idea. avoid serializing CPU startup, and eliminate arm_cpu_hatch_arg.
in mpstart, resolve own cpu index using array of cpu_mpidr[] (aarch64)
* add support fdt enable-method "spin-table"
* add support fdt enable-method "brcm,bcm2836-smp" (for 32bit RaspberryPi)
* use arm_fdt_cpu_bootstrap() instead of psci_fdt_bootstrap()
* rename "arm/fdt/psci_fdt.h" to "arm/fdt/psci_fdtvar.h" because of conflict of include file for needs-flag
* add devmap for cpu spin-table of raspberrypi3/aarch64
* no need to force hatch APs for raspberrypi3/arm32 ifndef MULTIPROCESSOR.
* fix to work pmap_extract(kerneltext/data/bss) even if before calling pmap_bootstrap

idea to use cpu_mpidr[] by jmcneill@. reviewd by skrll@. thanks.


Revision tags: pgoyette-compat-0906
# 1.20 27-Aug-2018 ryo

need to add VM_PROT_READ when pmap_kenter_pa(va, pa, VM_PROT_WRITE, 0) or pmap_kenter_pa(va, pa, VM_PROT_EXECUTE, 0).
VM_PROT_READ is treated as an access permission inernally.


# 1.19 11-Aug-2018 ryo

change to minimum invalidation of TLB.
specifying not only va but also asid, and not invalidate L0-L2 entry using tlbi_*_ll() if needed.


# 1.18 10-Aug-2018 ryo

treat kernel-exec attr and user-exec attr separately.
kernel cannot execute userland exec page, and user cannot execute kernel page.


# 1.17 06-Aug-2018 ryo

set kernel text/rodata readonly by default.
add function db_write_text() for setting ddb breakpoint.


# 1.16 31-Jul-2018 skrll

Define and use VPRINTF


Revision tags: pgoyette-compat-0728
# 1.15 27-Jul-2018 ryo

changes of pmap.c r1.13 seems to be unstable.
In order to invalidate icache, not to invalidate all icache,
but temporary to make the page writable and invalidate target address only.


# 1.14 24-Jul-2018 ryo

don't call pool_cache_put with locking pmap. pool_cache_put call pmap_kenter_pa internally.
(pool_cache_put_paddr -> pool_cache_put_slow -> pool_get -> pmap_kenter_pa)


# 1.13 23-Jul-2018 ryo

* fix icache invalidations.
* "ic ivau" (aarch64_icache_sync_range) with VA generates permission fault in some situations, therefore use KSEG address for now.


# 1.12 23-Jul-2018 ryo

rather than using flags to resolve nested locks, reserve pool_cache before locking.


# 1.11 21-Jul-2018 ryo

* avoid deadlock. mutex_owned() works only for adaptive lock, therefore we cannot use it for spinlock...
* add more NULL check
* clear pte when pmap_enter() fails


# 1.10 17-Jul-2018 ryo

Use __debugused


# 1.9 17-Jul-2018 christos

Add missing casts, remove unused variables.


# 1.8 09-Jul-2018 ryo

need locks in pmap_kremove() and pmap_fault_fixup()


Revision tags: phil-wifi-base pgoyette-compat-0625 pgoyette-compat-0521
# 1.7 20-May-2018 ryo

branches: 1.7.2;
pmap_enter() must update modified/referenced flags by 'flags' not 'prot'.


# 1.6 16-May-2018 ryo

Fix memory leak. it was leaking one page every pmap_create().
pm->pm_vmlist must be initialized before calling _pmap_alloc_pdp().


Revision tags: pgoyette-compat-0502
# 1.5 29-Apr-2018 ryo

fix KASSERT panic. pv_entry may not be exists in pvlist when pmap_remove().


# 1.4 29-Apr-2018 ryo

delete unused code


# 1.3 27-Apr-2018 ryo

fix instability behavior of bufcache on aarch64.
* fix to return correct ref/mod when PMAP_WIRED.
* changed to keep wired flags in pte instead of pv_entry, and cleanup.


Revision tags: pgoyette-compat-0422 pgoyette-compat-0415 pgoyette-compat-0407
# 1.2 01-Apr-2018 ryo

Add initial support for ARMv8 (AARCH64) (by nisimura@ and ryo@)

- sys/arch/evbarm64 is gone and integrated into sys/arch/evbarm. (by skrll@)
- add support fdt. evbarm/conf/GENERIC64 fdt (bcm2837,sunxi,tegra) based generic 64bit kernel config. (by skrll@, jmcneill@)


Revision tags: netbsd-8-2-RELEASE netbsd-8-1-RELEASE netbsd-8-1-RC1 netbsd-7-2-RELEASE netbsd-8-0-RELEASE netbsd-8-0-RC2 netbsd-8-0-RC1 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 netbsd-7-1-2-RELEASE pgoyette-compat-base netbsd-7-1-1-RELEASE tls-maxphys-base-20171202 matt-nb8-mediatek-base nick-nhusb-base-20170825 perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base pgoyette-localcount-20170320 netbsd-7-1-RELEASE netbsd-7-1-RC2 nick-nhusb-base-20170204 netbsd-7-nhusb-base-20170116 bouyer-socketcan-base pgoyette-localcount-20170107 netbsd-7-1-RC1 nick-nhusb-base-20161204 pgoyette-localcount-20161104 netbsd-7-0-2-RELEASE nick-nhusb-base-20161004 localcount-20160914 netbsd-7-nhusb-base pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907 nick-nhusb-base-20160529 netbsd-7-0-1-RELEASE nick-nhusb-base-20160422 nick-nhusb-base-20160319 nick-nhusb-base-20151226 netbsd-7-0-RELEASE nick-nhusb-base-20150921 netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 nick-nhusb-base-20150606 nick-nhusb-base-20150406 nick-nhusb-base tls-maxphys-base netbsd-7-base
# 1.1 10-Aug-2014 matt

branches: 1.1.4; 1.1.28;
Preliminary files for AARCH64 (64-bit ARM) support.
Enough for a distribution build.


# 1.135 17-Apr-2022 skrll

Add the missing kpreempt_enable to pmap_deactivate_efirt


# 1.134 10-Apr-2022 skrll

No need to flush icache for EFI RT mappings as bootaa64.efi flushed
the full icache for us. (Also this avoids traps)


# 1.133 09-Apr-2022 riastradh

sys: Use membar_release/acquire around reference drop.

This just goes through my recent reference count membar audit and
changes membar_exit to membar_release and membar_enter to
membar_acquire -- this should make everything cheaper on most CPUs
without hurting correctness, because membar_acquire is generally
cheaper than membar_enter.


# 1.132 02-Apr-2022 skrll

Update to support EFI runtime outside the kernel virtual address space
by creating an EFI RT pmap that can be activated / deactivated when
required.

Adds support for EFI RT to ARM_MMU_EXTENDED (ASID) 32-bit Arm machines.

On Arm64 the usage of pmapboot_enter is reduced and the mappings are
created much later in the boot process -- now in cpu_startup_hook.
Backward compatiblity for KVA mapped RT from old bootaa64.efi is
maintained.

Adding support to other platforms should be easier as a result.


# 1.131 19-Mar-2022 skrll

Slight code re-organisation. NFCI.


# 1.130 12-Mar-2022 riastradh

sys: Membar audit around reference count releases.

If two threads are using an object that is freed when the reference
count goes to zero, we need to ensure that all memory operations
related to the object happen before freeing the object.

Using an atomic_dec_uint_nv(&refcnt) == 0 ensures that only one
thread takes responsibility for freeing, but it's not enough to
ensure that the other thread's memory operations happen before the
freeing.

Consider:

Thread A Thread B
obj->foo = 42; obj->baz = 73;
mumble(&obj->bar); grumble(&obj->quux);
/* membar_exit(); */ /* membar_exit(); */
atomic_dec -- not last atomic_dec -- last
/* membar_enter(); */
KASSERT(invariant(obj->foo,
obj->bar));
free_stuff(obj);

The memory barriers ensure that

obj->foo = 42;
mumble(&obj->bar);

in thread A happens before

KASSERT(invariant(obj->foo, obj->bar));
free_stuff(obj);

in thread B. Without them, this ordering is not guaranteed.

So in general it is necessary to do

membar_exit();
if (atomic_dec_uint_nv(&obj->refcnt) != 0)
return;
membar_enter();

to release a reference, for the `last one out hit the lights' style
of reference counting. (This is in contrast to the style where one
thread blocks new references and then waits under a lock for existing
ones to drain with a condvar -- no membar needed thanks to mutex(9).)

I searched for atomic_dec to find all these. Obviously we ought to
have a better abstraction for this because there's so much copypasta.
This is a stop-gap measure to fix actual bugs until we have that. It
would be nice if an abstraction could gracefully handle the different
styles of reference counting in use -- some years ago I drafted an
API for this, but making it cover everything got a little out of hand
(particularly with struct vnode::v_usecount) and I ended up setting
it aside to work on psref/localcount instead for better scalability.

I got bored of adding #ifdef __HAVE_ATOMIC_AS_MEMBAR everywhere, so I
only put it on things that look performance-critical on 5sec review.
We should really adopt membar_enter_preatomic/membar_exit_postatomic
or something (except they are applicable only to atomic r/m/w, not to
atomic_load/store_*, making the naming annoying) and get rid of all
the ifdefs.


# 1.129 05-Mar-2022 skrll

Slight comment improvement.


# 1.128 16-Feb-2022 andvar

fix various typos, mainly in comments.


# 1.127 31-Jan-2022 ryo

add support Hardware updates to Access flag and Dirty state (FEAT_HAFDBS)

- The DBM bit of the PTE is now used to determine if it is writable, and
the AF bit is treated entirely as a reference bit. A valid PTE is always
treated as readable. There can be no valid PTE that is not readable.
- LX_BLKPAG_OS_{READ,WRITE} are used only for debugging purposes,
and has been superseded by LX_BLKPAG_AF and LX_BLKPAG_DBM.
- Improve comment

The need for reference/modify emulation has been eliminated,
and access/permission faults have been reduced, however,
there has been little change in overall performance.


# 1.126 31-Jan-2022 ryo

Skip unnecessary PTE operations and TLB invalidation.


# 1.125 16-Jan-2022 rillig

aarch64/pmap: remove stray semicolon

No binary change.


# 1.124 15-Jan-2022 skrll

The translations that need invalidation are always last level so remove
the (dubious) logic around tracking the level. The "any level" TLB
invalidation maintenance operation are used, but this may change after
further testing.

before
======
1661.0u 420.2s 2:53.82 1197.3% 231+29k 10+33918io 102pf+0w
1646.8u 425.2s 2:52.96 1198.0% 232+29k 1+33937io 49pf+0w
1647.9u 425.7s 2:52.58 1201.6% 232+29k 0+33940io 32pf+0w

After
=====
1602.5u 420.8s 2:49.09 1196.6% 238+30k 24+33893io 54pf+0w
1600.7u 421.3s 2:51.53 1178.8% 238+30k 1+33914io 33pf+0w
1597.5u 424.3s 2:50.46 1186.1% 238+30k 0+33915io 17pf+0w

LGTM from ryo@


# 1.123 14-Jan-2022 skrll

Restore the previous pmap_remove_all behaviour as the new method meant
the n1sdp couldn't complete a build.

No noticeable change in kernel build performance.


# 1.122 04-Jan-2022 skrll

KNF


# 1.121 10-Dec-2021 andvar

s/occured/occurred/ in comments, log messages and man pages.


# 1.120 07-Dec-2021 andvar

fix various typos, mainly in comments.


# 1.119 23-Oct-2021 skrll

Fix non-UVMHIST build


# 1.118 16-Oct-2021 ryo

fix non-MULTIPROCESSOR build


# 1.117 10-Oct-2021 skrll

Use sys/uvm/pmap/pmap_tlb.c on Aarch64 in the same way that some Arm, MIPS,
and some PPC kernels do. This removes the limitation of 256 processes on
CPUs with 8bit ASID field, e.g. Apple M1.

Additionally the following changes have been made

- removed a couple of unnecessary aarch64_tlbi_all calls
- removed any invalidation after freeing page tables due to
_pmap_sweep_pdp. This was never necessary afaict.
- all kernel mappings are marked global and userland mapping not-global.

Performance testing hasn't show a significant difference. The data here
is from building a kernel on an lx2k system with nvme.

before
1489.6u 400.4s 2:40.65 1176.5% 228+224k 0+32289io 57pf+0w
1482.6u 403.2s 2:38.49 1189.9% 228+222k 0+32274io 46pf+0w
1485.4u 402.2s 2:37.27 1200.2% 228+222k 0+32275io 12pf+0w

after
1493.9u 404.6s 2:37.50 1205.4% 227+221k 0+32265io 48pf+0w
1485.0u 408.0s 2:38.54 1194.0% 227+222k 0+32272io 36pf+0w
1484.3u 407.0s 2:35.88 1213.3% 228+224k 0+32268io 14pf+0w

>>> stats.ttest_ind([160.65,158.49,157.27], [157.5,158.54,155.88])
Ttest_indResult(statistic=1.1923622711296888, pvalue=0.2990182944606766)
>>>


# 1.116 30-Sep-2021 skrll

Ensure TCR_EPD0 is set on entry to pmap_activate and ensure it is set as
early as possible for APs.


# 1.115 26-Sep-2021 skrll

Use UVMHIST_CALLARGS


# 1.114 26-Sep-2021 skrll

'\n' is not required in KASSERTMSG either.


# 1.113 26-Sep-2021 skrll

"\n" is not required in KERNHIST


# 1.112 15-Sep-2021 skrll

Use __SHIFTIN. Same code before and after.


# 1.111 12-Sep-2021 skrll

pmap_page_remove: simply and reduce the code size slightly.


# 1.110 09-Sep-2021 skrll

In pmap_icache_sync_range change

for (...) {
...
if (condition) {
// do stuff
}
}

to

for (...) {
...
if (!conditional)
continue;
// do stuff
}

to save on indentation. Same code (modulo register usage) before and
after.


# 1.109 09-Sep-2021 skrll

KNF


Revision tags: thorpej-i2c-spi-conf2-base thorpej-futex2-base thorpej-cfargs2-base cjep_sun2x-base1 cjep_sun2x-base cjep_staticlib_x-base1 thorpej-i2c-spi-conf-base
# 1.108 29-May-2021 skrll

Deal with the pmap limitation of maxproc in a more complete way and
recognise CPUs with only 8bit ASIDs.


Revision tags: cjep_staticlib_x-base
# 1.107 30-Apr-2021 skrll

branches: 1.107.2;
Make the ddb for pmap / pte information pmap agnostic


# 1.106 29-Apr-2021 skrll

Remove some unnecessary tlb invalidate in pmap_growkernel and ASAN shadow
map. Ensure the shadow map mappings are visible to the TLB walkers.


# 1.105 21-Apr-2021 ryo

branches: 1.105.2;
added more attributes of PTE displayed by "ddb>machine pte"


Revision tags: thorpej-cfargs-base
# 1.104 17-Apr-2021 mrg

remove KERNHIST_INIT_STATIC(). it stradles the line between usable
early in boot and broken early in boot by requiring a partly static
structure with another structure that must be present by the time
any uses are performed. theoretically platform code could allocate
a chunk while seting up memory and assign it here, giving a dynamic
sizing for the entry list, but the reality is that all users have
a statically allocated entry list as well.

the existing KERNHIST_LINK_STATIC() is used in conjunction with
KERNHIST_INITIALIZER() instead.

this stops a NULL pointer deref when the _LOG() macro is called
before the storage is linked in, which happens with GCC 10 on OCTEON
with UVMHIST enabled, crashing in very early kernel init.


Revision tags: thorpej-futex-base
# 1.103 09-Mar-2021 ryo

branches: 1.103.2;
fix build error without options DDB.

kvtopte() is referenced from arm/acpi/acpi_machdep.c


# 1.102 13-Feb-2021 ryo

No assignment is needed here.

the loop in pmap_page_remove() always removes the first pv,
and since the list is managed by _pmap_remove_pv(), pp->pp_pv.pv_next always points to the first.


# 1.101 01-Feb-2021 ryo

It is enough to make a page accessible instead of writable.
same fix as r1.76


# 1.100 31-Jan-2021 ryo

implement pmap_remove_all().

The size of struct pv_entry has increased, but speed of kernel build has improved by about 1%
exec and exit should have been improved.


# 1.99 20-Dec-2020 skrll

Improve the English in the previous comment fix.


# 1.98 19-Dec-2020 skrll

Tweak a comment


# 1.97 11-Dec-2020 skrll

s:aarch64/cpufunc.h:arm/cpufunc.h:

a baby step in the grand arm header unification challenge


# 1.96 10-Nov-2020 skrll

AA64 is not MIPS.

Change all KSEG references to directmap


# 1.95 07-Nov-2020 skrll

In pmap_devmap_bootstrap only set pmap_devmap_bootstrap_done if there
is an entry and ALL of the entries have been done. The entry required
for EARLYCONS might not be the first/only one...


# 1.94 01-Nov-2020 jmcneill

branches: 1.94.2;
No need to disable translation table walks in pmap_activate().


# 1.93 22-Oct-2020 skrll

Use the isb macro - missed in previous commit


# 1.92 22-Oct-2020 skrll

Use the dmb/dsb/isb macros... if nothing else they're all now consistent
about the "memory" assembler contraint.

No binary change


# 1.91 28-Sep-2020 skrll

Only set pmap_devmap_bootstrap_done if something gets mapped.

Think acpi_platform_devmap


# 1.90 19-Sep-2020 skrll

Make __md_palloc pmap agnostic (think sys/uvm/pmap)


# 1.89 14-Sep-2020 ryo

PID_MAX is just an initial value (soft maximum). Don't use it for CTASSERT.
defined __HAVE_CPU_MAXPROC to use function cpu_maxproc().

pointed out by mrg@, thanks.


# 1.88 06-Sep-2020 ryo

Fix panic caused by modload. http://mail-index.netbsd.org/port-arm/2020/08/30/msg006960.html

The address space reserved for modules may not be mapped in L1-L3.


# 1.87 14-Aug-2020 skrll

Whitespace


# 1.86 12-Aug-2020 skrll

Part IV of ad's performance improvements for aarch64

- Implement pmap_growkernel(), and update kernel pmap's stats with atomics.

- Then, pmap_kenter_pa() and pmap_kremove() no longer need to allocate
memory nor take pm_lock, because they only modify L3 PTEs.

- Then, pm_lock and pp_lock can be adaptive mutexes at IPL_NONE which are
cheaper than spin mutexes.

- Take the pmap's lock in pmap_extract() if not the kernel's pmap, otherwise
pmap_extract() might see inconsistent state.


# 1.85 09-Aug-2020 skrll

Fix another UVMHIST so it doesn't use %s


# 1.84 16-Jul-2020 skrll

pmapboot_enter simplication
- bootpage_alloc in asm becomes pmapboot_pagealloc in C
- PMAPBOOT_ENTER_NOBLOCK is removed as it's not used
- PMAPBOOT_ENTER_NOOVERWRITE is removed as it's now always on
- physpage_allocator argument is removed as it's always
pmapboot_pagealloc
- Support for EARLYCONS without CONSADDR is removed so that the identity
map for CONSADDR is always known.

For the assembly files:
2 files changed, 40 insertions(+), 89 deletions(-)

LGTM ryo


# 1.83 04-Jul-2020 rin

Use tlen for temporary length variable instead of l, which is usually
used for struct lwp *.

No binary changes.


# 1.82 02-Jul-2020 rin

pmap_procwr(): sync icache even if p != curproc. This fixes applications
like GDB for arm32, that rewrite text of other process.

Thanks to ryo@ for discussion.


# 1.81 02-Jul-2020 rin

Set uvmexp.ncolors appropriately, which is required for some CPU
models with VIPT icache.

Otherwise, alias in virtual address results in inconsistent results,
at least for applications that rewrite text of other process, e.g.,
GDB for arm32.

Also, this hopefully fixes other unexpected failures due to alias.

Confirmed that there's no observable regression in performance;
difference in ``time make -j8'' for GENERIC64 kernel on BCM2837
with and without setting uvmexp.ncolors is within 0.1%.

Thanks to ryo@ for discussion.


# 1.80 27-Jun-2020 rin

Fix typo in name of evcnt(4) counter.


# 1.79 24-Jun-2020 ryo

Fix bug with incorrect range calculation when doing icache sync.
This is called by sysarch(ARM_SYNC_ICACHE) from aarch32 (compat_netbsd32) emul process.

pointed out by rin@, thanks.

XXX pullup-9


# 1.78 14-Jun-2020 ad

- Fix a lock order reversal in pmap_page_protect().

- Make sure pmap is always locked when updating stats; atomics no longer
needed to do that.

- Remove unneeded traversal of pv list in pmap_enter_pv().

- Shrink struct vm_page from 136 to 128 bytes (cache line sized) and struct
pv_entry from 48 to 32 bytes (power of 2 sized).

- Embed a pv_entry in each vm_page. This means PV entries don't need to
be allocated for private anonymous memory / COW pages / most UBC mappings.
Dynamic PV entries are then used only for stuff like shared libraries and
shared memory.

Proposed on port-arm@.


# 1.77 10-Jun-2020 ad

- Wired/resident stats shouldn't covered by PMAPCOUNTERS.
- Rename need_update_pv -> need_enter_pv.

Ok ryo@


# 1.76 01-Jun-2020 ryo

no need to make the PTE writable to do icache_sync, enough to accessible.


# 1.75 15-May-2020 skrll

Use __diagused


# 1.74 15-May-2020 tnn

fix non-diag build


# 1.73 14-May-2020 skrll

Use MUTEX_NODEBUG for PV locks as is commonly done. OK ryo.


# 1.72 13-May-2020 jmcneill

Implement pmap_extract_coherency


Revision tags: bouyer-xenpvh-base2 phil-wifi-20200421 bouyer-xenpvh-base1
# 1.71 18-Apr-2020 skrll

PMAP_DEBUG has been deleted on arm


# 1.70 13-Apr-2020 maxv

Add support for Branch Target Identification (BTI).

On the executable pages that have the GP (Guarded Page) bit, the semantic
of the "br" and "blr" instructions is changed: the CPU expects the first
instruction of the jump/call target to be "bti", and faults if it isn't.

We add the GP bit on the kernel .text pages (and incidentally the .rodata
pages, but we don't care). The compiler adds a "bti c" instruction at the
beginning of each C function. We modify the ENTRY() macros to manually add
"bti c" in the asm functions.

cpuswitch.S needs a specific change: with "br x27" the CPU expects "bti j",
which is bad because the functions begin with "bti c"; switch to "br x16",
for the CPU to accept "bti c".

BTI helps defend against JOP/COP. Tested on Qemu.


Revision tags: phil-wifi-20200411 bouyer-xenpvh-base
# 1.69 08-Apr-2020 ryo

branches: 1.69.2;
use PMAP_PAGE_INIT() to initialize mutex in pmap_page.

VM_MDPAGE_INIT() in pmap_free_pdp() had initialized pp_flags,
so it unintentionally cleared PMAP_PAGE_FLAGS_PV_TRACKED.
use PMAP_PAGE_INIT to avoid using PMAP_PAGE_FLAGS_PV_TRACKED.

pointed out by tnn@, thanks


Revision tags: phil-wifi-20200406
# 1.68 14-Mar-2020 ad

pmap_remove_all(): Return a boolean value to indicate the behaviour. If
true, all mappings have been removed, the pmap is totally cleared out, and
UVM can then avoid doing the work to call pmap_remove() for each map entry.
If false, either nothing has been done, or some helpful arch-specific voodoo
has taken place.


Revision tags: is-mlppp-base
# 1.67 02-Mar-2020 ryo

oops, fix incorrect usage of daif_enable() in my previous commit.


# 1.66 29-Feb-2020 ryo

Fix pmap to work correctly with tagged addresses

- when fault, untag from address before passing to uvm/pmap functions
- pmap_extract() checks more strictly and consider the address tag


# 1.65 29-Feb-2020 ryo

use pmapboot_enter_range()


Revision tags: ad-namecache-base3
# 1.64 10-Feb-2020 ryo

use LIST(3) instead of TAILQ(3) to save one word in struct vm_page and struct pmap.

pointed out by riastradh@. thanks


# 1.63 03-Feb-2020 ryo

add support pmap_pv(9)

Patch originally from jmcneill@. thanks


# 1.62 03-Feb-2020 ryo

separate struct vm_page_md into vm_page_md and pmap_page
for preparation pmap_pv(9)


Revision tags: ad-namecache-base2 ad-namecache-base1
# 1.61 09-Jan-2020 ryo

fix behaviour mmap()/mprotect() when passed only PROT_EXEC.

when mmap()/mprotect() with only PROT_EXEC, syscall will be successful,
but the page actually hadn't been mapped.
it should be mapped with PROT_READ|PROT_EXEC implicitly. (r-x)


Revision tags: ad-namecache-base
# 1.60 30-Dec-2019 skrll

branches: 1.60.2;
Update pmap_map_chunk to allow L[12] block mappings and L3 page mappings


# 1.59 30-Dec-2019 skrll

Remove unnecessary brackets and unwrap a conditional. Same code before
and after.


# 1.58 28-Dec-2019 jmcneill

Do not use Early Write Acknowledge for PCIe I/O and config space.


# 1.57 27-Dec-2019 jmcneill

Enable early write acknowledge for device memory mappings.


# 1.56 19-Dec-2019 skrll

G/C kasan_shadow_map call in pmap_enter

pmap_growkernel calls kasan_shadow_map for KVA


# 1.55 18-Dec-2019 ryo

atomic_add_16() is not used in pmap.c anymore. no need decl here.


# 1.54 18-Dec-2019 ryo

space to tab


# 1.53 14-Dec-2019 skrll

Fix build... wire_count probably doesn't need atomics


# 1.52 13-Dec-2019 skrll

Fix KASAN support by calling kasan_shadow_map in pmap_growkernel


# 1.51 10-Dec-2019 ad

pg->phys_addr -> VM_PAGE_TO_PHYS(pg)


Revision tags: phil-wifi-20191119
# 1.50 14-Nov-2019 maxv

Mark several kASan functions with __nothing, to avoid annoying #ifdefs.
Same as kCSan and kMSan.


# 1.49 14-Nov-2019 maxv

Don't include "opt_kasan.h" when there's already <sys/asan.h> included.


# 1.48 29-Oct-2019 maya

Define PMAP_NEED_PROCWR, providing strategically placed i-cache
synchronization where just-changed memory is about to be executed.

Fixes SIGILLs seen when running Mono 6 on QEMU Cortex-A57.

ok ryo


# 1.47 22-Sep-2019 jmcneill

Disable translation table walks using TTBR0 while changing its value and
when deactivating a pmap. Fixes stability issues on Ampere eMAG CPUs.


# 1.46 20-Sep-2019 ryo

ref/mod bit should be set according to 'flags' argument, not 'prot'. r1.44 was incomplete.


# 1.45 13-Sep-2019 ryo

In pmap_devmap_bootstrap(), cpu_earlydevice_va_p() must not return true until *all* devmap tables have been enabled.
console mapping may be present in the last table.


# 1.44 07-Sep-2019 ryo

- remove incorrect KASSERT. mmap(2) with prot=PROT_WRITE calls pmap_enter(..., PROT_WRITE) internally.
- fix to update page reference flags when only PROT_WRITE or PROT_EXECUTE specified


# 1.43 15-Aug-2019 skrll

Make pmap_db_pte_print more terse so it's quicker on serial consoles


# 1.42 12-Aug-2019 skrll

Use PMAP_DEV in DEVMAP_ENTRY rather than pmap_map_chunk. It's clearer and
means pmap_map_chunk can be made to map other memory types.


Revision tags: netbsd-9-base phil-wifi-20190609
# 1.41 17-May-2019 mrg

branches: 1.41.2;
apply some __diagused.


Revision tags: isaki-audio2-base
# 1.40 08-Apr-2019 ryo

- free empty page tables pages if reach a certain usage.
- need to lock at removing an old pg (_pmap_remove_pv) in _pmap_enter()


# 1.39 06-Apr-2019 ryo

Fix race conditions about pmap_page_protect() and pmap_enter().

while handling same PTE by these functions in same time, there
is a critical path that the number of valid PTEs and wire_count
are inconsistent, and it caused KASSERT.
Need to hold a pv_lock while modifying them.


# 1.38 20-Mar-2019 ryo

spinkle __printflike(), and use PRIxxx


# 1.37 19-Mar-2019 ryo

- add ddb command "machine ttbr" to dump MMU tables.
- tidy up descriptions, usages and messages.


# 1.36 19-Mar-2019 ryo

- free L1-L3 pages that has been emptied by pmap_remove().
- if no memories, pmap_enter will return correctly ENOMEM if PMAP_CANFAIL, or wait until available any memories if !PMAP_CANFAIL.

These changes improves the stability when we use a huge virtual memory spaces with mmap.


# 1.35 06-Feb-2019 ryo

improve pmap_remove
- don't lock/unlock per page in pmap_remove()
- speedup pte lookup for continuous addresses
- bring out pool_cache_put(&_pmap_pv_pool, pv) from lock/unlock section


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226
# 1.34 21-Dec-2018 ryo

- add workaround for Cavium ThunderX errata 27456.
- add cpufuncs table in cpu_info. each cpu clusters may have different erratum. (e.g. big.LITTLE)


Revision tags: pgoyette-compat-1126
# 1.33 01-Nov-2018 maxv

Add kASan support for aarch64. Stack tracking needs more investigation
and will come in a separate commit.

Reviewed by ryo@ jmcneill@ skrll@.


# 1.32 31-Oct-2018 ryo

invalidate icache correctly.
l3pte_executable() should be used for only valid pte.


Revision tags: pgoyette-compat-1020
# 1.31 18-Oct-2018 skrll

Provide generic start code that assumes the MMU is off and caches are
disabled as per the linux booting protocol for ARMv6 and ARMv7 boards.
u-boot image type should be changed to 'linux' for correct behaviour.

The new start code builds a minimal "bootstrap" L1PT with cached access
disabled and uses the same table for all processors. AP startup is
performed in less steps and more code is written in C.

The bootstrap tables and stack are placed into an (orphaned) section
"_init_memory" which is given to uvm when it is no longer used.

Various kernels have been converted to use this code and tested. Some
boards were provided by TNF. Thanks!

The GENERIC kernel now boots on boards using the TEGRA, SUNXI and EXYNOS
kernels. The GENERIC kernel will also work on RPI2 using u-boot.

Thanks to martin@ and aymeric@ for testing on parallella and nanosoc
respectively


# 1.30 14-Oct-2018 skrll

Use __nothing


# 1.29 12-Oct-2018 ryo

add initial support of COMPAT_NETBSD32 on AArch64.
arm ELF32 EABI binaries could be execute in AArch32 state on AArch64. A32 THUMB mode is not supported yet.


# 1.28 12-Oct-2018 ryo

- cleanup checking address ranges with IN_RANGE macro
- change PM_ADDR_CHECK macro to KASSERTMSG
- restore fast lookup cases with IN_RANGE macro for pmap_extract changed in my previous commit.


# 1.27 12-Oct-2018 ryo

rewrite pmap_pte_lookup() to share similar code.


# 1.26 04-Oct-2018 ryo

cleanup locore, and changed the way to map memories during boot.
- add functions bootpage_enter() and bootpage_alloc() to adapt various layout
of physical memory map. especially for 64bit physical memory layout.
pmapboot_alloc() allocates pagetable pages from _end[].
- changed to map only the required amount for PA=VA identity mapping
(kernel image, UART device, and FDT blob) with L2_BLOCK(2Mbyte).
- changing page permission for kernel image, and making KSEG mapping are done
at cpu_kernel_vm_init() instead of at locore.
- optimize PTE entries with PTE Contiguous bit. it is enabled on devmap only for now.

reviewed by skrll@, thanks.


# 1.25 04-Oct-2018 ryo

* define LX_BLKPAG_{OS,ATTR}_* for OS dependent PTE attributes in pmap.h
* cleanup macros


Revision tags: pgoyette-compat-0930
# 1.24 17-Sep-2018 ryo

delete debug printf and KASSERT.


# 1.23 10-Sep-2018 maxv

Replace KDASSERT by panic.


# 1.22 10-Sep-2018 maxv

Rename _pmap_alloc_pdp -> pmap_alloc_pdp, and make it public.


# 1.21 10-Sep-2018 ryo

cleanup aarch64 mpstart and fdt bootstrap
* arm_cpu_hatch_arg is a bad idea. avoid serializing CPU startup, and eliminate arm_cpu_hatch_arg.
in mpstart, resolve own cpu index using array of cpu_mpidr[] (aarch64)
* add support fdt enable-method "spin-table"
* add support fdt enable-method "brcm,bcm2836-smp" (for 32bit RaspberryPi)
* use arm_fdt_cpu_bootstrap() instead of psci_fdt_bootstrap()
* rename "arm/fdt/psci_fdt.h" to "arm/fdt/psci_fdtvar.h" because of conflict of include file for needs-flag
* add devmap for cpu spin-table of raspberrypi3/aarch64
* no need to force hatch APs for raspberrypi3/arm32 ifndef MULTIPROCESSOR.
* fix to work pmap_extract(kerneltext/data/bss) even if before calling pmap_bootstrap

idea to use cpu_mpidr[] by jmcneill@. reviewd by skrll@. thanks.


Revision tags: pgoyette-compat-0906
# 1.20 27-Aug-2018 ryo

need to add VM_PROT_READ when pmap_kenter_pa(va, pa, VM_PROT_WRITE, 0) or pmap_kenter_pa(va, pa, VM_PROT_EXECUTE, 0).
VM_PROT_READ is treated as an access permission inernally.


# 1.19 11-Aug-2018 ryo

change to minimum invalidation of TLB.
specifying not only va but also asid, and not invalidate L0-L2 entry using tlbi_*_ll() if needed.


# 1.18 10-Aug-2018 ryo

treat kernel-exec attr and user-exec attr separately.
kernel cannot execute userland exec page, and user cannot execute kernel page.


# 1.17 06-Aug-2018 ryo

set kernel text/rodata readonly by default.
add function db_write_text() for setting ddb breakpoint.


# 1.16 31-Jul-2018 skrll

Define and use VPRINTF


Revision tags: pgoyette-compat-0728
# 1.15 27-Jul-2018 ryo

changes of pmap.c r1.13 seems to be unstable.
In order to invalidate icache, not to invalidate all icache,
but temporary to make the page writable and invalidate target address only.


# 1.14 24-Jul-2018 ryo

don't call pool_cache_put with locking pmap. pool_cache_put call pmap_kenter_pa internally.
(pool_cache_put_paddr -> pool_cache_put_slow -> pool_get -> pmap_kenter_pa)


# 1.13 23-Jul-2018 ryo

* fix icache invalidations.
* "ic ivau" (aarch64_icache_sync_range) with VA generates permission fault in some situations, therefore use KSEG address for now.


# 1.12 23-Jul-2018 ryo

rather than using flags to resolve nested locks, reserve pool_cache before locking.


# 1.11 21-Jul-2018 ryo

* avoid deadlock. mutex_owned() works only for adaptive lock, therefore we cannot use it for spinlock...
* add more NULL check
* clear pte when pmap_enter() fails


# 1.10 17-Jul-2018 ryo

Use __debugused


# 1.9 17-Jul-2018 christos

Add missing casts, remove unused variables.


# 1.8 09-Jul-2018 ryo

need locks in pmap_kremove() and pmap_fault_fixup()


Revision tags: phil-wifi-base pgoyette-compat-0625 pgoyette-compat-0521
# 1.7 20-May-2018 ryo

branches: 1.7.2;
pmap_enter() must update modified/referenced flags by 'flags' not 'prot'.


# 1.6 16-May-2018 ryo

Fix memory leak. it was leaking one page every pmap_create().
pm->pm_vmlist must be initialized before calling _pmap_alloc_pdp().


Revision tags: pgoyette-compat-0502
# 1.5 29-Apr-2018 ryo

fix KASSERT panic. pv_entry may not be exists in pvlist when pmap_remove().


# 1.4 29-Apr-2018 ryo

delete unused code


# 1.3 27-Apr-2018 ryo

fix instability behavior of bufcache on aarch64.
* fix to return correct ref/mod when PMAP_WIRED.
* changed to keep wired flags in pte instead of pv_entry, and cleanup.


Revision tags: pgoyette-compat-0422 pgoyette-compat-0415 pgoyette-compat-0407
# 1.2 01-Apr-2018 ryo

Add initial support for ARMv8 (AARCH64) (by nisimura@ and ryo@)

- sys/arch/evbarm64 is gone and integrated into sys/arch/evbarm. (by skrll@)
- add support fdt. evbarm/conf/GENERIC64 fdt (bcm2837,sunxi,tegra) based generic 64bit kernel config. (by skrll@, jmcneill@)


Revision tags: netbsd-8-2-RELEASE netbsd-8-1-RELEASE netbsd-8-1-RC1 netbsd-7-2-RELEASE netbsd-8-0-RELEASE netbsd-8-0-RC2 netbsd-8-0-RC1 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 netbsd-7-1-2-RELEASE pgoyette-compat-base netbsd-7-1-1-RELEASE tls-maxphys-base-20171202 matt-nb8-mediatek-base nick-nhusb-base-20170825 perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base pgoyette-localcount-20170320 netbsd-7-1-RELEASE netbsd-7-1-RC2 nick-nhusb-base-20170204 netbsd-7-nhusb-base-20170116 bouyer-socketcan-base pgoyette-localcount-20170107 netbsd-7-1-RC1 nick-nhusb-base-20161204 pgoyette-localcount-20161104 netbsd-7-0-2-RELEASE nick-nhusb-base-20161004 localcount-20160914 netbsd-7-nhusb-base pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907 nick-nhusb-base-20160529 netbsd-7-0-1-RELEASE nick-nhusb-base-20160422 nick-nhusb-base-20160319 nick-nhusb-base-20151226 netbsd-7-0-RELEASE nick-nhusb-base-20150921 netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 nick-nhusb-base-20150606 nick-nhusb-base-20150406 nick-nhusb-base tls-maxphys-base netbsd-7-base
# 1.1 10-Aug-2014 matt

branches: 1.1.4; 1.1.28;
Preliminary files for AARCH64 (64-bit ARM) support.
Enough for a distribution build.


# 1.134 10-Apr-2022 skrll

No need to flush icache for EFI RT mappings as bootaa64.efi flushed
the full icache for us. (Also this avoids traps)


# 1.133 09-Apr-2022 riastradh

sys: Use membar_release/acquire around reference drop.

This just goes through my recent reference count membar audit and
changes membar_exit to membar_release and membar_enter to
membar_acquire -- this should make everything cheaper on most CPUs
without hurting correctness, because membar_acquire is generally
cheaper than membar_enter.


# 1.132 02-Apr-2022 skrll

Update to support EFI runtime outside the kernel virtual address space
by creating an EFI RT pmap that can be activated / deactivated when
required.

Adds support for EFI RT to ARM_MMU_EXTENDED (ASID) 32-bit Arm machines.

On Arm64 the usage of pmapboot_enter is reduced and the mappings are
created much later in the boot process -- now in cpu_startup_hook.
Backward compatiblity for KVA mapped RT from old bootaa64.efi is
maintained.

Adding support to other platforms should be easier as a result.


# 1.131 19-Mar-2022 skrll

Slight code re-organisation. NFCI.


# 1.130 12-Mar-2022 riastradh

sys: Membar audit around reference count releases.

If two threads are using an object that is freed when the reference
count goes to zero, we need to ensure that all memory operations
related to the object happen before freeing the object.

Using an atomic_dec_uint_nv(&refcnt) == 0 ensures that only one
thread takes responsibility for freeing, but it's not enough to
ensure that the other thread's memory operations happen before the
freeing.

Consider:

Thread A Thread B
obj->foo = 42; obj->baz = 73;
mumble(&obj->bar); grumble(&obj->quux);
/* membar_exit(); */ /* membar_exit(); */
atomic_dec -- not last atomic_dec -- last
/* membar_enter(); */
KASSERT(invariant(obj->foo,
obj->bar));
free_stuff(obj);

The memory barriers ensure that

obj->foo = 42;
mumble(&obj->bar);

in thread A happens before

KASSERT(invariant(obj->foo, obj->bar));
free_stuff(obj);

in thread B. Without them, this ordering is not guaranteed.

So in general it is necessary to do

membar_exit();
if (atomic_dec_uint_nv(&obj->refcnt) != 0)
return;
membar_enter();

to release a reference, for the `last one out hit the lights' style
of reference counting. (This is in contrast to the style where one
thread blocks new references and then waits under a lock for existing
ones to drain with a condvar -- no membar needed thanks to mutex(9).)

I searched for atomic_dec to find all these. Obviously we ought to
have a better abstraction for this because there's so much copypasta.
This is a stop-gap measure to fix actual bugs until we have that. It
would be nice if an abstraction could gracefully handle the different
styles of reference counting in use -- some years ago I drafted an
API for this, but making it cover everything got a little out of hand
(particularly with struct vnode::v_usecount) and I ended up setting
it aside to work on psref/localcount instead for better scalability.

I got bored of adding #ifdef __HAVE_ATOMIC_AS_MEMBAR everywhere, so I
only put it on things that look performance-critical on 5sec review.
We should really adopt membar_enter_preatomic/membar_exit_postatomic
or something (except they are applicable only to atomic r/m/w, not to
atomic_load/store_*, making the naming annoying) and get rid of all
the ifdefs.


# 1.129 05-Mar-2022 skrll

Slight comment improvement.


# 1.128 16-Feb-2022 andvar

fix various typos, mainly in comments.


# 1.127 31-Jan-2022 ryo

add support Hardware updates to Access flag and Dirty state (FEAT_HAFDBS)

- The DBM bit of the PTE is now used to determine if it is writable, and
the AF bit is treated entirely as a reference bit. A valid PTE is always
treated as readable. There can be no valid PTE that is not readable.
- LX_BLKPAG_OS_{READ,WRITE} are used only for debugging purposes,
and has been superseded by LX_BLKPAG_AF and LX_BLKPAG_DBM.
- Improve comment

The need for reference/modify emulation has been eliminated,
and access/permission faults have been reduced, however,
there has been little change in overall performance.


# 1.126 31-Jan-2022 ryo

Skip unnecessary PTE operations and TLB invalidation.


# 1.125 16-Jan-2022 rillig

aarch64/pmap: remove stray semicolon

No binary change.


# 1.124 15-Jan-2022 skrll

The translations that need invalidation are always last level so remove
the (dubious) logic around tracking the level. The "any level" TLB
invalidation maintenance operation are used, but this may change after
further testing.

before
======
1661.0u 420.2s 2:53.82 1197.3% 231+29k 10+33918io 102pf+0w
1646.8u 425.2s 2:52.96 1198.0% 232+29k 1+33937io 49pf+0w
1647.9u 425.7s 2:52.58 1201.6% 232+29k 0+33940io 32pf+0w

After
=====
1602.5u 420.8s 2:49.09 1196.6% 238+30k 24+33893io 54pf+0w
1600.7u 421.3s 2:51.53 1178.8% 238+30k 1+33914io 33pf+0w
1597.5u 424.3s 2:50.46 1186.1% 238+30k 0+33915io 17pf+0w

LGTM from ryo@


# 1.123 14-Jan-2022 skrll

Restore the previous pmap_remove_all behaviour as the new method meant
the n1sdp couldn't complete a build.

No noticeable change in kernel build performance.


# 1.122 04-Jan-2022 skrll

KNF


# 1.121 10-Dec-2021 andvar

s/occured/occurred/ in comments, log messages and man pages.


# 1.120 07-Dec-2021 andvar

fix various typos, mainly in comments.


# 1.119 23-Oct-2021 skrll

Fix non-UVMHIST build


# 1.118 16-Oct-2021 ryo

fix non-MULTIPROCESSOR build


# 1.117 10-Oct-2021 skrll

Use sys/uvm/pmap/pmap_tlb.c on Aarch64 in the same way that some Arm, MIPS,
and some PPC kernels do. This removes the limitation of 256 processes on
CPUs with 8bit ASID field, e.g. Apple M1.

Additionally the following changes have been made

- removed a couple of unnecessary aarch64_tlbi_all calls
- removed any invalidation after freeing page tables due to
_pmap_sweep_pdp. This was never necessary afaict.
- all kernel mappings are marked global and userland mapping not-global.

Performance testing hasn't show a significant difference. The data here
is from building a kernel on an lx2k system with nvme.

before
1489.6u 400.4s 2:40.65 1176.5% 228+224k 0+32289io 57pf+0w
1482.6u 403.2s 2:38.49 1189.9% 228+222k 0+32274io 46pf+0w
1485.4u 402.2s 2:37.27 1200.2% 228+222k 0+32275io 12pf+0w

after
1493.9u 404.6s 2:37.50 1205.4% 227+221k 0+32265io 48pf+0w
1485.0u 408.0s 2:38.54 1194.0% 227+222k 0+32272io 36pf+0w
1484.3u 407.0s 2:35.88 1213.3% 228+224k 0+32268io 14pf+0w

>>> stats.ttest_ind([160.65,158.49,157.27], [157.5,158.54,155.88])
Ttest_indResult(statistic=1.1923622711296888, pvalue=0.2990182944606766)
>>>


# 1.116 30-Sep-2021 skrll

Ensure TCR_EPD0 is set on entry to pmap_activate and ensure it is set as
early as possible for APs.


# 1.115 26-Sep-2021 skrll

Use UVMHIST_CALLARGS


# 1.114 26-Sep-2021 skrll

'\n' is not required in KASSERTMSG either.


# 1.113 26-Sep-2021 skrll

"\n" is not required in KERNHIST


# 1.112 15-Sep-2021 skrll

Use __SHIFTIN. Same code before and after.


# 1.111 12-Sep-2021 skrll

pmap_page_remove: simply and reduce the code size slightly.


# 1.110 09-Sep-2021 skrll

In pmap_icache_sync_range change

for (...) {
...
if (condition) {
// do stuff
}
}

to

for (...) {
...
if (!conditional)
continue;
// do stuff
}

to save on indentation. Same code (modulo register usage) before and
after.


# 1.109 09-Sep-2021 skrll

KNF


Revision tags: thorpej-i2c-spi-conf2-base thorpej-futex2-base thorpej-cfargs2-base cjep_sun2x-base1 cjep_sun2x-base cjep_staticlib_x-base1 thorpej-i2c-spi-conf-base
# 1.108 29-May-2021 skrll

Deal with the pmap limitation of maxproc in a more complete way and
recognise CPUs with only 8bit ASIDs.


Revision tags: cjep_staticlib_x-base
# 1.107 30-Apr-2021 skrll

branches: 1.107.2;
Make the ddb for pmap / pte information pmap agnostic


# 1.106 29-Apr-2021 skrll

Remove some unnecessary tlb invalidate in pmap_growkernel and ASAN shadow
map. Ensure the shadow map mappings are visible to the TLB walkers.


# 1.105 21-Apr-2021 ryo

branches: 1.105.2;
added more attributes of PTE displayed by "ddb>machine pte"


Revision tags: thorpej-cfargs-base
# 1.104 17-Apr-2021 mrg

remove KERNHIST_INIT_STATIC(). it stradles the line between usable
early in boot and broken early in boot by requiring a partly static
structure with another structure that must be present by the time
any uses are performed. theoretically platform code could allocate
a chunk while seting up memory and assign it here, giving a dynamic
sizing for the entry list, but the reality is that all users have
a statically allocated entry list as well.

the existing KERNHIST_LINK_STATIC() is used in conjunction with
KERNHIST_INITIALIZER() instead.

this stops a NULL pointer deref when the _LOG() macro is called
before the storage is linked in, which happens with GCC 10 on OCTEON
with UVMHIST enabled, crashing in very early kernel init.


Revision tags: thorpej-futex-base
# 1.103 09-Mar-2021 ryo

branches: 1.103.2;
fix build error without options DDB.

kvtopte() is referenced from arm/acpi/acpi_machdep.c


# 1.102 13-Feb-2021 ryo

No assignment is needed here.

the loop in pmap_page_remove() always removes the first pv,
and since the list is managed by _pmap_remove_pv(), pp->pp_pv.pv_next always points to the first.


# 1.101 01-Feb-2021 ryo

It is enough to make a page accessible instead of writable.
same fix as r1.76


# 1.100 31-Jan-2021 ryo

implement pmap_remove_all().

The size of struct pv_entry has increased, but speed of kernel build has improved by about 1%
exec and exit should have been improved.


# 1.99 20-Dec-2020 skrll

Improve the English in the previous comment fix.


# 1.98 19-Dec-2020 skrll

Tweak a comment


# 1.97 11-Dec-2020 skrll

s:aarch64/cpufunc.h:arm/cpufunc.h:

a baby step in the grand arm header unification challenge


# 1.96 10-Nov-2020 skrll

AA64 is not MIPS.

Change all KSEG references to directmap


# 1.95 07-Nov-2020 skrll

In pmap_devmap_bootstrap only set pmap_devmap_bootstrap_done if there
is an entry and ALL of the entries have been done. The entry required
for EARLYCONS might not be the first/only one...


# 1.94 01-Nov-2020 jmcneill

branches: 1.94.2;
No need to disable translation table walks in pmap_activate().


# 1.93 22-Oct-2020 skrll

Use the isb macro - missed in previous commit


# 1.92 22-Oct-2020 skrll

Use the dmb/dsb/isb macros... if nothing else they're all now consistent
about the "memory" assembler contraint.

No binary change


# 1.91 28-Sep-2020 skrll

Only set pmap_devmap_bootstrap_done if something gets mapped.

Think acpi_platform_devmap


# 1.90 19-Sep-2020 skrll

Make __md_palloc pmap agnostic (think sys/uvm/pmap)


# 1.89 14-Sep-2020 ryo

PID_MAX is just an initial value (soft maximum). Don't use it for CTASSERT.
defined __HAVE_CPU_MAXPROC to use function cpu_maxproc().

pointed out by mrg@, thanks.


# 1.88 06-Sep-2020 ryo

Fix panic caused by modload. http://mail-index.netbsd.org/port-arm/2020/08/30/msg006960.html

The address space reserved for modules may not be mapped in L1-L3.


# 1.87 14-Aug-2020 skrll

Whitespace


# 1.86 12-Aug-2020 skrll

Part IV of ad's performance improvements for aarch64

- Implement pmap_growkernel(), and update kernel pmap's stats with atomics.

- Then, pmap_kenter_pa() and pmap_kremove() no longer need to allocate
memory nor take pm_lock, because they only modify L3 PTEs.

- Then, pm_lock and pp_lock can be adaptive mutexes at IPL_NONE which are
cheaper than spin mutexes.

- Take the pmap's lock in pmap_extract() if not the kernel's pmap, otherwise
pmap_extract() might see inconsistent state.


# 1.85 09-Aug-2020 skrll

Fix another UVMHIST so it doesn't use %s


# 1.84 16-Jul-2020 skrll

pmapboot_enter simplication
- bootpage_alloc in asm becomes pmapboot_pagealloc in C
- PMAPBOOT_ENTER_NOBLOCK is removed as it's not used
- PMAPBOOT_ENTER_NOOVERWRITE is removed as it's now always on
- physpage_allocator argument is removed as it's always
pmapboot_pagealloc
- Support for EARLYCONS without CONSADDR is removed so that the identity
map for CONSADDR is always known.

For the assembly files:
2 files changed, 40 insertions(+), 89 deletions(-)

LGTM ryo


# 1.83 04-Jul-2020 rin

Use tlen for temporary length variable instead of l, which is usually
used for struct lwp *.

No binary changes.


# 1.82 02-Jul-2020 rin

pmap_procwr(): sync icache even if p != curproc. This fixes applications
like GDB for arm32, that rewrite text of other process.

Thanks to ryo@ for discussion.


# 1.81 02-Jul-2020 rin

Set uvmexp.ncolors appropriately, which is required for some CPU
models with VIPT icache.

Otherwise, alias in virtual address results in inconsistent results,
at least for applications that rewrite text of other process, e.g.,
GDB for arm32.

Also, this hopefully fixes other unexpected failures due to alias.

Confirmed that there's no observable regression in performance;
difference in ``time make -j8'' for GENERIC64 kernel on BCM2837
with and without setting uvmexp.ncolors is within 0.1%.

Thanks to ryo@ for discussion.


# 1.80 27-Jun-2020 rin

Fix typo in name of evcnt(4) counter.


# 1.79 24-Jun-2020 ryo

Fix bug with incorrect range calculation when doing icache sync.
This is called by sysarch(ARM_SYNC_ICACHE) from aarch32 (compat_netbsd32) emul process.

pointed out by rin@, thanks.

XXX pullup-9


# 1.78 14-Jun-2020 ad

- Fix a lock order reversal in pmap_page_protect().

- Make sure pmap is always locked when updating stats; atomics no longer
needed to do that.

- Remove unneeded traversal of pv list in pmap_enter_pv().

- Shrink struct vm_page from 136 to 128 bytes (cache line sized) and struct
pv_entry from 48 to 32 bytes (power of 2 sized).

- Embed a pv_entry in each vm_page. This means PV entries don't need to
be allocated for private anonymous memory / COW pages / most UBC mappings.
Dynamic PV entries are then used only for stuff like shared libraries and
shared memory.

Proposed on port-arm@.


# 1.77 10-Jun-2020 ad

- Wired/resident stats shouldn't covered by PMAPCOUNTERS.
- Rename need_update_pv -> need_enter_pv.

Ok ryo@


# 1.76 01-Jun-2020 ryo

no need to make the PTE writable to do icache_sync, enough to accessible.


# 1.75 15-May-2020 skrll

Use __diagused


# 1.74 15-May-2020 tnn

fix non-diag build


# 1.73 14-May-2020 skrll

Use MUTEX_NODEBUG for PV locks as is commonly done. OK ryo.


# 1.72 13-May-2020 jmcneill

Implement pmap_extract_coherency


Revision tags: bouyer-xenpvh-base2 phil-wifi-20200421 bouyer-xenpvh-base1
# 1.71 18-Apr-2020 skrll

PMAP_DEBUG has been deleted on arm


# 1.70 13-Apr-2020 maxv

Add support for Branch Target Identification (BTI).

On the executable pages that have the GP (Guarded Page) bit, the semantic
of the "br" and "blr" instructions is changed: the CPU expects the first
instruction of the jump/call target to be "bti", and faults if it isn't.

We add the GP bit on the kernel .text pages (and incidentally the .rodata
pages, but we don't care). The compiler adds a "bti c" instruction at the
beginning of each C function. We modify the ENTRY() macros to manually add
"bti c" in the asm functions.

cpuswitch.S needs a specific change: with "br x27" the CPU expects "bti j",
which is bad because the functions begin with "bti c"; switch to "br x16",
for the CPU to accept "bti c".

BTI helps defend against JOP/COP. Tested on Qemu.


Revision tags: phil-wifi-20200411 bouyer-xenpvh-base
# 1.69 08-Apr-2020 ryo

branches: 1.69.2;
use PMAP_PAGE_INIT() to initialize mutex in pmap_page.

VM_MDPAGE_INIT() in pmap_free_pdp() had initialized pp_flags,
so it unintentionally cleared PMAP_PAGE_FLAGS_PV_TRACKED.
use PMAP_PAGE_INIT to avoid using PMAP_PAGE_FLAGS_PV_TRACKED.

pointed out by tnn@, thanks


Revision tags: phil-wifi-20200406
# 1.68 14-Mar-2020 ad

pmap_remove_all(): Return a boolean value to indicate the behaviour. If
true, all mappings have been removed, the pmap is totally cleared out, and
UVM can then avoid doing the work to call pmap_remove() for each map entry.
If false, either nothing has been done, or some helpful arch-specific voodoo
has taken place.


Revision tags: is-mlppp-base
# 1.67 02-Mar-2020 ryo

oops, fix incorrect usage of daif_enable() in my previous commit.


# 1.66 29-Feb-2020 ryo

Fix pmap to work correctly with tagged addresses

- when fault, untag from address before passing to uvm/pmap functions
- pmap_extract() checks more strictly and consider the address tag


# 1.65 29-Feb-2020 ryo

use pmapboot_enter_range()


Revision tags: ad-namecache-base3
# 1.64 10-Feb-2020 ryo

use LIST(3) instead of TAILQ(3) to save one word in struct vm_page and struct pmap.

pointed out by riastradh@. thanks


# 1.63 03-Feb-2020 ryo

add support pmap_pv(9)

Patch originally from jmcneill@. thanks


# 1.62 03-Feb-2020 ryo

separate struct vm_page_md into vm_page_md and pmap_page
for preparation pmap_pv(9)


Revision tags: ad-namecache-base2 ad-namecache-base1
# 1.61 09-Jan-2020 ryo

fix behaviour mmap()/mprotect() when passed only PROT_EXEC.

when mmap()/mprotect() with only PROT_EXEC, syscall will be successful,
but the page actually hadn't been mapped.
it should be mapped with PROT_READ|PROT_EXEC implicitly. (r-x)


Revision tags: ad-namecache-base
# 1.60 30-Dec-2019 skrll

branches: 1.60.2;
Update pmap_map_chunk to allow L[12] block mappings and L3 page mappings


# 1.59 30-Dec-2019 skrll

Remove unnecessary brackets and unwrap a conditional. Same code before
and after.


# 1.58 28-Dec-2019 jmcneill

Do not use Early Write Acknowledge for PCIe I/O and config space.


# 1.57 27-Dec-2019 jmcneill

Enable early write acknowledge for device memory mappings.


# 1.56 19-Dec-2019 skrll

G/C kasan_shadow_map call in pmap_enter

pmap_growkernel calls kasan_shadow_map for KVA


# 1.55 18-Dec-2019 ryo

atomic_add_16() is not used in pmap.c anymore. no need decl here.


# 1.54 18-Dec-2019 ryo

space to tab


# 1.53 14-Dec-2019 skrll

Fix build... wire_count probably doesn't need atomics


# 1.52 13-Dec-2019 skrll

Fix KASAN support by calling kasan_shadow_map in pmap_growkernel


# 1.51 10-Dec-2019 ad

pg->phys_addr -> VM_PAGE_TO_PHYS(pg)


Revision tags: phil-wifi-20191119
# 1.50 14-Nov-2019 maxv

Mark several kASan functions with __nothing, to avoid annoying #ifdefs.
Same as kCSan and kMSan.


# 1.49 14-Nov-2019 maxv

Don't include "opt_kasan.h" when there's already <sys/asan.h> included.


# 1.48 29-Oct-2019 maya

Define PMAP_NEED_PROCWR, providing strategically placed i-cache
synchronization where just-changed memory is about to be executed.

Fixes SIGILLs seen when running Mono 6 on QEMU Cortex-A57.

ok ryo


# 1.47 22-Sep-2019 jmcneill

Disable translation table walks using TTBR0 while changing its value and
when deactivating a pmap. Fixes stability issues on Ampere eMAG CPUs.


# 1.46 20-Sep-2019 ryo

ref/mod bit should be set according to 'flags' argument, not 'prot'. r1.44 was incomplete.


# 1.45 13-Sep-2019 ryo

In pmap_devmap_bootstrap(), cpu_earlydevice_va_p() must not return true until *all* devmap tables have been enabled.
console mapping may be present in the last table.


# 1.44 07-Sep-2019 ryo

- remove incorrect KASSERT. mmap(2) with prot=PROT_WRITE calls pmap_enter(..., PROT_WRITE) internally.
- fix to update page reference flags when only PROT_WRITE or PROT_EXECUTE specified


# 1.43 15-Aug-2019 skrll

Make pmap_db_pte_print more terse so it's quicker on serial consoles


# 1.42 12-Aug-2019 skrll

Use PMAP_DEV in DEVMAP_ENTRY rather than pmap_map_chunk. It's clearer and
means pmap_map_chunk can be made to map other memory types.


Revision tags: netbsd-9-base phil-wifi-20190609
# 1.41 17-May-2019 mrg

branches: 1.41.2;
apply some __diagused.


Revision tags: isaki-audio2-base
# 1.40 08-Apr-2019 ryo

- free empty page tables pages if reach a certain usage.
- need to lock at removing an old pg (_pmap_remove_pv) in _pmap_enter()


# 1.39 06-Apr-2019 ryo

Fix race conditions about pmap_page_protect() and pmap_enter().

while handling same PTE by these functions in same time, there
is a critical path that the number of valid PTEs and wire_count
are inconsistent, and it caused KASSERT.
Need to hold a pv_lock while modifying them.


# 1.38 20-Mar-2019 ryo

spinkle __printflike(), and use PRIxxx


# 1.37 19-Mar-2019 ryo

- add ddb command "machine ttbr" to dump MMU tables.
- tidy up descriptions, usages and messages.


# 1.36 19-Mar-2019 ryo

- free L1-L3 pages that has been emptied by pmap_remove().
- if no memories, pmap_enter will return correctly ENOMEM if PMAP_CANFAIL, or wait until available any memories if !PMAP_CANFAIL.

These changes improves the stability when we use a huge virtual memory spaces with mmap.


# 1.35 06-Feb-2019 ryo

improve pmap_remove
- don't lock/unlock per page in pmap_remove()
- speedup pte lookup for continuous addresses
- bring out pool_cache_put(&_pmap_pv_pool, pv) from lock/unlock section


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226
# 1.34 21-Dec-2018 ryo

- add workaround for Cavium ThunderX errata 27456.
- add cpufuncs table in cpu_info. each cpu clusters may have different erratum. (e.g. big.LITTLE)


Revision tags: pgoyette-compat-1126
# 1.33 01-Nov-2018 maxv

Add kASan support for aarch64. Stack tracking needs more investigation
and will come in a separate commit.

Reviewed by ryo@ jmcneill@ skrll@.


# 1.32 31-Oct-2018 ryo

invalidate icache correctly.
l3pte_executable() should be used for only valid pte.


Revision tags: pgoyette-compat-1020
# 1.31 18-Oct-2018 skrll

Provide generic start code that assumes the MMU is off and caches are
disabled as per the linux booting protocol for ARMv6 and ARMv7 boards.
u-boot image type should be changed to 'linux' for correct behaviour.

The new start code builds a minimal "bootstrap" L1PT with cached access
disabled and uses the same table for all processors. AP startup is
performed in less steps and more code is written in C.

The bootstrap tables and stack are placed into an (orphaned) section
"_init_memory" which is given to uvm when it is no longer used.

Various kernels have been converted to use this code and tested. Some
boards were provided by TNF. Thanks!

The GENERIC kernel now boots on boards using the TEGRA, SUNXI and EXYNOS
kernels. The GENERIC kernel will also work on RPI2 using u-boot.

Thanks to martin@ and aymeric@ for testing on parallella and nanosoc
respectively


# 1.30 14-Oct-2018 skrll

Use __nothing


# 1.29 12-Oct-2018 ryo

add initial support of COMPAT_NETBSD32 on AArch64.
arm ELF32 EABI binaries could be execute in AArch32 state on AArch64. A32 THUMB mode is not supported yet.


# 1.28 12-Oct-2018 ryo

- cleanup checking address ranges with IN_RANGE macro
- change PM_ADDR_CHECK macro to KASSERTMSG
- restore fast lookup cases with IN_RANGE macro for pmap_extract changed in my previous commit.


# 1.27 12-Oct-2018 ryo

rewrite pmap_pte_lookup() to share similar code.


# 1.26 04-Oct-2018 ryo

cleanup locore, and changed the way to map memories during boot.
- add functions bootpage_enter() and bootpage_alloc() to adapt various layout
of physical memory map. especially for 64bit physical memory layout.
pmapboot_alloc() allocates pagetable pages from _end[].
- changed to map only the required amount for PA=VA identity mapping
(kernel image, UART device, and FDT blob) with L2_BLOCK(2Mbyte).
- changing page permission for kernel image, and making KSEG mapping are done
at cpu_kernel_vm_init() instead of at locore.
- optimize PTE entries with PTE Contiguous bit. it is enabled on devmap only for now.

reviewed by skrll@, thanks.


# 1.25 04-Oct-2018 ryo

* define LX_BLKPAG_{OS,ATTR}_* for OS dependent PTE attributes in pmap.h
* cleanup macros


Revision tags: pgoyette-compat-0930
# 1.24 17-Sep-2018 ryo

delete debug printf and KASSERT.


# 1.23 10-Sep-2018 maxv

Replace KDASSERT by panic.


# 1.22 10-Sep-2018 maxv

Rename _pmap_alloc_pdp -> pmap_alloc_pdp, and make it public.


# 1.21 10-Sep-2018 ryo

cleanup aarch64 mpstart and fdt bootstrap
* arm_cpu_hatch_arg is a bad idea. avoid serializing CPU startup, and eliminate arm_cpu_hatch_arg.
in mpstart, resolve own cpu index using array of cpu_mpidr[] (aarch64)
* add support fdt enable-method "spin-table"
* add support fdt enable-method "brcm,bcm2836-smp" (for 32bit RaspberryPi)
* use arm_fdt_cpu_bootstrap() instead of psci_fdt_bootstrap()
* rename "arm/fdt/psci_fdt.h" to "arm/fdt/psci_fdtvar.h" because of conflict of include file for needs-flag
* add devmap for cpu spin-table of raspberrypi3/aarch64
* no need to force hatch APs for raspberrypi3/arm32 ifndef MULTIPROCESSOR.
* fix to work pmap_extract(kerneltext/data/bss) even if before calling pmap_bootstrap

idea to use cpu_mpidr[] by jmcneill@. reviewd by skrll@. thanks.


Revision tags: pgoyette-compat-0906
# 1.20 27-Aug-2018 ryo

need to add VM_PROT_READ when pmap_kenter_pa(va, pa, VM_PROT_WRITE, 0) or pmap_kenter_pa(va, pa, VM_PROT_EXECUTE, 0).
VM_PROT_READ is treated as an access permission inernally.


# 1.19 11-Aug-2018 ryo

change to minimum invalidation of TLB.
specifying not only va but also asid, and not invalidate L0-L2 entry using tlbi_*_ll() if needed.


# 1.18 10-Aug-2018 ryo

treat kernel-exec attr and user-exec attr separately.
kernel cannot execute userland exec page, and user cannot execute kernel page.


# 1.17 06-Aug-2018 ryo

set kernel text/rodata readonly by default.
add function db_write_text() for setting ddb breakpoint.


# 1.16 31-Jul-2018 skrll

Define and use VPRINTF


Revision tags: pgoyette-compat-0728
# 1.15 27-Jul-2018 ryo

changes of pmap.c r1.13 seems to be unstable.
In order to invalidate icache, not to invalidate all icache,
but temporary to make the page writable and invalidate target address only.


# 1.14 24-Jul-2018 ryo

don't call pool_cache_put with locking pmap. pool_cache_put call pmap_kenter_pa internally.
(pool_cache_put_paddr -> pool_cache_put_slow -> pool_get -> pmap_kenter_pa)


# 1.13 23-Jul-2018 ryo

* fix icache invalidations.
* "ic ivau" (aarch64_icache_sync_range) with VA generates permission fault in some situations, therefore use KSEG address for now.


# 1.12 23-Jul-2018 ryo

rather than using flags to resolve nested locks, reserve pool_cache before locking.


# 1.11 21-Jul-2018 ryo

* avoid deadlock. mutex_owned() works only for adaptive lock, therefore we cannot use it for spinlock...
* add more NULL check
* clear pte when pmap_enter() fails


# 1.10 17-Jul-2018 ryo

Use __debugused


# 1.9 17-Jul-2018 christos

Add missing casts, remove unused variables.


# 1.8 09-Jul-2018 ryo

need locks in pmap_kremove() and pmap_fault_fixup()


Revision tags: phil-wifi-base pgoyette-compat-0625 pgoyette-compat-0521
# 1.7 20-May-2018 ryo

branches: 1.7.2;
pmap_enter() must update modified/referenced flags by 'flags' not 'prot'.


# 1.6 16-May-2018 ryo

Fix memory leak. it was leaking one page every pmap_create().
pm->pm_vmlist must be initialized before calling _pmap_alloc_pdp().


Revision tags: pgoyette-compat-0502
# 1.5 29-Apr-2018 ryo

fix KASSERT panic. pv_entry may not be exists in pvlist when pmap_remove().


# 1.4 29-Apr-2018 ryo

delete unused code


# 1.3 27-Apr-2018 ryo

fix instability behavior of bufcache on aarch64.
* fix to return correct ref/mod when PMAP_WIRED.
* changed to keep wired flags in pte instead of pv_entry, and cleanup.


Revision tags: pgoyette-compat-0422 pgoyette-compat-0415 pgoyette-compat-0407
# 1.2 01-Apr-2018 ryo

Add initial support for ARMv8 (AARCH64) (by nisimura@ and ryo@)

- sys/arch/evbarm64 is gone and integrated into sys/arch/evbarm. (by skrll@)
- add support fdt. evbarm/conf/GENERIC64 fdt (bcm2837,sunxi,tegra) based generic 64bit kernel config. (by skrll@, jmcneill@)


Revision tags: netbsd-8-2-RELEASE netbsd-8-1-RELEASE netbsd-8-1-RC1 netbsd-7-2-RELEASE netbsd-8-0-RELEASE netbsd-8-0-RC2 netbsd-8-0-RC1 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 netbsd-7-1-2-RELEASE pgoyette-compat-base netbsd-7-1-1-RELEASE tls-maxphys-base-20171202 matt-nb8-mediatek-base nick-nhusb-base-20170825 perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base pgoyette-localcount-20170320 netbsd-7-1-RELEASE netbsd-7-1-RC2 nick-nhusb-base-20170204 netbsd-7-nhusb-base-20170116 bouyer-socketcan-base pgoyette-localcount-20170107 netbsd-7-1-RC1 nick-nhusb-base-20161204 pgoyette-localcount-20161104 netbsd-7-0-2-RELEASE nick-nhusb-base-20161004 localcount-20160914 netbsd-7-nhusb-base pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907 nick-nhusb-base-20160529 netbsd-7-0-1-RELEASE nick-nhusb-base-20160422 nick-nhusb-base-20160319 nick-nhusb-base-20151226 netbsd-7-0-RELEASE nick-nhusb-base-20150921 netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 nick-nhusb-base-20150606 nick-nhusb-base-20150406 nick-nhusb-base tls-maxphys-base netbsd-7-base
# 1.1 10-Aug-2014 matt

branches: 1.1.4; 1.1.28;
Preliminary files for AARCH64 (64-bit ARM) support.
Enough for a distribution build.


# 1.132 02-Apr-2022 skrll

Update to support EFI runtime outside the kernel virtual address space
by creating an EFI RT pmap that can be activated / deactivated when
required.

Adds support for EFI RT to ARM_MMU_EXTENDED (ASID) 32-bit Arm machines.

On Arm64 the usage of pmapboot_enter is reduced and the mappings are
created much later in the boot process -- now in cpu_startup_hook.
Backward compatiblity for KVA mapped RT from old bootaa64.efi is
maintained.

Adding support to other platforms should be easier as a result.


# 1.131 19-Mar-2022 skrll

Slight code re-organisation. NFCI.


# 1.130 12-Mar-2022 riastradh

sys: Membar audit around reference count releases.

If two threads are using an object that is freed when the reference
count goes to zero, we need to ensure that all memory operations
related to the object happen before freeing the object.

Using an atomic_dec_uint_nv(&refcnt) == 0 ensures that only one
thread takes responsibility for freeing, but it's not enough to
ensure that the other thread's memory operations happen before the
freeing.

Consider:

Thread A Thread B
obj->foo = 42; obj->baz = 73;
mumble(&obj->bar); grumble(&obj->quux);
/* membar_exit(); */ /* membar_exit(); */
atomic_dec -- not last atomic_dec -- last
/* membar_enter(); */
KASSERT(invariant(obj->foo,
obj->bar));
free_stuff(obj);

The memory barriers ensure that

obj->foo = 42;
mumble(&obj->bar);

in thread A happens before

KASSERT(invariant(obj->foo, obj->bar));
free_stuff(obj);

in thread B. Without them, this ordering is not guaranteed.

So in general it is necessary to do

membar_exit();
if (atomic_dec_uint_nv(&obj->refcnt) != 0)
return;
membar_enter();

to release a reference, for the `last one out hit the lights' style
of reference counting. (This is in contrast to the style where one
thread blocks new references and then waits under a lock for existing
ones to drain with a condvar -- no membar needed thanks to mutex(9).)

I searched for atomic_dec to find all these. Obviously we ought to
have a better abstraction for this because there's so much copypasta.
This is a stop-gap measure to fix actual bugs until we have that. It
would be nice if an abstraction could gracefully handle the different
styles of reference counting in use -- some years ago I drafted an
API for this, but making it cover everything got a little out of hand
(particularly with struct vnode::v_usecount) and I ended up setting
it aside to work on psref/localcount instead for better scalability.

I got bored of adding #ifdef __HAVE_ATOMIC_AS_MEMBAR everywhere, so I
only put it on things that look performance-critical on 5sec review.
We should really adopt membar_enter_preatomic/membar_exit_postatomic
or something (except they are applicable only to atomic r/m/w, not to
atomic_load/store_*, making the naming annoying) and get rid of all
the ifdefs.


# 1.129 05-Mar-2022 skrll

Slight comment improvement.


# 1.128 16-Feb-2022 andvar

fix various typos, mainly in comments.


# 1.127 31-Jan-2022 ryo

add support Hardware updates to Access flag and Dirty state (FEAT_HAFDBS)

- The DBM bit of the PTE is now used to determine if it is writable, and
the AF bit is treated entirely as a reference bit. A valid PTE is always
treated as readable. There can be no valid PTE that is not readable.
- LX_BLKPAG_OS_{READ,WRITE} are used only for debugging purposes,
and has been superseded by LX_BLKPAG_AF and LX_BLKPAG_DBM.
- Improve comment

The need for reference/modify emulation has been eliminated,
and access/permission faults have been reduced, however,
there has been little change in overall performance.


# 1.126 31-Jan-2022 ryo

Skip unnecessary PTE operations and TLB invalidation.


# 1.125 16-Jan-2022 rillig

aarch64/pmap: remove stray semicolon

No binary change.


# 1.124 15-Jan-2022 skrll

The translations that need invalidation are always last level so remove
the (dubious) logic around tracking the level. The "any level" TLB
invalidation maintenance operation are used, but this may change after
further testing.

before
======
1661.0u 420.2s 2:53.82 1197.3% 231+29k 10+33918io 102pf+0w
1646.8u 425.2s 2:52.96 1198.0% 232+29k 1+33937io 49pf+0w
1647.9u 425.7s 2:52.58 1201.6% 232+29k 0+33940io 32pf+0w

After
=====
1602.5u 420.8s 2:49.09 1196.6% 238+30k 24+33893io 54pf+0w
1600.7u 421.3s 2:51.53 1178.8% 238+30k 1+33914io 33pf+0w
1597.5u 424.3s 2:50.46 1186.1% 238+30k 0+33915io 17pf+0w

LGTM from ryo@


# 1.123 14-Jan-2022 skrll

Restore the previous pmap_remove_all behaviour as the new method meant
the n1sdp couldn't complete a build.

No noticeable change in kernel build performance.


# 1.122 04-Jan-2022 skrll

KNF


# 1.121 10-Dec-2021 andvar

s/occured/occurred/ in comments, log messages and man pages.


# 1.120 07-Dec-2021 andvar

fix various typos, mainly in comments.


# 1.119 23-Oct-2021 skrll

Fix non-UVMHIST build


# 1.118 16-Oct-2021 ryo

fix non-MULTIPROCESSOR build


# 1.117 10-Oct-2021 skrll

Use sys/uvm/pmap/pmap_tlb.c on Aarch64 in the same way that some Arm, MIPS,
and some PPC kernels do. This removes the limitation of 256 processes on
CPUs with 8bit ASID field, e.g. Apple M1.

Additionally the following changes have been made

- removed a couple of unnecessary aarch64_tlbi_all calls
- removed any invalidation after freeing page tables due to
_pmap_sweep_pdp. This was never necessary afaict.
- all kernel mappings are marked global and userland mapping not-global.

Performance testing hasn't show a significant difference. The data here
is from building a kernel on an lx2k system with nvme.

before
1489.6u 400.4s 2:40.65 1176.5% 228+224k 0+32289io 57pf+0w
1482.6u 403.2s 2:38.49 1189.9% 228+222k 0+32274io 46pf+0w
1485.4u 402.2s 2:37.27 1200.2% 228+222k 0+32275io 12pf+0w

after
1493.9u 404.6s 2:37.50 1205.4% 227+221k 0+32265io 48pf+0w
1485.0u 408.0s 2:38.54 1194.0% 227+222k 0+32272io 36pf+0w
1484.3u 407.0s 2:35.88 1213.3% 228+224k 0+32268io 14pf+0w

>>> stats.ttest_ind([160.65,158.49,157.27], [157.5,158.54,155.88])
Ttest_indResult(statistic=1.1923622711296888, pvalue=0.2990182944606766)
>>>


# 1.116 30-Sep-2021 skrll

Ensure TCR_EPD0 is set on entry to pmap_activate and ensure it is set as
early as possible for APs.


# 1.115 26-Sep-2021 skrll

Use UVMHIST_CALLARGS


# 1.114 26-Sep-2021 skrll

'\n' is not required in KASSERTMSG either.


# 1.113 26-Sep-2021 skrll

"\n" is not required in KERNHIST


# 1.112 15-Sep-2021 skrll

Use __SHIFTIN. Same code before and after.


# 1.111 12-Sep-2021 skrll

pmap_page_remove: simply and reduce the code size slightly.


# 1.110 09-Sep-2021 skrll

In pmap_icache_sync_range change

for (...) {
...
if (condition) {
// do stuff
}
}

to

for (...) {
...
if (!conditional)
continue;
// do stuff
}

to save on indentation. Same code (modulo register usage) before and
after.


# 1.109 09-Sep-2021 skrll

KNF


Revision tags: thorpej-i2c-spi-conf2-base thorpej-futex2-base thorpej-cfargs2-base cjep_sun2x-base1 cjep_sun2x-base cjep_staticlib_x-base1 thorpej-i2c-spi-conf-base
# 1.108 29-May-2021 skrll

Deal with the pmap limitation of maxproc in a more complete way and
recognise CPUs with only 8bit ASIDs.


Revision tags: cjep_staticlib_x-base
# 1.107 30-Apr-2021 skrll

branches: 1.107.2;
Make the ddb for pmap / pte information pmap agnostic


# 1.106 29-Apr-2021 skrll

Remove some unnecessary tlb invalidate in pmap_growkernel and ASAN shadow
map. Ensure the shadow map mappings are visible to the TLB walkers.


# 1.105 21-Apr-2021 ryo

branches: 1.105.2;
added more attributes of PTE displayed by "ddb>machine pte"


Revision tags: thorpej-cfargs-base
# 1.104 17-Apr-2021 mrg

remove KERNHIST_INIT_STATIC(). it stradles the line between usable
early in boot and broken early in boot by requiring a partly static
structure with another structure that must be present by the time
any uses are performed. theoretically platform code could allocate
a chunk while seting up memory and assign it here, giving a dynamic
sizing for the entry list, but the reality is that all users have
a statically allocated entry list as well.

the existing KERNHIST_LINK_STATIC() is used in conjunction with
KERNHIST_INITIALIZER() instead.

this stops a NULL pointer deref when the _LOG() macro is called
before the storage is linked in, which happens with GCC 10 on OCTEON
with UVMHIST enabled, crashing in very early kernel init.


Revision tags: thorpej-futex-base
# 1.103 09-Mar-2021 ryo

branches: 1.103.2;
fix build error without options DDB.

kvtopte() is referenced from arm/acpi/acpi_machdep.c


# 1.102 13-Feb-2021 ryo

No assignment is needed here.

the loop in pmap_page_remove() always removes the first pv,
and since the list is managed by _pmap_remove_pv(), pp->pp_pv.pv_next always points to the first.


# 1.101 01-Feb-2021 ryo

It is enough to make a page accessible instead of writable.
same fix as r1.76


# 1.100 31-Jan-2021 ryo

implement pmap_remove_all().

The size of struct pv_entry has increased, but speed of kernel build has improved by about 1%
exec and exit should have been improved.


# 1.99 20-Dec-2020 skrll

Improve the English in the previous comment fix.


# 1.98 19-Dec-2020 skrll

Tweak a comment


# 1.97 11-Dec-2020 skrll

s:aarch64/cpufunc.h:arm/cpufunc.h:

a baby step in the grand arm header unification challenge


# 1.96 10-Nov-2020 skrll

AA64 is not MIPS.

Change all KSEG references to directmap


# 1.95 07-Nov-2020 skrll

In pmap_devmap_bootstrap only set pmap_devmap_bootstrap_done if there
is an entry and ALL of the entries have been done. The entry required
for EARLYCONS might not be the first/only one...


# 1.94 01-Nov-2020 jmcneill

branches: 1.94.2;
No need to disable translation table walks in pmap_activate().


# 1.93 22-Oct-2020 skrll

Use the isb macro - missed in previous commit


# 1.92 22-Oct-2020 skrll

Use the dmb/dsb/isb macros... if nothing else they're all now consistent
about the "memory" assembler contraint.

No binary change


# 1.91 28-Sep-2020 skrll

Only set pmap_devmap_bootstrap_done if something gets mapped.

Think acpi_platform_devmap


# 1.90 19-Sep-2020 skrll

Make __md_palloc pmap agnostic (think sys/uvm/pmap)


# 1.89 14-Sep-2020 ryo

PID_MAX is just an initial value (soft maximum). Don't use it for CTASSERT.
defined __HAVE_CPU_MAXPROC to use function cpu_maxproc().

pointed out by mrg@, thanks.


# 1.88 06-Sep-2020 ryo

Fix panic caused by modload. http://mail-index.netbsd.org/port-arm/2020/08/30/msg006960.html

The address space reserved for modules may not be mapped in L1-L3.


# 1.87 14-Aug-2020 skrll

Whitespace


# 1.86 12-Aug-2020 skrll

Part IV of ad's performance improvements for aarch64

- Implement pmap_growkernel(), and update kernel pmap's stats with atomics.

- Then, pmap_kenter_pa() and pmap_kremove() no longer need to allocate
memory nor take pm_lock, because they only modify L3 PTEs.

- Then, pm_lock and pp_lock can be adaptive mutexes at IPL_NONE which are
cheaper than spin mutexes.

- Take the pmap's lock in pmap_extract() if not the kernel's pmap, otherwise
pmap_extract() might see inconsistent state.


# 1.85 09-Aug-2020 skrll

Fix another UVMHIST so it doesn't use %s


# 1.84 16-Jul-2020 skrll

pmapboot_enter simplication
- bootpage_alloc in asm becomes pmapboot_pagealloc in C
- PMAPBOOT_ENTER_NOBLOCK is removed as it's not used
- PMAPBOOT_ENTER_NOOVERWRITE is removed as it's now always on
- physpage_allocator argument is removed as it's always
pmapboot_pagealloc
- Support for EARLYCONS without CONSADDR is removed so that the identity
map for CONSADDR is always known.

For the assembly files:
2 files changed, 40 insertions(+), 89 deletions(-)

LGTM ryo


# 1.83 04-Jul-2020 rin

Use tlen for temporary length variable instead of l, which is usually
used for struct lwp *.

No binary changes.


# 1.82 02-Jul-2020 rin

pmap_procwr(): sync icache even if p != curproc. This fixes applications
like GDB for arm32, that rewrite text of other process.

Thanks to ryo@ for discussion.


# 1.81 02-Jul-2020 rin

Set uvmexp.ncolors appropriately, which is required for some CPU
models with VIPT icache.

Otherwise, alias in virtual address results in inconsistent results,
at least for applications that rewrite text of other process, e.g.,
GDB for arm32.

Also, this hopefully fixes other unexpected failures due to alias.

Confirmed that there's no observable regression in performance;
difference in ``time make -j8'' for GENERIC64 kernel on BCM2837
with and without setting uvmexp.ncolors is within 0.1%.

Thanks to ryo@ for discussion.


# 1.80 27-Jun-2020 rin

Fix typo in name of evcnt(4) counter.


# 1.79 24-Jun-2020 ryo

Fix bug with incorrect range calculation when doing icache sync.
This is called by sysarch(ARM_SYNC_ICACHE) from aarch32 (compat_netbsd32) emul process.

pointed out by rin@, thanks.

XXX pullup-9


# 1.78 14-Jun-2020 ad

- Fix a lock order reversal in pmap_page_protect().

- Make sure pmap is always locked when updating stats; atomics no longer
needed to do that.

- Remove unneeded traversal of pv list in pmap_enter_pv().

- Shrink struct vm_page from 136 to 128 bytes (cache line sized) and struct
pv_entry from 48 to 32 bytes (power of 2 sized).

- Embed a pv_entry in each vm_page. This means PV entries don't need to
be allocated for private anonymous memory / COW pages / most UBC mappings.
Dynamic PV entries are then used only for stuff like shared libraries and
shared memory.

Proposed on port-arm@.


# 1.77 10-Jun-2020 ad

- Wired/resident stats shouldn't covered by PMAPCOUNTERS.
- Rename need_update_pv -> need_enter_pv.

Ok ryo@


# 1.76 01-Jun-2020 ryo

no need to make the PTE writable to do icache_sync, enough to accessible.


# 1.75 15-May-2020 skrll

Use __diagused


# 1.74 15-May-2020 tnn

fix non-diag build


# 1.73 14-May-2020 skrll

Use MUTEX_NODEBUG for PV locks as is commonly done. OK ryo.


# 1.72 13-May-2020 jmcneill

Implement pmap_extract_coherency


Revision tags: bouyer-xenpvh-base2 phil-wifi-20200421 bouyer-xenpvh-base1
# 1.71 18-Apr-2020 skrll

PMAP_DEBUG has been deleted on arm


# 1.70 13-Apr-2020 maxv

Add support for Branch Target Identification (BTI).

On the executable pages that have the GP (Guarded Page) bit, the semantic
of the "br" and "blr" instructions is changed: the CPU expects the first
instruction of the jump/call target to be "bti", and faults if it isn't.

We add the GP bit on the kernel .text pages (and incidentally the .rodata
pages, but we don't care). The compiler adds a "bti c" instruction at the
beginning of each C function. We modify the ENTRY() macros to manually add
"bti c" in the asm functions.

cpuswitch.S needs a specific change: with "br x27" the CPU expects "bti j",
which is bad because the functions begin with "bti c"; switch to "br x16",
for the CPU to accept "bti c".

BTI helps defend against JOP/COP. Tested on Qemu.


Revision tags: phil-wifi-20200411 bouyer-xenpvh-base
# 1.69 08-Apr-2020 ryo

branches: 1.69.2;
use PMAP_PAGE_INIT() to initialize mutex in pmap_page.

VM_MDPAGE_INIT() in pmap_free_pdp() had initialized pp_flags,
so it unintentionally cleared PMAP_PAGE_FLAGS_PV_TRACKED.
use PMAP_PAGE_INIT to avoid using PMAP_PAGE_FLAGS_PV_TRACKED.

pointed out by tnn@, thanks


Revision tags: phil-wifi-20200406
# 1.68 14-Mar-2020 ad

pmap_remove_all(): Return a boolean value to indicate the behaviour. If
true, all mappings have been removed, the pmap is totally cleared out, and
UVM can then avoid doing the work to call pmap_remove() for each map entry.
If false, either nothing has been done, or some helpful arch-specific voodoo
has taken place.


Revision tags: is-mlppp-base
# 1.67 02-Mar-2020 ryo

oops, fix incorrect usage of daif_enable() in my previous commit.


# 1.66 29-Feb-2020 ryo

Fix pmap to work correctly with tagged addresses

- when fault, untag from address before passing to uvm/pmap functions
- pmap_extract() checks more strictly and consider the address tag


# 1.65 29-Feb-2020 ryo

use pmapboot_enter_range()


Revision tags: ad-namecache-base3
# 1.64 10-Feb-2020 ryo

use LIST(3) instead of TAILQ(3) to save one word in struct vm_page and struct pmap.

pointed out by riastradh@. thanks


# 1.63 03-Feb-2020 ryo

add support pmap_pv(9)

Patch originally from jmcneill@. thanks


# 1.62 03-Feb-2020 ryo

separate struct vm_page_md into vm_page_md and pmap_page
for preparation pmap_pv(9)


Revision tags: ad-namecache-base2 ad-namecache-base1
# 1.61 09-Jan-2020 ryo

fix behaviour mmap()/mprotect() when passed only PROT_EXEC.

when mmap()/mprotect() with only PROT_EXEC, syscall will be successful,
but the page actually hadn't been mapped.
it should be mapped with PROT_READ|PROT_EXEC implicitly. (r-x)


Revision tags: ad-namecache-base
# 1.60 30-Dec-2019 skrll

branches: 1.60.2;
Update pmap_map_chunk to allow L[12] block mappings and L3 page mappings


# 1.59 30-Dec-2019 skrll

Remove unnecessary brackets and unwrap a conditional. Same code before
and after.


# 1.58 28-Dec-2019 jmcneill

Do not use Early Write Acknowledge for PCIe I/O and config space.


# 1.57 27-Dec-2019 jmcneill

Enable early write acknowledge for device memory mappings.


# 1.56 19-Dec-2019 skrll

G/C kasan_shadow_map call in pmap_enter

pmap_growkernel calls kasan_shadow_map for KVA


# 1.55 18-Dec-2019 ryo

atomic_add_16() is not used in pmap.c anymore. no need decl here.


# 1.54 18-Dec-2019 ryo

space to tab


# 1.53 14-Dec-2019 skrll

Fix build... wire_count probably doesn't need atomics


# 1.52 13-Dec-2019 skrll

Fix KASAN support by calling kasan_shadow_map in pmap_growkernel


# 1.51 10-Dec-2019 ad

pg->phys_addr -> VM_PAGE_TO_PHYS(pg)


Revision tags: phil-wifi-20191119
# 1.50 14-Nov-2019 maxv

Mark several kASan functions with __nothing, to avoid annoying #ifdefs.
Same as kCSan and kMSan.


# 1.49 14-Nov-2019 maxv

Don't include "opt_kasan.h" when there's already <sys/asan.h> included.


# 1.48 29-Oct-2019 maya

Define PMAP_NEED_PROCWR, providing strategically placed i-cache
synchronization where just-changed memory is about to be executed.

Fixes SIGILLs seen when running Mono 6 on QEMU Cortex-A57.

ok ryo


# 1.47 22-Sep-2019 jmcneill

Disable translation table walks using TTBR0 while changing its value and
when deactivating a pmap. Fixes stability issues on Ampere eMAG CPUs.


# 1.46 20-Sep-2019 ryo

ref/mod bit should be set according to 'flags' argument, not 'prot'. r1.44 was incomplete.


# 1.45 13-Sep-2019 ryo

In pmap_devmap_bootstrap(), cpu_earlydevice_va_p() must not return true until *all* devmap tables have been enabled.
console mapping may be present in the last table.


# 1.44 07-Sep-2019 ryo

- remove incorrect KASSERT. mmap(2) with prot=PROT_WRITE calls pmap_enter(..., PROT_WRITE) internally.
- fix to update page reference flags when only PROT_WRITE or PROT_EXECUTE specified


# 1.43 15-Aug-2019 skrll

Make pmap_db_pte_print more terse so it's quicker on serial consoles


# 1.42 12-Aug-2019 skrll

Use PMAP_DEV in DEVMAP_ENTRY rather than pmap_map_chunk. It's clearer and
means pmap_map_chunk can be made to map other memory types.


Revision tags: netbsd-9-base phil-wifi-20190609
# 1.41 17-May-2019 mrg

branches: 1.41.2;
apply some __diagused.


Revision tags: isaki-audio2-base
# 1.40 08-Apr-2019 ryo

- free empty page tables pages if reach a certain usage.
- need to lock at removing an old pg (_pmap_remove_pv) in _pmap_enter()


# 1.39 06-Apr-2019 ryo

Fix race conditions about pmap_page_protect() and pmap_enter().

while handling same PTE by these functions in same time, there
is a critical path that the number of valid PTEs and wire_count
are inconsistent, and it caused KASSERT.
Need to hold a pv_lock while modifying them.


# 1.38 20-Mar-2019 ryo

spinkle __printflike(), and use PRIxxx


# 1.37 19-Mar-2019 ryo

- add ddb command "machine ttbr" to dump MMU tables.
- tidy up descriptions, usages and messages.


# 1.36 19-Mar-2019 ryo

- free L1-L3 pages that has been emptied by pmap_remove().
- if no memories, pmap_enter will return correctly ENOMEM if PMAP_CANFAIL, or wait until available any memories if !PMAP_CANFAIL.

These changes improves the stability when we use a huge virtual memory spaces with mmap.


# 1.35 06-Feb-2019 ryo

improve pmap_remove
- don't lock/unlock per page in pmap_remove()
- speedup pte lookup for continuous addresses
- bring out pool_cache_put(&_pmap_pv_pool, pv) from lock/unlock section


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226
# 1.34 21-Dec-2018 ryo

- add workaround for Cavium ThunderX errata 27456.
- add cpufuncs table in cpu_info. each cpu clusters may have different erratum. (e.g. big.LITTLE)


Revision tags: pgoyette-compat-1126
# 1.33 01-Nov-2018 maxv

Add kASan support for aarch64. Stack tracking needs more investigation
and will come in a separate commit.

Reviewed by ryo@ jmcneill@ skrll@.


# 1.32 31-Oct-2018 ryo

invalidate icache correctly.
l3pte_executable() should be used for only valid pte.


Revision tags: pgoyette-compat-1020
# 1.31 18-Oct-2018 skrll

Provide generic start code that assumes the MMU is off and caches are
disabled as per the linux booting protocol for ARMv6 and ARMv7 boards.
u-boot image type should be changed to 'linux' for correct behaviour.

The new start code builds a minimal "bootstrap" L1PT with cached access
disabled and uses the same table for all processors. AP startup is
performed in less steps and more code is written in C.

The bootstrap tables and stack are placed into an (orphaned) section
"_init_memory" which is given to uvm when it is no longer used.

Various kernels have been converted to use this code and tested. Some
boards were provided by TNF. Thanks!

The GENERIC kernel now boots on boards using the TEGRA, SUNXI and EXYNOS
kernels. The GENERIC kernel will also work on RPI2 using u-boot.

Thanks to martin@ and aymeric@ for testing on parallella and nanosoc
respectively


# 1.30 14-Oct-2018 skrll

Use __nothing


# 1.29 12-Oct-2018 ryo

add initial support of COMPAT_NETBSD32 on AArch64.
arm ELF32 EABI binaries could be execute in AArch32 state on AArch64. A32 THUMB mode is not supported yet.


# 1.28 12-Oct-2018 ryo

- cleanup checking address ranges with IN_RANGE macro
- change PM_ADDR_CHECK macro to KASSERTMSG
- restore fast lookup cases with IN_RANGE macro for pmap_extract changed in my previous commit.


# 1.27 12-Oct-2018 ryo

rewrite pmap_pte_lookup() to share similar code.


# 1.26 04-Oct-2018 ryo

cleanup locore, and changed the way to map memories during boot.
- add functions bootpage_enter() and bootpage_alloc() to adapt various layout
of physical memory map. especially for 64bit physical memory layout.
pmapboot_alloc() allocates pagetable pages from _end[].
- changed to map only the required amount for PA=VA identity mapping
(kernel image, UART device, and FDT blob) with L2_BLOCK(2Mbyte).
- changing page permission for kernel image, and making KSEG mapping are done
at cpu_kernel_vm_init() instead of at locore.
- optimize PTE entries with PTE Contiguous bit. it is enabled on devmap only for now.

reviewed by skrll@, thanks.


# 1.25 04-Oct-2018 ryo

* define LX_BLKPAG_{OS,ATTR}_* for OS dependent PTE attributes in pmap.h
* cleanup macros


Revision tags: pgoyette-compat-0930
# 1.24 17-Sep-2018 ryo

delete debug printf and KASSERT.


# 1.23 10-Sep-2018 maxv

Replace KDASSERT by panic.


# 1.22 10-Sep-2018 maxv

Rename _pmap_alloc_pdp -> pmap_alloc_pdp, and make it public.


# 1.21 10-Sep-2018 ryo

cleanup aarch64 mpstart and fdt bootstrap
* arm_cpu_hatch_arg is a bad idea. avoid serializing CPU startup, and eliminate arm_cpu_hatch_arg.
in mpstart, resolve own cpu index using array of cpu_mpidr[] (aarch64)
* add support fdt enable-method "spin-table"
* add support fdt enable-method "brcm,bcm2836-smp" (for 32bit RaspberryPi)
* use arm_fdt_cpu_bootstrap() instead of psci_fdt_bootstrap()
* rename "arm/fdt/psci_fdt.h" to "arm/fdt/psci_fdtvar.h" because of conflict of include file for needs-flag
* add devmap for cpu spin-table of raspberrypi3/aarch64
* no need to force hatch APs for raspberrypi3/arm32 ifndef MULTIPROCESSOR.
* fix to work pmap_extract(kerneltext/data/bss) even if before calling pmap_bootstrap

idea to use cpu_mpidr[] by jmcneill@. reviewd by skrll@. thanks.


Revision tags: pgoyette-compat-0906
# 1.20 27-Aug-2018 ryo

need to add VM_PROT_READ when pmap_kenter_pa(va, pa, VM_PROT_WRITE, 0) or pmap_kenter_pa(va, pa, VM_PROT_EXECUTE, 0).
VM_PROT_READ is treated as an access permission inernally.


# 1.19 11-Aug-2018 ryo

change to minimum invalidation of TLB.
specifying not only va but also asid, and not invalidate L0-L2 entry using tlbi_*_ll() if needed.


# 1.18 10-Aug-2018 ryo

treat kernel-exec attr and user-exec attr separately.
kernel cannot execute userland exec page, and user cannot execute kernel page.


# 1.17 06-Aug-2018 ryo

set kernel text/rodata readonly by default.
add function db_write_text() for setting ddb breakpoint.


# 1.16 31-Jul-2018 skrll

Define and use VPRINTF


Revision tags: pgoyette-compat-0728
# 1.15 27-Jul-2018 ryo

changes of pmap.c r1.13 seems to be unstable.
In order to invalidate icache, not to invalidate all icache,
but temporary to make the page writable and invalidate target address only.


# 1.14 24-Jul-2018 ryo

don't call pool_cache_put with locking pmap. pool_cache_put call pmap_kenter_pa internally.
(pool_cache_put_paddr -> pool_cache_put_slow -> pool_get -> pmap_kenter_pa)


# 1.13 23-Jul-2018 ryo

* fix icache invalidations.
* "ic ivau" (aarch64_icache_sync_range) with VA generates permission fault in some situations, therefore use KSEG address for now.


# 1.12 23-Jul-2018 ryo

rather than using flags to resolve nested locks, reserve pool_cache before locking.


# 1.11 21-Jul-2018 ryo

* avoid deadlock. mutex_owned() works only for adaptive lock, therefore we cannot use it for spinlock...
* add more NULL check
* clear pte when pmap_enter() fails


# 1.10 17-Jul-2018 ryo

Use __debugused


# 1.9 17-Jul-2018 christos

Add missing casts, remove unused variables.


# 1.8 09-Jul-2018 ryo

need locks in pmap_kremove() and pmap_fault_fixup()


Revision tags: phil-wifi-base pgoyette-compat-0625 pgoyette-compat-0521
# 1.7 20-May-2018 ryo

branches: 1.7.2;
pmap_enter() must update modified/referenced flags by 'flags' not 'prot'.


# 1.6 16-May-2018 ryo

Fix memory leak. it was leaking one page every pmap_create().
pm->pm_vmlist must be initialized before calling _pmap_alloc_pdp().


Revision tags: pgoyette-compat-0502
# 1.5 29-Apr-2018 ryo

fix KASSERT panic. pv_entry may not be exists in pvlist when pmap_remove().


# 1.4 29-Apr-2018 ryo

delete unused code


# 1.3 27-Apr-2018 ryo

fix instability behavior of bufcache on aarch64.
* fix to return correct ref/mod when PMAP_WIRED.
* changed to keep wired flags in pte instead of pv_entry, and cleanup.


Revision tags: pgoyette-compat-0422 pgoyette-compat-0415 pgoyette-compat-0407
# 1.2 01-Apr-2018 ryo

Add initial support for ARMv8 (AARCH64) (by nisimura@ and ryo@)

- sys/arch/evbarm64 is gone and integrated into sys/arch/evbarm. (by skrll@)
- add support fdt. evbarm/conf/GENERIC64 fdt (bcm2837,sunxi,tegra) based generic 64bit kernel config. (by skrll@, jmcneill@)


Revision tags: netbsd-8-2-RELEASE netbsd-8-1-RELEASE netbsd-8-1-RC1 netbsd-7-2-RELEASE netbsd-8-0-RELEASE netbsd-8-0-RC2 netbsd-8-0-RC1 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 netbsd-7-1-2-RELEASE pgoyette-compat-base netbsd-7-1-1-RELEASE tls-maxphys-base-20171202 matt-nb8-mediatek-base nick-nhusb-base-20170825 perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base pgoyette-localcount-20170320 netbsd-7-1-RELEASE netbsd-7-1-RC2 nick-nhusb-base-20170204 netbsd-7-nhusb-base-20170116 bouyer-socketcan-base pgoyette-localcount-20170107 netbsd-7-1-RC1 nick-nhusb-base-20161204 pgoyette-localcount-20161104 netbsd-7-0-2-RELEASE nick-nhusb-base-20161004 localcount-20160914 netbsd-7-nhusb-base pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907 nick-nhusb-base-20160529 netbsd-7-0-1-RELEASE nick-nhusb-base-20160422 nick-nhusb-base-20160319 nick-nhusb-base-20151226 netbsd-7-0-RELEASE nick-nhusb-base-20150921 netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 nick-nhusb-base-20150606 nick-nhusb-base-20150406 nick-nhusb-base tls-maxphys-base netbsd-7-base
# 1.1 10-Aug-2014 matt

branches: 1.1.4; 1.1.28;
Preliminary files for AARCH64 (64-bit ARM) support.
Enough for a distribution build.


# 1.131 19-Mar-2022 skrll

Slight code re-organisation. NFCI.


# 1.130 12-Mar-2022 riastradh

sys: Membar audit around reference count releases.

If two threads are using an object that is freed when the reference
count goes to zero, we need to ensure that all memory operations
related to the object happen before freeing the object.

Using an atomic_dec_uint_nv(&refcnt) == 0 ensures that only one
thread takes responsibility for freeing, but it's not enough to
ensure that the other thread's memory operations happen before the
freeing.

Consider:

Thread A Thread B
obj->foo = 42; obj->baz = 73;
mumble(&obj->bar); grumble(&obj->quux);
/* membar_exit(); */ /* membar_exit(); */
atomic_dec -- not last atomic_dec -- last
/* membar_enter(); */
KASSERT(invariant(obj->foo,
obj->bar));
free_stuff(obj);

The memory barriers ensure that

obj->foo = 42;
mumble(&obj->bar);

in thread A happens before

KASSERT(invariant(obj->foo, obj->bar));
free_stuff(obj);

in thread B. Without them, this ordering is not guaranteed.

So in general it is necessary to do

membar_exit();
if (atomic_dec_uint_nv(&obj->refcnt) != 0)
return;
membar_enter();

to release a reference, for the `last one out hit the lights' style
of reference counting. (This is in contrast to the style where one
thread blocks new references and then waits under a lock for existing
ones to drain with a condvar -- no membar needed thanks to mutex(9).)

I searched for atomic_dec to find all these. Obviously we ought to
have a better abstraction for this because there's so much copypasta.
This is a stop-gap measure to fix actual bugs until we have that. It
would be nice if an abstraction could gracefully handle the different
styles of reference counting in use -- some years ago I drafted an
API for this, but making it cover everything got a little out of hand
(particularly with struct vnode::v_usecount) and I ended up setting
it aside to work on psref/localcount instead for better scalability.

I got bored of adding #ifdef __HAVE_ATOMIC_AS_MEMBAR everywhere, so I
only put it on things that look performance-critical on 5sec review.
We should really adopt membar_enter_preatomic/membar_exit_postatomic
or something (except they are applicable only to atomic r/m/w, not to
atomic_load/store_*, making the naming annoying) and get rid of all
the ifdefs.


# 1.129 05-Mar-2022 skrll

Slight comment improvement.


# 1.128 16-Feb-2022 andvar

fix various typos, mainly in comments.


# 1.127 31-Jan-2022 ryo

add support Hardware updates to Access flag and Dirty state (FEAT_HAFDBS)

- The DBM bit of the PTE is now used to determine if it is writable, and
the AF bit is treated entirely as a reference bit. A valid PTE is always
treated as readable. There can be no valid PTE that is not readable.
- LX_BLKPAG_OS_{READ,WRITE} are used only for debugging purposes,
and has been superseded by LX_BLKPAG_AF and LX_BLKPAG_DBM.
- Improve comment

The need for reference/modify emulation has been eliminated,
and access/permission faults have been reduced, however,
there has been little change in overall performance.


# 1.126 31-Jan-2022 ryo

Skip unnecessary PTE operations and TLB invalidation.


# 1.125 16-Jan-2022 rillig

aarch64/pmap: remove stray semicolon

No binary change.


# 1.124 15-Jan-2022 skrll

The translations that need invalidation are always last level so remove
the (dubious) logic around tracking the level. The "any level" TLB
invalidation maintenance operation are used, but this may change after
further testing.

before
======
1661.0u 420.2s 2:53.82 1197.3% 231+29k 10+33918io 102pf+0w
1646.8u 425.2s 2:52.96 1198.0% 232+29k 1+33937io 49pf+0w
1647.9u 425.7s 2:52.58 1201.6% 232+29k 0+33940io 32pf+0w

After
=====
1602.5u 420.8s 2:49.09 1196.6% 238+30k 24+33893io 54pf+0w
1600.7u 421.3s 2:51.53 1178.8% 238+30k 1+33914io 33pf+0w
1597.5u 424.3s 2:50.46 1186.1% 238+30k 0+33915io 17pf+0w

LGTM from ryo@


# 1.123 14-Jan-2022 skrll

Restore the previous pmap_remove_all behaviour as the new method meant
the n1sdp couldn't complete a build.

No noticeable change in kernel build performance.


# 1.122 04-Jan-2022 skrll

KNF


# 1.121 10-Dec-2021 andvar

s/occured/occurred/ in comments, log messages and man pages.


# 1.120 07-Dec-2021 andvar

fix various typos, mainly in comments.


# 1.119 23-Oct-2021 skrll

Fix non-UVMHIST build


# 1.118 16-Oct-2021 ryo

fix non-MULTIPROCESSOR build


# 1.117 10-Oct-2021 skrll

Use sys/uvm/pmap/pmap_tlb.c on Aarch64 in the same way that some Arm, MIPS,
and some PPC kernels do. This removes the limitation of 256 processes on
CPUs with 8bit ASID field, e.g. Apple M1.

Additionally the following changes have been made

- removed a couple of unnecessary aarch64_tlbi_all calls
- removed any invalidation after freeing page tables due to
_pmap_sweep_pdp. This was never necessary afaict.
- all kernel mappings are marked global and userland mapping not-global.

Performance testing hasn't show a significant difference. The data here
is from building a kernel on an lx2k system with nvme.

before
1489.6u 400.4s 2:40.65 1176.5% 228+224k 0+32289io 57pf+0w
1482.6u 403.2s 2:38.49 1189.9% 228+222k 0+32274io 46pf+0w
1485.4u 402.2s 2:37.27 1200.2% 228+222k 0+32275io 12pf+0w

after
1493.9u 404.6s 2:37.50 1205.4% 227+221k 0+32265io 48pf+0w
1485.0u 408.0s 2:38.54 1194.0% 227+222k 0+32272io 36pf+0w
1484.3u 407.0s 2:35.88 1213.3% 228+224k 0+32268io 14pf+0w

>>> stats.ttest_ind([160.65,158.49,157.27], [157.5,158.54,155.88])
Ttest_indResult(statistic=1.1923622711296888, pvalue=0.2990182944606766)
>>>


# 1.116 30-Sep-2021 skrll

Ensure TCR_EPD0 is set on entry to pmap_activate and ensure it is set as
early as possible for APs.


# 1.115 26-Sep-2021 skrll

Use UVMHIST_CALLARGS


# 1.114 26-Sep-2021 skrll

'\n' is not required in KASSERTMSG either.


# 1.113 26-Sep-2021 skrll

"\n" is not required in KERNHIST


# 1.112 15-Sep-2021 skrll

Use __SHIFTIN. Same code before and after.


# 1.111 12-Sep-2021 skrll

pmap_page_remove: simply and reduce the code size slightly.


# 1.110 09-Sep-2021 skrll

In pmap_icache_sync_range change

for (...) {
...
if (condition) {
// do stuff
}
}

to

for (...) {
...
if (!conditional)
continue;
// do stuff
}

to save on indentation. Same code (modulo register usage) before and
after.


# 1.109 09-Sep-2021 skrll

KNF


Revision tags: thorpej-i2c-spi-conf2-base thorpej-futex2-base thorpej-cfargs2-base cjep_sun2x-base1 cjep_sun2x-base cjep_staticlib_x-base1 thorpej-i2c-spi-conf-base
# 1.108 29-May-2021 skrll

Deal with the pmap limitation of maxproc in a more complete way and
recognise CPUs with only 8bit ASIDs.


Revision tags: cjep_staticlib_x-base
# 1.107 30-Apr-2021 skrll

branches: 1.107.2;
Make the ddb for pmap / pte information pmap agnostic


# 1.106 29-Apr-2021 skrll

Remove some unnecessary tlb invalidate in pmap_growkernel and ASAN shadow
map. Ensure the shadow map mappings are visible to the TLB walkers.


# 1.105 21-Apr-2021 ryo

branches: 1.105.2;
added more attributes of PTE displayed by "ddb>machine pte"


Revision tags: thorpej-cfargs-base
# 1.104 17-Apr-2021 mrg

remove KERNHIST_INIT_STATIC(). it stradles the line between usable
early in boot and broken early in boot by requiring a partly static
structure with another structure that must be present by the time
any uses are performed. theoretically platform code could allocate
a chunk while seting up memory and assign it here, giving a dynamic
sizing for the entry list, but the reality is that all users have
a statically allocated entry list as well.

the existing KERNHIST_LINK_STATIC() is used in conjunction with
KERNHIST_INITIALIZER() instead.

this stops a NULL pointer deref when the _LOG() macro is called
before the storage is linked in, which happens with GCC 10 on OCTEON
with UVMHIST enabled, crashing in very early kernel init.


Revision tags: thorpej-futex-base
# 1.103 09-Mar-2021 ryo

branches: 1.103.2;
fix build error without options DDB.

kvtopte() is referenced from arm/acpi/acpi_machdep.c


# 1.102 13-Feb-2021 ryo

No assignment is needed here.

the loop in pmap_page_remove() always removes the first pv,
and since the list is managed by _pmap_remove_pv(), pp->pp_pv.pv_next always points to the first.


# 1.101 01-Feb-2021 ryo

It is enough to make a page accessible instead of writable.
same fix as r1.76


# 1.100 31-Jan-2021 ryo

implement pmap_remove_all().

The size of struct pv_entry has increased, but speed of kernel build has improved by about 1%
exec and exit should have been improved.


# 1.99 20-Dec-2020 skrll

Improve the English in the previous comment fix.


# 1.98 19-Dec-2020 skrll

Tweak a comment


# 1.97 11-Dec-2020 skrll

s:aarch64/cpufunc.h:arm/cpufunc.h:

a baby step in the grand arm header unification challenge


# 1.96 10-Nov-2020 skrll

AA64 is not MIPS.

Change all KSEG references to directmap


# 1.95 07-Nov-2020 skrll

In pmap_devmap_bootstrap only set pmap_devmap_bootstrap_done if there
is an entry and ALL of the entries have been done. The entry required
for EARLYCONS might not be the first/only one...


# 1.94 01-Nov-2020 jmcneill

branches: 1.94.2;
No need to disable translation table walks in pmap_activate().


# 1.93 22-Oct-2020 skrll

Use the isb macro - missed in previous commit


# 1.92 22-Oct-2020 skrll

Use the dmb/dsb/isb macros... if nothing else they're all now consistent
about the "memory" assembler contraint.

No binary change


# 1.91 28-Sep-2020 skrll

Only set pmap_devmap_bootstrap_done if something gets mapped.

Think acpi_platform_devmap


# 1.90 19-Sep-2020 skrll

Make __md_palloc pmap agnostic (think sys/uvm/pmap)


# 1.89 14-Sep-2020 ryo

PID_MAX is just an initial value (soft maximum). Don't use it for CTASSERT.
defined __HAVE_CPU_MAXPROC to use function cpu_maxproc().

pointed out by mrg@, thanks.


# 1.88 06-Sep-2020 ryo

Fix panic caused by modload. http://mail-index.netbsd.org/port-arm/2020/08/30/msg006960.html

The address space reserved for modules may not be mapped in L1-L3.


# 1.87 14-Aug-2020 skrll

Whitespace


# 1.86 12-Aug-2020 skrll

Part IV of ad's performance improvements for aarch64

- Implement pmap_growkernel(), and update kernel pmap's stats with atomics.

- Then, pmap_kenter_pa() and pmap_kremove() no longer need to allocate
memory nor take pm_lock, because they only modify L3 PTEs.

- Then, pm_lock and pp_lock can be adaptive mutexes at IPL_NONE which are
cheaper than spin mutexes.

- Take the pmap's lock in pmap_extract() if not the kernel's pmap, otherwise
pmap_extract() might see inconsistent state.


# 1.85 09-Aug-2020 skrll

Fix another UVMHIST so it doesn't use %s


# 1.84 16-Jul-2020 skrll

pmapboot_enter simplication
- bootpage_alloc in asm becomes pmapboot_pagealloc in C
- PMAPBOOT_ENTER_NOBLOCK is removed as it's not used
- PMAPBOOT_ENTER_NOOVERWRITE is removed as it's now always on
- physpage_allocator argument is removed as it's always
pmapboot_pagealloc
- Support for EARLYCONS without CONSADDR is removed so that the identity
map for CONSADDR is always known.

For the assembly files:
2 files changed, 40 insertions(+), 89 deletions(-)

LGTM ryo


# 1.83 04-Jul-2020 rin

Use tlen for temporary length variable instead of l, which is usually
used for struct lwp *.

No binary changes.


# 1.82 02-Jul-2020 rin

pmap_procwr(): sync icache even if p != curproc. This fixes applications
like GDB for arm32, that rewrite text of other process.

Thanks to ryo@ for discussion.


# 1.81 02-Jul-2020 rin

Set uvmexp.ncolors appropriately, which is required for some CPU
models with VIPT icache.

Otherwise, alias in virtual address results in inconsistent results,
at least for applications that rewrite text of other process, e.g.,
GDB for arm32.

Also, this hopefully fixes other unexpected failures due to alias.

Confirmed that there's no observable regression in performance;
difference in ``time make -j8'' for GENERIC64 kernel on BCM2837
with and without setting uvmexp.ncolors is within 0.1%.

Thanks to ryo@ for discussion.


# 1.80 27-Jun-2020 rin

Fix typo in name of evcnt(4) counter.


# 1.79 24-Jun-2020 ryo

Fix bug with incorrect range calculation when doing icache sync.
This is called by sysarch(ARM_SYNC_ICACHE) from aarch32 (compat_netbsd32) emul process.

pointed out by rin@, thanks.

XXX pullup-9


# 1.78 14-Jun-2020 ad

- Fix a lock order reversal in pmap_page_protect().

- Make sure pmap is always locked when updating stats; atomics no longer
needed to do that.

- Remove unneeded traversal of pv list in pmap_enter_pv().

- Shrink struct vm_page from 136 to 128 bytes (cache line sized) and struct
pv_entry from 48 to 32 bytes (power of 2 sized).

- Embed a pv_entry in each vm_page. This means PV entries don't need to
be allocated for private anonymous memory / COW pages / most UBC mappings.
Dynamic PV entries are then used only for stuff like shared libraries and
shared memory.

Proposed on port-arm@.


# 1.77 10-Jun-2020 ad

- Wired/resident stats shouldn't covered by PMAPCOUNTERS.
- Rename need_update_pv -> need_enter_pv.

Ok ryo@


# 1.76 01-Jun-2020 ryo

no need to make the PTE writable to do icache_sync, enough to accessible.


# 1.75 15-May-2020 skrll

Use __diagused


# 1.74 15-May-2020 tnn

fix non-diag build


# 1.73 14-May-2020 skrll

Use MUTEX_NODEBUG for PV locks as is commonly done. OK ryo.


# 1.72 13-May-2020 jmcneill

Implement pmap_extract_coherency


Revision tags: bouyer-xenpvh-base2 phil-wifi-20200421 bouyer-xenpvh-base1
# 1.71 18-Apr-2020 skrll

PMAP_DEBUG has been deleted on arm


# 1.70 13-Apr-2020 maxv

Add support for Branch Target Identification (BTI).

On the executable pages that have the GP (Guarded Page) bit, the semantic
of the "br" and "blr" instructions is changed: the CPU expects the first
instruction of the jump/call target to be "bti", and faults if it isn't.

We add the GP bit on the kernel .text pages (and incidentally the .rodata
pages, but we don't care). The compiler adds a "bti c" instruction at the
beginning of each C function. We modify the ENTRY() macros to manually add
"bti c" in the asm functions.

cpuswitch.S needs a specific change: with "br x27" the CPU expects "bti j",
which is bad because the functions begin with "bti c"; switch to "br x16",
for the CPU to accept "bti c".

BTI helps defend against JOP/COP. Tested on Qemu.


Revision tags: phil-wifi-20200411 bouyer-xenpvh-base
# 1.69 08-Apr-2020 ryo

branches: 1.69.2;
use PMAP_PAGE_INIT() to initialize mutex in pmap_page.

VM_MDPAGE_INIT() in pmap_free_pdp() had initialized pp_flags,
so it unintentionally cleared PMAP_PAGE_FLAGS_PV_TRACKED.
use PMAP_PAGE_INIT to avoid using PMAP_PAGE_FLAGS_PV_TRACKED.

pointed out by tnn@, thanks


Revision tags: phil-wifi-20200406
# 1.68 14-Mar-2020 ad

pmap_remove_all(): Return a boolean value to indicate the behaviour. If
true, all mappings have been removed, the pmap is totally cleared out, and
UVM can then avoid doing the work to call pmap_remove() for each map entry.
If false, either nothing has been done, or some helpful arch-specific voodoo
has taken place.


Revision tags: is-mlppp-base
# 1.67 02-Mar-2020 ryo

oops, fix incorrect usage of daif_enable() in my previous commit.


# 1.66 29-Feb-2020 ryo

Fix pmap to work correctly with tagged addresses

- when fault, untag from address before passing to uvm/pmap functions
- pmap_extract() checks more strictly and consider the address tag


# 1.65 29-Feb-2020 ryo

use pmapboot_enter_range()


Revision tags: ad-namecache-base3
# 1.64 10-Feb-2020 ryo

use LIST(3) instead of TAILQ(3) to save one word in struct vm_page and struct pmap.

pointed out by riastradh@. thanks


# 1.63 03-Feb-2020 ryo

add support pmap_pv(9)

Patch originally from jmcneill@. thanks


# 1.62 03-Feb-2020 ryo

separate struct vm_page_md into vm_page_md and pmap_page
for preparation pmap_pv(9)


Revision tags: ad-namecache-base2 ad-namecache-base1
# 1.61 09-Jan-2020 ryo

fix behaviour mmap()/mprotect() when passed only PROT_EXEC.

when mmap()/mprotect() with only PROT_EXEC, syscall will be successful,
but the page actually hadn't been mapped.
it should be mapped with PROT_READ|PROT_EXEC implicitly. (r-x)


Revision tags: ad-namecache-base
# 1.60 30-Dec-2019 skrll

branches: 1.60.2;
Update pmap_map_chunk to allow L[12] block mappings and L3 page mappings


# 1.59 30-Dec-2019 skrll

Remove unnecessary brackets and unwrap a conditional. Same code before
and after.


# 1.58 28-Dec-2019 jmcneill

Do not use Early Write Acknowledge for PCIe I/O and config space.


# 1.57 27-Dec-2019 jmcneill

Enable early write acknowledge for device memory mappings.


# 1.56 19-Dec-2019 skrll

G/C kasan_shadow_map call in pmap_enter

pmap_growkernel calls kasan_shadow_map for KVA


# 1.55 18-Dec-2019 ryo

atomic_add_16() is not used in pmap.c anymore. no need decl here.


# 1.54 18-Dec-2019 ryo

space to tab


# 1.53 14-Dec-2019 skrll

Fix build... wire_count probably doesn't need atomics


# 1.52 13-Dec-2019 skrll

Fix KASAN support by calling kasan_shadow_map in pmap_growkernel


# 1.51 10-Dec-2019 ad

pg->phys_addr -> VM_PAGE_TO_PHYS(pg)


Revision tags: phil-wifi-20191119
# 1.50 14-Nov-2019 maxv

Mark several kASan functions with __nothing, to avoid annoying #ifdefs.
Same as kCSan and kMSan.


# 1.49 14-Nov-2019 maxv

Don't include "opt_kasan.h" when there's already <sys/asan.h> included.


# 1.48 29-Oct-2019 maya

Define PMAP_NEED_PROCWR, providing strategically placed i-cache
synchronization where just-changed memory is about to be executed.

Fixes SIGILLs seen when running Mono 6 on QEMU Cortex-A57.

ok ryo


# 1.47 22-Sep-2019 jmcneill

Disable translation table walks using TTBR0 while changing its value and
when deactivating a pmap. Fixes stability issues on Ampere eMAG CPUs.


# 1.46 20-Sep-2019 ryo

ref/mod bit should be set according to 'flags' argument, not 'prot'. r1.44 was incomplete.


# 1.45 13-Sep-2019 ryo

In pmap_devmap_bootstrap(), cpu_earlydevice_va_p() must not return true until *all* devmap tables have been enabled.
console mapping may be present in the last table.


# 1.44 07-Sep-2019 ryo

- remove incorrect KASSERT. mmap(2) with prot=PROT_WRITE calls pmap_enter(..., PROT_WRITE) internally.
- fix to update page reference flags when only PROT_WRITE or PROT_EXECUTE specified


# 1.43 15-Aug-2019 skrll

Make pmap_db_pte_print more terse so it's quicker on serial consoles


# 1.42 12-Aug-2019 skrll

Use PMAP_DEV in DEVMAP_ENTRY rather than pmap_map_chunk. It's clearer and
means pmap_map_chunk can be made to map other memory types.


Revision tags: netbsd-9-base phil-wifi-20190609
# 1.41 17-May-2019 mrg

branches: 1.41.2;
apply some __diagused.


Revision tags: isaki-audio2-base
# 1.40 08-Apr-2019 ryo

- free empty page tables pages if reach a certain usage.
- need to lock at removing an old pg (_pmap_remove_pv) in _pmap_enter()


# 1.39 06-Apr-2019 ryo

Fix race conditions about pmap_page_protect() and pmap_enter().

while handling same PTE by these functions in same time, there
is a critical path that the number of valid PTEs and wire_count
are inconsistent, and it caused KASSERT.
Need to hold a pv_lock while modifying them.


# 1.38 20-Mar-2019 ryo

spinkle __printflike(), and use PRIxxx


# 1.37 19-Mar-2019 ryo

- add ddb command "machine ttbr" to dump MMU tables.
- tidy up descriptions, usages and messages.


# 1.36 19-Mar-2019 ryo

- free L1-L3 pages that has been emptied by pmap_remove().
- if no memories, pmap_enter will return correctly ENOMEM if PMAP_CANFAIL, or wait until available any memories if !PMAP_CANFAIL.

These changes improves the stability when we use a huge virtual memory spaces with mmap.


# 1.35 06-Feb-2019 ryo

improve pmap_remove
- don't lock/unlock per page in pmap_remove()
- speedup pte lookup for continuous addresses
- bring out pool_cache_put(&_pmap_pv_pool, pv) from lock/unlock section


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226
# 1.34 21-Dec-2018 ryo

- add workaround for Cavium ThunderX errata 27456.
- add cpufuncs table in cpu_info. each cpu clusters may have different erratum. (e.g. big.LITTLE)


Revision tags: pgoyette-compat-1126
# 1.33 01-Nov-2018 maxv

Add kASan support for aarch64. Stack tracking needs more investigation
and will come in a separate commit.

Reviewed by ryo@ jmcneill@ skrll@.


# 1.32 31-Oct-2018 ryo

invalidate icache correctly.
l3pte_executable() should be used for only valid pte.


Revision tags: pgoyette-compat-1020
# 1.31 18-Oct-2018 skrll

Provide generic start code that assumes the MMU is off and caches are
disabled as per the linux booting protocol for ARMv6 and ARMv7 boards.
u-boot image type should be changed to 'linux' for correct behaviour.

The new start code builds a minimal "bootstrap" L1PT with cached access
disabled and uses the same table for all processors. AP startup is
performed in less steps and more code is written in C.

The bootstrap tables and stack are placed into an (orphaned) section
"_init_memory" which is given to uvm when it is no longer used.

Various kernels have been converted to use this code and tested. Some
boards were provided by TNF. Thanks!

The GENERIC kernel now boots on boards using the TEGRA, SUNXI and EXYNOS
kernels. The GENERIC kernel will also work on RPI2 using u-boot.

Thanks to martin@ and aymeric@ for testing on parallella and nanosoc
respectively


# 1.30 14-Oct-2018 skrll

Use __nothing


# 1.29 12-Oct-2018 ryo

add initial support of COMPAT_NETBSD32 on AArch64.
arm ELF32 EABI binaries could be execute in AArch32 state on AArch64. A32 THUMB mode is not supported yet.


# 1.28 12-Oct-2018 ryo

- cleanup checking address ranges with IN_RANGE macro
- change PM_ADDR_CHECK macro to KASSERTMSG
- restore fast lookup cases with IN_RANGE macro for pmap_extract changed in my previous commit.


# 1.27 12-Oct-2018 ryo

rewrite pmap_pte_lookup() to share similar code.


# 1.26 04-Oct-2018 ryo

cleanup locore, and changed the way to map memories during boot.
- add functions bootpage_enter() and bootpage_alloc() to adapt various layout
of physical memory map. especially for 64bit physical memory layout.
pmapboot_alloc() allocates pagetable pages from _end[].
- changed to map only the required amount for PA=VA identity mapping
(kernel image, UART device, and FDT blob) with L2_BLOCK(2Mbyte).
- changing page permission for kernel image, and making KSEG mapping are done
at cpu_kernel_vm_init() instead of at locore.
- optimize PTE entries with PTE Contiguous bit. it is enabled on devmap only for now.

reviewed by skrll@, thanks.


# 1.25 04-Oct-2018 ryo

* define LX_BLKPAG_{OS,ATTR}_* for OS dependent PTE attributes in pmap.h
* cleanup macros


Revision tags: pgoyette-compat-0930
# 1.24 17-Sep-2018 ryo

delete debug printf and KASSERT.


# 1.23 10-Sep-2018 maxv

Replace KDASSERT by panic.


# 1.22 10-Sep-2018 maxv

Rename _pmap_alloc_pdp -> pmap_alloc_pdp, and make it public.


# 1.21 10-Sep-2018 ryo

cleanup aarch64 mpstart and fdt bootstrap
* arm_cpu_hatch_arg is a bad idea. avoid serializing CPU startup, and eliminate arm_cpu_hatch_arg.
in mpstart, resolve own cpu index using array of cpu_mpidr[] (aarch64)
* add support fdt enable-method "spin-table"
* add support fdt enable-method "brcm,bcm2836-smp" (for 32bit RaspberryPi)
* use arm_fdt_cpu_bootstrap() instead of psci_fdt_bootstrap()
* rename "arm/fdt/psci_fdt.h" to "arm/fdt/psci_fdtvar.h" because of conflict of include file for needs-flag
* add devmap for cpu spin-table of raspberrypi3/aarch64
* no need to force hatch APs for raspberrypi3/arm32 ifndef MULTIPROCESSOR.
* fix to work pmap_extract(kerneltext/data/bss) even if before calling pmap_bootstrap

idea to use cpu_mpidr[] by jmcneill@. reviewd by skrll@. thanks.


Revision tags: pgoyette-compat-0906
# 1.20 27-Aug-2018 ryo

need to add VM_PROT_READ when pmap_kenter_pa(va, pa, VM_PROT_WRITE, 0) or pmap_kenter_pa(va, pa, VM_PROT_EXECUTE, 0).
VM_PROT_READ is treated as an access permission inernally.


# 1.19 11-Aug-2018 ryo

change to minimum invalidation of TLB.
specifying not only va but also asid, and not invalidate L0-L2 entry using tlbi_*_ll() if needed.


# 1.18 10-Aug-2018 ryo

treat kernel-exec attr and user-exec attr separately.
kernel cannot execute userland exec page, and user cannot execute kernel page.


# 1.17 06-Aug-2018 ryo

set kernel text/rodata readonly by default.
add function db_write_text() for setting ddb breakpoint.


# 1.16 31-Jul-2018 skrll

Define and use VPRINTF


Revision tags: pgoyette-compat-0728
# 1.15 27-Jul-2018 ryo

changes of pmap.c r1.13 seems to be unstable.
In order to invalidate icache, not to invalidate all icache,
but temporary to make the page writable and invalidate target address only.


# 1.14 24-Jul-2018 ryo

don't call pool_cache_put with locking pmap. pool_cache_put call pmap_kenter_pa internally.
(pool_cache_put_paddr -> pool_cache_put_slow -> pool_get -> pmap_kenter_pa)


# 1.13 23-Jul-2018 ryo

* fix icache invalidations.
* "ic ivau" (aarch64_icache_sync_range) with VA generates permission fault in some situations, therefore use KSEG address for now.


# 1.12 23-Jul-2018 ryo

rather than using flags to resolve nested locks, reserve pool_cache before locking.


# 1.11 21-Jul-2018 ryo

* avoid deadlock. mutex_owned() works only for adaptive lock, therefore we cannot use it for spinlock...
* add more NULL check
* clear pte when pmap_enter() fails


# 1.10 17-Jul-2018 ryo

Use __debugused


# 1.9 17-Jul-2018 christos

Add missing casts, remove unused variables.


# 1.8 09-Jul-2018 ryo

need locks in pmap_kremove() and pmap_fault_fixup()


Revision tags: phil-wifi-base pgoyette-compat-0625 pgoyette-compat-0521
# 1.7 20-May-2018 ryo

branches: 1.7.2;
pmap_enter() must update modified/referenced flags by 'flags' not 'prot'.


# 1.6 16-May-2018 ryo

Fix memory leak. it was leaking one page every pmap_create().
pm->pm_vmlist must be initialized before calling _pmap_alloc_pdp().


Revision tags: pgoyette-compat-0502
# 1.5 29-Apr-2018 ryo

fix KASSERT panic. pv_entry may not be exists in pvlist when pmap_remove().


# 1.4 29-Apr-2018 ryo

delete unused code


# 1.3 27-Apr-2018 ryo

fix instability behavior of bufcache on aarch64.
* fix to return correct ref/mod when PMAP_WIRED.
* changed to keep wired flags in pte instead of pv_entry, and cleanup.


Revision tags: pgoyette-compat-0422 pgoyette-compat-0415 pgoyette-compat-0407
# 1.2 01-Apr-2018 ryo

Add initial support for ARMv8 (AARCH64) (by nisimura@ and ryo@)

- sys/arch/evbarm64 is gone and integrated into sys/arch/evbarm. (by skrll@)
- add support fdt. evbarm/conf/GENERIC64 fdt (bcm2837,sunxi,tegra) based generic 64bit kernel config. (by skrll@, jmcneill@)


Revision tags: netbsd-8-2-RELEASE netbsd-8-1-RELEASE netbsd-8-1-RC1 netbsd-7-2-RELEASE netbsd-8-0-RELEASE netbsd-8-0-RC2 netbsd-8-0-RC1 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 netbsd-7-1-2-RELEASE pgoyette-compat-base netbsd-7-1-1-RELEASE tls-maxphys-base-20171202 matt-nb8-mediatek-base nick-nhusb-base-20170825 perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base pgoyette-localcount-20170320 netbsd-7-1-RELEASE netbsd-7-1-RC2 nick-nhusb-base-20170204 netbsd-7-nhusb-base-20170116 bouyer-socketcan-base pgoyette-localcount-20170107 netbsd-7-1-RC1 nick-nhusb-base-20161204 pgoyette-localcount-20161104 netbsd-7-0-2-RELEASE nick-nhusb-base-20161004 localcount-20160914 netbsd-7-nhusb-base pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907 nick-nhusb-base-20160529 netbsd-7-0-1-RELEASE nick-nhusb-base-20160422 nick-nhusb-base-20160319 nick-nhusb-base-20151226 netbsd-7-0-RELEASE nick-nhusb-base-20150921 netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 nick-nhusb-base-20150606 nick-nhusb-base-20150406 nick-nhusb-base tls-maxphys-base netbsd-7-base
# 1.1 10-Aug-2014 matt

branches: 1.1.4; 1.1.28;
Preliminary files for AARCH64 (64-bit ARM) support.
Enough for a distribution build.


# 1.130 12-Mar-2022 riastradh

sys: Membar audit around reference count releases.

If two threads are using an object that is freed when the reference
count goes to zero, we need to ensure that all memory operations
related to the object happen before freeing the object.

Using an atomic_dec_uint_nv(&refcnt) == 0 ensures that only one
thread takes responsibility for freeing, but it's not enough to
ensure that the other thread's memory operations happen before the
freeing.

Consider:

Thread A Thread B
obj->foo = 42; obj->baz = 73;
mumble(&obj->bar); grumble(&obj->quux);
/* membar_exit(); */ /* membar_exit(); */
atomic_dec -- not last atomic_dec -- last
/* membar_enter(); */
KASSERT(invariant(obj->foo,
obj->bar));
free_stuff(obj);

The memory barriers ensure that

obj->foo = 42;
mumble(&obj->bar);

in thread A happens before

KASSERT(invariant(obj->foo, obj->bar));
free_stuff(obj);

in thread B. Without them, this ordering is not guaranteed.

So in general it is necessary to do

membar_exit();
if (atomic_dec_uint_nv(&obj->refcnt) != 0)
return;
membar_enter();

to release a reference, for the `last one out hit the lights' style
of reference counting. (This is in contrast to the style where one
thread blocks new references and then waits under a lock for existing
ones to drain with a condvar -- no membar needed thanks to mutex(9).)

I searched for atomic_dec to find all these. Obviously we ought to
have a better abstraction for this because there's so much copypasta.
This is a stop-gap measure to fix actual bugs until we have that. It
would be nice if an abstraction could gracefully handle the different
styles of reference counting in use -- some years ago I drafted an
API for this, but making it cover everything got a little out of hand
(particularly with struct vnode::v_usecount) and I ended up setting
it aside to work on psref/localcount instead for better scalability.

I got bored of adding #ifdef __HAVE_ATOMIC_AS_MEMBAR everywhere, so I
only put it on things that look performance-critical on 5sec review.
We should really adopt membar_enter_preatomic/membar_exit_postatomic
or something (except they are applicable only to atomic r/m/w, not to
atomic_load/store_*, making the naming annoying) and get rid of all
the ifdefs.


# 1.129 05-Mar-2022 skrll

Slight comment improvement.


# 1.128 16-Feb-2022 andvar

fix various typos, mainly in comments.


# 1.127 31-Jan-2022 ryo

add support Hardware updates to Access flag and Dirty state (FEAT_HAFDBS)

- The DBM bit of the PTE is now used to determine if it is writable, and
the AF bit is treated entirely as a reference bit. A valid PTE is always
treated as readable. There can be no valid PTE that is not readable.
- LX_BLKPAG_OS_{READ,WRITE} are used only for debugging purposes,
and has been superseded by LX_BLKPAG_AF and LX_BLKPAG_DBM.
- Improve comment

The need for reference/modify emulation has been eliminated,
and access/permission faults have been reduced, however,
there has been little change in overall performance.


# 1.126 31-Jan-2022 ryo

Skip unnecessary PTE operations and TLB invalidation.


# 1.125 16-Jan-2022 rillig

aarch64/pmap: remove stray semicolon

No binary change.


# 1.124 15-Jan-2022 skrll

The translations that need invalidation are always last level so remove
the (dubious) logic around tracking the level. The "any level" TLB
invalidation maintenance operation are used, but this may change after
further testing.

before
======
1661.0u 420.2s 2:53.82 1197.3% 231+29k 10+33918io 102pf+0w
1646.8u 425.2s 2:52.96 1198.0% 232+29k 1+33937io 49pf+0w
1647.9u 425.7s 2:52.58 1201.6% 232+29k 0+33940io 32pf+0w

After
=====
1602.5u 420.8s 2:49.09 1196.6% 238+30k 24+33893io 54pf+0w
1600.7u 421.3s 2:51.53 1178.8% 238+30k 1+33914io 33pf+0w
1597.5u 424.3s 2:50.46 1186.1% 238+30k 0+33915io 17pf+0w

LGTM from ryo@


# 1.123 14-Jan-2022 skrll

Restore the previous pmap_remove_all behaviour as the new method meant
the n1sdp couldn't complete a build.

No noticeable change in kernel build performance.


# 1.122 04-Jan-2022 skrll

KNF


# 1.121 10-Dec-2021 andvar

s/occured/occurred/ in comments, log messages and man pages.


# 1.120 07-Dec-2021 andvar

fix various typos, mainly in comments.


# 1.119 23-Oct-2021 skrll

Fix non-UVMHIST build


# 1.118 16-Oct-2021 ryo

fix non-MULTIPROCESSOR build


# 1.117 10-Oct-2021 skrll

Use sys/uvm/pmap/pmap_tlb.c on Aarch64 in the same way that some Arm, MIPS,
and some PPC kernels do. This removes the limitation of 256 processes on
CPUs with 8bit ASID field, e.g. Apple M1.

Additionally the following changes have been made

- removed a couple of unnecessary aarch64_tlbi_all calls
- removed any invalidation after freeing page tables due to
_pmap_sweep_pdp. This was never necessary afaict.
- all kernel mappings are marked global and userland mapping not-global.

Performance testing hasn't show a significant difference. The data here
is from building a kernel on an lx2k system with nvme.

before
1489.6u 400.4s 2:40.65 1176.5% 228+224k 0+32289io 57pf+0w
1482.6u 403.2s 2:38.49 1189.9% 228+222k 0+32274io 46pf+0w
1485.4u 402.2s 2:37.27 1200.2% 228+222k 0+32275io 12pf+0w

after
1493.9u 404.6s 2:37.50 1205.4% 227+221k 0+32265io 48pf+0w
1485.0u 408.0s 2:38.54 1194.0% 227+222k 0+32272io 36pf+0w
1484.3u 407.0s 2:35.88 1213.3% 228+224k 0+32268io 14pf+0w

>>> stats.ttest_ind([160.65,158.49,157.27], [157.5,158.54,155.88])
Ttest_indResult(statistic=1.1923622711296888, pvalue=0.2990182944606766)
>>>


# 1.116 30-Sep-2021 skrll

Ensure TCR_EPD0 is set on entry to pmap_activate and ensure it is set as
early as possible for APs.


# 1.115 26-Sep-2021 skrll

Use UVMHIST_CALLARGS


# 1.114 26-Sep-2021 skrll

'\n' is not required in KASSERTMSG either.


# 1.113 26-Sep-2021 skrll

"\n" is not required in KERNHIST


# 1.112 15-Sep-2021 skrll

Use __SHIFTIN. Same code before and after.


# 1.111 12-Sep-2021 skrll

pmap_page_remove: simply and reduce the code size slightly.


# 1.110 09-Sep-2021 skrll

In pmap_icache_sync_range change

for (...) {
...
if (condition) {
// do stuff
}
}

to

for (...) {
...
if (!conditional)
continue;
// do stuff
}

to save on indentation. Same code (modulo register usage) before and
after.


# 1.109 09-Sep-2021 skrll

KNF


Revision tags: thorpej-i2c-spi-conf2-base thorpej-futex2-base thorpej-cfargs2-base cjep_sun2x-base1 cjep_sun2x-base cjep_staticlib_x-base1 thorpej-i2c-spi-conf-base
# 1.108 29-May-2021 skrll

Deal with the pmap limitation of maxproc in a more complete way and
recognise CPUs with only 8bit ASIDs.


Revision tags: cjep_staticlib_x-base
# 1.107 30-Apr-2021 skrll

branches: 1.107.2;
Make the ddb for pmap / pte information pmap agnostic


# 1.106 29-Apr-2021 skrll

Remove some unnecessary tlb invalidate in pmap_growkernel and ASAN shadow
map. Ensure the shadow map mappings are visible to the TLB walkers.


# 1.105 21-Apr-2021 ryo

branches: 1.105.2;
added more attributes of PTE displayed by "ddb>machine pte"


Revision tags: thorpej-cfargs-base
# 1.104 17-Apr-2021 mrg

remove KERNHIST_INIT_STATIC(). it stradles the line between usable
early in boot and broken early in boot by requiring a partly static
structure with another structure that must be present by the time
any uses are performed. theoretically platform code could allocate
a chunk while seting up memory and assign it here, giving a dynamic
sizing for the entry list, but the reality is that all users have
a statically allocated entry list as well.

the existing KERNHIST_LINK_STATIC() is used in conjunction with
KERNHIST_INITIALIZER() instead.

this stops a NULL pointer deref when the _LOG() macro is called
before the storage is linked in, which happens with GCC 10 on OCTEON
with UVMHIST enabled, crashing in very early kernel init.


Revision tags: thorpej-futex-base
# 1.103 09-Mar-2021 ryo

branches: 1.103.2;
fix build error without options DDB.

kvtopte() is referenced from arm/acpi/acpi_machdep.c


# 1.102 13-Feb-2021 ryo

No assignment is needed here.

the loop in pmap_page_remove() always removes the first pv,
and since the list is managed by _pmap_remove_pv(), pp->pp_pv.pv_next always points to the first.


# 1.101 01-Feb-2021 ryo

It is enough to make a page accessible instead of writable.
same fix as r1.76


# 1.100 31-Jan-2021 ryo

implement pmap_remove_all().

The size of struct pv_entry has increased, but speed of kernel build has improved by about 1%
exec and exit should have been improved.


# 1.99 20-Dec-2020 skrll

Improve the English in the previous comment fix.


# 1.98 19-Dec-2020 skrll

Tweak a comment


# 1.97 11-Dec-2020 skrll

s:aarch64/cpufunc.h:arm/cpufunc.h:

a baby step in the grand arm header unification challenge


# 1.96 10-Nov-2020 skrll

AA64 is not MIPS.

Change all KSEG references to directmap


# 1.95 07-Nov-2020 skrll

In pmap_devmap_bootstrap only set pmap_devmap_bootstrap_done if there
is an entry and ALL of the entries have been done. The entry required
for EARLYCONS might not be the first/only one...


# 1.94 01-Nov-2020 jmcneill

branches: 1.94.2;
No need to disable translation table walks in pmap_activate().


# 1.93 22-Oct-2020 skrll

Use the isb macro - missed in previous commit


# 1.92 22-Oct-2020 skrll

Use the dmb/dsb/isb macros... if nothing else they're all now consistent
about the "memory" assembler contraint.

No binary change


# 1.91 28-Sep-2020 skrll

Only set pmap_devmap_bootstrap_done if something gets mapped.

Think acpi_platform_devmap


# 1.90 19-Sep-2020 skrll

Make __md_palloc pmap agnostic (think sys/uvm/pmap)


# 1.89 14-Sep-2020 ryo

PID_MAX is just an initial value (soft maximum). Don't use it for CTASSERT.
defined __HAVE_CPU_MAXPROC to use function cpu_maxproc().

pointed out by mrg@, thanks.


# 1.88 06-Sep-2020 ryo

Fix panic caused by modload. http://mail-index.netbsd.org/port-arm/2020/08/30/msg006960.html

The address space reserved for modules may not be mapped in L1-L3.


# 1.87 14-Aug-2020 skrll

Whitespace


# 1.86 12-Aug-2020 skrll

Part IV of ad's performance improvements for aarch64

- Implement pmap_growkernel(), and update kernel pmap's stats with atomics.

- Then, pmap_kenter_pa() and pmap_kremove() no longer need to allocate
memory nor take pm_lock, because they only modify L3 PTEs.

- Then, pm_lock and pp_lock can be adaptive mutexes at IPL_NONE which are
cheaper than spin mutexes.

- Take the pmap's lock in pmap_extract() if not the kernel's pmap, otherwise
pmap_extract() might see inconsistent state.


# 1.85 09-Aug-2020 skrll

Fix another UVMHIST so it doesn't use %s


# 1.84 16-Jul-2020 skrll

pmapboot_enter simplication
- bootpage_alloc in asm becomes pmapboot_pagealloc in C
- PMAPBOOT_ENTER_NOBLOCK is removed as it's not used
- PMAPBOOT_ENTER_NOOVERWRITE is removed as it's now always on
- physpage_allocator argument is removed as it's always
pmapboot_pagealloc
- Support for EARLYCONS without CONSADDR is removed so that the identity
map for CONSADDR is always known.

For the assembly files:
2 files changed, 40 insertions(+), 89 deletions(-)

LGTM ryo


# 1.83 04-Jul-2020 rin

Use tlen for temporary length variable instead of l, which is usually
used for struct lwp *.

No binary changes.


# 1.82 02-Jul-2020 rin

pmap_procwr(): sync icache even if p != curproc. This fixes applications
like GDB for arm32, that rewrite text of other process.

Thanks to ryo@ for discussion.


# 1.81 02-Jul-2020 rin

Set uvmexp.ncolors appropriately, which is required for some CPU
models with VIPT icache.

Otherwise, alias in virtual address results in inconsistent results,
at least for applications that rewrite text of other process, e.g.,
GDB for arm32.

Also, this hopefully fixes other unexpected failures due to alias.

Confirmed that there's no observable regression in performance;
difference in ``time make -j8'' for GENERIC64 kernel on BCM2837
with and without setting uvmexp.ncolors is within 0.1%.

Thanks to ryo@ for discussion.


# 1.80 27-Jun-2020 rin

Fix typo in name of evcnt(4) counter.


# 1.79 24-Jun-2020 ryo

Fix bug with incorrect range calculation when doing icache sync.
This is called by sysarch(ARM_SYNC_ICACHE) from aarch32 (compat_netbsd32) emul process.

pointed out by rin@, thanks.

XXX pullup-9


# 1.78 14-Jun-2020 ad

- Fix a lock order reversal in pmap_page_protect().

- Make sure pmap is always locked when updating stats; atomics no longer
needed to do that.

- Remove unneeded traversal of pv list in pmap_enter_pv().

- Shrink struct vm_page from 136 to 128 bytes (cache line sized) and struct
pv_entry from 48 to 32 bytes (power of 2 sized).

- Embed a pv_entry in each vm_page. This means PV entries don't need to
be allocated for private anonymous memory / COW pages / most UBC mappings.
Dynamic PV entries are then used only for stuff like shared libraries and
shared memory.

Proposed on port-arm@.


# 1.77 10-Jun-2020 ad

- Wired/resident stats shouldn't covered by PMAPCOUNTERS.
- Rename need_update_pv -> need_enter_pv.

Ok ryo@


# 1.76 01-Jun-2020 ryo

no need to make the PTE writable to do icache_sync, enough to accessible.


# 1.75 15-May-2020 skrll

Use __diagused


# 1.74 15-May-2020 tnn

fix non-diag build


# 1.73 14-May-2020 skrll

Use MUTEX_NODEBUG for PV locks as is commonly done. OK ryo.


# 1.72 13-May-2020 jmcneill

Implement pmap_extract_coherency


Revision tags: bouyer-xenpvh-base2 phil-wifi-20200421 bouyer-xenpvh-base1
# 1.71 18-Apr-2020 skrll

PMAP_DEBUG has been deleted on arm


# 1.70 13-Apr-2020 maxv

Add support for Branch Target Identification (BTI).

On the executable pages that have the GP (Guarded Page) bit, the semantic
of the "br" and "blr" instructions is changed: the CPU expects the first
instruction of the jump/call target to be "bti", and faults if it isn't.

We add the GP bit on the kernel .text pages (and incidentally the .rodata
pages, but we don't care). The compiler adds a "bti c" instruction at the
beginning of each C function. We modify the ENTRY() macros to manually add
"bti c" in the asm functions.

cpuswitch.S needs a specific change: with "br x27" the CPU expects "bti j",
which is bad because the functions begin with "bti c"; switch to "br x16",
for the CPU to accept "bti c".

BTI helps defend against JOP/COP. Tested on Qemu.


Revision tags: phil-wifi-20200411 bouyer-xenpvh-base
# 1.69 08-Apr-2020 ryo

branches: 1.69.2;
use PMAP_PAGE_INIT() to initialize mutex in pmap_page.

VM_MDPAGE_INIT() in pmap_free_pdp() had initialized pp_flags,
so it unintentionally cleared PMAP_PAGE_FLAGS_PV_TRACKED.
use PMAP_PAGE_INIT to avoid using PMAP_PAGE_FLAGS_PV_TRACKED.

pointed out by tnn@, thanks


Revision tags: phil-wifi-20200406
# 1.68 14-Mar-2020 ad

pmap_remove_all(): Return a boolean value to indicate the behaviour. If
true, all mappings have been removed, the pmap is totally cleared out, and
UVM can then avoid doing the work to call pmap_remove() for each map entry.
If false, either nothing has been done, or some helpful arch-specific voodoo
has taken place.


Revision tags: is-mlppp-base
# 1.67 02-Mar-2020 ryo

oops, fix incorrect usage of daif_enable() in my previous commit.


# 1.66 29-Feb-2020 ryo

Fix pmap to work correctly with tagged addresses

- when fault, untag from address before passing to uvm/pmap functions
- pmap_extract() checks more strictly and consider the address tag


# 1.65 29-Feb-2020 ryo

use pmapboot_enter_range()


Revision tags: ad-namecache-base3
# 1.64 10-Feb-2020 ryo

use LIST(3) instead of TAILQ(3) to save one word in struct vm_page and struct pmap.

pointed out by riastradh@. thanks


# 1.63 03-Feb-2020 ryo

add support pmap_pv(9)

Patch originally from jmcneill@. thanks


# 1.62 03-Feb-2020 ryo

separate struct vm_page_md into vm_page_md and pmap_page
for preparation pmap_pv(9)


Revision tags: ad-namecache-base2 ad-namecache-base1
# 1.61 09-Jan-2020 ryo

fix behaviour mmap()/mprotect() when passed only PROT_EXEC.

when mmap()/mprotect() with only PROT_EXEC, syscall will be successful,
but the page actually hadn't been mapped.
it should be mapped with PROT_READ|PROT_EXEC implicitly. (r-x)


Revision tags: ad-namecache-base
# 1.60 30-Dec-2019 skrll

branches: 1.60.2;
Update pmap_map_chunk to allow L[12] block mappings and L3 page mappings


# 1.59 30-Dec-2019 skrll

Remove unnecessary brackets and unwrap a conditional. Same code before
and after.


# 1.58 28-Dec-2019 jmcneill

Do not use Early Write Acknowledge for PCIe I/O and config space.


# 1.57 27-Dec-2019 jmcneill

Enable early write acknowledge for device memory mappings.


# 1.56 19-Dec-2019 skrll

G/C kasan_shadow_map call in pmap_enter

pmap_growkernel calls kasan_shadow_map for KVA


# 1.55 18-Dec-2019 ryo

atomic_add_16() is not used in pmap.c anymore. no need decl here.


# 1.54 18-Dec-2019 ryo

space to tab


# 1.53 14-Dec-2019 skrll

Fix build... wire_count probably doesn't need atomics


# 1.52 13-Dec-2019 skrll

Fix KASAN support by calling kasan_shadow_map in pmap_growkernel


# 1.51 10-Dec-2019 ad

pg->phys_addr -> VM_PAGE_TO_PHYS(pg)


Revision tags: phil-wifi-20191119
# 1.50 14-Nov-2019 maxv

Mark several kASan functions with __nothing, to avoid annoying #ifdefs.
Same as kCSan and kMSan.


# 1.49 14-Nov-2019 maxv

Don't include "opt_kasan.h" when there's already <sys/asan.h> included.


# 1.48 29-Oct-2019 maya

Define PMAP_NEED_PROCWR, providing strategically placed i-cache
synchronization where just-changed memory is about to be executed.

Fixes SIGILLs seen when running Mono 6 on QEMU Cortex-A57.

ok ryo


# 1.47 22-Sep-2019 jmcneill

Disable translation table walks using TTBR0 while changing its value and
when deactivating a pmap. Fixes stability issues on Ampere eMAG CPUs.


# 1.46 20-Sep-2019 ryo

ref/mod bit should be set according to 'flags' argument, not 'prot'. r1.44 was incomplete.


# 1.45 13-Sep-2019 ryo

In pmap_devmap_bootstrap(), cpu_earlydevice_va_p() must not return true until *all* devmap tables have been enabled.
console mapping may be present in the last table.


# 1.44 07-Sep-2019 ryo

- remove incorrect KASSERT. mmap(2) with prot=PROT_WRITE calls pmap_enter(..., PROT_WRITE) internally.
- fix to update page reference flags when only PROT_WRITE or PROT_EXECUTE specified


# 1.43 15-Aug-2019 skrll

Make pmap_db_pte_print more terse so it's quicker on serial consoles


# 1.42 12-Aug-2019 skrll

Use PMAP_DEV in DEVMAP_ENTRY rather than pmap_map_chunk. It's clearer and
means pmap_map_chunk can be made to map other memory types.


Revision tags: netbsd-9-base phil-wifi-20190609
# 1.41 17-May-2019 mrg

branches: 1.41.2;
apply some __diagused.


Revision tags: isaki-audio2-base
# 1.40 08-Apr-2019 ryo

- free empty page tables pages if reach a certain usage.
- need to lock at removing an old pg (_pmap_remove_pv) in _pmap_enter()


# 1.39 06-Apr-2019 ryo

Fix race conditions about pmap_page_protect() and pmap_enter().

while handling same PTE by these functions in same time, there
is a critical path that the number of valid PTEs and wire_count
are inconsistent, and it caused KASSERT.
Need to hold a pv_lock while modifying them.


# 1.38 20-Mar-2019 ryo

spinkle __printflike(), and use PRIxxx


# 1.37 19-Mar-2019 ryo

- add ddb command "machine ttbr" to dump MMU tables.
- tidy up descriptions, usages and messages.


# 1.36 19-Mar-2019 ryo

- free L1-L3 pages that has been emptied by pmap_remove().
- if no memories, pmap_enter will return correctly ENOMEM if PMAP_CANFAIL, or wait until available any memories if !PMAP_CANFAIL.

These changes improves the stability when we use a huge virtual memory spaces with mmap.


# 1.35 06-Feb-2019 ryo

improve pmap_remove
- don't lock/unlock per page in pmap_remove()
- speedup pte lookup for continuous addresses
- bring out pool_cache_put(&_pmap_pv_pool, pv) from lock/unlock section


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226
# 1.34 21-Dec-2018 ryo

- add workaround for Cavium ThunderX errata 27456.
- add cpufuncs table in cpu_info. each cpu clusters may have different erratum. (e.g. big.LITTLE)


Revision tags: pgoyette-compat-1126
# 1.33 01-Nov-2018 maxv

Add kASan support for aarch64. Stack tracking needs more investigation
and will come in a separate commit.

Reviewed by ryo@ jmcneill@ skrll@.


# 1.32 31-Oct-2018 ryo

invalidate icache correctly.
l3pte_executable() should be used for only valid pte.


Revision tags: pgoyette-compat-1020
# 1.31 18-Oct-2018 skrll

Provide generic start code that assumes the MMU is off and caches are
disabled as per the linux booting protocol for ARMv6 and ARMv7 boards.
u-boot image type should be changed to 'linux' for correct behaviour.

The new start code builds a minimal "bootstrap" L1PT with cached access
disabled and uses the same table for all processors. AP startup is
performed in less steps and more code is written in C.

The bootstrap tables and stack are placed into an (orphaned) section
"_init_memory" which is given to uvm when it is no longer used.

Various kernels have been converted to use this code and tested. Some
boards were provided by TNF. Thanks!

The GENERIC kernel now boots on boards using the TEGRA, SUNXI and EXYNOS
kernels. The GENERIC kernel will also work on RPI2 using u-boot.

Thanks to martin@ and aymeric@ for testing on parallella and nanosoc
respectively


# 1.30 14-Oct-2018 skrll

Use __nothing


# 1.29 12-Oct-2018 ryo

add initial support of COMPAT_NETBSD32 on AArch64.
arm ELF32 EABI binaries could be execute in AArch32 state on AArch64. A32 THUMB mode is not supported yet.


# 1.28 12-Oct-2018 ryo

- cleanup checking address ranges with IN_RANGE macro
- change PM_ADDR_CHECK macro to KASSERTMSG
- restore fast lookup cases with IN_RANGE macro for pmap_extract changed in my previous commit.


# 1.27 12-Oct-2018 ryo

rewrite pmap_pte_lookup() to share similar code.


# 1.26 04-Oct-2018 ryo

cleanup locore, and changed the way to map memories during boot.
- add functions bootpage_enter() and bootpage_alloc() to adapt various layout
of physical memory map. especially for 64bit physical memory layout.
pmapboot_alloc() allocates pagetable pages from _end[].
- changed to map only the required amount for PA=VA identity mapping
(kernel image, UART device, and FDT blob) with L2_BLOCK(2Mbyte).
- changing page permission for kernel image, and making KSEG mapping are done
at cpu_kernel_vm_init() instead of at locore.
- optimize PTE entries with PTE Contiguous bit. it is enabled on devmap only for now.

reviewed by skrll@, thanks.


# 1.25 04-Oct-2018 ryo

* define LX_BLKPAG_{OS,ATTR}_* for OS dependent PTE attributes in pmap.h
* cleanup macros


Revision tags: pgoyette-compat-0930
# 1.24 17-Sep-2018 ryo

delete debug printf and KASSERT.


# 1.23 10-Sep-2018 maxv

Replace KDASSERT by panic.


# 1.22 10-Sep-2018 maxv

Rename _pmap_alloc_pdp -> pmap_alloc_pdp, and make it public.


# 1.21 10-Sep-2018 ryo

cleanup aarch64 mpstart and fdt bootstrap
* arm_cpu_hatch_arg is a bad idea. avoid serializing CPU startup, and eliminate arm_cpu_hatch_arg.
in mpstart, resolve own cpu index using array of cpu_mpidr[] (aarch64)
* add support fdt enable-method "spin-table"
* add support fdt enable-method "brcm,bcm2836-smp" (for 32bit RaspberryPi)
* use arm_fdt_cpu_bootstrap() instead of psci_fdt_bootstrap()
* rename "arm/fdt/psci_fdt.h" to "arm/fdt/psci_fdtvar.h" because of conflict of include file for needs-flag
* add devmap for cpu spin-table of raspberrypi3/aarch64
* no need to force hatch APs for raspberrypi3/arm32 ifndef MULTIPROCESSOR.
* fix to work pmap_extract(kerneltext/data/bss) even if before calling pmap_bootstrap

idea to use cpu_mpidr[] by jmcneill@. reviewd by skrll@. thanks.


Revision tags: pgoyette-compat-0906
# 1.20 27-Aug-2018 ryo

need to add VM_PROT_READ when pmap_kenter_pa(va, pa, VM_PROT_WRITE, 0) or pmap_kenter_pa(va, pa, VM_PROT_EXECUTE, 0).
VM_PROT_READ is treated as an access permission inernally.


# 1.19 11-Aug-2018 ryo

change to minimum invalidation of TLB.
specifying not only va but also asid, and not invalidate L0-L2 entry using tlbi_*_ll() if needed.


# 1.18 10-Aug-2018 ryo

treat kernel-exec attr and user-exec attr separately.
kernel cannot execute userland exec page, and user cannot execute kernel page.


# 1.17 06-Aug-2018 ryo

set kernel text/rodata readonly by default.
add function db_write_text() for setting ddb breakpoint.


# 1.16 31-Jul-2018 skrll

Define and use VPRINTF


Revision tags: pgoyette-compat-0728
# 1.15 27-Jul-2018 ryo

changes of pmap.c r1.13 seems to be unstable.
In order to invalidate icache, not to invalidate all icache,
but temporary to make the page writable and invalidate target address only.


# 1.14 24-Jul-2018 ryo

don't call pool_cache_put with locking pmap. pool_cache_put call pmap_kenter_pa internally.
(pool_cache_put_paddr -> pool_cache_put_slow -> pool_get -> pmap_kenter_pa)


# 1.13 23-Jul-2018 ryo

* fix icache invalidations.
* "ic ivau" (aarch64_icache_sync_range) with VA generates permission fault in some situations, therefore use KSEG address for now.


# 1.12 23-Jul-2018 ryo

rather than using flags to resolve nested locks, reserve pool_cache before locking.


# 1.11 21-Jul-2018 ryo

* avoid deadlock. mutex_owned() works only for adaptive lock, therefore we cannot use it for spinlock...
* add more NULL check
* clear pte when pmap_enter() fails


# 1.10 17-Jul-2018 ryo

Use __debugused


# 1.9 17-Jul-2018 christos

Add missing casts, remove unused variables.


# 1.8 09-Jul-2018 ryo

need locks in pmap_kremove() and pmap_fault_fixup()


Revision tags: phil-wifi-base pgoyette-compat-0625 pgoyette-compat-0521
# 1.7 20-May-2018 ryo

branches: 1.7.2;
pmap_enter() must update modified/referenced flags by 'flags' not 'prot'.


# 1.6 16-May-2018 ryo

Fix memory leak. it was leaking one page every pmap_create().
pm->pm_vmlist must be initialized before calling _pmap_alloc_pdp().


Revision tags: pgoyette-compat-0502
# 1.5 29-Apr-2018 ryo

fix KASSERT panic. pv_entry may not be exists in pvlist when pmap_remove().


# 1.4 29-Apr-2018 ryo

delete unused code


# 1.3 27-Apr-2018 ryo

fix instability behavior of bufcache on aarch64.
* fix to return correct ref/mod when PMAP_WIRED.
* changed to keep wired flags in pte instead of pv_entry, and cleanup.


Revision tags: pgoyette-compat-0422 pgoyette-compat-0415 pgoyette-compat-0407
# 1.2 01-Apr-2018 ryo

Add initial support for ARMv8 (AARCH64) (by nisimura@ and ryo@)

- sys/arch/evbarm64 is gone and integrated into sys/arch/evbarm. (by skrll@)
- add support fdt. evbarm/conf/GENERIC64 fdt (bcm2837,sunxi,tegra) based generic 64bit kernel config. (by skrll@, jmcneill@)


Revision tags: netbsd-8-2-RELEASE netbsd-8-1-RELEASE netbsd-8-1-RC1 netbsd-7-2-RELEASE netbsd-8-0-RELEASE netbsd-8-0-RC2 netbsd-8-0-RC1 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 netbsd-7-1-2-RELEASE pgoyette-compat-base netbsd-7-1-1-RELEASE tls-maxphys-base-20171202 matt-nb8-mediatek-base nick-nhusb-base-20170825 perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base pgoyette-localcount-20170320 netbsd-7-1-RELEASE netbsd-7-1-RC2 nick-nhusb-base-20170204 netbsd-7-nhusb-base-20170116 bouyer-socketcan-base pgoyette-localcount-20170107 netbsd-7-1-RC1 nick-nhusb-base-20161204 pgoyette-localcount-20161104 netbsd-7-0-2-RELEASE nick-nhusb-base-20161004 localcount-20160914 netbsd-7-nhusb-base pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907 nick-nhusb-base-20160529 netbsd-7-0-1-RELEASE nick-nhusb-base-20160422 nick-nhusb-base-20160319 nick-nhusb-base-20151226 netbsd-7-0-RELEASE nick-nhusb-base-20150921 netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 nick-nhusb-base-20150606 nick-nhusb-base-20150406 nick-nhusb-base tls-maxphys-base netbsd-7-base
# 1.1 10-Aug-2014 matt

branches: 1.1.4; 1.1.28;
Preliminary files for AARCH64 (64-bit ARM) support.
Enough for a distribution build.


# 1.129 05-Mar-2022 skrll

Slight comment improvement.


# 1.128 16-Feb-2022 andvar

fix various typos, mainly in comments.


# 1.127 31-Jan-2022 ryo

add support Hardware updates to Access flag and Dirty state (FEAT_HAFDBS)

- The DBM bit of the PTE is now used to determine if it is writable, and
the AF bit is treated entirely as a reference bit. A valid PTE is always
treated as readable. There can be no valid PTE that is not readable.
- LX_BLKPAG_OS_{READ,WRITE} are used only for debugging purposes,
and has been superseded by LX_BLKPAG_AF and LX_BLKPAG_DBM.
- Improve comment

The need for reference/modify emulation has been eliminated,
and access/permission faults have been reduced, however,
there has been little change in overall performance.


# 1.126 31-Jan-2022 ryo

Skip unnecessary PTE operations and TLB invalidation.


# 1.125 16-Jan-2022 rillig

aarch64/pmap: remove stray semicolon

No binary change.


# 1.124 15-Jan-2022 skrll

The translations that need invalidation are always last level so remove
the (dubious) logic around tracking the level. The "any level" TLB
invalidation maintenance operation are used, but this may change after
further testing.

before
======
1661.0u 420.2s 2:53.82 1197.3% 231+29k 10+33918io 102pf+0w
1646.8u 425.2s 2:52.96 1198.0% 232+29k 1+33937io 49pf+0w
1647.9u 425.7s 2:52.58 1201.6% 232+29k 0+33940io 32pf+0w

After
=====
1602.5u 420.8s 2:49.09 1196.6% 238+30k 24+33893io 54pf+0w
1600.7u 421.3s 2:51.53 1178.8% 238+30k 1+33914io 33pf+0w
1597.5u 424.3s 2:50.46 1186.1% 238+30k 0+33915io 17pf+0w

LGTM from ryo@


# 1.123 14-Jan-2022 skrll

Restore the previous pmap_remove_all behaviour as the new method meant
the n1sdp couldn't complete a build.

No noticeable change in kernel build performance.


# 1.122 04-Jan-2022 skrll

KNF


# 1.121 10-Dec-2021 andvar

s/occured/occurred/ in comments, log messages and man pages.


# 1.120 07-Dec-2021 andvar

fix various typos, mainly in comments.


# 1.119 23-Oct-2021 skrll

Fix non-UVMHIST build


# 1.118 16-Oct-2021 ryo

fix non-MULTIPROCESSOR build


# 1.117 10-Oct-2021 skrll

Use sys/uvm/pmap/pmap_tlb.c on Aarch64 in the same way that some Arm, MIPS,
and some PPC kernels do. This removes the limitation of 256 processes on
CPUs with 8bit ASID field, e.g. Apple M1.

Additionally the following changes have been made

- removed a couple of unnecessary aarch64_tlbi_all calls
- removed any invalidation after freeing page tables due to
_pmap_sweep_pdp. This was never necessary afaict.
- all kernel mappings are marked global and userland mapping not-global.

Performance testing hasn't show a significant difference. The data here
is from building a kernel on an lx2k system with nvme.

before
1489.6u 400.4s 2:40.65 1176.5% 228+224k 0+32289io 57pf+0w
1482.6u 403.2s 2:38.49 1189.9% 228+222k 0+32274io 46pf+0w
1485.4u 402.2s 2:37.27 1200.2% 228+222k 0+32275io 12pf+0w

after
1493.9u 404.6s 2:37.50 1205.4% 227+221k 0+32265io 48pf+0w
1485.0u 408.0s 2:38.54 1194.0% 227+222k 0+32272io 36pf+0w
1484.3u 407.0s 2:35.88 1213.3% 228+224k 0+32268io 14pf+0w

>>> stats.ttest_ind([160.65,158.49,157.27], [157.5,158.54,155.88])
Ttest_indResult(statistic=1.1923622711296888, pvalue=0.2990182944606766)
>>>


# 1.116 30-Sep-2021 skrll

Ensure TCR_EPD0 is set on entry to pmap_activate and ensure it is set as
early as possible for APs.


# 1.115 26-Sep-2021 skrll

Use UVMHIST_CALLARGS


# 1.114 26-Sep-2021 skrll

'\n' is not required in KASSERTMSG either.


# 1.113 26-Sep-2021 skrll

"\n" is not required in KERNHIST


# 1.112 15-Sep-2021 skrll

Use __SHIFTIN. Same code before and after.


# 1.111 12-Sep-2021 skrll

pmap_page_remove: simply and reduce the code size slightly.


# 1.110 09-Sep-2021 skrll

In pmap_icache_sync_range change

for (...) {
...
if (condition) {
// do stuff
}
}

to

for (...) {
...
if (!conditional)
continue;
// do stuff
}

to save on indentation. Same code (modulo register usage) before and
after.


# 1.109 09-Sep-2021 skrll

KNF


Revision tags: thorpej-i2c-spi-conf2-base thorpej-futex2-base thorpej-cfargs2-base cjep_sun2x-base1 cjep_sun2x-base cjep_staticlib_x-base1 thorpej-i2c-spi-conf-base
# 1.108 29-May-2021 skrll

Deal with the pmap limitation of maxproc in a more complete way and
recognise CPUs with only 8bit ASIDs.


Revision tags: cjep_staticlib_x-base
# 1.107 30-Apr-2021 skrll

branches: 1.107.2;
Make the ddb for pmap / pte information pmap agnostic


# 1.106 29-Apr-2021 skrll

Remove some unnecessary tlb invalidate in pmap_growkernel and ASAN shadow
map. Ensure the shadow map mappings are visible to the TLB walkers.


# 1.105 21-Apr-2021 ryo

branches: 1.105.2;
added more attributes of PTE displayed by "ddb>machine pte"


Revision tags: thorpej-cfargs-base
# 1.104 17-Apr-2021 mrg

remove KERNHIST_INIT_STATIC(). it stradles the line between usable
early in boot and broken early in boot by requiring a partly static
structure with another structure that must be present by the time
any uses are performed. theoretically platform code could allocate
a chunk while seting up memory and assign it here, giving a dynamic
sizing for the entry list, but the reality is that all users have
a statically allocated entry list as well.

the existing KERNHIST_LINK_STATIC() is used in conjunction with
KERNHIST_INITIALIZER() instead.

this stops a NULL pointer deref when the _LOG() macro is called
before the storage is linked in, which happens with GCC 10 on OCTEON
with UVMHIST enabled, crashing in very early kernel init.


Revision tags: thorpej-futex-base
# 1.103 09-Mar-2021 ryo

branches: 1.103.2;
fix build error without options DDB.

kvtopte() is referenced from arm/acpi/acpi_machdep.c


# 1.102 13-Feb-2021 ryo

No assignment is needed here.

the loop in pmap_page_remove() always removes the first pv,
and since the list is managed by _pmap_remove_pv(), pp->pp_pv.pv_next always points to the first.


# 1.101 01-Feb-2021 ryo

It is enough to make a page accessible instead of writable.
same fix as r1.76


# 1.100 31-Jan-2021 ryo

implement pmap_remove_all().

The size of struct pv_entry has increased, but speed of kernel build has improved by about 1%
exec and exit should have been improved.


# 1.99 20-Dec-2020 skrll

Improve the English in the previous comment fix.


# 1.98 19-Dec-2020 skrll

Tweak a comment


# 1.97 11-Dec-2020 skrll

s:aarch64/cpufunc.h:arm/cpufunc.h:

a baby step in the grand arm header unification challenge


# 1.96 10-Nov-2020 skrll

AA64 is not MIPS.

Change all KSEG references to directmap


# 1.95 07-Nov-2020 skrll

In pmap_devmap_bootstrap only set pmap_devmap_bootstrap_done if there
is an entry and ALL of the entries have been done. The entry required
for EARLYCONS might not be the first/only one...


# 1.94 01-Nov-2020 jmcneill

branches: 1.94.2;
No need to disable translation table walks in pmap_activate().


# 1.93 22-Oct-2020 skrll

Use the isb macro - missed in previous commit


# 1.92 22-Oct-2020 skrll

Use the dmb/dsb/isb macros... if nothing else they're all now consistent
about the "memory" assembler contraint.

No binary change


# 1.91 28-Sep-2020 skrll

Only set pmap_devmap_bootstrap_done if something gets mapped.

Think acpi_platform_devmap


# 1.90 19-Sep-2020 skrll

Make __md_palloc pmap agnostic (think sys/uvm/pmap)


# 1.89 14-Sep-2020 ryo

PID_MAX is just an initial value (soft maximum). Don't use it for CTASSERT.
defined __HAVE_CPU_MAXPROC to use function cpu_maxproc().

pointed out by mrg@, thanks.


# 1.88 06-Sep-2020 ryo

Fix panic caused by modload. http://mail-index.netbsd.org/port-arm/2020/08/30/msg006960.html

The address space reserved for modules may not be mapped in L1-L3.


# 1.87 14-Aug-2020 skrll

Whitespace


# 1.86 12-Aug-2020 skrll

Part IV of ad's performance improvements for aarch64

- Implement pmap_growkernel(), and update kernel pmap's stats with atomics.

- Then, pmap_kenter_pa() and pmap_kremove() no longer need to allocate
memory nor take pm_lock, because they only modify L3 PTEs.

- Then, pm_lock and pp_lock can be adaptive mutexes at IPL_NONE which are
cheaper than spin mutexes.

- Take the pmap's lock in pmap_extract() if not the kernel's pmap, otherwise
pmap_extract() might see inconsistent state.


# 1.85 09-Aug-2020 skrll

Fix another UVMHIST so it doesn't use %s


# 1.84 16-Jul-2020 skrll

pmapboot_enter simplication
- bootpage_alloc in asm becomes pmapboot_pagealloc in C
- PMAPBOOT_ENTER_NOBLOCK is removed as it's not used
- PMAPBOOT_ENTER_NOOVERWRITE is removed as it's now always on
- physpage_allocator argument is removed as it's always
pmapboot_pagealloc
- Support for EARLYCONS without CONSADDR is removed so that the identity
map for CONSADDR is always known.

For the assembly files:
2 files changed, 40 insertions(+), 89 deletions(-)

LGTM ryo


# 1.83 04-Jul-2020 rin

Use tlen for temporary length variable instead of l, which is usually
used for struct lwp *.

No binary changes.


# 1.82 02-Jul-2020 rin

pmap_procwr(): sync icache even if p != curproc. This fixes applications
like GDB for arm32, that rewrite text of other process.

Thanks to ryo@ for discussion.


# 1.81 02-Jul-2020 rin

Set uvmexp.ncolors appropriately, which is required for some CPU
models with VIPT icache.

Otherwise, alias in virtual address results in inconsistent results,
at least for applications that rewrite text of other process, e.g.,
GDB for arm32.

Also, this hopefully fixes other unexpected failures due to alias.

Confirmed that there's no observable regression in performance;
difference in ``time make -j8'' for GENERIC64 kernel on BCM2837
with and without setting uvmexp.ncolors is within 0.1%.

Thanks to ryo@ for discussion.


# 1.80 27-Jun-2020 rin

Fix typo in name of evcnt(4) counter.


# 1.79 24-Jun-2020 ryo

Fix bug with incorrect range calculation when doing icache sync.
This is called by sysarch(ARM_SYNC_ICACHE) from aarch32 (compat_netbsd32) emul process.

pointed out by rin@, thanks.

XXX pullup-9


# 1.78 14-Jun-2020 ad

- Fix a lock order reversal in pmap_page_protect().

- Make sure pmap is always locked when updating stats; atomics no longer
needed to do that.

- Remove unneeded traversal of pv list in pmap_enter_pv().

- Shrink struct vm_page from 136 to 128 bytes (cache line sized) and struct
pv_entry from 48 to 32 bytes (power of 2 sized).

- Embed a pv_entry in each vm_page. This means PV entries don't need to
be allocated for private anonymous memory / COW pages / most UBC mappings.
Dynamic PV entries are then used only for stuff like shared libraries and
shared memory.

Proposed on port-arm@.


# 1.77 10-Jun-2020 ad

- Wired/resident stats shouldn't covered by PMAPCOUNTERS.
- Rename need_update_pv -> need_enter_pv.

Ok ryo@


# 1.76 01-Jun-2020 ryo

no need to make the PTE writable to do icache_sync, enough to accessible.


# 1.75 15-May-2020 skrll

Use __diagused


# 1.74 15-May-2020 tnn

fix non-diag build


# 1.73 14-May-2020 skrll

Use MUTEX_NODEBUG for PV locks as is commonly done. OK ryo.


# 1.72 13-May-2020 jmcneill

Implement pmap_extract_coherency


Revision tags: bouyer-xenpvh-base2 phil-wifi-20200421 bouyer-xenpvh-base1
# 1.71 18-Apr-2020 skrll

PMAP_DEBUG has been deleted on arm


# 1.70 13-Apr-2020 maxv

Add support for Branch Target Identification (BTI).

On the executable pages that have the GP (Guarded Page) bit, the semantic
of the "br" and "blr" instructions is changed: the CPU expects the first
instruction of the jump/call target to be "bti", and faults if it isn't.

We add the GP bit on the kernel .text pages (and incidentally the .rodata
pages, but we don't care). The compiler adds a "bti c" instruction at the
beginning of each C function. We modify the ENTRY() macros to manually add
"bti c" in the asm functions.

cpuswitch.S needs a specific change: with "br x27" the CPU expects "bti j",
which is bad because the functions begin with "bti c"; switch to "br x16",
for the CPU to accept "bti c".

BTI helps defend against JOP/COP. Tested on Qemu.


Revision tags: phil-wifi-20200411 bouyer-xenpvh-base
# 1.69 08-Apr-2020 ryo

branches: 1.69.2;
use PMAP_PAGE_INIT() to initialize mutex in pmap_page.

VM_MDPAGE_INIT() in pmap_free_pdp() had initialized pp_flags,
so it unintentionally cleared PMAP_PAGE_FLAGS_PV_TRACKED.
use PMAP_PAGE_INIT to avoid using PMAP_PAGE_FLAGS_PV_TRACKED.

pointed out by tnn@, thanks


Revision tags: phil-wifi-20200406
# 1.68 14-Mar-2020 ad

pmap_remove_all(): Return a boolean value to indicate the behaviour. If
true, all mappings have been removed, the pmap is totally cleared out, and
UVM can then avoid doing the work to call pmap_remove() for each map entry.
If false, either nothing has been done, or some helpful arch-specific voodoo
has taken place.


Revision tags: is-mlppp-base
# 1.67 02-Mar-2020 ryo

oops, fix incorrect usage of daif_enable() in my previous commit.


# 1.66 29-Feb-2020 ryo

Fix pmap to work correctly with tagged addresses

- when fault, untag from address before passing to uvm/pmap functions
- pmap_extract() checks more strictly and consider the address tag


# 1.65 29-Feb-2020 ryo

use pmapboot_enter_range()


Revision tags: ad-namecache-base3
# 1.64 10-Feb-2020 ryo

use LIST(3) instead of TAILQ(3) to save one word in struct vm_page and struct pmap.

pointed out by riastradh@. thanks


# 1.63 03-Feb-2020 ryo

add support pmap_pv(9)

Patch originally from jmcneill@. thanks


# 1.62 03-Feb-2020 ryo

separate struct vm_page_md into vm_page_md and pmap_page
for preparation pmap_pv(9)


Revision tags: ad-namecache-base2 ad-namecache-base1
# 1.61 09-Jan-2020 ryo

fix behaviour mmap()/mprotect() when passed only PROT_EXEC.

when mmap()/mprotect() with only PROT_EXEC, syscall will be successful,
but the page actually hadn't been mapped.
it should be mapped with PROT_READ|PROT_EXEC implicitly. (r-x)


Revision tags: ad-namecache-base
# 1.60 30-Dec-2019 skrll

branches: 1.60.2;
Update pmap_map_chunk to allow L[12] block mappings and L3 page mappings


# 1.59 30-Dec-2019 skrll

Remove unnecessary brackets and unwrap a conditional. Same code before
and after.


# 1.58 28-Dec-2019 jmcneill

Do not use Early Write Acknowledge for PCIe I/O and config space.


# 1.57 27-Dec-2019 jmcneill

Enable early write acknowledge for device memory mappings.


# 1.56 19-Dec-2019 skrll

G/C kasan_shadow_map call in pmap_enter

pmap_growkernel calls kasan_shadow_map for KVA


# 1.55 18-Dec-2019 ryo

atomic_add_16() is not used in pmap.c anymore. no need decl here.


# 1.54 18-Dec-2019 ryo

space to tab


# 1.53 14-Dec-2019 skrll

Fix build... wire_count probably doesn't need atomics


# 1.52 13-Dec-2019 skrll

Fix KASAN support by calling kasan_shadow_map in pmap_growkernel


# 1.51 10-Dec-2019 ad

pg->phys_addr -> VM_PAGE_TO_PHYS(pg)


Revision tags: phil-wifi-20191119
# 1.50 14-Nov-2019 maxv

Mark several kASan functions with __nothing, to avoid annoying #ifdefs.
Same as kCSan and kMSan.


# 1.49 14-Nov-2019 maxv

Don't include "opt_kasan.h" when there's already <sys/asan.h> included.


# 1.48 29-Oct-2019 maya

Define PMAP_NEED_PROCWR, providing strategically placed i-cache
synchronization where just-changed memory is about to be executed.

Fixes SIGILLs seen when running Mono 6 on QEMU Cortex-A57.

ok ryo


# 1.47 22-Sep-2019 jmcneill

Disable translation table walks using TTBR0 while changing its value and
when deactivating a pmap. Fixes stability issues on Ampere eMAG CPUs.


# 1.46 20-Sep-2019 ryo

ref/mod bit should be set according to 'flags' argument, not 'prot'. r1.44 was incomplete.


# 1.45 13-Sep-2019 ryo

In pmap_devmap_bootstrap(), cpu_earlydevice_va_p() must not return true until *all* devmap tables have been enabled.
console mapping may be present in the last table.


# 1.44 07-Sep-2019 ryo

- remove incorrect KASSERT. mmap(2) with prot=PROT_WRITE calls pmap_enter(..., PROT_WRITE) internally.
- fix to update page reference flags when only PROT_WRITE or PROT_EXECUTE specified


# 1.43 15-Aug-2019 skrll

Make pmap_db_pte_print more terse so it's quicker on serial consoles


# 1.42 12-Aug-2019 skrll

Use PMAP_DEV in DEVMAP_ENTRY rather than pmap_map_chunk. It's clearer and
means pmap_map_chunk can be made to map other memory types.


Revision tags: netbsd-9-base phil-wifi-20190609
# 1.41 17-May-2019 mrg

branches: 1.41.2;
apply some __diagused.


Revision tags: isaki-audio2-base
# 1.40 08-Apr-2019 ryo

- free empty page tables pages if reach a certain usage.
- need to lock at removing an old pg (_pmap_remove_pv) in _pmap_enter()


# 1.39 06-Apr-2019 ryo

Fix race conditions about pmap_page_protect() and pmap_enter().

while handling same PTE by these functions in same time, there
is a critical path that the number of valid PTEs and wire_count
are inconsistent, and it caused KASSERT.
Need to hold a pv_lock while modifying them.


# 1.38 20-Mar-2019 ryo

spinkle __printflike(), and use PRIxxx


# 1.37 19-Mar-2019 ryo

- add ddb command "machine ttbr" to dump MMU tables.
- tidy up descriptions, usages and messages.


# 1.36 19-Mar-2019 ryo

- free L1-L3 pages that has been emptied by pmap_remove().
- if no memories, pmap_enter will return correctly ENOMEM if PMAP_CANFAIL, or wait until available any memories if !PMAP_CANFAIL.

These changes improves the stability when we use a huge virtual memory spaces with mmap.


# 1.35 06-Feb-2019 ryo

improve pmap_remove
- don't lock/unlock per page in pmap_remove()
- speedup pte lookup for continuous addresses
- bring out pool_cache_put(&_pmap_pv_pool, pv) from lock/unlock section


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226
# 1.34 21-Dec-2018 ryo

- add workaround for Cavium ThunderX errata 27456.
- add cpufuncs table in cpu_info. each cpu clusters may have different erratum. (e.g. big.LITTLE)


Revision tags: pgoyette-compat-1126
# 1.33 01-Nov-2018 maxv

Add kASan support for aarch64. Stack tracking needs more investigation
and will come in a separate commit.

Reviewed by ryo@ jmcneill@ skrll@.


# 1.32 31-Oct-2018 ryo

invalidate icache correctly.
l3pte_executable() should be used for only valid pte.


Revision tags: pgoyette-compat-1020
# 1.31 18-Oct-2018 skrll

Provide generic start code that assumes the MMU is off and caches are
disabled as per the linux booting protocol for ARMv6 and ARMv7 boards.
u-boot image type should be changed to 'linux' for correct behaviour.

The new start code builds a minimal "bootstrap" L1PT with cached access
disabled and uses the same table for all processors. AP startup is
performed in less steps and more code is written in C.

The bootstrap tables and stack are placed into an (orphaned) section
"_init_memory" which is given to uvm when it is no longer used.

Various kernels have been converted to use this code and tested. Some
boards were provided by TNF. Thanks!

The GENERIC kernel now boots on boards using the TEGRA, SUNXI and EXYNOS
kernels. The GENERIC kernel will also work on RPI2 using u-boot.

Thanks to martin@ and aymeric@ for testing on parallella and nanosoc
respectively


# 1.30 14-Oct-2018 skrll

Use __nothing


# 1.29 12-Oct-2018 ryo

add initial support of COMPAT_NETBSD32 on AArch64.
arm ELF32 EABI binaries could be execute in AArch32 state on AArch64. A32 THUMB mode is not supported yet.


# 1.28 12-Oct-2018 ryo

- cleanup checking address ranges with IN_RANGE macro
- change PM_ADDR_CHECK macro to KASSERTMSG
- restore fast lookup cases with IN_RANGE macro for pmap_extract changed in my previous commit.


# 1.27 12-Oct-2018 ryo

rewrite pmap_pte_lookup() to share similar code.


# 1.26 04-Oct-2018 ryo

cleanup locore, and changed the way to map memories during boot.
- add functions bootpage_enter() and bootpage_alloc() to adapt various layout
of physical memory map. especially for 64bit physical memory layout.
pmapboot_alloc() allocates pagetable pages from _end[].
- changed to map only the required amount for PA=VA identity mapping
(kernel image, UART device, and FDT blob) with L2_BLOCK(2Mbyte).
- changing page permission for kernel image, and making KSEG mapping are done
at cpu_kernel_vm_init() instead of at locore.
- optimize PTE entries with PTE Contiguous bit. it is enabled on devmap only for now.

reviewed by skrll@, thanks.


# 1.25 04-Oct-2018 ryo

* define LX_BLKPAG_{OS,ATTR}_* for OS dependent PTE attributes in pmap.h
* cleanup macros


Revision tags: pgoyette-compat-0930
# 1.24 17-Sep-2018 ryo

delete debug printf and KASSERT.


# 1.23 10-Sep-2018 maxv

Replace KDASSERT by panic.


# 1.22 10-Sep-2018 maxv

Rename _pmap_alloc_pdp -> pmap_alloc_pdp, and make it public.


# 1.21 10-Sep-2018 ryo

cleanup aarch64 mpstart and fdt bootstrap
* arm_cpu_hatch_arg is a bad idea. avoid serializing CPU startup, and eliminate arm_cpu_hatch_arg.
in mpstart, resolve own cpu index using array of cpu_mpidr[] (aarch64)
* add support fdt enable-method "spin-table"
* add support fdt enable-method "brcm,bcm2836-smp" (for 32bit RaspberryPi)
* use arm_fdt_cpu_bootstrap() instead of psci_fdt_bootstrap()
* rename "arm/fdt/psci_fdt.h" to "arm/fdt/psci_fdtvar.h" because of conflict of include file for needs-flag
* add devmap for cpu spin-table of raspberrypi3/aarch64
* no need to force hatch APs for raspberrypi3/arm32 ifndef MULTIPROCESSOR.
* fix to work pmap_extract(kerneltext/data/bss) even if before calling pmap_bootstrap

idea to use cpu_mpidr[] by jmcneill@. reviewd by skrll@. thanks.


Revision tags: pgoyette-compat-0906
# 1.20 27-Aug-2018 ryo

need to add VM_PROT_READ when pmap_kenter_pa(va, pa, VM_PROT_WRITE, 0) or pmap_kenter_pa(va, pa, VM_PROT_EXECUTE, 0).
VM_PROT_READ is treated as an access permission inernally.


# 1.19 11-Aug-2018 ryo

change to minimum invalidation of TLB.
specifying not only va but also asid, and not invalidate L0-L2 entry using tlbi_*_ll() if needed.


# 1.18 10-Aug-2018 ryo

treat kernel-exec attr and user-exec attr separately.
kernel cannot execute userland exec page, and user cannot execute kernel page.


# 1.17 06-Aug-2018 ryo

set kernel text/rodata readonly by default.
add function db_write_text() for setting ddb breakpoint.


# 1.16 31-Jul-2018 skrll

Define and use VPRINTF


Revision tags: pgoyette-compat-0728
# 1.15 27-Jul-2018 ryo

changes of pmap.c r1.13 seems to be unstable.
In order to invalidate icache, not to invalidate all icache,
but temporary to make the page writable and invalidate target address only.


# 1.14 24-Jul-2018 ryo

don't call pool_cache_put with locking pmap. pool_cache_put call pmap_kenter_pa internally.
(pool_cache_put_paddr -> pool_cache_put_slow -> pool_get -> pmap_kenter_pa)


# 1.13 23-Jul-2018 ryo

* fix icache invalidations.
* "ic ivau" (aarch64_icache_sync_range) with VA generates permission fault in some situations, therefore use KSEG address for now.


# 1.12 23-Jul-2018 ryo

rather than using flags to resolve nested locks, reserve pool_cache before locking.


# 1.11 21-Jul-2018 ryo

* avoid deadlock. mutex_owned() works only for adaptive lock, therefore we cannot use it for spinlock...
* add more NULL check
* clear pte when pmap_enter() fails


# 1.10 17-Jul-2018 ryo

Use __debugused


# 1.9 17-Jul-2018 christos

Add missing casts, remove unused variables.


# 1.8 09-Jul-2018 ryo

need locks in pmap_kremove() and pmap_fault_fixup()


Revision tags: phil-wifi-base pgoyette-compat-0625 pgoyette-compat-0521
# 1.7 20-May-2018 ryo

branches: 1.7.2;
pmap_enter() must update modified/referenced flags by 'flags' not 'prot'.


# 1.6 16-May-2018 ryo

Fix memory leak. it was leaking one page every pmap_create().
pm->pm_vmlist must be initialized before calling _pmap_alloc_pdp().


Revision tags: pgoyette-compat-0502
# 1.5 29-Apr-2018 ryo

fix KASSERT panic. pv_entry may not be exists in pvlist when pmap_remove().


# 1.4 29-Apr-2018 ryo

delete unused code


# 1.3 27-Apr-2018 ryo

fix instability behavior of bufcache on aarch64.
* fix to return correct ref/mod when PMAP_WIRED.
* changed to keep wired flags in pte instead of pv_entry, and cleanup.


Revision tags: pgoyette-compat-0422 pgoyette-compat-0415 pgoyette-compat-0407
# 1.2 01-Apr-2018 ryo

Add initial support for ARMv8 (AARCH64) (by nisimura@ and ryo@)

- sys/arch/evbarm64 is gone and integrated into sys/arch/evbarm. (by skrll@)
- add support fdt. evbarm/conf/GENERIC64 fdt (bcm2837,sunxi,tegra) based generic 64bit kernel config. (by skrll@, jmcneill@)


Revision tags: netbsd-8-2-RELEASE netbsd-8-1-RELEASE netbsd-8-1-RC1 netbsd-7-2-RELEASE netbsd-8-0-RELEASE netbsd-8-0-RC2 netbsd-8-0-RC1 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 netbsd-7-1-2-RELEASE pgoyette-compat-base netbsd-7-1-1-RELEASE tls-maxphys-base-20171202 matt-nb8-mediatek-base nick-nhusb-base-20170825 perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base pgoyette-localcount-20170320 netbsd-7-1-RELEASE netbsd-7-1-RC2 nick-nhusb-base-20170204 netbsd-7-nhusb-base-20170116 bouyer-socketcan-base pgoyette-localcount-20170107 netbsd-7-1-RC1 nick-nhusb-base-20161204 pgoyette-localcount-20161104 netbsd-7-0-2-RELEASE nick-nhusb-base-20161004 localcount-20160914 netbsd-7-nhusb-base pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907 nick-nhusb-base-20160529 netbsd-7-0-1-RELEASE nick-nhusb-base-20160422 nick-nhusb-base-20160319 nick-nhusb-base-20151226 netbsd-7-0-RELEASE nick-nhusb-base-20150921 netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 nick-nhusb-base-20150606 nick-nhusb-base-20150406 nick-nhusb-base tls-maxphys-base netbsd-7-base
# 1.1 10-Aug-2014 matt

branches: 1.1.4; 1.1.28;
Preliminary files for AARCH64 (64-bit ARM) support.
Enough for a distribution build.


# 1.128 16-Feb-2022 andvar

fix various typos, mainly in comments.


# 1.127 31-Jan-2022 ryo

add support Hardware updates to Access flag and Dirty state (FEAT_HAFDBS)

- The DBM bit of the PTE is now used to determine if it is writable, and
the AF bit is treated entirely as a reference bit. A valid PTE is always
treated as readable. There can be no valid PTE that is not readable.
- LX_BLKPAG_OS_{READ,WRITE} are used only for debugging purposes,
and has been superseded by LX_BLKPAG_AF and LX_BLKPAG_DBM.
- Improve comment

The need for reference/modify emulation has been eliminated,
and access/permission faults have been reduced, however,
there has been little change in overall performance.


# 1.126 31-Jan-2022 ryo

Skip unnecessary PTE operations and TLB invalidation.


# 1.125 16-Jan-2022 rillig

aarch64/pmap: remove stray semicolon

No binary change.


# 1.124 15-Jan-2022 skrll

The translations that need invalidation are always last level so remove
the (dubious) logic around tracking the level. The "any level" TLB
invalidation maintenance operation are used, but this may change after
further testing.

before
======
1661.0u 420.2s 2:53.82 1197.3% 231+29k 10+33918io 102pf+0w
1646.8u 425.2s 2:52.96 1198.0% 232+29k 1+33937io 49pf+0w
1647.9u 425.7s 2:52.58 1201.6% 232+29k 0+33940io 32pf+0w

After
=====
1602.5u 420.8s 2:49.09 1196.6% 238+30k 24+33893io 54pf+0w
1600.7u 421.3s 2:51.53 1178.8% 238+30k 1+33914io 33pf+0w
1597.5u 424.3s 2:50.46 1186.1% 238+30k 0+33915io 17pf+0w

LGTM from ryo@


# 1.123 14-Jan-2022 skrll

Restore the previous pmap_remove_all behaviour as the new method meant
the n1sdp couldn't complete a build.

No noticeable change in kernel build performance.


# 1.122 04-Jan-2022 skrll

KNF


# 1.121 10-Dec-2021 andvar

s/occured/occurred/ in comments, log messages and man pages.


# 1.120 07-Dec-2021 andvar

fix various typos, mainly in comments.


# 1.119 23-Oct-2021 skrll

Fix non-UVMHIST build


# 1.118 16-Oct-2021 ryo

fix non-MULTIPROCESSOR build


# 1.117 10-Oct-2021 skrll

Use sys/uvm/pmap/pmap_tlb.c on Aarch64 in the same way that some Arm, MIPS,
and some PPC kernels do. This removes the limitation of 256 processes on
CPUs with 8bit ASID field, e.g. Apple M1.

Additionally the following changes have been made

- removed a couple of unnecessary aarch64_tlbi_all calls
- removed any invalidation after freeing page tables due to
_pmap_sweep_pdp. This was never necessary afaict.
- all kernel mappings are marked global and userland mapping not-global.

Performance testing hasn't show a significant difference. The data here
is from building a kernel on an lx2k system with nvme.

before
1489.6u 400.4s 2:40.65 1176.5% 228+224k 0+32289io 57pf+0w
1482.6u 403.2s 2:38.49 1189.9% 228+222k 0+32274io 46pf+0w
1485.4u 402.2s 2:37.27 1200.2% 228+222k 0+32275io 12pf+0w

after
1493.9u 404.6s 2:37.50 1205.4% 227+221k 0+32265io 48pf+0w
1485.0u 408.0s 2:38.54 1194.0% 227+222k 0+32272io 36pf+0w
1484.3u 407.0s 2:35.88 1213.3% 228+224k 0+32268io 14pf+0w

>>> stats.ttest_ind([160.65,158.49,157.27], [157.5,158.54,155.88])
Ttest_indResult(statistic=1.1923622711296888, pvalue=0.2990182944606766)
>>>


# 1.116 30-Sep-2021 skrll

Ensure TCR_EPD0 is set on entry to pmap_activate and ensure it is set as
early as possible for APs.


# 1.115 26-Sep-2021 skrll

Use UVMHIST_CALLARGS


# 1.114 26-Sep-2021 skrll

'\n' is not required in KASSERTMSG either.


# 1.113 26-Sep-2021 skrll

"\n" is not required in KERNHIST


# 1.112 15-Sep-2021 skrll

Use __SHIFTIN. Same code before and after.


# 1.111 12-Sep-2021 skrll

pmap_page_remove: simply and reduce the code size slightly.


# 1.110 09-Sep-2021 skrll

In pmap_icache_sync_range change

for (...) {
...
if (condition) {
// do stuff
}
}

to

for (...) {
...
if (!conditional)
continue;
// do stuff
}

to save on indentation. Same code (modulo register usage) before and
after.


# 1.109 09-Sep-2021 skrll

KNF


Revision tags: thorpej-i2c-spi-conf2-base thorpej-futex2-base thorpej-cfargs2-base cjep_sun2x-base1 cjep_sun2x-base cjep_staticlib_x-base1 thorpej-i2c-spi-conf-base
# 1.108 29-May-2021 skrll

Deal with the pmap limitation of maxproc in a more complete way and
recognise CPUs with only 8bit ASIDs.


Revision tags: cjep_staticlib_x-base
# 1.107 30-Apr-2021 skrll

branches: 1.107.2;
Make the ddb for pmap / pte information pmap agnostic


# 1.106 29-Apr-2021 skrll

Remove some unnecessary tlb invalidate in pmap_growkernel and ASAN shadow
map. Ensure the shadow map mappings are visible to the TLB walkers.


# 1.105 21-Apr-2021 ryo

branches: 1.105.2;
added more attributes of PTE displayed by "ddb>machine pte"


Revision tags: thorpej-cfargs-base
# 1.104 17-Apr-2021 mrg

remove KERNHIST_INIT_STATIC(). it stradles the line between usable
early in boot and broken early in boot by requiring a partly static
structure with another structure that must be present by the time
any uses are performed. theoretically platform code could allocate
a chunk while seting up memory and assign it here, giving a dynamic
sizing for the entry list, but the reality is that all users have
a statically allocated entry list as well.

the existing KERNHIST_LINK_STATIC() is used in conjunction with
KERNHIST_INITIALIZER() instead.

this stops a NULL pointer deref when the _LOG() macro is called
before the storage is linked in, which happens with GCC 10 on OCTEON
with UVMHIST enabled, crashing in very early kernel init.


Revision tags: thorpej-futex-base
# 1.103 09-Mar-2021 ryo

branches: 1.103.2;
fix build error without options DDB.

kvtopte() is referenced from arm/acpi/acpi_machdep.c


# 1.102 13-Feb-2021 ryo

No assignment is needed here.

the loop in pmap_page_remove() always removes the first pv,
and since the list is managed by _pmap_remove_pv(), pp->pp_pv.pv_next always points to the first.


# 1.101 01-Feb-2021 ryo

It is enough to make a page accessible instead of writable.
same fix as r1.76


# 1.100 31-Jan-2021 ryo

implement pmap_remove_all().

The size of struct pv_entry has increased, but speed of kernel build has improved by about 1%
exec and exit should have been improved.


# 1.99 20-Dec-2020 skrll

Improve the English in the previous comment fix.


# 1.98 19-Dec-2020 skrll

Tweak a comment


# 1.97 11-Dec-2020 skrll

s:aarch64/cpufunc.h:arm/cpufunc.h:

a baby step in the grand arm header unification challenge


# 1.96 10-Nov-2020 skrll

AA64 is not MIPS.

Change all KSEG references to directmap


# 1.95 07-Nov-2020 skrll

In pmap_devmap_bootstrap only set pmap_devmap_bootstrap_done if there
is an entry and ALL of the entries have been done. The entry required
for EARLYCONS might not be the first/only one...


# 1.94 01-Nov-2020 jmcneill

branches: 1.94.2;
No need to disable translation table walks in pmap_activate().


# 1.93 22-Oct-2020 skrll

Use the isb macro - missed in previous commit


# 1.92 22-Oct-2020 skrll

Use the dmb/dsb/isb macros... if nothing else they're all now consistent
about the "memory" assembler contraint.

No binary change


# 1.91 28-Sep-2020 skrll

Only set pmap_devmap_bootstrap_done if something gets mapped.

Think acpi_platform_devmap


# 1.90 19-Sep-2020 skrll

Make __md_palloc pmap agnostic (think sys/uvm/pmap)


# 1.89 14-Sep-2020 ryo

PID_MAX is just an initial value (soft maximum). Don't use it for CTASSERT.
defined __HAVE_CPU_MAXPROC to use function cpu_maxproc().

pointed out by mrg@, thanks.


# 1.88 06-Sep-2020 ryo

Fix panic caused by modload. http://mail-index.netbsd.org/port-arm/2020/08/30/msg006960.html

The address space reserved for modules may not be mapped in L1-L3.


# 1.87 14-Aug-2020 skrll

Whitespace


# 1.86 12-Aug-2020 skrll

Part IV of ad's performance improvements for aarch64

- Implement pmap_growkernel(), and update kernel pmap's stats with atomics.

- Then, pmap_kenter_pa() and pmap_kremove() no longer need to allocate
memory nor take pm_lock, because they only modify L3 PTEs.

- Then, pm_lock and pp_lock can be adaptive mutexes at IPL_NONE which are
cheaper than spin mutexes.

- Take the pmap's lock in pmap_extract() if not the kernel's pmap, otherwise
pmap_extract() might see inconsistent state.


# 1.85 09-Aug-2020 skrll

Fix another UVMHIST so it doesn't use %s


# 1.84 16-Jul-2020 skrll

pmapboot_enter simplication
- bootpage_alloc in asm becomes pmapboot_pagealloc in C
- PMAPBOOT_ENTER_NOBLOCK is removed as it's not used
- PMAPBOOT_ENTER_NOOVERWRITE is removed as it's now always on
- physpage_allocator argument is removed as it's always
pmapboot_pagealloc
- Support for EARLYCONS without CONSADDR is removed so that the identity
map for CONSADDR is always known.

For the assembly files:
2 files changed, 40 insertions(+), 89 deletions(-)

LGTM ryo


# 1.83 04-Jul-2020 rin

Use tlen for temporary length variable instead of l, which is usually
used for struct lwp *.

No binary changes.


# 1.82 02-Jul-2020 rin

pmap_procwr(): sync icache even if p != curproc. This fixes applications
like GDB for arm32, that rewrite text of other process.

Thanks to ryo@ for discussion.


# 1.81 02-Jul-2020 rin

Set uvmexp.ncolors appropriately, which is required for some CPU
models with VIPT icache.

Otherwise, alias in virtual address results in inconsistent results,
at least for applications that rewrite text of other process, e.g.,
GDB for arm32.

Also, this hopefully fixes other unexpected failures due to alias.

Confirmed that there's no observable regression in performance;
difference in ``time make -j8'' for GENERIC64 kernel on BCM2837
with and without setting uvmexp.ncolors is within 0.1%.

Thanks to ryo@ for discussion.


# 1.80 27-Jun-2020 rin

Fix typo in name of evcnt(4) counter.


# 1.79 24-Jun-2020 ryo

Fix bug with incorrect range calculation when doing icache sync.
This is called by sysarch(ARM_SYNC_ICACHE) from aarch32 (compat_netbsd32) emul process.

pointed out by rin@, thanks.

XXX pullup-9


# 1.78 14-Jun-2020 ad

- Fix a lock order reversal in pmap_page_protect().

- Make sure pmap is always locked when updating stats; atomics no longer
needed to do that.

- Remove unneeded traversal of pv list in pmap_enter_pv().

- Shrink struct vm_page from 136 to 128 bytes (cache line sized) and struct
pv_entry from 48 to 32 bytes (power of 2 sized).

- Embed a pv_entry in each vm_page. This means PV entries don't need to
be allocated for private anonymous memory / COW pages / most UBC mappings.
Dynamic PV entries are then used only for stuff like shared libraries and
shared memory.

Proposed on port-arm@.


# 1.77 10-Jun-2020 ad

- Wired/resident stats shouldn't covered by PMAPCOUNTERS.
- Rename need_update_pv -> need_enter_pv.

Ok ryo@


# 1.76 01-Jun-2020 ryo

no need to make the PTE writable to do icache_sync, enough to accessible.


# 1.75 15-May-2020 skrll

Use __diagused


# 1.74 15-May-2020 tnn

fix non-diag build


# 1.73 14-May-2020 skrll

Use MUTEX_NODEBUG for PV locks as is commonly done. OK ryo.


# 1.72 13-May-2020 jmcneill

Implement pmap_extract_coherency


Revision tags: bouyer-xenpvh-base2 phil-wifi-20200421 bouyer-xenpvh-base1
# 1.71 18-Apr-2020 skrll

PMAP_DEBUG has been deleted on arm


# 1.70 13-Apr-2020 maxv

Add support for Branch Target Identification (BTI).

On the executable pages that have the GP (Guarded Page) bit, the semantic
of the "br" and "blr" instructions is changed: the CPU expects the first
instruction of the jump/call target to be "bti", and faults if it isn't.

We add the GP bit on the kernel .text pages (and incidentally the .rodata
pages, but we don't care). The compiler adds a "bti c" instruction at the
beginning of each C function. We modify the ENTRY() macros to manually add
"bti c" in the asm functions.

cpuswitch.S needs a specific change: with "br x27" the CPU expects "bti j",
which is bad because the functions begin with "bti c"; switch to "br x16",
for the CPU to accept "bti c".

BTI helps defend against JOP/COP. Tested on Qemu.


Revision tags: phil-wifi-20200411 bouyer-xenpvh-base
# 1.69 08-Apr-2020 ryo

branches: 1.69.2;
use PMAP_PAGE_INIT() to initialize mutex in pmap_page.

VM_MDPAGE_INIT() in pmap_free_pdp() had initialized pp_flags,
so it unintentionally cleared PMAP_PAGE_FLAGS_PV_TRACKED.
use PMAP_PAGE_INIT to avoid using PMAP_PAGE_FLAGS_PV_TRACKED.

pointed out by tnn@, thanks


Revision tags: phil-wifi-20200406
# 1.68 14-Mar-2020 ad

pmap_remove_all(): Return a boolean value to indicate the behaviour. If
true, all mappings have been removed, the pmap is totally cleared out, and
UVM can then avoid doing the work to call pmap_remove() for each map entry.
If false, either nothing has been done, or some helpful arch-specific voodoo
has taken place.


Revision tags: is-mlppp-base
# 1.67 02-Mar-2020 ryo

oops, fix incorrect usage of daif_enable() in my previous commit.


# 1.66 29-Feb-2020 ryo

Fix pmap to work correctly with tagged addresses

- when fault, untag from address before passing to uvm/pmap functions
- pmap_extract() checks more strictly and consider the address tag


# 1.65 29-Feb-2020 ryo

use pmapboot_enter_range()


Revision tags: ad-namecache-base3
# 1.64 10-Feb-2020 ryo

use LIST(3) instead of TAILQ(3) to save one word in struct vm_page and struct pmap.

pointed out by riastradh@. thanks


# 1.63 03-Feb-2020 ryo

add support pmap_pv(9)

Patch originally from jmcneill@. thanks


# 1.62 03-Feb-2020 ryo

separate struct vm_page_md into vm_page_md and pmap_page
for preparation pmap_pv(9)


Revision tags: ad-namecache-base2 ad-namecache-base1
# 1.61 09-Jan-2020 ryo

fix behaviour mmap()/mprotect() when passed only PROT_EXEC.

when mmap()/mprotect() with only PROT_EXEC, syscall will be successful,
but the page actually hadn't been mapped.
it should be mapped with PROT_READ|PROT_EXEC implicitly. (r-x)


Revision tags: ad-namecache-base
# 1.60 30-Dec-2019 skrll

branches: 1.60.2;
Update pmap_map_chunk to allow L[12] block mappings and L3 page mappings


# 1.59 30-Dec-2019 skrll

Remove unnecessary brackets and unwrap a conditional. Same code before
and after.


# 1.58 28-Dec-2019 jmcneill

Do not use Early Write Acknowledge for PCIe I/O and config space.


# 1.57 27-Dec-2019 jmcneill

Enable early write acknowledge for device memory mappings.


# 1.56 19-Dec-2019 skrll

G/C kasan_shadow_map call in pmap_enter

pmap_growkernel calls kasan_shadow_map for KVA


# 1.55 18-Dec-2019 ryo

atomic_add_16() is not used in pmap.c anymore. no need decl here.


# 1.54 18-Dec-2019 ryo

space to tab


# 1.53 14-Dec-2019 skrll

Fix build... wire_count probably doesn't need atomics


# 1.52 13-Dec-2019 skrll

Fix KASAN support by calling kasan_shadow_map in pmap_growkernel


# 1.51 10-Dec-2019 ad

pg->phys_addr -> VM_PAGE_TO_PHYS(pg)


Revision tags: phil-wifi-20191119
# 1.50 14-Nov-2019 maxv

Mark several kASan functions with __nothing, to avoid annoying #ifdefs.
Same as kCSan and kMSan.


# 1.49 14-Nov-2019 maxv

Don't include "opt_kasan.h" when there's already <sys/asan.h> included.


# 1.48 29-Oct-2019 maya

Define PMAP_NEED_PROCWR, providing strategically placed i-cache
synchronization where just-changed memory is about to be executed.

Fixes SIGILLs seen when running Mono 6 on QEMU Cortex-A57.

ok ryo


# 1.47 22-Sep-2019 jmcneill

Disable translation table walks using TTBR0 while changing its value and
when deactivating a pmap. Fixes stability issues on Ampere eMAG CPUs.


# 1.46 20-Sep-2019 ryo

ref/mod bit should be set according to 'flags' argument, not 'prot'. r1.44 was incomplete.


# 1.45 13-Sep-2019 ryo

In pmap_devmap_bootstrap(), cpu_earlydevice_va_p() must not return true until *all* devmap tables have been enabled.
console mapping may be present in the last table.


# 1.44 07-Sep-2019 ryo

- remove incorrect KASSERT. mmap(2) with prot=PROT_WRITE calls pmap_enter(..., PROT_WRITE) internally.
- fix to update page reference flags when only PROT_WRITE or PROT_EXECUTE specified


# 1.43 15-Aug-2019 skrll

Make pmap_db_pte_print more terse so it's quicker on serial consoles


# 1.42 12-Aug-2019 skrll

Use PMAP_DEV in DEVMAP_ENTRY rather than pmap_map_chunk. It's clearer and
means pmap_map_chunk can be made to map other memory types.


Revision tags: netbsd-9-base phil-wifi-20190609
# 1.41 17-May-2019 mrg

branches: 1.41.2;
apply some __diagused.


Revision tags: isaki-audio2-base
# 1.40 08-Apr-2019 ryo

- free empty page tables pages if reach a certain usage.
- need to lock at removing an old pg (_pmap_remove_pv) in _pmap_enter()


# 1.39 06-Apr-2019 ryo

Fix race conditions about pmap_page_protect() and pmap_enter().

while handling same PTE by these functions in same time, there
is a critical path that the number of valid PTEs and wire_count
are inconsistent, and it caused KASSERT.
Need to hold a pv_lock while modifying them.


# 1.38 20-Mar-2019 ryo

spinkle __printflike(), and use PRIxxx


# 1.37 19-Mar-2019 ryo

- add ddb command "machine ttbr" to dump MMU tables.
- tidy up descriptions, usages and messages.


# 1.36 19-Mar-2019 ryo

- free L1-L3 pages that has been emptied by pmap_remove().
- if no memories, pmap_enter will return correctly ENOMEM if PMAP_CANFAIL, or wait until available any memories if !PMAP_CANFAIL.

These changes improves the stability when we use a huge virtual memory spaces with mmap.


# 1.35 06-Feb-2019 ryo

improve pmap_remove
- don't lock/unlock per page in pmap_remove()
- speedup pte lookup for continuous addresses
- bring out pool_cache_put(&_pmap_pv_pool, pv) from lock/unlock section


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226
# 1.34 21-Dec-2018 ryo

- add workaround for Cavium ThunderX errata 27456.
- add cpufuncs table in cpu_info. each cpu clusters may have different erratum. (e.g. big.LITTLE)


Revision tags: pgoyette-compat-1126
# 1.33 01-Nov-2018 maxv

Add kASan support for aarch64. Stack tracking needs more investigation
and will come in a separate commit.

Reviewed by ryo@ jmcneill@ skrll@.


# 1.32 31-Oct-2018 ryo

invalidate icache correctly.
l3pte_executable() should be used for only valid pte.


Revision tags: pgoyette-compat-1020
# 1.31 18-Oct-2018 skrll

Provide generic start code that assumes the MMU is off and caches are
disabled as per the linux booting protocol for ARMv6 and ARMv7 boards.
u-boot image type should be changed to 'linux' for correct behaviour.

The new start code builds a minimal "bootstrap" L1PT with cached access
disabled and uses the same table for all processors. AP startup is
performed in less steps and more code is written in C.

The bootstrap tables and stack are placed into an (orphaned) section
"_init_memory" which is given to uvm when it is no longer used.

Various kernels have been converted to use this code and tested. Some
boards were provided by TNF. Thanks!

The GENERIC kernel now boots on boards using the TEGRA, SUNXI and EXYNOS
kernels. The GENERIC kernel will also work on RPI2 using u-boot.

Thanks to martin@ and aymeric@ for testing on parallella and nanosoc
respectively


# 1.30 14-Oct-2018 skrll

Use __nothing


# 1.29 12-Oct-2018 ryo

add initial support of COMPAT_NETBSD32 on AArch64.
arm ELF32 EABI binaries could be execute in AArch32 state on AArch64. A32 THUMB mode is not supported yet.


# 1.28 12-Oct-2018 ryo

- cleanup checking address ranges with IN_RANGE macro
- change PM_ADDR_CHECK macro to KASSERTMSG
- restore fast lookup cases with IN_RANGE macro for pmap_extract changed in my previous commit.


# 1.27 12-Oct-2018 ryo

rewrite pmap_pte_lookup() to share similar code.


# 1.26 04-Oct-2018 ryo

cleanup locore, and changed the way to map memories during boot.
- add functions bootpage_enter() and bootpage_alloc() to adapt various layout
of physical memory map. especially for 64bit physical memory layout.
pmapboot_alloc() allocates pagetable pages from _end[].
- changed to map only the required amount for PA=VA identity mapping
(kernel image, UART device, and FDT blob) with L2_BLOCK(2Mbyte).
- changing page permission for kernel image, and making KSEG mapping are done
at cpu_kernel_vm_init() instead of at locore.
- optimize PTE entries with PTE Contiguous bit. it is enabled on devmap only for now.

reviewed by skrll@, thanks.


# 1.25 04-Oct-2018 ryo

* define LX_BLKPAG_{OS,ATTR}_* for OS dependent PTE attributes in pmap.h
* cleanup macros


Revision tags: pgoyette-compat-0930
# 1.24 17-Sep-2018 ryo

delete debug printf and KASSERT.


# 1.23 10-Sep-2018 maxv

Replace KDASSERT by panic.


# 1.22 10-Sep-2018 maxv

Rename _pmap_alloc_pdp -> pmap_alloc_pdp, and make it public.


# 1.21 10-Sep-2018 ryo

cleanup aarch64 mpstart and fdt bootstrap
* arm_cpu_hatch_arg is a bad idea. avoid serializing CPU startup, and eliminate arm_cpu_hatch_arg.
in mpstart, resolve own cpu index using array of cpu_mpidr[] (aarch64)
* add support fdt enable-method "spin-table"
* add support fdt enable-method "brcm,bcm2836-smp" (for 32bit RaspberryPi)
* use arm_fdt_cpu_bootstrap() instead of psci_fdt_bootstrap()
* rename "arm/fdt/psci_fdt.h" to "arm/fdt/psci_fdtvar.h" because of conflict of include file for needs-flag
* add devmap for cpu spin-table of raspberrypi3/aarch64
* no need to force hatch APs for raspberrypi3/arm32 ifndef MULTIPROCESSOR.
* fix to work pmap_extract(kerneltext/data/bss) even if before calling pmap_bootstrap

idea to use cpu_mpidr[] by jmcneill@. reviewd by skrll@. thanks.


Revision tags: pgoyette-compat-0906
# 1.20 27-Aug-2018 ryo

need to add VM_PROT_READ when pmap_kenter_pa(va, pa, VM_PROT_WRITE, 0) or pmap_kenter_pa(va, pa, VM_PROT_EXECUTE, 0).
VM_PROT_READ is treated as an access permission inernally.


# 1.19 11-Aug-2018 ryo

change to minimum invalidation of TLB.
specifying not only va but also asid, and not invalidate L0-L2 entry using tlbi_*_ll() if needed.


# 1.18 10-Aug-2018 ryo

treat kernel-exec attr and user-exec attr separately.
kernel cannot execute userland exec page, and user cannot execute kernel page.


# 1.17 06-Aug-2018 ryo

set kernel text/rodata readonly by default.
add function db_write_text() for setting ddb breakpoint.


# 1.16 31-Jul-2018 skrll

Define and use VPRINTF


Revision tags: pgoyette-compat-0728
# 1.15 27-Jul-2018 ryo

changes of pmap.c r1.13 seems to be unstable.
In order to invalidate icache, not to invalidate all icache,
but temporary to make the page writable and invalidate target address only.


# 1.14 24-Jul-2018 ryo

don't call pool_cache_put with locking pmap. pool_cache_put call pmap_kenter_pa internally.
(pool_cache_put_paddr -> pool_cache_put_slow -> pool_get -> pmap_kenter_pa)


# 1.13 23-Jul-2018 ryo

* fix icache invalidations.
* "ic ivau" (aarch64_icache_sync_range) with VA generates permission fault in some situations, therefore use KSEG address for now.


# 1.12 23-Jul-2018 ryo

rather than using flags to resolve nested locks, reserve pool_cache before locking.


# 1.11 21-Jul-2018 ryo

* avoid deadlock. mutex_owned() works only for adaptive lock, therefore we cannot use it for spinlock...
* add more NULL check
* clear pte when pmap_enter() fails


# 1.10 17-Jul-2018 ryo

Use __debugused


# 1.9 17-Jul-2018 christos

Add missing casts, remove unused variables.


# 1.8 09-Jul-2018 ryo

need locks in pmap_kremove() and pmap_fault_fixup()


Revision tags: phil-wifi-base pgoyette-compat-0625 pgoyette-compat-0521
# 1.7 20-May-2018 ryo

branches: 1.7.2;
pmap_enter() must update modified/referenced flags by 'flags' not 'prot'.


# 1.6 16-May-2018 ryo

Fix memory leak. it was leaking one page every pmap_create().
pm->pm_vmlist must be initialized before calling _pmap_alloc_pdp().


Revision tags: pgoyette-compat-0502
# 1.5 29-Apr-2018 ryo

fix KASSERT panic. pv_entry may not be exists in pvlist when pmap_remove().


# 1.4 29-Apr-2018 ryo

delete unused code


# 1.3 27-Apr-2018 ryo

fix instability behavior of bufcache on aarch64.
* fix to return correct ref/mod when PMAP_WIRED.
* changed to keep wired flags in pte instead of pv_entry, and cleanup.


Revision tags: pgoyette-compat-0422 pgoyette-compat-0415 pgoyette-compat-0407
# 1.2 01-Apr-2018 ryo

Add initial support for ARMv8 (AARCH64) (by nisimura@ and ryo@)

- sys/arch/evbarm64 is gone and integrated into sys/arch/evbarm. (by skrll@)
- add support fdt. evbarm/conf/GENERIC64 fdt (bcm2837,sunxi,tegra) based generic 64bit kernel config. (by skrll@, jmcneill@)


Revision tags: netbsd-8-2-RELEASE netbsd-8-1-RELEASE netbsd-8-1-RC1 netbsd-7-2-RELEASE netbsd-8-0-RELEASE netbsd-8-0-RC2 netbsd-8-0-RC1 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 netbsd-7-1-2-RELEASE pgoyette-compat-base netbsd-7-1-1-RELEASE tls-maxphys-base-20171202 matt-nb8-mediatek-base nick-nhusb-base-20170825 perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base pgoyette-localcount-20170320 netbsd-7-1-RELEASE netbsd-7-1-RC2 nick-nhusb-base-20170204 netbsd-7-nhusb-base-20170116 bouyer-socketcan-base pgoyette-localcount-20170107 netbsd-7-1-RC1 nick-nhusb-base-20161204 pgoyette-localcount-20161104 netbsd-7-0-2-RELEASE nick-nhusb-base-20161004 localcount-20160914 netbsd-7-nhusb-base pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907 nick-nhusb-base-20160529 netbsd-7-0-1-RELEASE nick-nhusb-base-20160422 nick-nhusb-base-20160319 nick-nhusb-base-20151226 netbsd-7-0-RELEASE nick-nhusb-base-20150921 netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 nick-nhusb-base-20150606 nick-nhusb-base-20150406 nick-nhusb-base tls-maxphys-base netbsd-7-base
# 1.1 10-Aug-2014 matt

branches: 1.1.4; 1.1.28;
Preliminary files for AARCH64 (64-bit ARM) support.
Enough for a distribution build.


# 1.127 31-Jan-2022 ryo

add support Hardware updates to Access flag and Dirty state (FEAT_HAFDBS)

- The DBM bit of the PTE is now used to determine if it is writable, and
the AF bit is treated entirely as a reference bit. A valid PTE is always
treated as readable. There can be no valid PTE that is not readable.
- LX_BLKPAG_OS_{READ,WRITE} are used only for debugging purposes,
and has been superseded by LX_BLKPAG_AF and LX_BLKPAG_DBM.
- Improve comment

The need for reference/modify emulation has been eliminated,
and access/permission faults have been reduced, however,
there has been little change in overall performance.


# 1.126 31-Jan-2022 ryo

Skip unnecessary PTE operations and TLB invalidation.


# 1.125 16-Jan-2022 rillig

aarch64/pmap: remove stray semicolon

No binary change.


# 1.124 15-Jan-2022 skrll

The translations that need invalidation are always last level so remove
the (dubious) logic around tracking the level. The "any level" TLB
invalidation maintenance operation are used, but this may change after
further testing.

before
======
1661.0u 420.2s 2:53.82 1197.3% 231+29k 10+33918io 102pf+0w
1646.8u 425.2s 2:52.96 1198.0% 232+29k 1+33937io 49pf+0w
1647.9u 425.7s 2:52.58 1201.6% 232+29k 0+33940io 32pf+0w

After
=====
1602.5u 420.8s 2:49.09 1196.6% 238+30k 24+33893io 54pf+0w
1600.7u 421.3s 2:51.53 1178.8% 238+30k 1+33914io 33pf+0w
1597.5u 424.3s 2:50.46 1186.1% 238+30k 0+33915io 17pf+0w

LGTM from ryo@


# 1.123 14-Jan-2022 skrll

Restore the previous pmap_remove_all behaviour as the new method meant
the n1sdp couldn't complete a build.

No noticeable change in kernel build performance.


# 1.122 04-Jan-2022 skrll

KNF


# 1.121 10-Dec-2021 andvar

s/occured/occurred/ in comments, log messages and man pages.


# 1.120 07-Dec-2021 andvar

fix various typos, mainly in comments.


# 1.119 23-Oct-2021 skrll

Fix non-UVMHIST build


# 1.118 16-Oct-2021 ryo

fix non-MULTIPROCESSOR build


# 1.117 10-Oct-2021 skrll

Use sys/uvm/pmap/pmap_tlb.c on Aarch64 in the same way that some Arm, MIPS,
and some PPC kernels do. This removes the limitation of 256 processes on
CPUs with 8bit ASID field, e.g. Apple M1.

Additionally the following changes have been made

- removed a couple of unnecessary aarch64_tlbi_all calls
- removed any invalidation after freeing page tables due to
_pmap_sweep_pdp. This was never necessary afaict.
- all kernel mappings are marked global and userland mapping not-global.

Performance testing hasn't show a significant difference. The data here
is from building a kernel on an lx2k system with nvme.

before
1489.6u 400.4s 2:40.65 1176.5% 228+224k 0+32289io 57pf+0w
1482.6u 403.2s 2:38.49 1189.9% 228+222k 0+32274io 46pf+0w
1485.4u 402.2s 2:37.27 1200.2% 228+222k 0+32275io 12pf+0w

after
1493.9u 404.6s 2:37.50 1205.4% 227+221k 0+32265io 48pf+0w
1485.0u 408.0s 2:38.54 1194.0% 227+222k 0+32272io 36pf+0w
1484.3u 407.0s 2:35.88 1213.3% 228+224k 0+32268io 14pf+0w

>>> stats.ttest_ind([160.65,158.49,157.27], [157.5,158.54,155.88])
Ttest_indResult(statistic=1.1923622711296888, pvalue=0.2990182944606766)
>>>


# 1.116 30-Sep-2021 skrll

Ensure TCR_EPD0 is set on entry to pmap_activate and ensure it is set as
early as possible for APs.


# 1.115 26-Sep-2021 skrll

Use UVMHIST_CALLARGS


# 1.114 26-Sep-2021 skrll

'\n' is not required in KASSERTMSG either.


# 1.113 26-Sep-2021 skrll

"\n" is not required in KERNHIST


# 1.112 15-Sep-2021 skrll

Use __SHIFTIN. Same code before and after.


# 1.111 12-Sep-2021 skrll

pmap_page_remove: simply and reduce the code size slightly.


# 1.110 09-Sep-2021 skrll

In pmap_icache_sync_range change

for (...) {
...
if (condition) {
// do stuff
}
}

to

for (...) {
...
if (!conditional)
continue;
// do stuff
}

to save on indentation. Same code (modulo register usage) before and
after.


# 1.109 09-Sep-2021 skrll

KNF


Revision tags: thorpej-i2c-spi-conf2-base thorpej-futex2-base thorpej-cfargs2-base cjep_sun2x-base1 cjep_sun2x-base cjep_staticlib_x-base1 thorpej-i2c-spi-conf-base
# 1.108 29-May-2021 skrll

Deal with the pmap limitation of maxproc in a more complete way and
recognise CPUs with only 8bit ASIDs.


Revision tags: cjep_staticlib_x-base
# 1.107 30-Apr-2021 skrll

branches: 1.107.2;
Make the ddb for pmap / pte information pmap agnostic


# 1.106 29-Apr-2021 skrll

Remove some unnecessary tlb invalidate in pmap_growkernel and ASAN shadow
map. Ensure the shadow map mappings are visible to the TLB walkers.


# 1.105 21-Apr-2021 ryo

branches: 1.105.2;
added more attributes of PTE displayed by "ddb>machine pte"


Revision tags: thorpej-cfargs-base
# 1.104 17-Apr-2021 mrg

remove KERNHIST_INIT_STATIC(). it stradles the line between usable
early in boot and broken early in boot by requiring a partly static
structure with another structure that must be present by the time
any uses are performed. theoretically platform code could allocate
a chunk while seting up memory and assign it here, giving a dynamic
sizing for the entry list, but the reality is that all users have
a statically allocated entry list as well.

the existing KERNHIST_LINK_STATIC() is used in conjunction with
KERNHIST_INITIALIZER() instead.

this stops a NULL pointer deref when the _LOG() macro is called
before the storage is linked in, which happens with GCC 10 on OCTEON
with UVMHIST enabled, crashing in very early kernel init.


Revision tags: thorpej-futex-base
# 1.103 09-Mar-2021 ryo

branches: 1.103.2;
fix build error without options DDB.

kvtopte() is referenced from arm/acpi/acpi_machdep.c


# 1.102 13-Feb-2021 ryo

No assignment is needed here.

the loop in pmap_page_remove() always removes the first pv,
and since the list is managed by _pmap_remove_pv(), pp->pp_pv.pv_next always points to the first.


# 1.101 01-Feb-2021 ryo

It is enough to make a page accessible instead of writable.
same fix as r1.76


# 1.100 31-Jan-2021 ryo

implement pmap_remove_all().

The size of struct pv_entry has increased, but speed of kernel build has improved by about 1%
exec and exit should have been improved.


# 1.99 20-Dec-2020 skrll

Improve the English in the previous comment fix.


# 1.98 19-Dec-2020 skrll

Tweak a comment


# 1.97 11-Dec-2020 skrll

s:aarch64/cpufunc.h:arm/cpufunc.h:

a baby step in the grand arm header unification challenge


# 1.96 10-Nov-2020 skrll

AA64 is not MIPS.

Change all KSEG references to directmap


# 1.95 07-Nov-2020 skrll

In pmap_devmap_bootstrap only set pmap_devmap_bootstrap_done if there
is an entry and ALL of the entries have been done. The entry required
for EARLYCONS might not be the first/only one...


# 1.94 01-Nov-2020 jmcneill

branches: 1.94.2;
No need to disable translation table walks in pmap_activate().


# 1.93 22-Oct-2020 skrll

Use the isb macro - missed in previous commit


# 1.92 22-Oct-2020 skrll

Use the dmb/dsb/isb macros... if nothing else they're all now consistent
about the "memory" assembler contraint.

No binary change


# 1.91 28-Sep-2020 skrll

Only set pmap_devmap_bootstrap_done if something gets mapped.

Think acpi_platform_devmap


# 1.90 19-Sep-2020 skrll

Make __md_palloc pmap agnostic (think sys/uvm/pmap)


# 1.89 14-Sep-2020 ryo

PID_MAX is just an initial value (soft maximum). Don't use it for CTASSERT.
defined __HAVE_CPU_MAXPROC to use function cpu_maxproc().

pointed out by mrg@, thanks.


# 1.88 06-Sep-2020 ryo

Fix panic caused by modload. http://mail-index.netbsd.org/port-arm/2020/08/30/msg006960.html

The address space reserved for modules may not be mapped in L1-L3.


# 1.87 14-Aug-2020 skrll

Whitespace


# 1.86 12-Aug-2020 skrll

Part IV of ad's performance improvements for aarch64

- Implement pmap_growkernel(), and update kernel pmap's stats with atomics.

- Then, pmap_kenter_pa() and pmap_kremove() no longer need to allocate
memory nor take pm_lock, because they only modify L3 PTEs.

- Then, pm_lock and pp_lock can be adaptive mutexes at IPL_NONE which are
cheaper than spin mutexes.

- Take the pmap's lock in pmap_extract() if not the kernel's pmap, otherwise
pmap_extract() might see inconsistent state.


# 1.85 09-Aug-2020 skrll

Fix another UVMHIST so it doesn't use %s


# 1.84 16-Jul-2020 skrll

pmapboot_enter simplication
- bootpage_alloc in asm becomes pmapboot_pagealloc in C
- PMAPBOOT_ENTER_NOBLOCK is removed as it's not used
- PMAPBOOT_ENTER_NOOVERWRITE is removed as it's now always on
- physpage_allocator argument is removed as it's always
pmapboot_pagealloc
- Support for EARLYCONS without CONSADDR is removed so that the identity
map for CONSADDR is always known.

For the assembly files:
2 files changed, 40 insertions(+), 89 deletions(-)

LGTM ryo


# 1.83 04-Jul-2020 rin

Use tlen for temporary length variable instead of l, which is usually
used for struct lwp *.

No binary changes.


# 1.82 02-Jul-2020 rin

pmap_procwr(): sync icache even if p != curproc. This fixes applications
like GDB for arm32, that rewrite text of other process.

Thanks to ryo@ for discussion.


# 1.81 02-Jul-2020 rin

Set uvmexp.ncolors appropriately, which is required for some CPU
models with VIPT icache.

Otherwise, alias in virtual address results in inconsistent results,
at least for applications that rewrite text of other process, e.g.,
GDB for arm32.

Also, this hopefully fixes other unexpected failures due to alias.

Confirmed that there's no observable regression in performance;
difference in ``time make -j8'' for GENERIC64 kernel on BCM2837
with and without setting uvmexp.ncolors is within 0.1%.

Thanks to ryo@ for discussion.


# 1.80 27-Jun-2020 rin

Fix typo in name of evcnt(4) counter.


# 1.79 24-Jun-2020 ryo

Fix bug with incorrect range calculation when doing icache sync.
This is called by sysarch(ARM_SYNC_ICACHE) from aarch32 (compat_netbsd32) emul process.

pointed out by rin@, thanks.

XXX pullup-9


# 1.78 14-Jun-2020 ad

- Fix a lock order reversal in pmap_page_protect().

- Make sure pmap is always locked when updating stats; atomics no longer
needed to do that.

- Remove unneeded traversal of pv list in pmap_enter_pv().

- Shrink struct vm_page from 136 to 128 bytes (cache line sized) and struct
pv_entry from 48 to 32 bytes (power of 2 sized).

- Embed a pv_entry in each vm_page. This means PV entries don't need to
be allocated for private anonymous memory / COW pages / most UBC mappings.
Dynamic PV entries are then used only for stuff like shared libraries and
shared memory.

Proposed on port-arm@.


# 1.77 10-Jun-2020 ad

- Wired/resident stats shouldn't covered by PMAPCOUNTERS.
- Rename need_update_pv -> need_enter_pv.

Ok ryo@


# 1.76 01-Jun-2020 ryo

no need to make the PTE writable to do icache_sync, enough to accessible.


# 1.75 15-May-2020 skrll

Use __diagused


# 1.74 15-May-2020 tnn

fix non-diag build


# 1.73 14-May-2020 skrll

Use MUTEX_NODEBUG for PV locks as is commonly done. OK ryo.


# 1.72 13-May-2020 jmcneill

Implement pmap_extract_coherency


Revision tags: bouyer-xenpvh-base2 phil-wifi-20200421 bouyer-xenpvh-base1
# 1.71 18-Apr-2020 skrll

PMAP_DEBUG has been deleted on arm


# 1.70 13-Apr-2020 maxv

Add support for Branch Target Identification (BTI).

On the executable pages that have the GP (Guarded Page) bit, the semantic
of the "br" and "blr" instructions is changed: the CPU expects the first
instruction of the jump/call target to be "bti", and faults if it isn't.

We add the GP bit on the kernel .text pages (and incidentally the .rodata
pages, but we don't care). The compiler adds a "bti c" instruction at the
beginning of each C function. We modify the ENTRY() macros to manually add
"bti c" in the asm functions.

cpuswitch.S needs a specific change: with "br x27" the CPU expects "bti j",
which is bad because the functions begin with "bti c"; switch to "br x16",
for the CPU to accept "bti c".

BTI helps defend against JOP/COP. Tested on Qemu.


Revision tags: phil-wifi-20200411 bouyer-xenpvh-base
# 1.69 08-Apr-2020 ryo

branches: 1.69.2;
use PMAP_PAGE_INIT() to initialize mutex in pmap_page.

VM_MDPAGE_INIT() in pmap_free_pdp() had initialized pp_flags,
so it unintentionally cleared PMAP_PAGE_FLAGS_PV_TRACKED.
use PMAP_PAGE_INIT to avoid using PMAP_PAGE_FLAGS_PV_TRACKED.

pointed out by tnn@, thanks


Revision tags: phil-wifi-20200406
# 1.68 14-Mar-2020 ad

pmap_remove_all(): Return a boolean value to indicate the behaviour. If
true, all mappings have been removed, the pmap is totally cleared out, and
UVM can then avoid doing the work to call pmap_remove() for each map entry.
If false, either nothing has been done, or some helpful arch-specific voodoo
has taken place.


Revision tags: is-mlppp-base
# 1.67 02-Mar-2020 ryo

oops, fix incorrect usage of daif_enable() in my previous commit.


# 1.66 29-Feb-2020 ryo

Fix pmap to work correctly with tagged addresses

- when fault, untag from address before passing to uvm/pmap functions
- pmap_extract() checks more strictly and consider the address tag


# 1.65 29-Feb-2020 ryo

use pmapboot_enter_range()


Revision tags: ad-namecache-base3
# 1.64 10-Feb-2020 ryo

use LIST(3) instead of TAILQ(3) to save one word in struct vm_page and struct pmap.

pointed out by riastradh@. thanks


# 1.63 03-Feb-2020 ryo

add support pmap_pv(9)

Patch originally from jmcneill@. thanks


# 1.62 03-Feb-2020 ryo

separate struct vm_page_md into vm_page_md and pmap_page
for preparation pmap_pv(9)


Revision tags: ad-namecache-base2 ad-namecache-base1
# 1.61 09-Jan-2020 ryo

fix behaviour mmap()/mprotect() when passed only PROT_EXEC.

when mmap()/mprotect() with only PROT_EXEC, syscall will be successful,
but the page actually hadn't been mapped.
it should be mapped with PROT_READ|PROT_EXEC implicitly. (r-x)


Revision tags: ad-namecache-base
# 1.60 30-Dec-2019 skrll

branches: 1.60.2;
Update pmap_map_chunk to allow L[12] block mappings and L3 page mappings


# 1.59 30-Dec-2019 skrll

Remove unnecessary brackets and unwrap a conditional. Same code before
and after.


# 1.58 28-Dec-2019 jmcneill

Do not use Early Write Acknowledge for PCIe I/O and config space.


# 1.57 27-Dec-2019 jmcneill

Enable early write acknowledge for device memory mappings.


# 1.56 19-Dec-2019 skrll

G/C kasan_shadow_map call in pmap_enter

pmap_growkernel calls kasan_shadow_map for KVA


# 1.55 18-Dec-2019 ryo

atomic_add_16() is not used in pmap.c anymore. no need decl here.


# 1.54 18-Dec-2019 ryo

space to tab


# 1.53 14-Dec-2019 skrll

Fix build... wire_count probably doesn't need atomics


# 1.52 13-Dec-2019 skrll

Fix KASAN support by calling kasan_shadow_map in pmap_growkernel


# 1.51 10-Dec-2019 ad

pg->phys_addr -> VM_PAGE_TO_PHYS(pg)


Revision tags: phil-wifi-20191119
# 1.50 14-Nov-2019 maxv

Mark several kASan functions with __nothing, to avoid annoying #ifdefs.
Same as kCSan and kMSan.


# 1.49 14-Nov-2019 maxv

Don't include "opt_kasan.h" when there's already <sys/asan.h> included.


# 1.48 29-Oct-2019 maya

Define PMAP_NEED_PROCWR, providing strategically placed i-cache
synchronization where just-changed memory is about to be executed.

Fixes SIGILLs seen when running Mono 6 on QEMU Cortex-A57.

ok ryo


# 1.47 22-Sep-2019 jmcneill

Disable translation table walks using TTBR0 while changing its value and
when deactivating a pmap. Fixes stability issues on Ampere eMAG CPUs.


# 1.46 20-Sep-2019 ryo

ref/mod bit should be set according to 'flags' argument, not 'prot'. r1.44 was incomplete.


# 1.45 13-Sep-2019 ryo

In pmap_devmap_bootstrap(), cpu_earlydevice_va_p() must not return true until *all* devmap tables have been enabled.
console mapping may be present in the last table.


# 1.44 07-Sep-2019 ryo

- remove incorrect KASSERT. mmap(2) with prot=PROT_WRITE calls pmap_enter(..., PROT_WRITE) internally.
- fix to update page reference flags when only PROT_WRITE or PROT_EXECUTE specified


# 1.43 15-Aug-2019 skrll

Make pmap_db_pte_print more terse so it's quicker on serial consoles


# 1.42 12-Aug-2019 skrll

Use PMAP_DEV in DEVMAP_ENTRY rather than pmap_map_chunk. It's clearer and
means pmap_map_chunk can be made to map other memory types.


Revision tags: netbsd-9-base phil-wifi-20190609
# 1.41 17-May-2019 mrg

branches: 1.41.2;
apply some __diagused.


Revision tags: isaki-audio2-base
# 1.40 08-Apr-2019 ryo

- free empty page tables pages if reach a certain usage.
- need to lock at removing an old pg (_pmap_remove_pv) in _pmap_enter()


# 1.39 06-Apr-2019 ryo

Fix race conditions about pmap_page_protect() and pmap_enter().

while handling same PTE by these functions in same time, there
is a critical path that the number of valid PTEs and wire_count
are inconsistent, and it caused KASSERT.
Need to hold a pv_lock while modifying them.


# 1.38 20-Mar-2019 ryo

spinkle __printflike(), and use PRIxxx


# 1.37 19-Mar-2019 ryo

- add ddb command "machine ttbr" to dump MMU tables.
- tidy up descriptions, usages and messages.


# 1.36 19-Mar-2019 ryo

- free L1-L3 pages that has been emptied by pmap_remove().
- if no memories, pmap_enter will return correctly ENOMEM if PMAP_CANFAIL, or wait until available any memories if !PMAP_CANFAIL.

These changes improves the stability when we use a huge virtual memory spaces with mmap.


# 1.35 06-Feb-2019 ryo

improve pmap_remove
- don't lock/unlock per page in pmap_remove()
- speedup pte lookup for continuous addresses
- bring out pool_cache_put(&_pmap_pv_pool, pv) from lock/unlock section


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226
# 1.34 21-Dec-2018 ryo

- add workaround for Cavium ThunderX errata 27456.
- add cpufuncs table in cpu_info. each cpu clusters may have different erratum. (e.g. big.LITTLE)


Revision tags: pgoyette-compat-1126
# 1.33 01-Nov-2018 maxv

Add kASan support for aarch64. Stack tracking needs more investigation
and will come in a separate commit.

Reviewed by ryo@ jmcneill@ skrll@.


# 1.32 31-Oct-2018 ryo

invalidate icache correctly.
l3pte_executable() should be used for only valid pte.


Revision tags: pgoyette-compat-1020
# 1.31 18-Oct-2018 skrll

Provide generic start code that assumes the MMU is off and caches are
disabled as per the linux booting protocol for ARMv6 and ARMv7 boards.
u-boot image type should be changed to 'linux' for correct behaviour.

The new start code builds a minimal "bootstrap" L1PT with cached access
disabled and uses the same table for all processors. AP startup is
performed in less steps and more code is written in C.

The bootstrap tables and stack are placed into an (orphaned) section
"_init_memory" which is given to uvm when it is no longer used.

Various kernels have been converted to use this code and tested. Some
boards were provided by TNF. Thanks!

The GENERIC kernel now boots on boards using the TEGRA, SUNXI and EXYNOS
kernels. The GENERIC kernel will also work on RPI2 using u-boot.

Thanks to martin@ and aymeric@ for testing on parallella and nanosoc
respectively


# 1.30 14-Oct-2018 skrll

Use __nothing


# 1.29 12-Oct-2018 ryo

add initial support of COMPAT_NETBSD32 on AArch64.
arm ELF32 EABI binaries could be execute in AArch32 state on AArch64. A32 THUMB mode is not supported yet.


# 1.28 12-Oct-2018 ryo

- cleanup checking address ranges with IN_RANGE macro
- change PM_ADDR_CHECK macro to KASSERTMSG
- restore fast lookup cases with IN_RANGE macro for pmap_extract changed in my previous commit.


# 1.27 12-Oct-2018 ryo

rewrite pmap_pte_lookup() to share similar code.


# 1.26 04-Oct-2018 ryo

cleanup locore, and changed the way to map memories during boot.
- add functions bootpage_enter() and bootpage_alloc() to adapt various layout
of physical memory map. especially for 64bit physical memory layout.
pmapboot_alloc() allocates pagetable pages from _end[].
- changed to map only the required amount for PA=VA identity mapping
(kernel image, UART device, and FDT blob) with L2_BLOCK(2Mbyte).
- changing page permission for kernel image, and making KSEG mapping are done
at cpu_kernel_vm_init() instead of at locore.
- optimize PTE entries with PTE Contiguous bit. it is enabled on devmap only for now.

reviewed by skrll@, thanks.


# 1.25 04-Oct-2018 ryo

* define LX_BLKPAG_{OS,ATTR}_* for OS dependent PTE attributes in pmap.h
* cleanup macros


Revision tags: pgoyette-compat-0930
# 1.24 17-Sep-2018 ryo

delete debug printf and KASSERT.


# 1.23 10-Sep-2018 maxv

Replace KDASSERT by panic.


# 1.22 10-Sep-2018 maxv

Rename _pmap_alloc_pdp -> pmap_alloc_pdp, and make it public.


# 1.21 10-Sep-2018 ryo

cleanup aarch64 mpstart and fdt bootstrap
* arm_cpu_hatch_arg is a bad idea. avoid serializing CPU startup, and eliminate arm_cpu_hatch_arg.
in mpstart, resolve own cpu index using array of cpu_mpidr[] (aarch64)
* add support fdt enable-method "spin-table"
* add support fdt enable-method "brcm,bcm2836-smp" (for 32bit RaspberryPi)
* use arm_fdt_cpu_bootstrap() instead of psci_fdt_bootstrap()
* rename "arm/fdt/psci_fdt.h" to "arm/fdt/psci_fdtvar.h" because of conflict of include file for needs-flag
* add devmap for cpu spin-table of raspberrypi3/aarch64
* no need to force hatch APs for raspberrypi3/arm32 ifndef MULTIPROCESSOR.
* fix to work pmap_extract(kerneltext/data/bss) even if before calling pmap_bootstrap

idea to use cpu_mpidr[] by jmcneill@. reviewd by skrll@. thanks.


Revision tags: pgoyette-compat-0906
# 1.20 27-Aug-2018 ryo

need to add VM_PROT_READ when pmap_kenter_pa(va, pa, VM_PROT_WRITE, 0) or pmap_kenter_pa(va, pa, VM_PROT_EXECUTE, 0).
VM_PROT_READ is treated as an access permission inernally.


# 1.19 11-Aug-2018 ryo

change to minimum invalidation of TLB.
specifying not only va but also asid, and not invalidate L0-L2 entry using tlbi_*_ll() if needed.


# 1.18 10-Aug-2018 ryo

treat kernel-exec attr and user-exec attr separately.
kernel cannot execute userland exec page, and user cannot execute kernel page.


# 1.17 06-Aug-2018 ryo

set kernel text/rodata readonly by default.
add function db_write_text() for setting ddb breakpoint.


# 1.16 31-Jul-2018 skrll

Define and use VPRINTF


Revision tags: pgoyette-compat-0728
# 1.15 27-Jul-2018 ryo

changes of pmap.c r1.13 seems to be unstable.
In order to invalidate icache, not to invalidate all icache,
but temporary to make the page writable and invalidate target address only.


# 1.14 24-Jul-2018 ryo

don't call pool_cache_put with locking pmap. pool_cache_put call pmap_kenter_pa internally.
(pool_cache_put_paddr -> pool_cache_put_slow -> pool_get -> pmap_kenter_pa)


# 1.13 23-Jul-2018 ryo

* fix icache invalidations.
* "ic ivau" (aarch64_icache_sync_range) with VA generates permission fault in some situations, therefore use KSEG address for now.


# 1.12 23-Jul-2018 ryo

rather than using flags to resolve nested locks, reserve pool_cache before locking.


# 1.11 21-Jul-2018 ryo

* avoid deadlock. mutex_owned() works only for adaptive lock, therefore we cannot use it for spinlock...
* add more NULL check
* clear pte when pmap_enter() fails


# 1.10 17-Jul-2018 ryo

Use __debugused


# 1.9 17-Jul-2018 christos

Add missing casts, remove unused variables.


# 1.8 09-Jul-2018 ryo

need locks in pmap_kremove() and pmap_fault_fixup()


Revision tags: phil-wifi-base pgoyette-compat-0625 pgoyette-compat-0521
# 1.7 20-May-2018 ryo

branches: 1.7.2;
pmap_enter() must update modified/referenced flags by 'flags' not 'prot'.


# 1.6 16-May-2018 ryo

Fix memory leak. it was leaking one page every pmap_create().
pm->pm_vmlist must be initialized before calling _pmap_alloc_pdp().


Revision tags: pgoyette-compat-0502
# 1.5 29-Apr-2018 ryo

fix KASSERT panic. pv_entry may not be exists in pvlist when pmap_remove().


# 1.4 29-Apr-2018 ryo

delete unused code


# 1.3 27-Apr-2018 ryo

fix instability behavior of bufcache on aarch64.
* fix to return correct ref/mod when PMAP_WIRED.
* changed to keep wired flags in pte instead of pv_entry, and cleanup.


Revision tags: pgoyette-compat-0422 pgoyette-compat-0415 pgoyette-compat-0407
# 1.2 01-Apr-2018 ryo

Add initial support for ARMv8 (AARCH64) (by nisimura@ and ryo@)

- sys/arch/evbarm64 is gone and integrated into sys/arch/evbarm. (by skrll@)
- add support fdt. evbarm/conf/GENERIC64 fdt (bcm2837,sunxi,tegra) based generic 64bit kernel config. (by skrll@, jmcneill@)


Revision tags: netbsd-8-2-RELEASE netbsd-8-1-RELEASE netbsd-8-1-RC1 netbsd-7-2-RELEASE netbsd-8-0-RELEASE netbsd-8-0-RC2 netbsd-8-0-RC1 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 netbsd-7-1-2-RELEASE pgoyette-compat-base netbsd-7-1-1-RELEASE tls-maxphys-base-20171202 matt-nb8-mediatek-base nick-nhusb-base-20170825 perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base pgoyette-localcount-20170320 netbsd-7-1-RELEASE netbsd-7-1-RC2 nick-nhusb-base-20170204 netbsd-7-nhusb-base-20170116 bouyer-socketcan-base pgoyette-localcount-20170107 netbsd-7-1-RC1 nick-nhusb-base-20161204 pgoyette-localcount-20161104 netbsd-7-0-2-RELEASE nick-nhusb-base-20161004 localcount-20160914 netbsd-7-nhusb-base pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907 nick-nhusb-base-20160529 netbsd-7-0-1-RELEASE nick-nhusb-base-20160422 nick-nhusb-base-20160319 nick-nhusb-base-20151226 netbsd-7-0-RELEASE nick-nhusb-base-20150921 netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 nick-nhusb-base-20150606 nick-nhusb-base-20150406 nick-nhusb-base tls-maxphys-base netbsd-7-base
# 1.1 10-Aug-2014 matt

branches: 1.1.4; 1.1.28;
Preliminary files for AARCH64 (64-bit ARM) support.
Enough for a distribution build.


# 1.125 16-Jan-2022 rillig

aarch64/pmap: remove stray semicolon

No binary change.


# 1.124 15-Jan-2022 skrll

The translations that need invalidation are always last level so remove
the (dubious) logic around tracking the level. The "any level" TLB
invalidation maintenance operation are used, but this may change after
further testing.

before
======
1661.0u 420.2s 2:53.82 1197.3% 231+29k 10+33918io 102pf+0w
1646.8u 425.2s 2:52.96 1198.0% 232+29k 1+33937io 49pf+0w
1647.9u 425.7s 2:52.58 1201.6% 232+29k 0+33940io 32pf+0w

After
=====
1602.5u 420.8s 2:49.09 1196.6% 238+30k 24+33893io 54pf+0w
1600.7u 421.3s 2:51.53 1178.8% 238+30k 1+33914io 33pf+0w
1597.5u 424.3s 2:50.46 1186.1% 238+30k 0+33915io 17pf+0w

LGTM from ryo@


# 1.123 14-Jan-2022 skrll

Restore the previous pmap_remove_all behaviour as the new method meant
the n1sdp couldn't complete a build.

No noticeable change in kernel build performance.


# 1.122 04-Jan-2022 skrll

KNF


# 1.121 10-Dec-2021 andvar

s/occured/occurred/ in comments, log messages and man pages.


# 1.120 07-Dec-2021 andvar

fix various typos, mainly in comments.


# 1.119 23-Oct-2021 skrll

Fix non-UVMHIST build


# 1.118 16-Oct-2021 ryo

fix non-MULTIPROCESSOR build


# 1.117 10-Oct-2021 skrll

Use sys/uvm/pmap/pmap_tlb.c on Aarch64 in the same way that some Arm, MIPS,
and some PPC kernels do. This removes the limitation of 256 processes on
CPUs with 8bit ASID field, e.g. Apple M1.

Additionally the following changes have been made

- removed a couple of unnecessary aarch64_tlbi_all calls
- removed any invalidation after freeing page tables due to
_pmap_sweep_pdp. This was never necessary afaict.
- all kernel mappings are marked global and userland mapping not-global.

Performance testing hasn't show a significant difference. The data here
is from building a kernel on an lx2k system with nvme.

before
1489.6u 400.4s 2:40.65 1176.5% 228+224k 0+32289io 57pf+0w
1482.6u 403.2s 2:38.49 1189.9% 228+222k 0+32274io 46pf+0w
1485.4u 402.2s 2:37.27 1200.2% 228+222k 0+32275io 12pf+0w

after
1493.9u 404.6s 2:37.50 1205.4% 227+221k 0+32265io 48pf+0w
1485.0u 408.0s 2:38.54 1194.0% 227+222k 0+32272io 36pf+0w
1484.3u 407.0s 2:35.88 1213.3% 228+224k 0+32268io 14pf+0w

>>> stats.ttest_ind([160.65,158.49,157.27], [157.5,158.54,155.88])
Ttest_indResult(statistic=1.1923622711296888, pvalue=0.2990182944606766)
>>>


# 1.116 30-Sep-2021 skrll

Ensure TCR_EPD0 is set on entry to pmap_activate and ensure it is set as
early as possible for APs.


# 1.115 26-Sep-2021 skrll

Use UVMHIST_CALLARGS


# 1.114 26-Sep-2021 skrll

'\n' is not required in KASSERTMSG either.


# 1.113 26-Sep-2021 skrll

"\n" is not required in KERNHIST


# 1.112 15-Sep-2021 skrll

Use __SHIFTIN. Same code before and after.


# 1.111 12-Sep-2021 skrll

pmap_page_remove: simply and reduce the code size slightly.


# 1.110 09-Sep-2021 skrll

In pmap_icache_sync_range change

for (...) {
...
if (condition) {
// do stuff
}
}

to

for (...) {
...
if (!conditional)
continue;
// do stuff
}

to save on indentation. Same code (modulo register usage) before and
after.


# 1.109 09-Sep-2021 skrll

KNF


Revision tags: thorpej-i2c-spi-conf2-base thorpej-futex2-base thorpej-cfargs2-base cjep_sun2x-base1 cjep_sun2x-base cjep_staticlib_x-base1 thorpej-i2c-spi-conf-base
# 1.108 29-May-2021 skrll

Deal with the pmap limitation of maxproc in a more complete way and
recognise CPUs with only 8bit ASIDs.


Revision tags: cjep_staticlib_x-base
# 1.107 30-Apr-2021 skrll

branches: 1.107.2;
Make the ddb for pmap / pte information pmap agnostic


# 1.106 29-Apr-2021 skrll

Remove some unnecessary tlb invalidate in pmap_growkernel and ASAN shadow
map. Ensure the shadow map mappings are visible to the TLB walkers.


# 1.105 21-Apr-2021 ryo

branches: 1.105.2;
added more attributes of PTE displayed by "ddb>machine pte"


Revision tags: thorpej-cfargs-base
# 1.104 17-Apr-2021 mrg

remove KERNHIST_INIT_STATIC(). it stradles the line between usable
early in boot and broken early in boot by requiring a partly static
structure with another structure that must be present by the time
any uses are performed. theoretically platform code could allocate
a chunk while seting up memory and assign it here, giving a dynamic
sizing for the entry list, but the reality is that all users have
a statically allocated entry list as well.

the existing KERNHIST_LINK_STATIC() is used in conjunction with
KERNHIST_INITIALIZER() instead.

this stops a NULL pointer deref when the _LOG() macro is called
before the storage is linked in, which happens with GCC 10 on OCTEON
with UVMHIST enabled, crashing in very early kernel init.


Revision tags: thorpej-futex-base
# 1.103 09-Mar-2021 ryo

branches: 1.103.2;
fix build error without options DDB.

kvtopte() is referenced from arm/acpi/acpi_machdep.c


# 1.102 13-Feb-2021 ryo

No assignment is needed here.

the loop in pmap_page_remove() always removes the first pv,
and since the list is managed by _pmap_remove_pv(), pp->pp_pv.pv_next always points to the first.


# 1.101 01-Feb-2021 ryo

It is enough to make a page accessible instead of writable.
same fix as r1.76


# 1.100 31-Jan-2021 ryo

implement pmap_remove_all().

The size of struct pv_entry has increased, but speed of kernel build has improved by about 1%
exec and exit should have been improved.


# 1.99 20-Dec-2020 skrll

Improve the English in the previous comment fix.


# 1.98 19-Dec-2020 skrll

Tweak a comment


# 1.97 11-Dec-2020 skrll

s:aarch64/cpufunc.h:arm/cpufunc.h:

a baby step in the grand arm header unification challenge


# 1.96 10-Nov-2020 skrll

AA64 is not MIPS.

Change all KSEG references to directmap


# 1.95 07-Nov-2020 skrll

In pmap_devmap_bootstrap only set pmap_devmap_bootstrap_done if there
is an entry and ALL of the entries have been done. The entry required
for EARLYCONS might not be the first/only one...


# 1.94 01-Nov-2020 jmcneill

branches: 1.94.2;
No need to disable translation table walks in pmap_activate().


# 1.93 22-Oct-2020 skrll

Use the isb macro - missed in previous commit


# 1.92 22-Oct-2020 skrll

Use the dmb/dsb/isb macros... if nothing else they're all now consistent
about the "memory" assembler contraint.

No binary change


# 1.91 28-Sep-2020 skrll

Only set pmap_devmap_bootstrap_done if something gets mapped.

Think acpi_platform_devmap


# 1.90 19-Sep-2020 skrll

Make __md_palloc pmap agnostic (think sys/uvm/pmap)


# 1.89 14-Sep-2020 ryo

PID_MAX is just an initial value (soft maximum). Don't use it for CTASSERT.
defined __HAVE_CPU_MAXPROC to use function cpu_maxproc().

pointed out by mrg@, thanks.


# 1.88 06-Sep-2020 ryo

Fix panic caused by modload. http://mail-index.netbsd.org/port-arm/2020/08/30/msg006960.html

The address space reserved for modules may not be mapped in L1-L3.


# 1.87 14-Aug-2020 skrll

Whitespace


# 1.86 12-Aug-2020 skrll

Part IV of ad's performance improvements for aarch64

- Implement pmap_growkernel(), and update kernel pmap's stats with atomics.

- Then, pmap_kenter_pa() and pmap_kremove() no longer need to allocate
memory nor take pm_lock, because they only modify L3 PTEs.

- Then, pm_lock and pp_lock can be adaptive mutexes at IPL_NONE which are
cheaper than spin mutexes.

- Take the pmap's lock in pmap_extract() if not the kernel's pmap, otherwise
pmap_extract() might see inconsistent state.


# 1.85 09-Aug-2020 skrll

Fix another UVMHIST so it doesn't use %s


# 1.84 16-Jul-2020 skrll

pmapboot_enter simplication
- bootpage_alloc in asm becomes pmapboot_pagealloc in C
- PMAPBOOT_ENTER_NOBLOCK is removed as it's not used
- PMAPBOOT_ENTER_NOOVERWRITE is removed as it's now always on
- physpage_allocator argument is removed as it's always
pmapboot_pagealloc
- Support for EARLYCONS without CONSADDR is removed so that the identity
map for CONSADDR is always known.

For the assembly files:
2 files changed, 40 insertions(+), 89 deletions(-)

LGTM ryo


# 1.83 04-Jul-2020 rin

Use tlen for temporary length variable instead of l, which is usually
used for struct lwp *.

No binary changes.


# 1.82 02-Jul-2020 rin

pmap_procwr(): sync icache even if p != curproc. This fixes applications
like GDB for arm32, that rewrite text of other process.

Thanks to ryo@ for discussion.


# 1.81 02-Jul-2020 rin

Set uvmexp.ncolors appropriately, which is required for some CPU
models with VIPT icache.

Otherwise, alias in virtual address results in inconsistent results,
at least for applications that rewrite text of other process, e.g.,
GDB for arm32.

Also, this hopefully fixes other unexpected failures due to alias.

Confirmed that there's no observable regression in performance;
difference in ``time make -j8'' for GENERIC64 kernel on BCM2837
with and without setting uvmexp.ncolors is within 0.1%.

Thanks to ryo@ for discussion.


# 1.80 27-Jun-2020 rin

Fix typo in name of evcnt(4) counter.


# 1.79 24-Jun-2020 ryo

Fix bug with incorrect range calculation when doing icache sync.
This is called by sysarch(ARM_SYNC_ICACHE) from aarch32 (compat_netbsd32) emul process.

pointed out by rin@, thanks.

XXX pullup-9


# 1.78 14-Jun-2020 ad

- Fix a lock order reversal in pmap_page_protect().

- Make sure pmap is always locked when updating stats; atomics no longer
needed to do that.

- Remove unneeded traversal of pv list in pmap_enter_pv().

- Shrink struct vm_page from 136 to 128 bytes (cache line sized) and struct
pv_entry from 48 to 32 bytes (power of 2 sized).

- Embed a pv_entry in each vm_page. This means PV entries don't need to
be allocated for private anonymous memory / COW pages / most UBC mappings.
Dynamic PV entries are then used only for stuff like shared libraries and
shared memory.

Proposed on port-arm@.


# 1.77 10-Jun-2020 ad

- Wired/resident stats shouldn't covered by PMAPCOUNTERS.
- Rename need_update_pv -> need_enter_pv.

Ok ryo@


# 1.76 01-Jun-2020 ryo

no need to make the PTE writable to do icache_sync, enough to accessible.


# 1.75 15-May-2020 skrll

Use __diagused


# 1.74 15-May-2020 tnn

fix non-diag build


# 1.73 14-May-2020 skrll

Use MUTEX_NODEBUG for PV locks as is commonly done. OK ryo.


# 1.72 13-May-2020 jmcneill

Implement pmap_extract_coherency


Revision tags: bouyer-xenpvh-base2 phil-wifi-20200421 bouyer-xenpvh-base1
# 1.71 18-Apr-2020 skrll

PMAP_DEBUG has been deleted on arm


# 1.70 13-Apr-2020 maxv

Add support for Branch Target Identification (BTI).

On the executable pages that have the GP (Guarded Page) bit, the semantic
of the "br" and "blr" instructions is changed: the CPU expects the first
instruction of the jump/call target to be "bti", and faults if it isn't.

We add the GP bit on the kernel .text pages (and incidentally the .rodata
pages, but we don't care). The compiler adds a "bti c" instruction at the
beginning of each C function. We modify the ENTRY() macros to manually add
"bti c" in the asm functions.

cpuswitch.S needs a specific change: with "br x27" the CPU expects "bti j",
which is bad because the functions begin with "bti c"; switch to "br x16",
for the CPU to accept "bti c".

BTI helps defend against JOP/COP. Tested on Qemu.


Revision tags: phil-wifi-20200411 bouyer-xenpvh-base
# 1.69 08-Apr-2020 ryo

branches: 1.69.2;
use PMAP_PAGE_INIT() to initialize mutex in pmap_page.

VM_MDPAGE_INIT() in pmap_free_pdp() had initialized pp_flags,
so it unintentionally cleared PMAP_PAGE_FLAGS_PV_TRACKED.
use PMAP_PAGE_INIT to avoid using PMAP_PAGE_FLAGS_PV_TRACKED.

pointed out by tnn@, thanks


Revision tags: phil-wifi-20200406
# 1.68 14-Mar-2020 ad

pmap_remove_all(): Return a boolean value to indicate the behaviour. If
true, all mappings have been removed, the pmap is totally cleared out, and
UVM can then avoid doing the work to call pmap_remove() for each map entry.
If false, either nothing has been done, or some helpful arch-specific voodoo
has taken place.


Revision tags: is-mlppp-base
# 1.67 02-Mar-2020 ryo

oops, fix incorrect usage of daif_enable() in my previous commit.


# 1.66 29-Feb-2020 ryo

Fix pmap to work correctly with tagged addresses

- when fault, untag from address before passing to uvm/pmap functions
- pmap_extract() checks more strictly and consider the address tag


# 1.65 29-Feb-2020 ryo

use pmapboot_enter_range()


Revision tags: ad-namecache-base3
# 1.64 10-Feb-2020 ryo

use LIST(3) instead of TAILQ(3) to save one word in struct vm_page and struct pmap.

pointed out by riastradh@. thanks


# 1.63 03-Feb-2020 ryo

add support pmap_pv(9)

Patch originally from jmcneill@. thanks


# 1.62 03-Feb-2020 ryo

separate struct vm_page_md into vm_page_md and pmap_page
for preparation pmap_pv(9)


Revision tags: ad-namecache-base2 ad-namecache-base1
# 1.61 09-Jan-2020 ryo

fix behaviour mmap()/mprotect() when passed only PROT_EXEC.

when mmap()/mprotect() with only PROT_EXEC, syscall will be successful,
but the page actually hadn't been mapped.
it should be mapped with PROT_READ|PROT_EXEC implicitly. (r-x)


Revision tags: ad-namecache-base
# 1.60 30-Dec-2019 skrll

branches: 1.60.2;
Update pmap_map_chunk to allow L[12] block mappings and L3 page mappings


# 1.59 30-Dec-2019 skrll

Remove unnecessary brackets and unwrap a conditional. Same code before
and after.


# 1.58 28-Dec-2019 jmcneill

Do not use Early Write Acknowledge for PCIe I/O and config space.


# 1.57 27-Dec-2019 jmcneill

Enable early write acknowledge for device memory mappings.


# 1.56 19-Dec-2019 skrll

G/C kasan_shadow_map call in pmap_enter

pmap_growkernel calls kasan_shadow_map for KVA


# 1.55 18-Dec-2019 ryo

atomic_add_16() is not used in pmap.c anymore. no need decl here.


# 1.54 18-Dec-2019 ryo

space to tab


# 1.53 14-Dec-2019 skrll

Fix build... wire_count probably doesn't need atomics


# 1.52 13-Dec-2019 skrll

Fix KASAN support by calling kasan_shadow_map in pmap_growkernel


# 1.51 10-Dec-2019 ad

pg->phys_addr -> VM_PAGE_TO_PHYS(pg)


Revision tags: phil-wifi-20191119
# 1.50 14-Nov-2019 maxv

Mark several kASan functions with __nothing, to avoid annoying #ifdefs.
Same as kCSan and kMSan.


# 1.49 14-Nov-2019 maxv

Don't include "opt_kasan.h" when there's already <sys/asan.h> included.


# 1.48 29-Oct-2019 maya

Define PMAP_NEED_PROCWR, providing strategically placed i-cache
synchronization where just-changed memory is about to be executed.

Fixes SIGILLs seen when running Mono 6 on QEMU Cortex-A57.

ok ryo


# 1.47 22-Sep-2019 jmcneill

Disable translation table walks using TTBR0 while changing its value and
when deactivating a pmap. Fixes stability issues on Ampere eMAG CPUs.


# 1.46 20-Sep-2019 ryo

ref/mod bit should be set according to 'flags' argument, not 'prot'. r1.44 was incomplete.


# 1.45 13-Sep-2019 ryo

In pmap_devmap_bootstrap(), cpu_earlydevice_va_p() must not return true until *all* devmap tables have been enabled.
console mapping may be present in the last table.


# 1.44 07-Sep-2019 ryo

- remove incorrect KASSERT. mmap(2) with prot=PROT_WRITE calls pmap_enter(..., PROT_WRITE) internally.
- fix to update page reference flags when only PROT_WRITE or PROT_EXECUTE specified


# 1.43 15-Aug-2019 skrll

Make pmap_db_pte_print more terse so it's quicker on serial consoles


# 1.42 12-Aug-2019 skrll

Use PMAP_DEV in DEVMAP_ENTRY rather than pmap_map_chunk. It's clearer and
means pmap_map_chunk can be made to map other memory types.


Revision tags: netbsd-9-base phil-wifi-20190609
# 1.41 17-May-2019 mrg

branches: 1.41.2;
apply some __diagused.


Revision tags: isaki-audio2-base
# 1.40 08-Apr-2019 ryo

- free empty page tables pages if reach a certain usage.
- need to lock at removing an old pg (_pmap_remove_pv) in _pmap_enter()


# 1.39 06-Apr-2019 ryo

Fix race conditions about pmap_page_protect() and pmap_enter().

while handling same PTE by these functions in same time, there
is a critical path that the number of valid PTEs and wire_count
are inconsistent, and it caused KASSERT.
Need to hold a pv_lock while modifying them.


# 1.38 20-Mar-2019 ryo

spinkle __printflike(), and use PRIxxx


# 1.37 19-Mar-2019 ryo

- add ddb command "machine ttbr" to dump MMU tables.
- tidy up descriptions, usages and messages.


# 1.36 19-Mar-2019 ryo

- free L1-L3 pages that has been emptied by pmap_remove().
- if no memories, pmap_enter will return correctly ENOMEM if PMAP_CANFAIL, or wait until available any memories if !PMAP_CANFAIL.

These changes improves the stability when we use a huge virtual memory spaces with mmap.


# 1.35 06-Feb-2019 ryo

improve pmap_remove
- don't lock/unlock per page in pmap_remove()
- speedup pte lookup for continuous addresses
- bring out pool_cache_put(&_pmap_pv_pool, pv) from lock/unlock section


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226
# 1.34 21-Dec-2018 ryo

- add workaround for Cavium ThunderX errata 27456.
- add cpufuncs table in cpu_info. each cpu clusters may have different erratum. (e.g. big.LITTLE)


Revision tags: pgoyette-compat-1126
# 1.33 01-Nov-2018 maxv

Add kASan support for aarch64. Stack tracking needs more investigation
and will come in a separate commit.

Reviewed by ryo@ jmcneill@ skrll@.


# 1.32 31-Oct-2018 ryo

invalidate icache correctly.
l3pte_executable() should be used for only valid pte.


Revision tags: pgoyette-compat-1020
# 1.31 18-Oct-2018 skrll

Provide generic start code that assumes the MMU is off and caches are
disabled as per the linux booting protocol for ARMv6 and ARMv7 boards.
u-boot image type should be changed to 'linux' for correct behaviour.

The new start code builds a minimal "bootstrap" L1PT with cached access
disabled and uses the same table for all processors. AP startup is
performed in less steps and more code is written in C.

The bootstrap tables and stack are placed into an (orphaned) section
"_init_memory" which is given to uvm when it is no longer used.

Various kernels have been converted to use this code and tested. Some
boards were provided by TNF. Thanks!

The GENERIC kernel now boots on boards using the TEGRA, SUNXI and EXYNOS
kernels. The GENERIC kernel will also work on RPI2 using u-boot.

Thanks to martin@ and aymeric@ for testing on parallella and nanosoc
respectively


# 1.30 14-Oct-2018 skrll

Use __nothing


# 1.29 12-Oct-2018 ryo

add initial support of COMPAT_NETBSD32 on AArch64.
arm ELF32 EABI binaries could be execute in AArch32 state on AArch64. A32 THUMB mode is not supported yet.


# 1.28 12-Oct-2018 ryo

- cleanup checking address ranges with IN_RANGE macro
- change PM_ADDR_CHECK macro to KASSERTMSG
- restore fast lookup cases with IN_RANGE macro for pmap_extract changed in my previous commit.


# 1.27 12-Oct-2018 ryo

rewrite pmap_pte_lookup() to share similar code.


# 1.26 04-Oct-2018 ryo

cleanup locore, and changed the way to map memories during boot.
- add functions bootpage_enter() and bootpage_alloc() to adapt various layout
of physical memory map. especially for 64bit physical memory layout.
pmapboot_alloc() allocates pagetable pages from _end[].
- changed to map only the required amount for PA=VA identity mapping
(kernel image, UART device, and FDT blob) with L2_BLOCK(2Mbyte).
- changing page permission for kernel image, and making KSEG mapping are done
at cpu_kernel_vm_init() instead of at locore.
- optimize PTE entries with PTE Contiguous bit. it is enabled on devmap only for now.

reviewed by skrll@, thanks.


# 1.25 04-Oct-2018 ryo

* define LX_BLKPAG_{OS,ATTR}_* for OS dependent PTE attributes in pmap.h
* cleanup macros


Revision tags: pgoyette-compat-0930
# 1.24 17-Sep-2018 ryo

delete debug printf and KASSERT.


# 1.23 10-Sep-2018 maxv

Replace KDASSERT by panic.


# 1.22 10-Sep-2018 maxv

Rename _pmap_alloc_pdp -> pmap_alloc_pdp, and make it public.


# 1.21 10-Sep-2018 ryo

cleanup aarch64 mpstart and fdt bootstrap
* arm_cpu_hatch_arg is a bad idea. avoid serializing CPU startup, and eliminate arm_cpu_hatch_arg.
in mpstart, resolve own cpu index using array of cpu_mpidr[] (aarch64)
* add support fdt enable-method "spin-table"
* add support fdt enable-method "brcm,bcm2836-smp" (for 32bit RaspberryPi)
* use arm_fdt_cpu_bootstrap() instead of psci_fdt_bootstrap()
* rename "arm/fdt/psci_fdt.h" to "arm/fdt/psci_fdtvar.h" because of conflict of include file for needs-flag
* add devmap for cpu spin-table of raspberrypi3/aarch64
* no need to force hatch APs for raspberrypi3/arm32 ifndef MULTIPROCESSOR.
* fix to work pmap_extract(kerneltext/data/bss) even if before calling pmap_bootstrap

idea to use cpu_mpidr[] by jmcneill@. reviewd by skrll@. thanks.


Revision tags: pgoyette-compat-0906
# 1.20 27-Aug-2018 ryo

need to add VM_PROT_READ when pmap_kenter_pa(va, pa, VM_PROT_WRITE, 0) or pmap_kenter_pa(va, pa, VM_PROT_EXECUTE, 0).
VM_PROT_READ is treated as an access permission inernally.


# 1.19 11-Aug-2018 ryo

change to minimum invalidation of TLB.
specifying not only va but also asid, and not invalidate L0-L2 entry using tlbi_*_ll() if needed.


# 1.18 10-Aug-2018 ryo

treat kernel-exec attr and user-exec attr separately.
kernel cannot execute userland exec page, and user cannot execute kernel page.


# 1.17 06-Aug-2018 ryo

set kernel text/rodata readonly by default.
add function db_write_text() for setting ddb breakpoint.


# 1.16 31-Jul-2018 skrll

Define and use VPRINTF


Revision tags: pgoyette-compat-0728
# 1.15 27-Jul-2018 ryo

changes of pmap.c r1.13 seems to be unstable.
In order to invalidate icache, not to invalidate all icache,
but temporary to make the page writable and invalidate target address only.


# 1.14 24-Jul-2018 ryo

don't call pool_cache_put with locking pmap. pool_cache_put call pmap_kenter_pa internally.
(pool_cache_put_paddr -> pool_cache_put_slow -> pool_get -> pmap_kenter_pa)


# 1.13 23-Jul-2018 ryo

* fix icache invalidations.
* "ic ivau" (aarch64_icache_sync_range) with VA generates permission fault in some situations, therefore use KSEG address for now.


# 1.12 23-Jul-2018 ryo

rather than using flags to resolve nested locks, reserve pool_cache before locking.


# 1.11 21-Jul-2018 ryo

* avoid deadlock. mutex_owned() works only for adaptive lock, therefore we cannot use it for spinlock...
* add more NULL check
* clear pte when pmap_enter() fails


# 1.10 17-Jul-2018 ryo

Use __debugused


# 1.9 17-Jul-2018 christos

Add missing casts, remove unused variables.


# 1.8 09-Jul-2018 ryo

need locks in pmap_kremove() and pmap_fault_fixup()


Revision tags: phil-wifi-base pgoyette-compat-0625 pgoyette-compat-0521
# 1.7 20-May-2018 ryo

branches: 1.7.2;
pmap_enter() must update modified/referenced flags by 'flags' not 'prot'.


# 1.6 16-May-2018 ryo

Fix memory leak. it was leaking one page every pmap_create().
pm->pm_vmlist must be initialized before calling _pmap_alloc_pdp().


Revision tags: pgoyette-compat-0502
# 1.5 29-Apr-2018 ryo

fix KASSERT panic. pv_entry may not be exists in pvlist when pmap_remove().


# 1.4 29-Apr-2018 ryo

delete unused code


# 1.3 27-Apr-2018 ryo

fix instability behavior of bufcache on aarch64.
* fix to return correct ref/mod when PMAP_WIRED.
* changed to keep wired flags in pte instead of pv_entry, and cleanup.


Revision tags: pgoyette-compat-0422 pgoyette-compat-0415 pgoyette-compat-0407
# 1.2 01-Apr-2018 ryo

Add initial support for ARMv8 (AARCH64) (by nisimura@ and ryo@)

- sys/arch/evbarm64 is gone and integrated into sys/arch/evbarm. (by skrll@)
- add support fdt. evbarm/conf/GENERIC64 fdt (bcm2837,sunxi,tegra) based generic 64bit kernel config. (by skrll@, jmcneill@)


Revision tags: netbsd-8-2-RELEASE netbsd-8-1-RELEASE netbsd-8-1-RC1 netbsd-7-2-RELEASE netbsd-8-0-RELEASE netbsd-8-0-RC2 netbsd-8-0-RC1 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 netbsd-7-1-2-RELEASE pgoyette-compat-base netbsd-7-1-1-RELEASE tls-maxphys-base-20171202 matt-nb8-mediatek-base nick-nhusb-base-20170825 perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base pgoyette-localcount-20170320 netbsd-7-1-RELEASE netbsd-7-1-RC2 nick-nhusb-base-20170204 netbsd-7-nhusb-base-20170116 bouyer-socketcan-base pgoyette-localcount-20170107 netbsd-7-1-RC1 nick-nhusb-base-20161204 pgoyette-localcount-20161104 netbsd-7-0-2-RELEASE nick-nhusb-base-20161004 localcount-20160914 netbsd-7-nhusb-base pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907 nick-nhusb-base-20160529 netbsd-7-0-1-RELEASE nick-nhusb-base-20160422 nick-nhusb-base-20160319 nick-nhusb-base-20151226 netbsd-7-0-RELEASE nick-nhusb-base-20150921 netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 nick-nhusb-base-20150606 nick-nhusb-base-20150406 nick-nhusb-base tls-maxphys-base netbsd-7-base
# 1.1 10-Aug-2014 matt

branches: 1.1.4; 1.1.28;
Preliminary files for AARCH64 (64-bit ARM) support.
Enough for a distribution build.


# 1.124 15-Jan-2022 skrll

The translations that need invalidation are always last level so remove
the (dubious) logic around tracking the level. The "any level" TLB
invalidation maintenance operation are used, but this may change after
further testing.

before
======
1661.0u 420.2s 2:53.82 1197.3% 231+29k 10+33918io 102pf+0w
1646.8u 425.2s 2:52.96 1198.0% 232+29k 1+33937io 49pf+0w
1647.9u 425.7s 2:52.58 1201.6% 232+29k 0+33940io 32pf+0w

After
=====
1602.5u 420.8s 2:49.09 1196.6% 238+30k 24+33893io 54pf+0w
1600.7u 421.3s 2:51.53 1178.8% 238+30k 1+33914io 33pf+0w
1597.5u 424.3s 2:50.46 1186.1% 238+30k 0+33915io 17pf+0w

LGTM from ryo@


# 1.123 14-Jan-2022 skrll

Restore the previous pmap_remove_all behaviour as the new method meant
the n1sdp couldn't complete a build.

No noticeable change in kernel build performance.


# 1.122 04-Jan-2022 skrll

KNF


# 1.121 10-Dec-2021 andvar

s/occured/occurred/ in comments, log messages and man pages.


# 1.120 07-Dec-2021 andvar

fix various typos, mainly in comments.


# 1.119 23-Oct-2021 skrll

Fix non-UVMHIST build


# 1.118 16-Oct-2021 ryo

fix non-MULTIPROCESSOR build


# 1.117 10-Oct-2021 skrll

Use sys/uvm/pmap/pmap_tlb.c on Aarch64 in the same way that some Arm, MIPS,
and some PPC kernels do. This removes the limitation of 256 processes on
CPUs with 8bit ASID field, e.g. Apple M1.

Additionally the following changes have been made

- removed a couple of unnecessary aarch64_tlbi_all calls
- removed any invalidation after freeing page tables due to
_pmap_sweep_pdp. This was never necessary afaict.
- all kernel mappings are marked global and userland mapping not-global.

Performance testing hasn't show a significant difference. The data here
is from building a kernel on an lx2k system with nvme.

before
1489.6u 400.4s 2:40.65 1176.5% 228+224k 0+32289io 57pf+0w
1482.6u 403.2s 2:38.49 1189.9% 228+222k 0+32274io 46pf+0w
1485.4u 402.2s 2:37.27 1200.2% 228+222k 0+32275io 12pf+0w

after
1493.9u 404.6s 2:37.50 1205.4% 227+221k 0+32265io 48pf+0w
1485.0u 408.0s 2:38.54 1194.0% 227+222k 0+32272io 36pf+0w
1484.3u 407.0s 2:35.88 1213.3% 228+224k 0+32268io 14pf+0w

>>> stats.ttest_ind([160.65,158.49,157.27], [157.5,158.54,155.88])
Ttest_indResult(statistic=1.1923622711296888, pvalue=0.2990182944606766)
>>>


# 1.116 30-Sep-2021 skrll

Ensure TCR_EPD0 is set on entry to pmap_activate and ensure it is set as
early as possible for APs.


# 1.115 26-Sep-2021 skrll

Use UVMHIST_CALLARGS


# 1.114 26-Sep-2021 skrll

'\n' is not required in KASSERTMSG either.


# 1.113 26-Sep-2021 skrll

"\n" is not required in KERNHIST


# 1.112 15-Sep-2021 skrll

Use __SHIFTIN. Same code before and after.


# 1.111 12-Sep-2021 skrll

pmap_page_remove: simply and reduce the code size slightly.


# 1.110 09-Sep-2021 skrll

In pmap_icache_sync_range change

for (...) {
...
if (condition) {
// do stuff
}
}

to

for (...) {
...
if (!conditional)
continue;
// do stuff
}

to save on indentation. Same code (modulo register usage) before and
after.


# 1.109 09-Sep-2021 skrll

KNF


Revision tags: thorpej-i2c-spi-conf2-base thorpej-futex2-base thorpej-cfargs2-base cjep_sun2x-base1 cjep_sun2x-base cjep_staticlib_x-base1 thorpej-i2c-spi-conf-base
# 1.108 29-May-2021 skrll

Deal with the pmap limitation of maxproc in a more complete way and
recognise CPUs with only 8bit ASIDs.


Revision tags: cjep_staticlib_x-base
# 1.107 30-Apr-2021 skrll

branches: 1.107.2;
Make the ddb for pmap / pte information pmap agnostic


# 1.106 29-Apr-2021 skrll

Remove some unnecessary tlb invalidate in pmap_growkernel and ASAN shadow
map. Ensure the shadow map mappings are visible to the TLB walkers.


# 1.105 21-Apr-2021 ryo

branches: 1.105.2;
added more attributes of PTE displayed by "ddb>machine pte"


Revision tags: thorpej-cfargs-base
# 1.104 17-Apr-2021 mrg

remove KERNHIST_INIT_STATIC(). it stradles the line between usable
early in boot and broken early in boot by requiring a partly static
structure with another structure that must be present by the time
any uses are performed. theoretically platform code could allocate
a chunk while seting up memory and assign it here, giving a dynamic
sizing for the entry list, but the reality is that all users have
a statically allocated entry list as well.

the existing KERNHIST_LINK_STATIC() is used in conjunction with
KERNHIST_INITIALIZER() instead.

this stops a NULL pointer deref when the _LOG() macro is called
before the storage is linked in, which happens with GCC 10 on OCTEON
with UVMHIST enabled, crashing in very early kernel init.


Revision tags: thorpej-futex-base
# 1.103 09-Mar-2021 ryo

branches: 1.103.2;
fix build error without options DDB.

kvtopte() is referenced from arm/acpi/acpi_machdep.c


# 1.102 13-Feb-2021 ryo

No assignment is needed here.

the loop in pmap_page_remove() always removes the first pv,
and since the list is managed by _pmap_remove_pv(), pp->pp_pv.pv_next always points to the first.


# 1.101 01-Feb-2021 ryo

It is enough to make a page accessible instead of writable.
same fix as r1.76


# 1.100 31-Jan-2021 ryo

implement pmap_remove_all().

The size of struct pv_entry has increased, but speed of kernel build has improved by about 1%
exec and exit should have been improved.


# 1.99 20-Dec-2020 skrll

Improve the English in the previous comment fix.


# 1.98 19-Dec-2020 skrll

Tweak a comment


# 1.97 11-Dec-2020 skrll

s:aarch64/cpufunc.h:arm/cpufunc.h:

a baby step in the grand arm header unification challenge


# 1.96 10-Nov-2020 skrll

AA64 is not MIPS.

Change all KSEG references to directmap


# 1.95 07-Nov-2020 skrll

In pmap_devmap_bootstrap only set pmap_devmap_bootstrap_done if there
is an entry and ALL of the entries have been done. The entry required
for EARLYCONS might not be the first/only one...


# 1.94 01-Nov-2020 jmcneill

branches: 1.94.2;
No need to disable translation table walks in pmap_activate().


# 1.93 22-Oct-2020 skrll

Use the isb macro - missed in previous commit


# 1.92 22-Oct-2020 skrll

Use the dmb/dsb/isb macros... if nothing else they're all now consistent
about the "memory" assembler contraint.

No binary change


# 1.91 28-Sep-2020 skrll

Only set pmap_devmap_bootstrap_done if something gets mapped.

Think acpi_platform_devmap


# 1.90 19-Sep-2020 skrll

Make __md_palloc pmap agnostic (think sys/uvm/pmap)


# 1.89 14-Sep-2020 ryo

PID_MAX is just an initial value (soft maximum). Don't use it for CTASSERT.
defined __HAVE_CPU_MAXPROC to use function cpu_maxproc().

pointed out by mrg@, thanks.


# 1.88 06-Sep-2020 ryo

Fix panic caused by modload. http://mail-index.netbsd.org/port-arm/2020/08/30/msg006960.html

The address space reserved for modules may not be mapped in L1-L3.


# 1.87 14-Aug-2020 skrll

Whitespace


# 1.86 12-Aug-2020 skrll

Part IV of ad's performance improvements for aarch64

- Implement pmap_growkernel(), and update kernel pmap's stats with atomics.

- Then, pmap_kenter_pa() and pmap_kremove() no longer need to allocate
memory nor take pm_lock, because they only modify L3 PTEs.

- Then, pm_lock and pp_lock can be adaptive mutexes at IPL_NONE which are
cheaper than spin mutexes.

- Take the pmap's lock in pmap_extract() if not the kernel's pmap, otherwise
pmap_extract() might see inconsistent state.


# 1.85 09-Aug-2020 skrll

Fix another UVMHIST so it doesn't use %s


# 1.84 16-Jul-2020 skrll

pmapboot_enter simplication
- bootpage_alloc in asm becomes pmapboot_pagealloc in C
- PMAPBOOT_ENTER_NOBLOCK is removed as it's not used
- PMAPBOOT_ENTER_NOOVERWRITE is removed as it's now always on
- physpage_allocator argument is removed as it's always
pmapboot_pagealloc
- Support for EARLYCONS without CONSADDR is removed so that the identity
map for CONSADDR is always known.

For the assembly files:
2 files changed, 40 insertions(+), 89 deletions(-)

LGTM ryo


# 1.83 04-Jul-2020 rin

Use tlen for temporary length variable instead of l, which is usually
used for struct lwp *.

No binary changes.


# 1.82 02-Jul-2020 rin

pmap_procwr(): sync icache even if p != curproc. This fixes applications
like GDB for arm32, that rewrite text of other process.

Thanks to ryo@ for discussion.


# 1.81 02-Jul-2020 rin

Set uvmexp.ncolors appropriately, which is required for some CPU
models with VIPT icache.

Otherwise, alias in virtual address results in inconsistent results,
at least for applications that rewrite text of other process, e.g.,
GDB for arm32.

Also, this hopefully fixes other unexpected failures due to alias.

Confirmed that there's no observable regression in performance;
difference in ``time make -j8'' for GENERIC64 kernel on BCM2837
with and without setting uvmexp.ncolors is within 0.1%.

Thanks to ryo@ for discussion.


# 1.80 27-Jun-2020 rin

Fix typo in name of evcnt(4) counter.


# 1.79 24-Jun-2020 ryo

Fix bug with incorrect range calculation when doing icache sync.
This is called by sysarch(ARM_SYNC_ICACHE) from aarch32 (compat_netbsd32) emul process.

pointed out by rin@, thanks.

XXX pullup-9


# 1.78 14-Jun-2020 ad

- Fix a lock order reversal in pmap_page_protect().

- Make sure pmap is always locked when updating stats; atomics no longer
needed to do that.

- Remove unneeded traversal of pv list in pmap_enter_pv().

- Shrink struct vm_page from 136 to 128 bytes (cache line sized) and struct
pv_entry from 48 to 32 bytes (power of 2 sized).

- Embed a pv_entry in each vm_page. This means PV entries don't need to
be allocated for private anonymous memory / COW pages / most UBC mappings.
Dynamic PV entries are then used only for stuff like shared libraries and
shared memory.

Proposed on port-arm@.


# 1.77 10-Jun-2020 ad

- Wired/resident stats shouldn't covered by PMAPCOUNTERS.
- Rename need_update_pv -> need_enter_pv.

Ok ryo@


# 1.76 01-Jun-2020 ryo

no need to make the PTE writable to do icache_sync, enough to accessible.


# 1.75 15-May-2020 skrll

Use __diagused


# 1.74 15-May-2020 tnn

fix non-diag build


# 1.73 14-May-2020 skrll

Use MUTEX_NODEBUG for PV locks as is commonly done. OK ryo.


# 1.72 13-May-2020 jmcneill

Implement pmap_extract_coherency


Revision tags: bouyer-xenpvh-base2 phil-wifi-20200421 bouyer-xenpvh-base1
# 1.71 18-Apr-2020 skrll

PMAP_DEBUG has been deleted on arm


# 1.70 13-Apr-2020 maxv

Add support for Branch Target Identification (BTI).

On the executable pages that have the GP (Guarded Page) bit, the semantic
of the "br" and "blr" instructions is changed: the CPU expects the first
instruction of the jump/call target to be "bti", and faults if it isn't.

We add the GP bit on the kernel .text pages (and incidentally the .rodata
pages, but we don't care). The compiler adds a "bti c" instruction at the
beginning of each C function. We modify the ENTRY() macros to manually add
"bti c" in the asm functions.

cpuswitch.S needs a specific change: with "br x27" the CPU expects "bti j",
which is bad because the functions begin with "bti c"; switch to "br x16",
for the CPU to accept "bti c".

BTI helps defend against JOP/COP. Tested on Qemu.


Revision tags: phil-wifi-20200411 bouyer-xenpvh-base
# 1.69 08-Apr-2020 ryo

branches: 1.69.2;
use PMAP_PAGE_INIT() to initialize mutex in pmap_page.

VM_MDPAGE_INIT() in pmap_free_pdp() had initialized pp_flags,
so it unintentionally cleared PMAP_PAGE_FLAGS_PV_TRACKED.
use PMAP_PAGE_INIT to avoid using PMAP_PAGE_FLAGS_PV_TRACKED.

pointed out by tnn@, thanks


Revision tags: phil-wifi-20200406
# 1.68 14-Mar-2020 ad

pmap_remove_all(): Return a boolean value to indicate the behaviour. If
true, all mappings have been removed, the pmap is totally cleared out, and
UVM can then avoid doing the work to call pmap_remove() for each map entry.
If false, either nothing has been done, or some helpful arch-specific voodoo
has taken place.


Revision tags: is-mlppp-base
# 1.67 02-Mar-2020 ryo

oops, fix incorrect usage of daif_enable() in my previous commit.


# 1.66 29-Feb-2020 ryo

Fix pmap to work correctly with tagged addresses

- when fault, untag from address before passing to uvm/pmap functions
- pmap_extract() checks more strictly and consider the address tag


# 1.65 29-Feb-2020 ryo

use pmapboot_enter_range()


Revision tags: ad-namecache-base3
# 1.64 10-Feb-2020 ryo

use LIST(3) instead of TAILQ(3) to save one word in struct vm_page and struct pmap.

pointed out by riastradh@. thanks


# 1.63 03-Feb-2020 ryo

add support pmap_pv(9)

Patch originally from jmcneill@. thanks


# 1.62 03-Feb-2020 ryo

separate struct vm_page_md into vm_page_md and pmap_page
for preparation pmap_pv(9)


Revision tags: ad-namecache-base2 ad-namecache-base1
# 1.61 09-Jan-2020 ryo

fix behaviour mmap()/mprotect() when passed only PROT_EXEC.

when mmap()/mprotect() with only PROT_EXEC, syscall will be successful,
but the page actually hadn't been mapped.
it should be mapped with PROT_READ|PROT_EXEC implicitly. (r-x)


Revision tags: ad-namecache-base
# 1.60 30-Dec-2019 skrll

branches: 1.60.2;
Update pmap_map_chunk to allow L[12] block mappings and L3 page mappings


# 1.59 30-Dec-2019 skrll

Remove unnecessary brackets and unwrap a conditional. Same code before
and after.


# 1.58 28-Dec-2019 jmcneill

Do not use Early Write Acknowledge for PCIe I/O and config space.


# 1.57 27-Dec-2019 jmcneill

Enable early write acknowledge for device memory mappings.


# 1.56 19-Dec-2019 skrll

G/C kasan_shadow_map call in pmap_enter

pmap_growkernel calls kasan_shadow_map for KVA


# 1.55 18-Dec-2019 ryo

atomic_add_16() is not used in pmap.c anymore. no need decl here.


# 1.54 18-Dec-2019 ryo

space to tab


# 1.53 14-Dec-2019 skrll

Fix build... wire_count probably doesn't need atomics


# 1.52 13-Dec-2019 skrll

Fix KASAN support by calling kasan_shadow_map in pmap_growkernel


# 1.51 10-Dec-2019 ad

pg->phys_addr -> VM_PAGE_TO_PHYS(pg)


Revision tags: phil-wifi-20191119
# 1.50 14-Nov-2019 maxv

Mark several kASan functions with __nothing, to avoid annoying #ifdefs.
Same as kCSan and kMSan.


# 1.49 14-Nov-2019 maxv

Don't include "opt_kasan.h" when there's already <sys/asan.h> included.


# 1.48 29-Oct-2019 maya

Define PMAP_NEED_PROCWR, providing strategically placed i-cache
synchronization where just-changed memory is about to be executed.

Fixes SIGILLs seen when running Mono 6 on QEMU Cortex-A57.

ok ryo


# 1.47 22-Sep-2019 jmcneill

Disable translation table walks using TTBR0 while changing its value and
when deactivating a pmap. Fixes stability issues on Ampere eMAG CPUs.


# 1.46 20-Sep-2019 ryo

ref/mod bit should be set according to 'flags' argument, not 'prot'. r1.44 was incomplete.


# 1.45 13-Sep-2019 ryo

In pmap_devmap_bootstrap(), cpu_earlydevice_va_p() must not return true until *all* devmap tables have been enabled.
console mapping may be present in the last table.


# 1.44 07-Sep-2019 ryo

- remove incorrect KASSERT. mmap(2) with prot=PROT_WRITE calls pmap_enter(..., PROT_WRITE) internally.
- fix to update page reference flags when only PROT_WRITE or PROT_EXECUTE specified


# 1.43 15-Aug-2019 skrll

Make pmap_db_pte_print more terse so it's quicker on serial consoles


# 1.42 12-Aug-2019 skrll

Use PMAP_DEV in DEVMAP_ENTRY rather than pmap_map_chunk. It's clearer and
means pmap_map_chunk can be made to map other memory types.


Revision tags: netbsd-9-base phil-wifi-20190609
# 1.41 17-May-2019 mrg

branches: 1.41.2;
apply some __diagused.


Revision tags: isaki-audio2-base
# 1.40 08-Apr-2019 ryo

- free empty page tables pages if reach a certain usage.
- need to lock at removing an old pg (_pmap_remove_pv) in _pmap_enter()


# 1.39 06-Apr-2019 ryo

Fix race conditions about pmap_page_protect() and pmap_enter().

while handling same PTE by these functions in same time, there
is a critical path that the number of valid PTEs and wire_count
are inconsistent, and it caused KASSERT.
Need to hold a pv_lock while modifying them.


# 1.38 20-Mar-2019 ryo

spinkle __printflike(), and use PRIxxx


# 1.37 19-Mar-2019 ryo

- add ddb command "machine ttbr" to dump MMU tables.
- tidy up descriptions, usages and messages.


# 1.36 19-Mar-2019 ryo

- free L1-L3 pages that has been emptied by pmap_remove().
- if no memories, pmap_enter will return correctly ENOMEM if PMAP_CANFAIL, or wait until available any memories if !PMAP_CANFAIL.

These changes improves the stability when we use a huge virtual memory spaces with mmap.


# 1.35 06-Feb-2019 ryo

improve pmap_remove
- don't lock/unlock per page in pmap_remove()
- speedup pte lookup for continuous addresses
- bring out pool_cache_put(&_pmap_pv_pool, pv) from lock/unlock section


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226
# 1.34 21-Dec-2018 ryo

- add workaround for Cavium ThunderX errata 27456.
- add cpufuncs table in cpu_info. each cpu clusters may have different erratum. (e.g. big.LITTLE)


Revision tags: pgoyette-compat-1126
# 1.33 01-Nov-2018 maxv

Add kASan support for aarch64. Stack tracking needs more investigation
and will come in a separate commit.

Reviewed by ryo@ jmcneill@ skrll@.


# 1.32 31-Oct-2018 ryo

invalidate icache correctly.
l3pte_executable() should be used for only valid pte.


Revision tags: pgoyette-compat-1020
# 1.31 18-Oct-2018 skrll

Provide generic start code that assumes the MMU is off and caches are
disabled as per the linux booting protocol for ARMv6 and ARMv7 boards.
u-boot image type should be changed to 'linux' for correct behaviour.

The new start code builds a minimal "bootstrap" L1PT with cached access
disabled and uses the same table for all processors. AP startup is
performed in less steps and more code is written in C.

The bootstrap tables and stack are placed into an (orphaned) section
"_init_memory" which is given to uvm when it is no longer used.

Various kernels have been converted to use this code and tested. Some
boards were provided by TNF. Thanks!

The GENERIC kernel now boots on boards using the TEGRA, SUNXI and EXYNOS
kernels. The GENERIC kernel will also work on RPI2 using u-boot.

Thanks to martin@ and aymeric@ for testing on parallella and nanosoc
respectively


# 1.30 14-Oct-2018 skrll

Use __nothing


# 1.29 12-Oct-2018 ryo

add initial support of COMPAT_NETBSD32 on AArch64.
arm ELF32 EABI binaries could be execute in AArch32 state on AArch64. A32 THUMB mode is not supported yet.


# 1.28 12-Oct-2018 ryo

- cleanup checking address ranges with IN_RANGE macro
- change PM_ADDR_CHECK macro to KASSERTMSG
- restore fast lookup cases with IN_RANGE macro for pmap_extract changed in my previous commit.


# 1.27 12-Oct-2018 ryo

rewrite pmap_pte_lookup() to share similar code.


# 1.26 04-Oct-2018 ryo

cleanup locore, and changed the way to map memories during boot.
- add functions bootpage_enter() and bootpage_alloc() to adapt various layout
of physical memory map. especially for 64bit physical memory layout.
pmapboot_alloc() allocates pagetable pages from _end[].
- changed to map only the required amount for PA=VA identity mapping
(kernel image, UART device, and FDT blob) with L2_BLOCK(2Mbyte).
- changing page permission for kernel image, and making KSEG mapping are done
at cpu_kernel_vm_init() instead of at locore.
- optimize PTE entries with PTE Contiguous bit. it is enabled on devmap only for now.

reviewed by skrll@, thanks.


# 1.25 04-Oct-2018 ryo

* define LX_BLKPAG_{OS,ATTR}_* for OS dependent PTE attributes in pmap.h
* cleanup macros


Revision tags: pgoyette-compat-0930
# 1.24 17-Sep-2018 ryo

delete debug printf and KASSERT.


# 1.23 10-Sep-2018 maxv

Replace KDASSERT by panic.


# 1.22 10-Sep-2018 maxv

Rename _pmap_alloc_pdp -> pmap_alloc_pdp, and make it public.


# 1.21 10-Sep-2018 ryo

cleanup aarch64 mpstart and fdt bootstrap
* arm_cpu_hatch_arg is a bad idea. avoid serializing CPU startup, and eliminate arm_cpu_hatch_arg.
in mpstart, resolve own cpu index using array of cpu_mpidr[] (aarch64)
* add support fdt enable-method "spin-table"
* add support fdt enable-method "brcm,bcm2836-smp" (for 32bit RaspberryPi)
* use arm_fdt_cpu_bootstrap() instead of psci_fdt_bootstrap()
* rename "arm/fdt/psci_fdt.h" to "arm/fdt/psci_fdtvar.h" because of conflict of include file for needs-flag
* add devmap for cpu spin-table of raspberrypi3/aarch64
* no need to force hatch APs for raspberrypi3/arm32 ifndef MULTIPROCESSOR.
* fix to work pmap_extract(kerneltext/data/bss) even if before calling pmap_bootstrap

idea to use cpu_mpidr[] by jmcneill@. reviewd by skrll@. thanks.


Revision tags: pgoyette-compat-0906
# 1.20 27-Aug-2018 ryo

need to add VM_PROT_READ when pmap_kenter_pa(va, pa, VM_PROT_WRITE, 0) or pmap_kenter_pa(va, pa, VM_PROT_EXECUTE, 0).
VM_PROT_READ is treated as an access permission inernally.


# 1.19 11-Aug-2018 ryo

change to minimum invalidation of TLB.
specifying not only va but also asid, and not invalidate L0-L2 entry using tlbi_*_ll() if needed.


# 1.18 10-Aug-2018 ryo

treat kernel-exec attr and user-exec attr separately.
kernel cannot execute userland exec page, and user cannot execute kernel page.


# 1.17 06-Aug-2018 ryo

set kernel text/rodata readonly by default.
add function db_write_text() for setting ddb breakpoint.


# 1.16 31-Jul-2018 skrll

Define and use VPRINTF


Revision tags: pgoyette-compat-0728
# 1.15 27-Jul-2018 ryo

changes of pmap.c r1.13 seems to be unstable.
In order to invalidate icache, not to invalidate all icache,
but temporary to make the page writable and invalidate target address only.


# 1.14 24-Jul-2018 ryo

don't call pool_cache_put with locking pmap. pool_cache_put call pmap_kenter_pa internally.
(pool_cache_put_paddr -> pool_cache_put_slow -> pool_get -> pmap_kenter_pa)


# 1.13 23-Jul-2018 ryo

* fix icache invalidations.
* "ic ivau" (aarch64_icache_sync_range) with VA generates permission fault in some situations, therefore use KSEG address for now.


# 1.12 23-Jul-2018 ryo

rather than using flags to resolve nested locks, reserve pool_cache before locking.


# 1.11 21-Jul-2018 ryo

* avoid deadlock. mutex_owned() works only for adaptive lock, therefore we cannot use it for spinlock...
* add more NULL check
* clear pte when pmap_enter() fails


# 1.10 17-Jul-2018 ryo

Use __debugused


# 1.9 17-Jul-2018 christos

Add missing casts, remove unused variables.


# 1.8 09-Jul-2018 ryo

need locks in pmap_kremove() and pmap_fault_fixup()


Revision tags: phil-wifi-base pgoyette-compat-0625 pgoyette-compat-0521
# 1.7 20-May-2018 ryo

branches: 1.7.2;
pmap_enter() must update modified/referenced flags by 'flags' not 'prot'.


# 1.6 16-May-2018 ryo

Fix memory leak. it was leaking one page every pmap_create().
pm->pm_vmlist must be initialized before calling _pmap_alloc_pdp().


Revision tags: pgoyette-compat-0502
# 1.5 29-Apr-2018 ryo

fix KASSERT panic. pv_entry may not be exists in pvlist when pmap_remove().


# 1.4 29-Apr-2018 ryo

delete unused code


# 1.3 27-Apr-2018 ryo

fix instability behavior of bufcache on aarch64.
* fix to return correct ref/mod when PMAP_WIRED.
* changed to keep wired flags in pte instead of pv_entry, and cleanup.


Revision tags: pgoyette-compat-0422 pgoyette-compat-0415 pgoyette-compat-0407
# 1.2 01-Apr-2018 ryo

Add initial support for ARMv8 (AARCH64) (by nisimura@ and ryo@)

- sys/arch/evbarm64 is gone and integrated into sys/arch/evbarm. (by skrll@)
- add support fdt. evbarm/conf/GENERIC64 fdt (bcm2837,sunxi,tegra) based generic 64bit kernel config. (by skrll@, jmcneill@)


Revision tags: netbsd-8-2-RELEASE netbsd-8-1-RELEASE netbsd-8-1-RC1 netbsd-7-2-RELEASE netbsd-8-0-RELEASE netbsd-8-0-RC2 netbsd-8-0-RC1 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 netbsd-7-1-2-RELEASE pgoyette-compat-base netbsd-7-1-1-RELEASE tls-maxphys-base-20171202 matt-nb8-mediatek-base nick-nhusb-base-20170825 perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base pgoyette-localcount-20170320 netbsd-7-1-RELEASE netbsd-7-1-RC2 nick-nhusb-base-20170204 netbsd-7-nhusb-base-20170116 bouyer-socketcan-base pgoyette-localcount-20170107 netbsd-7-1-RC1 nick-nhusb-base-20161204 pgoyette-localcount-20161104 netbsd-7-0-2-RELEASE nick-nhusb-base-20161004 localcount-20160914 netbsd-7-nhusb-base pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907 nick-nhusb-base-20160529 netbsd-7-0-1-RELEASE nick-nhusb-base-20160422 nick-nhusb-base-20160319 nick-nhusb-base-20151226 netbsd-7-0-RELEASE nick-nhusb-base-20150921 netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 nick-nhusb-base-20150606 nick-nhusb-base-20150406 nick-nhusb-base tls-maxphys-base netbsd-7-base
# 1.1 10-Aug-2014 matt

branches: 1.1.4; 1.1.28;
Preliminary files for AARCH64 (64-bit ARM) support.
Enough for a distribution build.


# 1.123 14-Jan-2022 skrll

Restore the previous pmap_remove_all behaviour as the new method meant
the n1sdp couldn't complete a build.

No noticeable change in kernel build performance.


# 1.122 04-Jan-2022 skrll

KNF


# 1.121 10-Dec-2021 andvar

s/occured/occurred/ in comments, log messages and man pages.


# 1.120 07-Dec-2021 andvar

fix various typos, mainly in comments.


# 1.119 23-Oct-2021 skrll

Fix non-UVMHIST build


# 1.118 16-Oct-2021 ryo

fix non-MULTIPROCESSOR build


# 1.117 10-Oct-2021 skrll

Use sys/uvm/pmap/pmap_tlb.c on Aarch64 in the same way that some Arm, MIPS,
and some PPC kernels do. This removes the limitation of 256 processes on
CPUs with 8bit ASID field, e.g. Apple M1.

Additionally the following changes have been made

- removed a couple of unnecessary aarch64_tlbi_all calls
- removed any invalidation after freeing page tables due to
_pmap_sweep_pdp. This was never necessary afaict.
- all kernel mappings are marked global and userland mapping not-global.

Performance testing hasn't show a significant difference. The data here
is from building a kernel on an lx2k system with nvme.

before
1489.6u 400.4s 2:40.65 1176.5% 228+224k 0+32289io 57pf+0w
1482.6u 403.2s 2:38.49 1189.9% 228+222k 0+32274io 46pf+0w
1485.4u 402.2s 2:37.27 1200.2% 228+222k 0+32275io 12pf+0w

after
1493.9u 404.6s 2:37.50 1205.4% 227+221k 0+32265io 48pf+0w
1485.0u 408.0s 2:38.54 1194.0% 227+222k 0+32272io 36pf+0w
1484.3u 407.0s 2:35.88 1213.3% 228+224k 0+32268io 14pf+0w

>>> stats.ttest_ind([160.65,158.49,157.27], [157.5,158.54,155.88])
Ttest_indResult(statistic=1.1923622711296888, pvalue=0.2990182944606766)
>>>


# 1.116 30-Sep-2021 skrll

Ensure TCR_EPD0 is set on entry to pmap_activate and ensure it is set as
early as possible for APs.


# 1.115 26-Sep-2021 skrll

Use UVMHIST_CALLARGS


# 1.114 26-Sep-2021 skrll

'\n' is not required in KASSERTMSG either.


# 1.113 26-Sep-2021 skrll

"\n" is not required in KERNHIST


# 1.112 15-Sep-2021 skrll

Use __SHIFTIN. Same code before and after.


# 1.111 12-Sep-2021 skrll

pmap_page_remove: simply and reduce the code size slightly.


# 1.110 09-Sep-2021 skrll

In pmap_icache_sync_range change

for (...) {
...
if (condition) {
// do stuff
}
}

to

for (...) {
...
if (!conditional)
continue;
// do stuff
}

to save on indentation. Same code (modulo register usage) before and
after.


# 1.109 09-Sep-2021 skrll

KNF


Revision tags: thorpej-i2c-spi-conf2-base thorpej-futex2-base thorpej-cfargs2-base cjep_sun2x-base1 cjep_sun2x-base cjep_staticlib_x-base1 thorpej-i2c-spi-conf-base
# 1.108 29-May-2021 skrll

Deal with the pmap limitation of maxproc in a more complete way and
recognise CPUs with only 8bit ASIDs.


Revision tags: cjep_staticlib_x-base
# 1.107 30-Apr-2021 skrll

branches: 1.107.2;
Make the ddb for pmap / pte information pmap agnostic


# 1.106 29-Apr-2021 skrll

Remove some unnecessary tlb invalidate in pmap_growkernel and ASAN shadow
map. Ensure the shadow map mappings are visible to the TLB walkers.


# 1.105 21-Apr-2021 ryo

branches: 1.105.2;
added more attributes of PTE displayed by "ddb>machine pte"


Revision tags: thorpej-cfargs-base
# 1.104 17-Apr-2021 mrg

remove KERNHIST_INIT_STATIC(). it stradles the line between usable
early in boot and broken early in boot by requiring a partly static
structure with another structure that must be present by the time
any uses are performed. theoretically platform code could allocate
a chunk while seting up memory and assign it here, giving a dynamic
sizing for the entry list, but the reality is that all users have
a statically allocated entry list as well.

the existing KERNHIST_LINK_STATIC() is used in conjunction with
KERNHIST_INITIALIZER() instead.

this stops a NULL pointer deref when the _LOG() macro is called
before the storage is linked in, which happens with GCC 10 on OCTEON
with UVMHIST enabled, crashing in very early kernel init.


Revision tags: thorpej-futex-base
# 1.103 09-Mar-2021 ryo

branches: 1.103.2;
fix build error without options DDB.

kvtopte() is referenced from arm/acpi/acpi_machdep.c


# 1.102 13-Feb-2021 ryo

No assignment is needed here.

the loop in pmap_page_remove() always removes the first pv,
and since the list is managed by _pmap_remove_pv(), pp->pp_pv.pv_next always points to the first.


# 1.101 01-Feb-2021 ryo

It is enough to make a page accessible instead of writable.
same fix as r1.76


# 1.100 31-Jan-2021 ryo

implement pmap_remove_all().

The size of struct pv_entry has increased, but speed of kernel build has improved by about 1%
exec and exit should have been improved.


# 1.99 20-Dec-2020 skrll

Improve the English in the previous comment fix.


# 1.98 19-Dec-2020 skrll

Tweak a comment


# 1.97 11-Dec-2020 skrll

s:aarch64/cpufunc.h:arm/cpufunc.h:

a baby step in the grand arm header unification challenge


# 1.96 10-Nov-2020 skrll

AA64 is not MIPS.

Change all KSEG references to directmap


# 1.95 07-Nov-2020 skrll

In pmap_devmap_bootstrap only set pmap_devmap_bootstrap_done if there
is an entry and ALL of the entries have been done. The entry required
for EARLYCONS might not be the first/only one...


# 1.94 01-Nov-2020 jmcneill

branches: 1.94.2;
No need to disable translation table walks in pmap_activate().


# 1.93 22-Oct-2020 skrll

Use the isb macro - missed in previous commit


# 1.92 22-Oct-2020 skrll

Use the dmb/dsb/isb macros... if nothing else they're all now consistent
about the "memory" assembler contraint.

No binary change


# 1.91 28-Sep-2020 skrll

Only set pmap_devmap_bootstrap_done if something gets mapped.

Think acpi_platform_devmap


# 1.90 19-Sep-2020 skrll

Make __md_palloc pmap agnostic (think sys/uvm/pmap)


# 1.89 14-Sep-2020 ryo

PID_MAX is just an initial value (soft maximum). Don't use it for CTASSERT.
defined __HAVE_CPU_MAXPROC to use function cpu_maxproc().

pointed out by mrg@, thanks.


# 1.88 06-Sep-2020 ryo

Fix panic caused by modload. http://mail-index.netbsd.org/port-arm/2020/08/30/msg006960.html

The address space reserved for modules may not be mapped in L1-L3.


# 1.87 14-Aug-2020 skrll

Whitespace


# 1.86 12-Aug-2020 skrll

Part IV of ad's performance improvements for aarch64

- Implement pmap_growkernel(), and update kernel pmap's stats with atomics.

- Then, pmap_kenter_pa() and pmap_kremove() no longer need to allocate
memory nor take pm_lock, because they only modify L3 PTEs.

- Then, pm_lock and pp_lock can be adaptive mutexes at IPL_NONE which are
cheaper than spin mutexes.

- Take the pmap's lock in pmap_extract() if not the kernel's pmap, otherwise
pmap_extract() might see inconsistent state.


# 1.85 09-Aug-2020 skrll

Fix another UVMHIST so it doesn't use %s


# 1.84 16-Jul-2020 skrll

pmapboot_enter simplication
- bootpage_alloc in asm becomes pmapboot_pagealloc in C
- PMAPBOOT_ENTER_NOBLOCK is removed as it's not used
- PMAPBOOT_ENTER_NOOVERWRITE is removed as it's now always on
- physpage_allocator argument is removed as it's always
pmapboot_pagealloc
- Support for EARLYCONS without CONSADDR is removed so that the identity
map for CONSADDR is always known.

For the assembly files:
2 files changed, 40 insertions(+), 89 deletions(-)

LGTM ryo


# 1.83 04-Jul-2020 rin

Use tlen for temporary length variable instead of l, which is usually
used for struct lwp *.

No binary changes.


# 1.82 02-Jul-2020 rin

pmap_procwr(): sync icache even if p != curproc. This fixes applications
like GDB for arm32, that rewrite text of other process.

Thanks to ryo@ for discussion.


# 1.81 02-Jul-2020 rin

Set uvmexp.ncolors appropriately, which is required for some CPU
models with VIPT icache.

Otherwise, alias in virtual address results in inconsistent results,
at least for applications that rewrite text of other process, e.g.,
GDB for arm32.

Also, this hopefully fixes other unexpected failures due to alias.

Confirmed that there's no observable regression in performance;
difference in ``time make -j8'' for GENERIC64 kernel on BCM2837
with and without setting uvmexp.ncolors is within 0.1%.

Thanks to ryo@ for discussion.


# 1.80 27-Jun-2020 rin

Fix typo in name of evcnt(4) counter.


# 1.79 24-Jun-2020 ryo

Fix bug with incorrect range calculation when doing icache sync.
This is called by sysarch(ARM_SYNC_ICACHE) from aarch32 (compat_netbsd32) emul process.

pointed out by rin@, thanks.

XXX pullup-9


# 1.78 14-Jun-2020 ad

- Fix a lock order reversal in pmap_page_protect().

- Make sure pmap is always locked when updating stats; atomics no longer
needed to do that.

- Remove unneeded traversal of pv list in pmap_enter_pv().

- Shrink struct vm_page from 136 to 128 bytes (cache line sized) and struct
pv_entry from 48 to 32 bytes (power of 2 sized).

- Embed a pv_entry in each vm_page. This means PV entries don't need to
be allocated for private anonymous memory / COW pages / most UBC mappings.
Dynamic PV entries are then used only for stuff like shared libraries and
shared memory.

Proposed on port-arm@.


# 1.77 10-Jun-2020 ad

- Wired/resident stats shouldn't covered by PMAPCOUNTERS.
- Rename need_update_pv -> need_enter_pv.

Ok ryo@


# 1.76 01-Jun-2020 ryo

no need to make the PTE writable to do icache_sync, enough to accessible.


# 1.75 15-May-2020 skrll

Use __diagused


# 1.74 15-May-2020 tnn

fix non-diag build


# 1.73 14-May-2020 skrll

Use MUTEX_NODEBUG for PV locks as is commonly done. OK ryo.


# 1.72 13-May-2020 jmcneill

Implement pmap_extract_coherency


Revision tags: bouyer-xenpvh-base2 phil-wifi-20200421 bouyer-xenpvh-base1
# 1.71 18-Apr-2020 skrll

PMAP_DEBUG has been deleted on arm


# 1.70 13-Apr-2020 maxv

Add support for Branch Target Identification (BTI).

On the executable pages that have the GP (Guarded Page) bit, the semantic
of the "br" and "blr" instructions is changed: the CPU expects the first
instruction of the jump/call target to be "bti", and faults if it isn't.

We add the GP bit on the kernel .text pages (and incidentally the .rodata
pages, but we don't care). The compiler adds a "bti c" instruction at the
beginning of each C function. We modify the ENTRY() macros to manually add
"bti c" in the asm functions.

cpuswitch.S needs a specific change: with "br x27" the CPU expects "bti j",
which is bad because the functions begin with "bti c"; switch to "br x16",
for the CPU to accept "bti c".

BTI helps defend against JOP/COP. Tested on Qemu.


Revision tags: phil-wifi-20200411 bouyer-xenpvh-base
# 1.69 08-Apr-2020 ryo

branches: 1.69.2;
use PMAP_PAGE_INIT() to initialize mutex in pmap_page.

VM_MDPAGE_INIT() in pmap_free_pdp() had initialized pp_flags,
so it unintentionally cleared PMAP_PAGE_FLAGS_PV_TRACKED.
use PMAP_PAGE_INIT to avoid using PMAP_PAGE_FLAGS_PV_TRACKED.

pointed out by tnn@, thanks


Revision tags: phil-wifi-20200406
# 1.68 14-Mar-2020 ad

pmap_remove_all(): Return a boolean value to indicate the behaviour. If
true, all mappings have been removed, the pmap is totally cleared out, and
UVM can then avoid doing the work to call pmap_remove() for each map entry.
If false, either nothing has been done, or some helpful arch-specific voodoo
has taken place.


Revision tags: is-mlppp-base
# 1.67 02-Mar-2020 ryo

oops, fix incorrect usage of daif_enable() in my previous commit.


# 1.66 29-Feb-2020 ryo

Fix pmap to work correctly with tagged addresses

- when fault, untag from address before passing to uvm/pmap functions
- pmap_extract() checks more strictly and consider the address tag


# 1.65 29-Feb-2020 ryo

use pmapboot_enter_range()


Revision tags: ad-namecache-base3
# 1.64 10-Feb-2020 ryo

use LIST(3) instead of TAILQ(3) to save one word in struct vm_page and struct pmap.

pointed out by riastradh@. thanks


# 1.63 03-Feb-2020 ryo

add support pmap_pv(9)

Patch originally from jmcneill@. thanks


# 1.62 03-Feb-2020 ryo

separate struct vm_page_md into vm_page_md and pmap_page
for preparation pmap_pv(9)


Revision tags: ad-namecache-base2 ad-namecache-base1
# 1.61 09-Jan-2020 ryo

fix behaviour mmap()/mprotect() when passed only PROT_EXEC.

when mmap()/mprotect() with only PROT_EXEC, syscall will be successful,
but the page actually hadn't been mapped.
it should be mapped with PROT_READ|PROT_EXEC implicitly. (r-x)


Revision tags: ad-namecache-base
# 1.60 30-Dec-2019 skrll

branches: 1.60.2;
Update pmap_map_chunk to allow L[12] block mappings and L3 page mappings


# 1.59 30-Dec-2019 skrll

Remove unnecessary brackets and unwrap a conditional. Same code before
and after.


# 1.58 28-Dec-2019 jmcneill

Do not use Early Write Acknowledge for PCIe I/O and config space.


# 1.57 27-Dec-2019 jmcneill

Enable early write acknowledge for device memory mappings.


# 1.56 19-Dec-2019 skrll

G/C kasan_shadow_map call in pmap_enter

pmap_growkernel calls kasan_shadow_map for KVA


# 1.55 18-Dec-2019 ryo

atomic_add_16() is not used in pmap.c anymore. no need decl here.


# 1.54 18-Dec-2019 ryo

space to tab


# 1.53 14-Dec-2019 skrll

Fix build... wire_count probably doesn't need atomics


# 1.52 13-Dec-2019 skrll

Fix KASAN support by calling kasan_shadow_map in pmap_growkernel


# 1.51 10-Dec-2019 ad

pg->phys_addr -> VM_PAGE_TO_PHYS(pg)


Revision tags: phil-wifi-20191119
# 1.50 14-Nov-2019 maxv

Mark several kASan functions with __nothing, to avoid annoying #ifdefs.
Same as kCSan and kMSan.


# 1.49 14-Nov-2019 maxv

Don't include "opt_kasan.h" when there's already <sys/asan.h> included.


# 1.48 29-Oct-2019 maya

Define PMAP_NEED_PROCWR, providing strategically placed i-cache
synchronization where just-changed memory is about to be executed.

Fixes SIGILLs seen when running Mono 6 on QEMU Cortex-A57.

ok ryo


# 1.47 22-Sep-2019 jmcneill

Disable translation table walks using TTBR0 while changing its value and
when deactivating a pmap. Fixes stability issues on Ampere eMAG CPUs.


# 1.46 20-Sep-2019 ryo

ref/mod bit should be set according to 'flags' argument, not 'prot'. r1.44 was incomplete.


# 1.45 13-Sep-2019 ryo

In pmap_devmap_bootstrap(), cpu_earlydevice_va_p() must not return true until *all* devmap tables have been enabled.
console mapping may be present in the last table.


# 1.44 07-Sep-2019 ryo

- remove incorrect KASSERT. mmap(2) with prot=PROT_WRITE calls pmap_enter(..., PROT_WRITE) internally.
- fix to update page reference flags when only PROT_WRITE or PROT_EXECUTE specified


# 1.43 15-Aug-2019 skrll

Make pmap_db_pte_print more terse so it's quicker on serial consoles


# 1.42 12-Aug-2019 skrll

Use PMAP_DEV in DEVMAP_ENTRY rather than pmap_map_chunk. It's clearer and
means pmap_map_chunk can be made to map other memory types.


Revision tags: netbsd-9-base phil-wifi-20190609
# 1.41 17-May-2019 mrg

branches: 1.41.2;
apply some __diagused.


Revision tags: isaki-audio2-base
# 1.40 08-Apr-2019 ryo

- free empty page tables pages if reach a certain usage.
- need to lock at removing an old pg (_pmap_remove_pv) in _pmap_enter()


# 1.39 06-Apr-2019 ryo

Fix race conditions about pmap_page_protect() and pmap_enter().

while handling same PTE by these functions in same time, there
is a critical path that the number of valid PTEs and wire_count
are inconsistent, and it caused KASSERT.
Need to hold a pv_lock while modifying them.


# 1.38 20-Mar-2019 ryo

spinkle __printflike(), and use PRIxxx


# 1.37 19-Mar-2019 ryo

- add ddb command "machine ttbr" to dump MMU tables.
- tidy up descriptions, usages and messages.


# 1.36 19-Mar-2019 ryo

- free L1-L3 pages that has been emptied by pmap_remove().
- if no memories, pmap_enter will return correctly ENOMEM if PMAP_CANFAIL, or wait until available any memories if !PMAP_CANFAIL.

These changes improves the stability when we use a huge virtual memory spaces with mmap.


# 1.35 06-Feb-2019 ryo

improve pmap_remove
- don't lock/unlock per page in pmap_remove()
- speedup pte lookup for continuous addresses
- bring out pool_cache_put(&_pmap_pv_pool, pv) from lock/unlock section


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226
# 1.34 21-Dec-2018 ryo

- add workaround for Cavium ThunderX errata 27456.
- add cpufuncs table in cpu_info. each cpu clusters may have different erratum. (e.g. big.LITTLE)


Revision tags: pgoyette-compat-1126
# 1.33 01-Nov-2018 maxv

Add kASan support for aarch64. Stack tracking needs more investigation
and will come in a separate commit.

Reviewed by ryo@ jmcneill@ skrll@.


# 1.32 31-Oct-2018 ryo

invalidate icache correctly.
l3pte_executable() should be used for only valid pte.


Revision tags: pgoyette-compat-1020
# 1.31 18-Oct-2018 skrll

Provide generic start code that assumes the MMU is off and caches are
disabled as per the linux booting protocol for ARMv6 and ARMv7 boards.
u-boot image type should be changed to 'linux' for correct behaviour.

The new start code builds a minimal "bootstrap" L1PT with cached access
disabled and uses the same table for all processors. AP startup is
performed in less steps and more code is written in C.

The bootstrap tables and stack are placed into an (orphaned) section
"_init_memory" which is given to uvm when it is no longer used.

Various kernels have been converted to use this code and tested. Some
boards were provided by TNF. Thanks!

The GENERIC kernel now boots on boards using the TEGRA, SUNXI and EXYNOS
kernels. The GENERIC kernel will also work on RPI2 using u-boot.

Thanks to martin@ and aymeric@ for testing on parallella and nanosoc
respectively


# 1.30 14-Oct-2018 skrll

Use __nothing


# 1.29 12-Oct-2018 ryo

add initial support of COMPAT_NETBSD32 on AArch64.
arm ELF32 EABI binaries could be execute in AArch32 state on AArch64. A32 THUMB mode is not supported yet.


# 1.28 12-Oct-2018 ryo

- cleanup checking address ranges with IN_RANGE macro
- change PM_ADDR_CHECK macro to KASSERTMSG
- restore fast lookup cases with IN_RANGE macro for pmap_extract changed in my previous commit.


# 1.27 12-Oct-2018 ryo

rewrite pmap_pte_lookup() to share similar code.


# 1.26 04-Oct-2018 ryo

cleanup locore, and changed the way to map memories during boot.
- add functions bootpage_enter() and bootpage_alloc() to adapt various layout
of physical memory map. especially for 64bit physical memory layout.
pmapboot_alloc() allocates pagetable pages from _end[].
- changed to map only the required amount for PA=VA identity mapping
(kernel image, UART device, and FDT blob) with L2_BLOCK(2Mbyte).
- changing page permission for kernel image, and making KSEG mapping are done
at cpu_kernel_vm_init() instead of at locore.
- optimize PTE entries with PTE Contiguous bit. it is enabled on devmap only for now.

reviewed by skrll@, thanks.


# 1.25 04-Oct-2018 ryo

* define LX_BLKPAG_{OS,ATTR}_* for OS dependent PTE attributes in pmap.h
* cleanup macros


Revision tags: pgoyette-compat-0930
# 1.24 17-Sep-2018 ryo

delete debug printf and KASSERT.


# 1.23 10-Sep-2018 maxv

Replace KDASSERT by panic.


# 1.22 10-Sep-2018 maxv

Rename _pmap_alloc_pdp -> pmap_alloc_pdp, and make it public.


# 1.21 10-Sep-2018 ryo

cleanup aarch64 mpstart and fdt bootstrap
* arm_cpu_hatch_arg is a bad idea. avoid serializing CPU startup, and eliminate arm_cpu_hatch_arg.
in mpstart, resolve own cpu index using array of cpu_mpidr[] (aarch64)
* add support fdt enable-method "spin-table"
* add support fdt enable-method "brcm,bcm2836-smp" (for 32bit RaspberryPi)
* use arm_fdt_cpu_bootstrap() instead of psci_fdt_bootstrap()
* rename "arm/fdt/psci_fdt.h" to "arm/fdt/psci_fdtvar.h" because of conflict of include file for needs-flag
* add devmap for cpu spin-table of raspberrypi3/aarch64
* no need to force hatch APs for raspberrypi3/arm32 ifndef MULTIPROCESSOR.
* fix to work pmap_extract(kerneltext/data/bss) even if before calling pmap_bootstrap

idea to use cpu_mpidr[] by jmcneill@. reviewd by skrll@. thanks.


Revision tags: pgoyette-compat-0906
# 1.20 27-Aug-2018 ryo

need to add VM_PROT_READ when pmap_kenter_pa(va, pa, VM_PROT_WRITE, 0) or pmap_kenter_pa(va, pa, VM_PROT_EXECUTE, 0).
VM_PROT_READ is treated as an access permission inernally.


# 1.19 11-Aug-2018 ryo

change to minimum invalidation of TLB.
specifying not only va but also asid, and not invalidate L0-L2 entry using tlbi_*_ll() if needed.


# 1.18 10-Aug-2018 ryo

treat kernel-exec attr and user-exec attr separately.
kernel cannot execute userland exec page, and user cannot execute kernel page.


# 1.17 06-Aug-2018 ryo

set kernel text/rodata readonly by default.
add function db_write_text() for setting ddb breakpoint.


# 1.16 31-Jul-2018 skrll

Define and use VPRINTF


Revision tags: pgoyette-compat-0728
# 1.15 27-Jul-2018 ryo

changes of pmap.c r1.13 seems to be unstable.
In order to invalidate icache, not to invalidate all icache,
but temporary to make the page writable and invalidate target address only.


# 1.14 24-Jul-2018 ryo

don't call pool_cache_put with locking pmap. pool_cache_put call pmap_kenter_pa internally.
(pool_cache_put_paddr -> pool_cache_put_slow -> pool_get -> pmap_kenter_pa)


# 1.13 23-Jul-2018 ryo

* fix icache invalidations.
* "ic ivau" (aarch64_icache_sync_range) with VA generates permission fault in some situations, therefore use KSEG address for now.


# 1.12 23-Jul-2018 ryo

rather than using flags to resolve nested locks, reserve pool_cache before locking.


# 1.11 21-Jul-2018 ryo

* avoid deadlock. mutex_owned() works only for adaptive lock, therefore we cannot use it for spinlock...
* add more NULL check
* clear pte when pmap_enter() fails


# 1.10 17-Jul-2018 ryo

Use __debugused


# 1.9 17-Jul-2018 christos

Add missing casts, remove unused variables.


# 1.8 09-Jul-2018 ryo

need locks in pmap_kremove() and pmap_fault_fixup()


Revision tags: phil-wifi-base pgoyette-compat-0625 pgoyette-compat-0521
# 1.7 20-May-2018 ryo

branches: 1.7.2;
pmap_enter() must update modified/referenced flags by 'flags' not 'prot'.


# 1.6 16-May-2018 ryo

Fix memory leak. it was leaking one page every pmap_create().
pm->pm_vmlist must be initialized before calling _pmap_alloc_pdp().


Revision tags: pgoyette-compat-0502
# 1.5 29-Apr-2018 ryo

fix KASSERT panic. pv_entry may not be exists in pvlist when pmap_remove().


# 1.4 29-Apr-2018 ryo

delete unused code


# 1.3 27-Apr-2018 ryo

fix instability behavior of bufcache on aarch64.
* fix to return correct ref/mod when PMAP_WIRED.
* changed to keep wired flags in pte instead of pv_entry, and cleanup.


Revision tags: pgoyette-compat-0422 pgoyette-compat-0415 pgoyette-compat-0407
# 1.2 01-Apr-2018 ryo

Add initial support for ARMv8 (AARCH64) (by nisimura@ and ryo@)

- sys/arch/evbarm64 is gone and integrated into sys/arch/evbarm. (by skrll@)
- add support fdt. evbarm/conf/GENERIC64 fdt (bcm2837,sunxi,tegra) based generic 64bit kernel config. (by skrll@, jmcneill@)


Revision tags: netbsd-8-2-RELEASE netbsd-8-1-RELEASE netbsd-8-1-RC1 netbsd-7-2-RELEASE netbsd-8-0-RELEASE netbsd-8-0-RC2 netbsd-8-0-RC1 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 netbsd-7-1-2-RELEASE pgoyette-compat-base netbsd-7-1-1-RELEASE tls-maxphys-base-20171202 matt-nb8-mediatek-base nick-nhusb-base-20170825 perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base pgoyette-localcount-20170320 netbsd-7-1-RELEASE netbsd-7-1-RC2 nick-nhusb-base-20170204 netbsd-7-nhusb-base-20170116 bouyer-socketcan-base pgoyette-localcount-20170107 netbsd-7-1-RC1 nick-nhusb-base-20161204 pgoyette-localcount-20161104 netbsd-7-0-2-RELEASE nick-nhusb-base-20161004 localcount-20160914 netbsd-7-nhusb-base pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907 nick-nhusb-base-20160529 netbsd-7-0-1-RELEASE nick-nhusb-base-20160422 nick-nhusb-base-20160319 nick-nhusb-base-20151226 netbsd-7-0-RELEASE nick-nhusb-base-20150921 netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 nick-nhusb-base-20150606 nick-nhusb-base-20150406 nick-nhusb-base tls-maxphys-base netbsd-7-base
# 1.1 10-Aug-2014 matt

branches: 1.1.4; 1.1.28;
Preliminary files for AARCH64 (64-bit ARM) support.
Enough for a distribution build.


# 1.122 04-Jan-2022 skrll

KNF


# 1.121 10-Dec-2021 andvar

s/occured/occurred/ in comments, log messages and man pages.


# 1.120 07-Dec-2021 andvar

fix various typos, mainly in comments.


# 1.119 23-Oct-2021 skrll

Fix non-UVMHIST build


# 1.118 16-Oct-2021 ryo

fix non-MULTIPROCESSOR build


# 1.117 10-Oct-2021 skrll

Use sys/uvm/pmap/pmap_tlb.c on Aarch64 in the same way that some Arm, MIPS,
and some PPC kernels do. This removes the limitation of 256 processes on
CPUs with 8bit ASID field, e.g. Apple M1.

Additionally the following changes have been made

- removed a couple of unnecessary aarch64_tlbi_all calls
- removed any invalidation after freeing page tables due to
_pmap_sweep_pdp. This was never necessary afaict.
- all kernel mappings are marked global and userland mapping not-global.

Performance testing hasn't show a significant difference. The data here
is from building a kernel on an lx2k system with nvme.

before
1489.6u 400.4s 2:40.65 1176.5% 228+224k 0+32289io 57pf+0w
1482.6u 403.2s 2:38.49 1189.9% 228+222k 0+32274io 46pf+0w
1485.4u 402.2s 2:37.27 1200.2% 228+222k 0+32275io 12pf+0w

after
1493.9u 404.6s 2:37.50 1205.4% 227+221k 0+32265io 48pf+0w
1485.0u 408.0s 2:38.54 1194.0% 227+222k 0+32272io 36pf+0w
1484.3u 407.0s 2:35.88 1213.3% 228+224k 0+32268io 14pf+0w

>>> stats.ttest_ind([160.65,158.49,157.27], [157.5,158.54,155.88])
Ttest_indResult(statistic=1.1923622711296888, pvalue=0.2990182944606766)
>>>


# 1.116 30-Sep-2021 skrll

Ensure TCR_EPD0 is set on entry to pmap_activate and ensure it is set as
early as possible for APs.


# 1.115 26-Sep-2021 skrll

Use UVMHIST_CALLARGS


# 1.114 26-Sep-2021 skrll

'\n' is not required in KASSERTMSG either.


# 1.113 26-Sep-2021 skrll

"\n" is not required in KERNHIST


# 1.112 15-Sep-2021 skrll

Use __SHIFTIN. Same code before and after.


# 1.111 12-Sep-2021 skrll

pmap_page_remove: simply and reduce the code size slightly.


# 1.110 09-Sep-2021 skrll

In pmap_icache_sync_range change

for (...) {
...
if (condition) {
// do stuff
}
}

to

for (...) {
...
if (!conditional)
continue;
// do stuff
}

to save on indentation. Same code (modulo register usage) before and
after.


# 1.109 09-Sep-2021 skrll

KNF


Revision tags: thorpej-i2c-spi-conf2-base thorpej-futex2-base thorpej-cfargs2-base cjep_sun2x-base1 cjep_sun2x-base cjep_staticlib_x-base1 thorpej-i2c-spi-conf-base
# 1.108 29-May-2021 skrll

Deal with the pmap limitation of maxproc in a more complete way and
recognise CPUs with only 8bit ASIDs.


Revision tags: cjep_staticlib_x-base
# 1.107 30-Apr-2021 skrll

branches: 1.107.2;
Make the ddb for pmap / pte information pmap agnostic


# 1.106 29-Apr-2021 skrll

Remove some unnecessary tlb invalidate in pmap_growkernel and ASAN shadow
map. Ensure the shadow map mappings are visible to the TLB walkers.


# 1.105 21-Apr-2021 ryo

branches: 1.105.2;
added more attributes of PTE displayed by "ddb>machine pte"


Revision tags: thorpej-cfargs-base
# 1.104 17-Apr-2021 mrg

remove KERNHIST_INIT_STATIC(). it stradles the line between usable
early in boot and broken early in boot by requiring a partly static
structure with another structure that must be present by the time
any uses are performed. theoretically platform code could allocate
a chunk while seting up memory and assign it here, giving a dynamic
sizing for the entry list, but the reality is that all users have
a statically allocated entry list as well.

the existing KERNHIST_LINK_STATIC() is used in conjunction with
KERNHIST_INITIALIZER() instead.

this stops a NULL pointer deref when the _LOG() macro is called
before the storage is linked in, which happens with GCC 10 on OCTEON
with UVMHIST enabled, crashing in very early kernel init.


Revision tags: thorpej-futex-base
# 1.103 09-Mar-2021 ryo

branches: 1.103.2;
fix build error without options DDB.

kvtopte() is referenced from arm/acpi/acpi_machdep.c


# 1.102 13-Feb-2021 ryo

No assignment is needed here.

the loop in pmap_page_remove() always removes the first pv,
and since the list is managed by _pmap_remove_pv(), pp->pp_pv.pv_next always points to the first.


# 1.101 01-Feb-2021 ryo

It is enough to make a page accessible instead of writable.
same fix as r1.76


# 1.100 31-Jan-2021 ryo

implement pmap_remove_all().

The size of struct pv_entry has increased, but speed of kernel build has improved by about 1%
exec and exit should have been improved.


# 1.99 20-Dec-2020 skrll

Improve the English in the previous comment fix.


# 1.98 19-Dec-2020 skrll

Tweak a comment


# 1.97 11-Dec-2020 skrll

s:aarch64/cpufunc.h:arm/cpufunc.h:

a baby step in the grand arm header unification challenge


# 1.96 10-Nov-2020 skrll

AA64 is not MIPS.

Change all KSEG references to directmap


# 1.95 07-Nov-2020 skrll

In pmap_devmap_bootstrap only set pmap_devmap_bootstrap_done if there
is an entry and ALL of the entries have been done. The entry required
for EARLYCONS might not be the first/only one...


# 1.94 01-Nov-2020 jmcneill

branches: 1.94.2;
No need to disable translation table walks in pmap_activate().


# 1.93 22-Oct-2020 skrll

Use the isb macro - missed in previous commit


# 1.92 22-Oct-2020 skrll

Use the dmb/dsb/isb macros... if nothing else they're all now consistent
about the "memory" assembler contraint.

No binary change


# 1.91 28-Sep-2020 skrll

Only set pmap_devmap_bootstrap_done if something gets mapped.

Think acpi_platform_devmap


# 1.90 19-Sep-2020 skrll

Make __md_palloc pmap agnostic (think sys/uvm/pmap)


# 1.89 14-Sep-2020 ryo

PID_MAX is just an initial value (soft maximum). Don't use it for CTASSERT.
defined __HAVE_CPU_MAXPROC to use function cpu_maxproc().

pointed out by mrg@, thanks.


# 1.88 06-Sep-2020 ryo

Fix panic caused by modload. http://mail-index.netbsd.org/port-arm/2020/08/30/msg006960.html

The address space reserved for modules may not be mapped in L1-L3.


# 1.87 14-Aug-2020 skrll

Whitespace


# 1.86 12-Aug-2020 skrll

Part IV of ad's performance improvements for aarch64

- Implement pmap_growkernel(), and update kernel pmap's stats with atomics.

- Then, pmap_kenter_pa() and pmap_kremove() no longer need to allocate
memory nor take pm_lock, because they only modify L3 PTEs.

- Then, pm_lock and pp_lock can be adaptive mutexes at IPL_NONE which are
cheaper than spin mutexes.

- Take the pmap's lock in pmap_extract() if not the kernel's pmap, otherwise
pmap_extract() might see inconsistent state.


# 1.85 09-Aug-2020 skrll

Fix another UVMHIST so it doesn't use %s


# 1.84 16-Jul-2020 skrll

pmapboot_enter simplication
- bootpage_alloc in asm becomes pmapboot_pagealloc in C
- PMAPBOOT_ENTER_NOBLOCK is removed as it's not used
- PMAPBOOT_ENTER_NOOVERWRITE is removed as it's now always on
- physpage_allocator argument is removed as it's always
pmapboot_pagealloc
- Support for EARLYCONS without CONSADDR is removed so that the identity
map for CONSADDR is always known.

For the assembly files:
2 files changed, 40 insertions(+), 89 deletions(-)

LGTM ryo


# 1.83 04-Jul-2020 rin

Use tlen for temporary length variable instead of l, which is usually
used for struct lwp *.

No binary changes.


# 1.82 02-Jul-2020 rin

pmap_procwr(): sync icache even if p != curproc. This fixes applications
like GDB for arm32, that rewrite text of other process.

Thanks to ryo@ for discussion.


# 1.81 02-Jul-2020 rin

Set uvmexp.ncolors appropriately, which is required for some CPU
models with VIPT icache.

Otherwise, alias in virtual address results in inconsistent results,
at least for applications that rewrite text of other process, e.g.,
GDB for arm32.

Also, this hopefully fixes other unexpected failures due to alias.

Confirmed that there's no observable regression in performance;
difference in ``time make -j8'' for GENERIC64 kernel on BCM2837
with and without setting uvmexp.ncolors is within 0.1%.

Thanks to ryo@ for discussion.


# 1.80 27-Jun-2020 rin

Fix typo in name of evcnt(4) counter.


# 1.79 24-Jun-2020 ryo

Fix bug with incorrect range calculation when doing icache sync.
This is called by sysarch(ARM_SYNC_ICACHE) from aarch32 (compat_netbsd32) emul process.

pointed out by rin@, thanks.

XXX pullup-9


# 1.78 14-Jun-2020 ad

- Fix a lock order reversal in pmap_page_protect().

- Make sure pmap is always locked when updating stats; atomics no longer
needed to do that.

- Remove unneeded traversal of pv list in pmap_enter_pv().

- Shrink struct vm_page from 136 to 128 bytes (cache line sized) and struct
pv_entry from 48 to 32 bytes (power of 2 sized).

- Embed a pv_entry in each vm_page. This means PV entries don't need to
be allocated for private anonymous memory / COW pages / most UBC mappings.
Dynamic PV entries are then used only for stuff like shared libraries and
shared memory.

Proposed on port-arm@.


# 1.77 10-Jun-2020 ad

- Wired/resident stats shouldn't covered by PMAPCOUNTERS.
- Rename need_update_pv -> need_enter_pv.

Ok ryo@


# 1.76 01-Jun-2020 ryo

no need to make the PTE writable to do icache_sync, enough to accessible.


# 1.75 15-May-2020 skrll

Use __diagused


# 1.74 15-May-2020 tnn

fix non-diag build


# 1.73 14-May-2020 skrll

Use MUTEX_NODEBUG for PV locks as is commonly done. OK ryo.


# 1.72 13-May-2020 jmcneill

Implement pmap_extract_coherency


Revision tags: bouyer-xenpvh-base2 phil-wifi-20200421 bouyer-xenpvh-base1
# 1.71 18-Apr-2020 skrll

PMAP_DEBUG has been deleted on arm


# 1.70 13-Apr-2020 maxv

Add support for Branch Target Identification (BTI).

On the executable pages that have the GP (Guarded Page) bit, the semantic
of the "br" and "blr" instructions is changed: the CPU expects the first
instruction of the jump/call target to be "bti", and faults if it isn't.

We add the GP bit on the kernel .text pages (and incidentally the .rodata
pages, but we don't care). The compiler adds a "bti c" instruction at the
beginning of each C function. We modify the ENTRY() macros to manually add
"bti c" in the asm functions.

cpuswitch.S needs a specific change: with "br x27" the CPU expects "bti j",
which is bad because the functions begin with "bti c"; switch to "br x16",
for the CPU to accept "bti c".

BTI helps defend against JOP/COP. Tested on Qemu.


Revision tags: phil-wifi-20200411 bouyer-xenpvh-base
# 1.69 08-Apr-2020 ryo

branches: 1.69.2;
use PMAP_PAGE_INIT() to initialize mutex in pmap_page.

VM_MDPAGE_INIT() in pmap_free_pdp() had initialized pp_flags,
so it unintentionally cleared PMAP_PAGE_FLAGS_PV_TRACKED.
use PMAP_PAGE_INIT to avoid using PMAP_PAGE_FLAGS_PV_TRACKED.

pointed out by tnn@, thanks


Revision tags: phil-wifi-20200406
# 1.68 14-Mar-2020 ad

pmap_remove_all(): Return a boolean value to indicate the behaviour. If
true, all mappings have been removed, the pmap is totally cleared out, and
UVM can then avoid doing the work to call pmap_remove() for each map entry.
If false, either nothing has been done, or some helpful arch-specific voodoo
has taken place.


Revision tags: is-mlppp-base
# 1.67 02-Mar-2020 ryo

oops, fix incorrect usage of daif_enable() in my previous commit.


# 1.66 29-Feb-2020 ryo

Fix pmap to work correctly with tagged addresses

- when fault, untag from address before passing to uvm/pmap functions
- pmap_extract() checks more strictly and consider the address tag


# 1.65 29-Feb-2020 ryo

use pmapboot_enter_range()


Revision tags: ad-namecache-base3
# 1.64 10-Feb-2020 ryo

use LIST(3) instead of TAILQ(3) to save one word in struct vm_page and struct pmap.

pointed out by riastradh@. thanks


# 1.63 03-Feb-2020 ryo

add support pmap_pv(9)

Patch originally from jmcneill@. thanks


# 1.62 03-Feb-2020 ryo

separate struct vm_page_md into vm_page_md and pmap_page
for preparation pmap_pv(9)


Revision tags: ad-namecache-base2 ad-namecache-base1
# 1.61 09-Jan-2020 ryo

fix behaviour mmap()/mprotect() when passed only PROT_EXEC.

when mmap()/mprotect() with only PROT_EXEC, syscall will be successful,
but the page actually hadn't been mapped.
it should be mapped with PROT_READ|PROT_EXEC implicitly. (r-x)


Revision tags: ad-namecache-base
# 1.60 30-Dec-2019 skrll

branches: 1.60.2;
Update pmap_map_chunk to allow L[12] block mappings and L3 page mappings


# 1.59 30-Dec-2019 skrll

Remove unnecessary brackets and unwrap a conditional. Same code before
and after.


# 1.58 28-Dec-2019 jmcneill

Do not use Early Write Acknowledge for PCIe I/O and config space.


# 1.57 27-Dec-2019 jmcneill

Enable early write acknowledge for device memory mappings.


# 1.56 19-Dec-2019 skrll

G/C kasan_shadow_map call in pmap_enter

pmap_growkernel calls kasan_shadow_map for KVA


# 1.55 18-Dec-2019 ryo

atomic_add_16() is not used in pmap.c anymore. no need decl here.


# 1.54 18-Dec-2019 ryo

space to tab


# 1.53 14-Dec-2019 skrll

Fix build... wire_count probably doesn't need atomics


# 1.52 13-Dec-2019 skrll

Fix KASAN support by calling kasan_shadow_map in pmap_growkernel


# 1.51 10-Dec-2019 ad

pg->phys_addr -> VM_PAGE_TO_PHYS(pg)


Revision tags: phil-wifi-20191119
# 1.50 14-Nov-2019 maxv

Mark several kASan functions with __nothing, to avoid annoying #ifdefs.
Same as kCSan and kMSan.


# 1.49 14-Nov-2019 maxv

Don't include "opt_kasan.h" when there's already <sys/asan.h> included.


# 1.48 29-Oct-2019 maya

Define PMAP_NEED_PROCWR, providing strategically placed i-cache
synchronization where just-changed memory is about to be executed.

Fixes SIGILLs seen when running Mono 6 on QEMU Cortex-A57.

ok ryo


# 1.47 22-Sep-2019 jmcneill

Disable translation table walks using TTBR0 while changing its value and
when deactivating a pmap. Fixes stability issues on Ampere eMAG CPUs.


# 1.46 20-Sep-2019 ryo

ref/mod bit should be set according to 'flags' argument, not 'prot'. r1.44 was incomplete.


# 1.45 13-Sep-2019 ryo

In pmap_devmap_bootstrap(), cpu_earlydevice_va_p() must not return true until *all* devmap tables have been enabled.
console mapping may be present in the last table.


# 1.44 07-Sep-2019 ryo

- remove incorrect KASSERT. mmap(2) with prot=PROT_WRITE calls pmap_enter(..., PROT_WRITE) internally.
- fix to update page reference flags when only PROT_WRITE or PROT_EXECUTE specified


# 1.43 15-Aug-2019 skrll

Make pmap_db_pte_print more terse so it's quicker on serial consoles


# 1.42 12-Aug-2019 skrll

Use PMAP_DEV in DEVMAP_ENTRY rather than pmap_map_chunk. It's clearer and
means pmap_map_chunk can be made to map other memory types.


Revision tags: netbsd-9-base phil-wifi-20190609
# 1.41 17-May-2019 mrg

branches: 1.41.2;
apply some __diagused.


Revision tags: isaki-audio2-base
# 1.40 08-Apr-2019 ryo

- free empty page tables pages if reach a certain usage.
- need to lock at removing an old pg (_pmap_remove_pv) in _pmap_enter()


# 1.39 06-Apr-2019 ryo

Fix race conditions about pmap_page_protect() and pmap_enter().

while handling same PTE by these functions in same time, there
is a critical path that the number of valid PTEs and wire_count
are inconsistent, and it caused KASSERT.
Need to hold a pv_lock while modifying them.


# 1.38 20-Mar-2019 ryo

spinkle __printflike(), and use PRIxxx


# 1.37 19-Mar-2019 ryo

- add ddb command "machine ttbr" to dump MMU tables.
- tidy up descriptions, usages and messages.


# 1.36 19-Mar-2019 ryo

- free L1-L3 pages that has been emptied by pmap_remove().
- if no memories, pmap_enter will return correctly ENOMEM if PMAP_CANFAIL, or wait until available any memories if !PMAP_CANFAIL.

These changes improves the stability when we use a huge virtual memory spaces with mmap.


# 1.35 06-Feb-2019 ryo

improve pmap_remove
- don't lock/unlock per page in pmap_remove()
- speedup pte lookup for continuous addresses
- bring out pool_cache_put(&_pmap_pv_pool, pv) from lock/unlock section


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226
# 1.34 21-Dec-2018 ryo

- add workaround for Cavium ThunderX errata 27456.
- add cpufuncs table in cpu_info. each cpu clusters may have different erratum. (e.g. big.LITTLE)


Revision tags: pgoyette-compat-1126
# 1.33 01-Nov-2018 maxv

Add kASan support for aarch64. Stack tracking needs more investigation
and will come in a separate commit.

Reviewed by ryo@ jmcneill@ skrll@.


# 1.32 31-Oct-2018 ryo

invalidate icache correctly.
l3pte_executable() should be used for only valid pte.


Revision tags: pgoyette-compat-1020
# 1.31 18-Oct-2018 skrll

Provide generic start code that assumes the MMU is off and caches are
disabled as per the linux booting protocol for ARMv6 and ARMv7 boards.
u-boot image type should be changed to 'linux' for correct behaviour.

The new start code builds a minimal "bootstrap" L1PT with cached access
disabled and uses the same table for all processors. AP startup is
performed in less steps and more code is written in C.

The bootstrap tables and stack are placed into an (orphaned) section
"_init_memory" which is given to uvm when it is no longer used.

Various kernels have been converted to use this code and tested. Some
boards were provided by TNF. Thanks!

The GENERIC kernel now boots on boards using the TEGRA, SUNXI and EXYNOS
kernels. The GENERIC kernel will also work on RPI2 using u-boot.

Thanks to martin@ and aymeric@ for testing on parallella and nanosoc
respectively


# 1.30 14-Oct-2018 skrll

Use __nothing


# 1.29 12-Oct-2018 ryo

add initial support of COMPAT_NETBSD32 on AArch64.
arm ELF32 EABI binaries could be execute in AArch32 state on AArch64. A32 THUMB mode is not supported yet.


# 1.28 12-Oct-2018 ryo

- cleanup checking address ranges with IN_RANGE macro
- change PM_ADDR_CHECK macro to KASSERTMSG
- restore fast lookup cases with IN_RANGE macro for pmap_extract changed in my previous commit.


# 1.27 12-Oct-2018 ryo

rewrite pmap_pte_lookup() to share similar code.


# 1.26 04-Oct-2018 ryo

cleanup locore, and changed the way to map memories during boot.
- add functions bootpage_enter() and bootpage_alloc() to adapt various layout
of physical memory map. especially for 64bit physical memory layout.
pmapboot_alloc() allocates pagetable pages from _end[].
- changed to map only the required amount for PA=VA identity mapping
(kernel image, UART device, and FDT blob) with L2_BLOCK(2Mbyte).
- changing page permission for kernel image, and making KSEG mapping are done
at cpu_kernel_vm_init() instead of at locore.
- optimize PTE entries with PTE Contiguous bit. it is enabled on devmap only for now.

reviewed by skrll@, thanks.


# 1.25 04-Oct-2018 ryo

* define LX_BLKPAG_{OS,ATTR}_* for OS dependent PTE attributes in pmap.h
* cleanup macros


Revision tags: pgoyette-compat-0930
# 1.24 17-Sep-2018 ryo

delete debug printf and KASSERT.


# 1.23 10-Sep-2018 maxv

Replace KDASSERT by panic.


# 1.22 10-Sep-2018 maxv

Rename _pmap_alloc_pdp -> pmap_alloc_pdp, and make it public.


# 1.21 10-Sep-2018 ryo

cleanup aarch64 mpstart and fdt bootstrap
* arm_cpu_hatch_arg is a bad idea. avoid serializing CPU startup, and eliminate arm_cpu_hatch_arg.
in mpstart, resolve own cpu index using array of cpu_mpidr[] (aarch64)
* add support fdt enable-method "spin-table"
* add support fdt enable-method "brcm,bcm2836-smp" (for 32bit RaspberryPi)
* use arm_fdt_cpu_bootstrap() instead of psci_fdt_bootstrap()
* rename "arm/fdt/psci_fdt.h" to "arm/fdt/psci_fdtvar.h" because of conflict of include file for needs-flag
* add devmap for cpu spin-table of raspberrypi3/aarch64
* no need to force hatch APs for raspberrypi3/arm32 ifndef MULTIPROCESSOR.
* fix to work pmap_extract(kerneltext/data/bss) even if before calling pmap_bootstrap

idea to use cpu_mpidr[] by jmcneill@. reviewd by skrll@. thanks.


Revision tags: pgoyette-compat-0906
# 1.20 27-Aug-2018 ryo

need to add VM_PROT_READ when pmap_kenter_pa(va, pa, VM_PROT_WRITE, 0) or pmap_kenter_pa(va, pa, VM_PROT_EXECUTE, 0).
VM_PROT_READ is treated as an access permission inernally.


# 1.19 11-Aug-2018 ryo

change to minimum invalidation of TLB.
specifying not only va but also asid, and not invalidate L0-L2 entry using tlbi_*_ll() if needed.


# 1.18 10-Aug-2018 ryo

treat kernel-exec attr and user-exec attr separately.
kernel cannot execute userland exec page, and user cannot execute kernel page.


# 1.17 06-Aug-2018 ryo

set kernel text/rodata readonly by default.
add function db_write_text() for setting ddb breakpoint.


# 1.16 31-Jul-2018 skrll

Define and use VPRINTF


Revision tags: pgoyette-compat-0728
# 1.15 27-Jul-2018 ryo

changes of pmap.c r1.13 seems to be unstable.
In order to invalidate icache, not to invalidate all icache,
but temporary to make the page writable and invalidate target address only.


# 1.14 24-Jul-2018 ryo

don't call pool_cache_put with locking pmap. pool_cache_put call pmap_kenter_pa internally.
(pool_cache_put_paddr -> pool_cache_put_slow -> pool_get -> pmap_kenter_pa)


# 1.13 23-Jul-2018 ryo

* fix icache invalidations.
* "ic ivau" (aarch64_icache_sync_range) with VA generates permission fault in some situations, therefore use KSEG address for now.


# 1.12 23-Jul-2018 ryo

rather than using flags to resolve nested locks, reserve pool_cache before locking.


# 1.11 21-Jul-2018 ryo

* avoid deadlock. mutex_owned() works only for adaptive lock, therefore we cannot use it for spinlock...
* add more NULL check
* clear pte when pmap_enter() fails


# 1.10 17-Jul-2018 ryo

Use __debugused


# 1.9 17-Jul-2018 christos

Add missing casts, remove unused variables.


# 1.8 09-Jul-2018 ryo

need locks in pmap_kremove() and pmap_fault_fixup()


Revision tags: phil-wifi-base pgoyette-compat-0625 pgoyette-compat-0521
# 1.7 20-May-2018 ryo

branches: 1.7.2;
pmap_enter() must update modified/referenced flags by 'flags' not 'prot'.


# 1.6 16-May-2018 ryo

Fix memory leak. it was leaking one page every pmap_create().
pm->pm_vmlist must be initialized before calling _pmap_alloc_pdp().


Revision tags: pgoyette-compat-0502
# 1.5 29-Apr-2018 ryo

fix KASSERT panic. pv_entry may not be exists in pvlist when pmap_remove().


# 1.4 29-Apr-2018 ryo

delete unused code


# 1.3 27-Apr-2018 ryo

fix instability behavior of bufcache on aarch64.
* fix to return correct ref/mod when PMAP_WIRED.
* changed to keep wired flags in pte instead of pv_entry, and cleanup.


Revision tags: pgoyette-compat-0422 pgoyette-compat-0415 pgoyette-compat-0407
# 1.2 01-Apr-2018 ryo

Add initial support for ARMv8 (AARCH64) (by nisimura@ and ryo@)

- sys/arch/evbarm64 is gone and integrated into sys/arch/evbarm. (by skrll@)
- add support fdt. evbarm/conf/GENERIC64 fdt (bcm2837,sunxi,tegra) based generic 64bit kernel config. (by skrll@, jmcneill@)


Revision tags: netbsd-8-2-RELEASE netbsd-8-1-RELEASE netbsd-8-1-RC1 netbsd-7-2-RELEASE netbsd-8-0-RELEASE netbsd-8-0-RC2 netbsd-8-0-RC1 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 netbsd-7-1-2-RELEASE pgoyette-compat-base netbsd-7-1-1-RELEASE tls-maxphys-base-20171202 matt-nb8-mediatek-base nick-nhusb-base-20170825 perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base pgoyette-localcount-20170320 netbsd-7-1-RELEASE netbsd-7-1-RC2 nick-nhusb-base-20170204 netbsd-7-nhusb-base-20170116 bouyer-socketcan-base pgoyette-localcount-20170107 netbsd-7-1-RC1 nick-nhusb-base-20161204 pgoyette-localcount-20161104 netbsd-7-0-2-RELEASE nick-nhusb-base-20161004 localcount-20160914 netbsd-7-nhusb-base pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907 nick-nhusb-base-20160529 netbsd-7-0-1-RELEASE nick-nhusb-base-20160422 nick-nhusb-base-20160319 nick-nhusb-base-20151226 netbsd-7-0-RELEASE nick-nhusb-base-20150921 netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 nick-nhusb-base-20150606 nick-nhusb-base-20150406 nick-nhusb-base tls-maxphys-base netbsd-7-base
# 1.1 10-Aug-2014 matt

branches: 1.1.4; 1.1.28;
Preliminary files for AARCH64 (64-bit ARM) support.
Enough for a distribution build.


# 1.121 10-Dec-2021 andvar

s/occured/occurred/ in comments, log messages and man pages.


# 1.120 07-Dec-2021 andvar

fix various typos, mainly in comments.


# 1.119 23-Oct-2021 skrll

Fix non-UVMHIST build


# 1.118 16-Oct-2021 ryo

fix non-MULTIPROCESSOR build


# 1.117 10-Oct-2021 skrll

Use sys/uvm/pmap/pmap_tlb.c on Aarch64 in the same way that some Arm, MIPS,
and some PPC kernels do. This removes the limitation of 256 processes on
CPUs with 8bit ASID field, e.g. Apple M1.

Additionally the following changes have been made

- removed a couple of unnecessary aarch64_tlbi_all calls
- removed any invalidation after freeing page tables due to
_pmap_sweep_pdp. This was never necessary afaict.
- all kernel mappings are marked global and userland mapping not-global.

Performance testing hasn't show a significant difference. The data here
is from building a kernel on an lx2k system with nvme.

before
1489.6u 400.4s 2:40.65 1176.5% 228+224k 0+32289io 57pf+0w
1482.6u 403.2s 2:38.49 1189.9% 228+222k 0+32274io 46pf+0w
1485.4u 402.2s 2:37.27 1200.2% 228+222k 0+32275io 12pf+0w

after
1493.9u 404.6s 2:37.50 1205.4% 227+221k 0+32265io 48pf+0w
1485.0u 408.0s 2:38.54 1194.0% 227+222k 0+32272io 36pf+0w
1484.3u 407.0s 2:35.88 1213.3% 228+224k 0+32268io 14pf+0w

>>> stats.ttest_ind([160.65,158.49,157.27], [157.5,158.54,155.88])
Ttest_indResult(statistic=1.1923622711296888, pvalue=0.2990182944606766)
>>>


# 1.116 30-Sep-2021 skrll

Ensure TCR_EPD0 is set on entry to pmap_activate and ensure it is set as
early as possible for APs.


# 1.115 26-Sep-2021 skrll

Use UVMHIST_CALLARGS


# 1.114 26-Sep-2021 skrll

'\n' is not required in KASSERTMSG either.


# 1.113 26-Sep-2021 skrll

"\n" is not required in KERNHIST


# 1.112 15-Sep-2021 skrll

Use __SHIFTIN. Same code before and after.


# 1.111 12-Sep-2021 skrll

pmap_page_remove: simply and reduce the code size slightly.


# 1.110 09-Sep-2021 skrll

In pmap_icache_sync_range change

for (...) {
...
if (condition) {
// do stuff
}
}

to

for (...) {
...
if (!conditional)
continue;
// do stuff
}

to save on indentation. Same code (modulo register usage) before and
after.


# 1.109 09-Sep-2021 skrll

KNF


Revision tags: thorpej-i2c-spi-conf2-base thorpej-futex2-base thorpej-cfargs2-base cjep_sun2x-base1 cjep_sun2x-base cjep_staticlib_x-base1 thorpej-i2c-spi-conf-base
# 1.108 29-May-2021 skrll

Deal with the pmap limitation of maxproc in a more complete way and
recognise CPUs with only 8bit ASIDs.


Revision tags: cjep_staticlib_x-base
# 1.107 30-Apr-2021 skrll

branches: 1.107.2;
Make the ddb for pmap / pte information pmap agnostic


# 1.106 29-Apr-2021 skrll

Remove some unnecessary tlb invalidate in pmap_growkernel and ASAN shadow
map. Ensure the shadow map mappings are visible to the TLB walkers.


# 1.105 21-Apr-2021 ryo

branches: 1.105.2;
added more attributes of PTE displayed by "ddb>machine pte"


Revision tags: thorpej-cfargs-base
# 1.104 17-Apr-2021 mrg

remove KERNHIST_INIT_STATIC(). it stradles the line between usable
early in boot and broken early in boot by requiring a partly static
structure with another structure that must be present by the time
any uses are performed. theoretically platform code could allocate
a chunk while seting up memory and assign it here, giving a dynamic
sizing for the entry list, but the reality is that all users have
a statically allocated entry list as well.

the existing KERNHIST_LINK_STATIC() is used in conjunction with
KERNHIST_INITIALIZER() instead.

this stops a NULL pointer deref when the _LOG() macro is called
before the storage is linked in, which happens with GCC 10 on OCTEON
with UVMHIST enabled, crashing in very early kernel init.


Revision tags: thorpej-futex-base
# 1.103 09-Mar-2021 ryo

branches: 1.103.2;
fix build error without options DDB.

kvtopte() is referenced from arm/acpi/acpi_machdep.c


# 1.102 13-Feb-2021 ryo

No assignment is needed here.

the loop in pmap_page_remove() always removes the first pv,
and since the list is managed by _pmap_remove_pv(), pp->pp_pv.pv_next always points to the first.


# 1.101 01-Feb-2021 ryo

It is enough to make a page accessible instead of writable.
same fix as r1.76


# 1.100 31-Jan-2021 ryo

implement pmap_remove_all().

The size of struct pv_entry has increased, but speed of kernel build has improved by about 1%
exec and exit should have been improved.


# 1.99 20-Dec-2020 skrll

Improve the English in the previous comment fix.


# 1.98 19-Dec-2020 skrll

Tweak a comment


# 1.97 11-Dec-2020 skrll

s:aarch64/cpufunc.h:arm/cpufunc.h:

a baby step in the grand arm header unification challenge


# 1.96 10-Nov-2020 skrll

AA64 is not MIPS.

Change all KSEG references to directmap


# 1.95 07-Nov-2020 skrll

In pmap_devmap_bootstrap only set pmap_devmap_bootstrap_done if there
is an entry and ALL of the entries have been done. The entry required
for EARLYCONS might not be the first/only one...


# 1.94 01-Nov-2020 jmcneill

branches: 1.94.2;
No need to disable translation table walks in pmap_activate().


# 1.93 22-Oct-2020 skrll

Use the isb macro - missed in previous commit


# 1.92 22-Oct-2020 skrll

Use the dmb/dsb/isb macros... if nothing else they're all now consistent
about the "memory" assembler contraint.

No binary change


# 1.91 28-Sep-2020 skrll

Only set pmap_devmap_bootstrap_done if something gets mapped.

Think acpi_platform_devmap


# 1.90 19-Sep-2020 skrll

Make __md_palloc pmap agnostic (think sys/uvm/pmap)


# 1.89 14-Sep-2020 ryo

PID_MAX is just an initial value (soft maximum). Don't use it for CTASSERT.
defined __HAVE_CPU_MAXPROC to use function cpu_maxproc().

pointed out by mrg@, thanks.


# 1.88 06-Sep-2020 ryo

Fix panic caused by modload. http://mail-index.netbsd.org/port-arm/2020/08/30/msg006960.html

The address space reserved for modules may not be mapped in L1-L3.


# 1.87 14-Aug-2020 skrll

Whitespace


# 1.86 12-Aug-2020 skrll

Part IV of ad's performance improvements for aarch64

- Implement pmap_growkernel(), and update kernel pmap's stats with atomics.

- Then, pmap_kenter_pa() and pmap_kremove() no longer need to allocate
memory nor take pm_lock, because they only modify L3 PTEs.

- Then, pm_lock and pp_lock can be adaptive mutexes at IPL_NONE which are
cheaper than spin mutexes.

- Take the pmap's lock in pmap_extract() if not the kernel's pmap, otherwise
pmap_extract() might see inconsistent state.


# 1.85 09-Aug-2020 skrll

Fix another UVMHIST so it doesn't use %s


# 1.84 16-Jul-2020 skrll

pmapboot_enter simplication
- bootpage_alloc in asm becomes pmapboot_pagealloc in C
- PMAPBOOT_ENTER_NOBLOCK is removed as it's not used
- PMAPBOOT_ENTER_NOOVERWRITE is removed as it's now always on
- physpage_allocator argument is removed as it's always
pmapboot_pagealloc
- Support for EARLYCONS without CONSADDR is removed so that the identity
map for CONSADDR is always known.

For the assembly files:
2 files changed, 40 insertions(+), 89 deletions(-)

LGTM ryo


# 1.83 04-Jul-2020 rin

Use tlen for temporary length variable instead of l, which is usually
used for struct lwp *.

No binary changes.


# 1.82 02-Jul-2020 rin

pmap_procwr(): sync icache even if p != curproc. This fixes applications
like GDB for arm32, that rewrite text of other process.

Thanks to ryo@ for discussion.


# 1.81 02-Jul-2020 rin

Set uvmexp.ncolors appropriately, which is required for some CPU
models with VIPT icache.

Otherwise, alias in virtual address results in inconsistent results,
at least for applications that rewrite text of other process, e.g.,
GDB for arm32.

Also, this hopefully fixes other unexpected failures due to alias.

Confirmed that there's no observable regression in performance;
difference in ``time make -j8'' for GENERIC64 kernel on BCM2837
with and without setting uvmexp.ncolors is within 0.1%.

Thanks to ryo@ for discussion.


# 1.80 27-Jun-2020 rin

Fix typo in name of evcnt(4) counter.


# 1.79 24-Jun-2020 ryo

Fix bug with incorrect range calculation when doing icache sync.
This is called by sysarch(ARM_SYNC_ICACHE) from aarch32 (compat_netbsd32) emul process.

pointed out by rin@, thanks.

XXX pullup-9


# 1.78 14-Jun-2020 ad

- Fix a lock order reversal in pmap_page_protect().

- Make sure pmap is always locked when updating stats; atomics no longer
needed to do that.

- Remove unneeded traversal of pv list in pmap_enter_pv().

- Shrink struct vm_page from 136 to 128 bytes (cache line sized) and struct
pv_entry from 48 to 32 bytes (power of 2 sized).

- Embed a pv_entry in each vm_page. This means PV entries don't need to
be allocated for private anonymous memory / COW pages / most UBC mappings.
Dynamic PV entries are then used only for stuff like shared libraries and
shared memory.

Proposed on port-arm@.


# 1.77 10-Jun-2020 ad

- Wired/resident stats shouldn't covered by PMAPCOUNTERS.
- Rename need_update_pv -> need_enter_pv.

Ok ryo@


# 1.76 01-Jun-2020 ryo

no need to make the PTE writable to do icache_sync, enough to accessible.


# 1.75 15-May-2020 skrll

Use __diagused


# 1.74 15-May-2020 tnn

fix non-diag build


# 1.73 14-May-2020 skrll

Use MUTEX_NODEBUG for PV locks as is commonly done. OK ryo.


# 1.72 13-May-2020 jmcneill

Implement pmap_extract_coherency


Revision tags: bouyer-xenpvh-base2 phil-wifi-20200421 bouyer-xenpvh-base1
# 1.71 18-Apr-2020 skrll

PMAP_DEBUG has been deleted on arm


# 1.70 13-Apr-2020 maxv

Add support for Branch Target Identification (BTI).

On the executable pages that have the GP (Guarded Page) bit, the semantic
of the "br" and "blr" instructions is changed: the CPU expects the first
instruction of the jump/call target to be "bti", and faults if it isn't.

We add the GP bit on the kernel .text pages (and incidentally the .rodata
pages, but we don't care). The compiler adds a "bti c" instruction at the
beginning of each C function. We modify the ENTRY() macros to manually add
"bti c" in the asm functions.

cpuswitch.S needs a specific change: with "br x27" the CPU expects "bti j",
which is bad because the functions begin with "bti c"; switch to "br x16",
for the CPU to accept "bti c".

BTI helps defend against JOP/COP. Tested on Qemu.


Revision tags: phil-wifi-20200411 bouyer-xenpvh-base
# 1.69 08-Apr-2020 ryo

branches: 1.69.2;
use PMAP_PAGE_INIT() to initialize mutex in pmap_page.

VM_MDPAGE_INIT() in pmap_free_pdp() had initialized pp_flags,
so it unintentionally cleared PMAP_PAGE_FLAGS_PV_TRACKED.
use PMAP_PAGE_INIT to avoid using PMAP_PAGE_FLAGS_PV_TRACKED.

pointed out by tnn@, thanks


Revision tags: phil-wifi-20200406
# 1.68 14-Mar-2020 ad

pmap_remove_all(): Return a boolean value to indicate the behaviour. If
true, all mappings have been removed, the pmap is totally cleared out, and
UVM can then avoid doing the work to call pmap_remove() for each map entry.
If false, either nothing has been done, or some helpful arch-specific voodoo
has taken place.


Revision tags: is-mlppp-base
# 1.67 02-Mar-2020 ryo

oops, fix incorrect usage of daif_enable() in my previous commit.


# 1.66 29-Feb-2020 ryo

Fix pmap to work correctly with tagged addresses

- when fault, untag from address before passing to uvm/pmap functions
- pmap_extract() checks more strictly and consider the address tag


# 1.65 29-Feb-2020 ryo

use pmapboot_enter_range()


Revision tags: ad-namecache-base3
# 1.64 10-Feb-2020 ryo

use LIST(3) instead of TAILQ(3) to save one word in struct vm_page and struct pmap.

pointed out by riastradh@. thanks


# 1.63 03-Feb-2020 ryo

add support pmap_pv(9)

Patch originally from jmcneill@. thanks


# 1.62 03-Feb-2020 ryo

separate struct vm_page_md into vm_page_md and pmap_page
for preparation pmap_pv(9)


Revision tags: ad-namecache-base2 ad-namecache-base1
# 1.61 09-Jan-2020 ryo

fix behaviour mmap()/mprotect() when passed only PROT_EXEC.

when mmap()/mprotect() with only PROT_EXEC, syscall will be successful,
but the page actually hadn't been mapped.
it should be mapped with PROT_READ|PROT_EXEC implicitly. (r-x)


Revision tags: ad-namecache-base
# 1.60 30-Dec-2019 skrll

branches: 1.60.2;
Update pmap_map_chunk to allow L[12] block mappings and L3 page mappings


# 1.59 30-Dec-2019 skrll

Remove unnecessary brackets and unwrap a conditional. Same code before
and after.


# 1.58 28-Dec-2019 jmcneill

Do not use Early Write Acknowledge for PCIe I/O and config space.


# 1.57 27-Dec-2019 jmcneill

Enable early write acknowledge for device memory mappings.


# 1.56 19-Dec-2019 skrll

G/C kasan_shadow_map call in pmap_enter

pmap_growkernel calls kasan_shadow_map for KVA


# 1.55 18-Dec-2019 ryo

atomic_add_16() is not used in pmap.c anymore. no need decl here.


# 1.54 18-Dec-2019 ryo

space to tab


# 1.53 14-Dec-2019 skrll

Fix build... wire_count probably doesn't need atomics


# 1.52 13-Dec-2019 skrll

Fix KASAN support by calling kasan_shadow_map in pmap_growkernel


# 1.51 10-Dec-2019 ad

pg->phys_addr -> VM_PAGE_TO_PHYS(pg)


Revision tags: phil-wifi-20191119
# 1.50 14-Nov-2019 maxv

Mark several kASan functions with __nothing, to avoid annoying #ifdefs.
Same as kCSan and kMSan.


# 1.49 14-Nov-2019 maxv

Don't include "opt_kasan.h" when there's already <sys/asan.h> included.


# 1.48 29-Oct-2019 maya

Define PMAP_NEED_PROCWR, providing strategically placed i-cache
synchronization where just-changed memory is about to be executed.

Fixes SIGILLs seen when running Mono 6 on QEMU Cortex-A57.

ok ryo


# 1.47 22-Sep-2019 jmcneill

Disable translation table walks using TTBR0 while changing its value and
when deactivating a pmap. Fixes stability issues on Ampere eMAG CPUs.


# 1.46 20-Sep-2019 ryo

ref/mod bit should be set according to 'flags' argument, not 'prot'. r1.44 was incomplete.


# 1.45 13-Sep-2019 ryo

In pmap_devmap_bootstrap(), cpu_earlydevice_va_p() must not return true until *all* devmap tables have been enabled.
console mapping may be present in the last table.


# 1.44 07-Sep-2019 ryo

- remove incorrect KASSERT. mmap(2) with prot=PROT_WRITE calls pmap_enter(..., PROT_WRITE) internally.
- fix to update page reference flags when only PROT_WRITE or PROT_EXECUTE specified


# 1.43 15-Aug-2019 skrll

Make pmap_db_pte_print more terse so it's quicker on serial consoles


# 1.42 12-Aug-2019 skrll

Use PMAP_DEV in DEVMAP_ENTRY rather than pmap_map_chunk. It's clearer and
means pmap_map_chunk can be made to map other memory types.


Revision tags: netbsd-9-base phil-wifi-20190609
# 1.41 17-May-2019 mrg

branches: 1.41.2;
apply some __diagused.


Revision tags: isaki-audio2-base
# 1.40 08-Apr-2019 ryo

- free empty page tables pages if reach a certain usage.
- need to lock at removing an old pg (_pmap_remove_pv) in _pmap_enter()


# 1.39 06-Apr-2019 ryo

Fix race conditions about pmap_page_protect() and pmap_enter().

while handling same PTE by these functions in same time, there
is a critical path that the number of valid PTEs and wire_count
are inconsistent, and it caused KASSERT.
Need to hold a pv_lock while modifying them.


# 1.38 20-Mar-2019 ryo

spinkle __printflike(), and use PRIxxx


# 1.37 19-Mar-2019 ryo

- add ddb command "machine ttbr" to dump MMU tables.
- tidy up descriptions, usages and messages.


# 1.36 19-Mar-2019 ryo

- free L1-L3 pages that has been emptied by pmap_remove().
- if no memories, pmap_enter will return correctly ENOMEM if PMAP_CANFAIL, or wait until available any memories if !PMAP_CANFAIL.

These changes improves the stability when we use a huge virtual memory spaces with mmap.


# 1.35 06-Feb-2019 ryo

improve pmap_remove
- don't lock/unlock per page in pmap_remove()
- speedup pte lookup for continuous addresses
- bring out pool_cache_put(&_pmap_pv_pool, pv) from lock/unlock section


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226
# 1.34 21-Dec-2018 ryo

- add workaround for Cavium ThunderX errata 27456.
- add cpufuncs table in cpu_info. each cpu clusters may have different erratum. (e.g. big.LITTLE)


Revision tags: pgoyette-compat-1126
# 1.33 01-Nov-2018 maxv

Add kASan support for aarch64. Stack tracking needs more investigation
and will come in a separate commit.

Reviewed by ryo@ jmcneill@ skrll@.


# 1.32 31-Oct-2018 ryo

invalidate icache correctly.
l3pte_executable() should be used for only valid pte.


Revision tags: pgoyette-compat-1020
# 1.31 18-Oct-2018 skrll

Provide generic start code that assumes the MMU is off and caches are
disabled as per the linux booting protocol for ARMv6 and ARMv7 boards.
u-boot image type should be changed to 'linux' for correct behaviour.

The new start code builds a minimal "bootstrap" L1PT with cached access
disabled and uses the same table for all processors. AP startup is
performed in less steps and more code is written in C.

The bootstrap tables and stack are placed into an (orphaned) section
"_init_memory" which is given to uvm when it is no longer used.

Various kernels have been converted to use this code and tested. Some
boards were provided by TNF. Thanks!

The GENERIC kernel now boots on boards using the TEGRA, SUNXI and EXYNOS
kernels. The GENERIC kernel will also work on RPI2 using u-boot.

Thanks to martin@ and aymeric@ for testing on parallella and nanosoc
respectively


# 1.30 14-Oct-2018 skrll

Use __nothing


# 1.29 12-Oct-2018 ryo

add initial support of COMPAT_NETBSD32 on AArch64.
arm ELF32 EABI binaries could be execute in AArch32 state on AArch64. A32 THUMB mode is not supported yet.


# 1.28 12-Oct-2018 ryo

- cleanup checking address ranges with IN_RANGE macro
- change PM_ADDR_CHECK macro to KASSERTMSG
- restore fast lookup cases with IN_RANGE macro for pmap_extract changed in my previous commit.


# 1.27 12-Oct-2018 ryo

rewrite pmap_pte_lookup() to share similar code.


# 1.26 04-Oct-2018 ryo

cleanup locore, and changed the way to map memories during boot.
- add functions bootpage_enter() and bootpage_alloc() to adapt various layout
of physical memory map. especially for 64bit physical memory layout.
pmapboot_alloc() allocates pagetable pages from _end[].
- changed to map only the required amount for PA=VA identity mapping
(kernel image, UART device, and FDT blob) with L2_BLOCK(2Mbyte).
- changing page permission for kernel image, and making KSEG mapping are done
at cpu_kernel_vm_init() instead of at locore.
- optimize PTE entries with PTE Contiguous bit. it is enabled on devmap only for now.

reviewed by skrll@, thanks.


# 1.25 04-Oct-2018 ryo

* define LX_BLKPAG_{OS,ATTR}_* for OS dependent PTE attributes in pmap.h
* cleanup macros


Revision tags: pgoyette-compat-0930
# 1.24 17-Sep-2018 ryo

delete debug printf and KASSERT.


# 1.23 10-Sep-2018 maxv

Replace KDASSERT by panic.


# 1.22 10-Sep-2018 maxv

Rename _pmap_alloc_pdp -> pmap_alloc_pdp, and make it public.


# 1.21 10-Sep-2018 ryo

cleanup aarch64 mpstart and fdt bootstrap
* arm_cpu_hatch_arg is a bad idea. avoid serializing CPU startup, and eliminate arm_cpu_hatch_arg.
in mpstart, resolve own cpu index using array of cpu_mpidr[] (aarch64)
* add support fdt enable-method "spin-table"
* add support fdt enable-method "brcm,bcm2836-smp" (for 32bit RaspberryPi)
* use arm_fdt_cpu_bootstrap() instead of psci_fdt_bootstrap()
* rename "arm/fdt/psci_fdt.h" to "arm/fdt/psci_fdtvar.h" because of conflict of include file for needs-flag
* add devmap for cpu spin-table of raspberrypi3/aarch64
* no need to force hatch APs for raspberrypi3/arm32 ifndef MULTIPROCESSOR.
* fix to work pmap_extract(kerneltext/data/bss) even if before calling pmap_bootstrap

idea to use cpu_mpidr[] by jmcneill@. reviewd by skrll@. thanks.


Revision tags: pgoyette-compat-0906
# 1.20 27-Aug-2018 ryo

need to add VM_PROT_READ when pmap_kenter_pa(va, pa, VM_PROT_WRITE, 0) or pmap_kenter_pa(va, pa, VM_PROT_EXECUTE, 0).
VM_PROT_READ is treated as an access permission inernally.


# 1.19 11-Aug-2018 ryo

change to minimum invalidation of TLB.
specifying not only va but also asid, and not invalidate L0-L2 entry using tlbi_*_ll() if needed.


# 1.18 10-Aug-2018 ryo

treat kernel-exec attr and user-exec attr separately.
kernel cannot execute userland exec page, and user cannot execute kernel page.


# 1.17 06-Aug-2018 ryo

set kernel text/rodata readonly by default.
add function db_write_text() for setting ddb breakpoint.


# 1.16 31-Jul-2018 skrll

Define and use VPRINTF


Revision tags: pgoyette-compat-0728
# 1.15 27-Jul-2018 ryo

changes of pmap.c r1.13 seems to be unstable.
In order to invalidate icache, not to invalidate all icache,
but temporary to make the page writable and invalidate target address only.


# 1.14 24-Jul-2018 ryo

don't call pool_cache_put with locking pmap. pool_cache_put call pmap_kenter_pa internally.
(pool_cache_put_paddr -> pool_cache_put_slow -> pool_get -> pmap_kenter_pa)


# 1.13 23-Jul-2018 ryo

* fix icache invalidations.
* "ic ivau" (aarch64_icache_sync_range) with VA generates permission fault in some situations, therefore use KSEG address for now.


# 1.12 23-Jul-2018 ryo

rather than using flags to resolve nested locks, reserve pool_cache before locking.


# 1.11 21-Jul-2018 ryo

* avoid deadlock. mutex_owned() works only for adaptive lock, therefore we cannot use it for spinlock...
* add more NULL check
* clear pte when pmap_enter() fails


# 1.10 17-Jul-2018 ryo

Use __debugused


# 1.9 17-Jul-2018 christos

Add missing casts, remove unused variables.


# 1.8 09-Jul-2018 ryo

need locks in pmap_kremove() and pmap_fault_fixup()


Revision tags: phil-wifi-base pgoyette-compat-0625 pgoyette-compat-0521
# 1.7 20-May-2018 ryo

branches: 1.7.2;
pmap_enter() must update modified/referenced flags by 'flags' not 'prot'.


# 1.6 16-May-2018 ryo

Fix memory leak. it was leaking one page every pmap_create().
pm->pm_vmlist must be initialized before calling _pmap_alloc_pdp().


Revision tags: pgoyette-compat-0502
# 1.5 29-Apr-2018 ryo

fix KASSERT panic. pv_entry may not be exists in pvlist when pmap_remove().


# 1.4 29-Apr-2018 ryo

delete unused code


# 1.3 27-Apr-2018 ryo

fix instability behavior of bufcache on aarch64.
* fix to return correct ref/mod when PMAP_WIRED.
* changed to keep wired flags in pte instead of pv_entry, and cleanup.


Revision tags: pgoyette-compat-0422 pgoyette-compat-0415 pgoyette-compat-0407
# 1.2 01-Apr-2018 ryo

Add initial support for ARMv8 (AARCH64) (by nisimura@ and ryo@)

- sys/arch/evbarm64 is gone and integrated into sys/arch/evbarm. (by skrll@)
- add support fdt. evbarm/conf/GENERIC64 fdt (bcm2837,sunxi,tegra) based generic 64bit kernel config. (by skrll@, jmcneill@)


Revision tags: netbsd-8-2-RELEASE netbsd-8-1-RELEASE netbsd-8-1-RC1 netbsd-7-2-RELEASE netbsd-8-0-RELEASE netbsd-8-0-RC2 netbsd-8-0-RC1 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 netbsd-7-1-2-RELEASE pgoyette-compat-base netbsd-7-1-1-RELEASE tls-maxphys-base-20171202 matt-nb8-mediatek-base nick-nhusb-base-20170825 perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base pgoyette-localcount-20170320 netbsd-7-1-RELEASE netbsd-7-1-RC2 nick-nhusb-base-20170204 netbsd-7-nhusb-base-20170116 bouyer-socketcan-base pgoyette-localcount-20170107 netbsd-7-1-RC1 nick-nhusb-base-20161204 pgoyette-localcount-20161104 netbsd-7-0-2-RELEASE nick-nhusb-base-20161004 localcount-20160914 netbsd-7-nhusb-base pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907 nick-nhusb-base-20160529 netbsd-7-0-1-RELEASE nick-nhusb-base-20160422 nick-nhusb-base-20160319 nick-nhusb-base-20151226 netbsd-7-0-RELEASE nick-nhusb-base-20150921 netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 nick-nhusb-base-20150606 nick-nhusb-base-20150406 nick-nhusb-base tls-maxphys-base netbsd-7-base
# 1.1 10-Aug-2014 matt

branches: 1.1.4; 1.1.28;
Preliminary files for AARCH64 (64-bit ARM) support.
Enough for a distribution build.


# 1.120 07-Dec-2021 andvar

fix various typos, mainly in comments.


# 1.119 23-Oct-2021 skrll

Fix non-UVMHIST build


# 1.118 16-Oct-2021 ryo

fix non-MULTIPROCESSOR build


# 1.117 10-Oct-2021 skrll

Use sys/uvm/pmap/pmap_tlb.c on Aarch64 in the same way that some Arm, MIPS,
and some PPC kernels do. This removes the limitation of 256 processes on
CPUs with 8bit ASID field, e.g. Apple M1.

Additionally the following changes have been made

- removed a couple of unnecessary aarch64_tlbi_all calls
- removed any invalidation after freeing page tables due to
_pmap_sweep_pdp. This was never necessary afaict.
- all kernel mappings are marked global and userland mapping not-global.

Performance testing hasn't show a significant difference. The data here
is from building a kernel on an lx2k system with nvme.

before
1489.6u 400.4s 2:40.65 1176.5% 228+224k 0+32289io 57pf+0w
1482.6u 403.2s 2:38.49 1189.9% 228+222k 0+32274io 46pf+0w
1485.4u 402.2s 2:37.27 1200.2% 228+222k 0+32275io 12pf+0w

after
1493.9u 404.6s 2:37.50 1205.4% 227+221k 0+32265io 48pf+0w
1485.0u 408.0s 2:38.54 1194.0% 227+222k 0+32272io 36pf+0w
1484.3u 407.0s 2:35.88 1213.3% 228+224k 0+32268io 14pf+0w

>>> stats.ttest_ind([160.65,158.49,157.27], [157.5,158.54,155.88])
Ttest_indResult(statistic=1.1923622711296888, pvalue=0.2990182944606766)
>>>


# 1.116 30-Sep-2021 skrll

Ensure TCR_EPD0 is set on entry to pmap_activate and ensure it is set as
early as possible for APs.


# 1.115 26-Sep-2021 skrll

Use UVMHIST_CALLARGS


# 1.114 26-Sep-2021 skrll

'\n' is not required in KASSERTMSG either.


# 1.113 26-Sep-2021 skrll

"\n" is not required in KERNHIST


# 1.112 15-Sep-2021 skrll

Use __SHIFTIN. Same code before and after.


# 1.111 12-Sep-2021 skrll

pmap_page_remove: simply and reduce the code size slightly.


# 1.110 09-Sep-2021 skrll

In pmap_icache_sync_range change

for (...) {
...
if (condition) {
// do stuff
}
}

to

for (...) {
...
if (!conditional)
continue;
// do stuff
}

to save on indentation. Same code (modulo register usage) before and
after.


# 1.109 09-Sep-2021 skrll

KNF


Revision tags: thorpej-i2c-spi-conf2-base thorpej-futex2-base thorpej-cfargs2-base cjep_sun2x-base1 cjep_sun2x-base cjep_staticlib_x-base1 thorpej-i2c-spi-conf-base
# 1.108 29-May-2021 skrll

Deal with the pmap limitation of maxproc in a more complete way and
recognise CPUs with only 8bit ASIDs.


Revision tags: cjep_staticlib_x-base
# 1.107 30-Apr-2021 skrll

branches: 1.107.2;
Make the ddb for pmap / pte information pmap agnostic


# 1.106 29-Apr-2021 skrll

Remove some unnecessary tlb invalidate in pmap_growkernel and ASAN shadow
map. Ensure the shadow map mappings are visible to the TLB walkers.


# 1.105 21-Apr-2021 ryo

branches: 1.105.2;
added more attributes of PTE displayed by "ddb>machine pte"


Revision tags: thorpej-cfargs-base
# 1.104 17-Apr-2021 mrg

remove KERNHIST_INIT_STATIC(). it stradles the line between usable
early in boot and broken early in boot by requiring a partly static
structure with another structure that must be present by the time
any uses are performed. theoretically platform code could allocate
a chunk while seting up memory and assign it here, giving a dynamic
sizing for the entry list, but the reality is that all users have
a statically allocated entry list as well.

the existing KERNHIST_LINK_STATIC() is used in conjunction with
KERNHIST_INITIALIZER() instead.

this stops a NULL pointer deref when the _LOG() macro is called
before the storage is linked in, which happens with GCC 10 on OCTEON
with UVMHIST enabled, crashing in very early kernel init.


Revision tags: thorpej-futex-base
# 1.103 09-Mar-2021 ryo

branches: 1.103.2;
fix build error without options DDB.

kvtopte() is referenced from arm/acpi/acpi_machdep.c


# 1.102 13-Feb-2021 ryo

No assignment is needed here.

the loop in pmap_page_remove() always removes the first pv,
and since the list is managed by _pmap_remove_pv(), pp->pp_pv.pv_next always points to the first.


# 1.101 01-Feb-2021 ryo

It is enough to make a page accessible instead of writable.
same fix as r1.76


# 1.100 31-Jan-2021 ryo

implement pmap_remove_all().

The size of struct pv_entry has increased, but speed of kernel build has improved by about 1%
exec and exit should have been improved.


# 1.99 20-Dec-2020 skrll

Improve the English in the previous comment fix.


# 1.98 19-Dec-2020 skrll

Tweak a comment


# 1.97 11-Dec-2020 skrll

s:aarch64/cpufunc.h:arm/cpufunc.h:

a baby step in the grand arm header unification challenge


# 1.96 10-Nov-2020 skrll

AA64 is not MIPS.

Change all KSEG references to directmap


# 1.95 07-Nov-2020 skrll

In pmap_devmap_bootstrap only set pmap_devmap_bootstrap_done if there
is an entry and ALL of the entries have been done. The entry required
for EARLYCONS might not be the first/only one...


# 1.94 01-Nov-2020 jmcneill

branches: 1.94.2;
No need to disable translation table walks in pmap_activate().


# 1.93 22-Oct-2020 skrll

Use the isb macro - missed in previous commit


# 1.92 22-Oct-2020 skrll

Use the dmb/dsb/isb macros... if nothing else they're all now consistent
about the "memory" assembler contraint.

No binary change


# 1.91 28-Sep-2020 skrll

Only set pmap_devmap_bootstrap_done if something gets mapped.

Think acpi_platform_devmap


# 1.90 19-Sep-2020 skrll

Make __md_palloc pmap agnostic (think sys/uvm/pmap)


# 1.89 14-Sep-2020 ryo

PID_MAX is just an initial value (soft maximum). Don't use it for CTASSERT.
defined __HAVE_CPU_MAXPROC to use function cpu_maxproc().

pointed out by mrg@, thanks.


# 1.88 06-Sep-2020 ryo

Fix panic caused by modload. http://mail-index.netbsd.org/port-arm/2020/08/30/msg006960.html

The address space reserved for modules may not be mapped in L1-L3.


# 1.87 14-Aug-2020 skrll

Whitespace


# 1.86 12-Aug-2020 skrll

Part IV of ad's performance improvements for aarch64

- Implement pmap_growkernel(), and update kernel pmap's stats with atomics.

- Then, pmap_kenter_pa() and pmap_kremove() no longer need to allocate
memory nor take pm_lock, because they only modify L3 PTEs.

- Then, pm_lock and pp_lock can be adaptive mutexes at IPL_NONE which are
cheaper than spin mutexes.

- Take the pmap's lock in pmap_extract() if not the kernel's pmap, otherwise
pmap_extract() might see inconsistent state.


# 1.85 09-Aug-2020 skrll

Fix another UVMHIST so it doesn't use %s


# 1.84 16-Jul-2020 skrll

pmapboot_enter simplication
- bootpage_alloc in asm becomes pmapboot_pagealloc in C
- PMAPBOOT_ENTER_NOBLOCK is removed as it's not used
- PMAPBOOT_ENTER_NOOVERWRITE is removed as it's now always on
- physpage_allocator argument is removed as it's always
pmapboot_pagealloc
- Support for EARLYCONS without CONSADDR is removed so that the identity
map for CONSADDR is always known.

For the assembly files:
2 files changed, 40 insertions(+), 89 deletions(-)

LGTM ryo


# 1.83 04-Jul-2020 rin

Use tlen for temporary length variable instead of l, which is usually
used for struct lwp *.

No binary changes.


# 1.82 02-Jul-2020 rin

pmap_procwr(): sync icache even if p != curproc. This fixes applications
like GDB for arm32, that rewrite text of other process.

Thanks to ryo@ for discussion.


# 1.81 02-Jul-2020 rin

Set uvmexp.ncolors appropriately, which is required for some CPU
models with VIPT icache.

Otherwise, alias in virtual address results in inconsistent results,
at least for applications that rewrite text of other process, e.g.,
GDB for arm32.

Also, this hopefully fixes other unexpected failures due to alias.

Confirmed that there's no observable regression in performance;
difference in ``time make -j8'' for GENERIC64 kernel on BCM2837
with and without setting uvmexp.ncolors is within 0.1%.

Thanks to ryo@ for discussion.


# 1.80 27-Jun-2020 rin

Fix typo in name of evcnt(4) counter.


# 1.79 24-Jun-2020 ryo

Fix bug with incorrect range calculation when doing icache sync.
This is called by sysarch(ARM_SYNC_ICACHE) from aarch32 (compat_netbsd32) emul process.

pointed out by rin@, thanks.

XXX pullup-9


# 1.78 14-Jun-2020 ad

- Fix a lock order reversal in pmap_page_protect().

- Make sure pmap is always locked when updating stats; atomics no longer
needed to do that.

- Remove unneeded traversal of pv list in pmap_enter_pv().

- Shrink struct vm_page from 136 to 128 bytes (cache line sized) and struct
pv_entry from 48 to 32 bytes (power of 2 sized).

- Embed a pv_entry in each vm_page. This means PV entries don't need to
be allocated for private anonymous memory / COW pages / most UBC mappings.
Dynamic PV entries are then used only for stuff like shared libraries and
shared memory.

Proposed on port-arm@.


# 1.77 10-Jun-2020 ad

- Wired/resident stats shouldn't covered by PMAPCOUNTERS.
- Rename need_update_pv -> need_enter_pv.

Ok ryo@


# 1.76 01-Jun-2020 ryo

no need to make the PTE writable to do icache_sync, enough to accessible.


# 1.75 15-May-2020 skrll

Use __diagused


# 1.74 15-May-2020 tnn

fix non-diag build


# 1.73 14-May-2020 skrll

Use MUTEX_NODEBUG for PV locks as is commonly done. OK ryo.


# 1.72 13-May-2020 jmcneill

Implement pmap_extract_coherency


Revision tags: bouyer-xenpvh-base2 phil-wifi-20200421 bouyer-xenpvh-base1
# 1.71 18-Apr-2020 skrll

PMAP_DEBUG has been deleted on arm


# 1.70 13-Apr-2020 maxv

Add support for Branch Target Identification (BTI).

On the executable pages that have the GP (Guarded Page) bit, the semantic
of the "br" and "blr" instructions is changed: the CPU expects the first
instruction of the jump/call target to be "bti", and faults if it isn't.

We add the GP bit on the kernel .text pages (and incidentally the .rodata
pages, but we don't care). The compiler adds a "bti c" instruction at the
beginning of each C function. We modify the ENTRY() macros to manually add
"bti c" in the asm functions.

cpuswitch.S needs a specific change: with "br x27" the CPU expects "bti j",
which is bad because the functions begin with "bti c"; switch to "br x16",
for the CPU to accept "bti c".

BTI helps defend against JOP/COP. Tested on Qemu.


Revision tags: phil-wifi-20200411 bouyer-xenpvh-base
# 1.69 08-Apr-2020 ryo

branches: 1.69.2;
use PMAP_PAGE_INIT() to initialize mutex in pmap_page.

VM_MDPAGE_INIT() in pmap_free_pdp() had initialized pp_flags,
so it unintentionally cleared PMAP_PAGE_FLAGS_PV_TRACKED.
use PMAP_PAGE_INIT to avoid using PMAP_PAGE_FLAGS_PV_TRACKED.

pointed out by tnn@, thanks


Revision tags: phil-wifi-20200406
# 1.68 14-Mar-2020 ad

pmap_remove_all(): Return a boolean value to indicate the behaviour. If
true, all mappings have been removed, the pmap is totally cleared out, and
UVM can then avoid doing the work to call pmap_remove() for each map entry.
If false, either nothing has been done, or some helpful arch-specific voodoo
has taken place.


Revision tags: is-mlppp-base
# 1.67 02-Mar-2020 ryo

oops, fix incorrect usage of daif_enable() in my previous commit.


# 1.66 29-Feb-2020 ryo

Fix pmap to work correctly with tagged addresses

- when fault, untag from address before passing to uvm/pmap functions
- pmap_extract() checks more strictly and consider the address tag


# 1.65 29-Feb-2020 ryo

use pmapboot_enter_range()


Revision tags: ad-namecache-base3
# 1.64 10-Feb-2020 ryo

use LIST(3) instead of TAILQ(3) to save one word in struct vm_page and struct pmap.

pointed out by riastradh@. thanks


# 1.63 03-Feb-2020 ryo

add support pmap_pv(9)

Patch originally from jmcneill@. thanks


# 1.62 03-Feb-2020 ryo

separate struct vm_page_md into vm_page_md and pmap_page
for preparation pmap_pv(9)


Revision tags: ad-namecache-base2 ad-namecache-base1
# 1.61 09-Jan-2020 ryo

fix behaviour mmap()/mprotect() when passed only PROT_EXEC.

when mmap()/mprotect() with only PROT_EXEC, syscall will be successful,
but the page actually hadn't been mapped.
it should be mapped with PROT_READ|PROT_EXEC implicitly. (r-x)


Revision tags: ad-namecache-base
# 1.60 30-Dec-2019 skrll

branches: 1.60.2;
Update pmap_map_chunk to allow L[12] block mappings and L3 page mappings


# 1.59 30-Dec-2019 skrll

Remove unnecessary brackets and unwrap a conditional. Same code before
and after.


# 1.58 28-Dec-2019 jmcneill

Do not use Early Write Acknowledge for PCIe I/O and config space.


# 1.57 27-Dec-2019 jmcneill

Enable early write acknowledge for device memory mappings.


# 1.56 19-Dec-2019 skrll

G/C kasan_shadow_map call in pmap_enter

pmap_growkernel calls kasan_shadow_map for KVA


# 1.55 18-Dec-2019 ryo

atomic_add_16() is not used in pmap.c anymore. no need decl here.


# 1.54 18-Dec-2019 ryo

space to tab


# 1.53 14-Dec-2019 skrll

Fix build... wire_count probably doesn't need atomics


# 1.52 13-Dec-2019 skrll

Fix KASAN support by calling kasan_shadow_map in pmap_growkernel


# 1.51 10-Dec-2019 ad

pg->phys_addr -> VM_PAGE_TO_PHYS(pg)


Revision tags: phil-wifi-20191119
# 1.50 14-Nov-2019 maxv

Mark several kASan functions with __nothing, to avoid annoying #ifdefs.
Same as kCSan and kMSan.


# 1.49 14-Nov-2019 maxv

Don't include "opt_kasan.h" when there's already <sys/asan.h> included.


# 1.48 29-Oct-2019 maya

Define PMAP_NEED_PROCWR, providing strategically placed i-cache
synchronization where just-changed memory is about to be executed.

Fixes SIGILLs seen when running Mono 6 on QEMU Cortex-A57.

ok ryo


# 1.47 22-Sep-2019 jmcneill

Disable translation table walks using TTBR0 while changing its value and
when deactivating a pmap. Fixes stability issues on Ampere eMAG CPUs.


# 1.46 20-Sep-2019 ryo

ref/mod bit should be set according to 'flags' argument, not 'prot'. r1.44 was incomplete.


# 1.45 13-Sep-2019 ryo

In pmap_devmap_bootstrap(), cpu_earlydevice_va_p() must not return true until *all* devmap tables have been enabled.
console mapping may be present in the last table.


# 1.44 07-Sep-2019 ryo

- remove incorrect KASSERT. mmap(2) with prot=PROT_WRITE calls pmap_enter(..., PROT_WRITE) internally.
- fix to update page reference flags when only PROT_WRITE or PROT_EXECUTE specified


# 1.43 15-Aug-2019 skrll

Make pmap_db_pte_print more terse so it's quicker on serial consoles


# 1.42 12-Aug-2019 skrll

Use PMAP_DEV in DEVMAP_ENTRY rather than pmap_map_chunk. It's clearer and
means pmap_map_chunk can be made to map other memory types.


Revision tags: netbsd-9-base phil-wifi-20190609
# 1.41 17-May-2019 mrg

branches: 1.41.2;
apply some __diagused.


Revision tags: isaki-audio2-base
# 1.40 08-Apr-2019 ryo

- free empty page tables pages if reach a certain usage.
- need to lock at removing an old pg (_pmap_remove_pv) in _pmap_enter()


# 1.39 06-Apr-2019 ryo

Fix race conditions about pmap_page_protect() and pmap_enter().

while handling same PTE by these functions in same time, there
is a critical path that the number of valid PTEs and wire_count
are inconsistent, and it caused KASSERT.
Need to hold a pv_lock while modifying them.


# 1.38 20-Mar-2019 ryo

spinkle __printflike(), and use PRIxxx


# 1.37 19-Mar-2019 ryo

- add ddb command "machine ttbr" to dump MMU tables.
- tidy up descriptions, usages and messages.


# 1.36 19-Mar-2019 ryo

- free L1-L3 pages that has been emptied by pmap_remove().
- if no memories, pmap_enter will return correctly ENOMEM if PMAP_CANFAIL, or wait until available any memories if !PMAP_CANFAIL.

These changes improves the stability when we use a huge virtual memory spaces with mmap.


# 1.35 06-Feb-2019 ryo

improve pmap_remove
- don't lock/unlock per page in pmap_remove()
- speedup pte lookup for continuous addresses
- bring out pool_cache_put(&_pmap_pv_pool, pv) from lock/unlock section


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226
# 1.34 21-Dec-2018 ryo

- add workaround for Cavium ThunderX errata 27456.
- add cpufuncs table in cpu_info. each cpu clusters may have different erratum. (e.g. big.LITTLE)


Revision tags: pgoyette-compat-1126
# 1.33 01-Nov-2018 maxv

Add kASan support for aarch64. Stack tracking needs more investigation
and will come in a separate commit.

Reviewed by ryo@ jmcneill@ skrll@.


# 1.32 31-Oct-2018 ryo

invalidate icache correctly.
l3pte_executable() should be used for only valid pte.


Revision tags: pgoyette-compat-1020
# 1.31 18-Oct-2018 skrll

Provide generic start code that assumes the MMU is off and caches are
disabled as per the linux booting protocol for ARMv6 and ARMv7 boards.
u-boot image type should be changed to 'linux' for correct behaviour.

The new start code builds a minimal "bootstrap" L1PT with cached access
disabled and uses the same table for all processors. AP startup is
performed in less steps and more code is written in C.

The bootstrap tables and stack are placed into an (orphaned) section
"_init_memory" which is given to uvm when it is no longer used.

Various kernels have been converted to use this code and tested. Some
boards were provided by TNF. Thanks!

The GENERIC kernel now boots on boards using the TEGRA, SUNXI and EXYNOS
kernels. The GENERIC kernel will also work on RPI2 using u-boot.

Thanks to martin@ and aymeric@ for testing on parallella and nanosoc
respectively


# 1.30 14-Oct-2018 skrll

Use __nothing


# 1.29 12-Oct-2018 ryo

add initial support of COMPAT_NETBSD32 on AArch64.
arm ELF32 EABI binaries could be execute in AArch32 state on AArch64. A32 THUMB mode is not supported yet.


# 1.28 12-Oct-2018 ryo

- cleanup checking address ranges with IN_RANGE macro
- change PM_ADDR_CHECK macro to KASSERTMSG
- restore fast lookup cases with IN_RANGE macro for pmap_extract changed in my previous commit.


# 1.27 12-Oct-2018 ryo

rewrite pmap_pte_lookup() to share similar code.


# 1.26 04-Oct-2018 ryo

cleanup locore, and changed the way to map memories during boot.
- add functions bootpage_enter() and bootpage_alloc() to adapt various layout
of physical memory map. especially for 64bit physical memory layout.
pmapboot_alloc() allocates pagetable pages from _end[].
- changed to map only the required amount for PA=VA identity mapping
(kernel image, UART device, and FDT blob) with L2_BLOCK(2Mbyte).
- changing page permission for kernel image, and making KSEG mapping are done
at cpu_kernel_vm_init() instead of at locore.
- optimize PTE entries with PTE Contiguous bit. it is enabled on devmap only for now.

reviewed by skrll@, thanks.


# 1.25 04-Oct-2018 ryo

* define LX_BLKPAG_{OS,ATTR}_* for OS dependent PTE attributes in pmap.h
* cleanup macros


Revision tags: pgoyette-compat-0930
# 1.24 17-Sep-2018 ryo

delete debug printf and KASSERT.


# 1.23 10-Sep-2018 maxv

Replace KDASSERT by panic.


# 1.22 10-Sep-2018 maxv

Rename _pmap_alloc_pdp -> pmap_alloc_pdp, and make it public.


# 1.21 10-Sep-2018 ryo

cleanup aarch64 mpstart and fdt bootstrap
* arm_cpu_hatch_arg is a bad idea. avoid serializing CPU startup, and eliminate arm_cpu_hatch_arg.
in mpstart, resolve own cpu index using array of cpu_mpidr[] (aarch64)
* add support fdt enable-method "spin-table"
* add support fdt enable-method "brcm,bcm2836-smp" (for 32bit RaspberryPi)
* use arm_fdt_cpu_bootstrap() instead of psci_fdt_bootstrap()
* rename "arm/fdt/psci_fdt.h" to "arm/fdt/psci_fdtvar.h" because of conflict of include file for needs-flag
* add devmap for cpu spin-table of raspberrypi3/aarch64
* no need to force hatch APs for raspberrypi3/arm32 ifndef MULTIPROCESSOR.
* fix to work pmap_extract(kerneltext/data/bss) even if before calling pmap_bootstrap

idea to use cpu_mpidr[] by jmcneill@. reviewd by skrll@. thanks.


Revision tags: pgoyette-compat-0906
# 1.20 27-Aug-2018 ryo

need to add VM_PROT_READ when pmap_kenter_pa(va, pa, VM_PROT_WRITE, 0) or pmap_kenter_pa(va, pa, VM_PROT_EXECUTE, 0).
VM_PROT_READ is treated as an access permission inernally.


# 1.19 11-Aug-2018 ryo

change to minimum invalidation of TLB.
specifying not only va but also asid, and not invalidate L0-L2 entry using tlbi_*_ll() if needed.


# 1.18 10-Aug-2018 ryo

treat kernel-exec attr and user-exec attr separately.
kernel cannot execute userland exec page, and user cannot execute kernel page.


# 1.17 06-Aug-2018 ryo

set kernel text/rodata readonly by default.
add function db_write_text() for setting ddb breakpoint.


# 1.16 31-Jul-2018 skrll

Define and use VPRINTF


Revision tags: pgoyette-compat-0728
# 1.15 27-Jul-2018 ryo

changes of pmap.c r1.13 seems to be unstable.
In order to invalidate icache, not to invalidate all icache,
but temporary to make the page writable and invalidate target address only.


# 1.14 24-Jul-2018 ryo

don't call pool_cache_put with locking pmap. pool_cache_put call pmap_kenter_pa internally.
(pool_cache_put_paddr -> pool_cache_put_slow -> pool_get -> pmap_kenter_pa)


# 1.13 23-Jul-2018 ryo

* fix icache invalidations.
* "ic ivau" (aarch64_icache_sync_range) with VA generates permission fault in some situations, therefore use KSEG address for now.


# 1.12 23-Jul-2018 ryo

rather than using flags to resolve nested locks, reserve pool_cache before locking.


# 1.11 21-Jul-2018 ryo

* avoid deadlock. mutex_owned() works only for adaptive lock, therefore we cannot use it for spinlock...
* add more NULL check
* clear pte when pmap_enter() fails


# 1.10 17-Jul-2018 ryo

Use __debugused


# 1.9 17-Jul-2018 christos

Add missing casts, remove unused variables.


# 1.8 09-Jul-2018 ryo

need locks in pmap_kremove() and pmap_fault_fixup()


Revision tags: phil-wifi-base pgoyette-compat-0625 pgoyette-compat-0521
# 1.7 20-May-2018 ryo

branches: 1.7.2;
pmap_enter() must update modified/referenced flags by 'flags' not 'prot'.


# 1.6 16-May-2018 ryo

Fix memory leak. it was leaking one page every pmap_create().
pm->pm_vmlist must be initialized before calling _pmap_alloc_pdp().


Revision tags: pgoyette-compat-0502
# 1.5 29-Apr-2018 ryo

fix KASSERT panic. pv_entry may not be exists in pvlist when pmap_remove().


# 1.4 29-Apr-2018 ryo

delete unused code


# 1.3 27-Apr-2018 ryo

fix instability behavior of bufcache on aarch64.
* fix to return correct ref/mod when PMAP_WIRED.
* changed to keep wired flags in pte instead of pv_entry, and cleanup.


Revision tags: pgoyette-compat-0422 pgoyette-compat-0415 pgoyette-compat-0407
# 1.2 01-Apr-2018 ryo

Add initial support for ARMv8 (AARCH64) (by nisimura@ and ryo@)

- sys/arch/evbarm64 is gone and integrated into sys/arch/evbarm. (by skrll@)
- add support fdt. evbarm/conf/GENERIC64 fdt (bcm2837,sunxi,tegra) based generic 64bit kernel config. (by skrll@, jmcneill@)


Revision tags: netbsd-8-2-RELEASE netbsd-8-1-RELEASE netbsd-8-1-RC1 netbsd-7-2-RELEASE netbsd-8-0-RELEASE netbsd-8-0-RC2 netbsd-8-0-RC1 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 netbsd-7-1-2-RELEASE pgoyette-compat-base netbsd-7-1-1-RELEASE tls-maxphys-base-20171202 matt-nb8-mediatek-base nick-nhusb-base-20170825 perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base pgoyette-localcount-20170320 netbsd-7-1-RELEASE netbsd-7-1-RC2 nick-nhusb-base-20170204 netbsd-7-nhusb-base-20170116 bouyer-socketcan-base pgoyette-localcount-20170107 netbsd-7-1-RC1 nick-nhusb-base-20161204 pgoyette-localcount-20161104 netbsd-7-0-2-RELEASE nick-nhusb-base-20161004 localcount-20160914 netbsd-7-nhusb-base pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907 nick-nhusb-base-20160529 netbsd-7-0-1-RELEASE nick-nhusb-base-20160422 nick-nhusb-base-20160319 nick-nhusb-base-20151226 netbsd-7-0-RELEASE nick-nhusb-base-20150921 netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 nick-nhusb-base-20150606 nick-nhusb-base-20150406 nick-nhusb-base tls-maxphys-base netbsd-7-base
# 1.1 10-Aug-2014 matt

branches: 1.1.4; 1.1.28;
Preliminary files for AARCH64 (64-bit ARM) support.
Enough for a distribution build.


# 1.119 23-Oct-2021 skrll

Fix non-UVMHIST build


# 1.118 16-Oct-2021 ryo

fix non-MULTIPROCESSOR build


# 1.117 10-Oct-2021 skrll

Use sys/uvm/pmap/pmap_tlb.c on Aarch64 in the same way that some Arm, MIPS,
and some PPC kernels do. This removes the limitation of 256 processes on
CPUs with 8bit ASID field, e.g. Apple M1.

Additionally the following changes have been made

- removed a couple of unnecessary aarch64_tlbi_all calls
- removed any invalidation after freeing page tables due to
_pmap_sweep_pdp. This was never necessary afaict.
- all kernel mappings are marked global and userland mapping not-global.

Performance testing hasn't show a significant difference. The data here
is from building a kernel on an lx2k system with nvme.

before
1489.6u 400.4s 2:40.65 1176.5% 228+224k 0+32289io 57pf+0w
1482.6u 403.2s 2:38.49 1189.9% 228+222k 0+32274io 46pf+0w
1485.4u 402.2s 2:37.27 1200.2% 228+222k 0+32275io 12pf+0w

after
1493.9u 404.6s 2:37.50 1205.4% 227+221k 0+32265io 48pf+0w
1485.0u 408.0s 2:38.54 1194.0% 227+222k 0+32272io 36pf+0w
1484.3u 407.0s 2:35.88 1213.3% 228+224k 0+32268io 14pf+0w

>>> stats.ttest_ind([160.65,158.49,157.27], [157.5,158.54,155.88])
Ttest_indResult(statistic=1.1923622711296888, pvalue=0.2990182944606766)
>>>


# 1.116 30-Sep-2021 skrll

Ensure TCR_EPD0 is set on entry to pmap_activate and ensure it is set as
early as possible for APs.


# 1.115 26-Sep-2021 skrll

Use UVMHIST_CALLARGS


# 1.114 26-Sep-2021 skrll

'\n' is not required in KASSERTMSG either.


# 1.113 26-Sep-2021 skrll

"\n" is not required in KERNHIST


# 1.112 15-Sep-2021 skrll

Use __SHIFTIN. Same code before and after.


# 1.111 12-Sep-2021 skrll

pmap_page_remove: simply and reduce the code size slightly.


# 1.110 09-Sep-2021 skrll

In pmap_icache_sync_range change

for (...) {
...
if (condition) {
// do stuff
}
}

to

for (...) {
...
if (!conditional)
continue;
// do stuff
}

to save on indentation. Same code (modulo register usage) before and
after.


# 1.109 09-Sep-2021 skrll

KNF


Revision tags: thorpej-i2c-spi-conf2-base thorpej-futex2-base thorpej-cfargs2-base cjep_sun2x-base1 cjep_sun2x-base cjep_staticlib_x-base1 thorpej-i2c-spi-conf-base
# 1.108 29-May-2021 skrll

Deal with the pmap limitation of maxproc in a more complete way and
recognise CPUs with only 8bit ASIDs.


Revision tags: cjep_staticlib_x-base
# 1.107 30-Apr-2021 skrll

branches: 1.107.2;
Make the ddb for pmap / pte information pmap agnostic


# 1.106 29-Apr-2021 skrll

Remove some unnecessary tlb invalidate in pmap_growkernel and ASAN shadow
map. Ensure the shadow map mappings are visible to the TLB walkers.


# 1.105 21-Apr-2021 ryo

branches: 1.105.2;
added more attributes of PTE displayed by "ddb>machine pte"


Revision tags: thorpej-cfargs-base
# 1.104 17-Apr-2021 mrg

remove KERNHIST_INIT_STATIC(). it stradles the line between usable
early in boot and broken early in boot by requiring a partly static
structure with another structure that must be present by the time
any uses are performed. theoretically platform code could allocate
a chunk while seting up memory and assign it here, giving a dynamic
sizing for the entry list, but the reality is that all users have
a statically allocated entry list as well.

the existing KERNHIST_LINK_STATIC() is used in conjunction with
KERNHIST_INITIALIZER() instead.

this stops a NULL pointer deref when the _LOG() macro is called
before the storage is linked in, which happens with GCC 10 on OCTEON
with UVMHIST enabled, crashing in very early kernel init.


Revision tags: thorpej-futex-base
# 1.103 09-Mar-2021 ryo

branches: 1.103.2;
fix build error without options DDB.

kvtopte() is referenced from arm/acpi/acpi_machdep.c


# 1.102 13-Feb-2021 ryo

No assignment is needed here.

the loop in pmap_page_remove() always removes the first pv,
and since the list is managed by _pmap_remove_pv(), pp->pp_pv.pv_next always points to the first.


# 1.101 01-Feb-2021 ryo

It is enough to make a page accessible instead of writable.
same fix as r1.76


# 1.100 31-Jan-2021 ryo

implement pmap_remove_all().

The size of struct pv_entry has increased, but speed of kernel build has improved by about 1%
exec and exit should have been improved.


# 1.99 20-Dec-2020 skrll

Improve the English in the previous comment fix.


# 1.98 19-Dec-2020 skrll

Tweak a comment


# 1.97 11-Dec-2020 skrll

s:aarch64/cpufunc.h:arm/cpufunc.h:

a baby step in the grand arm header unification challenge


# 1.96 10-Nov-2020 skrll

AA64 is not MIPS.

Change all KSEG references to directmap


# 1.95 07-Nov-2020 skrll

In pmap_devmap_bootstrap only set pmap_devmap_bootstrap_done if there
is an entry and ALL of the entries have been done. The entry required
for EARLYCONS might not be the first/only one...


# 1.94 01-Nov-2020 jmcneill

branches: 1.94.2;
No need to disable translation table walks in pmap_activate().


# 1.93 22-Oct-2020 skrll

Use the isb macro - missed in previous commit


# 1.92 22-Oct-2020 skrll

Use the dmb/dsb/isb macros... if nothing else they're all now consistent
about the "memory" assembler contraint.

No binary change


# 1.91 28-Sep-2020 skrll

Only set pmap_devmap_bootstrap_done if something gets mapped.

Think acpi_platform_devmap


# 1.90 19-Sep-2020 skrll

Make __md_palloc pmap agnostic (think sys/uvm/pmap)


# 1.89 14-Sep-2020 ryo

PID_MAX is just an initial value (soft maximum). Don't use it for CTASSERT.
defined __HAVE_CPU_MAXPROC to use function cpu_maxproc().

pointed out by mrg@, thanks.


# 1.88 06-Sep-2020 ryo

Fix panic caused by modload. http://mail-index.netbsd.org/port-arm/2020/08/30/msg006960.html

The address space reserved for modules may not be mapped in L1-L3.


# 1.87 14-Aug-2020 skrll

Whitespace


# 1.86 12-Aug-2020 skrll

Part IV of ad's performance improvements for aarch64

- Implement pmap_growkernel(), and update kernel pmap's stats with atomics.

- Then, pmap_kenter_pa() and pmap_kremove() no longer need to allocate
memory nor take pm_lock, because they only modify L3 PTEs.

- Then, pm_lock and pp_lock can be adaptive mutexes at IPL_NONE which are
cheaper than spin mutexes.

- Take the pmap's lock in pmap_extract() if not the kernel's pmap, otherwise
pmap_extract() might see inconsistent state.


# 1.85 09-Aug-2020 skrll

Fix another UVMHIST so it doesn't use %s


# 1.84 16-Jul-2020 skrll

pmapboot_enter simplication
- bootpage_alloc in asm becomes pmapboot_pagealloc in C
- PMAPBOOT_ENTER_NOBLOCK is removed as it's not used
- PMAPBOOT_ENTER_NOOVERWRITE is removed as it's now always on
- physpage_allocator argument is removed as it's always
pmapboot_pagealloc
- Support for EARLYCONS without CONSADDR is removed so that the identity
map for CONSADDR is always known.

For the assembly files:
2 files changed, 40 insertions(+), 89 deletions(-)

LGTM ryo


# 1.83 04-Jul-2020 rin

Use tlen for temporary length variable instead of l, which is usually
used for struct lwp *.

No binary changes.


# 1.82 02-Jul-2020 rin

pmap_procwr(): sync icache even if p != curproc. This fixes applications
like GDB for arm32, that rewrite text of other process.

Thanks to ryo@ for discussion.


# 1.81 02-Jul-2020 rin

Set uvmexp.ncolors appropriately, which is required for some CPU
models with VIPT icache.

Otherwise, alias in virtual address results in inconsistent results,
at least for applications that rewrite text of other process, e.g.,
GDB for arm32.

Also, this hopefully fixes other unexpected failures due to alias.

Confirmed that there's no observable regression in performance;
difference in ``time make -j8'' for GENERIC64 kernel on BCM2837
with and without setting uvmexp.ncolors is within 0.1%.

Thanks to ryo@ for discussion.


# 1.80 27-Jun-2020 rin

Fix typo in name of evcnt(4) counter.


# 1.79 24-Jun-2020 ryo

Fix bug with incorrect range calculation when doing icache sync.
This is called by sysarch(ARM_SYNC_ICACHE) from aarch32 (compat_netbsd32) emul process.

pointed out by rin@, thanks.

XXX pullup-9


# 1.78 14-Jun-2020 ad

- Fix a lock order reversal in pmap_page_protect().

- Make sure pmap is always locked when updating stats; atomics no longer
needed to do that.

- Remove unneeded traversal of pv list in pmap_enter_pv().

- Shrink struct vm_page from 136 to 128 bytes (cache line sized) and struct
pv_entry from 48 to 32 bytes (power of 2 sized).

- Embed a pv_entry in each vm_page. This means PV entries don't need to
be allocated for private anonymous memory / COW pages / most UBC mappings.
Dynamic PV entries are then used only for stuff like shared libraries and
shared memory.

Proposed on port-arm@.


# 1.77 10-Jun-2020 ad

- Wired/resident stats shouldn't covered by PMAPCOUNTERS.
- Rename need_update_pv -> need_enter_pv.

Ok ryo@


# 1.76 01-Jun-2020 ryo

no need to make the PTE writable to do icache_sync, enough to accessible.


# 1.75 15-May-2020 skrll

Use __diagused


# 1.74 15-May-2020 tnn

fix non-diag build


# 1.73 14-May-2020 skrll

Use MUTEX_NODEBUG for PV locks as is commonly done. OK ryo.


# 1.72 13-May-2020 jmcneill

Implement pmap_extract_coherency


Revision tags: bouyer-xenpvh-base2 phil-wifi-20200421 bouyer-xenpvh-base1
# 1.71 18-Apr-2020 skrll

PMAP_DEBUG has been deleted on arm


# 1.70 13-Apr-2020 maxv

Add support for Branch Target Identification (BTI).

On the executable pages that have the GP (Guarded Page) bit, the semantic
of the "br" and "blr" instructions is changed: the CPU expects the first
instruction of the jump/call target to be "bti", and faults if it isn't.

We add the GP bit on the kernel .text pages (and incidentally the .rodata
pages, but we don't care). The compiler adds a "bti c" instruction at the
beginning of each C function. We modify the ENTRY() macros to manually add
"bti c" in the asm functions.

cpuswitch.S needs a specific change: with "br x27" the CPU expects "bti j",
which is bad because the functions begin with "bti c"; switch to "br x16",
for the CPU to accept "bti c".

BTI helps defend against JOP/COP. Tested on Qemu.


Revision tags: phil-wifi-20200411 bouyer-xenpvh-base
# 1.69 08-Apr-2020 ryo

branches: 1.69.2;
use PMAP_PAGE_INIT() to initialize mutex in pmap_page.

VM_MDPAGE_INIT() in pmap_free_pdp() had initialized pp_flags,
so it unintentionally cleared PMAP_PAGE_FLAGS_PV_TRACKED.
use PMAP_PAGE_INIT to avoid using PMAP_PAGE_FLAGS_PV_TRACKED.

pointed out by tnn@, thanks


Revision tags: phil-wifi-20200406
# 1.68 14-Mar-2020 ad

pmap_remove_all(): Return a boolean value to indicate the behaviour. If
true, all mappings have been removed, the pmap is totally cleared out, and
UVM can then avoid doing the work to call pmap_remove() for each map entry.
If false, either nothing has been done, or some helpful arch-specific voodoo
has taken place.


Revision tags: is-mlppp-base
# 1.67 02-Mar-2020 ryo

oops, fix incorrect usage of daif_enable() in my previous commit.


# 1.66 29-Feb-2020 ryo

Fix pmap to work correctly with tagged addresses

- when fault, untag from address before passing to uvm/pmap functions
- pmap_extract() checks more strictly and consider the address tag


# 1.65 29-Feb-2020 ryo

use pmapboot_enter_range()


Revision tags: ad-namecache-base3
# 1.64 10-Feb-2020 ryo

use LIST(3) instead of TAILQ(3) to save one word in struct vm_page and struct pmap.

pointed out by riastradh@. thanks


# 1.63 03-Feb-2020 ryo

add support pmap_pv(9)

Patch originally from jmcneill@. thanks


# 1.62 03-Feb-2020 ryo

separate struct vm_page_md into vm_page_md and pmap_page
for preparation pmap_pv(9)


Revision tags: ad-namecache-base2 ad-namecache-base1
# 1.61 09-Jan-2020 ryo

fix behaviour mmap()/mprotect() when passed only PROT_EXEC.

when mmap()/mprotect() with only PROT_EXEC, syscall will be successful,
but the page actually hadn't been mapped.
it should be mapped with PROT_READ|PROT_EXEC implicitly. (r-x)


Revision tags: ad-namecache-base
# 1.60 30-Dec-2019 skrll

branches: 1.60.2;
Update pmap_map_chunk to allow L[12] block mappings and L3 page mappings


# 1.59 30-Dec-2019 skrll

Remove unnecessary brackets and unwrap a conditional. Same code before
and after.


# 1.58 28-Dec-2019 jmcneill

Do not use Early Write Acknowledge for PCIe I/O and config space.


# 1.57 27-Dec-2019 jmcneill

Enable early write acknowledge for device memory mappings.


# 1.56 19-Dec-2019 skrll

G/C kasan_shadow_map call in pmap_enter

pmap_growkernel calls kasan_shadow_map for KVA


# 1.55 18-Dec-2019 ryo

atomic_add_16() is not used in pmap.c anymore. no need decl here.


# 1.54 18-Dec-2019 ryo

space to tab


# 1.53 14-Dec-2019 skrll

Fix build... wire_count probably doesn't need atomics


# 1.52 13-Dec-2019 skrll

Fix KASAN support by calling kasan_shadow_map in pmap_growkernel


# 1.51 10-Dec-2019 ad

pg->phys_addr -> VM_PAGE_TO_PHYS(pg)


Revision tags: phil-wifi-20191119
# 1.50 14-Nov-2019 maxv

Mark several kASan functions with __nothing, to avoid annoying #ifdefs.
Same as kCSan and kMSan.


# 1.49 14-Nov-2019 maxv

Don't include "opt_kasan.h" when there's already <sys/asan.h> included.


# 1.48 29-Oct-2019 maya

Define PMAP_NEED_PROCWR, providing strategically placed i-cache
synchronization where just-changed memory is about to be executed.

Fixes SIGILLs seen when running Mono 6 on QEMU Cortex-A57.

ok ryo


# 1.47 22-Sep-2019 jmcneill

Disable translation table walks using TTBR0 while changing its value and
when deactivating a pmap. Fixes stability issues on Ampere eMAG CPUs.


# 1.46 20-Sep-2019 ryo

ref/mod bit should be set according to 'flags' argument, not 'prot'. r1.44 was incomplete.


# 1.45 13-Sep-2019 ryo

In pmap_devmap_bootstrap(), cpu_earlydevice_va_p() must not return true until *all* devmap tables have been enabled.
console mapping may be present in the last table.


# 1.44 07-Sep-2019 ryo

- remove incorrect KASSERT. mmap(2) with prot=PROT_WRITE calls pmap_enter(..., PROT_WRITE) internally.
- fix to update page reference flags when only PROT_WRITE or PROT_EXECUTE specified


# 1.43 15-Aug-2019 skrll

Make pmap_db_pte_print more terse so it's quicker on serial consoles


# 1.42 12-Aug-2019 skrll

Use PMAP_DEV in DEVMAP_ENTRY rather than pmap_map_chunk. It's clearer and
means pmap_map_chunk can be made to map other memory types.


Revision tags: netbsd-9-base phil-wifi-20190609
# 1.41 17-May-2019 mrg

branches: 1.41.2;
apply some __diagused.


Revision tags: isaki-audio2-base
# 1.40 08-Apr-2019 ryo

- free empty page tables pages if reach a certain usage.
- need to lock at removing an old pg (_pmap_remove_pv) in _pmap_enter()


# 1.39 06-Apr-2019 ryo

Fix race conditions about pmap_page_protect() and pmap_enter().

while handling same PTE by these functions in same time, there
is a critical path that the number of valid PTEs and wire_count
are inconsistent, and it caused KASSERT.
Need to hold a pv_lock while modifying them.


# 1.38 20-Mar-2019 ryo

spinkle __printflike(), and use PRIxxx


# 1.37 19-Mar-2019 ryo

- add ddb command "machine ttbr" to dump MMU tables.
- tidy up descriptions, usages and messages.


# 1.36 19-Mar-2019 ryo

- free L1-L3 pages that has been emptied by pmap_remove().
- if no memories, pmap_enter will return correctly ENOMEM if PMAP_CANFAIL, or wait until available any memories if !PMAP_CANFAIL.

These changes improves the stability when we use a huge virtual memory spaces with mmap.


# 1.35 06-Feb-2019 ryo

improve pmap_remove
- don't lock/unlock per page in pmap_remove()
- speedup pte lookup for continuous addresses
- bring out pool_cache_put(&_pmap_pv_pool, pv) from lock/unlock section


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226
# 1.34 21-Dec-2018 ryo

- add workaround for Cavium ThunderX errata 27456.
- add cpufuncs table in cpu_info. each cpu clusters may have different erratum. (e.g. big.LITTLE)


Revision tags: pgoyette-compat-1126
# 1.33 01-Nov-2018 maxv

Add kASan support for aarch64. Stack tracking needs more investigation
and will come in a separate commit.

Reviewed by ryo@ jmcneill@ skrll@.


# 1.32 31-Oct-2018 ryo

invalidate icache correctly.
l3pte_executable() should be used for only valid pte.


Revision tags: pgoyette-compat-1020
# 1.31 18-Oct-2018 skrll

Provide generic start code that assumes the MMU is off and caches are
disabled as per the linux booting protocol for ARMv6 and ARMv7 boards.
u-boot image type should be changed to 'linux' for correct behaviour.

The new start code builds a minimal "bootstrap" L1PT with cached access
disabled and uses the same table for all processors. AP startup is
performed in less steps and more code is written in C.

The bootstrap tables and stack are placed into an (orphaned) section
"_init_memory" which is given to uvm when it is no longer used.

Various kernels have been converted to use this code and tested. Some
boards were provided by TNF. Thanks!

The GENERIC kernel now boots on boards using the TEGRA, SUNXI and EXYNOS
kernels. The GENERIC kernel will also work on RPI2 using u-boot.

Thanks to martin@ and aymeric@ for testing on parallella and nanosoc
respectively


# 1.30 14-Oct-2018 skrll

Use __nothing


# 1.29 12-Oct-2018 ryo

add initial support of COMPAT_NETBSD32 on AArch64.
arm ELF32 EABI binaries could be execute in AArch32 state on AArch64. A32 THUMB mode is not supported yet.


# 1.28 12-Oct-2018 ryo

- cleanup checking address ranges with IN_RANGE macro
- change PM_ADDR_CHECK macro to KASSERTMSG
- restore fast lookup cases with IN_RANGE macro for pmap_extract changed in my previous commit.


# 1.27 12-Oct-2018 ryo

rewrite pmap_pte_lookup() to share similar code.


# 1.26 04-Oct-2018 ryo

cleanup locore, and changed the way to map memories during boot.
- add functions bootpage_enter() and bootpage_alloc() to adapt various layout
of physical memory map. especially for 64bit physical memory layout.
pmapboot_alloc() allocates pagetable pages from _end[].
- changed to map only the required amount for PA=VA identity mapping
(kernel image, UART device, and FDT blob) with L2_BLOCK(2Mbyte).
- changing page permission for kernel image, and making KSEG mapping are done
at cpu_kernel_vm_init() instead of at locore.
- optimize PTE entries with PTE Contiguous bit. it is enabled on devmap only for now.

reviewed by skrll@, thanks.


# 1.25 04-Oct-2018 ryo

* define LX_BLKPAG_{OS,ATTR}_* for OS dependent PTE attributes in pmap.h
* cleanup macros


Revision tags: pgoyette-compat-0930
# 1.24 17-Sep-2018 ryo

delete debug printf and KASSERT.


# 1.23 10-Sep-2018 maxv

Replace KDASSERT by panic.


# 1.22 10-Sep-2018 maxv

Rename _pmap_alloc_pdp -> pmap_alloc_pdp, and make it public.


# 1.21 10-Sep-2018 ryo

cleanup aarch64 mpstart and fdt bootstrap
* arm_cpu_hatch_arg is a bad idea. avoid serializing CPU startup, and eliminate arm_cpu_hatch_arg.
in mpstart, resolve own cpu index using array of cpu_mpidr[] (aarch64)
* add support fdt enable-method "spin-table"
* add support fdt enable-method "brcm,bcm2836-smp" (for 32bit RaspberryPi)
* use arm_fdt_cpu_bootstrap() instead of psci_fdt_bootstrap()
* rename "arm/fdt/psci_fdt.h" to "arm/fdt/psci_fdtvar.h" because of conflict of include file for needs-flag
* add devmap for cpu spin-table of raspberrypi3/aarch64
* no need to force hatch APs for raspberrypi3/arm32 ifndef MULTIPROCESSOR.
* fix to work pmap_extract(kerneltext/data/bss) even if before calling pmap_bootstrap

idea to use cpu_mpidr[] by jmcneill@. reviewd by skrll@. thanks.


Revision tags: pgoyette-compat-0906
# 1.20 27-Aug-2018 ryo

need to add VM_PROT_READ when pmap_kenter_pa(va, pa, VM_PROT_WRITE, 0) or pmap_kenter_pa(va, pa, VM_PROT_EXECUTE, 0).
VM_PROT_READ is treated as an access permission inernally.


# 1.19 11-Aug-2018 ryo

change to minimum invalidation of TLB.
specifying not only va but also asid, and not invalidate L0-L2 entry using tlbi_*_ll() if needed.


# 1.18 10-Aug-2018 ryo

treat kernel-exec attr and user-exec attr separately.
kernel cannot execute userland exec page, and user cannot execute kernel page.


# 1.17 06-Aug-2018 ryo

set kernel text/rodata readonly by default.
add function db_write_text() for setting ddb breakpoint.


# 1.16 31-Jul-2018 skrll

Define and use VPRINTF


Revision tags: pgoyette-compat-0728
# 1.15 27-Jul-2018 ryo

changes of pmap.c r1.13 seems to be unstable.
In order to invalidate icache, not to invalidate all icache,
but temporary to make the page writable and invalidate target address only.


# 1.14 24-Jul-2018 ryo

don't call pool_cache_put with locking pmap. pool_cache_put call pmap_kenter_pa internally.
(pool_cache_put_paddr -> pool_cache_put_slow -> pool_get -> pmap_kenter_pa)


# 1.13 23-Jul-2018 ryo

* fix icache invalidations.
* "ic ivau" (aarch64_icache_sync_range) with VA generates permission fault in some situations, therefore use KSEG address for now.


# 1.12 23-Jul-2018 ryo

rather than using flags to resolve nested locks, reserve pool_cache before locking.


# 1.11 21-Jul-2018 ryo

* avoid deadlock. mutex_owned() works only for adaptive lock, therefore we cannot use it for spinlock...
* add more NULL check
* clear pte when pmap_enter() fails


# 1.10 17-Jul-2018 ryo

Use __debugused


# 1.9 17-Jul-2018 christos

Add missing casts, remove unused variables.


# 1.8 09-Jul-2018 ryo

need locks in pmap_kremove() and pmap_fault_fixup()


Revision tags: phil-wifi-base pgoyette-compat-0625 pgoyette-compat-0521
# 1.7 20-May-2018 ryo

branches: 1.7.2;
pmap_enter() must update modified/referenced flags by 'flags' not 'prot'.


# 1.6 16-May-2018 ryo

Fix memory leak. it was leaking one page every pmap_create().
pm->pm_vmlist must be initialized before calling _pmap_alloc_pdp().


Revision tags: pgoyette-compat-0502
# 1.5 29-Apr-2018 ryo

fix KASSERT panic. pv_entry may not be exists in pvlist when pmap_remove().


# 1.4 29-Apr-2018 ryo

delete unused code


# 1.3 27-Apr-2018 ryo

fix instability behavior of bufcache on aarch64.
* fix to return correct ref/mod when PMAP_WIRED.
* changed to keep wired flags in pte instead of pv_entry, and cleanup.


Revision tags: pgoyette-compat-0422 pgoyette-compat-0415 pgoyette-compat-0407
# 1.2 01-Apr-2018 ryo

Add initial support for ARMv8 (AARCH64) (by nisimura@ and ryo@)

- sys/arch/evbarm64 is gone and integrated into sys/arch/evbarm. (by skrll@)
- add support fdt. evbarm/conf/GENERIC64 fdt (bcm2837,sunxi,tegra) based generic 64bit kernel config. (by skrll@, jmcneill@)


Revision tags: netbsd-8-2-RELEASE netbsd-8-1-RELEASE netbsd-8-1-RC1 netbsd-7-2-RELEASE netbsd-8-0-RELEASE netbsd-8-0-RC2 netbsd-8-0-RC1 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 netbsd-7-1-2-RELEASE pgoyette-compat-base netbsd-7-1-1-RELEASE tls-maxphys-base-20171202 matt-nb8-mediatek-base nick-nhusb-base-20170825 perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base pgoyette-localcount-20170320 netbsd-7-1-RELEASE netbsd-7-1-RC2 nick-nhusb-base-20170204 netbsd-7-nhusb-base-20170116 bouyer-socketcan-base pgoyette-localcount-20170107 netbsd-7-1-RC1 nick-nhusb-base-20161204 pgoyette-localcount-20161104 netbsd-7-0-2-RELEASE nick-nhusb-base-20161004 localcount-20160914 netbsd-7-nhusb-base pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907 nick-nhusb-base-20160529 netbsd-7-0-1-RELEASE nick-nhusb-base-20160422 nick-nhusb-base-20160319 nick-nhusb-base-20151226 netbsd-7-0-RELEASE nick-nhusb-base-20150921 netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 nick-nhusb-base-20150606 nick-nhusb-base-20150406 nick-nhusb-base tls-maxphys-base netbsd-7-base
# 1.1 10-Aug-2014 matt

branches: 1.1.4; 1.1.28;
Preliminary files for AARCH64 (64-bit ARM) support.
Enough for a distribution build.


# 1.118 16-Oct-2021 ryo

fix non-MULTIPROCESSOR build


# 1.117 10-Oct-2021 skrll

Use sys/uvm/pmap/pmap_tlb.c on Aarch64 in the same way that some Arm, MIPS,
and some PPC kernels do. This removes the limitation of 256 processes on
CPUs with 8bit ASID field, e.g. Apple M1.

Additionally the following changes have been made

- removed a couple of unnecessary aarch64_tlbi_all calls
- removed any invalidation after freeing page tables due to
_pmap_sweep_pdp. This was never necessary afaict.
- all kernel mappings are marked global and userland mapping not-global.

Performance testing hasn't show a significant difference. The data here
is from building a kernel on an lx2k system with nvme.

before
1489.6u 400.4s 2:40.65 1176.5% 228+224k 0+32289io 57pf+0w
1482.6u 403.2s 2:38.49 1189.9% 228+222k 0+32274io 46pf+0w
1485.4u 402.2s 2:37.27 1200.2% 228+222k 0+32275io 12pf+0w

after
1493.9u 404.6s 2:37.50 1205.4% 227+221k 0+32265io 48pf+0w
1485.0u 408.0s 2:38.54 1194.0% 227+222k 0+32272io 36pf+0w
1484.3u 407.0s 2:35.88 1213.3% 228+224k 0+32268io 14pf+0w

>>> stats.ttest_ind([160.65,158.49,157.27], [157.5,158.54,155.88])
Ttest_indResult(statistic=1.1923622711296888, pvalue=0.2990182944606766)
>>>


# 1.116 30-Sep-2021 skrll

Ensure TCR_EPD0 is set on entry to pmap_activate and ensure it is set as
early as possible for APs.


# 1.115 26-Sep-2021 skrll

Use UVMHIST_CALLARGS


# 1.114 26-Sep-2021 skrll

'\n' is not required in KASSERTMSG either.


# 1.113 26-Sep-2021 skrll

"\n" is not required in KERNHIST


# 1.112 15-Sep-2021 skrll

Use __SHIFTIN. Same code before and after.


# 1.111 12-Sep-2021 skrll

pmap_page_remove: simply and reduce the code size slightly.


# 1.110 09-Sep-2021 skrll

In pmap_icache_sync_range change

for (...) {
...
if (condition) {
// do stuff
}
}

to

for (...) {
...
if (!conditional)
continue;
// do stuff
}

to save on indentation. Same code (modulo register usage) before and
after.


# 1.109 09-Sep-2021 skrll

KNF


Revision tags: thorpej-i2c-spi-conf2-base thorpej-futex2-base thorpej-cfargs2-base cjep_sun2x-base1 cjep_sun2x-base cjep_staticlib_x-base1 thorpej-i2c-spi-conf-base
# 1.108 29-May-2021 skrll

Deal with the pmap limitation of maxproc in a more complete way and
recognise CPUs with only 8bit ASIDs.


Revision tags: cjep_staticlib_x-base
# 1.107 30-Apr-2021 skrll

branches: 1.107.2;
Make the ddb for pmap / pte information pmap agnostic


# 1.106 29-Apr-2021 skrll

Remove some unnecessary tlb invalidate in pmap_growkernel and ASAN shadow
map. Ensure the shadow map mappings are visible to the TLB walkers.


# 1.105 21-Apr-2021 ryo

branches: 1.105.2;
added more attributes of PTE displayed by "ddb>machine pte"


Revision tags: thorpej-cfargs-base
# 1.104 17-Apr-2021 mrg

remove KERNHIST_INIT_STATIC(). it stradles the line between usable
early in boot and broken early in boot by requiring a partly static
structure with another structure that must be present by the time
any uses are performed. theoretically platform code could allocate
a chunk while seting up memory and assign it here, giving a dynamic
sizing for the entry list, but the reality is that all users have
a statically allocated entry list as well.

the existing KERNHIST_LINK_STATIC() is used in conjunction with
KERNHIST_INITIALIZER() instead.

this stops a NULL pointer deref when the _LOG() macro is called
before the storage is linked in, which happens with GCC 10 on OCTEON
with UVMHIST enabled, crashing in very early kernel init.


Revision tags: thorpej-futex-base
# 1.103 09-Mar-2021 ryo

branches: 1.103.2;
fix build error without options DDB.

kvtopte() is referenced from arm/acpi/acpi_machdep.c


# 1.102 13-Feb-2021 ryo

No assignment is needed here.

the loop in pmap_page_remove() always removes the first pv,
and since the list is managed by _pmap_remove_pv(), pp->pp_pv.pv_next always points to the first.


# 1.101 01-Feb-2021 ryo

It is enough to make a page accessible instead of writable.
same fix as r1.76


# 1.100 31-Jan-2021 ryo

implement pmap_remove_all().

The size of struct pv_entry has increased, but speed of kernel build has improved by about 1%
exec and exit should have been improved.


# 1.99 20-Dec-2020 skrll

Improve the English in the previous comment fix.


# 1.98 19-Dec-2020 skrll

Tweak a comment


# 1.97 11-Dec-2020 skrll

s:aarch64/cpufunc.h:arm/cpufunc.h:

a baby step in the grand arm header unification challenge


# 1.96 10-Nov-2020 skrll

AA64 is not MIPS.

Change all KSEG references to directmap


# 1.95 07-Nov-2020 skrll

In pmap_devmap_bootstrap only set pmap_devmap_bootstrap_done if there
is an entry and ALL of the entries have been done. The entry required
for EARLYCONS might not be the first/only one...


# 1.94 01-Nov-2020 jmcneill

branches: 1.94.2;
No need to disable translation table walks in pmap_activate().


# 1.93 22-Oct-2020 skrll

Use the isb macro - missed in previous commit


# 1.92 22-Oct-2020 skrll

Use the dmb/dsb/isb macros... if nothing else they're all now consistent
about the "memory" assembler contraint.

No binary change


# 1.91 28-Sep-2020 skrll

Only set pmap_devmap_bootstrap_done if something gets mapped.

Think acpi_platform_devmap


# 1.90 19-Sep-2020 skrll

Make __md_palloc pmap agnostic (think sys/uvm/pmap)


# 1.89 14-Sep-2020 ryo

PID_MAX is just an initial value (soft maximum). Don't use it for CTASSERT.
defined __HAVE_CPU_MAXPROC to use function cpu_maxproc().

pointed out by mrg@, thanks.


# 1.88 06-Sep-2020 ryo

Fix panic caused by modload. http://mail-index.netbsd.org/port-arm/2020/08/30/msg006960.html

The address space reserved for modules may not be mapped in L1-L3.


# 1.87 14-Aug-2020 skrll

Whitespace


# 1.86 12-Aug-2020 skrll

Part IV of ad's performance improvements for aarch64

- Implement pmap_growkernel(), and update kernel pmap's stats with atomics.

- Then, pmap_kenter_pa() and pmap_kremove() no longer need to allocate
memory nor take pm_lock, because they only modify L3 PTEs.

- Then, pm_lock and pp_lock can be adaptive mutexes at IPL_NONE which are
cheaper than spin mutexes.

- Take the pmap's lock in pmap_extract() if not the kernel's pmap, otherwise
pmap_extract() might see inconsistent state.


# 1.85 09-Aug-2020 skrll

Fix another UVMHIST so it doesn't use %s


# 1.84 16-Jul-2020 skrll

pmapboot_enter simplication
- bootpage_alloc in asm becomes pmapboot_pagealloc in C
- PMAPBOOT_ENTER_NOBLOCK is removed as it's not used
- PMAPBOOT_ENTER_NOOVERWRITE is removed as it's now always on
- physpage_allocator argument is removed as it's always
pmapboot_pagealloc
- Support for EARLYCONS without CONSADDR is removed so that the identity
map for CONSADDR is always known.

For the assembly files:
2 files changed, 40 insertions(+), 89 deletions(-)

LGTM ryo


# 1.83 04-Jul-2020 rin

Use tlen for temporary length variable instead of l, which is usually
used for struct lwp *.

No binary changes.


# 1.82 02-Jul-2020 rin

pmap_procwr(): sync icache even if p != curproc. This fixes applications
like GDB for arm32, that rewrite text of other process.

Thanks to ryo@ for discussion.


# 1.81 02-Jul-2020 rin

Set uvmexp.ncolors appropriately, which is required for some CPU
models with VIPT icache.

Otherwise, alias in virtual address results in inconsistent results,
at least for applications that rewrite text of other process, e.g.,
GDB for arm32.

Also, this hopefully fixes other unexpected failures due to alias.

Confirmed that there's no observable regression in performance;
difference in ``time make -j8'' for GENERIC64 kernel on BCM2837
with and without setting uvmexp.ncolors is within 0.1%.

Thanks to ryo@ for discussion.


# 1.80 27-Jun-2020 rin

Fix typo in name of evcnt(4) counter.


# 1.79 24-Jun-2020 ryo

Fix bug with incorrect range calculation when doing icache sync.
This is called by sysarch(ARM_SYNC_ICACHE) from aarch32 (compat_netbsd32) emul process.

pointed out by rin@, thanks.

XXX pullup-9


# 1.78 14-Jun-2020 ad

- Fix a lock order reversal in pmap_page_protect().

- Make sure pmap is always locked when updating stats; atomics no longer
needed to do that.

- Remove unneeded traversal of pv list in pmap_enter_pv().

- Shrink struct vm_page from 136 to 128 bytes (cache line sized) and struct
pv_entry from 48 to 32 bytes (power of 2 sized).

- Embed a pv_entry in each vm_page. This means PV entries don't need to
be allocated for private anonymous memory / COW pages / most UBC mappings.
Dynamic PV entries are then used only for stuff like shared libraries and
shared memory.

Proposed on port-arm@.


# 1.77 10-Jun-2020 ad

- Wired/resident stats shouldn't covered by PMAPCOUNTERS.
- Rename need_update_pv -> need_enter_pv.

Ok ryo@


# 1.76 01-Jun-2020 ryo

no need to make the PTE writable to do icache_sync, enough to accessible.


# 1.75 15-May-2020 skrll

Use __diagused


# 1.74 15-May-2020 tnn

fix non-diag build


# 1.73 14-May-2020 skrll

Use MUTEX_NODEBUG for PV locks as is commonly done. OK ryo.


# 1.72 13-May-2020 jmcneill

Implement pmap_extract_coherency


Revision tags: bouyer-xenpvh-base2 phil-wifi-20200421 bouyer-xenpvh-base1
# 1.71 18-Apr-2020 skrll

PMAP_DEBUG has been deleted on arm


# 1.70 13-Apr-2020 maxv

Add support for Branch Target Identification (BTI).

On the executable pages that have the GP (Guarded Page) bit, the semantic
of the "br" and "blr" instructions is changed: the CPU expects the first
instruction of the jump/call target to be "bti", and faults if it isn't.

We add the GP bit on the kernel .text pages (and incidentally the .rodata
pages, but we don't care). The compiler adds a "bti c" instruction at the
beginning of each C function. We modify the ENTRY() macros to manually add
"bti c" in the asm functions.

cpuswitch.S needs a specific change: with "br x27" the CPU expects "bti j",
which is bad because the functions begin with "bti c"; switch to "br x16",
for the CPU to accept "bti c".

BTI helps defend against JOP/COP. Tested on Qemu.


Revision tags: phil-wifi-20200411 bouyer-xenpvh-base
# 1.69 08-Apr-2020 ryo

branches: 1.69.2;
use PMAP_PAGE_INIT() to initialize mutex in pmap_page.

VM_MDPAGE_INIT() in pmap_free_pdp() had initialized pp_flags,
so it unintentionally cleared PMAP_PAGE_FLAGS_PV_TRACKED.
use PMAP_PAGE_INIT to avoid using PMAP_PAGE_FLAGS_PV_TRACKED.

pointed out by tnn@, thanks


Revision tags: phil-wifi-20200406
# 1.68 14-Mar-2020 ad

pmap_remove_all(): Return a boolean value to indicate the behaviour. If
true, all mappings have been removed, the pmap is totally cleared out, and
UVM can then avoid doing the work to call pmap_remove() for each map entry.
If false, either nothing has been done, or some helpful arch-specific voodoo
has taken place.


Revision tags: is-mlppp-base
# 1.67 02-Mar-2020 ryo

oops, fix incorrect usage of daif_enable() in my previous commit.


# 1.66 29-Feb-2020 ryo

Fix pmap to work correctly with tagged addresses

- when fault, untag from address before passing to uvm/pmap functions
- pmap_extract() checks more strictly and consider the address tag


# 1.65 29-Feb-2020 ryo

use pmapboot_enter_range()


Revision tags: ad-namecache-base3
# 1.64 10-Feb-2020 ryo

use LIST(3) instead of TAILQ(3) to save one word in struct vm_page and struct pmap.

pointed out by riastradh@. thanks


# 1.63 03-Feb-2020 ryo

add support pmap_pv(9)

Patch originally from jmcneill@. thanks


# 1.62 03-Feb-2020 ryo

separate struct vm_page_md into vm_page_md and pmap_page
for preparation pmap_pv(9)


Revision tags: ad-namecache-base2 ad-namecache-base1
# 1.61 09-Jan-2020 ryo

fix behaviour mmap()/mprotect() when passed only PROT_EXEC.

when mmap()/mprotect() with only PROT_EXEC, syscall will be successful,
but the page actually hadn't been mapped.
it should be mapped with PROT_READ|PROT_EXEC implicitly. (r-x)


Revision tags: ad-namecache-base
# 1.60 30-Dec-2019 skrll

branches: 1.60.2;
Update pmap_map_chunk to allow L[12] block mappings and L3 page mappings


# 1.59 30-Dec-2019 skrll

Remove unnecessary brackets and unwrap a conditional. Same code before
and after.


# 1.58 28-Dec-2019 jmcneill

Do not use Early Write Acknowledge for PCIe I/O and config space.


# 1.57 27-Dec-2019 jmcneill

Enable early write acknowledge for device memory mappings.


# 1.56 19-Dec-2019 skrll

G/C kasan_shadow_map call in pmap_enter

pmap_growkernel calls kasan_shadow_map for KVA


# 1.55 18-Dec-2019 ryo

atomic_add_16() is not used in pmap.c anymore. no need decl here.


# 1.54 18-Dec-2019 ryo

space to tab


# 1.53 14-Dec-2019 skrll

Fix build... wire_count probably doesn't need atomics


# 1.52 13-Dec-2019 skrll

Fix KASAN support by calling kasan_shadow_map in pmap_growkernel


# 1.51 10-Dec-2019 ad

pg->phys_addr -> VM_PAGE_TO_PHYS(pg)


Revision tags: phil-wifi-20191119
# 1.50 14-Nov-2019 maxv

Mark several kASan functions with __nothing, to avoid annoying #ifdefs.
Same as kCSan and kMSan.


# 1.49 14-Nov-2019 maxv

Don't include "opt_kasan.h" when there's already <sys/asan.h> included.


# 1.48 29-Oct-2019 maya

Define PMAP_NEED_PROCWR, providing strategically placed i-cache
synchronization where just-changed memory is about to be executed.

Fixes SIGILLs seen when running Mono 6 on QEMU Cortex-A57.

ok ryo


# 1.47 22-Sep-2019 jmcneill

Disable translation table walks using TTBR0 while changing its value and
when deactivating a pmap. Fixes stability issues on Ampere eMAG CPUs.


# 1.46 20-Sep-2019 ryo

ref/mod bit should be set according to 'flags' argument, not 'prot'. r1.44 was incomplete.


# 1.45 13-Sep-2019 ryo

In pmap_devmap_bootstrap(), cpu_earlydevice_va_p() must not return true until *all* devmap tables have been enabled.
console mapping may be present in the last table.


# 1.44 07-Sep-2019 ryo

- remove incorrect KASSERT. mmap(2) with prot=PROT_WRITE calls pmap_enter(..., PROT_WRITE) internally.
- fix to update page reference flags when only PROT_WRITE or PROT_EXECUTE specified


# 1.43 15-Aug-2019 skrll

Make pmap_db_pte_print more terse so it's quicker on serial consoles


# 1.42 12-Aug-2019 skrll

Use PMAP_DEV in DEVMAP_ENTRY rather than pmap_map_chunk. It's clearer and
means pmap_map_chunk can be made to map other memory types.


Revision tags: netbsd-9-base phil-wifi-20190609
# 1.41 17-May-2019 mrg

branches: 1.41.2;
apply some __diagused.


Revision tags: isaki-audio2-base
# 1.40 08-Apr-2019 ryo

- free empty page tables pages if reach a certain usage.
- need to lock at removing an old pg (_pmap_remove_pv) in _pmap_enter()


# 1.39 06-Apr-2019 ryo

Fix race conditions about pmap_page_protect() and pmap_enter().

while handling same PTE by these functions in same time, there
is a critical path that the number of valid PTEs and wire_count
are inconsistent, and it caused KASSERT.
Need to hold a pv_lock while modifying them.


# 1.38 20-Mar-2019 ryo

spinkle __printflike(), and use PRIxxx


# 1.37 19-Mar-2019 ryo

- add ddb command "machine ttbr" to dump MMU tables.
- tidy up descriptions, usages and messages.


# 1.36 19-Mar-2019 ryo

- free L1-L3 pages that has been emptied by pmap_remove().
- if no memories, pmap_enter will return correctly ENOMEM if PMAP_CANFAIL, or wait until available any memories if !PMAP_CANFAIL.

These changes improves the stability when we use a huge virtual memory spaces with mmap.


# 1.35 06-Feb-2019 ryo

improve pmap_remove
- don't lock/unlock per page in pmap_remove()
- speedup pte lookup for continuous addresses
- bring out pool_cache_put(&_pmap_pv_pool, pv) from lock/unlock section


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226
# 1.34 21-Dec-2018 ryo

- add workaround for Cavium ThunderX errata 27456.
- add cpufuncs table in cpu_info. each cpu clusters may have different erratum. (e.g. big.LITTLE)


Revision tags: pgoyette-compat-1126
# 1.33 01-Nov-2018 maxv

Add kASan support for aarch64. Stack tracking needs more investigation
and will come in a separate commit.

Reviewed by ryo@ jmcneill@ skrll@.


# 1.32 31-Oct-2018 ryo

invalidate icache correctly.
l3pte_executable() should be used for only valid pte.


Revision tags: pgoyette-compat-1020
# 1.31 18-Oct-2018 skrll

Provide generic start code that assumes the MMU is off and caches are
disabled as per the linux booting protocol for ARMv6 and ARMv7 boards.
u-boot image type should be changed to 'linux' for correct behaviour.

The new start code builds a minimal "bootstrap" L1PT with cached access
disabled and uses the same table for all processors. AP startup is
performed in less steps and more code is written in C.

The bootstrap tables and stack are placed into an (orphaned) section
"_init_memory" which is given to uvm when it is no longer used.

Various kernels have been converted to use this code and tested. Some
boards were provided by TNF. Thanks!

The GENERIC kernel now boots on boards using the TEGRA, SUNXI and EXYNOS
kernels. The GENERIC kernel will also work on RPI2 using u-boot.

Thanks to martin@ and aymeric@ for testing on parallella and nanosoc
respectively


# 1.30 14-Oct-2018 skrll

Use __nothing


# 1.29 12-Oct-2018 ryo

add initial support of COMPAT_NETBSD32 on AArch64.
arm ELF32 EABI binaries could be execute in AArch32 state on AArch64. A32 THUMB mode is not supported yet.


# 1.28 12-Oct-2018 ryo

- cleanup checking address ranges with IN_RANGE macro
- change PM_ADDR_CHECK macro to KASSERTMSG
- restore fast lookup cases with IN_RANGE macro for pmap_extract changed in my previous commit.


# 1.27 12-Oct-2018 ryo

rewrite pmap_pte_lookup() to share similar code.


# 1.26 04-Oct-2018 ryo

cleanup locore, and changed the way to map memories during boot.
- add functions bootpage_enter() and bootpage_alloc() to adapt various layout
of physical memory map. especially for 64bit physical memory layout.
pmapboot_alloc() allocates pagetable pages from _end[].
- changed to map only the required amount for PA=VA identity mapping
(kernel image, UART device, and FDT blob) with L2_BLOCK(2Mbyte).
- changing page permission for kernel image, and making KSEG mapping are done
at cpu_kernel_vm_init() instead of at locore.
- optimize PTE entries with PTE Contiguous bit. it is enabled on devmap only for now.

reviewed by skrll@, thanks.


# 1.25 04-Oct-2018 ryo

* define LX_BLKPAG_{OS,ATTR}_* for OS dependent PTE attributes in pmap.h
* cleanup macros


Revision tags: pgoyette-compat-0930
# 1.24 17-Sep-2018 ryo

delete debug printf and KASSERT.


# 1.23 10-Sep-2018 maxv

Replace KDASSERT by panic.


# 1.22 10-Sep-2018 maxv

Rename _pmap_alloc_pdp -> pmap_alloc_pdp, and make it public.


# 1.21 10-Sep-2018 ryo

cleanup aarch64 mpstart and fdt bootstrap
* arm_cpu_hatch_arg is a bad idea. avoid serializing CPU startup, and eliminate arm_cpu_hatch_arg.
in mpstart, resolve own cpu index using array of cpu_mpidr[] (aarch64)
* add support fdt enable-method "spin-table"
* add support fdt enable-method "brcm,bcm2836-smp" (for 32bit RaspberryPi)
* use arm_fdt_cpu_bootstrap() instead of psci_fdt_bootstrap()
* rename "arm/fdt/psci_fdt.h" to "arm/fdt/psci_fdtvar.h" because of conflict of include file for needs-flag
* add devmap for cpu spin-table of raspberrypi3/aarch64
* no need to force hatch APs for raspberrypi3/arm32 ifndef MULTIPROCESSOR.
* fix to work pmap_extract(kerneltext/data/bss) even if before calling pmap_bootstrap

idea to use cpu_mpidr[] by jmcneill@. reviewd by skrll@. thanks.


Revision tags: pgoyette-compat-0906
# 1.20 27-Aug-2018 ryo

need to add VM_PROT_READ when pmap_kenter_pa(va, pa, VM_PROT_WRITE, 0) or pmap_kenter_pa(va, pa, VM_PROT_EXECUTE, 0).
VM_PROT_READ is treated as an access permission inernally.


# 1.19 11-Aug-2018 ryo

change to minimum invalidation of TLB.
specifying not only va but also asid, and not invalidate L0-L2 entry using tlbi_*_ll() if needed.


# 1.18 10-Aug-2018 ryo

treat kernel-exec attr and user-exec attr separately.
kernel cannot execute userland exec page, and user cannot execute kernel page.


# 1.17 06-Aug-2018 ryo

set kernel text/rodata readonly by default.
add function db_write_text() for setting ddb breakpoint.


# 1.16 31-Jul-2018 skrll

Define and use VPRINTF


Revision tags: pgoyette-compat-0728
# 1.15 27-Jul-2018 ryo

changes of pmap.c r1.13 seems to be unstable.
In order to invalidate icache, not to invalidate all icache,
but temporary to make the page writable and invalidate target address only.


# 1.14 24-Jul-2018 ryo

don't call pool_cache_put with locking pmap. pool_cache_put call pmap_kenter_pa internally.
(pool_cache_put_paddr -> pool_cache_put_slow -> pool_get -> pmap_kenter_pa)


# 1.13 23-Jul-2018 ryo

* fix icache invalidations.
* "ic ivau" (aarch64_icache_sync_range) with VA generates permission fault in some situations, therefore use KSEG address for now.


# 1.12 23-Jul-2018 ryo

rather than using flags to resolve nested locks, reserve pool_cache before locking.


# 1.11 21-Jul-2018 ryo

* avoid deadlock. mutex_owned() works only for adaptive lock, therefore we cannot use it for spinlock...
* add more NULL check
* clear pte when pmap_enter() fails


# 1.10 17-Jul-2018 ryo

Use __debugused


# 1.9 17-Jul-2018 christos

Add missing casts, remove unused variables.


# 1.8 09-Jul-2018 ryo

need locks in pmap_kremove() and pmap_fault_fixup()


Revision tags: phil-wifi-base pgoyette-compat-0625 pgoyette-compat-0521
# 1.7 20-May-2018 ryo

branches: 1.7.2;
pmap_enter() must update modified/referenced flags by 'flags' not 'prot'.


# 1.6 16-May-2018 ryo

Fix memory leak. it was leaking one page every pmap_create().
pm->pm_vmlist must be initialized before calling _pmap_alloc_pdp().


Revision tags: pgoyette-compat-0502
# 1.5 29-Apr-2018 ryo

fix KASSERT panic. pv_entry may not be exists in pvlist when pmap_remove().


# 1.4 29-Apr-2018 ryo

delete unused code


# 1.3 27-Apr-2018 ryo

fix instability behavior of bufcache on aarch64.
* fix to return correct ref/mod when PMAP_WIRED.
* changed to keep wired flags in pte instead of pv_entry, and cleanup.


Revision tags: pgoyette-compat-0422 pgoyette-compat-0415 pgoyette-compat-0407
# 1.2 01-Apr-2018 ryo

Add initial support for ARMv8 (AARCH64) (by nisimura@ and ryo@)

- sys/arch/evbarm64 is gone and integrated into sys/arch/evbarm. (by skrll@)
- add support fdt. evbarm/conf/GENERIC64 fdt (bcm2837,sunxi,tegra) based generic 64bit kernel config. (by skrll@, jmcneill@)


Revision tags: netbsd-8-2-RELEASE netbsd-8-1-RELEASE netbsd-8-1-RC1 netbsd-7-2-RELEASE netbsd-8-0-RELEASE netbsd-8-0-RC2 netbsd-8-0-RC1 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 netbsd-7-1-2-RELEASE pgoyette-compat-base netbsd-7-1-1-RELEASE tls-maxphys-base-20171202 matt-nb8-mediatek-base nick-nhusb-base-20170825 perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base pgoyette-localcount-20170320 netbsd-7-1-RELEASE netbsd-7-1-RC2 nick-nhusb-base-20170204 netbsd-7-nhusb-base-20170116 bouyer-socketcan-base pgoyette-localcount-20170107 netbsd-7-1-RC1 nick-nhusb-base-20161204 pgoyette-localcount-20161104 netbsd-7-0-2-RELEASE nick-nhusb-base-20161004 localcount-20160914 netbsd-7-nhusb-base pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907 nick-nhusb-base-20160529 netbsd-7-0-1-RELEASE nick-nhusb-base-20160422 nick-nhusb-base-20160319 nick-nhusb-base-20151226 netbsd-7-0-RELEASE nick-nhusb-base-20150921 netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 nick-nhusb-base-20150606 nick-nhusb-base-20150406 nick-nhusb-base tls-maxphys-base netbsd-7-base
# 1.1 10-Aug-2014 matt

branches: 1.1.4; 1.1.28;
Preliminary files for AARCH64 (64-bit ARM) support.
Enough for a distribution build.


# 1.115 26-Sep-2021 skrll

Use UVMHIST_CALLARGS


# 1.114 26-Sep-2021 skrll

'\n' is not required in KASSERTMSG either.


# 1.113 26-Sep-2021 skrll

"\n" is not required in KERNHIST


# 1.112 15-Sep-2021 skrll

Use __SHIFTIN. Same code before and after.


# 1.111 12-Sep-2021 skrll

pmap_page_remove: simply and reduce the code size slightly.


# 1.110 09-Sep-2021 skrll

In pmap_icache_sync_range change

for (...) {
...
if (condition) {
// do stuff
}
}

to

for (...) {
...
if (!conditional)
continue;
// do stuff
}

to save on indentation. Same code (modulo register usage) before and
after.


# 1.109 09-Sep-2021 skrll

KNF


Revision tags: thorpej-i2c-spi-conf2-base thorpej-futex2-base thorpej-cfargs2-base cjep_sun2x-base1 cjep_sun2x-base cjep_staticlib_x-base1 thorpej-i2c-spi-conf-base
# 1.108 29-May-2021 skrll

Deal with the pmap limitation of maxproc in a more complete way and
recognise CPUs with only 8bit ASIDs.


Revision tags: cjep_staticlib_x-base
# 1.107 30-Apr-2021 skrll

branches: 1.107.2;
Make the ddb for pmap / pte information pmap agnostic


# 1.106 29-Apr-2021 skrll

Remove some unnecessary tlb invalidate in pmap_growkernel and ASAN shadow
map. Ensure the shadow map mappings are visible to the TLB walkers.


# 1.105 21-Apr-2021 ryo

branches: 1.105.2;
added more attributes of PTE displayed by "ddb>machine pte"


Revision tags: thorpej-cfargs-base
# 1.104 17-Apr-2021 mrg

remove KERNHIST_INIT_STATIC(). it stradles the line between usable
early in boot and broken early in boot by requiring a partly static
structure with another structure that must be present by the time
any uses are performed. theoretically platform code could allocate
a chunk while seting up memory and assign it here, giving a dynamic
sizing for the entry list, but the reality is that all users have
a statically allocated entry list as well.

the existing KERNHIST_LINK_STATIC() is used in conjunction with
KERNHIST_INITIALIZER() instead.

this stops a NULL pointer deref when the _LOG() macro is called
before the storage is linked in, which happens with GCC 10 on OCTEON
with UVMHIST enabled, crashing in very early kernel init.


Revision tags: thorpej-futex-base
# 1.103 09-Mar-2021 ryo

branches: 1.103.2;
fix build error without options DDB.

kvtopte() is referenced from arm/acpi/acpi_machdep.c


# 1.102 13-Feb-2021 ryo

No assignment is needed here.

the loop in pmap_page_remove() always removes the first pv,
and since the list is managed by _pmap_remove_pv(), pp->pp_pv.pv_next always points to the first.


# 1.101 01-Feb-2021 ryo

It is enough to make a page accessible instead of writable.
same fix as r1.76


# 1.100 31-Jan-2021 ryo

implement pmap_remove_all().

The size of struct pv_entry has increased, but speed of kernel build has improved by about 1%
exec and exit should have been improved.


# 1.99 20-Dec-2020 skrll

Improve the English in the previous comment fix.


# 1.98 19-Dec-2020 skrll

Tweak a comment


# 1.97 11-Dec-2020 skrll

s:aarch64/cpufunc.h:arm/cpufunc.h:

a baby step in the grand arm header unification challenge


# 1.96 10-Nov-2020 skrll

AA64 is not MIPS.

Change all KSEG references to directmap


# 1.95 07-Nov-2020 skrll

In pmap_devmap_bootstrap only set pmap_devmap_bootstrap_done if there
is an entry and ALL of the entries have been done. The entry required
for EARLYCONS might not be the first/only one...


# 1.94 01-Nov-2020 jmcneill

branches: 1.94.2;
No need to disable translation table walks in pmap_activate().


# 1.93 22-Oct-2020 skrll

Use the isb macro - missed in previous commit


# 1.92 22-Oct-2020 skrll

Use the dmb/dsb/isb macros... if nothing else they're all now consistent
about the "memory" assembler contraint.

No binary change


# 1.91 28-Sep-2020 skrll

Only set pmap_devmap_bootstrap_done if something gets mapped.

Think acpi_platform_devmap


# 1.90 19-Sep-2020 skrll

Make __md_palloc pmap agnostic (think sys/uvm/pmap)


# 1.89 14-Sep-2020 ryo

PID_MAX is just an initial value (soft maximum). Don't use it for CTASSERT.
defined __HAVE_CPU_MAXPROC to use function cpu_maxproc().

pointed out by mrg@, thanks.


# 1.88 06-Sep-2020 ryo

Fix panic caused by modload. http://mail-index.netbsd.org/port-arm/2020/08/30/msg006960.html

The address space reserved for modules may not be mapped in L1-L3.


# 1.87 14-Aug-2020 skrll

Whitespace


# 1.86 12-Aug-2020 skrll

Part IV of ad's performance improvements for aarch64

- Implement pmap_growkernel(), and update kernel pmap's stats with atomics.

- Then, pmap_kenter_pa() and pmap_kremove() no longer need to allocate
memory nor take pm_lock, because they only modify L3 PTEs.

- Then, pm_lock and pp_lock can be adaptive mutexes at IPL_NONE which are
cheaper than spin mutexes.

- Take the pmap's lock in pmap_extract() if not the kernel's pmap, otherwise
pmap_extract() might see inconsistent state.


# 1.85 09-Aug-2020 skrll

Fix another UVMHIST so it doesn't use %s


# 1.84 16-Jul-2020 skrll

pmapboot_enter simplication
- bootpage_alloc in asm becomes pmapboot_pagealloc in C
- PMAPBOOT_ENTER_NOBLOCK is removed as it's not used
- PMAPBOOT_ENTER_NOOVERWRITE is removed as it's now always on
- physpage_allocator argument is removed as it's always
pmapboot_pagealloc
- Support for EARLYCONS without CONSADDR is removed so that the identity
map for CONSADDR is always known.

For the assembly files:
2 files changed, 40 insertions(+), 89 deletions(-)

LGTM ryo


# 1.83 04-Jul-2020 rin

Use tlen for temporary length variable instead of l, which is usually
used for struct lwp *.

No binary changes.


# 1.82 02-Jul-2020 rin

pmap_procwr(): sync icache even if p != curproc. This fixes applications
like GDB for arm32, that rewrite text of other process.

Thanks to ryo@ for discussion.


# 1.81 02-Jul-2020 rin

Set uvmexp.ncolors appropriately, which is required for some CPU
models with VIPT icache.

Otherwise, alias in virtual address results in inconsistent results,
at least for applications that rewrite text of other process, e.g.,
GDB for arm32.

Also, this hopefully fixes other unexpected failures due to alias.

Confirmed that there's no observable regression in performance;
difference in ``time make -j8'' for GENERIC64 kernel on BCM2837
with and without setting uvmexp.ncolors is within 0.1%.

Thanks to ryo@ for discussion.


# 1.80 27-Jun-2020 rin

Fix typo in name of evcnt(4) counter.


# 1.79 24-Jun-2020 ryo

Fix bug with incorrect range calculation when doing icache sync.
This is called by sysarch(ARM_SYNC_ICACHE) from aarch32 (compat_netbsd32) emul process.

pointed out by rin@, thanks.

XXX pullup-9


# 1.78 14-Jun-2020 ad

- Fix a lock order reversal in pmap_page_protect().

- Make sure pmap is always locked when updating stats; atomics no longer
needed to do that.

- Remove unneeded traversal of pv list in pmap_enter_pv().

- Shrink struct vm_page from 136 to 128 bytes (cache line sized) and struct
pv_entry from 48 to 32 bytes (power of 2 sized).

- Embed a pv_entry in each vm_page. This means PV entries don't need to
be allocated for private anonymous memory / COW pages / most UBC mappings.
Dynamic PV entries are then used only for stuff like shared libraries and
shared memory.

Proposed on port-arm@.


# 1.77 10-Jun-2020 ad

- Wired/resident stats shouldn't covered by PMAPCOUNTERS.
- Rename need_update_pv -> need_enter_pv.

Ok ryo@


# 1.76 01-Jun-2020 ryo

no need to make the PTE writable to do icache_sync, enough to accessible.


# 1.75 15-May-2020 skrll

Use __diagused


# 1.74 15-May-2020 tnn

fix non-diag build


# 1.73 14-May-2020 skrll

Use MUTEX_NODEBUG for PV locks as is commonly done. OK ryo.


# 1.72 13-May-2020 jmcneill

Implement pmap_extract_coherency


Revision tags: bouyer-xenpvh-base2 phil-wifi-20200421 bouyer-xenpvh-base1
# 1.71 18-Apr-2020 skrll

PMAP_DEBUG has been deleted on arm


# 1.70 13-Apr-2020 maxv

Add support for Branch Target Identification (BTI).

On the executable pages that have the GP (Guarded Page) bit, the semantic
of the "br" and "blr" instructions is changed: the CPU expects the first
instruction of the jump/call target to be "bti", and faults if it isn't.

We add the GP bit on the kernel .text pages (and incidentally the .rodata
pages, but we don't care). The compiler adds a "bti c" instruction at the
beginning of each C function. We modify the ENTRY() macros to manually add
"bti c" in the asm functions.

cpuswitch.S needs a specific change: with "br x27" the CPU expects "bti j",
which is bad because the functions begin with "bti c"; switch to "br x16",
for the CPU to accept "bti c".

BTI helps defend against JOP/COP. Tested on Qemu.


Revision tags: phil-wifi-20200411 bouyer-xenpvh-base
# 1.69 08-Apr-2020 ryo

branches: 1.69.2;
use PMAP_PAGE_INIT() to initialize mutex in pmap_page.

VM_MDPAGE_INIT() in pmap_free_pdp() had initialized pp_flags,
so it unintentionally cleared PMAP_PAGE_FLAGS_PV_TRACKED.
use PMAP_PAGE_INIT to avoid using PMAP_PAGE_FLAGS_PV_TRACKED.

pointed out by tnn@, thanks


Revision tags: phil-wifi-20200406
# 1.68 14-Mar-2020 ad

pmap_remove_all(): Return a boolean value to indicate the behaviour. If
true, all mappings have been removed, the pmap is totally cleared out, and
UVM can then avoid doing the work to call pmap_remove() for each map entry.
If false, either nothing has been done, or some helpful arch-specific voodoo
has taken place.


Revision tags: is-mlppp-base
# 1.67 02-Mar-2020 ryo

oops, fix incorrect usage of daif_enable() in my previous commit.


# 1.66 29-Feb-2020 ryo

Fix pmap to work correctly with tagged addresses

- when fault, untag from address before passing to uvm/pmap functions
- pmap_extract() checks more strictly and consider the address tag


# 1.65 29-Feb-2020 ryo

use pmapboot_enter_range()


Revision tags: ad-namecache-base3
# 1.64 10-Feb-2020 ryo

use LIST(3) instead of TAILQ(3) to save one word in struct vm_page and struct pmap.

pointed out by riastradh@. thanks


# 1.63 03-Feb-2020 ryo

add support pmap_pv(9)

Patch originally from jmcneill@. thanks


# 1.62 03-Feb-2020 ryo

separate struct vm_page_md into vm_page_md and pmap_page
for preparation pmap_pv(9)


Revision tags: ad-namecache-base2 ad-namecache-base1
# 1.61 09-Jan-2020 ryo

fix behaviour mmap()/mprotect() when passed only PROT_EXEC.

when mmap()/mprotect() with only PROT_EXEC, syscall will be successful,
but the page actually hadn't been mapped.
it should be mapped with PROT_READ|PROT_EXEC implicitly. (r-x)


Revision tags: ad-namecache-base
# 1.60 30-Dec-2019 skrll

branches: 1.60.2;
Update pmap_map_chunk to allow L[12] block mappings and L3 page mappings


# 1.59 30-Dec-2019 skrll

Remove unnecessary brackets and unwrap a conditional. Same code before
and after.


# 1.58 28-Dec-2019 jmcneill

Do not use Early Write Acknowledge for PCIe I/O and config space.


# 1.57 27-Dec-2019 jmcneill

Enable early write acknowledge for device memory mappings.


# 1.56 19-Dec-2019 skrll

G/C kasan_shadow_map call in pmap_enter

pmap_growkernel calls kasan_shadow_map for KVA


# 1.55 18-Dec-2019 ryo

atomic_add_16() is not used in pmap.c anymore. no need decl here.


# 1.54 18-Dec-2019 ryo

space to tab


# 1.53 14-Dec-2019 skrll

Fix build... wire_count probably doesn't need atomics


# 1.52 13-Dec-2019 skrll

Fix KASAN support by calling kasan_shadow_map in pmap_growkernel


# 1.51 10-Dec-2019 ad

pg->phys_addr -> VM_PAGE_TO_PHYS(pg)


Revision tags: phil-wifi-20191119
# 1.50 14-Nov-2019 maxv

Mark several kASan functions with __nothing, to avoid annoying #ifdefs.
Same as kCSan and kMSan.


# 1.49 14-Nov-2019 maxv

Don't include "opt_kasan.h" when there's already <sys/asan.h> included.


# 1.48 29-Oct-2019 maya

Define PMAP_NEED_PROCWR, providing strategically placed i-cache
synchronization where just-changed memory is about to be executed.

Fixes SIGILLs seen when running Mono 6 on QEMU Cortex-A57.

ok ryo


# 1.47 22-Sep-2019 jmcneill

Disable translation table walks using TTBR0 while changing its value and
when deactivating a pmap. Fixes stability issues on Ampere eMAG CPUs.


# 1.46 20-Sep-2019 ryo

ref/mod bit should be set according to 'flags' argument, not 'prot'. r1.44 was incomplete.


# 1.45 13-Sep-2019 ryo

In pmap_devmap_bootstrap(), cpu_earlydevice_va_p() must not return true until *all* devmap tables have been enabled.
console mapping may be present in the last table.


# 1.44 07-Sep-2019 ryo

- remove incorrect KASSERT. mmap(2) with prot=PROT_WRITE calls pmap_enter(..., PROT_WRITE) internally.
- fix to update page reference flags when only PROT_WRITE or PROT_EXECUTE specified


# 1.43 15-Aug-2019 skrll

Make pmap_db_pte_print more terse so it's quicker on serial consoles


# 1.42 12-Aug-2019 skrll

Use PMAP_DEV in DEVMAP_ENTRY rather than pmap_map_chunk. It's clearer and
means pmap_map_chunk can be made to map other memory types.


Revision tags: netbsd-9-base phil-wifi-20190609
# 1.41 17-May-2019 mrg

branches: 1.41.2;
apply some __diagused.


Revision tags: isaki-audio2-base
# 1.40 08-Apr-2019 ryo

- free empty page tables pages if reach a certain usage.
- need to lock at removing an old pg (_pmap_remove_pv) in _pmap_enter()


# 1.39 06-Apr-2019 ryo

Fix race conditions about pmap_page_protect() and pmap_enter().

while handling same PTE by these functions in same time, there
is a critical path that the number of valid PTEs and wire_count
are inconsistent, and it caused KASSERT.
Need to hold a pv_lock while modifying them.


# 1.38 20-Mar-2019 ryo

spinkle __printflike(), and use PRIxxx


# 1.37 19-Mar-2019 ryo

- add ddb command "machine ttbr" to dump MMU tables.
- tidy up descriptions, usages and messages.


# 1.36 19-Mar-2019 ryo

- free L1-L3 pages that has been emptied by pmap_remove().
- if no memories, pmap_enter will return correctly ENOMEM if PMAP_CANFAIL, or wait until available any memories if !PMAP_CANFAIL.

These changes improves the stability when we use a huge virtual memory spaces with mmap.


# 1.35 06-Feb-2019 ryo

improve pmap_remove
- don't lock/unlock per page in pmap_remove()
- speedup pte lookup for continuous addresses
- bring out pool_cache_put(&_pmap_pv_pool, pv) from lock/unlock section


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226
# 1.34 21-Dec-2018 ryo

- add workaround for Cavium ThunderX errata 27456.
- add cpufuncs table in cpu_info. each cpu clusters may have different erratum. (e.g. big.LITTLE)


Revision tags: pgoyette-compat-1126
# 1.33 01-Nov-2018 maxv

Add kASan support for aarch64. Stack tracking needs more investigation
and will come in a separate commit.

Reviewed by ryo@ jmcneill@ skrll@.


# 1.32 31-Oct-2018 ryo

invalidate icache correctly.
l3pte_executable() should be used for only valid pte.


Revision tags: pgoyette-compat-1020
# 1.31 18-Oct-2018 skrll

Provide generic start code that assumes the MMU is off and caches are
disabled as per the linux booting protocol for ARMv6 and ARMv7 boards.
u-boot image type should be changed to 'linux' for correct behaviour.

The new start code builds a minimal "bootstrap" L1PT with cached access
disabled and uses the same table for all processors. AP startup is
performed in less steps and more code is written in C.

The bootstrap tables and stack are placed into an (orphaned) section
"_init_memory" which is given to uvm when it is no longer used.

Various kernels have been converted to use this code and tested. Some
boards were provided by TNF. Thanks!

The GENERIC kernel now boots on boards using the TEGRA, SUNXI and EXYNOS
kernels. The GENERIC kernel will also work on RPI2 using u-boot.

Thanks to martin@ and aymeric@ for testing on parallella and nanosoc
respectively


# 1.30 14-Oct-2018 skrll

Use __nothing


# 1.29 12-Oct-2018 ryo

add initial support of COMPAT_NETBSD32 on AArch64.
arm ELF32 EABI binaries could be execute in AArch32 state on AArch64. A32 THUMB mode is not supported yet.


# 1.28 12-Oct-2018 ryo

- cleanup checking address ranges with IN_RANGE macro
- change PM_ADDR_CHECK macro to KASSERTMSG
- restore fast lookup cases with IN_RANGE macro for pmap_extract changed in my previous commit.


# 1.27 12-Oct-2018 ryo

rewrite pmap_pte_lookup() to share similar code.


# 1.26 04-Oct-2018 ryo

cleanup locore, and changed the way to map memories during boot.
- add functions bootpage_enter() and bootpage_alloc() to adapt various layout
of physical memory map. especially for 64bit physical memory layout.
pmapboot_alloc() allocates pagetable pages from _end[].
- changed to map only the required amount for PA=VA identity mapping
(kernel image, UART device, and FDT blob) with L2_BLOCK(2Mbyte).
- changing page permission for kernel image, and making KSEG mapping are done
at cpu_kernel_vm_init() instead of at locore.
- optimize PTE entries with PTE Contiguous bit. it is enabled on devmap only for now.

reviewed by skrll@, thanks.


# 1.25 04-Oct-2018 ryo

* define LX_BLKPAG_{OS,ATTR}_* for OS dependent PTE attributes in pmap.h
* cleanup macros


Revision tags: pgoyette-compat-0930
# 1.24 17-Sep-2018 ryo

delete debug printf and KASSERT.


# 1.23 10-Sep-2018 maxv

Replace KDASSERT by panic.


# 1.22 10-Sep-2018 maxv

Rename _pmap_alloc_pdp -> pmap_alloc_pdp, and make it public.


# 1.21 10-Sep-2018 ryo

cleanup aarch64 mpstart and fdt bootstrap
* arm_cpu_hatch_arg is a bad idea. avoid serializing CPU startup, and eliminate arm_cpu_hatch_arg.
in mpstart, resolve own cpu index using array of cpu_mpidr[] (aarch64)
* add support fdt enable-method "spin-table"
* add support fdt enable-method "brcm,bcm2836-smp" (for 32bit RaspberryPi)
* use arm_fdt_cpu_bootstrap() instead of psci_fdt_bootstrap()
* rename "arm/fdt/psci_fdt.h" to "arm/fdt/psci_fdtvar.h" because of conflict of include file for needs-flag
* add devmap for cpu spin-table of raspberrypi3/aarch64
* no need to force hatch APs for raspberrypi3/arm32 ifndef MULTIPROCESSOR.
* fix to work pmap_extract(kerneltext/data/bss) even if before calling pmap_bootstrap

idea to use cpu_mpidr[] by jmcneill@. reviewd by skrll@. thanks.


Revision tags: pgoyette-compat-0906
# 1.20 27-Aug-2018 ryo

need to add VM_PROT_READ when pmap_kenter_pa(va, pa, VM_PROT_WRITE, 0) or pmap_kenter_pa(va, pa, VM_PROT_EXECUTE, 0).
VM_PROT_READ is treated as an access permission inernally.


# 1.19 11-Aug-2018 ryo

change to minimum invalidation of TLB.
specifying not only va but also asid, and not invalidate L0-L2 entry using tlbi_*_ll() if needed.


# 1.18 10-Aug-2018 ryo

treat kernel-exec attr and user-exec attr separately.
kernel cannot execute userland exec page, and user cannot execute kernel page.


# 1.17 06-Aug-2018 ryo

set kernel text/rodata readonly by default.
add function db_write_text() for setting ddb breakpoint.


# 1.16 31-Jul-2018 skrll

Define and use VPRINTF


Revision tags: pgoyette-compat-0728
# 1.15 27-Jul-2018 ryo

changes of pmap.c r1.13 seems to be unstable.
In order to invalidate icache, not to invalidate all icache,
but temporary to make the page writable and invalidate target address only.


# 1.14 24-Jul-2018 ryo

don't call pool_cache_put with locking pmap. pool_cache_put call pmap_kenter_pa internally.
(pool_cache_put_paddr -> pool_cache_put_slow -> pool_get -> pmap_kenter_pa)


# 1.13 23-Jul-2018 ryo

* fix icache invalidations.
* "ic ivau" (aarch64_icache_sync_range) with VA generates permission fault in some situations, therefore use KSEG address for now.


# 1.12 23-Jul-2018 ryo

rather than using flags to resolve nested locks, reserve pool_cache before locking.


# 1.11 21-Jul-2018 ryo

* avoid deadlock. mutex_owned() works only for adaptive lock, therefore we cannot use it for spinlock...
* add more NULL check
* clear pte when pmap_enter() fails


# 1.10 17-Jul-2018 ryo

Use __debugused


# 1.9 17-Jul-2018 christos

Add missing casts, remove unused variables.


# 1.8 09-Jul-2018 ryo

need locks in pmap_kremove() and pmap_fault_fixup()


Revision tags: phil-wifi-base pgoyette-compat-0625 pgoyette-compat-0521
# 1.7 20-May-2018 ryo

branches: 1.7.2;
pmap_enter() must update modified/referenced flags by 'flags' not 'prot'.


# 1.6 16-May-2018 ryo

Fix memory leak. it was leaking one page every pmap_create().
pm->pm_vmlist must be initialized before calling _pmap_alloc_pdp().


Revision tags: pgoyette-compat-0502
# 1.5 29-Apr-2018 ryo

fix KASSERT panic. pv_entry may not be exists in pvlist when pmap_remove().


# 1.4 29-Apr-2018 ryo

delete unused code


# 1.3 27-Apr-2018 ryo

fix instability behavior of bufcache on aarch64.
* fix to return correct ref/mod when PMAP_WIRED.
* changed to keep wired flags in pte instead of pv_entry, and cleanup.


Revision tags: pgoyette-compat-0422 pgoyette-compat-0415 pgoyette-compat-0407
# 1.2 01-Apr-2018 ryo

Add initial support for ARMv8 (AARCH64) (by nisimura@ and ryo@)

- sys/arch/evbarm64 is gone and integrated into sys/arch/evbarm. (by skrll@)
- add support fdt. evbarm/conf/GENERIC64 fdt (bcm2837,sunxi,tegra) based generic 64bit kernel config. (by skrll@, jmcneill@)


Revision tags: netbsd-8-2-RELEASE netbsd-8-1-RELEASE netbsd-8-1-RC1 netbsd-7-2-RELEASE netbsd-8-0-RELEASE netbsd-8-0-RC2 netbsd-8-0-RC1 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 netbsd-7-1-2-RELEASE pgoyette-compat-base netbsd-7-1-1-RELEASE tls-maxphys-base-20171202 matt-nb8-mediatek-base nick-nhusb-base-20170825 perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base pgoyette-localcount-20170320 netbsd-7-1-RELEASE netbsd-7-1-RC2 nick-nhusb-base-20170204 netbsd-7-nhusb-base-20170116 bouyer-socketcan-base pgoyette-localcount-20170107 netbsd-7-1-RC1 nick-nhusb-base-20161204 pgoyette-localcount-20161104 netbsd-7-0-2-RELEASE nick-nhusb-base-20161004 localcount-20160914 netbsd-7-nhusb-base pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907 nick-nhusb-base-20160529 netbsd-7-0-1-RELEASE nick-nhusb-base-20160422 nick-nhusb-base-20160319 nick-nhusb-base-20151226 netbsd-7-0-RELEASE nick-nhusb-base-20150921 netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 nick-nhusb-base-20150606 nick-nhusb-base-20150406 nick-nhusb-base tls-maxphys-base netbsd-7-base
# 1.1 10-Aug-2014 matt

branches: 1.1.4; 1.1.28;
Preliminary files for AARCH64 (64-bit ARM) support.
Enough for a distribution build.


# 1.112 15-Sep-2021 skrll

Use __SHIFTIN. Same code before and after.


# 1.111 12-Sep-2021 skrll

pmap_page_remove: simply and reduce the code size slightly.


# 1.110 09-Sep-2021 skrll

In pmap_icache_sync_range change

for (...) {
...
if (condition) {
// do stuff
}
}

to

for (...) {
...
if (!conditional)
continue;
// do stuff
}

to save on indentation. Same code (modulo register usage) before and
after.


# 1.109 09-Sep-2021 skrll

KNF


Revision tags: thorpej-i2c-spi-conf2-base thorpej-futex2-base thorpej-cfargs2-base cjep_sun2x-base1 cjep_sun2x-base cjep_staticlib_x-base1 thorpej-i2c-spi-conf-base
# 1.108 29-May-2021 skrll

Deal with the pmap limitation of maxproc in a more complete way and
recognise CPUs with only 8bit ASIDs.


Revision tags: cjep_staticlib_x-base
# 1.107 30-Apr-2021 skrll

branches: 1.107.2;
Make the ddb for pmap / pte information pmap agnostic


# 1.106 29-Apr-2021 skrll

Remove some unnecessary tlb invalidate in pmap_growkernel and ASAN shadow
map. Ensure the shadow map mappings are visible to the TLB walkers.


# 1.105 21-Apr-2021 ryo

branches: 1.105.2;
added more attributes of PTE displayed by "ddb>machine pte"


Revision tags: thorpej-cfargs-base
# 1.104 17-Apr-2021 mrg

remove KERNHIST_INIT_STATIC(). it stradles the line between usable
early in boot and broken early in boot by requiring a partly static
structure with another structure that must be present by the time
any uses are performed. theoretically platform code could allocate
a chunk while seting up memory and assign it here, giving a dynamic
sizing for the entry list, but the reality is that all users have
a statically allocated entry list as well.

the existing KERNHIST_LINK_STATIC() is used in conjunction with
KERNHIST_INITIALIZER() instead.

this stops a NULL pointer deref when the _LOG() macro is called
before the storage is linked in, which happens with GCC 10 on OCTEON
with UVMHIST enabled, crashing in very early kernel init.


Revision tags: thorpej-futex-base
# 1.103 09-Mar-2021 ryo

branches: 1.103.2;
fix build error without options DDB.

kvtopte() is referenced from arm/acpi/acpi_machdep.c


# 1.102 13-Feb-2021 ryo

No assignment is needed here.

the loop in pmap_page_remove() always removes the first pv,
and since the list is managed by _pmap_remove_pv(), pp->pp_pv.pv_next always points to the first.


# 1.101 01-Feb-2021 ryo

It is enough to make a page accessible instead of writable.
same fix as r1.76


# 1.100 31-Jan-2021 ryo

implement pmap_remove_all().

The size of struct pv_entry has increased, but speed of kernel build has improved by about 1%
exec and exit should have been improved.


# 1.99 20-Dec-2020 skrll

Improve the English in the previous comment fix.


# 1.98 19-Dec-2020 skrll

Tweak a comment


# 1.97 11-Dec-2020 skrll

s:aarch64/cpufunc.h:arm/cpufunc.h:

a baby step in the grand arm header unification challenge


# 1.96 10-Nov-2020 skrll

AA64 is not MIPS.

Change all KSEG references to directmap


# 1.95 07-Nov-2020 skrll

In pmap_devmap_bootstrap only set pmap_devmap_bootstrap_done if there
is an entry and ALL of the entries have been done. The entry required
for EARLYCONS might not be the first/only one...


# 1.94 01-Nov-2020 jmcneill

branches: 1.94.2;
No need to disable translation table walks in pmap_activate().


# 1.93 22-Oct-2020 skrll

Use the isb macro - missed in previous commit


# 1.92 22-Oct-2020 skrll

Use the dmb/dsb/isb macros... if nothing else they're all now consistent
about the "memory" assembler contraint.

No binary change


# 1.91 28-Sep-2020 skrll

Only set pmap_devmap_bootstrap_done if something gets mapped.

Think acpi_platform_devmap


# 1.90 19-Sep-2020 skrll

Make __md_palloc pmap agnostic (think sys/uvm/pmap)


# 1.89 14-Sep-2020 ryo

PID_MAX is just an initial value (soft maximum). Don't use it for CTASSERT.
defined __HAVE_CPU_MAXPROC to use function cpu_maxproc().

pointed out by mrg@, thanks.


# 1.88 06-Sep-2020 ryo

Fix panic caused by modload. http://mail-index.netbsd.org/port-arm/2020/08/30/msg006960.html

The address space reserved for modules may not be mapped in L1-L3.


# 1.87 14-Aug-2020 skrll

Whitespace


# 1.86 12-Aug-2020 skrll

Part IV of ad's performance improvements for aarch64

- Implement pmap_growkernel(), and update kernel pmap's stats with atomics.

- Then, pmap_kenter_pa() and pmap_kremove() no longer need to allocate
memory nor take pm_lock, because they only modify L3 PTEs.

- Then, pm_lock and pp_lock can be adaptive mutexes at IPL_NONE which are
cheaper than spin mutexes.

- Take the pmap's lock in pmap_extract() if not the kernel's pmap, otherwise
pmap_extract() might see inconsistent state.


# 1.85 09-Aug-2020 skrll

Fix another UVMHIST so it doesn't use %s


# 1.84 16-Jul-2020 skrll

pmapboot_enter simplication
- bootpage_alloc in asm becomes pmapboot_pagealloc in C
- PMAPBOOT_ENTER_NOBLOCK is removed as it's not used
- PMAPBOOT_ENTER_NOOVERWRITE is removed as it's now always on
- physpage_allocator argument is removed as it's always
pmapboot_pagealloc
- Support for EARLYCONS without CONSADDR is removed so that the identity
map for CONSADDR is always known.

For the assembly files:
2 files changed, 40 insertions(+), 89 deletions(-)

LGTM ryo


# 1.83 04-Jul-2020 rin

Use tlen for temporary length variable instead of l, which is usually
used for struct lwp *.

No binary changes.


# 1.82 02-Jul-2020 rin

pmap_procwr(): sync icache even if p != curproc. This fixes applications
like GDB for arm32, that rewrite text of other process.

Thanks to ryo@ for discussion.


# 1.81 02-Jul-2020 rin

Set uvmexp.ncolors appropriately, which is required for some CPU
models with VIPT icache.

Otherwise, alias in virtual address results in inconsistent results,
at least for applications that rewrite text of other process, e.g.,
GDB for arm32.

Also, this hopefully fixes other unexpected failures due to alias.

Confirmed that there's no observable regression in performance;
difference in ``time make -j8'' for GENERIC64 kernel on BCM2837
with and without setting uvmexp.ncolors is within 0.1%.

Thanks to ryo@ for discussion.


# 1.80 27-Jun-2020 rin

Fix typo in name of evcnt(4) counter.


# 1.79 24-Jun-2020 ryo

Fix bug with incorrect range calculation when doing icache sync.
This is called by sysarch(ARM_SYNC_ICACHE) from aarch32 (compat_netbsd32) emul process.

pointed out by rin@, thanks.

XXX pullup-9


# 1.78 14-Jun-2020 ad

- Fix a lock order reversal in pmap_page_protect().

- Make sure pmap is always locked when updating stats; atomics no longer
needed to do that.

- Remove unneeded traversal of pv list in pmap_enter_pv().

- Shrink struct vm_page from 136 to 128 bytes (cache line sized) and struct
pv_entry from 48 to 32 bytes (power of 2 sized).

- Embed a pv_entry in each vm_page. This means PV entries don't need to
be allocated for private anonymous memory / COW pages / most UBC mappings.
Dynamic PV entries are then used only for stuff like shared libraries and
shared memory.

Proposed on port-arm@.


# 1.77 10-Jun-2020 ad

- Wired/resident stats shouldn't covered by PMAPCOUNTERS.
- Rename need_update_pv -> need_enter_pv.

Ok ryo@


# 1.76 01-Jun-2020 ryo

no need to make the PTE writable to do icache_sync, enough to accessible.


# 1.75 15-May-2020 skrll

Use __diagused


# 1.74 15-May-2020 tnn

fix non-diag build


# 1.73 14-May-2020 skrll

Use MUTEX_NODEBUG for PV locks as is commonly done. OK ryo.


# 1.72 13-May-2020 jmcneill

Implement pmap_extract_coherency


Revision tags: bouyer-xenpvh-base2 phil-wifi-20200421 bouyer-xenpvh-base1
# 1.71 18-Apr-2020 skrll

PMAP_DEBUG has been deleted on arm


# 1.70 13-Apr-2020 maxv

Add support for Branch Target Identification (BTI).

On the executable pages that have the GP (Guarded Page) bit, the semantic
of the "br" and "blr" instructions is changed: the CPU expects the first
instruction of the jump/call target to be "bti", and faults if it isn't.

We add the GP bit on the kernel .text pages (and incidentally the .rodata
pages, but we don't care). The compiler adds a "bti c" instruction at the
beginning of each C function. We modify the ENTRY() macros to manually add
"bti c" in the asm functions.

cpuswitch.S needs a specific change: with "br x27" the CPU expects "bti j",
which is bad because the functions begin with "bti c"; switch to "br x16",
for the CPU to accept "bti c".

BTI helps defend against JOP/COP. Tested on Qemu.


Revision tags: phil-wifi-20200411 bouyer-xenpvh-base
# 1.69 08-Apr-2020 ryo

branches: 1.69.2;
use PMAP_PAGE_INIT() to initialize mutex in pmap_page.

VM_MDPAGE_INIT() in pmap_free_pdp() had initialized pp_flags,
so it unintentionally cleared PMAP_PAGE_FLAGS_PV_TRACKED.
use PMAP_PAGE_INIT to avoid using PMAP_PAGE_FLAGS_PV_TRACKED.

pointed out by tnn@, thanks


Revision tags: phil-wifi-20200406
# 1.68 14-Mar-2020 ad

pmap_remove_all(): Return a boolean value to indicate the behaviour. If
true, all mappings have been removed, the pmap is totally cleared out, and
UVM can then avoid doing the work to call pmap_remove() for each map entry.
If false, either nothing has been done, or some helpful arch-specific voodoo
has taken place.


Revision tags: is-mlppp-base
# 1.67 02-Mar-2020 ryo

oops, fix incorrect usage of daif_enable() in my previous commit.


# 1.66 29-Feb-2020 ryo

Fix pmap to work correctly with tagged addresses

- when fault, untag from address before passing to uvm/pmap functions
- pmap_extract() checks more strictly and consider the address tag


# 1.65 29-Feb-2020 ryo

use pmapboot_enter_range()


Revision tags: ad-namecache-base3
# 1.64 10-Feb-2020 ryo

use LIST(3) instead of TAILQ(3) to save one word in struct vm_page and struct pmap.

pointed out by riastradh@. thanks


# 1.63 03-Feb-2020 ryo

add support pmap_pv(9)

Patch originally from jmcneill@. thanks


# 1.62 03-Feb-2020 ryo

separate struct vm_page_md into vm_page_md and pmap_page
for preparation pmap_pv(9)


Revision tags: ad-namecache-base2 ad-namecache-base1
# 1.61 09-Jan-2020 ryo

fix behaviour mmap()/mprotect() when passed only PROT_EXEC.

when mmap()/mprotect() with only PROT_EXEC, syscall will be successful,
but the page actually hadn't been mapped.
it should be mapped with PROT_READ|PROT_EXEC implicitly. (r-x)


Revision tags: ad-namecache-base
# 1.60 30-Dec-2019 skrll

branches: 1.60.2;
Update pmap_map_chunk to allow L[12] block mappings and L3 page mappings


# 1.59 30-Dec-2019 skrll

Remove unnecessary brackets and unwrap a conditional. Same code before
and after.


# 1.58 28-Dec-2019 jmcneill

Do not use Early Write Acknowledge for PCIe I/O and config space.


# 1.57 27-Dec-2019 jmcneill

Enable early write acknowledge for device memory mappings.


# 1.56 19-Dec-2019 skrll

G/C kasan_shadow_map call in pmap_enter

pmap_growkernel calls kasan_shadow_map for KVA


# 1.55 18-Dec-2019 ryo

atomic_add_16() is not used in pmap.c anymore. no need decl here.


# 1.54 18-Dec-2019 ryo

space to tab


# 1.53 14-Dec-2019 skrll

Fix build... wire_count probably doesn't need atomics


# 1.52 13-Dec-2019 skrll

Fix KASAN support by calling kasan_shadow_map in pmap_growkernel


# 1.51 10-Dec-2019 ad

pg->phys_addr -> VM_PAGE_TO_PHYS(pg)


Revision tags: phil-wifi-20191119
# 1.50 14-Nov-2019 maxv

Mark several kASan functions with __nothing, to avoid annoying #ifdefs.
Same as kCSan and kMSan.


# 1.49 14-Nov-2019 maxv

Don't include "opt_kasan.h" when there's already <sys/asan.h> included.


# 1.48 29-Oct-2019 maya

Define PMAP_NEED_PROCWR, providing strategically placed i-cache
synchronization where just-changed memory is about to be executed.

Fixes SIGILLs seen when running Mono 6 on QEMU Cortex-A57.

ok ryo


# 1.47 22-Sep-2019 jmcneill

Disable translation table walks using TTBR0 while changing its value and
when deactivating a pmap. Fixes stability issues on Ampere eMAG CPUs.


# 1.46 20-Sep-2019 ryo

ref/mod bit should be set according to 'flags' argument, not 'prot'. r1.44 was incomplete.


# 1.45 13-Sep-2019 ryo

In pmap_devmap_bootstrap(), cpu_earlydevice_va_p() must not return true until *all* devmap tables have been enabled.
console mapping may be present in the last table.


# 1.44 07-Sep-2019 ryo

- remove incorrect KASSERT. mmap(2) with prot=PROT_WRITE calls pmap_enter(..., PROT_WRITE) internally.
- fix to update page reference flags when only PROT_WRITE or PROT_EXECUTE specified


# 1.43 15-Aug-2019 skrll

Make pmap_db_pte_print more terse so it's quicker on serial consoles


# 1.42 12-Aug-2019 skrll

Use PMAP_DEV in DEVMAP_ENTRY rather than pmap_map_chunk. It's clearer and
means pmap_map_chunk can be made to map other memory types.


Revision tags: netbsd-9-base phil-wifi-20190609
# 1.41 17-May-2019 mrg

branches: 1.41.2;
apply some __diagused.


Revision tags: isaki-audio2-base
# 1.40 08-Apr-2019 ryo

- free empty page tables pages if reach a certain usage.
- need to lock at removing an old pg (_pmap_remove_pv) in _pmap_enter()


# 1.39 06-Apr-2019 ryo

Fix race conditions about pmap_page_protect() and pmap_enter().

while handling same PTE by these functions in same time, there
is a critical path that the number of valid PTEs and wire_count
are inconsistent, and it caused KASSERT.
Need to hold a pv_lock while modifying them.


# 1.38 20-Mar-2019 ryo

spinkle __printflike(), and use PRIxxx


# 1.37 19-Mar-2019 ryo

- add ddb command "machine ttbr" to dump MMU tables.
- tidy up descriptions, usages and messages.


# 1.36 19-Mar-2019 ryo

- free L1-L3 pages that has been emptied by pmap_remove().
- if no memories, pmap_enter will return correctly ENOMEM if PMAP_CANFAIL, or wait until available any memories if !PMAP_CANFAIL.

These changes improves the stability when we use a huge virtual memory spaces with mmap.


# 1.35 06-Feb-2019 ryo

improve pmap_remove
- don't lock/unlock per page in pmap_remove()
- speedup pte lookup for continuous addresses
- bring out pool_cache_put(&_pmap_pv_pool, pv) from lock/unlock section


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226
# 1.34 21-Dec-2018 ryo

- add workaround for Cavium ThunderX errata 27456.
- add cpufuncs table in cpu_info. each cpu clusters may have different erratum. (e.g. big.LITTLE)


Revision tags: pgoyette-compat-1126
# 1.33 01-Nov-2018 maxv

Add kASan support for aarch64. Stack tracking needs more investigation
and will come in a separate commit.

Reviewed by ryo@ jmcneill@ skrll@.


# 1.32 31-Oct-2018 ryo

invalidate icache correctly.
l3pte_executable() should be used for only valid pte.


Revision tags: pgoyette-compat-1020
# 1.31 18-Oct-2018 skrll

Provide generic start code that assumes the MMU is off and caches are
disabled as per the linux booting protocol for ARMv6 and ARMv7 boards.
u-boot image type should be changed to 'linux' for correct behaviour.

The new start code builds a minimal "bootstrap" L1PT with cached access
disabled and uses the same table for all processors. AP startup is
performed in less steps and more code is written in C.

The bootstrap tables and stack are placed into an (orphaned) section
"_init_memory" which is given to uvm when it is no longer used.

Various kernels have been converted to use this code and tested. Some
boards were provided by TNF. Thanks!

The GENERIC kernel now boots on boards using the TEGRA, SUNXI and EXYNOS
kernels. The GENERIC kernel will also work on RPI2 using u-boot.

Thanks to martin@ and aymeric@ for testing on parallella and nanosoc
respectively


# 1.30 14-Oct-2018 skrll

Use __nothing


# 1.29 12-Oct-2018 ryo

add initial support of COMPAT_NETBSD32 on AArch64.
arm ELF32 EABI binaries could be execute in AArch32 state on AArch64. A32 THUMB mode is not supported yet.


# 1.28 12-Oct-2018 ryo

- cleanup checking address ranges with IN_RANGE macro
- change PM_ADDR_CHECK macro to KASSERTMSG
- restore fast lookup cases with IN_RANGE macro for pmap_extract changed in my previous commit.


# 1.27 12-Oct-2018 ryo

rewrite pmap_pte_lookup() to share similar code.


# 1.26 04-Oct-2018 ryo

cleanup locore, and changed the way to map memories during boot.
- add functions bootpage_enter() and bootpage_alloc() to adapt various layout
of physical memory map. especially for 64bit physical memory layout.
pmapboot_alloc() allocates pagetable pages from _end[].
- changed to map only the required amount for PA=VA identity mapping
(kernel image, UART device, and FDT blob) with L2_BLOCK(2Mbyte).
- changing page permission for kernel image, and making KSEG mapping are done
at cpu_kernel_vm_init() instead of at locore.
- optimize PTE entries with PTE Contiguous bit. it is enabled on devmap only for now.

reviewed by skrll@, thanks.


# 1.25 04-Oct-2018 ryo

* define LX_BLKPAG_{OS,ATTR}_* for OS dependent PTE attributes in pmap.h
* cleanup macros


Revision tags: pgoyette-compat-0930
# 1.24 17-Sep-2018 ryo

delete debug printf and KASSERT.


# 1.23 10-Sep-2018 maxv

Replace KDASSERT by panic.


# 1.22 10-Sep-2018 maxv

Rename _pmap_alloc_pdp -> pmap_alloc_pdp, and make it public.


# 1.21 10-Sep-2018 ryo

cleanup aarch64 mpstart and fdt bootstrap
* arm_cpu_hatch_arg is a bad idea. avoid serializing CPU startup, and eliminate arm_cpu_hatch_arg.
in mpstart, resolve own cpu index using array of cpu_mpidr[] (aarch64)
* add support fdt enable-method "spin-table"
* add support fdt enable-method "brcm,bcm2836-smp" (for 32bit RaspberryPi)
* use arm_fdt_cpu_bootstrap() instead of psci_fdt_bootstrap()
* rename "arm/fdt/psci_fdt.h" to "arm/fdt/psci_fdtvar.h" because of conflict of include file for needs-flag
* add devmap for cpu spin-table of raspberrypi3/aarch64
* no need to force hatch APs for raspberrypi3/arm32 ifndef MULTIPROCESSOR.
* fix to work pmap_extract(kerneltext/data/bss) even if before calling pmap_bootstrap

idea to use cpu_mpidr[] by jmcneill@. reviewd by skrll@. thanks.


Revision tags: pgoyette-compat-0906
# 1.20 27-Aug-2018 ryo

need to add VM_PROT_READ when pmap_kenter_pa(va, pa, VM_PROT_WRITE, 0) or pmap_kenter_pa(va, pa, VM_PROT_EXECUTE, 0).
VM_PROT_READ is treated as an access permission inernally.


# 1.19 11-Aug-2018 ryo

change to minimum invalidation of TLB.
specifying not only va but also asid, and not invalidate L0-L2 entry using tlbi_*_ll() if needed.


# 1.18 10-Aug-2018 ryo

treat kernel-exec attr and user-exec attr separately.
kernel cannot execute userland exec page, and user cannot execute kernel page.


# 1.17 06-Aug-2018 ryo

set kernel text/rodata readonly by default.
add function db_write_text() for setting ddb breakpoint.


# 1.16 31-Jul-2018 skrll

Define and use VPRINTF


Revision tags: pgoyette-compat-0728
# 1.15 27-Jul-2018 ryo

changes of pmap.c r1.13 seems to be unstable.
In order to invalidate icache, not to invalidate all icache,
but temporary to make the page writable and invalidate target address only.


# 1.14 24-Jul-2018 ryo

don't call pool_cache_put with locking pmap. pool_cache_put call pmap_kenter_pa internally.
(pool_cache_put_paddr -> pool_cache_put_slow -> pool_get -> pmap_kenter_pa)


# 1.13 23-Jul-2018 ryo

* fix icache invalidations.
* "ic ivau" (aarch64_icache_sync_range) with VA generates permission fault in some situations, therefore use KSEG address for now.


# 1.12 23-Jul-2018 ryo

rather than using flags to resolve nested locks, reserve pool_cache before locking.


# 1.11 21-Jul-2018 ryo

* avoid deadlock. mutex_owned() works only for adaptive lock, therefore we cannot use it for spinlock...
* add more NULL check
* clear pte when pmap_enter() fails


# 1.10 17-Jul-2018 ryo

Use __debugused


# 1.9 17-Jul-2018 christos

Add missing casts, remove unused variables.


# 1.8 09-Jul-2018 ryo

need locks in pmap_kremove() and pmap_fault_fixup()


Revision tags: phil-wifi-base pgoyette-compat-0625 pgoyette-compat-0521
# 1.7 20-May-2018 ryo

branches: 1.7.2;
pmap_enter() must update modified/referenced flags by 'flags' not 'prot'.


# 1.6 16-May-2018 ryo

Fix memory leak. it was leaking one page every pmap_create().
pm->pm_vmlist must be initialized before calling _pmap_alloc_pdp().


Revision tags: pgoyette-compat-0502
# 1.5 29-Apr-2018 ryo

fix KASSERT panic. pv_entry may not be exists in pvlist when pmap_remove().


# 1.4 29-Apr-2018 ryo

delete unused code


# 1.3 27-Apr-2018 ryo

fix instability behavior of bufcache on aarch64.
* fix to return correct ref/mod when PMAP_WIRED.
* changed to keep wired flags in pte instead of pv_entry, and cleanup.


Revision tags: pgoyette-compat-0422 pgoyette-compat-0415 pgoyette-compat-0407
# 1.2 01-Apr-2018 ryo

Add initial support for ARMv8 (AARCH64) (by nisimura@ and ryo@)

- sys/arch/evbarm64 is gone and integrated into sys/arch/evbarm. (by skrll@)
- add support fdt. evbarm/conf/GENERIC64 fdt (bcm2837,sunxi,tegra) based generic 64bit kernel config. (by skrll@, jmcneill@)


Revision tags: netbsd-8-2-RELEASE netbsd-8-1-RELEASE netbsd-8-1-RC1 netbsd-7-2-RELEASE netbsd-8-0-RELEASE netbsd-8-0-RC2 netbsd-8-0-RC1 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 netbsd-7-1-2-RELEASE pgoyette-compat-base netbsd-7-1-1-RELEASE tls-maxphys-base-20171202 matt-nb8-mediatek-base nick-nhusb-base-20170825 perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base pgoyette-localcount-20170320 netbsd-7-1-RELEASE netbsd-7-1-RC2 nick-nhusb-base-20170204 netbsd-7-nhusb-base-20170116 bouyer-socketcan-base pgoyette-localcount-20170107 netbsd-7-1-RC1 nick-nhusb-base-20161204 pgoyette-localcount-20161104 netbsd-7-0-2-RELEASE nick-nhusb-base-20161004 localcount-20160914 netbsd-7-nhusb-base pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907 nick-nhusb-base-20160529 netbsd-7-0-1-RELEASE nick-nhusb-base-20160422 nick-nhusb-base-20160319 nick-nhusb-base-20151226 netbsd-7-0-RELEASE nick-nhusb-base-20150921 netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 nick-nhusb-base-20150606 nick-nhusb-base-20150406 nick-nhusb-base tls-maxphys-base netbsd-7-base
# 1.1 10-Aug-2014 matt

branches: 1.1.4; 1.1.28;
Preliminary files for AARCH64 (64-bit ARM) support.
Enough for a distribution build.


# 1.111 12-Sep-2021 skrll

pmap_page_remove: simply and reduce the code size slightly.


# 1.110 09-Sep-2021 skrll

In pmap_icache_sync_range change

for (...) {
...
if (condition) {
// do stuff
}
}

to

for (...) {
...
if (!conditional)
continue;
// do stuff
}

to save on indentation. Same code (modulo register usage) before and
after.


# 1.109 09-Sep-2021 skrll

KNF


Revision tags: thorpej-i2c-spi-conf2-base thorpej-futex2-base thorpej-cfargs2-base cjep_sun2x-base1 cjep_sun2x-base cjep_staticlib_x-base1 thorpej-i2c-spi-conf-base
# 1.108 29-May-2021 skrll

Deal with the pmap limitation of maxproc in a more complete way and
recognise CPUs with only 8bit ASIDs.


Revision tags: cjep_staticlib_x-base
# 1.107 30-Apr-2021 skrll

branches: 1.107.2;
Make the ddb for pmap / pte information pmap agnostic


# 1.106 29-Apr-2021 skrll

Remove some unnecessary tlb invalidate in pmap_growkernel and ASAN shadow
map. Ensure the shadow map mappings are visible to the TLB walkers.


# 1.105 21-Apr-2021 ryo

branches: 1.105.2;
added more attributes of PTE displayed by "ddb>machine pte"


Revision tags: thorpej-cfargs-base
# 1.104 17-Apr-2021 mrg

remove KERNHIST_INIT_STATIC(). it stradles the line between usable
early in boot and broken early in boot by requiring a partly static
structure with another structure that must be present by the time
any uses are performed. theoretically platform code could allocate
a chunk while seting up memory and assign it here, giving a dynamic
sizing for the entry list, but the reality is that all users have
a statically allocated entry list as well.

the existing KERNHIST_LINK_STATIC() is used in conjunction with
KERNHIST_INITIALIZER() instead.

this stops a NULL pointer deref when the _LOG() macro is called
before the storage is linked in, which happens with GCC 10 on OCTEON
with UVMHIST enabled, crashing in very early kernel init.


Revision tags: thorpej-futex-base
# 1.103 09-Mar-2021 ryo

branches: 1.103.2;
fix build error without options DDB.

kvtopte() is referenced from arm/acpi/acpi_machdep.c


# 1.102 13-Feb-2021 ryo

No assignment is needed here.

the loop in pmap_page_remove() always removes the first pv,
and since the list is managed by _pmap_remove_pv(), pp->pp_pv.pv_next always points to the first.


# 1.101 01-Feb-2021 ryo

It is enough to make a page accessible instead of writable.
same fix as r1.76


# 1.100 31-Jan-2021 ryo

implement pmap_remove_all().

The size of struct pv_entry has increased, but speed of kernel build has improved by about 1%
exec and exit should have been improved.


# 1.99 20-Dec-2020 skrll

Improve the English in the previous comment fix.


# 1.98 19-Dec-2020 skrll

Tweak a comment


# 1.97 11-Dec-2020 skrll

s:aarch64/cpufunc.h:arm/cpufunc.h:

a baby step in the grand arm header unification challenge


# 1.96 10-Nov-2020 skrll

AA64 is not MIPS.

Change all KSEG references to directmap


# 1.95 07-Nov-2020 skrll

In pmap_devmap_bootstrap only set pmap_devmap_bootstrap_done if there
is an entry and ALL of the entries have been done. The entry required
for EARLYCONS might not be the first/only one...


# 1.94 01-Nov-2020 jmcneill

branches: 1.94.2;
No need to disable translation table walks in pmap_activate().


# 1.93 22-Oct-2020 skrll

Use the isb macro - missed in previous commit


# 1.92 22-Oct-2020 skrll

Use the dmb/dsb/isb macros... if nothing else they're all now consistent
about the "memory" assembler contraint.

No binary change


# 1.91 28-Sep-2020 skrll

Only set pmap_devmap_bootstrap_done if something gets mapped.

Think acpi_platform_devmap


# 1.90 19-Sep-2020 skrll

Make __md_palloc pmap agnostic (think sys/uvm/pmap)


# 1.89 14-Sep-2020 ryo

PID_MAX is just an initial value (soft maximum). Don't use it for CTASSERT.
defined __HAVE_CPU_MAXPROC to use function cpu_maxproc().

pointed out by mrg@, thanks.


# 1.88 06-Sep-2020 ryo

Fix panic caused by modload. http://mail-index.netbsd.org/port-arm/2020/08/30/msg006960.html

The address space reserved for modules may not be mapped in L1-L3.


# 1.87 14-Aug-2020 skrll

Whitespace


# 1.86 12-Aug-2020 skrll

Part IV of ad's performance improvements for aarch64

- Implement pmap_growkernel(), and update kernel pmap's stats with atomics.

- Then, pmap_kenter_pa() and pmap_kremove() no longer need to allocate
memory nor take pm_lock, because they only modify L3 PTEs.

- Then, pm_lock and pp_lock can be adaptive mutexes at IPL_NONE which are
cheaper than spin mutexes.

- Take the pmap's lock in pmap_extract() if not the kernel's pmap, otherwise
pmap_extract() might see inconsistent state.


# 1.85 09-Aug-2020 skrll

Fix another UVMHIST so it doesn't use %s


# 1.84 16-Jul-2020 skrll

pmapboot_enter simplication
- bootpage_alloc in asm becomes pmapboot_pagealloc in C
- PMAPBOOT_ENTER_NOBLOCK is removed as it's not used
- PMAPBOOT_ENTER_NOOVERWRITE is removed as it's now always on
- physpage_allocator argument is removed as it's always
pmapboot_pagealloc
- Support for EARLYCONS without CONSADDR is removed so that the identity
map for CONSADDR is always known.

For the assembly files:
2 files changed, 40 insertions(+), 89 deletions(-)

LGTM ryo


# 1.83 04-Jul-2020 rin

Use tlen for temporary length variable instead of l, which is usually
used for struct lwp *.

No binary changes.


# 1.82 02-Jul-2020 rin

pmap_procwr(): sync icache even if p != curproc. This fixes applications
like GDB for arm32, that rewrite text of other process.

Thanks to ryo@ for discussion.


# 1.81 02-Jul-2020 rin

Set uvmexp.ncolors appropriately, which is required for some CPU
models with VIPT icache.

Otherwise, alias in virtual address results in inconsistent results,
at least for applications that rewrite text of other process, e.g.,
GDB for arm32.

Also, this hopefully fixes other unexpected failures due to alias.

Confirmed that there's no observable regression in performance;
difference in ``time make -j8'' for GENERIC64 kernel on BCM2837
with and without setting uvmexp.ncolors is within 0.1%.

Thanks to ryo@ for discussion.


# 1.80 27-Jun-2020 rin

Fix typo in name of evcnt(4) counter.


# 1.79 24-Jun-2020 ryo

Fix bug with incorrect range calculation when doing icache sync.
This is called by sysarch(ARM_SYNC_ICACHE) from aarch32 (compat_netbsd32) emul process.

pointed out by rin@, thanks.

XXX pullup-9


# 1.78 14-Jun-2020 ad

- Fix a lock order reversal in pmap_page_protect().

- Make sure pmap is always locked when updating stats; atomics no longer
needed to do that.

- Remove unneeded traversal of pv list in pmap_enter_pv().

- Shrink struct vm_page from 136 to 128 bytes (cache line sized) and struct
pv_entry from 48 to 32 bytes (power of 2 sized).

- Embed a pv_entry in each vm_page. This means PV entries don't need to
be allocated for private anonymous memory / COW pages / most UBC mappings.
Dynamic PV entries are then used only for stuff like shared libraries and
shared memory.

Proposed on port-arm@.


# 1.77 10-Jun-2020 ad

- Wired/resident stats shouldn't covered by PMAPCOUNTERS.
- Rename need_update_pv -> need_enter_pv.

Ok ryo@


# 1.76 01-Jun-2020 ryo

no need to make the PTE writable to do icache_sync, enough to accessible.


# 1.75 15-May-2020 skrll

Use __diagused


# 1.74 15-May-2020 tnn

fix non-diag build


# 1.73 14-May-2020 skrll

Use MUTEX_NODEBUG for PV locks as is commonly done. OK ryo.


# 1.72 13-May-2020 jmcneill

Implement pmap_extract_coherency


Revision tags: bouyer-xenpvh-base2 phil-wifi-20200421 bouyer-xenpvh-base1
# 1.71 18-Apr-2020 skrll

PMAP_DEBUG has been deleted on arm


# 1.70 13-Apr-2020 maxv

Add support for Branch Target Identification (BTI).

On the executable pages that have the GP (Guarded Page) bit, the semantic
of the "br" and "blr" instructions is changed: the CPU expects the first
instruction of the jump/call target to be "bti", and faults if it isn't.

We add the GP bit on the kernel .text pages (and incidentally the .rodata
pages, but we don't care). The compiler adds a "bti c" instruction at the
beginning of each C function. We modify the ENTRY() macros to manually add
"bti c" in the asm functions.

cpuswitch.S needs a specific change: with "br x27" the CPU expects "bti j",
which is bad because the functions begin with "bti c"; switch to "br x16",
for the CPU to accept "bti c".

BTI helps defend against JOP/COP. Tested on Qemu.


Revision tags: phil-wifi-20200411 bouyer-xenpvh-base
# 1.69 08-Apr-2020 ryo

branches: 1.69.2;
use PMAP_PAGE_INIT() to initialize mutex in pmap_page.

VM_MDPAGE_INIT() in pmap_free_pdp() had initialized pp_flags,
so it unintentionally cleared PMAP_PAGE_FLAGS_PV_TRACKED.
use PMAP_PAGE_INIT to avoid using PMAP_PAGE_FLAGS_PV_TRACKED.

pointed out by tnn@, thanks


Revision tags: phil-wifi-20200406
# 1.68 14-Mar-2020 ad

pmap_remove_all(): Return a boolean value to indicate the behaviour. If
true, all mappings have been removed, the pmap is totally cleared out, and
UVM can then avoid doing the work to call pmap_remove() for each map entry.
If false, either nothing has been done, or some helpful arch-specific voodoo
has taken place.


Revision tags: is-mlppp-base
# 1.67 02-Mar-2020 ryo

oops, fix incorrect usage of daif_enable() in my previous commit.


# 1.66 29-Feb-2020 ryo

Fix pmap to work correctly with tagged addresses

- when fault, untag from address before passing to uvm/pmap functions
- pmap_extract() checks more strictly and consider the address tag


# 1.65 29-Feb-2020 ryo

use pmapboot_enter_range()


Revision tags: ad-namecache-base3
# 1.64 10-Feb-2020 ryo

use LIST(3) instead of TAILQ(3) to save one word in struct vm_page and struct pmap.

pointed out by riastradh@. thanks


# 1.63 03-Feb-2020 ryo

add support pmap_pv(9)

Patch originally from jmcneill@. thanks


# 1.62 03-Feb-2020 ryo

separate struct vm_page_md into vm_page_md and pmap_page
for preparation pmap_pv(9)


Revision tags: ad-namecache-base2 ad-namecache-base1
# 1.61 09-Jan-2020 ryo

fix behaviour mmap()/mprotect() when passed only PROT_EXEC.

when mmap()/mprotect() with only PROT_EXEC, syscall will be successful,
but the page actually hadn't been mapped.
it should be mapped with PROT_READ|PROT_EXEC implicitly. (r-x)


Revision tags: ad-namecache-base
# 1.60 30-Dec-2019 skrll

branches: 1.60.2;
Update pmap_map_chunk to allow L[12] block mappings and L3 page mappings


# 1.59 30-Dec-2019 skrll

Remove unnecessary brackets and unwrap a conditional. Same code before
and after.


# 1.58 28-Dec-2019 jmcneill

Do not use Early Write Acknowledge for PCIe I/O and config space.


# 1.57 27-Dec-2019 jmcneill

Enable early write acknowledge for device memory mappings.


# 1.56 19-Dec-2019 skrll

G/C kasan_shadow_map call in pmap_enter

pmap_growkernel calls kasan_shadow_map for KVA


# 1.55 18-Dec-2019 ryo

atomic_add_16() is not used in pmap.c anymore. no need decl here.


# 1.54 18-Dec-2019 ryo

space to tab


# 1.53 14-Dec-2019 skrll

Fix build... wire_count probably doesn't need atomics


# 1.52 13-Dec-2019 skrll

Fix KASAN support by calling kasan_shadow_map in pmap_growkernel


# 1.51 10-Dec-2019 ad

pg->phys_addr -> VM_PAGE_TO_PHYS(pg)


Revision tags: phil-wifi-20191119
# 1.50 14-Nov-2019 maxv

Mark several kASan functions with __nothing, to avoid annoying #ifdefs.
Same as kCSan and kMSan.


# 1.49 14-Nov-2019 maxv

Don't include "opt_kasan.h" when there's already <sys/asan.h> included.


# 1.48 29-Oct-2019 maya

Define PMAP_NEED_PROCWR, providing strategically placed i-cache
synchronization where just-changed memory is about to be executed.

Fixes SIGILLs seen when running Mono 6 on QEMU Cortex-A57.

ok ryo


# 1.47 22-Sep-2019 jmcneill

Disable translation table walks using TTBR0 while changing its value and
when deactivating a pmap. Fixes stability issues on Ampere eMAG CPUs.


# 1.46 20-Sep-2019 ryo

ref/mod bit should be set according to 'flags' argument, not 'prot'. r1.44 was incomplete.


# 1.45 13-Sep-2019 ryo

In pmap_devmap_bootstrap(), cpu_earlydevice_va_p() must not return true until *all* devmap tables have been enabled.
console mapping may be present in the last table.


# 1.44 07-Sep-2019 ryo

- remove incorrect KASSERT. mmap(2) with prot=PROT_WRITE calls pmap_enter(..., PROT_WRITE) internally.
- fix to update page reference flags when only PROT_WRITE or PROT_EXECUTE specified


# 1.43 15-Aug-2019 skrll

Make pmap_db_pte_print more terse so it's quicker on serial consoles


# 1.42 12-Aug-2019 skrll

Use PMAP_DEV in DEVMAP_ENTRY rather than pmap_map_chunk. It's clearer and
means pmap_map_chunk can be made to map other memory types.


Revision tags: netbsd-9-base phil-wifi-20190609
# 1.41 17-May-2019 mrg

branches: 1.41.2;
apply some __diagused.


Revision tags: isaki-audio2-base
# 1.40 08-Apr-2019 ryo

- free empty page tables pages if reach a certain usage.
- need to lock at removing an old pg (_pmap_remove_pv) in _pmap_enter()


# 1.39 06-Apr-2019 ryo

Fix race conditions about pmap_page_protect() and pmap_enter().

while handling same PTE by these functions in same time, there
is a critical path that the number of valid PTEs and wire_count
are inconsistent, and it caused KASSERT.
Need to hold a pv_lock while modifying them.


# 1.38 20-Mar-2019 ryo

spinkle __printflike(), and use PRIxxx


# 1.37 19-Mar-2019 ryo

- add ddb command "machine ttbr" to dump MMU tables.
- tidy up descriptions, usages and messages.


# 1.36 19-Mar-2019 ryo

- free L1-L3 pages that has been emptied by pmap_remove().
- if no memories, pmap_enter will return correctly ENOMEM if PMAP_CANFAIL, or wait until available any memories if !PMAP_CANFAIL.

These changes improves the stability when we use a huge virtual memory spaces with mmap.


# 1.35 06-Feb-2019 ryo

improve pmap_remove
- don't lock/unlock per page in pmap_remove()
- speedup pte lookup for continuous addresses
- bring out pool_cache_put(&_pmap_pv_pool, pv) from lock/unlock section


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226
# 1.34 21-Dec-2018 ryo

- add workaround for Cavium ThunderX errata 27456.
- add cpufuncs table in cpu_info. each cpu clusters may have different erratum. (e.g. big.LITTLE)


Revision tags: pgoyette-compat-1126
# 1.33 01-Nov-2018 maxv

Add kASan support for aarch64. Stack tracking needs more investigation
and will come in a separate commit.

Reviewed by ryo@ jmcneill@ skrll@.


# 1.32 31-Oct-2018 ryo

invalidate icache correctly.
l3pte_executable() should be used for only valid pte.


Revision tags: pgoyette-compat-1020
# 1.31 18-Oct-2018 skrll

Provide generic start code that assumes the MMU is off and caches are
disabled as per the linux booting protocol for ARMv6 and ARMv7 boards.
u-boot image type should be changed to 'linux' for correct behaviour.

The new start code builds a minimal "bootstrap" L1PT with cached access
disabled and uses the same table for all processors. AP startup is
performed in less steps and more code is written in C.

The bootstrap tables and stack are placed into an (orphaned) section
"_init_memory" which is given to uvm when it is no longer used.

Various kernels have been converted to use this code and tested. Some
boards were provided by TNF. Thanks!

The GENERIC kernel now boots on boards using the TEGRA, SUNXI and EXYNOS
kernels. The GENERIC kernel will also work on RPI2 using u-boot.

Thanks to martin@ and aymeric@ for testing on parallella and nanosoc
respectively


# 1.30 14-Oct-2018 skrll

Use __nothing


# 1.29 12-Oct-2018 ryo

add initial support of COMPAT_NETBSD32 on AArch64.
arm ELF32 EABI binaries could be execute in AArch32 state on AArch64. A32 THUMB mode is not supported yet.


# 1.28 12-Oct-2018 ryo

- cleanup checking address ranges with IN_RANGE macro
- change PM_ADDR_CHECK macro to KASSERTMSG
- restore fast lookup cases with IN_RANGE macro for pmap_extract changed in my previous commit.


# 1.27 12-Oct-2018 ryo

rewrite pmap_pte_lookup() to share similar code.


# 1.26 04-Oct-2018 ryo

cleanup locore, and changed the way to map memories during boot.
- add functions bootpage_enter() and bootpage_alloc() to adapt various layout
of physical memory map. especially for 64bit physical memory layout.
pmapboot_alloc() allocates pagetable pages from _end[].
- changed to map only the required amount for PA=VA identity mapping
(kernel image, UART device, and FDT blob) with L2_BLOCK(2Mbyte).
- changing page permission for kernel image, and making KSEG mapping are done
at cpu_kernel_vm_init() instead of at locore.
- optimize PTE entries with PTE Contiguous bit. it is enabled on devmap only for now.

reviewed by skrll@, thanks.


# 1.25 04-Oct-2018 ryo

* define LX_BLKPAG_{OS,ATTR}_* for OS dependent PTE attributes in pmap.h
* cleanup macros


Revision tags: pgoyette-compat-0930
# 1.24 17-Sep-2018 ryo

delete debug printf and KASSERT.


# 1.23 10-Sep-2018 maxv

Replace KDASSERT by panic.


# 1.22 10-Sep-2018 maxv

Rename _pmap_alloc_pdp -> pmap_alloc_pdp, and make it public.


# 1.21 10-Sep-2018 ryo

cleanup aarch64 mpstart and fdt bootstrap
* arm_cpu_hatch_arg is a bad idea. avoid serializing CPU startup, and eliminate arm_cpu_hatch_arg.
in mpstart, resolve own cpu index using array of cpu_mpidr[] (aarch64)
* add support fdt enable-method "spin-table"
* add support fdt enable-method "brcm,bcm2836-smp" (for 32bit RaspberryPi)
* use arm_fdt_cpu_bootstrap() instead of psci_fdt_bootstrap()
* rename "arm/fdt/psci_fdt.h" to "arm/fdt/psci_fdtvar.h" because of conflict of include file for needs-flag
* add devmap for cpu spin-table of raspberrypi3/aarch64
* no need to force hatch APs for raspberrypi3/arm32 ifndef MULTIPROCESSOR.
* fix to work pmap_extract(kerneltext/data/bss) even if before calling pmap_bootstrap

idea to use cpu_mpidr[] by jmcneill@. reviewd by skrll@. thanks.


Revision tags: pgoyette-compat-0906
# 1.20 27-Aug-2018 ryo

need to add VM_PROT_READ when pmap_kenter_pa(va, pa, VM_PROT_WRITE, 0) or pmap_kenter_pa(va, pa, VM_PROT_EXECUTE, 0).
VM_PROT_READ is treated as an access permission inernally.


# 1.19 11-Aug-2018 ryo

change to minimum invalidation of TLB.
specifying not only va but also asid, and not invalidate L0-L2 entry using tlbi_*_ll() if needed.


# 1.18 10-Aug-2018 ryo

treat kernel-exec attr and user-exec attr separately.
kernel cannot execute userland exec page, and user cannot execute kernel page.


# 1.17 06-Aug-2018 ryo

set kernel text/rodata readonly by default.
add function db_write_text() for setting ddb breakpoint.


# 1.16 31-Jul-2018 skrll

Define and use VPRINTF


Revision tags: pgoyette-compat-0728
# 1.15 27-Jul-2018 ryo

changes of pmap.c r1.13 seems to be unstable.
In order to invalidate icache, not to invalidate all icache,
but temporary to make the page writable and invalidate target address only.


# 1.14 24-Jul-2018 ryo

don't call pool_cache_put with locking pmap. pool_cache_put call pmap_kenter_pa internally.
(pool_cache_put_paddr -> pool_cache_put_slow -> pool_get -> pmap_kenter_pa)


# 1.13 23-Jul-2018 ryo

* fix icache invalidations.
* "ic ivau" (aarch64_icache_sync_range) with VA generates permission fault in some situations, therefore use KSEG address for now.


# 1.12 23-Jul-2018 ryo

rather than using flags to resolve nested locks, reserve pool_cache before locking.


# 1.11 21-Jul-2018 ryo

* avoid deadlock. mutex_owned() works only for adaptive lock, therefore we cannot use it for spinlock...
* add more NULL check
* clear pte when pmap_enter() fails


# 1.10 17-Jul-2018 ryo

Use __debugused


# 1.9 17-Jul-2018 christos

Add missing casts, remove unused variables.


# 1.8 09-Jul-2018 ryo

need locks in pmap_kremove() and pmap_fault_fixup()


Revision tags: phil-wifi-base pgoyette-compat-0625 pgoyette-compat-0521
# 1.7 20-May-2018 ryo

branches: 1.7.2;
pmap_enter() must update modified/referenced flags by 'flags' not 'prot'.


# 1.6 16-May-2018 ryo

Fix memory leak. it was leaking one page every pmap_create().
pm->pm_vmlist must be initialized before calling _pmap_alloc_pdp().


Revision tags: pgoyette-compat-0502
# 1.5 29-Apr-2018 ryo

fix KASSERT panic. pv_entry may not be exists in pvlist when pmap_remove().


# 1.4 29-Apr-2018 ryo

delete unused code


# 1.3 27-Apr-2018 ryo

fix instability behavior of bufcache on aarch64.
* fix to return correct ref/mod when PMAP_WIRED.
* changed to keep wired flags in pte instead of pv_entry, and cleanup.


Revision tags: pgoyette-compat-0422 pgoyette-compat-0415 pgoyette-compat-0407
# 1.2 01-Apr-2018 ryo

Add initial support for ARMv8 (AARCH64) (by nisimura@ and ryo@)

- sys/arch/evbarm64 is gone and integrated into sys/arch/evbarm. (by skrll@)
- add support fdt. evbarm/conf/GENERIC64 fdt (bcm2837,sunxi,tegra) based generic 64bit kernel config. (by skrll@, jmcneill@)


Revision tags: netbsd-8-2-RELEASE netbsd-8-1-RELEASE netbsd-8-1-RC1 netbsd-7-2-RELEASE netbsd-8-0-RELEASE netbsd-8-0-RC2 netbsd-8-0-RC1 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 netbsd-7-1-2-RELEASE pgoyette-compat-base netbsd-7-1-1-RELEASE tls-maxphys-base-20171202 matt-nb8-mediatek-base nick-nhusb-base-20170825 perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base pgoyette-localcount-20170320 netbsd-7-1-RELEASE netbsd-7-1-RC2 nick-nhusb-base-20170204 netbsd-7-nhusb-base-20170116 bouyer-socketcan-base pgoyette-localcount-20170107 netbsd-7-1-RC1 nick-nhusb-base-20161204 pgoyette-localcount-20161104 netbsd-7-0-2-RELEASE nick-nhusb-base-20161004 localcount-20160914 netbsd-7-nhusb-base pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907 nick-nhusb-base-20160529 netbsd-7-0-1-RELEASE nick-nhusb-base-20160422 nick-nhusb-base-20160319 nick-nhusb-base-20151226 netbsd-7-0-RELEASE nick-nhusb-base-20150921 netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 nick-nhusb-base-20150606 nick-nhusb-base-20150406 nick-nhusb-base tls-maxphys-base netbsd-7-base
# 1.1 10-Aug-2014 matt

branches: 1.1.4; 1.1.28;
Preliminary files for AARCH64 (64-bit ARM) support.
Enough for a distribution build.


# 1.110 09-Sep-2021 skrll

In pmap_icache_sync_range change

for (...) {
...
if (condition) {
// do stuff
}
}

to

for (...) {
...
if (!conditional)
continue;
// do stuff
}

to save on indentation. Same code (modulo register usage) before and
after.


# 1.109 09-Sep-2021 skrll

KNF


Revision tags: thorpej-i2c-spi-conf2-base thorpej-futex2-base thorpej-cfargs2-base cjep_sun2x-base1 cjep_sun2x-base cjep_staticlib_x-base1 thorpej-i2c-spi-conf-base
# 1.108 29-May-2021 skrll

Deal with the pmap limitation of maxproc in a more complete way and
recognise CPUs with only 8bit ASIDs.


Revision tags: cjep_staticlib_x-base
# 1.107 30-Apr-2021 skrll

branches: 1.107.2;
Make the ddb for pmap / pte information pmap agnostic


# 1.106 29-Apr-2021 skrll

Remove some unnecessary tlb invalidate in pmap_growkernel and ASAN shadow
map. Ensure the shadow map mappings are visible to the TLB walkers.


# 1.105 21-Apr-2021 ryo

branches: 1.105.2;
added more attributes of PTE displayed by "ddb>machine pte"


Revision tags: thorpej-cfargs-base
# 1.104 17-Apr-2021 mrg

remove KERNHIST_INIT_STATIC(). it stradles the line between usable
early in boot and broken early in boot by requiring a partly static
structure with another structure that must be present by the time
any uses are performed. theoretically platform code could allocate
a chunk while seting up memory and assign it here, giving a dynamic
sizing for the entry list, but the reality is that all users have
a statically allocated entry list as well.

the existing KERNHIST_LINK_STATIC() is used in conjunction with
KERNHIST_INITIALIZER() instead.

this stops a NULL pointer deref when the _LOG() macro is called
before the storage is linked in, which happens with GCC 10 on OCTEON
with UVMHIST enabled, crashing in very early kernel init.


Revision tags: thorpej-futex-base
# 1.103 09-Mar-2021 ryo

branches: 1.103.2;
fix build error without options DDB.

kvtopte() is referenced from arm/acpi/acpi_machdep.c


# 1.102 13-Feb-2021 ryo

No assignment is needed here.

the loop in pmap_page_remove() always removes the first pv,
and since the list is managed by _pmap_remove_pv(), pp->pp_pv.pv_next always points to the first.


# 1.101 01-Feb-2021 ryo

It is enough to make a page accessible instead of writable.
same fix as r1.76


# 1.100 31-Jan-2021 ryo

implement pmap_remove_all().

The size of struct pv_entry has increased, but speed of kernel build has improved by about 1%
exec and exit should have been improved.


# 1.99 20-Dec-2020 skrll

Improve the English in the previous comment fix.


# 1.98 19-Dec-2020 skrll

Tweak a comment


# 1.97 11-Dec-2020 skrll

s:aarch64/cpufunc.h:arm/cpufunc.h:

a baby step in the grand arm header unification challenge


# 1.96 10-Nov-2020 skrll

AA64 is not MIPS.

Change all KSEG references to directmap


# 1.95 07-Nov-2020 skrll

In pmap_devmap_bootstrap only set pmap_devmap_bootstrap_done if there
is an entry and ALL of the entries have been done. The entry required
for EARLYCONS might not be the first/only one...


# 1.94 01-Nov-2020 jmcneill

branches: 1.94.2;
No need to disable translation table walks in pmap_activate().


# 1.93 22-Oct-2020 skrll

Use the isb macro - missed in previous commit


# 1.92 22-Oct-2020 skrll

Use the dmb/dsb/isb macros... if nothing else they're all now consistent
about the "memory" assembler contraint.

No binary change


# 1.91 28-Sep-2020 skrll

Only set pmap_devmap_bootstrap_done if something gets mapped.

Think acpi_platform_devmap


# 1.90 19-Sep-2020 skrll

Make __md_palloc pmap agnostic (think sys/uvm/pmap)


# 1.89 14-Sep-2020 ryo

PID_MAX is just an initial value (soft maximum). Don't use it for CTASSERT.
defined __HAVE_CPU_MAXPROC to use function cpu_maxproc().

pointed out by mrg@, thanks.


# 1.88 06-Sep-2020 ryo

Fix panic caused by modload. http://mail-index.netbsd.org/port-arm/2020/08/30/msg006960.html

The address space reserved for modules may not be mapped in L1-L3.


# 1.87 14-Aug-2020 skrll

Whitespace


# 1.86 12-Aug-2020 skrll

Part IV of ad's performance improvements for aarch64

- Implement pmap_growkernel(), and update kernel pmap's stats with atomics.

- Then, pmap_kenter_pa() and pmap_kremove() no longer need to allocate
memory nor take pm_lock, because they only modify L3 PTEs.

- Then, pm_lock and pp_lock can be adaptive mutexes at IPL_NONE which are
cheaper than spin mutexes.

- Take the pmap's lock in pmap_extract() if not the kernel's pmap, otherwise
pmap_extract() might see inconsistent state.


# 1.85 09-Aug-2020 skrll

Fix another UVMHIST so it doesn't use %s


# 1.84 16-Jul-2020 skrll

pmapboot_enter simplication
- bootpage_alloc in asm becomes pmapboot_pagealloc in C
- PMAPBOOT_ENTER_NOBLOCK is removed as it's not used
- PMAPBOOT_ENTER_NOOVERWRITE is removed as it's now always on
- physpage_allocator argument is removed as it's always
pmapboot_pagealloc
- Support for EARLYCONS without CONSADDR is removed so that the identity
map for CONSADDR is always known.

For the assembly files:
2 files changed, 40 insertions(+), 89 deletions(-)

LGTM ryo


# 1.83 04-Jul-2020 rin

Use tlen for temporary length variable instead of l, which is usually
used for struct lwp *.

No binary changes.


# 1.82 02-Jul-2020 rin

pmap_procwr(): sync icache even if p != curproc. This fixes applications
like GDB for arm32, that rewrite text of other process.

Thanks to ryo@ for discussion.


# 1.81 02-Jul-2020 rin

Set uvmexp.ncolors appropriately, which is required for some CPU
models with VIPT icache.

Otherwise, alias in virtual address results in inconsistent results,
at least for applications that rewrite text of other process, e.g.,
GDB for arm32.

Also, this hopefully fixes other unexpected failures due to alias.

Confirmed that there's no observable regression in performance;
difference in ``time make -j8'' for GENERIC64 kernel on BCM2837
with and without setting uvmexp.ncolors is within 0.1%.

Thanks to ryo@ for discussion.


# 1.80 27-Jun-2020 rin

Fix typo in name of evcnt(4) counter.


# 1.79 24-Jun-2020 ryo

Fix bug with incorrect range calculation when doing icache sync.
This is called by sysarch(ARM_SYNC_ICACHE) from aarch32 (compat_netbsd32) emul process.

pointed out by rin@, thanks.

XXX pullup-9


# 1.78 14-Jun-2020 ad

- Fix a lock order reversal in pmap_page_protect().

- Make sure pmap is always locked when updating stats; atomics no longer
needed to do that.

- Remove unneeded traversal of pv list in pmap_enter_pv().

- Shrink struct vm_page from 136 to 128 bytes (cache line sized) and struct
pv_entry from 48 to 32 bytes (power of 2 sized).

- Embed a pv_entry in each vm_page. This means PV entries don't need to
be allocated for private anonymous memory / COW pages / most UBC mappings.
Dynamic PV entries are then used only for stuff like shared libraries and
shared memory.

Proposed on port-arm@.


# 1.77 10-Jun-2020 ad

- Wired/resident stats shouldn't covered by PMAPCOUNTERS.
- Rename need_update_pv -> need_enter_pv.

Ok ryo@


# 1.76 01-Jun-2020 ryo

no need to make the PTE writable to do icache_sync, enough to accessible.


# 1.75 15-May-2020 skrll

Use __diagused


# 1.74 15-May-2020 tnn

fix non-diag build


# 1.73 14-May-2020 skrll

Use MUTEX_NODEBUG for PV locks as is commonly done. OK ryo.


# 1.72 13-May-2020 jmcneill

Implement pmap_extract_coherency


Revision tags: bouyer-xenpvh-base2 phil-wifi-20200421 bouyer-xenpvh-base1
# 1.71 18-Apr-2020 skrll

PMAP_DEBUG has been deleted on arm


# 1.70 13-Apr-2020 maxv

Add support for Branch Target Identification (BTI).

On the executable pages that have the GP (Guarded Page) bit, the semantic
of the "br" and "blr" instructions is changed: the CPU expects the first
instruction of the jump/call target to be "bti", and faults if it isn't.

We add the GP bit on the kernel .text pages (and incidentally the .rodata
pages, but we don't care). The compiler adds a "bti c" instruction at the
beginning of each C function. We modify the ENTRY() macros to manually add
"bti c" in the asm functions.

cpuswitch.S needs a specific change: with "br x27" the CPU expects "bti j",
which is bad because the functions begin with "bti c"; switch to "br x16",
for the CPU to accept "bti c".

BTI helps defend against JOP/COP. Tested on Qemu.


Revision tags: phil-wifi-20200411 bouyer-xenpvh-base
# 1.69 08-Apr-2020 ryo

branches: 1.69.2;
use PMAP_PAGE_INIT() to initialize mutex in pmap_page.

VM_MDPAGE_INIT() in pmap_free_pdp() had initialized pp_flags,
so it unintentionally cleared PMAP_PAGE_FLAGS_PV_TRACKED.
use PMAP_PAGE_INIT to avoid using PMAP_PAGE_FLAGS_PV_TRACKED.

pointed out by tnn@, thanks


Revision tags: phil-wifi-20200406
# 1.68 14-Mar-2020 ad

pmap_remove_all(): Return a boolean value to indicate the behaviour. If
true, all mappings have been removed, the pmap is totally cleared out, and
UVM can then avoid doing the work to call pmap_remove() for each map entry.
If false, either nothing has been done, or some helpful arch-specific voodoo
has taken place.


Revision tags: is-mlppp-base
# 1.67 02-Mar-2020 ryo

oops, fix incorrect usage of daif_enable() in my previous commit.


# 1.66 29-Feb-2020 ryo

Fix pmap to work correctly with tagged addresses

- when fault, untag from address before passing to uvm/pmap functions
- pmap_extract() checks more strictly and consider the address tag


# 1.65 29-Feb-2020 ryo

use pmapboot_enter_range()


Revision tags: ad-namecache-base3
# 1.64 10-Feb-2020 ryo

use LIST(3) instead of TAILQ(3) to save one word in struct vm_page and struct pmap.

pointed out by riastradh@. thanks


# 1.63 03-Feb-2020 ryo

add support pmap_pv(9)

Patch originally from jmcneill@. thanks


# 1.62 03-Feb-2020 ryo

separate struct vm_page_md into vm_page_md and pmap_page
for preparation pmap_pv(9)


Revision tags: ad-namecache-base2 ad-namecache-base1
# 1.61 09-Jan-2020 ryo

fix behaviour mmap()/mprotect() when passed only PROT_EXEC.

when mmap()/mprotect() with only PROT_EXEC, syscall will be successful,
but the page actually hadn't been mapped.
it should be mapped with PROT_READ|PROT_EXEC implicitly. (r-x)


Revision tags: ad-namecache-base
# 1.60 30-Dec-2019 skrll

branches: 1.60.2;
Update pmap_map_chunk to allow L[12] block mappings and L3 page mappings


# 1.59 30-Dec-2019 skrll

Remove unnecessary brackets and unwrap a conditional. Same code before
and after.


# 1.58 28-Dec-2019 jmcneill

Do not use Early Write Acknowledge for PCIe I/O and config space.


# 1.57 27-Dec-2019 jmcneill

Enable early write acknowledge for device memory mappings.


# 1.56 19-Dec-2019 skrll

G/C kasan_shadow_map call in pmap_enter

pmap_growkernel calls kasan_shadow_map for KVA


# 1.55 18-Dec-2019 ryo

atomic_add_16() is not used in pmap.c anymore. no need decl here.


# 1.54 18-Dec-2019 ryo

space to tab


# 1.53 14-Dec-2019 skrll

Fix build... wire_count probably doesn't need atomics


# 1.52 13-Dec-2019 skrll

Fix KASAN support by calling kasan_shadow_map in pmap_growkernel


# 1.51 10-Dec-2019 ad

pg->phys_addr -> VM_PAGE_TO_PHYS(pg)


Revision tags: phil-wifi-20191119
# 1.50 14-Nov-2019 maxv

Mark several kASan functions with __nothing, to avoid annoying #ifdefs.
Same as kCSan and kMSan.


# 1.49 14-Nov-2019 maxv

Don't include "opt_kasan.h" when there's already <sys/asan.h> included.


# 1.48 29-Oct-2019 maya

Define PMAP_NEED_PROCWR, providing strategically placed i-cache
synchronization where just-changed memory is about to be executed.

Fixes SIGILLs seen when running Mono 6 on QEMU Cortex-A57.

ok ryo


# 1.47 22-Sep-2019 jmcneill

Disable translation table walks using TTBR0 while changing its value and
when deactivating a pmap. Fixes stability issues on Ampere eMAG CPUs.


# 1.46 20-Sep-2019 ryo

ref/mod bit should be set according to 'flags' argument, not 'prot'. r1.44 was incomplete.


# 1.45 13-Sep-2019 ryo

In pmap_devmap_bootstrap(), cpu_earlydevice_va_p() must not return true until *all* devmap tables have been enabled.
console mapping may be present in the last table.


# 1.44 07-Sep-2019 ryo

- remove incorrect KASSERT. mmap(2) with prot=PROT_WRITE calls pmap_enter(..., PROT_WRITE) internally.
- fix to update page reference flags when only PROT_WRITE or PROT_EXECUTE specified


# 1.43 15-Aug-2019 skrll

Make pmap_db_pte_print more terse so it's quicker on serial consoles


# 1.42 12-Aug-2019 skrll

Use PMAP_DEV in DEVMAP_ENTRY rather than pmap_map_chunk. It's clearer and
means pmap_map_chunk can be made to map other memory types.


Revision tags: netbsd-9-base phil-wifi-20190609
# 1.41 17-May-2019 mrg

branches: 1.41.2;
apply some __diagused.


Revision tags: isaki-audio2-base
# 1.40 08-Apr-2019 ryo

- free empty page tables pages if reach a certain usage.
- need to lock at removing an old pg (_pmap_remove_pv) in _pmap_enter()


# 1.39 06-Apr-2019 ryo

Fix race conditions about pmap_page_protect() and pmap_enter().

while handling same PTE by these functions in same time, there
is a critical path that the number of valid PTEs and wire_count
are inconsistent, and it caused KASSERT.
Need to hold a pv_lock while modifying them.


# 1.38 20-Mar-2019 ryo

spinkle __printflike(), and use PRIxxx


# 1.37 19-Mar-2019 ryo

- add ddb command "machine ttbr" to dump MMU tables.
- tidy up descriptions, usages and messages.


# 1.36 19-Mar-2019 ryo

- free L1-L3 pages that has been emptied by pmap_remove().
- if no memories, pmap_enter will return correctly ENOMEM if PMAP_CANFAIL, or wait until available any memories if !PMAP_CANFAIL.

These changes improves the stability when we use a huge virtual memory spaces with mmap.


# 1.35 06-Feb-2019 ryo

improve pmap_remove
- don't lock/unlock per page in pmap_remove()
- speedup pte lookup for continuous addresses
- bring out pool_cache_put(&_pmap_pv_pool, pv) from lock/unlock section


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226
# 1.34 21-Dec-2018 ryo

- add workaround for Cavium ThunderX errata 27456.
- add cpufuncs table in cpu_info. each cpu clusters may have different erratum. (e.g. big.LITTLE)


Revision tags: pgoyette-compat-1126
# 1.33 01-Nov-2018 maxv

Add kASan support for aarch64. Stack tracking needs more investigation
and will come in a separate commit.

Reviewed by ryo@ jmcneill@ skrll@.


# 1.32 31-Oct-2018 ryo

invalidate icache correctly.
l3pte_executable() should be used for only valid pte.


Revision tags: pgoyette-compat-1020
# 1.31 18-Oct-2018 skrll

Provide generic start code that assumes the MMU is off and caches are
disabled as per the linux booting protocol for ARMv6 and ARMv7 boards.
u-boot image type should be changed to 'linux' for correct behaviour.

The new start code builds a minimal "bootstrap" L1PT with cached access
disabled and uses the same table for all processors. AP startup is
performed in less steps and more code is written in C.

The bootstrap tables and stack are placed into an (orphaned) section
"_init_memory" which is given to uvm when it is no longer used.

Various kernels have been converted to use this code and tested. Some
boards were provided by TNF. Thanks!

The GENERIC kernel now boots on boards using the TEGRA, SUNXI and EXYNOS
kernels. The GENERIC kernel will also work on RPI2 using u-boot.

Thanks to martin@ and aymeric@ for testing on parallella and nanosoc
respectively


# 1.30 14-Oct-2018 skrll

Use __nothing


# 1.29 12-Oct-2018 ryo

add initial support of COMPAT_NETBSD32 on AArch64.
arm ELF32 EABI binaries could be execute in AArch32 state on AArch64. A32 THUMB mode is not supported yet.


# 1.28 12-Oct-2018 ryo

- cleanup checking address ranges with IN_RANGE macro
- change PM_ADDR_CHECK macro to KASSERTMSG
- restore fast lookup cases with IN_RANGE macro for pmap_extract changed in my previous commit.


# 1.27 12-Oct-2018 ryo

rewrite pmap_pte_lookup() to share similar code.


# 1.26 04-Oct-2018 ryo

cleanup locore, and changed the way to map memories during boot.
- add functions bootpage_enter() and bootpage_alloc() to adapt various layout
of physical memory map. especially for 64bit physical memory layout.
pmapboot_alloc() allocates pagetable pages from _end[].
- changed to map only the required amount for PA=VA identity mapping
(kernel image, UART device, and FDT blob) with L2_BLOCK(2Mbyte).
- changing page permission for kernel image, and making KSEG mapping are done
at cpu_kernel_vm_init() instead of at locore.
- optimize PTE entries with PTE Contiguous bit. it is enabled on devmap only for now.

reviewed by skrll@, thanks.


# 1.25 04-Oct-2018 ryo

* define LX_BLKPAG_{OS,ATTR}_* for OS dependent PTE attributes in pmap.h
* cleanup macros


Revision tags: pgoyette-compat-0930
# 1.24 17-Sep-2018 ryo

delete debug printf and KASSERT.


# 1.23 10-Sep-2018 maxv

Replace KDASSERT by panic.


# 1.22 10-Sep-2018 maxv

Rename _pmap_alloc_pdp -> pmap_alloc_pdp, and make it public.


# 1.21 10-Sep-2018 ryo

cleanup aarch64 mpstart and fdt bootstrap
* arm_cpu_hatch_arg is a bad idea. avoid serializing CPU startup, and eliminate arm_cpu_hatch_arg.
in mpstart, resolve own cpu index using array of cpu_mpidr[] (aarch64)
* add support fdt enable-method "spin-table"
* add support fdt enable-method "brcm,bcm2836-smp" (for 32bit RaspberryPi)
* use arm_fdt_cpu_bootstrap() instead of psci_fdt_bootstrap()
* rename "arm/fdt/psci_fdt.h" to "arm/fdt/psci_fdtvar.h" because of conflict of include file for needs-flag
* add devmap for cpu spin-table of raspberrypi3/aarch64
* no need to force hatch APs for raspberrypi3/arm32 ifndef MULTIPROCESSOR.
* fix to work pmap_extract(kerneltext/data/bss) even if before calling pmap_bootstrap

idea to use cpu_mpidr[] by jmcneill@. reviewd by skrll@. thanks.


Revision tags: pgoyette-compat-0906
# 1.20 27-Aug-2018 ryo

need to add VM_PROT_READ when pmap_kenter_pa(va, pa, VM_PROT_WRITE, 0) or pmap_kenter_pa(va, pa, VM_PROT_EXECUTE, 0).
VM_PROT_READ is treated as an access permission inernally.


# 1.19 11-Aug-2018 ryo

change to minimum invalidation of TLB.
specifying not only va but also asid, and not invalidate L0-L2 entry using tlbi_*_ll() if needed.


# 1.18 10-Aug-2018 ryo

treat kernel-exec attr and user-exec attr separately.
kernel cannot execute userland exec page, and user cannot execute kernel page.


# 1.17 06-Aug-2018 ryo

set kernel text/rodata readonly by default.
add function db_write_text() for setting ddb breakpoint.


# 1.16 31-Jul-2018 skrll

Define and use VPRINTF


Revision tags: pgoyette-compat-0728
# 1.15 27-Jul-2018 ryo

changes of pmap.c r1.13 seems to be unstable.
In order to invalidate icache, not to invalidate all icache,
but temporary to make the page writable and invalidate target address only.


# 1.14 24-Jul-2018 ryo

don't call pool_cache_put with locking pmap. pool_cache_put call pmap_kenter_pa internally.
(pool_cache_put_paddr -> pool_cache_put_slow -> pool_get -> pmap_kenter_pa)


# 1.13 23-Jul-2018 ryo

* fix icache invalidations.
* "ic ivau" (aarch64_icache_sync_range) with VA generates permission fault in some situations, therefore use KSEG address for now.


# 1.12 23-Jul-2018 ryo

rather than using flags to resolve nested locks, reserve pool_cache before locking.


# 1.11 21-Jul-2018 ryo

* avoid deadlock. mutex_owned() works only for adaptive lock, therefore we cannot use it for spinlock...
* add more NULL check
* clear pte when pmap_enter() fails


# 1.10 17-Jul-2018 ryo

Use __debugused


# 1.9 17-Jul-2018 christos

Add missing casts, remove unused variables.


# 1.8 09-Jul-2018 ryo

need locks in pmap_kremove() and pmap_fault_fixup()


Revision tags: phil-wifi-base pgoyette-compat-0625 pgoyette-compat-0521
# 1.7 20-May-2018 ryo

branches: 1.7.2;
pmap_enter() must update modified/referenced flags by 'flags' not 'prot'.


# 1.6 16-May-2018 ryo

Fix memory leak. it was leaking one page every pmap_create().
pm->pm_vmlist must be initialized before calling _pmap_alloc_pdp().


Revision tags: pgoyette-compat-0502
# 1.5 29-Apr-2018 ryo

fix KASSERT panic. pv_entry may not be exists in pvlist when pmap_remove().


# 1.4 29-Apr-2018 ryo

delete unused code


# 1.3 27-Apr-2018 ryo

fix instability behavior of bufcache on aarch64.
* fix to return correct ref/mod when PMAP_WIRED.
* changed to keep wired flags in pte instead of pv_entry, and cleanup.


Revision tags: pgoyette-compat-0422 pgoyette-compat-0415 pgoyette-compat-0407
# 1.2 01-Apr-2018 ryo

Add initial support for ARMv8 (AARCH64) (by nisimura@ and ryo@)

- sys/arch/evbarm64 is gone and integrated into sys/arch/evbarm. (by skrll@)
- add support fdt. evbarm/conf/GENERIC64 fdt (bcm2837,sunxi,tegra) based generic 64bit kernel config. (by skrll@, jmcneill@)


Revision tags: netbsd-8-2-RELEASE netbsd-8-1-RELEASE netbsd-8-1-RC1 netbsd-7-2-RELEASE netbsd-8-0-RELEASE netbsd-8-0-RC2 netbsd-8-0-RC1 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 netbsd-7-1-2-RELEASE pgoyette-compat-base netbsd-7-1-1-RELEASE tls-maxphys-base-20171202 matt-nb8-mediatek-base nick-nhusb-base-20170825 perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base pgoyette-localcount-20170320 netbsd-7-1-RELEASE netbsd-7-1-RC2 nick-nhusb-base-20170204 netbsd-7-nhusb-base-20170116 bouyer-socketcan-base pgoyette-localcount-20170107 netbsd-7-1-RC1 nick-nhusb-base-20161204 pgoyette-localcount-20161104 netbsd-7-0-2-RELEASE nick-nhusb-base-20161004 localcount-20160914 netbsd-7-nhusb-base pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907 nick-nhusb-base-20160529 netbsd-7-0-1-RELEASE nick-nhusb-base-20160422 nick-nhusb-base-20160319 nick-nhusb-base-20151226 netbsd-7-0-RELEASE nick-nhusb-base-20150921 netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 nick-nhusb-base-20150606 nick-nhusb-base-20150406 nick-nhusb-base tls-maxphys-base netbsd-7-base
# 1.1 10-Aug-2014 matt

branches: 1.1.4; 1.1.28;
Preliminary files for AARCH64 (64-bit ARM) support.
Enough for a distribution build.


# 1.108 29-May-2021 skrll

Deal with the pmap limitation of maxproc in a more complete way and
recognise CPUs with only 8bit ASIDs.


Revision tags: cjep_staticlib_x-base thorpej-i2c-spi-conf-base
# 1.107 30-Apr-2021 skrll

Make the ddb for pmap / pte information pmap agnostic


# 1.106 29-Apr-2021 skrll

Remove some unnecessary tlb invalidate in pmap_growkernel and ASAN shadow
map. Ensure the shadow map mappings are visible to the TLB walkers.


# 1.105 21-Apr-2021 ryo

branches: 1.105.2;
added more attributes of PTE displayed by "ddb>machine pte"


Revision tags: thorpej-cfargs-base
# 1.104 17-Apr-2021 mrg

remove KERNHIST_INIT_STATIC(). it stradles the line between usable
early in boot and broken early in boot by requiring a partly static
structure with another structure that must be present by the time
any uses are performed. theoretically platform code could allocate
a chunk while seting up memory and assign it here, giving a dynamic
sizing for the entry list, but the reality is that all users have
a statically allocated entry list as well.

the existing KERNHIST_LINK_STATIC() is used in conjunction with
KERNHIST_INITIALIZER() instead.

this stops a NULL pointer deref when the _LOG() macro is called
before the storage is linked in, which happens with GCC 10 on OCTEON
with UVMHIST enabled, crashing in very early kernel init.


Revision tags: thorpej-futex-base
# 1.103 09-Mar-2021 ryo

branches: 1.103.2;
fix build error without options DDB.

kvtopte() is referenced from arm/acpi/acpi_machdep.c


# 1.102 13-Feb-2021 ryo

No assignment is needed here.

the loop in pmap_page_remove() always removes the first pv,
and since the list is managed by _pmap_remove_pv(), pp->pp_pv.pv_next always points to the first.


# 1.101 01-Feb-2021 ryo

It is enough to make a page accessible instead of writable.
same fix as r1.76


# 1.100 31-Jan-2021 ryo

implement pmap_remove_all().

The size of struct pv_entry has increased, but speed of kernel build has improved by about 1%
exec and exit should have been improved.


# 1.99 20-Dec-2020 skrll

Improve the English in the previous comment fix.


# 1.98 19-Dec-2020 skrll

Tweak a comment


# 1.97 11-Dec-2020 skrll

s:aarch64/cpufunc.h:arm/cpufunc.h:

a baby step in the grand arm header unification challenge


# 1.96 10-Nov-2020 skrll

AA64 is not MIPS.

Change all KSEG references to directmap


# 1.95 07-Nov-2020 skrll

In pmap_devmap_bootstrap only set pmap_devmap_bootstrap_done if there
is an entry and ALL of the entries have been done. The entry required
for EARLYCONS might not be the first/only one...


# 1.94 01-Nov-2020 jmcneill

branches: 1.94.2;
No need to disable translation table walks in pmap_activate().


# 1.93 22-Oct-2020 skrll

Use the isb macro - missed in previous commit


# 1.92 22-Oct-2020 skrll

Use the dmb/dsb/isb macros... if nothing else they're all now consistent
about the "memory" assembler contraint.

No binary change


# 1.91 28-Sep-2020 skrll

Only set pmap_devmap_bootstrap_done if something gets mapped.

Think acpi_platform_devmap


# 1.90 19-Sep-2020 skrll

Make __md_palloc pmap agnostic (think sys/uvm/pmap)


# 1.89 14-Sep-2020 ryo

PID_MAX is just an initial value (soft maximum). Don't use it for CTASSERT.
defined __HAVE_CPU_MAXPROC to use function cpu_maxproc().

pointed out by mrg@, thanks.


# 1.88 06-Sep-2020 ryo

Fix panic caused by modload. http://mail-index.netbsd.org/port-arm/2020/08/30/msg006960.html

The address space reserved for modules may not be mapped in L1-L3.


# 1.87 14-Aug-2020 skrll

Whitespace


# 1.86 12-Aug-2020 skrll

Part IV of ad's performance improvements for aarch64

- Implement pmap_growkernel(), and update kernel pmap's stats with atomics.

- Then, pmap_kenter_pa() and pmap_kremove() no longer need to allocate
memory nor take pm_lock, because they only modify L3 PTEs.

- Then, pm_lock and pp_lock can be adaptive mutexes at IPL_NONE which are
cheaper than spin mutexes.

- Take the pmap's lock in pmap_extract() if not the kernel's pmap, otherwise
pmap_extract() might see inconsistent state.


# 1.85 09-Aug-2020 skrll

Fix another UVMHIST so it doesn't use %s


# 1.84 16-Jul-2020 skrll

pmapboot_enter simplication
- bootpage_alloc in asm becomes pmapboot_pagealloc in C
- PMAPBOOT_ENTER_NOBLOCK is removed as it's not used
- PMAPBOOT_ENTER_NOOVERWRITE is removed as it's now always on
- physpage_allocator argument is removed as it's always
pmapboot_pagealloc
- Support for EARLYCONS without CONSADDR is removed so that the identity
map for CONSADDR is always known.

For the assembly files:
2 files changed, 40 insertions(+), 89 deletions(-)

LGTM ryo


# 1.83 04-Jul-2020 rin

Use tlen for temporary length variable instead of l, which is usually
used for struct lwp *.

No binary changes.


# 1.82 02-Jul-2020 rin

pmap_procwr(): sync icache even if p != curproc. This fixes applications
like GDB for arm32, that rewrite text of other process.

Thanks to ryo@ for discussion.


# 1.81 02-Jul-2020 rin

Set uvmexp.ncolors appropriately, which is required for some CPU
models with VIPT icache.

Otherwise, alias in virtual address results in inconsistent results,
at least for applications that rewrite text of other process, e.g.,
GDB for arm32.

Also, this hopefully fixes other unexpected failures due to alias.

Confirmed that there's no observable regression in performance;
difference in ``time make -j8'' for GENERIC64 kernel on BCM2837
with and without setting uvmexp.ncolors is within 0.1%.

Thanks to ryo@ for discussion.


# 1.80 27-Jun-2020 rin

Fix typo in name of evcnt(4) counter.


# 1.79 24-Jun-2020 ryo

Fix bug with incorrect range calculation when doing icache sync.
This is called by sysarch(ARM_SYNC_ICACHE) from aarch32 (compat_netbsd32) emul process.

pointed out by rin@, thanks.

XXX pullup-9


# 1.78 14-Jun-2020 ad

- Fix a lock order reversal in pmap_page_protect().

- Make sure pmap is always locked when updating stats; atomics no longer
needed to do that.

- Remove unneeded traversal of pv list in pmap_enter_pv().

- Shrink struct vm_page from 136 to 128 bytes (cache line sized) and struct
pv_entry from 48 to 32 bytes (power of 2 sized).

- Embed a pv_entry in each vm_page. This means PV entries don't need to
be allocated for private anonymous memory / COW pages / most UBC mappings.
Dynamic PV entries are then used only for stuff like shared libraries and
shared memory.

Proposed on port-arm@.


# 1.77 10-Jun-2020 ad

- Wired/resident stats shouldn't covered by PMAPCOUNTERS.
- Rename need_update_pv -> need_enter_pv.

Ok ryo@


# 1.76 01-Jun-2020 ryo

no need to make the PTE writable to do icache_sync, enough to accessible.


# 1.75 15-May-2020 skrll

Use __diagused


# 1.74 15-May-2020 tnn

fix non-diag build


# 1.73 14-May-2020 skrll

Use MUTEX_NODEBUG for PV locks as is commonly done. OK ryo.


# 1.72 13-May-2020 jmcneill

Implement pmap_extract_coherency


Revision tags: bouyer-xenpvh-base2 phil-wifi-20200421 bouyer-xenpvh-base1
# 1.71 18-Apr-2020 skrll

PMAP_DEBUG has been deleted on arm


# 1.70 13-Apr-2020 maxv

Add support for Branch Target Identification (BTI).

On the executable pages that have the GP (Guarded Page) bit, the semantic
of the "br" and "blr" instructions is changed: the CPU expects the first
instruction of the jump/call target to be "bti", and faults if it isn't.

We add the GP bit on the kernel .text pages (and incidentally the .rodata
pages, but we don't care). The compiler adds a "bti c" instruction at the
beginning of each C function. We modify the ENTRY() macros to manually add
"bti c" in the asm functions.

cpuswitch.S needs a specific change: with "br x27" the CPU expects "bti j",
which is bad because the functions begin with "bti c"; switch to "br x16",
for the CPU to accept "bti c".

BTI helps defend against JOP/COP. Tested on Qemu.


Revision tags: phil-wifi-20200411 bouyer-xenpvh-base
# 1.69 08-Apr-2020 ryo

branches: 1.69.2;
use PMAP_PAGE_INIT() to initialize mutex in pmap_page.

VM_MDPAGE_INIT() in pmap_free_pdp() had initialized pp_flags,
so it unintentionally cleared PMAP_PAGE_FLAGS_PV_TRACKED.
use PMAP_PAGE_INIT to avoid using PMAP_PAGE_FLAGS_PV_TRACKED.

pointed out by tnn@, thanks


Revision tags: phil-wifi-20200406
# 1.68 14-Mar-2020 ad

pmap_remove_all(): Return a boolean value to indicate the behaviour. If
true, all mappings have been removed, the pmap is totally cleared out, and
UVM can then avoid doing the work to call pmap_remove() for each map entry.
If false, either nothing has been done, or some helpful arch-specific voodoo
has taken place.


Revision tags: is-mlppp-base
# 1.67 02-Mar-2020 ryo

oops, fix incorrect usage of daif_enable() in my previous commit.


# 1.66 29-Feb-2020 ryo

Fix pmap to work correctly with tagged addresses

- when fault, untag from address before passing to uvm/pmap functions
- pmap_extract() checks more strictly and consider the address tag


# 1.65 29-Feb-2020 ryo

use pmapboot_enter_range()


Revision tags: ad-namecache-base3
# 1.64 10-Feb-2020 ryo

use LIST(3) instead of TAILQ(3) to save one word in struct vm_page and struct pmap.

pointed out by riastradh@. thanks


# 1.63 03-Feb-2020 ryo

add support pmap_pv(9)

Patch originally from jmcneill@. thanks


# 1.62 03-Feb-2020 ryo

separate struct vm_page_md into vm_page_md and pmap_page
for preparation pmap_pv(9)


Revision tags: ad-namecache-base2 ad-namecache-base1
# 1.61 09-Jan-2020 ryo

fix behaviour mmap()/mprotect() when passed only PROT_EXEC.

when mmap()/mprotect() with only PROT_EXEC, syscall will be successful,
but the page actually hadn't been mapped.
it should be mapped with PROT_READ|PROT_EXEC implicitly. (r-x)


Revision tags: ad-namecache-base
# 1.60 30-Dec-2019 skrll

branches: 1.60.2;
Update pmap_map_chunk to allow L[12] block mappings and L3 page mappings


# 1.59 30-Dec-2019 skrll

Remove unnecessary brackets and unwrap a conditional. Same code before
and after.


# 1.58 28-Dec-2019 jmcneill

Do not use Early Write Acknowledge for PCIe I/O and config space.


# 1.57 27-Dec-2019 jmcneill

Enable early write acknowledge for device memory mappings.


# 1.56 19-Dec-2019 skrll

G/C kasan_shadow_map call in pmap_enter

pmap_growkernel calls kasan_shadow_map for KVA


# 1.55 18-Dec-2019 ryo

atomic_add_16() is not used in pmap.c anymore. no need decl here.


# 1.54 18-Dec-2019 ryo

space to tab


# 1.53 14-Dec-2019 skrll

Fix build... wire_count probably doesn't need atomics


# 1.52 13-Dec-2019 skrll

Fix KASAN support by calling kasan_shadow_map in pmap_growkernel


# 1.51 10-Dec-2019 ad

pg->phys_addr -> VM_PAGE_TO_PHYS(pg)


Revision tags: phil-wifi-20191119
# 1.50 14-Nov-2019 maxv

Mark several kASan functions with __nothing, to avoid annoying #ifdefs.
Same as kCSan and kMSan.


# 1.49 14-Nov-2019 maxv

Don't include "opt_kasan.h" when there's already <sys/asan.h> included.


# 1.48 29-Oct-2019 maya

Define PMAP_NEED_PROCWR, providing strategically placed i-cache
synchronization where just-changed memory is about to be executed.

Fixes SIGILLs seen when running Mono 6 on QEMU Cortex-A57.

ok ryo


# 1.47 22-Sep-2019 jmcneill

Disable translation table walks using TTBR0 while changing its value and
when deactivating a pmap. Fixes stability issues on Ampere eMAG CPUs.


# 1.46 20-Sep-2019 ryo

ref/mod bit should be set according to 'flags' argument, not 'prot'. r1.44 was incomplete.


# 1.45 13-Sep-2019 ryo

In pmap_devmap_bootstrap(), cpu_earlydevice_va_p() must not return true until *all* devmap tables have been enabled.
console mapping may be present in the last table.


# 1.44 07-Sep-2019 ryo

- remove incorrect KASSERT. mmap(2) with prot=PROT_WRITE calls pmap_enter(..., PROT_WRITE) internally.
- fix to update page reference flags when only PROT_WRITE or PROT_EXECUTE specified


# 1.43 15-Aug-2019 skrll

Make pmap_db_pte_print more terse so it's quicker on serial consoles


# 1.42 12-Aug-2019 skrll

Use PMAP_DEV in DEVMAP_ENTRY rather than pmap_map_chunk. It's clearer and
means pmap_map_chunk can be made to map other memory types.


Revision tags: netbsd-9-base phil-wifi-20190609
# 1.41 17-May-2019 mrg

branches: 1.41.2;
apply some __diagused.


Revision tags: isaki-audio2-base
# 1.40 08-Apr-2019 ryo

- free empty page tables pages if reach a certain usage.
- need to lock at removing an old pg (_pmap_remove_pv) in _pmap_enter()


# 1.39 06-Apr-2019 ryo

Fix race conditions about pmap_page_protect() and pmap_enter().

while handling same PTE by these functions in same time, there
is a critical path that the number of valid PTEs and wire_count
are inconsistent, and it caused KASSERT.
Need to hold a pv_lock while modifying them.


# 1.38 20-Mar-2019 ryo

spinkle __printflike(), and use PRIxxx


# 1.37 19-Mar-2019 ryo

- add ddb command "machine ttbr" to dump MMU tables.
- tidy up descriptions, usages and messages.


# 1.36 19-Mar-2019 ryo

- free L1-L3 pages that has been emptied by pmap_remove().
- if no memories, pmap_enter will return correctly ENOMEM if PMAP_CANFAIL, or wait until available any memories if !PMAP_CANFAIL.

These changes improves the stability when we use a huge virtual memory spaces with mmap.


# 1.35 06-Feb-2019 ryo

improve pmap_remove
- don't lock/unlock per page in pmap_remove()
- speedup pte lookup for continuous addresses
- bring out pool_cache_put(&_pmap_pv_pool, pv) from lock/unlock section


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226
# 1.34 21-Dec-2018 ryo

- add workaround for Cavium ThunderX errata 27456.
- add cpufuncs table in cpu_info. each cpu clusters may have different erratum. (e.g. big.LITTLE)


Revision tags: pgoyette-compat-1126
# 1.33 01-Nov-2018 maxv

Add kASan support for aarch64. Stack tracking needs more investigation
and will come in a separate commit.

Reviewed by ryo@ jmcneill@ skrll@.


# 1.32 31-Oct-2018 ryo

invalidate icache correctly.
l3pte_executable() should be used for only valid pte.


Revision tags: pgoyette-compat-1020
# 1.31 18-Oct-2018 skrll

Provide generic start code that assumes the MMU is off and caches are
disabled as per the linux booting protocol for ARMv6 and ARMv7 boards.
u-boot image type should be changed to 'linux' for correct behaviour.

The new start code builds a minimal "bootstrap" L1PT with cached access
disabled and uses the same table for all processors. AP startup is
performed in less steps and more code is written in C.

The bootstrap tables and stack are placed into an (orphaned) section
"_init_memory" which is given to uvm when it is no longer used.

Various kernels have been converted to use this code and tested. Some
boards were provided by TNF. Thanks!

The GENERIC kernel now boots on boards using the TEGRA, SUNXI and EXYNOS
kernels. The GENERIC kernel will also work on RPI2 using u-boot.

Thanks to martin@ and aymeric@ for testing on parallella and nanosoc
respectively


# 1.30 14-Oct-2018 skrll

Use __nothing


# 1.29 12-Oct-2018 ryo

add initial support of COMPAT_NETBSD32 on AArch64.
arm ELF32 EABI binaries could be execute in AArch32 state on AArch64. A32 THUMB mode is not supported yet.


# 1.28 12-Oct-2018 ryo

- cleanup checking address ranges with IN_RANGE macro
- change PM_ADDR_CHECK macro to KASSERTMSG
- restore fast lookup cases with IN_RANGE macro for pmap_extract changed in my previous commit.


# 1.27 12-Oct-2018 ryo

rewrite pmap_pte_lookup() to share similar code.


# 1.26 04-Oct-2018 ryo

cleanup locore, and changed the way to map memories during boot.
- add functions bootpage_enter() and bootpage_alloc() to adapt various layout
of physical memory map. especially for 64bit physical memory layout.
pmapboot_alloc() allocates pagetable pages from _end[].
- changed to map only the required amount for PA=VA identity mapping
(kernel image, UART device, and FDT blob) with L2_BLOCK(2Mbyte).
- changing page permission for kernel image, and making KSEG mapping are done
at cpu_kernel_vm_init() instead of at locore.
- optimize PTE entries with PTE Contiguous bit. it is enabled on devmap only for now.

reviewed by skrll@, thanks.


# 1.25 04-Oct-2018 ryo

* define LX_BLKPAG_{OS,ATTR}_* for OS dependent PTE attributes in pmap.h
* cleanup macros


Revision tags: pgoyette-compat-0930
# 1.24 17-Sep-2018 ryo

delete debug printf and KASSERT.


# 1.23 10-Sep-2018 maxv

Replace KDASSERT by panic.


# 1.22 10-Sep-2018 maxv

Rename _pmap_alloc_pdp -> pmap_alloc_pdp, and make it public.


# 1.21 10-Sep-2018 ryo

cleanup aarch64 mpstart and fdt bootstrap
* arm_cpu_hatch_arg is a bad idea. avoid serializing CPU startup, and eliminate arm_cpu_hatch_arg.
in mpstart, resolve own cpu index using array of cpu_mpidr[] (aarch64)
* add support fdt enable-method "spin-table"
* add support fdt enable-method "brcm,bcm2836-smp" (for 32bit RaspberryPi)
* use arm_fdt_cpu_bootstrap() instead of psci_fdt_bootstrap()
* rename "arm/fdt/psci_fdt.h" to "arm/fdt/psci_fdtvar.h" because of conflict of include file for needs-flag
* add devmap for cpu spin-table of raspberrypi3/aarch64
* no need to force hatch APs for raspberrypi3/arm32 ifndef MULTIPROCESSOR.
* fix to work pmap_extract(kerneltext/data/bss) even if before calling pmap_bootstrap

idea to use cpu_mpidr[] by jmcneill@. reviewd by skrll@. thanks.


Revision tags: pgoyette-compat-0906
# 1.20 27-Aug-2018 ryo

need to add VM_PROT_READ when pmap_kenter_pa(va, pa, VM_PROT_WRITE, 0) or pmap_kenter_pa(va, pa, VM_PROT_EXECUTE, 0).
VM_PROT_READ is treated as an access permission inernally.


# 1.19 11-Aug-2018 ryo

change to minimum invalidation of TLB.
specifying not only va but also asid, and not invalidate L0-L2 entry using tlbi_*_ll() if needed.


# 1.18 10-Aug-2018 ryo

treat kernel-exec attr and user-exec attr separately.
kernel cannot execute userland exec page, and user cannot execute kernel page.


# 1.17 06-Aug-2018 ryo

set kernel text/rodata readonly by default.
add function db_write_text() for setting ddb breakpoint.


# 1.16 31-Jul-2018 skrll

Define and use VPRINTF


Revision tags: pgoyette-compat-0728
# 1.15 27-Jul-2018 ryo

changes of pmap.c r1.13 seems to be unstable.
In order to invalidate icache, not to invalidate all icache,
but temporary to make the page writable and invalidate target address only.


# 1.14 24-Jul-2018 ryo

don't call pool_cache_put with locking pmap. pool_cache_put call pmap_kenter_pa internally.
(pool_cache_put_paddr -> pool_cache_put_slow -> pool_get -> pmap_kenter_pa)


# 1.13 23-Jul-2018 ryo

* fix icache invalidations.
* "ic ivau" (aarch64_icache_sync_range) with VA generates permission fault in some situations, therefore use KSEG address for now.


# 1.12 23-Jul-2018 ryo

rather than using flags to resolve nested locks, reserve pool_cache before locking.


# 1.11 21-Jul-2018 ryo

* avoid deadlock. mutex_owned() works only for adaptive lock, therefore we cannot use it for spinlock...
* add more NULL check
* clear pte when pmap_enter() fails


# 1.10 17-Jul-2018 ryo

Use __debugused


# 1.9 17-Jul-2018 christos

Add missing casts, remove unused variables.


# 1.8 09-Jul-2018 ryo

need locks in pmap_kremove() and pmap_fault_fixup()


Revision tags: phil-wifi-base pgoyette-compat-0625 pgoyette-compat-0521
# 1.7 20-May-2018 ryo

branches: 1.7.2;
pmap_enter() must update modified/referenced flags by 'flags' not 'prot'.


# 1.6 16-May-2018 ryo

Fix memory leak. it was leaking one page every pmap_create().
pm->pm_vmlist must be initialized before calling _pmap_alloc_pdp().


Revision tags: pgoyette-compat-0502
# 1.5 29-Apr-2018 ryo

fix KASSERT panic. pv_entry may not be exists in pvlist when pmap_remove().


# 1.4 29-Apr-2018 ryo

delete unused code


# 1.3 27-Apr-2018 ryo

fix instability behavior of bufcache on aarch64.
* fix to return correct ref/mod when PMAP_WIRED.
* changed to keep wired flags in pte instead of pv_entry, and cleanup.


Revision tags: pgoyette-compat-0422 pgoyette-compat-0415 pgoyette-compat-0407
# 1.2 01-Apr-2018 ryo

Add initial support for ARMv8 (AARCH64) (by nisimura@ and ryo@)

- sys/arch/evbarm64 is gone and integrated into sys/arch/evbarm. (by skrll@)
- add support fdt. evbarm/conf/GENERIC64 fdt (bcm2837,sunxi,tegra) based generic 64bit kernel config. (by skrll@, jmcneill@)


Revision tags: netbsd-8-2-RELEASE netbsd-8-1-RELEASE netbsd-8-1-RC1 netbsd-7-2-RELEASE netbsd-8-0-RELEASE netbsd-8-0-RC2 netbsd-8-0-RC1 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 netbsd-7-1-2-RELEASE pgoyette-compat-base netbsd-7-1-1-RELEASE tls-maxphys-base-20171202 matt-nb8-mediatek-base nick-nhusb-base-20170825 perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base pgoyette-localcount-20170320 netbsd-7-1-RELEASE netbsd-7-1-RC2 nick-nhusb-base-20170204 netbsd-7-nhusb-base-20170116 bouyer-socketcan-base pgoyette-localcount-20170107 netbsd-7-1-RC1 nick-nhusb-base-20161204 pgoyette-localcount-20161104 netbsd-7-0-2-RELEASE nick-nhusb-base-20161004 localcount-20160914 netbsd-7-nhusb-base pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907 nick-nhusb-base-20160529 netbsd-7-0-1-RELEASE nick-nhusb-base-20160422 nick-nhusb-base-20160319 nick-nhusb-base-20151226 netbsd-7-0-RELEASE nick-nhusb-base-20150921 netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 nick-nhusb-base-20150606 nick-nhusb-base-20150406 nick-nhusb-base tls-maxphys-base netbsd-7-base
# 1.1 10-Aug-2014 matt

branches: 1.1.4; 1.1.28;
Preliminary files for AARCH64 (64-bit ARM) support.
Enough for a distribution build.


# 1.107 30-Apr-2021 skrll

Make the ddb for pmap / pte information pmap agnostic


# 1.106 29-Apr-2021 skrll

Remove some unnecessary tlb invalidate in pmap_growkernel and ASAN shadow
map. Ensure the shadow map mappings are visible to the TLB walkers.


Revision tags: thorpej-i2c-spi-conf-base
# 1.105 21-Apr-2021 ryo

added more attributes of PTE displayed by "ddb>machine pte"


Revision tags: thorpej-cfargs-base
# 1.104 17-Apr-2021 mrg

remove KERNHIST_INIT_STATIC(). it stradles the line between usable
early in boot and broken early in boot by requiring a partly static
structure with another structure that must be present by the time
any uses are performed. theoretically platform code could allocate
a chunk while seting up memory and assign it here, giving a dynamic
sizing for the entry list, but the reality is that all users have
a statically allocated entry list as well.

the existing KERNHIST_LINK_STATIC() is used in conjunction with
KERNHIST_INITIALIZER() instead.

this stops a NULL pointer deref when the _LOG() macro is called
before the storage is linked in, which happens with GCC 10 on OCTEON
with UVMHIST enabled, crashing in very early kernel init.


Revision tags: thorpej-futex-base
# 1.103 09-Mar-2021 ryo

branches: 1.103.2;
fix build error without options DDB.

kvtopte() is referenced from arm/acpi/acpi_machdep.c


# 1.102 13-Feb-2021 ryo

No assignment is needed here.

the loop in pmap_page_remove() always removes the first pv,
and since the list is managed by _pmap_remove_pv(), pp->pp_pv.pv_next always points to the first.


# 1.101 01-Feb-2021 ryo

It is enough to make a page accessible instead of writable.
same fix as r1.76


# 1.100 31-Jan-2021 ryo

implement pmap_remove_all().

The size of struct pv_entry has increased, but speed of kernel build has improved by about 1%
exec and exit should have been improved.


# 1.99 20-Dec-2020 skrll

Improve the English in the previous comment fix.


# 1.98 19-Dec-2020 skrll

Tweak a comment


# 1.97 11-Dec-2020 skrll

s:aarch64/cpufunc.h:arm/cpufunc.h:

a baby step in the grand arm header unification challenge


# 1.96 10-Nov-2020 skrll

AA64 is not MIPS.

Change all KSEG references to directmap


# 1.95 07-Nov-2020 skrll

In pmap_devmap_bootstrap only set pmap_devmap_bootstrap_done if there
is an entry and ALL of the entries have been done. The entry required
for EARLYCONS might not be the first/only one...


# 1.94 01-Nov-2020 jmcneill

branches: 1.94.2;
No need to disable translation table walks in pmap_activate().


# 1.93 22-Oct-2020 skrll

Use the isb macro - missed in previous commit


# 1.92 22-Oct-2020 skrll

Use the dmb/dsb/isb macros... if nothing else they're all now consistent
about the "memory" assembler contraint.

No binary change


# 1.91 28-Sep-2020 skrll

Only set pmap_devmap_bootstrap_done if something gets mapped.

Think acpi_platform_devmap


# 1.90 19-Sep-2020 skrll

Make __md_palloc pmap agnostic (think sys/uvm/pmap)


# 1.89 14-Sep-2020 ryo

PID_MAX is just an initial value (soft maximum). Don't use it for CTASSERT.
defined __HAVE_CPU_MAXPROC to use function cpu_maxproc().

pointed out by mrg@, thanks.


# 1.88 06-Sep-2020 ryo

Fix panic caused by modload. http://mail-index.netbsd.org/port-arm/2020/08/30/msg006960.html

The address space reserved for modules may not be mapped in L1-L3.


# 1.87 14-Aug-2020 skrll

Whitespace


# 1.86 12-Aug-2020 skrll

Part IV of ad's performance improvements for aarch64

- Implement pmap_growkernel(), and update kernel pmap's stats with atomics.

- Then, pmap_kenter_pa() and pmap_kremove() no longer need to allocate
memory nor take pm_lock, because they only modify L3 PTEs.

- Then, pm_lock and pp_lock can be adaptive mutexes at IPL_NONE which are
cheaper than spin mutexes.

- Take the pmap's lock in pmap_extract() if not the kernel's pmap, otherwise
pmap_extract() might see inconsistent state.


# 1.85 09-Aug-2020 skrll

Fix another UVMHIST so it doesn't use %s


# 1.84 16-Jul-2020 skrll

pmapboot_enter simplication
- bootpage_alloc in asm becomes pmapboot_pagealloc in C
- PMAPBOOT_ENTER_NOBLOCK is removed as it's not used
- PMAPBOOT_ENTER_NOOVERWRITE is removed as it's now always on
- physpage_allocator argument is removed as it's always
pmapboot_pagealloc
- Support for EARLYCONS without CONSADDR is removed so that the identity
map for CONSADDR is always known.

For the assembly files:
2 files changed, 40 insertions(+), 89 deletions(-)

LGTM ryo


# 1.83 04-Jul-2020 rin

Use tlen for temporary length variable instead of l, which is usually
used for struct lwp *.

No binary changes.


# 1.82 02-Jul-2020 rin

pmap_procwr(): sync icache even if p != curproc. This fixes applications
like GDB for arm32, that rewrite text of other process.

Thanks to ryo@ for discussion.


# 1.81 02-Jul-2020 rin

Set uvmexp.ncolors appropriately, which is required for some CPU
models with VIPT icache.

Otherwise, alias in virtual address results in inconsistent results,
at least for applications that rewrite text of other process, e.g.,
GDB for arm32.

Also, this hopefully fixes other unexpected failures due to alias.

Confirmed that there's no observable regression in performance;
difference in ``time make -j8'' for GENERIC64 kernel on BCM2837
with and without setting uvmexp.ncolors is within 0.1%.

Thanks to ryo@ for discussion.


# 1.80 27-Jun-2020 rin

Fix typo in name of evcnt(4) counter.


# 1.79 24-Jun-2020 ryo

Fix bug with incorrect range calculation when doing icache sync.
This is called by sysarch(ARM_SYNC_ICACHE) from aarch32 (compat_netbsd32) emul process.

pointed out by rin@, thanks.

XXX pullup-9


# 1.78 14-Jun-2020 ad

- Fix a lock order reversal in pmap_page_protect().

- Make sure pmap is always locked when updating stats; atomics no longer
needed to do that.

- Remove unneeded traversal of pv list in pmap_enter_pv().

- Shrink struct vm_page from 136 to 128 bytes (cache line sized) and struct
pv_entry from 48 to 32 bytes (power of 2 sized).

- Embed a pv_entry in each vm_page. This means PV entries don't need to
be allocated for private anonymous memory / COW pages / most UBC mappings.
Dynamic PV entries are then used only for stuff like shared libraries and
shared memory.

Proposed on port-arm@.


# 1.77 10-Jun-2020 ad

- Wired/resident stats shouldn't covered by PMAPCOUNTERS.
- Rename need_update_pv -> need_enter_pv.

Ok ryo@


# 1.76 01-Jun-2020 ryo

no need to make the PTE writable to do icache_sync, enough to accessible.


# 1.75 15-May-2020 skrll

Use __diagused


# 1.74 15-May-2020 tnn

fix non-diag build


# 1.73 14-May-2020 skrll

Use MUTEX_NODEBUG for PV locks as is commonly done. OK ryo.


# 1.72 13-May-2020 jmcneill

Implement pmap_extract_coherency


Revision tags: bouyer-xenpvh-base2 phil-wifi-20200421 bouyer-xenpvh-base1
# 1.71 18-Apr-2020 skrll

PMAP_DEBUG has been deleted on arm


# 1.70 13-Apr-2020 maxv

Add support for Branch Target Identification (BTI).

On the executable pages that have the GP (Guarded Page) bit, the semantic
of the "br" and "blr" instructions is changed: the CPU expects the first
instruction of the jump/call target to be "bti", and faults if it isn't.

We add the GP bit on the kernel .text pages (and incidentally the .rodata
pages, but we don't care). The compiler adds a "bti c" instruction at the
beginning of each C function. We modify the ENTRY() macros to manually add
"bti c" in the asm functions.

cpuswitch.S needs a specific change: with "br x27" the CPU expects "bti j",
which is bad because the functions begin with "bti c"; switch to "br x16",
for the CPU to accept "bti c".

BTI helps defend against JOP/COP. Tested on Qemu.


Revision tags: phil-wifi-20200411 bouyer-xenpvh-base
# 1.69 08-Apr-2020 ryo

branches: 1.69.2;
use PMAP_PAGE_INIT() to initialize mutex in pmap_page.

VM_MDPAGE_INIT() in pmap_free_pdp() had initialized pp_flags,
so it unintentionally cleared PMAP_PAGE_FLAGS_PV_TRACKED.
use PMAP_PAGE_INIT to avoid using PMAP_PAGE_FLAGS_PV_TRACKED.

pointed out by tnn@, thanks


Revision tags: phil-wifi-20200406
# 1.68 14-Mar-2020 ad

pmap_remove_all(): Return a boolean value to indicate the behaviour. If
true, all mappings have been removed, the pmap is totally cleared out, and
UVM can then avoid doing the work to call pmap_remove() for each map entry.
If false, either nothing has been done, or some helpful arch-specific voodoo
has taken place.


Revision tags: is-mlppp-base
# 1.67 02-Mar-2020 ryo

oops, fix incorrect usage of daif_enable() in my previous commit.


# 1.66 29-Feb-2020 ryo

Fix pmap to work correctly with tagged addresses

- when fault, untag from address before passing to uvm/pmap functions
- pmap_extract() checks more strictly and consider the address tag


# 1.65 29-Feb-2020 ryo

use pmapboot_enter_range()


Revision tags: ad-namecache-base3
# 1.64 10-Feb-2020 ryo

use LIST(3) instead of TAILQ(3) to save one word in struct vm_page and struct pmap.

pointed out by riastradh@. thanks


# 1.63 03-Feb-2020 ryo

add support pmap_pv(9)

Patch originally from jmcneill@. thanks


# 1.62 03-Feb-2020 ryo

separate struct vm_page_md into vm_page_md and pmap_page
for preparation pmap_pv(9)


Revision tags: ad-namecache-base2 ad-namecache-base1
# 1.61 09-Jan-2020 ryo

fix behaviour mmap()/mprotect() when passed only PROT_EXEC.

when mmap()/mprotect() with only PROT_EXEC, syscall will be successful,
but the page actually hadn't been mapped.
it should be mapped with PROT_READ|PROT_EXEC implicitly. (r-x)


Revision tags: ad-namecache-base
# 1.60 30-Dec-2019 skrll

branches: 1.60.2;
Update pmap_map_chunk to allow L[12] block mappings and L3 page mappings


# 1.59 30-Dec-2019 skrll

Remove unnecessary brackets and unwrap a conditional. Same code before
and after.


# 1.58 28-Dec-2019 jmcneill

Do not use Early Write Acknowledge for PCIe I/O and config space.


# 1.57 27-Dec-2019 jmcneill

Enable early write acknowledge for device memory mappings.


# 1.56 19-Dec-2019 skrll

G/C kasan_shadow_map call in pmap_enter

pmap_growkernel calls kasan_shadow_map for KVA


# 1.55 18-Dec-2019 ryo

atomic_add_16() is not used in pmap.c anymore. no need decl here.


# 1.54 18-Dec-2019 ryo

space to tab


# 1.53 14-Dec-2019 skrll

Fix build... wire_count probably doesn't need atomics


# 1.52 13-Dec-2019 skrll

Fix KASAN support by calling kasan_shadow_map in pmap_growkernel


# 1.51 10-Dec-2019 ad

pg->phys_addr -> VM_PAGE_TO_PHYS(pg)


Revision tags: phil-wifi-20191119
# 1.50 14-Nov-2019 maxv

Mark several kASan functions with __nothing, to avoid annoying #ifdefs.
Same as kCSan and kMSan.


# 1.49 14-Nov-2019 maxv

Don't include "opt_kasan.h" when there's already <sys/asan.h> included.


# 1.48 29-Oct-2019 maya

Define PMAP_NEED_PROCWR, providing strategically placed i-cache
synchronization where just-changed memory is about to be executed.

Fixes SIGILLs seen when running Mono 6 on QEMU Cortex-A57.

ok ryo


# 1.47 22-Sep-2019 jmcneill

Disable translation table walks using TTBR0 while changing its value and
when deactivating a pmap. Fixes stability issues on Ampere eMAG CPUs.


# 1.46 20-Sep-2019 ryo

ref/mod bit should be set according to 'flags' argument, not 'prot'. r1.44 was incomplete.


# 1.45 13-Sep-2019 ryo

In pmap_devmap_bootstrap(), cpu_earlydevice_va_p() must not return true until *all* devmap tables have been enabled.
console mapping may be present in the last table.


# 1.44 07-Sep-2019 ryo

- remove incorrect KASSERT. mmap(2) with prot=PROT_WRITE calls pmap_enter(..., PROT_WRITE) internally.
- fix to update page reference flags when only PROT_WRITE or PROT_EXECUTE specified


# 1.43 15-Aug-2019 skrll

Make pmap_db_pte_print more terse so it's quicker on serial consoles


# 1.42 12-Aug-2019 skrll

Use PMAP_DEV in DEVMAP_ENTRY rather than pmap_map_chunk. It's clearer and
means pmap_map_chunk can be made to map other memory types.


Revision tags: netbsd-9-base phil-wifi-20190609
# 1.41 17-May-2019 mrg

branches: 1.41.2;
apply some __diagused.


Revision tags: isaki-audio2-base
# 1.40 08-Apr-2019 ryo

- free empty page tables pages if reach a certain usage.
- need to lock at removing an old pg (_pmap_remove_pv) in _pmap_enter()


# 1.39 06-Apr-2019 ryo

Fix race conditions about pmap_page_protect() and pmap_enter().

while handling same PTE by these functions in same time, there
is a critical path that the number of valid PTEs and wire_count
are inconsistent, and it caused KASSERT.
Need to hold a pv_lock while modifying them.


# 1.38 20-Mar-2019 ryo

spinkle __printflike(), and use PRIxxx


# 1.37 19-Mar-2019 ryo

- add ddb command "machine ttbr" to dump MMU tables.
- tidy up descriptions, usages and messages.


# 1.36 19-Mar-2019 ryo

- free L1-L3 pages that has been emptied by pmap_remove().
- if no memories, pmap_enter will return correctly ENOMEM if PMAP_CANFAIL, or wait until available any memories if !PMAP_CANFAIL.

These changes improves the stability when we use a huge virtual memory spaces with mmap.


# 1.35 06-Feb-2019 ryo

improve pmap_remove
- don't lock/unlock per page in pmap_remove()
- speedup pte lookup for continuous addresses
- bring out pool_cache_put(&_pmap_pv_pool, pv) from lock/unlock section


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226
# 1.34 21-Dec-2018 ryo

- add workaround for Cavium ThunderX errata 27456.
- add cpufuncs table in cpu_info. each cpu clusters may have different erratum. (e.g. big.LITTLE)


Revision tags: pgoyette-compat-1126
# 1.33 01-Nov-2018 maxv

Add kASan support for aarch64. Stack tracking needs more investigation
and will come in a separate commit.

Reviewed by ryo@ jmcneill@ skrll@.


# 1.32 31-Oct-2018 ryo

invalidate icache correctly.
l3pte_executable() should be used for only valid pte.


Revision tags: pgoyette-compat-1020
# 1.31 18-Oct-2018 skrll

Provide generic start code that assumes the MMU is off and caches are
disabled as per the linux booting protocol for ARMv6 and ARMv7 boards.
u-boot image type should be changed to 'linux' for correct behaviour.

The new start code builds a minimal "bootstrap" L1PT with cached access
disabled and uses the same table for all processors. AP startup is
performed in less steps and more code is written in C.

The bootstrap tables and stack are placed into an (orphaned) section
"_init_memory" which is given to uvm when it is no longer used.

Various kernels have been converted to use this code and tested. Some
boards were provided by TNF. Thanks!

The GENERIC kernel now boots on boards using the TEGRA, SUNXI and EXYNOS
kernels. The GENERIC kernel will also work on RPI2 using u-boot.

Thanks to martin@ and aymeric@ for testing on parallella and nanosoc
respectively


# 1.30 14-Oct-2018 skrll

Use __nothing


# 1.29 12-Oct-2018 ryo

add initial support of COMPAT_NETBSD32 on AArch64.
arm ELF32 EABI binaries could be execute in AArch32 state on AArch64. A32 THUMB mode is not supported yet.


# 1.28 12-Oct-2018 ryo

- cleanup checking address ranges with IN_RANGE macro
- change PM_ADDR_CHECK macro to KASSERTMSG
- restore fast lookup cases with IN_RANGE macro for pmap_extract changed in my previous commit.


# 1.27 12-Oct-2018 ryo

rewrite pmap_pte_lookup() to share similar code.


# 1.26 04-Oct-2018 ryo

cleanup locore, and changed the way to map memories during boot.
- add functions bootpage_enter() and bootpage_alloc() to adapt various layout
of physical memory map. especially for 64bit physical memory layout.
pmapboot_alloc() allocates pagetable pages from _end[].
- changed to map only the required amount for PA=VA identity mapping
(kernel image, UART device, and FDT blob) with L2_BLOCK(2Mbyte).
- changing page permission for kernel image, and making KSEG mapping are done
at cpu_kernel_vm_init() instead of at locore.
- optimize PTE entries with PTE Contiguous bit. it is enabled on devmap only for now.

reviewed by skrll@, thanks.


# 1.25 04-Oct-2018 ryo

* define LX_BLKPAG_{OS,ATTR}_* for OS dependent PTE attributes in pmap.h
* cleanup macros


Revision tags: pgoyette-compat-0930
# 1.24 17-Sep-2018 ryo

delete debug printf and KASSERT.


# 1.23 10-Sep-2018 maxv

Replace KDASSERT by panic.


# 1.22 10-Sep-2018 maxv

Rename _pmap_alloc_pdp -> pmap_alloc_pdp, and make it public.


# 1.21 10-Sep-2018 ryo

cleanup aarch64 mpstart and fdt bootstrap
* arm_cpu_hatch_arg is a bad idea. avoid serializing CPU startup, and eliminate arm_cpu_hatch_arg.
in mpstart, resolve own cpu index using array of cpu_mpidr[] (aarch64)
* add support fdt enable-method "spin-table"
* add support fdt enable-method "brcm,bcm2836-smp" (for 32bit RaspberryPi)
* use arm_fdt_cpu_bootstrap() instead of psci_fdt_bootstrap()
* rename "arm/fdt/psci_fdt.h" to "arm/fdt/psci_fdtvar.h" because of conflict of include file for needs-flag
* add devmap for cpu spin-table of raspberrypi3/aarch64
* no need to force hatch APs for raspberrypi3/arm32 ifndef MULTIPROCESSOR.
* fix to work pmap_extract(kerneltext/data/bss) even if before calling pmap_bootstrap

idea to use cpu_mpidr[] by jmcneill@. reviewd by skrll@. thanks.


Revision tags: pgoyette-compat-0906
# 1.20 27-Aug-2018 ryo

need to add VM_PROT_READ when pmap_kenter_pa(va, pa, VM_PROT_WRITE, 0) or pmap_kenter_pa(va, pa, VM_PROT_EXECUTE, 0).
VM_PROT_READ is treated as an access permission inernally.


# 1.19 11-Aug-2018 ryo

change to minimum invalidation of TLB.
specifying not only va but also asid, and not invalidate L0-L2 entry using tlbi_*_ll() if needed.


# 1.18 10-Aug-2018 ryo

treat kernel-exec attr and user-exec attr separately.
kernel cannot execute userland exec page, and user cannot execute kernel page.


# 1.17 06-Aug-2018 ryo

set kernel text/rodata readonly by default.
add function db_write_text() for setting ddb breakpoint.


# 1.16 31-Jul-2018 skrll

Define and use VPRINTF


Revision tags: pgoyette-compat-0728
# 1.15 27-Jul-2018 ryo

changes of pmap.c r1.13 seems to be unstable.
In order to invalidate icache, not to invalidate all icache,
but temporary to make the page writable and invalidate target address only.


# 1.14 24-Jul-2018 ryo

don't call pool_cache_put with locking pmap. pool_cache_put call pmap_kenter_pa internally.
(pool_cache_put_paddr -> pool_cache_put_slow -> pool_get -> pmap_kenter_pa)


# 1.13 23-Jul-2018 ryo

* fix icache invalidations.
* "ic ivau" (aarch64_icache_sync_range) with VA generates permission fault in some situations, therefore use KSEG address for now.


# 1.12 23-Jul-2018 ryo

rather than using flags to resolve nested locks, reserve pool_cache before locking.


# 1.11 21-Jul-2018 ryo

* avoid deadlock. mutex_owned() works only for adaptive lock, therefore we cannot use it for spinlock...
* add more NULL check
* clear pte when pmap_enter() fails


# 1.10 17-Jul-2018 ryo

Use __debugused


# 1.9 17-Jul-2018 christos

Add missing casts, remove unused variables.


# 1.8 09-Jul-2018 ryo

need locks in pmap_kremove() and pmap_fault_fixup()


Revision tags: phil-wifi-base pgoyette-compat-0625 pgoyette-compat-0521
# 1.7 20-May-2018 ryo

branches: 1.7.2;
pmap_enter() must update modified/referenced flags by 'flags' not 'prot'.


# 1.6 16-May-2018 ryo

Fix memory leak. it was leaking one page every pmap_create().
pm->pm_vmlist must be initialized before calling _pmap_alloc_pdp().


Revision tags: pgoyette-compat-0502
# 1.5 29-Apr-2018 ryo

fix KASSERT panic. pv_entry may not be exists in pvlist when pmap_remove().


# 1.4 29-Apr-2018 ryo

delete unused code


# 1.3 27-Apr-2018 ryo

fix instability behavior of bufcache on aarch64.
* fix to return correct ref/mod when PMAP_WIRED.
* changed to keep wired flags in pte instead of pv_entry, and cleanup.


Revision tags: pgoyette-compat-0422 pgoyette-compat-0415 pgoyette-compat-0407
# 1.2 01-Apr-2018 ryo

Add initial support for ARMv8 (AARCH64) (by nisimura@ and ryo@)

- sys/arch/evbarm64 is gone and integrated into sys/arch/evbarm. (by skrll@)
- add support fdt. evbarm/conf/GENERIC64 fdt (bcm2837,sunxi,tegra) based generic 64bit kernel config. (by skrll@, jmcneill@)


Revision tags: netbsd-8-2-RELEASE netbsd-8-1-RELEASE netbsd-8-1-RC1 netbsd-7-2-RELEASE netbsd-8-0-RELEASE netbsd-8-0-RC2 netbsd-8-0-RC1 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 netbsd-7-1-2-RELEASE pgoyette-compat-base netbsd-7-1-1-RELEASE tls-maxphys-base-20171202 matt-nb8-mediatek-base nick-nhusb-base-20170825 perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base pgoyette-localcount-20170320 netbsd-7-1-RELEASE netbsd-7-1-RC2 nick-nhusb-base-20170204 netbsd-7-nhusb-base-20170116 bouyer-socketcan-base pgoyette-localcount-20170107 netbsd-7-1-RC1 nick-nhusb-base-20161204 pgoyette-localcount-20161104 netbsd-7-0-2-RELEASE nick-nhusb-base-20161004 localcount-20160914 netbsd-7-nhusb-base pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907 nick-nhusb-base-20160529 netbsd-7-0-1-RELEASE nick-nhusb-base-20160422 nick-nhusb-base-20160319 nick-nhusb-base-20151226 netbsd-7-0-RELEASE nick-nhusb-base-20150921 netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 nick-nhusb-base-20150606 nick-nhusb-base-20150406 nick-nhusb-base tls-maxphys-base netbsd-7-base
# 1.1 10-Aug-2014 matt

branches: 1.1.4; 1.1.28;
Preliminary files for AARCH64 (64-bit ARM) support.
Enough for a distribution build.


# 1.106 29-Apr-2021 skrll

Remove some unnecessary tlb invalidate in pmap_growkernel and ASAN shadow
map. Ensure the shadow map mappings are visible to the TLB walkers.


Revision tags: thorpej-i2c-spi-conf-base
# 1.105 21-Apr-2021 ryo

added more attributes of PTE displayed by "ddb>machine pte"


Revision tags: thorpej-cfargs-base
# 1.104 17-Apr-2021 mrg

remove KERNHIST_INIT_STATIC(). it stradles the line between usable
early in boot and broken early in boot by requiring a partly static
structure with another structure that must be present by the time
any uses are performed. theoretically platform code could allocate
a chunk while seting up memory and assign it here, giving a dynamic
sizing for the entry list, but the reality is that all users have
a statically allocated entry list as well.

the existing KERNHIST_LINK_STATIC() is used in conjunction with
KERNHIST_INITIALIZER() instead.

this stops a NULL pointer deref when the _LOG() macro is called
before the storage is linked in, which happens with GCC 10 on OCTEON
with UVMHIST enabled, crashing in very early kernel init.


Revision tags: thorpej-futex-base
# 1.103 09-Mar-2021 ryo

branches: 1.103.2;
fix build error without options DDB.

kvtopte() is referenced from arm/acpi/acpi_machdep.c


# 1.102 13-Feb-2021 ryo

No assignment is needed here.

the loop in pmap_page_remove() always removes the first pv,
and since the list is managed by _pmap_remove_pv(), pp->pp_pv.pv_next always points to the first.


# 1.101 01-Feb-2021 ryo

It is enough to make a page accessible instead of writable.
same fix as r1.76


# 1.100 31-Jan-2021 ryo

implement pmap_remove_all().

The size of struct pv_entry has increased, but speed of kernel build has improved by about 1%
exec and exit should have been improved.


# 1.99 20-Dec-2020 skrll

Improve the English in the previous comment fix.


# 1.98 19-Dec-2020 skrll

Tweak a comment


# 1.97 11-Dec-2020 skrll

s:aarch64/cpufunc.h:arm/cpufunc.h:

a baby step in the grand arm header unification challenge


# 1.96 10-Nov-2020 skrll

AA64 is not MIPS.

Change all KSEG references to directmap


# 1.95 07-Nov-2020 skrll

In pmap_devmap_bootstrap only set pmap_devmap_bootstrap_done if there
is an entry and ALL of the entries have been done. The entry required
for EARLYCONS might not be the first/only one...


# 1.94 01-Nov-2020 jmcneill

branches: 1.94.2;
No need to disable translation table walks in pmap_activate().


# 1.93 22-Oct-2020 skrll

Use the isb macro - missed in previous commit


# 1.92 22-Oct-2020 skrll

Use the dmb/dsb/isb macros... if nothing else they're all now consistent
about the "memory" assembler contraint.

No binary change


# 1.91 28-Sep-2020 skrll

Only set pmap_devmap_bootstrap_done if something gets mapped.

Think acpi_platform_devmap


# 1.90 19-Sep-2020 skrll

Make __md_palloc pmap agnostic (think sys/uvm/pmap)


# 1.89 14-Sep-2020 ryo

PID_MAX is just an initial value (soft maximum). Don't use it for CTASSERT.
defined __HAVE_CPU_MAXPROC to use function cpu_maxproc().

pointed out by mrg@, thanks.


# 1.88 06-Sep-2020 ryo

Fix panic caused by modload. http://mail-index.netbsd.org/port-arm/2020/08/30/msg006960.html

The address space reserved for modules may not be mapped in L1-L3.


# 1.87 14-Aug-2020 skrll

Whitespace


# 1.86 12-Aug-2020 skrll

Part IV of ad's performance improvements for aarch64

- Implement pmap_growkernel(), and update kernel pmap's stats with atomics.

- Then, pmap_kenter_pa() and pmap_kremove() no longer need to allocate
memory nor take pm_lock, because they only modify L3 PTEs.

- Then, pm_lock and pp_lock can be adaptive mutexes at IPL_NONE which are
cheaper than spin mutexes.

- Take the pmap's lock in pmap_extract() if not the kernel's pmap, otherwise
pmap_extract() might see inconsistent state.


# 1.85 09-Aug-2020 skrll

Fix another UVMHIST so it doesn't use %s


# 1.84 16-Jul-2020 skrll

pmapboot_enter simplication
- bootpage_alloc in asm becomes pmapboot_pagealloc in C
- PMAPBOOT_ENTER_NOBLOCK is removed as it's not used
- PMAPBOOT_ENTER_NOOVERWRITE is removed as it's now always on
- physpage_allocator argument is removed as it's always
pmapboot_pagealloc
- Support for EARLYCONS without CONSADDR is removed so that the identity
map for CONSADDR is always known.

For the assembly files:
2 files changed, 40 insertions(+), 89 deletions(-)

LGTM ryo


# 1.83 04-Jul-2020 rin

Use tlen for temporary length variable instead of l, which is usually
used for struct lwp *.

No binary changes.


# 1.82 02-Jul-2020 rin

pmap_procwr(): sync icache even if p != curproc. This fixes applications
like GDB for arm32, that rewrite text of other process.

Thanks to ryo@ for discussion.


# 1.81 02-Jul-2020 rin

Set uvmexp.ncolors appropriately, which is required for some CPU
models with VIPT icache.

Otherwise, alias in virtual address results in inconsistent results,
at least for applications that rewrite text of other process, e.g.,
GDB for arm32.

Also, this hopefully fixes other unexpected failures due to alias.

Confirmed that there's no observable regression in performance;
difference in ``time make -j8'' for GENERIC64 kernel on BCM2837
with and without setting uvmexp.ncolors is within 0.1%.

Thanks to ryo@ for discussion.


# 1.80 27-Jun-2020 rin

Fix typo in name of evcnt(4) counter.


# 1.79 24-Jun-2020 ryo

Fix bug with incorrect range calculation when doing icache sync.
This is called by sysarch(ARM_SYNC_ICACHE) from aarch32 (compat_netbsd32) emul process.

pointed out by rin@, thanks.

XXX pullup-9


# 1.78 14-Jun-2020 ad

- Fix a lock order reversal in pmap_page_protect().

- Make sure pmap is always locked when updating stats; atomics no longer
needed to do that.

- Remove unneeded traversal of pv list in pmap_enter_pv().

- Shrink struct vm_page from 136 to 128 bytes (cache line sized) and struct
pv_entry from 48 to 32 bytes (power of 2 sized).

- Embed a pv_entry in each vm_page. This means PV entries don't need to
be allocated for private anonymous memory / COW pages / most UBC mappings.
Dynamic PV entries are then used only for stuff like shared libraries and
shared memory.

Proposed on port-arm@.


# 1.77 10-Jun-2020 ad

- Wired/resident stats shouldn't covered by PMAPCOUNTERS.
- Rename need_update_pv -> need_enter_pv.

Ok ryo@


# 1.76 01-Jun-2020 ryo

no need to make the PTE writable to do icache_sync, enough to accessible.


# 1.75 15-May-2020 skrll

Use __diagused


# 1.74 15-May-2020 tnn

fix non-diag build


# 1.73 14-May-2020 skrll

Use MUTEX_NODEBUG for PV locks as is commonly done. OK ryo.


# 1.72 13-May-2020 jmcneill

Implement pmap_extract_coherency


Revision tags: bouyer-xenpvh-base2 phil-wifi-20200421 bouyer-xenpvh-base1
# 1.71 18-Apr-2020 skrll

PMAP_DEBUG has been deleted on arm


# 1.70 13-Apr-2020 maxv

Add support for Branch Target Identification (BTI).

On the executable pages that have the GP (Guarded Page) bit, the semantic
of the "br" and "blr" instructions is changed: the CPU expects the first
instruction of the jump/call target to be "bti", and faults if it isn't.

We add the GP bit on the kernel .text pages (and incidentally the .rodata
pages, but we don't care). The compiler adds a "bti c" instruction at the
beginning of each C function. We modify the ENTRY() macros to manually add
"bti c" in the asm functions.

cpuswitch.S needs a specific change: with "br x27" the CPU expects "bti j",
which is bad because the functions begin with "bti c"; switch to "br x16",
for the CPU to accept "bti c".

BTI helps defend against JOP/COP. Tested on Qemu.


Revision tags: phil-wifi-20200411 bouyer-xenpvh-base
# 1.69 08-Apr-2020 ryo

branches: 1.69.2;
use PMAP_PAGE_INIT() to initialize mutex in pmap_page.

VM_MDPAGE_INIT() in pmap_free_pdp() had initialized pp_flags,
so it unintentionally cleared PMAP_PAGE_FLAGS_PV_TRACKED.
use PMAP_PAGE_INIT to avoid using PMAP_PAGE_FLAGS_PV_TRACKED.

pointed out by tnn@, thanks


Revision tags: phil-wifi-20200406
# 1.68 14-Mar-2020 ad

pmap_remove_all(): Return a boolean value to indicate the behaviour. If
true, all mappings have been removed, the pmap is totally cleared out, and
UVM can then avoid doing the work to call pmap_remove() for each map entry.
If false, either nothing has been done, or some helpful arch-specific voodoo
has taken place.


Revision tags: is-mlppp-base
# 1.67 02-Mar-2020 ryo

oops, fix incorrect usage of daif_enable() in my previous commit.


# 1.66 29-Feb-2020 ryo

Fix pmap to work correctly with tagged addresses

- when fault, untag from address before passing to uvm/pmap functions
- pmap_extract() checks more strictly and consider the address tag


# 1.65 29-Feb-2020 ryo

use pmapboot_enter_range()


Revision tags: ad-namecache-base3
# 1.64 10-Feb-2020 ryo

use LIST(3) instead of TAILQ(3) to save one word in struct vm_page and struct pmap.

pointed out by riastradh@. thanks


# 1.63 03-Feb-2020 ryo

add support pmap_pv(9)

Patch originally from jmcneill@. thanks


# 1.62 03-Feb-2020 ryo

separate struct vm_page_md into vm_page_md and pmap_page
for preparation pmap_pv(9)


Revision tags: ad-namecache-base2 ad-namecache-base1
# 1.61 09-Jan-2020 ryo

fix behaviour mmap()/mprotect() when passed only PROT_EXEC.

when mmap()/mprotect() with only PROT_EXEC, syscall will be successful,
but the page actually hadn't been mapped.
it should be mapped with PROT_READ|PROT_EXEC implicitly. (r-x)


Revision tags: ad-namecache-base
# 1.60 30-Dec-2019 skrll

branches: 1.60.2;
Update pmap_map_chunk to allow L[12] block mappings and L3 page mappings


# 1.59 30-Dec-2019 skrll

Remove unnecessary brackets and unwrap a conditional. Same code before
and after.


# 1.58 28-Dec-2019 jmcneill

Do not use Early Write Acknowledge for PCIe I/O and config space.


# 1.57 27-Dec-2019 jmcneill

Enable early write acknowledge for device memory mappings.


# 1.56 19-Dec-2019 skrll

G/C kasan_shadow_map call in pmap_enter

pmap_growkernel calls kasan_shadow_map for KVA


# 1.55 18-Dec-2019 ryo

atomic_add_16() is not used in pmap.c anymore. no need decl here.


# 1.54 18-Dec-2019 ryo

space to tab


# 1.53 14-Dec-2019 skrll

Fix build... wire_count probably doesn't need atomics


# 1.52 13-Dec-2019 skrll

Fix KASAN support by calling kasan_shadow_map in pmap_growkernel


# 1.51 10-Dec-2019 ad

pg->phys_addr -> VM_PAGE_TO_PHYS(pg)


Revision tags: phil-wifi-20191119
# 1.50 14-Nov-2019 maxv

Mark several kASan functions with __nothing, to avoid annoying #ifdefs.
Same as kCSan and kMSan.


# 1.49 14-Nov-2019 maxv

Don't include "opt_kasan.h" when there's already <sys/asan.h> included.


# 1.48 29-Oct-2019 maya

Define PMAP_NEED_PROCWR, providing strategically placed i-cache
synchronization where just-changed memory is about to be executed.

Fixes SIGILLs seen when running Mono 6 on QEMU Cortex-A57.

ok ryo


# 1.47 22-Sep-2019 jmcneill

Disable translation table walks using TTBR0 while changing its value and
when deactivating a pmap. Fixes stability issues on Ampere eMAG CPUs.


# 1.46 20-Sep-2019 ryo

ref/mod bit should be set according to 'flags' argument, not 'prot'. r1.44 was incomplete.


# 1.45 13-Sep-2019 ryo

In pmap_devmap_bootstrap(), cpu_earlydevice_va_p() must not return true until *all* devmap tables have been enabled.
console mapping may be present in the last table.


# 1.44 07-Sep-2019 ryo

- remove incorrect KASSERT. mmap(2) with prot=PROT_WRITE calls pmap_enter(..., PROT_WRITE) internally.
- fix to update page reference flags when only PROT_WRITE or PROT_EXECUTE specified


# 1.43 15-Aug-2019 skrll

Make pmap_db_pte_print more terse so it's quicker on serial consoles


# 1.42 12-Aug-2019 skrll

Use PMAP_DEV in DEVMAP_ENTRY rather than pmap_map_chunk. It's clearer and
means pmap_map_chunk can be made to map other memory types.


Revision tags: netbsd-9-base phil-wifi-20190609
# 1.41 17-May-2019 mrg

branches: 1.41.2;
apply some __diagused.


Revision tags: isaki-audio2-base
# 1.40 08-Apr-2019 ryo

- free empty page tables pages if reach a certain usage.
- need to lock at removing an old pg (_pmap_remove_pv) in _pmap_enter()


# 1.39 06-Apr-2019 ryo

Fix race conditions about pmap_page_protect() and pmap_enter().

while handling same PTE by these functions in same time, there
is a critical path that the number of valid PTEs and wire_count
are inconsistent, and it caused KASSERT.
Need to hold a pv_lock while modifying them.


# 1.38 20-Mar-2019 ryo

spinkle __printflike(), and use PRIxxx


# 1.37 19-Mar-2019 ryo

- add ddb command "machine ttbr" to dump MMU tables.
- tidy up descriptions, usages and messages.


# 1.36 19-Mar-2019 ryo

- free L1-L3 pages that has been emptied by pmap_remove().
- if no memories, pmap_enter will return correctly ENOMEM if PMAP_CANFAIL, or wait until available any memories if !PMAP_CANFAIL.

These changes improves the stability when we use a huge virtual memory spaces with mmap.


# 1.35 06-Feb-2019 ryo

improve pmap_remove
- don't lock/unlock per page in pmap_remove()
- speedup pte lookup for continuous addresses
- bring out pool_cache_put(&_pmap_pv_pool, pv) from lock/unlock section


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226
# 1.34 21-Dec-2018 ryo

- add workaround for Cavium ThunderX errata 27456.
- add cpufuncs table in cpu_info. each cpu clusters may have different erratum. (e.g. big.LITTLE)


Revision tags: pgoyette-compat-1126
# 1.33 01-Nov-2018 maxv

Add kASan support for aarch64. Stack tracking needs more investigation
and will come in a separate commit.

Reviewed by ryo@ jmcneill@ skrll@.


# 1.32 31-Oct-2018 ryo

invalidate icache correctly.
l3pte_executable() should be used for only valid pte.


Revision tags: pgoyette-compat-1020
# 1.31 18-Oct-2018 skrll

Provide generic start code that assumes the MMU is off and caches are
disabled as per the linux booting protocol for ARMv6 and ARMv7 boards.
u-boot image type should be changed to 'linux' for correct behaviour.

The new start code builds a minimal "bootstrap" L1PT with cached access
disabled and uses the same table for all processors. AP startup is
performed in less steps and more code is written in C.

The bootstrap tables and stack are placed into an (orphaned) section
"_init_memory" which is given to uvm when it is no longer used.

Various kernels have been converted to use this code and tested. Some
boards were provided by TNF. Thanks!

The GENERIC kernel now boots on boards using the TEGRA, SUNXI and EXYNOS
kernels. The GENERIC kernel will also work on RPI2 using u-boot.

Thanks to martin@ and aymeric@ for testing on parallella and nanosoc
respectively


# 1.30 14-Oct-2018 skrll

Use __nothing


# 1.29 12-Oct-2018 ryo

add initial support of COMPAT_NETBSD32 on AArch64.
arm ELF32 EABI binaries could be execute in AArch32 state on AArch64. A32 THUMB mode is not supported yet.


# 1.28 12-Oct-2018 ryo

- cleanup checking address ranges with IN_RANGE macro
- change PM_ADDR_CHECK macro to KASSERTMSG
- restore fast lookup cases with IN_RANGE macro for pmap_extract changed in my previous commit.


# 1.27 12-Oct-2018 ryo

rewrite pmap_pte_lookup() to share similar code.


# 1.26 04-Oct-2018 ryo

cleanup locore, and changed the way to map memories during boot.
- add functions bootpage_enter() and bootpage_alloc() to adapt various layout
of physical memory map. especially for 64bit physical memory layout.
pmapboot_alloc() allocates pagetable pages from _end[].
- changed to map only the required amount for PA=VA identity mapping
(kernel image, UART device, and FDT blob) with L2_BLOCK(2Mbyte).
- changing page permission for kernel image, and making KSEG mapping are done
at cpu_kernel_vm_init() instead of at locore.
- optimize PTE entries with PTE Contiguous bit. it is enabled on devmap only for now.

reviewed by skrll@, thanks.


# 1.25 04-Oct-2018 ryo

* define LX_BLKPAG_{OS,ATTR}_* for OS dependent PTE attributes in pmap.h
* cleanup macros


Revision tags: pgoyette-compat-0930
# 1.24 17-Sep-2018 ryo

delete debug printf and KASSERT.


# 1.23 10-Sep-2018 maxv

Replace KDASSERT by panic.


# 1.22 10-Sep-2018 maxv

Rename _pmap_alloc_pdp -> pmap_alloc_pdp, and make it public.


# 1.21 10-Sep-2018 ryo

cleanup aarch64 mpstart and fdt bootstrap
* arm_cpu_hatch_arg is a bad idea. avoid serializing CPU startup, and eliminate arm_cpu_hatch_arg.
in mpstart, resolve own cpu index using array of cpu_mpidr[] (aarch64)
* add support fdt enable-method "spin-table"
* add support fdt enable-method "brcm,bcm2836-smp" (for 32bit RaspberryPi)
* use arm_fdt_cpu_bootstrap() instead of psci_fdt_bootstrap()
* rename "arm/fdt/psci_fdt.h" to "arm/fdt/psci_fdtvar.h" because of conflict of include file for needs-flag
* add devmap for cpu spin-table of raspberrypi3/aarch64
* no need to force hatch APs for raspberrypi3/arm32 ifndef MULTIPROCESSOR.
* fix to work pmap_extract(kerneltext/data/bss) even if before calling pmap_bootstrap

idea to use cpu_mpidr[] by jmcneill@. reviewd by skrll@. thanks.


Revision tags: pgoyette-compat-0906
# 1.20 27-Aug-2018 ryo

need to add VM_PROT_READ when pmap_kenter_pa(va, pa, VM_PROT_WRITE, 0) or pmap_kenter_pa(va, pa, VM_PROT_EXECUTE, 0).
VM_PROT_READ is treated as an access permission inernally.


# 1.19 11-Aug-2018 ryo

change to minimum invalidation of TLB.
specifying not only va but also asid, and not invalidate L0-L2 entry using tlbi_*_ll() if needed.


# 1.18 10-Aug-2018 ryo

treat kernel-exec attr and user-exec attr separately.
kernel cannot execute userland exec page, and user cannot execute kernel page.


# 1.17 06-Aug-2018 ryo

set kernel text/rodata readonly by default.
add function db_write_text() for setting ddb breakpoint.


# 1.16 31-Jul-2018 skrll

Define and use VPRINTF


Revision tags: pgoyette-compat-0728
# 1.15 27-Jul-2018 ryo

changes of pmap.c r1.13 seems to be unstable.
In order to invalidate icache, not to invalidate all icache,
but temporary to make the page writable and invalidate target address only.


# 1.14 24-Jul-2018 ryo

don't call pool_cache_put with locking pmap. pool_cache_put call pmap_kenter_pa internally.
(pool_cache_put_paddr -> pool_cache_put_slow -> pool_get -> pmap_kenter_pa)


# 1.13 23-Jul-2018 ryo

* fix icache invalidations.
* "ic ivau" (aarch64_icache_sync_range) with VA generates permission fault in some situations, therefore use KSEG address for now.


# 1.12 23-Jul-2018 ryo

rather than using flags to resolve nested locks, reserve pool_cache before locking.


# 1.11 21-Jul-2018 ryo

* avoid deadlock. mutex_owned() works only for adaptive lock, therefore we cannot use it for spinlock...
* add more NULL check
* clear pte when pmap_enter() fails


# 1.10 17-Jul-2018 ryo

Use __debugused


# 1.9 17-Jul-2018 christos

Add missing casts, remove unused variables.


# 1.8 09-Jul-2018 ryo

need locks in pmap_kremove() and pmap_fault_fixup()


Revision tags: phil-wifi-base pgoyette-compat-0625 pgoyette-compat-0521
# 1.7 20-May-2018 ryo

branches: 1.7.2;
pmap_enter() must update modified/referenced flags by 'flags' not 'prot'.


# 1.6 16-May-2018 ryo

Fix memory leak. it was leaking one page every pmap_create().
pm->pm_vmlist must be initialized before calling _pmap_alloc_pdp().


Revision tags: pgoyette-compat-0502
# 1.5 29-Apr-2018 ryo

fix KASSERT panic. pv_entry may not be exists in pvlist when pmap_remove().


# 1.4 29-Apr-2018 ryo

delete unused code


# 1.3 27-Apr-2018 ryo

fix instability behavior of bufcache on aarch64.
* fix to return correct ref/mod when PMAP_WIRED.
* changed to keep wired flags in pte instead of pv_entry, and cleanup.


Revision tags: pgoyette-compat-0422 pgoyette-compat-0415 pgoyette-compat-0407
# 1.2 01-Apr-2018 ryo

Add initial support for ARMv8 (AARCH64) (by nisimura@ and ryo@)

- sys/arch/evbarm64 is gone and integrated into sys/arch/evbarm. (by skrll@)
- add support fdt. evbarm/conf/GENERIC64 fdt (bcm2837,sunxi,tegra) based generic 64bit kernel config. (by skrll@, jmcneill@)


Revision tags: netbsd-8-2-RELEASE netbsd-8-1-RELEASE netbsd-8-1-RC1 netbsd-7-2-RELEASE netbsd-8-0-RELEASE netbsd-8-0-RC2 netbsd-8-0-RC1 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 netbsd-7-1-2-RELEASE pgoyette-compat-base netbsd-7-1-1-RELEASE tls-maxphys-base-20171202 matt-nb8-mediatek-base nick-nhusb-base-20170825 perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base pgoyette-localcount-20170320 netbsd-7-1-RELEASE netbsd-7-1-RC2 nick-nhusb-base-20170204 netbsd-7-nhusb-base-20170116 bouyer-socketcan-base pgoyette-localcount-20170107 netbsd-7-1-RC1 nick-nhusb-base-20161204 pgoyette-localcount-20161104 netbsd-7-0-2-RELEASE nick-nhusb-base-20161004 localcount-20160914 netbsd-7-nhusb-base pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907 nick-nhusb-base-20160529 netbsd-7-0-1-RELEASE nick-nhusb-base-20160422 nick-nhusb-base-20160319 nick-nhusb-base-20151226 netbsd-7-0-RELEASE nick-nhusb-base-20150921 netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 nick-nhusb-base-20150606 nick-nhusb-base-20150406 nick-nhusb-base tls-maxphys-base netbsd-7-base
# 1.1 10-Aug-2014 matt

branches: 1.1.4; 1.1.28;
Preliminary files for AARCH64 (64-bit ARM) support.
Enough for a distribution build.


# 1.105 21-Apr-2021 ryo

added more attributes of PTE displayed by "ddb>machine pte"


Revision tags: thorpej-cfargs-base
# 1.104 17-Apr-2021 mrg

remove KERNHIST_INIT_STATIC(). it stradles the line between usable
early in boot and broken early in boot by requiring a partly static
structure with another structure that must be present by the time
any uses are performed. theoretically platform code could allocate
a chunk while seting up memory and assign it here, giving a dynamic
sizing for the entry list, but the reality is that all users have
a statically allocated entry list as well.

the existing KERNHIST_LINK_STATIC() is used in conjunction with
KERNHIST_INITIALIZER() instead.

this stops a NULL pointer deref when the _LOG() macro is called
before the storage is linked in, which happens with GCC 10 on OCTEON
with UVMHIST enabled, crashing in very early kernel init.


Revision tags: thorpej-futex-base
# 1.103 09-Mar-2021 ryo

branches: 1.103.2;
fix build error without options DDB.

kvtopte() is referenced from arm/acpi/acpi_machdep.c


# 1.102 13-Feb-2021 ryo

No assignment is needed here.

the loop in pmap_page_remove() always removes the first pv,
and since the list is managed by _pmap_remove_pv(), pp->pp_pv.pv_next always points to the first.


# 1.101 01-Feb-2021 ryo

It is enough to make a page accessible instead of writable.
same fix as r1.76


# 1.100 31-Jan-2021 ryo

implement pmap_remove_all().

The size of struct pv_entry has increased, but speed of kernel build has improved by about 1%
exec and exit should have been improved.


# 1.99 20-Dec-2020 skrll

Improve the English in the previous comment fix.


# 1.98 19-Dec-2020 skrll

Tweak a comment


# 1.97 11-Dec-2020 skrll

s:aarch64/cpufunc.h:arm/cpufunc.h:

a baby step in the grand arm header unification challenge


# 1.96 10-Nov-2020 skrll

AA64 is not MIPS.

Change all KSEG references to directmap


# 1.95 07-Nov-2020 skrll

In pmap_devmap_bootstrap only set pmap_devmap_bootstrap_done if there
is an entry and ALL of the entries have been done. The entry required
for EARLYCONS might not be the first/only one...


# 1.94 01-Nov-2020 jmcneill

branches: 1.94.2;
No need to disable translation table walks in pmap_activate().


# 1.93 22-Oct-2020 skrll

Use the isb macro - missed in previous commit


# 1.92 22-Oct-2020 skrll

Use the dmb/dsb/isb macros... if nothing else they're all now consistent
about the "memory" assembler contraint.

No binary change


# 1.91 28-Sep-2020 skrll

Only set pmap_devmap_bootstrap_done if something gets mapped.

Think acpi_platform_devmap


# 1.90 19-Sep-2020 skrll

Make __md_palloc pmap agnostic (think sys/uvm/pmap)


# 1.89 14-Sep-2020 ryo

PID_MAX is just an initial value (soft maximum). Don't use it for CTASSERT.
defined __HAVE_CPU_MAXPROC to use function cpu_maxproc().

pointed out by mrg@, thanks.


# 1.88 06-Sep-2020 ryo

Fix panic caused by modload. http://mail-index.netbsd.org/port-arm/2020/08/30/msg006960.html

The address space reserved for modules may not be mapped in L1-L3.


# 1.87 14-Aug-2020 skrll

Whitespace


# 1.86 12-Aug-2020 skrll

Part IV of ad's performance improvements for aarch64

- Implement pmap_growkernel(), and update kernel pmap's stats with atomics.

- Then, pmap_kenter_pa() and pmap_kremove() no longer need to allocate
memory nor take pm_lock, because they only modify L3 PTEs.

- Then, pm_lock and pp_lock can be adaptive mutexes at IPL_NONE which are
cheaper than spin mutexes.

- Take the pmap's lock in pmap_extract() if not the kernel's pmap, otherwise
pmap_extract() might see inconsistent state.


# 1.85 09-Aug-2020 skrll

Fix another UVMHIST so it doesn't use %s


# 1.84 16-Jul-2020 skrll

pmapboot_enter simplication
- bootpage_alloc in asm becomes pmapboot_pagealloc in C
- PMAPBOOT_ENTER_NOBLOCK is removed as it's not used
- PMAPBOOT_ENTER_NOOVERWRITE is removed as it's now always on
- physpage_allocator argument is removed as it's always
pmapboot_pagealloc
- Support for EARLYCONS without CONSADDR is removed so that the identity
map for CONSADDR is always known.

For the assembly files:
2 files changed, 40 insertions(+), 89 deletions(-)

LGTM ryo


# 1.83 04-Jul-2020 rin

Use tlen for temporary length variable instead of l, which is usually
used for struct lwp *.

No binary changes.


# 1.82 02-Jul-2020 rin

pmap_procwr(): sync icache even if p != curproc. This fixes applications
like GDB for arm32, that rewrite text of other process.

Thanks to ryo@ for discussion.


# 1.81 02-Jul-2020 rin

Set uvmexp.ncolors appropriately, which is required for some CPU
models with VIPT icache.

Otherwise, alias in virtual address results in inconsistent results,
at least for applications that rewrite text of other process, e.g.,
GDB for arm32.

Also, this hopefully fixes other unexpected failures due to alias.

Confirmed that there's no observable regression in performance;
difference in ``time make -j8'' for GENERIC64 kernel on BCM2837
with and without setting uvmexp.ncolors is within 0.1%.

Thanks to ryo@ for discussion.


# 1.80 27-Jun-2020 rin

Fix typo in name of evcnt(4) counter.


# 1.79 24-Jun-2020 ryo

Fix bug with incorrect range calculation when doing icache sync.
This is called by sysarch(ARM_SYNC_ICACHE) from aarch32 (compat_netbsd32) emul process.

pointed out by rin@, thanks.

XXX pullup-9


# 1.78 14-Jun-2020 ad

- Fix a lock order reversal in pmap_page_protect().

- Make sure pmap is always locked when updating stats; atomics no longer
needed to do that.

- Remove unneeded traversal of pv list in pmap_enter_pv().

- Shrink struct vm_page from 136 to 128 bytes (cache line sized) and struct
pv_entry from 48 to 32 bytes (power of 2 sized).

- Embed a pv_entry in each vm_page. This means PV entries don't need to
be allocated for private anonymous memory / COW pages / most UBC mappings.
Dynamic PV entries are then used only for stuff like shared libraries and
shared memory.

Proposed on port-arm@.


# 1.77 10-Jun-2020 ad

- Wired/resident stats shouldn't covered by PMAPCOUNTERS.
- Rename need_update_pv -> need_enter_pv.

Ok ryo@


# 1.76 01-Jun-2020 ryo

no need to make the PTE writable to do icache_sync, enough to accessible.


# 1.75 15-May-2020 skrll

Use __diagused


# 1.74 15-May-2020 tnn

fix non-diag build


# 1.73 14-May-2020 skrll

Use MUTEX_NODEBUG for PV locks as is commonly done. OK ryo.


# 1.72 13-May-2020 jmcneill

Implement pmap_extract_coherency


Revision tags: bouyer-xenpvh-base2 phil-wifi-20200421 bouyer-xenpvh-base1
# 1.71 18-Apr-2020 skrll

PMAP_DEBUG has been deleted on arm


# 1.70 13-Apr-2020 maxv

Add support for Branch Target Identification (BTI).

On the executable pages that have the GP (Guarded Page) bit, the semantic
of the "br" and "blr" instructions is changed: the CPU expects the first
instruction of the jump/call target to be "bti", and faults if it isn't.

We add the GP bit on the kernel .text pages (and incidentally the .rodata
pages, but we don't care). The compiler adds a "bti c" instruction at the
beginning of each C function. We modify the ENTRY() macros to manually add
"bti c" in the asm functions.

cpuswitch.S needs a specific change: with "br x27" the CPU expects "bti j",
which is bad because the functions begin with "bti c"; switch to "br x16",
for the CPU to accept "bti c".

BTI helps defend against JOP/COP. Tested on Qemu.


Revision tags: phil-wifi-20200411 bouyer-xenpvh-base
# 1.69 08-Apr-2020 ryo

branches: 1.69.2;
use PMAP_PAGE_INIT() to initialize mutex in pmap_page.

VM_MDPAGE_INIT() in pmap_free_pdp() had initialized pp_flags,
so it unintentionally cleared PMAP_PAGE_FLAGS_PV_TRACKED.
use PMAP_PAGE_INIT to avoid using PMAP_PAGE_FLAGS_PV_TRACKED.

pointed out by tnn@, thanks


Revision tags: phil-wifi-20200406
# 1.68 14-Mar-2020 ad

pmap_remove_all(): Return a boolean value to indicate the behaviour. If
true, all mappings have been removed, the pmap is totally cleared out, and
UVM can then avoid doing the work to call pmap_remove() for each map entry.
If false, either nothing has been done, or some helpful arch-specific voodoo
has taken place.


Revision tags: is-mlppp-base
# 1.67 02-Mar-2020 ryo

oops, fix incorrect usage of daif_enable() in my previous commit.


# 1.66 29-Feb-2020 ryo

Fix pmap to work correctly with tagged addresses

- when fault, untag from address before passing to uvm/pmap functions
- pmap_extract() checks more strictly and consider the address tag


# 1.65 29-Feb-2020 ryo

use pmapboot_enter_range()


Revision tags: ad-namecache-base3
# 1.64 10-Feb-2020 ryo

use LIST(3) instead of TAILQ(3) to save one word in struct vm_page and struct pmap.

pointed out by riastradh@. thanks


# 1.63 03-Feb-2020 ryo

add support pmap_pv(9)

Patch originally from jmcneill@. thanks


# 1.62 03-Feb-2020 ryo

separate struct vm_page_md into vm_page_md and pmap_page
for preparation pmap_pv(9)


Revision tags: ad-namecache-base2 ad-namecache-base1
# 1.61 09-Jan-2020 ryo

fix behaviour mmap()/mprotect() when passed only PROT_EXEC.

when mmap()/mprotect() with only PROT_EXEC, syscall will be successful,
but the page actually hadn't been mapped.
it should be mapped with PROT_READ|PROT_EXEC implicitly. (r-x)


Revision tags: ad-namecache-base
# 1.60 30-Dec-2019 skrll

branches: 1.60.2;
Update pmap_map_chunk to allow L[12] block mappings and L3 page mappings


# 1.59 30-Dec-2019 skrll

Remove unnecessary brackets and unwrap a conditional. Same code before
and after.


# 1.58 28-Dec-2019 jmcneill

Do not use Early Write Acknowledge for PCIe I/O and config space.


# 1.57 27-Dec-2019 jmcneill

Enable early write acknowledge for device memory mappings.


# 1.56 19-Dec-2019 skrll

G/C kasan_shadow_map call in pmap_enter

pmap_growkernel calls kasan_shadow_map for KVA


# 1.55 18-Dec-2019 ryo

atomic_add_16() is not used in pmap.c anymore. no need decl here.


# 1.54 18-Dec-2019 ryo

space to tab


# 1.53 14-Dec-2019 skrll

Fix build... wire_count probably doesn't need atomics


# 1.52 13-Dec-2019 skrll

Fix KASAN support by calling kasan_shadow_map in pmap_growkernel


# 1.51 10-Dec-2019 ad

pg->phys_addr -> VM_PAGE_TO_PHYS(pg)


Revision tags: phil-wifi-20191119
# 1.50 14-Nov-2019 maxv

Mark several kASan functions with __nothing, to avoid annoying #ifdefs.
Same as kCSan and kMSan.


# 1.49 14-Nov-2019 maxv

Don't include "opt_kasan.h" when there's already <sys/asan.h> included.


# 1.48 29-Oct-2019 maya

Define PMAP_NEED_PROCWR, providing strategically placed i-cache
synchronization where just-changed memory is about to be executed.

Fixes SIGILLs seen when running Mono 6 on QEMU Cortex-A57.

ok ryo


# 1.47 22-Sep-2019 jmcneill

Disable translation table walks using TTBR0 while changing its value and
when deactivating a pmap. Fixes stability issues on Ampere eMAG CPUs.


# 1.46 20-Sep-2019 ryo

ref/mod bit should be set according to 'flags' argument, not 'prot'. r1.44 was incomplete.


# 1.45 13-Sep-2019 ryo

In pmap_devmap_bootstrap(), cpu_earlydevice_va_p() must not return true until *all* devmap tables have been enabled.
console mapping may be present in the last table.


# 1.44 07-Sep-2019 ryo

- remove incorrect KASSERT. mmap(2) with prot=PROT_WRITE calls pmap_enter(..., PROT_WRITE) internally.
- fix to update page reference flags when only PROT_WRITE or PROT_EXECUTE specified


# 1.43 15-Aug-2019 skrll

Make pmap_db_pte_print more terse so it's quicker on serial consoles


# 1.42 12-Aug-2019 skrll

Use PMAP_DEV in DEVMAP_ENTRY rather than pmap_map_chunk. It's clearer and
means pmap_map_chunk can be made to map other memory types.


Revision tags: netbsd-9-base phil-wifi-20190609
# 1.41 17-May-2019 mrg

branches: 1.41.2;
apply some __diagused.


Revision tags: isaki-audio2-base
# 1.40 08-Apr-2019 ryo

- free empty page tables pages if reach a certain usage.
- need to lock at removing an old pg (_pmap_remove_pv) in _pmap_enter()


# 1.39 06-Apr-2019 ryo

Fix race conditions about pmap_page_protect() and pmap_enter().

while handling same PTE by these functions in same time, there
is a critical path that the number of valid PTEs and wire_count
are inconsistent, and it caused KASSERT.
Need to hold a pv_lock while modifying them.


# 1.38 20-Mar-2019 ryo

spinkle __printflike(), and use PRIxxx


# 1.37 19-Mar-2019 ryo

- add ddb command "machine ttbr" to dump MMU tables.
- tidy up descriptions, usages and messages.


# 1.36 19-Mar-2019 ryo

- free L1-L3 pages that has been emptied by pmap_remove().
- if no memories, pmap_enter will return correctly ENOMEM if PMAP_CANFAIL, or wait until available any memories if !PMAP_CANFAIL.

These changes improves the stability when we use a huge virtual memory spaces with mmap.


# 1.35 06-Feb-2019 ryo

improve pmap_remove
- don't lock/unlock per page in pmap_remove()
- speedup pte lookup for continuous addresses
- bring out pool_cache_put(&_pmap_pv_pool, pv) from lock/unlock section


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226
# 1.34 21-Dec-2018 ryo

- add workaround for Cavium ThunderX errata 27456.
- add cpufuncs table in cpu_info. each cpu clusters may have different erratum. (e.g. big.LITTLE)


Revision tags: pgoyette-compat-1126
# 1.33 01-Nov-2018 maxv

Add kASan support for aarch64. Stack tracking needs more investigation
and will come in a separate commit.

Reviewed by ryo@ jmcneill@ skrll@.


# 1.32 31-Oct-2018 ryo

invalidate icache correctly.
l3pte_executable() should be used for only valid pte.


Revision tags: pgoyette-compat-1020
# 1.31 18-Oct-2018 skrll

Provide generic start code that assumes the MMU is off and caches are
disabled as per the linux booting protocol for ARMv6 and ARMv7 boards.
u-boot image type should be changed to 'linux' for correct behaviour.

The new start code builds a minimal "bootstrap" L1PT with cached access
disabled and uses the same table for all processors. AP startup is
performed in less steps and more code is written in C.

The bootstrap tables and stack are placed into an (orphaned) section
"_init_memory" which is given to uvm when it is no longer used.

Various kernels have been converted to use this code and tested. Some
boards were provided by TNF. Thanks!

The GENERIC kernel now boots on boards using the TEGRA, SUNXI and EXYNOS
kernels. The GENERIC kernel will also work on RPI2 using u-boot.

Thanks to martin@ and aymeric@ for testing on parallella and nanosoc
respectively


# 1.30 14-Oct-2018 skrll

Use __nothing


# 1.29 12-Oct-2018 ryo

add initial support of COMPAT_NETBSD32 on AArch64.
arm ELF32 EABI binaries could be execute in AArch32 state on AArch64. A32 THUMB mode is not supported yet.


# 1.28 12-Oct-2018 ryo

- cleanup checking address ranges with IN_RANGE macro
- change PM_ADDR_CHECK macro to KASSERTMSG
- restore fast lookup cases with IN_RANGE macro for pmap_extract changed in my previous commit.


# 1.27 12-Oct-2018 ryo

rewrite pmap_pte_lookup() to share similar code.


# 1.26 04-Oct-2018 ryo

cleanup locore, and changed the way to map memories during boot.
- add functions bootpage_enter() and bootpage_alloc() to adapt various layout
of physical memory map. especially for 64bit physical memory layout.
pmapboot_alloc() allocates pagetable pages from _end[].
- changed to map only the required amount for PA=VA identity mapping
(kernel image, UART device, and FDT blob) with L2_BLOCK(2Mbyte).
- changing page permission for kernel image, and making KSEG mapping are done
at cpu_kernel_vm_init() instead of at locore.
- optimize PTE entries with PTE Contiguous bit. it is enabled on devmap only for now.

reviewed by skrll@, thanks.


# 1.25 04-Oct-2018 ryo

* define LX_BLKPAG_{OS,ATTR}_* for OS dependent PTE attributes in pmap.h
* cleanup macros


Revision tags: pgoyette-compat-0930
# 1.24 17-Sep-2018 ryo

delete debug printf and KASSERT.


# 1.23 10-Sep-2018 maxv

Replace KDASSERT by panic.


# 1.22 10-Sep-2018 maxv

Rename _pmap_alloc_pdp -> pmap_alloc_pdp, and make it public.


# 1.21 10-Sep-2018 ryo

cleanup aarch64 mpstart and fdt bootstrap
* arm_cpu_hatch_arg is a bad idea. avoid serializing CPU startup, and eliminate arm_cpu_hatch_arg.
in mpstart, resolve own cpu index using array of cpu_mpidr[] (aarch64)
* add support fdt enable-method "spin-table"
* add support fdt enable-method "brcm,bcm2836-smp" (for 32bit RaspberryPi)
* use arm_fdt_cpu_bootstrap() instead of psci_fdt_bootstrap()
* rename "arm/fdt/psci_fdt.h" to "arm/fdt/psci_fdtvar.h" because of conflict of include file for needs-flag
* add devmap for cpu spin-table of raspberrypi3/aarch64
* no need to force hatch APs for raspberrypi3/arm32 ifndef MULTIPROCESSOR.
* fix to work pmap_extract(kerneltext/data/bss) even if before calling pmap_bootstrap

idea to use cpu_mpidr[] by jmcneill@. reviewd by skrll@. thanks.


Revision tags: pgoyette-compat-0906
# 1.20 27-Aug-2018 ryo

need to add VM_PROT_READ when pmap_kenter_pa(va, pa, VM_PROT_WRITE, 0) or pmap_kenter_pa(va, pa, VM_PROT_EXECUTE, 0).
VM_PROT_READ is treated as an access permission inernally.


# 1.19 11-Aug-2018 ryo

change to minimum invalidation of TLB.
specifying not only va but also asid, and not invalidate L0-L2 entry using tlbi_*_ll() if needed.


# 1.18 10-Aug-2018 ryo

treat kernel-exec attr and user-exec attr separately.
kernel cannot execute userland exec page, and user cannot execute kernel page.


# 1.17 06-Aug-2018 ryo

set kernel text/rodata readonly by default.
add function db_write_text() for setting ddb breakpoint.


# 1.16 31-Jul-2018 skrll

Define and use VPRINTF


Revision tags: pgoyette-compat-0728
# 1.15 27-Jul-2018 ryo

changes of pmap.c r1.13 seems to be unstable.
In order to invalidate icache, not to invalidate all icache,
but temporary to make the page writable and invalidate target address only.


# 1.14 24-Jul-2018 ryo

don't call pool_cache_put with locking pmap. pool_cache_put call pmap_kenter_pa internally.
(pool_cache_put_paddr -> pool_cache_put_slow -> pool_get -> pmap_kenter_pa)


# 1.13 23-Jul-2018 ryo

* fix icache invalidations.
* "ic ivau" (aarch64_icache_sync_range) with VA generates permission fault in some situations, therefore use KSEG address for now.


# 1.12 23-Jul-2018 ryo

rather than using flags to resolve nested locks, reserve pool_cache before locking.


# 1.11 21-Jul-2018 ryo

* avoid deadlock. mutex_owned() works only for adaptive lock, therefore we cannot use it for spinlock...
* add more NULL check
* clear pte when pmap_enter() fails


# 1.10 17-Jul-2018 ryo

Use __debugused


# 1.9 17-Jul-2018 christos

Add missing casts, remove unused variables.


# 1.8 09-Jul-2018 ryo

need locks in pmap_kremove() and pmap_fault_fixup()


Revision tags: phil-wifi-base pgoyette-compat-0625 pgoyette-compat-0521
# 1.7 20-May-2018 ryo

branches: 1.7.2;
pmap_enter() must update modified/referenced flags by 'flags' not 'prot'.


# 1.6 16-May-2018 ryo

Fix memory leak. it was leaking one page every pmap_create().
pm->pm_vmlist must be initialized before calling _pmap_alloc_pdp().


Revision tags: pgoyette-compat-0502
# 1.5 29-Apr-2018 ryo

fix KASSERT panic. pv_entry may not be exists in pvlist when pmap_remove().


# 1.4 29-Apr-2018 ryo

delete unused code


# 1.3 27-Apr-2018 ryo

fix instability behavior of bufcache on aarch64.
* fix to return correct ref/mod when PMAP_WIRED.
* changed to keep wired flags in pte instead of pv_entry, and cleanup.


Revision tags: pgoyette-compat-0422 pgoyette-compat-0415 pgoyette-compat-0407
# 1.2 01-Apr-2018 ryo

Add initial support for ARMv8 (AARCH64) (by nisimura@ and ryo@)

- sys/arch/evbarm64 is gone and integrated into sys/arch/evbarm. (by skrll@)
- add support fdt. evbarm/conf/GENERIC64 fdt (bcm2837,sunxi,tegra) based generic 64bit kernel config. (by skrll@, jmcneill@)


Revision tags: netbsd-8-2-RELEASE netbsd-8-1-RELEASE netbsd-8-1-RC1 netbsd-7-2-RELEASE netbsd-8-0-RELEASE netbsd-8-0-RC2 netbsd-8-0-RC1 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 netbsd-7-1-2-RELEASE pgoyette-compat-base netbsd-7-1-1-RELEASE tls-maxphys-base-20171202 matt-nb8-mediatek-base nick-nhusb-base-20170825 perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base pgoyette-localcount-20170320 netbsd-7-1-RELEASE netbsd-7-1-RC2 nick-nhusb-base-20170204 netbsd-7-nhusb-base-20170116 bouyer-socketcan-base pgoyette-localcount-20170107 netbsd-7-1-RC1 nick-nhusb-base-20161204 pgoyette-localcount-20161104 netbsd-7-0-2-RELEASE nick-nhusb-base-20161004 localcount-20160914 netbsd-7-nhusb-base pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907 nick-nhusb-base-20160529 netbsd-7-0-1-RELEASE nick-nhusb-base-20160422 nick-nhusb-base-20160319 nick-nhusb-base-20151226 netbsd-7-0-RELEASE nick-nhusb-base-20150921 netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 nick-nhusb-base-20150606 nick-nhusb-base-20150406 nick-nhusb-base tls-maxphys-base netbsd-7-base
# 1.1 10-Aug-2014 matt

branches: 1.1.4; 1.1.28;
Preliminary files for AARCH64 (64-bit ARM) support.
Enough for a distribution build.


# 1.104 17-Apr-2021 mrg

remove KERNHIST_INIT_STATIC(). it stradles the line between usable
early in boot and broken early in boot by requiring a partly static
structure with another structure that must be present by the time
any uses are performed. theoretically platform code could allocate
a chunk while seting up memory and assign it here, giving a dynamic
sizing for the entry list, but the reality is that all users have
a statically allocated entry list as well.

the existing KERNHIST_LINK_STATIC() is used in conjunction with
KERNHIST_INITIALIZER() instead.

this stops a NULL pointer deref when the _LOG() macro is called
before the storage is linked in, which happens with GCC 10 on OCTEON
with UVMHIST enabled, crashing in very early kernel init.


Revision tags: thorpej-cfargs-base thorpej-futex-base
# 1.103 09-Mar-2021 ryo

fix build error without options DDB.

kvtopte() is referenced from arm/acpi/acpi_machdep.c


# 1.102 13-Feb-2021 ryo

No assignment is needed here.

the loop in pmap_page_remove() always removes the first pv,
and since the list is managed by _pmap_remove_pv(), pp->pp_pv.pv_next always points to the first.


# 1.101 01-Feb-2021 ryo

It is enough to make a page accessible instead of writable.
same fix as r1.76


# 1.100 31-Jan-2021 ryo

implement pmap_remove_all().

The size of struct pv_entry has increased, but speed of kernel build has improved by about 1%
exec and exit should have been improved.


# 1.99 20-Dec-2020 skrll

Improve the English in the previous comment fix.


# 1.98 19-Dec-2020 skrll

Tweak a comment


# 1.97 11-Dec-2020 skrll

s:aarch64/cpufunc.h:arm/cpufunc.h:

a baby step in the grand arm header unification challenge


# 1.96 10-Nov-2020 skrll

AA64 is not MIPS.

Change all KSEG references to directmap


# 1.95 07-Nov-2020 skrll

In pmap_devmap_bootstrap only set pmap_devmap_bootstrap_done if there
is an entry and ALL of the entries have been done. The entry required
for EARLYCONS might not be the first/only one...


# 1.94 01-Nov-2020 jmcneill

branches: 1.94.2;
No need to disable translation table walks in pmap_activate().


# 1.93 22-Oct-2020 skrll

Use the isb macro - missed in previous commit


# 1.92 22-Oct-2020 skrll

Use the dmb/dsb/isb macros... if nothing else they're all now consistent
about the "memory" assembler contraint.

No binary change


# 1.91 28-Sep-2020 skrll

Only set pmap_devmap_bootstrap_done if something gets mapped.

Think acpi_platform_devmap


# 1.90 19-Sep-2020 skrll

Make __md_palloc pmap agnostic (think sys/uvm/pmap)


# 1.89 14-Sep-2020 ryo

PID_MAX is just an initial value (soft maximum). Don't use it for CTASSERT.
defined __HAVE_CPU_MAXPROC to use function cpu_maxproc().

pointed out by mrg@, thanks.


# 1.88 06-Sep-2020 ryo

Fix panic caused by modload. http://mail-index.netbsd.org/port-arm/2020/08/30/msg006960.html

The address space reserved for modules may not be mapped in L1-L3.


# 1.87 14-Aug-2020 skrll

Whitespace


# 1.86 12-Aug-2020 skrll

Part IV of ad's performance improvements for aarch64

- Implement pmap_growkernel(), and update kernel pmap's stats with atomics.

- Then, pmap_kenter_pa() and pmap_kremove() no longer need to allocate
memory nor take pm_lock, because they only modify L3 PTEs.

- Then, pm_lock and pp_lock can be adaptive mutexes at IPL_NONE which are
cheaper than spin mutexes.

- Take the pmap's lock in pmap_extract() if not the kernel's pmap, otherwise
pmap_extract() might see inconsistent state.


# 1.85 09-Aug-2020 skrll

Fix another UVMHIST so it doesn't use %s


# 1.84 16-Jul-2020 skrll

pmapboot_enter simplication
- bootpage_alloc in asm becomes pmapboot_pagealloc in C
- PMAPBOOT_ENTER_NOBLOCK is removed as it's not used
- PMAPBOOT_ENTER_NOOVERWRITE is removed as it's now always on
- physpage_allocator argument is removed as it's always
pmapboot_pagealloc
- Support for EARLYCONS without CONSADDR is removed so that the identity
map for CONSADDR is always known.

For the assembly files:
2 files changed, 40 insertions(+), 89 deletions(-)

LGTM ryo


# 1.83 04-Jul-2020 rin

Use tlen for temporary length variable instead of l, which is usually
used for struct lwp *.

No binary changes.


# 1.82 02-Jul-2020 rin

pmap_procwr(): sync icache even if p != curproc. This fixes applications
like GDB for arm32, that rewrite text of other process.

Thanks to ryo@ for discussion.


# 1.81 02-Jul-2020 rin

Set uvmexp.ncolors appropriately, which is required for some CPU
models with VIPT icache.

Otherwise, alias in virtual address results in inconsistent results,
at least for applications that rewrite text of other process, e.g.,
GDB for arm32.

Also, this hopefully fixes other unexpected failures due to alias.

Confirmed that there's no observable regression in performance;
difference in ``time make -j8'' for GENERIC64 kernel on BCM2837
with and without setting uvmexp.ncolors is within 0.1%.

Thanks to ryo@ for discussion.


# 1.80 27-Jun-2020 rin

Fix typo in name of evcnt(4) counter.


# 1.79 24-Jun-2020 ryo

Fix bug with incorrect range calculation when doing icache sync.
This is called by sysarch(ARM_SYNC_ICACHE) from aarch32 (compat_netbsd32) emul process.

pointed out by rin@, thanks.

XXX pullup-9


# 1.78 14-Jun-2020 ad

- Fix a lock order reversal in pmap_page_protect().

- Make sure pmap is always locked when updating stats; atomics no longer
needed to do that.

- Remove unneeded traversal of pv list in pmap_enter_pv().

- Shrink struct vm_page from 136 to 128 bytes (cache line sized) and struct
pv_entry from 48 to 32 bytes (power of 2 sized).

- Embed a pv_entry in each vm_page. This means PV entries don't need to
be allocated for private anonymous memory / COW pages / most UBC mappings.
Dynamic PV entries are then used only for stuff like shared libraries and
shared memory.

Proposed on port-arm@.


# 1.77 10-Jun-2020 ad

- Wired/resident stats shouldn't covered by PMAPCOUNTERS.
- Rename need_update_pv -> need_enter_pv.

Ok ryo@


# 1.76 01-Jun-2020 ryo

no need to make the PTE writable to do icache_sync, enough to accessible.


# 1.75 15-May-2020 skrll

Use __diagused


# 1.74 15-May-2020 tnn

fix non-diag build


# 1.73 14-May-2020 skrll

Use MUTEX_NODEBUG for PV locks as is commonly done. OK ryo.


# 1.72 13-May-2020 jmcneill

Implement pmap_extract_coherency


Revision tags: bouyer-xenpvh-base2 phil-wifi-20200421 bouyer-xenpvh-base1
# 1.71 18-Apr-2020 skrll

PMAP_DEBUG has been deleted on arm


# 1.70 13-Apr-2020 maxv

Add support for Branch Target Identification (BTI).

On the executable pages that have the GP (Guarded Page) bit, the semantic
of the "br" and "blr" instructions is changed: the CPU expects the first
instruction of the jump/call target to be "bti", and faults if it isn't.

We add the GP bit on the kernel .text pages (and incidentally the .rodata
pages, but we don't care). The compiler adds a "bti c" instruction at the
beginning of each C function. We modify the ENTRY() macros to manually add
"bti c" in the asm functions.

cpuswitch.S needs a specific change: with "br x27" the CPU expects "bti j",
which is bad because the functions begin with "bti c"; switch to "br x16",
for the CPU to accept "bti c".

BTI helps defend against JOP/COP. Tested on Qemu.


Revision tags: phil-wifi-20200411 bouyer-xenpvh-base
# 1.69 08-Apr-2020 ryo

branches: 1.69.2;
use PMAP_PAGE_INIT() to initialize mutex in pmap_page.

VM_MDPAGE_INIT() in pmap_free_pdp() had initialized pp_flags,
so it unintentionally cleared PMAP_PAGE_FLAGS_PV_TRACKED.
use PMAP_PAGE_INIT to avoid using PMAP_PAGE_FLAGS_PV_TRACKED.

pointed out by tnn@, thanks


Revision tags: phil-wifi-20200406
# 1.68 14-Mar-2020 ad

pmap_remove_all(): Return a boolean value to indicate the behaviour. If
true, all mappings have been removed, the pmap is totally cleared out, and
UVM can then avoid doing the work to call pmap_remove() for each map entry.
If false, either nothing has been done, or some helpful arch-specific voodoo
has taken place.


Revision tags: is-mlppp-base
# 1.67 02-Mar-2020 ryo

oops, fix incorrect usage of daif_enable() in my previous commit.


# 1.66 29-Feb-2020 ryo

Fix pmap to work correctly with tagged addresses

- when fault, untag from address before passing to uvm/pmap functions
- pmap_extract() checks more strictly and consider the address tag


# 1.65 29-Feb-2020 ryo

use pmapboot_enter_range()


Revision tags: ad-namecache-base3
# 1.64 10-Feb-2020 ryo

use LIST(3) instead of TAILQ(3) to save one word in struct vm_page and struct pmap.

pointed out by riastradh@. thanks


# 1.63 03-Feb-2020 ryo

add support pmap_pv(9)

Patch originally from jmcneill@. thanks


# 1.62 03-Feb-2020 ryo

separate struct vm_page_md into vm_page_md and pmap_page
for preparation pmap_pv(9)


Revision tags: ad-namecache-base2 ad-namecache-base1
# 1.61 09-Jan-2020 ryo

fix behaviour mmap()/mprotect() when passed only PROT_EXEC.

when mmap()/mprotect() with only PROT_EXEC, syscall will be successful,
but the page actually hadn't been mapped.
it should be mapped with PROT_READ|PROT_EXEC implicitly. (r-x)


Revision tags: ad-namecache-base
# 1.60 30-Dec-2019 skrll

branches: 1.60.2;
Update pmap_map_chunk to allow L[12] block mappings and L3 page mappings


# 1.59 30-Dec-2019 skrll

Remove unnecessary brackets and unwrap a conditional. Same code before
and after.


# 1.58 28-Dec-2019 jmcneill

Do not use Early Write Acknowledge for PCIe I/O and config space.


# 1.57 27-Dec-2019 jmcneill

Enable early write acknowledge for device memory mappings.


# 1.56 19-Dec-2019 skrll

G/C kasan_shadow_map call in pmap_enter

pmap_growkernel calls kasan_shadow_map for KVA


# 1.55 18-Dec-2019 ryo

atomic_add_16() is not used in pmap.c anymore. no need decl here.


# 1.54 18-Dec-2019 ryo

space to tab


# 1.53 14-Dec-2019 skrll

Fix build... wire_count probably doesn't need atomics


# 1.52 13-Dec-2019 skrll

Fix KASAN support by calling kasan_shadow_map in pmap_growkernel


# 1.51 10-Dec-2019 ad

pg->phys_addr -> VM_PAGE_TO_PHYS(pg)


Revision tags: phil-wifi-20191119
# 1.50 14-Nov-2019 maxv

Mark several kASan functions with __nothing, to avoid annoying #ifdefs.
Same as kCSan and kMSan.


# 1.49 14-Nov-2019 maxv

Don't include "opt_kasan.h" when there's already <sys/asan.h> included.


# 1.48 29-Oct-2019 maya

Define PMAP_NEED_PROCWR, providing strategically placed i-cache
synchronization where just-changed memory is about to be executed.

Fixes SIGILLs seen when running Mono 6 on QEMU Cortex-A57.

ok ryo


# 1.47 22-Sep-2019 jmcneill

Disable translation table walks using TTBR0 while changing its value and
when deactivating a pmap. Fixes stability issues on Ampere eMAG CPUs.


# 1.46 20-Sep-2019 ryo

ref/mod bit should be set according to 'flags' argument, not 'prot'. r1.44 was incomplete.


# 1.45 13-Sep-2019 ryo

In pmap_devmap_bootstrap(), cpu_earlydevice_va_p() must not return true until *all* devmap tables have been enabled.
console mapping may be present in the last table.


# 1.44 07-Sep-2019 ryo

- remove incorrect KASSERT. mmap(2) with prot=PROT_WRITE calls pmap_enter(..., PROT_WRITE) internally.
- fix to update page reference flags when only PROT_WRITE or PROT_EXECUTE specified


# 1.43 15-Aug-2019 skrll

Make pmap_db_pte_print more terse so it's quicker on serial consoles


# 1.42 12-Aug-2019 skrll

Use PMAP_DEV in DEVMAP_ENTRY rather than pmap_map_chunk. It's clearer and
means pmap_map_chunk can be made to map other memory types.


Revision tags: netbsd-9-base phil-wifi-20190609
# 1.41 17-May-2019 mrg

branches: 1.41.2;
apply some __diagused.


Revision tags: isaki-audio2-base
# 1.40 08-Apr-2019 ryo

- free empty page tables pages if reach a certain usage.
- need to lock at removing an old pg (_pmap_remove_pv) in _pmap_enter()


# 1.39 06-Apr-2019 ryo

Fix race conditions about pmap_page_protect() and pmap_enter().

while handling same PTE by these functions in same time, there
is a critical path that the number of valid PTEs and wire_count
are inconsistent, and it caused KASSERT.
Need to hold a pv_lock while modifying them.


# 1.38 20-Mar-2019 ryo

spinkle __printflike(), and use PRIxxx


# 1.37 19-Mar-2019 ryo

- add ddb command "machine ttbr" to dump MMU tables.
- tidy up descriptions, usages and messages.


# 1.36 19-Mar-2019 ryo

- free L1-L3 pages that has been emptied by pmap_remove().
- if no memories, pmap_enter will return correctly ENOMEM if PMAP_CANFAIL, or wait until available any memories if !PMAP_CANFAIL.

These changes improves the stability when we use a huge virtual memory spaces with mmap.


# 1.35 06-Feb-2019 ryo

improve pmap_remove
- don't lock/unlock per page in pmap_remove()
- speedup pte lookup for continuous addresses
- bring out pool_cache_put(&_pmap_pv_pool, pv) from lock/unlock section


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226
# 1.34 21-Dec-2018 ryo

- add workaround for Cavium ThunderX errata 27456.
- add cpufuncs table in cpu_info. each cpu clusters may have different erratum. (e.g. big.LITTLE)


Revision tags: pgoyette-compat-1126
# 1.33 01-Nov-2018 maxv

Add kASan support for aarch64. Stack tracking needs more investigation
and will come in a separate commit.

Reviewed by ryo@ jmcneill@ skrll@.


# 1.32 31-Oct-2018 ryo

invalidate icache correctly.
l3pte_executable() should be used for only valid pte.


Revision tags: pgoyette-compat-1020
# 1.31 18-Oct-2018 skrll

Provide generic start code that assumes the MMU is off and caches are
disabled as per the linux booting protocol for ARMv6 and ARMv7 boards.
u-boot image type should be changed to 'linux' for correct behaviour.

The new start code builds a minimal "bootstrap" L1PT with cached access
disabled and uses the same table for all processors. AP startup is
performed in less steps and more code is written in C.

The bootstrap tables and stack are placed into an (orphaned) section
"_init_memory" which is given to uvm when it is no longer used.

Various kernels have been converted to use this code and tested. Some
boards were provided by TNF. Thanks!

The GENERIC kernel now boots on boards using the TEGRA, SUNXI and EXYNOS
kernels. The GENERIC kernel will also work on RPI2 using u-boot.

Thanks to martin@ and aymeric@ for testing on parallella and nanosoc
respectively


# 1.30 14-Oct-2018 skrll

Use __nothing


# 1.29 12-Oct-2018 ryo

add initial support of COMPAT_NETBSD32 on AArch64.
arm ELF32 EABI binaries could be execute in AArch32 state on AArch64. A32 THUMB mode is not supported yet.


# 1.28 12-Oct-2018 ryo

- cleanup checking address ranges with IN_RANGE macro
- change PM_ADDR_CHECK macro to KASSERTMSG
- restore fast lookup cases with IN_RANGE macro for pmap_extract changed in my previous commit.


# 1.27 12-Oct-2018 ryo

rewrite pmap_pte_lookup() to share similar code.


# 1.26 04-Oct-2018 ryo

cleanup locore, and changed the way to map memories during boot.
- add functions bootpage_enter() and bootpage_alloc() to adapt various layout
of physical memory map. especially for 64bit physical memory layout.
pmapboot_alloc() allocates pagetable pages from _end[].
- changed to map only the required amount for PA=VA identity mapping
(kernel image, UART device, and FDT blob) with L2_BLOCK(2Mbyte).
- changing page permission for kernel image, and making KSEG mapping are done
at cpu_kernel_vm_init() instead of at locore.
- optimize PTE entries with PTE Contiguous bit. it is enabled on devmap only for now.

reviewed by skrll@, thanks.


# 1.25 04-Oct-2018 ryo

* define LX_BLKPAG_{OS,ATTR}_* for OS dependent PTE attributes in pmap.h
* cleanup macros


Revision tags: pgoyette-compat-0930
# 1.24 17-Sep-2018 ryo

delete debug printf and KASSERT.


# 1.23 10-Sep-2018 maxv

Replace KDASSERT by panic.


# 1.22 10-Sep-2018 maxv

Rename _pmap_alloc_pdp -> pmap_alloc_pdp, and make it public.


# 1.21 10-Sep-2018 ryo

cleanup aarch64 mpstart and fdt bootstrap
* arm_cpu_hatch_arg is a bad idea. avoid serializing CPU startup, and eliminate arm_cpu_hatch_arg.
in mpstart, resolve own cpu index using array of cpu_mpidr[] (aarch64)
* add support fdt enable-method "spin-table"
* add support fdt enable-method "brcm,bcm2836-smp" (for 32bit RaspberryPi)
* use arm_fdt_cpu_bootstrap() instead of psci_fdt_bootstrap()
* rename "arm/fdt/psci_fdt.h" to "arm/fdt/psci_fdtvar.h" because of conflict of include file for needs-flag
* add devmap for cpu spin-table of raspberrypi3/aarch64
* no need to force hatch APs for raspberrypi3/arm32 ifndef MULTIPROCESSOR.
* fix to work pmap_extract(kerneltext/data/bss) even if before calling pmap_bootstrap

idea to use cpu_mpidr[] by jmcneill@. reviewd by skrll@. thanks.


Revision tags: pgoyette-compat-0906
# 1.20 27-Aug-2018 ryo

need to add VM_PROT_READ when pmap_kenter_pa(va, pa, VM_PROT_WRITE, 0) or pmap_kenter_pa(va, pa, VM_PROT_EXECUTE, 0).
VM_PROT_READ is treated as an access permission inernally.


# 1.19 11-Aug-2018 ryo

change to minimum invalidation of TLB.
specifying not only va but also asid, and not invalidate L0-L2 entry using tlbi_*_ll() if needed.


# 1.18 10-Aug-2018 ryo

treat kernel-exec attr and user-exec attr separately.
kernel cannot execute userland exec page, and user cannot execute kernel page.


# 1.17 06-Aug-2018 ryo

set kernel text/rodata readonly by default.
add function db_write_text() for setting ddb breakpoint.


# 1.16 31-Jul-2018 skrll

Define and use VPRINTF


Revision tags: pgoyette-compat-0728
# 1.15 27-Jul-2018 ryo

changes of pmap.c r1.13 seems to be unstable.
In order to invalidate icache, not to invalidate all icache,
but temporary to make the page writable and invalidate target address only.


# 1.14 24-Jul-2018 ryo

don't call pool_cache_put with locking pmap. pool_cache_put call pmap_kenter_pa internally.
(pool_cache_put_paddr -> pool_cache_put_slow -> pool_get -> pmap_kenter_pa)


# 1.13 23-Jul-2018 ryo

* fix icache invalidations.
* "ic ivau" (aarch64_icache_sync_range) with VA generates permission fault in some situations, therefore use KSEG address for now.


# 1.12 23-Jul-2018 ryo

rather than using flags to resolve nested locks, reserve pool_cache before locking.


# 1.11 21-Jul-2018 ryo

* avoid deadlock. mutex_owned() works only for adaptive lock, therefore we cannot use it for spinlock...
* add more NULL check
* clear pte when pmap_enter() fails


# 1.10 17-Jul-2018 ryo

Use __debugused


# 1.9 17-Jul-2018 christos

Add missing casts, remove unused variables.


# 1.8 09-Jul-2018 ryo

need locks in pmap_kremove() and pmap_fault_fixup()


Revision tags: phil-wifi-base pgoyette-compat-0625 pgoyette-compat-0521
# 1.7 20-May-2018 ryo

branches: 1.7.2;
pmap_enter() must update modified/referenced flags by 'flags' not 'prot'.


# 1.6 16-May-2018 ryo

Fix memory leak. it was leaking one page every pmap_create().
pm->pm_vmlist must be initialized before calling _pmap_alloc_pdp().


Revision tags: pgoyette-compat-0502
# 1.5 29-Apr-2018 ryo

fix KASSERT panic. pv_entry may not be exists in pvlist when pmap_remove().


# 1.4 29-Apr-2018 ryo

delete unused code


# 1.3 27-Apr-2018 ryo

fix instability behavior of bufcache on aarch64.
* fix to return correct ref/mod when PMAP_WIRED.
* changed to keep wired flags in pte instead of pv_entry, and cleanup.


Revision tags: pgoyette-compat-0422 pgoyette-compat-0415 pgoyette-compat-0407
# 1.2 01-Apr-2018 ryo

Add initial support for ARMv8 (AARCH64) (by nisimura@ and ryo@)

- sys/arch/evbarm64 is gone and integrated into sys/arch/evbarm. (by skrll@)
- add support fdt. evbarm/conf/GENERIC64 fdt (bcm2837,sunxi,tegra) based generic 64bit kernel config. (by skrll@, jmcneill@)


Revision tags: netbsd-8-2-RELEASE netbsd-8-1-RELEASE netbsd-8-1-RC1 netbsd-7-2-RELEASE netbsd-8-0-RELEASE netbsd-8-0-RC2 netbsd-8-0-RC1 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 netbsd-7-1-2-RELEASE pgoyette-compat-base netbsd-7-1-1-RELEASE tls-maxphys-base-20171202 matt-nb8-mediatek-base nick-nhusb-base-20170825 perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base pgoyette-localcount-20170320 netbsd-7-1-RELEASE netbsd-7-1-RC2 nick-nhusb-base-20170204 netbsd-7-nhusb-base-20170116 bouyer-socketcan-base pgoyette-localcount-20170107 netbsd-7-1-RC1 nick-nhusb-base-20161204 pgoyette-localcount-20161104 netbsd-7-0-2-RELEASE nick-nhusb-base-20161004 localcount-20160914 netbsd-7-nhusb-base pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907 nick-nhusb-base-20160529 netbsd-7-0-1-RELEASE nick-nhusb-base-20160422 nick-nhusb-base-20160319 nick-nhusb-base-20151226 netbsd-7-0-RELEASE nick-nhusb-base-20150921 netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 nick-nhusb-base-20150606 nick-nhusb-base-20150406 nick-nhusb-base tls-maxphys-base netbsd-7-base
# 1.1 10-Aug-2014 matt

branches: 1.1.4; 1.1.28;
Preliminary files for AARCH64 (64-bit ARM) support.
Enough for a distribution build.


# 1.103 09-Mar-2021 ryo

fix build error without options DDB.

kvtopte() is referenced from arm/acpi/acpi_machdep.c


# 1.102 13-Feb-2021 ryo

No assignment is needed here.

the loop in pmap_page_remove() always removes the first pv,
and since the list is managed by _pmap_remove_pv(), pp->pp_pv.pv_next always points to the first.


# 1.101 01-Feb-2021 ryo

It is enough to make a page accessible instead of writable.
same fix as r1.76


# 1.100 31-Jan-2021 ryo

implement pmap_remove_all().

The size of struct pv_entry has increased, but speed of kernel build has improved by about 1%
exec and exit should have been improved.


Revision tags: thorpej-futex-base
# 1.99 20-Dec-2020 skrll

Improve the English in the previous comment fix.


# 1.98 19-Dec-2020 skrll

Tweak a comment


# 1.97 11-Dec-2020 skrll

s:aarch64/cpufunc.h:arm/cpufunc.h:

a baby step in the grand arm header unification challenge


# 1.96 10-Nov-2020 skrll

AA64 is not MIPS.

Change all KSEG references to directmap


# 1.95 07-Nov-2020 skrll

In pmap_devmap_bootstrap only set pmap_devmap_bootstrap_done if there
is an entry and ALL of the entries have been done. The entry required
for EARLYCONS might not be the first/only one...


# 1.94 01-Nov-2020 jmcneill

branches: 1.94.2;
No need to disable translation table walks in pmap_activate().


# 1.93 22-Oct-2020 skrll

Use the isb macro - missed in previous commit


# 1.92 22-Oct-2020 skrll

Use the dmb/dsb/isb macros... if nothing else they're all now consistent
about the "memory" assembler contraint.

No binary change


# 1.91 28-Sep-2020 skrll

Only set pmap_devmap_bootstrap_done if something gets mapped.

Think acpi_platform_devmap


# 1.90 19-Sep-2020 skrll

Make __md_palloc pmap agnostic (think sys/uvm/pmap)


# 1.89 14-Sep-2020 ryo

PID_MAX is just an initial value (soft maximum). Don't use it for CTASSERT.
defined __HAVE_CPU_MAXPROC to use function cpu_maxproc().

pointed out by mrg@, thanks.


# 1.88 06-Sep-2020 ryo

Fix panic caused by modload. http://mail-index.netbsd.org/port-arm/2020/08/30/msg006960.html

The address space reserved for modules may not be mapped in L1-L3.


# 1.87 14-Aug-2020 skrll

Whitespace


# 1.86 12-Aug-2020 skrll

Part IV of ad's performance improvements for aarch64

- Implement pmap_growkernel(), and update kernel pmap's stats with atomics.

- Then, pmap_kenter_pa() and pmap_kremove() no longer need to allocate
memory nor take pm_lock, because they only modify L3 PTEs.

- Then, pm_lock and pp_lock can be adaptive mutexes at IPL_NONE which are
cheaper than spin mutexes.

- Take the pmap's lock in pmap_extract() if not the kernel's pmap, otherwise
pmap_extract() might see inconsistent state.


# 1.85 09-Aug-2020 skrll

Fix another UVMHIST so it doesn't use %s


# 1.84 16-Jul-2020 skrll

pmapboot_enter simplication
- bootpage_alloc in asm becomes pmapboot_pagealloc in C
- PMAPBOOT_ENTER_NOBLOCK is removed as it's not used
- PMAPBOOT_ENTER_NOOVERWRITE is removed as it's now always on
- physpage_allocator argument is removed as it's always
pmapboot_pagealloc
- Support for EARLYCONS without CONSADDR is removed so that the identity
map for CONSADDR is always known.

For the assembly files:
2 files changed, 40 insertions(+), 89 deletions(-)

LGTM ryo


# 1.83 04-Jul-2020 rin

Use tlen for temporary length variable instead of l, which is usually
used for struct lwp *.

No binary changes.


# 1.82 02-Jul-2020 rin

pmap_procwr(): sync icache even if p != curproc. This fixes applications
like GDB for arm32, that rewrite text of other process.

Thanks to ryo@ for discussion.


# 1.81 02-Jul-2020 rin

Set uvmexp.ncolors appropriately, which is required for some CPU
models with VIPT icache.

Otherwise, alias in virtual address results in inconsistent results,
at least for applications that rewrite text of other process, e.g.,
GDB for arm32.

Also, this hopefully fixes other unexpected failures due to alias.

Confirmed that there's no observable regression in performance;
difference in ``time make -j8'' for GENERIC64 kernel on BCM2837
with and without setting uvmexp.ncolors is within 0.1%.

Thanks to ryo@ for discussion.


# 1.80 27-Jun-2020 rin

Fix typo in name of evcnt(4) counter.


# 1.79 24-Jun-2020 ryo

Fix bug with incorrect range calculation when doing icache sync.
This is called by sysarch(ARM_SYNC_ICACHE) from aarch32 (compat_netbsd32) emul process.

pointed out by rin@, thanks.

XXX pullup-9


# 1.78 14-Jun-2020 ad

- Fix a lock order reversal in pmap_page_protect().

- Make sure pmap is always locked when updating stats; atomics no longer
needed to do that.

- Remove unneeded traversal of pv list in pmap_enter_pv().

- Shrink struct vm_page from 136 to 128 bytes (cache line sized) and struct
pv_entry from 48 to 32 bytes (power of 2 sized).

- Embed a pv_entry in each vm_page. This means PV entries don't need to
be allocated for private anonymous memory / COW pages / most UBC mappings.
Dynamic PV entries are then used only for stuff like shared libraries and
shared memory.

Proposed on port-arm@.


# 1.77 10-Jun-2020 ad

- Wired/resident stats shouldn't covered by PMAPCOUNTERS.
- Rename need_update_pv -> need_enter_pv.

Ok ryo@


# 1.76 01-Jun-2020 ryo

no need to make the PTE writable to do icache_sync, enough to accessible.


# 1.75 15-May-2020 skrll

Use __diagused


# 1.74 15-May-2020 tnn

fix non-diag build


# 1.73 14-May-2020 skrll

Use MUTEX_NODEBUG for PV locks as is commonly done. OK ryo.


# 1.72 13-May-2020 jmcneill

Implement pmap_extract_coherency


Revision tags: bouyer-xenpvh-base2 phil-wifi-20200421 bouyer-xenpvh-base1
# 1.71 18-Apr-2020 skrll

PMAP_DEBUG has been deleted on arm


# 1.70 13-Apr-2020 maxv

Add support for Branch Target Identification (BTI).

On the executable pages that have the GP (Guarded Page) bit, the semantic
of the "br" and "blr" instructions is changed: the CPU expects the first
instruction of the jump/call target to be "bti", and faults if it isn't.

We add the GP bit on the kernel .text pages (and incidentally the .rodata
pages, but we don't care). The compiler adds a "bti c" instruction at the
beginning of each C function. We modify the ENTRY() macros to manually add
"bti c" in the asm functions.

cpuswitch.S needs a specific change: with "br x27" the CPU expects "bti j",
which is bad because the functions begin with "bti c"; switch to "br x16",
for the CPU to accept "bti c".

BTI helps defend against JOP/COP. Tested on Qemu.


Revision tags: phil-wifi-20200411 bouyer-xenpvh-base
# 1.69 08-Apr-2020 ryo

branches: 1.69.2;
use PMAP_PAGE_INIT() to initialize mutex in pmap_page.

VM_MDPAGE_INIT() in pmap_free_pdp() had initialized pp_flags,
so it unintentionally cleared PMAP_PAGE_FLAGS_PV_TRACKED.
use PMAP_PAGE_INIT to avoid using PMAP_PAGE_FLAGS_PV_TRACKED.

pointed out by tnn@, thanks


Revision tags: phil-wifi-20200406
# 1.68 14-Mar-2020 ad

pmap_remove_all(): Return a boolean value to indicate the behaviour. If
true, all mappings have been removed, the pmap is totally cleared out, and
UVM can then avoid doing the work to call pmap_remove() for each map entry.
If false, either nothing has been done, or some helpful arch-specific voodoo
has taken place.


Revision tags: is-mlppp-base
# 1.67 02-Mar-2020 ryo

oops, fix incorrect usage of daif_enable() in my previous commit.


# 1.66 29-Feb-2020 ryo

Fix pmap to work correctly with tagged addresses

- when fault, untag from address before passing to uvm/pmap functions
- pmap_extract() checks more strictly and consider the address tag


# 1.65 29-Feb-2020 ryo

use pmapboot_enter_range()


Revision tags: ad-namecache-base3
# 1.64 10-Feb-2020 ryo

use LIST(3) instead of TAILQ(3) to save one word in struct vm_page and struct pmap.

pointed out by riastradh@. thanks


# 1.63 03-Feb-2020 ryo

add support pmap_pv(9)

Patch originally from jmcneill@. thanks


# 1.62 03-Feb-2020 ryo

separate struct vm_page_md into vm_page_md and pmap_page
for preparation pmap_pv(9)


Revision tags: ad-namecache-base2 ad-namecache-base1
# 1.61 09-Jan-2020 ryo

fix behaviour mmap()/mprotect() when passed only PROT_EXEC.

when mmap()/mprotect() with only PROT_EXEC, syscall will be successful,
but the page actually hadn't been mapped.
it should be mapped with PROT_READ|PROT_EXEC implicitly. (r-x)


Revision tags: ad-namecache-base
# 1.60 30-Dec-2019 skrll

branches: 1.60.2;
Update pmap_map_chunk to allow L[12] block mappings and L3 page mappings


# 1.59 30-Dec-2019 skrll

Remove unnecessary brackets and unwrap a conditional. Same code before
and after.


# 1.58 28-Dec-2019 jmcneill

Do not use Early Write Acknowledge for PCIe I/O and config space.


# 1.57 27-Dec-2019 jmcneill

Enable early write acknowledge for device memory mappings.


# 1.56 19-Dec-2019 skrll

G/C kasan_shadow_map call in pmap_enter

pmap_growkernel calls kasan_shadow_map for KVA


# 1.55 18-Dec-2019 ryo

atomic_add_16() is not used in pmap.c anymore. no need decl here.


# 1.54 18-Dec-2019 ryo

space to tab


# 1.53 14-Dec-2019 skrll

Fix build... wire_count probably doesn't need atomics


# 1.52 13-Dec-2019 skrll

Fix KASAN support by calling kasan_shadow_map in pmap_growkernel


# 1.51 10-Dec-2019 ad

pg->phys_addr -> VM_PAGE_TO_PHYS(pg)


Revision tags: phil-wifi-20191119
# 1.50 14-Nov-2019 maxv

Mark several kASan functions with __nothing, to avoid annoying #ifdefs.
Same as kCSan and kMSan.


# 1.49 14-Nov-2019 maxv

Don't include "opt_kasan.h" when there's already <sys/asan.h> included.


# 1.48 29-Oct-2019 maya

Define PMAP_NEED_PROCWR, providing strategically placed i-cache
synchronization where just-changed memory is about to be executed.

Fixes SIGILLs seen when running Mono 6 on QEMU Cortex-A57.

ok ryo


# 1.47 22-Sep-2019 jmcneill

Disable translation table walks using TTBR0 while changing its value and
when deactivating a pmap. Fixes stability issues on Ampere eMAG CPUs.


# 1.46 20-Sep-2019 ryo

ref/mod bit should be set according to 'flags' argument, not 'prot'. r1.44 was incomplete.


# 1.45 13-Sep-2019 ryo

In pmap_devmap_bootstrap(), cpu_earlydevice_va_p() must not return true until *all* devmap tables have been enabled.
console mapping may be present in the last table.


# 1.44 07-Sep-2019 ryo

- remove incorrect KASSERT. mmap(2) with prot=PROT_WRITE calls pmap_enter(..., PROT_WRITE) internally.
- fix to update page reference flags when only PROT_WRITE or PROT_EXECUTE specified


# 1.43 15-Aug-2019 skrll

Make pmap_db_pte_print more terse so it's quicker on serial consoles


# 1.42 12-Aug-2019 skrll

Use PMAP_DEV in DEVMAP_ENTRY rather than pmap_map_chunk. It's clearer and
means pmap_map_chunk can be made to map other memory types.


Revision tags: netbsd-9-base phil-wifi-20190609
# 1.41 17-May-2019 mrg

branches: 1.41.2;
apply some __diagused.


Revision tags: isaki-audio2-base
# 1.40 08-Apr-2019 ryo

- free empty page tables pages if reach a certain usage.
- need to lock at removing an old pg (_pmap_remove_pv) in _pmap_enter()


# 1.39 06-Apr-2019 ryo

Fix race conditions about pmap_page_protect() and pmap_enter().

while handling same PTE by these functions in same time, there
is a critical path that the number of valid PTEs and wire_count
are inconsistent, and it caused KASSERT.
Need to hold a pv_lock while modifying them.


# 1.38 20-Mar-2019 ryo

spinkle __printflike(), and use PRIxxx


# 1.37 19-Mar-2019 ryo

- add ddb command "machine ttbr" to dump MMU tables.
- tidy up descriptions, usages and messages.


# 1.36 19-Mar-2019 ryo

- free L1-L3 pages that has been emptied by pmap_remove().
- if no memories, pmap_enter will return correctly ENOMEM if PMAP_CANFAIL, or wait until available any memories if !PMAP_CANFAIL.

These changes improves the stability when we use a huge virtual memory spaces with mmap.


# 1.35 06-Feb-2019 ryo

improve pmap_remove
- don't lock/unlock per page in pmap_remove()
- speedup pte lookup for continuous addresses
- bring out pool_cache_put(&_pmap_pv_pool, pv) from lock/unlock section


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226
# 1.34 21-Dec-2018 ryo

- add workaround for Cavium ThunderX errata 27456.
- add cpufuncs table in cpu_info. each cpu clusters may have different erratum. (e.g. big.LITTLE)


Revision tags: pgoyette-compat-1126
# 1.33 01-Nov-2018 maxv

Add kASan support for aarch64. Stack tracking needs more investigation
and will come in a separate commit.

Reviewed by ryo@ jmcneill@ skrll@.


# 1.32 31-Oct-2018 ryo

invalidate icache correctly.
l3pte_executable() should be used for only valid pte.


Revision tags: pgoyette-compat-1020
# 1.31 18-Oct-2018 skrll

Provide generic start code that assumes the MMU is off and caches are
disabled as per the linux booting protocol for ARMv6 and ARMv7 boards.
u-boot image type should be changed to 'linux' for correct behaviour.

The new start code builds a minimal "bootstrap" L1PT with cached access
disabled and uses the same table for all processors. AP startup is
performed in less steps and more code is written in C.

The bootstrap tables and stack are placed into an (orphaned) section
"_init_memory" which is given to uvm when it is no longer used.

Various kernels have been converted to use this code and tested. Some
boards were provided by TNF. Thanks!

The GENERIC kernel now boots on boards using the TEGRA, SUNXI and EXYNOS
kernels. The GENERIC kernel will also work on RPI2 using u-boot.

Thanks to martin@ and aymeric@ for testing on parallella and nanosoc
respectively


# 1.30 14-Oct-2018 skrll

Use __nothing


# 1.29 12-Oct-2018 ryo

add initial support of COMPAT_NETBSD32 on AArch64.
arm ELF32 EABI binaries could be execute in AArch32 state on AArch64. A32 THUMB mode is not supported yet.


# 1.28 12-Oct-2018 ryo

- cleanup checking address ranges with IN_RANGE macro
- change PM_ADDR_CHECK macro to KASSERTMSG
- restore fast lookup cases with IN_RANGE macro for pmap_extract changed in my previous commit.


# 1.27 12-Oct-2018 ryo

rewrite pmap_pte_lookup() to share similar code.


# 1.26 04-Oct-2018 ryo

cleanup locore, and changed the way to map memories during boot.
- add functions bootpage_enter() and bootpage_alloc() to adapt various layout
of physical memory map. especially for 64bit physical memory layout.
pmapboot_alloc() allocates pagetable pages from _end[].
- changed to map only the required amount for PA=VA identity mapping
(kernel image, UART device, and FDT blob) with L2_BLOCK(2Mbyte).
- changing page permission for kernel image, and making KSEG mapping are done
at cpu_kernel_vm_init() instead of at locore.
- optimize PTE entries with PTE Contiguous bit. it is enabled on devmap only for now.

reviewed by skrll@, thanks.


# 1.25 04-Oct-2018 ryo

* define LX_BLKPAG_{OS,ATTR}_* for OS dependent PTE attributes in pmap.h
* cleanup macros


Revision tags: pgoyette-compat-0930
# 1.24 17-Sep-2018 ryo

delete debug printf and KASSERT.


# 1.23 10-Sep-2018 maxv

Replace KDASSERT by panic.


# 1.22 10-Sep-2018 maxv

Rename _pmap_alloc_pdp -> pmap_alloc_pdp, and make it public.


# 1.21 10-Sep-2018 ryo

cleanup aarch64 mpstart and fdt bootstrap
* arm_cpu_hatch_arg is a bad idea. avoid serializing CPU startup, and eliminate arm_cpu_hatch_arg.
in mpstart, resolve own cpu index using array of cpu_mpidr[] (aarch64)
* add support fdt enable-method "spin-table"
* add support fdt enable-method "brcm,bcm2836-smp" (for 32bit RaspberryPi)
* use arm_fdt_cpu_bootstrap() instead of psci_fdt_bootstrap()
* rename "arm/fdt/psci_fdt.h" to "arm/fdt/psci_fdtvar.h" because of conflict of include file for needs-flag
* add devmap for cpu spin-table of raspberrypi3/aarch64
* no need to force hatch APs for raspberrypi3/arm32 ifndef MULTIPROCESSOR.
* fix to work pmap_extract(kerneltext/data/bss) even if before calling pmap_bootstrap

idea to use cpu_mpidr[] by jmcneill@. reviewd by skrll@. thanks.


Revision tags: pgoyette-compat-0906
# 1.20 27-Aug-2018 ryo

need to add VM_PROT_READ when pmap_kenter_pa(va, pa, VM_PROT_WRITE, 0) or pmap_kenter_pa(va, pa, VM_PROT_EXECUTE, 0).
VM_PROT_READ is treated as an access permission inernally.


# 1.19 11-Aug-2018 ryo

change to minimum invalidation of TLB.
specifying not only va but also asid, and not invalidate L0-L2 entry using tlbi_*_ll() if needed.


# 1.18 10-Aug-2018 ryo

treat kernel-exec attr and user-exec attr separately.
kernel cannot execute userland exec page, and user cannot execute kernel page.


# 1.17 06-Aug-2018 ryo

set kernel text/rodata readonly by default.
add function db_write_text() for setting ddb breakpoint.


# 1.16 31-Jul-2018 skrll

Define and use VPRINTF


Revision tags: pgoyette-compat-0728
# 1.15 27-Jul-2018 ryo

changes of pmap.c r1.13 seems to be unstable.
In order to invalidate icache, not to invalidate all icache,
but temporary to make the page writable and invalidate target address only.


# 1.14 24-Jul-2018 ryo

don't call pool_cache_put with locking pmap. pool_cache_put call pmap_kenter_pa internally.
(pool_cache_put_paddr -> pool_cache_put_slow -> pool_get -> pmap_kenter_pa)


# 1.13 23-Jul-2018 ryo

* fix icache invalidations.
* "ic ivau" (aarch64_icache_sync_range) with VA generates permission fault in some situations, therefore use KSEG address for now.


# 1.12 23-Jul-2018 ryo

rather than using flags to resolve nested locks, reserve pool_cache before locking.


# 1.11 21-Jul-2018 ryo

* avoid deadlock. mutex_owned() works only for adaptive lock, therefore we cannot use it for spinlock...
* add more NULL check
* clear pte when pmap_enter() fails


# 1.10 17-Jul-2018 ryo

Use __debugused


# 1.9 17-Jul-2018 christos

Add missing casts, remove unused variables.


# 1.8 09-Jul-2018 ryo

need locks in pmap_kremove() and pmap_fault_fixup()


Revision tags: phil-wifi-base pgoyette-compat-0625 pgoyette-compat-0521
# 1.7 20-May-2018 ryo

branches: 1.7.2;
pmap_enter() must update modified/referenced flags by 'flags' not 'prot'.


# 1.6 16-May-2018 ryo

Fix memory leak. it was leaking one page every pmap_create().
pm->pm_vmlist must be initialized before calling _pmap_alloc_pdp().


Revision tags: pgoyette-compat-0502
# 1.5 29-Apr-2018 ryo

fix KASSERT panic. pv_entry may not be exists in pvlist when pmap_remove().


# 1.4 29-Apr-2018 ryo

delete unused code


# 1.3 27-Apr-2018 ryo

fix instability behavior of bufcache on aarch64.
* fix to return correct ref/mod when PMAP_WIRED.
* changed to keep wired flags in pte instead of pv_entry, and cleanup.


Revision tags: pgoyette-compat-0422 pgoyette-compat-0415 pgoyette-compat-0407
# 1.2 01-Apr-2018 ryo

Add initial support for ARMv8 (AARCH64) (by nisimura@ and ryo@)

- sys/arch/evbarm64 is gone and integrated into sys/arch/evbarm. (by skrll@)
- add support fdt. evbarm/conf/GENERIC64 fdt (bcm2837,sunxi,tegra) based generic 64bit kernel config. (by skrll@, jmcneill@)


Revision tags: netbsd-8-2-RELEASE netbsd-8-1-RELEASE netbsd-8-1-RC1 netbsd-7-2-RELEASE netbsd-8-0-RELEASE netbsd-8-0-RC2 netbsd-8-0-RC1 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 netbsd-7-1-2-RELEASE pgoyette-compat-base netbsd-7-1-1-RELEASE tls-maxphys-base-20171202 matt-nb8-mediatek-base nick-nhusb-base-20170825 perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base pgoyette-localcount-20170320 netbsd-7-1-RELEASE netbsd-7-1-RC2 nick-nhusb-base-20170204 netbsd-7-nhusb-base-20170116 bouyer-socketcan-base pgoyette-localcount-20170107 netbsd-7-1-RC1 nick-nhusb-base-20161204 pgoyette-localcount-20161104 netbsd-7-0-2-RELEASE nick-nhusb-base-20161004 localcount-20160914 netbsd-7-nhusb-base pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907 nick-nhusb-base-20160529 netbsd-7-0-1-RELEASE nick-nhusb-base-20160422 nick-nhusb-base-20160319 nick-nhusb-base-20151226 netbsd-7-0-RELEASE nick-nhusb-base-20150921 netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 nick-nhusb-base-20150606 nick-nhusb-base-20150406 nick-nhusb-base tls-maxphys-base netbsd-7-base
# 1.1 10-Aug-2014 matt

branches: 1.1.4; 1.1.28;
Preliminary files for AARCH64 (64-bit ARM) support.
Enough for a distribution build.


# 1.102 13-Feb-2021 ryo

No assignment is needed here.

the loop in pmap_page_remove() always removes the first pv,
and since the list is managed by _pmap_remove_pv(), pp->pp_pv.pv_next always points to the first.


# 1.101 01-Feb-2021 ryo

It is enough to make a page accessible instead of writable.
same fix as r1.76


# 1.100 31-Jan-2021 ryo

implement pmap_remove_all().

The size of struct pv_entry has increased, but speed of kernel build has improved by about 1%
exec and exit should have been improved.


Revision tags: thorpej-futex-base
# 1.99 20-Dec-2020 skrll

Improve the English in the previous comment fix.


# 1.98 19-Dec-2020 skrll

Tweak a comment


# 1.97 11-Dec-2020 skrll

s:aarch64/cpufunc.h:arm/cpufunc.h:

a baby step in the grand arm header unification challenge


# 1.96 10-Nov-2020 skrll

AA64 is not MIPS.

Change all KSEG references to directmap


# 1.95 07-Nov-2020 skrll

In pmap_devmap_bootstrap only set pmap_devmap_bootstrap_done if there
is an entry and ALL of the entries have been done. The entry required
for EARLYCONS might not be the first/only one...


# 1.94 01-Nov-2020 jmcneill

branches: 1.94.2;
No need to disable translation table walks in pmap_activate().


# 1.93 22-Oct-2020 skrll

Use the isb macro - missed in previous commit


# 1.92 22-Oct-2020 skrll

Use the dmb/dsb/isb macros... if nothing else they're all now consistent
about the "memory" assembler contraint.

No binary change


# 1.91 28-Sep-2020 skrll

Only set pmap_devmap_bootstrap_done if something gets mapped.

Think acpi_platform_devmap


# 1.90 19-Sep-2020 skrll

Make __md_palloc pmap agnostic (think sys/uvm/pmap)


# 1.89 14-Sep-2020 ryo

PID_MAX is just an initial value (soft maximum). Don't use it for CTASSERT.
defined __HAVE_CPU_MAXPROC to use function cpu_maxproc().

pointed out by mrg@, thanks.


# 1.88 06-Sep-2020 ryo

Fix panic caused by modload. http://mail-index.netbsd.org/port-arm/2020/08/30/msg006960.html

The address space reserved for modules may not be mapped in L1-L3.


# 1.87 14-Aug-2020 skrll

Whitespace


# 1.86 12-Aug-2020 skrll

Part IV of ad's performance improvements for aarch64

- Implement pmap_growkernel(), and update kernel pmap's stats with atomics.

- Then, pmap_kenter_pa() and pmap_kremove() no longer need to allocate
memory nor take pm_lock, because they only modify L3 PTEs.

- Then, pm_lock and pp_lock can be adaptive mutexes at IPL_NONE which are
cheaper than spin mutexes.

- Take the pmap's lock in pmap_extract() if not the kernel's pmap, otherwise
pmap_extract() might see inconsistent state.


# 1.85 09-Aug-2020 skrll

Fix another UVMHIST so it doesn't use %s


# 1.84 16-Jul-2020 skrll

pmapboot_enter simplication
- bootpage_alloc in asm becomes pmapboot_pagealloc in C
- PMAPBOOT_ENTER_NOBLOCK is removed as it's not used
- PMAPBOOT_ENTER_NOOVERWRITE is removed as it's now always on
- physpage_allocator argument is removed as it's always
pmapboot_pagealloc
- Support for EARLYCONS without CONSADDR is removed so that the identity
map for CONSADDR is always known.

For the assembly files:
2 files changed, 40 insertions(+), 89 deletions(-)

LGTM ryo


# 1.83 04-Jul-2020 rin

Use tlen for temporary length variable instead of l, which is usually
used for struct lwp *.

No binary changes.


# 1.82 02-Jul-2020 rin

pmap_procwr(): sync icache even if p != curproc. This fixes applications
like GDB for arm32, that rewrite text of other process.

Thanks to ryo@ for discussion.


# 1.81 02-Jul-2020 rin

Set uvmexp.ncolors appropriately, which is required for some CPU
models with VIPT icache.

Otherwise, alias in virtual address results in inconsistent results,
at least for applications that rewrite text of other process, e.g.,
GDB for arm32.

Also, this hopefully fixes other unexpected failures due to alias.

Confirmed that there's no observable regression in performance;
difference in ``time make -j8'' for GENERIC64 kernel on BCM2837
with and without setting uvmexp.ncolors is within 0.1%.

Thanks to ryo@ for discussion.


# 1.80 27-Jun-2020 rin

Fix typo in name of evcnt(4) counter.


# 1.79 24-Jun-2020 ryo

Fix bug with incorrect range calculation when doing icache sync.
This is called by sysarch(ARM_SYNC_ICACHE) from aarch32 (compat_netbsd32) emul process.

pointed out by rin@, thanks.

XXX pullup-9


# 1.78 14-Jun-2020 ad

- Fix a lock order reversal in pmap_page_protect().

- Make sure pmap is always locked when updating stats; atomics no longer
needed to do that.

- Remove unneeded traversal of pv list in pmap_enter_pv().

- Shrink struct vm_page from 136 to 128 bytes (cache line sized) and struct
pv_entry from 48 to 32 bytes (power of 2 sized).

- Embed a pv_entry in each vm_page. This means PV entries don't need to
be allocated for private anonymous memory / COW pages / most UBC mappings.
Dynamic PV entries are then used only for stuff like shared libraries and
shared memory.

Proposed on port-arm@.


# 1.77 10-Jun-2020 ad

- Wired/resident stats shouldn't covered by PMAPCOUNTERS.
- Rename need_update_pv -> need_enter_pv.

Ok ryo@


# 1.76 01-Jun-2020 ryo

no need to make the PTE writable to do icache_sync, enough to accessible.


# 1.75 15-May-2020 skrll

Use __diagused


# 1.74 15-May-2020 tnn

fix non-diag build


# 1.73 14-May-2020 skrll

Use MUTEX_NODEBUG for PV locks as is commonly done. OK ryo.


# 1.72 13-May-2020 jmcneill

Implement pmap_extract_coherency


Revision tags: bouyer-xenpvh-base2 phil-wifi-20200421 bouyer-xenpvh-base1
# 1.71 18-Apr-2020 skrll

PMAP_DEBUG has been deleted on arm


# 1.70 13-Apr-2020 maxv

Add support for Branch Target Identification (BTI).

On the executable pages that have the GP (Guarded Page) bit, the semantic
of the "br" and "blr" instructions is changed: the CPU expects the first
instruction of the jump/call target to be "bti", and faults if it isn't.

We add the GP bit on the kernel .text pages (and incidentally the .rodata
pages, but we don't care). The compiler adds a "bti c" instruction at the
beginning of each C function. We modify the ENTRY() macros to manually add
"bti c" in the asm functions.

cpuswitch.S needs a specific change: with "br x27" the CPU expects "bti j",
which is bad because the functions begin with "bti c"; switch to "br x16",
for the CPU to accept "bti c".

BTI helps defend against JOP/COP. Tested on Qemu.


Revision tags: phil-wifi-20200411 bouyer-xenpvh-base
# 1.69 08-Apr-2020 ryo

branches: 1.69.2;
use PMAP_PAGE_INIT() to initialize mutex in pmap_page.

VM_MDPAGE_INIT() in pmap_free_pdp() had initialized pp_flags,
so it unintentionally cleared PMAP_PAGE_FLAGS_PV_TRACKED.
use PMAP_PAGE_INIT to avoid using PMAP_PAGE_FLAGS_PV_TRACKED.

pointed out by tnn@, thanks


Revision tags: phil-wifi-20200406
# 1.68 14-Mar-2020 ad

pmap_remove_all(): Return a boolean value to indicate the behaviour. If
true, all mappings have been removed, the pmap is totally cleared out, and
UVM can then avoid doing the work to call pmap_remove() for each map entry.
If false, either nothing has been done, or some helpful arch-specific voodoo
has taken place.


Revision tags: is-mlppp-base
# 1.67 02-Mar-2020 ryo

oops, fix incorrect usage of daif_enable() in my previous commit.


# 1.66 29-Feb-2020 ryo

Fix pmap to work correctly with tagged addresses

- when fault, untag from address before passing to uvm/pmap functions
- pmap_extract() checks more strictly and consider the address tag


# 1.65 29-Feb-2020 ryo

use pmapboot_enter_range()


Revision tags: ad-namecache-base3
# 1.64 10-Feb-2020 ryo

use LIST(3) instead of TAILQ(3) to save one word in struct vm_page and struct pmap.

pointed out by riastradh@. thanks


# 1.63 03-Feb-2020 ryo

add support pmap_pv(9)

Patch originally from jmcneill@. thanks


# 1.62 03-Feb-2020 ryo

separate struct vm_page_md into vm_page_md and pmap_page
for preparation pmap_pv(9)


Revision tags: ad-namecache-base2 ad-namecache-base1
# 1.61 09-Jan-2020 ryo

fix behaviour mmap()/mprotect() when passed only PROT_EXEC.

when mmap()/mprotect() with only PROT_EXEC, syscall will be successful,
but the page actually hadn't been mapped.
it should be mapped with PROT_READ|PROT_EXEC implicitly. (r-x)


Revision tags: ad-namecache-base
# 1.60 30-Dec-2019 skrll

branches: 1.60.2;
Update pmap_map_chunk to allow L[12] block mappings and L3 page mappings


# 1.59 30-Dec-2019 skrll

Remove unnecessary brackets and unwrap a conditional. Same code before
and after.


# 1.58 28-Dec-2019 jmcneill

Do not use Early Write Acknowledge for PCIe I/O and config space.


# 1.57 27-Dec-2019 jmcneill

Enable early write acknowledge for device memory mappings.


# 1.56 19-Dec-2019 skrll

G/C kasan_shadow_map call in pmap_enter

pmap_growkernel calls kasan_shadow_map for KVA


# 1.55 18-Dec-2019 ryo

atomic_add_16() is not used in pmap.c anymore. no need decl here.


# 1.54 18-Dec-2019 ryo

space to tab


# 1.53 14-Dec-2019 skrll

Fix build... wire_count probably doesn't need atomics


# 1.52 13-Dec-2019 skrll

Fix KASAN support by calling kasan_shadow_map in pmap_growkernel


# 1.51 10-Dec-2019 ad

pg->phys_addr -> VM_PAGE_TO_PHYS(pg)


Revision tags: phil-wifi-20191119
# 1.50 14-Nov-2019 maxv

Mark several kASan functions with __nothing, to avoid annoying #ifdefs.
Same as kCSan and kMSan.


# 1.49 14-Nov-2019 maxv

Don't include "opt_kasan.h" when there's already <sys/asan.h> included.


# 1.48 29-Oct-2019 maya

Define PMAP_NEED_PROCWR, providing strategically placed i-cache
synchronization where just-changed memory is about to be executed.

Fixes SIGILLs seen when running Mono 6 on QEMU Cortex-A57.

ok ryo


# 1.47 22-Sep-2019 jmcneill

Disable translation table walks using TTBR0 while changing its value and
when deactivating a pmap. Fixes stability issues on Ampere eMAG CPUs.


# 1.46 20-Sep-2019 ryo

ref/mod bit should be set according to 'flags' argument, not 'prot'. r1.44 was incomplete.


# 1.45 13-Sep-2019 ryo

In pmap_devmap_bootstrap(), cpu_earlydevice_va_p() must not return true until *all* devmap tables have been enabled.
console mapping may be present in the last table.


# 1.44 07-Sep-2019 ryo

- remove incorrect KASSERT. mmap(2) with prot=PROT_WRITE calls pmap_enter(..., PROT_WRITE) internally.
- fix to update page reference flags when only PROT_WRITE or PROT_EXECUTE specified


# 1.43 15-Aug-2019 skrll

Make pmap_db_pte_print more terse so it's quicker on serial consoles


# 1.42 12-Aug-2019 skrll

Use PMAP_DEV in DEVMAP_ENTRY rather than pmap_map_chunk. It's clearer and
means pmap_map_chunk can be made to map other memory types.


Revision tags: netbsd-9-base phil-wifi-20190609
# 1.41 17-May-2019 mrg

branches: 1.41.2;
apply some __diagused.


Revision tags: isaki-audio2-base
# 1.40 08-Apr-2019 ryo

- free empty page tables pages if reach a certain usage.
- need to lock at removing an old pg (_pmap_remove_pv) in _pmap_enter()


# 1.39 06-Apr-2019 ryo

Fix race conditions about pmap_page_protect() and pmap_enter().

while handling same PTE by these functions in same time, there
is a critical path that the number of valid PTEs and wire_count
are inconsistent, and it caused KASSERT.
Need to hold a pv_lock while modifying them.


# 1.38 20-Mar-2019 ryo

spinkle __printflike(), and use PRIxxx


# 1.37 19-Mar-2019 ryo

- add ddb command "machine ttbr" to dump MMU tables.
- tidy up descriptions, usages and messages.


# 1.36 19-Mar-2019 ryo

- free L1-L3 pages that has been emptied by pmap_remove().
- if no memories, pmap_enter will return correctly ENOMEM if PMAP_CANFAIL, or wait until available any memories if !PMAP_CANFAIL.

These changes improves the stability when we use a huge virtual memory spaces with mmap.


# 1.35 06-Feb-2019 ryo

improve pmap_remove
- don't lock/unlock per page in pmap_remove()
- speedup pte lookup for continuous addresses
- bring out pool_cache_put(&_pmap_pv_pool, pv) from lock/unlock section


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226
# 1.34 21-Dec-2018 ryo

- add workaround for Cavium ThunderX errata 27456.
- add cpufuncs table in cpu_info. each cpu clusters may have different erratum. (e.g. big.LITTLE)


Revision tags: pgoyette-compat-1126
# 1.33 01-Nov-2018 maxv

Add kASan support for aarch64. Stack tracking needs more investigation
and will come in a separate commit.

Reviewed by ryo@ jmcneill@ skrll@.


# 1.32 31-Oct-2018 ryo

invalidate icache correctly.
l3pte_executable() should be used for only valid pte.


Revision tags: pgoyette-compat-1020
# 1.31 18-Oct-2018 skrll

Provide generic start code that assumes the MMU is off and caches are
disabled as per the linux booting protocol for ARMv6 and ARMv7 boards.
u-boot image type should be changed to 'linux' for correct behaviour.

The new start code builds a minimal "bootstrap" L1PT with cached access
disabled and uses the same table for all processors. AP startup is
performed in less steps and more code is written in C.

The bootstrap tables and stack are placed into an (orphaned) section
"_init_memory" which is given to uvm when it is no longer used.

Various kernels have been converted to use this code and tested. Some
boards were provided by TNF. Thanks!

The GENERIC kernel now boots on boards using the TEGRA, SUNXI and EXYNOS
kernels. The GENERIC kernel will also work on RPI2 using u-boot.

Thanks to martin@ and aymeric@ for testing on parallella and nanosoc
respectively


# 1.30 14-Oct-2018 skrll

Use __nothing


# 1.29 12-Oct-2018 ryo

add initial support of COMPAT_NETBSD32 on AArch64.
arm ELF32 EABI binaries could be execute in AArch32 state on AArch64. A32 THUMB mode is not supported yet.


# 1.28 12-Oct-2018 ryo

- cleanup checking address ranges with IN_RANGE macro
- change PM_ADDR_CHECK macro to KASSERTMSG
- restore fast lookup cases with IN_RANGE macro for pmap_extract changed in my previous commit.


# 1.27 12-Oct-2018 ryo

rewrite pmap_pte_lookup() to share similar code.


# 1.26 04-Oct-2018 ryo

cleanup locore, and changed the way to map memories during boot.
- add functions bootpage_enter() and bootpage_alloc() to adapt various layout
of physical memory map. especially for 64bit physical memory layout.
pmapboot_alloc() allocates pagetable pages from _end[].
- changed to map only the required amount for PA=VA identity mapping
(kernel image, UART device, and FDT blob) with L2_BLOCK(2Mbyte).
- changing page permission for kernel image, and making KSEG mapping are done
at cpu_kernel_vm_init() instead of at locore.
- optimize PTE entries with PTE Contiguous bit. it is enabled on devmap only for now.

reviewed by skrll@, thanks.


# 1.25 04-Oct-2018 ryo

* define LX_BLKPAG_{OS,ATTR}_* for OS dependent PTE attributes in pmap.h
* cleanup macros


Revision tags: pgoyette-compat-0930
# 1.24 17-Sep-2018 ryo

delete debug printf and KASSERT.


# 1.23 10-Sep-2018 maxv

Replace KDASSERT by panic.


# 1.22 10-Sep-2018 maxv

Rename _pmap_alloc_pdp -> pmap_alloc_pdp, and make it public.


# 1.21 10-Sep-2018 ryo

cleanup aarch64 mpstart and fdt bootstrap
* arm_cpu_hatch_arg is a bad idea. avoid serializing CPU startup, and eliminate arm_cpu_hatch_arg.
in mpstart, resolve own cpu index using array of cpu_mpidr[] (aarch64)
* add support fdt enable-method "spin-table"
* add support fdt enable-method "brcm,bcm2836-smp" (for 32bit RaspberryPi)
* use arm_fdt_cpu_bootstrap() instead of psci_fdt_bootstrap()
* rename "arm/fdt/psci_fdt.h" to "arm/fdt/psci_fdtvar.h" because of conflict of include file for needs-flag
* add devmap for cpu spin-table of raspberrypi3/aarch64
* no need to force hatch APs for raspberrypi3/arm32 ifndef MULTIPROCESSOR.
* fix to work pmap_extract(kerneltext/data/bss) even if before calling pmap_bootstrap

idea to use cpu_mpidr[] by jmcneill@. reviewd by skrll@. thanks.


Revision tags: pgoyette-compat-0906
# 1.20 27-Aug-2018 ryo

need to add VM_PROT_READ when pmap_kenter_pa(va, pa, VM_PROT_WRITE, 0) or pmap_kenter_pa(va, pa, VM_PROT_EXECUTE, 0).
VM_PROT_READ is treated as an access permission inernally.


# 1.19 11-Aug-2018 ryo

change to minimum invalidation of TLB.
specifying not only va but also asid, and not invalidate L0-L2 entry using tlbi_*_ll() if needed.


# 1.18 10-Aug-2018 ryo

treat kernel-exec attr and user-exec attr separately.
kernel cannot execute userland exec page, and user cannot execute kernel page.


# 1.17 06-Aug-2018 ryo

set kernel text/rodata readonly by default.
add function db_write_text() for setting ddb breakpoint.


# 1.16 31-Jul-2018 skrll

Define and use VPRINTF


Revision tags: pgoyette-compat-0728
# 1.15 27-Jul-2018 ryo

changes of pmap.c r1.13 seems to be unstable.
In order to invalidate icache, not to invalidate all icache,
but temporary to make the page writable and invalidate target address only.


# 1.14 24-Jul-2018 ryo

don't call pool_cache_put with locking pmap. pool_cache_put call pmap_kenter_pa internally.
(pool_cache_put_paddr -> pool_cache_put_slow -> pool_get -> pmap_kenter_pa)


# 1.13 23-Jul-2018 ryo

* fix icache invalidations.
* "ic ivau" (aarch64_icache_sync_range) with VA generates permission fault in some situations, therefore use KSEG address for now.


# 1.12 23-Jul-2018 ryo

rather than using flags to resolve nested locks, reserve pool_cache before locking.


# 1.11 21-Jul-2018 ryo

* avoid deadlock. mutex_owned() works only for adaptive lock, therefore we cannot use it for spinlock...
* add more NULL check
* clear pte when pmap_enter() fails


# 1.10 17-Jul-2018 ryo

Use __debugused


# 1.9 17-Jul-2018 christos

Add missing casts, remove unused variables.


# 1.8 09-Jul-2018 ryo

need locks in pmap_kremove() and pmap_fault_fixup()


Revision tags: phil-wifi-base pgoyette-compat-0625 pgoyette-compat-0521
# 1.7 20-May-2018 ryo

branches: 1.7.2;
pmap_enter() must update modified/referenced flags by 'flags' not 'prot'.


# 1.6 16-May-2018 ryo

Fix memory leak. it was leaking one page every pmap_create().
pm->pm_vmlist must be initialized before calling _pmap_alloc_pdp().


Revision tags: pgoyette-compat-0502
# 1.5 29-Apr-2018 ryo

fix KASSERT panic. pv_entry may not be exists in pvlist when pmap_remove().


# 1.4 29-Apr-2018 ryo

delete unused code


# 1.3 27-Apr-2018 ryo

fix instability behavior of bufcache on aarch64.
* fix to return correct ref/mod when PMAP_WIRED.
* changed to keep wired flags in pte instead of pv_entry, and cleanup.


Revision tags: pgoyette-compat-0422 pgoyette-compat-0415 pgoyette-compat-0407
# 1.2 01-Apr-2018 ryo

Add initial support for ARMv8 (AARCH64) (by nisimura@ and ryo@)

- sys/arch/evbarm64 is gone and integrated into sys/arch/evbarm. (by skrll@)
- add support fdt. evbarm/conf/GENERIC64 fdt (bcm2837,sunxi,tegra) based generic 64bit kernel config. (by skrll@, jmcneill@)


Revision tags: netbsd-8-2-RELEASE netbsd-8-1-RELEASE netbsd-8-1-RC1 netbsd-7-2-RELEASE netbsd-8-0-RELEASE netbsd-8-0-RC2 netbsd-8-0-RC1 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 netbsd-7-1-2-RELEASE pgoyette-compat-base netbsd-7-1-1-RELEASE tls-maxphys-base-20171202 matt-nb8-mediatek-base nick-nhusb-base-20170825 perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base pgoyette-localcount-20170320 netbsd-7-1-RELEASE netbsd-7-1-RC2 nick-nhusb-base-20170204 netbsd-7-nhusb-base-20170116 bouyer-socketcan-base pgoyette-localcount-20170107 netbsd-7-1-RC1 nick-nhusb-base-20161204 pgoyette-localcount-20161104 netbsd-7-0-2-RELEASE nick-nhusb-base-20161004 localcount-20160914 netbsd-7-nhusb-base pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907 nick-nhusb-base-20160529 netbsd-7-0-1-RELEASE nick-nhusb-base-20160422 nick-nhusb-base-20160319 nick-nhusb-base-20151226 netbsd-7-0-RELEASE nick-nhusb-base-20150921 netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 nick-nhusb-base-20150606 nick-nhusb-base-20150406 nick-nhusb-base tls-maxphys-base netbsd-7-base
# 1.1 10-Aug-2014 matt

branches: 1.1.4; 1.1.28;
Preliminary files for AARCH64 (64-bit ARM) support.
Enough for a distribution build.


# 1.101 01-Feb-2021 ryo

It is enough to make a page accessible instead of writable.
same fix as r1.76


# 1.100 31-Jan-2021 ryo

implement pmap_remove_all().

The size of struct pv_entry has increased, but speed of kernel build has improved by about 1%
exec and exit should have been improved.


Revision tags: thorpej-futex-base
# 1.99 20-Dec-2020 skrll

Improve the English in the previous comment fix.


# 1.98 19-Dec-2020 skrll

Tweak a comment


# 1.97 11-Dec-2020 skrll

s:aarch64/cpufunc.h:arm/cpufunc.h:

a baby step in the grand arm header unification challenge


# 1.96 10-Nov-2020 skrll

AA64 is not MIPS.

Change all KSEG references to directmap


# 1.95 07-Nov-2020 skrll

In pmap_devmap_bootstrap only set pmap_devmap_bootstrap_done if there
is an entry and ALL of the entries have been done. The entry required
for EARLYCONS might not be the first/only one...


# 1.94 01-Nov-2020 jmcneill

branches: 1.94.2;
No need to disable translation table walks in pmap_activate().


# 1.93 22-Oct-2020 skrll

Use the isb macro - missed in previous commit


# 1.92 22-Oct-2020 skrll

Use the dmb/dsb/isb macros... if nothing else they're all now consistent
about the "memory" assembler contraint.

No binary change


# 1.91 28-Sep-2020 skrll

Only set pmap_devmap_bootstrap_done if something gets mapped.

Think acpi_platform_devmap


# 1.90 19-Sep-2020 skrll

Make __md_palloc pmap agnostic (think sys/uvm/pmap)


# 1.89 14-Sep-2020 ryo

PID_MAX is just an initial value (soft maximum). Don't use it for CTASSERT.
defined __HAVE_CPU_MAXPROC to use function cpu_maxproc().

pointed out by mrg@, thanks.


# 1.88 06-Sep-2020 ryo

Fix panic caused by modload. http://mail-index.netbsd.org/port-arm/2020/08/30/msg006960.html

The address space reserved for modules may not be mapped in L1-L3.


# 1.87 14-Aug-2020 skrll

Whitespace


# 1.86 12-Aug-2020 skrll

Part IV of ad's performance improvements for aarch64

- Implement pmap_growkernel(), and update kernel pmap's stats with atomics.

- Then, pmap_kenter_pa() and pmap_kremove() no longer need to allocate
memory nor take pm_lock, because they only modify L3 PTEs.

- Then, pm_lock and pp_lock can be adaptive mutexes at IPL_NONE which are
cheaper than spin mutexes.

- Take the pmap's lock in pmap_extract() if not the kernel's pmap, otherwise
pmap_extract() might see inconsistent state.


# 1.85 09-Aug-2020 skrll

Fix another UVMHIST so it doesn't use %s


# 1.84 16-Jul-2020 skrll

pmapboot_enter simplication
- bootpage_alloc in asm becomes pmapboot_pagealloc in C
- PMAPBOOT_ENTER_NOBLOCK is removed as it's not used
- PMAPBOOT_ENTER_NOOVERWRITE is removed as it's now always on
- physpage_allocator argument is removed as it's always
pmapboot_pagealloc
- Support for EARLYCONS without CONSADDR is removed so that the identity
map for CONSADDR is always known.

For the assembly files:
2 files changed, 40 insertions(+), 89 deletions(-)

LGTM ryo


# 1.83 04-Jul-2020 rin

Use tlen for temporary length variable instead of l, which is usually
used for struct lwp *.

No binary changes.


# 1.82 02-Jul-2020 rin

pmap_procwr(): sync icache even if p != curproc. This fixes applications
like GDB for arm32, that rewrite text of other process.

Thanks to ryo@ for discussion.


# 1.81 02-Jul-2020 rin

Set uvmexp.ncolors appropriately, which is required for some CPU
models with VIPT icache.

Otherwise, alias in virtual address results in inconsistent results,
at least for applications that rewrite text of other process, e.g.,
GDB for arm32.

Also, this hopefully fixes other unexpected failures due to alias.

Confirmed that there's no observable regression in performance;
difference in ``time make -j8'' for GENERIC64 kernel on BCM2837
with and without setting uvmexp.ncolors is within 0.1%.

Thanks to ryo@ for discussion.


# 1.80 27-Jun-2020 rin

Fix typo in name of evcnt(4) counter.


# 1.79 24-Jun-2020 ryo

Fix bug with incorrect range calculation when doing icache sync.
This is called by sysarch(ARM_SYNC_ICACHE) from aarch32 (compat_netbsd32) emul process.

pointed out by rin@, thanks.

XXX pullup-9


# 1.78 14-Jun-2020 ad

- Fix a lock order reversal in pmap_page_protect().

- Make sure pmap is always locked when updating stats; atomics no longer
needed to do that.

- Remove unneeded traversal of pv list in pmap_enter_pv().

- Shrink struct vm_page from 136 to 128 bytes (cache line sized) and struct
pv_entry from 48 to 32 bytes (power of 2 sized).

- Embed a pv_entry in each vm_page. This means PV entries don't need to
be allocated for private anonymous memory / COW pages / most UBC mappings.
Dynamic PV entries are then used only for stuff like shared libraries and
shared memory.

Proposed on port-arm@.


# 1.77 10-Jun-2020 ad

- Wired/resident stats shouldn't covered by PMAPCOUNTERS.
- Rename need_update_pv -> need_enter_pv.

Ok ryo@


# 1.76 01-Jun-2020 ryo

no need to make the PTE writable to do icache_sync, enough to accessible.


# 1.75 15-May-2020 skrll

Use __diagused


# 1.74 15-May-2020 tnn

fix non-diag build


# 1.73 14-May-2020 skrll

Use MUTEX_NODEBUG for PV locks as is commonly done. OK ryo.


# 1.72 13-May-2020 jmcneill

Implement pmap_extract_coherency


Revision tags: bouyer-xenpvh-base2 phil-wifi-20200421 bouyer-xenpvh-base1
# 1.71 18-Apr-2020 skrll

PMAP_DEBUG has been deleted on arm


# 1.70 13-Apr-2020 maxv

Add support for Branch Target Identification (BTI).

On the executable pages that have the GP (Guarded Page) bit, the semantic
of the "br" and "blr" instructions is changed: the CPU expects the first
instruction of the jump/call target to be "bti", and faults if it isn't.

We add the GP bit on the kernel .text pages (and incidentally the .rodata
pages, but we don't care). The compiler adds a "bti c" instruction at the
beginning of each C function. We modify the ENTRY() macros to manually add
"bti c" in the asm functions.

cpuswitch.S needs a specific change: with "br x27" the CPU expects "bti j",
which is bad because the functions begin with "bti c"; switch to "br x16",
for the CPU to accept "bti c".

BTI helps defend against JOP/COP. Tested on Qemu.


Revision tags: phil-wifi-20200411 bouyer-xenpvh-base
# 1.69 08-Apr-2020 ryo

branches: 1.69.2;
use PMAP_PAGE_INIT() to initialize mutex in pmap_page.

VM_MDPAGE_INIT() in pmap_free_pdp() had initialized pp_flags,
so it unintentionally cleared PMAP_PAGE_FLAGS_PV_TRACKED.
use PMAP_PAGE_INIT to avoid using PMAP_PAGE_FLAGS_PV_TRACKED.

pointed out by tnn@, thanks


Revision tags: phil-wifi-20200406
# 1.68 14-Mar-2020 ad

pmap_remove_all(): Return a boolean value to indicate the behaviour. If
true, all mappings have been removed, the pmap is totally cleared out, and
UVM can then avoid doing the work to call pmap_remove() for each map entry.
If false, either nothing has been done, or some helpful arch-specific voodoo
has taken place.


Revision tags: is-mlppp-base
# 1.67 02-Mar-2020 ryo

oops, fix incorrect usage of daif_enable() in my previous commit.


# 1.66 29-Feb-2020 ryo

Fix pmap to work correctly with tagged addresses

- when fault, untag from address before passing to uvm/pmap functions
- pmap_extract() checks more strictly and consider the address tag


# 1.65 29-Feb-2020 ryo

use pmapboot_enter_range()


Revision tags: ad-namecache-base3
# 1.64 10-Feb-2020 ryo

use LIST(3) instead of TAILQ(3) to save one word in struct vm_page and struct pmap.

pointed out by riastradh@. thanks


# 1.63 03-Feb-2020 ryo

add support pmap_pv(9)

Patch originally from jmcneill@. thanks


# 1.62 03-Feb-2020 ryo

separate struct vm_page_md into vm_page_md and pmap_page
for preparation pmap_pv(9)


Revision tags: ad-namecache-base2 ad-namecache-base1
# 1.61 09-Jan-2020 ryo

fix behaviour mmap()/mprotect() when passed only PROT_EXEC.

when mmap()/mprotect() with only PROT_EXEC, syscall will be successful,
but the page actually hadn't been mapped.
it should be mapped with PROT_READ|PROT_EXEC implicitly. (r-x)


Revision tags: ad-namecache-base
# 1.60 30-Dec-2019 skrll

branches: 1.60.2;
Update pmap_map_chunk to allow L[12] block mappings and L3 page mappings


# 1.59 30-Dec-2019 skrll

Remove unnecessary brackets and unwrap a conditional. Same code before
and after.


# 1.58 28-Dec-2019 jmcneill

Do not use Early Write Acknowledge for PCIe I/O and config space.


# 1.57 27-Dec-2019 jmcneill

Enable early write acknowledge for device memory mappings.


# 1.56 19-Dec-2019 skrll

G/C kasan_shadow_map call in pmap_enter

pmap_growkernel calls kasan_shadow_map for KVA


# 1.55 18-Dec-2019 ryo

atomic_add_16() is not used in pmap.c anymore. no need decl here.


# 1.54 18-Dec-2019 ryo

space to tab


# 1.53 14-Dec-2019 skrll

Fix build... wire_count probably doesn't need atomics


# 1.52 13-Dec-2019 skrll

Fix KASAN support by calling kasan_shadow_map in pmap_growkernel


# 1.51 10-Dec-2019 ad

pg->phys_addr -> VM_PAGE_TO_PHYS(pg)


Revision tags: phil-wifi-20191119
# 1.50 14-Nov-2019 maxv

Mark several kASan functions with __nothing, to avoid annoying #ifdefs.
Same as kCSan and kMSan.


# 1.49 14-Nov-2019 maxv

Don't include "opt_kasan.h" when there's already <sys/asan.h> included.


# 1.48 29-Oct-2019 maya

Define PMAP_NEED_PROCWR, providing strategically placed i-cache
synchronization where just-changed memory is about to be executed.

Fixes SIGILLs seen when running Mono 6 on QEMU Cortex-A57.

ok ryo


# 1.47 22-Sep-2019 jmcneill

Disable translation table walks using TTBR0 while changing its value and
when deactivating a pmap. Fixes stability issues on Ampere eMAG CPUs.


# 1.46 20-Sep-2019 ryo

ref/mod bit should be set according to 'flags' argument, not 'prot'. r1.44 was incomplete.


# 1.45 13-Sep-2019 ryo

In pmap_devmap_bootstrap(), cpu_earlydevice_va_p() must not return true until *all* devmap tables have been enabled.
console mapping may be present in the last table.


# 1.44 07-Sep-2019 ryo

- remove incorrect KASSERT. mmap(2) with prot=PROT_WRITE calls pmap_enter(..., PROT_WRITE) internally.
- fix to update page reference flags when only PROT_WRITE or PROT_EXECUTE specified


# 1.43 15-Aug-2019 skrll

Make pmap_db_pte_print more terse so it's quicker on serial consoles


# 1.42 12-Aug-2019 skrll

Use PMAP_DEV in DEVMAP_ENTRY rather than pmap_map_chunk. It's clearer and
means pmap_map_chunk can be made to map other memory types.


Revision tags: netbsd-9-base phil-wifi-20190609
# 1.41 17-May-2019 mrg

branches: 1.41.2;
apply some __diagused.


Revision tags: isaki-audio2-base
# 1.40 08-Apr-2019 ryo

- free empty page tables pages if reach a certain usage.
- need to lock at removing an old pg (_pmap_remove_pv) in _pmap_enter()


# 1.39 06-Apr-2019 ryo

Fix race conditions about pmap_page_protect() and pmap_enter().

while handling same PTE by these functions in same time, there
is a critical path that the number of valid PTEs and wire_count
are inconsistent, and it caused KASSERT.
Need to hold a pv_lock while modifying them.


# 1.38 20-Mar-2019 ryo

spinkle __printflike(), and use PRIxxx


# 1.37 19-Mar-2019 ryo

- add ddb command "machine ttbr" to dump MMU tables.
- tidy up descriptions, usages and messages.


# 1.36 19-Mar-2019 ryo

- free L1-L3 pages that has been emptied by pmap_remove().
- if no memories, pmap_enter will return correctly ENOMEM if PMAP_CANFAIL, or wait until available any memories if !PMAP_CANFAIL.

These changes improves the stability when we use a huge virtual memory spaces with mmap.


# 1.35 06-Feb-2019 ryo

improve pmap_remove
- don't lock/unlock per page in pmap_remove()
- speedup pte lookup for continuous addresses
- bring out pool_cache_put(&_pmap_pv_pool, pv) from lock/unlock section


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226
# 1.34 21-Dec-2018 ryo

- add workaround for Cavium ThunderX errata 27456.
- add cpufuncs table in cpu_info. each cpu clusters may have different erratum. (e.g. big.LITTLE)


Revision tags: pgoyette-compat-1126
# 1.33 01-Nov-2018 maxv

Add kASan support for aarch64. Stack tracking needs more investigation
and will come in a separate commit.

Reviewed by ryo@ jmcneill@ skrll@.


# 1.32 31-Oct-2018 ryo

invalidate icache correctly.
l3pte_executable() should be used for only valid pte.


Revision tags: pgoyette-compat-1020
# 1.31 18-Oct-2018 skrll

Provide generic start code that assumes the MMU is off and caches are
disabled as per the linux booting protocol for ARMv6 and ARMv7 boards.
u-boot image type should be changed to 'linux' for correct behaviour.

The new start code builds a minimal "bootstrap" L1PT with cached access
disabled and uses the same table for all processors. AP startup is
performed in less steps and more code is written in C.

The bootstrap tables and stack are placed into an (orphaned) section
"_init_memory" which is given to uvm when it is no longer used.

Various kernels have been converted to use this code and tested. Some
boards were provided by TNF. Thanks!

The GENERIC kernel now boots on boards using the TEGRA, SUNXI and EXYNOS
kernels. The GENERIC kernel will also work on RPI2 using u-boot.

Thanks to martin@ and aymeric@ for testing on parallella and nanosoc
respectively


# 1.30 14-Oct-2018 skrll

Use __nothing


# 1.29 12-Oct-2018 ryo

add initial support of COMPAT_NETBSD32 on AArch64.
arm ELF32 EABI binaries could be execute in AArch32 state on AArch64. A32 THUMB mode is not supported yet.


# 1.28 12-Oct-2018 ryo

- cleanup checking address ranges with IN_RANGE macro
- change PM_ADDR_CHECK macro to KASSERTMSG
- restore fast lookup cases with IN_RANGE macro for pmap_extract changed in my previous commit.


# 1.27 12-Oct-2018 ryo

rewrite pmap_pte_lookup() to share similar code.


# 1.26 04-Oct-2018 ryo

cleanup locore, and changed the way to map memories during boot.
- add functions bootpage_enter() and bootpage_alloc() to adapt various layout
of physical memory map. especially for 64bit physical memory layout.
pmapboot_alloc() allocates pagetable pages from _end[].
- changed to map only the required amount for PA=VA identity mapping
(kernel image, UART device, and FDT blob) with L2_BLOCK(2Mbyte).
- changing page permission for kernel image, and making KSEG mapping are done
at cpu_kernel_vm_init() instead of at locore.
- optimize PTE entries with PTE Contiguous bit. it is enabled on devmap only for now.

reviewed by skrll@, thanks.


# 1.25 04-Oct-2018 ryo

* define LX_BLKPAG_{OS,ATTR}_* for OS dependent PTE attributes in pmap.h
* cleanup macros


Revision tags: pgoyette-compat-0930
# 1.24 17-Sep-2018 ryo

delete debug printf and KASSERT.


# 1.23 10-Sep-2018 maxv

Replace KDASSERT by panic.


# 1.22 10-Sep-2018 maxv

Rename _pmap_alloc_pdp -> pmap_alloc_pdp, and make it public.


# 1.21 10-Sep-2018 ryo

cleanup aarch64 mpstart and fdt bootstrap
* arm_cpu_hatch_arg is a bad idea. avoid serializing CPU startup, and eliminate arm_cpu_hatch_arg.
in mpstart, resolve own cpu index using array of cpu_mpidr[] (aarch64)
* add support fdt enable-method "spin-table"
* add support fdt enable-method "brcm,bcm2836-smp" (for 32bit RaspberryPi)
* use arm_fdt_cpu_bootstrap() instead of psci_fdt_bootstrap()
* rename "arm/fdt/psci_fdt.h" to "arm/fdt/psci_fdtvar.h" because of conflict of include file for needs-flag
* add devmap for cpu spin-table of raspberrypi3/aarch64
* no need to force hatch APs for raspberrypi3/arm32 ifndef MULTIPROCESSOR.
* fix to work pmap_extract(kerneltext/data/bss) even if before calling pmap_bootstrap

idea to use cpu_mpidr[] by jmcneill@. reviewd by skrll@. thanks.


Revision tags: pgoyette-compat-0906
# 1.20 27-Aug-2018 ryo

need to add VM_PROT_READ when pmap_kenter_pa(va, pa, VM_PROT_WRITE, 0) or pmap_kenter_pa(va, pa, VM_PROT_EXECUTE, 0).
VM_PROT_READ is treated as an access permission inernally.


# 1.19 11-Aug-2018 ryo

change to minimum invalidation of TLB.
specifying not only va but also asid, and not invalidate L0-L2 entry using tlbi_*_ll() if needed.


# 1.18 10-Aug-2018 ryo

treat kernel-exec attr and user-exec attr separately.
kernel cannot execute userland exec page, and user cannot execute kernel page.


# 1.17 06-Aug-2018 ryo

set kernel text/rodata readonly by default.
add function db_write_text() for setting ddb breakpoint.


# 1.16 31-Jul-2018 skrll

Define and use VPRINTF


Revision tags: pgoyette-compat-0728
# 1.15 27-Jul-2018 ryo

changes of pmap.c r1.13 seems to be unstable.
In order to invalidate icache, not to invalidate all icache,
but temporary to make the page writable and invalidate target address only.


# 1.14 24-Jul-2018 ryo

don't call pool_cache_put with locking pmap. pool_cache_put call pmap_kenter_pa internally.
(pool_cache_put_paddr -> pool_cache_put_slow -> pool_get -> pmap_kenter_pa)


# 1.13 23-Jul-2018 ryo

* fix icache invalidations.
* "ic ivau" (aarch64_icache_sync_range) with VA generates permission fault in some situations, therefore use KSEG address for now.


# 1.12 23-Jul-2018 ryo

rather than using flags to resolve nested locks, reserve pool_cache before locking.


# 1.11 21-Jul-2018 ryo

* avoid deadlock. mutex_owned() works only for adaptive lock, therefore we cannot use it for spinlock...
* add more NULL check
* clear pte when pmap_enter() fails


# 1.10 17-Jul-2018 ryo

Use __debugused


# 1.9 17-Jul-2018 christos

Add missing casts, remove unused variables.


# 1.8 09-Jul-2018 ryo

need locks in pmap_kremove() and pmap_fault_fixup()


Revision tags: phil-wifi-base pgoyette-compat-0625 pgoyette-compat-0521
# 1.7 20-May-2018 ryo

branches: 1.7.2;
pmap_enter() must update modified/referenced flags by 'flags' not 'prot'.


# 1.6 16-May-2018 ryo

Fix memory leak. it was leaking one page every pmap_create().
pm->pm_vmlist must be initialized before calling _pmap_alloc_pdp().


Revision tags: pgoyette-compat-0502
# 1.5 29-Apr-2018 ryo

fix KASSERT panic. pv_entry may not be exists in pvlist when pmap_remove().


# 1.4 29-Apr-2018 ryo

delete unused code


# 1.3 27-Apr-2018 ryo

fix instability behavior of bufcache on aarch64.
* fix to return correct ref/mod when PMAP_WIRED.
* changed to keep wired flags in pte instead of pv_entry, and cleanup.


Revision tags: pgoyette-compat-0422 pgoyette-compat-0415 pgoyette-compat-0407
# 1.2 01-Apr-2018 ryo

Add initial support for ARMv8 (AARCH64) (by nisimura@ and ryo@)

- sys/arch/evbarm64 is gone and integrated into sys/arch/evbarm. (by skrll@)
- add support fdt. evbarm/conf/GENERIC64 fdt (bcm2837,sunxi,tegra) based generic 64bit kernel config. (by skrll@, jmcneill@)


Revision tags: netbsd-8-2-RELEASE netbsd-8-1-RELEASE netbsd-8-1-RC1 netbsd-7-2-RELEASE netbsd-8-0-RELEASE netbsd-8-0-RC2 netbsd-8-0-RC1 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 netbsd-7-1-2-RELEASE pgoyette-compat-base netbsd-7-1-1-RELEASE tls-maxphys-base-20171202 matt-nb8-mediatek-base nick-nhusb-base-20170825 perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base pgoyette-localcount-20170320 netbsd-7-1-RELEASE netbsd-7-1-RC2 nick-nhusb-base-20170204 netbsd-7-nhusb-base-20170116 bouyer-socketcan-base pgoyette-localcount-20170107 netbsd-7-1-RC1 nick-nhusb-base-20161204 pgoyette-localcount-20161104 netbsd-7-0-2-RELEASE nick-nhusb-base-20161004 localcount-20160914 netbsd-7-nhusb-base pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907 nick-nhusb-base-20160529 netbsd-7-0-1-RELEASE nick-nhusb-base-20160422 nick-nhusb-base-20160319 nick-nhusb-base-20151226 netbsd-7-0-RELEASE nick-nhusb-base-20150921 netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 nick-nhusb-base-20150606 nick-nhusb-base-20150406 nick-nhusb-base tls-maxphys-base netbsd-7-base
# 1.1 10-Aug-2014 matt

branches: 1.1.4; 1.1.28;
Preliminary files for AARCH64 (64-bit ARM) support.
Enough for a distribution build.


# 1.100 31-Jan-2021 ryo

implement pmap_remove_all().

The size of struct pv_entry has increased, but speed of kernel build has improved by about 1%
exec and exit should have been improved.


Revision tags: thorpej-futex-base
# 1.99 20-Dec-2020 skrll

Improve the English in the previous comment fix.


# 1.98 19-Dec-2020 skrll

Tweak a comment


# 1.97 11-Dec-2020 skrll

s:aarch64/cpufunc.h:arm/cpufunc.h:

a baby step in the grand arm header unification challenge


# 1.96 10-Nov-2020 skrll

AA64 is not MIPS.

Change all KSEG references to directmap


# 1.95 07-Nov-2020 skrll

In pmap_devmap_bootstrap only set pmap_devmap_bootstrap_done if there
is an entry and ALL of the entries have been done. The entry required
for EARLYCONS might not be the first/only one...


# 1.94 01-Nov-2020 jmcneill

branches: 1.94.2;
No need to disable translation table walks in pmap_activate().


# 1.93 22-Oct-2020 skrll

Use the isb macro - missed in previous commit


# 1.92 22-Oct-2020 skrll

Use the dmb/dsb/isb macros... if nothing else they're all now consistent
about the "memory" assembler contraint.

No binary change


# 1.91 28-Sep-2020 skrll

Only set pmap_devmap_bootstrap_done if something gets mapped.

Think acpi_platform_devmap


# 1.90 19-Sep-2020 skrll

Make __md_palloc pmap agnostic (think sys/uvm/pmap)


# 1.89 14-Sep-2020 ryo

PID_MAX is just an initial value (soft maximum). Don't use it for CTASSERT.
defined __HAVE_CPU_MAXPROC to use function cpu_maxproc().

pointed out by mrg@, thanks.


# 1.88 06-Sep-2020 ryo

Fix panic caused by modload. http://mail-index.netbsd.org/port-arm/2020/08/30/msg006960.html

The address space reserved for modules may not be mapped in L1-L3.


# 1.87 14-Aug-2020 skrll

Whitespace


# 1.86 12-Aug-2020 skrll

Part IV of ad's performance improvements for aarch64

- Implement pmap_growkernel(), and update kernel pmap's stats with atomics.

- Then, pmap_kenter_pa() and pmap_kremove() no longer need to allocate
memory nor take pm_lock, because they only modify L3 PTEs.

- Then, pm_lock and pp_lock can be adaptive mutexes at IPL_NONE which are
cheaper than spin mutexes.

- Take the pmap's lock in pmap_extract() if not the kernel's pmap, otherwise
pmap_extract() might see inconsistent state.


# 1.85 09-Aug-2020 skrll

Fix another UVMHIST so it doesn't use %s


# 1.84 16-Jul-2020 skrll

pmapboot_enter simplication
- bootpage_alloc in asm becomes pmapboot_pagealloc in C
- PMAPBOOT_ENTER_NOBLOCK is removed as it's not used
- PMAPBOOT_ENTER_NOOVERWRITE is removed as it's now always on
- physpage_allocator argument is removed as it's always
pmapboot_pagealloc
- Support for EARLYCONS without CONSADDR is removed so that the identity
map for CONSADDR is always known.

For the assembly files:
2 files changed, 40 insertions(+), 89 deletions(-)

LGTM ryo


# 1.83 04-Jul-2020 rin

Use tlen for temporary length variable instead of l, which is usually
used for struct lwp *.

No binary changes.


# 1.82 02-Jul-2020 rin

pmap_procwr(): sync icache even if p != curproc. This fixes applications
like GDB for arm32, that rewrite text of other process.

Thanks to ryo@ for discussion.


# 1.81 02-Jul-2020 rin

Set uvmexp.ncolors appropriately, which is required for some CPU
models with VIPT icache.

Otherwise, alias in virtual address results in inconsistent results,
at least for applications that rewrite text of other process, e.g.,
GDB for arm32.

Also, this hopefully fixes other unexpected failures due to alias.

Confirmed that there's no observable regression in performance;
difference in ``time make -j8'' for GENERIC64 kernel on BCM2837
with and without setting uvmexp.ncolors is within 0.1%.

Thanks to ryo@ for discussion.


# 1.80 27-Jun-2020 rin

Fix typo in name of evcnt(4) counter.


# 1.79 24-Jun-2020 ryo

Fix bug with incorrect range calculation when doing icache sync.
This is called by sysarch(ARM_SYNC_ICACHE) from aarch32 (compat_netbsd32) emul process.

pointed out by rin@, thanks.

XXX pullup-9


# 1.78 14-Jun-2020 ad

- Fix a lock order reversal in pmap_page_protect().

- Make sure pmap is always locked when updating stats; atomics no longer
needed to do that.

- Remove unneeded traversal of pv list in pmap_enter_pv().

- Shrink struct vm_page from 136 to 128 bytes (cache line sized) and struct
pv_entry from 48 to 32 bytes (power of 2 sized).

- Embed a pv_entry in each vm_page. This means PV entries don't need to
be allocated for private anonymous memory / COW pages / most UBC mappings.
Dynamic PV entries are then used only for stuff like shared libraries and
shared memory.

Proposed on port-arm@.


# 1.77 10-Jun-2020 ad

- Wired/resident stats shouldn't covered by PMAPCOUNTERS.
- Rename need_update_pv -> need_enter_pv.

Ok ryo@


# 1.76 01-Jun-2020 ryo

no need to make the PTE writable to do icache_sync, enough to accessible.


# 1.75 15-May-2020 skrll

Use __diagused


# 1.74 15-May-2020 tnn

fix non-diag build


# 1.73 14-May-2020 skrll

Use MUTEX_NODEBUG for PV locks as is commonly done. OK ryo.


# 1.72 13-May-2020 jmcneill

Implement pmap_extract_coherency


Revision tags: bouyer-xenpvh-base2 phil-wifi-20200421 bouyer-xenpvh-base1
# 1.71 18-Apr-2020 skrll

PMAP_DEBUG has been deleted on arm


# 1.70 13-Apr-2020 maxv

Add support for Branch Target Identification (BTI).

On the executable pages that have the GP (Guarded Page) bit, the semantic
of the "br" and "blr" instructions is changed: the CPU expects the first
instruction of the jump/call target to be "bti", and faults if it isn't.

We add the GP bit on the kernel .text pages (and incidentally the .rodata
pages, but we don't care). The compiler adds a "bti c" instruction at the
beginning of each C function. We modify the ENTRY() macros to manually add
"bti c" in the asm functions.

cpuswitch.S needs a specific change: with "br x27" the CPU expects "bti j",
which is bad because the functions begin with "bti c"; switch to "br x16",
for the CPU to accept "bti c".

BTI helps defend against JOP/COP. Tested on Qemu.


Revision tags: phil-wifi-20200411 bouyer-xenpvh-base
# 1.69 08-Apr-2020 ryo

branches: 1.69.2;
use PMAP_PAGE_INIT() to initialize mutex in pmap_page.

VM_MDPAGE_INIT() in pmap_free_pdp() had initialized pp_flags,
so it unintentionally cleared PMAP_PAGE_FLAGS_PV_TRACKED.
use PMAP_PAGE_INIT to avoid using PMAP_PAGE_FLAGS_PV_TRACKED.

pointed out by tnn@, thanks


Revision tags: phil-wifi-20200406
# 1.68 14-Mar-2020 ad

pmap_remove_all(): Return a boolean value to indicate the behaviour. If
true, all mappings have been removed, the pmap is totally cleared out, and
UVM can then avoid doing the work to call pmap_remove() for each map entry.
If false, either nothing has been done, or some helpful arch-specific voodoo
has taken place.


Revision tags: is-mlppp-base
# 1.67 02-Mar-2020 ryo

oops, fix incorrect usage of daif_enable() in my previous commit.


# 1.66 29-Feb-2020 ryo

Fix pmap to work correctly with tagged addresses

- when fault, untag from address before passing to uvm/pmap functions
- pmap_extract() checks more strictly and consider the address tag


# 1.65 29-Feb-2020 ryo

use pmapboot_enter_range()


Revision tags: ad-namecache-base3
# 1.64 10-Feb-2020 ryo

use LIST(3) instead of TAILQ(3) to save one word in struct vm_page and struct pmap.

pointed out by riastradh@. thanks


# 1.63 03-Feb-2020 ryo

add support pmap_pv(9)

Patch originally from jmcneill@. thanks


# 1.62 03-Feb-2020 ryo

separate struct vm_page_md into vm_page_md and pmap_page
for preparation pmap_pv(9)


Revision tags: ad-namecache-base2 ad-namecache-base1
# 1.61 09-Jan-2020 ryo

fix behaviour mmap()/mprotect() when passed only PROT_EXEC.

when mmap()/mprotect() with only PROT_EXEC, syscall will be successful,
but the page actually hadn't been mapped.
it should be mapped with PROT_READ|PROT_EXEC implicitly. (r-x)


Revision tags: ad-namecache-base
# 1.60 30-Dec-2019 skrll

branches: 1.60.2;
Update pmap_map_chunk to allow L[12] block mappings and L3 page mappings


# 1.59 30-Dec-2019 skrll

Remove unnecessary brackets and unwrap a conditional. Same code before
and after.


# 1.58 28-Dec-2019 jmcneill

Do not use Early Write Acknowledge for PCIe I/O and config space.


# 1.57 27-Dec-2019 jmcneill

Enable early write acknowledge for device memory mappings.


# 1.56 19-Dec-2019 skrll

G/C kasan_shadow_map call in pmap_enter

pmap_growkernel calls kasan_shadow_map for KVA


# 1.55 18-Dec-2019 ryo

atomic_add_16() is not used in pmap.c anymore. no need decl here.


# 1.54 18-Dec-2019 ryo

space to tab


# 1.53 14-Dec-2019 skrll

Fix build... wire_count probably doesn't need atomics


# 1.52 13-Dec-2019 skrll

Fix KASAN support by calling kasan_shadow_map in pmap_growkernel


# 1.51 10-Dec-2019 ad

pg->phys_addr -> VM_PAGE_TO_PHYS(pg)


Revision tags: phil-wifi-20191119
# 1.50 14-Nov-2019 maxv

Mark several kASan functions with __nothing, to avoid annoying #ifdefs.
Same as kCSan and kMSan.


# 1.49 14-Nov-2019 maxv

Don't include "opt_kasan.h" when there's already <sys/asan.h> included.


# 1.48 29-Oct-2019 maya

Define PMAP_NEED_PROCWR, providing strategically placed i-cache
synchronization where just-changed memory is about to be executed.

Fixes SIGILLs seen when running Mono 6 on QEMU Cortex-A57.

ok ryo


# 1.47 22-Sep-2019 jmcneill

Disable translation table walks using TTBR0 while changing its value and
when deactivating a pmap. Fixes stability issues on Ampere eMAG CPUs.


# 1.46 20-Sep-2019 ryo

ref/mod bit should be set according to 'flags' argument, not 'prot'. r1.44 was incomplete.


# 1.45 13-Sep-2019 ryo

In pmap_devmap_bootstrap(), cpu_earlydevice_va_p() must not return true until *all* devmap tables have been enabled.
console mapping may be present in the last table.


# 1.44 07-Sep-2019 ryo

- remove incorrect KASSERT. mmap(2) with prot=PROT_WRITE calls pmap_enter(..., PROT_WRITE) internally.
- fix to update page reference flags when only PROT_WRITE or PROT_EXECUTE specified


# 1.43 15-Aug-2019 skrll

Make pmap_db_pte_print more terse so it's quicker on serial consoles


# 1.42 12-Aug-2019 skrll

Use PMAP_DEV in DEVMAP_ENTRY rather than pmap_map_chunk. It's clearer and
means pmap_map_chunk can be made to map other memory types.


Revision tags: netbsd-9-base phil-wifi-20190609
# 1.41 17-May-2019 mrg

branches: 1.41.2;
apply some __diagused.


Revision tags: isaki-audio2-base
# 1.40 08-Apr-2019 ryo

- free empty page tables pages if reach a certain usage.
- need to lock at removing an old pg (_pmap_remove_pv) in _pmap_enter()


# 1.39 06-Apr-2019 ryo

Fix race conditions about pmap_page_protect() and pmap_enter().

while handling same PTE by these functions in same time, there
is a critical path that the number of valid PTEs and wire_count
are inconsistent, and it caused KASSERT.
Need to hold a pv_lock while modifying them.


# 1.38 20-Mar-2019 ryo

spinkle __printflike(), and use PRIxxx


# 1.37 19-Mar-2019 ryo

- add ddb command "machine ttbr" to dump MMU tables.
- tidy up descriptions, usages and messages.


# 1.36 19-Mar-2019 ryo

- free L1-L3 pages that has been emptied by pmap_remove().
- if no memories, pmap_enter will return correctly ENOMEM if PMAP_CANFAIL, or wait until available any memories if !PMAP_CANFAIL.

These changes improves the stability when we use a huge virtual memory spaces with mmap.


# 1.35 06-Feb-2019 ryo

improve pmap_remove
- don't lock/unlock per page in pmap_remove()
- speedup pte lookup for continuous addresses
- bring out pool_cache_put(&_pmap_pv_pool, pv) from lock/unlock section


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226
# 1.34 21-Dec-2018 ryo

- add workaround for Cavium ThunderX errata 27456.
- add cpufuncs table in cpu_info. each cpu clusters may have different erratum. (e.g. big.LITTLE)


Revision tags: pgoyette-compat-1126
# 1.33 01-Nov-2018 maxv

Add kASan support for aarch64. Stack tracking needs more investigation
and will come in a separate commit.

Reviewed by ryo@ jmcneill@ skrll@.


# 1.32 31-Oct-2018 ryo

invalidate icache correctly.
l3pte_executable() should be used for only valid pte.


Revision tags: pgoyette-compat-1020
# 1.31 18-Oct-2018 skrll

Provide generic start code that assumes the MMU is off and caches are
disabled as per the linux booting protocol for ARMv6 and ARMv7 boards.
u-boot image type should be changed to 'linux' for correct behaviour.

The new start code builds a minimal "bootstrap" L1PT with cached access
disabled and uses the same table for all processors. AP startup is
performed in less steps and more code is written in C.

The bootstrap tables and stack are placed into an (orphaned) section
"_init_memory" which is given to uvm when it is no longer used.

Various kernels have been converted to use this code and tested. Some
boards were provided by TNF. Thanks!

The GENERIC kernel now boots on boards using the TEGRA, SUNXI and EXYNOS
kernels. The GENERIC kernel will also work on RPI2 using u-boot.

Thanks to martin@ and aymeric@ for testing on parallella and nanosoc
respectively


# 1.30 14-Oct-2018 skrll

Use __nothing


# 1.29 12-Oct-2018 ryo

add initial support of COMPAT_NETBSD32 on AArch64.
arm ELF32 EABI binaries could be execute in AArch32 state on AArch64. A32 THUMB mode is not supported yet.


# 1.28 12-Oct-2018 ryo

- cleanup checking address ranges with IN_RANGE macro
- change PM_ADDR_CHECK macro to KASSERTMSG
- restore fast lookup cases with IN_RANGE macro for pmap_extract changed in my previous commit.


# 1.27 12-Oct-2018 ryo

rewrite pmap_pte_lookup() to share similar code.


# 1.26 04-Oct-2018 ryo

cleanup locore, and changed the way to map memories during boot.
- add functions bootpage_enter() and bootpage_alloc() to adapt various layout
of physical memory map. especially for 64bit physical memory layout.
pmapboot_alloc() allocates pagetable pages from _end[].
- changed to map only the required amount for PA=VA identity mapping
(kernel image, UART device, and FDT blob) with L2_BLOCK(2Mbyte).
- changing page permission for kernel image, and making KSEG mapping are done
at cpu_kernel_vm_init() instead of at locore.
- optimize PTE entries with PTE Contiguous bit. it is enabled on devmap only for now.

reviewed by skrll@, thanks.


# 1.25 04-Oct-2018 ryo

* define LX_BLKPAG_{OS,ATTR}_* for OS dependent PTE attributes in pmap.h
* cleanup macros


Revision tags: pgoyette-compat-0930
# 1.24 17-Sep-2018 ryo

delete debug printf and KASSERT.


# 1.23 10-Sep-2018 maxv

Replace KDASSERT by panic.


# 1.22 10-Sep-2018 maxv

Rename _pmap_alloc_pdp -> pmap_alloc_pdp, and make it public.


# 1.21 10-Sep-2018 ryo

cleanup aarch64 mpstart and fdt bootstrap
* arm_cpu_hatch_arg is a bad idea. avoid serializing CPU startup, and eliminate arm_cpu_hatch_arg.
in mpstart, resolve own cpu index using array of cpu_mpidr[] (aarch64)
* add support fdt enable-method "spin-table"
* add support fdt enable-method "brcm,bcm2836-smp" (for 32bit RaspberryPi)
* use arm_fdt_cpu_bootstrap() instead of psci_fdt_bootstrap()
* rename "arm/fdt/psci_fdt.h" to "arm/fdt/psci_fdtvar.h" because of conflict of include file for needs-flag
* add devmap for cpu spin-table of raspberrypi3/aarch64
* no need to force hatch APs for raspberrypi3/arm32 ifndef MULTIPROCESSOR.
* fix to work pmap_extract(kerneltext/data/bss) even if before calling pmap_bootstrap

idea to use cpu_mpidr[] by jmcneill@. reviewd by skrll@. thanks.


Revision tags: pgoyette-compat-0906
# 1.20 27-Aug-2018 ryo

need to add VM_PROT_READ when pmap_kenter_pa(va, pa, VM_PROT_WRITE, 0) or pmap_kenter_pa(va, pa, VM_PROT_EXECUTE, 0).
VM_PROT_READ is treated as an access permission inernally.


# 1.19 11-Aug-2018 ryo

change to minimum invalidation of TLB.
specifying not only va but also asid, and not invalidate L0-L2 entry using tlbi_*_ll() if needed.


# 1.18 10-Aug-2018 ryo

treat kernel-exec attr and user-exec attr separately.
kernel cannot execute userland exec page, and user cannot execute kernel page.


# 1.17 06-Aug-2018 ryo

set kernel text/rodata readonly by default.
add function db_write_text() for setting ddb breakpoint.


# 1.16 31-Jul-2018 skrll

Define and use VPRINTF


Revision tags: pgoyette-compat-0728
# 1.15 27-Jul-2018 ryo

changes of pmap.c r1.13 seems to be unstable.
In order to invalidate icache, not to invalidate all icache,
but temporary to make the page writable and invalidate target address only.


# 1.14 24-Jul-2018 ryo

don't call pool_cache_put with locking pmap. pool_cache_put call pmap_kenter_pa internally.
(pool_cache_put_paddr -> pool_cache_put_slow -> pool_get -> pmap_kenter_pa)


# 1.13 23-Jul-2018 ryo

* fix icache invalidations.
* "ic ivau" (aarch64_icache_sync_range) with VA generates permission fault in some situations, therefore use KSEG address for now.


# 1.12 23-Jul-2018 ryo

rather than using flags to resolve nested locks, reserve pool_cache before locking.


# 1.11 21-Jul-2018 ryo

* avoid deadlock. mutex_owned() works only for adaptive lock, therefore we cannot use it for spinlock...
* add more NULL check
* clear pte when pmap_enter() fails


# 1.10 17-Jul-2018 ryo

Use __debugused


# 1.9 17-Jul-2018 christos

Add missing casts, remove unused variables.


# 1.8 09-Jul-2018 ryo

need locks in pmap_kremove() and pmap_fault_fixup()


Revision tags: phil-wifi-base pgoyette-compat-0625 pgoyette-compat-0521
# 1.7 20-May-2018 ryo

branches: 1.7.2;
pmap_enter() must update modified/referenced flags by 'flags' not 'prot'.


# 1.6 16-May-2018 ryo

Fix memory leak. it was leaking one page every pmap_create().
pm->pm_vmlist must be initialized before calling _pmap_alloc_pdp().


Revision tags: pgoyette-compat-0502
# 1.5 29-Apr-2018 ryo

fix KASSERT panic. pv_entry may not be exists in pvlist when pmap_remove().


# 1.4 29-Apr-2018 ryo

delete unused code


# 1.3 27-Apr-2018 ryo

fix instability behavior of bufcache on aarch64.
* fix to return correct ref/mod when PMAP_WIRED.
* changed to keep wired flags in pte instead of pv_entry, and cleanup.


Revision tags: pgoyette-compat-0422 pgoyette-compat-0415 pgoyette-compat-0407
# 1.2 01-Apr-2018 ryo

Add initial support for ARMv8 (AARCH64) (by nisimura@ and ryo@)

- sys/arch/evbarm64 is gone and integrated into sys/arch/evbarm. (by skrll@)
- add support fdt. evbarm/conf/GENERIC64 fdt (bcm2837,sunxi,tegra) based generic 64bit kernel config. (by skrll@, jmcneill@)


Revision tags: netbsd-8-2-RELEASE netbsd-8-1-RELEASE netbsd-8-1-RC1 netbsd-7-2-RELEASE netbsd-8-0-RELEASE netbsd-8-0-RC2 netbsd-8-0-RC1 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 netbsd-7-1-2-RELEASE pgoyette-compat-base netbsd-7-1-1-RELEASE tls-maxphys-base-20171202 matt-nb8-mediatek-base nick-nhusb-base-20170825 perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base pgoyette-localcount-20170320 netbsd-7-1-RELEASE netbsd-7-1-RC2 nick-nhusb-base-20170204 netbsd-7-nhusb-base-20170116 bouyer-socketcan-base pgoyette-localcount-20170107 netbsd-7-1-RC1 nick-nhusb-base-20161204 pgoyette-localcount-20161104 netbsd-7-0-2-RELEASE nick-nhusb-base-20161004 localcount-20160914 netbsd-7-nhusb-base pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907 nick-nhusb-base-20160529 netbsd-7-0-1-RELEASE nick-nhusb-base-20160422 nick-nhusb-base-20160319 nick-nhusb-base-20151226 netbsd-7-0-RELEASE nick-nhusb-base-20150921 netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 nick-nhusb-base-20150606 nick-nhusb-base-20150406 nick-nhusb-base tls-maxphys-base netbsd-7-base
# 1.1 10-Aug-2014 matt

branches: 1.1.4; 1.1.28;
Preliminary files for AARCH64 (64-bit ARM) support.
Enough for a distribution build.


# 1.99 20-Dec-2020 skrll

Improve the English in the previous comment fix.


# 1.98 19-Dec-2020 skrll

Tweak a comment


Revision tags: thorpej-futex-base
# 1.97 11-Dec-2020 skrll

s:aarch64/cpufunc.h:arm/cpufunc.h:

a baby step in the grand arm header unification challenge


# 1.96 10-Nov-2020 skrll

AA64 is not MIPS.

Change all KSEG references to directmap


# 1.95 07-Nov-2020 skrll

In pmap_devmap_bootstrap only set pmap_devmap_bootstrap_done if there
is an entry and ALL of the entries have been done. The entry required
for EARLYCONS might not be the first/only one...


# 1.94 01-Nov-2020 jmcneill

branches: 1.94.2;
No need to disable translation table walks in pmap_activate().


# 1.93 22-Oct-2020 skrll

Use the isb macro - missed in previous commit


# 1.92 22-Oct-2020 skrll

Use the dmb/dsb/isb macros... if nothing else they're all now consistent
about the "memory" assembler contraint.

No binary change


# 1.91 28-Sep-2020 skrll

Only set pmap_devmap_bootstrap_done if something gets mapped.

Think acpi_platform_devmap


# 1.90 19-Sep-2020 skrll

Make __md_palloc pmap agnostic (think sys/uvm/pmap)


# 1.89 14-Sep-2020 ryo

PID_MAX is just an initial value (soft maximum). Don't use it for CTASSERT.
defined __HAVE_CPU_MAXPROC to use function cpu_maxproc().

pointed out by mrg@, thanks.


# 1.88 06-Sep-2020 ryo

Fix panic caused by modload. http://mail-index.netbsd.org/port-arm/2020/08/30/msg006960.html

The address space reserved for modules may not be mapped in L1-L3.


# 1.87 14-Aug-2020 skrll

Whitespace


# 1.86 12-Aug-2020 skrll

Part IV of ad's performance improvements for aarch64

- Implement pmap_growkernel(), and update kernel pmap's stats with atomics.

- Then, pmap_kenter_pa() and pmap_kremove() no longer need to allocate
memory nor take pm_lock, because they only modify L3 PTEs.

- Then, pm_lock and pp_lock can be adaptive mutexes at IPL_NONE which are
cheaper than spin mutexes.

- Take the pmap's lock in pmap_extract() if not the kernel's pmap, otherwise
pmap_extract() might see inconsistent state.


# 1.85 09-Aug-2020 skrll

Fix another UVMHIST so it doesn't use %s


# 1.84 16-Jul-2020 skrll

pmapboot_enter simplication
- bootpage_alloc in asm becomes pmapboot_pagealloc in C
- PMAPBOOT_ENTER_NOBLOCK is removed as it's not used
- PMAPBOOT_ENTER_NOOVERWRITE is removed as it's now always on
- physpage_allocator argument is removed as it's always
pmapboot_pagealloc
- Support for EARLYCONS without CONSADDR is removed so that the identity
map for CONSADDR is always known.

For the assembly files:
2 files changed, 40 insertions(+), 89 deletions(-)

LGTM ryo


# 1.83 04-Jul-2020 rin

Use tlen for temporary length variable instead of l, which is usually
used for struct lwp *.

No binary changes.


# 1.82 02-Jul-2020 rin

pmap_procwr(): sync icache even if p != curproc. This fixes applications
like GDB for arm32, that rewrite text of other process.

Thanks to ryo@ for discussion.


# 1.81 02-Jul-2020 rin

Set uvmexp.ncolors appropriately, which is required for some CPU
models with VIPT icache.

Otherwise, alias in virtual address results in inconsistent results,
at least for applications that rewrite text of other process, e.g.,
GDB for arm32.

Also, this hopefully fixes other unexpected failures due to alias.

Confirmed that there's no observable regression in performance;
difference in ``time make -j8'' for GENERIC64 kernel on BCM2837
with and without setting uvmexp.ncolors is within 0.1%.

Thanks to ryo@ for discussion.


# 1.80 27-Jun-2020 rin

Fix typo in name of evcnt(4) counter.


# 1.79 24-Jun-2020 ryo

Fix bug with incorrect range calculation when doing icache sync.
This is called by sysarch(ARM_SYNC_ICACHE) from aarch32 (compat_netbsd32) emul process.

pointed out by rin@, thanks.

XXX pullup-9


# 1.78 14-Jun-2020 ad

- Fix a lock order reversal in pmap_page_protect().

- Make sure pmap is always locked when updating stats; atomics no longer
needed to do that.

- Remove unneeded traversal of pv list in pmap_enter_pv().

- Shrink struct vm_page from 136 to 128 bytes (cache line sized) and struct
pv_entry from 48 to 32 bytes (power of 2 sized).

- Embed a pv_entry in each vm_page. This means PV entries don't need to
be allocated for private anonymous memory / COW pages / most UBC mappings.
Dynamic PV entries are then used only for stuff like shared libraries and
shared memory.

Proposed on port-arm@.


# 1.77 10-Jun-2020 ad

- Wired/resident stats shouldn't covered by PMAPCOUNTERS.
- Rename need_update_pv -> need_enter_pv.

Ok ryo@


# 1.76 01-Jun-2020 ryo

no need to make the PTE writable to do icache_sync, enough to accessible.


# 1.75 15-May-2020 skrll

Use __diagused


# 1.74 15-May-2020 tnn

fix non-diag build


# 1.73 14-May-2020 skrll

Use MUTEX_NODEBUG for PV locks as is commonly done. OK ryo.


# 1.72 13-May-2020 jmcneill

Implement pmap_extract_coherency


Revision tags: bouyer-xenpvh-base2 phil-wifi-20200421 bouyer-xenpvh-base1
# 1.71 18-Apr-2020 skrll

PMAP_DEBUG has been deleted on arm


# 1.70 13-Apr-2020 maxv

Add support for Branch Target Identification (BTI).

On the executable pages that have the GP (Guarded Page) bit, the semantic
of the "br" and "blr" instructions is changed: the CPU expects the first
instruction of the jump/call target to be "bti", and faults if it isn't.

We add the GP bit on the kernel .text pages (and incidentally the .rodata
pages, but we don't care). The compiler adds a "bti c" instruction at the
beginning of each C function. We modify the ENTRY() macros to manually add
"bti c" in the asm functions.

cpuswitch.S needs a specific change: with "br x27" the CPU expects "bti j",
which is bad because the functions begin with "bti c"; switch to "br x16",
for the CPU to accept "bti c".

BTI helps defend against JOP/COP. Tested on Qemu.


Revision tags: phil-wifi-20200411 bouyer-xenpvh-base
# 1.69 08-Apr-2020 ryo

branches: 1.69.2;
use PMAP_PAGE_INIT() to initialize mutex in pmap_page.

VM_MDPAGE_INIT() in pmap_free_pdp() had initialized pp_flags,
so it unintentionally cleared PMAP_PAGE_FLAGS_PV_TRACKED.
use PMAP_PAGE_INIT to avoid using PMAP_PAGE_FLAGS_PV_TRACKED.

pointed out by tnn@, thanks


Revision tags: phil-wifi-20200406
# 1.68 14-Mar-2020 ad

pmap_remove_all(): Return a boolean value to indicate the behaviour. If
true, all mappings have been removed, the pmap is totally cleared out, and
UVM can then avoid doing the work to call pmap_remove() for each map entry.
If false, either nothing has been done, or some helpful arch-specific voodoo
has taken place.


Revision tags: is-mlppp-base
# 1.67 02-Mar-2020 ryo

oops, fix incorrect usage of daif_enable() in my previous commit.


# 1.66 29-Feb-2020 ryo

Fix pmap to work correctly with tagged addresses

- when fault, untag from address before passing to uvm/pmap functions
- pmap_extract() checks more strictly and consider the address tag


# 1.65 29-Feb-2020 ryo

use pmapboot_enter_range()


Revision tags: ad-namecache-base3
# 1.64 10-Feb-2020 ryo

use LIST(3) instead of TAILQ(3) to save one word in struct vm_page and struct pmap.

pointed out by riastradh@. thanks


# 1.63 03-Feb-2020 ryo

add support pmap_pv(9)

Patch originally from jmcneill@. thanks


# 1.62 03-Feb-2020 ryo

separate struct vm_page_md into vm_page_md and pmap_page
for preparation pmap_pv(9)


Revision tags: ad-namecache-base2 ad-namecache-base1
# 1.61 09-Jan-2020 ryo

fix behaviour mmap()/mprotect() when passed only PROT_EXEC.

when mmap()/mprotect() with only PROT_EXEC, syscall will be successful,
but the page actually hadn't been mapped.
it should be mapped with PROT_READ|PROT_EXEC implicitly. (r-x)


Revision tags: ad-namecache-base
# 1.60 30-Dec-2019 skrll

branches: 1.60.2;
Update pmap_map_chunk to allow L[12] block mappings and L3 page mappings


# 1.59 30-Dec-2019 skrll

Remove unnecessary brackets and unwrap a conditional. Same code before
and after.


# 1.58 28-Dec-2019 jmcneill

Do not use Early Write Acknowledge for PCIe I/O and config space.


# 1.57 27-Dec-2019 jmcneill

Enable early write acknowledge for device memory mappings.


# 1.56 19-Dec-2019 skrll

G/C kasan_shadow_map call in pmap_enter

pmap_growkernel calls kasan_shadow_map for KVA


# 1.55 18-Dec-2019 ryo

atomic_add_16() is not used in pmap.c anymore. no need decl here.


# 1.54 18-Dec-2019 ryo

space to tab


# 1.53 14-Dec-2019 skrll

Fix build... wire_count probably doesn't need atomics


# 1.52 13-Dec-2019 skrll

Fix KASAN support by calling kasan_shadow_map in pmap_growkernel


# 1.51 10-Dec-2019 ad

pg->phys_addr -> VM_PAGE_TO_PHYS(pg)


Revision tags: phil-wifi-20191119
# 1.50 14-Nov-2019 maxv

Mark several kASan functions with __nothing, to avoid annoying #ifdefs.
Same as kCSan and kMSan.


# 1.49 14-Nov-2019 maxv

Don't include "opt_kasan.h" when there's already <sys/asan.h> included.


# 1.48 29-Oct-2019 maya

Define PMAP_NEED_PROCWR, providing strategically placed i-cache
synchronization where just-changed memory is about to be executed.

Fixes SIGILLs seen when running Mono 6 on QEMU Cortex-A57.

ok ryo


# 1.47 22-Sep-2019 jmcneill

Disable translation table walks using TTBR0 while changing its value and
when deactivating a pmap. Fixes stability issues on Ampere eMAG CPUs.


# 1.46 20-Sep-2019 ryo

ref/mod bit should be set according to 'flags' argument, not 'prot'. r1.44 was incomplete.


# 1.45 13-Sep-2019 ryo

In pmap_devmap_bootstrap(), cpu_earlydevice_va_p() must not return true until *all* devmap tables have been enabled.
console mapping may be present in the last table.


# 1.44 07-Sep-2019 ryo

- remove incorrect KASSERT. mmap(2) with prot=PROT_WRITE calls pmap_enter(..., PROT_WRITE) internally.
- fix to update page reference flags when only PROT_WRITE or PROT_EXECUTE specified


# 1.43 15-Aug-2019 skrll

Make pmap_db_pte_print more terse so it's quicker on serial consoles


# 1.42 12-Aug-2019 skrll

Use PMAP_DEV in DEVMAP_ENTRY rather than pmap_map_chunk. It's clearer and
means pmap_map_chunk can be made to map other memory types.


Revision tags: netbsd-9-base phil-wifi-20190609
# 1.41 17-May-2019 mrg

branches: 1.41.2;
apply some __diagused.


Revision tags: isaki-audio2-base
# 1.40 08-Apr-2019 ryo

- free empty page tables pages if reach a certain usage.
- need to lock at removing an old pg (_pmap_remove_pv) in _pmap_enter()


# 1.39 06-Apr-2019 ryo

Fix race conditions about pmap_page_protect() and pmap_enter().

while handling same PTE by these functions in same time, there
is a critical path that the number of valid PTEs and wire_count
are inconsistent, and it caused KASSERT.
Need to hold a pv_lock while modifying them.


# 1.38 20-Mar-2019 ryo

spinkle __printflike(), and use PRIxxx


# 1.37 19-Mar-2019 ryo

- add ddb command "machine ttbr" to dump MMU tables.
- tidy up descriptions, usages and messages.


# 1.36 19-Mar-2019 ryo

- free L1-L3 pages that has been emptied by pmap_remove().
- if no memories, pmap_enter will return correctly ENOMEM if PMAP_CANFAIL, or wait until available any memories if !PMAP_CANFAIL.

These changes improves the stability when we use a huge virtual memory spaces with mmap.


# 1.35 06-Feb-2019 ryo

improve pmap_remove
- don't lock/unlock per page in pmap_remove()
- speedup pte lookup for continuous addresses
- bring out pool_cache_put(&_pmap_pv_pool, pv) from lock/unlock section


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226
# 1.34 21-Dec-2018 ryo

- add workaround for Cavium ThunderX errata 27456.
- add cpufuncs table in cpu_info. each cpu clusters may have different erratum. (e.g. big.LITTLE)


Revision tags: pgoyette-compat-1126
# 1.33 01-Nov-2018 maxv

Add kASan support for aarch64. Stack tracking needs more investigation
and will come in a separate commit.

Reviewed by ryo@ jmcneill@ skrll@.


# 1.32 31-Oct-2018 ryo

invalidate icache correctly.
l3pte_executable() should be used for only valid pte.


Revision tags: pgoyette-compat-1020
# 1.31 18-Oct-2018 skrll

Provide generic start code that assumes the MMU is off and caches are
disabled as per the linux booting protocol for ARMv6 and ARMv7 boards.
u-boot image type should be changed to 'linux' for correct behaviour.

The new start code builds a minimal "bootstrap" L1PT with cached access
disabled and uses the same table for all processors. AP startup is
performed in less steps and more code is written in C.

The bootstrap tables and stack are placed into an (orphaned) section
"_init_memory" which is given to uvm when it is no longer used.

Various kernels have been converted to use this code and tested. Some
boards were provided by TNF. Thanks!

The GENERIC kernel now boots on boards using the TEGRA, SUNXI and EXYNOS
kernels. The GENERIC kernel will also work on RPI2 using u-boot.

Thanks to martin@ and aymeric@ for testing on parallella and nanosoc
respectively


# 1.30 14-Oct-2018 skrll

Use __nothing


# 1.29 12-Oct-2018 ryo

add initial support of COMPAT_NETBSD32 on AArch64.
arm ELF32 EABI binaries could be execute in AArch32 state on AArch64. A32 THUMB mode is not supported yet.


# 1.28 12-Oct-2018 ryo

- cleanup checking address ranges with IN_RANGE macro
- change PM_ADDR_CHECK macro to KASSERTMSG
- restore fast lookup cases with IN_RANGE macro for pmap_extract changed in my previous commit.


# 1.27 12-Oct-2018 ryo

rewrite pmap_pte_lookup() to share similar code.


# 1.26 04-Oct-2018 ryo

cleanup locore, and changed the way to map memories during boot.
- add functions bootpage_enter() and bootpage_alloc() to adapt various layout
of physical memory map. especially for 64bit physical memory layout.
pmapboot_alloc() allocates pagetable pages from _end[].
- changed to map only the required amount for PA=VA identity mapping
(kernel image, UART device, and FDT blob) with L2_BLOCK(2Mbyte).
- changing page permission for kernel image, and making KSEG mapping are done
at cpu_kernel_vm_init() instead of at locore.
- optimize PTE entries with PTE Contiguous bit. it is enabled on devmap only for now.

reviewed by skrll@, thanks.


# 1.25 04-Oct-2018 ryo

* define LX_BLKPAG_{OS,ATTR}_* for OS dependent PTE attributes in pmap.h
* cleanup macros


Revision tags: pgoyette-compat-0930
# 1.24 17-Sep-2018 ryo

delete debug printf and KASSERT.


# 1.23 10-Sep-2018 maxv

Replace KDASSERT by panic.


# 1.22 10-Sep-2018 maxv

Rename _pmap_alloc_pdp -> pmap_alloc_pdp, and make it public.


# 1.21 10-Sep-2018 ryo

cleanup aarch64 mpstart and fdt bootstrap
* arm_cpu_hatch_arg is a bad idea. avoid serializing CPU startup, and eliminate arm_cpu_hatch_arg.
in mpstart, resolve own cpu index using array of cpu_mpidr[] (aarch64)
* add support fdt enable-method "spin-table"
* add support fdt enable-method "brcm,bcm2836-smp" (for 32bit RaspberryPi)
* use arm_fdt_cpu_bootstrap() instead of psci_fdt_bootstrap()
* rename "arm/fdt/psci_fdt.h" to "arm/fdt/psci_fdtvar.h" because of conflict of include file for needs-flag
* add devmap for cpu spin-table of raspberrypi3/aarch64
* no need to force hatch APs for raspberrypi3/arm32 ifndef MULTIPROCESSOR.
* fix to work pmap_extract(kerneltext/data/bss) even if before calling pmap_bootstrap

idea to use cpu_mpidr[] by jmcneill@. reviewd by skrll@. thanks.


Revision tags: pgoyette-compat-0906
# 1.20 27-Aug-2018 ryo

need to add VM_PROT_READ when pmap_kenter_pa(va, pa, VM_PROT_WRITE, 0) or pmap_kenter_pa(va, pa, VM_PROT_EXECUTE, 0).
VM_PROT_READ is treated as an access permission inernally.


# 1.19 11-Aug-2018 ryo

change to minimum invalidation of TLB.
specifying not only va but also asid, and not invalidate L0-L2 entry using tlbi_*_ll() if needed.


# 1.18 10-Aug-2018 ryo

treat kernel-exec attr and user-exec attr separately.
kernel cannot execute userland exec page, and user cannot execute kernel page.


# 1.17 06-Aug-2018 ryo

set kernel text/rodata readonly by default.
add function db_write_text() for setting ddb breakpoint.


# 1.16 31-Jul-2018 skrll

Define and use VPRINTF


Revision tags: pgoyette-compat-0728
# 1.15 27-Jul-2018 ryo

changes of pmap.c r1.13 seems to be unstable.
In order to invalidate icache, not to invalidate all icache,
but temporary to make the page writable and invalidate target address only.


# 1.14 24-Jul-2018 ryo

don't call pool_cache_put with locking pmap. pool_cache_put call pmap_kenter_pa internally.
(pool_cache_put_paddr -> pool_cache_put_slow -> pool_get -> pmap_kenter_pa)


# 1.13 23-Jul-2018 ryo

* fix icache invalidations.
* "ic ivau" (aarch64_icache_sync_range) with VA generates permission fault in some situations, therefore use KSEG address for now.


# 1.12 23-Jul-2018 ryo

rather than using flags to resolve nested locks, reserve pool_cache before locking.


# 1.11 21-Jul-2018 ryo

* avoid deadlock. mutex_owned() works only for adaptive lock, therefore we cannot use it for spinlock...
* add more NULL check
* clear pte when pmap_enter() fails


# 1.10 17-Jul-2018 ryo

Use __debugused


# 1.9 17-Jul-2018 christos

Add missing casts, remove unused variables.


# 1.8 09-Jul-2018 ryo

need locks in pmap_kremove() and pmap_fault_fixup()


Revision tags: phil-wifi-base pgoyette-compat-0625 pgoyette-compat-0521
# 1.7 20-May-2018 ryo

branches: 1.7.2;
pmap_enter() must update modified/referenced flags by 'flags' not 'prot'.


# 1.6 16-May-2018 ryo

Fix memory leak. it was leaking one page every pmap_create().
pm->pm_vmlist must be initialized before calling _pmap_alloc_pdp().


Revision tags: pgoyette-compat-0502
# 1.5 29-Apr-2018 ryo

fix KASSERT panic. pv_entry may not be exists in pvlist when pmap_remove().


# 1.4 29-Apr-2018 ryo

delete unused code


# 1.3 27-Apr-2018 ryo

fix instability behavior of bufcache on aarch64.
* fix to return correct ref/mod when PMAP_WIRED.
* changed to keep wired flags in pte instead of pv_entry, and cleanup.


Revision tags: pgoyette-compat-0422 pgoyette-compat-0415 pgoyette-compat-0407
# 1.2 01-Apr-2018 ryo

Add initial support for ARMv8 (AARCH64) (by nisimura@ and ryo@)

- sys/arch/evbarm64 is gone and integrated into sys/arch/evbarm. (by skrll@)
- add support fdt. evbarm/conf/GENERIC64 fdt (bcm2837,sunxi,tegra) based generic 64bit kernel config. (by skrll@, jmcneill@)


Revision tags: netbsd-8-2-RELEASE netbsd-8-1-RELEASE netbsd-8-1-RC1 netbsd-7-2-RELEASE netbsd-8-0-RELEASE netbsd-8-0-RC2 netbsd-8-0-RC1 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 netbsd-7-1-2-RELEASE pgoyette-compat-base netbsd-7-1-1-RELEASE tls-maxphys-base-20171202 matt-nb8-mediatek-base nick-nhusb-base-20170825 perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base pgoyette-localcount-20170320 netbsd-7-1-RELEASE netbsd-7-1-RC2 nick-nhusb-base-20170204 netbsd-7-nhusb-base-20170116 bouyer-socketcan-base pgoyette-localcount-20170107 netbsd-7-1-RC1 nick-nhusb-base-20161204 pgoyette-localcount-20161104 netbsd-7-0-2-RELEASE nick-nhusb-base-20161004 localcount-20160914 netbsd-7-nhusb-base pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907 nick-nhusb-base-20160529 netbsd-7-0-1-RELEASE nick-nhusb-base-20160422 nick-nhusb-base-20160319 nick-nhusb-base-20151226 netbsd-7-0-RELEASE nick-nhusb-base-20150921 netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 nick-nhusb-base-20150606 nick-nhusb-base-20150406 nick-nhusb-base tls-maxphys-base netbsd-7-base
# 1.1 10-Aug-2014 matt

branches: 1.1.4; 1.1.28;
Preliminary files for AARCH64 (64-bit ARM) support.
Enough for a distribution build.


# 1.98 19-Dec-2020 skrll

Tweak a comment


Revision tags: thorpej-futex-base
# 1.97 11-Dec-2020 skrll

s:aarch64/cpufunc.h:arm/cpufunc.h:

a baby step in the grand arm header unification challenge


# 1.96 10-Nov-2020 skrll

AA64 is not MIPS.

Change all KSEG references to directmap


# 1.95 07-Nov-2020 skrll

In pmap_devmap_bootstrap only set pmap_devmap_bootstrap_done if there
is an entry and ALL of the entries have been done. The entry required
for EARLYCONS might not be the first/only one...


# 1.94 01-Nov-2020 jmcneill

branches: 1.94.2;
No need to disable translation table walks in pmap_activate().


# 1.93 22-Oct-2020 skrll

Use the isb macro - missed in previous commit


# 1.92 22-Oct-2020 skrll

Use the dmb/dsb/isb macros... if nothing else they're all now consistent
about the "memory" assembler contraint.

No binary change


# 1.91 28-Sep-2020 skrll

Only set pmap_devmap_bootstrap_done if something gets mapped.

Think acpi_platform_devmap


# 1.90 19-Sep-2020 skrll

Make __md_palloc pmap agnostic (think sys/uvm/pmap)


# 1.89 14-Sep-2020 ryo

PID_MAX is just an initial value (soft maximum). Don't use it for CTASSERT.
defined __HAVE_CPU_MAXPROC to use function cpu_maxproc().

pointed out by mrg@, thanks.


# 1.88 06-Sep-2020 ryo

Fix panic caused by modload. http://mail-index.netbsd.org/port-arm/2020/08/30/msg006960.html

The address space reserved for modules may not be mapped in L1-L3.


# 1.87 14-Aug-2020 skrll

Whitespace


# 1.86 12-Aug-2020 skrll

Part IV of ad's performance improvements for aarch64

- Implement pmap_growkernel(), and update kernel pmap's stats with atomics.

- Then, pmap_kenter_pa() and pmap_kremove() no longer need to allocate
memory nor take pm_lock, because they only modify L3 PTEs.

- Then, pm_lock and pp_lock can be adaptive mutexes at IPL_NONE which are
cheaper than spin mutexes.

- Take the pmap's lock in pmap_extract() if not the kernel's pmap, otherwise
pmap_extract() might see inconsistent state.


# 1.85 09-Aug-2020 skrll

Fix another UVMHIST so it doesn't use %s


# 1.84 16-Jul-2020 skrll

pmapboot_enter simplication
- bootpage_alloc in asm becomes pmapboot_pagealloc in C
- PMAPBOOT_ENTER_NOBLOCK is removed as it's not used
- PMAPBOOT_ENTER_NOOVERWRITE is removed as it's now always on
- physpage_allocator argument is removed as it's always
pmapboot_pagealloc
- Support for EARLYCONS without CONSADDR is removed so that the identity
map for CONSADDR is always known.

For the assembly files:
2 files changed, 40 insertions(+), 89 deletions(-)

LGTM ryo


# 1.83 04-Jul-2020 rin

Use tlen for temporary length variable instead of l, which is usually
used for struct lwp *.

No binary changes.


# 1.82 02-Jul-2020 rin

pmap_procwr(): sync icache even if p != curproc. This fixes applications
like GDB for arm32, that rewrite text of other process.

Thanks to ryo@ for discussion.


# 1.81 02-Jul-2020 rin

Set uvmexp.ncolors appropriately, which is required for some CPU
models with VIPT icache.

Otherwise, alias in virtual address results in inconsistent results,
at least for applications that rewrite text of other process, e.g.,
GDB for arm32.

Also, this hopefully fixes other unexpected failures due to alias.

Confirmed that there's no observable regression in performance;
difference in ``time make -j8'' for GENERIC64 kernel on BCM2837
with and without setting uvmexp.ncolors is within 0.1%.

Thanks to ryo@ for discussion.


# 1.80 27-Jun-2020 rin

Fix typo in name of evcnt(4) counter.


# 1.79 24-Jun-2020 ryo

Fix bug with incorrect range calculation when doing icache sync.
This is called by sysarch(ARM_SYNC_ICACHE) from aarch32 (compat_netbsd32) emul process.

pointed out by rin@, thanks.

XXX pullup-9


# 1.78 14-Jun-2020 ad

- Fix a lock order reversal in pmap_page_protect().

- Make sure pmap is always locked when updating stats; atomics no longer
needed to do that.

- Remove unneeded traversal of pv list in pmap_enter_pv().

- Shrink struct vm_page from 136 to 128 bytes (cache line sized) and struct
pv_entry from 48 to 32 bytes (power of 2 sized).

- Embed a pv_entry in each vm_page. This means PV entries don't need to
be allocated for private anonymous memory / COW pages / most UBC mappings.
Dynamic PV entries are then used only for stuff like shared libraries and
shared memory.

Proposed on port-arm@.


# 1.77 10-Jun-2020 ad

- Wired/resident stats shouldn't covered by PMAPCOUNTERS.
- Rename need_update_pv -> need_enter_pv.

Ok ryo@


# 1.76 01-Jun-2020 ryo

no need to make the PTE writable to do icache_sync, enough to accessible.


# 1.75 15-May-2020 skrll

Use __diagused


# 1.74 15-May-2020 tnn

fix non-diag build


# 1.73 14-May-2020 skrll

Use MUTEX_NODEBUG for PV locks as is commonly done. OK ryo.


# 1.72 13-May-2020 jmcneill

Implement pmap_extract_coherency


Revision tags: bouyer-xenpvh-base2 phil-wifi-20200421 bouyer-xenpvh-base1
# 1.71 18-Apr-2020 skrll

PMAP_DEBUG has been deleted on arm


# 1.70 13-Apr-2020 maxv

Add support for Branch Target Identification (BTI).

On the executable pages that have the GP (Guarded Page) bit, the semantic
of the "br" and "blr" instructions is changed: the CPU expects the first
instruction of the jump/call target to be "bti", and faults if it isn't.

We add the GP bit on the kernel .text pages (and incidentally the .rodata
pages, but we don't care). The compiler adds a "bti c" instruction at the
beginning of each C function. We modify the ENTRY() macros to manually add
"bti c" in the asm functions.

cpuswitch.S needs a specific change: with "br x27" the CPU expects "bti j",
which is bad because the functions begin with "bti c"; switch to "br x16",
for the CPU to accept "bti c".

BTI helps defend against JOP/COP. Tested on Qemu.


Revision tags: phil-wifi-20200411 bouyer-xenpvh-base
# 1.69 08-Apr-2020 ryo

branches: 1.69.2;
use PMAP_PAGE_INIT() to initialize mutex in pmap_page.

VM_MDPAGE_INIT() in pmap_free_pdp() had initialized pp_flags,
so it unintentionally cleared PMAP_PAGE_FLAGS_PV_TRACKED.
use PMAP_PAGE_INIT to avoid using PMAP_PAGE_FLAGS_PV_TRACKED.

pointed out by tnn@, thanks


Revision tags: phil-wifi-20200406
# 1.68 14-Mar-2020 ad

pmap_remove_all(): Return a boolean value to indicate the behaviour. If
true, all mappings have been removed, the pmap is totally cleared out, and
UVM can then avoid doing the work to call pmap_remove() for each map entry.
If false, either nothing has been done, or some helpful arch-specific voodoo
has taken place.


Revision tags: is-mlppp-base
# 1.67 02-Mar-2020 ryo

oops, fix incorrect usage of daif_enable() in my previous commit.


# 1.66 29-Feb-2020 ryo

Fix pmap to work correctly with tagged addresses

- when fault, untag from address before passing to uvm/pmap functions
- pmap_extract() checks more strictly and consider the address tag


# 1.65 29-Feb-2020 ryo

use pmapboot_enter_range()


Revision tags: ad-namecache-base3
# 1.64 10-Feb-2020 ryo

use LIST(3) instead of TAILQ(3) to save one word in struct vm_page and struct pmap.

pointed out by riastradh@. thanks


# 1.63 03-Feb-2020 ryo

add support pmap_pv(9)

Patch originally from jmcneill@. thanks


# 1.62 03-Feb-2020 ryo

separate struct vm_page_md into vm_page_md and pmap_page
for preparation pmap_pv(9)


Revision tags: ad-namecache-base2 ad-namecache-base1
# 1.61 09-Jan-2020 ryo

fix behaviour mmap()/mprotect() when passed only PROT_EXEC.

when mmap()/mprotect() with only PROT_EXEC, syscall will be successful,
but the page actually hadn't been mapped.
it should be mapped with PROT_READ|PROT_EXEC implicitly. (r-x)


Revision tags: ad-namecache-base
# 1.60 30-Dec-2019 skrll

branches: 1.60.2;
Update pmap_map_chunk to allow L[12] block mappings and L3 page mappings


# 1.59 30-Dec-2019 skrll

Remove unnecessary brackets and unwrap a conditional. Same code before
and after.


# 1.58 28-Dec-2019 jmcneill

Do not use Early Write Acknowledge for PCIe I/O and config space.


# 1.57 27-Dec-2019 jmcneill

Enable early write acknowledge for device memory mappings.


# 1.56 19-Dec-2019 skrll

G/C kasan_shadow_map call in pmap_enter

pmap_growkernel calls kasan_shadow_map for KVA


# 1.55 18-Dec-2019 ryo

atomic_add_16() is not used in pmap.c anymore. no need decl here.


# 1.54 18-Dec-2019 ryo

space to tab


# 1.53 14-Dec-2019 skrll

Fix build... wire_count probably doesn't need atomics


# 1.52 13-Dec-2019 skrll

Fix KASAN support by calling kasan_shadow_map in pmap_growkernel


# 1.51 10-Dec-2019 ad

pg->phys_addr -> VM_PAGE_TO_PHYS(pg)


Revision tags: phil-wifi-20191119
# 1.50 14-Nov-2019 maxv

Mark several kASan functions with __nothing, to avoid annoying #ifdefs.
Same as kCSan and kMSan.


# 1.49 14-Nov-2019 maxv

Don't include "opt_kasan.h" when there's already <sys/asan.h> included.


# 1.48 29-Oct-2019 maya

Define PMAP_NEED_PROCWR, providing strategically placed i-cache
synchronization where just-changed memory is about to be executed.

Fixes SIGILLs seen when running Mono 6 on QEMU Cortex-A57.

ok ryo


# 1.47 22-Sep-2019 jmcneill

Disable translation table walks using TTBR0 while changing its value and
when deactivating a pmap. Fixes stability issues on Ampere eMAG CPUs.


# 1.46 20-Sep-2019 ryo

ref/mod bit should be set according to 'flags' argument, not 'prot'. r1.44 was incomplete.


# 1.45 13-Sep-2019 ryo

In pmap_devmap_bootstrap(), cpu_earlydevice_va_p() must not return true until *all* devmap tables have been enabled.
console mapping may be present in the last table.


# 1.44 07-Sep-2019 ryo

- remove incorrect KASSERT. mmap(2) with prot=PROT_WRITE calls pmap_enter(..., PROT_WRITE) internally.
- fix to update page reference flags when only PROT_WRITE or PROT_EXECUTE specified


# 1.43 15-Aug-2019 skrll

Make pmap_db_pte_print more terse so it's quicker on serial consoles


# 1.42 12-Aug-2019 skrll

Use PMAP_DEV in DEVMAP_ENTRY rather than pmap_map_chunk. It's clearer and
means pmap_map_chunk can be made to map other memory types.


Revision tags: netbsd-9-base phil-wifi-20190609
# 1.41 17-May-2019 mrg

branches: 1.41.2;
apply some __diagused.


Revision tags: isaki-audio2-base
# 1.40 08-Apr-2019 ryo

- free empty page tables pages if reach a certain usage.
- need to lock at removing an old pg (_pmap_remove_pv) in _pmap_enter()


# 1.39 06-Apr-2019 ryo

Fix race conditions about pmap_page_protect() and pmap_enter().

while handling same PTE by these functions in same time, there
is a critical path that the number of valid PTEs and wire_count
are inconsistent, and it caused KASSERT.
Need to hold a pv_lock while modifying them.


# 1.38 20-Mar-2019 ryo

spinkle __printflike(), and use PRIxxx


# 1.37 19-Mar-2019 ryo

- add ddb command "machine ttbr" to dump MMU tables.
- tidy up descriptions, usages and messages.


# 1.36 19-Mar-2019 ryo

- free L1-L3 pages that has been emptied by pmap_remove().
- if no memories, pmap_enter will return correctly ENOMEM if PMAP_CANFAIL, or wait until available any memories if !PMAP_CANFAIL.

These changes improves the stability when we use a huge virtual memory spaces with mmap.


# 1.35 06-Feb-2019 ryo

improve pmap_remove
- don't lock/unlock per page in pmap_remove()
- speedup pte lookup for continuous addresses
- bring out pool_cache_put(&_pmap_pv_pool, pv) from lock/unlock section


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226
# 1.34 21-Dec-2018 ryo

- add workaround for Cavium ThunderX errata 27456.
- add cpufuncs table in cpu_info. each cpu clusters may have different erratum. (e.g. big.LITTLE)


Revision tags: pgoyette-compat-1126
# 1.33 01-Nov-2018 maxv

Add kASan support for aarch64. Stack tracking needs more investigation
and will come in a separate commit.

Reviewed by ryo@ jmcneill@ skrll@.


# 1.32 31-Oct-2018 ryo

invalidate icache correctly.
l3pte_executable() should be used for only valid pte.


Revision tags: pgoyette-compat-1020
# 1.31 18-Oct-2018 skrll

Provide generic start code that assumes the MMU is off and caches are
disabled as per the linux booting protocol for ARMv6 and ARMv7 boards.
u-boot image type should be changed to 'linux' for correct behaviour.

The new start code builds a minimal "bootstrap" L1PT with cached access
disabled and uses the same table for all processors. AP startup is
performed in less steps and more code is written in C.

The bootstrap tables and stack are placed into an (orphaned) section
"_init_memory" which is given to uvm when it is no longer used.

Various kernels have been converted to use this code and tested. Some
boards were provided by TNF. Thanks!

The GENERIC kernel now boots on boards using the TEGRA, SUNXI and EXYNOS
kernels. The GENERIC kernel will also work on RPI2 using u-boot.

Thanks to martin@ and aymeric@ for testing on parallella and nanosoc
respectively


# 1.30 14-Oct-2018 skrll

Use __nothing


# 1.29 12-Oct-2018 ryo

add initial support of COMPAT_NETBSD32 on AArch64.
arm ELF32 EABI binaries could be execute in AArch32 state on AArch64. A32 THUMB mode is not supported yet.


# 1.28 12-Oct-2018 ryo

- cleanup checking address ranges with IN_RANGE macro
- change PM_ADDR_CHECK macro to KASSERTMSG
- restore fast lookup cases with IN_RANGE macro for pmap_extract changed in my previous commit.


# 1.27 12-Oct-2018 ryo

rewrite pmap_pte_lookup() to share similar code.


# 1.26 04-Oct-2018 ryo

cleanup locore, and changed the way to map memories during boot.
- add functions bootpage_enter() and bootpage_alloc() to adapt various layout
of physical memory map. especially for 64bit physical memory layout.
pmapboot_alloc() allocates pagetable pages from _end[].
- changed to map only the required amount for PA=VA identity mapping
(kernel image, UART device, and FDT blob) with L2_BLOCK(2Mbyte).
- changing page permission for kernel image, and making KSEG mapping are done
at cpu_kernel_vm_init() instead of at locore.
- optimize PTE entries with PTE Contiguous bit. it is enabled on devmap only for now.

reviewed by skrll@, thanks.


# 1.25 04-Oct-2018 ryo

* define LX_BLKPAG_{OS,ATTR}_* for OS dependent PTE attributes in pmap.h
* cleanup macros


Revision tags: pgoyette-compat-0930
# 1.24 17-Sep-2018 ryo

delete debug printf and KASSERT.


# 1.23 10-Sep-2018 maxv

Replace KDASSERT by panic.


# 1.22 10-Sep-2018 maxv

Rename _pmap_alloc_pdp -> pmap_alloc_pdp, and make it public.


# 1.21 10-Sep-2018 ryo

cleanup aarch64 mpstart and fdt bootstrap
* arm_cpu_hatch_arg is a bad idea. avoid serializing CPU startup, and eliminate arm_cpu_hatch_arg.
in mpstart, resolve own cpu index using array of cpu_mpidr[] (aarch64)
* add support fdt enable-method "spin-table"
* add support fdt enable-method "brcm,bcm2836-smp" (for 32bit RaspberryPi)
* use arm_fdt_cpu_bootstrap() instead of psci_fdt_bootstrap()
* rename "arm/fdt/psci_fdt.h" to "arm/fdt/psci_fdtvar.h" because of conflict of include file for needs-flag
* add devmap for cpu spin-table of raspberrypi3/aarch64
* no need to force hatch APs for raspberrypi3/arm32 ifndef MULTIPROCESSOR.
* fix to work pmap_extract(kerneltext/data/bss) even if before calling pmap_bootstrap

idea to use cpu_mpidr[] by jmcneill@. reviewd by skrll@. thanks.


Revision tags: pgoyette-compat-0906
# 1.20 27-Aug-2018 ryo

need to add VM_PROT_READ when pmap_kenter_pa(va, pa, VM_PROT_WRITE, 0) or pmap_kenter_pa(va, pa, VM_PROT_EXECUTE, 0).
VM_PROT_READ is treated as an access permission inernally.


# 1.19 11-Aug-2018 ryo

change to minimum invalidation of TLB.
specifying not only va but also asid, and not invalidate L0-L2 entry using tlbi_*_ll() if needed.


# 1.18 10-Aug-2018 ryo

treat kernel-exec attr and user-exec attr separately.
kernel cannot execute userland exec page, and user cannot execute kernel page.


# 1.17 06-Aug-2018 ryo

set kernel text/rodata readonly by default.
add function db_write_text() for setting ddb breakpoint.


# 1.16 31-Jul-2018 skrll

Define and use VPRINTF


Revision tags: pgoyette-compat-0728
# 1.15 27-Jul-2018 ryo

changes of pmap.c r1.13 seems to be unstable.
In order to invalidate icache, not to invalidate all icache,
but temporary to make the page writable and invalidate target address only.


# 1.14 24-Jul-2018 ryo

don't call pool_cache_put with locking pmap. pool_cache_put call pmap_kenter_pa internally.
(pool_cache_put_paddr -> pool_cache_put_slow -> pool_get -> pmap_kenter_pa)


# 1.13 23-Jul-2018 ryo

* fix icache invalidations.
* "ic ivau" (aarch64_icache_sync_range) with VA generates permission fault in some situations, therefore use KSEG address for now.


# 1.12 23-Jul-2018 ryo

rather than using flags to resolve nested locks, reserve pool_cache before locking.


# 1.11 21-Jul-2018 ryo

* avoid deadlock. mutex_owned() works only for adaptive lock, therefore we cannot use it for spinlock...
* add more NULL check
* clear pte when pmap_enter() fails


# 1.10 17-Jul-2018 ryo

Use __debugused


# 1.9 17-Jul-2018 christos

Add missing casts, remove unused variables.


# 1.8 09-Jul-2018 ryo

need locks in pmap_kremove() and pmap_fault_fixup()


Revision tags: phil-wifi-base pgoyette-compat-0625 pgoyette-compat-0521
# 1.7 20-May-2018 ryo

branches: 1.7.2;
pmap_enter() must update modified/referenced flags by 'flags' not 'prot'.


# 1.6 16-May-2018 ryo

Fix memory leak. it was leaking one page every pmap_create().
pm->pm_vmlist must be initialized before calling _pmap_alloc_pdp().


Revision tags: pgoyette-compat-0502
# 1.5 29-Apr-2018 ryo

fix KASSERT panic. pv_entry may not be exists in pvlist when pmap_remove().


# 1.4 29-Apr-2018 ryo

delete unused code


# 1.3 27-Apr-2018 ryo

fix instability behavior of bufcache on aarch64.
* fix to return correct ref/mod when PMAP_WIRED.
* changed to keep wired flags in pte instead of pv_entry, and cleanup.


Revision tags: pgoyette-compat-0422 pgoyette-compat-0415 pgoyette-compat-0407
# 1.2 01-Apr-2018 ryo

Add initial support for ARMv8 (AARCH64) (by nisimura@ and ryo@)

- sys/arch/evbarm64 is gone and integrated into sys/arch/evbarm. (by skrll@)
- add support fdt. evbarm/conf/GENERIC64 fdt (bcm2837,sunxi,tegra) based generic 64bit kernel config. (by skrll@, jmcneill@)


Revision tags: netbsd-8-2-RELEASE netbsd-8-1-RELEASE netbsd-8-1-RC1 netbsd-7-2-RELEASE netbsd-8-0-RELEASE netbsd-8-0-RC2 netbsd-8-0-RC1 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 netbsd-7-1-2-RELEASE pgoyette-compat-base netbsd-7-1-1-RELEASE tls-maxphys-base-20171202 matt-nb8-mediatek-base nick-nhusb-base-20170825 perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base pgoyette-localcount-20170320 netbsd-7-1-RELEASE netbsd-7-1-RC2 nick-nhusb-base-20170204 netbsd-7-nhusb-base-20170116 bouyer-socketcan-base pgoyette-localcount-20170107 netbsd-7-1-RC1 nick-nhusb-base-20161204 pgoyette-localcount-20161104 netbsd-7-0-2-RELEASE nick-nhusb-base-20161004 localcount-20160914 netbsd-7-nhusb-base pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907 nick-nhusb-base-20160529 netbsd-7-0-1-RELEASE nick-nhusb-base-20160422 nick-nhusb-base-20160319 nick-nhusb-base-20151226 netbsd-7-0-RELEASE nick-nhusb-base-20150921 netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 nick-nhusb-base-20150606 nick-nhusb-base-20150406 nick-nhusb-base tls-maxphys-base netbsd-7-base
# 1.1 10-Aug-2014 matt

branches: 1.1.4; 1.1.28;
Preliminary files for AARCH64 (64-bit ARM) support.
Enough for a distribution build.


# 1.97 11-Dec-2020 skrll

s:aarch64/cpufunc.h:arm/cpufunc.h:

a baby step in the grand arm header unification challenge


# 1.96 10-Nov-2020 skrll

AA64 is not MIPS.

Change all KSEG references to directmap


# 1.95 07-Nov-2020 skrll

In pmap_devmap_bootstrap only set pmap_devmap_bootstrap_done if there
is an entry and ALL of the entries have been done. The entry required
for EARLYCONS might not be the first/only one...


Revision tags: thorpej-futex-base
# 1.94 01-Nov-2020 jmcneill

No need to disable translation table walks in pmap_activate().


# 1.93 22-Oct-2020 skrll

Use the isb macro - missed in previous commit


# 1.92 22-Oct-2020 skrll

Use the dmb/dsb/isb macros... if nothing else they're all now consistent
about the "memory" assembler contraint.

No binary change


# 1.91 28-Sep-2020 skrll

Only set pmap_devmap_bootstrap_done if something gets mapped.

Think acpi_platform_devmap


# 1.90 19-Sep-2020 skrll

Make __md_palloc pmap agnostic (think sys/uvm/pmap)


# 1.89 14-Sep-2020 ryo

PID_MAX is just an initial value (soft maximum). Don't use it for CTASSERT.
defined __HAVE_CPU_MAXPROC to use function cpu_maxproc().

pointed out by mrg@, thanks.


# 1.88 06-Sep-2020 ryo

Fix panic caused by modload. http://mail-index.netbsd.org/port-arm/2020/08/30/msg006960.html

The address space reserved for modules may not be mapped in L1-L3.


# 1.87 14-Aug-2020 skrll

Whitespace


# 1.86 12-Aug-2020 skrll

Part IV of ad's performance improvements for aarch64

- Implement pmap_growkernel(), and update kernel pmap's stats with atomics.

- Then, pmap_kenter_pa() and pmap_kremove() no longer need to allocate
memory nor take pm_lock, because they only modify L3 PTEs.

- Then, pm_lock and pp_lock can be adaptive mutexes at IPL_NONE which are
cheaper than spin mutexes.

- Take the pmap's lock in pmap_extract() if not the kernel's pmap, otherwise
pmap_extract() might see inconsistent state.


# 1.85 09-Aug-2020 skrll

Fix another UVMHIST so it doesn't use %s


# 1.84 16-Jul-2020 skrll

pmapboot_enter simplication
- bootpage_alloc in asm becomes pmapboot_pagealloc in C
- PMAPBOOT_ENTER_NOBLOCK is removed as it's not used
- PMAPBOOT_ENTER_NOOVERWRITE is removed as it's now always on
- physpage_allocator argument is removed as it's always
pmapboot_pagealloc
- Support for EARLYCONS without CONSADDR is removed so that the identity
map for CONSADDR is always known.

For the assembly files:
2 files changed, 40 insertions(+), 89 deletions(-)

LGTM ryo


# 1.83 04-Jul-2020 rin

Use tlen for temporary length variable instead of l, which is usually
used for struct lwp *.

No binary changes.


# 1.82 02-Jul-2020 rin

pmap_procwr(): sync icache even if p != curproc. This fixes applications
like GDB for arm32, that rewrite text of other process.

Thanks to ryo@ for discussion.


# 1.81 02-Jul-2020 rin

Set uvmexp.ncolors appropriately, which is required for some CPU
models with VIPT icache.

Otherwise, alias in virtual address results in inconsistent results,
at least for applications that rewrite text of other process, e.g.,
GDB for arm32.

Also, this hopefully fixes other unexpected failures due to alias.

Confirmed that there's no observable regression in performance;
difference in ``time make -j8'' for GENERIC64 kernel on BCM2837
with and without setting uvmexp.ncolors is within 0.1%.

Thanks to ryo@ for discussion.


# 1.80 27-Jun-2020 rin

Fix typo in name of evcnt(4) counter.


# 1.79 24-Jun-2020 ryo

Fix bug with incorrect range calculation when doing icache sync.
This is called by sysarch(ARM_SYNC_ICACHE) from aarch32 (compat_netbsd32) emul process.

pointed out by rin@, thanks.

XXX pullup-9


# 1.78 14-Jun-2020 ad

- Fix a lock order reversal in pmap_page_protect().

- Make sure pmap is always locked when updating stats; atomics no longer
needed to do that.

- Remove unneeded traversal of pv list in pmap_enter_pv().

- Shrink struct vm_page from 136 to 128 bytes (cache line sized) and struct
pv_entry from 48 to 32 bytes (power of 2 sized).

- Embed a pv_entry in each vm_page. This means PV entries don't need to
be allocated for private anonymous memory / COW pages / most UBC mappings.
Dynamic PV entries are then used only for stuff like shared libraries and
shared memory.

Proposed on port-arm@.


# 1.77 10-Jun-2020 ad

- Wired/resident stats shouldn't covered by PMAPCOUNTERS.
- Rename need_update_pv -> need_enter_pv.

Ok ryo@


# 1.76 01-Jun-2020 ryo

no need to make the PTE writable to do icache_sync, enough to accessible.


# 1.75 15-May-2020 skrll

Use __diagused


# 1.74 15-May-2020 tnn

fix non-diag build


# 1.73 14-May-2020 skrll

Use MUTEX_NODEBUG for PV locks as is commonly done. OK ryo.


# 1.72 13-May-2020 jmcneill

Implement pmap_extract_coherency


Revision tags: bouyer-xenpvh-base2 phil-wifi-20200421 bouyer-xenpvh-base1
# 1.71 18-Apr-2020 skrll

PMAP_DEBUG has been deleted on arm


# 1.70 13-Apr-2020 maxv

Add support for Branch Target Identification (BTI).

On the executable pages that have the GP (Guarded Page) bit, the semantic
of the "br" and "blr" instructions is changed: the CPU expects the first
instruction of the jump/call target to be "bti", and faults if it isn't.

We add the GP bit on the kernel .text pages (and incidentally the .rodata
pages, but we don't care). The compiler adds a "bti c" instruction at the
beginning of each C function. We modify the ENTRY() macros to manually add
"bti c" in the asm functions.

cpuswitch.S needs a specific change: with "br x27" the CPU expects "bti j",
which is bad because the functions begin with "bti c"; switch to "br x16",
for the CPU to accept "bti c".

BTI helps defend against JOP/COP. Tested on Qemu.


Revision tags: phil-wifi-20200411 bouyer-xenpvh-base
# 1.69 08-Apr-2020 ryo

branches: 1.69.2;
use PMAP_PAGE_INIT() to initialize mutex in pmap_page.

VM_MDPAGE_INIT() in pmap_free_pdp() had initialized pp_flags,
so it unintentionally cleared PMAP_PAGE_FLAGS_PV_TRACKED.
use PMAP_PAGE_INIT to avoid using PMAP_PAGE_FLAGS_PV_TRACKED.

pointed out by tnn@, thanks


Revision tags: phil-wifi-20200406
# 1.68 14-Mar-2020 ad

pmap_remove_all(): Return a boolean value to indicate the behaviour. If
true, all mappings have been removed, the pmap is totally cleared out, and
UVM can then avoid doing the work to call pmap_remove() for each map entry.
If false, either nothing has been done, or some helpful arch-specific voodoo
has taken place.


Revision tags: is-mlppp-base
# 1.67 02-Mar-2020 ryo

oops, fix incorrect usage of daif_enable() in my previous commit.


# 1.66 29-Feb-2020 ryo

Fix pmap to work correctly with tagged addresses

- when fault, untag from address before passing to uvm/pmap functions
- pmap_extract() checks more strictly and consider the address tag


# 1.65 29-Feb-2020 ryo

use pmapboot_enter_range()


Revision tags: ad-namecache-base3
# 1.64 10-Feb-2020 ryo

use LIST(3) instead of TAILQ(3) to save one word in struct vm_page and struct pmap.

pointed out by riastradh@. thanks


# 1.63 03-Feb-2020 ryo

add support pmap_pv(9)

Patch originally from jmcneill@. thanks


# 1.62 03-Feb-2020 ryo

separate struct vm_page_md into vm_page_md and pmap_page
for preparation pmap_pv(9)


Revision tags: ad-namecache-base2 ad-namecache-base1
# 1.61 09-Jan-2020 ryo

fix behaviour mmap()/mprotect() when passed only PROT_EXEC.

when mmap()/mprotect() with only PROT_EXEC, syscall will be successful,
but the page actually hadn't been mapped.
it should be mapped with PROT_READ|PROT_EXEC implicitly. (r-x)


Revision tags: ad-namecache-base
# 1.60 30-Dec-2019 skrll

branches: 1.60.2;
Update pmap_map_chunk to allow L[12] block mappings and L3 page mappings


# 1.59 30-Dec-2019 skrll

Remove unnecessary brackets and unwrap a conditional. Same code before
and after.


# 1.58 28-Dec-2019 jmcneill

Do not use Early Write Acknowledge for PCIe I/O and config space.


# 1.57 27-Dec-2019 jmcneill

Enable early write acknowledge for device memory mappings.


# 1.56 19-Dec-2019 skrll

G/C kasan_shadow_map call in pmap_enter

pmap_growkernel calls kasan_shadow_map for KVA


# 1.55 18-Dec-2019 ryo

atomic_add_16() is not used in pmap.c anymore. no need decl here.


# 1.54 18-Dec-2019 ryo

space to tab


# 1.53 14-Dec-2019 skrll

Fix build... wire_count probably doesn't need atomics


# 1.52 13-Dec-2019 skrll

Fix KASAN support by calling kasan_shadow_map in pmap_growkernel


# 1.51 10-Dec-2019 ad

pg->phys_addr -> VM_PAGE_TO_PHYS(pg)


Revision tags: phil-wifi-20191119
# 1.50 14-Nov-2019 maxv

Mark several kASan functions with __nothing, to avoid annoying #ifdefs.
Same as kCSan and kMSan.


# 1.49 14-Nov-2019 maxv

Don't include "opt_kasan.h" when there's already <sys/asan.h> included.


# 1.48 29-Oct-2019 maya

Define PMAP_NEED_PROCWR, providing strategically placed i-cache
synchronization where just-changed memory is about to be executed.

Fixes SIGILLs seen when running Mono 6 on QEMU Cortex-A57.

ok ryo


# 1.47 22-Sep-2019 jmcneill

Disable translation table walks using TTBR0 while changing its value and
when deactivating a pmap. Fixes stability issues on Ampere eMAG CPUs.


# 1.46 20-Sep-2019 ryo

ref/mod bit should be set according to 'flags' argument, not 'prot'. r1.44 was incomplete.


# 1.45 13-Sep-2019 ryo

In pmap_devmap_bootstrap(), cpu_earlydevice_va_p() must not return true until *all* devmap tables have been enabled.
console mapping may be present in the last table.


# 1.44 07-Sep-2019 ryo

- remove incorrect KASSERT. mmap(2) with prot=PROT_WRITE calls pmap_enter(..., PROT_WRITE) internally.
- fix to update page reference flags when only PROT_WRITE or PROT_EXECUTE specified


# 1.43 15-Aug-2019 skrll

Make pmap_db_pte_print more terse so it's quicker on serial consoles


# 1.42 12-Aug-2019 skrll

Use PMAP_DEV in DEVMAP_ENTRY rather than pmap_map_chunk. It's clearer and
means pmap_map_chunk can be made to map other memory types.


Revision tags: netbsd-9-base phil-wifi-20190609
# 1.41 17-May-2019 mrg

branches: 1.41.2;
apply some __diagused.


Revision tags: isaki-audio2-base
# 1.40 08-Apr-2019 ryo

- free empty page tables pages if reach a certain usage.
- need to lock at removing an old pg (_pmap_remove_pv) in _pmap_enter()


# 1.39 06-Apr-2019 ryo

Fix race conditions about pmap_page_protect() and pmap_enter().

while handling same PTE by these functions in same time, there
is a critical path that the number of valid PTEs and wire_count
are inconsistent, and it caused KASSERT.
Need to hold a pv_lock while modifying them.


# 1.38 20-Mar-2019 ryo

spinkle __printflike(), and use PRIxxx


# 1.37 19-Mar-2019 ryo

- add ddb command "machine ttbr" to dump MMU tables.
- tidy up descriptions, usages and messages.


# 1.36 19-Mar-2019 ryo

- free L1-L3 pages that has been emptied by pmap_remove().
- if no memories, pmap_enter will return correctly ENOMEM if PMAP_CANFAIL, or wait until available any memories if !PMAP_CANFAIL.

These changes improves the stability when we use a huge virtual memory spaces with mmap.


# 1.35 06-Feb-2019 ryo

improve pmap_remove
- don't lock/unlock per page in pmap_remove()
- speedup pte lookup for continuous addresses
- bring out pool_cache_put(&_pmap_pv_pool, pv) from lock/unlock section


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226
# 1.34 21-Dec-2018 ryo

- add workaround for Cavium ThunderX errata 27456.
- add cpufuncs table in cpu_info. each cpu clusters may have different erratum. (e.g. big.LITTLE)


Revision tags: pgoyette-compat-1126
# 1.33 01-Nov-2018 maxv

Add kASan support for aarch64. Stack tracking needs more investigation
and will come in a separate commit.

Reviewed by ryo@ jmcneill@ skrll@.


# 1.32 31-Oct-2018 ryo

invalidate icache correctly.
l3pte_executable() should be used for only valid pte.


Revision tags: pgoyette-compat-1020
# 1.31 18-Oct-2018 skrll

Provide generic start code that assumes the MMU is off and caches are
disabled as per the linux booting protocol for ARMv6 and ARMv7 boards.
u-boot image type should be changed to 'linux' for correct behaviour.

The new start code builds a minimal "bootstrap" L1PT with cached access
disabled and uses the same table for all processors. AP startup is
performed in less steps and more code is written in C.

The bootstrap tables and stack are placed into an (orphaned) section
"_init_memory" which is given to uvm when it is no longer used.

Various kernels have been converted to use this code and tested. Some
boards were provided by TNF. Thanks!

The GENERIC kernel now boots on boards using the TEGRA, SUNXI and EXYNOS
kernels. The GENERIC kernel will also work on RPI2 using u-boot.

Thanks to martin@ and aymeric@ for testing on parallella and nanosoc
respectively


# 1.30 14-Oct-2018 skrll

Use __nothing


# 1.29 12-Oct-2018 ryo

add initial support of COMPAT_NETBSD32 on AArch64.
arm ELF32 EABI binaries could be execute in AArch32 state on AArch64. A32 THUMB mode is not supported yet.


# 1.28 12-Oct-2018 ryo

- cleanup checking address ranges with IN_RANGE macro
- change PM_ADDR_CHECK macro to KASSERTMSG
- restore fast lookup cases with IN_RANGE macro for pmap_extract changed in my previous commit.


# 1.27 12-Oct-2018 ryo

rewrite pmap_pte_lookup() to share similar code.


# 1.26 04-Oct-2018 ryo

cleanup locore, and changed the way to map memories during boot.
- add functions bootpage_enter() and bootpage_alloc() to adapt various layout
of physical memory map. especially for 64bit physical memory layout.
pmapboot_alloc() allocates pagetable pages from _end[].
- changed to map only the required amount for PA=VA identity mapping
(kernel image, UART device, and FDT blob) with L2_BLOCK(2Mbyte).
- changing page permission for kernel image, and making KSEG mapping are done
at cpu_kernel_vm_init() instead of at locore.
- optimize PTE entries with PTE Contiguous bit. it is enabled on devmap only for now.

reviewed by skrll@, thanks.


# 1.25 04-Oct-2018 ryo

* define LX_BLKPAG_{OS,ATTR}_* for OS dependent PTE attributes in pmap.h
* cleanup macros


Revision tags: pgoyette-compat-0930
# 1.24 17-Sep-2018 ryo

delete debug printf and KASSERT.


# 1.23 10-Sep-2018 maxv

Replace KDASSERT by panic.


# 1.22 10-Sep-2018 maxv

Rename _pmap_alloc_pdp -> pmap_alloc_pdp, and make it public.


# 1.21 10-Sep-2018 ryo

cleanup aarch64 mpstart and fdt bootstrap
* arm_cpu_hatch_arg is a bad idea. avoid serializing CPU startup, and eliminate arm_cpu_hatch_arg.
in mpstart, resolve own cpu index using array of cpu_mpidr[] (aarch64)
* add support fdt enable-method "spin-table"
* add support fdt enable-method "brcm,bcm2836-smp" (for 32bit RaspberryPi)
* use arm_fdt_cpu_bootstrap() instead of psci_fdt_bootstrap()
* rename "arm/fdt/psci_fdt.h" to "arm/fdt/psci_fdtvar.h" because of conflict of include file for needs-flag
* add devmap for cpu spin-table of raspberrypi3/aarch64
* no need to force hatch APs for raspberrypi3/arm32 ifndef MULTIPROCESSOR.
* fix to work pmap_extract(kerneltext/data/bss) even if before calling pmap_bootstrap

idea to use cpu_mpidr[] by jmcneill@. reviewd by skrll@. thanks.


Revision tags: pgoyette-compat-0906
# 1.20 27-Aug-2018 ryo

need to add VM_PROT_READ when pmap_kenter_pa(va, pa, VM_PROT_WRITE, 0) or pmap_kenter_pa(va, pa, VM_PROT_EXECUTE, 0).
VM_PROT_READ is treated as an access permission inernally.


# 1.19 11-Aug-2018 ryo

change to minimum invalidation of TLB.
specifying not only va but also asid, and not invalidate L0-L2 entry using tlbi_*_ll() if needed.


# 1.18 10-Aug-2018 ryo

treat kernel-exec attr and user-exec attr separately.
kernel cannot execute userland exec page, and user cannot execute kernel page.


# 1.17 06-Aug-2018 ryo

set kernel text/rodata readonly by default.
add function db_write_text() for setting ddb breakpoint.


# 1.16 31-Jul-2018 skrll

Define and use VPRINTF


Revision tags: pgoyette-compat-0728
# 1.15 27-Jul-2018 ryo

changes of pmap.c r1.13 seems to be unstable.
In order to invalidate icache, not to invalidate all icache,
but temporary to make the page writable and invalidate target address only.


# 1.14 24-Jul-2018 ryo

don't call pool_cache_put with locking pmap. pool_cache_put call pmap_kenter_pa internally.
(pool_cache_put_paddr -> pool_cache_put_slow -> pool_get -> pmap_kenter_pa)


# 1.13 23-Jul-2018 ryo

* fix icache invalidations.
* "ic ivau" (aarch64_icache_sync_range) with VA generates permission fault in some situations, therefore use KSEG address for now.


# 1.12 23-Jul-2018 ryo

rather than using flags to resolve nested locks, reserve pool_cache before locking.


# 1.11 21-Jul-2018 ryo

* avoid deadlock. mutex_owned() works only for adaptive lock, therefore we cannot use it for spinlock...
* add more NULL check
* clear pte when pmap_enter() fails


# 1.10 17-Jul-2018 ryo

Use __debugused


# 1.9 17-Jul-2018 christos

Add missing casts, remove unused variables.


# 1.8 09-Jul-2018 ryo

need locks in pmap_kremove() and pmap_fault_fixup()


Revision tags: phil-wifi-base pgoyette-compat-0625 pgoyette-compat-0521
# 1.7 20-May-2018 ryo

branches: 1.7.2;
pmap_enter() must update modified/referenced flags by 'flags' not 'prot'.


# 1.6 16-May-2018 ryo

Fix memory leak. it was leaking one page every pmap_create().
pm->pm_vmlist must be initialized before calling _pmap_alloc_pdp().


Revision tags: pgoyette-compat-0502
# 1.5 29-Apr-2018 ryo

fix KASSERT panic. pv_entry may not be exists in pvlist when pmap_remove().


# 1.4 29-Apr-2018 ryo

delete unused code


# 1.3 27-Apr-2018 ryo

fix instability behavior of bufcache on aarch64.
* fix to return correct ref/mod when PMAP_WIRED.
* changed to keep wired flags in pte instead of pv_entry, and cleanup.


Revision tags: pgoyette-compat-0422 pgoyette-compat-0415 pgoyette-compat-0407
# 1.2 01-Apr-2018 ryo

Add initial support for ARMv8 (AARCH64) (by nisimura@ and ryo@)

- sys/arch/evbarm64 is gone and integrated into sys/arch/evbarm. (by skrll@)
- add support fdt. evbarm/conf/GENERIC64 fdt (bcm2837,sunxi,tegra) based generic 64bit kernel config. (by skrll@, jmcneill@)


Revision tags: netbsd-8-2-RELEASE netbsd-8-1-RELEASE netbsd-8-1-RC1 netbsd-7-2-RELEASE netbsd-8-0-RELEASE netbsd-8-0-RC2 netbsd-8-0-RC1 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 netbsd-7-1-2-RELEASE pgoyette-compat-base netbsd-7-1-1-RELEASE tls-maxphys-base-20171202 matt-nb8-mediatek-base nick-nhusb-base-20170825 perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base pgoyette-localcount-20170320 netbsd-7-1-RELEASE netbsd-7-1-RC2 nick-nhusb-base-20170204 netbsd-7-nhusb-base-20170116 bouyer-socketcan-base pgoyette-localcount-20170107 netbsd-7-1-RC1 nick-nhusb-base-20161204 pgoyette-localcount-20161104 netbsd-7-0-2-RELEASE nick-nhusb-base-20161004 localcount-20160914 netbsd-7-nhusb-base pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907 nick-nhusb-base-20160529 netbsd-7-0-1-RELEASE nick-nhusb-base-20160422 nick-nhusb-base-20160319 nick-nhusb-base-20151226 netbsd-7-0-RELEASE nick-nhusb-base-20150921 netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 nick-nhusb-base-20150606 nick-nhusb-base-20150406 nick-nhusb-base tls-maxphys-base netbsd-7-base
# 1.1 10-Aug-2014 matt

branches: 1.1.4; 1.1.28;
Preliminary files for AARCH64 (64-bit ARM) support.
Enough for a distribution build.


# 1.96 10-Nov-2020 skrll

AA64 is not MIPS.

Change all KSEG references to directmap


# 1.95 07-Nov-2020 skrll

In pmap_devmap_bootstrap only set pmap_devmap_bootstrap_done if there
is an entry and ALL of the entries have been done. The entry required
for EARLYCONS might not be the first/only one...


Revision tags: thorpej-futex-base
# 1.94 01-Nov-2020 jmcneill

No need to disable translation table walks in pmap_activate().


# 1.93 22-Oct-2020 skrll

Use the isb macro - missed in previous commit


# 1.92 22-Oct-2020 skrll

Use the dmb/dsb/isb macros... if nothing else they're all now consistent
about the "memory" assembler contraint.

No binary change


# 1.91 28-Sep-2020 skrll

Only set pmap_devmap_bootstrap_done if something gets mapped.

Think acpi_platform_devmap


# 1.90 19-Sep-2020 skrll

Make __md_palloc pmap agnostic (think sys/uvm/pmap)


# 1.89 14-Sep-2020 ryo

PID_MAX is just an initial value (soft maximum). Don't use it for CTASSERT.
defined __HAVE_CPU_MAXPROC to use function cpu_maxproc().

pointed out by mrg@, thanks.


# 1.88 06-Sep-2020 ryo

Fix panic caused by modload. http://mail-index.netbsd.org/port-arm/2020/08/30/msg006960.html

The address space reserved for modules may not be mapped in L1-L3.


# 1.87 14-Aug-2020 skrll

Whitespace


# 1.86 12-Aug-2020 skrll

Part IV of ad's performance improvements for aarch64

- Implement pmap_growkernel(), and update kernel pmap's stats with atomics.

- Then, pmap_kenter_pa() and pmap_kremove() no longer need to allocate
memory nor take pm_lock, because they only modify L3 PTEs.

- Then, pm_lock and pp_lock can be adaptive mutexes at IPL_NONE which are
cheaper than spin mutexes.

- Take the pmap's lock in pmap_extract() if not the kernel's pmap, otherwise
pmap_extract() might see inconsistent state.


# 1.85 09-Aug-2020 skrll

Fix another UVMHIST so it doesn't use %s


# 1.84 16-Jul-2020 skrll

pmapboot_enter simplication
- bootpage_alloc in asm becomes pmapboot_pagealloc in C
- PMAPBOOT_ENTER_NOBLOCK is removed as it's not used
- PMAPBOOT_ENTER_NOOVERWRITE is removed as it's now always on
- physpage_allocator argument is removed as it's always
pmapboot_pagealloc
- Support for EARLYCONS without CONSADDR is removed so that the identity
map for CONSADDR is always known.

For the assembly files:
2 files changed, 40 insertions(+), 89 deletions(-)

LGTM ryo


# 1.83 04-Jul-2020 rin

Use tlen for temporary length variable instead of l, which is usually
used for struct lwp *.

No binary changes.


# 1.82 02-Jul-2020 rin

pmap_procwr(): sync icache even if p != curproc. This fixes applications
like GDB for arm32, that rewrite text of other process.

Thanks to ryo@ for discussion.


# 1.81 02-Jul-2020 rin

Set uvmexp.ncolors appropriately, which is required for some CPU
models with VIPT icache.

Otherwise, alias in virtual address results in inconsistent results,
at least for applications that rewrite text of other process, e.g.,
GDB for arm32.

Also, this hopefully fixes other unexpected failures due to alias.

Confirmed that there's no observable regression in performance;
difference in ``time make -j8'' for GENERIC64 kernel on BCM2837
with and without setting uvmexp.ncolors is within 0.1%.

Thanks to ryo@ for discussion.


# 1.80 27-Jun-2020 rin

Fix typo in name of evcnt(4) counter.


# 1.79 24-Jun-2020 ryo

Fix bug with incorrect range calculation when doing icache sync.
This is called by sysarch(ARM_SYNC_ICACHE) from aarch32 (compat_netbsd32) emul process.

pointed out by rin@, thanks.

XXX pullup-9


# 1.78 14-Jun-2020 ad

- Fix a lock order reversal in pmap_page_protect().

- Make sure pmap is always locked when updating stats; atomics no longer
needed to do that.

- Remove unneeded traversal of pv list in pmap_enter_pv().

- Shrink struct vm_page from 136 to 128 bytes (cache line sized) and struct
pv_entry from 48 to 32 bytes (power of 2 sized).

- Embed a pv_entry in each vm_page. This means PV entries don't need to
be allocated for private anonymous memory / COW pages / most UBC mappings.
Dynamic PV entries are then used only for stuff like shared libraries and
shared memory.

Proposed on port-arm@.


# 1.77 10-Jun-2020 ad

- Wired/resident stats shouldn't covered by PMAPCOUNTERS.
- Rename need_update_pv -> need_enter_pv.

Ok ryo@


# 1.76 01-Jun-2020 ryo

no need to make the PTE writable to do icache_sync, enough to accessible.


# 1.75 15-May-2020 skrll

Use __diagused


# 1.74 15-May-2020 tnn

fix non-diag build


# 1.73 14-May-2020 skrll

Use MUTEX_NODEBUG for PV locks as is commonly done. OK ryo.


# 1.72 13-May-2020 jmcneill

Implement pmap_extract_coherency


Revision tags: bouyer-xenpvh-base2 phil-wifi-20200421 bouyer-xenpvh-base1
# 1.71 18-Apr-2020 skrll

PMAP_DEBUG has been deleted on arm


# 1.70 13-Apr-2020 maxv

Add support for Branch Target Identification (BTI).

On the executable pages that have the GP (Guarded Page) bit, the semantic
of the "br" and "blr" instructions is changed: the CPU expects the first
instruction of the jump/call target to be "bti", and faults if it isn't.

We add the GP bit on the kernel .text pages (and incidentally the .rodata
pages, but we don't care). The compiler adds a "bti c" instruction at the
beginning of each C function. We modify the ENTRY() macros to manually add
"bti c" in the asm functions.

cpuswitch.S needs a specific change: with "br x27" the CPU expects "bti j",
which is bad because the functions begin with "bti c"; switch to "br x16",
for the CPU to accept "bti c".

BTI helps defend against JOP/COP. Tested on Qemu.


Revision tags: phil-wifi-20200411 bouyer-xenpvh-base
# 1.69 08-Apr-2020 ryo

branches: 1.69.2;
use PMAP_PAGE_INIT() to initialize mutex in pmap_page.

VM_MDPAGE_INIT() in pmap_free_pdp() had initialized pp_flags,
so it unintentionally cleared PMAP_PAGE_FLAGS_PV_TRACKED.
use PMAP_PAGE_INIT to avoid using PMAP_PAGE_FLAGS_PV_TRACKED.

pointed out by tnn@, thanks


Revision tags: phil-wifi-20200406
# 1.68 14-Mar-2020 ad

pmap_remove_all(): Return a boolean value to indicate the behaviour. If
true, all mappings have been removed, the pmap is totally cleared out, and
UVM can then avoid doing the work to call pmap_remove() for each map entry.
If false, either nothing has been done, or some helpful arch-specific voodoo
has taken place.


Revision tags: is-mlppp-base
# 1.67 02-Mar-2020 ryo

oops, fix incorrect usage of daif_enable() in my previous commit.


# 1.66 29-Feb-2020 ryo

Fix pmap to work correctly with tagged addresses

- when fault, untag from address before passing to uvm/pmap functions
- pmap_extract() checks more strictly and consider the address tag


# 1.65 29-Feb-2020 ryo

use pmapboot_enter_range()


Revision tags: ad-namecache-base3
# 1.64 10-Feb-2020 ryo

use LIST(3) instead of TAILQ(3) to save one word in struct vm_page and struct pmap.

pointed out by riastradh@. thanks


# 1.63 03-Feb-2020 ryo

add support pmap_pv(9)

Patch originally from jmcneill@. thanks


# 1.62 03-Feb-2020 ryo

separate struct vm_page_md into vm_page_md and pmap_page
for preparation pmap_pv(9)


Revision tags: ad-namecache-base2 ad-namecache-base1
# 1.61 09-Jan-2020 ryo

fix behaviour mmap()/mprotect() when passed only PROT_EXEC.

when mmap()/mprotect() with only PROT_EXEC, syscall will be successful,
but the page actually hadn't been mapped.
it should be mapped with PROT_READ|PROT_EXEC implicitly. (r-x)


Revision tags: ad-namecache-base
# 1.60 30-Dec-2019 skrll

branches: 1.60.2;
Update pmap_map_chunk to allow L[12] block mappings and L3 page mappings


# 1.59 30-Dec-2019 skrll

Remove unnecessary brackets and unwrap a conditional. Same code before
and after.


# 1.58 28-Dec-2019 jmcneill

Do not use Early Write Acknowledge for PCIe I/O and config space.


# 1.57 27-Dec-2019 jmcneill

Enable early write acknowledge for device memory mappings.


# 1.56 19-Dec-2019 skrll

G/C kasan_shadow_map call in pmap_enter

pmap_growkernel calls kasan_shadow_map for KVA


# 1.55 18-Dec-2019 ryo

atomic_add_16() is not used in pmap.c anymore. no need decl here.


# 1.54 18-Dec-2019 ryo

space to tab


# 1.53 14-Dec-2019 skrll

Fix build... wire_count probably doesn't need atomics


# 1.52 13-Dec-2019 skrll

Fix KASAN support by calling kasan_shadow_map in pmap_growkernel


# 1.51 10-Dec-2019 ad

pg->phys_addr -> VM_PAGE_TO_PHYS(pg)


Revision tags: phil-wifi-20191119
# 1.50 14-Nov-2019 maxv

Mark several kASan functions with __nothing, to avoid annoying #ifdefs.
Same as kCSan and kMSan.


# 1.49 14-Nov-2019 maxv

Don't include "opt_kasan.h" when there's already <sys/asan.h> included.


# 1.48 29-Oct-2019 maya

Define PMAP_NEED_PROCWR, providing strategically placed i-cache
synchronization where just-changed memory is about to be executed.

Fixes SIGILLs seen when running Mono 6 on QEMU Cortex-A57.

ok ryo


# 1.47 22-Sep-2019 jmcneill

Disable translation table walks using TTBR0 while changing its value and
when deactivating a pmap. Fixes stability issues on Ampere eMAG CPUs.


# 1.46 20-Sep-2019 ryo

ref/mod bit should be set according to 'flags' argument, not 'prot'. r1.44 was incomplete.


# 1.45 13-Sep-2019 ryo

In pmap_devmap_bootstrap(), cpu_earlydevice_va_p() must not return true until *all* devmap tables have been enabled.
console mapping may be present in the last table.


# 1.44 07-Sep-2019 ryo

- remove incorrect KASSERT. mmap(2) with prot=PROT_WRITE calls pmap_enter(..., PROT_WRITE) internally.
- fix to update page reference flags when only PROT_WRITE or PROT_EXECUTE specified


# 1.43 15-Aug-2019 skrll

Make pmap_db_pte_print more terse so it's quicker on serial consoles


# 1.42 12-Aug-2019 skrll

Use PMAP_DEV in DEVMAP_ENTRY rather than pmap_map_chunk. It's clearer and
means pmap_map_chunk can be made to map other memory types.


Revision tags: netbsd-9-base phil-wifi-20190609
# 1.41 17-May-2019 mrg

branches: 1.41.2;
apply some __diagused.


Revision tags: isaki-audio2-base
# 1.40 08-Apr-2019 ryo

- free empty page tables pages if reach a certain usage.
- need to lock at removing an old pg (_pmap_remove_pv) in _pmap_enter()


# 1.39 06-Apr-2019 ryo

Fix race conditions about pmap_page_protect() and pmap_enter().

while handling same PTE by these functions in same time, there
is a critical path that the number of valid PTEs and wire_count
are inconsistent, and it caused KASSERT.
Need to hold a pv_lock while modifying them.


# 1.38 20-Mar-2019 ryo

spinkle __printflike(), and use PRIxxx


# 1.37 19-Mar-2019 ryo

- add ddb command "machine ttbr" to dump MMU tables.
- tidy up descriptions, usages and messages.


# 1.36 19-Mar-2019 ryo

- free L1-L3 pages that has been emptied by pmap_remove().
- if no memories, pmap_enter will return correctly ENOMEM if PMAP_CANFAIL, or wait until available any memories if !PMAP_CANFAIL.

These changes improves the stability when we use a huge virtual memory spaces with mmap.


# 1.35 06-Feb-2019 ryo

improve pmap_remove
- don't lock/unlock per page in pmap_remove()
- speedup pte lookup for continuous addresses
- bring out pool_cache_put(&_pmap_pv_pool, pv) from lock/unlock section


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226
# 1.34 21-Dec-2018 ryo

- add workaround for Cavium ThunderX errata 27456.
- add cpufuncs table in cpu_info. each cpu clusters may have different erratum. (e.g. big.LITTLE)


Revision tags: pgoyette-compat-1126
# 1.33 01-Nov-2018 maxv

Add kASan support for aarch64. Stack tracking needs more investigation
and will come in a separate commit.

Reviewed by ryo@ jmcneill@ skrll@.


# 1.32 31-Oct-2018 ryo

invalidate icache correctly.
l3pte_executable() should be used for only valid pte.


Revision tags: pgoyette-compat-1020
# 1.31 18-Oct-2018 skrll

Provide generic start code that assumes the MMU is off and caches are
disabled as per the linux booting protocol for ARMv6 and ARMv7 boards.
u-boot image type should be changed to 'linux' for correct behaviour.

The new start code builds a minimal "bootstrap" L1PT with cached access
disabled and uses the same table for all processors. AP startup is
performed in less steps and more code is written in C.

The bootstrap tables and stack are placed into an (orphaned) section
"_init_memory" which is given to uvm when it is no longer used.

Various kernels have been converted to use this code and tested. Some
boards were provided by TNF. Thanks!

The GENERIC kernel now boots on boards using the TEGRA, SUNXI and EXYNOS
kernels. The GENERIC kernel will also work on RPI2 using u-boot.

Thanks to martin@ and aymeric@ for testing on parallella and nanosoc
respectively


# 1.30 14-Oct-2018 skrll

Use __nothing


# 1.29 12-Oct-2018 ryo

add initial support of COMPAT_NETBSD32 on AArch64.
arm ELF32 EABI binaries could be execute in AArch32 state on AArch64. A32 THUMB mode is not supported yet.


# 1.28 12-Oct-2018 ryo

- cleanup checking address ranges with IN_RANGE macro
- change PM_ADDR_CHECK macro to KASSERTMSG
- restore fast lookup cases with IN_RANGE macro for pmap_extract changed in my previous commit.


# 1.27 12-Oct-2018 ryo

rewrite pmap_pte_lookup() to share similar code.


# 1.26 04-Oct-2018 ryo

cleanup locore, and changed the way to map memories during boot.
- add functions bootpage_enter() and bootpage_alloc() to adapt various layout
of physical memory map. especially for 64bit physical memory layout.
pmapboot_alloc() allocates pagetable pages from _end[].
- changed to map only the required amount for PA=VA identity mapping
(kernel image, UART device, and FDT blob) with L2_BLOCK(2Mbyte).
- changing page permission for kernel image, and making KSEG mapping are done
at cpu_kernel_vm_init() instead of at locore.
- optimize PTE entries with PTE Contiguous bit. it is enabled on devmap only for now.

reviewed by skrll@, thanks.


# 1.25 04-Oct-2018 ryo

* define LX_BLKPAG_{OS,ATTR}_* for OS dependent PTE attributes in pmap.h
* cleanup macros


Revision tags: pgoyette-compat-0930
# 1.24 17-Sep-2018 ryo

delete debug printf and KASSERT.


# 1.23 10-Sep-2018 maxv

Replace KDASSERT by panic.


# 1.22 10-Sep-2018 maxv

Rename _pmap_alloc_pdp -> pmap_alloc_pdp, and make it public.


# 1.21 10-Sep-2018 ryo

cleanup aarch64 mpstart and fdt bootstrap
* arm_cpu_hatch_arg is a bad idea. avoid serializing CPU startup, and eliminate arm_cpu_hatch_arg.
in mpstart, resolve own cpu index using array of cpu_mpidr[] (aarch64)
* add support fdt enable-method "spin-table"
* add support fdt enable-method "brcm,bcm2836-smp" (for 32bit RaspberryPi)
* use arm_fdt_cpu_bootstrap() instead of psci_fdt_bootstrap()
* rename "arm/fdt/psci_fdt.h" to "arm/fdt/psci_fdtvar.h" because of conflict of include file for needs-flag
* add devmap for cpu spin-table of raspberrypi3/aarch64
* no need to force hatch APs for raspberrypi3/arm32 ifndef MULTIPROCESSOR.
* fix to work pmap_extract(kerneltext/data/bss) even if before calling pmap_bootstrap

idea to use cpu_mpidr[] by jmcneill@. reviewd by skrll@. thanks.


Revision tags: pgoyette-compat-0906
# 1.20 27-Aug-2018 ryo

need to add VM_PROT_READ when pmap_kenter_pa(va, pa, VM_PROT_WRITE, 0) or pmap_kenter_pa(va, pa, VM_PROT_EXECUTE, 0).
VM_PROT_READ is treated as an access permission inernally.


# 1.19 11-Aug-2018 ryo

change to minimum invalidation of TLB.
specifying not only va but also asid, and not invalidate L0-L2 entry using tlbi_*_ll() if needed.


# 1.18 10-Aug-2018 ryo

treat kernel-exec attr and user-exec attr separately.
kernel cannot execute userland exec page, and user cannot execute kernel page.


# 1.17 06-Aug-2018 ryo

set kernel text/rodata readonly by default.
add function db_write_text() for setting ddb breakpoint.


# 1.16 31-Jul-2018 skrll

Define and use VPRINTF


Revision tags: pgoyette-compat-0728
# 1.15 27-Jul-2018 ryo

changes of pmap.c r1.13 seems to be unstable.
In order to invalidate icache, not to invalidate all icache,
but temporary to make the page writable and invalidate target address only.


# 1.14 24-Jul-2018 ryo

don't call pool_cache_put with locking pmap. pool_cache_put call pmap_kenter_pa internally.
(pool_cache_put_paddr -> pool_cache_put_slow -> pool_get -> pmap_kenter_pa)


# 1.13 23-Jul-2018 ryo

* fix icache invalidations.
* "ic ivau" (aarch64_icache_sync_range) with VA generates permission fault in some situations, therefore use KSEG address for now.


# 1.12 23-Jul-2018 ryo

rather than using flags to resolve nested locks, reserve pool_cache before locking.


# 1.11 21-Jul-2018 ryo

* avoid deadlock. mutex_owned() works only for adaptive lock, therefore we cannot use it for spinlock...
* add more NULL check
* clear pte when pmap_enter() fails


# 1.10 17-Jul-2018 ryo

Use __debugused


# 1.9 17-Jul-2018 christos

Add missing casts, remove unused variables.


# 1.8 09-Jul-2018 ryo

need locks in pmap_kremove() and pmap_fault_fixup()


Revision tags: phil-wifi-base pgoyette-compat-0625 pgoyette-compat-0521
# 1.7 20-May-2018 ryo

branches: 1.7.2;
pmap_enter() must update modified/referenced flags by 'flags' not 'prot'.


# 1.6 16-May-2018 ryo

Fix memory leak. it was leaking one page every pmap_create().
pm->pm_vmlist must be initialized before calling _pmap_alloc_pdp().


Revision tags: pgoyette-compat-0502
# 1.5 29-Apr-2018 ryo

fix KASSERT panic. pv_entry may not be exists in pvlist when pmap_remove().


# 1.4 29-Apr-2018 ryo

delete unused code


# 1.3 27-Apr-2018 ryo

fix instability behavior of bufcache on aarch64.
* fix to return correct ref/mod when PMAP_WIRED.
* changed to keep wired flags in pte instead of pv_entry, and cleanup.


Revision tags: pgoyette-compat-0422 pgoyette-compat-0415 pgoyette-compat-0407
# 1.2 01-Apr-2018 ryo

Add initial support for ARMv8 (AARCH64) (by nisimura@ and ryo@)

- sys/arch/evbarm64 is gone and integrated into sys/arch/evbarm. (by skrll@)
- add support fdt. evbarm/conf/GENERIC64 fdt (bcm2837,sunxi,tegra) based generic 64bit kernel config. (by skrll@, jmcneill@)


Revision tags: netbsd-8-2-RELEASE netbsd-8-1-RELEASE netbsd-8-1-RC1 netbsd-7-2-RELEASE netbsd-8-0-RELEASE netbsd-8-0-RC2 netbsd-8-0-RC1 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 netbsd-7-1-2-RELEASE pgoyette-compat-base netbsd-7-1-1-RELEASE tls-maxphys-base-20171202 matt-nb8-mediatek-base nick-nhusb-base-20170825 perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base pgoyette-localcount-20170320 netbsd-7-1-RELEASE netbsd-7-1-RC2 nick-nhusb-base-20170204 netbsd-7-nhusb-base-20170116 bouyer-socketcan-base pgoyette-localcount-20170107 netbsd-7-1-RC1 nick-nhusb-base-20161204 pgoyette-localcount-20161104 netbsd-7-0-2-RELEASE nick-nhusb-base-20161004 localcount-20160914 netbsd-7-nhusb-base pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907 nick-nhusb-base-20160529 netbsd-7-0-1-RELEASE nick-nhusb-base-20160422 nick-nhusb-base-20160319 nick-nhusb-base-20151226 netbsd-7-0-RELEASE nick-nhusb-base-20150921 netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 nick-nhusb-base-20150606 nick-nhusb-base-20150406 nick-nhusb-base tls-maxphys-base netbsd-7-base
# 1.1 10-Aug-2014 matt

branches: 1.1.4; 1.1.28;
Preliminary files for AARCH64 (64-bit ARM) support.
Enough for a distribution build.


# 1.95 07-Nov-2020 skrll

In pmap_devmap_bootstrap only set pmap_devmap_bootstrap_done if there
is an entry and ALL of the entries have been done. The entry required
for EARLYCONS might not be the first/only one...


Revision tags: thorpej-futex-base
# 1.94 01-Nov-2020 jmcneill

No need to disable translation table walks in pmap_activate().


# 1.93 22-Oct-2020 skrll

Use the isb macro - missed in previous commit


# 1.92 22-Oct-2020 skrll

Use the dmb/dsb/isb macros... if nothing else they're all now consistent
about the "memory" assembler contraint.

No binary change


# 1.91 28-Sep-2020 skrll

Only set pmap_devmap_bootstrap_done if something gets mapped.

Think acpi_platform_devmap


# 1.90 19-Sep-2020 skrll

Make __md_palloc pmap agnostic (think sys/uvm/pmap)


# 1.89 14-Sep-2020 ryo

PID_MAX is just an initial value (soft maximum). Don't use it for CTASSERT.
defined __HAVE_CPU_MAXPROC to use function cpu_maxproc().

pointed out by mrg@, thanks.


# 1.88 06-Sep-2020 ryo

Fix panic caused by modload. http://mail-index.netbsd.org/port-arm/2020/08/30/msg006960.html

The address space reserved for modules may not be mapped in L1-L3.


# 1.87 14-Aug-2020 skrll

Whitespace


# 1.86 12-Aug-2020 skrll

Part IV of ad's performance improvements for aarch64

- Implement pmap_growkernel(), and update kernel pmap's stats with atomics.

- Then, pmap_kenter_pa() and pmap_kremove() no longer need to allocate
memory nor take pm_lock, because they only modify L3 PTEs.

- Then, pm_lock and pp_lock can be adaptive mutexes at IPL_NONE which are
cheaper than spin mutexes.

- Take the pmap's lock in pmap_extract() if not the kernel's pmap, otherwise
pmap_extract() might see inconsistent state.


# 1.85 09-Aug-2020 skrll

Fix another UVMHIST so it doesn't use %s


# 1.84 16-Jul-2020 skrll

pmapboot_enter simplication
- bootpage_alloc in asm becomes pmapboot_pagealloc in C
- PMAPBOOT_ENTER_NOBLOCK is removed as it's not used
- PMAPBOOT_ENTER_NOOVERWRITE is removed as it's now always on
- physpage_allocator argument is removed as it's always
pmapboot_pagealloc
- Support for EARLYCONS without CONSADDR is removed so that the identity
map for CONSADDR is always known.

For the assembly files:
2 files changed, 40 insertions(+), 89 deletions(-)

LGTM ryo


# 1.83 04-Jul-2020 rin

Use tlen for temporary length variable instead of l, which is usually
used for struct lwp *.

No binary changes.


# 1.82 02-Jul-2020 rin

pmap_procwr(): sync icache even if p != curproc. This fixes applications
like GDB for arm32, that rewrite text of other process.

Thanks to ryo@ for discussion.


# 1.81 02-Jul-2020 rin

Set uvmexp.ncolors appropriately, which is required for some CPU
models with VIPT icache.

Otherwise, alias in virtual address results in inconsistent results,
at least for applications that rewrite text of other process, e.g.,
GDB for arm32.

Also, this hopefully fixes other unexpected failures due to alias.

Confirmed that there's no observable regression in performance;
difference in ``time make -j8'' for GENERIC64 kernel on BCM2837
with and without setting uvmexp.ncolors is within 0.1%.

Thanks to ryo@ for discussion.


# 1.80 27-Jun-2020 rin

Fix typo in name of evcnt(4) counter.


# 1.79 24-Jun-2020 ryo

Fix bug with incorrect range calculation when doing icache sync.
This is called by sysarch(ARM_SYNC_ICACHE) from aarch32 (compat_netbsd32) emul process.

pointed out by rin@, thanks.

XXX pullup-9


# 1.78 14-Jun-2020 ad

- Fix a lock order reversal in pmap_page_protect().

- Make sure pmap is always locked when updating stats; atomics no longer
needed to do that.

- Remove unneeded traversal of pv list in pmap_enter_pv().

- Shrink struct vm_page from 136 to 128 bytes (cache line sized) and struct
pv_entry from 48 to 32 bytes (power of 2 sized).

- Embed a pv_entry in each vm_page. This means PV entries don't need to
be allocated for private anonymous memory / COW pages / most UBC mappings.
Dynamic PV entries are then used only for stuff like shared libraries and
shared memory.

Proposed on port-arm@.


# 1.77 10-Jun-2020 ad

- Wired/resident stats shouldn't covered by PMAPCOUNTERS.
- Rename need_update_pv -> need_enter_pv.

Ok ryo@


# 1.76 01-Jun-2020 ryo

no need to make the PTE writable to do icache_sync, enough to accessible.


# 1.75 15-May-2020 skrll

Use __diagused


# 1.74 15-May-2020 tnn

fix non-diag build


# 1.73 14-May-2020 skrll

Use MUTEX_NODEBUG for PV locks as is commonly done. OK ryo.


# 1.72 13-May-2020 jmcneill

Implement pmap_extract_coherency


Revision tags: bouyer-xenpvh-base2 phil-wifi-20200421 bouyer-xenpvh-base1
# 1.71 18-Apr-2020 skrll

PMAP_DEBUG has been deleted on arm


# 1.70 13-Apr-2020 maxv

Add support for Branch Target Identification (BTI).

On the executable pages that have the GP (Guarded Page) bit, the semantic
of the "br" and "blr" instructions is changed: the CPU expects the first
instruction of the jump/call target to be "bti", and faults if it isn't.

We add the GP bit on the kernel .text pages (and incidentally the .rodata
pages, but we don't care). The compiler adds a "bti c" instruction at the
beginning of each C function. We modify the ENTRY() macros to manually add
"bti c" in the asm functions.

cpuswitch.S needs a specific change: with "br x27" the CPU expects "bti j",
which is bad because the functions begin with "bti c"; switch to "br x16",
for the CPU to accept "bti c".

BTI helps defend against JOP/COP. Tested on Qemu.


Revision tags: phil-wifi-20200411 bouyer-xenpvh-base
# 1.69 08-Apr-2020 ryo

branches: 1.69.2;
use PMAP_PAGE_INIT() to initialize mutex in pmap_page.

VM_MDPAGE_INIT() in pmap_free_pdp() had initialized pp_flags,
so it unintentionally cleared PMAP_PAGE_FLAGS_PV_TRACKED.
use PMAP_PAGE_INIT to avoid using PMAP_PAGE_FLAGS_PV_TRACKED.

pointed out by tnn@, thanks


Revision tags: phil-wifi-20200406
# 1.68 14-Mar-2020 ad

pmap_remove_all(): Return a boolean value to indicate the behaviour. If
true, all mappings have been removed, the pmap is totally cleared out, and
UVM can then avoid doing the work to call pmap_remove() for each map entry.
If false, either nothing has been done, or some helpful arch-specific voodoo
has taken place.


Revision tags: is-mlppp-base
# 1.67 02-Mar-2020 ryo

oops, fix incorrect usage of daif_enable() in my previous commit.


# 1.66 29-Feb-2020 ryo

Fix pmap to work correctly with tagged addresses

- when fault, untag from address before passing to uvm/pmap functions
- pmap_extract() checks more strictly and consider the address tag


# 1.65 29-Feb-2020 ryo

use pmapboot_enter_range()


Revision tags: ad-namecache-base3
# 1.64 10-Feb-2020 ryo

use LIST(3) instead of TAILQ(3) to save one word in struct vm_page and struct pmap.

pointed out by riastradh@. thanks


# 1.63 03-Feb-2020 ryo

add support pmap_pv(9)

Patch originally from jmcneill@. thanks


# 1.62 03-Feb-2020 ryo

separate struct vm_page_md into vm_page_md and pmap_page
for preparation pmap_pv(9)


Revision tags: ad-namecache-base2 ad-namecache-base1
# 1.61 09-Jan-2020 ryo

fix behaviour mmap()/mprotect() when passed only PROT_EXEC.

when mmap()/mprotect() with only PROT_EXEC, syscall will be successful,
but the page actually hadn't been mapped.
it should be mapped with PROT_READ|PROT_EXEC implicitly. (r-x)


Revision tags: ad-namecache-base
# 1.60 30-Dec-2019 skrll

branches: 1.60.2;
Update pmap_map_chunk to allow L[12] block mappings and L3 page mappings


# 1.59 30-Dec-2019 skrll

Remove unnecessary brackets and unwrap a conditional. Same code before
and after.


# 1.58 28-Dec-2019 jmcneill

Do not use Early Write Acknowledge for PCIe I/O and config space.


# 1.57 27-Dec-2019 jmcneill

Enable early write acknowledge for device memory mappings.


# 1.56 19-Dec-2019 skrll

G/C kasan_shadow_map call in pmap_enter

pmap_growkernel calls kasan_shadow_map for KVA


# 1.55 18-Dec-2019 ryo

atomic_add_16() is not used in pmap.c anymore. no need decl here.


# 1.54 18-Dec-2019 ryo

space to tab


# 1.53 14-Dec-2019 skrll

Fix build... wire_count probably doesn't need atomics


# 1.52 13-Dec-2019 skrll

Fix KASAN support by calling kasan_shadow_map in pmap_growkernel


# 1.51 10-Dec-2019 ad

pg->phys_addr -> VM_PAGE_TO_PHYS(pg)


Revision tags: phil-wifi-20191119
# 1.50 14-Nov-2019 maxv

Mark several kASan functions with __nothing, to avoid annoying #ifdefs.
Same as kCSan and kMSan.


# 1.49 14-Nov-2019 maxv

Don't include "opt_kasan.h" when there's already <sys/asan.h> included.


# 1.48 29-Oct-2019 maya

Define PMAP_NEED_PROCWR, providing strategically placed i-cache
synchronization where just-changed memory is about to be executed.

Fixes SIGILLs seen when running Mono 6 on QEMU Cortex-A57.

ok ryo


# 1.47 22-Sep-2019 jmcneill

Disable translation table walks using TTBR0 while changing its value and
when deactivating a pmap. Fixes stability issues on Ampere eMAG CPUs.


# 1.46 20-Sep-2019 ryo

ref/mod bit should be set according to 'flags' argument, not 'prot'. r1.44 was incomplete.


# 1.45 13-Sep-2019 ryo

In pmap_devmap_bootstrap(), cpu_earlydevice_va_p() must not return true until *all* devmap tables have been enabled.
console mapping may be present in the last table.


# 1.44 07-Sep-2019 ryo

- remove incorrect KASSERT. mmap(2) with prot=PROT_WRITE calls pmap_enter(..., PROT_WRITE) internally.
- fix to update page reference flags when only PROT_WRITE or PROT_EXECUTE specified


# 1.43 15-Aug-2019 skrll

Make pmap_db_pte_print more terse so it's quicker on serial consoles


# 1.42 12-Aug-2019 skrll

Use PMAP_DEV in DEVMAP_ENTRY rather than pmap_map_chunk. It's clearer and
means pmap_map_chunk can be made to map other memory types.


Revision tags: netbsd-9-base phil-wifi-20190609
# 1.41 17-May-2019 mrg

branches: 1.41.2;
apply some __diagused.


Revision tags: isaki-audio2-base
# 1.40 08-Apr-2019 ryo

- free empty page tables pages if reach a certain usage.
- need to lock at removing an old pg (_pmap_remove_pv) in _pmap_enter()


# 1.39 06-Apr-2019 ryo

Fix race conditions about pmap_page_protect() and pmap_enter().

while handling same PTE by these functions in same time, there
is a critical path that the number of valid PTEs and wire_count
are inconsistent, and it caused KASSERT.
Need to hold a pv_lock while modifying them.


# 1.38 20-Mar-2019 ryo

spinkle __printflike(), and use PRIxxx


# 1.37 19-Mar-2019 ryo

- add ddb command "machine ttbr" to dump MMU tables.
- tidy up descriptions, usages and messages.


# 1.36 19-Mar-2019 ryo

- free L1-L3 pages that has been emptied by pmap_remove().
- if no memories, pmap_enter will return correctly ENOMEM if PMAP_CANFAIL, or wait until available any memories if !PMAP_CANFAIL.

These changes improves the stability when we use a huge virtual memory spaces with mmap.


# 1.35 06-Feb-2019 ryo

improve pmap_remove
- don't lock/unlock per page in pmap_remove()
- speedup pte lookup for continuous addresses
- bring out pool_cache_put(&_pmap_pv_pool, pv) from lock/unlock section


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226
# 1.34 21-Dec-2018 ryo

- add workaround for Cavium ThunderX errata 27456.
- add cpufuncs table in cpu_info. each cpu clusters may have different erratum. (e.g. big.LITTLE)


Revision tags: pgoyette-compat-1126
# 1.33 01-Nov-2018 maxv

Add kASan support for aarch64. Stack tracking needs more investigation
and will come in a separate commit.

Reviewed by ryo@ jmcneill@ skrll@.


# 1.32 31-Oct-2018 ryo

invalidate icache correctly.
l3pte_executable() should be used for only valid pte.


Revision tags: pgoyette-compat-1020
# 1.31 18-Oct-2018 skrll

Provide generic start code that assumes the MMU is off and caches are
disabled as per the linux booting protocol for ARMv6 and ARMv7 boards.
u-boot image type should be changed to 'linux' for correct behaviour.

The new start code builds a minimal "bootstrap" L1PT with cached access
disabled and uses the same table for all processors. AP startup is
performed in less steps and more code is written in C.

The bootstrap tables and stack are placed into an (orphaned) section
"_init_memory" which is given to uvm when it is no longer used.

Various kernels have been converted to use this code and tested. Some
boards were provided by TNF. Thanks!

The GENERIC kernel now boots on boards using the TEGRA, SUNXI and EXYNOS
kernels. The GENERIC kernel will also work on RPI2 using u-boot.

Thanks to martin@ and aymeric@ for testing on parallella and nanosoc
respectively


# 1.30 14-Oct-2018 skrll

Use __nothing


# 1.29 12-Oct-2018 ryo

add initial support of COMPAT_NETBSD32 on AArch64.
arm ELF32 EABI binaries could be execute in AArch32 state on AArch64. A32 THUMB mode is not supported yet.


# 1.28 12-Oct-2018 ryo

- cleanup checking address ranges with IN_RANGE macro
- change PM_ADDR_CHECK macro to KASSERTMSG
- restore fast lookup cases with IN_RANGE macro for pmap_extract changed in my previous commit.


# 1.27 12-Oct-2018 ryo

rewrite pmap_pte_lookup() to share similar code.


# 1.26 04-Oct-2018 ryo

cleanup locore, and changed the way to map memories during boot.
- add functions bootpage_enter() and bootpage_alloc() to adapt various layout
of physical memory map. especially for 64bit physical memory layout.
pmapboot_alloc() allocates pagetable pages from _end[].
- changed to map only the required amount for PA=VA identity mapping
(kernel image, UART device, and FDT blob) with L2_BLOCK(2Mbyte).
- changing page permission for kernel image, and making KSEG mapping are done
at cpu_kernel_vm_init() instead of at locore.
- optimize PTE entries with PTE Contiguous bit. it is enabled on devmap only for now.

reviewed by skrll@, thanks.


# 1.25 04-Oct-2018 ryo

* define LX_BLKPAG_{OS,ATTR}_* for OS dependent PTE attributes in pmap.h
* cleanup macros


Revision tags: pgoyette-compat-0930
# 1.24 17-Sep-2018 ryo

delete debug printf and KASSERT.


# 1.23 10-Sep-2018 maxv

Replace KDASSERT by panic.


# 1.22 10-Sep-2018 maxv

Rename _pmap_alloc_pdp -> pmap_alloc_pdp, and make it public.


# 1.21 10-Sep-2018 ryo

cleanup aarch64 mpstart and fdt bootstrap
* arm_cpu_hatch_arg is a bad idea. avoid serializing CPU startup, and eliminate arm_cpu_hatch_arg.
in mpstart, resolve own cpu index using array of cpu_mpidr[] (aarch64)
* add support fdt enable-method "spin-table"
* add support fdt enable-method "brcm,bcm2836-smp" (for 32bit RaspberryPi)
* use arm_fdt_cpu_bootstrap() instead of psci_fdt_bootstrap()
* rename "arm/fdt/psci_fdt.h" to "arm/fdt/psci_fdtvar.h" because of conflict of include file for needs-flag
* add devmap for cpu spin-table of raspberrypi3/aarch64
* no need to force hatch APs for raspberrypi3/arm32 ifndef MULTIPROCESSOR.
* fix to work pmap_extract(kerneltext/data/bss) even if before calling pmap_bootstrap

idea to use cpu_mpidr[] by jmcneill@. reviewd by skrll@. thanks.


Revision tags: pgoyette-compat-0906
# 1.20 27-Aug-2018 ryo

need to add VM_PROT_READ when pmap_kenter_pa(va, pa, VM_PROT_WRITE, 0) or pmap_kenter_pa(va, pa, VM_PROT_EXECUTE, 0).
VM_PROT_READ is treated as an access permission inernally.


# 1.19 11-Aug-2018 ryo

change to minimum invalidation of TLB.
specifying not only va but also asid, and not invalidate L0-L2 entry using tlbi_*_ll() if needed.


# 1.18 10-Aug-2018 ryo

treat kernel-exec attr and user-exec attr separately.
kernel cannot execute userland exec page, and user cannot execute kernel page.


# 1.17 06-Aug-2018 ryo

set kernel text/rodata readonly by default.
add function db_write_text() for setting ddb breakpoint.


# 1.16 31-Jul-2018 skrll

Define and use VPRINTF


Revision tags: pgoyette-compat-0728
# 1.15 27-Jul-2018 ryo

changes of pmap.c r1.13 seems to be unstable.
In order to invalidate icache, not to invalidate all icache,
but temporary to make the page writable and invalidate target address only.


# 1.14 24-Jul-2018 ryo

don't call pool_cache_put with locking pmap. pool_cache_put call pmap_kenter_pa internally.
(pool_cache_put_paddr -> pool_cache_put_slow -> pool_get -> pmap_kenter_pa)


# 1.13 23-Jul-2018 ryo

* fix icache invalidations.
* "ic ivau" (aarch64_icache_sync_range) with VA generates permission fault in some situations, therefore use KSEG address for now.


# 1.12 23-Jul-2018 ryo

rather than using flags to resolve nested locks, reserve pool_cache before locking.


# 1.11 21-Jul-2018 ryo

* avoid deadlock. mutex_owned() works only for adaptive lock, therefore we cannot use it for spinlock...
* add more NULL check
* clear pte when pmap_enter() fails


# 1.10 17-Jul-2018 ryo

Use __debugused


# 1.9 17-Jul-2018 christos

Add missing casts, remove unused variables.


# 1.8 09-Jul-2018 ryo

need locks in pmap_kremove() and pmap_fault_fixup()


Revision tags: phil-wifi-base pgoyette-compat-0625 pgoyette-compat-0521
# 1.7 20-May-2018 ryo

branches: 1.7.2;
pmap_enter() must update modified/referenced flags by 'flags' not 'prot'.


# 1.6 16-May-2018 ryo

Fix memory leak. it was leaking one page every pmap_create().
pm->pm_vmlist must be initialized before calling _pmap_alloc_pdp().


Revision tags: pgoyette-compat-0502
# 1.5 29-Apr-2018 ryo

fix KASSERT panic. pv_entry may not be exists in pvlist when pmap_remove().


# 1.4 29-Apr-2018 ryo

delete unused code


# 1.3 27-Apr-2018 ryo

fix instability behavior of bufcache on aarch64.
* fix to return correct ref/mod when PMAP_WIRED.
* changed to keep wired flags in pte instead of pv_entry, and cleanup.


Revision tags: pgoyette-compat-0422 pgoyette-compat-0415 pgoyette-compat-0407
# 1.2 01-Apr-2018 ryo

Add initial support for ARMv8 (AARCH64) (by nisimura@ and ryo@)

- sys/arch/evbarm64 is gone and integrated into sys/arch/evbarm. (by skrll@)
- add support fdt. evbarm/conf/GENERIC64 fdt (bcm2837,sunxi,tegra) based generic 64bit kernel config. (by skrll@, jmcneill@)


Revision tags: netbsd-8-2-RELEASE netbsd-8-1-RELEASE netbsd-8-1-RC1 netbsd-7-2-RELEASE netbsd-8-0-RELEASE netbsd-8-0-RC2 netbsd-8-0-RC1 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 netbsd-7-1-2-RELEASE pgoyette-compat-base netbsd-7-1-1-RELEASE tls-maxphys-base-20171202 matt-nb8-mediatek-base nick-nhusb-base-20170825 perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base pgoyette-localcount-20170320 netbsd-7-1-RELEASE netbsd-7-1-RC2 nick-nhusb-base-20170204 netbsd-7-nhusb-base-20170116 bouyer-socketcan-base pgoyette-localcount-20170107 netbsd-7-1-RC1 nick-nhusb-base-20161204 pgoyette-localcount-20161104 netbsd-7-0-2-RELEASE nick-nhusb-base-20161004 localcount-20160914 netbsd-7-nhusb-base pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907 nick-nhusb-base-20160529 netbsd-7-0-1-RELEASE nick-nhusb-base-20160422 nick-nhusb-base-20160319 nick-nhusb-base-20151226 netbsd-7-0-RELEASE nick-nhusb-base-20150921 netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 nick-nhusb-base-20150606 nick-nhusb-base-20150406 nick-nhusb-base tls-maxphys-base netbsd-7-base
# 1.1 10-Aug-2014 matt

branches: 1.1.4; 1.1.28;
Preliminary files for AARCH64 (64-bit ARM) support.
Enough for a distribution build.


Revision tags: thorpej-futex-base
# 1.94 01-Nov-2020 jmcneill

No need to disable translation table walks in pmap_activate().


# 1.93 22-Oct-2020 skrll

Use the isb macro - missed in previous commit


# 1.92 22-Oct-2020 skrll

Use the dmb/dsb/isb macros... if nothing else they're all now consistent
about the "memory" assembler contraint.

No binary change


# 1.91 28-Sep-2020 skrll

Only set pmap_devmap_bootstrap_done if something gets mapped.

Think acpi_platform_devmap


# 1.90 19-Sep-2020 skrll

Make __md_palloc pmap agnostic (think sys/uvm/pmap)


# 1.89 14-Sep-2020 ryo

PID_MAX is just an initial value (soft maximum). Don't use it for CTASSERT.
defined __HAVE_CPU_MAXPROC to use function cpu_maxproc().

pointed out by mrg@, thanks.


# 1.88 06-Sep-2020 ryo

Fix panic caused by modload. http://mail-index.netbsd.org/port-arm/2020/08/30/msg006960.html

The address space reserved for modules may not be mapped in L1-L3.


# 1.87 14-Aug-2020 skrll

Whitespace


# 1.86 12-Aug-2020 skrll

Part IV of ad's performance improvements for aarch64

- Implement pmap_growkernel(), and update kernel pmap's stats with atomics.

- Then, pmap_kenter_pa() and pmap_kremove() no longer need to allocate
memory nor take pm_lock, because they only modify L3 PTEs.

- Then, pm_lock and pp_lock can be adaptive mutexes at IPL_NONE which are
cheaper than spin mutexes.

- Take the pmap's lock in pmap_extract() if not the kernel's pmap, otherwise
pmap_extract() might see inconsistent state.


# 1.85 09-Aug-2020 skrll

Fix another UVMHIST so it doesn't use %s


# 1.84 16-Jul-2020 skrll

pmapboot_enter simplication
- bootpage_alloc in asm becomes pmapboot_pagealloc in C
- PMAPBOOT_ENTER_NOBLOCK is removed as it's not used
- PMAPBOOT_ENTER_NOOVERWRITE is removed as it's now always on
- physpage_allocator argument is removed as it's always
pmapboot_pagealloc
- Support for EARLYCONS without CONSADDR is removed so that the identity
map for CONSADDR is always known.

For the assembly files:
2 files changed, 40 insertions(+), 89 deletions(-)

LGTM ryo


# 1.83 04-Jul-2020 rin

Use tlen for temporary length variable instead of l, which is usually
used for struct lwp *.

No binary changes.


# 1.82 02-Jul-2020 rin

pmap_procwr(): sync icache even if p != curproc. This fixes applications
like GDB for arm32, that rewrite text of other process.

Thanks to ryo@ for discussion.


# 1.81 02-Jul-2020 rin

Set uvmexp.ncolors appropriately, which is required for some CPU
models with VIPT icache.

Otherwise, alias in virtual address results in inconsistent results,
at least for applications that rewrite text of other process, e.g.,
GDB for arm32.

Also, this hopefully fixes other unexpected failures due to alias.

Confirmed that there's no observable regression in performance;
difference in ``time make -j8'' for GENERIC64 kernel on BCM2837
with and without setting uvmexp.ncolors is within 0.1%.

Thanks to ryo@ for discussion.


# 1.80 27-Jun-2020 rin

Fix typo in name of evcnt(4) counter.


# 1.79 24-Jun-2020 ryo

Fix bug with incorrect range calculation when doing icache sync.
This is called by sysarch(ARM_SYNC_ICACHE) from aarch32 (compat_netbsd32) emul process.

pointed out by rin@, thanks.

XXX pullup-9


# 1.78 14-Jun-2020 ad

- Fix a lock order reversal in pmap_page_protect().

- Make sure pmap is always locked when updating stats; atomics no longer
needed to do that.

- Remove unneeded traversal of pv list in pmap_enter_pv().

- Shrink struct vm_page from 136 to 128 bytes (cache line sized) and struct
pv_entry from 48 to 32 bytes (power of 2 sized).

- Embed a pv_entry in each vm_page. This means PV entries don't need to
be allocated for private anonymous memory / COW pages / most UBC mappings.
Dynamic PV entries are then used only for stuff like shared libraries and
shared memory.

Proposed on port-arm@.


# 1.77 10-Jun-2020 ad

- Wired/resident stats shouldn't covered by PMAPCOUNTERS.
- Rename need_update_pv -> need_enter_pv.

Ok ryo@


# 1.76 01-Jun-2020 ryo

no need to make the PTE writable to do icache_sync, enough to accessible.


# 1.75 15-May-2020 skrll

Use __diagused


# 1.74 15-May-2020 tnn

fix non-diag build


# 1.73 14-May-2020 skrll

Use MUTEX_NODEBUG for PV locks as is commonly done. OK ryo.


# 1.72 13-May-2020 jmcneill

Implement pmap_extract_coherency


Revision tags: bouyer-xenpvh-base2 phil-wifi-20200421 bouyer-xenpvh-base1
# 1.71 18-Apr-2020 skrll

PMAP_DEBUG has been deleted on arm


# 1.70 13-Apr-2020 maxv

Add support for Branch Target Identification (BTI).

On the executable pages that have the GP (Guarded Page) bit, the semantic
of the "br" and "blr" instructions is changed: the CPU expects the first
instruction of the jump/call target to be "bti", and faults if it isn't.

We add the GP bit on the kernel .text pages (and incidentally the .rodata
pages, but we don't care). The compiler adds a "bti c" instruction at the
beginning of each C function. We modify the ENTRY() macros to manually add
"bti c" in the asm functions.

cpuswitch.S needs a specific change: with "br x27" the CPU expects "bti j",
which is bad because the functions begin with "bti c"; switch to "br x16",
for the CPU to accept "bti c".

BTI helps defend against JOP/COP. Tested on Qemu.


Revision tags: phil-wifi-20200411 bouyer-xenpvh-base
# 1.69 08-Apr-2020 ryo

branches: 1.69.2;
use PMAP_PAGE_INIT() to initialize mutex in pmap_page.

VM_MDPAGE_INIT() in pmap_free_pdp() had initialized pp_flags,
so it unintentionally cleared PMAP_PAGE_FLAGS_PV_TRACKED.
use PMAP_PAGE_INIT to avoid using PMAP_PAGE_FLAGS_PV_TRACKED.

pointed out by tnn@, thanks


Revision tags: phil-wifi-20200406
# 1.68 14-Mar-2020 ad

pmap_remove_all(): Return a boolean value to indicate the behaviour. If
true, all mappings have been removed, the pmap is totally cleared out, and
UVM can then avoid doing the work to call pmap_remove() for each map entry.
If false, either nothing has been done, or some helpful arch-specific voodoo
has taken place.


Revision tags: is-mlppp-base
# 1.67 02-Mar-2020 ryo

oops, fix incorrect usage of daif_enable() in my previous commit.


# 1.66 29-Feb-2020 ryo

Fix pmap to work correctly with tagged addresses

- when fault, untag from address before passing to uvm/pmap functions
- pmap_extract() checks more strictly and consider the address tag


# 1.65 29-Feb-2020 ryo

use pmapboot_enter_range()


Revision tags: ad-namecache-base3
# 1.64 10-Feb-2020 ryo

use LIST(3) instead of TAILQ(3) to save one word in struct vm_page and struct pmap.

pointed out by riastradh@. thanks


# 1.63 03-Feb-2020 ryo

add support pmap_pv(9)

Patch originally from jmcneill@. thanks


# 1.62 03-Feb-2020 ryo

separate struct vm_page_md into vm_page_md and pmap_page
for preparation pmap_pv(9)


Revision tags: ad-namecache-base2 ad-namecache-base1
# 1.61 09-Jan-2020 ryo

fix behaviour mmap()/mprotect() when passed only PROT_EXEC.

when mmap()/mprotect() with only PROT_EXEC, syscall will be successful,
but the page actually hadn't been mapped.
it should be mapped with PROT_READ|PROT_EXEC implicitly. (r-x)


Revision tags: ad-namecache-base
# 1.60 30-Dec-2019 skrll

branches: 1.60.2;
Update pmap_map_chunk to allow L[12] block mappings and L3 page mappings


# 1.59 30-Dec-2019 skrll

Remove unnecessary brackets and unwrap a conditional. Same code before
and after.


# 1.58 28-Dec-2019 jmcneill

Do not use Early Write Acknowledge for PCIe I/O and config space.


# 1.57 27-Dec-2019 jmcneill

Enable early write acknowledge for device memory mappings.


# 1.56 19-Dec-2019 skrll

G/C kasan_shadow_map call in pmap_enter

pmap_growkernel calls kasan_shadow_map for KVA


# 1.55 18-Dec-2019 ryo

atomic_add_16() is not used in pmap.c anymore. no need decl here.


# 1.54 18-Dec-2019 ryo

space to tab


# 1.53 14-Dec-2019 skrll

Fix build... wire_count probably doesn't need atomics


# 1.52 13-Dec-2019 skrll

Fix KASAN support by calling kasan_shadow_map in pmap_growkernel


# 1.51 10-Dec-2019 ad

pg->phys_addr -> VM_PAGE_TO_PHYS(pg)


Revision tags: phil-wifi-20191119
# 1.50 14-Nov-2019 maxv

Mark several kASan functions with __nothing, to avoid annoying #ifdefs.
Same as kCSan and kMSan.


# 1.49 14-Nov-2019 maxv

Don't include "opt_kasan.h" when there's already <sys/asan.h> included.


# 1.48 29-Oct-2019 maya

Define PMAP_NEED_PROCWR, providing strategically placed i-cache
synchronization where just-changed memory is about to be executed.

Fixes SIGILLs seen when running Mono 6 on QEMU Cortex-A57.

ok ryo


# 1.47 22-Sep-2019 jmcneill

Disable translation table walks using TTBR0 while changing its value and
when deactivating a pmap. Fixes stability issues on Ampere eMAG CPUs.


# 1.46 20-Sep-2019 ryo

ref/mod bit should be set according to 'flags' argument, not 'prot'. r1.44 was incomplete.


# 1.45 13-Sep-2019 ryo

In pmap_devmap_bootstrap(), cpu_earlydevice_va_p() must not return true until *all* devmap tables have been enabled.
console mapping may be present in the last table.


# 1.44 07-Sep-2019 ryo

- remove incorrect KASSERT. mmap(2) with prot=PROT_WRITE calls pmap_enter(..., PROT_WRITE) internally.
- fix to update page reference flags when only PROT_WRITE or PROT_EXECUTE specified


# 1.43 15-Aug-2019 skrll

Make pmap_db_pte_print more terse so it's quicker on serial consoles


# 1.42 12-Aug-2019 skrll

Use PMAP_DEV in DEVMAP_ENTRY rather than pmap_map_chunk. It's clearer and
means pmap_map_chunk can be made to map other memory types.


Revision tags: netbsd-9-base phil-wifi-20190609
# 1.41 17-May-2019 mrg

branches: 1.41.2;
apply some __diagused.


Revision tags: isaki-audio2-base
# 1.40 08-Apr-2019 ryo

- free empty page tables pages if reach a certain usage.
- need to lock at removing an old pg (_pmap_remove_pv) in _pmap_enter()


# 1.39 06-Apr-2019 ryo

Fix race conditions about pmap_page_protect() and pmap_enter().

while handling same PTE by these functions in same time, there
is a critical path that the number of valid PTEs and wire_count
are inconsistent, and it caused KASSERT.
Need to hold a pv_lock while modifying them.


# 1.38 20-Mar-2019 ryo

spinkle __printflike(), and use PRIxxx


# 1.37 19-Mar-2019 ryo

- add ddb command "machine ttbr" to dump MMU tables.
- tidy up descriptions, usages and messages.


# 1.36 19-Mar-2019 ryo

- free L1-L3 pages that has been emptied by pmap_remove().
- if no memories, pmap_enter will return correctly ENOMEM if PMAP_CANFAIL, or wait until available any memories if !PMAP_CANFAIL.

These changes improves the stability when we use a huge virtual memory spaces with mmap.


# 1.35 06-Feb-2019 ryo

improve pmap_remove
- don't lock/unlock per page in pmap_remove()
- speedup pte lookup for continuous addresses
- bring out pool_cache_put(&_pmap_pv_pool, pv) from lock/unlock section


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226
# 1.34 21-Dec-2018 ryo

- add workaround for Cavium ThunderX errata 27456.
- add cpufuncs table in cpu_info. each cpu clusters may have different erratum. (e.g. big.LITTLE)


Revision tags: pgoyette-compat-1126
# 1.33 01-Nov-2018 maxv

Add kASan support for aarch64. Stack tracking needs more investigation
and will come in a separate commit.

Reviewed by ryo@ jmcneill@ skrll@.


# 1.32 31-Oct-2018 ryo

invalidate icache correctly.
l3pte_executable() should be used for only valid pte.


Revision tags: pgoyette-compat-1020
# 1.31 18-Oct-2018 skrll

Provide generic start code that assumes the MMU is off and caches are
disabled as per the linux booting protocol for ARMv6 and ARMv7 boards.
u-boot image type should be changed to 'linux' for correct behaviour.

The new start code builds a minimal "bootstrap" L1PT with cached access
disabled and uses the same table for all processors. AP startup is
performed in less steps and more code is written in C.

The bootstrap tables and stack are placed into an (orphaned) section
"_init_memory" which is given to uvm when it is no longer used.

Various kernels have been converted to use this code and tested. Some
boards were provided by TNF. Thanks!

The GENERIC kernel now boots on boards using the TEGRA, SUNXI and EXYNOS
kernels. The GENERIC kernel will also work on RPI2 using u-boot.

Thanks to martin@ and aymeric@ for testing on parallella and nanosoc
respectively


# 1.30 14-Oct-2018 skrll

Use __nothing


# 1.29 12-Oct-2018 ryo

add initial support of COMPAT_NETBSD32 on AArch64.
arm ELF32 EABI binaries could be execute in AArch32 state on AArch64. A32 THUMB mode is not supported yet.


# 1.28 12-Oct-2018 ryo

- cleanup checking address ranges with IN_RANGE macro
- change PM_ADDR_CHECK macro to KASSERTMSG
- restore fast lookup cases with IN_RANGE macro for pmap_extract changed in my previous commit.


# 1.27 12-Oct-2018 ryo

rewrite pmap_pte_lookup() to share similar code.


# 1.26 04-Oct-2018 ryo

cleanup locore, and changed the way to map memories during boot.
- add functions bootpage_enter() and bootpage_alloc() to adapt various layout
of physical memory map. especially for 64bit physical memory layout.
pmapboot_alloc() allocates pagetable pages from _end[].
- changed to map only the required amount for PA=VA identity mapping
(kernel image, UART device, and FDT blob) with L2_BLOCK(2Mbyte).
- changing page permission for kernel image, and making KSEG mapping are done
at cpu_kernel_vm_init() instead of at locore.
- optimize PTE entries with PTE Contiguous bit. it is enabled on devmap only for now.

reviewed by skrll@, thanks.


# 1.25 04-Oct-2018 ryo

* define LX_BLKPAG_{OS,ATTR}_* for OS dependent PTE attributes in pmap.h
* cleanup macros


Revision tags: pgoyette-compat-0930
# 1.24 17-Sep-2018 ryo

delete debug printf and KASSERT.


# 1.23 10-Sep-2018 maxv

Replace KDASSERT by panic.


# 1.22 10-Sep-2018 maxv

Rename _pmap_alloc_pdp -> pmap_alloc_pdp, and make it public.


# 1.21 10-Sep-2018 ryo

cleanup aarch64 mpstart and fdt bootstrap
* arm_cpu_hatch_arg is a bad idea. avoid serializing CPU startup, and eliminate arm_cpu_hatch_arg.
in mpstart, resolve own cpu index using array of cpu_mpidr[] (aarch64)
* add support fdt enable-method "spin-table"
* add support fdt enable-method "brcm,bcm2836-smp" (for 32bit RaspberryPi)
* use arm_fdt_cpu_bootstrap() instead of psci_fdt_bootstrap()
* rename "arm/fdt/psci_fdt.h" to "arm/fdt/psci_fdtvar.h" because of conflict of include file for needs-flag
* add devmap for cpu spin-table of raspberrypi3/aarch64
* no need to force hatch APs for raspberrypi3/arm32 ifndef MULTIPROCESSOR.
* fix to work pmap_extract(kerneltext/data/bss) even if before calling pmap_bootstrap

idea to use cpu_mpidr[] by jmcneill@. reviewd by skrll@. thanks.


Revision tags: pgoyette-compat-0906
# 1.20 27-Aug-2018 ryo

need to add VM_PROT_READ when pmap_kenter_pa(va, pa, VM_PROT_WRITE, 0) or pmap_kenter_pa(va, pa, VM_PROT_EXECUTE, 0).
VM_PROT_READ is treated as an access permission inernally.


# 1.19 11-Aug-2018 ryo

change to minimum invalidation of TLB.
specifying not only va but also asid, and not invalidate L0-L2 entry using tlbi_*_ll() if needed.


# 1.18 10-Aug-2018 ryo

treat kernel-exec attr and user-exec attr separately.
kernel cannot execute userland exec page, and user cannot execute kernel page.


# 1.17 06-Aug-2018 ryo

set kernel text/rodata readonly by default.
add function db_write_text() for setting ddb breakpoint.


# 1.16 31-Jul-2018 skrll

Define and use VPRINTF


Revision tags: pgoyette-compat-0728
# 1.15 27-Jul-2018 ryo

changes of pmap.c r1.13 seems to be unstable.
In order to invalidate icache, not to invalidate all icache,
but temporary to make the page writable and invalidate target address only.


# 1.14 24-Jul-2018 ryo

don't call pool_cache_put with locking pmap. pool_cache_put call pmap_kenter_pa internally.
(pool_cache_put_paddr -> pool_cache_put_slow -> pool_get -> pmap_kenter_pa)


# 1.13 23-Jul-2018 ryo

* fix icache invalidations.
* "ic ivau" (aarch64_icache_sync_range) with VA generates permission fault in some situations, therefore use KSEG address for now.


# 1.12 23-Jul-2018 ryo

rather than using flags to resolve nested locks, reserve pool_cache before locking.


# 1.11 21-Jul-2018 ryo

* avoid deadlock. mutex_owned() works only for adaptive lock, therefore we cannot use it for spinlock...
* add more NULL check
* clear pte when pmap_enter() fails


# 1.10 17-Jul-2018 ryo

Use __debugused


# 1.9 17-Jul-2018 christos

Add missing casts, remove unused variables.


# 1.8 09-Jul-2018 ryo

need locks in pmap_kremove() and pmap_fault_fixup()


Revision tags: phil-wifi-base pgoyette-compat-0625 pgoyette-compat-0521
# 1.7 20-May-2018 ryo

branches: 1.7.2;
pmap_enter() must update modified/referenced flags by 'flags' not 'prot'.


# 1.6 16-May-2018 ryo

Fix memory leak. it was leaking one page every pmap_create().
pm->pm_vmlist must be initialized before calling _pmap_alloc_pdp().


Revision tags: pgoyette-compat-0502
# 1.5 29-Apr-2018 ryo

fix KASSERT panic. pv_entry may not be exists in pvlist when pmap_remove().


# 1.4 29-Apr-2018 ryo

delete unused code


# 1.3 27-Apr-2018 ryo

fix instability behavior of bufcache on aarch64.
* fix to return correct ref/mod when PMAP_WIRED.
* changed to keep wired flags in pte instead of pv_entry, and cleanup.


Revision tags: pgoyette-compat-0422 pgoyette-compat-0415 pgoyette-compat-0407
# 1.2 01-Apr-2018 ryo

Add initial support for ARMv8 (AARCH64) (by nisimura@ and ryo@)

- sys/arch/evbarm64 is gone and integrated into sys/arch/evbarm. (by skrll@)
- add support fdt. evbarm/conf/GENERIC64 fdt (bcm2837,sunxi,tegra) based generic 64bit kernel config. (by skrll@, jmcneill@)


Revision tags: netbsd-8-2-RELEASE netbsd-8-1-RELEASE netbsd-8-1-RC1 netbsd-7-2-RELEASE netbsd-8-0-RELEASE netbsd-8-0-RC2 netbsd-8-0-RC1 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 netbsd-7-1-2-RELEASE pgoyette-compat-base netbsd-7-1-1-RELEASE tls-maxphys-base-20171202 matt-nb8-mediatek-base nick-nhusb-base-20170825 perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base pgoyette-localcount-20170320 netbsd-7-1-RELEASE netbsd-7-1-RC2 nick-nhusb-base-20170204 netbsd-7-nhusb-base-20170116 bouyer-socketcan-base pgoyette-localcount-20170107 netbsd-7-1-RC1 nick-nhusb-base-20161204 pgoyette-localcount-20161104 netbsd-7-0-2-RELEASE nick-nhusb-base-20161004 localcount-20160914 netbsd-7-nhusb-base pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907 nick-nhusb-base-20160529 netbsd-7-0-1-RELEASE nick-nhusb-base-20160422 nick-nhusb-base-20160319 nick-nhusb-base-20151226 netbsd-7-0-RELEASE nick-nhusb-base-20150921 netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 nick-nhusb-base-20150606 nick-nhusb-base-20150406 nick-nhusb-base tls-maxphys-base netbsd-7-base
# 1.1 10-Aug-2014 matt

branches: 1.1.4; 1.1.28;
Preliminary files for AARCH64 (64-bit ARM) support.
Enough for a distribution build.


# 1.93 22-Oct-2020 skrll

Use the isb macro - missed in previous commit


# 1.92 22-Oct-2020 skrll

Use the dmb/dsb/isb macros... if nothing else they're all now consistent
about the "memory" assembler contraint.

No binary change


# 1.91 28-Sep-2020 skrll

Only set pmap_devmap_bootstrap_done if something gets mapped.

Think acpi_platform_devmap


# 1.90 19-Sep-2020 skrll

Make __md_palloc pmap agnostic (think sys/uvm/pmap)


# 1.89 14-Sep-2020 ryo

PID_MAX is just an initial value (soft maximum). Don't use it for CTASSERT.
defined __HAVE_CPU_MAXPROC to use function cpu_maxproc().

pointed out by mrg@, thanks.


# 1.88 06-Sep-2020 ryo

Fix panic caused by modload. http://mail-index.netbsd.org/port-arm/2020/08/30/msg006960.html

The address space reserved for modules may not be mapped in L1-L3.


# 1.87 14-Aug-2020 skrll

Whitespace


# 1.86 12-Aug-2020 skrll

Part IV of ad's performance improvements for aarch64

- Implement pmap_growkernel(), and update kernel pmap's stats with atomics.

- Then, pmap_kenter_pa() and pmap_kremove() no longer need to allocate
memory nor take pm_lock, because they only modify L3 PTEs.

- Then, pm_lock and pp_lock can be adaptive mutexes at IPL_NONE which are
cheaper than spin mutexes.

- Take the pmap's lock in pmap_extract() if not the kernel's pmap, otherwise
pmap_extract() might see inconsistent state.


# 1.85 09-Aug-2020 skrll

Fix another UVMHIST so it doesn't use %s


# 1.84 16-Jul-2020 skrll

pmapboot_enter simplication
- bootpage_alloc in asm becomes pmapboot_pagealloc in C
- PMAPBOOT_ENTER_NOBLOCK is removed as it's not used
- PMAPBOOT_ENTER_NOOVERWRITE is removed as it's now always on
- physpage_allocator argument is removed as it's always
pmapboot_pagealloc
- Support for EARLYCONS without CONSADDR is removed so that the identity
map for CONSADDR is always known.

For the assembly files:
2 files changed, 40 insertions(+), 89 deletions(-)

LGTM ryo


# 1.83 04-Jul-2020 rin

Use tlen for temporary length variable instead of l, which is usually
used for struct lwp *.

No binary changes.


# 1.82 02-Jul-2020 rin

pmap_procwr(): sync icache even if p != curproc. This fixes applications
like GDB for arm32, that rewrite text of other process.

Thanks to ryo@ for discussion.


# 1.81 02-Jul-2020 rin

Set uvmexp.ncolors appropriately, which is required for some CPU
models with VIPT icache.

Otherwise, alias in virtual address results in inconsistent results,
at least for applications that rewrite text of other process, e.g.,
GDB for arm32.

Also, this hopefully fixes other unexpected failures due to alias.

Confirmed that there's no observable regression in performance;
difference in ``time make -j8'' for GENERIC64 kernel on BCM2837
with and without setting uvmexp.ncolors is within 0.1%.

Thanks to ryo@ for discussion.


# 1.80 27-Jun-2020 rin

Fix typo in name of evcnt(4) counter.


# 1.79 24-Jun-2020 ryo

Fix bug with incorrect range calculation when doing icache sync.
This is called by sysarch(ARM_SYNC_ICACHE) from aarch32 (compat_netbsd32) emul process.

pointed out by rin@, thanks.

XXX pullup-9


# 1.78 14-Jun-2020 ad

- Fix a lock order reversal in pmap_page_protect().

- Make sure pmap is always locked when updating stats; atomics no longer
needed to do that.

- Remove unneeded traversal of pv list in pmap_enter_pv().

- Shrink struct vm_page from 136 to 128 bytes (cache line sized) and struct
pv_entry from 48 to 32 bytes (power of 2 sized).

- Embed a pv_entry in each vm_page. This means PV entries don't need to
be allocated for private anonymous memory / COW pages / most UBC mappings.
Dynamic PV entries are then used only for stuff like shared libraries and
shared memory.

Proposed on port-arm@.


# 1.77 10-Jun-2020 ad

- Wired/resident stats shouldn't covered by PMAPCOUNTERS.
- Rename need_update_pv -> need_enter_pv.

Ok ryo@


# 1.76 01-Jun-2020 ryo

no need to make the PTE writable to do icache_sync, enough to accessible.


# 1.75 15-May-2020 skrll

Use __diagused


# 1.74 15-May-2020 tnn

fix non-diag build


# 1.73 14-May-2020 skrll

Use MUTEX_NODEBUG for PV locks as is commonly done. OK ryo.


# 1.72 13-May-2020 jmcneill

Implement pmap_extract_coherency


Revision tags: bouyer-xenpvh-base2 phil-wifi-20200421 bouyer-xenpvh-base1
# 1.71 18-Apr-2020 skrll

PMAP_DEBUG has been deleted on arm


# 1.70 13-Apr-2020 maxv

Add support for Branch Target Identification (BTI).

On the executable pages that have the GP (Guarded Page) bit, the semantic
of the "br" and "blr" instructions is changed: the CPU expects the first
instruction of the jump/call target to be "bti", and faults if it isn't.

We add the GP bit on the kernel .text pages (and incidentally the .rodata
pages, but we don't care). The compiler adds a "bti c" instruction at the
beginning of each C function. We modify the ENTRY() macros to manually add
"bti c" in the asm functions.

cpuswitch.S needs a specific change: with "br x27" the CPU expects "bti j",
which is bad because the functions begin with "bti c"; switch to "br x16",
for the CPU to accept "bti c".

BTI helps defend against JOP/COP. Tested on Qemu.


Revision tags: phil-wifi-20200411 bouyer-xenpvh-base
# 1.69 08-Apr-2020 ryo

branches: 1.69.2;
use PMAP_PAGE_INIT() to initialize mutex in pmap_page.

VM_MDPAGE_INIT() in pmap_free_pdp() had initialized pp_flags,
so it unintentionally cleared PMAP_PAGE_FLAGS_PV_TRACKED.
use PMAP_PAGE_INIT to avoid using PMAP_PAGE_FLAGS_PV_TRACKED.

pointed out by tnn@, thanks


Revision tags: phil-wifi-20200406
# 1.68 14-Mar-2020 ad

pmap_remove_all(): Return a boolean value to indicate the behaviour. If
true, all mappings have been removed, the pmap is totally cleared out, and
UVM can then avoid doing the work to call pmap_remove() for each map entry.
If false, either nothing has been done, or some helpful arch-specific voodoo
has taken place.


Revision tags: is-mlppp-base
# 1.67 02-Mar-2020 ryo

oops, fix incorrect usage of daif_enable() in my previous commit.


# 1.66 29-Feb-2020 ryo

Fix pmap to work correctly with tagged addresses

- when fault, untag from address before passing to uvm/pmap functions
- pmap_extract() checks more strictly and consider the address tag


# 1.65 29-Feb-2020 ryo

use pmapboot_enter_range()


Revision tags: ad-namecache-base3
# 1.64 10-Feb-2020 ryo

use LIST(3) instead of TAILQ(3) to save one word in struct vm_page and struct pmap.

pointed out by riastradh@. thanks


# 1.63 03-Feb-2020 ryo

add support pmap_pv(9)

Patch originally from jmcneill@. thanks


# 1.62 03-Feb-2020 ryo

separate struct vm_page_md into vm_page_md and pmap_page
for preparation pmap_pv(9)


Revision tags: ad-namecache-base2 ad-namecache-base1
# 1.61 09-Jan-2020 ryo

fix behaviour mmap()/mprotect() when passed only PROT_EXEC.

when mmap()/mprotect() with only PROT_EXEC, syscall will be successful,
but the page actually hadn't been mapped.
it should be mapped with PROT_READ|PROT_EXEC implicitly. (r-x)


Revision tags: ad-namecache-base
# 1.60 30-Dec-2019 skrll

branches: 1.60.2;
Update pmap_map_chunk to allow L[12] block mappings and L3 page mappings


# 1.59 30-Dec-2019 skrll

Remove unnecessary brackets and unwrap a conditional. Same code before
and after.


# 1.58 28-Dec-2019 jmcneill

Do not use Early Write Acknowledge for PCIe I/O and config space.


# 1.57 27-Dec-2019 jmcneill

Enable early write acknowledge for device memory mappings.


# 1.56 19-Dec-2019 skrll

G/C kasan_shadow_map call in pmap_enter

pmap_growkernel calls kasan_shadow_map for KVA


# 1.55 18-Dec-2019 ryo

atomic_add_16() is not used in pmap.c anymore. no need decl here.


# 1.54 18-Dec-2019 ryo

space to tab


# 1.53 14-Dec-2019 skrll

Fix build... wire_count probably doesn't need atomics


# 1.52 13-Dec-2019 skrll

Fix KASAN support by calling kasan_shadow_map in pmap_growkernel


# 1.51 10-Dec-2019 ad

pg->phys_addr -> VM_PAGE_TO_PHYS(pg)


Revision tags: phil-wifi-20191119
# 1.50 14-Nov-2019 maxv

Mark several kASan functions with __nothing, to avoid annoying #ifdefs.
Same as kCSan and kMSan.


# 1.49 14-Nov-2019 maxv

Don't include "opt_kasan.h" when there's already <sys/asan.h> included.


# 1.48 29-Oct-2019 maya

Define PMAP_NEED_PROCWR, providing strategically placed i-cache
synchronization where just-changed memory is about to be executed.

Fixes SIGILLs seen when running Mono 6 on QEMU Cortex-A57.

ok ryo


# 1.47 22-Sep-2019 jmcneill

Disable translation table walks using TTBR0 while changing its value and
when deactivating a pmap. Fixes stability issues on Ampere eMAG CPUs.


# 1.46 20-Sep-2019 ryo

ref/mod bit should be set according to 'flags' argument, not 'prot'. r1.44 was incomplete.


# 1.45 13-Sep-2019 ryo

In pmap_devmap_bootstrap(), cpu_earlydevice_va_p() must not return true until *all* devmap tables have been enabled.
console mapping may be present in the last table.


# 1.44 07-Sep-2019 ryo

- remove incorrect KASSERT. mmap(2) with prot=PROT_WRITE calls pmap_enter(..., PROT_WRITE) internally.
- fix to update page reference flags when only PROT_WRITE or PROT_EXECUTE specified


# 1.43 15-Aug-2019 skrll

Make pmap_db_pte_print more terse so it's quicker on serial consoles


# 1.42 12-Aug-2019 skrll

Use PMAP_DEV in DEVMAP_ENTRY rather than pmap_map_chunk. It's clearer and
means pmap_map_chunk can be made to map other memory types.


Revision tags: netbsd-9-base phil-wifi-20190609
# 1.41 17-May-2019 mrg

branches: 1.41.2;
apply some __diagused.


Revision tags: isaki-audio2-base
# 1.40 08-Apr-2019 ryo

- free empty page tables pages if reach a certain usage.
- need to lock at removing an old pg (_pmap_remove_pv) in _pmap_enter()


# 1.39 06-Apr-2019 ryo

Fix race conditions about pmap_page_protect() and pmap_enter().

while handling same PTE by these functions in same time, there
is a critical path that the number of valid PTEs and wire_count
are inconsistent, and it caused KASSERT.
Need to hold a pv_lock while modifying them.


# 1.38 20-Mar-2019 ryo

spinkle __printflike(), and use PRIxxx


# 1.37 19-Mar-2019 ryo

- add ddb command "machine ttbr" to dump MMU tables.
- tidy up descriptions, usages and messages.


# 1.36 19-Mar-2019 ryo

- free L1-L3 pages that has been emptied by pmap_remove().
- if no memories, pmap_enter will return correctly ENOMEM if PMAP_CANFAIL, or wait until available any memories if !PMAP_CANFAIL.

These changes improves the stability when we use a huge virtual memory spaces with mmap.


# 1.35 06-Feb-2019 ryo

improve pmap_remove
- don't lock/unlock per page in pmap_remove()
- speedup pte lookup for continuous addresses
- bring out pool_cache_put(&_pmap_pv_pool, pv) from lock/unlock section


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226
# 1.34 21-Dec-2018 ryo

- add workaround for Cavium ThunderX errata 27456.
- add cpufuncs table in cpu_info. each cpu clusters may have different erratum. (e.g. big.LITTLE)


Revision tags: pgoyette-compat-1126
# 1.33 01-Nov-2018 maxv

Add kASan support for aarch64. Stack tracking needs more investigation
and will come in a separate commit.

Reviewed by ryo@ jmcneill@ skrll@.


# 1.32 31-Oct-2018 ryo

invalidate icache correctly.
l3pte_executable() should be used for only valid pte.


Revision tags: pgoyette-compat-1020
# 1.31 18-Oct-2018 skrll

Provide generic start code that assumes the MMU is off and caches are
disabled as per the linux booting protocol for ARMv6 and ARMv7 boards.
u-boot image type should be changed to 'linux' for correct behaviour.

The new start code builds a minimal "bootstrap" L1PT with cached access
disabled and uses the same table for all processors. AP startup is
performed in less steps and more code is written in C.

The bootstrap tables and stack are placed into an (orphaned) section
"_init_memory" which is given to uvm when it is no longer used.

Various kernels have been converted to use this code and tested. Some
boards were provided by TNF. Thanks!

The GENERIC kernel now boots on boards using the TEGRA, SUNXI and EXYNOS
kernels. The GENERIC kernel will also work on RPI2 using u-boot.

Thanks to martin@ and aymeric@ for testing on parallella and nanosoc
respectively


# 1.30 14-Oct-2018 skrll

Use __nothing


# 1.29 12-Oct-2018 ryo

add initial support of COMPAT_NETBSD32 on AArch64.
arm ELF32 EABI binaries could be execute in AArch32 state on AArch64. A32 THUMB mode is not supported yet.


# 1.28 12-Oct-2018 ryo

- cleanup checking address ranges with IN_RANGE macro
- change PM_ADDR_CHECK macro to KASSERTMSG
- restore fast lookup cases with IN_RANGE macro for pmap_extract changed in my previous commit.


# 1.27 12-Oct-2018 ryo

rewrite pmap_pte_lookup() to share similar code.


# 1.26 04-Oct-2018 ryo

cleanup locore, and changed the way to map memories during boot.
- add functions bootpage_enter() and bootpage_alloc() to adapt various layout
of physical memory map. especially for 64bit physical memory layout.
pmapboot_alloc() allocates pagetable pages from _end[].
- changed to map only the required amount for PA=VA identity mapping
(kernel image, UART device, and FDT blob) with L2_BLOCK(2Mbyte).
- changing page permission for kernel image, and making KSEG mapping are done
at cpu_kernel_vm_init() instead of at locore.
- optimize PTE entries with PTE Contiguous bit. it is enabled on devmap only for now.

reviewed by skrll@, thanks.


# 1.25 04-Oct-2018 ryo

* define LX_BLKPAG_{OS,ATTR}_* for OS dependent PTE attributes in pmap.h
* cleanup macros


Revision tags: pgoyette-compat-0930
# 1.24 17-Sep-2018 ryo

delete debug printf and KASSERT.


# 1.23 10-Sep-2018 maxv

Replace KDASSERT by panic.


# 1.22 10-Sep-2018 maxv

Rename _pmap_alloc_pdp -> pmap_alloc_pdp, and make it public.


# 1.21 10-Sep-2018 ryo

cleanup aarch64 mpstart and fdt bootstrap
* arm_cpu_hatch_arg is a bad idea. avoid serializing CPU startup, and eliminate arm_cpu_hatch_arg.
in mpstart, resolve own cpu index using array of cpu_mpidr[] (aarch64)
* add support fdt enable-method "spin-table"
* add support fdt enable-method "brcm,bcm2836-smp" (for 32bit RaspberryPi)
* use arm_fdt_cpu_bootstrap() instead of psci_fdt_bootstrap()
* rename "arm/fdt/psci_fdt.h" to "arm/fdt/psci_fdtvar.h" because of conflict of include file for needs-flag
* add devmap for cpu spin-table of raspberrypi3/aarch64
* no need to force hatch APs for raspberrypi3/arm32 ifndef MULTIPROCESSOR.
* fix to work pmap_extract(kerneltext/data/bss) even if before calling pmap_bootstrap

idea to use cpu_mpidr[] by jmcneill@. reviewd by skrll@. thanks.


Revision tags: pgoyette-compat-0906
# 1.20 27-Aug-2018 ryo

need to add VM_PROT_READ when pmap_kenter_pa(va, pa, VM_PROT_WRITE, 0) or pmap_kenter_pa(va, pa, VM_PROT_EXECUTE, 0).
VM_PROT_READ is treated as an access permission inernally.


# 1.19 11-Aug-2018 ryo

change to minimum invalidation of TLB.
specifying not only va but also asid, and not invalidate L0-L2 entry using tlbi_*_ll() if needed.


# 1.18 10-Aug-2018 ryo

treat kernel-exec attr and user-exec attr separately.
kernel cannot execute userland exec page, and user cannot execute kernel page.


# 1.17 06-Aug-2018 ryo

set kernel text/rodata readonly by default.
add function db_write_text() for setting ddb breakpoint.


# 1.16 31-Jul-2018 skrll

Define and use VPRINTF


Revision tags: pgoyette-compat-0728
# 1.15 27-Jul-2018 ryo

changes of pmap.c r1.13 seems to be unstable.
In order to invalidate icache, not to invalidate all icache,
but temporary to make the page writable and invalidate target address only.


# 1.14 24-Jul-2018 ryo

don't call pool_cache_put with locking pmap. pool_cache_put call pmap_kenter_pa internally.
(pool_cache_put_paddr -> pool_cache_put_slow -> pool_get -> pmap_kenter_pa)


# 1.13 23-Jul-2018 ryo

* fix icache invalidations.
* "ic ivau" (aarch64_icache_sync_range) with VA generates permission fault in some situations, therefore use KSEG address for now.


# 1.12 23-Jul-2018 ryo

rather than using flags to resolve nested locks, reserve pool_cache before locking.


# 1.11 21-Jul-2018 ryo

* avoid deadlock. mutex_owned() works only for adaptive lock, therefore we cannot use it for spinlock...
* add more NULL check
* clear pte when pmap_enter() fails


# 1.10 17-Jul-2018 ryo

Use __debugused


# 1.9 17-Jul-2018 christos

Add missing casts, remove unused variables.


# 1.8 09-Jul-2018 ryo

need locks in pmap_kremove() and pmap_fault_fixup()


Revision tags: phil-wifi-base pgoyette-compat-0625 pgoyette-compat-0521
# 1.7 20-May-2018 ryo

branches: 1.7.2;
pmap_enter() must update modified/referenced flags by 'flags' not 'prot'.


# 1.6 16-May-2018 ryo

Fix memory leak. it was leaking one page every pmap_create().
pm->pm_vmlist must be initialized before calling _pmap_alloc_pdp().


Revision tags: pgoyette-compat-0502
# 1.5 29-Apr-2018 ryo

fix KASSERT panic. pv_entry may not be exists in pvlist when pmap_remove().


# 1.4 29-Apr-2018 ryo

delete unused code


# 1.3 27-Apr-2018 ryo

fix instability behavior of bufcache on aarch64.
* fix to return correct ref/mod when PMAP_WIRED.
* changed to keep wired flags in pte instead of pv_entry, and cleanup.


Revision tags: pgoyette-compat-0422 pgoyette-compat-0415 pgoyette-compat-0407
# 1.2 01-Apr-2018 ryo

Add initial support for ARMv8 (AARCH64) (by nisimura@ and ryo@)

- sys/arch/evbarm64 is gone and integrated into sys/arch/evbarm. (by skrll@)
- add support fdt. evbarm/conf/GENERIC64 fdt (bcm2837,sunxi,tegra) based generic 64bit kernel config. (by skrll@, jmcneill@)


Revision tags: netbsd-8-2-RELEASE netbsd-8-1-RELEASE netbsd-8-1-RC1 netbsd-7-2-RELEASE netbsd-8-0-RELEASE netbsd-8-0-RC2 netbsd-8-0-RC1 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 netbsd-7-1-2-RELEASE pgoyette-compat-base netbsd-7-1-1-RELEASE tls-maxphys-base-20171202 matt-nb8-mediatek-base nick-nhusb-base-20170825 perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base pgoyette-localcount-20170320 netbsd-7-1-RELEASE netbsd-7-1-RC2 nick-nhusb-base-20170204 netbsd-7-nhusb-base-20170116 bouyer-socketcan-base pgoyette-localcount-20170107 netbsd-7-1-RC1 nick-nhusb-base-20161204 pgoyette-localcount-20161104 netbsd-7-0-2-RELEASE nick-nhusb-base-20161004 localcount-20160914 netbsd-7-nhusb-base pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907 nick-nhusb-base-20160529 netbsd-7-0-1-RELEASE nick-nhusb-base-20160422 nick-nhusb-base-20160319 nick-nhusb-base-20151226 netbsd-7-0-RELEASE nick-nhusb-base-20150921 netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 nick-nhusb-base-20150606 nick-nhusb-base-20150406 nick-nhusb-base tls-maxphys-base netbsd-7-base
# 1.1 10-Aug-2014 matt

branches: 1.1.4; 1.1.28;
Preliminary files for AARCH64 (64-bit ARM) support.
Enough for a distribution build.


# 1.91 28-Sep-2020 skrll

Only set pmap_devmap_bootstrap_done if something gets mapped.

Think acpi_platform_devmap


# 1.90 19-Sep-2020 skrll

Make __md_palloc pmap agnostic (think sys/uvm/pmap)


# 1.89 14-Sep-2020 ryo

PID_MAX is just an initial value (soft maximum). Don't use it for CTASSERT.
defined __HAVE_CPU_MAXPROC to use function cpu_maxproc().

pointed out by mrg@, thanks.


# 1.88 06-Sep-2020 ryo

Fix panic caused by modload. http://mail-index.netbsd.org/port-arm/2020/08/30/msg006960.html

The address space reserved for modules may not be mapped in L1-L3.


# 1.87 14-Aug-2020 skrll

Whitespace


# 1.86 12-Aug-2020 skrll

Part IV of ad's performance improvements for aarch64

- Implement pmap_growkernel(), and update kernel pmap's stats with atomics.

- Then, pmap_kenter_pa() and pmap_kremove() no longer need to allocate
memory nor take pm_lock, because they only modify L3 PTEs.

- Then, pm_lock and pp_lock can be adaptive mutexes at IPL_NONE which are
cheaper than spin mutexes.

- Take the pmap's lock in pmap_extract() if not the kernel's pmap, otherwise
pmap_extract() might see inconsistent state.


# 1.85 09-Aug-2020 skrll

Fix another UVMHIST so it doesn't use %s


# 1.84 16-Jul-2020 skrll

pmapboot_enter simplication
- bootpage_alloc in asm becomes pmapboot_pagealloc in C
- PMAPBOOT_ENTER_NOBLOCK is removed as it's not used
- PMAPBOOT_ENTER_NOOVERWRITE is removed as it's now always on
- physpage_allocator argument is removed as it's always
pmapboot_pagealloc
- Support for EARLYCONS without CONSADDR is removed so that the identity
map for CONSADDR is always known.

For the assembly files:
2 files changed, 40 insertions(+), 89 deletions(-)

LGTM ryo


# 1.83 04-Jul-2020 rin

Use tlen for temporary length variable instead of l, which is usually
used for struct lwp *.

No binary changes.


# 1.82 02-Jul-2020 rin

pmap_procwr(): sync icache even if p != curproc. This fixes applications
like GDB for arm32, that rewrite text of other process.

Thanks to ryo@ for discussion.


# 1.81 02-Jul-2020 rin

Set uvmexp.ncolors appropriately, which is required for some CPU
models with VIPT icache.

Otherwise, alias in virtual address results in inconsistent results,
at least for applications that rewrite text of other process, e.g.,
GDB for arm32.

Also, this hopefully fixes other unexpected failures due to alias.

Confirmed that there's no observable regression in performance;
difference in ``time make -j8'' for GENERIC64 kernel on BCM2837
with and without setting uvmexp.ncolors is within 0.1%.

Thanks to ryo@ for discussion.


# 1.80 27-Jun-2020 rin

Fix typo in name of evcnt(4) counter.


# 1.79 24-Jun-2020 ryo

Fix bug with incorrect range calculation when doing icache sync.
This is called by sysarch(ARM_SYNC_ICACHE) from aarch32 (compat_netbsd32) emul process.

pointed out by rin@, thanks.

XXX pullup-9


# 1.78 14-Jun-2020 ad

- Fix a lock order reversal in pmap_page_protect().

- Make sure pmap is always locked when updating stats; atomics no longer
needed to do that.

- Remove unneeded traversal of pv list in pmap_enter_pv().

- Shrink struct vm_page from 136 to 128 bytes (cache line sized) and struct
pv_entry from 48 to 32 bytes (power of 2 sized).

- Embed a pv_entry in each vm_page. This means PV entries don't need to
be allocated for private anonymous memory / COW pages / most UBC mappings.
Dynamic PV entries are then used only for stuff like shared libraries and
shared memory.

Proposed on port-arm@.


# 1.77 10-Jun-2020 ad

- Wired/resident stats shouldn't covered by PMAPCOUNTERS.
- Rename need_update_pv -> need_enter_pv.

Ok ryo@


# 1.76 01-Jun-2020 ryo

no need to make the PTE writable to do icache_sync, enough to accessible.


# 1.75 15-May-2020 skrll

Use __diagused


# 1.74 15-May-2020 tnn

fix non-diag build


# 1.73 14-May-2020 skrll

Use MUTEX_NODEBUG for PV locks as is commonly done. OK ryo.


# 1.72 13-May-2020 jmcneill

Implement pmap_extract_coherency


Revision tags: bouyer-xenpvh-base2 phil-wifi-20200421 bouyer-xenpvh-base1
# 1.71 18-Apr-2020 skrll

PMAP_DEBUG has been deleted on arm


# 1.70 13-Apr-2020 maxv

Add support for Branch Target Identification (BTI).

On the executable pages that have the GP (Guarded Page) bit, the semantic
of the "br" and "blr" instructions is changed: the CPU expects the first
instruction of the jump/call target to be "bti", and faults if it isn't.

We add the GP bit on the kernel .text pages (and incidentally the .rodata
pages, but we don't care). The compiler adds a "bti c" instruction at the
beginning of each C function. We modify the ENTRY() macros to manually add
"bti c" in the asm functions.

cpuswitch.S needs a specific change: with "br x27" the CPU expects "bti j",
which is bad because the functions begin with "bti c"; switch to "br x16",
for the CPU to accept "bti c".

BTI helps defend against JOP/COP. Tested on Qemu.


Revision tags: phil-wifi-20200411 bouyer-xenpvh-base
# 1.69 08-Apr-2020 ryo

branches: 1.69.2;
use PMAP_PAGE_INIT() to initialize mutex in pmap_page.

VM_MDPAGE_INIT() in pmap_free_pdp() had initialized pp_flags,
so it unintentionally cleared PMAP_PAGE_FLAGS_PV_TRACKED.
use PMAP_PAGE_INIT to avoid using PMAP_PAGE_FLAGS_PV_TRACKED.

pointed out by tnn@, thanks


Revision tags: phil-wifi-20200406
# 1.68 14-Mar-2020 ad

pmap_remove_all(): Return a boolean value to indicate the behaviour. If
true, all mappings have been removed, the pmap is totally cleared out, and
UVM can then avoid doing the work to call pmap_remove() for each map entry.
If false, either nothing has been done, or some helpful arch-specific voodoo
has taken place.


Revision tags: is-mlppp-base
# 1.67 02-Mar-2020 ryo

oops, fix incorrect usage of daif_enable() in my previous commit.


# 1.66 29-Feb-2020 ryo

Fix pmap to work correctly with tagged addresses

- when fault, untag from address before passing to uvm/pmap functions
- pmap_extract() checks more strictly and consider the address tag


# 1.65 29-Feb-2020 ryo

use pmapboot_enter_range()


Revision tags: ad-namecache-base3
# 1.64 10-Feb-2020 ryo

use LIST(3) instead of TAILQ(3) to save one word in struct vm_page and struct pmap.

pointed out by riastradh@. thanks


# 1.63 03-Feb-2020 ryo

add support pmap_pv(9)

Patch originally from jmcneill@. thanks


# 1.62 03-Feb-2020 ryo

separate struct vm_page_md into vm_page_md and pmap_page
for preparation pmap_pv(9)


Revision tags: ad-namecache-base2 ad-namecache-base1
# 1.61 09-Jan-2020 ryo

fix behaviour mmap()/mprotect() when passed only PROT_EXEC.

when mmap()/mprotect() with only PROT_EXEC, syscall will be successful,
but the page actually hadn't been mapped.
it should be mapped with PROT_READ|PROT_EXEC implicitly. (r-x)


Revision tags: ad-namecache-base
# 1.60 30-Dec-2019 skrll

branches: 1.60.2;
Update pmap_map_chunk to allow L[12] block mappings and L3 page mappings


# 1.59 30-Dec-2019 skrll

Remove unnecessary brackets and unwrap a conditional. Same code before
and after.


# 1.58 28-Dec-2019 jmcneill

Do not use Early Write Acknowledge for PCIe I/O and config space.


# 1.57 27-Dec-2019 jmcneill

Enable early write acknowledge for device memory mappings.


# 1.56 19-Dec-2019 skrll

G/C kasan_shadow_map call in pmap_enter

pmap_growkernel calls kasan_shadow_map for KVA


# 1.55 18-Dec-2019 ryo

atomic_add_16() is not used in pmap.c anymore. no need decl here.


# 1.54 18-Dec-2019 ryo

space to tab


# 1.53 14-Dec-2019 skrll

Fix build... wire_count probably doesn't need atomics


# 1.52 13-Dec-2019 skrll

Fix KASAN support by calling kasan_shadow_map in pmap_growkernel


# 1.51 10-Dec-2019 ad

pg->phys_addr -> VM_PAGE_TO_PHYS(pg)


Revision tags: phil-wifi-20191119
# 1.50 14-Nov-2019 maxv

Mark several kASan functions with __nothing, to avoid annoying #ifdefs.
Same as kCSan and kMSan.


# 1.49 14-Nov-2019 maxv

Don't include "opt_kasan.h" when there's already <sys/asan.h> included.


# 1.48 29-Oct-2019 maya

Define PMAP_NEED_PROCWR, providing strategically placed i-cache
synchronization where just-changed memory is about to be executed.

Fixes SIGILLs seen when running Mono 6 on QEMU Cortex-A57.

ok ryo


# 1.47 22-Sep-2019 jmcneill

Disable translation table walks using TTBR0 while changing its value and
when deactivating a pmap. Fixes stability issues on Ampere eMAG CPUs.


# 1.46 20-Sep-2019 ryo

ref/mod bit should be set according to 'flags' argument, not 'prot'. r1.44 was incomplete.


# 1.45 13-Sep-2019 ryo

In pmap_devmap_bootstrap(), cpu_earlydevice_va_p() must not return true until *all* devmap tables have been enabled.
console mapping may be present in the last table.


# 1.44 07-Sep-2019 ryo

- remove incorrect KASSERT. mmap(2) with prot=PROT_WRITE calls pmap_enter(..., PROT_WRITE) internally.
- fix to update page reference flags when only PROT_WRITE or PROT_EXECUTE specified


# 1.43 15-Aug-2019 skrll

Make pmap_db_pte_print more terse so it's quicker on serial consoles


# 1.42 12-Aug-2019 skrll

Use PMAP_DEV in DEVMAP_ENTRY rather than pmap_map_chunk. It's clearer and
means pmap_map_chunk can be made to map other memory types.


Revision tags: netbsd-9-base phil-wifi-20190609
# 1.41 17-May-2019 mrg

branches: 1.41.2;
apply some __diagused.


Revision tags: isaki-audio2-base
# 1.40 08-Apr-2019 ryo

- free empty page tables pages if reach a certain usage.
- need to lock at removing an old pg (_pmap_remove_pv) in _pmap_enter()


# 1.39 06-Apr-2019 ryo

Fix race conditions about pmap_page_protect() and pmap_enter().

while handling same PTE by these functions in same time, there
is a critical path that the number of valid PTEs and wire_count
are inconsistent, and it caused KASSERT.
Need to hold a pv_lock while modifying them.


# 1.38 20-Mar-2019 ryo

spinkle __printflike(), and use PRIxxx


# 1.37 19-Mar-2019 ryo

- add ddb command "machine ttbr" to dump MMU tables.
- tidy up descriptions, usages and messages.


# 1.36 19-Mar-2019 ryo

- free L1-L3 pages that has been emptied by pmap_remove().
- if no memories, pmap_enter will return correctly ENOMEM if PMAP_CANFAIL, or wait until available any memories if !PMAP_CANFAIL.

These changes improves the stability when we use a huge virtual memory spaces with mmap.


# 1.35 06-Feb-2019 ryo

improve pmap_remove
- don't lock/unlock per page in pmap_remove()
- speedup pte lookup for continuous addresses
- bring out pool_cache_put(&_pmap_pv_pool, pv) from lock/unlock section


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226
# 1.34 21-Dec-2018 ryo

- add workaround for Cavium ThunderX errata 27456.
- add cpufuncs table in cpu_info. each cpu clusters may have different erratum. (e.g. big.LITTLE)


Revision tags: pgoyette-compat-1126
# 1.33 01-Nov-2018 maxv

Add kASan support for aarch64. Stack tracking needs more investigation
and will come in a separate commit.

Reviewed by ryo@ jmcneill@ skrll@.


# 1.32 31-Oct-2018 ryo

invalidate icache correctly.
l3pte_executable() should be used for only valid pte.


Revision tags: pgoyette-compat-1020
# 1.31 18-Oct-2018 skrll

Provide generic start code that assumes the MMU is off and caches are
disabled as per the linux booting protocol for ARMv6 and ARMv7 boards.
u-boot image type should be changed to 'linux' for correct behaviour.

The new start code builds a minimal "bootstrap" L1PT with cached access
disabled and uses the same table for all processors. AP startup is
performed in less steps and more code is written in C.

The bootstrap tables and stack are placed into an (orphaned) section
"_init_memory" which is given to uvm when it is no longer used.

Various kernels have been converted to use this code and tested. Some
boards were provided by TNF. Thanks!

The GENERIC kernel now boots on boards using the TEGRA, SUNXI and EXYNOS
kernels. The GENERIC kernel will also work on RPI2 using u-boot.

Thanks to martin@ and aymeric@ for testing on parallella and nanosoc
respectively


# 1.30 14-Oct-2018 skrll

Use __nothing


# 1.29 12-Oct-2018 ryo

add initial support of COMPAT_NETBSD32 on AArch64.
arm ELF32 EABI binaries could be execute in AArch32 state on AArch64. A32 THUMB mode is not supported yet.


# 1.28 12-Oct-2018 ryo

- cleanup checking address ranges with IN_RANGE macro
- change PM_ADDR_CHECK macro to KASSERTMSG
- restore fast lookup cases with IN_RANGE macro for pmap_extract changed in my previous commit.


# 1.27 12-Oct-2018 ryo

rewrite pmap_pte_lookup() to share similar code.


# 1.26 04-Oct-2018 ryo

cleanup locore, and changed the way to map memories during boot.
- add functions bootpage_enter() and bootpage_alloc() to adapt various layout
of physical memory map. especially for 64bit physical memory layout.
pmapboot_alloc() allocates pagetable pages from _end[].
- changed to map only the required amount for PA=VA identity mapping
(kernel image, UART device, and FDT blob) with L2_BLOCK(2Mbyte).
- changing page permission for kernel image, and making KSEG mapping are done
at cpu_kernel_vm_init() instead of at locore.
- optimize PTE entries with PTE Contiguous bit. it is enabled on devmap only for now.

reviewed by skrll@, thanks.


# 1.25 04-Oct-2018 ryo

* define LX_BLKPAG_{OS,ATTR}_* for OS dependent PTE attributes in pmap.h
* cleanup macros


Revision tags: pgoyette-compat-0930
# 1.24 17-Sep-2018 ryo

delete debug printf and KASSERT.


# 1.23 10-Sep-2018 maxv

Replace KDASSERT by panic.


# 1.22 10-Sep-2018 maxv

Rename _pmap_alloc_pdp -> pmap_alloc_pdp, and make it public.


# 1.21 10-Sep-2018 ryo

cleanup aarch64 mpstart and fdt bootstrap
* arm_cpu_hatch_arg is a bad idea. avoid serializing CPU startup, and eliminate arm_cpu_hatch_arg.
in mpstart, resolve own cpu index using array of cpu_mpidr[] (aarch64)
* add support fdt enable-method "spin-table"
* add support fdt enable-method "brcm,bcm2836-smp" (for 32bit RaspberryPi)
* use arm_fdt_cpu_bootstrap() instead of psci_fdt_bootstrap()
* rename "arm/fdt/psci_fdt.h" to "arm/fdt/psci_fdtvar.h" because of conflict of include file for needs-flag
* add devmap for cpu spin-table of raspberrypi3/aarch64
* no need to force hatch APs for raspberrypi3/arm32 ifndef MULTIPROCESSOR.
* fix to work pmap_extract(kerneltext/data/bss) even if before calling pmap_bootstrap

idea to use cpu_mpidr[] by jmcneill@. reviewd by skrll@. thanks.


Revision tags: pgoyette-compat-0906
# 1.20 27-Aug-2018 ryo

need to add VM_PROT_READ when pmap_kenter_pa(va, pa, VM_PROT_WRITE, 0) or pmap_kenter_pa(va, pa, VM_PROT_EXECUTE, 0).
VM_PROT_READ is treated as an access permission inernally.


# 1.19 11-Aug-2018 ryo

change to minimum invalidation of TLB.
specifying not only va but also asid, and not invalidate L0-L2 entry using tlbi_*_ll() if needed.


# 1.18 10-Aug-2018 ryo

treat kernel-exec attr and user-exec attr separately.
kernel cannot execute userland exec page, and user cannot execute kernel page.


# 1.17 06-Aug-2018 ryo

set kernel text/rodata readonly by default.
add function db_write_text() for setting ddb breakpoint.


# 1.16 31-Jul-2018 skrll

Define and use VPRINTF


Revision tags: pgoyette-compat-0728
# 1.15 27-Jul-2018 ryo

changes of pmap.c r1.13 seems to be unstable.
In order to invalidate icache, not to invalidate all icache,
but temporary to make the page writable and invalidate target address only.


# 1.14 24-Jul-2018 ryo

don't call pool_cache_put with locking pmap. pool_cache_put call pmap_kenter_pa internally.
(pool_cache_put_paddr -> pool_cache_put_slow -> pool_get -> pmap_kenter_pa)


# 1.13 23-Jul-2018 ryo

* fix icache invalidations.
* "ic ivau" (aarch64_icache_sync_range) with VA generates permission fault in some situations, therefore use KSEG address for now.


# 1.12 23-Jul-2018 ryo

rather than using flags to resolve nested locks, reserve pool_cache before locking.


# 1.11 21-Jul-2018 ryo

* avoid deadlock. mutex_owned() works only for adaptive lock, therefore we cannot use it for spinlock...
* add more NULL check
* clear pte when pmap_enter() fails


# 1.10 17-Jul-2018 ryo

Use __debugused


# 1.9 17-Jul-2018 christos

Add missing casts, remove unused variables.


# 1.8 09-Jul-2018 ryo

need locks in pmap_kremove() and pmap_fault_fixup()


Revision tags: phil-wifi-base pgoyette-compat-0625 pgoyette-compat-0521
# 1.7 20-May-2018 ryo

branches: 1.7.2;
pmap_enter() must update modified/referenced flags by 'flags' not 'prot'.


# 1.6 16-May-2018 ryo

Fix memory leak. it was leaking one page every pmap_create().
pm->pm_vmlist must be initialized before calling _pmap_alloc_pdp().


Revision tags: pgoyette-compat-0502
# 1.5 29-Apr-2018 ryo

fix KASSERT panic. pv_entry may not be exists in pvlist when pmap_remove().


# 1.4 29-Apr-2018 ryo

delete unused code


# 1.3 27-Apr-2018 ryo

fix instability behavior of bufcache on aarch64.
* fix to return correct ref/mod when PMAP_WIRED.
* changed to keep wired flags in pte instead of pv_entry, and cleanup.


Revision tags: pgoyette-compat-0422 pgoyette-compat-0415 pgoyette-compat-0407
# 1.2 01-Apr-2018 ryo

Add initial support for ARMv8 (AARCH64) (by nisimura@ and ryo@)

- sys/arch/evbarm64 is gone and integrated into sys/arch/evbarm. (by skrll@)
- add support fdt. evbarm/conf/GENERIC64 fdt (bcm2837,sunxi,tegra) based generic 64bit kernel config. (by skrll@, jmcneill@)


Revision tags: netbsd-8-2-RELEASE netbsd-8-1-RELEASE netbsd-8-1-RC1 netbsd-7-2-RELEASE netbsd-8-0-RELEASE netbsd-8-0-RC2 netbsd-8-0-RC1 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 netbsd-7-1-2-RELEASE pgoyette-compat-base netbsd-7-1-1-RELEASE tls-maxphys-base-20171202 matt-nb8-mediatek-base nick-nhusb-base-20170825 perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base pgoyette-localcount-20170320 netbsd-7-1-RELEASE netbsd-7-1-RC2 nick-nhusb-base-20170204 netbsd-7-nhusb-base-20170116 bouyer-socketcan-base pgoyette-localcount-20170107 netbsd-7-1-RC1 nick-nhusb-base-20161204 pgoyette-localcount-20161104 netbsd-7-0-2-RELEASE nick-nhusb-base-20161004 localcount-20160914 netbsd-7-nhusb-base pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907 nick-nhusb-base-20160529 netbsd-7-0-1-RELEASE nick-nhusb-base-20160422 nick-nhusb-base-20160319 nick-nhusb-base-20151226 netbsd-7-0-RELEASE nick-nhusb-base-20150921 netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 nick-nhusb-base-20150606 nick-nhusb-base-20150406 nick-nhusb-base tls-maxphys-base netbsd-7-base
# 1.1 10-Aug-2014 matt

branches: 1.1.4; 1.1.28;
Preliminary files for AARCH64 (64-bit ARM) support.
Enough for a distribution build.


# 1.89 14-Sep-2020 ryo

PID_MAX is just an initial value (soft maximum). Don't use it for CTASSERT.
defined __HAVE_CPU_MAXPROC to use function cpu_maxproc().

pointed out by mrg@, thanks.


# 1.88 06-Sep-2020 ryo

Fix panic caused by modload. http://mail-index.netbsd.org/port-arm/2020/08/30/msg006960.html

The address space reserved for modules may not be mapped in L1-L3.


# 1.87 14-Aug-2020 skrll

Whitespace


# 1.86 12-Aug-2020 skrll

Part IV of ad's performance improvements for aarch64

- Implement pmap_growkernel(), and update kernel pmap's stats with atomics.

- Then, pmap_kenter_pa() and pmap_kremove() no longer need to allocate
memory nor take pm_lock, because they only modify L3 PTEs.

- Then, pm_lock and pp_lock can be adaptive mutexes at IPL_NONE which are
cheaper than spin mutexes.

- Take the pmap's lock in pmap_extract() if not the kernel's pmap, otherwise
pmap_extract() might see inconsistent state.


# 1.85 09-Aug-2020 skrll

Fix another UVMHIST so it doesn't use %s


# 1.84 16-Jul-2020 skrll

pmapboot_enter simplication
- bootpage_alloc in asm becomes pmapboot_pagealloc in C
- PMAPBOOT_ENTER_NOBLOCK is removed as it's not used
- PMAPBOOT_ENTER_NOOVERWRITE is removed as it's now always on
- physpage_allocator argument is removed as it's always
pmapboot_pagealloc
- Support for EARLYCONS without CONSADDR is removed so that the identity
map for CONSADDR is always known.

For the assembly files:
2 files changed, 40 insertions(+), 89 deletions(-)

LGTM ryo


# 1.83 04-Jul-2020 rin

Use tlen for temporary length variable instead of l, which is usually
used for struct lwp *.

No binary changes.


# 1.82 02-Jul-2020 rin

pmap_procwr(): sync icache even if p != curproc. This fixes applications
like GDB for arm32, that rewrite text of other process.

Thanks to ryo@ for discussion.


# 1.81 02-Jul-2020 rin

Set uvmexp.ncolors appropriately, which is required for some CPU
models with VIPT icache.

Otherwise, alias in virtual address results in inconsistent results,
at least for applications that rewrite text of other process, e.g.,
GDB for arm32.

Also, this hopefully fixes other unexpected failures due to alias.

Confirmed that there's no observable regression in performance;
difference in ``time make -j8'' for GENERIC64 kernel on BCM2837
with and without setting uvmexp.ncolors is within 0.1%.

Thanks to ryo@ for discussion.


# 1.80 27-Jun-2020 rin

Fix typo in name of evcnt(4) counter.


# 1.79 24-Jun-2020 ryo

Fix bug with incorrect range calculation when doing icache sync.
This is called by sysarch(ARM_SYNC_ICACHE) from aarch32 (compat_netbsd32) emul process.

pointed out by rin@, thanks.

XXX pullup-9


# 1.78 14-Jun-2020 ad

- Fix a lock order reversal in pmap_page_protect().

- Make sure pmap is always locked when updating stats; atomics no longer
needed to do that.

- Remove unneeded traversal of pv list in pmap_enter_pv().

- Shrink struct vm_page from 136 to 128 bytes (cache line sized) and struct
pv_entry from 48 to 32 bytes (power of 2 sized).

- Embed a pv_entry in each vm_page. This means PV entries don't need to
be allocated for private anonymous memory / COW pages / most UBC mappings.
Dynamic PV entries are then used only for stuff like shared libraries and
shared memory.

Proposed on port-arm@.


# 1.77 10-Jun-2020 ad

- Wired/resident stats shouldn't covered by PMAPCOUNTERS.
- Rename need_update_pv -> need_enter_pv.

Ok ryo@


# 1.76 01-Jun-2020 ryo

no need to make the PTE writable to do icache_sync, enough to accessible.


# 1.75 15-May-2020 skrll

Use __diagused


# 1.74 15-May-2020 tnn

fix non-diag build


# 1.73 14-May-2020 skrll

Use MUTEX_NODEBUG for PV locks as is commonly done. OK ryo.


# 1.72 13-May-2020 jmcneill

Implement pmap_extract_coherency


Revision tags: bouyer-xenpvh-base2 phil-wifi-20200421 bouyer-xenpvh-base1
# 1.71 18-Apr-2020 skrll

PMAP_DEBUG has been deleted on arm


# 1.70 13-Apr-2020 maxv

Add support for Branch Target Identification (BTI).

On the executable pages that have the GP (Guarded Page) bit, the semantic
of the "br" and "blr" instructions is changed: the CPU expects the first
instruction of the jump/call target to be "bti", and faults if it isn't.

We add the GP bit on the kernel .text pages (and incidentally the .rodata
pages, but we don't care). The compiler adds a "bti c" instruction at the
beginning of each C function. We modify the ENTRY() macros to manually add
"bti c" in the asm functions.

cpuswitch.S needs a specific change: with "br x27" the CPU expects "bti j",
which is bad because the functions begin with "bti c"; switch to "br x16",
for the CPU to accept "bti c".

BTI helps defend against JOP/COP. Tested on Qemu.


Revision tags: phil-wifi-20200411 bouyer-xenpvh-base
# 1.69 08-Apr-2020 ryo

branches: 1.69.2;
use PMAP_PAGE_INIT() to initialize mutex in pmap_page.

VM_MDPAGE_INIT() in pmap_free_pdp() had initialized pp_flags,
so it unintentionally cleared PMAP_PAGE_FLAGS_PV_TRACKED.
use PMAP_PAGE_INIT to avoid using PMAP_PAGE_FLAGS_PV_TRACKED.

pointed out by tnn@, thanks


Revision tags: phil-wifi-20200406
# 1.68 14-Mar-2020 ad

pmap_remove_all(): Return a boolean value to indicate the behaviour. If
true, all mappings have been removed, the pmap is totally cleared out, and
UVM can then avoid doing the work to call pmap_remove() for each map entry.
If false, either nothing has been done, or some helpful arch-specific voodoo
has taken place.


Revision tags: is-mlppp-base
# 1.67 02-Mar-2020 ryo

oops, fix incorrect usage of daif_enable() in my previous commit.


# 1.66 29-Feb-2020 ryo

Fix pmap to work correctly with tagged addresses

- when fault, untag from address before passing to uvm/pmap functions
- pmap_extract() checks more strictly and consider the address tag


# 1.65 29-Feb-2020 ryo

use pmapboot_enter_range()


Revision tags: ad-namecache-base3
# 1.64 10-Feb-2020 ryo

use LIST(3) instead of TAILQ(3) to save one word in struct vm_page and struct pmap.

pointed out by riastradh@. thanks


# 1.63 03-Feb-2020 ryo

add support pmap_pv(9)

Patch originally from jmcneill@. thanks


# 1.62 03-Feb-2020 ryo

separate struct vm_page_md into vm_page_md and pmap_page
for preparation pmap_pv(9)


Revision tags: ad-namecache-base2 ad-namecache-base1
# 1.61 09-Jan-2020 ryo

fix behaviour mmap()/mprotect() when passed only PROT_EXEC.

when mmap()/mprotect() with only PROT_EXEC, syscall will be successful,
but the page actually hadn't been mapped.
it should be mapped with PROT_READ|PROT_EXEC implicitly. (r-x)


Revision tags: ad-namecache-base
# 1.60 30-Dec-2019 skrll

branches: 1.60.2;
Update pmap_map_chunk to allow L[12] block mappings and L3 page mappings


# 1.59 30-Dec-2019 skrll

Remove unnecessary brackets and unwrap a conditional. Same code before
and after.


# 1.58 28-Dec-2019 jmcneill

Do not use Early Write Acknowledge for PCIe I/O and config space.


# 1.57 27-Dec-2019 jmcneill

Enable early write acknowledge for device memory mappings.


# 1.56 19-Dec-2019 skrll

G/C kasan_shadow_map call in pmap_enter

pmap_growkernel calls kasan_shadow_map for KVA


# 1.55 18-Dec-2019 ryo

atomic_add_16() is not used in pmap.c anymore. no need decl here.


# 1.54 18-Dec-2019 ryo

space to tab


# 1.53 14-Dec-2019 skrll

Fix build... wire_count probably doesn't need atomics


# 1.52 13-Dec-2019 skrll

Fix KASAN support by calling kasan_shadow_map in pmap_growkernel


# 1.51 10-Dec-2019 ad

pg->phys_addr -> VM_PAGE_TO_PHYS(pg)


Revision tags: phil-wifi-20191119
# 1.50 14-Nov-2019 maxv

Mark several kASan functions with __nothing, to avoid annoying #ifdefs.
Same as kCSan and kMSan.


# 1.49 14-Nov-2019 maxv

Don't include "opt_kasan.h" when there's already <sys/asan.h> included.


# 1.48 29-Oct-2019 maya

Define PMAP_NEED_PROCWR, providing strategically placed i-cache
synchronization where just-changed memory is about to be executed.

Fixes SIGILLs seen when running Mono 6 on QEMU Cortex-A57.

ok ryo


# 1.47 22-Sep-2019 jmcneill

Disable translation table walks using TTBR0 while changing its value and
when deactivating a pmap. Fixes stability issues on Ampere eMAG CPUs.


# 1.46 20-Sep-2019 ryo

ref/mod bit should be set according to 'flags' argument, not 'prot'. r1.44 was incomplete.


# 1.45 13-Sep-2019 ryo

In pmap_devmap_bootstrap(), cpu_earlydevice_va_p() must not return true until *all* devmap tables have been enabled.
console mapping may be present in the last table.


# 1.44 07-Sep-2019 ryo

- remove incorrect KASSERT. mmap(2) with prot=PROT_WRITE calls pmap_enter(..., PROT_WRITE) internally.
- fix to update page reference flags when only PROT_WRITE or PROT_EXECUTE specified


# 1.43 15-Aug-2019 skrll

Make pmap_db_pte_print more terse so it's quicker on serial consoles


# 1.42 12-Aug-2019 skrll

Use PMAP_DEV in DEVMAP_ENTRY rather than pmap_map_chunk. It's clearer and
means pmap_map_chunk can be made to map other memory types.


Revision tags: netbsd-9-base phil-wifi-20190609
# 1.41 17-May-2019 mrg

branches: 1.41.2;
apply some __diagused.


Revision tags: isaki-audio2-base
# 1.40 08-Apr-2019 ryo

- free empty page tables pages if reach a certain usage.
- need to lock at removing an old pg (_pmap_remove_pv) in _pmap_enter()


# 1.39 06-Apr-2019 ryo

Fix race conditions about pmap_page_protect() and pmap_enter().

while handling same PTE by these functions in same time, there
is a critical path that the number of valid PTEs and wire_count
are inconsistent, and it caused KASSERT.
Need to hold a pv_lock while modifying them.


# 1.38 20-Mar-2019 ryo

spinkle __printflike(), and use PRIxxx


# 1.37 19-Mar-2019 ryo

- add ddb command "machine ttbr" to dump MMU tables.
- tidy up descriptions, usages and messages.


# 1.36 19-Mar-2019 ryo

- free L1-L3 pages that has been emptied by pmap_remove().
- if no memories, pmap_enter will return correctly ENOMEM if PMAP_CANFAIL, or wait until available any memories if !PMAP_CANFAIL.

These changes improves the stability when we use a huge virtual memory spaces with mmap.


# 1.35 06-Feb-2019 ryo

improve pmap_remove
- don't lock/unlock per page in pmap_remove()
- speedup pte lookup for continuous addresses
- bring out pool_cache_put(&_pmap_pv_pool, pv) from lock/unlock section


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226
# 1.34 21-Dec-2018 ryo

- add workaround for Cavium ThunderX errata 27456.
- add cpufuncs table in cpu_info. each cpu clusters may have different erratum. (e.g. big.LITTLE)


Revision tags: pgoyette-compat-1126
# 1.33 01-Nov-2018 maxv

Add kASan support for aarch64. Stack tracking needs more investigation
and will come in a separate commit.

Reviewed by ryo@ jmcneill@ skrll@.


# 1.32 31-Oct-2018 ryo

invalidate icache correctly.
l3pte_executable() should be used for only valid pte.


Revision tags: pgoyette-compat-1020
# 1.31 18-Oct-2018 skrll

Provide generic start code that assumes the MMU is off and caches are
disabled as per the linux booting protocol for ARMv6 and ARMv7 boards.
u-boot image type should be changed to 'linux' for correct behaviour.

The new start code builds a minimal "bootstrap" L1PT with cached access
disabled and uses the same table for all processors. AP startup is
performed in less steps and more code is written in C.

The bootstrap tables and stack are placed into an (orphaned) section
"_init_memory" which is given to uvm when it is no longer used.

Various kernels have been converted to use this code and tested. Some
boards were provided by TNF. Thanks!

The GENERIC kernel now boots on boards using the TEGRA, SUNXI and EXYNOS
kernels. The GENERIC kernel will also work on RPI2 using u-boot.

Thanks to martin@ and aymeric@ for testing on parallella and nanosoc
respectively


# 1.30 14-Oct-2018 skrll

Use __nothing


# 1.29 12-Oct-2018 ryo

add initial support of COMPAT_NETBSD32 on AArch64.
arm ELF32 EABI binaries could be execute in AArch32 state on AArch64. A32 THUMB mode is not supported yet.


# 1.28 12-Oct-2018 ryo

- cleanup checking address ranges with IN_RANGE macro
- change PM_ADDR_CHECK macro to KASSERTMSG
- restore fast lookup cases with IN_RANGE macro for pmap_extract changed in my previous commit.


# 1.27 12-Oct-2018 ryo

rewrite pmap_pte_lookup() to share similar code.


# 1.26 04-Oct-2018 ryo

cleanup locore, and changed the way to map memories during boot.
- add functions bootpage_enter() and bootpage_alloc() to adapt various layout
of physical memory map. especially for 64bit physical memory layout.
pmapboot_alloc() allocates pagetable pages from _end[].
- changed to map only the required amount for PA=VA identity mapping
(kernel image, UART device, and FDT blob) with L2_BLOCK(2Mbyte).
- changing page permission for kernel image, and making KSEG mapping are done
at cpu_kernel_vm_init() instead of at locore.
- optimize PTE entries with PTE Contiguous bit. it is enabled on devmap only for now.

reviewed by skrll@, thanks.


# 1.25 04-Oct-2018 ryo

* define LX_BLKPAG_{OS,ATTR}_* for OS dependent PTE attributes in pmap.h
* cleanup macros


Revision tags: pgoyette-compat-0930
# 1.24 17-Sep-2018 ryo

delete debug printf and KASSERT.


# 1.23 10-Sep-2018 maxv

Replace KDASSERT by panic.


# 1.22 10-Sep-2018 maxv

Rename _pmap_alloc_pdp -> pmap_alloc_pdp, and make it public.


# 1.21 10-Sep-2018 ryo

cleanup aarch64 mpstart and fdt bootstrap
* arm_cpu_hatch_arg is a bad idea. avoid serializing CPU startup, and eliminate arm_cpu_hatch_arg.
in mpstart, resolve own cpu index using array of cpu_mpidr[] (aarch64)
* add support fdt enable-method "spin-table"
* add support fdt enable-method "brcm,bcm2836-smp" (for 32bit RaspberryPi)
* use arm_fdt_cpu_bootstrap() instead of psci_fdt_bootstrap()
* rename "arm/fdt/psci_fdt.h" to "arm/fdt/psci_fdtvar.h" because of conflict of include file for needs-flag
* add devmap for cpu spin-table of raspberrypi3/aarch64
* no need to force hatch APs for raspberrypi3/arm32 ifndef MULTIPROCESSOR.
* fix to work pmap_extract(kerneltext/data/bss) even if before calling pmap_bootstrap

idea to use cpu_mpidr[] by jmcneill@. reviewd by skrll@. thanks.


Revision tags: pgoyette-compat-0906
# 1.20 27-Aug-2018 ryo

need to add VM_PROT_READ when pmap_kenter_pa(va, pa, VM_PROT_WRITE, 0) or pmap_kenter_pa(va, pa, VM_PROT_EXECUTE, 0).
VM_PROT_READ is treated as an access permission inernally.


# 1.19 11-Aug-2018 ryo

change to minimum invalidation of TLB.
specifying not only va but also asid, and not invalidate L0-L2 entry using tlbi_*_ll() if needed.


# 1.18 10-Aug-2018 ryo

treat kernel-exec attr and user-exec attr separately.
kernel cannot execute userland exec page, and user cannot execute kernel page.


# 1.17 06-Aug-2018 ryo

set kernel text/rodata readonly by default.
add function db_write_text() for setting ddb breakpoint.


# 1.16 31-Jul-2018 skrll

Define and use VPRINTF


Revision tags: pgoyette-compat-0728
# 1.15 27-Jul-2018 ryo

changes of pmap.c r1.13 seems to be unstable.
In order to invalidate icache, not to invalidate all icache,
but temporary to make the page writable and invalidate target address only.


# 1.14 24-Jul-2018 ryo

don't call pool_cache_put with locking pmap. pool_cache_put call pmap_kenter_pa internally.
(pool_cache_put_paddr -> pool_cache_put_slow -> pool_get -> pmap_kenter_pa)


# 1.13 23-Jul-2018 ryo

* fix icache invalidations.
* "ic ivau" (aarch64_icache_sync_range) with VA generates permission fault in some situations, therefore use KSEG address for now.


# 1.12 23-Jul-2018 ryo

rather than using flags to resolve nested locks, reserve pool_cache before locking.


# 1.11 21-Jul-2018 ryo

* avoid deadlock. mutex_owned() works only for adaptive lock, therefore we cannot use it for spinlock...
* add more NULL check
* clear pte when pmap_enter() fails


# 1.10 17-Jul-2018 ryo

Use __debugused


# 1.9 17-Jul-2018 christos

Add missing casts, remove unused variables.


# 1.8 09-Jul-2018 ryo

need locks in pmap_kremove() and pmap_fault_fixup()


Revision tags: phil-wifi-base pgoyette-compat-0625 pgoyette-compat-0521
# 1.7 20-May-2018 ryo

branches: 1.7.2;
pmap_enter() must update modified/referenced flags by 'flags' not 'prot'.


# 1.6 16-May-2018 ryo

Fix memory leak. it was leaking one page every pmap_create().
pm->pm_vmlist must be initialized before calling _pmap_alloc_pdp().


Revision tags: pgoyette-compat-0502
# 1.5 29-Apr-2018 ryo

fix KASSERT panic. pv_entry may not be exists in pvlist when pmap_remove().


# 1.4 29-Apr-2018 ryo

delete unused code


# 1.3 27-Apr-2018 ryo

fix instability behavior of bufcache on aarch64.
* fix to return correct ref/mod when PMAP_WIRED.
* changed to keep wired flags in pte instead of pv_entry, and cleanup.


Revision tags: pgoyette-compat-0422 pgoyette-compat-0415 pgoyette-compat-0407
# 1.2 01-Apr-2018 ryo

Add initial support for ARMv8 (AARCH64) (by nisimura@ and ryo@)

- sys/arch/evbarm64 is gone and integrated into sys/arch/evbarm. (by skrll@)
- add support fdt. evbarm/conf/GENERIC64 fdt (bcm2837,sunxi,tegra) based generic 64bit kernel config. (by skrll@, jmcneill@)


Revision tags: netbsd-8-2-RELEASE netbsd-8-1-RELEASE netbsd-8-1-RC1 netbsd-7-2-RELEASE netbsd-8-0-RELEASE netbsd-8-0-RC2 netbsd-8-0-RC1 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 netbsd-7-1-2-RELEASE pgoyette-compat-base netbsd-7-1-1-RELEASE tls-maxphys-base-20171202 matt-nb8-mediatek-base nick-nhusb-base-20170825 perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base pgoyette-localcount-20170320 netbsd-7-1-RELEASE netbsd-7-1-RC2 nick-nhusb-base-20170204 netbsd-7-nhusb-base-20170116 bouyer-socketcan-base pgoyette-localcount-20170107 netbsd-7-1-RC1 nick-nhusb-base-20161204 pgoyette-localcount-20161104 netbsd-7-0-2-RELEASE nick-nhusb-base-20161004 localcount-20160914 netbsd-7-nhusb-base pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907 nick-nhusb-base-20160529 netbsd-7-0-1-RELEASE nick-nhusb-base-20160422 nick-nhusb-base-20160319 nick-nhusb-base-20151226 netbsd-7-0-RELEASE nick-nhusb-base-20150921 netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 nick-nhusb-base-20150606 nick-nhusb-base-20150406 nick-nhusb-base tls-maxphys-base netbsd-7-base
# 1.1 10-Aug-2014 matt

branches: 1.1.4; 1.1.28;
Preliminary files for AARCH64 (64-bit ARM) support.
Enough for a distribution build.


# 1.88 06-Sep-2020 ryo

Fix panic caused by modload. http://mail-index.netbsd.org/port-arm/2020/08/30/msg006960.html

The address space reserved for modules may not be mapped in L1-L3.


# 1.87 14-Aug-2020 skrll

Whitespace


# 1.86 12-Aug-2020 skrll

Part IV of ad's performance improvements for aarch64

- Implement pmap_growkernel(), and update kernel pmap's stats with atomics.

- Then, pmap_kenter_pa() and pmap_kremove() no longer need to allocate
memory nor take pm_lock, because they only modify L3 PTEs.

- Then, pm_lock and pp_lock can be adaptive mutexes at IPL_NONE which are
cheaper than spin mutexes.

- Take the pmap's lock in pmap_extract() if not the kernel's pmap, otherwise
pmap_extract() might see inconsistent state.


# 1.85 09-Aug-2020 skrll

Fix another UVMHIST so it doesn't use %s


# 1.84 16-Jul-2020 skrll

pmapboot_enter simplication
- bootpage_alloc in asm becomes pmapboot_pagealloc in C
- PMAPBOOT_ENTER_NOBLOCK is removed as it's not used
- PMAPBOOT_ENTER_NOOVERWRITE is removed as it's now always on
- physpage_allocator argument is removed as it's always
pmapboot_pagealloc
- Support for EARLYCONS without CONSADDR is removed so that the identity
map for CONSADDR is always known.

For the assembly files:
2 files changed, 40 insertions(+), 89 deletions(-)

LGTM ryo


# 1.83 04-Jul-2020 rin

Use tlen for temporary length variable instead of l, which is usually
used for struct lwp *.

No binary changes.


# 1.82 02-Jul-2020 rin

pmap_procwr(): sync icache even if p != curproc. This fixes applications
like GDB for arm32, that rewrite text of other process.

Thanks to ryo@ for discussion.


# 1.81 02-Jul-2020 rin

Set uvmexp.ncolors appropriately, which is required for some CPU
models with VIPT icache.

Otherwise, alias in virtual address results in inconsistent results,
at least for applications that rewrite text of other process, e.g.,
GDB for arm32.

Also, this hopefully fixes other unexpected failures due to alias.

Confirmed that there's no observable regression in performance;
difference in ``time make -j8'' for GENERIC64 kernel on BCM2837
with and without setting uvmexp.ncolors is within 0.1%.

Thanks to ryo@ for discussion.


# 1.80 27-Jun-2020 rin

Fix typo in name of evcnt(4) counter.


# 1.79 24-Jun-2020 ryo

Fix bug with incorrect range calculation when doing icache sync.
This is called by sysarch(ARM_SYNC_ICACHE) from aarch32 (compat_netbsd32) emul process.

pointed out by rin@, thanks.

XXX pullup-9


# 1.78 14-Jun-2020 ad

- Fix a lock order reversal in pmap_page_protect().

- Make sure pmap is always locked when updating stats; atomics no longer
needed to do that.

- Remove unneeded traversal of pv list in pmap_enter_pv().

- Shrink struct vm_page from 136 to 128 bytes (cache line sized) and struct
pv_entry from 48 to 32 bytes (power of 2 sized).

- Embed a pv_entry in each vm_page. This means PV entries don't need to
be allocated for private anonymous memory / COW pages / most UBC mappings.
Dynamic PV entries are then used only for stuff like shared libraries and
shared memory.

Proposed on port-arm@.


# 1.77 10-Jun-2020 ad

- Wired/resident stats shouldn't covered by PMAPCOUNTERS.
- Rename need_update_pv -> need_enter_pv.

Ok ryo@


# 1.76 01-Jun-2020 ryo

no need to make the PTE writable to do icache_sync, enough to accessible.


# 1.75 15-May-2020 skrll

Use __diagused


# 1.74 15-May-2020 tnn

fix non-diag build


# 1.73 14-May-2020 skrll

Use MUTEX_NODEBUG for PV locks as is commonly done. OK ryo.


# 1.72 13-May-2020 jmcneill

Implement pmap_extract_coherency


Revision tags: bouyer-xenpvh-base2 phil-wifi-20200421 bouyer-xenpvh-base1
# 1.71 18-Apr-2020 skrll

PMAP_DEBUG has been deleted on arm


# 1.70 13-Apr-2020 maxv

Add support for Branch Target Identification (BTI).

On the executable pages that have the GP (Guarded Page) bit, the semantic
of the "br" and "blr" instructions is changed: the CPU expects the first
instruction of the jump/call target to be "bti", and faults if it isn't.

We add the GP bit on the kernel .text pages (and incidentally the .rodata
pages, but we don't care). The compiler adds a "bti c" instruction at the
beginning of each C function. We modify the ENTRY() macros to manually add
"bti c" in the asm functions.

cpuswitch.S needs a specific change: with "br x27" the CPU expects "bti j",
which is bad because the functions begin with "bti c"; switch to "br x16",
for the CPU to accept "bti c".

BTI helps defend against JOP/COP. Tested on Qemu.


Revision tags: phil-wifi-20200411 bouyer-xenpvh-base
# 1.69 08-Apr-2020 ryo

branches: 1.69.2;
use PMAP_PAGE_INIT() to initialize mutex in pmap_page.

VM_MDPAGE_INIT() in pmap_free_pdp() had initialized pp_flags,
so it unintentionally cleared PMAP_PAGE_FLAGS_PV_TRACKED.
use PMAP_PAGE_INIT to avoid using PMAP_PAGE_FLAGS_PV_TRACKED.

pointed out by tnn@, thanks


Revision tags: phil-wifi-20200406
# 1.68 14-Mar-2020 ad

pmap_remove_all(): Return a boolean value to indicate the behaviour. If
true, all mappings have been removed, the pmap is totally cleared out, and
UVM can then avoid doing the work to call pmap_remove() for each map entry.
If false, either nothing has been done, or some helpful arch-specific voodoo
has taken place.


Revision tags: is-mlppp-base
# 1.67 02-Mar-2020 ryo

oops, fix incorrect usage of daif_enable() in my previous commit.


# 1.66 29-Feb-2020 ryo

Fix pmap to work correctly with tagged addresses

- when fault, untag from address before passing to uvm/pmap functions
- pmap_extract() checks more strictly and consider the address tag


# 1.65 29-Feb-2020 ryo

use pmapboot_enter_range()


Revision tags: ad-namecache-base3
# 1.64 10-Feb-2020 ryo

use LIST(3) instead of TAILQ(3) to save one word in struct vm_page and struct pmap.

pointed out by riastradh@. thanks


# 1.63 03-Feb-2020 ryo

add support pmap_pv(9)

Patch originally from jmcneill@. thanks


# 1.62 03-Feb-2020 ryo

separate struct vm_page_md into vm_page_md and pmap_page
for preparation pmap_pv(9)


Revision tags: ad-namecache-base2 ad-namecache-base1
# 1.61 09-Jan-2020 ryo

fix behaviour mmap()/mprotect() when passed only PROT_EXEC.

when mmap()/mprotect() with only PROT_EXEC, syscall will be successful,
but the page actually hadn't been mapped.
it should be mapped with PROT_READ|PROT_EXEC implicitly. (r-x)


Revision tags: ad-namecache-base
# 1.60 30-Dec-2019 skrll

branches: 1.60.2;
Update pmap_map_chunk to allow L[12] block mappings and L3 page mappings


# 1.59 30-Dec-2019 skrll

Remove unnecessary brackets and unwrap a conditional. Same code before
and after.


# 1.58 28-Dec-2019 jmcneill

Do not use Early Write Acknowledge for PCIe I/O and config space.


# 1.57 27-Dec-2019 jmcneill

Enable early write acknowledge for device memory mappings.


# 1.56 19-Dec-2019 skrll

G/C kasan_shadow_map call in pmap_enter

pmap_growkernel calls kasan_shadow_map for KVA


# 1.55 18-Dec-2019 ryo

atomic_add_16() is not used in pmap.c anymore. no need decl here.


# 1.54 18-Dec-2019 ryo

space to tab


# 1.53 14-Dec-2019 skrll

Fix build... wire_count probably doesn't need atomics


# 1.52 13-Dec-2019 skrll

Fix KASAN support by calling kasan_shadow_map in pmap_growkernel


# 1.51 10-Dec-2019 ad

pg->phys_addr -> VM_PAGE_TO_PHYS(pg)


Revision tags: phil-wifi-20191119
# 1.50 14-Nov-2019 maxv

Mark several kASan functions with __nothing, to avoid annoying #ifdefs.
Same as kCSan and kMSan.


# 1.49 14-Nov-2019 maxv

Don't include "opt_kasan.h" when there's already <sys/asan.h> included.


# 1.48 29-Oct-2019 maya

Define PMAP_NEED_PROCWR, providing strategically placed i-cache
synchronization where just-changed memory is about to be executed.

Fixes SIGILLs seen when running Mono 6 on QEMU Cortex-A57.

ok ryo


# 1.47 22-Sep-2019 jmcneill

Disable translation table walks using TTBR0 while changing its value and
when deactivating a pmap. Fixes stability issues on Ampere eMAG CPUs.


# 1.46 20-Sep-2019 ryo

ref/mod bit should be set according to 'flags' argument, not 'prot'. r1.44 was incomplete.


# 1.45 13-Sep-2019 ryo

In pmap_devmap_bootstrap(), cpu_earlydevice_va_p() must not return true until *all* devmap tables have been enabled.
console mapping may be present in the last table.


# 1.44 07-Sep-2019 ryo

- remove incorrect KASSERT. mmap(2) with prot=PROT_WRITE calls pmap_enter(..., PROT_WRITE) internally.
- fix to update page reference flags when only PROT_WRITE or PROT_EXECUTE specified


# 1.43 15-Aug-2019 skrll

Make pmap_db_pte_print more terse so it's quicker on serial consoles


# 1.42 12-Aug-2019 skrll

Use PMAP_DEV in DEVMAP_ENTRY rather than pmap_map_chunk. It's clearer and
means pmap_map_chunk can be made to map other memory types.


Revision tags: netbsd-9-base phil-wifi-20190609
# 1.41 17-May-2019 mrg

branches: 1.41.2;
apply some __diagused.


Revision tags: isaki-audio2-base
# 1.40 08-Apr-2019 ryo

- free empty page tables pages if reach a certain usage.
- need to lock at removing an old pg (_pmap_remove_pv) in _pmap_enter()


# 1.39 06-Apr-2019 ryo

Fix race conditions about pmap_page_protect() and pmap_enter().

while handling same PTE by these functions in same time, there
is a critical path that the number of valid PTEs and wire_count
are inconsistent, and it caused KASSERT.
Need to hold a pv_lock while modifying them.


# 1.38 20-Mar-2019 ryo

spinkle __printflike(), and use PRIxxx


# 1.37 19-Mar-2019 ryo

- add ddb command "machine ttbr" to dump MMU tables.
- tidy up descriptions, usages and messages.


# 1.36 19-Mar-2019 ryo

- free L1-L3 pages that has been emptied by pmap_remove().
- if no memories, pmap_enter will return correctly ENOMEM if PMAP_CANFAIL, or wait until available any memories if !PMAP_CANFAIL.

These changes improves the stability when we use a huge virtual memory spaces with mmap.


# 1.35 06-Feb-2019 ryo

improve pmap_remove
- don't lock/unlock per page in pmap_remove()
- speedup pte lookup for continuous addresses
- bring out pool_cache_put(&_pmap_pv_pool, pv) from lock/unlock section


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226
# 1.34 21-Dec-2018 ryo

- add workaround for Cavium ThunderX errata 27456.
- add cpufuncs table in cpu_info. each cpu clusters may have different erratum. (e.g. big.LITTLE)


Revision tags: pgoyette-compat-1126
# 1.33 01-Nov-2018 maxv

Add kASan support for aarch64. Stack tracking needs more investigation
and will come in a separate commit.

Reviewed by ryo@ jmcneill@ skrll@.


# 1.32 31-Oct-2018 ryo

invalidate icache correctly.
l3pte_executable() should be used for only valid pte.


Revision tags: pgoyette-compat-1020
# 1.31 18-Oct-2018 skrll

Provide generic start code that assumes the MMU is off and caches are
disabled as per the linux booting protocol for ARMv6 and ARMv7 boards.
u-boot image type should be changed to 'linux' for correct behaviour.

The new start code builds a minimal "bootstrap" L1PT with cached access
disabled and uses the same table for all processors. AP startup is
performed in less steps and more code is written in C.

The bootstrap tables and stack are placed into an (orphaned) section
"_init_memory" which is given to uvm when it is no longer used.

Various kernels have been converted to use this code and tested. Some
boards were provided by TNF. Thanks!

The GENERIC kernel now boots on boards using the TEGRA, SUNXI and EXYNOS
kernels. The GENERIC kernel will also work on RPI2 using u-boot.

Thanks to martin@ and aymeric@ for testing on parallella and nanosoc
respectively


# 1.30 14-Oct-2018 skrll

Use __nothing


# 1.29 12-Oct-2018 ryo

add initial support of COMPAT_NETBSD32 on AArch64.
arm ELF32 EABI binaries could be execute in AArch32 state on AArch64. A32 THUMB mode is not supported yet.


# 1.28 12-Oct-2018 ryo

- cleanup checking address ranges with IN_RANGE macro
- change PM_ADDR_CHECK macro to KASSERTMSG
- restore fast lookup cases with IN_RANGE macro for pmap_extract changed in my previous commit.


# 1.27 12-Oct-2018 ryo

rewrite pmap_pte_lookup() to share similar code.


# 1.26 04-Oct-2018 ryo

cleanup locore, and changed the way to map memories during boot.
- add functions bootpage_enter() and bootpage_alloc() to adapt various layout
of physical memory map. especially for 64bit physical memory layout.
pmapboot_alloc() allocates pagetable pages from _end[].
- changed to map only the required amount for PA=VA identity mapping
(kernel image, UART device, and FDT blob) with L2_BLOCK(2Mbyte).
- changing page permission for kernel image, and making KSEG mapping are done
at cpu_kernel_vm_init() instead of at locore.
- optimize PTE entries with PTE Contiguous bit. it is enabled on devmap only for now.

reviewed by skrll@, thanks.


# 1.25 04-Oct-2018 ryo

* define LX_BLKPAG_{OS,ATTR}_* for OS dependent PTE attributes in pmap.h
* cleanup macros


Revision tags: pgoyette-compat-0930
# 1.24 17-Sep-2018 ryo

delete debug printf and KASSERT.


# 1.23 10-Sep-2018 maxv

Replace KDASSERT by panic.


# 1.22 10-Sep-2018 maxv

Rename _pmap_alloc_pdp -> pmap_alloc_pdp, and make it public.


# 1.21 10-Sep-2018 ryo

cleanup aarch64 mpstart and fdt bootstrap
* arm_cpu_hatch_arg is a bad idea. avoid serializing CPU startup, and eliminate arm_cpu_hatch_arg.
in mpstart, resolve own cpu index using array of cpu_mpidr[] (aarch64)
* add support fdt enable-method "spin-table"
* add support fdt enable-method "brcm,bcm2836-smp" (for 32bit RaspberryPi)
* use arm_fdt_cpu_bootstrap() instead of psci_fdt_bootstrap()
* rename "arm/fdt/psci_fdt.h" to "arm/fdt/psci_fdtvar.h" because of conflict of include file for needs-flag
* add devmap for cpu spin-table of raspberrypi3/aarch64
* no need to force hatch APs for raspberrypi3/arm32 ifndef MULTIPROCESSOR.
* fix to work pmap_extract(kerneltext/data/bss) even if before calling pmap_bootstrap

idea to use cpu_mpidr[] by jmcneill@. reviewd by skrll@. thanks.


Revision tags: pgoyette-compat-0906
# 1.20 27-Aug-2018 ryo

need to add VM_PROT_READ when pmap_kenter_pa(va, pa, VM_PROT_WRITE, 0) or pmap_kenter_pa(va, pa, VM_PROT_EXECUTE, 0).
VM_PROT_READ is treated as an access permission inernally.


# 1.19 11-Aug-2018 ryo

change to minimum invalidation of TLB.
specifying not only va but also asid, and not invalidate L0-L2 entry using tlbi_*_ll() if needed.


# 1.18 10-Aug-2018 ryo

treat kernel-exec attr and user-exec attr separately.
kernel cannot execute userland exec page, and user cannot execute kernel page.


# 1.17 06-Aug-2018 ryo

set kernel text/rodata readonly by default.
add function db_write_text() for setting ddb breakpoint.


# 1.16 31-Jul-2018 skrll

Define and use VPRINTF


Revision tags: pgoyette-compat-0728
# 1.15 27-Jul-2018 ryo

changes of pmap.c r1.13 seems to be unstable.
In order to invalidate icache, not to invalidate all icache,
but temporary to make the page writable and invalidate target address only.


# 1.14 24-Jul-2018 ryo

don't call pool_cache_put with locking pmap. pool_cache_put call pmap_kenter_pa internally.
(pool_cache_put_paddr -> pool_cache_put_slow -> pool_get -> pmap_kenter_pa)


# 1.13 23-Jul-2018 ryo

* fix icache invalidations.
* "ic ivau" (aarch64_icache_sync_range) with VA generates permission fault in some situations, therefore use KSEG address for now.


# 1.12 23-Jul-2018 ryo

rather than using flags to resolve nested locks, reserve pool_cache before locking.


# 1.11 21-Jul-2018 ryo

* avoid deadlock. mutex_owned() works only for adaptive lock, therefore we cannot use it for spinlock...
* add more NULL check
* clear pte when pmap_enter() fails


# 1.10 17-Jul-2018 ryo

Use __debugused


# 1.9 17-Jul-2018 christos

Add missing casts, remove unused variables.


# 1.8 09-Jul-2018 ryo

need locks in pmap_kremove() and pmap_fault_fixup()


Revision tags: phil-wifi-base pgoyette-compat-0625 pgoyette-compat-0521
# 1.7 20-May-2018 ryo

branches: 1.7.2;
pmap_enter() must update modified/referenced flags by 'flags' not 'prot'.


# 1.6 16-May-2018 ryo

Fix memory leak. it was leaking one page every pmap_create().
pm->pm_vmlist must be initialized before calling _pmap_alloc_pdp().


Revision tags: pgoyette-compat-0502
# 1.5 29-Apr-2018 ryo

fix KASSERT panic. pv_entry may not be exists in pvlist when pmap_remove().


# 1.4 29-Apr-2018 ryo

delete unused code


# 1.3 27-Apr-2018 ryo

fix instability behavior of bufcache on aarch64.
* fix to return correct ref/mod when PMAP_WIRED.
* changed to keep wired flags in pte instead of pv_entry, and cleanup.


Revision tags: pgoyette-compat-0422 pgoyette-compat-0415 pgoyette-compat-0407
# 1.2 01-Apr-2018 ryo

Add initial support for ARMv8 (AARCH64) (by nisimura@ and ryo@)

- sys/arch/evbarm64 is gone and integrated into sys/arch/evbarm. (by skrll@)
- add support fdt. evbarm/conf/GENERIC64 fdt (bcm2837,sunxi,tegra) based generic 64bit kernel config. (by skrll@, jmcneill@)


Revision tags: netbsd-8-2-RELEASE netbsd-8-1-RELEASE netbsd-8-1-RC1 netbsd-7-2-RELEASE netbsd-8-0-RELEASE netbsd-8-0-RC2 netbsd-8-0-RC1 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 netbsd-7-1-2-RELEASE pgoyette-compat-base netbsd-7-1-1-RELEASE tls-maxphys-base-20171202 matt-nb8-mediatek-base nick-nhusb-base-20170825 perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base pgoyette-localcount-20170320 netbsd-7-1-RELEASE netbsd-7-1-RC2 nick-nhusb-base-20170204 netbsd-7-nhusb-base-20170116 bouyer-socketcan-base pgoyette-localcount-20170107 netbsd-7-1-RC1 nick-nhusb-base-20161204 pgoyette-localcount-20161104 netbsd-7-0-2-RELEASE nick-nhusb-base-20161004 localcount-20160914 netbsd-7-nhusb-base pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907 nick-nhusb-base-20160529 netbsd-7-0-1-RELEASE nick-nhusb-base-20160422 nick-nhusb-base-20160319 nick-nhusb-base-20151226 netbsd-7-0-RELEASE nick-nhusb-base-20150921 netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 nick-nhusb-base-20150606 nick-nhusb-base-20150406 nick-nhusb-base tls-maxphys-base netbsd-7-base
# 1.1 10-Aug-2014 matt

branches: 1.1.4; 1.1.28;
Preliminary files for AARCH64 (64-bit ARM) support.
Enough for a distribution build.


# 1.87 14-Aug-2020 skrll

Whitespace


# 1.86 12-Aug-2020 skrll

Part IV of ad's performance improvements for aarch64

- Implement pmap_growkernel(), and update kernel pmap's stats with atomics.

- Then, pmap_kenter_pa() and pmap_kremove() no longer need to allocate
memory nor take pm_lock, because they only modify L3 PTEs.

- Then, pm_lock and pp_lock can be adaptive mutexes at IPL_NONE which are
cheaper than spin mutexes.

- Take the pmap's lock in pmap_extract() if not the kernel's pmap, otherwise
pmap_extract() might see inconsistent state.


# 1.85 09-Aug-2020 skrll

Fix another UVMHIST so it doesn't use %s


# 1.84 16-Jul-2020 skrll

pmapboot_enter simplication
- bootpage_alloc in asm becomes pmapboot_pagealloc in C
- PMAPBOOT_ENTER_NOBLOCK is removed as it's not used
- PMAPBOOT_ENTER_NOOVERWRITE is removed as it's now always on
- physpage_allocator argument is removed as it's always
pmapboot_pagealloc
- Support for EARLYCONS without CONSADDR is removed so that the identity
map for CONSADDR is always known.

For the assembly files:
2 files changed, 40 insertions(+), 89 deletions(-)

LGTM ryo


# 1.83 04-Jul-2020 rin

Use tlen for temporary length variable instead of l, which is usually
used for struct lwp *.

No binary changes.


# 1.82 02-Jul-2020 rin

pmap_procwr(): sync icache even if p != curproc. This fixes applications
like GDB for arm32, that rewrite text of other process.

Thanks to ryo@ for discussion.


# 1.81 02-Jul-2020 rin

Set uvmexp.ncolors appropriately, which is required for some CPU
models with VIPT icache.

Otherwise, alias in virtual address results in inconsistent results,
at least for applications that rewrite text of other process, e.g.,
GDB for arm32.

Also, this hopefully fixes other unexpected failures due to alias.

Confirmed that there's no observable regression in performance;
difference in ``time make -j8'' for GENERIC64 kernel on BCM2837
with and without setting uvmexp.ncolors is within 0.1%.

Thanks to ryo@ for discussion.


# 1.80 27-Jun-2020 rin

Fix typo in name of evcnt(4) counter.


# 1.79 24-Jun-2020 ryo

Fix bug with incorrect range calculation when doing icache sync.
This is called by sysarch(ARM_SYNC_ICACHE) from aarch32 (compat_netbsd32) emul process.

pointed out by rin@, thanks.

XXX pullup-9


# 1.78 14-Jun-2020 ad

- Fix a lock order reversal in pmap_page_protect().

- Make sure pmap is always locked when updating stats; atomics no longer
needed to do that.

- Remove unneeded traversal of pv list in pmap_enter_pv().

- Shrink struct vm_page from 136 to 128 bytes (cache line sized) and struct
pv_entry from 48 to 32 bytes (power of 2 sized).

- Embed a pv_entry in each vm_page. This means PV entries don't need to
be allocated for private anonymous memory / COW pages / most UBC mappings.
Dynamic PV entries are then used only for stuff like shared libraries and
shared memory.

Proposed on port-arm@.


# 1.77 10-Jun-2020 ad

- Wired/resident stats shouldn't covered by PMAPCOUNTERS.
- Rename need_update_pv -> need_enter_pv.

Ok ryo@


# 1.76 01-Jun-2020 ryo

no need to make the PTE writable to do icache_sync, enough to accessible.


# 1.75 15-May-2020 skrll

Use __diagused


# 1.74 15-May-2020 tnn

fix non-diag build


# 1.73 14-May-2020 skrll

Use MUTEX_NODEBUG for PV locks as is commonly done. OK ryo.


# 1.72 13-May-2020 jmcneill

Implement pmap_extract_coherency


Revision tags: bouyer-xenpvh-base2 phil-wifi-20200421 bouyer-xenpvh-base1
# 1.71 18-Apr-2020 skrll

PMAP_DEBUG has been deleted on arm


# 1.70 13-Apr-2020 maxv

Add support for Branch Target Identification (BTI).

On the executable pages that have the GP (Guarded Page) bit, the semantic
of the "br" and "blr" instructions is changed: the CPU expects the first
instruction of the jump/call target to be "bti", and faults if it isn't.

We add the GP bit on the kernel .text pages (and incidentally the .rodata
pages, but we don't care). The compiler adds a "bti c" instruction at the
beginning of each C function. We modify the ENTRY() macros to manually add
"bti c" in the asm functions.

cpuswitch.S needs a specific change: with "br x27" the CPU expects "bti j",
which is bad because the functions begin with "bti c"; switch to "br x16",
for the CPU to accept "bti c".

BTI helps defend against JOP/COP. Tested on Qemu.


Revision tags: phil-wifi-20200411 bouyer-xenpvh-base
# 1.69 08-Apr-2020 ryo

branches: 1.69.2;
use PMAP_PAGE_INIT() to initialize mutex in pmap_page.

VM_MDPAGE_INIT() in pmap_free_pdp() had initialized pp_flags,
so it unintentionally cleared PMAP_PAGE_FLAGS_PV_TRACKED.
use PMAP_PAGE_INIT to avoid using PMAP_PAGE_FLAGS_PV_TRACKED.

pointed out by tnn@, thanks


Revision tags: phil-wifi-20200406
# 1.68 14-Mar-2020 ad

pmap_remove_all(): Return a boolean value to indicate the behaviour. If
true, all mappings have been removed, the pmap is totally cleared out, and
UVM can then avoid doing the work to call pmap_remove() for each map entry.
If false, either nothing has been done, or some helpful arch-specific voodoo
has taken place.


Revision tags: is-mlppp-base
# 1.67 02-Mar-2020 ryo

oops, fix incorrect usage of daif_enable() in my previous commit.


# 1.66 29-Feb-2020 ryo

Fix pmap to work correctly with tagged addresses

- when fault, untag from address before passing to uvm/pmap functions
- pmap_extract() checks more strictly and consider the address tag


# 1.65 29-Feb-2020 ryo

use pmapboot_enter_range()


Revision tags: ad-namecache-base3
# 1.64 10-Feb-2020 ryo

use LIST(3) instead of TAILQ(3) to save one word in struct vm_page and struct pmap.

pointed out by riastradh@. thanks


# 1.63 03-Feb-2020 ryo

add support pmap_pv(9)

Patch originally from jmcneill@. thanks


# 1.62 03-Feb-2020 ryo

separate struct vm_page_md into vm_page_md and pmap_page
for preparation pmap_pv(9)


Revision tags: ad-namecache-base2 ad-namecache-base1
# 1.61 09-Jan-2020 ryo

fix behaviour mmap()/mprotect() when passed only PROT_EXEC.

when mmap()/mprotect() with only PROT_EXEC, syscall will be successful,
but the page actually hadn't been mapped.
it should be mapped with PROT_READ|PROT_EXEC implicitly. (r-x)


Revision tags: ad-namecache-base
# 1.60 30-Dec-2019 skrll

branches: 1.60.2;
Update pmap_map_chunk to allow L[12] block mappings and L3 page mappings


# 1.59 30-Dec-2019 skrll

Remove unnecessary brackets and unwrap a conditional. Same code before
and after.


# 1.58 28-Dec-2019 jmcneill

Do not use Early Write Acknowledge for PCIe I/O and config space.


# 1.57 27-Dec-2019 jmcneill

Enable early write acknowledge for device memory mappings.


# 1.56 19-Dec-2019 skrll

G/C kasan_shadow_map call in pmap_enter

pmap_growkernel calls kasan_shadow_map for KVA


# 1.55 18-Dec-2019 ryo

atomic_add_16() is not used in pmap.c anymore. no need decl here.


# 1.54 18-Dec-2019 ryo

space to tab


# 1.53 14-Dec-2019 skrll

Fix build... wire_count probably doesn't need atomics


# 1.52 13-Dec-2019 skrll

Fix KASAN support by calling kasan_shadow_map in pmap_growkernel


# 1.51 10-Dec-2019 ad

pg->phys_addr -> VM_PAGE_TO_PHYS(pg)


Revision tags: phil-wifi-20191119
# 1.50 14-Nov-2019 maxv

Mark several kASan functions with __nothing, to avoid annoying #ifdefs.
Same as kCSan and kMSan.


# 1.49 14-Nov-2019 maxv

Don't include "opt_kasan.h" when there's already <sys/asan.h> included.


# 1.48 29-Oct-2019 maya

Define PMAP_NEED_PROCWR, providing strategically placed i-cache
synchronization where just-changed memory is about to be executed.

Fixes SIGILLs seen when running Mono 6 on QEMU Cortex-A57.

ok ryo


# 1.47 22-Sep-2019 jmcneill

Disable translation table walks using TTBR0 while changing its value and
when deactivating a pmap. Fixes stability issues on Ampere eMAG CPUs.


# 1.46 20-Sep-2019 ryo

ref/mod bit should be set according to 'flags' argument, not 'prot'. r1.44 was incomplete.


# 1.45 13-Sep-2019 ryo

In pmap_devmap_bootstrap(), cpu_earlydevice_va_p() must not return true until *all* devmap tables have been enabled.
console mapping may be present in the last table.


# 1.44 07-Sep-2019 ryo

- remove incorrect KASSERT. mmap(2) with prot=PROT_WRITE calls pmap_enter(..., PROT_WRITE) internally.
- fix to update page reference flags when only PROT_WRITE or PROT_EXECUTE specified


# 1.43 15-Aug-2019 skrll

Make pmap_db_pte_print more terse so it's quicker on serial consoles


# 1.42 12-Aug-2019 skrll

Use PMAP_DEV in DEVMAP_ENTRY rather than pmap_map_chunk. It's clearer and
means pmap_map_chunk can be made to map other memory types.


Revision tags: netbsd-9-base phil-wifi-20190609
# 1.41 17-May-2019 mrg

branches: 1.41.2;
apply some __diagused.


Revision tags: isaki-audio2-base
# 1.40 08-Apr-2019 ryo

- free empty page tables pages if reach a certain usage.
- need to lock at removing an old pg (_pmap_remove_pv) in _pmap_enter()


# 1.39 06-Apr-2019 ryo

Fix race conditions about pmap_page_protect() and pmap_enter().

while handling same PTE by these functions in same time, there
is a critical path that the number of valid PTEs and wire_count
are inconsistent, and it caused KASSERT.
Need to hold a pv_lock while modifying them.


# 1.38 20-Mar-2019 ryo

spinkle __printflike(), and use PRIxxx


# 1.37 19-Mar-2019 ryo

- add ddb command "machine ttbr" to dump MMU tables.
- tidy up descriptions, usages and messages.


# 1.36 19-Mar-2019 ryo

- free L1-L3 pages that has been emptied by pmap_remove().
- if no memories, pmap_enter will return correctly ENOMEM if PMAP_CANFAIL, or wait until available any memories if !PMAP_CANFAIL.

These changes improves the stability when we use a huge virtual memory spaces with mmap.


# 1.35 06-Feb-2019 ryo

improve pmap_remove
- don't lock/unlock per page in pmap_remove()
- speedup pte lookup for continuous addresses
- bring out pool_cache_put(&_pmap_pv_pool, pv) from lock/unlock section


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226
# 1.34 21-Dec-2018 ryo

- add workaround for Cavium ThunderX errata 27456.
- add cpufuncs table in cpu_info. each cpu clusters may have different erratum. (e.g. big.LITTLE)


Revision tags: pgoyette-compat-1126
# 1.33 01-Nov-2018 maxv

Add kASan support for aarch64. Stack tracking needs more investigation
and will come in a separate commit.

Reviewed by ryo@ jmcneill@ skrll@.


# 1.32 31-Oct-2018 ryo

invalidate icache correctly.
l3pte_executable() should be used for only valid pte.


Revision tags: pgoyette-compat-1020
# 1.31 18-Oct-2018 skrll

Provide generic start code that assumes the MMU is off and caches are
disabled as per the linux booting protocol for ARMv6 and ARMv7 boards.
u-boot image type should be changed to 'linux' for correct behaviour.

The new start code builds a minimal "bootstrap" L1PT with cached access
disabled and uses the same table for all processors. AP startup is
performed in less steps and more code is written in C.

The bootstrap tables and stack are placed into an (orphaned) section
"_init_memory" which is given to uvm when it is no longer used.

Various kernels have been converted to use this code and tested. Some
boards were provided by TNF. Thanks!

The GENERIC kernel now boots on boards using the TEGRA, SUNXI and EXYNOS
kernels. The GENERIC kernel will also work on RPI2 using u-boot.

Thanks to martin@ and aymeric@ for testing on parallella and nanosoc
respectively


# 1.30 14-Oct-2018 skrll

Use __nothing


# 1.29 12-Oct-2018 ryo

add initial support of COMPAT_NETBSD32 on AArch64.
arm ELF32 EABI binaries could be execute in AArch32 state on AArch64. A32 THUMB mode is not supported yet.


# 1.28 12-Oct-2018 ryo

- cleanup checking address ranges with IN_RANGE macro
- change PM_ADDR_CHECK macro to KASSERTMSG
- restore fast lookup cases with IN_RANGE macro for pmap_extract changed in my previous commit.


# 1.27 12-Oct-2018 ryo

rewrite pmap_pte_lookup() to share similar code.


# 1.26 04-Oct-2018 ryo

cleanup locore, and changed the way to map memories during boot.
- add functions bootpage_enter() and bootpage_alloc() to adapt various layout
of physical memory map. especially for 64bit physical memory layout.
pmapboot_alloc() allocates pagetable pages from _end[].
- changed to map only the required amount for PA=VA identity mapping
(kernel image, UART device, and FDT blob) with L2_BLOCK(2Mbyte).
- changing page permission for kernel image, and making KSEG mapping are done
at cpu_kernel_vm_init() instead of at locore.
- optimize PTE entries with PTE Contiguous bit. it is enabled on devmap only for now.

reviewed by skrll@, thanks.


# 1.25 04-Oct-2018 ryo

* define LX_BLKPAG_{OS,ATTR}_* for OS dependent PTE attributes in pmap.h
* cleanup macros


Revision tags: pgoyette-compat-0930
# 1.24 17-Sep-2018 ryo

delete debug printf and KASSERT.


# 1.23 10-Sep-2018 maxv

Replace KDASSERT by panic.


# 1.22 10-Sep-2018 maxv

Rename _pmap_alloc_pdp -> pmap_alloc_pdp, and make it public.


# 1.21 10-Sep-2018 ryo

cleanup aarch64 mpstart and fdt bootstrap
* arm_cpu_hatch_arg is a bad idea. avoid serializing CPU startup, and eliminate arm_cpu_hatch_arg.
in mpstart, resolve own cpu index using array of cpu_mpidr[] (aarch64)
* add support fdt enable-method "spin-table"
* add support fdt enable-method "brcm,bcm2836-smp" (for 32bit RaspberryPi)
* use arm_fdt_cpu_bootstrap() instead of psci_fdt_bootstrap()
* rename "arm/fdt/psci_fdt.h" to "arm/fdt/psci_fdtvar.h" because of conflict of include file for needs-flag
* add devmap for cpu spin-table of raspberrypi3/aarch64
* no need to force hatch APs for raspberrypi3/arm32 ifndef MULTIPROCESSOR.
* fix to work pmap_extract(kerneltext/data/bss) even if before calling pmap_bootstrap

idea to use cpu_mpidr[] by jmcneill@. reviewd by skrll@. thanks.


Revision tags: pgoyette-compat-0906
# 1.20 27-Aug-2018 ryo

need to add VM_PROT_READ when pmap_kenter_pa(va, pa, VM_PROT_WRITE, 0) or pmap_kenter_pa(va, pa, VM_PROT_EXECUTE, 0).
VM_PROT_READ is treated as an access permission inernally.


# 1.19 11-Aug-2018 ryo

change to minimum invalidation of TLB.
specifying not only va but also asid, and not invalidate L0-L2 entry using tlbi_*_ll() if needed.


# 1.18 10-Aug-2018 ryo

treat kernel-exec attr and user-exec attr separately.
kernel cannot execute userland exec page, and user cannot execute kernel page.


# 1.17 06-Aug-2018 ryo

set kernel text/rodata readonly by default.
add function db_write_text() for setting ddb breakpoint.


# 1.16 31-Jul-2018 skrll

Define and use VPRINTF


Revision tags: pgoyette-compat-0728
# 1.15 27-Jul-2018 ryo

changes of pmap.c r1.13 seems to be unstable.
In order to invalidate icache, not to invalidate all icache,
but temporary to make the page writable and invalidate target address only.


# 1.14 24-Jul-2018 ryo

don't call pool_cache_put with locking pmap. pool_cache_put call pmap_kenter_pa internally.
(pool_cache_put_paddr -> pool_cache_put_slow -> pool_get -> pmap_kenter_pa)


# 1.13 23-Jul-2018 ryo

* fix icache invalidations.
* "ic ivau" (aarch64_icache_sync_range) with VA generates permission fault in some situations, therefore use KSEG address for now.


# 1.12 23-Jul-2018 ryo

rather than using flags to resolve nested locks, reserve pool_cache before locking.


# 1.11 21-Jul-2018 ryo

* avoid deadlock. mutex_owned() works only for adaptive lock, therefore we cannot use it for spinlock...
* add more NULL check
* clear pte when pmap_enter() fails


# 1.10 17-Jul-2018 ryo

Use __debugused


# 1.9 17-Jul-2018 christos

Add missing casts, remove unused variables.


# 1.8 09-Jul-2018 ryo

need locks in pmap_kremove() and pmap_fault_fixup()


Revision tags: phil-wifi-base pgoyette-compat-0625 pgoyette-compat-0521
# 1.7 20-May-2018 ryo

branches: 1.7.2;
pmap_enter() must update modified/referenced flags by 'flags' not 'prot'.


# 1.6 16-May-2018 ryo

Fix memory leak. it was leaking one page every pmap_create().
pm->pm_vmlist must be initialized before calling _pmap_alloc_pdp().


Revision tags: pgoyette-compat-0502
# 1.5 29-Apr-2018 ryo

fix KASSERT panic. pv_entry may not be exists in pvlist when pmap_remove().


# 1.4 29-Apr-2018 ryo

delete unused code


# 1.3 27-Apr-2018 ryo

fix instability behavior of bufcache on aarch64.
* fix to return correct ref/mod when PMAP_WIRED.
* changed to keep wired flags in pte instead of pv_entry, and cleanup.


Revision tags: pgoyette-compat-0422 pgoyette-compat-0415 pgoyette-compat-0407
# 1.2 01-Apr-2018 ryo

Add initial support for ARMv8 (AARCH64) (by nisimura@ and ryo@)

- sys/arch/evbarm64 is gone and integrated into sys/arch/evbarm. (by skrll@)
- add support fdt. evbarm/conf/GENERIC64 fdt (bcm2837,sunxi,tegra) based generic 64bit kernel config. (by skrll@, jmcneill@)


Revision tags: netbsd-8-2-RELEASE netbsd-8-1-RELEASE netbsd-8-1-RC1 netbsd-7-2-RELEASE netbsd-8-0-RELEASE netbsd-8-0-RC2 netbsd-8-0-RC1 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 netbsd-7-1-2-RELEASE pgoyette-compat-base netbsd-7-1-1-RELEASE tls-maxphys-base-20171202 matt-nb8-mediatek-base nick-nhusb-base-20170825 perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base pgoyette-localcount-20170320 netbsd-7-1-RELEASE netbsd-7-1-RC2 nick-nhusb-base-20170204 netbsd-7-nhusb-base-20170116 bouyer-socketcan-base pgoyette-localcount-20170107 netbsd-7-1-RC1 nick-nhusb-base-20161204 pgoyette-localcount-20161104 netbsd-7-0-2-RELEASE nick-nhusb-base-20161004 localcount-20160914 netbsd-7-nhusb-base pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907 nick-nhusb-base-20160529 netbsd-7-0-1-RELEASE nick-nhusb-base-20160422 nick-nhusb-base-20160319 nick-nhusb-base-20151226 netbsd-7-0-RELEASE nick-nhusb-base-20150921 netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 nick-nhusb-base-20150606 nick-nhusb-base-20150406 nick-nhusb-base tls-maxphys-base netbsd-7-base
# 1.1 10-Aug-2014 matt

branches: 1.1.4; 1.1.28;
Preliminary files for AARCH64 (64-bit ARM) support.
Enough for a distribution build.


# 1.86 12-Aug-2020 skrll

Part IV of ad's performance improvements for aarch64

- Implement pmap_growkernel(), and update kernel pmap's stats with atomics.

- Then, pmap_kenter_pa() and pmap_kremove() no longer need to allocate
memory nor take pm_lock, because they only modify L3 PTEs.

- Then, pm_lock and pp_lock can be adaptive mutexes at IPL_NONE which are
cheaper than spin mutexes.

- Take the pmap's lock in pmap_extract() if not the kernel's pmap, otherwise
pmap_extract() might see inconsistent state.


# 1.85 09-Aug-2020 skrll

Fix another UVMHIST so it doesn't use %s


# 1.84 16-Jul-2020 skrll

pmapboot_enter simplication
- bootpage_alloc in asm becomes pmapboot_pagealloc in C
- PMAPBOOT_ENTER_NOBLOCK is removed as it's not used
- PMAPBOOT_ENTER_NOOVERWRITE is removed as it's now always on
- physpage_allocator argument is removed as it's always
pmapboot_pagealloc
- Support for EARLYCONS without CONSADDR is removed so that the identity
map for CONSADDR is always known.

For the assembly files:
2 files changed, 40 insertions(+), 89 deletions(-)

LGTM ryo


# 1.83 04-Jul-2020 rin

Use tlen for temporary length variable instead of l, which is usually
used for struct lwp *.

No binary changes.


# 1.82 02-Jul-2020 rin

pmap_procwr(): sync icache even if p != curproc. This fixes applications
like GDB for arm32, that rewrite text of other process.

Thanks to ryo@ for discussion.


# 1.81 02-Jul-2020 rin

Set uvmexp.ncolors appropriately, which is required for some CPU
models with VIPT icache.

Otherwise, alias in virtual address results in inconsistent results,
at least for applications that rewrite text of other process, e.g.,
GDB for arm32.

Also, this hopefully fixes other unexpected failures due to alias.

Confirmed that there's no observable regression in performance;
difference in ``time make -j8'' for GENERIC64 kernel on BCM2837
with and without setting uvmexp.ncolors is within 0.1%.

Thanks to ryo@ for discussion.


# 1.80 27-Jun-2020 rin

Fix typo in name of evcnt(4) counter.


# 1.79 24-Jun-2020 ryo

Fix bug with incorrect range calculation when doing icache sync.
This is called by sysarch(ARM_SYNC_ICACHE) from aarch32 (compat_netbsd32) emul process.

pointed out by rin@, thanks.

XXX pullup-9


# 1.78 14-Jun-2020 ad

- Fix a lock order reversal in pmap_page_protect().

- Make sure pmap is always locked when updating stats; atomics no longer
needed to do that.

- Remove unneeded traversal of pv list in pmap_enter_pv().

- Shrink struct vm_page from 136 to 128 bytes (cache line sized) and struct
pv_entry from 48 to 32 bytes (power of 2 sized).

- Embed a pv_entry in each vm_page. This means PV entries don't need to
be allocated for private anonymous memory / COW pages / most UBC mappings.
Dynamic PV entries are then used only for stuff like shared libraries and
shared memory.

Proposed on port-arm@.


# 1.77 10-Jun-2020 ad

- Wired/resident stats shouldn't covered by PMAPCOUNTERS.
- Rename need_update_pv -> need_enter_pv.

Ok ryo@


# 1.76 01-Jun-2020 ryo

no need to make the PTE writable to do icache_sync, enough to accessible.


# 1.75 15-May-2020 skrll

Use __diagused


# 1.74 15-May-2020 tnn

fix non-diag build


# 1.73 14-May-2020 skrll

Use MUTEX_NODEBUG for PV locks as is commonly done. OK ryo.


# 1.72 13-May-2020 jmcneill

Implement pmap_extract_coherency


Revision tags: bouyer-xenpvh-base2 phil-wifi-20200421 bouyer-xenpvh-base1
# 1.71 18-Apr-2020 skrll

PMAP_DEBUG has been deleted on arm


# 1.70 13-Apr-2020 maxv

Add support for Branch Target Identification (BTI).

On the executable pages that have the GP (Guarded Page) bit, the semantic
of the "br" and "blr" instructions is changed: the CPU expects the first
instruction of the jump/call target to be "bti", and faults if it isn't.

We add the GP bit on the kernel .text pages (and incidentally the .rodata
pages, but we don't care). The compiler adds a "bti c" instruction at the
beginning of each C function. We modify the ENTRY() macros to manually add
"bti c" in the asm functions.

cpuswitch.S needs a specific change: with "br x27" the CPU expects "bti j",
which is bad because the functions begin with "bti c"; switch to "br x16",
for the CPU to accept "bti c".

BTI helps defend against JOP/COP. Tested on Qemu.


Revision tags: phil-wifi-20200411 bouyer-xenpvh-base
# 1.69 08-Apr-2020 ryo

branches: 1.69.2;
use PMAP_PAGE_INIT() to initialize mutex in pmap_page.

VM_MDPAGE_INIT() in pmap_free_pdp() had initialized pp_flags,
so it unintentionally cleared PMAP_PAGE_FLAGS_PV_TRACKED.
use PMAP_PAGE_INIT to avoid using PMAP_PAGE_FLAGS_PV_TRACKED.

pointed out by tnn@, thanks


Revision tags: phil-wifi-20200406
# 1.68 14-Mar-2020 ad

pmap_remove_all(): Return a boolean value to indicate the behaviour. If
true, all mappings have been removed, the pmap is totally cleared out, and
UVM can then avoid doing the work to call pmap_remove() for each map entry.
If false, either nothing has been done, or some helpful arch-specific voodoo
has taken place.


Revision tags: is-mlppp-base
# 1.67 02-Mar-2020 ryo

oops, fix incorrect usage of daif_enable() in my previous commit.


# 1.66 29-Feb-2020 ryo

Fix pmap to work correctly with tagged addresses

- when fault, untag from address before passing to uvm/pmap functions
- pmap_extract() checks more strictly and consider the address tag


# 1.65 29-Feb-2020 ryo

use pmapboot_enter_range()


Revision tags: ad-namecache-base3
# 1.64 10-Feb-2020 ryo

use LIST(3) instead of TAILQ(3) to save one word in struct vm_page and struct pmap.

pointed out by riastradh@. thanks


# 1.63 03-Feb-2020 ryo

add support pmap_pv(9)

Patch originally from jmcneill@. thanks


# 1.62 03-Feb-2020 ryo

separate struct vm_page_md into vm_page_md and pmap_page
for preparation pmap_pv(9)


Revision tags: ad-namecache-base2 ad-namecache-base1
# 1.61 09-Jan-2020 ryo

fix behaviour mmap()/mprotect() when passed only PROT_EXEC.

when mmap()/mprotect() with only PROT_EXEC, syscall will be successful,
but the page actually hadn't been mapped.
it should be mapped with PROT_READ|PROT_EXEC implicitly. (r-x)


Revision tags: ad-namecache-base
# 1.60 30-Dec-2019 skrll

branches: 1.60.2;
Update pmap_map_chunk to allow L[12] block mappings and L3 page mappings


# 1.59 30-Dec-2019 skrll

Remove unnecessary brackets and unwrap a conditional. Same code before
and after.


# 1.58 28-Dec-2019 jmcneill

Do not use Early Write Acknowledge for PCIe I/O and config space.


# 1.57 27-Dec-2019 jmcneill

Enable early write acknowledge for device memory mappings.


# 1.56 19-Dec-2019 skrll

G/C kasan_shadow_map call in pmap_enter

pmap_growkernel calls kasan_shadow_map for KVA


# 1.55 18-Dec-2019 ryo

atomic_add_16() is not used in pmap.c anymore. no need decl here.


# 1.54 18-Dec-2019 ryo

space to tab


# 1.53 14-Dec-2019 skrll

Fix build... wire_count probably doesn't need atomics


# 1.52 13-Dec-2019 skrll

Fix KASAN support by calling kasan_shadow_map in pmap_growkernel


# 1.51 10-Dec-2019 ad

pg->phys_addr -> VM_PAGE_TO_PHYS(pg)


Revision tags: phil-wifi-20191119
# 1.50 14-Nov-2019 maxv

Mark several kASan functions with __nothing, to avoid annoying #ifdefs.
Same as kCSan and kMSan.


# 1.49 14-Nov-2019 maxv

Don't include "opt_kasan.h" when there's already <sys/asan.h> included.


# 1.48 29-Oct-2019 maya

Define PMAP_NEED_PROCWR, providing strategically placed i-cache
synchronization where just-changed memory is about to be executed.

Fixes SIGILLs seen when running Mono 6 on QEMU Cortex-A57.

ok ryo


# 1.47 22-Sep-2019 jmcneill

Disable translation table walks using TTBR0 while changing its value and
when deactivating a pmap. Fixes stability issues on Ampere eMAG CPUs.


# 1.46 20-Sep-2019 ryo

ref/mod bit should be set according to 'flags' argument, not 'prot'. r1.44 was incomplete.


# 1.45 13-Sep-2019 ryo

In pmap_devmap_bootstrap(), cpu_earlydevice_va_p() must not return true until *all* devmap tables have been enabled.
console mapping may be present in the last table.


# 1.44 07-Sep-2019 ryo

- remove incorrect KASSERT. mmap(2) with prot=PROT_WRITE calls pmap_enter(..., PROT_WRITE) internally.
- fix to update page reference flags when only PROT_WRITE or PROT_EXECUTE specified


# 1.43 15-Aug-2019 skrll

Make pmap_db_pte_print more terse so it's quicker on serial consoles


# 1.42 12-Aug-2019 skrll

Use PMAP_DEV in DEVMAP_ENTRY rather than pmap_map_chunk. It's clearer and
means pmap_map_chunk can be made to map other memory types.


Revision tags: netbsd-9-base phil-wifi-20190609
# 1.41 17-May-2019 mrg

branches: 1.41.2;
apply some __diagused.


Revision tags: isaki-audio2-base
# 1.40 08-Apr-2019 ryo

- free empty page tables pages if reach a certain usage.
- need to lock at removing an old pg (_pmap_remove_pv) in _pmap_enter()


# 1.39 06-Apr-2019 ryo

Fix race conditions about pmap_page_protect() and pmap_enter().

while handling same PTE by these functions in same time, there
is a critical path that the number of valid PTEs and wire_count
are inconsistent, and it caused KASSERT.
Need to hold a pv_lock while modifying them.


# 1.38 20-Mar-2019 ryo

spinkle __printflike(), and use PRIxxx


# 1.37 19-Mar-2019 ryo

- add ddb command "machine ttbr" to dump MMU tables.
- tidy up descriptions, usages and messages.


# 1.36 19-Mar-2019 ryo

- free L1-L3 pages that has been emptied by pmap_remove().
- if no memories, pmap_enter will return correctly ENOMEM if PMAP_CANFAIL, or wait until available any memories if !PMAP_CANFAIL.

These changes improves the stability when we use a huge virtual memory spaces with mmap.


# 1.35 06-Feb-2019 ryo

improve pmap_remove
- don't lock/unlock per page in pmap_remove()
- speedup pte lookup for continuous addresses
- bring out pool_cache_put(&_pmap_pv_pool, pv) from lock/unlock section


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226
# 1.34 21-Dec-2018 ryo

- add workaround for Cavium ThunderX errata 27456.
- add cpufuncs table in cpu_info. each cpu clusters may have different erratum. (e.g. big.LITTLE)


Revision tags: pgoyette-compat-1126
# 1.33 01-Nov-2018 maxv

Add kASan support for aarch64. Stack tracking needs more investigation
and will come in a separate commit.

Reviewed by ryo@ jmcneill@ skrll@.


# 1.32 31-Oct-2018 ryo

invalidate icache correctly.
l3pte_executable() should be used for only valid pte.


Revision tags: pgoyette-compat-1020
# 1.31 18-Oct-2018 skrll

Provide generic start code that assumes the MMU is off and caches are
disabled as per the linux booting protocol for ARMv6 and ARMv7 boards.
u-boot image type should be changed to 'linux' for correct behaviour.

The new start code builds a minimal "bootstrap" L1PT with cached access
disabled and uses the same table for all processors. AP startup is
performed in less steps and more code is written in C.

The bootstrap tables and stack are placed into an (orphaned) section
"_init_memory" which is given to uvm when it is no longer used.

Various kernels have been converted to use this code and tested. Some
boards were provided by TNF. Thanks!

The GENERIC kernel now boots on boards using the TEGRA, SUNXI and EXYNOS
kernels. The GENERIC kernel will also work on RPI2 using u-boot.

Thanks to martin@ and aymeric@ for testing on parallella and nanosoc
respectively


# 1.30 14-Oct-2018 skrll

Use __nothing


# 1.29 12-Oct-2018 ryo

add initial support of COMPAT_NETBSD32 on AArch64.
arm ELF32 EABI binaries could be execute in AArch32 state on AArch64. A32 THUMB mode is not supported yet.


# 1.28 12-Oct-2018 ryo

- cleanup checking address ranges with IN_RANGE macro
- change PM_ADDR_CHECK macro to KASSERTMSG
- restore fast lookup cases with IN_RANGE macro for pmap_extract changed in my previous commit.


# 1.27 12-Oct-2018 ryo

rewrite pmap_pte_lookup() to share similar code.


# 1.26 04-Oct-2018 ryo

cleanup locore, and changed the way to map memories during boot.
- add functions bootpage_enter() and bootpage_alloc() to adapt various layout
of physical memory map. especially for 64bit physical memory layout.
pmapboot_alloc() allocates pagetable pages from _end[].
- changed to map only the required amount for PA=VA identity mapping
(kernel image, UART device, and FDT blob) with L2_BLOCK(2Mbyte).
- changing page permission for kernel image, and making KSEG mapping are done
at cpu_kernel_vm_init() instead of at locore.
- optimize PTE entries with PTE Contiguous bit. it is enabled on devmap only for now.

reviewed by skrll@, thanks.


# 1.25 04-Oct-2018 ryo

* define LX_BLKPAG_{OS,ATTR}_* for OS dependent PTE attributes in pmap.h
* cleanup macros


Revision tags: pgoyette-compat-0930
# 1.24 17-Sep-2018 ryo

delete debug printf and KASSERT.


# 1.23 10-Sep-2018 maxv

Replace KDASSERT by panic.


# 1.22 10-Sep-2018 maxv

Rename _pmap_alloc_pdp -> pmap_alloc_pdp, and make it public.


# 1.21 10-Sep-2018 ryo

cleanup aarch64 mpstart and fdt bootstrap
* arm_cpu_hatch_arg is a bad idea. avoid serializing CPU startup, and eliminate arm_cpu_hatch_arg.
in mpstart, resolve own cpu index using array of cpu_mpidr[] (aarch64)
* add support fdt enable-method "spin-table"
* add support fdt enable-method "brcm,bcm2836-smp" (for 32bit RaspberryPi)
* use arm_fdt_cpu_bootstrap() instead of psci_fdt_bootstrap()
* rename "arm/fdt/psci_fdt.h" to "arm/fdt/psci_fdtvar.h" because of conflict of include file for needs-flag
* add devmap for cpu spin-table of raspberrypi3/aarch64
* no need to force hatch APs for raspberrypi3/arm32 ifndef MULTIPROCESSOR.
* fix to work pmap_extract(kerneltext/data/bss) even if before calling pmap_bootstrap

idea to use cpu_mpidr[] by jmcneill@. reviewd by skrll@. thanks.


Revision tags: pgoyette-compat-0906
# 1.20 27-Aug-2018 ryo

need to add VM_PROT_READ when pmap_kenter_pa(va, pa, VM_PROT_WRITE, 0) or pmap_kenter_pa(va, pa, VM_PROT_EXECUTE, 0).
VM_PROT_READ is treated as an access permission inernally.


# 1.19 11-Aug-2018 ryo

change to minimum invalidation of TLB.
specifying not only va but also asid, and not invalidate L0-L2 entry using tlbi_*_ll() if needed.


# 1.18 10-Aug-2018 ryo

treat kernel-exec attr and user-exec attr separately.
kernel cannot execute userland exec page, and user cannot execute kernel page.


# 1.17 06-Aug-2018 ryo

set kernel text/rodata readonly by default.
add function db_write_text() for setting ddb breakpoint.


# 1.16 31-Jul-2018 skrll

Define and use VPRINTF


Revision tags: pgoyette-compat-0728
# 1.15 27-Jul-2018 ryo

changes of pmap.c r1.13 seems to be unstable.
In order to invalidate icache, not to invalidate all icache,
but temporary to make the page writable and invalidate target address only.


# 1.14 24-Jul-2018 ryo

don't call pool_cache_put with locking pmap. pool_cache_put call pmap_kenter_pa internally.
(pool_cache_put_paddr -> pool_cache_put_slow -> pool_get -> pmap_kenter_pa)


# 1.13 23-Jul-2018 ryo

* fix icache invalidations.
* "ic ivau" (aarch64_icache_sync_range) with VA generates permission fault in some situations, therefore use KSEG address for now.


# 1.12 23-Jul-2018 ryo

rather than using flags to resolve nested locks, reserve pool_cache before locking.


# 1.11 21-Jul-2018 ryo

* avoid deadlock. mutex_owned() works only for adaptive lock, therefore we cannot use it for spinlock...
* add more NULL check
* clear pte when pmap_enter() fails


# 1.10 17-Jul-2018 ryo

Use __debugused


# 1.9 17-Jul-2018 christos

Add missing casts, remove unused variables.


# 1.8 09-Jul-2018 ryo

need locks in pmap_kremove() and pmap_fault_fixup()


Revision tags: phil-wifi-base pgoyette-compat-0625 pgoyette-compat-0521
# 1.7 20-May-2018 ryo

branches: 1.7.2;
pmap_enter() must update modified/referenced flags by 'flags' not 'prot'.


# 1.6 16-May-2018 ryo

Fix memory leak. it was leaking one page every pmap_create().
pm->pm_vmlist must be initialized before calling _pmap_alloc_pdp().


Revision tags: pgoyette-compat-0502
# 1.5 29-Apr-2018 ryo

fix KASSERT panic. pv_entry may not be exists in pvlist when pmap_remove().


# 1.4 29-Apr-2018 ryo

delete unused code


# 1.3 27-Apr-2018 ryo

fix instability behavior of bufcache on aarch64.
* fix to return correct ref/mod when PMAP_WIRED.
* changed to keep wired flags in pte instead of pv_entry, and cleanup.


Revision tags: pgoyette-compat-0422 pgoyette-compat-0415 pgoyette-compat-0407
# 1.2 01-Apr-2018 ryo

Add initial support for ARMv8 (AARCH64) (by nisimura@ and ryo@)

- sys/arch/evbarm64 is gone and integrated into sys/arch/evbarm. (by skrll@)
- add support fdt. evbarm/conf/GENERIC64 fdt (bcm2837,sunxi,tegra) based generic 64bit kernel config. (by skrll@, jmcneill@)


Revision tags: netbsd-8-2-RELEASE netbsd-8-1-RELEASE netbsd-8-1-RC1 netbsd-7-2-RELEASE netbsd-8-0-RELEASE netbsd-8-0-RC2 netbsd-8-0-RC1 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 netbsd-7-1-2-RELEASE pgoyette-compat-base netbsd-7-1-1-RELEASE tls-maxphys-base-20171202 matt-nb8-mediatek-base nick-nhusb-base-20170825 perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base pgoyette-localcount-20170320 netbsd-7-1-RELEASE netbsd-7-1-RC2 nick-nhusb-base-20170204 netbsd-7-nhusb-base-20170116 bouyer-socketcan-base pgoyette-localcount-20170107 netbsd-7-1-RC1 nick-nhusb-base-20161204 pgoyette-localcount-20161104 netbsd-7-0-2-RELEASE nick-nhusb-base-20161004 localcount-20160914 netbsd-7-nhusb-base pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907 nick-nhusb-base-20160529 netbsd-7-0-1-RELEASE nick-nhusb-base-20160422 nick-nhusb-base-20160319 nick-nhusb-base-20151226 netbsd-7-0-RELEASE nick-nhusb-base-20150921 netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 nick-nhusb-base-20150606 nick-nhusb-base-20150406 nick-nhusb-base tls-maxphys-base netbsd-7-base
# 1.1 10-Aug-2014 matt

branches: 1.1.4; 1.1.28;
Preliminary files for AARCH64 (64-bit ARM) support.
Enough for a distribution build.


# 1.85 09-Aug-2020 skrll

Fix another UVMHIST so it doesn't use %s


# 1.84 16-Jul-2020 skrll

pmapboot_enter simplication
- bootpage_alloc in asm becomes pmapboot_pagealloc in C
- PMAPBOOT_ENTER_NOBLOCK is removed as it's not used
- PMAPBOOT_ENTER_NOOVERWRITE is removed as it's now always on
- physpage_allocator argument is removed as it's always
pmapboot_pagealloc
- Support for EARLYCONS without CONSADDR is removed so that the identity
map for CONSADDR is always known.

For the assembly files:
2 files changed, 40 insertions(+), 89 deletions(-)

LGTM ryo


# 1.83 04-Jul-2020 rin

Use tlen for temporary length variable instead of l, which is usually
used for struct lwp *.

No binary changes.


# 1.82 02-Jul-2020 rin

pmap_procwr(): sync icache even if p != curproc. This fixes applications
like GDB for arm32, that rewrite text of other process.

Thanks to ryo@ for discussion.


# 1.81 02-Jul-2020 rin

Set uvmexp.ncolors appropriately, which is required for some CPU
models with VIPT icache.

Otherwise, alias in virtual address results in inconsistent results,
at least for applications that rewrite text of other process, e.g.,
GDB for arm32.

Also, this hopefully fixes other unexpected failures due to alias.

Confirmed that there's no observable regression in performance;
difference in ``time make -j8'' for GENERIC64 kernel on BCM2837
with and without setting uvmexp.ncolors is within 0.1%.

Thanks to ryo@ for discussion.


# 1.80 27-Jun-2020 rin

Fix typo in name of evcnt(4) counter.


# 1.79 24-Jun-2020 ryo

Fix bug with incorrect range calculation when doing icache sync.
This is called by sysarch(ARM_SYNC_ICACHE) from aarch32 (compat_netbsd32) emul process.

pointed out by rin@, thanks.

XXX pullup-9


# 1.78 14-Jun-2020 ad

- Fix a lock order reversal in pmap_page_protect().

- Make sure pmap is always locked when updating stats; atomics no longer
needed to do that.

- Remove unneeded traversal of pv list in pmap_enter_pv().

- Shrink struct vm_page from 136 to 128 bytes (cache line sized) and struct
pv_entry from 48 to 32 bytes (power of 2 sized).

- Embed a pv_entry in each vm_page. This means PV entries don't need to
be allocated for private anonymous memory / COW pages / most UBC mappings.
Dynamic PV entries are then used only for stuff like shared libraries and
shared memory.

Proposed on port-arm@.


# 1.77 10-Jun-2020 ad

- Wired/resident stats shouldn't covered by PMAPCOUNTERS.
- Rename need_update_pv -> need_enter_pv.

Ok ryo@


# 1.76 01-Jun-2020 ryo

no need to make the PTE writable to do icache_sync, enough to accessible.


# 1.75 15-May-2020 skrll

Use __diagused


# 1.74 15-May-2020 tnn

fix non-diag build


# 1.73 14-May-2020 skrll

Use MUTEX_NODEBUG for PV locks as is commonly done. OK ryo.


# 1.72 13-May-2020 jmcneill

Implement pmap_extract_coherency


Revision tags: bouyer-xenpvh-base2 phil-wifi-20200421 bouyer-xenpvh-base1
# 1.71 18-Apr-2020 skrll

PMAP_DEBUG has been deleted on arm


# 1.70 13-Apr-2020 maxv

Add support for Branch Target Identification (BTI).

On the executable pages that have the GP (Guarded Page) bit, the semantic
of the "br" and "blr" instructions is changed: the CPU expects the first
instruction of the jump/call target to be "bti", and faults if it isn't.

We add the GP bit on the kernel .text pages (and incidentally the .rodata
pages, but we don't care). The compiler adds a "bti c" instruction at the
beginning of each C function. We modify the ENTRY() macros to manually add
"bti c" in the asm functions.

cpuswitch.S needs a specific change: with "br x27" the CPU expects "bti j",
which is bad because the functions begin with "bti c"; switch to "br x16",
for the CPU to accept "bti c".

BTI helps defend against JOP/COP. Tested on Qemu.


Revision tags: phil-wifi-20200411 bouyer-xenpvh-base
# 1.69 08-Apr-2020 ryo

branches: 1.69.2;
use PMAP_PAGE_INIT() to initialize mutex in pmap_page.

VM_MDPAGE_INIT() in pmap_free_pdp() had initialized pp_flags,
so it unintentionally cleared PMAP_PAGE_FLAGS_PV_TRACKED.
use PMAP_PAGE_INIT to avoid using PMAP_PAGE_FLAGS_PV_TRACKED.

pointed out by tnn@, thanks


Revision tags: phil-wifi-20200406
# 1.68 14-Mar-2020 ad

pmap_remove_all(): Return a boolean value to indicate the behaviour. If
true, all mappings have been removed, the pmap is totally cleared out, and
UVM can then avoid doing the work to call pmap_remove() for each map entry.
If false, either nothing has been done, or some helpful arch-specific voodoo
has taken place.


Revision tags: is-mlppp-base
# 1.67 02-Mar-2020 ryo

oops, fix incorrect usage of daif_enable() in my previous commit.


# 1.66 29-Feb-2020 ryo

Fix pmap to work correctly with tagged addresses

- when fault, untag from address before passing to uvm/pmap functions
- pmap_extract() checks more strictly and consider the address tag


# 1.65 29-Feb-2020 ryo

use pmapboot_enter_range()


Revision tags: ad-namecache-base3
# 1.64 10-Feb-2020 ryo

use LIST(3) instead of TAILQ(3) to save one word in struct vm_page and struct pmap.

pointed out by riastradh@. thanks


# 1.63 03-Feb-2020 ryo

add support pmap_pv(9)

Patch originally from jmcneill@. thanks


# 1.62 03-Feb-2020 ryo

separate struct vm_page_md into vm_page_md and pmap_page
for preparation pmap_pv(9)


Revision tags: ad-namecache-base2 ad-namecache-base1
# 1.61 09-Jan-2020 ryo

fix behaviour mmap()/mprotect() when passed only PROT_EXEC.

when mmap()/mprotect() with only PROT_EXEC, syscall will be successful,
but the page actually hadn't been mapped.
it should be mapped with PROT_READ|PROT_EXEC implicitly. (r-x)


Revision tags: ad-namecache-base
# 1.60 30-Dec-2019 skrll

branches: 1.60.2;
Update pmap_map_chunk to allow L[12] block mappings and L3 page mappings


# 1.59 30-Dec-2019 skrll

Remove unnecessary brackets and unwrap a conditional. Same code before
and after.


# 1.58 28-Dec-2019 jmcneill

Do not use Early Write Acknowledge for PCIe I/O and config space.


# 1.57 27-Dec-2019 jmcneill

Enable early write acknowledge for device memory mappings.


# 1.56 19-Dec-2019 skrll

G/C kasan_shadow_map call in pmap_enter

pmap_growkernel calls kasan_shadow_map for KVA


# 1.55 18-Dec-2019 ryo

atomic_add_16() is not used in pmap.c anymore. no need decl here.


# 1.54 18-Dec-2019 ryo

space to tab


# 1.53 14-Dec-2019 skrll

Fix build... wire_count probably doesn't need atomics


# 1.52 13-Dec-2019 skrll

Fix KASAN support by calling kasan_shadow_map in pmap_growkernel


# 1.51 10-Dec-2019 ad

pg->phys_addr -> VM_PAGE_TO_PHYS(pg)


Revision tags: phil-wifi-20191119
# 1.50 14-Nov-2019 maxv

Mark several kASan functions with __nothing, to avoid annoying #ifdefs.
Same as kCSan and kMSan.


# 1.49 14-Nov-2019 maxv

Don't include "opt_kasan.h" when there's already <sys/asan.h> included.


# 1.48 29-Oct-2019 maya

Define PMAP_NEED_PROCWR, providing strategically placed i-cache
synchronization where just-changed memory is about to be executed.

Fixes SIGILLs seen when running Mono 6 on QEMU Cortex-A57.

ok ryo


# 1.47 22-Sep-2019 jmcneill

Disable translation table walks using TTBR0 while changing its value and
when deactivating a pmap. Fixes stability issues on Ampere eMAG CPUs.


# 1.46 20-Sep-2019 ryo

ref/mod bit should be set according to 'flags' argument, not 'prot'. r1.44 was incomplete.


# 1.45 13-Sep-2019 ryo

In pmap_devmap_bootstrap(), cpu_earlydevice_va_p() must not return true until *all* devmap tables have been enabled.
console mapping may be present in the last table.


# 1.44 07-Sep-2019 ryo

- remove incorrect KASSERT. mmap(2) with prot=PROT_WRITE calls pmap_enter(..., PROT_WRITE) internally.
- fix to update page reference flags when only PROT_WRITE or PROT_EXECUTE specified


# 1.43 15-Aug-2019 skrll

Make pmap_db_pte_print more terse so it's quicker on serial consoles


# 1.42 12-Aug-2019 skrll

Use PMAP_DEV in DEVMAP_ENTRY rather than pmap_map_chunk. It's clearer and
means pmap_map_chunk can be made to map other memory types.


Revision tags: netbsd-9-base phil-wifi-20190609
# 1.41 17-May-2019 mrg

branches: 1.41.2;
apply some __diagused.


Revision tags: isaki-audio2-base
# 1.40 08-Apr-2019 ryo

- free empty page tables pages if reach a certain usage.
- need to lock at removing an old pg (_pmap_remove_pv) in _pmap_enter()


# 1.39 06-Apr-2019 ryo

Fix race conditions about pmap_page_protect() and pmap_enter().

while handling same PTE by these functions in same time, there
is a critical path that the number of valid PTEs and wire_count
are inconsistent, and it caused KASSERT.
Need to hold a pv_lock while modifying them.


# 1.38 20-Mar-2019 ryo

spinkle __printflike(), and use PRIxxx


# 1.37 19-Mar-2019 ryo

- add ddb command "machine ttbr" to dump MMU tables.
- tidy up descriptions, usages and messages.


# 1.36 19-Mar-2019 ryo

- free L1-L3 pages that has been emptied by pmap_remove().
- if no memories, pmap_enter will return correctly ENOMEM if PMAP_CANFAIL, or wait until available any memories if !PMAP_CANFAIL.

These changes improves the stability when we use a huge virtual memory spaces with mmap.


# 1.35 06-Feb-2019 ryo

improve pmap_remove
- don't lock/unlock per page in pmap_remove()
- speedup pte lookup for continuous addresses
- bring out pool_cache_put(&_pmap_pv_pool, pv) from lock/unlock section


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226
# 1.34 21-Dec-2018 ryo

- add workaround for Cavium ThunderX errata 27456.
- add cpufuncs table in cpu_info. each cpu clusters may have different erratum. (e.g. big.LITTLE)


Revision tags: pgoyette-compat-1126
# 1.33 01-Nov-2018 maxv

Add kASan support for aarch64. Stack tracking needs more investigation
and will come in a separate commit.

Reviewed by ryo@ jmcneill@ skrll@.


# 1.32 31-Oct-2018 ryo

invalidate icache correctly.
l3pte_executable() should be used for only valid pte.


Revision tags: pgoyette-compat-1020
# 1.31 18-Oct-2018 skrll

Provide generic start code that assumes the MMU is off and caches are
disabled as per the linux booting protocol for ARMv6 and ARMv7 boards.
u-boot image type should be changed to 'linux' for correct behaviour.

The new start code builds a minimal "bootstrap" L1PT with cached access
disabled and uses the same table for all processors. AP startup is
performed in less steps and more code is written in C.

The bootstrap tables and stack are placed into an (orphaned) section
"_init_memory" which is given to uvm when it is no longer used.

Various kernels have been converted to use this code and tested. Some
boards were provided by TNF. Thanks!

The GENERIC kernel now boots on boards using the TEGRA, SUNXI and EXYNOS
kernels. The GENERIC kernel will also work on RPI2 using u-boot.

Thanks to martin@ and aymeric@ for testing on parallella and nanosoc
respectively


# 1.30 14-Oct-2018 skrll

Use __nothing


# 1.29 12-Oct-2018 ryo

add initial support of COMPAT_NETBSD32 on AArch64.
arm ELF32 EABI binaries could be execute in AArch32 state on AArch64. A32 THUMB mode is not supported yet.


# 1.28 12-Oct-2018 ryo

- cleanup checking address ranges with IN_RANGE macro
- change PM_ADDR_CHECK macro to KASSERTMSG
- restore fast lookup cases with IN_RANGE macro for pmap_extract changed in my previous commit.


# 1.27 12-Oct-2018 ryo

rewrite pmap_pte_lookup() to share similar code.


# 1.26 04-Oct-2018 ryo

cleanup locore, and changed the way to map memories during boot.
- add functions bootpage_enter() and bootpage_alloc() to adapt various layout
of physical memory map. especially for 64bit physical memory layout.
pmapboot_alloc() allocates pagetable pages from _end[].
- changed to map only the required amount for PA=VA identity mapping
(kernel image, UART device, and FDT blob) with L2_BLOCK(2Mbyte).
- changing page permission for kernel image, and making KSEG mapping are done
at cpu_kernel_vm_init() instead of at locore.
- optimize PTE entries with PTE Contiguous bit. it is enabled on devmap only for now.

reviewed by skrll@, thanks.


# 1.25 04-Oct-2018 ryo

* define LX_BLKPAG_{OS,ATTR}_* for OS dependent PTE attributes in pmap.h
* cleanup macros


Revision tags: pgoyette-compat-0930
# 1.24 17-Sep-2018 ryo

delete debug printf and KASSERT.


# 1.23 10-Sep-2018 maxv

Replace KDASSERT by panic.


# 1.22 10-Sep-2018 maxv

Rename _pmap_alloc_pdp -> pmap_alloc_pdp, and make it public.


# 1.21 10-Sep-2018 ryo

cleanup aarch64 mpstart and fdt bootstrap
* arm_cpu_hatch_arg is a bad idea. avoid serializing CPU startup, and eliminate arm_cpu_hatch_arg.
in mpstart, resolve own cpu index using array of cpu_mpidr[] (aarch64)
* add support fdt enable-method "spin-table"
* add support fdt enable-method "brcm,bcm2836-smp" (for 32bit RaspberryPi)
* use arm_fdt_cpu_bootstrap() instead of psci_fdt_bootstrap()
* rename "arm/fdt/psci_fdt.h" to "arm/fdt/psci_fdtvar.h" because of conflict of include file for needs-flag
* add devmap for cpu spin-table of raspberrypi3/aarch64
* no need to force hatch APs for raspberrypi3/arm32 ifndef MULTIPROCESSOR.
* fix to work pmap_extract(kerneltext/data/bss) even if before calling pmap_bootstrap

idea to use cpu_mpidr[] by jmcneill@. reviewd by skrll@. thanks.


Revision tags: pgoyette-compat-0906
# 1.20 27-Aug-2018 ryo

need to add VM_PROT_READ when pmap_kenter_pa(va, pa, VM_PROT_WRITE, 0) or pmap_kenter_pa(va, pa, VM_PROT_EXECUTE, 0).
VM_PROT_READ is treated as an access permission inernally.


# 1.19 11-Aug-2018 ryo

change to minimum invalidation of TLB.
specifying not only va but also asid, and not invalidate L0-L2 entry using tlbi_*_ll() if needed.


# 1.18 10-Aug-2018 ryo

treat kernel-exec attr and user-exec attr separately.
kernel cannot execute userland exec page, and user cannot execute kernel page.


# 1.17 06-Aug-2018 ryo

set kernel text/rodata readonly by default.
add function db_write_text() for setting ddb breakpoint.


# 1.16 31-Jul-2018 skrll

Define and use VPRINTF


Revision tags: pgoyette-compat-0728
# 1.15 27-Jul-2018 ryo

changes of pmap.c r1.13 seems to be unstable.
In order to invalidate icache, not to invalidate all icache,
but temporary to make the page writable and invalidate target address only.


# 1.14 24-Jul-2018 ryo

don't call pool_cache_put with locking pmap. pool_cache_put call pmap_kenter_pa internally.
(pool_cache_put_paddr -> pool_cache_put_slow -> pool_get -> pmap_kenter_pa)


# 1.13 23-Jul-2018 ryo

* fix icache invalidations.
* "ic ivau" (aarch64_icache_sync_range) with VA generates permission fault in some situations, therefore use KSEG address for now.


# 1.12 23-Jul-2018 ryo

rather than using flags to resolve nested locks, reserve pool_cache before locking.


# 1.11 21-Jul-2018 ryo

* avoid deadlock. mutex_owned() works only for adaptive lock, therefore we cannot use it for spinlock...
* add more NULL check
* clear pte when pmap_enter() fails


# 1.10 17-Jul-2018 ryo

Use __debugused


# 1.9 17-Jul-2018 christos

Add missing casts, remove unused variables.


# 1.8 09-Jul-2018 ryo

need locks in pmap_kremove() and pmap_fault_fixup()


Revision tags: phil-wifi-base pgoyette-compat-0625 pgoyette-compat-0521
# 1.7 20-May-2018 ryo

branches: 1.7.2;
pmap_enter() must update modified/referenced flags by 'flags' not 'prot'.


# 1.6 16-May-2018 ryo

Fix memory leak. it was leaking one page every pmap_create().
pm->pm_vmlist must be initialized before calling _pmap_alloc_pdp().


Revision tags: pgoyette-compat-0502
# 1.5 29-Apr-2018 ryo

fix KASSERT panic. pv_entry may not be exists in pvlist when pmap_remove().


# 1.4 29-Apr-2018 ryo

delete unused code


# 1.3 27-Apr-2018 ryo

fix instability behavior of bufcache on aarch64.
* fix to return correct ref/mod when PMAP_WIRED.
* changed to keep wired flags in pte instead of pv_entry, and cleanup.


Revision tags: pgoyette-compat-0422 pgoyette-compat-0415 pgoyette-compat-0407
# 1.2 01-Apr-2018 ryo

Add initial support for ARMv8 (AARCH64) (by nisimura@ and ryo@)

- sys/arch/evbarm64 is gone and integrated into sys/arch/evbarm. (by skrll@)
- add support fdt. evbarm/conf/GENERIC64 fdt (bcm2837,sunxi,tegra) based generic 64bit kernel config. (by skrll@, jmcneill@)


Revision tags: netbsd-8-2-RELEASE netbsd-8-1-RELEASE netbsd-8-1-RC1 netbsd-7-2-RELEASE netbsd-8-0-RELEASE netbsd-8-0-RC2 netbsd-8-0-RC1 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 netbsd-7-1-2-RELEASE pgoyette-compat-base netbsd-7-1-1-RELEASE tls-maxphys-base-20171202 matt-nb8-mediatek-base nick-nhusb-base-20170825 perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base pgoyette-localcount-20170320 netbsd-7-1-RELEASE netbsd-7-1-RC2 nick-nhusb-base-20170204 netbsd-7-nhusb-base-20170116 bouyer-socketcan-base pgoyette-localcount-20170107 netbsd-7-1-RC1 nick-nhusb-base-20161204 pgoyette-localcount-20161104 netbsd-7-0-2-RELEASE nick-nhusb-base-20161004 localcount-20160914 netbsd-7-nhusb-base pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907 nick-nhusb-base-20160529 netbsd-7-0-1-RELEASE nick-nhusb-base-20160422 nick-nhusb-base-20160319 nick-nhusb-base-20151226 netbsd-7-0-RELEASE nick-nhusb-base-20150921 netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 nick-nhusb-base-20150606 nick-nhusb-base-20150406 nick-nhusb-base tls-maxphys-base netbsd-7-base
# 1.1 10-Aug-2014 matt

branches: 1.1.4; 1.1.28;
Preliminary files for AARCH64 (64-bit ARM) support.
Enough for a distribution build.


# 1.84 16-Jul-2020 skrll

pmapboot_enter simplication
- bootpage_alloc in asm becomes pmapboot_pagealloc in C
- PMAPBOOT_ENTER_NOBLOCK is removed as it's not used
- PMAPBOOT_ENTER_NOOVERWRITE is removed as it's now always on
- physpage_allocator argument is removed as it's always
pmapboot_pagealloc
- Support for EARLYCONS without CONSADDR is removed so that the identity
map for CONSADDR is always known.

For the assembly files:
2 files changed, 40 insertions(+), 89 deletions(-)

LGTM ryo


# 1.83 04-Jul-2020 rin

Use tlen for temporary length variable instead of l, which is usually
used for struct lwp *.

No binary changes.


# 1.82 02-Jul-2020 rin

pmap_procwr(): sync icache even if p != curproc. This fixes applications
like GDB for arm32, that rewrite text of other process.

Thanks to ryo@ for discussion.


# 1.81 02-Jul-2020 rin

Set uvmexp.ncolors appropriately, which is required for some CPU
models with VIPT icache.

Otherwise, alias in virtual address results in inconsistent results,
at least for applications that rewrite text of other process, e.g.,
GDB for arm32.

Also, this hopefully fixes other unexpected failures due to alias.

Confirmed that there's no observable regression in performance;
difference in ``time make -j8'' for GENERIC64 kernel on BCM2837
with and without setting uvmexp.ncolors is within 0.1%.

Thanks to ryo@ for discussion.


# 1.80 27-Jun-2020 rin

Fix typo in name of evcnt(4) counter.


# 1.79 24-Jun-2020 ryo

Fix bug with incorrect range calculation when doing icache sync.
This is called by sysarch(ARM_SYNC_ICACHE) from aarch32 (compat_netbsd32) emul process.

pointed out by rin@, thanks.

XXX pullup-9


# 1.78 14-Jun-2020 ad

- Fix a lock order reversal in pmap_page_protect().

- Make sure pmap is always locked when updating stats; atomics no longer
needed to do that.

- Remove unneeded traversal of pv list in pmap_enter_pv().

- Shrink struct vm_page from 136 to 128 bytes (cache line sized) and struct
pv_entry from 48 to 32 bytes (power of 2 sized).

- Embed a pv_entry in each vm_page. This means PV entries don't need to
be allocated for private anonymous memory / COW pages / most UBC mappings.
Dynamic PV entries are then used only for stuff like shared libraries and
shared memory.

Proposed on port-arm@.


# 1.77 10-Jun-2020 ad

- Wired/resident stats shouldn't covered by PMAPCOUNTERS.
- Rename need_update_pv -> need_enter_pv.

Ok ryo@


# 1.76 01-Jun-2020 ryo

no need to make the PTE writable to do icache_sync, enough to accessible.


# 1.75 15-May-2020 skrll

Use __diagused


# 1.74 15-May-2020 tnn

fix non-diag build


# 1.73 14-May-2020 skrll

Use MUTEX_NODEBUG for PV locks as is commonly done. OK ryo.


# 1.72 13-May-2020 jmcneill

Implement pmap_extract_coherency


Revision tags: bouyer-xenpvh-base2 phil-wifi-20200421 bouyer-xenpvh-base1
# 1.71 18-Apr-2020 skrll

PMAP_DEBUG has been deleted on arm


# 1.70 13-Apr-2020 maxv

Add support for Branch Target Identification (BTI).

On the executable pages that have the GP (Guarded Page) bit, the semantic
of the "br" and "blr" instructions is changed: the CPU expects the first
instruction of the jump/call target to be "bti", and faults if it isn't.

We add the GP bit on the kernel .text pages (and incidentally the .rodata
pages, but we don't care). The compiler adds a "bti c" instruction at the
beginning of each C function. We modify the ENTRY() macros to manually add
"bti c" in the asm functions.

cpuswitch.S needs a specific change: with "br x27" the CPU expects "bti j",
which is bad because the functions begin with "bti c"; switch to "br x16",
for the CPU to accept "bti c".

BTI helps defend against JOP/COP. Tested on Qemu.


Revision tags: phil-wifi-20200411 bouyer-xenpvh-base
# 1.69 08-Apr-2020 ryo

branches: 1.69.2;
use PMAP_PAGE_INIT() to initialize mutex in pmap_page.

VM_MDPAGE_INIT() in pmap_free_pdp() had initialized pp_flags,
so it unintentionally cleared PMAP_PAGE_FLAGS_PV_TRACKED.
use PMAP_PAGE_INIT to avoid using PMAP_PAGE_FLAGS_PV_TRACKED.

pointed out by tnn@, thanks


Revision tags: phil-wifi-20200406
# 1.68 14-Mar-2020 ad

pmap_remove_all(): Return a boolean value to indicate the behaviour. If
true, all mappings have been removed, the pmap is totally cleared out, and
UVM can then avoid doing the work to call pmap_remove() for each map entry.
If false, either nothing has been done, or some helpful arch-specific voodoo
has taken place.


Revision tags: is-mlppp-base
# 1.67 02-Mar-2020 ryo

oops, fix incorrect usage of daif_enable() in my previous commit.


# 1.66 29-Feb-2020 ryo

Fix pmap to work correctly with tagged addresses

- when fault, untag from address before passing to uvm/pmap functions
- pmap_extract() checks more strictly and consider the address tag


# 1.65 29-Feb-2020 ryo

use pmapboot_enter_range()


Revision tags: ad-namecache-base3
# 1.64 10-Feb-2020 ryo

use LIST(3) instead of TAILQ(3) to save one word in struct vm_page and struct pmap.

pointed out by riastradh@. thanks


# 1.63 03-Feb-2020 ryo

add support pmap_pv(9)

Patch originally from jmcneill@. thanks


# 1.62 03-Feb-2020 ryo

separate struct vm_page_md into vm_page_md and pmap_page
for preparation pmap_pv(9)


Revision tags: ad-namecache-base2 ad-namecache-base1
# 1.61 09-Jan-2020 ryo

fix behaviour mmap()/mprotect() when passed only PROT_EXEC.

when mmap()/mprotect() with only PROT_EXEC, syscall will be successful,
but the page actually hadn't been mapped.
it should be mapped with PROT_READ|PROT_EXEC implicitly. (r-x)


Revision tags: ad-namecache-base
# 1.60 30-Dec-2019 skrll

branches: 1.60.2;
Update pmap_map_chunk to allow L[12] block mappings and L3 page mappings


# 1.59 30-Dec-2019 skrll

Remove unnecessary brackets and unwrap a conditional. Same code before
and after.


# 1.58 28-Dec-2019 jmcneill

Do not use Early Write Acknowledge for PCIe I/O and config space.


# 1.57 27-Dec-2019 jmcneill

Enable early write acknowledge for device memory mappings.


# 1.56 19-Dec-2019 skrll

G/C kasan_shadow_map call in pmap_enter

pmap_growkernel calls kasan_shadow_map for KVA


# 1.55 18-Dec-2019 ryo

atomic_add_16() is not used in pmap.c anymore. no need decl here.


# 1.54 18-Dec-2019 ryo

space to tab


# 1.53 14-Dec-2019 skrll

Fix build... wire_count probably doesn't need atomics


# 1.52 13-Dec-2019 skrll

Fix KASAN support by calling kasan_shadow_map in pmap_growkernel


# 1.51 10-Dec-2019 ad

pg->phys_addr -> VM_PAGE_TO_PHYS(pg)


Revision tags: phil-wifi-20191119
# 1.50 14-Nov-2019 maxv

Mark several kASan functions with __nothing, to avoid annoying #ifdefs.
Same as kCSan and kMSan.


# 1.49 14-Nov-2019 maxv

Don't include "opt_kasan.h" when there's already <sys/asan.h> included.


# 1.48 29-Oct-2019 maya

Define PMAP_NEED_PROCWR, providing strategically placed i-cache
synchronization where just-changed memory is about to be executed.

Fixes SIGILLs seen when running Mono 6 on QEMU Cortex-A57.

ok ryo


# 1.47 22-Sep-2019 jmcneill

Disable translation table walks using TTBR0 while changing its value and
when deactivating a pmap. Fixes stability issues on Ampere eMAG CPUs.


# 1.46 20-Sep-2019 ryo

ref/mod bit should be set according to 'flags' argument, not 'prot'. r1.44 was incomplete.


# 1.45 13-Sep-2019 ryo

In pmap_devmap_bootstrap(), cpu_earlydevice_va_p() must not return true until *all* devmap tables have been enabled.
console mapping may be present in the last table.


# 1.44 07-Sep-2019 ryo

- remove incorrect KASSERT. mmap(2) with prot=PROT_WRITE calls pmap_enter(..., PROT_WRITE) internally.
- fix to update page reference flags when only PROT_WRITE or PROT_EXECUTE specified


# 1.43 15-Aug-2019 skrll

Make pmap_db_pte_print more terse so it's quicker on serial consoles


# 1.42 12-Aug-2019 skrll

Use PMAP_DEV in DEVMAP_ENTRY rather than pmap_map_chunk. It's clearer and
means pmap_map_chunk can be made to map other memory types.


Revision tags: netbsd-9-base phil-wifi-20190609
# 1.41 17-May-2019 mrg

branches: 1.41.2;
apply some __diagused.


Revision tags: isaki-audio2-base
# 1.40 08-Apr-2019 ryo

- free empty page tables pages if reach a certain usage.
- need to lock at removing an old pg (_pmap_remove_pv) in _pmap_enter()


# 1.39 06-Apr-2019 ryo

Fix race conditions about pmap_page_protect() and pmap_enter().

while handling same PTE by these functions in same time, there
is a critical path that the number of valid PTEs and wire_count
are inconsistent, and it caused KASSERT.
Need to hold a pv_lock while modifying them.


# 1.38 20-Mar-2019 ryo

spinkle __printflike(), and use PRIxxx


# 1.37 19-Mar-2019 ryo

- add ddb command "machine ttbr" to dump MMU tables.
- tidy up descriptions, usages and messages.


# 1.36 19-Mar-2019 ryo

- free L1-L3 pages that has been emptied by pmap_remove().
- if no memories, pmap_enter will return correctly ENOMEM if PMAP_CANFAIL, or wait until available any memories if !PMAP_CANFAIL.

These changes improves the stability when we use a huge virtual memory spaces with mmap.


# 1.35 06-Feb-2019 ryo

improve pmap_remove
- don't lock/unlock per page in pmap_remove()
- speedup pte lookup for continuous addresses
- bring out pool_cache_put(&_pmap_pv_pool, pv) from lock/unlock section


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226
# 1.34 21-Dec-2018 ryo

- add workaround for Cavium ThunderX errata 27456.
- add cpufuncs table in cpu_info. each cpu clusters may have different erratum. (e.g. big.LITTLE)


Revision tags: pgoyette-compat-1126
# 1.33 01-Nov-2018 maxv

Add kASan support for aarch64. Stack tracking needs more investigation
and will come in a separate commit.

Reviewed by ryo@ jmcneill@ skrll@.


# 1.32 31-Oct-2018 ryo

invalidate icache correctly.
l3pte_executable() should be used for only valid pte.


Revision tags: pgoyette-compat-1020
# 1.31 18-Oct-2018 skrll

Provide generic start code that assumes the MMU is off and caches are
disabled as per the linux booting protocol for ARMv6 and ARMv7 boards.
u-boot image type should be changed to 'linux' for correct behaviour.

The new start code builds a minimal "bootstrap" L1PT with cached access
disabled and uses the same table for all processors. AP startup is
performed in less steps and more code is written in C.

The bootstrap tables and stack are placed into an (orphaned) section
"_init_memory" which is given to uvm when it is no longer used.

Various kernels have been converted to use this code and tested. Some
boards were provided by TNF. Thanks!

The GENERIC kernel now boots on boards using the TEGRA, SUNXI and EXYNOS
kernels. The GENERIC kernel will also work on RPI2 using u-boot.

Thanks to martin@ and aymeric@ for testing on parallella and nanosoc
respectively


# 1.30 14-Oct-2018 skrll

Use __nothing


# 1.29 12-Oct-2018 ryo

add initial support of COMPAT_NETBSD32 on AArch64.
arm ELF32 EABI binaries could be execute in AArch32 state on AArch64. A32 THUMB mode is not supported yet.


# 1.28 12-Oct-2018 ryo

- cleanup checking address ranges with IN_RANGE macro
- change PM_ADDR_CHECK macro to KASSERTMSG
- restore fast lookup cases with IN_RANGE macro for pmap_extract changed in my previous commit.


# 1.27 12-Oct-2018 ryo

rewrite pmap_pte_lookup() to share similar code.


# 1.26 04-Oct-2018 ryo

cleanup locore, and changed the way to map memories during boot.
- add functions bootpage_enter() and bootpage_alloc() to adapt various layout
of physical memory map. especially for 64bit physical memory layout.
pmapboot_alloc() allocates pagetable pages from _end[].
- changed to map only the required amount for PA=VA identity mapping
(kernel image, UART device, and FDT blob) with L2_BLOCK(2Mbyte).
- changing page permission for kernel image, and making KSEG mapping are done
at cpu_kernel_vm_init() instead of at locore.
- optimize PTE entries with PTE Contiguous bit. it is enabled on devmap only for now.

reviewed by skrll@, thanks.


# 1.25 04-Oct-2018 ryo

* define LX_BLKPAG_{OS,ATTR}_* for OS dependent PTE attributes in pmap.h
* cleanup macros


Revision tags: pgoyette-compat-0930
# 1.24 17-Sep-2018 ryo

delete debug printf and KASSERT.


# 1.23 10-Sep-2018 maxv

Replace KDASSERT by panic.


# 1.22 10-Sep-2018 maxv

Rename _pmap_alloc_pdp -> pmap_alloc_pdp, and make it public.


# 1.21 10-Sep-2018 ryo

cleanup aarch64 mpstart and fdt bootstrap
* arm_cpu_hatch_arg is a bad idea. avoid serializing CPU startup, and eliminate arm_cpu_hatch_arg.
in mpstart, resolve own cpu index using array of cpu_mpidr[] (aarch64)
* add support fdt enable-method "spin-table"
* add support fdt enable-method "brcm,bcm2836-smp" (for 32bit RaspberryPi)
* use arm_fdt_cpu_bootstrap() instead of psci_fdt_bootstrap()
* rename "arm/fdt/psci_fdt.h" to "arm/fdt/psci_fdtvar.h" because of conflict of include file for needs-flag
* add devmap for cpu spin-table of raspberrypi3/aarch64
* no need to force hatch APs for raspberrypi3/arm32 ifndef MULTIPROCESSOR.
* fix to work pmap_extract(kerneltext/data/bss) even if before calling pmap_bootstrap

idea to use cpu_mpidr[] by jmcneill@. reviewd by skrll@. thanks.


Revision tags: pgoyette-compat-0906
# 1.20 27-Aug-2018 ryo

need to add VM_PROT_READ when pmap_kenter_pa(va, pa, VM_PROT_WRITE, 0) or pmap_kenter_pa(va, pa, VM_PROT_EXECUTE, 0).
VM_PROT_READ is treated as an access permission inernally.


# 1.19 11-Aug-2018 ryo

change to minimum invalidation of TLB.
specifying not only va but also asid, and not invalidate L0-L2 entry using tlbi_*_ll() if needed.


# 1.18 10-Aug-2018 ryo

treat kernel-exec attr and user-exec attr separately.
kernel cannot execute userland exec page, and user cannot execute kernel page.


# 1.17 06-Aug-2018 ryo

set kernel text/rodata readonly by default.
add function db_write_text() for setting ddb breakpoint.


# 1.16 31-Jul-2018 skrll

Define and use VPRINTF


Revision tags: pgoyette-compat-0728
# 1.15 27-Jul-2018 ryo

changes of pmap.c r1.13 seems to be unstable.
In order to invalidate icache, not to invalidate all icache,
but temporary to make the page writable and invalidate target address only.


# 1.14 24-Jul-2018 ryo

don't call pool_cache_put with locking pmap. pool_cache_put call pmap_kenter_pa internally.
(pool_cache_put_paddr -> pool_cache_put_slow -> pool_get -> pmap_kenter_pa)


# 1.13 23-Jul-2018 ryo

* fix icache invalidations.
* "ic ivau" (aarch64_icache_sync_range) with VA generates permission fault in some situations, therefore use KSEG address for now.


# 1.12 23-Jul-2018 ryo

rather than using flags to resolve nested locks, reserve pool_cache before locking.


# 1.11 21-Jul-2018 ryo

* avoid deadlock. mutex_owned() works only for adaptive lock, therefore we cannot use it for spinlock...
* add more NULL check
* clear pte when pmap_enter() fails


# 1.10 17-Jul-2018 ryo

Use __debugused


# 1.9 17-Jul-2018 christos

Add missing casts, remove unused variables.


# 1.8 09-Jul-2018 ryo

need locks in pmap_kremove() and pmap_fault_fixup()


Revision tags: phil-wifi-base pgoyette-compat-0625 pgoyette-compat-0521
# 1.7 20-May-2018 ryo

branches: 1.7.2;
pmap_enter() must update modified/referenced flags by 'flags' not 'prot'.


# 1.6 16-May-2018 ryo

Fix memory leak. it was leaking one page every pmap_create().
pm->pm_vmlist must be initialized before calling _pmap_alloc_pdp().


Revision tags: pgoyette-compat-0502
# 1.5 29-Apr-2018 ryo

fix KASSERT panic. pv_entry may not be exists in pvlist when pmap_remove().


# 1.4 29-Apr-2018 ryo

delete unused code


# 1.3 27-Apr-2018 ryo

fix instability behavior of bufcache on aarch64.
* fix to return correct ref/mod when PMAP_WIRED.
* changed to keep wired flags in pte instead of pv_entry, and cleanup.


Revision tags: pgoyette-compat-0422 pgoyette-compat-0415 pgoyette-compat-0407
# 1.2 01-Apr-2018 ryo

Add initial support for ARMv8 (AARCH64) (by nisimura@ and ryo@)

- sys/arch/evbarm64 is gone and integrated into sys/arch/evbarm. (by skrll@)
- add support fdt. evbarm/conf/GENERIC64 fdt (bcm2837,sunxi,tegra) based generic 64bit kernel config. (by skrll@, jmcneill@)


Revision tags: netbsd-8-2-RELEASE netbsd-8-1-RELEASE netbsd-8-1-RC1 netbsd-7-2-RELEASE netbsd-8-0-RELEASE netbsd-8-0-RC2 netbsd-8-0-RC1 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 netbsd-7-1-2-RELEASE pgoyette-compat-base netbsd-7-1-1-RELEASE tls-maxphys-base-20171202 matt-nb8-mediatek-base nick-nhusb-base-20170825 perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base pgoyette-localcount-20170320 netbsd-7-1-RELEASE netbsd-7-1-RC2 nick-nhusb-base-20170204 netbsd-7-nhusb-base-20170116 bouyer-socketcan-base pgoyette-localcount-20170107 netbsd-7-1-RC1 nick-nhusb-base-20161204 pgoyette-localcount-20161104 netbsd-7-0-2-RELEASE nick-nhusb-base-20161004 localcount-20160914 netbsd-7-nhusb-base pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907 nick-nhusb-base-20160529 netbsd-7-0-1-RELEASE nick-nhusb-base-20160422 nick-nhusb-base-20160319 nick-nhusb-base-20151226 netbsd-7-0-RELEASE nick-nhusb-base-20150921 netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 nick-nhusb-base-20150606 nick-nhusb-base-20150406 nick-nhusb-base tls-maxphys-base netbsd-7-base
# 1.1 10-Aug-2014 matt

branches: 1.1.4; 1.1.28;
Preliminary files for AARCH64 (64-bit ARM) support.
Enough for a distribution build.


# 1.83 04-Jul-2020 rin

Use tlen for temporary length variable instead of l, which is usually
used for struct lwp *.

No binary changes.


# 1.82 02-Jul-2020 rin

pmap_procwr(): sync icache even if p != curproc. This fixes applications
like GDB for arm32, that rewrite text of other process.

Thanks to ryo@ for discussion.


# 1.81 02-Jul-2020 rin

Set uvmexp.ncolors appropriately, which is required for some CPU
models with VIPT icache.

Otherwise, alias in virtual address results in inconsistent results,
at least for applications that rewrite text of other process, e.g.,
GDB for arm32.

Also, this hopefully fixes other unexpected failures due to alias.

Confirmed that there's no observable regression in performance;
difference in ``time make -j8'' for GENERIC64 kernel on BCM2837
with and without setting uvmexp.ncolors is within 0.1%.

Thanks to ryo@ for discussion.


# 1.80 27-Jun-2020 rin

Fix typo in name of evcnt(4) counter.


# 1.79 24-Jun-2020 ryo

Fix bug with incorrect range calculation when doing icache sync.
This is called by sysarch(ARM_SYNC_ICACHE) from aarch32 (compat_netbsd32) emul process.

pointed out by rin@, thanks.

XXX pullup-9


# 1.78 14-Jun-2020 ad

- Fix a lock order reversal in pmap_page_protect().

- Make sure pmap is always locked when updating stats; atomics no longer
needed to do that.

- Remove unneeded traversal of pv list in pmap_enter_pv().

- Shrink struct vm_page from 136 to 128 bytes (cache line sized) and struct
pv_entry from 48 to 32 bytes (power of 2 sized).

- Embed a pv_entry in each vm_page. This means PV entries don't need to
be allocated for private anonymous memory / COW pages / most UBC mappings.
Dynamic PV entries are then used only for stuff like shared libraries and
shared memory.

Proposed on port-arm@.


# 1.77 10-Jun-2020 ad

- Wired/resident stats shouldn't covered by PMAPCOUNTERS.
- Rename need_update_pv -> need_enter_pv.

Ok ryo@


# 1.76 01-Jun-2020 ryo

no need to make the PTE writable to do icache_sync, enough to accessible.


# 1.75 15-May-2020 skrll

Use __diagused


# 1.74 15-May-2020 tnn

fix non-diag build


# 1.73 14-May-2020 skrll

Use MUTEX_NODEBUG for PV locks as is commonly done. OK ryo.


# 1.72 13-May-2020 jmcneill

Implement pmap_extract_coherency


Revision tags: bouyer-xenpvh-base2 phil-wifi-20200421 bouyer-xenpvh-base1
# 1.71 18-Apr-2020 skrll

PMAP_DEBUG has been deleted on arm


# 1.70 13-Apr-2020 maxv

Add support for Branch Target Identification (BTI).

On the executable pages that have the GP (Guarded Page) bit, the semantic
of the "br" and "blr" instructions is changed: the CPU expects the first
instruction of the jump/call target to be "bti", and faults if it isn't.

We add the GP bit on the kernel .text pages (and incidentally the .rodata
pages, but we don't care). The compiler adds a "bti c" instruction at the
beginning of each C function. We modify the ENTRY() macros to manually add
"bti c" in the asm functions.

cpuswitch.S needs a specific change: with "br x27" the CPU expects "bti j",
which is bad because the functions begin with "bti c"; switch to "br x16",
for the CPU to accept "bti c".

BTI helps defend against JOP/COP. Tested on Qemu.


Revision tags: phil-wifi-20200411 bouyer-xenpvh-base
# 1.69 08-Apr-2020 ryo

branches: 1.69.2;
use PMAP_PAGE_INIT() to initialize mutex in pmap_page.

VM_MDPAGE_INIT() in pmap_free_pdp() had initialized pp_flags,
so it unintentionally cleared PMAP_PAGE_FLAGS_PV_TRACKED.
use PMAP_PAGE_INIT to avoid using PMAP_PAGE_FLAGS_PV_TRACKED.

pointed out by tnn@, thanks


Revision tags: phil-wifi-20200406
# 1.68 14-Mar-2020 ad

pmap_remove_all(): Return a boolean value to indicate the behaviour. If
true, all mappings have been removed, the pmap is totally cleared out, and
UVM can then avoid doing the work to call pmap_remove() for each map entry.
If false, either nothing has been done, or some helpful arch-specific voodoo
has taken place.


Revision tags: is-mlppp-base
# 1.67 02-Mar-2020 ryo

oops, fix incorrect usage of daif_enable() in my previous commit.


# 1.66 29-Feb-2020 ryo

Fix pmap to work correctly with tagged addresses

- when fault, untag from address before passing to uvm/pmap functions
- pmap_extract() checks more strictly and consider the address tag


# 1.65 29-Feb-2020 ryo

use pmapboot_enter_range()


Revision tags: ad-namecache-base3
# 1.64 10-Feb-2020 ryo

use LIST(3) instead of TAILQ(3) to save one word in struct vm_page and struct pmap.

pointed out by riastradh@. thanks


# 1.63 03-Feb-2020 ryo

add support pmap_pv(9)

Patch originally from jmcneill@. thanks


# 1.62 03-Feb-2020 ryo

separate struct vm_page_md into vm_page_md and pmap_page
for preparation pmap_pv(9)


Revision tags: ad-namecache-base2 ad-namecache-base1
# 1.61 09-Jan-2020 ryo

fix behaviour mmap()/mprotect() when passed only PROT_EXEC.

when mmap()/mprotect() with only PROT_EXEC, syscall will be successful,
but the page actually hadn't been mapped.
it should be mapped with PROT_READ|PROT_EXEC implicitly. (r-x)


Revision tags: ad-namecache-base
# 1.60 30-Dec-2019 skrll

branches: 1.60.2;
Update pmap_map_chunk to allow L[12] block mappings and L3 page mappings


# 1.59 30-Dec-2019 skrll

Remove unnecessary brackets and unwrap a conditional. Same code before
and after.


# 1.58 28-Dec-2019 jmcneill

Do not use Early Write Acknowledge for PCIe I/O and config space.


# 1.57 27-Dec-2019 jmcneill

Enable early write acknowledge for device memory mappings.


# 1.56 19-Dec-2019 skrll

G/C kasan_shadow_map call in pmap_enter

pmap_growkernel calls kasan_shadow_map for KVA


# 1.55 18-Dec-2019 ryo

atomic_add_16() is not used in pmap.c anymore. no need decl here.


# 1.54 18-Dec-2019 ryo

space to tab


# 1.53 14-Dec-2019 skrll

Fix build... wire_count probably doesn't need atomics


# 1.52 13-Dec-2019 skrll

Fix KASAN support by calling kasan_shadow_map in pmap_growkernel


# 1.51 10-Dec-2019 ad

pg->phys_addr -> VM_PAGE_TO_PHYS(pg)


Revision tags: phil-wifi-20191119
# 1.50 14-Nov-2019 maxv

Mark several kASan functions with __nothing, to avoid annoying #ifdefs.
Same as kCSan and kMSan.


# 1.49 14-Nov-2019 maxv

Don't include "opt_kasan.h" when there's already <sys/asan.h> included.


# 1.48 29-Oct-2019 maya

Define PMAP_NEED_PROCWR, providing strategically placed i-cache
synchronization where just-changed memory is about to be executed.

Fixes SIGILLs seen when running Mono 6 on QEMU Cortex-A57.

ok ryo


# 1.47 22-Sep-2019 jmcneill

Disable translation table walks using TTBR0 while changing its value and
when deactivating a pmap. Fixes stability issues on Ampere eMAG CPUs.


# 1.46 20-Sep-2019 ryo

ref/mod bit should be set according to 'flags' argument, not 'prot'. r1.44 was incomplete.


# 1.45 13-Sep-2019 ryo

In pmap_devmap_bootstrap(), cpu_earlydevice_va_p() must not return true until *all* devmap tables have been enabled.
console mapping may be present in the last table.


# 1.44 07-Sep-2019 ryo

- remove incorrect KASSERT. mmap(2) with prot=PROT_WRITE calls pmap_enter(..., PROT_WRITE) internally.
- fix to update page reference flags when only PROT_WRITE or PROT_EXECUTE specified


# 1.43 15-Aug-2019 skrll

Make pmap_db_pte_print more terse so it's quicker on serial consoles


# 1.42 12-Aug-2019 skrll

Use PMAP_DEV in DEVMAP_ENTRY rather than pmap_map_chunk. It's clearer and
means pmap_map_chunk can be made to map other memory types.


Revision tags: netbsd-9-base phil-wifi-20190609
# 1.41 17-May-2019 mrg

branches: 1.41.2;
apply some __diagused.


Revision tags: isaki-audio2-base
# 1.40 08-Apr-2019 ryo

- free empty page tables pages if reach a certain usage.
- need to lock at removing an old pg (_pmap_remove_pv) in _pmap_enter()


# 1.39 06-Apr-2019 ryo

Fix race conditions about pmap_page_protect() and pmap_enter().

while handling same PTE by these functions in same time, there
is a critical path that the number of valid PTEs and wire_count
are inconsistent, and it caused KASSERT.
Need to hold a pv_lock while modifying them.


# 1.38 20-Mar-2019 ryo

spinkle __printflike(), and use PRIxxx


# 1.37 19-Mar-2019 ryo

- add ddb command "machine ttbr" to dump MMU tables.
- tidy up descriptions, usages and messages.


# 1.36 19-Mar-2019 ryo

- free L1-L3 pages that has been emptied by pmap_remove().
- if no memories, pmap_enter will return correctly ENOMEM if PMAP_CANFAIL, or wait until available any memories if !PMAP_CANFAIL.

These changes improves the stability when we use a huge virtual memory spaces with mmap.


# 1.35 06-Feb-2019 ryo

improve pmap_remove
- don't lock/unlock per page in pmap_remove()
- speedup pte lookup for continuous addresses
- bring out pool_cache_put(&_pmap_pv_pool, pv) from lock/unlock section


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226
# 1.34 21-Dec-2018 ryo

- add workaround for Cavium ThunderX errata 27456.
- add cpufuncs table in cpu_info. each cpu clusters may have different erratum. (e.g. big.LITTLE)


Revision tags: pgoyette-compat-1126
# 1.33 01-Nov-2018 maxv

Add kASan support for aarch64. Stack tracking needs more investigation
and will come in a separate commit.

Reviewed by ryo@ jmcneill@ skrll@.


# 1.32 31-Oct-2018 ryo

invalidate icache correctly.
l3pte_executable() should be used for only valid pte.


Revision tags: pgoyette-compat-1020
# 1.31 18-Oct-2018 skrll

Provide generic start code that assumes the MMU is off and caches are
disabled as per the linux booting protocol for ARMv6 and ARMv7 boards.
u-boot image type should be changed to 'linux' for correct behaviour.

The new start code builds a minimal "bootstrap" L1PT with cached access
disabled and uses the same table for all processors. AP startup is
performed in less steps and more code is written in C.

The bootstrap tables and stack are placed into an (orphaned) section
"_init_memory" which is given to uvm when it is no longer used.

Various kernels have been converted to use this code and tested. Some
boards were provided by TNF. Thanks!

The GENERIC kernel now boots on boards using the TEGRA, SUNXI and EXYNOS
kernels. The GENERIC kernel will also work on RPI2 using u-boot.

Thanks to martin@ and aymeric@ for testing on parallella and nanosoc
respectively


# 1.30 14-Oct-2018 skrll

Use __nothing


# 1.29 12-Oct-2018 ryo

add initial support of COMPAT_NETBSD32 on AArch64.
arm ELF32 EABI binaries could be execute in AArch32 state on AArch64. A32 THUMB mode is not supported yet.


# 1.28 12-Oct-2018 ryo

- cleanup checking address ranges with IN_RANGE macro
- change PM_ADDR_CHECK macro to KASSERTMSG
- restore fast lookup cases with IN_RANGE macro for pmap_extract changed in my previous commit.


# 1.27 12-Oct-2018 ryo

rewrite pmap_pte_lookup() to share similar code.


# 1.26 04-Oct-2018 ryo

cleanup locore, and changed the way to map memories during boot.
- add functions bootpage_enter() and bootpage_alloc() to adapt various layout
of physical memory map. especially for 64bit physical memory layout.
pmapboot_alloc() allocates pagetable pages from _end[].
- changed to map only the required amount for PA=VA identity mapping
(kernel image, UART device, and FDT blob) with L2_BLOCK(2Mbyte).
- changing page permission for kernel image, and making KSEG mapping are done
at cpu_kernel_vm_init() instead of at locore.
- optimize PTE entries with PTE Contiguous bit. it is enabled on devmap only for now.

reviewed by skrll@, thanks.


# 1.25 04-Oct-2018 ryo

* define LX_BLKPAG_{OS,ATTR}_* for OS dependent PTE attributes in pmap.h
* cleanup macros


Revision tags: pgoyette-compat-0930
# 1.24 17-Sep-2018 ryo

delete debug printf and KASSERT.


# 1.23 10-Sep-2018 maxv

Replace KDASSERT by panic.


# 1.22 10-Sep-2018 maxv

Rename _pmap_alloc_pdp -> pmap_alloc_pdp, and make it public.


# 1.21 10-Sep-2018 ryo

cleanup aarch64 mpstart and fdt bootstrap
* arm_cpu_hatch_arg is a bad idea. avoid serializing CPU startup, and eliminate arm_cpu_hatch_arg.
in mpstart, resolve own cpu index using array of cpu_mpidr[] (aarch64)
* add support fdt enable-method "spin-table"
* add support fdt enable-method "brcm,bcm2836-smp" (for 32bit RaspberryPi)
* use arm_fdt_cpu_bootstrap() instead of psci_fdt_bootstrap()
* rename "arm/fdt/psci_fdt.h" to "arm/fdt/psci_fdtvar.h" because of conflict of include file for needs-flag
* add devmap for cpu spin-table of raspberrypi3/aarch64
* no need to force hatch APs for raspberrypi3/arm32 ifndef MULTIPROCESSOR.
* fix to work pmap_extract(kerneltext/data/bss) even if before calling pmap_bootstrap

idea to use cpu_mpidr[] by jmcneill@. reviewd by skrll@. thanks.


Revision tags: pgoyette-compat-0906
# 1.20 27-Aug-2018 ryo

need to add VM_PROT_READ when pmap_kenter_pa(va, pa, VM_PROT_WRITE, 0) or pmap_kenter_pa(va, pa, VM_PROT_EXECUTE, 0).
VM_PROT_READ is treated as an access permission inernally.


# 1.19 11-Aug-2018 ryo

change to minimum invalidation of TLB.
specifying not only va but also asid, and not invalidate L0-L2 entry using tlbi_*_ll() if needed.


# 1.18 10-Aug-2018 ryo

treat kernel-exec attr and user-exec attr separately.
kernel cannot execute userland exec page, and user cannot execute kernel page.


# 1.17 06-Aug-2018 ryo

set kernel text/rodata readonly by default.
add function db_write_text() for setting ddb breakpoint.


# 1.16 31-Jul-2018 skrll

Define and use VPRINTF


Revision tags: pgoyette-compat-0728
# 1.15 27-Jul-2018 ryo

changes of pmap.c r1.13 seems to be unstable.
In order to invalidate icache, not to invalidate all icache,
but temporary to make the page writable and invalidate target address only.


# 1.14 24-Jul-2018 ryo

don't call pool_cache_put with locking pmap. pool_cache_put call pmap_kenter_pa internally.
(pool_cache_put_paddr -> pool_cache_put_slow -> pool_get -> pmap_kenter_pa)


# 1.13 23-Jul-2018 ryo

* fix icache invalidations.
* "ic ivau" (aarch64_icache_sync_range) with VA generates permission fault in some situations, therefore use KSEG address for now.


# 1.12 23-Jul-2018 ryo

rather than using flags to resolve nested locks, reserve pool_cache before locking.


# 1.11 21-Jul-2018 ryo

* avoid deadlock. mutex_owned() works only for adaptive lock, therefore we cannot use it for spinlock...
* add more NULL check
* clear pte when pmap_enter() fails


# 1.10 17-Jul-2018 ryo

Use __debugused


# 1.9 17-Jul-2018 christos

Add missing casts, remove unused variables.


# 1.8 09-Jul-2018 ryo

need locks in pmap_kremove() and pmap_fault_fixup()


Revision tags: phil-wifi-base pgoyette-compat-0625 pgoyette-compat-0521
# 1.7 20-May-2018 ryo

branches: 1.7.2;
pmap_enter() must update modified/referenced flags by 'flags' not 'prot'.


# 1.6 16-May-2018 ryo

Fix memory leak. it was leaking one page every pmap_create().
pm->pm_vmlist must be initialized before calling _pmap_alloc_pdp().


Revision tags: pgoyette-compat-0502
# 1.5 29-Apr-2018 ryo

fix KASSERT panic. pv_entry may not be exists in pvlist when pmap_remove().


# 1.4 29-Apr-2018 ryo

delete unused code


# 1.3 27-Apr-2018 ryo

fix instability behavior of bufcache on aarch64.
* fix to return correct ref/mod when PMAP_WIRED.
* changed to keep wired flags in pte instead of pv_entry, and cleanup.


Revision tags: pgoyette-compat-0422 pgoyette-compat-0415 pgoyette-compat-0407
# 1.2 01-Apr-2018 ryo

Add initial support for ARMv8 (AARCH64) (by nisimura@ and ryo@)

- sys/arch/evbarm64 is gone and integrated into sys/arch/evbarm. (by skrll@)
- add support fdt. evbarm/conf/GENERIC64 fdt (bcm2837,sunxi,tegra) based generic 64bit kernel config. (by skrll@, jmcneill@)


Revision tags: netbsd-8-2-RELEASE netbsd-8-1-RELEASE netbsd-8-1-RC1 netbsd-7-2-RELEASE netbsd-8-0-RELEASE netbsd-8-0-RC2 netbsd-8-0-RC1 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 netbsd-7-1-2-RELEASE pgoyette-compat-base netbsd-7-1-1-RELEASE tls-maxphys-base-20171202 matt-nb8-mediatek-base nick-nhusb-base-20170825 perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base pgoyette-localcount-20170320 netbsd-7-1-RELEASE netbsd-7-1-RC2 nick-nhusb-base-20170204 netbsd-7-nhusb-base-20170116 bouyer-socketcan-base pgoyette-localcount-20170107 netbsd-7-1-RC1 nick-nhusb-base-20161204 pgoyette-localcount-20161104 netbsd-7-0-2-RELEASE nick-nhusb-base-20161004 localcount-20160914 netbsd-7-nhusb-base pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907 nick-nhusb-base-20160529 netbsd-7-0-1-RELEASE nick-nhusb-base-20160422 nick-nhusb-base-20160319 nick-nhusb-base-20151226 netbsd-7-0-RELEASE nick-nhusb-base-20150921 netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 nick-nhusb-base-20150606 nick-nhusb-base-20150406 nick-nhusb-base tls-maxphys-base netbsd-7-base
# 1.1 10-Aug-2014 matt

branches: 1.1.4; 1.1.28;
Preliminary files for AARCH64 (64-bit ARM) support.
Enough for a distribution build.


# 1.82 02-Jul-2020 rin

pmap_procwr(): sync icache even if p != curproc. This fixes applications
like GDB for arm32, that rewrite text of other process.

Thanks to ryo@ for discussion.


# 1.81 02-Jul-2020 rin

Set uvmexp.ncolors appropriately, which is required for some CPU
models with VIPT icache.

Otherwise, alias in virtual address results in inconsistent results,
at least for applications that rewrite text of other process, e.g.,
GDB for arm32.

Also, this hopefully fixes other unexpected failures due to alias.

Confirmed that there's no observable regression in performance;
difference in ``time make -j8'' for GENERIC64 kernel on BCM2837
with and without setting uvmexp.ncolors is within 0.1%.

Thanks to ryo@ for discussion.


# 1.80 27-Jun-2020 rin

Fix typo in name of evcnt(4) counter.


# 1.79 24-Jun-2020 ryo

Fix bug with incorrect range calculation when doing icache sync.
This is called by sysarch(ARM_SYNC_ICACHE) from aarch32 (compat_netbsd32) emul process.

pointed out by rin@, thanks.

XXX pullup-9


# 1.78 14-Jun-2020 ad

- Fix a lock order reversal in pmap_page_protect().

- Make sure pmap is always locked when updating stats; atomics no longer
needed to do that.

- Remove unneeded traversal of pv list in pmap_enter_pv().

- Shrink struct vm_page from 136 to 128 bytes (cache line sized) and struct
pv_entry from 48 to 32 bytes (power of 2 sized).

- Embed a pv_entry in each vm_page. This means PV entries don't need to
be allocated for private anonymous memory / COW pages / most UBC mappings.
Dynamic PV entries are then used only for stuff like shared libraries and
shared memory.

Proposed on port-arm@.


# 1.77 10-Jun-2020 ad

- Wired/resident stats shouldn't covered by PMAPCOUNTERS.
- Rename need_update_pv -> need_enter_pv.

Ok ryo@


# 1.76 01-Jun-2020 ryo

no need to make the PTE writable to do icache_sync, enough to accessible.


# 1.75 15-May-2020 skrll

Use __diagused


# 1.74 15-May-2020 tnn

fix non-diag build


# 1.73 14-May-2020 skrll

Use MUTEX_NODEBUG for PV locks as is commonly done. OK ryo.


# 1.72 13-May-2020 jmcneill

Implement pmap_extract_coherency


Revision tags: bouyer-xenpvh-base2 phil-wifi-20200421 bouyer-xenpvh-base1
# 1.71 18-Apr-2020 skrll

PMAP_DEBUG has been deleted on arm


# 1.70 13-Apr-2020 maxv

Add support for Branch Target Identification (BTI).

On the executable pages that have the GP (Guarded Page) bit, the semantic
of the "br" and "blr" instructions is changed: the CPU expects the first
instruction of the jump/call target to be "bti", and faults if it isn't.

We add the GP bit on the kernel .text pages (and incidentally the .rodata
pages, but we don't care). The compiler adds a "bti c" instruction at the
beginning of each C function. We modify the ENTRY() macros to manually add
"bti c" in the asm functions.

cpuswitch.S needs a specific change: with "br x27" the CPU expects "bti j",
which is bad because the functions begin with "bti c"; switch to "br x16",
for the CPU to accept "bti c".

BTI helps defend against JOP/COP. Tested on Qemu.


Revision tags: phil-wifi-20200411 bouyer-xenpvh-base
# 1.69 08-Apr-2020 ryo

branches: 1.69.2;
use PMAP_PAGE_INIT() to initialize mutex in pmap_page.

VM_MDPAGE_INIT() in pmap_free_pdp() had initialized pp_flags,
so it unintentionally cleared PMAP_PAGE_FLAGS_PV_TRACKED.
use PMAP_PAGE_INIT to avoid using PMAP_PAGE_FLAGS_PV_TRACKED.

pointed out by tnn@, thanks


Revision tags: phil-wifi-20200406
# 1.68 14-Mar-2020 ad

pmap_remove_all(): Return a boolean value to indicate the behaviour. If
true, all mappings have been removed, the pmap is totally cleared out, and
UVM can then avoid doing the work to call pmap_remove() for each map entry.
If false, either nothing has been done, or some helpful arch-specific voodoo
has taken place.


Revision tags: is-mlppp-base
# 1.67 02-Mar-2020 ryo

oops, fix incorrect usage of daif_enable() in my previous commit.


# 1.66 29-Feb-2020 ryo

Fix pmap to work correctly with tagged addresses

- when fault, untag from address before passing to uvm/pmap functions
- pmap_extract() checks more strictly and consider the address tag


# 1.65 29-Feb-2020 ryo

use pmapboot_enter_range()


Revision tags: ad-namecache-base3
# 1.64 10-Feb-2020 ryo

use LIST(3) instead of TAILQ(3) to save one word in struct vm_page and struct pmap.

pointed out by riastradh@. thanks


# 1.63 03-Feb-2020 ryo

add support pmap_pv(9)

Patch originally from jmcneill@. thanks


# 1.62 03-Feb-2020 ryo

separate struct vm_page_md into vm_page_md and pmap_page
for preparation pmap_pv(9)


Revision tags: ad-namecache-base2 ad-namecache-base1
# 1.61 09-Jan-2020 ryo

fix behaviour mmap()/mprotect() when passed only PROT_EXEC.

when mmap()/mprotect() with only PROT_EXEC, syscall will be successful,
but the page actually hadn't been mapped.
it should be mapped with PROT_READ|PROT_EXEC implicitly. (r-x)


Revision tags: ad-namecache-base
# 1.60 30-Dec-2019 skrll

branches: 1.60.2;
Update pmap_map_chunk to allow L[12] block mappings and L3 page mappings


# 1.59 30-Dec-2019 skrll

Remove unnecessary brackets and unwrap a conditional. Same code before
and after.


# 1.58 28-Dec-2019 jmcneill

Do not use Early Write Acknowledge for PCIe I/O and config space.


# 1.57 27-Dec-2019 jmcneill

Enable early write acknowledge for device memory mappings.


# 1.56 19-Dec-2019 skrll

G/C kasan_shadow_map call in pmap_enter

pmap_growkernel calls kasan_shadow_map for KVA


# 1.55 18-Dec-2019 ryo

atomic_add_16() is not used in pmap.c anymore. no need decl here.


# 1.54 18-Dec-2019 ryo

space to tab


# 1.53 14-Dec-2019 skrll

Fix build... wire_count probably doesn't need atomics


# 1.52 13-Dec-2019 skrll

Fix KASAN support by calling kasan_shadow_map in pmap_growkernel


# 1.51 10-Dec-2019 ad

pg->phys_addr -> VM_PAGE_TO_PHYS(pg)


Revision tags: phil-wifi-20191119
# 1.50 14-Nov-2019 maxv

Mark several kASan functions with __nothing, to avoid annoying #ifdefs.
Same as kCSan and kMSan.


# 1.49 14-Nov-2019 maxv

Don't include "opt_kasan.h" when there's already <sys/asan.h> included.


# 1.48 29-Oct-2019 maya

Define PMAP_NEED_PROCWR, providing strategically placed i-cache
synchronization where just-changed memory is about to be executed.

Fixes SIGILLs seen when running Mono 6 on QEMU Cortex-A57.

ok ryo


# 1.47 22-Sep-2019 jmcneill

Disable translation table walks using TTBR0 while changing its value and
when deactivating a pmap. Fixes stability issues on Ampere eMAG CPUs.


# 1.46 20-Sep-2019 ryo

ref/mod bit should be set according to 'flags' argument, not 'prot'. r1.44 was incomplete.


# 1.45 13-Sep-2019 ryo

In pmap_devmap_bootstrap(), cpu_earlydevice_va_p() must not return true until *all* devmap tables have been enabled.
console mapping may be present in the last table.


# 1.44 07-Sep-2019 ryo

- remove incorrect KASSERT. mmap(2) with prot=PROT_WRITE calls pmap_enter(..., PROT_WRITE) internally.
- fix to update page reference flags when only PROT_WRITE or PROT_EXECUTE specified


# 1.43 15-Aug-2019 skrll

Make pmap_db_pte_print more terse so it's quicker on serial consoles


# 1.42 12-Aug-2019 skrll

Use PMAP_DEV in DEVMAP_ENTRY rather than pmap_map_chunk. It's clearer and
means pmap_map_chunk can be made to map other memory types.


Revision tags: netbsd-9-base phil-wifi-20190609
# 1.41 17-May-2019 mrg

branches: 1.41.2;
apply some __diagused.


Revision tags: isaki-audio2-base
# 1.40 08-Apr-2019 ryo

- free empty page tables pages if reach a certain usage.
- need to lock at removing an old pg (_pmap_remove_pv) in _pmap_enter()


# 1.39 06-Apr-2019 ryo

Fix race conditions about pmap_page_protect() and pmap_enter().

while handling same PTE by these functions in same time, there
is a critical path that the number of valid PTEs and wire_count
are inconsistent, and it caused KASSERT.
Need to hold a pv_lock while modifying them.


# 1.38 20-Mar-2019 ryo

spinkle __printflike(), and use PRIxxx


# 1.37 19-Mar-2019 ryo

- add ddb command "machine ttbr" to dump MMU tables.
- tidy up descriptions, usages and messages.


# 1.36 19-Mar-2019 ryo

- free L1-L3 pages that has been emptied by pmap_remove().
- if no memories, pmap_enter will return correctly ENOMEM if PMAP_CANFAIL, or wait until available any memories if !PMAP_CANFAIL.

These changes improves the stability when we use a huge virtual memory spaces with mmap.


# 1.35 06-Feb-2019 ryo

improve pmap_remove
- don't lock/unlock per page in pmap_remove()
- speedup pte lookup for continuous addresses
- bring out pool_cache_put(&_pmap_pv_pool, pv) from lock/unlock section


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226
# 1.34 21-Dec-2018 ryo

- add workaround for Cavium ThunderX errata 27456.
- add cpufuncs table in cpu_info. each cpu clusters may have different erratum. (e.g. big.LITTLE)


Revision tags: pgoyette-compat-1126
# 1.33 01-Nov-2018 maxv

Add kASan support for aarch64. Stack tracking needs more investigation
and will come in a separate commit.

Reviewed by ryo@ jmcneill@ skrll@.


# 1.32 31-Oct-2018 ryo

invalidate icache correctly.
l3pte_executable() should be used for only valid pte.


Revision tags: pgoyette-compat-1020
# 1.31 18-Oct-2018 skrll

Provide generic start code that assumes the MMU is off and caches are
disabled as per the linux booting protocol for ARMv6 and ARMv7 boards.
u-boot image type should be changed to 'linux' for correct behaviour.

The new start code builds a minimal "bootstrap" L1PT with cached access
disabled and uses the same table for all processors. AP startup is
performed in less steps and more code is written in C.

The bootstrap tables and stack are placed into an (orphaned) section
"_init_memory" which is given to uvm when it is no longer used.

Various kernels have been converted to use this code and tested. Some
boards were provided by TNF. Thanks!

The GENERIC kernel now boots on boards using the TEGRA, SUNXI and EXYNOS
kernels. The GENERIC kernel will also work on RPI2 using u-boot.

Thanks to martin@ and aymeric@ for testing on parallella and nanosoc
respectively


# 1.30 14-Oct-2018 skrll

Use __nothing


# 1.29 12-Oct-2018 ryo

add initial support of COMPAT_NETBSD32 on AArch64.
arm ELF32 EABI binaries could be execute in AArch32 state on AArch64. A32 THUMB mode is not supported yet.


# 1.28 12-Oct-2018 ryo

- cleanup checking address ranges with IN_RANGE macro
- change PM_ADDR_CHECK macro to KASSERTMSG
- restore fast lookup cases with IN_RANGE macro for pmap_extract changed in my previous commit.


# 1.27 12-Oct-2018 ryo

rewrite pmap_pte_lookup() to share similar code.


# 1.26 04-Oct-2018 ryo

cleanup locore, and changed the way to map memories during boot.
- add functions bootpage_enter() and bootpage_alloc() to adapt various layout
of physical memory map. especially for 64bit physical memory layout.
pmapboot_alloc() allocates pagetable pages from _end[].
- changed to map only the required amount for PA=VA identity mapping
(kernel image, UART device, and FDT blob) with L2_BLOCK(2Mbyte).
- changing page permission for kernel image, and making KSEG mapping are done
at cpu_kernel_vm_init() instead of at locore.
- optimize PTE entries with PTE Contiguous bit. it is enabled on devmap only for now.

reviewed by skrll@, thanks.


# 1.25 04-Oct-2018 ryo

* define LX_BLKPAG_{OS,ATTR}_* for OS dependent PTE attributes in pmap.h
* cleanup macros


Revision tags: pgoyette-compat-0930
# 1.24 17-Sep-2018 ryo

delete debug printf and KASSERT.


# 1.23 10-Sep-2018 maxv

Replace KDASSERT by panic.


# 1.22 10-Sep-2018 maxv

Rename _pmap_alloc_pdp -> pmap_alloc_pdp, and make it public.


# 1.21 10-Sep-2018 ryo

cleanup aarch64 mpstart and fdt bootstrap
* arm_cpu_hatch_arg is a bad idea. avoid serializing CPU startup, and eliminate arm_cpu_hatch_arg.
in mpstart, resolve own cpu index using array of cpu_mpidr[] (aarch64)
* add support fdt enable-method "spin-table"
* add support fdt enable-method "brcm,bcm2836-smp" (for 32bit RaspberryPi)
* use arm_fdt_cpu_bootstrap() instead of psci_fdt_bootstrap()
* rename "arm/fdt/psci_fdt.h" to "arm/fdt/psci_fdtvar.h" because of conflict of include file for needs-flag
* add devmap for cpu spin-table of raspberrypi3/aarch64
* no need to force hatch APs for raspberrypi3/arm32 ifndef MULTIPROCESSOR.
* fix to work pmap_extract(kerneltext/data/bss) even if before calling pmap_bootstrap

idea to use cpu_mpidr[] by jmcneill@. reviewd by skrll@. thanks.


Revision tags: pgoyette-compat-0906
# 1.20 27-Aug-2018 ryo

need to add VM_PROT_READ when pmap_kenter_pa(va, pa, VM_PROT_WRITE, 0) or pmap_kenter_pa(va, pa, VM_PROT_EXECUTE, 0).
VM_PROT_READ is treated as an access permission inernally.


# 1.19 11-Aug-2018 ryo

change to minimum invalidation of TLB.
specifying not only va but also asid, and not invalidate L0-L2 entry using tlbi_*_ll() if needed.


# 1.18 10-Aug-2018 ryo

treat kernel-exec attr and user-exec attr separately.
kernel cannot execute userland exec page, and user cannot execute kernel page.


# 1.17 06-Aug-2018 ryo

set kernel text/rodata readonly by default.
add function db_write_text() for setting ddb breakpoint.


# 1.16 31-Jul-2018 skrll

Define and use VPRINTF


Revision tags: pgoyette-compat-0728
# 1.15 27-Jul-2018 ryo

changes of pmap.c r1.13 seems to be unstable.
In order to invalidate icache, not to invalidate all icache,
but temporary to make the page writable and invalidate target address only.


# 1.14 24-Jul-2018 ryo

don't call pool_cache_put with locking pmap. pool_cache_put call pmap_kenter_pa internally.
(pool_cache_put_paddr -> pool_cache_put_slow -> pool_get -> pmap_kenter_pa)


# 1.13 23-Jul-2018 ryo

* fix icache invalidations.
* "ic ivau" (aarch64_icache_sync_range) with VA generates permission fault in some situations, therefore use KSEG address for now.


# 1.12 23-Jul-2018 ryo

rather than using flags to resolve nested locks, reserve pool_cache before locking.


# 1.11 21-Jul-2018 ryo

* avoid deadlock. mutex_owned() works only for adaptive lock, therefore we cannot use it for spinlock...
* add more NULL check
* clear pte when pmap_enter() fails


# 1.10 17-Jul-2018 ryo

Use __debugused


# 1.9 17-Jul-2018 christos

Add missing casts, remove unused variables.


# 1.8 09-Jul-2018 ryo

need locks in pmap_kremove() and pmap_fault_fixup()


Revision tags: phil-wifi-base pgoyette-compat-0625 pgoyette-compat-0521
# 1.7 20-May-2018 ryo

branches: 1.7.2;
pmap_enter() must update modified/referenced flags by 'flags' not 'prot'.


# 1.6 16-May-2018 ryo

Fix memory leak. it was leaking one page every pmap_create().
pm->pm_vmlist must be initialized before calling _pmap_alloc_pdp().


Revision tags: pgoyette-compat-0502
# 1.5 29-Apr-2018 ryo

fix KASSERT panic. pv_entry may not be exists in pvlist when pmap_remove().


# 1.4 29-Apr-2018 ryo

delete unused code


# 1.3 27-Apr-2018 ryo

fix instability behavior of bufcache on aarch64.
* fix to return correct ref/mod when PMAP_WIRED.
* changed to keep wired flags in pte instead of pv_entry, and cleanup.


Revision tags: pgoyette-compat-0422 pgoyette-compat-0415 pgoyette-compat-0407
# 1.2 01-Apr-2018 ryo

Add initial support for ARMv8 (AARCH64) (by nisimura@ and ryo@)

- sys/arch/evbarm64 is gone and integrated into sys/arch/evbarm. (by skrll@)
- add support fdt. evbarm/conf/GENERIC64 fdt (bcm2837,sunxi,tegra) based generic 64bit kernel config. (by skrll@, jmcneill@)


Revision tags: netbsd-8-2-RELEASE netbsd-8-1-RELEASE netbsd-8-1-RC1 netbsd-7-2-RELEASE netbsd-8-0-RELEASE netbsd-8-0-RC2 netbsd-8-0-RC1 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 netbsd-7-1-2-RELEASE pgoyette-compat-base netbsd-7-1-1-RELEASE tls-maxphys-base-20171202 matt-nb8-mediatek-base nick-nhusb-base-20170825 perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base pgoyette-localcount-20170320 netbsd-7-1-RELEASE netbsd-7-1-RC2 nick-nhusb-base-20170204 netbsd-7-nhusb-base-20170116 bouyer-socketcan-base pgoyette-localcount-20170107 netbsd-7-1-RC1 nick-nhusb-base-20161204 pgoyette-localcount-20161104 netbsd-7-0-2-RELEASE nick-nhusb-base-20161004 localcount-20160914 netbsd-7-nhusb-base pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907 nick-nhusb-base-20160529 netbsd-7-0-1-RELEASE nick-nhusb-base-20160422 nick-nhusb-base-20160319 nick-nhusb-base-20151226 netbsd-7-0-RELEASE nick-nhusb-base-20150921 netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 nick-nhusb-base-20150606 nick-nhusb-base-20150406 nick-nhusb-base tls-maxphys-base netbsd-7-base
# 1.1 10-Aug-2014 matt

branches: 1.1.4; 1.1.28;
Preliminary files for AARCH64 (64-bit ARM) support.
Enough for a distribution build.


# 1.80 27-Jun-2020 rin

Fix typo in name of evcnt(4) counter.


# 1.79 24-Jun-2020 ryo

Fix bug with incorrect range calculation when doing icache sync.
This is called by sysarch(ARM_SYNC_ICACHE) from aarch32 (compat_netbsd32) emul process.

pointed out by rin@, thanks.

XXX pullup-9


# 1.78 14-Jun-2020 ad

- Fix a lock order reversal in pmap_page_protect().

- Make sure pmap is always locked when updating stats; atomics no longer
needed to do that.

- Remove unneeded traversal of pv list in pmap_enter_pv().

- Shrink struct vm_page from 136 to 128 bytes (cache line sized) and struct
pv_entry from 48 to 32 bytes (power of 2 sized).

- Embed a pv_entry in each vm_page. This means PV entries don't need to
be allocated for private anonymous memory / COW pages / most UBC mappings.
Dynamic PV entries are then used only for stuff like shared libraries and
shared memory.

Proposed on port-arm@.


# 1.77 10-Jun-2020 ad

- Wired/resident stats shouldn't covered by PMAPCOUNTERS.
- Rename need_update_pv -> need_enter_pv.

Ok ryo@


# 1.76 01-Jun-2020 ryo

no need to make the PTE writable to do icache_sync, enough to accessible.


# 1.75 15-May-2020 skrll

Use __diagused


# 1.74 15-May-2020 tnn

fix non-diag build


# 1.73 14-May-2020 skrll

Use MUTEX_NODEBUG for PV locks as is commonly done. OK ryo.


# 1.72 13-May-2020 jmcneill

Implement pmap_extract_coherency


Revision tags: bouyer-xenpvh-base2 phil-wifi-20200421 bouyer-xenpvh-base1
# 1.71 18-Apr-2020 skrll

PMAP_DEBUG has been deleted on arm


# 1.70 13-Apr-2020 maxv

Add support for Branch Target Identification (BTI).

On the executable pages that have the GP (Guarded Page) bit, the semantic
of the "br" and "blr" instructions is changed: the CPU expects the first
instruction of the jump/call target to be "bti", and faults if it isn't.

We add the GP bit on the kernel .text pages (and incidentally the .rodata
pages, but we don't care). The compiler adds a "bti c" instruction at the
beginning of each C function. We modify the ENTRY() macros to manually add
"bti c" in the asm functions.

cpuswitch.S needs a specific change: with "br x27" the CPU expects "bti j",
which is bad because the functions begin with "bti c"; switch to "br x16",
for the CPU to accept "bti c".

BTI helps defend against JOP/COP. Tested on Qemu.


Revision tags: phil-wifi-20200411 bouyer-xenpvh-base
# 1.69 08-Apr-2020 ryo

branches: 1.69.2;
use PMAP_PAGE_INIT() to initialize mutex in pmap_page.

VM_MDPAGE_INIT() in pmap_free_pdp() had initialized pp_flags,
so it unintentionally cleared PMAP_PAGE_FLAGS_PV_TRACKED.
use PMAP_PAGE_INIT to avoid using PMAP_PAGE_FLAGS_PV_TRACKED.

pointed out by tnn@, thanks


Revision tags: phil-wifi-20200406
# 1.68 14-Mar-2020 ad

pmap_remove_all(): Return a boolean value to indicate the behaviour. If
true, all mappings have been removed, the pmap is totally cleared out, and
UVM can then avoid doing the work to call pmap_remove() for each map entry.
If false, either nothing has been done, or some helpful arch-specific voodoo
has taken place.


Revision tags: is-mlppp-base
# 1.67 02-Mar-2020 ryo

oops, fix incorrect usage of daif_enable() in my previous commit.


# 1.66 29-Feb-2020 ryo

Fix pmap to work correctly with tagged addresses

- when fault, untag from address before passing to uvm/pmap functions
- pmap_extract() checks more strictly and consider the address tag


# 1.65 29-Feb-2020 ryo

use pmapboot_enter_range()


Revision tags: ad-namecache-base3
# 1.64 10-Feb-2020 ryo

use LIST(3) instead of TAILQ(3) to save one word in struct vm_page and struct pmap.

pointed out by riastradh@. thanks


# 1.63 03-Feb-2020 ryo

add support pmap_pv(9)

Patch originally from jmcneill@. thanks


# 1.62 03-Feb-2020 ryo

separate struct vm_page_md into vm_page_md and pmap_page
for preparation pmap_pv(9)


Revision tags: ad-namecache-base2 ad-namecache-base1
# 1.61 09-Jan-2020 ryo

fix behaviour mmap()/mprotect() when passed only PROT_EXEC.

when mmap()/mprotect() with only PROT_EXEC, syscall will be successful,
but the page actually hadn't been mapped.
it should be mapped with PROT_READ|PROT_EXEC implicitly. (r-x)


Revision tags: ad-namecache-base
# 1.60 30-Dec-2019 skrll

branches: 1.60.2;
Update pmap_map_chunk to allow L[12] block mappings and L3 page mappings


# 1.59 30-Dec-2019 skrll

Remove unnecessary brackets and unwrap a conditional. Same code before
and after.


# 1.58 28-Dec-2019 jmcneill

Do not use Early Write Acknowledge for PCIe I/O and config space.


# 1.57 27-Dec-2019 jmcneill

Enable early write acknowledge for device memory mappings.


# 1.56 19-Dec-2019 skrll

G/C kasan_shadow_map call in pmap_enter

pmap_growkernel calls kasan_shadow_map for KVA


# 1.55 18-Dec-2019 ryo

atomic_add_16() is not used in pmap.c anymore. no need decl here.


# 1.54 18-Dec-2019 ryo

space to tab


# 1.53 14-Dec-2019 skrll

Fix build... wire_count probably doesn't need atomics


# 1.52 13-Dec-2019 skrll

Fix KASAN support by calling kasan_shadow_map in pmap_growkernel


# 1.51 10-Dec-2019 ad

pg->phys_addr -> VM_PAGE_TO_PHYS(pg)


Revision tags: phil-wifi-20191119
# 1.50 14-Nov-2019 maxv

Mark several kASan functions with __nothing, to avoid annoying #ifdefs.
Same as kCSan and kMSan.


# 1.49 14-Nov-2019 maxv

Don't include "opt_kasan.h" when there's already <sys/asan.h> included.


# 1.48 29-Oct-2019 maya

Define PMAP_NEED_PROCWR, providing strategically placed i-cache
synchronization where just-changed memory is about to be executed.

Fixes SIGILLs seen when running Mono 6 on QEMU Cortex-A57.

ok ryo


# 1.47 22-Sep-2019 jmcneill

Disable translation table walks using TTBR0 while changing its value and
when deactivating a pmap. Fixes stability issues on Ampere eMAG CPUs.


# 1.46 20-Sep-2019 ryo

ref/mod bit should be set according to 'flags' argument, not 'prot'. r1.44 was incomplete.


# 1.45 13-Sep-2019 ryo

In pmap_devmap_bootstrap(), cpu_earlydevice_va_p() must not return true until *all* devmap tables have been enabled.
console mapping may be present in the last table.


# 1.44 07-Sep-2019 ryo

- remove incorrect KASSERT. mmap(2) with prot=PROT_WRITE calls pmap_enter(..., PROT_WRITE) internally.
- fix to update page reference flags when only PROT_WRITE or PROT_EXECUTE specified


# 1.43 15-Aug-2019 skrll

Make pmap_db_pte_print more terse so it's quicker on serial consoles


# 1.42 12-Aug-2019 skrll

Use PMAP_DEV in DEVMAP_ENTRY rather than pmap_map_chunk. It's clearer and
means pmap_map_chunk can be made to map other memory types.


Revision tags: netbsd-9-base phil-wifi-20190609
# 1.41 17-May-2019 mrg

branches: 1.41.2;
apply some __diagused.


Revision tags: isaki-audio2-base
# 1.40 08-Apr-2019 ryo

- free empty page tables pages if reach a certain usage.
- need to lock at removing an old pg (_pmap_remove_pv) in _pmap_enter()


# 1.39 06-Apr-2019 ryo

Fix race conditions about pmap_page_protect() and pmap_enter().

while handling same PTE by these functions in same time, there
is a critical path that the number of valid PTEs and wire_count
are inconsistent, and it caused KASSERT.
Need to hold a pv_lock while modifying them.


# 1.38 20-Mar-2019 ryo

spinkle __printflike(), and use PRIxxx


# 1.37 19-Mar-2019 ryo

- add ddb command "machine ttbr" to dump MMU tables.
- tidy up descriptions, usages and messages.


# 1.36 19-Mar-2019 ryo

- free L1-L3 pages that has been emptied by pmap_remove().
- if no memories, pmap_enter will return correctly ENOMEM if PMAP_CANFAIL, or wait until available any memories if !PMAP_CANFAIL.

These changes improves the stability when we use a huge virtual memory spaces with mmap.


# 1.35 06-Feb-2019 ryo

improve pmap_remove
- don't lock/unlock per page in pmap_remove()
- speedup pte lookup for continuous addresses
- bring out pool_cache_put(&_pmap_pv_pool, pv) from lock/unlock section


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226
# 1.34 21-Dec-2018 ryo

- add workaround for Cavium ThunderX errata 27456.
- add cpufuncs table in cpu_info. each cpu clusters may have different erratum. (e.g. big.LITTLE)


Revision tags: pgoyette-compat-1126
# 1.33 01-Nov-2018 maxv

Add kASan support for aarch64. Stack tracking needs more investigation
and will come in a separate commit.

Reviewed by ryo@ jmcneill@ skrll@.


# 1.32 31-Oct-2018 ryo

invalidate icache correctly.
l3pte_executable() should be used for only valid pte.


Revision tags: pgoyette-compat-1020
# 1.31 18-Oct-2018 skrll

Provide generic start code that assumes the MMU is off and caches are
disabled as per the linux booting protocol for ARMv6 and ARMv7 boards.
u-boot image type should be changed to 'linux' for correct behaviour.

The new start code builds a minimal "bootstrap" L1PT with cached access
disabled and uses the same table for all processors. AP startup is
performed in less steps and more code is written in C.

The bootstrap tables and stack are placed into an (orphaned) section
"_init_memory" which is given to uvm when it is no longer used.

Various kernels have been converted to use this code and tested. Some
boards were provided by TNF. Thanks!

The GENERIC kernel now boots on boards using the TEGRA, SUNXI and EXYNOS
kernels. The GENERIC kernel will also work on RPI2 using u-boot.

Thanks to martin@ and aymeric@ for testing on parallella and nanosoc
respectively


# 1.30 14-Oct-2018 skrll

Use __nothing


# 1.29 12-Oct-2018 ryo

add initial support of COMPAT_NETBSD32 on AArch64.
arm ELF32 EABI binaries could be execute in AArch32 state on AArch64. A32 THUMB mode is not supported yet.


# 1.28 12-Oct-2018 ryo

- cleanup checking address ranges with IN_RANGE macro
- change PM_ADDR_CHECK macro to KASSERTMSG
- restore fast lookup cases with IN_RANGE macro for pmap_extract changed in my previous commit.


# 1.27 12-Oct-2018 ryo

rewrite pmap_pte_lookup() to share similar code.


# 1.26 04-Oct-2018 ryo

cleanup locore, and changed the way to map memories during boot.
- add functions bootpage_enter() and bootpage_alloc() to adapt various layout
of physical memory map. especially for 64bit physical memory layout.
pmapboot_alloc() allocates pagetable pages from _end[].
- changed to map only the required amount for PA=VA identity mapping
(kernel image, UART device, and FDT blob) with L2_BLOCK(2Mbyte).
- changing page permission for kernel image, and making KSEG mapping are done
at cpu_kernel_vm_init() instead of at locore.
- optimize PTE entries with PTE Contiguous bit. it is enabled on devmap only for now.

reviewed by skrll@, thanks.


# 1.25 04-Oct-2018 ryo

* define LX_BLKPAG_{OS,ATTR}_* for OS dependent PTE attributes in pmap.h
* cleanup macros


Revision tags: pgoyette-compat-0930
# 1.24 17-Sep-2018 ryo

delete debug printf and KASSERT.


# 1.23 10-Sep-2018 maxv

Replace KDASSERT by panic.


# 1.22 10-Sep-2018 maxv

Rename _pmap_alloc_pdp -> pmap_alloc_pdp, and make it public.


# 1.21 10-Sep-2018 ryo

cleanup aarch64 mpstart and fdt bootstrap
* arm_cpu_hatch_arg is a bad idea. avoid serializing CPU startup, and eliminate arm_cpu_hatch_arg.
in mpstart, resolve own cpu index using array of cpu_mpidr[] (aarch64)
* add support fdt enable-method "spin-table"
* add support fdt enable-method "brcm,bcm2836-smp" (for 32bit RaspberryPi)
* use arm_fdt_cpu_bootstrap() instead of psci_fdt_bootstrap()
* rename "arm/fdt/psci_fdt.h" to "arm/fdt/psci_fdtvar.h" because of conflict of include file for needs-flag
* add devmap for cpu spin-table of raspberrypi3/aarch64
* no need to force hatch APs for raspberrypi3/arm32 ifndef MULTIPROCESSOR.
* fix to work pmap_extract(kerneltext/data/bss) even if before calling pmap_bootstrap

idea to use cpu_mpidr[] by jmcneill@. reviewd by skrll@. thanks.


Revision tags: pgoyette-compat-0906
# 1.20 27-Aug-2018 ryo

need to add VM_PROT_READ when pmap_kenter_pa(va, pa, VM_PROT_WRITE, 0) or pmap_kenter_pa(va, pa, VM_PROT_EXECUTE, 0).
VM_PROT_READ is treated as an access permission inernally.


# 1.19 11-Aug-2018 ryo

change to minimum invalidation of TLB.
specifying not only va but also asid, and not invalidate L0-L2 entry using tlbi_*_ll() if needed.


# 1.18 10-Aug-2018 ryo

treat kernel-exec attr and user-exec attr separately.
kernel cannot execute userland exec page, and user cannot execute kernel page.


# 1.17 06-Aug-2018 ryo

set kernel text/rodata readonly by default.
add function db_write_text() for setting ddb breakpoint.


# 1.16 31-Jul-2018 skrll

Define and use VPRINTF


Revision tags: pgoyette-compat-0728
# 1.15 27-Jul-2018 ryo

changes of pmap.c r1.13 seems to be unstable.
In order to invalidate icache, not to invalidate all icache,
but temporary to make the page writable and invalidate target address only.


# 1.14 24-Jul-2018 ryo

don't call pool_cache_put with locking pmap. pool_cache_put call pmap_kenter_pa internally.
(pool_cache_put_paddr -> pool_cache_put_slow -> pool_get -> pmap_kenter_pa)


# 1.13 23-Jul-2018 ryo

* fix icache invalidations.
* "ic ivau" (aarch64_icache_sync_range) with VA generates permission fault in some situations, therefore use KSEG address for now.


# 1.12 23-Jul-2018 ryo

rather than using flags to resolve nested locks, reserve pool_cache before locking.


# 1.11 21-Jul-2018 ryo

* avoid deadlock. mutex_owned() works only for adaptive lock, therefore we cannot use it for spinlock...
* add more NULL check
* clear pte when pmap_enter() fails


# 1.10 17-Jul-2018 ryo

Use __debugused


# 1.9 17-Jul-2018 christos

Add missing casts, remove unused variables.


# 1.8 09-Jul-2018 ryo

need locks in pmap_kremove() and pmap_fault_fixup()


Revision tags: phil-wifi-base pgoyette-compat-0625 pgoyette-compat-0521
# 1.7 20-May-2018 ryo

branches: 1.7.2;
pmap_enter() must update modified/referenced flags by 'flags' not 'prot'.


# 1.6 16-May-2018 ryo

Fix memory leak. it was leaking one page every pmap_create().
pm->pm_vmlist must be initialized before calling _pmap_alloc_pdp().


Revision tags: pgoyette-compat-0502
# 1.5 29-Apr-2018 ryo

fix KASSERT panic. pv_entry may not be exists in pvlist when pmap_remove().


# 1.4 29-Apr-2018 ryo

delete unused code


# 1.3 27-Apr-2018 ryo

fix instability behavior of bufcache on aarch64.
* fix to return correct ref/mod when PMAP_WIRED.
* changed to keep wired flags in pte instead of pv_entry, and cleanup.


Revision tags: pgoyette-compat-0422 pgoyette-compat-0415 pgoyette-compat-0407
# 1.2 01-Apr-2018 ryo

Add initial support for ARMv8 (AARCH64) (by nisimura@ and ryo@)

- sys/arch/evbarm64 is gone and integrated into sys/arch/evbarm. (by skrll@)
- add support fdt. evbarm/conf/GENERIC64 fdt (bcm2837,sunxi,tegra) based generic 64bit kernel config. (by skrll@, jmcneill@)


Revision tags: netbsd-8-2-RELEASE netbsd-8-1-RELEASE netbsd-8-1-RC1 netbsd-7-2-RELEASE netbsd-8-0-RELEASE netbsd-8-0-RC2 netbsd-8-0-RC1 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 netbsd-7-1-2-RELEASE pgoyette-compat-base netbsd-7-1-1-RELEASE tls-maxphys-base-20171202 matt-nb8-mediatek-base nick-nhusb-base-20170825 perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base pgoyette-localcount-20170320 netbsd-7-1-RELEASE netbsd-7-1-RC2 nick-nhusb-base-20170204 netbsd-7-nhusb-base-20170116 bouyer-socketcan-base pgoyette-localcount-20170107 netbsd-7-1-RC1 nick-nhusb-base-20161204 pgoyette-localcount-20161104 netbsd-7-0-2-RELEASE nick-nhusb-base-20161004 localcount-20160914 netbsd-7-nhusb-base pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907 nick-nhusb-base-20160529 netbsd-7-0-1-RELEASE nick-nhusb-base-20160422 nick-nhusb-base-20160319 nick-nhusb-base-20151226 netbsd-7-0-RELEASE nick-nhusb-base-20150921 netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 nick-nhusb-base-20150606 nick-nhusb-base-20150406 nick-nhusb-base tls-maxphys-base netbsd-7-base
# 1.1 10-Aug-2014 matt

branches: 1.1.4; 1.1.28;
Preliminary files for AARCH64 (64-bit ARM) support.
Enough for a distribution build.


# 1.79 24-Jun-2020 ryo

Fix bug with incorrect range calculation when doing icache sync.
This is called by sysarch(ARM_SYNC_ICACHE) from aarch32 (compat_netbsd32) emul process.

pointed out by rin@, thanks.

XXX pullup-9


# 1.78 14-Jun-2020 ad

- Fix a lock order reversal in pmap_page_protect().

- Make sure pmap is always locked when updating stats; atomics no longer
needed to do that.

- Remove unneeded traversal of pv list in pmap_enter_pv().

- Shrink struct vm_page from 136 to 128 bytes (cache line sized) and struct
pv_entry from 48 to 32 bytes (power of 2 sized).

- Embed a pv_entry in each vm_page. This means PV entries don't need to
be allocated for private anonymous memory / COW pages / most UBC mappings.
Dynamic PV entries are then used only for stuff like shared libraries and
shared memory.

Proposed on port-arm@.


# 1.77 10-Jun-2020 ad

- Wired/resident stats shouldn't covered by PMAPCOUNTERS.
- Rename need_update_pv -> need_enter_pv.

Ok ryo@


# 1.76 01-Jun-2020 ryo

no need to make the PTE writable to do icache_sync, enough to accessible.


# 1.75 15-May-2020 skrll

Use __diagused


# 1.74 15-May-2020 tnn

fix non-diag build


# 1.73 14-May-2020 skrll

Use MUTEX_NODEBUG for PV locks as is commonly done. OK ryo.


# 1.72 13-May-2020 jmcneill

Implement pmap_extract_coherency


Revision tags: bouyer-xenpvh-base2 phil-wifi-20200421 bouyer-xenpvh-base1
# 1.71 18-Apr-2020 skrll

PMAP_DEBUG has been deleted on arm


# 1.70 13-Apr-2020 maxv

Add support for Branch Target Identification (BTI).

On the executable pages that have the GP (Guarded Page) bit, the semantic
of the "br" and "blr" instructions is changed: the CPU expects the first
instruction of the jump/call target to be "bti", and faults if it isn't.

We add the GP bit on the kernel .text pages (and incidentally the .rodata
pages, but we don't care). The compiler adds a "bti c" instruction at the
beginning of each C function. We modify the ENTRY() macros to manually add
"bti c" in the asm functions.

cpuswitch.S needs a specific change: with "br x27" the CPU expects "bti j",
which is bad because the functions begin with "bti c"; switch to "br x16",
for the CPU to accept "bti c".

BTI helps defend against JOP/COP. Tested on Qemu.


Revision tags: phil-wifi-20200411 bouyer-xenpvh-base
# 1.69 08-Apr-2020 ryo

branches: 1.69.2;
use PMAP_PAGE_INIT() to initialize mutex in pmap_page.

VM_MDPAGE_INIT() in pmap_free_pdp() had initialized pp_flags,
so it unintentionally cleared PMAP_PAGE_FLAGS_PV_TRACKED.
use PMAP_PAGE_INIT to avoid using PMAP_PAGE_FLAGS_PV_TRACKED.

pointed out by tnn@, thanks


Revision tags: phil-wifi-20200406
# 1.68 14-Mar-2020 ad

pmap_remove_all(): Return a boolean value to indicate the behaviour. If
true, all mappings have been removed, the pmap is totally cleared out, and
UVM can then avoid doing the work to call pmap_remove() for each map entry.
If false, either nothing has been done, or some helpful arch-specific voodoo
has taken place.


Revision tags: is-mlppp-base
# 1.67 02-Mar-2020 ryo

oops, fix incorrect usage of daif_enable() in my previous commit.


# 1.66 29-Feb-2020 ryo

Fix pmap to work correctly with tagged addresses

- when fault, untag from address before passing to uvm/pmap functions
- pmap_extract() checks more strictly and consider the address tag


# 1.65 29-Feb-2020 ryo

use pmapboot_enter_range()


Revision tags: ad-namecache-base3
# 1.64 10-Feb-2020 ryo

use LIST(3) instead of TAILQ(3) to save one word in struct vm_page and struct pmap.

pointed out by riastradh@. thanks


# 1.63 03-Feb-2020 ryo

add support pmap_pv(9)

Patch originally from jmcneill@. thanks


# 1.62 03-Feb-2020 ryo

separate struct vm_page_md into vm_page_md and pmap_page
for preparation pmap_pv(9)


Revision tags: ad-namecache-base2 ad-namecache-base1
# 1.61 09-Jan-2020 ryo

fix behaviour mmap()/mprotect() when passed only PROT_EXEC.

when mmap()/mprotect() with only PROT_EXEC, syscall will be successful,
but the page actually hadn't been mapped.
it should be mapped with PROT_READ|PROT_EXEC implicitly. (r-x)


Revision tags: ad-namecache-base
# 1.60 30-Dec-2019 skrll

branches: 1.60.2;
Update pmap_map_chunk to allow L[12] block mappings and L3 page mappings


# 1.59 30-Dec-2019 skrll

Remove unnecessary brackets and unwrap a conditional. Same code before
and after.


# 1.58 28-Dec-2019 jmcneill

Do not use Early Write Acknowledge for PCIe I/O and config space.


# 1.57 27-Dec-2019 jmcneill

Enable early write acknowledge for device memory mappings.


# 1.56 19-Dec-2019 skrll

G/C kasan_shadow_map call in pmap_enter

pmap_growkernel calls kasan_shadow_map for KVA


# 1.55 18-Dec-2019 ryo

atomic_add_16() is not used in pmap.c anymore. no need decl here.


# 1.54 18-Dec-2019 ryo

space to tab


# 1.53 14-Dec-2019 skrll

Fix build... wire_count probably doesn't need atomics


# 1.52 13-Dec-2019 skrll

Fix KASAN support by calling kasan_shadow_map in pmap_growkernel


# 1.51 10-Dec-2019 ad

pg->phys_addr -> VM_PAGE_TO_PHYS(pg)


Revision tags: phil-wifi-20191119
# 1.50 14-Nov-2019 maxv

Mark several kASan functions with __nothing, to avoid annoying #ifdefs.
Same as kCSan and kMSan.


# 1.49 14-Nov-2019 maxv

Don't include "opt_kasan.h" when there's already <sys/asan.h> included.


# 1.48 29-Oct-2019 maya

Define PMAP_NEED_PROCWR, providing strategically placed i-cache
synchronization where just-changed memory is about to be executed.

Fixes SIGILLs seen when running Mono 6 on QEMU Cortex-A57.

ok ryo


# 1.47 22-Sep-2019 jmcneill

Disable translation table walks using TTBR0 while changing its value and
when deactivating a pmap. Fixes stability issues on Ampere eMAG CPUs.


# 1.46 20-Sep-2019 ryo

ref/mod bit should be set according to 'flags' argument, not 'prot'. r1.44 was incomplete.


# 1.45 13-Sep-2019 ryo

In pmap_devmap_bootstrap(), cpu_earlydevice_va_p() must not return true until *all* devmap tables have been enabled.
console mapping may be present in the last table.


# 1.44 07-Sep-2019 ryo

- remove incorrect KASSERT. mmap(2) with prot=PROT_WRITE calls pmap_enter(..., PROT_WRITE) internally.
- fix to update page reference flags when only PROT_WRITE or PROT_EXECUTE specified


# 1.43 15-Aug-2019 skrll

Make pmap_db_pte_print more terse so it's quicker on serial consoles


# 1.42 12-Aug-2019 skrll

Use PMAP_DEV in DEVMAP_ENTRY rather than pmap_map_chunk. It's clearer and
means pmap_map_chunk can be made to map other memory types.


Revision tags: netbsd-9-base phil-wifi-20190609
# 1.41 17-May-2019 mrg

branches: 1.41.2;
apply some __diagused.


Revision tags: isaki-audio2-base
# 1.40 08-Apr-2019 ryo

- free empty page tables pages if reach a certain usage.
- need to lock at removing an old pg (_pmap_remove_pv) in _pmap_enter()


# 1.39 06-Apr-2019 ryo

Fix race conditions about pmap_page_protect() and pmap_enter().

while handling same PTE by these functions in same time, there
is a critical path that the number of valid PTEs and wire_count
are inconsistent, and it caused KASSERT.
Need to hold a pv_lock while modifying them.


# 1.38 20-Mar-2019 ryo

spinkle __printflike(), and use PRIxxx


# 1.37 19-Mar-2019 ryo

- add ddb command "machine ttbr" to dump MMU tables.
- tidy up descriptions, usages and messages.


# 1.36 19-Mar-2019 ryo

- free L1-L3 pages that has been emptied by pmap_remove().
- if no memories, pmap_enter will return correctly ENOMEM if PMAP_CANFAIL, or wait until available any memories if !PMAP_CANFAIL.

These changes improves the stability when we use a huge virtual memory spaces with mmap.


# 1.35 06-Feb-2019 ryo

improve pmap_remove
- don't lock/unlock per page in pmap_remove()
- speedup pte lookup for continuous addresses
- bring out pool_cache_put(&_pmap_pv_pool, pv) from lock/unlock section


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226
# 1.34 21-Dec-2018 ryo

- add workaround for Cavium ThunderX errata 27456.
- add cpufuncs table in cpu_info. each cpu clusters may have different erratum. (e.g. big.LITTLE)


Revision tags: pgoyette-compat-1126
# 1.33 01-Nov-2018 maxv

Add kASan support for aarch64. Stack tracking needs more investigation
and will come in a separate commit.

Reviewed by ryo@ jmcneill@ skrll@.


# 1.32 31-Oct-2018 ryo

invalidate icache correctly.
l3pte_executable() should be used for only valid pte.


Revision tags: pgoyette-compat-1020
# 1.31 18-Oct-2018 skrll

Provide generic start code that assumes the MMU is off and caches are
disabled as per the linux booting protocol for ARMv6 and ARMv7 boards.
u-boot image type should be changed to 'linux' for correct behaviour.

The new start code builds a minimal "bootstrap" L1PT with cached access
disabled and uses the same table for all processors. AP startup is
performed in less steps and more code is written in C.

The bootstrap tables and stack are placed into an (orphaned) section
"_init_memory" which is given to uvm when it is no longer used.

Various kernels have been converted to use this code and tested. Some
boards were provided by TNF. Thanks!

The GENERIC kernel now boots on boards using the TEGRA, SUNXI and EXYNOS
kernels. The GENERIC kernel will also work on RPI2 using u-boot.

Thanks to martin@ and aymeric@ for testing on parallella and nanosoc
respectively


# 1.30 14-Oct-2018 skrll

Use __nothing


# 1.29 12-Oct-2018 ryo

add initial support of COMPAT_NETBSD32 on AArch64.
arm ELF32 EABI binaries could be execute in AArch32 state on AArch64. A32 THUMB mode is not supported yet.


# 1.28 12-Oct-2018 ryo

- cleanup checking address ranges with IN_RANGE macro
- change PM_ADDR_CHECK macro to KASSERTMSG
- restore fast lookup cases with IN_RANGE macro for pmap_extract changed in my previous commit.


# 1.27 12-Oct-2018 ryo

rewrite pmap_pte_lookup() to share similar code.


# 1.26 04-Oct-2018 ryo

cleanup locore, and changed the way to map memories during boot.
- add functions bootpage_enter() and bootpage_alloc() to adapt various layout
of physical memory map. especially for 64bit physical memory layout.
pmapboot_alloc() allocates pagetable pages from _end[].
- changed to map only the required amount for PA=VA identity mapping
(kernel image, UART device, and FDT blob) with L2_BLOCK(2Mbyte).
- changing page permission for kernel image, and making KSEG mapping are done
at cpu_kernel_vm_init() instead of at locore.
- optimize PTE entries with PTE Contiguous bit. it is enabled on devmap only for now.

reviewed by skrll@, thanks.


# 1.25 04-Oct-2018 ryo

* define LX_BLKPAG_{OS,ATTR}_* for OS dependent PTE attributes in pmap.h
* cleanup macros


Revision tags: pgoyette-compat-0930
# 1.24 17-Sep-2018 ryo

delete debug printf and KASSERT.


# 1.23 10-Sep-2018 maxv

Replace KDASSERT by panic.


# 1.22 10-Sep-2018 maxv

Rename _pmap_alloc_pdp -> pmap_alloc_pdp, and make it public.


# 1.21 10-Sep-2018 ryo

cleanup aarch64 mpstart and fdt bootstrap
* arm_cpu_hatch_arg is a bad idea. avoid serializing CPU startup, and eliminate arm_cpu_hatch_arg.
in mpstart, resolve own cpu index using array of cpu_mpidr[] (aarch64)
* add support fdt enable-method "spin-table"
* add support fdt enable-method "brcm,bcm2836-smp" (for 32bit RaspberryPi)
* use arm_fdt_cpu_bootstrap() instead of psci_fdt_bootstrap()
* rename "arm/fdt/psci_fdt.h" to "arm/fdt/psci_fdtvar.h" because of conflict of include file for needs-flag
* add devmap for cpu spin-table of raspberrypi3/aarch64
* no need to force hatch APs for raspberrypi3/arm32 ifndef MULTIPROCESSOR.
* fix to work pmap_extract(kerneltext/data/bss) even if before calling pmap_bootstrap

idea to use cpu_mpidr[] by jmcneill@. reviewd by skrll@. thanks.


Revision tags: pgoyette-compat-0906
# 1.20 27-Aug-2018 ryo

need to add VM_PROT_READ when pmap_kenter_pa(va, pa, VM_PROT_WRITE, 0) or pmap_kenter_pa(va, pa, VM_PROT_EXECUTE, 0).
VM_PROT_READ is treated as an access permission inernally.


# 1.19 11-Aug-2018 ryo

change to minimum invalidation of TLB.
specifying not only va but also asid, and not invalidate L0-L2 entry using tlbi_*_ll() if needed.


# 1.18 10-Aug-2018 ryo

treat kernel-exec attr and user-exec attr separately.
kernel cannot execute userland exec page, and user cannot execute kernel page.


# 1.17 06-Aug-2018 ryo

set kernel text/rodata readonly by default.
add function db_write_text() for setting ddb breakpoint.


# 1.16 31-Jul-2018 skrll

Define and use VPRINTF


Revision tags: pgoyette-compat-0728
# 1.15 27-Jul-2018 ryo

changes of pmap.c r1.13 seems to be unstable.
In order to invalidate icache, not to invalidate all icache,
but temporary to make the page writable and invalidate target address only.


# 1.14 24-Jul-2018 ryo

don't call pool_cache_put with locking pmap. pool_cache_put call pmap_kenter_pa internally.
(pool_cache_put_paddr -> pool_cache_put_slow -> pool_get -> pmap_kenter_pa)


# 1.13 23-Jul-2018 ryo

* fix icache invalidations.
* "ic ivau" (aarch64_icache_sync_range) with VA generates permission fault in some situations, therefore use KSEG address for now.


# 1.12 23-Jul-2018 ryo

rather than using flags to resolve nested locks, reserve pool_cache before locking.


# 1.11 21-Jul-2018 ryo

* avoid deadlock. mutex_owned() works only for adaptive lock, therefore we cannot use it for spinlock...
* add more NULL check
* clear pte when pmap_enter() fails


# 1.10 17-Jul-2018 ryo

Use __debugused


# 1.9 17-Jul-2018 christos

Add missing casts, remove unused variables.


# 1.8 09-Jul-2018 ryo

need locks in pmap_kremove() and pmap_fault_fixup()


Revision tags: phil-wifi-base pgoyette-compat-0625 pgoyette-compat-0521
# 1.7 20-May-2018 ryo

branches: 1.7.2;
pmap_enter() must update modified/referenced flags by 'flags' not 'prot'.


# 1.6 16-May-2018 ryo

Fix memory leak. it was leaking one page every pmap_create().
pm->pm_vmlist must be initialized before calling _pmap_alloc_pdp().


Revision tags: pgoyette-compat-0502
# 1.5 29-Apr-2018 ryo

fix KASSERT panic. pv_entry may not be exists in pvlist when pmap_remove().


# 1.4 29-Apr-2018 ryo

delete unused code


# 1.3 27-Apr-2018 ryo

fix instability behavior of bufcache on aarch64.
* fix to return correct ref/mod when PMAP_WIRED.
* changed to keep wired flags in pte instead of pv_entry, and cleanup.


Revision tags: pgoyette-compat-0422 pgoyette-compat-0415 pgoyette-compat-0407
# 1.2 01-Apr-2018 ryo

Add initial support for ARMv8 (AARCH64) (by nisimura@ and ryo@)

- sys/arch/evbarm64 is gone and integrated into sys/arch/evbarm. (by skrll@)
- add support fdt. evbarm/conf/GENERIC64 fdt (bcm2837,sunxi,tegra) based generic 64bit kernel config. (by skrll@, jmcneill@)


Revision tags: netbsd-8-2-RELEASE netbsd-8-1-RELEASE netbsd-8-1-RC1 netbsd-7-2-RELEASE netbsd-8-0-RELEASE netbsd-8-0-RC2 netbsd-8-0-RC1 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 netbsd-7-1-2-RELEASE pgoyette-compat-base netbsd-7-1-1-RELEASE tls-maxphys-base-20171202 matt-nb8-mediatek-base nick-nhusb-base-20170825 perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base pgoyette-localcount-20170320 netbsd-7-1-RELEASE netbsd-7-1-RC2 nick-nhusb-base-20170204 netbsd-7-nhusb-base-20170116 bouyer-socketcan-base pgoyette-localcount-20170107 netbsd-7-1-RC1 nick-nhusb-base-20161204 pgoyette-localcount-20161104 netbsd-7-0-2-RELEASE nick-nhusb-base-20161004 localcount-20160914 netbsd-7-nhusb-base pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907 nick-nhusb-base-20160529 netbsd-7-0-1-RELEASE nick-nhusb-base-20160422 nick-nhusb-base-20160319 nick-nhusb-base-20151226 netbsd-7-0-RELEASE nick-nhusb-base-20150921 netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 nick-nhusb-base-20150606 nick-nhusb-base-20150406 nick-nhusb-base tls-maxphys-base netbsd-7-base
# 1.1 10-Aug-2014 matt

branches: 1.1.4; 1.1.28;
Preliminary files for AARCH64 (64-bit ARM) support.
Enough for a distribution build.


# 1.78 14-Jun-2020 ad

- Fix a lock order reversal in pmap_page_protect().

- Make sure pmap is always locked when updating stats; atomics no longer
needed to do that.

- Remove unneeded traversal of pv list in pmap_enter_pv().

- Shrink struct vm_page from 136 to 128 bytes (cache line sized) and struct
pv_entry from 48 to 32 bytes (power of 2 sized).

- Embed a pv_entry in each vm_page. This means PV entries don't need to
be allocated for private anonymous memory / COW pages / most UBC mappings.
Dynamic PV entries are then used only for stuff like shared libraries and
shared memory.

Proposed on port-arm@.


# 1.77 10-Jun-2020 ad

- Wired/resident stats shouldn't covered by PMAPCOUNTERS.
- Rename need_update_pv -> need_enter_pv.

Ok ryo@


# 1.76 01-Jun-2020 ryo

no need to make the PTE writable to do icache_sync, enough to accessible.


# 1.75 15-May-2020 skrll

Use __diagused


# 1.74 15-May-2020 tnn

fix non-diag build


# 1.73 14-May-2020 skrll

Use MUTEX_NODEBUG for PV locks as is commonly done. OK ryo.


# 1.72 13-May-2020 jmcneill

Implement pmap_extract_coherency


Revision tags: bouyer-xenpvh-base2 phil-wifi-20200421 bouyer-xenpvh-base1
# 1.71 18-Apr-2020 skrll

PMAP_DEBUG has been deleted on arm


# 1.70 13-Apr-2020 maxv

Add support for Branch Target Identification (BTI).

On the executable pages that have the GP (Guarded Page) bit, the semantic
of the "br" and "blr" instructions is changed: the CPU expects the first
instruction of the jump/call target to be "bti", and faults if it isn't.

We add the GP bit on the kernel .text pages (and incidentally the .rodata
pages, but we don't care). The compiler adds a "bti c" instruction at the
beginning of each C function. We modify the ENTRY() macros to manually add
"bti c" in the asm functions.

cpuswitch.S needs a specific change: with "br x27" the CPU expects "bti j",
which is bad because the functions begin with "bti c"; switch to "br x16",
for the CPU to accept "bti c".

BTI helps defend against JOP/COP. Tested on Qemu.


Revision tags: phil-wifi-20200411 bouyer-xenpvh-base
# 1.69 08-Apr-2020 ryo

branches: 1.69.2;
use PMAP_PAGE_INIT() to initialize mutex in pmap_page.

VM_MDPAGE_INIT() in pmap_free_pdp() had initialized pp_flags,
so it unintentionally cleared PMAP_PAGE_FLAGS_PV_TRACKED.
use PMAP_PAGE_INIT to avoid using PMAP_PAGE_FLAGS_PV_TRACKED.

pointed out by tnn@, thanks


Revision tags: phil-wifi-20200406
# 1.68 14-Mar-2020 ad

pmap_remove_all(): Return a boolean value to indicate the behaviour. If
true, all mappings have been removed, the pmap is totally cleared out, and
UVM can then avoid doing the work to call pmap_remove() for each map entry.
If false, either nothing has been done, or some helpful arch-specific voodoo
has taken place.


Revision tags: is-mlppp-base
# 1.67 02-Mar-2020 ryo

oops, fix incorrect usage of daif_enable() in my previous commit.


# 1.66 29-Feb-2020 ryo

Fix pmap to work correctly with tagged addresses

- when fault, untag from address before passing to uvm/pmap functions
- pmap_extract() checks more strictly and consider the address tag


# 1.65 29-Feb-2020 ryo

use pmapboot_enter_range()


Revision tags: ad-namecache-base3
# 1.64 10-Feb-2020 ryo

use LIST(3) instead of TAILQ(3) to save one word in struct vm_page and struct pmap.

pointed out by riastradh@. thanks


# 1.63 03-Feb-2020 ryo

add support pmap_pv(9)

Patch originally from jmcneill@. thanks


# 1.62 03-Feb-2020 ryo

separate struct vm_page_md into vm_page_md and pmap_page
for preparation pmap_pv(9)


Revision tags: ad-namecache-base2 ad-namecache-base1
# 1.61 09-Jan-2020 ryo

fix behaviour mmap()/mprotect() when passed only PROT_EXEC.

when mmap()/mprotect() with only PROT_EXEC, syscall will be successful,
but the page actually hadn't been mapped.
it should be mapped with PROT_READ|PROT_EXEC implicitly. (r-x)


Revision tags: ad-namecache-base
# 1.60 30-Dec-2019 skrll

branches: 1.60.2;
Update pmap_map_chunk to allow L[12] block mappings and L3 page mappings


# 1.59 30-Dec-2019 skrll

Remove unnecessary brackets and unwrap a conditional. Same code before
and after.


# 1.58 28-Dec-2019 jmcneill

Do not use Early Write Acknowledge for PCIe I/O and config space.


# 1.57 27-Dec-2019 jmcneill

Enable early write acknowledge for device memory mappings.


# 1.56 19-Dec-2019 skrll

G/C kasan_shadow_map call in pmap_enter

pmap_growkernel calls kasan_shadow_map for KVA


# 1.55 18-Dec-2019 ryo

atomic_add_16() is not used in pmap.c anymore. no need decl here.


# 1.54 18-Dec-2019 ryo

space to tab


# 1.53 14-Dec-2019 skrll

Fix build... wire_count probably doesn't need atomics


# 1.52 13-Dec-2019 skrll

Fix KASAN support by calling kasan_shadow_map in pmap_growkernel


# 1.51 10-Dec-2019 ad

pg->phys_addr -> VM_PAGE_TO_PHYS(pg)


Revision tags: phil-wifi-20191119
# 1.50 14-Nov-2019 maxv

Mark several kASan functions with __nothing, to avoid annoying #ifdefs.
Same as kCSan and kMSan.


# 1.49 14-Nov-2019 maxv

Don't include "opt_kasan.h" when there's already <sys/asan.h> included.


# 1.48 29-Oct-2019 maya

Define PMAP_NEED_PROCWR, providing strategically placed i-cache
synchronization where just-changed memory is about to be executed.

Fixes SIGILLs seen when running Mono 6 on QEMU Cortex-A57.

ok ryo


# 1.47 22-Sep-2019 jmcneill

Disable translation table walks using TTBR0 while changing its value and
when deactivating a pmap. Fixes stability issues on Ampere eMAG CPUs.


# 1.46 20-Sep-2019 ryo

ref/mod bit should be set according to 'flags' argument, not 'prot'. r1.44 was incomplete.


# 1.45 13-Sep-2019 ryo

In pmap_devmap_bootstrap(), cpu_earlydevice_va_p() must not return true until *all* devmap tables have been enabled.
console mapping may be present in the last table.


# 1.44 07-Sep-2019 ryo

- remove incorrect KASSERT. mmap(2) with prot=PROT_WRITE calls pmap_enter(..., PROT_WRITE) internally.
- fix to update page reference flags when only PROT_WRITE or PROT_EXECUTE specified


# 1.43 15-Aug-2019 skrll

Make pmap_db_pte_print more terse so it's quicker on serial consoles


# 1.42 12-Aug-2019 skrll

Use PMAP_DEV in DEVMAP_ENTRY rather than pmap_map_chunk. It's clearer and
means pmap_map_chunk can be made to map other memory types.


Revision tags: netbsd-9-base phil-wifi-20190609
# 1.41 17-May-2019 mrg

branches: 1.41.2;
apply some __diagused.


Revision tags: isaki-audio2-base
# 1.40 08-Apr-2019 ryo

- free empty page tables pages if reach a certain usage.
- need to lock at removing an old pg (_pmap_remove_pv) in _pmap_enter()


# 1.39 06-Apr-2019 ryo

Fix race conditions about pmap_page_protect() and pmap_enter().

while handling same PTE by these functions in same time, there
is a critical path that the number of valid PTEs and wire_count
are inconsistent, and it caused KASSERT.
Need to hold a pv_lock while modifying them.


# 1.38 20-Mar-2019 ryo

spinkle __printflike(), and use PRIxxx


# 1.37 19-Mar-2019 ryo

- add ddb command "machine ttbr" to dump MMU tables.
- tidy up descriptions, usages and messages.


# 1.36 19-Mar-2019 ryo

- free L1-L3 pages that has been emptied by pmap_remove().
- if no memories, pmap_enter will return correctly ENOMEM if PMAP_CANFAIL, or wait until available any memories if !PMAP_CANFAIL.

These changes improves the stability when we use a huge virtual memory spaces with mmap.


# 1.35 06-Feb-2019 ryo

improve pmap_remove
- don't lock/unlock per page in pmap_remove()
- speedup pte lookup for continuous addresses
- bring out pool_cache_put(&_pmap_pv_pool, pv) from lock/unlock section


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226
# 1.34 21-Dec-2018 ryo

- add workaround for Cavium ThunderX errata 27456.
- add cpufuncs table in cpu_info. each cpu clusters may have different erratum. (e.g. big.LITTLE)


Revision tags: pgoyette-compat-1126
# 1.33 01-Nov-2018 maxv

Add kASan support for aarch64. Stack tracking needs more investigation
and will come in a separate commit.

Reviewed by ryo@ jmcneill@ skrll@.


# 1.32 31-Oct-2018 ryo

invalidate icache correctly.
l3pte_executable() should be used for only valid pte.


Revision tags: pgoyette-compat-1020
# 1.31 18-Oct-2018 skrll

Provide generic start code that assumes the MMU is off and caches are
disabled as per the linux booting protocol for ARMv6 and ARMv7 boards.
u-boot image type should be changed to 'linux' for correct behaviour.

The new start code builds a minimal "bootstrap" L1PT with cached access
disabled and uses the same table for all processors. AP startup is
performed in less steps and more code is written in C.

The bootstrap tables and stack are placed into an (orphaned) section
"_init_memory" which is given to uvm when it is no longer used.

Various kernels have been converted to use this code and tested. Some
boards were provided by TNF. Thanks!

The GENERIC kernel now boots on boards using the TEGRA, SUNXI and EXYNOS
kernels. The GENERIC kernel will also work on RPI2 using u-boot.

Thanks to martin@ and aymeric@ for testing on parallella and nanosoc
respectively


# 1.30 14-Oct-2018 skrll

Use __nothing


# 1.29 12-Oct-2018 ryo

add initial support of COMPAT_NETBSD32 on AArch64.
arm ELF32 EABI binaries could be execute in AArch32 state on AArch64. A32 THUMB mode is not supported yet.


# 1.28 12-Oct-2018 ryo

- cleanup checking address ranges with IN_RANGE macro
- change PM_ADDR_CHECK macro to KASSERTMSG
- restore fast lookup cases with IN_RANGE macro for pmap_extract changed in my previous commit.


# 1.27 12-Oct-2018 ryo

rewrite pmap_pte_lookup() to share similar code.


# 1.26 04-Oct-2018 ryo

cleanup locore, and changed the way to map memories during boot.
- add functions bootpage_enter() and bootpage_alloc() to adapt various layout
of physical memory map. especially for 64bit physical memory layout.
pmapboot_alloc() allocates pagetable pages from _end[].
- changed to map only the required amount for PA=VA identity mapping
(kernel image, UART device, and FDT blob) with L2_BLOCK(2Mbyte).
- changing page permission for kernel image, and making KSEG mapping are done
at cpu_kernel_vm_init() instead of at locore.
- optimize PTE entries with PTE Contiguous bit. it is enabled on devmap only for now.

reviewed by skrll@, thanks.


# 1.25 04-Oct-2018 ryo

* define LX_BLKPAG_{OS,ATTR}_* for OS dependent PTE attributes in pmap.h
* cleanup macros


Revision tags: pgoyette-compat-0930
# 1.24 17-Sep-2018 ryo

delete debug printf and KASSERT.


# 1.23 10-Sep-2018 maxv

Replace KDASSERT by panic.


# 1.22 10-Sep-2018 maxv

Rename _pmap_alloc_pdp -> pmap_alloc_pdp, and make it public.


# 1.21 10-Sep-2018 ryo

cleanup aarch64 mpstart and fdt bootstrap
* arm_cpu_hatch_arg is a bad idea. avoid serializing CPU startup, and eliminate arm_cpu_hatch_arg.
in mpstart, resolve own cpu index using array of cpu_mpidr[] (aarch64)
* add support fdt enable-method "spin-table"
* add support fdt enable-method "brcm,bcm2836-smp" (for 32bit RaspberryPi)
* use arm_fdt_cpu_bootstrap() instead of psci_fdt_bootstrap()
* rename "arm/fdt/psci_fdt.h" to "arm/fdt/psci_fdtvar.h" because of conflict of include file for needs-flag
* add devmap for cpu spin-table of raspberrypi3/aarch64
* no need to force hatch APs for raspberrypi3/arm32 ifndef MULTIPROCESSOR.
* fix to work pmap_extract(kerneltext/data/bss) even if before calling pmap_bootstrap

idea to use cpu_mpidr[] by jmcneill@. reviewd by skrll@. thanks.


Revision tags: pgoyette-compat-0906
# 1.20 27-Aug-2018 ryo

need to add VM_PROT_READ when pmap_kenter_pa(va, pa, VM_PROT_WRITE, 0) or pmap_kenter_pa(va, pa, VM_PROT_EXECUTE, 0).
VM_PROT_READ is treated as an access permission inernally.


# 1.19 11-Aug-2018 ryo

change to minimum invalidation of TLB.
specifying not only va but also asid, and not invalidate L0-L2 entry using tlbi_*_ll() if needed.


# 1.18 10-Aug-2018 ryo

treat kernel-exec attr and user-exec attr separately.
kernel cannot execute userland exec page, and user cannot execute kernel page.


# 1.17 06-Aug-2018 ryo

set kernel text/rodata readonly by default.
add function db_write_text() for setting ddb breakpoint.


# 1.16 31-Jul-2018 skrll

Define and use VPRINTF


Revision tags: pgoyette-compat-0728
# 1.15 27-Jul-2018 ryo

changes of pmap.c r1.13 seems to be unstable.
In order to invalidate icache, not to invalidate all icache,
but temporary to make the page writable and invalidate target address only.


# 1.14 24-Jul-2018 ryo

don't call pool_cache_put with locking pmap. pool_cache_put call pmap_kenter_pa internally.
(pool_cache_put_paddr -> pool_cache_put_slow -> pool_get -> pmap_kenter_pa)


# 1.13 23-Jul-2018 ryo

* fix icache invalidations.
* "ic ivau" (aarch64_icache_sync_range) with VA generates permission fault in some situations, therefore use KSEG address for now.


# 1.12 23-Jul-2018 ryo

rather than using flags to resolve nested locks, reserve pool_cache before locking.


# 1.11 21-Jul-2018 ryo

* avoid deadlock. mutex_owned() works only for adaptive lock, therefore we cannot use it for spinlock...
* add more NULL check
* clear pte when pmap_enter() fails


# 1.10 17-Jul-2018 ryo

Use __debugused


# 1.9 17-Jul-2018 christos

Add missing casts, remove unused variables.


# 1.8 09-Jul-2018 ryo

need locks in pmap_kremove() and pmap_fault_fixup()


Revision tags: phil-wifi-base pgoyette-compat-0625 pgoyette-compat-0521
# 1.7 20-May-2018 ryo

branches: 1.7.2;
pmap_enter() must update modified/referenced flags by 'flags' not 'prot'.


# 1.6 16-May-2018 ryo

Fix memory leak. it was leaking one page every pmap_create().
pm->pm_vmlist must be initialized before calling _pmap_alloc_pdp().


Revision tags: pgoyette-compat-0502
# 1.5 29-Apr-2018 ryo

fix KASSERT panic. pv_entry may not be exists in pvlist when pmap_remove().


# 1.4 29-Apr-2018 ryo

delete unused code


# 1.3 27-Apr-2018 ryo

fix instability behavior of bufcache on aarch64.
* fix to return correct ref/mod when PMAP_WIRED.
* changed to keep wired flags in pte instead of pv_entry, and cleanup.


Revision tags: pgoyette-compat-0422 pgoyette-compat-0415 pgoyette-compat-0407
# 1.2 01-Apr-2018 ryo

Add initial support for ARMv8 (AARCH64) (by nisimura@ and ryo@)

- sys/arch/evbarm64 is gone and integrated into sys/arch/evbarm. (by skrll@)
- add support fdt. evbarm/conf/GENERIC64 fdt (bcm2837,sunxi,tegra) based generic 64bit kernel config. (by skrll@, jmcneill@)


Revision tags: netbsd-8-2-RELEASE netbsd-8-1-RELEASE netbsd-8-1-RC1 netbsd-7-2-RELEASE netbsd-8-0-RELEASE netbsd-8-0-RC2 netbsd-8-0-RC1 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 netbsd-7-1-2-RELEASE pgoyette-compat-base netbsd-7-1-1-RELEASE tls-maxphys-base-20171202 matt-nb8-mediatek-base nick-nhusb-base-20170825 perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base pgoyette-localcount-20170320 netbsd-7-1-RELEASE netbsd-7-1-RC2 nick-nhusb-base-20170204 netbsd-7-nhusb-base-20170116 bouyer-socketcan-base pgoyette-localcount-20170107 netbsd-7-1-RC1 nick-nhusb-base-20161204 pgoyette-localcount-20161104 netbsd-7-0-2-RELEASE nick-nhusb-base-20161004 localcount-20160914 netbsd-7-nhusb-base pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907 nick-nhusb-base-20160529 netbsd-7-0-1-RELEASE nick-nhusb-base-20160422 nick-nhusb-base-20160319 nick-nhusb-base-20151226 netbsd-7-0-RELEASE nick-nhusb-base-20150921 netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 nick-nhusb-base-20150606 nick-nhusb-base-20150406 nick-nhusb-base tls-maxphys-base netbsd-7-base
# 1.1 10-Aug-2014 matt

branches: 1.1.4; 1.1.28;
Preliminary files for AARCH64 (64-bit ARM) support.
Enough for a distribution build.


# 1.77 10-Jun-2020 ad

- Wired/resident stats shouldn't covered by PMAPCOUNTERS.
- Rename need_update_pv -> need_enter_pv.

Ok ryo@


# 1.76 01-Jun-2020 ryo

no need to make the PTE writable to do icache_sync, enough to accessible.


# 1.75 15-May-2020 skrll

Use __diagused


# 1.74 15-May-2020 tnn

fix non-diag build


# 1.73 14-May-2020 skrll

Use MUTEX_NODEBUG for PV locks as is commonly done. OK ryo.


# 1.72 13-May-2020 jmcneill

Implement pmap_extract_coherency


Revision tags: bouyer-xenpvh-base2 phil-wifi-20200421 bouyer-xenpvh-base1
# 1.71 18-Apr-2020 skrll

PMAP_DEBUG has been deleted on arm


# 1.70 13-Apr-2020 maxv

Add support for Branch Target Identification (BTI).

On the executable pages that have the GP (Guarded Page) bit, the semantic
of the "br" and "blr" instructions is changed: the CPU expects the first
instruction of the jump/call target to be "bti", and faults if it isn't.

We add the GP bit on the kernel .text pages (and incidentally the .rodata
pages, but we don't care). The compiler adds a "bti c" instruction at the
beginning of each C function. We modify the ENTRY() macros to manually add
"bti c" in the asm functions.

cpuswitch.S needs a specific change: with "br x27" the CPU expects "bti j",
which is bad because the functions begin with "bti c"; switch to "br x16",
for the CPU to accept "bti c".

BTI helps defend against JOP/COP. Tested on Qemu.


Revision tags: phil-wifi-20200411 bouyer-xenpvh-base
# 1.69 08-Apr-2020 ryo

branches: 1.69.2;
use PMAP_PAGE_INIT() to initialize mutex in pmap_page.

VM_MDPAGE_INIT() in pmap_free_pdp() had initialized pp_flags,
so it unintentionally cleared PMAP_PAGE_FLAGS_PV_TRACKED.
use PMAP_PAGE_INIT to avoid using PMAP_PAGE_FLAGS_PV_TRACKED.

pointed out by tnn@, thanks


Revision tags: phil-wifi-20200406
# 1.68 14-Mar-2020 ad

pmap_remove_all(): Return a boolean value to indicate the behaviour. If
true, all mappings have been removed, the pmap is totally cleared out, and
UVM can then avoid doing the work to call pmap_remove() for each map entry.
If false, either nothing has been done, or some helpful arch-specific voodoo
has taken place.


Revision tags: is-mlppp-base
# 1.67 02-Mar-2020 ryo

oops, fix incorrect usage of daif_enable() in my previous commit.


# 1.66 29-Feb-2020 ryo

Fix pmap to work correctly with tagged addresses

- when fault, untag from address before passing to uvm/pmap functions
- pmap_extract() checks more strictly and consider the address tag


# 1.65 29-Feb-2020 ryo

use pmapboot_enter_range()


Revision tags: ad-namecache-base3
# 1.64 10-Feb-2020 ryo

use LIST(3) instead of TAILQ(3) to save one word in struct vm_page and struct pmap.

pointed out by riastradh@. thanks


# 1.63 03-Feb-2020 ryo

add support pmap_pv(9)

Patch originally from jmcneill@. thanks


# 1.62 03-Feb-2020 ryo

separate struct vm_page_md into vm_page_md and pmap_page
for preparation pmap_pv(9)


Revision tags: ad-namecache-base2 ad-namecache-base1
# 1.61 09-Jan-2020 ryo

fix behaviour mmap()/mprotect() when passed only PROT_EXEC.

when mmap()/mprotect() with only PROT_EXEC, syscall will be successful,
but the page actually hadn't been mapped.
it should be mapped with PROT_READ|PROT_EXEC implicitly. (r-x)


Revision tags: ad-namecache-base
# 1.60 30-Dec-2019 skrll

branches: 1.60.2;
Update pmap_map_chunk to allow L[12] block mappings and L3 page mappings


# 1.59 30-Dec-2019 skrll

Remove unnecessary brackets and unwrap a conditional. Same code before
and after.


# 1.58 28-Dec-2019 jmcneill

Do not use Early Write Acknowledge for PCIe I/O and config space.


# 1.57 27-Dec-2019 jmcneill

Enable early write acknowledge for device memory mappings.


# 1.56 19-Dec-2019 skrll

G/C kasan_shadow_map call in pmap_enter

pmap_growkernel calls kasan_shadow_map for KVA


# 1.55 18-Dec-2019 ryo

atomic_add_16() is not used in pmap.c anymore. no need decl here.


# 1.54 18-Dec-2019 ryo

space to tab


# 1.53 14-Dec-2019 skrll

Fix build... wire_count probably doesn't need atomics


# 1.52 13-Dec-2019 skrll

Fix KASAN support by calling kasan_shadow_map in pmap_growkernel


# 1.51 10-Dec-2019 ad

pg->phys_addr -> VM_PAGE_TO_PHYS(pg)


Revision tags: phil-wifi-20191119
# 1.50 14-Nov-2019 maxv

Mark several kASan functions with __nothing, to avoid annoying #ifdefs.
Same as kCSan and kMSan.


# 1.49 14-Nov-2019 maxv

Don't include "opt_kasan.h" when there's already <sys/asan.h> included.


# 1.48 29-Oct-2019 maya

Define PMAP_NEED_PROCWR, providing strategically placed i-cache
synchronization where just-changed memory is about to be executed.

Fixes SIGILLs seen when running Mono 6 on QEMU Cortex-A57.

ok ryo


# 1.47 22-Sep-2019 jmcneill

Disable translation table walks using TTBR0 while changing its value and
when deactivating a pmap. Fixes stability issues on Ampere eMAG CPUs.


# 1.46 20-Sep-2019 ryo

ref/mod bit should be set according to 'flags' argument, not 'prot'. r1.44 was incomplete.


# 1.45 13-Sep-2019 ryo

In pmap_devmap_bootstrap(), cpu_earlydevice_va_p() must not return true until *all* devmap tables have been enabled.
console mapping may be present in the last table.


# 1.44 07-Sep-2019 ryo

- remove incorrect KASSERT. mmap(2) with prot=PROT_WRITE calls pmap_enter(..., PROT_WRITE) internally.
- fix to update page reference flags when only PROT_WRITE or PROT_EXECUTE specified


# 1.43 15-Aug-2019 skrll

Make pmap_db_pte_print more terse so it's quicker on serial consoles


# 1.42 12-Aug-2019 skrll

Use PMAP_DEV in DEVMAP_ENTRY rather than pmap_map_chunk. It's clearer and
means pmap_map_chunk can be made to map other memory types.


Revision tags: netbsd-9-base phil-wifi-20190609
# 1.41 17-May-2019 mrg

branches: 1.41.2;
apply some __diagused.


Revision tags: isaki-audio2-base
# 1.40 08-Apr-2019 ryo

- free empty page tables pages if reach a certain usage.
- need to lock at removing an old pg (_pmap_remove_pv) in _pmap_enter()


# 1.39 06-Apr-2019 ryo

Fix race conditions about pmap_page_protect() and pmap_enter().

while handling same PTE by these functions in same time, there
is a critical path that the number of valid PTEs and wire_count
are inconsistent, and it caused KASSERT.
Need to hold a pv_lock while modifying them.


# 1.38 20-Mar-2019 ryo

spinkle __printflike(), and use PRIxxx


# 1.37 19-Mar-2019 ryo

- add ddb command "machine ttbr" to dump MMU tables.
- tidy up descriptions, usages and messages.


# 1.36 19-Mar-2019 ryo

- free L1-L3 pages that has been emptied by pmap_remove().
- if no memories, pmap_enter will return correctly ENOMEM if PMAP_CANFAIL, or wait until available any memories if !PMAP_CANFAIL.

These changes improves the stability when we use a huge virtual memory spaces with mmap.


# 1.35 06-Feb-2019 ryo

improve pmap_remove
- don't lock/unlock per page in pmap_remove()
- speedup pte lookup for continuous addresses
- bring out pool_cache_put(&_pmap_pv_pool, pv) from lock/unlock section


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226
# 1.34 21-Dec-2018 ryo

- add workaround for Cavium ThunderX errata 27456.
- add cpufuncs table in cpu_info. each cpu clusters may have different erratum. (e.g. big.LITTLE)


Revision tags: pgoyette-compat-1126
# 1.33 01-Nov-2018 maxv

Add kASan support for aarch64. Stack tracking needs more investigation
and will come in a separate commit.

Reviewed by ryo@ jmcneill@ skrll@.


# 1.32 31-Oct-2018 ryo

invalidate icache correctly.
l3pte_executable() should be used for only valid pte.


Revision tags: pgoyette-compat-1020
# 1.31 18-Oct-2018 skrll

Provide generic start code that assumes the MMU is off and caches are
disabled as per the linux booting protocol for ARMv6 and ARMv7 boards.
u-boot image type should be changed to 'linux' for correct behaviour.

The new start code builds a minimal "bootstrap" L1PT with cached access
disabled and uses the same table for all processors. AP startup is
performed in less steps and more code is written in C.

The bootstrap tables and stack are placed into an (orphaned) section
"_init_memory" which is given to uvm when it is no longer used.

Various kernels have been converted to use this code and tested. Some
boards were provided by TNF. Thanks!

The GENERIC kernel now boots on boards using the TEGRA, SUNXI and EXYNOS
kernels. The GENERIC kernel will also work on RPI2 using u-boot.

Thanks to martin@ and aymeric@ for testing on parallella and nanosoc
respectively


# 1.30 14-Oct-2018 skrll

Use __nothing


# 1.29 12-Oct-2018 ryo

add initial support of COMPAT_NETBSD32 on AArch64.
arm ELF32 EABI binaries could be execute in AArch32 state on AArch64. A32 THUMB mode is not supported yet.


# 1.28 12-Oct-2018 ryo

- cleanup checking address ranges with IN_RANGE macro
- change PM_ADDR_CHECK macro to KASSERTMSG
- restore fast lookup cases with IN_RANGE macro for pmap_extract changed in my previous commit.


# 1.27 12-Oct-2018 ryo

rewrite pmap_pte_lookup() to share similar code.


# 1.26 04-Oct-2018 ryo

cleanup locore, and changed the way to map memories during boot.
- add functions bootpage_enter() and bootpage_alloc() to adapt various layout
of physical memory map. especially for 64bit physical memory layout.
pmapboot_alloc() allocates pagetable pages from _end[].
- changed to map only the required amount for PA=VA identity mapping
(kernel image, UART device, and FDT blob) with L2_BLOCK(2Mbyte).
- changing page permission for kernel image, and making KSEG mapping are done
at cpu_kernel_vm_init() instead of at locore.
- optimize PTE entries with PTE Contiguous bit. it is enabled on devmap only for now.

reviewed by skrll@, thanks.


# 1.25 04-Oct-2018 ryo

* define LX_BLKPAG_{OS,ATTR}_* for OS dependent PTE attributes in pmap.h
* cleanup macros


Revision tags: pgoyette-compat-0930
# 1.24 17-Sep-2018 ryo

delete debug printf and KASSERT.


# 1.23 10-Sep-2018 maxv

Replace KDASSERT by panic.


# 1.22 10-Sep-2018 maxv

Rename _pmap_alloc_pdp -> pmap_alloc_pdp, and make it public.


# 1.21 10-Sep-2018 ryo

cleanup aarch64 mpstart and fdt bootstrap
* arm_cpu_hatch_arg is a bad idea. avoid serializing CPU startup, and eliminate arm_cpu_hatch_arg.
in mpstart, resolve own cpu index using array of cpu_mpidr[] (aarch64)
* add support fdt enable-method "spin-table"
* add support fdt enable-method "brcm,bcm2836-smp" (for 32bit RaspberryPi)
* use arm_fdt_cpu_bootstrap() instead of psci_fdt_bootstrap()
* rename "arm/fdt/psci_fdt.h" to "arm/fdt/psci_fdtvar.h" because of conflict of include file for needs-flag
* add devmap for cpu spin-table of raspberrypi3/aarch64
* no need to force hatch APs for raspberrypi3/arm32 ifndef MULTIPROCESSOR.
* fix to work pmap_extract(kerneltext/data/bss) even if before calling pmap_bootstrap

idea to use cpu_mpidr[] by jmcneill@. reviewd by skrll@. thanks.


Revision tags: pgoyette-compat-0906
# 1.20 27-Aug-2018 ryo

need to add VM_PROT_READ when pmap_kenter_pa(va, pa, VM_PROT_WRITE, 0) or pmap_kenter_pa(va, pa, VM_PROT_EXECUTE, 0).
VM_PROT_READ is treated as an access permission inernally.


# 1.19 11-Aug-2018 ryo

change to minimum invalidation of TLB.
specifying not only va but also asid, and not invalidate L0-L2 entry using tlbi_*_ll() if needed.


# 1.18 10-Aug-2018 ryo

treat kernel-exec attr and user-exec attr separately.
kernel cannot execute userland exec page, and user cannot execute kernel page.


# 1.17 06-Aug-2018 ryo

set kernel text/rodata readonly by default.
add function db_write_text() for setting ddb breakpoint.


# 1.16 31-Jul-2018 skrll

Define and use VPRINTF


Revision tags: pgoyette-compat-0728
# 1.15 27-Jul-2018 ryo

changes of pmap.c r1.13 seems to be unstable.
In order to invalidate icache, not to invalidate all icache,
but temporary to make the page writable and invalidate target address only.


# 1.14 24-Jul-2018 ryo

don't call pool_cache_put with locking pmap. pool_cache_put call pmap_kenter_pa internally.
(pool_cache_put_paddr -> pool_cache_put_slow -> pool_get -> pmap_kenter_pa)


# 1.13 23-Jul-2018 ryo

* fix icache invalidations.
* "ic ivau" (aarch64_icache_sync_range) with VA generates permission fault in some situations, therefore use KSEG address for now.


# 1.12 23-Jul-2018 ryo

rather than using flags to resolve nested locks, reserve pool_cache before locking.


# 1.11 21-Jul-2018 ryo

* avoid deadlock. mutex_owned() works only for adaptive lock, therefore we cannot use it for spinlock...
* add more NULL check
* clear pte when pmap_enter() fails


# 1.10 17-Jul-2018 ryo

Use __debugused


# 1.9 17-Jul-2018 christos

Add missing casts, remove unused variables.


# 1.8 09-Jul-2018 ryo

need locks in pmap_kremove() and pmap_fault_fixup()


Revision tags: phil-wifi-base pgoyette-compat-0625 pgoyette-compat-0521
# 1.7 20-May-2018 ryo

branches: 1.7.2;
pmap_enter() must update modified/referenced flags by 'flags' not 'prot'.


# 1.6 16-May-2018 ryo

Fix memory leak. it was leaking one page every pmap_create().
pm->pm_vmlist must be initialized before calling _pmap_alloc_pdp().


Revision tags: pgoyette-compat-0502
# 1.5 29-Apr-2018 ryo

fix KASSERT panic. pv_entry may not be exists in pvlist when pmap_remove().


# 1.4 29-Apr-2018 ryo

delete unused code


# 1.3 27-Apr-2018 ryo

fix instability behavior of bufcache on aarch64.
* fix to return correct ref/mod when PMAP_WIRED.
* changed to keep wired flags in pte instead of pv_entry, and cleanup.


Revision tags: pgoyette-compat-0422 pgoyette-compat-0415 pgoyette-compat-0407
# 1.2 01-Apr-2018 ryo

Add initial support for ARMv8 (AARCH64) (by nisimura@ and ryo@)

- sys/arch/evbarm64 is gone and integrated into sys/arch/evbarm. (by skrll@)
- add support fdt. evbarm/conf/GENERIC64 fdt (bcm2837,sunxi,tegra) based generic 64bit kernel config. (by skrll@, jmcneill@)


Revision tags: netbsd-8-2-RELEASE netbsd-8-1-RELEASE netbsd-8-1-RC1 netbsd-7-2-RELEASE netbsd-8-0-RELEASE netbsd-8-0-RC2 netbsd-8-0-RC1 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 netbsd-7-1-2-RELEASE pgoyette-compat-base netbsd-7-1-1-RELEASE tls-maxphys-base-20171202 matt-nb8-mediatek-base nick-nhusb-base-20170825 perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base pgoyette-localcount-20170320 netbsd-7-1-RELEASE netbsd-7-1-RC2 nick-nhusb-base-20170204 netbsd-7-nhusb-base-20170116 bouyer-socketcan-base pgoyette-localcount-20170107 netbsd-7-1-RC1 nick-nhusb-base-20161204 pgoyette-localcount-20161104 netbsd-7-0-2-RELEASE nick-nhusb-base-20161004 localcount-20160914 netbsd-7-nhusb-base pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907 nick-nhusb-base-20160529 netbsd-7-0-1-RELEASE nick-nhusb-base-20160422 nick-nhusb-base-20160319 nick-nhusb-base-20151226 netbsd-7-0-RELEASE nick-nhusb-base-20150921 netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 nick-nhusb-base-20150606 nick-nhusb-base-20150406 nick-nhusb-base tls-maxphys-base netbsd-7-base
# 1.1 10-Aug-2014 matt

branches: 1.1.4; 1.1.28;
Preliminary files for AARCH64 (64-bit ARM) support.
Enough for a distribution build.


# 1.76 01-Jun-2020 ryo

no need to make the PTE writable to do icache_sync, enough to accessible.


# 1.75 15-May-2020 skrll

Use __diagused


# 1.74 15-May-2020 tnn

fix non-diag build


# 1.73 14-May-2020 skrll

Use MUTEX_NODEBUG for PV locks as is commonly done. OK ryo.


# 1.72 13-May-2020 jmcneill

Implement pmap_extract_coherency


Revision tags: bouyer-xenpvh-base2 phil-wifi-20200421 bouyer-xenpvh-base1
# 1.71 18-Apr-2020 skrll

PMAP_DEBUG has been deleted on arm


# 1.70 13-Apr-2020 maxv

Add support for Branch Target Identification (BTI).

On the executable pages that have the GP (Guarded Page) bit, the semantic
of the "br" and "blr" instructions is changed: the CPU expects the first
instruction of the jump/call target to be "bti", and faults if it isn't.

We add the GP bit on the kernel .text pages (and incidentally the .rodata
pages, but we don't care). The compiler adds a "bti c" instruction at the
beginning of each C function. We modify the ENTRY() macros to manually add
"bti c" in the asm functions.

cpuswitch.S needs a specific change: with "br x27" the CPU expects "bti j",
which is bad because the functions begin with "bti c"; switch to "br x16",
for the CPU to accept "bti c".

BTI helps defend against JOP/COP. Tested on Qemu.


Revision tags: phil-wifi-20200411 bouyer-xenpvh-base
# 1.69 08-Apr-2020 ryo

branches: 1.69.2;
use PMAP_PAGE_INIT() to initialize mutex in pmap_page.

VM_MDPAGE_INIT() in pmap_free_pdp() had initialized pp_flags,
so it unintentionally cleared PMAP_PAGE_FLAGS_PV_TRACKED.
use PMAP_PAGE_INIT to avoid using PMAP_PAGE_FLAGS_PV_TRACKED.

pointed out by tnn@, thanks


Revision tags: phil-wifi-20200406
# 1.68 14-Mar-2020 ad

pmap_remove_all(): Return a boolean value to indicate the behaviour. If
true, all mappings have been removed, the pmap is totally cleared out, and
UVM can then avoid doing the work to call pmap_remove() for each map entry.
If false, either nothing has been done, or some helpful arch-specific voodoo
has taken place.


Revision tags: is-mlppp-base
# 1.67 02-Mar-2020 ryo

oops, fix incorrect usage of daif_enable() in my previous commit.


# 1.66 29-Feb-2020 ryo

Fix pmap to work correctly with tagged addresses

- when fault, untag from address before passing to uvm/pmap functions
- pmap_extract() checks more strictly and consider the address tag


# 1.65 29-Feb-2020 ryo

use pmapboot_enter_range()


Revision tags: ad-namecache-base3
# 1.64 10-Feb-2020 ryo

use LIST(3) instead of TAILQ(3) to save one word in struct vm_page and struct pmap.

pointed out by riastradh@. thanks


# 1.63 03-Feb-2020 ryo

add support pmap_pv(9)

Patch originally from jmcneill@. thanks


# 1.62 03-Feb-2020 ryo

separate struct vm_page_md into vm_page_md and pmap_page
for preparation pmap_pv(9)


Revision tags: ad-namecache-base2 ad-namecache-base1
# 1.61 09-Jan-2020 ryo

fix behaviour mmap()/mprotect() when passed only PROT_EXEC.

when mmap()/mprotect() with only PROT_EXEC, syscall will be successful,
but the page actually hadn't been mapped.
it should be mapped with PROT_READ|PROT_EXEC implicitly. (r-x)


Revision tags: ad-namecache-base
# 1.60 30-Dec-2019 skrll

branches: 1.60.2;
Update pmap_map_chunk to allow L[12] block mappings and L3 page mappings


# 1.59 30-Dec-2019 skrll

Remove unnecessary brackets and unwrap a conditional. Same code before
and after.


# 1.58 28-Dec-2019 jmcneill

Do not use Early Write Acknowledge for PCIe I/O and config space.


# 1.57 27-Dec-2019 jmcneill

Enable early write acknowledge for device memory mappings.


# 1.56 19-Dec-2019 skrll

G/C kasan_shadow_map call in pmap_enter

pmap_growkernel calls kasan_shadow_map for KVA


# 1.55 18-Dec-2019 ryo

atomic_add_16() is not used in pmap.c anymore. no need decl here.


# 1.54 18-Dec-2019 ryo

space to tab


# 1.53 14-Dec-2019 skrll

Fix build... wire_count probably doesn't need atomics


# 1.52 13-Dec-2019 skrll

Fix KASAN support by calling kasan_shadow_map in pmap_growkernel


# 1.51 10-Dec-2019 ad

pg->phys_addr -> VM_PAGE_TO_PHYS(pg)


Revision tags: phil-wifi-20191119
# 1.50 14-Nov-2019 maxv

Mark several kASan functions with __nothing, to avoid annoying #ifdefs.
Same as kCSan and kMSan.


# 1.49 14-Nov-2019 maxv

Don't include "opt_kasan.h" when there's already <sys/asan.h> included.


# 1.48 29-Oct-2019 maya

Define PMAP_NEED_PROCWR, providing strategically placed i-cache
synchronization where just-changed memory is about to be executed.

Fixes SIGILLs seen when running Mono 6 on QEMU Cortex-A57.

ok ryo


# 1.47 22-Sep-2019 jmcneill

Disable translation table walks using TTBR0 while changing its value and
when deactivating a pmap. Fixes stability issues on Ampere eMAG CPUs.


# 1.46 20-Sep-2019 ryo

ref/mod bit should be set according to 'flags' argument, not 'prot'. r1.44 was incomplete.


# 1.45 13-Sep-2019 ryo

In pmap_devmap_bootstrap(), cpu_earlydevice_va_p() must not return true until *all* devmap tables have been enabled.
console mapping may be present in the last table.


# 1.44 07-Sep-2019 ryo

- remove incorrect KASSERT. mmap(2) with prot=PROT_WRITE calls pmap_enter(..., PROT_WRITE) internally.
- fix to update page reference flags when only PROT_WRITE or PROT_EXECUTE specified


# 1.43 15-Aug-2019 skrll

Make pmap_db_pte_print more terse so it's quicker on serial consoles


# 1.42 12-Aug-2019 skrll

Use PMAP_DEV in DEVMAP_ENTRY rather than pmap_map_chunk. It's clearer and
means pmap_map_chunk can be made to map other memory types.


Revision tags: netbsd-9-base phil-wifi-20190609
# 1.41 17-May-2019 mrg

branches: 1.41.2;
apply some __diagused.


Revision tags: isaki-audio2-base
# 1.40 08-Apr-2019 ryo

- free empty page tables pages if reach a certain usage.
- need to lock at removing an old pg (_pmap_remove_pv) in _pmap_enter()


# 1.39 06-Apr-2019 ryo

Fix race conditions about pmap_page_protect() and pmap_enter().

while handling same PTE by these functions in same time, there
is a critical path that the number of valid PTEs and wire_count
are inconsistent, and it caused KASSERT.
Need to hold a pv_lock while modifying them.


# 1.38 20-Mar-2019 ryo

spinkle __printflike(), and use PRIxxx


# 1.37 19-Mar-2019 ryo

- add ddb command "machine ttbr" to dump MMU tables.
- tidy up descriptions, usages and messages.


# 1.36 19-Mar-2019 ryo

- free L1-L3 pages that has been emptied by pmap_remove().
- if no memories, pmap_enter will return correctly ENOMEM if PMAP_CANFAIL, or wait until available any memories if !PMAP_CANFAIL.

These changes improves the stability when we use a huge virtual memory spaces with mmap.


# 1.35 06-Feb-2019 ryo

improve pmap_remove
- don't lock/unlock per page in pmap_remove()
- speedup pte lookup for continuous addresses
- bring out pool_cache_put(&_pmap_pv_pool, pv) from lock/unlock section


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226
# 1.34 21-Dec-2018 ryo

- add workaround for Cavium ThunderX errata 27456.
- add cpufuncs table in cpu_info. each cpu clusters may have different erratum. (e.g. big.LITTLE)


Revision tags: pgoyette-compat-1126
# 1.33 01-Nov-2018 maxv

Add kASan support for aarch64. Stack tracking needs more investigation
and will come in a separate commit.

Reviewed by ryo@ jmcneill@ skrll@.


# 1.32 31-Oct-2018 ryo

invalidate icache correctly.
l3pte_executable() should be used for only valid pte.


Revision tags: pgoyette-compat-1020
# 1.31 18-Oct-2018 skrll

Provide generic start code that assumes the MMU is off and caches are
disabled as per the linux booting protocol for ARMv6 and ARMv7 boards.
u-boot image type should be changed to 'linux' for correct behaviour.

The new start code builds a minimal "bootstrap" L1PT with cached access
disabled and uses the same table for all processors. AP startup is
performed in less steps and more code is written in C.

The bootstrap tables and stack are placed into an (orphaned) section
"_init_memory" which is given to uvm when it is no longer used.

Various kernels have been converted to use this code and tested. Some
boards were provided by TNF. Thanks!

The GENERIC kernel now boots on boards using the TEGRA, SUNXI and EXYNOS
kernels. The GENERIC kernel will also work on RPI2 using u-boot.

Thanks to martin@ and aymeric@ for testing on parallella and nanosoc
respectively


# 1.30 14-Oct-2018 skrll

Use __nothing


# 1.29 12-Oct-2018 ryo

add initial support of COMPAT_NETBSD32 on AArch64.
arm ELF32 EABI binaries could be execute in AArch32 state on AArch64. A32 THUMB mode is not supported yet.


# 1.28 12-Oct-2018 ryo

- cleanup checking address ranges with IN_RANGE macro
- change PM_ADDR_CHECK macro to KASSERTMSG
- restore fast lookup cases with IN_RANGE macro for pmap_extract changed in my previous commit.


# 1.27 12-Oct-2018 ryo

rewrite pmap_pte_lookup() to share similar code.


# 1.26 04-Oct-2018 ryo

cleanup locore, and changed the way to map memories during boot.
- add functions bootpage_enter() and bootpage_alloc() to adapt various layout
of physical memory map. especially for 64bit physical memory layout.
pmapboot_alloc() allocates pagetable pages from _end[].
- changed to map only the required amount for PA=VA identity mapping
(kernel image, UART device, and FDT blob) with L2_BLOCK(2Mbyte).
- changing page permission for kernel image, and making KSEG mapping are done
at cpu_kernel_vm_init() instead of at locore.
- optimize PTE entries with PTE Contiguous bit. it is enabled on devmap only for now.

reviewed by skrll@, thanks.


# 1.25 04-Oct-2018 ryo

* define LX_BLKPAG_{OS,ATTR}_* for OS dependent PTE attributes in pmap.h
* cleanup macros


Revision tags: pgoyette-compat-0930
# 1.24 17-Sep-2018 ryo

delete debug printf and KASSERT.


# 1.23 10-Sep-2018 maxv

Replace KDASSERT by panic.


# 1.22 10-Sep-2018 maxv

Rename _pmap_alloc_pdp -> pmap_alloc_pdp, and make it public.


# 1.21 10-Sep-2018 ryo

cleanup aarch64 mpstart and fdt bootstrap
* arm_cpu_hatch_arg is a bad idea. avoid serializing CPU startup, and eliminate arm_cpu_hatch_arg.
in mpstart, resolve own cpu index using array of cpu_mpidr[] (aarch64)
* add support fdt enable-method "spin-table"
* add support fdt enable-method "brcm,bcm2836-smp" (for 32bit RaspberryPi)
* use arm_fdt_cpu_bootstrap() instead of psci_fdt_bootstrap()
* rename "arm/fdt/psci_fdt.h" to "arm/fdt/psci_fdtvar.h" because of conflict of include file for needs-flag
* add devmap for cpu spin-table of raspberrypi3/aarch64
* no need to force hatch APs for raspberrypi3/arm32 ifndef MULTIPROCESSOR.
* fix to work pmap_extract(kerneltext/data/bss) even if before calling pmap_bootstrap

idea to use cpu_mpidr[] by jmcneill@. reviewd by skrll@. thanks.


Revision tags: pgoyette-compat-0906
# 1.20 27-Aug-2018 ryo

need to add VM_PROT_READ when pmap_kenter_pa(va, pa, VM_PROT_WRITE, 0) or pmap_kenter_pa(va, pa, VM_PROT_EXECUTE, 0).
VM_PROT_READ is treated as an access permission inernally.


# 1.19 11-Aug-2018 ryo

change to minimum invalidation of TLB.
specifying not only va but also asid, and not invalidate L0-L2 entry using tlbi_*_ll() if needed.


# 1.18 10-Aug-2018 ryo

treat kernel-exec attr and user-exec attr separately.
kernel cannot execute userland exec page, and user cannot execute kernel page.


# 1.17 06-Aug-2018 ryo

set kernel text/rodata readonly by default.
add function db_write_text() for setting ddb breakpoint.


# 1.16 31-Jul-2018 skrll

Define and use VPRINTF


Revision tags: pgoyette-compat-0728
# 1.15 27-Jul-2018 ryo

changes of pmap.c r1.13 seems to be unstable.
In order to invalidate icache, not to invalidate all icache,
but temporary to make the page writable and invalidate target address only.


# 1.14 24-Jul-2018 ryo

don't call pool_cache_put with locking pmap. pool_cache_put call pmap_kenter_pa internally.
(pool_cache_put_paddr -> pool_cache_put_slow -> pool_get -> pmap_kenter_pa)


# 1.13 23-Jul-2018 ryo

* fix icache invalidations.
* "ic ivau" (aarch64_icache_sync_range) with VA generates permission fault in some situations, therefore use KSEG address for now.


# 1.12 23-Jul-2018 ryo

rather than using flags to resolve nested locks, reserve pool_cache before locking.


# 1.11 21-Jul-2018 ryo

* avoid deadlock. mutex_owned() works only for adaptive lock, therefore we cannot use it for spinlock...
* add more NULL check
* clear pte when pmap_enter() fails


# 1.10 17-Jul-2018 ryo

Use __debugused


# 1.9 17-Jul-2018 christos

Add missing casts, remove unused variables.


# 1.8 09-Jul-2018 ryo

need locks in pmap_kremove() and pmap_fault_fixup()


Revision tags: phil-wifi-base pgoyette-compat-0625 pgoyette-compat-0521
# 1.7 20-May-2018 ryo

branches: 1.7.2;
pmap_enter() must update modified/referenced flags by 'flags' not 'prot'.


# 1.6 16-May-2018 ryo

Fix memory leak. it was leaking one page every pmap_create().
pm->pm_vmlist must be initialized before calling _pmap_alloc_pdp().


Revision tags: pgoyette-compat-0502
# 1.5 29-Apr-2018 ryo

fix KASSERT panic. pv_entry may not be exists in pvlist when pmap_remove().


# 1.4 29-Apr-2018 ryo

delete unused code


# 1.3 27-Apr-2018 ryo

fix instability behavior of bufcache on aarch64.
* fix to return correct ref/mod when PMAP_WIRED.
* changed to keep wired flags in pte instead of pv_entry, and cleanup.


Revision tags: pgoyette-compat-0422 pgoyette-compat-0415 pgoyette-compat-0407
# 1.2 01-Apr-2018 ryo

Add initial support for ARMv8 (AARCH64) (by nisimura@ and ryo@)

- sys/arch/evbarm64 is gone and integrated into sys/arch/evbarm. (by skrll@)
- add support fdt. evbarm/conf/GENERIC64 fdt (bcm2837,sunxi,tegra) based generic 64bit kernel config. (by skrll@, jmcneill@)


Revision tags: netbsd-8-2-RELEASE netbsd-8-1-RELEASE netbsd-8-1-RC1 netbsd-7-2-RELEASE netbsd-8-0-RELEASE netbsd-8-0-RC2 netbsd-8-0-RC1 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 netbsd-7-1-2-RELEASE pgoyette-compat-base netbsd-7-1-1-RELEASE tls-maxphys-base-20171202 matt-nb8-mediatek-base nick-nhusb-base-20170825 perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base pgoyette-localcount-20170320 netbsd-7-1-RELEASE netbsd-7-1-RC2 nick-nhusb-base-20170204 netbsd-7-nhusb-base-20170116 bouyer-socketcan-base pgoyette-localcount-20170107 netbsd-7-1-RC1 nick-nhusb-base-20161204 pgoyette-localcount-20161104 netbsd-7-0-2-RELEASE nick-nhusb-base-20161004 localcount-20160914 netbsd-7-nhusb-base pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907 nick-nhusb-base-20160529 netbsd-7-0-1-RELEASE nick-nhusb-base-20160422 nick-nhusb-base-20160319 nick-nhusb-base-20151226 netbsd-7-0-RELEASE nick-nhusb-base-20150921 netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 nick-nhusb-base-20150606 nick-nhusb-base-20150406 nick-nhusb-base tls-maxphys-base netbsd-7-base
# 1.1 10-Aug-2014 matt

branches: 1.1.4; 1.1.28;
Preliminary files for AARCH64 (64-bit ARM) support.
Enough for a distribution build.


# 1.75 15-May-2020 skrll

Use __diagused


# 1.74 15-May-2020 tnn

fix non-diag build


# 1.73 14-May-2020 skrll

Use MUTEX_NODEBUG for PV locks as is commonly done. OK ryo.


# 1.72 13-May-2020 jmcneill

Implement pmap_extract_coherency


Revision tags: bouyer-xenpvh-base2 phil-wifi-20200421 bouyer-xenpvh-base1
# 1.71 18-Apr-2020 skrll

PMAP_DEBUG has been deleted on arm


# 1.70 13-Apr-2020 maxv

Add support for Branch Target Identification (BTI).

On the executable pages that have the GP (Guarded Page) bit, the semantic
of the "br" and "blr" instructions is changed: the CPU expects the first
instruction of the jump/call target to be "bti", and faults if it isn't.

We add the GP bit on the kernel .text pages (and incidentally the .rodata
pages, but we don't care). The compiler adds a "bti c" instruction at the
beginning of each C function. We modify the ENTRY() macros to manually add
"bti c" in the asm functions.

cpuswitch.S needs a specific change: with "br x27" the CPU expects "bti j",
which is bad because the functions begin with "bti c"; switch to "br x16",
for the CPU to accept "bti c".

BTI helps defend against JOP/COP. Tested on Qemu.


Revision tags: phil-wifi-20200411 bouyer-xenpvh-base
# 1.69 08-Apr-2020 ryo

branches: 1.69.2;
use PMAP_PAGE_INIT() to initialize mutex in pmap_page.

VM_MDPAGE_INIT() in pmap_free_pdp() had initialized pp_flags,
so it unintentionally cleared PMAP_PAGE_FLAGS_PV_TRACKED.
use PMAP_PAGE_INIT to avoid using PMAP_PAGE_FLAGS_PV_TRACKED.

pointed out by tnn@, thanks


Revision tags: phil-wifi-20200406
# 1.68 14-Mar-2020 ad

pmap_remove_all(): Return a boolean value to indicate the behaviour. If
true, all mappings have been removed, the pmap is totally cleared out, and
UVM can then avoid doing the work to call pmap_remove() for each map entry.
If false, either nothing has been done, or some helpful arch-specific voodoo
has taken place.


Revision tags: is-mlppp-base
# 1.67 02-Mar-2020 ryo

oops, fix incorrect usage of daif_enable() in my previous commit.


# 1.66 29-Feb-2020 ryo

Fix pmap to work correctly with tagged addresses

- when fault, untag from address before passing to uvm/pmap functions
- pmap_extract() checks more strictly and consider the address tag


# 1.65 29-Feb-2020 ryo

use pmapboot_enter_range()


Revision tags: ad-namecache-base3
# 1.64 10-Feb-2020 ryo

use LIST(3) instead of TAILQ(3) to save one word in struct vm_page and struct pmap.

pointed out by riastradh@. thanks


# 1.63 03-Feb-2020 ryo

add support pmap_pv(9)

Patch originally from jmcneill@. thanks


# 1.62 03-Feb-2020 ryo

separate struct vm_page_md into vm_page_md and pmap_page
for preparation pmap_pv(9)


Revision tags: ad-namecache-base2 ad-namecache-base1
# 1.61 09-Jan-2020 ryo

fix behaviour mmap()/mprotect() when passed only PROT_EXEC.

when mmap()/mprotect() with only PROT_EXEC, syscall will be successful,
but the page actually hadn't been mapped.
it should be mapped with PROT_READ|PROT_EXEC implicitly. (r-x)


Revision tags: ad-namecache-base
# 1.60 30-Dec-2019 skrll

branches: 1.60.2;
Update pmap_map_chunk to allow L[12] block mappings and L3 page mappings


# 1.59 30-Dec-2019 skrll

Remove unnecessary brackets and unwrap a conditional. Same code before
and after.


# 1.58 28-Dec-2019 jmcneill

Do not use Early Write Acknowledge for PCIe I/O and config space.


# 1.57 27-Dec-2019 jmcneill

Enable early write acknowledge for device memory mappings.


# 1.56 19-Dec-2019 skrll

G/C kasan_shadow_map call in pmap_enter

pmap_growkernel calls kasan_shadow_map for KVA


# 1.55 18-Dec-2019 ryo

atomic_add_16() is not used in pmap.c anymore. no need decl here.


# 1.54 18-Dec-2019 ryo

space to tab


# 1.53 14-Dec-2019 skrll

Fix build... wire_count probably doesn't need atomics


# 1.52 13-Dec-2019 skrll

Fix KASAN support by calling kasan_shadow_map in pmap_growkernel


# 1.51 10-Dec-2019 ad

pg->phys_addr -> VM_PAGE_TO_PHYS(pg)


Revision tags: phil-wifi-20191119
# 1.50 14-Nov-2019 maxv

Mark several kASan functions with __nothing, to avoid annoying #ifdefs.
Same as kCSan and kMSan.


# 1.49 14-Nov-2019 maxv

Don't include "opt_kasan.h" when there's already <sys/asan.h> included.


# 1.48 29-Oct-2019 maya

Define PMAP_NEED_PROCWR, providing strategically placed i-cache
synchronization where just-changed memory is about to be executed.

Fixes SIGILLs seen when running Mono 6 on QEMU Cortex-A57.

ok ryo


# 1.47 22-Sep-2019 jmcneill

Disable translation table walks using TTBR0 while changing its value and
when deactivating a pmap. Fixes stability issues on Ampere eMAG CPUs.


# 1.46 20-Sep-2019 ryo

ref/mod bit should be set according to 'flags' argument, not 'prot'. r1.44 was incomplete.


# 1.45 13-Sep-2019 ryo

In pmap_devmap_bootstrap(), cpu_earlydevice_va_p() must not return true until *all* devmap tables have been enabled.
console mapping may be present in the last table.


# 1.44 07-Sep-2019 ryo

- remove incorrect KASSERT. mmap(2) with prot=PROT_WRITE calls pmap_enter(..., PROT_WRITE) internally.
- fix to update page reference flags when only PROT_WRITE or PROT_EXECUTE specified


# 1.43 15-Aug-2019 skrll

Make pmap_db_pte_print more terse so it's quicker on serial consoles


# 1.42 12-Aug-2019 skrll

Use PMAP_DEV in DEVMAP_ENTRY rather than pmap_map_chunk. It's clearer and
means pmap_map_chunk can be made to map other memory types.


Revision tags: netbsd-9-base phil-wifi-20190609
# 1.41 17-May-2019 mrg

branches: 1.41.2;
apply some __diagused.


Revision tags: isaki-audio2-base
# 1.40 08-Apr-2019 ryo

- free empty page tables pages if reach a certain usage.
- need to lock at removing an old pg (_pmap_remove_pv) in _pmap_enter()


# 1.39 06-Apr-2019 ryo

Fix race conditions about pmap_page_protect() and pmap_enter().

while handling same PTE by these functions in same time, there
is a critical path that the number of valid PTEs and wire_count
are inconsistent, and it caused KASSERT.
Need to hold a pv_lock while modifying them.


# 1.38 20-Mar-2019 ryo

spinkle __printflike(), and use PRIxxx


# 1.37 19-Mar-2019 ryo

- add ddb command "machine ttbr" to dump MMU tables.
- tidy up descriptions, usages and messages.


# 1.36 19-Mar-2019 ryo

- free L1-L3 pages that has been emptied by pmap_remove().
- if no memories, pmap_enter will return correctly ENOMEM if PMAP_CANFAIL, or wait until available any memories if !PMAP_CANFAIL.

These changes improves the stability when we use a huge virtual memory spaces with mmap.


# 1.35 06-Feb-2019 ryo

improve pmap_remove
- don't lock/unlock per page in pmap_remove()
- speedup pte lookup for continuous addresses
- bring out pool_cache_put(&_pmap_pv_pool, pv) from lock/unlock section


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226
# 1.34 21-Dec-2018 ryo

- add workaround for Cavium ThunderX errata 27456.
- add cpufuncs table in cpu_info. each cpu clusters may have different erratum. (e.g. big.LITTLE)


Revision tags: pgoyette-compat-1126
# 1.33 01-Nov-2018 maxv

Add kASan support for aarch64. Stack tracking needs more investigation
and will come in a separate commit.

Reviewed by ryo@ jmcneill@ skrll@.


# 1.32 31-Oct-2018 ryo

invalidate icache correctly.
l3pte_executable() should be used for only valid pte.


Revision tags: pgoyette-compat-1020
# 1.31 18-Oct-2018 skrll

Provide generic start code that assumes the MMU is off and caches are
disabled as per the linux booting protocol for ARMv6 and ARMv7 boards.
u-boot image type should be changed to 'linux' for correct behaviour.

The new start code builds a minimal "bootstrap" L1PT with cached access
disabled and uses the same table for all processors. AP startup is
performed in less steps and more code is written in C.

The bootstrap tables and stack are placed into an (orphaned) section
"_init_memory" which is given to uvm when it is no longer used.

Various kernels have been converted to use this code and tested. Some
boards were provided by TNF. Thanks!

The GENERIC kernel now boots on boards using the TEGRA, SUNXI and EXYNOS
kernels. The GENERIC kernel will also work on RPI2 using u-boot.

Thanks to martin@ and aymeric@ for testing on parallella and nanosoc
respectively


# 1.30 14-Oct-2018 skrll

Use __nothing


# 1.29 12-Oct-2018 ryo

add initial support of COMPAT_NETBSD32 on AArch64.
arm ELF32 EABI binaries could be execute in AArch32 state on AArch64. A32 THUMB mode is not supported yet.


# 1.28 12-Oct-2018 ryo

- cleanup checking address ranges with IN_RANGE macro
- change PM_ADDR_CHECK macro to KASSERTMSG
- restore fast lookup cases with IN_RANGE macro for pmap_extract changed in my previous commit.


# 1.27 12-Oct-2018 ryo

rewrite pmap_pte_lookup() to share similar code.


# 1.26 04-Oct-2018 ryo

cleanup locore, and changed the way to map memories during boot.
- add functions bootpage_enter() and bootpage_alloc() to adapt various layout
of physical memory map. especially for 64bit physical memory layout.
pmapboot_alloc() allocates pagetable pages from _end[].
- changed to map only the required amount for PA=VA identity mapping
(kernel image, UART device, and FDT blob) with L2_BLOCK(2Mbyte).
- changing page permission for kernel image, and making KSEG mapping are done
at cpu_kernel_vm_init() instead of at locore.
- optimize PTE entries with PTE Contiguous bit. it is enabled on devmap only for now.

reviewed by skrll@, thanks.


# 1.25 04-Oct-2018 ryo

* define LX_BLKPAG_{OS,ATTR}_* for OS dependent PTE attributes in pmap.h
* cleanup macros


Revision tags: pgoyette-compat-0930
# 1.24 17-Sep-2018 ryo

delete debug printf and KASSERT.


# 1.23 10-Sep-2018 maxv

Replace KDASSERT by panic.


# 1.22 10-Sep-2018 maxv

Rename _pmap_alloc_pdp -> pmap_alloc_pdp, and make it public.


# 1.21 10-Sep-2018 ryo

cleanup aarch64 mpstart and fdt bootstrap
* arm_cpu_hatch_arg is a bad idea. avoid serializing CPU startup, and eliminate arm_cpu_hatch_arg.
in mpstart, resolve own cpu index using array of cpu_mpidr[] (aarch64)
* add support fdt enable-method "spin-table"
* add support fdt enable-method "brcm,bcm2836-smp" (for 32bit RaspberryPi)
* use arm_fdt_cpu_bootstrap() instead of psci_fdt_bootstrap()
* rename "arm/fdt/psci_fdt.h" to "arm/fdt/psci_fdtvar.h" because of conflict of include file for needs-flag
* add devmap for cpu spin-table of raspberrypi3/aarch64
* no need to force hatch APs for raspberrypi3/arm32 ifndef MULTIPROCESSOR.
* fix to work pmap_extract(kerneltext/data/bss) even if before calling pmap_bootstrap

idea to use cpu_mpidr[] by jmcneill@. reviewd by skrll@. thanks.


Revision tags: pgoyette-compat-0906
# 1.20 27-Aug-2018 ryo

need to add VM_PROT_READ when pmap_kenter_pa(va, pa, VM_PROT_WRITE, 0) or pmap_kenter_pa(va, pa, VM_PROT_EXECUTE, 0).
VM_PROT_READ is treated as an access permission inernally.


# 1.19 11-Aug-2018 ryo

change to minimum invalidation of TLB.
specifying not only va but also asid, and not invalidate L0-L2 entry using tlbi_*_ll() if needed.


# 1.18 10-Aug-2018 ryo

treat kernel-exec attr and user-exec attr separately.
kernel cannot execute userland exec page, and user cannot execute kernel page.


# 1.17 06-Aug-2018 ryo

set kernel text/rodata readonly by default.
add function db_write_text() for setting ddb breakpoint.


# 1.16 31-Jul-2018 skrll

Define and use VPRINTF


Revision tags: pgoyette-compat-0728
# 1.15 27-Jul-2018 ryo

changes of pmap.c r1.13 seems to be unstable.
In order to invalidate icache, not to invalidate all icache,
but temporary to make the page writable and invalidate target address only.


# 1.14 24-Jul-2018 ryo

don't call pool_cache_put with locking pmap. pool_cache_put call pmap_kenter_pa internally.
(pool_cache_put_paddr -> pool_cache_put_slow -> pool_get -> pmap_kenter_pa)


# 1.13 23-Jul-2018 ryo

* fix icache invalidations.
* "ic ivau" (aarch64_icache_sync_range) with VA generates permission fault in some situations, therefore use KSEG address for now.


# 1.12 23-Jul-2018 ryo

rather than using flags to resolve nested locks, reserve pool_cache before locking.


# 1.11 21-Jul-2018 ryo

* avoid deadlock. mutex_owned() works only for adaptive lock, therefore we cannot use it for spinlock...
* add more NULL check
* clear pte when pmap_enter() fails


# 1.10 17-Jul-2018 ryo

Use __debugused


# 1.9 17-Jul-2018 christos

Add missing casts, remove unused variables.


# 1.8 09-Jul-2018 ryo

need locks in pmap_kremove() and pmap_fault_fixup()


Revision tags: phil-wifi-base pgoyette-compat-0625 pgoyette-compat-0521
# 1.7 20-May-2018 ryo

branches: 1.7.2;
pmap_enter() must update modified/referenced flags by 'flags' not 'prot'.


# 1.6 16-May-2018 ryo

Fix memory leak. it was leaking one page every pmap_create().
pm->pm_vmlist must be initialized before calling _pmap_alloc_pdp().


Revision tags: pgoyette-compat-0502
# 1.5 29-Apr-2018 ryo

fix KASSERT panic. pv_entry may not be exists in pvlist when pmap_remove().


# 1.4 29-Apr-2018 ryo

delete unused code


# 1.3 27-Apr-2018 ryo

fix instability behavior of bufcache on aarch64.
* fix to return correct ref/mod when PMAP_WIRED.
* changed to keep wired flags in pte instead of pv_entry, and cleanup.


Revision tags: pgoyette-compat-0422 pgoyette-compat-0415 pgoyette-compat-0407
# 1.2 01-Apr-2018 ryo

Add initial support for ARMv8 (AARCH64) (by nisimura@ and ryo@)

- sys/arch/evbarm64 is gone and integrated into sys/arch/evbarm. (by skrll@)
- add support fdt. evbarm/conf/GENERIC64 fdt (bcm2837,sunxi,tegra) based generic 64bit kernel config. (by skrll@, jmcneill@)


Revision tags: netbsd-8-2-RELEASE netbsd-8-1-RELEASE netbsd-8-1-RC1 netbsd-7-2-RELEASE netbsd-8-0-RELEASE netbsd-8-0-RC2 netbsd-8-0-RC1 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 netbsd-7-1-2-RELEASE pgoyette-compat-base netbsd-7-1-1-RELEASE tls-maxphys-base-20171202 matt-nb8-mediatek-base nick-nhusb-base-20170825 perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base pgoyette-localcount-20170320 netbsd-7-1-RELEASE netbsd-7-1-RC2 nick-nhusb-base-20170204 netbsd-7-nhusb-base-20170116 bouyer-socketcan-base pgoyette-localcount-20170107 netbsd-7-1-RC1 nick-nhusb-base-20161204 pgoyette-localcount-20161104 netbsd-7-0-2-RELEASE nick-nhusb-base-20161004 localcount-20160914 netbsd-7-nhusb-base pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907 nick-nhusb-base-20160529 netbsd-7-0-1-RELEASE nick-nhusb-base-20160422 nick-nhusb-base-20160319 nick-nhusb-base-20151226 netbsd-7-0-RELEASE nick-nhusb-base-20150921 netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 nick-nhusb-base-20150606 nick-nhusb-base-20150406 nick-nhusb-base tls-maxphys-base netbsd-7-base
# 1.1 10-Aug-2014 matt

branches: 1.1.4; 1.1.28;
Preliminary files for AARCH64 (64-bit ARM) support.
Enough for a distribution build.


# 1.73 14-May-2020 skrll

Use MUTEX_NODEBUG for PV locks as is commonly done. OK ryo.


# 1.72 13-May-2020 jmcneill

Implement pmap_extract_coherency


Revision tags: bouyer-xenpvh-base2 phil-wifi-20200421 bouyer-xenpvh-base1
# 1.71 18-Apr-2020 skrll

PMAP_DEBUG has been deleted on arm


# 1.70 13-Apr-2020 maxv

Add support for Branch Target Identification (BTI).

On the executable pages that have the GP (Guarded Page) bit, the semantic
of the "br" and "blr" instructions is changed: the CPU expects the first
instruction of the jump/call target to be "bti", and faults if it isn't.

We add the GP bit on the kernel .text pages (and incidentally the .rodata
pages, but we don't care). The compiler adds a "bti c" instruction at the
beginning of each C function. We modify the ENTRY() macros to manually add
"bti c" in the asm functions.

cpuswitch.S needs a specific change: with "br x27" the CPU expects "bti j",
which is bad because the functions begin with "bti c"; switch to "br x16",
for the CPU to accept "bti c".

BTI helps defend against JOP/COP. Tested on Qemu.


Revision tags: phil-wifi-20200411 bouyer-xenpvh-base
# 1.69 08-Apr-2020 ryo

branches: 1.69.2;
use PMAP_PAGE_INIT() to initialize mutex in pmap_page.

VM_MDPAGE_INIT() in pmap_free_pdp() had initialized pp_flags,
so it unintentionally cleared PMAP_PAGE_FLAGS_PV_TRACKED.
use PMAP_PAGE_INIT to avoid using PMAP_PAGE_FLAGS_PV_TRACKED.

pointed out by tnn@, thanks


Revision tags: phil-wifi-20200406
# 1.68 14-Mar-2020 ad

pmap_remove_all(): Return a boolean value to indicate the behaviour. If
true, all mappings have been removed, the pmap is totally cleared out, and
UVM can then avoid doing the work to call pmap_remove() for each map entry.
If false, either nothing has been done, or some helpful arch-specific voodoo
has taken place.


Revision tags: is-mlppp-base
# 1.67 02-Mar-2020 ryo

oops, fix incorrect usage of daif_enable() in my previous commit.


# 1.66 29-Feb-2020 ryo

Fix pmap to work correctly with tagged addresses

- when fault, untag from address before passing to uvm/pmap functions
- pmap_extract() checks more strictly and consider the address tag


# 1.65 29-Feb-2020 ryo

use pmapboot_enter_range()


Revision tags: ad-namecache-base3
# 1.64 10-Feb-2020 ryo

use LIST(3) instead of TAILQ(3) to save one word in struct vm_page and struct pmap.

pointed out by riastradh@. thanks


# 1.63 03-Feb-2020 ryo

add support pmap_pv(9)

Patch originally from jmcneill@. thanks


# 1.62 03-Feb-2020 ryo

separate struct vm_page_md into vm_page_md and pmap_page
for preparation pmap_pv(9)


Revision tags: ad-namecache-base2 ad-namecache-base1
# 1.61 09-Jan-2020 ryo

fix behaviour mmap()/mprotect() when passed only PROT_EXEC.

when mmap()/mprotect() with only PROT_EXEC, syscall will be successful,
but the page actually hadn't been mapped.
it should be mapped with PROT_READ|PROT_EXEC implicitly. (r-x)


Revision tags: ad-namecache-base
# 1.60 30-Dec-2019 skrll

branches: 1.60.2;
Update pmap_map_chunk to allow L[12] block mappings and L3 page mappings


# 1.59 30-Dec-2019 skrll

Remove unnecessary brackets and unwrap a conditional. Same code before
and after.


# 1.58 28-Dec-2019 jmcneill

Do not use Early Write Acknowledge for PCIe I/O and config space.


# 1.57 27-Dec-2019 jmcneill

Enable early write acknowledge for device memory mappings.


# 1.56 19-Dec-2019 skrll

G/C kasan_shadow_map call in pmap_enter

pmap_growkernel calls kasan_shadow_map for KVA


# 1.55 18-Dec-2019 ryo

atomic_add_16() is not used in pmap.c anymore. no need decl here.


# 1.54 18-Dec-2019 ryo

space to tab


# 1.53 14-Dec-2019 skrll

Fix build... wire_count probably doesn't need atomics


# 1.52 13-Dec-2019 skrll

Fix KASAN support by calling kasan_shadow_map in pmap_growkernel


# 1.51 10-Dec-2019 ad

pg->phys_addr -> VM_PAGE_TO_PHYS(pg)


Revision tags: phil-wifi-20191119
# 1.50 14-Nov-2019 maxv

Mark several kASan functions with __nothing, to avoid annoying #ifdefs.
Same as kCSan and kMSan.


# 1.49 14-Nov-2019 maxv

Don't include "opt_kasan.h" when there's already <sys/asan.h> included.


# 1.48 29-Oct-2019 maya

Define PMAP_NEED_PROCWR, providing strategically placed i-cache
synchronization where just-changed memory is about to be executed.

Fixes SIGILLs seen when running Mono 6 on QEMU Cortex-A57.

ok ryo


# 1.47 22-Sep-2019 jmcneill

Disable translation table walks using TTBR0 while changing its value and
when deactivating a pmap. Fixes stability issues on Ampere eMAG CPUs.


# 1.46 20-Sep-2019 ryo

ref/mod bit should be set according to 'flags' argument, not 'prot'. r1.44 was incomplete.


# 1.45 13-Sep-2019 ryo

In pmap_devmap_bootstrap(), cpu_earlydevice_va_p() must not return true until *all* devmap tables have been enabled.
console mapping may be present in the last table.


# 1.44 07-Sep-2019 ryo

- remove incorrect KASSERT. mmap(2) with prot=PROT_WRITE calls pmap_enter(..., PROT_WRITE) internally.
- fix to update page reference flags when only PROT_WRITE or PROT_EXECUTE specified


# 1.43 15-Aug-2019 skrll

Make pmap_db_pte_print more terse so it's quicker on serial consoles


# 1.42 12-Aug-2019 skrll

Use PMAP_DEV in DEVMAP_ENTRY rather than pmap_map_chunk. It's clearer and
means pmap_map_chunk can be made to map other memory types.


Revision tags: netbsd-9-base phil-wifi-20190609
# 1.41 17-May-2019 mrg

branches: 1.41.2;
apply some __diagused.


Revision tags: isaki-audio2-base
# 1.40 08-Apr-2019 ryo

- free empty page tables pages if reach a certain usage.
- need to lock at removing an old pg (_pmap_remove_pv) in _pmap_enter()


# 1.39 06-Apr-2019 ryo

Fix race conditions about pmap_page_protect() and pmap_enter().

while handling same PTE by these functions in same time, there
is a critical path that the number of valid PTEs and wire_count
are inconsistent, and it caused KASSERT.
Need to hold a pv_lock while modifying them.


# 1.38 20-Mar-2019 ryo

spinkle __printflike(), and use PRIxxx


# 1.37 19-Mar-2019 ryo

- add ddb command "machine ttbr" to dump MMU tables.
- tidy up descriptions, usages and messages.


# 1.36 19-Mar-2019 ryo

- free L1-L3 pages that has been emptied by pmap_remove().
- if no memories, pmap_enter will return correctly ENOMEM if PMAP_CANFAIL, or wait until available any memories if !PMAP_CANFAIL.

These changes improves the stability when we use a huge virtual memory spaces with mmap.


# 1.35 06-Feb-2019 ryo

improve pmap_remove
- don't lock/unlock per page in pmap_remove()
- speedup pte lookup for continuous addresses
- bring out pool_cache_put(&_pmap_pv_pool, pv) from lock/unlock section


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226
# 1.34 21-Dec-2018 ryo

- add workaround for Cavium ThunderX errata 27456.
- add cpufuncs table in cpu_info. each cpu clusters may have different erratum. (e.g. big.LITTLE)


Revision tags: pgoyette-compat-1126
# 1.33 01-Nov-2018 maxv

Add kASan support for aarch64. Stack tracking needs more investigation
and will come in a separate commit.

Reviewed by ryo@ jmcneill@ skrll@.


# 1.32 31-Oct-2018 ryo

invalidate icache correctly.
l3pte_executable() should be used for only valid pte.


Revision tags: pgoyette-compat-1020
# 1.31 18-Oct-2018 skrll

Provide generic start code that assumes the MMU is off and caches are
disabled as per the linux booting protocol for ARMv6 and ARMv7 boards.
u-boot image type should be changed to 'linux' for correct behaviour.

The new start code builds a minimal "bootstrap" L1PT with cached access
disabled and uses the same table for all processors. AP startup is
performed in less steps and more code is written in C.

The bootstrap tables and stack are placed into an (orphaned) section
"_init_memory" which is given to uvm when it is no longer used.

Various kernels have been converted to use this code and tested. Some
boards were provided by TNF. Thanks!

The GENERIC kernel now boots on boards using the TEGRA, SUNXI and EXYNOS
kernels. The GENERIC kernel will also work on RPI2 using u-boot.

Thanks to martin@ and aymeric@ for testing on parallella and nanosoc
respectively


# 1.30 14-Oct-2018 skrll

Use __nothing


# 1.29 12-Oct-2018 ryo

add initial support of COMPAT_NETBSD32 on AArch64.
arm ELF32 EABI binaries could be execute in AArch32 state on AArch64. A32 THUMB mode is not supported yet.


# 1.28 12-Oct-2018 ryo

- cleanup checking address ranges with IN_RANGE macro
- change PM_ADDR_CHECK macro to KASSERTMSG
- restore fast lookup cases with IN_RANGE macro for pmap_extract changed in my previous commit.


# 1.27 12-Oct-2018 ryo

rewrite pmap_pte_lookup() to share similar code.


# 1.26 04-Oct-2018 ryo

cleanup locore, and changed the way to map memories during boot.
- add functions bootpage_enter() and bootpage_alloc() to adapt various layout
of physical memory map. especially for 64bit physical memory layout.
pmapboot_alloc() allocates pagetable pages from _end[].
- changed to map only the required amount for PA=VA identity mapping
(kernel image, UART device, and FDT blob) with L2_BLOCK(2Mbyte).
- changing page permission for kernel image, and making KSEG mapping are done
at cpu_kernel_vm_init() instead of at locore.
- optimize PTE entries with PTE Contiguous bit. it is enabled on devmap only for now.

reviewed by skrll@, thanks.


# 1.25 04-Oct-2018 ryo

* define LX_BLKPAG_{OS,ATTR}_* for OS dependent PTE attributes in pmap.h
* cleanup macros


Revision tags: pgoyette-compat-0930
# 1.24 17-Sep-2018 ryo

delete debug printf and KASSERT.


# 1.23 10-Sep-2018 maxv

Replace KDASSERT by panic.


# 1.22 10-Sep-2018 maxv

Rename _pmap_alloc_pdp -> pmap_alloc_pdp, and make it public.


# 1.21 10-Sep-2018 ryo

cleanup aarch64 mpstart and fdt bootstrap
* arm_cpu_hatch_arg is a bad idea. avoid serializing CPU startup, and eliminate arm_cpu_hatch_arg.
in mpstart, resolve own cpu index using array of cpu_mpidr[] (aarch64)
* add support fdt enable-method "spin-table"
* add support fdt enable-method "brcm,bcm2836-smp" (for 32bit RaspberryPi)
* use arm_fdt_cpu_bootstrap() instead of psci_fdt_bootstrap()
* rename "arm/fdt/psci_fdt.h" to "arm/fdt/psci_fdtvar.h" because of conflict of include file for needs-flag
* add devmap for cpu spin-table of raspberrypi3/aarch64
* no need to force hatch APs for raspberrypi3/arm32 ifndef MULTIPROCESSOR.
* fix to work pmap_extract(kerneltext/data/bss) even if before calling pmap_bootstrap

idea to use cpu_mpidr[] by jmcneill@. reviewd by skrll@. thanks.


Revision tags: pgoyette-compat-0906
# 1.20 27-Aug-2018 ryo

need to add VM_PROT_READ when pmap_kenter_pa(va, pa, VM_PROT_WRITE, 0) or pmap_kenter_pa(va, pa, VM_PROT_EXECUTE, 0).
VM_PROT_READ is treated as an access permission inernally.


# 1.19 11-Aug-2018 ryo

change to minimum invalidation of TLB.
specifying not only va but also asid, and not invalidate L0-L2 entry using tlbi_*_ll() if needed.


# 1.18 10-Aug-2018 ryo

treat kernel-exec attr and user-exec attr separately.
kernel cannot execute userland exec page, and user cannot execute kernel page.


# 1.17 06-Aug-2018 ryo

set kernel text/rodata readonly by default.
add function db_write_text() for setting ddb breakpoint.


# 1.16 31-Jul-2018 skrll

Define and use VPRINTF


Revision tags: pgoyette-compat-0728
# 1.15 27-Jul-2018 ryo

changes of pmap.c r1.13 seems to be unstable.
In order to invalidate icache, not to invalidate all icache,
but temporary to make the page writable and invalidate target address only.


# 1.14 24-Jul-2018 ryo

don't call pool_cache_put with locking pmap. pool_cache_put call pmap_kenter_pa internally.
(pool_cache_put_paddr -> pool_cache_put_slow -> pool_get -> pmap_kenter_pa)


# 1.13 23-Jul-2018 ryo

* fix icache invalidations.
* "ic ivau" (aarch64_icache_sync_range) with VA generates permission fault in some situations, therefore use KSEG address for now.


# 1.12 23-Jul-2018 ryo

rather than using flags to resolve nested locks, reserve pool_cache before locking.


# 1.11 21-Jul-2018 ryo

* avoid deadlock. mutex_owned() works only for adaptive lock, therefore we cannot use it for spinlock...
* add more NULL check
* clear pte when pmap_enter() fails


# 1.10 17-Jul-2018 ryo

Use __debugused


# 1.9 17-Jul-2018 christos

Add missing casts, remove unused variables.


# 1.8 09-Jul-2018 ryo

need locks in pmap_kremove() and pmap_fault_fixup()


Revision tags: phil-wifi-base pgoyette-compat-0625 pgoyette-compat-0521
# 1.7 20-May-2018 ryo

branches: 1.7.2;
pmap_enter() must update modified/referenced flags by 'flags' not 'prot'.


# 1.6 16-May-2018 ryo

Fix memory leak. it was leaking one page every pmap_create().
pm->pm_vmlist must be initialized before calling _pmap_alloc_pdp().


Revision tags: pgoyette-compat-0502
# 1.5 29-Apr-2018 ryo

fix KASSERT panic. pv_entry may not be exists in pvlist when pmap_remove().


# 1.4 29-Apr-2018 ryo

delete unused code


# 1.3 27-Apr-2018 ryo

fix instability behavior of bufcache on aarch64.
* fix to return correct ref/mod when PMAP_WIRED.
* changed to keep wired flags in pte instead of pv_entry, and cleanup.


Revision tags: pgoyette-compat-0422 pgoyette-compat-0415 pgoyette-compat-0407
# 1.2 01-Apr-2018 ryo

Add initial support for ARMv8 (AARCH64) (by nisimura@ and ryo@)

- sys/arch/evbarm64 is gone and integrated into sys/arch/evbarm. (by skrll@)
- add support fdt. evbarm/conf/GENERIC64 fdt (bcm2837,sunxi,tegra) based generic 64bit kernel config. (by skrll@, jmcneill@)


Revision tags: netbsd-8-2-RELEASE netbsd-8-1-RELEASE netbsd-8-1-RC1 netbsd-7-2-RELEASE netbsd-8-0-RELEASE netbsd-8-0-RC2 netbsd-8-0-RC1 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 netbsd-7-1-2-RELEASE pgoyette-compat-base netbsd-7-1-1-RELEASE tls-maxphys-base-20171202 matt-nb8-mediatek-base nick-nhusb-base-20170825 perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base pgoyette-localcount-20170320 netbsd-7-1-RELEASE netbsd-7-1-RC2 nick-nhusb-base-20170204 netbsd-7-nhusb-base-20170116 bouyer-socketcan-base pgoyette-localcount-20170107 netbsd-7-1-RC1 nick-nhusb-base-20161204 pgoyette-localcount-20161104 netbsd-7-0-2-RELEASE nick-nhusb-base-20161004 localcount-20160914 netbsd-7-nhusb-base pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907 nick-nhusb-base-20160529 netbsd-7-0-1-RELEASE nick-nhusb-base-20160422 nick-nhusb-base-20160319 nick-nhusb-base-20151226 netbsd-7-0-RELEASE nick-nhusb-base-20150921 netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 nick-nhusb-base-20150606 nick-nhusb-base-20150406 nick-nhusb-base tls-maxphys-base netbsd-7-base
# 1.1 10-Aug-2014 matt

branches: 1.1.4; 1.1.28;
Preliminary files for AARCH64 (64-bit ARM) support.
Enough for a distribution build.


# 1.72 13-May-2020 jmcneill

Implement pmap_extract_coherency


Revision tags: bouyer-xenpvh-base2 phil-wifi-20200421 bouyer-xenpvh-base1
# 1.71 18-Apr-2020 skrll

PMAP_DEBUG has been deleted on arm


# 1.70 13-Apr-2020 maxv

Add support for Branch Target Identification (BTI).

On the executable pages that have the GP (Guarded Page) bit, the semantic
of the "br" and "blr" instructions is changed: the CPU expects the first
instruction of the jump/call target to be "bti", and faults if it isn't.

We add the GP bit on the kernel .text pages (and incidentally the .rodata
pages, but we don't care). The compiler adds a "bti c" instruction at the
beginning of each C function. We modify the ENTRY() macros to manually add
"bti c" in the asm functions.

cpuswitch.S needs a specific change: with "br x27" the CPU expects "bti j",
which is bad because the functions begin with "bti c"; switch to "br x16",
for the CPU to accept "bti c".

BTI helps defend against JOP/COP. Tested on Qemu.


Revision tags: phil-wifi-20200411 bouyer-xenpvh-base
# 1.69 08-Apr-2020 ryo

branches: 1.69.2;
use PMAP_PAGE_INIT() to initialize mutex in pmap_page.

VM_MDPAGE_INIT() in pmap_free_pdp() had initialized pp_flags,
so it unintentionally cleared PMAP_PAGE_FLAGS_PV_TRACKED.
use PMAP_PAGE_INIT to avoid using PMAP_PAGE_FLAGS_PV_TRACKED.

pointed out by tnn@, thanks


Revision tags: phil-wifi-20200406
# 1.68 14-Mar-2020 ad

pmap_remove_all(): Return a boolean value to indicate the behaviour. If
true, all mappings have been removed, the pmap is totally cleared out, and
UVM can then avoid doing the work to call pmap_remove() for each map entry.
If false, either nothing has been done, or some helpful arch-specific voodoo
has taken place.


Revision tags: is-mlppp-base
# 1.67 02-Mar-2020 ryo

oops, fix incorrect usage of daif_enable() in my previous commit.


# 1.66 29-Feb-2020 ryo

Fix pmap to work correctly with tagged addresses

- when fault, untag from address before passing to uvm/pmap functions
- pmap_extract() checks more strictly and consider the address tag


# 1.65 29-Feb-2020 ryo

use pmapboot_enter_range()


Revision tags: ad-namecache-base3
# 1.64 10-Feb-2020 ryo

use LIST(3) instead of TAILQ(3) to save one word in struct vm_page and struct pmap.

pointed out by riastradh@. thanks


# 1.63 03-Feb-2020 ryo

add support pmap_pv(9)

Patch originally from jmcneill@. thanks


# 1.62 03-Feb-2020 ryo

separate struct vm_page_md into vm_page_md and pmap_page
for preparation pmap_pv(9)


Revision tags: ad-namecache-base2 ad-namecache-base1
# 1.61 09-Jan-2020 ryo

fix behaviour mmap()/mprotect() when passed only PROT_EXEC.

when mmap()/mprotect() with only PROT_EXEC, syscall will be successful,
but the page actually hadn't been mapped.
it should be mapped with PROT_READ|PROT_EXEC implicitly. (r-x)


Revision tags: ad-namecache-base
# 1.60 30-Dec-2019 skrll

branches: 1.60.2;
Update pmap_map_chunk to allow L[12] block mappings and L3 page mappings


# 1.59 30-Dec-2019 skrll

Remove unnecessary brackets and unwrap a conditional. Same code before
and after.


# 1.58 28-Dec-2019 jmcneill

Do not use Early Write Acknowledge for PCIe I/O and config space.


# 1.57 27-Dec-2019 jmcneill

Enable early write acknowledge for device memory mappings.


# 1.56 19-Dec-2019 skrll

G/C kasan_shadow_map call in pmap_enter

pmap_growkernel calls kasan_shadow_map for KVA


# 1.55 18-Dec-2019 ryo

atomic_add_16() is not used in pmap.c anymore. no need decl here.


# 1.54 18-Dec-2019 ryo

space to tab


# 1.53 14-Dec-2019 skrll

Fix build... wire_count probably doesn't need atomics


# 1.52 13-Dec-2019 skrll

Fix KASAN support by calling kasan_shadow_map in pmap_growkernel


# 1.51 10-Dec-2019 ad

pg->phys_addr -> VM_PAGE_TO_PHYS(pg)


Revision tags: phil-wifi-20191119
# 1.50 14-Nov-2019 maxv

Mark several kASan functions with __nothing, to avoid annoying #ifdefs.
Same as kCSan and kMSan.


# 1.49 14-Nov-2019 maxv

Don't include "opt_kasan.h" when there's already <sys/asan.h> included.


# 1.48 29-Oct-2019 maya

Define PMAP_NEED_PROCWR, providing strategically placed i-cache
synchronization where just-changed memory is about to be executed.

Fixes SIGILLs seen when running Mono 6 on QEMU Cortex-A57.

ok ryo


# 1.47 22-Sep-2019 jmcneill

Disable translation table walks using TTBR0 while changing its value and
when deactivating a pmap. Fixes stability issues on Ampere eMAG CPUs.


# 1.46 20-Sep-2019 ryo

ref/mod bit should be set according to 'flags' argument, not 'prot'. r1.44 was incomplete.


# 1.45 13-Sep-2019 ryo

In pmap_devmap_bootstrap(), cpu_earlydevice_va_p() must not return true until *all* devmap tables have been enabled.
console mapping may be present in the last table.


# 1.44 07-Sep-2019 ryo

- remove incorrect KASSERT. mmap(2) with prot=PROT_WRITE calls pmap_enter(..., PROT_WRITE) internally.
- fix to update page reference flags when only PROT_WRITE or PROT_EXECUTE specified


# 1.43 15-Aug-2019 skrll

Make pmap_db_pte_print more terse so it's quicker on serial consoles


# 1.42 12-Aug-2019 skrll

Use PMAP_DEV in DEVMAP_ENTRY rather than pmap_map_chunk. It's clearer and
means pmap_map_chunk can be made to map other memory types.


Revision tags: netbsd-9-base phil-wifi-20190609
# 1.41 17-May-2019 mrg

branches: 1.41.2;
apply some __diagused.


Revision tags: isaki-audio2-base
# 1.40 08-Apr-2019 ryo

- free empty page tables pages if reach a certain usage.
- need to lock at removing an old pg (_pmap_remove_pv) in _pmap_enter()


# 1.39 06-Apr-2019 ryo

Fix race conditions about pmap_page_protect() and pmap_enter().

while handling same PTE by these functions in same time, there
is a critical path that the number of valid PTEs and wire_count
are inconsistent, and it caused KASSERT.
Need to hold a pv_lock while modifying them.


# 1.38 20-Mar-2019 ryo

spinkle __printflike(), and use PRIxxx


# 1.37 19-Mar-2019 ryo

- add ddb command "machine ttbr" to dump MMU tables.
- tidy up descriptions, usages and messages.


# 1.36 19-Mar-2019 ryo

- free L1-L3 pages that has been emptied by pmap_remove().
- if no memories, pmap_enter will return correctly ENOMEM if PMAP_CANFAIL, or wait until available any memories if !PMAP_CANFAIL.

These changes improves the stability when we use a huge virtual memory spaces with mmap.


# 1.35 06-Feb-2019 ryo

improve pmap_remove
- don't lock/unlock per page in pmap_remove()
- speedup pte lookup for continuous addresses
- bring out pool_cache_put(&_pmap_pv_pool, pv) from lock/unlock section


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226
# 1.34 21-Dec-2018 ryo

- add workaround for Cavium ThunderX errata 27456.
- add cpufuncs table in cpu_info. each cpu clusters may have different erratum. (e.g. big.LITTLE)


Revision tags: pgoyette-compat-1126
# 1.33 01-Nov-2018 maxv

Add kASan support for aarch64. Stack tracking needs more investigation
and will come in a separate commit.

Reviewed by ryo@ jmcneill@ skrll@.


# 1.32 31-Oct-2018 ryo

invalidate icache correctly.
l3pte_executable() should be used for only valid pte.


Revision tags: pgoyette-compat-1020
# 1.31 18-Oct-2018 skrll

Provide generic start code that assumes the MMU is off and caches are
disabled as per the linux booting protocol for ARMv6 and ARMv7 boards.
u-boot image type should be changed to 'linux' for correct behaviour.

The new start code builds a minimal "bootstrap" L1PT with cached access
disabled and uses the same table for all processors. AP startup is
performed in less steps and more code is written in C.

The bootstrap tables and stack are placed into an (orphaned) section
"_init_memory" which is given to uvm when it is no longer used.

Various kernels have been converted to use this code and tested. Some
boards were provided by TNF. Thanks!

The GENERIC kernel now boots on boards using the TEGRA, SUNXI and EXYNOS
kernels. The GENERIC kernel will also work on RPI2 using u-boot.

Thanks to martin@ and aymeric@ for testing on parallella and nanosoc
respectively


# 1.30 14-Oct-2018 skrll

Use __nothing


# 1.29 12-Oct-2018 ryo

add initial support of COMPAT_NETBSD32 on AArch64.
arm ELF32 EABI binaries could be execute in AArch32 state on AArch64. A32 THUMB mode is not supported yet.


# 1.28 12-Oct-2018 ryo

- cleanup checking address ranges with IN_RANGE macro
- change PM_ADDR_CHECK macro to KASSERTMSG
- restore fast lookup cases with IN_RANGE macro for pmap_extract changed in my previous commit.


# 1.27 12-Oct-2018 ryo

rewrite pmap_pte_lookup() to share similar code.


# 1.26 04-Oct-2018 ryo

cleanup locore, and changed the way to map memories during boot.
- add functions bootpage_enter() and bootpage_alloc() to adapt various layout
of physical memory map. especially for 64bit physical memory layout.
pmapboot_alloc() allocates pagetable pages from _end[].
- changed to map only the required amount for PA=VA identity mapping
(kernel image, UART device, and FDT blob) with L2_BLOCK(2Mbyte).
- changing page permission for kernel image, and making KSEG mapping are done
at cpu_kernel_vm_init() instead of at locore.
- optimize PTE entries with PTE Contiguous bit. it is enabled on devmap only for now.

reviewed by skrll@, thanks.


# 1.25 04-Oct-2018 ryo

* define LX_BLKPAG_{OS,ATTR}_* for OS dependent PTE attributes in pmap.h
* cleanup macros


Revision tags: pgoyette-compat-0930
# 1.24 17-Sep-2018 ryo

delete debug printf and KASSERT.


# 1.23 10-Sep-2018 maxv

Replace KDASSERT by panic.


# 1.22 10-Sep-2018 maxv

Rename _pmap_alloc_pdp -> pmap_alloc_pdp, and make it public.


# 1.21 10-Sep-2018 ryo

cleanup aarch64 mpstart and fdt bootstrap
* arm_cpu_hatch_arg is a bad idea. avoid serializing CPU startup, and eliminate arm_cpu_hatch_arg.
in mpstart, resolve own cpu index using array of cpu_mpidr[] (aarch64)
* add support fdt enable-method "spin-table"
* add support fdt enable-method "brcm,bcm2836-smp" (for 32bit RaspberryPi)
* use arm_fdt_cpu_bootstrap() instead of psci_fdt_bootstrap()
* rename "arm/fdt/psci_fdt.h" to "arm/fdt/psci_fdtvar.h" because of conflict of include file for needs-flag
* add devmap for cpu spin-table of raspberrypi3/aarch64
* no need to force hatch APs for raspberrypi3/arm32 ifndef MULTIPROCESSOR.
* fix to work pmap_extract(kerneltext/data/bss) even if before calling pmap_bootstrap

idea to use cpu_mpidr[] by jmcneill@. reviewd by skrll@. thanks.


Revision tags: pgoyette-compat-0906
# 1.20 27-Aug-2018 ryo

need to add VM_PROT_READ when pmap_kenter_pa(va, pa, VM_PROT_WRITE, 0) or pmap_kenter_pa(va, pa, VM_PROT_EXECUTE, 0).
VM_PROT_READ is treated as an access permission inernally.


# 1.19 11-Aug-2018 ryo

change to minimum invalidation of TLB.
specifying not only va but also asid, and not invalidate L0-L2 entry using tlbi_*_ll() if needed.


# 1.18 10-Aug-2018 ryo

treat kernel-exec attr and user-exec attr separately.
kernel cannot execute userland exec page, and user cannot execute kernel page.


# 1.17 06-Aug-2018 ryo

set kernel text/rodata readonly by default.
add function db_write_text() for setting ddb breakpoint.


# 1.16 31-Jul-2018 skrll

Define and use VPRINTF


Revision tags: pgoyette-compat-0728
# 1.15 27-Jul-2018 ryo

changes of pmap.c r1.13 seems to be unstable.
In order to invalidate icache, not to invalidate all icache,
but temporary to make the page writable and invalidate target address only.


# 1.14 24-Jul-2018 ryo

don't call pool_cache_put with locking pmap. pool_cache_put call pmap_kenter_pa internally.
(pool_cache_put_paddr -> pool_cache_put_slow -> pool_get -> pmap_kenter_pa)


# 1.13 23-Jul-2018 ryo

* fix icache invalidations.
* "ic ivau" (aarch64_icache_sync_range) with VA generates permission fault in some situations, therefore use KSEG address for now.


# 1.12 23-Jul-2018 ryo

rather than using flags to resolve nested locks, reserve pool_cache before locking.


# 1.11 21-Jul-2018 ryo

* avoid deadlock. mutex_owned() works only for adaptive lock, therefore we cannot use it for spinlock...
* add more NULL check
* clear pte when pmap_enter() fails


# 1.10 17-Jul-2018 ryo

Use __debugused


# 1.9 17-Jul-2018 christos

Add missing casts, remove unused variables.


# 1.8 09-Jul-2018 ryo

need locks in pmap_kremove() and pmap_fault_fixup()


Revision tags: phil-wifi-base pgoyette-compat-0625 pgoyette-compat-0521
# 1.7 20-May-2018 ryo

branches: 1.7.2;
pmap_enter() must update modified/referenced flags by 'flags' not 'prot'.


# 1.6 16-May-2018 ryo

Fix memory leak. it was leaking one page every pmap_create().
pm->pm_vmlist must be initialized before calling _pmap_alloc_pdp().


Revision tags: pgoyette-compat-0502
# 1.5 29-Apr-2018 ryo

fix KASSERT panic. pv_entry may not be exists in pvlist when pmap_remove().


# 1.4 29-Apr-2018 ryo

delete unused code


# 1.3 27-Apr-2018 ryo

fix instability behavior of bufcache on aarch64.
* fix to return correct ref/mod when PMAP_WIRED.
* changed to keep wired flags in pte instead of pv_entry, and cleanup.


Revision tags: pgoyette-compat-0422 pgoyette-compat-0415 pgoyette-compat-0407
# 1.2 01-Apr-2018 ryo

Add initial support for ARMv8 (AARCH64) (by nisimura@ and ryo@)

- sys/arch/evbarm64 is gone and integrated into sys/arch/evbarm. (by skrll@)
- add support fdt. evbarm/conf/GENERIC64 fdt (bcm2837,sunxi,tegra) based generic 64bit kernel config. (by skrll@, jmcneill@)


Revision tags: netbsd-8-2-RELEASE netbsd-8-1-RELEASE netbsd-8-1-RC1 netbsd-7-2-RELEASE netbsd-8-0-RELEASE netbsd-8-0-RC2 netbsd-8-0-RC1 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 netbsd-7-1-2-RELEASE pgoyette-compat-base netbsd-7-1-1-RELEASE tls-maxphys-base-20171202 matt-nb8-mediatek-base nick-nhusb-base-20170825 perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base pgoyette-localcount-20170320 netbsd-7-1-RELEASE netbsd-7-1-RC2 nick-nhusb-base-20170204 netbsd-7-nhusb-base-20170116 bouyer-socketcan-base pgoyette-localcount-20170107 netbsd-7-1-RC1 nick-nhusb-base-20161204 pgoyette-localcount-20161104 netbsd-7-0-2-RELEASE nick-nhusb-base-20161004 localcount-20160914 netbsd-7-nhusb-base pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907 nick-nhusb-base-20160529 netbsd-7-0-1-RELEASE nick-nhusb-base-20160422 nick-nhusb-base-20160319 nick-nhusb-base-20151226 netbsd-7-0-RELEASE nick-nhusb-base-20150921 netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 nick-nhusb-base-20150606 nick-nhusb-base-20150406 nick-nhusb-base tls-maxphys-base netbsd-7-base
# 1.1 10-Aug-2014 matt

branches: 1.1.4; 1.1.28;
Preliminary files for AARCH64 (64-bit ARM) support.
Enough for a distribution build.


# 1.71 18-Apr-2020 skrll

PMAP_DEBUG has been deleted on arm


# 1.70 13-Apr-2020 maxv

Add support for Branch Target Identification (BTI).

On the executable pages that have the GP (Guarded Page) bit, the semantic
of the "br" and "blr" instructions is changed: the CPU expects the first
instruction of the jump/call target to be "bti", and faults if it isn't.

We add the GP bit on the kernel .text pages (and incidentally the .rodata
pages, but we don't care). The compiler adds a "bti c" instruction at the
beginning of each C function. We modify the ENTRY() macros to manually add
"bti c" in the asm functions.

cpuswitch.S needs a specific change: with "br x27" the CPU expects "bti j",
which is bad because the functions begin with "bti c"; switch to "br x16",
for the CPU to accept "bti c".

BTI helps defend against JOP/COP. Tested on Qemu.


Revision tags: phil-wifi-20200411 bouyer-xenpvh-base
# 1.69 08-Apr-2020 ryo

use PMAP_PAGE_INIT() to initialize mutex in pmap_page.

VM_MDPAGE_INIT() in pmap_free_pdp() had initialized pp_flags,
so it unintentionally cleared PMAP_PAGE_FLAGS_PV_TRACKED.
use PMAP_PAGE_INIT to avoid using PMAP_PAGE_FLAGS_PV_TRACKED.

pointed out by tnn@, thanks


Revision tags: phil-wifi-20200406
# 1.68 14-Mar-2020 ad

pmap_remove_all(): Return a boolean value to indicate the behaviour. If
true, all mappings have been removed, the pmap is totally cleared out, and
UVM can then avoid doing the work to call pmap_remove() for each map entry.
If false, either nothing has been done, or some helpful arch-specific voodoo
has taken place.


Revision tags: is-mlppp-base
# 1.67 02-Mar-2020 ryo

oops, fix incorrect usage of daif_enable() in my previous commit.


# 1.66 29-Feb-2020 ryo

Fix pmap to work correctly with tagged addresses

- when fault, untag from address before passing to uvm/pmap functions
- pmap_extract() checks more strictly and consider the address tag


# 1.65 29-Feb-2020 ryo

use pmapboot_enter_range()


Revision tags: ad-namecache-base3
# 1.64 10-Feb-2020 ryo

use LIST(3) instead of TAILQ(3) to save one word in struct vm_page and struct pmap.

pointed out by riastradh@. thanks


# 1.63 03-Feb-2020 ryo

add support pmap_pv(9)

Patch originally from jmcneill@. thanks


# 1.62 03-Feb-2020 ryo

separate struct vm_page_md into vm_page_md and pmap_page
for preparation pmap_pv(9)


Revision tags: ad-namecache-base2 ad-namecache-base1
# 1.61 09-Jan-2020 ryo

fix behaviour mmap()/mprotect() when passed only PROT_EXEC.

when mmap()/mprotect() with only PROT_EXEC, syscall will be successful,
but the page actually hadn't been mapped.
it should be mapped with PROT_READ|PROT_EXEC implicitly. (r-x)


Revision tags: ad-namecache-base
# 1.60 30-Dec-2019 skrll

branches: 1.60.2;
Update pmap_map_chunk to allow L[12] block mappings and L3 page mappings


# 1.59 30-Dec-2019 skrll

Remove unnecessary brackets and unwrap a conditional. Same code before
and after.


# 1.58 28-Dec-2019 jmcneill

Do not use Early Write Acknowledge for PCIe I/O and config space.


# 1.57 27-Dec-2019 jmcneill

Enable early write acknowledge for device memory mappings.


# 1.56 19-Dec-2019 skrll

G/C kasan_shadow_map call in pmap_enter

pmap_growkernel calls kasan_shadow_map for KVA


# 1.55 18-Dec-2019 ryo

atomic_add_16() is not used in pmap.c anymore. no need decl here.


# 1.54 18-Dec-2019 ryo

space to tab


# 1.53 14-Dec-2019 skrll

Fix build... wire_count probably doesn't need atomics


# 1.52 13-Dec-2019 skrll

Fix KASAN support by calling kasan_shadow_map in pmap_growkernel


# 1.51 10-Dec-2019 ad

pg->phys_addr -> VM_PAGE_TO_PHYS(pg)


Revision tags: phil-wifi-20191119
# 1.50 14-Nov-2019 maxv

Mark several kASan functions with __nothing, to avoid annoying #ifdefs.
Same as kCSan and kMSan.


# 1.49 14-Nov-2019 maxv

Don't include "opt_kasan.h" when there's already <sys/asan.h> included.


# 1.48 29-Oct-2019 maya

Define PMAP_NEED_PROCWR, providing strategically placed i-cache
synchronization where just-changed memory is about to be executed.

Fixes SIGILLs seen when running Mono 6 on QEMU Cortex-A57.

ok ryo


# 1.47 22-Sep-2019 jmcneill

Disable translation table walks using TTBR0 while changing its value and
when deactivating a pmap. Fixes stability issues on Ampere eMAG CPUs.


# 1.46 20-Sep-2019 ryo

ref/mod bit should be set according to 'flags' argument, not 'prot'. r1.44 was incomplete.


# 1.45 13-Sep-2019 ryo

In pmap_devmap_bootstrap(), cpu_earlydevice_va_p() must not return true until *all* devmap tables have been enabled.
console mapping may be present in the last table.


# 1.44 07-Sep-2019 ryo

- remove incorrect KASSERT. mmap(2) with prot=PROT_WRITE calls pmap_enter(..., PROT_WRITE) internally.
- fix to update page reference flags when only PROT_WRITE or PROT_EXECUTE specified


# 1.43 15-Aug-2019 skrll

Make pmap_db_pte_print more terse so it's quicker on serial consoles


# 1.42 12-Aug-2019 skrll

Use PMAP_DEV in DEVMAP_ENTRY rather than pmap_map_chunk. It's clearer and
means pmap_map_chunk can be made to map other memory types.


Revision tags: netbsd-9-base phil-wifi-20190609
# 1.41 17-May-2019 mrg

branches: 1.41.2;
apply some __diagused.


Revision tags: isaki-audio2-base
# 1.40 08-Apr-2019 ryo

- free empty page tables pages if reach a certain usage.
- need to lock at removing an old pg (_pmap_remove_pv) in _pmap_enter()


# 1.39 06-Apr-2019 ryo

Fix race conditions about pmap_page_protect() and pmap_enter().

while handling same PTE by these functions in same time, there
is a critical path that the number of valid PTEs and wire_count
are inconsistent, and it caused KASSERT.
Need to hold a pv_lock while modifying them.


# 1.38 20-Mar-2019 ryo

spinkle __printflike(), and use PRIxxx


# 1.37 19-Mar-2019 ryo

- add ddb command "machine ttbr" to dump MMU tables.
- tidy up descriptions, usages and messages.


# 1.36 19-Mar-2019 ryo

- free L1-L3 pages that has been emptied by pmap_remove().
- if no memories, pmap_enter will return correctly ENOMEM if PMAP_CANFAIL, or wait until available any memories if !PMAP_CANFAIL.

These changes improves the stability when we use a huge virtual memory spaces with mmap.


# 1.35 06-Feb-2019 ryo

improve pmap_remove
- don't lock/unlock per page in pmap_remove()
- speedup pte lookup for continuous addresses
- bring out pool_cache_put(&_pmap_pv_pool, pv) from lock/unlock section


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226
# 1.34 21-Dec-2018 ryo

- add workaround for Cavium ThunderX errata 27456.
- add cpufuncs table in cpu_info. each cpu clusters may have different erratum. (e.g. big.LITTLE)


Revision tags: pgoyette-compat-1126
# 1.33 01-Nov-2018 maxv

Add kASan support for aarch64. Stack tracking needs more investigation
and will come in a separate commit.

Reviewed by ryo@ jmcneill@ skrll@.


# 1.32 31-Oct-2018 ryo

invalidate icache correctly.
l3pte_executable() should be used for only valid pte.


Revision tags: pgoyette-compat-1020
# 1.31 18-Oct-2018 skrll

Provide generic start code that assumes the MMU is off and caches are
disabled as per the linux booting protocol for ARMv6 and ARMv7 boards.
u-boot image type should be changed to 'linux' for correct behaviour.

The new start code builds a minimal "bootstrap" L1PT with cached access
disabled and uses the same table for all processors. AP startup is
performed in less steps and more code is written in C.

The bootstrap tables and stack are placed into an (orphaned) section
"_init_memory" which is given to uvm when it is no longer used.

Various kernels have been converted to use this code and tested. Some
boards were provided by TNF. Thanks!

The GENERIC kernel now boots on boards using the TEGRA, SUNXI and EXYNOS
kernels. The GENERIC kernel will also work on RPI2 using u-boot.

Thanks to martin@ and aymeric@ for testing on parallella and nanosoc
respectively


# 1.30 14-Oct-2018 skrll

Use __nothing


# 1.29 12-Oct-2018 ryo

add initial support of COMPAT_NETBSD32 on AArch64.
arm ELF32 EABI binaries could be execute in AArch32 state on AArch64. A32 THUMB mode is not supported yet.


# 1.28 12-Oct-2018 ryo

- cleanup checking address ranges with IN_RANGE macro
- change PM_ADDR_CHECK macro to KASSERTMSG
- restore fast lookup cases with IN_RANGE macro for pmap_extract changed in my previous commit.


# 1.27 12-Oct-2018 ryo

rewrite pmap_pte_lookup() to share similar code.


# 1.26 04-Oct-2018 ryo

cleanup locore, and changed the way to map memories during boot.
- add functions bootpage_enter() and bootpage_alloc() to adapt various layout
of physical memory map. especially for 64bit physical memory layout.
pmapboot_alloc() allocates pagetable pages from _end[].
- changed to map only the required amount for PA=VA identity mapping
(kernel image, UART device, and FDT blob) with L2_BLOCK(2Mbyte).
- changing page permission for kernel image, and making KSEG mapping are done
at cpu_kernel_vm_init() instead of at locore.
- optimize PTE entries with PTE Contiguous bit. it is enabled on devmap only for now.

reviewed by skrll@, thanks.


# 1.25 04-Oct-2018 ryo

* define LX_BLKPAG_{OS,ATTR}_* for OS dependent PTE attributes in pmap.h
* cleanup macros


Revision tags: pgoyette-compat-0930
# 1.24 17-Sep-2018 ryo

delete debug printf and KASSERT.


# 1.23 10-Sep-2018 maxv

Replace KDASSERT by panic.


# 1.22 10-Sep-2018 maxv

Rename _pmap_alloc_pdp -> pmap_alloc_pdp, and make it public.


# 1.21 10-Sep-2018 ryo

cleanup aarch64 mpstart and fdt bootstrap
* arm_cpu_hatch_arg is a bad idea. avoid serializing CPU startup, and eliminate arm_cpu_hatch_arg.
in mpstart, resolve own cpu index using array of cpu_mpidr[] (aarch64)
* add support fdt enable-method "spin-table"
* add support fdt enable-method "brcm,bcm2836-smp" (for 32bit RaspberryPi)
* use arm_fdt_cpu_bootstrap() instead of psci_fdt_bootstrap()
* rename "arm/fdt/psci_fdt.h" to "arm/fdt/psci_fdtvar.h" because of conflict of include file for needs-flag
* add devmap for cpu spin-table of raspberrypi3/aarch64
* no need to force hatch APs for raspberrypi3/arm32 ifndef MULTIPROCESSOR.
* fix to work pmap_extract(kerneltext/data/bss) even if before calling pmap_bootstrap

idea to use cpu_mpidr[] by jmcneill@. reviewd by skrll@. thanks.


Revision tags: pgoyette-compat-0906
# 1.20 27-Aug-2018 ryo

need to add VM_PROT_READ when pmap_kenter_pa(va, pa, VM_PROT_WRITE, 0) or pmap_kenter_pa(va, pa, VM_PROT_EXECUTE, 0).
VM_PROT_READ is treated as an access permission inernally.


# 1.19 11-Aug-2018 ryo

change to minimum invalidation of TLB.
specifying not only va but also asid, and not invalidate L0-L2 entry using tlbi_*_ll() if needed.


# 1.18 10-Aug-2018 ryo

treat kernel-exec attr and user-exec attr separately.
kernel cannot execute userland exec page, and user cannot execute kernel page.


# 1.17 06-Aug-2018 ryo

set kernel text/rodata readonly by default.
add function db_write_text() for setting ddb breakpoint.


# 1.16 31-Jul-2018 skrll

Define and use VPRINTF


Revision tags: pgoyette-compat-0728
# 1.15 27-Jul-2018 ryo

changes of pmap.c r1.13 seems to be unstable.
In order to invalidate icache, not to invalidate all icache,
but temporary to make the page writable and invalidate target address only.


# 1.14 24-Jul-2018 ryo

don't call pool_cache_put with locking pmap. pool_cache_put call pmap_kenter_pa internally.
(pool_cache_put_paddr -> pool_cache_put_slow -> pool_get -> pmap_kenter_pa)


# 1.13 23-Jul-2018 ryo

* fix icache invalidations.
* "ic ivau" (aarch64_icache_sync_range) with VA generates permission fault in some situations, therefore use KSEG address for now.


# 1.12 23-Jul-2018 ryo

rather than using flags to resolve nested locks, reserve pool_cache before locking.


# 1.11 21-Jul-2018 ryo

* avoid deadlock. mutex_owned() works only for adaptive lock, therefore we cannot use it for spinlock...
* add more NULL check
* clear pte when pmap_enter() fails


# 1.10 17-Jul-2018 ryo

Use __debugused


# 1.9 17-Jul-2018 christos

Add missing casts, remove unused variables.


# 1.8 09-Jul-2018 ryo

need locks in pmap_kremove() and pmap_fault_fixup()


Revision tags: phil-wifi-base pgoyette-compat-0625 pgoyette-compat-0521
# 1.7 20-May-2018 ryo

branches: 1.7.2;
pmap_enter() must update modified/referenced flags by 'flags' not 'prot'.


# 1.6 16-May-2018 ryo

Fix memory leak. it was leaking one page every pmap_create().
pm->pm_vmlist must be initialized before calling _pmap_alloc_pdp().


Revision tags: pgoyette-compat-0502
# 1.5 29-Apr-2018 ryo

fix KASSERT panic. pv_entry may not be exists in pvlist when pmap_remove().


# 1.4 29-Apr-2018 ryo

delete unused code


# 1.3 27-Apr-2018 ryo

fix instability behavior of bufcache on aarch64.
* fix to return correct ref/mod when PMAP_WIRED.
* changed to keep wired flags in pte instead of pv_entry, and cleanup.


Revision tags: pgoyette-compat-0422 pgoyette-compat-0415 pgoyette-compat-0407
# 1.2 01-Apr-2018 ryo

Add initial support for ARMv8 (AARCH64) (by nisimura@ and ryo@)

- sys/arch/evbarm64 is gone and integrated into sys/arch/evbarm. (by skrll@)
- add support fdt. evbarm/conf/GENERIC64 fdt (bcm2837,sunxi,tegra) based generic 64bit kernel config. (by skrll@, jmcneill@)


Revision tags: netbsd-8-2-RELEASE netbsd-8-1-RELEASE netbsd-8-1-RC1 netbsd-7-2-RELEASE netbsd-8-0-RELEASE netbsd-8-0-RC2 netbsd-8-0-RC1 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 netbsd-7-1-2-RELEASE pgoyette-compat-base netbsd-7-1-1-RELEASE tls-maxphys-base-20171202 matt-nb8-mediatek-base nick-nhusb-base-20170825 perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base pgoyette-localcount-20170320 netbsd-7-1-RELEASE netbsd-7-1-RC2 nick-nhusb-base-20170204 netbsd-7-nhusb-base-20170116 bouyer-socketcan-base pgoyette-localcount-20170107 netbsd-7-1-RC1 nick-nhusb-base-20161204 pgoyette-localcount-20161104 netbsd-7-0-2-RELEASE nick-nhusb-base-20161004 localcount-20160914 netbsd-7-nhusb-base pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907 nick-nhusb-base-20160529 netbsd-7-0-1-RELEASE nick-nhusb-base-20160422 nick-nhusb-base-20160319 nick-nhusb-base-20151226 netbsd-7-0-RELEASE nick-nhusb-base-20150921 netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 nick-nhusb-base-20150606 nick-nhusb-base-20150406 nick-nhusb-base tls-maxphys-base netbsd-7-base
# 1.1 10-Aug-2014 matt

branches: 1.1.4; 1.1.28;
Preliminary files for AARCH64 (64-bit ARM) support.
Enough for a distribution build.


# 1.70 13-Apr-2020 maxv

Add support for Branch Target Identification (BTI).

On the executable pages that have the GP (Guarded Page) bit, the semantic
of the "br" and "blr" instructions is changed: the CPU expects the first
instruction of the jump/call target to be "bti", and faults if it isn't.

We add the GP bit on the kernel .text pages (and incidentally the .rodata
pages, but we don't care). The compiler adds a "bti c" instruction at the
beginning of each C function. We modify the ENTRY() macros to manually add
"bti c" in the asm functions.

cpuswitch.S needs a specific change: with "br x27" the CPU expects "bti j",
which is bad because the functions begin with "bti c"; switch to "br x16",
for the CPU to accept "bti c".

BTI helps defend against JOP/COP. Tested on Qemu.


Revision tags: phil-wifi-20200411 bouyer-xenpvh-base
# 1.69 08-Apr-2020 ryo

use PMAP_PAGE_INIT() to initialize mutex in pmap_page.

VM_MDPAGE_INIT() in pmap_free_pdp() had initialized pp_flags,
so it unintentionally cleared PMAP_PAGE_FLAGS_PV_TRACKED.
use PMAP_PAGE_INIT to avoid using PMAP_PAGE_FLAGS_PV_TRACKED.

pointed out by tnn@, thanks


Revision tags: phil-wifi-20200406
# 1.68 14-Mar-2020 ad

pmap_remove_all(): Return a boolean value to indicate the behaviour. If
true, all mappings have been removed, the pmap is totally cleared out, and
UVM can then avoid doing the work to call pmap_remove() for each map entry.
If false, either nothing has been done, or some helpful arch-specific voodoo
has taken place.


Revision tags: is-mlppp-base
# 1.67 02-Mar-2020 ryo

oops, fix incorrect usage of daif_enable() in my previous commit.


# 1.66 29-Feb-2020 ryo

Fix pmap to work correctly with tagged addresses

- when fault, untag from address before passing to uvm/pmap functions
- pmap_extract() checks more strictly and consider the address tag


# 1.65 29-Feb-2020 ryo

use pmapboot_enter_range()


Revision tags: ad-namecache-base3
# 1.64 10-Feb-2020 ryo

use LIST(3) instead of TAILQ(3) to save one word in struct vm_page and struct pmap.

pointed out by riastradh@. thanks


# 1.63 03-Feb-2020 ryo

add support pmap_pv(9)

Patch originally from jmcneill@. thanks


# 1.62 03-Feb-2020 ryo

separate struct vm_page_md into vm_page_md and pmap_page
for preparation pmap_pv(9)


Revision tags: ad-namecache-base2 ad-namecache-base1
# 1.61 09-Jan-2020 ryo

fix behaviour mmap()/mprotect() when passed only PROT_EXEC.

when mmap()/mprotect() with only PROT_EXEC, syscall will be successful,
but the page actually hadn't been mapped.
it should be mapped with PROT_READ|PROT_EXEC implicitly. (r-x)


Revision tags: ad-namecache-base
# 1.60 30-Dec-2019 skrll

branches: 1.60.2;
Update pmap_map_chunk to allow L[12] block mappings and L3 page mappings


# 1.59 30-Dec-2019 skrll

Remove unnecessary brackets and unwrap a conditional. Same code before
and after.


# 1.58 28-Dec-2019 jmcneill

Do not use Early Write Acknowledge for PCIe I/O and config space.


# 1.57 27-Dec-2019 jmcneill

Enable early write acknowledge for device memory mappings.


# 1.56 19-Dec-2019 skrll

G/C kasan_shadow_map call in pmap_enter

pmap_growkernel calls kasan_shadow_map for KVA


# 1.55 18-Dec-2019 ryo

atomic_add_16() is not used in pmap.c anymore. no need decl here.


# 1.54 18-Dec-2019 ryo

space to tab


# 1.53 14-Dec-2019 skrll

Fix build... wire_count probably doesn't need atomics


# 1.52 13-Dec-2019 skrll

Fix KASAN support by calling kasan_shadow_map in pmap_growkernel


# 1.51 10-Dec-2019 ad

pg->phys_addr -> VM_PAGE_TO_PHYS(pg)


Revision tags: phil-wifi-20191119
# 1.50 14-Nov-2019 maxv

Mark several kASan functions with __nothing, to avoid annoying #ifdefs.
Same as kCSan and kMSan.


# 1.49 14-Nov-2019 maxv

Don't include "opt_kasan.h" when there's already <sys/asan.h> included.


# 1.48 29-Oct-2019 maya

Define PMAP_NEED_PROCWR, providing strategically placed i-cache
synchronization where just-changed memory is about to be executed.

Fixes SIGILLs seen when running Mono 6 on QEMU Cortex-A57.

ok ryo


# 1.47 22-Sep-2019 jmcneill

Disable translation table walks using TTBR0 while changing its value and
when deactivating a pmap. Fixes stability issues on Ampere eMAG CPUs.


# 1.46 20-Sep-2019 ryo

ref/mod bit should be set according to 'flags' argument, not 'prot'. r1.44 was incomplete.


# 1.45 13-Sep-2019 ryo

In pmap_devmap_bootstrap(), cpu_earlydevice_va_p() must not return true until *all* devmap tables have been enabled.
console mapping may be present in the last table.


# 1.44 07-Sep-2019 ryo

- remove incorrect KASSERT. mmap(2) with prot=PROT_WRITE calls pmap_enter(..., PROT_WRITE) internally.
- fix to update page reference flags when only PROT_WRITE or PROT_EXECUTE specified


# 1.43 15-Aug-2019 skrll

Make pmap_db_pte_print more terse so it's quicker on serial consoles


# 1.42 12-Aug-2019 skrll

Use PMAP_DEV in DEVMAP_ENTRY rather than pmap_map_chunk. It's clearer and
means pmap_map_chunk can be made to map other memory types.


Revision tags: netbsd-9-base phil-wifi-20190609
# 1.41 17-May-2019 mrg

branches: 1.41.2;
apply some __diagused.


Revision tags: isaki-audio2-base
# 1.40 08-Apr-2019 ryo

- free empty page tables pages if reach a certain usage.
- need to lock at removing an old pg (_pmap_remove_pv) in _pmap_enter()


# 1.39 06-Apr-2019 ryo

Fix race conditions about pmap_page_protect() and pmap_enter().

while handling same PTE by these functions in same time, there
is a critical path that the number of valid PTEs and wire_count
are inconsistent, and it caused KASSERT.
Need to hold a pv_lock while modifying them.


# 1.38 20-Mar-2019 ryo

spinkle __printflike(), and use PRIxxx


# 1.37 19-Mar-2019 ryo

- add ddb command "machine ttbr" to dump MMU tables.
- tidy up descriptions, usages and messages.


# 1.36 19-Mar-2019 ryo

- free L1-L3 pages that has been emptied by pmap_remove().
- if no memories, pmap_enter will return correctly ENOMEM if PMAP_CANFAIL, or wait until available any memories if !PMAP_CANFAIL.

These changes improves the stability when we use a huge virtual memory spaces with mmap.


# 1.35 06-Feb-2019 ryo

improve pmap_remove
- don't lock/unlock per page in pmap_remove()
- speedup pte lookup for continuous addresses
- bring out pool_cache_put(&_pmap_pv_pool, pv) from lock/unlock section


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226
# 1.34 21-Dec-2018 ryo

- add workaround for Cavium ThunderX errata 27456.
- add cpufuncs table in cpu_info. each cpu clusters may have different erratum. (e.g. big.LITTLE)


Revision tags: pgoyette-compat-1126
# 1.33 01-Nov-2018 maxv

Add kASan support for aarch64. Stack tracking needs more investigation
and will come in a separate commit.

Reviewed by ryo@ jmcneill@ skrll@.


# 1.32 31-Oct-2018 ryo

invalidate icache correctly.
l3pte_executable() should be used for only valid pte.


Revision tags: pgoyette-compat-1020
# 1.31 18-Oct-2018 skrll

Provide generic start code that assumes the MMU is off and caches are
disabled as per the linux booting protocol for ARMv6 and ARMv7 boards.
u-boot image type should be changed to 'linux' for correct behaviour.

The new start code builds a minimal "bootstrap" L1PT with cached access
disabled and uses the same table for all processors. AP startup is
performed in less steps and more code is written in C.

The bootstrap tables and stack are placed into an (orphaned) section
"_init_memory" which is given to uvm when it is no longer used.

Various kernels have been converted to use this code and tested. Some
boards were provided by TNF. Thanks!

The GENERIC kernel now boots on boards using the TEGRA, SUNXI and EXYNOS
kernels. The GENERIC kernel will also work on RPI2 using u-boot.

Thanks to martin@ and aymeric@ for testing on parallella and nanosoc
respectively


# 1.30 14-Oct-2018 skrll

Use __nothing


# 1.29 12-Oct-2018 ryo

add initial support of COMPAT_NETBSD32 on AArch64.
arm ELF32 EABI binaries could be execute in AArch32 state on AArch64. A32 THUMB mode is not supported yet.


# 1.28 12-Oct-2018 ryo

- cleanup checking address ranges with IN_RANGE macro
- change PM_ADDR_CHECK macro to KASSERTMSG
- restore fast lookup cases with IN_RANGE macro for pmap_extract changed in my previous commit.


# 1.27 12-Oct-2018 ryo

rewrite pmap_pte_lookup() to share similar code.


# 1.26 04-Oct-2018 ryo

cleanup locore, and changed the way to map memories during boot.
- add functions bootpage_enter() and bootpage_alloc() to adapt various layout
of physical memory map. especially for 64bit physical memory layout.
pmapboot_alloc() allocates pagetable pages from _end[].
- changed to map only the required amount for PA=VA identity mapping
(kernel image, UART device, and FDT blob) with L2_BLOCK(2Mbyte).
- changing page permission for kernel image, and making KSEG mapping are done
at cpu_kernel_vm_init() instead of at locore.
- optimize PTE entries with PTE Contiguous bit. it is enabled on devmap only for now.

reviewed by skrll@, thanks.


# 1.25 04-Oct-2018 ryo

* define LX_BLKPAG_{OS,ATTR}_* for OS dependent PTE attributes in pmap.h
* cleanup macros


Revision tags: pgoyette-compat-0930
# 1.24 17-Sep-2018 ryo

delete debug printf and KASSERT.


# 1.23 10-Sep-2018 maxv

Replace KDASSERT by panic.


# 1.22 10-Sep-2018 maxv

Rename _pmap_alloc_pdp -> pmap_alloc_pdp, and make it public.


# 1.21 10-Sep-2018 ryo

cleanup aarch64 mpstart and fdt bootstrap
* arm_cpu_hatch_arg is a bad idea. avoid serializing CPU startup, and eliminate arm_cpu_hatch_arg.
in mpstart, resolve own cpu index using array of cpu_mpidr[] (aarch64)
* add support fdt enable-method "spin-table"
* add support fdt enable-method "brcm,bcm2836-smp" (for 32bit RaspberryPi)
* use arm_fdt_cpu_bootstrap() instead of psci_fdt_bootstrap()
* rename "arm/fdt/psci_fdt.h" to "arm/fdt/psci_fdtvar.h" because of conflict of include file for needs-flag
* add devmap for cpu spin-table of raspberrypi3/aarch64
* no need to force hatch APs for raspberrypi3/arm32 ifndef MULTIPROCESSOR.
* fix to work pmap_extract(kerneltext/data/bss) even if before calling pmap_bootstrap

idea to use cpu_mpidr[] by jmcneill@. reviewd by skrll@. thanks.


Revision tags: pgoyette-compat-0906
# 1.20 27-Aug-2018 ryo

need to add VM_PROT_READ when pmap_kenter_pa(va, pa, VM_PROT_WRITE, 0) or pmap_kenter_pa(va, pa, VM_PROT_EXECUTE, 0).
VM_PROT_READ is treated as an access permission inernally.


# 1.19 11-Aug-2018 ryo

change to minimum invalidation of TLB.
specifying not only va but also asid, and not invalidate L0-L2 entry using tlbi_*_ll() if needed.


# 1.18 10-Aug-2018 ryo

treat kernel-exec attr and user-exec attr separately.
kernel cannot execute userland exec page, and user cannot execute kernel page.


# 1.17 06-Aug-2018 ryo

set kernel text/rodata readonly by default.
add function db_write_text() for setting ddb breakpoint.


# 1.16 31-Jul-2018 skrll

Define and use VPRINTF


Revision tags: pgoyette-compat-0728
# 1.15 27-Jul-2018 ryo

changes of pmap.c r1.13 seems to be unstable.
In order to invalidate icache, not to invalidate all icache,
but temporary to make the page writable and invalidate target address only.


# 1.14 24-Jul-2018 ryo

don't call pool_cache_put with locking pmap. pool_cache_put call pmap_kenter_pa internally.
(pool_cache_put_paddr -> pool_cache_put_slow -> pool_get -> pmap_kenter_pa)


# 1.13 23-Jul-2018 ryo

* fix icache invalidations.
* "ic ivau" (aarch64_icache_sync_range) with VA generates permission fault in some situations, therefore use KSEG address for now.


# 1.12 23-Jul-2018 ryo

rather than using flags to resolve nested locks, reserve pool_cache before locking.


# 1.11 21-Jul-2018 ryo

* avoid deadlock. mutex_owned() works only for adaptive lock, therefore we cannot use it for spinlock...
* add more NULL check
* clear pte when pmap_enter() fails


# 1.10 17-Jul-2018 ryo

Use __debugused


# 1.9 17-Jul-2018 christos

Add missing casts, remove unused variables.


# 1.8 09-Jul-2018 ryo

need locks in pmap_kremove() and pmap_fault_fixup()


Revision tags: phil-wifi-base pgoyette-compat-0625 pgoyette-compat-0521
# 1.7 20-May-2018 ryo

branches: 1.7.2;
pmap_enter() must update modified/referenced flags by 'flags' not 'prot'.


# 1.6 16-May-2018 ryo

Fix memory leak. it was leaking one page every pmap_create().
pm->pm_vmlist must be initialized before calling _pmap_alloc_pdp().


Revision tags: pgoyette-compat-0502
# 1.5 29-Apr-2018 ryo

fix KASSERT panic. pv_entry may not be exists in pvlist when pmap_remove().


# 1.4 29-Apr-2018 ryo

delete unused code


# 1.3 27-Apr-2018 ryo

fix instability behavior of bufcache on aarch64.
* fix to return correct ref/mod when PMAP_WIRED.
* changed to keep wired flags in pte instead of pv_entry, and cleanup.


Revision tags: pgoyette-compat-0422 pgoyette-compat-0415 pgoyette-compat-0407
# 1.2 01-Apr-2018 ryo

Add initial support for ARMv8 (AARCH64) (by nisimura@ and ryo@)

- sys/arch/evbarm64 is gone and integrated into sys/arch/evbarm. (by skrll@)
- add support fdt. evbarm/conf/GENERIC64 fdt (bcm2837,sunxi,tegra) based generic 64bit kernel config. (by skrll@, jmcneill@)


Revision tags: netbsd-8-2-RELEASE netbsd-8-1-RELEASE netbsd-8-1-RC1 netbsd-7-2-RELEASE netbsd-8-0-RELEASE netbsd-8-0-RC2 netbsd-8-0-RC1 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 netbsd-7-1-2-RELEASE pgoyette-compat-base netbsd-7-1-1-RELEASE tls-maxphys-base-20171202 matt-nb8-mediatek-base nick-nhusb-base-20170825 perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base pgoyette-localcount-20170320 netbsd-7-1-RELEASE netbsd-7-1-RC2 nick-nhusb-base-20170204 netbsd-7-nhusb-base-20170116 bouyer-socketcan-base pgoyette-localcount-20170107 netbsd-7-1-RC1 nick-nhusb-base-20161204 pgoyette-localcount-20161104 netbsd-7-0-2-RELEASE nick-nhusb-base-20161004 localcount-20160914 netbsd-7-nhusb-base pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907 nick-nhusb-base-20160529 netbsd-7-0-1-RELEASE nick-nhusb-base-20160422 nick-nhusb-base-20160319 nick-nhusb-base-20151226 netbsd-7-0-RELEASE nick-nhusb-base-20150921 netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 nick-nhusb-base-20150606 nick-nhusb-base-20150406 nick-nhusb-base tls-maxphys-base netbsd-7-base
# 1.1 10-Aug-2014 matt

branches: 1.1.4; 1.1.28;
Preliminary files for AARCH64 (64-bit ARM) support.
Enough for a distribution build.


# 1.69 08-Apr-2020 ryo

use PMAP_PAGE_INIT() to initialize mutex in pmap_page.

VM_MDPAGE_INIT() in pmap_free_pdp() had initialized pp_flags,
so it unintentionally cleared PMAP_PAGE_FLAGS_PV_TRACKED.
use PMAP_PAGE_INIT to avoid using PMAP_PAGE_FLAGS_PV_TRACKED.

pointed out by tnn@, thanks


Revision tags: phil-wifi-20200406
# 1.68 14-Mar-2020 ad

pmap_remove_all(): Return a boolean value to indicate the behaviour. If
true, all mappings have been removed, the pmap is totally cleared out, and
UVM can then avoid doing the work to call pmap_remove() for each map entry.
If false, either nothing has been done, or some helpful arch-specific voodoo
has taken place.


Revision tags: is-mlppp-base
# 1.67 02-Mar-2020 ryo

oops, fix incorrect usage of daif_enable() in my previous commit.


# 1.66 29-Feb-2020 ryo

Fix pmap to work correctly with tagged addresses

- when fault, untag from address before passing to uvm/pmap functions
- pmap_extract() checks more strictly and consider the address tag


# 1.65 29-Feb-2020 ryo

use pmapboot_enter_range()


Revision tags: ad-namecache-base3
# 1.64 10-Feb-2020 ryo

use LIST(3) instead of TAILQ(3) to save one word in struct vm_page and struct pmap.

pointed out by riastradh@. thanks


# 1.63 03-Feb-2020 ryo

add support pmap_pv(9)

Patch originally from jmcneill@. thanks


# 1.62 03-Feb-2020 ryo

separate struct vm_page_md into vm_page_md and pmap_page
for preparation pmap_pv(9)


Revision tags: ad-namecache-base2 ad-namecache-base1
# 1.61 09-Jan-2020 ryo

fix behaviour mmap()/mprotect() when passed only PROT_EXEC.

when mmap()/mprotect() with only PROT_EXEC, syscall will be successful,
but the page actually hadn't been mapped.
it should be mapped with PROT_READ|PROT_EXEC implicitly. (r-x)


Revision tags: ad-namecache-base
# 1.60 30-Dec-2019 skrll

branches: 1.60.2;
Update pmap_map_chunk to allow L[12] block mappings and L3 page mappings


# 1.59 30-Dec-2019 skrll

Remove unnecessary brackets and unwrap a conditional. Same code before
and after.


# 1.58 28-Dec-2019 jmcneill

Do not use Early Write Acknowledge for PCIe I/O and config space.


# 1.57 27-Dec-2019 jmcneill

Enable early write acknowledge for device memory mappings.


# 1.56 19-Dec-2019 skrll

G/C kasan_shadow_map call in pmap_enter

pmap_growkernel calls kasan_shadow_map for KVA


# 1.55 18-Dec-2019 ryo

atomic_add_16() is not used in pmap.c anymore. no need decl here.


# 1.54 18-Dec-2019 ryo

space to tab


# 1.53 14-Dec-2019 skrll

Fix build... wire_count probably doesn't need atomics


# 1.52 13-Dec-2019 skrll

Fix KASAN support by calling kasan_shadow_map in pmap_growkernel


# 1.51 10-Dec-2019 ad

pg->phys_addr -> VM_PAGE_TO_PHYS(pg)


Revision tags: phil-wifi-20191119
# 1.50 14-Nov-2019 maxv

Mark several kASan functions with __nothing, to avoid annoying #ifdefs.
Same as kCSan and kMSan.


# 1.49 14-Nov-2019 maxv

Don't include "opt_kasan.h" when there's already <sys/asan.h> included.


# 1.48 29-Oct-2019 maya

Define PMAP_NEED_PROCWR, providing strategically placed i-cache
synchronization where just-changed memory is about to be executed.

Fixes SIGILLs seen when running Mono 6 on QEMU Cortex-A57.

ok ryo


# 1.47 22-Sep-2019 jmcneill

Disable translation table walks using TTBR0 while changing its value and
when deactivating a pmap. Fixes stability issues on Ampere eMAG CPUs.


# 1.46 20-Sep-2019 ryo

ref/mod bit should be set according to 'flags' argument, not 'prot'. r1.44 was incomplete.


# 1.45 13-Sep-2019 ryo

In pmap_devmap_bootstrap(), cpu_earlydevice_va_p() must not return true until *all* devmap tables have been enabled.
console mapping may be present in the last table.


# 1.44 07-Sep-2019 ryo

- remove incorrect KASSERT. mmap(2) with prot=PROT_WRITE calls pmap_enter(..., PROT_WRITE) internally.
- fix to update page reference flags when only PROT_WRITE or PROT_EXECUTE specified


# 1.43 15-Aug-2019 skrll

Make pmap_db_pte_print more terse so it's quicker on serial consoles


# 1.42 12-Aug-2019 skrll

Use PMAP_DEV in DEVMAP_ENTRY rather than pmap_map_chunk. It's clearer and
means pmap_map_chunk can be made to map other memory types.


Revision tags: netbsd-9-base phil-wifi-20190609
# 1.41 17-May-2019 mrg

branches: 1.41.2;
apply some __diagused.


Revision tags: isaki-audio2-base
# 1.40 08-Apr-2019 ryo

- free empty page tables pages if reach a certain usage.
- need to lock at removing an old pg (_pmap_remove_pv) in _pmap_enter()


# 1.39 06-Apr-2019 ryo

Fix race conditions about pmap_page_protect() and pmap_enter().

while handling same PTE by these functions in same time, there
is a critical path that the number of valid PTEs and wire_count
are inconsistent, and it caused KASSERT.
Need to hold a pv_lock while modifying them.


# 1.38 20-Mar-2019 ryo

spinkle __printflike(), and use PRIxxx


# 1.37 19-Mar-2019 ryo

- add ddb command "machine ttbr" to dump MMU tables.
- tidy up descriptions, usages and messages.


# 1.36 19-Mar-2019 ryo

- free L1-L3 pages that has been emptied by pmap_remove().
- if no memories, pmap_enter will return correctly ENOMEM if PMAP_CANFAIL, or wait until available any memories if !PMAP_CANFAIL.

These changes improves the stability when we use a huge virtual memory spaces with mmap.


# 1.35 06-Feb-2019 ryo

improve pmap_remove
- don't lock/unlock per page in pmap_remove()
- speedup pte lookup for continuous addresses
- bring out pool_cache_put(&_pmap_pv_pool, pv) from lock/unlock section


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226
# 1.34 21-Dec-2018 ryo

- add workaround for Cavium ThunderX errata 27456.
- add cpufuncs table in cpu_info. each cpu clusters may have different erratum. (e.g. big.LITTLE)


Revision tags: pgoyette-compat-1126
# 1.33 01-Nov-2018 maxv

Add kASan support for aarch64. Stack tracking needs more investigation
and will come in a separate commit.

Reviewed by ryo@ jmcneill@ skrll@.


# 1.32 31-Oct-2018 ryo

invalidate icache correctly.
l3pte_executable() should be used for only valid pte.


Revision tags: pgoyette-compat-1020
# 1.31 18-Oct-2018 skrll

Provide generic start code that assumes the MMU is off and caches are
disabled as per the linux booting protocol for ARMv6 and ARMv7 boards.
u-boot image type should be changed to 'linux' for correct behaviour.

The new start code builds a minimal "bootstrap" L1PT with cached access
disabled and uses the same table for all processors. AP startup is
performed in less steps and more code is written in C.

The bootstrap tables and stack are placed into an (orphaned) section
"_init_memory" which is given to uvm when it is no longer used.

Various kernels have been converted to use this code and tested. Some
boards were provided by TNF. Thanks!

The GENERIC kernel now boots on boards using the TEGRA, SUNXI and EXYNOS
kernels. The GENERIC kernel will also work on RPI2 using u-boot.

Thanks to martin@ and aymeric@ for testing on parallella and nanosoc
respectively


# 1.30 14-Oct-2018 skrll

Use __nothing


# 1.29 12-Oct-2018 ryo

add initial support of COMPAT_NETBSD32 on AArch64.
arm ELF32 EABI binaries could be execute in AArch32 state on AArch64. A32 THUMB mode is not supported yet.


# 1.28 12-Oct-2018 ryo

- cleanup checking address ranges with IN_RANGE macro
- change PM_ADDR_CHECK macro to KASSERTMSG
- restore fast lookup cases with IN_RANGE macro for pmap_extract changed in my previous commit.


# 1.27 12-Oct-2018 ryo

rewrite pmap_pte_lookup() to share similar code.


# 1.26 04-Oct-2018 ryo

cleanup locore, and changed the way to map memories during boot.
- add functions bootpage_enter() and bootpage_alloc() to adapt various layout
of physical memory map. especially for 64bit physical memory layout.
pmapboot_alloc() allocates pagetable pages from _end[].
- changed to map only the required amount for PA=VA identity mapping
(kernel image, UART device, and FDT blob) with L2_BLOCK(2Mbyte).
- changing page permission for kernel image, and making KSEG mapping are done
at cpu_kernel_vm_init() instead of at locore.
- optimize PTE entries with PTE Contiguous bit. it is enabled on devmap only for now.

reviewed by skrll@, thanks.


# 1.25 04-Oct-2018 ryo

* define LX_BLKPAG_{OS,ATTR}_* for OS dependent PTE attributes in pmap.h
* cleanup macros


Revision tags: pgoyette-compat-0930
# 1.24 17-Sep-2018 ryo

delete debug printf and KASSERT.


# 1.23 10-Sep-2018 maxv

Replace KDASSERT by panic.


# 1.22 10-Sep-2018 maxv

Rename _pmap_alloc_pdp -> pmap_alloc_pdp, and make it public.


# 1.21 10-Sep-2018 ryo

cleanup aarch64 mpstart and fdt bootstrap
* arm_cpu_hatch_arg is a bad idea. avoid serializing CPU startup, and eliminate arm_cpu_hatch_arg.
in mpstart, resolve own cpu index using array of cpu_mpidr[] (aarch64)
* add support fdt enable-method "spin-table"
* add support fdt enable-method "brcm,bcm2836-smp" (for 32bit RaspberryPi)
* use arm_fdt_cpu_bootstrap() instead of psci_fdt_bootstrap()
* rename "arm/fdt/psci_fdt.h" to "arm/fdt/psci_fdtvar.h" because of conflict of include file for needs-flag
* add devmap for cpu spin-table of raspberrypi3/aarch64
* no need to force hatch APs for raspberrypi3/arm32 ifndef MULTIPROCESSOR.
* fix to work pmap_extract(kerneltext/data/bss) even if before calling pmap_bootstrap

idea to use cpu_mpidr[] by jmcneill@. reviewd by skrll@. thanks.


Revision tags: pgoyette-compat-0906
# 1.20 27-Aug-2018 ryo

need to add VM_PROT_READ when pmap_kenter_pa(va, pa, VM_PROT_WRITE, 0) or pmap_kenter_pa(va, pa, VM_PROT_EXECUTE, 0).
VM_PROT_READ is treated as an access permission inernally.


# 1.19 11-Aug-2018 ryo

change to minimum invalidation of TLB.
specifying not only va but also asid, and not invalidate L0-L2 entry using tlbi_*_ll() if needed.


# 1.18 10-Aug-2018 ryo

treat kernel-exec attr and user-exec attr separately.
kernel cannot execute userland exec page, and user cannot execute kernel page.


# 1.17 06-Aug-2018 ryo

set kernel text/rodata readonly by default.
add function db_write_text() for setting ddb breakpoint.


# 1.16 31-Jul-2018 skrll

Define and use VPRINTF


Revision tags: pgoyette-compat-0728
# 1.15 27-Jul-2018 ryo

changes of pmap.c r1.13 seems to be unstable.
In order to invalidate icache, not to invalidate all icache,
but temporary to make the page writable and invalidate target address only.


# 1.14 24-Jul-2018 ryo

don't call pool_cache_put with locking pmap. pool_cache_put call pmap_kenter_pa internally.
(pool_cache_put_paddr -> pool_cache_put_slow -> pool_get -> pmap_kenter_pa)


# 1.13 23-Jul-2018 ryo

* fix icache invalidations.
* "ic ivau" (aarch64_icache_sync_range) with VA generates permission fault in some situations, therefore use KSEG address for now.


# 1.12 23-Jul-2018 ryo

rather than using flags to resolve nested locks, reserve pool_cache before locking.


# 1.11 21-Jul-2018 ryo

* avoid deadlock. mutex_owned() works only for adaptive lock, therefore we cannot use it for spinlock...
* add more NULL check
* clear pte when pmap_enter() fails


# 1.10 17-Jul-2018 ryo

Use __debugused


# 1.9 17-Jul-2018 christos

Add missing casts, remove unused variables.


# 1.8 09-Jul-2018 ryo

need locks in pmap_kremove() and pmap_fault_fixup()


Revision tags: phil-wifi-base pgoyette-compat-0625 pgoyette-compat-0521
# 1.7 20-May-2018 ryo

branches: 1.7.2;
pmap_enter() must update modified/referenced flags by 'flags' not 'prot'.


# 1.6 16-May-2018 ryo

Fix memory leak. it was leaking one page every pmap_create().
pm->pm_vmlist must be initialized before calling _pmap_alloc_pdp().


Revision tags: pgoyette-compat-0502
# 1.5 29-Apr-2018 ryo

fix KASSERT panic. pv_entry may not be exists in pvlist when pmap_remove().


# 1.4 29-Apr-2018 ryo

delete unused code


# 1.3 27-Apr-2018 ryo

fix instability behavior of bufcache on aarch64.
* fix to return correct ref/mod when PMAP_WIRED.
* changed to keep wired flags in pte instead of pv_entry, and cleanup.


Revision tags: pgoyette-compat-0422 pgoyette-compat-0415 pgoyette-compat-0407
# 1.2 01-Apr-2018 ryo

Add initial support for ARMv8 (AARCH64) (by nisimura@ and ryo@)

- sys/arch/evbarm64 is gone and integrated into sys/arch/evbarm. (by skrll@)
- add support fdt. evbarm/conf/GENERIC64 fdt (bcm2837,sunxi,tegra) based generic 64bit kernel config. (by skrll@, jmcneill@)


Revision tags: netbsd-8-2-RELEASE netbsd-8-1-RELEASE netbsd-8-1-RC1 netbsd-7-2-RELEASE netbsd-8-0-RELEASE netbsd-8-0-RC2 netbsd-8-0-RC1 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 netbsd-7-1-2-RELEASE pgoyette-compat-base netbsd-7-1-1-RELEASE tls-maxphys-base-20171202 matt-nb8-mediatek-base nick-nhusb-base-20170825 perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base pgoyette-localcount-20170320 netbsd-7-1-RELEASE netbsd-7-1-RC2 nick-nhusb-base-20170204 netbsd-7-nhusb-base-20170116 bouyer-socketcan-base pgoyette-localcount-20170107 netbsd-7-1-RC1 nick-nhusb-base-20161204 pgoyette-localcount-20161104 netbsd-7-0-2-RELEASE nick-nhusb-base-20161004 localcount-20160914 netbsd-7-nhusb-base pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907 nick-nhusb-base-20160529 netbsd-7-0-1-RELEASE nick-nhusb-base-20160422 nick-nhusb-base-20160319 nick-nhusb-base-20151226 netbsd-7-0-RELEASE nick-nhusb-base-20150921 netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 nick-nhusb-base-20150606 nick-nhusb-base-20150406 nick-nhusb-base tls-maxphys-base netbsd-7-base
# 1.1 10-Aug-2014 matt

branches: 1.1.4; 1.1.28;
Preliminary files for AARCH64 (64-bit ARM) support.
Enough for a distribution build.


# 1.68 14-Mar-2020 ad

pmap_remove_all(): Return a boolean value to indicate the behaviour. If
true, all mappings have been removed, the pmap is totally cleared out, and
UVM can then avoid doing the work to call pmap_remove() for each map entry.
If false, either nothing has been done, or some helpful arch-specific voodoo
has taken place.


# 1.67 02-Mar-2020 ryo

oops, fix incorrect usage of daif_enable() in my previous commit.


# 1.66 29-Feb-2020 ryo

Fix pmap to work correctly with tagged addresses

- when fault, untag from address before passing to uvm/pmap functions
- pmap_extract() checks more strictly and consider the address tag


# 1.65 29-Feb-2020 ryo

use pmapboot_enter_range()


Revision tags: ad-namecache-base3
# 1.64 10-Feb-2020 ryo

use LIST(3) instead of TAILQ(3) to save one word in struct vm_page and struct pmap.

pointed out by riastradh@. thanks


# 1.63 03-Feb-2020 ryo

add support pmap_pv(9)

Patch originally from jmcneill@. thanks


# 1.62 03-Feb-2020 ryo

separate struct vm_page_md into vm_page_md and pmap_page
for preparation pmap_pv(9)


Revision tags: ad-namecache-base2 ad-namecache-base1
# 1.61 09-Jan-2020 ryo

fix behaviour mmap()/mprotect() when passed only PROT_EXEC.

when mmap()/mprotect() with only PROT_EXEC, syscall will be successful,
but the page actually hadn't been mapped.
it should be mapped with PROT_READ|PROT_EXEC implicitly. (r-x)


Revision tags: ad-namecache-base
# 1.60 30-Dec-2019 skrll

branches: 1.60.2;
Update pmap_map_chunk to allow L[12] block mappings and L3 page mappings


# 1.59 30-Dec-2019 skrll

Remove unnecessary brackets and unwrap a conditional. Same code before
and after.


# 1.58 28-Dec-2019 jmcneill

Do not use Early Write Acknowledge for PCIe I/O and config space.


# 1.57 27-Dec-2019 jmcneill

Enable early write acknowledge for device memory mappings.


# 1.56 19-Dec-2019 skrll

G/C kasan_shadow_map call in pmap_enter

pmap_growkernel calls kasan_shadow_map for KVA


# 1.55 18-Dec-2019 ryo

atomic_add_16() is not used in pmap.c anymore. no need decl here.


# 1.54 18-Dec-2019 ryo

space to tab


# 1.53 14-Dec-2019 skrll

Fix build... wire_count probably doesn't need atomics


# 1.52 13-Dec-2019 skrll

Fix KASAN support by calling kasan_shadow_map in pmap_growkernel


# 1.51 10-Dec-2019 ad

pg->phys_addr -> VM_PAGE_TO_PHYS(pg)


Revision tags: phil-wifi-20191119
# 1.50 14-Nov-2019 maxv

Mark several kASan functions with __nothing, to avoid annoying #ifdefs.
Same as kCSan and kMSan.


# 1.49 14-Nov-2019 maxv

Don't include "opt_kasan.h" when there's already <sys/asan.h> included.


# 1.48 29-Oct-2019 maya

Define PMAP_NEED_PROCWR, providing strategically placed i-cache
synchronization where just-changed memory is about to be executed.

Fixes SIGILLs seen when running Mono 6 on QEMU Cortex-A57.

ok ryo


# 1.47 22-Sep-2019 jmcneill

Disable translation table walks using TTBR0 while changing its value and
when deactivating a pmap. Fixes stability issues on Ampere eMAG CPUs.


# 1.46 20-Sep-2019 ryo

ref/mod bit should be set according to 'flags' argument, not 'prot'. r1.44 was incomplete.


# 1.45 13-Sep-2019 ryo

In pmap_devmap_bootstrap(), cpu_earlydevice_va_p() must not return true until *all* devmap tables have been enabled.
console mapping may be present in the last table.


# 1.44 07-Sep-2019 ryo

- remove incorrect KASSERT. mmap(2) with prot=PROT_WRITE calls pmap_enter(..., PROT_WRITE) internally.
- fix to update page reference flags when only PROT_WRITE or PROT_EXECUTE specified


# 1.43 15-Aug-2019 skrll

Make pmap_db_pte_print more terse so it's quicker on serial consoles


# 1.42 12-Aug-2019 skrll

Use PMAP_DEV in DEVMAP_ENTRY rather than pmap_map_chunk. It's clearer and
means pmap_map_chunk can be made to map other memory types.


Revision tags: netbsd-9-base phil-wifi-20190609
# 1.41 17-May-2019 mrg

branches: 1.41.2;
apply some __diagused.


Revision tags: isaki-audio2-base
# 1.40 08-Apr-2019 ryo

- free empty page tables pages if reach a certain usage.
- need to lock at removing an old pg (_pmap_remove_pv) in _pmap_enter()


# 1.39 06-Apr-2019 ryo

Fix race conditions about pmap_page_protect() and pmap_enter().

while handling same PTE by these functions in same time, there
is a critical path that the number of valid PTEs and wire_count
are inconsistent, and it caused KASSERT.
Need to hold a pv_lock while modifying them.


# 1.38 20-Mar-2019 ryo

spinkle __printflike(), and use PRIxxx


# 1.37 19-Mar-2019 ryo

- add ddb command "machine ttbr" to dump MMU tables.
- tidy up descriptions, usages and messages.


# 1.36 19-Mar-2019 ryo

- free L1-L3 pages that has been emptied by pmap_remove().
- if no memories, pmap_enter will return correctly ENOMEM if PMAP_CANFAIL, or wait until available any memories if !PMAP_CANFAIL.

These changes improves the stability when we use a huge virtual memory spaces with mmap.


# 1.35 06-Feb-2019 ryo

improve pmap_remove
- don't lock/unlock per page in pmap_remove()
- speedup pte lookup for continuous addresses
- bring out pool_cache_put(&_pmap_pv_pool, pv) from lock/unlock section


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226
# 1.34 21-Dec-2018 ryo

- add workaround for Cavium ThunderX errata 27456.
- add cpufuncs table in cpu_info. each cpu clusters may have different erratum. (e.g. big.LITTLE)


Revision tags: pgoyette-compat-1126
# 1.33 01-Nov-2018 maxv

Add kASan support for aarch64. Stack tracking needs more investigation
and will come in a separate commit.

Reviewed by ryo@ jmcneill@ skrll@.


# 1.32 31-Oct-2018 ryo

invalidate icache correctly.
l3pte_executable() should be used for only valid pte.


Revision tags: pgoyette-compat-1020
# 1.31 18-Oct-2018 skrll

Provide generic start code that assumes the MMU is off and caches are
disabled as per the linux booting protocol for ARMv6 and ARMv7 boards.
u-boot image type should be changed to 'linux' for correct behaviour.

The new start code builds a minimal "bootstrap" L1PT with cached access
disabled and uses the same table for all processors. AP startup is
performed in less steps and more code is written in C.

The bootstrap tables and stack are placed into an (orphaned) section
"_init_memory" which is given to uvm when it is no longer used.

Various kernels have been converted to use this code and tested. Some
boards were provided by TNF. Thanks!

The GENERIC kernel now boots on boards using the TEGRA, SUNXI and EXYNOS
kernels. The GENERIC kernel will also work on RPI2 using u-boot.

Thanks to martin@ and aymeric@ for testing on parallella and nanosoc
respectively


# 1.30 14-Oct-2018 skrll

Use __nothing


# 1.29 12-Oct-2018 ryo

add initial support of COMPAT_NETBSD32 on AArch64.
arm ELF32 EABI binaries could be execute in AArch32 state on AArch64. A32 THUMB mode is not supported yet.


# 1.28 12-Oct-2018 ryo

- cleanup checking address ranges with IN_RANGE macro
- change PM_ADDR_CHECK macro to KASSERTMSG
- restore fast lookup cases with IN_RANGE macro for pmap_extract changed in my previous commit.


# 1.27 12-Oct-2018 ryo

rewrite pmap_pte_lookup() to share similar code.


# 1.26 04-Oct-2018 ryo

cleanup locore, and changed the way to map memories during boot.
- add functions bootpage_enter() and bootpage_alloc() to adapt various layout
of physical memory map. especially for 64bit physical memory layout.
pmapboot_alloc() allocates pagetable pages from _end[].
- changed to map only the required amount for PA=VA identity mapping
(kernel image, UART device, and FDT blob) with L2_BLOCK(2Mbyte).
- changing page permission for kernel image, and making KSEG mapping are done
at cpu_kernel_vm_init() instead of at locore.
- optimize PTE entries with PTE Contiguous bit. it is enabled on devmap only for now.

reviewed by skrll@, thanks.


# 1.25 04-Oct-2018 ryo

* define LX_BLKPAG_{OS,ATTR}_* for OS dependent PTE attributes in pmap.h
* cleanup macros


Revision tags: pgoyette-compat-0930
# 1.24 17-Sep-2018 ryo

delete debug printf and KASSERT.


# 1.23 10-Sep-2018 maxv

Replace KDASSERT by panic.


# 1.22 10-Sep-2018 maxv

Rename _pmap_alloc_pdp -> pmap_alloc_pdp, and make it public.


# 1.21 10-Sep-2018 ryo

cleanup aarch64 mpstart and fdt bootstrap
* arm_cpu_hatch_arg is a bad idea. avoid serializing CPU startup, and eliminate arm_cpu_hatch_arg.
in mpstart, resolve own cpu index using array of cpu_mpidr[] (aarch64)
* add support fdt enable-method "spin-table"
* add support fdt enable-method "brcm,bcm2836-smp" (for 32bit RaspberryPi)
* use arm_fdt_cpu_bootstrap() instead of psci_fdt_bootstrap()
* rename "arm/fdt/psci_fdt.h" to "arm/fdt/psci_fdtvar.h" because of conflict of include file for needs-flag
* add devmap for cpu spin-table of raspberrypi3/aarch64
* no need to force hatch APs for raspberrypi3/arm32 ifndef MULTIPROCESSOR.
* fix to work pmap_extract(kerneltext/data/bss) even if before calling pmap_bootstrap

idea to use cpu_mpidr[] by jmcneill@. reviewd by skrll@. thanks.


Revision tags: pgoyette-compat-0906
# 1.20 27-Aug-2018 ryo

need to add VM_PROT_READ when pmap_kenter_pa(va, pa, VM_PROT_WRITE, 0) or pmap_kenter_pa(va, pa, VM_PROT_EXECUTE, 0).
VM_PROT_READ is treated as an access permission inernally.


# 1.19 11-Aug-2018 ryo

change to minimum invalidation of TLB.
specifying not only va but also asid, and not invalidate L0-L2 entry using tlbi_*_ll() if needed.


# 1.18 10-Aug-2018 ryo

treat kernel-exec attr and user-exec attr separately.
kernel cannot execute userland exec page, and user cannot execute kernel page.


# 1.17 06-Aug-2018 ryo

set kernel text/rodata readonly by default.
add function db_write_text() for setting ddb breakpoint.


# 1.16 31-Jul-2018 skrll

Define and use VPRINTF


Revision tags: pgoyette-compat-0728
# 1.15 27-Jul-2018 ryo

changes of pmap.c r1.13 seems to be unstable.
In order to invalidate icache, not to invalidate all icache,
but temporary to make the page writable and invalidate target address only.


# 1.14 24-Jul-2018 ryo

don't call pool_cache_put with locking pmap. pool_cache_put call pmap_kenter_pa internally.
(pool_cache_put_paddr -> pool_cache_put_slow -> pool_get -> pmap_kenter_pa)


# 1.13 23-Jul-2018 ryo

* fix icache invalidations.
* "ic ivau" (aarch64_icache_sync_range) with VA generates permission fault in some situations, therefore use KSEG address for now.


# 1.12 23-Jul-2018 ryo

rather than using flags to resolve nested locks, reserve pool_cache before locking.


# 1.11 21-Jul-2018 ryo

* avoid deadlock. mutex_owned() works only for adaptive lock, therefore we cannot use it for spinlock...
* add more NULL check
* clear pte when pmap_enter() fails


# 1.10 17-Jul-2018 ryo

Use __debugused


# 1.9 17-Jul-2018 christos

Add missing casts, remove unused variables.


# 1.8 09-Jul-2018 ryo

need locks in pmap_kremove() and pmap_fault_fixup()


Revision tags: phil-wifi-base pgoyette-compat-0625 pgoyette-compat-0521
# 1.7 20-May-2018 ryo

branches: 1.7.2;
pmap_enter() must update modified/referenced flags by 'flags' not 'prot'.


# 1.6 16-May-2018 ryo

Fix memory leak. it was leaking one page every pmap_create().
pm->pm_vmlist must be initialized before calling _pmap_alloc_pdp().


Revision tags: pgoyette-compat-0502
# 1.5 29-Apr-2018 ryo

fix KASSERT panic. pv_entry may not be exists in pvlist when pmap_remove().


# 1.4 29-Apr-2018 ryo

delete unused code


# 1.3 27-Apr-2018 ryo

fix instability behavior of bufcache on aarch64.
* fix to return correct ref/mod when PMAP_WIRED.
* changed to keep wired flags in pte instead of pv_entry, and cleanup.


Revision tags: pgoyette-compat-0422 pgoyette-compat-0415 pgoyette-compat-0407
# 1.2 01-Apr-2018 ryo

Add initial support for ARMv8 (AARCH64) (by nisimura@ and ryo@)

- sys/arch/evbarm64 is gone and integrated into sys/arch/evbarm. (by skrll@)
- add support fdt. evbarm/conf/GENERIC64 fdt (bcm2837,sunxi,tegra) based generic 64bit kernel config. (by skrll@, jmcneill@)


Revision tags: netbsd-8-1-RELEASE netbsd-8-1-RC1 netbsd-7-2-RELEASE netbsd-8-0-RELEASE netbsd-8-0-RC2 netbsd-8-0-RC1 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 netbsd-7-1-2-RELEASE pgoyette-compat-base netbsd-7-1-1-RELEASE tls-maxphys-base-20171202 matt-nb8-mediatek-base nick-nhusb-base-20170825 perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base pgoyette-localcount-20170320 netbsd-7-1-RELEASE netbsd-7-1-RC2 nick-nhusb-base-20170204 netbsd-7-nhusb-base-20170116 bouyer-socketcan-base pgoyette-localcount-20170107 netbsd-7-1-RC1 nick-nhusb-base-20161204 pgoyette-localcount-20161104 netbsd-7-0-2-RELEASE nick-nhusb-base-20161004 localcount-20160914 netbsd-7-nhusb-base pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907 nick-nhusb-base-20160529 netbsd-7-0-1-RELEASE nick-nhusb-base-20160422 nick-nhusb-base-20160319 nick-nhusb-base-20151226 netbsd-7-0-RELEASE nick-nhusb-base-20150921 netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 nick-nhusb-base-20150606 nick-nhusb-base-20150406 nick-nhusb-base tls-maxphys-base netbsd-7-base
# 1.1 10-Aug-2014 matt

branches: 1.1.4; 1.1.28;
Preliminary files for AARCH64 (64-bit ARM) support.
Enough for a distribution build.


# 1.67 02-Mar-2020 ryo

oops, fix incorrect usage of daif_enable() in my previous commit.


# 1.66 29-Feb-2020 ryo

Fix pmap to work correctly with tagged addresses

- when fault, untag from address before passing to uvm/pmap functions
- pmap_extract() checks more strictly and consider the address tag


# 1.65 29-Feb-2020 ryo

use pmapboot_enter_range()


Revision tags: ad-namecache-base3
# 1.64 10-Feb-2020 ryo

use LIST(3) instead of TAILQ(3) to save one word in struct vm_page and struct pmap.

pointed out by riastradh@. thanks


# 1.63 03-Feb-2020 ryo

add support pmap_pv(9)

Patch originally from jmcneill@. thanks


# 1.62 03-Feb-2020 ryo

separate struct vm_page_md into vm_page_md and pmap_page
for preparation pmap_pv(9)


Revision tags: ad-namecache-base2 ad-namecache-base1
# 1.61 09-Jan-2020 ryo

fix behaviour mmap()/mprotect() when passed only PROT_EXEC.

when mmap()/mprotect() with only PROT_EXEC, syscall will be successful,
but the page actually hadn't been mapped.
it should be mapped with PROT_READ|PROT_EXEC implicitly. (r-x)


Revision tags: ad-namecache-base
# 1.60 30-Dec-2019 skrll

branches: 1.60.2;
Update pmap_map_chunk to allow L[12] block mappings and L3 page mappings


# 1.59 30-Dec-2019 skrll

Remove unnecessary brackets and unwrap a conditional. Same code before
and after.


# 1.58 28-Dec-2019 jmcneill

Do not use Early Write Acknowledge for PCIe I/O and config space.


# 1.57 27-Dec-2019 jmcneill

Enable early write acknowledge for device memory mappings.


# 1.56 19-Dec-2019 skrll

G/C kasan_shadow_map call in pmap_enter

pmap_growkernel calls kasan_shadow_map for KVA


# 1.55 18-Dec-2019 ryo

atomic_add_16() is not used in pmap.c anymore. no need decl here.


# 1.54 18-Dec-2019 ryo

space to tab


# 1.53 14-Dec-2019 skrll

Fix build... wire_count probably doesn't need atomics


# 1.52 13-Dec-2019 skrll

Fix KASAN support by calling kasan_shadow_map in pmap_growkernel


# 1.51 10-Dec-2019 ad

pg->phys_addr -> VM_PAGE_TO_PHYS(pg)


Revision tags: phil-wifi-20191119
# 1.50 14-Nov-2019 maxv

Mark several kASan functions with __nothing, to avoid annoying #ifdefs.
Same as kCSan and kMSan.


# 1.49 14-Nov-2019 maxv

Don't include "opt_kasan.h" when there's already <sys/asan.h> included.


# 1.48 29-Oct-2019 maya

Define PMAP_NEED_PROCWR, providing strategically placed i-cache
synchronization where just-changed memory is about to be executed.

Fixes SIGILLs seen when running Mono 6 on QEMU Cortex-A57.

ok ryo


# 1.47 22-Sep-2019 jmcneill

Disable translation table walks using TTBR0 while changing its value and
when deactivating a pmap. Fixes stability issues on Ampere eMAG CPUs.


# 1.46 20-Sep-2019 ryo

ref/mod bit should be set according to 'flags' argument, not 'prot'. r1.44 was incomplete.


# 1.45 13-Sep-2019 ryo

In pmap_devmap_bootstrap(), cpu_earlydevice_va_p() must not return true until *all* devmap tables have been enabled.
console mapping may be present in the last table.


# 1.44 07-Sep-2019 ryo

- remove incorrect KASSERT. mmap(2) with prot=PROT_WRITE calls pmap_enter(..., PROT_WRITE) internally.
- fix to update page reference flags when only PROT_WRITE or PROT_EXECUTE specified


# 1.43 15-Aug-2019 skrll

Make pmap_db_pte_print more terse so it's quicker on serial consoles


# 1.42 12-Aug-2019 skrll

Use PMAP_DEV in DEVMAP_ENTRY rather than pmap_map_chunk. It's clearer and
means pmap_map_chunk can be made to map other memory types.


Revision tags: netbsd-9-base phil-wifi-20190609
# 1.41 17-May-2019 mrg

branches: 1.41.2;
apply some __diagused.


Revision tags: isaki-audio2-base
# 1.40 08-Apr-2019 ryo

- free empty page tables pages if reach a certain usage.
- need to lock at removing an old pg (_pmap_remove_pv) in _pmap_enter()


# 1.39 06-Apr-2019 ryo

Fix race conditions about pmap_page_protect() and pmap_enter().

while handling same PTE by these functions in same time, there
is a critical path that the number of valid PTEs and wire_count
are inconsistent, and it caused KASSERT.
Need to hold a pv_lock while modifying them.


# 1.38 20-Mar-2019 ryo

spinkle __printflike(), and use PRIxxx


# 1.37 19-Mar-2019 ryo

- add ddb command "machine ttbr" to dump MMU tables.
- tidy up descriptions, usages and messages.


# 1.36 19-Mar-2019 ryo

- free L1-L3 pages that has been emptied by pmap_remove().
- if no memories, pmap_enter will return correctly ENOMEM if PMAP_CANFAIL, or wait until available any memories if !PMAP_CANFAIL.

These changes improves the stability when we use a huge virtual memory spaces with mmap.


# 1.35 06-Feb-2019 ryo

improve pmap_remove
- don't lock/unlock per page in pmap_remove()
- speedup pte lookup for continuous addresses
- bring out pool_cache_put(&_pmap_pv_pool, pv) from lock/unlock section


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226
# 1.34 21-Dec-2018 ryo

- add workaround for Cavium ThunderX errata 27456.
- add cpufuncs table in cpu_info. each cpu clusters may have different erratum. (e.g. big.LITTLE)


Revision tags: pgoyette-compat-1126
# 1.33 01-Nov-2018 maxv

Add kASan support for aarch64. Stack tracking needs more investigation
and will come in a separate commit.

Reviewed by ryo@ jmcneill@ skrll@.


# 1.32 31-Oct-2018 ryo

invalidate icache correctly.
l3pte_executable() should be used for only valid pte.


Revision tags: pgoyette-compat-1020
# 1.31 18-Oct-2018 skrll

Provide generic start code that assumes the MMU is off and caches are
disabled as per the linux booting protocol for ARMv6 and ARMv7 boards.
u-boot image type should be changed to 'linux' for correct behaviour.

The new start code builds a minimal "bootstrap" L1PT with cached access
disabled and uses the same table for all processors. AP startup is
performed in less steps and more code is written in C.

The bootstrap tables and stack are placed into an (orphaned) section
"_init_memory" which is given to uvm when it is no longer used.

Various kernels have been converted to use this code and tested. Some
boards were provided by TNF. Thanks!

The GENERIC kernel now boots on boards using the TEGRA, SUNXI and EXYNOS
kernels. The GENERIC kernel will also work on RPI2 using u-boot.

Thanks to martin@ and aymeric@ for testing on parallella and nanosoc
respectively


# 1.30 14-Oct-2018 skrll

Use __nothing


# 1.29 12-Oct-2018 ryo

add initial support of COMPAT_NETBSD32 on AArch64.
arm ELF32 EABI binaries could be execute in AArch32 state on AArch64. A32 THUMB mode is not supported yet.


# 1.28 12-Oct-2018 ryo

- cleanup checking address ranges with IN_RANGE macro
- change PM_ADDR_CHECK macro to KASSERTMSG
- restore fast lookup cases with IN_RANGE macro for pmap_extract changed in my previous commit.


# 1.27 12-Oct-2018 ryo

rewrite pmap_pte_lookup() to share similar code.


# 1.26 04-Oct-2018 ryo

cleanup locore, and changed the way to map memories during boot.
- add functions bootpage_enter() and bootpage_alloc() to adapt various layout
of physical memory map. especially for 64bit physical memory layout.
pmapboot_alloc() allocates pagetable pages from _end[].
- changed to map only the required amount for PA=VA identity mapping
(kernel image, UART device, and FDT blob) with L2_BLOCK(2Mbyte).
- changing page permission for kernel image, and making KSEG mapping are done
at cpu_kernel_vm_init() instead of at locore.
- optimize PTE entries with PTE Contiguous bit. it is enabled on devmap only for now.

reviewed by skrll@, thanks.


# 1.25 04-Oct-2018 ryo

* define LX_BLKPAG_{OS,ATTR}_* for OS dependent PTE attributes in pmap.h
* cleanup macros


Revision tags: pgoyette-compat-0930
# 1.24 17-Sep-2018 ryo

delete debug printf and KASSERT.


# 1.23 10-Sep-2018 maxv

Replace KDASSERT by panic.


# 1.22 10-Sep-2018 maxv

Rename _pmap_alloc_pdp -> pmap_alloc_pdp, and make it public.


# 1.21 10-Sep-2018 ryo

cleanup aarch64 mpstart and fdt bootstrap
* arm_cpu_hatch_arg is a bad idea. avoid serializing CPU startup, and eliminate arm_cpu_hatch_arg.
in mpstart, resolve own cpu index using array of cpu_mpidr[] (aarch64)
* add support fdt enable-method "spin-table"
* add support fdt enable-method "brcm,bcm2836-smp" (for 32bit RaspberryPi)
* use arm_fdt_cpu_bootstrap() instead of psci_fdt_bootstrap()
* rename "arm/fdt/psci_fdt.h" to "arm/fdt/psci_fdtvar.h" because of conflict of include file for needs-flag
* add devmap for cpu spin-table of raspberrypi3/aarch64
* no need to force hatch APs for raspberrypi3/arm32 ifndef MULTIPROCESSOR.
* fix to work pmap_extract(kerneltext/data/bss) even if before calling pmap_bootstrap

idea to use cpu_mpidr[] by jmcneill@. reviewd by skrll@. thanks.


Revision tags: pgoyette-compat-0906
# 1.20 27-Aug-2018 ryo

need to add VM_PROT_READ when pmap_kenter_pa(va, pa, VM_PROT_WRITE, 0) or pmap_kenter_pa(va, pa, VM_PROT_EXECUTE, 0).
VM_PROT_READ is treated as an access permission inernally.


# 1.19 11-Aug-2018 ryo

change to minimum invalidation of TLB.
specifying not only va but also asid, and not invalidate L0-L2 entry using tlbi_*_ll() if needed.


# 1.18 10-Aug-2018 ryo

treat kernel-exec attr and user-exec attr separately.
kernel cannot execute userland exec page, and user cannot execute kernel page.


# 1.17 06-Aug-2018 ryo

set kernel text/rodata readonly by default.
add function db_write_text() for setting ddb breakpoint.


# 1.16 31-Jul-2018 skrll

Define and use VPRINTF


Revision tags: pgoyette-compat-0728
# 1.15 27-Jul-2018 ryo

changes of pmap.c r1.13 seems to be unstable.
In order to invalidate icache, not to invalidate all icache,
but temporary to make the page writable and invalidate target address only.


# 1.14 24-Jul-2018 ryo

don't call pool_cache_put with locking pmap. pool_cache_put call pmap_kenter_pa internally.
(pool_cache_put_paddr -> pool_cache_put_slow -> pool_get -> pmap_kenter_pa)


# 1.13 23-Jul-2018 ryo

* fix icache invalidations.
* "ic ivau" (aarch64_icache_sync_range) with VA generates permission fault in some situations, therefore use KSEG address for now.


# 1.12 23-Jul-2018 ryo

rather than using flags to resolve nested locks, reserve pool_cache before locking.


# 1.11 21-Jul-2018 ryo

* avoid deadlock. mutex_owned() works only for adaptive lock, therefore we cannot use it for spinlock...
* add more NULL check
* clear pte when pmap_enter() fails


# 1.10 17-Jul-2018 ryo

Use __debugused


# 1.9 17-Jul-2018 christos

Add missing casts, remove unused variables.


# 1.8 09-Jul-2018 ryo

need locks in pmap_kremove() and pmap_fault_fixup()


Revision tags: phil-wifi-base pgoyette-compat-0625 pgoyette-compat-0521
# 1.7 20-May-2018 ryo

branches: 1.7.2;
pmap_enter() must update modified/referenced flags by 'flags' not 'prot'.


# 1.6 16-May-2018 ryo

Fix memory leak. it was leaking one page every pmap_create().
pm->pm_vmlist must be initialized before calling _pmap_alloc_pdp().


Revision tags: pgoyette-compat-0502
# 1.5 29-Apr-2018 ryo

fix KASSERT panic. pv_entry may not be exists in pvlist when pmap_remove().


# 1.4 29-Apr-2018 ryo

delete unused code


# 1.3 27-Apr-2018 ryo

fix instability behavior of bufcache on aarch64.
* fix to return correct ref/mod when PMAP_WIRED.
* changed to keep wired flags in pte instead of pv_entry, and cleanup.


Revision tags: pgoyette-compat-0422 pgoyette-compat-0415 pgoyette-compat-0407
# 1.2 01-Apr-2018 ryo

Add initial support for ARMv8 (AARCH64) (by nisimura@ and ryo@)

- sys/arch/evbarm64 is gone and integrated into sys/arch/evbarm. (by skrll@)
- add support fdt. evbarm/conf/GENERIC64 fdt (bcm2837,sunxi,tegra) based generic 64bit kernel config. (by skrll@, jmcneill@)


Revision tags: netbsd-8-1-RELEASE netbsd-8-1-RC1 netbsd-7-2-RELEASE netbsd-8-0-RELEASE netbsd-8-0-RC2 netbsd-8-0-RC1 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 netbsd-7-1-2-RELEASE pgoyette-compat-base netbsd-7-1-1-RELEASE tls-maxphys-base-20171202 matt-nb8-mediatek-base nick-nhusb-base-20170825 perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base pgoyette-localcount-20170320 netbsd-7-1-RELEASE netbsd-7-1-RC2 nick-nhusb-base-20170204 netbsd-7-nhusb-base-20170116 bouyer-socketcan-base pgoyette-localcount-20170107 netbsd-7-1-RC1 nick-nhusb-base-20161204 pgoyette-localcount-20161104 netbsd-7-0-2-RELEASE nick-nhusb-base-20161004 localcount-20160914 netbsd-7-nhusb-base pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907 nick-nhusb-base-20160529 netbsd-7-0-1-RELEASE nick-nhusb-base-20160422 nick-nhusb-base-20160319 nick-nhusb-base-20151226 netbsd-7-0-RELEASE nick-nhusb-base-20150921 netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 nick-nhusb-base-20150606 nick-nhusb-base-20150406 nick-nhusb-base tls-maxphys-base netbsd-7-base
# 1.1 10-Aug-2014 matt

branches: 1.1.4; 1.1.28;
Preliminary files for AARCH64 (64-bit ARM) support.
Enough for a distribution build.


# 1.66 29-Feb-2020 ryo

Fix pmap to work correctly with tagged addresses

- when fault, untag from address before passing to uvm/pmap functions
- pmap_extract() checks more strictly and consider the address tag


# 1.65 29-Feb-2020 ryo

use pmapboot_enter_range()


Revision tags: ad-namecache-base3
# 1.64 10-Feb-2020 ryo

use LIST(3) instead of TAILQ(3) to save one word in struct vm_page and struct pmap.

pointed out by riastradh@. thanks


# 1.63 03-Feb-2020 ryo

add support pmap_pv(9)

Patch originally from jmcneill@. thanks


# 1.62 03-Feb-2020 ryo

separate struct vm_page_md into vm_page_md and pmap_page
for preparation pmap_pv(9)


Revision tags: ad-namecache-base2 ad-namecache-base1
# 1.61 09-Jan-2020 ryo

fix behaviour mmap()/mprotect() when passed only PROT_EXEC.

when mmap()/mprotect() with only PROT_EXEC, syscall will be successful,
but the page actually hadn't been mapped.
it should be mapped with PROT_READ|PROT_EXEC implicitly. (r-x)


Revision tags: ad-namecache-base
# 1.60 30-Dec-2019 skrll

branches: 1.60.2;
Update pmap_map_chunk to allow L[12] block mappings and L3 page mappings


# 1.59 30-Dec-2019 skrll

Remove unnecessary brackets and unwrap a conditional. Same code before
and after.


# 1.58 28-Dec-2019 jmcneill

Do not use Early Write Acknowledge for PCIe I/O and config space.


# 1.57 27-Dec-2019 jmcneill

Enable early write acknowledge for device memory mappings.


# 1.56 19-Dec-2019 skrll

G/C kasan_shadow_map call in pmap_enter

pmap_growkernel calls kasan_shadow_map for KVA


# 1.55 18-Dec-2019 ryo

atomic_add_16() is not used in pmap.c anymore. no need decl here.


# 1.54 18-Dec-2019 ryo

space to tab


# 1.53 14-Dec-2019 skrll

Fix build... wire_count probably doesn't need atomics


# 1.52 13-Dec-2019 skrll

Fix KASAN support by calling kasan_shadow_map in pmap_growkernel


# 1.51 10-Dec-2019 ad

pg->phys_addr -> VM_PAGE_TO_PHYS(pg)


Revision tags: phil-wifi-20191119
# 1.50 14-Nov-2019 maxv

Mark several kASan functions with __nothing, to avoid annoying #ifdefs.
Same as kCSan and kMSan.


# 1.49 14-Nov-2019 maxv

Don't include "opt_kasan.h" when there's already <sys/asan.h> included.


# 1.48 29-Oct-2019 maya

Define PMAP_NEED_PROCWR, providing strategically placed i-cache
synchronization where just-changed memory is about to be executed.

Fixes SIGILLs seen when running Mono 6 on QEMU Cortex-A57.

ok ryo


# 1.47 22-Sep-2019 jmcneill

Disable translation table walks using TTBR0 while changing its value and
when deactivating a pmap. Fixes stability issues on Ampere eMAG CPUs.


# 1.46 20-Sep-2019 ryo

ref/mod bit should be set according to 'flags' argument, not 'prot'. r1.44 was incomplete.


# 1.45 13-Sep-2019 ryo

In pmap_devmap_bootstrap(), cpu_earlydevice_va_p() must not return true until *all* devmap tables have been enabled.
console mapping may be present in the last table.


# 1.44 07-Sep-2019 ryo

- remove incorrect KASSERT. mmap(2) with prot=PROT_WRITE calls pmap_enter(..., PROT_WRITE) internally.
- fix to update page reference flags when only PROT_WRITE or PROT_EXECUTE specified


# 1.43 15-Aug-2019 skrll

Make pmap_db_pte_print more terse so it's quicker on serial consoles


# 1.42 12-Aug-2019 skrll

Use PMAP_DEV in DEVMAP_ENTRY rather than pmap_map_chunk. It's clearer and
means pmap_map_chunk can be made to map other memory types.


Revision tags: netbsd-9-base phil-wifi-20190609
# 1.41 17-May-2019 mrg

branches: 1.41.2;
apply some __diagused.


Revision tags: isaki-audio2-base
# 1.40 08-Apr-2019 ryo

- free empty page tables pages if reach a certain usage.
- need to lock at removing an old pg (_pmap_remove_pv) in _pmap_enter()


# 1.39 06-Apr-2019 ryo

Fix race conditions about pmap_page_protect() and pmap_enter().

while handling same PTE by these functions in same time, there
is a critical path that the number of valid PTEs and wire_count
are inconsistent, and it caused KASSERT.
Need to hold a pv_lock while modifying them.


# 1.38 20-Mar-2019 ryo

spinkle __printflike(), and use PRIxxx


# 1.37 19-Mar-2019 ryo

- add ddb command "machine ttbr" to dump MMU tables.
- tidy up descriptions, usages and messages.


# 1.36 19-Mar-2019 ryo

- free L1-L3 pages that has been emptied by pmap_remove().
- if no memories, pmap_enter will return correctly ENOMEM if PMAP_CANFAIL, or wait until available any memories if !PMAP_CANFAIL.

These changes improves the stability when we use a huge virtual memory spaces with mmap.


# 1.35 06-Feb-2019 ryo

improve pmap_remove
- don't lock/unlock per page in pmap_remove()
- speedup pte lookup for continuous addresses
- bring out pool_cache_put(&_pmap_pv_pool, pv) from lock/unlock section


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226
# 1.34 21-Dec-2018 ryo

- add workaround for Cavium ThunderX errata 27456.
- add cpufuncs table in cpu_info. each cpu clusters may have different erratum. (e.g. big.LITTLE)


Revision tags: pgoyette-compat-1126
# 1.33 01-Nov-2018 maxv

Add kASan support for aarch64. Stack tracking needs more investigation
and will come in a separate commit.

Reviewed by ryo@ jmcneill@ skrll@.


# 1.32 31-Oct-2018 ryo

invalidate icache correctly.
l3pte_executable() should be used for only valid pte.


Revision tags: pgoyette-compat-1020
# 1.31 18-Oct-2018 skrll

Provide generic start code that assumes the MMU is off and caches are
disabled as per the linux booting protocol for ARMv6 and ARMv7 boards.
u-boot image type should be changed to 'linux' for correct behaviour.

The new start code builds a minimal "bootstrap" L1PT with cached access
disabled and uses the same table for all processors. AP startup is
performed in less steps and more code is written in C.

The bootstrap tables and stack are placed into an (orphaned) section
"_init_memory" which is given to uvm when it is no longer used.

Various kernels have been converted to use this code and tested. Some
boards were provided by TNF. Thanks!

The GENERIC kernel now boots on boards using the TEGRA, SUNXI and EXYNOS
kernels. The GENERIC kernel will also work on RPI2 using u-boot.

Thanks to martin@ and aymeric@ for testing on parallella and nanosoc
respectively


# 1.30 14-Oct-2018 skrll

Use __nothing


# 1.29 12-Oct-2018 ryo

add initial support of COMPAT_NETBSD32 on AArch64.
arm ELF32 EABI binaries could be execute in AArch32 state on AArch64. A32 THUMB mode is not supported yet.


# 1.28 12-Oct-2018 ryo

- cleanup checking address ranges with IN_RANGE macro
- change PM_ADDR_CHECK macro to KASSERTMSG
- restore fast lookup cases with IN_RANGE macro for pmap_extract changed in my previous commit.


# 1.27 12-Oct-2018 ryo

rewrite pmap_pte_lookup() to share similar code.


# 1.26 04-Oct-2018 ryo

cleanup locore, and changed the way to map memories during boot.
- add functions bootpage_enter() and bootpage_alloc() to adapt various layout
of physical memory map. especially for 64bit physical memory layout.
pmapboot_alloc() allocates pagetable pages from _end[].
- changed to map only the required amount for PA=VA identity mapping
(kernel image, UART device, and FDT blob) with L2_BLOCK(2Mbyte).
- changing page permission for kernel image, and making KSEG mapping are done
at cpu_kernel_vm_init() instead of at locore.
- optimize PTE entries with PTE Contiguous bit. it is enabled on devmap only for now.

reviewed by skrll@, thanks.


# 1.25 04-Oct-2018 ryo

* define LX_BLKPAG_{OS,ATTR}_* for OS dependent PTE attributes in pmap.h
* cleanup macros


Revision tags: pgoyette-compat-0930
# 1.24 17-Sep-2018 ryo

delete debug printf and KASSERT.


# 1.23 10-Sep-2018 maxv

Replace KDASSERT by panic.


# 1.22 10-Sep-2018 maxv

Rename _pmap_alloc_pdp -> pmap_alloc_pdp, and make it public.


# 1.21 10-Sep-2018 ryo

cleanup aarch64 mpstart and fdt bootstrap
* arm_cpu_hatch_arg is a bad idea. avoid serializing CPU startup, and eliminate arm_cpu_hatch_arg.
in mpstart, resolve own cpu index using array of cpu_mpidr[] (aarch64)
* add support fdt enable-method "spin-table"
* add support fdt enable-method "brcm,bcm2836-smp" (for 32bit RaspberryPi)
* use arm_fdt_cpu_bootstrap() instead of psci_fdt_bootstrap()
* rename "arm/fdt/psci_fdt.h" to "arm/fdt/psci_fdtvar.h" because of conflict of include file for needs-flag
* add devmap for cpu spin-table of raspberrypi3/aarch64
* no need to force hatch APs for raspberrypi3/arm32 ifndef MULTIPROCESSOR.
* fix to work pmap_extract(kerneltext/data/bss) even if before calling pmap_bootstrap

idea to use cpu_mpidr[] by jmcneill@. reviewd by skrll@. thanks.


Revision tags: pgoyette-compat-0906
# 1.20 27-Aug-2018 ryo

need to add VM_PROT_READ when pmap_kenter_pa(va, pa, VM_PROT_WRITE, 0) or pmap_kenter_pa(va, pa, VM_PROT_EXECUTE, 0).
VM_PROT_READ is treated as an access permission inernally.


# 1.19 11-Aug-2018 ryo

change to minimum invalidation of TLB.
specifying not only va but also asid, and not invalidate L0-L2 entry using tlbi_*_ll() if needed.


# 1.18 10-Aug-2018 ryo

treat kernel-exec attr and user-exec attr separately.
kernel cannot execute userland exec page, and user cannot execute kernel page.


# 1.17 06-Aug-2018 ryo

set kernel text/rodata readonly by default.
add function db_write_text() for setting ddb breakpoint.


# 1.16 31-Jul-2018 skrll

Define and use VPRINTF


Revision tags: pgoyette-compat-0728
# 1.15 27-Jul-2018 ryo

changes of pmap.c r1.13 seems to be unstable.
In order to invalidate icache, not to invalidate all icache,
but temporary to make the page writable and invalidate target address only.


# 1.14 24-Jul-2018 ryo

don't call pool_cache_put with locking pmap. pool_cache_put call pmap_kenter_pa internally.
(pool_cache_put_paddr -> pool_cache_put_slow -> pool_get -> pmap_kenter_pa)


# 1.13 23-Jul-2018 ryo

* fix icache invalidations.
* "ic ivau" (aarch64_icache_sync_range) with VA generates permission fault in some situations, therefore use KSEG address for now.


# 1.12 23-Jul-2018 ryo

rather than using flags to resolve nested locks, reserve pool_cache before locking.


# 1.11 21-Jul-2018 ryo

* avoid deadlock. mutex_owned() works only for adaptive lock, therefore we cannot use it for spinlock...
* add more NULL check
* clear pte when pmap_enter() fails


# 1.10 17-Jul-2018 ryo

Use __debugused


# 1.9 17-Jul-2018 christos

Add missing casts, remove unused variables.


# 1.8 09-Jul-2018 ryo

need locks in pmap_kremove() and pmap_fault_fixup()


Revision tags: phil-wifi-base pgoyette-compat-0625 pgoyette-compat-0521
# 1.7 20-May-2018 ryo

branches: 1.7.2;
pmap_enter() must update modified/referenced flags by 'flags' not 'prot'.


# 1.6 16-May-2018 ryo

Fix memory leak. it was leaking one page every pmap_create().
pm->pm_vmlist must be initialized before calling _pmap_alloc_pdp().


Revision tags: pgoyette-compat-0502
# 1.5 29-Apr-2018 ryo

fix KASSERT panic. pv_entry may not be exists in pvlist when pmap_remove().


# 1.4 29-Apr-2018 ryo

delete unused code


# 1.3 27-Apr-2018 ryo

fix instability behavior of bufcache on aarch64.
* fix to return correct ref/mod when PMAP_WIRED.
* changed to keep wired flags in pte instead of pv_entry, and cleanup.


Revision tags: pgoyette-compat-0422 pgoyette-compat-0415 pgoyette-compat-0407
# 1.2 01-Apr-2018 ryo

Add initial support for ARMv8 (AARCH64) (by nisimura@ and ryo@)

- sys/arch/evbarm64 is gone and integrated into sys/arch/evbarm. (by skrll@)
- add support fdt. evbarm/conf/GENERIC64 fdt (bcm2837,sunxi,tegra) based generic 64bit kernel config. (by skrll@, jmcneill@)


Revision tags: netbsd-8-1-RELEASE netbsd-8-1-RC1 netbsd-7-2-RELEASE netbsd-8-0-RELEASE netbsd-8-0-RC2 netbsd-8-0-RC1 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 netbsd-7-1-2-RELEASE pgoyette-compat-base netbsd-7-1-1-RELEASE tls-maxphys-base-20171202 matt-nb8-mediatek-base nick-nhusb-base-20170825 perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base pgoyette-localcount-20170320 netbsd-7-1-RELEASE netbsd-7-1-RC2 nick-nhusb-base-20170204 netbsd-7-nhusb-base-20170116 bouyer-socketcan-base pgoyette-localcount-20170107 netbsd-7-1-RC1 nick-nhusb-base-20161204 pgoyette-localcount-20161104 netbsd-7-0-2-RELEASE nick-nhusb-base-20161004 localcount-20160914 netbsd-7-nhusb-base pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907 nick-nhusb-base-20160529 netbsd-7-0-1-RELEASE nick-nhusb-base-20160422 nick-nhusb-base-20160319 nick-nhusb-base-20151226 netbsd-7-0-RELEASE nick-nhusb-base-20150921 netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 nick-nhusb-base-20150606 nick-nhusb-base-20150406 nick-nhusb-base tls-maxphys-base netbsd-7-base
# 1.1 10-Aug-2014 matt

branches: 1.1.4; 1.1.28;
Preliminary files for AARCH64 (64-bit ARM) support.
Enough for a distribution build.


# 1.64 10-Feb-2020 ryo

use LIST(3) instead of TAILQ(3) to save one word in struct vm_page and struct pmap.

pointed out by riastradh@. thanks


# 1.63 03-Feb-2020 ryo

add support pmap_pv(9)

Patch originally from jmcneill@. thanks


# 1.62 03-Feb-2020 ryo

separate struct vm_page_md into vm_page_md and pmap_page
for preparation pmap_pv(9)


Revision tags: ad-namecache-base2 ad-namecache-base1
# 1.61 09-Jan-2020 ryo

fix behaviour mmap()/mprotect() when passed only PROT_EXEC.

when mmap()/mprotect() with only PROT_EXEC, syscall will be successful,
but the page actually hadn't been mapped.
it should be mapped with PROT_READ|PROT_EXEC implicitly. (r-x)


Revision tags: ad-namecache-base
# 1.60 30-Dec-2019 skrll

branches: 1.60.2;
Update pmap_map_chunk to allow L[12] block mappings and L3 page mappings


# 1.59 30-Dec-2019 skrll

Remove unnecessary brackets and unwrap a conditional. Same code before
and after.


# 1.58 28-Dec-2019 jmcneill

Do not use Early Write Acknowledge for PCIe I/O and config space.


# 1.57 27-Dec-2019 jmcneill

Enable early write acknowledge for device memory mappings.


# 1.56 19-Dec-2019 skrll

G/C kasan_shadow_map call in pmap_enter

pmap_growkernel calls kasan_shadow_map for KVA


# 1.55 18-Dec-2019 ryo

atomic_add_16() is not used in pmap.c anymore. no need decl here.


# 1.54 18-Dec-2019 ryo

space to tab


# 1.53 14-Dec-2019 skrll

Fix build... wire_count probably doesn't need atomics


# 1.52 13-Dec-2019 skrll

Fix KASAN support by calling kasan_shadow_map in pmap_growkernel


# 1.51 10-Dec-2019 ad

pg->phys_addr -> VM_PAGE_TO_PHYS(pg)


Revision tags: phil-wifi-20191119
# 1.50 14-Nov-2019 maxv

Mark several kASan functions with __nothing, to avoid annoying #ifdefs.
Same as kCSan and kMSan.


# 1.49 14-Nov-2019 maxv

Don't include "opt_kasan.h" when there's already <sys/asan.h> included.


# 1.48 29-Oct-2019 maya

Define PMAP_NEED_PROCWR, providing strategically placed i-cache
synchronization where just-changed memory is about to be executed.

Fixes SIGILLs seen when running Mono 6 on QEMU Cortex-A57.

ok ryo


# 1.47 22-Sep-2019 jmcneill

Disable translation table walks using TTBR0 while changing its value and
when deactivating a pmap. Fixes stability issues on Ampere eMAG CPUs.


# 1.46 20-Sep-2019 ryo

ref/mod bit should be set according to 'flags' argument, not 'prot'. r1.44 was incomplete.


# 1.45 13-Sep-2019 ryo

In pmap_devmap_bootstrap(), cpu_earlydevice_va_p() must not return true until *all* devmap tables have been enabled.
console mapping may be present in the last table.


# 1.44 07-Sep-2019 ryo

- remove incorrect KASSERT. mmap(2) with prot=PROT_WRITE calls pmap_enter(..., PROT_WRITE) internally.
- fix to update page reference flags when only PROT_WRITE or PROT_EXECUTE specified


# 1.43 15-Aug-2019 skrll

Make pmap_db_pte_print more terse so it's quicker on serial consoles


# 1.42 12-Aug-2019 skrll

Use PMAP_DEV in DEVMAP_ENTRY rather than pmap_map_chunk. It's clearer and
means pmap_map_chunk can be made to map other memory types.


Revision tags: netbsd-9-base phil-wifi-20190609
# 1.41 17-May-2019 mrg

branches: 1.41.2;
apply some __diagused.


Revision tags: isaki-audio2-base
# 1.40 08-Apr-2019 ryo

- free empty page tables pages if reach a certain usage.
- need to lock at removing an old pg (_pmap_remove_pv) in _pmap_enter()


# 1.39 06-Apr-2019 ryo

Fix race conditions about pmap_page_protect() and pmap_enter().

while handling same PTE by these functions in same time, there
is a critical path that the number of valid PTEs and wire_count
are inconsistent, and it caused KASSERT.
Need to hold a pv_lock while modifying them.


# 1.38 20-Mar-2019 ryo

spinkle __printflike(), and use PRIxxx


# 1.37 19-Mar-2019 ryo

- add ddb command "machine ttbr" to dump MMU tables.
- tidy up descriptions, usages and messages.


# 1.36 19-Mar-2019 ryo

- free L1-L3 pages that has been emptied by pmap_remove().
- if no memories, pmap_enter will return correctly ENOMEM if PMAP_CANFAIL, or wait until available any memories if !PMAP_CANFAIL.

These changes improves the stability when we use a huge virtual memory spaces with mmap.


# 1.35 06-Feb-2019 ryo

improve pmap_remove
- don't lock/unlock per page in pmap_remove()
- speedup pte lookup for continuous addresses
- bring out pool_cache_put(&_pmap_pv_pool, pv) from lock/unlock section


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226
# 1.34 21-Dec-2018 ryo

- add workaround for Cavium ThunderX errata 27456.
- add cpufuncs table in cpu_info. each cpu clusters may have different erratum. (e.g. big.LITTLE)


Revision tags: pgoyette-compat-1126
# 1.33 01-Nov-2018 maxv

Add kASan support for aarch64. Stack tracking needs more investigation
and will come in a separate commit.

Reviewed by ryo@ jmcneill@ skrll@.


# 1.32 31-Oct-2018 ryo

invalidate icache correctly.
l3pte_executable() should be used for only valid pte.


Revision tags: pgoyette-compat-1020
# 1.31 18-Oct-2018 skrll

Provide generic start code that assumes the MMU is off and caches are
disabled as per the linux booting protocol for ARMv6 and ARMv7 boards.
u-boot image type should be changed to 'linux' for correct behaviour.

The new start code builds a minimal "bootstrap" L1PT with cached access
disabled and uses the same table for all processors. AP startup is
performed in less steps and more code is written in C.

The bootstrap tables and stack are placed into an (orphaned) section
"_init_memory" which is given to uvm when it is no longer used.

Various kernels have been converted to use this code and tested. Some
boards were provided by TNF. Thanks!

The GENERIC kernel now boots on boards using the TEGRA, SUNXI and EXYNOS
kernels. The GENERIC kernel will also work on RPI2 using u-boot.

Thanks to martin@ and aymeric@ for testing on parallella and nanosoc
respectively


# 1.30 14-Oct-2018 skrll

Use __nothing


# 1.29 12-Oct-2018 ryo

add initial support of COMPAT_NETBSD32 on AArch64.
arm ELF32 EABI binaries could be execute in AArch32 state on AArch64. A32 THUMB mode is not supported yet.


# 1.28 12-Oct-2018 ryo

- cleanup checking address ranges with IN_RANGE macro
- change PM_ADDR_CHECK macro to KASSERTMSG
- restore fast lookup cases with IN_RANGE macro for pmap_extract changed in my previous commit.


# 1.27 12-Oct-2018 ryo

rewrite pmap_pte_lookup() to share similar code.


# 1.26 04-Oct-2018 ryo

cleanup locore, and changed the way to map memories during boot.
- add functions bootpage_enter() and bootpage_alloc() to adapt various layout
of physical memory map. especially for 64bit physical memory layout.
pmapboot_alloc() allocates pagetable pages from _end[].
- changed to map only the required amount for PA=VA identity mapping
(kernel image, UART device, and FDT blob) with L2_BLOCK(2Mbyte).
- changing page permission for kernel image, and making KSEG mapping are done
at cpu_kernel_vm_init() instead of at locore.
- optimize PTE entries with PTE Contiguous bit. it is enabled on devmap only for now.

reviewed by skrll@, thanks.


# 1.25 04-Oct-2018 ryo

* define LX_BLKPAG_{OS,ATTR}_* for OS dependent PTE attributes in pmap.h
* cleanup macros


Revision tags: pgoyette-compat-0930
# 1.24 17-Sep-2018 ryo

delete debug printf and KASSERT.


# 1.23 10-Sep-2018 maxv

Replace KDASSERT by panic.


# 1.22 10-Sep-2018 maxv

Rename _pmap_alloc_pdp -> pmap_alloc_pdp, and make it public.


# 1.21 10-Sep-2018 ryo

cleanup aarch64 mpstart and fdt bootstrap
* arm_cpu_hatch_arg is a bad idea. avoid serializing CPU startup, and eliminate arm_cpu_hatch_arg.
in mpstart, resolve own cpu index using array of cpu_mpidr[] (aarch64)
* add support fdt enable-method "spin-table"
* add support fdt enable-method "brcm,bcm2836-smp" (for 32bit RaspberryPi)
* use arm_fdt_cpu_bootstrap() instead of psci_fdt_bootstrap()
* rename "arm/fdt/psci_fdt.h" to "arm/fdt/psci_fdtvar.h" because of conflict of include file for needs-flag
* add devmap for cpu spin-table of raspberrypi3/aarch64
* no need to force hatch APs for raspberrypi3/arm32 ifndef MULTIPROCESSOR.
* fix to work pmap_extract(kerneltext/data/bss) even if before calling pmap_bootstrap

idea to use cpu_mpidr[] by jmcneill@. reviewd by skrll@. thanks.


Revision tags: pgoyette-compat-0906
# 1.20 27-Aug-2018 ryo

need to add VM_PROT_READ when pmap_kenter_pa(va, pa, VM_PROT_WRITE, 0) or pmap_kenter_pa(va, pa, VM_PROT_EXECUTE, 0).
VM_PROT_READ is treated as an access permission inernally.


# 1.19 11-Aug-2018 ryo

change to minimum invalidation of TLB.
specifying not only va but also asid, and not invalidate L0-L2 entry using tlbi_*_ll() if needed.


# 1.18 10-Aug-2018 ryo

treat kernel-exec attr and user-exec attr separately.
kernel cannot execute userland exec page, and user cannot execute kernel page.


# 1.17 06-Aug-2018 ryo

set kernel text/rodata readonly by default.
add function db_write_text() for setting ddb breakpoint.


# 1.16 31-Jul-2018 skrll

Define and use VPRINTF


Revision tags: pgoyette-compat-0728
# 1.15 27-Jul-2018 ryo

changes of pmap.c r1.13 seems to be unstable.
In order to invalidate icache, not to invalidate all icache,
but temporary to make the page writable and invalidate target address only.


# 1.14 24-Jul-2018 ryo

don't call pool_cache_put with locking pmap. pool_cache_put call pmap_kenter_pa internally.
(pool_cache_put_paddr -> pool_cache_put_slow -> pool_get -> pmap_kenter_pa)


# 1.13 23-Jul-2018 ryo

* fix icache invalidations.
* "ic ivau" (aarch64_icache_sync_range) with VA generates permission fault in some situations, therefore use KSEG address for now.


# 1.12 23-Jul-2018 ryo

rather than using flags to resolve nested locks, reserve pool_cache before locking.


# 1.11 21-Jul-2018 ryo

* avoid deadlock. mutex_owned() works only for adaptive lock, therefore we cannot use it for spinlock...
* add more NULL check
* clear pte when pmap_enter() fails


# 1.10 17-Jul-2018 ryo

Use __debugused


# 1.9 17-Jul-2018 christos

Add missing casts, remove unused variables.


# 1.8 09-Jul-2018 ryo

need locks in pmap_kremove() and pmap_fault_fixup()


Revision tags: phil-wifi-base pgoyette-compat-0625 pgoyette-compat-0521
# 1.7 20-May-2018 ryo

branches: 1.7.2;
pmap_enter() must update modified/referenced flags by 'flags' not 'prot'.


# 1.6 16-May-2018 ryo

Fix memory leak. it was leaking one page every pmap_create().
pm->pm_vmlist must be initialized before calling _pmap_alloc_pdp().


Revision tags: pgoyette-compat-0502
# 1.5 29-Apr-2018 ryo

fix KASSERT panic. pv_entry may not be exists in pvlist when pmap_remove().


# 1.4 29-Apr-2018 ryo

delete unused code


# 1.3 27-Apr-2018 ryo

fix instability behavior of bufcache on aarch64.
* fix to return correct ref/mod when PMAP_WIRED.
* changed to keep wired flags in pte instead of pv_entry, and cleanup.


Revision tags: pgoyette-compat-0422 pgoyette-compat-0415 pgoyette-compat-0407
# 1.2 01-Apr-2018 ryo

Add initial support for ARMv8 (AARCH64) (by nisimura@ and ryo@)

- sys/arch/evbarm64 is gone and integrated into sys/arch/evbarm. (by skrll@)
- add support fdt. evbarm/conf/GENERIC64 fdt (bcm2837,sunxi,tegra) based generic 64bit kernel config. (by skrll@, jmcneill@)


Revision tags: netbsd-8-1-RELEASE netbsd-8-1-RC1 netbsd-7-2-RELEASE netbsd-8-0-RELEASE netbsd-8-0-RC2 netbsd-8-0-RC1 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 netbsd-7-1-2-RELEASE pgoyette-compat-base netbsd-7-1-1-RELEASE tls-maxphys-base-20171202 matt-nb8-mediatek-base nick-nhusb-base-20170825 perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base pgoyette-localcount-20170320 netbsd-7-1-RELEASE netbsd-7-1-RC2 nick-nhusb-base-20170204 netbsd-7-nhusb-base-20170116 bouyer-socketcan-base pgoyette-localcount-20170107 netbsd-7-1-RC1 nick-nhusb-base-20161204 pgoyette-localcount-20161104 netbsd-7-0-2-RELEASE nick-nhusb-base-20161004 localcount-20160914 netbsd-7-nhusb-base pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907 nick-nhusb-base-20160529 netbsd-7-0-1-RELEASE nick-nhusb-base-20160422 nick-nhusb-base-20160319 nick-nhusb-base-20151226 netbsd-7-0-RELEASE nick-nhusb-base-20150921 netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 nick-nhusb-base-20150606 nick-nhusb-base-20150406 nick-nhusb-base tls-maxphys-base netbsd-7-base
# 1.1 10-Aug-2014 matt

branches: 1.1.4; 1.1.28;
Preliminary files for AARCH64 (64-bit ARM) support.
Enough for a distribution build.


# 1.63 03-Feb-2020 ryo

add support pmap_pv(9)

Patch originally from jmcneill@. thanks


# 1.62 03-Feb-2020 ryo

separate struct vm_page_md into vm_page_md and pmap_page
for preparation pmap_pv(9)


Revision tags: ad-namecache-base2 ad-namecache-base1
# 1.61 09-Jan-2020 ryo

fix behaviour mmap()/mprotect() when passed only PROT_EXEC.

when mmap()/mprotect() with only PROT_EXEC, syscall will be successful,
but the page actually hadn't been mapped.
it should be mapped with PROT_READ|PROT_EXEC implicitly. (r-x)


Revision tags: ad-namecache-base
# 1.60 30-Dec-2019 skrll

branches: 1.60.2;
Update pmap_map_chunk to allow L[12] block mappings and L3 page mappings


# 1.59 30-Dec-2019 skrll

Remove unnecessary brackets and unwrap a conditional. Same code before
and after.


# 1.58 28-Dec-2019 jmcneill

Do not use Early Write Acknowledge for PCIe I/O and config space.


# 1.57 27-Dec-2019 jmcneill

Enable early write acknowledge for device memory mappings.


# 1.56 19-Dec-2019 skrll

G/C kasan_shadow_map call in pmap_enter

pmap_growkernel calls kasan_shadow_map for KVA


# 1.55 18-Dec-2019 ryo

atomic_add_16() is not used in pmap.c anymore. no need decl here.


# 1.54 18-Dec-2019 ryo

space to tab


# 1.53 14-Dec-2019 skrll

Fix build... wire_count probably doesn't need atomics


# 1.52 13-Dec-2019 skrll

Fix KASAN support by calling kasan_shadow_map in pmap_growkernel


# 1.51 10-Dec-2019 ad

pg->phys_addr -> VM_PAGE_TO_PHYS(pg)


Revision tags: phil-wifi-20191119
# 1.50 14-Nov-2019 maxv

Mark several kASan functions with __nothing, to avoid annoying #ifdefs.
Same as kCSan and kMSan.


# 1.49 14-Nov-2019 maxv

Don't include "opt_kasan.h" when there's already <sys/asan.h> included.


# 1.48 29-Oct-2019 maya

Define PMAP_NEED_PROCWR, providing strategically placed i-cache
synchronization where just-changed memory is about to be executed.

Fixes SIGILLs seen when running Mono 6 on QEMU Cortex-A57.

ok ryo


# 1.47 22-Sep-2019 jmcneill

Disable translation table walks using TTBR0 while changing its value and
when deactivating a pmap. Fixes stability issues on Ampere eMAG CPUs.


# 1.46 20-Sep-2019 ryo

ref/mod bit should be set according to 'flags' argument, not 'prot'. r1.44 was incomplete.


# 1.45 13-Sep-2019 ryo

In pmap_devmap_bootstrap(), cpu_earlydevice_va_p() must not return true until *all* devmap tables have been enabled.
console mapping may be present in the last table.


# 1.44 07-Sep-2019 ryo

- remove incorrect KASSERT. mmap(2) with prot=PROT_WRITE calls pmap_enter(..., PROT_WRITE) internally.
- fix to update page reference flags when only PROT_WRITE or PROT_EXECUTE specified


# 1.43 15-Aug-2019 skrll

Make pmap_db_pte_print more terse so it's quicker on serial consoles


# 1.42 12-Aug-2019 skrll

Use PMAP_DEV in DEVMAP_ENTRY rather than pmap_map_chunk. It's clearer and
means pmap_map_chunk can be made to map other memory types.


Revision tags: netbsd-9-base phil-wifi-20190609
# 1.41 17-May-2019 mrg

branches: 1.41.2;
apply some __diagused.


Revision tags: isaki-audio2-base
# 1.40 08-Apr-2019 ryo

- free empty page tables pages if reach a certain usage.
- need to lock at removing an old pg (_pmap_remove_pv) in _pmap_enter()


# 1.39 06-Apr-2019 ryo

Fix race conditions about pmap_page_protect() and pmap_enter().

while handling same PTE by these functions in same time, there
is a critical path that the number of valid PTEs and wire_count
are inconsistent, and it caused KASSERT.
Need to hold a pv_lock while modifying them.


# 1.38 20-Mar-2019 ryo

spinkle __printflike(), and use PRIxxx


# 1.37 19-Mar-2019 ryo

- add ddb command "machine ttbr" to dump MMU tables.
- tidy up descriptions, usages and messages.


# 1.36 19-Mar-2019 ryo

- free L1-L3 pages that has been emptied by pmap_remove().
- if no memories, pmap_enter will return correctly ENOMEM if PMAP_CANFAIL, or wait until available any memories if !PMAP_CANFAIL.

These changes improves the stability when we use a huge virtual memory spaces with mmap.


# 1.35 06-Feb-2019 ryo

improve pmap_remove
- don't lock/unlock per page in pmap_remove()
- speedup pte lookup for continuous addresses
- bring out pool_cache_put(&_pmap_pv_pool, pv) from lock/unlock section


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226
# 1.34 21-Dec-2018 ryo

- add workaround for Cavium ThunderX errata 27456.
- add cpufuncs table in cpu_info. each cpu clusters may have different erratum. (e.g. big.LITTLE)


Revision tags: pgoyette-compat-1126
# 1.33 01-Nov-2018 maxv

Add kASan support for aarch64. Stack tracking needs more investigation
and will come in a separate commit.

Reviewed by ryo@ jmcneill@ skrll@.


# 1.32 31-Oct-2018 ryo

invalidate icache correctly.
l3pte_executable() should be used for only valid pte.


Revision tags: pgoyette-compat-1020
# 1.31 18-Oct-2018 skrll

Provide generic start code that assumes the MMU is off and caches are
disabled as per the linux booting protocol for ARMv6 and ARMv7 boards.
u-boot image type should be changed to 'linux' for correct behaviour.

The new start code builds a minimal "bootstrap" L1PT with cached access
disabled and uses the same table for all processors. AP startup is
performed in less steps and more code is written in C.

The bootstrap tables and stack are placed into an (orphaned) section
"_init_memory" which is given to uvm when it is no longer used.

Various kernels have been converted to use this code and tested. Some
boards were provided by TNF. Thanks!

The GENERIC kernel now boots on boards using the TEGRA, SUNXI and EXYNOS
kernels. The GENERIC kernel will also work on RPI2 using u-boot.

Thanks to martin@ and aymeric@ for testing on parallella and nanosoc
respectively


# 1.30 14-Oct-2018 skrll

Use __nothing


# 1.29 12-Oct-2018 ryo

add initial support of COMPAT_NETBSD32 on AArch64.
arm ELF32 EABI binaries could be execute in AArch32 state on AArch64. A32 THUMB mode is not supported yet.


# 1.28 12-Oct-2018 ryo

- cleanup checking address ranges with IN_RANGE macro
- change PM_ADDR_CHECK macro to KASSERTMSG
- restore fast lookup cases with IN_RANGE macro for pmap_extract changed in my previous commit.


# 1.27 12-Oct-2018 ryo

rewrite pmap_pte_lookup() to share similar code.


# 1.26 04-Oct-2018 ryo

cleanup locore, and changed the way to map memories during boot.
- add functions bootpage_enter() and bootpage_alloc() to adapt various layout
of physical memory map. especially for 64bit physical memory layout.
pmapboot_alloc() allocates pagetable pages from _end[].
- changed to map only the required amount for PA=VA identity mapping
(kernel image, UART device, and FDT blob) with L2_BLOCK(2Mbyte).
- changing page permission for kernel image, and making KSEG mapping are done
at cpu_kernel_vm_init() instead of at locore.
- optimize PTE entries with PTE Contiguous bit. it is enabled on devmap only for now.

reviewed by skrll@, thanks.


# 1.25 04-Oct-2018 ryo

* define LX_BLKPAG_{OS,ATTR}_* for OS dependent PTE attributes in pmap.h
* cleanup macros


Revision tags: pgoyette-compat-0930
# 1.24 17-Sep-2018 ryo

delete debug printf and KASSERT.


# 1.23 10-Sep-2018 maxv

Replace KDASSERT by panic.


# 1.22 10-Sep-2018 maxv

Rename _pmap_alloc_pdp -> pmap_alloc_pdp, and make it public.


# 1.21 10-Sep-2018 ryo

cleanup aarch64 mpstart and fdt bootstrap
* arm_cpu_hatch_arg is a bad idea. avoid serializing CPU startup, and eliminate arm_cpu_hatch_arg.
in mpstart, resolve own cpu index using array of cpu_mpidr[] (aarch64)
* add support fdt enable-method "spin-table"
* add support fdt enable-method "brcm,bcm2836-smp" (for 32bit RaspberryPi)
* use arm_fdt_cpu_bootstrap() instead of psci_fdt_bootstrap()
* rename "arm/fdt/psci_fdt.h" to "arm/fdt/psci_fdtvar.h" because of conflict of include file for needs-flag
* add devmap for cpu spin-table of raspberrypi3/aarch64
* no need to force hatch APs for raspberrypi3/arm32 ifndef MULTIPROCESSOR.
* fix to work pmap_extract(kerneltext/data/bss) even if before calling pmap_bootstrap

idea to use cpu_mpidr[] by jmcneill@. reviewd by skrll@. thanks.


Revision tags: pgoyette-compat-0906
# 1.20 27-Aug-2018 ryo

need to add VM_PROT_READ when pmap_kenter_pa(va, pa, VM_PROT_WRITE, 0) or pmap_kenter_pa(va, pa, VM_PROT_EXECUTE, 0).
VM_PROT_READ is treated as an access permission inernally.


# 1.19 11-Aug-2018 ryo

change to minimum invalidation of TLB.
specifying not only va but also asid, and not invalidate L0-L2 entry using tlbi_*_ll() if needed.


# 1.18 10-Aug-2018 ryo

treat kernel-exec attr and user-exec attr separately.
kernel cannot execute userland exec page, and user cannot execute kernel page.


# 1.17 06-Aug-2018 ryo

set kernel text/rodata readonly by default.
add function db_write_text() for setting ddb breakpoint.


# 1.16 31-Jul-2018 skrll

Define and use VPRINTF


Revision tags: pgoyette-compat-0728
# 1.15 27-Jul-2018 ryo

changes of pmap.c r1.13 seems to be unstable.
In order to invalidate icache, not to invalidate all icache,
but temporary to make the page writable and invalidate target address only.


# 1.14 24-Jul-2018 ryo

don't call pool_cache_put with locking pmap. pool_cache_put call pmap_kenter_pa internally.
(pool_cache_put_paddr -> pool_cache_put_slow -> pool_get -> pmap_kenter_pa)


# 1.13 23-Jul-2018 ryo

* fix icache invalidations.
* "ic ivau" (aarch64_icache_sync_range) with VA generates permission fault in some situations, therefore use KSEG address for now.


# 1.12 23-Jul-2018 ryo

rather than using flags to resolve nested locks, reserve pool_cache before locking.


# 1.11 21-Jul-2018 ryo

* avoid deadlock. mutex_owned() works only for adaptive lock, therefore we cannot use it for spinlock...
* add more NULL check
* clear pte when pmap_enter() fails


# 1.10 17-Jul-2018 ryo

Use __debugused


# 1.9 17-Jul-2018 christos

Add missing casts, remove unused variables.


# 1.8 09-Jul-2018 ryo

need locks in pmap_kremove() and pmap_fault_fixup()


Revision tags: phil-wifi-base pgoyette-compat-0625 pgoyette-compat-0521
# 1.7 20-May-2018 ryo

branches: 1.7.2;
pmap_enter() must update modified/referenced flags by 'flags' not 'prot'.


# 1.6 16-May-2018 ryo

Fix memory leak. it was leaking one page every pmap_create().
pm->pm_vmlist must be initialized before calling _pmap_alloc_pdp().


Revision tags: pgoyette-compat-0502
# 1.5 29-Apr-2018 ryo

fix KASSERT panic. pv_entry may not be exists in pvlist when pmap_remove().


# 1.4 29-Apr-2018 ryo

delete unused code


# 1.3 27-Apr-2018 ryo

fix instability behavior of bufcache on aarch64.
* fix to return correct ref/mod when PMAP_WIRED.
* changed to keep wired flags in pte instead of pv_entry, and cleanup.


Revision tags: pgoyette-compat-0422 pgoyette-compat-0415 pgoyette-compat-0407
# 1.2 01-Apr-2018 ryo

Add initial support for ARMv8 (AARCH64) (by nisimura@ and ryo@)

- sys/arch/evbarm64 is gone and integrated into sys/arch/evbarm. (by skrll@)
- add support fdt. evbarm/conf/GENERIC64 fdt (bcm2837,sunxi,tegra) based generic 64bit kernel config. (by skrll@, jmcneill@)


Revision tags: netbsd-8-1-RELEASE netbsd-8-1-RC1 netbsd-7-2-RELEASE netbsd-8-0-RELEASE netbsd-8-0-RC2 netbsd-8-0-RC1 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 netbsd-7-1-2-RELEASE pgoyette-compat-base netbsd-7-1-1-RELEASE tls-maxphys-base-20171202 matt-nb8-mediatek-base nick-nhusb-base-20170825 perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base pgoyette-localcount-20170320 netbsd-7-1-RELEASE netbsd-7-1-RC2 nick-nhusb-base-20170204 netbsd-7-nhusb-base-20170116 bouyer-socketcan-base pgoyette-localcount-20170107 netbsd-7-1-RC1 nick-nhusb-base-20161204 pgoyette-localcount-20161104 netbsd-7-0-2-RELEASE nick-nhusb-base-20161004 localcount-20160914 netbsd-7-nhusb-base pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907 nick-nhusb-base-20160529 netbsd-7-0-1-RELEASE nick-nhusb-base-20160422 nick-nhusb-base-20160319 nick-nhusb-base-20151226 netbsd-7-0-RELEASE nick-nhusb-base-20150921 netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 nick-nhusb-base-20150606 nick-nhusb-base-20150406 nick-nhusb-base tls-maxphys-base netbsd-7-base
# 1.1 10-Aug-2014 matt

branches: 1.1.4; 1.1.28;
Preliminary files for AARCH64 (64-bit ARM) support.
Enough for a distribution build.


# 1.61 09-Jan-2020 ryo

fix behaviour mmap()/mprotect() when passed only PROT_EXEC.

when mmap()/mprotect() with only PROT_EXEC, syscall will be successful,
but the page actually hadn't been mapped.
it should be mapped with PROT_READ|PROT_EXEC implicitly. (r-x)


Revision tags: ad-namecache-base
# 1.60 30-Dec-2019 skrll

Update pmap_map_chunk to allow L[12] block mappings and L3 page mappings


# 1.59 30-Dec-2019 skrll

Remove unnecessary brackets and unwrap a conditional. Same code before
and after.


# 1.58 28-Dec-2019 jmcneill

Do not use Early Write Acknowledge for PCIe I/O and config space.


# 1.57 27-Dec-2019 jmcneill

Enable early write acknowledge for device memory mappings.


# 1.56 19-Dec-2019 skrll

G/C kasan_shadow_map call in pmap_enter

pmap_growkernel calls kasan_shadow_map for KVA


# 1.55 18-Dec-2019 ryo

atomic_add_16() is not used in pmap.c anymore. no need decl here.


# 1.54 18-Dec-2019 ryo

space to tab


# 1.53 14-Dec-2019 skrll

Fix build... wire_count probably doesn't need atomics


# 1.52 13-Dec-2019 skrll

Fix KASAN support by calling kasan_shadow_map in pmap_growkernel


# 1.51 10-Dec-2019 ad

pg->phys_addr -> VM_PAGE_TO_PHYS(pg)


Revision tags: phil-wifi-20191119
# 1.50 14-Nov-2019 maxv

Mark several kASan functions with __nothing, to avoid annoying #ifdefs.
Same as kCSan and kMSan.


# 1.49 14-Nov-2019 maxv

Don't include "opt_kasan.h" when there's already <sys/asan.h> included.


# 1.48 29-Oct-2019 maya

Define PMAP_NEED_PROCWR, providing strategically placed i-cache
synchronization where just-changed memory is about to be executed.

Fixes SIGILLs seen when running Mono 6 on QEMU Cortex-A57.

ok ryo


# 1.47 22-Sep-2019 jmcneill

Disable translation table walks using TTBR0 while changing its value and
when deactivating a pmap. Fixes stability issues on Ampere eMAG CPUs.


# 1.46 20-Sep-2019 ryo

ref/mod bit should be set according to 'flags' argument, not 'prot'. r1.44 was incomplete.


# 1.45 13-Sep-2019 ryo

In pmap_devmap_bootstrap(), cpu_earlydevice_va_p() must not return true until *all* devmap tables have been enabled.
console mapping may be present in the last table.


# 1.44 07-Sep-2019 ryo

- remove incorrect KASSERT. mmap(2) with prot=PROT_WRITE calls pmap_enter(..., PROT_WRITE) internally.
- fix to update page reference flags when only PROT_WRITE or PROT_EXECUTE specified


# 1.43 15-Aug-2019 skrll

Make pmap_db_pte_print more terse so it's quicker on serial consoles


# 1.42 12-Aug-2019 skrll

Use PMAP_DEV in DEVMAP_ENTRY rather than pmap_map_chunk. It's clearer and
means pmap_map_chunk can be made to map other memory types.


Revision tags: netbsd-9-base phil-wifi-20190609
# 1.41 17-May-2019 mrg

branches: 1.41.2;
apply some __diagused.


Revision tags: isaki-audio2-base
# 1.40 08-Apr-2019 ryo

- free empty page tables pages if reach a certain usage.
- need to lock at removing an old pg (_pmap_remove_pv) in _pmap_enter()


# 1.39 06-Apr-2019 ryo

Fix race conditions about pmap_page_protect() and pmap_enter().

while handling same PTE by these functions in same time, there
is a critical path that the number of valid PTEs and wire_count
are inconsistent, and it caused KASSERT.
Need to hold a pv_lock while modifying them.


# 1.38 20-Mar-2019 ryo

spinkle __printflike(), and use PRIxxx


# 1.37 19-Mar-2019 ryo

- add ddb command "machine ttbr" to dump MMU tables.
- tidy up descriptions, usages and messages.


# 1.36 19-Mar-2019 ryo

- free L1-L3 pages that has been emptied by pmap_remove().
- if no memories, pmap_enter will return correctly ENOMEM if PMAP_CANFAIL, or wait until available any memories if !PMAP_CANFAIL.

These changes improves the stability when we use a huge virtual memory spaces with mmap.


# 1.35 06-Feb-2019 ryo

improve pmap_remove
- don't lock/unlock per page in pmap_remove()
- speedup pte lookup for continuous addresses
- bring out pool_cache_put(&_pmap_pv_pool, pv) from lock/unlock section


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226
# 1.34 21-Dec-2018 ryo

- add workaround for Cavium ThunderX errata 27456.
- add cpufuncs table in cpu_info. each cpu clusters may have different erratum. (e.g. big.LITTLE)


Revision tags: pgoyette-compat-1126
# 1.33 01-Nov-2018 maxv

Add kASan support for aarch64. Stack tracking needs more investigation
and will come in a separate commit.

Reviewed by ryo@ jmcneill@ skrll@.


# 1.32 31-Oct-2018 ryo

invalidate icache correctly.
l3pte_executable() should be used for only valid pte.


Revision tags: pgoyette-compat-1020
# 1.31 18-Oct-2018 skrll

Provide generic start code that assumes the MMU is off and caches are
disabled as per the linux booting protocol for ARMv6 and ARMv7 boards.
u-boot image type should be changed to 'linux' for correct behaviour.

The new start code builds a minimal "bootstrap" L1PT with cached access
disabled and uses the same table for all processors. AP startup is
performed in less steps and more code is written in C.

The bootstrap tables and stack are placed into an (orphaned) section
"_init_memory" which is given to uvm when it is no longer used.

Various kernels have been converted to use this code and tested. Some
boards were provided by TNF. Thanks!

The GENERIC kernel now boots on boards using the TEGRA, SUNXI and EXYNOS
kernels. The GENERIC kernel will also work on RPI2 using u-boot.

Thanks to martin@ and aymeric@ for testing on parallella and nanosoc
respectively


# 1.30 14-Oct-2018 skrll

Use __nothing


# 1.29 12-Oct-2018 ryo

add initial support of COMPAT_NETBSD32 on AArch64.
arm ELF32 EABI binaries could be execute in AArch32 state on AArch64. A32 THUMB mode is not supported yet.


# 1.28 12-Oct-2018 ryo

- cleanup checking address ranges with IN_RANGE macro
- change PM_ADDR_CHECK macro to KASSERTMSG
- restore fast lookup cases with IN_RANGE macro for pmap_extract changed in my previous commit.


# 1.27 12-Oct-2018 ryo

rewrite pmap_pte_lookup() to share similar code.


# 1.26 04-Oct-2018 ryo

cleanup locore, and changed the way to map memories during boot.
- add functions bootpage_enter() and bootpage_alloc() to adapt various layout
of physical memory map. especially for 64bit physical memory layout.
pmapboot_alloc() allocates pagetable pages from _end[].
- changed to map only the required amount for PA=VA identity mapping
(kernel image, UART device, and FDT blob) with L2_BLOCK(2Mbyte).
- changing page permission for kernel image, and making KSEG mapping are done
at cpu_kernel_vm_init() instead of at locore.
- optimize PTE entries with PTE Contiguous bit. it is enabled on devmap only for now.

reviewed by skrll@, thanks.


# 1.25 04-Oct-2018 ryo

* define LX_BLKPAG_{OS,ATTR}_* for OS dependent PTE attributes in pmap.h
* cleanup macros


Revision tags: pgoyette-compat-0930
# 1.24 17-Sep-2018 ryo

delete debug printf and KASSERT.


# 1.23 10-Sep-2018 maxv

Replace KDASSERT by panic.


# 1.22 10-Sep-2018 maxv

Rename _pmap_alloc_pdp -> pmap_alloc_pdp, and make it public.


# 1.21 10-Sep-2018 ryo

cleanup aarch64 mpstart and fdt bootstrap
* arm_cpu_hatch_arg is a bad idea. avoid serializing CPU startup, and eliminate arm_cpu_hatch_arg.
in mpstart, resolve own cpu index using array of cpu_mpidr[] (aarch64)
* add support fdt enable-method "spin-table"
* add support fdt enable-method "brcm,bcm2836-smp" (for 32bit RaspberryPi)
* use arm_fdt_cpu_bootstrap() instead of psci_fdt_bootstrap()
* rename "arm/fdt/psci_fdt.h" to "arm/fdt/psci_fdtvar.h" because of conflict of include file for needs-flag
* add devmap for cpu spin-table of raspberrypi3/aarch64
* no need to force hatch APs for raspberrypi3/arm32 ifndef MULTIPROCESSOR.
* fix to work pmap_extract(kerneltext/data/bss) even if before calling pmap_bootstrap

idea to use cpu_mpidr[] by jmcneill@. reviewd by skrll@. thanks.


Revision tags: pgoyette-compat-0906
# 1.20 27-Aug-2018 ryo

need to add VM_PROT_READ when pmap_kenter_pa(va, pa, VM_PROT_WRITE, 0) or pmap_kenter_pa(va, pa, VM_PROT_EXECUTE, 0).
VM_PROT_READ is treated as an access permission inernally.


# 1.19 11-Aug-2018 ryo

change to minimum invalidation of TLB.
specifying not only va but also asid, and not invalidate L0-L2 entry using tlbi_*_ll() if needed.


# 1.18 10-Aug-2018 ryo

treat kernel-exec attr and user-exec attr separately.
kernel cannot execute userland exec page, and user cannot execute kernel page.


# 1.17 06-Aug-2018 ryo

set kernel text/rodata readonly by default.
add function db_write_text() for setting ddb breakpoint.


# 1.16 31-Jul-2018 skrll

Define and use VPRINTF


Revision tags: pgoyette-compat-0728
# 1.15 27-Jul-2018 ryo

changes of pmap.c r1.13 seems to be unstable.
In order to invalidate icache, not to invalidate all icache,
but temporary to make the page writable and invalidate target address only.


# 1.14 24-Jul-2018 ryo

don't call pool_cache_put with locking pmap. pool_cache_put call pmap_kenter_pa internally.
(pool_cache_put_paddr -> pool_cache_put_slow -> pool_get -> pmap_kenter_pa)


# 1.13 23-Jul-2018 ryo

* fix icache invalidations.
* "ic ivau" (aarch64_icache_sync_range) with VA generates permission fault in some situations, therefore use KSEG address for now.


# 1.12 23-Jul-2018 ryo

rather than using flags to resolve nested locks, reserve pool_cache before locking.


# 1.11 21-Jul-2018 ryo

* avoid deadlock. mutex_owned() works only for adaptive lock, therefore we cannot use it for spinlock...
* add more NULL check
* clear pte when pmap_enter() fails


# 1.10 17-Jul-2018 ryo

Use __debugused


# 1.9 17-Jul-2018 christos

Add missing casts, remove unused variables.


# 1.8 09-Jul-2018 ryo

need locks in pmap_kremove() and pmap_fault_fixup()


Revision tags: phil-wifi-base pgoyette-compat-0625 pgoyette-compat-0521
# 1.7 20-May-2018 ryo

branches: 1.7.2;
pmap_enter() must update modified/referenced flags by 'flags' not 'prot'.


# 1.6 16-May-2018 ryo

Fix memory leak. it was leaking one page every pmap_create().
pm->pm_vmlist must be initialized before calling _pmap_alloc_pdp().


Revision tags: pgoyette-compat-0502
# 1.5 29-Apr-2018 ryo

fix KASSERT panic. pv_entry may not be exists in pvlist when pmap_remove().


# 1.4 29-Apr-2018 ryo

delete unused code


# 1.3 27-Apr-2018 ryo

fix instability behavior of bufcache on aarch64.
* fix to return correct ref/mod when PMAP_WIRED.
* changed to keep wired flags in pte instead of pv_entry, and cleanup.


Revision tags: pgoyette-compat-0422 pgoyette-compat-0415 pgoyette-compat-0407
# 1.2 01-Apr-2018 ryo

Add initial support for ARMv8 (AARCH64) (by nisimura@ and ryo@)

- sys/arch/evbarm64 is gone and integrated into sys/arch/evbarm. (by skrll@)
- add support fdt. evbarm/conf/GENERIC64 fdt (bcm2837,sunxi,tegra) based generic 64bit kernel config. (by skrll@, jmcneill@)


Revision tags: netbsd-8-1-RELEASE netbsd-8-1-RC1 netbsd-7-2-RELEASE netbsd-8-0-RELEASE netbsd-8-0-RC2 netbsd-8-0-RC1 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 netbsd-7-1-2-RELEASE pgoyette-compat-base netbsd-7-1-1-RELEASE tls-maxphys-base-20171202 matt-nb8-mediatek-base nick-nhusb-base-20170825 perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base pgoyette-localcount-20170320 netbsd-7-1-RELEASE netbsd-7-1-RC2 nick-nhusb-base-20170204 netbsd-7-nhusb-base-20170116 bouyer-socketcan-base pgoyette-localcount-20170107 netbsd-7-1-RC1 nick-nhusb-base-20161204 pgoyette-localcount-20161104 netbsd-7-0-2-RELEASE nick-nhusb-base-20161004 localcount-20160914 netbsd-7-nhusb-base pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907 nick-nhusb-base-20160529 netbsd-7-0-1-RELEASE nick-nhusb-base-20160422 nick-nhusb-base-20160319 nick-nhusb-base-20151226 netbsd-7-0-RELEASE nick-nhusb-base-20150921 netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 nick-nhusb-base-20150606 nick-nhusb-base-20150406 nick-nhusb-base tls-maxphys-base netbsd-7-base
# 1.1 10-Aug-2014 matt

branches: 1.1.4; 1.1.28;
Preliminary files for AARCH64 (64-bit ARM) support.
Enough for a distribution build.


# 1.60 30-Dec-2019 skrll

Update pmap_map_chunk to allow L[12] block mappings and L3 page mappings


# 1.59 30-Dec-2019 skrll

Remove unnecessary brackets and unwrap a conditional. Same code before
and after.


# 1.58 28-Dec-2019 jmcneill

Do not use Early Write Acknowledge for PCIe I/O and config space.


# 1.57 27-Dec-2019 jmcneill

Enable early write acknowledge for device memory mappings.


# 1.56 19-Dec-2019 skrll

G/C kasan_shadow_map call in pmap_enter

pmap_growkernel calls kasan_shadow_map for KVA


# 1.55 18-Dec-2019 ryo

atomic_add_16() is not used in pmap.c anymore. no need decl here.


# 1.54 18-Dec-2019 ryo

space to tab


# 1.53 14-Dec-2019 skrll

Fix build... wire_count probably doesn't need atomics


# 1.52 13-Dec-2019 skrll

Fix KASAN support by calling kasan_shadow_map in pmap_growkernel


# 1.51 10-Dec-2019 ad

pg->phys_addr -> VM_PAGE_TO_PHYS(pg)


Revision tags: phil-wifi-20191119
# 1.50 14-Nov-2019 maxv

Mark several kASan functions with __nothing, to avoid annoying #ifdefs.
Same as kCSan and kMSan.


# 1.49 14-Nov-2019 maxv

Don't include "opt_kasan.h" when there's already <sys/asan.h> included.


# 1.48 29-Oct-2019 maya

Define PMAP_NEED_PROCWR, providing strategically placed i-cache
synchronization where just-changed memory is about to be executed.

Fixes SIGILLs seen when running Mono 6 on QEMU Cortex-A57.

ok ryo


# 1.47 22-Sep-2019 jmcneill

Disable translation table walks using TTBR0 while changing its value and
when deactivating a pmap. Fixes stability issues on Ampere eMAG CPUs.


# 1.46 20-Sep-2019 ryo

ref/mod bit should be set according to 'flags' argument, not 'prot'. r1.44 was incomplete.


# 1.45 13-Sep-2019 ryo

In pmap_devmap_bootstrap(), cpu_earlydevice_va_p() must not return true until *all* devmap tables have been enabled.
console mapping may be present in the last table.


# 1.44 07-Sep-2019 ryo

- remove incorrect KASSERT. mmap(2) with prot=PROT_WRITE calls pmap_enter(..., PROT_WRITE) internally.
- fix to update page reference flags when only PROT_WRITE or PROT_EXECUTE specified


# 1.43 15-Aug-2019 skrll

Make pmap_db_pte_print more terse so it's quicker on serial consoles


# 1.42 12-Aug-2019 skrll

Use PMAP_DEV in DEVMAP_ENTRY rather than pmap_map_chunk. It's clearer and
means pmap_map_chunk can be made to map other memory types.


Revision tags: netbsd-9-base phil-wifi-20190609
# 1.41 17-May-2019 mrg

branches: 1.41.2;
apply some __diagused.


Revision tags: isaki-audio2-base
# 1.40 08-Apr-2019 ryo

- free empty page tables pages if reach a certain usage.
- need to lock at removing an old pg (_pmap_remove_pv) in _pmap_enter()


# 1.39 06-Apr-2019 ryo

Fix race conditions about pmap_page_protect() and pmap_enter().

while handling same PTE by these functions in same time, there
is a critical path that the number of valid PTEs and wire_count
are inconsistent, and it caused KASSERT.
Need to hold a pv_lock while modifying them.


# 1.38 20-Mar-2019 ryo

spinkle __printflike(), and use PRIxxx


# 1.37 19-Mar-2019 ryo

- add ddb command "machine ttbr" to dump MMU tables.
- tidy up descriptions, usages and messages.


# 1.36 19-Mar-2019 ryo

- free L1-L3 pages that has been emptied by pmap_remove().
- if no memories, pmap_enter will return correctly ENOMEM if PMAP_CANFAIL, or wait until available any memories if !PMAP_CANFAIL.

These changes improves the stability when we use a huge virtual memory spaces with mmap.


# 1.35 06-Feb-2019 ryo

improve pmap_remove
- don't lock/unlock per page in pmap_remove()
- speedup pte lookup for continuous addresses
- bring out pool_cache_put(&_pmap_pv_pool, pv) from lock/unlock section


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226
# 1.34 21-Dec-2018 ryo

- add workaround for Cavium ThunderX errata 27456.
- add cpufuncs table in cpu_info. each cpu clusters may have different erratum. (e.g. big.LITTLE)


Revision tags: pgoyette-compat-1126
# 1.33 01-Nov-2018 maxv

Add kASan support for aarch64. Stack tracking needs more investigation
and will come in a separate commit.

Reviewed by ryo@ jmcneill@ skrll@.


# 1.32 31-Oct-2018 ryo

invalidate icache correctly.
l3pte_executable() should be used for only valid pte.


Revision tags: pgoyette-compat-1020
# 1.31 18-Oct-2018 skrll

Provide generic start code that assumes the MMU is off and caches are
disabled as per the linux booting protocol for ARMv6 and ARMv7 boards.
u-boot image type should be changed to 'linux' for correct behaviour.

The new start code builds a minimal "bootstrap" L1PT with cached access
disabled and uses the same table for all processors. AP startup is
performed in less steps and more code is written in C.

The bootstrap tables and stack are placed into an (orphaned) section
"_init_memory" which is given to uvm when it is no longer used.

Various kernels have been converted to use this code and tested. Some
boards were provided by TNF. Thanks!

The GENERIC kernel now boots on boards using the TEGRA, SUNXI and EXYNOS
kernels. The GENERIC kernel will also work on RPI2 using u-boot.

Thanks to martin@ and aymeric@ for testing on parallella and nanosoc
respectively


# 1.30 14-Oct-2018 skrll

Use __nothing


# 1.29 12-Oct-2018 ryo

add initial support of COMPAT_NETBSD32 on AArch64.
arm ELF32 EABI binaries could be execute in AArch32 state on AArch64. A32 THUMB mode is not supported yet.


# 1.28 12-Oct-2018 ryo

- cleanup checking address ranges with IN_RANGE macro
- change PM_ADDR_CHECK macro to KASSERTMSG
- restore fast lookup cases with IN_RANGE macro for pmap_extract changed in my previous commit.


# 1.27 12-Oct-2018 ryo

rewrite pmap_pte_lookup() to share similar code.


# 1.26 04-Oct-2018 ryo

cleanup locore, and changed the way to map memories during boot.
- add functions bootpage_enter() and bootpage_alloc() to adapt various layout
of physical memory map. especially for 64bit physical memory layout.
pmapboot_alloc() allocates pagetable pages from _end[].
- changed to map only the required amount for PA=VA identity mapping
(kernel image, UART device, and FDT blob) with L2_BLOCK(2Mbyte).
- changing page permission for kernel image, and making KSEG mapping are done
at cpu_kernel_vm_init() instead of at locore.
- optimize PTE entries with PTE Contiguous bit. it is enabled on devmap only for now.

reviewed by skrll@, thanks.


# 1.25 04-Oct-2018 ryo

* define LX_BLKPAG_{OS,ATTR}_* for OS dependent PTE attributes in pmap.h
* cleanup macros


Revision tags: pgoyette-compat-0930
# 1.24 17-Sep-2018 ryo

delete debug printf and KASSERT.


# 1.23 10-Sep-2018 maxv

Replace KDASSERT by panic.


# 1.22 10-Sep-2018 maxv

Rename _pmap_alloc_pdp -> pmap_alloc_pdp, and make it public.


# 1.21 10-Sep-2018 ryo

cleanup aarch64 mpstart and fdt bootstrap
* arm_cpu_hatch_arg is a bad idea. avoid serializing CPU startup, and eliminate arm_cpu_hatch_arg.
in mpstart, resolve own cpu index using array of cpu_mpidr[] (aarch64)
* add support fdt enable-method "spin-table"
* add support fdt enable-method "brcm,bcm2836-smp" (for 32bit RaspberryPi)
* use arm_fdt_cpu_bootstrap() instead of psci_fdt_bootstrap()
* rename "arm/fdt/psci_fdt.h" to "arm/fdt/psci_fdtvar.h" because of conflict of include file for needs-flag
* add devmap for cpu spin-table of raspberrypi3/aarch64
* no need to force hatch APs for raspberrypi3/arm32 ifndef MULTIPROCESSOR.
* fix to work pmap_extract(kerneltext/data/bss) even if before calling pmap_bootstrap

idea to use cpu_mpidr[] by jmcneill@. reviewd by skrll@. thanks.


Revision tags: pgoyette-compat-0906
# 1.20 27-Aug-2018 ryo

need to add VM_PROT_READ when pmap_kenter_pa(va, pa, VM_PROT_WRITE, 0) or pmap_kenter_pa(va, pa, VM_PROT_EXECUTE, 0).
VM_PROT_READ is treated as an access permission inernally.


# 1.19 11-Aug-2018 ryo

change to minimum invalidation of TLB.
specifying not only va but also asid, and not invalidate L0-L2 entry using tlbi_*_ll() if needed.


# 1.18 10-Aug-2018 ryo

treat kernel-exec attr and user-exec attr separately.
kernel cannot execute userland exec page, and user cannot execute kernel page.


# 1.17 06-Aug-2018 ryo

set kernel text/rodata readonly by default.
add function db_write_text() for setting ddb breakpoint.


# 1.16 31-Jul-2018 skrll

Define and use VPRINTF


Revision tags: pgoyette-compat-0728
# 1.15 27-Jul-2018 ryo

changes of pmap.c r1.13 seems to be unstable.
In order to invalidate icache, not to invalidate all icache,
but temporary to make the page writable and invalidate target address only.


# 1.14 24-Jul-2018 ryo

don't call pool_cache_put with locking pmap. pool_cache_put call pmap_kenter_pa internally.
(pool_cache_put_paddr -> pool_cache_put_slow -> pool_get -> pmap_kenter_pa)


# 1.13 23-Jul-2018 ryo

* fix icache invalidations.
* "ic ivau" (aarch64_icache_sync_range) with VA generates permission fault in some situations, therefore use KSEG address for now.


# 1.12 23-Jul-2018 ryo

rather than using flags to resolve nested locks, reserve pool_cache before locking.


# 1.11 21-Jul-2018 ryo

* avoid deadlock. mutex_owned() works only for adaptive lock, therefore we cannot use it for spinlock...
* add more NULL check
* clear pte when pmap_enter() fails


# 1.10 17-Jul-2018 ryo

Use __debugused


# 1.9 17-Jul-2018 christos

Add missing casts, remove unused variables.


# 1.8 09-Jul-2018 ryo

need locks in pmap_kremove() and pmap_fault_fixup()


Revision tags: phil-wifi-base pgoyette-compat-0625 pgoyette-compat-0521
# 1.7 20-May-2018 ryo

branches: 1.7.2;
pmap_enter() must update modified/referenced flags by 'flags' not 'prot'.


# 1.6 16-May-2018 ryo

Fix memory leak. it was leaking one page every pmap_create().
pm->pm_vmlist must be initialized before calling _pmap_alloc_pdp().


Revision tags: pgoyette-compat-0502
# 1.5 29-Apr-2018 ryo

fix KASSERT panic. pv_entry may not be exists in pvlist when pmap_remove().


# 1.4 29-Apr-2018 ryo

delete unused code


# 1.3 27-Apr-2018 ryo

fix instability behavior of bufcache on aarch64.
* fix to return correct ref/mod when PMAP_WIRED.
* changed to keep wired flags in pte instead of pv_entry, and cleanup.


Revision tags: pgoyette-compat-0422 pgoyette-compat-0415 pgoyette-compat-0407
# 1.2 01-Apr-2018 ryo

Add initial support for ARMv8 (AARCH64) (by nisimura@ and ryo@)

- sys/arch/evbarm64 is gone and integrated into sys/arch/evbarm. (by skrll@)
- add support fdt. evbarm/conf/GENERIC64 fdt (bcm2837,sunxi,tegra) based generic 64bit kernel config. (by skrll@, jmcneill@)


Revision tags: netbsd-8-1-RELEASE netbsd-8-1-RC1 netbsd-7-2-RELEASE netbsd-8-0-RELEASE netbsd-8-0-RC2 netbsd-8-0-RC1 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 netbsd-7-1-2-RELEASE pgoyette-compat-base netbsd-7-1-1-RELEASE tls-maxphys-base-20171202 matt-nb8-mediatek-base nick-nhusb-base-20170825 perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base pgoyette-localcount-20170320 netbsd-7-1-RELEASE netbsd-7-1-RC2 nick-nhusb-base-20170204 netbsd-7-nhusb-base-20170116 bouyer-socketcan-base pgoyette-localcount-20170107 netbsd-7-1-RC1 nick-nhusb-base-20161204 pgoyette-localcount-20161104 netbsd-7-0-2-RELEASE nick-nhusb-base-20161004 localcount-20160914 netbsd-7-nhusb-base pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907 nick-nhusb-base-20160529 netbsd-7-0-1-RELEASE nick-nhusb-base-20160422 nick-nhusb-base-20160319 nick-nhusb-base-20151226 netbsd-7-0-RELEASE nick-nhusb-base-20150921 netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 nick-nhusb-base-20150606 nick-nhusb-base-20150406 nick-nhusb-base tls-maxphys-base netbsd-7-base
# 1.1 10-Aug-2014 matt

branches: 1.1.4; 1.1.28;
Preliminary files for AARCH64 (64-bit ARM) support.
Enough for a distribution build.


# 1.58 28-Dec-2019 jmcneill

Do not use Early Write Acknowledge for PCIe I/O and config space.


# 1.57 27-Dec-2019 jmcneill

Enable early write acknowledge for device memory mappings.


# 1.56 19-Dec-2019 skrll

G/C kasan_shadow_map call in pmap_enter

pmap_growkernel calls kasan_shadow_map for KVA


# 1.55 18-Dec-2019 ryo

atomic_add_16() is not used in pmap.c anymore. no need decl here.


# 1.54 18-Dec-2019 ryo

space to tab


# 1.53 14-Dec-2019 skrll

Fix build... wire_count probably doesn't need atomics


# 1.52 13-Dec-2019 skrll

Fix KASAN support by calling kasan_shadow_map in pmap_growkernel


# 1.51 10-Dec-2019 ad

pg->phys_addr -> VM_PAGE_TO_PHYS(pg)


Revision tags: phil-wifi-20191119
# 1.50 14-Nov-2019 maxv

Mark several kASan functions with __nothing, to avoid annoying #ifdefs.
Same as kCSan and kMSan.


# 1.49 14-Nov-2019 maxv

Don't include "opt_kasan.h" when there's already <sys/asan.h> included.


# 1.48 29-Oct-2019 maya

Define PMAP_NEED_PROCWR, providing strategically placed i-cache
synchronization where just-changed memory is about to be executed.

Fixes SIGILLs seen when running Mono 6 on QEMU Cortex-A57.

ok ryo


# 1.47 22-Sep-2019 jmcneill

Disable translation table walks using TTBR0 while changing its value and
when deactivating a pmap. Fixes stability issues on Ampere eMAG CPUs.


# 1.46 20-Sep-2019 ryo

ref/mod bit should be set according to 'flags' argument, not 'prot'. r1.44 was incomplete.


# 1.45 13-Sep-2019 ryo

In pmap_devmap_bootstrap(), cpu_earlydevice_va_p() must not return true until *all* devmap tables have been enabled.
console mapping may be present in the last table.


# 1.44 07-Sep-2019 ryo

- remove incorrect KASSERT. mmap(2) with prot=PROT_WRITE calls pmap_enter(..., PROT_WRITE) internally.
- fix to update page reference flags when only PROT_WRITE or PROT_EXECUTE specified


# 1.43 15-Aug-2019 skrll

Make pmap_db_pte_print more terse so it's quicker on serial consoles


# 1.42 12-Aug-2019 skrll

Use PMAP_DEV in DEVMAP_ENTRY rather than pmap_map_chunk. It's clearer and
means pmap_map_chunk can be made to map other memory types.


Revision tags: netbsd-9-base phil-wifi-20190609
# 1.41 17-May-2019 mrg

branches: 1.41.2;
apply some __diagused.


Revision tags: isaki-audio2-base
# 1.40 08-Apr-2019 ryo

- free empty page tables pages if reach a certain usage.
- need to lock at removing an old pg (_pmap_remove_pv) in _pmap_enter()


# 1.39 06-Apr-2019 ryo

Fix race conditions about pmap_page_protect() and pmap_enter().

while handling same PTE by these functions in same time, there
is a critical path that the number of valid PTEs and wire_count
are inconsistent, and it caused KASSERT.
Need to hold a pv_lock while modifying them.


# 1.38 20-Mar-2019 ryo

spinkle __printflike(), and use PRIxxx


# 1.37 19-Mar-2019 ryo

- add ddb command "machine ttbr" to dump MMU tables.
- tidy up descriptions, usages and messages.


# 1.36 19-Mar-2019 ryo

- free L1-L3 pages that has been emptied by pmap_remove().
- if no memories, pmap_enter will return correctly ENOMEM if PMAP_CANFAIL, or wait until available any memories if !PMAP_CANFAIL.

These changes improves the stability when we use a huge virtual memory spaces with mmap.


# 1.35 06-Feb-2019 ryo

improve pmap_remove
- don't lock/unlock per page in pmap_remove()
- speedup pte lookup for continuous addresses
- bring out pool_cache_put(&_pmap_pv_pool, pv) from lock/unlock section


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226
# 1.34 21-Dec-2018 ryo

- add workaround for Cavium ThunderX errata 27456.
- add cpufuncs table in cpu_info. each cpu clusters may have different erratum. (e.g. big.LITTLE)


Revision tags: pgoyette-compat-1126
# 1.33 01-Nov-2018 maxv

Add kASan support for aarch64. Stack tracking needs more investigation
and will come in a separate commit.

Reviewed by ryo@ jmcneill@ skrll@.


# 1.32 31-Oct-2018 ryo

invalidate icache correctly.
l3pte_executable() should be used for only valid pte.


Revision tags: pgoyette-compat-1020
# 1.31 18-Oct-2018 skrll

Provide generic start code that assumes the MMU is off and caches are
disabled as per the linux booting protocol for ARMv6 and ARMv7 boards.
u-boot image type should be changed to 'linux' for correct behaviour.

The new start code builds a minimal "bootstrap" L1PT with cached access
disabled and uses the same table for all processors. AP startup is
performed in less steps and more code is written in C.

The bootstrap tables and stack are placed into an (orphaned) section
"_init_memory" which is given to uvm when it is no longer used.

Various kernels have been converted to use this code and tested. Some
boards were provided by TNF. Thanks!

The GENERIC kernel now boots on boards using the TEGRA, SUNXI and EXYNOS
kernels. The GENERIC kernel will also work on RPI2 using u-boot.

Thanks to martin@ and aymeric@ for testing on parallella and nanosoc
respectively


# 1.30 14-Oct-2018 skrll

Use __nothing


# 1.29 12-Oct-2018 ryo

add initial support of COMPAT_NETBSD32 on AArch64.
arm ELF32 EABI binaries could be execute in AArch32 state on AArch64. A32 THUMB mode is not supported yet.


# 1.28 12-Oct-2018 ryo

- cleanup checking address ranges with IN_RANGE macro
- change PM_ADDR_CHECK macro to KASSERTMSG
- restore fast lookup cases with IN_RANGE macro for pmap_extract changed in my previous commit.


# 1.27 12-Oct-2018 ryo

rewrite pmap_pte_lookup() to share similar code.


# 1.26 04-Oct-2018 ryo

cleanup locore, and changed the way to map memories during boot.
- add functions bootpage_enter() and bootpage_alloc() to adapt various layout
of physical memory map. especially for 64bit physical memory layout.
pmapboot_alloc() allocates pagetable pages from _end[].
- changed to map only the required amount for PA=VA identity mapping
(kernel image, UART device, and FDT blob) with L2_BLOCK(2Mbyte).
- changing page permission for kernel image, and making KSEG mapping are done
at cpu_kernel_vm_init() instead of at locore.
- optimize PTE entries with PTE Contiguous bit. it is enabled on devmap only for now.

reviewed by skrll@, thanks.


# 1.25 04-Oct-2018 ryo

* define LX_BLKPAG_{OS,ATTR}_* for OS dependent PTE attributes in pmap.h
* cleanup macros


Revision tags: pgoyette-compat-0930
# 1.24 17-Sep-2018 ryo

delete debug printf and KASSERT.


# 1.23 10-Sep-2018 maxv

Replace KDASSERT by panic.


# 1.22 10-Sep-2018 maxv

Rename _pmap_alloc_pdp -> pmap_alloc_pdp, and make it public.


# 1.21 10-Sep-2018 ryo

cleanup aarch64 mpstart and fdt bootstrap
* arm_cpu_hatch_arg is a bad idea. avoid serializing CPU startup, and eliminate arm_cpu_hatch_arg.
in mpstart, resolve own cpu index using array of cpu_mpidr[] (aarch64)
* add support fdt enable-method "spin-table"
* add support fdt enable-method "brcm,bcm2836-smp" (for 32bit RaspberryPi)
* use arm_fdt_cpu_bootstrap() instead of psci_fdt_bootstrap()
* rename "arm/fdt/psci_fdt.h" to "arm/fdt/psci_fdtvar.h" because of conflict of include file for needs-flag
* add devmap for cpu spin-table of raspberrypi3/aarch64
* no need to force hatch APs for raspberrypi3/arm32 ifndef MULTIPROCESSOR.
* fix to work pmap_extract(kerneltext/data/bss) even if before calling pmap_bootstrap

idea to use cpu_mpidr[] by jmcneill@. reviewd by skrll@. thanks.


Revision tags: pgoyette-compat-0906
# 1.20 27-Aug-2018 ryo

need to add VM_PROT_READ when pmap_kenter_pa(va, pa, VM_PROT_WRITE, 0) or pmap_kenter_pa(va, pa, VM_PROT_EXECUTE, 0).
VM_PROT_READ is treated as an access permission inernally.


# 1.19 11-Aug-2018 ryo

change to minimum invalidation of TLB.
specifying not only va but also asid, and not invalidate L0-L2 entry using tlbi_*_ll() if needed.


# 1.18 10-Aug-2018 ryo

treat kernel-exec attr and user-exec attr separately.
kernel cannot execute userland exec page, and user cannot execute kernel page.


# 1.17 06-Aug-2018 ryo

set kernel text/rodata readonly by default.
add function db_write_text() for setting ddb breakpoint.


# 1.16 31-Jul-2018 skrll

Define and use VPRINTF


Revision tags: pgoyette-compat-0728
# 1.15 27-Jul-2018 ryo

changes of pmap.c r1.13 seems to be unstable.
In order to invalidate icache, not to invalidate all icache,
but temporary to make the page writable and invalidate target address only.


# 1.14 24-Jul-2018 ryo

don't call pool_cache_put with locking pmap. pool_cache_put call pmap_kenter_pa internally.
(pool_cache_put_paddr -> pool_cache_put_slow -> pool_get -> pmap_kenter_pa)


# 1.13 23-Jul-2018 ryo

* fix icache invalidations.
* "ic ivau" (aarch64_icache_sync_range) with VA generates permission fault in some situations, therefore use KSEG address for now.


# 1.12 23-Jul-2018 ryo

rather than using flags to resolve nested locks, reserve pool_cache before locking.


# 1.11 21-Jul-2018 ryo

* avoid deadlock. mutex_owned() works only for adaptive lock, therefore we cannot use it for spinlock...
* add more NULL check
* clear pte when pmap_enter() fails


# 1.10 17-Jul-2018 ryo

Use __debugused


# 1.9 17-Jul-2018 christos

Add missing casts, remove unused variables.


# 1.8 09-Jul-2018 ryo

need locks in pmap_kremove() and pmap_fault_fixup()


Revision tags: phil-wifi-base pgoyette-compat-0625 pgoyette-compat-0521
# 1.7 20-May-2018 ryo

branches: 1.7.2;
pmap_enter() must update modified/referenced flags by 'flags' not 'prot'.


# 1.6 16-May-2018 ryo

Fix memory leak. it was leaking one page every pmap_create().
pm->pm_vmlist must be initialized before calling _pmap_alloc_pdp().


Revision tags: pgoyette-compat-0502
# 1.5 29-Apr-2018 ryo

fix KASSERT panic. pv_entry may not be exists in pvlist when pmap_remove().


# 1.4 29-Apr-2018 ryo

delete unused code


# 1.3 27-Apr-2018 ryo

fix instability behavior of bufcache on aarch64.
* fix to return correct ref/mod when PMAP_WIRED.
* changed to keep wired flags in pte instead of pv_entry, and cleanup.


Revision tags: pgoyette-compat-0422 pgoyette-compat-0415 pgoyette-compat-0407
# 1.2 01-Apr-2018 ryo

Add initial support for ARMv8 (AARCH64) (by nisimura@ and ryo@)

- sys/arch/evbarm64 is gone and integrated into sys/arch/evbarm. (by skrll@)
- add support fdt. evbarm/conf/GENERIC64 fdt (bcm2837,sunxi,tegra) based generic 64bit kernel config. (by skrll@, jmcneill@)


Revision tags: netbsd-8-1-RELEASE netbsd-8-1-RC1 netbsd-7-2-RELEASE netbsd-8-0-RELEASE netbsd-8-0-RC2 netbsd-8-0-RC1 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 netbsd-7-1-2-RELEASE pgoyette-compat-base netbsd-7-1-1-RELEASE tls-maxphys-base-20171202 matt-nb8-mediatek-base nick-nhusb-base-20170825 perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base pgoyette-localcount-20170320 netbsd-7-1-RELEASE netbsd-7-1-RC2 nick-nhusb-base-20170204 netbsd-7-nhusb-base-20170116 bouyer-socketcan-base pgoyette-localcount-20170107 netbsd-7-1-RC1 nick-nhusb-base-20161204 pgoyette-localcount-20161104 netbsd-7-0-2-RELEASE nick-nhusb-base-20161004 localcount-20160914 netbsd-7-nhusb-base pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907 nick-nhusb-base-20160529 netbsd-7-0-1-RELEASE nick-nhusb-base-20160422 nick-nhusb-base-20160319 nick-nhusb-base-20151226 netbsd-7-0-RELEASE nick-nhusb-base-20150921 netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 nick-nhusb-base-20150606 nick-nhusb-base-20150406 nick-nhusb-base tls-maxphys-base netbsd-7-base
# 1.1 10-Aug-2014 matt

branches: 1.1.4; 1.1.28;
Preliminary files for AARCH64 (64-bit ARM) support.
Enough for a distribution build.


# 1.57 27-Dec-2019 jmcneill

Enable early write acknowledge for device memory mappings.


# 1.56 19-Dec-2019 skrll

G/C kasan_shadow_map call in pmap_enter

pmap_growkernel calls kasan_shadow_map for KVA


# 1.55 18-Dec-2019 ryo

atomic_add_16() is not used in pmap.c anymore. no need decl here.


# 1.54 18-Dec-2019 ryo

space to tab


# 1.53 14-Dec-2019 skrll

Fix build... wire_count probably doesn't need atomics


# 1.52 13-Dec-2019 skrll

Fix KASAN support by calling kasan_shadow_map in pmap_growkernel


# 1.51 10-Dec-2019 ad

pg->phys_addr -> VM_PAGE_TO_PHYS(pg)


Revision tags: phil-wifi-20191119
# 1.50 14-Nov-2019 maxv

Mark several kASan functions with __nothing, to avoid annoying #ifdefs.
Same as kCSan and kMSan.


# 1.49 14-Nov-2019 maxv

Don't include "opt_kasan.h" when there's already <sys/asan.h> included.


# 1.48 29-Oct-2019 maya

Define PMAP_NEED_PROCWR, providing strategically placed i-cache
synchronization where just-changed memory is about to be executed.

Fixes SIGILLs seen when running Mono 6 on QEMU Cortex-A57.

ok ryo


# 1.47 22-Sep-2019 jmcneill

Disable translation table walks using TTBR0 while changing its value and
when deactivating a pmap. Fixes stability issues on Ampere eMAG CPUs.


# 1.46 20-Sep-2019 ryo

ref/mod bit should be set according to 'flags' argument, not 'prot'. r1.44 was incomplete.


# 1.45 13-Sep-2019 ryo

In pmap_devmap_bootstrap(), cpu_earlydevice_va_p() must not return true until *all* devmap tables have been enabled.
console mapping may be present in the last table.


# 1.44 07-Sep-2019 ryo

- remove incorrect KASSERT. mmap(2) with prot=PROT_WRITE calls pmap_enter(..., PROT_WRITE) internally.
- fix to update page reference flags when only PROT_WRITE or PROT_EXECUTE specified


# 1.43 15-Aug-2019 skrll

Make pmap_db_pte_print more terse so it's quicker on serial consoles


# 1.42 12-Aug-2019 skrll

Use PMAP_DEV in DEVMAP_ENTRY rather than pmap_map_chunk. It's clearer and
means pmap_map_chunk can be made to map other memory types.


Revision tags: netbsd-9-base phil-wifi-20190609
# 1.41 17-May-2019 mrg

branches: 1.41.2;
apply some __diagused.


Revision tags: isaki-audio2-base
# 1.40 08-Apr-2019 ryo

- free empty page tables pages if reach a certain usage.
- need to lock at removing an old pg (_pmap_remove_pv) in _pmap_enter()


# 1.39 06-Apr-2019 ryo

Fix race conditions about pmap_page_protect() and pmap_enter().

while handling same PTE by these functions in same time, there
is a critical path that the number of valid PTEs and wire_count
are inconsistent, and it caused KASSERT.
Need to hold a pv_lock while modifying them.


# 1.38 20-Mar-2019 ryo

spinkle __printflike(), and use PRIxxx


# 1.37 19-Mar-2019 ryo

- add ddb command "machine ttbr" to dump MMU tables.
- tidy up descriptions, usages and messages.


# 1.36 19-Mar-2019 ryo

- free L1-L3 pages that has been emptied by pmap_remove().
- if no memories, pmap_enter will return correctly ENOMEM if PMAP_CANFAIL, or wait until available any memories if !PMAP_CANFAIL.

These changes improves the stability when we use a huge virtual memory spaces with mmap.


# 1.35 06-Feb-2019 ryo

improve pmap_remove
- don't lock/unlock per page in pmap_remove()
- speedup pte lookup for continuous addresses
- bring out pool_cache_put(&_pmap_pv_pool, pv) from lock/unlock section


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226
# 1.34 21-Dec-2018 ryo

- add workaround for Cavium ThunderX errata 27456.
- add cpufuncs table in cpu_info. each cpu clusters may have different erratum. (e.g. big.LITTLE)


Revision tags: pgoyette-compat-1126
# 1.33 01-Nov-2018 maxv

Add kASan support for aarch64. Stack tracking needs more investigation
and will come in a separate commit.

Reviewed by ryo@ jmcneill@ skrll@.


# 1.32 31-Oct-2018 ryo

invalidate icache correctly.
l3pte_executable() should be used for only valid pte.


Revision tags: pgoyette-compat-1020
# 1.31 18-Oct-2018 skrll

Provide generic start code that assumes the MMU is off and caches are
disabled as per the linux booting protocol for ARMv6 and ARMv7 boards.
u-boot image type should be changed to 'linux' for correct behaviour.

The new start code builds a minimal "bootstrap" L1PT with cached access
disabled and uses the same table for all processors. AP startup is
performed in less steps and more code is written in C.

The bootstrap tables and stack are placed into an (orphaned) section
"_init_memory" which is given to uvm when it is no longer used.

Various kernels have been converted to use this code and tested. Some
boards were provided by TNF. Thanks!

The GENERIC kernel now boots on boards using the TEGRA, SUNXI and EXYNOS
kernels. The GENERIC kernel will also work on RPI2 using u-boot.

Thanks to martin@ and aymeric@ for testing on parallella and nanosoc
respectively


# 1.30 14-Oct-2018 skrll

Use __nothing


# 1.29 12-Oct-2018 ryo

add initial support of COMPAT_NETBSD32 on AArch64.
arm ELF32 EABI binaries could be execute in AArch32 state on AArch64. A32 THUMB mode is not supported yet.


# 1.28 12-Oct-2018 ryo

- cleanup checking address ranges with IN_RANGE macro
- change PM_ADDR_CHECK macro to KASSERTMSG
- restore fast lookup cases with IN_RANGE macro for pmap_extract changed in my previous commit.


# 1.27 12-Oct-2018 ryo

rewrite pmap_pte_lookup() to share similar code.


# 1.26 04-Oct-2018 ryo

cleanup locore, and changed the way to map memories during boot.
- add functions bootpage_enter() and bootpage_alloc() to adapt various layout
of physical memory map. especially for 64bit physical memory layout.
pmapboot_alloc() allocates pagetable pages from _end[].
- changed to map only the required amount for PA=VA identity mapping
(kernel image, UART device, and FDT blob) with L2_BLOCK(2Mbyte).
- changing page permission for kernel image, and making KSEG mapping are done
at cpu_kernel_vm_init() instead of at locore.
- optimize PTE entries with PTE Contiguous bit. it is enabled on devmap only for now.

reviewed by skrll@, thanks.


# 1.25 04-Oct-2018 ryo

* define LX_BLKPAG_{OS,ATTR}_* for OS dependent PTE attributes in pmap.h
* cleanup macros


Revision tags: pgoyette-compat-0930
# 1.24 17-Sep-2018 ryo

delete debug printf and KASSERT.


# 1.23 10-Sep-2018 maxv

Replace KDASSERT by panic.


# 1.22 10-Sep-2018 maxv

Rename _pmap_alloc_pdp -> pmap_alloc_pdp, and make it public.


# 1.21 10-Sep-2018 ryo

cleanup aarch64 mpstart and fdt bootstrap
* arm_cpu_hatch_arg is a bad idea. avoid serializing CPU startup, and eliminate arm_cpu_hatch_arg.
in mpstart, resolve own cpu index using array of cpu_mpidr[] (aarch64)
* add support fdt enable-method "spin-table"
* add support fdt enable-method "brcm,bcm2836-smp" (for 32bit RaspberryPi)
* use arm_fdt_cpu_bootstrap() instead of psci_fdt_bootstrap()
* rename "arm/fdt/psci_fdt.h" to "arm/fdt/psci_fdtvar.h" because of conflict of include file for needs-flag
* add devmap for cpu spin-table of raspberrypi3/aarch64
* no need to force hatch APs for raspberrypi3/arm32 ifndef MULTIPROCESSOR.
* fix to work pmap_extract(kerneltext/data/bss) even if before calling pmap_bootstrap

idea to use cpu_mpidr[] by jmcneill@. reviewd by skrll@. thanks.


Revision tags: pgoyette-compat-0906
# 1.20 27-Aug-2018 ryo

need to add VM_PROT_READ when pmap_kenter_pa(va, pa, VM_PROT_WRITE, 0) or pmap_kenter_pa(va, pa, VM_PROT_EXECUTE, 0).
VM_PROT_READ is treated as an access permission inernally.


# 1.19 11-Aug-2018 ryo

change to minimum invalidation of TLB.
specifying not only va but also asid, and not invalidate L0-L2 entry using tlbi_*_ll() if needed.


# 1.18 10-Aug-2018 ryo

treat kernel-exec attr and user-exec attr separately.
kernel cannot execute userland exec page, and user cannot execute kernel page.


# 1.17 06-Aug-2018 ryo

set kernel text/rodata readonly by default.
add function db_write_text() for setting ddb breakpoint.


# 1.16 31-Jul-2018 skrll

Define and use VPRINTF


Revision tags: pgoyette-compat-0728
# 1.15 27-Jul-2018 ryo

changes of pmap.c r1.13 seems to be unstable.
In order to invalidate icache, not to invalidate all icache,
but temporary to make the page writable and invalidate target address only.


# 1.14 24-Jul-2018 ryo

don't call pool_cache_put with locking pmap. pool_cache_put call pmap_kenter_pa internally.
(pool_cache_put_paddr -> pool_cache_put_slow -> pool_get -> pmap_kenter_pa)


# 1.13 23-Jul-2018 ryo

* fix icache invalidations.
* "ic ivau" (aarch64_icache_sync_range) with VA generates permission fault in some situations, therefore use KSEG address for now.


# 1.12 23-Jul-2018 ryo

rather than using flags to resolve nested locks, reserve pool_cache before locking.


# 1.11 21-Jul-2018 ryo

* avoid deadlock. mutex_owned() works only for adaptive lock, therefore we cannot use it for spinlock...
* add more NULL check
* clear pte when pmap_enter() fails


# 1.10 17-Jul-2018 ryo

Use __debugused


# 1.9 17-Jul-2018 christos

Add missing casts, remove unused variables.


# 1.8 09-Jul-2018 ryo

need locks in pmap_kremove() and pmap_fault_fixup()


Revision tags: phil-wifi-base pgoyette-compat-0625 pgoyette-compat-0521
# 1.7 20-May-2018 ryo

branches: 1.7.2;
pmap_enter() must update modified/referenced flags by 'flags' not 'prot'.


# 1.6 16-May-2018 ryo

Fix memory leak. it was leaking one page every pmap_create().
pm->pm_vmlist must be initialized before calling _pmap_alloc_pdp().


Revision tags: pgoyette-compat-0502
# 1.5 29-Apr-2018 ryo

fix KASSERT panic. pv_entry may not be exists in pvlist when pmap_remove().


# 1.4 29-Apr-2018 ryo

delete unused code


# 1.3 27-Apr-2018 ryo

fix instability behavior of bufcache on aarch64.
* fix to return correct ref/mod when PMAP_WIRED.
* changed to keep wired flags in pte instead of pv_entry, and cleanup.


Revision tags: pgoyette-compat-0422 pgoyette-compat-0415 pgoyette-compat-0407
# 1.2 01-Apr-2018 ryo

Add initial support for ARMv8 (AARCH64) (by nisimura@ and ryo@)

- sys/arch/evbarm64 is gone and integrated into sys/arch/evbarm. (by skrll@)
- add support fdt. evbarm/conf/GENERIC64 fdt (bcm2837,sunxi,tegra) based generic 64bit kernel config. (by skrll@, jmcneill@)


Revision tags: netbsd-8-1-RELEASE netbsd-8-1-RC1 netbsd-7-2-RELEASE netbsd-8-0-RELEASE netbsd-8-0-RC2 netbsd-8-0-RC1 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 netbsd-7-1-2-RELEASE pgoyette-compat-base netbsd-7-1-1-RELEASE tls-maxphys-base-20171202 matt-nb8-mediatek-base nick-nhusb-base-20170825 perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base pgoyette-localcount-20170320 netbsd-7-1-RELEASE netbsd-7-1-RC2 nick-nhusb-base-20170204 netbsd-7-nhusb-base-20170116 bouyer-socketcan-base pgoyette-localcount-20170107 netbsd-7-1-RC1 nick-nhusb-base-20161204 pgoyette-localcount-20161104 netbsd-7-0-2-RELEASE nick-nhusb-base-20161004 localcount-20160914 netbsd-7-nhusb-base pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907 nick-nhusb-base-20160529 netbsd-7-0-1-RELEASE nick-nhusb-base-20160422 nick-nhusb-base-20160319 nick-nhusb-base-20151226 netbsd-7-0-RELEASE nick-nhusb-base-20150921 netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 nick-nhusb-base-20150606 nick-nhusb-base-20150406 nick-nhusb-base tls-maxphys-base netbsd-7-base
# 1.1 10-Aug-2014 matt

branches: 1.1.4; 1.1.28;
Preliminary files for AARCH64 (64-bit ARM) support.
Enough for a distribution build.


# 1.56 19-Dec-2019 skrll

G/C kasan_shadow_map call in pmap_enter

pmap_growkernel calls kasan_shadow_map for KVA


# 1.55 18-Dec-2019 ryo

atomic_add_16() is not used in pmap.c anymore. no need decl here.


# 1.54 18-Dec-2019 ryo

space to tab


# 1.53 14-Dec-2019 skrll

Fix build... wire_count probably doesn't need atomics


# 1.52 13-Dec-2019 skrll

Fix KASAN support by calling kasan_shadow_map in pmap_growkernel


# 1.51 10-Dec-2019 ad

pg->phys_addr -> VM_PAGE_TO_PHYS(pg)


Revision tags: phil-wifi-20191119
# 1.50 14-Nov-2019 maxv

Mark several kASan functions with __nothing, to avoid annoying #ifdefs.
Same as kCSan and kMSan.


# 1.49 14-Nov-2019 maxv

Don't include "opt_kasan.h" when there's already <sys/asan.h> included.


# 1.48 29-Oct-2019 maya

Define PMAP_NEED_PROCWR, providing strategically placed i-cache
synchronization where just-changed memory is about to be executed.

Fixes SIGILLs seen when running Mono 6 on QEMU Cortex-A57.

ok ryo


# 1.47 22-Sep-2019 jmcneill

Disable translation table walks using TTBR0 while changing its value and
when deactivating a pmap. Fixes stability issues on Ampere eMAG CPUs.


# 1.46 20-Sep-2019 ryo

ref/mod bit should be set according to 'flags' argument, not 'prot'. r1.44 was incomplete.


# 1.45 13-Sep-2019 ryo

In pmap_devmap_bootstrap(), cpu_earlydevice_va_p() must not return true until *all* devmap tables have been enabled.
console mapping may be present in the last table.


# 1.44 07-Sep-2019 ryo

- remove incorrect KASSERT. mmap(2) with prot=PROT_WRITE calls pmap_enter(..., PROT_WRITE) internally.
- fix to update page reference flags when only PROT_WRITE or PROT_EXECUTE specified


# 1.43 15-Aug-2019 skrll

Make pmap_db_pte_print more terse so it's quicker on serial consoles


# 1.42 12-Aug-2019 skrll

Use PMAP_DEV in DEVMAP_ENTRY rather than pmap_map_chunk. It's clearer and
means pmap_map_chunk can be made to map other memory types.


Revision tags: netbsd-9-base phil-wifi-20190609
# 1.41 17-May-2019 mrg

branches: 1.41.2;
apply some __diagused.


Revision tags: isaki-audio2-base
# 1.40 08-Apr-2019 ryo

- free empty page tables pages if reach a certain usage.
- need to lock at removing an old pg (_pmap_remove_pv) in _pmap_enter()


# 1.39 06-Apr-2019 ryo

Fix race conditions about pmap_page_protect() and pmap_enter().

while handling same PTE by these functions in same time, there
is a critical path that the number of valid PTEs and wire_count
are inconsistent, and it caused KASSERT.
Need to hold a pv_lock while modifying them.


# 1.38 20-Mar-2019 ryo

spinkle __printflike(), and use PRIxxx


# 1.37 19-Mar-2019 ryo

- add ddb command "machine ttbr" to dump MMU tables.
- tidy up descriptions, usages and messages.


# 1.36 19-Mar-2019 ryo

- free L1-L3 pages that has been emptied by pmap_remove().
- if no memories, pmap_enter will return correctly ENOMEM if PMAP_CANFAIL, or wait until available any memories if !PMAP_CANFAIL.

These changes improves the stability when we use a huge virtual memory spaces with mmap.


# 1.35 06-Feb-2019 ryo

improve pmap_remove
- don't lock/unlock per page in pmap_remove()
- speedup pte lookup for continuous addresses
- bring out pool_cache_put(&_pmap_pv_pool, pv) from lock/unlock section


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226
# 1.34 21-Dec-2018 ryo

- add workaround for Cavium ThunderX errata 27456.
- add cpufuncs table in cpu_info. each cpu clusters may have different erratum. (e.g. big.LITTLE)


Revision tags: pgoyette-compat-1126
# 1.33 01-Nov-2018 maxv

Add kASan support for aarch64. Stack tracking needs more investigation
and will come in a separate commit.

Reviewed by ryo@ jmcneill@ skrll@.


# 1.32 31-Oct-2018 ryo

invalidate icache correctly.
l3pte_executable() should be used for only valid pte.


Revision tags: pgoyette-compat-1020
# 1.31 18-Oct-2018 skrll

Provide generic start code that assumes the MMU is off and caches are
disabled as per the linux booting protocol for ARMv6 and ARMv7 boards.
u-boot image type should be changed to 'linux' for correct behaviour.

The new start code builds a minimal "bootstrap" L1PT with cached access
disabled and uses the same table for all processors. AP startup is
performed in less steps and more code is written in C.

The bootstrap tables and stack are placed into an (orphaned) section
"_init_memory" which is given to uvm when it is no longer used.

Various kernels have been converted to use this code and tested. Some
boards were provided by TNF. Thanks!

The GENERIC kernel now boots on boards using the TEGRA, SUNXI and EXYNOS
kernels. The GENERIC kernel will also work on RPI2 using u-boot.

Thanks to martin@ and aymeric@ for testing on parallella and nanosoc
respectively


# 1.30 14-Oct-2018 skrll

Use __nothing


# 1.29 12-Oct-2018 ryo

add initial support of COMPAT_NETBSD32 on AArch64.
arm ELF32 EABI binaries could be execute in AArch32 state on AArch64. A32 THUMB mode is not supported yet.


# 1.28 12-Oct-2018 ryo

- cleanup checking address ranges with IN_RANGE macro
- change PM_ADDR_CHECK macro to KASSERTMSG
- restore fast lookup cases with IN_RANGE macro for pmap_extract changed in my previous commit.


# 1.27 12-Oct-2018 ryo

rewrite pmap_pte_lookup() to share similar code.


# 1.26 04-Oct-2018 ryo

cleanup locore, and changed the way to map memories during boot.
- add functions bootpage_enter() and bootpage_alloc() to adapt various layout
of physical memory map. especially for 64bit physical memory layout.
pmapboot_alloc() allocates pagetable pages from _end[].
- changed to map only the required amount for PA=VA identity mapping
(kernel image, UART device, and FDT blob) with L2_BLOCK(2Mbyte).
- changing page permission for kernel image, and making KSEG mapping are done
at cpu_kernel_vm_init() instead of at locore.
- optimize PTE entries with PTE Contiguous bit. it is enabled on devmap only for now.

reviewed by skrll@, thanks.


# 1.25 04-Oct-2018 ryo

* define LX_BLKPAG_{OS,ATTR}_* for OS dependent PTE attributes in pmap.h
* cleanup macros


Revision tags: pgoyette-compat-0930
# 1.24 17-Sep-2018 ryo

delete debug printf and KASSERT.


# 1.23 10-Sep-2018 maxv

Replace KDASSERT by panic.


# 1.22 10-Sep-2018 maxv

Rename _pmap_alloc_pdp -> pmap_alloc_pdp, and make it public.


# 1.21 10-Sep-2018 ryo

cleanup aarch64 mpstart and fdt bootstrap
* arm_cpu_hatch_arg is a bad idea. avoid serializing CPU startup, and eliminate arm_cpu_hatch_arg.
in mpstart, resolve own cpu index using array of cpu_mpidr[] (aarch64)
* add support fdt enable-method "spin-table"
* add support fdt enable-method "brcm,bcm2836-smp" (for 32bit RaspberryPi)
* use arm_fdt_cpu_bootstrap() instead of psci_fdt_bootstrap()
* rename "arm/fdt/psci_fdt.h" to "arm/fdt/psci_fdtvar.h" because of conflict of include file for needs-flag
* add devmap for cpu spin-table of raspberrypi3/aarch64
* no need to force hatch APs for raspberrypi3/arm32 ifndef MULTIPROCESSOR.
* fix to work pmap_extract(kerneltext/data/bss) even if before calling pmap_bootstrap

idea to use cpu_mpidr[] by jmcneill@. reviewd by skrll@. thanks.


Revision tags: pgoyette-compat-0906
# 1.20 27-Aug-2018 ryo

need to add VM_PROT_READ when pmap_kenter_pa(va, pa, VM_PROT_WRITE, 0) or pmap_kenter_pa(va, pa, VM_PROT_EXECUTE, 0).
VM_PROT_READ is treated as an access permission inernally.


# 1.19 11-Aug-2018 ryo

change to minimum invalidation of TLB.
specifying not only va but also asid, and not invalidate L0-L2 entry using tlbi_*_ll() if needed.


# 1.18 10-Aug-2018 ryo

treat kernel-exec attr and user-exec attr separately.
kernel cannot execute userland exec page, and user cannot execute kernel page.


# 1.17 06-Aug-2018 ryo

set kernel text/rodata readonly by default.
add function db_write_text() for setting ddb breakpoint.


# 1.16 31-Jul-2018 skrll

Define and use VPRINTF


Revision tags: pgoyette-compat-0728
# 1.15 27-Jul-2018 ryo

changes of pmap.c r1.13 seems to be unstable.
In order to invalidate icache, not to invalidate all icache,
but temporary to make the page writable and invalidate target address only.


# 1.14 24-Jul-2018 ryo

don't call pool_cache_put with locking pmap. pool_cache_put call pmap_kenter_pa internally.
(pool_cache_put_paddr -> pool_cache_put_slow -> pool_get -> pmap_kenter_pa)


# 1.13 23-Jul-2018 ryo

* fix icache invalidations.
* "ic ivau" (aarch64_icache_sync_range) with VA generates permission fault in some situations, therefore use KSEG address for now.


# 1.12 23-Jul-2018 ryo

rather than using flags to resolve nested locks, reserve pool_cache before locking.


# 1.11 21-Jul-2018 ryo

* avoid deadlock. mutex_owned() works only for adaptive lock, therefore we cannot use it for spinlock...
* add more NULL check
* clear pte when pmap_enter() fails


# 1.10 17-Jul-2018 ryo

Use __debugused


# 1.9 17-Jul-2018 christos

Add missing casts, remove unused variables.


# 1.8 09-Jul-2018 ryo

need locks in pmap_kremove() and pmap_fault_fixup()


Revision tags: phil-wifi-base pgoyette-compat-0625 pgoyette-compat-0521
# 1.7 20-May-2018 ryo

branches: 1.7.2;
pmap_enter() must update modified/referenced flags by 'flags' not 'prot'.


# 1.6 16-May-2018 ryo

Fix memory leak. it was leaking one page every pmap_create().
pm->pm_vmlist must be initialized before calling _pmap_alloc_pdp().


Revision tags: pgoyette-compat-0502
# 1.5 29-Apr-2018 ryo

fix KASSERT panic. pv_entry may not be exists in pvlist when pmap_remove().


# 1.4 29-Apr-2018 ryo

delete unused code


# 1.3 27-Apr-2018 ryo

fix instability behavior of bufcache on aarch64.
* fix to return correct ref/mod when PMAP_WIRED.
* changed to keep wired flags in pte instead of pv_entry, and cleanup.


Revision tags: pgoyette-compat-0422 pgoyette-compat-0415 pgoyette-compat-0407
# 1.2 01-Apr-2018 ryo

Add initial support for ARMv8 (AARCH64) (by nisimura@ and ryo@)

- sys/arch/evbarm64 is gone and integrated into sys/arch/evbarm. (by skrll@)
- add support fdt. evbarm/conf/GENERIC64 fdt (bcm2837,sunxi,tegra) based generic 64bit kernel config. (by skrll@, jmcneill@)


Revision tags: netbsd-8-1-RELEASE netbsd-8-1-RC1 netbsd-7-2-RELEASE netbsd-8-0-RELEASE netbsd-8-0-RC2 netbsd-8-0-RC1 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 netbsd-7-1-2-RELEASE pgoyette-compat-base netbsd-7-1-1-RELEASE tls-maxphys-base-20171202 matt-nb8-mediatek-base nick-nhusb-base-20170825 perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base pgoyette-localcount-20170320 netbsd-7-1-RELEASE netbsd-7-1-RC2 nick-nhusb-base-20170204 netbsd-7-nhusb-base-20170116 bouyer-socketcan-base pgoyette-localcount-20170107 netbsd-7-1-RC1 nick-nhusb-base-20161204 pgoyette-localcount-20161104 netbsd-7-0-2-RELEASE nick-nhusb-base-20161004 localcount-20160914 netbsd-7-nhusb-base pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907 nick-nhusb-base-20160529 netbsd-7-0-1-RELEASE nick-nhusb-base-20160422 nick-nhusb-base-20160319 nick-nhusb-base-20151226 netbsd-7-0-RELEASE nick-nhusb-base-20150921 netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 nick-nhusb-base-20150606 nick-nhusb-base-20150406 nick-nhusb-base tls-maxphys-base netbsd-7-base
# 1.1 10-Aug-2014 matt

branches: 1.1.4; 1.1.28;
Preliminary files for AARCH64 (64-bit ARM) support.
Enough for a distribution build.


# 1.55 18-Dec-2019 ryo

atomic_add_16() is not used in pmap.c anymore. no need decl here.


# 1.54 18-Dec-2019 ryo

space to tab


# 1.53 14-Dec-2019 skrll

Fix build... wire_count probably doesn't need atomics


# 1.52 13-Dec-2019 skrll

Fix KASAN support by calling kasan_shadow_map in pmap_growkernel


# 1.51 10-Dec-2019 ad

pg->phys_addr -> VM_PAGE_TO_PHYS(pg)


Revision tags: phil-wifi-20191119
# 1.50 14-Nov-2019 maxv

Mark several kASan functions with __nothing, to avoid annoying #ifdefs.
Same as kCSan and kMSan.


# 1.49 14-Nov-2019 maxv

Don't include "opt_kasan.h" when there's already <sys/asan.h> included.


# 1.48 29-Oct-2019 maya

Define PMAP_NEED_PROCWR, providing strategically placed i-cache
synchronization where just-changed memory is about to be executed.

Fixes SIGILLs seen when running Mono 6 on QEMU Cortex-A57.

ok ryo


# 1.47 22-Sep-2019 jmcneill

Disable translation table walks using TTBR0 while changing its value and
when deactivating a pmap. Fixes stability issues on Ampere eMAG CPUs.


# 1.46 20-Sep-2019 ryo

ref/mod bit should be set according to 'flags' argument, not 'prot'. r1.44 was incomplete.


# 1.45 13-Sep-2019 ryo

In pmap_devmap_bootstrap(), cpu_earlydevice_va_p() must not return true until *all* devmap tables have been enabled.
console mapping may be present in the last table.


# 1.44 07-Sep-2019 ryo

- remove incorrect KASSERT. mmap(2) with prot=PROT_WRITE calls pmap_enter(..., PROT_WRITE) internally.
- fix to update page reference flags when only PROT_WRITE or PROT_EXECUTE specified


# 1.43 15-Aug-2019 skrll

Make pmap_db_pte_print more terse so it's quicker on serial consoles


# 1.42 12-Aug-2019 skrll

Use PMAP_DEV in DEVMAP_ENTRY rather than pmap_map_chunk. It's clearer and
means pmap_map_chunk can be made to map other memory types.


Revision tags: netbsd-9-base phil-wifi-20190609
# 1.41 17-May-2019 mrg

branches: 1.41.2;
apply some __diagused.


Revision tags: isaki-audio2-base
# 1.40 08-Apr-2019 ryo

- free empty page tables pages if reach a certain usage.
- need to lock at removing an old pg (_pmap_remove_pv) in _pmap_enter()


# 1.39 06-Apr-2019 ryo

Fix race conditions about pmap_page_protect() and pmap_enter().

while handling same PTE by these functions in same time, there
is a critical path that the number of valid PTEs and wire_count
are inconsistent, and it caused KASSERT.
Need to hold a pv_lock while modifying them.


# 1.38 20-Mar-2019 ryo

spinkle __printflike(), and use PRIxxx


# 1.37 19-Mar-2019 ryo

- add ddb command "machine ttbr" to dump MMU tables.
- tidy up descriptions, usages and messages.


# 1.36 19-Mar-2019 ryo

- free L1-L3 pages that has been emptied by pmap_remove().
- if no memories, pmap_enter will return correctly ENOMEM if PMAP_CANFAIL, or wait until available any memories if !PMAP_CANFAIL.

These changes improves the stability when we use a huge virtual memory spaces with mmap.


# 1.35 06-Feb-2019 ryo

improve pmap_remove
- don't lock/unlock per page in pmap_remove()
- speedup pte lookup for continuous addresses
- bring out pool_cache_put(&_pmap_pv_pool, pv) from lock/unlock section


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226
# 1.34 21-Dec-2018 ryo

- add workaround for Cavium ThunderX errata 27456.
- add cpufuncs table in cpu_info. each cpu clusters may have different erratum. (e.g. big.LITTLE)


Revision tags: pgoyette-compat-1126
# 1.33 01-Nov-2018 maxv

Add kASan support for aarch64. Stack tracking needs more investigation
and will come in a separate commit.

Reviewed by ryo@ jmcneill@ skrll@.


# 1.32 31-Oct-2018 ryo

invalidate icache correctly.
l3pte_executable() should be used for only valid pte.


Revision tags: pgoyette-compat-1020
# 1.31 18-Oct-2018 skrll

Provide generic start code that assumes the MMU is off and caches are
disabled as per the linux booting protocol for ARMv6 and ARMv7 boards.
u-boot image type should be changed to 'linux' for correct behaviour.

The new start code builds a minimal "bootstrap" L1PT with cached access
disabled and uses the same table for all processors. AP startup is
performed in less steps and more code is written in C.

The bootstrap tables and stack are placed into an (orphaned) section
"_init_memory" which is given to uvm when it is no longer used.

Various kernels have been converted to use this code and tested. Some
boards were provided by TNF. Thanks!

The GENERIC kernel now boots on boards using the TEGRA, SUNXI and EXYNOS
kernels. The GENERIC kernel will also work on RPI2 using u-boot.

Thanks to martin@ and aymeric@ for testing on parallella and nanosoc
respectively


# 1.30 14-Oct-2018 skrll

Use __nothing


# 1.29 12-Oct-2018 ryo

add initial support of COMPAT_NETBSD32 on AArch64.
arm ELF32 EABI binaries could be execute in AArch32 state on AArch64. A32 THUMB mode is not supported yet.


# 1.28 12-Oct-2018 ryo

- cleanup checking address ranges with IN_RANGE macro
- change PM_ADDR_CHECK macro to KASSERTMSG
- restore fast lookup cases with IN_RANGE macro for pmap_extract changed in my previous commit.


# 1.27 12-Oct-2018 ryo

rewrite pmap_pte_lookup() to share similar code.


# 1.26 04-Oct-2018 ryo

cleanup locore, and changed the way to map memories during boot.
- add functions bootpage_enter() and bootpage_alloc() to adapt various layout
of physical memory map. especially for 64bit physical memory layout.
pmapboot_alloc() allocates pagetable pages from _end[].
- changed to map only the required amount for PA=VA identity mapping
(kernel image, UART device, and FDT blob) with L2_BLOCK(2Mbyte).
- changing page permission for kernel image, and making KSEG mapping are done
at cpu_kernel_vm_init() instead of at locore.
- optimize PTE entries with PTE Contiguous bit. it is enabled on devmap only for now.

reviewed by skrll@, thanks.


# 1.25 04-Oct-2018 ryo

* define LX_BLKPAG_{OS,ATTR}_* for OS dependent PTE attributes in pmap.h
* cleanup macros


Revision tags: pgoyette-compat-0930
# 1.24 17-Sep-2018 ryo

delete debug printf and KASSERT.


# 1.23 10-Sep-2018 maxv

Replace KDASSERT by panic.


# 1.22 10-Sep-2018 maxv

Rename _pmap_alloc_pdp -> pmap_alloc_pdp, and make it public.


# 1.21 10-Sep-2018 ryo

cleanup aarch64 mpstart and fdt bootstrap
* arm_cpu_hatch_arg is a bad idea. avoid serializing CPU startup, and eliminate arm_cpu_hatch_arg.
in mpstart, resolve own cpu index using array of cpu_mpidr[] (aarch64)
* add support fdt enable-method "spin-table"
* add support fdt enable-method "brcm,bcm2836-smp" (for 32bit RaspberryPi)
* use arm_fdt_cpu_bootstrap() instead of psci_fdt_bootstrap()
* rename "arm/fdt/psci_fdt.h" to "arm/fdt/psci_fdtvar.h" because of conflict of include file for needs-flag
* add devmap for cpu spin-table of raspberrypi3/aarch64
* no need to force hatch APs for raspberrypi3/arm32 ifndef MULTIPROCESSOR.
* fix to work pmap_extract(kerneltext/data/bss) even if before calling pmap_bootstrap

idea to use cpu_mpidr[] by jmcneill@. reviewd by skrll@. thanks.


Revision tags: pgoyette-compat-0906
# 1.20 27-Aug-2018 ryo

need to add VM_PROT_READ when pmap_kenter_pa(va, pa, VM_PROT_WRITE, 0) or pmap_kenter_pa(va, pa, VM_PROT_EXECUTE, 0).
VM_PROT_READ is treated as an access permission inernally.


# 1.19 11-Aug-2018 ryo

change to minimum invalidation of TLB.
specifying not only va but also asid, and not invalidate L0-L2 entry using tlbi_*_ll() if needed.


# 1.18 10-Aug-2018 ryo

treat kernel-exec attr and user-exec attr separately.
kernel cannot execute userland exec page, and user cannot execute kernel page.


# 1.17 06-Aug-2018 ryo

set kernel text/rodata readonly by default.
add function db_write_text() for setting ddb breakpoint.


# 1.16 31-Jul-2018 skrll

Define and use VPRINTF


Revision tags: pgoyette-compat-0728
# 1.15 27-Jul-2018 ryo

changes of pmap.c r1.13 seems to be unstable.
In order to invalidate icache, not to invalidate all icache,
but temporary to make the page writable and invalidate target address only.


# 1.14 24-Jul-2018 ryo

don't call pool_cache_put with locking pmap. pool_cache_put call pmap_kenter_pa internally.
(pool_cache_put_paddr -> pool_cache_put_slow -> pool_get -> pmap_kenter_pa)


# 1.13 23-Jul-2018 ryo

* fix icache invalidations.
* "ic ivau" (aarch64_icache_sync_range) with VA generates permission fault in some situations, therefore use KSEG address for now.


# 1.12 23-Jul-2018 ryo

rather than using flags to resolve nested locks, reserve pool_cache before locking.


# 1.11 21-Jul-2018 ryo

* avoid deadlock. mutex_owned() works only for adaptive lock, therefore we cannot use it for spinlock...
* add more NULL check
* clear pte when pmap_enter() fails


# 1.10 17-Jul-2018 ryo

Use __debugused


# 1.9 17-Jul-2018 christos

Add missing casts, remove unused variables.


# 1.8 09-Jul-2018 ryo

need locks in pmap_kremove() and pmap_fault_fixup()


Revision tags: phil-wifi-base pgoyette-compat-0625 pgoyette-compat-0521
# 1.7 20-May-2018 ryo

branches: 1.7.2;
pmap_enter() must update modified/referenced flags by 'flags' not 'prot'.


# 1.6 16-May-2018 ryo

Fix memory leak. it was leaking one page every pmap_create().
pm->pm_vmlist must be initialized before calling _pmap_alloc_pdp().


Revision tags: pgoyette-compat-0502
# 1.5 29-Apr-2018 ryo

fix KASSERT panic. pv_entry may not be exists in pvlist when pmap_remove().


# 1.4 29-Apr-2018 ryo

delete unused code


# 1.3 27-Apr-2018 ryo

fix instability behavior of bufcache on aarch64.
* fix to return correct ref/mod when PMAP_WIRED.
* changed to keep wired flags in pte instead of pv_entry, and cleanup.


Revision tags: pgoyette-compat-0422 pgoyette-compat-0415 pgoyette-compat-0407
# 1.2 01-Apr-2018 ryo

Add initial support for ARMv8 (AARCH64) (by nisimura@ and ryo@)

- sys/arch/evbarm64 is gone and integrated into sys/arch/evbarm. (by skrll@)
- add support fdt. evbarm/conf/GENERIC64 fdt (bcm2837,sunxi,tegra) based generic 64bit kernel config. (by skrll@, jmcneill@)


Revision tags: netbsd-8-1-RELEASE netbsd-8-1-RC1 netbsd-7-2-RELEASE netbsd-8-0-RELEASE netbsd-8-0-RC2 netbsd-8-0-RC1 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 netbsd-7-1-2-RELEASE pgoyette-compat-base netbsd-7-1-1-RELEASE tls-maxphys-base-20171202 matt-nb8-mediatek-base nick-nhusb-base-20170825 perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base pgoyette-localcount-20170320 netbsd-7-1-RELEASE netbsd-7-1-RC2 nick-nhusb-base-20170204 netbsd-7-nhusb-base-20170116 bouyer-socketcan-base pgoyette-localcount-20170107 netbsd-7-1-RC1 nick-nhusb-base-20161204 pgoyette-localcount-20161104 netbsd-7-0-2-RELEASE nick-nhusb-base-20161004 localcount-20160914 netbsd-7-nhusb-base pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907 nick-nhusb-base-20160529 netbsd-7-0-1-RELEASE nick-nhusb-base-20160422 nick-nhusb-base-20160319 nick-nhusb-base-20151226 netbsd-7-0-RELEASE nick-nhusb-base-20150921 netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 nick-nhusb-base-20150606 nick-nhusb-base-20150406 nick-nhusb-base tls-maxphys-base netbsd-7-base
# 1.1 10-Aug-2014 matt

branches: 1.1.4; 1.1.28;
Preliminary files for AARCH64 (64-bit ARM) support.
Enough for a distribution build.


# 1.53 14-Dec-2019 skrll

Fix build... wire_count probably doesn't need atomics


# 1.52 13-Dec-2019 skrll

Fix KASAN support by calling kasan_shadow_map in pmap_growkernel


# 1.51 10-Dec-2019 ad

pg->phys_addr -> VM_PAGE_TO_PHYS(pg)


Revision tags: phil-wifi-20191119
# 1.50 14-Nov-2019 maxv

Mark several kASan functions with __nothing, to avoid annoying #ifdefs.
Same as kCSan and kMSan.


# 1.49 14-Nov-2019 maxv

Don't include "opt_kasan.h" when there's already <sys/asan.h> included.


# 1.48 29-Oct-2019 maya

Define PMAP_NEED_PROCWR, providing strategically placed i-cache
synchronization where just-changed memory is about to be executed.

Fixes SIGILLs seen when running Mono 6 on QEMU Cortex-A57.

ok ryo


# 1.47 22-Sep-2019 jmcneill

Disable translation table walks using TTBR0 while changing its value and
when deactivating a pmap. Fixes stability issues on Ampere eMAG CPUs.


# 1.46 20-Sep-2019 ryo

ref/mod bit should be set according to 'flags' argument, not 'prot'. r1.44 was incomplete.


# 1.45 13-Sep-2019 ryo

In pmap_devmap_bootstrap(), cpu_earlydevice_va_p() must not return true until *all* devmap tables have been enabled.
console mapping may be present in the last table.


# 1.44 07-Sep-2019 ryo

- remove incorrect KASSERT. mmap(2) with prot=PROT_WRITE calls pmap_enter(..., PROT_WRITE) internally.
- fix to update page reference flags when only PROT_WRITE or PROT_EXECUTE specified


# 1.43 15-Aug-2019 skrll

Make pmap_db_pte_print more terse so it's quicker on serial consoles


# 1.42 12-Aug-2019 skrll

Use PMAP_DEV in DEVMAP_ENTRY rather than pmap_map_chunk. It's clearer and
means pmap_map_chunk can be made to map other memory types.


Revision tags: netbsd-9-base phil-wifi-20190609
# 1.41 17-May-2019 mrg

branches: 1.41.2;
apply some __diagused.


Revision tags: isaki-audio2-base
# 1.40 08-Apr-2019 ryo

- free empty page tables pages if reach a certain usage.
- need to lock at removing an old pg (_pmap_remove_pv) in _pmap_enter()


# 1.39 06-Apr-2019 ryo

Fix race conditions about pmap_page_protect() and pmap_enter().

while handling same PTE by these functions in same time, there
is a critical path that the number of valid PTEs and wire_count
are inconsistent, and it caused KASSERT.
Need to hold a pv_lock while modifying them.


# 1.38 20-Mar-2019 ryo

spinkle __printflike(), and use PRIxxx


# 1.37 19-Mar-2019 ryo

- add ddb command "machine ttbr" to dump MMU tables.
- tidy up descriptions, usages and messages.


# 1.36 19-Mar-2019 ryo

- free L1-L3 pages that has been emptied by pmap_remove().
- if no memories, pmap_enter will return correctly ENOMEM if PMAP_CANFAIL, or wait until available any memories if !PMAP_CANFAIL.

These changes improves the stability when we use a huge virtual memory spaces with mmap.


# 1.35 06-Feb-2019 ryo

improve pmap_remove
- don't lock/unlock per page in pmap_remove()
- speedup pte lookup for continuous addresses
- bring out pool_cache_put(&_pmap_pv_pool, pv) from lock/unlock section


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226
# 1.34 21-Dec-2018 ryo

- add workaround for Cavium ThunderX errata 27456.
- add cpufuncs table in cpu_info. each cpu clusters may have different erratum. (e.g. big.LITTLE)


Revision tags: pgoyette-compat-1126
# 1.33 01-Nov-2018 maxv

Add kASan support for aarch64. Stack tracking needs more investigation
and will come in a separate commit.

Reviewed by ryo@ jmcneill@ skrll@.


# 1.32 31-Oct-2018 ryo

invalidate icache correctly.
l3pte_executable() should be used for only valid pte.


Revision tags: pgoyette-compat-1020
# 1.31 18-Oct-2018 skrll

Provide generic start code that assumes the MMU is off and caches are
disabled as per the linux booting protocol for ARMv6 and ARMv7 boards.
u-boot image type should be changed to 'linux' for correct behaviour.

The new start code builds a minimal "bootstrap" L1PT with cached access
disabled and uses the same table for all processors. AP startup is
performed in less steps and more code is written in C.

The bootstrap tables and stack are placed into an (orphaned) section
"_init_memory" which is given to uvm when it is no longer used.

Various kernels have been converted to use this code and tested. Some
boards were provided by TNF. Thanks!

The GENERIC kernel now boots on boards using the TEGRA, SUNXI and EXYNOS
kernels. The GENERIC kernel will also work on RPI2 using u-boot.

Thanks to martin@ and aymeric@ for testing on parallella and nanosoc
respectively


# 1.30 14-Oct-2018 skrll

Use __nothing


# 1.29 12-Oct-2018 ryo

add initial support of COMPAT_NETBSD32 on AArch64.
arm ELF32 EABI binaries could be execute in AArch32 state on AArch64. A32 THUMB mode is not supported yet.


# 1.28 12-Oct-2018 ryo

- cleanup checking address ranges with IN_RANGE macro
- change PM_ADDR_CHECK macro to KASSERTMSG
- restore fast lookup cases with IN_RANGE macro for pmap_extract changed in my previous commit.


# 1.27 12-Oct-2018 ryo

rewrite pmap_pte_lookup() to share similar code.


# 1.26 04-Oct-2018 ryo

cleanup locore, and changed the way to map memories during boot.
- add functions bootpage_enter() and bootpage_alloc() to adapt various layout
of physical memory map. especially for 64bit physical memory layout.
pmapboot_alloc() allocates pagetable pages from _end[].
- changed to map only the required amount for PA=VA identity mapping
(kernel image, UART device, and FDT blob) with L2_BLOCK(2Mbyte).
- changing page permission for kernel image, and making KSEG mapping are done
at cpu_kernel_vm_init() instead of at locore.
- optimize PTE entries with PTE Contiguous bit. it is enabled on devmap only for now.

reviewed by skrll@, thanks.


# 1.25 04-Oct-2018 ryo

* define LX_BLKPAG_{OS,ATTR}_* for OS dependent PTE attributes in pmap.h
* cleanup macros


Revision tags: pgoyette-compat-0930
# 1.24 17-Sep-2018 ryo

delete debug printf and KASSERT.


# 1.23 10-Sep-2018 maxv

Replace KDASSERT by panic.


# 1.22 10-Sep-2018 maxv

Rename _pmap_alloc_pdp -> pmap_alloc_pdp, and make it public.


# 1.21 10-Sep-2018 ryo

cleanup aarch64 mpstart and fdt bootstrap
* arm_cpu_hatch_arg is a bad idea. avoid serializing CPU startup, and eliminate arm_cpu_hatch_arg.
in mpstart, resolve own cpu index using array of cpu_mpidr[] (aarch64)
* add support fdt enable-method "spin-table"
* add support fdt enable-method "brcm,bcm2836-smp" (for 32bit RaspberryPi)
* use arm_fdt_cpu_bootstrap() instead of psci_fdt_bootstrap()
* rename "arm/fdt/psci_fdt.h" to "arm/fdt/psci_fdtvar.h" because of conflict of include file for needs-flag
* add devmap for cpu spin-table of raspberrypi3/aarch64
* no need to force hatch APs for raspberrypi3/arm32 ifndef MULTIPROCESSOR.
* fix to work pmap_extract(kerneltext/data/bss) even if before calling pmap_bootstrap

idea to use cpu_mpidr[] by jmcneill@. reviewd by skrll@. thanks.


Revision tags: pgoyette-compat-0906
# 1.20 27-Aug-2018 ryo

need to add VM_PROT_READ when pmap_kenter_pa(va, pa, VM_PROT_WRITE, 0) or pmap_kenter_pa(va, pa, VM_PROT_EXECUTE, 0).
VM_PROT_READ is treated as an access permission inernally.


# 1.19 11-Aug-2018 ryo

change to minimum invalidation of TLB.
specifying not only va but also asid, and not invalidate L0-L2 entry using tlbi_*_ll() if needed.


# 1.18 10-Aug-2018 ryo

treat kernel-exec attr and user-exec attr separately.
kernel cannot execute userland exec page, and user cannot execute kernel page.


# 1.17 06-Aug-2018 ryo

set kernel text/rodata readonly by default.
add function db_write_text() for setting ddb breakpoint.


# 1.16 31-Jul-2018 skrll

Define and use VPRINTF


Revision tags: pgoyette-compat-0728
# 1.15 27-Jul-2018 ryo

changes of pmap.c r1.13 seems to be unstable.
In order to invalidate icache, not to invalidate all icache,
but temporary to make the page writable and invalidate target address only.


# 1.14 24-Jul-2018 ryo

don't call pool_cache_put with locking pmap. pool_cache_put call pmap_kenter_pa internally.
(pool_cache_put_paddr -> pool_cache_put_slow -> pool_get -> pmap_kenter_pa)


# 1.13 23-Jul-2018 ryo

* fix icache invalidations.
* "ic ivau" (aarch64_icache_sync_range) with VA generates permission fault in some situations, therefore use KSEG address for now.


# 1.12 23-Jul-2018 ryo

rather than using flags to resolve nested locks, reserve pool_cache before locking.


# 1.11 21-Jul-2018 ryo

* avoid deadlock. mutex_owned() works only for adaptive lock, therefore we cannot use it for spinlock...
* add more NULL check
* clear pte when pmap_enter() fails


# 1.10 17-Jul-2018 ryo

Use __debugused


# 1.9 17-Jul-2018 christos

Add missing casts, remove unused variables.


# 1.8 09-Jul-2018 ryo

need locks in pmap_kremove() and pmap_fault_fixup()


Revision tags: phil-wifi-base pgoyette-compat-0625 pgoyette-compat-0521
# 1.7 20-May-2018 ryo

branches: 1.7.2;
pmap_enter() must update modified/referenced flags by 'flags' not 'prot'.


# 1.6 16-May-2018 ryo

Fix memory leak. it was leaking one page every pmap_create().
pm->pm_vmlist must be initialized before calling _pmap_alloc_pdp().


Revision tags: pgoyette-compat-0502
# 1.5 29-Apr-2018 ryo

fix KASSERT panic. pv_entry may not be exists in pvlist when pmap_remove().


# 1.4 29-Apr-2018 ryo

delete unused code


# 1.3 27-Apr-2018 ryo

fix instability behavior of bufcache on aarch64.
* fix to return correct ref/mod when PMAP_WIRED.
* changed to keep wired flags in pte instead of pv_entry, and cleanup.


Revision tags: pgoyette-compat-0422 pgoyette-compat-0415 pgoyette-compat-0407
# 1.2 01-Apr-2018 ryo

Add initial support for ARMv8 (AARCH64) (by nisimura@ and ryo@)

- sys/arch/evbarm64 is gone and integrated into sys/arch/evbarm. (by skrll@)
- add support fdt. evbarm/conf/GENERIC64 fdt (bcm2837,sunxi,tegra) based generic 64bit kernel config. (by skrll@, jmcneill@)


Revision tags: netbsd-8-1-RELEASE netbsd-8-1-RC1 netbsd-7-2-RELEASE netbsd-8-0-RELEASE netbsd-8-0-RC2 netbsd-8-0-RC1 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 netbsd-7-1-2-RELEASE pgoyette-compat-base netbsd-7-1-1-RELEASE tls-maxphys-base-20171202 matt-nb8-mediatek-base nick-nhusb-base-20170825 perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base pgoyette-localcount-20170320 netbsd-7-1-RELEASE netbsd-7-1-RC2 nick-nhusb-base-20170204 netbsd-7-nhusb-base-20170116 bouyer-socketcan-base pgoyette-localcount-20170107 netbsd-7-1-RC1 nick-nhusb-base-20161204 pgoyette-localcount-20161104 netbsd-7-0-2-RELEASE nick-nhusb-base-20161004 localcount-20160914 netbsd-7-nhusb-base pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907 nick-nhusb-base-20160529 netbsd-7-0-1-RELEASE nick-nhusb-base-20160422 nick-nhusb-base-20160319 nick-nhusb-base-20151226 netbsd-7-0-RELEASE nick-nhusb-base-20150921 netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 nick-nhusb-base-20150606 nick-nhusb-base-20150406 nick-nhusb-base tls-maxphys-base netbsd-7-base
# 1.1 10-Aug-2014 matt

branches: 1.1.4; 1.1.28;
Preliminary files for AARCH64 (64-bit ARM) support.
Enough for a distribution build.


# 1.52 13-Dec-2019 skrll

Fix KASAN support by calling kasan_shadow_map in pmap_growkernel


# 1.51 10-Dec-2019 ad

pg->phys_addr -> VM_PAGE_TO_PHYS(pg)


Revision tags: phil-wifi-20191119
# 1.50 14-Nov-2019 maxv

Mark several kASan functions with __nothing, to avoid annoying #ifdefs.
Same as kCSan and kMSan.


# 1.49 14-Nov-2019 maxv

Don't include "opt_kasan.h" when there's already <sys/asan.h> included.


# 1.48 29-Oct-2019 maya

Define PMAP_NEED_PROCWR, providing strategically placed i-cache
synchronization where just-changed memory is about to be executed.

Fixes SIGILLs seen when running Mono 6 on QEMU Cortex-A57.

ok ryo


# 1.47 22-Sep-2019 jmcneill

Disable translation table walks using TTBR0 while changing its value and
when deactivating a pmap. Fixes stability issues on Ampere eMAG CPUs.


# 1.46 20-Sep-2019 ryo

ref/mod bit should be set according to 'flags' argument, not 'prot'. r1.44 was incomplete.


# 1.45 13-Sep-2019 ryo

In pmap_devmap_bootstrap(), cpu_earlydevice_va_p() must not return true until *all* devmap tables have been enabled.
console mapping may be present in the last table.


# 1.44 07-Sep-2019 ryo

- remove incorrect KASSERT. mmap(2) with prot=PROT_WRITE calls pmap_enter(..., PROT_WRITE) internally.
- fix to update page reference flags when only PROT_WRITE or PROT_EXECUTE specified


# 1.43 15-Aug-2019 skrll

Make pmap_db_pte_print more terse so it's quicker on serial consoles


# 1.42 12-Aug-2019 skrll

Use PMAP_DEV in DEVMAP_ENTRY rather than pmap_map_chunk. It's clearer and
means pmap_map_chunk can be made to map other memory types.


Revision tags: netbsd-9-base phil-wifi-20190609
# 1.41 17-May-2019 mrg

branches: 1.41.2;
apply some __diagused.


Revision tags: isaki-audio2-base
# 1.40 08-Apr-2019 ryo

- free empty page tables pages if reach a certain usage.
- need to lock at removing an old pg (_pmap_remove_pv) in _pmap_enter()


# 1.39 06-Apr-2019 ryo

Fix race conditions about pmap_page_protect() and pmap_enter().

while handling same PTE by these functions in same time, there
is a critical path that the number of valid PTEs and wire_count
are inconsistent, and it caused KASSERT.
Need to hold a pv_lock while modifying them.


# 1.38 20-Mar-2019 ryo

spinkle __printflike(), and use PRIxxx


# 1.37 19-Mar-2019 ryo

- add ddb command "machine ttbr" to dump MMU tables.
- tidy up descriptions, usages and messages.


# 1.36 19-Mar-2019 ryo

- free L1-L3 pages that has been emptied by pmap_remove().
- if no memories, pmap_enter will return correctly ENOMEM if PMAP_CANFAIL, or wait until available any memories if !PMAP_CANFAIL.

These changes improves the stability when we use a huge virtual memory spaces with mmap.


# 1.35 06-Feb-2019 ryo

improve pmap_remove
- don't lock/unlock per page in pmap_remove()
- speedup pte lookup for continuous addresses
- bring out pool_cache_put(&_pmap_pv_pool, pv) from lock/unlock section


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226
# 1.34 21-Dec-2018 ryo

- add workaround for Cavium ThunderX errata 27456.
- add cpufuncs table in cpu_info. each cpu clusters may have different erratum. (e.g. big.LITTLE)


Revision tags: pgoyette-compat-1126
# 1.33 01-Nov-2018 maxv

Add kASan support for aarch64. Stack tracking needs more investigation
and will come in a separate commit.

Reviewed by ryo@ jmcneill@ skrll@.


# 1.32 31-Oct-2018 ryo

invalidate icache correctly.
l3pte_executable() should be used for only valid pte.


Revision tags: pgoyette-compat-1020
# 1.31 18-Oct-2018 skrll

Provide generic start code that assumes the MMU is off and caches are
disabled as per the linux booting protocol for ARMv6 and ARMv7 boards.
u-boot image type should be changed to 'linux' for correct behaviour.

The new start code builds a minimal "bootstrap" L1PT with cached access
disabled and uses the same table for all processors. AP startup is
performed in less steps and more code is written in C.

The bootstrap tables and stack are placed into an (orphaned) section
"_init_memory" which is given to uvm when it is no longer used.

Various kernels have been converted to use this code and tested. Some
boards were provided by TNF. Thanks!

The GENERIC kernel now boots on boards using the TEGRA, SUNXI and EXYNOS
kernels. The GENERIC kernel will also work on RPI2 using u-boot.

Thanks to martin@ and aymeric@ for testing on parallella and nanosoc
respectively


# 1.30 14-Oct-2018 skrll

Use __nothing


# 1.29 12-Oct-2018 ryo

add initial support of COMPAT_NETBSD32 on AArch64.
arm ELF32 EABI binaries could be execute in AArch32 state on AArch64. A32 THUMB mode is not supported yet.


# 1.28 12-Oct-2018 ryo

- cleanup checking address ranges with IN_RANGE macro
- change PM_ADDR_CHECK macro to KASSERTMSG
- restore fast lookup cases with IN_RANGE macro for pmap_extract changed in my previous commit.


# 1.27 12-Oct-2018 ryo

rewrite pmap_pte_lookup() to share similar code.


# 1.26 04-Oct-2018 ryo

cleanup locore, and changed the way to map memories during boot.
- add functions bootpage_enter() and bootpage_alloc() to adapt various layout
of physical memory map. especially for 64bit physical memory layout.
pmapboot_alloc() allocates pagetable pages from _end[].
- changed to map only the required amount for PA=VA identity mapping
(kernel image, UART device, and FDT blob) with L2_BLOCK(2Mbyte).
- changing page permission for kernel image, and making KSEG mapping are done
at cpu_kernel_vm_init() instead of at locore.
- optimize PTE entries with PTE Contiguous bit. it is enabled on devmap only for now.

reviewed by skrll@, thanks.


# 1.25 04-Oct-2018 ryo

* define LX_BLKPAG_{OS,ATTR}_* for OS dependent PTE attributes in pmap.h
* cleanup macros


Revision tags: pgoyette-compat-0930
# 1.24 17-Sep-2018 ryo

delete debug printf and KASSERT.


# 1.23 10-Sep-2018 maxv

Replace KDASSERT by panic.


# 1.22 10-Sep-2018 maxv

Rename _pmap_alloc_pdp -> pmap_alloc_pdp, and make it public.


# 1.21 10-Sep-2018 ryo

cleanup aarch64 mpstart and fdt bootstrap
* arm_cpu_hatch_arg is a bad idea. avoid serializing CPU startup, and eliminate arm_cpu_hatch_arg.
in mpstart, resolve own cpu index using array of cpu_mpidr[] (aarch64)
* add support fdt enable-method "spin-table"
* add support fdt enable-method "brcm,bcm2836-smp" (for 32bit RaspberryPi)
* use arm_fdt_cpu_bootstrap() instead of psci_fdt_bootstrap()
* rename "arm/fdt/psci_fdt.h" to "arm/fdt/psci_fdtvar.h" because of conflict of include file for needs-flag
* add devmap for cpu spin-table of raspberrypi3/aarch64
* no need to force hatch APs for raspberrypi3/arm32 ifndef MULTIPROCESSOR.
* fix to work pmap_extract(kerneltext/data/bss) even if before calling pmap_bootstrap

idea to use cpu_mpidr[] by jmcneill@. reviewd by skrll@. thanks.


Revision tags: pgoyette-compat-0906
# 1.20 27-Aug-2018 ryo

need to add VM_PROT_READ when pmap_kenter_pa(va, pa, VM_PROT_WRITE, 0) or pmap_kenter_pa(va, pa, VM_PROT_EXECUTE, 0).
VM_PROT_READ is treated as an access permission inernally.


# 1.19 11-Aug-2018 ryo

change to minimum invalidation of TLB.
specifying not only va but also asid, and not invalidate L0-L2 entry using tlbi_*_ll() if needed.


# 1.18 10-Aug-2018 ryo

treat kernel-exec attr and user-exec attr separately.
kernel cannot execute userland exec page, and user cannot execute kernel page.


# 1.17 06-Aug-2018 ryo

set kernel text/rodata readonly by default.
add function db_write_text() for setting ddb breakpoint.


# 1.16 31-Jul-2018 skrll

Define and use VPRINTF


Revision tags: pgoyette-compat-0728
# 1.15 27-Jul-2018 ryo

changes of pmap.c r1.13 seems to be unstable.
In order to invalidate icache, not to invalidate all icache,
but temporary to make the page writable and invalidate target address only.


# 1.14 24-Jul-2018 ryo

don't call pool_cache_put with locking pmap. pool_cache_put call pmap_kenter_pa internally.
(pool_cache_put_paddr -> pool_cache_put_slow -> pool_get -> pmap_kenter_pa)


# 1.13 23-Jul-2018 ryo

* fix icache invalidations.
* "ic ivau" (aarch64_icache_sync_range) with VA generates permission fault in some situations, therefore use KSEG address for now.


# 1.12 23-Jul-2018 ryo

rather than using flags to resolve nested locks, reserve pool_cache before locking.


# 1.11 21-Jul-2018 ryo

* avoid deadlock. mutex_owned() works only for adaptive lock, therefore we cannot use it for spinlock...
* add more NULL check
* clear pte when pmap_enter() fails


# 1.10 17-Jul-2018 ryo

Use __debugused


# 1.9 17-Jul-2018 christos

Add missing casts, remove unused variables.


# 1.8 09-Jul-2018 ryo

need locks in pmap_kremove() and pmap_fault_fixup()


Revision tags: phil-wifi-base pgoyette-compat-0625 pgoyette-compat-0521
# 1.7 20-May-2018 ryo

branches: 1.7.2;
pmap_enter() must update modified/referenced flags by 'flags' not 'prot'.


# 1.6 16-May-2018 ryo

Fix memory leak. it was leaking one page every pmap_create().
pm->pm_vmlist must be initialized before calling _pmap_alloc_pdp().


Revision tags: pgoyette-compat-0502
# 1.5 29-Apr-2018 ryo

fix KASSERT panic. pv_entry may not be exists in pvlist when pmap_remove().


# 1.4 29-Apr-2018 ryo

delete unused code


# 1.3 27-Apr-2018 ryo

fix instability behavior of bufcache on aarch64.
* fix to return correct ref/mod when PMAP_WIRED.
* changed to keep wired flags in pte instead of pv_entry, and cleanup.


Revision tags: pgoyette-compat-0422 pgoyette-compat-0415 pgoyette-compat-0407
# 1.2 01-Apr-2018 ryo

Add initial support for ARMv8 (AARCH64) (by nisimura@ and ryo@)

- sys/arch/evbarm64 is gone and integrated into sys/arch/evbarm. (by skrll@)
- add support fdt. evbarm/conf/GENERIC64 fdt (bcm2837,sunxi,tegra) based generic 64bit kernel config. (by skrll@, jmcneill@)


Revision tags: netbsd-8-1-RELEASE netbsd-8-1-RC1 netbsd-7-2-RELEASE netbsd-8-0-RELEASE netbsd-8-0-RC2 netbsd-8-0-RC1 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 netbsd-7-1-2-RELEASE pgoyette-compat-base netbsd-7-1-1-RELEASE tls-maxphys-base-20171202 matt-nb8-mediatek-base nick-nhusb-base-20170825 perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base pgoyette-localcount-20170320 netbsd-7-1-RELEASE netbsd-7-1-RC2 nick-nhusb-base-20170204 netbsd-7-nhusb-base-20170116 bouyer-socketcan-base pgoyette-localcount-20170107 netbsd-7-1-RC1 nick-nhusb-base-20161204 pgoyette-localcount-20161104 netbsd-7-0-2-RELEASE nick-nhusb-base-20161004 localcount-20160914 netbsd-7-nhusb-base pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907 nick-nhusb-base-20160529 netbsd-7-0-1-RELEASE nick-nhusb-base-20160422 nick-nhusb-base-20160319 nick-nhusb-base-20151226 netbsd-7-0-RELEASE nick-nhusb-base-20150921 netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 nick-nhusb-base-20150606 nick-nhusb-base-20150406 nick-nhusb-base tls-maxphys-base netbsd-7-base
# 1.1 10-Aug-2014 matt

branches: 1.1.4; 1.1.28;
Preliminary files for AARCH64 (64-bit ARM) support.
Enough for a distribution build.


# 1.51 10-Dec-2019 ad

pg->phys_addr -> VM_PAGE_TO_PHYS(pg)


Revision tags: phil-wifi-20191119
# 1.50 14-Nov-2019 maxv

Mark several kASan functions with __nothing, to avoid annoying #ifdefs.
Same as kCSan and kMSan.


# 1.49 14-Nov-2019 maxv

Don't include "opt_kasan.h" when there's already <sys/asan.h> included.


# 1.48 29-Oct-2019 maya

Define PMAP_NEED_PROCWR, providing strategically placed i-cache
synchronization where just-changed memory is about to be executed.

Fixes SIGILLs seen when running Mono 6 on QEMU Cortex-A57.

ok ryo


# 1.47 22-Sep-2019 jmcneill

Disable translation table walks using TTBR0 while changing its value and
when deactivating a pmap. Fixes stability issues on Ampere eMAG CPUs.


# 1.46 20-Sep-2019 ryo

ref/mod bit should be set according to 'flags' argument, not 'prot'. r1.44 was incomplete.


# 1.45 13-Sep-2019 ryo

In pmap_devmap_bootstrap(), cpu_earlydevice_va_p() must not return true until *all* devmap tables have been enabled.
console mapping may be present in the last table.


# 1.44 07-Sep-2019 ryo

- remove incorrect KASSERT. mmap(2) with prot=PROT_WRITE calls pmap_enter(..., PROT_WRITE) internally.
- fix to update page reference flags when only PROT_WRITE or PROT_EXECUTE specified


# 1.43 15-Aug-2019 skrll

Make pmap_db_pte_print more terse so it's quicker on serial consoles


# 1.42 12-Aug-2019 skrll

Use PMAP_DEV in DEVMAP_ENTRY rather than pmap_map_chunk. It's clearer and
means pmap_map_chunk can be made to map other memory types.


Revision tags: netbsd-9-base phil-wifi-20190609
# 1.41 17-May-2019 mrg

branches: 1.41.2;
apply some __diagused.


Revision tags: isaki-audio2-base
# 1.40 08-Apr-2019 ryo

- free empty page tables pages if reach a certain usage.
- need to lock at removing an old pg (_pmap_remove_pv) in _pmap_enter()


# 1.39 06-Apr-2019 ryo

Fix race conditions about pmap_page_protect() and pmap_enter().

while handling same PTE by these functions in same time, there
is a critical path that the number of valid PTEs and wire_count
are inconsistent, and it caused KASSERT.
Need to hold a pv_lock while modifying them.


# 1.38 20-Mar-2019 ryo

spinkle __printflike(), and use PRIxxx


# 1.37 19-Mar-2019 ryo

- add ddb command "machine ttbr" to dump MMU tables.
- tidy up descriptions, usages and messages.


# 1.36 19-Mar-2019 ryo

- free L1-L3 pages that has been emptied by pmap_remove().
- if no memories, pmap_enter will return correctly ENOMEM if PMAP_CANFAIL, or wait until available any memories if !PMAP_CANFAIL.

These changes improves the stability when we use a huge virtual memory spaces with mmap.


# 1.35 06-Feb-2019 ryo

improve pmap_remove
- don't lock/unlock per page in pmap_remove()
- speedup pte lookup for continuous addresses
- bring out pool_cache_put(&_pmap_pv_pool, pv) from lock/unlock section


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226
# 1.34 21-Dec-2018 ryo

- add workaround for Cavium ThunderX errata 27456.
- add cpufuncs table in cpu_info. each cpu clusters may have different erratum. (e.g. big.LITTLE)


Revision tags: pgoyette-compat-1126
# 1.33 01-Nov-2018 maxv

Add kASan support for aarch64. Stack tracking needs more investigation
and will come in a separate commit.

Reviewed by ryo@ jmcneill@ skrll@.


# 1.32 31-Oct-2018 ryo

invalidate icache correctly.
l3pte_executable() should be used for only valid pte.


Revision tags: pgoyette-compat-1020
# 1.31 18-Oct-2018 skrll

Provide generic start code that assumes the MMU is off and caches are
disabled as per the linux booting protocol for ARMv6 and ARMv7 boards.
u-boot image type should be changed to 'linux' for correct behaviour.

The new start code builds a minimal "bootstrap" L1PT with cached access
disabled and uses the same table for all processors. AP startup is
performed in less steps and more code is written in C.

The bootstrap tables and stack are placed into an (orphaned) section
"_init_memory" which is given to uvm when it is no longer used.

Various kernels have been converted to use this code and tested. Some
boards were provided by TNF. Thanks!

The GENERIC kernel now boots on boards using the TEGRA, SUNXI and EXYNOS
kernels. The GENERIC kernel will also work on RPI2 using u-boot.

Thanks to martin@ and aymeric@ for testing on parallella and nanosoc
respectively


# 1.30 14-Oct-2018 skrll

Use __nothing


# 1.29 12-Oct-2018 ryo

add initial support of COMPAT_NETBSD32 on AArch64.
arm ELF32 EABI binaries could be execute in AArch32 state on AArch64. A32 THUMB mode is not supported yet.


# 1.28 12-Oct-2018 ryo

- cleanup checking address ranges with IN_RANGE macro
- change PM_ADDR_CHECK macro to KASSERTMSG
- restore fast lookup cases with IN_RANGE macro for pmap_extract changed in my previous commit.


# 1.27 12-Oct-2018 ryo

rewrite pmap_pte_lookup() to share similar code.


# 1.26 04-Oct-2018 ryo

cleanup locore, and changed the way to map memories during boot.
- add functions bootpage_enter() and bootpage_alloc() to adapt various layout
of physical memory map. especially for 64bit physical memory layout.
pmapboot_alloc() allocates pagetable pages from _end[].
- changed to map only the required amount for PA=VA identity mapping
(kernel image, UART device, and FDT blob) with L2_BLOCK(2Mbyte).
- changing page permission for kernel image, and making KSEG mapping are done
at cpu_kernel_vm_init() instead of at locore.
- optimize PTE entries with PTE Contiguous bit. it is enabled on devmap only for now.

reviewed by skrll@, thanks.


# 1.25 04-Oct-2018 ryo

* define LX_BLKPAG_{OS,ATTR}_* for OS dependent PTE attributes in pmap.h
* cleanup macros


Revision tags: pgoyette-compat-0930
# 1.24 17-Sep-2018 ryo

delete debug printf and KASSERT.


# 1.23 10-Sep-2018 maxv

Replace KDASSERT by panic.


# 1.22 10-Sep-2018 maxv

Rename _pmap_alloc_pdp -> pmap_alloc_pdp, and make it public.


# 1.21 10-Sep-2018 ryo

cleanup aarch64 mpstart and fdt bootstrap
* arm_cpu_hatch_arg is a bad idea. avoid serializing CPU startup, and eliminate arm_cpu_hatch_arg.
in mpstart, resolve own cpu index using array of cpu_mpidr[] (aarch64)
* add support fdt enable-method "spin-table"
* add support fdt enable-method "brcm,bcm2836-smp" (for 32bit RaspberryPi)
* use arm_fdt_cpu_bootstrap() instead of psci_fdt_bootstrap()
* rename "arm/fdt/psci_fdt.h" to "arm/fdt/psci_fdtvar.h" because of conflict of include file for needs-flag
* add devmap for cpu spin-table of raspberrypi3/aarch64
* no need to force hatch APs for raspberrypi3/arm32 ifndef MULTIPROCESSOR.
* fix to work pmap_extract(kerneltext/data/bss) even if before calling pmap_bootstrap

idea to use cpu_mpidr[] by jmcneill@. reviewd by skrll@. thanks.


Revision tags: pgoyette-compat-0906
# 1.20 27-Aug-2018 ryo

need to add VM_PROT_READ when pmap_kenter_pa(va, pa, VM_PROT_WRITE, 0) or pmap_kenter_pa(va, pa, VM_PROT_EXECUTE, 0).
VM_PROT_READ is treated as an access permission inernally.


# 1.19 11-Aug-2018 ryo

change to minimum invalidation of TLB.
specifying not only va but also asid, and not invalidate L0-L2 entry using tlbi_*_ll() if needed.


# 1.18 10-Aug-2018 ryo

treat kernel-exec attr and user-exec attr separately.
kernel cannot execute userland exec page, and user cannot execute kernel page.


# 1.17 06-Aug-2018 ryo

set kernel text/rodata readonly by default.
add function db_write_text() for setting ddb breakpoint.


# 1.16 31-Jul-2018 skrll

Define and use VPRINTF


Revision tags: pgoyette-compat-0728
# 1.15 27-Jul-2018 ryo

changes of pmap.c r1.13 seems to be unstable.
In order to invalidate icache, not to invalidate all icache,
but temporary to make the page writable and invalidate target address only.


# 1.14 24-Jul-2018 ryo

don't call pool_cache_put with locking pmap. pool_cache_put call pmap_kenter_pa internally.
(pool_cache_put_paddr -> pool_cache_put_slow -> pool_get -> pmap_kenter_pa)


# 1.13 23-Jul-2018 ryo

* fix icache invalidations.
* "ic ivau" (aarch64_icache_sync_range) with VA generates permission fault in some situations, therefore use KSEG address for now.


# 1.12 23-Jul-2018 ryo

rather than using flags to resolve nested locks, reserve pool_cache before locking.


# 1.11 21-Jul-2018 ryo

* avoid deadlock. mutex_owned() works only for adaptive lock, therefore we cannot use it for spinlock...
* add more NULL check
* clear pte when pmap_enter() fails


# 1.10 17-Jul-2018 ryo

Use __debugused


# 1.9 17-Jul-2018 christos

Add missing casts, remove unused variables.


# 1.8 09-Jul-2018 ryo

need locks in pmap_kremove() and pmap_fault_fixup()


Revision tags: phil-wifi-base pgoyette-compat-0625 pgoyette-compat-0521
# 1.7 20-May-2018 ryo

branches: 1.7.2;
pmap_enter() must update modified/referenced flags by 'flags' not 'prot'.


# 1.6 16-May-2018 ryo

Fix memory leak. it was leaking one page every pmap_create().
pm->pm_vmlist must be initialized before calling _pmap_alloc_pdp().


Revision tags: pgoyette-compat-0502
# 1.5 29-Apr-2018 ryo

fix KASSERT panic. pv_entry may not be exists in pvlist when pmap_remove().


# 1.4 29-Apr-2018 ryo

delete unused code


# 1.3 27-Apr-2018 ryo

fix instability behavior of bufcache on aarch64.
* fix to return correct ref/mod when PMAP_WIRED.
* changed to keep wired flags in pte instead of pv_entry, and cleanup.


Revision tags: pgoyette-compat-0422 pgoyette-compat-0415 pgoyette-compat-0407
# 1.2 01-Apr-2018 ryo

Add initial support for ARMv8 (AARCH64) (by nisimura@ and ryo@)

- sys/arch/evbarm64 is gone and integrated into sys/arch/evbarm. (by skrll@)
- add support fdt. evbarm/conf/GENERIC64 fdt (bcm2837,sunxi,tegra) based generic 64bit kernel config. (by skrll@, jmcneill@)


Revision tags: netbsd-8-1-RELEASE netbsd-8-1-RC1 netbsd-7-2-RELEASE netbsd-8-0-RELEASE netbsd-8-0-RC2 netbsd-8-0-RC1 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 netbsd-7-1-2-RELEASE pgoyette-compat-base netbsd-7-1-1-RELEASE tls-maxphys-base-20171202 matt-nb8-mediatek-base nick-nhusb-base-20170825 perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base pgoyette-localcount-20170320 netbsd-7-1-RELEASE netbsd-7-1-RC2 nick-nhusb-base-20170204 netbsd-7-nhusb-base-20170116 bouyer-socketcan-base pgoyette-localcount-20170107 netbsd-7-1-RC1 nick-nhusb-base-20161204 pgoyette-localcount-20161104 netbsd-7-0-2-RELEASE nick-nhusb-base-20161004 localcount-20160914 netbsd-7-nhusb-base pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907 nick-nhusb-base-20160529 netbsd-7-0-1-RELEASE nick-nhusb-base-20160422 nick-nhusb-base-20160319 nick-nhusb-base-20151226 netbsd-7-0-RELEASE nick-nhusb-base-20150921 netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 nick-nhusb-base-20150606 nick-nhusb-base-20150406 nick-nhusb-base tls-maxphys-base netbsd-7-base
# 1.1 10-Aug-2014 matt

branches: 1.1.4; 1.1.28;
Preliminary files for AARCH64 (64-bit ARM) support.
Enough for a distribution build.


# 1.50 14-Nov-2019 maxv

Mark several kASan functions with __nothing, to avoid annoying #ifdefs.
Same as kCSan and kMSan.


# 1.49 14-Nov-2019 maxv

Don't include "opt_kasan.h" when there's already <sys/asan.h> included.


# 1.48 29-Oct-2019 maya

Define PMAP_NEED_PROCWR, providing strategically placed i-cache
synchronization where just-changed memory is about to be executed.

Fixes SIGILLs seen when running Mono 6 on QEMU Cortex-A57.

ok ryo


# 1.47 22-Sep-2019 jmcneill

Disable translation table walks using TTBR0 while changing its value and
when deactivating a pmap. Fixes stability issues on Ampere eMAG CPUs.


# 1.46 20-Sep-2019 ryo

ref/mod bit should be set according to 'flags' argument, not 'prot'. r1.44 was incomplete.


# 1.45 13-Sep-2019 ryo

In pmap_devmap_bootstrap(), cpu_earlydevice_va_p() must not return true until *all* devmap tables have been enabled.
console mapping may be present in the last table.


# 1.44 07-Sep-2019 ryo

- remove incorrect KASSERT. mmap(2) with prot=PROT_WRITE calls pmap_enter(..., PROT_WRITE) internally.
- fix to update page reference flags when only PROT_WRITE or PROT_EXECUTE specified


# 1.43 15-Aug-2019 skrll

Make pmap_db_pte_print more terse so it's quicker on serial consoles


# 1.42 12-Aug-2019 skrll

Use PMAP_DEV in DEVMAP_ENTRY rather than pmap_map_chunk. It's clearer and
means pmap_map_chunk can be made to map other memory types.


Revision tags: netbsd-9-base phil-wifi-20190609
# 1.41 17-May-2019 mrg

branches: 1.41.2;
apply some __diagused.


Revision tags: isaki-audio2-base
# 1.40 08-Apr-2019 ryo

- free empty page tables pages if reach a certain usage.
- need to lock at removing an old pg (_pmap_remove_pv) in _pmap_enter()


# 1.39 06-Apr-2019 ryo

Fix race conditions about pmap_page_protect() and pmap_enter().

while handling same PTE by these functions in same time, there
is a critical path that the number of valid PTEs and wire_count
are inconsistent, and it caused KASSERT.
Need to hold a pv_lock while modifying them.


# 1.38 20-Mar-2019 ryo

spinkle __printflike(), and use PRIxxx


# 1.37 19-Mar-2019 ryo

- add ddb command "machine ttbr" to dump MMU tables.
- tidy up descriptions, usages and messages.


# 1.36 19-Mar-2019 ryo

- free L1-L3 pages that has been emptied by pmap_remove().
- if no memories, pmap_enter will return correctly ENOMEM if PMAP_CANFAIL, or wait until available any memories if !PMAP_CANFAIL.

These changes improves the stability when we use a huge virtual memory spaces with mmap.


# 1.35 06-Feb-2019 ryo

improve pmap_remove
- don't lock/unlock per page in pmap_remove()
- speedup pte lookup for continuous addresses
- bring out pool_cache_put(&_pmap_pv_pool, pv) from lock/unlock section


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226
# 1.34 21-Dec-2018 ryo

- add workaround for Cavium ThunderX errata 27456.
- add cpufuncs table in cpu_info. each cpu clusters may have different erratum. (e.g. big.LITTLE)


Revision tags: pgoyette-compat-1126
# 1.33 01-Nov-2018 maxv

Add kASan support for aarch64. Stack tracking needs more investigation
and will come in a separate commit.

Reviewed by ryo@ jmcneill@ skrll@.


# 1.32 31-Oct-2018 ryo

invalidate icache correctly.
l3pte_executable() should be used for only valid pte.


Revision tags: pgoyette-compat-1020
# 1.31 18-Oct-2018 skrll

Provide generic start code that assumes the MMU is off and caches are
disabled as per the linux booting protocol for ARMv6 and ARMv7 boards.
u-boot image type should be changed to 'linux' for correct behaviour.

The new start code builds a minimal "bootstrap" L1PT with cached access
disabled and uses the same table for all processors. AP startup is
performed in less steps and more code is written in C.

The bootstrap tables and stack are placed into an (orphaned) section
"_init_memory" which is given to uvm when it is no longer used.

Various kernels have been converted to use this code and tested. Some
boards were provided by TNF. Thanks!

The GENERIC kernel now boots on boards using the TEGRA, SUNXI and EXYNOS
kernels. The GENERIC kernel will also work on RPI2 using u-boot.

Thanks to martin@ and aymeric@ for testing on parallella and nanosoc
respectively


# 1.30 14-Oct-2018 skrll

Use __nothing


# 1.29 12-Oct-2018 ryo

add initial support of COMPAT_NETBSD32 on AArch64.
arm ELF32 EABI binaries could be execute in AArch32 state on AArch64. A32 THUMB mode is not supported yet.


# 1.28 12-Oct-2018 ryo

- cleanup checking address ranges with IN_RANGE macro
- change PM_ADDR_CHECK macro to KASSERTMSG
- restore fast lookup cases with IN_RANGE macro for pmap_extract changed in my previous commit.


# 1.27 12-Oct-2018 ryo

rewrite pmap_pte_lookup() to share similar code.


# 1.26 04-Oct-2018 ryo

cleanup locore, and changed the way to map memories during boot.
- add functions bootpage_enter() and bootpage_alloc() to adapt various layout
of physical memory map. especially for 64bit physical memory layout.
pmapboot_alloc() allocates pagetable pages from _end[].
- changed to map only the required amount for PA=VA identity mapping
(kernel image, UART device, and FDT blob) with L2_BLOCK(2Mbyte).
- changing page permission for kernel image, and making KSEG mapping are done
at cpu_kernel_vm_init() instead of at locore.
- optimize PTE entries with PTE Contiguous bit. it is enabled on devmap only for now.

reviewed by skrll@, thanks.


# 1.25 04-Oct-2018 ryo

* define LX_BLKPAG_{OS,ATTR}_* for OS dependent PTE attributes in pmap.h
* cleanup macros


Revision tags: pgoyette-compat-0930
# 1.24 17-Sep-2018 ryo

delete debug printf and KASSERT.


# 1.23 10-Sep-2018 maxv

Replace KDASSERT by panic.


# 1.22 10-Sep-2018 maxv

Rename _pmap_alloc_pdp -> pmap_alloc_pdp, and make it public.


# 1.21 10-Sep-2018 ryo

cleanup aarch64 mpstart and fdt bootstrap
* arm_cpu_hatch_arg is a bad idea. avoid serializing CPU startup, and eliminate arm_cpu_hatch_arg.
in mpstart, resolve own cpu index using array of cpu_mpidr[] (aarch64)
* add support fdt enable-method "spin-table"
* add support fdt enable-method "brcm,bcm2836-smp" (for 32bit RaspberryPi)
* use arm_fdt_cpu_bootstrap() instead of psci_fdt_bootstrap()
* rename "arm/fdt/psci_fdt.h" to "arm/fdt/psci_fdtvar.h" because of conflict of include file for needs-flag
* add devmap for cpu spin-table of raspberrypi3/aarch64
* no need to force hatch APs for raspberrypi3/arm32 ifndef MULTIPROCESSOR.
* fix to work pmap_extract(kerneltext/data/bss) even if before calling pmap_bootstrap

idea to use cpu_mpidr[] by jmcneill@. reviewd by skrll@. thanks.


Revision tags: pgoyette-compat-0906
# 1.20 27-Aug-2018 ryo

need to add VM_PROT_READ when pmap_kenter_pa(va, pa, VM_PROT_WRITE, 0) or pmap_kenter_pa(va, pa, VM_PROT_EXECUTE, 0).
VM_PROT_READ is treated as an access permission inernally.


# 1.19 11-Aug-2018 ryo

change to minimum invalidation of TLB.
specifying not only va but also asid, and not invalidate L0-L2 entry using tlbi_*_ll() if needed.


# 1.18 10-Aug-2018 ryo

treat kernel-exec attr and user-exec attr separately.
kernel cannot execute userland exec page, and user cannot execute kernel page.


# 1.17 06-Aug-2018 ryo

set kernel text/rodata readonly by default.
add function db_write_text() for setting ddb breakpoint.


# 1.16 31-Jul-2018 skrll

Define and use VPRINTF


Revision tags: pgoyette-compat-0728
# 1.15 27-Jul-2018 ryo

changes of pmap.c r1.13 seems to be unstable.
In order to invalidate icache, not to invalidate all icache,
but temporary to make the page writable and invalidate target address only.


# 1.14 24-Jul-2018 ryo

don't call pool_cache_put with locking pmap. pool_cache_put call pmap_kenter_pa internally.
(pool_cache_put_paddr -> pool_cache_put_slow -> pool_get -> pmap_kenter_pa)


# 1.13 23-Jul-2018 ryo

* fix icache invalidations.
* "ic ivau" (aarch64_icache_sync_range) with VA generates permission fault in some situations, therefore use KSEG address for now.


# 1.12 23-Jul-2018 ryo

rather than using flags to resolve nested locks, reserve pool_cache before locking.


# 1.11 21-Jul-2018 ryo

* avoid deadlock. mutex_owned() works only for adaptive lock, therefore we cannot use it for spinlock...
* add more NULL check
* clear pte when pmap_enter() fails


# 1.10 17-Jul-2018 ryo

Use __debugused


# 1.9 17-Jul-2018 christos

Add missing casts, remove unused variables.


# 1.8 09-Jul-2018 ryo

need locks in pmap_kremove() and pmap_fault_fixup()


Revision tags: phil-wifi-base pgoyette-compat-0625 pgoyette-compat-0521
# 1.7 20-May-2018 ryo

branches: 1.7.2;
pmap_enter() must update modified/referenced flags by 'flags' not 'prot'.


# 1.6 16-May-2018 ryo

Fix memory leak. it was leaking one page every pmap_create().
pm->pm_vmlist must be initialized before calling _pmap_alloc_pdp().


Revision tags: pgoyette-compat-0502
# 1.5 29-Apr-2018 ryo

fix KASSERT panic. pv_entry may not be exists in pvlist when pmap_remove().


# 1.4 29-Apr-2018 ryo

delete unused code


# 1.3 27-Apr-2018 ryo

fix instability behavior of bufcache on aarch64.
* fix to return correct ref/mod when PMAP_WIRED.
* changed to keep wired flags in pte instead of pv_entry, and cleanup.


Revision tags: pgoyette-compat-0422 pgoyette-compat-0415 pgoyette-compat-0407
# 1.2 01-Apr-2018 ryo

Add initial support for ARMv8 (AARCH64) (by nisimura@ and ryo@)

- sys/arch/evbarm64 is gone and integrated into sys/arch/evbarm. (by skrll@)
- add support fdt. evbarm/conf/GENERIC64 fdt (bcm2837,sunxi,tegra) based generic 64bit kernel config. (by skrll@, jmcneill@)


Revision tags: netbsd-8-1-RELEASE netbsd-8-1-RC1 netbsd-7-2-RELEASE netbsd-8-0-RELEASE netbsd-8-0-RC2 netbsd-8-0-RC1 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 netbsd-7-1-2-RELEASE pgoyette-compat-base netbsd-7-1-1-RELEASE tls-maxphys-base-20171202 matt-nb8-mediatek-base nick-nhusb-base-20170825 perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base pgoyette-localcount-20170320 netbsd-7-1-RELEASE netbsd-7-1-RC2 nick-nhusb-base-20170204 netbsd-7-nhusb-base-20170116 bouyer-socketcan-base pgoyette-localcount-20170107 netbsd-7-1-RC1 nick-nhusb-base-20161204 pgoyette-localcount-20161104 netbsd-7-0-2-RELEASE nick-nhusb-base-20161004 localcount-20160914 netbsd-7-nhusb-base pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907 nick-nhusb-base-20160529 netbsd-7-0-1-RELEASE nick-nhusb-base-20160422 nick-nhusb-base-20160319 nick-nhusb-base-20151226 netbsd-7-0-RELEASE nick-nhusb-base-20150921 netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 nick-nhusb-base-20150606 nick-nhusb-base-20150406 nick-nhusb-base tls-maxphys-base netbsd-7-base
# 1.1 10-Aug-2014 matt

branches: 1.1.4; 1.1.28;
Preliminary files for AARCH64 (64-bit ARM) support.
Enough for a distribution build.


# 1.48 29-Oct-2019 maya

Define PMAP_NEED_PROCWR, providing strategically placed i-cache
synchronization where just-changed memory is about to be executed.

Fixes SIGILLs seen when running Mono 6 on QEMU Cortex-A57.

ok ryo


# 1.47 22-Sep-2019 jmcneill

Disable translation table walks using TTBR0 while changing its value and
when deactivating a pmap. Fixes stability issues on Ampere eMAG CPUs.


# 1.46 20-Sep-2019 ryo

ref/mod bit should be set according to 'flags' argument, not 'prot'. r1.44 was incomplete.


# 1.45 13-Sep-2019 ryo

In pmap_devmap_bootstrap(), cpu_earlydevice_va_p() must not return true until *all* devmap tables have been enabled.
console mapping may be present in the last table.


# 1.44 07-Sep-2019 ryo

- remove incorrect KASSERT. mmap(2) with prot=PROT_WRITE calls pmap_enter(..., PROT_WRITE) internally.
- fix to update page reference flags when only PROT_WRITE or PROT_EXECUTE specified


# 1.43 15-Aug-2019 skrll

Make pmap_db_pte_print more terse so it's quicker on serial consoles


# 1.42 12-Aug-2019 skrll

Use PMAP_DEV in DEVMAP_ENTRY rather than pmap_map_chunk. It's clearer and
means pmap_map_chunk can be made to map other memory types.


Revision tags: netbsd-9-base phil-wifi-20190609
# 1.41 17-May-2019 mrg

branches: 1.41.2;
apply some __diagused.


Revision tags: isaki-audio2-base
# 1.40 08-Apr-2019 ryo

- free empty page tables pages if reach a certain usage.
- need to lock at removing an old pg (_pmap_remove_pv) in _pmap_enter()


# 1.39 06-Apr-2019 ryo

Fix race conditions about pmap_page_protect() and pmap_enter().

while handling same PTE by these functions in same time, there
is a critical path that the number of valid PTEs and wire_count
are inconsistent, and it caused KASSERT.
Need to hold a pv_lock while modifying them.


# 1.38 20-Mar-2019 ryo

spinkle __printflike(), and use PRIxxx


# 1.37 19-Mar-2019 ryo

- add ddb command "machine ttbr" to dump MMU tables.
- tidy up descriptions, usages and messages.


# 1.36 19-Mar-2019 ryo

- free L1-L3 pages that has been emptied by pmap_remove().
- if no memories, pmap_enter will return correctly ENOMEM if PMAP_CANFAIL, or wait until available any memories if !PMAP_CANFAIL.

These changes improves the stability when we use a huge virtual memory spaces with mmap.


# 1.35 06-Feb-2019 ryo

improve pmap_remove
- don't lock/unlock per page in pmap_remove()
- speedup pte lookup for continuous addresses
- bring out pool_cache_put(&_pmap_pv_pool, pv) from lock/unlock section


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226
# 1.34 21-Dec-2018 ryo

- add workaround for Cavium ThunderX errata 27456.
- add cpufuncs table in cpu_info. each cpu clusters may have different erratum. (e.g. big.LITTLE)


Revision tags: pgoyette-compat-1126
# 1.33 01-Nov-2018 maxv

Add kASan support for aarch64. Stack tracking needs more investigation
and will come in a separate commit.

Reviewed by ryo@ jmcneill@ skrll@.


# 1.32 31-Oct-2018 ryo

invalidate icache correctly.
l3pte_executable() should be used for only valid pte.


Revision tags: pgoyette-compat-1020
# 1.31 18-Oct-2018 skrll

Provide generic start code that assumes the MMU is off and caches are
disabled as per the linux booting protocol for ARMv6 and ARMv7 boards.
u-boot image type should be changed to 'linux' for correct behaviour.

The new start code builds a minimal "bootstrap" L1PT with cached access
disabled and uses the same table for all processors. AP startup is
performed in less steps and more code is written in C.

The bootstrap tables and stack are placed into an (orphaned) section
"_init_memory" which is given to uvm when it is no longer used.

Various kernels have been converted to use this code and tested. Some
boards were provided by TNF. Thanks!

The GENERIC kernel now boots on boards using the TEGRA, SUNXI and EXYNOS
kernels. The GENERIC kernel will also work on RPI2 using u-boot.

Thanks to martin@ and aymeric@ for testing on parallella and nanosoc
respectively


# 1.30 14-Oct-2018 skrll

Use __nothing


# 1.29 12-Oct-2018 ryo

add initial support of COMPAT_NETBSD32 on AArch64.
arm ELF32 EABI binaries could be execute in AArch32 state on AArch64. A32 THUMB mode is not supported yet.


# 1.28 12-Oct-2018 ryo

- cleanup checking address ranges with IN_RANGE macro
- change PM_ADDR_CHECK macro to KASSERTMSG
- restore fast lookup cases with IN_RANGE macro for pmap_extract changed in my previous commit.


# 1.27 12-Oct-2018 ryo

rewrite pmap_pte_lookup() to share similar code.


# 1.26 04-Oct-2018 ryo

cleanup locore, and changed the way to map memories during boot.
- add functions bootpage_enter() and bootpage_alloc() to adapt various layout
of physical memory map. especially for 64bit physical memory layout.
pmapboot_alloc() allocates pagetable pages from _end[].
- changed to map only the required amount for PA=VA identity mapping
(kernel image, UART device, and FDT blob) with L2_BLOCK(2Mbyte).
- changing page permission for kernel image, and making KSEG mapping are done
at cpu_kernel_vm_init() instead of at locore.
- optimize PTE entries with PTE Contiguous bit. it is enabled on devmap only for now.

reviewed by skrll@, thanks.


# 1.25 04-Oct-2018 ryo

* define LX_BLKPAG_{OS,ATTR}_* for OS dependent PTE attributes in pmap.h
* cleanup macros


Revision tags: pgoyette-compat-0930
# 1.24 17-Sep-2018 ryo

delete debug printf and KASSERT.


# 1.23 10-Sep-2018 maxv

Replace KDASSERT by panic.


# 1.22 10-Sep-2018 maxv

Rename _pmap_alloc_pdp -> pmap_alloc_pdp, and make it public.


# 1.21 10-Sep-2018 ryo

cleanup aarch64 mpstart and fdt bootstrap
* arm_cpu_hatch_arg is a bad idea. avoid serializing CPU startup, and eliminate arm_cpu_hatch_arg.
in mpstart, resolve own cpu index using array of cpu_mpidr[] (aarch64)
* add support fdt enable-method "spin-table"
* add support fdt enable-method "brcm,bcm2836-smp" (for 32bit RaspberryPi)
* use arm_fdt_cpu_bootstrap() instead of psci_fdt_bootstrap()
* rename "arm/fdt/psci_fdt.h" to "arm/fdt/psci_fdtvar.h" because of conflict of include file for needs-flag
* add devmap for cpu spin-table of raspberrypi3/aarch64
* no need to force hatch APs for raspberrypi3/arm32 ifndef MULTIPROCESSOR.
* fix to work pmap_extract(kerneltext/data/bss) even if before calling pmap_bootstrap

idea to use cpu_mpidr[] by jmcneill@. reviewd by skrll@. thanks.


Revision tags: pgoyette-compat-0906
# 1.20 27-Aug-2018 ryo

need to add VM_PROT_READ when pmap_kenter_pa(va, pa, VM_PROT_WRITE, 0) or pmap_kenter_pa(va, pa, VM_PROT_EXECUTE, 0).
VM_PROT_READ is treated as an access permission inernally.


# 1.19 11-Aug-2018 ryo

change to minimum invalidation of TLB.
specifying not only va but also asid, and not invalidate L0-L2 entry using tlbi_*_ll() if needed.


# 1.18 10-Aug-2018 ryo

treat kernel-exec attr and user-exec attr separately.
kernel cannot execute userland exec page, and user cannot execute kernel page.


# 1.17 06-Aug-2018 ryo

set kernel text/rodata readonly by default.
add function db_write_text() for setting ddb breakpoint.


# 1.16 31-Jul-2018 skrll

Define and use VPRINTF


Revision tags: pgoyette-compat-0728
# 1.15 27-Jul-2018 ryo

changes of pmap.c r1.13 seems to be unstable.
In order to invalidate icache, not to invalidate all icache,
but temporary to make the page writable and invalidate target address only.


# 1.14 24-Jul-2018 ryo

don't call pool_cache_put with locking pmap. pool_cache_put call pmap_kenter_pa internally.
(pool_cache_put_paddr -> pool_cache_put_slow -> pool_get -> pmap_kenter_pa)


# 1.13 23-Jul-2018 ryo

* fix icache invalidations.
* "ic ivau" (aarch64_icache_sync_range) with VA generates permission fault in some situations, therefore use KSEG address for now.


# 1.12 23-Jul-2018 ryo

rather than using flags to resolve nested locks, reserve pool_cache before locking.


# 1.11 21-Jul-2018 ryo

* avoid deadlock. mutex_owned() works only for adaptive lock, therefore we cannot use it for spinlock...
* add more NULL check
* clear pte when pmap_enter() fails


# 1.10 17-Jul-2018 ryo

Use __debugused


# 1.9 17-Jul-2018 christos

Add missing casts, remove unused variables.


# 1.8 09-Jul-2018 ryo

need locks in pmap_kremove() and pmap_fault_fixup()


Revision tags: phil-wifi-base pgoyette-compat-0625 pgoyette-compat-0521
# 1.7 20-May-2018 ryo

branches: 1.7.2;
pmap_enter() must update modified/referenced flags by 'flags' not 'prot'.


# 1.6 16-May-2018 ryo

Fix memory leak. it was leaking one page every pmap_create().
pm->pm_vmlist must be initialized before calling _pmap_alloc_pdp().


Revision tags: pgoyette-compat-0502
# 1.5 29-Apr-2018 ryo

fix KASSERT panic. pv_entry may not be exists in pvlist when pmap_remove().


# 1.4 29-Apr-2018 ryo

delete unused code


# 1.3 27-Apr-2018 ryo

fix instability behavior of bufcache on aarch64.
* fix to return correct ref/mod when PMAP_WIRED.
* changed to keep wired flags in pte instead of pv_entry, and cleanup.


Revision tags: pgoyette-compat-0422 pgoyette-compat-0415 pgoyette-compat-0407
# 1.2 01-Apr-2018 ryo

Add initial support for ARMv8 (AARCH64) (by nisimura@ and ryo@)

- sys/arch/evbarm64 is gone and integrated into sys/arch/evbarm. (by skrll@)
- add support fdt. evbarm/conf/GENERIC64 fdt (bcm2837,sunxi,tegra) based generic 64bit kernel config. (by skrll@, jmcneill@)


Revision tags: netbsd-8-1-RELEASE netbsd-8-1-RC1 netbsd-7-2-RELEASE netbsd-8-0-RELEASE netbsd-8-0-RC2 netbsd-8-0-RC1 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 netbsd-7-1-2-RELEASE pgoyette-compat-base netbsd-7-1-1-RELEASE tls-maxphys-base-20171202 matt-nb8-mediatek-base nick-nhusb-base-20170825 perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base pgoyette-localcount-20170320 netbsd-7-1-RELEASE netbsd-7-1-RC2 nick-nhusb-base-20170204 netbsd-7-nhusb-base-20170116 bouyer-socketcan-base pgoyette-localcount-20170107 netbsd-7-1-RC1 nick-nhusb-base-20161204 pgoyette-localcount-20161104 netbsd-7-0-2-RELEASE nick-nhusb-base-20161004 localcount-20160914 netbsd-7-nhusb-base pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907 nick-nhusb-base-20160529 netbsd-7-0-1-RELEASE nick-nhusb-base-20160422 nick-nhusb-base-20160319 nick-nhusb-base-20151226 netbsd-7-0-RELEASE nick-nhusb-base-20150921 netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 nick-nhusb-base-20150606 nick-nhusb-base-20150406 nick-nhusb-base tls-maxphys-base netbsd-7-base
# 1.1 10-Aug-2014 matt

branches: 1.1.4; 1.1.28;
Preliminary files for AARCH64 (64-bit ARM) support.
Enough for a distribution build.


# 1.47 22-Sep-2019 jmcneill

Disable translation table walks using TTBR0 while changing its value and
when deactivating a pmap. Fixes stability issues on Ampere eMAG CPUs.


# 1.46 20-Sep-2019 ryo

ref/mod bit should be set according to 'flags' argument, not 'prot'. r1.44 was incomplete.


# 1.45 13-Sep-2019 ryo

In pmap_devmap_bootstrap(), cpu_earlydevice_va_p() must not return true until *all* devmap tables have been enabled.
console mapping may be present in the last table.


# 1.44 07-Sep-2019 ryo

- remove incorrect KASSERT. mmap(2) with prot=PROT_WRITE calls pmap_enter(..., PROT_WRITE) internally.
- fix to update page reference flags when only PROT_WRITE or PROT_EXECUTE specified


# 1.43 15-Aug-2019 skrll

Make pmap_db_pte_print more terse so it's quicker on serial consoles


# 1.42 12-Aug-2019 skrll

Use PMAP_DEV in DEVMAP_ENTRY rather than pmap_map_chunk. It's clearer and
means pmap_map_chunk can be made to map other memory types.


Revision tags: netbsd-9-base phil-wifi-20190609
# 1.41 17-May-2019 mrg

branches: 1.41.2;
apply some __diagused.


Revision tags: isaki-audio2-base
# 1.40 08-Apr-2019 ryo

- free empty page tables pages if reach a certain usage.
- need to lock at removing an old pg (_pmap_remove_pv) in _pmap_enter()


# 1.39 06-Apr-2019 ryo

Fix race conditions about pmap_page_protect() and pmap_enter().

while handling same PTE by these functions in same time, there
is a critical path that the number of valid PTEs and wire_count
are inconsistent, and it caused KASSERT.
Need to hold a pv_lock while modifying them.


# 1.38 20-Mar-2019 ryo

spinkle __printflike(), and use PRIxxx


# 1.37 19-Mar-2019 ryo

- add ddb command "machine ttbr" to dump MMU tables.
- tidy up descriptions, usages and messages.


# 1.36 19-Mar-2019 ryo

- free L1-L3 pages that has been emptied by pmap_remove().
- if no memories, pmap_enter will return correctly ENOMEM if PMAP_CANFAIL, or wait until available any memories if !PMAP_CANFAIL.

These changes improves the stability when we use a huge virtual memory spaces with mmap.


# 1.35 06-Feb-2019 ryo

improve pmap_remove
- don't lock/unlock per page in pmap_remove()
- speedup pte lookup for continuous addresses
- bring out pool_cache_put(&_pmap_pv_pool, pv) from lock/unlock section


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226
# 1.34 21-Dec-2018 ryo

- add workaround for Cavium ThunderX errata 27456.
- add cpufuncs table in cpu_info. each cpu clusters may have different erratum. (e.g. big.LITTLE)


Revision tags: pgoyette-compat-1126
# 1.33 01-Nov-2018 maxv

Add kASan support for aarch64. Stack tracking needs more investigation
and will come in a separate commit.

Reviewed by ryo@ jmcneill@ skrll@.


# 1.32 31-Oct-2018 ryo

invalidate icache correctly.
l3pte_executable() should be used for only valid pte.


Revision tags: pgoyette-compat-1020
# 1.31 18-Oct-2018 skrll

Provide generic start code that assumes the MMU is off and caches are
disabled as per the linux booting protocol for ARMv6 and ARMv7 boards.
u-boot image type should be changed to 'linux' for correct behaviour.

The new start code builds a minimal "bootstrap" L1PT with cached access
disabled and uses the same table for all processors. AP startup is
performed in less steps and more code is written in C.

The bootstrap tables and stack are placed into an (orphaned) section
"_init_memory" which is given to uvm when it is no longer used.

Various kernels have been converted to use this code and tested. Some
boards were provided by TNF. Thanks!

The GENERIC kernel now boots on boards using the TEGRA, SUNXI and EXYNOS
kernels. The GENERIC kernel will also work on RPI2 using u-boot.

Thanks to martin@ and aymeric@ for testing on parallella and nanosoc
respectively


# 1.30 14-Oct-2018 skrll

Use __nothing


# 1.29 12-Oct-2018 ryo

add initial support of COMPAT_NETBSD32 on AArch64.
arm ELF32 EABI binaries could be execute in AArch32 state on AArch64. A32 THUMB mode is not supported yet.


# 1.28 12-Oct-2018 ryo

- cleanup checking address ranges with IN_RANGE macro
- change PM_ADDR_CHECK macro to KASSERTMSG
- restore fast lookup cases with IN_RANGE macro for pmap_extract changed in my previous commit.


# 1.27 12-Oct-2018 ryo

rewrite pmap_pte_lookup() to share similar code.


# 1.26 04-Oct-2018 ryo

cleanup locore, and changed the way to map memories during boot.
- add functions bootpage_enter() and bootpage_alloc() to adapt various layout
of physical memory map. especially for 64bit physical memory layout.
pmapboot_alloc() allocates pagetable pages from _end[].
- changed to map only the required amount for PA=VA identity mapping
(kernel image, UART device, and FDT blob) with L2_BLOCK(2Mbyte).
- changing page permission for kernel image, and making KSEG mapping are done
at cpu_kernel_vm_init() instead of at locore.
- optimize PTE entries with PTE Contiguous bit. it is enabled on devmap only for now.

reviewed by skrll@, thanks.


# 1.25 04-Oct-2018 ryo

* define LX_BLKPAG_{OS,ATTR}_* for OS dependent PTE attributes in pmap.h
* cleanup macros


Revision tags: pgoyette-compat-0930
# 1.24 17-Sep-2018 ryo

delete debug printf and KASSERT.


# 1.23 10-Sep-2018 maxv

Replace KDASSERT by panic.


# 1.22 10-Sep-2018 maxv

Rename _pmap_alloc_pdp -> pmap_alloc_pdp, and make it public.


# 1.21 10-Sep-2018 ryo

cleanup aarch64 mpstart and fdt bootstrap
* arm_cpu_hatch_arg is a bad idea. avoid serializing CPU startup, and eliminate arm_cpu_hatch_arg.
in mpstart, resolve own cpu index using array of cpu_mpidr[] (aarch64)
* add support fdt enable-method "spin-table"
* add support fdt enable-method "brcm,bcm2836-smp" (for 32bit RaspberryPi)
* use arm_fdt_cpu_bootstrap() instead of psci_fdt_bootstrap()
* rename "arm/fdt/psci_fdt.h" to "arm/fdt/psci_fdtvar.h" because of conflict of include file for needs-flag
* add devmap for cpu spin-table of raspberrypi3/aarch64
* no need to force hatch APs for raspberrypi3/arm32 ifndef MULTIPROCESSOR.
* fix to work pmap_extract(kerneltext/data/bss) even if before calling pmap_bootstrap

idea to use cpu_mpidr[] by jmcneill@. reviewd by skrll@. thanks.


Revision tags: pgoyette-compat-0906
# 1.20 27-Aug-2018 ryo

need to add VM_PROT_READ when pmap_kenter_pa(va, pa, VM_PROT_WRITE, 0) or pmap_kenter_pa(va, pa, VM_PROT_EXECUTE, 0).
VM_PROT_READ is treated as an access permission inernally.


# 1.19 11-Aug-2018 ryo

change to minimum invalidation of TLB.
specifying not only va but also asid, and not invalidate L0-L2 entry using tlbi_*_ll() if needed.


# 1.18 10-Aug-2018 ryo

treat kernel-exec attr and user-exec attr separately.
kernel cannot execute userland exec page, and user cannot execute kernel page.


# 1.17 06-Aug-2018 ryo

set kernel text/rodata readonly by default.
add function db_write_text() for setting ddb breakpoint.


# 1.16 31-Jul-2018 skrll

Define and use VPRINTF


Revision tags: pgoyette-compat-0728
# 1.15 27-Jul-2018 ryo

changes of pmap.c r1.13 seems to be unstable.
In order to invalidate icache, not to invalidate all icache,
but temporary to make the page writable and invalidate target address only.


# 1.14 24-Jul-2018 ryo

don't call pool_cache_put with locking pmap. pool_cache_put call pmap_kenter_pa internally.
(pool_cache_put_paddr -> pool_cache_put_slow -> pool_get -> pmap_kenter_pa)


# 1.13 23-Jul-2018 ryo

* fix icache invalidations.
* "ic ivau" (aarch64_icache_sync_range) with VA generates permission fault in some situations, therefore use KSEG address for now.


# 1.12 23-Jul-2018 ryo

rather than using flags to resolve nested locks, reserve pool_cache before locking.


# 1.11 21-Jul-2018 ryo

* avoid deadlock. mutex_owned() works only for adaptive lock, therefore we cannot use it for spinlock...
* add more NULL check
* clear pte when pmap_enter() fails


# 1.10 17-Jul-2018 ryo

Use __debugused


# 1.9 17-Jul-2018 christos

Add missing casts, remove unused variables.


# 1.8 09-Jul-2018 ryo

need locks in pmap_kremove() and pmap_fault_fixup()


Revision tags: phil-wifi-base pgoyette-compat-0625 pgoyette-compat-0521
# 1.7 20-May-2018 ryo

branches: 1.7.2;
pmap_enter() must update modified/referenced flags by 'flags' not 'prot'.


# 1.6 16-May-2018 ryo

Fix memory leak. it was leaking one page every pmap_create().
pm->pm_vmlist must be initialized before calling _pmap_alloc_pdp().


Revision tags: pgoyette-compat-0502
# 1.5 29-Apr-2018 ryo

fix KASSERT panic. pv_entry may not be exists in pvlist when pmap_remove().


# 1.4 29-Apr-2018 ryo

delete unused code


# 1.3 27-Apr-2018 ryo

fix instability behavior of bufcache on aarch64.
* fix to return correct ref/mod when PMAP_WIRED.
* changed to keep wired flags in pte instead of pv_entry, and cleanup.


Revision tags: pgoyette-compat-0422 pgoyette-compat-0415 pgoyette-compat-0407
# 1.2 01-Apr-2018 ryo

Add initial support for ARMv8 (AARCH64) (by nisimura@ and ryo@)

- sys/arch/evbarm64 is gone and integrated into sys/arch/evbarm. (by skrll@)
- add support fdt. evbarm/conf/GENERIC64 fdt (bcm2837,sunxi,tegra) based generic 64bit kernel config. (by skrll@, jmcneill@)


Revision tags: netbsd-8-1-RELEASE netbsd-8-1-RC1 netbsd-7-2-RELEASE netbsd-8-0-RELEASE netbsd-8-0-RC2 netbsd-8-0-RC1 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 netbsd-7-1-2-RELEASE pgoyette-compat-base netbsd-7-1-1-RELEASE tls-maxphys-base-20171202 matt-nb8-mediatek-base nick-nhusb-base-20170825 perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base pgoyette-localcount-20170320 netbsd-7-1-RELEASE netbsd-7-1-RC2 nick-nhusb-base-20170204 netbsd-7-nhusb-base-20170116 bouyer-socketcan-base pgoyette-localcount-20170107 netbsd-7-1-RC1 nick-nhusb-base-20161204 pgoyette-localcount-20161104 netbsd-7-0-2-RELEASE nick-nhusb-base-20161004 localcount-20160914 netbsd-7-nhusb-base pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907 nick-nhusb-base-20160529 netbsd-7-0-1-RELEASE nick-nhusb-base-20160422 nick-nhusb-base-20160319 nick-nhusb-base-20151226 netbsd-7-0-RELEASE nick-nhusb-base-20150921 netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 nick-nhusb-base-20150606 nick-nhusb-base-20150406 nick-nhusb-base tls-maxphys-base netbsd-7-base
# 1.1 10-Aug-2014 matt

branches: 1.1.4; 1.1.28;
Preliminary files for AARCH64 (64-bit ARM) support.
Enough for a distribution build.


# 1.46 20-Sep-2019 ryo

ref/mod bit should be set according to 'flags' argument, not 'prot'. r1.44 was incomplete.


# 1.45 13-Sep-2019 ryo

In pmap_devmap_bootstrap(), cpu_earlydevice_va_p() must not return true until *all* devmap tables have been enabled.
console mapping may be present in the last table.


# 1.44 07-Sep-2019 ryo

- remove incorrect KASSERT. mmap(2) with prot=PROT_WRITE calls pmap_enter(..., PROT_WRITE) internally.
- fix to update page reference flags when only PROT_WRITE or PROT_EXECUTE specified


# 1.43 15-Aug-2019 skrll

Make pmap_db_pte_print more terse so it's quicker on serial consoles


# 1.42 12-Aug-2019 skrll

Use PMAP_DEV in DEVMAP_ENTRY rather than pmap_map_chunk. It's clearer and
means pmap_map_chunk can be made to map other memory types.


Revision tags: netbsd-9-base phil-wifi-20190609
# 1.41 17-May-2019 mrg

apply some __diagused.


Revision tags: isaki-audio2-base
# 1.40 08-Apr-2019 ryo

- free empty page tables pages if reach a certain usage.
- need to lock at removing an old pg (_pmap_remove_pv) in _pmap_enter()


# 1.39 06-Apr-2019 ryo

Fix race conditions about pmap_page_protect() and pmap_enter().

while handling same PTE by these functions in same time, there
is a critical path that the number of valid PTEs and wire_count
are inconsistent, and it caused KASSERT.
Need to hold a pv_lock while modifying them.


# 1.38 20-Mar-2019 ryo

spinkle __printflike(), and use PRIxxx


# 1.37 19-Mar-2019 ryo

- add ddb command "machine ttbr" to dump MMU tables.
- tidy up descriptions, usages and messages.


# 1.36 19-Mar-2019 ryo

- free L1-L3 pages that has been emptied by pmap_remove().
- if no memories, pmap_enter will return correctly ENOMEM if PMAP_CANFAIL, or wait until available any memories if !PMAP_CANFAIL.

These changes improves the stability when we use a huge virtual memory spaces with mmap.


# 1.35 06-Feb-2019 ryo

improve pmap_remove
- don't lock/unlock per page in pmap_remove()
- speedup pte lookup for continuous addresses
- bring out pool_cache_put(&_pmap_pv_pool, pv) from lock/unlock section


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226
# 1.34 21-Dec-2018 ryo

- add workaround for Cavium ThunderX errata 27456.
- add cpufuncs table in cpu_info. each cpu clusters may have different erratum. (e.g. big.LITTLE)


Revision tags: pgoyette-compat-1126
# 1.33 01-Nov-2018 maxv

Add kASan support for aarch64. Stack tracking needs more investigation
and will come in a separate commit.

Reviewed by ryo@ jmcneill@ skrll@.


# 1.32 31-Oct-2018 ryo

invalidate icache correctly.
l3pte_executable() should be used for only valid pte.


Revision tags: pgoyette-compat-1020
# 1.31 18-Oct-2018 skrll

Provide generic start code that assumes the MMU is off and caches are
disabled as per the linux booting protocol for ARMv6 and ARMv7 boards.
u-boot image type should be changed to 'linux' for correct behaviour.

The new start code builds a minimal "bootstrap" L1PT with cached access
disabled and uses the same table for all processors. AP startup is
performed in less steps and more code is written in C.

The bootstrap tables and stack are placed into an (orphaned) section
"_init_memory" which is given to uvm when it is no longer used.

Various kernels have been converted to use this code and tested. Some
boards were provided by TNF. Thanks!

The GENERIC kernel now boots on boards using the TEGRA, SUNXI and EXYNOS
kernels. The GENERIC kernel will also work on RPI2 using u-boot.

Thanks to martin@ and aymeric@ for testing on parallella and nanosoc
respectively


# 1.30 14-Oct-2018 skrll

Use __nothing


# 1.29 12-Oct-2018 ryo

add initial support of COMPAT_NETBSD32 on AArch64.
arm ELF32 EABI binaries could be execute in AArch32 state on AArch64. A32 THUMB mode is not supported yet.


# 1.28 12-Oct-2018 ryo

- cleanup checking address ranges with IN_RANGE macro
- change PM_ADDR_CHECK macro to KASSERTMSG
- restore fast lookup cases with IN_RANGE macro for pmap_extract changed in my previous commit.


# 1.27 12-Oct-2018 ryo

rewrite pmap_pte_lookup() to share similar code.


# 1.26 04-Oct-2018 ryo

cleanup locore, and changed the way to map memories during boot.
- add functions bootpage_enter() and bootpage_alloc() to adapt various layout
of physical memory map. especially for 64bit physical memory layout.
pmapboot_alloc() allocates pagetable pages from _end[].
- changed to map only the required amount for PA=VA identity mapping
(kernel image, UART device, and FDT blob) with L2_BLOCK(2Mbyte).
- changing page permission for kernel image, and making KSEG mapping are done
at cpu_kernel_vm_init() instead of at locore.
- optimize PTE entries with PTE Contiguous bit. it is enabled on devmap only for now.

reviewed by skrll@, thanks.


# 1.25 04-Oct-2018 ryo

* define LX_BLKPAG_{OS,ATTR}_* for OS dependent PTE attributes in pmap.h
* cleanup macros


Revision tags: pgoyette-compat-0930
# 1.24 17-Sep-2018 ryo

delete debug printf and KASSERT.


# 1.23 10-Sep-2018 maxv

Replace KDASSERT by panic.


# 1.22 10-Sep-2018 maxv

Rename _pmap_alloc_pdp -> pmap_alloc_pdp, and make it public.


# 1.21 10-Sep-2018 ryo

cleanup aarch64 mpstart and fdt bootstrap
* arm_cpu_hatch_arg is a bad idea. avoid serializing CPU startup, and eliminate arm_cpu_hatch_arg.
in mpstart, resolve own cpu index using array of cpu_mpidr[] (aarch64)
* add support fdt enable-method "spin-table"
* add support fdt enable-method "brcm,bcm2836-smp" (for 32bit RaspberryPi)
* use arm_fdt_cpu_bootstrap() instead of psci_fdt_bootstrap()
* rename "arm/fdt/psci_fdt.h" to "arm/fdt/psci_fdtvar.h" because of conflict of include file for needs-flag
* add devmap for cpu spin-table of raspberrypi3/aarch64
* no need to force hatch APs for raspberrypi3/arm32 ifndef MULTIPROCESSOR.
* fix to work pmap_extract(kerneltext/data/bss) even if before calling pmap_bootstrap

idea to use cpu_mpidr[] by jmcneill@. reviewd by skrll@. thanks.


Revision tags: pgoyette-compat-0906
# 1.20 27-Aug-2018 ryo

need to add VM_PROT_READ when pmap_kenter_pa(va, pa, VM_PROT_WRITE, 0) or pmap_kenter_pa(va, pa, VM_PROT_EXECUTE, 0).
VM_PROT_READ is treated as an access permission inernally.


# 1.19 11-Aug-2018 ryo

change to minimum invalidation of TLB.
specifying not only va but also asid, and not invalidate L0-L2 entry using tlbi_*_ll() if needed.


# 1.18 10-Aug-2018 ryo

treat kernel-exec attr and user-exec attr separately.
kernel cannot execute userland exec page, and user cannot execute kernel page.


# 1.17 06-Aug-2018 ryo

set kernel text/rodata readonly by default.
add function db_write_text() for setting ddb breakpoint.


# 1.16 31-Jul-2018 skrll

Define and use VPRINTF


Revision tags: pgoyette-compat-0728
# 1.15 27-Jul-2018 ryo

changes of pmap.c r1.13 seems to be unstable.
In order to invalidate icache, not to invalidate all icache,
but temporary to make the page writable and invalidate target address only.


# 1.14 24-Jul-2018 ryo

don't call pool_cache_put with locking pmap. pool_cache_put call pmap_kenter_pa internally.
(pool_cache_put_paddr -> pool_cache_put_slow -> pool_get -> pmap_kenter_pa)


# 1.13 23-Jul-2018 ryo

* fix icache invalidations.
* "ic ivau" (aarch64_icache_sync_range) with VA generates permission fault in some situations, therefore use KSEG address for now.


# 1.12 23-Jul-2018 ryo

rather than using flags to resolve nested locks, reserve pool_cache before locking.


# 1.11 21-Jul-2018 ryo

* avoid deadlock. mutex_owned() works only for adaptive lock, therefore we cannot use it for spinlock...
* add more NULL check
* clear pte when pmap_enter() fails


# 1.10 17-Jul-2018 ryo

Use __debugused


# 1.9 17-Jul-2018 christos

Add missing casts, remove unused variables.


# 1.8 09-Jul-2018 ryo

need locks in pmap_kremove() and pmap_fault_fixup()


Revision tags: phil-wifi-base pgoyette-compat-0625 pgoyette-compat-0521
# 1.7 20-May-2018 ryo

branches: 1.7.2;
pmap_enter() must update modified/referenced flags by 'flags' not 'prot'.


# 1.6 16-May-2018 ryo

Fix memory leak. it was leaking one page every pmap_create().
pm->pm_vmlist must be initialized before calling _pmap_alloc_pdp().


Revision tags: pgoyette-compat-0502
# 1.5 29-Apr-2018 ryo

fix KASSERT panic. pv_entry may not be exists in pvlist when pmap_remove().


# 1.4 29-Apr-2018 ryo

delete unused code


# 1.3 27-Apr-2018 ryo

fix instability behavior of bufcache on aarch64.
* fix to return correct ref/mod when PMAP_WIRED.
* changed to keep wired flags in pte instead of pv_entry, and cleanup.


Revision tags: pgoyette-compat-0422 pgoyette-compat-0415 pgoyette-compat-0407
# 1.2 01-Apr-2018 ryo

Add initial support for ARMv8 (AARCH64) (by nisimura@ and ryo@)

- sys/arch/evbarm64 is gone and integrated into sys/arch/evbarm. (by skrll@)
- add support fdt. evbarm/conf/GENERIC64 fdt (bcm2837,sunxi,tegra) based generic 64bit kernel config. (by skrll@, jmcneill@)


Revision tags: netbsd-8-1-RELEASE netbsd-8-1-RC1 netbsd-7-2-RELEASE netbsd-8-0-RELEASE netbsd-8-0-RC2 netbsd-8-0-RC1 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 netbsd-7-1-2-RELEASE pgoyette-compat-base netbsd-7-1-1-RELEASE tls-maxphys-base-20171202 matt-nb8-mediatek-base nick-nhusb-base-20170825 perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base pgoyette-localcount-20170320 netbsd-7-1-RELEASE netbsd-7-1-RC2 nick-nhusb-base-20170204 netbsd-7-nhusb-base-20170116 bouyer-socketcan-base pgoyette-localcount-20170107 netbsd-7-1-RC1 nick-nhusb-base-20161204 pgoyette-localcount-20161104 netbsd-7-0-2-RELEASE nick-nhusb-base-20161004 localcount-20160914 netbsd-7-nhusb-base pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907 nick-nhusb-base-20160529 netbsd-7-0-1-RELEASE nick-nhusb-base-20160422 nick-nhusb-base-20160319 nick-nhusb-base-20151226 netbsd-7-0-RELEASE nick-nhusb-base-20150921 netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 nick-nhusb-base-20150606 nick-nhusb-base-20150406 nick-nhusb-base tls-maxphys-base netbsd-7-base
# 1.1 10-Aug-2014 matt

branches: 1.1.4; 1.1.28;
Preliminary files for AARCH64 (64-bit ARM) support.
Enough for a distribution build.


# 1.45 13-Sep-2019 ryo

In pmap_devmap_bootstrap(), cpu_earlydevice_va_p() must not return true until *all* devmap tables have been enabled.
console mapping may be present in the last table.


# 1.44 07-Sep-2019 ryo

- remove incorrect KASSERT. mmap(2) with prot=PROT_WRITE calls pmap_enter(..., PROT_WRITE) internally.
- fix to update page reference flags when only PROT_WRITE or PROT_EXECUTE specified


# 1.43 15-Aug-2019 skrll

Make pmap_db_pte_print more terse so it's quicker on serial consoles


# 1.42 12-Aug-2019 skrll

Use PMAP_DEV in DEVMAP_ENTRY rather than pmap_map_chunk. It's clearer and
means pmap_map_chunk can be made to map other memory types.


Revision tags: netbsd-9-base phil-wifi-20190609
# 1.41 17-May-2019 mrg

apply some __diagused.


Revision tags: isaki-audio2-base
# 1.40 08-Apr-2019 ryo

- free empty page tables pages if reach a certain usage.
- need to lock at removing an old pg (_pmap_remove_pv) in _pmap_enter()


# 1.39 06-Apr-2019 ryo

Fix race conditions about pmap_page_protect() and pmap_enter().

while handling same PTE by these functions in same time, there
is a critical path that the number of valid PTEs and wire_count
are inconsistent, and it caused KASSERT.
Need to hold a pv_lock while modifying them.


# 1.38 20-Mar-2019 ryo

spinkle __printflike(), and use PRIxxx


# 1.37 19-Mar-2019 ryo

- add ddb command "machine ttbr" to dump MMU tables.
- tidy up descriptions, usages and messages.


# 1.36 19-Mar-2019 ryo

- free L1-L3 pages that has been emptied by pmap_remove().
- if no memories, pmap_enter will return correctly ENOMEM if PMAP_CANFAIL, or wait until available any memories if !PMAP_CANFAIL.

These changes improves the stability when we use a huge virtual memory spaces with mmap.


# 1.35 06-Feb-2019 ryo

improve pmap_remove
- don't lock/unlock per page in pmap_remove()
- speedup pte lookup for continuous addresses
- bring out pool_cache_put(&_pmap_pv_pool, pv) from lock/unlock section


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226
# 1.34 21-Dec-2018 ryo

- add workaround for Cavium ThunderX errata 27456.
- add cpufuncs table in cpu_info. each cpu clusters may have different erratum. (e.g. big.LITTLE)


Revision tags: pgoyette-compat-1126
# 1.33 01-Nov-2018 maxv

Add kASan support for aarch64. Stack tracking needs more investigation
and will come in a separate commit.

Reviewed by ryo@ jmcneill@ skrll@.


# 1.32 31-Oct-2018 ryo

invalidate icache correctly.
l3pte_executable() should be used for only valid pte.


Revision tags: pgoyette-compat-1020
# 1.31 18-Oct-2018 skrll

Provide generic start code that assumes the MMU is off and caches are
disabled as per the linux booting protocol for ARMv6 and ARMv7 boards.
u-boot image type should be changed to 'linux' for correct behaviour.

The new start code builds a minimal "bootstrap" L1PT with cached access
disabled and uses the same table for all processors. AP startup is
performed in less steps and more code is written in C.

The bootstrap tables and stack are placed into an (orphaned) section
"_init_memory" which is given to uvm when it is no longer used.

Various kernels have been converted to use this code and tested. Some
boards were provided by TNF. Thanks!

The GENERIC kernel now boots on boards using the TEGRA, SUNXI and EXYNOS
kernels. The GENERIC kernel will also work on RPI2 using u-boot.

Thanks to martin@ and aymeric@ for testing on parallella and nanosoc
respectively


# 1.30 14-Oct-2018 skrll

Use __nothing


# 1.29 12-Oct-2018 ryo

add initial support of COMPAT_NETBSD32 on AArch64.
arm ELF32 EABI binaries could be execute in AArch32 state on AArch64. A32 THUMB mode is not supported yet.


# 1.28 12-Oct-2018 ryo

- cleanup checking address ranges with IN_RANGE macro
- change PM_ADDR_CHECK macro to KASSERTMSG
- restore fast lookup cases with IN_RANGE macro for pmap_extract changed in my previous commit.


# 1.27 12-Oct-2018 ryo

rewrite pmap_pte_lookup() to share similar code.


# 1.26 04-Oct-2018 ryo

cleanup locore, and changed the way to map memories during boot.
- add functions bootpage_enter() and bootpage_alloc() to adapt various layout
of physical memory map. especially for 64bit physical memory layout.
pmapboot_alloc() allocates pagetable pages from _end[].
- changed to map only the required amount for PA=VA identity mapping
(kernel image, UART device, and FDT blob) with L2_BLOCK(2Mbyte).
- changing page permission for kernel image, and making KSEG mapping are done
at cpu_kernel_vm_init() instead of at locore.
- optimize PTE entries with PTE Contiguous bit. it is enabled on devmap only for now.

reviewed by skrll@, thanks.


# 1.25 04-Oct-2018 ryo

* define LX_BLKPAG_{OS,ATTR}_* for OS dependent PTE attributes in pmap.h
* cleanup macros


Revision tags: pgoyette-compat-0930
# 1.24 17-Sep-2018 ryo

delete debug printf and KASSERT.


# 1.23 10-Sep-2018 maxv

Replace KDASSERT by panic.


# 1.22 10-Sep-2018 maxv

Rename _pmap_alloc_pdp -> pmap_alloc_pdp, and make it public.


# 1.21 10-Sep-2018 ryo

cleanup aarch64 mpstart and fdt bootstrap
* arm_cpu_hatch_arg is a bad idea. avoid serializing CPU startup, and eliminate arm_cpu_hatch_arg.
in mpstart, resolve own cpu index using array of cpu_mpidr[] (aarch64)
* add support fdt enable-method "spin-table"
* add support fdt enable-method "brcm,bcm2836-smp" (for 32bit RaspberryPi)
* use arm_fdt_cpu_bootstrap() instead of psci_fdt_bootstrap()
* rename "arm/fdt/psci_fdt.h" to "arm/fdt/psci_fdtvar.h" because of conflict of include file for needs-flag
* add devmap for cpu spin-table of raspberrypi3/aarch64
* no need to force hatch APs for raspberrypi3/arm32 ifndef MULTIPROCESSOR.
* fix to work pmap_extract(kerneltext/data/bss) even if before calling pmap_bootstrap

idea to use cpu_mpidr[] by jmcneill@. reviewd by skrll@. thanks.


Revision tags: pgoyette-compat-0906
# 1.20 27-Aug-2018 ryo

need to add VM_PROT_READ when pmap_kenter_pa(va, pa, VM_PROT_WRITE, 0) or pmap_kenter_pa(va, pa, VM_PROT_EXECUTE, 0).
VM_PROT_READ is treated as an access permission inernally.


# 1.19 11-Aug-2018 ryo

change to minimum invalidation of TLB.
specifying not only va but also asid, and not invalidate L0-L2 entry using tlbi_*_ll() if needed.


# 1.18 10-Aug-2018 ryo

treat kernel-exec attr and user-exec attr separately.
kernel cannot execute userland exec page, and user cannot execute kernel page.


# 1.17 06-Aug-2018 ryo

set kernel text/rodata readonly by default.
add function db_write_text() for setting ddb breakpoint.


# 1.16 31-Jul-2018 skrll

Define and use VPRINTF


Revision tags: pgoyette-compat-0728
# 1.15 27-Jul-2018 ryo

changes of pmap.c r1.13 seems to be unstable.
In order to invalidate icache, not to invalidate all icache,
but temporary to make the page writable and invalidate target address only.


# 1.14 24-Jul-2018 ryo

don't call pool_cache_put with locking pmap. pool_cache_put call pmap_kenter_pa internally.
(pool_cache_put_paddr -> pool_cache_put_slow -> pool_get -> pmap_kenter_pa)


# 1.13 23-Jul-2018 ryo

* fix icache invalidations.
* "ic ivau" (aarch64_icache_sync_range) with VA generates permission fault in some situations, therefore use KSEG address for now.


# 1.12 23-Jul-2018 ryo

rather than using flags to resolve nested locks, reserve pool_cache before locking.


# 1.11 21-Jul-2018 ryo

* avoid deadlock. mutex_owned() works only for adaptive lock, therefore we cannot use it for spinlock...
* add more NULL check
* clear pte when pmap_enter() fails


# 1.10 17-Jul-2018 ryo

Use __debugused


# 1.9 17-Jul-2018 christos

Add missing casts, remove unused variables.


# 1.8 09-Jul-2018 ryo

need locks in pmap_kremove() and pmap_fault_fixup()


Revision tags: phil-wifi-base pgoyette-compat-0625 pgoyette-compat-0521
# 1.7 20-May-2018 ryo

branches: 1.7.2;
pmap_enter() must update modified/referenced flags by 'flags' not 'prot'.


# 1.6 16-May-2018 ryo

Fix memory leak. it was leaking one page every pmap_create().
pm->pm_vmlist must be initialized before calling _pmap_alloc_pdp().


Revision tags: pgoyette-compat-0502
# 1.5 29-Apr-2018 ryo

fix KASSERT panic. pv_entry may not be exists in pvlist when pmap_remove().


# 1.4 29-Apr-2018 ryo

delete unused code


# 1.3 27-Apr-2018 ryo

fix instability behavior of bufcache on aarch64.
* fix to return correct ref/mod when PMAP_WIRED.
* changed to keep wired flags in pte instead of pv_entry, and cleanup.


Revision tags: pgoyette-compat-0422 pgoyette-compat-0415 pgoyette-compat-0407
# 1.2 01-Apr-2018 ryo

Add initial support for ARMv8 (AARCH64) (by nisimura@ and ryo@)

- sys/arch/evbarm64 is gone and integrated into sys/arch/evbarm. (by skrll@)
- add support fdt. evbarm/conf/GENERIC64 fdt (bcm2837,sunxi,tegra) based generic 64bit kernel config. (by skrll@, jmcneill@)


Revision tags: netbsd-8-1-RELEASE netbsd-8-1-RC1 netbsd-7-2-RELEASE netbsd-8-0-RELEASE netbsd-8-0-RC2 netbsd-8-0-RC1 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 netbsd-7-1-2-RELEASE pgoyette-compat-base netbsd-7-1-1-RELEASE tls-maxphys-base-20171202 matt-nb8-mediatek-base nick-nhusb-base-20170825 perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base pgoyette-localcount-20170320 netbsd-7-1-RELEASE netbsd-7-1-RC2 nick-nhusb-base-20170204 netbsd-7-nhusb-base-20170116 bouyer-socketcan-base pgoyette-localcount-20170107 netbsd-7-1-RC1 nick-nhusb-base-20161204 pgoyette-localcount-20161104 netbsd-7-0-2-RELEASE nick-nhusb-base-20161004 localcount-20160914 netbsd-7-nhusb-base pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907 nick-nhusb-base-20160529 netbsd-7-0-1-RELEASE nick-nhusb-base-20160422 nick-nhusb-base-20160319 nick-nhusb-base-20151226 netbsd-7-0-RELEASE nick-nhusb-base-20150921 netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 nick-nhusb-base-20150606 nick-nhusb-base-20150406 nick-nhusb-base tls-maxphys-base netbsd-7-base
# 1.1 10-Aug-2014 matt

branches: 1.1.4; 1.1.28;
Preliminary files for AARCH64 (64-bit ARM) support.
Enough for a distribution build.


# 1.44 07-Sep-2019 ryo

- remove incorrect KASSERT. mmap(2) with prot=PROT_WRITE calls pmap_enter(..., PROT_WRITE) internally.
- fix to update page reference flags when only PROT_WRITE or PROT_EXECUTE specified


# 1.43 15-Aug-2019 skrll

Make pmap_db_pte_print more terse so it's quicker on serial consoles


# 1.42 12-Aug-2019 skrll

Use PMAP_DEV in DEVMAP_ENTRY rather than pmap_map_chunk. It's clearer and
means pmap_map_chunk can be made to map other memory types.


Revision tags: netbsd-9-base phil-wifi-20190609
# 1.41 17-May-2019 mrg

apply some __diagused.


Revision tags: isaki-audio2-base
# 1.40 08-Apr-2019 ryo

- free empty page tables pages if reach a certain usage.
- need to lock at removing an old pg (_pmap_remove_pv) in _pmap_enter()


# 1.39 06-Apr-2019 ryo

Fix race conditions about pmap_page_protect() and pmap_enter().

while handling same PTE by these functions in same time, there
is a critical path that the number of valid PTEs and wire_count
are inconsistent, and it caused KASSERT.
Need to hold a pv_lock while modifying them.


# 1.38 20-Mar-2019 ryo

spinkle __printflike(), and use PRIxxx


# 1.37 19-Mar-2019 ryo

- add ddb command "machine ttbr" to dump MMU tables.
- tidy up descriptions, usages and messages.


# 1.36 19-Mar-2019 ryo

- free L1-L3 pages that has been emptied by pmap_remove().
- if no memories, pmap_enter will return correctly ENOMEM if PMAP_CANFAIL, or wait until available any memories if !PMAP_CANFAIL.

These changes improves the stability when we use a huge virtual memory spaces with mmap.


# 1.35 06-Feb-2019 ryo

improve pmap_remove
- don't lock/unlock per page in pmap_remove()
- speedup pte lookup for continuous addresses
- bring out pool_cache_put(&_pmap_pv_pool, pv) from lock/unlock section


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226
# 1.34 21-Dec-2018 ryo

- add workaround for Cavium ThunderX errata 27456.
- add cpufuncs table in cpu_info. each cpu clusters may have different erratum. (e.g. big.LITTLE)


Revision tags: pgoyette-compat-1126
# 1.33 01-Nov-2018 maxv

Add kASan support for aarch64. Stack tracking needs more investigation
and will come in a separate commit.

Reviewed by ryo@ jmcneill@ skrll@.


# 1.32 31-Oct-2018 ryo

invalidate icache correctly.
l3pte_executable() should be used for only valid pte.


Revision tags: pgoyette-compat-1020
# 1.31 18-Oct-2018 skrll

Provide generic start code that assumes the MMU is off and caches are
disabled as per the linux booting protocol for ARMv6 and ARMv7 boards.
u-boot image type should be changed to 'linux' for correct behaviour.

The new start code builds a minimal "bootstrap" L1PT with cached access
disabled and uses the same table for all processors. AP startup is
performed in less steps and more code is written in C.

The bootstrap tables and stack are placed into an (orphaned) section
"_init_memory" which is given to uvm when it is no longer used.

Various kernels have been converted to use this code and tested. Some
boards were provided by TNF. Thanks!

The GENERIC kernel now boots on boards using the TEGRA, SUNXI and EXYNOS
kernels. The GENERIC kernel will also work on RPI2 using u-boot.

Thanks to martin@ and aymeric@ for testing on parallella and nanosoc
respectively


# 1.30 14-Oct-2018 skrll

Use __nothing


# 1.29 12-Oct-2018 ryo

add initial support of COMPAT_NETBSD32 on AArch64.
arm ELF32 EABI binaries could be execute in AArch32 state on AArch64. A32 THUMB mode is not supported yet.


# 1.28 12-Oct-2018 ryo

- cleanup checking address ranges with IN_RANGE macro
- change PM_ADDR_CHECK macro to KASSERTMSG
- restore fast lookup cases with IN_RANGE macro for pmap_extract changed in my previous commit.


# 1.27 12-Oct-2018 ryo

rewrite pmap_pte_lookup() to share similar code.


# 1.26 04-Oct-2018 ryo

cleanup locore, and changed the way to map memories during boot.
- add functions bootpage_enter() and bootpage_alloc() to adapt various layout
of physical memory map. especially for 64bit physical memory layout.
pmapboot_alloc() allocates pagetable pages from _end[].
- changed to map only the required amount for PA=VA identity mapping
(kernel image, UART device, and FDT blob) with L2_BLOCK(2Mbyte).
- changing page permission for kernel image, and making KSEG mapping are done
at cpu_kernel_vm_init() instead of at locore.
- optimize PTE entries with PTE Contiguous bit. it is enabled on devmap only for now.

reviewed by skrll@, thanks.


# 1.25 04-Oct-2018 ryo

* define LX_BLKPAG_{OS,ATTR}_* for OS dependent PTE attributes in pmap.h
* cleanup macros


Revision tags: pgoyette-compat-0930
# 1.24 17-Sep-2018 ryo

delete debug printf and KASSERT.


# 1.23 10-Sep-2018 maxv

Replace KDASSERT by panic.


# 1.22 10-Sep-2018 maxv

Rename _pmap_alloc_pdp -> pmap_alloc_pdp, and make it public.


# 1.21 10-Sep-2018 ryo

cleanup aarch64 mpstart and fdt bootstrap
* arm_cpu_hatch_arg is a bad idea. avoid serializing CPU startup, and eliminate arm_cpu_hatch_arg.
in mpstart, resolve own cpu index using array of cpu_mpidr[] (aarch64)
* add support fdt enable-method "spin-table"
* add support fdt enable-method "brcm,bcm2836-smp" (for 32bit RaspberryPi)
* use arm_fdt_cpu_bootstrap() instead of psci_fdt_bootstrap()
* rename "arm/fdt/psci_fdt.h" to "arm/fdt/psci_fdtvar.h" because of conflict of include file for needs-flag
* add devmap for cpu spin-table of raspberrypi3/aarch64
* no need to force hatch APs for raspberrypi3/arm32 ifndef MULTIPROCESSOR.
* fix to work pmap_extract(kerneltext/data/bss) even if before calling pmap_bootstrap

idea to use cpu_mpidr[] by jmcneill@. reviewd by skrll@. thanks.


Revision tags: pgoyette-compat-0906
# 1.20 27-Aug-2018 ryo

need to add VM_PROT_READ when pmap_kenter_pa(va, pa, VM_PROT_WRITE, 0) or pmap_kenter_pa(va, pa, VM_PROT_EXECUTE, 0).
VM_PROT_READ is treated as an access permission inernally.


# 1.19 11-Aug-2018 ryo

change to minimum invalidation of TLB.
specifying not only va but also asid, and not invalidate L0-L2 entry using tlbi_*_ll() if needed.


# 1.18 10-Aug-2018 ryo

treat kernel-exec attr and user-exec attr separately.
kernel cannot execute userland exec page, and user cannot execute kernel page.


# 1.17 06-Aug-2018 ryo

set kernel text/rodata readonly by default.
add function db_write_text() for setting ddb breakpoint.


# 1.16 31-Jul-2018 skrll

Define and use VPRINTF


Revision tags: pgoyette-compat-0728
# 1.15 27-Jul-2018 ryo

changes of pmap.c r1.13 seems to be unstable.
In order to invalidate icache, not to invalidate all icache,
but temporary to make the page writable and invalidate target address only.


# 1.14 24-Jul-2018 ryo

don't call pool_cache_put with locking pmap. pool_cache_put call pmap_kenter_pa internally.
(pool_cache_put_paddr -> pool_cache_put_slow -> pool_get -> pmap_kenter_pa)


# 1.13 23-Jul-2018 ryo

* fix icache invalidations.
* "ic ivau" (aarch64_icache_sync_range) with VA generates permission fault in some situations, therefore use KSEG address for now.


# 1.12 23-Jul-2018 ryo

rather than using flags to resolve nested locks, reserve pool_cache before locking.


# 1.11 21-Jul-2018 ryo

* avoid deadlock. mutex_owned() works only for adaptive lock, therefore we cannot use it for spinlock...
* add more NULL check
* clear pte when pmap_enter() fails


# 1.10 17-Jul-2018 ryo

Use __debugused


# 1.9 17-Jul-2018 christos

Add missing casts, remove unused variables.


# 1.8 09-Jul-2018 ryo

need locks in pmap_kremove() and pmap_fault_fixup()


Revision tags: phil-wifi-base pgoyette-compat-0625 pgoyette-compat-0521
# 1.7 20-May-2018 ryo

branches: 1.7.2;
pmap_enter() must update modified/referenced flags by 'flags' not 'prot'.


# 1.6 16-May-2018 ryo

Fix memory leak. it was leaking one page every pmap_create().
pm->pm_vmlist must be initialized before calling _pmap_alloc_pdp().


Revision tags: pgoyette-compat-0502
# 1.5 29-Apr-2018 ryo

fix KASSERT panic. pv_entry may not be exists in pvlist when pmap_remove().


# 1.4 29-Apr-2018 ryo

delete unused code


# 1.3 27-Apr-2018 ryo

fix instability behavior of bufcache on aarch64.
* fix to return correct ref/mod when PMAP_WIRED.
* changed to keep wired flags in pte instead of pv_entry, and cleanup.


Revision tags: pgoyette-compat-0422 pgoyette-compat-0415 pgoyette-compat-0407
# 1.2 01-Apr-2018 ryo

Add initial support for ARMv8 (AARCH64) (by nisimura@ and ryo@)

- sys/arch/evbarm64 is gone and integrated into sys/arch/evbarm. (by skrll@)
- add support fdt. evbarm/conf/GENERIC64 fdt (bcm2837,sunxi,tegra) based generic 64bit kernel config. (by skrll@, jmcneill@)


Revision tags: netbsd-8-1-RELEASE netbsd-8-1-RC1 netbsd-7-2-RELEASE netbsd-8-0-RELEASE netbsd-8-0-RC2 netbsd-8-0-RC1 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 netbsd-7-1-2-RELEASE pgoyette-compat-base netbsd-7-1-1-RELEASE tls-maxphys-base-20171202 matt-nb8-mediatek-base nick-nhusb-base-20170825 perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base pgoyette-localcount-20170320 netbsd-7-1-RELEASE netbsd-7-1-RC2 nick-nhusb-base-20170204 netbsd-7-nhusb-base-20170116 bouyer-socketcan-base pgoyette-localcount-20170107 netbsd-7-1-RC1 nick-nhusb-base-20161204 pgoyette-localcount-20161104 netbsd-7-0-2-RELEASE nick-nhusb-base-20161004 localcount-20160914 netbsd-7-nhusb-base pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907 nick-nhusb-base-20160529 netbsd-7-0-1-RELEASE nick-nhusb-base-20160422 nick-nhusb-base-20160319 nick-nhusb-base-20151226 netbsd-7-0-RELEASE nick-nhusb-base-20150921 netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 nick-nhusb-base-20150606 nick-nhusb-base-20150406 nick-nhusb-base tls-maxphys-base netbsd-7-base
# 1.1 10-Aug-2014 matt

branches: 1.1.4; 1.1.28;
Preliminary files for AARCH64 (64-bit ARM) support.
Enough for a distribution build.


# 1.43 15-Aug-2019 skrll

Make pmap_db_pte_print more terse so it's quicker on serial consoles


# 1.42 12-Aug-2019 skrll

Use PMAP_DEV in DEVMAP_ENTRY rather than pmap_map_chunk. It's clearer and
means pmap_map_chunk can be made to map other memory types.


Revision tags: netbsd-9-base phil-wifi-20190609
# 1.41 17-May-2019 mrg

apply some __diagused.


Revision tags: isaki-audio2-base
# 1.40 08-Apr-2019 ryo

- free empty page tables pages if reach a certain usage.
- need to lock at removing an old pg (_pmap_remove_pv) in _pmap_enter()


# 1.39 06-Apr-2019 ryo

Fix race conditions about pmap_page_protect() and pmap_enter().

while handling same PTE by these functions in same time, there
is a critical path that the number of valid PTEs and wire_count
are inconsistent, and it caused KASSERT.
Need to hold a pv_lock while modifying them.


# 1.38 20-Mar-2019 ryo

spinkle __printflike(), and use PRIxxx


# 1.37 19-Mar-2019 ryo

- add ddb command "machine ttbr" to dump MMU tables.
- tidy up descriptions, usages and messages.


# 1.36 19-Mar-2019 ryo

- free L1-L3 pages that has been emptied by pmap_remove().
- if no memories, pmap_enter will return correctly ENOMEM if PMAP_CANFAIL, or wait until available any memories if !PMAP_CANFAIL.

These changes improves the stability when we use a huge virtual memory spaces with mmap.


# 1.35 06-Feb-2019 ryo

improve pmap_remove
- don't lock/unlock per page in pmap_remove()
- speedup pte lookup for continuous addresses
- bring out pool_cache_put(&_pmap_pv_pool, pv) from lock/unlock section


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226
# 1.34 21-Dec-2018 ryo

- add workaround for Cavium ThunderX errata 27456.
- add cpufuncs table in cpu_info. each cpu clusters may have different erratum. (e.g. big.LITTLE)


Revision tags: pgoyette-compat-1126
# 1.33 01-Nov-2018 maxv

Add kASan support for aarch64. Stack tracking needs more investigation
and will come in a separate commit.

Reviewed by ryo@ jmcneill@ skrll@.


# 1.32 31-Oct-2018 ryo

invalidate icache correctly.
l3pte_executable() should be used for only valid pte.


Revision tags: pgoyette-compat-1020
# 1.31 18-Oct-2018 skrll

Provide generic start code that assumes the MMU is off and caches are
disabled as per the linux booting protocol for ARMv6 and ARMv7 boards.
u-boot image type should be changed to 'linux' for correct behaviour.

The new start code builds a minimal "bootstrap" L1PT with cached access
disabled and uses the same table for all processors. AP startup is
performed in less steps and more code is written in C.

The bootstrap tables and stack are placed into an (orphaned) section
"_init_memory" which is given to uvm when it is no longer used.

Various kernels have been converted to use this code and tested. Some
boards were provided by TNF. Thanks!

The GENERIC kernel now boots on boards using the TEGRA, SUNXI and EXYNOS
kernels. The GENERIC kernel will also work on RPI2 using u-boot.

Thanks to martin@ and aymeric@ for testing on parallella and nanosoc
respectively


# 1.30 14-Oct-2018 skrll

Use __nothing


# 1.29 12-Oct-2018 ryo

add initial support of COMPAT_NETBSD32 on AArch64.
arm ELF32 EABI binaries could be execute in AArch32 state on AArch64. A32 THUMB mode is not supported yet.


# 1.28 12-Oct-2018 ryo

- cleanup checking address ranges with IN_RANGE macro
- change PM_ADDR_CHECK macro to KASSERTMSG
- restore fast lookup cases with IN_RANGE macro for pmap_extract changed in my previous commit.


# 1.27 12-Oct-2018 ryo

rewrite pmap_pte_lookup() to share similar code.


# 1.26 04-Oct-2018 ryo

cleanup locore, and changed the way to map memories during boot.
- add functions bootpage_enter() and bootpage_alloc() to adapt various layout
of physical memory map. especially for 64bit physical memory layout.
pmapboot_alloc() allocates pagetable pages from _end[].
- changed to map only the required amount for PA=VA identity mapping
(kernel image, UART device, and FDT blob) with L2_BLOCK(2Mbyte).
- changing page permission for kernel image, and making KSEG mapping are done
at cpu_kernel_vm_init() instead of at locore.
- optimize PTE entries with PTE Contiguous bit. it is enabled on devmap only for now.

reviewed by skrll@, thanks.


# 1.25 04-Oct-2018 ryo

* define LX_BLKPAG_{OS,ATTR}_* for OS dependent PTE attributes in pmap.h
* cleanup macros


Revision tags: pgoyette-compat-0930
# 1.24 17-Sep-2018 ryo

delete debug printf and KASSERT.


# 1.23 10-Sep-2018 maxv

Replace KDASSERT by panic.


# 1.22 10-Sep-2018 maxv

Rename _pmap_alloc_pdp -> pmap_alloc_pdp, and make it public.


# 1.21 10-Sep-2018 ryo

cleanup aarch64 mpstart and fdt bootstrap
* arm_cpu_hatch_arg is a bad idea. avoid serializing CPU startup, and eliminate arm_cpu_hatch_arg.
in mpstart, resolve own cpu index using array of cpu_mpidr[] (aarch64)
* add support fdt enable-method "spin-table"
* add support fdt enable-method "brcm,bcm2836-smp" (for 32bit RaspberryPi)
* use arm_fdt_cpu_bootstrap() instead of psci_fdt_bootstrap()
* rename "arm/fdt/psci_fdt.h" to "arm/fdt/psci_fdtvar.h" because of conflict of include file for needs-flag
* add devmap for cpu spin-table of raspberrypi3/aarch64
* no need to force hatch APs for raspberrypi3/arm32 ifndef MULTIPROCESSOR.
* fix to work pmap_extract(kerneltext/data/bss) even if before calling pmap_bootstrap

idea to use cpu_mpidr[] by jmcneill@. reviewd by skrll@. thanks.


Revision tags: pgoyette-compat-0906
# 1.20 27-Aug-2018 ryo

need to add VM_PROT_READ when pmap_kenter_pa(va, pa, VM_PROT_WRITE, 0) or pmap_kenter_pa(va, pa, VM_PROT_EXECUTE, 0).
VM_PROT_READ is treated as an access permission inernally.


# 1.19 11-Aug-2018 ryo

change to minimum invalidation of TLB.
specifying not only va but also asid, and not invalidate L0-L2 entry using tlbi_*_ll() if needed.


# 1.18 10-Aug-2018 ryo

treat kernel-exec attr and user-exec attr separately.
kernel cannot execute userland exec page, and user cannot execute kernel page.


# 1.17 06-Aug-2018 ryo

set kernel text/rodata readonly by default.
add function db_write_text() for setting ddb breakpoint.


# 1.16 31-Jul-2018 skrll

Define and use VPRINTF


Revision tags: pgoyette-compat-0728
# 1.15 27-Jul-2018 ryo

changes of pmap.c r1.13 seems to be unstable.
In order to invalidate icache, not to invalidate all icache,
but temporary to make the page writable and invalidate target address only.


# 1.14 24-Jul-2018 ryo

don't call pool_cache_put with locking pmap. pool_cache_put call pmap_kenter_pa internally.
(pool_cache_put_paddr -> pool_cache_put_slow -> pool_get -> pmap_kenter_pa)


# 1.13 23-Jul-2018 ryo

* fix icache invalidations.
* "ic ivau" (aarch64_icache_sync_range) with VA generates permission fault in some situations, therefore use KSEG address for now.


# 1.12 23-Jul-2018 ryo

rather than using flags to resolve nested locks, reserve pool_cache before locking.


# 1.11 21-Jul-2018 ryo

* avoid deadlock. mutex_owned() works only for adaptive lock, therefore we cannot use it for spinlock...
* add more NULL check
* clear pte when pmap_enter() fails


# 1.10 17-Jul-2018 ryo

Use __debugused


# 1.9 17-Jul-2018 christos

Add missing casts, remove unused variables.


# 1.8 09-Jul-2018 ryo

need locks in pmap_kremove() and pmap_fault_fixup()


Revision tags: phil-wifi-base pgoyette-compat-0625 pgoyette-compat-0521
# 1.7 20-May-2018 ryo

branches: 1.7.2;
pmap_enter() must update modified/referenced flags by 'flags' not 'prot'.


# 1.6 16-May-2018 ryo

Fix memory leak. it was leaking one page every pmap_create().
pm->pm_vmlist must be initialized before calling _pmap_alloc_pdp().


Revision tags: pgoyette-compat-0502
# 1.5 29-Apr-2018 ryo

fix KASSERT panic. pv_entry may not be exists in pvlist when pmap_remove().


# 1.4 29-Apr-2018 ryo

delete unused code


# 1.3 27-Apr-2018 ryo

fix instability behavior of bufcache on aarch64.
* fix to return correct ref/mod when PMAP_WIRED.
* changed to keep wired flags in pte instead of pv_entry, and cleanup.


Revision tags: pgoyette-compat-0422 pgoyette-compat-0415 pgoyette-compat-0407
# 1.2 01-Apr-2018 ryo

Add initial support for ARMv8 (AARCH64) (by nisimura@ and ryo@)

- sys/arch/evbarm64 is gone and integrated into sys/arch/evbarm. (by skrll@)
- add support fdt. evbarm/conf/GENERIC64 fdt (bcm2837,sunxi,tegra) based generic 64bit kernel config. (by skrll@, jmcneill@)


Revision tags: netbsd-8-1-RELEASE netbsd-8-1-RC1 netbsd-7-2-RELEASE netbsd-8-0-RELEASE netbsd-8-0-RC2 netbsd-8-0-RC1 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 netbsd-7-1-2-RELEASE pgoyette-compat-base netbsd-7-1-1-RELEASE tls-maxphys-base-20171202 matt-nb8-mediatek-base nick-nhusb-base-20170825 perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base pgoyette-localcount-20170320 netbsd-7-1-RELEASE netbsd-7-1-RC2 nick-nhusb-base-20170204 netbsd-7-nhusb-base-20170116 bouyer-socketcan-base pgoyette-localcount-20170107 netbsd-7-1-RC1 nick-nhusb-base-20161204 pgoyette-localcount-20161104 netbsd-7-0-2-RELEASE nick-nhusb-base-20161004 localcount-20160914 netbsd-7-nhusb-base pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907 nick-nhusb-base-20160529 netbsd-7-0-1-RELEASE nick-nhusb-base-20160422 nick-nhusb-base-20160319 nick-nhusb-base-20151226 netbsd-7-0-RELEASE nick-nhusb-base-20150921 netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 nick-nhusb-base-20150606 nick-nhusb-base-20150406 nick-nhusb-base tls-maxphys-base netbsd-7-base
# 1.1 10-Aug-2014 matt

branches: 1.1.4; 1.1.28;
Preliminary files for AARCH64 (64-bit ARM) support.
Enough for a distribution build.


# 1.41 17-May-2019 mrg

apply some __diagused.


Revision tags: isaki-audio2-base
# 1.40 08-Apr-2019 ryo

- free empty page tables pages if reach a certain usage.
- need to lock at removing an old pg (_pmap_remove_pv) in _pmap_enter()


# 1.39 06-Apr-2019 ryo

Fix race conditions about pmap_page_protect() and pmap_enter().

while handling same PTE by these functions in same time, there
is a critical path that the number of valid PTEs and wire_count
are inconsistent, and it caused KASSERT.
Need to hold a pv_lock while modifying them.


# 1.38 20-Mar-2019 ryo

spinkle __printflike(), and use PRIxxx


# 1.37 19-Mar-2019 ryo

- add ddb command "machine ttbr" to dump MMU tables.
- tidy up descriptions, usages and messages.


# 1.36 19-Mar-2019 ryo

- free L1-L3 pages that has been emptied by pmap_remove().
- if no memories, pmap_enter will return correctly ENOMEM if PMAP_CANFAIL, or wait until available any memories if !PMAP_CANFAIL.

These changes improves the stability when we use a huge virtual memory spaces with mmap.


# 1.35 06-Feb-2019 ryo

improve pmap_remove
- don't lock/unlock per page in pmap_remove()
- speedup pte lookup for continuous addresses
- bring out pool_cache_put(&_pmap_pv_pool, pv) from lock/unlock section


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226
# 1.34 21-Dec-2018 ryo

- add workaround for Cavium ThunderX errata 27456.
- add cpufuncs table in cpu_info. each cpu clusters may have different erratum. (e.g. big.LITTLE)


Revision tags: pgoyette-compat-1126
# 1.33 01-Nov-2018 maxv

Add kASan support for aarch64. Stack tracking needs more investigation
and will come in a separate commit.

Reviewed by ryo@ jmcneill@ skrll@.


# 1.32 31-Oct-2018 ryo

invalidate icache correctly.
l3pte_executable() should be used for only valid pte.


Revision tags: pgoyette-compat-1020
# 1.31 18-Oct-2018 skrll

Provide generic start code that assumes the MMU is off and caches are
disabled as per the linux booting protocol for ARMv6 and ARMv7 boards.
u-boot image type should be changed to 'linux' for correct behaviour.

The new start code builds a minimal "bootstrap" L1PT with cached access
disabled and uses the same table for all processors. AP startup is
performed in less steps and more code is written in C.

The bootstrap tables and stack are placed into an (orphaned) section
"_init_memory" which is given to uvm when it is no longer used.

Various kernels have been converted to use this code and tested. Some
boards were provided by TNF. Thanks!

The GENERIC kernel now boots on boards using the TEGRA, SUNXI and EXYNOS
kernels. The GENERIC kernel will also work on RPI2 using u-boot.

Thanks to martin@ and aymeric@ for testing on parallella and nanosoc
respectively


# 1.30 14-Oct-2018 skrll

Use __nothing


# 1.29 12-Oct-2018 ryo

add initial support of COMPAT_NETBSD32 on AArch64.
arm ELF32 EABI binaries could be execute in AArch32 state on AArch64. A32 THUMB mode is not supported yet.


# 1.28 12-Oct-2018 ryo

- cleanup checking address ranges with IN_RANGE macro
- change PM_ADDR_CHECK macro to KASSERTMSG
- restore fast lookup cases with IN_RANGE macro for pmap_extract changed in my previous commit.


# 1.27 12-Oct-2018 ryo

rewrite pmap_pte_lookup() to share similar code.


# 1.26 04-Oct-2018 ryo

cleanup locore, and changed the way to map memories during boot.
- add functions bootpage_enter() and bootpage_alloc() to adapt various layout
of physical memory map. especially for 64bit physical memory layout.
pmapboot_alloc() allocates pagetable pages from _end[].
- changed to map only the required amount for PA=VA identity mapping
(kernel image, UART device, and FDT blob) with L2_BLOCK(2Mbyte).
- changing page permission for kernel image, and making KSEG mapping are done
at cpu_kernel_vm_init() instead of at locore.
- optimize PTE entries with PTE Contiguous bit. it is enabled on devmap only for now.

reviewed by skrll@, thanks.


# 1.25 04-Oct-2018 ryo

* define LX_BLKPAG_{OS,ATTR}_* for OS dependent PTE attributes in pmap.h
* cleanup macros


Revision tags: pgoyette-compat-0930
# 1.24 17-Sep-2018 ryo

delete debug printf and KASSERT.


# 1.23 10-Sep-2018 maxv

Replace KDASSERT by panic.


# 1.22 10-Sep-2018 maxv

Rename _pmap_alloc_pdp -> pmap_alloc_pdp, and make it public.


# 1.21 10-Sep-2018 ryo

cleanup aarch64 mpstart and fdt bootstrap
* arm_cpu_hatch_arg is a bad idea. avoid serializing CPU startup, and eliminate arm_cpu_hatch_arg.
in mpstart, resolve own cpu index using array of cpu_mpidr[] (aarch64)
* add support fdt enable-method "spin-table"
* add support fdt enable-method "brcm,bcm2836-smp" (for 32bit RaspberryPi)
* use arm_fdt_cpu_bootstrap() instead of psci_fdt_bootstrap()
* rename "arm/fdt/psci_fdt.h" to "arm/fdt/psci_fdtvar.h" because of conflict of include file for needs-flag
* add devmap for cpu spin-table of raspberrypi3/aarch64
* no need to force hatch APs for raspberrypi3/arm32 ifndef MULTIPROCESSOR.
* fix to work pmap_extract(kerneltext/data/bss) even if before calling pmap_bootstrap

idea to use cpu_mpidr[] by jmcneill@. reviewd by skrll@. thanks.


Revision tags: pgoyette-compat-0906
# 1.20 27-Aug-2018 ryo

need to add VM_PROT_READ when pmap_kenter_pa(va, pa, VM_PROT_WRITE, 0) or pmap_kenter_pa(va, pa, VM_PROT_EXECUTE, 0).
VM_PROT_READ is treated as an access permission inernally.


# 1.19 11-Aug-2018 ryo

change to minimum invalidation of TLB.
specifying not only va but also asid, and not invalidate L0-L2 entry using tlbi_*_ll() if needed.


# 1.18 10-Aug-2018 ryo

treat kernel-exec attr and user-exec attr separately.
kernel cannot execute userland exec page, and user cannot execute kernel page.


# 1.17 06-Aug-2018 ryo

set kernel text/rodata readonly by default.
add function db_write_text() for setting ddb breakpoint.


# 1.16 31-Jul-2018 skrll

Define and use VPRINTF


Revision tags: pgoyette-compat-0728
# 1.15 27-Jul-2018 ryo

changes of pmap.c r1.13 seems to be unstable.
In order to invalidate icache, not to invalidate all icache,
but temporary to make the page writable and invalidate target address only.


# 1.14 24-Jul-2018 ryo

don't call pool_cache_put with locking pmap. pool_cache_put call pmap_kenter_pa internally.
(pool_cache_put_paddr -> pool_cache_put_slow -> pool_get -> pmap_kenter_pa)


# 1.13 23-Jul-2018 ryo

* fix icache invalidations.
* "ic ivau" (aarch64_icache_sync_range) with VA generates permission fault in some situations, therefore use KSEG address for now.


# 1.12 23-Jul-2018 ryo

rather than using flags to resolve nested locks, reserve pool_cache before locking.


# 1.11 21-Jul-2018 ryo

* avoid deadlock. mutex_owned() works only for adaptive lock, therefore we cannot use it for spinlock...
* add more NULL check
* clear pte when pmap_enter() fails


# 1.10 17-Jul-2018 ryo

Use __debugused


# 1.9 17-Jul-2018 christos

Add missing casts, remove unused variables.


# 1.8 09-Jul-2018 ryo

need locks in pmap_kremove() and pmap_fault_fixup()


Revision tags: phil-wifi-base pgoyette-compat-0625 pgoyette-compat-0521
# 1.7 20-May-2018 ryo

pmap_enter() must update modified/referenced flags by 'flags' not 'prot'.


# 1.6 16-May-2018 ryo

Fix memory leak. it was leaking one page every pmap_create().
pm->pm_vmlist must be initialized before calling _pmap_alloc_pdp().


Revision tags: pgoyette-compat-0502
# 1.5 29-Apr-2018 ryo

fix KASSERT panic. pv_entry may not be exists in pvlist when pmap_remove().


# 1.4 29-Apr-2018 ryo

delete unused code


# 1.3 27-Apr-2018 ryo

fix instability behavior of bufcache on aarch64.
* fix to return correct ref/mod when PMAP_WIRED.
* changed to keep wired flags in pte instead of pv_entry, and cleanup.


Revision tags: pgoyette-compat-0422 pgoyette-compat-0415 pgoyette-compat-0407
# 1.2 01-Apr-2018 ryo

Add initial support for ARMv8 (AARCH64) (by nisimura@ and ryo@)

- sys/arch/evbarm64 is gone and integrated into sys/arch/evbarm. (by skrll@)
- add support fdt. evbarm/conf/GENERIC64 fdt (bcm2837,sunxi,tegra) based generic 64bit kernel config. (by skrll@, jmcneill@)


Revision tags: netbsd-8-1-RC1 netbsd-7-2-RELEASE netbsd-8-0-RELEASE netbsd-8-0-RC2 netbsd-8-0-RC1 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 netbsd-7-1-2-RELEASE pgoyette-compat-base netbsd-7-1-1-RELEASE tls-maxphys-base-20171202 matt-nb8-mediatek-base nick-nhusb-base-20170825 perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base pgoyette-localcount-20170320 netbsd-7-1-RELEASE netbsd-7-1-RC2 nick-nhusb-base-20170204 netbsd-7-nhusb-base-20170116 bouyer-socketcan-base pgoyette-localcount-20170107 netbsd-7-1-RC1 nick-nhusb-base-20161204 pgoyette-localcount-20161104 netbsd-7-0-2-RELEASE nick-nhusb-base-20161004 localcount-20160914 netbsd-7-nhusb-base pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907 nick-nhusb-base-20160529 netbsd-7-0-1-RELEASE nick-nhusb-base-20160422 nick-nhusb-base-20160319 nick-nhusb-base-20151226 netbsd-7-0-RELEASE nick-nhusb-base-20150921 netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 nick-nhusb-base-20150606 nick-nhusb-base-20150406 nick-nhusb-base tls-maxphys-base netbsd-7-base
# 1.1 10-Aug-2014 matt

branches: 1.1.4; 1.1.28;
Preliminary files for AARCH64 (64-bit ARM) support.
Enough for a distribution build.


Revision tags: isaki-audio2-base
# 1.40 08-Apr-2019 ryo

- free empty page tables pages if reach a certain usage.
- need to lock at removing an old pg (_pmap_remove_pv) in _pmap_enter()


# 1.39 06-Apr-2019 ryo

Fix race conditions about pmap_page_protect() and pmap_enter().

while handling same PTE by these functions in same time, there
is a critical path that the number of valid PTEs and wire_count
are inconsistent, and it caused KASSERT.
Need to hold a pv_lock while modifying them.


# 1.38 20-Mar-2019 ryo

spinkle __printflike(), and use PRIxxx


# 1.37 19-Mar-2019 ryo

- add ddb command "machine ttbr" to dump MMU tables.
- tidy up descriptions, usages and messages.


# 1.36 19-Mar-2019 ryo

- free L1-L3 pages that has been emptied by pmap_remove().
- if no memories, pmap_enter will return correctly ENOMEM if PMAP_CANFAIL, or wait until available any memories if !PMAP_CANFAIL.

These changes improves the stability when we use a huge virtual memory spaces with mmap.


# 1.35 06-Feb-2019 ryo

improve pmap_remove
- don't lock/unlock per page in pmap_remove()
- speedup pte lookup for continuous addresses
- bring out pool_cache_put(&_pmap_pv_pool, pv) from lock/unlock section


Revision tags: pgoyette-compat-20190127 pgoyette-compat-20190118 pgoyette-compat-1226
# 1.34 21-Dec-2018 ryo

- add workaround for Cavium ThunderX errata 27456.
- add cpufuncs table in cpu_info. each cpu clusters may have different erratum. (e.g. big.LITTLE)


Revision tags: pgoyette-compat-1126
# 1.33 01-Nov-2018 maxv

Add kASan support for aarch64. Stack tracking needs more investigation
and will come in a separate commit.

Reviewed by ryo@ jmcneill@ skrll@.


# 1.32 31-Oct-2018 ryo

invalidate icache correctly.
l3pte_executable() should be used for only valid pte.


Revision tags: pgoyette-compat-1020
# 1.31 18-Oct-2018 skrll

Provide generic start code that assumes the MMU is off and caches are
disabled as per the linux booting protocol for ARMv6 and ARMv7 boards.
u-boot image type should be changed to 'linux' for correct behaviour.

The new start code builds a minimal "bootstrap" L1PT with cached access
disabled and uses the same table for all processors. AP startup is
performed in less steps and more code is written in C.

The bootstrap tables and stack are placed into an (orphaned) section
"_init_memory" which is given to uvm when it is no longer used.

Various kernels have been converted to use this code and tested. Some
boards were provided by TNF. Thanks!

The GENERIC kernel now boots on boards using the TEGRA, SUNXI and EXYNOS
kernels. The GENERIC kernel will also work on RPI2 using u-boot.

Thanks to martin@ and aymeric@ for testing on parallella and nanosoc
respectively


# 1.30 14-Oct-2018 skrll

Use __nothing


# 1.29 12-Oct-2018 ryo

add initial support of COMPAT_NETBSD32 on AArch64.
arm ELF32 EABI binaries could be execute in AArch32 state on AArch64. A32 THUMB mode is not supported yet.


# 1.28 12-Oct-2018 ryo

- cleanup checking address ranges with IN_RANGE macro
- change PM_ADDR_CHECK macro to KASSERTMSG
- restore fast lookup cases with IN_RANGE macro for pmap_extract changed in my previous commit.


# 1.27 12-Oct-2018 ryo

rewrite pmap_pte_lookup() to share similar code.


# 1.26 04-Oct-2018 ryo

cleanup locore, and changed the way to map memories during boot.
- add functions bootpage_enter() and bootpage_alloc() to adapt various layout
of physical memory map. especially for 64bit physical memory layout.
pmapboot_alloc() allocates pagetable pages from _end[].
- changed to map only the required amount for PA=VA identity mapping
(kernel image, UART device, and FDT blob) with L2_BLOCK(2Mbyte).
- changing page permission for kernel image, and making KSEG mapping are done
at cpu_kernel_vm_init() instead of at locore.
- optimize PTE entries with PTE Contiguous bit. it is enabled on devmap only for now.

reviewed by skrll@, thanks.


# 1.25 04-Oct-2018 ryo

* define LX_BLKPAG_{OS,ATTR}_* for OS dependent PTE attributes in pmap.h
* cleanup macros


Revision tags: pgoyette-compat-0930
# 1.24 17-Sep-2018 ryo

delete debug printf and KASSERT.


# 1.23 10-Sep-2018 maxv

Replace KDASSERT by panic.


# 1.22 10-Sep-2018 maxv

Rename _pmap_alloc_pdp -> pmap_alloc_pdp, and make it public.


# 1.21 10-Sep-2018 ryo

cleanup aarch64 mpstart and fdt bootstrap
* arm_cpu_hatch_arg is a bad idea. avoid serializing CPU startup, and eliminate arm_cpu_hatch_arg.
in mpstart, resolve own cpu index using array of cpu_mpidr[] (aarch64)
* add support fdt enable-method "spin-table"
* add support fdt enable-method "brcm,bcm2836-smp" (for 32bit RaspberryPi)
* use arm_fdt_cpu_bootstrap() instead of psci_fdt_bootstrap()
* rename "arm/fdt/psci_fdt.h" to "arm/fdt/psci_fdtvar.h" because of conflict of include file for needs-flag
* add devmap for cpu spin-table of raspberrypi3/aarch64
* no need to force hatch APs for raspberrypi3/arm32 ifndef MULTIPROCESSOR.
* fix to work pmap_extract(kerneltext/data/bss) even if before calling pmap_bootstrap

idea to use cpu_mpidr[] by jmcneill@. reviewd by skrll@. thanks.


Revision tags: pgoyette-compat-0906
# 1.20 27-Aug-2018 ryo

need to add VM_PROT_READ when pmap_kenter_pa(va, pa, VM_PROT_WRITE, 0) or pmap_kenter_pa(va, pa, VM_PROT_EXECUTE, 0).
VM_PROT_READ is treated as an access permission inernally.


# 1.19 11-Aug-2018 ryo

change to minimum invalidation of TLB.
specifying not only va but also asid, and not invalidate L0-L2 entry using tlbi_*_ll() if needed.


# 1.18 10-Aug-2018 ryo

treat kernel-exec attr and user-exec attr separately.
kernel cannot execute userland exec page, and user cannot execute kernel page.


# 1.17 06-Aug-2018 ryo

set kernel text/rodata readonly by default.
add function db_write_text() for setting ddb breakpoint.


# 1.16 31-Jul-2018 skrll

Define and use VPRINTF


Revision tags: pgoyette-compat-0728
# 1.15 27-Jul-2018 ryo

changes of pmap.c r1.13 seems to be unstable.
In order to invalidate icache, not to invalidate all icache,
but temporary to make the page writable and invalidate target address only.


# 1.14 24-Jul-2018 ryo

don't call pool_cache_put with locking pmap. pool_cache_put call pmap_kenter_pa internally.
(pool_cache_put_paddr -> pool_cache_put_slow -> pool_get -> pmap_kenter_pa)


# 1.13 23-Jul-2018 ryo

* fix icache invalidations.
* "ic ivau" (aarch64_icache_sync_range) with VA generates permission fault in some situations, therefore use KSEG address for now.


# 1.12 23-Jul-2018 ryo

rather than using flags to resolve nested locks, reserve pool_cache before locking.


# 1.11 21-Jul-2018 ryo

* avoid deadlock. mutex_owned() works only for adaptive lock, therefore we cannot use it for spinlock...
* add more NULL check
* clear pte when pmap_enter() fails


# 1.10 17-Jul-2018 ryo

Use __debugused


# 1.9 17-Jul-2018 christos

Add missing casts, remove unused variables.


# 1.8 09-Jul-2018 ryo

need locks in pmap_kremove() and pmap_fault_fixup()


Revision tags: phil-wifi-base pgoyette-compat-0625 pgoyette-compat-0521
# 1.7 20-May-2018 ryo

pmap_enter() must update modified/referenced flags by 'flags' not 'prot'.


# 1.6 16-May-2018 ryo

Fix memory leak. it was leaking one page every pmap_create().
pm->pm_vmlist must be initialized before calling _pmap_alloc_pdp().


Revision tags: pgoyette-compat-0502
# 1.5 29-Apr-2018 ryo

fix KASSERT panic. pv_entry may not be exists in pvlist when pmap_remove().


# 1.4 29-Apr-2018 ryo

delete unused code


# 1.3 27-Apr-2018 ryo

fix instability behavior of bufcache on aarch64.
* fix to return correct ref/mod when PMAP_WIRED.
* changed to keep wired flags in pte instead of pv_entry, and cleanup.


Revision tags: pgoyette-compat-0422 pgoyette-compat-0415 pgoyette-compat-0407
# 1.2 01-Apr-2018 ryo

Add initial support for ARMv8 (AARCH64) (by nisimura@ and ryo@)

- sys/arch/evbarm64 is gone and integrated into sys/arch/evbarm. (by skrll@)
- add support fdt. evbarm/conf/GENERIC64 fdt (bcm2837,sunxi,tegra) based generic 64bit kernel config. (by skrll@, jmcneill@)


Revision tags: netbsd-7-2-RELEASE netbsd-8-0-RELEASE netbsd-8-0-RC2 netbsd-8-0-RC1 pgoyette-compat-0330 pgoyette-compat-0322 pgoyette-compat-0315 netbsd-7-1-2-RELEASE pgoyette-compat-base netbsd-7-1-1-RELEASE tls-maxphys-base-20171202 matt-nb8-mediatek-base nick-nhusb-base-20170825 perseant-stdc-iso10646-base netbsd-8-base prg-localcount2-base3 prg-localcount2-base2 prg-localcount2-base1 prg-localcount2-base pgoyette-localcount-20170426 bouyer-socketcan-base1 jdolecek-ncq-base pgoyette-localcount-20170320 netbsd-7-1-RELEASE netbsd-7-1-RC2 nick-nhusb-base-20170204 netbsd-7-nhusb-base-20170116 bouyer-socketcan-base pgoyette-localcount-20170107 netbsd-7-1-RC1 nick-nhusb-base-20161204 pgoyette-localcount-20161104 netbsd-7-0-2-RELEASE nick-nhusb-base-20161004 localcount-20160914 netbsd-7-nhusb-base pgoyette-localcount-20160806 pgoyette-localcount-20160726 pgoyette-localcount-base nick-nhusb-base-20160907 nick-nhusb-base-20160529 netbsd-7-0-1-RELEASE nick-nhusb-base-20160422 nick-nhusb-base-20160319 nick-nhusb-base-20151226 netbsd-7-0-RELEASE nick-nhusb-base-20150921 netbsd-7-0-RC3 netbsd-7-0-RC2 netbsd-7-0-RC1 nick-nhusb-base-20150606 nick-nhusb-base-20150406 nick-nhusb-base tls-maxphys-base netbsd-7-base
# 1.1 10-Aug-2014 matt

branches: 1.1.4; 1.1.28;
Preliminary files for AARCH64 (64-bit ARM) support.
Enough for a distribution build.