Skip to contentSkip to conversation

asm-generic: current: Don't include thread-info.h if building asm

PATCH In review David Gow 3 participants 4 messages Jul 4, 2023 – Aug 19, 2023

Subsystems (4)
lore
Share & tools
lore

David Gow

author
#0 lore raw

PATCH 1/2 asm-generic: current: Don't include thread-info.h if building asm

asm/current.h is included by some assembly files (either directly, or indirectly). This works on some architectures (such as x86), as their implementation of current.h is careful to not include any C, but the asm-generic version includes linux/thread-info.h unconditionally, which leads to errors when either C code or non-asm-compatible preprocessor directives are included.

Just wrap the contents behind an #ifndef __ASSEMBLY__ to avoid any C code making its way in.

---

This is requrired for patch #2 here, as UML uses this asm-generic header, but works with x86 assembly files which are expecting the x86 current.h, which is assembly-friendly.

---
 include/asm-generic/current.h | 2 ++
 1 file changed, 2 insertions(+)
include/asm-generic/current.h +2 -0
index 3a2e224b9fa0..9c2aeecbd05a 100644
@@ -2,9 +2,11 @@
 #ifndef __ASM_GENERIC_CURRENT_H
 #define __ASM_GENERIC_CURRENT_H
 
+#ifndef __ASSEMBLY__
 #include <linux/thread_info.h>
 
 #define get_current() (current_thread_info()->task)
 #define current get_current()
+#endif
 
 #endif /* __ASM_GENERIC_CURRENT_H */
Signature · 1 line
2.41.0.255.g8b1d071c50-goog
author
#1 lore raw

PATCH 2/2 arch: um: Use the x86 checksum implementation on 32-bit

When UML is compiled under 32-bit x86, it uses its own copy of checksum_32.S, which is terribly out-of-date and doesn't support checksumming unaligned data.

This causes the new "checksum" KUnit test to fail:
./tools/testing/kunit/kunit.py run --kconfig_add CONFIG_64BIT=n --cross_compile i686-linux-gnu- checksum

    KTAP version 1
    # Subtest: checksum
    1..3
    # test_csum_fixed_random_inputs: ASSERTION FAILED at lib/checksum_kunit.c:243
    Expected result == expec, but
        result == 33316 (0x8224)
        expec == 33488 (0x82d0)
    not ok 1 test_csum_fixed_random_inputs
    # test_csum_all_carry_inputs: ASSERTION FAILED at lib/checksum_kunit.c:267
    Expected result == expec, but
        result == 65280 (0xff00)
        expec == 0 (0x0)
    not ok 2 test_csum_all_carry_inputs
    # test_csum_no_carry_inputs: ASSERTION FAILED at lib/checksum_kunit.c:306
    Expected result == expec, but
        result == 65531 (0xfffb)
        expec == 0 (0x0)
    not ok 3 test_csum_no_carry_inputs

Sharing the normal implementation in arch/x86/lib both fixes all of these issues and means any further fixes only need to be done once.

x86_64 already seems to share the same implementation between UML and "normal" x86.

---

Note that there is a further issue with the pre-pentium-pro codepath in the shared x86 code, which I'll send a separate fix out for. i686+ works fine with just this series.

---
 arch/x86/um/Makefile      |   3 +-
 arch/x86/um/checksum_32.S | 214 --------------------------------------
 2 files changed, 2 insertions(+), 215 deletions(-)
 delete mode 100644 arch/x86/um/checksum_32.S
arch/x86/um/Makefile +2 -1
index ee89f6bb9242..cb738967a9f5 100644
@@ -17,11 +17,12 @@ obj-y = bugs_$(BITS).o delay.o fault.o ldt.o \
 
 ifeq ($(CONFIG_X86_32),y)
 
-obj-y += checksum_32.o syscalls_32.o
+obj-y += syscalls_32.o
 obj-$(CONFIG_ELF_CORE) += elfcore.o
 
 subarch-y = ../lib/string_32.o ../lib/atomic64_32.o ../lib/atomic64_cx8_32.o
 subarch-y += ../lib/cmpxchg8b_emu.o ../lib/atomic64_386_32.o
+subarch-y += ../lib/checksum_32.o
 subarch-y += ../kernel/sys_ia32.o
 
 else
arch/x86/um/checksum_32.S deleted +0 -214

214 lines not on this page · raw message

Signature · 7 lines
2.41.0.255.g8b1d071c50-goog


_______________________________________________
linux-um mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-um
#2 lore raw
In reply to David Gow

----- Ursprüngliche Mail -----

Quoted 28 lines

Von: "davidgow" <[email protected]>
asm/current.h is included by some assembly files (either directly, or indirectly). This works on some architectures (such as x86), as their implementation of current.h is careful to not include any C, but the asm-generic version includes linux/thread-info.h unconditionally, which leads to errors when either C code or non-asm-compatible preprocessor directives are included.

Just wrap the contents behind an #ifndef __ASSEMBLY__ to avoid any C code making its way in.

---

This is requrired for patch #2 here, as UML uses this asm-generic header, but works with x86 assembly files which are expecting the x86 current.h, which is assembly-friendly.

---
include/asm-generic/current.h | 2 ++

1 file changed, 2 insertions(+)
include/asm-generic/current.h +0 -0
index 3a2e224b9fa0..9c2aeecbd05a 100644
@@ -2,9 +2,11 @@
 #ifndef __ASM_GENERIC_CURRENT_H

include/asm-generic/current.h line 12

Quoted 10 lines
include/asm-generic/current.h +2 -0
 #define __ASM_GENERIC_CURRENT_H
 
+#ifndef __ASSEMBLY__
 #include <linux/thread_info.h>
 
 #define get_current() (current_thread_info()->task)
 #define current get_current()
+#endif
 
 #endif /* __ASM_GENERIC_CURRENT_H */

I'm fine with the UML side of this change but the generic part needs Arnd's ACK.

Thanks,
//richard

_______________________________________________
linux-um mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-um

maintainer Acked-by on v1 1/2
#3 lore raw
In reply to David Gow
Quoted 11 lines · David Gow

asm/current.h is included by some assembly files (either directly, or indirectly). This works on some architectures (such as x86), as their implementation of current.h is careful to not include any C, but the asm-generic version includes linux/thread-info.h unconditionally, which leads to errors when either C code or non-asm-compatible preprocessor directives are included.

Just wrap the contents behind an #ifndef __ASSEMBLY__ to avoid any C code making its way in.

_______________________________________________
linux-um mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-um