Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp5643195img; Wed, 27 Mar 2019 12:17:58 -0700 (PDT) X-Google-Smtp-Source: APXvYqwo7EeqehIfIAeAiSnsOPeqp/05UAxx1Pc7vitUHa8qIpduuQPHTiHh3jsdrhm0fPOcyOWI X-Received: by 2002:a63:7808:: with SMTP id t8mr2812107pgc.127.1553714278128; Wed, 27 Mar 2019 12:17:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553714278; cv=none; d=google.com; s=arc-20160816; b=XvN0H7f1iI/5FoQxPuJy6hakQ4IrGliB5tFuR+oAWQUiSjP6OzGBTAzkOQE38lUjwp vyF6vFDtSdu0viW4iZJu5oWO0zi7YVbpH4ikFHPTgw3pDX89xRtsJpUbRiG0QU7Z2Vr7 RyRB+qB0OHHp4Jit2CI9EV97R9ZEnRzUxcPK0Qif8DE7CFQ3yj0cKNN8Elq44dej6Dyl vMiZUANxff6gYmIieaNBm4KPlvoiZxvEyilDB8DiCE+3shmkk+S4qjR0ag5nVZnVkuew nUd8k0kBdtxgI4Jn8/olRp1nWAFyyeur0nL7sY6i56M8u5G/nHDQsZWlBYz9ADvLwOKh Dhpw== 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=vdFAZgAEj16zb5IDkQjOoPhUW5sCEpYfWWjPz7wydo4=; b=OI2myzL63nJs+JUe3QvOXKE/zePmyHOPqvK2kPXNczOy20xFVlpce/kRuSCv7j5rgM GXHeo6Az9le169nzc7UJfioo5X5O6ko3Z72R4GLFN372vR9jvM1/l7sWzu+1UgYcj20A 1/ALejNxB8/qEOk1bu1/fdkNBfLmCnentQWFxTYR6p0DkSoKtESc1lxpFRJRc2rJwcDZ XzblQ9fRy38VFEv2JD9wBuSnJFW01yPznjRAHZRYeSSnBqmIDmd0hzbRnWuFjMrBjqTN V4eMTqKc3C7tzK8vRvlBBbQChL2q3nWxbbcNpz38nMwJ6PK3ga+e2ePslwzMMBN6N/KU wuJA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=PncUpHO6; 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 d14si12590964pgb.26.2019.03.27.12.17.43; Wed, 27 Mar 2019 12:17:58 -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=PncUpHO6; 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 S2388722AbfC0TQ2 (ORCPT + 99 others); Wed, 27 Mar 2019 15:16:28 -0400 Received: from mail.kernel.org ([198.145.29.99]:50904 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388492AbfC0SJF (ORCPT ); Wed, 27 Mar 2019 14:09:05 -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 28264217F5; Wed, 27 Mar 2019 18:09:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1553710144; bh=C+m6dDbr8RtFbwiDPqHtgWLlpOXUXxJZlReMOk2cRm0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PncUpHO6W+29BM1e2K5+O/Cd7cmQeqguHxXqJph9gG4S2oDF0uoZoifdysISfLNtf bwjsVK8/d6xGDmspX3GtsjWMrb9EVWGUHMENP0eyg1NeKbzVcY6JY2UGvX2Nan752p wONwPCXrDZl+9Qt+ML5s/1zsSeCrfNXsYGqqYXCU= 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 5.0 216/262] hwrng: virtio - Avoid repeated init of completion Date: Wed, 27 Mar 2019 14:01:11 -0400 Message-Id: <20190327180158.10245-216-sashal@kernel.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190327180158.10245-1-sashal@kernel.org> References: <20190327180158.10245-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 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