[1/2] debugfs: regset32: Add Runtime PM support
diff mbox series

Message ID 20200124132957.15769-2-geert+renesas@glider.be
State Superseded
Delegated to: Herbert Xu
Headers show
Series
  • Fix debugfs register access while suspended
Related show

Commit Message

Geert Uytterhoeven Jan. 24, 2020, 1:29 p.m. UTC
Hardware registers of devices under control of power management cannot
be accessed at all times.  If such a device is suspended, register
accesses may lead to undefined behavior, like reading bogus values, or
causing exceptions or system locks.

Extend struct debugfs_regset32 with an optional field to let device
drivers specify the device the registers in the set belong to.  This
allows debugfs_show_regset32() to make sure the device is resumed while
its registers are being read.

Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
---
 fs/debugfs/file.c       | 8 ++++++++
 include/linux/debugfs.h | 1 +
 2 files changed, 9 insertions(+)

Comments

Rafael J. Wysocki Jan. 31, 2020, 10:13 a.m. UTC | #1
On Fri, Jan 24, 2020 at 2:30 PM Geert Uytterhoeven
<geert+renesas@glider.be> wrote:
>
> Hardware registers of devices under control of power management cannot
> be accessed at all times.  If such a device is suspended, register
> accesses may lead to undefined behavior, like reading bogus values, or
> causing exceptions or system locks.
>
> Extend struct debugfs_regset32 with an optional field to let device
> drivers specify the device the registers in the set belong to.  This
> allows debugfs_show_regset32() to make sure the device is resumed while
> its registers are being read.
>
> Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>

LGTM:

Acked-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

> ---
>  fs/debugfs/file.c       | 8 ++++++++
>  include/linux/debugfs.h | 1 +
>  2 files changed, 9 insertions(+)
>
> diff --git a/fs/debugfs/file.c b/fs/debugfs/file.c
> index dede25247b81f72a..5e52d68421c678f2 100644
> --- a/fs/debugfs/file.c
> +++ b/fs/debugfs/file.c
> @@ -18,6 +18,7 @@
>  #include <linux/slab.h>
>  #include <linux/atomic.h>
>  #include <linux/device.h>
> +#include <linux/pm_runtime.h>
>  #include <linux/poll.h>
>  #include <linux/security.h>
>
> @@ -1057,7 +1058,14 @@ static int debugfs_show_regset32(struct seq_file *s, void *data)
>  {
>         struct debugfs_regset32 *regset = s->private;
>
> +       if (regset->dev)
> +               pm_runtime_get_sync(regset->dev);
> +
>         debugfs_print_regs32(s, regset->regs, regset->nregs, regset->base, "");
> +
> +       if (regset->dev)
> +               pm_runtime_put(regset->dev);
> +
>         return 0;
>  }
>
> diff --git a/include/linux/debugfs.h b/include/linux/debugfs.h
> index bf9b6cafa4c26a68..5d0783ae09f365ac 100644
> --- a/include/linux/debugfs.h
> +++ b/include/linux/debugfs.h
> @@ -35,6 +35,7 @@ struct debugfs_regset32 {
>         const struct debugfs_reg32 *regs;
>         int nregs;
>         void __iomem *base;
> +       struct device *dev;     /* Optional device for Runtime PM */
>  };
>
>  extern struct dentry *arch_debugfs_dir;
> --
> 2.17.1
>
Greg KH Feb. 10, 2020, 7:01 p.m. UTC | #2
On Fri, Jan 24, 2020 at 02:29:56PM +0100, Geert Uytterhoeven wrote:
> Hardware registers of devices under control of power management cannot
> be accessed at all times.  If such a device is suspended, register
> accesses may lead to undefined behavior, like reading bogus values, or
> causing exceptions or system locks.
> 
> Extend struct debugfs_regset32 with an optional field to let device
> drivers specify the device the registers in the set belong to.  This
> allows debugfs_show_regset32() to make sure the device is resumed while
> its registers are being read.
> 
> Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
> ---
>  fs/debugfs/file.c       | 8 ++++++++
>  include/linux/debugfs.h | 1 +
>  2 files changed, 9 insertions(+)
> 
> diff --git a/fs/debugfs/file.c b/fs/debugfs/file.c
> index dede25247b81f72a..5e52d68421c678f2 100644
> --- a/fs/debugfs/file.c
> +++ b/fs/debugfs/file.c
> @@ -18,6 +18,7 @@
>  #include <linux/slab.h>
>  #include <linux/atomic.h>
>  #include <linux/device.h>
> +#include <linux/pm_runtime.h>
>  #include <linux/poll.h>
>  #include <linux/security.h>
>  
> @@ -1057,7 +1058,14 @@ static int debugfs_show_regset32(struct seq_file *s, void *data)
>  {
>  	struct debugfs_regset32 *regset = s->private;
>  
> +	if (regset->dev)
> +		pm_runtime_get_sync(regset->dev);
> +
>  	debugfs_print_regs32(s, regset->regs, regset->nregs, regset->base, "");
> +
> +	if (regset->dev)
> +		pm_runtime_put(regset->dev);
> +
>  	return 0;
>  }
>  
> diff --git a/include/linux/debugfs.h b/include/linux/debugfs.h
> index bf9b6cafa4c26a68..5d0783ae09f365ac 100644
> --- a/include/linux/debugfs.h
> +++ b/include/linux/debugfs.h
> @@ -35,6 +35,7 @@ struct debugfs_regset32 {
>  	const struct debugfs_reg32 *regs;
>  	int nregs;
>  	void __iomem *base;
> +	struct device *dev;	/* Optional device for Runtime PM */
>  };
>  
>  extern struct dentry *arch_debugfs_dir;

Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

Patch
diff mbox series

diff --git a/fs/debugfs/file.c b/fs/debugfs/file.c
index dede25247b81f72a..5e52d68421c678f2 100644
--- a/fs/debugfs/file.c
+++ b/fs/debugfs/file.c
@@ -18,6 +18,7 @@ 
 #include <linux/slab.h>
 #include <linux/atomic.h>
 #include <linux/device.h>
+#include <linux/pm_runtime.h>
 #include <linux/poll.h>
 #include <linux/security.h>
 
@@ -1057,7 +1058,14 @@  static int debugfs_show_regset32(struct seq_file *s, void *data)
 {
 	struct debugfs_regset32 *regset = s->private;
 
+	if (regset->dev)
+		pm_runtime_get_sync(regset->dev);
+
 	debugfs_print_regs32(s, regset->regs, regset->nregs, regset->base, "");
+
+	if (regset->dev)
+		pm_runtime_put(regset->dev);
+
 	return 0;
 }
 
diff --git a/include/linux/debugfs.h b/include/linux/debugfs.h
index bf9b6cafa4c26a68..5d0783ae09f365ac 100644
--- a/include/linux/debugfs.h
+++ b/include/linux/debugfs.h
@@ -35,6 +35,7 @@  struct debugfs_regset32 {
 	const struct debugfs_reg32 *regs;
 	int nregs;
 	void __iomem *base;
+	struct device *dev;	/* Optional device for Runtime PM */
 };
 
 extern struct dentry *arch_debugfs_dir;