From nobody Tue Feb 10 03:39:30 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1558061284; cv=none; d=zoho.com; s=zohoarc; b=eIjZKVdAZepimZWzolrtyoahddGwhPGnpb7kP6ybVfVcDVVjHIKN1gWeWP3S4fFwicjgegidHJQplvKghoQpiUHROIZDVKDWuiDpuTTHc/XwrmGXeK3Oj+hSyvJu+MwpgSonXDmuv+Mlagq76LaxYGsGrpbDlhzJwpWajXh7Xx4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1558061284; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=VqY3mH4YRn0WtpmEi7qlWT5KRhdZPDg5AxBMBXlF56s=; b=KVAD+6EYc243GauIMR4+ZFtl/yXbPR/A/P+CarFJU0efqg5AqKYxoU+FL4dGFg9pSgxv295AZ7eVdV1deadOyH1rIBxPiH6b5uqhH1piexG4Z1o6vFLBHM6GMZ3zj4SL339MxiL4nHLqIj6CQ6Ef40eqGWm6rjNy+n1O/VOAtlg= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1558061284108882.7715400709349; Thu, 16 May 2019 19:48:04 -0700 (PDT) Received: from localhost ([127.0.0.1]:40206 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hRSub-0003fM-Pn for importer@patchew.org; Thu, 16 May 2019 22:47:57 -0400 Received: from eggs.gnu.org ([209.51.188.92]:38970) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hRSmU-0005Ne-HW for qemu-devel@nongnu.org; Thu, 16 May 2019 22:39:35 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hRSmT-00020l-GC for qemu-devel@nongnu.org; Thu, 16 May 2019 22:39:34 -0400 Received: from mail-pf1-x442.google.com ([2607:f8b0:4864:20::442]:36256) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hRSmT-0001zx-AI for qemu-devel@nongnu.org; Thu, 16 May 2019 22:39:33 -0400 Received: by mail-pf1-x442.google.com with SMTP id v80so2879662pfa.3 for ; Thu, 16 May 2019 19:39:33 -0700 (PDT) Received: from localhost.localdomain (97-113-13-231.tukw.qwest.net. [97.113.13.231]) by smtp.gmail.com with ESMTPSA id w6sm6984152pge.30.2019.05.16.19.39.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 16 May 2019 19:39:31 -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=VqY3mH4YRn0WtpmEi7qlWT5KRhdZPDg5AxBMBXlF56s=; b=bZklSu4nLG9mzO4Em6BjiaiukE2qTMXlROCJUwW7jLFSfh4FmkSKL8zMx/h20r7zPk 3QCBpWW6AuyLAGNrq48A24n2UOsItxqVbtqXd3ZfoMnQF7MaV+kxKfr6vhFJ9XSynyc4 /k+r71HE3Vf9fjtaG7nMjk7bSdUBImGMqmQP89LPMzMvhnUGKJFPUDvM81BW+cYA4Gkg X6vrX06U9ZgE9gT/AdiIPq2yiGPRxd9Swve70MDZaM2HmYMWtitNFxf7i4/8kFx+A72z KoigzvcXeuGNs5nT8wHC9yn0R2lR+GnAZrUmqeKKfy0nJpC54JlsTAka11Eg9aAfeUKw 43yA== 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=VqY3mH4YRn0WtpmEi7qlWT5KRhdZPDg5AxBMBXlF56s=; b=BHfwTaMiiubONQspuZ8lchYanQmamtdFnn4wwVbdPOmphpe0z1M0KtcogbgJAfyvXN AakKgTooycZhugiUCV6L/MgDJ/Id56I2zI7TshfHhI/RJ92/nMD9G5XFnGCUtYt0u3pT vQqA7NRKKDtjJ9nPyzeQCwV82Xr/0nc550uqRVNtm4xDNDSL9Wk+8Xps5qcpPyZ68gY+ WcUh9y0gviEPWH6R/KHHGADw9xEVMRvYCeZRa2/oYh60B60zGkph+bZMphCwx5GKy/mS bwUIepiFJZOnyMe48scKgA+9VqAul4dbnKLTqV0NIUJwnzWqsK/JzOKDm9wbzXrrYpla kqaA== X-Gm-Message-State: APjAAAXteFS5hxjzOXeiZvQOesedX7yA2z1G5tQyL0XibQeuHtzWxXl0 mk92Tnnltkohlxw7fV68Hg8qIQ5cwdw= X-Google-Smtp-Source: APXvYqybXpc205TJ723aGKc4I7rd/tC8Ko7fL5ffaiKnY+oVP3iDFK0zp8j3yenkVXf9cCiNE6ZsNQ== X-Received: by 2002:a62:460a:: with SMTP id t10mr56441228pfa.3.1558060772044; Thu, 16 May 2019 19:39:32 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Thu, 16 May 2019 19:39:03 -0700 Message-Id: <20190517023924.1686-5-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190517023924.1686-1-richard.henderson@linaro.org> References: <20190517023924.1686-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::442 Subject: [Qemu-devel] [PATCH v8 04/25] crypto: Do not fail for EINTR during qcrypto_random_bytes X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: lvivier@redhat.com, berrange@redhat.com, armbru@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) We can always get EINTR for read; /dev/urandom is no exception. Rearrange the order of tests for likelihood; allow degenerate buflen=3D=3D0 case to perform a no-op zero-length read. This means that the normal success path is a straight line with a single test for success. Reviewed-by: Laurent Vivier Reviewed-by: Daniel P. Berrang=C3=A9 Signed-off-by: Richard Henderson --- crypto/random-platform.c | 36 +++++++++++++++--------------------- 1 file changed, 15 insertions(+), 21 deletions(-) diff --git a/crypto/random-platform.c b/crypto/random-platform.c index f995fc0ef1..260b64564d 100644 --- a/crypto/random-platform.c +++ b/crypto/random-platform.c @@ -65,29 +65,23 @@ int qcrypto_random_bytes(uint8_t *buf G_GNUC_UNUSED, "Unable to read random bytes"); return -1; } - - return 0; #else - int ret =3D -1; - int got; - - while (buflen > 0) { - got =3D read(fd, buf, buflen); - if (got < 0) { - error_setg_errno(errp, errno, - "Unable to read random bytes"); - goto cleanup; - } else if (!got) { - error_setg(errp, - "Unexpected EOF reading random bytes"); - goto cleanup; + while (1) { + ssize_t got =3D read(fd, buf, buflen); + if (likely(got =3D=3D buflen)) { + return 0; + } + if (got > 0) { + buflen -=3D got; + buf +=3D got; + } else if (got =3D=3D 0) { + error_setg(errp, "Unexpected EOF reading random bytes"); + return -1; + } else if (errno !=3D EINTR) { + error_setg_errno(errp, errno, "Unable to read random bytes"); + return -1; } - buflen -=3D got; - buf +=3D got; } - - ret =3D 0; - cleanup: - return ret; #endif + return 0; } --=20 2.17.1