git: DragonFly_RELEASE_6_2 libc/net: Fix b64_pton() for some exact-sized buffer

2022-05-01 Thread Aaron LI


commit bdf470c4003cab60427283746458a1eddd6486e4
Author: Aaron LI 
Date:   Sat Apr 30 21:06:40 2022 +0800

libc/net: Fix b64_pton() for some exact-sized buffer

When decoding a base64 string with padding, b64_pton() can fail when the
output buffer is exactly the needed size.  For example, decoding the
following base64 string to buffer[32] would fail:

% dd if=/dev/random bs=32 count=1 | base64
FCiWkKuhdRq3tMmtAt9CpchTTYMlIW3U3gJsavDNxZI=

This commit fixes the above issue.

Reported-by: dczheng
Obtained-from: OpenBSD
See also: FreeBSD revision 275060, https://reviews.freebsd.org/D1218

Summary of changes:
 lib/libc/net/base64.c | 26 +-
 1 file changed, 17 insertions(+), 9 deletions(-)

http://gitweb.dragonflybsd.org/dragonfly.git/commitdiff/bdf470c4003cab60427283746458a1eddd6486e4


-- 
DragonFly BSD source repository


git: Add base64(3) man page for b64_ntop() and b64_pton()

2022-05-01 Thread Aaron LI


commit ea3dc9921401b579b2d0f2f0f8e226e392d468fb
Author: Aaron LI 
Date:   Sat Apr 30 22:22:20 2022 +0800

Add base64(3) man page for b64_ntop() and b64_pton()

Reviewed-and-improved-by: swildner

Summary of changes:
 lib/libc/net/Makefile.inc|   4 +-
 lib/libc/{sys/lwp_setname.2 => net/base64.3} | 119 ---
 2 files changed, 73 insertions(+), 50 deletions(-)
 copy lib/libc/{sys/lwp_setname.2 => net/base64.3} (53%)

http://gitweb.dragonflybsd.org/dragonfly.git/commitdiff/ea3dc9921401b579b2d0f2f0f8e226e392d468fb


-- 
DragonFly BSD source repository


git: libc/net: Fix b64_pton() for some exact-sized buffer

2022-05-01 Thread Aaron LI


commit 3bf574a91d98898f33673d3b78fb3fe581c3c4e7
Author: Aaron LI 
Date:   Sat Apr 30 21:06:40 2022 +0800

libc/net: Fix b64_pton() for some exact-sized buffer

When decoding a base64 string with padding, b64_pton() can fail when the
output buffer is exactly the needed size.  For example, decoding the
following base64 string to buffer[32] would fail:

% dd if=/dev/random bs=32 count=1 | base64
FCiWkKuhdRq3tMmtAt9CpchTTYMlIW3U3gJsavDNxZI=

This commit fixes the above issue.

Reported-by: dczheng
Obtained-from: OpenBSD
See also: FreeBSD revision 275060, https://reviews.freebsd.org/D1218

Summary of changes:
 lib/libc/net/base64.c | 27 +--
 1 file changed, 17 insertions(+), 10 deletions(-)

http://gitweb.dragonflybsd.org/dragonfly.git/commitdiff/3bf574a91d98898f33673d3b78fb3fe581c3c4e7


-- 
DragonFly BSD source repository


git: libc/net: Multiple minor cleanups to base64.c

2022-05-01 Thread Aaron LI


commit fe2da4c891f6d5ab555eac0ac3edc3241c50c1c5
Author: Aaron LI 
Date:   Sat Apr 30 21:01:02 2022 +0800

libc/net: Multiple minor cleanups to base64.c

* Remove unused but included headers.
* Use 'unsigned char' instead of 'u_char'.
* Properly cast 'char' to 'unsigned char'.
* Remove the debug Assert()s.

Partially obtained from OpenBSD.

Summary of changes:
 lib/libc/net/base64.c | 58 ++-
 1 file changed, 25 insertions(+), 33 deletions(-)

http://gitweb.dragonflybsd.org/dragonfly.git/commitdiff/fe2da4c891f6d5ab555eac0ac3edc3241c50c1c5


-- 
DragonFly BSD source repository


git: pf: Make ":0" (noalias) also ignore link-local IPv6 addresses

2022-04-30 Thread Aaron LI


commit 6aa338e1205b533679b84dd50b38f5664f0d9cef
Author: Aaron LI 
Date:   Sun May 1 12:59:57 2022 +0800

pf: Make ":0" (noalias) also ignore link-local IPv6 addresses

When users mark an interface to not use aliases they likely also don't
want to use the link-local IPv6 address there.

For example, with the following rule to NAT IPv6:

nat on $ext_if inet6 from $int_if:network to !$int_if:network -> ($ext_if:0)

PF was selecting the link-local address (which comes the first) for the
NAT'ed IPv6 address, which was wrong and broke the NAT setup.

This commit makes PF to ignore the link-local IPv6 addresses so that the
above NAT setup would work.

Obtained-from: FreeBSD (revision 339835, review D17633)
See also: 
https://lists.freebsd.org/pipermail/freebsd-pf/2014-September/007441.html

Summary of changes:
 share/man/man5/pf.conf.5  | 6 +++---
 sys/net/pf/pf_if.c| 3 ++-
 usr.sbin/pfctl/pfctl_parser.c | 3 +++
 3 files changed, 8 insertions(+), 4 deletions(-)

http://gitweb.dragonflybsd.org/dragonfly.git/commitdiff/6aa338e1205b533679b84dd50b38f5664f0d9cef


-- 
DragonFly BSD source repository


git: pf: Fix 'set skip on' for interface groups

2022-04-30 Thread Aaron LI


commit 1f4644306e2abec3b56e1ef6ef21613ff4c991ad
Author: Aaron LI 
Date:   Sun May 1 11:31:41 2022 +0800

pf: Fix 'set skip on' for interface groups

Previously if an interface type (without number), e.g. "set skip on vlan"
or "set skip on em" was used, it would have the *undocumented* behavior
of matching *any* interface of that type.

Now it will only match an interface which is a member of the named group.
And thus it works with interface groups of arbitrary names, e.g., one
can "set skip on home" with "home" being the group containing interfaces
"em1" and "tun0".

This results in some changed behavior:

If you currently use "set skip" with a physical interface type (e.g.
"set skip on ix") you will need to add the interface to a group of that
name: 'ifconfig ix0 group ix' or add 'group ix' to hostname.ix0.

Interfaces cloned at runtime (e.g. lo, tap, tun, vlan) default to being
in a group named after the interface type, so for these interfaces there
will be no change in the behavior unless you have deliberately changed
groups.

Obtained-from: FreeBSD (revision 337643)
Obtained-from: OpenBSD (pf_if.c,v 1.62, 1.63)

Summary of changes:
 sys/net/pf/pf_if.c | 19 ++-
 1 file changed, 14 insertions(+), 5 deletions(-)

http://gitweb.dragonflybsd.org/dragonfly.git/commitdiff/1f4644306e2abec3b56e1ef6ef21613ff4c991ad


-- 
DragonFly BSD source repository


git: libkern: Import timingsafe_bcmp() from FreeBSD

2022-04-15 Thread Aaron LI


commit ee3ffe9a0449377a35ea3d21f28e7ec5522c6c6d
Author: Aaron LI 
Date:   Fri Apr 15 22:35:27 2022 +0800

libkern: Import timingsafe_bcmp() from FreeBSD

Will be used by WireGuard.

Obtained-from: FreeBSD

Summary of changes:
 sys/conf/files | 1 +
 {lib/libc/string => sys/libkern}/timingsafe_bcmp.c | 4 ++--
 sys/sys/libkern.h  | 1 +
 3 files changed, 4 insertions(+), 2 deletions(-)
 copy {lib/libc/string => sys/libkern}/timingsafe_bcmp.c (90%)

http://gitweb.dragonflybsd.org/dragonfly.git/commitdiff/ee3ffe9a0449377a35ea3d21f28e7ec5522c6c6d


-- 
DragonFly BSD source repository


git: callout.9: Multiple minor fixes

2022-04-15 Thread Aaron LI


commit 740d86cc2e1e40d6a9ce413790bf0a99e9cbbda7
Author: Aaron LI 
Date:   Fri Apr 15 21:52:09 2022 +0800

callout.9: Multiple minor fixes

* Fix prototype of callout_init(); it has only one argument.
  (reported-by: dczheng)
* Fix '.Dt' to 'CALLOUT'
* Use 'function' instead of 'macro'; those are really functions and the
  'function' reads more generic.
* Mention callout_cancel() in 'RETURN VALUES' section.
* Other styles and words adjustments.

Summary of changes:
 share/man/man9/callout.9 | 73 
 1 file changed, 37 insertions(+), 36 deletions(-)

http://gitweb.dragonflybsd.org/dragonfly.git/commitdiff/740d86cc2e1e40d6a9ce413790bf0a99e9cbbda7


-- 
DragonFly BSD source repository


git: lpr.1: Tweak a bit about '-i' option

2022-02-19 Thread Aaron LI


commit 6dcbde115ef3af3193b5d80b0f87f916d9d21b65
Author: Aaron LI 
Date:   Sat Feb 19 17:53:05 2022 +0800

lpr.1: Tweak a bit about '-i' option

I made a mistake so that I lost this change in a rebase...

Reviewed-by: swildner

Summary of changes:
 usr.sbin/lpr/lpr/lpr.1 | 12 ++--
 1 file changed, 6 insertions(+), 6 deletions(-)

http://gitweb.dragonflybsd.org/dragonfly.git/commitdiff/6dcbde115ef3af3193b5d80b0f87f916d9d21b65


-- 
DragonFly BSD source repository


git: getopt.3: Clarify option string syntax

2022-02-19 Thread Aaron LI


commit cd85487ee5969aac1c1a34258daf05c3e598d591
Author: Aaron LI 
Date:   Sat Feb 19 17:36:13 2022 +0800

getopt.3: Clarify option string syntax

The recently added 'option::' syntax requires the following argument
(if present) *must* be in the same word as the option name itself
(e.g., "-x").  This is different than the normal 'option:' syntax,
for which the argument may have a leading white space (e.g., "-x ").
Update the man page to explicitly describe the syntax.

Update to use a list to describe the 3 types of option string syntaxes
with examples.

Summary of changes:
 lib/libc/stdlib/getopt.3 | 53 
 1 file changed, 36 insertions(+), 17 deletions(-)

http://gitweb.dragonflybsd.org/dragonfly.git/commitdiff/cd85487ee5969aac1c1a34258daf05c3e598d591


-- 
DragonFly BSD source repository


git: lpr(1): Fix '-i' option with optional argument

2022-02-19 Thread Aaron LI


commit 7a1c99d311f1595cdc33d2ea3804d7fe580e1d87
Author: Aaron LI 
Date:   Sat Feb 19 17:53:05 2022 +0800

lpr(1): Fix '-i' option with optional argument

lpr(1)'s '-i' option accepts an optional argument, but the
implementation was incomplete.  For example, 'lpr -i -#3' errors with:
'Bad argument to -i, number expected'.

However, because the argument to '-i' option can have a leading white
space (i.e., '-i 4'), we can't use getopt(3)'s new 'option::' feature
here.  Fix the code in another way inspired by dma(8) (see
'libexec/dma/dma.c').

In addition, update the usage text as well as the man page.

Summary of changes:
 usr.sbin/lpr/lpr/lpr.1 | 12 
 usr.sbin/lpr/lpr/lpr.c | 16 
 2 files changed, 20 insertions(+), 8 deletions(-)

http://gitweb.dragonflybsd.org/dragonfly.git/commitdiff/7a1c99d311f1595cdc33d2ea3804d7fe580e1d87


-- 
DragonFly BSD source repository


git: getopt.3: Fix date

2022-02-16 Thread Aaron LI


commit 4cf91089fff1c81fc43377968ea9920d2c6b38e9
Author: Aaron LI 
Date:   Thu Feb 17 07:02:54 2022 +0800

getopt.3: Fix date

Reported-by: swildner

Summary of changes:
 lib/libc/stdlib/getopt.3 | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

http://gitweb.dragonflybsd.org/dragonfly.git/commitdiff/4cf91089fff1c81fc43377968ea9920d2c6b38e9


-- 
DragonFly BSD source repository


git: getopt(3): Recognize 'option::' for optional argument

2022-02-16 Thread Aaron LI


commit cf9179eef9dcb2908603f6aed2a14f797a8edb9a
Author: Aaron LI 
Date:   Wed Feb 16 14:31:36 2022 +0800

getopt(3): Recognize 'option::' for optional argument

If the option is followed by two colons, then the option argument is
optional.  This is a GNU extension.

Obtained from NetBSD via FreeBSD (revision 267745).

Summary of changes:
 lib/libc/stdlib/getopt.3 | 13 -
 lib/libc/stdlib/getopt.c |  7 ++-
 2 files changed, 18 insertions(+), 2 deletions(-)

http://gitweb.dragonflybsd.org/dragonfly.git/commitdiff/cf9179eef9dcb2908603f6aed2a14f797a8edb9a


-- 
DragonFly BSD source repository


git: stand: Fix a typo in comment

2022-01-03 Thread Aaron LI


commit dc3a1b4664b2a57847267e7da055e8a772359b70
Author: Aaron LI 
Date:   Mon Jan 3 17:21:34 2022 +0800

stand: Fix a typo in comment

While there, adjust header inclusion a bit.

Summary of changes:
 stand/lib/hammer2.c | 10 +-
 1 file changed, 5 insertions(+), 5 deletions(-)

http://gitweb.dragonflybsd.org/dragonfly.git/commitdiff/dc3a1b4664b2a57847267e7da055e8a772359b70


-- 
DragonFly BSD source repository


git: DragonFly_RELEASE_6_0 kernel - Workaround qemu bug w/ MSR_IA32_ARCH_CAPABILITIES

2021-10-08 Thread Aaron LI


commit 3905720f4b42877bb5149e5fcdf7359a3572c92f
Author: Matthew Dillon 
Date:   Mon Aug 9 10:45:53 2021 -0700

kernel - Workaround qemu bug w/ MSR_IA32_ARCH_CAPABILITIES

* qemu allows cpuid report that MSR_IA32_ARCH_CAPABILITIES exists, but
  then fails to implement the MSR.  This causes the kernel to panic
  in early boot.

* Use rdmsr_safe() and report the non-working msr instead of panicing.

* Fixes qemu + DFly on some recent Intel cpus.

refs #3292

Summary of changes:
 sys/platform/pc64/x86_64/identcpu.c   | 24 ++--
 sys/platform/pc64/x86_64/vm_machdep.c | 11 ++-
 2 files changed, 28 insertions(+), 7 deletions(-)

http://gitweb.dragonflybsd.org/dragonfly.git/commitdiff/3905720f4b42877bb5149e5fcdf7359a3572c92f


-- 
DragonFly BSD source repository


git: DragonFly_RELEASE_6_0 x86_64/specialreg.h: Deprecate old defines of Spectre mitigation

2021-10-08 Thread Aaron LI


commit 22e07bffca3d72ff01814e82b1d64a84d8fd6051
Author: Aaron LI 
Date:   Wed May 26 19:40:58 2021 +0800

x86_64/specialreg.h: Deprecate old defines of Spectre mitigation

Migrate the old defines of Spectre mitigation to the new ones obtained
from NetBSD and FreeBSD.  Specifically, apply the following changes:

* CPUID_7_0_I3_* -> CPUID_STDEXT3_*
* CPUID_SEF_* -> CPUID_STDEXT3_*
* CPUID_*_8008_I1_* -> CPUID_CAPEX_*

In addition, merge the comments to the relevant code.

No functional changes.

Summary of changes:
 sys/cpu/x86_64/include/specialreg.h   | 43 ---
 sys/platform/pc64/x86_64/identcpu.c   |  2 +-
 sys/platform/pc64/x86_64/vm_machdep.c | 48 ++-
 3 files changed, 26 insertions(+), 67 deletions(-)

http://gitweb.dragonflybsd.org/dragonfly.git/commitdiff/22e07bffca3d72ff01814e82b1d64a84d8fd6051


-- 
DragonFly BSD source repository


git: DragonFly_RELEASE_6_0 x86_64/specialreg.h: Reorganize SPEC_CTRL_* macros

2021-10-08 Thread Aaron LI


commit 6f0a4046651cb87a06cbd900ac797c3229bb1291
Author: Aaron LI 
Date:   Wed May 26 19:38:00 2021 +0800

x86_64/specialreg.h: Reorganize SPEC_CTRL_* macros

Move the SPEC_CTRL_* bit defines near to the corresponding MSR_SPEC_CTRL
MSR definition.

Summary of changes:
 sys/cpu/x86_64/include/specialreg.h | 25 ++---
 1 file changed, 14 insertions(+), 11 deletions(-)

http://gitweb.dragonflybsd.org/dragonfly.git/commitdiff/6f0a4046651cb87a06cbd900ac797c3229bb1291


-- 
DragonFly BSD source repository


git: DragonFly_RELEASE_6_0 x86_64/specialreg.h: Add more CPUID Fn8000_0008 defines

2021-10-08 Thread Aaron LI


commit 680dd03bde779276929e816ff53f8b84c69922d9
Author: Aaron LI 
Date:   Tue May 11 00:14:21 2021 +0800

x86_64/specialreg.h: Add more CPUID Fn8000_0008 defines

CPUID Fn8000_0008 - AMD Processor Capacity Parameters and Extended Features

These CPUID defines are taken from NetBSD, and some of them will be used
by NVMM.

Note that FreeBSD also has such CPUID, but in different names.

Summary of changes:
 sys/cpu/x86_64/include/specialreg.h | 24 +++-
 1 file changed, 23 insertions(+), 1 deletion(-)

http://gitweb.dragonflybsd.org/dragonfly.git/commitdiff/680dd03bde779276929e816ff53f8b84c69922d9


-- 
DragonFly BSD source repository


git: DragonFly_RELEASE_6_0 x86_64/specialreg.h: Rename two IA32_ARCH_* defines for consistency

2021-10-08 Thread Aaron LI


commit d74f34a269e030caa89ebb6a1a02bd42a9eaf539
Author: Aaron LI 
Date:   Tue May 11 13:18:43 2021 +0800

x86_64/specialreg.h: Rename two IA32_ARCH_* defines for consistency

Rename IA32_ARCH_SSB_NO -> IA32_ARCH_CAP_SSB_NO, and
IA32_ARCH_MDS_NO -> IA32_ARCH_CAP_MDS_NO, for better consistency with
other IA32_ARCH_CAP_* defines.

Submitted in bug #3265 by chicken.
https://bugs.dragonflybsd.org/issues/3265

Summary of changes:
 sys/cpu/x86_64/include/specialreg.h   | 4 ++--
 sys/platform/pc64/x86_64/vm_machdep.c | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)

http://gitweb.dragonflybsd.org/dragonfly.git/commitdiff/d74f34a269e030caa89ebb6a1a02bd42a9eaf539


-- 
DragonFly BSD source repository


git: DragonFly_RELEASE_6_0 x86_64/specialreg.h: Add various CPUID Fn0000_0007 defines

2021-10-08 Thread Aaron LI


commit 7cdfc2a839bb17b316663079a23bd95c6421a958
Author: Aaron LI 
Date:   Mon May 10 23:46:06 2021 +0800

x86_64/specialreg.h: Add various CPUID Fn_0007 defines

These Structured Extended Features (SEF) defines are taken from FreeBSD,
but with comments taken from NetBSD.

Some of these SEF defines will be used by NVMM. (Although NetBSD define
them with different names than FreeBSD.)

Summary of changes:
 sys/cpu/x86_64/include/specialreg.h | 116 +---
 1 file changed, 95 insertions(+), 21 deletions(-)

http://gitweb.dragonflybsd.org/dragonfly.git/commitdiff/7cdfc2a839bb17b316663079a23bd95c6421a958


-- 
DragonFly BSD source repository


git: Revert "WIP"

2021-07-28 Thread Aaron LI


commit b7ad3369a06e06ee49a61cdb894f9d9a2eed1036
Author: Aaron LI 
Date:   Thu Jul 29 07:30:27 2021 +0800

Revert "WIP"

This reverts commit 5d4c71cc3f59393bac29819031ed5afcedda6359.

Oops, didn't intend to commit this...

Summary of changes:
 sys/dev/virtual/nvmm/x86/nvmm_x86_svm.c | 1 -
 1 file changed, 1 deletion(-)

http://gitweb.dragonflybsd.org/dragonfly.git/commitdiff/b7ad3369a06e06ee49a61cdb894f9d9a2eed1036


-- 
DragonFly BSD source repository


git: WIP

2021-07-28 Thread Aaron LI


commit 5d4c71cc3f59393bac29819031ed5afcedda6359
Author: Aaron LI 
Date:   Wed Jul 28 19:08:35 2021 +0800

WIP

Summary of changes:
 sys/dev/virtual/nvmm/x86/nvmm_x86_svm.c | 1 +
 1 file changed, 1 insertion(+)

http://gitweb.dragonflybsd.org/dragonfly.git/commitdiff/5d4c71cc3f59393bac29819031ed5afcedda6359


-- 
DragonFly BSD source repository


git: test/nvmm/demo: Clean up header inclusions

2021-07-28 Thread Aaron LI


commit db3748d66cd4118cb8a910da198671ba63c8117f
Author: Aaron LI 
Date:   Wed Jul 28 19:06:44 2021 +0800

test/nvmm/demo: Clean up header inclusions

* Remove unused header inclusions.
* Reorder header inclusions.
* Define MSR_APICBASE, APICBASE_BSP and APICBASE_EN locally to be more
  OS-independent.

Summary of changes:
 test/nvmm/demo/toyvirt/common.h |  2 ++
 test/nvmm/demo/toyvirt/elf.c| 16 ++--
 test/nvmm/demo/toyvirt/main.c   | 28 +---
 test/nvmm/demo/toyvirt/toydev.c | 11 ++-
 4 files changed, 23 insertions(+), 34 deletions(-)

http://gitweb.dragonflybsd.org/dragonfly.git/commitdiff/db3748d66cd4118cb8a910da198671ba63c8117f


-- 
DragonFly BSD source repository


git: libnvmm: Remove unneeded header inclusions and defines

2021-07-28 Thread Aaron LI


commit ee35a76531765b13cb8c5cf07fbda8ac35f6ac68
Author: Aaron LI 
Date:   Wed Jul 28 18:41:18 2021 +0800

libnvmm: Remove unneeded header inclusions and defines

They are now provided by the  header file.

Summary of changes:
 lib/libnvmm/libnvmm.c | 1 -
 lib/libnvmm/libnvmm_x86.c | 4 
 2 files changed, 5 deletions(-)

http://gitweb.dragonflybsd.org/dragonfly.git/commitdiff/ee35a76531765b13cb8c5cf07fbda8ac35f6ac68


-- 
DragonFly BSD source repository


git: testcases/libnvmm: Remove unneeded header inclusions

2021-07-28 Thread Aaron LI


commit 5eafb1779f3de040f3c68fff1047789f14f0dcd5
Author: Aaron LI 
Date:   Wed Jul 28 18:44:24 2021 +0800

testcases/libnvmm: Remove unneeded header inclusions

They are now provided by the  header file.

Summary of changes:
 test/testcases/libnvmm/h_io_assist.c  | 4 
 test/testcases/libnvmm/h_mem_assist.c | 4 
 2 files changed, 8 deletions(-)

http://gitweb.dragonflybsd.org/dragonfly.git/commitdiff/5eafb1779f3de040f3c68fff1047789f14f0dcd5


-- 
DragonFly BSD source repository


git: nvmm: Move DragonFly-specific code to os_vmspace_create()

2021-07-28 Thread Aaron LI


commit 24f14bf420a8b016f2534fd3c7f3b9e45ce582e3
Author: Aaron LI 
Date:   Wed Jul 28 18:30:22 2021 +0800

nvmm: Move DragonFly-specific code to os_vmspace_create()

Move the DragonFly-specific pmap code to os_vmspace_create() in
nvmm_dragonfly.c, making the nvmm.c code more OS-independent.

Summary of changes:
 sys/dev/virtual/nvmm/nvmm.c   | 12 +---
 sys/dev/virtual/nvmm/nvmm_dragonfly.c | 14 +-
 2 files changed, 14 insertions(+), 12 deletions(-)

http://gitweb.dragonflybsd.org/dragonfly.git/commitdiff/24f14bf420a8b016f2534fd3c7f3b9e45ce582e3


-- 
DragonFly BSD source repository


git: nvmm: Adjust comments about TSC sync and gd_reqflags check

2021-07-28 Thread Aaron LI


commit 5d89fb896cac480f94283161572659828e344664
Author: Aaron LI 
Date:   Wed Jul 28 18:37:22 2021 +0800

nvmm: Adjust comments about TSC sync and gd_reqflags check

Replace QEMU with a more generic "emulator", and adjust the comments
about TSC sync to be more consistent and concise.

Summary of changes:
 sys/dev/virtual/nvmm/x86/nvmm_x86_svm.c | 24 +---
 sys/dev/virtual/nvmm/x86/nvmm_x86_vmx.c | 23 +--
 2 files changed, 18 insertions(+), 29 deletions(-)

http://gitweb.dragonflybsd.org/dragonfly.git/commitdiff/5d89fb896cac480f94283161572659828e344664


-- 
DragonFly BSD source repository


git: kernel - Rename vm_map_wire() and vm_map_unwire() (3)

2021-07-23 Thread Aaron LI


commit 046fb897988184761d9689559f8405b8844d6961
Author: Aaron LI 
Date:   Fri Jul 23 21:03:36 2021 +0800

kernel - Rename vm_map_wire() and vm_map_unwire() (3)

Remove a now obsolete comment.

Summary of changes:
 sys/vm/vm_map.c | 2 --
 1 file changed, 2 deletions(-)

http://gitweb.dragonflybsd.org/dragonfly.git/commitdiff/046fb897988184761d9689559f8405b8844d6961


-- 
DragonFly BSD source repository


git: nvmm: Fix building nvmm into kernel

2021-07-21 Thread Aaron LI


commit 11755db6b4ad8e01f32f277b591496121e03fc5d
Author: Aaron LI 
Date:   Wed Jul 21 14:53:38 2021 +0800

nvmm: Fix building nvmm into kernel

* Remove 'DIAGNOSTIC' define from 'nvmm_os.h'.  First, 'DIAGNOSTIC' and
  'INVARIANTS' are different options.  Secondly, 'DIAGNOSTIC' should be
  defined in kernel configs, e.g., LINT64 defines it.
* Remove 'LOCORE' define from 'nvmm_x86_{svmfunc,vmxfunc}.S'.  It's
  already defined on the command line, when compiling ASM source files
  with the kernel (i.e., building the module into the kernel).
* Manually define 'LOCORE' for 'nvmm_x86_{svmfunc,vmxfunc}.o'
  compilation in the Makefile, fixing building as a standalone module.

This fixes building nvmm into kernel, like LINT64.

Thanks swildner for reporting the issue and helping with the fix.

Summary of changes:
 sys/dev/virtual/nvmm/Makefile   | 3 +++
 sys/dev/virtual/nvmm/nvmm_os.h  | 1 -
 sys/dev/virtual/nvmm/x86/nvmm_x86_svmfunc.S | 1 -
 sys/dev/virtual/nvmm/x86/nvmm_x86_vmxfunc.S | 1 -
 4 files changed, 3 insertions(+), 3 deletions(-)

http://gitweb.dragonflybsd.org/dragonfly.git/commitdiff/11755db6b4ad8e01f32f277b591496121e03fc5d


-- 
DragonFly BSD source repository


git: nvmm: Port to DragonFly #15: anonymous object management

2021-07-20 Thread Aaron LI


commit b0d5436ed006f40d4b0e445281c4236be3d0fafd
Author: Aaron LI 
Date:   Wed May 19 18:52:22 2021 +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.

Summary of changes:
 sys/dev/virtual/nvmm/nvmm_compat.h | 40 ++
 1 file changed, 40 insertions(+)

http://gitweb.dragonflybsd.org/dragonfly.git/commitdiff/b0d5436ed006f40d4b0e445281c4236be3d0fafd


-- 
DragonFly BSD source repository


git: nvmm: Optimize DB regs save & restore

2021-07-20 Thread Aaron LI


commit b3f7271ce8a6736910e3e66d2fff5ddf4bd2c570
Author: Aaron LI 
Date:   Sun Jul 18 16:32:04 2021 +0800

nvmm: Optimize DB regs save & restore

Check PCB_DBREGS flag before save/restore DB regs.  If the current
thread doesn't use DB regs, then no need to save & restore them.

Meanwhile, revert to use x86_dbregs_save() and x86_dbregs_restore()
for the NetBSD code.

This is a partial revert of commit:
"nvmm: Save host DB regs in per-cpu structure"

Summary of changes:
 sys/dev/virtual/nvmm/x86/nvmm_x86.h | 64 -
 1 file changed, 42 insertions(+), 22 deletions(-)

http://gitweb.dragonflybsd.org/dragonfly.git/commitdiff/b3f7271ce8a6736910e3e66d2fff5ddf4bd2c570


-- 
DragonFly BSD source repository


git: nvmm: Clarify state handling

2021-07-20 Thread Aaron LI


commit a5120bfadfad0de9935ab56fe964d81273e72e37
Author: Aaron LI 
Date:   Sat Jul 3 11:16:33 2021 +0800

nvmm: Clarify state handling

* Make a clear distinction between global host state and per-cpu host
  state.  The former gets saved in a global structure, while the latter
  stays in the per-cpu structure.

* Make the host XCR0 part of the global host state, and stop using
  rdxcr() in each world switch because it's unnecessary.

Summary of changes:
 sys/dev/virtual/nvmm/x86/nvmm_x86_svm.c | 82 +++--
 sys/dev/virtual/nvmm/x86/nvmm_x86_vmx.c | 74 +
 2 files changed, 92 insertions(+), 64 deletions(-)

http://gitweb.dragonflybsd.org/dragonfly.git/commitdiff/a5120bfadfad0de9935ab56fe964d81273e72e37


-- 
DragonFly BSD source repository


git: test/nvmm/demo: Fix some compilation warnings

2021-07-20 Thread Aaron LI


commit ce7051ae204547a0cd2e8a5ad65b9be2e7f528e5
Author: Aaron LI 
Date:   Fri May 28 23:10:04 2021 +0800

test/nvmm/demo: Fix some compilation warnings

Summary of changes:
 test/nvmm/demo/smallkern/console.c | 2 +-
 test/nvmm/demo/smallkern/main.c| 4 ++--
 test/nvmm/demo/toyvirt/elf.c   | 2 +-
 test/nvmm/demo/toyvirt/main.c  | 2 +-
 test/nvmm/demo/toyvirt/toydev.c| 2 +-
 5 files changed, 6 insertions(+), 6 deletions(-)

http://gitweb.dragonflybsd.org/dragonfly.git/commitdiff/ce7051ae204547a0cd2e8a5ad65b9be2e7f528e5


-- 
DragonFly BSD source repository


git: nvmm: Save host DB regs in per-cpu structure

2021-07-20 Thread Aaron LI


commit f6c0185203d8a0e5955a47e12e0efad053b88532
Author: Aaron LI 
Date:   Fri Jul 9 12:50:33 2021 +0800

nvmm: Save host DB regs in per-cpu structure

* The host DB regs save/restore operations are performed outside the
  hard interrupt disablement.  If the DB regs were saved in curthread's
  PCB, an interrupt thread running just after hard interrupts are
  enabled again could overwrite the DB regs in the PCB with the guest DB
  regs.  Saving the host DB regs in the per-cpu structure avoid such
  issues.

* This change also makes the code a bit more OS-independent.

Credit-to: Matt Dillon
Referred-to: FreeBSD bhyve

Summary of changes:
 sys/dev/virtual/nvmm/x86/nvmm_x86.h | 63 -
 sys/dev/virtual/nvmm/x86/nvmm_x86_svm.c |  5 +--
 sys/dev/virtual/nvmm/x86/nvmm_x86_vmx.c |  5 +--
 3 files changed, 28 insertions(+), 45 deletions(-)

http://gitweb.dragonflybsd.org/dragonfly.git/commitdiff/f6c0185203d8a0e5955a47e12e0efad053b88532


-- 
DragonFly BSD source repository


git: kernel - Remove 'td %p blah: timeout race' kprintf

2021-07-20 Thread Aaron LI


commit 8ef3e14af2bbd354a089d97c3f18a94817561e88
Author: Matthew Dillon 
Date:   Thu Jul 15 19:27:35 2021 -0700

kernel - Remove 'td %p blah: timeout race' kprintf

* Remove debugging kprintf() used to verify that the race can
  happen.  Yes, it can, particularly on a guest VM (but it can
  happen on a host too).

Summary of changes:
 sys/kern/kern_synch.c | 9 +
 1 file changed, 5 insertions(+), 4 deletions(-)

http://gitweb.dragonflybsd.org/dragonfly.git/commitdiff/8ef3e14af2bbd354a089d97c3f18a94817561e88


-- 
DragonFly BSD source repository


git: libnvmm.3: Mention 'calc-vm' and 'demo' test code in FILES

2021-07-20 Thread Aaron LI


commit 297ce728f02cb4d66932a4fb8447fd88631e92a4
Author: Aaron LI 
Date:   Mon Jun 7 21:41:21 2021 +0800

libnvmm.3: Mention 'calc-vm' and 'demo' test code in FILES

Also sort the items in FILES section.

Summary of changes:
 lib/libnvmm/libnvmm.3 | 29 -
 1 file changed, 20 insertions(+), 9 deletions(-)

http://gitweb.dragonflybsd.org/dragonfly.git/commitdiff/297ce728f02cb4d66932a4fb8447fd88631e92a4


-- 
DragonFly BSD source repository


git: libnvmm.3: Mention regression tests in FILES section

2021-07-20 Thread Aaron LI


commit 0fd9ec5066ba94c995feefaa254b9225377bbf7c
Author: Aaron LI 
Date:   Thu Jun 17 06:49:59 2021 +0800

libnvmm.3: Mention regression tests in FILES section

Summary of changes:
 lib/libnvmm/libnvmm.3 | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

http://gitweb.dragonflybsd.org/dragonfly.git/commitdiff/0fd9ec5066ba94c995feefaa254b9225377bbf7c


-- 
DragonFly BSD source repository


git: kernel - Improve invltlb latency warnings

2021-07-20 Thread Aaron LI


commit ab4aa0bb83f0276cd18a2336e3bb759843d8c3a3
Author: Matthew Dillon 
Date:   Thu Jul 15 20:36:34 2021 -0700

kernel - Improve invltlb latency warnings

* Improve kprintf()s for smp_invltlb latency warnings.  Make
  it abundantly clear that these are mostly WARNING messages,
  not fatal messages.

* Tested on VM with host under load and VM running nice +5.

Summary of changes:
 sys/kern/lwkt_thread.c| 9 +++--
 sys/platform/pc64/x86_64/mp_machdep.c | 3 ++-
 sys/platform/pc64/x86_64/pmap_inval.c | 4 +++-
 3 files changed, 12 insertions(+), 4 deletions(-)

http://gitweb.dragonflybsd.org/dragonfly.git/commitdiff/ab4aa0bb83f0276cd18a2336e3bb759843d8c3a3


-- 
DragonFly BSD source repository


git: test/nvmm: Add 'calc-vm' (simple VM-based calculator)

2021-07-20 Thread Aaron LI


commit a4da4a906fbdf93c54552e46f5ece1f7597cd169
Author: Aaron LI 
Date:   Fri May 28 07:22:52 2021 +0800

test/nvmm: Add 'calc-vm' (simple VM-based calculator)

A simple calculator. Creates a VM which performs the addition of the two
ints given as argument.

Obtained from: https://www.netbsd.org/~maxv/nvmm/calc-vm.c
Blog: https://blog.netbsd.org/tnf/entry/from_zero_to_nvmm

Summary of changes:
 test/nvmm/calc-vm.c | 115 
 1 file changed, 115 insertions(+)
 create mode 100644 test/nvmm/calc-vm.c

http://gitweb.dragonflybsd.org/dragonfly.git/commitdiff/a4da4a906fbdf93c54552e46f5ece1f7597cd169


-- 
DragonFly BSD source repository


git: testcases/libnvmm: Improve makefile to not write in source tree

2021-07-20 Thread Aaron LI


commit edaa287824f1526c0efb7162c79c5b919eefbd23
Author: Aaron LI 
Date:   Sat Jun 19 20:31:52 2021 +0800

testcases/libnvmm: Improve makefile to not write in source tree

Both build and dfregress(8) would write output in place in the source
tree, which however may be on a readonly mount via NFS.  Improve the
makefile to cpdup the whole directory to /tmp and then do everything
there. (credit to Matt Dillon for the idea)

Summary of changes:
 test/testcases/libnvmm/Makefile | 13 ++---
 1 file changed, 10 insertions(+), 3 deletions(-)

http://gitweb.dragonflybsd.org/dragonfly.git/commitdiff/edaa287824f1526c0efb7162c79c5b919eefbd23


-- 
DragonFly BSD source repository


git: test/nvmm: Add a demo for demonstration of libnvmm(3) API

2021-07-20 Thread Aaron LI


commit 8368e25f758b85c2863fe95506b40c66b86379d5
Author: Aaron LI 
Date:   Fri May 28 07:28:27 2021 +0800

test/nvmm: Add a demo for demonstration of libnvmm(3) API

The demo consists of two components:

* toyvirt: a toy virtualizer, that executes in a VM the 64bit ELF binary
  given as argument;
* smallkern: an example of such binary.

Obtained from: https://www.netbsd.org/~maxv/nvmm/nvmm-demo.zip

Summary of changes:
 test/nvmm/demo/README.txt   | 103 ++
 test/nvmm/demo/smallkern/Makefile   |   7 +
 test/nvmm/demo/smallkern/console.c  |  70 
 test/nvmm/demo/smallkern/locore.S   | 512 
 test/nvmm/demo/smallkern/main.c | 320 +
 test/nvmm/demo/smallkern/pdir.h |  85 +
 test/nvmm/demo/smallkern/smallkern.h|  68 
 test/nvmm/demo/smallkern/smallkern.ldscript |  52 +++
 test/nvmm/demo/smallkern/trap.S | 199 +++
 test/nvmm/demo/toyvirt/Makefile |   6 +
 test/nvmm/demo/toyvirt/common.h |  48 +++
 test/nvmm/demo/toyvirt/elf.c| 112 ++
 test/nvmm/demo/toyvirt/main.c   | 434 +++
 test/nvmm/demo/toyvirt/toydev.c | 137 
 14 files changed, 2153 insertions(+)
 create mode 100644 test/nvmm/demo/README.txt
 create mode 100644 test/nvmm/demo/smallkern/Makefile
 create mode 100644 test/nvmm/demo/smallkern/console.c
 create mode 100644 test/nvmm/demo/smallkern/locore.S
 create mode 100644 test/nvmm/demo/smallkern/main.c
 create mode 100644 test/nvmm/demo/smallkern/pdir.h
 create mode 100644 test/nvmm/demo/smallkern/smallkern.h
 create mode 100644 test/nvmm/demo/smallkern/smallkern.ldscript
 create mode 100644 test/nvmm/demo/smallkern/trap.S
 create mode 100644 test/nvmm/demo/toyvirt/Makefile
 create mode 100644 test/nvmm/demo/toyvirt/common.h
 create mode 100644 test/nvmm/demo/toyvirt/elf.c
 create mode 100644 test/nvmm/demo/toyvirt/main.c
 create mode 100644 test/nvmm/demo/toyvirt/toydev.c

http://gitweb.dragonflybsd.org/dragonfly.git/commitdiff/8368e25f758b85c2863fe95506b40c66b86379d5


-- 
DragonFly BSD source repository


git: NVMM: Sync with NetBSD #2: SVM & VMX backends

2021-07-20 Thread Aaron LI


commit 5aaefa93888b1a52b8cbe581ad3b049976fb9bf7
Author: Aaron LI 
Date:   Sun Jun 27 07:58:06 2021 +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.

Summary of changes:
 sys/dev/virtual/nvmm/nvmm.c |   2 +-
 sys/dev/virtual/nvmm/nvmm_compat.h  |   7 +-
 sys/dev/virtual/nvmm/x86/nvmm_x86_svm.c |  43 ++
 sys/dev/virtual/nvmm/x86/nvmm_x86_svmfunc.S |   6 --
 sys/dev/virtual/nvmm/x86/nvmm_x86_vmx.c | 122 ++--
 sys/dev/virtual/nvmm/x86/nvmm_x86_vmxfunc.S |  11 ---
 6 files changed, 109 insertions(+), 82 deletions(-)

http://gitweb.dragonflybsd.org/dragonfly.git/commitdiff/5aaefa93888b1a52b8cbe581ad3b049976fb9bf7


-- 
DragonFly BSD source repository


git: kernel - Make most IPI related globals __read_mostly

2021-07-20 Thread Aaron LI


commit 36bbfccb653463167eb07cf99d167905daa3cd46
Author: Matthew Dillon 
Date:   Thu Jul 15 19:55:08 2021 -0700

kernel - Make most IPI related globals __read_mostly

* Most of these globals should be made __read_mostly, so make
  them __read_mostly.

Summary of changes:
 sys/platform/pc64/x86_64/mp_machdep.c | 18 +-
 1 file changed, 9 insertions(+), 9 deletions(-)

http://gitweb.dragonflybsd.org/dragonfly.git/commitdiff/36bbfccb653463167eb07cf99d167905daa3cd46


-- 
DragonFly BSD source repository


git: NVMM: Update libnvmm.3 and TODO.nvmm

2021-07-20 Thread Aaron LI


commit b6772502b01cecb3898e900026d25fa4215216dd
Author: Aaron LI 
Date:   Sun Jul 4 21:31:40 2021 +0800

NVMM: Update libnvmm.3 and TODO.nvmm

Summary of changes:
 doc/TODO.nvmm | 10 --
 lib/libnvmm/libnvmm.3 | 37 ++---
 2 files changed, 34 insertions(+), 13 deletions(-)

http://gitweb.dragonflybsd.org/dragonfly.git/commitdiff/b6772502b01cecb3898e900026d25fa4215216dd


-- 
DragonFly BSD source repository


git: nvmm: Implement waits for lwkt_send_ipiq_mask()

2021-07-20 Thread Aaron LI


commit 8b383bf46fb3eda81af783e8a2acc6ad467bf0b5
Author: Aaron LI 
Date:   Sun Jun 13 14:25:39 2021 +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.

Summary of changes:
 sys/dev/virtual/nvmm/x86/nvmm_x86_svm.c | 31 +--
 sys/dev/virtual/nvmm/x86/nvmm_x86_vmx.c | 30 --
 2 files changed, 49 insertions(+), 12 deletions(-)

http://gitweb.dragonflybsd.org/dragonfly.git/commitdiff/8b383bf46fb3eda81af783e8a2acc6ad467bf0b5


-- 
DragonFly BSD source repository


git: Import libnvmm tests from NetBSD-current

2021-07-20 Thread Aaron LI


commit 8f70d46c99a693ffe1b10d34c1715ccb6815d400
Author: Aaron LI 
Date:   Wed Jun 16 07:17:28 2021 +0800

Import libnvmm tests from NetBSD-current

Branch: NetBSD-current
Date: 2021-06-25
Path: tests/lib/libnvmm

Summary of changes:
 test/testcases/libnvmm/Makefile   |  26 ++
 test/testcases/libnvmm/h_io_assist.c  | 389 
 test/testcases/libnvmm/h_io_assist_asm.S  | 218 ++
 test/testcases/libnvmm/h_mem_assist.c | 473 ++
 test/testcases/libnvmm/h_mem_assist_asm.S | 409 ++
 test/testcases/libnvmm/t_io_assist.sh |  50 
 test/testcases/libnvmm/t_mem_assist.sh|  50 
 7 files changed, 1615 insertions(+)
 create mode 100644 test/testcases/libnvmm/Makefile
 create mode 100644 test/testcases/libnvmm/h_io_assist.c
 create mode 100644 test/testcases/libnvmm/h_io_assist_asm.S
 create mode 100644 test/testcases/libnvmm/h_mem_assist.c
 create mode 100644 test/testcases/libnvmm/h_mem_assist_asm.S
 create mode 100644 test/testcases/libnvmm/t_io_assist.sh
 create mode 100644 test/testcases/libnvmm/t_mem_assist.sh

http://gitweb.dragonflybsd.org/dragonfly.git/commitdiff/8f70d46c99a693ffe1b10d34c1715ccb6815d400


-- 
DragonFly BSD source repository


git: test/nvmm: Add progress logs in 'calc-vm'

2021-07-20 Thread Aaron LI


commit 2e818704e32025b58b73bb73f2d03dd85cc4b2b2
Author: Aaron LI 
Date:   Mon May 31 07:18:21 2021 +0800

test/nvmm: Add progress logs in 'calc-vm'

Help test/debug NVMM/libnvmm.

Summary of changes:
 test/nvmm/calc-vm.c | 9 +
 1 file changed, 9 insertions(+)

http://gitweb.dragonflybsd.org/dragonfly.git/commitdiff/2e818704e32025b58b73bb73f2d03dd85cc4b2b2


-- 
DragonFly BSD source repository


git: nvmm - Fix TSC synchronization issues

2021-07-20 Thread Aaron LI


commit c9096cab4ce6c0febd2dfe41f841c7e844fea2a9
Author: Matthew Dillon 
Date:   Wed Jun 23 17:51:40 2021 -0700

nvmm - Fix TSC synchronization issues

* Save the guest TSC offset in cpudata as 'gtsc_offset', replacing the
  origin absolute TSC value stored as 'gtsc'.

* QEMU and other emulators probably have no intention of actually
  forcing the TSC state in the SETSTATE call, so don't act on it
  if it matches the value we previously returned.

  This allows the guest to inherit a completely synchronized TSC from
  the host.  Without it, the TSC's for the VCPUs wind up being badly
  out of sync.

* Updating MSR_TSC completely blows up TSC mp synchronization.  We
  assume QEMU did not intend to update the TSC if it tries to write
  0 or tries to write the value returned in the previous getstate.

* This allows kernels to use the TSC as a clock, which costs nothing,
  verses the ACPI or HPET which have horrible overhead and a global
  mutex in QEMU.

Summary of changes:
 sys/dev/virtual/nvmm/x86/nvmm_x86_svm.c | 37 ++---
 sys/dev/virtual/nvmm/x86/nvmm_x86_vmx.c | 36 +---
 2 files changed, 57 insertions(+), 16 deletions(-)

http://gitweb.dragonflybsd.org/dragonfly.git/commitdiff/c9096cab4ce6c0febd2dfe41f841c7e844fea2a9


-- 
DragonFly BSD source repository


git: nvmm: Don't assume comm page size to be PAGE_SIZE

2021-07-20 Thread Aaron LI


commit d8a7506105a94efa46aa081628a34fd465090a5d
Author: Aaron LI 
Date:   Mon Jul 12 22:37:55 2021 +0800

nvmm: Don't assume comm page size to be PAGE_SIZE

Don't assume the comm page size to be PAGE_SIZE but add the
'NVMM_COMM_PAGE_SIZE' macro to determine the size.  So the code is
now independent to comm page size and thus it can be easily extended
in the future.

Summary of changes:
 sys/dev/virtual/nvmm/nvmm.c  | 18 ++
 sys/dev/virtual/nvmm/nvmm.h  |  5 -
 sys/dev/virtual/nvmm/nvmm_internal.h |  3 +++
 3 files changed, 13 insertions(+), 13 deletions(-)

http://gitweb.dragonflybsd.org/dragonfly.git/commitdiff/d8a7506105a94efa46aa081628a34fd465090a5d


-- 
DragonFly BSD source repository


git: nvmm: Add volatile and memory barrier to clts inline ASM

2021-07-20 Thread Aaron LI


commit e0cf4209f611a3c97846b8d074cff9d32d52791e
Author: Aaron LI 
Date:   Sun Jul 11 13:10:45 2021 +0800

nvmm: Add volatile and memory barrier to clts inline ASM

The clts inline ASM should have a memory barrier.  Also add 'volatile'
to it.  Now it fully matches the one in NetBSD FPU code.

Summary of changes:
 sys/dev/virtual/nvmm/x86/nvmm_x86.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

http://gitweb.dragonflybsd.org/dragonfly.git/commitdiff/e0cf4209f611a3c97846b8d074cff9d32d52791e


-- 
DragonFly BSD source repository


git: nvmm: Move DragonFly module code in nvmm.c to nvmm_dragonfly.c

2021-07-20 Thread Aaron LI


commit 002185e5cffeaa6b95bb215e075d8828b4d21e70
Author: Aaron LI 
Date:   Sun Jul 18 18:58:01 2021 +0800

nvmm: Move DragonFly module code in nvmm.c to nvmm_dragonfly.c

Move the OS-specific DragonFly module code in nvmm.c to nvmm_dragonfly.c,
making nvmm.c source file more OS-independent.  Adjust several static
functions and variables for this purpose.

Summary of changes:
 sys/dev/virtual/nvmm/nvmm.c   | 174 ++
 sys/dev/virtual/nvmm/nvmm_dragonfly.c | 153 ++
 sys/dev/virtual/nvmm/nvmm_internal.h  |  10 ++
 3 files changed, 173 insertions(+), 164 deletions(-)

http://gitweb.dragonflybsd.org/dragonfly.git/commitdiff/002185e5cffeaa6b95bb215e075d8828b4d21e70


-- 
DragonFly BSD source repository


git: nvmm: Port to DragonFly #24: pmap transform & TLB invalidation

2021-07-20 Thread Aaron LI


commit 3ecc20a00d040552c4244a2ec7848d16c6af5e15
Author: Aaron LI 
Date:   Sun Jun 6 19:31:54 2021 +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.

Summary of changes:
 sys/dev/virtual/nvmm/x86/nvmm_x86_svm.c |  9 +
 sys/dev/virtual/nvmm/x86/nvmm_x86_vmx.c | 10 --
 sys/platform/pc64/include/pmap.h|  4 
 sys/platform/pc64/x86_64/pmap.c |  4 
 sys/platform/pc64/x86_64/pmap_inval.c   | 18 ++
 5 files changed, 43 insertions(+), 2 deletions(-)

http://gitweb.dragonflybsd.org/dragonfly.git/commitdiff/3ecc20a00d040552c4244a2ec7848d16c6af5e15


-- 
DragonFly BSD source repository


git: nvmm: Reduce NVMM_MAX_VCPUS from 256 to 128

2021-07-20 Thread Aaron LI


commit ddb95be16a84b930e22002e1ffea3cad1ddd5049
Author: Aaron LI 
Date:   Sun Jul 4 20:41:42 2021 +0800

nvmm: Reduce NVMM_MAX_VCPUS from 256 to 128

Unfortunately not all x86 guests can work with a max value of 256, due
to overflowing uint8_t.  Reduce it to 128.

Summary of changes:
 sys/dev/virtual/nvmm/nvmm_internal.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

http://gitweb.dragonflybsd.org/dragonfly.git/commitdiff/ddb95be16a84b930e22002e1ffea3cad1ddd5049


-- 
DragonFly BSD source repository


git: nvmm: Make FPU state more OS-indenpendent

2021-07-20 Thread Aaron LI


commit 23b2397d3e9775d301066c9a22f31ebb559af446
Author: Aaron LI 
Date:   Sat Jul 3 16:59:33 2021 +0800

nvmm: Make FPU state more OS-indenpendent

* Introduce an OS-indenpendent 'nvmm_x64_state_fpu' structure, derived
  from NetBSD's current FPU implementation.
* Also introduce the 'nvmm_x86_xsave' structure, containing the FPU area
  and the XSAVE header.
* Add the 'nvmm_x86_xsave_size()' that determines the XSAVE area size to
  simplify the code.
* Rename gfpu -> gxsave, for clarity.
* Define 'CTASSERT' because 'nvmm.h' and 'nvmm_x86.h' headers will
  be used by libnvmm(3), but  only defines 'CTASSERT' for
  kernel.
* Update libnvmm.3 man page accordingly.

Summary of changes:
 lib/libnvmm/libnvmm.3   |  4 +-
 sys/dev/virtual/nvmm/nvmm.h |  6 +++
 sys/dev/virtual/nvmm/nvmm_compat.h  | 11 --
 sys/dev/virtual/nvmm/x86/nvmm_x86.c | 15 
 sys/dev/virtual/nvmm/x86/nvmm_x86.h | 65 ++---
 sys/dev/virtual/nvmm/x86/nvmm_x86_svm.c | 41 ++---
 sys/dev/virtual/nvmm/x86/nvmm_x86_vmx.c | 42 ++---
 7 files changed, 121 insertions(+), 63 deletions(-)

http://gitweb.dragonflybsd.org/dragonfly.git/commitdiff/23b2397d3e9775d301066c9a22f31ebb559af446


-- 
DragonFly BSD source repository


git: nvmm: Improve nvmm_return_needed() by using nvmm_break_wanted()

2021-07-20 Thread Aaron LI


commit 2b54422ce4d4ae3ffc257cd862f31e7c191b0360
Author: Aaron LI 
Date:   Sun Jun 27 11:54:20 2021 +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.

Summary of changes:
 sys/dev/virtual/nvmm/nvmm_compat.h   | 8 
 sys/dev/virtual/nvmm/nvmm_internal.h | 4 ++--
 2 files changed, 2 insertions(+), 10 deletions(-)

http://gitweb.dragonflybsd.org/dragonfly.git/commitdiff/2b54422ce4d4ae3ffc257cd862f31e7c191b0360


-- 
DragonFly BSD source repository


git: nvmm: Add back NetBSD bits

2021-07-20 Thread Aaron LI


commit 8a0a54bf1b2d5a47a44eb96b452cc7a0d77d83fd
Author: Aaron LI 
Date:   Sun Jul 18 20:03:57 2021 +0800

nvmm: Add back NetBSD bits

Bring back the NetBSD bits lost during the porting.  One minor change is
required: MODULE_CLASS_MISC -> MODULE_CLASS_DRIVER.  Otherwise, loading
nvmm.kmod would fail with error:

module error: incompatible module class 1 for `nvmm' (wanted 3)

Now the same code builds and works on NetBSD (of course, NetBSD requires
a different set of Makefiles).

Summary of changes:
 sys/dev/virtual/nvmm/nvmm_netbsd.c  | 236 
 sys/dev/virtual/nvmm/x86/nvmm_x86_svm.c |   6 +-
 sys/dev/virtual/nvmm/x86/nvmm_x86_svmfunc.S |  23 ++-
 sys/dev/virtual/nvmm/x86/nvmm_x86_vmx.c |   6 +-
 sys/dev/virtual/nvmm/x86/nvmm_x86_vmxfunc.S |  13 +-
 5 files changed, 277 insertions(+), 7 deletions(-)

http://gitweb.dragonflybsd.org/dragonfly.git/commitdiff/8a0a54bf1b2d5a47a44eb96b452cc7a0d77d83fd


-- 
DragonFly BSD source repository


git: test/nvmm/demo: Make 'smallkern' more self-contained

2021-07-20 Thread Aaron LI


commit 3bac6f2a5f43885bd5ef44f59869d5c23e5bc972
Author: Aaron LI 
Date:   Tue Jun 8 12:52:46 2021 +0800

test/nvmm/demo: Make 'smallkern' more self-contained

Provide local 'asm.h' and 'trap.h' headers (derived from NetBSD),
extract necessary PTE_* and PSL_* defines, making 'smallkern' much more
self-contained, which greatly reduces the needed modifications for
porting it to DragonFly.  Moreover, it helps to keep the ported code
working on both operating systems.

Summary of changes:
 .../fake_sbrk.S => test/nvmm/demo/smallkern/asm.h  | 88 ++
 test/nvmm/demo/smallkern/locore.S  | 14 ++--
 test/nvmm/demo/smallkern/trap.S| 12 +--
 sys/sys/reg.h => test/nvmm/demo/smallkern/trap.h   | 61 ---
 4 files changed, 83 insertions(+), 92 deletions(-)
 copy lib/libc/x86_64/sys/fake_sbrk.S => test/nvmm/demo/smallkern/asm.h (62%)
 copy sys/sys/reg.h => test/nvmm/demo/smallkern/trap.h (57%)

http://gitweb.dragonflybsd.org/dragonfly.git/commitdiff/3bac6f2a5f43885bd5ef44f59869d5c23e5bc972


-- 
DragonFly BSD source repository


git: kernel - Add RQF_XINVLTLB to gd_reqflags

2021-07-20 Thread Aaron LI


commit 1dc32433919f9a93f185b6d21071bbe57cea24f4
Author: Matthew Dillon 
Date:   Tue Jun 22 22:19:33 2021 -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.

Summary of changes:
 sys/cpu/x86_64/include/cpu.h | 11 ++-
 sys/kern/usched_dfly.c   |  2 +-
 sys/platform/pc64/apic/apic_vector.s |  1 +
 sys/platform/pc64/x86_64/genassym.c  |  2 ++
 sys/sys/globaldata.h |  7 ++-
 5 files changed, 16 insertions(+), 7 deletions(-)

http://gitweb.dragonflybsd.org/dragonfly.git/commitdiff/1dc32433919f9a93f185b6d21071bbe57cea24f4


-- 
DragonFly BSD source repository


git: nnvm - Move *_fpu_enter/leave inside the cli/sti

2021-07-20 Thread Aaron LI


commit 3042e1c3c65207e98573ac087d9f00cf8008f9eb
Author: Matthew Dillon 
Date:   Mon Jun 28 23:04:31 2021 -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.

Summary of changes:
 sys/dev/virtual/nvmm/x86/nvmm_x86_svm.c | 6 +++---
 sys/dev/virtual/nvmm/x86/nvmm_x86_vmx.c | 6 +++---
 2 files changed, 6 insertions(+), 6 deletions(-)

http://gitweb.dragonflybsd.org/dragonfly.git/commitdiff/3042e1c3c65207e98573ac087d9f00cf8008f9eb


-- 
DragonFly BSD source repository


git: nvmm: Improve FPU support and reduce diff against NetBSD

2021-07-20 Thread Aaron LI


commit e809d7331258dcdc48c5719f441ab5c827a0df10
Author: Aaron LI 
Date:   Wed Jun 30 07:29:27 2021 +0800

nvmm: Improve FPU support and reduce diff against NetBSD

I was using 'struct savexmm64' to translate NetBSD's 'struct xsave_header'.
This works but isn't good enough, because 'savexmm64' can't deal with
xstate, so I disabled the xstate header related code in the old code.

This commit changes to use 'struct saveymm64' instead.  It contains the
XSAVE header and YMM xstate component, allowing us to enable the
originally disabled xstate header code in NVMM.

In addition, define some compat macros to adapt NetBSD's FPU structures
to ours, reducing the NVMM code difference against NetBSD.

Will later work on AVX support in guest VM.

Summary of changes:
 sys/dev/virtual/nvmm/nvmm_compat.h  | 11 +++
 sys/dev/virtual/nvmm/x86/nvmm_x86.c | 12 ++--
 sys/dev/virtual/nvmm/x86/nvmm_x86_svm.c | 21 +
 sys/dev/virtual/nvmm/x86/nvmm_x86_vmx.c | 20 +---
 4 files changed, 35 insertions(+), 29 deletions(-)

http://gitweb.dragonflybsd.org/dragonfly.git/commitdiff/e809d7331258dcdc48c5719f441ab5c827a0df10


-- 
DragonFly BSD source repository


git: pmap: Change pmap->pm_invgen to uint64_t to be compatible with NVMM

2021-07-20 Thread Aaron LI


commit 39d0d2cbbe1148ae03999ea78008fd6898d8835d
Author: Aaron LI 
Date:   Fri Jun 25 18:08:46 2021 +0800

pmap: Change pmap->pm_invgen to uint64_t to be compatible with NVMM

Change the 'pmap->pm_invgen' member from 'long' to 'uint64_t', to be
compatible with NVMM's machgen.

Update the atomic operation on 'pm_invgen' accordingly, and no need to
use the '_acq' acquire version (including a read barrier).

Credit to Matt Dillon.

Summary of changes:
 sys/kern/sys_vmm.c| 2 +-
 sys/platform/pc64/include/pmap.h  | 2 +-
 sys/platform/pc64/x86_64/pmap_inval.c | 4 ++--
 3 files changed, 4 insertions(+), 4 deletions(-)

http://gitweb.dragonflybsd.org/dragonfly.git/commitdiff/39d0d2cbbe1148ae03999ea78008fd6898d8835d


-- 
DragonFly BSD source repository


git: nvmm - Improve cast portability of vmx_resume_rip

2021-07-20 Thread Aaron LI


commit bd9b21da6dcfb7d9820090791388a4b55b68673b
Author: Matthew Dillon 
Date:   Sat Jul 10 11:32:30 2021 -0700

nvmm - Improve cast portability of vmx_resume_rip

* Cast pointer to function through uintptr_t for maximum portability
  (avoids warnings on some compilers).

Summary of changes:
 sys/dev/virtual/nvmm/x86/nvmm_x86_vmx.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

http://gitweb.dragonflybsd.org/dragonfly.git/commitdiff/bd9b21da6dcfb7d9820090791388a4b55b68673b


-- 
DragonFly BSD source repository


git: nvmm: Check for pending host events before VM entry

2021-07-20 Thread Aaron LI


commit d33f1ab72c6e870a34ca45a24b9f1b368ab25a7a
Author: Aaron LI 
Date:   Sun Jun 27 11:59:13 2021 +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.

Summary of changes:
 sys/dev/virtual/nvmm/x86/nvmm_x86_svm.c | 20 +++-
 sys/dev/virtual/nvmm/x86/nvmm_x86_vmx.c | 17 +
 2 files changed, 36 insertions(+), 1 deletion(-)

http://gitweb.dragonflybsd.org/dragonfly.git/commitdiff/d33f1ab72c6e870a34ca45a24b9f1b368ab25a7a


-- 
DragonFly BSD source repository


git: nvmm: Improve CPUID emulation #1: flags

2021-07-20 Thread Aaron LI


commit 3247cd11e7d330e1724d1214fc71385392a8e6a6
Author: Aaron LI 
Date:   Sat Jul 3 11:51:53 2021 +0800

nvmm: Improve CPUID emulation #1: flags

* Mask PQE (Platform Quality of Service Enforcement); shouldn't be
  exposed.
* Add LA57, for completeness.
* Add more flags in Fn8000_0001:EDX, for AMD CPUs.

Summary of changes:
 sys/dev/virtual/nvmm/x86/nvmm_x86.c | 20 ++--
 1 file changed, 18 insertions(+), 2 deletions(-)

http://gitweb.dragonflybsd.org/dragonfly.git/commitdiff/3247cd11e7d330e1724d1214fc71385392a8e6a6


-- 
DragonFly BSD source repository


git: Revert "libnvmm: Fix mmap() failure with 'permission denied'"

2021-07-20 Thread Aaron LI


commit ec2ba06409873bb923872be7ec143cd627de1698
Author: Aaron LI 
Date:   Sat Jul 3 23:10:56 2021 +0800

Revert "libnvmm: Fix mmap() failure with 'permission denied'"

Because libnvmm no longer calls mmap() to map the VCPU comm page, revert
to the original code to distinguish root owner (open '/dev/nvmm' with
O_WRONLY) vs. non-root owner (open with O_RDONLY).

Summary of changes:
 lib/libnvmm/libnvmm.c   | 20 
 sys/dev/virtual/nvmm/nvmm.c |  5 ++---
 2 files changed, 18 insertions(+), 7 deletions(-)

http://gitweb.dragonflybsd.org/dragonfly.git/commitdiff/ec2ba06409873bb923872be7ec143cd627de1698


-- 
DragonFly BSD source repository


git: nvmm: Revert to use os_curcpu() in vmx_vmcs_enter()

2021-07-20 Thread Aaron LI


commit ac42d1dfa1b03a85a780470425488466a76ae96b
Author: Aaron LI 
Date:   Sun Jul 11 16:08:23 2021 +0800

nvmm: Revert to use os_curcpu() in vmx_vmcs_enter()

os_curcpu() returns a pointer to the current per-cpu data, which is used
in vmx_vmcs_enter() to clear a VMCS from a remote CPU.  So it's more
efficient and clean than using the os_curcpu_number(), which requires
another lookup to obtain the per-cpu data pointer from the CPU id.

This effectively reverts the commit:
nvmm: Fix issues of porting 'curcpu()' as 'mycpu'

The "VMX fail valid" panics I had then were actually caused by the
missing wait for the asynchronous IPI request to clear VMCS from a
remote CPU, which had been fixed in a later commit.

Summary of changes:
 sys/dev/virtual/nvmm/nvmm_os.h  |  2 --
 sys/dev/virtual/nvmm/x86/nvmm_x86_vmx.c | 15 +++
 2 files changed, 7 insertions(+), 10 deletions(-)

http://gitweb.dragonflybsd.org/dragonfly.git/commitdiff/ac42d1dfa1b03a85a780470425488466a76ae96b


-- 
DragonFly BSD source repository


git: test/nvmm/demo: Update makefiles and README

2021-07-20 Thread Aaron LI


commit ff902b0e20a1cf6b0ae36a43b338114fd6da7694
Author: Aaron LI 
Date:   Fri May 28 18:39:58 2021 +0800

test/nvmm/demo: Update makefiles and README

* Adjust makefiles to be a bit more generic.
* Adjust compiler flags to enable more warnings and debug info.
* Add top-level makefile to ease the build.
* Update README.

Summary of changes:
 test/nvmm/demo/Makefile   |  3 +++
 test/nvmm/demo/README.txt | 37 +++--
 test/nvmm/demo/smallkern/Makefile | 10 +++---
 test/nvmm/demo/toyvirt/Makefile   |  8 +---
 4 files changed, 34 insertions(+), 24 deletions(-)
 create mode 100644 test/nvmm/demo/Makefile

http://gitweb.dragonflybsd.org/dragonfly.git/commitdiff/ff902b0e20a1cf6b0ae36a43b338114fd6da7694


-- 
DragonFly BSD source repository


git: nvmm: Port to DragonFly #20: preemption & critical section

2021-07-20 Thread Aaron LI


commit 0059657bc2079e0533a8ec5814c9f8279e94bd6c
Author: Aaron LI 
Date:   Sat May 22 21:58:44 2021 +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.

Summary of changes:
 sys/dev/virtual/nvmm/nvmm_compat.h   | 30 --
 sys/dev/virtual/nvmm/nvmm_internal.h |  2 +-
 2 files changed, 29 insertions(+), 3 deletions(-)

http://gitweb.dragonflybsd.org/dragonfly.git/commitdiff/0059657bc2079e0533a8ec5814c9f8279e94bd6c


-- 
DragonFly BSD source repository


git: nvmm - Fix event commit logic

2021-07-20 Thread Aaron LI


commit dd353e3086ebbad842607aab7b78ac7f759aa284
Author: Matthew Dillon 
Date:   Mon Jul 5 23:22:22 2021 -0700

nvmm - Fix event commit logic

* Because DragonFly needs to do some tests after hard interrupt
  disablement, possibly aborting a VM entry before the VM is actually
  run.  Certain assumptions made by QEMU related to event injection
  might not hold.  Two situations can cause events to be lost.

  (1) QEMU overwrites its own event after assuming the event would be
  injected when it might not be.

  (2) Or nvmm overwrites an event for the same reason.

* To fix this we avoid trying to inject the event unless we are
  absolutely sure that we will issue the VM entry instruction, and we
  force the system call (the ioctl() actually) to restart with ERESTART
  to ensure that QEMU doesn't see the ioctl() return until the event is
  actually injected.

* The tests DragonFly needs to do relate to ASTs and SWIs that might be
  queued via an IPI prior to VM entry.  We absolutely do not want to run
  the VM if any such flags are pending as it might cause other unrelated
  interactive processes to stall out for too long a period of time, or
  allow a signal delivery to the QEMU process to race the VM entry.

Summary of changes:
 sys/dev/virtual/nvmm/x86/nvmm_x86_svm.c | 28 ++--
 sys/dev/virtual/nvmm/x86/nvmm_x86_vmx.c | 28 ++--
 2 files changed, 52 insertions(+), 4 deletions(-)

http://gitweb.dragonflybsd.org/dragonfly.git/commitdiff/dd353e3086ebbad842607aab7b78ac7f759aa284


-- 
DragonFly BSD source repository


git: test/nvmm/demo: Port 'toyvirt' to DragonFly

2021-07-20 Thread Aaron LI


commit 4dec84dc19a010d960b486be34a751bbd705187f
Author: Aaron LI 
Date:   Tue Jun 8 09:34:31 2021 +0800

test/nvmm/demo: Port 'toyvirt' to DragonFly

Just some minor subsitutions.

Use 'ifdef's to make it work on both NetBSD and DragonFly.

Summary of changes:
 test/nvmm/demo/toyvirt/elf.c  | 8 +++-
 test/nvmm/demo/toyvirt/main.c | 6 ++
 2 files changed, 13 insertions(+), 1 deletion(-)

http://gitweb.dragonflybsd.org/dragonfly.git/commitdiff/4dec84dc19a010d960b486be34a751bbd705187f


-- 
DragonFly BSD source repository


git: nvmm: Fix comm page unmapping issue by doing it on userland side

2021-07-20 Thread Aaron LI


commit cca384e4794b145c2db2c13903239d9c019de498
Author: Aaron LI 
Date:   Tue Jul 20 19:47:38 2021 +0800

nvmm: Fix comm page unmapping issue by doing it on userland side

Previously, we're mapping and unmapping the comm page for userland
process both on the kernel side.  The unmapping was called at the point
of closing the fd.

However, the kernel may destroy process' vmspace before or after closing
the fd, so there is no guarantee that kernel can get the correct address
space to unmap the comm page for the userland process.  Therefore, do
the comm page unmapping on the userland side in libnvmm to fix the above
issue.

In addition, add the 'comm_size' member to 'struct nvmm_capability' to
expose the comm page size to userland, which is required for the
unmapping operation.  This breaks ABI, so bump NVMM_KERN_VERSION.
Update nvmmctl(8) accordingly to print the comm page size.

This commit partially reverts:
"nvmm: Add missing comm page unmapping"

Summary of changes:
 lib/libnvmm/libnvmm.3|  3 ++-
 lib/libnvmm/libnvmm.c|  9 +
 sys/dev/virtual/nvmm/nvmm.c  | 14 +++---
 sys/dev/virtual/nvmm/nvmm.h  |  3 ++-
 sys/dev/virtual/nvmm/nvmm_internal.h |  1 -
 usr.sbin/nvmmctl/nvmmctl.c   |  1 +
 6 files changed, 21 insertions(+), 10 deletions(-)

http://gitweb.dragonflybsd.org/dragonfly.git/commitdiff/cca384e4794b145c2db2c13903239d9c019de498


-- 
DragonFly BSD source repository


git: syslogd(8): Fix klog may be broken into multiple incomplete lines

2021-07-20 Thread Aaron LI


commit ae46c1640fd9f8c4ae021ca4d591411738a7cb31
Author: Aaron LI 
Date:   Tue Jul 20 07:33:33 2021 +0800

syslogd(8): Fix klog may be broken into multiple incomplete lines

Fix readklog() to not emit partial lines by changing it to use a static
buffer for reading log lines from /dev/klog.  Thus we can make it
only emit the line for printing if there is a complete line.

This fixes the issue that a kernel log line may be broken into multiple
incomplete lines that are written into log file by syslogd(8),
especially when the system is under load.

Patch-by: Matt Dillon

Summary of changes:
 usr.sbin/syslogd/syslogd.c | 12 +++-
 1 file changed, 7 insertions(+), 5 deletions(-)

http://gitweb.dragonflybsd.org/dragonfly.git/commitdiff/ae46c1640fd9f8c4ae021ca4d591411738a7cb31


-- 
DragonFly BSD source repository


git: test/nvmm/demo: Port 'smallkern' to DragonFly

2021-07-20 Thread Aaron LI


commit 20b815aaa70f0fb8a4c815b9686a6de1feb2fa58
Author: Aaron LI 
Date:   Tue Jun 8 14:29:40 2021 +0800

test/nvmm/demo: Port 'smallkern' to DragonFly

Summary of changes:
 test/nvmm/demo/smallkern/locore.S|  1 +
 test/nvmm/demo/smallkern/main.c  | 18 +-
 test/nvmm/demo/smallkern/pdir.h  |  9 +
 test/nvmm/demo/smallkern/smallkern.h | 13 +
 test/nvmm/demo/smallkern/trap.S  |  1 +
 5 files changed, 41 insertions(+), 1 deletion(-)

http://gitweb.dragonflybsd.org/dragonfly.git/commitdiff/20b815aaa70f0fb8a4c815b9686a6de1feb2fa58


-- 
DragonFly BSD source repository


git: nvmm: Rewrite vmx_vmx{on,off}() as inline ASM functions

2021-07-20 Thread Aaron LI


commit 7c2420fbd4f1cdecbd0335c4f7b10d4e16a34845
Author: Aaron LI 
Date:   Sat Jul 3 16:11:46 2021 +0800

nvmm: Rewrite vmx_vmx{on,off}() as inline ASM functions

Summary of changes:
 sys/dev/virtual/nvmm/x86/nvmm_x86_vmx.c | 37 -
 sys/dev/virtual/nvmm/x86/nvmm_x86_vmxfunc.S | 28 --
 2 files changed, 26 insertions(+), 39 deletions(-)

http://gitweb.dragonflybsd.org/dragonfly.git/commitdiff/7c2420fbd4f1cdecbd0335c4f7b10d4e16a34845


-- 
DragonFly BSD source repository


git: libnvmm: Misc cleanups

2021-07-20 Thread Aaron LI


commit b8ee5f9f1cc7c7ef92583156c3eabeef8688c846
Author: Aaron LI 
Date:   Sun Jul 4 09:27:40 2021 +0800

libnvmm: Misc cleanups

* Remove unused arguments.
* Use literal numbers instead of __BITS().
* Improve two printf()s.
* Remove NetBSD VCS markers and update copyright.

Summary of changes:
 lib/libnvmm/libnvmm.c |  9 +++--
 lib/libnvmm/libnvmm_x86.c | 27 +++
 lib/libnvmm/nvmm.h|  4 +---
 3 files changed, 15 insertions(+), 25 deletions(-)

http://gitweb.dragonflybsd.org/dragonfly.git/commitdiff/b8ee5f9f1cc7c7ef92583156c3eabeef8688c846


-- 
DragonFly BSD source repository


git: nvmm: Fix SVM TSS restore on DragonFly

2021-07-20 Thread Aaron LI


commit aeee078a87aa2ccde9b4ee5c7a9c827eb2b925b1
Author: Aaron LI 
Date:   Tue Jun 15 07:26:03 2021 +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

Summary of changes:
 sys/dev/virtual/nvmm/x86/nvmm_x86_svmfunc.S | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

http://gitweb.dragonflybsd.org/dragonfly.git/commitdiff/aeee078a87aa2ccde9b4ee5c7a9c827eb2b925b1


-- 
DragonFly BSD source repository


git: test/nvmm/demo: Improve progress logs to help test/debug

2021-07-20 Thread Aaron LI


commit ce659a16aa0c5865699bf06e3aa5619646e41b9c
Author: Aaron LI 
Date:   Mon Jun 7 21:40:58 2021 +0800

test/nvmm/demo: Improve progress logs to help test/debug

* Add several more progress logs.
* Reduce accepting trap count to 6, reducing the total test time.
* Update the example output in README.

Summary of changes:
 test/nvmm/demo/README.txt   | 84 -
 test/nvmm/demo/smallkern/main.c |  3 +-
 test/nvmm/demo/toyvirt/main.c   |  4 ++
 3 files changed, 47 insertions(+), 44 deletions(-)

http://gitweb.dragonflybsd.org/dragonfly.git/commitdiff/ce659a16aa0c5865699bf06e3aa5619646e41b9c


-- 
DragonFly BSD source repository


git: nvmm: Adjust EPT/NPT transform code for NetBSD

2021-07-20 Thread Aaron LI


commit 3f1b1a2b1ab407afd22c9efb41fd2ce2d7852575
Author: Aaron LI 
Date:   Sun Jul 11 22:47:23 2021 +0800

nvmm: Adjust EPT/NPT transform code for NetBSD

* Rename variable 'pmap_ept_has_ad' to 'vmx_ept_has_ad' to avoid
  conflict with the global variable in NetBSD.
* Set 'pmap_ept_has_ad' global for NetBSD in vmx_ident().
* Add macro os_vmspace_pmap() to 'nvmm_os.h'.
* Add ifdef's in vmx_machine_create() and svm_machine_create() to
  properly handle EPT/NPT pmap transform on both DragonFly and NetBSD.

Summary of changes:
 sys/dev/virtual/nvmm/nvmm_os.h  |  3 +++
 sys/dev/virtual/nvmm/x86/nvmm_x86_svm.c | 11 +--
 sys/dev/virtual/nvmm/x86/nvmm_x86_vmx.c | 24 +---
 3 files changed, 21 insertions(+), 17 deletions(-)

http://gitweb.dragonflybsd.org/dragonfly.git/commitdiff/3f1b1a2b1ab407afd22c9efb41fd2ce2d7852575


-- 
DragonFly BSD source repository


git: nvmm: Redefine CPUID values to be OS-indenpendent

2021-07-20 Thread Aaron LI


commit c1d369d51a3634213470b453736fbea38700a838
Author: Aaron LI 
Date:   Sat Jul 3 15:14:23 2021 +0800

nvmm: Redefine CPUID values to be OS-indenpendent

Redefine all CPUID values locally to be OS-indenpendent.

Remove those compat CPUID defines from nvmm_compat.h, no longer needed.

Summary of changes:
 sys/dev/virtual/nvmm/nvmm_compat.h  | 116 -
 sys/dev/virtual/nvmm/x86/nvmm_x86.c | 409 +---
 sys/dev/virtual/nvmm/x86/nvmm_x86.h | 294 +++
 sys/dev/virtual/nvmm/x86/nvmm_x86_svm.c |  35 +--
 sys/dev/virtual/nvmm/x86/nvmm_x86_vmx.c |  51 ++--
 5 files changed, 553 insertions(+), 352 deletions(-)

http://gitweb.dragonflybsd.org/dragonfly.git/commitdiff/c1d369d51a3634213470b453736fbea38700a838


-- 
DragonFly BSD source repository


git: nvmm: Add missing comm page unmapping

2021-07-20 Thread Aaron LI


commit 1759ebc3e19ae5ff5bfc6cfa50e1e532a51051b0
Author: Aaron LI 
Date:   Mon Jul 12 22:36:54 2021 +0800

nvmm: Add missing comm page unmapping

The comm page mapping has been changed from libnvmm to the kernel side,
so I removed the munmap() code from libnvmm, but the kernel wasn't doing
the unmapping.  Now add the missing unmapping operation.

Summary of changes:
 sys/dev/virtual/nvmm/nvmm.c  | 11 +--
 sys/dev/virtual/nvmm/nvmm_internal.h |  1 +
 2 files changed, 10 insertions(+), 2 deletions(-)

http://gitweb.dragonflybsd.org/dragonfly.git/commitdiff/1759ebc3e19ae5ff5bfc6cfa50e1e532a51051b0


-- 
DragonFly BSD source repository


git: test/nvmm/demo: Various cleanups to 'smallkern'

2021-07-20 Thread Aaron LI


commit aaa1e810e6b6a6e4cab5a739def087631750de17
Author: Aaron LI 
Date:   Tue Jun 8 12:47:45 2021 +0800

test/nvmm/demo: Various cleanups to 'smallkern'

* Remove unused variables, symbols, function prototypes and functions.
* Move function prototypes and 'extern' declarations to header files.
* Add 'static' qualifier for file-local variables.
* Add inclusion guard to header files.
* Various minor adjustments.

Summary of changes:
 test/nvmm/demo/smallkern/Makefile|  2 +-
 test/nvmm/demo/smallkern/console.c   |  2 --
 test/nvmm/demo/smallkern/locore.S| 19 ++-
 test/nvmm/demo/smallkern/main.c  | 31 +---
 test/nvmm/demo/smallkern/pdir.h  | 18 +-
 test/nvmm/demo/smallkern/smallkern.h | 47 +---
 6 files changed, 54 insertions(+), 65 deletions(-)

http://gitweb.dragonflybsd.org/dragonfly.git/commitdiff/aaa1e810e6b6a6e4cab5a739def087631750de17


-- 
DragonFly BSD source repository


git: nvmm: Clarify the RESET state

2021-07-20 Thread Aaron LI


commit 38c91b8cbcb24b0cbe8b7eb2a14c50eb66e0126c
Author: Aaron LI 
Date:   Sat Jul 3 10:03:40 2021 +0800

nvmm: Clarify the RESET state

Just use plain values instead of macros.

This also eliminates the PAT* compat code in 'nvmm_compat.h'.

Summary of changes:
 sys/dev/virtual/nvmm/nvmm_compat.h  | 12 
 sys/dev/virtual/nvmm/x86/nvmm_x86.c | 11 +++
 2 files changed, 3 insertions(+), 20 deletions(-)

http://gitweb.dragonflybsd.org/dragonfly.git/commitdiff/38c91b8cbcb24b0cbe8b7eb2a14c50eb66e0126c


-- 
DragonFly BSD source repository


git: nvmm: Port to DragonFly #21: virtual address space management

2021-07-20 Thread Aaron LI


commit fe7b14d632ffc4e8b0a257d206a1b547ae6c8604
Author: Aaron LI 
Date:   Sun May 23 18:13:54 2021 +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

Summary of changes:
 sys/dev/virtual/nvmm/nvmm_compat.h | 145 +
 1 file changed, 145 insertions(+)

http://gitweb.dragonflybsd.org/dragonfly.git/commitdiff/fe7b14d632ffc4e8b0a257d206a1b547ae6c8604


-- 
DragonFly BSD source repository


git: test/nvmm/demo: Fix ELF load/mmap issue on DragonFly

2021-07-20 Thread Aaron LI


commit f2252fff15e614477b9361f1e13c890db0c28e9d
Author: Aaron LI 
Date:   Sun Jun 6 12:02:25 2021 +0800

test/nvmm/demo: Fix ELF load/mmap issue on DragonFly

The 'smallkern' ELF built on DragonFly has a zero-sized GNU_STACK
segment, which causes mmap() to fail (EINVAL).  Add conditionals
in elf_parse() to ignore such a segment (while also check for
unsupported non-LOAD segments).

Now 'toyvirt' correctly loads the 'smallkern' ELF on DragonFly.

In addition, assert in toyvirt_mem_add() that the size must be
greater than zero.

Summary of changes:
 test/nvmm/demo/toyvirt/elf.c  | 10 ++
 test/nvmm/demo/toyvirt/main.c |  6 --
 2 files changed, 14 insertions(+), 2 deletions(-)

http://gitweb.dragonflybsd.org/dragonfly.git/commitdiff/f2252fff15e614477b9361f1e13c890db0c28e9d


-- 
DragonFly BSD source repository


git: Bump __DragonFly_version for adding nvmm(4) and libnvmm(3)

2021-07-20 Thread Aaron LI


commit ec74c40d03d61b3d9c30f623b20adf201450be60
Author: Aaron LI 
Date:   Sun Jun 13 22:34:25 2021 +0800

Bump __DragonFly_version for adding nvmm(4) and libnvmm(3)

Summary of changes:
 sys/sys/param.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

http://gitweb.dragonflybsd.org/dragonfly.git/commitdiff/ec74c40d03d61b3d9c30f623b20adf201450be60


-- 
DragonFly BSD source repository


git: nvmm - Use a critical section around the vmrun again

2021-07-20 Thread Aaron LI


commit 665a79c84141f1c0d18b69b7cf1c016190578177
Author: Matthew Dillon 
Date:   Thu Jul 15 14:00:09 2021 -0700

nvmm - Use a critical section around the vmrun again

* In DragonFly, a thread in kernel mode will not be preemptively migrated
  to another CPU or preemptively switched to another normal kernel thread,
  but can be preemptively switched to an interrupt thread (which switches
  back to the kernel thread it preempted the instant it is done or blocks).

  However, we still need to use a critical section to prevent this nominal
  interrupt thread preemption to avoid exposing interrupt threads to
  guest DB and FP register state.  We operate under the assumption that
  the hard interrupt code won't mess with this state.

Summary of changes:
 sys/dev/virtual/nvmm/nvmm_os.h | 21 -
 1 file changed, 12 insertions(+), 9 deletions(-)

http://gitweb.dragonflybsd.org/dragonfly.git/commitdiff/665a79c84141f1c0d18b69b7cf1c016190578177


-- 
DragonFly BSD source repository


git: nvmmctl(8): Misc cleanups

2021-07-20 Thread Aaron LI


commit 7a5114379c43f0e1c78cd19e39bac8e7c29f3480
Author: Aaron LI 
Date:   Sun Jul 4 09:32:23 2021 +0800

nvmmctl(8): Misc cleanups

Summary of changes:
 usr.sbin/nvmmctl/nvmmctl.8 | 3 +--
 usr.sbin/nvmmctl/nvmmctl.c | 6 +-
 2 files changed, 2 insertions(+), 7 deletions(-)

http://gitweb.dragonflybsd.org/dragonfly.git/commitdiff/7a5114379c43f0e1c78cd19e39bac8e7c29f3480


-- 
DragonFly BSD source repository


git: libnvmm: Clarify x86 MOVS emulation

2021-07-20 Thread Aaron LI


commit 9cc8047ece163aa4fe643caf3600b2a538bc838d
Author: Aaron LI 
Date:   Sat Jul 3 08:29:53 2021 +0800

libnvmm: Clarify x86 MOVS emulation

Summary of changes:
 lib/libnvmm/libnvmm_x86.c | 46 +-
 1 file changed, 17 insertions(+), 29 deletions(-)

http://gitweb.dragonflybsd.org/dragonfly.git/commitdiff/9cc8047ece163aa4fe643caf3600b2a538bc838d


-- 
DragonFly BSD source repository


git: kernel - Make kprintf / kputchar more robust

2021-07-20 Thread Aaron LI


commit d9126105909034b7d4010f933837c7db307c8ebf
Author: Matthew Dillon 
Date:   Thu Jul 15 14:02:21 2021 -0700

kernel - Make kprintf / kputchar more robust

* kprintf() via kputchar() can deadlock due to kprintf()s made from
  Xinvltlb (which ignores critical sections).  However, we still want
  to be able to dump diagnostic information from Xinvltlb!

* Adjust sccnputc() to use a non-blocking syscons lock.

* Adjust kputchar() to not issue a wakeup() on the console support
  thread if called with mycpu->gd_intr_nesting_level != 0.  To
  compensate, the support thread now checks at a minimum rate of
  once per second.

* Adjust kvcprintf() to always spin_trylock(), which means that
  lines will be lost if multiple cpu's compete for the console
  (but all lines will still wind up in the dmesg buffer).  This
  needs to be done to allow kprintf()s from Xinvltlb (which ignore
  critical sections) to not deadlock the machine.

Summary of changes:
 sys/dev/misc/syscons/syscons.c |  3 ++-
 sys/kern/subr_prf.c| 42 --
 2 files changed, 22 insertions(+), 23 deletions(-)

http://gitweb.dragonflybsd.org/dragonfly.git/commitdiff/d9126105909034b7d4010f933837c7db307c8ebf


-- 
DragonFly BSD source repository


git: testcases/libnvmm: Port to DragonFly

2021-07-20 Thread Aaron LI


commit 80c9a0accdd00a4a3e5aca2096e4021e8bf7e521
Author: Aaron LI 
Date:   Wed Jun 16 22:33:53 2021 +0800

testcases/libnvmm: Port to DragonFly

Minor tweaks similar to the porting of libnvmm(3).

Summary of changes:
 test/testcases/libnvmm/h_io_assist.c  | 20 ++--
 test/testcases/libnvmm/h_mem_assist.c | 19 +--
 2 files changed, 35 insertions(+), 4 deletions(-)

http://gitweb.dragonflybsd.org/dragonfly.git/commitdiff/80c9a0accdd00a4a3e5aca2096e4021e8bf7e521


-- 
DragonFly BSD source repository


git: nvmm: Implement os_ipi_broadcast() for _change_cpu()

2021-07-20 Thread Aaron LI


commit 5d445d4ccd1cd9a6c8af2fed063bdb0b30bbff86
Author: Aaron LI 
Date:   Sun Jul 11 14:05:26 2021 +0800

nvmm: Implement os_ipi_broadcast() for _change_cpu()

os_ipi_broadcast() is used in {svm,vmx}_init() and {svm,vmx}_fini() to
enable/disable SVM/VMX on all CPUs.  The previous implementation used an
interlock and made significant changes to the code.  Reimplement it in
another way (loop on each CPU and execute the task), so it can be easily
enclosed in the os_ipi_broadcast() function.

The new implementation referred to our pc64/vmm/vmx.c code.

Summary of changes:
 sys/dev/virtual/nvmm/nvmm_os.h  | 12 +++-
 sys/dev/virtual/nvmm/x86/nvmm_x86_svm.c | 29 -
 sys/dev/virtual/nvmm/x86/nvmm_x86_vmx.c | 28 
 3 files changed, 11 insertions(+), 58 deletions(-)

http://gitweb.dragonflybsd.org/dragonfly.git/commitdiff/5d445d4ccd1cd9a6c8af2fed063bdb0b30bbff86


-- 
DragonFly BSD source repository


git: nvmm: Create comm page in nvmm_vcpu_create() rather than via mmap()

2021-07-20 Thread Aaron LI


commit 9aa070ef83dc4a7f702fac98a66ea80e7f4fefb8
Author: Aaron LI 
Date:   Sat Jul 3 22:59:38 2021 +0800

nvmm: Create comm page in nvmm_vcpu_create() rather than via mmap()

Create the VCPU comm page in nvmm_vcpu_create() in kernel, rather than
via mmap() in userland.  With this change, the 'mmap' operation support
is no longer needed by the '/dev/nvmm' device.

This change breaks ABI, so bump NVMM_KERN_VERSION accordingly.

No API change.

Summary of changes:
 lib/libnvmm/libnvmm.c | 16 +++-
 sys/dev/virtual/nvmm/nvmm.c   | 54 ++-
 sys/dev/virtual/nvmm/nvmm.h   | 17 ++--
 sys/dev/virtual/nvmm/nvmm_ioctl.h |  3 ++-
 4 files changed, 21 insertions(+), 69 deletions(-)

http://gitweb.dragonflybsd.org/dragonfly.git/commitdiff/9aa070ef83dc4a7f702fac98a66ea80e7f4fefb8


-- 
DragonFly BSD source repository


git: Add group 'nvmm' and GID_NVMM for nvmm(4) & nvmmctl(8)

2021-07-20 Thread Aaron LI


commit 76b1f6231f5abc8d0793b5318f51b7619cf52f77
Author: Aaron LI 
Date:   Mon May 10 07:06:54 2021 +0800

Add group 'nvmm' and GID_NVMM for nvmm(4) & nvmmctl(8)

Summary of changes:
 etc/group  | 1 +
 sys/sys/conf.h | 1 +
 2 files changed, 2 insertions(+)

http://gitweb.dragonflybsd.org/dragonfly.git/commitdiff/76b1f6231f5abc8d0793b5318f51b7619cf52f77


-- 
DragonFly BSD source repository


git: nvmm: Improve CPUID emulation #2: mask upper bits of guest EAX/ECX

2021-07-20 Thread Aaron LI


commit 1cc8c8a2fcca3f7d8724ad0bf495c5a54f6ca553
Author: Aaron LI 
Date:   Sat Jul 3 12:04:35 2021 +0800

nvmm: Improve CPUID emulation #2: mask upper bits of guest EAX/ECX

Use uint32_t instead of uint64_t for guest EAX/ECX and mask the upper
bits, to prevent wrong results if the upper bits happen to contain
garbage.  Not encountered in the wild so far, but could happen.

Summary of changes:
 sys/dev/virtual/nvmm/x86/nvmm_x86_svm.c | 10 +-
 sys/dev/virtual/nvmm/x86/nvmm_x86_vmx.c | 10 +-
 2 files changed, 10 insertions(+), 10 deletions(-)

http://gitweb.dragonflybsd.org/dragonfly.git/commitdiff/1cc8c8a2fcca3f7d8724ad0bf495c5a54f6ca553


-- 
DragonFly BSD source repository


git: nvmm: Port to DragonFly #0: initial nvmm_compat.h

2021-07-20 Thread Aaron LI


commit 550f54fb7c030e3f0cd1f7ae29c3c63851cb74e2
Author: Aaron LI 
Date:   Tue May 25 14:39:10 2021 +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

Summary of changes:
 sys/dev/virtual/nvmm/nvmm_compat.h | 145 +
 1 file changed, 145 insertions(+)
 create mode 100644 sys/dev/virtual/nvmm/nvmm_compat.h

http://gitweb.dragonflybsd.org/dragonfly.git/commitdiff/550f54fb7c030e3f0cd1f7ae29c3c63851cb74e2


-- 
DragonFly BSD source repository


git: doc: Import nvmm TODO note from NetBSD-current

2021-07-20 Thread Aaron LI


commit cf6ae6e9a0e837c15e56bfe3e9658f9cf393c719
Author: Aaron LI 
Date:   Tue Jun 29 22:33:06 2021 +0800

doc: Import nvmm TODO note from NetBSD-current

Summary of changes:
 doc/TODO.nvmm | 22 ++
 1 file changed, 22 insertions(+)
 create mode 100644 doc/TODO.nvmm

http://gitweb.dragonflybsd.org/dragonfly.git/commitdiff/cf6ae6e9a0e837c15e56bfe3e9658f9cf393c719


-- 
DragonFly BSD source repository


git: nvmm: Rename a few things for clarity

2021-07-20 Thread Aaron LI


commit 412bdc0a01f3ae8c168f8cceaeac667d46d0c49e
Author: Aaron LI 
Date:   Sat Jul 3 18:03:29 2021 +0800

nvmm: Rename a few things for clarity

Summary of changes:
 sys/dev/virtual/nvmm/nvmm.c | 64 -
 sys/dev/virtual/nvmm/nvmm_internal.h|  4 +--
 sys/dev/virtual/nvmm/x86/nvmm_x86_svm.c |  4 +--
 sys/dev/virtual/nvmm/x86/nvmm_x86_vmx.c |  4 +--
 4 files changed, 36 insertions(+), 40 deletions(-)

http://gitweb.dragonflybsd.org/dragonfly.git/commitdiff/412bdc0a01f3ae8c168f8cceaeac667d46d0c49e


-- 
DragonFly BSD source repository


git: nvmm: Various misc cleanups and minor updates

2021-07-20 Thread Aaron LI


commit bfc69df088bd6ffec4826015a02e8b5a96b32344
Author: Aaron LI 
Date:   Sun Jul 4 08:56:02 2021 +0800

nvmm: Various misc cleanups and minor updates

* Rework header inclusions.
* Improve the arguments given to uvmspace_alloc().
* Lowercase "NVMM" in printf() logs.
* Reorganize a few macros in 'nvmm_x86.h' for clarity.
* Remove NetBSD VCS markers and update copyright.

Summary of changes:
 share/man/man4/nvmm.4   | 30 +++---
 sys/dev/virtual/nvmm/nvmm.c | 14 +++
 sys/dev/virtual/nvmm/nvmm.h |  4 +-
 sys/dev/virtual/nvmm/nvmm_compat.h  |  1 -
 sys/dev/virtual/nvmm/nvmm_internal.h|  4 +-
 sys/dev/virtual/nvmm/nvmm_ioctl.h   |  4 +-
 sys/dev/virtual/nvmm/x86/nvmm_x86.c | 12 +++---
 sys/dev/virtual/nvmm/x86/nvmm_x86.h | 13 +++---
 sys/dev/virtual/nvmm/x86/nvmm_x86_svm.c | 28 ++---
 sys/dev/virtual/nvmm/x86/nvmm_x86_svmfunc.S |  6 +--
 sys/dev/virtual/nvmm/x86/nvmm_x86_vmx.c | 62 ++---
 sys/dev/virtual/nvmm/x86/nvmm_x86_vmxfunc.S |  6 +--
 12 files changed, 80 insertions(+), 104 deletions(-)

http://gitweb.dragonflybsd.org/dragonfly.git/commitdiff/bfc69df088bd6ffec4826015a02e8b5a96b32344


-- 
DragonFly BSD source repository


git: nvmm: Fix VMX VMCS remote clear issues

2021-07-20 Thread Aaron LI


commit 05e20678271a04b00c9dcbd7fd66be613f14
Author: Aaron LI 
Date:   Sun Jun 13 14:16:59 2021 +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.

Summary of changes:
 sys/dev/virtual/nvmm/x86/nvmm_x86_vmx.c | 11 ---
 1 file changed, 8 insertions(+), 3 deletions(-)

http://gitweb.dragonflybsd.org/dragonfly.git/commitdiff/05e20678271a04b00c9dcbd7fd66be613f14


-- 
DragonFly BSD source repository


git: nvmm: Port to DragonFly #1: nvmm_x86_{svmfunc,vmxfunc}.S

2021-07-20 Thread Aaron LI


commit 1c2d6221242490208fa2b4ff59ab9615a063bd2a
Author: Aaron LI 
Date:   Tue May 11 14:25:17 2021 +0800

nvmm: Port to DragonFly #1: nvmm_x86_{svmfunc,vmxfunc}.S

Summary of changes:
 sys/dev/virtual/nvmm/x86/nvmm_x86_svmfunc.S | 16 +---
 sys/dev/virtual/nvmm/x86/nvmm_x86_vmxfunc.S | 15 +--
 2 files changed, 10 insertions(+), 21 deletions(-)

http://gitweb.dragonflybsd.org/dragonfly.git/commitdiff/1c2d6221242490208fa2b4ff59ab9615a063bd2a


-- 
DragonFly BSD source repository


  1   2   3   4   5   6   7   >