From patchwork Fri Jul 31 19:06:35 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filip Bozuta X-Patchwork-Id: 11695395 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id F2B611392 for ; Fri, 31 Jul 2020 19:07:55 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id BA7C722B42 for ; Fri, 31 Jul 2020 19:07:55 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=syrmia.com header.i=@syrmia.com header.b="sLwp23nb" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org BA7C722B42 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=syrmia.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:54538 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1k1aNn-00085F-0q for patchwork-qemu-devel@patchwork.kernel.org; Fri, 31 Jul 2020 15:07:55 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38360) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k1aMy-0006WN-Ay for qemu-devel@nongnu.org; Fri, 31 Jul 2020 15:07:04 -0400 Received: from mail-am6eur05on2132.outbound.protection.outlook.com ([40.107.22.132]:59583 helo=EUR05-AM6-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k1aMu-0002Mw-UJ for qemu-devel@nongnu.org; Fri, 31 Jul 2020 15:07:04 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=HQF06dGXuwBWfCIfJu31+wjoJZisan6i+AhUTcMmA1JxucEiwFmCvkQFSlM2QPNNizduZSyLIM96Jm/G1yhEYzyqZU3Nt5ZKUngRScrnkKJoH7Lq1BsTbMLCSe4S/Bs95SIBzAhf0YL4QkO11HdDwq4z4o/Uk37ByVitWiVh4xH4P9+Q3ydvHKYr7II1BBwd4Y4PDETJG8JchE9Ed3hASD4KDLDZhqWxf/82cOa1qyJe2MMaRJ1pD/cMNKkth2R67KUhKt6vv/aBSOhkqWXW+F8tA1W8zlGd+v/5D69/LaMoIzGjgw1DFf8PoHY2gSlz/tTUNImnx94CyPOBUtewqg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=ns52SGx06j5UyEtQx51dsg4ZQZ94lRnc89aUFbqthqI=; b=mIhrd1MsJgUZo3HrbA46iWZUfvMPwWVuw/HxnbKHbiV0BUWJoGosBpQep3V+MFuQz58v3/jOVb9SjU3dEc2gsE+2ADTaStBrmQx+5regW1WHEUTnFhKvXx15RXakhJ6/qCpSjxnjG1zo8JZEGw4DNg3XqORAqGz1FtwHQiS+LxLzrgPRh4mggGBz2kTpcLo9k7TbsRWG0HCGWetO5ARAGtMoMliDdyRF5Skz++tcnmP6vKwk1moGMtYEIsoyBfTafpmk9QmNrsU3WXZmRogzFtsJ1jXr0fuDQqjVPpMjiZI5dYbzHXTmIUo9GzxwwPccDnQPHXjx1b55X+P+uVOWxg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=syrmia.com; dmarc=pass action=none header.from=syrmia.com; dkim=pass header.d=syrmia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=syrmia.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=ns52SGx06j5UyEtQx51dsg4ZQZ94lRnc89aUFbqthqI=; b=sLwp23nbGKS1Hl5z7IevFv575AG1PQFsAce4HuZ7odPaIbKZpLNeo84WafL0c0l3V43RbKu0/50547JEbGIAIF1jLZ552insb7L6sisjaWy01itrlSX+PF4Wi5Pd83YoeoqQXPE6qaY+dPiwnlTlZxOZAfBkx3XaLMipFiTqGgI= Authentication-Results: nongnu.org; dkim=none (message not signed) header.d=none;nongnu.org; dmarc=none action=none header.from=syrmia.com; Received: from AM6PR03MB5233.eurprd03.prod.outlook.com (2603:10a6:20b:d1::19) by AM5PR03MB2884.eurprd03.prod.outlook.com (2603:10a6:206:1a::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3216.26; Fri, 31 Jul 2020 19:06:52 +0000 Received: from AM6PR03MB5233.eurprd03.prod.outlook.com ([fe80::98f0:b948:78a8:f618]) by AM6PR03MB5233.eurprd03.prod.outlook.com ([fe80::98f0:b948:78a8:f618%7]) with mapi id 15.20.3239.020; Fri, 31 Jul 2020 19:06:52 +0000 From: Filip Bozuta To: qemu-devel@nongnu.org Subject: [PATCH 1/3] linux-user: Modify 'sendmmsg()' and 'recvmmsg()' implementation Date: Fri, 31 Jul 2020 21:06:35 +0200 Message-Id: <20200731190637.66698-2-Filip.Bozuta@syrmia.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200731190637.66698-1-Filip.Bozuta@syrmia.com> References: <20200731190637.66698-1-Filip.Bozuta@syrmia.com> X-ClientProxiedBy: ZR0P278CA0002.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:16::12) To AM6PR03MB5233.eurprd03.prod.outlook.com (2603:10a6:20b:d1::19) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from localhost.localdomain (147.91.217.235) by ZR0P278CA0002.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:16::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3239.17 via Frontend Transport; Fri, 31 Jul 2020 19:06:51 +0000 X-Mailer: git-send-email 2.25.1 X-Originating-IP: [147.91.217.235] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: cdb00de4-d512-400d-ba19-08d83584e26d X-MS-TrafficTypeDiagnostic: AM5PR03MB2884: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:8882; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: WRvJmvQyE/YlXE19FG4EYiTkSX/zx6D5qPdpYpHQWWlNoIEQ5kvKuBBP8u4CoJF8JGx7hVrtqVtohvEtonVdNgwERVnNTRcJQgqyotLpV3pmy0hpkxn7HmNuGeW7Gm3tWTb0KYKyRHJJGEDyY968N+SDGPLSKJVM/z/MbaAek1WozSylaiCh74p4kdhaJk5FLNk49TFQgKk1dK1l2uNYBQz1Aq3fUYCTkw39wUYP+IBqwWgXv3hSXPungjgefxPWtLPWLME6CkoZhSylpIe0yTTgLmKycKwPXnx/xe1IhCRLJ04jcEPGJzYEph3z70ACG9HdcKf2tQ1bVBzvSwmkLyyYCceOTjRnOzx7LRoIcS3dqPMx28r/opF9PY8wZ4my X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM6PR03MB5233.eurprd03.prod.outlook.com; PTR:; CAT:NONE; SFTY:; SFS:(396003)(39830400003)(376002)(346002)(366004)(136003)(6506007)(26005)(66556008)(186003)(6486002)(107886003)(66946007)(69590400007)(2616005)(66476007)(54906003)(6512007)(8676002)(2906002)(36756003)(4326008)(16526019)(5660300002)(52116002)(316002)(6666004)(83380400001)(86362001)(508600001)(956004)(6916009)(8936002)(1076003); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData: twUN+WVmIX7I1mhHj8/itRMIut60ZmXrZoJitgfP84KT2nsmv7A/Ce8iJOglX9qNPzWWnPV7dTDzLJgDE/4fPqu2qzf3XXo7yAtnDnYBMsR+ghsygoAalQ5FopXJHTSeC56Aelajw8+yEMJgSDlzhi19hZEoFcNxle2FO4EnD2Y9rpVrb1RvAgQ3enNDn3VcTfQX5yK9b3irJP3TaIs3oHqED387GpD5rTqfnVp8NBrpNH7Qc0utvpI21s8UDCpInWJHtYF13iFVYmOHXnDAMs/5ineElVJUxfjwRCr+cQCR/cqgbLu+bBE8hv1GiYybCQntKwlQpeUigKrTkwrMTFN7sRNU1Xjjjlf4jz+pTzOzFcLImEtZLFVES3hN79+hukIUCIzlh3nZ9XXGHJjRo248KJVLlXuk9zRqYWj7KHdF6wLgm4gdlMSHSGRjOX6pnMdTu5r6VKC8bolbSq1jSX5IIp0r7tW2iPpTAIQ0g7Q= X-OriginatorOrg: syrmia.com X-MS-Exchange-CrossTenant-Network-Message-Id: cdb00de4-d512-400d-ba19-08d83584e26d X-MS-Exchange-CrossTenant-AuthSource: AM6PR03MB5233.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 Jul 2020 19:06:52.6221 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 19214a73-c1ab-4e19-8f59-14bdcb09a66e X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 43H3yDZdqhKfBLT2VXESX720ysaJtdSrVdRp6S+BMZzrUkJ/LvkarA/EGoHepROE0NkGg/Hr3fhWo5t27F/0UQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM5PR03MB2884 Received-SPF: pass client-ip=40.107.22.132; envelope-from=Filip.Bozuta@syrmia.com; helo=EUR05-AM6-obe.outbound.protection.outlook.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/07/31 15:06:59 X-ACL-Warn: Detected OS = Windows NT kernel [generic] [fuzzy] X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-1, RCVD_IN_SORBS_WEB=1.5, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Riku Voipio , Laurent Vivier , Filip Bozuta Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" Implementations of 'sendmmsg()' and 'recvmmsg()' in 'syscall.c' use a loop over a host command of 'sendmsg()' and 'recvmsg()' respectively to send/receive individual messages from a socket. This patch changes these implementations to use the host commands 'sendmmsg()' and 'recvmmsg()' to send all messages without looping over 'sendmsg()' and 'recvmsg()'. Implementation notes: Parts of code from 'do_sendrecvmsg_locked()', that are used to transfer values of 'struct msghdr' between host and target, were moved to separate functions 'target_to_host_msghdr()' and 'host_to_target_msghdr()'. These functions are used in 'do_sendrecvmmsg()' to transfer the data of each individual 'struct msghdr' from the 'msgvec' argument. Memory allocation for the 'iovec' field is done outside of these functions as to ensure that the memory is freed after the syscall execution. Signed-off-by: Filip Bozuta --- linux-user/syscall.c | 243 ++++++++++++++++++++++++++++--------------- 1 file changed, 159 insertions(+), 84 deletions(-) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 05f03919ff..8cbefdb561 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -798,6 +798,10 @@ safe_syscall6(ssize_t, recvfrom, int, fd, void *, buf, size_t, len, int, flags, struct sockaddr *, addr, socklen_t *, addrlen) safe_syscall3(ssize_t, sendmsg, int, fd, const struct msghdr *, msg, int, flags) safe_syscall3(ssize_t, recvmsg, int, fd, struct msghdr *, msg, int, flags) +safe_syscall4(int, sendmmsg, int, fd, struct mmsghdr *, msgvec, + unsigned int, vlen, int, flags) +safe_syscall5(int, recvmmsg, int, fd, struct mmsghdr *, msgvec, + unsigned int, vlen, int, flags, struct timespec *, timeout) safe_syscall2(int, flock, int, fd, int, operation) #ifdef TARGET_NR_rt_sigtimedwait safe_syscall4(int, rt_sigtimedwait, const sigset_t *, these, siginfo_t *, uinfo, @@ -3064,41 +3068,94 @@ static abi_long do_connect(int sockfd, abi_ulong target_addr, return get_errno(safe_connect(sockfd, addr, addrlen)); } -/* do_sendrecvmsg_locked() Must return target values and target errnos. */ -static abi_long do_sendrecvmsg_locked(int fd, struct target_msghdr *msgp, - int flags, int send) +static abi_long target_to_host_msghdr(int fd, struct msghdr *host_msg, + struct target_msghdr *target_msg, + int send) { - abi_long ret, len; - struct msghdr msg; - abi_ulong count; - struct iovec *vec; - abi_ulong target_vec; - - if (msgp->msg_name) { - msg.msg_namelen = tswap32(msgp->msg_namelen); - msg.msg_name = alloca(msg.msg_namelen+1); - ret = target_to_host_sockaddr(fd, msg.msg_name, - tswapal(msgp->msg_name), - msg.msg_namelen); + abi_long ret = 0; + if (target_msg->msg_name) { + host_msg->msg_namelen = tswap32(target_msg->msg_namelen); + host_msg->msg_name = alloca(host_msg->msg_namelen + 1); + ret = target_to_host_sockaddr(fd, host_msg->msg_name, + tswapal(target_msg->msg_name), + host_msg->msg_namelen); if (ret == -TARGET_EFAULT) { - /* For connected sockets msg_name and msg_namelen must + /* + * For connected sockets msg_name and msg_namelen must * be ignored, so returning EFAULT immediately is wrong. * Instead, pass a bad msg_name to the host kernel, and * let it decide whether to return EFAULT or not. */ - msg.msg_name = (void *)-1; + host_msg->msg_name = (void *)-1; + ret = 0; } else if (ret) { - goto out2; + return ret; } } else { - msg.msg_name = NULL; - msg.msg_namelen = 0; + host_msg->msg_name = NULL; + host_msg->msg_namelen = 0; + } + host_msg->msg_controllen = 2 * tswapal(target_msg->msg_controllen); + host_msg->msg_control = alloca(host_msg->msg_controllen); + memset(host_msg->msg_control, 0, host_msg->msg_controllen); + host_msg->msg_flags = tswap32(target_msg->msg_flags); + if (send) { + if (fd_trans_target_to_host_data(fd)) { + void *host_iov_base; + + host_iov_base = g_malloc(host_msg->msg_iov->iov_len); + memcpy(host_iov_base, host_msg->msg_iov->iov_base, + host_msg->msg_iov->iov_len); + ret = fd_trans_target_to_host_data(fd)(host_iov_base, + host_msg->msg_iov->iov_len); + if (ret >= 0) { + host_msg->msg_iov->iov_base = host_iov_base; + ret = 0; + } + g_free(host_iov_base); + } else { + ret = target_to_host_cmsg(host_msg, target_msg); + } + } + return ret; +} + +static abi_long host_to_target_msghdr(int fd, struct target_msghdr *target_msg, + struct msghdr *host_msg, int len) +{ + abi_long ret; + + if (fd_trans_host_to_target_data(fd)) { + ret = fd_trans_host_to_target_data(fd)(host_msg->msg_iov->iov_base, + MIN(host_msg->msg_iov->iov_len, len)); + } else { + ret = host_to_target_cmsg(target_msg, host_msg); + } + if (!is_error(ret)) { + target_msg->msg_namelen = tswap32(host_msg->msg_namelen); + target_msg->msg_flags = tswap32(host_msg->msg_flags); + if (host_msg->msg_name != NULL && host_msg->msg_name != (void *)-1) { + ret = host_to_target_sockaddr(tswapal(target_msg->msg_name), + host_msg->msg_name, host_msg->msg_namelen); + if (ret) { + return ret; + } + } + ret = len; } - msg.msg_controllen = 2 * tswapal(msgp->msg_controllen); - msg.msg_control = alloca(msg.msg_controllen); - memset(msg.msg_control, 0, msg.msg_controllen); - msg.msg_flags = tswap32(msgp->msg_flags); + return ret; +} + +/* do_sendrecvmsg_locked() Must return target values and target errnos. */ +static abi_long do_sendrecvmsg_locked(int fd, struct target_msghdr *msgp, + int flags, int send) +{ + abi_long ret; + struct msghdr msg; + abi_ulong count; + struct iovec *vec; + abi_ulong target_vec; count = tswapal(msgp->msg_iovlen); target_vec = tswapal(msgp->msg_iov); @@ -3120,48 +3177,18 @@ static abi_long do_sendrecvmsg_locked(int fd, struct target_msghdr *msgp, msg.msg_iovlen = count; msg.msg_iov = vec; - if (send) { - if (fd_trans_target_to_host_data(fd)) { - void *host_msg; + ret = target_to_host_msghdr(fd, &msg, msgp, send); - host_msg = g_malloc(msg.msg_iov->iov_len); - memcpy(host_msg, msg.msg_iov->iov_base, msg.msg_iov->iov_len); - ret = fd_trans_target_to_host_data(fd)(host_msg, - msg.msg_iov->iov_len); - if (ret >= 0) { - msg.msg_iov->iov_base = host_msg; - ret = get_errno(safe_sendmsg(fd, &msg, flags)); - } - g_free(host_msg); - } else { - ret = target_to_host_cmsg(&msg, msgp); - if (ret == 0) { - ret = get_errno(safe_sendmsg(fd, &msg, flags)); - } - } + if (ret) { + goto out; + } + + if (send) { + ret = get_errno(safe_sendmsg(fd, &msg, flags)); } else { ret = get_errno(safe_recvmsg(fd, &msg, flags)); if (!is_error(ret)) { - len = ret; - if (fd_trans_host_to_target_data(fd)) { - ret = fd_trans_host_to_target_data(fd)(msg.msg_iov->iov_base, - MIN(msg.msg_iov->iov_len, len)); - } else { - ret = host_to_target_cmsg(msgp, &msg); - } - if (!is_error(ret)) { - msgp->msg_namelen = tswap32(msg.msg_namelen); - msgp->msg_flags = tswap32(msg.msg_flags); - if (msg.msg_name != NULL && msg.msg_name != (void *)-1) { - ret = host_to_target_sockaddr(tswapal(msgp->msg_name), - msg.msg_name, msg.msg_namelen); - if (ret) { - goto out; - } - } - - ret = len; - } + ret = host_to_target_msghdr(fd, msgp, &msg, ret); } } @@ -3188,50 +3215,98 @@ static abi_long do_sendrecvmsg(int fd, abi_ulong target_msg, return ret; } -/* We don't rely on the C library to have sendmmsg/recvmmsg support, - * so it might not have this *mmsg-specific flag either. - */ -#ifndef MSG_WAITFORONE -#define MSG_WAITFORONE 0x10000 -#endif - -static abi_long do_sendrecvmmsg(int fd, abi_ulong target_msgvec, +static abi_long do_sendrecvmmsg(int fd, abi_ulong target_msgvec_addr, unsigned int vlen, unsigned int flags, int send) { - struct target_mmsghdr *mmsgp; + struct mmsghdr *host_msgvec; + struct target_mmsghdr *target_msgvec; abi_long ret = 0; + int num_sentrecv = 0; + int num_iovec = 0; + abi_ulong iovlen = 0; + struct iovec *host_iovec; + abi_ulong target_iovec; int i; if (vlen > UIO_MAXIOV) { vlen = UIO_MAXIOV; } - mmsgp = lock_user(VERIFY_WRITE, target_msgvec, sizeof(*mmsgp) * vlen, 1); - if (!mmsgp) { + target_msgvec = lock_user(VERIFY_WRITE, target_msgvec_addr, + sizeof(target_msgvec) * vlen, 1); + if (!target_msgvec) { return -TARGET_EFAULT; } + host_msgvec = alloca(sizeof(*host_msgvec) * vlen); + for (i = 0; i < vlen; i++) { - ret = do_sendrecvmsg_locked(fd, &mmsgp[i].msg_hdr, flags, send); + + iovlen = tswapal(target_msgvec[i].msg_hdr.msg_iovlen); + target_iovec = tswapal(target_msgvec[i].msg_hdr.msg_iov); + + if (iovlen > IOV_MAX) { + ret = -TARGET_EMSGSIZE; + break; + } + host_iovec = lock_iovec(send ? VERIFY_READ : VERIFY_WRITE, + target_iovec, iovlen, send); + + if (host_iovec == NULL) { + ret = -host_to_target_errno(errno); + break; + } + + num_iovec++; + + host_msgvec[i].msg_hdr.msg_iovlen = iovlen; + host_msgvec[i].msg_hdr.msg_iov = host_iovec; + + ret = target_to_host_msghdr(fd, &host_msgvec[i].msg_hdr, + &target_msgvec[i].msg_hdr, send); + if (is_error(ret)) { break; } - mmsgp[i].msg_len = tswap32(ret); - /* MSG_WAITFORONE turns on MSG_DONTWAIT after one packet */ - if (flags & MSG_WAITFORONE) { - flags |= MSG_DONTWAIT; + } + + if (i > 0) { + if (send) { + ret = get_errno(safe_sendmmsg(fd, host_msgvec, i, flags)); + } else { + ret = get_errno(safe_recvmmsg(fd, host_msgvec, i, flags, NULL)); + } + } + + if (!is_error(ret)) { + num_sentrecv = ret; + for (i = 0; i < num_sentrecv; i++) { + if (!send) { + ret = host_to_target_msghdr(fd, &target_msgvec[i].msg_hdr, + &host_msgvec[i].msg_hdr, + host_msgvec[i].msg_len); + if (is_error(ret)) { + num_sentrecv = i; + break; + } + } + target_msgvec[i].msg_len = tswap32(host_msgvec[i].msg_len); } } - unlock_user(mmsgp, target_msgvec, sizeof(*mmsgp) * i); + for (i = 0; i < num_iovec; i++) { + target_iovec = tswapal(target_msgvec[i].msg_hdr.msg_iov); + unlock_iovec(host_msgvec[i].msg_hdr.msg_iov, + target_iovec, iovlen, !send); + } + + unlock_user(target_msgvec, target_msgvec_addr, sizeof(*target_msgvec) * i); - /* Return number of datagrams sent if we sent any at all; - * otherwise return the error. - */ - if (i) { - return i; + if (num_sentrecv) { + return num_sentrecv; } + return ret; } From patchwork Fri Jul 31 19:06:36 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filip Bozuta X-Patchwork-Id: 11695399 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9DC7E1392 for ; Fri, 31 Jul 2020 19:09:30 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 73A8A21744 for ; Fri, 31 Jul 2020 19:09:30 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=syrmia.com header.i=@syrmia.com header.b="tZQ5Fk8T" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 73A8A21744 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=syrmia.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:59776 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1k1aPJ-0001mB-Ok for patchwork-qemu-devel@patchwork.kernel.org; Fri, 31 Jul 2020 15:09:29 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38386) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k1aN2-0006Ym-78 for qemu-devel@nongnu.org; Fri, 31 Jul 2020 15:07:08 -0400 Received: from mail-am6eur05on2132.outbound.protection.outlook.com ([40.107.22.132]:59583 helo=EUR05-AM6-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k1aMy-0002Mw-HR for qemu-devel@nongnu.org; Fri, 31 Jul 2020 15:07:05 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=gpqeVh6u3Ff+BY0slhSDDYi/uo5E4SR9uXTghOnQbUPjZyMYCrGaMGuf7QK9TFayGlF3bFb7UpI+Avs3SDeQjht0cU4Fjw+0Dn8ntUFt07SP78kw0H9KlPrc94xGJ3UsvDVS+hKdr/zMlZSEVq+dijBFgae1fUUfpMX779DdU0ZRc2/rXMLTUvOeDbjKjAReqVCMlCoPvsDshM5gV2edz3wcwh3QDt68j/s5IwSI/x+atOolnaqMiPAIND0poSsl1NMs50s4Dk6bqVbIc46uZIuqrGZJZXIf+d2e8Oxug4mk5Qmo+UQRN4I9OSUIswA5xu5h/0IWtv8iT9RlsNpA6A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=rKclw02c0T6RMOCR7gCOHfKzbJb4MchvU5i+3wNOd/0=; b=OE0d6fDln28cOK++KfQ7RKQFc3j7/QOizQhQ7VDAsLwaadf0p1ctj5pDUoMaa2d7dL0aUCMinDwpha2nGS/NVk5rTCKKzFg02Uu73+EjCvJ4gZQPRwTyFWH6iedY/5QBQx7t+VNitpDmoLZipoQd/qRtbnncNLQZuY+9FEQ45uU9g/4DhV4Ee7Yeq5/1NNSJVMrcDyZlLWk96OWtLFEMDOILgHasE0lPb8FGwPEFk5H0MtRCUWsd0NE7+Zv1q1GlZ7eeLGZidaujt5sdzexfSx14vSlO9TdJonsG9pgCOMSb46gXXTqLH3JvAwSBkmpKWbDoRdJGE4a+O+LVaS9kUA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=syrmia.com; dmarc=pass action=none header.from=syrmia.com; dkim=pass header.d=syrmia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=syrmia.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=rKclw02c0T6RMOCR7gCOHfKzbJb4MchvU5i+3wNOd/0=; b=tZQ5Fk8Tu2n926jpaZ/+j6SPQNQVkyGGU7W1roJLSgWlBE9ofK+W0LHxc0K/FcOhbGz6CuVBsq4B9e2Zrsu6t2eyCvRHaXjJlUgxUpq9x6CkNRf7+zoD2t4/Th8AutptpLFXTeuNF6+jc8otW9iWmddJaJIFu8NQNc0E1zDca3E= Authentication-Results: nongnu.org; dkim=none (message not signed) header.d=none;nongnu.org; dmarc=none action=none header.from=syrmia.com; Received: from AM6PR03MB5233.eurprd03.prod.outlook.com (2603:10a6:20b:d1::19) by AM5PR03MB2884.eurprd03.prod.outlook.com (2603:10a6:206:1a::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3216.26; Fri, 31 Jul 2020 19:06:53 +0000 Received: from AM6PR03MB5233.eurprd03.prod.outlook.com ([fe80::98f0:b948:78a8:f618]) by AM6PR03MB5233.eurprd03.prod.outlook.com ([fe80::98f0:b948:78a8:f618%7]) with mapi id 15.20.3239.020; Fri, 31 Jul 2020 19:06:53 +0000 From: Filip Bozuta To: qemu-devel@nongnu.org Subject: [PATCH 2/3] linux-user: Fix 'recvmmsg()' implementation Date: Fri, 31 Jul 2020 21:06:36 +0200 Message-Id: <20200731190637.66698-3-Filip.Bozuta@syrmia.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200731190637.66698-1-Filip.Bozuta@syrmia.com> References: <20200731190637.66698-1-Filip.Bozuta@syrmia.com> X-ClientProxiedBy: ZR0P278CA0002.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:16::12) To AM6PR03MB5233.eurprd03.prod.outlook.com (2603:10a6:20b:d1::19) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from localhost.localdomain (147.91.217.235) by ZR0P278CA0002.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:16::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3239.17 via Frontend Transport; Fri, 31 Jul 2020 19:06:52 +0000 X-Mailer: git-send-email 2.25.1 X-Originating-IP: [147.91.217.235] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 39f6a098-11cf-4227-890c-08d83584e2ed X-MS-TrafficTypeDiagnostic: AM5PR03MB2884: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:6790; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: NiBMvEszE3EDyLwNWsG5NO36FrHqdpKetpQyjD3JRlgRYLuiLHjzQmJkQHZBRKc8VYvFBqLeVgo+QFsVVnYfkmPGCLoqV5KKj77jhCPycR/2kQot9CZyTCI4FmguPpMhuOUwYNh1XDvM058RWPh8K/Uh7auL0OsMduEHQTS/ET4noJp3XHsw7seAAcAkpfKI+UU6VPfz0vloeU1uFPXzRs4EVKU6vWY6/LMUA/VYmRofSo4ufb/JO8EYMNePb/QeXKwH6+aMInm/I0TPvKRBpLiS/h/eGrVLcH7t8ZDyf9rKg1UGol0S+4R5DlmonwBualFNwpeJGGdYmzWEpOhXs5izWVYTL1i5A2GkAubd7uEBenPL1JW5/jZ09EScAj5C X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM6PR03MB5233.eurprd03.prod.outlook.com; PTR:; CAT:NONE; SFTY:; SFS:(396003)(39830400003)(376002)(346002)(366004)(136003)(6506007)(26005)(66556008)(186003)(6486002)(107886003)(66946007)(69590400007)(2616005)(66476007)(54906003)(6512007)(8676002)(2906002)(36756003)(4326008)(16526019)(5660300002)(52116002)(316002)(6666004)(83380400001)(86362001)(508600001)(956004)(6916009)(8936002)(1076003); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData: vefNGuoCb36TZTAGNcnZVzDsnYrbVoaaMR8MOxQvBqmJGgGmInQ9DUKTS/y6rAmv/3V/XxSlDY5U7M9kS2YyOzA4YibekZqMjpHELXEZAoQqh0ynU20TgH6kX1DehHDFJOoncnYnYavxxH1xnryxl41PObjAupfNK00V6wBgvsLRUjuOhMBjriL11dZUJBDuQ9DZM/+KAFbiTOh95hLuwcoXqPq+UXkRe+aFBVE2SvUnt3htmKlSZPSBczPpMn18xDoQ+g7ik87Xwt2ViX3Mhp1H7tv9+4yM0/1ls1Rh8P+4yNTGmGFjET9V/C55ts+TGKITggmWNo1urkS6vDrDEYflG//fWNwGbVIw+yC4DHLPwQPtG3NwutSVWU1hginNCemkjbiONGbv8l7yJaEwdHGR/ItdwDEyL1Nnzl1WVz4dISmda50egRnAdT7db2O8HjFQIcsDtfkCGL+3/l5c73WiDrJ4llDA4G61Y6CEzds= X-OriginatorOrg: syrmia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 39f6a098-11cf-4227-890c-08d83584e2ed X-MS-Exchange-CrossTenant-AuthSource: AM6PR03MB5233.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 Jul 2020 19:06:53.3977 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 19214a73-c1ab-4e19-8f59-14bdcb09a66e X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: LQu+qing3Z8Pe1nm3ad7Zi5x6ct7rBuF01BOtPTWV7ZM0cJsNNAPuRkzSOZLeehuguTJvPIioXgRvepFySbyEA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM5PR03MB2884 Received-SPF: pass client-ip=40.107.22.132; envelope-from=Filip.Bozuta@syrmia.com; helo=EUR05-AM6-obe.outbound.protection.outlook.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/07/31 15:06:59 X-ACL-Warn: Detected OS = Windows NT kernel [generic] [fuzzy] X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-1, RCVD_IN_SORBS_WEB=1.5, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Riku Voipio , Laurent Vivier , Filip Bozuta Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" Syscall 'recvmmsg()' takes an argument which is of type 'struct timespec' that represents a timeout for the receive operation. Before changes from this patch, the timeout argument was ignored. This was probably due to the way 'recvmmsg()' was implemented with looping over 'recvmsg()' which doesn't have the timeout argument. This was changed with the previous patch in this series and which is why the timeout argument should be added accordingly. Implementation notes: Function 'do_sendrecvmmsg()' was changed with the addition of a new argument which represents the timeout. This argument is only passed in case of 'TARGET_NR_recvmmsg' and for 'TARGENT_NR_sendmmsg' 0 is passed. Function 'do_sendrecvmmsg()' was also updated accordingly in 'do_socketcall()' for 'TARGET_SYS_recvmmsg' and 'TARGET_SYS_sendmmsg'. Signed-off-by: Filip Bozuta --- linux-user/syscall.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 8cbefdb561..420d7e7334 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -3217,10 +3217,11 @@ static abi_long do_sendrecvmsg(int fd, abi_ulong target_msg, static abi_long do_sendrecvmmsg(int fd, abi_ulong target_msgvec_addr, unsigned int vlen, unsigned int flags, - int send) + abi_long timeout, int send) { struct mmsghdr *host_msgvec; struct target_mmsghdr *target_msgvec; + struct timespec ts; abi_long ret = 0; int num_sentrecv = 0; int num_iovec = 0; @@ -3275,7 +3276,14 @@ static abi_long do_sendrecvmmsg(int fd, abi_ulong target_msgvec_addr, if (send) { ret = get_errno(safe_sendmmsg(fd, host_msgvec, i, flags)); } else { - ret = get_errno(safe_recvmmsg(fd, host_msgvec, i, flags, NULL)); + if (timeout) { + if (target_to_host_timespec(&ts, timeout)) { + return -TARGET_EFAULT; + } + ret = get_errno(safe_recvmmsg(fd, host_msgvec, i, flags, &ts)); + } else { + ret = get_errno(safe_recvmmsg(fd, host_msgvec, i, flags, NULL)); + } } } @@ -3611,10 +3619,10 @@ static abi_long do_socketcall(int num, abi_ulong vptr) return do_sendrecvmsg(a[0], a[1], a[2], 0); case TARGET_SYS_ACCEPT4: /* sockfd, addr, addrlen, flags */ return do_accept4(a[0], a[1], a[2], a[3]); - case TARGET_SYS_RECVMMSG: /* sockfd, msgvec, vlen, flags */ - return do_sendrecvmmsg(a[0], a[1], a[2], a[3], 0); + case TARGET_SYS_RECVMMSG: /* sockfd, msgvec, vlen, timeout, flags */ + return do_sendrecvmmsg(a[0], a[1], a[2], a[3], a[4], 0); case TARGET_SYS_SENDMMSG: /* sockfd, msgvec, vlen, flags */ - return do_sendrecvmmsg(a[0], a[1], a[2], a[3], 1); + return do_sendrecvmmsg(a[0], a[1], a[2], a[3], 0, 1); default: qemu_log_mask(LOG_UNIMP, "Unsupported socketcall: %d\n", num); return -TARGET_EINVAL; @@ -9418,11 +9426,11 @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1, #endif #ifdef TARGET_NR_sendmmsg case TARGET_NR_sendmmsg: - return do_sendrecvmmsg(arg1, arg2, arg3, arg4, 1); + return do_sendrecvmmsg(arg1, arg2, arg3, arg4, 0, 1); #endif #ifdef TARGET_NR_recvmmsg case TARGET_NR_recvmmsg: - return do_sendrecvmmsg(arg1, arg2, arg3, arg4, 0); + return do_sendrecvmmsg(arg1, arg2, arg3, arg4, arg5, 0); #endif #ifdef TARGET_NR_sendto case TARGET_NR_sendto: From patchwork Fri Jul 31 19:06:37 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filip Bozuta X-Patchwork-Id: 11695397 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1FDFD1392 for ; Fri, 31 Jul 2020 19:08:00 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id EB2F021744 for ; Fri, 31 Jul 2020 19:07:59 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=syrmia.com header.i=@syrmia.com header.b="eQ509e+b" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org EB2F021744 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=syrmia.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:54960 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1k1aNr-0008Fe-3t for patchwork-qemu-devel@patchwork.kernel.org; Fri, 31 Jul 2020 15:07:59 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38424) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k1aN4-0006ce-DS for qemu-devel@nongnu.org; Fri, 31 Jul 2020 15:07:10 -0400 Received: from mail-am6eur05on2132.outbound.protection.outlook.com ([40.107.22.132]:59583 helo=EUR05-AM6-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k1aN2-0002Mw-Eq for qemu-devel@nongnu.org; Fri, 31 Jul 2020 15:07:10 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=TzTUlgm5kx7KGCXxeb0BFfN5keInzekYiAnSde7HYa3MaXSg1CDWCrhl8lqQjZWjd8DIQPiiBfjsUkczqQ2XY37EM++3LWofNCKMnY1vYsiY7YWWSTi71uSeuGFY8Cl70OoOHil0FxNC0g06M05Rk0LbC5VfaC72TSyZLzyrZ7MaKgwmEUD3HYhX2aivO5cE8RL7hN8r+gPBhHpEUxeOheIf1GNj3dGrMd+NUdiP8Z2OU5ULVL3U9J4qswNRIO4fcwkWtDm0uVT+uueHoIg7H6HMFyUx5YYTgr+gXYpVWK+iFtw4fIGHBloSMQ8L8p33BNtqzVWZ33/UmLoGJNmCPQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=177K06JJ8UNK8z3ttRiYU5Je3f6CgV2TrN/7b9EUlNE=; b=kW9zVBCM795H1Zqi7Bfzv0TLf+/w0lShpH+zGp/Hy9JK+KRf5TXoEiLxslEcL27muJi15Tsz//QsMw4WFm3iZycuexppf9/uFb/E8zNN/LphFB/tNdYnB9IkwpESymRmTWexK2EL771eWiy48mxgkfwrIFxfwfLSwp8hvSCQSIWXDAq3F3RKDsnDiendf/ZAkd5A5RrE0E9O7Ylc5R9xOa/oGZCQc54FGLGPmSzrENRTwwJk7TTHl4iTlBybGIHq8egIPez342P0YEidDNuErDnz1R8qx/eQBUgQa+aflXahkfcU/6PZcIdKHtyvWZe8xKbJVz4cLJgjnvfc1X6Sqg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=syrmia.com; dmarc=pass action=none header.from=syrmia.com; dkim=pass header.d=syrmia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=syrmia.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=177K06JJ8UNK8z3ttRiYU5Je3f6CgV2TrN/7b9EUlNE=; b=eQ509e+bw2hw/BOd6JBT/H6g3wKuNcWcHCYUMI3euPD6Q3FT03gJe4gHwNk0GAvJ3YJ8RSKBlkR5kuucXukYT52RHQmySrK2QkdnvEso8JDwSIpHKKvy/tKinhDxZB3FVYTDmm3iKUrk3nLN3Tb5e1rRXBVNiuSkoFz7m+JwPA4= Authentication-Results: nongnu.org; dkim=none (message not signed) header.d=none;nongnu.org; dmarc=none action=none header.from=syrmia.com; Received: from AM6PR03MB5233.eurprd03.prod.outlook.com (2603:10a6:20b:d1::19) by AM5PR03MB2884.eurprd03.prod.outlook.com (2603:10a6:206:1a::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3216.26; Fri, 31 Jul 2020 19:06:54 +0000 Received: from AM6PR03MB5233.eurprd03.prod.outlook.com ([fe80::98f0:b948:78a8:f618]) by AM6PR03MB5233.eurprd03.prod.outlook.com ([fe80::98f0:b948:78a8:f618%7]) with mapi id 15.20.3239.020; Fri, 31 Jul 2020 19:06:54 +0000 From: Filip Bozuta To: qemu-devel@nongnu.org Subject: [PATCH 3/3] linux-user: Add support for 'recvmmsg_time64()' Date: Fri, 31 Jul 2020 21:06:37 +0200 Message-Id: <20200731190637.66698-4-Filip.Bozuta@syrmia.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200731190637.66698-1-Filip.Bozuta@syrmia.com> References: <20200731190637.66698-1-Filip.Bozuta@syrmia.com> X-ClientProxiedBy: ZR0P278CA0002.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:16::12) To AM6PR03MB5233.eurprd03.prod.outlook.com (2603:10a6:20b:d1::19) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from localhost.localdomain (147.91.217.235) by ZR0P278CA0002.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:16::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3239.17 via Frontend Transport; Fri, 31 Jul 2020 19:06:53 +0000 X-Mailer: git-send-email 2.25.1 X-Originating-IP: [147.91.217.235] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: fcbea771-363b-47c3-200e-08d83584e363 X-MS-TrafficTypeDiagnostic: AM5PR03MB2884: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:5516; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: jxXksW3uBRCWPTUO4REWCNQ/x71tryo/Q3JO7tmH9Ya3qiX4zMCSTrf+6pR9n4if0luPiSnJXu2yjNjho6mXJ97JdPr0CtTOOXGoJiRrN76EE4TsaaTgw6zBSXSM5kioekgZtvbtz7uiID4W3fQ8hfafgpba3a3dJfGkaOZRDflP4yev2jxE+tnJuENQp3m8RAUbJ6fnZgOeYJti/UN//flrk180sWekUsRWTzj4ITnK4Xii/XkYCVPO9r7+CEBOcNW7A5hdvnN8LAZ7rYPERlG+XtJdjWCwVkFJllQEMGHfQbJh6cFyjOr1aQCAosYpkf8M+jPkwXpnSKaqWNGPqb7VPvjtYDfSC/ZBa22R+2h8EkMjwrtzr3UWigU5SzULmGx9d8NKzdivWR3QsVFhwzDTkrLYWnjtFcECE0/Q/HZPr+Oq8mxEB+OhvgAljtTBiVxDKHomcrN8+w2UEbpO4A== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM6PR03MB5233.eurprd03.prod.outlook.com; PTR:; CAT:NONE; SFTY:; SFS:(396003)(39830400003)(376002)(346002)(366004)(136003)(6506007)(26005)(66556008)(186003)(6486002)(107886003)(66946007)(69590400007)(2616005)(66476007)(54906003)(6512007)(8676002)(2906002)(36756003)(4326008)(16526019)(5660300002)(52116002)(316002)(6666004)(83380400001)(966005)(86362001)(508600001)(956004)(6916009)(8936002)(1076003); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData: 5ESTF8lQRsTTaMrUKQCUNVC7tkEHRBvGbkgTq/TwCPytzFhS9WLaGnvMcI/2ublvG7ftXGtvXgCHAWPuecD1xWDDcb53AdLkW5J41JWGDWT2C6FzEWdLsrqviYMJQTcW3dmYqqLLxGraulW0EhTd1n0dSmWhxctgPugF5iQBPPnYUfeHfJsCbBlZZtsVHXks12H9gqpBT/XLdfmbWYpMqvRmmzBmJ2gXIhWN3WE3nKQw5cESXjHltPjjgEwy4Ar/SibjFBQI3kpiphq/OnrVvJl5toA/vnkpi51PhwF7Tt5xZzCU9oZg1qbwggyTSyOmq8WlzChh64nvDHQeHzmYb7g/FYD0sgCzCZAXq3tiuWh8cW+bZqQMQjSSofExmRbJLXbvQj+dKpoUM6hBsqHUwFKXQXgHVXD33pLzTyE0pocvi/5VlHcq27TBnlyYdlfKtMVF/iK1uGcA4a/4rraDslyu0FZFuLv5mR21VBoKGYM= X-OriginatorOrg: syrmia.com X-MS-Exchange-CrossTenant-Network-Message-Id: fcbea771-363b-47c3-200e-08d83584e363 X-MS-Exchange-CrossTenant-AuthSource: AM6PR03MB5233.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 Jul 2020 19:06:54.1833 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 19214a73-c1ab-4e19-8f59-14bdcb09a66e X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 0Fr3gpMjvXHsqnE6wEKw0HRUGCqugEG3XeF9IXBblErJWTUd3FGwbmSV0nrRWLxVEJoWwxWfISS9ydWmaEsIDA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM5PR03MB2884 Received-SPF: pass client-ip=40.107.22.132; envelope-from=Filip.Bozuta@syrmia.com; helo=EUR05-AM6-obe.outbound.protection.outlook.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/07/31 15:06:59 X-ACL-Warn: Detected OS = Windows NT kernel [generic] [fuzzy] X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-1, RCVD_IN_SORBS_WEB=1.5, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Riku Voipio , Laurent Vivier , Filip Bozuta Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" This patch introduces functionality for syscall: *recvmmsg_time64 This syscall is a 2038 safe variant for syscall: int recvmmsg(int sockfd, struct mmsghdr *msgvec, unsigned int vlen, int flags, struct timespec *timeout) --receive multiple messages on a socket-- man page: https://man7.org/linux/man-pages/man2/recvmmsg.2.html Implementation notes: Function 'do_sendrecvmmsg()' in 'syscall.c' was changed with the addition of a new argument 'time64' which represents a flag by which the function knows what kind of 'struct timespec' converting function to call ('target_to_host_timespec() or 'target_to_host_timespec64()'). It is 0 in case of 'TARGET_NR_recvmmsg' and 1 in case of 'TARGET_NR_recvmmsg_time64'. In 'do_socketcall()', the 'TARGET_ABI_BITS' was checked to know what value for 'time64' argument to pass (0 if 'TARGET_ABI_BITS == 32' and 1 otherwise). Signed-off-by: Filip Bozuta --- linux-user/syscall.c | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 420d7e7334..ed9c2cb7ab 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -3217,7 +3217,7 @@ static abi_long do_sendrecvmsg(int fd, abi_ulong target_msg, static abi_long do_sendrecvmmsg(int fd, abi_ulong target_msgvec_addr, unsigned int vlen, unsigned int flags, - abi_long timeout, int send) + abi_long timeout, int time64, int send) { struct mmsghdr *host_msgvec; struct target_mmsghdr *target_msgvec; @@ -3277,7 +3277,10 @@ static abi_long do_sendrecvmmsg(int fd, abi_ulong target_msgvec_addr, ret = get_errno(safe_sendmmsg(fd, host_msgvec, i, flags)); } else { if (timeout) { - if (target_to_host_timespec(&ts, timeout)) { + if (!time64 && target_to_host_timespec(&ts, timeout)) { + return -TARGET_EFAULT; + } + if (time64 && target_to_host_timespec64(&ts, timeout)) { return -TARGET_EFAULT; } ret = get_errno(safe_recvmmsg(fd, host_msgvec, i, flags, &ts)); @@ -3619,10 +3622,14 @@ static abi_long do_socketcall(int num, abi_ulong vptr) return do_sendrecvmsg(a[0], a[1], a[2], 0); case TARGET_SYS_ACCEPT4: /* sockfd, addr, addrlen, flags */ return do_accept4(a[0], a[1], a[2], a[3]); - case TARGET_SYS_RECVMMSG: /* sockfd, msgvec, vlen, timeout, flags */ - return do_sendrecvmmsg(a[0], a[1], a[2], a[3], a[4], 0); + case TARGET_SYS_RECVMMSG: /* sockfd, msgvec, vlen, flags, timeout, */ +#if TARGET_ABI_BITS == 32 + return do_sendrecvmmsg(a[0], a[1], a[2], a[3], a[4], 0, 0); +#else + return do_sendrecvmmsg(a[0], a[1], a[2], a[3], a[4], 1, 0); +#endif case TARGET_SYS_SENDMMSG: /* sockfd, msgvec, vlen, flags */ - return do_sendrecvmmsg(a[0], a[1], a[2], a[3], 0, 1); + return do_sendrecvmmsg(a[0], a[1], a[2], a[3], 0, 0, 1); default: qemu_log_mask(LOG_UNIMP, "Unsupported socketcall: %d\n", num); return -TARGET_EINVAL; @@ -9426,11 +9433,15 @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1, #endif #ifdef TARGET_NR_sendmmsg case TARGET_NR_sendmmsg: - return do_sendrecvmmsg(arg1, arg2, arg3, arg4, 0, 1); + return do_sendrecvmmsg(arg1, arg2, arg3, arg4, 0, 0, 1); #endif #ifdef TARGET_NR_recvmmsg case TARGET_NR_recvmmsg: - return do_sendrecvmmsg(arg1, arg2, arg3, arg4, arg5, 0); + return do_sendrecvmmsg(arg1, arg2, arg3, arg4, arg5, 0, 0); +#endif +#ifdef TARGET_NR_recvmmsg_time64 + case TARGET_NR_recvmmsg_time64: + return do_sendrecvmmsg(arg1, arg2, arg3, arg4, arg5, 1, 0); #endif #ifdef TARGET_NR_sendto case TARGET_NR_sendto: