All of lore.kernel.org
 help / color / mirror / Atom feed
* mmap/munmap in sysfs
@ 2019-06-25 22:36 Bjorn Helgaas
  2019-06-26  1:07 ` Greg Kroah-Hartman
  0 siblings, 1 reply; 3+ messages in thread
From: Bjorn Helgaas @ 2019-06-25 22:36 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Rafael J. Wysocki, Myron Stowe, linux-pci, linux-kernel

Hi Greg, et al,

Userspace can mmap PCI device memory via the resourceN files in sysfs,
which use pci_mmap_resource().  I think this path is unaware of power
management, so the device may be runtime-suspended, e.g., it may be in
D1, D2, or D3, where it will not respond to memory accesses.

Userspace accesses while the device is suspended will cause PCI
errors, so I think we need something like the patch below.  But this
isn't sufficient by itself because we would need a corresponding
pm_runtime_put() when the mapping goes away.  Where should that go?
Or is there a better way to do this?


diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
index 6d27475e39b2..aab7a47679a7 100644
--- a/drivers/pci/pci-sysfs.c
+++ b/drivers/pci/pci-sysfs.c
@@ -1173,6 +1173,7 @@ static int pci_mmap_resource(struct kobject *kobj, struct bin_attribute *attr,
 
 	mmap_type = res->flags & IORESOURCE_MEM ? pci_mmap_mem : pci_mmap_io;
 
+	pm_runtime_get_sync(pdev);
 	return pci_mmap_resource_range(pdev, bar, vma, mmap_type, write_combine);
 }
 

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: mmap/munmap in sysfs
  2019-06-25 22:36 mmap/munmap in sysfs Bjorn Helgaas
@ 2019-06-26  1:07 ` Greg Kroah-Hartman
  2019-06-26 11:06   ` Rafael J. Wysocki
  0 siblings, 1 reply; 3+ messages in thread
From: Greg Kroah-Hartman @ 2019-06-26  1:07 UTC (permalink / raw)
  To: Bjorn Helgaas, Rafael J. Wysocki; +Cc: Myron Stowe, linux-pci, linux-kernel

On Tue, Jun 25, 2019 at 05:36:08PM -0500, Bjorn Helgaas wrote:
> Hi Greg, et al,
> 
> Userspace can mmap PCI device memory via the resourceN files in sysfs,
> which use pci_mmap_resource().  I think this path is unaware of power
> management, so the device may be runtime-suspended, e.g., it may be in
> D1, D2, or D3, where it will not respond to memory accesses.
> 
> Userspace accesses while the device is suspended will cause PCI
> errors, so I think we need something like the patch below.  But this
> isn't sufficient by itself because we would need a corresponding
> pm_runtime_put() when the mapping goes away.  Where should that go?
> Or is there a better way to do this?
> 
> 
> diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
> index 6d27475e39b2..aab7a47679a7 100644
> --- a/drivers/pci/pci-sysfs.c
> +++ b/drivers/pci/pci-sysfs.c
> @@ -1173,6 +1173,7 @@ static int pci_mmap_resource(struct kobject *kobj, struct bin_attribute *attr,
>  
>  	mmap_type = res->flags & IORESOURCE_MEM ? pci_mmap_mem : pci_mmap_io;
>  
> +	pm_runtime_get_sync(pdev);
>  	return pci_mmap_resource_range(pdev, bar, vma, mmap_type, write_combine);
>  }
>  

Ugh, we never thought about this when adding the mmap sysfs interface
all those years ago :(

I think you are right, this will not properly solve the issue, but I
don't know off the top of my head where to solve this.  Maybe Rafael has
a better idea as he knows the pm paths much better than I do?

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: mmap/munmap in sysfs
  2019-06-26  1:07 ` Greg Kroah-Hartman
@ 2019-06-26 11:06   ` Rafael J. Wysocki
  0 siblings, 0 replies; 3+ messages in thread
From: Rafael J. Wysocki @ 2019-06-26 11:06 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Bjorn Helgaas, Myron Stowe, linux-pci, linux-kernel, Mika Westerberg

On Wednesday, June 26, 2019 3:07:46 AM CEST Greg Kroah-Hartman wrote:
> On Tue, Jun 25, 2019 at 05:36:08PM -0500, Bjorn Helgaas wrote:
> > Hi Greg, et al,
> > 
> > Userspace can mmap PCI device memory via the resourceN files in sysfs,
> > which use pci_mmap_resource().  I think this path is unaware of power
> > management, so the device may be runtime-suspended, e.g., it may be in
> > D1, D2, or D3, where it will not respond to memory accesses.
> > 
> > Userspace accesses while the device is suspended will cause PCI
> > errors, so I think we need something like the patch below.  But this
> > isn't sufficient by itself because we would need a corresponding
> > pm_runtime_put() when the mapping goes away.  Where should that go?
> > Or is there a better way to do this?
> > 
> > 
> > diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
> > index 6d27475e39b2..aab7a47679a7 100644
> > --- a/drivers/pci/pci-sysfs.c
> > +++ b/drivers/pci/pci-sysfs.c
> > @@ -1173,6 +1173,7 @@ static int pci_mmap_resource(struct kobject *kobj, struct bin_attribute *attr,
> >  
> >  	mmap_type = res->flags & IORESOURCE_MEM ? pci_mmap_mem : pci_mmap_io;
> >  
> > +	pm_runtime_get_sync(pdev);
> >  	return pci_mmap_resource_range(pdev, bar, vma, mmap_type, write_combine);
> >  }
> >  
> 
> Ugh, we never thought about this when adding the mmap sysfs interface
> all those years ago :(
> 
> I think you are right, this will not properly solve the issue, but I
> don't know off the top of my head where to solve this.  Maybe Rafael has
> a better idea as he knows the pm paths much better than I do?

Well, let me think about this a bit.




^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2019-06-26 11:06 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-06-25 22:36 mmap/munmap in sysfs Bjorn Helgaas
2019-06-26  1:07 ` Greg Kroah-Hartman
2019-06-26 11:06   ` Rafael J. Wysocki

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.