From: Laurent Vivier <laurent@vivier.eu>
To: Filip Bozuta <Filip.Bozuta@syrmia.com>, qemu-devel@nongnu.org
Subject: Re: [PATCH v2 2/2] linux-user: Add support for utimensat_time64() and semtimedop_time64()
Date: Thu, 27 Aug 2020 00:50:54 +0200 [thread overview]
Message-ID: <0640cf00-1b5c-c407-c86d-86c7459d2538@vivier.eu> (raw)
In-Reply-To: <fe09ba5a-b521-073b-6e85-3f4e9520be78@vivier.eu>
Le 26/08/2020 à 15:58, Laurent Vivier a écrit :
> Le 25/08/2020 à 16:23, Laurent Vivier a écrit :
>> Le 25/08/2020 à 09:18, Laurent Vivier a écrit :
>>> Le 25/08/2020 à 00:30, Filip Bozuta a écrit :
>>>> This patch introduces functionality for following time64 syscalls:
>>>>
>>>> *utimensat_time64()
>>>>
>>>> int utimensat(int dirfd, const char *pathname,
>>>> const struct timespec times[2], int flags);
>>>> -- change file timestamps with nanosecond precision --
>>>> man page: https://man7.org/linux/man-pages/man2/utimensat.2.html
>>>>
>>>> *semtimedop_time64()
>>>>
>>>> int semtimedop(int semid, struct sembuf *sops, size_t nsops,
>>>> const struct timespec *timeout);
>>>> -- System V semaphore operations --
>>>> man page: https://www.man7.org/linux/man-pages/man2/semtimedop.2.html
>>>>
>>>> Implementation notes:
>>>>
>>>> Syscall 'utimensat_time64()' is implemented in similar way as its
>>>> regular variants only difference being that time64 converting function
>>>> is used to convert values of 'struct timespec' between host and target
>>>> ('target_to_host_timespec64()').
>>>>
>>>> For syscall 'semtimedop_time64()' and additional argument is added
>>>> in function 'do_semtimedop()' through which the aproppriate 'struct timespec'
>>>> converting function is called (false for regular target_to_host_timespec()
>>>> and true for target_to_host_timespec64()). For 'do_ipc()' a
>>>> check was added as that additional argument: 'TARGET_ABI_BITS == 64'.
>>>>
>>>> Signed-off-by: Filip Bozuta <Filip.Bozuta@syrmia.com>
>>>> Reviewed-by: Laurent Vivier <laurent@vivier.eu>
>>>> ---
>>>> linux-user/syscall.c | 60 ++++++++++++++++++++++++++++++++++++--------
>>>> 1 file changed, 50 insertions(+), 10 deletions(-)
>>>>
>>>> diff --git a/linux-user/syscall.c b/linux-user/syscall.c
>>>> index fc6a6e32e4..4d460af744 100644
>>>> --- a/linux-user/syscall.c
>>>> +++ b/linux-user/syscall.c
>>>> @@ -1253,7 +1253,8 @@ static inline abi_long target_to_host_timespec(struct timespec *host_ts,
>>>> #endif
>>>>
>>>> #if defined(TARGET_NR_clock_settime64) || defined(TARGET_NR_futex_time64) || \
>>>> - defined(TARGET_NR_pselect6_time64) || defined(TARGET_NR_ppoll_time64)
>>>> + defined(TARGET_NR_pselect6_time64) || defined(TARGET_NR_ppoll_time64) || \
>>>> + defined(TARGET_NR_utimensat_time64) || defined(TARGET_NR_semtimedop_time64)
>>>> static inline abi_long target_to_host_timespec64(struct timespec *host_ts,
>>>> abi_ulong target_addr)
>>>> {
>>>> @@ -4117,7 +4118,7 @@ static inline abi_long target_to_host_sembuf(struct sembuf *host_sembuf,
>>>> }
>>>>
>>>> #if defined(TARGET_NR_ipc) || defined(TARGET_NR_semop) || \
>>>> - defined(TARGET_NR_semtimedop)
>>>> + defined(TARGET_NR_semtimedop) || defined(TARGET_NR_semtimedop_time64)
>>>>
>>>> /*
>>>> * This macro is required to handle the s390 variants, which passes the
>>>> @@ -4134,7 +4135,7 @@ static inline abi_long target_to_host_sembuf(struct sembuf *host_sembuf,
>>>> static inline abi_long do_semtimedop(int semid,
>>>> abi_long ptr,
>>>> unsigned nsops,
>>>> - abi_long timeout)
>>>> + abi_long timeout, bool time64)
>>>> {
>>>> struct sembuf sops[nsops];
>>>> struct timespec ts, *pts = NULL;
>>>> @@ -4142,8 +4143,14 @@ static inline abi_long do_semtimedop(int semid,
>>>>
>>>> if (timeout) {
>>>> pts = &ts;
>>>> - if (target_to_host_timespec(pts, timeout)) {
>>>> - return -TARGET_EFAULT;
>>>> + if (time64) {
>>>> + if (target_to_host_timespec64(pts, timeout)) {
>>>> + return -TARGET_EFAULT;
>>>> + }
>>>> + } else {
>>>> + if (target_to_host_timespec(pts, timeout)) {
>>>> + return -TARGET_EFAULT;
>>>> + }
>>>> }
>>>> }
>>>>
>>>> @@ -4657,7 +4664,7 @@ static abi_long do_ipc(CPUArchState *cpu_env,
>>>>
>>>> switch (call) {
>>>> case IPCOP_semop:
>>>> - ret = do_semtimedop(first, ptr, second, 0);
>>>> + ret = do_semtimedop(first, ptr, second, 0, false);
>>>> break;
>>>> case IPCOP_semtimedop:
>>>> /*
>>>> @@ -4667,9 +4674,9 @@ static abi_long do_ipc(CPUArchState *cpu_env,
>>>> * to a struct timespec where the generic variant uses fifth parameter.
>>>> */
>>>> #if defined(TARGET_S390X)
>>>> - ret = do_semtimedop(first, ptr, second, third);
>>>> + ret = do_semtimedop(first, ptr, second, third, TARGET_ABI_BITS == 64);
>>>> #else
>>>> - ret = do_semtimedop(first, ptr, second, fifth);
>>>> + ret = do_semtimedop(first, ptr, second, fifth, TARGET_ABI_BITS == 64);
>>>> #endif
>>>> break;
>>>>
>>>> @@ -9887,11 +9894,15 @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1,
>>>> #endif
>>>> #ifdef TARGET_NR_semop
>>>> case TARGET_NR_semop:
>>>> - return do_semtimedop(arg1, arg2, arg3, 0);
>>>> + return do_semtimedop(arg1, arg2, arg3, 0, false);
>>>> #endif
>>>> #ifdef TARGET_NR_semtimedop
>>>> case TARGET_NR_semtimedop:
>>>> - return do_semtimedop(arg1, arg2, arg3, arg4);
>>>> + return do_semtimedop(arg1, arg2, arg3, arg4, false);
>>>> +#endif
>>>> +#ifdef TARGET_NR_semtimedop_time64
>>>> + case TARGET_NR_semtimedop_time64:
>>>> + return do_semtimedop(arg1, arg2, arg3, arg4, true);
>>>> #endif
>>>> #ifdef TARGET_NR_semctl
>>>> case TARGET_NR_semctl:
>>>> @@ -11938,6 +11949,35 @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1,
>>>> }
>>>> return ret;
>>>> #endif
>>>> +#ifdef TARGET_NR_utimensat_time64
>>>> + case TARGET_NR_utimensat_time64:
>>>> + {
>>>> + struct timespec *tsp, ts[2];
>>>> + if (!arg3) {
>>>> + tsp = NULL;
>>>> + } else {
>>>> + if (target_to_host_timespec64(ts, arg3)) {
>>>> + return -TARGET_EFAULT;
>>>> + }
>>>> + if (target_to_host_timespec64(ts + 1, arg3 +
>>>> + sizeof(struct target__kernel_timespec))) {
>>>> + return -TARGET_EFAULT;
>>>> + }
>>>> + tsp = ts;
>>>> + }
>>>> + if (!arg2)
>>>> + ret = get_errno(sys_utimensat(arg1, NULL, tsp, arg4));
>>>> + else {
>>>> + p = lock_user_string(arg2);
>>>> + if (!p) {
>>>> + return -TARGET_EFAULT;
>>>> + }
>>>> + ret = get_errno(sys_utimensat(arg1, path(p), tsp, arg4));
>>>> + unlock_user(p, arg2, 0);
>>>> + }
>>>> + }
>>>> + return ret;
>>>> +#endif
>>>> #ifdef TARGET_NR_futex
>>>> case TARGET_NR_futex:
>>>> return do_futex(arg1, arg2, arg3, arg4, arg5, arg6);
>>>>
>>>
>>> Applied to my linux-user-for-5.2 branch.
>>
>> I have removed it from my queue because the "TARGET_NR_utimensat_time64"
>> part breaks something (at least with sh4/sid on x86_64):
>>
>> $ touch a
>> $ cp -p a b
>> /usr/bin/cp: preserving times for 'b': Invalid argument
>
> In fact, on sh4, he timespec64 conversion is broken for all syscalls.
> tv_sec is ok but tv_nsec is totally corrupted (as it would be only a
> 32bit value).
In kernel, in get_timespec64(), we have:
/* In 32-bit mode, this drops the padding */
ts->tv_nsec = kts.tv_nsec;
and ts is "struct timespec64" (kts is __kernel_timespec):
struct timespec64 {
time64_t tv_sec; /* seconds */
long tv_nsec; /* nanoseconds */
};
So I think we need something like:
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index c82b73e03234..5f53d5d65eb6 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -1253,6 +1253,8 @@ static inline abi_long
target_to_host_timespec64(struct timespec *host_ts,
}
__get_user(host_ts->tv_sec, &target_ts->tv_sec);
__get_user(host_ts->tv_nsec, &target_ts->tv_nsec);
+ /* in 32bit mode this drops the padding */
+ host_ts->tv_nsec = (abi_long)host_ts->tv_nsec;
unlock_user_struct(target_ts, target_addr, 0);
return 0;
}
Thanks,
Laurent
prev parent reply other threads:[~2020-08-26 22:51 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-08-24 22:30 [PATCH v2 0/2] linux-user: Adding support for a group of 4 time64 syscalls Filip Bozuta
2020-08-24 22:30 ` [PATCH v2 1/2] linux-user: Add support for ppoll_time64() and pselect6_time64() Filip Bozuta
2020-08-25 7:00 ` Laurent Vivier
2020-08-25 7:17 ` Laurent Vivier
2020-08-25 15:23 ` Laurent Vivier
2020-09-05 20:41 ` Laurent Vivier
2020-08-24 22:30 ` [PATCH v2 2/2] linux-user: Add support for utimensat_time64() and semtimedop_time64() Filip Bozuta
2020-08-25 7:18 ` Laurent Vivier
2020-08-25 14:23 ` Laurent Vivier
2020-08-26 13:58 ` Laurent Vivier
2020-08-26 22:50 ` Laurent Vivier [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=0640cf00-1b5c-c407-c86d-86c7459d2538@vivier.eu \
--to=laurent@vivier.eu \
--cc=Filip.Bozuta@syrmia.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).