From patchwork Mon Apr 1 14:02:46 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony Liguori X-Patchwork-Id: 232738 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 5F0382C00EF for ; Tue, 2 Apr 2013 01:03:16 +1100 (EST) Received: from localhost ([::1]:54011 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UMfKM-00007Y-Ds for incoming@patchwork.ozlabs.org; Mon, 01 Apr 2013 10:03:14 -0400 Received: from eggs.gnu.org ([208.118.235.92]:57836) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UMfK2-00006k-Vi for qemu-devel@nongnu.org; Mon, 01 Apr 2013 10:03:01 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UMfK0-0004jw-Qb for qemu-devel@nongnu.org; Mon, 01 Apr 2013 10:02:54 -0400 Received: from mail-pb0-f53.google.com ([209.85.160.53]:33564) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UMfK0-0004jY-IL for qemu-devel@nongnu.org; Mon, 01 Apr 2013 10:02:52 -0400 Received: by mail-pb0-f53.google.com with SMTP id un1so1203181pbc.26 for ; Mon, 01 Apr 2013 07:02:51 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:from:to:cc:subject:in-reply-to:references:user-agent :date:message-id:mime-version:content-type:x-gm-message-state; bh=9nLuWQ7eIpPUUeRRgW5DNULa2cIm2pTmhzktgAdQeHI=; b=Oe+DRp2pirvAsWOI0eSTd+7FOkewsPib1+EjqweBEZtEAnvprJsyIJBTcQfLBdDAz7 oWumC6S/2jWlglsHWsIJjxX+Rni47J6ggMYu3l+rovhPqv9ILfQsDbjaFZeSSsyyeiLr lnmhCJbtNrHiA8SfGflYp3R2v8kHnc18DU+vPLGI/LVWIRRjtvKnjGIOlEm0xLRdknrx JMGgyhonPIrT3PIdXLIX4Db61OmJ57hYcFwhZNrnRRGP/SL9k5u1973ODjHkZn6by+C3 V1nZmP54hFKD75s/cLg0SYlnNU1cCltI8E/dZacaOPzZnA8dsELIfSRCr/5gzffdiqi3 rOsA== X-Received: by 10.66.161.33 with SMTP id xp1mr19230479pab.36.1364824971323; Mon, 01 Apr 2013 07:02:51 -0700 (PDT) Received: from titi.smtp.gmail.com (cpe-70-112-157-87.austin.res.rr.com. [70.112.157.87]) by mx.google.com with ESMTPS id cn1sm13977081pbb.7.2013.04.01.07.02.49 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Mon, 01 Apr 2013 07:02:50 -0700 (PDT) From: Anthony Liguori To: Amit Shah In-Reply-To: <74d06e1f94cc2337aa1bb6784a7ad2210ec55364.1364808312.git.amit.shah@redhat.com> References: <74d06e1f94cc2337aa1bb6784a7ad2210ec55364.1364808312.git.amit.shah@redhat.com> User-Agent: Notmuch/0.13.2+93~ged93d79 (http://notmuchmail.org) Emacs/23.3.1 (x86_64-pc-linux-gnu) Date: Mon, 01 Apr 2013 09:02:46 -0500 Message-ID: <87eheus60p.fsf@codemonkey.ws> MIME-Version: 1.0 X-Gm-Message-State: ALoCoQmP0f+i6X+5SWnGFRIJG5z2Vi4BJD2nuk73r3K+8HLsvNLsgUZkOBp2Nsrx2DNzUlrOWBYm X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 209.85.160.53 Cc: Amit Shah , qemu list Subject: Re: [Qemu-devel] [PATCH 1/1] rng backend: open backend in blocking mode X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Amit Shah writes: > Opening backends in non-blocking mode isn't necessary, we don't do > anything while waiting for data. > > This also excuses us from checking for EAGAIN, which for the default > random backend, is a very common return error type. It's not common... It really shouldn't happen however. > Starting the guest > with '-device virtio-rng-pci', issuing a 'cat /dev/hwrng' in the guest > while also doing 'cat /dev/random' on the host causes You are essentially cat'ing the same device twice. What's happening is that there is entropy available in /dev/random so a select() notification happens but before we are able to read() it, the cat of /dev/hwrng ends up consuming that entropy. This would never happen with a socket, for instance. /dev/random is special in there are multiple readers. > > backends/rng-random.c:44:entropy_available: assertion failed: (len != -1) > > without this fix. This fix would cause QEMU to block indefinitely which I don't think is very good behavior. I think a better solution would be: Since this simply ignores the extraneous select notification that occurs because of the race above. Regards, Anthony Liguori > > Reported-by: yunpingzheng > Signed-off-by: Amit Shah > --- > backends/rng-random.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/backends/rng-random.c b/backends/rng-random.c > index acd20af..252139b 100644 > --- a/backends/rng-random.c > +++ b/backends/rng-random.c > @@ -74,7 +74,7 @@ static void rng_random_opened(RngBackend *b, Error **errp) > error_set(errp, QERR_INVALID_PARAMETER_VALUE, > "filename", "a valid filename"); > } else { > - s->fd = qemu_open(s->filename, O_RDONLY | O_NONBLOCK); > + s->fd = qemu_open(s->filename, O_RDONLY); > > if (s->fd == -1) { > error_set(errp, QERR_OPEN_FILE_FAILED, s->filename); > -- > 1.8.1.4 diff --git a/backends/rng-random.c b/backends/rng-random.c index acd20af..9fde566 100644 --- a/backends/rng-random.c +++ b/backends/rng-random.c @@ -41,6 +41,9 @@ static void entropy_available(void *opaque) ssize_t len; len = read(s->fd, buffer, s->size); + if (len == -1 && errno == EINTR) { + return; + } g_assert(len != -1); s->receive_func(s->opaque, buffer, len);