dragonfly.git
2 years agonnvm - Move *_fpu_enter/leave inside the cli/sti
Matthew Dillon [Tue, 29 Jun 2021 06:04:31 +0000 (23:04 -0700)]
nnvm - Move *_fpu_enter/leave inside the cli/sti

* Move the host-to-guest and guest-to-host FP code inside the
  hard interrupt disablement.  The main reason this needs to
  be done is that DragonFly's normal interrupt mechanism is
  allowed to use the FP unit (using npxpush/npxpop).

  In addition, interrupts will allow the 'interrupt thread' to
  preempt the current kernel thread outside of a critical section.
  And inside a critical section the interrupt still fires, but
  just sets a flag.

* I don't want the host kernel dealing with guest FP state at all,
  under any circumstances.

2 years agonvmm: Check for pending host events before VM entry
Aaron LI [Sun, 27 Jun 2021 03:59:13 +0000 (11:59 +0800)]
nvmm: Check for pending host events before VM entry

mycpu->gd_reqflags can accumulate action items (pending host interrupts,
AST (asynchronous software trap), etc.).  Even if not in a critical
section, some action items can accumulate.  When in a critical section,
even more action items can accumulate.  Thus, gd_reqflags MUST be
checked *after* hard interrupt disablement to determine if the VM entry
has to be aborted, making the state safe to VM entry.

Credit to Matt Dillon.

2 years agonvmm: Improve nvmm_return_needed() by using nvmm_break_wanted()
Aaron LI [Sun, 27 Jun 2021 03:54:20 +0000 (11:54 +0800)]
nvmm: Improve nvmm_return_needed() by using nvmm_break_wanted()

Use the newly added nvmm_break_wanted() routine to check for pending
host events, improving nvmm_return_needed().  Just stuff
nvmm_break_wanted() into nvmm_return_needed() and get rid of
preempt_needed(), making the code clearer.

Also add __predict_false() macro to help performance a bit.

2 years agokernel - Add RQF_XINVLTLB to gd_reqflags
Matthew Dillon [Wed, 23 Jun 2021 05:19:33 +0000 (22:19 -0700)]
kernel - Add RQF_XINVLTLB to gd_reqflags

Add RQF_XINVLTLB to gd_reqflags.  This bit is set on every CPU related
to a pmap after a pmap_inval*() operation makes an adjustment in that
pmap, as part of the IPI sequence.

Will be used by NVMM.

2 years agoNVMM: Sync with NetBSD #2: SVM & VMX backends
Aaron LI [Sat, 26 Jun 2021 23:58:06 +0000 (07:58 +0800)]
NVMM: Sync with NetBSD #2: SVM & VMX backends

This commit syncs the NVMM kernel part to match NetBSD current (as of
2021-06-25).  The main changes are as follows:

* Improve host FPU handling.  The host FPU state is now save in PCB
  instead of in vCPU data area.

* Clear TS flag from the host's CR0 in _vcpu_init(), because it is also
  cleared inside the _vcpu_run() loop.  Not clearing it could trigger
  DNAs on VMEXITs.

* Set VMCS_HOST_IDTR_BASE on each CPU independently, because the IDT is
  now per-CPU (in NetBSD).

  NOTE: DragonFly is also using per-CPU IDT, so this change fixes a
  porting issue.

* Disable interrupts earlier to prevent possible race against TLB flush
  IPIs, because such IPIs don't respect the IPL, so enforcing IPL_HIGH
  has no effect.

* VMX: Improve CR0 handling:

  - Flush the guest TLB when certain CR0 bits change.
  - Employ VMCS_CR0_SHADOW to allow the guest to update certain static
    CR0 bits.  Guest gets the illusion that the CR0 change was applied,
    but the "real" CR0 bits remain unchanged.
  - Force CR0_ET to 1 in shadow CR0; force CR0_ET and CR0_NE in real
    CR0.
  - Add comments to clarify better.

NOTE:
NetBSD has overhauled the FPU handling, so NVMM no longer needs to save
host FPU state in the _cpudata structure.  I haven't found a way to do
this on DragonFly yet, so leave it and investigate it later.

2 years agoNVMM: Sync with NetBSD #1: copyright headers
Aaron LI [Sat, 26 Jun 2021 11:14:24 +0000 (19:14 +0800)]
NVMM: Sync with NetBSD #1: copyright headers

2 years agonvmm: Fix SVM TSS restore on DragonFly
Aaron LI [Mon, 14 Jun 2021 23:26:03 +0000 (07:26 +0800)]
nvmm: Fix SVM TSS restore on DragonFly

In DragonFly, PCPU(tss_gdt) points directly to the gdt[] entry for the
current CPU's TSS descriptor; while NetBSD's CPUVAR(GDT) points to the
gdtstore[] table.  Fix that 'and' instruction so it works on DragonFly.
(Credit to Matt Dillon for debugging and fixing this.)

The 'and' instruction clears the busy bit (bit 41) so the TSS descriptor
becomes "available" for the reloading, as required by 'ltr' instruction.
(The TSS descriptor was in use prior to launching the guest so it has
been marked busy.)

Credit:
* Illumos: Bug #13029: AMD bhyve should reload TSS ASAP
  https://www.illumos.org/issues/13029
* Illumos: 13029 AMD bhyve should reload TSS ASAP
  https://github.com/illumos/illumos-gate/commit/4d3fdeb14779bb6b0838521971d9ac99d65b0572

2 years agonvmm: Implement waits for lwkt_send_ipiq_mask()
Aaron LI [Sun, 13 Jun 2021 06:25:39 +0000 (14:25 +0800)]
nvmm: Implement waits for lwkt_send_ipiq_mask()

Unlike lwkt_send_ipiq(), lwkt_send_ipiq_mask() doesn't have a sequence
number to wait for completion, and a wait mechanism like that would be
very expensive.

Here we choose a simple method.  Just have {vmx,svm}_change_cpu()
decrement a global with an atomic op and issue a wakeup() when it hits
0.  And the callers can just tsleep in a loop until its zero

Credit to Matt Dillon for the patch.

2 years agonvmm: Fix VMX VMCS remote clear issues
Aaron LI [Sun, 13 Jun 2021 06:16:59 +0000 (14:16 +0800)]
nvmm: Fix VMX VMCS remote clear issues

When clearing a VMCS from a remote CPU, must wait for the IPI to
complete.  Otherwise the VMCS may be wrong when the thread migrates to
another CPU and thus cause panics when executing VMX instructions.

Credit to Matt Dillon for the debugging and fix.

2 years agonvmm: Fix issues of porting 'curcpu()' as 'mycpu'
Aaron LI [Sun, 13 Jun 2021 07:00:51 +0000 (15:00 +0800)]
nvmm: Fix issues of porting 'curcpu()' as 'mycpu'

In NVMM porting step #10, I ported NetBSD's 'curcpu()' as our 'mycpu'.
This was incorrect, because the 'struct globaldata *' pointer returned
by 'mycpu' is NOT stable and can change. (see the comments in
'pc64/include/thread.h')

Use 'mycpuid' to implement 'curcpu()' and adjust the code accordingly.

2 years agonvmm: Fix '-Wnested-externs' warning nvmm_x86_vmx.c
Aaron LI [Sun, 6 Jun 2021 11:38:17 +0000 (19:38 +0800)]
nvmm: Fix '-Wnested-externs' warning nvmm_x86_vmx.c

The 'extern uint8_t vmx_resume_rip' declaration in vmx_vcpu_init()
causes a 'nested extern declaration'.  Fix it by changing it to a
function prototype, which is actually an assembly function.

2 years agonvmm: Port to DragonFly #24: pmap transform & TLB invalidation
Aaron LI [Sun, 6 Jun 2021 11:31:54 +0000 (19:31 +0800)]
nvmm: Port to DragonFly #24: pmap transform & TLB invalidation

* Port NetBSD's pmap_ept_transform() to DragonFly's.  We don't make
  'pmap_ept_has_ad' a global in the pmap code, so need to pass extra
  flags to our pmap_ept_transform().

* Replace NetBSD's pmap_tlb_shootdown() with our pmap_inval_smp().

* Add two new fields 'pm_data' & 'pm_tlb_flush' to 'struct pmap', which
  are used as a callback by NVMM to handle its own TLB invalidation.

  Note that pmap_enter() also calls pmap_inval_smp() on EPT/NPT pmap
  and requires the old PTE be returned, so we can't place the NVMM TLB
  callback at the beginning part of pmap_inval_smp() and return 0.

2 years agopmap: Implement pmap_npt_transform() for NVMM
Aaron LI [Sun, 6 Jun 2021 12:06:59 +0000 (20:06 +0800)]
pmap: Implement pmap_npt_transform() for NVMM

This function will transform an initialized pmap structure for use by
NVMM's AMD SVM backend.

AMD's NPT (nested page table), aka RVI (rapid virtualization indexing)
implementation is more complete than Intel's EPT; it supports A/D bits
and uses the same bits positions as native x86 page tables.  So this
function is a simplified version of pmap_ept_transform().

2 years agopc64/vmm: Use pmap_ept_transform() to simplify EPT code
Aaron LI [Sun, 6 Jun 2021 04:51:50 +0000 (12:51 +0800)]
pc64/vmm: Use pmap_ept_transform() to simplify EPT code

2 years agopmap: Implement pmap_ept_transform() for NVMM
Aaron LI [Sun, 6 Jun 2021 03:30:13 +0000 (11:30 +0800)]
pmap: Implement pmap_ept_transform() for NVMM

The pmap_ept_transform() transforms an initialized pmap structure to be
EPT type for Intel VMX hypervisor (e.g., NVMM) use.  This implementation
is derived from vmx_ept_init() and vmx_ept_pmap_pinit() in
'pc64/vmm/ept.c'.

Note that this function has a different prototype as NetBSD's one,
because we don't make 'pmap_ept_has_ad' a global variable so we need to
pass extra flags to the pmap.

When zeroing out the page directories, note that the valid area is two
pages if there is a pm_pmlpv_iso PTE installed (i.e., the system has
meltdown mitigation enabled), otherwise, it's only one page.  (credit to
Matt Dillon)

2 years agonvmmctl(8): Rewrite makefile and hook to build
Aaron LI [Tue, 25 May 2021 23:43:54 +0000 (07:43 +0800)]
nvmmctl(8): Rewrite makefile and hook to build

2 years agonvmmctl(8): Port to DragonFly
Aaron LI [Tue, 25 May 2021 23:43:29 +0000 (07:43 +0800)]
nvmmctl(8): Port to DragonFly

* Adjust header inclusions
* Add 'XCR0_FLAGS1' macro define
* Add several '__unused' attributes
* Rename '__dead' to '__dead2'

2 years agolibnvmm: Adapt to also build on NetBSD
Aaron LI [Sat, 12 Jun 2021 10:11:10 +0000 (18:11 +0800)]
libnvmm: Adapt to also build on NetBSD

Adapt the libnvmm code to build and work on both DragonFly and NetBSD.
So it can help debug the porting issues.

2 years agolibnvmm: Fix mmap() failure with 'permission denied'
Aaron LI [Sun, 30 May 2021 23:25:14 +0000 (07:25 +0800)]
libnvmm: Fix mmap() failure with 'permission denied'

The mmap() in nvmm_vcpu_create() was always failing with the EACCES
(permission denied) error code.  It was because mmap() was requesting
prot = PROT_READ|PROT_WRITE and flags = MAP_SHARED, but the fd was
opened with O_RDONLY (or O_WRONLY in nvmm_root_init()) and thus
disallowed such a mmap request.

Fix this issue by opening the nvmm fd with O_RDWR flag.  This also
requires to change the mode of '/dev/nvmm' from 0640 to 0660.
However, this makes root owner distinguishing in nvmm kernel module
useless.  So change to identify root owner by checking whether the
caller has root privilege.

In addition, refactor nvmm_root_init() to also check for root privilege
first and then call nvmm_init().

2 years agolibnvmm: Update makefiles and hook to build
Aaron LI [Sun, 9 May 2021 23:05:43 +0000 (07:05 +0800)]
libnvmm: Update makefiles and hook to build

2 years agolibnvmm: Port to DragonFly
Aaron LI [Sun, 9 May 2021 23:05:16 +0000 (07:05 +0800)]
libnvmm: Port to DragonFly

* Add 'nvmm_compat.h' to adapt some macros/constants for DragonFly.
* Add some '__unused' attributes to fix compilation warnings/errors.
* Adjust header inclusions.
* Update nvmm(4) kernel source path in the man page, also update
  'struct nvmm_x64_state' to match DragonFly's version.

2 years agonvmm: Improve makefile to allow standalone build
Aaron LI [Sat, 29 May 2021 15:14:06 +0000 (23:14 +0800)]
nvmm: Improve makefile to allow standalone build

This change makes the nvmm kernel module is buildable in its own
directory.  This helps debug the module.

2 years agonvmm: Rewrite makefiles and hook to build
Aaron LI [Sun, 9 May 2021 23:35:35 +0000 (07:35 +0800)]
nvmm: Rewrite makefiles and hook to build

Note that kernel header files are install by the top-level
'include/Makefile'.  However, it will install all found header
files in the specified directories, including 'nvmm_compat.h'
and 'nvmm_internal.h'.  Therefore, add a guard to prevent them
from including by userland utilities (e.g., libnvmm, nvmmctl).

2 years agonvmm: Add to sys/conf/files and LINT64
Aaron LI [Sun, 9 May 2021 23:17:27 +0000 (07:17 +0800)]
nvmm: Add to sys/conf/files and LINT64

Meanwhile, remove the unused 'files.nvmm'.

2 years agonvmm: Port to DragonFly #23: header inclusion adjustments
Aaron LI [Sun, 23 May 2021 10:52:45 +0000 (18:52 +0800)]
nvmm: Port to DragonFly #23: header inclusion adjustments

2 years agonvmm: Port to DragonFly #22: pmap EPT/NPT base address
Aaron LI [Sun, 23 May 2021 10:21:31 +0000 (18:21 +0800)]
nvmm: Port to DragonFly #22: pmap EPT/NPT base address

Replace NetBSD's pmap->pm_pdirpa[0] with our vtophys(pmap->pm_pml4).

In addition, use vmspace_pmap() to grab the pmap, which is more
consistent with other code in our code base.

2 years agonvmm: Port to DragonFly #21: virtual address space management
Aaron LI [Sun, 23 May 2021 10:13:54 +0000 (18:13 +0800)]
nvmm: Port to DragonFly #21: virtual address space management

Adapt the following NetBSD UVM functions to DragonFly:

* uvmspace_alloc() -> vmspace_alloc()
* uvmspace_free() -> vmspace_rel()
* uvm_fault() -> vm_fault()
* uvm_map() -> vm_map_insert() + vm_map_inherit() + vm_map_madvise() ...
* uvm_map_pageable() -> vm_map_wire()
* uvm_unmap(), uvm_deallocate() -> vm_map_remove()

To support the UVM_FLAG_FIXED & UVM_FLAG_UNMAP flags in uvm_map(),
vm_map_delete() is called unconditionally to make room fot the coming
new mapping.  Note that vm_map_findspace() cannot be called in this case,
because it's not guaranteed to return the input hint address if the
hint range is available.

Use vm_map_wire() to wire/unwire the mapping; vm_map_unwire() is for
userland mlock operations.

In uvm_deallocate(), need to unwire kernel page before remove, because
vm_map_remove() only handles user wirings.

Reviewed-by: Matt Dillon
2 years agonvmm: Port to DragonFly #20: preemption & critical section
Aaron LI [Sat, 22 May 2021 13:58:44 +0000 (21:58 +0800)]
nvmm: Port to DragonFly #20: preemption & critical section

In DragonFly, a normal kernel thread will not migrate to another CPU or be
preempted (except by an interrupt thread), so kpreempt_{disable,enable}()
are not needed.  However, we can't use critical section as an instead,
because that would also prevent interrupt/reschedule flags from being
set, which would be a problem for nvmm_return_needed() that's called from
vcpu_run() loop.  (credit to Matt Dillon)

Port nvmm_return_needed() to DragonFly.  But note that the
*_resched_wanted() functions cannot be used in critical sections, which
would prevent the relevant flags from being set.  (credit to Matt Dillon)

Port splhigh()/splx() as critical sections in DragonFly for the moment.
Don't worry about it unless we have issues with it later.

2 years agonvmm: Port to DragonFly #19: IPI cross-cpu calls
Aaron LI [Sat, 22 May 2021 08:28:48 +0000 (16:28 +0800)]
nvmm: Port to DragonFly #19: IPI cross-cpu calls

Replace NetBSD xcall(9) API by our lwkt_send_ipiq() and
lwkt_send_ipiq_mask() to unicast/broadcast a function call to one/all
CPUs.

In DragonFly, a normal kernel thread won't migrate to another CPU,
so no need to implement NetBSD's curlwp_bind() and curlwp_bindx().

2 years agonvmm: Port to DragonFly #18: kernel memory allocation
Aaron LI [Sat, 22 May 2021 04:03:06 +0000 (12:03 +0800)]
nvmm: Port to DragonFly #18: kernel memory allocation

Use kmem_alloc() and kmem_free() to implement uvm_km_alloc() and
uvm_km_free() as they're used in svm_vcpu_create() and vmx_vcpu_create().
However, our kmem_alloc() may return 0 (i.e., allocation failure), so
need an extra check in the caller functions.

Since we've defined 'kmem_alloc' and 'kmem_free' macros to adapt
NetBSD's functions to use our kmalloc() and kfree().  Therefore, extra
parentheses are added around 'kmem_alloc' and 'kmem_free' to avoid macro
expansion, so the original functions would be called.

In addition, change the 'kmem_free()' to 'uvm_km_free()' in
vmx_vcpu_create(), aligning with the invocation pattern as well as
the use case in svm_vcpu_create().

2 years agonvmm: Port to DragonFly #17: physical page allocation
Aaron LI [Fri, 21 May 2021 15:19:46 +0000 (23:19 +0800)]
nvmm: Port to DragonFly #17: physical page allocation

Implement uvm_pagealloc() and uvm_pagefree() with vm_page_alloczwq() and
vm_page_freezwq(), respectively, which are added for this purpose by
Matt Dillon in 14067db606f14f728f62891ebcdc30366e95aa3d.

These two functions are used in 'nvmm_x86_svm.c' to allocate the HSAVE
memory.

2 years agonvmm: Port to DragonFly #16: contiguous memory allocation
Aaron LI [Fri, 21 May 2021 14:39:59 +0000 (22:39 +0800)]
nvmm: Port to DragonFly #16: contiguous memory allocation

svm_memalloc() and vmx_memalloc() need to allocate memory block that's
both virtually contiguous and physically contiguous.  NetBSD achieves
this requirement by first allocating a list of physically contiguous
pages and a virtually contiguous memory address, and then mapping them
page by page.

We can just use contigmalloc(9) to achieve the same goal.

2 years agonvmm: Port to DragonFly #15: anonymous object management
Aaron LI [Wed, 19 May 2021 10:52:22 +0000 (18:52 +0800)]
nvmm: Port to DragonFly #15: anonymous object management

Implement compat code for NetBSD anonymous object management:
uao_create(), uao_reference() and uao_detach().

The created object should be pageable by default, for example, the
object of guest physical memory.  So choose the default pager to create
the anonymous object.

If the object needs to be wired (e.g., the object for communicating
between kernel and userland), the uvm_map_pageable() can be called to
wire the object.

2 years agonvmm: Port to DragonFly #14: device & module operations
Aaron LI [Tue, 18 May 2021 06:05:40 +0000 (14:05 +0800)]
nvmm: Port to DragonFly #14: device & module operations

Replace NetBSD 'cdevsw' and 'fileops' structs with our 'dev_ops' struct,
and port NVMM to support both device open/close and module load/unload
operations.

NetBSD doesn't support cloning device, so it clones the file descriptor
(fd_clone() function) of the opened device (/dev/nvmm) and reassociates
it to the current process.  So that each process sees a separate
instance of the device.  See also NetBSD 'sys/net/if_tap.c' for an
example with detailed explanation on this mechansim.

DragonFly supports per-file-descriptor data with the devfs cdevpriv API,
which is much simpler than the method with autoclone device.

Also credit to Jaromír Doleček for his porting work of NVMM to DragonFly.
See: https://github.com/Moritz-Systems/DragonFlyBSD/commit/b96e5836fd25b448bb54775ac0107917adc2937d

2 years agonvmm: Port to DragonFly #13: debug register save & restore
Aaron LI [Sun, 16 May 2021 09:18:00 +0000 (17:18 +0800)]
nvmm: Port to DragonFly #13: debug register save & restore

Derived from NetBSD's x86_dbregs_save()/x86_dbregs_restore() in
'sys/arch/x86/x86/dbregs.c'.

2 years agonvmm: Port to DragonFly #12: FPU save & restore
Aaron LI [Tue, 25 May 2021 06:40:41 +0000 (14:40 +0800)]
nvmm: Port to DragonFly #12: FPU save & restore

Note that the host FPU state is indeterminant and depends on whether
the user program used the FPU or not, so there might not be any state to
save.  npxpush() and npxpop() can handle this.  Accordingly, need to use
'mcontext_t' to store host FPU state.

At first I used fpu_area_save() and fpu_area_restore() to deal with the
host FPU state, but it caused a hard fault loop when trying to boot an
OS in QEMU, because it failed to handle an uninitialized FPU.  Thanks
to Matt Dillon for tracking it down and fixing it.

Credit to FreeBSD vmm code: save_guest_fpustate(), restore_guest_fpustate()

2 years agonvmm: Port to DragonFly #11: CPU features
Aaron LI [Sat, 15 May 2021 14:37:08 +0000 (22:37 +0800)]
nvmm: Port to DragonFly #11: CPU features

2 years agonvmm: Port to DragonFly #10: cpu_info etc.
Aaron LI [Fri, 14 May 2021 12:10:32 +0000 (20:10 +0800)]
nvmm: Port to DragonFly #10: cpu_info etc.

* Replace 'struct cpu_info' with 'struct globaldata'.
* Port cpu_info's ci_tss_sel/ci_tss/ci_gdt.
* Port curcpu(), cpu_number(), cpu_index() functions.
* Port CPU iteration code.

2 years agonvmm: Port to DragonFly #9: atomic operations
Aaron LI [Fri, 14 May 2021 00:09:58 +0000 (08:09 +0800)]
nvmm: Port to DragonFly #9: atomic operations

Add compat defines for NetBSD's atomic_inc_64(), atomic_{inc,dec}_uint().
However, we don't have an alternative for the type-generic
atomic_load_relaxed() function.  So just modify the code accordingly.

2 years agonvmm: Port to DragonFly #8: kcpuset(9) -> cpumask(9)
Aaron LI [Wed, 12 May 2021 23:25:59 +0000 (07:25 +0800)]
nvmm: Port to DragonFly #8: kcpuset(9) -> cpumask(9)

Translate NetBSD's kcpuset(9) API to our cpumask(9) API.  Use the atomic
version to avoid possible races between multiple vCPUs.

2 years agonvmm: Port to DragonFly #7: memory allocation
Aaron LI [Wed, 12 May 2021 23:23:04 +0000 (07:23 +0800)]
nvmm: Port to DragonFly #7: memory allocation

Add compat code to adapt NetBSD's kmem_alloc()/kmem_zalloc()/kmem_free().

2 years agonvmm: Port to DragonFly #6: mutex/rwlock
Aaron LI [Tue, 11 May 2021 23:16:23 +0000 (07:16 +0800)]
nvmm: Port to DragonFly #6: mutex/rwlock

Add compat code to adapt NetBSD's mutex and rwlock to use DragonFly's
lockmgr(9).

2 years agonvmm: Port to DragonFly #5: constants/functions/macros
Aaron LI [Sun, 30 May 2021 08:02:49 +0000 (16:02 +0800)]
nvmm: Port to DragonFly #5: constants/functions/macros

Update nvmm_compat.h to include various compat constant/functions
defines.

2 years agonvmm: Port to DragonFly #4: PAT modes
Aaron LI [Sun, 30 May 2021 08:01:24 +0000 (16:01 +0800)]
nvmm: Port to DragonFly #4: PAT modes

Adapt NetBSD's PATENTRY() and PAT_* modes to ours PAT_VALUE() and PAT_*
defines.

2 years agonvmm: Port to DragonFly #3: CR/MSR defines
Aaron LI [Tue, 11 May 2021 23:10:55 +0000 (07:10 +0800)]
nvmm: Port to DragonFly #3: CR/MSR defines

Add XCR0 and various MSRs compat defines.

2 years agonvmm: Port to DragonFly #2: CPUID Fn0000_000B for SVM
Aaron LI [Tue, 11 May 2021 23:03:56 +0000 (07:03 +0800)]
nvmm: Port to DragonFly #2: CPUID Fn0000_000B for SVM

Add CPUID Fn0000_000B (Extended Topology Enumeration) defines for SVM.

Obtained from NetBSD.

2 years agonvmm: Port to DragonFly #1: nvmm_x86_{svmfunc,vmxfunc}.S
Aaron LI [Tue, 11 May 2021 06:25:17 +0000 (14:25 +0800)]
nvmm: Port to DragonFly #1: nvmm_x86_{svmfunc,vmxfunc}.S

2 years agonvmm: Port to DragonFly #0: initial nvmm_compat.h
Aaron LI [Tue, 25 May 2021 06:39:10 +0000 (14:39 +0800)]
nvmm: Port to DragonFly #0: initial nvmm_compat.h

Add nvmm_compat.h to hold the major compatibility code for the porting.
Currently there are mostly CPUID2_* and CPUID_SEF_* defines.

Credit to Jaromír Doleček for his initial porting of NVMM to DragonFly.
See: https://github.com/Moritz-Systems/DragonFlyBSD/commit/b96e5836fd25b448bb54775ac0107917adc2937d

2 years agoAdd group 'nvmm' and GID_NVMM for nvmm(4) & nvmmctl(8)
Aaron LI [Sun, 9 May 2021 23:06:54 +0000 (07:06 +0800)]
Add group 'nvmm' and GID_NVMM for nvmm(4) & nvmmctl(8)

2 years agonvmm.4: Add HISTORY and hook to build
Aaron LI [Sun, 9 May 2021 23:03:31 +0000 (07:03 +0800)]
nvmm.4: Add HISTORY and hook to build

2 years agonvmm: Bring some minor changes from NetBSD-current
Aaron LI [Sun, 9 May 2021 22:52:17 +0000 (06:52 +0800)]
nvmm: Bring some minor changes from NetBSD-current

These changes help port NVMM to DragonFly by reducing the required
difference.

2 years agoImport nvmm.4 manpage from NetBSD 9-stable
Aaron LI [Wed, 5 May 2021 08:16:06 +0000 (16:16 +0800)]
Import nvmm.4 manpage from NetBSD 9-stable

Branch: NetBSD 9-stable
Date: Fri Apr 30 14:08:16 2021 +0000
Path: share/man/man4/nvmm.4

2 years agoImport nvmmctl(8) from NetBSD 9-stable
Aaron LI [Wed, 5 May 2021 08:06:40 +0000 (16:06 +0800)]
Import nvmmctl(8) from NetBSD 9-stable

This is a program to control NVMM(4) virtual machines.  It currently
implements the following two commands:
- identify: display the capabilities of the system.
- list: display information on each virtual machine registered in the
  system.

Branch: NetBSD 9-stable
Date: Fri Apr 30 14:08:16 2021 +0000
Path: usr.sbin/nvmmctl

2 years agoImport libnvmm(3) from NetBSD 9-stable
Aaron LI [Wed, 5 May 2021 07:58:32 +0000 (15:58 +0800)]
Import libnvmm(3) from NetBSD 9-stable

This is the virtualization API that provides a way for VMM software to
effortlessly create and manage virtual machines via NVMM(4).

Branch: NetBSD 9-stable
Date: Fri Apr 30 14:08:16 2021 +0000
Path: lib/libnvmm

2 years agoImport nvmm(4) from NetBSD 9-stable
Aaron LI [Wed, 5 May 2021 07:35:16 +0000 (15:35 +0800)]
Import nvmm(4) from NetBSD 9-stable

This is the kernel driver that provides support for hardware-accelerated
virtualization.  It is made of an MI frontend with the following two MD
backends:
- x86 Intel VMX
- x86 AMD SVM

Branch: NetBSD 9-stable
Date: Fri Apr 30 14:08:16 2021 +0000
Path: sys/dev/nvmm

2 years ago<sys/signal.h>: Put sig_t and sigmask() under __BSD_VISIBLE.
Sascha Wildner [Tue, 20 Jul 2021 16:01:52 +0000 (18:01 +0200)]
<sys/signal.h>: Put sig_t and sigmask() under __BSD_VISIBLE.

2 years agopam_passwdqc: Local modifications.
Sascha Wildner [Tue, 20 Jul 2021 14:53:51 +0000 (16:53 +0200)]
pam_passwdqc: Local modifications.

2 years agoMerge branch 'vendor/PAM_PASSWDQC'
Sascha Wildner [Tue, 20 Jul 2021 14:52:42 +0000 (16:52 +0200)]
Merge branch 'vendor/PAM_PASSWDQC'

2 years agoImport passwdqc 2.0.2 vendor/PAM_PASSWDQC
Sascha Wildner [Tue, 20 Jul 2021 14:50:57 +0000 (16:50 +0200)]
Import passwdqc 2.0.2

2 years agoopenpam: Push README.DELETED to master.
Sascha Wildner [Tue, 20 Jul 2021 14:46:18 +0000 (16:46 +0200)]
openpam: Push README.DELETED to master.

2 years agoImport OpenPAM Tabebuia.
Sascha Wildner [Tue, 20 Jul 2021 14:45:26 +0000 (16:45 +0200)]
Import OpenPAM Tabebuia.

Fixes an off-by-one in pam_getenv(3).

See HISTORY for the details.

2 years agosbin/hammer2: Print freemap leaf's linear offset when "show"
Tomohiro Kusumi [Sat, 17 Jul 2021 16:23:28 +0000 (01:23 +0900)]
sbin/hammer2: Print freemap leaf's linear offset when "show"

2 years agosys/vfs/hammer2: Fix compilation when HAMMER2_IO_DEBUG enabled
Tomohiro Kusumi [Thu, 15 Jul 2021 16:45:08 +0000 (01:45 +0900)]
sys/vfs/hammer2: Fix compilation when HAMMER2_IO_DEBUG enabled

No such field debug_data in struct hammer2_io.

2 years agosys/vfs/hammer2: #if0 incomplete HAMMER2_FREEMAP_{DOMAYFREE,DOREALFREE} related
Tomohiro Kusumi [Wed, 14 Jul 2021 16:12:28 +0000 (01:12 +0900)]
sys/vfs/hammer2: #if0 incomplete HAMMER2_FREEMAP_{DOMAYFREE,DOREALFREE} related

Disable related code in addition to already #if0'd parts.

Neither "how == HAMMER2_FREEMAP_DOMAYFREE" nor "how == HAMMER2_FREEMAP_DOREALFREE"
happen. Looks like these weren't completely implemented since first
appeared in 10136ab6cde1969ab6ca22168b2a10ed5d9cc557 in 2013.

2 years agosys/vfs/hammer2: Remove unused HAMMER2_XOP_IROOT
Tomohiro Kusumi [Mon, 12 Jul 2021 17:02:23 +0000 (02:02 +0900)]
sys/vfs/hammer2: Remove unused HAMMER2_XOP_IROOT

Never used since first appeared in 6f445d15835c6677a0a79c8d168ef44d0b9b22c3 in 2018.
Also remove a comment for nonexistent HAMMER2_XOP_RECURSE.

2 years agokernel/acpi: Adjust MADT revision check.
Sascha Wildner [Sat, 17 Jul 2021 09:02:22 +0000 (11:02 +0200)]
kernel/acpi: Adjust MADT revision check.

2 years agoUpdate the pciconf(8) database.
Sascha Wildner [Thu, 15 Jul 2021 03:53:32 +0000 (05:53 +0200)]
Update the pciconf(8) database.

July 5, 2021 snapshot from https://pci-ids.ucw.cz

2 years agolibstand: Unbreak buildworld.
Sascha Wildner [Tue, 13 Jul 2021 04:31:03 +0000 (06:31 +0200)]
libstand: Unbreak buildworld.

Oops, this was a stupid last minute mistake.

2 years agoMake stand/lib an internal one, i.e. don't install libstand anymore.
Sascha Wildner [Mon, 12 Jul 2021 14:36:07 +0000 (16:36 +0200)]
Make stand/lib an internal one, i.e. don't install libstand anymore.

Nothing in dports needs it either.

Also, leave the manual page.

2 years agoboot: Move boot source code /usr/src/stand.
Sascha Wildner [Mon, 12 Jul 2021 14:20:16 +0000 (16:20 +0200)]
boot: Move boot source code /usr/src/stand.

sys/boot becomes stand/boot and lib/libstand becomes stand/lib.

My main reason is to have boot out of the way when for example grepping
in sys/. It also makes more sense since it's not really userland or
kernel code.

Other BSDs have moved their boot/standalone code around too, but maybe
with different directory layouts.

Approved-by: dillon, zrj
2 years agosys/vfs/hammer2: Remove unused HAMMER2_OFFSET_{MIN,MAX}
Tomohiro Kusumi [Wed, 7 Jul 2021 17:18:06 +0000 (02:18 +0900)]
sys/vfs/hammer2: Remove unused HAMMER2_OFFSET_{MIN,MAX}

Never used since first appeared in 504565062f34ec55037ac0cf308fe3562f091460 in 2014.

2 years agoperiodic/whatis: Remove whatis(1) db rebuilding for localized manpages.
Sascha Wildner [Sun, 11 Jul 2021 10:01:53 +0000 (12:01 +0200)]
periodic/whatis: Remove whatis(1) db rebuilding for localized manpages.

makewhatis doesn't have an -L option since the switch to mandoc's version.

Besides, we don't have localized manual pages in base and also in dports
I couldn't find a trace of any.

2 years agoperiodic: Enable {daily,weekly,monthly,security}_show_badconfig by default.
Sascha Wildner [Sat, 10 Jul 2021 17:44:42 +0000 (19:44 +0200)]
periodic: Enable {daily,weekly,monthly,security}_show_badconfig by default.

It can be helpful and found an issue in a dports periodic script, so we
want this on, I guess. Our base scripts have been cleaned up to not error
on optional things like a missing accounting file when accounting is not
enabled, etc.

Reported-by: James Cook (falsifian)
2 years agoperiodic: Do not error with rc==2 for some optional stuff.
Sascha Wildner [Sat, 10 Jul 2021 17:40:39 +0000 (19:40 +0200)]
periodic: Do not error with rc==2 for some optional stuff.

* UFS accounting has to be enabled in rc.conf, and if it is not, the
  script should just do nothing.

* /etc/news.expire is just some backwards compatibility stuff, so
  don't worry if it doesn't exist.

2 years agoperiodic: Do not error with rc=2 when /etc/daily.local etc. don't exist.
Sascha Wildner [Sat, 10 Jul 2021 16:59:54 +0000 (18:59 +0200)]
periodic: Do not error with rc=2 when /etc/daily.local etc. don't exist.

These scripts are only for backwards compatibility and we could even
remove 999.* but for now, just stay silent and do nothing if they
don't exist.

2 years agouname.1: Add missing options to the usage.
Sascha Wildner [Thu, 8 Jul 2021 11:00:07 +0000 (13:00 +0200)]
uname.1: Add missing options to the usage.

Submitted-by: yellowrabbit2010
Dragonfly-bug: https://bugs.dragonflybsd.org/issues/3285

2 years agosys/vfs/hammer2: Use HAMMER2_IND_COUNT_XXX
Tomohiro Kusumi [Sun, 4 Jul 2021 17:32:28 +0000 (02:32 +0900)]
sys/vfs/hammer2: Use HAMMER2_IND_COUNT_XXX

2 years agosys/vfs/hammer2: HAMMER2_CHAIN_BMAP* should be HAMMER2_CHAIN_BLKMAP*
Tomohiro Kusumi [Sun, 4 Jul 2021 16:30:10 +0000 (01:30 +0900)]
sys/vfs/hammer2: HAMMER2_CHAIN_BMAP* should be HAMMER2_CHAIN_BLKMAP*

The freemap code uses "bmap" and "BMAP" for bitmap,
so these two macros should be "BLKMAP" as the comment implies.

2 years agonpx: Remove an unused typedef and clean up a bit
Aaron LI [Wed, 7 Jul 2021 01:12:43 +0000 (09:12 +0800)]
npx: Remove an unused typedef and clean up a bit

* Remove unused typedef bool_t
* Fix a minor typo: FXRSTR -> FXRSTOR
* Fix indentation
* Reorganize a bit

2 years agonpx: Fix inline ASM error in fpu_clean_state()
Aaron LI [Wed, 7 Jul 2021 14:54:03 +0000 (22:54 +0800)]
npx: Fix inline ASM error in fpu_clean_state()

I made a mistake in commit 6becaabbb80a1d1b37c868ce7f22fca2ef6a743f when
I changed it use 'fldz' in the inline ASM.  Fix it.

2 years agomknod(2): Allow for the creation of fifos with mknod() to satisfy POSIX.
Sascha Wildner [Wed, 7 Jul 2021 14:49:16 +0000 (16:49 +0200)]
mknod(2): Allow for the creation of fifos with mknod() to satisfy POSIX.

Calling mknod() and mknodat() with S_IFIFO shall be equivalent to
calling mkfifo() and mkfifoat().

Note that we ignore 'dev' if S_IFIFO is passed, like Linux does, but
different from what {Free,Net,Open}BSD do, which require it to be 0.
It's true that the standard leaves anything but 0 undefined for this
case but also note the standard's example which does indeed pass a
'dev' arg and doesn't take any precautions of initializing it:

https://pubs.opengroup.org/onlinepubs/9699919799/functions/mknod.html#tag_16_328_06

I don't think it makes any difference in practice, though.

Reported-by: DanDan
While here, fix the manual page's HISTORY a bit (taken from FreeBSD).

2 years agoperiodic/snapshot-hammer2: Change scarce free space handling slightly.
Sascha Wildner [Wed, 7 Jul 2021 14:07:37 +0000 (16:07 +0200)]
periodic/snapshot-hammer2: Change scarce free space handling slightly.

The idea is that whenever the user falls into free space shortage
situation, the "sliding window" of snapshots potentially continues
rolling forward, instead of becoming stuck into the past.

Submitted-by: Francis GUDIN
Dragonfly-bug: <https://bugs.dragonflybsd.org/issues/3287>

2 years agonpx: Use 64-bit version FXSAVE64/FXRSTOR64 and XSAVE64/XRSTOR64
Aaron LI [Mon, 5 Jul 2021 11:50:51 +0000 (19:50 +0800)]
npx: Use 64-bit version FXSAVE64/FXRSTOR64 and XSAVE64/XRSTOR64

Since DragonFly is 64-bit only, use the 64-bit version
FXSAVE64/FXRSTOR64 and XSAVE64/XRSTOR64.

The new FXSAVE64/FXRSTOR64 version represents FIP/FDP as 64-bit fields
(union fp_addr.fa_64), while the legacy FXSAVE/FXRSTOR version uses
split fields: 32-bit offset, 16-bit segment and 16-bit reserved field
(union fp_addr.fa_32).  The latter implies that the actual addresses are
truncated to 32 bits which is insufficient in modern programs.

Improve the inline ASM code a bit to use 'xsave64'/'xrstor64' names.
The extra 'area' variable is introduced to help avoid dereferencing
'void *' pointer.

Referred-to: NetBSD

2 years agonpx: Extend fpusave/fpurstor() to accept an XSAVE mask argument
Aaron LI [Tue, 6 Jul 2021 23:32:56 +0000 (07:32 +0800)]
npx: Extend fpusave/fpurstor() to accept an XSAVE mask argument

XSAVE/XRSTOR requires a mask argument that determines the
components/states to save/restore.  Thus this argument controls the
save area size.

Extend fpusave/fpurstor() functions to accept an XSAVE mask argument,
so the caller can choose the wanted components/states to save/restore
and knows the exact area size.

NVMM will use this feature.

2 years agonpx: Use 'fldz' in fpu_clean_state() to load dummy zero
Aaron LI [Tue, 6 Jul 2021 23:17:46 +0000 (07:17 +0800)]
npx: Use 'fldz' in fpu_clean_state() to load dummy zero

The 'fldz' instruction pushs +0.0 onto the FPU register stack.  Use it
to replace the 'dummy_variable' variable.

Referred-to: NetBSD

2 years agoffs.5 : ffs is the default filesystem for /boot only
Pierre-Alain TORET [Tue, 6 Jul 2021 20:24:05 +0000 (22:24 +0200)]
ffs.5 : ffs is the default filesystem for /boot only

2 years agoinetd: Adjust error message too (a la the removed fcntl one).
Sascha Wildner [Tue, 6 Jul 2021 19:16:53 +0000 (21:16 +0200)]
inetd: Adjust error message too (a la the removed fcntl one).

2 years agoinetd: Use pipe2() instead of pipe()/fcntl()/fcntl() combo.
Sascha Wildner [Tue, 6 Jul 2021 19:12:20 +0000 (21:12 +0200)]
inetd: Use pipe2() instead of pipe()/fcntl()/fcntl() combo.

2 years agofile: Update README.DRAGONFLY and config.h.
Sascha Wildner [Tue, 6 Jul 2021 19:07:55 +0000 (21:07 +0200)]
file: Update README.DRAGONFLY and config.h.

2 years agoMerge branch 'vendor/FILE'
Sascha Wildner [Tue, 6 Jul 2021 18:47:45 +0000 (20:47 +0200)]
Merge branch 'vendor/FILE'

2 years agovendor/file: upgrade from 5.39 to 5.40
Sascha Wildner [Tue, 6 Jul 2021 18:44:23 +0000 (20:44 +0200)]
vendor/file: upgrade from 5.39 to 5.40

For details, see ChangeLog.

2 years agolibmagic/mkmagic: Add generated header(s) to CLEANFILES.
Sascha Wildner [Tue, 6 Jul 2021 18:23:34 +0000 (20:23 +0200)]
libmagic/mkmagic: Add generated header(s) to CLEANFILES.

2 years agokernel/modules: Simplify a number of .PATHs in module Makefiles.
Sascha Wildner [Mon, 5 Jul 2021 10:09:58 +0000 (12:09 +0200)]
kernel/modules: Simplify a number of .PATHs in module Makefiles.

2 years ago<sys/sensors.h>: Include <sys/types.h> for timeval and int64_t.
Sascha Wildner [Mon, 5 Jul 2021 07:30:40 +0000 (09:30 +0200)]
<sys/sensors.h>: Include <sys/types.h> for timeval and int64_t.

While here, remove an unused define.

2 years agoworld - Add covid(1) utility and port manual page from netbsd (2)
Matthew Dillon [Sun, 4 Jul 2021 19:03:11 +0000 (12:03 -0700)]
world - Add covid(1) utility and port manual page from netbsd (2)

* Though perhaps one could say that the 512-byte page-table pages
  the VAX had were a kind of disease, no... we won't go there.

  Fix manual page, move to section 1, and it isn't vax-specific.

2 years agoworld - Add covid(1) utility and port manual page from netbsd
Matthew Dillon [Sun, 4 Jul 2021 18:58:21 +0000 (11:58 -0700)]
world - Add covid(1) utility and port manual page from netbsd

* Move from section (4) to section (1) and include a utility which
  dumps one of the genome sequences.  Just to put an exclamation
  mark on the amount of damage such an absurdly short genetic sequence
  can wreak on the world

2 years agoMakefile.inc1: Remove unneeded exists() checks.
Sascha Wildner [Sun, 4 Jul 2021 18:39:12 +0000 (20:39 +0200)]
Makefile.inc1: Remove unneeded exists() checks.

Just doing 'make' in /usr/src isn't used for building anymore for a long
time, and our targets don't really make sense with an incomplete sounrce
tree.

2 years agoMakefile.inc1: Put all backup related stuff under the NO_BACKUP check.
Sascha Wildner [Sun, 4 Jul 2021 18:33:36 +0000 (20:33 +0200)]
Makefile.inc1: Put all backup related stuff under the NO_BACKUP check.

Main effect is that /usr/obj/world_backup is no longer created when
NO_BACKUP is set.

2 years agosys/vfs/hammer2: #if0 unused HAMMER2_DIRHASH_{HIMASK,FORCED}
Tomohiro Kusumi [Sat, 3 Jul 2021 17:50:42 +0000 (02:50 +0900)]
sys/vfs/hammer2: #if0 unused HAMMER2_DIRHASH_{HIMASK,FORCED}

HIMASK was no longer used since e028fa747e9825425f74da7e9c57a50a82b48e82 in 2012.
FORCED bit was never used since first appeared in above commit.

Only LOMASK bits are relevant for dirent lookup.

2 years agosys/vfs/hammer2: Fix function name in xop kprintf's
Tomohiro Kusumi [Sat, 3 Jul 2021 16:54:09 +0000 (01:54 +0900)]
sys/vfs/hammer2: Fix function name in xop kprintf's