Skip to contentSkip to conversation

kernel/dma/direct: Do not include SME mask in the DMA supported check

PATCH Superseded Lendacky, Thomas 2 participants 6 messages Dec 13, 2018 – Dec 17, 2018 DMA mapping helpers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 kernel/dma/direct: Do not include SME mask in the DMA supported check

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")
---
 kernel/dma/direct.c |    7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
kernel/dma/direct.c +6 -1
index 22a12ab..375c77e 100644
@@ -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)
#1 lore raw

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

#2 lore raw
Quoted 2 lines · Christoph Hellwig

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

Quoted 1 line
#3 lore raw
Quoted 7 lines · Tom Lendacky
Quoted 2 lines · Christoph Hellwig

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

Quoted 5 lines

Thanks,
Tom

Quoted 1 line
#4 lore raw

PATCH RESEND 1/1 kernel/dma/direct: Do not include SME mask in the DMA supported check

In reply to Lendacky, Thomas

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")
---
 kernel/dma/direct.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
kernel/dma/direct.c +6 -1
index 22a12ab..375c77e 100644
@@ -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)
Signature · 1 line
1.9.1