Skip to contentSkip to conversation

linux-user: correct argument number for sys_mremap and sys_splice

PATCH Applied Petar Jovanovic 5 participants 6 messages Jul 23, 2013 – Jul 28, 2013

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 linux-user: correct argument number for sys_mremap and sys_splice

From: Petar Jovanovic <[email protected]>

sys_mremap missed 5th argument (new_address), which caused examples that remap to a specific address to fail.
sys_splice missed 5th and 6th argument which caused different examples to fail.
This change has an effect on MIPS target only.

---
 linux-user/main.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
linux-user/main.c +2 -2
index 99c3b3f..1c20229 100644
@@ -1957,7 +1957,7 @@ static const uint8_t mips_syscall_args[] = {
 	MIPS_SYS(sys_sched_get_priority_min, 1)
 	MIPS_SYS(sys_sched_rr_get_interval, 2)	/* 4165 */
 	MIPS_SYS(sys_nanosleep,	2)
-	MIPS_SYS(sys_mremap	, 4)
+	MIPS_SYS(sys_mremap	, 5)
 	MIPS_SYS(sys_accept	, 3)
 	MIPS_SYS(sys_bind	, 3)
 	MIPS_SYS(sys_connect	, 3)	/* 4170 */
@@ -2094,7 +2094,7 @@ static const uint8_t mips_syscall_args[] = {
 	MIPS_SYS(sys_pselect6, 6)
 	MIPS_SYS(sys_ppoll, 5)
 	MIPS_SYS(sys_unshare, 1)
-	MIPS_SYS(sys_splice, 4)
+	MIPS_SYS(sys_splice, 6)
 	MIPS_SYS(sys_sync_file_range, 7) /* 4305 */
 	MIPS_SYS(sys_tee, 4)
 	MIPS_SYS(sys_vmsplice, 4)
Signature · 1 line
1.7.9.5
#1 lore raw
Quoted 7 lines · Petar Jovanovic

From: Petar Jovanovic <[email protected]>

sys_mremap missed 5th argument (new_address), which caused examples that remap to a specific address to fail.
sys_splice missed 5th and 6th argument which caused different examples to fail.
This change has an effect on MIPS target only.

While splice is obvious and appears to be correct, with mremap I'm not this sure. The last, 5th argument of mremap(), which is `void *new_address', is optional and may be either present or not. So, without understanding how the underlying tables/code works, I'm not really sure if the resulting change will work or not. On the other hand, sys_open is also declared as having 3 arguments while the 3rd one (mode) is also optional, so the patch appears to be correct there as well, so I was almost ready to apply it, until your last comment which states that the change has only effect on MIPS. Which is quite puzzling to me who, again, does not really know how the code works.

So either the patch isn't trivial enough, or maybe you can provide some more verbose explanation... ;)

Thanks,

/mjt

Reviewed-by
#2 lore raw
Quoted 11 lines · Michael Tokarev
Quoted 7 lines · Petar Jovanovic

From: Petar Jovanovic <[email protected]>

sys_mremap missed 5th argument (new_address), which caused examples that remap to a specific address to fail.
sys_splice missed 5th and 6th argument which caused different examples to fail.
This change has an effect on MIPS target only.

While splice is obvious and appears to be correct, with mremap I'm not this sure.

This table in QEMU corresponds to the table in the kernel in arch/mips/kernel/scall32-o32.S and should generally have the same numbers in it.

The fix to mremap corresponds to Linux kernel commit 7dbdf43c (from 2006); the fix to splice is 08d30879 (from 2008).

Quoted 2 lines

On the other hand, sys_open is also declared as having 3 arguments while the 3rd one (mode) is also optional,

Yes. All the number-of-arguments param does is cause the main.c code to fish the extra arguments out of the stack, since the MIPS 32 bit ABI doesn't have enough registers for all of them to be in registers. If the argument is optional and isn't used in this case, it means we've just copied garbage as the arg6/7/8 param to do_syscall(), which is exactly the same situation as if the guest ABI put all syscall args in registers.

Quoted 2 lines

until your last comment which states that the change has only effect on MIPS. Which is quite puzzling to me

It's trivially obvious that it only has effect on MIPS, because it's patching a piece of code which is inside an #ifdef TARGET_MIPS guard.

Petar: I think it would be a good idea if you checked the whole of our table against a recent kernel and made sure we're in sync for everything, rather than fixing things one at a time.

-- PMM

#3 lore raw

________________________________________
From: Peter Maydell [[email protected]]
Sent: Tuesday, July 23, 2013 7:33 PM
To: Michael Tokarev
Cc: Petar Jovanovic; [email protected]; [email protected]; [email protected]; Petar Jovanovic
Subject: Re: [Qemu-devel] [Qemu-trivial] [PATCH] linux-user: correct argument number for sys_mremap and sys_splice

Quoted 5 lines

Petar: I think it would be a good idea if you checked the whole of our table against a recent kernel and made sure we're in sync for everything, rather than fixing things one at a time.

I did, this is how I came up with these two system calls.

Here are all the differences:

Syscall Qemu Kernel

sys_acct            0    1
sys_epoll_wait      3    4
sys_fdatasync       0    1
sys_lookup_dcookie  3    4
sys_mremap          4    5
sys_quotactl        0    4
sys_sigaltstack     2    0
sys_splice          4    6
sys_waitid          4    5

So, we are not fully in sync, but the rest of it will not cause any problems. In the existing QEMU code in cpu_loop(CPUMIPSState *env) first four arguments are always passed, so for sys_acct, sys_epoll_wait, sys_fdatasync, sys_quotactl, sys_lookup_dcookie and sys_sigaltstack the differences do not matter.

For sys_splice and sys_mremap, the difference is important so I added this change and came up with test cases.

The last on the list is sys_waitid, the difference could be important yet it still is not, since the host part does not seem to make use of it.

Considering the turn-around times for code reviews and getting the changes in, I am guided by "If it ain't broke, don't fix it", otherwise I would change the other values for clarity and readability, I would also change tabs/spaces mix in the table mips_syscall_args, etc.

Regards,
Petar

#4 lore raw
In reply to Peter Maydell
Quoted 9 lines · Peter Maydell
Quoted 8 lines · Michael Tokarev
Quoted 7 lines · Petar Jovanovic

From: Petar Jovanovic <[email protected]>

sys_mremap missed 5th argument (new_address), which caused examples that remap to a specific address to fail.
sys_splice missed 5th and 6th argument which caused different examples to fail.
This change has an effect on MIPS target only.

Thanks, applied to the trivial patches queue.

/mjt

#5 lore raw
In reply to Petar Jovanovic
Quoted 27 lines · Petar Jovanovic

From: Petar Jovanovic <[email protected]>

sys_mremap missed 5th argument (new_address), which caused examples that remap to a specific address to fail.
sys_splice missed 5th and 6th argument which caused different examples to fail.
This change has an effect on MIPS target only.

---
 linux-user/main.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
linux-user/main.c +1 -1
index 99c3b3f..1c20229 100644
@@ -1957,7 +1957,7 @@ static const uint8_t mips_syscall_args[] = {
 	MIPS_SYS(sys_sched_get_priority_min, 1)
 	MIPS_SYS(sys_sched_rr_get_interval, 2)	/* 4165 */
 	MIPS_SYS(sys_nanosleep,	2)
-	MIPS_SYS(sys_mremap	, 4)
+	MIPS_SYS(sys_mremap	, 5)
 	MIPS_SYS(sys_accept	, 3)
 	MIPS_SYS(sys_bind	, 3)
 	MIPS_SYS(sys_connect	, 3)	/* 4170 */

linux-user/main.c static const uint8_t mips_syscall_args[] = { · line 2100

Quoted 8 lines
linux-user/main.c +1 -1
@@ -2094,7 +2094,7 @@ static const uint8_t mips_syscall_args[] = {
 	MIPS_SYS(sys_pselect6, 6)
 	MIPS_SYS(sys_ppoll, 5)
 	MIPS_SYS(sys_unshare, 1)
-	MIPS_SYS(sys_splice, 4)
+	MIPS_SYS(sys_splice, 6)
 	MIPS_SYS(sys_sync_file_range, 7) /* 4305 */
 	MIPS_SYS(sys_tee, 4)
 	MIPS_SYS(sys_vmsplice, 4)

Thanks, applied.

Signature · 2 lines
Aurelien Jarno                          GPG: 1024D/F1BCDB73
[email protected]                 http://www.aurel32.net