Skip to contentSkip to conversation

clean-includes: improve exclude list, run on cxl, vfio, tests

PATCH Superseded Peter Maydell 6 participants 26 messages Nov 4, 2025 – Nov 17, 2025 Arm/Aspeed machine support

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover clean-includes: improve exclude list, run on cxl, vfio, tests

I realised that we haven't run clean-includes recently, and unsurprisingly various violations of our include policy have crept in to the tree. The exclude-list of files it shouldn't be run on has also grown rather out of date.

While looking at this I realised that one reason the exclude list is stale is that it's encoded in the script in a really awkward single long line extended regex. So the main thing this patch series does is fix that to instead use a list of regexes, one per line, with comments permitted.

The other useful new feature here is that you can now point the script at a directory (previously your only options were an explicit list of files, or '--all' to scan everything).

The other changes to the script itself are minor cleanups.

Finally, I have a couple of patches which are the result of running the script on some subdirectories. I do think that all the changes that the script now suggests are correct (it wants to make changes to 28 files other than these) but I wanted to get the script changes through review first, and then perhaps send those last changes a bit more broken up per-subsystem.

thanks
-- PMM

Peter Maydell (9):
scripts/clean-includes: Allow directories on command line scripts/clean-includes: Remove outdated comment scripts/clean-includes: Make ignore-regexes one per line scripts/clean-includes: Do all our exclusions with REGEXFILE scripts/clean-includes: Give the args in git commit messages scripts/clean-includes: Update exclude list
cxl: Clean up includes
vfio: Clean up includes
tests: Clean up includes

 hw/vfio-user/container.h             |  1 -
 hw/vfio-user/device.h                |  1 -
 hw/vfio/pci-quirks.h                 |  1 -
 tests/qtest/aspeed-hace-utils.h      |  1 -
 tests/qtest/aspeed-smc-utils.h       |  1 -
 hw/cxl/cxl-mailbox-utils.c           |  2 +-
 hw/mem/cxl_type3.c                   |  2 +-
 hw/vfio-user/container.c             |  2 +-
 hw/vfio-user/pci.c                   |  2 +-
 hw/vfio/ap.c                         |  1 -
 hw/vfio/container.c                  |  2 +-
 hw/vfio/cpr-legacy.c                 |  2 +-
 tests/qtest/aspeed_gpio-test.c       |  1 -
 tests/qtest/dbus-display-test.c      |  3 -
 tests/qtest/pnv-spi-seeprom-test.c   |  1 -
 tests/unit/test-cutils.c             |  2 +-
 tests/unit/test-error-report.c       |  1 -
 tests/unit/test-io-channel-command.c |  2 -
 scripts/clean-includes               | 88 ++++++++++++++++++----------
 19 files changed, 63 insertions(+), 53 deletions(-)
Signature · 1 line
2.43.0
#1 lore raw

PATCH 1/9 scripts/clean-includes: Allow directories on command line

Currently clean-includes supports two ways of specifying files to check:
* --all to run on everything
* specific files
There's no way to say "check everything in target/arm".

Add support for handling directory names, by always running the arguments through git ls-files.

---
 scripts/clean-includes | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
scripts/clean-includes +8 -4
index 25dbf16c021..07c0fd44e46 100755
@@ -14,7 +14,7 @@
 # the top-level directory.
 
 # Usage:
-#   clean-includes [--git subjectprefix] [--check-dup-head] file ...
+#   clean-includes [--git subjectprefix] [--check-dup-head] file-or-dir ...
 # or
 #   clean-includes [--git subjectprefix] [--check-dup-head] --all
 #
@@ -28,7 +28,8 @@
 #
 # Using --all will cause clean-includes to run on the whole source
 # tree (excluding certain directories which are known not to need
-# handling).
+# handling). This is equivalent to passing '.' as the directory to
+# scan.
 
 # This script requires Coccinelle to be installed.
 
@@ -86,11 +87,14 @@ if [ $# -eq 0 ]; then
     exit 1
 fi
 
+# --all means "scan everything starting from the current directory"
 if [ "$1" = "--all" ]; then
-    # We assume there are no files in the tree with spaces in their name
-    set -- $(git ls-files '*.[ch]' | grep -E -v "$XDIRREGEX")
+    set -- '.'
 fi
 
+# We assume there are no files in the tree with spaces in their name
+set -- $(git ls-files "$@" | grep '\.[ch]$' | grep -E -v "$XDIRREGEX")
+
 # Annoyingly coccinelle won't read a scriptfile unless its
 # name ends '.cocci', so write it out to a tempfile with the
 # right kind of name.
Signature · 1 line
2.43.0
Reviewed-by on v1 1/9
#2 lore raw

Re: [PATCH 1/9] scripts/clean-includes: Allow directories on command line

Quoted 5 lines · Peter Maydell

Currently clean-includes supports two ways of specifying files to check:
* --all to run on everything
* specific files
There's no way to say "check everything in target/arm".

Quoted 7 lines

Add support for handling directory names, by always running the arguments through git ls-files.

---
  scripts/clean-includes | 12 ++++++++----
  1 file changed, 8 insertions(+), 4 deletions(-)

r~

#3 lore raw

PATCH 2/9 scripts/clean-includes: Remove outdated comment

In reply to Peter Maydell

Remove an old comment suggesting a manual shell line to use to find files to run the script on. The script's exclude-list and its support for directory names make this irrelevant.

---
 scripts/clean-includes | 9 ---------
 1 file changed, 9 deletions(-)
scripts/clean-includes +0 -9
index 07c0fd44e46..568033ee9c1 100755
@@ -39,15 +39,6 @@
 # removed.
 # Other files (including C++ and ObjectiveC) can't be handled by this script.
 
-# The following one-liner may be handy for finding files to run this on.
-# However some caution is required regarding files that might be part
-# of the guest agent or standalone tests.
-
-# for i in $(git ls-tree --name-only HEAD) ; do test -f $i && \
-#   grep -E '^# *include' $i | head -1 | grep 'osdep.h' ; test $? != 0 && \
-#   echo $i ; done
-
-
 GIT=no
 DUPHEAD=no
 
Signature · 1 line
2.43.0
Reviewed-by on v1 2/9
#4 lore raw

Re: [PATCH 2/9] scripts/clean-includes: Remove outdated comment

Quoted 8 lines · Peter Maydell

Remove an old comment suggesting a manual shell line to use to find files to run the script on. The script's exclude-list and its support for directory names make this irrelevant.

---
  scripts/clean-includes | 9 ---------
  1 file changed, 9 deletions(-)

r~

#5 lore raw

PATCH 3/9 scripts/clean-includes: Make ignore-regexes one per line

In reply to Peter Maydell

Currently we have a single extended regular expression defining files that clean-includes should ignore. This is now very long and awkward to read and edit.

Switch to having a list of newline-separated EREs that we write to a file for grep's -f option, so we can express them more legibly in the shell script. We allow for comments in the regex list, which lets us document why we have put the exclusions in.

---
 scripts/clean-includes | 28 ++++++++++++++++++++++------
 1 file changed, 22 insertions(+), 6 deletions(-)
scripts/clean-includes +22 -6
index 568033ee9c1..5ab3b071967 100755
@@ -42,8 +42,6 @@
 GIT=no
 DUPHEAD=no
 
-# Extended regular expression defining files to ignore when using --all
-XDIRREGEX='^(tests/tcg|tests/multiboot|tests/fp|tests/plugin|tests/uefi-test-tools|pc-bios|subprojects|contrib/plugins|tools/ebpf|ebpf/rss.bpf.skeleton.h|linux-user/(mips64|x86_64)/(cpu_loop|signal).c)'
 
 while true
 do
@@ -83,15 +81,33 @@ if [ "$1" = "--all" ]; then
     set -- '.'
 fi
 
-# We assume there are no files in the tree with spaces in their name
-set -- $(git ls-files "$@" | grep '\.[ch]$' | grep -E -v "$XDIRREGEX")
-
 # Annoyingly coccinelle won't read a scriptfile unless its
 # name ends '.cocci', so write it out to a tempfile with the
 # right kind of name.
 COCCIFILE="$(mktemp --suffix=.cocci)"
+REGEXFILE="$(mktemp --suffix=.regex)"
 
-trap 'rm -f -- "$COCCIFILE"' INT TERM HUP EXIT
+trap 'rm -f -- "$COCCIFILE" "$REGEXFILE"' INT TERM HUP EXIT
+
+# List of extended regular expressions defining files to ignore
+# Comments starting with '#' are permitted
+grep -v '^#' >"$REGEXFILE" <<EOT
+# These tests are generally standalone binaries
+^tests/(tcg|multiboot|fp|plugin|uefi-test-tools)
+# BIOS sources and third-party subprojects don't follow our rules
+^pc-bios
+^subprojects
+# plugin binaries are standalone
+^contrib/plugins
+# the ebpf tool is standalone, and the skeleton header is autogenerated
+^tools/ebpf
+^ebpf/rss.bpf.skeleton.h
+# These files just include some other .c file and have no content themselves
+^linux-user/(mips64|x86_64)/(cpu_loop|signal).c
+EOT
+
+# We assume there are no files in the tree with spaces in their name
+set -- $(git ls-files "$@" | grep '\.[ch]$' | grep -E -v -f "$REGEXFILE")
 
 cat >"$COCCIFILE" <<EOT
 @@
Signature · 1 line
2.43.0
Reviewed-by on v1 3/9
#6 lore raw

Re: [PATCH 3/9] scripts/clean-includes: Make ignore-regexes one per line

Quoted 10 lines · Peter Maydell

Currently we have a single extended regular expression defining files that clean-includes should ignore. This is now very long and awkward to read and edit.

Switch to having a list of newline-separated EREs that we write to a file for grep's -f option, so we can express them more legibly in the shell script. We allow for comments in the regex list, which lets us document why we have put the exclusions in.

Quoted 4 lines
---
  scripts/clean-includes | 28 ++++++++++++++++++++++------
  1 file changed, 22 insertions(+), 6 deletions(-)

r~

#7 lore raw

PATCH 4/9 scripts/clean-includes: Do all our exclusions with REGEXFILE

In reply to Peter Maydell

We currently have two mechanisms for excluding files:
* the REGEXFILE which excludes by regex
* special cases in the "loop over each file" which make us skip the file

Roll all the "skip this" cases into REGEXFILE, so we use a single mechanism for identifying which files to exclude.

---
 scripts/clean-includes | 24 +++++++++---------------
 1 file changed, 9 insertions(+), 15 deletions(-)
scripts/clean-includes +9 -15
index 5ab3b071967..a45421d2ff7 100755
@@ -104,6 +104,15 @@ grep -v '^#' >"$REGEXFILE" <<EOT
 ^ebpf/rss.bpf.skeleton.h
 # These files just include some other .c file and have no content themselves
 ^linux-user/(mips64|x86_64)/(cpu_loop|signal).c
+# These are autogenerated headers
+^include/standard-headers/
+# osdep.h itself and its friends are expected to include system headers
+^include/qemu/osdep.h
+^include/qemu/compiler.h
+^include/glib-compat.h
+^include/system/os-(posix|win32).h
+# This is for use by plugins, which are standalone binaries
+^include/qemu/qemu-plugin.h
 EOT
 
 # We assume there are no files in the tree with spaces in their name
@@ -137,21 +146,6 @@ for f in "$@"; do
     *.c)
       MODE=c
       ;;
-    *include/qemu/osdep.h | \
-    *include/qemu/compiler.h | \
-    *include/qemu/qemu-plugin.h | \
-    *include/glib-compat.h | \
-    *include/system/os-posix.h | \
-    *include/system/os-win32.h | \
-    *include/standard-headers/ )
-      # Removing include lines from osdep.h itself would be counterproductive.
-      echo "SKIPPING $f (special case header)"
-      continue
-      ;;
-    *include/standard-headers/*)
-      echo "SKIPPING $f (autogenerated header)"
-      continue
-      ;;
     *.h)
       MODE=h
       ;;
Signature · 1 line
2.43.0
Reviewed-by on v1 4/9
#8 lore raw

Re: [PATCH 4/9] scripts/clean-includes: Do all our exclusions with REGEXFILE

Quoted 5 lines · Peter Maydell

We currently have two mechanisms for excluding files:
* the REGEXFILE which excludes by regex
* special cases in the "loop over each file" which make us skip the file

Quoted 7 lines

Roll all the "skip this" cases into REGEXFILE, so we use a single mechanism for identifying which files to exclude.

---
  scripts/clean-includes | 24 +++++++++---------------
  1 file changed, 9 insertions(+), 15 deletions(-)

r~

#9 lore raw

PATCH 5/9 scripts/clean-includes: Give the args in git commit messages

In reply to Peter Maydell

If clean-includes is creating a git commit for its changes, currently it says only "created with scripts/clean-includes". Add the command line arguments the user passed us, as useful extra information.

---
 scripts/clean-includes | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
scripts/clean-includes +5 -1
index a45421d2ff7..694e12f062c 100755
@@ -42,6 +42,9 @@
 GIT=no
 DUPHEAD=no
 
+# Save the original arguments in case we want to put them in
+# a git commit message
+ORIGARGS="$*"
 
 while true
 do
@@ -198,7 +201,8 @@ if [ "$GIT" = "yes" ]; then
     git commit --signoff -F - <<EOF
 $GITSUBJ: Clean up includes
 
-This commit was created with scripts/clean-includes.
+This commit was created with scripts/clean-includes:
+ ./scripts/clean-includes $ORIGARGS
 
 All .c should include qemu/osdep.h first.  The script performs three
 related cleanups:
Signature · 1 line
2.43.0
#10 lore raw

Re: [PATCH 5/9] scripts/clean-includes: Give the args in git commit messages

Quoted 25 lines · Peter Maydell

If clean-includes is creating a git commit for its changes, currently it says only "created with scripts/clean-includes". Add the command line arguments the user passed us, as useful extra information.

---
 scripts/clean-includes | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
scripts/clean-includes +3 -0
index a45421d2ff7..694e12f062c 100755
@@ -42,6 +42,9 @@
 GIT=no
 DUPHEAD=no
 
+# Save the original arguments in case we want to put them in
+# a git commit message
+ORIGARGS="$*"
 
 while true
 do

scripts/clean-includes if [ "$GIT" = "yes" ]; then · line 205

Quoted 6 lines
scripts/clean-includes +2 -1
@@ -198,7 +201,8 @@ if [ "$GIT" = "yes" ]; then
     git commit --signoff -F - <<EOF
 $GITSUBJ: Clean up includes
 
-This commit was created with scripts/clean-includes.
+This commit was created with scripts/clean-includes:
+ ./scripts/clean-includes $ORIGARGS

Consider

    $ ./scripts/clean-includes --git 'a b c' a b c
Quoted 3 lines
scripts/clean-includes +0 -0
 All .c should include qemu/osdep.h first.  The script performs three
 related cleanups:
#11 lore raw

Re: [PATCH 5/9] scripts/clean-includes: Give the args in git commit messages

Quoted 31 lines · Markus Armbruster
Quoted 28 lines · Peter Maydell

If clean-includes is creating a git commit for its changes, currently it says only "created with scripts/clean-includes". Add the command line arguments the user passed us, as useful extra information.

---
 scripts/clean-includes | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
scripts/clean-includes +3 -0
index a45421d2ff7..694e12f062c 100755
@@ -42,6 +42,9 @@
 GIT=no
 DUPHEAD=no
 
+# Save the original arguments in case we want to put them in
+# a git commit message
+ORIGARGS="$*"
 
 while true
 do
@@ -198,7 +201,8 @@ if [ "$GIT" = "yes" ]; then
     git commit --signoff -F - <<EOF
 $GITSUBJ: Clean up includes
 
Quoted 7 lines

scripts/clean-includes if [ "$GIT" = "yes" ]; then · line 205

Quoted 3 lines
scripts/clean-includes +2 -1
-This commit was created with scripts/clean-includes.
+This commit was created with scripts/clean-includes:
+ ./scripts/clean-includes $ORIGARGS

Consider

    $ ./scripts/clean-includes --git 'a b c' a b c

Yes. Do you have a way to deal with that that isn't more complex than justified by what we're doing here?

thanks
-- PMM

#12 lore raw

Re: [PATCH 5/9] scripts/clean-includes: Give the args in git commit messages

Quoted 38 lines · Peter Maydell
Quoted 37 lines · Markus Armbruster
Quoted 25 lines · Peter Maydell

If clean-includes is creating a git commit for its changes, currently it says only "created with scripts/clean-includes". Add the command line arguments the user passed us, as useful extra information.

---
 scripts/clean-includes | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
scripts/clean-includes +3 -0
index a45421d2ff7..694e12f062c 100755
@@ -42,6 +42,9 @@
 GIT=no
 DUPHEAD=no
 
+# Save the original arguments in case we want to put them in
+# a git commit message
+ORIGARGS="$*"
 
 while true
 do

scripts/clean-includes if [ "$GIT" = "yes" ]; then · line 205

Quoted 6 lines
scripts/clean-includes +2 -1
@@ -198,7 +201,8 @@ if [ "$GIT" = "yes" ]; then
     git commit --signoff -F - <<EOF
 $GITSUBJ: Clean up includes
 
-This commit was created with scripts/clean-includes.
+This commit was created with scripts/clean-includes:
+ ./scripts/clean-includes $ORIGARGS

Consider

Quoted 7 lines
Quoted 1 line
    $ ./scripts/clean-includes --git 'a b c' a b c

Yes. Do you have a way to deal with that that isn't more complex than justified by what we're doing here?

thanks
-- PMM

This doesn't feel too onerous:

    args=
    for i
    do args+=" '""$i""'"
    done

However, += is bash.

#13 lore raw

Re: [PATCH 5/9] scripts/clean-includes: Give the args in git commit messages

Quoted 48 lines · Markus Armbruster
Quoted 38 lines · Peter Maydell
Quoted 37 lines · Markus Armbruster
Quoted 25 lines · Peter Maydell

If clean-includes is creating a git commit for its changes, currently it says only "created with scripts/clean-includes". Add the command line arguments the user passed us, as useful extra information.

---
 scripts/clean-includes | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
scripts/clean-includes +3 -0
index a45421d2ff7..694e12f062c 100755
@@ -42,6 +42,9 @@
 GIT=no
 DUPHEAD=no
 
+# Save the original arguments in case we want to put them in
+# a git commit message
+ORIGARGS="$*"
 
 while true
 do

scripts/clean-includes if [ "$GIT" = "yes" ]; then · line 205

Quoted 6 lines
scripts/clean-includes +2 -1
@@ -198,7 +201,8 @@ if [ "$GIT" = "yes" ]; then
     git commit --signoff -F - <<EOF
 $GITSUBJ: Clean up includes
 
-This commit was created with scripts/clean-includes.
+This commit was created with scripts/clean-includes:
+ ./scripts/clean-includes $ORIGARGS

Consider

Quoted 7 lines
Quoted 1 line
    $ ./scripts/clean-includes --git 'a b c' a b c

Yes. Do you have a way to deal with that that isn't more complex than justified by what we're doing here?

thanks
-- PMM

Quoted 8 lines

This doesn't feel too onerous:

    args=
    for i
    do args+=" '""$i""'"
    done

However, += is bash.

Have a look at configure:

    printf "exec" >>config.status
    for i in "$0" "$@"; do
      test "$i" = --skip-meson || printf " %s" "$(quote_sh "$i")" >>config.status
    done

with shell function

    quote_sh() {
        printf "%s" "$1" | sed "s,','\\\\'',g; s,.*,'&',"
    }
#14 lore raw

PATCH 6/9 scripts/clean-includes: Update exclude list

In reply to Peter Maydell

Remove from the exclude list:
* tests/plugin, which is a non-existent directory. This was probably intended to exclude tests/tcg/plugins/, which is caught by the tests/tcg exclude pattern anyway
Add to the exclude list:
* rust/ -- the headers in here are purely for input to bindgen
* target/hexagon has some standalone tools used at build time
* linux-user/gen-vsdo.c -- another standalone tool
* linux-user/mips64/elfload.c just includes mips/elfload.c
* scripts/xen-detect.c is feature-detection code used by meson.build
* tests/tracetool/simple.c is autogenerated
* tests/unit/ has some "C file just includes another one" files
* include/system/os-wasm.h is like os-posix.h and os-win32.h and shouldn't be adjusted

---
 scripts/clean-includes | 19 +++++++++++++++++--
 1 file changed, 17 insertions(+), 2 deletions(-)
scripts/clean-includes +17 -2
index 694e12f062c..256ff5b5faa 100755
@@ -96,10 +96,12 @@ trap 'rm -f -- "$COCCIFILE" "$REGEXFILE"' INT TERM HUP EXIT
 # Comments starting with '#' are permitted
 grep -v '^#' >"$REGEXFILE" <<EOT
 # These tests are generally standalone binaries
-^tests/(tcg|multiboot|fp|plugin|uefi-test-tools)
+^tests/(tcg|multiboot|fp|uefi-test-tools|qtest/migration/s390x)
 # BIOS sources and third-party subprojects don't follow our rules
 ^pc-bios
 ^subprojects
+# headers under rust are only used for input to bindgen
+^rust
 # plugin binaries are standalone
 ^contrib/plugins
 # the ebpf tool is standalone, and the skeleton header is autogenerated
@@ -107,15 +109,28 @@ grep -v '^#' >"$REGEXFILE" <<EOT
 ^ebpf/rss.bpf.skeleton.h
 # These files just include some other .c file and have no content themselves
 ^linux-user/(mips64|x86_64)/(cpu_loop|signal).c
+^linux-user/mips64/elfload.c
 # These are autogenerated headers
 ^include/standard-headers/
 # osdep.h itself and its friends are expected to include system headers
 ^include/qemu/osdep.h
 ^include/qemu/compiler.h
 ^include/glib-compat.h
-^include/system/os-(posix|win32).h
+^include/system/os-(posix|win32|wasm).h
 # This is for use by plugins, which are standalone binaries
 ^include/qemu/qemu-plugin.h
+# standalone tools used in building the hexagon target code
+^target/hexagon/(idef-parser|gen_semantics.c|gen_dectree_import.c)
+# standalone tool
+^target/s390x/gen-features.c
+# gen-vdso is a standalone tool
+^linux-user/gen-vdso.c
+# feature-detection code used by meson.bulid
+^scripts/xen-detect.c
+# autogenerated by tracetool
+^tests/tracetool/simple.c
+# these just include another C file
+^tests/unit/test-rcu-(simpleq|slist|tailq).c
 EOT
 
 # We assume there are no files in the tree with spaces in their name
Signature · 1 line
2.43.0
Reviewed-by on v1 6/9
#15 lore raw

Re: [PATCH 6/9] scripts/clean-includes: Update exclude list

Quoted 15 lines · Peter Maydell

Remove from the exclude list:
* tests/plugin, which is a non-existent directory. This was probably intended to exclude tests/tcg/plugins/, which is caught by the tests/tcg exclude pattern anyway
Add to the exclude list:
* rust/ -- the headers in here are purely for input to bindgen
* target/hexagon has some standalone tools used at build time
* linux-user/gen-vsdo.c -- another standalone tool
* linux-user/mips64/elfload.c just includes mips/elfload.c
* scripts/xen-detect.c is feature-detection code used by meson.build
* tests/tracetool/simple.c is autogenerated
* tests/unit/ has some "C file just includes another one" files
* include/system/os-wasm.h is like os-posix.h and os-win32.h and shouldn't be adjusted

Quoted 4 lines
---
  scripts/clean-includes | 19 +++++++++++++++++--
  1 file changed, 17 insertions(+), 2 deletions(-)

r~

#16 lore raw

PATCH 7/9 cxl: Clean up includes

In reply to Peter Maydell

This commit was created with scripts/clean-includes:
./scripts/clean-includes --git cxl hw/cxl hw/mem

All .c should include qemu/osdep.h first. The script performs three related cleanups:

* Ensure .c files include qemu/osdep.h first.
* Including it in a .h is redundant, since the .c already includes it. Drop such inclusions.
* Likewise, including headers qemu/osdep.h includes is redundant. Drop these, too.

---
 hw/cxl/cxl-mailbox-utils.c | 2 +-
 hw/mem/cxl_type3.c         | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
hw/cxl/cxl-mailbox-utils.c +1 -1
index 68c7cc98912..6cfdd98168f 100644
@@ -7,9 +7,9 @@
  * COPYING file in the top-level directory.
  */
 
+#include "qemu/osdep.h"
 #include <math.h>
 
-#include "qemu/osdep.h"
 #include "hw/pci/msi.h"
 #include "hw/pci/msix.h"
 #include "hw/cxl/cxl.h"
hw/mem/cxl_type3.c +1 -1
index be609ff9d03..4f3688a71b6 100644
@@ -8,9 +8,9 @@
  *
  * SPDX-License-Identifier: GPL-v2-only
  */
+#include "qemu/osdep.h"
 #include <math.h>
 
-#include "qemu/osdep.h"
 #include "qemu/units.h"
 #include "qemu/error-report.h"
 #include "qapi/qapi-commands-cxl.h"
Signature · 1 line
2.43.0
Reviewed-by on v1 7/9
#17 lore raw

Re: [PATCH 7/9] cxl: Clean up includes

Quoted 12 lines · Peter Maydell

This commit was created with scripts/clean-includes:
./scripts/clean-includes --git cxl hw/cxl hw/mem

All .c should include qemu/osdep.h first. The script performs three related cleanups:

* Ensure .c files include qemu/osdep.h first.
* Including it in a .h is redundant, since the .c already includes it. Drop such inclusions.
* Likewise, including headers qemu/osdep.h includes is redundant. Drop these, too.

Quoted 5 lines
---
  hw/cxl/cxl-mailbox-utils.c | 2 +-
  hw/mem/cxl_type3.c         | 2 +-
  2 files changed, 2 insertions(+), 2 deletions(-)
Acked-by Jonathan Cameron on v1 7/9
#18 lore raw

Re: [PATCH 7/9] cxl: Clean up includes

In reply to Peter Maydell
Quoted 6 lines · On Tue, 4 Nov 2025 16:09:41 +0000 Peter Maydell <[email protected]>…

This commit was created with scripts/clean-includes:
./scripts/clean-includes --git cxl hw/cxl hw/mem

All .c should include qemu/osdep.h first. The script performs three related cleanups:

Quoted 7 lines

* Ensure .c files include qemu/osdep.h first.
* Including it in a .h is redundant, since the .c already includes it. Drop such inclusions.
* Likewise, including headers qemu/osdep.h includes is redundant. Drop these, too.

FWIW

Reviewed-by on v1 7/9
#19 lore raw

Re: [PATCH 7/9] cxl: Clean up includes

In reply to Peter Maydell
Quoted 12 lines · Peter Maydell

This commit was created with scripts/clean-includes:
./scripts/clean-includes --git cxl hw/cxl hw/mem

All .c should include qemu/osdep.h first. The script performs three related cleanups:

* Ensure .c files include qemu/osdep.h first.
* Including it in a .h is redundant, since the .c already includes it. Drop such inclusions.
* Likewise, including headers qemu/osdep.h includes is redundant. Drop these, too.

Quoted 5 lines
---
  hw/cxl/cxl-mailbox-utils.c | 2 +-
  hw/mem/cxl_type3.c         | 2 +-
  2 files changed, 2 insertions(+), 2 deletions(-)

r~

#20 lore raw

PATCH 8/9 vfio: Clean up includes

In reply to Peter Maydell

This commit was created with scripts/clean-includes:
./scripts/clean-includes --git vfio hw/vfio hw/vfio-user

All .c should include qemu/osdep.h first. The script performs three related cleanups:

* Ensure .c files include qemu/osdep.h first.
* Including it in a .h is redundant, since the .c already includes it. Drop such inclusions.
* Likewise, including headers qemu/osdep.h includes is redundant. Drop these, too.

---
 hw/vfio-user/container.h | 1 -
 hw/vfio-user/device.h    | 1 -
 hw/vfio/pci-quirks.h     | 1 -
 hw/vfio-user/container.c | 2 +-
 hw/vfio-user/pci.c       | 2 +-
 hw/vfio/ap.c             | 1 -
 hw/vfio/container.c      | 2 +-
 hw/vfio/cpr-legacy.c     | 2 +-
 8 files changed, 4 insertions(+), 8 deletions(-)
hw/vfio-user/container.h +0 -1
index a2b42e3169d..c952e090631 100644
@@ -7,7 +7,6 @@
 #ifndef HW_VFIO_USER_CONTAINER_H
 #define HW_VFIO_USER_CONTAINER_H
 
-#include "qemu/osdep.h"
 
 #include "hw/vfio/vfio-container.h"
 #include "hw/vfio-user/proxy.h"
hw/vfio-user/device.h +0 -1
index d183a3950e2..49c05848f1a 100644
@@ -9,7 +9,6 @@
  * SPDX-License-Identifier: GPL-2.0-or-later
  */
 
-#include "qemu/osdep.h"
 #include "linux/vfio.h"
 
 #include "hw/vfio-user/proxy.h"
hw/vfio/pci-quirks.h +0 -1
index d1532e379b1..a6282e063a1 100644
@@ -12,7 +12,6 @@
 #ifndef HW_VFIO_VFIO_PCI_QUIRKS_H
 #define HW_VFIO_VFIO_PCI_QUIRKS_H
 
-#include "qemu/osdep.h"
 #include "exec/memop.h"
 
 /*
hw/vfio-user/container.c +1 -1
index e45192fef65..dab7a23224c 100644
@@ -6,9 +6,9 @@
  * SPDX-License-Identifier: GPL-2.0-or-later
  */
 
+#include "qemu/osdep.h"
 #include <sys/ioctl.h>
 #include <linux/vfio.h>
-#include "qemu/osdep.h"
 
 #include "hw/vfio-user/container.h"
 #include "hw/vfio-user/device.h"
hw/vfio-user/pci.c +1 -1
index b53ed3b456f..353d07e7819 100644
@@ -6,8 +6,8 @@
  * SPDX-License-Identifier: GPL-2.0-or-later
  */
 
-#include <sys/ioctl.h>
 #include "qemu/osdep.h"
+#include <sys/ioctl.h>
 #include "qapi-visit-sockets.h"
 #include "qemu/error-report.h"
 
hw/vfio/ap.c +0 -1
index 7719f245797..3368ac89150 100644
@@ -10,7 +10,6 @@
  * directory.
  */
 
-#include <stdbool.h>
 #include "qemu/osdep.h"
 #include CONFIG_DEVICES /* CONFIG_IOMMUFD */
 #include <linux/vfio.h>
hw/vfio/container.c +1 -1
index 9ddec300e35..013a691bc5a 100644
@@ -10,10 +10,10 @@
  * SPDX-License-Identifier: GPL-2.0-or-later
  */
 
+#include "qemu/osdep.h"
 #include <sys/ioctl.h>
 #include <linux/vfio.h>
 
-#include "qemu/osdep.h"
 #include "system/tcg.h"
 #include "system/ram_addr.h"
 #include "qapi/error.h"
hw/vfio/cpr-legacy.c +1 -1
index 7184c939912..273b5978806 100644
@@ -4,9 +4,9 @@
  * SPDX-License-Identifier: GPL-2.0-or-later
  */
 
+#include "qemu/osdep.h"
 #include <sys/ioctl.h>
 #include <linux/vfio.h>
-#include "qemu/osdep.h"
 #include "hw/vfio/vfio-container-legacy.h"
 #include "hw/vfio/vfio-device.h"
 #include "hw/vfio/vfio-listener.h"
Signature · 1 line
2.43.0
Reviewed-by on v1 8/9
#21 lore raw

Re: [PATCH 8/9] vfio: Clean up includes

Quoted 13 lines · Peter Maydell

This commit was created with scripts/clean-includes:
./scripts/clean-includes --git vfio hw/vfio hw/vfio-user

All .c should include qemu/osdep.h first. The script performs three related cleanups:

* Ensure .c files include qemu/osdep.h first.
* Including it in a .h is redundant, since the .c already includes it. Drop such inclusions.
* Likewise, including headers qemu/osdep.h includes is redundant. Drop these, too.

Quoted 11 lines
---
  hw/vfio-user/container.h | 1 -
  hw/vfio-user/device.h    | 1 -
  hw/vfio/pci-quirks.h     | 1 -
  hw/vfio-user/container.c | 2 +-
  hw/vfio-user/pci.c       | 2 +-
  hw/vfio/ap.c             | 1 -
  hw/vfio/container.c      | 2 +-
  hw/vfio/cpr-legacy.c     | 2 +-
  8 files changed, 4 insertions(+), 8 deletions(-)

Thanks,

C.

Reviewed-by on v1 8/9
#22 lore raw

Re: [PATCH 8/9] vfio: Clean up includes

In reply to Peter Maydell
Quoted 13 lines · Peter Maydell

This commit was created with scripts/clean-includes:
./scripts/clean-includes --git vfio hw/vfio hw/vfio-user

All .c should include qemu/osdep.h first. The script performs three related cleanups:

* Ensure .c files include qemu/osdep.h first.
* Including it in a .h is redundant, since the .c already includes it. Drop such inclusions.
* Likewise, including headers qemu/osdep.h includes is redundant. Drop these, too.

Quoted 10 lines
---
  hw/vfio-user/container.h | 1 -
  hw/vfio-user/device.h    | 1 -
  hw/vfio/pci-quirks.h     | 1 -
  hw/vfio-user/container.c | 2 +-
  hw/vfio-user/pci.c       | 2 +-
  hw/vfio/ap.c             | 1 -
  hw/vfio/container.c      | 2 +-
  hw/vfio/cpr-legacy.c     | 2 +-
  8 files changed, 4 insertions(+), 8 deletions(-)
#23 lore raw

PATCH 9/9 tests: Clean up includes

In reply to Peter Maydell

This commit was created with scripts/clean-includes:
./scripts/clean-includes --git tests tests

with one hand-edit to remove a now-empty #ifndef WIN32...#endif from tests/qtest/dbus-display-test.c .

All .c should include qemu/osdep.h first. The script performs three related cleanups:

* Ensure .c files include qemu/osdep.h first.
* Including it in a .h is redundant, since the .c already includes it. Drop such inclusions.
* Likewise, including headers qemu/osdep.h includes is redundant. Drop these, too.

---
 tests/qtest/aspeed-hace-utils.h      | 1 -
 tests/qtest/aspeed-smc-utils.h       | 1 -
 tests/qtest/aspeed_gpio-test.c       | 1 -
 tests/qtest/dbus-display-test.c      | 3 ---
 tests/qtest/pnv-spi-seeprom-test.c   | 1 -
 tests/unit/test-cutils.c             | 2 +-
 tests/unit/test-error-report.c       | 1 -
 tests/unit/test-io-channel-command.c | 2 --
 8 files changed, 1 insertion(+), 11 deletions(-)
tests/qtest/aspeed-hace-utils.h +0 -1
index c8b2ec45af2..27ab2bb9758 100644
@@ -8,7 +8,6 @@
 #ifndef TESTS_ASPEED_HACE_UTILS_H
 #define TESTS_ASPEED_HACE_UTILS_H
 
-#include "qemu/osdep.h"
 #include "libqtest.h"
 #include "qemu/bitops.h"
 
tests/qtest/aspeed-smc-utils.h +0 -1
index b07870f3b8f..e2fd8ff1bd1 100644
@@ -26,7 +26,6 @@
 #ifndef TESTS_ASPEED_SMC_UTILS_H
 #define TESTS_ASPEED_SMC_UTILS_H
 
-#include "qemu/osdep.h"
 #include "qemu/bswap.h"
 #include "libqtest-single.h"
 #include "qemu/bitops.h"
tests/qtest/aspeed_gpio-test.c +0 -1
index c2f9ca2298a..decbba23c8f 100644
@@ -27,7 +27,6 @@
 #include "qemu/timer.h"
 #include "qobject/qdict.h"
 #include "libqtest-single.h"
-#include "qemu/typedefs.h"
 
 #define AST2600_GPIO_BASE 0x1E780000
 
tests/qtest/dbus-display-test.c +0 -3
index f7fc873bfb3..1d5951b7117 100644
@@ -7,9 +7,6 @@
 #include <gio/gio.h>
 #include <gio/gunixfdlist.h>
 #include "libqtest.h"
-#ifndef WIN32
-#include <sys/mman.h>
-#endif
 #include "ui/dbus-display1.h"
 
 static GDBusConnection*
tests/qtest/pnv-spi-seeprom-test.c +0 -1
index 600493c425d..8033261758b 100644
@@ -5,7 +5,6 @@
  *
  * SPDX-License-Identifier: GPL-2.0-or-later
  */
-#include <unistd.h>
 #include "qemu/osdep.h"
 #include "libqtest.h"
 #include "qemu/bswap.h"
tests/unit/test-cutils.c +1 -1
index 227acc59955..75fae29003a 100644
@@ -25,9 +25,9 @@
  * THE SOFTWARE.
  */
 
+#include "qemu/osdep.h"
 #include <math.h>
 
-#include "qemu/osdep.h"
 #include "qemu/cutils.h"
 #include "qemu/units.h"
 
tests/unit/test-error-report.c +0 -1
index 0cbde3c4cf5..a8532fc58fc 100644
@@ -8,7 +8,6 @@
  */
 
 #include "qemu/osdep.h"
-#include "glib-compat.h"
 #include <locale.h>
 
 #include "qemu/error-report.h"
tests/unit/test-io-channel-command.c +0 -2
index 4f022617df0..964418b5cd9 100644
@@ -20,8 +20,6 @@
 
 #include "qemu/osdep.h"
 #include <glib/gstdio.h>
-#include <sys/types.h>
-#include <sys/stat.h>
 #include "io/channel-command.h"
 #include "io-channel-helpers.h"
 #include "qapi/error.h"
Signature · 1 line
2.43.0
Reviewed-by on v1 9/9
#24 lore raw

Re: [PATCH 9/9] tests: Clean up includes

Quoted 16 lines · Peter Maydell

This commit was created with scripts/clean-includes:
./scripts/clean-includes --git tests tests

with one hand-edit to remove a now-empty #ifndef WIN32...#endif from tests/qtest/dbus-display-test.c .

All .c should include qemu/osdep.h first. The script performs three related cleanups:

* Ensure .c files include qemu/osdep.h first.
* Including it in a .h is redundant, since the .c already includes it. Drop such inclusions.
* Likewise, including headers qemu/osdep.h includes is redundant. Drop these, too.

Quoted 10 lines
---
  tests/qtest/aspeed-hace-utils.h      | 1 -
  tests/qtest/aspeed-smc-utils.h       | 1 -
  tests/qtest/aspeed_gpio-test.c       | 1 -
  tests/qtest/dbus-display-test.c      | 3 ---
  tests/qtest/pnv-spi-seeprom-test.c   | 1 -
  tests/unit/test-cutils.c             | 2 +-
  tests/unit/test-error-report.c       | 1 -
  tests/unit/test-io-channel-command.c | 2 --
  8 files changed, 1 insertion(+), 11 deletions(-)

Thanks,

C.

#25 lore raw
In reply to Peter Maydell
Quoted 28 lines · Peter Maydell

I realised that we haven't run clean-includes recently, and unsurprisingly various violations of our include policy have crept in to the tree. The exclude-list of files it shouldn't be run on has also grown rather out of date.

While looking at this I realised that one reason the exclude list is stale is that it's encoded in the script in a really awkward single long line extended regex. So the main thing this patch series does is fix that to instead use a list of regexes, one per line, with comments permitted.

The other useful new feature here is that you can now point the script at a directory (previously your only options were an explicit list of files, or '--all' to scan everything).

The other changes to the script itself are minor cleanups.

Finally, I have a couple of patches which are the result of running the script on some subdirectories. I do think that all the changes that the script now suggests are correct (it wants to make changes to 28 files other than these) but I wanted to get the script changes through review first, and then perhaps send those last changes a bit more broken up per-subsystem.

thanks
-- PMM

Quoted 10 lines

Peter Maydell (9):
scripts/clean-includes: Allow directories on command line scripts/clean-includes: Remove outdated comment scripts/clean-includes: Make ignore-regexes one per line scripts/clean-includes: Do all our exclusions with REGEXFILE scripts/clean-includes: Give the args in git commit messages scripts/clean-includes: Update exclude list
cxl: Clean up includes
vfio: Clean up includes
tests: Clean up includes

I've taken the "actually clean some include files" patches into target-arm.next, since those have been reviewed. Review of the actual script changes would still be appreciated.

thanks
-- PMM