linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [sparc-next] SPARC64: Fix sun4v DMA panic
@ 2017-07-11 21:34 Tushar Dave
  2017-07-12  7:21 ` Christoph Hellwig
  2017-07-12 15:13 ` David Miller
  0 siblings, 2 replies; 3+ messages in thread
From: Tushar Dave @ 2017-07-11 21:34 UTC (permalink / raw)
  To: davem, chris.hyser, sowmini.varadhan, egtvedt, dan.carpenter,
	krzk, bart.vanassche, sparclinux
  Cc: linux-kernel, hch, mroos

64bit DMA only supported on sun4v equipped with ATU IOMMU HW.
'Commit b02c2b0bfd7ae ("sparc: remove arch specific dma_supported
implementations")' introduced a code that incorrectly allow
dma_supported() to succeed for 64bit dma mask even if system doesn't
have ATU IOMMU. This results into panic.

Fix it.

Reported-by: Meelis Roos <mroos@linux.ee>
Signed-off-by: Tushar Dave <tushar.n.dave@oracle.com>
---
 arch/sparc/kernel/pci_sun4v.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/arch/sparc/kernel/pci_sun4v.c b/arch/sparc/kernel/pci_sun4v.c
index 24f21c7..f10e2f7 100644
--- a/arch/sparc/kernel/pci_sun4v.c
+++ b/arch/sparc/kernel/pci_sun4v.c
@@ -673,12 +673,14 @@ static void dma_4v_unmap_sg(struct device *dev, struct scatterlist *sglist,
 static int dma_4v_supported(struct device *dev, u64 device_mask)
 {
 	struct iommu *iommu = dev->archdata.iommu;
-	u64 dma_addr_mask;
+	u64 dma_addr_mask = iommu->dma_addr_mask;
 
-	if (device_mask > DMA_BIT_MASK(32) && iommu->atu)
-		dma_addr_mask = iommu->atu->dma_addr_mask;
-	else
-		dma_addr_mask = iommu->dma_addr_mask;
+	if (device_mask > DMA_BIT_MASK(32)) {
+		if (iommu->atu)
+			dma_addr_mask = iommu->atu->dma_addr_mask;
+		else
+			return 0;
+	}
 
 	if ((device_mask & dma_addr_mask) == dma_addr_mask)
 		return 1;
-- 
1.9.1

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

* Re: [sparc-next] SPARC64: Fix sun4v DMA panic
  2017-07-11 21:34 [sparc-next] SPARC64: Fix sun4v DMA panic Tushar Dave
@ 2017-07-12  7:21 ` Christoph Hellwig
  2017-07-12 15:13 ` David Miller
  1 sibling, 0 replies; 3+ messages in thread
From: Christoph Hellwig @ 2017-07-12  7:21 UTC (permalink / raw)
  To: Tushar Dave
  Cc: davem, chris.hyser, sowmini.varadhan, egtvedt, dan.carpenter,
	krzk, bart.vanassche, sparclinux, linux-kernel, hch, mroos

On Tue, Jul 11, 2017 at 02:34:47PM -0700, Tushar Dave wrote:
> 64bit DMA only supported on sun4v equipped with ATU IOMMU HW.
> 'Commit b02c2b0bfd7ae ("sparc: remove arch specific dma_supported
> implementations")' introduced a code that incorrectly allow
> dma_supported() to succeed for 64bit dma mask even if system doesn't
> have ATU IOMMU. This results into panic.
> 
> Fix it.
> 
> Reported-by: Meelis Roos <mroos@linux.ee>
> Signed-off-by: Tushar Dave <tushar.n.dave@oracle.com>
> ---
>  arch/sparc/kernel/pci_sun4v.c | 12 +++++++-----
>  1 file changed, 7 insertions(+), 5 deletions(-)
> 
> diff --git a/arch/sparc/kernel/pci_sun4v.c b/arch/sparc/kernel/pci_sun4v.c
> index 24f21c7..f10e2f7 100644
> --- a/arch/sparc/kernel/pci_sun4v.c
> +++ b/arch/sparc/kernel/pci_sun4v.c
> @@ -673,12 +673,14 @@ static void dma_4v_unmap_sg(struct device *dev, struct scatterlist *sglist,
>  static int dma_4v_supported(struct device *dev, u64 device_mask)
>  {
>  	struct iommu *iommu = dev->archdata.iommu;
> -	u64 dma_addr_mask;
> +	u64 dma_addr_mask = iommu->dma_addr_mask;
>  
> -	if (device_mask > DMA_BIT_MASK(32) && iommu->atu)
> -		dma_addr_mask = iommu->atu->dma_addr_mask;
> -	else
> -		dma_addr_mask = iommu->dma_addr_mask;
> +	if (device_mask > DMA_BIT_MASK(32)) {
> +		if (iommu->atu)
> +			dma_addr_mask = iommu->atu->dma_addr_mask;
> +		else
> +			return 0;
> +	}

This would be more readable as:

	if (device_mask > DMA_BIT_MASK(32)) {
		if (!iommu->atu)
			return 0;
		dma_addr_mask = iommu->atu->dma_addr_mask;
	}

But except for that it looks fine to me:

Reviewed-by: Christoph Hellwig <hch@lst.de>

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

* Re: [sparc-next] SPARC64: Fix sun4v DMA panic
  2017-07-11 21:34 [sparc-next] SPARC64: Fix sun4v DMA panic Tushar Dave
  2017-07-12  7:21 ` Christoph Hellwig
@ 2017-07-12 15:13 ` David Miller
  1 sibling, 0 replies; 3+ messages in thread
From: David Miller @ 2017-07-12 15:13 UTC (permalink / raw)
  To: tushar.n.dave
  Cc: chris.hyser, sowmini.varadhan, egtvedt, dan.carpenter, krzk,
	bart.vanassche, sparclinux, linux-kernel, hch, mroos

From: Tushar Dave <tushar.n.dave@oracle.com>
Date: Tue, 11 Jul 2017 14:34:47 -0700

> 64bit DMA only supported on sun4v equipped with ATU IOMMU HW.
> 'Commit b02c2b0bfd7ae ("sparc: remove arch specific dma_supported
> implementations")' introduced a code that incorrectly allow
> dma_supported() to succeed for 64bit dma mask even if system doesn't
> have ATU IOMMU. This results into panic.
> 
> Fix it.
> 
> Reported-by: Meelis Roos <mroos@linux.ee>
> Signed-off-by: Tushar Dave <tushar.n.dave@oracle.com>

Applied to the 'sparc' tree, thanks.

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

end of thread, other threads:[~2017-07-12 15:13 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-07-11 21:34 [sparc-next] SPARC64: Fix sun4v DMA panic Tushar Dave
2017-07-12  7:21 ` Christoph Hellwig
2017-07-12 15:13 ` David Miller

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