Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp1115201pxa; Wed, 5 Aug 2020 23:12:50 -0700 (PDT) X-Google-Smtp-Source: ABdhPJztQY0WH5FPnY9qQUFaroJ/i2mj5RpwriE88yH66lDZbDT3r38IY6e3pbIA+w5RCdXYKATx X-Received: by 2002:aa7:d688:: with SMTP id d8mr2659200edr.168.1596694370238; Wed, 05 Aug 2020 23:12:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1596694370; cv=none; d=google.com; s=arc-20160816; b=xRU8r8KdL1SCIs8Fb4psqWvF2hhYNzLtbXgKUb6HzqC5NHfYubhhyO4v7QqY+27rDh 0FY49cHdf9OPYDIlvdtPgR055t69HtwBZtVKX+wp05Qh88Ugn8tbYwkJM7GjWb348dHX VddjQZM3p3BL8NkEzKLtuOJcKzztJZgTIrxtvUOrfzulUnoqKQ4kWkadbJOst0YX/1yS 96q8Cise9G+3lYMujUA7tK0VGrlEBUpaNRsVEkiNdUzv0G7rmVj9COxUw7PEqfnF4khc PvBd3IlhdfJJrrqYMnz8UDO6XJVzawO8qDpv7QenFqUN+a5KJqGZjSFiD9B35Rsc7SLI M9aQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=3lg769i6ESd9+yFvgCTcrA71u1CCKdaazplbdD339OQ=; b=0DYmZGg9DiTh5ImH7FrHE2+tN8mzYzYTnCZJLIctREEacnixWlGBvV9/I34rD6OXyr 4TvJ7WiHeTCtPkSr5QiWmPb7z7ccZdNssuOMnMQleirK3eP9IiUtRbbndcUh0b0jFrGO fphvmeNNIiYD34QV2ZB623Q3/nDtF3oT8l+Ctc/z0kAw+nUmPA31b33MfIXUzDj0QHAB nUDT9BQFlnAqXo6likm9HuqzYB5feABuY6Pe1qG/Kq0oWE0SDhuKQOpfrudrlgxexv0n kdoCG4lJwp/gV/VTn99NdpbI2NO9WUqhzzD4z62G2HtRuvGQAdaIyMwjo52rpSAqEye3 THbQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=qqCb6gas; 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=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r20si2731080ejz.158.2020.08.05.23.12.13; Wed, 05 Aug 2020 23:12:50 -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=@linaro.org header.s=google header.b=qqCb6gas; 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=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728158AbgHFGMM (ORCPT + 99 others); Thu, 6 Aug 2020 02:12:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58046 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728152AbgHFGMJ (ORCPT ); Thu, 6 Aug 2020 02:12:09 -0400 Received: from mail-lj1-x242.google.com (mail-lj1-x242.google.com [IPv6:2a00:1450:4864:20::242]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E14AAC061575 for ; Wed, 5 Aug 2020 23:12:08 -0700 (PDT) Received: by mail-lj1-x242.google.com with SMTP id t6so37475208ljk.9 for ; Wed, 05 Aug 2020 23:12:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=3lg769i6ESd9+yFvgCTcrA71u1CCKdaazplbdD339OQ=; b=qqCb6gaszZMEF69Qou9EINe7FP2GiyFrcwvuWpDSf6gXUV3uKkERKD2LVJh2bWO5z3 B1/dhoPl6Vec8dngb4dype3A9Ip5Npb6bKRGF8Avp8c742h7Yzdv9cw6/t5cKzMKE4aR aCUJc0kJcNIKefeCfEk2uGxaRiTf8O48UNEQIeIFrLL8zbGOEDkT7R5BmupXn6+v1yDV q4fpIBuYjsVuJiz4aVQr1OADiTZEPMYTlzmcbLJvdQC6P8rgIpiUg9bleMamjf7zGtIf iLIrwNepo9C1bne0Db1xpp6CIgLH9yALqo5MPRJ3PYZ3+wgdJxYjMDtFvnWrkxTOPjQI TtQw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=3lg769i6ESd9+yFvgCTcrA71u1CCKdaazplbdD339OQ=; b=EtIb0PWo21Hv/+xrenBXfKTVX+K8aL0OORTW0ogkT3jyeiuaBKK8C9eLQpk7AztFi5 QV/uqw9HHhGTwYCRQcaIgSID6paLhlCTT681lyOkGkO0oXGkZTKX0wKfCGqI+HrvdMVk lGpFJ3Xmb/7lOFJqVMY7ATswIp6p7nt39d0Ec2ys+iQGR0FJ0N1MicBQm1jAQf388has Qs3bYUpb1i39R0OCL3s79yceSZLx3YXDOafrIbvOR0/G1ZTJhNFxvNFsb+lt30zPaIm7 i3nxuGJWoDSVIRMqxnk1C/WVFAWArqF5iECS/SjCfrPpOKQHxzdh7M1a7jpSpbFYQFZV b+CA== X-Gm-Message-State: AOAM5330tZMbiOBCcN0op6RV+dgMdPGpUsc83WBW/9PpKWyqt+nELEVa rt84bF6aAIVriCQthupAidxoRvdsZ2fDSLvJok7YQz6q X-Received: by 2002:a2e:b6cc:: with SMTP id m12mr2784456ljo.256.1596694324935; Wed, 05 Aug 2020 23:12:04 -0700 (PDT) MIME-Version: 1.0 References: <20200723084622.31134-1-jorge@foundries.io> <20200723084622.31134-2-jorge@foundries.io> <20200724142305.GA24164@trex> <20200805203817.GA12229@trex> In-Reply-To: <20200805203817.GA12229@trex> From: Sumit Garg Date: Thu, 6 Aug 2020 11:41:53 +0530 Message-ID: Subject: Re: [PATCHv2 2/2] hwrng: optee: fix wait use case To: "Jorge Ramirez-Ortiz, Foundries" Cc: Matt Mackall , Herbert Xu , Jens Wiklander , Arnd Bergmann , ricardo@foundries.io, Michael Scott , Greg Kroah-Hartman , op-tee@lists.trustedfirmware.org, "open list:HARDWARE RANDOM NUMBER GENERATOR CORE" , Linux Kernel Mailing List Content-Type: text/plain; charset="UTF-8" Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org On Thu, 6 Aug 2020 at 02:08, Jorge Ramirez-Ortiz, Foundries wrote: > > On 05/08/20, Sumit Garg wrote: > > Apologies for my delayed response as I was busy with some other tasks > > along with holidays. > > no pb! was just making sure this wasnt falling through some cracks. > > > > > On Fri, 24 Jul 2020 at 19:53, Jorge Ramirez-Ortiz, Foundries > > wrote: > > > > > > On 24/07/20, Sumit Garg wrote: > > > > On Thu, 23 Jul 2020 at 14:16, Jorge Ramirez-Ortiz wrote: > > > > > > > > > > The current code waits for data to be available before attempting a > > > > > second read. However the second read would not be executed as the > > > > > while loop exits. > > > > > > > > > > This fix does not wait if all data has been read and reads a second > > > > > time if only partial data was retrieved on the first read. > > > > > > > > > > This fix also does not attempt to read if not data is requested. > > > > > > > > I am not sure how this is possible, can you elaborate? > > > > > > currently, if the user sets max 0, get_optee_rng_data will regardless > > > issuese a call to the secure world requesting 0 bytes from the RNG > > > > > > > This case is already handled by core API: rng_dev_read(). > > ah ok good point, you are right > but yeah, there is no consequence to the actual patch. > So, at least you could get rid of the corresponding text from commit message. > > > > > with this patch, this request is avoided. > > > > > > > > > > > > > > > > > Signed-off-by: Jorge Ramirez-Ortiz > > > > > --- > > > > > v2: tidy up the while loop to avoid reading when no data is requested > > > > > > > > > > drivers/char/hw_random/optee-rng.c | 4 ++-- > > > > > 1 file changed, 2 insertions(+), 2 deletions(-) > > > > > > > > > > diff --git a/drivers/char/hw_random/optee-rng.c b/drivers/char/hw_random/optee-rng.c > > > > > index 5bc4700c4dae..a99d82949981 100644 > > > > > --- a/drivers/char/hw_random/optee-rng.c > > > > > +++ b/drivers/char/hw_random/optee-rng.c > > > > > @@ -122,14 +122,14 @@ static int optee_rng_read(struct hwrng *rng, void *buf, size_t max, bool wait) > > > > > if (max > MAX_ENTROPY_REQ_SZ) > > > > > max = MAX_ENTROPY_REQ_SZ; > > > > > > > > > > - while (read == 0) { > > > > > + while (read < max) { > > > > > rng_size = get_optee_rng_data(pvt_data, data, (max - read)); > > > > > > > > > > data += rng_size; > > > > > read += rng_size; > > > > > > > > > > if (wait && pvt_data->data_rate) { > > > > > - if (timeout-- == 0) > > > > > + if ((timeout-- == 0) || (read == max)) > > > > > > > > If read == max, would there be any sleep? > > > > > > no but I see no reason why there should be a wait since we already have > > > all the data that we need; the msleep is only required when we need to > > > wait for the RNG to generate entropy for the number of bytes we are > > > requesting. if we are requesting 0 bytes, the entropy is already > > > available. at leat this is what makes sense to me. > > > > > > > Wouldn't it lead to a call as msleep(0); that means no wait as well? > > I dont understand: there is no reason to wait if read == max and this > patch will not wait: if read == max it calls 'return read' > > am I misunderstanding your point? What I mean is that we shouldn't require this extra check here as there wasn't any wait if read == max with existing implementation too. -Sumit > > > > > -Sumit > > > > > > > > > > > > > -Sumit > > > > > > > > > return read; > > > > > msleep((1000 * (max - read)) / pvt_data->data_rate); > > > > > } else { > > > > > -- > > > > > 2.17.1 > > > > >