Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp5613571img; Wed, 27 Mar 2019 11:43:38 -0700 (PDT) X-Google-Smtp-Source: APXvYqzKB7OgkM9ZEmaaqv56kQIg0MmWC8imKgFdT2YULyUYTEtPQ+q1nZ7LrNHY/ctRHeh3z6nX X-Received: by 2002:a17:902:ba8b:: with SMTP id k11mr29745961pls.40.1553712218504; Wed, 27 Mar 2019 11:43:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553712218; cv=none; d=google.com; s=arc-20160816; b=qIFdOCaS/NYS0eSSbt9sOImURN44h38FgnTBNZc1sij9Xc2vYEBRFnermVAu21nwpt QDo5X4b5qs+SOSfusB/pGS/KncKkXU1pS+HuPwZdcqwByV3CYPKMxItsAYEwBhHbQYCX HOyhzvno8fGkzoELdGIZf2Us9jbO9K2zaB8zXVptfLJWK2XcV/z/KkiLcWUaEJc/vyC8 zLm3MGoV9xmIftrKn4oxtgcsq28QOs0MuOYsHtqcCNeLceBODHTrFL1jF8NfnCGMSCO/ GcGk2FHXnQEbR7q7Yk+bfPBGSqA85nE3w2U3nF/GRN2C52Myoy18iYSG+4J6ZaHQIYs9 bkEg== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=wQ9hK29lp1X5rbo58Tnjjjr+ttzjqXEasm3/4l2uNSs=; b=acEMZWEOFwRGsZdvxbBU2jIaobwTquylc7j3sNfQZ+OCBwaGEECMz21cgM5j2ia0lv 6Ct/CFDyBpssUTsYEYnwamM3GwyFg29fMQrFtZjOW5Kv15/38fAPTyzo6pDdwnnwUknZ 1EEXdZhXNa7/HjGhZhNjmhb+VpRVcr0rP8OmiNPu/S+cBT7MWWh6do4EWURr6ILg9oVJ PvglHsbK/0PrQEwKOdI1LbVUR+hW46jwfeL9QRrf1RiK4VBHvxmQNa9lAx1RQvBCGP28 xX0p7KKKEFwJcsUny9VUljtPEGpAffy2tdf9i1FMvviLZ91/L7cNzhf2Iotb+tfl2+6p zMCA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="fCx/ng0e"; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f17si18903680pgd.143.2019.03.27.11.43.23; Wed, 27 Mar 2019 11:43:38 -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="fCx/ng0e"; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2404052AbfC0Skk (ORCPT + 99 others); Wed, 27 Mar 2019 14:40:40 -0400 Received: from mail.kernel.org ([198.145.29.99]:41096 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2391157AbfC0SWw (ORCPT ); Wed, 27 Mar 2019 14:22:52 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id ADEBC20449; Wed, 27 Mar 2019 18:22:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1553710972; bh=J5KM3Gz8B7BYdGn1fiYz+A1YR240YxFGAk4JGLcdUWU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fCx/ng0em14tXb9jyBNn4vzUMQFwSD5a0PjHtLtlWiuUEQ06GlXedWnlv2CV/1oyf n1HNv5RvPkm43dwRfX0HRI0+cSIFKqF6OiRuutDMc9oH7XYLnjyK4toTZMSfFMQJYn NV9UAI/5NBg2hQ3H8NJiQWFy5Ckx4a3M/fD8lXcs= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: David Tolnay , Herbert Xu , Sasha Levin , linux-crypto@vger.kernel.org Subject: [PATCH AUTOSEL 4.9 70/87] hwrng: virtio - Avoid repeated init of completion Date: Wed, 27 Mar 2019 14:20:23 -0400 Message-Id: <20190327182040.17444-70-sashal@kernel.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190327182040.17444-1-sashal@kernel.org> References: <20190327182040.17444-1-sashal@kernel.org> MIME-Version: 1.0 X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: David Tolnay [ 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