Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp833739yba; Wed, 24 Apr 2019 10:20:01 -0700 (PDT) X-Google-Smtp-Source: APXvYqzWXqAQ6n+0BPMu7Wnk2etIdm2HkRFIBqyCpmhX6XT0fFayeWRMkd8CroVXG0SzleB9rMP5 X-Received: by 2002:aa7:9285:: with SMTP id j5mr6007259pfa.129.1556126401327; Wed, 24 Apr 2019 10:20:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556126401; cv=none; d=google.com; s=arc-20160816; b=jyWe/zIGrYscSD+pynA9EmKAx+Z5TOy+YkRd90zRA0Kc55DW3rLGUj64rtbR/+DDFy SbeykI5F4kRzValEL2DWyfChfETg65uWYjarbuUDYUbbx2sao+qi9//GBvnoVpSCagwY vkgbCKhBmUmsivxk36dEycnRDPIF26QgI6Fqdx3r6pguWvwfjm5f5LazhrFQWFzDqTNF o9ls71ngbObs4vk2jytmWtL0SEDQUDvJGh22ZngFrciqHFUC3yzcyUIdyz+7X2jgUUf3 85MAlrXcKAe5p9h4K/0xPoeefIapQwBcEaOq8PuIx6LimSy/FGR6Ijo7xCg0JW3CSxKA XBYQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=OhtrhvhDeOiGgAvvMCGXQar7SW/oqtOA8nZ5bgr0viA=; b=JBs5JaqkTZvSrj33sWDiiFeu6auT7zynJxC9MI5KJ3vBJ5ETfuUcE1JfE5EM3EAOdP 0r4+zdJWvpG0zEma+E7/9LHrtTLsuEHqaNvoTSWbSxENiOIiUK/qcZhe2fc7ui6R7bSE byscgkXEdzqtpbX7dIO8pX/MbENyoh2VXl6u1SGNscfQ9IwQ0iaOFrYechoiPgLt7Vqh wMZZh5yG1CJpi83TjtDurc8VrNsoCPhyWdBuTUdroPc1OJWDJZbvEd7QpZ8nEbJrmoWk vacApjLOT9DqU9Erza8+ynxjgkPTiqPgYNSFlRc2mTM3p0E9T5601W+vacixliZcv4cA bW1Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=EJWuOhG2; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h13si18399871pgh.57.2019.04.24.10.19.46; Wed, 24 Apr 2019 10:20:01 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=EJWuOhG2; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388212AbfDXRSF (ORCPT + 99 others); Wed, 24 Apr 2019 13:18:05 -0400 Received: from mail.kernel.org ([198.145.29.99]:43056 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388749AbfDXRSE (ORCPT ); Wed, 24 Apr 2019 13:18:04 -0400 Received: from localhost (62-193-50-229.as16211.net [62.193.50.229]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 2526B21909; Wed, 24 Apr 2019 17:18:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1556126283; bh=nWSw3dpRfrh23uz92UnFunuYPReheyzgcl9q1cC91BM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=EJWuOhG2hOfrgagpwuh1oZf8Bq8PxYv0zAKBlRoQWRP6vbelG7swkevrLtWx90IwZ gLt2+qMoMKDqINzgKSCDSYGSC7BAKe235k+b7xLX1NPOGpvIVaJk5a2ov2tUhqdpb4 tAq+PUwtUN8S8Ex+doqyax0D31I/XBtBOr0LRIds= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, David Tolnay , Herbert Xu , Sasha Levin Subject: [PATCH 4.4 058/168] hwrng: virtio - Avoid repeated init of completion Date: Wed, 24 Apr 2019 19:08:22 +0200 Message-Id: <20190424170927.224435608@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190424170923.452349382@linuxfoundation.org> References: <20190424170923.452349382@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org [ Upstream commit aef027db48da56b6f25d0e54c07c8401ada6ce21 ] The virtio-rng driver uses a completion called have_data to wait for a virtio read to be fulfilled by the hypervisor. The completion is reset before placing a buffer on the virtio queue and completed by the virtio callback once data has been written into the buffer. Prior to this commit, the driver called init_completion on this completion both during probe as well as when registering virtio buffers as part of a hwrng read operation. The second of these init_completion calls should instead be reinit_completion because the have_data completion has already been inited by probe. As described in Documentation/scheduler/completion.txt, "Calling init_completion() twice on the same completion object is most likely a bug". This bug was present in the initial implementation of virtio-rng in f7f510ec1957 ("virtio: An entropy device, as suggested by hpa"). Back then the have_data completion was a single static completion rather than a member of one of potentially multiple virtrng_info structs as implemented later by 08e53fbdb85c ("virtio-rng: support multiple virtio-rng devices"). The original driver incorrectly used init_completion rather than INIT_COMPLETION to reset have_data during read. Tested by running `head -c48 /dev/random | hexdump` within crosvm, the Chrome OS virtual machine monitor, and confirming that the virtio-rng driver successfully produces random bytes from the host. Signed-off-by: David Tolnay Tested-by: David Tolnay Signed-off-by: Herbert Xu Signed-off-by: Sasha Levin --- drivers/char/hw_random/virtio-rng.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/char/hw_random/virtio-rng.c b/drivers/char/hw_random/virtio-rng.c index 3fa2f8a009b3..1c5c4314c6b5 100644 --- a/drivers/char/hw_random/virtio-rng.c +++ b/drivers/char/hw_random/virtio-rng.c @@ -73,7 +73,7 @@ static int virtio_read(struct hwrng *rng, void *buf, size_t size, bool wait) if (!vi->busy) { vi->busy = true; - init_completion(&vi->have_data); + reinit_completion(&vi->have_data); register_buffer(vi, buf, size); } -- 2.19.1