Skip to contentSkip to conversation

syscalls/signal06: loop being clobbered by syscall on clang

PATCH Superseded Edward Liaw via ltp 1 participant 2 messages Aug 19, 2022 – Aug 22, 2022

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 syscalls/signal06: loop being clobbered by syscall on clang

Indicate to the compiler that the syscall will modify registers rcx and r11 to prevent loop from getting clobbered.

---
When I combined the asm instruction into one line, it threw an error that the "Asm-specifier for input or output variable conflicts with asm clobber list" for rax. I omitted it for now, but I'm not sure if that is correct.

Also, is it ok to change the subject line like I did?

---
 testcases/kernel/syscalls/signal/signal06.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
testcases/kernel/syscalls/signal/signal06.c +1 -2
index 64f886ee3..fba380610 100644
@@ -72,8 +72,7 @@ void test(void)
 	while (D == VALUE && loop < LOOPS) {
 		/* sys_tkill(pid, SIGHUP); asm to avoid save/reload
 		 * fp regs around c call */
-		asm ("" : : "a"(__NR_tkill), "D"(pid), "S"(SIGHUP));
-		asm ("syscall" : : : "ax");
+		asm volatile ("syscall" : : "a"(__NR_tkill), "D"(pid), "S"(SIGHUP) : "rcx", "r11");
 
 		loop++;
 	}
Signature · 5 lines
2.37.2.609.g9ff673ca1a-goog


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#1 lore raw

Hello!

The syscall will get the return value in %rax I believe, so it may be wise to indicate that it gets modified no? I would assume something like

*int foo; *
asm volatile ("syscall" : *"=a" (foo)*: "a"(__NR_tkill), "D"(pid), "S"(SIGHUP) : "rcx", "r11");

would instruct the compiler to expect that %rax has been modified, and it can't rely on it staying the same. An optimization pass may otherwise take away the repeated setting of __NR_tkill in %rax.

/V

Quoted 40 lines · Edward Liaw' via kernel-team

Indicate to the compiler that the syscall will modify registers rcx and r11 to prevent loop from getting clobbered.

---
When I combined the asm instruction into one line, it threw an error that the "Asm-specifier for input or output variable conflicts with asm clobber list" for rax. I omitted it for now, but I'm not sure if that is correct.

Also, is it ok to change the subject line like I did?

---
 testcases/kernel/syscalls/signal/signal06.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
testcases/kernel/syscalls/signal/signal06.c +1 -2
index 64f886ee3..fba380610 100644
@@ -72,8 +72,7 @@ void test(void)
        while (D == VALUE && loop < LOOPS) {
                /* sys_tkill(pid, SIGHUP); asm to avoid save/reload
                 * fp regs around c call */
-               asm ("" : : "a"(__NR_tkill), "D"(pid), "S"(SIGHUP));
-               asm ("syscall" : : : "ax");
+               asm volatile ("syscall" : : "a"(__NR_tkill), "D"(pid),
 "S"(SIGHUP) : "rcx", "r11");
 
                loop++;
        }

--
2.37.2.609.g9ff673ca1a-goog

--
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].

Signature · 2 lines
-- 
Mailing list info: https://lists.linux.it/listinfo/ltp