Re: drivers/iommu/io-pgtable-arm.c:330:13: error: void value not ignored as it ought to be

From: Mark Rutland
Date: Mon Jul 08 2024 - 07:42:59 EST


On Sun, Jul 07, 2024 at 07:58:28AM +0800, kernel test robot wrote:
> Hi Mark,
>
> FYI, the error/warning was bisected to this commit, please ignore it if it's irrelevant.
>
> tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
> head: 22f902dfc51eb3602ff9b505ac3980f6ff77b1df
> commit: 9257959a6e5b4fca6fc8e985790bff62c2046f20 locking/atomic: scripts: restructure fallback ifdeffery
> date: 1 year, 1 month ago
> config: arc-allmodconfig (https://download.01.org/0day-ci/archive/20240707/202407070708.Bm6Ker3L-lkp@xxxxxxxxx/config)
> compiler: arceb-elf-gcc (GCC) 13.2.0
> reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240707/202407070708.Bm6Ker3L-lkp@xxxxxxxxx/reproduce)
>
> If you fix the issue in a separate patch/commit (i.e. not just a new version of
> the same patch/commit), kindly add following tags
> | Reported-by: kernel test robot <lkp@xxxxxxxxx>
> | Closes: https://lore.kernel.org/oe-kbuild-all/202407070708.Bm6Ker3L-lkp@xxxxxxxxx/
>
> All errors (new ones prefixed by >>):
>
> drivers/iommu/io-pgtable-arm.c: In function 'arm_lpae_install_table':
> >> drivers/iommu/io-pgtable-arm.c:330:13: error: void value not ignored as it ought to be
> 330 | old = cmpxchg64_relaxed(ptep, curr, new);
> | ^
> --
> drivers/iommu/io-pgtable-dart.c: In function 'dart_install_table':
> >> drivers/iommu/io-pgtable-dart.c:168:13: error: void value not ignored as it ought to be
> 168 | old = cmpxchg64_relaxed(ptep, curr, new);
> | ^
> drivers/iommu/io-pgtable-dart.c:157:25: warning: variable 'new' set but not used [-Wunused-but-set-variable]
> 157 | dart_iopte old, new;
> | ^~~

The warning here is due to an extant bug for which the error message has
changed, see the example logs below.

The issue here is that the drivers/iommu/io-pgtable-* code wants cmpxchg64(),
but arch/arc doesn't provide arch_cmpxchg64() in some configurations. The
drivers/iommu/Kconfig file tries to detect this based on
CONFIG_GENERIC_ATOMIC64, but that doesn't actually describe whether cmpxchg64()
exists, and AFAICT we have no config symbol that does describe that.

Immediately before this patch, we'd still see a build error:

| [mark@lakrids:~/src/linux]% git describe HEAD
| v6.4-rc2-33-g1815da1718aa4
| [mark@lakrids:~/src/linux]% git clean -qfdx
| [mark@lakrids:~/src/linux]% usekorg 13.2.0 make ARCH=arc CROSS_COMPILE=arc-linux- -s allmodconfig
| [mark@lakrids:~/src/linux]% usekorg 13.2.0 make ARCH=arc CROSS_COMPILE=arc-linux- -s drivers/iommu/io-pgtable-arm.o
| In file included from ./include/linux/atomic.h:80,
| from drivers/iommu/io-pgtable-arm.c:12:
| drivers/iommu/io-pgtable-arm.c: In function 'arm_lpae_install_table':
| ./include/linux/atomic/atomic-arch-fallback.h:60:32: error: implicit declaration of function 'arch_cmpxchg64'; did you mean 'arch_cmpxchg'? [-Werror=implicit-function-declaration]
| 60 | #define arch_cmpxchg64_relaxed arch_cmpxchg64
| | ^~~~~~~~~~~~~~
| ./include/linux/atomic/atomic-raw.h:1063:9: note: in expansion of macro 'arch_cmpxchg64_relaxed'
| 1063 | arch_cmpxchg64_relaxed(__VA_ARGS__)
| | ^~~~~~~~~~~~~~~~~~~~~~
| ./include/linux/atomic/atomic-instrumented.h:2029:9: note: in expansion of macro 'raw_cmpxchg64_relaxed'
| 2029 | raw_cmpxchg64_relaxed(__ai_ptr, __VA_ARGS__); \
| | ^~~~~~~~~~~~~~~~~~~~~
| drivers/iommu/io-pgtable-arm.c:330:15: note: in expansion of macro 'cmpxchg64_relaxed'
| 330 | old = cmpxchg64_relaxed(ptep, curr, new);
| | ^~~~~~~~~~~~~~~~~
| cc1: all warnings being treated as errors
| make[3]: *** [scripts/Makefile.build:252: drivers/iommu/io-pgtable-arm.o] Error 1
| make[2]: *** [scripts/Makefile.build:494: drivers/iommu] Error 2
| make[1]: *** [scripts/Makefile.build:494: drivers] Error 2
| make: *** [Makefile:2026: .] Error 2

... which is the same as before the series which added this patch:

| [mark@lakrids:~/src/linux]% git describe HEAD
| v6.4-rc2
| [mark@lakrids:~/src/linux]% git clean -qfdx
| [mark@lakrids:~/src/linux]% usekorg 13.2.0 make ARCH=arc CROSS_COMPILE=arc-linux- -s allmodconfig
| [mark@lakrids:~/src/linux]% usekorg 13.2.0 make ARCH=arc CROSS_COMPILE=arc-linux- -s drivers/iommu/io-pgtable-arm.o
| In file included from ./include/linux/atomic.h:80,
| from drivers/iommu/io-pgtable-arm.c:12:
| drivers/iommu/io-pgtable-arm.c: In function 'arm_lpae_install_table':
| ./include/linux/atomic/atomic-arch-fallback.h:60:32: error: implicit declaration of function 'arch_cmpxchg64'; did you mean 'arch_cmpxchg'? [-Werror=implicit-function-declaration]
| 60 | #define arch_cmpxchg64_relaxed arch_cmpxchg64
| | ^~~~~~~~~~~~~~
| ./include/linux/atomic/atomic-instrumented.h:2034:9: note: in expansion of macro 'arch_cmpxchg64_relaxed'
| 2034 | arch_cmpxchg64_relaxed(__ai_ptr, __VA_ARGS__); \
| | ^~~~~~~~~~~~~~~~~~~~~~
| drivers/iommu/io-pgtable-arm.c:330:15: note: in expansion of macro 'cmpxchg64_relaxed'
| 330 | old = cmpxchg64_relaxed(ptep, curr, new);
| | ^~~~~~~~~~~~~~~~~
| cc1: all warnings being treated as errors
| make[3]: *** [scripts/Makefile.build:252: drivers/iommu/io-pgtable-arm.o] Error 1
| make[2]: *** [scripts/Makefile.build:494: drivers/iommu] Error 2
| make[1]: *** [scripts/Makefile.build:494: drivers] Error 2
| make: *** [Makefile:2026: .] Error 2

We could probably make the error message a bit nicer in future, but I
don't think this is a bug in the commit in question, and regardless we
should figure out a way to detect the presence/absence of cmpxchg64().

Since GCC errors out on the return type first, we'd need something like
the below to get a nice error message.

Mark.

---->8----
diff --git a/scripts/atomic/gen-atomic-fallback.sh b/scripts/atomic/gen-atomic-fallback.sh
index 86aca4f9f315a..3dd8844b9af53 100755
--- a/scripts/atomic/gen-atomic-fallback.sh
+++ b/scripts/atomic/gen-atomic-fallback.sh
@@ -193,8 +193,8 @@ gen_xchg_order_fallback()
fi

printf "#else\n"
- printf "extern void raw_${xchg}${order}_not_implemented(void);\n"
- printf "#define raw_${xchg}${order}(...) raw_${xchg}${order}_not_implemented()\n"
+ printf "#define raw_${xchg}${order}(ptr, ...) \\\\\n"
+ printf " ({ BUILD_BUG_ON_MSG(1, \"raw_${xchg}${order}() not implemented\"); (typeof(*(ptr)))0UL; })\n"
printf "#endif\n\n"
}