Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src Add the "nvmm" group, and make nvmm_init() public. Sent to t...
details: https://anonhg.NetBSD.org/src/rev/fd970096ed9a
branches: trunk
changeset: 1004367:fd970096ed9a
user: maxv <maxv%NetBSD.org@localhost>
date: Sun Oct 27 07:08:15 2019 +0000
description:
Add the "nvmm" group, and make nvmm_init() public. Sent to tech-kern@ a few
days ago.
diffstat:
etc/MAKEDEV.tmpl | 5 +++--
etc/group | 1 +
lib/libnvmm/libnvmm.3 | 27 ++++++++++++++++++++++++++-
lib/libnvmm/libnvmm.c | 16 ++--------------
lib/libnvmm/nvmm.h | 4 +++-
tests/lib/libnvmm/h_io_assist.c | 4 +++-
tests/lib/libnvmm/h_mem_assist.c | 4 +++-
7 files changed, 41 insertions(+), 20 deletions(-)
diffs (198 lines):
diff -r 1edc515190eb -r fd970096ed9a etc/MAKEDEV.tmpl
--- a/etc/MAKEDEV.tmpl Sun Oct 27 02:07:42 2019 +0000
+++ b/etc/MAKEDEV.tmpl Sun Oct 27 07:08:15 2019 +0000
@@ -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 @@
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 @@
;;
nvmm)
- mkdev nvmm c %nvmm_chr% 0
+ mkdev nvmm c %nvmm_chr% 0 640 $g_nvmm
;;
autofs)
diff -r 1edc515190eb -r fd970096ed9a etc/group
--- a/etc/group Sun Oct 27 02:07:42 2019 +0000
+++ b/etc/group Sun Oct 27 07:08:15 2019 +0000
@@ -29,6 +29,7 @@
guest:*:31:root
_unbound:*:32:
_nsd:*:33:
+nvmm:*:34:root
nobody:*:39:
utmp:*:45:
authpf:*:72:
diff -r 1edc515190eb -r fd970096ed9a lib/libnvmm/libnvmm.3
--- a/lib/libnvmm/libnvmm.3 Sun Oct 27 02:07:42 2019 +0000
+++ b/lib/libnvmm/libnvmm.3 Sun Oct 27 07:08:15 2019 +0000
@@ -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 @@
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 @@
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
diff -r 1edc515190eb -r fd970096ed9a lib/libnvmm/libnvmm.c
--- a/lib/libnvmm/libnvmm.c Sun Oct 27 02:07:42 2019 +0000
+++ b/lib/libnvmm/libnvmm.c Sun Oct 27 07:08:15 2019 +0000
@@ -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 @@
/* -------------------------------------------------------------------------- */
-static int
+int
nvmm_init(void)
{
if (nvmm_fd != -1)
@@ -185,10 +185,6 @@
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 @@
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 @@
struct nvmm_ioc_ctl args;
int ret;
- if (nvmm_init() == -1) {
- return -1;
- }
-
args.op = op;
args.data = data;
args.size = size;
diff -r 1edc515190eb -r fd970096ed9a lib/libnvmm/nvmm.h
--- a/lib/libnvmm/nvmm.h Sun Oct 27 02:07:42 2019 +0000
+++ b/lib/libnvmm/nvmm.h Sun Oct 27 07:08:15 2019 +0000
@@ -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 @@
#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 *);
diff -r 1edc515190eb -r fd970096ed9a tests/lib/libnvmm/h_io_assist.c
--- a/tests/lib/libnvmm/h_io_assist.c Sun Oct 27 02:07:42 2019 +0000
+++ b/tests/lib/libnvmm/h_io_assist.c Sun Oct 27 07:08:15 2019 +0000
@@ -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 @@
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)
diff -r 1edc515190eb -r fd970096ed9a tests/lib/libnvmm/h_mem_assist.c
--- a/tests/lib/libnvmm/h_mem_assist.c Sun Oct 27 02:07:42 2019 +0000
+++ b/tests/lib/libnvmm/h_mem_assist.c Sun Oct 27 07:08:15 2019 +0000
@@ -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 @@
int main(int argc, char *argv[])
{
+ if (nvmm_init() == -1)
+ err(errno, "nvmm_init");
test_vm64();
test_vm16();
return 0;
Home |
Main Index |
Thread Index |
Old Index