* [PATCH] drm: hibmc: Initialize the hibmc_bo_driver.io_mem_pfn
@ 2017-11-29 11:33 msrb
2017-11-29 14:47 ` Sean Paul
0 siblings, 1 reply; 11+ messages in thread
From: msrb @ 2017-11-29 11:33 UTC (permalink / raw)
To: dri-devel
From: Michal Srb <msrb@suse.com>
The io_mem_pfn field was added in ea642c3216cb2a60d1c0e760ae47ee85c9c16447 and
is used unconditionally. Most drivers were updated to set it to the default
implementation ttm_bo_default_io_mem_pfn, but hibmc was not.
This fixes crash in ttm_bo_vm_fault when hibmc driver is used.
Signed-off-by: Michal Srb <msrb@suse.com>
---
drivers/gpu/drm/hisilicon/hibmc/hibmc_ttm.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/gpu/drm/hisilicon/hibmc/hibmc_ttm.c b/drivers/gpu/drm/hisilicon/hibmc/hibmc_ttm.c
index 3518167a7dc4..0b165ce4ee00 100644
--- a/drivers/gpu/drm/hisilicon/hibmc/hibmc_ttm.c
+++ b/drivers/gpu/drm/hisilicon/hibmc/hibmc_ttm.c
@@ -243,6 +243,7 @@ struct ttm_bo_driver hibmc_bo_driver = {
.verify_access = hibmc_bo_verify_access,
.io_mem_reserve = &hibmc_ttm_io_mem_reserve,
.io_mem_free = NULL,
+ .io_mem_pfn = ttm_bo_default_io_mem_pfn,
};
int hibmc_mm_init(struct hibmc_drm_private *hibmc)
--
2.13.6
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel
^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: [PATCH] drm: hibmc: Initialize the hibmc_bo_driver.io_mem_pfn
2017-11-29 11:33 [PATCH] drm: hibmc: Initialize the hibmc_bo_driver.io_mem_pfn msrb
@ 2017-11-29 14:47 ` Sean Paul
2017-11-29 14:54 ` Michal Srb
2017-11-29 15:20 ` [PATCH] drm/ttm: Use ttm_bo_default_io_mem_pfn if io_mem_pfn is NULL Michal Srb
0 siblings, 2 replies; 11+ messages in thread
From: Sean Paul @ 2017-11-29 14:47 UTC (permalink / raw)
To: msrb; +Cc: dri-devel
On Wed, Nov 29, 2017 at 12:33:24PM +0100, msrb@suse.com wrote:
> From: Michal Srb <msrb@suse.com>
>
> The io_mem_pfn field was added in ea642c3216cb2a60d1c0e760ae47ee85c9c16447 and
> is used unconditionally. Most drivers were updated to set it to the default
> implementation ttm_bo_default_io_mem_pfn, but hibmc was not.
>
> This fixes crash in ttm_bo_vm_fault when hibmc driver is used.
Instead of just doing the same cargo cult in this driver, lets just call the
default function when io_mem_pfn is NULL. Looks like 9 other drivers are
affected as well.
Sean
>
> Signed-off-by: Michal Srb <msrb@suse.com>
> ---
> drivers/gpu/drm/hisilicon/hibmc/hibmc_ttm.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/drivers/gpu/drm/hisilicon/hibmc/hibmc_ttm.c b/drivers/gpu/drm/hisilicon/hibmc/hibmc_ttm.c
> index 3518167a7dc4..0b165ce4ee00 100644
> --- a/drivers/gpu/drm/hisilicon/hibmc/hibmc_ttm.c
> +++ b/drivers/gpu/drm/hisilicon/hibmc/hibmc_ttm.c
> @@ -243,6 +243,7 @@ struct ttm_bo_driver hibmc_bo_driver = {
> .verify_access = hibmc_bo_verify_access,
> .io_mem_reserve = &hibmc_ttm_io_mem_reserve,
> .io_mem_free = NULL,
> + .io_mem_pfn = ttm_bo_default_io_mem_pfn,
> };
>
> int hibmc_mm_init(struct hibmc_drm_private *hibmc)
> --
> 2.13.6
>
> _______________________________________________
> dri-devel mailing list
> dri-devel@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/dri-devel
--
Sean Paul, Software Engineer, Google / Chromium OS
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH] drm: hibmc: Initialize the hibmc_bo_driver.io_mem_pfn
2017-11-29 14:47 ` Sean Paul
@ 2017-11-29 14:54 ` Michal Srb
2017-11-29 15:20 ` [PATCH] drm/ttm: Use ttm_bo_default_io_mem_pfn if io_mem_pfn is NULL Michal Srb
1 sibling, 0 replies; 11+ messages in thread
From: Michal Srb @ 2017-11-29 14:54 UTC (permalink / raw)
To: Sean Paul; +Cc: dri-devel
On středa 29. listopadu 2017 15:47:30 CET Sean Paul wrote:
> On Wed, Nov 29, 2017 at 12:33:24PM +0100, msrb@suse.com wrote:
> > From: Michal Srb <msrb@suse.com>
> >
> > The io_mem_pfn field was added in ea642c3216cb2a60d1c0e760ae47ee85c9c16447
> > and is used unconditionally. Most drivers were updated to set it to the
> > default implementation ttm_bo_default_io_mem_pfn, but hibmc was not.
> >
> > This fixes crash in ttm_bo_vm_fault when hibmc driver is used.
>
> Instead of just doing the same cargo cult in this driver, lets just call the
> default function when io_mem_pfn is NULL. Looks like 9 other drivers are
> affected as well.
Ok, that makes sense.
Michal
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH] drm/ttm: Use ttm_bo_default_io_mem_pfn if io_mem_pfn is NULL
2017-11-29 14:47 ` Sean Paul
2017-11-29 14:54 ` Michal Srb
@ 2017-11-29 15:20 ` Michal Srb
2017-11-29 15:24 ` Christian König
1 sibling, 1 reply; 11+ messages in thread
From: Michal Srb @ 2017-11-29 15:20 UTC (permalink / raw)
To: dri-devel
The io_mem_pfn field was added in commit ea642c3216cb2a60d1c0e760ae47ee85c9c16447
and is called unconditionally. However, not all drivers were updated to set it.
Use the ttm_bo_default_io_mem_pfn function if a driver did not set its own.
Signed-off-by: Michal Srb <msrb@suse.com>
---
drivers/gpu/drm/ttm/ttm_bo_vm.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/drivers/gpu/drm/ttm/ttm_bo_vm.c b/drivers/gpu/drm/ttm/ttm_bo_vm.c
index c8ebb757e36b..e25a99bc519d 100644
--- a/drivers/gpu/drm/ttm/ttm_bo_vm.c
+++ b/drivers/gpu/drm/ttm/ttm_bo_vm.c
@@ -234,7 +234,10 @@ static int ttm_bo_vm_fault(struct vm_fault *vmf)
if (bo->mem.bus.is_iomem) {
/* Iomem should not be marked encrypted */
cvma.vm_page_prot = pgprot_decrypted(cvma.vm_page_prot);
- pfn = bdev->driver->io_mem_pfn(bo, page_offset);
+ if (bdev->driver->io_mem_pfn)
+ pfn = bdev->driver->io_mem_pfn(bo, page_offset);
+ else
+ pfn = ttm_bo_default_io_mem_pfn(bo, page_offset);
} else {
page = ttm->pages[page_offset];
if (unlikely(!page && i == 0)) {
--
2.13.6
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel
^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: [PATCH] drm/ttm: Use ttm_bo_default_io_mem_pfn if io_mem_pfn is NULL
2017-11-29 15:20 ` [PATCH] drm/ttm: Use ttm_bo_default_io_mem_pfn if io_mem_pfn is NULL Michal Srb
@ 2017-11-29 15:24 ` Christian König
2017-11-29 15:29 ` Michal Srb
2017-11-29 15:36 ` Sean Paul
0 siblings, 2 replies; 11+ messages in thread
From: Christian König @ 2017-11-29 15:24 UTC (permalink / raw)
To: Michal Srb, dri-devel
Am 29.11.2017 um 16:20 schrieb Michal Srb:
> The io_mem_pfn field was added in commit ea642c3216cb2a60d1c0e760ae47ee85c9c16447
> and is called unconditionally. However, not all drivers were updated to set it.
>
> Use the ttm_bo_default_io_mem_pfn function if a driver did not set its own.
>
> Signed-off-by: Michal Srb <msrb@suse.com>
NAK, when we have drivers missing this we should set this in the driver
and not add the workaround here.
Which driver is missing this? I thought I fixed all of them.
Regards,
Christian.
> ---
> drivers/gpu/drm/ttm/ttm_bo_vm.c | 5 ++++-
> 1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/drm/ttm/ttm_bo_vm.c b/drivers/gpu/drm/ttm/ttm_bo_vm.c
> index c8ebb757e36b..e25a99bc519d 100644
> --- a/drivers/gpu/drm/ttm/ttm_bo_vm.c
> +++ b/drivers/gpu/drm/ttm/ttm_bo_vm.c
> @@ -234,7 +234,10 @@ static int ttm_bo_vm_fault(struct vm_fault *vmf)
> if (bo->mem.bus.is_iomem) {
> /* Iomem should not be marked encrypted */
> cvma.vm_page_prot = pgprot_decrypted(cvma.vm_page_prot);
> - pfn = bdev->driver->io_mem_pfn(bo, page_offset);
> + if (bdev->driver->io_mem_pfn)
> + pfn = bdev->driver->io_mem_pfn(bo, page_offset);
> + else
> + pfn = ttm_bo_default_io_mem_pfn(bo, page_offset);
> } else {
> page = ttm->pages[page_offset];
> if (unlikely(!page && i == 0)) {
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH] drm/ttm: Use ttm_bo_default_io_mem_pfn if io_mem_pfn is NULL
2017-11-29 15:24 ` Christian König
@ 2017-11-29 15:29 ` Michal Srb
2017-11-29 15:36 ` Sean Paul
1 sibling, 0 replies; 11+ messages in thread
From: Michal Srb @ 2017-11-29 15:29 UTC (permalink / raw)
To: christian.koenig; +Cc: dri-devel
On Wednesday 29th November 2017 16:24:21 CET Christian König wrote:
> Am 29.11.2017 um 16:20 schrieb Michal Srb:
> > The io_mem_pfn field was added in commit
> > ea642c3216cb2a60d1c0e760ae47ee85c9c16447 and is called unconditionally.
> > However, not all drivers were updated to set it.
> >
> > Use the ttm_bo_default_io_mem_pfn function if a driver did not set its
> > own.
> >
> > Signed-off-by: Michal Srb <msrb@suse.com>
>
> NAK, when we have drivers missing this we should set this in the driver
> and not add the workaround here.
>
> Which driver is missing this? I thought I fixed all of them.
The one where I ran into the problem is hibmc. I've sent patch fixing it, but
reportedly there is more drivers with the same issue, so this fix was
suggested instead:
On Wednesday 29th November 2017 15:47:30 CET Sean Paul wrote:
> Instead of just doing the same cargo cult in this driver, lets just call the
> default function when io_mem_pfn is NULL. Looks like 9 other drivers are
> affected as well.
> Sean
Michal
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH] drm/ttm: Use ttm_bo_default_io_mem_pfn if io_mem_pfn is NULL
2017-11-29 15:24 ` Christian König
2017-11-29 15:29 ` Michal Srb
@ 2017-11-29 15:36 ` Sean Paul
2017-11-29 15:40 ` Christian König
1 sibling, 1 reply; 11+ messages in thread
From: Sean Paul @ 2017-11-29 15:36 UTC (permalink / raw)
To: christian.koenig; +Cc: dri-devel
On Wed, Nov 29, 2017 at 04:24:21PM +0100, Christian König wrote:
> Am 29.11.2017 um 16:20 schrieb Michal Srb:
> > The io_mem_pfn field was added in commit ea642c3216cb2a60d1c0e760ae47ee85c9c16447
> > and is called unconditionally. However, not all drivers were updated to set it.
> >
> > Use the ttm_bo_default_io_mem_pfn function if a driver did not set its own.
> >
> > Signed-off-by: Michal Srb <msrb@suse.com>
>
> NAK, when we have drivers missing this we should set this in the driver and
> not add the workaround here.
Why? What's the benefit in adding the same hook in 10 drivers (I was hoping
Michal would also remove the token .io_mem_pfn = ttm_bo_default_io_mem_pfn from
those as well)?
Sean
>
> Which driver is missing this? I thought I fixed all of them.
>
> Regards,
> Christian.
>
> > ---
> > drivers/gpu/drm/ttm/ttm_bo_vm.c | 5 ++++-
> > 1 file changed, 4 insertions(+), 1 deletion(-)
> >
> > diff --git a/drivers/gpu/drm/ttm/ttm_bo_vm.c b/drivers/gpu/drm/ttm/ttm_bo_vm.c
> > index c8ebb757e36b..e25a99bc519d 100644
> > --- a/drivers/gpu/drm/ttm/ttm_bo_vm.c
> > +++ b/drivers/gpu/drm/ttm/ttm_bo_vm.c
> > @@ -234,7 +234,10 @@ static int ttm_bo_vm_fault(struct vm_fault *vmf)
> > if (bo->mem.bus.is_iomem) {
> > /* Iomem should not be marked encrypted */
> > cvma.vm_page_prot = pgprot_decrypted(cvma.vm_page_prot);
> > - pfn = bdev->driver->io_mem_pfn(bo, page_offset);
> > + if (bdev->driver->io_mem_pfn)
> > + pfn = bdev->driver->io_mem_pfn(bo, page_offset);
> > + else
> > + pfn = ttm_bo_default_io_mem_pfn(bo, page_offset);
> > } else {
> > page = ttm->pages[page_offset];
> > if (unlikely(!page && i == 0)) {
>
> _______________________________________________
> dri-devel mailing list
> dri-devel@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/dri-devel
--
Sean Paul, Software Engineer, Google / Chromium OS
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH] drm/ttm: Use ttm_bo_default_io_mem_pfn if io_mem_pfn is NULL
2017-11-29 15:36 ` Sean Paul
@ 2017-11-29 15:40 ` Christian König
2017-11-29 15:44 ` Sean Paul
0 siblings, 1 reply; 11+ messages in thread
From: Christian König @ 2017-11-29 15:40 UTC (permalink / raw)
To: Sean Paul; +Cc: dri-devel
Am 29.11.2017 um 16:36 schrieb Sean Paul:
> On Wed, Nov 29, 2017 at 04:24:21PM +0100, Christian König wrote:
>> Am 29.11.2017 um 16:20 schrieb Michal Srb:
>>> The io_mem_pfn field was added in commit ea642c3216cb2a60d1c0e760ae47ee85c9c16447
>>> and is called unconditionally. However, not all drivers were updated to set it.
>>>
>>> Use the ttm_bo_default_io_mem_pfn function if a driver did not set its own.
>>>
>>> Signed-off-by: Michal Srb <msrb@suse.com>
>> NAK, when we have drivers missing this we should set this in the driver and
>> not add the workaround here.
> Why? What's the benefit in adding the same hook in 10 drivers (I was hoping
> Michal would also remove the token .io_mem_pfn = ttm_bo_default_io_mem_pfn from
> those as well)?
Not have this extra check in common TTM code? That is seriously bad
coding style.
We have tons of fallbacks like this and I unfortunately even created new
one without realizing that this is a problem.
But this really clutters the TTM code and makes it harder to understand.
Christian.
>
> Sean
>
>> Which driver is missing this? I thought I fixed all of them.
>>
>> Regards,
>> Christian.
>>
>>> ---
>>> drivers/gpu/drm/ttm/ttm_bo_vm.c | 5 ++++-
>>> 1 file changed, 4 insertions(+), 1 deletion(-)
>>>
>>> diff --git a/drivers/gpu/drm/ttm/ttm_bo_vm.c b/drivers/gpu/drm/ttm/ttm_bo_vm.c
>>> index c8ebb757e36b..e25a99bc519d 100644
>>> --- a/drivers/gpu/drm/ttm/ttm_bo_vm.c
>>> +++ b/drivers/gpu/drm/ttm/ttm_bo_vm.c
>>> @@ -234,7 +234,10 @@ static int ttm_bo_vm_fault(struct vm_fault *vmf)
>>> if (bo->mem.bus.is_iomem) {
>>> /* Iomem should not be marked encrypted */
>>> cvma.vm_page_prot = pgprot_decrypted(cvma.vm_page_prot);
>>> - pfn = bdev->driver->io_mem_pfn(bo, page_offset);
>>> + if (bdev->driver->io_mem_pfn)
>>> + pfn = bdev->driver->io_mem_pfn(bo, page_offset);
>>> + else
>>> + pfn = ttm_bo_default_io_mem_pfn(bo, page_offset);
>>> } else {
>>> page = ttm->pages[page_offset];
>>> if (unlikely(!page && i == 0)) {
>> _______________________________________________
>> 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] 11+ messages in thread
* Re: [PATCH] drm/ttm: Use ttm_bo_default_io_mem_pfn if io_mem_pfn is NULL
2017-11-29 15:40 ` Christian König
@ 2017-11-29 15:44 ` Sean Paul
2017-11-29 15:59 ` Christian König
0 siblings, 1 reply; 11+ messages in thread
From: Sean Paul @ 2017-11-29 15:44 UTC (permalink / raw)
To: Christian König; +Cc: dri-devel
On Wed, Nov 29, 2017 at 04:40:18PM +0100, Christian König wrote:
> Am 29.11.2017 um 16:36 schrieb Sean Paul:
> > On Wed, Nov 29, 2017 at 04:24:21PM +0100, Christian König wrote:
> > > Am 29.11.2017 um 16:20 schrieb Michal Srb:
> > > > The io_mem_pfn field was added in commit ea642c3216cb2a60d1c0e760ae47ee85c9c16447
> > > > and is called unconditionally. However, not all drivers were updated to set it.
> > > >
> > > > Use the ttm_bo_default_io_mem_pfn function if a driver did not set its own.
> > > >
> > > > Signed-off-by: Michal Srb <msrb@suse.com>
> > > NAK, when we have drivers missing this we should set this in the driver and
> > > not add the workaround here.
> > Why? What's the benefit in adding the same hook in 10 drivers (I was hoping
> > Michal would also remove the token .io_mem_pfn = ttm_bo_default_io_mem_pfn from
> > those as well)?
>
> Not have this extra check in common TTM code? That is seriously bad coding
> style.
>
[citation neeeded]
I'd argue it's bad form to require everyone add a copypasta hook to their driver
everytime an unrelated driver needs more control than the default gives :-)
I think your point would hold if we were talking about a couple of drivers, but
once you scale to 10+, it's no longer a trivial amount of code. If the null check
is too distracting, you could always pull it out into an inline.
Sean
> We have tons of fallbacks like this and I unfortunately even created new one
> without realizing that this is a problem.
>
> But this really clutters the TTM code and makes it harder to understand.
>
> Christian.
>
> >
> > Sean
> >
> > > Which driver is missing this? I thought I fixed all of them.
> > >
> > > Regards,
> > > Christian.
> > >
> > > > ---
> > > > drivers/gpu/drm/ttm/ttm_bo_vm.c | 5 ++++-
> > > > 1 file changed, 4 insertions(+), 1 deletion(-)
> > > >
> > > > diff --git a/drivers/gpu/drm/ttm/ttm_bo_vm.c b/drivers/gpu/drm/ttm/ttm_bo_vm.c
> > > > index c8ebb757e36b..e25a99bc519d 100644
> > > > --- a/drivers/gpu/drm/ttm/ttm_bo_vm.c
> > > > +++ b/drivers/gpu/drm/ttm/ttm_bo_vm.c
> > > > @@ -234,7 +234,10 @@ static int ttm_bo_vm_fault(struct vm_fault *vmf)
> > > > if (bo->mem.bus.is_iomem) {
> > > > /* Iomem should not be marked encrypted */
> > > > cvma.vm_page_prot = pgprot_decrypted(cvma.vm_page_prot);
> > > > - pfn = bdev->driver->io_mem_pfn(bo, page_offset);
> > > > + if (bdev->driver->io_mem_pfn)
> > > > + pfn = bdev->driver->io_mem_pfn(bo, page_offset);
> > > > + else
> > > > + pfn = ttm_bo_default_io_mem_pfn(bo, page_offset);
> > > > } else {
> > > > page = ttm->pages[page_offset];
> > > > if (unlikely(!page && i == 0)) {
> > > _______________________________________________
> > > dri-devel mailing list
> > > dri-devel@lists.freedesktop.org
> > > https://lists.freedesktop.org/mailman/listinfo/dri-devel
>
--
Sean Paul, Software Engineer, Google / Chromium OS
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH] drm/ttm: Use ttm_bo_default_io_mem_pfn if io_mem_pfn is NULL
2017-11-29 15:44 ` Sean Paul
@ 2017-11-29 15:59 ` Christian König
2017-11-29 16:13 ` Sean Paul
0 siblings, 1 reply; 11+ messages in thread
From: Christian König @ 2017-11-29 15:59 UTC (permalink / raw)
To: Sean Paul, Christian König; +Cc: dri-devel
Am 29.11.2017 um 16:44 schrieb Sean Paul:
> On Wed, Nov 29, 2017 at 04:40:18PM +0100, Christian König wrote:
>> Am 29.11.2017 um 16:36 schrieb Sean Paul:
>>> On Wed, Nov 29, 2017 at 04:24:21PM +0100, Christian König wrote:
>>>> Am 29.11.2017 um 16:20 schrieb Michal Srb:
>>>>> The io_mem_pfn field was added in commit ea642c3216cb2a60d1c0e760ae47ee85c9c16447
>>>>> and is called unconditionally. However, not all drivers were updated to set it.
>>>>>
>>>>> Use the ttm_bo_default_io_mem_pfn function if a driver did not set its own.
>>>>>
>>>>> Signed-off-by: Michal Srb <msrb@suse.com>
>>>> NAK, when we have drivers missing this we should set this in the driver and
>>>> not add the workaround here.
>>> Why? What's the benefit in adding the same hook in 10 drivers (I was hoping
>>> Michal would also remove the token .io_mem_pfn = ttm_bo_default_io_mem_pfn from
>>> those as well)?
>> Not have this extra check in common TTM code? That is seriously bad coding
>> style.
>>
> [citation neeeded]
>
> I'd argue it's bad form to require everyone add a copypasta hook to their driver
> everytime an unrelated driver needs more control than the default gives :-)
Well that is another design problem of TTM that it works like a middle
layer instead of a tool. But I'm seriously not going to fix this anytime
soon.
> I think your point would hold if we were talking about a couple of drivers, but
> once you scale to 10+, it's no longer a trivial amount of code. If the null check
> is too distracting, you could always pull it out into an inline.
Yeah, that is one possibility that would work for me as well.
TTM has patterns like the following:
First occasion:
if (a_is_available)
do_a();
else
do_b();
Same code a bit lower:
if (a_is_available)
do_a()
/* Else is missing here */
I'm seriously favoring updating a dozen drivers just to avoid more of this.
If you want to fix that with adding wrapper functions to call the driver
callback and give a consistent operation when the callback isn't
available then I'm perfectly fine with that as well. Patches are always
welcome.
Christian.
>
> Sean
>
>
>> We have tons of fallbacks like this and I unfortunately even created new one
>> without realizing that this is a problem.
>>
>> But this really clutters the TTM code and makes it harder to understand.
>>
>> Christian.
>>
>>> Sean
>>>
>>>> Which driver is missing this? I thought I fixed all of them.
>>>>
>>>> Regards,
>>>> Christian.
>>>>
>>>>> ---
>>>>> drivers/gpu/drm/ttm/ttm_bo_vm.c | 5 ++++-
>>>>> 1 file changed, 4 insertions(+), 1 deletion(-)
>>>>>
>>>>> diff --git a/drivers/gpu/drm/ttm/ttm_bo_vm.c b/drivers/gpu/drm/ttm/ttm_bo_vm.c
>>>>> index c8ebb757e36b..e25a99bc519d 100644
>>>>> --- a/drivers/gpu/drm/ttm/ttm_bo_vm.c
>>>>> +++ b/drivers/gpu/drm/ttm/ttm_bo_vm.c
>>>>> @@ -234,7 +234,10 @@ static int ttm_bo_vm_fault(struct vm_fault *vmf)
>>>>> if (bo->mem.bus.is_iomem) {
>>>>> /* Iomem should not be marked encrypted */
>>>>> cvma.vm_page_prot = pgprot_decrypted(cvma.vm_page_prot);
>>>>> - pfn = bdev->driver->io_mem_pfn(bo, page_offset);
>>>>> + if (bdev->driver->io_mem_pfn)
>>>>> + pfn = bdev->driver->io_mem_pfn(bo, page_offset);
>>>>> + else
>>>>> + pfn = ttm_bo_default_io_mem_pfn(bo, page_offset);
>>>>> } else {
>>>>> page = ttm->pages[page_offset];
>>>>> if (unlikely(!page && i == 0)) {
>>>> _______________________________________________
>>>> 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] 11+ messages in thread
* Re: [PATCH] drm/ttm: Use ttm_bo_default_io_mem_pfn if io_mem_pfn is NULL
2017-11-29 15:59 ` Christian König
@ 2017-11-29 16:13 ` Sean Paul
0 siblings, 0 replies; 11+ messages in thread
From: Sean Paul @ 2017-11-29 16:13 UTC (permalink / raw)
To: christian.koenig; +Cc: dri-devel
On Wed, Nov 29, 2017 at 04:59:29PM +0100, Christian König wrote:
> Am 29.11.2017 um 16:44 schrieb Sean Paul:
> > On Wed, Nov 29, 2017 at 04:40:18PM +0100, Christian König wrote:
> > > Am 29.11.2017 um 16:36 schrieb Sean Paul:
> > > > On Wed, Nov 29, 2017 at 04:24:21PM +0100, Christian König wrote:
> > > > > Am 29.11.2017 um 16:20 schrieb Michal Srb:
> > > > > > The io_mem_pfn field was added in commit ea642c3216cb2a60d1c0e760ae47ee85c9c16447
> > > > > > and is called unconditionally. However, not all drivers were updated to set it.
> > > > > >
> > > > > > Use the ttm_bo_default_io_mem_pfn function if a driver did not set its own.
> > > > > >
> > > > > > Signed-off-by: Michal Srb <msrb@suse.com>
> > > > > NAK, when we have drivers missing this we should set this in the driver and
> > > > > not add the workaround here.
> > > > Why? What's the benefit in adding the same hook in 10 drivers (I was hoping
> > > > Michal would also remove the token .io_mem_pfn = ttm_bo_default_io_mem_pfn from
> > > > those as well)?
> > > Not have this extra check in common TTM code? That is seriously bad coding
> > > style.
> > >
> > [citation neeeded]
> >
> > I'd argue it's bad form to require everyone add a copypasta hook to their driver
> > everytime an unrelated driver needs more control than the default gives :-)
>
> Well that is another design problem of TTM that it works like a middle layer
> instead of a tool. But I'm seriously not going to fix this anytime soon.
>
> > I think your point would hold if we were talking about a couple of drivers, but
> > once you scale to 10+, it's no longer a trivial amount of code. If the null check
> > is too distracting, you could always pull it out into an inline.
> Yeah, that is one possibility that would work for me as well.
>
> TTM has patterns like the following:
>
> First occasion:
> if (a_is_available)
> do_a();
> else
> do_b();
>
> Same code a bit lower:
> if (a_is_available)
> do_a()
> /* Else is missing here */
>
> I'm seriously favoring updating a dozen drivers just to avoid more of this.
>
> If you want to fix that with adding wrapper functions to call the driver
> callback and give a consistent operation when the callback isn't available
> then I'm perfectly fine with that as well. Patches are always welcome.
Yeah, that's what I was asking Michal for. I'd like a patch series where:
[0/N] adds the inline to call the default if io_mem_pfn is NULL
[1..N-1/N] remove all .io_mem_pfn = ttm_bo_default_io_mem_pfn from drivers
[N/N] unexport ttm_bo_default_io_mem_pfn and make it static
Sean
>
> Christian.
>
> >
> > Sean
> >
> >
> > > We have tons of fallbacks like this and I unfortunately even created new one
> > > without realizing that this is a problem.
> > >
> > > But this really clutters the TTM code and makes it harder to understand.
> > >
> > > Christian.
> > >
> > > > Sean
> > > >
> > > > > Which driver is missing this? I thought I fixed all of them.
> > > > >
> > > > > Regards,
> > > > > Christian.
> > > > >
> > > > > > ---
> > > > > > drivers/gpu/drm/ttm/ttm_bo_vm.c | 5 ++++-
> > > > > > 1 file changed, 4 insertions(+), 1 deletion(-)
> > > > > >
> > > > > > diff --git a/drivers/gpu/drm/ttm/ttm_bo_vm.c b/drivers/gpu/drm/ttm/ttm_bo_vm.c
> > > > > > index c8ebb757e36b..e25a99bc519d 100644
> > > > > > --- a/drivers/gpu/drm/ttm/ttm_bo_vm.c
> > > > > > +++ b/drivers/gpu/drm/ttm/ttm_bo_vm.c
> > > > > > @@ -234,7 +234,10 @@ static int ttm_bo_vm_fault(struct vm_fault *vmf)
> > > > > > if (bo->mem.bus.is_iomem) {
> > > > > > /* Iomem should not be marked encrypted */
> > > > > > cvma.vm_page_prot = pgprot_decrypted(cvma.vm_page_prot);
> > > > > > - pfn = bdev->driver->io_mem_pfn(bo, page_offset);
> > > > > > + if (bdev->driver->io_mem_pfn)
> > > > > > + pfn = bdev->driver->io_mem_pfn(bo, page_offset);
> > > > > > + else
> > > > > > + pfn = ttm_bo_default_io_mem_pfn(bo, page_offset);
> > > > > > } else {
> > > > > > page = ttm->pages[page_offset];
> > > > > > if (unlikely(!page && i == 0)) {
> > > > > _______________________________________________
> > > > > dri-devel mailing list
> > > > > dri-devel@lists.freedesktop.org
> > > > > https://lists.freedesktop.org/mailman/listinfo/dri-devel
>
--
Sean Paul, Software Engineer, Google / Chromium OS
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel
^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2017-11-29 16:13 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-11-29 11:33 [PATCH] drm: hibmc: Initialize the hibmc_bo_driver.io_mem_pfn msrb
2017-11-29 14:47 ` Sean Paul
2017-11-29 14:54 ` Michal Srb
2017-11-29 15:20 ` [PATCH] drm/ttm: Use ttm_bo_default_io_mem_pfn if io_mem_pfn is NULL Michal Srb
2017-11-29 15:24 ` Christian König
2017-11-29 15:29 ` Michal Srb
2017-11-29 15:36 ` Sean Paul
2017-11-29 15:40 ` Christian König
2017-11-29 15:44 ` Sean Paul
2017-11-29 15:59 ` Christian König
2017-11-29 16:13 ` Sean Paul
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.