Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp668186pxb; Wed, 22 Sep 2021 10:10:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwV13aut1VlWEAl1R8XG8Jw8rmoItkLrVMzC+0Oe72x3l0wzUJzyrlBAv8QcRPsg7cMvwMQ X-Received: by 2002:a50:e009:: with SMTP id e9mr395870edl.254.1632330604099; Wed, 22 Sep 2021 10:10:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632330604; cv=none; d=google.com; s=arc-20160816; b=HOwpBSIoVdCsDR2mAAlcf+5lzkw+qL84ZcvananbOYNlxnc2HEc6wwCcW7jT+PvK06 kwFwlVbn9ELZ6EYaufXdtl+Qe3S9dmjPoof61OJ4khr7FlxVYuLaxPwBkApZMysEJXLh /E0frhkThglKi9szZAOtUB9K3PeLlkd+4txJfobD50BpkhmTAoZG1x681Fh+QADDI+rC 8WMdqC+LkZDWqd5wR6LUd1WPwn9P0TrujGznOYr0tzX2RJrsHbJcsumitIdn8i6trFqO kdrDNJi9eMRVfHpWTKXXqMCc9fZ2awGd7gLYR16uW3ZpzRO+Uo4PgYQbS0EQ5gVXSd+H S1fw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Du5vZNXnhXvnlyGaYPOtC+IJQXZjh+l7JG2ObOtN8d0=; b=TuI+jQzuMjcHGlgnv4wbCQhGmDjj/nppgXyIOqe+CML29T6omh19e4qbeVB5qdnPmR gndQ6J+2R8xe0/qre57CuMWPghX/OHt+fbFaBy6+BQquovRZSf+MRJD1DUdaTzc5E3al vSXh/qoRVvu/9ZnoqqCqNx24/OjrMFfd2wuaoW1AsFaJ5Tg2MQ1gYRoWMg1tTY3kfy+r 5wGW0nyG46rxiWcV0hOgURKgshjyLIor0ZpAe+LRme0+falxwoQCBo0OkqY1VsA/Ml4n HuVS3K60mKauzJFbz/rXM/AqkOXvlVw0/jiwpfFarScJSZgHCb+nMWb+xXmyp9NXhLTg BvHg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=M1KlAm6B; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r2si3030333eda.616.2021.09.22.10.09.39; Wed, 22 Sep 2021 10:10:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=M1KlAm6B; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236793AbhIVRKx (ORCPT + 99 others); Wed, 22 Sep 2021 13:10:53 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:30170 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236803AbhIVRKs (ORCPT ); Wed, 22 Sep 2021 13:10:48 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1632330558; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Du5vZNXnhXvnlyGaYPOtC+IJQXZjh+l7JG2ObOtN8d0=; b=M1KlAm6BFWd0NEHRfI7Boh38hMu0LDZ+r8/HaU1RKgRhSGbKDuV9zVuKG5aD3rFFQvwflL 2OP/14m5wQ5b3Uct7ljVlBp8KPS1QvfF8rc0CLB2ubLv65bJvHWsprka2lzMceT4Gne0Y6 O0wOcAQXj40/Uhm3S/+BHCHh8ZCvAfs= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-154-R0K_rPlnNMGz-__ugYJ27g-1; Wed, 22 Sep 2021 13:09:16 -0400 X-MC-Unique: R0K_rPlnNMGz-__ugYJ27g-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 1BE888145EE; Wed, 22 Sep 2021 17:09:15 +0000 (UTC) Received: from thinkpad.redhat.com (unknown [10.39.192.105]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8B620652A1; Wed, 22 Sep 2021 17:09:12 +0000 (UTC) From: Laurent Vivier To: linux-kernel@vger.kernel.org Cc: Alexander Potapenko , linux-crypto@vger.kernel.org, Dmitriy Vyukov , rusty@rustcorp.com.au, amit@kernel.org, akong@redhat.com, Herbert Xu , "Michael S . Tsirkin" , Matt Mackall , virtualization@lists.linux-foundation.org, Laurent Vivier Subject: [PATCH 2/4] hwrng: virtio - don't wait on cleanup Date: Wed, 22 Sep 2021 19:09:01 +0200 Message-Id: <20210922170903.577801-3-lvivier@redhat.com> In-Reply-To: <20210922170903.577801-1-lvivier@redhat.com> References: <20210922170903.577801-1-lvivier@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org When virtio-rng device was dropped by the hwrng core we were forced to wait the buffer to come back from the device to not have remaining ongoing operation that could spoil the buffer. But now, as the buffer is internal to the virtio-rng we can release the waiting loop immediately, the buffer will be retrieve and use when the virtio-rng driver will be selected again. This avoids to hang on an rng_current write command if the virtio-rng device is blocked by a lack of entropy. This allows to select another entropy source if the current one is empty. Signed-off-by: Laurent Vivier --- drivers/char/hw_random/virtio-rng.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/drivers/char/hw_random/virtio-rng.c b/drivers/char/hw_random/virtio-rng.c index 208c547dcac1..173aeea835bb 100644 --- a/drivers/char/hw_random/virtio-rng.c +++ b/drivers/char/hw_random/virtio-rng.c @@ -82,6 +82,11 @@ static int virtio_read(struct hwrng *rng, void *buf, size_t size, bool wait) ret = wait_for_completion_killable(&vi->have_data); if (ret < 0) return ret; + /* if vi->data_avail is 0, we have been interrupted + * by a cleanup, but buffer stays in the queue + */ + if (vi->data_avail == 0) + return read; chunk = min_t(unsigned int, size, vi->data_avail); memcpy(buf + read, vi->data, chunk); @@ -105,7 +110,7 @@ static void virtio_cleanup(struct hwrng *rng) struct virtrng_info *vi = (struct virtrng_info *)rng->priv; if (vi->busy) - wait_for_completion(&vi->have_data); + complete(&vi->have_data); } static int probe_common(struct virtio_device *vdev) -- 2.31.1