From patchwork Tue Sep 8 14:57:38 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 40381 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 70B7739518B8; Tue, 8 Sep 2020 14:58:07 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 70B7739518B8 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1599577087; bh=r2pGEFiLQAIX8Ms8hii/Q13lFfm//DnkGt0JbQUavzY=; 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=DQ793HMF0RsU/jUcnV8krZoZa4RwhHh9MU8W0/GyQUZ1vNxGWrcI+zOztdddcJ3UU 5a7eLbdNiMNTHe2kjz9Le/VG7d4eHxvx/AE3FQJuzwdTb0wG1NYBqcTCgMCwbzvNYN xmuhUIUtzTmn4K6XZ1XBgxICCz31jCOyiFQptVnE= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-qv1-xf41.google.com (mail-qv1-xf41.google.com [IPv6:2607:f8b0:4864:20::f41]) by sourceware.org (Postfix) with ESMTPS id 70C173951C3A for ; Tue, 8 Sep 2020 14:58:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 70C173951C3A Received: by mail-qv1-xf41.google.com with SMTP id j3so7934745qvi.7 for ; Tue, 08 Sep 2020 07:58:05 -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=r2pGEFiLQAIX8Ms8hii/Q13lFfm//DnkGt0JbQUavzY=; b=p70eShUZTdYt8SDc3swjnLcNzbkLHR/GyOfQecepLd9jIgRadPPass3V9LTrGLLmJa wGqUg6dsck5JOP0uif6vmX/b3EHqjPws2dV20wMY7eR5sd6eEa1hDg+/F9spA1yWsA7X hoOcGkAvBAiCza4qFVIPMY150Wa1QRcHzAYiGHRr0zLbEzazpInMuqx7a7WZRLmV9m8B 8qFj1psf966PS8nlt5WXVp8o+eGfUBI6uQf1NwYCsz7uKcY5RNv3/EDjXU8DXg8Tt+Wx bonkAwNuiQEAX0pnCaRNewEbOu3tJEBMTEGduziyV8i8RmP+K9SQKBAjlrCnXR7JrHK6 w45Q== X-Gm-Message-State: AOAM530aUBa1YeDLuFtyoB0fcGgqwXP0BHz9R7DMD6zAA704LJyFb0Uh GKszKHcmekOjR1xdJ6BO4am6H5wFNRbMKQ== X-Google-Smtp-Source: ABdhPJxIWcUZwK88AGSrLXiQ4bpsmZ34C815KFCkSZD71lF5uYmRxrgux+KRtWG9b0YD6ik4kTas7w== X-Received: by 2002:a0c:eeca:: with SMTP id h10mr464545qvs.13.1599577084789; Tue, 08 Sep 2020 07:58:04 -0700 (PDT) Received: from localhost.localdomain ([177.194.48.209]) by smtp.googlemail.com with ESMTPSA id e188sm10800748qkd.55.2020.09.08.07.58.03 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Sep 2020 07:58:04 -0700 (PDT) To: libc-alpha@sourceware.org Subject: [RFC 14/14] linux: Add recvvmsg fallback for 64-bit time_t SO_TIMESTAMP{NS} Date: Tue, 8 Sep 2020 11:57:38 -0300 Message-Id: <20200908145738.640039-14-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200908145738.640039-1-adhemerval.zanella@linaro.org> References: <20200908145738.640039-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-13.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.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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 Netto Reply-To: Adhemerval Zanella Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" Handle the SO_TIMESTAMP{NS} similar to recvmsg: for !__ASSUME_TIME64_SYSCALLS it converts the first 32-bit time SO_TIMESTAMP or SO_TIMESTAMPNS and appends it to the control buffer if has extra space or returns MSG_CTRUNC otherwise. The 32-bit time field is kept as-is. Also for !__ASSUME_TIME64_SYSCALLS it limits the maximum number of 'struct mmsghdr *' to IOV_MAX (and also increases the stack size requirement to IOV_MAX times sizeof (socklen_t)). The Linux imposes a similar limit to sendmmsg, so bound the array size on recvmmsg is not unreasonable. And this will be used only on older when building with 32-bit time support. Checked on x86_64-linux-gnu and i686-linux-gnu (on 5.4 and on 4.15 kernel). --- include/sys/socket.h | 3 +++ sysdeps/unix/sysv/linux/recvmmsg.c | 17 +++++++++++++++-- sysdeps/unix/sysv/linux/recvmsg.c | 6 +++--- 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/include/sys/socket.h b/include/sys/socket.h index c551c8fa87..171440ab14 100644 --- a/include/sys/socket.h +++ b/include/sys/socket.h @@ -171,6 +171,9 @@ libc_hidden_proto (__libc_sa_len) #define SCM_TIMESTAMPNS_NEW SO_TIMESTAMPNS_NEW #define SCM_TIMESTAMPING_NEW SO_TIMESTAMPING_NEW +extern void __convert_scm_timestamps (struct msghdr *msg, socklen_t msgsize) + attribute_hidden; + libc_hidden_proto (__cmsg_nxthdr) #endif diff --git a/sysdeps/unix/sysv/linux/recvmmsg.c b/sysdeps/unix/sysv/linux/recvmmsg.c index a29c91fb76..0f67e2dcac 100644 --- a/sysdeps/unix/sysv/linux/recvmmsg.c +++ b/sysdeps/unix/sysv/linux/recvmmsg.c @@ -44,13 +44,26 @@ __recvmmsg64 (int fd, struct mmsghdr *vmessages, unsigned int vlen, int flags, ts32 = valid_timespec64_to_timespec (*timeout); pts32 = &ts32; } + + socklen_t csize[IOV_MAX]; + if (vlen > IOV_MAX) + vlen = IOV_MAX; + for (int i = 0; i < vlen; i++) + csize[i] = vmessages[i].msg_hdr.msg_controllen; + # ifdef __ASSUME_RECVMMSG_SYSCALL r = SYSCALL_CANCEL (recvmmsg, fd, vmessages, vlen, flags, pts32); # else r = SOCKETCALL_CANCEL (recvmmsg, fd, vmessages, vlen, flags, pts32); # endif - if (r >= 0 && timeout != NULL) - *timeout = valid_timespec_to_timespec64 (ts32); + if (r >= 0) + { + if (timeout != NULL) + *timeout = valid_timespec_to_timespec64 (ts32); + + for (int i=0; i < r; i++) + __convert_scm_timestamps (&vmessages[i].msg_hdr, csize[i]); + } #endif /* __ASSUME_TIME64_SYSCALLS */ return r; } diff --git a/sysdeps/unix/sysv/linux/recvmsg.c b/sysdeps/unix/sysv/linux/recvmsg.c index c6d1d10b05..510ed04ea5 100644 --- a/sysdeps/unix/sysv/linux/recvmsg.c +++ b/sysdeps/unix/sysv/linux/recvmsg.c @@ -32,8 +32,8 @@ original message as a spurious control ones of unknown typ while running on kernel with native 64-bit time support will only see the time64 version of the control message. */ -static void -convert_scm_timestamps (struct msghdr *msg, socklen_t msgsize) +void +__convert_scm_timestamps (struct msghdr *msg, socklen_t msgsize) { if (msg->msg_control == NULL || msg->msg_controllen == 0) return; @@ -108,7 +108,7 @@ __libc_recvmsg (int fd, struct msghdr *msg, int flags) #ifndef __ASSUME_TIME64_SYSCALLS if (r >= 0) - convert_scm_timestamps (msg, orig_controllen); + __convert_scm_timestamps (msg, orig_controllen); #endif return r;