From patchwork Wed Jul 22 06:29:02 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 246976 Delivered-To: patch@linaro.org Received: by 2002:a92:d244:0:0:0:0:0 with SMTP id v4csp270743ilg; Tue, 21 Jul 2020 23:35:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw3Sp7+flPy030AD6pmSCyJuiQvqR3PpjfD4OCSyj00NSJQ20ErGKW4Ix+iTT/K15Jlkx+z X-Received: by 2002:a25:41d3:: with SMTP id o202mr50470765yba.236.1595399753411; Tue, 21 Jul 2020 23:35:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595399753; cv=none; d=google.com; s=arc-20160816; b=P5qjy3H8ITV+6iN5+8urP8BP7vkiXx/YbqxHqDbkNiSPOX1BIUiTwQCfnEUCVGA7DZ 7oQsz91t7iTFtovc4vpfP7u6jxJ78wl0phTCO/jzmt3o4Cqsv+olXdRkMHctLxweH0ah oVAqoPpFUe+mokaFsF+U0d4+Zqt7g5Nn0ujV08aMMzMZqR2jO+6r88bb++wMFRiL+B6H Htc8Zks5wCPFCbkwJRVAbGuIdyM9Wb3YyzR9bzHUviglikXfeE8wqnn9zJ6V4WlSeNLP o0GGjWLUM8+t57oVUhrC8x53DYXNqv0Uon/yxn+b3ul6QPSEuoXSZgXlplPlFTM86jib Cv5A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=R6W72fqt6nZhVleVWEEALghgISIRTfZPOqJF2eNqmeg=; b=pWUsJqAAX5qRq21hLe9KiH4SsbzsOGZK1/e90vSS8a4I3rOhPXZ0MnCtGthtS+N4vB wbZOU6Sm0lGcXEnkJiBntwc9wZIkauTFOwO03N9MrtfNd86B20+5rJ3blupqQGQwuj7W JZ3D9RZuPyek5LNLwBCkp5EFLAX7msfvuCcxkrZKcUndRG+ncNYh6lKjSZzIkxBOLoop M+OMsJNJoVLRzKrrYJdFdyNIz8Giy7eh4p3HXLBGKNwIaPNV5G2FalC/lKhJkeEAZ4YK uls9nz8We6t9h1EiO4l/PKGeGcjFF78V/tLb+Duf1R/LFHAkOWlcvJYGpO3GitpVa5qq sbkA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=djW38PXf; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id r14si10741699ybl.1.2020.07.21.23.35.53 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 21 Jul 2020 23:35:53 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=djW38PXf; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:49102 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jy8M4-0000oE-U8 for patch@linaro.org; Wed, 22 Jul 2020 02:35:52 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:41412) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jy8Fn-0007Vm-Qt for qemu-devel@nongnu.org; Wed, 22 Jul 2020 02:29:23 -0400 Received: from mail-wr1-x442.google.com ([2a00:1450:4864:20::442]:41131) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jy8Fm-0006wB-3n for qemu-devel@nongnu.org; Wed, 22 Jul 2020 02:29:23 -0400 Received: by mail-wr1-x442.google.com with SMTP id z15so694852wrl.8 for ; Tue, 21 Jul 2020 23:29:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=R6W72fqt6nZhVleVWEEALghgISIRTfZPOqJF2eNqmeg=; b=djW38PXfbv4y5Pi/E/iIqcdlGNZBd61zyjKfvdfLkjS6oWNidlQjl+KNL0Y7GJjIgJ a1AVzJHUyv6MwBgLWgmOITMVPGk62xNuVjNEckZ06cxI9x/RzU+HDOAI+mmxCIGEzW69 jSDON5w2S3fSg0pfwmxYBjOQbg/DQuwIdakTUAyhutRxkQB8PCpPo7YsoqG94XPtpJ4K 02WeKyVzOa7tzHpx0aF2UQ1L4J2QICUkVxjniNfnWKiBVqZTOZ5Ckco0sd+nfMK8onaA IIQ7SInSIxEj2RWumB0m4VPSFH9g7XhmNb74P8Osf0WMVf89JmYbSch/uW2Hnhock60j NEXw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=R6W72fqt6nZhVleVWEEALghgISIRTfZPOqJF2eNqmeg=; b=X0kGfDqPUhQkoOyLjWxFxC2mzx87fJGVGinyg/rzf47qGDP7JZ1oU6eOSj/WK0bqmr ap2UP0kZILCHbpN/+ZfDWzPoPXln5Bd+BWYiyaGWvow+DEYd497yfYOuy3Y7Y+r+q/ht g+CvlonXqSqmS3ZFxv98/QYq4eCAiBLL52O1q+uqg7uiEShl3aU21+rbvna69Ps5MGEM cfIQQ3MBw7EoF7gjm7w0sntNk4PgKEm/SXOQ9Extrjb+i81B9U93dQ3qTiBVQuI7mgKb XGpqdOSz5YTQTJKIwDBsFKqnGUjVc+WupbBq2PpM9+u9s21+mlcZVX0b/8Z5fJLIwqay Pt5w== X-Gm-Message-State: AOAM530zVQ8+iFVYvsnAnIu/XATahlpY9xROWtl1elKxcJoz5eZyhja1 0kemPPev5Hm5p7CURHQNH82jAhz2gG0= X-Received: by 2002:adf:f0ce:: with SMTP id x14mr28337613wro.137.1595399360719; Tue, 21 Jul 2020 23:29:20 -0700 (PDT) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id h14sm39361088wrt.36.2020.07.21.23.29.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Jul 2020 23:29:13 -0700 (PDT) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 215F01FF9B; Wed, 22 Jul 2020 07:29:04 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [PATCH v2 12/12] linux-user: fix clock_nanosleep() Date: Wed, 22 Jul 2020 07:29:02 +0100 Message-Id: <20200722062902.24509-13-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200722062902.24509-1-alex.bennee@linaro.org> References: <20200722062902.24509-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::442; envelope-from=alex.bennee@linaro.org; helo=mail-wr1-x442.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-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: fam@euphon.net, berrange@redhat.com, richard.henderson@linaro.org, f4bug@amsat.org, Laurent Vivier , cota@braap.org, aurelien@aurel32.net Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Laurent Vivier If clock_nanosleep() encounters an error, it returns one of the positive error number. If the call is interrupted by a signal handler, it fails with error EINTR and if "remain" is not NULL and "flags" is not TIMER_ABSTIME, it returns the remaining unslept time in "remain". Update linux-user to not overwrite the "remain" structure if there is no error. Found with "make check-tcg", linux-test fails on nanosleep test: TEST linux-test on x86_64 .../tests/tcg/multiarch/linux-test.c:242: nanosleep make[2]: *** [../Makefile.target:153: run-linux-test] Error 1 make[1]: *** [.../tests/tcg/Makefile.qemu:76: run-guest-tests] Error 2 make: *** [.../tests/Makefile.include:857: run-tcg-tests-x86_64-linux-user] Error 2 Reported-by: Philippe Mathieu-Daudé Signed-off-by: Laurent Vivier Message-Id: <20200721201754.2731479-1-laurent@vivier.eu> --- linux-user/syscall.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) -- 2.20.1 Tested-by: Philippe Mathieu-Daudé diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 1211e759c26..caa7cd3cab9 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -11829,10 +11829,19 @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1, { struct timespec ts; target_to_host_timespec(&ts, arg3); - ret = get_errno(safe_clock_nanosleep(arg1, arg2, - &ts, arg4 ? &ts : NULL)); - if (arg4) + /* + * clock_nanosleep() returns 0 or one of the *positive* error number. + */ + ret = host_to_target_errno(safe_clock_nanosleep(arg1, arg2, &ts, + arg4 ? &ts : NULL)); + /* + * if the call is interrupted by a signal handler, it fails + * with error TARGET_EINTR and if arg4 is not NULL and arg2 is not + * TIMER_ABSTIME, it returns the remaining unslept time in arg4. + */ + if (ret == TARGET_EINTR && arg4 && arg2 != TIMER_ABSTIME) { host_to_target_timespec(arg4, &ts); + } #if defined(TARGET_PPC) /* clock_nanosleep is odd in that it returns positive errno values.