All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] kernel/dma/direct: Do not include SME mask in the DMA supported check
@ 2018-12-13 22:51 ` Lendacky, Thomas
  0 siblings, 0 replies; 11+ messages in thread
From: Lendacky, Thomas @ 2018-12-13 22:51 UTC (permalink / raw)
  To: iommu@lists.linux-foundation.org
  Cc: Benjamin Herrenschmidt, linuxppc-dev@lists.ozlabs.org,
	Alexander Duyck, linux-kernel@vger.kernel.org, Greg KH,
	Robin Murphy, Christoph Hellwig, Guenter Roeck

The dma_direct_supported() function intends to check the DMA mask against
specific values. However, the phys_to_dma() function includes the SME
encryption mask, which defeats the intended purpose of the check. This
results in drivers that support less than 48-bit DMA (SME encryption mask
is bit 47) from being able to set the DMA mask successfully when SME is
active, which results in the driver failing to initialize.

Change the function used to check the mask from phys_to_dma() to
__phys_to_dma() so that the SME encryption mask is not part of the check.

Fixes: c1d0af1a1d5d ("kernel/dma/direct: take DMA offset into account in dma_direct_supported")
Signed-off-by: Tom Lendacky <thomas.lendacky@amd.com>
---
 kernel/dma/direct.c |    7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/kernel/dma/direct.c b/kernel/dma/direct.c
index 22a12ab..375c77e 100644
--- a/kernel/dma/direct.c
+++ b/kernel/dma/direct.c
@@ -309,7 +309,12 @@ int dma_direct_supported(struct device *dev, u64 mask)
 
 	min_mask = min_t(u64, min_mask, (max_pfn - 1) << PAGE_SHIFT);
 
-	return mask >= phys_to_dma(dev, min_mask);
+	/*
+	 * This check needs to be against the actual bit mask value, so
+	 * use __phys_to_dma() here so that the SME encryption mask isn't
+	 * part of the check.
+	 */
+	return mask >= __phys_to_dma(dev, min_mask);
 }
 
 int dma_direct_mapping_error(struct device *dev, dma_addr_t dma_addr)


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

* [PATCH] kernel/dma/direct: Do not include SME mask in the DMA supported check
@ 2018-12-13 22:51 ` Lendacky, Thomas
  0 siblings, 0 replies; 11+ messages in thread
From: Lendacky, Thomas @ 2018-12-13 22:51 UTC (permalink / raw)
  To: iommu@lists.linux-foundation.org
  Cc: linuxppc-dev@lists.ozlabs.org, Alexander Duyck,
	linux-kernel@vger.kernel.org, Greg KH, Robin Murphy,
	Christoph Hellwig, Guenter Roeck

The dma_direct_supported() function intends to check the DMA mask against
specific values. However, the phys_to_dma() function includes the SME
encryption mask, which defeats the intended purpose of the check. This
results in drivers that support less than 48-bit DMA (SME encryption mask
is bit 47) from being able to set the DMA mask successfully when SME is
active, which results in the driver failing to initialize.

Change the function used to check the mask from phys_to_dma() to
__phys_to_dma() so that the SME encryption mask is not part of the check.

Fixes: c1d0af1a1d5d ("kernel/dma/direct: take DMA offset into account in dma_direct_supported")
Signed-off-by: Tom Lendacky <thomas.lendacky@amd.com>
---
 kernel/dma/direct.c |    7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/kernel/dma/direct.c b/kernel/dma/direct.c
index 22a12ab..375c77e 100644
--- a/kernel/dma/direct.c
+++ b/kernel/dma/direct.c
@@ -309,7 +309,12 @@ int dma_direct_supported(struct device *dev, u64 mask)
 
 	min_mask = min_t(u64, min_mask, (max_pfn - 1) << PAGE_SHIFT);
 
-	return mask >= phys_to_dma(dev, min_mask);
+	/*
+	 * This check needs to be against the actual bit mask value, so
+	 * use __phys_to_dma() here so that the SME encryption mask isn't
+	 * part of the check.
+	 */
+	return mask >= __phys_to_dma(dev, min_mask);
 }
 
 int dma_direct_mapping_error(struct device *dev, dma_addr_t dma_addr)


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

* Re: [PATCH] kernel/dma/direct: Do not include SME mask in the DMA supported check
  2018-12-13 22:51 ` Lendacky, Thomas
@ 2018-12-15 10:55   ` Christoph Hellwig
  -1 siblings, 0 replies; 11+ messages in thread
From: Christoph Hellwig @ 2018-12-15 10:55 UTC (permalink / raw)
  To: Lendacky, Thomas
  Cc: iommu@lists.linux-foundation.org, Benjamin Herrenschmidt,
	linuxppc-dev@lists.ozlabs.org, Alexander Duyck,
	linux-kernel@vger.kernel.org, Greg KH, Robin Murphy,
	Christoph Hellwig, Guenter Roeck

The mail seems to be so oddly encoded so that git-am fails on it.  Can
you resend as plain text?

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

* Re: [PATCH] kernel/dma/direct: Do not include SME mask in the DMA supported check
@ 2018-12-15 10:55   ` Christoph Hellwig
  0 siblings, 0 replies; 11+ messages in thread
From: Christoph Hellwig @ 2018-12-15 10:55 UTC (permalink / raw)
  To: Lendacky, Thomas
  Cc: linux-kernel@vger.kernel.org, Alexander Duyck,
	iommu@lists.linux-foundation.org, Greg KH,
	linuxppc-dev@lists.ozlabs.org, Christoph Hellwig, Guenter Roeck,
	Robin Murphy

The mail seems to be so oddly encoded so that git-am fails on it.  Can
you resend as plain text?

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

* Re: [PATCH] kernel/dma/direct: Do not include SME mask in the DMA supported check
  2018-12-15 10:55   ` Christoph Hellwig
  (?)
@ 2018-12-16 23:41       ` Lendacky, Thomas
  -1 siblings, 0 replies; 11+ messages in thread
From: Lendacky, Thomas @ 2018-12-16 23:41 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: Benjamin Herrenschmidt,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org,
	Greg KH, linuxppc-dev-uLR06cmDAlY/bJ5BZ2RsiQ@public.gmane.org,
	Guenter Roeck, Robin Murphy

On 12/15/2018 04:55 AM, Christoph Hellwig wrote:
> The mail seems to be so oddly encoded so that git-am fails on it.  Can
> you resend as plain text?

Hmmm... not sure what happened with that, but yeah, looking at the message
source shows something strange went on. Let me take a look and I'll try to
get a good version to you tommorow (Monday).

Thanks,
Tom

> 

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

* Re: [PATCH] kernel/dma/direct: Do not include SME mask in the DMA supported check
@ 2018-12-16 23:41       ` Lendacky, Thomas
  0 siblings, 0 replies; 11+ messages in thread
From: Lendacky, Thomas @ 2018-12-16 23:41 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: linux-kernel@vger.kernel.org, Alexander Duyck,
	iommu@lists.linux-foundation.org, Greg KH,
	linuxppc-dev@lists.ozlabs.org, Guenter Roeck, Robin Murphy

On 12/15/2018 04:55 AM, Christoph Hellwig wrote:
> The mail seems to be so oddly encoded so that git-am fails on it.  Can
> you resend as plain text?

Hmmm... not sure what happened with that, but yeah, looking at the message
source shows something strange went on. Let me take a look and I'll try to
get a good version to you tommorow (Monday).

Thanks,
Tom

> 

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

* Re: [PATCH] kernel/dma/direct: Do not include SME mask in the DMA supported check
@ 2018-12-16 23:41       ` Lendacky, Thomas
  0 siblings, 0 replies; 11+ messages in thread
From: Lendacky, Thomas @ 2018-12-16 23:41 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: iommu@lists.linux-foundation.org, Benjamin Herrenschmidt,
	linuxppc-dev@lists.ozlabs.org, Alexander Duyck,
	linux-kernel@vger.kernel.org, Greg KH, Robin Murphy,
	Guenter Roeck

On 12/15/2018 04:55 AM, Christoph Hellwig wrote:
> The mail seems to be so oddly encoded so that git-am fails on it.  Can
> you resend as plain text?

Hmmm... not sure what happened with that, but yeah, looking at the message
source shows something strange went on. Let me take a look and I'll try to
get a good version to you tommorow (Monday).

Thanks,
Tom

> 

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

* Re: [PATCH] kernel/dma/direct: Do not include SME mask in the DMA supported check
  2018-12-16 23:41       ` Lendacky, Thomas
@ 2018-12-17 14:49         ` Lendacky, Thomas
  -1 siblings, 0 replies; 11+ messages in thread
From: Lendacky, Thomas @ 2018-12-17 14:49 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: iommu@lists.linux-foundation.org, Benjamin Herrenschmidt,
	linuxppc-dev@lists.ozlabs.org, Alexander Duyck,
	linux-kernel@vger.kernel.org, Greg KH, Robin Murphy,
	Guenter Roeck

On 12/16/2018 05:41 PM, Tom Lendacky wrote:
> On 12/15/2018 04:55 AM, Christoph Hellwig wrote:
>> The mail seems to be so oddly encoded so that git-am fails on it.  Can
>> you resend as plain text?
> 
> Hmmm... not sure what happened with that, but yeah, looking at the message
> source shows something strange went on. Let me take a look and I'll try to
> get a good version to you tommorow (Monday).

Must have been something with stgit... just resent using git format-patch
and git send-email and it looks ok.  Let me know if it's still not right
when it gets to you.

Thanks,
Tom

> 
> Thanks,
> Tom
> 
>>

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

* Re: [PATCH] kernel/dma/direct: Do not include SME mask in the DMA supported check
@ 2018-12-17 14:49         ` Lendacky, Thomas
  0 siblings, 0 replies; 11+ messages in thread
From: Lendacky, Thomas @ 2018-12-17 14:49 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: linux-kernel@vger.kernel.org, Alexander Duyck,
	iommu@lists.linux-foundation.org, Greg KH,
	linuxppc-dev@lists.ozlabs.org, Guenter Roeck, Robin Murphy

On 12/16/2018 05:41 PM, Tom Lendacky wrote:
> On 12/15/2018 04:55 AM, Christoph Hellwig wrote:
>> The mail seems to be so oddly encoded so that git-am fails on it.  Can
>> you resend as plain text?
> 
> Hmmm... not sure what happened with that, but yeah, looking at the message
> source shows something strange went on. Let me take a look and I'll try to
> get a good version to you tommorow (Monday).

Must have been something with stgit... just resent using git format-patch
and git send-email and it looks ok.  Let me know if it's still not right
when it gets to you.

Thanks,
Tom

> 
> Thanks,
> Tom
> 
>>

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

* [PATCH] kernel/dma/direct: Do not include SME mask in the DMA supported check
@ 2018-12-22 16:32 Lendacky, Thomas
  2019-01-10 19:13 ` Greg KH
  0 siblings, 1 reply; 11+ messages in thread
From: Lendacky, Thomas @ 2018-12-22 16:32 UTC (permalink / raw)
  To: stable@vger.kernel.org; +Cc: Greg KH, Sasha Levin

commit c92a54cfa0257e8ffd66b2a17d49e9c0bd4b769f upstream

This fix appears in 4.20, but dma_direct_supported() was changed in 4.20
such that the original version of the fix will not apply to previous
versions of the kernel. The fix only applies to the 4.19-stable tree and
has been backported for that tree.

The dma_direct_supported() function intends to check the DMA mask against
specific values. However, the phys_to_dma() function includes the SME
encryption mask, which defeats the intended purpose of the check. This
results in drivers that support less than 48-bit DMA (SME encryption mask
is bit 47) from being able to set the DMA mask successfully when SME is
active, which results in the driver failing to initialize.

Change the function used to check the mask from phys_to_dma() to
__phys_to_dma() so that the SME encryption mask is not part of the check.

Fixes: c1d0af1a1d5d ("kernel/dma/direct: take DMA offset into account in dma_direct_supported")
Cc: <stable@vger.kernel.org> # 4.19.x
Signed-off-by: Tom Lendacky <thomas.lendacky@amd.com>
---
 kernel/dma/direct.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/kernel/dma/direct.c b/kernel/dma/direct.c
index de87b02..1d2f147 100644
--- a/kernel/dma/direct.c
+++ b/kernel/dma/direct.c
@@ -168,7 +168,12 @@ int dma_direct_map_sg(struct device *dev, struct scatterlist *sgl, int nents,
 int dma_direct_supported(struct device *dev, u64 mask)
 {
 #ifdef CONFIG_ZONE_DMA
-	if (mask < phys_to_dma(dev, DMA_BIT_MASK(ARCH_ZONE_DMA_BITS)))
+	/*
+	 * This check needs to be against the actual bit mask value, so
+	 * use __phys_to_dma() here so that the SME encryption mask isn't
+	 * part of the check.
+	 */
+	if (mask < __phys_to_dma(dev, DMA_BIT_MASK(ARCH_ZONE_DMA_BITS)))
 		return 0;
 #else
 	/*
@@ -176,8 +181,12 @@ int dma_direct_supported(struct device *dev, u64 mask)
 	 * to be able to satisfy them - either by not supporting more physical
 	 * memory, or by providing a ZONE_DMA32.  If neither is the case, the
 	 * architecture needs to use an IOMMU instead of the direct mapping.
+	 *
+	 * This check needs to be against the actual bit mask value, so
+	 * use __phys_to_dma() here so that the SME encryption mask isn't
+	 * part of the check.
 	 */
-	if (mask < phys_to_dma(dev, DMA_BIT_MASK(32)))
+	if (mask < __phys_to_dma(dev, DMA_BIT_MASK(32)))
 		return 0;
 #endif
 	/*
-- 
1.9.1

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

* Re: [PATCH] kernel/dma/direct: Do not include SME mask in the DMA supported check
  2018-12-22 16:32 [PATCH] kernel/dma/direct: Do not include SME mask in the DMA supported check Lendacky, Thomas
@ 2019-01-10 19:13 ` Greg KH
  0 siblings, 0 replies; 11+ messages in thread
From: Greg KH @ 2019-01-10 19:13 UTC (permalink / raw)
  To: Lendacky, Thomas; +Cc: stable@vger.kernel.org, Sasha Levin

On Sat, Dec 22, 2018 at 04:32:40PM +0000, Lendacky, Thomas wrote:
> commit c92a54cfa0257e8ffd66b2a17d49e9c0bd4b769f upstream
> 
> This fix appears in 4.20, but dma_direct_supported() was changed in 4.20
> such that the original version of the fix will not apply to previous
> versions of the kernel. The fix only applies to the 4.19-stable tree and
> has been backported for that tree.
> 
> The dma_direct_supported() function intends to check the DMA mask against
> specific values. However, the phys_to_dma() function includes the SME
> encryption mask, which defeats the intended purpose of the check. This
> results in drivers that support less than 48-bit DMA (SME encryption mask
> is bit 47) from being able to set the DMA mask successfully when SME is
> active, which results in the driver failing to initialize.
> 
> Change the function used to check the mask from phys_to_dma() to
> __phys_to_dma() so that the SME encryption mask is not part of the check.
> 
> Fixes: c1d0af1a1d5d ("kernel/dma/direct: take DMA offset into account in dma_direct_supported")
> Cc: <stable@vger.kernel.org> # 4.19.x
> Signed-off-by: Tom Lendacky <thomas.lendacky@amd.com>
> ---
>  kernel/dma/direct.c | 13 +++++++++++--
>  1 file changed, 11 insertions(+), 2 deletions(-)

Now queued up, thanks.

greg k-h

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

end of thread, other threads:[~2019-01-10 19:13 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-12-22 16:32 [PATCH] kernel/dma/direct: Do not include SME mask in the DMA supported check Lendacky, Thomas
2019-01-10 19:13 ` Greg KH
  -- strict thread matches above, loose matches on Subject: below --
2018-12-13 22:51 Lendacky, Thomas
2018-12-13 22:51 ` Lendacky, Thomas
2018-12-15 10:55 ` Christoph Hellwig
2018-12-15 10:55   ` Christoph Hellwig
     [not found]   ` <20181215105510.GA1806-jcswGhMUV9g@public.gmane.org>
2018-12-16 23:41     ` Lendacky, Thomas
2018-12-16 23:41       ` Lendacky, Thomas
2018-12-16 23:41       ` Lendacky, Thomas
2018-12-17 14:49       ` Lendacky, Thomas
2018-12-17 14:49         ` Lendacky, Thomas

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.