linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] iommu: WARN_ON when removing a device with no iommu_group associated
@ 2013-08-23  1:55 Wei Yang
  2013-08-23  3:33 ` Alex Williamson
  0 siblings, 1 reply; 3+ messages in thread
From: Wei Yang @ 2013-08-23  1:55 UTC (permalink / raw)
  To: alex.williamson, linux-kernel, linuxppc-dev; +Cc: aik, paulus, benh, Wei Yang

When removing a device from the system, iommu_group driver will try to
disconnect it from its group. While in some cases, one device may not
associated with any iommu_group. For example, not enough DMA address space.

In the generic bus notification, it will check dev->iommu_group before calling
iommu_group_remove_device(). While in some cases, developers may call
iommu_group_remove_device() in a different code path and without check. For
those devices with dev->iommu_group set to NULL, kernel will crash.

This patch gives a warning and return when trying to remove a device from an
iommu_group with dev->iommu_group set to NULL. This helps to indicate some bad
behavior and also guard the kernel.

Signed-off-by: Wei Yang <weiyang@linux.vnet.ibm.com>
---
 drivers/iommu/iommu.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)

diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
index fbe9ca7..43396f0 100644
--- a/drivers/iommu/iommu.c
+++ b/drivers/iommu/iommu.c
@@ -379,6 +379,9 @@ void iommu_group_remove_device(struct device *dev)
 	struct iommu_group *group = dev->iommu_group;
 	struct iommu_device *tmp_device, *device = NULL;
 
+	if (WARN_ON(!group))
+		return;
+
 	/* Pre-notify listeners that a device is being removed. */
 	blocking_notifier_call_chain(&group->notifier,
 				     IOMMU_GROUP_NOTIFY_DEL_DEVICE, dev);
-- 
1.7.5.4

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

* Re: [PATCH] iommu: WARN_ON when removing a device with no iommu_group associated
  2013-08-23  1:55 [PATCH] iommu: WARN_ON when removing a device with no iommu_group associated Wei Yang
@ 2013-08-23  3:33 ` Alex Williamson
  2013-09-03  3:15   ` Wei Yang
  0 siblings, 1 reply; 3+ messages in thread
From: Alex Williamson @ 2013-08-23  3:33 UTC (permalink / raw)
  To: Wei Yang; +Cc: benh, aik, linux-kernel, iommu, paulus, linuxppc-dev

[+cc iommu]

On Fri, 2013-08-23 at 09:55 +0800, Wei Yang wrote:
> When removing a device from the system, iommu_group driver will try to
> disconnect it from its group. While in some cases, one device may not
> associated with any iommu_group. For example, not enough DMA address space.
> 
> In the generic bus notification, it will check dev->iommu_group before calling
> iommu_group_remove_device(). While in some cases, developers may call
> iommu_group_remove_device() in a different code path and without check. For
> those devices with dev->iommu_group set to NULL, kernel will crash.
> 
> This patch gives a warning and return when trying to remove a device from an
> iommu_group with dev->iommu_group set to NULL. This helps to indicate some bad
> behavior and also guard the kernel.
> 
> Signed-off-by: Wei Yang <weiyang@linux.vnet.ibm.com>

Acked-by: Alex Williamson <alex.williamson@redhat.com>

> ---
>  drivers/iommu/iommu.c |    3 +++
>  1 files changed, 3 insertions(+), 0 deletions(-)
> 
> diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
> index fbe9ca7..43396f0 100644
> --- a/drivers/iommu/iommu.c
> +++ b/drivers/iommu/iommu.c
> @@ -379,6 +379,9 @@ void iommu_group_remove_device(struct device *dev)
>  	struct iommu_group *group = dev->iommu_group;
>  	struct iommu_device *tmp_device, *device = NULL;
>  
> +	if (WARN_ON(!group))
> +		return;
> +
>  	/* Pre-notify listeners that a device is being removed. */
>  	blocking_notifier_call_chain(&group->notifier,
>  				     IOMMU_GROUP_NOTIFY_DEL_DEVICE, dev);

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

* Re: [PATCH] iommu: WARN_ON when removing a device with no iommu_group associated
  2013-08-23  3:33 ` Alex Williamson
@ 2013-09-03  3:15   ` Wei Yang
  0 siblings, 0 replies; 3+ messages in thread
From: Wei Yang @ 2013-09-03  3:15 UTC (permalink / raw)
  To: Alex Williamson
  Cc: Wei Yang, benh, aik, linux-kernel, iommu, paulus, linuxppc-dev

Any more comments? Or this one is not proper?

On Thu, Aug 22, 2013 at 09:33:27PM -0600, Alex Williamson wrote:
>[+cc iommu]
>
>On Fri, 2013-08-23 at 09:55 +0800, Wei Yang wrote:
>> When removing a device from the system, iommu_group driver will try to
>> disconnect it from its group. While in some cases, one device may not
>> associated with any iommu_group. For example, not enough DMA address space.
>> 
>> In the generic bus notification, it will check dev->iommu_group before calling
>> iommu_group_remove_device(). While in some cases, developers may call
>> iommu_group_remove_device() in a different code path and without check. For
>> those devices with dev->iommu_group set to NULL, kernel will crash.
>> 
>> This patch gives a warning and return when trying to remove a device from an
>> iommu_group with dev->iommu_group set to NULL. This helps to indicate some bad
>> behavior and also guard the kernel.
>> 
>> Signed-off-by: Wei Yang <weiyang@linux.vnet.ibm.com>
>
>Acked-by: Alex Williamson <alex.williamson@redhat.com>
>
>> ---
>>  drivers/iommu/iommu.c |    3 +++
>>  1 files changed, 3 insertions(+), 0 deletions(-)
>> 
>> diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
>> index fbe9ca7..43396f0 100644
>> --- a/drivers/iommu/iommu.c
>> +++ b/drivers/iommu/iommu.c
>> @@ -379,6 +379,9 @@ void iommu_group_remove_device(struct device *dev)
>>  	struct iommu_group *group = dev->iommu_group;
>>  	struct iommu_device *tmp_device, *device = NULL;
>>  
>> +	if (WARN_ON(!group))
>> +		return;
>> +
>>  	/* Pre-notify listeners that a device is being removed. */
>>  	blocking_notifier_call_chain(&group->notifier,
>>  				     IOMMU_GROUP_NOTIFY_DEL_DEVICE, dev);
>
>

-- 
Richard Yang
Help you, Help me

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

end of thread, other threads:[~2013-09-03  3:15 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-08-23  1:55 [PATCH] iommu: WARN_ON when removing a device with no iommu_group associated Wei Yang
2013-08-23  3:33 ` Alex Williamson
2013-09-03  3:15   ` Wei Yang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).