* Re: Regression due to d98849aff879 (dma-direct: handle DMA_ATTR_NO_KERNEL_MAPPING in common code)
@ 2019-08-06 14:06 ` Lucas Stach
0 siblings, 0 replies; 26+ messages in thread
From: Lucas Stach @ 2019-08-06 14:06 UTC (permalink / raw)
To: Christoph Hellwig, Lendacky, Thomas
Cc: iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org,
Thiago Jung Bauermann, Halil Pasic
Am Dienstag, den 06.08.2019, 16:04 +0200 schrieb Christoph Hellwig:
> Ok, does this work?
>
> --
> From 34d35f335a98f515f2516b515051e12eae744c8d Mon Sep 17 00:00:00 2001
> > From: Christoph Hellwig <hch@lst.de>
> Date: Tue, 6 Aug 2019 14:33:23 +0300
> Subject: dma-direct: fix DMA_ATTR_NO_KERNEL_MAPPING
>
> The new DMA_ATTR_NO_KERNEL_MAPPING needs to actually assign
> a dma_addr to work. Also skip it if the architecture needs
> forced decryption handling, as that needs a kernel virtual
> address.
>
> Fixes: d98849aff879 (dma-direct: handle DMA_ATTR_NO_KERNEL_MAPPING in common code)
> > Signed-off-by: Christoph Hellwig <hch@lst.de>
> ---
> kernel/dma/direct.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/kernel/dma/direct.c b/kernel/dma/direct.c
> index 59bdceea3737..b01064d884f2 100644
> --- a/kernel/dma/direct.c
> +++ b/kernel/dma/direct.c
> @@ -130,11 +130,13 @@ void *dma_direct_alloc_pages(struct device *dev, size_t size,
> > if (!page)
> > return NULL;
>
> > - if (attrs & DMA_ATTR_NO_KERNEL_MAPPING) {
> > + if ((attrs & DMA_ATTR_NO_KERNEL_MAPPING) &&
> + !force_dma_unencrypted(dev)) {
dma_direct_free_pages() then needs the same check, as otherwise the cpu
address is treated as a cookie instead of a real address and the
encryption needs to be re-enabled.
Regards,
Lucas
> /* remove any dirty cache lines on the kernel alias */
> > if (!PageHighMem(page))
> > arch_dma_prep_coherent(page, size);
> > /* return the page pointer as the opaque cookie */
> > + *dma_handle = phys_to_dma(dev, page_to_phys(page));
> > return page;
> > }
>
^ permalink raw reply [flat|nested] 26+ messages in thread* Re: Regression due to d98849aff879 (dma-direct: handle DMA_ATTR_NO_KERNEL_MAPPING in common code)
2019-08-06 14:06 ` Lucas Stach
@ 2019-08-06 14:18 ` Lendacky, Thomas
-1 siblings, 0 replies; 26+ messages in thread
From: Lendacky, Thomas @ 2019-08-06 14:18 UTC (permalink / raw)
To: Lucas Stach, Christoph Hellwig
Cc: Halil Pasic, iommu@lists.linux-foundation.org,
linux-kernel@vger.kernel.org
On 8/6/19 9:06 AM, Lucas Stach wrote:
> Am Dienstag, den 06.08.2019, 16:04 +0200 schrieb Christoph Hellwig:
>> Ok, does this work?
>>
>> --
>> From 34d35f335a98f515f2516b515051e12eae744c8d Mon Sep 17 00:00:00 2001
>>> From: Christoph Hellwig <hch@lst.de>
>> Date: Tue, 6 Aug 2019 14:33:23 +0300
>> Subject: dma-direct: fix DMA_ATTR_NO_KERNEL_MAPPING
>>
>> The new DMA_ATTR_NO_KERNEL_MAPPING needs to actually assign
>> a dma_addr to work. Also skip it if the architecture needs
>> forced decryption handling, as that needs a kernel virtual
>> address.
>>
>> Fixes: d98849aff879 (dma-direct: handle DMA_ATTR_NO_KERNEL_MAPPING in common code)
>>> Signed-off-by: Christoph Hellwig <hch@lst.de>
>> ---
>> kernel/dma/direct.c | 4 +++-
>> 1 file changed, 3 insertions(+), 1 deletion(-)
>>
>> diff --git a/kernel/dma/direct.c b/kernel/dma/direct.c
>> index 59bdceea3737..b01064d884f2 100644
>> --- a/kernel/dma/direct.c
>> +++ b/kernel/dma/direct.c
>> @@ -130,11 +130,13 @@ void *dma_direct_alloc_pages(struct device *dev, size_t size,
>>> if (!page)
>>> return NULL;
>>
>>> - if (attrs & DMA_ATTR_NO_KERNEL_MAPPING) {
>>> + if ((attrs & DMA_ATTR_NO_KERNEL_MAPPING) &&
>> + !force_dma_unencrypted(dev)) {
I think you need to keep everything inside the original if statement since
the caller is expecting a page pointer to be returned in this case and not
the page_address() which is returned when the DMA_ATTR_NO_KERNEL_MAPPING
is not present.
>
> dma_direct_free_pages() then needs the same check, as otherwise the cpu
Agreed. And the cpu_addr passed in here will be the page pointer, so
will need to keep everything inside the if check of the
DMA_ATTR_NO_KERNEL_MAPPING attr here as well.
Thanks,
Tom
> address is treated as a cookie instead of a real address and the
> encryption needs to be re-enabled.
>
> Regards,
> Lucas
>
>> /* remove any dirty cache lines on the kernel alias */
>>> if (!PageHighMem(page))
>>> arch_dma_prep_coherent(page, size);
>>> /* return the page pointer as the opaque cookie */
>>> + *dma_handle = phys_to_dma(dev, page_to_phys(page));
>>> return page;
>>> }
>>
_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu
^ permalink raw reply [flat|nested] 26+ messages in thread* Re: Regression due to d98849aff879 (dma-direct: handle DMA_ATTR_NO_KERNEL_MAPPING in common code)
@ 2019-08-06 14:18 ` Lendacky, Thomas
0 siblings, 0 replies; 26+ messages in thread
From: Lendacky, Thomas @ 2019-08-06 14:18 UTC (permalink / raw)
To: Lucas Stach, Christoph Hellwig
Cc: iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org,
Thiago Jung Bauermann, Halil Pasic
On 8/6/19 9:06 AM, Lucas Stach wrote:
> Am Dienstag, den 06.08.2019, 16:04 +0200 schrieb Christoph Hellwig:
>> Ok, does this work?
>>
>> --
>> From 34d35f335a98f515f2516b515051e12eae744c8d Mon Sep 17 00:00:00 2001
>>> From: Christoph Hellwig <hch@lst.de>
>> Date: Tue, 6 Aug 2019 14:33:23 +0300
>> Subject: dma-direct: fix DMA_ATTR_NO_KERNEL_MAPPING
>>
>> The new DMA_ATTR_NO_KERNEL_MAPPING needs to actually assign
>> a dma_addr to work. Also skip it if the architecture needs
>> forced decryption handling, as that needs a kernel virtual
>> address.
>>
>> Fixes: d98849aff879 (dma-direct: handle DMA_ATTR_NO_KERNEL_MAPPING in common code)
>>> Signed-off-by: Christoph Hellwig <hch@lst.de>
>> ---
>> kernel/dma/direct.c | 4 +++-
>> 1 file changed, 3 insertions(+), 1 deletion(-)
>>
>> diff --git a/kernel/dma/direct.c b/kernel/dma/direct.c
>> index 59bdceea3737..b01064d884f2 100644
>> --- a/kernel/dma/direct.c
>> +++ b/kernel/dma/direct.c
>> @@ -130,11 +130,13 @@ void *dma_direct_alloc_pages(struct device *dev, size_t size,
>>> if (!page)
>>> return NULL;
>>
>>> - if (attrs & DMA_ATTR_NO_KERNEL_MAPPING) {
>>> + if ((attrs & DMA_ATTR_NO_KERNEL_MAPPING) &&
>> + !force_dma_unencrypted(dev)) {
I think you need to keep everything inside the original if statement since
the caller is expecting a page pointer to be returned in this case and not
the page_address() which is returned when the DMA_ATTR_NO_KERNEL_MAPPING
is not present.
>
> dma_direct_free_pages() then needs the same check, as otherwise the cpu
Agreed. And the cpu_addr passed in here will be the page pointer, so
will need to keep everything inside the if check of the
DMA_ATTR_NO_KERNEL_MAPPING attr here as well.
Thanks,
Tom
> address is treated as a cookie instead of a real address and the
> encryption needs to be re-enabled.
>
> Regards,
> Lucas
>
>> /* remove any dirty cache lines on the kernel alias */
>>> if (!PageHighMem(page))
>>> arch_dma_prep_coherent(page, size);
>>> /* return the page pointer as the opaque cookie */
>>> + *dma_handle = phys_to_dma(dev, page_to_phys(page));
>>> return page;
>>> }
>>
^ permalink raw reply [flat|nested] 26+ messages in thread* Re: Regression due to d98849aff879 (dma-direct: handle DMA_ATTR_NO_KERNEL_MAPPING in common code)
2019-08-06 14:18 ` Lendacky, Thomas
@ 2019-08-06 15:46 ` Christoph Hellwig
-1 siblings, 0 replies; 26+ messages in thread
From: Christoph Hellwig @ 2019-08-06 15:46 UTC (permalink / raw)
To: Lendacky, Thomas
Cc: linux-kernel@vger.kernel.org, Halil Pasic,
iommu@lists.linux-foundation.org, Christoph Hellwig, Lucas Stach
On Tue, Aug 06, 2019 at 02:18:49PM +0000, Lendacky, Thomas wrote:
> I think you need to keep everything inside the original if statement since
> the caller is expecting a page pointer to be returned in this case and not
> the page_address() which is returned when the DMA_ATTR_NO_KERNEL_MAPPING
> is not present.
DMA_ATTR_NO_KERNEL_MAPPING is defined to return an opaque cookie,
which just happens to be a page pointer. So if we fix up the free side
as pointed out by Lucas we should be fine.
_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu
^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: Regression due to d98849aff879 (dma-direct: handle DMA_ATTR_NO_KERNEL_MAPPING in common code)
@ 2019-08-06 15:46 ` Christoph Hellwig
0 siblings, 0 replies; 26+ messages in thread
From: Christoph Hellwig @ 2019-08-06 15:46 UTC (permalink / raw)
To: Lendacky, Thomas
Cc: Lucas Stach, Christoph Hellwig, iommu@lists.linux-foundation.org,
linux-kernel@vger.kernel.org, Thiago Jung Bauermann, Halil Pasic
On Tue, Aug 06, 2019 at 02:18:49PM +0000, Lendacky, Thomas wrote:
> I think you need to keep everything inside the original if statement since
> the caller is expecting a page pointer to be returned in this case and not
> the page_address() which is returned when the DMA_ATTR_NO_KERNEL_MAPPING
> is not present.
DMA_ATTR_NO_KERNEL_MAPPING is defined to return an opaque cookie,
which just happens to be a page pointer. So if we fix up the free side
as pointed out by Lucas we should be fine.
^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: Regression due to d98849aff879 (dma-direct: handle DMA_ATTR_NO_KERNEL_MAPPING in common code)
2019-08-06 15:46 ` Christoph Hellwig
@ 2019-08-06 15:59 ` Lendacky, Thomas
-1 siblings, 0 replies; 26+ messages in thread
From: Lendacky, Thomas @ 2019-08-06 15:59 UTC (permalink / raw)
To: Christoph Hellwig
Cc: Halil Pasic, iommu@lists.linux-foundation.org,
linux-kernel@vger.kernel.org, Lucas Stach
On 8/6/19 10:46 AM, Christoph Hellwig wrote:
> On Tue, Aug 06, 2019 at 02:18:49PM +0000, Lendacky, Thomas wrote:
>> I think you need to keep everything inside the original if statement since
>> the caller is expecting a page pointer to be returned in this case and not
>> the page_address() which is returned when the DMA_ATTR_NO_KERNEL_MAPPING
>> is not present.
>
> DMA_ATTR_NO_KERNEL_MAPPING is defined to return an opaque cookie,
> which just happens to be a page pointer. So if we fix up the free side
> as pointed out by Lucas we should be fine.
As long as two different cookie types (page pointer for encrypted DMA
and virtual address returned from page_address() for unencrypted DMA)
is ok. I'm just not familiar with how the cookie is used in any other
functions, if at all.
Thanks,
Tom
>
_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu
^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: Regression due to d98849aff879 (dma-direct: handle DMA_ATTR_NO_KERNEL_MAPPING in common code)
@ 2019-08-06 15:59 ` Lendacky, Thomas
0 siblings, 0 replies; 26+ messages in thread
From: Lendacky, Thomas @ 2019-08-06 15:59 UTC (permalink / raw)
To: Christoph Hellwig
Cc: Lucas Stach, iommu@lists.linux-foundation.org,
linux-kernel@vger.kernel.org, Thiago Jung Bauermann, Halil Pasic
On 8/6/19 10:46 AM, Christoph Hellwig wrote:
> On Tue, Aug 06, 2019 at 02:18:49PM +0000, Lendacky, Thomas wrote:
>> I think you need to keep everything inside the original if statement since
>> the caller is expecting a page pointer to be returned in this case and not
>> the page_address() which is returned when the DMA_ATTR_NO_KERNEL_MAPPING
>> is not present.
>
> DMA_ATTR_NO_KERNEL_MAPPING is defined to return an opaque cookie,
> which just happens to be a page pointer. So if we fix up the free side
> as pointed out by Lucas we should be fine.
As long as two different cookie types (page pointer for encrypted DMA
and virtual address returned from page_address() for unencrypted DMA)
is ok. I'm just not familiar with how the cookie is used in any other
functions, if at all.
Thanks,
Tom
>
^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: Regression due to d98849aff879 (dma-direct: handle DMA_ATTR_NO_KERNEL_MAPPING in common code)
2019-08-06 15:59 ` Lendacky, Thomas
@ 2019-08-06 16:07 ` Christoph Hellwig
-1 siblings, 0 replies; 26+ messages in thread
From: Christoph Hellwig @ 2019-08-06 16:07 UTC (permalink / raw)
To: Lendacky, Thomas
Cc: linux-kernel@vger.kernel.org, Halil Pasic,
iommu@lists.linux-foundation.org, Christoph Hellwig, Lucas Stach
On Tue, Aug 06, 2019 at 03:59:40PM +0000, Lendacky, Thomas wrote:
> As long as two different cookie types (page pointer for encrypted DMA
> and virtual address returned from page_address() for unencrypted DMA)
> is ok. I'm just not familiar with how the cookie is used in any other
> functions, if at all.
DMA_ATTR_NO_KERNEL_MAPPING is intended for memory never used in the
kernel, either because it is just a buffer for device that are too cheap
to enough dram, or because it is a buffer for userspace to device
communication that the kernel just mediates.
_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu
^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: Regression due to d98849aff879 (dma-direct: handle DMA_ATTR_NO_KERNEL_MAPPING in common code)
@ 2019-08-06 16:07 ` Christoph Hellwig
0 siblings, 0 replies; 26+ messages in thread
From: Christoph Hellwig @ 2019-08-06 16:07 UTC (permalink / raw)
To: Lendacky, Thomas
Cc: Christoph Hellwig, Lucas Stach, iommu@lists.linux-foundation.org,
linux-kernel@vger.kernel.org, Thiago Jung Bauermann, Halil Pasic
On Tue, Aug 06, 2019 at 03:59:40PM +0000, Lendacky, Thomas wrote:
> As long as two different cookie types (page pointer for encrypted DMA
> and virtual address returned from page_address() for unencrypted DMA)
> is ok. I'm just not familiar with how the cookie is used in any other
> functions, if at all.
DMA_ATTR_NO_KERNEL_MAPPING is intended for memory never used in the
kernel, either because it is just a buffer for device that are too cheap
to enough dram, or because it is a buffer for userspace to device
communication that the kernel just mediates.
^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: Regression due to d98849aff879 (dma-direct: handle DMA_ATTR_NO_KERNEL_MAPPING in common code)
2019-08-06 14:06 ` Lucas Stach
@ 2019-08-06 15:44 ` Christoph Hellwig
-1 siblings, 0 replies; 26+ messages in thread
From: Christoph Hellwig @ 2019-08-06 15:44 UTC (permalink / raw)
To: Lucas Stach
Cc: Lendacky, Thomas, linux-kernel@vger.kernel.org, Halil Pasic,
iommu@lists.linux-foundation.org, Christoph Hellwig
On Tue, Aug 06, 2019 at 04:06:58PM +0200, Lucas Stach wrote:
>
> dma_direct_free_pages() then needs the same check, as otherwise the cpu
> address is treated as a cookie instead of a real address and the
> encryption needs to be re-enabled.
Ok, lets try this one instead:
--
From 3a7aa9fe38a5eae5d879831b4f8c1032e735a0b6 Mon Sep 17 00:00:00 2001
From: Christoph Hellwig <hch@lst.de>
Date: Tue, 6 Aug 2019 14:33:23 +0300
Subject: dma-direct: fix DMA_ATTR_NO_KERNEL_MAPPING
The new DMA_ATTR_NO_KERNEL_MAPPING needs to actually assign
a dma_addr to work. Also skip it if the architecture needs
forced decryption handling, as that needs a kernel virtual
address.
Fixes: d98849aff879 (dma-direct: handle DMA_ATTR_NO_KERNEL_MAPPING in common code)
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
kernel/dma/direct.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/kernel/dma/direct.c b/kernel/dma/direct.c
index 59bdceea3737..4c211c87a719 100644
--- a/kernel/dma/direct.c
+++ b/kernel/dma/direct.c
@@ -130,11 +130,13 @@ void *dma_direct_alloc_pages(struct device *dev, size_t size,
if (!page)
return NULL;
- if (attrs & DMA_ATTR_NO_KERNEL_MAPPING) {
+ if ((attrs & DMA_ATTR_NO_KERNEL_MAPPING) &&
+ !force_dma_unencrypted(dev)) {
/* remove any dirty cache lines on the kernel alias */
if (!PageHighMem(page))
arch_dma_prep_coherent(page, size);
/* return the page pointer as the opaque cookie */
+ *dma_handle = phys_to_dma(dev, page_to_phys(page));
return page;
}
@@ -178,7 +180,8 @@ void dma_direct_free_pages(struct device *dev, size_t size, void *cpu_addr,
{
unsigned int page_order = get_order(size);
- if (attrs & DMA_ATTR_NO_KERNEL_MAPPING) {
+ if ((attrs & DMA_ATTR_NO_KERNEL_MAPPING) &&
+ !force_dma_unencrypted(dev)) {
/* cpu_addr is a struct page cookie, not a kernel address */
__dma_direct_free_pages(dev, size, cpu_addr);
return;
--
2.20.1
_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu
^ permalink raw reply related [flat|nested] 26+ messages in thread* Re: Regression due to d98849aff879 (dma-direct: handle DMA_ATTR_NO_KERNEL_MAPPING in common code)
@ 2019-08-06 15:44 ` Christoph Hellwig
0 siblings, 0 replies; 26+ messages in thread
From: Christoph Hellwig @ 2019-08-06 15:44 UTC (permalink / raw)
To: Lucas Stach
Cc: Christoph Hellwig, Lendacky, Thomas,
iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org,
Thiago Jung Bauermann, Halil Pasic
On Tue, Aug 06, 2019 at 04:06:58PM +0200, Lucas Stach wrote:
>
> dma_direct_free_pages() then needs the same check, as otherwise the cpu
> address is treated as a cookie instead of a real address and the
> encryption needs to be re-enabled.
Ok, lets try this one instead:
--
From 3a7aa9fe38a5eae5d879831b4f8c1032e735a0b6 Mon Sep 17 00:00:00 2001
From: Christoph Hellwig <hch@lst.de>
Date: Tue, 6 Aug 2019 14:33:23 +0300
Subject: dma-direct: fix DMA_ATTR_NO_KERNEL_MAPPING
The new DMA_ATTR_NO_KERNEL_MAPPING needs to actually assign
a dma_addr to work. Also skip it if the architecture needs
forced decryption handling, as that needs a kernel virtual
address.
Fixes: d98849aff879 (dma-direct: handle DMA_ATTR_NO_KERNEL_MAPPING in common code)
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
kernel/dma/direct.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/kernel/dma/direct.c b/kernel/dma/direct.c
index 59bdceea3737..4c211c87a719 100644
--- a/kernel/dma/direct.c
+++ b/kernel/dma/direct.c
@@ -130,11 +130,13 @@ void *dma_direct_alloc_pages(struct device *dev, size_t size,
if (!page)
return NULL;
- if (attrs & DMA_ATTR_NO_KERNEL_MAPPING) {
+ if ((attrs & DMA_ATTR_NO_KERNEL_MAPPING) &&
+ !force_dma_unencrypted(dev)) {
/* remove any dirty cache lines on the kernel alias */
if (!PageHighMem(page))
arch_dma_prep_coherent(page, size);
/* return the page pointer as the opaque cookie */
+ *dma_handle = phys_to_dma(dev, page_to_phys(page));
return page;
}
@@ -178,7 +180,8 @@ void dma_direct_free_pages(struct device *dev, size_t size, void *cpu_addr,
{
unsigned int page_order = get_order(size);
- if (attrs & DMA_ATTR_NO_KERNEL_MAPPING) {
+ if ((attrs & DMA_ATTR_NO_KERNEL_MAPPING) &&
+ !force_dma_unencrypted(dev)) {
/* cpu_addr is a struct page cookie, not a kernel address */
__dma_direct_free_pages(dev, size, cpu_addr);
return;
--
2.20.1
^ permalink raw reply related [flat|nested] 26+ messages in thread* Re: Regression due to d98849aff879 (dma-direct: handle DMA_ATTR_NO_KERNEL_MAPPING in common code)
2019-08-06 15:44 ` Christoph Hellwig
@ 2019-08-07 15:24 ` Lucas Stach
-1 siblings, 0 replies; 26+ messages in thread
From: Lucas Stach @ 2019-08-07 15:24 UTC (permalink / raw)
To: Christoph Hellwig
Cc: Halil Pasic, Lendacky, Thomas, iommu@lists.linux-foundation.org,
linux-kernel@vger.kernel.org
Am Dienstag, den 06.08.2019, 17:44 +0200 schrieb Christoph Hellwig:
> On Tue, Aug 06, 2019 at 04:06:58PM +0200, Lucas Stach wrote:
> >
> > dma_direct_free_pages() then needs the same check, as otherwise the cpu
> > address is treated as a cookie instead of a real address and the
> > encryption needs to be re-enabled.
>
> Ok, lets try this one instead:
>
> --
> From 3a7aa9fe38a5eae5d879831b4f8c1032e735a0b6 Mon Sep 17 00:00:00 2001
> From: Christoph Hellwig <hch@lst.de>
> Date: Tue, 6 Aug 2019 14:33:23 +0300
> Subject: dma-direct: fix DMA_ATTR_NO_KERNEL_MAPPING
>
> The new DMA_ATTR_NO_KERNEL_MAPPING needs to actually assign
> a dma_addr to work. Also skip it if the architecture needs
> forced decryption handling, as that needs a kernel virtual
> address.
>
> Fixes: d98849aff879 (dma-direct: handle DMA_ATTR_NO_KERNEL_MAPPING in common code)
> Signed-off-by: Christoph Hellwig <hch@lst.de>
> ---
> kernel/dma/direct.c | 7 +++++--
> 1 file changed, 5 insertions(+), 2 deletions(-)
>
> diff --git a/kernel/dma/direct.c b/kernel/dma/direct.c
> index 59bdceea3737..4c211c87a719 100644
> --- a/kernel/dma/direct.c
> +++ b/kernel/dma/direct.c
> @@ -130,11 +130,13 @@ void *dma_direct_alloc_pages(struct device *dev, size_t size,
> if (!page)
> return NULL;
>
> - if (attrs & DMA_ATTR_NO_KERNEL_MAPPING) {
> + if ((attrs & DMA_ATTR_NO_KERNEL_MAPPING) &&
> + !force_dma_unencrypted(dev)) {
> /* remove any dirty cache lines on the kernel alias */
> if (!PageHighMem(page))
> arch_dma_prep_coherent(page, size);
> /* return the page pointer as the opaque cookie */
> + *dma_handle = phys_to_dma(dev, page_to_phys(page));
I would suggest to place this line above the comment, as the comment
only really applies to the return value. Other than this nitpick, this
matches my understanding of the required changes, so:
Reviewed-by: Lucas Stach <l.stach@pengutronix.de>
> return page;
> }
>
> @@ -178,7 +180,8 @@ void dma_direct_free_pages(struct device *dev, size_t size, void *cpu_addr,
> {
> unsigned int page_order = get_order(size);
>
> - if (attrs & DMA_ATTR_NO_KERNEL_MAPPING) {
> + if ((attrs & DMA_ATTR_NO_KERNEL_MAPPING) &&
> + !force_dma_unencrypted(dev)) {
> /* cpu_addr is a struct page cookie, not a kernel address */
> __dma_direct_free_pages(dev, size, cpu_addr);
> return;
_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu
^ permalink raw reply [flat|nested] 26+ messages in thread* Re: Regression due to d98849aff879 (dma-direct: handle DMA_ATTR_NO_KERNEL_MAPPING in common code)
@ 2019-08-07 15:24 ` Lucas Stach
0 siblings, 0 replies; 26+ messages in thread
From: Lucas Stach @ 2019-08-07 15:24 UTC (permalink / raw)
To: Christoph Hellwig
Cc: Lendacky, Thomas, iommu@lists.linux-foundation.org,
linux-kernel@vger.kernel.org, Thiago Jung Bauermann, Halil Pasic
Am Dienstag, den 06.08.2019, 17:44 +0200 schrieb Christoph Hellwig:
> On Tue, Aug 06, 2019 at 04:06:58PM +0200, Lucas Stach wrote:
> >
> > dma_direct_free_pages() then needs the same check, as otherwise the cpu
> > address is treated as a cookie instead of a real address and the
> > encryption needs to be re-enabled.
>
> Ok, lets try this one instead:
>
> --
> From 3a7aa9fe38a5eae5d879831b4f8c1032e735a0b6 Mon Sep 17 00:00:00 2001
> From: Christoph Hellwig <hch@lst.de>
> Date: Tue, 6 Aug 2019 14:33:23 +0300
> Subject: dma-direct: fix DMA_ATTR_NO_KERNEL_MAPPING
>
> The new DMA_ATTR_NO_KERNEL_MAPPING needs to actually assign
> a dma_addr to work. Also skip it if the architecture needs
> forced decryption handling, as that needs a kernel virtual
> address.
>
> Fixes: d98849aff879 (dma-direct: handle DMA_ATTR_NO_KERNEL_MAPPING in common code)
> Signed-off-by: Christoph Hellwig <hch@lst.de>
> ---
> kernel/dma/direct.c | 7 +++++--
> 1 file changed, 5 insertions(+), 2 deletions(-)
>
> diff --git a/kernel/dma/direct.c b/kernel/dma/direct.c
> index 59bdceea3737..4c211c87a719 100644
> --- a/kernel/dma/direct.c
> +++ b/kernel/dma/direct.c
> @@ -130,11 +130,13 @@ void *dma_direct_alloc_pages(struct device *dev, size_t size,
> if (!page)
> return NULL;
>
> - if (attrs & DMA_ATTR_NO_KERNEL_MAPPING) {
> + if ((attrs & DMA_ATTR_NO_KERNEL_MAPPING) &&
> + !force_dma_unencrypted(dev)) {
> /* remove any dirty cache lines on the kernel alias */
> if (!PageHighMem(page))
> arch_dma_prep_coherent(page, size);
> /* return the page pointer as the opaque cookie */
> + *dma_handle = phys_to_dma(dev, page_to_phys(page));
I would suggest to place this line above the comment, as the comment
only really applies to the return value. Other than this nitpick, this
matches my understanding of the required changes, so:
Reviewed-by: Lucas Stach <l.stach@pengutronix.de>
> return page;
> }
>
> @@ -178,7 +180,8 @@ void dma_direct_free_pages(struct device *dev, size_t size, void *cpu_addr,
> {
> unsigned int page_order = get_order(size);
>
> - if (attrs & DMA_ATTR_NO_KERNEL_MAPPING) {
> + if ((attrs & DMA_ATTR_NO_KERNEL_MAPPING) &&
> + !force_dma_unencrypted(dev)) {
> /* cpu_addr is a struct page cookie, not a kernel address */
> __dma_direct_free_pages(dev, size, cpu_addr);
> return;
^ permalink raw reply [flat|nested] 26+ messages in thread* Re: Regression due to d98849aff879 (dma-direct: handle DMA_ATTR_NO_KERNEL_MAPPING in common code)
2019-08-07 15:24 ` Lucas Stach
@ 2019-08-08 7:48 ` Christoph Hellwig
-1 siblings, 0 replies; 26+ messages in thread
From: Christoph Hellwig @ 2019-08-08 7:48 UTC (permalink / raw)
To: Lucas Stach
Cc: Lendacky, Thomas, linux-kernel@vger.kernel.org, Halil Pasic,
iommu@lists.linux-foundation.org, Christoph Hellwig
On Wed, Aug 07, 2019 at 05:24:17PM +0200, Lucas Stach wrote:
> I would suggest to place this line above the comment, as the comment
> only really applies to the return value. Other than this nitpick, this
> matches my understanding of the required changes, so:
>
> Reviewed-by: Lucas Stach <l.stach@pengutronix.de>
Thanks, I've applied it with that fixed up.
_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu
^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: Regression due to d98849aff879 (dma-direct: handle DMA_ATTR_NO_KERNEL_MAPPING in common code)
@ 2019-08-08 7:48 ` Christoph Hellwig
0 siblings, 0 replies; 26+ messages in thread
From: Christoph Hellwig @ 2019-08-08 7:48 UTC (permalink / raw)
To: Lucas Stach
Cc: Christoph Hellwig, Lendacky, Thomas,
iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org,
Thiago Jung Bauermann, Halil Pasic
On Wed, Aug 07, 2019 at 05:24:17PM +0200, Lucas Stach wrote:
> I would suggest to place this line above the comment, as the comment
> only really applies to the return value. Other than this nitpick, this
> matches my understanding of the required changes, so:
>
> Reviewed-by: Lucas Stach <l.stach@pengutronix.de>
Thanks, I've applied it with that fixed up.
^ permalink raw reply [flat|nested] 26+ messages in thread