linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] dma-direct: use the correct size for dma_set_encrypted()
@ 2022-06-22 19:14 Dexuan Cui
  2022-06-23  5:43 ` Christoph Hellwig
  0 siblings, 1 reply; 5+ messages in thread
From: Dexuan Cui @ 2022-06-22 19:14 UTC (permalink / raw)
  To: hch, m.szyprowski, robin.murphy, iommu, linux-kernel
  Cc: linux-hyperv, mikelley, Andrea.Parri, Tianyu.Lan, Dexuan Cui

The third parameter of dma_set_encrypted() is a size in bytes rather than
the number of pages.

Fixes: 4d0564785bb0 ("dma-direct: factor out dma_set_{de,en}crypted helpers")
Signed-off-by: Dexuan Cui <decui@microsoft.com>
---
 kernel/dma/direct.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/kernel/dma/direct.c b/kernel/dma/direct.c
index e978f36e6be8..8d0b68a17042 100644
--- a/kernel/dma/direct.c
+++ b/kernel/dma/direct.c
@@ -357,7 +357,7 @@ void dma_direct_free(struct device *dev, size_t size,
 	} else {
 		if (IS_ENABLED(CONFIG_ARCH_HAS_DMA_CLEAR_UNCACHED))
 			arch_dma_clear_uncached(cpu_addr, size);
-		if (dma_set_encrypted(dev, cpu_addr, 1 << page_order))
+		if (dma_set_encrypted(dev, cpu_addr, size))
 			return;
 	}
 
@@ -392,7 +392,6 @@ void dma_direct_free_pages(struct device *dev, size_t size,
 		struct page *page, dma_addr_t dma_addr,
 		enum dma_data_direction dir)
 {
-	unsigned int page_order = get_order(size);
 	void *vaddr = page_address(page);
 
 	/* If cpu_addr is not from an atomic pool, dma_free_from_pool() fails */
@@ -400,7 +399,7 @@ void dma_direct_free_pages(struct device *dev, size_t size,
 	    dma_free_from_pool(dev, vaddr, size))
 		return;
 
-	if (dma_set_encrypted(dev, vaddr, 1 << page_order))
+	if (dma_set_encrypted(dev, vaddr, size))
 		return;
 	__dma_direct_free_pages(dev, page, size);
 }
-- 
2.25.1


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

* Re: [PATCH] dma-direct: use the correct size for dma_set_encrypted()
  2022-06-22 19:14 [PATCH] dma-direct: use the correct size for dma_set_encrypted() Dexuan Cui
@ 2022-06-23  5:43 ` Christoph Hellwig
  2022-06-23  7:00   ` Dexuan Cui
  0 siblings, 1 reply; 5+ messages in thread
From: Christoph Hellwig @ 2022-06-23  5:43 UTC (permalink / raw)
  To: Dexuan Cui
  Cc: hch, m.szyprowski, robin.murphy, iommu, linux-kernel,
	linux-hyperv, mikelley, Andrea.Parri, Tianyu.Lan

On Wed, Jun 22, 2022 at 12:14:24PM -0700, Dexuan Cui wrote:
> The third parameter of dma_set_encrypted() is a size in bytes rather than
> the number of pages.
> 
> Fixes: 4d0564785bb0 ("dma-direct: factor out dma_set_{de,en}crypted helpers")
> Signed-off-by: Dexuan Cui <decui@microsoft.com>

see:

commit 4a37f3dd9a83186cb88d44808ab35b78375082c9 (tag: dma-mapping-5.19-2022-05-25)
Author: Robin Murphy <robin.murphy@arm.com>
Date:   Fri May 20 18:10:13 2022 +0100

    dma-direct: don't over-decrypt memory

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

* RE: [PATCH] dma-direct: use the correct size for dma_set_encrypted()
  2022-06-23  5:43 ` Christoph Hellwig
@ 2022-06-23  7:00   ` Dexuan Cui
  2022-06-23  9:01     ` Robin Murphy
  2022-06-23 13:28     ` Christoph Hellwig
  0 siblings, 2 replies; 5+ messages in thread
From: Dexuan Cui @ 2022-06-23  7:00 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: m.szyprowski, robin.murphy, iommu, linux-kernel, linux-hyperv,
	Michael Kelley (LINUX),
	Andrea Parri, Tianyu Lan

> From: Christoph Hellwig <hch@lst.de>
> Sent: Wednesday, June 22, 2022 10:44 PM
> To: Dexuan Cui <decui@microsoft.com>
>  ...
> On Wed, Jun 22, 2022 at 12:14:24PM -0700, Dexuan Cui wrote:
> > The third parameter of dma_set_encrypted() is a size in bytes rather than
> > the number of pages.
> >
> > Fixes: 4d0564785bb0 ("dma-direct: factor out dma_set_{de,en}crypted
> helpers")
> > Signed-off-by: Dexuan Cui <decui@microsoft.com>
> 
> see:
> 
> commit 4a37f3dd9a83186cb88d44808ab35b78375082c9 (tag:
> dma-mapping-5.19-2022-05-25)
> Author: Robin Murphy <robin.murphy@arm.com>
> Date:   Fri May 20 18:10:13 2022 +0100
> 
>     dma-direct: don't over-decrypt memory

It looks like commit 4a37f3dd9a831 fixed a different issue?

Here my patch is for the latest mainline:

In dma_direct_alloc()'s error handling path, we pass 'size' to dma_set_encrypted():
  out_encrypt_pages:
	  if (dma_set_encrypted(dev, page_address(page), size))

However, in dma_direct_free(), we pass ' 1 << page_order ' to dma_set_encrypted().
I think the ' 1 << page_order' is incorrect and it should be 'size' as well?

Thanks,
-- Dexuan


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

* Re: [PATCH] dma-direct: use the correct size for dma_set_encrypted()
  2022-06-23  7:00   ` Dexuan Cui
@ 2022-06-23  9:01     ` Robin Murphy
  2022-06-23 13:28     ` Christoph Hellwig
  1 sibling, 0 replies; 5+ messages in thread
From: Robin Murphy @ 2022-06-23  9:01 UTC (permalink / raw)
  To: Dexuan Cui, Christoph Hellwig
  Cc: m.szyprowski, iommu, linux-kernel, linux-hyperv,
	Michael Kelley (LINUX),
	Andrea Parri, Tianyu Lan

On 2022-06-23 08:00, Dexuan Cui wrote:
>> From: Christoph Hellwig <hch@lst.de>
>> Sent: Wednesday, June 22, 2022 10:44 PM
>> To: Dexuan Cui <decui@microsoft.com>
>>   ...
>> On Wed, Jun 22, 2022 at 12:14:24PM -0700, Dexuan Cui wrote:
>>> The third parameter of dma_set_encrypted() is a size in bytes rather than
>>> the number of pages.
>>>
>>> Fixes: 4d0564785bb0 ("dma-direct: factor out dma_set_{de,en}crypted
>> helpers")
>>> Signed-off-by: Dexuan Cui <decui@microsoft.com>
>>
>> see:
>>
>> commit 4a37f3dd9a83186cb88d44808ab35b78375082c9 (tag:
>> dma-mapping-5.19-2022-05-25)
>> Author: Robin Murphy <robin.murphy@arm.com>
>> Date:   Fri May 20 18:10:13 2022 +0100
>>
>>      dma-direct: don't over-decrypt memory
> 
> It looks like commit 4a37f3dd9a831 fixed a different issue?
> 
> Here my patch is for the latest mainline:
> 
> In dma_direct_alloc()'s error handling path, we pass 'size' to dma_set_encrypted():
>    out_encrypt_pages:
> 	  if (dma_set_encrypted(dev, page_address(page), size))
> 
> However, in dma_direct_free(), we pass ' 1 << page_order ' to dma_set_encrypted().
> I think the ' 1 << page_order' is incorrect and it should be 'size' as well?

I think technically you're both right - these instances clearly have a 
history tracing back to the original bug that my patch addressed, but 
the refactoring then made them into their own distinct bug in terms of 
the internal dma_set_encrypted() interface, per the commit message here. 
Apparently I failed to spot this when forward-porting 4a37f3dd9a831 from 
5.10 (as the commit message says, don't ask... ;) ) - I guess I was only 
looking at where the set_memory_*() callsites had moved to. For this patch,

Reviewed-by: Robin Murphy <robin.murphy@arm.com>

Thanks
Robin.

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

* Re: [PATCH] dma-direct: use the correct size for dma_set_encrypted()
  2022-06-23  7:00   ` Dexuan Cui
  2022-06-23  9:01     ` Robin Murphy
@ 2022-06-23 13:28     ` Christoph Hellwig
  1 sibling, 0 replies; 5+ messages in thread
From: Christoph Hellwig @ 2022-06-23 13:28 UTC (permalink / raw)
  To: Dexuan Cui
  Cc: Christoph Hellwig, m.szyprowski, robin.murphy, iommu,
	linux-kernel, linux-hyperv, Michael Kelley (LINUX),
	Andrea Parri, Tianyu Lan

On Thu, Jun 23, 2022 at 07:00:58AM +0000, Dexuan Cui wrote:
> It looks like commit 4a37f3dd9a831 fixed a different issue?
> 
> Here my patch is for the latest mainline:
> 
> In dma_direct_alloc()'s error handling path, we pass 'size' to dma_set_encrypted():
>   out_encrypt_pages:
> 	  if (dma_set_encrypted(dev, page_address(page), size))
> 
> However, in dma_direct_free(), we pass ' 1 << page_order ' to dma_set_encrypted().
> I think the ' 1 << page_order' is incorrect and it should be 'size' as well?

Indeed.  I've applied the patch now.

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

end of thread, other threads:[~2022-06-23 13:28 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-22 19:14 [PATCH] dma-direct: use the correct size for dma_set_encrypted() Dexuan Cui
2022-06-23  5:43 ` Christoph Hellwig
2022-06-23  7:00   ` Dexuan Cui
2022-06-23  9:01     ` Robin Murphy
2022-06-23 13:28     ` Christoph Hellwig

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