Patch "selftests/bpf: Fix error compiling tc_redirect.c with musl libc" has been added to the 6.10-stable tree

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This is a note to let you know that I've just added the patch titled

    selftests/bpf: Fix error compiling tc_redirect.c with musl libc

to the 6.10-stable tree which can be found at:
    http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
     selftests-bpf-fix-error-compiling-tc_redirect.c-with.patch
and it can be found in the queue-6.10 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree,
please let <stable@xxxxxxxxxxxxxxx> know about it.



commit 10d909ef56b04f3d117e14f76c0f5dc5b61e06ea
Author: Tony Ambardar <tony.ambardar@xxxxxxxxx>
Date:   Mon Jul 29 02:24:24 2024 -0700

    selftests/bpf: Fix error compiling tc_redirect.c with musl libc
    
    [ Upstream commit 21c5f4f55da759c7444a1ef13e90b6e6f674eeeb ]
    
    Linux 5.1 implemented 64-bit time types and related syscalls to address the
    Y2038 problem generally across archs. Userspace handling of Y2038 varies
    with the libc however. While musl libc uses 64-bit time across all 32-bit
    and 64-bit platforms, GNU glibc uses 64-bit time on 64-bit platforms but
    defaults to 32-bit time on 32-bit platforms unless they "opt-in" to 64-bit
    time or explicitly use 64-bit syscalls and time structures.
    
    One specific area is the standard setsockopt() call, SO_TIMESTAMPNS option
    used for timestamping, and the related output 'struct timespec'. GNU glibc
    defaults as above, also exposing the SO_TIMESTAMPNS_NEW flag to explicitly
    use a 64-bit call and 'struct __kernel_timespec'. Since these are not
    exposed or needed with musl libc, their use in tc_redirect.c leads to
    compile errors building for mips64el/musl:
    
      tc_redirect.c: In function 'rcv_tstamp':
      tc_redirect.c:425:32: error: 'SO_TIMESTAMPNS_NEW' undeclared (first use in this function); did you mean 'SO_TIMESTAMPNS'?
        425 |             cmsg->cmsg_type == SO_TIMESTAMPNS_NEW)
            |                                ^~~~~~~~~~~~~~~~~~
            |                                SO_TIMESTAMPNS
      tc_redirect.c:425:32: note: each undeclared identifier is reported only once for each function it appears in
      tc_redirect.c: In function 'test_inet_dtime':
      tc_redirect.c:491:49: error: 'SO_TIMESTAMPNS_NEW' undeclared (first use in this function); did you mean 'SO_TIMESTAMPNS'?
        491 |         err = setsockopt(listen_fd, SOL_SOCKET, SO_TIMESTAMPNS_NEW,
            |                                                 ^~~~~~~~~~~~~~~~~~
            |                                                 SO_TIMESTAMPNS
    
    However, using SO_TIMESTAMPNS_NEW isn't strictly needed, nor is Y2038 being
    explicitly tested. The timestamp checks in tc_redirect.c are simple: the
    packet receive timestamp is non-zero and processed/handled in less than 5
    seconds.
    
    Switch to using the standard setsockopt() call and SO_TIMESTAMPNS option to
    ensure compatibility across glibc and musl libc. In the worst-case, there
    is a 5-second window 14 years from now where tc_redirect tests may fail on
    32-bit systems. However, we should reasonably expect glibc to adopt a
    64-bit mandate rather than the current "opt-in" policy before the Y2038
    roll-over.
    
    Fixes: ce6f6cffaeaa ("selftests/bpf: Wait for the netstamp_needed_key static key to be turned on")
    Fixes: c803475fd8dd ("bpf: selftests: test skb->tstamp in redirect_neigh")
    Signed-off-by: Tony Ambardar <tony.ambardar@xxxxxxxxx>
    Signed-off-by: Andrii Nakryiko <andrii@xxxxxxxxxx>
    Link: https://lore.kernel.org/bpf/031d656c058b4e55ceae56ef49c4e1729b5090f3.1722244708.git.tony.ambardar@xxxxxxxxx
    Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>

diff --git a/tools/testing/selftests/bpf/prog_tests/tc_redirect.c b/tools/testing/selftests/bpf/prog_tests/tc_redirect.c
index b1073d36d77ac..a80a83e0440e3 100644
--- a/tools/testing/selftests/bpf/prog_tests/tc_redirect.c
+++ b/tools/testing/selftests/bpf/prog_tests/tc_redirect.c
@@ -471,7 +471,7 @@ static int set_forwarding(bool enable)
 
 static int __rcv_tstamp(int fd, const char *expected, size_t s, __u64 *tstamp)
 {
-	struct __kernel_timespec pkt_ts = {};
+	struct timespec pkt_ts = {};
 	char ctl[CMSG_SPACE(sizeof(pkt_ts))];
 	struct timespec now_ts;
 	struct msghdr msg = {};
@@ -495,7 +495,7 @@ static int __rcv_tstamp(int fd, const char *expected, size_t s, __u64 *tstamp)
 
 	cmsg = CMSG_FIRSTHDR(&msg);
 	if (cmsg && cmsg->cmsg_level == SOL_SOCKET &&
-	    cmsg->cmsg_type == SO_TIMESTAMPNS_NEW)
+	    cmsg->cmsg_type == SO_TIMESTAMPNS)
 		memcpy(&pkt_ts, CMSG_DATA(cmsg), sizeof(pkt_ts));
 
 	pkt_ns = pkt_ts.tv_sec * NSEC_PER_SEC + pkt_ts.tv_nsec;
@@ -537,9 +537,9 @@ static int wait_netstamp_needed_key(void)
 	if (!ASSERT_GE(srv_fd, 0, "start_server"))
 		goto done;
 
-	err = setsockopt(srv_fd, SOL_SOCKET, SO_TIMESTAMPNS_NEW,
+	err = setsockopt(srv_fd, SOL_SOCKET, SO_TIMESTAMPNS,
 			 &opt, sizeof(opt));
-	if (!ASSERT_OK(err, "setsockopt(SO_TIMESTAMPNS_NEW)"))
+	if (!ASSERT_OK(err, "setsockopt(SO_TIMESTAMPNS)"))
 		goto done;
 
 	cli_fd = connect_to_fd(srv_fd, TIMEOUT_MILLIS);
@@ -621,9 +621,9 @@ static void test_inet_dtime(int family, int type, const char *addr, __u16 port)
 		return;
 
 	/* Ensure the kernel puts the (rcv) timestamp for all skb */
-	err = setsockopt(listen_fd, SOL_SOCKET, SO_TIMESTAMPNS_NEW,
+	err = setsockopt(listen_fd, SOL_SOCKET, SO_TIMESTAMPNS,
 			 &opt, sizeof(opt));
-	if (!ASSERT_OK(err, "setsockopt(SO_TIMESTAMPNS_NEW)"))
+	if (!ASSERT_OK(err, "setsockopt(SO_TIMESTAMPNS)"))
 		goto done;
 
 	if (type == SOCK_STREAM) {




[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux