Commit Graph

3659 Commits

Author SHA1 Message Date
Brandon Bergren
95090cd024 [PowerPC64] Hide dssall instruction from llvm assembler
When doing a build for a modern CPUTYPE, llvm will throw errors if obsolete
instructions are used, even if they will never run due to runtime checks.

Hiding the dssall instruction from the assembler fixes kernel build when
overriding CPUTYPE, without having any effect on the generated binary.

This has been in my local tree for over a year and is well tested across
a variety of machines.

Sponsored by:	Tag1 Consulting, Inc.
2020-09-08 22:59:43 +00:00
Brandon Bergren
d20ae9cca2 [PowerPC] Add root_pic assertion.
When enabling an interrupt, assert that we do in fact have a root PIC.

This would have saved me some debugging effort.

Sponsored by:	Tag1 Consulting, Inc.
2020-09-08 22:42:41 +00:00
Brandon Bergren
328b5f2570 [PowerPC] Implement VDSO timebase access on powerpc*
Implement the remaining pieces needed to allow userland timestamp reading.

Rewritten based on an intial essay into the problem by Justin Hibbits.
(Copyright changed to my own on his request.)

Tested on ppc64 (POWER9 Talos II), powerpcspe (e500v2 RB800), and
powerpc (g4 PowerBook).

Reviewed by:	jhibbits (in irc)
Sponsored by:	Tag1 Consulting, Inc.
Differential Revision:	https://reviews.freebsd.org/D26347
2020-09-08 03:00:31 +00:00
Brandon Bergren
3d4217bc0f [PowerPC] Initialize ELFv1 as a secondary sysvec to ELFv2.
In order to enable VDSO timekeeping, it is necessary that there be exactly
one primary FreeBSD sysvec for each of the host and (optionally) compat32.

So, switch ELFv1 to being a secondary sysvec of ELFv2, so it does not get
double-allocated in the shared page.

Since secondary sysvecs use the same sigcode allocation as the primary,
define both to use the main sigcode64, and adjust the sv_sigcode_base on
ELFv2 after initialization to point to the correct offset.

This has the desirable side effect of avoiding having a separate copy of
the signal trampoline in the shared page. Our sigcode64 was already written
to take advantage of trampoline sharing, it was just not being allocated
that way until now.

Submitted by:	jhibbits
Sponsored by:	Tag1 Consulting, Inc.
2020-09-07 20:25:54 +00:00
Mark Johnston
847ab36bf2 Include the psind in data returned by mincore(2).
Currently we use a single bit to indicate whether the virtual page is
part of a superpage.  To support a forthcoming implementation of
non-transparent 1GB superpages, it is useful to provide more detailed
information about large page sizes.

The change converts MINCORE_SUPER into a mask for MINCORE_PSIND(psind)
values, indicating a mapping of size psind, where psind is an index into
the pagesizes array returned by getpagesizes(3), which in turn comes
from the hw.pagesizes sysctl.  MINCORE_PSIND(1) is equal to the old
value of MINCORE_SUPER.

For now, two bits are used to record the page size, permitting values
of MAXPAGESIZES up to 4.

Reviewed by:	alc, kib
Sponsored by:	Juniper Networks, Inc.
Sponsored by:	Klara, Inc.
Differential Revision:	https://reviews.freebsd.org/D26238
2020-09-02 18:16:43 +00:00
Mark Johnston
2d838cd867 Add the MEM_EXTRACT_PADDR ioctl to /dev/mem.
This allows privileged userspace processes to find information about the
physical page backing a given mapping.  It is useful in applications
such as DPDK which perform some of their own memory management.

Reviewed by:	kib, jhb (previous version)
MFC after:	2 weeks
Sponsored by:	Juniper Networks, Inc.
Sponsored by:	Klara Inc.
Differential Revision:	https://reviews.freebsd.org/D26237
2020-09-02 18:12:47 +00:00
Mateusz Guzik
b64b31338f powerpc: clean up empty lines in .c and .h files 2020-09-01 21:20:08 +00:00
Leandro Lupori
51488825f1 [PowerPC] Fix PMCLOG address width
PMCLOG macros were always using 32-bit addresses, even on PPC64.
This resulted in truncated addresses in logs, when running on 64-bit PPC
machines.

Sponsored by:	Eldorado Research Institute (eldorado.org.br)
Differential Revision:	https://reviews.freebsd.org/D26112
2020-09-01 11:34:05 +00:00
Leandro Lupori
9b23e3845b [PowerPC] Move pmc_hook out of critical section
Calling pmc_hook inside a critical section may result in a panic.

This happens when the user callchain is fetched, because it uses
pmap_map_user_ptr, that tries to get the (sleepable) pmap lock when the
needed vsid is not found.

Judging by the implementation in other platforms, intr_irq_handler in
kern/subr_intr.c and what pmc_hook do, it seems safe to move pmc_hook
outside the critical section.

Sponsored by:	Eldorado Research Institute (eldorado.org.br)
Differential Revision:	https://reviews.freebsd.org/D26111
2020-09-01 11:30:39 +00:00
Brandon Bergren
3ae3a7a7c0 [PowerPC] Remove unused openpic_set_priority().
When SMP support for powerpc was added in r178628, the last callers of this
function were removed. All code that needs to manipulate the task priority
just does it directly instead.

Noticed while reading through the lint logs.

Sponsored by:	Tag1 Consulting, Inc.
2020-09-01 01:57:56 +00:00
Leandro Lupori
fb27a570ad [PowerPC] Make new auxv format default
Assume ELF images without OSREL use the new auxv format.

This is specially important for rtld, that is not tagged. Using
direct exec mode with new (ELFv2) binaries that expect the new auxv
format would result in crashes otherwise.

Unfortunately, this may break direct exec'ing old binaries,
but it seems better to correctly support new binaries by default,
considering the transition to ELFv2 happened quite some time
ago. If needed, a sysctl may be added to allow old auxv format to
be used when OSREL is not found.

Reviewed by:	bdragon
Sponsored by:	Eldorado Research Institute (eldorado.org.br)
Differential Revision:	https://reviews.freebsd.org/D25651
2020-08-24 13:40:35 +00:00
Konstantin Belousov
0cad2aa2dd Pass pointers to info parsed from notes, to brandinfo->header_supported filter.
Currently, we parse notes for the values of ELF FreeBSD feature flags
and osrel.  Knowing these values, or knowing that image does not carry
the note if pointers are NULL, is useful to decide which ABI variant
(brand) we want to activate for the image.

Right now this is only a plumbing change

Tested by:	pho
Sponsored by:	The FreeBSD Foundation
Differential revision:	https://reviews.freebsd.org/D25273
2020-08-23 20:06:55 +00:00
Brandon Bergren
f10baa4049 [PowerPC] Fix translation-related crashes during startup
After spending a lot of time trying to track down what was going on, I have
isolated the "black screen" failures when using boot1 to boot a G4 machine.

It turns out we were replacing the traps before installing the temporary
BAT entry for the bottom of physical memory. That meant that until the MMU
was bootstrapped, the cached translations were the only thing keeping us
from losing.

Throwing boot1 into the mix was affecting execution flow enough to cause us
to hit an uncached page and crash.

Fix this by properly setting up the initial BAT entry at the same time we
are replacing the OpenFirmware traps, so we can continue executing in
segment 0 until the rest of the DMAP has been set up.

A second thing discovered while researching this is that we were entering a
BAT region for segment 16. It turns out this range was a) considered part
of KVA, and b) has firmware mappings with varying attributes.

If we ever accessed an unmapped page in segment 16, it would cause a BAT
entry to be installed for the whole segment, which would bypass the
existing mappings until it was flushed out again.

Instead, translate the OFW memory attributes into VM memory attributes and
install the ranges into the kernel address space properly.

Reviewed by:	adalava
MFC after:	3 weeks
Sponsored by:	Tag1 Consulting, Inc.
Differential Revision:	https://reviews.freebsd.org/D25547
2020-08-21 03:31:01 +00:00
Brandon Bergren
b94b2fcd61 [PowerPC64] Fix invalid OPAL call in xive_bind().
This fixes spurious "XIVE[ IC 00  ] ISN 1 lead to invalid IVE !" messages
generated by OPAL when running with the debug level cranked up.

Discussed with jhibbits.

Sponsored by:	Tag1 Consulting, Inc.
2020-08-21 03:23:10 +00:00
Dimitry Andric
21673cf0bd Fix clang 11 inline asm constraint error when building powerpc GENERIC64
kernels:

sys/powerpc/aim/mmu_radix.c:728:19: error: invalid operand for inline asm constraint 'i'
        __asm __volatile(PPC_TLBIEL(%0, %1, %2, %3, 1)
                         ^
sys/powerpc/aim/mmu_radix.c:149:3: note: expanded from macro 'PPC_TLBIEL'
         __XSTRING(.long PPC_INST_TLBIEL | \
         ^
sys/sys/cdefs.h:161:22: note: expanded from macro '__XSTRING'
#define __XSTRING(x)    __STRING(x)     /* expand x, then stringify */
                        ^
sys/sys/cdefs.h:160:21: note: expanded from macro '__STRING'
#define __STRING(x)     #x              /* stringify without expanding x */
                        ^
<scratch space>:112:1: note: expanded from here
".long 0x7c000224 | (((%0) & 0x1f) << 11) | (((%1) & 0x1f) << 21) | (((%2) & 0x3) << 18) | (((%3) & 0x1) << 17) | (((1) & 0x1) << 16)"
^

This is solved by making the affected inline functions __always_inline.

Suggested by:	jhibbits
MFC after:	3 days
2020-08-07 19:32:54 +00:00
John Baldwin
7d351d60fa Set si_addr to dar for MMU and alignment faults.
Reviewed by:	kib
Sponsored by:	DARPA
Differential Revision:	https://reviews.freebsd.org/D25776
2020-07-27 16:34:31 +00:00
Alex Richardson
b798ef6490 Include TMPFS in all the GENERIC kernel configs
Being able to use tmpfs without kernel modules is very useful when building
small MFS_ROOT kernels without a real file system.
Including TMPFS also matches arm/GENERIC and the MIPS std.MALTA configs.

Compiling TMPFS only adds 4 .c files so this should not make much of a
difference to NO_MODULES build times (as we do for our minimal RISC-V
images).

Reviewed By: br (earlier version for riscv), brooks, emaste
Differential Revision: https://reviews.freebsd.org/D25317
2020-07-24 08:40:04 +00:00
Conrad Meyer
4ae224c663 Revert r240317 to prevent leaking pmap entries
Subsequent to r240317, kmem_free() was replaced with kva_free() (r254025).
kva_free() releases the KVA allocation for the mapped region, but no longer
clears the pmap (pagetable) entries.

An affected pmap_unmapdev operation would leave the still-pmap'd VA space
free for allocation by other KVA consumers.  However, this bug easily
avoided notice for ~7 years because most devices (1) never call
pmap_unmapdev and (2) on amd64, mostly fit within the DMAP and do not need
KVA allocations.  Other affected arch are less popular: i386, MIPS, and
PowerPC.  Arm64, arm32, and riscv are not affected.

Reported by:	Don Morris <dgmorris AT earthlink.net>
Submitted by:	Don Morris (amd64 part)
Reviewed by:	kib, markj, Don (!amd64 parts)
MFC after:	I don't intend to, but you might want to
Sponsored by:	Dell Isilon
Differential Revision:	https://reviews.freebsd.org/D25689
2020-07-16 23:29:26 +00:00
Mark Johnston
e64080e79c Switch from SCTP to SCTP_SUPPORT in GENERIC configs.
This removes SCTP from in-tree kernel configuration files.  Now, SCTP
can be enabled by simply loading the module, as discussed on
freebsd-net@.

Reviewed by:	tuexen
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D25611
2020-07-16 15:09:04 +00:00
Leandro Lupori
4c0c2fb1ad [PowerPC] Use PVO_PADDR to get the PA from PVO
Use PVO_PADDR macro to get the physical address from a PVO, instead of
explicitly ANDing pvo_pte.pa with LPTE_RPGN where it is needed.  Besides
improving readability, this is needed to support superpages (D25237), where
the steps to get the PA from a PVO are different.

Reviewed by:	markj
Sponsored by:	Eldorado Research Institute (eldorado.org.br)
Differential Revision:	https://reviews.freebsd.org/D25654
2020-07-15 13:43:48 +00:00
Scott Long
ffc568ba8b Revert r362998, r326999 while a better compatibility strategy is devised. 2020-07-09 22:38:36 +00:00
Scott Long
b302c2e5c9 Migrate the feature of excluding RAM pages to use "excludelist"
as its nomenclature.

MFC after:	1 week
2020-07-07 20:33:11 +00:00
Brandon Bergren
60185d8965 [PowerPC] XIVE dispatch tweaks
* Only read the DPCPU pointer once per xive_dispatch call.
  * Optimize HE decoding for the common cases.

Reported by:	jhibbits (in irc)
Reviewed by:	jhibbits
Sponsored by:	Tag1 Consulting, Inc.
Differential Revision:	https://reviews.freebsd.org/D25545
2020-07-06 15:15:37 +00:00
Brandon Bergren
40b664f64b [PowerPC] More relocation fixes
It turns out relocating the symbol table itself can cause issues, like fbt
crashing because it applies the offsets to the kernel twice.

This had been previously brought up in rS333447 when the stoffs hack was
added, but I had been unaware of this and reimplemented symtab relocation.

Instead of relocating the symbol table, keep track of the relocation base
in ddb, so the ddb symbols behave like the kernel linker-provided symbols.

This is intended to be NFC on platforms other than PowerPC, which do not
use fully relocatable kernels. (The relbase will always be 0)

 * Remove the rest of the stoffs hack.
 * Remove my half-baked displace_symbol_table() function.
 * Extend ddb initialization to cope with having a relocation offset on the
   kernel symbol table.
 * Fix my kernel-as-initrd hack to work with booke64 by using a temporary
   mapping to access the data.
 * Fix another instance of __powerpc__ that is actually RELOCATABLE_KERNEL.
 * Change the behavior or X_db_symbol_values to apply the relocation base
   when updating valp, to match link_elf_symbol_values() behavior.

Reviewed by:	jhibbits
Sponsored by:	Tag1 Consulting, Inc.
Differential Revision:	https://reviews.freebsd.org/D25223
2020-06-21 03:39:26 +00:00
Brandon Bergren
fb0543afa8 [PowerPC] Add virtio to GENERIC
Due to kldxref not being able to generate hints for nonnative platforms,
any cross built VM images do not have /boot/kernel/linker.hints.

This prevents the virtio modules from being loaded, as the fallback code
will always fail the version check when the hints are missing.

Since we want to be able to generate VM images for 32 bit powerpc, add the
virtio modules to GENERIC like we do on powerpc64.

Reviewed by:	jhibbits
Sponsored by:	Tag1 Consulting, Inc.
Differential Revision:	https://reviews.freebsd.org/D25271
2020-06-19 18:43:13 +00:00
Brandon Bergren
8415f755f1 [PowerPC] Fix booke64 qemu infinite loop in L2 cache enable
Since qemu does not implement the L2 cache, we get stuck forever waiting
for a bit to be set when trying to invalidate it.

To prevent that, we should bail out if the L2 cache is missing.
One easy way to check this is L2CFG0 == 0 (since L2CSIZE always has at
least one bit set in a valid implementation)

(tested on qemu, rb800, and x5000)

Reviewed by:	jhibbits
Sponsored by:	Tag1 Consulting, Inc.
Differential Revision:	https://reviews.freebsd.org/D25225
2020-06-19 18:40:39 +00:00
Justin Hibbits
ae672aa5e3 powerpc/pmap: Fix pte_find_next() iterators for booke64 pmap
After r361988 fixed the reference count leak on booke64, it became possible
for an iteration somewhere in the middle of a page to become stale, with the
page vanishing (correctly) due to all PTEs on that page going away.
pte_find_next() would start at that iterator, and move along 'higher' order
directory pages until it finds a valid one, without zeroing out the lower
order pages.  For instance:

	/* Find next pte at or above 0x10002000. */
	pte = pte_find_next(pmap, &(0x10002000));
	pte_remove(pmap, pte);
	/* This pte was the last reference in the page table page, page is
	 * gone.
	 */
	pte = pte_find_next(pmap, 0x10002000);
	/* pte_find_next will see 0x10002000's page is gone, and jump to the
	 * next one, but starting iteration at the '0x2000' slot, skipping
	 * 0x0000 and 0x1000.
	 */

This caused some processes, like git, to trip the KASSERT() in
pmap_release().

Fix this by zeroing all lower order iterators at each level.
2020-06-10 23:03:35 +00:00
Justin Hibbits
46e8ab5aa1 powerpc/powernv: Don't use the vmem quantum cache for OPAL PCI MSI allocations
vmem quantum cache is only needed when doing a lot of concurrent allocations,
which doesn't happen when allocating MSIs.  This wastes memory for the cache
zones.  Avoid this waste and don't use the quantum cache.

Reported by:	markj
2020-06-10 04:08:16 +00:00
Justin Hibbits
76d5f5e22c powerpc/mpc85xx: Don't use the quantum cache in vmem for MPIC MSIs
The qcache is unnecessary for this purpose, it's only needed when there are
lots of concurrent allocations.

Reported by:	markj
2020-06-10 04:04:59 +00:00
Justin Hibbits
c8c5600701 powerpc/pmap: Fix wired memory leak in booke64 page directories
Properly handle reference counts in the 64-bit pmap page directories.
Otherwise all page table pages would leak due to over-referencing.  This
would cause a quick enter to swap on a desktop system (AmigaOne X5000) when
quitting and rerunning applications, or just building world.

Add an INVARIANTS check to validate no leakage at pmap release time.
2020-06-09 21:59:13 +00:00
Justin Hibbits
e48f804f8c powerpc/powernv: Don't configure disabled CPUs
If the POWER firmware detects a bad CPU core, it will "GUARD" it out,
marking it disabled.  Any attempt to spin up a bad CPU will trigger a panic
later on when waiting for threads on said core to wake up.  Support limping
along on fewer cores instead.
2020-06-08 02:28:00 +00:00
Justin Hibbits
9016fac6a2 powerpc: Fix nits in copyinout comments from r361861
Also, remove useless nested #ifdefs in the IFUNC block.

Reported by:	bdragon@
2020-06-06 18:56:40 +00:00
Justin Hibbits
d31111442e powerpc: Use IFUNCs for copyin/copyout/etc
Summary:
Radix on AIM, and all of Book-E (currently), can do direct addressing of
user space, instead of needing to map user addresses into kernel space.
Take advantage of this to optimize the copy(9) functions for this
behavior, and avoid effectively NOP translations.

Test Plan: Tested on powerpcspe, powerpc64/booke, powerpc64/AIM

Reviewed by:	bdragon
Differential Revision:	https://reviews.freebsd.org/D25129
2020-06-06 03:09:12 +00:00
Justin Hibbits
3f24b50567 powerpc: Add a (CPU/runtime features) flags set to pcpu struct
Summary:
The point of this addition is to cache CPU behavior 'features', to avoid
having to recompute based on CPU, etc.

The first such use case is to avoid the unnecessary manipulation of the
SLBs (Segment Lookaside Buffers) when using the Radix pmap on POWER9.
Since we already get the PCPU pointer wherever we swap the SLB entries,
we can use a cached flag to check if it's necessary to perform the
operation anyway, and skip it when not.

Reviewed by:	bdragon
Differential Revision:	https://reviews.freebsd.org/D24908
2020-06-06 02:40:52 +00:00
Justin Hibbits
c4bc4ae778 powerpc: Stop advertising that POWER8 and POWER9 support HTM
HTM is on the chopping block, doesn't work on FreeBSD, and has only token
support in PowerISA 3.1 and POWER10.  Don't advertise something we'll never
support.
2020-05-29 00:46:31 +00:00
Justin Hibbits
9a47dfc308 powerpc/pmap: Remove some debug from r361544 2020-05-28 03:08:50 +00:00
Brandon Bergren
9b51a10a9c [PowerPC] Fix radix crash when passing -1 from userspace
Found by running libc tests with radix enabled.

Detect unsigned integer wrapping with a postcondition.

Note: Radix MMU is not enabled by default yet.

Sponsored by:	Tag1 Consulting, Inc.
2020-05-28 00:49:02 +00:00
Justin Hibbits
45b69dd63e powerpc/mmu: Convert PowerPC pmap drivers to ifunc from kobj
With IFUNC support in the kernel, we can finally get rid of our poor-man's
ifunc for pmap, utilizing kobj.  Since moea64 uses a second tier kobj as
well, for its own private methods, this adds a second pmap install function
(pmap_mmu_init()) to perform pmap 'post-install pre-bootstrap'
initialization, before the IFUNCs get initialized.

Reviewed by:	bdragon
2020-05-27 01:24:12 +00:00
Brandon Bergren
64cc3b0c28 [PowerPC] Fix invalid asm in trap code
In this context, 0 actually means 0 (i.e. this is a li instruction).

While most assemblers will ignore this, I did have a compile failure at one
point when using an external toolchain.

In the future, we should use the li syntax to make this clearer.

Sponsored by:	Tag1 Consulting, Inc.
2020-05-27 00:17:05 +00:00
Brandon Bergren
9941cb0657 [PowerPC] Fix atomic_cmpset_masked().
A recent kernel change caused the previously unused atomic_cmpset_masked() to
be used.

It had a typo in it.

Instead of reading the old value from an uninitialized variable, read it
from the passed-in pointer as intended.

This fixes crashes on 64 bit Book-E.

Obtained from:	jhibbits
2020-05-26 19:03:45 +00:00
Justin Hibbits
0aca9ecd85 powerpc/booke pmap: Fix iteration for 64-bit kernel page table creation
Kernel page tables actually start at index 4096, given kernel base address
of 0xc008000000000000, not index 0, which would yield 0xc000000000000000.
Fix this by indexing at the real base, instead of the assumed base.
2020-05-26 03:58:19 +00:00
Brandon Bergren
8ef0c667f4 [PowerPC] Ensure ppc32 cpu_switch routines set up Secure-PLT.
This is a correctness fix needed to enable the ifunc conversion of the pmap
in D24993.

Since we are making function calls that may need to go through the PLT, ensure
r30 is set up correctly.

This fixes crashes when booting with D24993 applied.

Reviewed by:	jhibbits (in IRC)
Sponsored by:	Tag1 Consulting, Inc.
2020-05-26 02:27:10 +00:00
Conrad Meyer
852c303b61 copystr(9): Move to deprecate (attempt #2)
This reapplies logical r360944 and r360946 (reverting r360955), with fixed
copystr() stand-in replacement macro.  Eventually the goal is to convert
consumers and kill the macro, but for a first step it helps if the macro is
correct.

Prior commit message:

Unlike the other copy*() functions, it does not serve to copy from one
address space to another or protect against potential faults.  It's just
an older incarnation of the now-more-common strlcpy().

Add a coccinelle script to tools/ which can be used to mechanically
convert existing instances where replacement with strlcpy is trivial.
In the two cases which matched, fuse_vfsops.c and union_vfsops.c, the
code was further refactored manually to simplify.

Replace the declaration of copystr() in systm.h with a small macro
wrapper around strlcpy (with correction from brooks@ -- thanks).

Remove N redundant MI implementations of copystr.  For MIPS, this
entailed inlining the assembler copystr into the only consumer,
copyinstr, and making the latter a leaf function.

Reviewed by:		jhb (earlier version)
Discussed with:		brooks (thanks!)
Differential Revision:	https://reviews.freebsd.org/D24672
2020-05-25 16:40:48 +00:00
Brandon Bergren
e1110c4082 [PowerPC] Fix kernel boot on powerpc
Recent changes have caused the vmspace objects to start coming from KVA
instead of direct-mapped memory on powerpc. As far as I can tell, this is
not actually a problem, so we should stop arbitrarily asserting that it is.

I do not know why this was not being triggered before.

Approved by:	jhibbits
Sponsored by:	Tag1 Consulting, Inc.
2020-05-21 15:53:16 +00:00
Justin Hibbits
b923b34a0f powerpc: Handle machine checks caused by D-ERAT multihit
Instead of crashing the user process when a D-ERAT multihit is detected, try
to flush the ERAT, and continue.  This machine check indicates a likely PMAP
invalidation shortcoming that will need to be addressed, but it's
recoverable, so just recover.  The recovery is pmap-specific to flush the
ERAT, so add a pmap function to do so, currently only implemented by the
POWER9 radix pmap.
2020-05-21 03:33:20 +00:00
Justin Hibbits
baeeef1d8f powerpc/radix mmu: No need for delayed TLB invalidation
x86 needs delayed TLB invalidation because invalidation requires an
expensive IPI.  PowerPC has had a TLB invalidation instruction since the
POWER1 in 1990, so there's no need to delay anything.
2020-05-20 02:33:41 +00:00
Justin Hibbits
1da3138f68 powerpc/mmu: Don't use the cache instructions to zero pages
A page (even physmem) can be marked as cache-inhibited.  Attempting to use
'dcbz' to zero a page mapped cache-inhibited triggers an alignment
exception, which is fatal in kernel.  This was seen when testing hardware
acceleration with X on POWER9.

At some point in the future, this should be changed to a more straight
forward zero loop instead of bzero(), and a similar change be made to the
other pmaps.

Reported by:	pkubaj@
2020-05-19 01:06:31 +00:00
Justin Hibbits
26644b0125 powerpc/qoriq: Add more devices to config for desktop usage
The most likely users of the QORIQ64 config nowadays are users of AmigaOne
X5000 systems, which are desktops.  They need a framebuffer and
keyboard/mouse, so add these to the config so it works by default once
drm-current-kmod is installed.
2020-05-16 03:33:28 +00:00
Conrad Meyer
051fc58cb3 Revert r360944 and r360946 until reported issues can be resolved
Reported by:	cy
2020-05-12 04:34:26 +00:00
Brandon Bergren
8b4b91df3f [PowerPC64] Minor correctness fix in rstcode.
TRAP_ENTRY(0) should be TRAP_GENTRAP(0) here.

However, in practice, it doesn't matter, as the only time TRAP_ENTRY and
TRAP_GENTRAP can differ is when bridge mode is active, which is impossible
on the 64 bit kernel.

Fix it anyway in case we ever need to add a trap preamble on PPC64.
2020-05-12 01:04:50 +00:00
Conrad Meyer
580744621f copystr(9): Move to deprecate [2/2]
Unlike the other copy*() functions, it does not serve to copy from one
address space to another or protect against potential faults.  It's just
an older incarnation of the now-more-common strlcpy().

Add a coccinelle script to tools/ which can be used to mechanically
convert existing instances where replacement with strlcpy is trivial.
In the two cases which matched, fuse_vfsops.c and union_vfsops.c, the
code was further refactored manually to simplify.

Replace the declaration of copystr() in systm.h with a small macro
wrapper around strlcpy.

Remove N redundant MI implementations of copystr.  For MIPS, this
entailed inlining the assembler copystr into the only consumer,
copyinstr, and making the latter a leaf function.

Reviewed by:	jhb
Differential Revision:	https://reviews.freebsd.org/D24672
2020-05-11 22:57:21 +00:00
Justin Hibbits
65bbba25d2 powerpc64: Implement Radix MMU for POWER9 CPUs
Summary:
POWER9 supports two MMU formats: traditional hashed page tables, and Radix
page tables, similar to what's presesnt on most other architectures.  The
PowerISA also specifies a process table -- a table of page table pointers--
which on the POWER9 is only available with the Radix MMU, so we can take
advantage of it with the Radix MMU driver.

Written by Matt Macy.

Differential Revision: https://reviews.freebsd.org/D19516
2020-05-11 02:33:37 +00:00
Justin Hibbits
81962477fc powerpc: Add a CPU-custom machine check handler
Summary:
Some machine checks are process-recoverable, others are not.  Let a
CPU-specific handler decide what to do.

This works around a machine check error hit while building www/firefox
and mail/thunderbird, which would otherwise cause the build to fail.

More work is needed to handle all possible machine check conditions, but
this is sufficient to unblock some ports building.

Differential Revision: https://reviews.freebsd.org/D23731
2020-05-10 19:00:57 +00:00
Brandon Bergren
9411e24df3 [PowerPC] kernel ifunc support for powerpc*, fix ppc64 relocation oddities.
This is a general cleanup of the relocatable kernel support on powerpc,
needed to enable kernel ifuncs.

 * Fix some relocatable issues in the kernel linker, and change to using
   a RELOCATABLE_KERNEL #define instead of #ifdef __powerpc__ for parts that
   other platforms can use in the future if they wish to have ET_DYN kernels.

 * Get rid of the DB_STOFFS hack now that the kernel is relocated to the DMAP
   properly across the board on powerpc64.

 * Add powerpc64 and powerpc32 ifunc functionality.

 * Allow AIM64 virtual mode OF kernels to run from the DMAP like other AIM64
   by implementing a virtual mode restart. This fixes the runtime address on
   PowerMac G5.

 * Fix symbol relocation problems on post-relocation kernels by relocating
   the symbol table.

 * Add an undocumented method for supplying kernel symbols on powernv and
   other powerpc machines using linux-style kernel/initrd loading -- If
   you pass the kernel in as the initrd as well, the copy resident in initrd
   will be used as a source for symbols when initializing the debugger.
   This method is subject to removal once we have a better way of doing this.

Approved by:	jhibbits
Relnotes:	yes
Sponsored by:	Tag1 Consulting, Inc.
Differential Revision:	https://reviews.freebsd.org/D23156
2020-05-07 19:32:49 +00:00
Mark Johnston
1d6638472b Remove an obsolete TODO comment from several minidump implementations.
The comment referenced a non-existent function, and these minidump
implementations already buffer discontiguous physical data pages by
mapping them into a single VA range that gets passed to the dump device,
so there is no real advantage in batching calls to blk_write().

The RISC-V and MIPS minidump implementations still write a page at a
time and so would benefit from some form of batching.

MFC after:	2 weeks
Sponsored by:	Juniper Networks, Klara Inc.
2020-04-24 18:47:42 +00:00
Brooks Davis
b24e6ac8b7 Convert canary, execpathp, and pagesizes to pointers.
Use AUXARGS_ENTRY_PTR to export these pointers.  This is a followup to
r359987 and r359988.

Reviewed by:	jhb
Obtained from:	CheriBSD
Sponsored by:	DARPA
Differential Revision:	https://reviews.freebsd.org/D24446
2020-04-16 21:53:17 +00:00
John Baldwin
d3920c5b12 Use %zu to print a size_t value instead of %ju.
This fixes the build for 32-bit kernels.
2020-04-16 20:46:35 +00:00
Alfredo Dal'Ava Junior
d80a924822 powerpc: autosize bpvo based on physical memory
Default moea64_bpvo_pool_size 327680 was insufficient for initial
memory mapping at boot time on systems with, for example, 64G and
no huge pages enabled.

Submitted by:	Andre Silva <afscoelho@gmail.com>
Reviewed by:	jhibbits, alfredo
Approved by:	jhibbits (mentor)
Sponsored by:	Eldorado Research Institute (eldorado.org.br)
Differential Revision:	https://reviews.freebsd.org/D24102
2020-04-15 20:33:09 +00:00
Justin Hibbits
69e8f478d5 powerpc/booke: Use power-of-two mappings in 64-bit pmap_mapdev
Summary:
This reduces the precious TLB1 entry consumption (64 possible in
existing 64-bit cores), by adjusting the size and alignment of a device
mapping to a power of 2, to encompass the full mapping and its
surroundings.

One caveat with this: If a mapping really is smaller than a power of 2,
it's possible to get a machine check or hang if the 'missing' physical
space is accessed.  In practice this should not be an issue for users,
as devices overwhelmingly have physical spaces on power-of-two sizes and
alignments, and any design that includes devices which don't follow this
can be addressed by undefining the POW2_MAPPINGS guard.

Reviewed by:	bdragon
Differential Revision: https://reviews.freebsd.org/D24248
2020-04-11 00:17:55 +00:00
Justin Hibbits
d7c0543ff8 powerpc/booke: Add pte_find_next() to find the next in-use PTE
Summary:
Iterating over VM_MIN_ADDRESS->VM_MAXUSER_ADDRESS can take a very long
time iterating one page at a time (2**(log_2(SIZE)-12) operations),
yielding possibly several days or even weeks on 64-bit Book-E, even for
a largely empty, which can happen when swapping out a process by
vmdaemon.  Speed this up by instead finding the next PTE at or equal to
the given VA.

Reviewed by:	bdragon
Differential Revision: https://reviews.freebsd.org/D24238
2020-04-11 00:16:50 +00:00
Justin Hibbits
dd8775a1b0 powerpc/booke: Change Book-E 64-bit pmap to 4-level table
Summary:
The existing page table is fraught with errors, since it creates a hole
in the address space bits.  Fix this by taking a cue from the POWER9
radix pmap, and make the page table 4 levels, 52 bits.

Reviewed by:	bdragon
Differential Revision:	https://reviews.freebsd.org/D24220
2020-04-11 00:12:34 +00:00
Justin Hibbits
ccb1ebe01c powerpc/amigaone: Add CPLD driver for AmigaOne A1222 "Tabor"
Like the X5000, the main CPLD on the A1222 is the communication medium
between the CPU and the GPIO CPLD.  It provides a mailbox communication
feature, along with dual-port RAM accessible from both the CPU and GPIO
CPLD, and 3 fan speed reporting registers.
2020-04-03 20:45:16 +00:00
John Baldwin
59838c1a19 Retire procfs-based process debugging.
Modern debuggers and process tracers use ptrace() rather than procfs
for debugging.  ptrace() has a supserset of functionality available
via procfs and new debugging features are only added to ptrace().
While the two debugging services share some fields in struct proc,
they each use dedicated fields and separate code.  This results in
extra complexity to support a feature that hasn't been enabled in the
default install for several years.

PR:		244939 (exp-run)
Reviewed by:	kib, mjg (earlier version)
Relnotes:	yes
Differential Revision:	https://reviews.freebsd.org/D23837
2020-04-01 19:22:09 +00:00
Justin Hibbits
abc00e5fb9 powerpc/pmap: Replace a logical TAILQ_FOREACH_SAFE with the real thing
No functional change, just cleanup.
2020-03-30 16:32:55 +00:00
Conrad Meyer
ca0ec73c11 Expand generic subword atomic primitives
The goal of this change is to make the atomic_load_acq_{8,16},
atomic_testandset{,_acq}_long, and atomic_testandclear_long primitives
available in MI-namespace.

The second goal is to get this draft out of my local tree, as anything that
requires a full tinderbox is a big burden out of tree.  MD specifics can be
refined individually afterwards.

The generic implementations may not be ideal for your architecture; feel
free to implement better versions.  If no subword_atomic definitions are
needed, the include can be removed from your arch's machine/atomic.h.
Generic definitions are guarded by defined macros of the same name.  To
avoid picking up conflicting generic definitions, some macro defines are
added to various MD machine/atomic.h to register an existing implementation.

Include _atomic_subword.h in arm and arm64 machine/atomic.h.

For some odd reason, KCSAN only generates some versions of primitives.
Generate the _acq variants of atomic_load.*_8, atomic_load.*_16, and
atomic_testandset.*_long.  There are other questionably disabled primitives,
but I didn't run into them, so I left them alone.  KCSAN is only built for
amd64 in tinderbox for now.

Add atomic_subword implementations of atomic_load_acq_{8,16} implemented
using masking and atomic_load_acq_32.

Add generic atomic_subword implementations of atomic_testandset_long(),
atomic_testandclear_long(), and atomic_testandset_acq_long(), using
atomic_fcmpset_long() and atomic_fcmpset_acq_long().

On x86, add atomic_testandset_acq_long as an alias for
atomic_testandset_long.

Reviewed by:	kevans, rlibby (previous versions both)
Differential Revision:	https://reviews.freebsd.org/D22963
2020-03-25 23:12:43 +00:00
Alfredo Dal'Ava Junior
d2d06767b5 [PowerPC] fix panic reading /dev/kmem on !DMAP machines
This fixes /dev/kmem causing panic on machines not using DMAP.

Found when running libkvm Kyua test case on QEMU VM with no
Huge Pages support.

Reviewed by:	jhibbits, luporl
Approved by:	jhibbits (mentor)
Sponsored by:	Eldorado Research Institute (eldorado.org.br)
Differential Revision:	https://reviews.freebsd.org/D23776
2020-03-20 11:51:08 +00:00
Brandon Bergren
3069380898 [PowerPC][Book-E] Fix missing load base in elf_cpu_parse_dynamic().
When I implemented MD DYNAMIC parsing, I was originally passing a
linker_file_t so that the MD code could relocate pointers.

However, it turns out this isn't even filled in until later, so it was
always 0.

Just pass the load base (ef->address) directly, as that's really the only
thing we were interested in in the first place.

This fixes a crash on RB800 where it was trying to write to an unmapped
address when updating the GOT.

Reviewed by:	jhibbits
Sponsored by:	Tag1 Consulting, Inc.
Differential Revision:	https://reviews.freebsd.org/D24105
2020-03-18 02:58:18 +00:00
Justin Hibbits
889d304bb4 powerpc: Axe PPC4xx support.
Summary:
The support was added almost a decade ago, and never completed.  Just axe
it.  It was also inadvertently broken 5 years ago, and nobody noticed.

Reviewed by:	bdragon
Differential Revision:	https://reviews.freebsd.org/D23753
2020-03-18 01:09:43 +00:00
Justin Hibbits
8cf2c8ed64 powerpc: Simplify _nodrop variants of FPU and vector register saves
No need for an extra temporary.  It doesn't even help with readability.

Suggested by:	kib (almost 2 years ago)
2020-03-13 01:27:37 +00:00
Leandro Lupori
c5568ba087 Enable ixl device on PowerPC64
The ixl driver now works on PowerPC64 and may be compiled in-kernel and
as a module.

Reviewed by:	alfredo, erj
Sponsored by:	Eldorado Research Institute (eldorado.org.br)
Differential Revision:	https://reviews.freebsd.org/D23974
2020-03-12 12:47:10 +00:00
Justin Hibbits
d926d5780e powerpc/booke: Split out 32- and 64- bit pmap details from main body
Summary:
This is largely a straight-forward cleave of the 32-bit and 64-bit page
table specifics, along with the mmu_booke_*() functions that are wholely
different between the two implementations.

The ultimate goal of this is to make it easier to reason about and
update a specific implementation without wading through the other
implementation details.  This is in support of further changes to the 64-bit
pmap.

Reviewed by: bdragon
Differential Revision: https://reviews.freebsd.org/D23983
2020-03-10 03:30:11 +00:00
Andreas Tobler
11236821c6 Revert 2020-03-06 23:01:49 +00:00
Andreas Tobler
7e0d320048 Drop 'All rights reserved'
Replace hardcoded sizes by nitems and sizeof
Replace CTLFLAG_NEEDGIANT with CTLFLAG_MPSAFE, I run this driver since a few
years with CTLFLAG_MPSAFE w/o issues.
2020-03-06 21:51:28 +00:00
Mark Johnston
3eac6de2f0 Remove dead code from the powerpc uma_small_alloc().
32-bit Book-E doesn't set UMA_MD_SMALL_ALLOC, and 32-bit OEA platforms
have a 32-bit vm_paddr_t.  Moreover, this code was wrong in that it
leaked the page if the check failed.

Reviewed by:	jhibbits
MFC after:	1 week
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D23991
2020-03-06 20:44:22 +00:00
Leandro Lupori
d8c51c6f74 [aacraid] Port driver to big-endian
Port aacraid driver to big-endian (BE) hosts.

The immediate goal of this change is to make it possible to use the
aacraid driver on PowerPC64 machines that have Adaptec Series 8 SAS
controllers.

Adapters supported by this driver expect FIB contents in little-endian
(LE) byte order. All FIBs have a fixed header part as well as a data
part that depends on the command being issued to the controller.

In this way, on BE hosts, the FIB header and all FIB data structures
used in aacraid.c and aacraid_cam.c need to be converted to LE before
being sent to the adapter and converted to BE when coming from it.

The functions to convert each struct are on aacraid_endian.c.
For little-endian (LE) targets, they are macros that expand
to nothing.
In some cases, when only a few fields of a large structure are used,
the fields are converted inline, by the code using them.

PR:		237463
Reviewed by:	jhibbits
Sponsored by:	Eldorado Research Institute (eldorado.org.br)
Differential Revision:	https://reviews.freebsd.org/D23887
2020-03-05 20:04:41 +00:00
Alfredo Dal'Ava Junior
5554f4cc45 [PowerPC64] fix uma_small_free panic
Fix panic "Freeing UMA block at 0xn with no associated page".
Also replaces pmap_remove call by pmap_kremove, for symmetry.

Reviewed by:	jhibbits
Approved by:	jhibbits (mentor)
Differential Revision:	https://reviews.freebsd.org/D23931
2020-03-05 12:24:48 +00:00
Justin Hibbits
6df6aae9bd powerpc/powernv: powernv_node_numa_domain() fix non-NUMA case
If NUMA is not enabled in the kernel config, or is disabled at boot, this
function should just return domain 0 regardless of what's in the device
tree.

Fixes a panic in iflib with NUMA disabled.

Reported by:	luporl
2020-03-03 03:22:00 +00:00
Warner Losh
daba5ace03 Finish removal of bktr
Remove the old ioctl .h files
Remove copying/linking ioctl .h files in instasllworld
Remove bktr from lint
Add now-removed files with ObsoleteFiles
2020-03-01 20:37:42 +00:00
Pawel Biernacki
7029da5c36 Mark more nodes as CTLFLAG_MPSAFE or CTLFLAG_NEEDGIANT (17 of many)
r357614 added CTLFLAG_NEEDGIANT to make it easier to find nodes that are
still not MPSAFE (or already are but aren’t properly marked).
Use it in preparation for a general review of all nodes.

This is non-functional change that adds annotations to SYSCTL_NODE and
SYSCTL_PROC nodes using one of the soon-to-be-required flags.

Mark all obvious cases as MPSAFE.  All entries that haven't been marked
as MPSAFE before are by default marked as NEEDGIANT

Approved by:	kib (mentor, blanket)
Commented by:	kib, gallatin, melifaro
Differential Revision:	https://reviews.freebsd.org/D23718
2020-02-26 14:26:36 +00:00
Justin Hibbits
d029e3b3f7 Unbreak the 32-bit powerpc builds
Force unsigned integer usage by casting to vm_offset_t, to avoid integer
overflow, from r358305
2020-02-25 02:42:43 +00:00
Justin Hibbits
0b2f25287c powerpc/booke: Use a pseudo-DMAP for the device mappings on booke64
Since powerpc64 has such a large virtual address space, significantly larger
than its physical address space, take advantage of this, and create yet
another DMAP-like instance for the device mappings.  In this case, the
device mapping "DMAP" is in the 0x8000000000000000 - 0xc000000000000000
range, so as not to overlap the physical memory DMAP.

This will allow us to add TLB1 entry coalescing in the future, especially
useful for things like the radeonkms driver, which maps parts of the GPU at
a time, but eventually maps all of it, using up a lot of TLB1 entries (~40).
2020-02-25 01:40:22 +00:00
Justin Hibbits
5915b638b0 powerpc/booke: Fix handling of pvh_global_lock and pmap lock
ptbl_alloc() is expected to return with the pvh_global_lock and pmap
lock held.  However, it will return with them unlocked if nosleep is
specified.

Along with this, fix lock ordering of pvh_global_lock with respect to
the pmap lock in other places.

Differential Revision: https://reviews.freebsd.org/D23692
2020-02-22 01:31:06 +00:00
Ryan Libby
9fab908a79 powerpc: unconditionally mark SLB zones UMA_ZONE_CONTIG
PR:		244118
Reported by:	Francis Little <oggy at farscape.co.uk>
Tested by:	Francis Little, Mark Millard <marklmi at yahoo.com>
Reviewed by:	markj
Sponsored by:	Dell EMC Isilon
Differential Revision:	https://reviews.freebsd.org/D23729
2020-02-19 04:46:41 +00:00
Justin Hibbits
478d3cf5b8 powerpc/amigaone: Fix license header formatting on cpld files
This should've been fixed before initial commit, but wasn't.  Not even sure
how it happened in the first place.
2020-02-19 03:39:11 +00:00
Dimitry Andric
816dab96c1 Disable new clang 10.0.0 warnings about misleading indentation in
sys/contrib/ncsw/Peripherals/FM/fman_ncsw.c.

This is horribly formatted contributed code, and fixing it is not worth
the effort.
2020-02-17 19:20:47 +00:00
Justin Hibbits
31091dea96 powerpc: Fix altivec disabling in set_mcontext()
We somewhat blindly copy the srr1 from the new context to the trap frame,
but disable FPU and VSX unconditionally, relying on the trap to re-enable
them.  This works because the FPU manages the VSX extended FP registers,
which is governed by the PCB_FPFREGS flag.  However, with altivec, we
would blindly disable PSL_VEC, without touching PCB_VEC.  Handle this case
by disabling altivec in both srr1 and pcb_flags, if the mcontext doesn't
have _MC_AV_VALID set.

Reported by:	pkubaj
2020-02-06 01:25:30 +00:00
Mark Johnston
c3d326fd44 Define MAXCPU consistently between the kernel and KLDs.
This reverts r177661.  The change is no longer very useful since
out-of-tree KLDs will be built to target SMP kernels anyway.  Moveover
it breaks the KBI in !SMP builds since cpuset_t's layout depends on the
value of MAXCPU, and several kernel interfaces, notably
smp_rendezvous_cpus(), take a cpuset_t as a parameter.

PR:		243711
Reviewed by:	jhb, kib
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D23512
2020-02-05 19:08:21 +00:00
Ryan Libby
10c8fb47d9 uma: convert mbuf_jumbo_alloc to UMA_ZONE_CONTIG & tag others
Remove mbuf_jumbo_alloc and let large mbuf zones use the new uma default
contig allocator (a copy of mbuf_jumbo_alloc).  Tag other zones which
require contiguous objects, even if they don't use the new default
contig allocator, so that uma knows about their constraints.

Reviewed by:	jeff, markj
Sponsored by:	Dell EMC Isilon
Differential Revision:	https://reviews.freebsd.org/D23238
2020-02-04 22:40:23 +00:00
Brandon Bergren
d98eb707b0 [PowerPC] Fix VSX context handling
In r356767, memcpy/memmove/bcopy optimizations were added to libc to
improve performance.

This exposed an existing kernel issue in VSX handling. The PSL_VSX flag was
not being excluded from the psl_userstatic set, which meant that any thread
that used these and then called swapcontext(3) would get an EINVAL error.

Fixing this exposed a second issue - in r344123, the FPU was being forced
off in set_mcontext(). However, this was neglecting to ensure VSX was turned
off at the same time.

While here, add some code comments to explain what's going on.

Reviewed by:	jhibbits, luporl (earlier rev), pkubaj (earlier rev)
Sponsored by:	Tag1 Consulting, Inc.
Differential Revision:	https://reviews.freebsd.org/D23497
2020-02-04 20:40:45 +00:00
Mark Johnston
1c29da0279 Reimplement stack capture of running threads on i386 and amd64.
After r355784 the td_oncpu field is no longer synchronized by the thread
lock, so the stack capture interrupt cannot be delievered precisely.
Fix this using a loop which drops the thread lock and restarts if the
wrong thread was sampled from the stack capture interrupt handler.

Change the implementation to use a regular interrupt instead of an NMI.
Now that we drop the thread lock, there is no advantage to the latter.

Simplify the KPIs.  Remove stack_save_td_running() and add a return
value to stack_save_td().  On platforms that do not support stack
capture of running threads, stack_save_td() returns EOPNOTSUPP.  If the
target thread is running in user mode, stack_save_td() returns EBUSY.

Reviewed by:	kib
Reported by:	mjg, pho
Tested by:	pho
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D23355
2020-01-31 15:43:33 +00:00
Leandro Lupori
a9d8f71f7b [PPC64] Fix NUMA on POWER8
On some POWER8 machines, 'ibm,associativity' property may have 6
cells, which would overflow the 5 cells buffer being used.
There was also an issue with the "check if node is root" part,
that have been fixed too.

Reviewed by:	jhibbits
Differential Revision:	https://reviews.freebsd.org/D23414
2020-01-29 18:13:44 +00:00
Gleb Smirnoff
de086f1a6c This is Ethernet driver so mark the interrupt appropriately. 2020-01-23 01:46:05 +00:00
Justin Hibbits
f3f43ab1f0 powerpc/amiga: Hide CPLD date and time printing behind bootverbose
There's no need to see the CPLD build date and time every boot.
2020-01-20 04:01:35 +00:00
Justin Hibbits
2a05eb9f3c PowerPC: Add CPLD driver for AmigaOne X5000
Summary:
The CPLD is the communications medium between the CPU and the XMOS
"Xena" event coprocessor.  It provides a mailbox communication feature,
along with dual-port RAM to be used between the CPU and XMOS.  Also, it
provides basic board stats as well, such as PCIe presence, JTAG signals,
and CPU fan speed reporting (in revolutions per second).  Only fan speed
reading is handled, as a sysctl.

Reviewed by:	bdragon
Differential Revision:	https://reviews.freebsd.org/D23136
2020-01-19 21:43:15 +00:00
Justin Hibbits
95a8fce118 [PowerPC64] fix crash when using machdep.moea64_bpvo_pool_size tunable
Summary:
This fixes kernel crashing when tunable "machdep.moea64_bpvo_pool_size" is
set to a value higher then 327680 (default value).  Function
moea64_mid_bootstrap() relies on moea64_bpvo_pool_size, but at time of the
use the variable wan't yet updated with the new value provided by user.

Problem was detected after trying to use a VM with 64GB of RAM, and default
moea64_bpvo_pool_size is insufficient (kernel boot used more than 470000) .
I think default value must be discussed to address this use case, or find a
way to calculate pool size automatically based on amount of memory detected.

Test Plan: Tested on QEMU VM with 64GB of RAM using "set
machdep.moea64_bpvo_pool_size=655360" on loader prompt

Submitted by:	Alfredo Dal'Ava Júnior (alfredo.junior_eldorado.org.br)
Differential Revision:	https://reviews.freebsd.org/D23233
2020-01-19 21:17:57 +00:00
Brandon Bergren
ee628685e8 D23057: [PowerPC] Fix offset calculations in bridge mode
In rS354701, I replaced text relocations with offsets from &generictrap.

Unfortunately, the magic variable I was using doesn't actually mean the
address of &generictrap, in bridge mode it actually means &generictrap64.

So, for bridge mode to work, it is necessary to differentiate between
"where do we need to branch to to handle a trap" and "where is &generictrap
for purposes of doing relative math".

Introduce a new TRAP_ENTRY and use it instead of TRAP_GENTRAP for doing
actual calls to the generic trap handler.

Reported by:	Mark Millard <marklmi@yahoo.com>
Reviewed by:	jhibbits
Sponsored by:	Tag1 Consulting, Inc.
Differential Revision:	https://reviews.freebsd.org/D23057
2020-01-18 04:12:41 +00:00
Justin Hibbits
de8dd262c4 Add a 'SINGLETON' directive to kobj interface definition
Summary:
This makes the interface described in the definition file act like a
pseudo-IFUNC service, by caching the found method locally.

Applying this to the PowerPC MMU definitions, it yields a significant
(15-20%) performance improvement, seen in both a 'make buildworld' and a
parallel build of LLVM, on a POWER9 system.

Reviewed By:	imp
Differential Revision:	https://reviews.freebsd.org/D23245
2020-01-18 02:39:38 +00:00
Justin Hibbits
490ebb8f35 powerpc: Fix the NUMA domain list on powernv
Summary:
Consolidate the NUMA associativity handling into a platform function.
Non-NUMA platforms will just fall back to the default (0).  Currently
only implemented for powernv, which uses a lookup table to map the
device tree associativity into a system NUMA domain.

Fixes hangs on powernv after r356534, and corrects a fairly longstanding
bug in powernv's NUMA handling, which ended up using domains 1 and 2 for
devices and memory on power9, while CPUs were bound to domains 0 and 1.

Reviewed by:	bdragon, luporl
Differential Revision:	https://reviews.freebsd.org/D23220
2020-01-18 01:26:54 +00:00
Brandon Bergren
432ff6eead [PowerPC] Fix Book-E direct map for >=16G ram on e5500
It turns out the maximum TLB1 page size on e5500 is 4G, despite the format
being defined for up to 1TB.

So, we need to clamp the DMAP TLB1 entries to not attempt to create 16G or
larger entries.

Fixes boot on my X5000 in which I just installed 16G of RAM.

Reviewed by:	jhibbits
Sponsored by:	Tag1 Consulting, Inc.
Differential Revision:	https://reviews.freebsd.org/D23244
2020-01-18 01:22:54 +00:00
Brandon Bergren
eabe020579 [PowerPC] Save a dword in the powerpc64 signal trampoline
In r291668, an instruction was added to sigcode64.S without the nop pad at
the end being taken out.

Due to alignment, this means that a dword is being wasted on the shared
page for no reason.

Take out this nop, and add some comments while I'm here.

Reviewed by:	jhibbits
Sponsored by:	Tag1 Consulting, Inc.
Differential Revision:	https://reviews.freebsd.org/D23055
2020-01-17 23:41:35 +00:00
Leandro Lupori
e07530d2df [PPC] Fix wrong comment
pcb_context[20] holds r12-r31 and not r14-r31, as the comment said.
2020-01-17 14:43:58 +00:00
Leandro Lupori
d4633a9e3c [PowerPC64] Enable virtio drivers
This enables virtio modules on PowerPC* target.
On PowerPC64, drivers are also kernel builtin.

QEMU currently needs to be patched to in order to work on LE hosts due to known
issue affecting pre-1.0 (legacy) virtio drivers.

The patch was submitted to QEMU mail list by @afscoelho_gmail.com, available at
https://lists.nongnu.org/archive/html/qemu-devel/2020-01/msg01496.html

Submitted by:	Alfredo Dal'Ava Junior <alfredo.junior@eldorado.org.br>
Reviewed by:	luporl
Differential Revision:	https://reviews.freebsd.org/D22833
2020-01-16 11:33:15 +00:00
Justin Hibbits
a80e3de39b powerpc/mpc85xx: Partially revert r356640
The count block was correct before.  r356640 caused a read past the end of
the tuple.
2020-01-13 23:09:00 +00:00
Justin Hibbits
7d7671db00 powerpc/mpc85xx: Fix localbus child reg property decoding
r302340, as an attempt to fix the localbus child handling post-rman change,
actually broke child resource allocation, due to typos in
fdt_lbc_reg_decode().  This went unnoticed because there aren't any drivers
currently in tree that use localbus.
2020-01-11 22:29:44 +00:00
Justin Hibbits
a11dc32ebc powerpc: Prevent infinite loop in moea_sync_icache()
This applies r344049 to the 32-bit pmap.

Reported by:	Mark Millard <marklmi_yahoo.com>
2020-01-10 04:13:16 +00:00
Justin Hibbits
4dc25d4452 powerpc: Mark cpu_feature-based sysctls as MP_SAFE
hw.floatingpoint and hw.altivec are effectively runtime constants (bits from
the cpu_feature bitfield), so don't need Giant, or any locking for that
matter.
2020-01-10 03:16:40 +00:00
Justin Hibbits
03b6e7a627 powerpc/powernv: Un-Giant-ify opal_nvram driver
It may be possible to make this completely lock free, but for now it's using
a statically allocated bounce buffer in the softc, so it needs to be
guarded.
2020-01-10 01:24:49 +00:00
Justin Hibbits
24e87ffae8 powerpc: Remove 'sec' device from QORIQ64 config
The SEC crypto engine, as implemented in this driver, does not exist on any
64-bit SoC, so don't bother compiling it in.
2020-01-04 01:13:00 +00:00
Brandon Bergren
9aafc7c052 [PowerPC] [MIPS] Implement 32-bit kernel emulation of atomic64 operations
This is a lock-based emulation of 64-bit atomics for kernel use, split off
from an earlier patch by jhibbits.

This is needed to unblock future improvements that reduce the need for
locking on 64-bit platforms by using atomic updates.

The implementation allows for future integration with userland atomic64,
but as that implies going through sysarch for every use, the current
status quo of userland doing its own locking may be for the best.

Submitted by:	jhibbits (original patch), kevans (mips bits)
Reviewed by:	jhibbits, jeff, kevans
Differential Revision:	https://reviews.freebsd.org/D22976
2020-01-02 23:20:37 +00:00
Brandon Bergren
9367fb301c [PowerPC] Fix panic when attempting to handle an HMI from an idle thread
In IRC, sfs_ finally managed to get a good trace of a kernel panic that was
happening when attempting to use webengine.

As it turns out, we were using vtophys() from interrupt context on an idle
thread in opal_hmi_handler2().

Since this involves locking the kernel pmap on PPC64 at the moment, this
ended up tripping a KASSERT in mtx_lock(), which then caused a parallel
panic stampede.

So, avoid this by preallocating the flags variable and storing it in PCPU.

Fixes "panic: mtx_lock() by idle thread 0x... on sleep mutex kernelpmap".

Differential Revision:	https://reviews.freebsd.org/D22962
2019-12-30 02:56:47 +00:00
Kyle Evans
06b367b2b6 sc(4) md bits: stop setting sc->kbd entirely
The machdep parts no longer need to touch keyboard parts after r356043;
sc->kbd will be 0-initialized and this works as expected.
2019-12-30 02:07:55 +00:00
Brandon Bergren
12fe21a3d8 [PowerPC] Ignore fortify-source warning in trap vector copy
Due to a bug in clang 9.0.0 source tracking, the trap vector copying will
always trigger a fortify-source warning.

The destination buffers are 0x2f00 bytes, and the bcopy region is 0x2e00
bytes, so there is not an overflow here.

(I have been running with this patch since September.)
2019-12-27 19:58:14 +00:00
Justin Hibbits
741dfd86b3 Fix the powerpc copyout fixup from r356113
Summary:
r356113 used an older patch, which predated the
freebsd_copyout_auxargs() addition.  Fix this by using a private
powerpc_copyout_auxargs() instead, and keep it private to powerpc, not in MI
files.

Reviewed by:	kib, bdragon
Differential Revision:	https://reviews.freebsd.org/D22935
2019-12-27 17:38:25 +00:00
Justin Hibbits
e211e5fec6 powerpc: Move ppc32_runtime_resolve() declaration to the right place
The function is only used in 32-bit kernels, so move the declaration to
!powerpc64.
2019-12-26 22:47:24 +00:00
Brandon Bergren
057832282f [PowerPC] Define powerpc IFUNC kernel/userspace ABI.
This is a prerequisite for anything IFUNC in the ELFv2 / clang switch.

Since probing cpu info on powerpc is a privileged operation, define that we
pass AT_HWCAP / AT_HWCAP2 through as cpu_features and cpu_features2 to ifunc
resolvers.

This is particularly important when dealing with non-PLT GNU IFUNC, which is
not allowed to PLT call from resolvers and therefore can't access global
variables.

The naming convention "cpu_features"/"cpu_features2" is an existing FreeBSD
PowerPC convention and matches the way we treat these variables in
machine/cpu.h.

The underlying variables are u_long, however, as per the commit message for
r332868, only the low 32 bits are ever used, so the underlying flags are
compatible across all of PowerPC.

The resolver prototype is defined to reserve the maximum number of
register-passed parameters the various PowerPC ABIs allow. This leaves
plenty of room for growth without needing to resort to passing via the
stack in the future.

Reviewed by:	jhibbits
Differential Revision:	https://reviews.freebsd.org/D22787
2019-12-24 20:13:29 +00:00
Brandon Bergren
7821a820d0 [PowerPC] Implement Secure-PLT jump table processing for ppc32.
Due to clang and LLD's tendency to use a PLT for builtins, and as they
don't have full support for EABI, we sometimes have to deal with a PLT in
.ko files in a clang-built kernel.

As such, augment the in-kernel linker to support jump table processing.

As there is no particular reason to support lazy binding in kernel modules,
only implement Secure-PLT immediate binding.

As part of these changes, add elf_cpu_parse_dynamic() to the MD API of the
in-kernel linker (except on platforms that use raw object files.)

The new function will allow MD code to act on MD tags in _DYNAMIC.

Use this new function in the PowerPC MD code to ensure BSS-PLT modules using
PLT will be rejected during insertion, and to poison the runtime resolver to
ensure we get a clear panic reason if a call is made to the resolver.

Reviewed by:	jhibbits
Differential Revision:	https://reviews.freebsd.org/D22608
2019-12-24 15:56:24 +00:00
Scott Long
757d4fbaa7 Introduce the concept of busdma tag templates. A template can be allocated
off the stack, initialized to default values, and then filled in with
driver-specific values, all without having to worry about the numerous
other fields in the tag. The resulting template is then passed into
busdma and the normal opaque tag object created.  See the man page for
details on how to initialize a template.

Templates do not support tag filters.  Filters have been broken for many
years, and only existed for an ancient make/model of hardware that had a
quirky DMA engine.  Instead of breaking the ABI/API and changing the
arugment signature of bus_dma_tag_create() to remove the filter arguments,
templates allow us to ignore them, and also significantly reduce the
complexity of creating and managing tags.

Reviewed by:	imp, kib
Differential Revision:	https://reviews.freebsd.org/D22906
2019-12-24 14:48:46 +00:00
Kyle Evans
19352ba5ad powerpc: repeat of r356044
It would have been nice to not have these duplicated in every single
sc_machdep.
2019-12-23 21:57:11 +00:00
Kyle Evans
db41cd0e06 Kill off dummy kbd drivers
As far as I can tell, these are an artifact of times when linker sets
couldn't be empty, otherwise the kernel build would fail due to unresolved
symbols. hselasky fixed this in r268138, and I've audited the kbd portions
to make sure nothing would blow up due to the empty linker set and
successfully compiled+ran a kernel with no keyboard support at all.

Kill them off now since they're no longer required.

MFC after:	1 week
2019-12-20 16:22:14 +00:00
Jeff Roberson
a94ba188c3 Repeat the spinlock_enter/exit pattern from amd64 on other architectures to
fix an assert violation introduced in r355784.  Without this spinlock_exit()
may see owepreempt and switch before reducing the spinlock count.  amd64
had been optimized to do a single critical enter/exit regardless of the
number of spinlocks which avoided the problem and this optimization had
not been applied elsewhere.

Reported by:	emaste
Suggested by:	rlibby
Discussed with:	jhb, rlibby
Tested by:	manu (arm64)
2019-12-16 20:15:04 +00:00
Leandro Lupori
fa76c6f9ba [PPC] Handle qOffsets packet
On PowerPC, this is needed in order for the debugger to find out
the memory offset where the kernel image was loaded on the remote
target.

This fixes symbol resolution when remote debugging a PowerPC kernel.

Reviewed by:	cem
Differential Revision:	https://reviews.freebsd.org/D22767
2019-12-16 13:17:39 +00:00
Justin Hibbits
1223b40eba powerpc/powernv: Set the PTCR for the Nest MMU
The Nest MMU manages address translation for accelerators on the POWER9.  To
do so, it needs a page table, so export the system page table to the Nest
MMU.  This will quietly fail on pre-POWER9 systems that do not have a NMMU.

The NMMU is currently unused, so this change is currently effectively a NOP,
but the NMMU and VAS will eventually be used.
2019-12-15 21:20:18 +00:00
Justin Hibbits
0548026500 powerpc/mpc85xx: Clean up Freescale SATA driver a little
* Remove unused ATA_IN/OUT macros, they just clutter up the file.
* Fix some RID management bits for the channel memory resource.
2019-12-15 21:08:40 +00:00
Brandon Bergren
4f9ed3156c [PowerPC] Fix SPE floating point environment manipulation
Fix multiple problems in the powerpcspe floating point code.

* Endianness handling of the SPEFSCR in fenv.h was completely broken.
* Ensure SPEFSCR synchronization requirements are being met.

The __r.__d -> __r transformations were written by jhibbits.

Reviewed by:	jhibbits
Differential Revision:	https://reviews.freebsd.org/D22526
2019-12-12 17:12:18 +00:00
Brandon Bergren
0343972379 [PowerPC] Fix powerpc 32 bit build in mmu_oea64.c
Due to ppc32 building mmu_oea64.c (for use when in bridge mode on a G5), we
need to guard the new moea64_page_array_startup code behind __powerpc64__
to avoid a compile error, since vm_offset_t is not 64-bit on ppc32.

Reviewed by:	jhibbits
Differential Revision:	https://reviews.freebsd.org/D22782
2019-12-12 16:49:55 +00:00
Mark Johnston
5cff1f4dc3 Introduce vm_page_astate.
This is a 32-bit structure embedded in each vm_page, consisting mostly
of page queue state.  The use of a structure makes it easy to store a
snapshot of a page's queue state in a stack variable and use cmpset
loops to update that state without requiring the page lock.

This change merely adds the structure and updates references to atomic
state fields.  No functional change intended.

Reviewed by:	alc, jeff, kib
Sponsored by:	Netflix, Intel
Differential Revision:	https://reviews.freebsd.org/D22650
2019-12-10 18:14:50 +00:00
Leandro Lupori
35f294270c Enable use of ofwcons for early debug
This change enables the use of OpenFirmware Console (ofwcons), even when VGA is
available, allowing early kernel messages to be seen, that is important in case
of crashes before VGA console initialization.

This is specially useful in virtualized environments, where the user/developer
doesn't have full control of the virtualization engine (e.g. OpenStack).

The old behavior is preserved by default and, in order to use ofwcons, a few
tunables that have been introduced need to be set:
- hw.ofwfb.disable=1     - disable OFW FrameBuffer device
- machdep.ofw.mtx_spin=1 - change PPC OFW mutex to SPIN type, to match kernel
                           console's mutex type
- debug.quiesce_ofw=0    - don't call OFW quiesce, needed to keep ofwcons I/O
                           working

More details can be found at differential revision D20640.

Reviewed by:	jhibbits
Differential Revision:	https://reviews.freebsd.org/D20640
2019-12-09 13:40:23 +00:00
Leandro Lupori
a16111e6a2 [PPC64] Enable opal console use as a GDB DBGPORT
This change makes it possible to use OPAL console as a GDB debug port.

Similar to uart and uart_phyp debug ports, it has to be enabled by
setting the hw.uart.dbgport variable to the serial console node
of the device tree.

Reviewed by:	jhibbits
Differential Revision:	https://reviews.freebsd.org/D22649
2019-12-09 13:09:32 +00:00
Justin Hibbits
9e319462a0 powerpc: Use builtins for fls/flsl
Summary:
There's no need to use the fallback fls() and flsl() libkern functions
when the PowerISA includes instructions that already do the bulk of the
work.  Take advantage of this through the GCC builtins __builtin_clz()
and __builtin_clzl().

Reviewed by:	luporl
Differential Revision:	https://reviews.freebsd.org/D22340
2019-12-08 04:36:42 +00:00
Justin Hibbits
a795401110 powerpc64/pmap: micro-optimize some PVO-PTE logic
Summary:
moea64_pte_sync_native() and moea64_pte_unset_native() don't need the
full PTE created, they only need to check that the PVO has a matching
PTE to the PTE in the page table.  Don't waste time creating the full
PTE in this case.

Reviewed by:	luporl
Differential Revision:	https://reviews.freebsd.org/D22341
2019-12-08 04:17:04 +00:00
Justin Hibbits
caef3e1280 powerpc/pmap: NUMA-ize vm_page_array on powerpc
Summary:
This matches r351198 from amd64.  This only applies to AIM64 and Book-E.
On AIM64 it short-circuits with one domain, to behave similar to
existing.  Otherwise it will allocate 16MB huge pages to hold the page
array, across all NUMA domains.  On the first domain it will shift the
page array base up, to "upper-align" the page array in that domain, so
as to reduce the number of pages from the next domain appearing in this
domain.  After the first domain, subsequent domains will be allocated in
full 16MB pages, until the final domain, which can be short.  This means
some inner domains may have pages accounted in earlier domains.

On Book-E the page array is setup at MMU bootstrap time so that it's
always mapped in TLB1, on both 32-bit and 64-bit.  This reduces the TLB0
overhead for touching the vm_page_array, which reduces up to one TLB
miss per array access.

Since page_range (vm_page_startup()) is no longer used on Book-E but is on
32-bit AIM, mark the variable as potentially unused, rather than using a
nasty #if defined() list.

Reviewed by:	luporl
Differential Revision:	https://reviews.freebsd.org/D21449
2019-12-07 03:34:03 +00:00
John Baldwin
65d2f9c12b Use a void * argument to callout handlers instead of timeout_t casts.
Reviewed by:	kib
Differential Revision:	https://reviews.freebsd.org/D22684
2019-12-05 18:47:29 +00:00
Warner Losh
f86e60008b Regularize my copyright notice
o Remove All Rights Reserved from my notices
o imp@FreeBSD.org everywhere
o regularize punctiation, eliminate date ranges
o Make sure that it's clear that I don't claim All Rights reserved by listing
  All Rights Reserved on same line as other copyright holders (but not
  me). Other such holders are also listed last where it's clear.
2019-12-04 16:56:11 +00:00
Justin Hibbits
ad73d2ab3f powerpc/booke: Fix some formatting errors in debug printfs
Use the right formats for the types given (vm_offset_t and vm_size_t are
both uint32_t on 32-bit platforms, and uint64_t on 64-bit platforms, and
match size_t in size, so we can use the size_t format as we do in other
similar code).

These were found by clang.
2019-12-04 03:51:30 +00:00
Justin Hibbits
4160ed6f8b powerpc/booke: Fix 32-bit Book-E SMP AP bringup
r354266 changed the type of bp_kernload to vm_paddr_t in platform_mpc85xx.c,
but not the variable itself in locore.S.  This caused the AP to not come up,
due to overwriting the following variable (bp_virtaddr).  Also, properly
load bp_kernload into MAS3 and MAS7.  Prior to r354266, we required loading
into the low 4GB, but now we can load from anywhere in memory that ubldr can
access.
2019-12-04 03:41:55 +00:00
John Baldwin
31174518d2 Use uintptr_t instead of register_t * for the stack base.
- Use ustringp for the location of the argv and environment strings
  and allow destp to travel further down the stack for the stackgap
  and auxv regions.
- Update the Linux copyout_strings variants to move destp down the
  stack as was done for the native ABIs in r263349.
- Stop allocating a space for a stack gap in the Linux ABIs.  This
  used to hold translated system call arguments, but hasn't been used
  since r159992.

Reviewed by:	kib
Tested on:	md64 (amd64, i386, linux64), i386 (i386, linux)
Sponsored by:	DARPA
Differential Revision:	https://reviews.freebsd.org/D22501
2019-12-03 23:17:54 +00:00
Justin Hibbits
1fb6e11ed5 powerpc: Add 'show frame <addr>' to show an arbitrary trap frame
This lets us print, for example, the user's trap frame when a panic occurs.
The frame address is given in the backtrace at the trap point, which can
then be passed to 'show frame'.  This is useful for debugging as it can show
inputs that lead to a panic or fault.  It can also be used to print trap
frames from other CPUs that get stuck.

i386 already has a similar command, but no others do.
2019-12-01 21:29:34 +00:00
Kyle Evans
80d6dbeea0 Remove more needless <sys/tty.h> includes
As part of my journey to make it easy to determine what's relying on tty
bits, remove a couple more. Some of these just outright didn't need it,
while others did rely on <sys/tty.h> pollution for mutex headers.
2019-12-01 20:43:37 +00:00
Leandro Lupori
0b0c23fee3 [PPC] Remove extra \0 char inserted on vty by QEMU
Since version 2.11.0, QEMU became bug-compatible with
PowerVM's vty implementation, by inserting a \0 after
every \r going to the guest. Guests are expected to
workaround this issue by removing every \0 immediately
following a \r.

Reviewed by:	jhibbits
Differential Revision:	https://reviews.freebsd.org/D22171
2019-11-29 11:34:11 +00:00
Leandro Lupori
4ceaf951fb [PPC64] Enable phyp vty use as a GDB DBGPORT
This change makes it possible to use a POWER Hypervisor virtual
terminal device (phyp vty) as a GDB debug port.

Similar to the uart debug port, it has to be enabled by setting
the hw.uart_phyp.dbgport variable to the vty node of the device
tree.

Reviewed by:	jhibbits
Differential Revision:	https://reviews.freebsd.org/D22205
2019-11-25 16:30:38 +00:00
Brandon Bergren
a638bf2a76 [PowerPC] Use QEMU-compatible version of SPE accumulator save
Switch from "evaddumiaaw 0,0" to "evmwumiaa 0,0,0" when persisting the
accumulator. This has the benefit of actually being implemented in QEMU
as it is the form Linux uses for the same task.

Both instructions are functionally equivilent, as we are using them for
their side effect of copying the accumulator to GPRs rather than for the
actual math operation that they are performing.

Reviewed by: jhibbits
2019-11-23 21:18:55 +00:00
Justin Hibbits
e988a68e5a powerpc/ptrace: Give ptrace(2) access to SPE registers when available
SPE registers are already exported in core dumps with the VMX note, so use
the same interface for live access.

Instead of simply guarding out in #ifndef __SPE__ the cpu_feature check, I
chose to keep the check and check against PPC_FEATURE_SPE, on the off-chance
someone decides to run a SPE kernel on a non-SPE device (which is possible,
though highly unlikely, and would be no different from running a MPC85XX
kernel in that instance).
2019-11-22 04:34:46 +00:00
Justin Hibbits
309d2bc890 powerpc/pmap: Remove an unused error from moea64_pvo_enter()
ENOENT is leftover from mmu_oea.c's moea_pvo_enter(), where it's used to
syncicache() on the first new mapping of a page.  This sync is done
differently in OEA64.
2019-11-19 02:00:13 +00:00
Justin Hibbits
7194b0a3b0 powerpc/booke pmap: Use the right 'tlbilx' form to invalidate TIDs
'tlbilxpid' is 'tlbilx 1, 0', while the existing form is 'tlbilx 0, 0',
which translates to 'tlbilxlpid', invalidating a LDPID.  This effectively
invalidates the entire TLB, causing unnecessary reloads.
2019-11-19 01:28:06 +00:00
Mark Johnston
85e06c728c Set MALLOC_DEBUG_MAXZONES=1 in GENERIC-NODEBUG configurations.
The purpose of this option is to make it easier to track down memory
corruption bugs by reducing the number of malloc(9) types that might
have recently been associated with a given chunk of memory.  However, it
increases fragmentation and is disabled in release kernels.

MFC after:	2 weeks
Sponsored by:	The FreeBSD Foundation
2019-11-18 20:03:28 +00:00
Justin Hibbits
0700132b16 powerpc: Re-add -Wno-redundant-decls to DPAA build flags
Since the DPAA code is from a third party, with minimal edits, there is no
intent to fix these specific warnings at this time.  Hide these warnings to
prevent the noise from hiding real warnings.
2019-11-17 20:49:24 +00:00
Justin Hibbits
5979bb0b7d powerpc: Return SIGILL if DSCR does not exist in m{f,t}spr emulation
Guard against programs written for one powerpc target running on another,
and panicking the system due to not having the DSCR register.
2019-11-17 01:01:02 +00:00
Justin Hibbits
6f83eb8b21 powerpcspe: Don't leak kernel registers in SPE dumps
save_vec_int() for SPE saves off only the high word of the register, leaving
the low word as "garbage", but really containing whatever was in the kernel
register at the time.  This leaks into core dumps, and in a near future
commit also into ptrace.  Instead, save the GPR in the low word in
save_vec_nodrop(), which is used only for core dumps and ptrace.
2019-11-16 16:36:20 +00:00
Justin Hibbits
fe6277692f powerpcspe: Mark asm statement in spe_save_reg_high as clobbering memory
Modern gcc errors that "'vec[0]' is used uninitialized in this function"
without us telling it that vec is clobbered.  Neither clang nor gcc 4.2.1
error on the existing construct.

Submitted by:	bdragon
2019-11-16 16:27:31 +00:00
John Baldwin
e353233118 Add a sv_copyout_auxargs() hook in sysentvec.
Change the FreeBSD ELF ABIs to use this new hook to copyout ELF auxv
instead of doing it in the sv_fixup hook.  In particular, this new
hook allows the stack space to be allocated at the same time the auxv
values are copied out to userland.  This allows us to avoid wasting
space for unused auxv entries as well as not having to recalculate
where the auxv vector is by walking back up over the argv and
environment vectors.

Reviewed by:	brooks, emaste
Tested on:	amd64 (amd64 and i386 binaries), i386, mips, mips64
Sponsored by:	DARPA
Differential Revision:	https://reviews.freebsd.org/D22355
2019-11-15 18:42:13 +00:00
Justin Hibbits
d0bdb11139 atomic: Add atomic_cmpset_masked to powerpc and use it
Summary:
This is a more optimal way of doing atomic_compset_masked() than the
fallback in sys/_atomic_subword.h.  There's also an override for
_atomic_fcmpset_masked_word(), which may or may not be necessary, and is
unused for powerpc.

Reviewed by:	kevans, kib
Differential Revision:	https://reviews.freebsd.org/D22359
2019-11-15 04:33:07 +00:00
Brandon Bergren
6d515b0cc7 powerpc: Kernel fixes for ppc32 and powerpcspe w/ lld
Fix wrong section ordering that was causing a ".got is not contiguous with
other relro sections" lld error. This also brings ldscript.powerpc and
ldscript.powerpcspe closer to ldscript.powerpc64.

Also, remove unnecessary text relocs from the ppc32 AIM trap code.

Approved by: jhibbits (mentor)
Differential Revision: https://reviews.freebsd.org/D22349
2019-11-14 04:34:17 +00:00
Justin Hibbits
cf33fa7e80 powerpc64: Don't guard ISA 3.0 partition table setup with hw_direct_map
PowerISA 3.0 eliminated the 64-bit bridge mode which allowed 32-bit kernels
to run on 64-bit AIM/Book-S hardware.  Since therefore only a 64-bit kernel
can run on this hardware, and 64-bit native always has the direct map, there
is no need to guard it.
2019-11-13 02:22:00 +00:00
Justin Hibbits
56ee6bb943 powerpc: Don't savectx() twice in IPI_STOP handler
We already save context in stoppcbs[] array, so there's no need to also save it
in the PCB, it won't be used.
2019-11-13 02:16:24 +00:00
Justin Hibbits
0b4753405b powerpc64/powernv: Use OPAL call for non-POWER8 PCI TCE reset
According to the OPAL documentation, only the POWER8 (PHB3) should use
the register write TCE reset method.  All others should use the OPAL
call.

On POWER9 the call is semantically identical to the register write, with
a wait for completion.
2019-11-10 04:24:36 +00:00
Justin Hibbits
55073c7837 powerpc/booke: Only handle kernel page faults in KVA range
The memory range between VM_MAXUSER_ADDRESS and VM_MIN_KERNEL_ADDRESS is
reserved for devices currently, which are always mapped in TLB1, and
therefore do not exist in the kernel page table.  Any page fault in this
range is therefore automatically a fatal fault.
2019-11-08 04:26:19 +00:00
Justin Hibbits
d3895bffd9 powerpc/booke: Make the TLB save area and mask match
Since TLB_MAXNEST is 3, the insert mask should only be 2 bits.  Given that 2
bits counts to 4, and that we already have plenty of space wasted in
padding, make the nest level 4 to match the mask.
2019-11-08 03:45:13 +00:00
Justin Hibbits
9e2b2d6996 powerpc/mpc85xx: Add MSI support for Freescale PowerPC SoCs
Freescale SoCs use a set of IRQs at the high end of the OpenPIC IRQ
list, not counted in the NIRQs of the Feature reporting register.  Some
SoCs include a MSI inbound window in the PCIe controller configuration
registers as well, but some don't.  Currently, this only handles the
SoCs *with* the MSI window.

There are 256 MSIs per MSI bank (32 per MSI IRQ, 8 IRQs per MSI bank).
The P5020 has 3 banks, yielding up to 768 MSIs; older SoCs have only one
bank.
2019-11-08 03:36:19 +00:00
Justin Hibbits
b5d5429449 powerpc/booke: Fix pmap_mapdev_attr() for multi-TLB1 entry mappings
Also, fix pmap_change_attr() to ignore non-kernel mappings.

* Fix a masking bug in mmu_booke_mapdev_attr() which caused it to align
  mappings to the smallest mapping alignment, instead of the largest.  This
  caused mappings to be potentially pessimally aligned, using more TLB
  entries than necessary.
* Return existing mappings from mmu_booke_mapdev_attr() that span more than
  one TLB1 entry.  The drm-current-kmod drivers map discontiguous segments
  of the GPU, resulting in more than one TLB entry being used to satisfy the
  mapping.
* Ignore non-kernel mappings in mmu_booke_change_attr().  There's a bug in
  the linuxkpi layer that causes it to actually try to change physical
  address mappings, instead of virtual addresses.  amd64 doesn't encounter
  this because it ignores non-kernel mappings.

With this it's possible to use drm-current-kmod on Book-E.
2019-11-06 04:40:12 +00:00
Justin Hibbits
730de0f746 powerpc/pmap: Make use of tlb1_mapin_region in pmap_mapdev_attr()
tlb1_mapin_region() and pmap_mapdev_attr() do roughly the same thing -- map
a chunk of physical address space(memory or MMIO) into virtual, but do it in
differing ways.  Unify the code, settling on pmap_mapdev_attr()'s algorithm,
to simplify and unify the logic.  This fixes a bug with growing the kernel
mappings in mmu_booke_bootstrap(), where part of the mapping was not getting
done, leading to a hang when the unmapped VAs were accessed.
2019-11-04 00:35:40 +00:00
Brandon Bergren
2128001171 powerpc: Add display of raw instruction values to x/I in ddb.
The "alternate format" character 'I' previously had the same behavior as
the "display as an instruction" character 'i'. With this change, it will now
prefix each disassembled instruction with the raw hex value.

As PowerPC instructions are always 32 bits and always aligned, and there are
no alternate modes that would affect instruction decoding or display, this
seemed to me to be the obvious interpretation of "alternate format".

Approved by: jhibbits (mentor)
Differential Revision: https://reviews.freebsd.org/D22223
2019-11-03 02:18:45 +00:00
Brandon Bergren
2276d9024d powerpc: Fix incorrect disassembly of the cntlzw instruction in ddb.
Noticed while comparing disassembly between ddb and objdump.

Approved by: jhibbits (mentor)
Differential Revision: https://reviews.freebsd.org/D22121
2019-11-03 01:52:50 +00:00
Brandon Bergren
ab3f2a3861 Add support for building Book-E kernels with clang/lld.
This involved several changes:

* Since lld does not like text relocations, replace SMP boot page text relocs
in booke/locore.S with position-independent math, and track the virtual base
in the SMP boot page header.

* As some SPRs are interpreted differently on clang due to the way it handles
platform-specific SPRs, switch m*dear and m*esr mnemonics out for regular
m*spr. Add both forms of SPR_DEAR to spr.h so the correct encoding is selected.

* Change some hardcoded 32 bit things in the boot page to be pointer-sized, and
fix alignment.

* Fix 64-bit build of booke/pmap.c when enabling pmap debugging.

Additionally, I took the opportunity to document how the SMP boot page works.

Approved by: jhibbits (mentor)
Differential Revision: https://reviews.freebsd.org/D21999
2019-11-02 21:15:56 +00:00
Justin Hibbits
b144826d79 powerpc/mpc85xx: Set description for the MPC85xx RC bridge 2019-11-02 02:24:53 +00:00
Justin Hibbits
8b079fcca7 powerpc/booke: Fix TLB1 entry accounting
It's possible, with per-CPU mappings, for TLB1 indices to get out of sync.
This presents a problem when trying to insert an entry into TLB1 of all
CPUs.  Currently that's done by assuming (hoping) that the TLBs are
perfectly synced, and inserting to the same index for all CPUs.  However,
with aforementioned private mappings, this can result in overwriting
mappings on the other CPUs.

An example:

    CPU0                    CPU1
    <setup all mappings>    <idle>
        3 private mappings
      kick off CPU 1
                            initialize shared mappings (3 indices low)
                            Load kernel module, triggers 20 new mappings
      Sync mappings at N-3
                            initialize 3 private mappings.

At this point, CPU 1 has all the correct mappings, while CPU 0 is missing 3
mappings that were shared across to CPU 1.  When CPU 0 tries to access
memory in one of the overwritten mappings, it hangs while tripping through
the TLB miss handler.  Device mappings are not stored in any page table.

This fixes by introducing a '-1' index for tlb1_write_entry_int(), so each
CPU searches for an available index private to itself.

MFC after:	3 weeks
2019-11-01 02:55:58 +00:00
Leandro Lupori
a8a6278ea0 Fix GDB machdep code for PPC/PPC64
There was a couple issues with GDB machdep code for PPC/PPC64, the main ones being:
- wrong register sizes being returned
- pcb_context index was wrong (this affects all PPC variants)

Reviewed by:	jhibbits
Differential Revision:	https://reviews.freebsd.org/D22201
2019-10-31 12:03:47 +00:00
Leandro Lupori
d7271ace1d [PPC64] Fix trapstk overflow
In some scenarios, the 4K trapstk may overflow, corrupting tmpstk.

This was observed during remote debugging, with the following steps:

At remote host (R):
- enter kdb during boot
- switch to gdb backend

At local host (L):
- attach gdb to R
- try to read an invalid memory position

At R:
- a DSI trap occurs and kdb restarts (all this occurs on trapstk)
- while printing the stacktrace, trapstk overflows and corrupts tmpstk

Reviewed by:	jhibbits
Differential Revision:	https://reviews.freebsd.org/D22200
2019-10-31 11:59:00 +00:00
Justin Hibbits
6087140822 powerpc/booke: Simplify the MPC85XX PCIe root complex driver
Summary:
Due to bugs in the enumeration code, fsl_pcib_init() was not configuring
sub-bridges properly, so devices hanging off a separate bridge would not
be found.  Since the generic PCI code already supports probing child
buses, just delete this code and initialize only the device itself,
letting the generic code handle all the additional probing and
initializing.

This also deletes setup for some PCI peripherals found on some MPC85XX
evaluation boards.  The code can be resurrected if needed, but overly
complicated this code in the first place.

Reviewed by:	bdragon
Differential Revision:	https://reviews.freebsd.org/D22050
2019-10-24 03:51:33 +00:00
Justin Hibbits
dc2b5bb497 powerpc/booke: Fix Book-E boot post-minidump
r353489 added minidump support for powerpc64, but it added a dependency on
the dump_avail array.  Leaving it uninitialized caused breakage in late
boot.  Initialize dump_avail, even though the 64-bit booke pmap doesn't yet
support minidumps, but will in the future.
2019-10-23 00:31:19 +00:00
Leandro Lupori
f2c7768cce [PPC] Avoid underflows in NUMA domains
On POWER8 systems with only one memory domain, the "ibm,associativity"
number that corresponds to it is 0, unlike POWER9 systems with two
or more domains, in which the minimum value is 1.

In POWER8 case, subtracting 1 causes an underflow on the unsigned domain
variable and a subsequent index out-of-bounds access.

Reviewed by:	jhibbits
Tested by:	bdragon, luporl
2019-10-22 18:28:58 +00:00
Gleb Smirnoff
38e1a6585b Convert to if_foreach_llmaddr() KPI. 2019-10-21 18:13:37 +00:00
Gleb Smirnoff
d01532086c Convert to if_foreach_llmaddr() KPI. 2019-10-21 18:13:33 +00:00
Leandro Lupori
95ca4720f0 [PPC64] Add minidump support to PowerNV
Implementation of PowerNV specific minidump code.

Reviewed by:	jhibbits
Differential Revision:	https://reviews.freebsd.org/D21643
2019-10-21 11:56:57 +00:00
Justin Hibbits
1cf56858b0 powerpc/booke: Don't zero MAS8, it's unnecessary
MAS8 is hypervisor privileged, defining the logical partition (VM) to
operate on for TLB accesses.  It's already guaranteed to be cleared when
booting bare metal (bootloader needs it zeroed to work), and we can't touch
it from a guest.  Assume that if/when we eventually port bhyve to PowerPC
(and Book-E) the hypervisor module will take care of managing MAS8.  This
saves several (tens) of clocks on each TLB miss.

MFC after:	2 weeks
2019-10-20 15:50:33 +00:00
Justin Hibbits
4ffdb9f2a4 powerpc/booke pmap: Fix printf format type warnings 2019-10-19 16:09:06 +00:00
Justin Hibbits
f1d4707c31 powerpc/aim: Fix comment typo 2019-10-19 02:47:32 +00:00
Justin Hibbits
a877eb6143 powerpc/mpc85xx: Replace global PCI config mutex with per-controller mutex
PCI controllers need to enforce exclusive config register access on their
own bus, not between all buses.
2019-10-19 01:07:35 +00:00
Conrad Meyer
7790c8c199 Split out a more generic debugnet(4) from netdump(4)
Debugnet is a simplistic and specialized panic- or debug-time reliable
datagram transport.  It can drive a single connection at a time and is
currently unidirectional (debug/panic machine transmit to remote server
only).

It is mostly a verbatim code lift from netdump(4).  Netdump(4) remains
the only consumer (until the rest of this patch series lands).

The INET-specific logic has been extracted somewhat more thoroughly than
previously in netdump(4), into debugnet_inet.c.  UDP-layer logic and up, as
much as possible as is protocol-independent, remains in debugnet.c.  The
separation is not perfect and future improvement is welcome.  Supporting
INET6 is a long-term goal.

Much of the diff is "gratuitous" renaming from 'netdump_' or 'nd_' to
'debugnet_' or 'dn_' -- sorry.  I thought keeping the netdump name on the
generic module would be more confusing than the refactoring.

The only functional change here is the mbuf allocation / tracking.  Instead
of initiating solely on netdump-configured interface(s) at dumpon(8)
configuration time, we watch for any debugnet-enabled NIC for link
activation and query it for mbuf parameters at that time.  If they exceed
the existing high-water mark allocation, we re-allocate and track the new
high-water mark.  Otherwise, we leave the pre-panic mbuf allocation alone.
In a future patch in this series, this will allow initiating netdump from
panic ddb(4) without pre-panic configuration.

No other functional change intended.

Reviewed by:	markj (earlier version)
Some discussion with:	emaste, jhb
Objection from:	marius
Differential Revision:	https://reviews.freebsd.org/D21421
2019-10-17 16:23:03 +00:00
Mark Johnston
01cef4caa7 Remove page locking from pmap_mincore().
After r352110 the page lock no longer protects a page's identity, so
there is no purpose in locking the page in pmap_mincore().  Instead,
if vm.mincore_mapped is set to the non-default value of 0, re-lookup
the page after acquiring its object lock, which holds the page's
identity stable.

The change removes the last callers of vm_page_pa_tryrelock(), so
remove it.

Reviewed by:	kib
Sponsored by:	Netflix
Differential Revision:	https://reviews.freebsd.org/D21823
2019-10-16 22:03:27 +00:00
Mark Johnston
b4efea53e0 Clear PGA_WRITEABLE in moea_pvo_remove().
moea_pvo_remove() might remove the last mapping of a page, in which case
it is clearly no longer writeable.  This can happen via pmap_remove(),
or when a CoW fault removes the last mapping of the old page.

Reported and tested by:	bdragon
Reviewed by:	alc, bdragon, kib
MFC after:	1 week
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D22044
2019-10-16 15:50:12 +00:00
Konstantin Belousov
2a499f92ba Fix assert in PowerPC pmaps after introduction of object busy.
The VM_PAGE_OBJECT_BUSY_ASSERT() in pmap_enter() implementation should
be only asserted when the code is executed as result of pmap_enter(),
not when the same code is entered from e.g. pmap_enter_quick().  This
is relevant for all PowerPC pmap variants, because mmu_*_enter() is
used as the backend, and assert is located there.

Add a PowerPC private pmap_enter() PMAP_ENTER_QUICK_LOCKED flag to
indicate that the call is not from pmap_enter().  For non-quick-locked
calls, assert that the object is locked.

Reported and tested by:	bdragon
Reviewed by:	alc, bdragon, markj
Sponsored by:	The FreeBSD Foundation
Differential revision:	https://reviews.freebsd.org/D22041
2019-10-16 07:09:15 +00:00
Justin Hibbits
d70b36edb5 powerpc/mpc85xx: Fix function type for fsl_pcib_error_intr()
Since it's only called as an interrupt handler, fsl_pcib_eror_intr() should just
match the driver_intr_t type.

Reported by:	bdragon
2019-10-16 03:03:59 +00:00
Justin Hibbits
34ed25a82e powerpc: Add AmigaOne platform, a subclass of MPC85xx
Summary:
The AmigaOne platform, encompassing the X5000 and A1222 at this time, is
based on the mpc85xx platform, but includes some things not listed in
the device tree.  Some custom devices, like CPLD, could be added to the
device tree with an overlay, or other means.  However, some cannot
easily be done, such as the power button interrupt.

The directory will also become a location to add AmigaOne platform drivers,
such as the aforementioned CPLD, and its children.

Reviewed by:	bdragon
Differential Revision:	https://reviews.freebsd.org/D21829
2019-10-16 00:38:50 +00:00
Jeff Roberson
638f867814 (6/6) Convert pmap to expect busy in write related operations now that all
callers hold it.

This simplifies pmap code and removes a dependency on the object lock.

Reviewed by:    kib, markj
Tested by:      pho
Sponsored by:   Netflix, Intel
Differential Revision:	https://reviews.freebsd.org/D21596
2019-10-15 03:51:46 +00:00
Jeff Roberson
205be21d99 (3/6) Add a shared object busy synchronization mechanism that blocks new page
busy acquires while held.

This allows code that would need to acquire and release a very large number
of page busy locks to use the old mechanism where busy is only checked and
not held.  This comes at the cost of false positives but never false
negatives which the single consumer, vm_fault_soft_fast(), handles.

Reviewed by:    kib
Tested by:      pho
Sponsored by:   Netflix, Intel
Differential Revision:	https://reviews.freebsd.org/D21592
2019-10-15 03:41:36 +00:00
Justin Hibbits
9551397f51 powerpc/atomic: Fix atomic_cmpset_rel()
Need a release barrier, not an acquire barrier, else bad things happen.
2019-10-15 03:37:21 +00:00
Leandro Lupori
fa14f7f1b7 Fix powerpc/powerpcspe builds
Revision 353489 introduced some new function calls in common powerpc code,
but these must be called only on powerpc64.
2019-10-14 19:06:17 +00:00
Leandro Lupori
0ecc478b74 [PPC64] Initial kernel minidump implementation
Based on POWER9BSD implementation, with all POWER9 specific code removed and
addition of new methods in PPC64 MMU interface, to isolate platform specific
code. Currently, the new methods are implemented on pseries and PowerNV
(D21643).

Reviewed by:	jhibbits
Differential Revision:	https://reviews.freebsd.org/D21551
2019-10-14 13:04:04 +00:00
Justin Hibbits
ec17d5e06a powerpc/pmap: Tighten condition for removing tracked pages in Book-E pmap
There are cases where there's no vm_page_t structure for a given physical
address, such as the CCSR.  In this case, trying to obtain the
md.page_tracked struct member would lead to a NULL dereference, and panic.
Tighten this up by checking for kernel_pmap AND that the page structure
actually exists before dereferencing.  The flag can only be set when it's
tracked in the kernel pmap anyway.

MFC after:	3 weeks
2019-10-13 19:33:00 +00:00
Justin Hibbits
84046d16eb powerpc: Implement atomic_(f)cmpset_ for short and char
|
This adds two implementations for each atomic_fcmpset_ and atomic_cmpset_
short and char functions, selectable at compile time for the target
architecture.  By default, it uses a generic shift-and-mask to perform atomic
updates to sub-components of 32-bit words from <sys/_atomic_subword.h>.
However, if ISA_206_ATOMICS is defined it uses the ll/sc instructions for
halfword and bytes, introduced in PowerISA 2.06.  These instructions are
supported by all IBM processors from POWER7 on, as well as the Freescale/NXP
e6500 core.  Although the e5500 and e500mc both implement PowerISA 2.06 they
do not implement these instructions.

As part of this, clean up the atomic_(f)cmpset_acq and _rel wrappers, by
using macros to reduce code duplication.

ISA_206_ATOMICS requires clang or newer binutils (2.20 or later).

Differential Revision:	https://reviews.freebsd.org/D21682
2019-10-08 01:36:34 +00:00
Justin Hibbits
02e7952133 powerpc64/pmap: Fix release order to match lock order in moea64_enter()
Page PV lock is always taken first, so should be released last.  This also
(trivially) shortens the hold time of the pmap lock.

Submitted by:	mjg
2019-10-07 02:36:42 +00:00
Justin Hibbits
d137ff5521 powerpc/pmap64: Properly parenthesize PV_LOCK_COUNT macros
As pointed out by mjg, without the parentheses the calculations done against
these macros are incorrect, resulting in only 1/3 of locks being used.

Reported by:	mjg
2019-10-06 19:11:01 +00:00
Justin Hibbits
69cea06f34 powerpc/booke64: Align initial stack setting to match that of aim64's
Clang9/LLD9 appears to get quite confused with the instruction stream used
to obtain the tmpstack pointer, almost as though it thinks this is a C
function, so tries to optimize it.  Since the AIM64 method doesn't use the
TOC to obtain the tmpstack, just follow that model, and lld won't get
confused.

Reported by:	bdragon
MFC after:	2 weeks
2019-09-28 03:33:07 +00:00
Konstantin Belousov
df08823d07 Improve MD page fault handlers.
Centralize calculation of signal and ucode delivered on unhandled page
fault in new function vm_fault_trap().  MD trap_pfault() now almost
always uses the signal numbers and error codes calculated in
consistent MI way.

This introduces the protection fault compatibility sysctls to all
non-x86 architectures which did not have that bug, but apparently they
were already much more wrong in selecting delivered signals on
protection violations.

Change the delivered signal for accesses to mapped area after the
backing object was truncated.  According to POSIX description for
mmap(2):
   The system shall always zero-fill any partial page at the end of an
   object. Further, the system shall never write out any modified
   portions of the last page of an object which are beyond its
   end. References within the address range starting at pa and
   continuing for len bytes to whole pages following the end of an
   object shall result in delivery of a SIGBUS signal.

   An implementation may generate SIGBUS signals when a reference
   would cause an error in the mapped object, such as out-of-space
   condition.
Adjust according to the description, keeping the existing
compatibility code for SIGSEGV/SIGBUS on protection failures.

For situations where kernel cannot handle page fault due to resource
limit enforcement, SIGBUS with a new error code BUS_OBJERR is
delivered.  Also, provide a new error code SEGV_PKUERR for SIGSEGV on
amd64 due to protection key access violation.

vm_fault_hold() is renamed to vm_fault().  Fixed some nits in
trap_pfault()s like mis-interpreting Mach errors as errnos.  Removed
unneeded truncations of the fault addresses reported by hardware.

PR:	211924
Reviewed by:	alc
Discussed with:	jilles, markj
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D21566
2019-09-27 18:43:36 +00:00
Mark Johnston
b119329d81 Complete the removal of the "wire_count" field from struct vm_page.
Convert all remaining references to that field to "ref_count" and update
comments accordingly.  No functional change intended.

Reviewed by:	alc, kib
Sponsored by:	Intel, Netflix
Differential Revision:	https://reviews.freebsd.org/D21768
2019-09-25 16:11:35 +00:00
Justin Hibbits
e44ed9d3d4 powerpc/atomic: Follow recommendations on atomic primitive comparisons
Both IBM and Freescale programming examples presume the cmpset operands will
favor equal, and pessimize the non-equal case instead.  Do the same for
atomic_cmpset_* and atomic_fcmpset_*.  This slightly pessimizes the failure
case, in favor of the success case.

MFC after:	3 weeks
2019-09-25 01:39:58 +00:00
Justin Hibbits
0cfa351ec5 powerpc: Allocate DPCPU block from domain-local memory
This should improve NUMA scalability a little, by binding to the CPU's NUMA
domain.  This matches what's done on amd64.
2019-09-25 01:23:08 +00:00
Mark Johnston
e8bcf6966b Revert r352406, which contained changes I didn't intend to commit. 2019-09-16 15:04:45 +00:00
Mark Johnston
41fd4b9422 Fix a couple of nits in r352110.
- Remove a dead variable from the amd64 pmap_extract_and_hold().
- Fix grammar in the vm_page_wire man page.

Reported by:	alc
Reviewed by:	alc, kib
Sponsored by:	Netflix
Differential Revision:	https://reviews.freebsd.org/D21639
2019-09-16 15:03:12 +00:00
Justin Hibbits
1c56203bcf powerpc64/powernv: Add opal NVRAM driver for PowerNV systems
Add a very basic NVRAM driver for OPAL which can be used by the IBM
powerpc-utils nvram utility, not to be confused with the base nvram utility,
which only operates on powermac_nvram.

The IBM utility handles all partitions itself, treating the nvram device as
a plain store.

An alternative would be to manage partitions in the kernel, and augment the
base nvram utility to deal with different backing stores, but that
complicates the driver significantly.  Instead, present the same interface
IBM's utlity expects, and we get the usage for free.

Tested by:	bdragon
2019-09-14 03:30:34 +00:00
Mark Johnston
fee2a2fa39 Change synchonization rules for vm_page reference counting.
There are several mechanisms by which a vm_page reference is held,
preventing the page from being freed back to the page allocator.  In
particular, holding the page's object lock is sufficient to prevent the
page from being freed; holding the busy lock or a wiring is sufficent as
well.  These references are protected by the page lock, which must
therefore be acquired for many per-page operations.  This results in
false sharing since the page locks are external to the vm_page
structures themselves and each lock protects multiple structures.

Transition to using an atomically updated per-page reference counter.
The object's reference is counted using a flag bit in the counter.  A
second flag bit is used to atomically block new references via
pmap_extract_and_hold() while removing managed mappings of a page.
Thus, the reference count of a page is guaranteed not to increase if the
page is unbusied, unmapped, and the object's write lock is held.  As
a consequence of this, the page lock no longer protects a page's
identity; operations which move pages between objects are now
synchronized solely by the objects' locks.

The vm_page_wire() and vm_page_unwire() KPIs are changed.  The former
requires that either the object lock or the busy lock is held.  The
latter no longer has a return value and may free the page if it releases
the last reference to that page.  vm_page_unwire_noq() behaves the same
as before; the caller is responsible for checking its return value and
freeing or enqueuing the page as appropriate.  vm_page_wire_mapped() is
introduced for use in pmap_extract_and_hold().  It fails if the page is
concurrently being unmapped, typically triggering a fallback to the
fault handler.  vm_page_wire() no longer requires the page lock and
vm_page_unwire() now internally acquires the page lock when releasing
the last wiring of a page (since the page lock still protects a page's
queue state).  In particular, synchronization details are no longer
leaked into the caller.

The change excises the page lock from several frequently executed code
paths.  In particular, vm_object_terminate() no longer bounces between
page locks as it releases an object's pages, and direct I/O and
sendfile(SF_NOCACHE) completions no longer require the page lock.  In
these latter cases we now get linear scalability in the common scenario
where different threads are operating on different files.

__FreeBSD_version is bumped.  The DRM ports have been updated to
accomodate the KPI changes.

Reviewed by:	jeff (earlier version)
Tested by:	gallatin (earlier version), pho
Sponsored by:	Netflix
Differential Revision:	https://reviews.freebsd.org/D20486
2019-09-09 21:32:42 +00:00
Justin Hibbits
e0b5c15c54 powerpc64/pmap: Fix a WITNESS error in alloc_pvo_entry()
We only call alloc_pvo_entry() with M_WAITOK from one location.  However,
this can be called while holding nonsleepable locks.  Rather than passing
M_WAITOK down, use vm_wait() and loop.
2019-09-06 03:02:12 +00:00
Justin Hibbits
197a7e48c9 powerpc64/pmap: Simplify the code path for moea64_pte_replace_native()
Summary:
MOEA64_PTE_REPLACE() is called often with the pmap lock held, and
sometimes with the page pv lock held.  The less work done while holding
a lock, the better.  Since we are intending to replace the same PTE
(same hash index), we don't need to recalculate anything, just flat
replace the PTE.  This cuts more than 200 instructions off the
invalidating code path.  In addition, we don't need to replace a PTE
that's not occupied by this PVO.

Reviewed by:	luporl
Differential Revision:	https://reviews.freebsd.org/D21515
2019-09-06 02:45:46 +00:00
Konstantin Belousov
a2a0f90654 Centralize __pcpu definitions.
Many extern struct pcpu <something>__pcpu declarations were
copied/pasted in sources.  The issue is that the definition is MD, but
it cannot be provided by machine/pcpu.h due to actual struct pcpu
defined in sys/pcpu.h later than the inclusion of machine/pcpu.h.
This forced the copying when other code needed direct access to
__pcpu.  There is no way around it, due to machine/pcpu.h supplying
part of struct pcpu fields.

To work around the problem, add a new machine/pcpu_aux.h header, which
should fill any needed MD definitions after struct pcpu definition is
completed. This allows to remove copies of __pcpu spread around the
source.  Also on x86 it makes it possible to remove work arounds like
OFFSETOF_CURTHREAD or clang specific warnings supressions.

Reported and tested by:	lwhsu, bcran
Reviewed by:	imp, markj (previous version)
Discussed with:	jhb
Sponsored by:	The FreeBSD Foundation
Differential revision:	https://reviews.freebsd.org/D21418
2019-08-29 07:25:27 +00:00
Justin Hibbits
7038069e9c Revert a part of r350883 that should never have gone in
The wire_count change is not part of the unification, and doesn't even make
sense.

Reported by:	markj
2019-08-27 14:04:32 +00:00
Justin Hibbits
8da08d5123 powerpc/booke: Clean up pmap a little for 64-bit
64-bit Book-E pmap doesn't need copy and zero bounce pages, nor the mutex.
Don't initialize them or reserve space for them.
2019-08-25 20:11:35 +00:00
Justin Hibbits
e7f2151c75 powerpc/booke: Use the DMAP if possible in pmap_map()
This avoids unnecessary TLB usage for statically mapped regions, such as
vm_page_array.
2019-08-25 20:08:48 +00:00
Warner Losh
7d65d42046 Fix bogusly declared WERRORs in kernel build
Many arm kernel configs bogusly specified WERROR=-Werror. There's no
reason for this because the default is that and there's no reason to
override. These date from a time when we needed to add additional
warning->error suppression. They are obsolete and were cut and paste
propagated from file to file.

Comment out all the WERROR=.... lines in powerpc. They aren't bogus,
but were appropriate for the old defaults for gcc4.2.1. Now that we've
made the policy decision to suppress -Werror by default on these
platforms, it is appropriate to comment these out. People wishing to
fix these errors can still un-comment them out, or say WERROR=-Werror
on the command line.

Fix two instances (cut and paste propagation) of hard-coded -Werror
in x86 code. Replace with ${WERROR} instead. This is a no-op change
except for people who build WERROR=-Wno-error :).

This should fix tinderbox / CI breakage.
2019-08-25 19:39:31 +00:00
Justin Hibbits
6793e5b23d powerpc: Link Book-E kernels at the same address as AIM kernels
Summary:
Reduce the diff between AIM and Book-E even more.  This also cleans up
vmparam.h significantly.

Reviewed by:	luporl
Differential Revision:	https://reviews.freebsd.org/D21301
2019-08-20 01:26:02 +00:00
Jeff Roberson
2194393787 Move phys_avail definition into MI code. It is consumed in the MI layer and
doing so adds more flexibility with less redundant code.

Reviewed by:	jhb, markj, kib
Sponsored by:	Netflix
Differential Revision:	https://reviews.freebsd.org/D21250
2019-08-16 00:45:14 +00:00
Justin Hibbits
141a0ab012 powerpc/pmap: Enable UMA_MD_SMALL_ALLOC for 64-bit booke
The only thing blocking UMA_MD_SMALL_ALLOC from working on 64-bit booke
powerpc was a missing check in pmap_kextract().  Adding DMAP handling into
pmap_kextract(), we can now use UMA_MD_SMALL_ALLOC.  This should improve
performance and stability a bit, since DMAP is always mapped in TLB1, so
this relieves pressure on TLB0.

MFC after:	3 weeks
2019-08-15 03:42:15 +00:00
Warner Losh
77af66f0d4 Fix powerpc LINT build
tcpratelimit isn't supported as there's now atomic_add_64, so add it to the exclusion list
Add comment for why PPC_PROBE_CHIPSET is on the list
Remove UKBD_DFLT_KEYMAP now that ukbd works on all platforms.
2019-08-12 23:25:21 +00:00
Warner Losh
c1ab04fce5 Floppy driver really only works on x86
Move the floppy driver to the x86 specific notes file.

Reviewed by: jhb, manu, jhibbits, emaste
Differential Revision: https://reviews.freebsd.org/D21208
2019-08-12 22:58:50 +00:00
Warner Losh
99e1c5ab38 Move sc out of the global file
x86 needs sc, as does sparc64. powerpc doesn't use it by default, but some old
powermac notebooks do not work with vt yet for reasons unknonw. Even so, I've
removed it from powerpc LINT. It's not in daily use there, and the intent is to
100% switch to vt now that it works for that platform to limit support burden.

All the other architectures omit some or all of the screen savers from their
lint config. Move them to the x86 NOTES files and remove the exclusions. This
reduces slightly the number of savers sparc64 compiles, but since they are in
GENERIC, the overage is adequate and if someone reaelly wants to sort them out
in sparc64 they can sweat the details and the testing.

Reviewed by: jhb (earlier version), manu (earlier version), jhibbits
Differential Revision: https://reviews.freebsd.org/D21233
2019-08-12 22:58:44 +00:00
Leandro Lupori
26b6a67b98 Fix style and clarify comment
Fix code style in proc.h and clarify comment about empty structs.
2019-08-12 19:44:57 +00:00
Leandro Lupori
4e8872c800 [ppc] avoid empty mdproc struct
Avoid empty structs, that have undefined behavior in C99 and
make compilers complain about it
(empty struct has size 0 in C, size 1 in C++).

Reviewed by:	jhibbits
Differential Revision:	https://reviews.freebsd.org/D21231
2019-08-12 17:18:20 +00:00
Leandro Lupori
b501589d81 [PPC64] Save FPU registers before enabling VSX
Fixed trap handler logic, in order to make it save FPU registers,
if FPU is enabled, before enabling VSX. Without this change, FPU
register contents were being lost when set before VSX was enabled.
2019-08-12 12:51:47 +00:00
Justin Hibbits
3be09f300d powerpc: Unify pmap definitions between AIM and Book-E
This is part 2 of r347078, pulling the page directory out of the Book-E
pmap.  This breaks KBI for anything that uses struct pmap (such as vm_map)
so any modules that access this must be rebuilt.
2019-08-12 03:03:56 +00:00
Justin Hibbits
937e8f20af powerpc/pmap: Minor optimizations to 64-bit booke pmap
Don't recalculate the VM page of the page table pages, just pass them down
to free.  Also, use the pmap's page zero function instead of bzero().
2019-08-08 03:18:35 +00:00
Justin Hibbits
8b1531eca8 Fix build from r350622
It helps if my local kernel build has INVARIANTS.
2019-08-06 03:49:40 +00:00
Justin Hibbits
dc825fed55 powerpc/pmap: Simplify Book-E 64-bit page table management
There is no need for the 64-bit pmap to have a fixed number of page table
buffers.  Since the 64-bit pmap has a DMAP, we can effectively have user
page tables limited only by total RAM size.
2019-08-06 03:16:06 +00:00
Justin Hibbits
2b50838563 powerpc: Get 32-bit AIM building with secure-PLT
The last few changes needed before 32-bit AIM builds with secure-PLT with
base GCC.  Because ofwcall32.S and swtch32.S were branching to the GOT it
could not use secure PLT.
2019-08-05 01:37:18 +00:00
Justin Hibbits
69a277d98e powerpc: Enable the BUS_DMA_NOCACHE flag handling
The flag handling was committed commented out 7 years ago.  It works, and is
needed for LinuxKPI-based DRM drivers.

Also mark a local as potentially unusable, as it's only really used when KTR
is enabled.

Submitted by:	mmacy
2019-08-04 19:25:23 +00:00
Justin Hibbits
84ce4f0375 powerpc/powernv: Fix OPAL cfgread/cfgwrite error handling
Freeze clearing needs to heppen any time OPAL reads return either an error
(except OPAL_HARDWARE), AND any time it returns 0xff for all bytes.

For cfgwrite, any error that's not OPAL_HARDWARE should be cleaned up.
2019-08-03 01:55:51 +00:00
Justin Hibbits
0effb2ccf3 powerpc/powernv: Only clear EEH freeze for some errors
Only clear an EEH freeze if an error occurs.  However, if an OPAL_HARDWARE
error is returned, this indicates a hardware failure which cannot be
unfrozen, and instead needs a hardware reset.  Attempting to unfreeze a
broken PCH will result in console spam for each attempt.  To avoid the spam,
just don't do it.
2019-08-01 03:59:25 +00:00
Justin Hibbits
be01018809 powerpc64/mmu: Use a SLIST for the PVO delete list, instead of a RB_TREE
Summary:
Although it's convenient to reuse the pvo_plist for deletion, RB_TREE
insertion and removal is not free, and can result in a lot of extra work
to rebalance the tree.  Instead, use a SLIST as a LIFO delete queue,
which gives us almost free insertion, deletion, and traversal.

Reviewed by:	luporl
Differential Revision: https://reviews.freebsd.org/D21061
2019-08-01 03:55:58 +00:00
Leandro Lupori
6962841780 powerpc: Improve pvo allocation code
Added allocation retry loop in alloc_pvo_entry(), to wait for
memory to become available if the caller specifies the M_WAITOK flag.

Also, the loop in moa64_enter() was removed, as moea64_pvo_enter()
never returns ENOMEM. It is alloc_pvo_entry() memory allocation that
can fail and must be retried.

Reviewed by:	jhibbits
Differential Revision:	https://reviews.freebsd.org/D21035
2019-07-25 15:27:05 +00:00
Justin Hibbits
7c382eea30 powerpc/pmap64: Make moea64 statistics optional
Summary:
It turns out statistics accounting is very expensive in the pmap driver,
and doesn't seem necessary in the common case.  Make this optional
behind a MOEA64_STATS #define, which one can set if they really need
statistics.

This saves ~7-8% on buildworld time on a POWER9.

Found by bdragon.

Reviewed by:	luporl
Differential Revision: https://reviews.freebsd.org/D20903
2019-07-25 03:47:27 +00:00
Justin Hibbits
b75bd60a04 powerpc: Unbreak 64-bit pmap from 350206
oldpvo is never explicitly NULL'd by moea64_pvo_enter(), so don't check for
NULL to do anything, only check error.

PR:		239372
Reported by:	Francis Little
2019-07-22 22:59:50 +00:00
Justin Hibbits
5db86748b5 powerpc64/mmu: Make moea64_pvo_enter() return if an entry already exists
Summary:
Instead of searching for a PVO entry before adding, take advantage of
the fact that RB_INSERT() returns NULL if it inserts, and the existing entry if
an entry exists, without inserting a new entry.  This saves an extra tree
traversal in the cases where the PVO does not exist.

Reviewed by:	luporl
Differential Revision: https://reviews.freebsd.org/D20944
2019-07-22 03:11:54 +00:00
Justin Hibbits
b982c7ee20 powerpc: Remove an unnecessary #ifdef guard from slb.c
slb.c is only compiled for powerpc64, so no need for the #ifdef in this block.
2019-07-21 03:19:54 +00:00
Justin Hibbits
cafceaebea powerpc/SPE: Enable SPV bit for EFSCFD instruction emulation
EFSCFD (floating point single convert from double) emulation requires saving
the high word of the register, which uses SPE instructions.  Enable the SPE
to avoid an SPV Unavailable exception.

MFC after:	1 week
2019-07-20 18:22:01 +00:00
Justin Hibbits
8d00d89228 powerpc: Fix casueword(9) post-r349951
'=' asm constraint marks a variable as write-only.  Because of this, gcc
throws away the initialization of 'res', causing garbage to be returned if
the CAS was successful.  Use '+' to mark res as read/write, so that the
initialization stays in the generated asm.  Also, fix the reservation
clearing stwcx store index register in casueword32, and only do the dummy
store when needed, skip it if the real store has already succeeded.
2019-07-16 03:55:27 +00:00
John Baldwin
c18ca74916 Don't pass error from syscallenter() to syscallret().
syscallret() doesn't use error anymore.  Fix a few other places to permit
removing the return value from syscallenter() entirely.
- Remove a duplicated assertion from arm's syscall().
- Use td_errno for amd64_syscall_ret_flush_l1d.

Reviewed by:	kib
MFC after:	1 month
Sponsored by:	DARPA
Differential Revision:	https://reviews.freebsd.org/D2090
2019-07-15 21:25:16 +00:00
Justin Hibbits
07b57507c9 powerpc64/pmap: No need for moea64_pvo_remove_from_page_locked() wrapper
The only consumer of moea64_pvo_remove_from_page_locked() already has the
page in hand, so there is no need to search for the page while holding the
lock.  Drop the wrapper, and rename _moea64_pvo_remove_from_page_locked().

Reported by:	alc
2019-07-13 03:39:46 +00:00
Justin Hibbits
a7e6ec601a powerpc64/pmap: Reduce scope of PV_LOCK in remove path
Summary:
Since the 'page pv' lock is one of the most highly contended locks, we
need to try to do as much work outside of the lock as we can.  The
moea64_pvo_remove_from_page() path is a low hanging fruit, where we can
do some heavy work (PHYS_TO_VM_PAGE()) outside of the lock if needed.
In one path, moea64_remove_all(), the PV lock is already held and can't
be swizzled, so we provide two ways to perform the locked operation, one
that can call PHYS_TO_VM_PAGE outside the lock, and one that calls with
the lock already held.

Reviewed By: luporl
Differential Revision: https://reviews.freebsd.org/D20694
2019-07-13 03:02:11 +00:00
Justin Hibbits
21e47be25e Set pcpu curpmap for powerpc64
Summary:
If an illegal instruction is encountered on a process running on a
powerpc64 kernel it would attempt to sync the cache before retrying the
instruction "just in case".  However, since curpmap is not set, when
moea64_sync_icache() attempts to lock the pmap, it's locking on a NULL pointer,
triggering a panic.  Fix this by adding a (assumed unnecessary) fallback to
curthread's pmap in moea64_sync_icache().

Reported by:	alfredo.junior_eldorado.org.br
Reviewed by:	luporl, alfredo.junior_eldorado.org.br
Differential Revision: https://reviews.freebsd.org/D20911
2019-07-13 00:19:57 +00:00
Konstantin Belousov
30b3018d48 Provide protection against starvation of the ll/sc loops when accessing userpace.
Casueword(9) on ll/sc architectures must be prepared for userspace
constantly modifying the same cache line as containing the CAS word,
and not loop infinitely.  Otherwise, rogue userspace livelocks the
kernel.

To fix the issue, change casueword(9) interface to return new value 1
indicating that either comparision or store failed, instead of relying
on the oldval == *oldvalp comparison.  The primitive no longer retries
the operation if it failed spuriously.  Modify callers of
casueword(9), all in kern_umtx.c, to handle retries, and react to
stops and requests to terminate between retries.

On x86, despite cmpxchg should not return spurious failures, we can
take advantage of the new interface and just return PSL.ZF.

Reviewed by:	andrew (arm64, previous version), markj
Tested by:	pho
Reported by:	https://xenbits.xen.org/xsa/advisory-295.txt
Sponsored by:	The FreeBSD Foundation
MFC after:	2 weeks
Differential revision:	https://reviews.freebsd.org/D20772
2019-07-12 18:43:24 +00:00
Justin Hibbits
9ac516a6f1 powerpc: Only worry about the lower 32 bits of SP in a 32-bit process
Summary:
Running a 32-bit process on a 64-bit POWER CPU may still use all 64-bits
in calculations, while ignoring the upper 32 bits for addressing
storage.  It so happens that some processes end up with r1 (SP) having
bit 31 set in some cases (33-bit address).  Writing out to this 33-bit
address obviosly fails.  Since the CPU ignores the upper bits, we should
as well.

sendsig() and cpu_fetch_syscall_args() appear to be the only functions
that actually rely on userspace register values for copy in/out, and
cpu_fetch_syscall_args() doesn't seem to be bitten in practice yet.

Reviewed By: luporl
Differential Revision: https://reviews.freebsd.org/D20896
2019-07-11 03:29:25 +00:00
Leandro Lupori
8b55f9f853 [PPC64] pseries: fix realmaxaddr calculation
On POWER9/pseries, QEMU passes several regions of memory,
instead of a single region containing all memory, as the
code was expecting.

Reviewed by:	jhibbits
Differential Revision:	https://reviews.freebsd.org/D20857
2019-07-10 13:36:17 +00:00
Justin Hibbits
b51bfc30ac powerpc: Clamp 32-bit binaries to 32-bit MAXUSER
sv_maxuser specifies the maximum addressable space for user space.  Presently
this is all 64-bits worth, which is impossible for a 32-bit process.

This bug has existed since the initial import of powerpc64 in 2010.

MFC after:	2 weeks
2019-07-10 04:09:15 +00:00
Mark Johnston
eeacb3b02f Merge the vm_page hold and wire mechanisms.
The hold_count and wire_count fields of struct vm_page are separate
reference counters with similar semantics.  The remaining essential
differences are that holds are not counted as a reference with respect
to LRU, and holds have an implicit free-on-last unhold semantic whereas
vm_page_unwire() callers must explicitly determine whether to free the
page once the last reference to the page is released.

This change removes the KPIs which directly manipulate hold_count.
Functions such as vm_fault_quick_hold_pages() now return wired pages
instead.  Since r328977 the overhead of maintaining LRU for wired pages
is lower, and in many cases vm_fault_quick_hold_pages() callers would
swap holds for wirings on the returned pages anyway, so with this change
we remove a number of page lock acquisitions.

No functional change is intended.  __FreeBSD_version is bumped.

Reviewed by:	alc, kib
Discussed with:	jeff
Discussed with:	jhb, np (cxgbe)
Tested by:	pho (previous version)
Sponsored by:	Netflix
Differential Revision:	https://reviews.freebsd.org/D19247
2019-07-08 19:46:20 +00:00
Leandro Lupori
54fdf3bf19 [PPC] Add missing SLB allocation KASSERT
Although PPC SLB code doesn't handle allocation failures,
which are rare, in most places it asserts that the pointer
returned by uma_zalloc() is not NULL, making it easier to
identify the failure and avoiding an invalid pointer dereference.

This change simply adds a missing KASSERT in SLB code.
2019-07-08 13:01:54 +00:00
Leandro Lupori
57d0d4a271 [PPC64] pseries llan: fix MAC address
There was an issue in pseries llan driver, that resulted in the first 2 bytes
of the MAC address getting stripped, and the last 2 being always 0.

In most cases the network interface still worked, despite the MAC being
different of what was specified to QEMU, but when some other host or DHCP
server expected a specific MAC, this would fail.

This change fixes this by shifting right by 2 the local-mac-address read from
device tree, if its length is 6 instead of 8, as observed in QEMU DT, that
always presents a 6 bytes value for this property.

PR:		237471
Reported by:	Alfredo Dal'Ava Junior
Reviewed by:	jhibbits
Differential Revision:	https://reviews.freebsd.org/D20843
2019-07-04 12:31:24 +00:00
Justin Hibbits
088c26aee8 powerpc/booke: Handle misaligned floating point loads/stores as on AIM
Misaligned floating point loads and stores are already handled for AIM, but
use the DSISR to obtain the necessary data.  Book-E does not have the DSISR,
so these fixups are not performed, leading to a SIGBUS on misaligned FP
loads or stores.  Obtain the necessary data on the Book-E side, similar to
how is done for SPE.

MFC after:	1 week
2019-06-26 01:14:39 +00:00
Justin Hibbits
f62da49b2f powerpc: Transition to Secure-PLT, like most other OSs
Summary:
PowerPC has two PLT models: BSS-PLT and Secure-PLT.  BSS-PLT uses runtime
code generation to generate the PLT stubs.  Secure-PLT was introduced with
GCC 4.1 and Binutils 2.17 (base has GCC 4.2.1 and Binutils 2.17), and is a
more secure PLT format, using a read-only linkage table, with the dynamic
linker populating a non-executable index table.

This is the libc, rtld, and kernel support only.  The toolchain and build
parts will be updated separately.

Reviewed By: nwhitehorn, bdragon, pfg
Differential Revision: https://reviews.freebsd.org/D20598
MFC after:	1 month
2019-06-25 00:40:44 +00:00
Conrad Meyer
c363b16c63 sys: Remove DEV_RANDOM device option
Remove 'device random' from kernel configurations that reference it (most).
Replace perhaps mistaken 'nodevice random' in two MIPS configs with 'options
RANDOM_LOADABLE' instead.  Document removal in UPDATING; update NOTES and
random.4.

Reviewed by:	delphij, markm (previous version)
Approved by:	secteam(delphij)
Differential Revision:	https://reviews.freebsd.org/D19918
2019-06-21 00:16:30 +00:00
Nathan Whitehorn
4d210a60c3 Fix bug on newbus device deletion: we should delete the child's devinfo
on deletion, not the parent's.

MFC after:	3 weeks
2019-06-16 21:56:45 +00:00
Brandon Bergren
664104b4af Fix PPC970 boot after r348783
r348783 changed the behavior of the kernel mappings and broke booting on G5.

- Split the kernel mapping logic out so that the case where we are
running from the wrong memory space is handled using identity
mappings, and the case where we are not using a DMAP is handled by
forcibly mapping the kernel into the dmap range as intended by
r348783.

Reported by:	Mikael Urankar
Reviewed by:	luporl
Approved by:	jhibbits (mentor)
Differential Revision:	https://reviews.freebsd.org/D20608
2019-06-12 15:58:11 +00:00
Leandro Lupori
49f10b5181 [PPC] Fix build error when POWERNV is disabled
When building a kernel supporting PSERIES but not POWERNV,
the compiler would complain about an error variable being
possibly used before being initialized.

In practice, however, this should never happen. In any case, it
is now initialized to an error value.
2019-06-11 11:23:15 +00:00
Leandro Lupori
5d8c3a0657 [PPC64] Fix ofw_initrd
Before this change, OFW initrd (as md) handling code was simulating an ofwbus
device. But as there isn't really a Device Tree (DT) node representing OFW
initrd (it is specified in 2 properties under /chosen), its driver was in fact
stealing other driver's DT node.  This was noticed after MD_ROOT_MEM became
default and QEMU's USB keyboard stopped working under VNC.

This change consists in simplifying the process of detection and mapping of
initrd memory, turning it into a simple startup step, instead of trying to
simulate a device.

Reviewed by:	jhibbits
Differential Revision:	https://reviews.freebsd.org/D20553
2019-06-11 11:16:41 +00:00
Justin Hibbits
fdb916d53e powernv: Port HMI handler to use the message framework
When an HMI occurs a message event also gets created with the details of the
exception.  Hook into the messaging framework to retrieve the HMI message.
Nothing is done with it yet, except to panic on unhandled exception.
2019-06-10 03:24:38 +00:00
Justin Hibbits
f433dab2de powerpc/powernv: Reduce the scope of the sensor guarding mutex
vmem_xalloc() cannot be called while holding a nonblocking mutex, warned
by WITNESS.  The lock may not be necessary in general, but it avoids
superfluous concurrent OPAL calls for the same sensor.

Reported by:	pkubaj
2019-06-10 03:16:55 +00:00
Justin Hibbits
988d63af1c powerpc/pmap: Move the SLB spill handlers to a better place
The SLB spill handlers are AIM-specific, and belong better with the rest of
the SLB code anyway.  No functional change.
2019-06-08 03:07:08 +00:00
Justin Hibbits
b7918b86b3 powerpc/aim: Use nitems() for calculating size of phys_avail in AIM pmaps
Same thing was already done in r347164 for Book-E pmap.
2019-06-08 02:36:07 +00:00
Leandro Lupori
b934fc7468 [PPC64] Support QEMU/KVM pseries without hugepages
This set of changes make it possible to run FreeBSD for PowerPC64/pseries,
under QEMU/KVM, without requiring the host to make hugepages available to the
guest.

While there was already this possibility, by means of setting hw_direct_map to
0, on PowerPC64 there were a couple of issues/wrong assumptions that prevented
this from working, before this changelist.

Reviewed by:	jhibbits
Differential Revision:	https://reviews.freebsd.org/D20522
2019-06-07 17:58:59 +00:00
Justin Hibbits
4420fc895f powerpc/moea: Fix moea64 native VA invalidation
Summary:
moea64_insert_pteg_native()'s invalidation only works by happenstance.
The purpose of the shifts and XORs is to extract the VSID in order to
reverse-engineer the lower bits of the VPN.  Currently a segment size is 256MB
(2**28), and ADDR_API_SHFT64 is 16, so ADDR_PIDX_SHIFT is equivalent.  However,
it's semantically incorrect, in that we don't want to shift by the page shift
size, we want to shift to get to the VSID.

Tested by:	bdragon
Differential Revision: https://reviews.freebsd.org/D20467
2019-06-01 01:40:14 +00:00
Justin Hibbits
8cd3016c00 powerpc64/pmap: Reapply r334235 to OEA64 pmap, clearing HID0_RADIX
This was lost in the re-merger of ISA3 MMU into moea64_native.
2019-05-25 04:56:06 +00:00
Piotr Kubaj
57557e714e Add snd_hda(4) to GENERIC64 used by powerpc64.
amd64 also has snd_hda(4) in GENERIC.

Approved by:	jhibbits (src committer), linimon (mentor)
2019-05-24 20:01:59 +00:00
Leandro Lupori
d3f78f00db Make options MD_ROOT_MEM default on PPC64
Having this option enabled by default on PowerPC64 kernels makes
booting ISO images much easier when on PowerNV.

With it, the ISO may simply be given to the -i flag of kexec.
Better yet, the ISO may be loop mounted on PetitBoot and its
kernel may be used to load itself.

Without this option, booting ISOs on remote PPC64 machines usually
involve preparing a separate kernel, with this option enabled.
2019-05-24 18:41:31 +00:00
Justin Hibbits
702818d200 powerpc/mpc85xx: Use the proper (EREF) form of writing to DBCR0
DBCR0, according to the Freescale EREF, is guaranteed to be updated, and
changes take effect, after an isync plus change of MSR[DE] from 0 to 1.
Otherwise it's guaranteed to be updated "eventually".  Use the expected
synchronization sequence to write it for resetting.

This prevents "Reset failed" from being printed immediately before the CPU
resets.

MFC after:	2 weeks
2019-05-23 03:47:25 +00:00
Justin Hibbits
72e58595b1 powerpc/booke: It helps to set variables before using them
Actually set the source and destination VA's before using them.  Fixes a
bizarre panic on 32-bit Book-E.  Not sure why this wasn't caught by the
compiler.
2019-05-23 03:40:48 +00:00
Leandro Lupori
0632bb89db Fix PPC64 kernel build with clang8 + lld8
This patch fixes the following lld link errors:

- unsupported dynamic relocations on read-only sections
- out-of-range TOC references

Submitted by:	git_bdragon.rtk0.net
Reviewed by:	jhibbits, luporl
MFC after:	2 weeks
Differential Revision:	https://reviews.freebsd.org/D19352
2019-05-22 15:56:41 +00:00
Justin Hibbits
b4b2e7a7b9 powerpc/booke: Use wrtee instead of msr to restore EE bit
The MSR[EE] bit does not require synchronization when changing.  This is a
trivial micro-optimization, removing the trailing isync from mtmsr().

MFC after:	1 week
2019-05-22 02:43:17 +00:00
Conrad Meyer
e2e050c8ef Extract eventfilter declarations to sys/_eventfilter.h
This allows replacing "sys/eventfilter.h" includes with "sys/_eventfilter.h"
in other header files (e.g., sys/{bus,conf,cpu}.h) and reduces header
pollution substantially.

EVENTHANDLER_DECLARE and EVENTHANDLER_LIST_DECLAREs were moved out of .c
files into appropriate headers (e.g., sys/proc.h, powernv/opal.h).

As a side effect of reduced header pollution, many .c files and headers no
longer contain needed definitions.  The remainder of the patch addresses
adding appropriate includes to fix those files.

LOCK_DEBUG and LOCK_FILE_LINE_ARG are moved to sys/_lock.h, as required by
sys/mutex.h since r326106 (but silently protected by header pollution prior
to this change).

No functional change (intended).  Of course, any out of tree modules that
relied on header pollution for sys/eventhandler.h, sys/lock.h, or
sys/mutex.h inclusion need to be fixed.  __FreeBSD_version has been bumped.
2019-05-20 00:38:23 +00:00
Justin Hibbits
c3acaec564 powerpc: Fix moea64 pmap from 347952
vm_paddr_t is only 32 bits on AIM32 (currently), causing a build failure with
the shifting.

MFC after:	2 weeks
MFC with:	r347952
2019-05-18 14:55:59 +00:00
Justin Hibbits
a57ec59f9c powerpc64/pmap: NUMA-ize the page pv lock pool to reduce contention
It was found during building llvm that the page pv lock pool was seeing very
high contention.  Since the pmap is already NUMA aware, it was surmised that
the domains were referencing similar pages in the different domains.  This
reduces contention to the point of noise in a lockstat(8) run (~51% down to
under 5%), reducing build times by up to 20%.

This doesn't do a perfect domain alignment, just a best-guess based on
hardware available, that the domain is roughly specified in the upper bits
of the PA.  Trying to be more clever would more than likely result in
reduced performance just on the work needed.

MFC after:	2 weeks
2019-05-18 11:14:43 +00:00
Brooks Davis
9e774e5340 FCP-101: Remove bm(4).
Relnotes:	yes
FCP:		https://github.com/freebsd/fcp/blob/master/fcp-0101.md
Reviewed by:	jhb, imp
Differential Revision:	https://reviews.freebsd.org/D20230
2019-05-17 15:20:51 +00:00
Justin Hibbits
f04019c3c6 powerpc: Initialize the Hardware Interrupt Offset Register (HIOR) earlier for ppc970
Since we now have a much larger KVA on powerpc64, it's possible to get SLB
traps earlier in boot, possibly even before the HIOR is properly configured
for us.  Move the HIOR setup to immediately after reset, so that we use our
exception handlers instead of Open Firmware's.

PR:		233863
Submitted by:	Mark Millard (partial)
Reported by:	Mark Millard
MFC after:	2 weeks
2019-05-10 19:36:14 +00:00
Andrew Gallatin
542970fa2d Remove IPSEC from GENERIC due to performance issues
Having IPSEC compiled into the kernel imposes a non-trivial
performance penalty on multi-threaded workloads due to IPSEC
refcounting. In my benchmarks of multi-threaded UDP
transmit (connected sockets), I've seen a roughly 20% performance
penalty when the IPSEC option is included in the kernel (16.8Mpps
vs 13.8Mpps with 32 senders on a 14 core / 28 HTT Xeon
2697v3)). This is largely due to key_addref() incrementing and
decrementing an atomic reference count on the default
policy. This cause all CPUs to stall on the same cacheline, as it
bounces between different CPUs.

Given that relatively few users use ipsec, and that it can be
loaded as a module, it seems reasonable to ask those users to
load the ipsec module so as to avoid imposing this penalty on the
GENERIC kernel. Its my hope that this will make FreeBSD look
better in "out of the box" benchmark comparisons with other
operating systems.

Many thanks to ae for fixing auto-loading of ipsec.ko when
ifconfig tries to configure ipsec, and to cy for volunteering
to ensure the the racoon ports will load the ipsec.ko module

Reviewed by:	cem, cy, delphij, gnn, jhb, jpaetzel
Differential Revision:	https://reviews.freebsd.org/D20163
2019-05-09 22:38:15 +00:00
Justin Hibbits
2b03b6bd45 powerpc/booke: Rewrite pmap_sync_icache() a bit
* Make mmu_booke_sync_icache() use the DMAP on 64-bit prcoesses, no need to
  map the page into the user's address space.  This removes the
  pvh_global_lock from the equation on 64-bit.
* Don't map the page with user-readability on 32-bit.  I don't know what the
  chance of a given user process being able to access the NULL page when
  another process's page is added there, but it doesn't seem like a good
  idea to map it to NULL with user read permissions.
* Only sync as much as we need to.  There are only two significant places
  where pmap_sync_icache is used: proc_rwmem(), and the SIGILL second-chance
  for powerpc.  The SIGILL second chance is likely the most common, and only
  syncs 4 bytes, so avoid the other 127 loop iterations (4096 / 32 byte
  cacheline) in __syncicache().
2019-05-08 16:15:28 +00:00
Justin Hibbits
4023311a29 powerpc/booke: Do as much work outside of TLB locks as possible
Reduce the surface area of the TLB locks.  Unfortunately the same trick for
serializing the tlbie instruction on OEA64 cannot be used here to reduce the
scope of the tlbivax mutex to the tlbsync only, as the mutex also serializes
the TLB miss lock as a side effect, so contention on this lock may not be
reducible any further.
2019-05-08 16:05:18 +00:00
Justin Hibbits
7d91f528a6 powerpc: hide innocuous printf behind bootverbose
NUMA associativity, and OFW node existence, is completely optional, and
shouldn't warn always.
2019-05-08 03:15:22 +00:00
Kyle Evans
251a32b5b2 tun/tap: merge and rename to tuntap
tun(4) and tap(4) share the same general management interface and have a lot
in common. Bugs exist in tap(4) that have been fixed in tun(4), and
vice-versa. Let's reduce the maintenance requirements by merging them
together and using flags to differentiate between the three interface types
(tun, tap, vmnet).

This fixes a couple of tap(4)/vmnet(4) issues right out of the gate:
- tap devices may no longer be destroyed while they're open [0]
- VIMAGE issues already addressed in tun by kp

[0] emaste had removed an easy-panic-button in r240938 due to devdrn
blocking. A naive glance over this leads me to believe that this isn't quite
complete -- destroy_devl will only block while executing d_* functions, but
doesn't block the device from being destroyed while a process has it open.
The latter is the intent of the condvar in tun, so this is "fixed" (for
certain definitions of the word -- it wasn't really broken in tap, it just
wasn't quite ideal).

ifconfig(8) also grew the ability to map an interface name to a kld, so
that `ifconfig {tun,tap}0` can continue to autoload the correct module, and
`ifconfig vmnet0 create` will now autoload the correct module. This is a
low overhead addition.

(MFC commentary)

This may get MFC'd if many bugs in tun(4)/tap(4) are discovered after this,
and how critical they are. Changes after this are likely easily MFC'd
without taking this merge, but the merge will be easier.

I have no plans to do this MFC as of now.

Reviewed by:	bcr (manpages), tuexen (testing, syzkaller/packetdrill)
Input also from:	melifaro
Relnotes:	yes
Differential Revision:	https://reviews.freebsd.org/D20044
2019-05-08 02:32:11 +00:00
Justin Hibbits
2154a866b6 powerpc/booke: Use #ifdef __powerpc64__ instead of hw_direct_map in places
Since the DMAP is only available on powerpc64, and is *always* available on
Book-E powerpc64, don't penalize either side (32-bit or 64-bit) by always
checking hw_direct_map to perform operations.  This saves 5-10% time on
various ports builds, and on buildworld+buildkernel on Book-E hardware.

MFC after:	3 weeks
2019-05-05 20:23:43 +00:00
Justin Hibbits
bfd0787769 powerpc/booke: Fix size check for phys_avail in pmap bootstrap
Use the nitems() macro instead of the expansion, a'la r298352.  Also, fix the
location of this check to after initializing availmem_regions_sz, so that the
check isn't always against 0, thus always failing (nitems(phys_avail) is always
more than 0).
2019-05-05 20:05:50 +00:00
Justin Hibbits
73a30b035e powerpc/mpc85xx: Attach MPC85xx PCI bus and root complex at the right pass
No signifcant change, just matches other PCI attachments, attaching at
BUS_PASS_BUS.

MFC after:	2 weeks
2019-05-04 16:24:43 +00:00
Justin Hibbits
e280e2ea3d powerpc: Optimize padding in bus_dma_tag
Avoid 8 bytes of padding (2 noncontiguous ints).

Submitted by:	Brandon Bergren <git_bdragon.rtk0.net>
Differential Revision: https://reviews.freebsd.org/D20121
2019-05-04 02:45:24 +00:00
Justin Hibbits
5d67b612d0 powerpc: Merge all pmap struct definitions
Summary:
A few ports fail to build due to missing pmap-related definitions, which are
specific per-pmap type.  This tries to appease those ports, by merging all
pmaps together.

A future change will move the inline page directory out of the Book-E pmap,
to eliminate the last #ifdefs in pmap.h and complete the merge.

Reviewed By: luporl
Differential Revision: https://reviews.freebsd.org/D20119
2019-05-04 02:34:28 +00:00
Conrad Meyer
d6745408c7 Add a COMPAT_FREEBSD12 kernel option.
Use it wherever COMPAT_FREEBSD11 is currently specified, like r309749.

Reviewed by:	imp, jhb, markj
Sponsored by:	Dell EMC Isilon
Differential Revision:	https://reviews.freebsd.org/D20120
2019-05-02 18:10:23 +00:00
Justin Hibbits
b4698b7a6c powerpc: Drop OPAL_HANDLE_HMI2 for now, to avoid panicking
It's possible for a Hypervisor Maintenance Interrupt (HMI) to occur while in
the pmap code, holding locks.  This can cause WITNESS to panic due to lock
errors in calling pmap_kextract().  Since we don't yet handle the flags
returned by OPAL_HANDLE_HMI2, just stop using it, so that we don't call into
pmap_kextract().

Reported by:	pkubaj
2019-05-02 03:39:03 +00:00
Justin Hibbits
0af5d6f7d9 powerpc: Stop pretending we run on e500v1 cores
Unconditional writing to MAS7, which doesn't exist on the e500v1 core, in a
TLB miss handler has been in the code for several years now.  Since this has
gone unnoticed for so long, it's easily concluded that e500v1 is not in use
with FreeBSD.  Simplify the code path a bit, by unconditionally zeroing MAS7
instead of calling a subroutine to do it.
2019-04-30 03:45:46 +00:00
Justin Hibbits
7122ab6ed3 powerpc64: Fix switch panic from cpu_throw()
r18 is used to hold the old PCB flags, but cpu_throw doesn't populate r18
with PCB flags, since the old thread is gone.  This can lead to panics on
cores that don't have the registers guarded by these flags.
2019-04-29 22:37:35 +00:00
Leandro Lupori
508864649b [PPC64] Turn opal_flash.c into a device
This change makes it easier to enable/disable the inclusion of
OPAL flash in the kernel.

Reviewed by:	jhibbits
Differential Revision:	https://reviews.freebsd.org/D20098
2019-04-29 16:50:33 +00:00
Justin Hibbits
e2e3e7d28e powerpc: Make OPAL root node probe at bus pass
This way its children can attach earlier if needed, and some subsystems are
attached earlier, like the asynchronous token management.

MFC after:	2 weeks
2019-04-29 01:10:57 +00:00
Justin Hibbits
d1d73b0e27 powerpc: Add support for additional FSCR-managed facilities
Add support to enable, save, and restore the following facilities:
* Target Address Register (bctar) -- seemingly just another register to
  branch to.
* Event-based branching -- an interrupt-like userspace event handler
  subsystem.
* Load-monitored facility -- A facility that allows monitoring a range of
  physical memory, and triggering an event on access.  Targeted to garbage
  collection software features.
2019-04-27 22:30:22 +00:00
Justin Hibbits
3eb5d5dd25 powerpc: Add SPR definitions for additional POWER8/POWER9 facilities
This only adds the new SPR definitions and the associated FSCR bits.  The
facilities themselves will be added in separate commits.
2019-04-27 19:32:33 +00:00
Justin Hibbits
8b7f0d83e6 powerpc64: Add the DSCR facility on POWER8 and later
The Data Stream Control Register (DSCR) is privileged on POWER7, but
unprivileged (different register) on POWER8 and later.  However, it's now
guarded by a new register, the Facility Status and Control Register, instead of
the MSR like other pre-existing facilities (FPU, Altivec).  The FSCR must be
managed explicitly, since it's effectively an extension of the MSR.

Tested by:	Brandon Bergren
2019-04-27 16:28:34 +00:00
Justin Hibbits
f074eff155 powerpc: Add POWER8NVL definition
The POWER8NVL (POWER8 NVLink) architecturally behaves identically to the
POWER8, with a different PVR identifier.  Mark it as such, so it shows up
appropriately to the user.

Reported by:	Alexey Kardashevskiy
MFC after:	2 weeks
2019-04-27 02:33:49 +00:00
Justin Hibbits
19cfd8759e powerpc: micro-optimize cpu_switch()
Since the non-volatile registers are restored at the end of cpu_switchin (of
the new thread) they're free for us to use for our own purposes.  Load the
PCB_FLAGS into a non-volatile register so it's preserved across the C
function calls that manage FPU and altivec state.  This removes 4 loads from
each file.  Might be a trivial performance improvement (~12 clock cycles per
context switch).

MFC after:	3 weeks
2019-04-27 00:53:41 +00:00
Justin Hibbits
17b72853f4 powerpc64: Clear FSCR SPR, so that it's in a known state
This now turns any access to the DSCR SPR into a SIGILL.  Later commits will
make DCSR work correctly on POWER8 and POWER9.

PR:		237208
2019-04-26 03:18:49 +00:00
Justin Hibbits
38a6d5495b powerpc: Fix whitespace in SPR header. 2019-04-26 03:13:44 +00:00
Justin Hibbits
da54cd8721 powerpc: Add another feature2 flag, and update power9 definition
Also fix the definition of PPC_FEATURE2_HTM_NOSUSPEND, a bad line copy.

This now closer matches Linux's definition.
2019-04-26 02:30:03 +00:00
Justin Hibbits
19b86243f4 powerpc: Add a couple missing isyncs
mtmsr and mtsr require context synchronizing instructions to follow.  Without
a CSI, there's a chance for a machine check exception.  This reportedly does
occur on a MPC750 (PowerMac G3).

Reported by:	Mark Millard
2019-04-24 02:51:58 +00:00
Leandro Lupori
8920043674 [PPC64] Fix wrong KASSERT in mphyp_pte_insert()
As mphyp_pte_unset() can also remove PTE entries, and as this can
happen in parallel with PTEs evicted by mphyp_pte_insert(), there
is a (rare) chance the PTE being evicted gets removed before
mphyp_pte_insert() is able to do so. Thus, the KASSERT should
check wether the result is H_SUCCESS or H_NOT_FOUND, to avoid
panics if the situation described above occurs.

More details about this issue can be found in PR 237470.

PR:		237470
Reviewed by:	jhibbits
Differential Revision:	https://reviews.freebsd.org/D20012
2019-04-23 17:11:45 +00:00
Justin Hibbits
f4c5f64d30 [PowerPC64] pseries-llan: increment packet output counters on error and success
Summary: when using pseries-llan driver, Opkts and Oerrs counters (netstat
-i) are always zero. This patch adds an small error handling to increment
these counters.

Submitted by:	alfredo.junior_eldorado.org.br
Differential Revision: https://reviews.freebsd.org/D20009
2019-04-23 03:19:03 +00:00
Justin Hibbits
ba5189f7be powerpc64/pseries: Fix hypervisor call with extra arguments
Some hypervisor calls, such as H_SEND_LOGICAL_LAN, take more arguments than
are traditionally passed in registers.  The HCALL ABI will accept these
arguments in r11 and r12.  With ELFv2 ABI, these arguments are 2
double-words lower than ELFv1 ABI, as two double-words in the stack frame
are no longer used, and therefore removed from the frame.  Fix the offsets
for loading the registers for the HCALL.  This fixes the phyp_llan driver
with ELFv2 kernel.

Submitted by:	alfredo.junior_eldorado.org.br
Differential Revision:	https://reviews.freebsd.org/D20008
2019-04-23 03:05:26 +00:00
Justin Hibbits
93096fecb6 powerpc64/powernv: Relax flash block write requirements
Since writes don't necessarily need to be on erase-block boundaries, we can
relax the block size and alignments down to sector size.  If it needs to be
erased, opalflash_erase() will check proper alignment and size.
2019-04-20 02:44:38 +00:00
Justin Hibbits
bc60451a47 powerpc/powernv: Make erasing before writes optional
If the OPAL flash driver supports writing without erase, it adds a
'no-erase' property to the flash device node.  Honor that property and don't
bother erasing if it exists.
2019-04-19 02:28:04 +00:00
Warner Losh
f7ab01581a Move mpr/mps drivers from per-arch NOTES files into the MI notes
file. They are in more arches they they aren't. Add appropriate
nodevice directives in powerpc and arm.
2019-04-13 06:30:45 +00:00
Justin Hibbits
49d9a59783 Add NUMA support to powerpc
Summary:
Initial NUMA support:
    - associate CPU with domain
    - associate memory ranges with domain
    - identify domain for devices
    - limit device interrupt binding to appropriate domain

- Additionally fixes a bug in the setting of Maxmem which led to
  only memory attached to the first socket being enabled for DMA

A pmap variant can opt in to numa support by by calling `numa_mem_regions`
at the end of pmap_bootstrap - registering the corresponding ranges with the
VM.

This yields a ~20% improvement in build times of llvm on dual socket POWER9
over non-NUMA.

Original patch by mmacy.

Differential Revision: https://reviews.freebsd.org/D17933
2019-04-13 04:03:18 +00:00
Justin Hibbits
77eb50c7a3 powerpc: Add file forgotten in r346144
Forgot to add the changes for DELAY(), which lowers priority during the
delay period.  Also, mark the timebase read as volatile so newer GCC does
not optimize it away, as it reportedly does currently.

MFC after:	2 weeks
MFC with:	r346144
2019-04-13 02:29:30 +00:00
Justin Hibbits
e92d228bbb powerpc: Adjust priority NOPs, and make them functions
PowerISA 2.07 and PowerISA 3.0 both specify special NOPs for priority
adjustments, with "medium" priority being normal.  We had been setting
medium-low as our normal priority.  Rather than guess each time as to what
we want and the right NOP, wrap them in inline functions, and replace the
occurrances of the NOPs with the functions.  Also, make DELAY() drop to very
low priority while waiting, so we don't burn CPU.

Coupled with r346143, this shaves off a modest 5-8% on buildworld times with
-j72.  There may be more room for improvement with judicious use of these
NOPs.

MFC after:	2 weeks
2019-04-12 00:53:30 +00:00
Justin Hibbits
6b74fa3f3e powerpc64: Increase the nap level on power9 idling
The POWER9 documentation specifies that levels 0-3 are the 'lightest' sleep
level, meaning lowest latency and with no state loss.  However, state 3 is
not implemented, and is instead reserved for future chips.  This now
properly configures the PSSCR, specifying state 2 as the lowest level to
enter, but request level 0 for quickest sleep level.  If the OCC determines
that the CPU can enter states 1 or 2 it will trigger the transition to those
states on demand.

MFC after:	1 week
2019-04-12 00:44:33 +00:00
Justin Hibbits
3c8c50f955 powerpc/powernv: Fix major bugs in opal_flash
* The BIO bio_data may not be page aligned.  Only the base address of each
  page worth of data is extracted to pass to OPAL.  Without page alignment
  it can scribble over random memory when finishing the page read.  Fix this
  by short-reading the first page to properly align for full page reads.
* Fix the definition of OPAL_FLASH_ERASE.
* Properly handle the async message result, as now returned from r345974.
2019-04-06 02:39:56 +00:00
Justin Hibbits
947079ebee powerpc/powernv: Fix issues in opal_async
* Properly return the full opal_msg from an async completion.
* Don't keep bugging OPAL, wait 100us or so.  With some minor changes to
  DELAY() to drop to very low priority, the thread won't hog the CPU while
  polling for the async completion.
2019-04-06 02:31:01 +00:00
Justin Hibbits
62c7ea1f1d powerpc: Allow emulating optional FPU instructions on CPUs with an FPU
The e5500 has an FPU, but lacks the optional fsqrt instruction.  This
instruction gets emulated in the kernel, but the emulation uses stale data,
from the last switch out, and does not return the result of the operation
immediately.  Fix both of these conditions by saving and restoring the FPRs
around the emulation point.

MFC after:	1 week
MFC with:	r345829
2019-04-03 04:01:08 +00:00
Justin Hibbits
81dd9c5e69 powerpc: Apply r178139 from sparc64 to powerpc's fpu_sqrt
This fix was committed less than 2 months after the code was forked into the
powerpc kernel.  Though powerpc doesn't use quad-precision floating point,
or need it for emulation, the changes do look like correctness fixes
overall.

This was found while trying to get fsqrt emulation working on e5500, which
does have a real FPU, but lacks the fsqrt instruction.  This is not the
complete fix, the rest is to be committed separately.

MFC after:	1 week
2019-04-03 03:54:30 +00:00
Justin Hibbits
fbf7737949 powernv: Port OPAL asynchronous framework to use the new message framework
Since OPAL_GET_MSG does not discriminate between message types, asynchronous
completion events may be received in the OPAL_GET_MSG call, which dequeues
them from the list, thus preventing OPAL_CHECK_ASYNC_COMPLETION from
succeeding.  Handle this case by integrating with the messaging framework.
2019-04-02 04:02:57 +00:00
Justin Hibbits
911a92603e powerpc/powernv: Add OPAL heartbeat thread
Summary:
OPAL needs to be kicked periodically in order for the firmware to make
progress on its tasks.  To do so, create a heartbeat thread to perform this task
every N milliseconds, defined by the device tree.  This task is also a central
location to handle all messages received from OPAL.

Reviewed By: luporl
Differential Revision: https://reviews.freebsd.org/D19743
2019-04-02 04:00:01 +00:00
Justin Hibbits
0499e9c619 powerpc64: Use medium code model in asm files for TOC references
Summary:
With a sufficiently large TOC, it's possible to index out of range, as
the immediate load instructions only permit 16-bit indices, allowing up
to 64kB range (signed) from the base pointer.  Allow +/- 2GB range, with
the medium code model TOC accesses in asm.

Patch originally by Brandon Bergren.  The issue appears to impact ELFv2
more than ELFv1.

Reviewed by:	luporl
Differential Revision: https://reviews.freebsd.org/D19708
2019-03-29 02:38:30 +00:00
Justin Hibbits
4b4b6f0191 powerpc: Remove now-obsolete P9H MMU name 2019-03-29 02:11:48 +00:00
Justin Hibbits
9f1a007da7 powerpc64: Micro-optimize moea64 native pmap tlbie
* Cache moea64_need_lock in a local variable; gcc generates slightly better
  code this way, it doesn't need to reload the value from memory each read.
* VPN cropping is only needed on PowerPC ISA 2.02 and older cores, a subset
  of those that need serialization, so move this under the need_lock check,
  so those that don't need the lock don't even need to check this.
2019-03-26 02:53:35 +00:00
Justin Hibbits
8af4cc4d5a powernv: Add Hypervisor Maintenance Interrupt handler
Attempting to build www/firefox on POWER9 resulted in a HMI exception being
thrown, a fatal trap currently.  This is typically caused by timer facility
errors, but examination of the Hypervisor Maintenance Exception Register
(HMER) yielded only that an exception had recovered, with no information of
the actual exception cause.

When an HMI occurs, OPAL_HANDLE_HMI or OPAL_HANDLE_HMI2 must be called to
handle the exception at the firmware level.  If the exception is handled, we
can continue.

This adds only the preliminary handler, enough to prevent package building
from panicking.  An enhancement in the future is to use the flags returned
by OPAL_HANDLE_HMI2 to print more useful error messages, and log maintenance
events.

Reviewed by:	luporl
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D19634
2019-03-23 03:23:20 +00:00
Justin Hibbits
bc94b70098 powerpc: Re-merge isa3 HPT with moea64 native HPT
r345402 fixed the bug that led to the split of the ISA 3.0 HPT handling from
the existing manager.  The cause of the bug was gcc moving the register
holding VPN to a different register (not r0), which triggered bizarre
behaviors.  With the fix, things work, so they can be re-merged.  No
performance lost with the merge.
2019-03-22 22:14:14 +00:00
Justin Hibbits
091a23cbf8 powerpc64: Handle the modern (2.05+) implementaiton of tlbie
By happenstance gcc4 puts 'vpn' into r0 in all uses of TLBIE(), but modern
gcc does not.  Also, the single-argument form of tlbie zeros all unused
arguments, making the modern tlbie instruction use r0 as the RS field
(LPID).

The vpn argument has the bottom 12 bits cleared (the input having been
left-shifted by 12 bits), which just so happens, on the POWER9 and previous
incarnations, to be the number of LPID bits supported.  With those bits
being zero, the instruction:

	tlbie r0, r0

will invalidate the VPN in r0, in LPAR 0 (ignoring the upper bits of r0 for
the RS field).  One build with gcc8 yields:

	tlbie r9, r0

with r0 having arbitrary contents, not equal to r9.  This leads to strange
crashes, behaviors, and panics, due to the requested TLB entry not actually
being invalidated.

As the moea64_native must work on both old and new, we explicitly zero out
r0 so that it can work with only the single argument, built with base gcc
and modern gcc.  isa3_hashtb takes a different approach, encoding the
two-argument form, soas not to explicitly clobber r0, and instead let the
compiler decide.

Reported by:	Brandon Bergren
Tested by:	Brandon Bergren
MFC after:	1 week
2019-03-22 01:43:31 +00:00
Konstantin Belousov
fd8d844f76 amd64 KPTI: add control from procctl(2).
Add the infrastructure to allow MD procctl(2) commands, and use it to
introduce amd64 PTI control and reporting.  PTI mode cannot be
modified for existing pmap, the knob controls PTI of the new vmspace
created on exec.

Requested by:	jhb
Reviewed by:	jhb, markj (previous version)
Tested by:	pho
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D19514
2019-03-16 11:44:33 +00:00
Konstantin Belousov
6f1fe3305a amd64: Add md process flags and first P_MD_PTI flag.
PTI mode for the process pmap on exec is activated iff P_MD_PTI is set.

On exec, the existing vmspace can be reused only if pti mode of the
pmap matches the P_MD_PTI flag of the process.  Add MD
cpu_exec_vmspace_reuse() callback for exec_new_vmspace() which can
vetoed reuse of the existing vmspace.

MFC note: md_flags change struct proc KBI.

Reviewed by:	jhb, markj
Tested by:	pho
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D19514
2019-03-16 11:31:01 +00:00
Justin Hibbits
093f7de620 powerpc: Print trap frame address in ddb backtraces
Registers visible from 'show reg' don't always match the registers from the
offending trap frame.  Knowing the frame address lets one examine the
registers manually.

MFC after:	1 week
2019-03-09 03:24:39 +00:00
Justin Hibbits
66306e6acd powerpc: Print trap frame address for fatal traps
MFC after:	1 week
2019-03-09 03:18:37 +00:00
Justin Hibbits
b2c820735a powerpc: Print data address register on alignment exceptions
MFC after:	1 week
2019-03-09 03:10:56 +00:00
Justin Hibbits
1cd7081eb1 powerpc64: Fix early exit with invalid kernel SLB entries
The check for early exit should be checking the SLB entry itself.  As
currently written it was checking the address of the SLB, which is always
non-zero, so would go through the kernel SR restore loop regardless.

Submitted by:	mmacy
MFC after:	2 weeks
2019-03-08 04:20:33 +00:00
Justin Hibbits
9ffdae0fd7 powerpc: Fix cpufreq statement scoping
The second statements on the lines are not guarded by the `if' condition.
This triggers a warning with newer gcc.  It's relatively harmless given the
usage, but incorrect.  Instead, wrap the statements so they're properly
guarded.

Reported by:	powerpc64-gcc xtoolchain
MFC after:	1 week
2019-03-08 03:59:53 +00:00
Justin Hibbits
058250a8ab powerpc: Save stack pointer in savectx
This allows 'show acttrace' to show backtrace on processes currently running
on CPUs.

Reported by:	Brandon Bergren
MFC after:	1 week
2019-03-07 04:43:08 +00:00
Justin Hibbits
83b009dab5 powerpc: fix 'show spr' for ELFv1 powerpc64
Update and flush the right cache range for the ELFv1 ABI.

MFC after:	1 week
2019-03-02 21:11:46 +00:00
Justin Hibbits
5b4c63b781 powerpc/booke: Depessimize MAS register updates even more
Remove isyncs between MAS register updates in the TLB miss handler, since
it's only needed before the TLB update instructions.
2019-03-02 20:59:18 +00:00
Justin Hibbits
51244b1e46 powerpc: Scale intrcnt by mp_ncpus
On very large powerpc64 systems (2x22x4 power9) it's very easy to run out of
available IRQs and crash the system at boot.  Scale the count by mp_ncpus,
similar to x86, so this doesn't happen.  Further work can be done in the future
to scale the I/O IRQs as well, but that's left for the future.

Submitted by:	mmacy
MFC after:	3 weeks
2019-03-02 01:51:41 +00:00
Edward Tomasz Napierala
1699546def Remove sv_pagesize, originally introduced with r100384.
In all of the architectures we have today, we always use PAGE_SIZE.
While in theory one could define different things, none of the
current architectures do, even the ones that have transitioned from
32-bit to 64-bit like i386 and arm. Some ancient mips binaries on
other systems used 8k instead of 4k, but we don't support running
those and likely never will due to their age and obscurity.

Reviewed by:	imp (who also contributed the commit message)
Sponsored by:	DARPA, AFRL
Differential Revision:	https://reviews.freebsd.org/D19280
2019-03-01 16:16:38 +00:00
Justin Hibbits
6775dfdf54 powerpc/powernv: Add OPAL flash device driver
Firmware needed by petitboot, for example, GPU firmware, can be installed to
a partition in the flash filesystem.  This driver exposes the full flash
given by the device tree, letting the user manage firmware, etc, from
FreeBSD.

To use the partitions provided by the flash module, the fdt_slicer module is
needed, but the module isn't needed for raw access, so there's no direct
dependency link in here.

MFC after:	2 weeks
2019-03-01 04:36:55 +00:00
Justin Hibbits
dac618a648 powerpc/powernv: Add asynchronous token management for powernv
The OPAL firmware only supports a finite number of in-flight asynchronous
operations.  Rather than have each subsystem try to manage its own, use a
central management service to hand out tokens.

More work can be done to improve asynchronous behavior, such as funneling
things through a future OPAL heartbeat handler, but capabilities will be
added as needed.

Augment the existing consumers (i2c and sensors) to use this new API.

MFC after:	4 weeks
2019-03-01 02:49:47 +00:00
Justin Hibbits
0d69f00b4d powerpc/mpc85xx: Synchronize timebase the platform correct way
Summary:
To safely synchronize timebase we need to disable the timebase on all
cores, set timebase, and resynchronize.  This adds two new devices, mutually
exclusive, which attach on the SoC simplebus, to freeze and unfreeze the
timebase.  The devices are singletons, and platform-specific, so no reason
to make them optional and in separate files.

This was found to be necessary for top(1) to work correctly on an AmigaOne
X5000 (P5020 SoC).  It also fixes bufdaemon and bufspacedaemon hangs at
shutdown.

Test Plan: Regression test on various Book-E hardware.

Reviewed by:	nwhitehorn
Tested by:	Brandon Bergren (git_bdragon.rtk0.net)
MFC after:	2 weeks
Differential Revision: https://reviews.freebsd.org/D19208
2019-02-27 03:30:49 +00:00
Konstantin Belousov
e7a9df16e6 Add kernel support for Intel userspace protection keys feature on
Skylake Xeons.

See SDM rev. 68 Vol 3 4.6.2 Protection Keys and the description of the
RDPKRU and WRPKRU instructions.

Reviewed by:	markj
Tested by:	pho
Sponsored by:	The FreeBSD Foundation
MFC after:	2 weeks
Differential revision:	https://reviews.freebsd.org/D18893
2019-02-20 09:51:13 +00:00
Justin Hibbits
a9b033c2f3 powerpc/booke: Fix 32-bit build
MFC after:	2 weeks
MFC with:	344202
2019-02-16 04:47:33 +00:00
Justin Hibbits
0454ed9794 powerpc/booke: depessimize MAS register updates
We only need to isync before we actually use the MAS registers, so before and
after the TLB read/write/sync/search operations.

MFC after:	2 weeks
2019-02-16 04:38:34 +00:00
Justin Hibbits
18f7e2b45e powerpc/booke: Use DMAP where possible for page copy and zeroing
This avoids several locks and pmap_kenter()'s, improving performance
marginally.

MFC after:	2 weeks
2019-02-16 04:16:10 +00:00
Leandro Lupori
59621b207c [PPC64] Fix mismatch between thread flags and MSR
When sigreturn() restored a thread's context, SRR1 was being restored
to its previous value, but pcb_flags was not being touched.

This could cause a mismatch between the thread's MSR and its pcb_flags.
For instance, when the thread used the FPU for the first time inside
the signal handler, sigreturn() would clear SRR1, but not pcb_flags.
Then, the thread would return with the FPU bit cleared in MSR and,
the next time it tried to use the FPU, it would fail on a KASSERT
that checked if the FPU was disabled.

This change clears the FPU bit in both pcb_flags and frame->srr1,
as the code that restores the context expects to use the FPU trap
to re-enable it.

PR:		234539
Reported by:	sbruno
Reviewed by:	jhibbits, sbruno
Differential Revision:	https://reviews.freebsd.org/D19166
2019-02-14 15:15:32 +00:00
Konstantin Belousov
72091bb393 Enable enabling ASLR on non-x86 architectures.
Discussed with:	emaste
Sponsored by:	The FreeBSD Foundation
2019-02-14 14:44:53 +00:00
Justin Hibbits
64143619ab powerpc/booke: Use the 'tlbilx' instruction on newer cores
Newer cores have the 'tlbilx' instruction, which doesn't broadcast over
CoreNet.  This is significantly faster than walking the TLB to invalidate
the PID mappings.  tlbilx with the arguments given takes 131 clock cycles to
complete, as opposed to 512 iterations through the loop plus tlbre/tlbwe at
each iteration.

MFC after:	3 weeks
2019-02-13 03:11:12 +00:00
Leandro Lupori
b8efbfb9d3 [ppc64] prevent infinite loop on icache sync
At moea64_sync_icache(), when the 'va' argument has page size
alignment, round_page() will return the same value as 'va'.
This would cause 'len' to be 0 and thus an infinite loop.

With this change, 'lim' will always point to the next page boundary.

This issue occurred especially during debugging sessions, when a breakpoint
was placed on an exact page-aligned offset, for instance.

Reviewed by:	jhibbits
Differential Revision:	https://reviews.freebsd.org/D19149
2019-02-12 11:29:03 +00:00
Justin Hibbits
dcbd7de5b6 powerpc: Clamp MAXCPU for MPC85XXSPE kernel to 2
SoCs with e500v2 chips only have at most 2 cores, and there are no plans to
release any more e500v2-based SoCs.  Clamping MAXCPU down to 2 saves 5MB of
data, and 1.5MB bss.
2019-02-10 20:21:20 +00:00
Justin Hibbits
83191e19b7 powerpc: Fix AIM build
cpu_idle_e500mc is only used in booke, so ignore it completely in AIM.

MFC after:	2 weeks
MFC with:	r343944
2019-02-09 23:19:33 +00:00
Justin Hibbits
d6919f21dc powerpc: Split out the e500mc idling from rest of Book-E
The e500v2 and e500mc (and derivatives) have different idling procedures, so
make them different functions.

MFC after:	2 weeks
2019-02-09 21:19:53 +00:00
Leandro Lupori
59a8224976 [ppc64] fix /dev/kmem
For direct mapped kernel addresses, ppc64 function was not
performing the dmap to physical conversion, before jumping
to the code that fetched the value from physical memory.

Reviewed by:	jhibbits
Differential Revision:	https://reviews.freebsd.org/D19086
2019-02-07 17:30:44 +00:00
Justin Hibbits
4290b4b849 powerpc: Bind IRQs to only one interrupt on QorIQ SoCs
The QorIQ SoCs don't actually support multicast interrupts, and the
references state explicitly that multicast is undefined behavior.  Avoid the
undefined behavior by binding to only a single CPU, using a quirk to
determine if this is necessary.

MFC after:	3 weeks
2019-02-06 03:52:14 +00:00
Leandro Lupori
4a8450ceff [ppc64] llan: fix fatal kernel trap when system is low on memory
When running several builders in parallel, on QEMU, with 8GB of
memory, a fatal kernel trap (0x300 (data storage interrupt))
caused by llan driver is sometimes observed, when the system
starts to run out of swap space.

This happens because, at llan_intr(), a phyp call to add a
logical LAN buffer is always made when llan_add_rxbuf() fails,
even if it fails to allocate a new buffer.

PR:	235489
Reviewed by:	jhibbits
Differential Revision:	https://reviews.freebsd.org/D19084
2019-02-05 18:16:14 +00:00
Justin Hibbits
9c22a13345 powerpc: Don't idle with the wait instruction on booke
It appears idling via 'wait' on e5500 causes strange behaviors, such as
top(1) simply hanging sporadically, until input.  Until this can possibly be
sorted out (interrupt issue?), just don't idle on this hardware.  The SoCs
are low power already, and the wait state doesn't save much anyway.
2019-02-05 04:47:41 +00:00
Leandro Lupori
6174048251 powerpc64: Add a trap stack area
Currently, the trap code switches to the the temporary stack in the dbtrap
section. It works in most cases, but in the beginning of the execution, the
temp stack is being used, as starting in the powerpc_init() code.

In this current scenario, the stack is being overwritten, which causes the
return of breakpoint() to take abnormal execution.

This current patchset create a small stack to use by the dbtrap: codepath
avoiding the corruption of the temporary stack.

PR:		224872
Submitted by:	breno.leitao_gmail.com
Reviewed by:	jhibbits
Differential Revision:	https://reviews.freebsd.org/D14484
2019-02-04 16:02:03 +00:00
Justin Hibbits
d49fc192c1 powerpc/powernv: Add a driver for the POWER9 XIVE interrupt controller
The XIVE (External Interrupt Virtualization Engine) is a new interrupt
controller present in IBM's POWER9 processor.  It's a very powerful,
very complex device using queues and shared memory to improve interrupt
dispatch performance in a virtualized environment.

This yields a ~10% performance improvment over the XICS emulation mode,
measured in both buildworld, and 'dd' from nvme to /dev/null.

Currently, this only supports native access.

MFC after:	1 month
2019-02-02 04:15:16 +00:00
Konstantin Belousov
c75f49f7d8 Make iflib a loadable module.
iflib is already a module, but it is unconditionally compiled into the
kernel.  There are drivers which do not need iflib(4), and there are
situations where somebody might not want iflib in kernel because of
using the corresponding driver as module.

Reviewed by:	marius
Discussed with:	erj
Sponsored by:	The FreeBSD Foundation
MFC after:	2 weeks
Differential revision:	https://reviews.freebsd.org/D19041
2019-01-31 19:05:56 +00:00
Andriy Voskoboinyk
86d535ab47 Garbage collect AH_SUPPORT_AR5416 config option.
It does nothing since r318857.
2019-01-25 13:48:40 +00:00