All of lore.kernel.org
 help / color / mirror / Atom feed
From: Harald Freudenberger <freude@linux.vnet.ibm.com>
To: PrasannaKumar Muralidharan <prasannatsmkumar@gmail.com>
Cc: linux-crypto@vger.kernel.org,
	Herbert Xu <herbert@gondor.apana.org.au>,
	Arnd Bergmann <arnd@arndb.de>,
	Greg KH <gregkh@linuxfoundation.org>,
	schwidefsky@de.ibm.com
Subject: Re: [PATCH 3/3] crypto: hwrng add sysfs attribute to show user selected rng
Date: Wed, 5 Jul 2017 14:09:31 +0200	[thread overview]
Message-ID: <0954fe1d-e0ff-6b35-6d2d-96901cad6503@linux.vnet.ibm.com> (raw)
In-Reply-To: <CANc+2y4SQhDdwbV+FLda9OwQpX=2fUsvDiD1eZE0QqQp1N+_hg@mail.gmail.com>

On 07/04/2017 03:15 PM, PrasannaKumar Muralidharan wrote:
> On 3 July 2017 at 15:33, Harald Freudenberger <freude@linux.vnet.ibm.com> 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 <freude@linux.vnet.ibm.com>
>> ---
>>  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 <freude@linux.vnet.ibm.com>
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 <freude@linux.vnet.ibm.com>
---
 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;
-- 
2.7.4
========== cut ==========

  reply	other threads:[~2017-07-05 12:09 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-07-03 10:03 [PATCH 0/3] crypto hwrng consider quality value, remember user choice Harald Freudenberger
2017-07-03 10:03 ` [PATCH 1/3] crypto: hwrng use rng source with best quality Harald Freudenberger
2017-07-04 13:17   ` PrasannaKumar Muralidharan
2017-07-03 10:03 ` [PATCH 2/3] crypto: hwrng remember rng chosen by user Harald Freudenberger
2017-07-04 13:18   ` PrasannaKumar Muralidharan
2017-07-03 10:03 ` [PATCH 3/3] crypto: hwrng add sysfs attribute to show user selected rng Harald Freudenberger
2017-07-04 13:15   ` PrasannaKumar Muralidharan
2017-07-05 12:09     ` Harald Freudenberger [this message]
2017-07-06  4:51       ` PrasannaKumar Muralidharan
2017-07-07 10:22         ` Harald Freudenberger
2017-07-10  6:19           ` PrasannaKumar Muralidharan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=0954fe1d-e0ff-6b35-6d2d-96901cad6503@linux.vnet.ibm.com \
    --to=freude@linux.vnet.ibm.com \
    --cc=arnd@arndb.de \
    --cc=gregkh@linuxfoundation.org \
    --cc=herbert@gondor.apana.org.au \
    --cc=linux-crypto@vger.kernel.org \
    --cc=prasannatsmkumar@gmail.com \
    --cc=schwidefsky@de.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.