Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 9 Jan 2016 17:11:25 +0000 (UTC)
From:      Dmitry Chagin <dchagin@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org
Subject:   svn commit: r293565 - stable/10/sys/compat/linux
Message-ID:  <201601091711.u09HBP1a054344@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: dchagin
Date: Sat Jan  9 17:11:25 2016
New Revision: 293565
URL: https://svnweb.freebsd.org/changeset/base/293565

Log:
  MFC r283463:
  
  Do not use struct l_timespec without conversion. While here move
  args->timeout handling before acquiring the futex key at FUTEX_WAIT path.

Modified:
  stable/10/sys/compat/linux/linux_futex.c
  stable/10/sys/compat/linux/linux_misc.c
  stable/10/sys/compat/linux/linux_time.c
  stable/10/sys/compat/linux/linux_timer.h
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/sys/compat/linux/linux_futex.c
==============================================================================
--- stable/10/sys/compat/linux/linux_futex.c	Sat Jan  9 17:10:22 2016	(r293564)
+++ stable/10/sys/compat/linux/linux_futex.c	Sat Jan  9 17:11:25 2016	(r293565)
@@ -66,6 +66,7 @@ __KERNEL_RCSID(1, "$NetBSD: linux_futex.
 #include <compat/linux/linux_dtrace.h>
 #include <compat/linux/linux_emul.h>
 #include <compat/linux/linux_futex.h>
+#include <compat/linux/linux_timer.h>
 #include <compat/linux/linux_util.h>
 
 /* DTrace init */
@@ -670,7 +671,8 @@ linux_sys_futex(struct thread *td, struc
 	struct linux_pemuldata *pem;
 	struct waiting_proc *wp;
 	struct futex *f, *f2;
-	struct l_timespec timeout;
+	struct l_timespec ltimeout;
+	struct timespec timeout;
 	struct timeval utv, ctv;
 	int timeout_hz;
 	int error;
@@ -714,6 +716,38 @@ linux_sys_futex(struct thread *td, struc
 		LINUX_CTR3(sys_futex, "WAIT uaddr %p val 0x%x bitset 0x%x",
 		    args->uaddr, args->val, args->val3);
 
+		if (args->timeout != NULL) {
+			error = copyin(args->timeout, &ltimeout, sizeof(ltimeout));
+			if (error) {
+				LIN_SDT_PROBE1(futex, linux_sys_futex, copyin_error,
+				    error);
+				LIN_SDT_PROBE1(futex, linux_sys_futex, return, error);
+				return (error);
+			}
+			error = linux_to_native_timespec(&timeout, &ltimeout);
+			if (error)
+				return (error);
+			TIMESPEC_TO_TIMEVAL(&utv, &timeout);
+			error = itimerfix(&utv);
+			if (error) {
+				LIN_SDT_PROBE1(futex, linux_sys_futex, itimerfix_error,
+				    error);
+				LIN_SDT_PROBE1(futex, linux_sys_futex, return, error);
+				return (error);
+			}
+			if (clockrt) {
+				microtime(&ctv);
+				timevalsub(&utv, &ctv);
+			} else if (args->op == LINUX_FUTEX_WAIT_BITSET) {
+				microuptime(&ctv);
+				timevalsub(&utv, &ctv);
+			}
+			if (utv.tv_sec < 0)
+				timevalclear(&utv);
+			timeout_hz = tvtohz(&utv);
+		} else
+			timeout_hz = 0;
+
 		error = futex_get(args->uaddr, &wp, &f,
 		    flags | FUTEX_CREATE_WP);
 		if (error) {
@@ -746,37 +780,6 @@ linux_sys_futex(struct thread *td, struc
 			return (EWOULDBLOCK);
 		}
 
-		if (args->timeout != NULL) {
-			error = copyin(args->timeout, &timeout, sizeof(timeout));
-			if (error) {
-				LIN_SDT_PROBE1(futex, linux_sys_futex, copyin_error,
-				    error);
-				LIN_SDT_PROBE1(futex, linux_sys_futex, return, error);
-				futex_put(f, wp);
-				return (error);
-			}
-			TIMESPEC_TO_TIMEVAL(&utv, &timeout);
-			error = itimerfix(&utv);
-			if (error) {
-				LIN_SDT_PROBE1(futex, linux_sys_futex, itimerfix_error,
-				    error);
-				LIN_SDT_PROBE1(futex, linux_sys_futex, return, error);
-				futex_put(f, wp);
-				return (error);
-			}
-			if (clockrt) {
-				microtime(&ctv);
-				timevalsub(&utv, &ctv);
-			} else if (args->op == LINUX_FUTEX_WAIT_BITSET) {
-				microuptime(&ctv);
-				timevalsub(&utv, &ctv);
-			}
-			if (utv.tv_sec < 0)
-				timevalclear(&utv);
-			timeout_hz = tvtohz(&utv);
-		} else
-			timeout_hz = 0;
-
 		error = futex_wait(f, wp, timeout_hz, args->val3);
 		break;
 

Modified: stable/10/sys/compat/linux/linux_misc.c
==============================================================================
--- stable/10/sys/compat/linux/linux_misc.c	Sat Jan  9 17:10:22 2016	(r293564)
+++ stable/10/sys/compat/linux/linux_misc.c	Sat Jan  9 17:11:25 2016	(r293565)
@@ -89,6 +89,7 @@ __FBSDID("$FreeBSD$");
 #include <compat/linux/linux_file.h>
 #include <compat/linux/linux_mib.h>
 #include <compat/linux/linux_signal.h>
+#include <compat/linux/linux_timer.h>
 #include <compat/linux/linux_util.h>
 #include <compat/linux/linux_sysproto.h>
 #include <compat/linux/linux_emul.h>
@@ -2166,8 +2167,9 @@ linux_pselect6(struct thread *td, struct
 		error = copyin(args->tsp, &lts, sizeof(lts));
 		if (error != 0)
 			return (error);
-		uts.tv_sec = lts.tv_sec;
-		uts.tv_nsec = lts.tv_nsec;
+		error = linux_to_native_timespec(&uts, &lts);
+		if (error != 0)
+			return (error);
 
 		TIMESPEC_TO_TIMEVAL(&utv, &uts);
 		if (itimerfix(&utv))
@@ -2199,8 +2201,8 @@ linux_pselect6(struct thread *td, struct
 			timevalclear(&utv);
 
 		TIMEVAL_TO_TIMESPEC(&utv, &uts);
-		lts.tv_sec = uts.tv_sec;
-		lts.tv_nsec = uts.tv_nsec;
+
+		native_to_linux_timespec(&lts, &uts);
 		error = copyout(&lts, args->tsp, sizeof(lts));
 	}
 
@@ -2232,8 +2234,9 @@ linux_ppoll(struct thread *td, struct li
 		error = copyin(args->tsp, &lts, sizeof(lts));
 		if (error)
 			return (error);
-		uts.tv_sec = lts.tv_sec;
-		uts.tv_nsec = lts.tv_nsec;
+		error = linux_to_native_timespec(&uts, &lts);
+		if (error != 0)
+			return (error);
 
 		nanotime(&ts0);
 		tsp = &uts;
@@ -2252,8 +2255,7 @@ linux_ppoll(struct thread *td, struct li
 		} else
 			timespecclear(&uts);
 
-		lts.tv_sec = uts.tv_sec;
-		lts.tv_nsec = uts.tv_nsec;
+		native_to_linux_timespec(&lts, &uts);
 		error = copyout(&lts, args->tsp, sizeof(lts));
 	}
 
@@ -2341,8 +2343,7 @@ linux_sched_rr_get_interval(struct threa
 	PROC_UNLOCK(tdt->td_proc);
 	if (error != 0)
 		return (error);
-	lts.tv_sec = ts.tv_sec;
-	lts.tv_nsec = ts.tv_nsec;
+	native_to_linux_timespec(&lts, &ts);
 	return (copyout(&lts, uap->interval, sizeof(lts)));
 }
 

Modified: stable/10/sys/compat/linux/linux_time.c
==============================================================================
--- stable/10/sys/compat/linux/linux_time.c	Sat Jan  9 17:10:22 2016	(r293564)
+++ stable/10/sys/compat/linux/linux_time.c	Sat Jan  9 17:11:25 2016	(r293565)
@@ -120,13 +120,10 @@ LIN_SDT_PROBE_DEFINE1(time, linux_clock_
 LIN_SDT_PROBE_DEFINE1(time, linux_clock_nanosleep, unsupported_clockid, "int");
 LIN_SDT_PROBE_DEFINE1(time, linux_clock_nanosleep, return, "int");
 
-static void native_to_linux_timespec(struct l_timespec *,
-				     struct timespec *);
-static int linux_to_native_timespec(struct timespec *,
-				     struct l_timespec *);
 static int linux_to_native_clockid(clockid_t *, clockid_t);
 
-static void
+
+void
 native_to_linux_timespec(struct l_timespec *ltp, struct timespec *ntp)
 {
 
@@ -138,7 +135,7 @@ native_to_linux_timespec(struct l_timesp
 	LIN_SDT_PROBE0(time, native_to_linux_timespec, return);
 }
 
-static int
+int
 linux_to_native_timespec(struct timespec *ntp, struct l_timespec *ltp)
 {
 

Modified: stable/10/sys/compat/linux/linux_timer.h
==============================================================================
--- stable/10/sys/compat/linux/linux_timer.h	Sat Jan  9 17:10:22 2016	(r293564)
+++ stable/10/sys/compat/linux/linux_timer.h	Sat Jan  9 17:11:25 2016	(r293565)
@@ -111,4 +111,9 @@ struct l_itimerspec {
 	struct l_timespec it_value;
 };
 
+void native_to_linux_timespec(struct l_timespec *,
+				     struct timespec *);
+int linux_to_native_timespec(struct timespec *,
+				     struct l_timespec *);
+
 #endif	/* _LINUX_TIMER_H */



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201601091711.u09HBP1a054344>