From patchwork Thu Mar 3 09:48:34 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ladi Prosek X-Patchwork-Id: 8490741 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id CD5ADC0553 for ; Thu, 3 Mar 2016 09:49:19 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 418B120270 for ; Thu, 3 Mar 2016 09:49:19 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 8B46C201DD for ; Thu, 3 Mar 2016 09:49:18 +0000 (UTC) Received: from localhost ([::1]:33517 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1abPsk-0002Mc-1O for patchwork-qemu-devel@patchwork.kernel.org; Thu, 03 Mar 2016 04:49:18 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49371) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1abPsb-0002KK-Ql for qemu-devel@nongnu.org; Thu, 03 Mar 2016 04:49:10 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1abPsY-0007b5-M3 for qemu-devel@nongnu.org; Thu, 03 Mar 2016 04:49:09 -0500 Received: from mx1.redhat.com ([209.132.183.28]:37141) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1abPsY-0007ay-GO for qemu-devel@nongnu.org; Thu, 03 Mar 2016 04:49:06 -0500 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (Postfix) with ESMTPS id CDA752DC371 for ; Thu, 3 Mar 2016 09:49:05 +0000 (UTC) Received: from dhcp-1-107.brq.redhat.com (dhcp-1-127.brq.redhat.com [10.34.1.127]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u239n3KU012920; Thu, 3 Mar 2016 04:49:04 -0500 From: Ladi Prosek To: qemu-devel@nongnu.org Date: Thu, 3 Mar 2016 10:48:34 +0100 Message-Id: <1456998514-19271-1-git-send-email-lprosek@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: amit.shah@redhat.com, pbonzini@redhat.com, mst@redhat.com, Ladi Prosek , pagupta@redhat.com Subject: [Qemu-devel] [PATCH] virtio-rng: ask for more data if queue is not fully drained 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This commit effectively reverts: commit 4621c1768ef5d12171cca2aa1473595ecb9f1c9e Author: Amit Shah Date: Wed Nov 21 11:21:19 2012 +0530 virtio-rng: remove extra request for entropy but instead of calling virtio_rng_process unconditionally, it first checks to see if the queue is empty as a little bit of optimization. Signed-off-by: Ladi Prosek Reviewed-by: Amit Shah --- This commit has a logical dependency on [PATCH v3 0/4] rng-random: implement request queue which removes a synchronous invocation of the receive_func callback in rng_random_request_entropy, thereby eliminating the risk of infinite recursion. hw/virtio/virtio-rng.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/hw/virtio/virtio-rng.c b/hw/virtio/virtio-rng.c index 17da2f8..d713464 100644 --- a/hw/virtio/virtio-rng.c +++ b/hw/virtio/virtio-rng.c @@ -69,6 +69,13 @@ static void chr_read(void *opaque, const void *buf, size_t size) g_free(elem); } virtio_notify(vdev, vrng->vq); + + if (!virtio_queue_empty(vrng->vq)) { + /* If we didn't drain the queue, call virtio_rng_process + * to take care of asking for more data as appropriate. + */ + virtio_rng_process(vrng); + } } static void virtio_rng_process(VirtIORNG *vrng)