From nobody Sun Mar 22 14:11:52 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=1773986275; cv=none; d=zohomail.com; s=zohoarc; b=nwMEtsQcqnaoY3c/QJaF07he+rguLsalEsCiDstSMW3IxBXLVNaFNmu5gX45XmqBkNk9naPYmmLWxyEVJf0bM6xjIIKiVgK2Ep+Sqjng6f2Igqt1fjvWBWjRweXes1ohZ2vfqft+kUqYVGxDn7jRKonjIS5l4XqHqGjJoklHQqA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1773986275; 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=My95SPpHjRcuFz7aK3c2e214kGlA/rWmvgbPKbtVFJ4=; b=kJWgMO/RTu+LvKWN+pAINK7m5Qk9vVjgvnhhdkisDWQVpEK3F1rnAMwaQGuueWo8i7IMCe6jUPmNEjyRC02tSIwPj46oBLzjkm+7DRFuied5XA4C9G8wPUrCYQZUS3Y5QxKHvKrmn9PP/JBcUU8hzZcRUnBWxCca4y+mJVexINQ= 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 1773986275647414.2160568788843; Thu, 19 Mar 2026 22:57:55 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1w3SrF-0000GG-OL; Fri, 20 Mar 2026 01:57:17 -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 1w3SrE-0000Fu-EH for qemu-devel@nongnu.org; Fri, 20 Mar 2026 01:57:16 -0400 Received: from relay3.mymailcheap.com ([217.182.119.157]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1w3SrC-0007UY-Gw for qemu-devel@nongnu.org; Fri, 20 Mar 2026 01:57:16 -0400 Received: from nf1.mymailcheap.com (nf1.mymailcheap.com [51.75.14.91]) by relay3.mymailcheap.com (Postfix) with ESMTPS id 152433EC16; Fri, 20 Mar 2026 05:57:11 +0000 (UTC) Received: from mail20.mymailcheap.com (mail20.mymailcheap.com [51.83.111.147]) by nf1.mymailcheap.com (Postfix) with ESMTPSA id CE138400D5; Fri, 20 Mar 2026 05:57:10 +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 0EB0941347; Fri, 20 Mar 2026 05:57:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=aosc.io; s=default; t=1773986230; bh=8eN7yNUG5kqkKBltS86n2uvYxdqFwVQ25wpBZnY3VFs=; h=From:To:Cc:Subject:Date:From; b=JYROJUhg63ZBN9Wc8yb756DnMpMvgdm4rtgmxwGOYbL3yA+E8kz5cbGNqfD1F5Wmc tIE7x+20HIw5gQMGsWfajNi63I4wWfnBrcjTi66sghJIvq4kT0BVMyz6N8A4FoaG/y DuitnJMvoMd5gAWvzRp2zw1tIE4Sq869S7gM/Aoc= To: qemu-devel@nongnu.org Cc: laurent@vivier.eu, pierrick.bouvier@linaro.org, peter.maydell@linaro.org, Sun Haoyu Subject: [PATCH v2] linux-user: update select timeout writeback Date: Fri, 20 Mar 2026 13:57:00 +0800 Message-ID: <20260320055700.44715-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: CE138400D5 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=217.182.119.157; envelope-from=shyliuli@aosc.io; helo=relay3.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_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, 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: 1773986278074154100 Content-Type: text/plain; charset="utf-8" Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3343 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. Signed-off-by: Sun Haoyu --- Changes since v1: - write back the timeout in all cases - handle do_select() too - keep the original return value if timeout writeback fails linux-user/syscall.c | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 064bc604c9..877a3b8bb6 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -1394,13 +1394,12 @@ 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; + if (copy_to_user_timeval(target_tv_addr, &tv)) { + return ret; } } =20 @@ -1529,16 +1528,18 @@ 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) { if (time64) { - if (ts_addr && host_to_target_timespec64(ts_addr, &ts)) { - return -TARGET_EFAULT; + if (host_to_target_timespec64(ts_addr, &ts)) { + return ret; } } else { - if (ts_addr && host_to_target_timespec(ts_addr, &ts)) { - return -TARGET_EFAULT; + if (host_to_target_timespec(ts_addr, &ts)) { + return ret; } } - } + } return ret; } #endif @@ -1606,14 +1607,14 @@ 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) { if (time64) { if (host_to_target_timespec64(arg3, timeout_ts)) { - return -TARGET_EFAULT; + return ret; } } else { if (host_to_target_timespec(arg3, timeout_ts)) { - return -TARGET_EFAULT; + return ret; } } } --=20 2.53.0