Commit graph

1068 commits

Author SHA1 Message Date
Bojan Novković 858ead4bce powerpc_mmu_radix: Release PTP reference on leaf ptpage allocation failure
0013741 fixed an edge case invloving mlock() and superpage creation
by creating and inserting a leaf pagetable page for mlock'd superpages.
However, the code does not properly release the reference to the
pagetable page in the error handling path.
This commit fixes the issue by adding calls to 'pmap_abort_ptp'
in the error handling path.

Reported by: alc
Approved by: markj (mentor)
Fixes: 0013741
Differential Revision: https://reviews.freebsd.org/D45582
2024-06-16 18:19:27 +02:00
Bojan Novković 200de4dc07 powerpc_mmu_radix: Introduce 'pmap_abort_ptp'
This commit moves code for releasing pagetable page references
into a separate function. No functional change intended.

Approved by: markj (mentor)
Differential Revision:  https://reviews.freebsd.org/D45581
2024-06-16 18:19:26 +02:00
Alan Cox f1d73aacdc pmap: Skip some superpage promotion attempts that will fail
Implement a simple heuristic to skip pointless promotion attempts by
pmap_enter_quick_locked() and moea64_enter().  Specifically, when
vm_fault() calls pmap_enter_quick() to map neighboring pages at the end
of a copy-on-write fault, there is no point in attempting promotion in
pmap_enter_quick_locked() and moea64_enter().  Promotion will fail
because the base pages have differing protection.

Reviewed by:	kib
Differential Revision:	https://reviews.freebsd.org/D45431
MFC after:	1 week
2024-06-04 00:38:05 -05:00
John Baldwin 1f1b2286fd pmap: Convert boolean_t to bool.
Reviewed by:	kib (older version)
Differential Revision:	https://reviews.freebsd.org/D39921
2024-01-31 14:48:26 -08:00
Robert Wing 0013741108 powerpc_mmu_radix: add leaf page for wired mappings when pmap_enter(psind=1)
This applies the fix to powerpc's pmap as was done in commit aa3bcaad51
and d0941ed9b5 for amd64 and riscv pmaps, respectively.

Reported by:    Jenkins
Reviewed by:	bojan.novkovic_fer.hr, markj
Fixes: e4078494f3
Differential Revision:	https://reviews.freebsd.org/D43339
2024-01-09 11:23:18 -09:00
Warner Losh fdafd315ad sys: Automated cleanup of cdefs and other formatting
Apply the following automated changes to try to eliminate
no-longer-needed sys/cdefs.h includes as well as now-empty
blank lines in a row.

Remove /^#if.*\n#endif.*\n#include\s+<sys/cdefs.h>.*\n/
Remove /\n+#include\s+<sys/cdefs.h>.*\n+#if.*\n#endif.*\n+/
Remove /\n+#if.*\n#endif.*\n+/
Remove /^#if.*\n#endif.*\n/
Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/types.h>/
Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/param.h>/
Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/capsicum.h>/

Sponsored by:		Netflix
2023-11-26 22:24:00 -07:00
Doug Moore 8763b9862f powerpc pmap: initialize kernel pmap radix trie
Commit 2d2bcba7ba changed radix trie
implementation and made it necessary that radix tries be initialized
with vm_radix_init. @dbaio reports that in some configurations, there
is a powerpc boot panic and that this commit introduced the
problem. In powerpc/aim/mmu_radix.c, the radix trie in kernel_pmap is
initialized by zeroing all its fields.

Add a call to vm_radix_init to properly initialize
kernel_pmap->pm_radix.

Reported by:	dbaio
Reviewed by:	alc, jhibbits
Fixes:	2d2bcba7ba drop NULL check from radix trie search
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D41846
2023-09-13 13:17:57 -05:00
Doug Moore e5635c3dab powerpc_mmu_radix: include vm_radix.h file
Replacing _vm_radix.h with vm_radix.h in one header file leaves one
source file short of function definitions.  Include vm_radix.h in that
source file.

Fixes a problem rooted in change 429c871ddd.
2023-09-12 14:35:48 -05:00
Warner Losh 685dc743dc sys: Remove $FreeBSD$: one-line .c pattern
Remove /^[\s*]*__FBSDID\("\$FreeBSD\$"\);?\s*\n/
2023-08-16 11:54:36 -06:00
Warner Losh 71625ec9ad sys: Remove $FreeBSD$: one-line .c comment pattern
Remove /^/[*/]\s*\$FreeBSD\$.*\n/
2023-08-16 11:54:24 -06:00
Warner Losh 95ee2897e9 sys: Remove $FreeBSD$: two-line .h pattern
Remove /^\s*\*\n \*\s+\$FreeBSD\$$\n/
2023-08-16 11:54:11 -06:00
Warner Losh 4d846d260e spdx: The BSD-2-Clause-FreeBSD identifier is obsolete, drop -FreeBSD
The SPDX folks have obsoleted the BSD-2-Clause-FreeBSD identifier. Catch
up to that fact and revert to their recommended match of BSD-2-Clause.

Discussed with:		pfg
MFC After:		3 days
Sponsored by:		Netflix
2023-05-12 10:44:03 -06:00
John Baldwin 9b02f2daf4 powerpc: Use valid prototypes for function declarations with no arguments.
Reviewed by:	emaste
Differential Revision:	https://reviews.freebsd.org/D39733
2023-04-24 08:53:50 -07:00
Dimitry Andric d142601887 powerpc: fix a few pmap related functions to return correct types
While experimenting with changing boolean_t to another type, I noticed
that several powerpc pmap related functions returned the wrong type:
boolean_t instead of int.

Fix several declarations and definitions to match the actual pmap
function types: pmap_dev_direct_mapped_t and pmap_ts_referenced_t.

MFC after:	3 days
2023-04-23 15:23:04 +02:00
Justin Hibbits 379e14ba6c powerpc/pmap: Account for a potential NULL pmap in pmap_sync_icache
It's apparently possible for pcpu->pc_curpmap to be NULL at some point,
leading to a panic.  Account for this as is done with the other 64-bit
AIM pmap.

Reported by:	pkubaj
Tested by:	pkubaj
Fixes:		6f0b2a235a ("Add pmap_sync_icache() for radix pmap")
MFC after:	3 days
2023-03-21 09:56:26 -04:00
Justin Hibbits 6f0b2a235a powerpc/pmap: Add pmap_sync_icache() for radix pmap
DTrace pid provider writes to user space to set breakpoints.  Failing to
sync the icache can lead to SIGTRAP.  Radix pmap is the only one missing
a pmap_sync_icache() method, so the pid provider would only potentially
crash a process on a POWER9 or later system.
2023-03-12 11:51:42 -04:00
Piotr Kubaj 429ba161fb powerpc: fix warning: a function declaration without a prototype is deprecated in all versions of C
Reviewers: #powerpc
Approved by: alfredo

Subscribers: imp, jhibbits

Differential Revision: https://reviews.freebsd.org/D38787
2023-02-26 01:00:19 +01:00
Alfredo Dal'Ava Junior ff80ab1ceb powerpc: slb_alloc_user_cache: fix missing uma_zalloc wait flag
Flags should be M_WAITOK | M_ZERO instead of just M_ZERO

Reviewed by:	markj
MFC after:	2 days
Sponsored by:	Instituto de Pesquisas Eldorado (eldorado.org.br)
Differential Revision:	https://reviews.freebsd.org/D36865
2022-10-03 20:56:41 -03:00
John Baldwin f49fd63a6a kmem_malloc/free: Use void * instead of vm_offset_t for kernel pointers.
Reviewed by:	kib, markj
Sponsored by:	DARPA
Differential Revision:	https://reviews.freebsd.org/D36549
2022-09-22 15:09:19 -07:00
John Baldwin 7ae99f80b6 pmap_unmapdev/bios: Accept a pointer instead of a vm_offset_t.
This matches the return type of pmap_mapdev/bios.

Reviewed by:	kib, markj
Sponsored by:	DARPA
Differential Revision:	https://reviews.freebsd.org/D36548
2022-09-22 15:08:52 -07:00
John Baldwin e663907366 Define _NPCM and the last PC_FREEn constant in terms of _NPCPV.
This applies one of the changes from
5567d6b441 to other architectures
besides arm64.

Reviewed by:	kib
Sponsored by:	DARPA
Differential Revision:	https://reviews.freebsd.org/D36263
2022-08-23 13:31:02 -07:00
Dimitry Andric ff490346fd Adjust function definition in moea64_native.c to avoid clang 15 warning
With clang 15, the following -Werror warning is produced:

    sys/powerpc/aim/moea64_native.c:306:22: error: a function declaration without a prototype is deprecated in all versions of C [-Werror,-Wstrict-prototypes]
    moea64_install_native()
                         ^
                          void

This is because moea64_install_native() is declared with a (void)
argument list, but defined with an empty argument list. Make the
definition match the declaration.

MFC after:	3 days
2022-08-15 20:48:35 +02:00
Dimitry Andric 3446738e8d Fix unused variable warning in mmu_radix.c
With clang 15, the following -Werror warning is produced:

    sys/powerpc/aim/mmu_radix.c:5409:22: error: variable 'freed' set but not used [-Werror,-Wunused-but-set-variable]
            int allfree, field, freed, idx;
                                ^

The 'freed' variable is only used when PV_STATS is defined. Ensure it is
only declared and set in that case.

MFC after:	3 days
2022-08-15 20:48:34 +02:00
Dimitry Andric fb203abd9d Adjust function definitions in mmu_radix.c to avoid clang 15 warnings
With clang 15, the following -Werror warnings are produced:

    sys/powerpc/aim/mmu_radix.c:786:20: error: a function declaration without a prototype is deprecated in all versions of C [-Werror,-Wstrict-prototypes]
    mmu_radix_tlbie_all()
                       ^
                        void
    sys/powerpc/aim/mmu_radix.c:3615:15: error: a function declaration without a prototype is deprecated in all versions of C [-Werror,-Wstrict-prototypes]
    mmu_radix_init()
                  ^
                   void
    sys/powerpc/aim/mmu_radix.c:6081:20: error: a function declaration without a prototype is deprecated in all versions of C [-Werror,-Wstrict-prototypes]
    mmu_radix_scan_init()
                       ^
                        void

This is because mmu_radix_tlbie_all(), mmu_radix_init(), and
mmu_radix_scan_init() are declared with (void) argument lists, but
defined with empty argument lists. Make the definitions match the
declarations.

MFC after:	3 days
2022-08-15 20:48:34 +02:00
Dimitry Andric 7a98c884f2 Adjust function definitions in mmu_oea64.c to avoid clang 15 warnings
With clang 15, the following -Werror warnings are produced:

    sys/powerpc/aim/mmu_oea64.c:1947:12: error: a function declaration without a prototype is deprecated in all versions of C [-Werror,-Wstrict-prototypes]
    moea64_init()
               ^
                void
    sys/powerpc/aim/mmu_oea64.c:3257:17: error: a function declaration without a prototype is deprecated in all versions of C [-Werror,-Wstrict-prototypes]
    moea64_scan_init()
                    ^
                     void

This is because moea64_init() and moea64_scan_init() are declared with
(void) argument lists, but defined with empty argument lists. Make the
definitions match the declarations.

MFC after:	3 days
2022-08-15 20:48:34 +02:00
Dimitry Andric 06fce030e7 Adjust function definition in aim_machdep.c to avoid clang 15 warning
With clang 15, the following -Werror warning is produced:

    sys/powerpc/aim/aim_machdep.c:750:14: error: a function declaration without a prototype is deprecated in all versions of C [-Werror,-Wstrict-prototypes]
    mpc745x_sleep()
                 ^
                  void

This is because mpc745x_sleep() is declared with a (void) argument list,
but defined with an empty argument list. Make the definition match the
declaration.

MFC after:	3 days
2022-08-15 20:48:34 +02:00
Konstantin Belousov c6d31b8306 AST: rework
Make most AST handlers dynamically registered.  This allows to have
subsystem-specific handler source located in the subsystem files,
instead of making subr_trap.c aware of it.  For instance, signal
delivery code on return to userspace is now moved to kern_sig.c.

Also, it allows to have some handlers designated as the cleanup (kclear)
type, which are called both at AST and on thread/process exit.  For
instance, ast(), exit1(), and NFS server no longer need to be aware
about UFS softdep processing.

The dynamic registration also allows third-party modules to register AST
handlers if needed.  There is one caveat with loadable modules: the
code does not make any effort to ensure that the module is not unloaded
before all threads processed through AST handler in it.  In fact, this
is already present behavior for hwpmc.ko and ufs.ko.  I do not think it
is worth the efforts and the runtime overhead to try to fix it.

Reviewed by:	markj
Tested by:	emaste (arm64), pho
Discussed with:	jhb
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D35888
2022-08-02 21:11:09 +03:00
John Baldwin 1c311640c0 powerpc: Use __diagused for variables only used in KASSERT(). 2022-04-13 16:08:23 -07:00
John Baldwin 7e7f7b91d0 powerpc cpudep_ap_setup: Quite unused variable warnings. 2022-04-12 14:58:59 -07:00
John Baldwin da8b238529 powerpc: Remove unused variables. 2022-04-12 14:58:58 -07:00
John Baldwin c9d26ca24c ppc mmoea64: Workaround set but unused warnings for RB_NEXT.
Inline the unused expression passed as the second argument to RB_NEXT.
2022-04-12 14:58:58 -07:00
John Baldwin 8d95af873f ppc aim flush_disable_caches: Use void casts instead of a dummy variable. 2022-04-12 14:58:58 -07:00
Gordon Bergling f259d24fa5 powerpc: Fix two typos in source code comments
- s/mutiplying/multiplying/

MFC after:	3 days
2022-04-09 09:14:07 +02:00
Warner Losh 47796d47ec powerpc/aim: ifdef DDB pmap debugging functions
INVARIANTS and DDB can be enabled independently.

Submitted by: Sterling Jensen
Pull Request: https://github.com/freebsd/freebsd-src/pull/566
2022-01-07 08:56:57 -07:00
Leandro Lupori a076e2060c powerpc64: fix the calculation of Maxmem
The calculation of Maxmem was skipping the last phys_avail segment,
because of a wrong stop condition.

This was detected when using QEMU/PowerNV with Radix MMU and low
memory (2G). In this case opal_pci would allocate a DMA window that
was too small to cover all physical memory, resulting in reading all
zeroes from disk when using memory that was not inside the allocated
window.

Reviewed by:		jhibbits
Sponsored by:		Instituto de Pesquisas Eldorado (eldorado.org.br)
Differential Revision:	https://reviews.freebsd.org/D33449
MFC after:		2 weeks
2021-12-15 08:49:47 -03:00
Leandro Lupori e141b62d20 powerpc64le: fix boot when using QEMU PowerNV
When using QEMU PowerNV with latest op-build release (v2.7), its
kexec transfers control to FreeBSD kernel in BE mode, causing an
instant exception on LE kernels. Make kboot able to detect and
swap endian to fix this.

Reviewed by:		imp
Sponsored by:		Instituto de Pesquisas Eldorado (eldorado.org.br)
Differential Revision:	https://reviews.freebsd.org/D33104
2021-11-25 16:41:46 -03:00
Mitchell Horne 10fe6f80a6 minidump: Use the provided dump bitset
When constructing the set of dumpable pages, use the bitset provided by
the state argument, rather than assuming vm_page_dump invariably. For
normal kernel minidumps this will be a pointer to vm_page_dump, but when
dumping the live system it will not.

To do this, the functions in vm_dumpset.h are extended to accept the
desired bitset as an argument. Note that this provided bitset is assumed
to be derived from vm_page_dump, and therefore has the same size.

Reviewed by:	kib, markj, jhb
MFC after:	2 weeks
Sponsored by:	Juniper Networks, Inc.
Sponsored by:	Klara, Inc.
Differential Revision:	https://reviews.freebsd.org/D31992
2021-11-19 15:05:52 -04:00
Kyle Evans 589aed00e3 sched: separate out schedinit_ap()
schedinit_ap() sets up an AP for a later call to sched_throw(NULL).

Currently, ULE sets up some pcpu bits and fixes the idlethread lock with
a call to sched_throw(NULL); this results in a window where curthread is
setup in platforms' init_secondary(), but it has the wrong td_lock.
Typical platform AP startup procedure looks something like:

- Setup curthread
- ... other stuff, including cpu_initclocks_ap()
- Signal smp_started
- sched_throw(NULL) to enter the scheduler

cpu_initclocks_ap() may have callouts to process (e.g., nvme) and
attempt to sched_add() for this AP, but this attempt fails because
of the noted violated assumption leading to locking heartburn in
sched_setpreempt().

Interrupts are still disabled until cpu_throw() so we're not really at
risk of being preempted -- just let the scheduler in on it a little
earlier as part of setting up curthread.

Reviewed by:	alfredo, kib, markj
Triage help from:	andrew, markj
Smoke-tested by:	alfredo (ppc), kevans (arm64, x86), mhorne (arm)
Differential Revision:	https://reviews.freebsd.org/D32797
2021-11-03 15:54:59 -05:00
Mark Johnston ff93447d8e Use the vm_radix_init() helper when initializing pmaps
No functional change intended.

Reviewed by:	alc, kib
MFC after:	1 week
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D32527
2021-10-19 21:22:56 -04:00
Mark Johnston 84c3922243 Convert consumers to vm_page_alloc_noobj_contig()
Remove now-unneeded page zeroing.  No functional change intended.

Reviewed by:	alc, hselasky, kib
MFC after:	1 week
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D32006
2021-10-19 21:22:56 -04:00
Mark Johnston a4667e09e6 Convert vm_page_alloc() callers to use vm_page_alloc_noobj().
Remove page zeroing code from consumers and stop specifying
VM_ALLOC_NOOBJ.  In a few places, also convert an allocation loop to
simply use VM_ALLOC_WAITOK.

Similarly, convert vm_page_alloc_domain() callers.

Note that callers are now responsible for assigning the pindex.

Reviewed by:	alc, hselasky, kib
MFC after:	1 week
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D31986
2021-10-19 21:22:56 -04:00
Leandro Lupori 8ecf9a8bab powerpc64: make radix with superpages default
As Radix MMU with superpages enabled is now stable, make it the
default choice on supported hardware (POWER9 and above), since its
performance is greater than that of HPT MMU.

Reviewed by:		alfredo, jhibbits
Sponsored by:		Instituto de Pesquisas Eldorado (eldorado.org.br)
Differential Revision:	https://reviews.freebsd.org/D30797
2021-10-14 13:13:27 -03:00
Leandro Lupori 76384bd10f powerpc64: fix OFWFB with Radix MMU
Current implementation of Radix MMU doesn't support mapping
arbitrary virtual addresses, such as the ones generated by
"direct mapping" I/O addresses. This caused the system to hang, when
early I/O addresses, such as those used by OpenFirmware Frame Buffer,
were remapped after the MMU was up.

To avoid having to modify mmu_radix_kenter_attr just to support this
use case, this change makes early I/O map use virtual addresses from
KVA area instead (similar to what mmu_radix_mapdev_attr does), as
these can be safely remapped later.

Reviewed by:		alfredo (earlier version), jhibbits (in irc)
MFC after:		2 weeks
Sponsored by:		Instituto de Pesquisas Eldorado (eldorado.org.br)
Differential Revision:	https://reviews.freebsd.org/D31232
2021-10-14 10:39:52 -03:00
Mitchell Horne 31991a5a45 minidump: De-duplicate is_dumpable()
The function is identical in each minidump implementation, so move it to
vm_phys.c. The only slight exception is powerpc where the function was
public, for use in moea64_scan_pmap().

Reviewed by:	kib, markj, imp (earlier version)
MFC after:	2 weeks
Sponsored by:	Juniper Networks, Inc.
Sponsored by:	Klara, Inc.
Differential Revision:	https://reviews.freebsd.org/D31884
2021-09-29 16:41:52 -03:00
Leandro Lupori 4f7c436548 powerpc64: fix radix on pseries TLB invalidation
When running in a virtualized environment, TLB invalidations can only
be performed on process scope, as only the hypervisor is allowed to
invalidate a global scope, or else a Program Interrupt is triggered.

Since we are here, also make sure that the register process table
hypercall returns success.

Reviewed by:		jhibbits
MFC after:		2 weeks
Sponsored by:		Instituto de Pesquisas Eldorado (eldorado.org.br)
Differential Revision:	https://reviews.freebsd.org/D31775
2021-09-08 08:37:11 -03:00
Andrew Turner b792434150 Create sys/reg.h for the common code previously in machine/reg.h
Move the common kernel function signatures from machine/reg.h to a new
sys/reg.h. This is in preperation for adding PT_GETREGSET to ptrace(2).

Reviewed by:	imp, markj
Sponsored by:	DARPA, AFRL (original work)
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D19830
2021-08-30 12:50:53 +01:00
Justin Hibbits 5ae48eb998 powerpc/pseries: Allow radix pmap in pseries for ISA 3.0
ISA 3.0 allows for nested radix translations with minimal to no
involvement of the hypervisor.  This should make pseries signficantly
faster on POWER9 pseries instances, as fewer hypercalls are needed to
manage pmap now.

MFC after:	2 weeks
Relnotes:	yes
2021-08-11 19:07:04 -05:00
Mark Johnston b092c58c00 Assert that valid PTEs are not overwritten when installing a new PTP
amd64 and 32-bit ARM already had assertions to this effect.  Add them to
other pmaps.

Reviewed by:	alc, kib
MFC after:	2 weeks
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D31171
2021-07-15 12:17:33 -04:00
Justin Hibbits d7bfb412a7 powerpc64le/pmap: Fix superpage promotions
The page table is always big endian.  Without byte swapping on LE, the
promotion ability checks were invalid, and superpage promotions always
failed.
2021-06-05 21:49:42 -05:00
Justin Hibbits 811e645d28 Apply r350463(43ded0a321) to powerpc64 radix pmap
Invalidate the last page of a demoted superpage mapping, instead of the
first page, as it results in slightly more promotions and fewer
failures.  While here, replace 'boolean_t's with 'bool's in
mmu_radix_advise().
2021-05-29 15:14:33 -05:00