linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] habanalabs: Stop using iommu_present()
@ 2022-04-05 13:46 Robin Murphy
  2022-04-10 10:59 ` Oded Gabbay
  0 siblings, 1 reply; 3+ messages in thread
From: Robin Murphy @ 2022-04-05 13:46 UTC (permalink / raw)
  To: ogabbay, arnd, gregkh; +Cc: linux-kernel, iommu

Even if an IOMMU might be present for some PCI segment in the system,
that doesn't necessarily mean it provides translation for the device
we care about. Replace iommu_present() with a more appropriate check.

Signed-off-by: Robin Murphy <robin.murphy@arm.com>
---
 drivers/misc/habanalabs/gaudi/gaudi.c | 8 ++++----
 drivers/misc/habanalabs/goya/goya.c   | 8 ++++----
 2 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/drivers/misc/habanalabs/gaudi/gaudi.c b/drivers/misc/habanalabs/gaudi/gaudi.c
index 21c2b678ff72..5dc66dc7618e 100644
--- a/drivers/misc/habanalabs/gaudi/gaudi.c
+++ b/drivers/misc/habanalabs/gaudi/gaudi.c
@@ -6133,7 +6133,7 @@ static int gaudi_debugfs_read32(struct hl_device *hdev, u64 addr,
 			rc = -EIO;
 
 	} else if (addr >= HOST_PHYS_BASE && addr < host_phys_end &&
-			user_address && !iommu_present(&pci_bus_type)) {
+			user_address && !device_iommu_mapped(&hdev->pdev->dev)) {
 
 		*val = *(u32 *) phys_to_virt(addr - HOST_PHYS_BASE);
 
@@ -6176,7 +6176,7 @@ static int gaudi_debugfs_write32(struct hl_device *hdev, u64 addr,
 			rc = -EIO;
 
 	} else if (addr >= HOST_PHYS_BASE && addr < host_phys_end &&
-			user_address && !iommu_present(&pci_bus_type)) {
+			user_address && !device_iommu_mapped(&hdev->pdev->dev)) {
 
 		*(u32 *) phys_to_virt(addr - HOST_PHYS_BASE) = val;
 
@@ -6223,7 +6223,7 @@ static int gaudi_debugfs_read64(struct hl_device *hdev, u64 addr,
 			rc = -EIO;
 
 	} else if (addr >= HOST_PHYS_BASE && addr < host_phys_end &&
-			user_address && !iommu_present(&pci_bus_type)) {
+			user_address && !device_iommu_mapped(&hdev->pdev->dev)) {
 
 		*val = *(u64 *) phys_to_virt(addr - HOST_PHYS_BASE);
 
@@ -6268,7 +6268,7 @@ static int gaudi_debugfs_write64(struct hl_device *hdev, u64 addr,
 			rc = -EIO;
 
 	} else if (addr >= HOST_PHYS_BASE && addr < host_phys_end &&
-			user_address && !iommu_present(&pci_bus_type)) {
+			user_address && !device_iommu_mapped(&hdev->pdev->dev)) {
 
 		*(u64 *) phys_to_virt(addr - HOST_PHYS_BASE) = val;
 
diff --git a/drivers/misc/habanalabs/goya/goya.c b/drivers/misc/habanalabs/goya/goya.c
index ec9358bcbf0b..0c455bf460f4 100644
--- a/drivers/misc/habanalabs/goya/goya.c
+++ b/drivers/misc/habanalabs/goya/goya.c
@@ -4309,7 +4309,7 @@ static int goya_debugfs_read32(struct hl_device *hdev, u64 addr,
 			rc = -EIO;
 
 	} else if (addr >= HOST_PHYS_BASE && addr < host_phys_end &&
-			user_address && !iommu_present(&pci_bus_type)) {
+			user_address && !device_iommu_mapped(&hdev->pdev->dev)) {
 		*val = *(u32 *) phys_to_virt(addr - HOST_PHYS_BASE);
 
 	} else {
@@ -4369,7 +4369,7 @@ static int goya_debugfs_write32(struct hl_device *hdev, u64 addr,
 			rc = -EIO;
 
 	} else if (addr >= HOST_PHYS_BASE && addr < host_phys_end &&
-			user_address && !iommu_present(&pci_bus_type)) {
+			user_address && !device_iommu_mapped(&hdev->pdev->dev)) {
 		*(u32 *) phys_to_virt(addr - HOST_PHYS_BASE) = val;
 
 	} else {
@@ -4418,7 +4418,7 @@ static int goya_debugfs_read64(struct hl_device *hdev, u64 addr,
 			rc = -EIO;
 
 	} else if (addr >= HOST_PHYS_BASE && addr < host_phys_end &&
-			user_address && !iommu_present(&pci_bus_type)) {
+			user_address && !device_iommu_mapped(&hdev->pdev->dev)) {
 		*val = *(u64 *) phys_to_virt(addr - HOST_PHYS_BASE);
 
 	} else {
@@ -4465,7 +4465,7 @@ static int goya_debugfs_write64(struct hl_device *hdev, u64 addr,
 			rc = -EIO;
 
 	} else if (addr >= HOST_PHYS_BASE && addr < host_phys_end &&
-			user_address && !iommu_present(&pci_bus_type)) {
+			user_address && !device_iommu_mapped(&hdev->pdev->dev)) {
 		*(u64 *) phys_to_virt(addr - HOST_PHYS_BASE) = val;
 
 	} else {
-- 
2.28.0.dirty


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

* Re: [PATCH] habanalabs: Stop using iommu_present()
  2022-04-05 13:46 [PATCH] habanalabs: Stop using iommu_present() Robin Murphy
@ 2022-04-10 10:59 ` Oded Gabbay
  2022-04-11 10:43   ` Robin Murphy
  0 siblings, 1 reply; 3+ messages in thread
From: Oded Gabbay @ 2022-04-10 10:59 UTC (permalink / raw)
  To: Robin Murphy
  Cc: Arnd Bergmann, Greg Kroah-Hartman,
	Linux-Kernel@Vger. Kernel. Org,
	list@263.net:IOMMU DRIVERS
	<iommu@lists.linux-foundation.org>,
	Joerg Roedel <joro@8bytes.org>,

On Tue, Apr 5, 2022 at 4:46 PM Robin Murphy <robin.murphy@arm.com> wrote:
>
> Even if an IOMMU might be present for some PCI segment in the system,
> that doesn't necessarily mean it provides translation for the device
> we care about. Replace iommu_present() with a more appropriate check.
>
> Signed-off-by: Robin Murphy <robin.murphy@arm.com>
> ---
>  drivers/misc/habanalabs/gaudi/gaudi.c | 8 ++++----
>  drivers/misc/habanalabs/goya/goya.c   | 8 ++++----
>  2 files changed, 8 insertions(+), 8 deletions(-)
>
> diff --git a/drivers/misc/habanalabs/gaudi/gaudi.c b/drivers/misc/habanalabs/gaudi/gaudi.c
> index 21c2b678ff72..5dc66dc7618e 100644
> --- a/drivers/misc/habanalabs/gaudi/gaudi.c
> +++ b/drivers/misc/habanalabs/gaudi/gaudi.c
> @@ -6133,7 +6133,7 @@ static int gaudi_debugfs_read32(struct hl_device *hdev, u64 addr,
>                         rc = -EIO;
>
>         } else if (addr >= HOST_PHYS_BASE && addr < host_phys_end &&
> -                       user_address && !iommu_present(&pci_bus_type)) {
> +                       user_address && !device_iommu_mapped(&hdev->pdev->dev)) {
>
>                 *val = *(u32 *) phys_to_virt(addr - HOST_PHYS_BASE);
>
> @@ -6176,7 +6176,7 @@ static int gaudi_debugfs_write32(struct hl_device *hdev, u64 addr,
>                         rc = -EIO;
>
>         } else if (addr >= HOST_PHYS_BASE && addr < host_phys_end &&
> -                       user_address && !iommu_present(&pci_bus_type)) {
> +                       user_address && !device_iommu_mapped(&hdev->pdev->dev)) {
>
>                 *(u32 *) phys_to_virt(addr - HOST_PHYS_BASE) = val;
>
> @@ -6223,7 +6223,7 @@ static int gaudi_debugfs_read64(struct hl_device *hdev, u64 addr,
>                         rc = -EIO;
>
>         } else if (addr >= HOST_PHYS_BASE && addr < host_phys_end &&
> -                       user_address && !iommu_present(&pci_bus_type)) {
> +                       user_address && !device_iommu_mapped(&hdev->pdev->dev)) {
>
>                 *val = *(u64 *) phys_to_virt(addr - HOST_PHYS_BASE);
>
> @@ -6268,7 +6268,7 @@ static int gaudi_debugfs_write64(struct hl_device *hdev, u64 addr,
>                         rc = -EIO;
>
>         } else if (addr >= HOST_PHYS_BASE && addr < host_phys_end &&
> -                       user_address && !iommu_present(&pci_bus_type)) {
> +                       user_address && !device_iommu_mapped(&hdev->pdev->dev)) {
>
>                 *(u64 *) phys_to_virt(addr - HOST_PHYS_BASE) = val;
>
> diff --git a/drivers/misc/habanalabs/goya/goya.c b/drivers/misc/habanalabs/goya/goya.c
> index ec9358bcbf0b..0c455bf460f4 100644
> --- a/drivers/misc/habanalabs/goya/goya.c
> +++ b/drivers/misc/habanalabs/goya/goya.c
> @@ -4309,7 +4309,7 @@ static int goya_debugfs_read32(struct hl_device *hdev, u64 addr,
>                         rc = -EIO;
>
>         } else if (addr >= HOST_PHYS_BASE && addr < host_phys_end &&
> -                       user_address && !iommu_present(&pci_bus_type)) {
> +                       user_address && !device_iommu_mapped(&hdev->pdev->dev)) {
>                 *val = *(u32 *) phys_to_virt(addr - HOST_PHYS_BASE);
>
>         } else {
> @@ -4369,7 +4369,7 @@ static int goya_debugfs_write32(struct hl_device *hdev, u64 addr,
>                         rc = -EIO;
>
>         } else if (addr >= HOST_PHYS_BASE && addr < host_phys_end &&
> -                       user_address && !iommu_present(&pci_bus_type)) {
> +                       user_address && !device_iommu_mapped(&hdev->pdev->dev)) {
>                 *(u32 *) phys_to_virt(addr - HOST_PHYS_BASE) = val;
>
>         } else {
> @@ -4418,7 +4418,7 @@ static int goya_debugfs_read64(struct hl_device *hdev, u64 addr,
>                         rc = -EIO;
>
>         } else if (addr >= HOST_PHYS_BASE && addr < host_phys_end &&
> -                       user_address && !iommu_present(&pci_bus_type)) {
> +                       user_address && !device_iommu_mapped(&hdev->pdev->dev)) {
>                 *val = *(u64 *) phys_to_virt(addr - HOST_PHYS_BASE);
>
>         } else {
> @@ -4465,7 +4465,7 @@ static int goya_debugfs_write64(struct hl_device *hdev, u64 addr,
>                         rc = -EIO;
>
>         } else if (addr >= HOST_PHYS_BASE && addr < host_phys_end &&
> -                       user_address && !iommu_present(&pci_bus_type)) {
> +                       user_address && !device_iommu_mapped(&hdev->pdev->dev)) {
>                 *(u64 *) phys_to_virt(addr - HOST_PHYS_BASE) = val;
>
>         } else {
> --
> 2.28.0.dirty
>

Hi Robin,
Can you please rebase this over the latest habanalabs-next ?
The code was totally changed, but I think your core change is
definitely relevant.
Thanks,
Oded

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

* Re: [PATCH] habanalabs: Stop using iommu_present()
  2022-04-10 10:59 ` Oded Gabbay
@ 2022-04-11 10:43   ` Robin Murphy
  0 siblings, 0 replies; 3+ messages in thread
From: Robin Murphy @ 2022-04-11 10:43 UTC (permalink / raw)
  To: Oded Gabbay
  Cc: Arnd Bergmann, Greg Kroah-Hartman,
	Linux-Kernel@Vger. Kernel. Org, list@263.net:IOMMU DRIVERS,
	Joerg Roedel, iommu

On 2022-04-10 11:59, Oded Gabbay wrote:
> On Tue, Apr 5, 2022 at 4:46 PM Robin Murphy <robin.murphy@arm.com> wrote:
>>
>> Even if an IOMMU might be present for some PCI segment in the system,
>> that doesn't necessarily mean it provides translation for the device
>> we care about. Replace iommu_present() with a more appropriate check.
>>
>> Signed-off-by: Robin Murphy <robin.murphy@arm.com>
>> ---
>>   drivers/misc/habanalabs/gaudi/gaudi.c | 8 ++++----
>>   drivers/misc/habanalabs/goya/goya.c   | 8 ++++----
>>   2 files changed, 8 insertions(+), 8 deletions(-)
>>
>> diff --git a/drivers/misc/habanalabs/gaudi/gaudi.c b/drivers/misc/habanalabs/gaudi/gaudi.c
>> index 21c2b678ff72..5dc66dc7618e 100644
>> --- a/drivers/misc/habanalabs/gaudi/gaudi.c
>> +++ b/drivers/misc/habanalabs/gaudi/gaudi.c
>> @@ -6133,7 +6133,7 @@ static int gaudi_debugfs_read32(struct hl_device *hdev, u64 addr,
>>                          rc = -EIO;
>>
>>          } else if (addr >= HOST_PHYS_BASE && addr < host_phys_end &&
>> -                       user_address && !iommu_present(&pci_bus_type)) {
>> +                       user_address && !device_iommu_mapped(&hdev->pdev->dev)) {
>>
>>                  *val = *(u32 *) phys_to_virt(addr - HOST_PHYS_BASE);
>>
>> @@ -6176,7 +6176,7 @@ static int gaudi_debugfs_write32(struct hl_device *hdev, u64 addr,
>>                          rc = -EIO;
>>
>>          } else if (addr >= HOST_PHYS_BASE && addr < host_phys_end &&
>> -                       user_address && !iommu_present(&pci_bus_type)) {
>> +                       user_address && !device_iommu_mapped(&hdev->pdev->dev)) {
>>
>>                  *(u32 *) phys_to_virt(addr - HOST_PHYS_BASE) = val;
>>
>> @@ -6223,7 +6223,7 @@ static int gaudi_debugfs_read64(struct hl_device *hdev, u64 addr,
>>                          rc = -EIO;
>>
>>          } else if (addr >= HOST_PHYS_BASE && addr < host_phys_end &&
>> -                       user_address && !iommu_present(&pci_bus_type)) {
>> +                       user_address && !device_iommu_mapped(&hdev->pdev->dev)) {
>>
>>                  *val = *(u64 *) phys_to_virt(addr - HOST_PHYS_BASE);
>>
>> @@ -6268,7 +6268,7 @@ static int gaudi_debugfs_write64(struct hl_device *hdev, u64 addr,
>>                          rc = -EIO;
>>
>>          } else if (addr >= HOST_PHYS_BASE && addr < host_phys_end &&
>> -                       user_address && !iommu_present(&pci_bus_type)) {
>> +                       user_address && !device_iommu_mapped(&hdev->pdev->dev)) {
>>
>>                  *(u64 *) phys_to_virt(addr - HOST_PHYS_BASE) = val;
>>
>> diff --git a/drivers/misc/habanalabs/goya/goya.c b/drivers/misc/habanalabs/goya/goya.c
>> index ec9358bcbf0b..0c455bf460f4 100644
>> --- a/drivers/misc/habanalabs/goya/goya.c
>> +++ b/drivers/misc/habanalabs/goya/goya.c
>> @@ -4309,7 +4309,7 @@ static int goya_debugfs_read32(struct hl_device *hdev, u64 addr,
>>                          rc = -EIO;
>>
>>          } else if (addr >= HOST_PHYS_BASE && addr < host_phys_end &&
>> -                       user_address && !iommu_present(&pci_bus_type)) {
>> +                       user_address && !device_iommu_mapped(&hdev->pdev->dev)) {
>>                  *val = *(u32 *) phys_to_virt(addr - HOST_PHYS_BASE);
>>
>>          } else {
>> @@ -4369,7 +4369,7 @@ static int goya_debugfs_write32(struct hl_device *hdev, u64 addr,
>>                          rc = -EIO;
>>
>>          } else if (addr >= HOST_PHYS_BASE && addr < host_phys_end &&
>> -                       user_address && !iommu_present(&pci_bus_type)) {
>> +                       user_address && !device_iommu_mapped(&hdev->pdev->dev)) {
>>                  *(u32 *) phys_to_virt(addr - HOST_PHYS_BASE) = val;
>>
>>          } else {
>> @@ -4418,7 +4418,7 @@ static int goya_debugfs_read64(struct hl_device *hdev, u64 addr,
>>                          rc = -EIO;
>>
>>          } else if (addr >= HOST_PHYS_BASE && addr < host_phys_end &&
>> -                       user_address && !iommu_present(&pci_bus_type)) {
>> +                       user_address && !device_iommu_mapped(&hdev->pdev->dev)) {
>>                  *val = *(u64 *) phys_to_virt(addr - HOST_PHYS_BASE);
>>
>>          } else {
>> @@ -4465,7 +4465,7 @@ static int goya_debugfs_write64(struct hl_device *hdev, u64 addr,
>>                          rc = -EIO;
>>
>>          } else if (addr >= HOST_PHYS_BASE && addr < host_phys_end &&
>> -                       user_address && !iommu_present(&pci_bus_type)) {
>> +                       user_address && !device_iommu_mapped(&hdev->pdev->dev)) {
>>                  *(u64 *) phys_to_virt(addr - HOST_PHYS_BASE) = val;
>>
>>          } else {
>> --
>> 2.28.0.dirty
>>
> 
> Hi Robin,
> Can you please rebase this over the latest habanalabs-next ?
> The code was totally changed, but I think your core change is
> definitely relevant.

Oh, lovely, that makes for a much nicer patch indeed! I'll spin a v2 
shortly.

Thanks,
Robin.

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

end of thread, other threads:[~2022-04-11 10:43 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-05 13:46 [PATCH] habanalabs: Stop using iommu_present() Robin Murphy
2022-04-10 10:59 ` Oded Gabbay
2022-04-11 10:43   ` Robin Murphy

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).