diff --git a/.gitignore b/.gitignore new file mode 100644 index 000000000..3fdff78bc --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +**/obj +**/tags diff --git a/bin/ksh/sh.1 b/bin/ksh/sh.1 index 864713a62..b73dcf31e 100644 --- a/bin/ksh/sh.1 +++ b/bin/ksh/sh.1 @@ -1,4 +1,4 @@ -.\" $OpenBSD: sh.1,v 1.156 2022/12/19 08:19:50 sdk Exp $ +.\" $OpenBSD: sh.1,v 1.157 2023/05/13 18:34:49 jmc Exp $ .\" .\" Copyright (c) 2015 Jason McIntyre .\" @@ -14,7 +14,7 @@ .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. .\" -.Dd $Mdocdate: December 19 2022 $ +.Dd $Mdocdate: May 13 2023 $ .Dt SH 1 .Os .Sh NAME @@ -2108,7 +2108,7 @@ on .Ox is: .Bd -literal -offset 2n -/usr/bin:/bin:/usr/sbin:/sbin:/usr/X11R6/bin:/usr/local/bin +/usr/bin:/bin:/usr/sbin:/sbin:/usr/X11R6/bin:/usr/local/bin:/usr/local/sbin .Ed .It Ev POSIXLY_CORRECT Enable POSIX mode diff --git a/gnu/gcc/gcc/config/arm/secbsd.h b/gnu/gcc/gcc/config/arm/secbsd.h index b148a64e1..c61dff822 100644 --- a/gnu/gcc/gcc/config/arm/secbsd.h +++ b/gnu/gcc/gcc/config/arm/secbsd.h @@ -1,4 +1,4 @@ -/* Definitions of target machine for GNU compiler, OpenBSD/arm ELF version. +/* Definitions of target machine for GNU compiler, SecBSD/arm ELF version. Copyright (C) 2002 Free Software Foundation, Inc. Contributed by Wasabi Systems, Inc. @@ -21,11 +21,11 @@ Boston, MA 02111-1307, USA. */ /* Run-time Target Specification. */ #undef TARGET_VERSION -#define TARGET_VERSION fputs (" (OpenBSD/arm)", stderr); +#define TARGET_VERSION fputs (" (SecBSD/arm)", stderr); /* This is used in ASM_FILE_START. */ #undef ARM_OS_NAME -#define ARM_OS_NAME "OpenBSD" +#define ARM_OS_NAME "SecBSD" /* Unsigned chars produces much better code than signed. */ #define DEFAULT_SIGNED_CHAR 0 @@ -55,21 +55,21 @@ Boston, MA 02111-1307, USA. */ do \ { \ builtin_define ("__GXX_MERGED_TYPEINFO_NAMES=0"); \ - OPENBSD_OS_CPP_BUILTINS_ELF(); \ + SECBSD_OS_CPP_BUILTINS_ELF(); \ } \ while (0) #undef SUBTARGET_CPP_SPEC -#define SUBTARGET_CPP_SPEC OBSD_CPP_SPEC +#define SUBTARGET_CPP_SPEC SBSD_CPP_SPEC -/* OBSD_LINK_SPEC appropriate for OpenBSD. Support for GCC options +/* SBSD_LINK_SPEC appropriate for SecBSD. Support for GCC options -static, -assert, and -nostdlib. */ -#undef OBSD_LINK_SPEC -#ifdef OBSD_NO_DYNAMIC_LIBRARIES -#define OBSD_LINK_SPEC \ +#undef SBSD_LINK_SPEC +#ifdef SBSD_NO_DYNAMIC_LIBRARIES +#define SBSD_LINK_SPEC \ "%{!nostdlib:%{!r*:%{!e*:-e __start}}} %{assert*}" #else -#define OBSD_LINK_SPEC \ +#define SBSD_LINK_SPEC \ "%{!shared:%{!nostdlib:%{!r*:%{!e*:-e __start}}}} \ %{shared:-shared} %{R*} \ %{static:-Bstatic} \ @@ -97,10 +97,10 @@ Boston, MA 02111-1307, USA. */ #define SUBTARGET_EXTRA_SPECS \ { "subtarget_extra_asm_spec", SUBTARGET_EXTRA_ASM_SPEC }, \ { "subtarget_asm_float_spec", SUBTARGET_ASM_FLOAT_SPEC }, \ - { "openbsd_link_spec", OBSD_LINK_SPEC }, \ - { "openbsd_entry_point", OPENBSD_ENTRY_POINT }, + { "openbsd_link_spec", SBSD_LINK_SPEC }, \ + { "openbsd_entry_point", SECBSD_ENTRY_POINT }, -#define OPENBSD_ENTRY_POINT "__start" +#define SECBSD_ENTRY_POINT "__start" /* Pass -X to the linker so that it will strip symbols starting with 'L' */ #undef LINK_SPEC @@ -131,7 +131,7 @@ Boston, MA 02111-1307, USA. */ /* We don't have any limit on the length as out debugger is GDB. */ #undef DBX_CONTIN_LENGTH -/* OpenBSD and NetBSD do their profiling differently to the Acorn compiler. We +/* SecBSD and NetBSD do their profiling differently to the Acorn compiler. We don't need a word following the mcount call; and to skip it requires either an assembly stub or use of fomit-frame-pointer when compiling the profiling functions. Since we break Acorn CC @@ -153,12 +153,12 @@ Boston, MA 02111-1307, USA. */ #undef FPUTYPE_DEFAULT #define FPUTYPE_DEFAULT FPUTYPE_VFP -/* VERY BIG NOTE: Change of structure alignment for OpenBSD|NetBSD/arm. +/* VERY BIG NOTE: Change of structure alignment for SecBSD|NetBSD/arm. There are consequences you should be aware of... Normally GCC/arm uses a structure alignment of 32 for compatibility with armcc. This means that structures are padded to a word - boundary. However this causes problems with bugged OpenBSD|NetBSD kernel + boundary. However this causes problems with bugged SecBSD|NetBSD kernel code (possibly userland code as well - I have not checked every binary). The nature of this bugged code is to rely on sizeof() returning the correct size of various structures rounded to the @@ -166,7 +166,7 @@ Boston, MA 02111-1307, USA. */ is another). This code breaks when the structure alignment is 32 as sizeof() will report a word=rounded size. By changing the structure alignment to 8. GCC will conform to what is expected by - OpenBSD|NetBSD. + SecBSD|NetBSD. This has several side effects that should be considered. 1. Structures will only be aligned to the size of the largest member. @@ -182,7 +182,7 @@ Boston, MA 02111-1307, USA. */ short strings. This modification is not encouraged but with the present state of the - OpenBSD|NetBSD source tree it is currently the only solution that meets the + SecBSD|NetBSD source tree it is currently the only solution that meets the requirements. */ #undef DEFAULT_STRUCTURE_SIZE_BOUNDARY diff --git a/lib/libc/gen/execv.3 b/lib/libc/gen/execv.3 index efff84e61..6e4f1485b 100644 --- a/lib/libc/gen/execv.3 +++ b/lib/libc/gen/execv.3 @@ -1,4 +1,4 @@ -.\" $OpenBSD: execv.3,v 1.1 2019/08/11 15:48:08 deraadt Exp $ +.\" $OpenBSD: execv.3,v 1.2 2023/05/13 16:36:40 kn Exp $ .\" .\" Copyright (c) 1991, 1993 .\" The Regents of the University of California. All rights reserved. @@ -27,7 +27,7 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.Dd $Mdocdate: August 11 2019 $ +.Dd $Mdocdate: May 13 2023 $ .Dt EXECV 3 .Os .Sh NAME @@ -136,8 +136,14 @@ If this variable isn't specified, .Dv _PATH_DEFPATH from .In paths.h -is used instead, its value being: -.Pa /usr/bin:/bin:/usr/sbin:/sbin:/usr/X11R6/bin:/usr/local/bin +is used instead, consisting of +.Pa /usr/bin , +.Pa /bin , +.Pa /usr/sbin , +.Pa /sbin , +.Pa /usr/X11R6/bin , +.Pa /usr/local/bin , +.Pa /usr/local/sbin . .Pp In addition, certain errors are treated specially. .Pp @@ -201,7 +207,9 @@ Historically, the default path for the and .Fn execvp functions was -.Pa \&.:/bin:/usr/bin . +.Pa \&. , +.Pa /bin , +.Pa /usr/bin . This was changed to improve security and behaviour. .Pp The behavior of diff --git a/lib/libcrypto/bio/bf_lbuf.c b/lib/libcrypto/bio/bf_lbuf.c deleted file mode 100644 index d65150881..000000000 --- a/lib/libcrypto/bio/bf_lbuf.c +++ /dev/null @@ -1,377 +0,0 @@ -/* $OpenBSD: bf_lbuf.c,v 1.15 2022/01/14 08:40:57 tb Exp $ */ -/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) - * All rights reserved. - * - * This package is an SSL implementation written - * by Eric Young (eay@cryptsoft.com). - * The implementation was written so as to conform with Netscapes SSL. - * - * This library is free for commercial and non-commercial use as long as - * the following conditions are aheared to. The following conditions - * apply to all code found in this distribution, be it the RC4, RSA, - * lhash, DES, etc., code; not just the SSL code. The SSL documentation - * included with this distribution is covered by the same copyright terms - * except that the holder is Tim Hudson (tjh@cryptsoft.com). - * - * Copyright remains Eric Young's, and as such any Copyright notices in - * the code are not to be removed. - * If this package is used in a product, Eric Young should be given attribution - * as the author of the parts of the library used. - * This can be in the form of a textual message at program startup or - * in documentation (online or textual) provided with the package. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * "This product includes cryptographic software written by - * Eric Young (eay@cryptsoft.com)" - * The word 'cryptographic' can be left out if the rouines from the library - * being used are not cryptographic related :-). - * 4. If you include any Windows specific code (or a derivative thereof) from - * the apps directory (application code) you must include an acknowledgement: - * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" - * - * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * The licence and distribution terms for any publically available version or - * derivative of this code cannot be changed. i.e. this code cannot simply be - * copied and put under another distribution licence - * [including the GNU Public Licence.] - */ - -#include -#include - -#include -#include - -static int linebuffer_write(BIO *h, const char *buf, int num); -static int linebuffer_read(BIO *h, char *buf, int size); -static int linebuffer_puts(BIO *h, const char *str); -static int linebuffer_gets(BIO *h, char *str, int size); -static long linebuffer_ctrl(BIO *h, int cmd, long arg1, void *arg2); -static int linebuffer_new(BIO *h); -static int linebuffer_free(BIO *data); -static long linebuffer_callback_ctrl(BIO *h, int cmd, BIO_info_cb *fp); - -/* A 10k maximum should be enough for most purposes */ -#define DEFAULT_LINEBUFFER_SIZE 1024*10 - -/* #define DEBUG */ - -static BIO_METHOD methods_linebuffer = { - .type = BIO_TYPE_LINEBUFFER, - .name = "linebuffer", - .bwrite = linebuffer_write, - .bread = linebuffer_read, - .bputs = linebuffer_puts, - .bgets = linebuffer_gets, - .ctrl = linebuffer_ctrl, - .create = linebuffer_new, - .destroy = linebuffer_free, - .callback_ctrl = linebuffer_callback_ctrl -}; - -BIO_METHOD * -BIO_f_linebuffer(void) -{ - return (&methods_linebuffer); -} - -typedef struct bio_linebuffer_ctx_struct { - char *obuf; /* the output char array */ - int obuf_size; /* how big is the output buffer */ - int obuf_len; /* how many bytes are in it */ -} BIO_LINEBUFFER_CTX; - -static int -linebuffer_new(BIO *bi) -{ - BIO_LINEBUFFER_CTX *ctx; - - ctx = malloc(sizeof(BIO_LINEBUFFER_CTX)); - if (ctx == NULL) - return (0); - ctx->obuf = malloc(DEFAULT_LINEBUFFER_SIZE); - if (ctx->obuf == NULL) { - free(ctx); - return (0); - } - ctx->obuf_size = DEFAULT_LINEBUFFER_SIZE; - ctx->obuf_len = 0; - - bi->init = 1; - bi->ptr = (char *)ctx; - bi->flags = 0; - return (1); -} - -static int -linebuffer_free(BIO *a) -{ - BIO_LINEBUFFER_CTX *b; - - if (a == NULL) - return (0); - b = (BIO_LINEBUFFER_CTX *)a->ptr; - free(b->obuf); - free(a->ptr); - a->ptr = NULL; - a->init = 0; - a->flags = 0; - return (1); -} - -static int -linebuffer_read(BIO *b, char *out, int outl) -{ - int ret = 0; - - if (out == NULL) - return (0); - if (b->next_bio == NULL) - return (0); - ret = BIO_read(b->next_bio, out, outl); - BIO_clear_retry_flags(b); - BIO_copy_next_retry(b); - return (ret); -} - -static int -linebuffer_write(BIO *b, const char *in, int inl) -{ - int i, num = 0, foundnl; - BIO_LINEBUFFER_CTX *ctx; - - if ((in == NULL) || (inl <= 0)) - return (0); - ctx = (BIO_LINEBUFFER_CTX *)b->ptr; - if ((ctx == NULL) || (b->next_bio == NULL)) - return (0); - - BIO_clear_retry_flags(b); - - do { - const char *p; - - for (p = in; p < in + inl && *p != '\n'; p++) - ; - if (*p == '\n') { - p++; - foundnl = 1; - } else - foundnl = 0; - - /* If a NL was found and we already have text in the save - buffer, concatenate them and write */ - while ((foundnl || p - in > ctx->obuf_size - ctx->obuf_len) && - ctx->obuf_len > 0) { - int orig_olen = ctx->obuf_len; - - i = ctx->obuf_size - ctx->obuf_len; - if (p - in > 0) { - if (i >= p - in) { - memcpy(&(ctx->obuf[ctx->obuf_len]), - in, p - in); - ctx->obuf_len += p - in; - inl -= p - in; - num += p - in; - in = p; - } else { - memcpy(&(ctx->obuf[ctx->obuf_len]), - in, i); - ctx->obuf_len += i; - inl -= i; - in += i; - num += i; - } - } - - i = BIO_write(b->next_bio, ctx->obuf, ctx->obuf_len); - if (i <= 0) { - ctx->obuf_len = orig_olen; - BIO_copy_next_retry(b); - if (i < 0) - return ((num > 0) ? num : i); - if (i == 0) - return (num); - } - if (i < ctx->obuf_len) - memmove(ctx->obuf, ctx->obuf + i, - ctx->obuf_len - i); - ctx->obuf_len -= i; - } - - /* Now that the save buffer is emptied, let's write the input - buffer if a NL was found and there is anything to write. */ - if ((foundnl || p - in > ctx->obuf_size) && p - in > 0) { - i = BIO_write(b->next_bio, in, p - in); - if (i <= 0) { - BIO_copy_next_retry(b); - if (i < 0) - return ((num > 0) ? num : i); - if (i == 0) - return (num); - } - num += i; - in += i; - inl -= i; - } - } while (foundnl && inl > 0); - /* We've written as much as we can. The rest of the input buffer, if - any, is text that doesn't and with a NL and therefore needs to be - saved for the next trip. */ - if (inl > 0) { - memcpy(&(ctx->obuf[ctx->obuf_len]), in, inl); - ctx->obuf_len += inl; - num += inl; - } - return num; -} - -static long -linebuffer_ctrl(BIO *b, int cmd, long num, void *ptr) -{ - BIO *dbio; - BIO_LINEBUFFER_CTX *ctx; - long ret = 1; - char *p; - int r; - int obs; - - ctx = (BIO_LINEBUFFER_CTX *)b->ptr; - - switch (cmd) { - case BIO_CTRL_RESET: - ctx->obuf_len = 0; - if (b->next_bio == NULL) - return (0); - ret = BIO_ctrl(b->next_bio, cmd, num, ptr); - break; - case BIO_CTRL_INFO: - ret = (long)ctx->obuf_len; - break; - case BIO_CTRL_WPENDING: - ret = (long)ctx->obuf_len; - if (ret == 0) { - if (b->next_bio == NULL) - return (0); - ret = BIO_ctrl(b->next_bio, cmd, num, ptr); - } - break; - case BIO_C_SET_BUFF_SIZE: - obs = (int)num; - p = ctx->obuf; - if ((obs > DEFAULT_LINEBUFFER_SIZE) && (obs != ctx->obuf_size)) { - p = malloc(num); - if (p == NULL) - goto malloc_error; - } - if (ctx->obuf != p) { - if (ctx->obuf_len > obs) { - ctx->obuf_len = obs; - } - memcpy(p, ctx->obuf, ctx->obuf_len); - free(ctx->obuf); - ctx->obuf = p; - ctx->obuf_size = obs; - } - break; - case BIO_C_DO_STATE_MACHINE: - if (b->next_bio == NULL) - return (0); - BIO_clear_retry_flags(b); - ret = BIO_ctrl(b->next_bio, cmd, num, ptr); - BIO_copy_next_retry(b); - break; - - case BIO_CTRL_FLUSH: - if (b->next_bio == NULL) - return (0); - if (ctx->obuf_len <= 0) { - ret = BIO_ctrl(b->next_bio, cmd, num, ptr); - break; - } - - for (;;) { - BIO_clear_retry_flags(b); - if (ctx->obuf_len > 0) { - r = BIO_write(b->next_bio, - ctx->obuf, ctx->obuf_len); - BIO_copy_next_retry(b); - if (r <= 0) - return ((long)r); - if (r < ctx->obuf_len) - memmove(ctx->obuf, ctx->obuf + r, - ctx->obuf_len - r); - ctx->obuf_len -= r; - } else { - ctx->obuf_len = 0; - ret = 1; - break; - } - } - ret = BIO_ctrl(b->next_bio, cmd, num, ptr); - break; - case BIO_CTRL_DUP: - dbio = (BIO *)ptr; - if (!BIO_set_write_buffer_size(dbio, ctx->obuf_size)) - ret = 0; - break; - default: - if (b->next_bio == NULL) - return (0); - ret = BIO_ctrl(b->next_bio, cmd, num, ptr); - break; - } - return (ret); -malloc_error: - BIOerror(ERR_R_MALLOC_FAILURE); - return (0); -} - -static long -linebuffer_callback_ctrl(BIO *b, int cmd, BIO_info_cb *fp) -{ - long ret = 1; - - if (b->next_bio == NULL) - return (0); - switch (cmd) { - default: - ret = BIO_callback_ctrl(b->next_bio, cmd, fp); - break; - } - return (ret); -} - -static int -linebuffer_gets(BIO *b, char *buf, int size) -{ - if (b->next_bio == NULL) - return (0); - return (BIO_gets(b->next_bio, buf, size)); -} - -static int -linebuffer_puts(BIO *b, const char *str) -{ - return (linebuffer_write(b, str, strlen(str))); -} diff --git a/lib/libcrypto/man/DSA_generate_parameters.3 b/lib/libcrypto/man/DSA_generate_parameters.3 index f7dcb901f..07fa5acf9 100644 --- a/lib/libcrypto/man/DSA_generate_parameters.3 +++ b/lib/libcrypto/man/DSA_generate_parameters.3 @@ -1,4 +1,4 @@ -.\" $OpenBSD: DSA_generate_parameters.3,v 1.12 2019/06/10 14:58:48 schwarze Exp $ +.\" $OpenBSD: DSA_generate_parameters.3,v 1.13 2023/05/14 09:27:15 tb Exp $ .\" OpenSSL 9b86974e Aug 7 22:14:47 2015 -0400 .\" .\" This file was written by Ulf Moeller , @@ -49,7 +49,7 @@ .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED .\" OF THE POSSIBILITY OF SUCH DAMAGE. .\" -.Dd $Mdocdate: June 10 2019 $ +.Dd $Mdocdate: May 14 2023 $ .Dt DSA_GENERATE_PARAMETERS 3 .Os .Sh NAME @@ -216,7 +216,7 @@ reached the squaring step (the parameters to did not reveal how many witnesses had been tested); since OpenSSL 0.9.5, .Fn callback 1 ...\& is called as in -.Xr BN_is_prime 3 , +.Xr BN_is_prime_ex 3 , i.e. once for each witness. .Pp .Fn DSA_generate_parameters_ex diff --git a/lib/libcrypto/man/EVP_PKEY_encrypt.3 b/lib/libcrypto/man/EVP_PKEY_encrypt.3 index 210c43d6d..a13594b5e 100644 --- a/lib/libcrypto/man/EVP_PKEY_encrypt.3 +++ b/lib/libcrypto/man/EVP_PKEY_encrypt.3 @@ -1,4 +1,4 @@ -.\" $OpenBSD: EVP_PKEY_encrypt.3,v 1.7 2022/03/31 17:27:17 naddy Exp $ +.\" $OpenBSD: EVP_PKEY_encrypt.3,v 1.8 2023/05/14 09:29:37 tb Exp $ .\" OpenSSL b97fdb57 Nov 11 09:33:09 2016 +0100 .\" .\" This file was written by Dr. Stephen Henson . @@ -49,7 +49,7 @@ .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED .\" OF THE POSSIBILITY OF SUCH DAMAGE. .\" -.Dd $Mdocdate: March 31 2022 $ +.Dd $Mdocdate: May 14 2023 $ .Dt EVP_PKEY_ENCRYPT 3 .Os .Sh NAME @@ -131,7 +131,9 @@ and .Xr d2i_X509 3 for means to load a public key. You may also simply set -.Ql eng = NULL; +.Dq eng +to +.Dv NULL to start with the default OpenSSL RSA implementation: .Bd -literal -offset indent #include diff --git a/lib/libcrypto/man/POLICYINFO_new.3 b/lib/libcrypto/man/POLICYINFO_new.3 index b5cb6a5c7..52c004414 100644 --- a/lib/libcrypto/man/POLICYINFO_new.3 +++ b/lib/libcrypto/man/POLICYINFO_new.3 @@ -1,4 +1,4 @@ -.\" $OpenBSD: POLICYINFO_new.3,v 1.9 2021/10/27 11:24:47 schwarze Exp $ +.\" $OpenBSD: POLICYINFO_new.3,v 1.11 2023/05/14 08:03:57 tb Exp $ .\" .\" Copyright (c) 2016 Ingo Schwarze .\" @@ -14,7 +14,7 @@ .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. .\" -.Dd $Mdocdate: October 27 2021 $ +.Dd $Mdocdate: May 14 2023 $ .Dt POLICYINFO_NEW 3 .Os .Sh NAME @@ -179,8 +179,7 @@ if an error occurs. .Xr NAME_CONSTRAINTS_new 3 , .Xr X509_EXTENSION_new 3 , .Xr X509_get_extension_flags 3 , -.Xr X509_new 3 , -.Xr X509_policy_tree_level_count 3 +.Xr X509_new 3 .Sh STANDARDS RFC 5280: Internet X.509 Public Key Infrastructure Certificate and Certificate Revocation List (CRL) Profile: diff --git a/lib/libcrypto/man/RSA_set_method.3 b/lib/libcrypto/man/RSA_set_method.3 index 0169ba599..818b64823 100644 --- a/lib/libcrypto/man/RSA_set_method.3 +++ b/lib/libcrypto/man/RSA_set_method.3 @@ -1,4 +1,4 @@ -.\" $OpenBSD: RSA_set_method.3,v 1.16 2022/01/15 23:38:50 jsg Exp $ +.\" $OpenBSD: RSA_set_method.3,v 1.17 2023/05/14 09:33:19 tb Exp $ .\" OpenSSL 99d63d46 Oct 26 13:56:48 2016 -0400 .\" .\" This file was written by Ulf Moeller @@ -50,7 +50,7 @@ .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED .\" OF THE POSSIBILITY OF SUCH DAMAGE. .\" -.Dd $Mdocdate: January 15 2022 $ +.Dd $Mdocdate: May 14 2023 $ .Dt RSA_SET_METHOD 3 .Os .Sh NAME @@ -274,5 +274,7 @@ but will not be reflected in the return value of the .Fn RSA_flags function - in effect .Fn RSA_flags -behaves more like an RSA_default_flags() function, which does not +behaves more like an +.Fn RSA_default_flags +function, which does not currently exist. diff --git a/lib/libcrypto/x509/x509_err.c b/lib/libcrypto/x509/x509_err.c index bcb04f1fd..2cbd34935 100644 --- a/lib/libcrypto/x509/x509_err.c +++ b/lib/libcrypto/x509/x509_err.c @@ -1,4 +1,4 @@ -/* $OpenBSD: x509_err.c,v 1.21 2023/04/24 08:39:06 job Exp $ */ +/* $OpenBSD: x509_err.c,v 1.22 2023/05/14 17:20:26 tb Exp $ */ /* ==================================================================== * Copyright (c) 1999-2006 The OpenSSL Project. All rights reserved. * @@ -71,11 +71,6 @@ static ERR_STRING_DATA X509_str_functs[] = { {0, NULL} }; -static ERR_STRING_DATA X509V3_str_functs[] = { - {ERR_FUNC(0xfff), "CRYPTO_internal"}, - {0, NULL} -}; - static ERR_STRING_DATA X509_str_reasons[] = { {ERR_REASON(X509_R_BAD_X509_FILETYPE) , "bad x509 filetype"}, {ERR_REASON(X509_R_BASE64_DECODE_ERROR) , "base64 decode error"}, @@ -108,6 +103,16 @@ static ERR_STRING_DATA X509_str_reasons[] = { {0, NULL} }; +#undef ERR_FUNC +#undef ERR_REASON +#define ERR_FUNC(func) ERR_PACK(ERR_LIB_X509V3,func,0) +#define ERR_REASON(reason) ERR_PACK(ERR_LIB_X509V3,0,reason) + +static ERR_STRING_DATA X509V3_str_functs[] = { + {ERR_FUNC(0xfff), "CRYPTO_internal"}, + {0, NULL} +}; + static ERR_STRING_DATA X509V3_str_reasons[] = { {ERR_REASON(X509V3_R_BAD_IP_ADDRESS) , "bad ip address"}, {ERR_REASON(X509V3_R_BAD_OBJECT) , "bad object"}, diff --git a/lib/libtls/tls.c b/lib/libtls/tls.c index ff33ebe53..f3e7148f0 100644 --- a/lib/libtls/tls.c +++ b/lib/libtls/tls.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tls.c,v 1.94 2022/02/08 19:13:50 tb Exp $ */ +/* $OpenBSD: tls.c,v 1.95 2023/05/14 07:26:25 op Exp $ */ /* * Copyright (c) 2014 Joel Sing * @@ -21,6 +21,7 @@ #include #include #include +#include #include #include diff --git a/lib/libtls/tls_bio_cb.c b/lib/libtls/tls_bio_cb.c index dad9d23ef..8a1edfd5e 100644 --- a/lib/libtls/tls_bio_cb.c +++ b/lib/libtls/tls_bio_cb.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tls_bio_cb.c,v 1.20 2022/01/10 23:39:48 tb Exp $ */ +/* $OpenBSD: tls_bio_cb.c,v 1.21 2023/05/14 07:26:25 op Exp $ */ /* * Copyright (c) 2016 Tobias Pape * @@ -17,6 +17,7 @@ #include #include +#include #include #include diff --git a/lib/libtls/tls_client.c b/lib/libtls/tls_client.c index 1629697f8..deb24ebc2 100644 --- a/lib/libtls/tls_client.c +++ b/lib/libtls/tls_client.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tls_client.c,v 1.48 2021/10/21 08:38:11 tb Exp $ */ +/* $OpenBSD: tls_client.c,v 1.49 2023/05/14 07:26:25 op Exp $ */ /* * Copyright (c) 2014 Joel Sing * @@ -25,6 +25,7 @@ #include #include #include +#include #include #include diff --git a/lib/libtls/tls_config.c b/lib/libtls/tls_config.c index 15e218b4e..3efd0ddd5 100644 --- a/lib/libtls/tls_config.c +++ b/lib/libtls/tls_config.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tls_config.c,v 1.65 2022/01/25 21:51:24 eric Exp $ */ +/* $OpenBSD: tls_config.c,v 1.66 2023/05/14 07:26:25 op Exp $ */ /* * Copyright (c) 2014 Joel Sing * @@ -22,6 +22,7 @@ #include #include #include +#include #include #include diff --git a/lib/libtls/tls_conninfo.c b/lib/libtls/tls_conninfo.c index 4d9ae29e0..b2aadab08 100644 --- a/lib/libtls/tls_conninfo.c +++ b/lib/libtls/tls_conninfo.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tls_conninfo.c,v 1.22 2021/01/05 15:57:38 tb Exp $ */ +/* $OpenBSD: tls_conninfo.c,v 1.23 2023/05/14 07:26:25 op Exp $ */ /* * Copyright (c) 2015 Joel Sing * Copyright (c) 2015 Bob Beck @@ -17,6 +17,7 @@ */ #include +#include #include diff --git a/lib/libtls/tls_ocsp.c b/lib/libtls/tls_ocsp.c index 83585fac0..acf6935a5 100644 --- a/lib/libtls/tls_ocsp.c +++ b/lib/libtls/tls_ocsp.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tls_ocsp.c,v 1.22 2021/10/31 16:39:32 tb Exp $ */ +/* $OpenBSD: tls_ocsp.c,v 1.23 2023/05/14 07:26:25 op Exp $ */ /* * Copyright (c) 2015 Marko Kreen * Copyright (c) 2016 Bob Beck @@ -21,6 +21,8 @@ #include #include +#include + #include #include #include diff --git a/lib/libtls/tls_server.c b/lib/libtls/tls_server.c index 72f797b86..5f93c7a03 100644 --- a/lib/libtls/tls_server.c +++ b/lib/libtls/tls_server.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tls_server.c,v 1.48 2022/01/19 11:10:55 inoguchi Exp $ */ +/* $OpenBSD: tls_server.c,v 1.49 2023/05/14 07:26:25 op Exp $ */ /* * Copyright (c) 2014 Joel Sing * @@ -19,6 +19,8 @@ #include +#include + #include #include #include diff --git a/lib/libtls/tls_util.c b/lib/libtls/tls_util.c index d8103a506..b276d2cfa 100644 --- a/lib/libtls/tls_util.c +++ b/lib/libtls/tls_util.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tls_util.c,v 1.15 2021/08/16 13:54:38 tb Exp $ */ +/* $OpenBSD: tls_util.c,v 1.16 2023/05/14 07:26:25 op Exp $ */ /* * Copyright (c) 2014 Joel Sing * Copyright (c) 2014 Ted Unangst @@ -20,6 +20,7 @@ #include #include +#include #include #include diff --git a/regress/lib/libcrypto/asn1/asn1oct.c b/regress/lib/libcrypto/asn1/asn1oct.c index fef312d73..d989d1e6e 100644 --- a/regress/lib/libcrypto/asn1/asn1oct.c +++ b/regress/lib/libcrypto/asn1/asn1oct.c @@ -1,4 +1,4 @@ -/* $OpenBSD: asn1oct.c,v 1.3 2023/05/12 10:43:28 tb Exp $ */ +/* $OpenBSD: asn1oct.c,v 1.4 2023/05/13 07:17:32 tb Exp $ */ /* * Copyright (c) 2023 Theo Buehler @@ -16,6 +16,7 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ +#include #include #include @@ -239,6 +240,7 @@ test_s2i_ASN1_OCTET_STRING(const struct s2i_asn1_octet_string_test *test) if ((got = i2s_ASN1_OCTET_STRING(NULL, aos)) == NULL) errx(1, "%s: i2s_ASN1_OCTET_STRING", test->desc); + assert(test->want != NULL); if (strcmp(test->want, got) != 0) { fprintf(stderr, "%s: \"%s\" failed: want \"%s\", got \"%s\"\n", __func__, test->desc, test->want, got); diff --git a/regress/sys/arch/amd64/vmm/vcpu.c b/regress/sys/arch/amd64/vmm/vcpu.c index f221b58f7..84bd9492a 100644 --- a/regress/sys/arch/amd64/vmm/vcpu.c +++ b/regress/sys/arch/amd64/vmm/vcpu.c @@ -1,4 +1,4 @@ -/* $OpenBSD: vcpu.c,v 1.5 2023/04/27 05:42:44 anton Exp $ */ +/* $OpenBSD: vcpu.c,v 1.6 2023/05/13 23:15:28 dv Exp $ */ /* * Copyright (c) 2022 Dave Voutila @@ -83,6 +83,7 @@ main(int argc, char **argv) struct vm_resetcpu_params vresetp; struct vm_run_params vrunp; struct vm_terminate_params vtp; + struct vm_sharemem_params vsp; struct vm_mem_range *vmr; int fd, ret = 1; @@ -127,8 +128,9 @@ main(int argc, char **argv) ((uint8_t*)p)[j + 1] = PCKBC_AUX; } vmr->vmr_va = (vaddr_t)p; - printf("mapped region %zu: { gpa: 0x%08lx, size: %lu }\n", - i, vmr->vmr_gpa, vmr->vmr_size); + printf("created mapped region %zu: { gpa: 0x%08lx, size: %lu," + " hva: 0x%lx }\n", i, vmr->vmr_gpa, vmr->vmr_size, + vmr->vmr_va); } if (ioctl(fd, VMM_IOC_CREATE, &vcp) == -1) @@ -136,7 +138,54 @@ main(int argc, char **argv) printf("created vm %d named \"%s\"\n", vcp.vcp_id, vcp.vcp_name); /* - * 2. Check that our VM exists. + * 2. Check we can create shared memory mappings. + */ + memset(&vsp, 0, sizeof(vsp)); + vsp.vsp_nmemranges = vcp.vcp_nmemranges; + memcpy(&vsp.vsp_memranges, &vcp.vcp_memranges, + sizeof(vsp.vsp_memranges)); + vsp.vsp_vm_id = vcp.vcp_id; + + /* Find some new va ranges... */ + for (i = 0; i < vsp.vsp_nmemranges; i++) { + vmr = &vsp.vsp_memranges[i]; + p = mmap(NULL, vmr->vmr_size, PROT_READ | PROT_WRITE, + MAP_PRIVATE | MAP_ANON, -1, 0); + if (p == MAP_FAILED) + err(1, "mmap"); + vmr->vmr_va = (vaddr_t)p; + } + + /* Release our mappings so vmm can replace them. */ + for (i = 0; i < vsp.vsp_nmemranges; i++) { + vmr = &vsp.vsp_memranges[i]; + munmap((void*)vmr->vmr_va, vmr->vmr_size); + } + + /* Perform the shared mapping. */ + if (ioctl(fd, VMM_IOC_SHAREMEM, &vsp) == -1) + err(1, "VMM_IOC_SHAREMEM"); + printf("created shared memory mappings\n"); + + /* We should see our reset vector instructions in the new mappings. */ + for (i = 0; i < vsp.vsp_nmemranges; i++) { + vmr = &vsp.vsp_memranges[i]; + p = (void*)vmr->vmr_va; + + for (j = 0; j < vmr->vmr_size; j += 2) { + if (((uint8_t*)p)[j + 0] != 0xE4) + errx(1, "bad byte"); + if (((uint8_t*)p)[j + 1] != PCKBC_AUX) + errx(1, "bad byte"); + } + printf("checked shared region %zu: { gpa: 0x%08lx, size: %lu," + " hva: 0x%lx }\n", i, vmr->vmr_gpa, vmr->vmr_size, + vmr->vmr_va); + } + printf("validated shared memory mappings\n"); + + /* + * 3. Check that our VM exists. */ memset(&vip, 0, sizeof(vip)); vip.vip_size = 0; @@ -189,7 +238,7 @@ main(int argc, char **argv) ours = NULL; /* - * 3. Reset our VCPU and initialize register state. + * 4. Reset our VCPU and initialize register state. */ memset(&vresetp, 0, sizeof(vresetp)); vresetp.vrp_vm_id = vcp.vcp_id; @@ -205,7 +254,7 @@ main(int argc, char **argv) vresetp.vrp_vm_id); /* - * 4. Run the vcpu, expecting an immediate exit for IO assist. + * 5. Run the vcpu, expecting an immediate exit for IO assist. */ exit = malloc(sizeof(*exit)); if (exit == NULL) { @@ -258,7 +307,7 @@ main(int argc, char **argv) out: /* - * 5. Terminate our VM and clean up. + * 6. Terminate our VM and clean up. */ memset(&vtp, 0, sizeof(vtp)); vtp.vtp_vm_id = vcp.vcp_id; @@ -277,12 +326,22 @@ out: vmr = &vcp.vcp_memranges[i]; if (vmr->vmr_va) { if (munmap((void *)vmr->vmr_va, vmr->vmr_size)) { - warn("failed to unmap region %zu at 0x%08lx", - i, vmr->vmr_va); + warn("failed to unmap orginal region %zu @ hva " + "0x%lx", i, vmr->vmr_va); ret = 1; } else - printf("unmapped region %zu @ gpa 0x%08lx\n", - i, vmr->vmr_gpa); + printf("unmapped origin region %zu @ hva " + "0x%lx\n", i, vmr->vmr_va); + } + vmr = &vsp.vsp_memranges[i]; + if (vmr->vmr_va) { + if (munmap((void *)vmr->vmr_va, vmr->vmr_size)) { + warn("failed to unmap shared region %zu @ hva " + "0x%lx", i, vmr->vmr_va); + ret = 1; + } else + printf("unmapped shared region %zu @ hva " + "0x%lx\n", i, vmr->vmr_va); } } diff --git a/sbin/disklabel/disklabel.8 b/sbin/disklabel/disklabel.8 index 389f1ec9a..8c7735eb6 100644 --- a/sbin/disklabel/disklabel.8 +++ b/sbin/disklabel/disklabel.8 @@ -1,4 +1,4 @@ -.\" $OpenBSD: disklabel.8,v 1.154 2023/04/27 14:19:28 krw Exp $ +.\" $OpenBSD: disklabel.8,v 1.155 2023/05/13 18:13:42 krw Exp $ .\" $NetBSD: disklabel.8,v 1.9 1995/03/18 14:54:38 cgd Exp $ .\" .\" Copyright (c) 1987, 1988, 1991, 1993 @@ -33,7 +33,7 @@ .\" .\" @(#)disklabel.8 8.2 (Berkeley) 4/19/94 .\" -.Dd $Mdocdate: April 27 2023 $ +.Dd $Mdocdate: May 13 2023 $ .Dt DISKLABEL 8 .Os .Sh NAME @@ -353,7 +353,7 @@ Delete an existing partition (or to delete all partitions). If no partition is specified, the user will be prompted for one. .It Cm e -Edit disk type, e.g. 'SCSI', and label description, e.g. 'UMIS RPJTJ256MED'. +Edit label description, e.g. 'UMIS RPJTJ256MED'. .It Cm i Change the disklabel UID, specified as a 16-character hexadecimal string. If set to all zeros, a new UID will automatically be allocated when the diff --git a/sbin/disklabel/disklabel.c b/sbin/disklabel/disklabel.c index 7d7e4396b..de1f28030 100644 --- a/sbin/disklabel/disklabel.c +++ b/sbin/disklabel/disklabel.c @@ -1,4 +1,4 @@ -/* $OpenBSD: disklabel.c,v 1.248 2023/05/06 15:07:02 krw Exp $ */ +/* $OpenBSD: disklabel.c,v 1.249 2023/05/13 18:13:42 krw Exp $ */ /* * Copyright (c) 1987, 1993 @@ -354,6 +354,7 @@ readlabel(int f) lab.d_ntracks = dl.d_ntracks; lab.d_secpercyl = dl.d_secpercyl; lab.d_ncylinders = dl.d_ncylinders; + lab.d_type = dl.d_type; } } @@ -840,24 +841,6 @@ getasciilabel(FILE *f, struct disklabel *lp) continue; } *tp++ = '\0', tp = skip(tp); - if (!strcmp(cp, "type")) { - if (tp == NULL) - tp = "unknown"; - else if (strcasecmp(tp, "IDE") == 0) - tp = "ESDI"; - cpp = dktypenames; - for (; cpp < &dktypenames[DKMAXTYPES]; cpp++) - if ((s = *cpp) && !strcasecmp(s, tp)) { - lp->d_type = cpp - dktypenames; - goto next; - } - v = GETNUM(lp->d_type, tp, 0, &errstr); - if (errstr || v >= DKMAXTYPES) - warnx("line %d: warning, unknown disk type: %s", - lineno, tp); - lp->d_type = v; - continue; - } if (!strcmp(cp, "flags")) { for (v = 0; (cp = tp) && *cp != '\0';) { tp = word(cp); @@ -919,7 +902,8 @@ getasciilabel(FILE *f, struct disklabel *lp) !strcmp(cp, "sectors/track") || !strcmp(cp, "sectors/cylinder") || !strcmp(cp, "tracks/cylinder") || - !strcmp(cp, "cylinders")) + !strcmp(cp, "cylinders") || + !strcmp(cp, "type")) continue; if ('a' <= *cp && *cp <= 'z' && cp[1] == '\0') { diff --git a/sbin/disklabel/editor.c b/sbin/disklabel/editor.c index d813adde5..eb1bbc356 100644 --- a/sbin/disklabel/editor.c +++ b/sbin/disklabel/editor.c @@ -1,4 +1,4 @@ -/* $OpenBSD: editor.c,v 1.404 2023/04/27 14:19:28 krw Exp $ */ +/* $OpenBSD: editor.c,v 1.405 2023/05/13 18:13:42 krw Exp $ */ /* * Copyright (c) 1997-2000 Todd C. Miller @@ -136,7 +136,7 @@ struct alloc_table alloc_table_default[] = { struct alloc_table *alloc_table = alloc_table_default; int alloc_table_nitems = 4; -void edit_parms(struct disklabel *); +void edit_packname(struct disklabel *); void editor_resize(struct disklabel *, const char *); void editor_add(struct disklabel *, const char *); void editor_change(struct disklabel *, const char *); @@ -153,7 +153,6 @@ int getpartno(const struct disklabel *, const char *, const char *); int has_overlap(struct disklabel *); int partition_cmp(const void *, const void *); const struct partition **sort_partitions(const struct disklabel *, int); -void getdisktype(struct disklabel *, const char *, char *); void find_bounds(const struct disklabel *); void set_bounds(struct disklabel *); void set_duid(struct disklabel *); @@ -202,10 +201,6 @@ editor(int f) !(tmpmountpoints = calloc(MAXPARTITIONS, sizeof(char *)))) errx(4, "out of memory"); - /* Don't allow disk type of "unknown" */ - getdisktype(&newlab, "You need to specify a type for this disk.", - specname); - /* How big is the OpenBSD portion of the disk? */ find_bounds(&newlab); @@ -310,7 +305,7 @@ editor(int f) break; case 'e': - edit_parms(&newlab); + edit_packname(&newlab); break; case 'i': @@ -1229,41 +1224,12 @@ done: } void -edit_parms(struct disklabel *lp) +edit_packname(struct disklabel *lp) { char *p; - u_int64_t ui; struct disklabel oldlabel = *lp; - printf("Changing disk type and label description for %s:\n", specname); - - /* disk type */ - for (;;) { - p = getstring("disk type", - "What kind of disk is this? Usually SCSI, ESDI, ST506, or " - "floppy (use ESDI for IDE).", dktypenames[lp->d_type]); - if (p == NULL) - return; - if (strcasecmp(p, "IDE") == 0) - ui = DTYPE_ESDI; - else - for (ui = 1; ui < DKMAXTYPES && strcasecmp(p, - dktypenames[ui]); ui++) - ; - if (ui < DKMAXTYPES) { - break; - } else { - printf("\"%s\" is not a valid disk type.\n", p); - fputs("Valid types are: ", stdout); - for (ui = 1; ui < DKMAXTYPES; ui++) { - printf("\"%s\"", dktypenames[ui]); - if (ui < DKMAXTYPES - 1) - fputs(", ", stdout); - } - putchar('\n'); - } - } - lp->d_type = ui; + printf("Changing label description for %s:\n", specname); /* pack/label id */ p = getstring("label name", @@ -1302,77 +1268,6 @@ sort_partitions(const struct disklabel *lp, int ignore) return (spp); } -/* - * Get a valid disk type if necessary. - */ -void -getdisktype(struct disklabel *lp, const char *banner, char *dev) -{ - int i; - char *s; - const char *def = "SCSI"; - const struct dtypes { - const char *dev; - const char *type; - } dtypes[] = { - { "sd", "SCSI" }, - { "wd", "IDE" }, - { "fd", "FLOPPY" }, - { "vnd", "VND" }, - }; - - if ((s = basename(dev)) != NULL) { - if (*s == 'r') - s++; - i = strcspn(s, "0123456789"); - s[i] = '\0'; - dev = s; - for (i = 0; i < nitems(dtypes); i++) { - if (strcmp(dev, dtypes[i].dev) == 0) { - def = dtypes[i].type; - break; - } - } - } - - if (lp->d_type > DKMAXTYPES || lp->d_type == 0) { - puts(banner); - puts("Possible values are:"); - printf("\"IDE\", "); - for (i = 1; i < DKMAXTYPES; i++) { - printf("\"%s\"", dktypenames[i]); - if (i < DKMAXTYPES - 1) - fputs(", ", stdout); - } - putchar('\n'); - - for (;;) { - s = getstring("Disk type", - "What kind of disk is this? Usually SCSI, IDE, " - "ESDI, ST506, or floppy.", def); - if (s == NULL) - continue; - if (strcasecmp(s, "IDE") == 0) { - lp->d_type = DTYPE_ESDI; - return; - } - for (i = 1; i < DKMAXTYPES; i++) - if (strcasecmp(s, dktypenames[i]) == 0) { - lp->d_type = i; - return; - } - printf("\"%s\" is not a valid disk type.\n", s); - fputs("Valid types are: ", stdout); - for (i = 1; i < DKMAXTYPES; i++) { - printf("\"%s\"", dktypenames[i]); - if (i < DKMAXTYPES - 1) - fputs(", ", stdout); - } - putchar('\n'); - } - } -} - /* * Get beginning and ending sectors of the OpenBSD portion of the disk * from the user. @@ -1547,7 +1442,7 @@ editor_help(void) " c [part] - change partition size r - display free space\n" " D - reset label to default s [path] - save label to file\n" " d [part] - delete partition U - undo all changes\n" -" e - edit type and label name u - undo last change\n" +" e - edit label description u - undo last change\n" " i - modify disklabel UID w - write label to disk\n" " l [unit] - print disk label header x - exit & lose changes\n" " M - disklabel(8) man page z - delete all partitions\n" diff --git a/sys/dev/pci/drm/drm_drv.c b/sys/dev/pci/drm/drm_drv.c index 940830493..02b0e50c7 100644 --- a/sys/dev/pci/drm/drm_drv.c +++ b/sys/dev/pci/drm/drm_drv.c @@ -90,7 +90,7 @@ DEFINE_STATIC_SRCU(drm_unplug_srcu); * Some functions are only called once on init regardless of how many times * drm attaches. In linux this is handled via module_init()/module_exit() */ -int drm_refcnt; +int drm_refcnt; struct drm_softc { struct device sc_dev; @@ -1225,7 +1225,7 @@ drm_attach_pci(const struct drm_driver *driver, struct pci_attach_args *pa, sc = (struct drm_softc *)config_found_sm(dev, &arg, drmprint, drmsubmatch); if (sc == NULL) return NULL; - + return sc->sc_drm; } @@ -1522,7 +1522,7 @@ const struct pci_device_id * drm_find_description(int vendor, int device, const struct pci_device_id *idlist) { int i = 0; - + for (i = 0; idlist[i].vendor != 0; i++) { if ((idlist[i].vendor == vendor) && (idlist[i].device == device || @@ -1546,7 +1546,7 @@ struct drm_file * drm_find_file_by_minor(struct drm_device *dev, int minor) { struct drm_file key; - + key.fminor = minor; return (SPLAY_FIND(drm_file_tree, &dev->files, &key)); } @@ -1886,7 +1886,7 @@ drm_dmamem_alloc(bus_dma_tag_t dmat, bus_size_t size, bus_size_t alignment, struct drm_dmamem *mem; size_t strsize; /* - * segs is the last member of the struct since we modify the size + * segs is the last member of the struct since we modify the size * to allow extra segments if more than one are allowed. */ strsize = sizeof(*mem) + (sizeof(bus_dma_segment_t) * (nsegments - 1)); @@ -1904,7 +1904,7 @@ drm_dmamem_alloc(bus_dma_tag_t dmat, bus_size_t size, bus_size_t alignment, &mem->nsegs, BUS_DMA_NOWAIT | BUS_DMA_ZERO) != 0) goto destroy; - if (bus_dmamem_map(dmat, mem->segs, mem->nsegs, size, + if (bus_dmamem_map(dmat, mem->segs, mem->nsegs, size, &mem->kva, BUS_DMA_NOWAIT | mapflags) != 0) goto free; diff --git a/sys/dev/pv/vmmci.c b/sys/dev/pv/vmmci.c index 461df5801..543975d0a 100644 --- a/sys/dev/pv/vmmci.c +++ b/sys/dev/pv/vmmci.c @@ -176,10 +176,10 @@ vmmci_config_change(struct virtio_softc *vsc) case VMMCI_SYNCRTC: inittodr(gettime()); sc->sc_cmd = VMMCI_NONE; - break; + break; default: printf("%s: invalid command %d\n", sc->sc_dev.dv_xname, cmd); - cmd = VMMCI_NONE; + cmd = VMMCI_NONE; break; } diff --git a/sys/dev/pv/vmt.c b/sys/dev/pv/vmt.c index 569b8600b..601fb5c4d 100644 --- a/sys/dev/pv/vmt.c +++ b/sys/dev/pv/vmt.c @@ -1338,7 +1338,7 @@ vmt_xdr_nic_info(char *data) nictotal = vmt_xdr_nic_entry(iface, data); if (nictotal == 0) continue; - + if (data != NULL) data += nictotal; diff --git a/sys/dev/vmm/vmm.c b/sys/dev/vmm/vmm.c index d46b34310..4d4866f70 100644 --- a/sys/dev/vmm/vmm.c +++ b/sys/dev/vmm/vmm.c @@ -1,4 +1,4 @@ -/* $OpenBSD: vmm.c,v 1.1 2023/04/26 15:11:21 mlarkin Exp $ */ +/* $OpenBSD: vmm.c,v 1.2 2023/05/13 23:15:28 dv Exp $ */ /* * Copyright (c) 2014-2023 Mike Larkin * @@ -262,6 +262,9 @@ vmmioctl(dev_t dev, u_long cmd, caddr_t data, int flag, struct proc *p) case VMM_IOC_WRITEVMPARAMS: ret = vm_rwvmparams((struct vm_rwvmparams_params *)data, 1); break; + case VMM_IOC_SHAREMEM: + ret = vm_share_mem((struct vm_sharemem_params *)data, p); + break; default: ret = vmmioctl_machdep(dev, cmd, data, flag, p); break; @@ -286,6 +289,7 @@ pledge_ioctl_vmm(struct proc *p, long com) switch (com) { case VMM_IOC_CREATE: case VMM_IOC_INFO: + case VMM_IOC_SHAREMEM: /* The "parent" process in vmd forks and manages VMs */ if (p->p_p->ps_pledge & PLEDGE_PROC) return (0); @@ -780,3 +784,82 @@ vcpu_must_stop(struct vcpu *vcpu) return (1); return (0); } + +/* + * vm_share_mem + * + * Share a uvm mapping for the vm guest memory ranges into the calling process. + * + * Return values: + * 0: if successful + * ENOENT: if the vm cannot be found by vm_find + * EPERM: if the vm cannot be accessed by the current process + * EINVAL: if the provide memory ranges fail checks + * ENOMEM: if uvm_share fails to find available memory in the destination map + */ +int +vm_share_mem(struct vm_sharemem_params *vsp, struct proc *p) +{ + int ret = EINVAL; + size_t i, n; + struct vm *vm; + struct vm_mem_range *src, *dst; + + ret = vm_find(vsp->vsp_vm_id, &vm); + if (ret) + return (ret); + + /* Check we have the expected number of ranges. */ + if (vm->vm_nmemranges != vsp->vsp_nmemranges) + goto out; + n = vm->vm_nmemranges; + + /* Check their types, sizes, and gpa's (implying page alignment). */ + for (i = 0; i < n; i++) { + src = &vm->vm_memranges[i]; + dst = &vsp->vsp_memranges[i]; + + /* + * The vm memranges were already checked during creation, so + * compare to them to confirm validity of mapping request. + */ + if (src->vmr_type != dst->vmr_type) + goto out; + if (src->vmr_gpa != dst->vmr_gpa) + goto out; + if (src->vmr_size != dst->vmr_size) + goto out; + + /* Check our intended destination is page-aligned. */ + if (dst->vmr_va & PAGE_MASK) + goto out; + } + + /* + * Share each range individually with the calling process. We do + * not need PROC_EXEC as the emulated devices do not need to execute + * instructions from guest memory. + */ + for (i = 0; i < n; i++) { + src = &vm->vm_memranges[i]; + dst = &vsp->vsp_memranges[i]; + + /* Skip MMIO range. */ + if (src->vmr_type == VM_MEM_MMIO) + continue; + + DPRINTF("sharing gpa=0x%lx for pid %d @ va=0x%lx\n", + src->vmr_gpa, p->p_p->ps_pid, dst->vmr_va); + ret = uvm_share(&p->p_vmspace->vm_map, dst->vmr_va, + PROT_READ | PROT_WRITE, vm->vm_map, src->vmr_gpa, + src->vmr_size); + if (ret) { + printf("%s: uvm_share failed (%d)\n", __func__, ret); + break; + } + } + ret = 0; +out: + refcnt_rele_wake(&vm->vm_refcnt); + return (ret); +} diff --git a/sys/dev/vmm/vmm.h b/sys/dev/vmm/vmm.h index d2355d42b..38b4a3f85 100644 --- a/sys/dev/vmm/vmm.h +++ b/sys/dev/vmm/vmm.h @@ -1,4 +1,4 @@ -/* $OpenBSD: vmm.h,v 1.2 2023/04/26 16:13:19 mlarkin Exp $ */ +/* $OpenBSD: vmm.h,v 1.3 2023/05/13 23:15:28 dv Exp $ */ /* * Copyright (c) 2014-2023 Mike Larkin * @@ -76,6 +76,13 @@ struct vm_resetcpu_params { struct vcpu_reg_state vrp_init_state; }; +struct vm_sharemem_params { + /* Input parameters to VMM_IOC_SHAREMEM */ + uint32_t vsp_vm_id; + size_t vsp_nmemranges; + struct vm_mem_range vsp_memranges[VMM_MAX_MEM_RANGES]; +}; + /* IOCTL definitions */ #define VMM_IOC_CREATE _IOWR('V', 1, struct vm_create_params) /* Create VM */ #define VMM_IOC_RUN _IOWR('V', 2, struct vm_run_params) /* Run VCPU */ @@ -88,7 +95,7 @@ struct vm_resetcpu_params { #define VMM_IOC_READVMPARAMS _IOWR('V', 9, struct vm_rwvmparams_params) /* Set VM params */ #define VMM_IOC_WRITEVMPARAMS _IOW('V', 10, struct vm_rwvmparams_params) - +#define VMM_IOC_SHAREMEM _IOW('V', 11, struct vm_sharemem_params) #ifdef _KERNEL @@ -194,6 +201,7 @@ int vm_get_info(struct vm_info_params *); int vm_terminate(struct vm_terminate_params *); int vm_resetcpu(struct vm_resetcpu_params *); int vcpu_must_stop(struct vcpu *); +int vm_share_mem(struct vm_sharemem_params *, struct proc *); #endif /* _KERNEL */ #endif /* DEV_VMM_H */ diff --git a/sys/dev/x86emu/x86emu.c b/sys/dev/x86emu/x86emu.c index e521b8121..f6c103b59 100644 --- a/sys/dev/x86emu/x86emu.c +++ b/sys/dev/x86emu/x86emu.c @@ -189,7 +189,7 @@ x86emu_intr_dispatch(struct x86emu *emu, uint8_t intno) } } -static void +static void x86emu_intr_handle(struct x86emu *emu) { uint8_t intno; @@ -204,12 +204,12 @@ x86emu_intr_handle(struct x86emu *emu) /* * PARAMETERS: * intrnum - Interrupt number to raise - * + * * REMARKS: * Raise the specified interrupt to be handled before the execution of the * next instruction. */ -void +void x86emu_intr_raise(struct x86emu *emu, uint8_t intrnum) { emu->x86.intno = intrnum; @@ -222,7 +222,7 @@ x86emu_intr_raise(struct x86emu *emu, uint8_t intrnum) * halts, which is normally caused by a stack fault when we return from the * original real mode call. */ -void +void x86emu_exec(struct x86emu *emu) { emu->x86.intr = 0; @@ -280,7 +280,7 @@ x86emu_exec_intr(struct x86emu *emu, uint8_t intr) * REMARKS: * Halts the system by setting the halted system flag. */ -void +void x86emu_halt_sys(struct x86emu *emu) { #ifdef _KERNEL @@ -295,14 +295,14 @@ x86emu_halt_sys(struct x86emu *emu) * mod - Mod value from decoded byte * regh - Reg h value from decoded byte * regl - Reg l value from decoded byte - * + * * REMARKS: * Raise the specified interrupt to be handled before the execution of the * next instruction. - * + * * NOTE: Do not inline this function, as (*emu->emu_rdb) is already inline! */ -static void +static void fetch_decode_modrm(struct x86emu *emu) { int fetched; @@ -316,14 +316,14 @@ fetch_decode_modrm(struct x86emu *emu) /* * RETURNS: * Immediate byte value read from instruction queue - * + * * REMARKS: * This function returns the immediate byte from the instruction queue, and * moves the instruction pointer to the next value. - * + * * NOTE: Do not inline this function, as (*emu->emu_rdb) is already inline! */ -static uint8_t +static uint8_t fetch_byte_imm(struct x86emu *emu) { uint8_t fetched; @@ -336,14 +336,14 @@ fetch_byte_imm(struct x86emu *emu) /* * RETURNS: * Immediate word value read from instruction queue - * + * * REMARKS: * This function returns the immediate byte from the instruction queue, and * moves the instruction pointer to the next value. - * + * * NOTE: Do not inline this function, as (*emu->emu_rdw) is already inline! */ -static uint16_t +static uint16_t fetch_word_imm(struct x86emu *emu) { uint16_t fetched; @@ -356,14 +356,14 @@ fetch_word_imm(struct x86emu *emu) /* * RETURNS: * Immediate lone value read from instruction queue - * + * * REMARKS: * This function returns the immediate byte from the instruction queue, and * moves the instruction pointer to the next value. - * + * * NOTE: Do not inline this function, as (*emu->emu_rdw) is already inline! */ -static uint32_t +static uint32_t fetch_long_imm(struct x86emu *emu) { uint32_t fetched; @@ -376,33 +376,33 @@ fetch_long_imm(struct x86emu *emu) /* * RETURNS: * Value of the default data segment - * + * * REMARKS: * Inline function that returns the default data segment for the current * instruction. - * + * * On the x86 processor, the default segment is not always DS if there is * no segment override. Address modes such as -3[BP] or 10[BP+SI] all refer to * addresses relative to SS (ie: on the stack). So, at the minimum, all * decodings of addressing modes would have to set/clear a bit describing * whether the access is relative to DS or SS. That is the function of the * cpu-state-variable emu->x86.mode. There are several potential states: - * + * * repe prefix seen (handled elsewhere) * repne prefix seen (ditto) - * + * * cs segment override * ds segment override * es segment override * fs segment override * gs segment override * ss segment override - * + * * ds/ss select (in absense of override) - * + * * Each of the above 7 items are handled with a bit in the mode field. */ -static uint32_t +static uint32_t get_data_segment(struct x86emu *emu) { switch (emu->x86.mode & SYSMODE_SEGMASK) { @@ -434,13 +434,13 @@ get_data_segment(struct x86emu *emu) /* * PARAMETERS: * offset - Offset to load data from - * + * * RETURNS: * Byte value read from the absolute memory location. - * + * * NOTE: Do not inline this function as (*emu->emu_rdX) is already inline! */ -static uint8_t +static uint8_t fetch_data_byte(struct x86emu *emu, uint32_t offset) { return fetch_byte(emu, get_data_segment(emu), offset); @@ -449,13 +449,13 @@ fetch_data_byte(struct x86emu *emu, uint32_t offset) /* * PARAMETERS: * offset - Offset to load data from - * + * * RETURNS: * Word value read from the absolute memory location. - * + * * NOTE: Do not inline this function as (*emu->emu_rdX) is already inline! */ -static uint16_t +static uint16_t fetch_data_word(struct x86emu *emu, uint32_t offset) { return fetch_word(emu, get_data_segment(emu), offset); @@ -464,13 +464,13 @@ fetch_data_word(struct x86emu *emu, uint32_t offset) /* * PARAMETERS: * offset - Offset to load data from - * + * * RETURNS: * Long value read from the absolute memory location. - * + * * NOTE: Do not inline this function as (*emu->emu_rdX) is already inline! */ -static uint32_t +static uint32_t fetch_data_long(struct x86emu *emu, uint32_t offset) { return fetch_long(emu, get_data_segment(emu), offset); @@ -480,13 +480,13 @@ fetch_data_long(struct x86emu *emu, uint32_t offset) * PARAMETERS: * segment - Segment to load data from * offset - Offset to load data from - * + * * RETURNS: * Byte value read from the absolute memory location. - * + * * NOTE: Do not inline this function as (*emu->emu_rdX) is already inline! */ -static uint8_t +static uint8_t fetch_byte(struct x86emu *emu, uint32_t segment, uint32_t offset) { return (*emu->emu_rdb) (emu, ((uint32_t) segment << 4) + offset); @@ -496,13 +496,13 @@ fetch_byte(struct x86emu *emu, uint32_t segment, uint32_t offset) * PARAMETERS: * segment - Segment to load data from * offset - Offset to load data from - * + * * RETURNS: * Word value read from the absolute memory location. - * + * * NOTE: Do not inline this function as (*emu->emu_rdX) is already inline! */ -static uint16_t +static uint16_t fetch_word(struct x86emu *emu, uint32_t segment, uint32_t offset) { return (*emu->emu_rdw) (emu, ((uint32_t) segment << 4) + offset); @@ -512,13 +512,13 @@ fetch_word(struct x86emu *emu, uint32_t segment, uint32_t offset) * PARAMETERS: * segment - Segment to load data from * offset - Offset to load data from - * + * * RETURNS: * Long value read from the absolute memory location. - * + * * NOTE: Do not inline this function as (*emu->emu_rdX) is already inline! */ -static uint32_t +static uint32_t fetch_long(struct x86emu *emu, uint32_t segment, uint32_t offset) { return (*emu->emu_rdl) (emu, ((uint32_t) segment << 4) + offset); @@ -528,14 +528,14 @@ fetch_long(struct x86emu *emu, uint32_t segment, uint32_t offset) * PARAMETERS: * offset - Offset to store data at * val - Value to store - * + * * REMARKS: * Writes a word value to an segmented memory location. The segment used is * the current 'default' segment, which may have been overridden. - * + * * NOTE: Do not inline this function as (*emu->emu_wrX) is already inline! */ -static void +static void store_data_byte(struct x86emu *emu, uint32_t offset, uint8_t val) { store_byte(emu, get_data_segment(emu), offset, val); @@ -545,14 +545,14 @@ store_data_byte(struct x86emu *emu, uint32_t offset, uint8_t val) * PARAMETERS: * offset - Offset to store data at * val - Value to store - * + * * REMARKS: * Writes a word value to an segmented memory location. The segment used is * the current 'default' segment, which may have been overridden. - * + * * NOTE: Do not inline this function as (*emu->emu_wrX) is already inline! */ -static void +static void store_data_word(struct x86emu *emu, uint32_t offset, uint16_t val) { store_word(emu, get_data_segment(emu), offset, val); @@ -562,14 +562,14 @@ store_data_word(struct x86emu *emu, uint32_t offset, uint16_t val) * PARAMETERS: * offset - Offset to store data at * val - Value to store - * + * * REMARKS: * Writes a long value to an segmented memory location. The segment used is * the current 'default' segment, which may have been overridden. - * + * * NOTE: Do not inline this function as (*emu->emu_wrX) is already inline! */ -static void +static void store_data_long(struct x86emu *emu, uint32_t offset, uint32_t val) { store_long(emu, get_data_segment(emu), offset, val); @@ -580,13 +580,13 @@ store_data_long(struct x86emu *emu, uint32_t offset, uint32_t val) * segment - Segment to store data at * offset - Offset to store data at * val - Value to store - * + * * REMARKS: * Writes a byte value to an absolute memory location. - * + * * NOTE: Do not inline this function as (*emu->emu_wrX) is already inline! */ -static void +static void store_byte(struct x86emu *emu, uint32_t segment, uint32_t offset, uint8_t val) { (*emu->emu_wrb) (emu, ((uint32_t) segment << 4) + offset, val); @@ -597,13 +597,13 @@ store_byte(struct x86emu *emu, uint32_t segment, uint32_t offset, uint8_t val) * segment - Segment to store data at * offset - Offset to store data at * val - Value to store - * + * * REMARKS: * Writes a word value to an absolute memory location. - * + * * NOTE: Do not inline this function as (*emu->emu_wrX) is already inline! */ -static void +static void store_word(struct x86emu *emu, uint32_t segment, uint32_t offset, uint16_t val) { (*emu->emu_wrw) (emu, ((uint32_t) segment << 4) + offset, val); @@ -614,13 +614,13 @@ store_word(struct x86emu *emu, uint32_t segment, uint32_t offset, uint16_t val) * segment - Segment to store data at * offset - Offset to store data at * val - Value to store - * + * * REMARKS: * Writes a long value to an absolute memory location. - * + * * NOTE: Do not inline this function as (*emu->emu_wrX) is already inline! */ -static void +static void store_long(struct x86emu *emu, uint32_t segment, uint32_t offset, uint32_t val) { (*emu->emu_wrl) (emu, ((uint32_t) segment << 4) + offset, val); @@ -629,10 +629,10 @@ store_long(struct x86emu *emu, uint32_t segment, uint32_t offset, uint32_t val) /* * PARAMETERS: * reg - Register to decode - * + * * RETURNS: * Pointer to the appropriate register - * + * * REMARKS: * Return a pointer to the register given by the R/RM field of the * modrm byte, for byte operands. Also enables the decoding of instructions. @@ -677,10 +677,10 @@ decode_rh_byte_register(struct x86emu *emu) /* * PARAMETERS: * reg - Register to decode - * + * * RETURNS: * Pointer to the appropriate register - * + * * REMARKS: * Return a pointer to the register given by the R/RM field of the * modrm byte, for word operands. Also enables the decoding of instructions. @@ -725,10 +725,10 @@ decode_rh_word_register(struct x86emu *emu) /* * PARAMETERS: * reg - Register to decode - * + * * RETURNS: * Pointer to the appropriate register - * + * * REMARKS: * Return a pointer to the register given by the R/RM field of the * modrm byte, for dword operands. Also enables the decoding of instructions. @@ -774,10 +774,10 @@ decode_rh_long_register(struct x86emu *emu) /* * PARAMETERS: * reg - Register to decode - * + * * RETURNS: * Pointer to the appropriate register - * + * * REMARKS: * Return a pointer to the register given by the R/RM field of the * modrm byte, for word operands, modified from above for the weirdo @@ -807,7 +807,7 @@ decode_rh_seg_register(struct x86emu *emu) /* * Return offset from the SIB Byte. */ -static uint32_t +static uint32_t decode_sib_address(struct x86emu *emu, int sib, int mod) { uint32_t base = 0, i = 0, scale = 1; @@ -878,10 +878,10 @@ decode_sib_address(struct x86emu *emu, int sib, int mod) /* * PARAMETERS: * rm - RM value to decode - * + * * RETURNS: * Offset in memory for the address decoding - * + * * REMARKS: * Return the offset given by mod=00, mod=01 or mod=10 addressing. * Also enables the decoding of instructions. @@ -1114,7 +1114,7 @@ common_dec_word_long(struct x86emu *emu, union x86emu_register *reg) } static void -common_binop_byte_rm_r(struct x86emu *emu, +common_binop_byte_rm_r(struct x86emu *emu, uint8_t (*binop)(struct x86emu *, uint8_t, uint8_t)) { uint32_t destoffset; @@ -1135,7 +1135,7 @@ common_binop_byte_rm_r(struct x86emu *emu, } static void -common_binop_ns_byte_rm_r(struct x86emu *emu, +common_binop_ns_byte_rm_r(struct x86emu *emu, void (*binop)(struct x86emu *, uint8_t, uint8_t)) { uint32_t destoffset; @@ -1484,7 +1484,7 @@ x86emuOp_cmp_byte_R_RM(struct x86emu *emu) /* * REMARKS: - * + * * Handles opcode 0x3b */ static void @@ -2440,7 +2440,7 @@ x86emuOp_call_far_IMM(struct x86emu *emu) faroff = fetch_word_imm(emu); farseg = fetch_word_imm(emu); /* XXX - * + * * Hooked interrupt vectors calling into our "BIOS" will cause problems * unless all intersegment stuff is checked for BIOS access. Check * needed here. For moment, let it alone. */ @@ -2829,7 +2829,7 @@ x86emuOp_stos_word(struct x86emu *emu) inc = 4; else inc = 2; - + if (ACCESS_FLAG(F_DF)) /* down */ inc = -inc; @@ -3565,12 +3565,12 @@ x86emuOp_xlat(struct x86emu *emu) } /* opcode=0xd8 */ -static void +static void x86emuOp_esc_coprocess_d8(struct x86emu *emu) { } /* opcode=0xd9 */ -static void +static void x86emuOp_esc_coprocess_d9(struct x86emu *emu) { fetch_decode_modrm(emu); @@ -3578,7 +3578,7 @@ x86emuOp_esc_coprocess_d9(struct x86emu *emu) decode_rl_address(emu); } /* opcode=0xda */ -static void +static void x86emuOp_esc_coprocess_da(struct x86emu *emu) { fetch_decode_modrm(emu); @@ -3586,7 +3586,7 @@ x86emuOp_esc_coprocess_da(struct x86emu *emu) decode_rl_address(emu); } /* opcode=0xdb */ -static void +static void x86emuOp_esc_coprocess_db(struct x86emu *emu) { fetch_decode_modrm(emu); @@ -3594,7 +3594,7 @@ x86emuOp_esc_coprocess_db(struct x86emu *emu) decode_rl_address(emu); } /* opcode=0xdc */ -static void +static void x86emuOp_esc_coprocess_dc(struct x86emu *emu) { fetch_decode_modrm(emu); @@ -3602,7 +3602,7 @@ x86emuOp_esc_coprocess_dc(struct x86emu *emu) decode_rl_address(emu); } /* opcode=0xdd */ -static void +static void x86emuOp_esc_coprocess_dd(struct x86emu *emu) { fetch_decode_modrm(emu); @@ -3610,7 +3610,7 @@ x86emuOp_esc_coprocess_dd(struct x86emu *emu) decode_rl_address(emu); } /* opcode=0xde */ -static void +static void x86emuOp_esc_coprocess_de(struct x86emu *emu) { fetch_decode_modrm(emu); @@ -3618,7 +3618,7 @@ x86emuOp_esc_coprocess_de(struct x86emu *emu) decode_rl_address(emu); } /* opcode=0xdf */ -static void +static void x86emuOp_esc_coprocess_df(struct x86emu *emu) { fetch_decode_modrm(emu); @@ -5742,7 +5742,7 @@ x86emu_exec_two_byte(struct x86emu * emu) || ACCESS_FLAG(F_ZF))); break; case 0x8f: - common_jmp_long(emu, + common_jmp_long(emu, !(xorl(ACCESS_FLAG(F_SF), ACCESS_FLAG(F_OF)) || ACCESS_FLAG(F_ZF))); break; @@ -5981,7 +5981,7 @@ static uint32_t x86emu_parity_tab[8] = * REMARKS: * Implements the AAA instruction and side effects. */ -static uint16_t +static uint16_t aaa_word(struct x86emu *emu, uint16_t d) { uint16_t res; @@ -6005,7 +6005,7 @@ aaa_word(struct x86emu *emu, uint16_t d) * REMARKS: * Implements the AAA instruction and side effects. */ -static uint16_t +static uint16_t aas_word(struct x86emu *emu, uint16_t d) { uint16_t res; @@ -6029,7 +6029,7 @@ aas_word(struct x86emu *emu, uint16_t d) * REMARKS: * Implements the AAD instruction and side effects. */ -static uint16_t +static uint16_t aad_word(struct x86emu *emu, uint16_t d) { uint16_t l; @@ -6052,7 +6052,7 @@ aad_word(struct x86emu *emu, uint16_t d) * REMARKS: * Implements the AAM instruction and side effects. */ -static uint16_t +static uint16_t aam_word(struct x86emu *emu, uint8_t d) { uint16_t h, l; @@ -6074,7 +6074,7 @@ aam_word(struct x86emu *emu, uint8_t d) * REMARKS: * Implements the ADC instruction and side effects. */ -static uint8_t +static uint8_t adc_byte(struct x86emu *emu, uint8_t d, uint8_t s) { uint32_t res; /* all operands in native machine order */ @@ -6101,7 +6101,7 @@ adc_byte(struct x86emu *emu, uint8_t d, uint8_t s) * REMARKS: * Implements the ADC instruction and side effects. */ -static uint16_t +static uint16_t adc_word(struct x86emu *emu, uint16_t d, uint16_t s) { uint32_t res; /* all operands in native machine order */ @@ -6128,7 +6128,7 @@ adc_word(struct x86emu *emu, uint16_t d, uint16_t s) * REMARKS: * Implements the ADC instruction and side effects. */ -static uint32_t +static uint32_t adc_long(struct x86emu *emu, uint32_t d, uint32_t s) { uint32_t lo; /* all operands in native machine order */ @@ -6161,7 +6161,7 @@ adc_long(struct x86emu *emu, uint32_t d, uint32_t s) * REMARKS: * Implements the ADD instruction and side effects. */ -static uint8_t +static uint8_t add_byte(struct x86emu *emu, uint8_t d, uint8_t s) { uint32_t res; /* all operands in native machine order */ @@ -6184,7 +6184,7 @@ add_byte(struct x86emu *emu, uint8_t d, uint8_t s) * REMARKS: * Implements the ADD instruction and side effects. */ -static uint16_t +static uint16_t add_word(struct x86emu *emu, uint16_t d, uint16_t s) { uint32_t res; /* all operands in native machine order */ @@ -6207,7 +6207,7 @@ add_word(struct x86emu *emu, uint16_t d, uint16_t s) * REMARKS: * Implements the ADD instruction and side effects. */ -static uint32_t +static uint32_t add_long(struct x86emu *emu, uint32_t d, uint32_t s) { uint32_t lo; /* all operands in native machine order */ @@ -6236,7 +6236,7 @@ add_long(struct x86emu *emu, uint32_t d, uint32_t s) * REMARKS: * Implements the AND instruction and side effects. */ -static uint8_t +static uint8_t and_byte(struct x86emu *emu, uint8_t d, uint8_t s) { uint8_t res; /* all operands in native machine order */ @@ -6257,7 +6257,7 @@ and_byte(struct x86emu *emu, uint8_t d, uint8_t s) * REMARKS: * Implements the AND instruction and side effects. */ -static uint16_t +static uint16_t and_word(struct x86emu *emu, uint16_t d, uint16_t s) { uint16_t res; /* all operands in native machine order */ @@ -6278,7 +6278,7 @@ and_word(struct x86emu *emu, uint16_t d, uint16_t s) * REMARKS: * Implements the AND instruction and side effects. */ -static uint32_t +static uint32_t and_long(struct x86emu *emu, uint32_t d, uint32_t s) { uint32_t res; /* all operands in native machine order */ @@ -6299,7 +6299,7 @@ and_long(struct x86emu *emu, uint32_t d, uint32_t s) * REMARKS: * Implements the CMP instruction and side effects. */ -static uint8_t +static uint8_t cmp_byte(struct x86emu *emu, uint8_t d, uint8_t s) { uint32_t res; /* all operands in native machine order */ @@ -6319,7 +6319,7 @@ cmp_byte(struct x86emu *emu, uint8_t d, uint8_t s) return d; } -static void +static void cmp_byte_no_return(struct x86emu *emu, uint8_t d, uint8_t s) { cmp_byte(emu, d, s); @@ -6329,7 +6329,7 @@ cmp_byte_no_return(struct x86emu *emu, uint8_t d, uint8_t s) * REMARKS: * Implements the CMP instruction and side effects. */ -static uint16_t +static uint16_t cmp_word(struct x86emu *emu, uint16_t d, uint16_t s) { uint32_t res; /* all operands in native machine order */ @@ -6348,7 +6348,7 @@ cmp_word(struct x86emu *emu, uint16_t d, uint16_t s) return d; } -static void +static void cmp_word_no_return(struct x86emu *emu, uint16_t d, uint16_t s) { cmp_word(emu, d, s); @@ -6358,7 +6358,7 @@ cmp_word_no_return(struct x86emu *emu, uint16_t d, uint16_t s) * REMARKS: * Implements the CMP instruction and side effects. */ -static uint32_t +static uint32_t cmp_long(struct x86emu *emu, uint32_t d, uint32_t s) { uint32_t res; /* all operands in native machine order */ @@ -6377,7 +6377,7 @@ cmp_long(struct x86emu *emu, uint32_t d, uint32_t s) return d; } -static void +static void cmp_long_no_return(struct x86emu *emu, uint32_t d, uint32_t s) { cmp_long(emu, d, s); @@ -6387,7 +6387,7 @@ cmp_long_no_return(struct x86emu *emu, uint32_t d, uint32_t s) * REMARKS: * Implements the DAA instruction and side effects. */ -static uint8_t +static uint8_t daa_byte(struct x86emu *emu, uint8_t d) { uint32_t res = d; @@ -6409,7 +6409,7 @@ daa_byte(struct x86emu *emu, uint8_t d) * REMARKS: * Implements the DAS instruction and side effects. */ -static uint8_t +static uint8_t das_byte(struct x86emu *emu, uint8_t d) { if ((d & 0xf) > 9 || ACCESS_FLAG(F_AF)) { @@ -6430,7 +6430,7 @@ das_byte(struct x86emu *emu, uint8_t d) * REMARKS: * Implements the DEC instruction and side effects. */ -static uint8_t +static uint8_t dec_byte(struct x86emu *emu, uint8_t d) { uint32_t res; /* all operands in native machine order */ @@ -6454,7 +6454,7 @@ dec_byte(struct x86emu *emu, uint8_t d) * REMARKS: * Implements the DEC instruction and side effects. */ -static uint16_t +static uint16_t dec_word(struct x86emu *emu, uint16_t d) { uint32_t res; /* all operands in native machine order */ @@ -6478,7 +6478,7 @@ dec_word(struct x86emu *emu, uint16_t d) * REMARKS: * Implements the DEC instruction and side effects. */ -static uint32_t +static uint32_t dec_long(struct x86emu *emu, uint32_t d) { uint32_t res; /* all operands in native machine order */ @@ -6502,7 +6502,7 @@ dec_long(struct x86emu *emu, uint32_t d) * REMARKS: * Implements the INC instruction and side effects. */ -static uint8_t +static uint8_t inc_byte(struct x86emu *emu, uint8_t d) { uint32_t res; /* all operands in native machine order */ @@ -6524,7 +6524,7 @@ inc_byte(struct x86emu *emu, uint8_t d) * REMARKS: * Implements the INC instruction and side effects. */ -static uint16_t +static uint16_t inc_word(struct x86emu *emu, uint16_t d) { uint32_t res; /* all operands in native machine order */ @@ -6546,7 +6546,7 @@ inc_word(struct x86emu *emu, uint16_t d) * REMARKS: * Implements the INC instruction and side effects. */ -static uint32_t +static uint32_t inc_long(struct x86emu *emu, uint32_t d) { uint32_t res; /* all operands in native machine order */ @@ -6568,7 +6568,7 @@ inc_long(struct x86emu *emu, uint32_t d) * REMARKS: * Implements the OR instruction and side effects. */ -static uint8_t +static uint8_t or_byte(struct x86emu *emu, uint8_t d, uint8_t s) { uint8_t res; /* all operands in native machine order */ @@ -6587,7 +6587,7 @@ or_byte(struct x86emu *emu, uint8_t d, uint8_t s) * REMARKS: * Implements the OR instruction and side effects. */ -static uint16_t +static uint16_t or_word(struct x86emu *emu, uint16_t d, uint16_t s) { uint16_t res; /* all operands in native machine order */ @@ -6607,7 +6607,7 @@ or_word(struct x86emu *emu, uint16_t d, uint16_t s) * REMARKS: * Implements the OR instruction and side effects. */ -static uint32_t +static uint32_t or_long(struct x86emu *emu, uint32_t d, uint32_t s) { uint32_t res; /* all operands in native machine order */ @@ -6628,7 +6628,7 @@ or_long(struct x86emu *emu, uint32_t d, uint32_t s) * REMARKS: * Implements the OR instruction and side effects. */ -static uint8_t +static uint8_t neg_byte(struct x86emu *emu, uint8_t s) { uint8_t res; @@ -6654,7 +6654,7 @@ neg_byte(struct x86emu *emu, uint8_t s) * REMARKS: * Implements the OR instruction and side effects. */ -static uint16_t +static uint16_t neg_word(struct x86emu *emu, uint16_t s) { uint16_t res; @@ -6681,7 +6681,7 @@ neg_word(struct x86emu *emu, uint16_t s) * REMARKS: * Implements the OR instruction and side effects. */ -static uint32_t +static uint32_t neg_long(struct x86emu *emu, uint32_t s) { uint32_t res; @@ -6708,29 +6708,29 @@ neg_long(struct x86emu *emu, uint32_t s) * REMARKS: * Implements the RCL instruction and side effects. */ -static uint8_t +static uint8_t rcl_byte(struct x86emu *emu, uint8_t d, uint8_t s) { unsigned int res, cnt, mask, cf; /* s is the rotate distance. It varies from 0 - 8. */ /* have - * + * * CF B_7 B_6 B_5 B_4 B_3 B_2 B_1 B_0 - * + * * want to rotate through the carry by "s" bits. We could loop, but * that's inefficient. So the width is 9, and we split into three * parts: - * + * * The new carry flag (was B_n) the stuff in B_n-1 .. B_0 the stuff * in B_7 .. B_n+1 - * + * * The new rotate is done mod 9, and given this, for a rotation of n * bits (mod 9) the new carry flag is then located n bits from the MSB. * The low part is then shifted up cnt bits, and the high part is or'd * in. Using CAPS for new values, and lowercase for the original * values, this can be expressed as: - * + * * IF n > 0 1) CF <- b_(8-n) 2) B_(7) .. B_(n) <- b_(8-(n+1)) .. b_0 * 3) B_(n-1) <- cf 4) B_(n-2) .. B_0 <- b_7 .. b_(8-(n-1)) */ @@ -6740,14 +6740,14 @@ rcl_byte(struct x86emu *emu, uint8_t d, uint8_t s) /* CF <- b_(8-n) */ cf = (d >> (8 - cnt)) & 0x1; - /* + /* * Get the low stuff which rotated into the range B_7 .. B_cnt * B_(7) .. B_(n) <- b_(8-(n+1)) .. b_0 * note that the right hand side done by the mask. */ res = (d << cnt) & 0xff; - /* + /* * now the high stuff which rotated around into the positions * B_cnt-2 .. B_0 * B_(n-2) .. B_0 <- b_7 .. b_(8-(n-1)) @@ -6779,7 +6779,7 @@ rcl_byte(struct x86emu *emu, uint8_t d, uint8_t s) * REMARKS: * Implements the RCL instruction and side effects. */ -static uint16_t +static uint16_t rcl_word(struct x86emu *emu, uint16_t d, uint8_t s) { unsigned int res, cnt, mask, cf; @@ -6804,7 +6804,7 @@ rcl_word(struct x86emu *emu, uint16_t d, uint8_t s) * REMARKS: * Implements the RCL instruction and side effects. */ -static uint32_t +static uint32_t rcl_long(struct x86emu *emu, uint32_t d, uint8_t s) { uint32_t res, cnt, mask, cf; @@ -6829,7 +6829,7 @@ rcl_long(struct x86emu *emu, uint32_t d, uint8_t s) * REMARKS: * Implements the RCR instruction and side effects. */ -static uint8_t +static uint8_t rcr_byte(struct x86emu *emu, uint8_t d, uint8_t s) { uint32_t res, cnt; @@ -6838,19 +6838,19 @@ rcr_byte(struct x86emu *emu, uint8_t d, uint8_t s) /* rotate right through carry */ /* s is the rotate distance. It varies from 0 - 8. d is the byte * object rotated. - * + * * have - * + * * CF B_7 B_6 B_5 B_4 B_3 B_2 B_1 B_0 - * + * * The new rotate is done mod 9, and given this, for a rotation of n * bits (mod 9) the new carry flag is then located n bits from the LSB. * The low part is then shifted up cnt bits, and the high part is or'd * in. Using CAPS for new values, and lowercase for the original * values, this can be expressed as: - * - * IF n > 0 - * 1) CF <- b_(n-1) + * + * IF n > 0 + * 1) CF <- b_(n-1) * 2) B_(8-(n+1)) .. B_(0) <- b_(7) .. b_(n) * 3) B_(8-n) <- cf 4) B_(7) .. B_(8-(n-1)) <- b_(n-2) .. b_(0) */ @@ -6907,7 +6907,7 @@ rcr_byte(struct x86emu *emu, uint8_t d, uint8_t s) * REMARKS: * Implements the RCR instruction and side effects. */ -static uint16_t +static uint16_t rcr_word(struct x86emu *emu, uint16_t d, uint8_t s) { uint32_t res, cnt; @@ -6940,7 +6940,7 @@ rcr_word(struct x86emu *emu, uint16_t d, uint8_t s) * REMARKS: * Implements the RCR instruction and side effects. */ -static uint32_t +static uint32_t rcr_long(struct x86emu *emu, uint32_t d, uint8_t s) { uint32_t res, cnt; @@ -6974,7 +6974,7 @@ rcr_long(struct x86emu *emu, uint32_t d, uint8_t s) * REMARKS: * Implements the ROL instruction and side effects. */ -static uint8_t +static uint8_t rol_byte(struct x86emu *emu, uint8_t d, uint8_t s) { unsigned int res, cnt, mask; @@ -6982,14 +6982,14 @@ rol_byte(struct x86emu *emu, uint8_t d, uint8_t s) /* rotate left */ /* s is the rotate distance. It varies from 0 - 8. d is the byte * object rotated. - * + * * have - * + * * CF B_7 ... B_0 - * + * * The new rotate is done mod 8. Much simpler than the "rcl" or "rcr" * operations. - * + * * IF n > 0 1) B_(7) .. B_(n) <- b_(8-(n+1)) .. b_(0) 2) B_(n-1) .. * B_(0) <- b_(7) .. b_(8-n) */ res = d; @@ -7021,7 +7021,7 @@ rol_byte(struct x86emu *emu, uint8_t d, uint8_t s) * REMARKS: * Implements the ROL instruction and side effects. */ -static uint16_t +static uint16_t rol_word(struct x86emu *emu, uint16_t d, uint8_t s) { unsigned int res, cnt, mask; @@ -7047,7 +7047,7 @@ rol_word(struct x86emu *emu, uint16_t d, uint8_t s) * REMARKS: * Implements the ROL instruction and side effects. */ -static uint32_t +static uint32_t rol_long(struct x86emu *emu, uint32_t d, uint8_t s) { uint32_t res, cnt, mask; @@ -7073,7 +7073,7 @@ rol_long(struct x86emu *emu, uint32_t d, uint8_t s) * REMARKS: * Implements the ROR instruction and side effects. */ -static uint8_t +static uint8_t ror_byte(struct x86emu *emu, uint8_t d, uint8_t s) { unsigned int res, cnt, mask; @@ -7081,13 +7081,13 @@ ror_byte(struct x86emu *emu, uint8_t d, uint8_t s) /* rotate right */ /* s is the rotate distance. It varies from 0 - 8. d is the byte * object rotated. - * + * * have - * + * * B_7 ... B_0 - * + * * The rotate is done mod 8. - * + * * IF n > 0 1) B_(8-(n+1)) .. B_(0) <- b_(7) .. b_(n) 2) B_(7) .. * B_(8-n) <- b_(n-1) .. b_(0) */ res = d; @@ -7117,7 +7117,7 @@ ror_byte(struct x86emu *emu, uint8_t d, uint8_t s) * REMARKS: * Implements the ROR instruction and side effects. */ -static uint16_t +static uint16_t ror_word(struct x86emu *emu, uint16_t d, uint8_t s) { unsigned int res, cnt, mask; @@ -7141,7 +7141,7 @@ ror_word(struct x86emu *emu, uint16_t d, uint8_t s) * REMARKS: * Implements the ROR instruction and side effects. */ -static uint32_t +static uint32_t ror_long(struct x86emu *emu, uint32_t d, uint8_t s) { uint32_t res, cnt, mask; @@ -7165,7 +7165,7 @@ ror_long(struct x86emu *emu, uint32_t d, uint8_t s) * REMARKS: * Implements the SHL instruction and side effects. */ -static uint8_t +static uint8_t shl_byte(struct x86emu *emu, uint8_t d, uint8_t s) { unsigned int cnt, res, cf; @@ -7210,7 +7210,7 @@ shl_byte(struct x86emu *emu, uint8_t d, uint8_t s) * REMARKS: * Implements the SHL instruction and side effects. */ -static uint16_t +static uint16_t shl_word(struct x86emu *emu, uint16_t d, uint8_t s) { unsigned int cnt, res, cf; @@ -7251,7 +7251,7 @@ shl_word(struct x86emu *emu, uint16_t d, uint8_t s) * REMARKS: * Implements the SHL instruction and side effects. */ -static uint32_t +static uint32_t shl_long(struct x86emu *emu, uint32_t d, uint8_t s) { unsigned int cnt, res, cf; @@ -7289,7 +7289,7 @@ shl_long(struct x86emu *emu, uint32_t d, uint8_t s) * REMARKS: * Implements the SHR instruction and side effects. */ -static uint8_t +static uint8_t shr_byte(struct x86emu *emu, uint8_t d, uint8_t s) { unsigned int cnt, res, cf; @@ -7327,7 +7327,7 @@ shr_byte(struct x86emu *emu, uint8_t d, uint8_t s) * REMARKS: * Implements the SHR instruction and side effects. */ -static uint16_t +static uint16_t shr_word(struct x86emu *emu, uint16_t d, uint8_t s) { unsigned int cnt, res, cf; @@ -7365,7 +7365,7 @@ shr_word(struct x86emu *emu, uint16_t d, uint8_t s) * REMARKS: * Implements the SHR instruction and side effects. */ -static uint32_t +static uint32_t shr_long(struct x86emu *emu, uint32_t d, uint8_t s) { unsigned int cnt, res, cf; @@ -7402,7 +7402,7 @@ shr_long(struct x86emu *emu, uint32_t d, uint8_t s) * REMARKS: * Implements the SAR instruction and side effects. */ -static uint8_t +static uint8_t sar_byte(struct x86emu *emu, uint8_t d, uint8_t s) { unsigned int cnt, res, cf, mask, sf; @@ -7443,7 +7443,7 @@ sar_byte(struct x86emu *emu, uint8_t d, uint8_t s) * REMARKS: * Implements the SAR instruction and side effects. */ -static uint16_t +static uint16_t sar_word(struct x86emu *emu, uint16_t d, uint8_t s) { unsigned int cnt, res, cf, mask, sf; @@ -7484,7 +7484,7 @@ sar_word(struct x86emu *emu, uint16_t d, uint8_t s) * REMARKS: * Implements the SAR instruction and side effects. */ -static uint32_t +static uint32_t sar_long(struct x86emu *emu, uint32_t d, uint8_t s) { uint32_t cnt, res, cf, mask, sf; @@ -7525,7 +7525,7 @@ sar_long(struct x86emu *emu, uint32_t d, uint8_t s) * REMARKS: * Implements the SHLD instruction and side effects. */ -static uint16_t +static uint16_t shld_word(struct x86emu *emu, uint16_t d, uint16_t fill, uint8_t s) { unsigned int cnt, res, cf; @@ -7563,7 +7563,7 @@ shld_word(struct x86emu *emu, uint16_t d, uint16_t fill, uint8_t s) * REMARKS: * Implements the SHLD instruction and side effects. */ -static uint32_t +static uint32_t shld_long(struct x86emu *emu, uint32_t d, uint32_t fill, uint8_t s) { unsigned int cnt, res, cf; @@ -7601,7 +7601,7 @@ shld_long(struct x86emu *emu, uint32_t d, uint32_t fill, uint8_t s) * REMARKS: * Implements the SHRD instruction and side effects. */ -static uint16_t +static uint16_t shrd_word(struct x86emu *emu, uint16_t d, uint16_t fill, uint8_t s) { unsigned int cnt, res, cf; @@ -7639,7 +7639,7 @@ shrd_word(struct x86emu *emu, uint16_t d, uint16_t fill, uint8_t s) * REMARKS: * Implements the SHRD instruction and side effects. */ -static uint32_t +static uint32_t shrd_long(struct x86emu *emu, uint32_t d, uint32_t fill, uint8_t s) { unsigned int cnt, res, cf; @@ -7676,7 +7676,7 @@ shrd_long(struct x86emu *emu, uint32_t d, uint32_t fill, uint8_t s) * REMARKS: * Implements the SBB instruction and side effects. */ -static uint8_t +static uint8_t sbb_byte(struct x86emu *emu, uint8_t d, uint8_t s) { uint32_t res; /* all operands in native machine order */ @@ -7702,7 +7702,7 @@ sbb_byte(struct x86emu *emu, uint8_t d, uint8_t s) * REMARKS: * Implements the SBB instruction and side effects. */ -static uint16_t +static uint16_t sbb_word(struct x86emu *emu, uint16_t d, uint16_t s) { uint32_t res; /* all operands in native machine order */ @@ -7728,7 +7728,7 @@ sbb_word(struct x86emu *emu, uint16_t d, uint16_t s) * REMARKS: * Implements the SBB instruction and side effects. */ -static uint32_t +static uint32_t sbb_long(struct x86emu *emu, uint32_t d, uint32_t s) { uint32_t res; /* all operands in native machine order */ @@ -7754,7 +7754,7 @@ sbb_long(struct x86emu *emu, uint32_t d, uint32_t s) * REMARKS: * Implements the SUB instruction and side effects. */ -static uint8_t +static uint8_t sub_byte(struct x86emu *emu, uint8_t d, uint8_t s) { uint32_t res; /* all operands in native machine order */ @@ -7777,7 +7777,7 @@ sub_byte(struct x86emu *emu, uint8_t d, uint8_t s) * REMARKS: * Implements the SUB instruction and side effects. */ -static uint16_t +static uint16_t sub_word(struct x86emu *emu, uint16_t d, uint16_t s) { uint32_t res; /* all operands in native machine order */ @@ -7800,7 +7800,7 @@ sub_word(struct x86emu *emu, uint16_t d, uint16_t s) * REMARKS: * Implements the SUB instruction and side effects. */ -static uint32_t +static uint32_t sub_long(struct x86emu *emu, uint32_t d, uint32_t s) { uint32_t res; /* all operands in native machine order */ @@ -7823,7 +7823,7 @@ sub_long(struct x86emu *emu, uint32_t d, uint32_t s) * REMARKS: * Implements the TEST instruction and side effects. */ -static void +static void test_byte(struct x86emu *emu, uint8_t d, uint8_t s) { uint32_t res; /* all operands in native machine order */ @@ -7842,7 +7842,7 @@ test_byte(struct x86emu *emu, uint8_t d, uint8_t s) * REMARKS: * Implements the TEST instruction and side effects. */ -static void +static void test_word(struct x86emu *emu, uint16_t d, uint16_t s) { uint32_t res; /* all operands in native machine order */ @@ -7861,7 +7861,7 @@ test_word(struct x86emu *emu, uint16_t d, uint16_t s) * REMARKS: * Implements the TEST instruction and side effects. */ -static void +static void test_long(struct x86emu *emu, uint32_t d, uint32_t s) { uint32_t res; /* all operands in native machine order */ @@ -7880,7 +7880,7 @@ test_long(struct x86emu *emu, uint32_t d, uint32_t s) * REMARKS: * Implements the XOR instruction and side effects. */ -static uint8_t +static uint8_t xor_byte(struct x86emu *emu, uint8_t d, uint8_t s) { uint8_t res; /* all operands in native machine order */ @@ -7899,7 +7899,7 @@ xor_byte(struct x86emu *emu, uint8_t d, uint8_t s) * REMARKS: * Implements the XOR instruction and side effects. */ -static uint16_t +static uint16_t xor_word(struct x86emu *emu, uint16_t d, uint16_t s) { uint16_t res; /* all operands in native machine order */ @@ -7918,7 +7918,7 @@ xor_word(struct x86emu *emu, uint16_t d, uint16_t s) * REMARKS: * Implements the XOR instruction and side effects. */ -static uint32_t +static uint32_t xor_long(struct x86emu *emu, uint32_t d, uint32_t s) { uint32_t res; /* all operands in native machine order */ @@ -7937,7 +7937,7 @@ xor_long(struct x86emu *emu, uint32_t d, uint32_t s) * REMARKS: * Implements the IMUL instruction and side effects. */ -static void +static void imul_byte(struct x86emu *emu, uint8_t s) { int16_t res = (int16_t) ((int8_t) emu->x86.R_AL * (int8_t) s); @@ -7957,7 +7957,7 @@ imul_byte(struct x86emu *emu, uint8_t s) * REMARKS: * Implements the IMUL instruction and side effects. */ -static void +static void imul_word(struct x86emu *emu, uint16_t s) { int32_t res = (int16_t) emu->x86.R_AX * (int16_t) s; @@ -7978,11 +7978,11 @@ imul_word(struct x86emu *emu, uint16_t s) * REMARKS: * Implements the IMUL instruction and side effects. */ -static void +static void imul_long(struct x86emu *emu, uint32_t s) { int64_t res; - + res = (int64_t)(int32_t)emu->x86.R_EAX * (int32_t)s; emu->x86.R_EAX = (uint32_t)res; emu->x86.R_EDX = ((uint64_t)res) >> 32; @@ -8000,7 +8000,7 @@ imul_long(struct x86emu *emu, uint32_t s) * REMARKS: * Implements the MUL instruction and side effects. */ -static void +static void mul_byte(struct x86emu *emu, uint8_t s) { uint16_t res = (uint16_t) (emu->x86.R_AL * s); @@ -8019,7 +8019,7 @@ mul_byte(struct x86emu *emu, uint8_t s) * REMARKS: * Implements the MUL instruction and side effects. */ -static void +static void mul_word(struct x86emu *emu, uint16_t s) { uint32_t res = emu->x86.R_AX * s; @@ -8039,7 +8039,7 @@ mul_word(struct x86emu *emu, uint16_t s) * REMARKS: * Implements the MUL instruction and side effects. */ -static void +static void mul_long(struct x86emu *emu, uint32_t s) { uint64_t res = (uint64_t) emu->x86.R_EAX * s; @@ -8060,7 +8060,7 @@ mul_long(struct x86emu *emu, uint32_t s) * REMARKS: * Implements the IDIV instruction and side effects. */ -static void +static void idiv_byte(struct x86emu *emu, uint8_t s) { int32_t dvd, div, mod; @@ -8084,7 +8084,7 @@ idiv_byte(struct x86emu *emu, uint8_t s) * REMARKS: * Implements the IDIV instruction and side effects. */ -static void +static void idiv_word(struct x86emu *emu, uint16_t s) { int32_t dvd, div, mod; @@ -8113,7 +8113,7 @@ idiv_word(struct x86emu *emu, uint16_t s) * REMARKS: * Implements the IDIV instruction and side effects. */ -static void +static void idiv_long(struct x86emu *emu, uint32_t s) { int64_t dvd, div, mod; @@ -8143,7 +8143,7 @@ idiv_long(struct x86emu *emu, uint32_t s) * REMARKS: * Implements the DIV instruction and side effects. */ -static void +static void div_byte(struct x86emu *emu, uint8_t s) { uint32_t dvd, div, mod; @@ -8167,7 +8167,7 @@ div_byte(struct x86emu *emu, uint8_t s) * REMARKS: * Implements the DIV instruction and side effects. */ -static void +static void div_word(struct x86emu *emu, uint16_t s) { uint32_t dvd, div, mod; @@ -8196,7 +8196,7 @@ div_word(struct x86emu *emu, uint16_t s) * REMARKS: * Implements the DIV instruction and side effects. */ -static void +static void div_long(struct x86emu *emu, uint32_t s) { uint64_t dvd, div, mod; @@ -8226,7 +8226,7 @@ div_long(struct x86emu *emu, uint32_t s) * REMARKS: * Implements the IN string instruction and side effects. */ -static void +static void ins(struct x86emu *emu, int size) { int inc = size; @@ -8291,7 +8291,7 @@ ins(struct x86emu *emu, int size) * REMARKS: * Implements the OUT string instruction and side effects. */ -static void +static void outs(struct x86emu *emu, int size) { int inc = size; @@ -8358,10 +8358,10 @@ outs(struct x86emu *emu, int size) /* * REMARKS: * Pushes a word onto the stack. - * + * * NOTE: Do not inline this, as (*emu->emu_wrX) is already inline! */ -static void +static void push_word(struct x86emu *emu, uint16_t w) { emu->x86.R_SP -= 2; @@ -8371,10 +8371,10 @@ push_word(struct x86emu *emu, uint16_t w) /* * REMARKS: * Pushes a long onto the stack. - * + * * NOTE: Do not inline this, as (*emu->emu_wrX) is already inline! */ -static void +static void push_long(struct x86emu *emu, uint32_t w) { emu->x86.R_SP -= 4; @@ -8384,10 +8384,10 @@ push_long(struct x86emu *emu, uint32_t w) /* * REMARKS: * Pops a word from the stack. - * + * * NOTE: Do not inline this, as (*emu->emu_rdX) is already inline! */ -static uint16_t +static uint16_t pop_word(struct x86emu *emu) { uint16_t res; @@ -8400,10 +8400,10 @@ pop_word(struct x86emu *emu) /* * REMARKS: * Pops a long from the stack. - * + * * NOTE: Do not inline this, as (*emu->emu_rdX) is already inline! */ -static uint32_t +static uint32_t pop_long(struct x86emu *emu) { uint32_t res; diff --git a/sys/dev/x86emu/x86emu.h b/sys/dev/x86emu/x86emu.h index 4fd0f8a39..6f5fc3ff4 100644 --- a/sys/dev/x86emu/x86emu.h +++ b/sys/dev/x86emu/x86emu.h @@ -123,8 +123,8 @@ struct x86emu_regs { * Delayed flag set 3 bits (zero, signed, parity) * reserved 6 bits * interrupt # 8 bits instruction raised interrupt - * BIOS video segregs 4 bits - * Interrupt Pending 1 bits + * BIOS video segregs 4 bits + * Interrupt Pending 1 bits * Extern interrupt 1 bits * Halted 1 bits */ diff --git a/sys/dev/x86emu/x86emu_util.c b/sys/dev/x86emu/x86emu_util.c index 182a774e3..0740f88ee 100644 --- a/sys/dev/x86emu/x86emu_util.c +++ b/sys/dev/x86emu/x86emu_util.c @@ -42,10 +42,10 @@ /* * PARAMETERS: * addr - Emulator memory address to read - * + * * RETURNS: * Byte value read from emulator memory. - * + * * REMARKS: * Reads a byte value from the emulator memory. */ @@ -60,10 +60,10 @@ rdb(struct x86emu *emu, uint32_t addr) /* * PARAMETERS: * addr - Emulator memory address to read - * + * * RETURNS: * Word value read from emulator memory. - * + * * REMARKS: * Reads a word value from the emulator memory. */ @@ -90,7 +90,7 @@ rdw(struct x86emu *emu, uint32_t addr) /* * PARAMETERS: * addr - Emulator memory address to read - * + * * RETURNS: * Long value read from emulator memory. * REMARKS: @@ -122,7 +122,7 @@ rdl(struct x86emu *emu, uint32_t addr) * PARAMETERS: * addr - Emulator memory address to read * val - Value to store - * + * * REMARKS: * Writes a byte value to emulator memory. */ @@ -138,7 +138,7 @@ wrb(struct x86emu *emu, uint32_t addr, uint8_t val) * PARAMETERS: * addr - Emulator memory address to read * val - Value to store - * + * * REMARKS: * Writes a word value to emulator memory. */ @@ -164,7 +164,7 @@ wrw(struct x86emu *emu, uint32_t addr, uint16_t val) * PARAMETERS: * addr - Emulator memory address to read * val - Value to store - * + * * REMARKS: * Writes a long value to emulator memory. */ diff --git a/sys/net/bfd.c b/sys/net/bfd.c index 95e73ca59..bbc58a040 100644 --- a/sys/net/bfd.c +++ b/sys/net/bfd.c @@ -640,7 +640,7 @@ bfd_upcall(struct socket *so, caddr_t arg, int waitflag) struct bfd_config *bfd = (struct bfd_config *)arg; bfd->bc_upcallso = so; - task_add(bfdtq, &bfd->bc_upcall_task); + task_add(bfdtq, &bfd->bc_upcall_task); } void diff --git a/sys/net/if.c b/sys/net/if.c index e9ea77f61..855e5dfc9 100644 --- a/sys/net/if.c +++ b/sys/net/if.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if.c,v 1.695 2023/05/07 16:23:23 bluhm Exp $ */ +/* $OpenBSD: if.c,v 1.696 2023/05/14 01:46:53 dlg Exp $ */ /* $NetBSD: if.c,v 1.35 1996/05/07 05:26:04 thorpej Exp $ */ /* @@ -243,8 +243,13 @@ int ifq_congestion; int netisr; +struct softnet { + char sn_name[16]; + struct taskq *sn_taskq; +}; + #define NET_TASKQ 4 -struct taskq *nettqmp[NET_TASKQ]; +struct softnet softnets[NET_TASKQ]; struct task if_input_task_locked = TASK_INITIALIZER(if_netisr, NULL); @@ -269,8 +274,11 @@ ifinit(void) if_idxmap_init(8); /* 8 is a nice power of 2 for malloc */ for (i = 0; i < NET_TASKQ; i++) { - nettqmp[i] = taskq_create("softnet", 1, IPL_NET, TASKQ_MPSAFE); - if (nettqmp[i] == NULL) + struct softnet *sn = &softnets[i]; + snprintf(sn->sn_name, sizeof(sn->sn_name), "softnet%u", i); + sn->sn_taskq = taskq_create(sn->sn_name, 1, IPL_NET, + TASKQ_MPSAFE); + if (sn->sn_taskq == NULL) panic("unable to create network taskq %d", i); } } @@ -3463,13 +3471,13 @@ unhandled_af(int af) struct taskq * net_tq(unsigned int ifindex) { - struct taskq *t = NULL; + struct softnet *sn; static int nettaskqs; if (nettaskqs == 0) nettaskqs = min(NET_TASKQ, ncpus); - t = nettqmp[ifindex % nettaskqs]; + sn = &softnets[ifindex % nettaskqs]; - return (t); + return (sn->sn_taskq); } diff --git a/sys/net/if_bridge.c b/sys/net/if_bridge.c index 463ca9cf9..a5ad2281a 100644 --- a/sys/net/if_bridge.c +++ b/sys/net/if_bridge.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if_bridge.c,v 1.366 2023/05/07 16:23:23 bluhm Exp $ */ +/* $OpenBSD: if_bridge.c,v 1.367 2023/05/13 13:35:17 bluhm Exp $ */ /* * Copyright (c) 1999, 2000 Jason L. Wright (jason@thought.net) @@ -1735,15 +1735,8 @@ bridge_ip(struct ifnet *brifp, int dir, struct ifnet *ifp, return (NULL); if (m->m_len < sizeof(struct ip)) goto dropit; + in_hdr_cksum_out(m, ifp); in_proto_cksum_out(m, ifp); - ip = mtod(m, struct ip *); - ip->ip_sum = 0; - if (0 && (ifp->if_capabilities & IFCAP_CSUM_IPv4)) - m->m_pkthdr.csum_flags |= M_IPV4_CSUM_OUT; - else { - ipstat_inc(ips_outswcsum); - ip->ip_sum = in_cksum(m, hlen); - } #if NPF > 0 if (dir == BRIDGE_IN && @@ -1993,8 +1986,7 @@ bridge_send_icmp_err(struct ifnet *ifp, ip->ip_off &= htons(IP_DF); ip->ip_id = htons(ip_randomid()); ip->ip_ttl = MAXTTL; - ip->ip_sum = 0; - ip->ip_sum = in_cksum(m, hlen); + in_hdr_cksum_out(m, NULL); /* Swap ethernet addresses */ bcopy(&eh->ether_dhost, ðer_tmp, sizeof(ether_tmp)); diff --git a/sys/net/if_gre.c b/sys/net/if_gre.c index 6aebed6ee..cac48bb8f 100644 --- a/sys/net/if_gre.c +++ b/sys/net/if_gre.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if_gre.c,v 1.173 2023/04/13 02:19:05 jsg Exp $ */ +/* $OpenBSD: if_gre.c,v 1.174 2023/05/13 13:35:17 bluhm Exp $ */ /* $NetBSD: if_gre.c,v 1.9 1999/10/25 19:18:11 drochner Exp $ */ /* @@ -3028,8 +3028,7 @@ gre_keepalive_send(void *arg) ip = mtod(m, struct ip *); ip->ip_id = htons(ip_randomid()); - ip->ip_sum = 0; - ip->ip_sum = in_cksum(m, sizeof(*ip)); + in_hdr_cksum_out(m, NULL); proto = htons(ETHERTYPE_IP); break; diff --git a/sys/net/pf.c b/sys/net/pf.c index ee979d9e8..7c395644c 100644 --- a/sys/net/pf.c +++ b/sys/net/pf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: pf.c,v 1.1178 2023/05/10 12:07:16 bluhm Exp $ */ +/* $OpenBSD: pf.c,v 1.1179 2023/05/13 13:35:17 bluhm Exp $ */ /* * Copyright (c) 2001 Daniel Hartmeier @@ -2868,7 +2868,7 @@ pf_change_icmp_af(struct mbuf *m, int ipoff2, struct pf_pdesc *pd, ip4->ip_p = pd2->proto; ip4->ip_src = src->v4; ip4->ip_dst = dst->v4; - ip4->ip_sum = in_cksum(n, ip4->ip_hl << 2); + in_hdr_cksum_out(n, NULL); break; case AF_INET6: ip6 = mtod(n, struct ip6_hdr *); @@ -6549,13 +6549,7 @@ pf_route(struct pf_pdesc *pd, struct pf_state *st) } if (ntohs(ip->ip_len) <= ifp->if_mtu) { - ip->ip_sum = 0; - if (ifp->if_capabilities & IFCAP_CSUM_IPv4) - m0->m_pkthdr.csum_flags |= M_IPV4_CSUM_OUT; - else { - ipstat_inc(ips_outswcsum); - ip->ip_sum = in_cksum(m0, ip->ip_hl << 2); - } + in_hdr_cksum_out(m0, ifp); in_proto_cksum_out(m0, ifp); ifp->if_output(ifp, m0, sintosa(dst), rt); goto done; diff --git a/sys/netinet/in.h b/sys/netinet/in.h index 16dcdb24c..359be65f6 100644 --- a/sys/netinet/in.h +++ b/sys/netinet/in.h @@ -1,4 +1,4 @@ -/* $OpenBSD: in.h,v 1.143 2023/05/10 12:07:16 bluhm Exp $ */ +/* $OpenBSD: in.h,v 1.144 2023/05/13 13:35:17 bluhm Exp $ */ /* $NetBSD: in.h,v 1.20 1996/02/13 23:41:47 christos Exp $ */ /* @@ -779,6 +779,7 @@ int in_broadcast(struct in_addr, u_int); int in_canforward(struct in_addr); int in_cksum(struct mbuf *, int); int in4_cksum(struct mbuf *, u_int8_t, int, int); +void in_hdr_cksum_out(struct mbuf *, struct ifnet *); void in_proto_cksum_out(struct mbuf *, struct ifnet *); int in_ifcap_cksum(struct mbuf *, struct ifnet *, int); void in_ifdetach(struct ifnet *); diff --git a/sys/netinet/ip_divert.c b/sys/netinet/ip_divert.c index 77d769807..acb00eb85 100644 --- a/sys/netinet/ip_divert.c +++ b/sys/netinet/ip_divert.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ip_divert.c,v 1.90 2023/04/04 10:12:03 bluhm Exp $ */ +/* $OpenBSD: ip_divert.c,v 1.91 2023/05/13 13:35:17 bluhm Exp $ */ /* * Copyright (c) 2009 Michele Marchetto @@ -157,8 +157,7 @@ divert_output(struct inpcb *inp, struct mbuf *m, struct mbuf *nam, * since the userspace application may have modified the packet * prior to reinjection. */ - ip->ip_sum = 0; - ip->ip_sum = in_cksum(m, off); + in_hdr_cksum_out(m, NULL); in_proto_cksum_out(m, NULL); ifp = if_get(m->m_pkthdr.ph_ifidx); @@ -190,8 +189,6 @@ divert_packet(struct mbuf *m, int dir, u_int16_t divert_port) struct inpcb *inp = NULL; struct socket *so; struct sockaddr_in sin; - struct ip *ip; - int off; divstat_inc(divs_ipackets); @@ -239,11 +236,7 @@ divert_packet(struct mbuf *m, int dir, u_int16_t divert_port) * Calculate IP and protocol checksums for outbound packet * diverted to userland. pf rule diverts before cksum offload. */ - ip = mtod(m, struct ip *); - off = ip->ip_hl << 2; - - ip->ip_sum = 0; - ip->ip_sum = in_cksum(m, off); + in_hdr_cksum_out(m, NULL); in_proto_cksum_out(m, NULL); } diff --git a/sys/netinet/ip_output.c b/sys/netinet/ip_output.c index f5b1173a2..394da08ad 100644 --- a/sys/netinet/ip_output.c +++ b/sys/netinet/ip_output.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ip_output.c,v 1.385 2023/05/10 12:07:16 bluhm Exp $ */ +/* $OpenBSD: ip_output.c,v 1.386 2023/05/13 13:35:17 bluhm Exp $ */ /* $NetBSD: ip_output.c,v 1.28 1996/02/13 23:43:07 christos Exp $ */ /* @@ -81,8 +81,7 @@ int ip_pcbopts(struct mbuf **, struct mbuf *); int ip_multicast_if(struct ip_mreqn *, u_int, unsigned int *); int ip_setmoptions(int, struct ip_moptions **, struct mbuf *, u_int); void ip_mloopback(struct ifnet *, struct mbuf *, struct sockaddr_in *); -static __inline u_int16_t __attribute__((__unused__)) - in_cksum_phdr(u_int32_t, u_int32_t, u_int32_t); +static u_int16_t in_cksum_phdr(u_int32_t, u_int32_t, u_int32_t); void in_delayed_cksum(struct mbuf *); int ip_output_ipsec_lookup(struct mbuf *m, int hlen, struct inpcb *inp, @@ -455,13 +454,7 @@ sendit: * If small enough for interface, can just send directly. */ if (ntohs(ip->ip_len) <= mtu) { - ip->ip_sum = 0; - if (in_ifcap_cksum(m, ifp, IFCAP_CSUM_IPv4)) - m->m_pkthdr.csum_flags |= M_IPV4_CSUM_OUT; - else { - ipstat_inc(ips_outswcsum); - ip->ip_sum = in_cksum(m, hlen); - } + in_hdr_cksum_out(m, ifp); in_proto_cksum_out(m, ifp); error = ifp->if_output(ifp, m, sintosa(dst), ro->ro_rt); goto done; @@ -772,13 +765,7 @@ ip_fragment(struct mbuf *m0, struct mbuf_list *ml, struct ifnet *ifp, goto bad; } - mhip->ip_sum = 0; - if (in_ifcap_cksum(m, ifp, IFCAP_CSUM_IPv4)) - m->m_pkthdr.csum_flags |= M_IPV4_CSUM_OUT; - else { - ipstat_inc(ips_outswcsum); - mhip->ip_sum = in_cksum(m, mhlen); - } + in_hdr_cksum_out(m, ifp); } /* @@ -791,13 +778,7 @@ ip_fragment(struct mbuf *m0, struct mbuf_list *ml, struct ifnet *ifp, } ip->ip_len = htons(m0->m_pkthdr.len); - ip->ip_sum = 0; - if (in_ifcap_cksum(m0, ifp, IFCAP_CSUM_IPv4)) - m0->m_pkthdr.csum_flags |= M_IPV4_CSUM_OUT; - else { - ipstat_inc(ips_outswcsum); - ip->ip_sum = in_cksum(m0, hlen); - } + in_hdr_cksum_out(m0, ifp); ipstat_add(ips_ofragments, ml_len(ml)); return (0); @@ -1806,7 +1787,6 @@ ip_freemoptions(struct ip_moptions *imo) void ip_mloopback(struct ifnet *ifp, struct mbuf *m, struct sockaddr_in *dst) { - struct ip *ip; struct mbuf *copym; copym = m_dup_pkt(m, max_linkhdr, M_DONTWAIT); @@ -1815,18 +1795,31 @@ ip_mloopback(struct ifnet *ifp, struct mbuf *m, struct sockaddr_in *dst) * We don't bother to fragment if the IP length is greater * than the interface's MTU. Can this possibly matter? */ - ip = mtod(copym, struct ip *); - ip->ip_sum = 0; - ip->ip_sum = in_cksum(copym, ip->ip_hl << 2); + in_hdr_cksum_out(copym, NULL); if_input_local(ifp, copym, dst->sin_family); } } +void +in_hdr_cksum_out(struct mbuf *m, struct ifnet *ifp) +{ + struct ip *ip = mtod(m, struct ip *); + + ip->ip_sum = 0; + if (ifp && in_ifcap_cksum(m, ifp, IFCAP_CSUM_IPv4)) { + SET(m->m_pkthdr.csum_flags, M_IPV4_CSUM_OUT); + } else { + ipstat_inc(ips_outswcsum); + ip->ip_sum = in_cksum(m, ip->ip_hl << 2); + CLR(m->m_pkthdr.csum_flags, M_IPV4_CSUM_OUT); + } +} + /* * Compute significant parts of the IPv4 checksum pseudo-header * for use in a delayed TCP/UDP checksum calculation. */ -static __inline u_int16_t __attribute__((__unused__)) +static u_int16_t in_cksum_phdr(u_int32_t src, u_int32_t dst, u_int32_t lenproto) { u_int32_t sum; diff --git a/sys/netinet/ipsec_input.c b/sys/netinet/ipsec_input.c index 353466af1..5df9a4f96 100644 --- a/sys/netinet/ipsec_input.c +++ b/sys/netinet/ipsec_input.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ipsec_input.c,v 1.203 2022/02/22 01:35:40 guenther Exp $ */ +/* $OpenBSD: ipsec_input.c,v 1.204 2023/05/13 13:35:17 bluhm Exp $ */ /* * The authors of this code are John Ioannidis (ji@tla.org), * Angelos D. Keromytis (kermit@csd.uch.gr) and @@ -389,8 +389,7 @@ ipsec_common_input_cb(struct mbuf **mp, struct tdb *tdbp, int skip, int protoff) ip = mtod(m, struct ip *); ip->ip_len = htons(m->m_pkthdr.len); - ip->ip_sum = 0; - ip->ip_sum = in_cksum(m, ip->ip_hl << 2); + in_hdr_cksum_out(m, NULL); prot = ip->ip_p; } diff --git a/sys/netinet/tcp_output.c b/sys/netinet/tcp_output.c index 84adc729b..752b485ba 100644 --- a/sys/netinet/tcp_output.c +++ b/sys/netinet/tcp_output.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tcp_output.c,v 1.136 2023/05/10 12:07:16 bluhm Exp $ */ +/* $OpenBSD: tcp_output.c,v 1.137 2023/05/13 13:35:18 bluhm Exp $ */ /* $NetBSD: tcp_output.c,v 1.16 1997/06/03 16:17:09 kml Exp $ */ /* @@ -1302,13 +1302,7 @@ tcp_chopper(struct mbuf *m0, struct mbuf_list *ml, struct ifnet *ifp, *mhip = *ip; mhip->ip_len = htons(hlen + len); mhip->ip_id = htons(ip_randomid()); - mhip->ip_sum = 0; - if (ifp && in_ifcap_cksum(m, ifp, IFCAP_CSUM_IPv4)) { - m->m_pkthdr.csum_flags |= M_IPV4_CSUM_OUT; - } else { - ipstat_inc(ips_outswcsum); - mhip->ip_sum = in_cksum(m, iphlen); - } + in_hdr_cksum_out(m, ifp); in_proto_cksum_out(m, ifp); } #ifdef INET6 @@ -1337,12 +1331,7 @@ tcp_chopper(struct mbuf *m0, struct mbuf_list *ml, struct ifnet *ifp, if (ip) { ip->ip_len = htons(m0->m_pkthdr.len); ip->ip_sum = 0; - if (ifp && in_ifcap_cksum(m0, ifp, IFCAP_CSUM_IPv4)) { - m0->m_pkthdr.csum_flags |= M_IPV4_CSUM_OUT; - } else { - ipstat_inc(ips_outswcsum); - ip->ip_sum = in_cksum(m0, iphlen); - } + in_hdr_cksum_out(m0, ifp); in_proto_cksum_out(m0, ifp); } #ifdef INET6 diff --git a/sys/netinet6/nd6.c b/sys/netinet6/nd6.c index fd3836a31..8ddde1536 100644 --- a/sys/netinet6/nd6.c +++ b/sys/netinet6/nd6.c @@ -1,4 +1,4 @@ -/* $OpenBSD: nd6.c,v 1.279 2023/05/12 12:42:16 bluhm Exp $ */ +/* $OpenBSD: nd6.c,v 1.280 2023/05/13 16:27:59 bluhm Exp $ */ /* $KAME: nd6.c,v 1.280 2002/06/08 19:52:07 itojun Exp $ */ /* @@ -306,7 +306,7 @@ nd6_llinfo_timer(struct rtentry *rt) struct sockaddr_in6 *dst = satosin6(rt_key(rt)); struct ifnet *ifp; - NET_ASSERT_LOCKED(); + NET_ASSERT_LOCKED_EXCLUSIVE(); if ((ifp = if_get(rt->rt_ifidx)) == NULL) return 1; @@ -557,9 +557,11 @@ nd6_lookup(const struct in6_addr *addr6, int create, struct ifnet *ifp, rtableid); if (error) return (NULL); + mtx_enter(&nd6_mtx); ln = (struct llinfo_nd6 *)rt->rt_llinfo; if (ln != NULL) ln->ln_state = ND6_LLINFO_NOSTATE; + mtx_leave(&nd6_mtx); } else return (NULL); } @@ -665,7 +667,7 @@ nd6_free(struct rtentry *rt) struct in6_addr in6 = satosin6(rt_key(rt))->sin6_addr; struct ifnet *ifp; - NET_ASSERT_LOCKED(); + NET_ASSERT_LOCKED_EXCLUSIVE(); ifp = if_get(rt->rt_ifidx); @@ -705,6 +707,8 @@ nd6_nud_hint(struct rtentry *rt) struct llinfo_nd6 *ln; struct ifnet *ifp; + NET_ASSERT_LOCKED_EXCLUSIVE(); + ifp = if_get(rt->rt_ifidx); if (ifp == NULL) return; @@ -990,8 +994,10 @@ nd6_ioctl(u_long cmd, caddr_t data, struct ifnet *ifp) } rt = nd6_lookup(&nb_addr, 0, ifp, ifp->if_rdomain); + mtx_enter(&nd6_mtx); if (rt == NULL || (ln = (struct llinfo_nd6 *)rt->rt_llinfo) == NULL) { + mtx_leave(&nd6_mtx); rtfree(rt); NET_UNLOCK_SHARED(); return (EINVAL); @@ -1006,6 +1012,7 @@ nd6_ioctl(u_long cmd, caddr_t data, struct ifnet *ifp) nbi->asked = ln->ln_asked; nbi->isrouter = ln->ln_router; nbi->expire = expire; + mtx_leave(&nd6_mtx); rtfree(rt); NET_UNLOCK_SHARED(); @@ -1035,6 +1042,8 @@ nd6_cache_lladdr(struct ifnet *ifp, const struct in6_addr *from, char *lladdr, int llchange; int newstate = 0; + NET_ASSERT_LOCKED_EXCLUSIVE(); + if (!ifp) panic("%s: ifp == NULL", __func__); if (!from) @@ -1294,23 +1303,20 @@ nd6_resolve(struct ifnet *ifp, struct rtentry *rt0, struct mbuf *m, goto bad; } - KERNEL_LOCK(); - if (!ISSET(rt->rt_flags, RTF_LLINFO)) { - KERNEL_UNLOCK(); + mtx_enter(&nd6_mtx); + ln = (struct llinfo_nd6 *)rt->rt_llinfo; + if (ln == NULL) { + mtx_leave(&nd6_mtx); goto bad; } - ln = (struct llinfo_nd6 *)rt->rt_llinfo; - KASSERT(ln != NULL); /* * Move this entry to the head of the queue so that it is less likely * for this entry to be a target of forced garbage collection (see * nd6_rtrequest()). */ - mtx_enter(&nd6_mtx); TAILQ_REMOVE(&nd6_list, ln, ln_list); TAILQ_INSERT_HEAD(&nd6_list, ln, ln_list); - mtx_leave(&nd6_mtx); /* * The first time we send a packet to a neighbor whose entry is @@ -1331,7 +1337,7 @@ nd6_resolve(struct ifnet *ifp, struct rtentry *rt0, struct mbuf *m, * send the packet. */ if (ln->ln_state > ND6_LLINFO_INCOMPLETE) { - KERNEL_UNLOCK(); + mtx_leave(&nd6_mtx); sdl = satosdl(rt->rt_gateway); if (sdl->sdl_alen != ETHER_ADDR_LEN) { @@ -1377,7 +1383,7 @@ nd6_resolve(struct ifnet *ifp, struct rtentry *rt0, struct mbuf *m, saddr6 = ln->ln_saddr6; solicit = 1; } - KERNEL_UNLOCK(); + mtx_leave(&nd6_mtx); if (solicit) nd6_ns_output(ifp, NULL, &satosin6(dst)->sin6_addr, &saddr6, 0); diff --git a/sys/netmpls/mpls_input.c b/sys/netmpls/mpls_input.c index a307499ff..b25a9806a 100644 --- a/sys/netmpls/mpls_input.c +++ b/sys/netmpls/mpls_input.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mpls_input.c,v 1.78 2021/07/22 11:07:17 mvs Exp $ */ +/* $OpenBSD: mpls_input.c,v 1.79 2023/05/13 13:35:18 bluhm Exp $ */ /* * Copyright (c) 2008 Claudio Jeker @@ -416,8 +416,7 @@ mpls_do_error(struct mbuf *m, int type, int code, int destmtu) /* stuff to fix up which is normally done in ip_output */ ip->ip_v = IPVERSION; ip->ip_id = htons(ip_randomid()); - ip->ip_sum = 0; - ip->ip_sum = in_cksum(m, sizeof(*ip)); + in_hdr_cksum_out(m, NULL); /* stolen from icmp_send() */ icp = (struct icmp *)(mtod(m, caddr_t) + sizeof(*ip)); diff --git a/sys/netmpls/mpls_output.c b/sys/netmpls/mpls_output.c index 44c48eaef..ff7696cfc 100644 --- a/sys/netmpls/mpls_output.c +++ b/sys/netmpls/mpls_output.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mpls_output.c,v 1.28 2019/09/03 10:39:08 jsg Exp $ */ +/* $OpenBSD: mpls_output.c,v 1.29 2023/05/13 13:35:18 bluhm Exp $ */ /* * Copyright (c) 2008 Claudio Jeker @@ -39,7 +39,6 @@ #define MPLS_LABEL_GET(l) ((ntohl((l) & MPLS_LABEL_MASK)) >> MPLS_LABEL_OFFSET) #endif -void mpls_do_cksum(struct mbuf *); u_int8_t mpls_getttl(struct mbuf *, sa_family_t); int @@ -62,7 +61,9 @@ mpls_output(struct ifnet *ifp, struct mbuf *m, struct sockaddr *dst, } /* need to calculate checksums now if necessary */ - mpls_do_cksum(m); + if (m->m_pkthdr.csum_flags & M_IPV4_CSUM_OUT) + in_hdr_cksum_out(m, NULL); + in_proto_cksum_out(m, NULL); /* initialize sockaddr_mpls */ bzero(&sa_mpls, sizeof(sa_mpls)); @@ -143,22 +144,6 @@ bad: return (error); } -void -mpls_do_cksum(struct mbuf *m) -{ - struct ip *ip; - u_int16_t hlen; - - in_proto_cksum_out(m, NULL); - - if (m->m_pkthdr.csum_flags & M_IPV4_CSUM_OUT) { - ip = mtod(m, struct ip *); - hlen = ip->ip_hl << 2; - ip->ip_sum = in_cksum(m, hlen); - m->m_pkthdr.csum_flags &= ~M_IPV4_CSUM_OUT; - } -} - u_int8_t mpls_getttl(struct mbuf *m, sa_family_t af) { diff --git a/sys/sys/blist.h b/sys/sys/blist.h index 24e1faf5e..c4ee569fa 100644 --- a/sys/sys/blist.h +++ b/sys/sys/blist.h @@ -2,14 +2,14 @@ /* DragonFlyBSD:7b80531f545c7d3c51c1660130c71d01f6bccbe0:/sys/sys/blist.h */ /* * Copyright (c) 2003,2004 The DragonFly Project. All rights reserved. - * + * * This code is derived from software contributed to The DragonFly Project * by Matthew Dillon - * + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: - * + * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright @@ -19,7 +19,7 @@ * 3. Neither the name of The DragonFly Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific, prior written permission. - * + * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS @@ -32,7 +32,7 @@ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. - * + * * Implements bitmap resource lists. * * Usage: diff --git a/sys/sys/cdio.h b/sys/sys/cdio.h index 02069c453..7db836e8c 100644 --- a/sys/sys/cdio.h +++ b/sys/sys/cdio.h @@ -69,16 +69,16 @@ struct cd_sub_channel_q_data { u_int mc_valid:1; u_int :7; #endif - u_char mc_number[15]; + u_char mc_number[15]; #if _BYTE_ORDER == _LITTLE_ENDIAN u_int :7; - u_int ti_valid:1; + u_int ti_valid:1; #endif #if _BYTE_ORDER == _BIG_ENDIAN - u_int ti_valid:1; + u_int ti_valid:1; u_int :7; #endif - u_char ti_number[15]; + u_char ti_number[15]; }; struct cd_sub_channel_position_data { @@ -272,7 +272,7 @@ struct dvd_layer { u_int32_t end_sector; u_int32_t end_sector_l0; }; - + struct dvd_physical { u_int8_t type; diff --git a/sys/sys/chio.h b/sys/sys/chio.h index a6cb8b110..f9ae6ed4e 100644 --- a/sys/sys/chio.h +++ b/sys/sys/chio.h @@ -51,7 +51,7 @@ /* * Maximum length of a volume identification string - */ + */ #define CH_VOLTAG_MAXLEN 32 /* @@ -142,7 +142,7 @@ struct changer_element_status { struct changer_element_status_request { int cesr_type; /* element type */ int cesr_flags; -#define CESR_VOLTAGS 0x01 +#define CESR_VOLTAGS 0x01 struct changer_element_status *cesr_data; /* pre-allocated data storage */ }; diff --git a/sys/sys/clockintr.h b/sys/sys/clockintr.h index 19fa5459a..06f7493a5 100644 --- a/sys/sys/clockintr.h +++ b/sys/sys/clockintr.h @@ -101,7 +101,7 @@ struct clockintr_queue { struct clockintr *cq_statclock; /* [o] statclock handle */ struct intrclock cq_intrclock; /* [I] local interrupt clock */ struct clockintr_stat cq_stat; /* [o] dispatch statistics */ - volatile u_int cq_gen; /* [o] cq_stat update generation */ + volatile u_int cq_gen; /* [o] cq_stat update generation */ volatile u_int cq_dispatch; /* [o] dispatch is running */ u_int cq_flags; /* [I] CQ_* flags; see below */ }; diff --git a/sys/sys/exec.h b/sys/sys/exec.h index c70d1d94a..0fb89f402 100644 --- a/sys/sys/exec.h +++ b/sys/sys/exec.h @@ -193,7 +193,7 @@ void new_vmcmd(struct exec_vmcmd_set *evsp, (vmc)->evs_cnt = EXEC_DEFAULT_VMCMD_SETSIZE; \ (vmc)->evs_cmds = (vmc)->evs_start; \ (vmc)->evs_used = 0; \ -} while (0) +} while (0) /* * Exec function switch: @@ -276,7 +276,7 @@ struct exec { #define MID_VAX 150 /* vax */ #define MID_SPARC64 151 /* LP64 sparc */ #define MID_MIPS2 152 /* MIPS2 */ -#define MID_M88K 153 /* m88k BSD binary */ +#define MID_M88K 153 /* m88k BSD binary */ #define MID_HPPA 154 /* hppa */ #define MID_AMD64 157 /* AMD64 */ #define MID_MIPS64 158 /* big-endian MIPS64 */ diff --git a/sys/sys/exec_elf.h b/sys/sys/exec_elf.h index 1ffb60df1..1bbacff54 100644 --- a/sys/sys/exec_elf.h +++ b/sys/sys/exec_elf.h @@ -270,7 +270,7 @@ typedef struct { #define SHT_SUNW_dof 0x6ffffff4 /* used by dtrace */ #define SHT_GNU_LIBLIST 0x6ffffff7 /* libraries to be prelinked */ #define SHT_SUNW_move 0x6ffffffa /* inf for partially init'ed symbols */ -#define SHT_SUNW_syminfo 0x6ffffffc /* ad symbol information */ +#define SHT_SUNW_syminfo 0x6ffffffc /* ad symbol information */ #define SHT_SUNW_verdef 0x6ffffffd /* symbol versioning inf */ #define SHT_SUNW_verneed 0x6ffffffe /* symbol versioning req */ #define SHT_SUNW_versym 0x6fffffff /* symbol versioning table */ diff --git a/sys/sys/kstat.h b/sys/sys/kstat.h index 9e8baba9c..5bba6f6e4 100644 --- a/sys/sys/kstat.h +++ b/sys/sys/kstat.h @@ -96,7 +96,7 @@ struct kstat_kv { char kv_key[KSTAT_KV_NAMELEN]; union { char v_istr[16]; - unsigned int v_bool; + unsigned int v_bool; uint64_t v_u64; int64_t v_s64; uint32_t v_u32; diff --git a/sys/sys/limits.h b/sys/sys/limits.h index 1faba69f6..5c6471633 100644 --- a/sys/sys/limits.h +++ b/sys/sys/limits.h @@ -60,9 +60,9 @@ #ifdef __LP64__ # define ULONG_MAX 0xffffffffffffffffUL /* max value for unsigned long */ -# define LONG_MAX 0x7fffffffffffffffL +# define LONG_MAX 0x7fffffffffffffffL /* max value for a signed long */ -# define LONG_MIN (-0x7fffffffffffffffL-1) +# define LONG_MIN (-0x7fffffffffffffffL-1) /* min value for a signed long */ #else # define ULONG_MAX 0xffffffffUL /* max value for an unsigned long */ @@ -71,11 +71,11 @@ #endif #if __BSD_VISIBLE || __ISO_C_VISIBLE >= 1999 -# define ULLONG_MAX 0xffffffffffffffffULL +# define ULLONG_MAX 0xffffffffffffffffULL /* max value for unsigned long long */ -# define LLONG_MAX 0x7fffffffffffffffLL +# define LLONG_MAX 0x7fffffffffffffffLL /* max value for a signed long long */ -# define LLONG_MIN (-0x7fffffffffffffffLL-1) +# define LLONG_MIN (-0x7fffffffffffffffLL-1) /* min value for a signed long long */ #endif diff --git a/sys/sys/lock.h b/sys/sys/lock.h index 2388b5955..9f6727220 100644 --- a/sys/sys/lock.h +++ b/sys/sys/lock.h @@ -1,6 +1,6 @@ /* $OpenBSD: lock.h,v 1.27 2016/06/19 11:54:33 natano Exp $ */ -/* +/* * Copyright (c) 1995 * The Regents of the University of California. All rights reserved. * diff --git a/sys/sys/mount.h b/sys/sys/mount.h index 40c12e976..695773fea 100644 --- a/sys/sys/mount.h +++ b/sys/sys/mount.h @@ -398,7 +398,7 @@ struct mount { #define MNT_DELEXPORT 0x00020000 /* delete export host lists */ #define MNT_RELOAD 0x00040000 /* reload filesystem data */ #define MNT_FORCE 0x00080000 /* force unmount or readonly change */ -#define MNT_STALLED 0x00100000 /* filesystem stalled */ +#define MNT_STALLED 0x00100000 /* filesystem stalled */ #define MNT_SWAPPABLE 0x00200000 /* filesystem can be used for swap */ #define MNT_WANTRDWR 0x02000000 /* want upgrade to read/write */ #define MNT_SOFTDEP 0x04000000 /* soft dependencies being done */ @@ -441,7 +441,7 @@ typedef struct fhandle fhandle_t; #define VFS_MAXTYPENUM 1 /* int: highest defined filesystem type */ #define VFS_CONF 2 /* struct: vfsconf for filesystem given as next argument */ -#define VFS_BCACHESTAT 3 /* struct: buffer cache statistics given +#define VFS_BCACHESTAT 3 /* struct: buffer cache statistics given as next argument */ #define CTL_VFSGENCTL_NAMES { \ { 0, 0 }, \ diff --git a/sys/sys/mtio.h b/sys/sys/mtio.h index fa7a32bad..06da67fd3 100644 --- a/sys/sys/mtio.h +++ b/sys/sys/mtio.h @@ -72,7 +72,7 @@ struct mtget { short mt_erreg; /* ``error'' register */ /* end device-dependent registers */ short mt_resid; /* residual count */ - int mt_fileno; /* current file number relative to BOT. */ + int mt_fileno; /* current file number relative to BOT. */ int mt_blkno; /* current block number relative to BOF. */ int mt_blksiz; /* current block size */ int mt_density; /* current density code */ diff --git a/sys/sys/proc.h b/sys/sys/proc.h index 60003397c..475916c11 100644 --- a/sys/sys/proc.h +++ b/sys/sys/proc.h @@ -356,7 +356,7 @@ struct proc { struct plimit *p_limit; /* [l] read ref. of p_p->ps_limit */ struct kcov_dev *p_kd; /* kcov device handle */ - struct lock_list_entry *p_sleeplocks; /* WITNESS lock tracking */ + struct lock_list_entry *p_sleeplocks; /* WITNESS lock tracking */ struct kqueue *p_kq; /* [o] select/poll queue of evts */ unsigned long p_kq_serial; /* [o] to check against enqueued evts */ diff --git a/sys/sys/protosw.h b/sys/sys/protosw.h index 0109c0760..476b4bac1 100644 --- a/sys/sys/protosw.h +++ b/sys/sys/protosw.h @@ -106,7 +106,7 @@ struct protosw { /* user-protocol hooks */ const struct pr_usrreqs *pr_usrreqs; - + /* utility hooks */ void (*pr_init)(void); /* initialization hook */ void (*pr_fasttimo)(void); /* fast timeout (200ms) */ diff --git a/sys/sys/sched.h b/sys/sys/sched.h index e5d461dcf..ff1fb20a9 100644 --- a/sys/sys/sched.h +++ b/sys/sys/sched.h @@ -106,7 +106,7 @@ struct schedstate_percpu { u_char spc_curpriority; /* usrpri of curproc */ int spc_rrticks; /* ticks until roundrobin() */ int spc_pscnt; /* prof/stat counter */ - int spc_psdiv; /* prof/stat divisor */ + int spc_psdiv; /* prof/stat divisor */ u_int spc_nrun; /* procs on the run queues */ fixpt_t spc_ldavg; /* shortest load avg. for this cpu */ diff --git a/sys/sys/scsiio.h b/sys/sys/scsiio.h index a21735593..fda863c55 100644 --- a/sys/sys/scsiio.h +++ b/sys/sys/scsiio.h @@ -60,7 +60,7 @@ struct scsi_addr { }; #define SCIOCRESET _IO('Q', 7) /* reset the device */ -#define SCIOCIDENTIFY _IOR('Q', 9, struct scsi_addr) +#define SCIOCIDENTIFY _IOR('Q', 9, struct scsi_addr) struct sbioc_device { void *sd_cookie; diff --git a/sys/sys/siginfo.h b/sys/sys/siginfo.h index c534ab104..c10c1b43e 100644 --- a/sys/sys/siginfo.h +++ b/sys/sys/siginfo.h @@ -29,19 +29,19 @@ #define _SYS_SIGINFO_H #include - + union sigval { int sival_int; /* integer value */ void *sival_ptr; /* pointer value */ }; - + /* * Negative signal codes are reserved for future use for * user generated signals. */ #define SI_FROMUSER(sip) ((sip)->si_code <= 0) #define SI_FROMKERNEL(sip) ((sip)->si_code > 0) - + #define SI_NOINFO 32767 /* no signal information */ #define SI_USER 0 /* user generated signal via kill() */ #define SI_LWP (-1) /* user generated signal via lwp_kill()*/ diff --git a/sys/sys/sockio.h b/sys/sys/sockio.h index e876572e2..44a2f5b2e 100644 --- a/sys/sys/sockio.h +++ b/sys/sys/sockio.h @@ -174,7 +174,7 @@ #define SIOCDVNETID _IOW('i', 175, struct ifreq) /* del virt net id */ -#define SIOCSIFPAIR _IOW('i', 176, struct ifreq) /* set paired if */ +#define SIOCSIFPAIR _IOW('i', 176, struct ifreq) /* set paired if */ #define SIOCGIFPAIR _IOWR('i', 177, struct ifreq) /* get paired if */ #define SIOCSIFPARENT _IOW('i', 178, struct if_parent) /* set parent if */ diff --git a/sys/uvm/uvm_aobj.c b/sys/uvm/uvm_aobj.c index faea505fb..490c94d67 100644 --- a/sys/uvm/uvm_aobj.c +++ b/sys/uvm/uvm_aobj.c @@ -1,4 +1,4 @@ -/* $OpenBSD: uvm_aobj.c,v 1.107 2022/08/29 02:58:13 jsg Exp $ */ +/* $OpenBSD: uvm_aobj.c,v 1.108 2023/05/13 09:24:59 mpi Exp $ */ /* $NetBSD: uvm_aobj.c,v 1.39 2001/02/18 21:19:08 chs Exp $ */ /* @@ -143,7 +143,6 @@ struct pool uvm_aobj_pool; static struct uao_swhash_elt *uao_find_swhash_elt(struct uvm_aobj *, int, boolean_t); -static int uao_find_swslot(struct uvm_object *, int); static boolean_t uao_flush(struct uvm_object *, voff_t, voff_t, int); static void uao_free(struct uvm_aobj *); @@ -241,7 +240,7 @@ uao_find_swhash_elt(struct uvm_aobj *aobj, int pageidx, boolean_t create) /* * uao_find_swslot: find the swap slot number for an aobj/pageidx */ -static inline int +int uao_find_swslot(struct uvm_object *uobj, int pageidx) { struct uvm_aobj *aobj = (struct uvm_aobj *)uobj; diff --git a/sys/uvm/uvm_aobj.h b/sys/uvm/uvm_aobj.h index e9e2936d2..203609019 100644 --- a/sys/uvm/uvm_aobj.h +++ b/sys/uvm/uvm_aobj.h @@ -1,4 +1,4 @@ -/* $OpenBSD: uvm_aobj.h,v 1.19 2022/07/24 11:00:22 mpi Exp $ */ +/* $OpenBSD: uvm_aobj.h,v 1.20 2023/05/13 09:24:59 mpi Exp $ */ /* $NetBSD: uvm_aobj.h,v 1.10 2000/01/11 06:57:49 chs Exp $ */ /* @@ -60,6 +60,7 @@ void uao_init(void); int uao_set_swslot(struct uvm_object *, int, int); +int uao_find_swslot(struct uvm_object *, int); int uao_dropswap(struct uvm_object *, int); int uao_swap_off(int, int); int uao_shrink(struct uvm_object *, int); diff --git a/sys/uvm/uvm_page.c b/sys/uvm/uvm_page.c index c4eb92d86..bab50a86f 100644 --- a/sys/uvm/uvm_page.c +++ b/sys/uvm/uvm_page.c @@ -1,4 +1,4 @@ -/* $OpenBSD: uvm_page.c,v 1.171 2023/04/11 00:45:09 jsg Exp $ */ +/* $OpenBSD: uvm_page.c,v 1.172 2023/05/13 09:24:59 mpi Exp $ */ /* $NetBSD: uvm_page.c,v 1.44 2000/11/27 08:40:04 chs Exp $ */ /* @@ -1036,13 +1036,14 @@ uvm_pagefree(struct vm_page *pg) * uvm_page_unbusy: unbusy an array of pages. * * => pages must either all belong to the same object, or all belong to anons. + * => if pages are object-owned, object must be locked. * => if pages are anon-owned, anons must have 0 refcount. + * => caller must make sure that anon-owned pages are not PG_RELEASED. */ void uvm_page_unbusy(struct vm_page **pgs, int npgs) { struct vm_page *pg; - struct uvm_object *uobj; int i; for (i = 0; i < npgs; i++) { @@ -1052,35 +1053,20 @@ uvm_page_unbusy(struct vm_page **pgs, int npgs) continue; } -#if notyet - /* - * XXX swap case in uvm_aio_aiodone() is not holding the lock. - * - * This isn't compatible with the PG_RELEASED anon case below. - */ KASSERT(uvm_page_owner_locked_p(pg)); -#endif KASSERT(pg->pg_flags & PG_BUSY); if (pg->pg_flags & PG_WANTED) { wakeup(pg); } if (pg->pg_flags & PG_RELEASED) { - uobj = pg->uobject; - if (uobj != NULL) { - uvm_lock_pageq(); - pmap_page_protect(pg, PROT_NONE); - /* XXX won't happen right now */ - if (pg->pg_flags & PQ_AOBJ) - uao_dropswap(uobj, - pg->offset >> PAGE_SHIFT); - uvm_pagefree(pg); - uvm_unlock_pageq(); - } else { - rw_enter(pg->uanon->an_lock, RW_WRITE); - uvm_anon_release(pg->uanon); - } + KASSERT(pg->uobject != NULL || + (pg->uanon != NULL && pg->uanon->an_ref > 0)); + atomic_clearbits_int(&pg->pg_flags, PG_RELEASED); + pmap_page_protect(pg, PROT_NONE); + uvm_pagefree(pg); } else { + KASSERT((pg->pg_flags & PG_FAKE) == 0); atomic_clearbits_int(&pg->pg_flags, PG_WANTED|PG_BUSY); UVM_PAGE_OWN(pg, NULL); } diff --git a/sys/uvm/uvm_pager.c b/sys/uvm/uvm_pager.c index adb363204..a348311f5 100644 --- a/sys/uvm/uvm_pager.c +++ b/sys/uvm/uvm_pager.c @@ -1,4 +1,4 @@ -/* $OpenBSD: uvm_pager.c,v 1.89 2022/08/19 05:53:19 mpi Exp $ */ +/* $OpenBSD: uvm_pager.c,v 1.90 2023/05/13 09:24:59 mpi Exp $ */ /* $NetBSD: uvm_pager.c,v 1.36 2000/11/27 18:26:41 chs Exp $ */ /* @@ -755,50 +755,77 @@ void uvm_aio_aiodone_pages(struct vm_page **pgs, int npages, boolean_t write, int error) { - struct vm_page *pg; struct uvm_object *uobj; + struct vm_page *pg; + struct rwlock *slock; boolean_t swap; - int i; + int i, swslot; + slock = NULL; uobj = NULL; + pg = pgs[0]; + swap = (pg->uanon != NULL && pg->uobject == NULL) || + (pg->pg_flags & PQ_AOBJ) != 0; + + KASSERT(swap); + KASSERT(write); + + if (error) { + if (pg->uobject != NULL) { + swslot = uao_find_swslot(pg->uobject, + pg->offset >> PAGE_SHIFT); + } else { + swslot = pg->uanon->an_swslot; + } + KASSERT(swslot); + } for (i = 0; i < npages; i++) { + int anon_disposed = 0; + pg = pgs[i]; - - if (i == 0) { - swap = (pg->pg_flags & PQ_SWAPBACKED) != 0; - if (!swap) { - uobj = pg->uobject; - rw_enter(uobj->vmobjlock, RW_WRITE); - } - } - KASSERT(swap || pg->uobject == uobj); + KASSERT((pg->pg_flags & PG_FAKE) == 0); /* - * if this is a read and we got an error, mark the pages - * PG_RELEASED so that uvm_page_unbusy() will free them. + * lock each page's object (or anon) individually since + * each page may need a different lock. */ - if (!write && error) { - atomic_setbits_int(&pg->pg_flags, PG_RELEASED); - continue; + if (pg->uobject != NULL) { + slock = pg->uobject->vmobjlock; + } else { + slock = pg->uanon->an_lock; } - KASSERT(!write || (pgs[i]->pg_flags & PG_FAKE) == 0); + rw_enter(slock, RW_WRITE); + anon_disposed = (pg->pg_flags & PG_RELEASED) != 0; + KASSERT(!anon_disposed || pg->uobject != NULL || + pg->uanon->an_ref == 0); + uvm_lock_pageq(); /* - * if this is a read and the page is PG_FAKE, - * or this was a successful write, - * mark the page PG_CLEAN and not PG_FAKE. + * if this was a successful write, + * mark the page PG_CLEAN. */ - if ((pgs[i]->pg_flags & PG_FAKE) || (write && error != ENOMEM)) { - pmap_clear_reference(pgs[i]); - pmap_clear_modify(pgs[i]); - atomic_setbits_int(&pgs[i]->pg_flags, PG_CLEAN); - atomic_clearbits_int(&pgs[i]->pg_flags, PG_FAKE); + if (!error) { + pmap_clear_reference(pg); + pmap_clear_modify(pg); + atomic_setbits_int(&pg->pg_flags, PG_CLEAN); + } + + /* + * unlock everything for this page now. + */ + if (pg->uobject == NULL && anon_disposed) { + uvm_unlock_pageq(); + uvm_anon_release(pg->uanon); + } else { + uvm_page_unbusy(&pg, 1); + uvm_unlock_pageq(); + rw_exit(slock); } } - uvm_page_unbusy(pgs, npages); - if (!swap) { - rw_exit(uobj->vmobjlock); + + if (error) { + uvm_swap_markbad(swslot, npages); } } diff --git a/usr.sbin/vmd/vioblk.c b/usr.sbin/vmd/vioblk.c index 9373a135a..33d447a94 100644 --- a/usr.sbin/vmd/vioblk.c +++ b/usr.sbin/vmd/vioblk.c @@ -1,4 +1,4 @@ -/* $OpenBSD: vioblk.c,v 1.2 2023/04/28 18:52:22 dv Exp $ */ +/* $OpenBSD: vioblk.c,v 1.3 2023/05/13 23:15:28 dv Exp $ */ /* * Copyright (c) 2023 Dave Voutila @@ -58,7 +58,7 @@ disk_type(int type) } __dead void -vioblk_main(int fd) +vioblk_main(int fd, int fd_vmm) { struct virtio_dev dev; struct vioblk_dev *vioblk; @@ -71,8 +71,11 @@ vioblk_main(int fd) log_procinit("vioblk"); - /* stdio - needed for read/write to disk fds and channels to the vm. */ - if (pledge("stdio", NULL) == -1) + /* + * stdio - needed for read/write to disk fds and channels to the vm. + * vmm + proc - needed to create shared vm mappings. + */ + if (pledge("stdio vmm proc", NULL) == -1) fatal("pledge"); /* Receive our virtio_dev, mostly preconfigured. */ @@ -92,8 +95,9 @@ vioblk_main(int fd) vioblk = &dev.vioblk; log_debug("%s: got viblk dev. num disk fds = %d, sync fd = %d, " - "async fd = %d, sz = %lld maxfer = %d", __func__, vioblk->ndisk_fd, - dev.sync_fd, dev.async_fd, vioblk->sz, vioblk->max_xfer); + "async fd = %d, sz = %lld maxfer = %d, vmm fd = %d", __func__, + vioblk->ndisk_fd, dev.sync_fd, dev.async_fd, vioblk->sz, + vioblk->max_xfer, fd_vmm); /* Receive our vm information from the vm process. */ memset(&vm, 0, sizeof(vm)); @@ -108,12 +112,19 @@ vioblk_main(int fd) setproctitle("%s/vioblk[%d]", vcp->vcp_name, vioblk->idx); /* Now that we have our vm information, we can remap memory. */ - ret = remap_guest_mem(&vm); + ret = remap_guest_mem(&vm, fd_vmm); if (ret) { log_warnx("failed to remap guest memory"); goto fail; } + /* + * We no longer need /dev/vmm access. + */ + close_fd(fd_vmm); + if (pledge("stdio", NULL) == -1) + fatal("pledge2"); + /* Initialize the virtio block abstractions. */ type = vm.vm_params.vmc_disktypes[vioblk->idx]; switch (type) { diff --git a/usr.sbin/vmd/vionet.c b/usr.sbin/vmd/vionet.c index 6ce905fdc..c16ad2635 100644 --- a/usr.sbin/vmd/vionet.c +++ b/usr.sbin/vmd/vionet.c @@ -1,4 +1,4 @@ -/* $OpenBSD: vionet.c,v 1.2 2023/04/28 18:52:22 dv Exp $ */ +/* $OpenBSD: vionet.c,v 1.3 2023/05/13 23:15:28 dv Exp $ */ /* * Copyright (c) 2023 Dave Voutila @@ -61,7 +61,7 @@ static void dev_dispatch_vm(int, short, void *); static void handle_sync_io(int, short, void *); __dead void -vionet_main(int fd) +vionet_main(int fd, int fd_vmm) { struct virtio_dev dev; struct vionet_dev *vionet = NULL; @@ -73,8 +73,11 @@ vionet_main(int fd) log_procinit("vionet"); - /* stdio - needed for read/write to tap fd and channels to the vm. */ - if (pledge("stdio", NULL) == -1) + /* + * stdio - needed for read/write to disk fds and channels to the vm. + * vmm + proc - needed to create shared vm mappings. + */ + if (pledge("stdio vmm proc", NULL) == -1) fatal("pledge"); /* Receive our vionet_dev, mostly preconfigured. */ @@ -92,8 +95,9 @@ vionet_main(int fd) dev.sync_fd = fd; vionet = &dev.vionet; - log_debug("%s: got vionet dev. tap fd = %d, syncfd = %d, asyncfd = %d", - __func__, vionet->data_fd, dev.sync_fd, dev.async_fd); + log_debug("%s: got vionet dev. tap fd = %d, syncfd = %d, asyncfd = %d" + ", vmm fd = %d", __func__, vionet->data_fd, dev.sync_fd, + dev.async_fd, fd_vmm); /* Receive our vm information from the vm process. */ memset(&vm, 0, sizeof(vm)); @@ -108,9 +112,18 @@ vionet_main(int fd) setproctitle("%s/vionet[%d]", vcp->vcp_name, vionet->idx); /* Now that we have our vm information, we can remap memory. */ - ret = remap_guest_mem(&vm); - if (ret) + ret = remap_guest_mem(&vm, fd_vmm); + if (ret) { + fatal("%s: failed to remap", __func__); goto fail; + } + + /* + * We no longer need /dev/vmm access. + */ + close_fd(fd_vmm); + if (pledge("stdio", NULL) == -1) + fatal("pledge2"); /* If we're restoring hardware, re-initialize virtqueue hva's. */ if (vm.vm_state & VM_STATE_RECEIVED) { diff --git a/usr.sbin/vmd/virtio.c b/usr.sbin/vmd/virtio.c index 92e77b8f8..d29b9e7b8 100644 --- a/usr.sbin/vmd/virtio.c +++ b/usr.sbin/vmd/virtio.c @@ -1,4 +1,4 @@ -/* $OpenBSD: virtio.c,v 1.102 2023/04/27 22:47:27 dv Exp $ */ +/* $OpenBSD: virtio.c,v 1.103 2023/05/13 23:15:28 dv Exp $ */ /* * Copyright (c) 2015 Mike Larkin @@ -1297,7 +1297,7 @@ virtio_start(struct vmd_vm *vm) static int virtio_dev_launch(struct vmd_vm *vm, struct virtio_dev *dev) { - char *nargv[8], num[32], t[2]; + char *nargv[10], num[32], vmm_fd[32], t[2]; pid_t dev_pid; int data_fds[VM_MAX_BASE_PER_DISK], sync_fds[2], async_fds[2], ret = 0; size_t i, j, data_fds_sz, sz = 0; @@ -1483,6 +1483,8 @@ virtio_dev_launch(struct vmd_vm *vm, struct virtio_dev *dev) memset(&nargv, 0, sizeof(nargv)); memset(num, 0, sizeof(num)); snprintf(num, sizeof(num), "%d", sync_fds[1]); + memset(vmm_fd, 0, sizeof(vmm_fd)); + snprintf(vmm_fd, sizeof(vmm_fd), "%d", env->vmd_fd); t[0] = dev->dev_type; t[1] = '\0'; @@ -1492,13 +1494,15 @@ virtio_dev_launch(struct vmd_vm *vm, struct virtio_dev *dev) nargv[2] = num; nargv[3] = "-t"; nargv[4] = t; - nargv[5] = "-n"; + nargv[5] = "-i"; + nargv[6] = vmm_fd; + nargv[7] = "-n"; if (env->vmd_verbose) { - nargv[6] = "-v"; - nargv[7] = NULL; + nargv[8] = "-v"; + nargv[9] = NULL; } else - nargv[6] = NULL; + nargv[8] = NULL; /* Control resumes in vmd.c:main(). */ execvp(nargv[0], nargv); diff --git a/usr.sbin/vmd/vm.c b/usr.sbin/vmd/vm.c index d42abb5a8..8ec69d605 100644 --- a/usr.sbin/vmd/vm.c +++ b/usr.sbin/vmd/vm.c @@ -1,4 +1,4 @@ -/* $OpenBSD: vm.c,v 1.88 2023/04/28 19:46:42 dv Exp $ */ +/* $OpenBSD: vm.c,v 1.89 2023/05/13 23:15:28 dv Exp $ */ /* * Copyright (c) 2015 Mike Larkin @@ -218,9 +218,10 @@ static const struct vcpu_reg_state vcpu_init_flat16 = { * Primary entrypoint for launching a vm. Does not return. * * fd: file descriptor for communicating with vmm process. + * fd_vmm: file descriptor for communicating with vmm(4) device */ void -vm_main(int fd) +vm_main(int fd, int vmm_fd) { struct vm_create_params *vcp = NULL; struct vmd_vm vm; @@ -241,9 +242,8 @@ vm_main(int fd) * vmm - for the vmm ioctls and operations. * proc exec - fork/exec for launching devices. * recvfd - for vm send/recv and sending fd to devices. - * tmppath/rpath - for shm_mkstemp, ftruncate, unlink */ - if (pledge("stdio vmm proc exec recvfd tmppath rpath", NULL) == -1) + if (pledge("stdio vmm proc exec recvfd", NULL) == -1) fatal("pledge"); /* Receive our vm configuration. */ @@ -254,13 +254,6 @@ vm_main(int fd) _exit(EIO); } - /* Receive the /dev/vmm fd number. */ - sz = atomicio(read, fd, &env->vmd_fd, sizeof(env->vmd_fd)); - if (sz != sizeof(env->vmd_fd)) { - log_warnx("failed to receive /dev/vmm fd"); - _exit(EIO); - } - /* Update process with the vm name. */ vcp = &vm.vm_params.vmc_params; setproctitle("%s", vcp->vcp_name); @@ -1099,63 +1092,34 @@ int alloc_guest_mem(struct vmd_vm *vm) { void *p; - char *tmp; - int fd, ret = 0; + int ret = 0; size_t i, j; struct vm_create_params *vcp = &vm->vm_params.vmc_params; struct vm_mem_range *vmr; - tmp = calloc(32, sizeof(char)); - if (tmp == NULL) { - ret = errno; - log_warn("%s: calloc", __func__); - return (ret); - } - strlcpy(tmp, "/tmp/vmd.XXXXXXXXXX", 32); - - vm->vm_nmemfds = vcp->vcp_nmemranges; - for (i = 0; i < vcp->vcp_nmemranges; i++) { vmr = &vcp->vcp_memranges[i]; - fd = shm_mkstemp(tmp); - if (fd < 0) { - ret = errno; - log_warn("%s: shm_mkstemp", __func__); - return (ret); - } - if (ftruncate(fd, vmr->vmr_size) == -1) { - ret = errno; - log_warn("%s: ftruncate", __func__); - goto out; - } - if (fcntl(fd, F_SETFD, 0) == -1) { - ret = errno; - log_warn("%s: fcntl", __func__); - goto out; - } - if (shm_unlink(tmp) == -1) { - ret = errno; - log_warn("%s: shm_unlink", __func__); - goto out; - } - strlcpy(tmp, "/tmp/vmd.XXXXXXXXXX", 32); - + /* + * We only need R/W as userland. vmm(4) will use R/W/X in its + * mapping. + * + * We must use MAP_SHARED so emulated devices will be able + * to generate shared mappings. + */ p = mmap(NULL, vmr->vmr_size, PROT_READ | PROT_WRITE, - MAP_SHARED | MAP_CONCEAL, fd, 0); + MAP_ANON | MAP_CONCEAL | MAP_SHARED, -1, 0); if (p == MAP_FAILED) { ret = errno; for (j = 0; j < i; j++) { vmr = &vcp->vcp_memranges[j]; munmap((void *)vmr->vmr_va, vmr->vmr_size); } - goto out; + return (ret); } - vm->vm_memfds[i] = fd; vmr->vmr_va = (vaddr_t)p; } -out: - free(tmp); + return (ret); } @@ -2552,10 +2516,11 @@ vm_pipe_recv(struct vm_dev_pipe *p) * Returns 0 on success, non-zero in event of failure. */ int -remap_guest_mem(struct vmd_vm *vm) +remap_guest_mem(struct vmd_vm *vm, int vmm_fd) { struct vm_create_params *vcp; struct vm_mem_range *vmr; + struct vm_sharemem_params vsp; size_t i, j; void *p = NULL; int ret; @@ -2566,23 +2531,32 @@ remap_guest_mem(struct vmd_vm *vm) vcp = &vm->vm_params.vmc_params; /* - * We've execve'd, so we need to re-map the guest VM memory. Iterate - * over all possible vm_mem_range entries so we can initialize all - * file descriptors to a value. + * Initialize our VM shared memory request using our original + * creation parameters. We'll overwrite the va's after mmap(2). + */ + memset(&vsp, 0, sizeof(vsp)); + vsp.vsp_nmemranges = vcp->vcp_nmemranges; + vsp.vsp_vm_id = vcp->vcp_id; + memcpy(&vsp.vsp_memranges, &vcp->vcp_memranges, + sizeof(vsp.vsp_memranges)); + + /* + * Use mmap(2) to identify virtual address space for our mappings. */ for (i = 0; i < VMM_MAX_MEM_RANGES; i++) { - if (i < vcp->vcp_nmemranges) { - vmr = &vcp->vcp_memranges[i]; - /* Skip ranges we know we don't need right now. */ + if (i < vsp.vsp_nmemranges) { + vmr = &vsp.vsp_memranges[i]; + + /* Ignore any MMIO ranges. */ if (vmr->vmr_type == VM_MEM_MMIO) { - log_debug("%s: skipping range i=%ld, type=%d", - __func__, i, vmr->vmr_type); - vm->vm_memfds[i] = -1; + vmr->vmr_va = 0; + vcp->vcp_memranges[i].vmr_va = 0; continue; } - /* Re-mmap the memrange. */ - p = mmap(NULL, vmr->vmr_size, PROT_READ | PROT_WRITE, - MAP_SHARED | MAP_CONCEAL, vm->vm_memfds[i], 0); + + /* Make initial mappings for the memrange. */ + p = mmap(NULL, vmr->vmr_size, PROT_READ, MAP_ANON, -1, + 0); if (p == MAP_FAILED) { ret = errno; log_warn("%s: mmap", __func__); @@ -2594,11 +2568,29 @@ remap_guest_mem(struct vmd_vm *vm) return (ret); } vmr->vmr_va = (vaddr_t)p; - } else { - /* Initialize with an invalid fd. */ - vm->vm_memfds[i] = -1; + vcp->vcp_memranges[i].vmr_va = vmr->vmr_va; } } + /* + * munmap(2) now that we have va's and ranges that don't overlap. vmm + * will use the va's and sizes to recreate the mappings for us. + */ + for (i = 0; i < vsp.vsp_nmemranges; i++) { + vmr = &vsp.vsp_memranges[i]; + if (vmr->vmr_type == VM_MEM_MMIO) + continue; + if (munmap((void*)vmr->vmr_va, vmr->vmr_size) == -1) + fatal("%s: munmap", __func__); + } + + /* + * Ask vmm to enter the shared mappings for us. They'll point + * to the same host physical memory, but will have a randomized + * virtual address for the calling process. + */ + if (ioctl(vmm_fd, VMM_IOC_SHAREMEM, &vsp) == -1) + return (errno); + return (0); } diff --git a/usr.sbin/vmd/vmd.c b/usr.sbin/vmd/vmd.c index b8cc0a09f..86a5132fe 100644 --- a/usr.sbin/vmd/vmd.c +++ b/usr.sbin/vmd/vmd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: vmd.c,v 1.148 2023/05/12 16:18:17 dv Exp $ */ +/* $OpenBSD: vmd.c,v 1.149 2023/05/13 23:15:28 dv Exp $ */ /* * Copyright (c) 2015 Reyk Floeter @@ -788,7 +788,8 @@ main(int argc, char **argv) struct privsep *ps; int ch; enum privsep_procid proc_id = PROC_PARENT; - int proc_instance = 0, vm_launch = 0, vm_fd = -1; + int proc_instance = 0, vm_launch = 0; + int vmm_fd = -1, vm_fd = -1; const char *errp, *title = NULL; int argc0 = argc; char dev_type = '\0'; @@ -798,7 +799,7 @@ main(int argc, char **argv) if ((env = calloc(1, sizeof(*env))) == NULL) fatal("calloc: env"); - while ((ch = getopt(argc, argv, "D:P:I:V:X:df:nt:v")) != -1) { + while ((ch = getopt(argc, argv, "D:P:I:V:X:df:i:nt:v")) != -1) { switch (ch) { case 'D': if (cmdline_symset(optarg) < 0) @@ -852,6 +853,11 @@ main(int argc, char **argv) default: fatalx("invalid device type"); } break; + case 'i': + vmm_fd = strtonum(optarg, 0, 128, &errp); + if (errp) + fatalx("invalid vmm fd"); + break; default: usage(); } @@ -880,7 +886,7 @@ main(int argc, char **argv) ps = &env->vmd_ps; ps->ps_env = env; - env->vmd_fd = -1; + env->vmd_fd = vmm_fd; if (config_init(env) == -1) fatal("failed to initialize configuration"); @@ -896,14 +902,14 @@ main(int argc, char **argv) * If we're launching a new vm or its device, we short out here. */ if (vm_launch == VMD_LAUNCH_VM) { - vm_main(vm_fd); + vm_main(vm_fd, vmm_fd); /* NOTREACHED */ } else if (vm_launch == VMD_LAUNCH_DEV) { if (dev_type == VMD_DEVTYPE_NET) { - vionet_main(vm_fd); + vionet_main(vm_fd, vmm_fd); /* NOTREACHED */ } else if (dev_type == VMD_DEVTYPE_DISK) { - vioblk_main(vm_fd); + vioblk_main(vm_fd, vmm_fd); /* NOTREACHED */ } fatalx("unsupported device type '%c'", dev_type); diff --git a/usr.sbin/vmd/vmd.h b/usr.sbin/vmd/vmd.h index 68de05447..9c25b0c92 100644 --- a/usr.sbin/vmd/vmd.h +++ b/usr.sbin/vmd/vmd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: vmd.h,v 1.121 2023/04/28 19:46:42 dv Exp $ */ +/* $OpenBSD: vmd.h,v 1.122 2023/05/13 23:15:28 dv Exp $ */ /* * Copyright (c) 2015 Mike Larkin @@ -329,9 +329,6 @@ struct vmd_vm { struct timeval vm_start_tv; int vm_start_limit; - int vm_memfds[VMM_MAX_MEM_RANGES]; - size_t vm_nmemfds; - TAILQ_ENTRY(vmd_vm) vm_entry; }; TAILQ_HEAD(vmlist, vmd_vm); @@ -488,7 +485,7 @@ int fd_hasdata(int); int vmm_pipe(struct vmd_vm *, int, void (*)(int, short, void *)); /* vm.c */ -void vm_main(int); +void vm_main(int, int); void mutex_lock(pthread_mutex_t *); void mutex_unlock(pthread_mutex_t *); int read_mem(paddr_t, void *buf, size_t); @@ -499,7 +496,7 @@ void vm_pipe_send(struct vm_dev_pipe *, enum pipe_msg_type); enum pipe_msg_type vm_pipe_recv(struct vm_dev_pipe *); int write_mem(paddr_t, const void *buf, size_t); void* hvaddr_mem(paddr_t, size_t); -int remap_guest_mem(struct vmd_vm *); +int remap_guest_mem(struct vmd_vm *, int); /* config.c */ int config_init(struct vmd *); @@ -527,9 +524,9 @@ int host(const char *, struct address *); int virtio_get_base(int, char *, size_t, int, const char *); /* vionet.c */ -__dead void vionet_main(int); +__dead void vionet_main(int, int); /* vioblk.c */ -__dead void vioblk_main(int); +__dead void vioblk_main(int, int); #endif /* VMD_H */ diff --git a/usr.sbin/vmd/vmm.c b/usr.sbin/vmd/vmm.c index 35119673d..7f307f99c 100644 --- a/usr.sbin/vmd/vmm.c +++ b/usr.sbin/vmd/vmm.c @@ -1,4 +1,4 @@ -/* $OpenBSD: vmm.c,v 1.111 2023/04/27 22:47:27 dv Exp $ */ +/* $OpenBSD: vmm.c,v 1.112 2023/05/13 23:15:28 dv Exp $ */ /* * Copyright (c) 2015 Mike Larkin @@ -627,7 +627,7 @@ vmm_start_vm(struct imsg *imsg, uint32_t *id, pid_t *pid) { struct vm_create_params *vcp; struct vmd_vm *vm; - char *nargv[6], num[32]; + char *nargv[8], num[32], vmm_fd[32]; int fd, ret = EINVAL; int fds[2]; pid_t vm_pid; @@ -701,16 +701,6 @@ vmm_start_vm(struct imsg *imsg, uint32_t *id, pid_t *pid) if (ret == EIO) goto err; - /* Send the fd number for /dev/vmm. */ - sz = atomicio(vwrite, fds[0], &env->vmd_fd, - sizeof(env->vmd_fd)); - if (sz != sizeof(env->vmd_fd)) { - log_warnx("%s: failed to send /dev/vmm fd for vm '%s'", - __func__, vcp->vcp_name); - ret = EIO; - goto err; - } - /* Read back the kernel-generated vm id from the child */ sz = atomicio(read, fds[0], &vcp->vcp_id, sizeof(vcp->vcp_id)); if (sz != sizeof(vcp->vcp_id)) { @@ -773,17 +763,21 @@ vmm_start_vm(struct imsg *imsg, uint32_t *id, pid_t *pid) memset(&nargv, 0, sizeof(nargv)); memset(num, 0, sizeof(num)); snprintf(num, sizeof(num), "%d", fds[1]); + memset(vmm_fd, 0, sizeof(vmm_fd)); + snprintf(vmm_fd, sizeof(vmm_fd), "%d", env->vmd_fd); nargv[0] = env->argv0; nargv[1] = "-V"; nargv[2] = num; nargv[3] = "-n"; + nargv[4] = "-i"; + nargv[5] = vmm_fd; if (env->vmd_verbose) { - nargv[4] = "-v"; - nargv[5] = NULL; + nargv[6] = "-v"; + nargv[7] = NULL; } else - nargv[4] = NULL; + nargv[6] = NULL; /* Control resumes in vmd main(). */ execvp(nargv[0], nargv);