Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp1010892yba; Thu, 4 Apr 2019 02:22:05 -0700 (PDT) X-Google-Smtp-Source: APXvYqxakKNRkGzAQdC7Owxc4peaPBeSb6aegP/efxfOGp22xsDwAOAXe3/QiYylVZzTX2bs60Op X-Received: by 2002:a65:6210:: with SMTP id d16mr4648572pgv.110.1554369725330; Thu, 04 Apr 2019 02:22:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554369725; cv=none; d=google.com; s=arc-20160816; b=s7qBwpv4vpKeBcW2tl0xiXHEjY2/EHHTiBuvTPsTI92/qnSRm6g25E77o50rvj+934 NPxmB85/d0iwS8SqjDJVxlxwNzp9/foKG9XMo6jX4OJepmp68R2EYictl9t4vur8qxFO 7vgMidpFBAgsvnEBOMIxB5a1GQzJduJGxaoLs5UVSK5WkwKQYSqb+V6Gxn/exfWy9vMm P3DJEQZMPgjphcM/3Cvsxp5Mm9zFFSxMIMJdSfownIohdfUKZrqzsY6nNMjKItUPa5yU eXRYVnBDUc91KyPOt/6MqykyZv6rlZ5etzYUPbEjpEavjkiytJLliMNGyPUjJffPPqV1 c1Zg== 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=X6HdvaLTS3SsStHpkP5vSqa+5MEx2pJHpmMkEov2XKw=; b=1Jc6l9nlhUgYKJKLPaN/7+wC0WUVS0+kR8vc9rs3kFM1idW1iMNBZb5fVnzp3CCiaF 3JV3OI93DBBRnbC7FmOLQQB/t03dKolsND4453jvi/DCVxb32KAT5nT+/s9jR9FISOd8 xps7gYZsIV3ksc0Y4ijPUS/nnovekUhUciDzZG5SmYC+d/avlf9lmA6rcDvAqySLm7V5 eN5hDVeXZAnhWmi3xuJhGqboBDLavbhqwNKu+byVZUn57N/vm8gDb12UENOZUbYTMXb3 RksIu6nRBSHCgEP+MZ2GCwLi05PwjZ6msJlaqm6k1ZLVUVuoXET1P3y5NkMEJp0/ViZI Oo5g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=0tWfc0cT; 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 v25si15941217pgo.317.2019.04.04.02.21.50; Thu, 04 Apr 2019 02:22:05 -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=0tWfc0cT; 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 S2388240AbfDDJU6 (ORCPT + 99 others); Thu, 4 Apr 2019 05:20:58 -0400 Received: from mail.kernel.org ([198.145.29.99]:58698 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1733276AbfDDJRI (ORCPT ); Thu, 4 Apr 2019 05:17:08 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (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 BB50720693; Thu, 4 Apr 2019 09:17:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1554369428; bh=XAk1OCT/5Hw+r6Xdyd4YqzWL8OIm9LX+eFvSmYxlF8U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=0tWfc0cT8Tvea932FZm5GBbs5d7MFKJokJGNEgfOpVIcuMmqrzdC8e4uh+td+qFDK 3iQzmfbzZj38pVKleciR2YxrEYg3L5DiU7p81aaQ5ElnfeICRGI7KNv+QMYrnVEoyI 80r7wn2fzSXJictfnrJStN+G85zCjgRss0K2BKlc= 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 5.0 204/246] hwrng: virtio - Avoid repeated init of completion Date: Thu, 4 Apr 2019 10:48:24 +0200 Message-Id: <20190404084626.333448026@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190404084619.236418459@linuxfoundation.org> References: <20190404084619.236418459@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore 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 5.0-stable review patch. If anyone has any objections, please let me know. ------------------ [ 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 b89df66ea1ae..7abd604e938c 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