Module Name:    src
Committed By:   maxv
Date:           Sun Oct 27 07:08:15 UTC 2019

Modified Files:
        src/etc: MAKEDEV.tmpl group
        src/lib/libnvmm: libnvmm.3 libnvmm.c nvmm.h
        src/tests/lib/libnvmm: h_io_assist.c h_mem_assist.c

Log Message:
Add the "nvmm" group, and make nvmm_init() public. Sent to tech-kern@ a few
days ago.


To generate a diff of this commit:
cvs rdiff -u -r1.208 -r1.209 src/etc/MAKEDEV.tmpl
cvs rdiff -u -r1.34 -r1.35 src/etc/group
cvs rdiff -u -r1.20 -r1.21 src/lib/libnvmm/libnvmm.3
cvs rdiff -u -r1.16 -r1.17 src/lib/libnvmm/libnvmm.c
cvs rdiff -u -r1.14 -r1.15 src/lib/libnvmm/nvmm.h
cvs rdiff -u -r1.10 -r1.11 src/tests/lib/libnvmm/h_io_assist.c
cvs rdiff -u -r1.16 -r1.17 src/tests/lib/libnvmm/h_mem_assist.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/etc/MAKEDEV.tmpl
diff -u src/etc/MAKEDEV.tmpl:1.208 src/etc/MAKEDEV.tmpl:1.209
--- src/etc/MAKEDEV.tmpl:1.208	Thu Sep 19 01:44:48 2019
+++ src/etc/MAKEDEV.tmpl	Sun Oct 27 07:08:15 2019
@@ -1,5 +1,5 @@
 #!/bin/sh -
-#	$NetBSD: MAKEDEV.tmpl,v 1.208 2019/09/19 01:44:48 thorpej Exp $
+#	$NetBSD: MAKEDEV.tmpl,v 1.209 2019/10/27 07:08:15 maxv Exp $
 #
 # Copyright (c) 2003,2007,2008 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -500,6 +500,7 @@ setup()
 	g_gpio="%gid__gpio%"
 	g_kmem="%gid_kmem%"
 	g_ntpd="%gid_ntpd%"
+	g_nvmm="%gid_nvmm%"
 	g_operator="%gid_operator%"
 	g_wheel="%gid_wheel%"
 	dialin=0
@@ -2227,7 +2228,7 @@ nvme[0-9]*)
 	;;
 
 nvmm)
-	mkdev nvmm c %nvmm_chr% 0
+	mkdev nvmm c %nvmm_chr% 0 640 $g_nvmm
 	;;
 
 autofs)

Index: src/etc/group
diff -u src/etc/group:1.34 src/etc/group:1.35
--- src/etc/group:1.34	Sat Jan  7 20:00:33 2017
+++ src/etc/group	Sun Oct 27 07:08:15 2019
@@ -29,6 +29,7 @@ _rtadvd:*:30:
 guest:*:31:root
 _unbound:*:32:
 _nsd:*:33:
+nvmm:*:34:root
 nobody:*:39:
 utmp:*:45:
 authpf:*:72:

Index: src/lib/libnvmm/libnvmm.3
diff -u src/lib/libnvmm/libnvmm.3:1.20 src/lib/libnvmm/libnvmm.3:1.21
--- src/lib/libnvmm/libnvmm.3:1.20	Fri Oct 25 09:09:24 2019
+++ src/lib/libnvmm/libnvmm.3	Sun Oct 27 07:08:15 2019
@@ -1,4 +1,4 @@
-.\"	$NetBSD: libnvmm.3,v 1.20 2019/10/25 09:09:24 maxv Exp $
+.\"	$NetBSD: libnvmm.3,v 1.21 2019/10/27 07:08:15 maxv Exp $
 .\"
 .\" Copyright (c) 2018, 2019 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -38,6 +38,8 @@
 .Sh SYNOPSIS
 .In nvmm.h
 .Ft int
+.Fn nvmm_init "void"
+.Ft int
 .Fn nvmm_capability "struct nvmm_capability *cap"
 .Ft int
 .Fn nvmm_machine_create "struct nvmm_machine *mach"
@@ -98,6 +100,12 @@ to manage virtual machines.
 A virtual CPU is described by a public structure,
 .Cd nvmm_vcpu .
 .Pp
+.Fn nvmm_init
+initializes NVMM.
+See
+.Sx NVMM Initialization
+below for details.
+.Pp
 .Fn nvmm_capability
 gets the capabilities of NVMM.
 See
@@ -277,6 +285,23 @@ from machine
 See
 .Sx Mem Assist
 below for details.
+.Ss NVMM Initialization
+NVMM initialization is performed by the
+.Fn nvmm_init
+function, which must be invoked by emulator software before any other NVMM
+function.
+.Pp
+.Fn nvmm_init
+opens the NVMM device, and expects to have the proper permissions to do so.
+In a default configuration, this implies being part of the "nvmm" group.
+If using a special configuration, emulator software should arrange to have the
+proper permissions before invoking
+.Fn nvmm_init ,
+and can drop them after the call has completed.
+.Pp
+It is to be noted that
+.Fn nvmm_init
+may perform non-re-entrant operations, and should be called only once.
 .Ss NVMM Capability
 The
 .Cd nvmm_capability

Index: src/lib/libnvmm/libnvmm.c
diff -u src/lib/libnvmm/libnvmm.c:1.16 src/lib/libnvmm/libnvmm.c:1.17
--- src/lib/libnvmm/libnvmm.c:1.16	Wed Oct 23 12:02:55 2019
+++ src/lib/libnvmm/libnvmm.c	Sun Oct 27 07:08:15 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: libnvmm.c,v 1.16 2019/10/23 12:02:55 maxv Exp $	*/
+/*	$NetBSD: libnvmm.c,v 1.17 2019/10/27 07:08:15 maxv Exp $	*/
 
 /*
  * Copyright (c) 2018-2019 The NetBSD Foundation, Inc.
@@ -156,7 +156,7 @@ __area_remove_all(struct nvmm_machine *m
 
 /* -------------------------------------------------------------------------- */
 
-static int
+int
 nvmm_init(void)
 {
 	if (nvmm_fd != -1)
@@ -185,10 +185,6 @@ nvmm_capability(struct nvmm_capability *
 	struct nvmm_ioc_capability args;
 	int ret;
 
-	if (nvmm_init() == -1) {
-		return -1;
-	}
-
 	ret = ioctl(nvmm_fd, NVMM_IOC_CAPABILITY, &args);
 	if (ret == -1)
 		return -1;
@@ -206,10 +202,6 @@ nvmm_machine_create(struct nvmm_machine 
 	area_list_t *areas;
 	int ret;
 
-	if (nvmm_init() == -1) {
-		return -1;
-	}
-
 	areas = calloc(1, sizeof(*areas));
 	if (areas == NULL)
 		return -1;
@@ -537,10 +529,6 @@ nvmm_ctl(int op, void *data, size_t size
 	struct nvmm_ioc_ctl args;
 	int ret;
 
-	if (nvmm_init() == -1) {
-		return -1;
-	}
-
 	args.op = op;
 	args.data = data;
 	args.size = size;

Index: src/lib/libnvmm/nvmm.h
diff -u src/lib/libnvmm/nvmm.h:1.14 src/lib/libnvmm/nvmm.h:1.15
--- src/lib/libnvmm/nvmm.h:1.14	Wed Oct 23 12:02:55 2019
+++ src/lib/libnvmm/nvmm.h	Sun Oct 27 07:08:15 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: nvmm.h,v 1.14 2019/10/23 12:02:55 maxv Exp $	*/
+/*	$NetBSD: nvmm.h,v 1.15 2019/10/27 07:08:15 maxv Exp $	*/
 
 /*
  * Copyright (c) 2018-2019 The NetBSD Foundation, Inc.
@@ -89,6 +89,8 @@ struct nvmm_mem {
 #define NVMM_PROT_ALL		0x0F
 typedef uint64_t nvmm_prot_t;
 
+int nvmm_init(void);
+
 int nvmm_capability(struct nvmm_capability *);
 
 int nvmm_machine_create(struct nvmm_machine *);

Index: src/tests/lib/libnvmm/h_io_assist.c
diff -u src/tests/lib/libnvmm/h_io_assist.c:1.10 src/tests/lib/libnvmm/h_io_assist.c:1.11
--- src/tests/lib/libnvmm/h_io_assist.c:1.10	Wed Oct 23 12:02:55 2019
+++ src/tests/lib/libnvmm/h_io_assist.c	Sun Oct 27 07:08:15 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: h_io_assist.c,v 1.10 2019/10/23 12:02:55 maxv Exp $	*/
+/*	$NetBSD: h_io_assist.c,v 1.11 2019/10/27 07:08:15 maxv Exp $	*/
 
 /*
  * Copyright (c) 2018-2019 The NetBSD Foundation, Inc.
@@ -373,6 +373,8 @@ int main(int argc, char *argv[])
 	struct nvmm_vcpu vcpu;
 	size_t i;
 
+	if (nvmm_init() == -1)
+		err(errno, "nvmm_init");
 	if (nvmm_machine_create(&mach) == -1)
 		err(errno, "nvmm_machine_create");
 	if (nvmm_vcpu_create(&mach, 0, &vcpu) == -1)

Index: src/tests/lib/libnvmm/h_mem_assist.c
diff -u src/tests/lib/libnvmm/h_mem_assist.c:1.16 src/tests/lib/libnvmm/h_mem_assist.c:1.17
--- src/tests/lib/libnvmm/h_mem_assist.c:1.16	Wed Oct 23 12:02:55 2019
+++ src/tests/lib/libnvmm/h_mem_assist.c	Sun Oct 27 07:08:15 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: h_mem_assist.c,v 1.16 2019/10/23 12:02:55 maxv Exp $	*/
+/*	$NetBSD: h_mem_assist.c,v 1.17 2019/10/27 07:08:15 maxv Exp $	*/
 
 /*
  * Copyright (c) 2018-2019 The NetBSD Foundation, Inc.
@@ -459,6 +459,8 @@ test_vm16(void)
 
 int main(int argc, char *argv[])
 {
+	if (nvmm_init() == -1)
+		err(errno, "nvmm_init");
 	test_vm64();
 	test_vm16();
 	return 0;

Reply via email to