From nobody Sun May 08 13:17:08 2022 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 8D0FD1AD7779; Sun, 8 May 2022 13:17:08 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Kx4b83NsZz4pvw; Sun, 8 May 2022 13:17:08 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1652015828; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=mYrmmXRlhlGkp0WK+6pHXGxv0RpJuFe2nJPXtUUGZUM=; b=GpSlSITiCWYColZO+T+HmrYzDKYFP3SHMh+I33T50ndcSG15BdZ22RKmiIpXemFSs2iZbc 7ZbcsMvbFCcA5ahojzG+uh3c4ZeKjD7mvQ8cZf+MnZaX1QuQ2X964mFSWk4MbvDKbIE2+k b4LUEVjxdD7MCDfHkVnEnbaAekQzHK1ef3jKhrF72j6fkx29WqVtS5popGncROXl3bC95G jg9k/GHLP2JG7SrIMVlTOwuV4IfCq47CbThtrk3IU/Adng4FxqBpyJYULoWa4Q2L3SOM46 tmongTFNrvvVc78dJ//fgOR5IJqFcTYN3nNxZBOBjBy4qU6ffR0QbWAjsXHC0w== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 5426625791; Sun, 8 May 2022 13:17:08 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 248DH8S2044013; Sun, 8 May 2022 13:17:08 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 248DH8at044012; Sun, 8 May 2022 13:17:08 GMT (envelope-from git) Date: Sun, 8 May 2022 13:17:08 GMT Message-Id: <202205081317.248DH8at044012@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Dmitry Chagin Subject: git: 9a9482f87490 - main - linux(4): Add a helper intended for copying timespec's to the userspace. List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: dchagin X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 9a9482f87490bcbb054ba1799d69fdab7cdb6dc9 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1652015828; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=mYrmmXRlhlGkp0WK+6pHXGxv0RpJuFe2nJPXtUUGZUM=; b=ZLLNWiNi0VLDnebCldZ2CNNyJqqs5vphpf861lW4RtbCaG6YWNmPCgCucgUzDoLxjppnF9 I7tBjIE54sd82p56Y+XpdNjxSkqv/xCTDPzLgfcb4X8xdOpZ/CrM1TyoxYiWg5xSQUh91h ek5WeZvZFnDm/t4fDi2v/+scsxBmyodRATuTaKIiNFKgMvAgxRImJWQBcfGQu9Fo6rWie1 pDdZ7sVKxpxkmbT/VKYzF4Oz0cCskshV0pmC3qXzG1VA/HCoTJSR/+P8BZ+vCi+v1NlfV3 9roX6UEkInBuMKXjPRnocs8sE/uSNSB73XGA8vrfzP++S5T1fUcodCCJDDEIrw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1652015828; a=rsa-sha256; cv=none; b=UOO7ZGeQ0zzlljSYomxy1uGDxa6oalnce0LjLaSBENNGU+MqCtmAoGGC4YhmBSiMMxU5+a +QinYxgQUGC7sH28QTSyCOc+mgsbaeKxbOeug40ammajy//ZAHkE3wfIkBd0huoMRq815F NMu+2Zb4IJYTBlgY5i2rgEEMoxBY8GvR0UdI25TkcZBy+tdz4lpDUKMB9N3GCaAC9Qs543 P1Qa8md9tIEr7glYzj8BHIGCFm3mTfz/IUPHEA9/ykMmEHh+jAqT7ToBoBJ+NRKY9EqHN9 sVIBSlGDPmcAWy5Es97cPa64NH31j2T9QwcSK4/cLA8FaFCUEJkTHrf2xiMN1g== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by dchagin: URL: https://cgit.FreeBSD.org/src/commit/?id=9a9482f87490bcbb054ba1799d69fdab7cdb6dc9 commit 9a9482f87490bcbb054ba1799d69fdab7cdb6dc9 Author: Dmitry Chagin AuthorDate: 2022-05-08 12:37:27 +0000 Commit: Dmitry Chagin CommitDate: 2022-05-08 12:37:27 +0000 linux(4): Add a helper intended for copying timespec's to the userspace. There are many places where we convert natvie timespec and copyout it to the userspace. To avoid code duplication add a tiny halper for doing this. MFC after: 2 weeks --- sys/compat/linux/linux_misc.c | 48 +++++++--------------------- sys/compat/linux/linux_time.c | 71 ++++++++++++++++++++---------------------- sys/compat/linux/linux_timer.h | 4 +++ 3 files changed, 50 insertions(+), 73 deletions(-) diff --git a/sys/compat/linux/linux_misc.c b/sys/compat/linux/linux_misc.c index 118318d9bae1..10f4f52ba500 100644 --- a/sys/compat/linux/linux_misc.c +++ b/sys/compat/linux/linux_misc.c @@ -2379,7 +2379,7 @@ linux_pselect6(struct thread *td, struct linux_pselect6_args *args) { struct l_timespec lts; struct timespec ts, *tsp; - int error, error2; + int error; if (args->tsp != NULL) { error = copyin(args->tsp, <s, sizeof(lts)); @@ -2395,11 +2395,8 @@ linux_pselect6(struct thread *td, struct linux_pselect6_args *args) error = linux_common_pselect6(td, args->nfds, args->readfds, args->writefds, args->exceptfds, tsp, args->sig); - if (args->tsp != NULL) { - error2 = native_to_linux_timespec(<s, tsp); - if (error2 == 0) - copyout(<s, args->tsp, sizeof(lts)); - } + if (args->tsp != NULL) + linux_put_timespec(&ts, args->tsp); return (error); } @@ -2474,7 +2471,7 @@ linux_pselect6_time64(struct thread *td, { struct l_timespec64 lts; struct timespec ts, *tsp; - int error, error2; + int error; if (args->tsp != NULL) { error = copyin(args->tsp, <s, sizeof(lts)); @@ -2490,11 +2487,8 @@ linux_pselect6_time64(struct thread *td, error = linux_common_pselect6(td, args->nfds, args->readfds, args->writefds, args->exceptfds, tsp, args->sig); - if (args->tsp != NULL) { - error2 = native_to_linux_timespec64(<s, tsp); - if (error2 == 0) - copyout(<s, args->tsp, sizeof(lts)); - } + if (args->tsp != NULL) + linux_put_timespec64(&ts, args->tsp); return (error); } #endif /* __i386__ || (__amd64__ && COMPAT_LINUX32) */ @@ -2519,13 +2513,8 @@ linux_ppoll(struct thread *td, struct linux_ppoll_args *args) error = linux_common_ppoll(td, args->fds, args->nfds, tsp, args->sset, args->ssize); - if (error != 0) - return (error); - if (tsp != NULL) { - error = native_to_linux_timespec(<s, tsp); - if (error == 0) - error = copyout(<s, args->tsp, sizeof(lts)); - } + if (error == 0 && args->tsp != NULL) + error = linux_put_timespec(&uts, args->tsp); return (error); } @@ -2605,13 +2594,8 @@ linux_ppoll_time64(struct thread *td, struct linux_ppoll_time64_args *args) tsp = NULL; error = linux_common_ppoll(td, args->fds, args->nfds, tsp, args->sset, args->ssize); - if (error != 0) - return (error); - if (tsp != NULL) { - error = native_to_linux_timespec64(<s, tsp); - if (error == 0) - error = copyout(<s, args->tsp, sizeof(lts)); - } + if (error == 0 && args->tsp != NULL) + error = linux_put_timespec64(&uts, args->tsp); return (error); } #endif /* __i386__ || (__amd64__ && COMPAT_LINUX32) */ @@ -2686,16 +2670,12 @@ linux_sched_rr_get_interval(struct thread *td, struct linux_sched_rr_get_interval_args *uap) { struct timespec ts; - struct l_timespec lts; int error; error = linux_sched_rr_get_interval_common(td, uap->pid, &ts); if (error != 0) return (error); - error = native_to_linux_timespec(<s, &ts); - if (error != 0) - return (error); - return (copyout(<s, uap->interval, sizeof(lts))); + return (linux_put_timespec(&ts, uap->interval)); } #if defined(__i386__) || (defined(__amd64__) && defined(COMPAT_LINUX32)) @@ -2704,16 +2684,12 @@ linux_sched_rr_get_interval_time64(struct thread *td, struct linux_sched_rr_get_interval_time64_args *uap) { struct timespec ts; - struct l_timespec64 lts; int error; error = linux_sched_rr_get_interval_common(td, uap->pid, &ts); if (error != 0) return (error); - error = native_to_linux_timespec64(<s, &ts); - if (error != 0) - return (error); - return (copyout(<s, uap->interval, sizeof(lts))); + return (linux_put_timespec64(&ts, uap->interval)); } #endif diff --git a/sys/compat/linux/linux_time.c b/sys/compat/linux/linux_time.c index 447319a7edc9..e97a1145d31b 100644 --- a/sys/compat/linux/linux_time.c +++ b/sys/compat/linux/linux_time.c @@ -150,6 +150,18 @@ linux_to_native_timespec(struct timespec *ntp, struct l_timespec *ltp) return (0); } +int +linux_put_timespec(struct timespec *ntp, struct l_timespec *ltp) +{ + struct l_timespec lts; + int error; + + error = native_to_linux_timespec(<s, ntp); + if (error != 0) + return (error); + return (copyout(<s, ltp, sizeof(lts))); +} + #if defined(__i386__) || (defined(__amd64__) && defined(COMPAT_LINUX32)) int native_to_linux_timespec64(struct l_timespec64 *ltp64, struct timespec *ntp) @@ -172,6 +184,18 @@ linux_to_native_timespec64(struct timespec *ntp, struct l_timespec64 *ltp64) return (0); } + +int +linux_put_timespec64(struct timespec *ntp, struct l_timespec64 *ltp) +{ + struct l_timespec64 lts; + int error; + + error = native_to_linux_timespec64(<s, ntp); + if (error != 0) + return (error); + return (copyout(<s, ltp, sizeof(lts))); +} #endif int @@ -414,7 +438,6 @@ linux_common_clock_gettime(struct thread *td, clockid_t which, int linux_clock_gettime(struct thread *td, struct linux_clock_gettime_args *args) { - struct l_timespec lts; struct timespec tp; int error; @@ -423,10 +446,7 @@ linux_clock_gettime(struct thread *td, struct linux_clock_gettime_args *args) LIN_SDT_PROBE1(time, linux_clock_gettime, gettime_error, error); return (error); } - error = native_to_linux_timespec(<s, &tp); - if (error != 0) - return (error); - error = copyout(<s, args->tp, sizeof(lts)); + error = linux_put_timespec(&tp, args->tp); if (error != 0) LIN_SDT_PROBE1(time, linux_clock_gettime, copyout_error, error); @@ -437,7 +457,6 @@ linux_clock_gettime(struct thread *td, struct linux_clock_gettime_args *args) int linux_clock_gettime64(struct thread *td, struct linux_clock_gettime64_args *args) { - struct l_timespec64 lts; struct timespec tp; int error; @@ -446,10 +465,7 @@ linux_clock_gettime64(struct thread *td, struct linux_clock_gettime64_args *args LIN_SDT_PROBE1(time, linux_clock_gettime64, gettime_error, error); return (error); } - error = native_to_linux_timespec64(<s, &tp); - if (error != 0) - return (error); - error = copyout(<s, args->tp, sizeof(lts)); + error = linux_put_timespec64(&tp, args->tp); if (error != 0) LIN_SDT_PROBE1(time, linux_clock_gettime64, copyout_error, error); @@ -622,17 +638,12 @@ linux_clock_getres(struct thread *td, struct linux_clock_getres_args *args) { struct timespec ts; - struct l_timespec lts; int error; error = linux_common_clock_getres(td, args->which, &ts); if (error != 0 || args->tp == NULL) return (error); - - error = native_to_linux_timespec(<s, &ts); - if (error != 0) - return (error); - error = copyout(<s, args->tp, sizeof(lts)); + error = linux_put_timespec(&ts, args->tp); if (error != 0) LIN_SDT_PROBE1(time, linux_clock_getres, copyout_error, error); @@ -645,17 +656,12 @@ linux_clock_getres_time64(struct thread *td, struct linux_clock_getres_time64_args *args) { struct timespec ts; - struct l_timespec64 lts; int error; error = linux_common_clock_getres(td, args->which, &ts); if (error != 0 || args->tp == NULL) return (error); - - error = native_to_linux_timespec64(<s, &ts); - if (error != 0) - return (error); - error = copyout(<s, args->tp, sizeof(lts)); + error = linux_put_timespec64(&ts, args->tp); if (error != 0) LIN_SDT_PROBE1(time, linux_clock_getres_time64, copyout_error, error); @@ -667,7 +673,7 @@ int linux_nanosleep(struct thread *td, struct linux_nanosleep_args *args) { struct timespec *rmtp; - struct l_timespec lrqts, lrmts; + struct l_timespec lrqts; struct timespec rqts, rmts; int error, error2; @@ -689,10 +695,7 @@ linux_nanosleep(struct thread *td, struct linux_nanosleep_args *args) } error = kern_nanosleep(td, &rqts, rmtp); if (error == EINTR && args->rmtp != NULL) { - error2 = native_to_linux_timespec(&lrmts, rmtp); - if (error2 != 0) - return (error2); - error2 = copyout(&lrmts, args->rmtp, sizeof(lrmts)); + error2 = linux_put_timespec(rmtp, args->rmtp); if (error2 != 0) { LIN_SDT_PROBE1(time, linux_nanosleep, copyout_error, error2); @@ -736,7 +739,7 @@ linux_clock_nanosleep(struct thread *td, struct linux_clock_nanosleep_args *args) { struct timespec *rmtp; - struct l_timespec lrqts, lrmts; + struct l_timespec lrqts; struct timespec rqts, rmts; int error, error2; @@ -763,10 +766,7 @@ linux_clock_nanosleep(struct thread *td, &rqts, rmtp); if (error == EINTR && (args->flags & LINUX_TIMER_ABSTIME) == 0 && args->rmtp != NULL) { - error2 = native_to_linux_timespec(&lrmts, rmtp); - if (error2 != 0) - return (error2); - error2 = copyout(&lrmts, args->rmtp, sizeof(lrmts)); + error2 = linux_put_timespec(rmtp, args->rmtp); if (error2 != 0) { LIN_SDT_PROBE1(time, linux_clock_nanosleep, copyout_error, error2); @@ -782,7 +782,7 @@ linux_clock_nanosleep_time64(struct thread *td, struct linux_clock_nanosleep_time64_args *args) { struct timespec *rmtp; - struct l_timespec64 lrqts, lrmts; + struct l_timespec64 lrqts; struct timespec rqts, rmts; int error, error2; @@ -809,10 +809,7 @@ linux_clock_nanosleep_time64(struct thread *td, &rqts, rmtp); if (error == EINTR && (args->flags & LINUX_TIMER_ABSTIME) == 0 && args->rmtp != NULL) { - error2 = native_to_linux_timespec64(&lrmts, rmtp); - if (error2 != 0) - return (error2); - error2 = copyout(&lrmts, args->rmtp, sizeof(lrmts)); + error2 = linux_put_timespec64(rmtp, args->rmtp); if (error2 != 0) { LIN_SDT_PROBE1(time, linux_clock_nanosleep_time64, copyout_error, error2); diff --git a/sys/compat/linux/linux_timer.h b/sys/compat/linux/linux_timer.h index 7617316b09c6..edff6c845032 100644 --- a/sys/compat/linux/linux_timer.h +++ b/sys/compat/linux/linux_timer.h @@ -115,11 +115,15 @@ int native_to_linux_timespec(struct l_timespec *, struct timespec *); int linux_to_native_timespec(struct timespec *, struct l_timespec *); +int linux_put_timespec(struct timespec *, + struct l_timespec *); #if defined(__i386__) || (defined(__amd64__) && defined(COMPAT_LINUX32)) int native_to_linux_timespec64(struct l_timespec64 *, struct timespec *); int linux_to_native_timespec64(struct timespec *, struct l_timespec64 *); +int linux_put_timespec64(struct timespec *, + struct l_timespec64 *); #endif int linux_to_native_clockid(clockid_t *, clockid_t); int native_to_linux_itimerspec(struct l_itimerspec *,