From nobody Sun Mar 22 14:31:33 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1774005478; cv=none; d=zohomail.com; s=zohoarc; b=Dki9DH0WFYe/Be0cbsZrT88UmoYorW05g9Q0Q12aj3fAIc8Oc7+tOHNcwf+jJL7T0z9uo3XxractMDgg4IgGkx5aXFSg9I8rS7MoGDF5LFCfO888AgJeku7l1qWcsS3e3hQGVTgOQDYcaojOm10JhQPu+hVUPVXMo+timRM9PkI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1774005478; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:Sender:Subject:Subject:To:To:Message-Id; bh=LEieoGlCaH6s7s0PPDVzOfznuv2fg98bF7Mxs8neEuQ=; b=e2DRd6B9zGjsHn0iKmLrj2e1vz86sh5se72qCwSpnKBWY16p5ox6/SAwP6sxocGarb9LHn7dY/kQct7Yx62ts0WFeaGKXA0hmPEkqvxtyuzxzAxS56IduozBnDDAINDC+7+mKVCBo3QxMymJgNYrObvDMU/QJzC/A87WKHaGG7E= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 177400547817412.167160231766388; Fri, 20 Mar 2026 04:17:58 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1w3Xr0-0000Ok-6l; Fri, 20 Mar 2026 07:17:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1w3Xqz-0000OZ-0C for qemu-devel@nongnu.org; Fri, 20 Mar 2026 07:17:21 -0400 Received: from relay1.mymailcheap.com ([149.56.97.132]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1w3Xqx-0007RI-DO for qemu-devel@nongnu.org; Fri, 20 Mar 2026 07:17:20 -0400 Received: from nf1.mymailcheap.com (nf1.mymailcheap.com [51.75.14.91]) by relay1.mymailcheap.com (Postfix) with ESMTPS id F100C3EB10; Fri, 20 Mar 2026 11:17:17 +0000 (UTC) Received: from mail20.mymailcheap.com (mail20.mymailcheap.com [51.83.111.147]) by nf1.mymailcheap.com (Postfix) with ESMTPSA id 1A9D9400D6; Fri, 20 Mar 2026 11:17:17 +0000 (UTC) Received: from ArchLinux-desktop (unknown [113.200.174.83]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mail20.mymailcheap.com (Postfix) with ESMTPSA id 2E27C41140; Fri, 20 Mar 2026 11:17:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=aosc.io; s=default; t=1774005436; bh=NF1N6jWbPBNkzq6/LF2CnCQ6R2bO0g8QTIr3v8BHue8=; h=From:To:Cc:Subject:Date:From; b=mmGeQf/821aI2i/ym+7bvemsjwNvUU72PI/wL+OlkRDMI8FI+i2+PCtyQ9laRP2gP F4M6BAc85YpwdIPV6j4wk/1LRDw+jeNXvbTdhI0h7FtExC5tMzXYETCeyy3SfhgodT iLzt43dDpc9ArM47OcHC9ZfdCbtEyXVUCOpJaM1Y= To: qemu-devel@nongnu.org Cc: laurent@vivier.eu, pierrick.bouvier@linaro.org, peter.maydell@linaro.org, Sun Haoyu Subject: [PATCH v3] linux-user: update select timeout writeback Date: Fri, 20 Mar 2026 19:16:47 +0800 Message-ID: <20260320111647.138984-1-shyliuli@aosc.io> X-Mailer: git-send-email 2.53.0 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Rspamd-Server: nf1.mymailcheap.com X-Rspamd-Queue-Id: 1A9D9400D6 X-Spamd-Result: default: False [1.20 / 10.00]; MID_CONTAINS_FROM(1.00)[]; R_MISSING_CHARSET(0.50)[]; R_DKIM_ALLOW(-0.10)[aosc.io:s=default]; R_SPF_ALLOW(-0.10)[+mx]; MIME_GOOD(-0.10)[text/plain]; LOCAL_OUTBOUND(0.00)[]; RCVD_COUNT_ONE(0.00)[1]; ARC_NA(0.00)[]; TO_DN_SOME(0.00)[]; MIME_TRACE(0.00)[0:+]; DMARC_POLICY_ALLOW(0.00)[aosc.io,quarantine]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_EQ_ENVFROM(0.00)[]; TO_MATCH_ENVRCPT_SOME(0.00)[]; FROM_HAS_DN(0.00)[]; DKIM_TRACE(0.00)[aosc.io:+]; RCPT_COUNT_FIVE(0.00)[5]; RCVD_TLS_ALL(0.00)[] X-Rspamd-Action: no action Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=149.56.97.132; envelope-from=shyliuli@aosc.io; helo=relay1.mymailcheap.com X-Spam_score_int: -3 X-Spam_score: -0.4 X-Spam_bar: / X-Spam_report: (-0.4 / 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, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.819, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.903, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-to: Sun Haoyu From: Sun Haoyu via qemu development Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1774005479775158500 Content-Type: text/plain; charset="utf-8" The Linux kernel writes back the remaining timeout for select-family syscalls in poll_select_finish(). If that writeback fails, it keeps the original return value. However, QEMU only writes back the timeout on success. If the writeback fails, QEMU returns -TARGET_EFAULT. This can lose the remaining timeout and change the return value. Update do_select(), do_pselect6(), and do_ppoll() to always write back the timeout to match the Linux kernel's behavior. If the timeout writeback fails, keep the original return value. Tested with the issue reproducer. Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3343 Signed-off-by: Sun Haoyu Reviewed-by: Peter Maydell --- Changes since v2: - move the Resolves: tag above Signed-off-by - ignore timeout writeback failures directly(to match kernel) and add com= ments - fix indentation in do_pselect6() linux-user/syscall.c | 45 +++++++++++++++++++++++--------------------- 1 file changed, 24 insertions(+), 21 deletions(-) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 064bc604c9..0a0c2fa1eb 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -1394,14 +1394,15 @@ static abi_long do_select(int n, return -TARGET_EFAULT; if (efd_addr && copy_to_user_fdset(efd_addr, &efds, n)) return -TARGET_EFAULT; - - if (target_tv_addr) { - tv.tv_sec =3D ts.tv_sec; - tv.tv_usec =3D ts.tv_nsec / 1000; - if (copy_to_user_timeval(target_tv_addr, &tv)) { - return -TARGET_EFAULT; - } - } + } + if (target_tv_addr) { + tv.tv_sec =3D ts.tv_sec; + tv.tv_usec =3D ts.tv_nsec / 1000; + /* + * Like the kernel, we deliberately ignore possible + * failures writing back to the timeout struct. + */ + copy_to_user_timeval(target_tv_addr, &tv); } =20 return ret; @@ -1529,14 +1530,16 @@ static abi_long do_pselect6(abi_long arg1, abi_long= arg2, abi_long arg3, if (efd_addr && copy_to_user_fdset(efd_addr, &efds, n)) { return -TARGET_EFAULT; } + } + if (ts_addr) { + /* + * Like the kernel, we deliberately ignore possible + * failures writing back to the timeout struct. + */ if (time64) { - if (ts_addr && host_to_target_timespec64(ts_addr, &ts)) { - return -TARGET_EFAULT; - } + host_to_target_timespec64(ts_addr, &ts); } else { - if (ts_addr && host_to_target_timespec(ts_addr, &ts)) { - return -TARGET_EFAULT; - } + host_to_target_timespec(ts_addr, &ts); } } return ret; @@ -1606,15 +1609,15 @@ static abi_long do_ppoll(abi_long arg1, abi_long ar= g2, abi_long arg3, if (set) { finish_sigsuspend_mask(ret); } - if (!is_error(ret) && arg3) { + if (arg3) { + /* + * Like the kernel, we deliberately ignore possible + * failures writing back to the timeout struct. + */ if (time64) { - if (host_to_target_timespec64(arg3, timeout_ts)) { - return -TARGET_EFAULT; - } + host_to_target_timespec64(arg3, timeout_ts); } else { - if (host_to_target_timespec(arg3, timeout_ts)) { - return -TARGET_EFAULT; - } + host_to_target_timespec(arg3, timeout_ts); } } } else { --=20 2.53.0