All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] PCI: access.c: Piggyback user config access on pci_read/write_*()
@ 2018-06-04 15:48 Alexandru Gagniuc
  2018-06-04 16:12 ` Keith Busch
  0 siblings, 1 reply; 4+ messages in thread
From: Alexandru Gagniuc @ 2018-06-04 15:48 UTC (permalink / raw)
  To: bhelgaas
  Cc: alex_gagniuc, austin_bolen, shyam_iyer, keith.busch,
	Alexandru Gagniuc, linux-pci, linux-kernel

pci_read/write_config*() functions have several safeguards to prevent
stallling accesses when a device is removed. However, their "_user_"
counterparts use a different code path.

To make sure that safeguards are used for userspace PCI config
accesses, piggyback the "_user_" functions on the in-kernel
pci_read/write_config*().

Signed-off-by: Alexandru Gagniuc <mr.nuke.me@gmail.com>
---
 drivers/pci/access.c | 16 ++--------------
 1 file changed, 2 insertions(+), 14 deletions(-)

diff --git a/drivers/pci/access.c b/drivers/pci/access.c
index a3ad2fe185b9..6db2a8713c85 100644
--- a/drivers/pci/access.c
+++ b/drivers/pci/access.c
@@ -223,16 +223,9 @@ int pci_user_read_config_##size						\
 	(struct pci_dev *dev, int pos, type *val)			\
 {									\
 	int ret = PCIBIOS_SUCCESSFUL;					\
-	u32 data = -1;							\
 	if (PCI_##size##_BAD)						\
 		return -EINVAL;						\
-	raw_spin_lock_irq(&pci_lock);				\
-	if (unlikely(dev->block_cfg_access))				\
-		pci_wait_cfg(dev);					\
-	ret = dev->bus->ops->read(dev->bus, dev->devfn,			\
-					pos, sizeof(type), &data);	\
-	raw_spin_unlock_irq(&pci_lock);				\
-	*val = (type)data;						\
+	ret = pci_read_config_##size(dev, pos, val);			\
 	return pcibios_err_to_errno(ret);				\
 }									\
 EXPORT_SYMBOL_GPL(pci_user_read_config_##size);
@@ -245,12 +238,7 @@ int pci_user_write_config_##size					\
 	int ret = PCIBIOS_SUCCESSFUL;					\
 	if (PCI_##size##_BAD)						\
 		return -EINVAL;						\
-	raw_spin_lock_irq(&pci_lock);				\
-	if (unlikely(dev->block_cfg_access))				\
-		pci_wait_cfg(dev);					\
-	ret = dev->bus->ops->write(dev->bus, dev->devfn,		\
-					pos, sizeof(type), val);	\
-	raw_spin_unlock_irq(&pci_lock);				\
+	ret = pci_write_config_##size(dev, pos, val);			\
 	return pcibios_err_to_errno(ret);				\
 }									\
 EXPORT_SYMBOL_GPL(pci_user_write_config_##size);
-- 
2.14.4

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

* Re: [PATCH] PCI: access.c: Piggyback user config access on pci_read/write_*()
  2018-06-04 15:48 [PATCH] PCI: access.c: Piggyback user config access on pci_read/write_*() Alexandru Gagniuc
@ 2018-06-04 16:12 ` Keith Busch
  2018-06-04 16:14     ` Alex_Gagniuc
  0 siblings, 1 reply; 4+ messages in thread
From: Keith Busch @ 2018-06-04 16:12 UTC (permalink / raw)
  To: Alexandru Gagniuc
  Cc: bhelgaas, alex_gagniuc, austin_bolen, shyam_iyer, linux-pci,
	linux-kernel

On Mon, Jun 04, 2018 at 10:48:02AM -0500, Alexandru Gagniuc wrote:
> +++ b/drivers/pci/access.c
> @@ -223,16 +223,9 @@ int pci_user_read_config_##size						\
>  	(struct pci_dev *dev, int pos, type *val)			\
>  {									\
>  	int ret = PCIBIOS_SUCCESSFUL;					\
> -	u32 data = -1;							\
>  	if (PCI_##size##_BAD)						\
>  		return -EINVAL;						\
> -	raw_spin_lock_irq(&pci_lock);				\
> -	if (unlikely(dev->block_cfg_access))				\
> -		pci_wait_cfg(dev);					\
> -	ret = dev->bus->ops->read(dev->bus, dev->devfn,			\
> -					pos, sizeof(type), &data);	\
> -	raw_spin_unlock_irq(&pci_lock);				\
> -	*val = (type)data;						\
> +	ret = pci_read_config_##size(dev, pos, val);			\
>  	return pcibios_err_to_errno(ret);				\
>  }									\

If it wasn't for the block_cfg_access check for user access, this would
have been a nice code reuse cleanup.

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

* Re: [PATCH] PCI: access.c: Piggyback user config access on pci_read/write_*()
  2018-06-04 16:12 ` Keith Busch
@ 2018-06-04 16:14     ` Alex_Gagniuc
  0 siblings, 0 replies; 4+ messages in thread
From: Alex_Gagniuc @ 2018-06-04 16:14 UTC (permalink / raw)
  To: keith.busch, mr.nuke.me
  Cc: bhelgaas, Austin.Bolen, Shyam.Iyer, linux-pci, linux-kernel

On 6/4/2018 11:09 AM, Keith Busch wrote:
> On Mon, Jun 04, 2018 at 10:48:02AM -0500, Alexandru Gagniuc wrote:
>> +++ b/drivers/pci/access.c
>> @@ -223,16 +223,9 @@ int pci_user_read_config_##size						\
>>   	(struct pci_dev *dev, int pos, type *val)			\
>>   {									\
>>   	int ret = PCIBIOS_SUCCESSFUL;					\
>> -	u32 data = -1;							\
>>   	if (PCI_##size##_BAD)						\
>>   		return -EINVAL;						\
>> -	raw_spin_lock_irq(&pci_lock);				\
>> -	if (unlikely(dev->block_cfg_access))				\
>> -		pci_wait_cfg(dev);					\
>> -	ret = dev->bus->ops->read(dev->bus, dev->devfn,			\
>> -					pos, sizeof(type), &data);	\
>> -	raw_spin_unlock_irq(&pci_lock);				\
>> -	*val = (type)data;						\
>> +	ret = pci_read_config_##size(dev, pos, val);			\
>>   	return pcibios_err_to_errno(ret);				\
>>   }									\
> 
> If it wasn't for the block_cfg_access check for user access, this would
> have been a nice code reuse cleanup.

Great fresh catch! I'll get that fixed in v2.

Alex


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

* Re: [PATCH] PCI: access.c: Piggyback user config access on pci_read/write_*()
@ 2018-06-04 16:14     ` Alex_Gagniuc
  0 siblings, 0 replies; 4+ messages in thread
From: Alex_Gagniuc @ 2018-06-04 16:14 UTC (permalink / raw)
  To: keith.busch, mr.nuke.me
  Cc: bhelgaas, Austin.Bolen, Shyam.Iyer, linux-pci, linux-kernel

On 6/4/2018 11:09 AM, Keith Busch wrote:=0A=
> On Mon, Jun 04, 2018 at 10:48:02AM -0500, Alexandru Gagniuc wrote:=0A=
>> +++ b/drivers/pci/access.c=0A=
>> @@ -223,16 +223,9 @@ int pci_user_read_config_##size						\=0A=
>>   	(struct pci_dev *dev, int pos, type *val)			\=0A=
>>   {									\=0A=
>>   	int ret =3D PCIBIOS_SUCCESSFUL;					\=0A=
>> -	u32 data =3D -1;							\=0A=
>>   	if (PCI_##size##_BAD)						\=0A=
>>   		return -EINVAL;						\=0A=
>> -	raw_spin_lock_irq(&pci_lock);				\=0A=
>> -	if (unlikely(dev->block_cfg_access))				\=0A=
>> -		pci_wait_cfg(dev);					\=0A=
>> -	ret =3D dev->bus->ops->read(dev->bus, dev->devfn,			\=0A=
>> -					pos, sizeof(type), &data);	\=0A=
>> -	raw_spin_unlock_irq(&pci_lock);				\=0A=
>> -	*val =3D (type)data;						\=0A=
>> +	ret =3D pci_read_config_##size(dev, pos, val);			\=0A=
>>   	return pcibios_err_to_errno(ret);				\=0A=
>>   }									\=0A=
> =0A=
> If it wasn't for the block_cfg_access check for user access, this would=
=0A=
> have been a nice code reuse cleanup.=0A=
=0A=
Great fresh catch! I'll get that fixed in v2.=0A=
=0A=
Alex=0A=
=0A=

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

end of thread, other threads:[~2018-06-04 16:14 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-06-04 15:48 [PATCH] PCI: access.c: Piggyback user config access on pci_read/write_*() Alexandru Gagniuc
2018-06-04 16:12 ` Keith Busch
2018-06-04 16:14   ` Alex_Gagniuc
2018-06-04 16:14     ` Alex_Gagniuc

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.