aboutsummaryrefslogtreecommitdiff
path: root/sys/x86/xen
Commit message (Collapse)AuthorAgeFilesLines
* x86/xen: use correct printf specifier.Roger Pau Monné2024-02-221-1/+1
| | | | | | | | Use %p instead of wrongly casting to uintptr_t and printing with %lx. Reported by: bapt Fixes: 9a687d1fe3af ('x86/xen: introduce a Xen early init function') Sponsored by: Cloud Software Group
* x86/xen: implement early init hookRoger Pau Monné2024-02-222-109/+13
| | | | | | | | | | | | | | | | | | Unify the HVM and PVH early setup, byt making both rely on the hypervisor initialization hook part of identify_hypervisor(). The current initialization takes care of the hypercall page, the sahred info page and does any fixup necessary to metadata video console information if FreeBSD is booted as the initial domain (so the video console is handed from Xen into FreeBSD). Note this has the nice side effect of also allowing to use the Xen console on HVM guests, which allows to get rid of the QEMU emulated uart and still get a nice text console. Sponsored by: Cloud Software Group Reviewed by: markj Differential revision: https://reviews.freebsd.org/D43764
* x86/xen: replace xen_cpuid_base with hv_baseRoger Pau Monné2024-02-222-7/+7
| | | | | | | | | | | Where possible, replace the usage of xen_cpuid_base for hv_base in preparation for removing xen_cpuid_base. No functional change intended. Sponsored by: Cloud Software Group Reviewed by: markj Differential revision: https://reviews.freebsd.org/D43935
* x86/xen: do video console fixup as part of early initializationRoger Pau Monné2024-02-222-83/+87
| | | | | | | | | | | | | When FreeBSD is running as dom0 the video console metadata provided by the bootloader might not be accurate, as Xen has very likely taken over the console and possibly changed the mode. Adjust the video console information in the kernel metadata as part of early Xen initialization. Sponsored by: Cloud Software Group Reviewed by: imp Differential revision: https://reviews.freebsd.org/D43934
* x86/xen: move shared page setup to early init handlerRoger Pau Monné2024-02-222-14/+43
| | | | | | | | | | As done with the hypercall page, move the setup fo the shared info page into the newly introduced helper, which the aim of having a single helper and call site used by both HVM and PV in order to setup the basic Xen environment. Sponsored by: Cloud Software Group Reviewed by: markj Differential revision: https://reviews.freebsd.org/D43933
* x86/xen: introduce a Xen early init functionRoger Pau Monné2024-02-222-5/+52
| | | | | | | | | | | | Start by moving the hyeprcall setup to such function. The aim is to have a function that does all the required Xen early initialization for both HVM and PVH, instead of having it scattered across different paths. Sponsored by: Cloud Software Group Reviewed by: markj Differential revision: https://reviews.freebsd.org/D43932
* x86/xen: remove parameter from fixup_console()Roger Pau Monné2024-02-221-3/+12
| | | | | | | | | | | | | And instead fetch the metadata inside of the function. This is done in preparation for changing the call site of fixup_console(), which will no longer have the kernel metedata pointer in context. No functional change intended. Sponsored by: Cloud Software Group Reviewed by: markj Differential revision: https://reviews.freebsd.org/D43931
* x86/xen: introduce non-hypercall based emergency printRoger Pau Monné2024-02-221-0/+5
| | | | | | | | | | | | | | | | | | | | | 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 HVM guest hypercall page setupRoger Pau Monné2024-01-161-26/+9
| | | | | | | | | | | | | | | | | | | c7368ccb6801 didn't take into account that vm_guest will also get setup by generic identify CPU code, and hence by the time xen_hvm_init() gets called vm_guest will always be set if running as a Xen guest, either by the PVH entry point code, or by generic CPU identification. xen_hvm_init() and xen_hvm_init_hypercall_stubs() were relying on xen_domain() returning false when running as an HVM guest, and used that into order to figure out whether hypercall page needed to be populated. Get rid of such assumptions and simplify the code since legacy PVH is no longer supported. This fixes booting FreeBSD as a Xen HVM guest. Fixes: c7368ccb6801 ('xen: remove xen_domain_type enum/variable') Sponsored by: Cloud Software Group
* xen: remove xen_domain_type enum/variableElliott Mitchell2023-11-282-5/+2
| | | | | | | | 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/apic: remove passing trapframe as argumentElliott Mitchell2023-11-281-5/+2
| | | | | | | | | | While otherwise a handy potential approach, getting the trapframe via the argument isn't documented and isn't supposed to be used. While ipi_bitmap_handler() and ipi_swi_handler() need to be passed the trapframe as their arguments, the Xen functions can retrieve it from curthread->td_intr_frame, which is the proper way. Reviewed by: royger
* sys: Automated cleanup of cdefs and other formattingWarner Losh2023-11-273-3/+0
| | | | | | | | | | | | | | | | 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 .c patternWarner Losh2023-08-164-8/+0
| | | | Remove /^[\s*]*__FBSDID\("\$FreeBSD\$"\);?\s*\n/
* xen: move vcpu_info to common, leave hook for setupElliott Mitchell2023-07-211-22/+3
| | | | | | | | | | | | | | | | | | | | | | 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
* Revert "Revert "tslog: Annotate some early boot functions""Colin Percival2023-06-051-0/+3
| | | | | | | | Now that <sys/tslog.h> is wrapped in #ifdef _KERNEL, it's safe to have tslog annotations in files which might be built from userland (i.e. in subr_boot.c, which is built as part of the boot loader). This reverts commit 59588a546f55523d6fd37ab42eb08b719311d7d6.
* Revert "tslog: Annotate some early boot functions"Colin Percival2023-06-041-3/+0
| | | | | | | | | | | | The change to subr_boot.c broke the libsa build because the TSLOG macros have their own definitions for the boot loader -- I didn't realize that the loader code used subr_boot.c. I'm currently testing a fix and I'll revert this revert once I'm satisfied that everything works, but I don't want to leave the tree broken for too long. This reverts commit 469cfa3c30ee7a5ddeb597d0a8c3e7cac909b27a.
* tslog: Annotate some early boot functionsColin Percival2023-06-041-0/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Booting an amd64 kernel on Firecracker with 1 CPU and 128 MB of RAM, hammer_time takes roughly 2740 us: * 55 us in xen_pvh_parse_preload_data * 20 us in boot_parse_cmdline_delim * 20 us in boot_env_to_howto * 15 us in identify_hypervisor * 1320 us in link_elf_reloc * 1310 us in relocate_file1 handling ef->rela * 25 us in init_param1 * 30 us in dpcpu_init * 355 us in initializecpu * 255 us in initializecpu calling load_cr4 * 425 us in getmemsize * 280 us in pmap_bootstrap * 205 us in create_pagetables * 10 us in init_param2 * 25 us in pci_early_quirks * 60 us in cninit * 90 us in kdb_init * 105 us in msgbufinit * 20 us in fpuinit * 205 us elsewhere in hammer_time Some of these are unavoidable (e.g. identify_hypervisor uses CPUID and load_cr4 loads the CR4 register, both of which trap to the hypervisor) but others may deserve attention. Sponsored by: https://www.patreon.com/cperciva Differential Revision: https://reviews.freebsd.org/D40325
* spdx: The BSD-2-Clause-NetBSD identifier is obsolete, drop -NetBSDWarner Losh2023-05-121-1/+1
| | | | | | | | | The SPDX folks have obsoleted the BSD-2-Clause-NetBSD 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
* spdx: The BSD-2-Clause-FreeBSD identifier is obsolete, drop -FreeBSDWarner Losh2023-05-121-1/+1
| | | | | | | | | 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-11/+0
| | | | | | | | | | | | 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 sys/x86/xen/xen_intr.c to sys/dev/xen/bus/Julien Grall2023-04-141-1131/+0
| | | | | | | | | | | | The event channel source code or equivalent is needed on all architectures. Since much of this is viable to share, get this moved out of x86-land. Each interrupt interface then needs a distinct back-end implementation. Reviewed by: royger Submitted by: Elliott Mitchell <ehem+freebsd@m5p.com> Original implementation: Julien Grall <julien@xen.org>, 2014-01-13 17:41:04 Differential Revision: https://reviews.freebsd.org/D30236
* xen/intr: move interrupt allocation/release to architectureElliott Mitchell2023-04-142-109/+117
| | | | | | | | | | | | | | | | Simply moving the interrupt allocation and release functions into files which belong to the architecture. Since x86 interrupt handling is quite distinct from other architectures, this is a crucial necessary step. Identifying the border between x86 and architecture-independent is actually quite tricky. Similarly, getting the prototypes for the border right is also quite tricky. Inspired by the work of Julien Grall <julien@xen.org>, 2015-10-20 09:14:56, but heavily adjusted. Reviewed by: royger Differential Revision: https://reviews.freebsd.org/D30936
* xen/intr: move x86 PIC interface to xen_arch_intr.c, introduce wrappersJulien Grall2023-04-142-148/+193
| | | | | | | | | | | | | | | | | | | | | | | | | | | | The x86 PIC interface is very much x86-specific and not used by other architectures. Since most of xen_intr.c can be shared with other architectures, the PIC interface needs to be broken off. Introduce wrappers for calls into the architecture-dependent interrupt layer. All architectures need roughly the same functionality, but the interface is slightly different between architectures. Due to the wrappers being so thin, all of them are implemented as inline in arch-intr.h. The original implementation was done by Julien Grall in 2015, but this has required major updating. Removal of PVHv1 meant substantial portions disappeared. The original implementation took care of moving interrupt allocation to xen_arch_intr.c, but this has required massive rework and was broken off. In the original implementation the wrappers were normal functions. Some had empty stubs in xen_intr.c and were removed. Reviewed by: royger Submitted by: Elliott Mitchell <ehem+freebsd@m5p.com> Original implementation: Julien Grall <julien@xen.org>, 2015-10-20 09:14:56 Differential Revision: https://reviews.freebsd.org/D30909
* xen/intr: remove type argument from xen_intr_alloc_isrc()Elliott Mitchell2023-04-141-4/+3
| | | | | | | | | | | This value doesn't need to be set in xen_intr_alloc_isrc(). What is needed is simply to ensure the allocated xenisrc won't appear as free, even if xi_type is written non-atomically. Since the type is no longer used to indicate free or not, the calling function should take care of all non-architecture initialization. Reviewed by: royger Differential Revision: https://reviews.freebsd.org/D31188
* xen/x86: rework isrc allocation to use list instead of table scanningElliott Mitchell2023-04-141-47/+29
| | | | | | | | | | | | | Scanning the list of interrupts to find an unused entry is rather inefficient. Instead overlay a free list structure and use a list instead. This also has the useful effect of removing the last use of evtchn_type values outside of xen_intr.c. Reviewed by: royger [royger] - Make avail_list static.
* xen/intr: introduce dev/xen/bus/intr-internal.hJulien Grall2023-04-141-33/+19
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Move the xenisrc structure which needs to be shared between the core Xen interrupt code and architecture-dependent code into a separate header. A similar situation exists for the NR_EVENT_CHANNELS constant. Turn xi_intsrc into a type definition named xi_arch to reflect the new purpose of being an architectural variable for the interrupt source. This was originally implemented by Julien Grall, but has been heavily modified. The core side was renamed "intr-internal.h" and is #include'd by "arch-intr.h" instead of the other way around. This allows the architecture to add function definitions which use struct xenisrc. The original version only moved xi_intsrc into xen_arch_isrc_t. Moving xi_vector was done by the submitter. The submitter had also moved xi_activehi and xi_edgetrigger into xen_arch_isrc_t. Those disappeared with the removal of PVHv1 support. Copyright note. The current xenisrc structure was introduced at 76acc41fb7c7 by Justin T. Gibbs. Traces remain, but the strength of Copyright claims from before 2013 seem pretty weak. Reviewed by: royger Submitted by: Elliott Mitchell <ehem+freebsd@m5p.com>, 2021-03-17 19:09:01 Original implementation: Julien Grall <julien@xen.org>, 2015-10-20 09:14:56 Differential Revision: https://reviews.freebsd.org/D30648 [royger] - Adjust some line lengths - Fix comment about NR_EVENT_CHANNELS after movement. - Use #include instead of symlinks.
* xen/intr: adjust xen_intr_handle_upcall() to match driver filterElliott Mitchell2023-04-142-57/+112
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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/intr: do full xenisrc initialization during bindingElliott Mitchell2023-04-141-4/+3
| | | | | | | | | | Keeping released xenisrcs in a known state simplifies allocation, but forces the allocation function to maintain that state. This turns into a problem when trying to allow for interchangeable allocation functions. Fix this issue by ensuring xenisrcs are always *fully* initialized during binding. Reviewed by: royger
* xen/intr: split xen_intr_isrc_lock usesElliott Mitchell2023-04-141-7/+34
| | | | | | | | | | There are actually several distinct locking domains in xen_intr.c, but all were sharing the same lock. Both xen_intr_port_to_isrc[] and the x86 interrupt structures needed protection. Split these two apart as a precursor to splitting the architecture portions off the file. Reviewed by: royger Differential Revision: https://reviews.freebsd.org/D30726
* xen/intr: rework xen_intr_alloc_isrc() lockingElliott Mitchell2023-04-141-7/+6
| | | | | | | | | | | | | Locking for allocation was being done in xen_intr_bind_isrc(), but the unlock was inside xen_intr_alloc_isrc(). While the lock acquisition at the end of xen_intr_alloc_isrc() was to modify xen_intr_port_to_isrc[], NOT allocation. Fix this garbled (though working) locking scheme. Now locking for allocation is strictly in xen_intr_alloc_isrc(), while locking to modify xen_intr_port_to_isrc[] is in xen_intr_bind_isrc(). Reviewed by: royger Differential Revision: https://reviews.freebsd.org/D30726
* xen/intr: rework xen_intr_alloc_isrc() call structureElliott Mitchell2023-04-141-6/+7
| | | | | | | | | | The call structure around xen_intr_alloc_isrc() was rather awful. Notably finding a structure for reuse is part of allocation, but this was done outside xen_intr_alloc_isrc(). Move this into xen_intr_alloc_isrc() so the function handles all allocation steps. Reviewed by: royger Differential Revision: https://reviews.freebsd.org/D30726
* xen/intr: adjust xenisrc types, adjust format strings to matchElliott Mitchell2023-04-141-14/+14
| | | | | | | | | | | As "CPUs", IRQs (vector) and virtual IRQs are always positive integers, adjust the Xen code to use unsigned integers. Several format strings need adjustment to match. Additionally single-bit bitfields are boolean. No functional change expected. Reviewed by: royger
* xen: introduce XEN_CPUID_TO_VCPUID()/XEN_VCPUID()Julien Grall2023-04-141-17/+23
| | | | | | | | | | | | | | | | | | | | | | | | Part of the series for allowing FreeBSD/ARM to run on Xen. On ARM the function is a trivial pass-through, other architectures need distinct implementations. While implementing XEN_VCPUID() as a call to XEN_CPUID_TO_VCPUID() works, that involves multiple accesses to the PCPU region. As such make this a distinct macro. Only callers in machine independent code have been switched. Add a wrapper for the x86 PIC interface to use matching the old prototype. Partially inspired by the work of Julien Grall <julien@xen.org>, 2015-08-01 09:45:06, but XEN_VCPUID() was redone by Elliott Mitchell on 2022-06-13 12:51:57. Reviewed by: royger Submitted by: Elliott Mitchell <ehem+freebsd@m5p.com> Original implementation: Julien Grall <julien@xen.org>, 2014-04-19 08:57:40 Original implementation: Julien Grall <julien@xen.org>, 2014-04-19 14:32:01 Differential Revision: https://reviews.freebsd.org/D29404
* xen/intr: xen_intr_bind_isrc() always set handleElliott Mitchell2023-04-141-18/+16
| | | | | | | | | | | Previously the upper layer handle was being set before the last potential error condition. The reasoning appears to have been it was assumed invalid in case of an error being returned. Now ensure it is invalid until just before a successful return. Fixes: 76acc41fb7c7 ("Implement vector callback for PVHVM and unify event channel implementations") Fixes: 6d54cab1fe7d ("xen: allow to register event channels without handlers") Reviewed by: royger
* xen/intr: rework xen_intr_resume() for in-place remappingElliott Mitchell2023-03-291-14/+27
| | | | | | | | | | | | | | | The prior implementation of xen_intr_resume() was wiping xen_intr_port_to_isrc[] and then rebuilding from the x86 interrupt table. Rework to instead wipe the channel numbers (->xi_port) and then scan the table for sources with invalid channels. This will be slower due to scanning the whole table, but this removes the dependency on the x86 interrupt code. Reviewed by: royger Differential Revision: https://reviews.freebsd.org/D30599 [royger] Split line over 80 characters.
* xen/intr: merge parts of resume functionality into new functionElliott Mitchell2023-03-291-25/+27
| | | | | | | | | | | | | The portions of xen_rebind_ipi() and xen_rebind_virq() were already near-identical. While xen_rebind_ipi() should panic() on single-processor, still having the functionality to invoke seems harmless. Meanwhile much of the loop from xen_intr_resume() seemed to want to be closer to this same code. This pushes related bits closer together. Reviewed by: royger Differential Revision: https://reviews.freebsd.org/D30598
* xen/intr: remove x86 APIC headers from xen_intr.cJulien Grall2023-03-291-2/+0
| | | | | | | | | | | | | Remove these no longer needed headers. Key for making xen_intr.c machine-independent as they don't exist on other architectures. Originally this was part of a much larger commit, but was broken off for submission to the FreeBSD project. Reviewed by: royger Submitted by: Elliott Mitchell <ehem+freebsd@m5p.com> Original implementation: Julien Grall <julien@xen.org>, 2015-10-20 09:14:56 MFC after: 1 week
* xen/intr: stop passing shared_info_t to xen_intr_active_ports()Elliott Mitchell2023-03-291-6/+5
| | | | | | | | There is only a single global HYPERVISOR_shared_info pointer, so directly use the global pointer. Reviewed by: royger MFC after: 1 week
* xen: switch to using core atomics for synchronizationElliott Mitchell2023-03-291-3/+1
| | | | | | | | | | | | | | 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/intr: add check for intr_register_source() errorsElliott Mitchell2023-03-291-3/+15
| | | | | | | | | | | | | | | While unusual, intr_register_source() can return failure. A likely cause might be another device grabbing from Xen's interrupt range. This should NOT happen, but could happen due to a bug. As such check for this and fail if it occurs. This theoretical situation also effects xen_intr_find_unused_isrc(). There, .is_pic must be tested to ensure such an intrusion doesn't cause misbehavior. Reviewed by: royger MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D31995
* xen/intr: cleanup event channel number useElliott Mitchell2023-03-291-6/+18
| | | | | | | | | | Consistently use ~0 instead of 0 when clearing xenisrc structures. 0 is a valid event channel number, even though it is reserved by Xen. Whereas ~0 is guaranteed invalid. Reviewed by: royger MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D30743
* xen/intr: fix corruption of event channel tableElliott Mitchell2023-03-291-12/+15
| | | | | | | | | | | | | | In xen_intr_release_isrc(), the isrc should only be removed if it is assigned to a valid port. This had been mitigated by using 0 for not having a port, but this is actually corrupting the table. Fix this bug as modifying the code would cause this bug to manifest as kernel memory corruption. Similar issue for the vCPU bitmap masks. The KASSERT() doesn't need lock protection. Reviewed by: royger MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D30743
* xen/intr: fix overflow of Xen interrupt rangeElliott Mitchell2023-03-291-2/+2
| | | | | | | | | | | | | | The comparison was wrong. Hopefully this never occurred in the wild, but now ensure the error message will occur before damage is caused. This appears non-exploitable as exploitation would require a guest to force Domain 0 to allocate all event channels, which a guest shouldn't be able to do. Adjust the error message to better describe what has occurred. Reviewed by: royger MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D30743
* xen/intr: always set xi_close in xen_intr_bind_isrc()Elliott Mitchell2023-03-291-0/+2
| | | | | | | | | Appears errors are uncommon since calling xen_intr_release_isrc() on a xenisrc with xi_close in an undefined state could be bad. Fix this problematic lurking nasty. Reviewed by: royger MFC after: 1 week
* xen: take struct size into account for video informationRoger Pau Monné2023-03-141-6/+9
| | | | | | | | | | | | | | | The xenpf_dom0_console_t structure can grow as more data is added, and hence we need to check that the fields we accesses have been filled by Xen. The only extra field FreeBSD currently uses is the top 32 bits for the frame buffer physical address. Note that this field is present in all the versions that make the information available from the platform hypercall interface, so the check here is mostly cosmetic, and to remember us that newly added fields require checking the size of the returned data. Fixes: 6f80738b228c ('xen: fetch dom0 video console information from Xen') Sponsored by: Citrix Systems R&D
* xen: fetch dom0 video console information from XenRoger Pau Monné2023-03-091-0/+71
| | | | | | | | | It's possible for Xen to switch the video mode set by the boot loader, so that the information passed in the kernel metadata is no longer valid. Fetch the video mode used by Xen using an hypercall and update the medatada for the kernel to use the correct video mode. Sponsored by: Citrix Systems R&D
* xen: bump used interface versionRoger Pau Monné2023-03-091-0/+3
| | | | | | | | | 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
* PVH: Set bootmethod to PVHColin Percival2022-10-181-1/+1
| | | | | | | | | | Now that we can PVH boot on a non-Xen hypervisor, we shouldn't set machdep.bootmethod to "XEN". Instead, set it to "PVH"; there are other ways to discern the hypervisor. Reviewed by: royger Sponsored by: https://www.patreon.com/cperciva Differential Revision: https://reviews.freebsd.org/D36191
* PVH: support whitespace cmdline splittingColin Percival2022-10-181-1/+1
| | | | | | | | | | | | For historical reasons, Xen kernel command lines have options separated by commas. Every other FreeBSD platform uses whitespace; this is also necessary in PVH in order to support the Firecracker VMM. Allow options to be separated by any combination of commas and whitespace. Reviewed by: imp Sponsored by: https://www.patreon.com/cperciva Differential Revision: https://reviews.freebsd.org/D36190
* x86: Distinguish Xen from non-Xen PVH bootsColin Percival2022-10-181-24/+68
| | | | | | | | | | | | | | | | | | | | | | | The PVH boot protocol, introduced by Xen, is now used by some non-Xen platforms (e.g. the Firecracker VM) as well. In order to accommodate these, we use CPUID to detect Xen and only perform Xen-specific setup when running on that platform. The "isxen" function duplicates some work done by identcpu.c later in the boot process; but we need it here since this is the very first C code which runs when PVH booting (even before hammer_time). In many places the existing code had xc_printf(...); HYPERVISOR_shutdown(SHUTDOWN_crash); making use of Xen functionality to print a message and shut down; in the places where this idiom can be reached in the non-xen case, we replace it idiom with a CRASH(...) macro which calls those in the Xen case and halts in the non-Xen case. Reviewed by: royger Sponsored by: https://www.patreon.com/cperciva Differential Revision: https://reviews.freebsd.org/D35801