Commit graph

1568 commits

Author SHA1 Message Date
Konstantin Belousov
58d1fdfaa9 amd iommu: remove unused function
Sponsored by:	Advanced Micro Devices (AMD)
Sponsored by:	The FreeBSD Foundation
MFC after:	3 days
2024-12-16 00:49:52 +02:00
Bojan Novković
7bcaff0522 x86: Add routines for querying XSAVE feature information
This patch adds several routines that track and expose information
about various XSAVE-related features. More specifically, it adds the
ability to check whether a given XFEATURE is supported and which XSAVE
extensions are supported. Furthermore, it adds several routines for
calculating the size and offsets within a save area given a XSAVE
feature bitmap.

Reviewed by:	kib
Differential Revision:	https://reviews.freebsd.org/D47394
2024-12-15 16:39:36 +01:00
Bojan Novković
0c4fa0bdcf x86: Add definitions for some Intel Processor Trace bits
This patch adds definitions for Intel PT-related MSRs and
several PT feature bits.

Reviewed by:	kib, markj
Differential Revision:	https://reviews.freebsd.org/D46419
2024-12-15 16:39:36 +01:00
Bojan Novković
04e8326721 x86: Allow sharing of perfomance counter interrupts
This patch refactors the Performance Counter interrupt setup code to
allow sharing the interrupt line between multiple drivers.
More specifically, Performance Counter interrupts are used by both
hwpmc(4) and hwt(4)'s upcoming Intel Processor Trace backend.

Reviewed by:	kib
Differential Revision:	https://reviews.freebsd.org/D46420
2024-12-15 16:39:36 +01:00
Bojan Novković
459dc42787 x86: Refactor kernel-mode NMI handling
This refactor aims to add the ability to share performance counter
interrupts by refactoring the kernel-mode NMI handler. The handler now
allows multiple drivers to service the same interrupt (e.g. hwpmc(4)
and hwt(4)'s Intel Processor Trace backend).

Reviewed by:	kib, avg
Differential Revision:	https://reviews.freebsd.org/D46421
2024-12-15 16:39:36 +01:00
Elliott Mitchell
90fb07edbd intr/x86: add ioapic_drv_t to reduce number of casts in IO-APIC implementation
void * is handy when you truly do not care about the type.  Yet there is
so much casting back and forth in the IO-APIC code as to be hazardous.
Achieve better static checking by the compiler using a typedef.

Reviewed by: imp
Pull Request: https://github.com/freebsd/freebsd-src/pull/1457
2024-12-11 16:14:30 -07:00
Elliott Mitchell
638b29fe65 x86/atpic: convert INTSRC() macro into designated initializer
Move to using C99 initializers. These make the macros more
understandable and easier to use.

Reviewed by: imp
Pull Request: https://github.com/freebsd/freebsd-src/pull/1457
2024-12-11 15:54:09 -07:00
Konstantin Belousov
53adc0b898 amdiommu: correctly initialize iommu.unit
The field is mostly used for display, and should match device unit, not
BIOS IVHD device id, which is deprecated and is practically zero.

Sponsored by:	Advanced Micro Devices (AMD)
Sponsored by:	The FreeBSD Foundation
MFC after:	3 days
2024-12-07 03:54:01 +02:00
John Baldwin
18250ec6c0 Replace calls to bus_generic_attach with bus_attach_children
Reviewed by:	imp
Differential Revision:	https://reviews.freebsd.org/D47675
2024-12-06 17:26:16 -05:00
John Baldwin
723da5d92f Replace calls to bus_generic_probe with bus_identify_children
Reviewed by:	imp
Differential Revision:	https://reviews.freebsd.org/D47674
2024-12-06 17:26:05 -05:00
Elliott Mitchell
839fb85336 intr/x86: cleanup io_apic device method tables
Replace the { 0, 0 } construct with the preferred DEVMETHOD_END.  Add
a space after to indicate it is separate from the section above.

Reviewed by: imp
Pull Request: https://github.com/freebsd/freebsd-src/pull/1457
2024-12-06 11:56:32 -07:00
Elliott Mitchell
bd6cd409a9 x86: remove LOCORE: No longer needed
Remove the #ifdef LOCORE. No assembly file includes this file since the
XEN update of 1a52c10530.

Pull-Request: https://github.com/freebsd/freebsd-src/pull/1286
2024-12-05 19:07:45 -07:00
Kristof Provost
daad0b6501 LINT: Remove DTrace support, but leave the commented out option
Fixes:		2f91534563
Reported by:	John Baldwin <jhb@FreeBSD.org>
Sponsored by:	Rubicon Communications, LLC ("Netgate")
2024-12-03 16:59:50 +01:00
Kristof Provost
2f91534563 LINT: Remove DTrace support
Ensure we have at least one commonly built kernel config that does not include
DTrace.
This is intended to help detect issues such as 45d108ee14 where a variable is
only used for static probe point, resulting in build failures when DTrace is
disabled.

Sponsored by:	Rubicon Communications, LLC ("Netgate")
Differential Revision:	https://reviews.freebsd.org/D47821
2024-12-02 20:36:35 +01:00
Joshua Rogers
0b32ef71f9 vmm: Correctly suspend and resume the vmm driver.
Previously, VMXON would be executed on a resume, contrary to proper
initalization. The contents of MSR_IA32_FEATURE_CONTROL may be lost on
suspension, therefore must be restored. Likewise, the VMX Enable bit may be
cleared upon suspend, requiring it to be re-set.

Concretely disable VMX on suspend, and re-enable it on resume.

Note: any IOMMU context will remain lost for any enabled vmm devices.

Signed-off-by: Joshua Rogers <Joshua@Joshua.Hu>
Reviewed by: jhb,imp
Pull Request: https://github.com/freebsd/freebsd-src/pull/1419
2024-11-29 14:38:35 -07:00
Konstantin Belousov
3f0289ea7f dmar: set acpi ivar domain on identify()
Reviewed by:	jhb
Sponsored by:	Advanced Micro Devices (AMD)
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D47291
2024-11-26 23:56:45 +02:00
Mark Johnston
ef9ffb8594 kern: Make fileops and filterops tables const where possible
No functional change intended.

MFC after:	1 week
2024-11-26 21:04:21 +00:00
Jason A. Harmening
31e796c86d amdiommu: use static array for device table base register offsets
This is a somewhat cleaner and more future-proof way to get the correct
device table offsets.

Reviewed by:		kib
Reported by:		crest_freebsd_rlwinm.de
Fixes:			5035db22 "amdiommu: Fix device table segment
			base register offsets"
Differential Revision:	https://reviews.freebsd.org/D47769
2024-11-26 14:14:25 -06:00
Bojan Novković
b42b18fb24 x86: Add definitions for XSAVE state component information
Reviewed by: kib
2024-11-26 19:16:05 +01:00
Jason A. Harmening
5035db222e amdiommu: Fix device table segment base register offsets
Segment base registers are at 8-byte intervals, while the register
write helper takes a byte-aligned offset.  This fixes
DEV_TAB_HARDWARE_ERROR events and associated peripheral I/O failures
on an Epyc-based system with 8-segment device tables.

Reviewed by:		kib
Differential Revision:	https://reviews.freebsd.org/D47752
2024-11-25 21:40:45 -06:00
Konstantin Belousov
9805e5b071 amdiommu: short-circuit all amdiommu_find_unit() functions
for the case where amdiommu is not enabled.  In this case, it does not
matter if IVHD does not describe some device.  Similarly, no unit can be
found for a device, because units are not instantiated, but it does not
matter.

Reported by:	mav
Sponsored by:	Advanced Micro Devices (AMD)
Sponsored by:	The FreeBSD Foundation
MFC after:	3 days
2024-11-10 00:32:37 +02:00
Konstantin Belousov
1bca58a1d4 amdiommu: hide HPET report under verbose
Reported by:	markj
Sponsored by:	Advanced Micro Devices (AMD)
Sponsored by:	The FreeBSD Foundation
MFC after:	3 days
2024-11-09 23:07:41 +02:00
Andrew Gallatin
fd67ff5c7a Use the correct idle routine on recent AMD EPYC servers
We have been incorrectly choosing the "hlt" idle method on modern AMD
EPYC servers for C1 idle. This is because AMD also uses the Functional
Fixed Hardware interface. Due to not parsing the table properly for
AMD, and due to a weird quirk where the mwait latency for C1 is
mis-interpreted as the latency for hlt, we wind up choosing hlt for
c1, which has a far higher wake up latency (similar to IO) of roughly
400us on my test system (AMD 7502P).

This patch fixes this by:

- Looking for AMD in addition to Intel in the FFH
 (Note the vendor id of "2" for AMD is not publically documented, but
 AMD has confirmed they are using "2" and has promised to document it.)

- Using mwait on AMD when specified in the table, and when CPUid says
 its supported

- Fixing a weird issue where we copy the contents of cx_ptr for C1 and
 when moving to C2, we do not reinitialize cx_ptr. This leads to
 mwait being selected, and ignoring the specified i/o halt method
 unless we clear mwait before looking at the table for C2.

Differential Revision: https://reviews.freebsd.org/D47444
Reviewed by: dab, kib, vangyzen
Sponsored by: Netflix
2024-11-08 17:10:44 -05:00
Mark Johnston
ff84f8b536 iommu: Clean up a lingering function prototype
Reported by:	clang
Fixes:		d97838b7c2 ("iommu: eliminate iommu_free_ctx()")
2024-11-04 19:38:22 +00:00
Konstantin Belousov
43bfb4e714 amdiommu: print more domain information from ddb show
Sponsored by:	Advanced Micro Devices (AMD)
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
2024-11-03 21:38:19 +02:00
Konstantin Belousov
d97838b7c2 iommu: eliminate iommu_free_ctx()
iommu_free_ctx_locked() alone is enough

Sponsored by:	Advanced Micro Devices (AMD)
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
2024-11-03 21:38:19 +02:00
Konstantin Belousov
57aebec4f7 x86/iommu/amd_reg.h: fix typo in comment
Sponsored by:	Advanced Micro Devices (AMD)
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
2024-11-03 21:38:19 +02:00
Konstantin Belousov
0f5116d7ef AMD IOMMU driver
This driver is functionally equivalent to the in-tree Intel DMAR code.
It handles busdma and interrupt remapping from the host OS.  There is no
integration with bhyve, and the stub iommu drivers in bhyve code cannot
coexist with this driver (planned).

The biggest architectural problem with the code is that the AMD IOMMU
units are enumerated as PCIe-attached security devices, which is much
later after HPET and IOAPIC drivers attached and actived interrupts.
Because of this, HPET FSB interrupts and IOAPIC interrupts are always
identity-mapped.

The code is of late alpha quality.  By default the driver is disabled.
To enable for testing, set in loader.conf:
hw.amdiommu.enable=1
hw.iommu.dma=1 <- to enable iommu busdma
hw.iommu.ir=1 <- to enable interrupt remapping

Discussed with:	emaste
Sponsored by:	Advanced Micro Devices (AMD)
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D47256
2024-11-03 01:45:40 +02:00
Konstantin Belousov
0a9bec1744 x86/iommu/amd_reg.h: AMD IOMMU registers definitions
Reviewed by:	emaste
Sponsored by:	Advanced Micro Devices (AMD)
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D47255
2024-11-03 01:45:40 +02:00
John Baldwin
df61573596 x86: Remove invalid DEVMETHOD methods for leaf devices
None of these drivers are for bus devices, so bus_generic_* is not
appropriate.  Most of these were nops except that detach would
actually "succeed" (but not do any cleanup).

Reviewed by:	imp
Differential Revision:	https://reviews.freebsd.org/D47374
2024-11-01 10:10:30 -04:00
Konstantin Belousov
439fa16e1f x86: do not leak msi_lock in msix_alloc() on iommu remapping failure
Sponsored by:	Advanced Micro Devices (AMD)
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
2024-10-27 03:50:15 +02:00
Konstantin Belousov
9f718b57b8 x86 specialreg: add bit masks definitions for LASS and LAM features
in CPUID Structured Extended Features %eax 0x7 leaf 1 %eax, from
Intel SDM vol. 2 rev. 085.

Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
2024-10-24 05:41:11 +03:00
Konstantin Belousov
6308db659f x86 specialreg: add bit masks definitions for EFER features
listed in AMD64 APM vol.2 rev. 3.42.

Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
2024-10-24 05:41:10 +03:00
Konstantin Belousov
5999b74e96 x86 specialreg: add bit masks definitions for LAM in %cr3
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
2024-10-24 05:41:10 +03:00
Konstantin Belousov
cc4b25f102 x86 specialreg: reorder %cr3 bits masks definitions by value
and align them visually.

Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
2024-10-24 05:41:10 +03:00
Konstantin Belousov
cc11bc1150 x86 specialreg.h: add all defined bits for %cr4
taken from Intel SDM rev. 085

Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
2024-10-24 05:41:10 +03:00
Konstantin Belousov
2ac21f2c98 x86 specialreg.h: visually align %cr4 and MSR_EFER bit mask definitions
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
2024-10-24 05:41:10 +03:00
Konstantin Belousov
705090cba4 DMAR: handle affinity for in-memory data structures
Reviewed and tested by:	markj
Sponsored by:	Advanced Micro Devices (AMD)
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D47254
2024-10-23 23:00:10 +03:00
John Baldwin
ab4f969f8d legacy cpu: Add proper device_probe and device_attach routines
Set a device description in probe and handle both adding and attaching
children in attach.

Reviewed by:	imp
Differential Revision:	https://reviews.freebsd.org/D47185
2024-10-21 10:24:28 -04:00
Konstantin Belousov
b08d332da0 devices: report iommu data for the device in the dev. sysctl tree
Show the iommu unit' device name/unit which translates the device'
requests, if any, as parsed out from the BIOS tables.
Also show the rid value for the device.

Sponsored by:	Advanced Micro Devices (AMD)
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D47098
2024-10-17 17:31:50 +03:00
Konstantin Belousov
ea4e4449b8 apic: add ioapic_get_dev() method
which returns apic device_t by apic_id, if there exists the pci representer

Sponsored by:	Advanced Micro Devices (AMD)
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
2024-10-17 17:31:50 +03:00
Kristof Provost
96f1dfc1be acpi_sbl_wmi: add a driver to trigger SBL firmware updates
Expose a sysctl knob to inform the SBL bootloader that a firmware update is
available and should be applied on the next reboot.

See also:	https://slimbootloader.github.io/security/firmware-update.html#triggering-firmware-update
Sponsored by:	Rubicon Communications, LLC ("Netgate")
Differential Revision:	https://reviews.freebsd.org/D47035
2024-10-15 16:29:11 +02:00
Konstantin Belousov
c9e22c749c iommu: extract driver-independent ddb context and mapping reporting
Sponsored by:	Advanced Micro Devices (AMD)
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
2024-10-14 01:30:26 +03:00
Konstantin Belousov
e9d948cfe0 iommu: move context link and ref count into device-independent parts
This also allows to move some bits of ddb print routines into
iommu_utils.c common for x86 iommu drivers.

Sponsored by:	Advanced Micro Devices (AMD)
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
2024-10-14 01:30:26 +03:00
Konstantin Belousov
eb8326421e iommu_qi_seq_processed: use atomic to read hw-written seq number
otherwise iommu_qi_wait_for_seq() can be legitimately optimized out.

Sponsored by:	Advanced Micro Devices (AMD)
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
2024-10-03 09:19:09 +03:00
Konstantin Belousov
3848dc4fe6 dmar: on unmap, postpone freeing page table pages after the invalidation is done
IOMMU is free to access page tables until we invalidate them

Sponsored by:	Advanced Micro Devices (AMD)
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
2024-09-27 20:34:23 +03:00
Konstantin Belousov
f713ed6694 iommu: extend iommu_map_entry to store the list of associated freed page table pages
The pages are inserted into the added slist if the entry parameter is
passed to iommu_pgfree().  For now it is nop.

Sponsored by:	Advanced Micro Devices (AMD)
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
2024-09-27 20:34:23 +03:00
Konstantin Belousov
bdd5eb33ca iommu: change iommu_domain_map_ops to take iommu_map_entry
instead of base/size.

Sponsored by:	Advanced Micro Devices (AMD)
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
2024-09-27 20:34:23 +03:00
Konstantin Belousov
d50403a691 iommu: add per-unit sysctls reporting the state of DMA and interrupt remapping
Sponsored by:	Advanced Micro Devices (AMD)
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
2024-09-27 20:34:23 +03:00
Konstantin Belousov
10ebd230f4 intel_idpgtbl.c: rename domain_* functions to dmar_*
Sponsored by:	Advanced Micro Devices (AMD)
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
2024-09-27 20:34:23 +03:00