From patchwork Mon Jul 5 18:30:21 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 44155 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 76824383D809 for ; Mon, 5 Jul 2021 18:31:40 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 76824383D809 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1625509900; bh=BLl4/W6VAyJ5bqm4j9oz9qtDPZjPpr4KxixYq1mPpTk=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=MVteg0yTcEH90qhb/o8aJq2gmm9knDSHXJ816OfbwwJJTX+dgzCPqAYQIeYjICMJz OzXDnqD22C/FG+Xm4zeOOiJjzRmowHW4GLPCj91+SCgwI2jcWFQv5XP6OG+7zBcpTt QaLSJm1sFIO9+AGd6s29u1eTS2GkmBhWiQpUSFjY= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pl1-x632.google.com (mail-pl1-x632.google.com [IPv6:2607:f8b0:4864:20::632]) by sourceware.org (Postfix) with ESMTPS id 01B5938515E5 for ; Mon, 5 Jul 2021 18:30:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 01B5938515E5 Received: by mail-pl1-x632.google.com with SMTP id o4so7599197plg.1 for ; Mon, 05 Jul 2021 11:30:34 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=BLl4/W6VAyJ5bqm4j9oz9qtDPZjPpr4KxixYq1mPpTk=; b=ShSo8GoLfgAtM5ICB+q8dciV7NrwQiuwQhDZO6LGY7Tz/EL54gDc+XX8rkArgic1s+ 1OVM3Lt7fo2GbiSWK0Jlzr8ymtuyaq0Ht/B8H8MPg3uKv/2UxdCNI17gtv7Vo3RrYy3w E3VM4LcvEJk21EVS07ykZ/Xf/3rd7yVKoDhZoS2WKluodAhmwd/zqUhGOUfJRZWiM4jT 0Sd/wZjz9DOIgzp0r8dJ87827ZmJghvQlK4yjMYRM96CYJodLW7XdJ53fkaf23w1ypfl xbFZ8yDqmAj7uTGIZ0z7d9xn6ZNzLqzB0f5ZDKoN3puRoVGQkEbyAmMUWVrkWtt1N930 4k8g== X-Gm-Message-State: AOAM533m7GyQ5rOb/uXbSvXHDW+xvthlF5jFwvLV7t0kqKEZJsVIkRSn 3qSngZYCui3PjnwFORizbG7AnojhnlSl2g== X-Google-Smtp-Source: ABdhPJy01znyhdsjk8pZCgud43VmfX8M1eYxuQ3nzPQ1kG2PaYoGDfS/cawbLYRNsp0R/53Rtq/GSw== X-Received: by 2002:a17:902:d2c1:b029:128:d851:77fc with SMTP id n1-20020a170902d2c1b0290128d85177fcmr13684513plc.23.1625509833822; Mon, 05 Jul 2021 11:30:33 -0700 (PDT) Received: from birita.. ([177.194.59.218]) by smtp.gmail.com with ESMTPSA id y13sm14311299pgp.16.2021.07.05.11.30.32 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Jul 2021 11:30:33 -0700 (PDT) To: libc-alpha@sourceware.org Subject: [PATCH 1/7] linux: Consolidate Linux getsockopt implementation Date: Mon, 5 Jul 2021 15:30:21 -0300 Message-Id: <20210705183027.3804093-2-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210705183027.3804093-1-adhemerval.zanella@linaro.org> References: <20210705183027.3804093-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-12.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Adhemerval Zanella via Libc-alpha From: Adhemerval Zanella Reply-To: Adhemerval Zanella Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" This patch consolidates the getsockopt Linux syscall implementation on sysdeps/unix/sysv/linux/getsockopt.c. The changes are: 1. Remove it from auto-generation syscalls.list on all architectures. 2. Add __ASSUME_GETSOCKOPT_SYSCALL as default and undef if for specific kernel versions on some architectures. This also fix a potential issue where 32-bit time_t ABI should use the linux getsockopt which overrides the underlying SO_* constants used for socket timestamping for _TIME_BITS=64. Checked on x86_64-linux-gnu and i686-linux-gnu. --- sysdeps/unix/sysv/linux/alpha/syscalls.list | 1 - sysdeps/unix/sysv/linux/arm/syscalls.list | 1 - sysdeps/unix/sysv/linux/generic/syscalls.list | 1 - sysdeps/unix/sysv/linux/hppa/syscalls.list | 1 - sysdeps/unix/sysv/linux/i386/kernel-features.h | 2 +- sysdeps/unix/sysv/linux/ia64/syscalls.list | 1 - sysdeps/unix/sysv/linux/kernel-features.h | 1 + sysdeps/unix/sysv/linux/m68k/kernel-features.h | 2 +- sysdeps/unix/sysv/linux/microblaze/kernel-features.h | 1 - sysdeps/unix/sysv/linux/mips/syscalls.list | 1 - sysdeps/unix/sysv/linux/powerpc/kernel-features.h | 1 - sysdeps/unix/sysv/linux/s390/kernel-features.h | 2 +- sysdeps/unix/sysv/linux/sh/kernel-features.h | 1 - sysdeps/unix/sysv/linux/sparc/kernel-features.h | 2 +- sysdeps/unix/sysv/linux/x86_64/syscalls.list | 1 - 15 files changed, 5 insertions(+), 14 deletions(-) diff --git a/sysdeps/unix/sysv/linux/alpha/syscalls.list b/sysdeps/unix/sysv/linux/alpha/syscalls.list index c848fcbd99..0a39d0871c 100644 --- a/sysdeps/unix/sysv/linux/alpha/syscalls.list +++ b/sysdeps/unix/sysv/linux/alpha/syscalls.list @@ -8,7 +8,6 @@ getpriority - getpriority i:ii __getpriority getpriority bind - bind i:ipi __bind bind getpeername - getpeername i:ipp __getpeername getpeername getsockname - getsockname i:ipp __getsockname getsockname -getsockopt - getsockopt i:iiiBN __getsockopt getsockopt listen - listen i:ii __listen listen setsockopt - setsockopt i:iiibn __setsockopt setsockopt shutdown - shutdown i:ii __shutdown shutdown diff --git a/sysdeps/unix/sysv/linux/arm/syscalls.list b/sysdeps/unix/sysv/linux/arm/syscalls.list index 13441f7eb4..b530057cd8 100644 --- a/sysdeps/unix/sysv/linux/arm/syscalls.list +++ b/sysdeps/unix/sysv/linux/arm/syscalls.list @@ -25,7 +25,6 @@ personality EXTRA personality Ei:i __personality personality bind - bind i:ipi __bind bind getpeername - getpeername i:ipp __getpeername getpeername getsockname - getsockname i:ipp __getsockname getsockname -getsockopt - getsockopt i:iiiBN __getsockopt getsockopt listen - listen i:ii __listen listen setsockopt - setsockopt i:iiibn __setsockopt setsockopt shutdown - shutdown i:ii __shutdown shutdown diff --git a/sysdeps/unix/sysv/linux/generic/syscalls.list b/sysdeps/unix/sysv/linux/generic/syscalls.list index ed8b216d47..7397797571 100644 --- a/sysdeps/unix/sysv/linux/generic/syscalls.list +++ b/sysdeps/unix/sysv/linux/generic/syscalls.list @@ -8,5 +8,4 @@ listen - listen i:ii __listen listen getsockname - getsockname i:ipp __getsockname getsockname getpeername - getpeername i:ipp __getpeername getpeername setsockopt - setsockopt i:iiibn __setsockopt setsockopt -getsockopt - getsockopt i:iiiBN __getsockopt getsockopt shutdown - shutdown i:ii __shutdown shutdown diff --git a/sysdeps/unix/sysv/linux/hppa/syscalls.list b/sysdeps/unix/sysv/linux/hppa/syscalls.list index cd37573b89..2451cc90f1 100644 --- a/sysdeps/unix/sysv/linux/hppa/syscalls.list +++ b/sysdeps/unix/sysv/linux/hppa/syscalls.list @@ -4,7 +4,6 @@ bind - bind i:ipi __bind bind getpeername - getpeername i:ipp __getpeername getpeername getsockname - getsockname i:ipp __getsockname getsockname -getsockopt - getsockopt i:iiiBN __getsockopt getsockopt listen - listen i:ii __listen listen setsockopt - setsockopt i:iiibn __setsockopt setsockopt shutdown - shutdown i:ii __shutdown shutdown diff --git a/sysdeps/unix/sysv/linux/i386/kernel-features.h b/sysdeps/unix/sysv/linux/i386/kernel-features.h index 923fa0b997..a6eca4092d 100644 --- a/sysdeps/unix/sysv/linux/i386/kernel-features.h +++ b/sysdeps/unix/sysv/linux/i386/kernel-features.h @@ -23,7 +23,6 @@ # define __ASSUME_SOCKETPAIR_SYSCALL 1 # define __ASSUME_BIND_SYSCALL 1 # define __ASSUME_LISTEN_SYSCALL 1 -# define __ASSUME_GETSOCKOPT_SYSCALL 1 # define __ASSUME_SETSOCKOPT_SYSCALL 1 # define __ASSUME_GETSOCKNAME_SYSCALL 1 # define __ASSUME_GETPEERNAME_SYSCALL 1 @@ -41,6 +40,7 @@ # undef __ASSUME_CONNECT_SYSCALL # undef __ASSUME_RECVFROM_SYSCALL # undef __ASSUME_SENDTO_SYSCALL +# undef __ASSUME_GETSOCKOPT_SYSCALL #endif /* i686 only supports ipc syscall before 5.1. */ diff --git a/sysdeps/unix/sysv/linux/ia64/syscalls.list b/sysdeps/unix/sysv/linux/ia64/syscalls.list index bd39441d3c..c0e9ea207c 100644 --- a/sysdeps/unix/sysv/linux/ia64/syscalls.list +++ b/sysdeps/unix/sysv/linux/ia64/syscalls.list @@ -6,7 +6,6 @@ getpriority - getpriority i:ii __getpriority getpriority bind - bind i:ipi __bind bind getpeername - getpeername i:ipp __getpeername getpeername getsockname - getsockname i:ipp __getsockname getsockname -getsockopt - getsockopt i:iiiBN __getsockopt getsockopt listen - listen i:ii __listen listen setsockopt - setsockopt i:iiibn __setsockopt setsockopt shutdown - shutdown i:ii __shutdown shutdown diff --git a/sysdeps/unix/sysv/linux/kernel-features.h b/sysdeps/unix/sysv/linux/kernel-features.h index 1680b10ca1..913c3fc222 100644 --- a/sysdeps/unix/sysv/linux/kernel-features.h +++ b/sysdeps/unix/sysv/linux/kernel-features.h @@ -77,6 +77,7 @@ #define __ASSUME_ACCEPT4_SYSCALL 1 #define __ASSUME_RECVMMSG_SYSCALL 1 #define __ASSUME_SENDMMSG_SYSCALL 1 +#define __ASSUME_GETSOCKOPT_SYSCALL 1 /* Support for SysV IPC through wired syscalls. All supported architectures either support ipc syscall and/or all the ipc correspondent syscalls. */ diff --git a/sysdeps/unix/sysv/linux/m68k/kernel-features.h b/sysdeps/unix/sysv/linux/m68k/kernel-features.h index 46bb9d8b26..e1fa35c784 100644 --- a/sysdeps/unix/sysv/linux/m68k/kernel-features.h +++ b/sysdeps/unix/sysv/linux/m68k/kernel-features.h @@ -23,7 +23,6 @@ # define __ASSUME_SOCKETPAIR_SYSCALL 1 # define __ASSUME_BIND_SYSCALL 1 # define __ASSUME_LISTEN_SYSCALL 1 -# define __ASSUME_GETSOCKOPT_SYSCALL 1 # define __ASSUME_SETSOCKOPT_SYSCALL 1 # define __ASSUME_GETSOCKNAME_SYSCALL 1 # define __ASSUME_GETPEERNAME_SYSCALL 1 @@ -43,6 +42,7 @@ # undef __ASSUME_CONNECT_SYSCALL # undef __ASSUME_RECVFROM_SYSCALL # undef __ASSUME_SENDTO_SYSCALL +# undef __ASSUME_GETSOCKOPT_SYSCALL #endif /* No support for PI futexes or robust mutexes before 3.10 for m68k. */ diff --git a/sysdeps/unix/sysv/linux/microblaze/kernel-features.h b/sysdeps/unix/sysv/linux/microblaze/kernel-features.h index 69d8ccaa23..a09a9ea09d 100644 --- a/sysdeps/unix/sysv/linux/microblaze/kernel-features.h +++ b/sysdeps/unix/sysv/linux/microblaze/kernel-features.h @@ -28,7 +28,6 @@ #define __ASSUME_SEND_SYSCALL 1 #define __ASSUME_RECV_SYSCALL 1 #define __ASSUME_SHUTDOWN_SYSCALL 1 -#define __ASSUME_GETSOCKOPT_SYSCALL 1 #define __ASSUME_SETSOCKOPT_SYSCALL 1 #include_next diff --git a/sysdeps/unix/sysv/linux/mips/syscalls.list b/sysdeps/unix/sysv/linux/mips/syscalls.list index f3621cdd51..07e07dec03 100644 --- a/sysdeps/unix/sysv/linux/mips/syscalls.list +++ b/sysdeps/unix/sysv/linux/mips/syscalls.list @@ -15,7 +15,6 @@ sysmips - sysmips i:iiii __sysmips sysmips bind - bind i:ipi __bind bind getpeername - getpeername i:ipp __getpeername getpeername getsockname - getsockname i:ipp __getsockname getsockname -getsockopt - getsockopt i:iiiBN __getsockopt getsockopt listen - listen i:ii __listen listen setsockopt - setsockopt i:iiibn __setsockopt setsockopt shutdown - shutdown i:ii __shutdown shutdown diff --git a/sysdeps/unix/sysv/linux/powerpc/kernel-features.h b/sysdeps/unix/sysv/linux/powerpc/kernel-features.h index c2056959a5..769ef1386d 100644 --- a/sysdeps/unix/sysv/linux/powerpc/kernel-features.h +++ b/sysdeps/unix/sysv/linux/powerpc/kernel-features.h @@ -28,7 +28,6 @@ #define __ASSUME_SEND_SYSCALL 1 #define __ASSUME_RECV_SYSCALL 1 #define __ASSUME_SHUTDOWN_SYSCALL 1 -#define __ASSUME_GETSOCKOPT_SYSCALL 1 #define __ASSUME_SETSOCKOPT_SYSCALL 1 /* Define this if your 32-bit syscall API requires 64-bit register diff --git a/sysdeps/unix/sysv/linux/s390/kernel-features.h b/sysdeps/unix/sysv/linux/s390/kernel-features.h index 724f207e9f..0221a0e0bc 100644 --- a/sysdeps/unix/sysv/linux/s390/kernel-features.h +++ b/sysdeps/unix/sysv/linux/s390/kernel-features.h @@ -23,7 +23,6 @@ # define __ASSUME_SOCKETPAIR_SYSCALL 1 # define __ASSUME_BIND_SYSCALL 1 # define __ASSUME_LISTEN_SYSCALL 1 -# define __ASSUME_GETSOCKOPT_SYSCALL 1 # define __ASSUME_SETSOCKOPT_SYSCALL 1 # define __ASSUME_GETSOCKNAME_SYSCALL 1 # define __ASSUME_GETPEERNAME_SYSCALL 1 @@ -43,6 +42,7 @@ # undef __ASSUME_CONNECT_SYSCALL # undef __ASSUME_RECVFROM_SYSCALL # undef __ASSUME_SENDTO_SYSCALL +# undef __ASSUME_GETSOCKOPT_SYSCALL #endif /* s390 only supports ipc syscall before 5.1. */ diff --git a/sysdeps/unix/sysv/linux/sh/kernel-features.h b/sysdeps/unix/sysv/linux/sh/kernel-features.h index 334e69b0c7..3b0c385260 100644 --- a/sysdeps/unix/sysv/linux/sh/kernel-features.h +++ b/sysdeps/unix/sysv/linux/sh/kernel-features.h @@ -33,7 +33,6 @@ #define __ASSUME_SEND_SYSCALL 1 #define __ASSUME_RECV_SYSCALL 1 #define __ASSUME_SHUTDOWN_SYSCALL 1 -#define __ASSUME_GETSOCKOPT_SYSCALL 1 #define __ASSUME_SETSOCKOPT_SYSCALL 1 #include_next diff --git a/sysdeps/unix/sysv/linux/sparc/kernel-features.h b/sysdeps/unix/sysv/linux/sparc/kernel-features.h index 7ffafc9fd0..0b105eb849 100644 --- a/sysdeps/unix/sysv/linux/sparc/kernel-features.h +++ b/sysdeps/unix/sysv/linux/sparc/kernel-features.h @@ -38,10 +38,10 @@ # undef __ASSUME_CONNECT_SYSCALL # undef __ASSUME_RECVFROM_SYSCALL # undef __ASSUME_SENDTO_SYSCALL +# undef __ASSUME_GETSOCKOPT_SYSCALL #else # define __ASSUME_SOCKET_SYSCALL 1 # define __ASSUME_SOCKETPAIR_SYSCALL 1 -# define __ASSUME_GETSOCKOPT_SYSCALL 1 # define __ASSUME_SHUTDOWN_SYSCALL 1 #endif diff --git a/sysdeps/unix/sysv/linux/x86_64/syscalls.list b/sysdeps/unix/sysv/linux/x86_64/syscalls.list index d46524eff3..fceb6d2415 100644 --- a/sysdeps/unix/sysv/linux/x86_64/syscalls.list +++ b/sysdeps/unix/sysv/linux/x86_64/syscalls.list @@ -9,7 +9,6 @@ syscall_clock_gettime EXTRA clock_gettime Ei:ip __syscall_clock_gettime bind - bind i:ipi __bind bind getpeername - getpeername i:ipp __getpeername getpeername getsockname - getsockname i:ipp __getsockname getsockname -getsockopt - getsockopt i:iiiBN __getsockopt getsockopt listen - listen i:ii __listen listen setsockopt - setsockopt i:iiibn __setsockopt setsockopt shutdown - shutdown i:ii __shutdown shutdown From patchwork Mon Jul 5 18:30:22 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 44156 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 8798C3857C63 for ; Mon, 5 Jul 2021 18:32:33 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8798C3857C63 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1625509953; bh=x3t6+JYmjXmsQGro9jbirYEKh1PnKxOEvJGH3C++kg4=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=DmQznYoIpraAlF7riqUcPXyisbUwEtNhmD7VGScCwrAXE+EXznNUCfmDqWfAkUHOC d3ZoBX2ukTEtRasJrWaBFtlbm6wzd3hu0P4giMSmSjNOyJWUTu+xLZ3jxip6uM7fbm 71ngFYRG7y6ASN+15P2D6QGlaruuF7kFhvZcla+4= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pj1-x1034.google.com (mail-pj1-x1034.google.com [IPv6:2607:f8b0:4864:20::1034]) by sourceware.org (Postfix) with ESMTPS id 5F0753857C63 for ; Mon, 5 Jul 2021 18:30:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 5F0753857C63 Received: by mail-pj1-x1034.google.com with SMTP id 67-20020a17090a0fc9b02901725ed49016so74934pjz.1 for ; Mon, 05 Jul 2021 11:30:36 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=x3t6+JYmjXmsQGro9jbirYEKh1PnKxOEvJGH3C++kg4=; b=nF/5pgdZXwifXR2he+vUQwKfg7BKBz4vBYVFsGKAMKb6BHiSPRzyG/8IKGGVsoWJuD Z6ypi61kMCaQP1/Xi/Uo5C75alr0X6KKoWikAkZl47A8Kw/zFP75akJQ4hUD1zw1/eP7 H3sN5uKAcNoz4H+cdf84XQPMo9QslsafifTQKqo2qJTVC1H95e4Ff2LciEnDKWVXFSQh ck4TGJXGiiAfkx49T5zricFR8K9KFrA9d145fUPn4J085L/1hKuPLwFm0Tmg1lLDjPCx qoSYrajH409iTMbMj89hHUbq+MA4j72l+mS847qYpj8nX5xmNo8D3FHcNjvQHgk206US xSKQ== X-Gm-Message-State: AOAM533PZCoipk0SbFcHcQpnEIU2m3pVD9SZwtsc8kp9vSamWR8+8mAl ljZTAt9YJKU/PIuOsYP8zgScY/IbZTXZ7g== X-Google-Smtp-Source: ABdhPJzYNQiFu9XNhPxWq9Mvin1yYPqeFTWv1tDMUg7Aq57tGLmXItLT3kIn++6HMBBjPBlvsaOVQg== X-Received: by 2002:a17:903:228e:b029:101:af04:4e24 with SMTP id b14-20020a170903228eb0290101af044e24mr13362217plh.3.1625509835238; Mon, 05 Jul 2021 11:30:35 -0700 (PDT) Received: from birita.. ([177.194.59.218]) by smtp.gmail.com with ESMTPSA id y13sm14311299pgp.16.2021.07.05.11.30.34 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Jul 2021 11:30:34 -0700 (PDT) To: libc-alpha@sourceware.org Subject: [PATCH 2/7] linux: Consolidate Linux setsockopt implementation Date: Mon, 5 Jul 2021 15:30:22 -0300 Message-Id: <20210705183027.3804093-3-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210705183027.3804093-1-adhemerval.zanella@linaro.org> References: <20210705183027.3804093-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-12.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Adhemerval Zanella via Libc-alpha From: Adhemerval Zanella Reply-To: Adhemerval Zanella Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" This patch consolidates the setsockopt implementation on sysdeps/unix/sysv/linux/getsockopt.c. The changes are: 1. Remove it from auto-generation syscalls.list on all architectures. 2. Add __ASSUME_SETSOCKOPT_SYSCALL as default and undef if for specific kernel versions on some architectures. This also fix a potential issue where 32-bit time_t ABI should use the linux setsockopt which overrides the underlying SO_* constants used for socket timestamping for _TIME_BITS=64. Checked on x86_64-linux-gnu and i686-linux-gnu. --- sysdeps/unix/sysv/linux/alpha/syscalls.list | 1 - sysdeps/unix/sysv/linux/arm/syscalls.list | 1 - sysdeps/unix/sysv/linux/generic/syscalls.list | 1 - sysdeps/unix/sysv/linux/hppa/syscalls.list | 1 - sysdeps/unix/sysv/linux/i386/kernel-features.h | 2 +- sysdeps/unix/sysv/linux/ia64/syscalls.list | 1 - sysdeps/unix/sysv/linux/kernel-features.h | 1 + sysdeps/unix/sysv/linux/m68k/kernel-features.h | 2 +- sysdeps/unix/sysv/linux/microblaze/kernel-features.h | 1 - sysdeps/unix/sysv/linux/mips/syscalls.list | 1 - sysdeps/unix/sysv/linux/powerpc/kernel-features.h | 1 - sysdeps/unix/sysv/linux/s390/kernel-features.h | 2 +- sysdeps/unix/sysv/linux/sh/kernel-features.h | 1 - sysdeps/unix/sysv/linux/sparc/kernel-features.h | 2 +- sysdeps/unix/sysv/linux/x86_64/syscalls.list | 1 - 15 files changed, 5 insertions(+), 14 deletions(-) diff --git a/sysdeps/unix/sysv/linux/alpha/syscalls.list b/sysdeps/unix/sysv/linux/alpha/syscalls.list index 0a39d0871c..cbfd12588b 100644 --- a/sysdeps/unix/sysv/linux/alpha/syscalls.list +++ b/sysdeps/unix/sysv/linux/alpha/syscalls.list @@ -9,7 +9,6 @@ bind - bind i:ipi __bind bind getpeername - getpeername i:ipp __getpeername getpeername getsockname - getsockname i:ipp __getsockname getsockname listen - listen i:ii __listen listen -setsockopt - setsockopt i:iiibn __setsockopt setsockopt shutdown - shutdown i:ii __shutdown shutdown socket - socket i:iii __socket socket socketpair - socketpair i:iiif __socketpair socketpair diff --git a/sysdeps/unix/sysv/linux/arm/syscalls.list b/sysdeps/unix/sysv/linux/arm/syscalls.list index b530057cd8..10c3ae9dae 100644 --- a/sysdeps/unix/sysv/linux/arm/syscalls.list +++ b/sysdeps/unix/sysv/linux/arm/syscalls.list @@ -26,7 +26,6 @@ bind - bind i:ipi __bind bind getpeername - getpeername i:ipp __getpeername getpeername getsockname - getsockname i:ipp __getsockname getsockname listen - listen i:ii __listen listen -setsockopt - setsockopt i:iiibn __setsockopt setsockopt shutdown - shutdown i:ii __shutdown shutdown socket - socket i:iii __socket socket socketpair - socketpair i:iiif __socketpair socketpair diff --git a/sysdeps/unix/sysv/linux/generic/syscalls.list b/sysdeps/unix/sysv/linux/generic/syscalls.list index 7397797571..f573f27c8b 100644 --- a/sysdeps/unix/sysv/linux/generic/syscalls.list +++ b/sysdeps/unix/sysv/linux/generic/syscalls.list @@ -7,5 +7,4 @@ bind - bind i:ipi __bind bind listen - listen i:ii __listen listen getsockname - getsockname i:ipp __getsockname getsockname getpeername - getpeername i:ipp __getpeername getpeername -setsockopt - setsockopt i:iiibn __setsockopt setsockopt shutdown - shutdown i:ii __shutdown shutdown diff --git a/sysdeps/unix/sysv/linux/hppa/syscalls.list b/sysdeps/unix/sysv/linux/hppa/syscalls.list index 2451cc90f1..043d884bf9 100644 --- a/sysdeps/unix/sysv/linux/hppa/syscalls.list +++ b/sysdeps/unix/sysv/linux/hppa/syscalls.list @@ -5,7 +5,6 @@ bind - bind i:ipi __bind bind getpeername - getpeername i:ipp __getpeername getpeername getsockname - getsockname i:ipp __getsockname getsockname listen - listen i:ii __listen listen -setsockopt - setsockopt i:iiibn __setsockopt setsockopt shutdown - shutdown i:ii __shutdown shutdown socket - socket i:iii __socket socket socketpair - socketpair i:iiif __socketpair socketpair diff --git a/sysdeps/unix/sysv/linux/i386/kernel-features.h b/sysdeps/unix/sysv/linux/i386/kernel-features.h index a6eca4092d..8327f822b0 100644 --- a/sysdeps/unix/sysv/linux/i386/kernel-features.h +++ b/sysdeps/unix/sysv/linux/i386/kernel-features.h @@ -23,7 +23,6 @@ # define __ASSUME_SOCKETPAIR_SYSCALL 1 # define __ASSUME_BIND_SYSCALL 1 # define __ASSUME_LISTEN_SYSCALL 1 -# define __ASSUME_SETSOCKOPT_SYSCALL 1 # define __ASSUME_GETSOCKNAME_SYSCALL 1 # define __ASSUME_GETPEERNAME_SYSCALL 1 # define __ASSUME_SHUTDOWN_SYSCALL 1 @@ -41,6 +40,7 @@ # undef __ASSUME_RECVFROM_SYSCALL # undef __ASSUME_SENDTO_SYSCALL # undef __ASSUME_GETSOCKOPT_SYSCALL +# undef __ASSUME_SETSOCKOPT_SYSCALL #endif /* i686 only supports ipc syscall before 5.1. */ diff --git a/sysdeps/unix/sysv/linux/ia64/syscalls.list b/sysdeps/unix/sysv/linux/ia64/syscalls.list index c0e9ea207c..8aa85fcb02 100644 --- a/sysdeps/unix/sysv/linux/ia64/syscalls.list +++ b/sysdeps/unix/sysv/linux/ia64/syscalls.list @@ -7,7 +7,6 @@ bind - bind i:ipi __bind bind getpeername - getpeername i:ipp __getpeername getpeername getsockname - getsockname i:ipp __getsockname getsockname listen - listen i:ii __listen listen -setsockopt - setsockopt i:iiibn __setsockopt setsockopt shutdown - shutdown i:ii __shutdown shutdown socket - socket i:iii __socket socket socketpair - socketpair i:iiif __socketpair socketpair diff --git a/sysdeps/unix/sysv/linux/kernel-features.h b/sysdeps/unix/sysv/linux/kernel-features.h index 913c3fc222..3930e14322 100644 --- a/sysdeps/unix/sysv/linux/kernel-features.h +++ b/sysdeps/unix/sysv/linux/kernel-features.h @@ -78,6 +78,7 @@ #define __ASSUME_RECVMMSG_SYSCALL 1 #define __ASSUME_SENDMMSG_SYSCALL 1 #define __ASSUME_GETSOCKOPT_SYSCALL 1 +#define __ASSUME_SETSOCKOPT_SYSCALL 1 /* Support for SysV IPC through wired syscalls. All supported architectures either support ipc syscall and/or all the ipc correspondent syscalls. */ diff --git a/sysdeps/unix/sysv/linux/m68k/kernel-features.h b/sysdeps/unix/sysv/linux/m68k/kernel-features.h index e1fa35c784..70f1154559 100644 --- a/sysdeps/unix/sysv/linux/m68k/kernel-features.h +++ b/sysdeps/unix/sysv/linux/m68k/kernel-features.h @@ -23,7 +23,6 @@ # define __ASSUME_SOCKETPAIR_SYSCALL 1 # define __ASSUME_BIND_SYSCALL 1 # define __ASSUME_LISTEN_SYSCALL 1 -# define __ASSUME_SETSOCKOPT_SYSCALL 1 # define __ASSUME_GETSOCKNAME_SYSCALL 1 # define __ASSUME_GETPEERNAME_SYSCALL 1 # define __ASSUME_SHUTDOWN_SYSCALL 1 @@ -43,6 +42,7 @@ # undef __ASSUME_RECVFROM_SYSCALL # undef __ASSUME_SENDTO_SYSCALL # undef __ASSUME_GETSOCKOPT_SYSCALL +# undef __ASSUME_SETSOCKOPT_SYSCALL #endif /* No support for PI futexes or robust mutexes before 3.10 for m68k. */ diff --git a/sysdeps/unix/sysv/linux/microblaze/kernel-features.h b/sysdeps/unix/sysv/linux/microblaze/kernel-features.h index a09a9ea09d..a8fbc67384 100644 --- a/sysdeps/unix/sysv/linux/microblaze/kernel-features.h +++ b/sysdeps/unix/sysv/linux/microblaze/kernel-features.h @@ -28,7 +28,6 @@ #define __ASSUME_SEND_SYSCALL 1 #define __ASSUME_RECV_SYSCALL 1 #define __ASSUME_SHUTDOWN_SYSCALL 1 -#define __ASSUME_SETSOCKOPT_SYSCALL 1 #include_next diff --git a/sysdeps/unix/sysv/linux/mips/syscalls.list b/sysdeps/unix/sysv/linux/mips/syscalls.list index 07e07dec03..d99504774c 100644 --- a/sysdeps/unix/sysv/linux/mips/syscalls.list +++ b/sysdeps/unix/sysv/linux/mips/syscalls.list @@ -16,7 +16,6 @@ bind - bind i:ipi __bind bind getpeername - getpeername i:ipp __getpeername getpeername getsockname - getsockname i:ipp __getsockname getsockname listen - listen i:ii __listen listen -setsockopt - setsockopt i:iiibn __setsockopt setsockopt shutdown - shutdown i:ii __shutdown shutdown socket - socket i:iii __socket socket socketpair - socketpair i:iiif __socketpair socketpair diff --git a/sysdeps/unix/sysv/linux/powerpc/kernel-features.h b/sysdeps/unix/sysv/linux/powerpc/kernel-features.h index 769ef1386d..6c04e187ce 100644 --- a/sysdeps/unix/sysv/linux/powerpc/kernel-features.h +++ b/sysdeps/unix/sysv/linux/powerpc/kernel-features.h @@ -28,7 +28,6 @@ #define __ASSUME_SEND_SYSCALL 1 #define __ASSUME_RECV_SYSCALL 1 #define __ASSUME_SHUTDOWN_SYSCALL 1 -#define __ASSUME_SETSOCKOPT_SYSCALL 1 /* Define this if your 32-bit syscall API requires 64-bit register pairs to start with an even-number register. */ diff --git a/sysdeps/unix/sysv/linux/s390/kernel-features.h b/sysdeps/unix/sysv/linux/s390/kernel-features.h index 0221a0e0bc..4757e9eb02 100644 --- a/sysdeps/unix/sysv/linux/s390/kernel-features.h +++ b/sysdeps/unix/sysv/linux/s390/kernel-features.h @@ -23,7 +23,6 @@ # define __ASSUME_SOCKETPAIR_SYSCALL 1 # define __ASSUME_BIND_SYSCALL 1 # define __ASSUME_LISTEN_SYSCALL 1 -# define __ASSUME_SETSOCKOPT_SYSCALL 1 # define __ASSUME_GETSOCKNAME_SYSCALL 1 # define __ASSUME_GETPEERNAME_SYSCALL 1 # define __ASSUME_SHUTDOWN_SYSCALL 1 @@ -43,6 +42,7 @@ # undef __ASSUME_RECVFROM_SYSCALL # undef __ASSUME_SENDTO_SYSCALL # undef __ASSUME_GETSOCKOPT_SYSCALL +# undef __ASSUME_SETSOCKOPT_SYSCALL #endif /* s390 only supports ipc syscall before 5.1. */ diff --git a/sysdeps/unix/sysv/linux/sh/kernel-features.h b/sysdeps/unix/sysv/linux/sh/kernel-features.h index 3b0c385260..15f5cc2c85 100644 --- a/sysdeps/unix/sysv/linux/sh/kernel-features.h +++ b/sysdeps/unix/sysv/linux/sh/kernel-features.h @@ -33,7 +33,6 @@ #define __ASSUME_SEND_SYSCALL 1 #define __ASSUME_RECV_SYSCALL 1 #define __ASSUME_SHUTDOWN_SYSCALL 1 -#define __ASSUME_SETSOCKOPT_SYSCALL 1 #include_next diff --git a/sysdeps/unix/sysv/linux/sparc/kernel-features.h b/sysdeps/unix/sysv/linux/sparc/kernel-features.h index 0b105eb849..2c28393647 100644 --- a/sysdeps/unix/sysv/linux/sparc/kernel-features.h +++ b/sysdeps/unix/sysv/linux/sparc/kernel-features.h @@ -39,6 +39,7 @@ # undef __ASSUME_RECVFROM_SYSCALL # undef __ASSUME_SENDTO_SYSCALL # undef __ASSUME_GETSOCKOPT_SYSCALL +# undef __ASSUME_SETSOCKOPT_SYSCALL #else # define __ASSUME_SOCKET_SYSCALL 1 # define __ASSUME_SOCKETPAIR_SYSCALL 1 @@ -49,7 +50,6 @@ #if __LINUX_KERNEL_VERSION >= 0x040400 # define __ASSUME_BIND_SYSCALL 1 # define __ASSUME_LISTEN_SYSCALL 1 -# define __ASSUME_SETSOCKOPT_SYSCALL 1 #endif #ifdef __arch64__ diff --git a/sysdeps/unix/sysv/linux/x86_64/syscalls.list b/sysdeps/unix/sysv/linux/x86_64/syscalls.list index fceb6d2415..4ce5913a86 100644 --- a/sysdeps/unix/sysv/linux/x86_64/syscalls.list +++ b/sysdeps/unix/sysv/linux/x86_64/syscalls.list @@ -10,7 +10,6 @@ bind - bind i:ipi __bind bind getpeername - getpeername i:ipp __getpeername getpeername getsockname - getsockname i:ipp __getsockname getsockname listen - listen i:ii __listen listen -setsockopt - setsockopt i:iiibn __setsockopt setsockopt shutdown - shutdown i:ii __shutdown shutdown socket - socket i:iii __socket socket socketpair - socketpair i:iiif __socketpair socketpair From patchwork Mon Jul 5 18:30:23 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 44157 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 2DADA383D809 for ; Mon, 5 Jul 2021 18:33:18 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2DADA383D809 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1625509998; bh=M959oLHOsWUnb+QZaQhzbtvyYoqosgBDi0yHHfJeh1E=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=fhPX2co2css9MWhxJacC4KyB0FJLE6GeuoHzu2BnVX1g3kJBkeyITByajBJ8xw6Nj YJDmCH/ysH+HEVxWsT/pG4/4aElO7ILWWiGvXLnvbgMxgB/5e9lm6RUjod1apoTaiz VkH6ZD0WsXI84ExncZ0hYMHqnB5a55x2h1UtAr8Q= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pg1-x536.google.com (mail-pg1-x536.google.com [IPv6:2607:f8b0:4864:20::536]) by sourceware.org (Postfix) with ESMTPS id 7B1263853804 for ; Mon, 5 Jul 2021 18:30:37 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 7B1263853804 Received: by mail-pg1-x536.google.com with SMTP id o18so18409187pgu.10 for ; Mon, 05 Jul 2021 11:30:37 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=M959oLHOsWUnb+QZaQhzbtvyYoqosgBDi0yHHfJeh1E=; b=MEBkUJdE/bRznqFw5LQrEC1g1zPm9MgNaF7He9CA+Une7/ItzcG26yUstFkkgVR5PQ JCreaxGaTj9bn3LKdHlSohZoSlzwY1pH0znZl417deFohL8l/OqbVrYQ/ZKxKkW93sfE lFi9DcvCUjP5Z5PDUW2WMNQfzRc3GaO8a8KeBUn+mW2SdR+aWJZICiCEew9sgET4wUiZ SuUKAc1oOE9iz/51z2sEMozFpPmNlJljHtVk3gED6T9AWQ9yGaXq6PNtOlP5IRpc31qx Sx+40aCYCTt5lVibboIvn17Wju37I7HLsA3xfmVk8y6cPMh3fmDJ3PeIKRFNexucdZq3 qkIg== X-Gm-Message-State: AOAM533DYaAlCvRWDoYQKXA3P/VsM7mP5fY4Y2T02iYRQvbNWrR34qd2 f9ohHtiF3CxN2z8qLLJ0IMiE0oE59jo4LA== X-Google-Smtp-Source: ABdhPJyY+pMxmiI6fQsikfWtOLGT03/PBmX+9soihr8dGJQGld3dUQ2Jnrh+y3WlQKxihaYKMFP+RA== X-Received: by 2002:a05:6a00:9a5:b029:30d:fad7:4515 with SMTP id u37-20020a056a0009a5b029030dfad74515mr16582719pfg.28.1625509836498; Mon, 05 Jul 2021 11:30:36 -0700 (PDT) Received: from birita.. ([177.194.59.218]) by smtp.gmail.com with ESMTPSA id y13sm14311299pgp.16.2021.07.05.11.30.35 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Jul 2021 11:30:36 -0700 (PDT) To: libc-alpha@sourceware.org Subject: [PATCH 3/7] linux: Use the expected size for SO_TIMESTAMP{NS} convertion Date: Mon, 5 Jul 2021 15:30:23 -0300 Message-Id: <20210705183027.3804093-4-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210705183027.3804093-1-adhemerval.zanella@linaro.org> References: <20210705183027.3804093-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-12.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Adhemerval Zanella via Libc-alpha From: Adhemerval Zanella Reply-To: Adhemerval Zanella Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" Kernel returns 32-bit values for COMPAT_SO_TIMESTAMP{NS}_OLD, no 64-bit ones. Checked on x86_64-linux-gnu and i686-linux-gnu. --- sysdeps/unix/sysv/linux/convert_scm_timestamps.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/sysdeps/unix/sysv/linux/convert_scm_timestamps.c b/sysdeps/unix/sysv/linux/convert_scm_timestamps.c index 5af71847f5..2db5750f50 100644 --- a/sysdeps/unix/sysv/linux/convert_scm_timestamps.c +++ b/sysdeps/unix/sysv/linux/convert_scm_timestamps.c @@ -44,7 +44,8 @@ __convert_scm_timestamps (struct msghdr *msg, socklen_t msgsize) 'struct __kernel_sock_timeval' while for SO_TIMESTAMPNS_NEW is a 'struct __kernel_timespec'. In either case it is two uint64_t members. */ - uint64_t tvts[2]; + int64_t tvts[2]; + int32_t tmp; struct cmsghdr *cmsg, *last = NULL; int type = 0; @@ -69,7 +70,10 @@ __convert_scm_timestamps (struct msghdr *msg, socklen_t msgsize) /* fallthrough */ common: - memcpy (tvts, CMSG_DATA (cmsg), sizeof (tvts)); + memcpy (&tmp, CMSG_DATA (cmsg), sizeof (tmp)); + tvts[0] = tmp; + memcpy (&tmp, CMSG_DATA (cmsg) + sizeof (tmp), sizeof (tmp)); + tvts[1] = tmp; break; } From patchwork Mon Jul 5 18:30:24 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 44158 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A26E2383F43B for ; Mon, 5 Jul 2021 18:34:02 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A26E2383F43B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1625510042; bh=1l5dexN4Z2QL0l6VfWwezxj0WzvZBFAw1MYl/+/P12c=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=ZFJV6LxTKVhuTnlDHLPDOq+PoyIm2MFuC8xbFujCDi7s7LiR4IuHZcCvMMaTnMKDW 1ElLQfqPNUrOSzNMOXNrwkLPf17RdhSt/lPgEQeNeQFhe3poPFxWxFSci/MC4Jotw4 6J2TfV7ivCrk4XrHUoB+ZhA1LuHrDaYBT5+merts= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pj1-x1031.google.com (mail-pj1-x1031.google.com [IPv6:2607:f8b0:4864:20::1031]) by sourceware.org (Postfix) with ESMTPS id CB7B5383F415 for ; Mon, 5 Jul 2021 18:30:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org CB7B5383F415 Received: by mail-pj1-x1031.google.com with SMTP id p17-20020a17090b0111b02901723ab8d11fso420701pjz.1 for ; Mon, 05 Jul 2021 11:30:38 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=1l5dexN4Z2QL0l6VfWwezxj0WzvZBFAw1MYl/+/P12c=; b=S1PKTbZNsOtqRVRWE+1KKgZbUUol2VzFhKXDiSjupACjdBH+naTsuOjbfG3FB31KAe xOcqXUi8iEZyiHyoHbay2YE5GrxP/Ezo4KAOyp4bEvDIwbZMEVnyWQaNs0YOYLXeqzAb bCpqrnDHunNL++OnHALklhIcE/45L860Z6HLAIEpYwe7ZHFEXKN/JJuu/pjMoVjz2iKC x5IwnS/Md7DJ4GAtAIJ59KR6yJlD7qbzhvBiR9HBi7iWHa6gw67MTscMrG9wxWsTrVET p5c35CT8fO1X2jXnj+QwapG1EPy5Rc5IWMNTADfowVl5OxmOfX/41XHSKG/ZaM2PLxXV JoIQ== X-Gm-Message-State: AOAM5312QJQEAlFyrpRY6B8aaur3fec4ao8zaPniVHxnR26uX2np/NPC 3oxcON7f3bRSR98SKCNLDikCmkpchFXvfg== X-Google-Smtp-Source: ABdhPJx0pP7hhRgAWniQE0rP8ym0E/AQru+qrQg9lqLRPhtgeHXuA9Akkyb45wQDwZhSBzUplmpnfQ== X-Received: by 2002:a17:90b:430f:: with SMTP id ih15mr411012pjb.56.1625509837798; Mon, 05 Jul 2021 11:30:37 -0700 (PDT) Received: from birita.. ([177.194.59.218]) by smtp.gmail.com with ESMTPSA id y13sm14311299pgp.16.2021.07.05.11.30.36 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Jul 2021 11:30:37 -0700 (PDT) To: libc-alpha@sourceware.org Subject: [PATCH 4/7] linux: Fix setsockopt fallback Date: Mon, 5 Jul 2021 15:30:24 -0300 Message-Id: <20210705183027.3804093-5-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210705183027.3804093-1-adhemerval.zanella@linaro.org> References: <20210705183027.3804093-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-12.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Adhemerval Zanella via Libc-alpha From: Adhemerval Zanella Reply-To: Adhemerval Zanella Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" The final 2 arguments for SO_TIMESTAMP/SO_TIMESTAMPNS are being set wrongly. Checked on x86_64-linux-gnu and i686-linux-gnu. --- sysdeps/unix/sysv/linux/setsockopt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sysdeps/unix/sysv/linux/setsockopt.c b/sysdeps/unix/sysv/linux/setsockopt.c index a4780a9d33..fae7305c9d 100644 --- a/sysdeps/unix/sysv/linux/setsockopt.c +++ b/sysdeps/unix/sysv/linux/setsockopt.c @@ -78,7 +78,7 @@ setsockopt32 (int fd, int level, int optname, const void *optval, optname = COMPAT_SO_TIMESTAMP_OLD; if (optname == COMPAT_SO_TIMESTAMPNS_NEW) optname = COMPAT_SO_TIMESTAMPNS_OLD; - r = setsockopt_syscall (fd, level, optname, NULL, 0); + r = setsockopt_syscall (fd, level, optname, optval, len); } break; } From patchwork Mon Jul 5 18:30:25 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 44159 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 53A1B383D837 for ; Mon, 5 Jul 2021 18:34:47 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 53A1B383D837 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1625510087; bh=DVlT4WaDTxx6Ux8eRh5dlOkk6nWRcd14OvgiwGvPyik=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=vQ3GltWFl6cD6LzrNgZJkd8hXfDDCxSNSD6AWxNqGXIWRT7oUtnl0e063LVvr6NHL tTgNwJSFO/t+EUxZycy2OEYEy09mMGYch/NWNgxDVrfbuEvUl39Z4pxrbxAxyvRv1+ lh0/DXT0IfsE7ltj2q4lvcSY6aRangG3O48TrgqI= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pj1-x1036.google.com (mail-pj1-x1036.google.com [IPv6:2607:f8b0:4864:20::1036]) by sourceware.org (Postfix) with ESMTPS id 1F717383F415 for ; Mon, 5 Jul 2021 18:30:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 1F717383F415 Received: by mail-pj1-x1036.google.com with SMTP id b14-20020a17090a7aceb029017261c7d206so53664pjl.5 for ; Mon, 05 Jul 2021 11:30:40 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=DVlT4WaDTxx6Ux8eRh5dlOkk6nWRcd14OvgiwGvPyik=; b=IIFdZRvmv7q2nLc9SC1ghh/wOQ17Kqt8kB3YQm6IrLArFX5RPaYub3MbyY6DLzz63v ItUbnQXOMYMghVVmrOsQmTZtX2j4+AupopP6TQ6Dy6gvVUKnpKXIHWQznFKWGUhyM+qM A9hItczGbxD9kbojVY/tgG1RshMjG8iTSMejNEJJNWEERnFU/uI4Uz+60yCmnwW+SNkL xEyZKE40L3ZyXKToJCXQnClAfkzFA5c2Cm7UbCyz3zHZH0ww7PrqFBH/S08av7PsSROI 3iLgkNkVjIHf7So3/v027GpDNGdAeYpbAA2lnLLZYUgV7zgSDhWUJWpd2jdYbPjZyRwk +lUg== X-Gm-Message-State: AOAM533HC27NbaMcETg2hTNPnc81tOqbT1LhPWy6jknpaJN7lMuXCkV4 UKMrerIduSpJyujhYu6iCgE+VQ6A7DFFgg== X-Google-Smtp-Source: ABdhPJxOJUk04ewUANVb0vvF2rlVU4JUd3fKOVkuhY4SkP2wnfX1AbYlY54INCpimjGWfNVNkPFMqg== X-Received: by 2002:a17:90a:5306:: with SMTP id x6mr16328906pjh.59.1625509839100; Mon, 05 Jul 2021 11:30:39 -0700 (PDT) Received: from birita.. ([177.194.59.218]) by smtp.gmail.com with ESMTPSA id y13sm14311299pgp.16.2021.07.05.11.30.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Jul 2021 11:30:38 -0700 (PDT) To: libc-alpha@sourceware.org Subject: [PATCH 5/7] support: Add support_socket_time64_timestamp Date: Mon, 5 Jul 2021 15:30:25 -0300 Message-Id: <20210705183027.3804093-6-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210705183027.3804093-1-adhemerval.zanella@linaro.org> References: <20210705183027.3804093-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-12.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Adhemerval Zanella via Libc-alpha From: Adhemerval Zanella Reply-To: Adhemerval Zanella Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" Check if the socket support 64-bit network packages timestamps (SO_TIMESTAMP and SO_TIMESTAMPNS). This will be used on recvmsg and recvmmsg tests to check if the timestamp should be generated. --- support/Makefile | 1 + support/support.h | 3 + support/support_socket_time64_timestamp.c | 68 +++++++++++++++++++++++ 3 files changed, 72 insertions(+) create mode 100644 support/support_socket_time64_timestamp.c diff --git a/support/Makefile b/support/Makefile index 5c69f0de4b..7659357b28 100644 --- a/support/Makefile +++ b/support/Makefile @@ -76,6 +76,7 @@ libsupport-routines = \ support_set_small_thread_stack_size \ support_shared_allocate \ support_small_stack_thread_attribute \ + support_socket_time64_timestamp \ support_stat_nanoseconds \ support_subprocess \ support_test_compare_blob \ diff --git a/support/support.h b/support/support.h index 9ec8ecb8d7..bf74a2584b 100644 --- a/support/support.h +++ b/support/support.h @@ -154,6 +154,9 @@ extern bool support_select_modifies_timeout (void); tv_usec larger than 1000000. */ extern bool support_select_normalizes_timeout (void); +/* Return true if socket FD supports 64-bit timestamps. */ +extern bool support_socket_time64_timestamp (int fd); + /* Create a timer that trigger after SEC seconds and NSEC nanoseconds. If REPEAT is true the timer will repeat indefinitely. If CALLBACK is not NULL, the function will be called when the timer expires; otherwise a diff --git a/support/support_socket_time64_timestamp.c b/support/support_socket_time64_timestamp.c new file mode 100644 index 0000000000..2d5af65471 --- /dev/null +++ b/support/support_socket_time64_timestamp.c @@ -0,0 +1,68 @@ +/* Return whether socket supports 64-bit timestamps. + Copyright (C) 2021 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#include +#include +#include +#include +#include + +#ifdef __linux__ +# include + +static int +__attribute_used__ +setsockopt_syscall (int fd, int enable) +{ + int level = SOL_SOCKET; + int optname = COMPAT_SO_TIMESTAMP_NEW; + int optval = enable; + + int r = syscall (__NR_setsockopt, fd, level, optname, &optval, + sizeof (optval)); +# ifdef __NR_setsockopt + if (r == -1 && errno == ENOSYS) + { + long int args[] = { fd, level, optname, (long int) &optval, + sizeof (optval) }; + r = syscall (__NR_setsockopt, 14 /* SOCKOP_setsockopt */ , args); + } +# endif + return r; +} +#endif + +bool +support_socket_time64_timestamp (int fd) +{ +#ifdef __linux__ +# if __LINUX_KERNEL_VERSION >= 0x050100 \ + || __WORDSIZE == 64 \ + || (defined __SYSCALL_WORDSIZE && __SYSCALL_WORDSIZE == 64) + return true; +# else + int r = setsockopt_syscall (fd, 1); + if (r == -1 && errno == ENOPROTOOPT) + return false; + setsockopt_syscall (fd, 0); + return true; +# endif +#else + return false; +#endif +} From patchwork Mon Jul 5 18:30:26 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 44160 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id BBF18383F43B for ; Mon, 5 Jul 2021 18:35:31 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BBF18383F43B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1625510131; bh=uvGQWPPMvyLJL0UR3sdOnw/hxYGasGfl5+2Q/DQOl04=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=bKKWdRkHzpzSzhr39QU8uZUn7IBXNqXVjL/HWeySApWk+N8wnJRIgjGsF9mw00rZ5 oSmkQNPt1NLEfTd+2sMUVueflXRhaHrpWzNzRMnd2Xo8eQZmHlyACrucjzZLmGJ/av eULhydQmywr9dSjxQrRDCERcSSfNGYhA2hCz52aQ= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pj1-x1034.google.com (mail-pj1-x1034.google.com [IPv6:2607:f8b0:4864:20::1034]) by sourceware.org (Postfix) with ESMTPS id 72EC5383E80A for ; Mon, 5 Jul 2021 18:30:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 72EC5383E80A Received: by mail-pj1-x1034.google.com with SMTP id p17-20020a17090b0111b02901723ab8d11fso420752pjz.1 for ; Mon, 05 Jul 2021 11:30:41 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=uvGQWPPMvyLJL0UR3sdOnw/hxYGasGfl5+2Q/DQOl04=; b=c/TdYGpWUmRyp8LGCQuec3CNwKZiq9jU+3ATZPPHDqmEM/tIZDYR3SYQComlj3E0sa YuSQ0/QuXoclrCzpwgw+/17ax0HrjL+VbS9OBwkXFfi25P+aRxR8Wbk9OULRbbdtM4zs RNwY+ee9jsV8FmIb4dUBBJk0A3pI5BEQNdKqsF7paGLAJEa++6N53sqvwdDUrEr/xg1o 3XUZLtuOVaKTuvjwRrzDQeJPgl5Xibr7J10S6TQAxen/nwFONuuxEf7puSEeehEK5Js1 3zBMoM9Tq+ncrbbOtGTrl53wTj6DbA/ADcEfL27kljFQse1DGlsDgA55z8XdezonZDHL kkFA== X-Gm-Message-State: AOAM530Wl9dPSPv7JtqbrXgSB2+r8kKSEo+TLpjFKNCYeelEdl2Ti3PT HEeRfRYDrk/QqfO45y2Uv5YPwaX49gonYw== X-Google-Smtp-Source: ABdhPJzdMVcKFNPWQI7ubkPzO2p7EHdvOPBTTwdQ6IkyAlKa2qiswOJi06Vqdrs2b8FEDb4jDZf/VQ== X-Received: by 2002:a17:90a:f2d7:: with SMTP id gt23mr371450pjb.21.1625509840350; Mon, 05 Jul 2021 11:30:40 -0700 (PDT) Received: from birita.. ([177.194.59.218]) by smtp.gmail.com with ESMTPSA id y13sm14311299pgp.16.2021.07.05.11.30.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Jul 2021 11:30:40 -0700 (PDT) To: libc-alpha@sourceware.org Subject: [PATCH 6/7] socket: Add recvmsg timestamp test Date: Mon, 5 Jul 2021 15:30:26 -0300 Message-Id: <20210705183027.3804093-7-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210705183027.3804093-1-adhemerval.zanella@linaro.org> References: <20210705183027.3804093-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-12.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Adhemerval Zanella via Libc-alpha From: Adhemerval Zanella Reply-To: Adhemerval Zanella Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" The test check if SO_TIMESTAMP and SO_TIMESTAMPNS is correctly generated. The recvmsg() is called with different ancilliary data buffers, to check if the conversion for 64-bit time on 32-bit legacy ABIs are handled correctly. For such archicutures, depending of the remmaning ancially data space the timestamp can not be appended and MSG_TRUNC is returned instead. Checked on x86_64-linux and on i686-linux-gnu on both 5.11 and 4.15 kernel. --- sysdeps/unix/sysv/linux/Makefile | 3 + sysdeps/unix/sysv/linux/tst-recvmsg-time64.c | 1 + sysdeps/unix/sysv/linux/tst-recvmsg.c | 171 +++++++++++++++++++ 3 files changed, 175 insertions(+) create mode 100644 sysdeps/unix/sysv/linux/tst-recvmsg-time64.c create mode 100644 sysdeps/unix/sysv/linux/tst-recvmsg.c diff --git a/sysdeps/unix/sysv/linux/Makefile b/sysdeps/unix/sysv/linux/Makefile index faea02bd1b..be6fe08ac2 100644 --- a/sysdeps/unix/sysv/linux/Makefile +++ b/sysdeps/unix/sysv/linux/Makefile @@ -237,6 +237,9 @@ sysdep_routines += cmsg_nxthdr CFLAGS-recvmmsg.c = -fexceptions -fasynchronous-unwind-tables CFLAGS-sendmmsg.c = -fexceptions -fasynchronous-unwind-tables +tests += tst-recvmsg +tests-time64 += tst-recvmsg-time64 + tests-special += $(objpfx)tst-socket-consts.out $(objpfx)tst-socket-consts.out: ../sysdeps/unix/sysv/linux/tst-socket-consts.py PYTHONPATH=../scripts \ diff --git a/sysdeps/unix/sysv/linux/tst-recvmsg-time64.c b/sysdeps/unix/sysv/linux/tst-recvmsg-time64.c new file mode 100644 index 0000000000..6cc8bbff6b --- /dev/null +++ b/sysdeps/unix/sysv/linux/tst-recvmsg-time64.c @@ -0,0 +1 @@ +#include "tst-recvmsg.c" diff --git a/sysdeps/unix/sysv/linux/tst-recvmsg.c b/sysdeps/unix/sysv/linux/tst-recvmsg.c new file mode 100644 index 0000000000..361dcbb8cc --- /dev/null +++ b/sysdeps/unix/sysv/linux/tst-recvmsg.c @@ -0,0 +1,171 @@ +/* Check recvmsg timestamp support. + Copyright (C) 2021 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/* Some extra space added for ancillary data, it might be used to convert + 32-bit timestamp to 64-bit for _TIME_BITS=64 on older kernels. */ +static const int slack[] = { 0, 4, 8, 16, 32, 64 }; + +static size_t pagesize; + +static int +do_test_send (const struct sockaddr_in *addr, int nmsgs) +{ + int s = xsocket (AF_INET, SOCK_DGRAM | SOCK_CLOEXEC, 0); + xconnect (s, (const struct sockaddr *) addr, sizeof (*addr)); + + for (int i = 0; i < nmsgs; i++) + xsendto (s, &i, sizeof (i), 0, (const struct sockaddr *) addr, + sizeof (*addr)); + + return 0; +} + +static void +do_recvmsg (int s, bool support_64_timestamp, void *cmsg, size_t slack, + size_t tsize, int exp_msg) +{ + /* A timestamp is expected if 32-bit timestamp are used (support in every + configuration) or if underlying kernel support 64-bit timestamps. + Otherwise recvmsg will need extra space do add the 64-bit timestamp. */ + bool exp_timestamp; + if (sizeof (time_t) == 4 || support_64_timestamp) + exp_timestamp = true; + else + exp_timestamp = slack >= CMSG_SPACE (tsize); + + int msg; + struct iovec iov = + { + .iov_base = &msg, + .iov_len = sizeof (msg) + }; + size_t msgs = CMSG_SPACE (tsize) + slack; + struct msghdr msghdr = + { + .msg_name = NULL, + .msg_namelen = 0, + .msg_iov = &iov, + .msg_iovlen = 1, + .msg_controllen = msgs, + .msg_control = cmsg != NULL ? cmsg + pagesize - msgs : NULL, + }; + TEST_COMPARE (recvmsg (s, &msghdr, 0), sizeof (int)); + TEST_COMPARE (msg, exp_msg); + + if (cmsg == NULL) + return; + + int timestamp = false; + for (struct cmsghdr *cmsg = CMSG_FIRSTHDR (&msghdr); + cmsg != NULL; + cmsg = CMSG_NXTHDR (&msghdr, cmsg)) + { + if (cmsg->cmsg_level != SOL_SOCKET) + continue; + if (cmsg->cmsg_type == SCM_TIMESTAMP + && cmsg->cmsg_len == CMSG_LEN (sizeof (struct timeval))) + { + struct timeval tv; + memcpy (&tv, CMSG_DATA (cmsg), sizeof (tv)); + printf ("SCM_TIMESTAMP: {%jd, %jd}\n", (intmax_t)tv.tv_sec, + (intmax_t)tv.tv_usec); + timestamp = true; + } + else if (cmsg->cmsg_type == SCM_TIMESTAMPNS + && cmsg->cmsg_len == CMSG_LEN (sizeof (struct timespec))) + { + struct timespec ts; + memcpy (&ts, CMSG_DATA (cmsg), sizeof (ts)); + printf ("SCM_TIMESTAMPNS: {%jd, %jd}\n", (intmax_t)ts.tv_sec, + (intmax_t)ts.tv_nsec); + timestamp = true; + } + } + + /* If there is not timestamp in the ancilliary data, recvmsg should set + the flag inidcating it. */ + if (exp_timestamp && !timestamp) + TEST_VERIFY (msghdr.msg_flags & MSG_TRUNC); + else + TEST_COMPARE (exp_timestamp, timestamp); +} + +static int +do_test (void) +{ + int srv = xsocket (AF_INET, SOCK_DGRAM, 0); + struct sockaddr_in srv_addr = + { + .sin_family = AF_INET, + .sin_addr = {.s_addr = htonl (INADDR_LOOPBACK) }, + }; + xbind (srv, (struct sockaddr *) &srv_addr, sizeof (srv_addr)); + { + socklen_t sa_len = sizeof (srv_addr); + xgetsockname (srv, (struct sockaddr *) &srv_addr, &sa_len); + TEST_VERIFY (sa_len == sizeof (srv_addr)); + } + + TEST_COMPARE (recvmsg (-1, NULL, 0), -1); + TEST_COMPARE (errno, EBADF); + + /* Setup the ancillary data buffer with an extra page with PROT_NONE to + check the possible timestamp conversion on some systems. */ + pagesize = sysconf (_SC_PAGESIZE); + if (pagesize == -1) + FAIL_EXIT1 ("sysconf (_SC_PAGESIZE): %m\n"); + void *msgbuf = xmmap (0, 2 * pagesize, PROT_NONE, + MAP_ANONYMOUS | MAP_PRIVATE, -1); + xmprotect (msgbuf, pagesize, PROT_READ | PROT_WRITE); + + do_test_send (&srv_addr, 1); + do_recvmsg (srv, false, NULL, 0, 0, 0); + + /* If underlying kernel does not support */ + bool support_64_timestamp = support_socket_time64_timestamp (srv); + + /* Enable the timestamp using struct timeval precision. */ + xsetsockopt (srv, SOL_SOCKET, SO_TIMESTAMP, &(int){1}, sizeof (int)); + do_test_send (&srv_addr, array_length (slack)); + for (int s = 0; s < array_length (slack); s++) + do_recvmsg (srv, support_64_timestamp, msgbuf, slack[s], + sizeof (struct timeval), s); + + /* Now enable timestamp using a higher precision, it overwrites the previous + precision. */ + xsetsockopt (srv, SOL_SOCKET, SO_TIMESTAMPNS, &(int){1}, sizeof (int)); + do_test_send (&srv_addr, array_length (slack)); + for (int s = 0; s < array_length (slack); s++) + do_recvmsg (srv, support_64_timestamp, msgbuf, slack[s], + sizeof (struct timespec), s); + + return 0; +} + +#include From patchwork Mon Jul 5 18:30:27 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 44161 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 7AB5D383D028 for ; Mon, 5 Jul 2021 18:36:22 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7AB5D383D028 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1625510182; bh=/KoU7Cah9tNOqACzTmKUq1JYozWoISuKyxqokqXeZSc=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=YXoN4h4QMUEoBCv2lM6OeU/YwS+EHN6nFFlIqszFdeQtWjryoUfVSVuyxRCppnu0I 22M7A5LP+VKnDH7pgeP1h3bUKyG3EQoxz3DyoicYQ2lsuDiVYf4jt0F+9Eafc7AX6Q SO69IgaYBXTcwHv16eK+7hmOvPRdSsWeRZF8YByc= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pj1-x102d.google.com (mail-pj1-x102d.google.com [IPv6:2607:f8b0:4864:20::102d]) by sourceware.org (Postfix) with ESMTPS id 080AA383D805 for ; Mon, 5 Jul 2021 18:30:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 080AA383D805 Received: by mail-pj1-x102d.google.com with SMTP id 67-20020a17090a0fc9b02901725ed49016so75076pjz.1 for ; Mon, 05 Jul 2021 11:30:42 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=/KoU7Cah9tNOqACzTmKUq1JYozWoISuKyxqokqXeZSc=; b=dVMgvlgaQ71zSqn7NGyIwHA3BmpvCY+YURv0prVpHEyA3wqnf9crL/Q61G71iU2OmI 6JYLsPKWCHtBgT+inp6CMO1TD/eZ+d+x/oc8mvBOql2MPryb5gS/jlvXOPlOtT4fvyyy slHqFNj5WMZaWt/o6Tg/fb/3d7YdCaPVNxth1ypRXu5Tj3gQhOjytPu+TXER355Y0veO k0S48DMpVmgeH1D4k48pHJSPY0iqeACB+Va8Np2poIqxEm98geBP/TlP72cmrndf7s7D YZvnI1nw32pZ5oe246LTDraQcA+G43AgAUlSqtboibSpNfvIgGB8JQ8OovX2CwRlYxeN kWeA== X-Gm-Message-State: AOAM533q7FEVOwQ2YJOo5OZiYKJLFHw1MYMpa4Nxffv7yVr15Ea600ap D3juh3fNRVmQstZTVRssd+V2oMd6xV7SpA== X-Google-Smtp-Source: ABdhPJxThoauPk0CPHe8+EfNfqltFntLtZGoHRclqwxVZ8rZLynnHsj4xq2eWeLTRt01wnORclolyQ== X-Received: by 2002:a17:90a:73ca:: with SMTP id n10mr404704pjk.16.1625509841807; Mon, 05 Jul 2021 11:30:41 -0700 (PDT) Received: from birita.. ([177.194.59.218]) by smtp.gmail.com with ESMTPSA id y13sm14311299pgp.16.2021.07.05.11.30.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Jul 2021 11:30:41 -0700 (PDT) To: libc-alpha@sourceware.org Subject: [PATCH 7/7] socket: Add recvmmsg timestamp test Date: Mon, 5 Jul 2021 15:30:27 -0300 Message-Id: <20210705183027.3804093-8-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210705183027.3804093-1-adhemerval.zanella@linaro.org> References: <20210705183027.3804093-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-12.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Adhemerval Zanella via Libc-alpha From: Adhemerval Zanella Reply-To: Adhemerval Zanella Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" The test check if SO_TIMESTAMP and SO_TIMESTAMPNS is correctly generated. The recvmsg() is called with different ancilliary data buffers, to check if the conversion for 64-bit time on 32-bit legacy ABIs are handled correctly. For such archicutures, depending of the remmaning ancially data space the timestamp can not be appended and MSG_TRUNC is returned instead. Checked on x86_64-linux and on i686-linux-gnu on both 5.11 and 4.15 kernel. --- sysdeps/unix/sysv/linux/Makefile | 4 +- sysdeps/unix/sysv/linux/tst-recvmmsg-time64.c | 1 + sysdeps/unix/sysv/linux/tst-recvmmsg.c | 185 ++++++++++++++++++ 3 files changed, 188 insertions(+), 2 deletions(-) create mode 100644 sysdeps/unix/sysv/linux/tst-recvmmsg-time64.c create mode 100644 sysdeps/unix/sysv/linux/tst-recvmmsg.c diff --git a/sysdeps/unix/sysv/linux/Makefile b/sysdeps/unix/sysv/linux/Makefile index be6fe08ac2..74a8d865b2 100644 --- a/sysdeps/unix/sysv/linux/Makefile +++ b/sysdeps/unix/sysv/linux/Makefile @@ -237,8 +237,8 @@ sysdep_routines += cmsg_nxthdr CFLAGS-recvmmsg.c = -fexceptions -fasynchronous-unwind-tables CFLAGS-sendmmsg.c = -fexceptions -fasynchronous-unwind-tables -tests += tst-recvmsg -tests-time64 += tst-recvmsg-time64 +tests += tst-recvmsg tst-recvmmsg +tests-time64 += tst-recvmsg-time64 tst-recvmmsg-time64 tests-special += $(objpfx)tst-socket-consts.out $(objpfx)tst-socket-consts.out: ../sysdeps/unix/sysv/linux/tst-socket-consts.py diff --git a/sysdeps/unix/sysv/linux/tst-recvmmsg-time64.c b/sysdeps/unix/sysv/linux/tst-recvmmsg-time64.c new file mode 100644 index 0000000000..7b9b1bea03 --- /dev/null +++ b/sysdeps/unix/sysv/linux/tst-recvmmsg-time64.c @@ -0,0 +1 @@ +#include "tst-recvmmsg.c" diff --git a/sysdeps/unix/sysv/linux/tst-recvmmsg.c b/sysdeps/unix/sysv/linux/tst-recvmmsg.c new file mode 100644 index 0000000000..012b364434 --- /dev/null +++ b/sysdeps/unix/sysv/linux/tst-recvmmsg.c @@ -0,0 +1,185 @@ +/* Check recvmmsg timestamp support. + Copyright (C) 2021 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/* Some extra space added for ancillary data, it might be used to convert + 32-bit timestamp to 64-bit for _TIME_BITS=64 on older kernels. */ +static const int slack[] = { 0, 4, 8, 16, 32, 64 }; + +static size_t pagesize; + +static int +do_test_send (const struct sockaddr_in *addr, int nmsgs) +{ + int s = xsocket (AF_INET, SOCK_DGRAM | SOCK_CLOEXEC, 0); + xconnect (s, (const struct sockaddr *) addr, sizeof (*addr)); + + for (int i = 0; i < nmsgs; i++) + xsendto (s, &i, sizeof (i), 0, (const struct sockaddr *) addr, + sizeof (*addr)); + + return 0; +} + +#define NMSGS 5 + +static void +do_recvmmsg (int s, bool support_64_timestamp, void *cmsg[], size_t slack, + size_t tsize) +{ + /* A timestamp is expected if 32-bit timestamp are used (support in every + configuration) or if underlying kernel support 64-bit timestamps. + Otherwise recvmsg will need extra space do add the 64-bit timestamp. */ + bool exp_timestamp; + if (sizeof (time_t) == 4 || support_64_timestamp) + exp_timestamp = true; + else + exp_timestamp = slack >= CMSG_SPACE (tsize); + + int msg[5]; + struct iovec iov[NMSGS]; + for (int i = 0; i < NMSGS; i++) + { + iov[i].iov_base = &msg[i]; + iov[i].iov_len = sizeof (msg[i]); + } + struct mmsghdr msghdr[NMSGS]; + size_t msgs = CMSG_SPACE (tsize + slack); + for (int i = 0; i < NMSGS; i++) + { + msghdr[i].msg_hdr.msg_name = NULL; + msghdr[i].msg_hdr.msg_namelen = 0; + msghdr[i].msg_hdr.msg_iov = &iov[i]; + msghdr[i].msg_hdr.msg_iovlen = 1; + msghdr[i].msg_hdr.msg_controllen = msgs, + msghdr[i].msg_hdr.msg_control = cmsg[i] != NULL + ? cmsg[i] + pagesize - msgs : NULL; + } + + TEST_COMPARE (recvmmsg (s, msghdr, NMSGS, 0, NULL), NMSGS); + for (int i = 0; i < NMSGS; i++) + { + if (msghdr[i].msg_len == 0) + continue; + + TEST_COMPARE (msg[i], i); + + int timestamp = false; + for (struct cmsghdr *cmsg = CMSG_FIRSTHDR (&msghdr[i].msg_hdr); + cmsg != NULL; + cmsg = CMSG_NXTHDR (&msghdr[i].msg_hdr, cmsg)) + { + if (cmsg->cmsg_level != SOL_SOCKET) + continue; + if (cmsg->cmsg_type == SCM_TIMESTAMP + && cmsg->cmsg_len == CMSG_LEN (sizeof (struct timeval))) + { + struct timeval tv; + memcpy (&tv, CMSG_DATA (cmsg), sizeof (tv)); + printf ("SCM_TIMESTAMP: {%jd, %jd}\n", (intmax_t)tv.tv_sec, + (intmax_t)tv.tv_usec); + timestamp = true; + } + else if (cmsg->cmsg_type == SCM_TIMESTAMPNS + && cmsg->cmsg_len == CMSG_LEN (sizeof (struct timespec))) + { + struct timespec ts; + memcpy (&ts, CMSG_DATA (cmsg), sizeof (ts)); + printf ("SCM_TIMESTAMPNS: {%jd, %jd}\n", (intmax_t)ts.tv_sec, + (intmax_t)ts.tv_nsec); + timestamp = true; + } + } + + /* If there is not timestamp in the ancilliary data, recvmsg should set + the flag inidcating it. */ + if (exp_timestamp && !timestamp) + TEST_VERIFY (msghdr[i].msg_hdr.msg_flags & MSG_TRUNC); + else + TEST_COMPARE (exp_timestamp, timestamp); + } +} + +static int +do_test (void) +{ + int srv = xsocket (AF_INET, SOCK_DGRAM, 0); + struct sockaddr_in srv_addr = + { + .sin_family = AF_INET, + .sin_addr = {.s_addr = htonl (INADDR_LOOPBACK) }, + }; + xbind (srv, (struct sockaddr *) &srv_addr, sizeof (srv_addr)); + { + socklen_t sa_len = sizeof (srv_addr); + xgetsockname (srv, (struct sockaddr *) &srv_addr, &sa_len); + TEST_VERIFY (sa_len == sizeof (srv_addr)); + } + + TEST_COMPARE (recvmmsg (-1, NULL, 0, 0, NULL), -1); + TEST_COMPARE (errno, EBADF); + + /* Setup the ancillary data buffer with an extra page with PROT_NONE to + check the possible timestamp conversion on some systems. */ + pagesize = sysconf (_SC_PAGESIZE); + if (pagesize == -1) + FAIL_EXIT1 ("sysconf (_SC_PAGESIZE): %m\n"); + void *msgbuf[NMSGS]; + for (int i = 0; i < NMSGS; i++) + { + msgbuf[i] = xmmap (0, 2 * pagesize, PROT_NONE, + MAP_ANONYMOUS | MAP_PRIVATE, -1); + xmprotect (msgbuf[i], pagesize, PROT_READ | PROT_WRITE); + } + + /* If underlying kernel does not support */ + bool support_64_timestamp = support_socket_time64_timestamp (srv); + + /* Enable the timestamp using struct timeval precision. */ + xsetsockopt (srv, SOL_SOCKET, SO_TIMESTAMP, &(int){1}, sizeof (int)); + for (int s = 0; s < array_length (slack); s++) + { + do_test_send (&srv_addr, NMSGS); + do_recvmmsg (srv, support_64_timestamp, msgbuf, slack[s], + sizeof (struct timeval)); + } + + /* Now enable timestamp using a higher precision, it overwrites the previous + precision. */ + xsetsockopt (srv, SOL_SOCKET, SO_TIMESTAMPNS, &(int){1}, sizeof (int)); + for (int s = 0; s < array_length (slack); s++) + { + do_test_send (&srv_addr, NMSGS); + do_recvmmsg (srv, support_64_timestamp, msgbuf, slack[s], + sizeof (struct timespec)); + } + + return 0; +} + +#include