All of lore.kernel.org
 help / color / mirror / Atom feed
* linux-user: Add sockopts for SO_RCVTIMEO_NEW and SO_SNDTIMEO_NEW
@ 2026-04-24  9:08 Helge Deller
  2026-04-24  9:08 ` [PATCH 1/4] linux-user: Use int64_t in target__kernel_sock_timeval Helge Deller
                   ` (4 more replies)
  0 siblings, 5 replies; 8+ messages in thread
From: Helge Deller @ 2026-04-24  9:08 UTC (permalink / raw)
  To: laurent, qemu-devel; +Cc: deller

This series should fix
https://gitlab.com/qemu-project/qemu/-/work_items/885

Please review.


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH 1/4] linux-user: Use int64_t in target__kernel_sock_timeval
  2026-04-24  9:08 linux-user: Add sockopts for SO_RCVTIMEO_NEW and SO_SNDTIMEO_NEW Helge Deller
@ 2026-04-24  9:08 ` Helge Deller
  2026-04-24 22:14   ` Richard Henderson
  2026-04-24  9:08 ` [PATCH 2/4] linux-user: Define SO_TIMESTAMP*_NEW and SO_RCVTIMEIO_NEW Helge Deller
                   ` (3 subsequent siblings)
  4 siblings, 1 reply; 8+ messages in thread
From: Helge Deller @ 2026-04-24  9:08 UTC (permalink / raw)
  To: laurent, qemu-devel; +Cc: deller

From: Helge Deller <deller@gmx.de>

The Linux kernel uses the __s64 type for the tv_sec and tv_usec members of
target__kernel_sock_timeval, so prefer the native type here as well.

Signed-off-by: Helge Deller <deller@gmx.de>
---
 linux-user/syscall_defs.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h
index 6967306be4..138ce6abb1 100644
--- a/linux-user/syscall_defs.h
+++ b/linux-user/syscall_defs.h
@@ -238,8 +238,8 @@ struct target_timeval {
 };
 
 struct target__kernel_sock_timeval {
-    abi_llong tv_sec;
-    abi_llong tv_usec;
+    int64_t tv_sec;
+    int64_t tv_usec;
 };
 #endif
 
-- 
2.53.0



^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 2/4] linux-user: Define SO_TIMESTAMP*_NEW and SO_RCVTIMEIO_NEW
  2026-04-24  9:08 linux-user: Add sockopts for SO_RCVTIMEO_NEW and SO_SNDTIMEO_NEW Helge Deller
  2026-04-24  9:08 ` [PATCH 1/4] linux-user: Use int64_t in target__kernel_sock_timeval Helge Deller
@ 2026-04-24  9:08 ` Helge Deller
  2026-04-24  9:08 ` [PATCH 3/4] linux-user: Add setsockopt() for SO_RCVTIMEO_NEW and SO_SNDTIMEO_NEW Helge Deller
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 8+ messages in thread
From: Helge Deller @ 2026-04-24  9:08 UTC (permalink / raw)
  To: laurent, qemu-devel; +Cc: deller

From: Helge Deller <deller@gmx.de>

Define the entries which always use the 64-bit timestamps.

Signed-off-by: Helge Deller <deller@gmx.de>
---
 linux-user/alpha/sockbits.h   | 7 +++++++
 linux-user/generic/sockbits.h | 8 ++++++++
 linux-user/hppa/sockbits.h    | 7 +++++++
 linux-user/mips/sockbits.h    | 7 +++++++
 linux-user/sparc/sockbits.h   | 7 +++++++
 5 files changed, 36 insertions(+)

diff --git a/linux-user/alpha/sockbits.h b/linux-user/alpha/sockbits.h
index d54dc98c09..0201ab9374 100644
--- a/linux-user/alpha/sockbits.h
+++ b/linux-user/alpha/sockbits.h
@@ -75,6 +75,13 @@
 /* Instruct lower device to use last 4-bytes of skb data as FCS */
 #define TARGET_SO_NOFCS     43
 
+#define TARGET_SO_TIMESTAMP_NEW        63
+#define TARGET_SO_TIMESTAMPNS_NEW      64
+#define TARGET_SO_TIMESTAMPING_NEW     65
+
+#define TARGET_SO_RCVTIMEO_NEW         66
+#define TARGET_SO_SNDTIMEO_NEW         67
+
 /* TARGET_O_NONBLOCK clashes with the bits used for socket types.  Therefore we
  * have to define SOCK_NONBLOCK to a different value here.
  */
diff --git a/linux-user/generic/sockbits.h b/linux-user/generic/sockbits.h
index b3b4a8e44c..33e6c3a572 100644
--- a/linux-user/generic/sockbits.h
+++ b/linux-user/generic/sockbits.h
@@ -58,4 +58,12 @@
 
 #define TARGET_SO_PROTOCOL             38
 #define TARGET_SO_DOMAIN               39
+
+#define TARGET_SO_TIMESTAMP_NEW        63
+#define TARGET_SO_TIMESTAMPNS_NEW      64
+#define TARGET_SO_TIMESTAMPING_NEW     65
+
+#define TARGET_SO_RCVTIMEO_NEW         66
+#define TARGET_SO_SNDTIMEO_NEW         67
+
 #endif
diff --git a/linux-user/hppa/sockbits.h b/linux-user/hppa/sockbits.h
index 23f69a3293..2304dbbf79 100644
--- a/linux-user/hppa/sockbits.h
+++ b/linux-user/hppa/sockbits.h
@@ -67,6 +67,13 @@
 
 #define TARGET_SO_CNX_ADVICE           0x402E
 
+#define TARGET_SO_TIMESTAMP_NEW        0x4038
+#define TARGET_SO_TIMESTAMPNS_NEW      0x4039
+#define TARGET_SO_TIMESTAMPING_NEW     0x403A
+
+#define TARGET_SO_RCVTIMEO_NEW         0x4040
+#define TARGET_SO_SNDTIMEO_NEW         0x4041
+
 /* TARGET_O_NONBLOCK clashes with the bits used for socket types.  Therefore we
  * have to define SOCK_NONBLOCK to a different value here.
  */
diff --git a/linux-user/mips/sockbits.h b/linux-user/mips/sockbits.h
index 562cad88e2..1f479d54aa 100644
--- a/linux-user/mips/sockbits.h
+++ b/linux-user/mips/sockbits.h
@@ -71,6 +71,13 @@
 #define TARGET_SO_RCVBUFFORCE          33
 #define TARGET_SO_PASSSEC              34
 
+#define TARGET_SO_TIMESTAMP_NEW        63
+#define TARGET_SO_TIMESTAMPNS_NEW      64
+#define TARGET_SO_TIMESTAMPING_NEW     65
+
+#define TARGET_SO_RCVTIMEO_NEW         66
+#define TARGET_SO_SNDTIMEO_NEW         67
+
 /** sock_type - Socket types
  *
  * Please notice that for binary compat reasons MIPS has to
diff --git a/linux-user/sparc/sockbits.h b/linux-user/sparc/sockbits.h
index 0a822e3e1f..42ecfdc8f9 100644
--- a/linux-user/sparc/sockbits.h
+++ b/linux-user/sparc/sockbits.h
@@ -61,6 +61,13 @@
 #define TARGET_SO_TIMESTAMPING         0x0023
 #define TARGET_SCM_TIMESTAMPING        TARGET_SO_TIMESTAMPING
 
+#define TARGET_SO_TIMESTAMP_NEW        0x0046
+#define TARGET_SO_TIMESTAMPNS_NEW      0x0042
+#define TARGET_SO_TIMESTAMPING_NEW     0x0043
+
+#define TARGET_SO_RCVTIMEO_NEW         0x0044
+#define TARGET_SO_SNDTIMEO_NEW         0x0045
+
 #define TARGET_SO_RXQ_OVFL             0x0024
 
 #define TARGET_SO_WIFI_STATUS          0x0025
-- 
2.53.0



^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 3/4] linux-user: Add setsockopt() for SO_RCVTIMEO_NEW and SO_SNDTIMEO_NEW
  2026-04-24  9:08 linux-user: Add sockopts for SO_RCVTIMEO_NEW and SO_SNDTIMEO_NEW Helge Deller
  2026-04-24  9:08 ` [PATCH 1/4] linux-user: Use int64_t in target__kernel_sock_timeval Helge Deller
  2026-04-24  9:08 ` [PATCH 2/4] linux-user: Define SO_TIMESTAMP*_NEW and SO_RCVTIMEIO_NEW Helge Deller
@ 2026-04-24  9:08 ` Helge Deller
  2026-04-24  9:08 ` [PATCH 4/4] linux-user: Add getsockopt() " Helge Deller
  2026-04-30 16:34 ` linux-user: Add sockopts " Michael Tokarev
  4 siblings, 0 replies; 8+ messages in thread
From: Helge Deller @ 2026-04-24  9:08 UTC (permalink / raw)
  To: laurent, qemu-devel; +Cc: deller

From: Helge Deller <deller@gmx.de>

Add handlers for both sockopts which use 64-bit time_t from userspace.

Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/885
Signed-off-by: Helge Deller <deller@gmx.de>
---
 linux-user/syscall.c | 21 +++++++++++++++++++--
 1 file changed, 19 insertions(+), 2 deletions(-)

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 077ecb7554..7bd5ad548b 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -1143,7 +1143,6 @@ static inline abi_long copy_to_user_timeval(abi_ulong target_tv_addr,
     return 0;
 }
 
-#if defined(TARGET_NR_clock_adjtime64) && defined(CONFIG_CLOCK_ADJTIME)
 static inline abi_long copy_from_user_timeval64(struct timeval *tv,
                                                 abi_ulong target_tv_addr)
 {
@@ -1160,7 +1159,6 @@ static inline abi_long copy_from_user_timeval64(struct timeval *tv,
 
     return 0;
 }
-#endif
 
 static inline abi_long copy_to_user_timeval64(abi_ulong target_tv_addr,
                                               const struct timeval *tv)
@@ -2391,6 +2389,25 @@ static abi_long do_setsockopt(int sockfd, int level, int optname,
                                 &tv, sizeof(tv)));
                 return ret;
         }
+        case TARGET_SO_RCVTIMEO_NEW:
+        case TARGET_SO_SNDTIMEO_NEW:
+        {
+                struct timeval tv;
+
+                if (optlen != sizeof(struct target__kernel_sock_timeval)) {
+                    return -TARGET_EINVAL;
+                }
+
+                if (copy_from_user_timeval64(&tv, optval_addr)) {
+                    return -TARGET_EFAULT;
+                }
+
+                ret = get_errno(setsockopt(sockfd, SOL_SOCKET,
+                                optname == TARGET_SO_RCVTIMEO_NEW ?
+                                    SO_RCVTIMEO : SO_SNDTIMEO,
+                                &tv, sizeof(tv)));
+                return ret;
+        }
         case TARGET_SO_ATTACH_FILTER:
         {
                 struct target_sock_fprog *tfprog;
-- 
2.53.0



^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 4/4] linux-user: Add getsockopt() for SO_RCVTIMEO_NEW and SO_SNDTIMEO_NEW
  2026-04-24  9:08 linux-user: Add sockopts for SO_RCVTIMEO_NEW and SO_SNDTIMEO_NEW Helge Deller
                   ` (2 preceding siblings ...)
  2026-04-24  9:08 ` [PATCH 3/4] linux-user: Add setsockopt() for SO_RCVTIMEO_NEW and SO_SNDTIMEO_NEW Helge Deller
@ 2026-04-24  9:08 ` Helge Deller
  2026-04-30 16:34 ` linux-user: Add sockopts " Michael Tokarev
  4 siblings, 0 replies; 8+ messages in thread
From: Helge Deller @ 2026-04-24  9:08 UTC (permalink / raw)
  To: laurent, qemu-devel; +Cc: deller

From: Helge Deller <deller@gmx.de>

Add handlers for both sockopts which use 64-bit time_t from userspace.

Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/885
Signed-off-by: Helge Deller <deller@gmx.de>
---
 linux-user/syscall.c | 20 ++++++++++++++------
 1 file changed, 14 insertions(+), 6 deletions(-)

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 7bd5ad548b..a75dbceb5c 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -2621,7 +2621,8 @@ static abi_long do_getsockopt(int sockfd, int level, int optname,
         /* These don't just return a single integer */
         case TARGET_SO_PEERNAME:
             goto unimplemented;
-        case TARGET_SO_RCVTIMEO: {
+        case TARGET_SO_RCVTIMEO:
+        case TARGET_SO_RCVTIMEO_NEW: {
             struct timeval tv;
             socklen_t tvlen;
 
@@ -2641,11 +2642,17 @@ get_timeout:
             if (ret < 0) {
                 return ret;
             }
-            if (len > sizeof(struct target_timeval)) {
-                len = sizeof(struct target_timeval);
-            }
-            if (copy_to_user_timeval(optval_addr, &tv)) {
-                return -TARGET_EFAULT;
+            if (len == sizeof(struct target__kernel_sock_timeval)) {
+                if (copy_to_user_timeval64(optval_addr, &tv)) {
+                    return -TARGET_EFAULT;
+                }
+            } else {
+                if (len >= sizeof(struct target_timeval)) {
+                    len = sizeof(struct target_timeval);
+                    if (copy_to_user_timeval(optval_addr, &tv)) {
+                        return -TARGET_EFAULT;
+                    }
+                }
             }
             if (put_user_u32(len, optlen)) {
                 return -TARGET_EFAULT;
@@ -2653,6 +2660,7 @@ get_timeout:
             break;
         }
         case TARGET_SO_SNDTIMEO:
+        case TARGET_SO_SNDTIMEO_NEW:
             optname = SO_SNDTIMEO;
             goto get_timeout;
         case TARGET_SO_PEERCRED: {
-- 
2.53.0



^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH 1/4] linux-user: Use int64_t in target__kernel_sock_timeval
  2026-04-24  9:08 ` [PATCH 1/4] linux-user: Use int64_t in target__kernel_sock_timeval Helge Deller
@ 2026-04-24 22:14   ` Richard Henderson
  2026-04-24 22:37     ` Helge Deller
  0 siblings, 1 reply; 8+ messages in thread
From: Richard Henderson @ 2026-04-24 22:14 UTC (permalink / raw)
  To: qemu-devel

On 4/24/26 19:08, Helge Deller wrote:
> From: Helge Deller <deller@gmx.de>
> 
> The Linux kernel uses the __s64 type for the tv_sec and tv_usec members of
> target__kernel_sock_timeval, so prefer the native type here as well.
> 
> Signed-off-by: Helge Deller <deller@gmx.de>
> ---
>   linux-user/syscall_defs.h | 4 ++--
>   1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h
> index 6967306be4..138ce6abb1 100644
> --- a/linux-user/syscall_defs.h
> +++ b/linux-user/syscall_defs.h
> @@ -238,8 +238,8 @@ struct target_timeval {
>   };
>   
>   struct target__kernel_sock_timeval {
> -    abi_llong tv_sec;
> -    abi_llong tv_usec;
> +    int64_t tv_sec;
> +    int64_t tv_usec;
>   };
>   #endif
>   

Nack. This has target alignment implications.


r~


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 1/4] linux-user: Use int64_t in target__kernel_sock_timeval
  2026-04-24 22:14   ` Richard Henderson
@ 2026-04-24 22:37     ` Helge Deller
  0 siblings, 0 replies; 8+ messages in thread
From: Helge Deller @ 2026-04-24 22:37 UTC (permalink / raw)
  To: Richard Henderson, qemu-devel

On 4/25/26 00:14, Richard Henderson wrote:
> On 4/24/26 19:08, Helge Deller wrote:
>> From: Helge Deller <deller@gmx.de>
>>
>> The Linux kernel uses the __s64 type for the tv_sec and tv_usec members of
>> target__kernel_sock_timeval, so prefer the native type here as well.
>>
>> Signed-off-by: Helge Deller <deller@gmx.de>
>> ---
>>   linux-user/syscall_defs.h | 4 ++--
>>   1 file changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h
>> index 6967306be4..138ce6abb1 100644
>> --- a/linux-user/syscall_defs.h
>> +++ b/linux-user/syscall_defs.h
>> @@ -238,8 +238,8 @@ struct target_timeval {
>>   };
>>   struct target__kernel_sock_timeval {
>> -    abi_llong tv_sec;
>> -    abi_llong tv_usec;
>> +    int64_t tv_sec;
>> +    int64_t tv_usec;
>>   };
>>   #endif
> 
> Nack. This has target alignment implications.

Oh, now I see:
typedef uint64_t abi_ullong __attribute__((aligned(ABI_LLONG_ALIGNMENT)));

I drop that patch.

Thanks!
Helge


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: linux-user: Add sockopts for SO_RCVTIMEO_NEW and SO_SNDTIMEO_NEW
  2026-04-24  9:08 linux-user: Add sockopts for SO_RCVTIMEO_NEW and SO_SNDTIMEO_NEW Helge Deller
                   ` (3 preceding siblings ...)
  2026-04-24  9:08 ` [PATCH 4/4] linux-user: Add getsockopt() " Helge Deller
@ 2026-04-30 16:34 ` Michael Tokarev
  4 siblings, 0 replies; 8+ messages in thread
From: Michael Tokarev @ 2026-04-30 16:34 UTC (permalink / raw)
  To: Helge Deller, laurent, qemu-devel; +Cc: deller, qemu-stable

On 24.04.2026 12:08, Helge Deller wrote:
> This series should fix
> https://gitlab.com/qemu-project/qemu/-/work_items/885
> 
> Please review.

I'm picking this series up for qemu-stable as well, despite it
being a "new feature", so to say, since with the situation
before this series, things will break for more recent linux
kernel and userspace.

Hopefully it will work in qemu 10.0.x series too, which still
had support for 32bit hosts..  do we have testcase for the
whole thing?

Sigh, that was very unfortunate naming, why didn't they used
something like SO_RCVTIMEO_T64??..  But this has nothing to
do with this patch series..

Thanks,

/mjt


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2026-04-30 16:35 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-24  9:08 linux-user: Add sockopts for SO_RCVTIMEO_NEW and SO_SNDTIMEO_NEW Helge Deller
2026-04-24  9:08 ` [PATCH 1/4] linux-user: Use int64_t in target__kernel_sock_timeval Helge Deller
2026-04-24 22:14   ` Richard Henderson
2026-04-24 22:37     ` Helge Deller
2026-04-24  9:08 ` [PATCH 2/4] linux-user: Define SO_TIMESTAMP*_NEW and SO_RCVTIMEIO_NEW Helge Deller
2026-04-24  9:08 ` [PATCH 3/4] linux-user: Add setsockopt() for SO_RCVTIMEO_NEW and SO_SNDTIMEO_NEW Helge Deller
2026-04-24  9:08 ` [PATCH 4/4] linux-user: Add getsockopt() " Helge Deller
2026-04-30 16:34 ` linux-user: Add sockopts " Michael Tokarev

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.