git: d14c38ceb8aa - main - sys: Avoid relying on pollution from refcount.h

From: Mark Johnston <markj_at_FreeBSD.org>
Date: Tue, 05 Nov 2024 18:24:42 UTC
The branch main has been updated by markj:

URL: https://cgit.FreeBSD.org/src/commit/?id=d14c38ceb8aa10bd94913d0456ec0f726693379b

commit d14c38ceb8aa10bd94913d0456ec0f726693379b
Author:     Mark Johnston <markj@FreeBSD.org>
AuthorDate: 2024-11-05 14:31:50 +0000
Commit:     Mark Johnston <markj@FreeBSD.org>
CommitDate: 2024-11-05 18:22:20 +0000

    sys: Avoid relying on pollution from refcount.h
    
    Fix up headers which previously assumed that refcount.h includes
    systm.h, and make them more self-contained.  Then, replace the systm.h
    include in refcount with kassert.h.
    
    Reviewed by:    imp, kib
    MFC after:      1 week
    Differential Revision:  https://reviews.freebsd.org/D47450
---
 sys/powerpc/include/counter.h          |  2 ++
 sys/sys/_lock.h                        |  4 ++--
 sys/sys/_mutex.h                       |  6 ++++--
 sys/sys/_rmlock.h                      | 10 ++++++++--
 sys/sys/_rwlock.h                      |  6 ++++--
 sys/sys/_sx.h                          |  5 ++++-
 sys/sys/file.h                         |  7 +++++--
 sys/sys/ktls.h                         |  3 +++
 sys/sys/refcount.h                     |  7 ++++---
 sys/sys/sglist.h                       |  1 +
 tools/build/test-includes/badfiles.inc |  1 -
 11 files changed, 37 insertions(+), 15 deletions(-)

diff --git a/sys/powerpc/include/counter.h b/sys/powerpc/include/counter.h
index 68e292cde7f6..90e6400ad562 100644
--- a/sys/powerpc/include/counter.h
+++ b/sys/powerpc/include/counter.h
@@ -100,6 +100,8 @@ counter_u64_add(counter_u64_t c, int64_t inc)
 
 #else	/* !64bit */
 
+#include <sys/systm.h>
+
 #define	counter_enter()	critical_enter()
 #define	counter_exit()	critical_exit()
 
diff --git a/sys/sys/_lock.h b/sys/sys/_lock.h
index ef167b9ab5ec..7057463fbde2 100644
--- a/sys/sys/_lock.h
+++ b/sys/sys/_lock.h
@@ -33,8 +33,8 @@
 
 struct lock_object {
 	const	char *lo_name;		/* Individual lock name. */
-	u_int	lo_flags;
-	u_int	lo_data;		/* General class specific data. */
+	unsigned int lo_flags;
+	unsigned int lo_data;		/* General class specific data. */
 	struct	witness *lo_witness;	/* Data for witness. */
 };
 
diff --git a/sys/sys/_mutex.h b/sys/sys/_mutex.h
index 0fcd5a2c2809..7241f9f1d31c 100644
--- a/sys/sys/_mutex.h
+++ b/sys/sys/_mutex.h
@@ -31,6 +31,8 @@
 #ifndef _SYS__MUTEX_H_
 #define	_SYS__MUTEX_H_
 
+#include <sys/_types.h>
+#include <sys/_lock.h>
 #include <machine/param.h>
 
 /*
@@ -44,7 +46,7 @@
  */
 struct mtx {
 	struct lock_object	lock_object;	/* Common lock properties. */
-	volatile uintptr_t	mtx_lock;	/* Owner and flags. */
+	volatile __uintptr_t	mtx_lock;	/* Owner and flags. */
 };
 
 /*
@@ -58,7 +60,7 @@ struct mtx {
  */
 struct mtx_padalign {
 	struct lock_object	lock_object;	/* Common lock properties. */
-	volatile uintptr_t	mtx_lock;	/* Owner and flags. */
+	volatile __uintptr_t	mtx_lock;	/* Owner and flags. */
 } __aligned(CACHE_LINE_SIZE);
 
 #endif /* !_SYS__MUTEX_H_ */
diff --git a/sys/sys/_rmlock.h b/sys/sys/_rmlock.h
index 38375b623a65..9c8893efe19c 100644
--- a/sys/sys/_rmlock.h
+++ b/sys/sys/_rmlock.h
@@ -32,6 +32,14 @@
 #ifndef _SYS__RMLOCK_H_
 #define	_SYS__RMLOCK_H_
 
+#include <sys/_cpuset.h>
+#include <sys/_lock.h>
+#include <sys/_mutex.h>
+#include <sys/queue.h>
+#include <sys/_sx.h>
+
+struct thread;
+
 /*
  * Mostly reader/occasional writer lock.
  */
@@ -66,8 +74,6 @@ struct rm_priotracker {
 	LIST_ENTRY(rm_priotracker) rmp_qentry;
 };
 
-#include <sys/_mutex.h>
-
 struct rmslock_pcpu;
 
 struct rmslock {
diff --git a/sys/sys/_rwlock.h b/sys/sys/_rwlock.h
index d360cfe2a4e9..8c15771cb172 100644
--- a/sys/sys/_rwlock.h
+++ b/sys/sys/_rwlock.h
@@ -28,6 +28,8 @@
 #ifndef _SYS__RWLOCK_H_
 #define	_SYS__RWLOCK_H_
 
+#include <sys/_types.h>
+#include <sys/_lock.h>
 #include <machine/param.h>
 
 /*
@@ -41,7 +43,7 @@
  */
 struct rwlock {
 	struct lock_object	lock_object;
-	volatile uintptr_t	rw_lock;
+	volatile __uintptr_t	rw_lock;
 };
 
 /*
@@ -55,7 +57,7 @@ struct rwlock {
  */
 struct rwlock_padalign {
 	struct lock_object	lock_object;
-	volatile uintptr_t	rw_lock;
+	volatile __uintptr_t	rw_lock;
 } __aligned(CACHE_LINE_SIZE);
 
 #endif /* !_SYS__RWLOCK_H_ */
diff --git a/sys/sys/_sx.h b/sys/sys/_sx.h
index f70462c9a008..c6fd485620c6 100644
--- a/sys/sys/_sx.h
+++ b/sys/sys/_sx.h
@@ -31,12 +31,15 @@
 #ifndef	_SYS__SX_H_
 #define	_SYS__SX_H_
 
+#include <sys/_types.h>
+#include <sys/_lock.h>
+
 /*
  * Shared/exclusive lock main structure definition.
  */
 struct sx {
 	struct lock_object	lock_object;
-	volatile uintptr_t	sx_lock;
+	volatile __uintptr_t	sx_lock;
 };
 
 #endif	/* !_SYS__SX_H_ */
diff --git a/sys/sys/file.h b/sys/sys/file.h
index 820ad1015573..a2dc02e523d8 100644
--- a/sys/sys/file.h
+++ b/sys/sys/file.h
@@ -37,13 +37,16 @@
 #include <sys/fcntl.h>
 #include <sys/unistd.h>
 #else
-#include <sys/queue.h>
-#include <sys/refcount.h>
+#include <sys/errno.h>
 #include <sys/_lock.h>
 #include <sys/_mutex.h>
+#include <sys/_null.h>
+#include <sys/queue.h>
+#include <sys/refcount.h>
 #include <vm/vm.h>
 
 struct filedesc;
+struct proc;
 struct stat;
 struct thread;
 struct uio;
diff --git a/sys/sys/ktls.h b/sys/sys/ktls.h
index 9b3433f4b1fd..0e52d643fe3b 100644
--- a/sys/sys/ktls.h
+++ b/sys/sys/ktls.h
@@ -28,8 +28,11 @@
 #define	_SYS_KTLS_H_
 
 #ifdef _KERNEL
+#include <sys/_null.h>
 #include <sys/refcount.h>
 #include <sys/_task.h>
+
+#include <machine/param.h>
 #endif
 
 struct tls_record_layer {
diff --git a/sys/sys/refcount.h b/sys/sys/refcount.h
index 44588fe3c812..ae0ec44fd7a6 100644
--- a/sys/sys/refcount.h
+++ b/sys/sys/refcount.h
@@ -28,13 +28,14 @@
 #ifndef __SYS_REFCOUNT_H__
 #define __SYS_REFCOUNT_H__
 
-#include <machine/atomic.h>
-
-#include <sys/systm.h>
+#include <sys/types.h>
+#include <sys/kassert.h>
 #if !defined(_KERNEL) && !defined(_STANDALONE)
 #include <stdbool.h>
 #endif
 
+#include <machine/atomic.h>
+
 #define	REFCOUNT_SATURATED(val)		(((val) & (1U << 31)) != 0)
 #define	REFCOUNT_SATURATION_VALUE	(3U << 30)
 
diff --git a/sys/sys/sglist.h b/sys/sys/sglist.h
index 96f3c1cd5ffb..3bbada573772 100644
--- a/sys/sys/sglist.h
+++ b/sys/sys/sglist.h
@@ -55,6 +55,7 @@ struct sglist {
 
 struct bio;
 struct mbuf;
+struct thread;
 struct uio;
 
 static __inline void
diff --git a/tools/build/test-includes/badfiles.inc b/tools/build/test-includes/badfiles.inc
index eb0cd05cb39f..1d648819cd8c 100644
--- a/tools/build/test-includes/badfiles.inc
+++ b/tools/build/test-includes/badfiles.inc
@@ -100,7 +100,6 @@ BADHDRS= \
 	sys/prng.h \
 	sys/qmath.h \
 	sys/racct.h \
-	sys/refcount.h \
 	sys/resourcevar.h \
 	sys/rman.h \
 	sys/rmlock.h \