CVS commit: src

2023-05-22 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Tue May 23 06:43:19 UTC 2023

Modified Files:
src/tests/usr.bin/indent: fmt_decl.c
src/usr.bin/indent: indent.c

Log Message:
indent: fix spacing around '*' in declarations


To generate a diff of this commit:
cvs rdiff -u -r1.44 -r1.45 src/tests/usr.bin/indent/fmt_decl.c
cvs rdiff -u -r1.305 -r1.306 src/usr.bin/indent/indent.c

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

Modified files:

Index: src/tests/usr.bin/indent/fmt_decl.c
diff -u src/tests/usr.bin/indent/fmt_decl.c:1.44 src/tests/usr.bin/indent/fmt_decl.c:1.45
--- src/tests/usr.bin/indent/fmt_decl.c:1.44	Tue May 23 06:18:00 2023
+++ src/tests/usr.bin/indent/fmt_decl.c	Tue May 23 06:43:19 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: fmt_decl.c,v 1.44 2023/05/23 06:18:00 rillig Exp $	*/
+/*	$NetBSD: fmt_decl.c,v 1.45 2023/05/23 06:43:19 rillig Exp $	*/
 
 /*
  * Tests for declarations of global variables, external functions, and local
@@ -1005,8 +1005,7 @@ void
 //indent run -ci4 -di0 -ndj -nlp
 void
 // $ FIXME: Wrong indentation, should be 0 instead.
-// $ FIXME: Wrong spacing around '*'.
- (error_at)(int msgid, const pos_t * pos, ...)
+ (error_at)(int msgid, const pos_t *pos, ...)
 {
 }
 //indent end

Index: src/usr.bin/indent/indent.c
diff -u src/usr.bin/indent/indent.c:1.305 src/usr.bin/indent/indent.c:1.306
--- src/usr.bin/indent/indent.c:1.305	Tue May 23 06:35:01 2023
+++ src/usr.bin/indent/indent.c	Tue May 23 06:43:19 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: indent.c,v 1.305 2023/05/23 06:35:01 rillig Exp $	*/
+/*	$NetBSD: indent.c,v 1.306 2023/05/23 06:43:19 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -38,7 +38,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: indent.c,v 1.305 2023/05/23 06:35:01 rillig Exp $");
+__RCSID("$NetBSD: indent.c,v 1.306 2023/05/23 06:43:19 rillig Exp $");
 
 #include 
 #include 
@@ -366,6 +366,8 @@ update_ps_decl_ptr(lexer_symbol lsym)
 		if (lsym == lsym_lparen_or_lbracket
 		&& ps.prev_token == lsym_for)
 			ps.decl_ptr = dp_start;
+		if (lsym == lsym_comma && ps.in_decl)
+			ps.decl_ptr = dp_start;
 		break;
 	}
 }



CVS commit: src

2023-05-22 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Tue May 23 06:43:19 UTC 2023

Modified Files:
src/tests/usr.bin/indent: fmt_decl.c
src/usr.bin/indent: indent.c

Log Message:
indent: fix spacing around '*' in declarations


To generate a diff of this commit:
cvs rdiff -u -r1.44 -r1.45 src/tests/usr.bin/indent/fmt_decl.c
cvs rdiff -u -r1.305 -r1.306 src/usr.bin/indent/indent.c

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



CVS commit: src

2023-05-22 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Tue May 23 06:35:01 UTC 2023

Modified Files:
src/tests/usr.bin/indent: lsym_for.c
src/usr.bin/indent: debug.c indent.c indent.h lexi.c

Log Message:
indent: fix spacing in declarations in for loops


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/tests/usr.bin/indent/lsym_for.c
cvs rdiff -u -r1.20 -r1.21 src/usr.bin/indent/debug.c
cvs rdiff -u -r1.304 -r1.305 src/usr.bin/indent/indent.c
cvs rdiff -u -r1.157 -r1.158 src/usr.bin/indent/indent.h
cvs rdiff -u -r1.203 -r1.204 src/usr.bin/indent/lexi.c

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

Modified files:

Index: src/tests/usr.bin/indent/lsym_for.c
diff -u src/tests/usr.bin/indent/lsym_for.c:1.5 src/tests/usr.bin/indent/lsym_for.c:1.6
--- src/tests/usr.bin/indent/lsym_for.c:1.5	Tue May 23 06:18:00 2023
+++ src/tests/usr.bin/indent/lsym_for.c	Tue May 23 06:35:01 2023
@@ -1,4 +1,4 @@
-/* $NetBSD: lsym_for.c,v 1.5 2023/05/23 06:18:00 rillig Exp $ */
+/* $NetBSD: lsym_for.c,v 1.6 2023/05/23 06:35:01 rillig Exp $ */
 
 /*
  * Tests for the token lsym_for, which represents the keyword 'for' that
@@ -89,17 +89,18 @@ function(void)
 //indent run-equals-input
 
 
+/* Ensure that the '*' after 'list_item' is a unary operator. */
 //indent input
 {
 	for (const list_item *i = first; i != NULL; i = i->next) {
 	}
-}
-//indent end
-
-//indent run
-{
-// $ FIXME: Wrong spacing after '*'.
-	for (const list_item * i = first; i != NULL; i = i->next) {
+	for (list_item **i = first; i != NULL; i = i->next) {
+	}
+	for (list_item *const *i = first; i != NULL; i = i->next) {
+	}
+	for (const char *const *i = first; i != NULL; i = i->next) {
 	}
 }
 //indent end
+
+//indent run-equals-input

Index: src/usr.bin/indent/debug.c
diff -u src/usr.bin/indent/debug.c:1.20 src/usr.bin/indent/debug.c:1.21
--- src/usr.bin/indent/debug.c:1.20	Mon May 22 10:28:59 2023
+++ src/usr.bin/indent/debug.c	Tue May 23 06:35:01 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: debug.c,v 1.20 2023/05/22 10:28:59 rillig Exp $	*/
+/*	$NetBSD: debug.c,v 1.21 2023/05/23 06:35:01 rillig Exp $	*/
 
 /*-
  * Copyright (c) 2023 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: debug.c,v 1.20 2023/05/22 10:28:59 rillig Exp $");
+__RCSID("$NetBSD: debug.c,v 1.21 2023/05/23 06:35:01 rillig Exp $");
 
 #include 
 
@@ -127,6 +127,13 @@ const char *const line_kind_name[] = {
 	"block comment",
 };
 
+static const char *const decl_ptr_name[] = {
+	"start",
+	"word",
+	"word *",
+	"other",
+};
+
 void
 debug_printf(const char *fmt, ...)
 {
@@ -316,6 +323,7 @@ debug_parser_state(lexer_symbol lsym)
 	debug_ps_bool(blank_line_after_decl);
 	debug_ps_bool(in_func_def_params);
 	debug_ps_enum(in_enum, in_enum_name);
+	debug_ps_enum(decl_ptr, decl_ptr_name);
 	debug_ps_bool(decl_indent_done);
 	debug_ps_int(decl_ind);
 	debug_ps_bool(tabs_to_var);

Index: src/usr.bin/indent/indent.c
diff -u src/usr.bin/indent/indent.c:1.304 src/usr.bin/indent/indent.c:1.305
--- src/usr.bin/indent/indent.c:1.304	Mon May 22 23:03:16 2023
+++ src/usr.bin/indent/indent.c	Tue May 23 06:35:01 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: indent.c,v 1.304 2023/05/22 23:03:16 rillig Exp $	*/
+/*	$NetBSD: indent.c,v 1.305 2023/05/23 06:35:01 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -38,7 +38,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: indent.c,v 1.304 2023/05/22 23:03:16 rillig Exp $");
+__RCSID("$NetBSD: indent.c,v 1.305 2023/05/23 06:35:01 rillig Exp $");
 
 #include 
 #include 
@@ -334,6 +334,42 @@ code_add_decl_indent(int decl_ind, bool 
 	}
 }
 
+static void
+update_ps_decl_ptr(lexer_symbol lsym)
+{
+	switch (ps.decl_ptr) {
+	case dp_start:
+		if (lsym == lsym_storage_class)
+			ps.decl_ptr = dp_start;
+		else if (lsym == lsym_type_outside_parentheses)
+			ps.decl_ptr = dp_word;
+		else if (lsym == lsym_word)
+			ps.decl_ptr = dp_word;
+		else
+			ps.decl_ptr = dp_other;
+		break;
+	case dp_word:
+		if (lsym == lsym_unary_op && token.st[0] == '*')
+			ps.decl_ptr = dp_word_asterisk;
+		else
+			ps.decl_ptr = dp_other;
+		break;
+	case dp_word_asterisk:
+		if (lsym == lsym_unary_op && token.st[0] == '*')
+			ps.decl_ptr = dp_word_asterisk;
+		else
+			ps.decl_ptr = dp_other;
+		break;
+	case dp_other:
+		if (lsym == lsym_semicolon || lsym == lsym_rbrace)
+			ps.decl_ptr = dp_start;
+		if (lsym == lsym_lparen_or_lbracket
+		&& ps.prev_token == lsym_for)
+			ps.decl_ptr = dp_start;
+		break;
+	}
+}
+
 static int
 process_eof(void)
 {
@@ -1006,6 +1042,8 @@ indent(void)
 move_com_to_code(lsym);
 		}
 
+		update_ps_decl_ptr(lsym);
+
 		switch (lsym) {
 
 		case lsym_newline:

Index: src/usr.bin/indent/indent.h
diff -u src/usr.bin/indent/indent.h:1.157 src/usr.bin/indent/indent.h:1.158
--- src/usr.bin/indent/indent.h:1.157	Mon May 22 10:28:59 2023
+++ src/usr.bin/indent/indent.h	Tue May 23 06:35:01 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: indent.h,v 1.157 2023/

CVS commit: src

2023-05-22 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Tue May 23 06:35:01 UTC 2023

Modified Files:
src/tests/usr.bin/indent: lsym_for.c
src/usr.bin/indent: debug.c indent.c indent.h lexi.c

Log Message:
indent: fix spacing in declarations in for loops


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/tests/usr.bin/indent/lsym_for.c
cvs rdiff -u -r1.20 -r1.21 src/usr.bin/indent/debug.c
cvs rdiff -u -r1.304 -r1.305 src/usr.bin/indent/indent.c
cvs rdiff -u -r1.157 -r1.158 src/usr.bin/indent/indent.h
cvs rdiff -u -r1.203 -r1.204 src/usr.bin/indent/lexi.c

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



CVS commit: src/tests/usr.bin/indent

2023-05-22 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Tue May 23 06:18:00 UTC 2023

Modified Files:
src/tests/usr.bin/indent: fmt_decl.c lsym_for.c lsym_unary_op.c
opt_bap.c opt_lp.c opt_sob.c

Log Message:
tests/indent: add code snippets found in make and lint1


To generate a diff of this commit:
cvs rdiff -u -r1.43 -r1.44 src/tests/usr.bin/indent/fmt_decl.c
cvs rdiff -u -r1.4 -r1.5 src/tests/usr.bin/indent/lsym_for.c
cvs rdiff -u -r1.6 -r1.7 src/tests/usr.bin/indent/lsym_unary_op.c \
src/tests/usr.bin/indent/opt_lp.c
cvs rdiff -u -r1.8 -r1.9 src/tests/usr.bin/indent/opt_bap.c
cvs rdiff -u -r1.7 -r1.8 src/tests/usr.bin/indent/opt_sob.c

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



CVS commit: src/tests/usr.bin/indent

2023-05-22 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Tue May 23 06:18:00 UTC 2023

Modified Files:
src/tests/usr.bin/indent: fmt_decl.c lsym_for.c lsym_unary_op.c
opt_bap.c opt_lp.c opt_sob.c

Log Message:
tests/indent: add code snippets found in make and lint1


To generate a diff of this commit:
cvs rdiff -u -r1.43 -r1.44 src/tests/usr.bin/indent/fmt_decl.c
cvs rdiff -u -r1.4 -r1.5 src/tests/usr.bin/indent/lsym_for.c
cvs rdiff -u -r1.6 -r1.7 src/tests/usr.bin/indent/lsym_unary_op.c \
src/tests/usr.bin/indent/opt_lp.c
cvs rdiff -u -r1.8 -r1.9 src/tests/usr.bin/indent/opt_bap.c
cvs rdiff -u -r1.7 -r1.8 src/tests/usr.bin/indent/opt_sob.c

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

Modified files:

Index: src/tests/usr.bin/indent/fmt_decl.c
diff -u src/tests/usr.bin/indent/fmt_decl.c:1.43 src/tests/usr.bin/indent/fmt_decl.c:1.44
--- src/tests/usr.bin/indent/fmt_decl.c:1.43	Tue May 16 08:22:11 2023
+++ src/tests/usr.bin/indent/fmt_decl.c	Tue May 23 06:18:00 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: fmt_decl.c,v 1.43 2023/05/16 08:22:11 rillig Exp $	*/
+/*	$NetBSD: fmt_decl.c,v 1.44 2023/05/23 06:18:00 rillig Exp $	*/
 
 /*
  * Tests for declarations of global variables, external functions, and local
@@ -960,3 +960,53 @@ ch_isalpha(char ch)
 //indent end
 
 //indent run-equals-input -i4 -di0
+
+
+//indent input
+struct {
+	void *list;
+	Table /* comment */ table;
+} var;
+//indent end
+
+//indent run -di0
+struct {
+	void *list;
+// $ FIXME: Wrong indentation, as 'Table' starts a new declaration.
+	 Table /* comment */ table;
+} var;
+//indent end
+
+
+//indent input
+void __printflike(1, 2)
+debug_printf(const char *fmt, ...)
+{
+}
+//indent end
+
+//indent run
+void
+// $ FIXME: No line break here.
+__printflike(1, 2)
+debug_printf(const char *fmt, ...)
+{
+}
+//indent end
+
+
+//indent input
+void
+(error_at)(int msgid, const pos_t *pos, ...)
+{
+}
+//indent end
+
+//indent run -ci4 -di0 -ndj -nlp
+void
+// $ FIXME: Wrong indentation, should be 0 instead.
+// $ FIXME: Wrong spacing around '*'.
+ (error_at)(int msgid, const pos_t * pos, ...)
+{
+}
+//indent end

Index: src/tests/usr.bin/indent/lsym_for.c
diff -u src/tests/usr.bin/indent/lsym_for.c:1.4 src/tests/usr.bin/indent/lsym_for.c:1.5
--- src/tests/usr.bin/indent/lsym_for.c:1.4	Sun Apr 24 10:36:37 2022
+++ src/tests/usr.bin/indent/lsym_for.c	Tue May 23 06:18:00 2023
@@ -1,4 +1,4 @@
-/* $NetBSD: lsym_for.c,v 1.4 2022/04/24 10:36:37 rillig Exp $ */
+/* $NetBSD: lsym_for.c,v 1.5 2023/05/23 06:18:00 rillig Exp $ */
 
 /*
  * Tests for the token lsym_for, which represents the keyword 'for' that
@@ -87,3 +87,19 @@ function(void)
 //indent end
 
 //indent run-equals-input
+
+
+//indent input
+{
+	for (const list_item *i = first; i != NULL; i = i->next) {
+	}
+}
+//indent end
+
+//indent run
+{
+// $ FIXME: Wrong spacing after '*'.
+	for (const list_item * i = first; i != NULL; i = i->next) {
+	}
+}
+//indent end

Index: src/tests/usr.bin/indent/lsym_unary_op.c
diff -u src/tests/usr.bin/indent/lsym_unary_op.c:1.6 src/tests/usr.bin/indent/lsym_unary_op.c:1.7
--- src/tests/usr.bin/indent/lsym_unary_op.c:1.6	Sat May 13 06:52:48 2023
+++ src/tests/usr.bin/indent/lsym_unary_op.c	Tue May 23 06:18:00 2023
@@ -1,4 +1,4 @@
-/* $NetBSD: lsym_unary_op.c,v 1.6 2023/05/13 06:52:48 rillig Exp $ */
+/* $NetBSD: lsym_unary_op.c,v 1.7 2023/05/23 06:18:00 rillig Exp $ */
 
 /*
  * Tests for the token lsym_unary_op, which represents a unary operator.
@@ -77,3 +77,18 @@ unary_operators(void)
 //indent end
 
 //indent run-equals-input -di0
+
+
+//indent input
+{
+sbuf_t *sb = *(sbuf_t **)sp;
+}
+//indent end
+
+//indent run -di0
+{
+// $ FIXME: Wrong spacing between the '*'.
+// $ FIXME: Wrong spacing after the cast.
+	sbuf_t *sb = *(sbuf_t * *) sp;
+}
+//indent end
Index: src/tests/usr.bin/indent/opt_lp.c
diff -u src/tests/usr.bin/indent/opt_lp.c:1.6 src/tests/usr.bin/indent/opt_lp.c:1.7
--- src/tests/usr.bin/indent/opt_lp.c:1.6	Sun Apr 24 09:04:12 2022
+++ src/tests/usr.bin/indent/opt_lp.c	Tue May 23 06:18:00 2023
@@ -1,4 +1,4 @@
-/* $NetBSD: opt_lp.c,v 1.6 2022/04/24 09:04:12 rillig Exp $ */
+/* $NetBSD: opt_lp.c,v 1.7 2023/05/23 06:18:00 rillig Exp $ */
 
 /*
  * Tests for the options '-lp' and '-nlp'.
@@ -87,3 +87,25 @@ example(void)
 	third_procedure(p4, p5));
 }
 //indent end
+
+
+//indent input
+{
+if (cond) {
+} else if (cond &&
+cond &&
+cond) {
+}
+}
+//indent end
+
+//indent run -ci4 -nlp
+{
+	if (cond) {
+	} else if (cond &&
+// $ FIXME: Wrong indentation, should be 4 spaces only.
+		cond &&
+	cond) {
+	}
+}
+//indent end

Index: src/tests/usr.bin/indent/opt_bap.c
diff -u src/tests/usr.bin/indent/opt_bap.c:1.8 src/tests/usr.bin/indent/opt_bap.c:1.9
--- src/tests/usr.bin/indent/opt_bap.c:1.8	Sat May 20 12:05:01 2023
+++ src/tests/usr.bin/indent/opt_bap.c	Tue May 23 06:18:00 2023
@@ -1,4 +1,4 @@
-/* $NetBSD: opt_bap.c,v 1.8 2023/05/20 12:05:01 rillig Exp $ */
+

CVS commit: src/sys/kern

2023-05-22 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Tue May 23 00:31:43 UTC 2023

Modified Files:
src/sys/kern: subr_autoconf.c

Log Message:
autoconf(9): Omit config_attach_pseudo kernel lock assertion for now.

Breaks too many things that I didn't test in the branch (cgd, fss,
&c.); let's address all forty-odd cases before turning it on.


To generate a diff of this commit:
cvs rdiff -u -r1.311 -r1.312 src/sys/kern/subr_autoconf.c

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



CVS commit: src/sys/kern

2023-05-22 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Tue May 23 00:31:43 UTC 2023

Modified Files:
src/sys/kern: subr_autoconf.c

Log Message:
autoconf(9): Omit config_attach_pseudo kernel lock assertion for now.

Breaks too many things that I didn't test in the branch (cgd, fss,
&c.); let's address all forty-odd cases before turning it on.


To generate a diff of this commit:
cvs rdiff -u -r1.311 -r1.312 src/sys/kern/subr_autoconf.c

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

Modified files:

Index: src/sys/kern/subr_autoconf.c
diff -u src/sys/kern/subr_autoconf.c:1.311 src/sys/kern/subr_autoconf.c:1.312
--- src/sys/kern/subr_autoconf.c:1.311	Mon May 22 14:58:22 2023
+++ src/sys/kern/subr_autoconf.c	Tue May 23 00:31:42 2023
@@ -1,4 +1,4 @@
-/* $NetBSD: subr_autoconf.c,v 1.311 2023/05/22 14:58:22 riastradh Exp $ */
+/* $NetBSD: subr_autoconf.c,v 1.312 2023/05/23 00:31:42 riastradh Exp $ */
 
 /*
  * Copyright (c) 1996, 2000 Christopher G. Demetriou
@@ -77,7 +77,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: subr_autoconf.c,v 1.311 2023/05/22 14:58:22 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: subr_autoconf.c,v 1.312 2023/05/23 00:31:42 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_ddb.h"
@@ -1994,8 +1994,6 @@ config_attach_pseudo(cfdata_t cf)
 {
 	device_t dev;
 
-	KASSERT(KERNEL_LOCKED_P());
-
 	dev = config_attach_pseudo_acquire(cf, NULL);
 	if (dev == NULL)
 		return dev;



CVS commit: src

2023-05-22 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Mon May 22 23:03:16 UTC 2023

Modified Files:
src/tests/usr.bin/indent: fmt_block.c
src/usr.bin/indent: indent.c

Log Message:
indent: fix spacing between block braces


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/tests/usr.bin/indent/fmt_block.c
cvs rdiff -u -r1.303 -r1.304 src/usr.bin/indent/indent.c

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

Modified files:

Index: src/tests/usr.bin/indent/fmt_block.c
diff -u src/tests/usr.bin/indent/fmt_block.c:1.6 src/tests/usr.bin/indent/fmt_block.c:1.7
--- src/tests/usr.bin/indent/fmt_block.c:1.6	Sat May 13 06:52:48 2023
+++ src/tests/usr.bin/indent/fmt_block.c	Mon May 22 23:03:16 2023
@@ -1,4 +1,4 @@
-/* $NetBSD: fmt_block.c,v 1.6 2023/05/13 06:52:48 rillig Exp $ */
+/* $NetBSD: fmt_block.c,v 1.7 2023/05/22 23:03:16 rillig Exp $ */
 
 /*
  * Tests for formatting blocks of statements and declarations.
@@ -47,24 +47,10 @@ void
 function(void)
 {
 	{
-/* $ FIXME: '{' must start a new line. */
-	} {
-	}
-}
-//indent end
-
-/*
- * The buggy behavior only occurs with the default setting '-br', which
- * places an opening brace to the right of the preceding 'if (expr)' or
- * similar statements.
- */
-//indent run -bl
-void
-function(void)
-{
-	{
 	}
 	{
 	}
 }
 //indent end
+
+//indent run-equals-prev-output -bl

Index: src/usr.bin/indent/indent.c
diff -u src/usr.bin/indent/indent.c:1.303 src/usr.bin/indent/indent.c:1.304
--- src/usr.bin/indent/indent.c:1.303	Mon May 22 10:28:59 2023
+++ src/usr.bin/indent/indent.c	Mon May 22 23:03:16 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: indent.c,v 1.303 2023/05/22 10:28:59 rillig Exp $	*/
+/*	$NetBSD: indent.c,v 1.304 2023/05/22 23:03:16 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -38,7 +38,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: indent.c,v 1.303 2023/05/22 10:28:59 rillig Exp $");
+__RCSID("$NetBSD: indent.c,v 1.304 2023/05/22 23:03:16 rillig Exp $");
 
 #include 
 #include 
@@ -669,7 +669,8 @@ process_lbrace(void)
 		ps.block_init_level++;
 
 	if (code.len > 0 && !ps.block_init) {
-		if (!opt.brace_same_line)
+		if (!opt.brace_same_line ||
+		(code.len > 0 && code.mem[code.len - 1] == '}'))
 			output_line();
 		else if (ps.in_func_def_params && !ps.init_or_struct) {
 			ps.ind_level_follow = 0;



CVS commit: src

2023-05-22 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Mon May 22 23:03:16 UTC 2023

Modified Files:
src/tests/usr.bin/indent: fmt_block.c
src/usr.bin/indent: indent.c

Log Message:
indent: fix spacing between block braces


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/tests/usr.bin/indent/fmt_block.c
cvs rdiff -u -r1.303 -r1.304 src/usr.bin/indent/indent.c

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



CVS commit: src/tests/usr.bin/indent

2023-05-22 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Mon May 22 23:01:27 UTC 2023

Modified Files:
src/tests/usr.bin/indent: edge_cases.c lsym_do.c lsym_funcname.c

Log Message:
tests/indent: refine a few tests


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/tests/usr.bin/indent/edge_cases.c
cvs rdiff -u -r1.6 -r1.7 src/tests/usr.bin/indent/lsym_do.c
cvs rdiff -u -r1.4 -r1.5 src/tests/usr.bin/indent/lsym_funcname.c

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

Modified files:

Index: src/tests/usr.bin/indent/edge_cases.c
diff -u src/tests/usr.bin/indent/edge_cases.c:1.1 src/tests/usr.bin/indent/edge_cases.c:1.2
--- src/tests/usr.bin/indent/edge_cases.c:1.1	Sun Apr 24 10:36:37 2022
+++ src/tests/usr.bin/indent/edge_cases.c	Mon May 22 23:01:27 2023
@@ -1,4 +1,4 @@
-/* $NetBSD: edge_cases.c,v 1.1 2022/04/24 10:36:37 rillig Exp $ */
+/* $NetBSD: edge_cases.c,v 1.2 2023/05/22 23:01:27 rillig Exp $ */
 
 /*
  * Tests for edge cases in the C programming language that indent does not
@@ -7,7 +7,8 @@
 
 /*
  * Digraphs are replacements for the characters '[', '{' and '#', which are
- * missing in some exotic restricted source character sets.
+ * missing in some exotic restricted source character sets.  They are not used
+ * in practice, therefore indent doesn't need to support them.
  *
  * See C99 6.4.6
  */
@@ -28,12 +29,15 @@ void
 digraphs(void)
 {
 	/* same as 'array[subscript]' */
-// $ XXX: The indentation is completely wrong.
-// $ XXX: The space between 'array' and '<' doesn't belong there.
+// $ Indent interprets everything before the second ':' as a label name,
+// $ therefore the statement is indented that far to the left.
+// $
+// $ The space between 'array' and '<' comes from the binary operator '<'.
 number = array <:subscript:>;
 
 	/* same as '(int){ initializer }' */
-// $ XXX: The space between '%' and '>' doesn't belong there.
+// $ The opening '<' and '%' are interpreted as unary operators.
+// $ The closing '%' and '>' are interpreted as a binary and unary operator.
 	number = (int)<%initializer % >;
 }
 //indent end

Index: src/tests/usr.bin/indent/lsym_do.c
diff -u src/tests/usr.bin/indent/lsym_do.c:1.6 src/tests/usr.bin/indent/lsym_do.c:1.7
--- src/tests/usr.bin/indent/lsym_do.c:1.6	Sat May 13 06:52:48 2023
+++ src/tests/usr.bin/indent/lsym_do.c	Mon May 22 23:01:27 2023
@@ -1,4 +1,4 @@
-/* $NetBSD: lsym_do.c,v 1.6 2023/05/13 06:52:48 rillig Exp $ */
+/* $NetBSD: lsym_do.c,v 1.7 2023/05/22 23:01:27 rillig Exp $ */
 
 /*
  * Tests for the token lsym_do, which represents the keyword 'do' that starts
@@ -86,3 +86,27 @@ variants(void)
 		} while (0);
 }
 //indent end
+
+//indent run -bl
+void
+variants(void)
+{
+	do
+		stmt();
+	while (0);
+
+	do
+	{
+		stmt();
+	} while (0);
+
+	do			/* comment */
+		stmt();
+	while (0);
+
+	while (0)
+		do
+		{
+		} while (0);
+}
+//indent end

Index: src/tests/usr.bin/indent/lsym_funcname.c
diff -u src/tests/usr.bin/indent/lsym_funcname.c:1.4 src/tests/usr.bin/indent/lsym_funcname.c:1.5
--- src/tests/usr.bin/indent/lsym_funcname.c:1.4	Sun Apr 24 10:36:37 2022
+++ src/tests/usr.bin/indent/lsym_funcname.c	Mon May 22 23:01:27 2023
@@ -1,10 +1,8 @@
-/* $NetBSD: lsym_funcname.c,v 1.4 2022/04/24 10:36:37 rillig Exp $ */
+/* $NetBSD: lsym_funcname.c,v 1.5 2023/05/22 23:01:27 rillig Exp $ */
 
 /*
- * Tests for the token lsym_funcname, which is an identifier that is followed
- * by an opening parenthesis.
- *
- * TODO: Document how lsym_funcname is handled differently from lsym_word.
+ * Tests for the token lsym_funcname, which is the name of a function, but only
+ * in a function definition, not in a declaration or a call expression.
  *
  * See also:
  *	lsym_word.c



CVS commit: src/tests/usr.bin/indent

2023-05-22 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Mon May 22 23:01:27 UTC 2023

Modified Files:
src/tests/usr.bin/indent: edge_cases.c lsym_do.c lsym_funcname.c

Log Message:
tests/indent: refine a few tests


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/tests/usr.bin/indent/edge_cases.c
cvs rdiff -u -r1.6 -r1.7 src/tests/usr.bin/indent/lsym_do.c
cvs rdiff -u -r1.4 -r1.5 src/tests/usr.bin/indent/lsym_funcname.c

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



CVS commit: src/sys/external/bsd/drm2/i915drm

2023-05-22 Thread Nathanial Sloss
Module Name:src
Committed By:   nat
Date:   Mon May 22 22:36:53 UTC 2023

Modified Files:
src/sys/external/bsd/drm2/i915drm: intelfb.c

Log Message:
Use the offset in mmap calculations.

It fixes wsfb(4) when used with intelfb(4).

Ok riastradh@

XXX pullup-10


To generate a diff of this commit:
cvs rdiff -u -r1.24 -r1.25 src/sys/external/bsd/drm2/i915drm/intelfb.c

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

Modified files:

Index: src/sys/external/bsd/drm2/i915drm/intelfb.c
diff -u src/sys/external/bsd/drm2/i915drm/intelfb.c:1.24 src/sys/external/bsd/drm2/i915drm/intelfb.c:1.25
--- src/sys/external/bsd/drm2/i915drm/intelfb.c:1.24	Mon Jul 18 23:34:02 2022
+++ src/sys/external/bsd/drm2/i915drm/intelfb.c	Mon May 22 22:36:53 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: intelfb.c,v 1.24 2022/07/18 23:34:02 riastradh Exp $	*/
+/*	$NetBSD: intelfb.c,v 1.25 2023/05/22 22:36:53 nat Exp $	*/
 
 /*-
  * Copyright (c) 2014 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: intelfb.c,v 1.24 2022/07/18 23:34:02 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: intelfb.c,v 1.25 2023/05/22 22:36:53 nat Exp $");
 
 #include 
 #include 
@@ -181,8 +181,8 @@ intelfb_drmfb_mmapfb(struct drmfb_softc 
 	KASSERT(0 <= offset);
 	KASSERT(offset < vma->node.size);
 
-	return bus_space_mmap(dev->bst, ggtt->gmadr.start, vma->node.start,
-	prot, BUS_SPACE_MAP_PREFETCHABLE);
+	return bus_space_mmap(dev->bst, ggtt->gmadr.start,
+	vma->node.start + offset, prot, BUS_SPACE_MAP_PREFETCHABLE);
 }
 
 static void



CVS commit: src/sys/external/bsd/drm2/i915drm

2023-05-22 Thread Nathanial Sloss
Module Name:src
Committed By:   nat
Date:   Mon May 22 22:36:53 UTC 2023

Modified Files:
src/sys/external/bsd/drm2/i915drm: intelfb.c

Log Message:
Use the offset in mmap calculations.

It fixes wsfb(4) when used with intelfb(4).

Ok riastradh@

XXX pullup-10


To generate a diff of this commit:
cvs rdiff -u -r1.24 -r1.25 src/sys/external/bsd/drm2/i915drm/intelfb.c

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



CVS commit: src/usr.bin/indent

2023-05-22 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Mon May 22 22:09:46 UTC 2023

Modified Files:
src/usr.bin/indent: lexi.c

Log Message:
indent: adjust indentation in lexer

No binary change.


To generate a diff of this commit:
cvs rdiff -u -r1.202 -r1.203 src/usr.bin/indent/lexi.c

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

Modified files:

Index: src/usr.bin/indent/lexi.c
diff -u src/usr.bin/indent/lexi.c:1.202 src/usr.bin/indent/lexi.c:1.203
--- src/usr.bin/indent/lexi.c:1.202	Sat May 20 11:53:53 2023
+++ src/usr.bin/indent/lexi.c	Mon May 22 22:09:45 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: lexi.c,v 1.202 2023/05/20 11:53:53 rillig Exp $	*/
+/*	$NetBSD: lexi.c,v 1.203 2023/05/22 22:09:45 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -38,7 +38,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: lexi.c,v 1.202 2023/05/20 11:53:53 rillig Exp $");
+__RCSID("$NetBSD: lexi.c,v 1.203 2023/05/22 22:09:45 rillig Exp $");
 
 #include 
 #include 
@@ -559,19 +559,19 @@ lexi(void)
 
 	switch (token.mem[token.len - 1]) {
 
-/* INDENT OFF */
-case '(':
-case '[':	lsym = lsym_lparen_or_lbracket;	next_unary = true;	break;
-case ')':
-case ']':	lsym = lsym_rparen_or_rbracket;	next_unary = false;	break;
-case '?':	lsym = lsym_question;		next_unary = true;	break;
-case ':':	lsym = lsym_colon;		next_unary = true;	break;
-case ';':	lsym = lsym_semicolon;		next_unary = true;	break;
-case '{':	lsym = lsym_lbrace;		next_unary = true;	break;
-case '}':	lsym = lsym_rbrace;		next_unary = true;	break;
-case ',':	lsym = lsym_comma;		next_unary = true;	break;
-case '.':	lsym = lsym_period;		next_unary = false;	break;
-/* INDENT ON */
+	/* INDENT OFF */
+	case '(':
+	case '[': lsym = lsym_lparen_or_lbracket; next_unary = true;	break;
+	case ')':
+	case ']': lsym = lsym_rparen_or_rbracket; next_unary = false;	break;
+	case '?':	lsym = lsym_question;	next_unary = true;	break;
+	case ':':	lsym = lsym_colon;	next_unary = true;	break;
+	case ';':	lsym = lsym_semicolon;	next_unary = true;	break;
+	case '{':	lsym = lsym_lbrace;	next_unary = true;	break;
+	case '}':	lsym = lsym_rbrace;	next_unary = true;	break;
+	case ',':	lsym = lsym_comma;	next_unary = true;	break;
+	case '.':	lsym = lsym_period;	next_unary = false;	break;
+	/* INDENT ON */
 
 	case '\n':
 		/* if data has been exhausted, the '\n' is a dummy. */



CVS commit: src/usr.bin/indent

2023-05-22 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Mon May 22 22:09:46 UTC 2023

Modified Files:
src/usr.bin/indent: lexi.c

Log Message:
indent: adjust indentation in lexer

No binary change.


To generate a diff of this commit:
cvs rdiff -u -r1.202 -r1.203 src/usr.bin/indent/lexi.c

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



CVS commit: src/tests/usr.bin/xlint/lint1

2023-05-22 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Mon May 22 20:11:24 UTC 2023

Modified Files:
src/tests/usr.bin/xlint/lint1: emit.exp-ln emit_lp64.exp-ln
t_integration.sh

Log Message:
tests/lint1: allow whitespace in files containing the expected output

This reduces the amount of wizardry needed to interpret the files.  For
a more gentle introduction of the file format, see ../lint2/msg_000.ln.

The whitespace that is removed is very similar to the one in the lint2
tests, the difference is that '%' and '%#' need to be preserved
in abbreviated printf and scanf format strings.


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 src/tests/usr.bin/xlint/lint1/emit.exp-ln
cvs rdiff -u -r1.1 -r1.2 src/tests/usr.bin/xlint/lint1/emit_lp64.exp-ln
cvs rdiff -u -r1.79 -r1.80 src/tests/usr.bin/xlint/lint1/t_integration.sh

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

Modified files:

Index: src/tests/usr.bin/xlint/lint1/emit.exp-ln
diff -u src/tests/usr.bin/xlint/lint1/emit.exp-ln:1.12 src/tests/usr.bin/xlint/lint1/emit.exp-ln:1.13
--- src/tests/usr.bin/xlint/lint1/emit.exp-ln:1.12	Mon May 22 17:53:27 2023
+++ src/tests/usr.bin/xlint/lint1/emit.exp-ln	Mon May 22 20:11:24 2023
@@ -1,85 +1,85 @@
-0semit.c
-Semit.c
-47d0.47e12extern__BoolB
-48d0.48e21extern__Complex_floatsX
-49d0.49e22extern__Complex_doubleX
-50d0.50e27extern__Complex_long_doublelX
-51d0.51e11extern_charC
-52d0.52e18extern_signed_charsC
-53d0.53e20extern_unsigned_charuC
-54d0.54e12extern_shortS
-55d0.55e19extern_signed_shortS
-56d0.56e21extern_unsigned_shortuS
-57d0.57e10extern_intI
-58d0.58e17extern_signed_intI
-59d0.59e19extern_unsigned_intuI
-60d0.60e11extern_longL
-61d0.61e18extern_signed_longL
-62d0.62e20extern_unsigned_longuL
-63d0.63e16extern_long_longQ
-64d0.64e23extern_signed_long_longQ
-65d0.65e25extern_unsigned_long_longuQ
-66d0.66e12extern_floatsD
-67d0.67e13extern_doubleD
-68d0.68e18extern_long_doublelD
-74d0.74e22extern_pointer_to_voidPV
-75d0.75e21extern_array_5_of_intA5I
-82d0.82e17extern_struct_tagsT110struct_tag
-83d0.83e21extern_struct_typedefsT214struct_typedef
-84d0.84e16extern_union_taguT19union_tag
-85d0.85e20extern_union_typedefuT213union_typedef
-86d0.86e15extern_enum_tageT18enum_tag
-87d0.87e19extern_enum_typedefeT212enum_typedef
-91d0.91e23extern_anonymous_structsT389.0.0
-94d0.94e22extern_anonymous_unionuT392.0.0
-97d0.97e21extern_anonymous_enumeT395.0.0
-105d0.105e12declared_intI
-106d0.106t11defined_intI
-114d0.114e16extern_const_intcI
-115d0.115e19extern_volatile_intvI
-116d0.116e25extern_const_volatile_intcvI
-122d0.122e30return_void_unknown_parametersFV
-123d0.123e38return_implicit_int_unknown_parametersFI
-126d0.126e32extern_return_void_no_parametersF0V
-127d0.127e25return_void_no_parametersF0V
-129d0.129es32static_return_void_no_parametersF0V
-131d0.131e10taking_intF1IV
-133d0.133e16taking_const_intF1cIV
-134d0.134e22taking_int_double_boolF3IDBV
-136d0.135e29taking_struct_union_enum_tagsF3sT110struct_taguT19union_tageT18enum_tagV
-138d0.137e33taking_struct_union_enum_typedefsF3sT214struct_typedefuT213union_typedefeT212enum_typedefV
-140d0.140e14taking_varargsF2PcCEV
-149d0.149es15static_functionF0I
-151d0.151e9my_printfF2PcCEV
-152d0.152e8my_scanfF2PcCEV
-165c0.165s2"%"i9my_printff2PcCPCV
-166c0.166s2"%s"i9my_printff2PcCPCV
-167c0.167s2"%%"i9my_printff2PcCPCV
-168c0.168s2"%\\%\"%\'%\a%\b%\f%\n%\r%\t%\v%\177"i9my_printff2PcCPCV
-163d0.163d14cover_outqcharF0V
-174c0.174s2"%-3d%+3d% d%#x%03d%*.*s%6.2f%hd%ld%Ld%qd"i9my_printff2PcCPCV
-175c0.175s2"%[-]%[--]%[---]%[]"i8my_scanff2PcCPCV
-172d0.172d14cover_outfstrgF0V
-184d0.184d17call_gcc_builtinsF2IPLV
-204d0.204v0d15varargs_commentF1PcCV
-210d0.210v0d17varargs_0_commentF1PcCV
-216d0.216v3d17varargs_3_commentF4IIIPcCV
-222d0.222d18printflike_commentF1PcCV
-228d0.228d20printflike_0_commentF1PcCV
-234d0.234v3P3d20printflike_3_commentF3IIPcCV
-240d0.240v10P10d21printflike_10_commentF10IPcCV
-248d0.248d17scanflike_commentF1PcCV
-254d0.254d19scanflike_0_commentF1PcCV
-260d0.260v3S3d19scanflike_3_commentF3IIPcCV
-265d0.265dr13used_functionF0I
-273c0.273i13used_functionf0I
-274c0.274d13used_functionf0I
-275c0.275u13used_functionf0I
-271d0.271dri15inline_functionF0I
-278d0.278e17declared_used_varI
-279d0.279t16defined_used_varI
-288u0.288x17declared_used_var
-289u0.289x16defined_used_var
-286d0.286d8use_varsF0V
-305d0.305d8compoundsT134compound_expression_in_initializer
-317d0.317d21array_of_unknown_sizeA8cC
+0 s emit.c
+S emit.c
+47 d 0.47 e 12extern__Bool B
+48 d 0.48 e 21extern__Complex_float sX
+49 d 0.49 e 22extern__Complex_double X
+50 d 0.50 e 27extern__Complex_long_double lX
+51 d 0.51 e 11extern_char C
+52 d 0.52 e 18extern_signed_char sC
+53 d 0.53 e 20extern_unsigned_char uC
+54 d 0.54 e 12extern_short S
+55 d 0.55 e 19extern_signed_short S
+56 d 0.56 e 21extern_unsigned_short uS
+57 d 0.57 e 10extern_int I
+58 d 0.58 e 17extern_signed_int I
+59 d 0.59 e 

CVS commit: src/tests/usr.bin/xlint/lint1

2023-05-22 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Mon May 22 20:11:24 UTC 2023

Modified Files:
src/tests/usr.bin/xlint/lint1: emit.exp-ln emit_lp64.exp-ln
t_integration.sh

Log Message:
tests/lint1: allow whitespace in files containing the expected output

This reduces the amount of wizardry needed to interpret the files.  For
a more gentle introduction of the file format, see ../lint2/msg_000.ln.

The whitespace that is removed is very similar to the one in the lint2
tests, the difference is that '%' and '%#' need to be preserved
in abbreviated printf and scanf format strings.


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 src/tests/usr.bin/xlint/lint1/emit.exp-ln
cvs rdiff -u -r1.1 -r1.2 src/tests/usr.bin/xlint/lint1/emit_lp64.exp-ln
cvs rdiff -u -r1.79 -r1.80 src/tests/usr.bin/xlint/lint1/t_integration.sh

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



CVS commit: src/usr.bin/xlint/xlint

2023-05-22 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Mon May 22 19:36:13 UTC 2023

Modified Files:
src/usr.bin/xlint/xlint: lint.1

Log Message:
lint.1: add a few examples

In default mode, lint runs in a mode that aids in migrating from
traditional C to C90, which is not widely useful nowadays.  Instead,
suggest some examples of using lint in more practical ways.


To generate a diff of this commit:
cvs rdiff -u -r1.57 -r1.58 src/usr.bin/xlint/xlint/lint.1

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



CVS commit: src/usr.bin/xlint/xlint

2023-05-22 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Mon May 22 19:36:13 UTC 2023

Modified Files:
src/usr.bin/xlint/xlint: lint.1

Log Message:
lint.1: add a few examples

In default mode, lint runs in a mode that aids in migrating from
traditional C to C90, which is not widely useful nowadays.  Instead,
suggest some examples of using lint in more practical ways.


To generate a diff of this commit:
cvs rdiff -u -r1.57 -r1.58 src/usr.bin/xlint/xlint/lint.1

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

Modified files:

Index: src/usr.bin/xlint/xlint/lint.1
diff -u src/usr.bin/xlint/xlint/lint.1:1.57 src/usr.bin/xlint/xlint/lint.1:1.58
--- src/usr.bin/xlint/xlint/lint.1:1.57	Sat Apr 15 12:29:43 2023
+++ src/usr.bin/xlint/xlint/lint.1	Mon May 22 19:36:13 2023
@@ -1,4 +1,4 @@
-.\" $NetBSD: lint.1,v 1.57 2023/04/15 12:29:43 rillig Exp $
+.\" $NetBSD: lint.1,v 1.58 2023/05/22 19:36:13 rillig Exp $
 .\"
 .\" Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
 .\" Copyright (c) 1994, 1995 Jochen Pohl
@@ -30,7 +30,7 @@
 .\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
 .\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 .\"
-.Dd January 21, 2023
+.Dd May 22, 2023
 .Dt LINT 1
 .Os
 .Sh NAME
@@ -277,8 +277,7 @@ and
 are always available).
 .It Fl H
 If a complaint stems from an included file,
-.Nm
-prints the name of the included file instead of the source file name
+print the name of the included file instead of the source file name
 followed by a question mark.
 .It Fl h
 Apply a number of heuristic tests to attempt to intuit
@@ -581,6 +580,11 @@ to be used to
 only the source files that have been modified since the last
 time the set of source files were
 .Nm Ns No ed .
+.Sh EXIT STATUS
+.Ex -std lint
+If the
+.Fl w
+flag is given, warnings are considered errors.
 .Sh ENVIRONMENT
 .Bl -tag -width Fl
 .It Ev LIBDIR
@@ -612,16 +616,43 @@ various prebuilt lint libraries
 .It Pa /tmp/lint*
 temporaries
 .El
+.Sh EXAMPLES
+.Bl -tag
+.It Li Nm Fl i Fl Sg Pa source.c
+Run
+.Nm
+in C99 mode with GNU extensions,
+with only few checks,
+creating
+.Pa source.ln .
+.It Li Nm Fl i Fl abcFghprSxz Pa source.c
+Run
+.Nm
+with the same checks as in the NetBSD build.
+.It Li Nm Fl i Fl Ac11 Fl g Fl aabceFhpPrTxz Pa source.c
+Run
+.Nm
+in C11 mode with GNU extensions,
+enabling all available checks,
+including lossy conversions on small integer types,
+unusual operations on enum types,
+more portability warnings,
+and strict bool mode.
+.El
+.\" .Sh DIAGNOSTICS
 .Sh SEE ALSO
 .Xr cc 1 ,
 .Xr cpp 1 ,
 .Xr make 1 ,
 .Xr lint 7
+.\" .Sh STANDARDS
+.\" .Sh HISTORY
 .Sh AUTHORS
 .An Jochen Pohl
 (1995)
 .An Roland Illig
 (2021)
+.\" .Sh CAVEATS
 .Sh BUGS
 The routines
 .Xr exit 3 ,
@@ -643,3 +674,4 @@ to be reported in error messages.
 For these reasons, it is recommended to use the
 .Fl C
 option to create lint libraries.
+.\" .Sh SECURITY CONSIDERATIONS



CVS commit: src/usr.bin/xlint/lint1

2023-05-22 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Mon May 22 18:10:58 UTC 2023

Modified Files:
src/usr.bin/xlint/lint1: decl.c

Log Message:
lint: use consistent variable name for redeclared symbol

No binary change.


To generate a diff of this commit:
cvs rdiff -u -r1.313 -r1.314 src/usr.bin/xlint/lint1/decl.c

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

Modified files:

Index: src/usr.bin/xlint/lint1/decl.c
diff -u src/usr.bin/xlint/lint1/decl.c:1.313 src/usr.bin/xlint/lint1/decl.c:1.314
--- src/usr.bin/xlint/lint1/decl.c:1.313	Mon May 22 17:53:27 2023
+++ src/usr.bin/xlint/lint1/decl.c	Mon May 22 18:10:57 2023
@@ -1,4 +1,4 @@
-/* $NetBSD: decl.c,v 1.313 2023/05/22 17:53:27 rillig Exp $ */
+/* $NetBSD: decl.c,v 1.314 2023/05/22 18:10:57 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -38,7 +38,7 @@
 
 #include 
 #if defined(__RCSID)
-__RCSID("$NetBSD: decl.c,v 1.313 2023/05/22 17:53:27 rillig Exp $");
+__RCSID("$NetBSD: decl.c,v 1.314 2023/05/22 18:10:57 rillig Exp $");
 #endif
 
 #include 
@@ -1997,8 +1997,8 @@ declare_extern(sym_t *dsym, bool has_ini
 		outsym(dsym, dsym->s_scl, dsym->s_def);
 	}
 
-	sym_t *rdsym;
-	if ((rdsym = dcs->d_redeclared_symbol) != NULL) {
+	sym_t *rdsym = dcs->d_redeclared_symbol;
+	if (rdsym != NULL) {
 
 		/*
 		 * If the old symbol stems from an old-style function
@@ -2107,58 +2107,58 @@ bool
 check_redeclaration(sym_t *dsym, bool *dowarn)
 {
 
-	sym_t *rsym = dcs->d_redeclared_symbol;
-	if (rsym->s_scl == ENUM_CONST) {
+	sym_t *rdsym = dcs->d_redeclared_symbol;
+	if (rdsym->s_scl == ENUM_CONST) {
 		/* redeclaration of '%s' */
 		error(27, dsym->s_name);
-		print_previous_declaration(rsym);
+		print_previous_declaration(rdsym);
 		return true;
 	}
-	if (rsym->s_scl == TYPEDEF) {
+	if (rdsym->s_scl == TYPEDEF) {
 		/* typedef '%s' redeclared */
 		error(89, dsym->s_name);
-		print_previous_declaration(rsym);
+		print_previous_declaration(rdsym);
 		return true;
 	}
 	if (dsym->s_scl == TYPEDEF) {
 		/* redeclaration of '%s' */
 		error(27, dsym->s_name);
-		print_previous_declaration(rsym);
+		print_previous_declaration(rdsym);
 		return true;
 	}
-	if (rsym->s_def == DEF && dsym->s_def == DEF) {
+	if (rdsym->s_def == DEF && dsym->s_def == DEF) {
 		/* redefinition of '%s' */
 		error(28, dsym->s_name);
-		print_previous_declaration(rsym);
+		print_previous_declaration(rdsym);
 		return true;
 	}
-	if (!types_compatible(rsym->s_type, dsym->s_type, false, false, dowarn)) {
+	if (!types_compatible(rdsym->s_type, dsym->s_type, false, false, dowarn)) {
 		/* redeclaration of '%s' with type '%s', expected '%s' */
 		error(347, dsym->s_name,
-		type_name(dsym->s_type), type_name(rsym->s_type));
-		print_previous_declaration(rsym);
+		type_name(dsym->s_type), type_name(rdsym->s_type));
+		print_previous_declaration(rdsym);
 		return true;
 	}
-	if (rsym->s_scl == EXTERN && dsym->s_scl == EXTERN)
+	if (rdsym->s_scl == EXTERN && dsym->s_scl == EXTERN)
 		return false;
-	if (rsym->s_scl == STATIC && dsym->s_scl == STATIC)
+	if (rdsym->s_scl == STATIC && dsym->s_scl == STATIC)
 		return false;
-	if (rsym->s_scl == STATIC && dsym->s_def == DECL)
+	if (rdsym->s_scl == STATIC && dsym->s_def == DECL)
 		return false;
-	if (rsym->s_scl == EXTERN && rsym->s_def == DEF) {
+	if (rdsym->s_scl == EXTERN && rdsym->s_def == DEF) {
 		/*
 		 * All cases except "int a = 1; static int a;" are caught
 		 * above with or without a warning
 		 */
 		/* redeclaration of '%s' */
 		error(27, dsym->s_name);
-		print_previous_declaration(rsym);
+		print_previous_declaration(rdsym);
 		return true;
 	}
-	if (rsym->s_scl == EXTERN) {
+	if (rdsym->s_scl == EXTERN) {
 		/* '%s' was previously declared extern, becomes static */
 		warning(29, dsym->s_name);
-		print_previous_declaration(rsym);
+		print_previous_declaration(rdsym);
 		return false;
 	}
 	/*
@@ -2169,7 +2169,7 @@ check_redeclaration(sym_t *dsym, bool *d
 	if (!allow_trad && !allow_c99) {
 		/* redeclaration of '%s'; ANSI C requires static */
 		warning(30, dsym->s_name);
-		print_previous_declaration(rsym);
+		print_previous_declaration(rdsym);
 	}
 	dsym->s_scl = STATIC;
 	return false;
@@ -2680,16 +2680,16 @@ check_local_hiding(const sym_t *dsym)
 }
 
 static void
-check_local_redeclaration(const sym_t *dsym, sym_t *rsym)
+check_local_redeclaration(const sym_t *dsym, sym_t *rdsym)
 {
-	if (rsym->s_block_level == 0) {
+	if (rdsym->s_block_level == 0) {
 		if (hflag)
 			check_local_hiding(dsym);
 
-	} else if (rsym->s_block_level == block_level) {
+	} else if (rdsym->s_block_level == block_level) {
 
 		/* no hflag, because it's illegal! */
-		if (rsym->s_arg) {
+		if (rdsym->s_arg) {
 			/*
 			 * if allow_c90, a "redeclaration of '%s'" error
 			 * is produced below
@@ -2699,21 +2699,21 @@ check_local_redeclaration(const sym_t *d
 	/* declaration of '%s' hides ... */
 	warning(91, dsym->s_name)

CVS commit: src/usr.bin/xlint/lint1

2023-05-22 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Mon May 22 18:10:58 UTC 2023

Modified Files:
src/usr.bin/xlint/lint1: decl.c

Log Message:
lint: use consistent variable name for redeclared symbol

No binary change.


To generate a diff of this commit:
cvs rdiff -u -r1.313 -r1.314 src/usr.bin/xlint/lint1/decl.c

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



CVS commit: src

2023-05-22 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Mon May 22 17:53:27 UTC 2023

Modified Files:
src/tests/usr.bin/xlint/lint1: emit.c emit.exp-ln
src/usr.bin/xlint/lint1: decl.c init.c

Log Message:
lint: fix emitted type for arrays of unknown size


To generate a diff of this commit:
cvs rdiff -u -r1.16 -r1.17 src/tests/usr.bin/xlint/lint1/emit.c
cvs rdiff -u -r1.11 -r1.12 src/tests/usr.bin/xlint/lint1/emit.exp-ln
cvs rdiff -u -r1.312 -r1.313 src/usr.bin/xlint/lint1/decl.c
cvs rdiff -u -r1.241 -r1.242 src/usr.bin/xlint/lint1/init.c

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

Modified files:

Index: src/tests/usr.bin/xlint/lint1/emit.c
diff -u src/tests/usr.bin/xlint/lint1/emit.c:1.16 src/tests/usr.bin/xlint/lint1/emit.c:1.17
--- src/tests/usr.bin/xlint/lint1/emit.c:1.16	Mon May 22 11:51:46 2023
+++ src/tests/usr.bin/xlint/lint1/emit.c	Mon May 22 17:53:27 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: emit.c,v 1.16 2023/05/22 11:51:46 rillig Exp $	*/
+/*	$NetBSD: emit.c,v 1.17 2023/05/22 17:53:27 rillig Exp $	*/
 # 3 "emit.c"
 
 /*
@@ -309,10 +309,9 @@ struct compound_expression_in_initialize
 };
 
 /*
- * FIXME: The type that ends up in the .ln file is 'A0cC', which is wrong as it
- * has array size 0 instead of the correct 8.
- *
- * This is caused by cgram_declare being called before processing the
+ * Before decl.c 1.312 and init.c 1.242 from 2023-05-22, the type that ended up
+ * in the .ln file was 'A0cC', which was wrong as it had array size 0 instead
+ * of the correct 8.  That type had been taken too early, before looking at the
  * initializer.
  */
 const char array_of_unknown_size[] = "unknown";

Index: src/tests/usr.bin/xlint/lint1/emit.exp-ln
diff -u src/tests/usr.bin/xlint/lint1/emit.exp-ln:1.11 src/tests/usr.bin/xlint/lint1/emit.exp-ln:1.12
--- src/tests/usr.bin/xlint/lint1/emit.exp-ln:1.11	Mon May 22 11:51:46 2023
+++ src/tests/usr.bin/xlint/lint1/emit.exp-ln	Mon May 22 17:53:27 2023
@@ -82,4 +82,4 @@ Semit.c
 289u0.289x16defined_used_var
 286d0.286d8use_varsF0V
 305d0.305d8compoundsT134compound_expression_in_initializer
-318d0.318d21array_of_unknown_sizeA0cC
+317d0.317d21array_of_unknown_sizeA8cC

Index: src/usr.bin/xlint/lint1/decl.c
diff -u src/usr.bin/xlint/lint1/decl.c:1.312 src/usr.bin/xlint/lint1/decl.c:1.313
--- src/usr.bin/xlint/lint1/decl.c:1.312	Mon May 22 17:47:27 2023
+++ src/usr.bin/xlint/lint1/decl.c	Mon May 22 17:53:27 2023
@@ -1,4 +1,4 @@
-/* $NetBSD: decl.c,v 1.312 2023/05/22 17:47:27 rillig Exp $ */
+/* $NetBSD: decl.c,v 1.313 2023/05/22 17:53:27 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -38,7 +38,7 @@
 
 #include 
 #if defined(__RCSID)
-__RCSID("$NetBSD: decl.c,v 1.312 2023/05/22 17:47:27 rillig Exp $");
+__RCSID("$NetBSD: decl.c,v 1.313 2023/05/22 17:53:27 rillig Exp $");
 #endif
 
 #include 
@@ -1992,7 +1992,8 @@ declare_extern(sym_t *dsym, bool has_ini
 		 */
 		bool rval = dsym->s_type->t_subt->t_tspec != VOID;
 		outfdef(dsym, &dsym->s_def_pos, rval, false, NULL);
-	} else if (!is_compiler_builtin(dsym->s_name)) {
+	} else if (!is_compiler_builtin(dsym->s_name)
+	&& !(has_initializer && dsym->s_type->t_incomplete_array)) {
 		outsym(dsym, dsym->s_scl, dsym->s_def);
 	}
 

Index: src/usr.bin/xlint/lint1/init.c
diff -u src/usr.bin/xlint/lint1/init.c:1.241 src/usr.bin/xlint/lint1/init.c:1.242
--- src/usr.bin/xlint/lint1/init.c:1.241	Sat Apr 22 17:49:15 2023
+++ src/usr.bin/xlint/lint1/init.c	Mon May 22 17:53:27 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: init.c,v 1.241 2023/04/22 17:49:15 rillig Exp $	*/
+/*	$NetBSD: init.c,v 1.242 2023/05/22 17:53:27 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -38,7 +38,7 @@
 
 #include 
 #if defined(__RCSID)
-__RCSID("$NetBSD: init.c,v 1.241 2023/04/22 17:49:15 rillig Exp $");
+__RCSID("$NetBSD: init.c,v 1.242 2023/05/22 17:53:27 rillig Exp $");
 #endif
 
 #include 
@@ -252,6 +252,7 @@ update_type_of_array_of_unknown_size(sym
 	tp->t_incomplete_array = false;
 	sym->s_type = tp;
 	debug_step("completed array type is '%s'", type_name(sym->s_type));
+	outsym(sym, sym->s_scl, sym->s_def);
 }
 
 



CVS commit: src

2023-05-22 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Mon May 22 17:53:27 UTC 2023

Modified Files:
src/tests/usr.bin/xlint/lint1: emit.c emit.exp-ln
src/usr.bin/xlint/lint1: decl.c init.c

Log Message:
lint: fix emitted type for arrays of unknown size


To generate a diff of this commit:
cvs rdiff -u -r1.16 -r1.17 src/tests/usr.bin/xlint/lint1/emit.c
cvs rdiff -u -r1.11 -r1.12 src/tests/usr.bin/xlint/lint1/emit.exp-ln
cvs rdiff -u -r1.312 -r1.313 src/usr.bin/xlint/lint1/decl.c
cvs rdiff -u -r1.241 -r1.242 src/usr.bin/xlint/lint1/init.c

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



CVS commit: src/usr.bin/xlint/lint1

2023-05-22 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Mon May 22 17:47:27 UTC 2023

Modified Files:
src/usr.bin/xlint/lint1: cgram.y decl.c

Log Message:
lint: clean up the name of a local variable

No binary change.


To generate a diff of this commit:
cvs rdiff -u -r1.435 -r1.436 src/usr.bin/xlint/lint1/cgram.y
cvs rdiff -u -r1.311 -r1.312 src/usr.bin/xlint/lint1/decl.c

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

Modified files:

Index: src/usr.bin/xlint/lint1/cgram.y
diff -u src/usr.bin/xlint/lint1/cgram.y:1.435 src/usr.bin/xlint/lint1/cgram.y:1.436
--- src/usr.bin/xlint/lint1/cgram.y:1.435	Sat Apr 22 17:49:15 2023
+++ src/usr.bin/xlint/lint1/cgram.y	Mon May 22 17:47:27 2023
@@ -1,5 +1,5 @@
 %{
-/* $NetBSD: cgram.y,v 1.435 2023/04/22 17:49:15 rillig Exp $ */
+/* $NetBSD: cgram.y,v 1.436 2023/05/22 17:47:27 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -35,7 +35,7 @@
 
 #include 
 #if defined(__RCSID)
-__RCSID("$NetBSD: cgram.y,v 1.435 2023/04/22 17:49:15 rillig Exp $");
+__RCSID("$NetBSD: cgram.y,v 1.436 2023/05/22 17:47:27 rillig Exp $");
 #endif
 
 #include 
@@ -2151,9 +2151,9 @@ cgram_print(FILE *output, int token, YYS
 #endif
 
 static void
-cgram_declare(sym_t *decl, bool initflg, sbuf_t *renaming)
+cgram_declare(sym_t *decl, bool has_initializer, sbuf_t *renaming)
 {
-	declare(decl, initflg, renaming);
+	declare(decl, has_initializer, renaming);
 	if (renaming != NULL)
 		freeyyv(&renaming, T_NAME);
 }

Index: src/usr.bin/xlint/lint1/decl.c
diff -u src/usr.bin/xlint/lint1/decl.c:1.311 src/usr.bin/xlint/lint1/decl.c:1.312
--- src/usr.bin/xlint/lint1/decl.c:1.311	Mon May 22 12:55:04 2023
+++ src/usr.bin/xlint/lint1/decl.c	Mon May 22 17:47:27 2023
@@ -1,4 +1,4 @@
-/* $NetBSD: decl.c,v 1.311 2023/05/22 12:55:04 rillig Exp $ */
+/* $NetBSD: decl.c,v 1.312 2023/05/22 17:47:27 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -38,7 +38,7 @@
 
 #include 
 #if defined(__RCSID)
-__RCSID("$NetBSD: decl.c,v 1.311 2023/05/22 12:55:04 rillig Exp $");
+__RCSID("$NetBSD: decl.c,v 1.312 2023/05/22 17:47:27 rillig Exp $");
 #endif
 
 #include 
@@ -1946,7 +1946,7 @@ check_extern_declaration(const sym_t *sy
 
 /* Process a single external or 'static' declarator. */
 static void
-declare_extern(sym_t *dsym, bool initflg, sbuf_t *renaming)
+declare_extern(sym_t *dsym, bool has_initializer, sbuf_t *renaming)
 {
 
 	if (renaming != NULL) {
@@ -1963,7 +1963,7 @@ declare_extern(sym_t *dsym, bool initflg
 
 	check_type(dsym);
 
-	if (initflg && !check_init(dsym))
+	if (has_initializer && !check_init(dsym))
 		dsym->s_def = DEF;
 
 	/*
@@ -2061,25 +2061,25 @@ declare_extern(sym_t *dsym, bool initflg
 }
 
 void
-declare(sym_t *decl, bool initflg, sbuf_t *renaming)
+declare(sym_t *decl, bool has_initializer, sbuf_t *renaming)
 {
 
 	if (dcs->d_kind == DK_EXTERN)
-		declare_extern(decl, initflg, renaming);
+		declare_extern(decl, has_initializer, renaming);
 	else if (dcs->d_kind == DK_OLD_STYLE_ARG ||
 		 dcs->d_kind == DK_PROTO_ARG) {
 		if (renaming != NULL) {
 			/* symbol renaming can't be used on function arguments */
 			error(310);
 		} else
-			(void)declare_argument(decl, initflg);
+			(void)declare_argument(decl, has_initializer);
 	} else {
 		lint_assert(dcs->d_kind == DK_AUTO);
 		if (renaming != NULL) {
 			/* symbol renaming can't be used on automatic variables */
 			error(311);
 		} else
-			declare_local(decl, initflg);
+			declare_local(decl, has_initializer);
 	}
 }
 
@@ -2414,7 +2414,7 @@ complete_type(sym_t *dsym, sym_t *ssym)
  * Completes the declaration of a single argument.
  */
 sym_t *
-declare_argument(sym_t *sym, bool initflg)
+declare_argument(sym_t *sym, bool has_initializer)
 {
 	tspec_t t;
 
@@ -2436,7 +2436,7 @@ declare_argument(sym_t *sym, bool initfl
 		sym->s_arg = true;
 	}
 
-	if (initflg) {
+	if (has_initializer) {
 		/* cannot initialize parameter '%s' */
 		error(52, sym->s_name);
 	}
@@ -2720,7 +2720,7 @@ check_local_redeclaration(const sym_t *d
  * Completes a single local declaration/definition.
  */
 void
-declare_local(sym_t *dsym, bool initflg)
+declare_local(sym_t *dsym, bool has_initializer)
 {
 
 	/* Correct a mistake done in declarator_name(). */
@@ -2785,7 +2785,7 @@ declare_local(sym_t *dsym, bool initflg)
 	if (dcs->d_redeclared_symbol != NULL)
 		check_local_redeclaration(dsym, dcs->d_redeclared_symbol);
 
-	if (initflg && !check_init(dsym)) {
+	if (has_initializer && !check_init(dsym)) {
 		dsym->s_def = DEF;
 		mark_as_set(dsym);
 	}



CVS commit: src/usr.bin/xlint/lint1

2023-05-22 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Mon May 22 17:47:27 UTC 2023

Modified Files:
src/usr.bin/xlint/lint1: cgram.y decl.c

Log Message:
lint: clean up the name of a local variable

No binary change.


To generate a diff of this commit:
cvs rdiff -u -r1.435 -r1.436 src/usr.bin/xlint/lint1/cgram.y
cvs rdiff -u -r1.311 -r1.312 src/usr.bin/xlint/lint1/decl.c

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



CVS commit: src/sys/arch/i386/conf

2023-05-22 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Mon May 22 16:28:34 UTC 2023

Modified Files:
src/sys/arch/i386/conf: GENERIC

Log Message:
i386/GENERIC: Enable EFI runtime support.

PR kern/57076

XXX pullup-10


To generate a diff of this commit:
cvs rdiff -u -r1.1246 -r1.1247 src/sys/arch/i386/conf/GENERIC

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

Modified files:

Index: src/sys/arch/i386/conf/GENERIC
diff -u src/sys/arch/i386/conf/GENERIC:1.1246 src/sys/arch/i386/conf/GENERIC:1.1247
--- src/sys/arch/i386/conf/GENERIC:1.1246	Thu Feb  9 14:09:48 2023
+++ src/sys/arch/i386/conf/GENERIC	Mon May 22 16:28:34 2023
@@ -1,4 +1,4 @@
-# $NetBSD: GENERIC,v 1.1246 2023/02/09 14:09:48 abs Exp $
+# $NetBSD: GENERIC,v 1.1247 2023/05/22 16:28:34 riastradh Exp $
 #
 # GENERIC machine description file
 #
@@ -22,7 +22,7 @@ include 	"arch/i386/conf/std.i386"
 
 options 	INCLUDE_CONFIG_FILE	# embed config file in kernel binary
 
-#ident		"GENERIC-$Revision: 1.1246 $"
+#ident		"GENERIC-$Revision: 1.1247 $"
 
 maxusers	64		# estimated number of users
 
@@ -1504,9 +1504,9 @@ pseudo-device	cmos
 # userland interface to drivers, including autoconf and properties retrieval
 pseudo-device	drvctl
 
-# EFI runtime support -- not yet tested
-#options 	EFI_RUNTIME
-#pseudo-device 	efi			# /dev/efi
+# EFI runtime support
+options 	EFI_RUNTIME
+pseudo-device 	efi			# /dev/efi
 
 include "dev/veriexec.config"
 



CVS commit: src/sys/arch/i386/conf

2023-05-22 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Mon May 22 16:28:34 UTC 2023

Modified Files:
src/sys/arch/i386/conf: GENERIC

Log Message:
i386/GENERIC: Enable EFI runtime support.

PR kern/57076

XXX pullup-10


To generate a diff of this commit:
cvs rdiff -u -r1.1246 -r1.1247 src/sys/arch/i386/conf/GENERIC

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



CVS commit: src/sys/arch/i386/conf

2023-05-22 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Mon May 22 16:28:25 UTC 2023

Modified Files:
src/sys/arch/i386/conf: ALL

Log Message:
i386/ALL: Enable EFI runtime support.

PR kern/57076

XXX pullup-10


To generate a diff of this commit:
cvs rdiff -u -r1.506 -r1.507 src/sys/arch/i386/conf/ALL

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

Modified files:

Index: src/sys/arch/i386/conf/ALL
diff -u src/sys/arch/i386/conf/ALL:1.506 src/sys/arch/i386/conf/ALL:1.507
--- src/sys/arch/i386/conf/ALL:1.506	Thu Feb  9 14:09:48 2023
+++ src/sys/arch/i386/conf/ALL	Mon May 22 16:28:25 2023
@@ -1,4 +1,4 @@
-# $NetBSD: ALL,v 1.506 2023/02/09 14:09:48 abs Exp $
+# $NetBSD: ALL,v 1.507 2023/05/22 16:28:25 riastradh Exp $
 # From NetBSD: GENERIC,v 1.787 2006/10/01 18:37:54 bouyer Exp
 #
 # ALL machine description file
@@ -17,7 +17,7 @@ include 	"arch/i386/conf/std.i386"
 
 options 	INCLUDE_CONFIG_FILE	# embed config file in kernel binary
 
-#ident		"ALL-$Revision: 1.506 $"
+#ident		"ALL-$Revision: 1.507 $"
 
 maxusers	64		# estimated number of users
 
@@ -1810,9 +1810,9 @@ pseudo-device	pad
 # userland interface to drivers, including autoconf and properties retrieval
 pseudo-device	drvctl
 
-# EFI runtime support -- doesn't build yet
-#options 	EFI_RUNTIME
-#pseudo-device 	efi			# /dev/efi
+# EFI runtime support
+options 	EFI_RUNTIME
+pseudo-device 	efi			# /dev/efi
 
 # Pass-to-Userspace Transporter
 pseudo-device	putter



CVS commit: src/sys/arch/i386/conf

2023-05-22 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Mon May 22 16:28:25 UTC 2023

Modified Files:
src/sys/arch/i386/conf: ALL

Log Message:
i386/ALL: Enable EFI runtime support.

PR kern/57076

XXX pullup-10


To generate a diff of this commit:
cvs rdiff -u -r1.506 -r1.507 src/sys/arch/i386/conf/ALL

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



CVS commit: src/sys/dev

2023-05-22 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Mon May 22 16:28:16 UTC 2023

Modified Files:
src/sys/dev: efi.c

Log Message:
efi(4): Translate between size_t and unsigned long.

Fixes i386 build.

PR kern/57076

XXX pullup-10


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/sys/dev/efi.c

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

Modified files:

Index: src/sys/dev/efi.c
diff -u src/sys/dev/efi.c:1.7 src/sys/dev/efi.c:1.8
--- src/sys/dev/efi.c:1.7	Mon May 22 16:27:58 2023
+++ src/sys/dev/efi.c	Mon May 22 16:28:16 2023
@@ -1,4 +1,4 @@
-/* $NetBSD: efi.c,v 1.7 2023/05/22 16:27:58 riastradh Exp $ */
+/* $NetBSD: efi.c,v 1.8 2023/05/22 16:28:16 riastradh Exp $ */
 
 /*-
  * Copyright (c) 2021 Jared McNeill 
@@ -32,7 +32,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: efi.c,v 1.7 2023/05/22 16:27:58 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: efi.c,v 1.8 2023/05/22 16:28:16 riastradh Exp $");
 
 #include 
 #include 
@@ -336,7 +336,8 @@ efi_ioctl_var_get(struct efi_var_ioc *va
 {
 	uint16_t *namebuf;
 	void *databuf = NULL;
-	size_t datasize;
+	size_t databufsize;
+	unsigned long datasize;
 	efi_status status;
 	int error;
 
@@ -347,6 +348,9 @@ efi_ioctl_var_get(struct efi_var_ioc *va
 	if (var->namesize > EFI_VARNAME_MAXLENGTH) {
 		return ENOMEM;
 	}
+	if (var->datasize > ULONG_MAX) { /* XXX stricter limit */
+		return ENOMEM;
+	}
 
 	namebuf = kmem_alloc(var->namesize, KM_SLEEP);
 	error = copyin(var->name, namebuf, var->namesize);
@@ -357,21 +361,24 @@ efi_ioctl_var_get(struct efi_var_ioc *va
 		error = EINVAL;
 		goto done;
 	}
-	datasize = var->datasize;
-	if (datasize != 0) {
-		databuf = kmem_alloc(datasize, KM_SLEEP);
-		error = copyin(var->data, databuf, datasize);
+	databufsize = var->datasize;
+	if (databufsize != 0) {
+		databuf = kmem_alloc(databufsize, KM_SLEEP);
+		error = copyin(var->data, databuf, databufsize);
 		if (error != 0) {
 			goto done;
 		}
 	}
 
+	datasize = databufsize;
 	status = efi_ops->efi_getvar(namebuf, &var->vendor, &var->attrib,
-	&var->datasize, databuf);
+	&datasize, databuf);
 	if (status != EFI_SUCCESS && status != EFI_BUFFER_TOO_SMALL) {
 		error = efi_status_to_error(status);
 		goto done;
 	}
+	KASSERT(datasize <= databufsize);
+	var->datasize = datasize;
 	if (status == EFI_SUCCESS && databuf != NULL) {
 		error = copyout(databuf, var->data, var->datasize);
 	} else {
@@ -381,7 +388,7 @@ efi_ioctl_var_get(struct efi_var_ioc *va
 done:
 	kmem_free(namebuf, var->namesize);
 	if (databuf != NULL) {
-		kmem_free(databuf, datasize);
+		kmem_free(databuf, databufsize);
 	}
 	return error;
 }
@@ -391,7 +398,8 @@ efi_ioctl_var_next(struct efi_var_ioc *v
 {
 	efi_status status;
 	uint16_t *namebuf;
-	size_t namesize;
+	size_t namebufsize;
+	unsigned long namesize;
 	int error;
 
 	if (var->name == NULL || var->namesize == 0) {
@@ -401,18 +409,22 @@ efi_ioctl_var_next(struct efi_var_ioc *v
 		return ENOMEM;
 	}
 
-	namesize = var->namesize;
-	namebuf = kmem_alloc(namesize, KM_SLEEP);
-	error = copyin(var->name, namebuf, namesize);
+	namebufsize = var->namesize;
+	namebuf = kmem_alloc(namebufsize, KM_SLEEP);
+	error = copyin(var->name, namebuf, namebufsize);
 	if (error != 0) {
 		goto done;
 	}
 
-	status = efi_ops->efi_nextvar(&var->namesize, namebuf, &var->vendor);
+	CTASSERT(EFI_VARNAME_MAXLENGTH <= ULONG_MAX);
+	namesize = namebufsize;
+	status = efi_ops->efi_nextvar(&namesize, namebuf, &var->vendor);
 	if (status != EFI_SUCCESS && status != EFI_BUFFER_TOO_SMALL) {
 		error = efi_status_to_error(status);
 		goto done;
 	}
+	KASSERT(namesize <= namebufsize);
+	var->namesize = namesize;
 	if (status == EFI_SUCCESS) {
 		error = copyout(namebuf, var->name, var->namesize);
 	} else {
@@ -420,7 +432,7 @@ efi_ioctl_var_next(struct efi_var_ioc *v
 	}
 
 done:
-	kmem_free(namebuf, namesize);
+	kmem_free(namebuf, namebufsize);
 	return error;
 }
 



CVS commit: src/sys

2023-05-22 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Mon May 22 16:27:59 UTC 2023

Modified Files:
src/sys/dev: efi.c efivar.h
src/sys/sys: efiio.h

Log Message:
efi(4): Implement MI parts of EFIIOC_GET_TABLE.

Intended to be compatible with FreeBSD.

Not yet supported on any architectures.

PR kern/57076

XXX pullup-10


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/sys/dev/efi.c
cvs rdiff -u -r1.1 -r1.2 src/sys/dev/efivar.h
cvs rdiff -u -r1.2 -r1.3 src/sys/sys/efiio.h

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



CVS commit: src/sys/dev

2023-05-22 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Mon May 22 16:28:16 UTC 2023

Modified Files:
src/sys/dev: efi.c

Log Message:
efi(4): Translate between size_t and unsigned long.

Fixes i386 build.

PR kern/57076

XXX pullup-10


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/sys/dev/efi.c

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



CVS commit: src/sys/arch/x86/x86

2023-05-22 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Mon May 22 16:28:08 UTC 2023

Modified Files:
src/sys/arch/x86/x86: efi_machdep.c

Log Message:
efi(4): Implement EFIIOC_GET_TABLE on x86.

PR kern/57076

XXX pullup-10


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/sys/arch/x86/x86/efi_machdep.c

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

Modified files:

Index: src/sys/arch/x86/x86/efi_machdep.c
diff -u src/sys/arch/x86/x86/efi_machdep.c:1.5 src/sys/arch/x86/x86/efi_machdep.c:1.6
--- src/sys/arch/x86/x86/efi_machdep.c:1.5	Mon May 22 16:27:48 2023
+++ src/sys/arch/x86/x86/efi_machdep.c	Mon May 22 16:28:07 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: efi_machdep.c,v 1.5 2023/05/22 16:27:48 riastradh Exp $	*/
+/*	$NetBSD: efi_machdep.c,v 1.6 2023/05/22 16:28:07 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2016 The NetBSD Foundation, Inc.
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: efi_machdep.c,v 1.5 2023/05/22 16:27:48 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: efi_machdep.c,v 1.6 2023/05/22 16:28:07 riastradh Exp $");
 
 #include "efi.h"
 #include "opt_efi.h"
@@ -973,12 +973,29 @@ efi_runtime_setvar(efi_char *name, struc
 	return status;
 }
 
+static efi_status
+efi_runtime_gettab(const struct uuid *vendor, uint64_t *addrp)
+{
+	struct efi_cfgtbl *cfgtbl = efi_getcfgtblhead();
+	paddr_t pa;
+
+	if (cfgtbl == NULL)
+		return EFI_UNSUPPORTED;
+
+	pa = efi_getcfgtblpa(vendor);
+	if (pa == 0)
+		return EFI_NOT_FOUND;
+	*addrp = pa;
+	return EFI_SUCCESS;
+}
+
 static struct efi_ops efi_runtime_ops = {
 	.efi_gettime = efi_runtime_gettime,
 	.efi_settime = efi_runtime_settime,
 	.efi_getvar = efi_runtime_getvar,
 	.efi_setvar = efi_runtime_setvar,
 	.efi_nextvar = efi_runtime_nextvar,
+	.efi_gettab = efi_runtime_gettab,
 };
 
 #endif	/* EFI_RUNTIME */



CVS commit: src/sys/arch/x86/x86

2023-05-22 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Mon May 22 16:28:08 UTC 2023

Modified Files:
src/sys/arch/x86/x86: efi_machdep.c

Log Message:
efi(4): Implement EFIIOC_GET_TABLE on x86.

PR kern/57076

XXX pullup-10


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/sys/arch/x86/x86/efi_machdep.c

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



CVS commit: src/sys

2023-05-22 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Mon May 22 16:27:59 UTC 2023

Modified Files:
src/sys/dev: efi.c efivar.h
src/sys/sys: efiio.h

Log Message:
efi(4): Implement MI parts of EFIIOC_GET_TABLE.

Intended to be compatible with FreeBSD.

Not yet supported on any architectures.

PR kern/57076

XXX pullup-10


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/sys/dev/efi.c
cvs rdiff -u -r1.1 -r1.2 src/sys/dev/efivar.h
cvs rdiff -u -r1.2 -r1.3 src/sys/sys/efiio.h

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

Modified files:

Index: src/sys/dev/efi.c
diff -u src/sys/dev/efi.c:1.6 src/sys/dev/efi.c:1.7
--- src/sys/dev/efi.c:1.6	Mon May 22 16:27:49 2023
+++ src/sys/dev/efi.c	Mon May 22 16:27:58 2023
@@ -1,4 +1,4 @@
-/* $NetBSD: efi.c,v 1.6 2023/05/22 16:27:49 riastradh Exp $ */
+/* $NetBSD: efi.c,v 1.7 2023/05/22 16:27:58 riastradh Exp $ */
 
 /*-
  * Copyright (c) 2021 Jared McNeill 
@@ -32,7 +32,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: efi.c,v 1.6 2023/05/22 16:27:49 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: efi.c,v 1.7 2023/05/22 16:27:58 riastradh Exp $");
 
 #include 
 #include 
@@ -40,7 +40,10 @@ __KERNEL_RCSID(0, "$NetBSD: efi.c,v 1.6 
 #include 
 #include 
 
+#include 
+
 #include 
+#include 
 
 #include "ioconf.h"
 
@@ -133,6 +136,201 @@ efi_status_to_error(efi_status status)
 	}
 }
 
+/* XXX move to efi.h */
+#define	EFI_SYSTEM_RESOURCE_TABLE_GUID	  \
+	{0xb122a263,0x3661,0x4f68,0x99,0x29,{0x78,0xf8,0xb0,0xd6,0x21,0x80}}
+#define	EFI_PROPERTIES_TABLE		  \
+	{0x880aaca3,0x4adc,0x4a04,0x90,0x79,{0xb7,0x47,0x34,0x08,0x25,0xe5}}
+
+#define	EFI_SYSTEM_RESOURCE_TABLE_FIRMWARE_RESOURCE_VERSION	1
+
+struct EFI_SYSTEM_RESOURCE_ENTRY {
+	struct uuid	FwClass;
+	uint32_t	FwType;
+	uint32_t	FwVersion;
+	uint32_t	LowestSupportedFwVersion;
+	uint32_t	CapsuleFlags;
+	uint32_t	LastAttemptVersion;
+	uint32_t	LastAttemptStatus;
+};
+
+struct EFI_SYSTEM_RESOURCE_TABLE {
+	uint32_t	FwResourceCount;
+	uint32_t	FwResourceCountMax;
+	uint64_t	FwResourceVersion;
+	struct EFI_SYSTEM_RESOURCE_ENTRY	Entries[];
+};
+
+static void *
+efi_map_pa(uint64_t addr, bool *directp)
+{
+	paddr_t pa = addr;
+	vaddr_t va;
+
+	/*
+	 * Verify the address is not truncated by conversion to
+	 * paddr_t.  This might happen with a 64-bit EFI booting a
+	 * 32-bit OS.
+	 */
+	if (pa != addr)
+		return NULL;
+
+	/*
+	 * Try direct-map if we have it.  If it works, note that it was
+	 * direct-mapped for efi_unmap.
+	 */
+#ifdef __HAVE_MM_MD_DIRECT_MAPPED_PHYS
+	if (mm_md_direct_mapped_phys(pa, &va)) {
+		*directp = true;
+		return (void *)va;
+	}
+#endif
+
+	/*
+	 * No direct map.  Reserve a page of kernel virtual address
+	 * space, with no backing, to map to the physical address.
+	 */
+	va = uvm_km_alloc(kernel_map, PAGE_SIZE, 0,
+	UVM_KMF_VAONLY|UVM_KMF_WAITVA);
+	KASSERT(va != 0);
+
+	/*
+	 * Map the kva page to the physical address and update the
+	 * kernel pmap so we can use it.
+	 */
+	pmap_kenter_pa(va, pa, VM_PROT_READ, 0);
+	pmap_update(pmap_kernel());
+
+	/*
+	 * Success!  Return the VA and note that it was not
+	 * direct-mapped for efi_unmap.
+	 */
+	*directp = false;
+	return (void *)va;
+}
+
+static void
+efi_unmap(void *ptr, bool direct)
+{
+	vaddr_t va = (vaddr_t)ptr;
+
+	/*
+	 * If it was direct-mapped, nothing to do here.
+	 */
+	if (direct)
+		return;
+
+	/*
+	 * First remove the mapping from the kernel pmap so that it can
+	 * be reused, before we free the kva and let anyone else reuse
+	 * it.
+	 */
+	pmap_kremove(va, PAGE_SIZE);
+	pmap_update(pmap_kernel());
+
+	/*
+	 * Next free the kva so it can be reused by someone else.
+	 */
+	uvm_km_free(kernel_map, va, PAGE_SIZE, UVM_KMF_VAONLY);
+}
+
+static int
+efi_ioctl_got_table(struct efi_get_table_ioc *ioc, void *ptr, size_t len)
+{
+
+	/*
+	 * Return the actual table length.
+	 */
+	ioc->table_len = len;
+
+	/*
+	 * Copy out as much as we can into the user's allocated buffer.
+	 */
+	return copyout(ptr, ioc->buf, MIN(ioc->buf_len, len));
+}
+
+static int
+efi_ioctl_get_esrt(struct efi_get_table_ioc *ioc,
+struct EFI_SYSTEM_RESOURCE_TABLE *tab)
+{
+
+	/*
+	 * Verify the firmware resource version is one we understand.
+	 */
+	if (tab->FwResourceVersion !=
+	EFI_SYSTEM_RESOURCE_TABLE_FIRMWARE_RESOURCE_VERSION)
+		return ENOENT;
+
+	/*
+	 * Verify the resource count fits within the single page we
+	 * have mapped.
+	 *
+	 * XXX What happens if it doesn't?  Are we expected to map more
+	 * than one page, according to the table header?  The UEFI spec
+	 * is unclear on this.
+	 */
+	const size_t entry_space = PAGE_SIZE -
+	offsetof(struct EFI_SYSTEM_RESOURCE_TABLE, Entries);
+	if (tab->FwResourceCount > entry_space/sizeof(tab->Entries[0]))
+		return ENOENT;
+
+	/*
+	 * Success!  Return everything through the last table entry.
+	 */
+	const size_t len = offsetof(struct EFI_SYSTEM_RESOURCE_TABLE,
+	Entries[tab->FwRes

CVS commit: src/sys

2023-05-22 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Mon May 22 16:27:49 UTC 2023

Modified Files:
src/sys/arch/arm/arm: efi_runtime.c
src/sys/arch/x86/x86: efi_machdep.c
src/sys/dev: efi.c
src/sys/dev/efi: efi.h

Log Message:
efi(4): Move error macros to efi.h.

PR kern/57076

XXX pullup-10


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/sys/arch/arm/arm/efi_runtime.c
cvs rdiff -u -r1.4 -r1.5 src/sys/arch/x86/x86/efi_machdep.c
cvs rdiff -u -r1.5 -r1.6 src/sys/dev/efi.c
cvs rdiff -u -r1.2 -r1.3 src/sys/dev/efi/efi.h

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

Modified files:

Index: src/sys/arch/arm/arm/efi_runtime.c
diff -u src/sys/arch/arm/arm/efi_runtime.c:1.10 src/sys/arch/arm/arm/efi_runtime.c:1.11
--- src/sys/arch/arm/arm/efi_runtime.c:1.10	Sat Oct 15 11:19:23 2022
+++ src/sys/arch/arm/arm/efi_runtime.c	Mon May 22 16:27:48 2023
@@ -1,4 +1,4 @@
-/* $NetBSD: efi_runtime.c,v 1.10 2022/10/15 11:19:23 jmcneill Exp $ */
+/* $NetBSD: efi_runtime.c,v 1.11 2023/05/22 16:27:48 riastradh Exp $ */
 
 /*-
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -32,7 +32,7 @@
 #include "efi.h"
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: efi_runtime.c,v 1.10 2022/10/15 11:19:23 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: efi_runtime.c,v 1.11 2023/05/22 16:27:48 riastradh Exp $");
 
 #include 
 #include 
@@ -45,15 +45,6 @@ __KERNEL_RCSID(0, "$NetBSD: efi_runtime.
 #include 
 #include 
 
-#ifdef _LP64
-#define	EFIERR(x)	(0x8000 | x)
-#else
-#define	EFIERR(x)	(0x8000 | x)
-#endif
-
-#define	EFI_UNSUPPORTED		EFIERR(3)
-#define	EFI_DEVICE_ERROR	EFIERR(7)
-
 static kmutex_t efi_lock;
 static struct efi_rt *RT;
 #if BYTE_ORDER == LITTLE_ENDIAN

Index: src/sys/arch/x86/x86/efi_machdep.c
diff -u src/sys/arch/x86/x86/efi_machdep.c:1.4 src/sys/arch/x86/x86/efi_machdep.c:1.5
--- src/sys/arch/x86/x86/efi_machdep.c:1.4	Sat Dec 24 15:23:02 2022
+++ src/sys/arch/x86/x86/efi_machdep.c	Mon May 22 16:27:48 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: efi_machdep.c,v 1.4 2022/12/24 15:23:02 andvar Exp $	*/
+/*	$NetBSD: efi_machdep.c,v 1.5 2023/05/22 16:27:48 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2016 The NetBSD Foundation, Inc.
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: efi_machdep.c,v 1.4 2022/12/24 15:23:02 andvar Exp $");
+__KERNEL_RCSID(0, "$NetBSD: efi_machdep.c,v 1.5 2023/05/22 16:27:48 riastradh Exp $");
 
 #include "efi.h"
 #include "opt_efi.h"
@@ -582,18 +582,6 @@ efi_get_e820memmap(void)
 #ifdef EFI_RUNTIME
 
 /*
- * XXX move to sys/dev/efi/efi.h
- */
-#ifdef _LP64
-#define	EFIERR(x)	(0x8000ul | (x))
-#else
-#define	EFIERR(x)	(0x8000ul | (x))
-#endif
-
-#define	EFI_UNSUPPORTED		EFIERR(3)
-#define	EFI_DEVICE_ERROR	EFIERR(7)
-
-/*
  * efi_runtime_init()
  *
  *	Set up kernel access to EFI runtime services:

Index: src/sys/dev/efi.c
diff -u src/sys/dev/efi.c:1.5 src/sys/dev/efi.c:1.6
--- src/sys/dev/efi.c:1.5	Mon May 22 16:27:39 2023
+++ src/sys/dev/efi.c	Mon May 22 16:27:49 2023
@@ -1,4 +1,4 @@
-/* $NetBSD: efi.c,v 1.5 2023/05/22 16:27:39 riastradh Exp $ */
+/* $NetBSD: efi.c,v 1.6 2023/05/22 16:27:49 riastradh Exp $ */
 
 /*-
  * Copyright (c) 2021 Jared McNeill 
@@ -32,7 +32,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: efi.c,v 1.5 2023/05/22 16:27:39 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: efi.c,v 1.6 2023/05/22 16:27:49 riastradh Exp $");
 
 #include 
 #include 
@@ -42,22 +42,6 @@ __KERNEL_RCSID(0, "$NetBSD: efi.c,v 1.5 
 
 #include 
 
-#ifdef _LP64
-#define	EFIERR(x)		(0x8000 | (x))
-#else
-#define	EFIERR(x)		(0x8000 | (x))
-#endif
-
-#define	EFI_SUCCESS		0
-#define	EFI_INVALID_PARAMETER	EFIERR(2)
-#define	EFI_UNSUPPORTED		EFIERR(3)
-#define	EFI_BUFFER_TOO_SMALL	EFIERR(5)
-#define	EFI_DEVICE_ERROR	EFIERR(7)
-#define	EFI_WRITE_PROTECTED	EFIERR(8)
-#define	EFI_OUT_OF_RESOURCES	EFIERR(9)
-#define	EFI_NOT_FOUND		EFIERR(14)
-#define	EFI_SECURITY_VIOLATION	EFIERR(26)
-
 #include "ioconf.h"
 
 /*

Index: src/sys/dev/efi/efi.h
diff -u src/sys/dev/efi/efi.h:1.2 src/sys/dev/efi/efi.h:1.3
--- src/sys/dev/efi/efi.h:1.2	Thu Sep 22 14:46:37 2022
+++ src/sys/dev/efi/efi.h	Mon May 22 16:27:49 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: efi.h,v 1.2 2022/09/22 14:46:37 riastradh Exp $	*/
+/*	$NetBSD: efi.h,v 1.3 2023/05/22 16:27:49 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2004 Marcel Moolenaar
@@ -44,6 +44,22 @@
 #define	EFIAPI	/* empty */
 #endif
 
+#ifdef _LP64
+#define	EFIERR(x)		(0x8000 | (x))
+#else
+#define	EFIERR(x)		(0x8000 | (x))
+#endif
+
+#define	EFI_SUCCESS		0
+#define	EFI_INVALID_PARAMETER	EFIERR(2)
+#define	EFI_UNSUPPORTED		EFIERR(3)
+#define	EFI_BUFFER_TOO_SMALL	EFIERR(5)
+#define	EFI_DEVICE_ERROR	EFIERR(7)
+#define	EFI_WRITE_PROTECTED	EFIERR(8)
+#define	EFI_OUT_OF_RESOURCES	EFIERR(9)
+#define	EFI_NOT_FOUND		EFIERR(14)
+#define	EFI_SECURITY_VIOLATION	EFIERR(26)
+
 enum efi_reset {
 	EFI_RESET_COLD,
 	EFI_RESET_W

CVS commit: src/sys

2023-05-22 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Mon May 22 16:27:49 UTC 2023

Modified Files:
src/sys/arch/arm/arm: efi_runtime.c
src/sys/arch/x86/x86: efi_machdep.c
src/sys/dev: efi.c
src/sys/dev/efi: efi.h

Log Message:
efi(4): Move error macros to efi.h.

PR kern/57076

XXX pullup-10


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/sys/arch/arm/arm/efi_runtime.c
cvs rdiff -u -r1.4 -r1.5 src/sys/arch/x86/x86/efi_machdep.c
cvs rdiff -u -r1.5 -r1.6 src/sys/dev/efi.c
cvs rdiff -u -r1.2 -r1.3 src/sys/dev/efi/efi.h

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



CVS commit: src/sys/dev

2023-05-22 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Mon May 22 16:27:39 UTC 2023

Modified Files:
src/sys/dev: efi.c

Log Message:
efi(4): Parenthesize EFIERR argument out of paranoia.

PR kern/57076

XXX pullup-10


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/sys/dev/efi.c

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

Modified files:

Index: src/sys/dev/efi.c
diff -u src/sys/dev/efi.c:1.4 src/sys/dev/efi.c:1.5
--- src/sys/dev/efi.c:1.4	Sat Sep 24 11:06:03 2022
+++ src/sys/dev/efi.c	Mon May 22 16:27:39 2023
@@ -1,4 +1,4 @@
-/* $NetBSD: efi.c,v 1.4 2022/09/24 11:06:03 riastradh Exp $ */
+/* $NetBSD: efi.c,v 1.5 2023/05/22 16:27:39 riastradh Exp $ */
 
 /*-
  * Copyright (c) 2021 Jared McNeill 
@@ -32,7 +32,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: efi.c,v 1.4 2022/09/24 11:06:03 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: efi.c,v 1.5 2023/05/22 16:27:39 riastradh Exp $");
 
 #include 
 #include 
@@ -43,9 +43,9 @@ __KERNEL_RCSID(0, "$NetBSD: efi.c,v 1.4 
 #include 
 
 #ifdef _LP64
-#define	EFIERR(x)		(0x8000 | x)
+#define	EFIERR(x)		(0x8000 | (x))
 #else
-#define	EFIERR(x)		(0x8000 | x)
+#define	EFIERR(x)		(0x8000 | (x))
 #endif
 
 #define	EFI_SUCCESS		0



CVS commit: src/sys/dev

2023-05-22 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Mon May 22 16:27:39 UTC 2023

Modified Files:
src/sys/dev: efi.c

Log Message:
efi(4): Parenthesize EFIERR argument out of paranoia.

PR kern/57076

XXX pullup-10


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/sys/dev/efi.c

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



CVS commit: src/external/cddl/osnet/dev/fbt/arm

2023-05-22 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Mon May 22 15:12:54 UTC 2023

Modified Files:
src/external/cddl/osnet/dev/fbt/arm: fbt_isa.c

Log Message:
dtrace_fbt: Read and write instructions appropriately-endian on arm.

arm is a little more complicated because it has three cases:
- big-endian data, big-endian instructions
- big-endian data, little-endian instructions
- little-endian data, little-endian instructions


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/external/cddl/osnet/dev/fbt/arm/fbt_isa.c

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

Modified files:

Index: src/external/cddl/osnet/dev/fbt/arm/fbt_isa.c
diff -u src/external/cddl/osnet/dev/fbt/arm/fbt_isa.c:1.1 src/external/cddl/osnet/dev/fbt/arm/fbt_isa.c:1.2
--- src/external/cddl/osnet/dev/fbt/arm/fbt_isa.c:1.1	Mon May 28 23:47:39 2018
+++ src/external/cddl/osnet/dev/fbt/arm/fbt_isa.c	Mon May 22 15:12:54 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: fbt_isa.c,v 1.1 2018/05/28 23:47:39 chs Exp $	*/
+/*	$NetBSD: fbt_isa.c,v 1.2 2023/05/22 15:12:54 riastradh Exp $	*/
 
 /*
  * CDDL HEADER START
@@ -56,6 +56,26 @@
 #define	FBT_ENTRY	"entry"
 #define	FBT_RETURN	"return"
 
+static uint32_t
+ldinstr(const uint32_t *instr)
+{
+#ifdef _ARM_ARCH_BE8		/* big-endian data, big-endian instructions */
+	return *instr;
+#else/* little-endian instructions */
+	return le32toh(*instr);
+#endif
+}
+
+static void
+stinstr(uint32_t *instr, uint32_t val)
+{
+
+#ifdef _ARM_ARCH_BE8		/* big-endian data, big-endian instructions */
+	val = bswap32(val);
+#endif
+	ktext_write(instr, &val, sizeof(val)); /* write little-endian */
+}
+
 int
 fbt_invop(uintptr_t addr, struct trapframe *frame, uintptr_t rval)
 {
@@ -98,9 +118,7 @@ fbt_patch_tracepoint(fbt_probe_t *fbt, f
 	dtrace_icookie_t c;
 
 	c = dtrace_interrupt_disable();
-
-	ktext_write(fbt->fbtp_patchpoint, &val, sizeof (val));
-
+	stinstr(fbt->fbtp_patchpoint, val);
 	dtrace_interrupt_enable(c);
 }
 
@@ -126,14 +144,14 @@ fbt_provide_module_function(linker_file_
 	 * va_arg functions has first instruction of
 	 * sub sp, sp, #?
 	 */
-	if ((*instr & 0xf000) == FBT_SUBSP)
+	if ((ldinstr(instr) & 0xf000) == FBT_SUBSP)
 		instr++;
 
 	/*
 	 * check if insn is a pushm with LR
 	 */
-	if ((*instr & 0x) != FBT_PUSHM ||
-	(*instr & (1 << LR)) == 0)
+	if ((ldinstr(instr) & 0x) != FBT_PUSHM ||
+	(ldinstr(instr) & (1 << LR)) == 0)
 		return (0);
 
 	fbt = kmem_zalloc(sizeof (fbt_probe_t), KM_SLEEP);
@@ -143,7 +161,7 @@ fbt_provide_module_function(linker_file_
 	fbt->fbtp_patchpoint = instr;
 	fbt->fbtp_ctl = lf;
 	fbt->fbtp_loadcnt = lf->loadcnt;
-	fbt->fbtp_savedval = *instr;
+	fbt->fbtp_savedval = ldinstr(instr);
 	fbt->fbtp_patchval = FBT_BREAKPOINT;
 	fbt->fbtp_rval = DTRACE_INVOP_PUSHM;
 	fbt->fbtp_symindx = symindx;
@@ -153,18 +171,18 @@ fbt_provide_module_function(linker_file_
 
 	lf->fbt_nentries++;
 
-	popm = FBT_POPM | ((*instr) & 0x3FFF) | 0x8000;
+	popm = FBT_POPM | (ldinstr(instr) & 0x3FFF) | 0x8000;
 
 	retfbt = NULL;
 again:
 	for (; instr < limit; instr++) {
-		if (*instr == popm)
+		if (ldinstr(instr) == popm)
 			break;
-		else if ((*instr & 0xff00) == FBT_JUMP) {
+		else if ((ldinstr(instr) & 0xff00) == FBT_JUMP) {
 			uint32_t *target, *start;
 			int offset;
 
-			offset = (*instr & 0xff);
+			offset = (ldinstr(instr) & 0xff);
 			offset <<= 8;
 			offset /= 64;
 			target = instr + (2 + offset);
@@ -195,11 +213,11 @@ again:
 	fbt->fbtp_ctl = lf;
 	fbt->fbtp_loadcnt = lf->loadcnt;
 	fbt->fbtp_symindx = symindx;
-	if ((*instr & 0xff00) == FBT_JUMP)
+	if ((ldinstr(instr) & 0xff00) == FBT_JUMP)
 		fbt->fbtp_rval = DTRACE_INVOP_B;
 	else
 		fbt->fbtp_rval = DTRACE_INVOP_POPM;
-	fbt->fbtp_savedval = *instr;
+	fbt->fbtp_savedval = ldinstr(instr);
 	fbt->fbtp_patchval = FBT_BREAKPOINT;
 	fbt->fbtp_hashnext = fbt_probetab[FBT_ADDR2NDX(instr)];
 	fbt_probetab[FBT_ADDR2NDX(instr)] = fbt;
@@ -279,14 +297,14 @@ fbt_provide_module_cb(const char *name, 
 	instr = (uint32_t *) value;
 	limit = (uint32_t *)((uintptr_t)value + symsize);
 
-	if (!FBT_MOV_IP_SP_P(*instr)
-	&& !FBT_BX_LR_P(*instr)
-	&& !FBT_MOVW_P(*instr)
-	&& !FBT_MOV_IMM_P(*instr)
-	&& !FBT_B_LABEL_P(*instr)
-	&& !FBT_LDR_IMM_P(*instr)
-	&& !FBT_CMP_IMM_P(*instr)
-	&& !FBT_PUSH_P(*instr)
+	if (!FBT_MOV_IP_SP_P(ldinstr(instr))
+	&& !FBT_BX_LR_P(ldinstr(instr))
+	&& !FBT_MOVW_P(ldinstr(instr))
+	&& !FBT_MOV_IMM_P(ldinstr(instr))
+	&& !FBT_B_LABEL_P(ldinstr(instr))
+	&& !FBT_LDR_IMM_P(ldinstr(instr))
+	&& !FBT_CMP_IMM_P(ldinstr(instr))
+	&& !FBT_PUSH_P(ldinstr(instr))
 	) {
 		return 0;
 	}
@@ -298,31 +316,39 @@ fbt_provide_module_cb(const char *name, 
 	fbt->fbtp_patchpoint = instr;
 	fbt->fbtp_ctl = mod;
 	/* fbt->fbtp_loadcnt = lf->loadcnt; */
-	if (FBT_MOV_IP_SP_P(*instr))
-		fbt->fbtp_rval = BUILD_RVAL(*instr, DTRACE_INVOP_MOV_IP_SP);
-	

CVS commit: src/external/cddl/osnet/dev/fbt/arm

2023-05-22 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Mon May 22 15:12:54 UTC 2023

Modified Files:
src/external/cddl/osnet/dev/fbt/arm: fbt_isa.c

Log Message:
dtrace_fbt: Read and write instructions appropriately-endian on arm.

arm is a little more complicated because it has three cases:
- big-endian data, big-endian instructions
- big-endian data, little-endian instructions
- little-endian data, little-endian instructions


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/external/cddl/osnet/dev/fbt/arm/fbt_isa.c

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



CVS commit: src/sys/dev/dkwedge

2023-05-22 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Mon May 22 15:00:17 UTC 2023

Modified Files:
src/sys/dev/dkwedge: dk.c

Log Message:
dk(4): Add locking notes.


To generate a diff of this commit:
cvs rdiff -u -r1.170 -r1.171 src/sys/dev/dkwedge/dk.c

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



CVS commit: src/sys/dev/dkwedge

2023-05-22 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Mon May 22 14:59:58 UTC 2023

Modified Files:
src/sys/dev/dkwedge: dk.c

Log Message:
dk(4): Strengthen preconditions of various devsw operations.

These can only happen between dkopen and dkclose, so there's no need
to test -- we can assert instead that the wedge exists and is fully
initialized.


To generate a diff of this commit:
cvs rdiff -u -r1.168 -r1.169 src/sys/dev/dkwedge/dk.c

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



CVS commit: src/sys/dev/dkwedge

2023-05-22 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Mon May 22 14:59:50 UTC 2023

Modified Files:
src/sys/dev/dkwedge: dk.c

Log Message:
dk(4): Strengthen dkclose preconditions.

Like dkopen, except it is possible for this to be called after the
wedge has transitioned to dying.

XXX sc_state read here races with sc_state write in dkwedge_detach.
Could change this to atomic_load/store.


To generate a diff of this commit:
cvs rdiff -u -r1.167 -r1.168 src/sys/dev/dkwedge/dk.c

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



CVS commit: src/sys/dev/dkwedge

2023-05-22 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Mon May 22 14:59:42 UTC 2023

Modified Files:
src/sys/dev/dkwedge: dk.c

Log Message:
dk(4): Strengthen dkopen preconditions.

This cannot be called before dkwedge_attach for the same unit
returns, so sc->sc_dev is guaranteed to be set to a nonnull device_t
and the state is guaranteed not to be larval.

And this cannot be called concurrently with dkwedge_detach, or after
dkwedge_detach does vdevgone until another wedge with the same number
is attached (which can't happen until dkwedge_detach completes), so
the state is guaranteed not to be dying or dead.

Hence sc->sc_dev != NULL and sc->sc_state == DKW_STATE_RUNNING.


To generate a diff of this commit:
cvs rdiff -u -r1.166 -r1.167 src/sys/dev/dkwedge/dk.c

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

Modified files:

Index: src/sys/dev/dkwedge/dk.c
diff -u src/sys/dev/dkwedge/dk.c:1.166 src/sys/dev/dkwedge/dk.c:1.167
--- src/sys/dev/dkwedge/dk.c:1.166	Mon May 22 14:59:34 2023
+++ src/sys/dev/dkwedge/dk.c	Mon May 22 14:59:42 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: dk.c,v 1.166 2023/05/22 14:59:34 riastradh Exp $	*/
+/*	$NetBSD: dk.c,v 1.167 2023/05/22 14:59:42 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2004, 2005, 2006, 2007 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: dk.c,v 1.166 2023/05/22 14:59:34 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: dk.c,v 1.167 2023/05/22 14:59:42 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_dkwedge.h"
@@ -1277,8 +1277,8 @@ dkopen(dev_t dev, int flags, int fmt, st
 
 	if (sc == NULL)
 		return ENXIO;
-	if (sc->sc_state != DKW_STATE_RUNNING)
-		return ENXIO;
+	KASSERT(sc->sc_dev != NULL);
+	KASSERT(sc->sc_state == DKW_STATE_RUNNING);
 
 	/*
 	 * We go through a complicated little dance to only open the parent



CVS commit: src/sys/dev/dkwedge

2023-05-22 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Mon May 22 14:59:34 UTC 2023

Modified Files:
src/sys/dev/dkwedge: dk.c

Log Message:
dk(4): Prevent race between dkwedge_get_parent_name and wedge detach.

Still races with parent detach but maybe this is better.

XXX Maybe we should ditch dkwedge_get_parent_name -- it's used only
by rf_containsboot, which kinda suggests it shouldn't exist.


To generate a diff of this commit:
cvs rdiff -u -r1.165 -r1.166 src/sys/dev/dkwedge/dk.c

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

Modified files:

Index: src/sys/dev/dkwedge/dk.c
diff -u src/sys/dev/dkwedge/dk.c:1.165 src/sys/dev/dkwedge/dk.c:1.166
--- src/sys/dev/dkwedge/dk.c:1.165	Mon May 22 14:59:25 2023
+++ src/sys/dev/dkwedge/dk.c	Mon May 22 14:59:34 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: dk.c,v 1.165 2023/05/22 14:59:25 riastradh Exp $	*/
+/*	$NetBSD: dk.c,v 1.166 2023/05/22 14:59:34 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2004, 2005, 2006, 2007 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: dk.c,v 1.165 2023/05/22 14:59:25 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: dk.c,v 1.166 2023/05/22 14:59:34 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_dkwedge.h"
@@ -1210,6 +1210,16 @@ dkwedge_lookup(dev_t dev)
 	return device_lookup_private(&dk_cd, minor(dev));
 }
 
+static struct dkwedge_softc *
+dkwedge_lookup_acquire(dev_t dev)
+{
+	device_t dv = device_lookup_acquire(&dk_cd, minor(dev));
+
+	if (dv == NULL)
+		return NULL;
+	return device_private(dv);
+}
+
 static int
 dk_open_parent(dev_t dev, int mode, struct vnode **vpp)
 {
@@ -1925,8 +1935,11 @@ dkwedge_get_parent_name(dev_t dev)
 
 	if (major(dev) != bmaj && major(dev) != cmaj)
 		return NULL;
-	struct dkwedge_softc *sc = dkwedge_lookup(dev);
+
+	struct dkwedge_softc *const sc = dkwedge_lookup_acquire(dev);
 	if (sc == NULL)
 		return NULL;
-	return sc->sc_parent->dk_name;
+	const char *const name = sc->sc_parent->dk_name;
+	device_release(sc->sc_dev);
+	return name;
 }



CVS commit: src/sys/dev/dkwedge

2023-05-22 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Mon May 22 14:59:34 UTC 2023

Modified Files:
src/sys/dev/dkwedge: dk.c

Log Message:
dk(4): Prevent race between dkwedge_get_parent_name and wedge detach.

Still races with parent detach but maybe this is better.

XXX Maybe we should ditch dkwedge_get_parent_name -- it's used only
by rf_containsboot, which kinda suggests it shouldn't exist.


To generate a diff of this commit:
cvs rdiff -u -r1.165 -r1.166 src/sys/dev/dkwedge/dk.c

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



CVS commit: src/sys/dev/dkwedge

2023-05-22 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Mon May 22 14:59:25 UTC 2023

Modified Files:
src/sys/dev/dkwedge: dk.c

Log Message:
dk(4): Split unsafe lookups into safe subroutines and unsafe wrappers.

No functional change intended.

Eventually we should adjust the callers to use the safe subroutines
instead and device_release when done.


To generate a diff of this commit:
cvs rdiff -u -r1.164 -r1.165 src/sys/dev/dkwedge/dk.c

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



CVS commit: src/sys/dev/dkwedge

2023-05-22 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Mon May 22 14:59:17 UTC 2023

Modified Files:
src/sys/dev/dkwedge: dk.c

Log Message:
dk(4): Don't hold lock around uiomove in dkwedge_list.

Instead, hold a device reference.  dkwedge_detach will not run until
the device reference is released.


To generate a diff of this commit:
cvs rdiff -u -r1.163 -r1.164 src/sys/dev/dkwedge/dk.c

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



CVS commit: src/sys/dev/dkwedge

2023-05-22 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Mon May 22 14:59:08 UTC 2023

Modified Files:
src/sys/dev/dkwedge: dk.c

Log Message:
dk(4): Skip larval wedges in various lookup routines.

These have not yet finished a concurent dkwedge_attach, so there's
nothing we can safely do with them.  Just pretend they don't exist --
as if we had arrived at the lookup a moment earlier.


To generate a diff of this commit:
cvs rdiff -u -r1.162 -r1.163 src/sys/dev/dkwedge/dk.c

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

Modified files:

Index: src/sys/dev/dkwedge/dk.c
diff -u src/sys/dev/dkwedge/dk.c:1.162 src/sys/dev/dkwedge/dk.c:1.163
--- src/sys/dev/dkwedge/dk.c:1.162	Mon May 22 14:58:59 2023
+++ src/sys/dev/dkwedge/dk.c	Mon May 22 14:59:07 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: dk.c,v 1.162 2023/05/22 14:58:59 riastradh Exp $	*/
+/*	$NetBSD: dk.c,v 1.163 2023/05/22 14:59:07 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2004, 2005, 2006, 2007 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: dk.c,v 1.162 2023/05/22 14:58:59 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: dk.c,v 1.163 2023/05/22 14:59:07 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_dkwedge.h"
@@ -849,7 +849,7 @@ dkwedge_list(struct disk *pdk, struct dk
 		if (uio.uio_resid < sizeof(dkw))
 			break;
 
-		if (sc->sc_state != DKW_STATE_RUNNING)
+		if (sc->sc_dev == NULL)
 			continue;
 
 		strlcpy(dkw.dkw_devname, device_xname(sc->sc_dev),
@@ -882,7 +882,7 @@ dkwedge_find_by_wname(const char *wname)
 
 	rw_enter(&dkwedges_lock, RW_READER);
 	for (i = 0; i < ndkwedges; i++) {
-		if ((sc = dkwedges[i]) == NULL)
+		if ((sc = dkwedges[i]) == NULL || sc->sc_dev == NULL)
 			continue;
 		if (strcmp(sc->sc_wname, wname) == 0) {
 			if (dv != NULL) {
@@ -906,7 +906,7 @@ dkwedge_find_by_parent(const char *name,
 	rw_enter(&dkwedges_lock, RW_READER);
 	for (; *i < (size_t)ndkwedges; (*i)++) {
 		struct dkwedge_softc *sc;
-		if ((sc = dkwedges[*i]) == NULL)
+		if ((sc = dkwedges[*i]) == NULL || sc->sc_dev == NULL)
 			continue;
 		if (strcmp(sc->sc_parent->dk_name, name) != 0)
 			continue;
@@ -925,7 +925,7 @@ dkwedge_print_wnames(void)
 
 	rw_enter(&dkwedges_lock, RW_READER);
 	for (i = 0; i < ndkwedges; i++) {
-		if ((sc = dkwedges[i]) == NULL)
+		if ((sc = dkwedges[i]) == NULL || sc->sc_dev == NULL)
 			continue;
 		printf(" wedge:%s", sc->sc_wname);
 	}
@@ -1844,7 +1844,7 @@ dkwedge_find_partition(device_t parent, 
 
 	rw_enter(&dkwedges_lock, RW_READER);
 	for (i = 0; i < ndkwedges; i++) {
-		if ((sc = dkwedges[i]) == NULL)
+		if ((sc = dkwedges[i]) == NULL || sc->sc_dev == NULL)
 			continue;
 		if (strcmp(sc->sc_parent->dk_name, device_xname(parent)) == 0 &&
 		sc->sc_offset == startblk &&



CVS commit: src/sys/dev/dkwedge

2023-05-22 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Mon May 22 14:58:59 UTC 2023

Modified Files:
src/sys/dev/dkwedge: dk.c

Log Message:
dk(4): Simplify dkwedge_delall by detaching directly.

No need for O(n^2) algorithm and potentially racy lookups -- not that
n is large enough for n^2 to matter, but the mechanism is simpler
this way.


To generate a diff of this commit:
cvs rdiff -u -r1.161 -r1.162 src/sys/dev/dkwedge/dk.c

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

Modified files:

Index: src/sys/dev/dkwedge/dk.c
diff -u src/sys/dev/dkwedge/dk.c:1.161 src/sys/dev/dkwedge/dk.c:1.162
--- src/sys/dev/dkwedge/dk.c:1.161	Mon May 22 14:58:50 2023
+++ src/sys/dev/dkwedge/dk.c	Mon May 22 14:58:59 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: dk.c,v 1.161 2023/05/22 14:58:50 riastradh Exp $	*/
+/*	$NetBSD: dk.c,v 1.162 2023/05/22 14:58:59 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2004, 2005, 2006, 2007 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: dk.c,v 1.161 2023/05/22 14:58:50 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: dk.c,v 1.162 2023/05/22 14:58:59 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_dkwedge.h"
@@ -781,7 +781,6 @@ dkwedge_delidle(struct disk *pdk)
 static void
 dkwedge_delall1(struct disk *pdk, bool idleonly)
 {
-	struct dkwedge_info dkw;
 	struct dkwedge_softc *sc;
 	int flags;
 
@@ -793,8 +792,18 @@ dkwedge_delall1(struct disk *pdk, bool i
 		mutex_enter(&pdk->dk_rawlock); /* for sc->sc_dk.dk_openmask */
 		mutex_enter(&pdk->dk_openlock);
 		LIST_FOREACH(sc, &pdk->dk_wedges, sc_plink) {
-			if (!idleonly || sc->sc_dk.dk_openmask == 0)
+			/*
+			 * Wedge is not yet created.  This is a race --
+			 * it may as well have been added just after we
+			 * deleted all the wedges, so pretend it's not
+			 * here yet.
+			 */
+			if (sc->sc_dev == NULL)
+continue;
+			if (!idleonly || sc->sc_dk.dk_openmask == 0) {
+device_acquire(sc->sc_dev);
 break;
+			}
 		}
 		if (sc == NULL) {
 			KASSERT(idleonly || pdk->dk_nwedges == 0);
@@ -802,12 +811,9 @@ dkwedge_delall1(struct disk *pdk, bool i
 			mutex_exit(&pdk->dk_rawlock);
 			return;
 		}
-		strlcpy(dkw.dkw_parent, pdk->dk_name, sizeof(dkw.dkw_parent));
-		strlcpy(dkw.dkw_devname, device_xname(sc->sc_dev),
-		sizeof(dkw.dkw_devname));
 		mutex_exit(&pdk->dk_openlock);
 		mutex_exit(&pdk->dk_rawlock);
-		(void) dkwedge_del1(&dkw, flags);
+		(void)config_detach_release(sc->sc_dev, flags);
 	}
 }
 



CVS commit: src/sys/dev/dkwedge

2023-05-22 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Mon May 22 14:58:59 UTC 2023

Modified Files:
src/sys/dev/dkwedge: dk.c

Log Message:
dk(4): Simplify dkwedge_delall by detaching directly.

No need for O(n^2) algorithm and potentially racy lookups -- not that
n is large enough for n^2 to matter, but the mechanism is simpler
this way.


To generate a diff of this commit:
cvs rdiff -u -r1.161 -r1.162 src/sys/dev/dkwedge/dk.c

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



CVS commit: src/sys/dev/dkwedge

2023-05-22 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Mon May 22 14:58:51 UTC 2023

Modified Files:
src/sys/dev/dkwedge: dk.c

Log Message:
dk(4): Use device_lookup_private for dkwedge_lookup.

No longer necessary to go through the dkwedges array.

Currently device_lookup_private still involves touching other global
locks, but that will change eventually to a lockless pserialized fast
path.


To generate a diff of this commit:
cvs rdiff -u -r1.160 -r1.161 src/sys/dev/dkwedge/dk.c

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



CVS commit: src/sys/dev/dkwedge

2023-05-22 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Mon May 22 15:00:06 UTC 2023

Modified Files:
src/sys/dev/dkwedge: dk.c

Log Message:
dk(4): Explain why no need for device reference in dksize, dkdump.


To generate a diff of this commit:
cvs rdiff -u -r1.169 -r1.170 src/sys/dev/dkwedge/dk.c

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

Modified files:

Index: src/sys/dev/dkwedge/dk.c
diff -u src/sys/dev/dkwedge/dk.c:1.169 src/sys/dev/dkwedge/dk.c:1.170
--- src/sys/dev/dkwedge/dk.c:1.169	Mon May 22 14:59:58 2023
+++ src/sys/dev/dkwedge/dk.c	Mon May 22 15:00:06 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: dk.c,v 1.169 2023/05/22 14:59:58 riastradh Exp $	*/
+/*	$NetBSD: dk.c,v 1.170 2023/05/22 15:00:06 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2004, 2005, 2006, 2007 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: dk.c,v 1.169 2023/05/22 14:59:58 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: dk.c,v 1.170 2023/05/22 15:00:06 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_dkwedge.h"
@@ -1824,6 +1824,11 @@ dkdiscard(dev_t dev, off_t pos, off_t le
 static int
 dksize(dev_t dev)
 {
+	/*
+	 * Don't bother taking a reference because this is only used
+	 * either (a) while the device is open (for swap), or (b) while
+	 * any multiprocessing is quiescent (for crash dumps).
+	 */
 	struct dkwedge_softc *sc = dkwedge_lookup(dev);
 	uint64_t p_size;
 	int rv = -1;
@@ -1855,6 +1860,10 @@ dksize(dev_t dev)
 static int
 dkdump(dev_t dev, daddr_t blkno, void *va, size_t size)
 {
+	/*
+	 * Don't bother taking a reference because this is only used
+	 * while any multiprocessing is quiescent.
+	 */
 	struct dkwedge_softc *sc = dkwedge_lookup(dev);
 	const struct bdevsw *bdev;
 	uint64_t p_size, p_offset;



CVS commit: src/sys/dev/dkwedge

2023-05-22 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Mon May 22 15:00:06 UTC 2023

Modified Files:
src/sys/dev/dkwedge: dk.c

Log Message:
dk(4): Explain why no need for device reference in dksize, dkdump.


To generate a diff of this commit:
cvs rdiff -u -r1.169 -r1.170 src/sys/dev/dkwedge/dk.c

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



CVS commit: src/sys/dev/dkwedge

2023-05-22 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Mon May 22 15:00:17 UTC 2023

Modified Files:
src/sys/dev/dkwedge: dk.c

Log Message:
dk(4): Add locking notes.


To generate a diff of this commit:
cvs rdiff -u -r1.170 -r1.171 src/sys/dev/dkwedge/dk.c

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

Modified files:

Index: src/sys/dev/dkwedge/dk.c
diff -u src/sys/dev/dkwedge/dk.c:1.170 src/sys/dev/dkwedge/dk.c:1.171
--- src/sys/dev/dkwedge/dk.c:1.170	Mon May 22 15:00:06 2023
+++ src/sys/dev/dkwedge/dk.c	Mon May 22 15:00:17 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: dk.c,v 1.170 2023/05/22 15:00:06 riastradh Exp $	*/
+/*	$NetBSD: dk.c,v 1.171 2023/05/22 15:00:17 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2004, 2005, 2006, 2007 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: dk.c,v 1.170 2023/05/22 15:00:06 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: dk.c,v 1.171 2023/05/22 15:00:17 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_dkwedge.h"
@@ -70,29 +70,65 @@ typedef enum {
 	DKW_STATE_DEAD		= 666
 } dkwedge_state_t;
 
+/*
+ * Lock order:
+ *
+ *	sc->sc_dk.dk_openlock
+ *	=> sc->sc_parent->dk_rawlock
+ *	=> sc->sc_parent->dk_openlock
+ *	=> dkwedges_lock
+ *	=> sc->sc_sizelock
+ *
+ * Locking notes:
+ *
+ *	W	dkwedges_lock
+ *	D	device reference
+ *	O	sc->sc_dk.dk_openlock
+ *	P	sc->sc_parent->dk_openlock
+ *	R	sc->sc_parent->dk_rawlock
+ *	S	sc->sc_sizelock
+ *	I	sc->sc_iolock
+ *	$	stable after initialization
+ *	1	used only by a single thread
+ *
+ * x&y means both x and y must be held to write (with a write lock if
+ * one is rwlock), and either x or y must be held to read.
+ */
+
 struct dkwedge_softc {
-	device_t	sc_dev;	/* pointer to our pseudo-device */
-	struct cfdata	sc_cfdata;	/* our cfdata structure */
-	uint8_t		sc_wname[128];	/* wedge name (Unicode, UTF-8) */
+	device_t	sc_dev;	/* P&W: pointer to our pseudo-device */
+		/* sc_dev is also stable while device is referenced */
+	struct cfdata	sc_cfdata;	/* 1: our cfdata structure */
+	uint8_t		sc_wname[128];	/* $: wedge name (Unicode, UTF-8) */
 
 	dkwedge_state_t sc_state;	/* state this wedge is in */
+		/* stable while device is referenced */
+		/* used only in assertions when stable, and in dump in ddb */
 
-	struct disk	*sc_parent;	/* parent disk */
-	daddr_t		sc_offset;	/* LBA offset of wedge in parent */
+	struct disk	*sc_parent;	/* $: parent disk */
+		/* P: sc_parent->dk_openmask */
+		/* P: sc_parent->dk_nwedges */
+		/* P: sc_parent->dk_wedges */
+		/* R: sc_parent->dk_rawopens */
+		/* R: sc_parent->dk_rawvp (also stable while wedge is open) */
+	daddr_t		sc_offset;	/* $: LBA offset of wedge in parent */
 	krwlock_t	sc_sizelock;
-	uint64_t	sc_size;	/* size of wedge in blocks */
-	char		sc_ptype[32];	/* partition type */
-	dev_t		sc_pdev;	/* cached parent's dev_t */
-	/* link on parent's wedge list */
+	uint64_t	sc_size;	/* S: size of wedge in blocks */
+	char		sc_ptype[32];	/* $: partition type */
+	dev_t		sc_pdev;	/* $: cached parent's dev_t */
+	/* P: link on parent's wedge list */
 	LIST_ENTRY(dkwedge_softc) sc_plink;
 
 	struct disk	sc_dk;		/* our own disk structure */
-	struct bufq_state *sc_bufq;	/* buffer queue */
-	struct callout	sc_restart_ch;	/* callout to restart I/O */
+		/* O&R: sc_dk.dk_bopenmask */
+		/* O&R: sc_dk.dk_copenmask */
+		/* O&R: sc_dk.dk_openmask */
+	struct bufq_state *sc_bufq;	/* $: buffer queue */
+	struct callout	sc_restart_ch;	/* I: callout to restart I/O */
 
 	kmutex_t	sc_iolock;
-	bool		sc_iostop;	/* don't schedule restart */
-	int		sc_mode;	/* parent open mode */
+	bool		sc_iostop;	/* I: don't schedule restart */
+	int		sc_mode;	/* O&R: parent open mode */
 };
 
 static int	dkwedge_match(device_t, cfdata_t, void *);



CVS commit: src/sys/dev/dkwedge

2023-05-22 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Mon May 22 14:59:58 UTC 2023

Modified Files:
src/sys/dev/dkwedge: dk.c

Log Message:
dk(4): Strengthen preconditions of various devsw operations.

These can only happen between dkopen and dkclose, so there's no need
to test -- we can assert instead that the wedge exists and is fully
initialized.


To generate a diff of this commit:
cvs rdiff -u -r1.168 -r1.169 src/sys/dev/dkwedge/dk.c

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

Modified files:

Index: src/sys/dev/dkwedge/dk.c
diff -u src/sys/dev/dkwedge/dk.c:1.168 src/sys/dev/dkwedge/dk.c:1.169
--- src/sys/dev/dkwedge/dk.c:1.168	Mon May 22 14:59:50 2023
+++ src/sys/dev/dkwedge/dk.c	Mon May 22 14:59:58 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: dk.c,v 1.168 2023/05/22 14:59:50 riastradh Exp $	*/
+/*	$NetBSD: dk.c,v 1.169 2023/05/22 14:59:58 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2004, 2005, 2006, 2007 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: dk.c,v 1.168 2023/05/22 14:59:50 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: dk.c,v 1.169 2023/05/22 14:59:58 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_dkwedge.h"
@@ -1477,6 +1477,7 @@ dkstrategy(struct buf *bp)
 	uint64_t p_size, p_offset;
 
 	KASSERT(sc != NULL);
+	KASSERT(sc->sc_dev != NULL);
 	KASSERT(sc->sc_state != DKW_STATE_LARVAL);
 	KASSERT(sc->sc_state != DKW_STATE_DEAD);
 	KASSERT(sc->sc_parent->dk_rawvp != NULL);
@@ -1605,6 +1606,9 @@ dkiodone(struct buf *bp)
 	struct buf *obp = bp->b_private;
 	struct dkwedge_softc *sc = dkwedge_lookup(obp->b_dev);
 
+	KASSERT(sc != NULL);
+	KASSERT(sc->sc_dev != NULL);
+
 	if (bp->b_error != 0)
 		obp->b_error = bp->b_error;
 	obp->b_resid = bp->b_resid;
@@ -1646,6 +1650,9 @@ dkminphys(struct buf *bp)
 	struct dkwedge_softc *sc = dkwedge_lookup(bp->b_dev);
 	dev_t dev;
 
+	KASSERT(sc != NULL);
+	KASSERT(sc->sc_dev != NULL);
+
 	dev = bp->b_dev;
 	bp->b_dev = sc->sc_pdev;
 	if (sc->sc_parent->dk_driver && sc->sc_parent->dk_driver->d_minphys)
@@ -1666,6 +1673,7 @@ dkread(dev_t dev, struct uio *uio, int f
 	struct dkwedge_softc *sc __diagused = dkwedge_lookup(dev);
 
 	KASSERT(sc != NULL);
+	KASSERT(sc->sc_dev != NULL);
 	KASSERT(sc->sc_state != DKW_STATE_LARVAL);
 	KASSERT(sc->sc_state != DKW_STATE_DEAD);
 
@@ -1683,6 +1691,7 @@ dkwrite(dev_t dev, struct uio *uio, int 
 	struct dkwedge_softc *sc __diagused = dkwedge_lookup(dev);
 
 	KASSERT(sc != NULL);
+	KASSERT(sc->sc_dev != NULL);
 	KASSERT(sc->sc_state != DKW_STATE_LARVAL);
 	KASSERT(sc->sc_state != DKW_STATE_DEAD);
 
@@ -1701,6 +1710,7 @@ dkioctl(dev_t dev, u_long cmd, void *dat
 	int error = 0;
 
 	KASSERT(sc != NULL);
+	KASSERT(sc->sc_dev != NULL);
 	KASSERT(sc->sc_state != DKW_STATE_LARVAL);
 	KASSERT(sc->sc_state != DKW_STATE_DEAD);
 	KASSERT(sc->sc_parent->dk_rawvp != NULL);
@@ -1776,6 +1786,7 @@ dkdiscard(dev_t dev, off_t pos, off_t le
 	int error;
 
 	KASSERT(sc != NULL);
+	KASSERT(sc->sc_dev != NULL);
 	KASSERT(sc->sc_state != DKW_STATE_LARVAL);
 	KASSERT(sc->sc_state != DKW_STATE_DEAD);
 	KASSERT(sc->sc_parent->dk_rawvp != NULL);



CVS commit: src/sys/dev/dkwedge

2023-05-22 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Mon May 22 14:59:50 UTC 2023

Modified Files:
src/sys/dev/dkwedge: dk.c

Log Message:
dk(4): Strengthen dkclose preconditions.

Like dkopen, except it is possible for this to be called after the
wedge has transitioned to dying.

XXX sc_state read here races with sc_state write in dkwedge_detach.
Could change this to atomic_load/store.


To generate a diff of this commit:
cvs rdiff -u -r1.167 -r1.168 src/sys/dev/dkwedge/dk.c

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

Modified files:

Index: src/sys/dev/dkwedge/dk.c
diff -u src/sys/dev/dkwedge/dk.c:1.167 src/sys/dev/dkwedge/dk.c:1.168
--- src/sys/dev/dkwedge/dk.c:1.167	Mon May 22 14:59:42 2023
+++ src/sys/dev/dkwedge/dk.c	Mon May 22 14:59:50 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: dk.c,v 1.167 2023/05/22 14:59:42 riastradh Exp $	*/
+/*	$NetBSD: dk.c,v 1.168 2023/05/22 14:59:50 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2004, 2005, 2006, 2007 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: dk.c,v 1.167 2023/05/22 14:59:42 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: dk.c,v 1.168 2023/05/22 14:59:50 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_dkwedge.h"
@@ -1404,11 +1404,16 @@ dkclose(dev_t dev, int flags, int fmt, s
 {
 	struct dkwedge_softc *sc = dkwedge_lookup(dev);
 
+	/*
+	 * dkclose can be called even if dkopen didn't succeed, so we
+	 * have to handle the same possibility that the wedge may not
+	 * exist.
+	 */
 	if (sc == NULL)
 		return ENXIO;
-	if (sc->sc_state != DKW_STATE_RUNNING &&
-	sc->sc_state != DKW_STATE_DYING)
-		return ENXIO;
+	KASSERT(sc->sc_dev != NULL);
+	KASSERT(sc->sc_state != DKW_STATE_LARVAL);
+	KASSERT(sc->sc_state != DKW_STATE_DEAD);
 
 	mutex_enter(&sc->sc_dk.dk_openlock);
 	mutex_enter(&sc->sc_parent->dk_rawlock);



CVS commit: src/sys/dev/dkwedge

2023-05-22 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Mon May 22 14:58:33 UTC 2023

Modified Files:
src/sys/dev/dkwedge: dk.c

Log Message:
dk(4): Use config_attach_pseudo_acquire to create wedges.

This way, indexing of the dkwedges array coincides with numbering of
autoconf dk(4) instances.

As a side effect, this plugs a race in dkwedge_add with concurrent
drvctl -r.  There are a lot of such races in dk(4) left -- to be
addressed with more device references.


To generate a diff of this commit:
cvs rdiff -u -r1.158 -r1.159 src/sys/dev/dkwedge/dk.c

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

Modified files:

Index: src/sys/dev/dkwedge/dk.c
diff -u src/sys/dev/dkwedge/dk.c:1.158 src/sys/dev/dkwedge/dk.c:1.159
--- src/sys/dev/dkwedge/dk.c:1.158	Sat May 13 10:11:36 2023
+++ src/sys/dev/dkwedge/dk.c	Mon May 22 14:58:32 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: dk.c,v 1.158 2023/05/13 10:11:36 riastradh Exp $	*/
+/*	$NetBSD: dk.c,v 1.159 2023/05/22 14:58:32 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2004, 2005, 2006, 2007 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: dk.c,v 1.158 2023/05/13 10:11:36 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: dk.c,v 1.159 2023/05/22 14:58:32 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_dkwedge.h"
@@ -99,6 +99,8 @@ static int	dkwedge_match(device_t, cfdat
 static void	dkwedge_attach(device_t, device_t, void *);
 static int	dkwedge_detach(device_t, int);
 
+static void	dk_set_geometry(struct dkwedge_softc *, struct disk *);
+
 static void	dkstart(struct dkwedge_softc *);
 static void	dkiodone(struct buf *);
 static void	dkrestart(void *);
@@ -190,9 +192,34 @@ dkwedge_match(device_t parent, cfdata_t 
 static void
 dkwedge_attach(device_t parent, device_t self, void *aux)
 {
+	struct dkwedge_softc *sc = aux;
+	struct disk *pdk = sc->sc_parent;
+	int unit = device_unit(self);
+
+	KASSERTMSG(unit >= 0, "unit=%d", unit);
 
 	if (!pmf_device_register(self, NULL, NULL))
 		aprint_error_dev(self, "couldn't establish power handler\n");
+
+	mutex_enter(&pdk->dk_openlock);
+	rw_enter(&dkwedges_lock, RW_WRITER);
+	KASSERTMSG(unit < ndkwedges, "unit=%d ndkwedges=%u", unit, ndkwedges);
+	KASSERTMSG(sc == dkwedges[unit], "sc=%p dkwedges[%d]=%p",
+	sc, unit, dkwedges[unit]);
+	KASSERTMSG(sc->sc_dev == NULL, "sc=%p sc->sc_dev=%p", sc, sc->sc_dev);
+	sc->sc_dev = self;
+	rw_exit(&dkwedges_lock);
+	mutex_exit(&pdk->dk_openlock);
+
+	disk_init(&sc->sc_dk, device_xname(sc->sc_dev), NULL);
+	mutex_enter(&pdk->dk_openlock);
+	dk_set_geometry(sc, pdk);
+	mutex_exit(&pdk->dk_openlock);
+	disk_attach(&sc->sc_dk);
+
+	/* Disk wedge is ready for use! */
+	device_set_private(self, sc);
+	sc->sc_state = DKW_STATE_RUNNING;
 }
 
 /*
@@ -364,6 +391,7 @@ dkwedge_add(struct dkwedge_info *dkw)
 	u_int unit;
 	int error;
 	dev_t pdev;
+	device_t dev __diagused;
 
 	dkw->dkw_parent[sizeof(dkw->dkw_parent) - 1] = '\0';
 	pdk = disk_find(dkw->dkw_parent);
@@ -393,8 +421,11 @@ dkwedge_add(struct dkwedge_info *dkw)
 			break;
 		if (dkwedge_size(lsc) > dkw->dkw_size)
 			break;
+		if (lsc->sc_dev == NULL)
+			break;
 
 		sc = lsc;
+		device_acquire(sc->sc_dev);
 		dkwedge_size_increase(sc, dkw->dkw_size);
 		dk_set_geometry(sc, pdk);
 
@@ -477,7 +508,7 @@ dkwedge_add(struct dkwedge_info *dkw)
 	sc->sc_cfdata.cf_name = dk_cd.cd_name;
 	sc->sc_cfdata.cf_atname = dk_ca.ca_name;
 	/* sc->sc_cfdata.cf_unit set below */
-	sc->sc_cfdata.cf_fstate = FSTATE_STAR;
+	sc->sc_cfdata.cf_fstate = FSTATE_NOTFOUND; /* use chosen cf_unit */
 
 	/* Insert the larval wedge into the array. */
 	rw_enter(&dkwedges_lock, RW_WRITER);
@@ -538,7 +569,7 @@ dkwedge_add(struct dkwedge_info *dkw)
 	 * This should never fail, unless we're almost totally out of
 	 * memory.
 	 */
-	if ((sc->sc_dev = config_attach_pseudo(&sc->sc_cfdata)) == NULL) {
+	if ((dev = config_attach_pseudo_acquire(&sc->sc_cfdata, sc)) == NULL) {
 		aprint_error("%s%u: unable to attach pseudo-device\n",
 		sc->sc_cfdata.cf_name, sc->sc_cfdata.cf_unit);
 
@@ -559,19 +590,7 @@ dkwedge_add(struct dkwedge_info *dkw)
 		return ENOMEM;
 	}
 
-	/*
-	 * XXX Really ought to make the disk_attach() and the changing
-	 * of state to RUNNING atomic.
-	 */
-
-	disk_init(&sc->sc_dk, device_xname(sc->sc_dev), NULL);
-	mutex_enter(&pdk->dk_openlock);
-	dk_set_geometry(sc, pdk);
-	mutex_exit(&pdk->dk_openlock);
-	disk_attach(&sc->sc_dk);
-
-	/* Disk wedge is ready for use! */
-	sc->sc_state = DKW_STATE_RUNNING;
+	KASSERT(dev == sc->sc_dev);
 
 announce:
 	/* Announce our arrival. */
@@ -586,11 +605,12 @@ announce:
 	strlcpy(dkw->dkw_devname, device_xname(sc->sc_dev),
 	sizeof(dkw->dkw_devname));
 
+	device_release(sc->sc_dev);
 	return 0;
 }
 
 /*
- * dkwedge_find:
+ * dkwedge_find_acquire:
  *
  *	Lookup a disk wedge based on the provided information.
  *	NOTE: We look up the wedge based on the wedge devname,
@@ -598,10 +618,11 @@ announce:
  *

CVS commit: src/sys/dev/dkwedge

2023-05-22 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Mon May 22 14:58:41 UTC 2023

Modified Files:
src/sys/dev/dkwedge: dk.c

Log Message:
dk(4): dkunit is no longer needed; nix it.

dkwedges array indexing now coincides with autoconf device numbering.


To generate a diff of this commit:
cvs rdiff -u -r1.159 -r1.160 src/sys/dev/dkwedge/dk.c

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



CVS commit: src/sys/dev/dkwedge

2023-05-22 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Mon May 22 14:59:42 UTC 2023

Modified Files:
src/sys/dev/dkwedge: dk.c

Log Message:
dk(4): Strengthen dkopen preconditions.

This cannot be called before dkwedge_attach for the same unit
returns, so sc->sc_dev is guaranteed to be set to a nonnull device_t
and the state is guaranteed not to be larval.

And this cannot be called concurrently with dkwedge_detach, or after
dkwedge_detach does vdevgone until another wedge with the same number
is attached (which can't happen until dkwedge_detach completes), so
the state is guaranteed not to be dying or dead.

Hence sc->sc_dev != NULL and sc->sc_state == DKW_STATE_RUNNING.


To generate a diff of this commit:
cvs rdiff -u -r1.166 -r1.167 src/sys/dev/dkwedge/dk.c

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



CVS commit: src/sys/dev/dkwedge

2023-05-22 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Mon May 22 14:59:25 UTC 2023

Modified Files:
src/sys/dev/dkwedge: dk.c

Log Message:
dk(4): Split unsafe lookups into safe subroutines and unsafe wrappers.

No functional change intended.

Eventually we should adjust the callers to use the safe subroutines
instead and device_release when done.


To generate a diff of this commit:
cvs rdiff -u -r1.164 -r1.165 src/sys/dev/dkwedge/dk.c

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

Modified files:

Index: src/sys/dev/dkwedge/dk.c
diff -u src/sys/dev/dkwedge/dk.c:1.164 src/sys/dev/dkwedge/dk.c:1.165
--- src/sys/dev/dkwedge/dk.c:1.164	Mon May 22 14:59:16 2023
+++ src/sys/dev/dkwedge/dk.c	Mon May 22 14:59:25 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: dk.c,v 1.164 2023/05/22 14:59:16 riastradh Exp $	*/
+/*	$NetBSD: dk.c,v 1.165 2023/05/22 14:59:25 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2004, 2005, 2006, 2007 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: dk.c,v 1.164 2023/05/22 14:59:16 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: dk.c,v 1.165 2023/05/22 14:59:25 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_dkwedge.h"
@@ -883,8 +883,8 @@ dkwedge_list(struct disk *pdk, struct dk
 	return error;
 }
 
-device_t
-dkwedge_find_by_wname(const char *wname)
+static device_t
+dkwedge_find_by_wname_acquire(const char *wname)
 {
 	device_t dv = NULL;
 	struct dkwedge_softc *sc;
@@ -902,6 +902,7 @@ dkwedge_find_by_wname(const char *wname)
 device_xname(sc->sc_dev));
 continue;
 			}
+			device_acquire(sc->sc_dev);
 			dv = sc->sc_dev;
 		}
 	}
@@ -909,8 +910,8 @@ dkwedge_find_by_wname(const char *wname)
 	return dv;
 }
 
-device_t
-dkwedge_find_by_parent(const char *name, size_t *i)
+static device_t
+dkwedge_find_by_parent_acquire(const char *name, size_t *i)
 {
 
 	rw_enter(&dkwedges_lock, RW_READER);
@@ -920,6 +921,7 @@ dkwedge_find_by_parent(const char *name,
 			continue;
 		if (strcmp(sc->sc_parent->dk_name, name) != 0)
 			continue;
+		device_acquire(sc->sc_dev);
 		rw_exit(&dkwedges_lock);
 		return sc->sc_dev;
 	}
@@ -927,6 +929,30 @@ dkwedge_find_by_parent(const char *name,
 	return NULL;
 }
 
+/* XXX unsafe */
+device_t
+dkwedge_find_by_wname(const char *wname)
+{
+	device_t dv;
+
+	if ((dv = dkwedge_find_by_wname_acquire(wname)) == NULL)
+		return NULL;
+	device_release(dv);
+	return dv;
+}
+
+/* XXX unsafe */
+device_t
+dkwedge_find_by_parent(const char *name, size_t *i)
+{
+	device_t dv;
+
+	if ((dv = dkwedge_find_by_parent_acquire(name, i)) == NULL)
+		return NULL;
+	device_release(dv);
+	return dv;
+}
+
 void
 dkwedge_print_wnames(void)
 {
@@ -1845,8 +1871,9 @@ dkdump(dev_t dev, daddr_t blkno, void *v
  *	Find wedge corresponding to the specified parent name
  *	and offset/length.
  */
-device_t
-dkwedge_find_partition(device_t parent, daddr_t startblk, uint64_t nblks)
+static device_t
+dkwedge_find_partition_acquire(device_t parent, daddr_t startblk,
+uint64_t nblks)
 {
 	struct dkwedge_softc *sc;
 	int i;
@@ -1867,6 +1894,7 @@ dkwedge_find_partition(device_t parent, 
 continue;
 			}
 			wedge = sc->sc_dev;
+			device_acquire(wedge);
 		}
 	}
 	rw_exit(&dkwedges_lock);
@@ -1874,6 +1902,20 @@ dkwedge_find_partition(device_t parent, 
 	return wedge;
 }
 
+/* XXX unsafe */
+device_t
+dkwedge_find_partition(device_t parent, daddr_t startblk,
+uint64_t nblks)
+{
+	device_t dv;
+
+	if ((dv = dkwedge_find_partition_acquire(parent, startblk, nblks))
+	== NULL)
+		return NULL;
+	device_release(dv);
+	return dv;
+}
+
 const char *
 dkwedge_get_parent_name(dev_t dev)
 {



CVS commit: src/sys/dev/dkwedge

2023-05-22 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Mon May 22 14:59:17 UTC 2023

Modified Files:
src/sys/dev/dkwedge: dk.c

Log Message:
dk(4): Don't hold lock around uiomove in dkwedge_list.

Instead, hold a device reference.  dkwedge_detach will not run until
the device reference is released.


To generate a diff of this commit:
cvs rdiff -u -r1.163 -r1.164 src/sys/dev/dkwedge/dk.c

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

Modified files:

Index: src/sys/dev/dkwedge/dk.c
diff -u src/sys/dev/dkwedge/dk.c:1.163 src/sys/dev/dkwedge/dk.c:1.164
--- src/sys/dev/dkwedge/dk.c:1.163	Mon May 22 14:59:07 2023
+++ src/sys/dev/dkwedge/dk.c	Mon May 22 14:59:16 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: dk.c,v 1.163 2023/05/22 14:59:07 riastradh Exp $	*/
+/*	$NetBSD: dk.c,v 1.164 2023/05/22 14:59:16 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2004, 2005, 2006, 2007 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: dk.c,v 1.163 2023/05/22 14:59:07 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: dk.c,v 1.164 2023/05/22 14:59:16 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_dkwedge.h"
@@ -862,9 +862,19 @@ dkwedge_list(struct disk *pdk, struct dk
 		dkw.dkw_size = dkwedge_size(sc);
 		strlcpy(dkw.dkw_ptype, sc->sc_ptype, sizeof(dkw.dkw_ptype));
 
+		/*
+		 * Acquire a device reference so this wedge doesn't go
+		 * away before our next iteration in LIST_FOREACH, and
+		 * then release the lock for uiomove.
+		 */
+		device_acquire(sc->sc_dev);
+		mutex_exit(&pdk->dk_openlock);
 		error = uiomove(&dkw, sizeof(dkw), &uio);
+		mutex_enter(&pdk->dk_openlock);
+		device_release(sc->sc_dev);
 		if (error)
 			break;
+
 		dkwl->dkwl_ncopied++;
 	}
 	dkwl->dkwl_nwedges = pdk->dk_nwedges;



CVS commit: src/sys/dev/dkwedge

2023-05-22 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Mon May 22 14:59:08 UTC 2023

Modified Files:
src/sys/dev/dkwedge: dk.c

Log Message:
dk(4): Skip larval wedges in various lookup routines.

These have not yet finished a concurent dkwedge_attach, so there's
nothing we can safely do with them.  Just pretend they don't exist --
as if we had arrived at the lookup a moment earlier.


To generate a diff of this commit:
cvs rdiff -u -r1.162 -r1.163 src/sys/dev/dkwedge/dk.c

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



CVS commit: src/sys/dev/dkwedge

2023-05-22 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Mon May 22 14:58:51 UTC 2023

Modified Files:
src/sys/dev/dkwedge: dk.c

Log Message:
dk(4): Use device_lookup_private for dkwedge_lookup.

No longer necessary to go through the dkwedges array.

Currently device_lookup_private still involves touching other global
locks, but that will change eventually to a lockless pserialized fast
path.


To generate a diff of this commit:
cvs rdiff -u -r1.160 -r1.161 src/sys/dev/dkwedge/dk.c

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

Modified files:

Index: src/sys/dev/dkwedge/dk.c
diff -u src/sys/dev/dkwedge/dk.c:1.160 src/sys/dev/dkwedge/dk.c:1.161
--- src/sys/dev/dkwedge/dk.c:1.160	Mon May 22 14:58:41 2023
+++ src/sys/dev/dkwedge/dk.c	Mon May 22 14:58:50 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: dk.c,v 1.160 2023/05/22 14:58:41 riastradh Exp $	*/
+/*	$NetBSD: dk.c,v 1.161 2023/05/22 14:58:50 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2004, 2005, 2006, 2007 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: dk.c,v 1.160 2023/05/22 14:58:41 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: dk.c,v 1.161 2023/05/22 14:58:50 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_dkwedge.h"
@@ -1164,17 +1164,8 @@ dkwedge_read(struct disk *pdk, struct vn
 static struct dkwedge_softc *
 dkwedge_lookup(dev_t dev)
 {
-	const int unit = minor(dev);
-	struct dkwedge_softc *sc;
-
-	rw_enter(&dkwedges_lock, RW_READER);
-	if (unit < 0 || unit >= ndkwedges)
-		sc = NULL;
-	else
-		sc = dkwedges[unit];
-	rw_exit(&dkwedges_lock);
 
-	return sc;
+	return device_lookup_private(&dk_cd, minor(dev));
 }
 
 static int



CVS commit: src/sys/dev/dkwedge

2023-05-22 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Mon May 22 14:58:41 UTC 2023

Modified Files:
src/sys/dev/dkwedge: dk.c

Log Message:
dk(4): dkunit is no longer needed; nix it.

dkwedges array indexing now coincides with autoconf device numbering.


To generate a diff of this commit:
cvs rdiff -u -r1.159 -r1.160 src/sys/dev/dkwedge/dk.c

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

Modified files:

Index: src/sys/dev/dkwedge/dk.c
diff -u src/sys/dev/dkwedge/dk.c:1.159 src/sys/dev/dkwedge/dk.c:1.160
--- src/sys/dev/dkwedge/dk.c:1.159	Mon May 22 14:58:32 2023
+++ src/sys/dev/dkwedge/dk.c	Mon May 22 14:58:41 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: dk.c,v 1.159 2023/05/22 14:58:32 riastradh Exp $	*/
+/*	$NetBSD: dk.c,v 1.160 2023/05/22 14:58:41 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2004, 2005, 2006, 2007 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: dk.c,v 1.159 2023/05/22 14:58:32 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: dk.c,v 1.160 2023/05/22 14:58:41 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_dkwedge.h"
@@ -114,8 +114,6 @@ static int	dkwedge_del1(struct dkwedge_i
 static int	dk_open_parent(dev_t, int, struct vnode **);
 static int	dk_close_parent(struct vnode *, int);
 
-static int	dkunit(dev_t);
-
 static dev_type_open(dkopen);
 static dev_type_close(dkclose);
 static dev_type_cancel(dkcancel);
@@ -142,7 +140,7 @@ const struct bdevsw dk_bdevsw = {
 	.d_psize = dksize,
 	.d_discard = dkdiscard,
 	.d_cfdriver = &dk_cd,
-	.d_devtounit = dkunit,
+	.d_devtounit = dev_minor_unit,
 	.d_flag = D_DISK | D_MPSAFE
 };
 
@@ -160,7 +158,7 @@ const struct cdevsw dk_cdevsw = {
 	.d_kqfilter = nokqfilter,
 	.d_discard = dkdiscard,
 	.d_cfdriver = &dk_cd,
-	.d_devtounit = dkunit,
+	.d_devtounit = dev_minor_unit,
 	.d_flag = D_DISK | D_MPSAFE
 };
 
@@ -1224,36 +1222,6 @@ dk_close_parent(struct vnode *vp, int mo
 }
 
 /*
- * dkunit:		[devsw entry point]
- *
- *	Return the autoconf device_t unit number of a wedge by its
- *	devsw dev_t number, or -1 if there is none.
- *
- *	XXX This is a temporary hack until dkwedge numbering is made to
- *	correspond 1:1 to autoconf device numbering.
- */
-static int
-dkunit(dev_t dev)
-{
-	int mn = minor(dev);
-	struct dkwedge_softc *sc;
-	device_t dv;
-	int unit = -1;
-
-	if (mn < 0)
-		return -1;
-
-	rw_enter(&dkwedges_lock, RW_READER);
-	if (mn < ndkwedges &&
-	(sc = dkwedges[minor(dev)]) != NULL &&
-	(dv = sc->sc_dev) != NULL)
-		unit = device_unit(dv);
-	rw_exit(&dkwedges_lock);
-
-	return unit;
-}
-
-/*
  * dkopen:		[devsw entry point]
  *
  *	Open a wedge.



CVS commit: src/sys/dev/dkwedge

2023-05-22 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Mon May 22 14:58:33 UTC 2023

Modified Files:
src/sys/dev/dkwedge: dk.c

Log Message:
dk(4): Use config_attach_pseudo_acquire to create wedges.

This way, indexing of the dkwedges array coincides with numbering of
autoconf dk(4) instances.

As a side effect, this plugs a race in dkwedge_add with concurrent
drvctl -r.  There are a lot of such races in dk(4) left -- to be
addressed with more device references.


To generate a diff of this commit:
cvs rdiff -u -r1.158 -r1.159 src/sys/dev/dkwedge/dk.c

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



CVS commit: src/sys

2023-05-22 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Mon May 22 14:58:22 UTC 2023

Modified Files:
src/sys/kern: subr_autoconf.c
src/sys/sys: device.h

Log Message:
autoconf(9): New functions for referenced attach/detach.

New functions:

- config_found_acquire(dev, aux, print, cfargs)
- config_attach_acquire(parent, cf, aux, print, cfargs)
- config_attach_pseudo_acquire(cf, aux)
- config_detach_release(dev, flags)
- device_acquire(dev)

The config_*_acquire functions are like the non-acquire versions, but
they return a referenced device_t, which is guaranteed to be safe to
use until released.  The device's detach function may run while it is
referenced, but the device_t will not be freed and the parent's
.ca_childdetached routine will not be called.

=> config_attach_pseudo_acquire additionally lets you pass an aux
   argument to the device's .ca_attach routine, unlike
   config_attach_pseudo which always passes NULL.

=> Eventually, config_found, config_attach, and config_attach_pseudo
   should be made to return void, because use of the device_t they
   return is unsafe without the kernel lock and difficult to use
   safely even with the kernel lock or in a UP system.  For now,
   they require the caller to hold the kernel lock, while
   config_*_acquire do not.

config_detach_release is like device_release and then config_detach,
but avoids the race inherent with that sequence.

=> Eventually, config_detach should be eliminated, because getting at
   the device_t it needs is unsafe without the kernel lock and
   difficult to use safely even with the kernel lock or in a UP
   system.  For now, it requires the caller to hold the kernel lock,
   while config_detach_release does not.

device_acquire acquires a reference to a device.  It never fails and
can be used in thread context (but not interrupt context, hard or
soft).  Caller is responsible for ensuring that the device_t cannot
be freed; in other words, the device_t must be made unavailable to
any device_acquire callers before the .ca_detach function returns.
Typically device_acquire will be used in a read section (mutex,
rwlock, pserialize, &c.) in a data structure lookup, with
corresponding logic in the .ca_detach function to remove the device
from the data structure and wait for all read sections to complete.

Proposed on tech-kern:
https://mail-index.netbsd.org/tech-kern/2023/05/10/msg028889.html


To generate a diff of this commit:
cvs rdiff -u -r1.310 -r1.311 src/sys/kern/subr_autoconf.c
cvs rdiff -u -r1.185 -r1.186 src/sys/sys/device.h

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

Modified files:

Index: src/sys/kern/subr_autoconf.c
diff -u src/sys/kern/subr_autoconf.c:1.310 src/sys/kern/subr_autoconf.c:1.311
--- src/sys/kern/subr_autoconf.c:1.310	Fri Apr 21 17:35:43 2023
+++ src/sys/kern/subr_autoconf.c	Mon May 22 14:58:22 2023
@@ -1,4 +1,4 @@
-/* $NetBSD: subr_autoconf.c,v 1.310 2023/04/21 17:35:43 riastradh Exp $ */
+/* $NetBSD: subr_autoconf.c,v 1.311 2023/05/22 14:58:22 riastradh Exp $ */
 
 /*
  * Copyright (c) 1996, 2000 Christopher G. Demetriou
@@ -77,7 +77,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: subr_autoconf.c,v 1.310 2023/04/21 17:35:43 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: subr_autoconf.c,v 1.311 2023/05/22 14:58:22 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_ddb.h"
@@ -1259,17 +1259,21 @@ static const char * const msgs[] = {
  * not configured, call the given `print' function and return NULL.
  */
 device_t
-config_found(device_t parent, void *aux, cfprint_t print,
+config_found_acquire(device_t parent, void *aux, cfprint_t print,
 const struct cfargs * const cfargs)
 {
 	cfdata_t cf;
 	struct cfargs_internal store;
 	const struct cfargs_internal * const args =
 	cfargs_canonicalize(cfargs, &store);
+	device_t dev;
+
+	KERNEL_LOCK(1, NULL);
 
 	cf = config_search_internal(parent, aux, args);
 	if (cf != NULL) {
-		return config_attach_internal(parent, cf, aux, print, args);
+		dev = config_attach_internal(parent, cf, aux, print, args);
+		goto out;
 	}
 
 	if (print) {
@@ -1283,7 +1287,39 @@ config_found(device_t parent, void *aux,
 		aprint_normal("%s", msgs[pret]);
 	}
 
-	return NULL;
+	dev = NULL;
+
+out:	KERNEL_UNLOCK_ONE(NULL);
+	return dev;
+}
+
+/*
+ * config_found(parent, aux, print, cfargs)
+ *
+ *	Legacy entry point for callers whose use of the returned
+ *	device_t is not delimited by device_release.
+ *
+ *	The caller is required to hold the kernel lock as a fragile
+ *	defence against races.
+ *
+ *	Callers should ignore the return value or be converted to
+ *	config_found_acquire with a matching device_release once they
+ *	have finished with the returned device_t.
+ */
+device_t
+config_found(device_t parent, void *aux, cfprint_t print,
+const struct cfargs * const cfargs)
+{
+	device_t dev;
+
+	KASSERT(KERNEL_LOCKED_P());
+
+	dev = config_found_acquire(parent, aux, print, cfargs

CVS commit: src/sys

2023-05-22 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Mon May 22 14:58:22 UTC 2023

Modified Files:
src/sys/kern: subr_autoconf.c
src/sys/sys: device.h

Log Message:
autoconf(9): New functions for referenced attach/detach.

New functions:

- config_found_acquire(dev, aux, print, cfargs)
- config_attach_acquire(parent, cf, aux, print, cfargs)
- config_attach_pseudo_acquire(cf, aux)
- config_detach_release(dev, flags)
- device_acquire(dev)

The config_*_acquire functions are like the non-acquire versions, but
they return a referenced device_t, which is guaranteed to be safe to
use until released.  The device's detach function may run while it is
referenced, but the device_t will not be freed and the parent's
.ca_childdetached routine will not be called.

=> config_attach_pseudo_acquire additionally lets you pass an aux
   argument to the device's .ca_attach routine, unlike
   config_attach_pseudo which always passes NULL.

=> Eventually, config_found, config_attach, and config_attach_pseudo
   should be made to return void, because use of the device_t they
   return is unsafe without the kernel lock and difficult to use
   safely even with the kernel lock or in a UP system.  For now,
   they require the caller to hold the kernel lock, while
   config_*_acquire do not.

config_detach_release is like device_release and then config_detach,
but avoids the race inherent with that sequence.

=> Eventually, config_detach should be eliminated, because getting at
   the device_t it needs is unsafe without the kernel lock and
   difficult to use safely even with the kernel lock or in a UP
   system.  For now, it requires the caller to hold the kernel lock,
   while config_detach_release does not.

device_acquire acquires a reference to a device.  It never fails and
can be used in thread context (but not interrupt context, hard or
soft).  Caller is responsible for ensuring that the device_t cannot
be freed; in other words, the device_t must be made unavailable to
any device_acquire callers before the .ca_detach function returns.
Typically device_acquire will be used in a read section (mutex,
rwlock, pserialize, &c.) in a data structure lookup, with
corresponding logic in the .ca_detach function to remove the device
from the data structure and wait for all read sections to complete.

Proposed on tech-kern:
https://mail-index.netbsd.org/tech-kern/2023/05/10/msg028889.html


To generate a diff of this commit:
cvs rdiff -u -r1.310 -r1.311 src/sys/kern/subr_autoconf.c
cvs rdiff -u -r1.185 -r1.186 src/sys/sys/device.h

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



CVS commit: src/sys/kern

2023-05-22 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Mon May 22 14:07:37 UTC 2023

Modified Files:
src/sys/kern: tty.c

Log Message:
tty(9): Make ttwrite update uio with only how much it has consumed.

As is, it leaves uio in an inconsistent state.  Good enough for the
write(2) return value to be correct for a userland caller to restart
write(2) where it left off, but not good enough for a loop in the
kernel to reuse the same uio.

Reported-by: syzbot+e0f56178d0add0d8b...@syzkaller.appspotmail.com
https://syzkaller.appspot.com/bug?id=6290eb02b8fe73361dc15c7bc44e1208601e6af8

Reported-by: syzbot+7caa189e8fccd9263...@syzkaller.appspotmail.com
https://syzkaller.appspot.com/bug?id=c0a3b77b4831dfa81fc855857bde81755d246bd3

Reported-by: syzbot+4a1eff91eb4e7c197...@syzkaller.appspotmail.com
https://syzkaller.appspot.com/bug?id=10523a633a4ad9749f57dc7cf03f9447d518c5b8

Reported-by: syzbot+1d3c280f59099dc82...@syzkaller.appspotmail.com
https://syzkaller.appspot.com/bug?id=8e02ebb0da76a8e286461f33502117a1d30275c6

Reported-by: syzbot+080d51214d0634472...@syzkaller.appspotmail.com
https://syzkaller.appspot.com/bug?id=1f617747db8087e5554d3df1b79a545dee26a650

Reported-by: syzbot+dd50b448e49e50201...@syzkaller.appspotmail.com
https://syzkaller.appspot.com/bug?id=f71c8cef4110b7eeac6eca67b6a4d1f4a8b3e96f

Reported-by: syzbot+26b675ecf0cc9dfd8...@syzkaller.appspotmail.com
https://syzkaller.appspot.com/bug?id=57b1901f5b3e090a964d08dd0d729f9909f203be

Reported-by: syzbot+87f0df2c9056313a5...@syzkaller.appspotmail.com
https://syzkaller.appspot.com/bug?id=67994a3da32d075144e25d1ac314be1d9694ae6e

Reported-by: syzbot+e5bc98e18aa42f0cb...@syzkaller.appspotmail.com
https://syzkaller.appspot.com/bug?id=6374bd286532423c63f2b331748280729134224c

Reported-by: syzbot+7e587f4c5aaaf80e8...@syzkaller.appspotmail.com
https://syzkaller.appspot.com/bug?id=976210ed438d48ac275d77d7ebf4a086e43b5fcb


To generate a diff of this commit:
cvs rdiff -u -r1.310 -r1.311 src/sys/kern/tty.c

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

Modified files:

Index: src/sys/kern/tty.c
diff -u src/sys/kern/tty.c:1.310 src/sys/kern/tty.c:1.311
--- src/sys/kern/tty.c:1.310	Wed Apr 12 06:35:26 2023
+++ src/sys/kern/tty.c	Mon May 22 14:07:37 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: tty.c,v 1.310 2023/04/12 06:35:26 riastradh Exp $	*/
+/*	$NetBSD: tty.c,v 1.311 2023/05/22 14:07:37 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2008, 2020 The NetBSD Foundation, Inc.
@@ -63,7 +63,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: tty.c,v 1.310 2023/04/12 06:35:26 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tty.c,v 1.311 2023/05/22 14:07:37 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_compat_netbsd.h"
@@ -2229,13 +2229,13 @@ ttwrite(struct tty *tp, struct uio *uio,
 {
 	u_char		*cp;
 	struct proc	*p;
-	int		cc, ce, i, hiwat, error;
+	int		cc, cc0, ce, i, hiwat, error;
 	u_char		obuf[OBUFSIZ];
 
 	cp = NULL;
 	hiwat = tp->t_hiwat;
 	error = 0;
-	cc = 0;
+	cc0 = cc = 0;
  loop:
 	mutex_spin_enter(&tty_lock);
 	if (!CONNECTED(tp)) {
@@ -2300,9 +2300,10 @@ ttwrite(struct tty *tp, struct uio *uio,
 		 * leftover from last time.
 		 */
 		if (cc == 0) {
-			cc = uimin(uio->uio_resid, OBUFSIZ);
+			uioskip(cc0, uio);
+			cc0 = cc = uimin(uio->uio_resid, OBUFSIZ);
 			cp = obuf;
-			error = uiomove(cp, cc, uio);
+			error = uiopeek(cp, cc, uio);
 			if (error) {
 cc = 0;
 goto out;
@@ -2373,13 +2374,9 @@ ttwrite(struct tty *tp, struct uio *uio,
 	}
 
  out:
-	/*
-	 * If cc is nonzero, we leave the uio structure inconsistent, as the
-	 * offset and iov pointers have moved forward, but it doesn't matter
-	 * (the call will either return short or restart with a new uio).
-	 */
 	KASSERTMSG(error || cc == 0, "error=%d cc=%d", error, cc);
-	uio->uio_resid += cc;
+	KASSERTMSG(cc0 >= cc, "cc0=%d cc=%d", cc0, cc);
+	uioskip(cc0 - cc, uio);
 	return (error);
 
  overfull:



CVS commit: src/sys/kern

2023-05-22 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Mon May 22 14:07:37 UTC 2023

Modified Files:
src/sys/kern: tty.c

Log Message:
tty(9): Make ttwrite update uio with only how much it has consumed.

As is, it leaves uio in an inconsistent state.  Good enough for the
write(2) return value to be correct for a userland caller to restart
write(2) where it left off, but not good enough for a loop in the
kernel to reuse the same uio.

Reported-by: syzbot+e0f56178d0add0d8b...@syzkaller.appspotmail.com
https://syzkaller.appspot.com/bug?id=6290eb02b8fe73361dc15c7bc44e1208601e6af8

Reported-by: syzbot+7caa189e8fccd9263...@syzkaller.appspotmail.com
https://syzkaller.appspot.com/bug?id=c0a3b77b4831dfa81fc855857bde81755d246bd3

Reported-by: syzbot+4a1eff91eb4e7c197...@syzkaller.appspotmail.com
https://syzkaller.appspot.com/bug?id=10523a633a4ad9749f57dc7cf03f9447d518c5b8

Reported-by: syzbot+1d3c280f59099dc82...@syzkaller.appspotmail.com
https://syzkaller.appspot.com/bug?id=8e02ebb0da76a8e286461f33502117a1d30275c6

Reported-by: syzbot+080d51214d0634472...@syzkaller.appspotmail.com
https://syzkaller.appspot.com/bug?id=1f617747db8087e5554d3df1b79a545dee26a650

Reported-by: syzbot+dd50b448e49e50201...@syzkaller.appspotmail.com
https://syzkaller.appspot.com/bug?id=f71c8cef4110b7eeac6eca67b6a4d1f4a8b3e96f

Reported-by: syzbot+26b675ecf0cc9dfd8...@syzkaller.appspotmail.com
https://syzkaller.appspot.com/bug?id=57b1901f5b3e090a964d08dd0d729f9909f203be

Reported-by: syzbot+87f0df2c9056313a5...@syzkaller.appspotmail.com
https://syzkaller.appspot.com/bug?id=67994a3da32d075144e25d1ac314be1d9694ae6e

Reported-by: syzbot+e5bc98e18aa42f0cb...@syzkaller.appspotmail.com
https://syzkaller.appspot.com/bug?id=6374bd286532423c63f2b331748280729134224c

Reported-by: syzbot+7e587f4c5aaaf80e8...@syzkaller.appspotmail.com
https://syzkaller.appspot.com/bug?id=976210ed438d48ac275d77d7ebf4a086e43b5fcb


To generate a diff of this commit:
cvs rdiff -u -r1.310 -r1.311 src/sys/kern/tty.c

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



CVS commit: src

2023-05-22 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Mon May 22 14:07:24 UTC 2023

Modified Files:
src/share/man/man9: uiomove.9
src/sys/kern: subr_copy.c
src/sys/sys: systm.h

Log Message:
uiomove(9): Add uiopeek/uioskip operations.

This allows a caller to grab some data, consume part of it, and
atomically update the uio with only the amount it consumed.  This
way, the caller can use a buffer of a size that doesn't depend on how
much it will actually consume, which it may not know in advance --
e.g., because it depends on how much an underlying hardware tty
device will accept before it decides it has had too much.

Proposed on tech-kern:
https://mail-index.netbsd.org/tech-kern/2023/05/09/msg028883.html

(Opinions were divided between `uioadvance' and `uioskip'.  I stuck
with `uioskip' because that was less work for me.)


To generate a diff of this commit:
cvs rdiff -u -r1.20 -r1.21 src/share/man/man9/uiomove.9
cvs rdiff -u -r1.18 -r1.19 src/sys/kern/subr_copy.c
cvs rdiff -u -r1.301 -r1.302 src/sys/sys/systm.h

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

Modified files:

Index: src/share/man/man9/uiomove.9
diff -u src/share/man/man9/uiomove.9:1.20 src/share/man/man9/uiomove.9:1.21
--- src/share/man/man9/uiomove.9:1.20	Sun Sep  1 19:08:35 2019
+++ src/share/man/man9/uiomove.9	Mon May 22 14:07:24 2023
@@ -1,4 +1,4 @@
-.\"	$NetBSD: uiomove.9,v 1.20 2019/09/01 19:08:35 wiz Exp $
+.\"	$NetBSD: uiomove.9,v 1.21 2023/05/22 14:07:24 riastradh Exp $
 .\"
 .\" Copyright (c) 1996 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -24,7 +24,7 @@
 .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 .\" POSSIBILITY OF SUCH DAMAGE.
 .\"
-.Dd April 26, 2010
+.Dd May 9, 2023
 .Dt UIOMOVE 9
 .Os
 .Sh NAME
@@ -34,6 +34,10 @@
 .In sys/systm.h
 .Ft int
 .Fn uiomove "void *buf" "size_t n" "struct uio *uio"
+.Ft int
+.Fn uiopeek "void *buf" "size_t n" "struct uio *uio"
+.Ft void
+.Fn uioskip "void *buf" "size_t n" "struct uio *uio"
 .Sh DESCRIPTION
 The
 .Fn uiomove
@@ -140,10 +144,35 @@ to point that much farther into the regi
 This allows multiple calls to
 .Fn uiomove
 to easily be used to fill or drain the region of data.
+.Pp
+The
+.Fn uiopeek
+function copies up to
+.Fa n
+bytes of data without updating
+.Fa uio ;
+the
+.Fn uioskip
+function updates
+.Fa uio
+without copying any data, and is guaranteed never to sleep or fault
+even if the buffers are in userspace and memory access via
+.Fn uiomove
+or
+.Fn uiopeek
+would trigger paging.
+A successful
+.Fn uiomove buf n uio
+call is equivalent to a successful
+.Fn uiopeek buf n uio
+followed by
+.Fn uioskip n uio .
 .Sh RETURN VALUES
 Upon successful completion,
 .Fn uiomove
-returns 0.
+and
+.Fn uiopeek
+return 0.
 If a bad address is encountered,
 .Er EFAULT
 is returned.

Index: src/sys/kern/subr_copy.c
diff -u src/sys/kern/subr_copy.c:1.18 src/sys/kern/subr_copy.c:1.19
--- src/sys/kern/subr_copy.c:1.18	Tue Apr 11 10:22:04 2023
+++ src/sys/kern/subr_copy.c	Mon May 22 14:07:24 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: subr_copy.c,v 1.18 2023/04/11 10:22:04 riastradh Exp $	*/
+/*	$NetBSD: subr_copy.c,v 1.19 2023/05/22 14:07:24 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 1997, 1998, 1999, 2002, 2007, 2008, 2019
@@ -80,7 +80,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: subr_copy.c,v 1.18 2023/04/11 10:22:04 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: subr_copy.c,v 1.19 2023/05/22 14:07:24 riastradh Exp $");
 
 #define	__UFETCHSTORE_PRIVATE
 #define	__UCAS_PRIVATE
@@ -166,6 +166,93 @@ uiomove_frombuf(void *buf, size_t buflen
 	return (uiomove((char *)buf + offset, buflen - offset, uio));
 }
 
+int
+uiopeek(void *buf, size_t n, struct uio *uio)
+{
+	struct vmspace *vm = uio->uio_vmspace;
+	struct iovec *iov;
+	size_t cnt;
+	int error = 0;
+	char *cp = buf;
+	size_t resid = uio->uio_resid;
+	int iovcnt = uio->uio_iovcnt;
+	char *base;
+	size_t len;
+
+	KASSERT(uio->uio_rw == UIO_READ || uio->uio_rw == UIO_WRITE);
+
+	if (n == 0 || resid == 0)
+		return 0;
+	iov = uio->uio_iov;
+	base = iov->iov_base;
+	len = iov->iov_len;
+
+	while (n > 0 && resid > 0) {
+		KASSERT(iovcnt > 0);
+		cnt = len;
+		if (cnt == 0) {
+			KASSERT(iovcnt > 1);
+			iov++;
+			iovcnt--;
+			base = iov->iov_base;
+			len = iov->iov_len;
+			continue;
+		}
+		if (cnt > n)
+			cnt = n;
+		if (!VMSPACE_IS_KERNEL_P(vm)) {
+			preempt_point();
+		}
+
+		if (uio->uio_rw == UIO_READ) {
+			error = copyout_vmspace(vm, cp, base, cnt);
+		} else {
+			error = copyin_vmspace(vm, base, cp, cnt);
+		}
+		if (error) {
+			break;
+		}
+		base += cnt;
+		len -= cnt;
+		resid -= cnt;
+		cp += cnt;
+		KDASSERT(cnt <= n);
+		n -= cnt;
+	}
+
+	return error;
+}
+
+void
+uioskip(size_t n, struct uio *uio)
+{
+	struct iovec *iov;
+	size_t cnt;
+
+	KASSERTMSG(n <= uio->uio_resid, "n=%zu resid=%zu", n, uio->uio_resid);
+
+	KASSERT(uio->uio_rw == UIO_READ || uio->uio_rw == UIO_WRITE);
+	while (

CVS commit: src

2023-05-22 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Mon May 22 14:07:24 UTC 2023

Modified Files:
src/share/man/man9: uiomove.9
src/sys/kern: subr_copy.c
src/sys/sys: systm.h

Log Message:
uiomove(9): Add uiopeek/uioskip operations.

This allows a caller to grab some data, consume part of it, and
atomically update the uio with only the amount it consumed.  This
way, the caller can use a buffer of a size that doesn't depend on how
much it will actually consume, which it may not know in advance --
e.g., because it depends on how much an underlying hardware tty
device will accept before it decides it has had too much.

Proposed on tech-kern:
https://mail-index.netbsd.org/tech-kern/2023/05/09/msg028883.html

(Opinions were divided between `uioadvance' and `uioskip'.  I stuck
with `uioskip' because that was less work for me.)


To generate a diff of this commit:
cvs rdiff -u -r1.20 -r1.21 src/share/man/man9/uiomove.9
cvs rdiff -u -r1.18 -r1.19 src/sys/kern/subr_copy.c
cvs rdiff -u -r1.301 -r1.302 src/sys/sys/systm.h

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



CVS commit: src/share

2023-05-22 Thread Luke Mewburn
Module Name:src
Committed By:   lukem
Date:   Mon May 22 12:55:45 UTC 2023

Modified Files:
src/share/man/man0: Makefile
src/share/mk: bsd.own.mk
Removed Files:
src/share/man/man0: mkman

Log Message:
man0: support objdirs, tools, parallel builds

man0 creates files, so write to the the OBJDIR instead of the
source directory.

Use TOOL_ appropriately.
Add MAKEVERBOSE support.

Add separate rules to generate:
- all.files: the list of all man files to process (based on mkman)
- manNpages.files: per-section files from all.files. (based on mkman)
- manNpages.ps: per-section .ps from manNpages.files, with
  per-file MAKEVERBOSE messages to stderr (as before, just prettier).
- manNpages.pdf: per-section .pdf from manNpages.ps.

Remove the now-obsolete mkman script.

Add TOOL_GROPS and _MKSHMSG_FORMAT to 


To generate a diff of this commit:
cvs rdiff -u -r1.17 -r1.18 src/share/man/man0/Makefile
cvs rdiff -u -r1.5 -r0 src/share/man/man0/mkman
cvs rdiff -u -r1.1324 -r1.1325 src/share/mk/bsd.own.mk

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



CVS commit: src/share

2023-05-22 Thread Luke Mewburn
Module Name:src
Committed By:   lukem
Date:   Mon May 22 12:55:45 UTC 2023

Modified Files:
src/share/man/man0: Makefile
src/share/mk: bsd.own.mk
Removed Files:
src/share/man/man0: mkman

Log Message:
man0: support objdirs, tools, parallel builds

man0 creates files, so write to the the OBJDIR instead of the
source directory.

Use TOOL_ appropriately.
Add MAKEVERBOSE support.

Add separate rules to generate:
- all.files: the list of all man files to process (based on mkman)
- manNpages.files: per-section files from all.files. (based on mkman)
- manNpages.ps: per-section .ps from manNpages.files, with
  per-file MAKEVERBOSE messages to stderr (as before, just prettier).
- manNpages.pdf: per-section .pdf from manNpages.ps.

Remove the now-obsolete mkman script.

Add TOOL_GROPS and _MKSHMSG_FORMAT to 


To generate a diff of this commit:
cvs rdiff -u -r1.17 -r1.18 src/share/man/man0/Makefile
cvs rdiff -u -r1.5 -r0 src/share/man/man0/mkman
cvs rdiff -u -r1.1324 -r1.1325 src/share/mk/bsd.own.mk

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

Modified files:

Index: src/share/man/man0/Makefile
diff -u src/share/man/man0/Makefile:1.17 src/share/man/man0/Makefile:1.18
--- src/share/man/man0/Makefile:1.17	Tue Feb  7 19:13:31 2012
+++ src/share/man/man0/Makefile	Mon May 22 12:55:44 2023
@@ -1,7 +1,9 @@
 #	from: @(#)Makefile	5.9 (Berkeley) 7/1/91
-#	$NetBSD: Makefile,v 1.17 2012/02/07 19:13:31 joerg Exp $
+#	$NetBSD: Makefile,v 1.18 2023/05/22 12:55:44 lukem Exp $
 
-NOOBJ=		# defined
+#
+# Note: Needs ps2pdf to convert .ps to .pdf
+#
 
 .include 
 
@@ -10,63 +12,97 @@ FILES=		makewhatis.sed
 FILESDIR=	/usr/share/man
 .endif
 
-CLEANFILES+=	man?
-CLEANFILES+=	man?pages.tmp
-CLEANFILES+=	man?pages.ps
-CLEANFILES+=	man?pages.pdf
-CLEANFILES+=	toc? tocx?
-
 SECTIONS?=	1 2 3 4 5 6 7 8 9
 
+MANSRCDIRS=	"${.CURDIR}/../../.." ../../..
+
 # Takes out some fluff from the PostScript files created by
 # grops which does some VM saving/restoring that bloats the
 # PDF file pdf2ps generates.  By u...@netbsd.org.
 OPTIMIZE_PDF?=	\
-			-e '/^\/level0 0 def/d' 		\
-			-e '/^\/level0 save/d' 			\
-			-e '/^level0 restore/d' 		
-
-all: man man.ps man.pdf
-
-man: 
-	${HOST_SH} mkman
-
-man.ps: 
-	for i in ${SECTIONS} ; 	\
-	do			\
-		for f in `grep "$${i}\$$" intros` `cat man$${i}` ; \
-		do		\
-			if [ ! -f $${f} ]; then 		\
-continue ; 			\
-			fi ;	\
-			if grep -q ^\\.TS back ;		\
-			then	\
-echo >&2 $${f} ; 			\
-cat $${f} | tbl | troff -msafer -man -Tps ; \
-			else 	\
-echo >&2 $${f} "(tbl)" ;	\
-cat $${f} | troff -msafer -man -Tps ; \
-			fi ; 	\
-		done >man$${i}pages.tmp ;			\
-		cat man$${i}pages.tmp\
-		| grep -v '^x stop' \
-		| grops >man$${i}pages.ps ;			\
-		rm man$${i}pages.tmp ; 		\
-	done
-
-man.pdf: 
-	for i in ${SECTIONS} ; 	\
-	do			\
-		echo Chewing on man$${i}pages.pdf ;		\
-		${TOOL_SED} 	\
-			${OPTIMIZE_PDF} 			\
-			man$${i}pages.ps.tmp ; \
-		ps2pdf man$${i}pages.ps.tmp man$${i}pages.pdf ;	\
-		rm man$${i}pages.ps.tmp ; 			\
-	done
+			-e '/^\/level0 0 def/d'		\
+			-e '/^\/level0 save/d'		\
+			-e '/^level0 restore/d'
+
+MAN0SRCS=
+.if ${MKMAN} != "no"
+MAN0SRCS+=	all.files
+MAN0SRCS+=	${SECTIONS:@S@man${S}pages.files@}
+MAN0SRCS+=	${SECTIONS:@S@man${S}pages.ps @}
+MAN0SRCS+=	${SECTIONS:@S@man${S}pages.pdf@}
+.endif
+
+CLEANFILES+=	${MAN0SRCS}
+CLEANFILES+=	*.tmp
+CLEANFILES+=	toc? tocx?
+
+all: ${MAN0SRCS}
+
+all.files:
+	${_MKTARGET_CREATE}
+	find ${MANSRCDIRS} -name '*.[1-9]' -print	\
+	| xargs ${TOOL_MKMAGIC}\
+	| ${TOOL_GREP} troff\
+	| ${TOOL_SED} 's/:[ 	]*.*$$//'		\
+	| ${TOOL_GREP} -F -v -f "${.CURDIR}/noman"	\
+	| ${TOOL_GREP} -v '#'\
+	| ${TOOL_GREP} -v '/obj\.'			\
+	| ${TOOL_GREP} -v '/destdir\.'			\
+	| ${TOOL_GREP} -v '/tooldir\.'			\
+	> ${.TARGET}.tmp\
+	&& ${MV} ${.TARGET}.tmp ${.TARGET} ;		\
+	rm -f ${.TARGET}.tmp
+
+
+.for _S in ${SECTIONS}
+
+man${_S}pages.files: all.files
+	${_MKTARGET_CREATE}
+	cat ${.ALLSRC}	\
+	| ${TOOL_GREP} "${_S}\$$"			\
+	| ${TOOL_SED} 's,\(.*/\)\([^/]*\),\2 \1\2,'	\
+	| sort		\
+	| ${TOOL_SED} 's/^.* //'			\
+	> ${.TARGET}.tmp\
+	&& ${MV} ${.TARGET}.tmp ${.TARGET} ;		\
+	rm -f ${.TARGET}.tmp
+
+man${_S}pages.ps: man${_S}pages.files
+	${_MKTARGET_CREATE}
+	for f in `${TOOL_GREP} "${_S}\$$" "${.CURDIR}/intros"` `cat ${.ALLSRC}` ; \
+	do		\
+		if [ ! -f $${f} ]; then			\
+			continue ;			\
+		fi ;	\
+		if ${TOOL_GREP} -q ^\\.TS "${.CURDIR}/back" ; \
+		then	\
+			${_MKSHMSG_FORMAT} >&2 $${f} ;	\
+			cat $${f} | ${TOOL_TBL} | ${TOOL_GROFF} -Z -msafer -man -Tps ; \
+		else	\
+			${_MKSHMSG_FORMAT} >&2 $${f} "(tbl)";	\
+			cat $${f} | ${TOOL_GROFF} -Z -msafer -man -Tps ; \
+		fi ;	\
+	done > ${.TARGET}.troff.tmp			\
+	&& cat ${.TARGET}.troff.tmp			\
+	| ${TOOL_GREP} -v '^x stop'			\
+	| ${TOOL_GROPS} \
+	> ${.TARGET}.tmp\
+	&& ${MV} 

CVS commit: src

2023-05-22 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Mon May 22 12:55:04 UTC 2023

Modified Files:
src/tests/usr.bin/xlint/lint1: decl_struct_member.c msg_108.c
src/tests/usr.bin/xlint/lint2: read.ln
src/usr.bin/xlint/common: inittyp.c lint.h
src/usr.bin/xlint/lint1: ckbool.c debug.c decl.c tree.c
src/usr.bin/xlint/lint2: chk.c read.c

Log Message:
lint: rename constant NOTSPEC to NO_TSPEC

It was too easy to misread the old name as NOT_SPEC instead of the
intended NO_TSPEC.


To generate a diff of this commit:
cvs rdiff -u -r1.16 -r1.17 src/tests/usr.bin/xlint/lint1/decl_struct_member.c
cvs rdiff -u -r1.7 -r1.8 src/tests/usr.bin/xlint/lint1/msg_108.c
cvs rdiff -u -r1.5 -r1.6 src/tests/usr.bin/xlint/lint2/read.ln
cvs rdiff -u -r1.33 -r1.34 src/usr.bin/xlint/common/inittyp.c
cvs rdiff -u -r1.35 -r1.36 src/usr.bin/xlint/common/lint.h
cvs rdiff -u -r1.20 -r1.21 src/usr.bin/xlint/lint1/ckbool.c
cvs rdiff -u -r1.30 -r1.31 src/usr.bin/xlint/lint1/debug.c
cvs rdiff -u -r1.310 -r1.311 src/usr.bin/xlint/lint1/decl.c
cvs rdiff -u -r1.523 -r1.524 src/usr.bin/xlint/lint1/tree.c
cvs rdiff -u -r1.53 -r1.54 src/usr.bin/xlint/lint2/chk.c
cvs rdiff -u -r1.79 -r1.80 src/usr.bin/xlint/lint2/read.c

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

Modified files:

Index: src/tests/usr.bin/xlint/lint1/decl_struct_member.c
diff -u src/tests/usr.bin/xlint/lint1/decl_struct_member.c:1.16 src/tests/usr.bin/xlint/lint1/decl_struct_member.c:1.17
--- src/tests/usr.bin/xlint/lint1/decl_struct_member.c:1.16	Tue Mar 28 14:44:34 2023
+++ src/tests/usr.bin/xlint/lint1/decl_struct_member.c	Mon May 22 12:55:04 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: decl_struct_member.c,v 1.16 2023/03/28 14:44:34 rillig Exp $	*/
+/*	$NetBSD: decl_struct_member.c,v 1.17 2023/05/22 12:55:04 rillig Exp $	*/
 # 3 "decl_struct_member.c"
 
 /* lint1-extra-flags: -X 351 */
@@ -86,7 +86,7 @@ struct {
  * Before cgram.y 1.328 from 2021-07-15, lint ran into an assertion failure
  * at the closing semicolon:
  *
- * assertion "t == NOTSPEC" failed in end_type at decl.c:774
+ * assertion "t == NO_TSPEC" failed in end_type at decl.c:774
  */
 };
 /* expect+1: error: cannot recover from previous errors [224] */

Index: src/tests/usr.bin/xlint/lint1/msg_108.c
diff -u src/tests/usr.bin/xlint/lint1/msg_108.c:1.7 src/tests/usr.bin/xlint/lint1/msg_108.c:1.8
--- src/tests/usr.bin/xlint/lint1/msg_108.c:1.7	Tue Jun 21 21:18:30 2022
+++ src/tests/usr.bin/xlint/lint1/msg_108.c	Mon May 22 12:55:04 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: msg_108.c,v 1.7 2022/06/21 21:18:30 rillig Exp $	*/
+/*	$NetBSD: msg_108.c,v 1.8 2023/05/22 12:55:04 rillig Exp $	*/
 # 3 "msg_108.c"
 
 // Test for message: operand of '%s' has invalid type '%s' [108]
@@ -6,8 +6,8 @@
 /*
  * Before tree.c 1.137 from 2021-01-19, taking the complement of a struct
  * (an absurd idea, by the way), resulted in an internal error because the
- * message 108 had two operands, the second of which was always NOTSPEC, as
- * could be expected for a unary operator.
+ * message 108 took two type operands, the second of which was not available
+ * for unary operators.
  *
  * Since an error "invalid type 'none'" doesn't make sense, lint rather chose
  * to crash than to generate such an error.

Index: src/tests/usr.bin/xlint/lint2/read.ln
diff -u src/tests/usr.bin/xlint/lint2/read.ln:1.5 src/tests/usr.bin/xlint/lint2/read.ln:1.6
--- src/tests/usr.bin/xlint/lint2/read.ln:1.5	Mon Aug 30 21:23:37 2021
+++ src/tests/usr.bin/xlint/lint2/read.ln	Mon May 22 12:55:04 2023
@@ -1,4 +1,4 @@
-# $NetBSD: read.ln,v 1.5 2021/08/30 21:23:37 rillig Exp $
+# $NetBSD: read.ln,v 1.6 2023/05/22 12:55:04 rillig Exp $
 #
 # Cover each path of reading declarations, definitions and usages.
 
@@ -10,7 +10,7 @@ S read.c
 # The line numbers correspond to the constant values of tspec_t,
 # with the 128-bit types included.
 #
-# NOTSPEC	cannot occur in lint1 output.
+# NO_TSPEC	cannot occur in lint1 output.
 # SIGNED	cannot occur in lint1 output.
 # UNSIGN	cannot occur in lint1 output.
 103 d 0.103 e 4f103 F0 B	# BOOL		_Bool		f103(void);

Index: src/usr.bin/xlint/common/inittyp.c
diff -u src/usr.bin/xlint/common/inittyp.c:1.33 src/usr.bin/xlint/common/inittyp.c:1.34
--- src/usr.bin/xlint/common/inittyp.c:1.33	Wed Nov 30 20:50:22 2022
+++ src/usr.bin/xlint/common/inittyp.c	Mon May 22 12:55:04 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: inittyp.c,v 1.33 2022/11/30 20:50:22 rillig Exp $	*/
+/*	$NetBSD: inittyp.c,v 1.34 2023/05/22 12:55:04 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
 
 #include 
 #if defined(__RCSID)
-__RCSID("$NetBSD: inittyp.c,v 1.33 2022/11/30 20:50:22 rillig Exp $");
+__RCSID("$NetBSD: inittyp.c,v 1.34 2023/05/22 12:55:04 rillig Exp $");
 #endif
 
 #if defined(IS_LINT1)
@@ -80,7 +80,7 @@ __RCSID("$NetBSD: inittyp.c,v 1.33 2022/
 
 /* various type information */
 ttab_t	ttab[NTSPEC] = {
-	typeinfo(NULL, NOTSPEC, NOTSPEC

CVS commit: src

2023-05-22 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Mon May 22 12:55:04 UTC 2023

Modified Files:
src/tests/usr.bin/xlint/lint1: decl_struct_member.c msg_108.c
src/tests/usr.bin/xlint/lint2: read.ln
src/usr.bin/xlint/common: inittyp.c lint.h
src/usr.bin/xlint/lint1: ckbool.c debug.c decl.c tree.c
src/usr.bin/xlint/lint2: chk.c read.c

Log Message:
lint: rename constant NOTSPEC to NO_TSPEC

It was too easy to misread the old name as NOT_SPEC instead of the
intended NO_TSPEC.


To generate a diff of this commit:
cvs rdiff -u -r1.16 -r1.17 src/tests/usr.bin/xlint/lint1/decl_struct_member.c
cvs rdiff -u -r1.7 -r1.8 src/tests/usr.bin/xlint/lint1/msg_108.c
cvs rdiff -u -r1.5 -r1.6 src/tests/usr.bin/xlint/lint2/read.ln
cvs rdiff -u -r1.33 -r1.34 src/usr.bin/xlint/common/inittyp.c
cvs rdiff -u -r1.35 -r1.36 src/usr.bin/xlint/common/lint.h
cvs rdiff -u -r1.20 -r1.21 src/usr.bin/xlint/lint1/ckbool.c
cvs rdiff -u -r1.30 -r1.31 src/usr.bin/xlint/lint1/debug.c
cvs rdiff -u -r1.310 -r1.311 src/usr.bin/xlint/lint1/decl.c
cvs rdiff -u -r1.523 -r1.524 src/usr.bin/xlint/lint1/tree.c
cvs rdiff -u -r1.53 -r1.54 src/usr.bin/xlint/lint2/chk.c
cvs rdiff -u -r1.79 -r1.80 src/usr.bin/xlint/lint2/read.c

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



CVS commit: src/share/man/man0

2023-05-22 Thread Luke Mewburn
Module Name:src
Committed By:   lukem
Date:   Mon May 22 12:34:48 UTC 2023

Modified Files:
src/share/man/man0: noman

Log Message:
man0: add bind/dist/bin/tests to noman


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/share/man/man0/noman

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

Modified files:

Index: src/share/man/man0/noman
diff -u src/share/man/man0/noman:1.1 src/share/man/man0/noman:1.2
--- src/share/man/man0/noman:1.1	Sun Jun 24 02:34:49 2001
+++ src/share/man/man0/noman	Mon May 22 12:34:48 2023
@@ -1,5 +1,6 @@
-#	$NetBSD: noman,v 1.1 2001/06/24 02:34:49 hubertf Exp $
+#	$NetBSD: noman,v 1.2 2023/05/22 12:34:48 lukem Exp $
 # troff files that are no manpages - ready for fgrep -v
 USD.doc/csh
+bind/dist/bin/tests
 libcurses/PSD.doc
 /intro



CVS commit: src/share/man/man0

2023-05-22 Thread Luke Mewburn
Module Name:src
Committed By:   lukem
Date:   Mon May 22 12:34:48 UTC 2023

Modified Files:
src/share/man/man0: noman

Log Message:
man0: add bind/dist/bin/tests to noman


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/share/man/man0/noman

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



CVS commit: src/tests/usr.bin/xlint/lint1

2023-05-22 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Mon May 22 11:51:46 UTC 2023

Modified Files:
src/tests/usr.bin/xlint/lint1: emit.c emit.exp-ln

Log Message:
tests/lint: demonstrate wrong emitted array length in initialization

Seen in usr.bin/indent/debug.c, in the various 'name' arrays.


To generate a diff of this commit:
cvs rdiff -u -r1.15 -r1.16 src/tests/usr.bin/xlint/lint1/emit.c
cvs rdiff -u -r1.10 -r1.11 src/tests/usr.bin/xlint/lint1/emit.exp-ln

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



CVS commit: src/tests/usr.bin/xlint/lint1

2023-05-22 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Mon May 22 11:51:46 UTC 2023

Modified Files:
src/tests/usr.bin/xlint/lint1: emit.c emit.exp-ln

Log Message:
tests/lint: demonstrate wrong emitted array length in initialization

Seen in usr.bin/indent/debug.c, in the various 'name' arrays.


To generate a diff of this commit:
cvs rdiff -u -r1.15 -r1.16 src/tests/usr.bin/xlint/lint1/emit.c
cvs rdiff -u -r1.10 -r1.11 src/tests/usr.bin/xlint/lint1/emit.exp-ln

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

Modified files:

Index: src/tests/usr.bin/xlint/lint1/emit.c
diff -u src/tests/usr.bin/xlint/lint1/emit.c:1.15 src/tests/usr.bin/xlint/lint1/emit.c:1.16
--- src/tests/usr.bin/xlint/lint1/emit.c:1.15	Tue Mar 28 14:44:34 2023
+++ src/tests/usr.bin/xlint/lint1/emit.c	Mon May 22 11:51:46 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: emit.c,v 1.15 2023/03/28 14:44:34 rillig Exp $	*/
+/*	$NetBSD: emit.c,v 1.16 2023/05/22 11:51:46 rillig Exp $	*/
 # 3 "emit.c"
 
 /*
@@ -307,3 +307,12 @@ struct compound_expression_in_initialize
 		[0] = "zero",
 	},
 };
+
+/*
+ * FIXME: The type that ends up in the .ln file is 'A0cC', which is wrong as it
+ * has array size 0 instead of the correct 8.
+ *
+ * This is caused by cgram_declare being called before processing the
+ * initializer.
+ */
+const char array_of_unknown_size[] = "unknown";

Index: src/tests/usr.bin/xlint/lint1/emit.exp-ln
diff -u src/tests/usr.bin/xlint/lint1/emit.exp-ln:1.10 src/tests/usr.bin/xlint/lint1/emit.exp-ln:1.11
--- src/tests/usr.bin/xlint/lint1/emit.exp-ln:1.10	Sat Jan 15 14:22:03 2022
+++ src/tests/usr.bin/xlint/lint1/emit.exp-ln	Mon May 22 11:51:46 2023
@@ -82,3 +82,4 @@ Semit.c
 289u0.289x16defined_used_var
 286d0.286d8use_varsF0V
 305d0.305d8compoundsT134compound_expression_in_initializer
+318d0.318d21array_of_unknown_sizeA0cC



CVS commit: src

2023-05-22 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Mon May 22 10:28:59 UTC 2023

Modified Files:
src/tests/usr.bin/indent: opt_sob.c
src/usr.bin/indent: debug.c indent.c indent.h io.c

Log Message:
indent: implement suppressing optional blank lines


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/tests/usr.bin/indent/opt_sob.c
cvs rdiff -u -r1.19 -r1.20 src/usr.bin/indent/debug.c
cvs rdiff -u -r1.302 -r1.303 src/usr.bin/indent/indent.c
cvs rdiff -u -r1.156 -r1.157 src/usr.bin/indent/indent.h
cvs rdiff -u -r1.184 -r1.185 src/usr.bin/indent/io.c

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



CVS commit: src

2023-05-22 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Mon May 22 10:28:59 UTC 2023

Modified Files:
src/tests/usr.bin/indent: opt_sob.c
src/usr.bin/indent: debug.c indent.c indent.h io.c

Log Message:
indent: implement suppressing optional blank lines


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/tests/usr.bin/indent/opt_sob.c
cvs rdiff -u -r1.19 -r1.20 src/usr.bin/indent/debug.c
cvs rdiff -u -r1.302 -r1.303 src/usr.bin/indent/indent.c
cvs rdiff -u -r1.156 -r1.157 src/usr.bin/indent/indent.h
cvs rdiff -u -r1.184 -r1.185 src/usr.bin/indent/io.c

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

Modified files:

Index: src/tests/usr.bin/indent/opt_sob.c
diff -u src/tests/usr.bin/indent/opt_sob.c:1.6 src/tests/usr.bin/indent/opt_sob.c:1.7
--- src/tests/usr.bin/indent/opt_sob.c:1.6	Thu May 11 09:28:53 2023
+++ src/tests/usr.bin/indent/opt_sob.c	Mon May 22 10:28:59 2023
@@ -1,4 +1,4 @@
-/* $NetBSD: opt_sob.c,v 1.6 2023/05/11 09:28:53 rillig Exp $ */
+/* $NetBSD: opt_sob.c,v 1.7 2023/05/22 10:28:59 rillig Exp $ */
 
 /*
  * Tests for the options '-sob' and '-nsob'.
@@ -62,7 +62,7 @@ function_with_2_blank_lines(void)
 /* $ The following 2 lines are "optional" and are removed due to '-sob'. */
 
 
-	var--;
+		var--;
 
 
 	return var;
@@ -94,7 +94,6 @@ function_with_1_blank_line(void)
 	var = value;
 
 	if (var > 0)
-
 		var--;
 
 	return var;
@@ -106,23 +105,16 @@ int
 function_with_2_blank_lines(void)
 {
 
-
 	int		var;
 
-
 	var = value;
 
-
 	if (var > 0)
-
-
 		var--;
 
-
 	return var;
 
-
 }
 //indent end
 
-//indent run-equals-prev-output -nsob
+//indent run-equals-input -nsob

Index: src/usr.bin/indent/debug.c
diff -u src/usr.bin/indent/debug.c:1.19 src/usr.bin/indent/debug.c:1.20
--- src/usr.bin/indent/debug.c:1.19	Sat May 20 11:53:53 2023
+++ src/usr.bin/indent/debug.c	Mon May 22 10:28:59 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: debug.c,v 1.19 2023/05/20 11:53:53 rillig Exp $	*/
+/*	$NetBSD: debug.c,v 1.20 2023/05/22 10:28:59 rillig Exp $	*/
 
 /*-
  * Copyright (c) 2023 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: debug.c,v 1.19 2023/05/20 11:53:53 rillig Exp $");
+__RCSID("$NetBSD: debug.c,v 1.20 2023/05/22 10:28:59 rillig Exp $");
 
 #include 
 
@@ -119,8 +119,10 @@ const char *const paren_level_cast_name[
 
 const char *const line_kind_name[] = {
 	"other",
+	"blank",
 	"#if",
 	"#endif",
+	"stmt head",
 	"}",
 	"block comment",
 };

Index: src/usr.bin/indent/indent.c
diff -u src/usr.bin/indent/indent.c:1.302 src/usr.bin/indent/indent.c:1.303
--- src/usr.bin/indent/indent.c:1.302	Sun May 21 10:05:20 2023
+++ src/usr.bin/indent/indent.c	Mon May 22 10:28:59 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: indent.c,v 1.302 2023/05/21 10:05:20 rillig Exp $	*/
+/*	$NetBSD: indent.c,v 1.303 2023/05/22 10:28:59 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -38,7 +38,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: indent.c,v 1.302 2023/05/21 10:05:20 rillig Exp $");
+__RCSID("$NetBSD: indent.c,v 1.303 2023/05/22 10:28:59 rillig Exp $");
 
 #include 
 #include 
@@ -515,6 +515,7 @@ unbalanced:
 		parse(ps.spaced_expr_psym);
 		ps.spaced_expr_psym = psym_0;
 		ps.want_blank = true;
+		out.line_kind = lk_stmt_head;
 	}
 }
 

Index: src/usr.bin/indent/indent.h
diff -u src/usr.bin/indent/indent.h:1.156 src/usr.bin/indent/indent.h:1.157
--- src/usr.bin/indent/indent.h:1.156	Sat May 20 11:53:53 2023
+++ src/usr.bin/indent/indent.h	Mon May 22 10:28:59 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: indent.h,v 1.156 2023/05/20 11:53:53 rillig Exp $	*/
+/*	$NetBSD: indent.h,v 1.157 2023/05/22 10:28:59 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
@@ -407,14 +407,20 @@ extern struct parser_state {
 extern struct output_state {
 	enum line_kind {
 		lk_other,
+		lk_blank,
 		lk_if,		/* #if, #ifdef, #ifndef */
 		lk_endif,	/* #endif */
+		lk_stmt_head,	/* the ')' of an incomplete statement such as
+ * 'if (expr)' or 'for (expr; expr; expr)' */
 		lk_func_end,	/* the last '}' of a function body */
 		lk_block_comment,
-	} line_kind;		/* kind of the current output line, is reset to
- * lk_other at the beginning of each output
- * line; used for inserting blank lines */
-	enum line_kind prev_line_kind;
+	} line_kind;		/* kind of the line that is being prepared for
+ * output; is reset to lk_other each time after
+ * trying to send a line to the output, even if
+ * that line was a suppressed blank line; used
+ * for inserting or removing blank lines */
+	enum line_kind prev_line_kind;	/* the kind of line that was actually
+	 * sent to the output */
 
 	struct buffer indent_off_text;	/* text from between 'INDENT OFF' and
 	 * 'INDENT ON', both inclusive */

Index: src/usr.bin/indent/io.c
diff -u src/usr.bin/indent/io.c:1.184 src/usr.bin/indent/io.c:1.185
--- src/usr.bin/indent/io.c:1.184	Sat May 20 12:05:01 2023
+++ src/usr.bin/indent/io.c	Mon