Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp1411856pxb; Thu, 28 Oct 2021 03:14:23 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzT6JYa9328ZgLrXCNiN4LaNHXGKtzIxYiY2S384I1bN28OwJeiCsw9iwH4/tlK3C6FUAin X-Received: by 2002:aa7:c6c1:: with SMTP id b1mr4865337eds.11.1635416063081; Thu, 28 Oct 2021 03:14:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635416063; cv=none; d=google.com; s=arc-20160816; b=yHTX+Cuw6HmEu7UFHiUH3tJnOXmTpC7dxdu+0xCAuQGtwqYaLlkv15F8SQ8SuKyHv/ YPES0hwZ46ouHsItjo1hMjZoRNSUprathSNeW7X+gDYZbzZCnXXYfaVGYtTJ9HYXEBgs UJ4MmUtiDrlYOIFDfniihcAwIyJHj4TqcXsthEUNFSQ6k1JitxMFYX0AuVMFm2YdxrSJ /QyM4v4tlTl33js2OqA+acThvJciOD2ORDrD2fz5BITSLVp4MmVKnb2mHWL9V6E4vjqR peHzQpjDoHf+zyGF85zrQ6IuQ/HAZMuS9BsGjjUZTUUbOMLvqZNegG+cpGGrz0PZpSMo VHNw== 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=vWTfdPo8KOnlWJdxY12fg5B8B5rHjKb4fZeXQIN1PZwgHOo3+WJAVrsGHyTaT1e9Fw kteUU+ZXen40g/ukNZXBqYEf7olTJZDQ0YZ7ohnzbMA8+LP0Sev1Ab+jLHEy3uMoQ+wf ryCTaAbFWCdb3rVT0TsKboGGCsEqvDg/wmf1x5PG3odXd4Acesx7NWltgOgDDdb1xGRK 9ZOkjNVC0iBNructZXXjCG7Hs/tC9R32PzAQazD0vd7/MwLHW7QBt2HA3WYnoD2vv3w8 a8RSIuBw9ZtjXApHzX6aubmym+8gsf89JjNeRcT08lkZG7WeZYqnR4xTXxYQ+RTQdJVO 16FA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=NUa+7fRt; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-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 y8si3781023ejw.761.2021.10.28.03.14.00; Thu, 28 Oct 2021 03:14:23 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-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=NUa+7fRt; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-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 S230101AbhJ1KO3 (ORCPT + 99 others); Thu, 28 Oct 2021 06:14:29 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:30761 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230046AbhJ1KO2 (ORCPT ); Thu, 28 Oct 2021 06:14:28 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1635415921; 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=NUa+7fRt8R4q19ByDwUArUsIxej7trY2WyBrY3y08qndttRSXuws3RQqIpWklmxAW6fBl/ gNRXEGGiPWTeJlm9t33tDD4hukGJtrqVrIm5ilNpkjkQBV4PwQdycqxXbesX9t6vVdTKai V8Sm+1RTDmILMt0gkNdy51U/+rAYtfE= 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-61-dxtiFGm-NyuBUa_Y-ZIraA-1; Thu, 28 Oct 2021 06:11:58 -0400 X-MC-Unique: dxtiFGm-NyuBUa_Y-ZIraA-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 8F0D65074B; Thu, 28 Oct 2021 10:11:56 +0000 (UTC) Received: from thinkpad.redhat.com (unknown [10.39.194.156]) by smtp.corp.redhat.com (Postfix) with ESMTP id 69D3A60C04; Thu, 28 Oct 2021 10:11:36 +0000 (UTC) From: Laurent Vivier To: linux-kernel@vger.kernel.org Cc: amit@kernel.org, Herbert Xu , Matt Mackall , virtualization@lists.linux-foundation.org, Dmitriy Vyukov , rusty@rustcorp.com.au, akong@redhat.com, Alexander Potapenko , "Michael S . Tsirkin" , linux-crypto@vger.kernel.org, Laurent Vivier Subject: [PATCH v2 2/4] hwrng: virtio - don't wait on cleanup Date: Thu, 28 Oct 2021 12:11:09 +0200 Message-Id: <20211028101111.128049-3-lvivier@redhat.com> In-Reply-To: <20211028101111.128049-1-lvivier@redhat.com> References: <20211028101111.128049-1-lvivier@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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