aboutsummaryrefslogtreecommitdiff
path: root/sys/xen
Commit message (Collapse)AuthorAgeFilesLines
* bus: Document special ranges of IVARsJohn Baldwin2026-02-171-1/+1
| | | | | | | | | | | | | Some IVAR indices are special in that they have global meaning across multiple buses where as other IVARs are always private to the local bus. Try to document this a bit and add constants for the various ranges to avoid future conflicts. This is a no-op, but IVAR indices are now generally defined as enums as that makes it easier to define them in terms of ranges. Reviewed by: imp, royger, andrew Differential Revision: https://reviews.freebsd.org/D54159
* sys/xen: Use __printflike() instead of format(printf)Alex Richardson2025-12-283-6/+6
| | | | | | | | The __printflike macro sets the format to freebsd_kprintf which recent clang understands and warns about. Fixes the following error: `passing 'printf' format string where 'freebsd_kprintf' format string is expected [-Werror,-Wformat]` MFC after: 1 week
* machine/stdarg.h -> sys/stdarg.hBrooks Davis2025-06-116-12/+6
| | | | | | | | | | | | | Switch to using sys/stdarg.h for va_list type and va_* builtins. Make an attempt to insert the include in a sensible place. Where style(9) was followed this is easy, where it was ignored, aim for the first block of sys/*.h headers and don't get too fussy or try to fix other style bugs. Reviewed by: imp Exp-run by: antoine (PR 286274) Pull Request: https://github.com/freebsd/freebsd-src/pull/1595
* x86/xen: Use intended values in HVM_CALLBACK_VECTORAlan Robinson2024-11-061-1/+1
| | | | | | | | | | | Replace the HVM_CB_GSI_GSI SHIFT and MASK with the existing but currently unused HVM_CB_VECTOR_VECTOR_SHIFT and MASK. The binary values are identical. Reviewed by: Elliott Mitchell <ehem+freebsd@m5p.com> Reviewed by: royger Pull request: https://github.com/freebsd/freebsd-src/pull/1490
* xen: introduce a per-arch scratch mapping rangesRoger Pau Monné2024-07-301-0/+5
| | | | | | | | | | | | | | | | | | | The current approach is to create foreign mappings in any unpopulated address on the memory map. This however can cause issues, as late-loaded drivers could then found their MMIO region has been stolen to be used as foreign mapping scratch space (due to the Xen drivers having started first). Add a local resource manager to the xenpv bus driver, architectures can add suitable resources to that resource manager at boot in order to be used in preference of the generic MMIO resource allocator. No functional change, as the introduced scratch mapping range is not yet populated. Sponsored by: Cloud Software Group MFC after: 1 week Reviewed by: Elliott Mitchell <ehem+freebsd@m5p.com> Differential revision: https://reviews.freebsd.org/D46122
* newbus: globally replace device_add_child(..., -1) with DEVICE_UNIT_ANYWarner Losh2024-07-251-1/+1
| | | | Sponsored by: Netflix
* x86/xen: introduce non-hypercall based emergency printRoger Pau Monné2024-02-221-0/+7
| | | | | | | | | | | | | | | | | | | | | The current xc_printf() function uses an hypercall in order to send character buffers to the hypervisor for it to print on the hypervisor console (if the hypervisor is configured to print such messages). This requires the hypercall page to be initialized, which is extra work and can go wrong. On x86 instead of using the console IO hypercall use the debug console IO port, also called "port E9 hack". This allows sending characters to Xen using an outb instruction, without any initialization required. Keep the previous hypervisor based implementation by using the weak attribute, which allows each architecture to provide an alternate (arch-specific) implementation. Sponsored by: Cloud Software Group Reviewed by: markj Differential revision: https://reviews.freebsd.org/D43929
* x86/xen: fix out of bounds access to the event channel masks on resumeRoger Pau Monné2024-02-221-2/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When resuming from migration or suspension all regular event channels ports are reset to the INVALID_EVTCHN value, and drivers should re-initialize them according to the new value provided by the other end of the connection. However, the driver would first attempt to unbind the event channel handler before attempting to bind it using the newly provided port. This unbind uses the stale event channel port that has been set to INVALID_EVTCHN for some operations (notably as a result of the handler removal the interrupt subsystem ends up calling disable intr and source PIC hooks). This was fine when INVALID_EVTCHN was 0, as then the operation would just result in pointless setting of the 0 bit in the different event channel related control arrays (evtchn_{pending,mask} for example). However with the change to define INVALID_EVTCHN as ~0 the write is no longer pointless, and we end up triggering a page-fault, or corrupting random data that happens to be mapped at the array position + ~0 bits. In hindsight the change of INVALID_EVTCHN from 0 to ~0 was way more risky than initially assessed, and I believe has end up resulting in more fragile code for no real benefit. Fix the disable intr and source wrappers to check whether the event channel is valid before attempting to use it. Also introduce some extra KASSERTs in several array accesses in order to avoid out of bounds accesses if INVALID_EVTCHN ever reaches those functions. Fixes: 1797ff962769 ('xen/intr: cleanup event channel number use') MFC after: 1 week Sponsored by: Cloud Software Group Reviewed by: markj Differential revision: https://reviews.freebsd.org/D43928
* xen: add atomic #defines to accomodate differing xen_ulong_t sizesElliott Mitchell2023-12-152-9/+9
| | | | | | | | Alas, ARM declared xen_ulong_t to be 64-bits long, unlike i386 where it matches the word size. As a result, compatibility wrappers are needed for Xen atomic operations. Reviewed by: royger
* xen: add SPDX license tags to Xen headersElliott Mitchell2023-12-152-0/+4
| | | | | | | | | These are in fact GPLv2 when distributed with the Linux kernel, but the license also allows MIT if distributed separately. Add the markers to avoid interference by automated tools. Differential Revision: https://reviews.freebsd.org/D32796 Reviewed by: royger
* xen: remove xen_domain_type enum/variableElliott Mitchell2023-11-282-16/+6
| | | | | | | | The vm_guest variable readily covers all uses of xen_domain_type, so merge them together. Since support for PV domains has been removed hard-core xen_pv_domain() to return false. Reviewed by: royger
* xen/dev: remove __unused from driver argument of identify functionsElliott Mitchell2023-11-281-1/+1
| | | | | | | The driver argument is most certainly now used by these functions. When originally implemented it might have been unused, but not now. Reviewed by: royger
* xen/dev: switch to DEVMETHOD_ENDElliott Mitchell2023-11-282-2/+4
| | | | | | | Switch to the preferred end of the device method table. These hadn't been updated previously. Reviewed by: royger
* xen/x86: move x86-only variable out of commonElliott Mitchell2023-11-281-1/+0
| | | | | | | | | Commit 27c36a12f15 is an x86-only feature. As such xen_evtchn_needs_ack should only exist on x86. Differential Revision: https://reviews.freebsd.org/D29913 Reviewed by: royger [royger]: adjust comment.
* xen: remove declaration of evtchn_device_upcall()Elliott Mitchell2023-11-281-3/+0
| | | | | | | | This function was removed at 5779d8ad577. Long past time to remove the declaration to ensure people aren't confused. Differential Revision: https://reviews.freebsd.org/D30865 Reviewed by: royger
* sys: Automated cleanup of cdefs and other formattingWarner Losh2023-11-275-5/+4
| | | | | | | | | | | | | | | | 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
* sys: Remove $FreeBSD$: one-line sh patternWarner Losh2023-08-163-3/+0
| | | | Remove /^\s*#[#!]?\s*\$FreeBSD\$.*$\n/
* sys: Remove $FreeBSD$: one-line .c patternWarner Losh2023-08-166-12/+0
| | | | Remove /^[\s*]*__FBSDID\("\$FreeBSD\$"\);?\s*\n/
* sys: Remove $FreeBSD$: two-line .h patternWarner Losh2023-08-1615-30/+0
| | | | Remove /^\s*\*\n \*\s+\$FreeBSD\$$\n/
* xen: move vcpu_info to common, leave hook for setupElliott Mitchell2023-07-212-0/+58
| | | | | | | | | | | | | | | | | | | | | | vcpu_info is crucial for the Xen event channel core. Since both the data and setup steps are identical between architectures, move them to the common file. Since there is no cross-architecture method to call a function on every processor during bring-up, simply leave the setup function. The number of vcpu_info structures available on the shared information page varies by architecture. Instead of hard-coding the count use nitems(). Add a warning message for this being used. Switch to XEN_VCPUID() and use Xen's typedefs. panic() on failure since >32 processors is no longer unusual. royger: Specify 64-byte alignment for vcpu_info to try to defend against vcpu_info crossing a page boundary. Add detection for this limit. Reviewed by: royger
* spdx: Remove duplicate linesWarner Losh2023-05-121-2/+0
| | | | | | Remove duplicated SPDX lines. Sponsored by: Netflix
* spdx: The BSD-2-Clause-FreeBSD identifier is obsolete, drop -FreeBSDWarner Losh2023-05-123-4/+4
| | | | | | | | | 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
* xen: move common variables off of sys/x86/xen/hvm.cElliott Mitchell2023-04-141-0/+51
| | | | | | | | | | | | The xen_domain_type and HYPERVISOR_shared_info variables are shared by all Xen architectures, so they should be in common rather than reimplemented by each architecture. hvm_start_flags is used by xen_initial_domain() and so needs to be in common. Reviewed by: royger Differential Revision: https://reviews.freebsd.org/D28982
* xen/intr: move evtchn_type to intr-internal.hElliott Mitchell2023-04-141-8/+0
| | | | | | | | | | | | The evtchn_type enum is only touched by the Xen interrupt code. Other event channel uses no longer need the value, so that has been moved to restrict its use. Copyright note. The current evtchn_type was introduced at 76acc41fb7c7 by Justin T. Gibbs. This in turn appears to have been heavily inspired by 30d1eefe3937 done by Kip Macy. Reviewed by: royger
* xen/intr: adjust xen_intr_handle_upcall() to match driver filterElliott Mitchell2023-04-141-1/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | xen_intr_handle_upcall() has two interfaces. It needs to be called by the x86 assembly code invoked by the APIC. Second, it needs to be called as a driver_filter_t for the XenPCI code and for architectures besides x86. Unfortunately the driver_filter_t interface was implemented as a wrapper around the x86-APIC interface. Now create a simple wrapper for the x86-APIC code, which calls an architecture-independent xen_intr_handle_upcall(). When called via intr_event_handle(), driver_filter_t functions expect preemption to be disabled. This removes the need for critical_enter()/critical_exit() when called this way. The lapic_eoi() call is only needed on x86 in some cases when invoked directly as an APIC vector handler. Additionally driver_filter_t functions have no need to handle interrupt counters. The intrcnt_add() calling function was reworked to match the current situation. intrcnt_add() is now only called via one path. The increment/decrement of curthread->td_intr_nesting_level had previously been left out. Appears this was mostly harmless, but this was noticed during implementation and has been added. CONFIG_X86 is a leftover from use with Linux. While the barrier isn't needed for FreeBSD on x86, it will be needed for FreeBSD on other architectures. Copyright note. xen_intr_intrcnt_add() was introduced at 76acc41fb7c7 by Justin T. Gibbs. xen_intrcnt_init() was introduced at fd036deac1695 by John Baldwin. sys/x86/xen/xen_arch_intr.c was originally created by Julien Grall in 2015 for the purpose of holding the x86 interrupt interface. Later it was found xen_intr_handle_upcall() was better earlier, and the x86 interrupt interface better later. As such the filename and header list belong to Julien Grall, but what those were created for is later. Reviewed by: royger Differential Revision: https://reviews.freebsd.org/D30006
* xen: remove CONFIG_XEN_COMPAT, purge Xen 3.0 compatibilityElliott Mitchell2023-04-141-9/+1
| | | | | | | | | This overlaps the purpose of __XEN_INTERFACE_VERSION__. Remove Xen 3.0.2 compatibility. __XEN_INTERFACE_VERSION__ has compatibility to Xen 3.2.8 enabled. As Xen 3.3 was released almost 15 years ago, it seems unlikely anyone hasn't updated. Reviewed by: royger
* xen: purge no longer used hypervisor functionsElliott Mitchell2023-04-141-44/+0
| | | | | | | | | | HYPERVISOR_poll(), HYPERVISOR_block(), and HYPERVISOR_crash() appear no longer used. Further get_system_time() appears to have disappeared at some point in the past, so HYPERVISOR_poll() was broken anyway. No functional change intended. Reviewed by: royger
* xen: switch to using core atomics for synchronizationElliott Mitchell2023-03-291-6/+13
| | | | | | | | | | | | | | Now that the atomic macros are always genuinely atomic on x86, they can be used for synchronization with Xen. A single core VM isn't too unusual, but actual single core hardware is uncommon. Replace an open-coding of evtchn_clear_port() with the inline. Substantially inspired by work done by Julien Grall <julien@xen.org>, 2014-01-13 17:40:58. Reviewed by: royger MFC after: 1 week
* xen: bump used interface versionRoger Pau Monné2023-03-091-1/+1
| | | | | | | | | This is required for a further change that will make use of a field that was added in version 0x00040d00. No functional change expected. Sponsored by: Citrix Systems R&D
* xenbus: improve device trackingRoger Pau Monné2022-06-071-24/+43
| | | | | | | | | | | | | | | | | | | | | | | xenbus needs to keep track of the devices exposed on xenstore, so that it can trigger frontend and backend device creation. Removal of backend devices is currently detected by checking the existence of the device (backend) xenstore directory, but that's prone to races as the device driver would usually add entries to such directory itself, so under certain circumstances it's possible for a driver to add node to the directory after the toolstack has removed it. This leads to devices not removed, which can eventually exhaust the memory of FreeBSD. Fix this by checking for the existence of the 'state' node instead of the directory, as such node will always be present when a device is active, and will be removed by the toolstack when the device is shut down. In order to avoid any races with the updating of the 'state' node by FreeBSD and the toolstack removing it use a transaction in xenbusb_write_ivar() for that purpose. Reported by: Ze Dupsys <zedupsys@gmail.com> Sponsored by: Citrix Systems R&D
* xen: Remove unused devclass arguments to DRIVER_MODULE.John Baldwin2022-05-062-6/+2
|
* xen: Use __diagused for a variable only used in KASSERT().John Baldwin2022-04-131-1/+1
|
* xen(3): Fix a typo in a source code commentGordon Bergling2022-03-281-1/+1
| | | | | | - s/mmaping/mapping/ MFC after: 3 days
* xen: remove public headers in sys/xen/interfaceRoger Pau Monné2022-02-0775-23313/+0
| | | | | | | Those are superseded by the ones in sys/contrib/xen and no longer used. Sponsored by: Citrix Systems R&D
* xen: switch to use headers in contribElliott Mitchell2022-02-0711-26/+26
| | | | | | | | | | These headers originate with the Xen project and shouldn't be mixed with the main portion of the FreeBSD kernel. Notably they shouldn't be the target of clean-up commits. Switch to use the headers in sys/contrib/xen. Reviewed by: royger
* xen(4): Fix a common typo in a source code commentsGordon Bergling2022-02-063-3/+3
| | | | | | - s/existance/existence/ MFC after: 3 days
* Create wrapper for Giant taken for newbusWarner Losh2021-12-101-5/+2
| | | | | | | | | | | Create a wrapper for newbus to take giant and for busses to take it too. bus_topo_lock() should be called before interacting with newbus routines and unlocked with bus_topo_unlock(). If you need the topology lock for some reason, bus_topo_mtx() will provide that. Sponsored by: Netflix Reviewed by: mav Differential Revision: https://reviews.freebsd.org/D31831
* xen/privcmd: fix MMAP_RESOURCE ioctl to copy out resultsRoger Pau Monné2021-11-181-1/+1
| | | | | | | | | | | The current definition for the MMAP_RESOURCE ioctl was wrong as it didn't copy back the result to the caller. Fix the definition and also remove the bogus attempt to copy the result in the implementation. Note such copy back is only needed when querying the size of a resource. Sponsored by: Citrix Systems R&D
* xen: introduce xen_pv_disks_disabled()Julien Grall2021-07-281-2/+0
| | | | | | | | | ARM guest is considered as HVM in Freebsd but they only support PV disk (no emulation available). Submitted by: Elliott Mitchell <ehem+freebsd@m5p.com> Reviewed by: royger Differential Revision: https://reviews.freebsd.org/D29403
* xen/netfront: introduce xen_pv_nics_disabled()Julien Grall2021-07-281-1/+0
| | | | | | | | | ARM guest is considered as HVM but it only supports PV nics (no emulation available). Submitted by: Elliott Mitchell <ehem+freebsd@m5p.com> Reviewed by: royger Differential Revision: https://reviews.freebsd.org/D29405
* xen/xen-os: move inclusion of machine/xen-os.h laterElliott Mitchell2021-07-281-6/+6
| | | | | | | | | | | | | Several of x86 enable/disable functions depend upon the xen*domain() functions. As such the xen*domain() functions need to be declared before machine/xen-os.h. Officially declare direct inclusion of machine/xen/xen-os.h verboten as such will break these functions/macros. Remove one such soon to be broken inclusion. Reviewed by: royger Differential Revision: https://reviews.freebsd.org/D29811
* xen/xen-os: don't let anyone else defining __XEN_INTERFACE_VERSION__Julien Grall2021-07-281-2/+0
| | | | | | | | | FreeBSD should always use the same version across the source. If not it's a call for problem. Submitted by: Elliott Mitchell <ehem+freebsd@m5p.com> Reviewed by: royger Differential Revision: https://reviews.freebsd.org/D29407
* x86/xen: remove PVHv1 codeRoger Pau Monné2021-05-174-121/+0
| | | | | | | | | | | PVHv1 was officially removed from Xen in 4.9, so just axe the related code from FreeBSD. Note FreeBSD supports PVHv2, which is the replacement for PVHv1. Sponsored by: Citrix Systems R&D Reviewed by: kib, Elliott Mitchell Differential Revision: https://reviews.freebsd.org/D30228
* xen: remove hypervisor_infoMitchell Horne2021-05-171-21/+6
| | | | | | | This was a source of indirection needed to support PVHv1. Now that that support has been removed, we can eliminate it. Reviewed by: royger
* xen: move x86-specific xen_vector_callback_enabled to sys/x86Julien Grall2021-03-151-3/+0
| | | | | | | | This is x86-only and so should not be in the common area. Submitted by: Elliott Mitchell <ehem+freebsd@m5p.com> Reviewed by: royger Differential revision: https://reviews.freebsd.org/D29040
* xen/xenusb: always include xen/xen-os.h rather than machine/xen/xen-os.hJulien Grall2021-03-152-2/+2
| | | | | | | | | | | Fix compilation since machine/xen/xen-os.h is requiring definition existing in xen/xen-os.h. In general machine/xen/xen-os.h should never be included Submitted by: Elliott Mitchell <ehem+freebsd@m5p.com> Reviewed by: royger Differential revision: https://reviews.freebsd.org/D29043
* xen: remove .swp file from public headersRoger Pau Monné2021-01-111-0/+0
| | | | Should have never been there in the first place.
* xen/privcmd: implement the restrict ioctlRoger Pau Monne2021-01-111-0/+2
| | | | | | | | | | | Use an interface compatible with the Linux one so that the user-space libraries already using the Linux interface can be used without much modifications. This allows an open privcmd instance to limit against which domains it can act upon. Sponsored by: Citrix Systems R&D
* xen/privcmd: implement the dm op ioctlRoger Pau Monne2021-01-112-0/+14
| | | | | | | | | | | Use an interface compatible with the Linux one so that the user-space libraries already using the Linux interface can be used without much modifications. This allows user-space to make use of the dm_op family of hypercalls, which are used by device models. Sponsored by: Citrix Systems R&D
* xen/privcmd: implement the map resource ioctlRoger Pau Monne2021-01-111-0/+15
| | | | | | | | | The interface is mostly the same as the Linux ioctl, so that we don't need to modify the user-space libraries that make use of it. The ioctl is just a proxy for the XENMEM_acquire_resource hypercall. Sponsored by: Citrix Systems R&D