* [PATCH V2] drm/amdgpu: limit DMA size to PAGE_SIZE for scatter-gather buffers
@ 2018-04-10 20:59 Sinan Kaya
[not found] ` <20180411062602.GA29109@hr-amur2>
2018-04-11 12:03 ` Robin Murphy
0 siblings, 2 replies; 8+ messages in thread
From: Sinan Kaya @ 2018-04-10 20:59 UTC (permalink / raw)
To: amd-gfx, timur, sulrich
Cc: linux-arm-msm, linux-arm-kernel, Sinan Kaya, Alex Deucher,
Christian König, David (ChunMing) Zhou, David Airlie,
Felix Kuehling, Monk Liu, Roger He, Jim Qu, Emily Deng, Feifei Xu,
Huang Rui, Tom St Denis, David Panariti, open list:DRM DRIVERS,
open list
Code is expecing to observe the same number of buffers returned from
dma_map_sg() function compared to sg_alloc_table_from_pages(). This
doesn't hold true universally especially for systems with IOMMU.
IOMMU driver tries to combine buffers into a single DMA address as much
as it can. The right thing is to tell the DMA layer how much combining
IOMMU can do.
Signed-off-by: Sinan Kaya <okaya@codeaurora.org>
---
drivers/gpu/drm/amd/amdgpu/gmc_v6_0.c | 2 +-
drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c | 1 +
drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c | 1 +
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c | 1 +
4 files changed, 4 insertions(+), 1 deletion(-)
diff --git a/drivers/gpu/drm/amd/amdgpu/gmc_v6_0.c b/drivers/gpu/drm/amd/amdgpu/gmc_v6_0.c
index 8e28270..1b031eb 100644
--- a/drivers/gpu/drm/amd/amdgpu/gmc_v6_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/gmc_v6_0.c
@@ -851,7 +851,7 @@ static int gmc_v6_0_sw_init(void *handle)
pci_set_consistent_dma_mask(adev->pdev, DMA_BIT_MASK(32));
dev_warn(adev->dev, "amdgpu: No coherent DMA available.\n");
}
-
+ dma_set_max_seg_size(adev->dev, PAGE_SIZE);
r = gmc_v6_0_init_microcode(adev);
if (r) {
dev_err(adev->dev, "Failed to load mc firmware!\n");
diff --git a/drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c b/drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c
index 86e9d682..0a4b2cc1 100644
--- a/drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c
@@ -999,6 +999,7 @@ static int gmc_v7_0_sw_init(void *handle)
pci_set_consistent_dma_mask(adev->pdev, DMA_BIT_MASK(32));
pr_warn("amdgpu: No coherent DMA available\n");
}
+ dma_set_max_seg_size(adev->dev, PAGE_SIZE);
r = gmc_v7_0_init_microcode(adev);
if (r) {
diff --git a/drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c b/drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c
index 9a813d8..b171529 100644
--- a/drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c
@@ -1096,6 +1096,7 @@ static int gmc_v8_0_sw_init(void *handle)
pci_set_consistent_dma_mask(adev->pdev, DMA_BIT_MASK(32));
pr_warn("amdgpu: No coherent DMA available\n");
}
+ dma_set_max_seg_size(adev->dev, PAGE_SIZE);
r = gmc_v8_0_init_microcode(adev);
if (r) {
diff --git a/drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c b/drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c
index 3b7e7af..36e658ab 100644
--- a/drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c
@@ -855,6 +855,7 @@ static int gmc_v9_0_sw_init(void *handle)
pci_set_consistent_dma_mask(adev->pdev, DMA_BIT_MASK(32));
printk(KERN_WARNING "amdgpu: No coherent DMA available.\n");
}
+ dma_set_max_seg_size(adev->dev, PAGE_SIZE);
r = gmc_v9_0_mc_init(adev);
if (r)
--
2.7.4
^ permalink raw reply related [flat|nested] 8+ messages in thread[parent not found: <20180411062602.GA29109@hr-amur2>]
* Re: [PATCH V2] drm/amdgpu: limit DMA size to PAGE_SIZE for scatter-gather buffers
[not found] ` <20180411062602.GA29109@hr-amur2>
@ 2018-04-11 9:17 ` Christian König
0 siblings, 0 replies; 8+ messages in thread
From: Christian König @ 2018-04-11 9:17 UTC (permalink / raw)
To: Huang Rui, Sinan Kaya
Cc: Tom St Denis, David Panariti, sulrich, Jim Qu, David Airlie,
linux-arm-msm, timur, open list, open list:DRM DRIVERS,
Christian König, Emily Deng, Roger He, amd-gfx, Feifei Xu,
Alex Deucher, Felix Kuehling, Monk Liu, linux-arm-kernel
Am 11.04.2018 um 08:26 schrieb Huang Rui:
> On Tue, Apr 10, 2018 at 04:59:55PM -0400, Sinan Kaya wrote:
>> Code is expecing to observe the same number of buffers returned from
>> dma_map_sg() function compared to sg_alloc_table_from_pages(). This
>> doesn't hold true universally especially for systems with IOMMU.
>>
>> IOMMU driver tries to combine buffers into a single DMA address as much
>> as it can. The right thing is to tell the DMA layer how much combining
>> IOMMU can do.
>>
>> Signed-off-by: Sinan Kaya <okaya@codeaurora.org>
> Sinan, I guess Christian's suggestion is to add amdgpu_device_init function
> like here:
Yes, exactly. Looks like Sinan just tried to place the call next to
pci_set_dma_mask()/pci_set_consistent_dma_mask().
Not necessary a bad idea, but in this case not optimal.
Sinan please refine your patch as Rui suggested and resend.
Thanks,
Christian.
>
> 8<-------
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
> index 0e798b3..9b96771 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
> @@ -2339,6 +2339,8 @@ int amdgpu_device_init(struct amdgpu_device *adev,
> /* init the mode config */
> drm_mode_config_init(adev->ddev);
>
> + dma_set_max_seg_size(adev->dev, PAGE_SIZE);
> +
> r = amdgpu_device_ip_init(adev);
> if (r) {
> /* failed in exclusive mode due to timeout */
> 8<-------
>
> After that, we don't do it in each generation.
>
> Thanks,
> Ray
> _______________________________________________
> dri-devel mailing list
> dri-devel@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/dri-devel
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH V2] drm/amdgpu: limit DMA size to PAGE_SIZE for scatter-gather buffers
2018-04-10 20:59 [PATCH V2] drm/amdgpu: limit DMA size to PAGE_SIZE for scatter-gather buffers Sinan Kaya
[not found] ` <20180411062602.GA29109@hr-amur2>
@ 2018-04-11 12:03 ` Robin Murphy
[not found] ` <32b82296-bba5-b5f1-266b-45c1ed66da94-5wv7dgnIgG8@public.gmane.org>
2018-04-12 6:26 ` Christoph Hellwig
1 sibling, 2 replies; 8+ messages in thread
From: Robin Murphy @ 2018-04-11 12:03 UTC (permalink / raw)
To: Sinan Kaya, amd-gfx, timur, sulrich
Cc: Tom St Denis, David Panariti, David Airlie, linux-arm-msm,
Felix Kuehling, open list, open list:DRM DRIVERS, hch, Emily Deng,
iommu, Huang Rui, Roger He, linux-arm-kernel, Feifei Xu,
Alex Deucher, Jim Qu, Christian König, Monk Liu
On 10/04/18 21:59, Sinan Kaya wrote:
> Code is expecing to observe the same number of buffers returned from
> dma_map_sg() function compared to sg_alloc_table_from_pages(). This
> doesn't hold true universally especially for systems with IOMMU.
So why not fix said code? It's clearly not a real hardware limitation,
and the map_sg() APIs have potentially returned fewer than nents since
forever, so there's really no excuse.
> IOMMU driver tries to combine buffers into a single DMA address as much
> as it can. The right thing is to tell the DMA layer how much combining
> IOMMU can do.
Disagree; this is a dodgy hack, since you'll now end up passing
scatterlists into dma_map_sg() which already violate max_seg_size to
begin with, and I think a conscientious DMA API implementation would be
at rights to fail the mapping for that reason (I know arm64 happens not
to, but that was a deliberate design decision to make my life easier at
the time).
As a short-term fix, at least do something like what i915 does and
constrain the table allocation to the desired segment size as well, so
things remain self-consistent. But still never claim that faking a
hardware constraint as a workaround for a driver shortcoming is "the
right thing to do" ;)
Robin.
> Signed-off-by: Sinan Kaya <okaya@codeaurora.org>
> ---
> drivers/gpu/drm/amd/amdgpu/gmc_v6_0.c | 2 +-
> drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c | 1 +
> drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c | 1 +
> drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c | 1 +
> 4 files changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/gmc_v6_0.c b/drivers/gpu/drm/amd/amdgpu/gmc_v6_0.c
> index 8e28270..1b031eb 100644
> --- a/drivers/gpu/drm/amd/amdgpu/gmc_v6_0.c
> +++ b/drivers/gpu/drm/amd/amdgpu/gmc_v6_0.c
> @@ -851,7 +851,7 @@ static int gmc_v6_0_sw_init(void *handle)
> pci_set_consistent_dma_mask(adev->pdev, DMA_BIT_MASK(32));
> dev_warn(adev->dev, "amdgpu: No coherent DMA available.\n");
> }
> -
> + dma_set_max_seg_size(adev->dev, PAGE_SIZE);
> r = gmc_v6_0_init_microcode(adev);
> if (r) {
> dev_err(adev->dev, "Failed to load mc firmware!\n");
> diff --git a/drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c b/drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c
> index 86e9d682..0a4b2cc1 100644
> --- a/drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c
> +++ b/drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c
> @@ -999,6 +999,7 @@ static int gmc_v7_0_sw_init(void *handle)
> pci_set_consistent_dma_mask(adev->pdev, DMA_BIT_MASK(32));
> pr_warn("amdgpu: No coherent DMA available\n");
> }
> + dma_set_max_seg_size(adev->dev, PAGE_SIZE);
>
> r = gmc_v7_0_init_microcode(adev);
> if (r) {
> diff --git a/drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c b/drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c
> index 9a813d8..b171529 100644
> --- a/drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c
> +++ b/drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c
> @@ -1096,6 +1096,7 @@ static int gmc_v8_0_sw_init(void *handle)
> pci_set_consistent_dma_mask(adev->pdev, DMA_BIT_MASK(32));
> pr_warn("amdgpu: No coherent DMA available\n");
> }
> + dma_set_max_seg_size(adev->dev, PAGE_SIZE);
>
> r = gmc_v8_0_init_microcode(adev);
> if (r) {
> diff --git a/drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c b/drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c
> index 3b7e7af..36e658ab 100644
> --- a/drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c
> +++ b/drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c
> @@ -855,6 +855,7 @@ static int gmc_v9_0_sw_init(void *handle)
> pci_set_consistent_dma_mask(adev->pdev, DMA_BIT_MASK(32));
> printk(KERN_WARNING "amdgpu: No coherent DMA available.\n");
> }
> + dma_set_max_seg_size(adev->dev, PAGE_SIZE);
>
> r = gmc_v9_0_mc_init(adev);
> if (r)
>
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel
^ permalink raw reply [flat|nested] 8+ messages in thread[parent not found: <32b82296-bba5-b5f1-266b-45c1ed66da94-5wv7dgnIgG8@public.gmane.org>]
* Re: [PATCH V2] drm/amdgpu: limit DMA size to PAGE_SIZE for scatter-gather buffers
[not found] ` <32b82296-bba5-b5f1-266b-45c1ed66da94-5wv7dgnIgG8@public.gmane.org>
@ 2018-04-11 14:33 ` Sinan Kaya
[not found] ` <1a1d0069-c8d3-cc0d-cf1c-8e90e4a2b0d7-sgV2jX0FEOL9JmXXK+q4OQ@public.gmane.org>
0 siblings, 1 reply; 8+ messages in thread
From: Sinan Kaya @ 2018-04-11 14:33 UTC (permalink / raw)
To: Robin Murphy, amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW,
timur-sgV2jX0FEOL9JmXXK+q4OQ, sulrich-sgV2jX0FEOL9JmXXK+q4OQ
Cc: Tom St Denis, David (ChunMing) Zhou, David Panariti, David Airlie,
linux-arm-msm-u79uwXL29TY76Z2rM5mHXA, Felix Kuehling, open list,
open list:DRM DRIVERS, hch-jcswGhMUV9g, Emily Deng,
iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA, Huang Rui,
Roger He, linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
Feifei Xu, Alex Deucher, Jim Qu, Christian König, Monk Liu
On 4/11/2018 8:03 AM, Robin Murphy wrote:
> On 10/04/18 21:59, Sinan Kaya wrote:
>> Code is expecing to observe the same number of buffers returned from
>> dma_map_sg() function compared to sg_alloc_table_from_pages(). This
>> doesn't hold true universally especially for systems with IOMMU.
>
> So why not fix said code? It's clearly not a real hardware limitation, and the map_sg() APIs have potentially returned fewer than nents since forever, so there's really no excuse.
Sure, I'll take a better fix if there is one.
>
>> IOMMU driver tries to combine buffers into a single DMA address as much
>> as it can. The right thing is to tell the DMA layer how much combining
>> IOMMU can do.
>
> Disagree; this is a dodgy hack, since you'll now end up passing scatterlists into dma_map_sg() which already violate max_seg_size to begin with, and I think a conscientious DMA API implementation would be at rights to fail the mapping for that reason (I know arm64 happens not to, but that was a deliberate design decision to make my life easier at the time).
>
> As a short-term fix, at least do something like what i915 does and constrain the table allocation to the desired segment size as well, so things remain self-consistent. But still never claim that faking a hardware constraint as a workaround for a driver shortcoming is "the right thing to do" ;)
You are asking for something like this from here, right?
https://elixir.bootlin.com/linux/v4.16.1/source/drivers/gpu/drm/i915/i915_gem_dmabuf.c#L58
ret = sg_alloc_table(st, obj->mm.pages->nents, GFP_KERNEL);
if (ret)
goto err_free;
src = obj->mm.pages->sgl;
dst = st->sgl;
for (i = 0; i < obj->mm.pages->nents; i++) {
sg_set_page(dst, sg_page(src), src->length, 0);
dst = sg_next(dst);
src = sg_next(src);
}
This seems to allocate the scatter gather list and fill it in manually before passing it
to dma_map_sg(). I'll give it a try.
Just double checking.
>
> Robin.
>
>> Signed-off-by: Sinan Kaya <okaya-sgV2jX0FEOL9JmXXK+q4OQ@public.gmane.org>
--
Sinan Kaya
Qualcomm Datacenter Technologies, Inc. as an affiliate of Qualcomm Technologies, Inc.
Qualcomm Technologies, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH V2] drm/amdgpu: limit DMA size to PAGE_SIZE for scatter-gather buffers
2018-04-11 12:03 ` Robin Murphy
[not found] ` <32b82296-bba5-b5f1-266b-45c1ed66da94-5wv7dgnIgG8@public.gmane.org>
@ 2018-04-12 6:26 ` Christoph Hellwig
[not found] ` <20180412062600.GB30499-jcswGhMUV9g@public.gmane.org>
1 sibling, 1 reply; 8+ messages in thread
From: Christoph Hellwig @ 2018-04-12 6:26 UTC (permalink / raw)
To: Robin Murphy
Cc: Sinan Kaya, amd-gfx, timur, sulrich, Tom St Denis,
David (ChunMing) Zhou, Emily Deng, David Airlie, linux-arm-msm,
Felix Kuehling, open list, open list:DRM DRIVERS, David Panariti,
Jim Qu, Huang Rui, Roger He, Monk Liu, Feifei Xu, Alex Deucher,
Christian König, linux-arm-kernel
On Wed, Apr 11, 2018 at 01:03:59PM +0100, Robin Murphy wrote:
> On 10/04/18 21:59, Sinan Kaya wrote:
>> Code is expecing to observe the same number of buffers returned from
>> dma_map_sg() function compared to sg_alloc_table_from_pages(). This
>> doesn't hold true universally especially for systems with IOMMU.
>
> So why not fix said code? It's clearly not a real hardware limitation, and
> the map_sg() APIs have potentially returned fewer than nents since forever,
> so there's really no excuse.
Yes, relying on dma_map_sg returning the same number of entries as passed
it is completely bogus.
>> IOMMU driver tries to combine buffers into a single DMA address as much
>> as it can. The right thing is to tell the DMA layer how much combining
>> IOMMU can do.
>
> Disagree; this is a dodgy hack, since you'll now end up passing
> scatterlists into dma_map_sg() which already violate max_seg_size to begin
> with, and I think a conscientious DMA API implementation would be at rights
> to fail the mapping for that reason (I know arm64 happens not to, but that
> was a deliberate design decision to make my life easier at the time).
Agreed.
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2018-04-12 13:51 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-04-10 20:59 [PATCH V2] drm/amdgpu: limit DMA size to PAGE_SIZE for scatter-gather buffers Sinan Kaya
[not found] ` <20180411062602.GA29109@hr-amur2>
2018-04-11 9:17 ` Christian König
2018-04-11 12:03 ` Robin Murphy
[not found] ` <32b82296-bba5-b5f1-266b-45c1ed66da94-5wv7dgnIgG8@public.gmane.org>
2018-04-11 14:33 ` Sinan Kaya
[not found] ` <1a1d0069-c8d3-cc0d-cf1c-8e90e4a2b0d7-sgV2jX0FEOL9JmXXK+q4OQ@public.gmane.org>
2018-04-11 15:32 ` Robin Murphy
2018-04-12 6:26 ` Christoph Hellwig
[not found] ` <20180412062600.GB30499-jcswGhMUV9g@public.gmane.org>
2018-04-12 9:42 ` Christian König
[not found] ` <6802bd0c-7da6-659a-7e34-8f05d7c6422c-5C7GfCeVMHo@public.gmane.org>
2018-04-12 13:51 ` Robin Murphy
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox