From patchwork Wed Jul 5 12:09:31 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Harald Freudenberger X-Patchwork-Id: 9826445 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 7BDA4603B5 for ; Wed, 5 Jul 2017 12:09:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7550C283FB for ; Wed, 5 Jul 2017 12:09:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 69173284B5; Wed, 5 Jul 2017 12:09:40 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C7FD8283FB for ; Wed, 5 Jul 2017 12:09:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752027AbdGEMJi (ORCPT ); Wed, 5 Jul 2017 08:09:38 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:38652 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751637AbdGEMJi (ORCPT ); Wed, 5 Jul 2017 08:09:38 -0400 Received: from pps.filterd (m0098421.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.20/8.16.0.20) with SMTP id v65C95g8119078 for ; Wed, 5 Jul 2017 08:09:37 -0400 Received: from e06smtp14.uk.ibm.com (e06smtp14.uk.ibm.com [195.75.94.110]) by mx0a-001b2d01.pphosted.com with ESMTP id 2bgvtxqs2p-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Wed, 05 Jul 2017 08:09:36 -0400 Received: from localhost by e06smtp14.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 5 Jul 2017 13:09:35 +0100 Received: from b06cxnps4075.portsmouth.uk.ibm.com (9.149.109.197) by e06smtp14.uk.ibm.com (192.168.101.144) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Wed, 5 Jul 2017 13:09:32 +0100 Received: from d06av22.portsmouth.uk.ibm.com (d06av22.portsmouth.uk.ibm.com [9.149.105.58]) by b06cxnps4075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v65C9WQC38076664; Wed, 5 Jul 2017 12:09:32 GMT Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 5D21D4C040; Wed, 5 Jul 2017 13:07:22 +0100 (BST) Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id D5E8D4C050; Wed, 5 Jul 2017 13:07:21 +0100 (BST) Received: from [10.0.2.15] (unknown [9.152.224.51]) by d06av22.portsmouth.uk.ibm.com (Postfix) with ESMTP; Wed, 5 Jul 2017 13:07:21 +0100 (BST) Subject: Re: [PATCH 3/3] crypto: hwrng add sysfs attribute to show user selected rng To: PrasannaKumar Muralidharan Cc: linux-crypto@vger.kernel.org, Herbert Xu , Arnd Bergmann , Greg KH , schwidefsky@de.ibm.com References: <1499076204-18547-1-git-send-email-freude@linux.vnet.ibm.com> <1499076204-18547-4-git-send-email-freude@linux.vnet.ibm.com> From: Harald Freudenberger Date: Wed, 5 Jul 2017 14:09:31 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.1.1 MIME-Version: 1.0 In-Reply-To: Content-Language: en-US X-TM-AS-GCONF: 00 x-cbid: 17070512-0016-0000-0000-000004CF2D7C X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17070512-0017-0000-0000-00002802929F Message-Id: <0954fe1d-e0ff-6b35-6d2d-96901cad6503@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-07-05_08:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=0 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1703280000 definitions=main-1707050203 Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP On 07/04/2017 03:15 PM, PrasannaKumar Muralidharan wrote: > On 3 July 2017 at 15:33, Harald Freudenberger wrote: >> This patch introduces a new sysfs attribute file 'rng_selected' >> which shows the the rng chosen by userspace. >> >> If a rng source is chosen by user via echo some valid string >> to rng_current there should be a way to signal this choice to >> userspace. The new attribute file 'rng_selected' shows either >> the name of the rng chosen or 'none'. >> >> Signed-off-by: Harald Freudenberger >> --- >> drivers/char/hw_random/core.c | 22 +++++++++++++++++----- >> 1 file changed, 17 insertions(+), 5 deletions(-) >> >> diff --git a/drivers/char/hw_random/core.c b/drivers/char/hw_random/core.c >> index ffd4e36..6a6276a 100644 >> --- a/drivers/char/hw_random/core.c >> +++ b/drivers/char/hw_random/core.c >> @@ -28,8 +28,8 @@ >> #define RNG_MODULE_NAME "hw_random" >> >> static struct hwrng *current_rng; >> -/* the current rng has been explicitly chosen by user via sysfs */ >> -static int cur_rng_set_by_user; >> +/* the rng explicitly selected by user via sysfs */ >> +static struct hwrng *selected_rng; >> static struct task_struct *hwrng_fill; >> /* list of registered rngs, sorted decending by quality */ >> static LIST_HEAD(rng_list); >> @@ -306,7 +306,7 @@ static ssize_t hwrng_attr_current_store(struct device *dev, >> list_for_each_entry(rng, &rng_list, list) { >> if (sysfs_streq(rng->name, buf)) { >> err = 0; >> - cur_rng_set_by_user = 1; >> + selected_rng = rng; >> if (rng != current_rng) >> err = set_current_rng(rng); >> break; >> @@ -355,16 +355,28 @@ static ssize_t hwrng_attr_available_show(struct device *dev, >> return strlen(buf); >> } >> >> +static ssize_t hwrng_attr_selected_show(struct device *dev, >> + struct device_attribute *attr, >> + char *buf) >> +{ >> + return snprintf(buf, PAGE_SIZE, "%s\n", >> + selected_rng ? selected_rng->name : "none"); >> +} >> + >> static DEVICE_ATTR(rng_current, S_IRUGO | S_IWUSR, >> hwrng_attr_current_show, >> hwrng_attr_current_store); >> static DEVICE_ATTR(rng_available, S_IRUGO, >> hwrng_attr_available_show, >> NULL); >> +static DEVICE_ATTR(rng_selected, S_IRUGO, >> + hwrng_attr_selected_show, >> + NULL); >> >> static struct attribute *rng_dev_attrs[] = { >> &dev_attr_rng_current.attr, >> &dev_attr_rng_available.attr, >> + &dev_attr_rng_selected.attr, >> NULL >> }; >> >> @@ -448,7 +460,7 @@ int hwrng_register(struct hwrng *rng) >> old_rng = current_rng; >> err = 0; >> if (!old_rng || >> - (!cur_rng_set_by_user && rng->quality > old_rng->quality)) { >> + (!selected_rng && rng->quality > old_rng->quality)) { >> /* >> * Set new rng as current as the new rng source >> * provides better entropy quality and was not >> @@ -484,7 +496,7 @@ void hwrng_unregister(struct hwrng *rng) >> list_del(&rng->list); >> if (current_rng == rng) { >> drop_current_rng(); >> - cur_rng_set_by_user = 0; >> + selected_rng = NULL; >> /* rng_list is sorted by quality, use the best (=first) one */ >> if (!list_empty(&rng_list)) { >> struct hwrng *new_rng; >> -- >> 2.7.4 >> > The current_rng sysfs attribute shows currently selected rng. So this > new attribute can contain 1 to indicate user's choice, 0 otherwise. > > Regards, > PrasannaKumar > Here is an updated version with just showing 0 or 1 in the new sysfs attribute file: ========== cut ========== From: Harald Freudenberger Date: Mon, 3 Jul 2017 10:19:22 +0200 Subject: [PATCH 3/3] crypto: hwrng add sysfs attribute to show user selected rng This patch introduces a new sysfs attribute file 'rng_selected' which shows if the current rng has been chosen by userspace. If a rng source is chosen by user via echo some valid string to rng_current there should be a way to signal this choice to userspace. The new attribute file 'rng_selected' shows '1' for user selecte rng and '0' otherwise. Signed-off-by: Harald Freudenberger --- drivers/char/hw_random/core.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/drivers/char/hw_random/core.c b/drivers/char/hw_random/core.c index ffd4e36..2b4c7f6 100644 --- a/drivers/char/hw_random/core.c +++ b/drivers/char/hw_random/core.c @@ -28,8 +28,8 @@ #define RNG_MODULE_NAME "hw_random" static struct hwrng *current_rng; -/* the current rng has been explicitly chosen by user via sysfs */ -static int cur_rng_set_by_user; +/* the rng explicitly selected by user via sysfs */ +static struct hwrng *selected_rng; static struct task_struct *hwrng_fill; /* list of registered rngs, sorted decending by quality */ static LIST_HEAD(rng_list); @@ -306,7 +306,7 @@ static ssize_t hwrng_attr_current_store(struct device *dev, list_for_each_entry(rng, &rng_list, list) { if (sysfs_streq(rng->name, buf)) { err = 0; - cur_rng_set_by_user = 1; + selected_rng = rng; if (rng != current_rng) err = set_current_rng(rng); break; @@ -355,16 +355,27 @@ static ssize_t hwrng_attr_available_show(struct device *dev, return strlen(buf); } +static ssize_t hwrng_attr_selected_show(struct device *dev, + struct device_attribute *attr, + char *buf) +{ + return snprintf(buf, PAGE_SIZE, "%d\n", selected_rng ? 1 : 0); +} + static DEVICE_ATTR(rng_current, S_IRUGO | S_IWUSR, hwrng_attr_current_show, hwrng_attr_current_store); static DEVICE_ATTR(rng_available, S_IRUGO, hwrng_attr_available_show, NULL); +static DEVICE_ATTR(rng_selected, S_IRUGO, + hwrng_attr_selected_show, + NULL); static struct attribute *rng_dev_attrs[] = { &dev_attr_rng_current.attr, &dev_attr_rng_available.attr, + &dev_attr_rng_selected.attr, NULL }; @@ -448,7 +459,7 @@ int hwrng_register(struct hwrng *rng) old_rng = current_rng; err = 0; if (!old_rng || - (!cur_rng_set_by_user && rng->quality > old_rng->quality)) { + (!selected_rng && rng->quality > old_rng->quality)) { /* * Set new rng as current as the new rng source * provides better entropy quality and was not @@ -484,7 +495,7 @@ void hwrng_unregister(struct hwrng *rng) list_del(&rng->list); if (current_rng == rng) { drop_current_rng(); - cur_rng_set_by_user = 0; + selected_rng = NULL; /* rng_list is sorted by quality, use the best (=first) one */ if (!list_empty(&rng_list)) { struct hwrng *new_rng;