virtio:rng: Virtio RNG devices need to be re-registered after suspend/resume
Subsystems (3)
The patch for
commit: 5c06273401f2eb7b290cadbae18ee00f8f65e893 Author: Amit Shah <[email protected]> Date: Sun Jul 27 07:34:01 2014 +0930
virtio: rng: delay hwrng_register() till driver is ready
moved the call to hwrng_register() out of the probe routine into the scan routine. We need to call hwrng_register() after a suspend/restore cycle to re-register the device, but the scan function is not invoked for the restore. Add the call to hwrng_register() to virtio_restore().
--- drivers/char/hw_random/virtio-rng.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-)
drivers/char/hw_random/virtio-rng.c +20 -1
@@ -184,7 +184,26 @@ static int virtrng_freeze(struct virtio_device *vdev)static int virtrng_restore (struct virtio_device *vdev) { -return probe_common (vdev); +int err; + + err =probe_common (vdev); +if (!err) { +struct virtrng_info *vi = vdev->priv; + +/* +* Set hwrng_removed to ensure that virtio_read() +* does not block waiting for data before the +* registration is complete. +*/ + vi->hwrng_removed = true; + err =hwrng_register (&vi->hwrng); +if (!err) { + vi->hwrng_register_done = true; + vi->hwrng_removed = false; + } + } + +return err; }#endif
Signature · 1 line
1.8.3.1
Hi Jim,
Quoted 52 lines · Jim Quigley
The patch for
commit: 5c06273401f2eb7b290cadbae18ee00f8f65e893 Author: Amit Shah <[email protected]> Date: Sun Jul 27 07:34:01 2014 +0930virtio: rng: delay
hwrng_register()till driver is readymoved the call to
hwrng_register()out of the probe routine into the scan routine. We need to callhwrng_register()after a suspend/restore cycle to re-register the device, but the scan function is not invoked for the restore. Add the call tohwrng_register()tovirtio_restore().Reviewed-by Liam Merwick <[email protected]>Signed-off-by Jim Quigley <[email protected]>--- drivers/char/hw_random/virtio-rng.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-)drivers/char/hw_random/virtio-rng.c +20
-2@@ -184,7 +184,26 @@ static int virtrng_freeze(struct virtio_device *vdev)static int virtrng_restore (struct virtio_device *vdev) { -return probe_common (vdev); +int err; + + err =probe_common (vdev); +if (!err) { +struct virtrng_info *vi = vdev->priv; + +/* +* Set hwrng_removed to ensure that virtio_read() +* does not block waiting for data before the +* registration is complete. +*/ + vi->hwrng_removed = true; + err =hwrng_register (&vi->hwrng); +if (!err) { + vi->hwrng_register_done = true; + vi->hwrng_removed = false; + } + } + +return err; }#endif --
Quoted 2 lines
1.8.3.1
This patch makes me wonder why hwrng_unregister is required in virtrng_freeze. Looks strange and unusual. May be that is not required and it can be removed. If it is required can you please add a comment on why it is required?
Thanks,
PrasannaKumar
Quoted 54 lines · PrasannaKumar Muralidharan
Hi Jim,
Quoted 51 lines · Jim Quigley
The patch for
commit: 5c06273401f2eb7b290cadbae18ee00f8f65e893 Author: Amit Shah <[email protected]> Date: Sun Jul 27 07:34:01 2014 +0930virtio: rng: delay
hwrng_register()till driver is readymoved the call to
hwrng_register()out of the probe routine into the scan routine. We need to callhwrng_register()after a suspend/restore cycle to re-register the device, but the scan function is not invoked for the restore. Add the call tohwrng_register()tovirtio_restore().Reviewed-by Liam Merwick <[email protected]>Signed-off-by Jim Quigley <[email protected]>--- drivers/char/hw_random/virtio-rng.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-)drivers/char/hw_random/virtio-rng.c +20
-1@@ -184,7 +184,26 @@ static int virtrng_freeze(struct virtio_device *vdev)static int virtrng_restore (struct virtio_device *vdev) { -return probe_common (vdev); +int err; + + err =probe_common (vdev); +if (!err) { +struct virtrng_info *vi = vdev->priv; + +/* +* Set hwrng_removed to ensure that virtio_read() +* does not block waiting for data before the +* registration is complete. +*/ + vi->hwrng_removed = true; + err =hwrng_register (&vi->hwrng); +if (!err) { + vi->hwrng_register_done = true; + vi->hwrng_removed = false; + } + } + +return err; }#endif
Quoted 7 lines
Quoted 3 lines
--
1.8.3.1This patch makes me wonder why
hwrng_unregisteris required invirtrng_freeze. Looks strange and unusual. May be that is not required and it can be removed. If it is required can you please add a comment on why it is required?
The reason it's required is because the virtrng_restore() uses probe_common() which allocates a new virtrng_info struct, changing the devices private pointer . This virtrng struct is used in hwrng_register() to set the current RNG etc. If we don't unregister/re-register then we would need to split probe_common() to avoid
vi = kzalloc(sizeof(struct virtrng_info), GFP_KERNEL);
overwriting vdev->priv on a restore.
It would be cleaner to just get rid of probe_common() altogether in that case, and do whatever needs to be done in virtrng_probe()/virtrng_restore() respectively, but I didn't want to change code affecting the normal probe path as well as suspend/resume. Is it OK to leave it that way to avoid the more extensive changes ?
thanks
regards
Jim Q.
Quoted 2 lines
Thanks,
PrasannaKumar
A message that is not in the archive (sent off-list or not yet received): CANc+2y4cEAHudxdK6Y0TbskGMH6jpLg0cfWt77JR44fzYU94HA@mail.gmail.com
Did reply instead of reply all. Forwarding my previous message.
---------- Forwarded message ----------
From: PrasannaKumar Muralidharan <[email protected]>
Date: 3 November 2017 at 20:19
Subject: Re: virtio:rng: Virtio RNG devices need to be re-registered after suspend/resume
To: Jim Quigley <[email protected]>
Hi Jim,
Quoted 76 lines · Jim Quigley
Quoted 58 lines · PrasannaKumar Muralidharan
Hi Jim,
Quoted 54 lines · Jim Quigley
The patch for
commit: 5c06273401f2eb7b290cadbae18ee00f8f65e893 Author: Amit Shah <[email protected]> Date: Sun Jul 27 07:34:01 2014 +0930virtio: rng: delay
hwrng_register()till driver is readymoved the call to
hwrng_register()out of the probe routine into the scan routine. We need to callhwrng_register()after a suspend/restore cycle to re-register the device, but the scan function is not invoked for the restore. Add the call tohwrng_register()tovirtio_restore().Reviewed-by Liam Merwick <[email protected]>Signed-off-by Jim Quigley <[email protected]>--- drivers/char/hw_random/virtio-rng.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-)drivers/char/hw_random/virtio-rng.c +20
-1@@ -184,7 +184,26 @@ static int virtrng_freeze(struct virtio_device *vdev)static int virtrng_restore (struct virtio_device *vdev) { -return probe_common (vdev); +int err; + + err =probe_common (vdev); +if (!err) { +struct virtrng_info *vi = vdev->priv; + +/* +* Set hwrng_removed to ensure that virtio_read() +* does not block waiting for data before the +* registration is complete. +*/ + vi->hwrng_removed = true; + err =hwrng_register (&vi->hwrng); +if (!err) { + vi->hwrng_register_done = true; + vi->hwrng_removed = false; + } + } + +return err; }#endif Quoted 7 lines
Quoted 3 lines
--
1.8.3.1This patch makes me wonder why
hwrng_unregisteris required invirtrng_freeze. Looks strange and unusual. May be that is not required and it can be removed. If it is required can you please add a comment on why it is required?The reason it's required is because the
virtrng_restore()usesprobe_common()which allocates
a newvirtrng_infostruct, changing the devices private pointer . This
virtrng struct is used in
hwrng_register()to set the current RNG etc. If we don't
unregister/re-register then we would
Quoted 5 lines
need to split probe_common() to avoid
vi = kzalloc(sizeof(struct virtrng_info), GFP_KERNEL);
overwriting vdev->priv on a restore.True. As restore uses probe_common calling hwrng_register is required.
But I think it is not correct way to do.
Quoted 4 lines
It would be cleaner to just get rid of
probe_common()altogether in that
case, and do whatever
needs to be done in virtrng_probe()/virtrng_restore() respectively, but
That's correct.
Quoted 4 lines
I didn't want to change code
affecting the normal probe path as well as suspend/resume. Is it OK to
leave it that way to avoid
the more extensive changes ?
Personally I would prefer to do the cleaner way. It is up to the virtio and hwrng maintainer.
Regards,
PrasannaKumar
Hi Jim,
Have second thoughts on this.
Quoted 7 lines · PrasannaKumar Muralidharan
Quoted 4 lines
It would be cleaner to just get rid of
probe_common()altogether in that
case, and do whatever
needs to be done in virtrng_probe()/virtrng_restore() respectively, butThat's correct.
Quoted 7 lines
Quoted 4 lines
I didn't want to change code
affecting the normal probe path as well as suspend/resume. Is it OK to
leave it that way to avoid
the more extensive changes ?Personally I would prefer to do the cleaner way. It is up to the virtio and hwrng maintainer.
You are trying to restore the status quo of the driver that was before the commit 5c06273401. It is really important and valid. The driver's suspend/resume code is not in best shape but that is not what you are trying to solve. I am fine with this change.
Regards,
PrasannaKumar
Jim,
Minor comment below.
Quoted 30 lines · Jim Quigley
The patch for
commit: 5c06273401f2eb7b290cadbae18ee00f8f65e893 Author: Amit Shah <[email protected]> Date: Sun Jul 27 07:34:01 2014 +0930virtio: rng: delay
hwrng_register()till driver is readymoved the call to
hwrng_register()out of the probe routine into the scan routine. We need to callhwrng_register()after a suspend/restore cycle to re-register the device, but the scan function is not invoked for the restore. Add the call tohwrng_register()tovirtio_restore().Reviewed-by Liam Merwick <[email protected]>Signed-off-by Jim Quigley <[email protected]>--- drivers/char/hw_random/virtio-rng.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-)drivers/char/hw_random/virtio-rng.c +2
-1@@ -184,7 +184,26 @@ static int virtrng_freeze(struct virtio_device *vdev)static int virtrng_restore (struct virtio_device *vdev) { -return probe_common (vdev); +int err; +
drivers/char/hw_random/virtio-rng.c static int virtrng_freeze(struct virtio_device *vdev) · line 198
Quoted 10 lines
drivers/char/hw_random/virtio-rng.c +10
-0+ err =probe_common (vdev); +if (!err) { +struct virtrng_info *vi = vdev->priv; + +/* +* Set hwrng_removed to ensure that virtio_read() +* does not block waiting for data before the +* registration is complete. +*/ + vi->hwrng_removed = true;
Hwrng core does not call read method till hwrng_register has finished. Is this really required? I think it has no effect.
Quoted 12 lines
drivers/char/hw_random/virtio-rng.c +8
-1+ err =hwrng_register (&vi->hwrng); +if (!err) { + vi->hwrng_register_done = true; + vi->hwrng_removed = false; + } + } + +return err; }#endif --
Quoted 2 lines
1.8.3.1
I am fine with this change as is. Reviewed-by: PrasannaKumar Muralidharan <[email protected]>
Regards,
PrasannaKumar
Herbert Xu
maintainerQuoted 8 lines · Jim Quigley
The patch for
commit: 5c06273401f2eb7b290cadbae18ee00f8f65e893 Author: Amit Shah <[email protected]> Date: Sun Jul 27 07:34:01 2014 +0930virtio: rng: delay
hwrng_register()till driver is ready
Quoted 7 lines
moved the call to
hwrng_register()out of the probe routine into the scan routine. We need to callhwrng_register()after a suspend/restore cycle to re-register the device, but the scan function is not invoked for the restore. Add the call tohwrng_register()tovirtio_restore().Reviewed-by Liam Merwick <[email protected]>Signed-off-by Jim Quigley <[email protected]>
Patch applied. Thanks.
Signature · 3 lines
Email: Herbert Xu <[email protected]> Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
Hi Herbert,
Quoted 7 lines · Herbert Xu
Quoted 4 lines · Jim Quigley
moved the call to
hwrng_register()out of the probe routine into the scan routine. We need to callhwrng_register()after a suspend/restore cycle to re-register the device, but the scan function is not invoked for the restore. Add the call tohwrng_register()tovirtio_restore().Patch applied. Thanks.
My rb tag is missing in the commit.
Regards,
PrasannaKumar
Herbert Xu
maintainerQuoted 4 lines · PrasannaKumar Muralidharan
Hi Herbert,
Quoted 1 line · Herbert Xu
On Fri, Nov 03, 2017 at 09:57:21AM +0000, Jim Quigley wrote:
Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
moved the call to
hwrng_register()out of the probe routine into the scan routine. We need to callhwrng_register()after a suspend/restore cycle to re-register the device, but the scan function is not invoked for the restore. Add the call tohwrng_register()tovirtio_restore().Patch applied. Thanks.
My rb tag is missing in the commit.
That's because you didn't start it on a new line.
Cheers,
Signature · 3 lines
Email: Herbert Xu <[email protected]> Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt