Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src Pass enums over the hypercall interface as ints to avoid some



details:   https://anonhg.NetBSD.org/src/rev/5e18906eb189
branches:  trunk
changeset: 786845:5e18906eb189
user:      pooka <pooka%NetBSD.org@localhost>
date:      Wed May 15 14:52:49 2013 +0000

description:
Pass enums over the hypercall interface as ints to avoid some
pathological scenarios from arising in setups where enums might be
of a different size in the rump kernel and hypervisor.

diffstat:

 lib/librumpuser/rumpuser.3           |  56 +++++++++++++++++++++--------------
 lib/librumpuser/rumpuser.c           |  12 ++++---
 lib/librumpuser/rumpuser_pth.c       |  16 ++++++---
 lib/librumpuser/rumpuser_pth_dummy.c |  21 +++++++++----
 sys/rump/include/rump/rumpuser.h     |  14 ++++----
 sys/rump/librump/rumpkern/locks.c    |  12 +++---
 6 files changed, 78 insertions(+), 53 deletions(-)

diffs (truncated from 467 to 300 lines):

diff -r 66b337e482fc -r 5e18906eb189 lib/librumpuser/rumpuser.3
--- a/lib/librumpuser/rumpuser.3        Wed May 15 14:07:26 2013 +0000
+++ b/lib/librumpuser/rumpuser.3        Wed May 15 14:52:49 2013 +0000
@@ -1,4 +1,4 @@
-.\"     $NetBSD: rumpuser.3,v 1.10 2013/05/15 14:07:26 pooka Exp $
+.\"     $NetBSD: rumpuser.3,v 1.11 2013/05/15 14:52:49 pooka Exp $
 .\"
 .\" Copyright (c) 2013 Antti Kantee.  All rights reserved.
 .\"
@@ -44,6 +44,18 @@
 is for POSIX hosts.
 This document is divided into sections based on the functionality
 group of each hypercall.
+.Pp
+Since the hypercall interface is a C function interface, both the
+rump kernel and the hypervisor must conform to the same ABI.
+The interface itself attempts to assume as little as possible from
+the type systems, and for example
+.Vt off_t
+is passed as
+.Vt int64_t
+and enums are passed as ints.
+It is recommended that the hypervisor converts these to the native
+types before starting to process the hypercall, for example by
+assigning the ints back to enums.
 .Sh UPCALLS AND RUMP KERNEL CONTEXT
 A hypercall is always entered with the calling thread scheduled in
 the rump kernel.
@@ -73,7 +85,7 @@
 .Fn rumpuser_init "int version" "struct rump_hyperup *hyp"
 .Pp
 Initialize the hypervisor.
-.Bl -tag -width "xalignmentx"
+.Bl -tag -width "xenum_rumpclock"
 .It Fa version
 hypercall interface version number that the kernel expects to be used.
 In case the hypervisor cannot provide an exact match, this routine must
@@ -84,7 +96,7 @@
 .Ss Memory allocation
 .Ft int
 .Fn rumpuser_malloc "size_t len" "int alignment" "void **memp"
-.Bl -tag -width "xalignmentx"
+.Bl -tag -width "xenum_rumpclock"
 .It Fa len
 amount of memory to allocate
 .It Fa alignment
@@ -97,7 +109,7 @@
 .Pp
 .Ft void
 .Fn rumpuser_free "void *mem" "size_t len"
-.Bl -tag -width "xalignmentx"
+.Bl -tag -width "xenum_rumpclock"
 .It Fa mem
 memory to free
 .It Fa len
@@ -120,7 +132,7 @@
 For example, it is possible to associate the file descriptor with
 device I/O registers for special values of
 .Fa name .
-.Bl -tag -width "xalignmentx"
+.Bl -tag -width "xenum_rumpclock"
 .It Fa name
 the identifier of the file to open for I/O
 .It Fa mode
@@ -163,7 +175,7 @@
 .Pp
 .Ft int
 .Fn rumpuser_getfileinfo "const char *name" "uint64_t *size" "int *type"
-.Bl -tag -width "xalignmentx"
+.Bl -tag -width "xenum_rumpclock"
 .It Fa name
 file for which information is returned.
 The namespace is equal to that of
@@ -190,7 +202,7 @@
 .Fc
 .Pp
 Initiate block I/O and return immediately.
-.Bl -tag -width "xalignmentx"
+.Bl -tag -width "xenum_rumpclock"
 .It Fa fd
 perform I/O on this file descriptor.
 The file descriptor must have been opened with
@@ -239,7 +251,7 @@
 block I/O by nature and therefore cannot be handled by
 .Fn rumpuser_bio .
 .Pp
-.Bl -tag -width "xalignmentx"
+.Bl -tag -width "xenum_rumpclock"
 .It Fa fd
 file descriptor to perform I/O on
 .It Fa ruiov
@@ -276,10 +288,10 @@
 retain semantics.
 .Pp
 .Ft int
-.Fn rumpuser_clock_gettime "enum rumpclock clk" "int64_t *sec" "long *nsec"
+.Fn rumpuser_clock_gettime "int enum_rumpclock" "int64_t *sec" "long *nsec"
 .Pp
-.Bl -tag -width "xalignmentx"
-.It Fa clk
+.Bl -tag -width "xenum_rumpclock"
+.It Fa enum_rumpclock
 specifies the clock type.
 In case of
 .Dv RUMPUSER_CLOCK_RELWALL
@@ -294,9 +306,9 @@
 .El
 .Pp
 .Ft int
-.Fn rumpuser_clock_sleep "enum rumpclock clk" "int64_t sec" "long nsec"
-.Bl -tag -width "xalignmentx"
-.It Fa clk
+.Fn rumpuser_clock_sleep "int enum_rumpclock" "int64_t sec" "long nsec"
+.Bl -tag -width "xenum_rumpclock"
+.It Fa enum_rumpclock
 In case of
 .Dv RUMPUSER_CLOCK_RELWALL ,
 the sleep should last at least as long as specified.
@@ -319,7 +331,7 @@
 .Pp
 Retrieve a configuration parameter from the hypervisor.
 It is up to the hypervisor to decide how the parameters can be set.
-.Bl -tag -width "xalignmentx"
+.Bl -tag -width "xenum_rumpclock"
 .It Fa name
 name of the parameter.
 If the name starts with an underscore, it means a mandatory parameter.
@@ -371,7 +383,7 @@
 .Ft int
 .Fn rumpuser_getrandom "void *buf" "size_t buflen" "int flags" "size_t *retp"
 .Pp
-.Bl -tag -width "xalignmentx"
+.Bl -tag -width "xenum_rumpclock"
 .It Fa buf
 buffer that the randomness is written to
 .It Fa buflen
@@ -402,7 +414,7 @@
 and
 .Fa cpuidx
 parameters.
-.Bl -tag -width "xalignmentx"
+.Bl -tag -width "xenum_rumpclock"
 .It Fa fun
 function that the new thread must call
 .It Fa arg
@@ -448,11 +460,11 @@
 .Fn rumpuser_thread_create .
 .Pp
 .Ft void
-.Fn rumpuser_curlwpop "enum rumplwpop op" "struct lwp *l"
+.Fn rumpuser_curlwpop "int enum_rumplwpop" "struct lwp *l"
 .Pp
 Manipulate the hypervisor's thread context database.
 The possible operations are create, destroy, and set as specified by
-.Fa op :
+.Fa enum_rumplwpop :
 .Bl -tag -width "XRUMPUSER_LWP_DESTROY"
 .It Dv RUMPUSER_LWP_CREATE
 Inform the hypervisor that
@@ -563,10 +575,10 @@
 .Fn rumpuser_rw_init "struct rumpuser_rw **rwp"
 .Pp
 .Ft void
-.Fn rumpuser_rw_enter "struct rumpuser_rw *rw" "const enum rumprwlock lk"
+.Fn rumpuser_rw_enter "int enum_rumprwlock" "struct rumpuser_rw *rw"
 .Pp
 .Ft int
-.Fn rumpuser_rw_tryenter "struct rumpuser_rw *rw" "const enum rumprwlock lk"
+.Fn rumpuser_rw_tryenter "int enum_rumprwlock" "struct rumpuser_rw *rw"
 .Pp
 .Ft int
 .Fn rumpuser_rw_tryupgrade "struct rumpuser_rw *rw"
@@ -582,7 +594,7 @@
 .Pp
 .Ft void
 .Fo rumpuser_rw_held
-.Fa "struct rumpuser_rw *rw" "const enum rumprwlock lk" "int *heldp"
+.Fa "int enum_rumprwlock" "struct rumpuser_rw *rw" "int *heldp"
 .Fc
 .Pp
 Read/write locks provide either shared or exclusive locking.
diff -r 66b337e482fc -r 5e18906eb189 lib/librumpuser/rumpuser.c
--- a/lib/librumpuser/rumpuser.c        Wed May 15 14:07:26 2013 +0000
+++ b/lib/librumpuser/rumpuser.c        Wed May 15 14:52:49 2013 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: rumpuser.c,v 1.50 2013/05/02 21:45:29 pooka Exp $      */
+/*     $NetBSD: rumpuser.c,v 1.51 2013/05/15 14:52:49 pooka Exp $      */
 
 /*
  * Copyright (c) 2007-2010 Antti Kantee.  All Rights Reserved.
@@ -28,7 +28,7 @@
 #include "rumpuser_port.h"
 
 #if !defined(lint)
-__RCSID("$NetBSD: rumpuser.c,v 1.50 2013/05/02 21:45:29 pooka Exp $");
+__RCSID("$NetBSD: rumpuser.c,v 1.51 2013/05/15 14:52:49 pooka Exp $");
 #endif /* !lint */
 
 #include <sys/ioctl.h>
@@ -395,8 +395,9 @@
 }
 
 int
-rumpuser_clock_gettime(enum rumpclock rclk, int64_t *sec, long *nsec)
+rumpuser_clock_gettime(int enum_rumpclock, int64_t *sec, long *nsec)
 {
+       enum rumpclock rclk = enum_rumpclock;
        struct timespec ts;
        clockid_t clk;
        int rv;
@@ -428,8 +429,9 @@
 }
 
 int
-rumpuser_clock_sleep(enum rumpclock clk, int64_t sec, long nsec)
+rumpuser_clock_sleep(int enum_rumpclock, int64_t sec, long nsec)
 {
+       enum rumpclock rclk = enum_rumpclock;
        struct timespec rqt, rmt;
        int nlocks;
        int rv;
@@ -441,7 +443,7 @@
        /*LINTED*/
        rqt.tv_nsec = nsec;
 
-       switch (clk) {
+       switch (rclk) {
        case RUMPUSER_CLOCK_RELWALL:
                do {
                        rv = nanosleep(&rqt, &rmt);
diff -r 66b337e482fc -r 5e18906eb189 lib/librumpuser/rumpuser_pth.c
--- a/lib/librumpuser/rumpuser_pth.c    Wed May 15 14:07:26 2013 +0000
+++ b/lib/librumpuser/rumpuser_pth.c    Wed May 15 14:52:49 2013 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: rumpuser_pth.c,v 1.29 2013/05/15 14:07:26 pooka Exp $  */
+/*     $NetBSD: rumpuser_pth.c,v 1.30 2013/05/15 14:52:49 pooka Exp $  */
 
 /*
  * Copyright (c) 2007-2010 Antti Kantee.  All Rights Reserved.
@@ -28,7 +28,7 @@
 #include "rumpuser_port.h"
 
 #if !defined(lint)
-__RCSID("$NetBSD: rumpuser_pth.c,v 1.29 2013/05/15 14:07:26 pooka Exp $");
+__RCSID("$NetBSD: rumpuser_pth.c,v 1.30 2013/05/15 14:52:49 pooka Exp $");
 #endif /* !lint */
 
 #include <sys/queue.h>
@@ -321,8 +321,9 @@
 }
 
 void
-rumpuser_rw_enter(struct rumpuser_rw *rw, const enum rumprwlock lk)
+rumpuser_rw_enter(int enum_rumprwlock, struct rumpuser_rw *rw)
 {
+       enum rumprwlock lk = enum_rumprwlock;
 
        switch (lk) {
        case RUMPUSER_RW_WRITER:
@@ -342,8 +343,9 @@
 }
 
 int
-rumpuser_rw_tryenter(struct rumpuser_rw *rw, const enum rumprwlock lk)
+rumpuser_rw_tryenter(int enum_rumprwlock, struct rumpuser_rw *rw)
 {
+       enum rumprwlock lk = enum_rumprwlock;
        int rv;
 
        switch (lk) {
@@ -421,8 +423,9 @@
 }
 
 void
-rumpuser_rw_held(struct rumpuser_rw *rw, const enum rumprwlock lk, int *rv)
+rumpuser_rw_held(int enum_rumprwlock, struct rumpuser_rw *rw, int *rv)
 {
+       enum rumprwlock lk = enum_rumprwlock;
 
        switch (lk) {
        case RUMPUSER_RW_WRITER:
@@ -663,8 +666,9 @@
 #else
 
 void
-rumpuser_curlwpop(enum rumplwpop op, struct lwp *l)
+rumpuser_curlwpop(int enum_rumplwpop, struct lwp *l)
 {
+       enum rumplwpop op = enum_rumplwpop;
 
        switch (op) {
        case RUMPUSER_LWP_CREATE:
diff -r 66b337e482fc -r 5e18906eb189 lib/librumpuser/rumpuser_pth_dummy.c
--- a/lib/librumpuser/rumpuser_pth_dummy.c      Wed May 15 14:07:26 2013 +0000
+++ b/lib/librumpuser/rumpuser_pth_dummy.c      Wed May 15 14:52:49 2013 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: rumpuser_pth_dummy.c,v 1.15 2013/05/07 16:40:31 pooka Exp $    */
+/*     $NetBSD: rumpuser_pth_dummy.c,v 1.16 2013/05/15 14:52:49 pooka Exp $    */
 
 /*



Home | Main Index | Thread Index | Old Index